diff --git a/CHANGELOG.md b/CHANGELOG.md index c46417f..511b47b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,14 +6,20 @@ All notable changes to NextFloor, newest first. Every release lists what is **Ad ### Added +- **IP-Symcon variable reload:** A button in the designer title bar reloads the complete object tree, variables and current presentation metadata without closing the plan, with progress, success and error feedback. + - **IP-Symcon object-tree picker:** Data point fields open a modal dialog with the real Symcon hierarchy, including instances, links, hidden objects and empty categories, ordered as in the console. Search keeps matching objects in their original branches; confirmation, cancellation and keyboard navigation are supported. ### Changed +- **Foldable wall menu:** The wall settings in the room sidebar can be collapsed using their heading. + - **IP-Symcon picker main category:** Hidden categories and their variables always remain visible. I/O, splitter, core, configurator, discovery and visualization instances are grouped under a collapsed virtual “System” folder, with searchable/selectable descendants and no changes to the actual Symcon object tree. ### Fixed +- **IP-Symcon KNX room temperatures:** Current Symcon presentation units are read alongside legacy profiles. Numeric temperature variables remain selectable and readable even when a parent name caused an actuator classification; saved mappings stay intact. + - **IP-Symcon “HTTP 200” / output-buffer overflow:** Large API responses use bounded response chunks instead of exceeding the kernel's 1 MiB output limit. The full variable/object tree, packs, plans, images and backups are reassembled without data loss, polling cannot overlap, and malformed responses receive a useful error message. - **IP-Symcon “Hook not found”:** The module restores its internal WebHook after kernel startup and before opening the designer or tile, reports registration failures instead of showing “ready”, retries failed registrations and offers a “Repair WebHook” button without replacing the instance or its saved project. - **IP-Symcon module discovery:** NextFloor is registered as a regular device instance with complete module metadata, so it is available in “Add instance”. The independent HTML-SDK tile remains enabled. A package check now rejects invalid module types, missing manifest fields and an incorrect installation directory layout before building. diff --git a/custom_components/nextfloor/frontend/nextfloor-card-editor.js b/custom_components/nextfloor/frontend/nextfloor-card-editor.js index c9c869b..cbc922a 100644 --- a/custom_components/nextfloor/frontend/nextfloor-card-editor.js +++ b/custom_components/nextfloor/frontend/nextfloor-card-editor.js @@ -1,5 +1,5 @@ /*! NextFloor, MIT licence. Includes three.js (MIT) and Lit (BSD-3-Clause); see LICENSE and THIRD_PARTY_NOTICES.md */ -var p={cs:"4be67fcd522e",da:"0fe66a82bf2a",es:"bd89dffd1355",fi:"9a17bc084f56",fr:"6312d0f61ebf",hu:"27ba348531dc",it:"1b705e76dd00",nb:"c5ea24fb9ef6",nl:"b64142c67c2e",pl:"8527a4930402",pt:"31857a2d2277",ro:"e3cb5f449f0f",sk:"320611594db0",sl:"8071691ceda3",sv:"711b911ec8da",tr:"7c83ce1c3372",zh:"50518d9f494e"};var M=globalThis,N=M.ShadowRoot&&(M.ShadyCSS===void 0||M.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,U=Symbol(),me=new WeakMap,R=class{constructor(e,t,n){if(this._$cssResult$=!0,n!==U)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=e,this.t=t}get styleSheet(){let e=this.o,t=this.t;if(N&&e===void 0){let n=t!==void 0&&t.length===1;n&&(e=me.get(t)),e===void 0&&((this.o=e=new CSSStyleSheet).replaceSync(this.cssText),n&&me.set(t,e))}return e}toString(){return this.cssText}},pe=i=>new R(typeof i=="string"?i:i+"",void 0,U),V=(i,...e)=>{let t=i.length===1?i[0]:e.reduce((n,r,o)=>n+(a=>{if(a._$cssResult$===!0)return a.cssText;if(typeof a=="number")return a;throw Error("Value passed to 'css' function must be a 'css' function result: "+a+". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.")})(r)+i[o+1],i[0]);return new R(t,i,U)},fe=(i,e)=>{if(N)i.adoptedStyleSheets=e.map(t=>t instanceof CSSStyleSheet?t:t.styleSheet);else for(let t of e){let n=document.createElement("style"),r=M.litNonce;r!==void 0&&n.setAttribute("nonce",r),n.textContent=t.cssText,i.appendChild(n)}},j=N?i=>i:i=>i instanceof CSSStyleSheet?(e=>{let t="";for(let n of e.cssRules)t+=n.cssText;return pe(t)})(i):i;var{is:Ke,defineProperty:Ge,getOwnPropertyDescriptor:Oe,getOwnPropertyNames:Ie,getOwnPropertySymbols:Ze,getPrototypeOf:Ue}=Object,C=globalThis,ge=C.trustedTypes,Ve=ge?ge.emptyScript:"",je=C.reactiveElementPolyfillSupport,F=(i,e)=>i,q={toAttribute(i,e){switch(e){case Boolean:i=i?Ve:null;break;case Object:case Array:i=i==null?i:JSON.stringify(i)}return i},fromAttribute(i,e){let t=i;switch(e){case Boolean:t=i!==null;break;case Number:t=i===null?null:Number(i);break;case Object:case Array:try{t=JSON.parse(i)}catch{t=null}}return t}},we=(i,e)=>!Ke(i,e),be={attribute:!0,type:String,converter:q,reflect:!1,useDefault:!1,hasChanged:we};Symbol.metadata??=Symbol("metadata"),C.litPropertyMetadata??=new WeakMap;var b=class extends HTMLElement{static addInitializer(e){this._$Ei(),(this.l??=[]).push(e)}static get observedAttributes(){return this.finalize(),this._$Eh&&[...this._$Eh.keys()]}static createProperty(e,t=be){if(t.state&&(t.attribute=!1),this._$Ei(),this.prototype.hasOwnProperty(e)&&((t=Object.create(t)).wrapped=!0),this.elementProperties.set(e,t),!t.noAccessor){let n=Symbol(),r=this.getPropertyDescriptor(e,n,t);r!==void 0&&Ge(this.prototype,e,r)}}static getPropertyDescriptor(e,t,n){let{get:r,set:o}=Oe(this.prototype,e)??{get(){return this[t]},set(a){this[t]=a}};return{get:r,set(a){let s=r?.call(this);o?.call(this,a),this.requestUpdate(e,s,n)},configurable:!0,enumerable:!0}}static getPropertyOptions(e){return this.elementProperties.get(e)??be}static _$Ei(){if(this.hasOwnProperty(F("elementProperties")))return;let e=Ue(this);e.finalize(),e.l!==void 0&&(this.l=[...e.l]),this.elementProperties=new Map(e.elementProperties)}static finalize(){if(this.hasOwnProperty(F("finalized")))return;if(this.finalized=!0,this._$Ei(),this.hasOwnProperty(F("properties"))){let t=this.properties,n=[...Ie(t),...Ze(t)];for(let r of n)this.createProperty(r,t[r])}let e=this[Symbol.metadata];if(e!==null){let t=litPropertyMetadata.get(e);if(t!==void 0)for(let[n,r]of t)this.elementProperties.set(n,r)}this._$Eh=new Map;for(let[t,n]of this.elementProperties){let r=this._$Eu(t,n);r!==void 0&&this._$Eh.set(r,t)}this.elementStyles=this.finalizeStyles(this.styles)}static finalizeStyles(e){let t=[];if(Array.isArray(e)){let n=new Set(e.flat(1/0).reverse());for(let r of n)t.unshift(j(r))}else e!==void 0&&t.push(j(e));return t}static _$Eu(e,t){let n=t.attribute;return n===!1?void 0:typeof n=="string"?n:typeof e=="string"?e.toLowerCase():void 0}constructor(){super(),this._$Ep=void 0,this.isUpdatePending=!1,this.hasUpdated=!1,this._$Em=null,this._$Ev()}_$Ev(){this._$ES=new Promise(e=>this.enableUpdating=e),this._$AL=new Map,this._$E_(),this.requestUpdate(),this.constructor.l?.forEach(e=>e(this))}addController(e){(this._$EO??=new Set).add(e),this.renderRoot!==void 0&&this.isConnected&&e.hostConnected?.()}removeController(e){this._$EO?.delete(e)}_$E_(){let e=new Map,t=this.constructor.elementProperties;for(let n of t.keys())this.hasOwnProperty(n)&&(e.set(n,this[n]),delete this[n]);e.size>0&&(this._$Ep=e)}createRenderRoot(){let e=this.shadowRoot??this.attachShadow(this.constructor.shadowRootOptions);return fe(e,this.constructor.elementStyles),e}connectedCallback(){this.renderRoot??=this.createRenderRoot(),this.enableUpdating(!0),this._$EO?.forEach(e=>e.hostConnected?.())}enableUpdating(e){}disconnectedCallback(){this._$EO?.forEach(e=>e.hostDisconnected?.())}attributeChangedCallback(e,t,n){this._$AK(e,n)}_$ET(e,t){let n=this.constructor.elementProperties.get(e),r=this.constructor._$Eu(e,n);if(r!==void 0&&n.reflect===!0){let o=(n.converter?.toAttribute!==void 0?n.converter:q).toAttribute(t,n.type);this._$Em=e,o==null?this.removeAttribute(r):this.setAttribute(r,o),this._$Em=null}}_$AK(e,t){let n=this.constructor,r=n._$Eh.get(e);if(r!==void 0&&this._$Em!==r){let o=n.getPropertyOptions(r),a=typeof o.converter=="function"?{fromAttribute:o.converter}:o.converter?.fromAttribute!==void 0?o.converter:q;this._$Em=r;let s=a.fromAttribute(t,o.type);this[r]=s??this._$Ej?.get(r)??s,this._$Em=null}}requestUpdate(e,t,n,r=!1,o){if(e!==void 0){let a=this.constructor;if(r===!1&&(o=this[e]),n??=a.getPropertyOptions(e),!((n.hasChanged??we)(o,t)||n.useDefault&&n.reflect&&o===this._$Ej?.get(e)&&!this.hasAttribute(a._$Eu(e,n))))return;this.C(e,t,n)}this.isUpdatePending===!1&&(this._$ES=this._$EP())}C(e,t,{useDefault:n,reflect:r,wrapped:o},a){n&&!(this._$Ej??=new Map).has(e)&&(this._$Ej.set(e,a??t??this[e]),o!==!0||a!==void 0)||(this._$AL.has(e)||(this.hasUpdated||n||(t=void 0),this._$AL.set(e,t)),r===!0&&this._$Em!==e&&(this._$Eq??=new Set).add(e))}async _$EP(){this.isUpdatePending=!0;try{await this._$ES}catch(t){Promise.reject(t)}let e=this.scheduleUpdate();return e!=null&&await e,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){if(!this.isUpdatePending)return;if(!this.hasUpdated){if(this.renderRoot??=this.createRenderRoot(),this._$Ep){for(let[r,o]of this._$Ep)this[r]=o;this._$Ep=void 0}let n=this.constructor.elementProperties;if(n.size>0)for(let[r,o]of n){let{wrapped:a}=o,s=this[r];a!==!0||this._$AL.has(r)||s===void 0||this.C(r,void 0,o,s)}}let e=!1,t=this._$AL;try{e=this.shouldUpdate(t),e?(this.willUpdate(t),this._$EO?.forEach(n=>n.hostUpdate?.()),this.update(t)):this._$EM()}catch(n){throw e=!1,this._$EM(),n}e&&this._$AE(t)}willUpdate(e){}_$AE(e){this._$EO?.forEach(t=>t.hostUpdated?.()),this.hasUpdated||(this.hasUpdated=!0,this.firstUpdated(e)),this.updated(e)}_$EM(){this._$AL=new Map,this.isUpdatePending=!1}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$ES}shouldUpdate(e){return!0}update(e){this._$Eq&&=this._$Eq.forEach(t=>this._$ET(t,this[t])),this._$EM()}updated(e){}firstUpdated(e){}};b.elementStyles=[],b.shadowRootOptions={mode:"open"},b[F("elementProperties")]=new Map,b[F("finalized")]=new Map,je?.({ReactiveElement:b}),(C.reactiveElementVersions??=[]).push("2.1.2");var ne=globalThis,ke=i=>i,K=ne.trustedTypes,ve=K?K.createPolicy("lit-html",{createHTML:i=>i}):void 0,Ee="$lit$",v=`lit$${Math.random().toFixed(9).slice(2)}$`,Te="?"+v,qe=`<${Te}>`,D=document,H=()=>D.createComment(""),W=i=>i===null||typeof i!="object"&&typeof i!="function",re=Array.isArray,Je=i=>re(i)||typeof i?.[Symbol.iterator]=="function",J=`[ +var p={cs:"4be67fcd522e",da:"0fe66a82bf2a",es:"bd89dffd1355",fi:"9a17bc084f56",fr:"6312d0f61ebf",hu:"27ba348531dc",it:"1b705e76dd00",nb:"c5ea24fb9ef6",nl:"b64142c67c2e",pl:"8527a4930402",pt:"31857a2d2277",ro:"e3cb5f449f0f",sk:"320611594db0",sl:"8071691ceda3",sv:"711b911ec8da",tr:"7c83ce1c3372",zh:"50518d9f494e"};var M=globalThis,N=M.ShadowRoot&&(M.ShadyCSS===void 0||M.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,V=Symbol(),me=new WeakMap,R=class{constructor(e,t,n){if(this._$cssResult$=!0,n!==V)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=e,this.t=t}get styleSheet(){let e=this.o,t=this.t;if(N&&e===void 0){let n=t!==void 0&&t.length===1;n&&(e=me.get(t)),e===void 0&&((this.o=e=new CSSStyleSheet).replaceSync(this.cssText),n&&me.set(t,e))}return e}toString(){return this.cssText}},pe=i=>new R(typeof i=="string"?i:i+"",void 0,V),U=(i,...e)=>{let t=i.length===1?i[0]:e.reduce((n,r,o)=>n+(a=>{if(a._$cssResult$===!0)return a.cssText;if(typeof a=="number")return a;throw Error("Value passed to 'css' function must be a 'css' function result: "+a+". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.")})(r)+i[o+1],i[0]);return new R(t,i,V)},fe=(i,e)=>{if(N)i.adoptedStyleSheets=e.map(t=>t instanceof CSSStyleSheet?t:t.styleSheet);else for(let t of e){let n=document.createElement("style"),r=M.litNonce;r!==void 0&&n.setAttribute("nonce",r),n.textContent=t.cssText,i.appendChild(n)}},j=N?i=>i:i=>i instanceof CSSStyleSheet?(e=>{let t="";for(let n of e.cssRules)t+=n.cssText;return pe(t)})(i):i;var{is:Ke,defineProperty:Ge,getOwnPropertyDescriptor:Oe,getOwnPropertyNames:Ie,getOwnPropertySymbols:Ze,getPrototypeOf:Ve}=Object,C=globalThis,ge=C.trustedTypes,Ue=ge?ge.emptyScript:"",je=C.reactiveElementPolyfillSupport,F=(i,e)=>i,q={toAttribute(i,e){switch(e){case Boolean:i=i?Ue:null;break;case Object:case Array:i=i==null?i:JSON.stringify(i)}return i},fromAttribute(i,e){let t=i;switch(e){case Boolean:t=i!==null;break;case Number:t=i===null?null:Number(i);break;case Object:case Array:try{t=JSON.parse(i)}catch{t=null}}return t}},we=(i,e)=>!Ke(i,e),be={attribute:!0,type:String,converter:q,reflect:!1,useDefault:!1,hasChanged:we};Symbol.metadata??=Symbol("metadata"),C.litPropertyMetadata??=new WeakMap;var b=class extends HTMLElement{static addInitializer(e){this._$Ei(),(this.l??=[]).push(e)}static get observedAttributes(){return this.finalize(),this._$Eh&&[...this._$Eh.keys()]}static createProperty(e,t=be){if(t.state&&(t.attribute=!1),this._$Ei(),this.prototype.hasOwnProperty(e)&&((t=Object.create(t)).wrapped=!0),this.elementProperties.set(e,t),!t.noAccessor){let n=Symbol(),r=this.getPropertyDescriptor(e,n,t);r!==void 0&&Ge(this.prototype,e,r)}}static getPropertyDescriptor(e,t,n){let{get:r,set:o}=Oe(this.prototype,e)??{get(){return this[t]},set(a){this[t]=a}};return{get:r,set(a){let s=r?.call(this);o?.call(this,a),this.requestUpdate(e,s,n)},configurable:!0,enumerable:!0}}static getPropertyOptions(e){return this.elementProperties.get(e)??be}static _$Ei(){if(this.hasOwnProperty(F("elementProperties")))return;let e=Ve(this);e.finalize(),e.l!==void 0&&(this.l=[...e.l]),this.elementProperties=new Map(e.elementProperties)}static finalize(){if(this.hasOwnProperty(F("finalized")))return;if(this.finalized=!0,this._$Ei(),this.hasOwnProperty(F("properties"))){let t=this.properties,n=[...Ie(t),...Ze(t)];for(let r of n)this.createProperty(r,t[r])}let e=this[Symbol.metadata];if(e!==null){let t=litPropertyMetadata.get(e);if(t!==void 0)for(let[n,r]of t)this.elementProperties.set(n,r)}this._$Eh=new Map;for(let[t,n]of this.elementProperties){let r=this._$Eu(t,n);r!==void 0&&this._$Eh.set(r,t)}this.elementStyles=this.finalizeStyles(this.styles)}static finalizeStyles(e){let t=[];if(Array.isArray(e)){let n=new Set(e.flat(1/0).reverse());for(let r of n)t.unshift(j(r))}else e!==void 0&&t.push(j(e));return t}static _$Eu(e,t){let n=t.attribute;return n===!1?void 0:typeof n=="string"?n:typeof e=="string"?e.toLowerCase():void 0}constructor(){super(),this._$Ep=void 0,this.isUpdatePending=!1,this.hasUpdated=!1,this._$Em=null,this._$Ev()}_$Ev(){this._$ES=new Promise(e=>this.enableUpdating=e),this._$AL=new Map,this._$E_(),this.requestUpdate(),this.constructor.l?.forEach(e=>e(this))}addController(e){(this._$EO??=new Set).add(e),this.renderRoot!==void 0&&this.isConnected&&e.hostConnected?.()}removeController(e){this._$EO?.delete(e)}_$E_(){let e=new Map,t=this.constructor.elementProperties;for(let n of t.keys())this.hasOwnProperty(n)&&(e.set(n,this[n]),delete this[n]);e.size>0&&(this._$Ep=e)}createRenderRoot(){let e=this.shadowRoot??this.attachShadow(this.constructor.shadowRootOptions);return fe(e,this.constructor.elementStyles),e}connectedCallback(){this.renderRoot??=this.createRenderRoot(),this.enableUpdating(!0),this._$EO?.forEach(e=>e.hostConnected?.())}enableUpdating(e){}disconnectedCallback(){this._$EO?.forEach(e=>e.hostDisconnected?.())}attributeChangedCallback(e,t,n){this._$AK(e,n)}_$ET(e,t){let n=this.constructor.elementProperties.get(e),r=this.constructor._$Eu(e,n);if(r!==void 0&&n.reflect===!0){let o=(n.converter?.toAttribute!==void 0?n.converter:q).toAttribute(t,n.type);this._$Em=e,o==null?this.removeAttribute(r):this.setAttribute(r,o),this._$Em=null}}_$AK(e,t){let n=this.constructor,r=n._$Eh.get(e);if(r!==void 0&&this._$Em!==r){let o=n.getPropertyOptions(r),a=typeof o.converter=="function"?{fromAttribute:o.converter}:o.converter?.fromAttribute!==void 0?o.converter:q;this._$Em=r;let s=a.fromAttribute(t,o.type);this[r]=s??this._$Ej?.get(r)??s,this._$Em=null}}requestUpdate(e,t,n,r=!1,o){if(e!==void 0){let a=this.constructor;if(r===!1&&(o=this[e]),n??=a.getPropertyOptions(e),!((n.hasChanged??we)(o,t)||n.useDefault&&n.reflect&&o===this._$Ej?.get(e)&&!this.hasAttribute(a._$Eu(e,n))))return;this.C(e,t,n)}this.isUpdatePending===!1&&(this._$ES=this._$EP())}C(e,t,{useDefault:n,reflect:r,wrapped:o},a){n&&!(this._$Ej??=new Map).has(e)&&(this._$Ej.set(e,a??t??this[e]),o!==!0||a!==void 0)||(this._$AL.has(e)||(this.hasUpdated||n||(t=void 0),this._$AL.set(e,t)),r===!0&&this._$Em!==e&&(this._$Eq??=new Set).add(e))}async _$EP(){this.isUpdatePending=!0;try{await this._$ES}catch(t){Promise.reject(t)}let e=this.scheduleUpdate();return e!=null&&await e,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){if(!this.isUpdatePending)return;if(!this.hasUpdated){if(this.renderRoot??=this.createRenderRoot(),this._$Ep){for(let[r,o]of this._$Ep)this[r]=o;this._$Ep=void 0}let n=this.constructor.elementProperties;if(n.size>0)for(let[r,o]of n){let{wrapped:a}=o,s=this[r];a!==!0||this._$AL.has(r)||s===void 0||this.C(r,void 0,o,s)}}let e=!1,t=this._$AL;try{e=this.shouldUpdate(t),e?(this.willUpdate(t),this._$EO?.forEach(n=>n.hostUpdate?.()),this.update(t)):this._$EM()}catch(n){throw e=!1,this._$EM(),n}e&&this._$AE(t)}willUpdate(e){}_$AE(e){this._$EO?.forEach(t=>t.hostUpdated?.()),this.hasUpdated||(this.hasUpdated=!0,this.firstUpdated(e)),this.updated(e)}_$EM(){this._$AL=new Map,this.isUpdatePending=!1}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$ES}shouldUpdate(e){return!0}update(e){this._$Eq&&=this._$Eq.forEach(t=>this._$ET(t,this[t])),this._$EM()}updated(e){}firstUpdated(e){}};b.elementStyles=[],b.shadowRootOptions={mode:"open"},b[F("elementProperties")]=new Map,b[F("finalized")]=new Map,je?.({ReactiveElement:b}),(C.reactiveElementVersions??=[]).push("2.1.2");var ne=globalThis,ke=i=>i,K=ne.trustedTypes,ve=K?K.createPolicy("lit-html",{createHTML:i=>i}):void 0,Ee="$lit$",v=`lit$${Math.random().toFixed(9).slice(2)}$`,Te="?"+v,qe=`<${Te}>`,D=document,H=()=>D.createComment(""),W=i=>i===null||typeof i!="object"&&typeof i!="function",re=Array.isArray,Je=i=>re(i)||typeof i?.[Symbol.iterator]=="function",J=`[ \f\r]`,x=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,ye=/-->/g,Se=/>/g,S=RegExp(`>|${J}(?:([^\\s"'>=/]+)(${J}*=${J}*(?:[^ \f\r"'\`<>=]|("|')|))|$)`,"g"),Ae=/'/g,De=/"/g,Re=/^(?:script|style|textarea|title)$/i,ie=i=>(e,...t)=>({_$litType$:i,strings:e,values:t}),l=ie(1),ct=ie(2),ut=ie(3),z=Symbol.for("lit-noChange"),d=Symbol.for("lit-nothing"),ze=new WeakMap,A=D.createTreeWalker(D,129);function Fe(i,e){if(!re(i)||!i.hasOwnProperty("raw"))throw Error("invalid template strings array");return ve!==void 0?ve.createHTML(e):e}var Xe=(i,e)=>{let t=i.length-1,n=[],r,o=e===2?"":e===3?"":"",a=x;for(let s=0;s"?(a=r??x,_=-1):m[1]===void 0?_=-2:(_=a.lastIndex-m[2].length,u=m[1],a=m[3]===void 0?S:m[3]==='"'?De:Ae):a===De||a===Ae?a=S:a===ye||a===Se?a=x:(a=S,r=void 0);let k=a===S&&i[s+1].startsWith("/>")?" ":"";o+=a===x?h+qe:_>=0?(n.push(u),h.slice(0,_)+Ee+h.slice(_)+v+k):h+v+(_===-2?s:k)}return[Fe(i,o+(i[t]||"")+(e===2?"":e===3?"":"")),n]},B=class i{constructor({strings:e,_$litType$:t},n){let r;this.parts=[];let o=0,a=0,s=e.length-1,h=this.parts,[u,m]=Xe(e,t);if(this.el=i.createElement(u,n),A.currentNode=this.el.content,t===2||t===3){let _=this.el.content.firstChild;_.replaceWith(..._.childNodes)}for(;(r=A.nextNode())!==null&&h.length0){r.textContent=K?K.emptyScript:"";for(let k=0;k2||n[0]!==""||n[1]!==""?(this._$AH=Array(n.length-1).fill(new String),this.strings=n):this._$AH=d}_$AI(e,t=this,n,r){let o=this.strings,a=!1;if(o===void 0)e=E(this,e,t,0),a=!W(e)||e!==this._$AH&&e!==z,a&&(this._$AH=e);else{let s=e,h,u;for(e=o[0],h=0;h{let n=t?.renderBefore??e,r=n._$litPart$;if(r===void 0){let o=t?.renderBefore??null;n._$litPart$=r=new P(e.insertBefore(H(),o),o,void 0,t??{})}return r._$AI(i),r};var oe=globalThis,y=class extends b{constructor(){super(...arguments),this.renderOptions={host:this},this._$Do=void 0}createRenderRoot(){let e=super.createRenderRoot();return this.renderOptions.renderBefore??=e.firstChild,e}update(e){let t=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(e),this._$Do=xe(t,this.renderRoot,this.renderOptions)}connectedCallback(){super.connectedCallback(),this._$Do?.setConnected(!0)}disconnectedCallback(){super.disconnectedCallback(),this._$Do?.setConnected(!1)}render(){return z}};y._$litElement$=!0,y.finalized=!0,oe.litElementHydrateSupport?.({LitElement:y});var Qe=oe.litElementPolyfillSupport;Qe?.({LitElement:y});(oe.litElementVersions??=[]).push("4.2.2");var et=(i,e,t={})=>i.callWS({type:`nextfloor/${e}`,...t}),He=i=>et(i,"building/get");var G=["light","cover","climate","media","switch","fan","lock","binary","sensor","tap","other"];var We=["body","wood","fabric","white","metal","dark"],Be={body:"#172238",wood:"#19233c",fabric:"#1a2644",white:"#1d2946",metal:"#2a3a60",dark:"#0b111f"};var $=["walls","floors","temperature","humidity","co2"];var ae={height:420,walls:"auto",solid_walls:!1,explode:!0,roof_fade:!0,quality:"auto",stats:!1,markers:"important",heatmap:"none",theme:"neon",energy:!0,room_panel:!0,room_buttons:!1,fill:!1,controls:!1,fullscreen_button:!1,room_names:!0,floor_stack:"dim",alerts:!0,alert_jump:!1,scenes:!0,announcements:!0,sensor_bar:!0,weather:!0,weather_density:1,idle_return:0,controls_hidden:!1,controls_hide_after:0,marker_names:!1,tap_in_room:!1,room_double_tap:"auto",central:!0,central_open:!1,keep_camera:!1,readable:!1,plain:!1,right_back:!1,today:!0,night:"off",idle_orbit:!1},tt=i=>i.target.value,O=i=>i.target.value,nt=i=>i.target.checked;function f(i,e,t,n,r){return l``}var Pe=V` + `}var Pe=U` :host { display: block; color: var(--primary-text-color); diff --git a/custom_components/nextfloor/frontend/nextfloor-editor.js b/custom_components/nextfloor/frontend/nextfloor-editor.js index ec8bc93..526a08c 100644 --- a/custom_components/nextfloor/frontend/nextfloor-editor.js +++ b/custom_components/nextfloor/frontend/nextfloor-editor.js @@ -1,7 +1,7 @@ /*! NextFloor, MIT licence. Includes three.js (MIT) and Lit (BSD-3-Clause); see LICENSE and THIRD_PARTY_NOTICES.md */ var S={cs:"4be67fcd522e",da:"0fe66a82bf2a",es:"bd89dffd1355",fi:"9a17bc084f56",fr:"6312d0f61ebf",hu:"27ba348531dc",it:"1b705e76dd00",nb:"c5ea24fb9ef6",nl:"b64142c67c2e",pl:"8527a4930402",pt:"31857a2d2277",ro:"e3cb5f449f0f",sk:"320611594db0",sl:"8071691ceda3",sv:"711b911ec8da",tr:"7c83ce1c3372",zh:"50518d9f494e"};var bo=globalThis,yo=bo.ShadowRoot&&(bo.ShadyCSS===void 0||bo.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,qi=Symbol(),Ll=new WeakMap,lr=class{constructor(e,n,r){if(this._$cssResult$=!0,r!==qi)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=e,this.t=n}get styleSheet(){let e=this.o,n=this.t;if(yo&&e===void 0){let r=n!==void 0&&n.length===1;r&&(e=Ll.get(n)),e===void 0&&((this.o=e=new CSSStyleSheet).replaceSync(this.cssText),r&&Ll.set(n,e))}return e}toString(){return this.cssText}},Cl=t=>new lr(typeof t=="string"?t:t+"",void 0,qi),se=(t,...e)=>{let n=t.length===1?t[0]:e.reduce((r,o,i)=>r+(s=>{if(s._$cssResult$===!0)return s.cssText;if(typeof s=="number")return s;throw Error("Value passed to 'css' function must be a 'css' function result: "+s+". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.")})(o)+t[i+1],t[0]);return new lr(n,t,qi)},Nl=(t,e)=>{if(yo)t.adoptedStyleSheets=e.map(n=>n instanceof CSSStyleSheet?n:n.styleSheet);else for(let n of e){let r=document.createElement("style"),o=bo.litNonce;o!==void 0&&r.setAttribute("nonce",o),r.textContent=n.cssText,t.appendChild(r)}},Yi=yo?t=>t:t=>t instanceof CSSStyleSheet?(e=>{let n="";for(let r of e.cssRules)n+=r.cssText;return Cl(n)})(t):t;var{is:Xg,defineProperty:Qg,getOwnPropertyDescriptor:Jg,getOwnPropertyNames:e_,getOwnPropertySymbols:t_,getPrototypeOf:n_}=Object,wo=globalThis,Bl=wo.trustedTypes,r_=Bl?Bl.emptyScript:"",o_=wo.reactiveElementPolyfillSupport,cr=(t,e)=>t,Xi={toAttribute(t,e){switch(e){case Boolean:t=t?r_:null;break;case Object:case Array:t=t==null?t:JSON.stringify(t)}return t},fromAttribute(t,e){let n=t;switch(e){case Boolean:n=t!==null;break;case Number:n=t===null?null:Number(t);break;case Object:case Array:try{n=JSON.parse(t)}catch{n=null}}return n}},Vl=(t,e)=>!Xg(t,e),Wl={attribute:!0,type:String,converter:Xi,reflect:!1,useDefault:!1,hasChanged:Vl};Symbol.metadata??=Symbol("metadata"),wo.litPropertyMetadata??=new WeakMap;var ft=class extends HTMLElement{static addInitializer(e){this._$Ei(),(this.l??=[]).push(e)}static get observedAttributes(){return this.finalize(),this._$Eh&&[...this._$Eh.keys()]}static createProperty(e,n=Wl){if(n.state&&(n.attribute=!1),this._$Ei(),this.prototype.hasOwnProperty(e)&&((n=Object.create(n)).wrapped=!0),this.elementProperties.set(e,n),!n.noAccessor){let r=Symbol(),o=this.getPropertyDescriptor(e,r,n);o!==void 0&&Qg(this.prototype,e,o)}}static getPropertyDescriptor(e,n,r){let{get:o,set:i}=Jg(this.prototype,e)??{get(){return this[n]},set(s){this[n]=s}};return{get:o,set(s){let l=o?.call(this);i?.call(this,s),this.requestUpdate(e,l,r)},configurable:!0,enumerable:!0}}static getPropertyOptions(e){return this.elementProperties.get(e)??Wl}static _$Ei(){if(this.hasOwnProperty(cr("elementProperties")))return;let e=n_(this);e.finalize(),e.l!==void 0&&(this.l=[...e.l]),this.elementProperties=new Map(e.elementProperties)}static finalize(){if(this.hasOwnProperty(cr("finalized")))return;if(this.finalized=!0,this._$Ei(),this.hasOwnProperty(cr("properties"))){let n=this.properties,r=[...e_(n),...t_(n)];for(let o of r)this.createProperty(o,n[o])}let e=this[Symbol.metadata];if(e!==null){let n=litPropertyMetadata.get(e);if(n!==void 0)for(let[r,o]of n)this.elementProperties.set(r,o)}this._$Eh=new Map;for(let[n,r]of this.elementProperties){let o=this._$Eu(n,r);o!==void 0&&this._$Eh.set(o,n)}this.elementStyles=this.finalizeStyles(this.styles)}static finalizeStyles(e){let n=[];if(Array.isArray(e)){let r=new Set(e.flat(1/0).reverse());for(let o of r)n.unshift(Yi(o))}else e!==void 0&&n.push(Yi(e));return n}static _$Eu(e,n){let r=n.attribute;return r===!1?void 0:typeof r=="string"?r:typeof e=="string"?e.toLowerCase():void 0}constructor(){super(),this._$Ep=void 0,this.isUpdatePending=!1,this.hasUpdated=!1,this._$Em=null,this._$Ev()}_$Ev(){this._$ES=new Promise(e=>this.enableUpdating=e),this._$AL=new Map,this._$E_(),this.requestUpdate(),this.constructor.l?.forEach(e=>e(this))}addController(e){(this._$EO??=new Set).add(e),this.renderRoot!==void 0&&this.isConnected&&e.hostConnected?.()}removeController(e){this._$EO?.delete(e)}_$E_(){let e=new Map,n=this.constructor.elementProperties;for(let r of n.keys())this.hasOwnProperty(r)&&(e.set(r,this[r]),delete this[r]);e.size>0&&(this._$Ep=e)}createRenderRoot(){let e=this.shadowRoot??this.attachShadow(this.constructor.shadowRootOptions);return Nl(e,this.constructor.elementStyles),e}connectedCallback(){this.renderRoot??=this.createRenderRoot(),this.enableUpdating(!0),this._$EO?.forEach(e=>e.hostConnected?.())}enableUpdating(e){}disconnectedCallback(){this._$EO?.forEach(e=>e.hostDisconnected?.())}attributeChangedCallback(e,n,r){this._$AK(e,r)}_$ET(e,n){let r=this.constructor.elementProperties.get(e),o=this.constructor._$Eu(e,r);if(o!==void 0&&r.reflect===!0){let i=(r.converter?.toAttribute!==void 0?r.converter:Xi).toAttribute(n,r.type);this._$Em=e,i==null?this.removeAttribute(o):this.setAttribute(o,i),this._$Em=null}}_$AK(e,n){let r=this.constructor,o=r._$Eh.get(e);if(o!==void 0&&this._$Em!==o){let i=r.getPropertyOptions(o),s=typeof i.converter=="function"?{fromAttribute:i.converter}:i.converter?.fromAttribute!==void 0?i.converter:Xi;this._$Em=o;let l=s.fromAttribute(n,i.type);this[o]=l??this._$Ej?.get(o)??l,this._$Em=null}}requestUpdate(e,n,r,o=!1,i){if(e!==void 0){let s=this.constructor;if(o===!1&&(i=this[e]),r??=s.getPropertyOptions(e),!((r.hasChanged??Vl)(i,n)||r.useDefault&&r.reflect&&i===this._$Ej?.get(e)&&!this.hasAttribute(s._$Eu(e,r))))return;this.C(e,n,r)}this.isUpdatePending===!1&&(this._$ES=this._$EP())}C(e,n,{useDefault:r,reflect:o,wrapped:i},s){r&&!(this._$Ej??=new Map).has(e)&&(this._$Ej.set(e,s??n??this[e]),i!==!0||s!==void 0)||(this._$AL.has(e)||(this.hasUpdated||r||(n=void 0),this._$AL.set(e,n)),o===!0&&this._$Em!==e&&(this._$Eq??=new Set).add(e))}async _$EP(){this.isUpdatePending=!0;try{await this._$ES}catch(n){Promise.reject(n)}let e=this.scheduleUpdate();return e!=null&&await e,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){if(!this.isUpdatePending)return;if(!this.hasUpdated){if(this.renderRoot??=this.createRenderRoot(),this._$Ep){for(let[o,i]of this._$Ep)this[o]=i;this._$Ep=void 0}let r=this.constructor.elementProperties;if(r.size>0)for(let[o,i]of r){let{wrapped:s}=i,l=this[o];s!==!0||this._$AL.has(o)||l===void 0||this.C(o,void 0,i,l)}}let e=!1,n=this._$AL;try{e=this.shouldUpdate(n),e?(this.willUpdate(n),this._$EO?.forEach(r=>r.hostUpdate?.()),this.update(n)):this._$EM()}catch(r){throw e=!1,this._$EM(),r}e&&this._$AE(n)}willUpdate(e){}_$AE(e){this._$EO?.forEach(n=>n.hostUpdated?.()),this.hasUpdated||(this.hasUpdated=!0,this.firstUpdated(e)),this.updated(e)}_$EM(){this._$AL=new Map,this.isUpdatePending=!1}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$ES}shouldUpdate(e){return!0}update(e){this._$Eq&&=this._$Eq.forEach(n=>this._$ET(n,this[n])),this._$EM()}updated(e){}firstUpdated(e){}};ft.elementStyles=[],ft.shadowRootOptions={mode:"open"},ft[cr("elementProperties")]=new Map,ft[cr("finalized")]=new Map,o_?.({ReactiveElement:ft}),(wo.reactiveElementVersions??=[]).push("2.1.2");var Ji=globalThis,Kl=t=>t,vo=Ji.trustedTypes,Gl=vo?vo.createPolicy("lit-html",{createHTML:t=>t}):void 0,es="$lit$",mt=`lit$${Math.random().toFixed(9).slice(2)}$`,ts="?"+mt,i_=`<${ts}>`,jt=document,ur=()=>jt.createComment(""),hr=t=>t===null||typeof t!="object"&&typeof t!="function",ns=Array.isArray,Xl=t=>ns(t)||typeof t?.[Symbol.iterator]=="function",Qi=`[ \f\r]`,dr=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,jl=/-->/g,Ul=/>/g,Kt=RegExp(`>|${Qi}(?:([^\\s"'>=/]+)(${Qi}*=${Qi}*(?:[^ -\f\r"'\`<>=]|("|')|))|$)`,"g"),Zl=/'/g,ql=/"/g,Ql=/^(?:script|style|textarea|title)$/i,rs=t=>(e,...n)=>({_$litType$:t,strings:e,values:n}),m=rs(1),R=rs(2),Ek=rs(3),Qe=Symbol.for("lit-noChange"),_=Symbol.for("lit-nothing"),Yl=new WeakMap,Gt=jt.createTreeWalker(jt,129);function Jl(t,e){if(!ns(t)||!t.hasOwnProperty("raw"))throw Error("invalid template strings array");return Gl!==void 0?Gl.createHTML(e):e}var ec=(t,e)=>{let n=t.length-1,r=[],o,i=e===2?"":e===3?"":"",s=dr;for(let l=0;l"?(s=o??dr,u=-1):d[1]===void 0?u=-2:(u=s.lastIndex-d[2].length,c=d[1],s=d[3]===void 0?Kt:d[3]==='"'?ql:Zl):s===ql||s===Zl?s=Kt:s===jl||s===Ul?s=dr:(s=Kt,o=void 0);let h=s===Kt&&t[l+1].startsWith("/>")?" ":"";i+=s===dr?a+i_:u>=0?(r.push(c),a.slice(0,u)+es+a.slice(u)+mt+h):a+mt+(u===-2?l:h)}return[Jl(t,i+(t[n]||"")+(e===2?"":e===3?"":"")),r]},pr=class t{constructor({strings:e,_$litType$:n},r){let o;this.parts=[];let i=0,s=0,l=e.length-1,a=this.parts,[c,d]=ec(e,n);if(this.el=t.createElement(c,r),Gt.currentNode=this.el.content,n===2||n===3){let u=this.el.content.firstChild;u.replaceWith(...u.childNodes)}for(;(o=Gt.nextNode())!==null&&a.length0){o.textContent=vo?vo.emptyScript:"";for(let h=0;h2||r[0]!==""||r[1]!==""?(this._$AH=Array(r.length-1).fill(new String),this.strings=r):this._$AH=_}_$AI(e,n=this,r,o){let i=this.strings,s=!1;if(i===void 0)e=Ut(this,e,n,0),s=!hr(e)||e!==this._$AH&&e!==Qe,s&&(this._$AH=e);else{let l=e,a,c;for(e=i[0],a=0;a{let r=n?.renderBefore??e,o=r._$litPart$;if(o===void 0){let i=n?.renderBefore??null;r._$litPart$=o=new bn(e.insertBefore(ur(),i),i,void 0,n??{})}return o._$AI(t),o};var os=globalThis,ne=class extends ft{constructor(){super(...arguments),this.renderOptions={host:this},this._$Do=void 0}createRenderRoot(){let e=super.createRenderRoot();return this.renderOptions.renderBefore??=e.firstChild,e}update(e){let n=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(e),this._$Do=nc(n,this.renderRoot,this.renderOptions)}connectedCallback(){super.connectedCallback(),this._$Do?.setConnected(!0)}disconnectedCallback(){super.disconnectedCallback(),this._$Do?.setConnected(!1)}render(){return Qe}};ne._$litElement$=!0,ne.finalized=!0,os.litElementHydrateSupport?.({LitElement:ne});var a_=os.litElementPolyfillSupport;a_?.({LitElement:ne});(os.litElementVersions??=[]).push("4.2.2");var Je=(t,e,n={})=>t.callWS({type:`nextfloor/${e}`,...n});async function Ro(t,e){return(await Je(t,"image/get",{image_id:e})).data}async function St(t,e,n){await Je(t,"image/set",{image_id:e,data:n})}async function rc(t){return(await Je(t,"history/list")).snapshots}async function oc(t,e){return(await Je(t,"history/snapshot",e?{name:e}:{})).id}async function ic(t,e){return(await Je(t,"history/get",{snapshot_id:e})).building}async function sc(t,e){await Je(t,"history/delete",{snapshot_id:e})}async function ac(t,e){return(await Je(t,"history/restore",{snapshot_id:e})).revision}var fr=(t,e)=>Je(t,"packs/import",{pack:e});async function lc(t,e){await Je(t,"packs/remove",{pack_id:e})}var cc=t=>Je(t,"backup/export"),dc=(t,e,n)=>Je(t,"backup/import",{building:e,packs:n});var ss=t=>t.slice(0,t.indexOf(".")),l_={light:"light",switch:"switch",input_boolean:"switch",valve:"switch",fan:"fan",cover:"cover",climate:"climate",media_player:"media",lock:"lock",sensor:"sensor",binary_sensor:"binary",event:"sensor",scene:"scene",script:"script"},X=t=>l_[ss(t)]??null,as=["light","cover","climate","media","switch","fan","lock","binary","sensor","scene","script"];var uc=new Set(["light","switch","fan"]),Mt=t=>t!==null&&t!=="scene"&&t!=="script",Rt=t=>!t||t.state==="unavailable"||t.state==="unknown"&&!t.entity_id.startsWith("event.");function W(t,e,n){let r=String(t?.states[e]?.attributes.friendly_name??t?.entities?.[e]?.name??e);if(!n||r.length<=n.length+1||!r.toLowerCase().startsWith(`${n.toLowerCase()} `))return r;let o=r.slice(n.length+1);return o[0].toUpperCase()+o.slice(1)}var hc=t=>!!t&&t.entity_id.startsWith("sensor.")&&t.attributes.device_class==="enum";var pc=t=>Math.min(1,Math.max(0,t));function c_(t){let e=pc((t-2200)/4300),n=[1,.66,.26],r=[.78,.9,1];return[0,1,2].map(o=>n[o]+(r[o]-n[o])*e)}function is(t,e){if(!t||t.state!=="on")return null;let n=e&&!["unavailable","unknown"].includes(e.state)?e.attributes:t.attributes,r=typeof n.brightness=="number"?.2+.8*Math.sqrt(pc(n.brightness/255)):1,o=n.rgb_color;return o&&!["color_temp","brightness","onoff"].includes(String(n.color_mode))?{color:[o[0]/255,o[1]/255,o[2]/255],level:r}:typeof n.color_temp_kelvin=="number"?{color:c_(n.color_temp_kelvin),level:r}:{color:[1,.71,.28],level:r}}function fc(t,e,n){let r=is(t,n);if(r)return r;for(let o of e){let i=is(o);if(i)return{color:i.color,level:i.level*.6}}return null}function Eo(t,e,n=null){if(t==="light"&&n==="floor")return 1.95;if(t==="light"&&n==="table")return 1.25;if(t==="light"&&n==="wall")return 1.95;switch(t){case"light":return Math.max(.5,e-.25);case"cover":return Math.min(2,e-.3);case"climate":return .6;case"media":return .9;case"binary":case"sensor":return 1.4;default:return 1.05}}var bc=[],Ao=new Map,d_=0,ue=(t,e)=>`pack:${t}:${e}`,gt=t=>t.startsWith("pack:");function ls(t){bc=t,Ao=new Map;for(let e of t)for(let n of e.items)Ao.set(ue(e.id,n.id),n);d_+=1}var gr=()=>bc;var u_={};function G(t){if(!gt(t))return;let e=Ao.get(t);if(e)return e;let[,n,...r]=t.split(":"),o=u_[n];return o?Ao.get(ue(o,r.join(":"))):void 0}var h_=.22;function mc(t,e,n,r){let o=Math.min(h_,n/3);if(r<=o*2.4||Math.abs(r-n)<1e-6)return e*(r/n)+(t-e)*(r/n);let i=e*(r/n),s=t-e;return s<=o?i+s:s>=n-o?i+r-(n-s):i+o+(s-o)*(r-2*o)/(n-2*o)}function mr(t,e,n,r,o){return[mc(t*r,n*r,r,o)/o,mc(e*r,n*r,r,o)/o]}var gc=new WeakMap;function yc(t,e,n,r){let[o,i,s]=t.size;if(t.vehicle||t.stretch||Math.abs(e-o)<1e-4&&Math.abs(n-i)<1e-4&&Math.abs(r-s)<1e-4)return t.parts;let l=`${e.toFixed(4)}|${n.toFixed(4)}|${r.toFixed(4)}`,a=gc.get(t),c=a?.get(l);if(c)return c;let d=t.parts.map(u=>{if(u.shape==="sweep")return u;let[p,h]=mr(u.x-u.w/2,u.x+u.w/2,-.5,o,e),[f,g]=mr(u.z-u.d/2,u.z+u.d/2,-.5,i,n),[y,b]=mr(u.y,u.y+u.h,0,s,r);if(u.rot)return{...u,x:(p+h)/2,z:(f+g)/2,w:u.w*o/e,d:u.d*i/n,y,h:b-y};let v={...u,x:(p+h)/2,z:(f+g)/2,w:h-p,d:g-f,y,h:b-y};if(u.shape==="loft"){let[w,x,k,$]=[u.tx??u.x,u.tz??u.z,u.tw??u.w,u.td??u.d],[A,F]=mr(w-k/2,w+k/2,-.5,o,e),[T,I]=mr(x-$/2,x+$/2,-.5,i,n);Object.assign(v,{tx:(A+F)/2,tz:(T+I)/2,tw:F-A,td:I-T})}return v});return a||gc.set(t,a=new Map),a.size>32&&a.clear(),a.set(l,d),d}var cs=t=>!!t?.parts.some(e=>e.move);var wc=t=>G(t)?.parts.find(e=>e.screen),_c=.06;function vc(t){let e=G(t);if(!e)return!1;let[n,r,o]=e.size;return e.parts.filter(i=>i.screen).some(i=>{let[s,l]=[i.w*n,i.d*r,i.h*o].sort((a,c)=>c-a);return l>=_c&&s>=_c})}function at(t){return et[t]??G(t)?.size??[.6,.6,.8]}function Et(t){let e=G(t);return Ac.has(t)||!!e?.electric||!!e?.light||!!e?.climate}var kc=t=>!!G(t)?.parts.some(e=>e.picture),yn=t=>!!G(t)?.climate;function xc(t,e){return t.name[e.split("-")[0]]??t.name.en??Object.values(t.name)[0]??t.id}var p_={wohnen:"Living & Pets",kino:"Home Cinema & Gaming",kueche:"Kitchen Extras",bad:"Bathroom Extras",schlafen:"Bedroom & Kids",technik:"Office & Homelab",energie:"Energy & Building Services",garten:"Garden & Terrace (older)",fitness:"Fitness (older)",fahrzeuge:"Vehicles",ikea:"IKEA sizes",treppen:"Stairs & railings",ausbau:"Architecture & fit-out",werkstatt:"Garage & workshop",a_wohnzimmer:"Living room",a_schlafzimmer:"Bedroom",a_kueche:"Kitchen",a_bad:"Bathroom",a_kinderzimmer:"Kids' room",a_buero:"Office & gaming",a_fitness:"Fitness",a_haustiere:"Pets",a_garten:"Garden & patio",a_kino:"Home cinema & hi-fi",a_smart:"Smart home & tech",a_haustechnik:"Utility & building services",a_saison:"Season & decoration",a_smart2:"Smart home 2",a_haustechnik2:"Building services 2",a_wellness:"Wellness",a_garten2:"Garden 2",a_kueche2:"Kitchen 2",a_fahrzeuge2:"Vehicles 2",a_aussenkueche:"Outdoor kitchen & terrace",a_werkstatt2:"Workshop 2",a_japandi:"Japandi & Scandi",a_loft:"Loft & industrial",a_gruen:"Indoor greenery",a_musik:"Music & studio",a_bilder:"Pictures & frames"};function $c(t,e){if(e.split("-")[0]==="de")return t.name;let n=/^nextfloor\.(.+)$/.exec(t.id)?.[1];return n&&p_[n]||t.name}function At(t,e){return e.mount_y!=null?e.mount_y:m_(t,e)+(f_(e)?0:Rc(t,e.x,e.z))}var f_=t=>t.type==="led_strip"||G(t.type)?.mount==="ceiling";function m_(t,e){if(e.type==="lamp_wall")return Sc;if(e.type==="led_strip")return Math.max(0,lt(t,e.x,e.z)-.04-Math.max(.02,e.h));let n=G(e.type);if(!n)return Mc(e);switch(n.mount){case"surface":return Ec(t,e.x,e.z);case"wall":return n.wall_y??1;case"ceiling":return Math.max(0,Fo(t,e)-e.h);default:return 0}}function ds(t){if(t==="plant")return"plant";let e=G(t);return e?e.household?e.household:/monstera|plant|herb_garden|flower_pots|bonsai|ficus|cactus|kaktus/.test(e.id)?"plant":null:null}var Fc=["turn","slide","top"],Tc=["always","active","no_power","never"],zc=1.3,To=(t,e=new Date().toISOString().slice(0,10))=>!!t.due&&t.due<=e,Pc=["gable","hip","halfhip","pyramid","mansard","pent","flat","parapet"],Ic=["brick","round","wide","steel"],zo=["navigate","more_info","service","fire_dom_event"];function Po(t,e,n){return t?e?!!n.lock_plan:!!t.locked:!1}var Dc=["rain","snow","fog","clouds","lightning","sky"],Oc=["rain","snow","clouds","lightning","sky"],Hc=["lawn","terrace","path","driveway","pool","bed","wild","hedge","fence","pergola"],us={lawn:.012,terrace:.12,path:.02,driveway:.02,pool:-.25,bed:.15,wild:.03,hedge:1.2,fence:1,pergola:2.2};function hs(t){return t==="hedge"||t==="fence"||t==="pergola"}var Lc=["x","-x","z","-z"];function g_(t,e,n){let r=t.slope??0;if(!r||t.type==="pool")return 0;let o=t.slope_dir??"x",i=(c,d)=>o==="x"?c:o==="-x"?-c:o==="z"?d:-d,s=1/0,l=-1/0;for(let[c,d]of t.points){let u=i(c,d);s=Math.min(s,u),l=Math.max(l,u)}if(l-s<1e-6)return 0;let a=Math.min(1,Math.max(0,(i(e,n)-s)/(l-s)));return r*a}function __(t,e,n,r){return Cc(t)+(e.offset??0)+us[e.type]-g_(e,n,r)}function Cc(t){return t.elevation>.3?0:-.2}function Nc(t,e,n){let r=(t.outdoor??[]).filter(i=>!hs(i.type)&&i.type!=="pool"&&N([e,n],i.points)),o=[...r].reverse().find(i=>i.cut)??r[0];return o?__(t,o,e,n):Cc(t)}var Bc=t=>t.cut??t.type==="pool",Wc=30,Vc={meter:null,grid:null,grid_invert:!1,solar:null,battery:null,battery_invert:!1,battery_soc:null,consumption:null,tariff:null},Kc=["wood","oak","tiles","carpet","stone","concrete"],Gc={type:"none",pitch:35,overhang:.4},Io="#d6cfc2",Do="#e8e3da",jc={wall_exterior:.24,wall_interior:.12,grid:.05,north:0,roof:{...Gc}};function Ft(){return{version:1,floors:[],settings:{...jc},energy:{...Vc},presence:[]}}function Le(t,e,n){return{id:t,name:e,elevation:n,height:2.5,cut_height:1.15,rooms:[],openings:[],furniture:[],placements:[],background:null,outdoor:[],walls:[],ha_floor:null}}var b_=2.75;function Uc(t,e){if(e!=null&&Number.isFinite(e))return Math.round(e*b_*100)/100;let n=t.reduce((r,o)=>!r||o.elevation>r.elevation?o:r,null);return n?Math.round((n.elevation+n.height+.25)*100)/100:0}function Zc(t,e,n){let r=t.rooms.flatMap(l=>l.points.map(a=>a[0])),o=t.rooms.flatMap(l=>l.points.map(a=>a[1])),i=r.length?Math.ceil(Math.max(...r))+1:0,s=o.length?Math.floor(Math.min(...o)):0;return e.map((l,a)=>{let c=i+a%3*4.5,d=s+Math.floor(a/3)*3.5;return{id:n(),name:l.name,area_id:l.area_id,points:[[c,d],[c+4,d],[c+4,d+3],[c,d+3]],floor_material:"wood"}})}function qc(t,e,n,r){let o=t.rotation*Math.PI/180,i=Math.cos(o),s=Math.sin(o),[l,a]=e,c=t.x-l*(t.w/2)*i+a*(t.d/2)*s,d=t.z-l*(t.w/2)*s-a*(t.d/2)*i,u=n[0]-c,p=n[1]-d,h=b=>Math.max(.1,Math.round(b/r)*r),f=h((u*i+p*s)*l),g=h((-u*s+p*i)*a),y=b=>Math.round(b*1e3)/1e3;return{x:y(c+l*(f/2)*i-a*(g/2)*s),z:y(d+l*(f/2)*s+a*(g/2)*i),w:y(f),d:y(g)}}var Oo=["lamp_ceiling","lamp_downlight","lamp_spot","lamp_panel","lamp_pendant","ceiling_fan","lamp_floor","lamp_table","lamp_wall","led_strip","lamp_uplight","lamp_bollard","lamp_garden","radiator","sofa","armchair","stool","coffee_table","tv_board","tv_wall","sideboard","shelf","plant","rug","table","table_round","chair","bench","corner_bench","bar_stool","kitchen","kitchen_wall","kitchen_tall","island","worktop","sink","stove","dishwasher","fridge","bed","bunk_bed","nightstand","wardrobe","dresser","bathtub","shower","wc","washbasin","washer","dryer","desk","office_chair","tall_cabinet","coat_rack","stairs","robot_vacuum","inverter","home_battery","wallbox","meter","grid_point","parking","fridge_smart","stairwell"],Yc={lights:["lamp_ceiling","lamp_downlight","lamp_spot","lamp_panel","lamp_pendant","ceiling_fan","lamp_floor","lamp_uplight","lamp_table","lamp_wall","led_strip","lamp_bollard","lamp_garden"],living:["sofa","armchair","stool","coffee_table","tv_board","tv_wall","sideboard","shelf","plant","rug"],dining:["table","table_round","chair","bench","corner_bench","bar_stool"],kitchen:["kitchen","kitchen_wall","kitchen_tall","island","worktop","sink","stove","dishwasher","fridge"],sleeping:["bed","bunk_bed","nightstand","wardrobe","dresser"],bath:["bathtub","shower","wc","washbasin","washer","dryer"],work:["desk","worktop","office_chair","tall_cabinet","coat_rack","radiator","stairs","robot_vacuum"],vehicles:["parking"]},Ce=["meter","inverter","home_battery","wallbox","grid_point"],Xc=new Set(["lamp_ceiling","lamp_downlight","lamp_spot","lamp_panel","lamp_pendant","ceiling_fan","lamp_floor","lamp_uplight","lamp_table","lamp_wall","led_strip","lamp_bollard","lamp_garden"]),Sc=1.75;function Ho(t){return ps.has(t.type)||["stairwell","parking"].includes(t.type)?!1:G(t.type)?.mount!=="ceiling"}function ce(t){return Xc.has(t)||!!G(t)?.light}var y_=new Set(["table","table_round","coffee_table","desk","nightstand","sideboard","dresser","kitchen","island","worktop","tv_board","dishwasher","washer","dryer"]);function Qc(t,e,n,r=0){let o=de(t.points),i=o.x1-o.x0-2*r,s=o.z1-o.z0-2*r,l=[];for(let a=0;aMath.round(s*1e3)/1e3,[o,i]={right:[1,0],down:[0,1],left:[-1,0],up:[0,-1]}[n];return[r(t[0]+o*e),r(t[1]+i*e)]}function Mc(t){switch(t.type){case"home_battery":return t.variant==="wall"?.5:0;case"kitchen_wall":return 1.45;case"tv_wall":return Math.max(0,1.3-t.h/2);case"radiator":return .12;case"inverter":return 1.1;case"wallbox":return 1;case"meter":return .4;default:return 0}}var ps=new Set(["lamp_ceiling","lamp_downlight","lamp_spot","lamp_panel","lamp_pendant","ceiling_fan"]);function Jc(t,e){return t.filter(n=>n.elevationn.rooms.filter(r=>r.points.length>=3&&r.ceiling!=null&&r.ceiling>n.height+.005&&n.elevation+r.ceiling>e.elevation+.05)).map(n=>n.points)}var fs=t=>t?.floor_offset&&Number.isFinite(t.floor_offset)?t.floor_offset:0;function Rc(t,e,n){let r=t.rooms.find(o=>o.points.length>=3&&o.floor_offset&&N([e,n],o.points));return fs(r)}function lt(t,e,n){let r=t.rooms.find(o=>o.points.length>=3&&N([e,n],o.points));return r?.ceiling!=null&&r.ceiling>0?r.ceiling:t.height}var Fo=(t,e)=>e.ceiling_y!=null&&e.ceiling_y>0?e.ceiling_y:lt(t,e.x,e.z);function Ec(t,e,n){let r=0;for(let o of t.furniture)!(y_.has(o.type)||G(o.type)?.surface)||!N([e,n],bs(o))||(r=Math.max(r,o.h));return r}var Ac=new Set([...Xc,"radiator","robot_vacuum","inverter","home_battery","wallbox","meter","tv_board","tv_wall","desk","fridge","fridge_smart","stove","kitchen_tall","dishwasher","washer","dryer","kitchen","island","sink"]),et={sofa:[2.2,.9,.82],armchair:[.85,.85,.8],table:[1.6,.9,.75],chair:[.46,.5,.9],bed:[1.6,2.05,.9],nightstand:[.45,.4,.5],wardrobe:[1.8,.6,2.1],shelf:[.9,.35,1.9],kitchen:[2.4,.62,.92],worktop:[1.2,.62,.91],inverter:[.5,.2,.65],home_battery:[.6,.25,1.1],wallbox:[.3,.15,.42],meter:[.55,.21,1.1],grid_point:[.4,.22,.6],fridge:[.6,.65,1.8],fridge_smart:[.91,.73,1.78],stairwell:[1,2.6,.02],stove:[.6,.62,.92],sink:[.9,.62,.92],bathtub:[1.7,.75,.58],shower:[.9,.9,2],wc:[.38,.6,.8],washbasin:[.6,.46,.85],desk:[1.4,.7,.75],tv_board:[1.8,.42,.5],plant:[.45,.45,1.1],rug:[2,1.4,.01],stairs:[1,3.2,2.75],stool:[.55,.55,.42],lamp_ceiling:[.4,.4,.08],lamp_downlight:[.1,.1,.02],lamp_spot:[.1,.1,.14],lamp_panel:[.6,.6,.03],lamp_uplight:[.35,.35,1.8],lamp_bollard:[.16,.16,.8],lamp_garden:[.12,.12,.3],radiator:[1,.1,.6],robot_vacuum:[.36,.5,.1],parking:[2.6,5.2,.02],lamp_pendant:[.4,.4,.8],ceiling_fan:[1.32,1.32,.32],lamp_floor:[.4,.4,1.7],lamp_table:[.28,.28,.45],lamp_wall:[.22,.12,.2],led_strip:[2,.04,.03],coffee_table:[1.1,.6,.42],tv_wall:[1.3,.08,.75],sideboard:[1.6,.45,.8],table_round:[1.1,1.1,.75],bench:[1.4,.45,.85],corner_bench:[2,1.6,.9],bar_stool:[.42,.42,.75],kitchen_wall:[.8,.35,.7],kitchen_tall:[.6,.62,2.1],island:[1.8,.9,.92],dishwasher:[.6,.62,.92],bunk_bed:[1,2.05,1.65],dresser:[1,.5,.9],washer:[.6,.6,.85],dryer:[.6,.6,.85],office_chair:[.65,.65,1.1],tall_cabinet:[.6,.6,2.1],coat_rack:[1,.35,1.9]};var ms=["interior","front","front_glass","sidelight","sidelights","glass","sliding","passage"],gs=["standard","bars","glass_wall"],Lo=new Set(["interior","front"]);function qt(t,e){return t.type==="door"?t.style&&ms.includes(t.style)?t.style:e?"front":"interior":t.style&&gs.includes(t.style)?t.style:"standard"}function ed(t,e,n,r){if(e!=="sidelight"&&e!=="sidelights")return null;let o=e==="sidelights",i=t-.04,s=Math.min(1.05,Math.max(.6,i-(o?.6:.3))),l=(i-s)/(o?2:1),a=r.sidelight_width??l,c=o?r.sidelight_width2??r.sidelight_width??l:0;a=Math.max(.1,a),c=o?Math.max(.1,c):0;let d=i-.5;if(a+c>d){let p=Math.max(0,d)/(a+c);a*=p,c*=p}return o?{panels:[[.02,.02+a],[t-.02-c,t-.02]],x0:.02+a,x1:t-.02-c}:(n?!!r.sidelight_hinge:!r.sidelight_hinge)?{panels:[[.02,.02+a]],x0:.02+a,x1:t-.02}:{panels:[[t-.02-a,t-.02]],x0:.02,x1:t-.02-a}}function _s(t){return t==="front"||t==="front_glass"||t==="sidelight"||t==="sidelights"}var vn={door:{type:"door",leaves:1,width:.9,sill:0,height:2.05,style:"interior"},front:{type:"door",leaves:1,width:1,sill:0,height:2.1,style:"front"},door_double:{type:"door",leaves:2,width:1.6,sill:0,height:2.05},window:{type:"window",leaves:1,width:1.2,sill:.9,height:1.3},window_double:{type:"window",leaves:2,width:1.6,sill:.9,height:1.3},terrace:{type:"window",leaves:1,width:1,sill:0,height:2.1},terrace_double:{type:"window",leaves:2,width:1.8,sill:0,height:2.1},lift_slide:{type:"window",leaves:1,width:2.4,sill:0,height:2.15,opens:"slide"},garage:{type:"garage",leaves:1,width:2.5,sill:0,height:2.1},glass_wall:{type:"window",leaves:1,width:2,sill:0,height:2.4,style:"glass_wall"}};function kn(t){if(t.type==="garage")return"garage";if(t.type==="window"&&t.style==="glass_wall")return"glass_wall";if(t.type==="window"&&t.opens==="slide"&&t.sill<.1)return"lift_slide";let e=t.leaves===2;return t.type==="door"?!e&&t.style&&_s(t.style)?"front":e?"door_double":"door":t.sill<.1?e?"terrace_double":"terrace":e?"window_double":"window"}function ze(t){t.energy={...Vc,...t.energy??{}},t.presence=t.presence??[],t.version=1,t.settings={...jc,...t.settings,roof:{...Gc,...t.settings?.roof??{}}},t.floors.forEach((e,n)=>{let r=Le(e.id,e.name??`Floor ${n+1}`,e.elevation??n*2.8);for(let o of Object.keys(r))e[o]===void 0&&(e[o]=r[o])});for(let e of t.floors){e.outdoor=e.outdoor??[],e.walls=e.walls??[],e.rooms=e.rooms.map(r=>({...r,name:r.name??"",area_id:r.area_id??null,floor_material:r.floor_material??"wood",panel:r.panel??[]})),e.ha_floor=e.ha_floor??null,e.placements=e.placements.map(r=>({...r,mount:r.mount??null,rotation:r.rotation??0})),e.furniture=e.furniture.map(r=>({...r,entity:r.entity??null,power:r.power??null}));let n=e.placements.filter(r=>r.entity_id.startsWith("light."));if(n.length){let r={ceiling:"lamp_ceiling",floor:"lamp_floor",table:"lamp_table",wall:"lamp_wall"};for(let o of n){let i=r[o.mount??"ceiling"],[s,l,a]=et[i],c=`lamp_${o.entity_id.slice(6).replace(/[^A-Za-z0-9_\-.]/g,"_")}`.slice(0,54),d=c,u=1;for(;e.furniture.some(p=>p.id===d);)d=`${c}_${u++}`;e.furniture.push({id:d,type:i,x:o.x,z:o.z,rotation:0,w:s,d:l,h:a,variant:null,entity:o.entity_id,power:null,animations_enabled:o.animations_enabled,effect_animations:structuredClone(o.effect_animations)})}e.placements=e.placements.filter(o=>!o.entity_id.startsWith("light."))}e.openings=e.openings.map(r=>({...r,type:["door","window","garage"].includes(r.type)?r.type:"door",edge:Number.isInteger(r.edge)?r.edge:0,offset:Number.isFinite(r.offset)?r.offset:.5,width:Number.isFinite(r.width)&&r.width>0?r.width:r.type==="garage"?2.5:r.type==="window"?1.2:.9,height:Number.isFinite(r.height)&&r.height>0?r.height:r.type==="window"?1.3:r.type==="garage"?2.1:2.05,sill:Number.isFinite(r.sill)?r.sill:r.type==="window"?.9:0,hinge:r.hinge??"left",leaves:r.leaves??1,swing:r.swing??"in",style:r.style??null,cover:r.cover??null,contact:r.contact??null,contact2:r.contact2??null,tilt:r.tilt??null}))}return w_(t),t}function w_(t){let e=(n,r)=>{let o=new Set;for(let i of n)(typeof i.id!="string"||!i.id||o.has(i.id))&&(i.id=D(r)),o.add(i.id)};e(t.floors,"floor");for(let n of t.floors){for(let r of n.rooms)(typeof r.id!="string"||!r.id)&&(r.id=D("room"));e(n.openings,"op"),e(n.furniture,"furn"),e(n.outdoor,"out")}}function D(t){return`${t}_${Math.random().toString(36).slice(2,10)}`}function ge(t){let e=0;for(let n=0;ni+s[0],0)/o,t.reduce((i,s)=>i+s[1],0)/o]}let n=0,r=0;for(let o=0;o1e-6&&Math.abs(r-i)>1e-6)return!1}return!0}function de(t){let e=1/0,n=1/0,r=-1/0,o=-1/0;for(let[i,s]of t)e=Math.min(e,i),n=Math.min(n,s),r=Math.max(r,i),o=Math.max(o,s);return{x0:e,z0:n,x1:r,z1:o}}function bs(t){let e=t.rotation*Math.PI/180,n=Math.cos(e),r=Math.sin(e),o=t.w/2,i=t.d/2;return[[-o,-i],[o,-i],[o,i],[-o,i]].map(([s,l])=>[t.x+s*n-l*r,t.z+s*r+l*n])}function N(t,e){let n=!1;for(let r=0,o=e.length-1;rt[1]!=a>t[1]&&t[0]<(l-i)*(t[1]-s)/(a-s)+i&&(n=!n)}return n}var Co={lamp_ceiling:"ceiling",lamp_downlight:"downlight",lamp_spot:"spot",lamp_panel:"panel",lamp_uplight:"uplight",lamp_bollard:"bollard",lamp_garden:"garden",lamp_pendant:"pendant",ceiling_fan:"fan",lamp_floor:"floor",lamp_table:"table",lamp_wall:"wall",led_strip:"strip"};var ys=t=>t.trim().replace(/^\/local\/www\//i,"/local/"),ws=t=>/^(https:\/\/|\/local\/|\/hacsfiles\/)\S+\.m?js(\?\S*)?$/i.test(t.trim());var k_=globalThis,nd=k_.__nextfloorPluginStore??={plugins:new Map,listeners:new Set},vs=nd.plugins,td=nd.listeners;var x_=5;function rd(t,e){t.errors.lengthtd.delete(t)}var ks=()=>[...vs.values()].map(t=>t.status),od=()=>[...vs.values()].flatMap(t=>Object.keys(t.plugin.lightAnimations??{}));function*Bo(t,e){for(let{plugin:n,status:r}of vs.values())for(let o of n.devices??[]){let i=!1;try{i=o.match(t,e)}catch(s){rd(r,s)}i&&(yield{device:o,status:r})}}function Wo(t,e){for(let{device:n}of Bo(t,e))return n.kind??"sensor";return null}function id(t,e){let n=t.states[e];if(!n)return null;let r=$_({hass:t,entityId:e,state:n})?.icon?.trim();return r&&/^mdi:[a-z0-9-]+$/i.test(r)?r:null}function $_(t){let e=null;for(let{device:n,status:r}of Bo(t.entityId,t.state))if(n.marker)try{let o=n.marker(t);if(!o)continue;e={...e??{}},typeof o.icon=="string"&&o.icon&&(e.icon=o.icon),typeof o.text=="string"&&(e.text=o.text.slice(0,60)),typeof o.active=="boolean"&&(e.active=o.active)}catch(o){rd(r,o)}return e}function Vo(t,e){return t?typeof t=="string"?t:t[e]??t[e.split("-")[0]]??t.en??Object.values(t)[0]??"":""}function sd(t,e){let n=[];for(let{device:r,status:o}of Bo(t,e))r.settings?.length&&n.push({pluginId:o.id,name:o.name,settings:r.settings});return n}function ad(t,e){let n={};for(let r of t??[]){let o=e?.[r.key],i=r.type==="number"?typeof o=="number"&&Number.isFinite(o):r.type==="boolean"?typeof o=="boolean":typeof o=="string"&&(r.options??[]).some(([s])=>s===o);n[r.key]=i?o:r.default}return n}function ld(t,e){for(let{device:n}of Bo(t,e))if(n.floorWedge)return!0;return!1}var S_=new Set(["temperature","humidity","power","carbon_dioxide","energy","gas","water","volume","volume_storage","volume_flow_rate","illuminance","pressure","atmospheric_pressure","pm1","pm25","pm10","volatile_organic_compounds","volatile_organic_compounds_parts","carbon_monoxide","nitrogen_dioxide","moisture","sound_pressure"]),M_=new Set(["m\xB3","m3","L","l","kWh","Wh","MWh","lx"]),R_=new Set(["door","window","opening","garage_door","motion","occupancy","presence","smoke","moisture","gas","carbon_monoxide"]),E_=new Set(["battery","signal_strength","timestamp","date","duration","data_rate","data_size","frequency","enum"]);function Tt(t,e){let n=t.entities?.[e];return n&&(n.area_id||(n.device_id?t.devices?.[n.device_id]?.area_id:null))||null}var dd=(t,e)=>{let n=t.entities?.[e];return!!(n?.hidden||n?.entity_category)},Ne=(t,e)=>X(e)??Wo(e,t.states[e]);function cd(t,e){let n=t.states[e];if(!n||dd(t,e))return!1;if(Wo(e,n)!==null)return!0;let r=X(e);if(!r)return!1;let o=n.attributes.device_class;return e.startsWith("event.")?!o||o==="button"||o==="doorbell":r==="sensor"?o?S_.has(o):M_.has(String(n.attributes.unit_of_measurement??"")):r==="binary"?o?R_.has(o):!!t.entities?.[e]?.area_id:!0}function A_(t,e){let n=t.states[e];return X(e)!=="sensor"||!n?.attributes.unit_of_measurement||dd(t,e)||E_.has(String(n.attributes.device_class??""))?!1:Number.isFinite(Number(n.state))||Rt(n)}var Go=(t,e)=>e.startsWith("sensor.")&&t.states[e]?.attributes.device_class==="power",xs=null;No(()=>xs=null);function $s(t,e){let n=t.get(e);return n||t.set(e,n=[]),n}function F_(t){let e=new Map,n=new Map,r=new Map,o=new Map,i=[],s=d=>{(cd(t,d)||A_(t,d))&&Mt(Ne(t,d))&&i.push(d)};for(let[d,u]of Object.entries(t.entities??{})){let p=u.device_id;p&&u.area_id&&(o.get(p)??o.set(p,new Set).get(p)).add(u.area_id),p&&Go(t,d)&&$s(n,p).push(d),p&&!u.hidden&&!u.entity_category&&(r.get(p)??r.set(p,new Set).get(p)).add(ss(d));let h=Tt(t,d);h===null?s(d):cd(t,d)&&$s(e,h).push(d)}if(t.entities)for(let d of Object.keys(t.states))t.entities[d]||s(d);let l=as.indexOf("binary")-.5,a=d=>{let u=X(d),p=u?as.indexOf(u):l;return p>l&&Wo(d,t.states[d])!==null?l:p};i.sort((d,u)=>a(d)-a(u)||W(t,d).localeCompare(W(t,u)));for(let[d,u]of e){let p=t.areas?.[d]?.name;u.sort((h,f)=>a(h)-a(f)||W(t,h,p).localeCompare(W(t,f,p)))}let c=new Set;for(let[d,u]of o)u.size>1&&c.add(d);return{entities:t.entities,devices:t.devices,states:t.states,stateCount:Object.keys(t.states).length,byArea:e,powerByDevice:n,withoutArea:i,domainsByDevice:r,hubs:c}}function $n(t){let e=xs;return e&&e.entities===t.entities&&e.devices===t.devices&&(e.states===t.states||(e.states=t.states,Object.keys(t.states).length===e.stateCount))?e:xs=F_(t)}function be(t,e){let n=Ko(t,e.area_id);return e.sub_areas?.length?[...new Set([...n,...e.sub_areas.flatMap(r=>Ko(t,r))])]:n}function Ko(t,e){return!e||!t.entities?[]:$n(t).byArea.get(e)??[]}function ud(t,e){if(!t.entities)return[];let n=[];for(let[r,o]of $n(t).byArea){let i=o.filter(s=>Mt(Ne(t,s)));r!==e&&i.length>0&&n.push({areaId:r,name:t.areas?.[r]?.name??r,ids:i})}return n.sort((r,o)=>r.name.localeCompare(o.name))}var hd=t=>t.entities?$n(t).withoutArea:[],Ss=(t,e)=>!!t.entities&&$n(t).hubs.has(e),jo=(t,e)=>t.entities?$n(t).powerByDevice.get(e)??[]:[];function Sn(t,e){let n=new Map;for(let o of e)$s(n,t.entities?.[o]?.device_id??`entity:${o}`).push(o);let r=new Map(e.map((o,i)=>[o,i]));return[...n.values()].map(o=>{let i=o.find(s=>!t.entities?.[s]?.name)??o[0];return{primary:i,others:o.filter(s=>s!==i)}}).sort((o,i)=>r.get(o.primary)-r.get(i.primary))}var Uo=(t,e)=>Sn(t,e).map(n=>n.primary),Ms={temperature:"temperature",humidity:"humidity",co2:"carbon_dioxide"},T_=new Set(["climate","water_heater","switch","button","camera","media_player","vacuum","light","fan","lawn_mower"]),z_=["vorlauf","r(\xFC|ue)cklauf","flow","return","d(\xFC|ue)se","nozzle","hotend","extruder","druckbett","heatbed","(^|[^a-z])bed($|[^a-z])","chamber","cpu","gpu","chip","soc","akku","batter","wasser","water","kessel","boiler","au(\xDF|ss)en","outdoor","outside","abgas","exhaust","sole","brine","verdampfer","kondensat","verdichter","compressor","motor","k(\xFC|ue)hl","freezer","fridge","gefrier"],P_=new RegExp(`(${z_.join("|")})`,"i");function Rs(t,e){let n=t.entities?.[e]?.device_id,r=n&&!Ss(t,n)?$n(t).domainsByDevice.get(n):void 0;return r&&[...r].some(o=>T_.has(o))?!1:!P_.test(`${e} ${t.states[e]?.attributes.friendly_name??""}`)}function pd(t,e,n,r){let o=n.climate?.[r];if(o==="none")return[];if(o)return[o].flat().filter(c=>t.states[c]);let i=(e?.placements??[]).filter(c=>c.entity_id.startsWith("sensor.")),s=i.filter(c=>N([c.x,c.z],n.points)).map(c=>c.entity_id),l=new Set(i.filter(c=>!N([c.x,c.z],n.points)).map(c=>c.entity_id));return[...new Set([...be(t,n).filter(c=>!l.has(c)),...s])].filter(c=>c.startsWith("sensor.")&&t.states[c]?.attributes.device_class===Ms[r]&&Rs(t,c))}var I_=new Set([void 0,"shutter","blind","awning","shade","curtain","window"]),D_=new Set(["garage","gate"]),O_=new Set(["window","opening"]);function _r(t,e,n=!1){let r=new Map;return t.forEach((o,i)=>{let s=n&&e.length===1?e[0]:e[i];s&&r.set(o.id,s)}),r}var fd=(t,e)=>t==="none"?null:t??e??null,Mn=t=>t&&t!=="none"?t:null;function br(t,e){let n=new Map;for(let r of e)for(let o of r.rooms){let i=r.openings.filter(g=>g.room_id===o.id).sort((g,y)=>g.edge-y.edge||g.offset-y.offset);if(i.length===0)continue;let s=be(t,o),l=g=>t.states[g]?.attributes.device_class,a=g=>s.filter(y=>X(y)==="binary"&&g(l(y)??"")),c=g=>i.filter(y=>y.type===g),d=_r(c("window"),s.filter(g=>X(g)==="cover"&&I_.has(l(g))),!0),u=_r(c("window"),a(g=>O_.has(g))),p=_r(c("door"),a(g=>g==="door")),h=_r(c("garage"),s.filter(g=>X(g)==="cover"&&D_.has(l(g)??""))),f=_r(c("garage"),a(g=>g==="garage_door"));for(let g of i){let y=g.type==="window"?d:g.type==="garage"?h:null,b=g.type==="window"?u:g.type==="garage"?f:p,v=g.leaves===2;n.set(g.id,{cover:fd(g.cover,y?.get(g.id)),contact:g.sensor==="handle"&&g.contact==null?null:fd(g.contact,b.get(g.id)),tilt:g.tilt==="none"?null:g.tilt,contact2:v?Mn(g.contact2):null,tilt2:v?Mn(g.tilt2):null,position:Mn(g.position),positionInverted:!!g.position_inverted,tiltAngle:Mn(g.tilt_angle),tiltMax:g.tilt_max??null,tiltOffset:g.tilt_offset??null,tiltInvert:!!g.tilt_invert,shut:!!g.shut,angled:g.type==="door"&&!!g.open_angle,lock:g.type==="door"?Mn(g.lock):null,cover2:g.type==="garage"?null:Mn(g.cover2)})}}return n}var H_=[[/^(tilted|tilt|gekippt|kipp)/i,"tilted"],[/^(open|opened|offen|geöffnet|on)$/i,"open"],[/^(closed|close|geschlossen|zu|off)$/i,"closed"]];function Es(t){if(!t||Rt(t))return null;let e=t.attributes.window_state;for(let n of[typeof e=="string"?e:"",t.state]){let r=n.trim(),o=r&&H_.find(([i])=>i.test(r));if(o)return o[1]}return null}var md=/\b(tv|fernseh|television|fire ?tv|apple ?tv|chromecast|shield)/i,gd=/(kühl|fridge|gefrier|freezer)/i,_d=/(spülmaschine|geschirrspül|dishwasher)/i,L_=/(kochfeld|herd|induktion|cooktop)/i,C_={robot_vacuum:/(saug|vacuum|robo|roomba|roborock|dreame|ecovacs|deebot)/i,tv_board:md,tv_wall:md,desk:/\b(pc|computer|rechner|desktop|monitor|workstation)/i,fridge:gd,fridge_smart:gd,stove:/(herd|kochfeld|cooktop|stove|induktion)/i,kitchen_tall:/(backofen|oven|ofen)/i,dishwasher:_d,washer:/(waschmaschine|washer|washing)/i,dryer:/(trockner|dryer)/i,kitchen:/(kaffee|coffee|wasserkocher|kettle)/i,island:L_,sink:_d,radiator:/(heiz|radiator|thermostat|climate|hk|trv)/i},bd={lamp_ceiling:/(decke|ceiling|haupt|main)/i,lamp_downlight:/(spot|strahler|downlight|einbau)/i,lamp_spot:/(spot|strahler)/i,lamp_panel:/(panel|decke|ceiling)/i,lamp_uplight:/(fluter|uplight|steh)/i,lamp_bollard:/(weg|garten|garden|path|poller|außen|aussen|outdoor)/i,lamp_garden:/(garten|garden|spot|außen|aussen|outdoor|baum|tree)/i,lamp_pendant:/(pendel|pendant|hänge|esstisch|dining)/i,ceiling_fan:/(ventilator|fan)/i,lamp_floor:/(steh|floor)/i,lamp_table:/(tisch|nacht|table|bedside|lese|reading)/i,lamp_wall:/(wand|wall)/i,led_strip:/(led|strip|streifen|leiste|band)/i},yd=new Set(["tv_board","tv_wall"]);var Rn=t=>yd.has(t)||!!wc(t),Zo=t=>!!G(t)?.electric&&/speaker|multiroom|soundbar/.test(t.split(":").pop()??t),wr=t=>Rn(t)||t==="desk"||t==="fridge_smart",N_=t=>!!t&&t!=="none";function B_(t,e){if(Go(t,e))return e;let n=t.entities?.[e]?.device_id;return n?jo(t,n).find(r=>r!==e)??null:null}var W_=(t,e,n)=>t.rooms.find(r=>r.points.length>=3&&N([e,n],r.points));function yr(t,e,n,r){return t.find(o=>e?.test(n(o)))??(r?t[0]??null:null)}function Be(t,e){let n=new Map;for(let r of e){let o=new Set([...r.furniture.flatMap(i=>[i.entity,i.power,i.fan_entity]),...r.placements.map(i=>i.entity_id)].filter(N_));for(let i of r.furniture){let s=i.type in bd,l=yn(i.type),a=s?bd[i.type]:C_[i.type];if(!a&&!l&&!Zo(i.type)&&i.entity==null&&i.power==null)continue;let c=W_(r,i.x,i.z),d=(c?Uo(t,be(t,c)):[]).filter(y=>!o.has(y)),u=y=>`${y} ${W(t,y)}`,p=y=>d.filter(b=>X(b)===y),h=i.entity==="none"?null:i.entity??null;if(i.entity==null){if(i.type==="ceiling_fan"){let y=(c?be(t,c):[]).filter(v=>!o.has(v)),b=new Set(y.filter(v=>X(v)==="fan").map(v=>t.entities?.[v]?.device_id).filter(Boolean));h=y.find(v=>X(v)==="light"&&b.has(t.entities?.[v]?.device_id))??yr(p("light"),a,u,!1)}else if(s)h=yr(p("light"),a,u,!0);else if(i.type==="robot_vacuum"){let y=c?.area_id??null;h=Object.keys(t.entities??{}).find(b=>b.startsWith("vacuum.")&&!o.has(b)&&Tt(t,b)===y)??null}else if(i.type==="radiator"||l)h=yr(p("climate"),a,u,!0);else if(Rn(i.type)){let y=p("media");h=y.find(b=>t.states[b]?.attributes.device_class==="tv")??yr(y,a,u,yd.has(i.type))}else if(Zo(i.type)){let y=p("media").filter(b=>t.states[b]?.attributes.device_class!=="tv");h=yr(y,a,u,!1)??(y.length===1?y[0]:null)}else a&&(h=d.find(y=>["switch","media","fan"].includes(X(y)??"")&&a.test(u(y)))??null);h&&o.add(h)}let f=i.power==="none"?null:i.power??null;i.power==null&&(f=h?B_(t,h):null,!f&&a&&c&&!s&&(f=be(t,c).find(y=>Go(t,y)&&!o.has(y)&&a.test(u(y)))??null),f&&o.add(f));let g=null;if(i.type==="ceiling_fan"&&(g=i.fan_entity==="none"?null:i.fan_entity??null,i.fan_entity==null)){let y=(c?be(t,c):[]).filter(v=>X(v)==="fan"&&!o.has(v)),b=h?t.entities?.[h]?.device_id:void 0;g=(b?y.find(v=>t.entities?.[v]?.device_id===b):void 0)??y[0]??null,g&&o.add(g)}(h||f||g)&&n.set(i.id,{entity:h,power:f,...i.type==="ceiling_fan"?{fan:g}:{}})}}return n}var wd=t=>t==="fridge"||t==="fridge_smart"||/(fridge|freezer|kuehl|gefrier|chest_freezer)/.test(t.slice(t.lastIndexOf(":")+1));function vd(t,e,n=[]){let r=[];for(let o of e){let i=(l,a)=>o.rooms.some(c=>c.points.length>=3&&N([l,a],c.points)),s=Be(t,[o]);r.push(...o.placements.filter(l=>l.outside||!i(l.x,l.z)).map(l=>l.entity_id)),r.push(...o.furniture.filter(l=>!i(l.x,l.z)).flatMap(l=>[s.get(l.id)?.entity,s.get(l.id)?.power]));for(let l of o.outdoor??[])l.area_id&&r.push(...Uo(t,Ko(t,l.area_id))),r.push(l.pump_entity,l.temp_entity)}return[...new Set(r.filter(o=>!!o&&!!t.states[o]&&!n.includes(o)))]}function V_(t,e){return Math.min(...e.map((n,r)=>{let o=e[(r+1)%e.length],[i,s]=[o[0]-n[0],o[1]-n[1]],l=Math.min(1,Math.max(0,((t[0]-n[0])*i+(t[1]-n[1])*s)/(i*i+s*s||1)));return Math.hypot(t[0]-n[0]-i*l,t[1]-n[1]-s*l)}))}function xd(t,e,n=[]){let r=t.points;if(r.length<3||e.length===0)return[];let o=r.map(b=>b[0]),i=r.map(b=>b[1]),[s,l,a,c]=[Math.min(...o),Math.max(...o),Math.min(...i),Math.max(...i)],d=Math.min(l-s,c-a),u=Math.max(.1,Math.min(.25,d/8)),p=Math.min(.35,d/5),h=Math.min(.7,d/4),f=_e(r),g=[];for(let b=s+u/2;b=p&&g.push({at:w,wallDistance:x})}g.length===0&&g.push({at:f,wallDistance:0});let y=[...n];return e.map(b=>{let v=X(b)==="light",w=g[0].at,x=-1/0;for(let{at:$,wallDistance:A}of g){let F=y.length?Math.min(...y.map(z=>Math.hypot($[0]-z[0],$[1]-z[1]))):3,T=Math.hypot($[0]-f[0],$[1]-f[1]),I=Math.min(F,3)*2;Tx+1e-9&&(x=I,w=$)}let k=[Math.round(w[0]*100)/100,Math.round(w[1]*100)/100];return y.push(k),{entity_id:b,x:k[0],z:k[1],y:null,mount:null}})}var kd=/(^|_)(current_room|current_segment|aktueller_raum|current_area)($|_)/;function $d(t,e,n){if(n==="none")return null;if(n)return n;let r=e?t.entities?.[e]?.device_id:null;return!r||!t.entities?null:Object.values(t.entities).find(i=>i.device_id===r&&i.entity_id.startsWith("sensor.")&&(kd.test(i.translation_key??"")||kd.test(i.entity_id.split(".")[1])))?.entity_id??null}var K=(t,e)=>[t[0]-e[0],t[1]-e[1]],ct=(t,e)=>[t[0]+e[0],t[1]+e[1]],tt=(t,e)=>[t[0]*e,t[1]*e],Q=(t,e)=>t[0]*e[0]+t[1]*e[1],$e=(t,e)=>t[0]*e[1]-t[1]*e[0],me=t=>Math.hypot(t[0],t[1]),nt=t=>{let e=me(t)||1;return[t[0]/e,t[1]/e]},As=t=>[-t[1],t[0]],Fs=t=>[t[1],-t[0]];var K_=.05,G_=.2,j_=.12;function U_(t){let e=[];return t.forEach((n,r)=>{let o=n.points;if(o.length<3)return;let i=ge(o)>=0;o.forEach((s,l)=>{let a=o[(l+1)%o.length],c=me(K(a,s));if(c<.05)return;let d=[(a[0]-s[0])/c,(a[1]-s[1])/c],u=i?[d[1],-d[0]]:[-d[1],d[0]];(d[1]<-1e-9||Math.abs(d[1])<=1e-9&&d[0]<0)&&(d=[-d[0],-d[1]]);let p=[-d[1],d[0]],[h,f]=[Q(s,d),Q(a,d)];e.push({room:r,index:l,dir:d,normal:p,offset:Q(s,p),outside:Q(u,p)>0?1:-1,from:Math.min(h,f),to:Math.max(h,f)})})}),e}function Z_(t,e,n){if(t.room===e.room||Math.abs($e(t.dir,e.dir))>K_||t.outside===e.outside)return null;let r=(e.offset-t.offset)*t.outside;return r>n||r<-j_||Math.abs(r)<1e-4||Math.min(t.to,e.to)-Math.max(t.from,e.from)Math.round(t*1e3)/1e3;function Sd(t,e=.6){let n=U_(t),r=n.map((g,y)=>y),o=g=>r[g]===g?g:r[g]=o(r[g]),i=[],s=new Set,l=[];for(let g=0;gMath.abs(g[2])-Math.abs(y[2]));let a=new Map(n.map((g,y)=>[y,[y]])),c=(g,y)=>g.some(b=>y.some(v=>n[b].room===n[v].room&&Math.abs(n[b].offset-n[v].offset)>=.002));for(let[g,y,b]of l){let[v,w]=[o(g),o(y)];if(v!==w){if(c(a.get(v),a.get(w)))continue;r[v]=w,a.set(w,[...a.get(w),...a.get(v)]),a.delete(v)}i.push(Ts(b)),s.add(g).add(y)}let d=new Map(n.map((g,y)=>[`${g.room}:${g.index}`,y]));for(let g=s.size>0;g;)g=!1,n.forEach((y,b)=>{let v=d.get(`${y.room}:${(y.index+1)%t[y.room].points.length}`);if(v===void 0||v===b)return;let w=n[v];!(Math.abs($e(y.dir,w.dir))<1e-6&&Math.abs(y.offset-w.offset)<.002&&y.outside===w.outside)||s.has(b)===s.has(v)||(s.add(b).add(v),g=!0)});n.forEach((g,y)=>{let b=d.get(`${g.room}:${(g.index+1)%t[g.room].points.length}`);if(b===void 0||b===y||!s.has(y)||!s.has(b))return;let v=n[b];Math.abs($e(g.dir,v.dir))<1e-6&&Math.abs(g.offset-v.offset)<.002&&g.outside===v.outside&&(r[o(y)]=o(b))});let u=()=>t.map(g=>({...g,points:g.points.map(y=>[y[0],y[1]])}));if(i.length===0)return{rooms:u(),gaps:i};let p=new Map;for(let g of s)p.set(o(g),[...p.get(o(g))??[],g]);let h=t.map(g=>g.points.map(()=>new Map));for(let[g,y]of p){let b=new Map(y.map(w=>[`${n[w].room}:${Math.round(n[w].offset*500)}`,n[w].offset])),v=[...b.values()].reduce((w,x)=>w+x,0)/b.size;for(let w of y){let x=n[w],k=[x.normal[0]*(v-x.offset),x.normal[1]*(v-x.offset)];h[x.room][x.index].set(g,k),h[x.room][(x.index+1)%t[x.room].points.length].set(g,k)}}return{rooms:t.map((g,y)=>({...g,points:g.points.map((b,v)=>{let w=[...h[y][v].values()].reduce((x,k)=>[x[0]+k[0],x[1]+k[1]],[b[0],b[1]]);return[Ts(w[0]),Ts(w[1])]})})),gaps:i}}function Md(t){let e=t.filter(n=>n>.04).sort((n,r)=>n-r);return e.length===0?null:Math.min(.5,Math.max(.08,Math.round(e[Math.floor(e.length/2)]*100)/100))}var q_=.25,Rd=t=>Math.round(t*1e3)/1e3,Ed=(t,e,n)=>t.rooms.find(r=>r.points.length>=3&&N([e,n],r.points));function Ps(t,e,n,r,o){let i=Ed(t,e,n);if(!i)return[r,o];let s=(l,a)=>N([l,a],i.points);return s(r,o)?[r,o]:s(r,n)?[r,n]:s(e,o)?[e,o]:[e,n]}function Y_(t,e,n,r){return t.rooms.some(o=>o.id!==e.id&&o.points.some((i,s)=>{let l=o.points[(s+1)%o.points.length];return Math.abs(Q(K(i,n),r))<.02&&Math.abs(Q(K(l,n),r))<.02}))}var zs=(t,e)=>Math.abs((t-e+540)%360-180);function vr(t,e,n,r=q_){let o=Ed(t,e.x,e.z);if(!o)return null;let i=o.points,s=ge(i)>=0?1:-1,l=null;return i.forEach((a,c)=>{let d=i[(c+1)%i.length],u=me(K(d,a));if(u<.3)return;let p=[(d[0]-a[0])/u,(d[1]-a[1])/u],h=[-p[1]*s,p[0]*s],f=Q(K([e.x,e.z],a),p);if(f<0||f>u)return;let g=Y_(t,o,a,h)?n/2:0,y=Q(K([e.x,e.z],a),h)-g,b=Math.atan2(-h[0],h[1])*180/Math.PI,w=[{rotation:b,extent:e.d/2},{rotation:b+90,extent:e.w/2},{rotation:b-90,extent:e.w/2}].reduce((k,$)=>zs(e.rotation,$.rotation)50)return;let x=y-w.extent;Math.abs(x)>r||l&&Math.abs(x)>=Math.abs(l.gap)||(l={x:Rd(e.x-h[0]*x),z:Rd(e.z-h[1]*x),rotation:(Math.round(w.rotation)%360+360)%360,gap:x})}),l&&{x:l.x,z:l.z,rotation:l.rotation}}var En=Math.PI/180,rt=t=>Math.tan(Math.min(80,Math.max(0,t))*En);function xr(t){return{x0:Math.min(t.x0,t.x1),x1:Math.max(t.x0,t.x1),z0:Math.min(t.z0,t.z1),z1:Math.max(t.z0,t.z1)}}function Ad(t){if(!t.rotation)return null;let e=t.rotation*En;return{cx:(t.x0+t.x1)/2,cz:(t.z0+t.z1)/2,c:Math.cos(e),sn:Math.sin(e)}}function Fd(t,e){let n=Ad(t);if(!n)return e;let[r,o]=[e[0]-n.cx,e[1]-n.cz];return[n.cx+r*n.c-o*n.sn,n.cz+r*n.sn+o*n.c]}function Is(t,e,n){let r=Ad(t);if(!r)return[e,n];let[o,i]=[e-r.cx,n-r.cz];return[r.cx+o*r.c+i*r.sn,r.cz-o*r.sn+i*r.c]}function $r(t,e=0){let{x0:n,x1:r,z0:o,z1:i}=xr(t);return[[n-e,o-e],[r+e,o-e],[r+e,i+e],[n-e,i+e]].map(s=>Fd(t,s))}function ve(t){let{x0:e,x1:n,z0:r,z1:o}=xr(t),i=s=>Fd(t,s);return t.axis==="x"?{u0:e,u1:n,w:o-r,at:(s,l)=>i([s,t.flip?o-l:r+l])}:{u0:r,u1:o,w:n-e,at:(s,l)=>i([t.flip?n-l:e+l,s])}}function Sr(t,e,n){let{x0:r,x1:o,z0:i,z1:s}=xr(t),[l,a]=Is(t,e,n);return t.axis==="x"?[l,t.flip?s-a:a-i]:[a,t.flip?o-l:l-r]}var kr=Math.tan(30*En);function Mr(t,e,n,r,o){let i=Math.min(t*.3,r>1e-6?2.4/r:t*.3),s=Math.min(t*.3,o>1e-6?2.4/o:t*.3),l=e+i*r,a=n+s*o,c=Math.min(t-s,Math.max(i,(a-l+kr*(t-s+i))/(2*kr))),d=l+(c-i)*kr;return{vla:i,vlb:s,yla:l,ylb:a,vr:c,rh:d,y:p=>p<=i?e+p*r:p<=c?l+(p-i)*kr:p<=t-s?a+(t-s-p)*kr:n+(t-p)*o}}function Pe(t){let e=ve(t).w,[n,r]=[t.eave_a,t.eave_b],[o,i]=[rt(t.pitch_a),rt(t.pitch_b)];switch(t.shape){case"flat":case"parapet":return{vr:e/2,rh:n,y:()=>n};case"pent":return{vr:e,rh:n+e*o,y:s=>n+s*o};case"mansard":{let s=Mr(e,n,r,o,i);return{vr:s.vr,rh:s.rh,y:s.y}}default:{let s=o+i>1e-6?Math.min(e,Math.max(0,(r-n+e*i)/(o+i))):e/2;return{vr:s,rh:n+s*o,y:l=>l<=s?n+l*o:r+(e-l)*i}}}}var Yt=t=>Pe(t).rh;function Td(t){let e=t.heightEnd!==void 0;return{...t,a:t.b,b:t.a,left:t.right,right:t.left,roomLeft:t.roomRight,roomRight:t.roomLeft,height:e?t.heightEnd:t.height,heightEnd:e?t.height:void 0}}function X_(t,e){let n=t.map(r=>({...r}));for(let r of e){let o=n.find(i=>i.room_id===r.room_id&&i.edge===r.edge&&(Math.abs(i.t1-r.t0)<1e-6||Math.abs(r.t1-i.t0)<1e-6));o?(o.t0=Math.min(o.t0,r.t0),o.t1=Math.max(o.t1,r.t1)):n.push({...r})}return n}function Q_(t,e,n){if(t.a===e.b)return!1;let r=nt(K(n[t.b],n[t.a])),o=nt(K(n[e.b],n[e.a]));return Math.abs($e(r,o))>1e-6||Q(r,o)<=0||t.free||e.free||t.heightEnd!==void 0||e.heightEnd!==void 0?!1:t.height===e.height&&t.exterior===e.exterior&&t.roomLeft===e.roomLeft&&t.roomRight===e.roomRight&&Math.abs(t.left-e.left)<=1e-9&&Math.abs(t.right-e.right)<=1e-9}function zd(t,e,n=new Set){let r=t.slice();for(;;){let o=new Map;r.forEach((s,l)=>{for(let a of[s.a,s.b])o.set(a,[...o.get(a)??[],l])});let i=null;for(let[s,l]of o){if(l.length!==2||n.has(s))continue;let a=r[l[0]].b===s?r[l[0]]:Td(r[l[0]]),c=r[l[1]].a===s?r[l[1]]:Td(r[l[1]]);if(!Q_(a,c,e))continue;let d={...a,b:c.b,sources:X_(a.sources,c.sources)};i=[...r.filter((u,p)=>p!==l[0]&&p!==l[1]),d];break}if(!i)return r;r=i}}function Pd(t,e){let n=new Map;t.forEach((o,i)=>{let s=nt(K(e[o.b],e[o.a])),l=[[o.a,{key:`${i}:a`,d:s,left:o.left,right:o.right,angle:Math.atan2(s[1],s[0])}],[o.b,{key:`${i}:b`,d:tt(s,-1),left:o.right,right:o.left,angle:Math.atan2(-s[1],-s[0])}]];for(let[a,c]of l)n.set(a,[...n.get(a)??[],c])});let r=new Map;for(let[o,i]of n){let s=e[o];i.sort((a,c)=>a.angle-c.angle);for(let a of i)r.set(a.key,{left:ct(s,tt(As(a.d),a.left)),right:ct(s,tt(Fs(a.d),a.right))});if(i.length<2)continue;let l=4*Math.max(...i.map(a=>Math.max(a.left,a.right)))+1e-9;i.forEach((a,c)=>{let d=i[(c+1)%i.length],u=ct(s,tt(As(a.d),a.left)),p=ct(s,tt(Fs(d.d),d.right)),h=$e(a.d,d.d);if(Math.abs(h)<1e-4)return;let f=ct(u,tt(a.d,$e(K(p,u),d.d)/h));me(K(f,s))>l||(r.get(a.key).left=f,r.get(d.key).right=f)})}return r}function Id(t,e){let n=t.filter((r,o)=>me(K(r,t[(o+1)%t.length]))>e);for(;;){if(n.length<=3)return n;let r=n.findIndex((o,i)=>{let s=n[(i+n.length-1)%n.length],l=n[(i+1)%n.length],[a,c]=[K(o,s),K(l,o)];return Math.abs($e(nt(a),nt(c)))<1e-7&&Q(a,c)>0});if(r===-1)return n;n=n.filter((o,i)=>i!==r)}}function J_(t){let e=[];return{points:e,idOf(n){let r=e.findIndex(o=>Math.abs(o[0]-n[0])<=t&&Math.abs(o[1]-n[1])<=t);return r>=0?r:(e.push([n[0],n[1]]),e.length-1)}}}function eb(t,e){let n=[];for(let r of t){let o=r.points;if(o.length<3||Math.abs(ge(o))<1e-6)continue;let i=ge(o)>0,s=o.map(l=>e.idOf(l));s.forEach((l,a)=>{let c=s[(a+1)%s.length];l!==c&&n.push(i?{u:l,v:c,room:r.id,edge:a,forward:!0}:{u:c,v:l,room:r.id,edge:a,forward:!1})})}return n}function tb(t,e,n){let r=[];for(let o of t){let[i,s]=[e[o.u],e[o.v]],l=K(s,i),a=me(l),c=tt(l,1/a),d=e.map((p,h)=>({id:h,rel:K(p,i)})).filter(({id:p,rel:h})=>p!==o.u&&p!==o.v&&Q(h,c)>n&&Q(h,c)({t:Q(h,c),id:p})).sort((p,h)=>p.t-h.t),u=[{t:0,id:o.u},...d,{t:a,id:o.v}];for(let p=0;p+1({room_id:t.room,edge:t.edge,t0:t.t0,t1:t.t1});function nb(t,e){let n=new Map(t.map(l=>[l.id,l])),r=new Map;for(let l of e){let a=`${l.room}:${l.edge}`;r.set(a,[...r.get(a)??[],l.t0].sort((c,d)=>c-d))}let o=l=>{let a=n.get(l.room)?.wall_heights?.[l.edge];return Array.isArray(a)?a[(r.get(`${l.room}:${l.edge}`)??[]).indexOf(l.t0)]??null:a},i=l=>{let a=n.get(l.room),[c,d]=[a?.wall_heights?.[l.edge],a?.wall_slopes?.[l.edge]];if(!a||typeof c!="number"||typeof d!="number"||c<=0||d<=0)return null;let[u,p]=[a.points[l.edge],a.points[(l.edge+1)%a.points.length]];return{from:c,to:d,length:Math.hypot(p[0]-u[0],p[1]-u[1])}},s=l=>{let a=i(l);if(!a||a.length<1e-9){let d=o(l);return typeof d=="number"&&d>0?[d,d]:[null,null]}let c=d=>a.from+(a.to-a.from)*d/a.length;return l.forward?[c(l.t0),c(l.t1)]:[c(l.t1),c(l.t0)]};return{heightsOf(l){let[a,c]=[1/0,1/0];for(let u of l){let[p,h]=s(u),[f,g]=u===l[0]?[p,h]:[h,p];f!==null&&(a=Math.min(a,f)),g!==null&&(c=Math.min(c,g))}let d=l.map(u=>n.get(u.room)?.ceiling);if(d.every(u=>typeof u=="number"&&u>0)){let u=Math.max(...d);a===1/0&&(a=u),c===1/0&&(c=u)}return{...a<1/0?{a}:{},...c<1/0?{b:c}:{}}},thicknessOf(l){let a=l.map(c=>{let d=n.get(c.room)?.wall_thickness?.[c.edge];return Array.isArray(d)?d[(r.get(`${c.room}:${c.edge}`)??[]).indexOf(c.t0)]:d}).filter(c=>typeof c=="number"&&c>0);return a.length?Math.max(...a):void 0},hasNoWall:l=>l.some(a=>o(a)===0)}}function Od(t){let e=n=>Math.round(n*1e6)/1e6;return t.a===void 0||t.b===void 0?t.a!==void 0?{height:e(t.a)}:t.b!==void 0?{height:e(t.b)}:{}:Math.abs(t.a-t.b)<1e-6?{height:e(t.a)}:{height:e(t.a),heightEnd:e(t.b)}}function rb(t,e,n,r){let o=nb(e,t),i=new Map;for(let a of t){let c=a.up!==c&&p.u===c.v&&p.v===c.u&&p.room!==c.room);for(let p of a)p!==c&&p!==d&&p.room!==c.room&&r.push(`overlap:${c.room}:${p.room}`);let u=d?[c,d]:[c];if(o.hasNoWall(u)){d&&l.push([c.room,d.room]);continue}if(d){let p=o.thicknessOf(u)??n.interior;s.push({a:c.u,b:c.v,left:p/2,right:p/2,exterior:!1,roomLeft:c.room,roomRight:d.room,sources:u.map(Dd),...Od(o.heightsOf(u))})}else s.push({a:c.u,b:c.v,left:0,right:o.thicknessOf(u)??n.exterior,exterior:!0,roomLeft:c.room,roomRight:null,sources:[Dd(c)],...Od(o.heightsOf(u))})}return{drafts:s,open:l}}function ob(t,e){let n=i=>nt(K(e[i.b],e[i.a])),r=t.filter(i=>!i.exterior&&!i.free),o=new Map;for(let i of r){if(o.has(i))continue;let s=[i];o.set(i,s);for(let l=0;l1e-6||a.add(Q(s,h)>0?"left":"right")}if(a.size!==1)continue;let c=[...a][0];for(let d of i){let u=d.left+d.right,p=Q(n(d),s)>0,h=c==="left"===p;[d.left,d.right]=h?[0,u]:[u,0]}}}var ib=(t,e)=>{let n=i=>Math.round(i*100),[r,o]=t[0]Math.hypot(b.b[0]-b.a[0],b.b[1]-b.a[1])>.05),a=l.map(b=>[i.idOf(b.a),i.idOf(b.b)]),c=new Set;for(let b of t){let v=b.points;v.length<3||(b.wall_splits??[]).forEach((w,x)=>{if(!w||x>=v.length)return;let k=v[x],$=K(v[(x+1)%v.length],k),A=me($);for(let F of w)F>r&&F{let[w,x]=a[v];if(w===x)return;let k=[(b.a[0]+b.b[0])/2,(b.a[1]+b.b[1])/2],$=t.find(F=>F.points.length>=3&&N(k,F.points))?.id??null,A=(b.thickness??e.interior)/2;h.push({free:b.id,a:w,b:x,left:A,right:A,exterior:!1,roomLeft:$,roomRight:$,sources:[],height:typeof b.height=="number"&&b.height>0?b.height:void 0,...typeof b.height=="number"&&b.height>0&&typeof b.height_end=="number"&&b.height_end>0&&Math.abs(b.height_end-b.height)>1e-6?{heightEnd:b.height_end}:{}})});let f=zd(h,i.points,c),g=Pd(f,i.points);return{walls:f.map((b,v)=>{let[w,x]=[i.points[b.a],i.points[b.b]],[k,$]=[g.get(`${v}:a`),g.get(`${v}:b`)],A=Id([k.right,$.left,x,$.right,k.left,w],1e-6);return{id:ib(w,x),a:[w[0],w[1]],b:[x[0],x[1]],left:b.left,right:b.right,exterior:b.exterior,roomLeft:b.roomLeft,roomRight:b.roomRight,sources:b.sources,footprint:A,...b.free?{free:b.free}:{},...b.height!==void 0?{height:b.height}:{},...b.heightEnd!==void 0?{heightEnd:b.heightEnd}:{}}}),warnings:[...new Set(o)],open:p}}function An(t,e,n){let r=t.points[e];return ct(r,tt(nt(K(t.points[(e+1)%t.points.length],r)),n))}function Ie(t,e,n){if(t.wall){let o=n.find(l=>l.id===t.wall);if(!o||Math.hypot(o.b[0]-o.a[0],o.b[1]-o.a[1])<.05)return null;let i=nt(K(o.b,o.a));return{room:{id:t.room_id,name:"",area_id:null,points:[o.a,o.b,ct(o.a,[-i[1],i[0]])]},edge:0}}let r=e.find(o=>o.id===t.room_id);return r&&t.edgeQ(K(e,t.a),nt(K(t.b,t.a)));function zt(t,e,n){if(!e.wall)return sb(t,n.room,n.edge,e.offset);let r=t.find(o=>o.free===e.wall);return r?{wall:r,s:Hd(r,An(n.room,0,e.offset))}:null}function sb(t,e,n,r){for(let o of t)if(o.sources.some(s=>s.room_id===e.id&&s.edge===n&&r>=s.t0-1e-6&&r<=s.t1+1e-6))return{wall:o,s:Hd(o,An(e,n,r))};return null}function Ld(t,e){let n=t.points.map(h=>h[0]),r=t.points.map(h=>h[1]);if(t.points.length!==4||new Set(n.map(h=>h.toFixed(3))).size!==2||new Set(r.map(h=>h.toFixed(3))).size!==2)return null;let[o,i,s,l]=[Math.min(...n),Math.max(...n),Math.min(...r),Math.max(...r)],a=h=>Math.max(0,...e.filter(f=>(f.roomLeft===t.id||f.roomRight===t.id)&&h(f)).map(f=>f.roomLeft===t.id?f.left:f.right)),c=(h,f)=>Math.abs(h-f)<.001,d=(h,f,g)=>c(h.a[f],g)&&c(h.b[f],g),u=i-o-a(h=>d(h,0,o))-a(h=>d(h,0,i)),p=l-s-a(h=>d(h,1,s))-a(h=>d(h,1,l));return[Math.round(u*1e3)/1e3,Math.round(p*1e3)/1e3]}var Cd=([t,e])=>{let n=Math.hypot(t,e)||1;return[t/n,e/n]};function ab(t){return t.reduce((e,n,r)=>e+(n[0]*t[(r+1)%t.length][1]-t[(r+1)%t.length][0]*n[1]),0)/2}function Nd(t,e){let n=t.length;if(n<3||Math.abs(e)<1e-9)return t.map(([o,i])=>[o,i]);let r=ab(t)>=0?1:-1;return t.map((o,i)=>{let s=t[(i+n-1)%n],l=t[(i+1)%n],[a,c]=Cd([o[0]-s[0],o[1]-s[1]]),[d,u]=Cd([l[0]-o[0],l[1]-o[1]]),p=[c*r,-a*r],h=[u*r,-d*r],f=[p[0]+h[0],p[1]+h[1]],g=Math.hypot(f[0],f[1]);if(g<1e-6)return[o[0]+p[0]*e,o[1]+p[1]*e];let y=(f[0]*p[0]+f[1]*p[1])/g,b=Math.min(4,1/Math.max(.25,y));return[o[0]+f[0]/g*e*b,o[1]+f[1]/g*e*b]})}function Pt(t){let e=t.map(r=>r[0]),n=t.map(r=>r[1]);return{x0:Math.min(...e),z0:Math.min(...n),x1:Math.max(...e),z1:Math.max(...n)}}function lb(t){let e=([i,s])=>`${Math.round(i*1e3)}:${Math.round(s*1e3)}`,n=new Map;for(let i of t)for(let s of[i.a,i.b])n.set(e(s),[...n.get(e(s))??[],i]);let r=new Set,o=null;for(let i of t){if(r.has(i))continue;r.add(i);let s=[i.a,i.b],l=i.b;for(;;){let c=(n.get(e(l))??[]).find(d=>!r.has(d));if(!c||(r.add(c),l=e(c.a)===e(l)?c.b:c.a,e(l)===e(s[0])))break;s.push(l)}s.length>=3&&e(l)===e(s[0])&&(!o||Math.abs(we(s))>Math.abs(we(o)))&&(o=s)}return o}function Ds(t,e,n,r){let o=fe(t,{exterior:n,interior:r},e).walls.filter(l=>l.exterior&&!l.free),i=o.length?lb(o.map(l=>({a:l.a,b:l.b}))):null;if(!i)return null;let s=i.filter((l,a)=>{let c=i[(a+i.length-1)%i.length],d=i[(a+1)%i.length];return Math.abs((l[0]-c[0])*(d[1]-l[1])-(l[1]-c[1])*(d[0]-l[0]))>1e-6});return s.length>=3?Nd(s,n):null}function Xt(t,e){let n=ve(t),r=Pe(t),o=n.w,[i,s]=[Math.max(0,e.a),Math.max(0,e.b)],l=n.u0-Math.max(0,e.u0),a=n.u1+Math.max(0,e.u1),c=(b,v)=>[b,v,r.y(v)],d=c(l,-i),u=c(a,-i),p=c(a,o+s),h=c(l,o+s),[f,g]=[rt(t.pitch_a),rt(t.pitch_b)],y=b=>[b,r.vr,r.rh];if(t.ends&&(t.shape==="gable"||t.shape==="hip"||t.shape==="halfhip")){let b=(n.u1-n.u0)/2,v=Math.min(b,Math.min(r.vr,o-r.vr)||o/2),w=Math.min(r.y(0),r.y(o)),x=w+(r.rh-w)*Math.min(.9,Math.max(.2,t.halfhip??.55)),k=f>1e-6?Math.min(r.vr,(x-t.eave_a)/f):r.vr,$=g>1e-6?Math.max(r.vr,o-(x-t.eave_b)/g):r.vr,A=Math.min(b-.1,(r.rh-x)/Math.max(.2,f)),F=[[0,r.y(0)],[r.vr,r.rh],[o,r.y(o)]],T=[[0,r.y(0)],[k,x],[$,x],[o,r.y(o)]],I=(V,Vt,_o)=>{if(V==="hip")return{upA:[],upB:[],ridge:y(Vt===l?n.u0+v*_o:n.u1-v*_o),profile:null};if(V==="halfhip"){let qg=y(Vt===l?n.u0+A:n.u1-A);return{upA:[[Vt,k,x]],upB:[[Vt,$,x]],ridge:qg,profile:T}}return{upA:[],upB:[],ridge:y(Vt),profile:F}},z=I(t.ends[0],l,1),C=I(t.ends[1],a,1),B=[[d,u,...C.upA,C.ridge,z.ridge,...[...z.upA].reverse()],[z.ridge,C.ridge,...[...C.upB].reverse(),p,h,...z.upB]],q=[[z.ridge,C.ridge]];for(let[V,Vt,_o]of[[z,d,h],[C,u,p]])V.profile===null?(B.push(V===z?[h,d,V.ridge]:[u,p,V.ridge]),q.push([Vt,V.ridge],[_o,V.ridge])):V.upA.length&&(B.push(V===z?[V.upB[0],V.upA[0],V.ridge]:[V.upA[0],V.upB[0],V.ridge]),q.push([V.upA[0],V.ridge],[V.upB[0],V.ridge]));let ye=V=>V.profile===null?[]:V.upA.length?[V.upA[0],V.upB[0]]:[V.ridge],$t=[d,u,...ye(C),p,h,...[...ye(z)].reverse()];return{faces:B,rim:$t,ridges:q,gable:F,endProfiles:[z.profile,C.profile]}}switch(t.shape){case"pent":return{faces:[[d,u,p,h]],rim:[d,u,p,h],ridges:[[p,h]],gable:[[0,r.y(0)],[o,r.y(o)]]};case"hip":case"pyramid":{let b=(n.u1-n.u0)/2,v=t.shape==="pyramid"?b:Math.min(b,Math.min(r.vr,o-r.vr)||o/2),w=y(n.u0+v),x=y(n.u1-v);return t.shape==="pyramid"?{faces:[[d,u,w],[u,p,w],[p,h,w],[h,d,w]],rim:[d,u,p,h],ridges:[[d,w],[h,w],[u,w],[p,w]],gable:null}:{faces:[[d,u,x,w],[w,x,p,h],[h,d,w],[u,p,x]],rim:[d,u,p,h],ridges:[[w,x],[d,w],[h,w],[u,x],[p,x]],gable:null}}case"halfhip":{let b=Math.min(r.y(0),r.y(o)),v=b+(r.rh-b)*Math.min(.9,Math.max(.2,t.halfhip??.55)),w=f>1e-6?Math.min(r.vr,(v-t.eave_a)/f):r.vr,x=g>1e-6?Math.max(r.vr,o-(v-t.eave_b)/g):r.vr,k=Math.min((n.u1-n.u0)/2-.1,(r.rh-v)/Math.max(.2,f)),$=y(n.u0+k),A=y(n.u1-k),F=[l,w,v],T=[l,x,v],I=[a,w,v],z=[a,x,v];return{faces:[[d,u,I,A,$,F],[$,A,z,p,h,T],[T,F,$],[I,z,A]],rim:[d,u,I,z,p,h,T,F],ridges:[[$,A],[F,$],[T,$],[I,A],[z,A]],gable:[[0,r.y(0)],[w,v],[x,v],[o,r.y(o)]]}}case"mansard":{let b=Mr(o,t.eave_a,t.eave_b,f,g),v=[l,b.vla,b.yla],w=[a,b.vla,b.yla],x=[l,o-b.vlb,b.ylb],k=[a,o-b.vlb,b.ylb],$=[l,b.vr,b.rh],A=[a,b.vr,b.rh];return{faces:[[d,u,w,v],[v,w,A,$],[$,A,k,x],[x,k,p,h]],rim:[d,u,w,A,k,p,h,x,$,v],ridges:[[$,A],[v,w],[x,k]],gable:[[0,r.y(0)],[b.vla,b.yla],[b.vr,b.rh],[o-b.vlb,b.ylb],[o,r.y(o)]]}}default:{let b=y(l),v=y(a);return{faces:[[d,u,v,b],[b,v,p,h]],rim:[d,u,v,p,h,b],ridges:[[b,v]],gable:[[0,r.y(0)],[r.vr,r.rh],[o,r.y(o)]]}}}}function Rr(t,e,n){let r=null;for(let o of t.faces){if(!N([e,n],o.map(([p,h])=>[p,h])))continue;let[i,s]=o,l=o.slice(2).find(p=>Math.abs((s[0]-i[0])*(p[1]-i[1])-(s[1]-i[1])*(p[0]-i[0]))>1e-9);if(!l)continue;let a=[s[0]-i[0],s[2]-i[2],s[1]-i[1]],c=[l[0]-i[0],l[2]-i[2],l[1]-i[1]],d=[a[1]*c[2]-a[2]*c[1],a[2]*c[0]-a[0]*c[2],a[0]*c[1]-a[1]*c[0]];if(Math.abs(d[1])<1e-9)continue;let u=i[2]-(d[0]*(e-i[0])+d[2]*(n-i[1]))/d[1];r=r===null?u:Math.min(r,u)}return r}function Er(t,e,n){let r=ve(e),o=t.floors.flatMap(u=>u.rooms.filter(p=>p.points.length>=3&&u.elevation+u.height>e.base+.05)),i=u=>u.some(p=>o.some(h=>N(p,h.points))),s=.35,l=[.15,.5,.85].map(u=>r.u0+(r.u1-r.u0)*u),a=[.15,.5,.85].map(u=>r.w*u),c=u=>u?0:n,d=(u,p)=>{let h=e.overhang_sides?.[u];return typeof h=="number"&&Number.isFinite(h)?Math.min(2,Math.max(0,h)):p};return{a:d("a",c(i(l.map(u=>r.at(u,-s))))),b:d("b",c(i(l.map(u=>r.at(u,r.w+s))))),u0:d("u0",c(i(a.map(u=>r.at(r.u0-s,u))))),u1:d("u1",c(i(a.map(u=>r.at(r.u1+s,u)))))}}var qo=t=>Math.abs((t.x1-t.x0)*(t.z1-t.z0)),Bd=t=>t.shape==="flat"||t.shape==="parapet",Qt=t=>Math.round(t*100)/100;function Yo(t,e){let[n,r]=[(e.x0+e.x1)/2,(e.z0+e.z1)/2];return t.filter(i=>{if(i===e||i.dormer||i.open||Bd(i)||qo(i)=s.x0&&n<=s.x1&&r>=s.z0&&r<=s.z1}).reduce((i,s)=>i===null||qo(s){let[i,s]=e.at(o,e.w/2),[l,a]=Sr(t,i,s);return Rr(n,l,a)??r.y(a)}}function Hs(t,e){if(Bd(e))return e;let n=ve(e),r=Pe(e).rh,o=db(t,n),i=o(n.u0)<=o(n.u1),[s,l]=i?[n.u0,n.u1]:[n.u1,n.u0],a=i?1:-1,c=l;for(let p=.5;p=r-.02){c=s+a*p;break}if(Math.abs(c-l)<.05)return e;let d={...e},u=l===n.u1;return e.axis==="x"?d[u?"x1":"x0"]=c:d[u?"z1":"z0"]=c,d}var Ls=.14,Wd=t=>t.shape==="flat"||t.shape==="parapet";function Cs(t,e){return!t.open&&Math.min(t.base,t.eave_a,t.eave_b)a+o||pd+o||s.points&&s.points.length>=3&&!N([e,n],s.points))continue;let[h,f]=Sr(s,e,n),g=Math.max(0,s.overhang??r),y=Wd(s)?null:Rr(Xt(s,{u0:g,u1:g,a:g,b:g}),h,f);i.push((y??Pe(s).y(f))-Ls)}return i.length?Math.max(...i):null}function Ns(t,e,n){let r=[],o=e+n+Ls;for(let i of t.settings.roof.sections??[]){if(i.open||Wd(i)||i.shape==="mansard")continue;let s=ve(i),l=Pe(i),[a,c]=[rt(i.pitch_a),rt(i.pitch_b)],d=[];a>1e-6&&d.push((o-i.eave_a)/a),i.shape==="gable"&&c>1e-6&&d.push(s.w-(o-i.eave_b)/c);for(let u of d)u<=.01||u>=s.w-.01||i.shape==="gable"&&Math.abs(l.y(u)-o)>1e-6||r.push([s.at(s.u0,u),s.at(s.u1,u)])}return r}function Bs(t,e,n,r,o){let i=[];for(let l of[.2,.5,.8])for(let a of[.2,.5,.8])i.push([e+(r-e)*l,n+(o-n)*a]);let s=t.floors.filter(l=>l.rooms.some(a=>a.points.length>=3&&i.some(c=>N(c,a.points)))).map(l=>l.elevation+l.height);return s.length?Math.max(...s):null}function Ws(t,e){let n=t.floors.filter(a=>a.rooms.length>0).sort((a,c)=>a.elevation-c.elevation),r=n.filter(a=>a.elevationd.rooms.some(u=>u.points.length>=3&&a.some(p=>N(p,u.points))));if(c)return c}return r.at(-1)??n[0]}var _t=t=>Math.round(t*1e3)/1e3;function Vs(t,e=n=>`roof_${n+1}`){let n=t.settings.roof?.pitch??35,r=t.settings.wall_exterior,o=t.floors.filter(a=>a.rooms.some(c=>c.points.length>=3)).sort((a,c)=>c.elevation-a.elevation),i=[],s=[],l=(a,c)=>a.some(d=>N(c,d.points));for(let a of o){let c=a.rooms.filter(y=>y.points.length>=3),d=[...new Set(c.flatMap(y=>y.points.map(b=>_t(b[0]))))].sort((y,b)=>y-b),u=[...new Set(c.flatMap(y=>y.points.map(b=>_t(b[1]))))].sort((y,b)=>y-b),p=u.slice(0,-1).map((y,b)=>d.slice(0,-1).map((v,w)=>{let x=[(d[w]+d[w+1])/2,(u[b]+u[b+1])/2];return l(c,x)&&!l(s,x)})),h=p.map(y=>y.map(()=>!1)),f=(y,b)=>p[b][y]&&!h[b][y],g=a.elevation+a.height;for(let y=0;yf(b+T,w+1)).every(Boolean);)w++;for(let F=y;F<=w;F++)for(let T=b;T<=v;T++)h[F][T]=!0;let[x,k]=[d[b]-r,d[v+1]+r],[$,A]=[u[y]-r,u[w+1]+r];Math.min(k-x,A-$)<.8||i.push({id:e(i.length),x0:_t(x),z0:_t($),x1:_t(k),z1:_t(A),shape:"gable",axis:k-x>=A-$?"x":"z",eave_a:_t(g),eave_b:_t(g),pitch_a:n,pitch_b:n,base:_t(g),overhang:null})}s.push(...c)}return i}var Se=Math.PI/180,We=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],Jt=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2],Fn=t=>Math.hypot(t[0],t[1],t[2]),en=t=>{let e=Fn(t)||1;return[t[0]/e,t[1]/e,t[2]/e]},Vd=(t,e)=>[t[1]*e[2]-t[2]*e[1],t[2]*e[0]-t[0]*e[2],t[0]*e[1]-t[1]*e[0]],Ve=t=>Math.round(t*100)/100,Fr=([t,e],n)=>(Math.atan2(t,-e)/Se-n+720)%360;var Gd=.25;function jd(t,e,n,r,o,i,s){let l=o-n>=i-r,a=l?o-n:i-r;return{key:`${t}:top`,section:e,side:"top",flat:!0,o:[n,s,r],eu:l?[1,0,0]:[0,0,1],es:l?[0,0,1]:[1,0,0],n:[0,1,0],lu:a,ls:l?i-r:o-n,pitch:0,span:()=>[0,a],facing:l?[0,1]:[1,0]}}function Ud(t,e){let n=en(Vd(t,e));return n[1]<0?[-n[0],-n[1],-n[2]]:n}var Zd=t=>{let e=en([-t[0],0,-t[2]]);return[e[0],e[2]]};function bt(t,e,n,r,o,i,s,l){let a=en(We(o,r)),c=en(We(i,r));return{key:t,section:e,side:n,flat:!1,o:r,eu:a,es:c,n:Ud(a,c),lu:Fn(We(o,r)),ls:Fn(We(i,r)),pitch:s,span:l,facing:Zd(c)}}function Kd(t,e,n,r,o,i){let s=Fn(We(o,r));if(s<.3)return null;let l=en(We(o,r)),a=We(i,r),c=a[0]*l[0]+a[1]*l[1]+a[2]*l[2],d=[a[0]-l[0]*c,a[1]-l[1]*c,a[2]-l[2]*c],u=Fn(d);if(u<.3)return null;let p=en(d),h=f=>{let g=Math.min(1,Math.max(0,f/u));return[c*g,s-(s-c)*g]};return{key:t,section:e,side:n,flat:!1,o:r,eu:l,es:p,n:Ud(l,p),lu:s,ls:u,pitch:Math.atan2(p[1],Math.hypot(p[0],p[2]))/Se,span:h,facing:Zd(p)}}function ub(t,e){let n=ve(t),r=Pe(t),o=(v,w,x)=>{let[k,$]=n.at(v,w);return[k,x,$]},[i,s]=[Math.max(0,e.a),Math.max(0,e.b)],l=n.u0-Math.max(0,e.u0),a=n.u1+Math.max(0,e.u1),c=a-l,d=r.y(-i),u=r.y(n.w+s);if(t.shape==="flat"||t.shape==="parapet"){let[v,w]=[n.at(l,-i),n.at(a,n.w+s)];return[jd(t.id,t.id,Math.min(v[0],w[0]),Math.min(v[1],w[1]),Math.max(v[0],w[0]),Math.max(v[1],w[1]),t.eave_a+Gd)]}if(t.shape==="pent")return[bt(`${t.id}:a`,t.id,"a",o(l,-i,d),o(a,-i,d),o(l,n.w+s,u),t.pitch_a,()=>[0,c])];if(t.shape==="mansard")return hb(t,n,l,a,i,s);let p=t.shape==="hip"||t.shape==="pyramid",h=(n.u1-n.u0)/2,f=t.shape==="pyramid"?h:p?Math.min(h,Math.min(r.vr,n.w-r.vr)||n.w/2):0,g=p?n.u0+f-l:0,y=p?a-(n.u1-f):0,b=[];if(r.vr>.3){let v=Math.hypot(r.vr+i,r.rh-d);b.push(bt(`${t.id}:a`,t.id,"a",o(l,-i,d),o(a,-i,d),o(l,r.vr,r.rh),t.pitch_a,w=>[g*(w/v),c-y*(w/v)]))}if(n.w-r.vr>.3){let v=Math.hypot(n.w+s-r.vr,r.rh-u);b.push(bt(`${t.id}:b`,t.id,"b",o(a,n.w+s,u),o(l,n.w+s,u),o(a,r.vr,r.rh),t.pitch_b,w=>[y*(w/v),c-g*(w/v)]))}if(p){let v=Kd(`${t.id}:c`,t.id,"c",o(l,n.w+s,u),o(l,-i,d),o(n.u0+f,r.vr,r.rh)),w=Kd(`${t.id}:d`,t.id,"d",o(a,-i,d),o(a,n.w+s,u),o(n.u1-f,r.vr,r.rh));b.push(...[v,w].filter(x=>x!==null))}return b}function hb(t,e,n,r,o,i){let s=Mr(e.w,t.eave_a,t.eave_b,rt(t.pitch_a),rt(t.pitch_b)),l=(f,g)=>{let[y,b]=e.at(f,g);return[y,s.y(g),b]},a=r-n,c=()=>[0,a],d=(f,g)=>Math.atan2(f,g)/Se,u=[],[p,h]=[e.w+i,e.w-s.vlb];return s.vla+o>.3&&u.push(bt(`${t.id}:a`,t.id,"a",l(n,-o),l(r,-o),l(n,s.vla),t.pitch_a,c)),s.vr-s.vla>.3&&u.push(bt(`${t.id}:au`,t.id,"a",l(n,s.vla),l(r,s.vla),l(n,s.vr),d(s.rh-s.yla,s.vr-s.vla),c)),s.vlb+i>.3&&u.push(bt(`${t.id}:b`,t.id,"b",l(r,p),l(n,p),l(r,h),t.pitch_b,c)),h-s.vr>.3&&u.push(bt(`${t.id}:bu`,t.id,"b",l(r,h),l(n,h),l(r,s.vr),d(s.rh-s.ylb,h-s.vr),c)),u}function Ks(t){return t.floors.filter(n=>n.rooms.some(r=>r.points.length>=3)).sort((n,r)=>r.elevation-n.elevation)[0]??null}function U(t){let e=t.settings.roof;if(!e||e.type==="none")return[];if(e.type==="custom")return(e.sections??[]).flatMap(w=>ub(w,Er(t,w,w.overhang??e.overhang)));let n=Ks(t);if(!n)return[];let r=n.rooms.flatMap(w=>w.points.map(x=>x[0])),o=n.rooms.flatMap(w=>w.points.map(x=>x[1])),i=t.settings.wall_exterior+e.overhang,[s,l]=[Math.min(...r)-i,Math.max(...r)+i],[a,c]=[Math.min(...o)-i,Math.max(...o)+i],d=n.elevation+n.height;if(e.type==="flat")return[jd("main",null,s,a,l,c,d+Gd)];let u=l-s>=c-a,p=e.ridge==="short"?!u:u,h=(p?c-a:l-s)/2,f=h*Math.tan(e.pitch*Se),g=(w,x,k)=>p?[w,d+k,(a+c)/2+x]:[(s+l)/2+x,d+k,w],[y,b]=p?[s,l]:[a,c],v=()=>[0,b-y];return[bt("main:a",null,"a",g(y,-h,0),g(b,-h,0),g(y,0,f),e.pitch,v),bt("main:b",null,"b",g(y,h,0),g(b,h,0),g(y,0,f),e.pitch,v)]}function Ke(t,e){let n=[];for(let r of t.floors.filter(o=>!e||o.id===e)){let{walls:o}=fe(r.rooms,{exterior:t.settings.wall_exterior,interior:t.settings.wall_interior},r.walls??[]);for(let i of o){if(!i.exterior&&!i.free)continue;let[s,l]=[i.b[0]-i.a[0],i.b[1]-i.a[1]],a=Math.hypot(s,l);if(a<1.2)continue;let[c,d]=[l/a,-s/a],u=Math.min(r.height,i.height??r.height,i.heightEnd??1/0),p=(h,f,g,y)=>n.push({key:h,section:null,side:"top",flat:!1,o:f,eu:g,es:[0,1,0],n:y,lu:a,ls:u,pitch:90,span:()=>[0,a],facing:[y[0],y[2]],wall:{floorId:r.id}});p(`wall:${r.id}:${i.id}`,[i.a[0]+c*i.right,r.elevation,i.a[1]+d*i.right],[s/a,0,l/a],[c,0,d]),i.free&&p(`wall:${r.id}:${i.id}:back`,[i.b[0]-c*i.left,r.elevation,i.b[1]-d*i.left],[-s/a,0,-l/a],[-c,0,-d])}}return n}var De="ground";function Xo(t){let e=t.floors.filter(n=>n.rooms.some(r=>r.points.length>=3)).sort((n,r)=>n.elevation-r.elevation);return e.find(n=>n.elevation>-.5)??e[0]??t.floors[0]??null}function Qo(t,e){let n=(e.rotation??0)*Se,r=[Math.cos(n),0,Math.sin(n)],o=[-Math.sin(n),0,Math.cos(n)],i=Xo(t),s=r[0]*e.u+o[0]*e.v,l=r[2]*e.u+o[2]*e.v,a=i?i.elevation+(e.base!=null?e.base:Nc(i,s,l)):e.base??0;return{key:De,section:null,side:"top",flat:!0,o:[0,a,0],eu:r,es:o,n:[0,1,0],lu:1e4,ls:1e4,pitch:0,span:()=>[-1e4,1e4],facing:[o[0],o[2]],unbounded:!0}}function ke(t,e,n=U(t)){return e.face===De?Qo(t,e):e.face.startsWith("wall:")?Ke(t,e.face.split(":")[1]).find(r=>r.key===e.face)??null:n.find(r=>r.key===e.face)??null}var Jo=1.13,zr=1.72,Ge=.025,ot=.07;function tn(t){let e=t.module_w||Jo,n=t.module_h||zr;return t.portrait===!1?[n,e]:[e,n]}function Pr(t){return t.layout?.length?t.layout.map(e=>Math.max(0,Math.min(60,Math.round(e)))):Array.from({length:Math.max(1,t.rows)},()=>Math.max(1,t.cols))}function Gs(t,e){return t.flat?Math.min(45,Math.max(0,e.tilt??15))*Se:t.wall?Math.min(90,Math.max(0,e.tilt??0))*Se:Math.min(45,Math.max(0,e.tilt??0))*Se}function Ir(t,e){let[,n]=tn(e),r=Gs(t,e);return t.wall?n*Math.cos(r)+Ge:!t.flat&&r<.001?n+Ge:t.flat&&e.rack==="ew"?n*Math.cos(r)+.08:n*Math.cos(r)+Math.max(.3,2*n*Math.sin(r))}function Tn(t,e){let[n,r]=tn(e),o=Pr(e),i=Math.max(1,...o);return[i*n+(i-1)*Ge,(o.length-1)*Ir(t,e)+r*Math.cos(Gs(t,e))]}var pb=t=>t.flat&&!t.unbounded&&!t.wall;function qd(t,e){if(!pb(t)||!e.rotation)return null;let n=e.rotation*Se,[r,o]=Tn(t,e);return{cos:Math.cos(n),sin:Math.sin(n),u:e.u+r/2,s:e.v+o/2}}function je(t,e,n=!1){let[r,o]=tn(e),i=Gs(t,e),s=o*Math.cos(i),l=Ir(t,e),a=Pr(e),c=Math.max(1,...a),d=new Set(e.skip??[]),u=qd(t,e),p=(y,b)=>u?[u.u+(y-u.u)*u.cos-(b-u.s)*u.sin,u.s+(y-u.u)*u.sin+(b-u.s)*u.cos]:[y,b],h=(y,b,v)=>{let[w,x]=p(y,b);return[0,1,2].map(k=>t.o[k]+t.eu[k]*w+t.es[k]*x+t.n[k]*v)},f=(y,b)=>{let[v,w]=p(y,b);if(t.unbounded)return!0;if(w<-1e-6||w>t.ls+1e-6)return!1;let[x,k]=t.span(w);return v>=x-1e-6&&v<=k+1e-6},g=[];return a.forEach((y,b)=>{let v=e.align==="right"?c-y:e.align==="center"?(c-y)/2:0;for(let w=0;w.001?s:o);if([[$,F],[A,F],[A,T],[$,T]].every(([I,z])=>f(I,z)))if(t.wall&&i>.001){let I=ot+o*Math.sin(i),[z,C]=e.flip?[I,ot]:[ot,I],B=[h($,F,z),h(A,F,z),h(A,T,C),h($,T,C)],q=e.flip?F:T;g.push({corners:B,posts:[$+.05,A-.05].map(ye=>[h(ye,q,0),h(ye,q,I)]),cell:x,skipped:k})}else if(!t.flat&&i>.001){let I=ot+o*Math.sin(i),z=[h($,F,ot),h(A,F,ot),h(A,T,I),h($,T,I)];g.push({corners:z,posts:[$+.05,A-.05].map(C=>[h(C,T,0),h(C,T,I)]),cell:x,skipped:k})}else if(!t.flat)g.push({corners:[h($,F,ot),h(A,F,ot),h(A,T,ot),h($,T,ot)],posts:[],cell:x,skipped:k});else{let z=.15+o*Math.sin(i),C=e.rack==="ew"&&b%2===1?!e.flip:!!e.flip,[B,q]=C?[T,F]:[F,T],ye=[h($,B,.15),h(A,B,.15),h(A,q,z),h($,q,z)],$t=[$+.05,A-.05].flatMap(V=>[[h(V,B,0),h(V,B,.15)],[h(V,q,0),h(V,q,z)]]);g.push({corners:ye,posts:$t,cell:x,skipped:k})}}}),g}function dt(t,e){if(t.unbounded)return{u:e.u,v:e.v};let[n,r]=Tn(t,e),o=qd(t,e);if(o){let[s,l]=[(n*Math.abs(o.cos)+r*Math.abs(o.sin))/2,(n*Math.abs(o.sin)+r*Math.abs(o.cos))/2],a=(u,p,h)=>Math.floor(Math.max(p,Math.min(u,h-p))*100+1e-6)/100,[c,d]=[e.u+n/2,e.v+r/2];return{u:Math.round((a(c,s,t.lu)-n/2)*100)/100,v:Math.round((a(d,l,t.ls)-r/2)*100)/100}}let i=s=>Math.floor(s*100+1e-6)/100;return{u:i(Math.min(Math.max(0,e.u),Math.max(0,t.lu-n))),v:i(Math.min(Math.max(0,e.v),Math.max(0,t.ls-r)))}}function Dr(t,e){let[n,r]=Tn(t,e),[o,i]=[e.u+n/2,e.v+r/2];return[t.o[0]+t.eu[0]*o+t.es[0]*i,t.o[2]+t.eu[2]*o+t.es[2]*i]}var ei=.78,Or=1.18,nn=t=>({id:t.id,face:t.face,u:t.u,v:t.v,rows:1,cols:1,portrait:!0,module_w:t.w||ei,module_h:t.h||Or});function js(t,e){let n=je(t,nn(e))[0];if(!n)return null;let r=o=>[o[0]-t.n[0]*.05,o[1]-t.n[1]*.05,o[2]-t.n[2]*.05];return n.corners.map(r)}var Tr={brick:{w:.5,d:.5,h:1},round:{w:.4,d:.4,h:1},wide:{w:1,d:.5,h:1},steel:{w:.2,d:.2,h:1.2}};function rn(t){let e=t.shape??"brick",n=Tr[e]??Tr.brick;return{shape:e,w:t.w||n.w,d:t.d||n.d,h:t.h||n.h}}function yt(t,e){let{w:n,d:r}=rn(t),o=e&&!e.flat?Math.cos(e.pitch*Se):1;return{id:t.id,face:t.face,u:t.u,v:t.v,rows:1,cols:1,portrait:!0,module_w:n,module_h:r/Math.max(.2,o),tilt:0}}function Us(t,e){let n=yt(e,t),[r,o]=[n.module_w,n.module_h],i=(d,u)=>[t.o[0]+t.eu[0]*d+t.es[0]*u,t.o[1]+t.eu[1]*d+t.es[1]*u,t.o[2]+t.eu[2]*d+t.es[2]*u],[s,l]=[i(e.u+r/2,e.v),i(e.u+r/2,e.v+o)],a=i(e.u+r/2,e.v+o/2),c=d=>{let u=Math.hypot(d[0],d[2])||1;return[d[0]/u,d[2]/u]};return{center:[a[0],a[2]],along:c(t.eu),across:c(t.es),low:Math.min(s[1],l[1]),high:Math.max(s[1],l[1])}}function Zs(t,e){let[n]=tn(e);return Ve((t.lu-(e.cols*n+(e.cols-1)*Ge))/2)}var Hr=.4;function zn(t,e){let n={id:e,face:t.key,u:0,v:0,rows:1,cols:1,portrait:!0,tilt:t.flat?15:null,flip:!1,entity:null,look:"black"},[r]=tn(n),[o,i]=t.span(t.ls/2);for(n.cols=Math.max(1,Math.floor((i-o-2*Hr+Ge)/(r+Ge))),n.rows=Math.max(1,Math.min(4,Math.floor((t.ls-2*Hr)/Ir(t,n))));n.cols>1&&je(t,{...n,u:Zs(t,n),v:Hr}).lengthl.lu*(1.3+Math.cos((Fr(l.facing,r)-180)*Math.PI/180)),i=Ke(t,n).sort((l,a)=>o(a)-o(l))[0];if(!i)return null;let s={...zn(i,e),portrait:!1,rows:1};return s.cols=Math.max(1,Math.floor((i.lu-.8+Ge)/(zr+Ge))),s.u=Ve((i.lu-(s.cols*zr+(s.cols-1)*Ge))/2),s.v=Ve(Math.max(0,i.ls-Jo-.3)),s}function Lr(t,e){let n=t.floors.flatMap(i=>i.rooms.flatMap(s=>s.points)),r=n.length?Math.max(...n.map(i=>i[0]))+3:0,o=n.length?Math.min(...n.map(i=>i[1])):0;return{id:e,face:De,u:Ve(r),v:Ve(o),rows:2,cols:4,portrait:!0,tilt:25,flip:!0,rotation:(t.settings.north??0)||0,look:"black",entity:null}}function Cr(t,e,n){let r=Qo(t,e),[o,i]=Tn(r,e),[s,l]=[e.u+o/2,e.v+i/2],a=[r.eu[0]*s+r.es[0]*l,r.eu[2]*s+r.es[2]*l],c=n*Se,d=a[0]*Math.cos(c)+a[1]*Math.sin(c)-o/2,u=a[0]*-Math.sin(c)+a[1]*Math.cos(c)-i/2;return{u:Ve(d),v:Ve(u),rotation:(Math.round(n)%360+360)%360}}function Nr(t,e){let[n,r]=t.span(t.ls/2);return{id:e,face:t.key,u:Ve((n+r-ei)/2),v:Ve(Math.max(0,Math.min(t.ls-Or,t.ls*.45-Or/2))),w:null,h:null,cover:null,contact:null,tilt:null}}function Br(t,e){let n=Tr.brick,[r,o]=t.span(t.ls*.8),i=yt({id:e,face:t.key,u:0,v:0},t).module_h;return{id:e,face:t.key,u:Ve((r+o-n.w)/2),v:Ve(Math.max(0,Math.min(t.ls-i,t.ls*.8-i/2))),shape:"brick",w:null,d:null,h:null}}function Pn(t,e){let[n,r]=[e[0]-t.o[0],e[1]-t.o[2]],[o,i,s,l]=[t.eu[0],t.eu[2],t.es[0],t.es[2]],a=o*l-i*s;if(Math.abs(a)<1e-9)return null;let c=(n*l-r*s)/a,d=(o*r-i*n)/a;if(d<0||d>t.ls)return null;let[u,p]=t.span(d);return c>=u&&c<=p?{u:c,s:d}:null}function Ys(t,e){let n=null;for(let r of t){if(r.wall){let[s,l]=[e[0]-r.o[0],e[1]-r.o[2]],a=s*r.eu[0]+l*r.eu[2],c=s*r.n[0]+l*r.n[2],d=a>=0&&a<=r.lu;if(d&&c>=-.05&&c<=.35)return{face:r,u:a,s:Number.NaN};d&&c>.35&&c<=.8&&!n&&(n={face:r,u:a,s:Number.NaN,y:-1/0});continue}let o=Pn(r,e);if(!o)continue;let i=r.o[1]+r.es[1]*o.s;(!n||i>n.y)&&(n={face:r,...o,y:i})}return n&&{face:n.face,u:n.u,s:n.s}}function ni(t,e,n){let r=Jt(n,t.n);if(Math.abs(r)<1e-6)return null;let o=Jt(We(t.o,e),t.n)/r;if(o<=0)return null;let i=We([e[0]+n[0]*o,e[1]+n[1]*o,e[2]+n[2]*o],t.o);return{t:o,u:Jt(i,t.eu),s:Jt(i,t.es)}}function Xs(t,e,n){if(t.unbounded)return!0;if(n<0||n>t.ls)return!1;let[r,o]=t.span(n);return e>=r&&e<=o}function Qs(t,e,n,r){return je(t,e).some(i=>{let s=i.corners.map(c=>{let d=We(c,t.o);return[Jt(d,t.eu),Jt(d,t.es)]}),l=s.map(c=>c[0]),a=s.map(c=>c[1]);return n>=Math.min(...l)-.05&&n<=Math.max(...l)+.05&&r>=Math.min(...a)-.05&&r<=Math.max(...a)+.05})}var fb=["n","ne","e","se","s","sw","w","nw"],Js=(t,e)=>fb[Math.round(Fr(t.facing,e)/45)%8];function Wr(t,e){let n=r=>{if(r.flat)return r.lu*r.ls*.8;let o=Math.cos((Fr(r.facing,e)-180)*Math.PI/180);return r.lu*r.ls*(1.2+o)};return[...t].sort((r,o)=>n(o)-n(r))[0]??null}var Jd=["kitchen_row","kitchen_l","bath","bedroom","living","dining","office","kids","hall"],Yd={kitchen_row:{rows:[["back","start",["fridge","kitchen_tall",["kitchen",[.9,.62,.92]],"sink","dishwasher","stove",["kitchen",[.6,.62,.92]]]],["back","start",[["kitchen_wall",[1.2,.35,.7]]]]],spots:[[["table",[1.2,.8,.75]],.5,.72,0],["lamp_pendant",.5,.72,0],["lamp_ceiling",.5,.3,0]]},kitchen_l:{rows:[["back","start",["fridge",["kitchen",[.9,.62,.92]],"sink","dishwasher","stove"]],["right","start",[["kitchen",[.9,.62,.92]],["kitchen",[.6,.62,.92]],"kitchen_tall"]],["back","start",[["kitchen_wall",[1.2,.35,.7]]]]],spots:[["table",.4,.68,0],["bar_stool",.72,.86,180],["lamp_ceiling",.5,.35,0]]},bath:{rows:[["back","center",["washbasin"]],["back","end",["wc"]],["front","start",["bathtub"]],["left","start",["washer"]]],spots:[["lamp_downlight",.5,.5,0]]},bedroom:{rows:[["back","center",["nightstand","bed","nightstand"]],["left","center",[["wardrobe",[2,.6,2.1]]]],["front","end",["dresser"]]],spots:[["lamp_ceiling",.5,.55,0]]},living:{rows:[["back","center",["tv_board"]],["right","start",["shelf"]]],spots:[["sofa",.5,.72,180],["coffee_table",.5,.52,0],[["rug",[2.2,1.6,.01]],.5,.55,0],["armchair",.14,.5,270],["lamp_floor",.86,.8,0],["plant",.9,.12,0],["lamp_ceiling",.5,.45,0]]},dining:{rows:[["back","center",["sideboard"]]],spots:[["table",.5,.55,0],["chair",.4,.35,0],["chair",.6,.35,0],["chair",.4,.75,180],["chair",.6,.75,180],["lamp_pendant",.5,.55,0]]},office:{rows:[["back","center",["desk"]],["left","center",["shelf","shelf"]]],spots:[["office_chair",.5,.38,180],["lamp_ceiling",.5,.55,0]]},kids:{rows:[["left","start",[["bed",[.9,2,.8]]]],["back","end",[["desk",[1.2,.6,.75]]]],["right","end",["shelf"]]],spots:[[["rug",[1.6,1.2,.01]],.55,.6,0],["lamp_ceiling",.5,.5,0]]},hall:{rows:[["left","start",["coat_rack"]]],spots:[["lamp_downlight",.5,.3,0],["lamp_downlight",.5,.7,0]]}},Xd=t=>typeof t=="string"?t:t[0],ri=t=>typeof t=="string"?et[t]:t[1],In=.05,mb=.02,Qd=t=>Math.round(t*1e3)/1e3;function gb(t,e,n,r){switch(e){case"back":return{x:t.x0+n,z:t.z0+r,turn:0};case"right":return{x:t.x1-r,z:t.z0+n,turn:90};case"front":return{x:t.x1-n,z:t.z1-r,turn:180};case"left":return{x:t.x0+r,z:t.z1-n,turn:270}}}function eu(t,e,n){let r=de(t.points),o=r.x1-r.x0,i=r.z1-r.z0,s=[],l=(a,c,d,u,[p,h,f])=>{s.push({id:n(),type:a,x:Qd(c),z:Qd(d),rotation:u,w:p,d:h,h:f,variant:null,entity:null,power:null})};for(let[a,c,d]of Yd[e].rows){let u=a==="back"||a==="front"?o:i,p=0,h=[];for(let g of d){if(p+ri(g)[0]>u-.1)break;h.push(g),p+=ri(g)[0]}let f=c==="start"?In:c==="end"?u-p-In:(u-p)/2;for(let g of h){let y=ri(g),b=gb(r,a,f+y[0]/2,y[1]/2+mb);l(Xd(g),b.x,b.z,b.turn,y),f+=y[0]}}for(let[a,c,d,u]of Yd[e].spots){let p=ri(a),h=(y,b,v)=>Math.min(v,Math.max(b,y)),f=h(r.x0+o*c,r.x0+p[0]/2+In,r.x1-p[0]/2-In),g=h(r.z0+i*d,r.z0+p[1]/2+In,r.z1-p[1]/2-In);l(Xd(a),f,g,u,p)}return s}var _b=30*Math.PI/180,tu=.05;function ea(t){let e=t.points.length;return t.points.map((n,r)=>{let o=t.points[(r+1)%e];return Math.hypot(o[0]-n[0],o[1]-n[1])})}function Vr(t){return ea(t).reduce((e,n)=>e+n,0)}function bb(t,e){let n=ea(t),r=0;for(let o=0;oh+f,0);if(o<3||!(i>0)||!(n>0))return null;let s=Math.min(n,i),l=(e%i+i)%i,a=0,c=0;for(;a=c+r[a];)c+=r[a],a++;let d=l-c,u=s,p=[];for(let h=0;h<=o&&u>1e-9;h++){let f=r[a]-d,g=Math.min(u,f);g>1e-9&&p.push({edge:a,t0:d,t1:d+g}),u-=g,d=0;let y=(a+1)%o;if(u>1e-9&&yb(t,a)>_b)break;a=y}for(;p.length>1&&p[0].t1-p[0].t01&&p[p.length-1].t1-p[p.length-1].t0({edge:h.edge,offset:(h.t0+h.t1)/2,width:h.t1-h.t0})):null}function Dn(t,e){let n=e[0];return n?{from:bb(t,n.edge)+n.offset-n.width/2,width:e.reduce((r,o)=>r+o.width,0)}:null}function It(t,e){return e.front?t.filter(n=>n.front===e.front):[e]}function na(t,e){let n=t.points.length,r=1/0,o=0,i=0;for(let s=0;sD("opening")){let s=ta(e,r,o);if(!s)return null;let l=It(t,n),a=new Set(l.map(h=>h.id)),c=s.length>1?l[0].front??`front-${l[0].id}`:null,d=s.map((h,f)=>({...n,id:f===0?l[0].id:i(),edge:h.edge,offset:h.offset,width:h.width,front:c})),u=[],p=!1;for(let h of t){if(!a.has(h.id)){u.push(h);continue}p||(u.push(...d),p=!0)}return u}var ia=globalThis,ra=ia.__nextfloorBuiltin?.de??{},oa=ia.__nextfloorBuiltin?.en??{};ia.__nextfloorBuiltin??={de:ra,en:oa};var wb=()=>typeof S=="object"&&S||{},vb=globalThis,kb=vb.__nextfloorTexts??=new Map;function xb(t){let e=t.toLowerCase().split("-")[0];return e!=="de"&&e!=="en"&&e in wb()?e:void 0}function nu(t){let e=xb(t),n=e===void 0?void 0:kb.get(e);return n instanceof Promise?void 0:n}function oi(t,e){return nu(t)?.[e]}function xe(t,e,n={}){let r=t?.language??navigator.language,o=r.startsWith("de"),i=(o?void 0:nu(r)?.[e])??(o?ra:oa)[e]??oa[e]??ra[e]??e;for(let[s,l]of Object.entries(n))i=i.replace(`{${s}}`,String(l));return i}function j(t,e,n=2){return e.toLocaleString(t?.language??void 0,{maximumFractionDigits:n})}var Me=se` +\f\r"'\`<>=]|("|')|))|$)`,"g"),Zl=/'/g,ql=/"/g,Ql=/^(?:script|style|textarea|title)$/i,rs=t=>(e,...n)=>({_$litType$:t,strings:e,values:n}),m=rs(1),R=rs(2),Ak=rs(3),Qe=Symbol.for("lit-noChange"),_=Symbol.for("lit-nothing"),Yl=new WeakMap,Gt=jt.createTreeWalker(jt,129);function Jl(t,e){if(!ns(t)||!t.hasOwnProperty("raw"))throw Error("invalid template strings array");return Gl!==void 0?Gl.createHTML(e):e}var ec=(t,e)=>{let n=t.length-1,r=[],o,i=e===2?"":e===3?"":"",s=dr;for(let l=0;l"?(s=o??dr,u=-1):d[1]===void 0?u=-2:(u=s.lastIndex-d[2].length,c=d[1],s=d[3]===void 0?Kt:d[3]==='"'?ql:Zl):s===ql||s===Zl?s=Kt:s===jl||s===Ul?s=dr:(s=Kt,o=void 0);let h=s===Kt&&t[l+1].startsWith("/>")?" ":"";i+=s===dr?a+i_:u>=0?(r.push(c),a.slice(0,u)+es+a.slice(u)+mt+h):a+mt+(u===-2?l:h)}return[Jl(t,i+(t[n]||"")+(e===2?"":e===3?"":"")),r]},pr=class t{constructor({strings:e,_$litType$:n},r){let o;this.parts=[];let i=0,s=0,l=e.length-1,a=this.parts,[c,d]=ec(e,n);if(this.el=t.createElement(c,r),Gt.currentNode=this.el.content,n===2||n===3){let u=this.el.content.firstChild;u.replaceWith(...u.childNodes)}for(;(o=Gt.nextNode())!==null&&a.length0){o.textContent=vo?vo.emptyScript:"";for(let h=0;h2||r[0]!==""||r[1]!==""?(this._$AH=Array(r.length-1).fill(new String),this.strings=r):this._$AH=_}_$AI(e,n=this,r,o){let i=this.strings,s=!1;if(i===void 0)e=Ut(this,e,n,0),s=!hr(e)||e!==this._$AH&&e!==Qe,s&&(this._$AH=e);else{let l=e,a,c;for(e=i[0],a=0;a{let r=n?.renderBefore??e,o=r._$litPart$;if(o===void 0){let i=n?.renderBefore??null;r._$litPart$=o=new bn(e.insertBefore(ur(),i),i,void 0,n??{})}return o._$AI(t),o};var os=globalThis,ne=class extends ft{constructor(){super(...arguments),this.renderOptions={host:this},this._$Do=void 0}createRenderRoot(){let e=super.createRenderRoot();return this.renderOptions.renderBefore??=e.firstChild,e}update(e){let n=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(e),this._$Do=nc(n,this.renderRoot,this.renderOptions)}connectedCallback(){super.connectedCallback(),this._$Do?.setConnected(!0)}disconnectedCallback(){super.disconnectedCallback(),this._$Do?.setConnected(!1)}render(){return Qe}};ne._$litElement$=!0,ne.finalized=!0,os.litElementHydrateSupport?.({LitElement:ne});var a_=os.litElementPolyfillSupport;a_?.({LitElement:ne});(os.litElementVersions??=[]).push("4.2.2");var Je=(t,e,n={})=>t.callWS({type:`nextfloor/${e}`,...n});async function Ro(t,e){return(await Je(t,"image/get",{image_id:e})).data}async function St(t,e,n){await Je(t,"image/set",{image_id:e,data:n})}async function rc(t){return(await Je(t,"history/list")).snapshots}async function oc(t,e){return(await Je(t,"history/snapshot",e?{name:e}:{})).id}async function ic(t,e){return(await Je(t,"history/get",{snapshot_id:e})).building}async function sc(t,e){await Je(t,"history/delete",{snapshot_id:e})}async function ac(t,e){return(await Je(t,"history/restore",{snapshot_id:e})).revision}var fr=(t,e)=>Je(t,"packs/import",{pack:e});async function lc(t,e){await Je(t,"packs/remove",{pack_id:e})}var cc=t=>Je(t,"backup/export"),dc=(t,e,n)=>Je(t,"backup/import",{building:e,packs:n});var ss=t=>t.slice(0,t.indexOf(".")),l_={light:"light",switch:"switch",input_boolean:"switch",valve:"switch",fan:"fan",cover:"cover",climate:"climate",media_player:"media",lock:"lock",sensor:"sensor",binary_sensor:"binary",event:"sensor",scene:"scene",script:"script"},X=t=>l_[ss(t)]??null,as=["light","cover","climate","media","switch","fan","lock","binary","sensor","scene","script"];var uc=new Set(["light","switch","fan"]),Mt=t=>t!==null&&t!=="scene"&&t!=="script",Rt=t=>!t||t.state==="unavailable"||t.state==="unknown"&&!t.entity_id.startsWith("event.");function W(t,e,n){let r=String(t?.states[e]?.attributes.friendly_name??t?.entities?.[e]?.name??e);if(!n||r.length<=n.length+1||!r.toLowerCase().startsWith(`${n.toLowerCase()} `))return r;let o=r.slice(n.length+1);return o[0].toUpperCase()+o.slice(1)}var hc=t=>!!t&&t.entity_id.startsWith("sensor.")&&t.attributes.device_class==="enum";var pc=t=>Math.min(1,Math.max(0,t));function c_(t){let e=pc((t-2200)/4300),n=[1,.66,.26],r=[.78,.9,1];return[0,1,2].map(o=>n[o]+(r[o]-n[o])*e)}function is(t,e){if(!t||t.state!=="on")return null;let n=e&&!["unavailable","unknown"].includes(e.state)?e.attributes:t.attributes,r=typeof n.brightness=="number"?.2+.8*Math.sqrt(pc(n.brightness/255)):1,o=n.rgb_color;return o&&!["color_temp","brightness","onoff"].includes(String(n.color_mode))?{color:[o[0]/255,o[1]/255,o[2]/255],level:r}:typeof n.color_temp_kelvin=="number"?{color:c_(n.color_temp_kelvin),level:r}:{color:[1,.71,.28],level:r}}function fc(t,e,n){let r=is(t,n);if(r)return r;for(let o of e){let i=is(o);if(i)return{color:i.color,level:i.level*.6}}return null}function Eo(t,e,n=null){if(t==="light"&&n==="floor")return 1.95;if(t==="light"&&n==="table")return 1.25;if(t==="light"&&n==="wall")return 1.95;switch(t){case"light":return Math.max(.5,e-.25);case"cover":return Math.min(2,e-.3);case"climate":return .6;case"media":return .9;case"binary":case"sensor":return 1.4;default:return 1.05}}var bc=[],Ao=new Map,d_=0,ue=(t,e)=>`pack:${t}:${e}`,gt=t=>t.startsWith("pack:");function ls(t){bc=t,Ao=new Map;for(let e of t)for(let n of e.items)Ao.set(ue(e.id,n.id),n);d_+=1}var gr=()=>bc;var u_={};function G(t){if(!gt(t))return;let e=Ao.get(t);if(e)return e;let[,n,...r]=t.split(":"),o=u_[n];return o?Ao.get(ue(o,r.join(":"))):void 0}var h_=.22;function mc(t,e,n,r){let o=Math.min(h_,n/3);if(r<=o*2.4||Math.abs(r-n)<1e-6)return e*(r/n)+(t-e)*(r/n);let i=e*(r/n),s=t-e;return s<=o?i+s:s>=n-o?i+r-(n-s):i+o+(s-o)*(r-2*o)/(n-2*o)}function mr(t,e,n,r,o){return[mc(t*r,n*r,r,o)/o,mc(e*r,n*r,r,o)/o]}var gc=new WeakMap;function yc(t,e,n,r){let[o,i,s]=t.size;if(t.vehicle||t.stretch||Math.abs(e-o)<1e-4&&Math.abs(n-i)<1e-4&&Math.abs(r-s)<1e-4)return t.parts;let l=`${e.toFixed(4)}|${n.toFixed(4)}|${r.toFixed(4)}`,a=gc.get(t),c=a?.get(l);if(c)return c;let d=t.parts.map(u=>{if(u.shape==="sweep")return u;let[p,h]=mr(u.x-u.w/2,u.x+u.w/2,-.5,o,e),[f,g]=mr(u.z-u.d/2,u.z+u.d/2,-.5,i,n),[y,b]=mr(u.y,u.y+u.h,0,s,r);if(u.rot)return{...u,x:(p+h)/2,z:(f+g)/2,w:u.w*o/e,d:u.d*i/n,y,h:b-y};let v={...u,x:(p+h)/2,z:(f+g)/2,w:h-p,d:g-f,y,h:b-y};if(u.shape==="loft"){let[w,x,k,$]=[u.tx??u.x,u.tz??u.z,u.tw??u.w,u.td??u.d],[A,F]=mr(w-k/2,w+k/2,-.5,o,e),[T,I]=mr(x-$/2,x+$/2,-.5,i,n);Object.assign(v,{tx:(A+F)/2,tz:(T+I)/2,tw:F-A,td:I-T})}return v});return a||gc.set(t,a=new Map),a.size>32&&a.clear(),a.set(l,d),d}var cs=t=>!!t?.parts.some(e=>e.move);var wc=t=>G(t)?.parts.find(e=>e.screen),_c=.06;function vc(t){let e=G(t);if(!e)return!1;let[n,r,o]=e.size;return e.parts.filter(i=>i.screen).some(i=>{let[s,l]=[i.w*n,i.d*r,i.h*o].sort((a,c)=>c-a);return l>=_c&&s>=_c})}function at(t){return et[t]??G(t)?.size??[.6,.6,.8]}function Et(t){let e=G(t);return Ac.has(t)||!!e?.electric||!!e?.light||!!e?.climate}var kc=t=>!!G(t)?.parts.some(e=>e.picture),yn=t=>!!G(t)?.climate;function xc(t,e){return t.name[e.split("-")[0]]??t.name.en??Object.values(t.name)[0]??t.id}var p_={wohnen:"Living & Pets",kino:"Home Cinema & Gaming",kueche:"Kitchen Extras",bad:"Bathroom Extras",schlafen:"Bedroom & Kids",technik:"Office & Homelab",energie:"Energy & Building Services",garten:"Garden & Terrace (older)",fitness:"Fitness (older)",fahrzeuge:"Vehicles",ikea:"IKEA sizes",treppen:"Stairs & railings",ausbau:"Architecture & fit-out",werkstatt:"Garage & workshop",a_wohnzimmer:"Living room",a_schlafzimmer:"Bedroom",a_kueche:"Kitchen",a_bad:"Bathroom",a_kinderzimmer:"Kids' room",a_buero:"Office & gaming",a_fitness:"Fitness",a_haustiere:"Pets",a_garten:"Garden & patio",a_kino:"Home cinema & hi-fi",a_smart:"Smart home & tech",a_haustechnik:"Utility & building services",a_saison:"Season & decoration",a_smart2:"Smart home 2",a_haustechnik2:"Building services 2",a_wellness:"Wellness",a_garten2:"Garden 2",a_kueche2:"Kitchen 2",a_fahrzeuge2:"Vehicles 2",a_aussenkueche:"Outdoor kitchen & terrace",a_werkstatt2:"Workshop 2",a_japandi:"Japandi & Scandi",a_loft:"Loft & industrial",a_gruen:"Indoor greenery",a_musik:"Music & studio",a_bilder:"Pictures & frames"};function $c(t,e){if(e.split("-")[0]==="de")return t.name;let n=/^nextfloor\.(.+)$/.exec(t.id)?.[1];return n&&p_[n]||t.name}function At(t,e){return e.mount_y!=null?e.mount_y:m_(t,e)+(f_(e)?0:Rc(t,e.x,e.z))}var f_=t=>t.type==="led_strip"||G(t.type)?.mount==="ceiling";function m_(t,e){if(e.type==="lamp_wall")return Sc;if(e.type==="led_strip")return Math.max(0,lt(t,e.x,e.z)-.04-Math.max(.02,e.h));let n=G(e.type);if(!n)return Mc(e);switch(n.mount){case"surface":return Ec(t,e.x,e.z);case"wall":return n.wall_y??1;case"ceiling":return Math.max(0,Fo(t,e)-e.h);default:return 0}}function ds(t){if(t==="plant")return"plant";let e=G(t);return e?e.household?e.household:/monstera|plant|herb_garden|flower_pots|bonsai|ficus|cactus|kaktus/.test(e.id)?"plant":null:null}var Fc=["turn","slide","top"],Tc=["always","active","no_power","never"],zc=1.3,To=(t,e=new Date().toISOString().slice(0,10))=>!!t.due&&t.due<=e,Pc=["gable","hip","halfhip","pyramid","mansard","pent","flat","parapet"],Ic=["brick","round","wide","steel"],zo=["navigate","more_info","service","fire_dom_event"];function Po(t,e,n){return t?e?!!n.lock_plan:!!t.locked:!1}var Dc=["rain","snow","fog","clouds","lightning","sky"],Oc=["rain","snow","clouds","lightning","sky"],Hc=["lawn","terrace","path","driveway","pool","bed","wild","hedge","fence","pergola"],us={lawn:.012,terrace:.12,path:.02,driveway:.02,pool:-.25,bed:.15,wild:.03,hedge:1.2,fence:1,pergola:2.2};function hs(t){return t==="hedge"||t==="fence"||t==="pergola"}var Lc=["x","-x","z","-z"];function g_(t,e,n){let r=t.slope??0;if(!r||t.type==="pool")return 0;let o=t.slope_dir??"x",i=(c,d)=>o==="x"?c:o==="-x"?-c:o==="z"?d:-d,s=1/0,l=-1/0;for(let[c,d]of t.points){let u=i(c,d);s=Math.min(s,u),l=Math.max(l,u)}if(l-s<1e-6)return 0;let a=Math.min(1,Math.max(0,(i(e,n)-s)/(l-s)));return r*a}function __(t,e,n,r){return Cc(t)+(e.offset??0)+us[e.type]-g_(e,n,r)}function Cc(t){return t.elevation>.3?0:-.2}function Nc(t,e,n){let r=(t.outdoor??[]).filter(i=>!hs(i.type)&&i.type!=="pool"&&N([e,n],i.points)),o=[...r].reverse().find(i=>i.cut)??r[0];return o?__(t,o,e,n):Cc(t)}var Bc=t=>t.cut??t.type==="pool",Wc=30,Vc={meter:null,grid:null,grid_invert:!1,solar:null,battery:null,battery_invert:!1,battery_soc:null,consumption:null,tariff:null},Kc=["wood","oak","tiles","carpet","stone","concrete"],Gc={type:"none",pitch:35,overhang:.4},Io="#d6cfc2",Do="#e8e3da",jc={wall_exterior:.24,wall_interior:.12,grid:.05,north:0,roof:{...Gc}};function Ft(){return{version:1,floors:[],settings:{...jc},energy:{...Vc},presence:[]}}function Le(t,e,n){return{id:t,name:e,elevation:n,height:2.5,cut_height:1.15,rooms:[],openings:[],furniture:[],placements:[],background:null,outdoor:[],walls:[],ha_floor:null}}var b_=2.75;function Uc(t,e){if(e!=null&&Number.isFinite(e))return Math.round(e*b_*100)/100;let n=t.reduce((r,o)=>!r||o.elevation>r.elevation?o:r,null);return n?Math.round((n.elevation+n.height+.25)*100)/100:0}function Zc(t,e,n){let r=t.rooms.flatMap(l=>l.points.map(a=>a[0])),o=t.rooms.flatMap(l=>l.points.map(a=>a[1])),i=r.length?Math.ceil(Math.max(...r))+1:0,s=o.length?Math.floor(Math.min(...o)):0;return e.map((l,a)=>{let c=i+a%3*4.5,d=s+Math.floor(a/3)*3.5;return{id:n(),name:l.name,area_id:l.area_id,points:[[c,d],[c+4,d],[c+4,d+3],[c,d+3]],floor_material:"wood"}})}function qc(t,e,n,r){let o=t.rotation*Math.PI/180,i=Math.cos(o),s=Math.sin(o),[l,a]=e,c=t.x-l*(t.w/2)*i+a*(t.d/2)*s,d=t.z-l*(t.w/2)*s-a*(t.d/2)*i,u=n[0]-c,p=n[1]-d,h=b=>Math.max(.1,Math.round(b/r)*r),f=h((u*i+p*s)*l),g=h((-u*s+p*i)*a),y=b=>Math.round(b*1e3)/1e3;return{x:y(c+l*(f/2)*i-a*(g/2)*s),z:y(d+l*(f/2)*s+a*(g/2)*i),w:y(f),d:y(g)}}var Oo=["lamp_ceiling","lamp_downlight","lamp_spot","lamp_panel","lamp_pendant","ceiling_fan","lamp_floor","lamp_table","lamp_wall","led_strip","lamp_uplight","lamp_bollard","lamp_garden","radiator","sofa","armchair","stool","coffee_table","tv_board","tv_wall","sideboard","shelf","plant","rug","table","table_round","chair","bench","corner_bench","bar_stool","kitchen","kitchen_wall","kitchen_tall","island","worktop","sink","stove","dishwasher","fridge","bed","bunk_bed","nightstand","wardrobe","dresser","bathtub","shower","wc","washbasin","washer","dryer","desk","office_chair","tall_cabinet","coat_rack","stairs","robot_vacuum","inverter","home_battery","wallbox","meter","grid_point","parking","fridge_smart","stairwell"],Yc={lights:["lamp_ceiling","lamp_downlight","lamp_spot","lamp_panel","lamp_pendant","ceiling_fan","lamp_floor","lamp_uplight","lamp_table","lamp_wall","led_strip","lamp_bollard","lamp_garden"],living:["sofa","armchair","stool","coffee_table","tv_board","tv_wall","sideboard","shelf","plant","rug"],dining:["table","table_round","chair","bench","corner_bench","bar_stool"],kitchen:["kitchen","kitchen_wall","kitchen_tall","island","worktop","sink","stove","dishwasher","fridge"],sleeping:["bed","bunk_bed","nightstand","wardrobe","dresser"],bath:["bathtub","shower","wc","washbasin","washer","dryer"],work:["desk","worktop","office_chair","tall_cabinet","coat_rack","radiator","stairs","robot_vacuum"],vehicles:["parking"]},Ce=["meter","inverter","home_battery","wallbox","grid_point"],Xc=new Set(["lamp_ceiling","lamp_downlight","lamp_spot","lamp_panel","lamp_pendant","ceiling_fan","lamp_floor","lamp_uplight","lamp_table","lamp_wall","led_strip","lamp_bollard","lamp_garden"]),Sc=1.75;function Ho(t){return ps.has(t.type)||["stairwell","parking"].includes(t.type)?!1:G(t.type)?.mount!=="ceiling"}function ce(t){return Xc.has(t)||!!G(t)?.light}var y_=new Set(["table","table_round","coffee_table","desk","nightstand","sideboard","dresser","kitchen","island","worktop","tv_board","dishwasher","washer","dryer"]);function Qc(t,e,n,r=0){let o=de(t.points),i=o.x1-o.x0-2*r,s=o.z1-o.z0-2*r,l=[];for(let a=0;aMath.round(s*1e3)/1e3,[o,i]={right:[1,0],down:[0,1],left:[-1,0],up:[0,-1]}[n];return[r(t[0]+o*e),r(t[1]+i*e)]}function Mc(t){switch(t.type){case"home_battery":return t.variant==="wall"?.5:0;case"kitchen_wall":return 1.45;case"tv_wall":return Math.max(0,1.3-t.h/2);case"radiator":return .12;case"inverter":return 1.1;case"wallbox":return 1;case"meter":return .4;default:return 0}}var ps=new Set(["lamp_ceiling","lamp_downlight","lamp_spot","lamp_panel","lamp_pendant","ceiling_fan"]);function Jc(t,e){return t.filter(n=>n.elevationn.rooms.filter(r=>r.points.length>=3&&r.ceiling!=null&&r.ceiling>n.height+.005&&n.elevation+r.ceiling>e.elevation+.05)).map(n=>n.points)}var fs=t=>t?.floor_offset&&Number.isFinite(t.floor_offset)?t.floor_offset:0;function Rc(t,e,n){let r=t.rooms.find(o=>o.points.length>=3&&o.floor_offset&&N([e,n],o.points));return fs(r)}function lt(t,e,n){let r=t.rooms.find(o=>o.points.length>=3&&N([e,n],o.points));return r?.ceiling!=null&&r.ceiling>0?r.ceiling:t.height}var Fo=(t,e)=>e.ceiling_y!=null&&e.ceiling_y>0?e.ceiling_y:lt(t,e.x,e.z);function Ec(t,e,n){let r=0;for(let o of t.furniture)!(y_.has(o.type)||G(o.type)?.surface)||!N([e,n],bs(o))||(r=Math.max(r,o.h));return r}var Ac=new Set([...Xc,"radiator","robot_vacuum","inverter","home_battery","wallbox","meter","tv_board","tv_wall","desk","fridge","fridge_smart","stove","kitchen_tall","dishwasher","washer","dryer","kitchen","island","sink"]),et={sofa:[2.2,.9,.82],armchair:[.85,.85,.8],table:[1.6,.9,.75],chair:[.46,.5,.9],bed:[1.6,2.05,.9],nightstand:[.45,.4,.5],wardrobe:[1.8,.6,2.1],shelf:[.9,.35,1.9],kitchen:[2.4,.62,.92],worktop:[1.2,.62,.91],inverter:[.5,.2,.65],home_battery:[.6,.25,1.1],wallbox:[.3,.15,.42],meter:[.55,.21,1.1],grid_point:[.4,.22,.6],fridge:[.6,.65,1.8],fridge_smart:[.91,.73,1.78],stairwell:[1,2.6,.02],stove:[.6,.62,.92],sink:[.9,.62,.92],bathtub:[1.7,.75,.58],shower:[.9,.9,2],wc:[.38,.6,.8],washbasin:[.6,.46,.85],desk:[1.4,.7,.75],tv_board:[1.8,.42,.5],plant:[.45,.45,1.1],rug:[2,1.4,.01],stairs:[1,3.2,2.75],stool:[.55,.55,.42],lamp_ceiling:[.4,.4,.08],lamp_downlight:[.1,.1,.02],lamp_spot:[.1,.1,.14],lamp_panel:[.6,.6,.03],lamp_uplight:[.35,.35,1.8],lamp_bollard:[.16,.16,.8],lamp_garden:[.12,.12,.3],radiator:[1,.1,.6],robot_vacuum:[.36,.5,.1],parking:[2.6,5.2,.02],lamp_pendant:[.4,.4,.8],ceiling_fan:[1.32,1.32,.32],lamp_floor:[.4,.4,1.7],lamp_table:[.28,.28,.45],lamp_wall:[.22,.12,.2],led_strip:[2,.04,.03],coffee_table:[1.1,.6,.42],tv_wall:[1.3,.08,.75],sideboard:[1.6,.45,.8],table_round:[1.1,1.1,.75],bench:[1.4,.45,.85],corner_bench:[2,1.6,.9],bar_stool:[.42,.42,.75],kitchen_wall:[.8,.35,.7],kitchen_tall:[.6,.62,2.1],island:[1.8,.9,.92],dishwasher:[.6,.62,.92],bunk_bed:[1,2.05,1.65],dresser:[1,.5,.9],washer:[.6,.6,.85],dryer:[.6,.6,.85],office_chair:[.65,.65,1.1],tall_cabinet:[.6,.6,2.1],coat_rack:[1,.35,1.9]};var ms=["interior","front","front_glass","sidelight","sidelights","glass","sliding","passage"],gs=["standard","bars","glass_wall"],Lo=new Set(["interior","front"]);function qt(t,e){return t.type==="door"?t.style&&ms.includes(t.style)?t.style:e?"front":"interior":t.style&&gs.includes(t.style)?t.style:"standard"}function ed(t,e,n,r){if(e!=="sidelight"&&e!=="sidelights")return null;let o=e==="sidelights",i=t-.04,s=Math.min(1.05,Math.max(.6,i-(o?.6:.3))),l=(i-s)/(o?2:1),a=r.sidelight_width??l,c=o?r.sidelight_width2??r.sidelight_width??l:0;a=Math.max(.1,a),c=o?Math.max(.1,c):0;let d=i-.5;if(a+c>d){let p=Math.max(0,d)/(a+c);a*=p,c*=p}return o?{panels:[[.02,.02+a],[t-.02-c,t-.02]],x0:.02+a,x1:t-.02-c}:(n?!!r.sidelight_hinge:!r.sidelight_hinge)?{panels:[[.02,.02+a]],x0:.02+a,x1:t-.02}:{panels:[[t-.02-a,t-.02]],x0:.02,x1:t-.02-a}}function _s(t){return t==="front"||t==="front_glass"||t==="sidelight"||t==="sidelights"}var vn={door:{type:"door",leaves:1,width:.9,sill:0,height:2.05,style:"interior"},front:{type:"door",leaves:1,width:1,sill:0,height:2.1,style:"front"},door_double:{type:"door",leaves:2,width:1.6,sill:0,height:2.05},window:{type:"window",leaves:1,width:1.2,sill:.9,height:1.3},window_double:{type:"window",leaves:2,width:1.6,sill:.9,height:1.3},terrace:{type:"window",leaves:1,width:1,sill:0,height:2.1},terrace_double:{type:"window",leaves:2,width:1.8,sill:0,height:2.1},lift_slide:{type:"window",leaves:1,width:2.4,sill:0,height:2.15,opens:"slide"},garage:{type:"garage",leaves:1,width:2.5,sill:0,height:2.1},glass_wall:{type:"window",leaves:1,width:2,sill:0,height:2.4,style:"glass_wall"}};function kn(t){if(t.type==="garage")return"garage";if(t.type==="window"&&t.style==="glass_wall")return"glass_wall";if(t.type==="window"&&t.opens==="slide"&&t.sill<.1)return"lift_slide";let e=t.leaves===2;return t.type==="door"?!e&&t.style&&_s(t.style)?"front":e?"door_double":"door":t.sill<.1?e?"terrace_double":"terrace":e?"window_double":"window"}function ze(t){t.energy={...Vc,...t.energy??{}},t.presence=t.presence??[],t.version=1,t.settings={...jc,...t.settings,roof:{...Gc,...t.settings?.roof??{}}},t.floors.forEach((e,n)=>{let r=Le(e.id,e.name??`Floor ${n+1}`,e.elevation??n*2.8);for(let o of Object.keys(r))e[o]===void 0&&(e[o]=r[o])});for(let e of t.floors){e.outdoor=e.outdoor??[],e.walls=e.walls??[],e.rooms=e.rooms.map(r=>({...r,name:r.name??"",area_id:r.area_id??null,floor_material:r.floor_material??"wood",panel:r.panel??[]})),e.ha_floor=e.ha_floor??null,e.placements=e.placements.map(r=>({...r,mount:r.mount??null,rotation:r.rotation??0})),e.furniture=e.furniture.map(r=>({...r,entity:r.entity??null,power:r.power??null}));let n=e.placements.filter(r=>r.entity_id.startsWith("light."));if(n.length){let r={ceiling:"lamp_ceiling",floor:"lamp_floor",table:"lamp_table",wall:"lamp_wall"};for(let o of n){let i=r[o.mount??"ceiling"],[s,l,a]=et[i],c=`lamp_${o.entity_id.slice(6).replace(/[^A-Za-z0-9_\-.]/g,"_")}`.slice(0,54),d=c,u=1;for(;e.furniture.some(p=>p.id===d);)d=`${c}_${u++}`;e.furniture.push({id:d,type:i,x:o.x,z:o.z,rotation:0,w:s,d:l,h:a,variant:null,entity:o.entity_id,power:null,animations_enabled:o.animations_enabled,effect_animations:structuredClone(o.effect_animations)})}e.placements=e.placements.filter(o=>!o.entity_id.startsWith("light."))}e.openings=e.openings.map(r=>({...r,type:["door","window","garage"].includes(r.type)?r.type:"door",edge:Number.isInteger(r.edge)?r.edge:0,offset:Number.isFinite(r.offset)?r.offset:.5,width:Number.isFinite(r.width)&&r.width>0?r.width:r.type==="garage"?2.5:r.type==="window"?1.2:.9,height:Number.isFinite(r.height)&&r.height>0?r.height:r.type==="window"?1.3:r.type==="garage"?2.1:2.05,sill:Number.isFinite(r.sill)?r.sill:r.type==="window"?.9:0,hinge:r.hinge??"left",leaves:r.leaves??1,swing:r.swing??"in",style:r.style??null,cover:r.cover??null,contact:r.contact??null,contact2:r.contact2??null,tilt:r.tilt??null}))}return w_(t),t}function w_(t){let e=(n,r)=>{let o=new Set;for(let i of n)(typeof i.id!="string"||!i.id||o.has(i.id))&&(i.id=D(r)),o.add(i.id)};e(t.floors,"floor");for(let n of t.floors){for(let r of n.rooms)(typeof r.id!="string"||!r.id)&&(r.id=D("room"));e(n.openings,"op"),e(n.furniture,"furn"),e(n.outdoor,"out")}}function D(t){return`${t}_${Math.random().toString(36).slice(2,10)}`}function ge(t){let e=0;for(let n=0;ni+s[0],0)/o,t.reduce((i,s)=>i+s[1],0)/o]}let n=0,r=0;for(let o=0;o1e-6&&Math.abs(r-i)>1e-6)return!1}return!0}function de(t){let e=1/0,n=1/0,r=-1/0,o=-1/0;for(let[i,s]of t)e=Math.min(e,i),n=Math.min(n,s),r=Math.max(r,i),o=Math.max(o,s);return{x0:e,z0:n,x1:r,z1:o}}function bs(t){let e=t.rotation*Math.PI/180,n=Math.cos(e),r=Math.sin(e),o=t.w/2,i=t.d/2;return[[-o,-i],[o,-i],[o,i],[-o,i]].map(([s,l])=>[t.x+s*n-l*r,t.z+s*r+l*n])}function N(t,e){let n=!1;for(let r=0,o=e.length-1;rt[1]!=a>t[1]&&t[0]<(l-i)*(t[1]-s)/(a-s)+i&&(n=!n)}return n}var Co={lamp_ceiling:"ceiling",lamp_downlight:"downlight",lamp_spot:"spot",lamp_panel:"panel",lamp_uplight:"uplight",lamp_bollard:"bollard",lamp_garden:"garden",lamp_pendant:"pendant",ceiling_fan:"fan",lamp_floor:"floor",lamp_table:"table",lamp_wall:"wall",led_strip:"strip"};var ys=t=>t.trim().replace(/^\/local\/www\//i,"/local/"),ws=t=>/^(https:\/\/|\/local\/|\/hacsfiles\/)\S+\.m?js(\?\S*)?$/i.test(t.trim());var k_=globalThis,nd=k_.__nextfloorPluginStore??={plugins:new Map,listeners:new Set},vs=nd.plugins,td=nd.listeners;var x_=5;function rd(t,e){t.errors.lengthtd.delete(t)}var ks=()=>[...vs.values()].map(t=>t.status),od=()=>[...vs.values()].flatMap(t=>Object.keys(t.plugin.lightAnimations??{}));function*Bo(t,e){for(let{plugin:n,status:r}of vs.values())for(let o of n.devices??[]){let i=!1;try{i=o.match(t,e)}catch(s){rd(r,s)}i&&(yield{device:o,status:r})}}function Wo(t,e){for(let{device:n}of Bo(t,e))return n.kind??"sensor";return null}function id(t,e){let n=t.states[e];if(!n)return null;let r=$_({hass:t,entityId:e,state:n})?.icon?.trim();return r&&/^mdi:[a-z0-9-]+$/i.test(r)?r:null}function $_(t){let e=null;for(let{device:n,status:r}of Bo(t.entityId,t.state))if(n.marker)try{let o=n.marker(t);if(!o)continue;e={...e??{}},typeof o.icon=="string"&&o.icon&&(e.icon=o.icon),typeof o.text=="string"&&(e.text=o.text.slice(0,60)),typeof o.active=="boolean"&&(e.active=o.active)}catch(o){rd(r,o)}return e}function Vo(t,e){return t?typeof t=="string"?t:t[e]??t[e.split("-")[0]]??t.en??Object.values(t)[0]??"":""}function sd(t,e){let n=[];for(let{device:r,status:o}of Bo(t,e))r.settings?.length&&n.push({pluginId:o.id,name:o.name,settings:r.settings});return n}function ad(t,e){let n={};for(let r of t??[]){let o=e?.[r.key],i=r.type==="number"?typeof o=="number"&&Number.isFinite(o):r.type==="boolean"?typeof o=="boolean":typeof o=="string"&&(r.options??[]).some(([s])=>s===o);n[r.key]=i?o:r.default}return n}function ld(t,e){for(let{device:n}of Bo(t,e))if(n.floorWedge)return!0;return!1}var S_=new Set(["temperature","humidity","power","carbon_dioxide","energy","gas","water","volume","volume_storage","volume_flow_rate","illuminance","pressure","atmospheric_pressure","pm1","pm25","pm10","volatile_organic_compounds","volatile_organic_compounds_parts","carbon_monoxide","nitrogen_dioxide","moisture","sound_pressure"]),M_=new Set(["m\xB3","m3","L","l","kWh","Wh","MWh","lx"]),R_=new Set(["door","window","opening","garage_door","motion","occupancy","presence","smoke","moisture","gas","carbon_monoxide"]),E_=new Set(["battery","signal_strength","timestamp","date","duration","data_rate","data_size","frequency","enum"]);function Tt(t,e){let n=t.entities?.[e];return n&&(n.area_id||(n.device_id?t.devices?.[n.device_id]?.area_id:null))||null}var dd=(t,e)=>{let n=t.entities?.[e];return!!(n?.hidden||n?.entity_category)},Ne=(t,e)=>X(e)??Wo(e,t.states[e]);function cd(t,e){let n=t.states[e];if(!n||dd(t,e))return!1;if(Wo(e,n)!==null)return!0;let r=X(e);if(!r)return!1;let o=n.attributes.device_class;return e.startsWith("event.")?!o||o==="button"||o==="doorbell":r==="sensor"?o?S_.has(o):M_.has(String(n.attributes.unit_of_measurement??"")):r==="binary"?o?R_.has(o):!!t.entities?.[e]?.area_id:!0}function A_(t,e){let n=t.states[e];return X(e)!=="sensor"||!n?.attributes.unit_of_measurement||dd(t,e)||E_.has(String(n.attributes.device_class??""))?!1:Number.isFinite(Number(n.state))||Rt(n)}var Go=(t,e)=>e.startsWith("sensor.")&&t.states[e]?.attributes.device_class==="power",xs=null;No(()=>xs=null);function $s(t,e){let n=t.get(e);return n||t.set(e,n=[]),n}function F_(t){let e=new Map,n=new Map,r=new Map,o=new Map,i=[],s=d=>{(cd(t,d)||A_(t,d))&&Mt(Ne(t,d))&&i.push(d)};for(let[d,u]of Object.entries(t.entities??{})){let p=u.device_id;p&&u.area_id&&(o.get(p)??o.set(p,new Set).get(p)).add(u.area_id),p&&Go(t,d)&&$s(n,p).push(d),p&&!u.hidden&&!u.entity_category&&(r.get(p)??r.set(p,new Set).get(p)).add(ss(d));let h=Tt(t,d);h===null?s(d):cd(t,d)&&$s(e,h).push(d)}if(t.entities)for(let d of Object.keys(t.states))t.entities[d]||s(d);let l=as.indexOf("binary")-.5,a=d=>{let u=X(d),p=u?as.indexOf(u):l;return p>l&&Wo(d,t.states[d])!==null?l:p};i.sort((d,u)=>a(d)-a(u)||W(t,d).localeCompare(W(t,u)));for(let[d,u]of e){let p=t.areas?.[d]?.name;u.sort((h,f)=>a(h)-a(f)||W(t,h,p).localeCompare(W(t,f,p)))}let c=new Set;for(let[d,u]of o)u.size>1&&c.add(d);return{entities:t.entities,devices:t.devices,states:t.states,stateCount:Object.keys(t.states).length,byArea:e,powerByDevice:n,withoutArea:i,domainsByDevice:r,hubs:c}}function $n(t){let e=xs;return e&&e.entities===t.entities&&e.devices===t.devices&&(e.states===t.states||(e.states=t.states,Object.keys(t.states).length===e.stateCount))?e:xs=F_(t)}function be(t,e){let n=Ko(t,e.area_id);return e.sub_areas?.length?[...new Set([...n,...e.sub_areas.flatMap(r=>Ko(t,r))])]:n}function Ko(t,e){return!e||!t.entities?[]:$n(t).byArea.get(e)??[]}function ud(t,e){if(!t.entities)return[];let n=[];for(let[r,o]of $n(t).byArea){let i=o.filter(s=>Mt(Ne(t,s)));r!==e&&i.length>0&&n.push({areaId:r,name:t.areas?.[r]?.name??r,ids:i})}return n.sort((r,o)=>r.name.localeCompare(o.name))}var hd=t=>t.entities?$n(t).withoutArea:[],Ss=(t,e)=>!!t.entities&&$n(t).hubs.has(e),jo=(t,e)=>t.entities?$n(t).powerByDevice.get(e)??[]:[];function Sn(t,e){let n=new Map;for(let o of e)$s(n,t.entities?.[o]?.device_id??`entity:${o}`).push(o);let r=new Map(e.map((o,i)=>[o,i]));return[...n.values()].map(o=>{let i=o.find(s=>!t.entities?.[s]?.name)??o[0];return{primary:i,others:o.filter(s=>s!==i)}}).sort((o,i)=>r.get(o.primary)-r.get(i.primary))}var Uo=(t,e)=>Sn(t,e).map(n=>n.primary),T_={temperature:"temperature",humidity:"humidity",co2:"carbon_dioxide"};function Ms(t,e,n){let r=t.states[e]?.attributes;if(!r||!((r.symcon_variable_type===1||r.symcon_variable_type===2)&&typeof r.symcon_id=="number")&&!/^(sensor|input_number|number)\./.test(e))return!1;let i=String(r.unit_of_measurement??"").replace(/\s/g,"").toLowerCase();return n==="temperature"&&["\xB0c","\xB0f","\u2103","\u2109","k"].includes(i)?!0:r.device_class===T_[n]}var z_=new Set(["climate","water_heater","switch","button","camera","media_player","vacuum","light","fan","lawn_mower"]),P_=["vorlauf","r(\xFC|ue)cklauf","flow","return","d(\xFC|ue)se","nozzle","hotend","extruder","druckbett","heatbed","(^|[^a-z])bed($|[^a-z])","chamber","cpu","gpu","chip","soc","akku","batter","wasser","water","kessel","boiler","au(\xDF|ss)en","outdoor","outside","abgas","exhaust","sole","brine","verdampfer","kondensat","verdichter","compressor","motor","k(\xFC|ue)hl","freezer","fridge","gefrier"],I_=new RegExp(`(${P_.join("|")})`,"i");function Rs(t,e){let n=t.entities?.[e]?.device_id,r=n&&!Ss(t,n)?$n(t).domainsByDevice.get(n):void 0;return r&&[...r].some(o=>z_.has(o))?!1:!I_.test(`${e} ${t.states[e]?.attributes.friendly_name??""}`)}function pd(t,e,n,r){let o=n.climate?.[r];if(o==="none")return[];if(o)return[o].flat().filter(c=>t.states[c]);let i=(e?.placements??[]).filter(c=>c.entity_id.startsWith("sensor.")),s=i.filter(c=>N([c.x,c.z],n.points)).map(c=>c.entity_id),l=new Set(i.filter(c=>!N([c.x,c.z],n.points)).map(c=>c.entity_id));return[...new Set([...be(t,n).filter(c=>!l.has(c)),...s])].filter(c=>c.startsWith("sensor.")&&Ms(t,c,r)&&Rs(t,c))}var D_=new Set([void 0,"shutter","blind","awning","shade","curtain","window"]),O_=new Set(["garage","gate"]),H_=new Set(["window","opening"]);function _r(t,e,n=!1){let r=new Map;return t.forEach((o,i)=>{let s=n&&e.length===1?e[0]:e[i];s&&r.set(o.id,s)}),r}var fd=(t,e)=>t==="none"?null:t??e??null,Mn=t=>t&&t!=="none"?t:null;function br(t,e){let n=new Map;for(let r of e)for(let o of r.rooms){let i=r.openings.filter(g=>g.room_id===o.id).sort((g,y)=>g.edge-y.edge||g.offset-y.offset);if(i.length===0)continue;let s=be(t,o),l=g=>t.states[g]?.attributes.device_class,a=g=>s.filter(y=>X(y)==="binary"&&g(l(y)??"")),c=g=>i.filter(y=>y.type===g),d=_r(c("window"),s.filter(g=>X(g)==="cover"&&D_.has(l(g))),!0),u=_r(c("window"),a(g=>H_.has(g))),p=_r(c("door"),a(g=>g==="door")),h=_r(c("garage"),s.filter(g=>X(g)==="cover"&&O_.has(l(g)??""))),f=_r(c("garage"),a(g=>g==="garage_door"));for(let g of i){let y=g.type==="window"?d:g.type==="garage"?h:null,b=g.type==="window"?u:g.type==="garage"?f:p,v=g.leaves===2;n.set(g.id,{cover:fd(g.cover,y?.get(g.id)),contact:g.sensor==="handle"&&g.contact==null?null:fd(g.contact,b.get(g.id)),tilt:g.tilt==="none"?null:g.tilt,contact2:v?Mn(g.contact2):null,tilt2:v?Mn(g.tilt2):null,position:Mn(g.position),positionInverted:!!g.position_inverted,tiltAngle:Mn(g.tilt_angle),tiltMax:g.tilt_max??null,tiltOffset:g.tilt_offset??null,tiltInvert:!!g.tilt_invert,shut:!!g.shut,angled:g.type==="door"&&!!g.open_angle,lock:g.type==="door"?Mn(g.lock):null,cover2:g.type==="garage"?null:Mn(g.cover2)})}}return n}var L_=[[/^(tilted|tilt|gekippt|kipp)/i,"tilted"],[/^(open|opened|offen|geöffnet|on)$/i,"open"],[/^(closed|close|geschlossen|zu|off)$/i,"closed"]];function Es(t){if(!t||Rt(t))return null;let e=t.attributes.window_state;for(let n of[typeof e=="string"?e:"",t.state]){let r=n.trim(),o=r&&L_.find(([i])=>i.test(r));if(o)return o[1]}return null}var md=/\b(tv|fernseh|television|fire ?tv|apple ?tv|chromecast|shield)/i,gd=/(kühl|fridge|gefrier|freezer)/i,_d=/(spülmaschine|geschirrspül|dishwasher)/i,C_=/(kochfeld|herd|induktion|cooktop)/i,N_={robot_vacuum:/(saug|vacuum|robo|roomba|roborock|dreame|ecovacs|deebot)/i,tv_board:md,tv_wall:md,desk:/\b(pc|computer|rechner|desktop|monitor|workstation)/i,fridge:gd,fridge_smart:gd,stove:/(herd|kochfeld|cooktop|stove|induktion)/i,kitchen_tall:/(backofen|oven|ofen)/i,dishwasher:_d,washer:/(waschmaschine|washer|washing)/i,dryer:/(trockner|dryer)/i,kitchen:/(kaffee|coffee|wasserkocher|kettle)/i,island:C_,sink:_d,radiator:/(heiz|radiator|thermostat|climate|hk|trv)/i},bd={lamp_ceiling:/(decke|ceiling|haupt|main)/i,lamp_downlight:/(spot|strahler|downlight|einbau)/i,lamp_spot:/(spot|strahler)/i,lamp_panel:/(panel|decke|ceiling)/i,lamp_uplight:/(fluter|uplight|steh)/i,lamp_bollard:/(weg|garten|garden|path|poller|außen|aussen|outdoor)/i,lamp_garden:/(garten|garden|spot|außen|aussen|outdoor|baum|tree)/i,lamp_pendant:/(pendel|pendant|hänge|esstisch|dining)/i,ceiling_fan:/(ventilator|fan)/i,lamp_floor:/(steh|floor)/i,lamp_table:/(tisch|nacht|table|bedside|lese|reading)/i,lamp_wall:/(wand|wall)/i,led_strip:/(led|strip|streifen|leiste|band)/i},yd=new Set(["tv_board","tv_wall"]);var Rn=t=>yd.has(t)||!!wc(t),Zo=t=>!!G(t)?.electric&&/speaker|multiroom|soundbar/.test(t.split(":").pop()??t),wr=t=>Rn(t)||t==="desk"||t==="fridge_smart",B_=t=>!!t&&t!=="none";function W_(t,e){if(Go(t,e))return e;let n=t.entities?.[e]?.device_id;return n?jo(t,n).find(r=>r!==e)??null:null}var V_=(t,e,n)=>t.rooms.find(r=>r.points.length>=3&&N([e,n],r.points));function yr(t,e,n,r){return t.find(o=>e?.test(n(o)))??(r?t[0]??null:null)}function Be(t,e){let n=new Map;for(let r of e){let o=new Set([...r.furniture.flatMap(i=>[i.entity,i.power,i.fan_entity]),...r.placements.map(i=>i.entity_id)].filter(B_));for(let i of r.furniture){let s=i.type in bd,l=yn(i.type),a=s?bd[i.type]:N_[i.type];if(!a&&!l&&!Zo(i.type)&&i.entity==null&&i.power==null)continue;let c=V_(r,i.x,i.z),d=(c?Uo(t,be(t,c)):[]).filter(y=>!o.has(y)),u=y=>`${y} ${W(t,y)}`,p=y=>d.filter(b=>X(b)===y),h=i.entity==="none"?null:i.entity??null;if(i.entity==null){if(i.type==="ceiling_fan"){let y=(c?be(t,c):[]).filter(v=>!o.has(v)),b=new Set(y.filter(v=>X(v)==="fan").map(v=>t.entities?.[v]?.device_id).filter(Boolean));h=y.find(v=>X(v)==="light"&&b.has(t.entities?.[v]?.device_id))??yr(p("light"),a,u,!1)}else if(s)h=yr(p("light"),a,u,!0);else if(i.type==="robot_vacuum"){let y=c?.area_id??null;h=Object.keys(t.entities??{}).find(b=>b.startsWith("vacuum.")&&!o.has(b)&&Tt(t,b)===y)??null}else if(i.type==="radiator"||l)h=yr(p("climate"),a,u,!0);else if(Rn(i.type)){let y=p("media");h=y.find(b=>t.states[b]?.attributes.device_class==="tv")??yr(y,a,u,yd.has(i.type))}else if(Zo(i.type)){let y=p("media").filter(b=>t.states[b]?.attributes.device_class!=="tv");h=yr(y,a,u,!1)??(y.length===1?y[0]:null)}else a&&(h=d.find(y=>["switch","media","fan"].includes(X(y)??"")&&a.test(u(y)))??null);h&&o.add(h)}let f=i.power==="none"?null:i.power??null;i.power==null&&(f=h?W_(t,h):null,!f&&a&&c&&!s&&(f=be(t,c).find(y=>Go(t,y)&&!o.has(y)&&a.test(u(y)))??null),f&&o.add(f));let g=null;if(i.type==="ceiling_fan"&&(g=i.fan_entity==="none"?null:i.fan_entity??null,i.fan_entity==null)){let y=(c?be(t,c):[]).filter(v=>X(v)==="fan"&&!o.has(v)),b=h?t.entities?.[h]?.device_id:void 0;g=(b?y.find(v=>t.entities?.[v]?.device_id===b):void 0)??y[0]??null,g&&o.add(g)}(h||f||g)&&n.set(i.id,{entity:h,power:f,...i.type==="ceiling_fan"?{fan:g}:{}})}}return n}var wd=t=>t==="fridge"||t==="fridge_smart"||/(fridge|freezer|kuehl|gefrier|chest_freezer)/.test(t.slice(t.lastIndexOf(":")+1));function vd(t,e,n=[]){let r=[];for(let o of e){let i=(l,a)=>o.rooms.some(c=>c.points.length>=3&&N([l,a],c.points)),s=Be(t,[o]);r.push(...o.placements.filter(l=>l.outside||!i(l.x,l.z)).map(l=>l.entity_id)),r.push(...o.furniture.filter(l=>!i(l.x,l.z)).flatMap(l=>[s.get(l.id)?.entity,s.get(l.id)?.power]));for(let l of o.outdoor??[])l.area_id&&r.push(...Uo(t,Ko(t,l.area_id))),r.push(l.pump_entity,l.temp_entity)}return[...new Set(r.filter(o=>!!o&&!!t.states[o]&&!n.includes(o)))]}function K_(t,e){return Math.min(...e.map((n,r)=>{let o=e[(r+1)%e.length],[i,s]=[o[0]-n[0],o[1]-n[1]],l=Math.min(1,Math.max(0,((t[0]-n[0])*i+(t[1]-n[1])*s)/(i*i+s*s||1)));return Math.hypot(t[0]-n[0]-i*l,t[1]-n[1]-s*l)}))}function xd(t,e,n=[]){let r=t.points;if(r.length<3||e.length===0)return[];let o=r.map(b=>b[0]),i=r.map(b=>b[1]),[s,l,a,c]=[Math.min(...o),Math.max(...o),Math.min(...i),Math.max(...i)],d=Math.min(l-s,c-a),u=Math.max(.1,Math.min(.25,d/8)),p=Math.min(.35,d/5),h=Math.min(.7,d/4),f=_e(r),g=[];for(let b=s+u/2;b=p&&g.push({at:w,wallDistance:x})}g.length===0&&g.push({at:f,wallDistance:0});let y=[...n];return e.map(b=>{let v=X(b)==="light",w=g[0].at,x=-1/0;for(let{at:$,wallDistance:A}of g){let F=y.length?Math.min(...y.map(z=>Math.hypot($[0]-z[0],$[1]-z[1]))):3,T=Math.hypot($[0]-f[0],$[1]-f[1]),I=Math.min(F,3)*2;Tx+1e-9&&(x=I,w=$)}let k=[Math.round(w[0]*100)/100,Math.round(w[1]*100)/100];return y.push(k),{entity_id:b,x:k[0],z:k[1],y:null,mount:null}})}var kd=/(^|_)(current_room|current_segment|aktueller_raum|current_area)($|_)/;function $d(t,e,n){if(n==="none")return null;if(n)return n;let r=e?t.entities?.[e]?.device_id:null;return!r||!t.entities?null:Object.values(t.entities).find(i=>i.device_id===r&&i.entity_id.startsWith("sensor.")&&(kd.test(i.translation_key??"")||kd.test(i.entity_id.split(".")[1])))?.entity_id??null}var K=(t,e)=>[t[0]-e[0],t[1]-e[1]],ct=(t,e)=>[t[0]+e[0],t[1]+e[1]],tt=(t,e)=>[t[0]*e,t[1]*e],Q=(t,e)=>t[0]*e[0]+t[1]*e[1],$e=(t,e)=>t[0]*e[1]-t[1]*e[0],fe=t=>Math.hypot(t[0],t[1]),nt=t=>{let e=fe(t)||1;return[t[0]/e,t[1]/e]},As=t=>[-t[1],t[0]],Fs=t=>[t[1],-t[0]];var G_=.05,j_=.2,U_=.12;function Z_(t){let e=[];return t.forEach((n,r)=>{let o=n.points;if(o.length<3)return;let i=ge(o)>=0;o.forEach((s,l)=>{let a=o[(l+1)%o.length],c=fe(K(a,s));if(c<.05)return;let d=[(a[0]-s[0])/c,(a[1]-s[1])/c],u=i?[d[1],-d[0]]:[-d[1],d[0]];(d[1]<-1e-9||Math.abs(d[1])<=1e-9&&d[0]<0)&&(d=[-d[0],-d[1]]);let p=[-d[1],d[0]],[h,f]=[Q(s,d),Q(a,d)];e.push({room:r,index:l,dir:d,normal:p,offset:Q(s,p),outside:Q(u,p)>0?1:-1,from:Math.min(h,f),to:Math.max(h,f)})})}),e}function q_(t,e,n){if(t.room===e.room||Math.abs($e(t.dir,e.dir))>G_||t.outside===e.outside)return null;let r=(e.offset-t.offset)*t.outside;return r>n||r<-U_||Math.abs(r)<1e-4||Math.min(t.to,e.to)-Math.max(t.from,e.from)Math.round(t*1e3)/1e3;function Sd(t,e=.6){let n=Z_(t),r=n.map((g,y)=>y),o=g=>r[g]===g?g:r[g]=o(r[g]),i=[],s=new Set,l=[];for(let g=0;gMath.abs(g[2])-Math.abs(y[2]));let a=new Map(n.map((g,y)=>[y,[y]])),c=(g,y)=>g.some(b=>y.some(v=>n[b].room===n[v].room&&Math.abs(n[b].offset-n[v].offset)>=.002));for(let[g,y,b]of l){let[v,w]=[o(g),o(y)];if(v!==w){if(c(a.get(v),a.get(w)))continue;r[v]=w,a.set(w,[...a.get(w),...a.get(v)]),a.delete(v)}i.push(Ts(b)),s.add(g).add(y)}let d=new Map(n.map((g,y)=>[`${g.room}:${g.index}`,y]));for(let g=s.size>0;g;)g=!1,n.forEach((y,b)=>{let v=d.get(`${y.room}:${(y.index+1)%t[y.room].points.length}`);if(v===void 0||v===b)return;let w=n[v];!(Math.abs($e(y.dir,w.dir))<1e-6&&Math.abs(y.offset-w.offset)<.002&&y.outside===w.outside)||s.has(b)===s.has(v)||(s.add(b).add(v),g=!0)});n.forEach((g,y)=>{let b=d.get(`${g.room}:${(g.index+1)%t[g.room].points.length}`);if(b===void 0||b===y||!s.has(y)||!s.has(b))return;let v=n[b];Math.abs($e(g.dir,v.dir))<1e-6&&Math.abs(g.offset-v.offset)<.002&&g.outside===v.outside&&(r[o(y)]=o(b))});let u=()=>t.map(g=>({...g,points:g.points.map(y=>[y[0],y[1]])}));if(i.length===0)return{rooms:u(),gaps:i};let p=new Map;for(let g of s)p.set(o(g),[...p.get(o(g))??[],g]);let h=t.map(g=>g.points.map(()=>new Map));for(let[g,y]of p){let b=new Map(y.map(w=>[`${n[w].room}:${Math.round(n[w].offset*500)}`,n[w].offset])),v=[...b.values()].reduce((w,x)=>w+x,0)/b.size;for(let w of y){let x=n[w],k=[x.normal[0]*(v-x.offset),x.normal[1]*(v-x.offset)];h[x.room][x.index].set(g,k),h[x.room][(x.index+1)%t[x.room].points.length].set(g,k)}}return{rooms:t.map((g,y)=>({...g,points:g.points.map((b,v)=>{let w=[...h[y][v].values()].reduce((x,k)=>[x[0]+k[0],x[1]+k[1]],[b[0],b[1]]);return[Ts(w[0]),Ts(w[1])]})})),gaps:i}}function Md(t){let e=t.filter(n=>n>.04).sort((n,r)=>n-r);return e.length===0?null:Math.min(.5,Math.max(.08,Math.round(e[Math.floor(e.length/2)]*100)/100))}var Y_=.25,Rd=t=>Math.round(t*1e3)/1e3,Ed=(t,e,n)=>t.rooms.find(r=>r.points.length>=3&&N([e,n],r.points));function Ps(t,e,n,r,o){let i=Ed(t,e,n);if(!i)return[r,o];let s=(l,a)=>N([l,a],i.points);return s(r,o)?[r,o]:s(r,n)?[r,n]:s(e,o)?[e,o]:[e,n]}function X_(t,e,n,r){return t.rooms.some(o=>o.id!==e.id&&o.points.some((i,s)=>{let l=o.points[(s+1)%o.points.length];return Math.abs(Q(K(i,n),r))<.02&&Math.abs(Q(K(l,n),r))<.02}))}var zs=(t,e)=>Math.abs((t-e+540)%360-180);function vr(t,e,n,r=Y_){let o=Ed(t,e.x,e.z);if(!o)return null;let i=o.points,s=ge(i)>=0?1:-1,l=null;return i.forEach((a,c)=>{let d=i[(c+1)%i.length],u=fe(K(d,a));if(u<.3)return;let p=[(d[0]-a[0])/u,(d[1]-a[1])/u],h=[-p[1]*s,p[0]*s],f=Q(K([e.x,e.z],a),p);if(f<0||f>u)return;let g=X_(t,o,a,h)?n/2:0,y=Q(K([e.x,e.z],a),h)-g,b=Math.atan2(-h[0],h[1])*180/Math.PI,w=[{rotation:b,extent:e.d/2},{rotation:b+90,extent:e.w/2},{rotation:b-90,extent:e.w/2}].reduce((k,$)=>zs(e.rotation,$.rotation)50)return;let x=y-w.extent;Math.abs(x)>r||l&&Math.abs(x)>=Math.abs(l.gap)||(l={x:Rd(e.x-h[0]*x),z:Rd(e.z-h[1]*x),rotation:(Math.round(w.rotation)%360+360)%360,gap:x})}),l&&{x:l.x,z:l.z,rotation:l.rotation}}var En=Math.PI/180,rt=t=>Math.tan(Math.min(80,Math.max(0,t))*En);function xr(t){return{x0:Math.min(t.x0,t.x1),x1:Math.max(t.x0,t.x1),z0:Math.min(t.z0,t.z1),z1:Math.max(t.z0,t.z1)}}function Ad(t){if(!t.rotation)return null;let e=t.rotation*En;return{cx:(t.x0+t.x1)/2,cz:(t.z0+t.z1)/2,c:Math.cos(e),sn:Math.sin(e)}}function Fd(t,e){let n=Ad(t);if(!n)return e;let[r,o]=[e[0]-n.cx,e[1]-n.cz];return[n.cx+r*n.c-o*n.sn,n.cz+r*n.sn+o*n.c]}function Is(t,e,n){let r=Ad(t);if(!r)return[e,n];let[o,i]=[e-r.cx,n-r.cz];return[r.cx+o*r.c+i*r.sn,r.cz-o*r.sn+i*r.c]}function $r(t,e=0){let{x0:n,x1:r,z0:o,z1:i}=xr(t);return[[n-e,o-e],[r+e,o-e],[r+e,i+e],[n-e,i+e]].map(s=>Fd(t,s))}function ve(t){let{x0:e,x1:n,z0:r,z1:o}=xr(t),i=s=>Fd(t,s);return t.axis==="x"?{u0:e,u1:n,w:o-r,at:(s,l)=>i([s,t.flip?o-l:r+l])}:{u0:r,u1:o,w:n-e,at:(s,l)=>i([t.flip?n-l:e+l,s])}}function Sr(t,e,n){let{x0:r,x1:o,z0:i,z1:s}=xr(t),[l,a]=Is(t,e,n);return t.axis==="x"?[l,t.flip?s-a:a-i]:[a,t.flip?o-l:l-r]}var kr=Math.tan(30*En);function Mr(t,e,n,r,o){let i=Math.min(t*.3,r>1e-6?2.4/r:t*.3),s=Math.min(t*.3,o>1e-6?2.4/o:t*.3),l=e+i*r,a=n+s*o,c=Math.min(t-s,Math.max(i,(a-l+kr*(t-s+i))/(2*kr))),d=l+(c-i)*kr;return{vla:i,vlb:s,yla:l,ylb:a,vr:c,rh:d,y:p=>p<=i?e+p*r:p<=c?l+(p-i)*kr:p<=t-s?a+(t-s-p)*kr:n+(t-p)*o}}function Pe(t){let e=ve(t).w,[n,r]=[t.eave_a,t.eave_b],[o,i]=[rt(t.pitch_a),rt(t.pitch_b)];switch(t.shape){case"flat":case"parapet":return{vr:e/2,rh:n,y:()=>n};case"pent":return{vr:e,rh:n+e*o,y:s=>n+s*o};case"mansard":{let s=Mr(e,n,r,o,i);return{vr:s.vr,rh:s.rh,y:s.y}}default:{let s=o+i>1e-6?Math.min(e,Math.max(0,(r-n+e*i)/(o+i))):e/2;return{vr:s,rh:n+s*o,y:l=>l<=s?n+l*o:r+(e-l)*i}}}}var Yt=t=>Pe(t).rh;function Td(t){let e=t.heightEnd!==void 0;return{...t,a:t.b,b:t.a,left:t.right,right:t.left,roomLeft:t.roomRight,roomRight:t.roomLeft,height:e?t.heightEnd:t.height,heightEnd:e?t.height:void 0}}function Q_(t,e){let n=t.map(r=>({...r}));for(let r of e){let o=n.find(i=>i.room_id===r.room_id&&i.edge===r.edge&&(Math.abs(i.t1-r.t0)<1e-6||Math.abs(r.t1-i.t0)<1e-6));o?(o.t0=Math.min(o.t0,r.t0),o.t1=Math.max(o.t1,r.t1)):n.push({...r})}return n}function J_(t,e,n){if(t.a===e.b)return!1;let r=nt(K(n[t.b],n[t.a])),o=nt(K(n[e.b],n[e.a]));return Math.abs($e(r,o))>1e-6||Q(r,o)<=0||t.free||e.free||t.heightEnd!==void 0||e.heightEnd!==void 0?!1:t.height===e.height&&t.exterior===e.exterior&&t.roomLeft===e.roomLeft&&t.roomRight===e.roomRight&&Math.abs(t.left-e.left)<=1e-9&&Math.abs(t.right-e.right)<=1e-9}function zd(t,e,n=new Set){let r=t.slice();for(;;){let o=new Map;r.forEach((s,l)=>{for(let a of[s.a,s.b])o.set(a,[...o.get(a)??[],l])});let i=null;for(let[s,l]of o){if(l.length!==2||n.has(s))continue;let a=r[l[0]].b===s?r[l[0]]:Td(r[l[0]]),c=r[l[1]].a===s?r[l[1]]:Td(r[l[1]]);if(!J_(a,c,e))continue;let d={...a,b:c.b,sources:Q_(a.sources,c.sources)};i=[...r.filter((u,p)=>p!==l[0]&&p!==l[1]),d];break}if(!i)return r;r=i}}function Pd(t,e){let n=new Map;t.forEach((o,i)=>{let s=nt(K(e[o.b],e[o.a])),l=[[o.a,{key:`${i}:a`,d:s,left:o.left,right:o.right,angle:Math.atan2(s[1],s[0])}],[o.b,{key:`${i}:b`,d:tt(s,-1),left:o.right,right:o.left,angle:Math.atan2(-s[1],-s[0])}]];for(let[a,c]of l)n.set(a,[...n.get(a)??[],c])});let r=new Map;for(let[o,i]of n){let s=e[o];i.sort((a,c)=>a.angle-c.angle);for(let a of i)r.set(a.key,{left:ct(s,tt(As(a.d),a.left)),right:ct(s,tt(Fs(a.d),a.right))});if(i.length<2)continue;let l=4*Math.max(...i.map(a=>Math.max(a.left,a.right)))+1e-9;i.forEach((a,c)=>{let d=i[(c+1)%i.length],u=ct(s,tt(As(a.d),a.left)),p=ct(s,tt(Fs(d.d),d.right)),h=$e(a.d,d.d);if(Math.abs(h)<1e-4)return;let f=ct(u,tt(a.d,$e(K(p,u),d.d)/h));fe(K(f,s))>l||(r.get(a.key).left=f,r.get(d.key).right=f)})}return r}function Id(t,e){let n=t.filter((r,o)=>fe(K(r,t[(o+1)%t.length]))>e);for(;;){if(n.length<=3)return n;let r=n.findIndex((o,i)=>{let s=n[(i+n.length-1)%n.length],l=n[(i+1)%n.length],[a,c]=[K(o,s),K(l,o)];return Math.abs($e(nt(a),nt(c)))<1e-7&&Q(a,c)>0});if(r===-1)return n;n=n.filter((o,i)=>i!==r)}}function eb(t){let e=[];return{points:e,idOf(n){let r=e.findIndex(o=>Math.abs(o[0]-n[0])<=t&&Math.abs(o[1]-n[1])<=t);return r>=0?r:(e.push([n[0],n[1]]),e.length-1)}}}function tb(t,e){let n=[];for(let r of t){let o=r.points;if(o.length<3||Math.abs(ge(o))<1e-6)continue;let i=ge(o)>0,s=o.map(l=>e.idOf(l));s.forEach((l,a)=>{let c=s[(a+1)%s.length];l!==c&&n.push(i?{u:l,v:c,room:r.id,edge:a,forward:!0}:{u:c,v:l,room:r.id,edge:a,forward:!1})})}return n}function nb(t,e,n){let r=[];for(let o of t){let[i,s]=[e[o.u],e[o.v]],l=K(s,i),a=fe(l),c=tt(l,1/a),d=e.map((p,h)=>({id:h,rel:K(p,i)})).filter(({id:p,rel:h})=>p!==o.u&&p!==o.v&&Q(h,c)>n&&Q(h,c)({t:Q(h,c),id:p})).sort((p,h)=>p.t-h.t),u=[{t:0,id:o.u},...d,{t:a,id:o.v}];for(let p=0;p+1({room_id:t.room,edge:t.edge,t0:t.t0,t1:t.t1});function rb(t,e){let n=new Map(t.map(l=>[l.id,l])),r=new Map;for(let l of e){let a=`${l.room}:${l.edge}`;r.set(a,[...r.get(a)??[],l.t0].sort((c,d)=>c-d))}let o=l=>{let a=n.get(l.room)?.wall_heights?.[l.edge];return Array.isArray(a)?a[(r.get(`${l.room}:${l.edge}`)??[]).indexOf(l.t0)]??null:a},i=l=>{let a=n.get(l.room),[c,d]=[a?.wall_heights?.[l.edge],a?.wall_slopes?.[l.edge]];if(!a||typeof c!="number"||typeof d!="number"||c<=0||d<=0)return null;let[u,p]=[a.points[l.edge],a.points[(l.edge+1)%a.points.length]];return{from:c,to:d,length:Math.hypot(p[0]-u[0],p[1]-u[1])}},s=l=>{let a=i(l);if(!a||a.length<1e-9){let d=o(l);return typeof d=="number"&&d>0?[d,d]:[null,null]}let c=d=>a.from+(a.to-a.from)*d/a.length;return l.forward?[c(l.t0),c(l.t1)]:[c(l.t1),c(l.t0)]};return{heightsOf(l){let[a,c]=[1/0,1/0];for(let u of l){let[p,h]=s(u),[f,g]=u===l[0]?[p,h]:[h,p];f!==null&&(a=Math.min(a,f)),g!==null&&(c=Math.min(c,g))}let d=l.map(u=>n.get(u.room)?.ceiling);if(d.every(u=>typeof u=="number"&&u>0)){let u=Math.max(...d);a===1/0&&(a=u),c===1/0&&(c=u)}return{...a<1/0?{a}:{},...c<1/0?{b:c}:{}}},thicknessOf(l){let a=l.map(c=>{let d=n.get(c.room)?.wall_thickness?.[c.edge];return Array.isArray(d)?d[(r.get(`${c.room}:${c.edge}`)??[]).indexOf(c.t0)]:d}).filter(c=>typeof c=="number"&&c>0);return a.length?Math.max(...a):void 0},hasNoWall:l=>l.some(a=>o(a)===0)}}function Od(t){let e=n=>Math.round(n*1e6)/1e6;return t.a===void 0||t.b===void 0?t.a!==void 0?{height:e(t.a)}:t.b!==void 0?{height:e(t.b)}:{}:Math.abs(t.a-t.b)<1e-6?{height:e(t.a)}:{height:e(t.a),heightEnd:e(t.b)}}function ob(t,e,n,r){let o=rb(e,t),i=new Map;for(let a of t){let c=a.up!==c&&p.u===c.v&&p.v===c.u&&p.room!==c.room);for(let p of a)p!==c&&p!==d&&p.room!==c.room&&r.push(`overlap:${c.room}:${p.room}`);let u=d?[c,d]:[c];if(o.hasNoWall(u)){d&&l.push([c.room,d.room]);continue}if(d){let p=o.thicknessOf(u)??n.interior;s.push({a:c.u,b:c.v,left:p/2,right:p/2,exterior:!1,roomLeft:c.room,roomRight:d.room,sources:u.map(Dd),...Od(o.heightsOf(u))})}else s.push({a:c.u,b:c.v,left:0,right:o.thicknessOf(u)??n.exterior,exterior:!0,roomLeft:c.room,roomRight:null,sources:[Dd(c)],...Od(o.heightsOf(u))})}return{drafts:s,open:l}}function ib(t,e){let n=i=>nt(K(e[i.b],e[i.a])),r=t.filter(i=>!i.exterior&&!i.free),o=new Map;for(let i of r){if(o.has(i))continue;let s=[i];o.set(i,s);for(let l=0;l1e-6||a.add(Q(s,h)>0?"left":"right")}if(a.size!==1)continue;let c=[...a][0];for(let d of i){let u=d.left+d.right,p=Q(n(d),s)>0,h=c==="left"===p;[d.left,d.right]=h?[0,u]:[u,0]}}}var sb=(t,e)=>{let n=i=>Math.round(i*100),[r,o]=t[0]Math.hypot(b.b[0]-b.a[0],b.b[1]-b.a[1])>.05),a=l.map(b=>[i.idOf(b.a),i.idOf(b.b)]),c=new Set;for(let b of t){let v=b.points;v.length<3||(b.wall_splits??[]).forEach((w,x)=>{if(!w||x>=v.length)return;let k=v[x],$=K(v[(x+1)%v.length],k),A=fe($);for(let F of w)F>r&&F{let[w,x]=a[v];if(w===x)return;let k=[(b.a[0]+b.b[0])/2,(b.a[1]+b.b[1])/2],$=t.find(F=>F.points.length>=3&&N(k,F.points))?.id??null,A=(b.thickness??e.interior)/2;h.push({free:b.id,a:w,b:x,left:A,right:A,exterior:!1,roomLeft:$,roomRight:$,sources:[],height:typeof b.height=="number"&&b.height>0?b.height:void 0,...typeof b.height=="number"&&b.height>0&&typeof b.height_end=="number"&&b.height_end>0&&Math.abs(b.height_end-b.height)>1e-6?{heightEnd:b.height_end}:{}})});let f=zd(h,i.points,c),g=Pd(f,i.points);return{walls:f.map((b,v)=>{let[w,x]=[i.points[b.a],i.points[b.b]],[k,$]=[g.get(`${v}:a`),g.get(`${v}:b`)],A=Id([k.right,$.left,x,$.right,k.left,w],1e-6);return{id:sb(w,x),a:[w[0],w[1]],b:[x[0],x[1]],left:b.left,right:b.right,exterior:b.exterior,roomLeft:b.roomLeft,roomRight:b.roomRight,sources:b.sources,footprint:A,...b.free?{free:b.free}:{},...b.height!==void 0?{height:b.height}:{},...b.heightEnd!==void 0?{heightEnd:b.heightEnd}:{}}}),warnings:[...new Set(o)],open:p}}function An(t,e,n){let r=t.points[e];return ct(r,tt(nt(K(t.points[(e+1)%t.points.length],r)),n))}function Ie(t,e,n){if(t.wall){let o=n.find(l=>l.id===t.wall);if(!o||Math.hypot(o.b[0]-o.a[0],o.b[1]-o.a[1])<.05)return null;let i=nt(K(o.b,o.a));return{room:{id:t.room_id,name:"",area_id:null,points:[o.a,o.b,ct(o.a,[-i[1],i[0]])]},edge:0}}let r=e.find(o=>o.id===t.room_id);return r&&t.edgeQ(K(e,t.a),nt(K(t.b,t.a)));function zt(t,e,n){if(!e.wall)return ab(t,n.room,n.edge,e.offset);let r=t.find(o=>o.free===e.wall);return r?{wall:r,s:Hd(r,An(n.room,0,e.offset))}:null}function ab(t,e,n,r){for(let o of t)if(o.sources.some(s=>s.room_id===e.id&&s.edge===n&&r>=s.t0-1e-6&&r<=s.t1+1e-6))return{wall:o,s:Hd(o,An(e,n,r))};return null}function Ld(t,e){let n=t.points.map(h=>h[0]),r=t.points.map(h=>h[1]);if(t.points.length!==4||new Set(n.map(h=>h.toFixed(3))).size!==2||new Set(r.map(h=>h.toFixed(3))).size!==2)return null;let[o,i,s,l]=[Math.min(...n),Math.max(...n),Math.min(...r),Math.max(...r)],a=h=>Math.max(0,...e.filter(f=>(f.roomLeft===t.id||f.roomRight===t.id)&&h(f)).map(f=>f.roomLeft===t.id?f.left:f.right)),c=(h,f)=>Math.abs(h-f)<.001,d=(h,f,g)=>c(h.a[f],g)&&c(h.b[f],g),u=i-o-a(h=>d(h,0,o))-a(h=>d(h,0,i)),p=l-s-a(h=>d(h,1,s))-a(h=>d(h,1,l));return[Math.round(u*1e3)/1e3,Math.round(p*1e3)/1e3]}var Cd=([t,e])=>{let n=Math.hypot(t,e)||1;return[t/n,e/n]};function lb(t){return t.reduce((e,n,r)=>e+(n[0]*t[(r+1)%t.length][1]-t[(r+1)%t.length][0]*n[1]),0)/2}function Nd(t,e){let n=t.length;if(n<3||Math.abs(e)<1e-9)return t.map(([o,i])=>[o,i]);let r=lb(t)>=0?1:-1;return t.map((o,i)=>{let s=t[(i+n-1)%n],l=t[(i+1)%n],[a,c]=Cd([o[0]-s[0],o[1]-s[1]]),[d,u]=Cd([l[0]-o[0],l[1]-o[1]]),p=[c*r,-a*r],h=[u*r,-d*r],f=[p[0]+h[0],p[1]+h[1]],g=Math.hypot(f[0],f[1]);if(g<1e-6)return[o[0]+p[0]*e,o[1]+p[1]*e];let y=(f[0]*p[0]+f[1]*p[1])/g,b=Math.min(4,1/Math.max(.25,y));return[o[0]+f[0]/g*e*b,o[1]+f[1]/g*e*b]})}function Pt(t){let e=t.map(r=>r[0]),n=t.map(r=>r[1]);return{x0:Math.min(...e),z0:Math.min(...n),x1:Math.max(...e),z1:Math.max(...n)}}function cb(t){let e=([i,s])=>`${Math.round(i*1e3)}:${Math.round(s*1e3)}`,n=new Map;for(let i of t)for(let s of[i.a,i.b])n.set(e(s),[...n.get(e(s))??[],i]);let r=new Set,o=null;for(let i of t){if(r.has(i))continue;r.add(i);let s=[i.a,i.b],l=i.b;for(;;){let c=(n.get(e(l))??[]).find(d=>!r.has(d));if(!c||(r.add(c),l=e(c.a)===e(l)?c.b:c.a,e(l)===e(s[0])))break;s.push(l)}s.length>=3&&e(l)===e(s[0])&&(!o||Math.abs(we(s))>Math.abs(we(o)))&&(o=s)}return o}function Ds(t,e,n,r){let o=pe(t,{exterior:n,interior:r},e).walls.filter(l=>l.exterior&&!l.free),i=o.length?cb(o.map(l=>({a:l.a,b:l.b}))):null;if(!i)return null;let s=i.filter((l,a)=>{let c=i[(a+i.length-1)%i.length],d=i[(a+1)%i.length];return Math.abs((l[0]-c[0])*(d[1]-l[1])-(l[1]-c[1])*(d[0]-l[0]))>1e-6});return s.length>=3?Nd(s,n):null}function Xt(t,e){let n=ve(t),r=Pe(t),o=n.w,[i,s]=[Math.max(0,e.a),Math.max(0,e.b)],l=n.u0-Math.max(0,e.u0),a=n.u1+Math.max(0,e.u1),c=(b,v)=>[b,v,r.y(v)],d=c(l,-i),u=c(a,-i),p=c(a,o+s),h=c(l,o+s),[f,g]=[rt(t.pitch_a),rt(t.pitch_b)],y=b=>[b,r.vr,r.rh];if(t.ends&&(t.shape==="gable"||t.shape==="hip"||t.shape==="halfhip")){let b=(n.u1-n.u0)/2,v=Math.min(b,Math.min(r.vr,o-r.vr)||o/2),w=Math.min(r.y(0),r.y(o)),x=w+(r.rh-w)*Math.min(.9,Math.max(.2,t.halfhip??.55)),k=f>1e-6?Math.min(r.vr,(x-t.eave_a)/f):r.vr,$=g>1e-6?Math.max(r.vr,o-(x-t.eave_b)/g):r.vr,A=Math.min(b-.1,(r.rh-x)/Math.max(.2,f)),F=[[0,r.y(0)],[r.vr,r.rh],[o,r.y(o)]],T=[[0,r.y(0)],[k,x],[$,x],[o,r.y(o)]],I=(V,Vt,_o)=>{if(V==="hip")return{upA:[],upB:[],ridge:y(Vt===l?n.u0+v*_o:n.u1-v*_o),profile:null};if(V==="halfhip"){let qg=y(Vt===l?n.u0+A:n.u1-A);return{upA:[[Vt,k,x]],upB:[[Vt,$,x]],ridge:qg,profile:T}}return{upA:[],upB:[],ridge:y(Vt),profile:F}},z=I(t.ends[0],l,1),C=I(t.ends[1],a,1),B=[[d,u,...C.upA,C.ridge,z.ridge,...[...z.upA].reverse()],[z.ridge,C.ridge,...[...C.upB].reverse(),p,h,...z.upB]],q=[[z.ridge,C.ridge]];for(let[V,Vt,_o]of[[z,d,h],[C,u,p]])V.profile===null?(B.push(V===z?[h,d,V.ridge]:[u,p,V.ridge]),q.push([Vt,V.ridge],[_o,V.ridge])):V.upA.length&&(B.push(V===z?[V.upB[0],V.upA[0],V.ridge]:[V.upA[0],V.upB[0],V.ridge]),q.push([V.upA[0],V.ridge],[V.upB[0],V.ridge]));let ye=V=>V.profile===null?[]:V.upA.length?[V.upA[0],V.upB[0]]:[V.ridge],$t=[d,u,...ye(C),p,h,...[...ye(z)].reverse()];return{faces:B,rim:$t,ridges:q,gable:F,endProfiles:[z.profile,C.profile]}}switch(t.shape){case"pent":return{faces:[[d,u,p,h]],rim:[d,u,p,h],ridges:[[p,h]],gable:[[0,r.y(0)],[o,r.y(o)]]};case"hip":case"pyramid":{let b=(n.u1-n.u0)/2,v=t.shape==="pyramid"?b:Math.min(b,Math.min(r.vr,o-r.vr)||o/2),w=y(n.u0+v),x=y(n.u1-v);return t.shape==="pyramid"?{faces:[[d,u,w],[u,p,w],[p,h,w],[h,d,w]],rim:[d,u,p,h],ridges:[[d,w],[h,w],[u,w],[p,w]],gable:null}:{faces:[[d,u,x,w],[w,x,p,h],[h,d,w],[u,p,x]],rim:[d,u,p,h],ridges:[[w,x],[d,w],[h,w],[u,x],[p,x]],gable:null}}case"halfhip":{let b=Math.min(r.y(0),r.y(o)),v=b+(r.rh-b)*Math.min(.9,Math.max(.2,t.halfhip??.55)),w=f>1e-6?Math.min(r.vr,(v-t.eave_a)/f):r.vr,x=g>1e-6?Math.max(r.vr,o-(v-t.eave_b)/g):r.vr,k=Math.min((n.u1-n.u0)/2-.1,(r.rh-v)/Math.max(.2,f)),$=y(n.u0+k),A=y(n.u1-k),F=[l,w,v],T=[l,x,v],I=[a,w,v],z=[a,x,v];return{faces:[[d,u,I,A,$,F],[$,A,z,p,h,T],[T,F,$],[I,z,A]],rim:[d,u,I,z,p,h,T,F],ridges:[[$,A],[F,$],[T,$],[I,A],[z,A]],gable:[[0,r.y(0)],[w,v],[x,v],[o,r.y(o)]]}}case"mansard":{let b=Mr(o,t.eave_a,t.eave_b,f,g),v=[l,b.vla,b.yla],w=[a,b.vla,b.yla],x=[l,o-b.vlb,b.ylb],k=[a,o-b.vlb,b.ylb],$=[l,b.vr,b.rh],A=[a,b.vr,b.rh];return{faces:[[d,u,w,v],[v,w,A,$],[$,A,k,x],[x,k,p,h]],rim:[d,u,w,A,k,p,h,x,$,v],ridges:[[$,A],[v,w],[x,k]],gable:[[0,r.y(0)],[b.vla,b.yla],[b.vr,b.rh],[o-b.vlb,b.ylb],[o,r.y(o)]]}}default:{let b=y(l),v=y(a);return{faces:[[d,u,v,b],[b,v,p,h]],rim:[d,u,v,p,h,b],ridges:[[b,v]],gable:[[0,r.y(0)],[r.vr,r.rh],[o,r.y(o)]]}}}}function Rr(t,e,n){let r=null;for(let o of t.faces){if(!N([e,n],o.map(([p,h])=>[p,h])))continue;let[i,s]=o,l=o.slice(2).find(p=>Math.abs((s[0]-i[0])*(p[1]-i[1])-(s[1]-i[1])*(p[0]-i[0]))>1e-9);if(!l)continue;let a=[s[0]-i[0],s[2]-i[2],s[1]-i[1]],c=[l[0]-i[0],l[2]-i[2],l[1]-i[1]],d=[a[1]*c[2]-a[2]*c[1],a[2]*c[0]-a[0]*c[2],a[0]*c[1]-a[1]*c[0]];if(Math.abs(d[1])<1e-9)continue;let u=i[2]-(d[0]*(e-i[0])+d[2]*(n-i[1]))/d[1];r=r===null?u:Math.min(r,u)}return r}function Er(t,e,n){let r=ve(e),o=t.floors.flatMap(u=>u.rooms.filter(p=>p.points.length>=3&&u.elevation+u.height>e.base+.05)),i=u=>u.some(p=>o.some(h=>N(p,h.points))),s=.35,l=[.15,.5,.85].map(u=>r.u0+(r.u1-r.u0)*u),a=[.15,.5,.85].map(u=>r.w*u),c=u=>u?0:n,d=(u,p)=>{let h=e.overhang_sides?.[u];return typeof h=="number"&&Number.isFinite(h)?Math.min(2,Math.max(0,h)):p};return{a:d("a",c(i(l.map(u=>r.at(u,-s))))),b:d("b",c(i(l.map(u=>r.at(u,r.w+s))))),u0:d("u0",c(i(a.map(u=>r.at(r.u0-s,u))))),u1:d("u1",c(i(a.map(u=>r.at(r.u1+s,u)))))}}var qo=t=>Math.abs((t.x1-t.x0)*(t.z1-t.z0)),Bd=t=>t.shape==="flat"||t.shape==="parapet",Qt=t=>Math.round(t*100)/100;function Yo(t,e){let[n,r]=[(e.x0+e.x1)/2,(e.z0+e.z1)/2];return t.filter(i=>{if(i===e||i.dormer||i.open||Bd(i)||qo(i)=s.x0&&n<=s.x1&&r>=s.z0&&r<=s.z1}).reduce((i,s)=>i===null||qo(s){let[i,s]=e.at(o,e.w/2),[l,a]=Sr(t,i,s);return Rr(n,l,a)??r.y(a)}}function Hs(t,e){if(Bd(e))return e;let n=ve(e),r=Pe(e).rh,o=ub(t,n),i=o(n.u0)<=o(n.u1),[s,l]=i?[n.u0,n.u1]:[n.u1,n.u0],a=i?1:-1,c=l;for(let p=.5;p=r-.02){c=s+a*p;break}if(Math.abs(c-l)<.05)return e;let d={...e},u=l===n.u1;return e.axis==="x"?d[u?"x1":"x0"]=c:d[u?"z1":"z0"]=c,d}var Ls=.14,Wd=t=>t.shape==="flat"||t.shape==="parapet";function Cs(t,e){return!t.open&&Math.min(t.base,t.eave_a,t.eave_b)a+o||pd+o||s.points&&s.points.length>=3&&!N([e,n],s.points))continue;let[h,f]=Sr(s,e,n),g=Math.max(0,s.overhang??r),y=Wd(s)?null:Rr(Xt(s,{u0:g,u1:g,a:g,b:g}),h,f);i.push((y??Pe(s).y(f))-Ls)}return i.length?Math.max(...i):null}function Ns(t,e,n){let r=[],o=e+n+Ls;for(let i of t.settings.roof.sections??[]){if(i.open||Wd(i)||i.shape==="mansard")continue;let s=ve(i),l=Pe(i),[a,c]=[rt(i.pitch_a),rt(i.pitch_b)],d=[];a>1e-6&&d.push((o-i.eave_a)/a),i.shape==="gable"&&c>1e-6&&d.push(s.w-(o-i.eave_b)/c);for(let u of d)u<=.01||u>=s.w-.01||i.shape==="gable"&&Math.abs(l.y(u)-o)>1e-6||r.push([s.at(s.u0,u),s.at(s.u1,u)])}return r}function Bs(t,e,n,r,o){let i=[];for(let l of[.2,.5,.8])for(let a of[.2,.5,.8])i.push([e+(r-e)*l,n+(o-n)*a]);let s=t.floors.filter(l=>l.rooms.some(a=>a.points.length>=3&&i.some(c=>N(c,a.points)))).map(l=>l.elevation+l.height);return s.length?Math.max(...s):null}function Ws(t,e){let n=t.floors.filter(a=>a.rooms.length>0).sort((a,c)=>a.elevation-c.elevation),r=n.filter(a=>a.elevationd.rooms.some(u=>u.points.length>=3&&a.some(p=>N(p,u.points))));if(c)return c}return r.at(-1)??n[0]}var _t=t=>Math.round(t*1e3)/1e3;function Vs(t,e=n=>`roof_${n+1}`){let n=t.settings.roof?.pitch??35,r=t.settings.wall_exterior,o=t.floors.filter(a=>a.rooms.some(c=>c.points.length>=3)).sort((a,c)=>c.elevation-a.elevation),i=[],s=[],l=(a,c)=>a.some(d=>N(c,d.points));for(let a of o){let c=a.rooms.filter(y=>y.points.length>=3),d=[...new Set(c.flatMap(y=>y.points.map(b=>_t(b[0]))))].sort((y,b)=>y-b),u=[...new Set(c.flatMap(y=>y.points.map(b=>_t(b[1]))))].sort((y,b)=>y-b),p=u.slice(0,-1).map((y,b)=>d.slice(0,-1).map((v,w)=>{let x=[(d[w]+d[w+1])/2,(u[b]+u[b+1])/2];return l(c,x)&&!l(s,x)})),h=p.map(y=>y.map(()=>!1)),f=(y,b)=>p[b][y]&&!h[b][y],g=a.elevation+a.height;for(let y=0;yf(b+T,w+1)).every(Boolean);)w++;for(let F=y;F<=w;F++)for(let T=b;T<=v;T++)h[F][T]=!0;let[x,k]=[d[b]-r,d[v+1]+r],[$,A]=[u[y]-r,u[w+1]+r];Math.min(k-x,A-$)<.8||i.push({id:e(i.length),x0:_t(x),z0:_t($),x1:_t(k),z1:_t(A),shape:"gable",axis:k-x>=A-$?"x":"z",eave_a:_t(g),eave_b:_t(g),pitch_a:n,pitch_b:n,base:_t(g),overhang:null})}s.push(...c)}return i}var Se=Math.PI/180,We=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],Jt=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2],Fn=t=>Math.hypot(t[0],t[1],t[2]),en=t=>{let e=Fn(t)||1;return[t[0]/e,t[1]/e,t[2]/e]},Vd=(t,e)=>[t[1]*e[2]-t[2]*e[1],t[2]*e[0]-t[0]*e[2],t[0]*e[1]-t[1]*e[0]],Ve=t=>Math.round(t*100)/100,Fr=([t,e],n)=>(Math.atan2(t,-e)/Se-n+720)%360;var Gd=.25;function jd(t,e,n,r,o,i,s){let l=o-n>=i-r,a=l?o-n:i-r;return{key:`${t}:top`,section:e,side:"top",flat:!0,o:[n,s,r],eu:l?[1,0,0]:[0,0,1],es:l?[0,0,1]:[1,0,0],n:[0,1,0],lu:a,ls:l?i-r:o-n,pitch:0,span:()=>[0,a],facing:l?[0,1]:[1,0]}}function Ud(t,e){let n=en(Vd(t,e));return n[1]<0?[-n[0],-n[1],-n[2]]:n}var Zd=t=>{let e=en([-t[0],0,-t[2]]);return[e[0],e[2]]};function bt(t,e,n,r,o,i,s,l){let a=en(We(o,r)),c=en(We(i,r));return{key:t,section:e,side:n,flat:!1,o:r,eu:a,es:c,n:Ud(a,c),lu:Fn(We(o,r)),ls:Fn(We(i,r)),pitch:s,span:l,facing:Zd(c)}}function Kd(t,e,n,r,o,i){let s=Fn(We(o,r));if(s<.3)return null;let l=en(We(o,r)),a=We(i,r),c=a[0]*l[0]+a[1]*l[1]+a[2]*l[2],d=[a[0]-l[0]*c,a[1]-l[1]*c,a[2]-l[2]*c],u=Fn(d);if(u<.3)return null;let p=en(d),h=f=>{let g=Math.min(1,Math.max(0,f/u));return[c*g,s-(s-c)*g]};return{key:t,section:e,side:n,flat:!1,o:r,eu:l,es:p,n:Ud(l,p),lu:s,ls:u,pitch:Math.atan2(p[1],Math.hypot(p[0],p[2]))/Se,span:h,facing:Zd(p)}}function hb(t,e){let n=ve(t),r=Pe(t),o=(v,w,x)=>{let[k,$]=n.at(v,w);return[k,x,$]},[i,s]=[Math.max(0,e.a),Math.max(0,e.b)],l=n.u0-Math.max(0,e.u0),a=n.u1+Math.max(0,e.u1),c=a-l,d=r.y(-i),u=r.y(n.w+s);if(t.shape==="flat"||t.shape==="parapet"){let[v,w]=[n.at(l,-i),n.at(a,n.w+s)];return[jd(t.id,t.id,Math.min(v[0],w[0]),Math.min(v[1],w[1]),Math.max(v[0],w[0]),Math.max(v[1],w[1]),t.eave_a+Gd)]}if(t.shape==="pent")return[bt(`${t.id}:a`,t.id,"a",o(l,-i,d),o(a,-i,d),o(l,n.w+s,u),t.pitch_a,()=>[0,c])];if(t.shape==="mansard")return pb(t,n,l,a,i,s);let p=t.shape==="hip"||t.shape==="pyramid",h=(n.u1-n.u0)/2,f=t.shape==="pyramid"?h:p?Math.min(h,Math.min(r.vr,n.w-r.vr)||n.w/2):0,g=p?n.u0+f-l:0,y=p?a-(n.u1-f):0,b=[];if(r.vr>.3){let v=Math.hypot(r.vr+i,r.rh-d);b.push(bt(`${t.id}:a`,t.id,"a",o(l,-i,d),o(a,-i,d),o(l,r.vr,r.rh),t.pitch_a,w=>[g*(w/v),c-y*(w/v)]))}if(n.w-r.vr>.3){let v=Math.hypot(n.w+s-r.vr,r.rh-u);b.push(bt(`${t.id}:b`,t.id,"b",o(a,n.w+s,u),o(l,n.w+s,u),o(a,r.vr,r.rh),t.pitch_b,w=>[y*(w/v),c-g*(w/v)]))}if(p){let v=Kd(`${t.id}:c`,t.id,"c",o(l,n.w+s,u),o(l,-i,d),o(n.u0+f,r.vr,r.rh)),w=Kd(`${t.id}:d`,t.id,"d",o(a,-i,d),o(a,n.w+s,u),o(n.u1-f,r.vr,r.rh));b.push(...[v,w].filter(x=>x!==null))}return b}function pb(t,e,n,r,o,i){let s=Mr(e.w,t.eave_a,t.eave_b,rt(t.pitch_a),rt(t.pitch_b)),l=(f,g)=>{let[y,b]=e.at(f,g);return[y,s.y(g),b]},a=r-n,c=()=>[0,a],d=(f,g)=>Math.atan2(f,g)/Se,u=[],[p,h]=[e.w+i,e.w-s.vlb];return s.vla+o>.3&&u.push(bt(`${t.id}:a`,t.id,"a",l(n,-o),l(r,-o),l(n,s.vla),t.pitch_a,c)),s.vr-s.vla>.3&&u.push(bt(`${t.id}:au`,t.id,"a",l(n,s.vla),l(r,s.vla),l(n,s.vr),d(s.rh-s.yla,s.vr-s.vla),c)),s.vlb+i>.3&&u.push(bt(`${t.id}:b`,t.id,"b",l(r,p),l(n,p),l(r,h),t.pitch_b,c)),h-s.vr>.3&&u.push(bt(`${t.id}:bu`,t.id,"b",l(r,h),l(n,h),l(r,s.vr),d(s.rh-s.ylb,h-s.vr),c)),u}function Ks(t){return t.floors.filter(n=>n.rooms.some(r=>r.points.length>=3)).sort((n,r)=>r.elevation-n.elevation)[0]??null}function U(t){let e=t.settings.roof;if(!e||e.type==="none")return[];if(e.type==="custom")return(e.sections??[]).flatMap(w=>hb(w,Er(t,w,w.overhang??e.overhang)));let n=Ks(t);if(!n)return[];let r=n.rooms.flatMap(w=>w.points.map(x=>x[0])),o=n.rooms.flatMap(w=>w.points.map(x=>x[1])),i=t.settings.wall_exterior+e.overhang,[s,l]=[Math.min(...r)-i,Math.max(...r)+i],[a,c]=[Math.min(...o)-i,Math.max(...o)+i],d=n.elevation+n.height;if(e.type==="flat")return[jd("main",null,s,a,l,c,d+Gd)];let u=l-s>=c-a,p=e.ridge==="short"?!u:u,h=(p?c-a:l-s)/2,f=h*Math.tan(e.pitch*Se),g=(w,x,k)=>p?[w,d+k,(a+c)/2+x]:[(s+l)/2+x,d+k,w],[y,b]=p?[s,l]:[a,c],v=()=>[0,b-y];return[bt("main:a",null,"a",g(y,-h,0),g(b,-h,0),g(y,0,f),e.pitch,v),bt("main:b",null,"b",g(y,h,0),g(b,h,0),g(y,0,f),e.pitch,v)]}function Ke(t,e){let n=[];for(let r of t.floors.filter(o=>!e||o.id===e)){let{walls:o}=pe(r.rooms,{exterior:t.settings.wall_exterior,interior:t.settings.wall_interior},r.walls??[]);for(let i of o){if(!i.exterior&&!i.free)continue;let[s,l]=[i.b[0]-i.a[0],i.b[1]-i.a[1]],a=Math.hypot(s,l);if(a<1.2)continue;let[c,d]=[l/a,-s/a],u=Math.min(r.height,i.height??r.height,i.heightEnd??1/0),p=(h,f,g,y)=>n.push({key:h,section:null,side:"top",flat:!1,o:f,eu:g,es:[0,1,0],n:y,lu:a,ls:u,pitch:90,span:()=>[0,a],facing:[y[0],y[2]],wall:{floorId:r.id}});p(`wall:${r.id}:${i.id}`,[i.a[0]+c*i.right,r.elevation,i.a[1]+d*i.right],[s/a,0,l/a],[c,0,d]),i.free&&p(`wall:${r.id}:${i.id}:back`,[i.b[0]-c*i.left,r.elevation,i.b[1]-d*i.left],[-s/a,0,-l/a],[-c,0,-d])}}return n}var De="ground";function Xo(t){let e=t.floors.filter(n=>n.rooms.some(r=>r.points.length>=3)).sort((n,r)=>n.elevation-r.elevation);return e.find(n=>n.elevation>-.5)??e[0]??t.floors[0]??null}function Qo(t,e){let n=(e.rotation??0)*Se,r=[Math.cos(n),0,Math.sin(n)],o=[-Math.sin(n),0,Math.cos(n)],i=Xo(t),s=r[0]*e.u+o[0]*e.v,l=r[2]*e.u+o[2]*e.v,a=i?i.elevation+(e.base!=null?e.base:Nc(i,s,l)):e.base??0;return{key:De,section:null,side:"top",flat:!0,o:[0,a,0],eu:r,es:o,n:[0,1,0],lu:1e4,ls:1e4,pitch:0,span:()=>[-1e4,1e4],facing:[o[0],o[2]],unbounded:!0}}function ke(t,e,n=U(t)){return e.face===De?Qo(t,e):e.face.startsWith("wall:")?Ke(t,e.face.split(":")[1]).find(r=>r.key===e.face)??null:n.find(r=>r.key===e.face)??null}var Jo=1.13,zr=1.72,Ge=.025,ot=.07;function tn(t){let e=t.module_w||Jo,n=t.module_h||zr;return t.portrait===!1?[n,e]:[e,n]}function Pr(t){return t.layout?.length?t.layout.map(e=>Math.max(0,Math.min(60,Math.round(e)))):Array.from({length:Math.max(1,t.rows)},()=>Math.max(1,t.cols))}function Gs(t,e){return t.flat?Math.min(45,Math.max(0,e.tilt??15))*Se:t.wall?Math.min(90,Math.max(0,e.tilt??0))*Se:Math.min(45,Math.max(0,e.tilt??0))*Se}function Ir(t,e){let[,n]=tn(e),r=Gs(t,e);return t.wall?n*Math.cos(r)+Ge:!t.flat&&r<.001?n+Ge:t.flat&&e.rack==="ew"?n*Math.cos(r)+.08:n*Math.cos(r)+Math.max(.3,2*n*Math.sin(r))}function Tn(t,e){let[n,r]=tn(e),o=Pr(e),i=Math.max(1,...o);return[i*n+(i-1)*Ge,(o.length-1)*Ir(t,e)+r*Math.cos(Gs(t,e))]}var fb=t=>t.flat&&!t.unbounded&&!t.wall;function qd(t,e){if(!fb(t)||!e.rotation)return null;let n=e.rotation*Se,[r,o]=Tn(t,e);return{cos:Math.cos(n),sin:Math.sin(n),u:e.u+r/2,s:e.v+o/2}}function je(t,e,n=!1){let[r,o]=tn(e),i=Gs(t,e),s=o*Math.cos(i),l=Ir(t,e),a=Pr(e),c=Math.max(1,...a),d=new Set(e.skip??[]),u=qd(t,e),p=(y,b)=>u?[u.u+(y-u.u)*u.cos-(b-u.s)*u.sin,u.s+(y-u.u)*u.sin+(b-u.s)*u.cos]:[y,b],h=(y,b,v)=>{let[w,x]=p(y,b);return[0,1,2].map(k=>t.o[k]+t.eu[k]*w+t.es[k]*x+t.n[k]*v)},f=(y,b)=>{let[v,w]=p(y,b);if(t.unbounded)return!0;if(w<-1e-6||w>t.ls+1e-6)return!1;let[x,k]=t.span(w);return v>=x-1e-6&&v<=k+1e-6},g=[];return a.forEach((y,b)=>{let v=e.align==="right"?c-y:e.align==="center"?(c-y)/2:0;for(let w=0;w.001?s:o);if([[$,F],[A,F],[A,T],[$,T]].every(([I,z])=>f(I,z)))if(t.wall&&i>.001){let I=ot+o*Math.sin(i),[z,C]=e.flip?[I,ot]:[ot,I],B=[h($,F,z),h(A,F,z),h(A,T,C),h($,T,C)],q=e.flip?F:T;g.push({corners:B,posts:[$+.05,A-.05].map(ye=>[h(ye,q,0),h(ye,q,I)]),cell:x,skipped:k})}else if(!t.flat&&i>.001){let I=ot+o*Math.sin(i),z=[h($,F,ot),h(A,F,ot),h(A,T,I),h($,T,I)];g.push({corners:z,posts:[$+.05,A-.05].map(C=>[h(C,T,0),h(C,T,I)]),cell:x,skipped:k})}else if(!t.flat)g.push({corners:[h($,F,ot),h(A,F,ot),h(A,T,ot),h($,T,ot)],posts:[],cell:x,skipped:k});else{let z=.15+o*Math.sin(i),C=e.rack==="ew"&&b%2===1?!e.flip:!!e.flip,[B,q]=C?[T,F]:[F,T],ye=[h($,B,.15),h(A,B,.15),h(A,q,z),h($,q,z)],$t=[$+.05,A-.05].flatMap(V=>[[h(V,B,0),h(V,B,.15)],[h(V,q,0),h(V,q,z)]]);g.push({corners:ye,posts:$t,cell:x,skipped:k})}}}),g}function dt(t,e){if(t.unbounded)return{u:e.u,v:e.v};let[n,r]=Tn(t,e),o=qd(t,e);if(o){let[s,l]=[(n*Math.abs(o.cos)+r*Math.abs(o.sin))/2,(n*Math.abs(o.sin)+r*Math.abs(o.cos))/2],a=(u,p,h)=>Math.floor(Math.max(p,Math.min(u,h-p))*100+1e-6)/100,[c,d]=[e.u+n/2,e.v+r/2];return{u:Math.round((a(c,s,t.lu)-n/2)*100)/100,v:Math.round((a(d,l,t.ls)-r/2)*100)/100}}let i=s=>Math.floor(s*100+1e-6)/100;return{u:i(Math.min(Math.max(0,e.u),Math.max(0,t.lu-n))),v:i(Math.min(Math.max(0,e.v),Math.max(0,t.ls-r)))}}function Dr(t,e){let[n,r]=Tn(t,e),[o,i]=[e.u+n/2,e.v+r/2];return[t.o[0]+t.eu[0]*o+t.es[0]*i,t.o[2]+t.eu[2]*o+t.es[2]*i]}var ei=.78,Or=1.18,nn=t=>({id:t.id,face:t.face,u:t.u,v:t.v,rows:1,cols:1,portrait:!0,module_w:t.w||ei,module_h:t.h||Or});function js(t,e){let n=je(t,nn(e))[0];if(!n)return null;let r=o=>[o[0]-t.n[0]*.05,o[1]-t.n[1]*.05,o[2]-t.n[2]*.05];return n.corners.map(r)}var Tr={brick:{w:.5,d:.5,h:1},round:{w:.4,d:.4,h:1},wide:{w:1,d:.5,h:1},steel:{w:.2,d:.2,h:1.2}};function rn(t){let e=t.shape??"brick",n=Tr[e]??Tr.brick;return{shape:e,w:t.w||n.w,d:t.d||n.d,h:t.h||n.h}}function yt(t,e){let{w:n,d:r}=rn(t),o=e&&!e.flat?Math.cos(e.pitch*Se):1;return{id:t.id,face:t.face,u:t.u,v:t.v,rows:1,cols:1,portrait:!0,module_w:n,module_h:r/Math.max(.2,o),tilt:0}}function Us(t,e){let n=yt(e,t),[r,o]=[n.module_w,n.module_h],i=(d,u)=>[t.o[0]+t.eu[0]*d+t.es[0]*u,t.o[1]+t.eu[1]*d+t.es[1]*u,t.o[2]+t.eu[2]*d+t.es[2]*u],[s,l]=[i(e.u+r/2,e.v),i(e.u+r/2,e.v+o)],a=i(e.u+r/2,e.v+o/2),c=d=>{let u=Math.hypot(d[0],d[2])||1;return[d[0]/u,d[2]/u]};return{center:[a[0],a[2]],along:c(t.eu),across:c(t.es),low:Math.min(s[1],l[1]),high:Math.max(s[1],l[1])}}function Zs(t,e){let[n]=tn(e);return Ve((t.lu-(e.cols*n+(e.cols-1)*Ge))/2)}var Hr=.4;function zn(t,e){let n={id:e,face:t.key,u:0,v:0,rows:1,cols:1,portrait:!0,tilt:t.flat?15:null,flip:!1,entity:null,look:"black"},[r]=tn(n),[o,i]=t.span(t.ls/2);for(n.cols=Math.max(1,Math.floor((i-o-2*Hr+Ge)/(r+Ge))),n.rows=Math.max(1,Math.min(4,Math.floor((t.ls-2*Hr)/Ir(t,n))));n.cols>1&&je(t,{...n,u:Zs(t,n),v:Hr}).lengthl.lu*(1.3+Math.cos((Fr(l.facing,r)-180)*Math.PI/180)),i=Ke(t,n).sort((l,a)=>o(a)-o(l))[0];if(!i)return null;let s={...zn(i,e),portrait:!1,rows:1};return s.cols=Math.max(1,Math.floor((i.lu-.8+Ge)/(zr+Ge))),s.u=Ve((i.lu-(s.cols*zr+(s.cols-1)*Ge))/2),s.v=Ve(Math.max(0,i.ls-Jo-.3)),s}function Lr(t,e){let n=t.floors.flatMap(i=>i.rooms.flatMap(s=>s.points)),r=n.length?Math.max(...n.map(i=>i[0]))+3:0,o=n.length?Math.min(...n.map(i=>i[1])):0;return{id:e,face:De,u:Ve(r),v:Ve(o),rows:2,cols:4,portrait:!0,tilt:25,flip:!0,rotation:(t.settings.north??0)||0,look:"black",entity:null}}function Cr(t,e,n){let r=Qo(t,e),[o,i]=Tn(r,e),[s,l]=[e.u+o/2,e.v+i/2],a=[r.eu[0]*s+r.es[0]*l,r.eu[2]*s+r.es[2]*l],c=n*Se,d=a[0]*Math.cos(c)+a[1]*Math.sin(c)-o/2,u=a[0]*-Math.sin(c)+a[1]*Math.cos(c)-i/2;return{u:Ve(d),v:Ve(u),rotation:(Math.round(n)%360+360)%360}}function Nr(t,e){let[n,r]=t.span(t.ls/2);return{id:e,face:t.key,u:Ve((n+r-ei)/2),v:Ve(Math.max(0,Math.min(t.ls-Or,t.ls*.45-Or/2))),w:null,h:null,cover:null,contact:null,tilt:null}}function Br(t,e){let n=Tr.brick,[r,o]=t.span(t.ls*.8),i=yt({id:e,face:t.key,u:0,v:0},t).module_h;return{id:e,face:t.key,u:Ve((r+o-n.w)/2),v:Ve(Math.max(0,Math.min(t.ls-i,t.ls*.8-i/2))),shape:"brick",w:null,d:null,h:null}}function Pn(t,e){let[n,r]=[e[0]-t.o[0],e[1]-t.o[2]],[o,i,s,l]=[t.eu[0],t.eu[2],t.es[0],t.es[2]],a=o*l-i*s;if(Math.abs(a)<1e-9)return null;let c=(n*l-r*s)/a,d=(o*r-i*n)/a;if(d<0||d>t.ls)return null;let[u,p]=t.span(d);return c>=u&&c<=p?{u:c,s:d}:null}function Ys(t,e){let n=null;for(let r of t){if(r.wall){let[s,l]=[e[0]-r.o[0],e[1]-r.o[2]],a=s*r.eu[0]+l*r.eu[2],c=s*r.n[0]+l*r.n[2],d=a>=0&&a<=r.lu;if(d&&c>=-.05&&c<=.35)return{face:r,u:a,s:Number.NaN};d&&c>.35&&c<=.8&&!n&&(n={face:r,u:a,s:Number.NaN,y:-1/0});continue}let o=Pn(r,e);if(!o)continue;let i=r.o[1]+r.es[1]*o.s;(!n||i>n.y)&&(n={face:r,...o,y:i})}return n&&{face:n.face,u:n.u,s:n.s}}function ni(t,e,n){let r=Jt(n,t.n);if(Math.abs(r)<1e-6)return null;let o=Jt(We(t.o,e),t.n)/r;if(o<=0)return null;let i=We([e[0]+n[0]*o,e[1]+n[1]*o,e[2]+n[2]*o],t.o);return{t:o,u:Jt(i,t.eu),s:Jt(i,t.es)}}function Xs(t,e,n){if(t.unbounded)return!0;if(n<0||n>t.ls)return!1;let[r,o]=t.span(n);return e>=r&&e<=o}function Qs(t,e,n,r){return je(t,e).some(i=>{let s=i.corners.map(c=>{let d=We(c,t.o);return[Jt(d,t.eu),Jt(d,t.es)]}),l=s.map(c=>c[0]),a=s.map(c=>c[1]);return n>=Math.min(...l)-.05&&n<=Math.max(...l)+.05&&r>=Math.min(...a)-.05&&r<=Math.max(...a)+.05})}var mb=["n","ne","e","se","s","sw","w","nw"],Js=(t,e)=>mb[Math.round(Fr(t.facing,e)/45)%8];function Wr(t,e){let n=r=>{if(r.flat)return r.lu*r.ls*.8;let o=Math.cos((Fr(r.facing,e)-180)*Math.PI/180);return r.lu*r.ls*(1.2+o)};return[...t].sort((r,o)=>n(o)-n(r))[0]??null}var Jd=["kitchen_row","kitchen_l","bath","bedroom","living","dining","office","kids","hall"],Yd={kitchen_row:{rows:[["back","start",["fridge","kitchen_tall",["kitchen",[.9,.62,.92]],"sink","dishwasher","stove",["kitchen",[.6,.62,.92]]]],["back","start",[["kitchen_wall",[1.2,.35,.7]]]]],spots:[[["table",[1.2,.8,.75]],.5,.72,0],["lamp_pendant",.5,.72,0],["lamp_ceiling",.5,.3,0]]},kitchen_l:{rows:[["back","start",["fridge",["kitchen",[.9,.62,.92]],"sink","dishwasher","stove"]],["right","start",[["kitchen",[.9,.62,.92]],["kitchen",[.6,.62,.92]],"kitchen_tall"]],["back","start",[["kitchen_wall",[1.2,.35,.7]]]]],spots:[["table",.4,.68,0],["bar_stool",.72,.86,180],["lamp_ceiling",.5,.35,0]]},bath:{rows:[["back","center",["washbasin"]],["back","end",["wc"]],["front","start",["bathtub"]],["left","start",["washer"]]],spots:[["lamp_downlight",.5,.5,0]]},bedroom:{rows:[["back","center",["nightstand","bed","nightstand"]],["left","center",[["wardrobe",[2,.6,2.1]]]],["front","end",["dresser"]]],spots:[["lamp_ceiling",.5,.55,0]]},living:{rows:[["back","center",["tv_board"]],["right","start",["shelf"]]],spots:[["sofa",.5,.72,180],["coffee_table",.5,.52,0],[["rug",[2.2,1.6,.01]],.5,.55,0],["armchair",.14,.5,270],["lamp_floor",.86,.8,0],["plant",.9,.12,0],["lamp_ceiling",.5,.45,0]]},dining:{rows:[["back","center",["sideboard"]]],spots:[["table",.5,.55,0],["chair",.4,.35,0],["chair",.6,.35,0],["chair",.4,.75,180],["chair",.6,.75,180],["lamp_pendant",.5,.55,0]]},office:{rows:[["back","center",["desk"]],["left","center",["shelf","shelf"]]],spots:[["office_chair",.5,.38,180],["lamp_ceiling",.5,.55,0]]},kids:{rows:[["left","start",[["bed",[.9,2,.8]]]],["back","end",[["desk",[1.2,.6,.75]]]],["right","end",["shelf"]]],spots:[[["rug",[1.6,1.2,.01]],.55,.6,0],["lamp_ceiling",.5,.5,0]]},hall:{rows:[["left","start",["coat_rack"]]],spots:[["lamp_downlight",.5,.3,0],["lamp_downlight",.5,.7,0]]}},Xd=t=>typeof t=="string"?t:t[0],ri=t=>typeof t=="string"?et[t]:t[1],In=.05,gb=.02,Qd=t=>Math.round(t*1e3)/1e3;function _b(t,e,n,r){switch(e){case"back":return{x:t.x0+n,z:t.z0+r,turn:0};case"right":return{x:t.x1-r,z:t.z0+n,turn:90};case"front":return{x:t.x1-n,z:t.z1-r,turn:180};case"left":return{x:t.x0+r,z:t.z1-n,turn:270}}}function eu(t,e,n){let r=de(t.points),o=r.x1-r.x0,i=r.z1-r.z0,s=[],l=(a,c,d,u,[p,h,f])=>{s.push({id:n(),type:a,x:Qd(c),z:Qd(d),rotation:u,w:p,d:h,h:f,variant:null,entity:null,power:null})};for(let[a,c,d]of Yd[e].rows){let u=a==="back"||a==="front"?o:i,p=0,h=[];for(let g of d){if(p+ri(g)[0]>u-.1)break;h.push(g),p+=ri(g)[0]}let f=c==="start"?In:c==="end"?u-p-In:(u-p)/2;for(let g of h){let y=ri(g),b=_b(r,a,f+y[0]/2,y[1]/2+gb);l(Xd(g),b.x,b.z,b.turn,y),f+=y[0]}}for(let[a,c,d,u]of Yd[e].spots){let p=ri(a),h=(y,b,v)=>Math.min(v,Math.max(b,y)),f=h(r.x0+o*c,r.x0+p[0]/2+In,r.x1-p[0]/2-In),g=h(r.z0+i*d,r.z0+p[1]/2+In,r.z1-p[1]/2-In);l(Xd(a),f,g,u,p)}return s}var bb=30*Math.PI/180,tu=.05;function ea(t){let e=t.points.length;return t.points.map((n,r)=>{let o=t.points[(r+1)%e];return Math.hypot(o[0]-n[0],o[1]-n[1])})}function Vr(t){return ea(t).reduce((e,n)=>e+n,0)}function yb(t,e){let n=ea(t),r=0;for(let o=0;oh+f,0);if(o<3||!(i>0)||!(n>0))return null;let s=Math.min(n,i),l=(e%i+i)%i,a=0,c=0;for(;a=c+r[a];)c+=r[a],a++;let d=l-c,u=s,p=[];for(let h=0;h<=o&&u>1e-9;h++){let f=r[a]-d,g=Math.min(u,f);g>1e-9&&p.push({edge:a,t0:d,t1:d+g}),u-=g,d=0;let y=(a+1)%o;if(u>1e-9&&wb(t,a)>bb)break;a=y}for(;p.length>1&&p[0].t1-p[0].t01&&p[p.length-1].t1-p[p.length-1].t0({edge:h.edge,offset:(h.t0+h.t1)/2,width:h.t1-h.t0})):null}function Dn(t,e){let n=e[0];return n?{from:yb(t,n.edge)+n.offset-n.width/2,width:e.reduce((r,o)=>r+o.width,0)}:null}function It(t,e){return e.front?t.filter(n=>n.front===e.front):[e]}function na(t,e){let n=t.points.length,r=1/0,o=0,i=0;for(let s=0;sD("opening")){let s=ta(e,r,o);if(!s)return null;let l=It(t,n),a=new Set(l.map(h=>h.id)),c=s.length>1?l[0].front??`front-${l[0].id}`:null,d=s.map((h,f)=>({...n,id:f===0?l[0].id:i(),edge:h.edge,offset:h.offset,width:h.width,front:c})),u=[],p=!1;for(let h of t){if(!a.has(h.id)){u.push(h);continue}p||(u.push(...d),p=!0)}return u}var ia=globalThis,ra=ia.__nextfloorBuiltin?.de??{},oa=ia.__nextfloorBuiltin?.en??{};ia.__nextfloorBuiltin??={de:ra,en:oa};var vb=()=>typeof S=="object"&&S||{},kb=globalThis,xb=kb.__nextfloorTexts??=new Map;function $b(t){let e=t.toLowerCase().split("-")[0];return e!=="de"&&e!=="en"&&e in vb()?e:void 0}function nu(t){let e=$b(t),n=e===void 0?void 0:xb.get(e);return n instanceof Promise?void 0:n}function oi(t,e){return nu(t)?.[e]}function xe(t,e,n={}){let r=t?.language??navigator.language,o=r.startsWith("de"),i=(o?void 0:nu(r)?.[e])??(o?ra:oa)[e]??oa[e]??ra[e]??e;for(let[s,l]of Object.entries(n))i=i.replace(`{${s}}`,String(l));return i}function j(t,e,n=2){return e.toLocaleString(t?.language??void 0,{maximumFractionDigits:n})}var Me=se` :host { --nf-text: var(--primary-text-color, #e1e1e1); --nf-muted: var(--secondary-text-color, #9b9b9b); @@ -29,7 +29,7 @@ var S={cs:"4be67fcd522e",da:"0fe66a82bf2a",es:"bd89dffd1355",fi:"9a17bc084f56",f font-family: var(--nf-font); color: var(--nf-text); } -`,O$=se` +`,H$=se` :host([readable]) { --secondary-text-color: var(--primary-text-color, #e1e1e1); --divider-color: color-mix(in srgb, var(--primary-text-color, #e1e1e1) 40%, transparent); @@ -203,7 +203,7 @@ var S={cs:"4be67fcd522e",da:"0fe66a82bf2a",es:"bd89dffd1355",fi:"9a17bc084f56",f min-height: 40px; } } -`;var he=t=>/^(sensor|input_number|number)\./.test(t),ii=t=>/^(binary_sensor|input_boolean)\./.test(t);function On(t,e){if(!he(e))return!1;let n=t?.states[e]?.attributes;return n?.device_class==="power"||n?.unit_of_measurement==="W"||n?.unit_of_measurement==="kW"}function $b(t,e){let n=t?.entities?.[e],r=n?.area_id??(n?.device_id?t?.devices?.[n.device_id]?.area_id:null);return r?t?.areas?.[r]?.name:void 0}function L(t,e){return Object.keys(t?.states??{}).filter(e).map(n=>{let r=$b(t,n),o=t?.states[n],i=typeof o?.attributes.symcon_path=="string"?o.attributes.symcon_path:void 0,s={id:n,label:r?`${W(t,n)} \xB7 ${r}`:W(t,n)};return i&&(s.detail=`Objektbaum: ${i}`),s}).sort((n,r)=>n.label.localeCompare(r.label))}function si(t,e){return t.power&&t.power!=="none"?t.power:e.get(t.id)?.power??null}var Hn={ATTRIBUTE:1,CHILD:2,PROPERTY:3,BOOLEAN_ATTRIBUTE:4,EVENT:5,ELEMENT:6},on=t=>(...e)=>({_$litDirective$:t,values:e}),Dt=class{constructor(e){}get _$AU(){return this._$AM._$AU}_$AT(e,n,r){this._$Ct=e,this._$AM=n,this._$Ci=r}_$AS(e,n){return this.update(e,n)}update(e,n){return this.render(...n)}};var Gr=class extends Dt{constructor(e){if(super(e),this.it=_,e.type!==Hn.CHILD)throw Error(this.constructor.directiveName+"() can only be used in child bindings")}render(e){if(e===_||e==null)return this._t=void 0,this.it=e;if(e===Qe)return e;if(typeof e!="string")throw Error(this.constructor.directiveName+"() called with a non-string value");if(e===this.it)return this._t;this.it=e;let n=[e];return n.raw=n,this._t={_$litType$:this.constructor.resultType,strings:n,values:[]}}};Gr.directiveName="unsafeHTML",Gr.resultType=1;var ru=on(Gr);var{I:Sb}=tc,ou=t=>t;var su=t=>t.strings===void 0,iu=()=>document.createComment(""),Ln=(t,e,n)=>{let r=t._$AA.parentNode,o=e===void 0?t._$AB:e._$AA;if(n===void 0){let i=r.insertBefore(iu(),o),s=r.insertBefore(iu(),o);n=new Sb(i,s,t,t.options)}else{let i=n._$AB.nextSibling,s=n._$AM,l=s!==t;if(l){let a;n._$AQ?.(t),n._$AM=t,n._$AP!==void 0&&(a=t._$AU)!==s._$AU&&n._$AP(a)}if(i!==o||l){let a=n._$AA;for(;a!==i;){let c=ou(a).nextSibling;ou(r).insertBefore(a,o),a=c}}}return n},Ot=(t,e,n=t)=>(t._$AI(e,n),t),Mb={},au=(t,e=Mb)=>t._$AH=e,lu=t=>t._$AH,ai=t=>{t._$AR(),t._$AA.remove()};var cu=(t,e,n)=>{let r=new Map;for(let o=e;o<=n;o++)r.set(t[o],o);return r},du=on(class extends Dt{constructor(t){if(super(t),t.type!==Hn.CHILD)throw Error("repeat() can only be used in text expressions")}dt(t,e,n){let r;n===void 0?n=e:e!==void 0&&(r=e);let o=[],i=[],s=0;for(let l of t)o[s]=r?r(l,s):s,i[s]=n(l,s),s++;return{values:i,keys:o}}render(t,e,n){return this.dt(t,e,n).values}update(t,[e,n,r]){let o=lu(t),{values:i,keys:s}=this.dt(e,n,r);if(!Array.isArray(o))return this.ut=s,i;let l=this.ut??=[],a=[],c,d,u=0,p=o.length-1,h=0,f=i.length-1;for(;u<=p&&h<=f;)if(o[u]===null)u++;else if(o[p]===null)p--;else if(l[u]===s[h])a[h]=Ot(o[u],i[h]),u++,h++;else if(l[p]===s[f])a[f]=Ot(o[p],i[f]),p--,f--;else if(l[u]===s[f])a[f]=Ot(o[u],i[f]),Ln(t,a[f+1],o[u]),u++,f--;else if(l[p]===s[h])a[h]=Ot(o[p],i[h]),Ln(t,o[u],o[p]),p--,h++;else if(c===void 0&&(c=cu(s,h,f),d=cu(l,u,p)),c.has(l[u]))if(c.has(l[p])){let g=d.get(s[h]),y=g!==void 0?o[g]:null;if(y===null){let b=Ln(t,o[u]);Ot(b,i[h]),a[h]=b}else a[h]=Ot(y,i[h]),Ln(t,o[u],y),o[g]=null;h++}else ai(o[p]),p--;else ai(o[u]),u++;for(;h<=f;){let g=Ln(t,a[f+1]);Ot(g,i[h]),a[h++]=g}for(;u<=p;){let g=o[u++];g!==null&&ai(g)}return this.ut=s,au(t,a),Qe}});var Rb=new Intl.Collator("de",{numeric:!0,sensitivity:"base"}),sa=-1,hu=[{type:1,name:"I/O"},{type:2,name:"Splitter"},{type:0,name:"Kerninstanzen"},{type:4,name:"Konfiguratoren"},{type:5,name:"Discovery"},{type:6,name:"Visualisierungen"}],uu=t=>t.object_type===1&&hu.some(e=>e.type===t.module_type);function Eb(t){let e=new Map(t.map(a=>[a.object_id,a])),n=t.filter(a=>{if(!uu(a))return!1;let c=new Set([a.object_id]),d=e.get(a.parent_id);for(;d&&!c.has(d.object_id);){if(uu(d))return!1;c.add(d.object_id),d=e.get(d.parent_id)}return!0});if(!n.length)return t;let r=new Map(e),o=new Map;for(let a of t){let c=o.get(a.parent_id)??[];c.push(a),o.set(a.parent_id,c)}let i=(a,c,d,u,p)=>({object_id:a,parent_id:c,name:d,path:u,position:p,object_type:0,hidden:!1,icon:"",virtual:!0});r.set(sa,i(sa,0,"System","System",Number.MAX_SAFE_INTEGER));let s=new Set,l=(a,c,d)=>{if(s.has(a.object_id))return;s.add(a.object_id);let u={...a,parent_id:c,path:`${d} / ${a.name}`};r.set(a.object_id,u);for(let p of o.get(a.object_id)??[])l(p,a.object_id,u.path)};return hu.forEach((a,c)=>{let d=n.filter(h=>h.module_type===a.type);if(!d.length)return;let u=-10-a.type,p=`System / ${a.name}`;r.set(u,i(u,sa,a.name,p,c));for(let h of d)l(h,u,p)}),[...r.values()]}function aa(t){let e=Eb(t),n=new Map(e.map(o=>[o.object_id,o])),r=new Map;for(let o of e){let i=n.has(o.parent_id)?o.parent_id:0,s=r.get(i)??[];s.push(o),r.set(i,s)}for(let o of r.values())o.sort((i,s)=>i.position-s.position||i.object_type-s.object_type||Rb.compare(i.name,s.name));return{nodes:n,children:r}}function la(t,e){let n=[],r=new Set([e]),o=t.nodes.get(e)?.parent_id;for(;o&&!r.has(o)&&t.nodes.has(o);)n.push(o),r.add(o),o=t.nodes.get(o)?.parent_id;return n}function ca(t,e,n=""){let r=n.trim().toLocaleLowerCase("de").split(/\s+/).filter(Boolean),o=r.length?new Set:null;if(o){for(let a of t.nodes.values())if(r.every(c=>`${a.name} ${a.path}`.toLocaleLowerCase("de").includes(c))){o.add(a.object_id);for(let c of la(t,a.object_id))o.add(c)}}let i=[],s=new Set,l=(a,c)=>{let d=(t.children.get(a)??[]).filter(u=>!o||o.has(u.object_id));d.forEach((u,p)=>{if(s.has(u.object_id))return;s.add(u.object_id);let h=(t.children.get(u.object_id)?.length??0)>0,f=h&&(!!o||e.has(u.object_id));i.push({node:u,depth:c,hasChildren:h,expanded:f,index:p+1,siblings:d.length}),f&&l(u.object_id,c+1)})};return l(0,0),i}var Ab=["Kategorie","Instanz","Variable","Skript","Ereignis","Medium","Link"],da=class extends ne{static properties={objects:{attribute:!1},options:{attribute:!1},fixed:{attribute:!1},value:{attribute:!1},disabled:{type:Boolean},placeholder:{attribute:!1},_query:{state:!0},_expanded:{state:!0},_pending:{state:!0},_active:{state:!0},_selected:{state:!0}};tree=aa([]);allowed=new Map;constructor(){super(),this.objects=[],this.options=[],this.fixed=[],this.value=null,this.disabled=!1,this.placeholder="Datenpunkt ausw\xE4hlen",this._query="",this._expanded=new Set,this._pending=null,this._active=null,this._selected=null}willUpdate(e){e.has("objects")&&(this.tree=aa(this.objects)),(e.has("options")||e.has("fixed"))&&(this.allowed=new Map([...this.fixed,...this.options].map(n=>[n.id,n])))}get dialog(){return this.renderRoot.querySelector("dialog")}variableNode(e){let n=this.objects.find(r=>r.entity_id===e&&r.object_type===2);return n?this.tree.nodes.get(n.object_id):void 0}async open(){if(this.disabled)return;this._pending=this.allowed.has(this.value??"")?this.value:null,this._query="";let e=this.variableNode(this.value)??this.objects.find(r=>r.entity_id===this.value);this._active=e?.object_id??null,this._selected=e?.object_id??null;let n=new Set(this._expanded);if(e)for(let r of la(this.tree,e.object_id))n.add(r);this._expanded=n,await this.updateComplete,this.isConnected&&(this.dialog?.open||this.dialog?.showModal(),this.renderRoot.querySelector(".search")?.focus(),this.renderRoot.querySelector("[aria-selected=true]")?.scrollIntoView({block:"nearest"}))}close(){this.dialog?.close()}commit(){this.disabled||!this._pending||!this.allowed.has(this._pending)||(this.value=this._pending,this.close(),this.dispatchEvent(new CustomEvent("change",{detail:{value:this.value},bubbles:!0,composed:!0})))}toggle(e){let n=new Set(this._expanded);n.has(e)?n.delete(e):n.add(e),this._expanded=n}select(e){this._active=e.object_id,e.entity_id&&this.allowed.has(e.entity_id)&&(this._pending=e.entity_id,this._selected=e.object_id)}async onTreeKey(e){let n=ca(this.tree,this._expanded,this._query),r=Math.max(0,n.findIndex(s=>s.node.object_id===this._active)),o=n[r];if(!o)return;let i=r;if(e.key==="ArrowDown")i=Math.min(n.length-1,r+1);else if(e.key==="ArrowUp")i=Math.max(0,r-1);else if(e.key==="Home")i=0;else if(e.key==="End")i=n.length-1;else if(e.key==="ArrowRight")o.hasChildren&&!o.expanded?this.toggle(o.node.object_id):o.hasChildren&&(i=Math.min(n.length-1,r+1));else if(e.key==="ArrowLeft")o.expanded&&!this._query?this.toggle(o.node.object_id):i=Math.max(0,n.findIndex(s=>s.node.object_id===o.node.parent_id));else if(e.key===" "||e.key==="Enter")this.select(o.node),e.key==="Enter"&&o.node.entity_id&&this.allowed.has(o.node.entity_id)&&this.commit();else return;e.preventDefault(),(i!==r||this._active===null)&&(this._active=n[i].node.object_id),await this.updateComplete,this.renderRoot.querySelector(`#object-${this._active}`)?.scrollIntoView({block:"nearest"})}icon(e){let n=[R``,R``,R``,R``,R``,R``,R``];return R``}renderRow(e){let{node:n}=e,r=!!n.entity_id&&this.allowed.has(n.entity_id);return m`
/^(sensor|input_number|number)\./.test(t),ii=t=>/^(binary_sensor|input_boolean)\./.test(t);function On(t,e){if(!me(e))return!1;let n=t?.states[e]?.attributes;return n?.device_class==="power"||n?.unit_of_measurement==="W"||n?.unit_of_measurement==="kW"}function Sb(t,e){let n=t?.entities?.[e],r=n?.area_id??(n?.device_id?t?.devices?.[n.device_id]?.area_id:null);return r?t?.areas?.[r]?.name:void 0}function L(t,e){return Object.keys(t?.states??{}).filter(e).map(n=>{let r=Sb(t,n),o=t?.states[n],i=typeof o?.attributes.symcon_path=="string"?o.attributes.symcon_path:void 0,s={id:n,label:r?`${W(t,n)} \xB7 ${r}`:W(t,n)};return i&&(s.detail=`Objektbaum: ${i}`),s}).sort((n,r)=>n.label.localeCompare(r.label))}function si(t,e){return t.power&&t.power!=="none"?t.power:e.get(t.id)?.power??null}var Hn={ATTRIBUTE:1,CHILD:2,PROPERTY:3,BOOLEAN_ATTRIBUTE:4,EVENT:5,ELEMENT:6},on=t=>(...e)=>({_$litDirective$:t,values:e}),Dt=class{constructor(e){}get _$AU(){return this._$AM._$AU}_$AT(e,n,r){this._$Ct=e,this._$AM=n,this._$Ci=r}_$AS(e,n){return this.update(e,n)}update(e,n){return this.render(...n)}};var Gr=class extends Dt{constructor(e){if(super(e),this.it=_,e.type!==Hn.CHILD)throw Error(this.constructor.directiveName+"() can only be used in child bindings")}render(e){if(e===_||e==null)return this._t=void 0,this.it=e;if(e===Qe)return e;if(typeof e!="string")throw Error(this.constructor.directiveName+"() called with a non-string value");if(e===this.it)return this._t;this.it=e;let n=[e];return n.raw=n,this._t={_$litType$:this.constructor.resultType,strings:n,values:[]}}};Gr.directiveName="unsafeHTML",Gr.resultType=1;var ru=on(Gr);var{I:Mb}=tc,ou=t=>t;var su=t=>t.strings===void 0,iu=()=>document.createComment(""),Ln=(t,e,n)=>{let r=t._$AA.parentNode,o=e===void 0?t._$AB:e._$AA;if(n===void 0){let i=r.insertBefore(iu(),o),s=r.insertBefore(iu(),o);n=new Mb(i,s,t,t.options)}else{let i=n._$AB.nextSibling,s=n._$AM,l=s!==t;if(l){let a;n._$AQ?.(t),n._$AM=t,n._$AP!==void 0&&(a=t._$AU)!==s._$AU&&n._$AP(a)}if(i!==o||l){let a=n._$AA;for(;a!==i;){let c=ou(a).nextSibling;ou(r).insertBefore(a,o),a=c}}}return n},Ot=(t,e,n=t)=>(t._$AI(e,n),t),Rb={},au=(t,e=Rb)=>t._$AH=e,lu=t=>t._$AH,ai=t=>{t._$AR(),t._$AA.remove()};var cu=(t,e,n)=>{let r=new Map;for(let o=e;o<=n;o++)r.set(t[o],o);return r},du=on(class extends Dt{constructor(t){if(super(t),t.type!==Hn.CHILD)throw Error("repeat() can only be used in text expressions")}dt(t,e,n){let r;n===void 0?n=e:e!==void 0&&(r=e);let o=[],i=[],s=0;for(let l of t)o[s]=r?r(l,s):s,i[s]=n(l,s),s++;return{values:i,keys:o}}render(t,e,n){return this.dt(t,e,n).values}update(t,[e,n,r]){let o=lu(t),{values:i,keys:s}=this.dt(e,n,r);if(!Array.isArray(o))return this.ut=s,i;let l=this.ut??=[],a=[],c,d,u=0,p=o.length-1,h=0,f=i.length-1;for(;u<=p&&h<=f;)if(o[u]===null)u++;else if(o[p]===null)p--;else if(l[u]===s[h])a[h]=Ot(o[u],i[h]),u++,h++;else if(l[p]===s[f])a[f]=Ot(o[p],i[f]),p--,f--;else if(l[u]===s[f])a[f]=Ot(o[u],i[f]),Ln(t,a[f+1],o[u]),u++,f--;else if(l[p]===s[h])a[h]=Ot(o[p],i[h]),Ln(t,o[u],o[p]),p--,h++;else if(c===void 0&&(c=cu(s,h,f),d=cu(l,u,p)),c.has(l[u]))if(c.has(l[p])){let g=d.get(s[h]),y=g!==void 0?o[g]:null;if(y===null){let b=Ln(t,o[u]);Ot(b,i[h]),a[h]=b}else a[h]=Ot(y,i[h]),Ln(t,o[u],y),o[g]=null;h++}else ai(o[p]),p--;else ai(o[u]),u++;for(;h<=f;){let g=Ln(t,a[f+1]);Ot(g,i[h]),a[h++]=g}for(;u<=p;){let g=o[u++];g!==null&&ai(g)}return this.ut=s,au(t,a),Qe}});var Eb=new Intl.Collator("de",{numeric:!0,sensitivity:"base"}),sa=-1,hu=[{type:1,name:"I/O"},{type:2,name:"Splitter"},{type:0,name:"Kerninstanzen"},{type:4,name:"Konfiguratoren"},{type:5,name:"Discovery"},{type:6,name:"Visualisierungen"}],uu=t=>t.object_type===1&&hu.some(e=>e.type===t.module_type);function Ab(t){let e=new Map(t.map(a=>[a.object_id,a])),n=t.filter(a=>{if(!uu(a))return!1;let c=new Set([a.object_id]),d=e.get(a.parent_id);for(;d&&!c.has(d.object_id);){if(uu(d))return!1;c.add(d.object_id),d=e.get(d.parent_id)}return!0});if(!n.length)return t;let r=new Map(e),o=new Map;for(let a of t){let c=o.get(a.parent_id)??[];c.push(a),o.set(a.parent_id,c)}let i=(a,c,d,u,p)=>({object_id:a,parent_id:c,name:d,path:u,position:p,object_type:0,hidden:!1,icon:"",virtual:!0});r.set(sa,i(sa,0,"System","System",Number.MAX_SAFE_INTEGER));let s=new Set,l=(a,c,d)=>{if(s.has(a.object_id))return;s.add(a.object_id);let u={...a,parent_id:c,path:`${d} / ${a.name}`};r.set(a.object_id,u);for(let p of o.get(a.object_id)??[])l(p,a.object_id,u.path)};return hu.forEach((a,c)=>{let d=n.filter(h=>h.module_type===a.type);if(!d.length)return;let u=-10-a.type,p=`System / ${a.name}`;r.set(u,i(u,sa,a.name,p,c));for(let h of d)l(h,u,p)}),[...r.values()]}function aa(t){let e=Ab(t),n=new Map(e.map(o=>[o.object_id,o])),r=new Map;for(let o of e){let i=n.has(o.parent_id)?o.parent_id:0,s=r.get(i)??[];s.push(o),r.set(i,s)}for(let o of r.values())o.sort((i,s)=>i.position-s.position||i.object_type-s.object_type||Eb.compare(i.name,s.name));return{nodes:n,children:r}}function la(t,e){let n=[],r=new Set([e]),o=t.nodes.get(e)?.parent_id;for(;o&&!r.has(o)&&t.nodes.has(o);)n.push(o),r.add(o),o=t.nodes.get(o)?.parent_id;return n}function ca(t,e,n=""){let r=n.trim().toLocaleLowerCase("de").split(/\s+/).filter(Boolean),o=r.length?new Set:null;if(o){for(let a of t.nodes.values())if(r.every(c=>`${a.name} ${a.path}`.toLocaleLowerCase("de").includes(c))){o.add(a.object_id);for(let c of la(t,a.object_id))o.add(c)}}let i=[],s=new Set,l=(a,c)=>{let d=(t.children.get(a)??[]).filter(u=>!o||o.has(u.object_id));d.forEach((u,p)=>{if(s.has(u.object_id))return;s.add(u.object_id);let h=(t.children.get(u.object_id)?.length??0)>0,f=h&&(!!o||e.has(u.object_id));i.push({node:u,depth:c,hasChildren:h,expanded:f,index:p+1,siblings:d.length}),f&&l(u.object_id,c+1)})};return l(0,0),i}var Fb=["Kategorie","Instanz","Variable","Skript","Ereignis","Medium","Link"],da=class extends ne{static properties={objects:{attribute:!1},options:{attribute:!1},fixed:{attribute:!1},value:{attribute:!1},disabled:{type:Boolean},placeholder:{attribute:!1},_query:{state:!0},_expanded:{state:!0},_pending:{state:!0},_active:{state:!0},_selected:{state:!0}};tree=aa([]);allowed=new Map;constructor(){super(),this.objects=[],this.options=[],this.fixed=[],this.value=null,this.disabled=!1,this.placeholder="Datenpunkt ausw\xE4hlen",this._query="",this._expanded=new Set,this._pending=null,this._active=null,this._selected=null}willUpdate(e){e.has("objects")&&(this.tree=aa(this.objects)),(e.has("options")||e.has("fixed"))&&(this.allowed=new Map([...this.fixed,...this.options].map(n=>[n.id,n])))}get dialog(){return this.renderRoot.querySelector("dialog")}variableNode(e){let n=this.objects.find(r=>r.entity_id===e&&r.object_type===2);return n?this.tree.nodes.get(n.object_id):void 0}async open(){if(this.disabled)return;this._pending=this.allowed.has(this.value??"")?this.value:null,this._query="";let e=this.variableNode(this.value)??this.objects.find(r=>r.entity_id===this.value);this._active=e?.object_id??null,this._selected=e?.object_id??null;let n=new Set(this._expanded);if(e)for(let r of la(this.tree,e.object_id))n.add(r);this._expanded=n,await this.updateComplete,this.isConnected&&(this.dialog?.open||this.dialog?.showModal(),this.renderRoot.querySelector(".search")?.focus(),this.renderRoot.querySelector("[aria-selected=true]")?.scrollIntoView({block:"nearest"}))}close(){this.dialog?.close()}commit(){this.disabled||!this._pending||!this.allowed.has(this._pending)||(this.value=this._pending,this.close(),this.dispatchEvent(new CustomEvent("change",{detail:{value:this.value},bubbles:!0,composed:!0})))}toggle(e){let n=new Set(this._expanded);n.has(e)?n.delete(e):n.add(e),this._expanded=n}select(e){this._active=e.object_id,e.entity_id&&this.allowed.has(e.entity_id)&&(this._pending=e.entity_id,this._selected=e.object_id)}async onTreeKey(e){let n=ca(this.tree,this._expanded,this._query),r=Math.max(0,n.findIndex(s=>s.node.object_id===this._active)),o=n[r];if(!o)return;let i=r;if(e.key==="ArrowDown")i=Math.min(n.length-1,r+1);else if(e.key==="ArrowUp")i=Math.max(0,r-1);else if(e.key==="Home")i=0;else if(e.key==="End")i=n.length-1;else if(e.key==="ArrowRight")o.hasChildren&&!o.expanded?this.toggle(o.node.object_id):o.hasChildren&&(i=Math.min(n.length-1,r+1));else if(e.key==="ArrowLeft")o.expanded&&!this._query?this.toggle(o.node.object_id):i=Math.max(0,n.findIndex(s=>s.node.object_id===o.node.parent_id));else if(e.key===" "||e.key==="Enter")this.select(o.node),e.key==="Enter"&&o.node.entity_id&&this.allowed.has(o.node.entity_id)&&this.commit();else return;e.preventDefault(),(i!==r||this._active===null)&&(this._active=n[i].node.object_id),await this.updateComplete,this.renderRoot.querySelector(`#object-${this._active}`)?.scrollIntoView({block:"nearest"})}icon(e){let n=[R``,R``,R``,R``,R``,R``,R``];return R``}renderRow(e){let{node:n}=e,r=!!n.entity_id&&this.allowed.has(n.entity_id);return m`
${this.icon(n.object_type)}${n.name||"(Ohne Namen)"} - ${n.virtual?"Systembereich":Ab[n.object_type]??"Objekt"}${n.hidden?" \xB7 ausgeblendet":""} + ${n.virtual?"Systembereich":Fb[n.object_type]??"Objekt"}${n.hidden?" \xB7 ausgeblendet":""} ${r&&n.object_id===this._selected&&n.entity_id===this._pending?m``:_}
`}render(){let e=this.allowed.get(this.value??""),n=this.variableNode(this.value),r=this.allowed.get(this._pending??""),o=this._selected===null?void 0:this.tree.nodes.get(this._selected),i=(o?.entity_id===this._pending?o:void 0)??this.variableNode(this._pending),s=ca(this.tree,this._expanded,this._query),l=s.find(a=>a.node.object_id===this._active);return m``;function Db(t){let e=t.doc.settings.favorites??[],n=l=>t.change(a=>a.settings.favorites=ht(l)),r=t.doc.floors,o=t.doc.settings.favorite_floors??{},i=L(t.hass,l=>Fb.includes(l.split(".")[0])&&!e.includes(l)),s=(l,a)=>m`
+ `}function mu(t,e,n){let r=t.find(a=>a.person===e),o="sensor"in n?n.sensor&&n.sensor!=="none"?n.sensor:null:r?.sensor??null,i="room"in n?n.room||null:r?.room??null,s=t.filter(a=>a.person!==e);if(!o&&!i)return s;let l=i?{person:e,sensor:o,room:i}:{person:e,sensor:o};return r?t.map(a=>a.person===e?l:a):[...s,l]}function gu(t,e){let n=e.slice(e.indexOf(".")+1),r=o=>o.id.includes(n)&&/(area|room|raum|bermuda|espresense)/.test(o.id);return[...t.filter(r),...t.filter(o=>!r(o))]}function _u(t){let e=t.target?`, target: { x: ${t.target.x}, y: ${t.target.y}, z: ${t.target.z} }`:"";return`start_view: { theta: ${t.theta}, phi: ${t.phi}, radius: ${t.radius}${e} }`}function bu(t){let e=t.trim();if(!e)return{ok:!0,value:null};try{let n=JSON.parse(e);return n&&typeof n=="object"&&!Array.isArray(n)?{ok:!0,value:n}:{ok:!1}}catch{return{ok:!1}}}function li(t,e,n){let r=[...t],[o]=r.splice(e,1);return r.splice(Math.max(0,Math.min(r.length,e+n)),0,o),r}var Lt=(t,e)=>t.filter((n,r)=>r!==e),jr=(t,e,n)=>t.map((r,o)=>o===e?{...r,...n}:r),ht=t=>t.length>0?t:void 0;var Tb=["scene","script","automation","button","input_button","switch","input_boolean","light","fan","cover","lock"],zb=40,Pb=20,Ib=30,Db=["music","url","playlist","SPOTIFY","AMAZON_MUSIC","TUNEIN","APPLE_MUSIC"],pa={navigate:"/lovelace/rollos",more_info:"cover.wohnzimmer",service:"script.turn_on",fire_dom_event:""},Ur=(t,e,n,r=!1)=>m``;function Ob(t){let e=t.doc.settings.favorites??[],n=l=>t.change(a=>a.settings.favorites=ht(l)),r=t.doc.floors,o=t.doc.settings.favorite_floors??{},i=L(t.hass,l=>Tb.includes(l.split(".")[0])&&!e.includes(l)),s=(l,a)=>m`
${W(t.hass,l)} ${r.length>1?m` - `}function Vb(t){let e=t.doc.settings.buttons??[],n=s=>t.change(l=>l.settings.buttons=ht(s)),r=(s,l)=>n(jr(e,s,l)),o=zo.map(s=>[s,t.t(`own_action_${s}`)]),i=(s,l)=>m`
+ `}function Kb(t){let e=t.doc.settings.buttons??[],n=s=>t.change(l=>l.settings.buttons=ht(s)),r=(s,l)=>n(jr(e,s,l)),o=zo.map(s=>[s,t.t(`own_action_${s}`)]),i=(s,l)=>m`
${Z(t,t.t("own_button_label"),s.label,a=>r(l,{label:a||t.t("own_button_new")}),{maxlength:60})} ${O(t,t.t("own_button_action"),s.action,o,a=>r(l,{action:a}))} ${Ht(t,s.icon??null,a=>r(l,{icon:a}))} ${s.action!=="fire_dom_event"?Z(t,t.t(`own_target_${s.action}`),s.target??"",a=>r(l,{target:a||null}),{wide:!0,placeholder:pa[s.action]}):_} @@ -526,15 +526,15 @@ var S={cs:"4be67fcd522e",da:"0fe66a82bf2a",es:"bd89dffd1355",fi:"9a17bc084f56",f
`;return m`

${t.t("own_buttons")}

${M(t.t("own_buttons_hint"))} ${e.map(i)} - ${e.lengthn([...e,{id:D("btn"),label:t.t("own_button_new"),action:"navigate",target:null}])}>+ ${t.t("own_button_add")}`):_}`}function Kb(t){let e=t.doc.settings.room_facts_off??[],n=["sun","comfort","air","circuits"].map(r=>H(t,t.t(`room_fact_${r}`),!e.includes(r),o=>t.change(i=>i.settings.room_facts_off=ht(o?e.filter(s=>s!==r):[...e,r]))));return m`

${t.t("room_facts")}

${n}
`}function yu(t){return m`
${Db(t)} ${Vb(t)} ${Lb(t)} ${Cb(t)} ${Nb(t)} ${Wb(t)} ${Kb(t)}
`}function wu(t,e){return m`
+ ${e.lengthn([...e,{id:D("btn"),label:t.t("own_button_new"),action:"navigate",target:null}])}>+ ${t.t("own_button_add")}`):_}`}function Gb(t){let e=t.doc.settings.room_facts_off??[],n=["sun","comfort","air","circuits"].map(r=>H(t,t.t(`room_fact_${r}`),!e.includes(r),o=>t.change(i=>i.settings.room_facts_off=ht(o?e.filter(s=>s!==r):[...e,r]))));return m`

${t.t("room_facts")}

${n}
`}function yu(t){return m`
${Ob(t)} ${Kb(t)} ${Cb(t)} ${Nb(t)} ${Bb(t)} ${Vb(t)} ${Gb(t)}
`}function wu(t,e){return m`
🌳 ${t.t("outside_area")} - ${Ob(t,e)} + ${Hb(t,e)}
`}function vu(t,e){let n=t.doc.settings.start_view??null,r=()=>{let o=e();o&&t.change(i=>i.settings.start_view=o)};return m`
${t.t("start_view")} ${M(t.t("start_view_hint"))} ${Y(m``,n?m``:_)} ${n?m`${M(t.t("start_view_saved"))} ${M(t.t("start_view_card"))}${_u(n)}`:_} -
`}function ku(t){let e=t.doc.presence.map(a=>a.person),n=[...new Set([...Object.keys(t.hass?.states??{}).filter(a=>a.startsWith("person.")).sort(),...e])],r=L(t.hass,he),o=t.doc.floors.flatMap(a=>a.rooms.map(c=>({id:c.id,label:t.doc.floors.length>1?`${a.name} \xB7 ${c.name}`:c.name}))),i=(a,c)=>t.replace({...structuredClone(t.doc),presence:mu(t.doc.presence,a,c)}),s=a=>{let c=t.doc.presence.find(u=>u.person===a),d=!a.startsWith("person.");return m`${P(t,`${W(t.hass,a)} \xB7 ${t.t("presence_sensor")}`,c?.sensor??null,void 0,gu(r,a),u=>i(a,{sensor:u}))} +
`}function ku(t){let e=t.doc.presence.map(a=>a.person),n=[...new Set([...Object.keys(t.hass?.states??{}).filter(a=>a.startsWith("person.")).sort(),...e])],r=L(t.hass,me),o=t.doc.floors.flatMap(a=>a.rooms.map(c=>({id:c.id,label:t.doc.floors.length>1?`${a.name} \xB7 ${c.name}`:c.name}))),i=(a,c)=>t.replace({...structuredClone(t.doc),presence:mu(t.doc.presence,a,c)}),s=a=>{let c=t.doc.presence.find(u=>u.person===a),d=!a.startsWith("person.");return m`${P(t,`${W(t.hass,a)} \xB7 ${t.t("presence_sensor")}`,c?.sensor??null,void 0,gu(r,a),u=>i(a,{sensor:u}))} `,Sy={added:"\uFF0B",removed:"\u2212",renamed:"\u270E",reshaped:"\u2922",moved:"\u2194"};function My(t,e){let n=t.t;if(!e.length)return m`

${n("version_same")}

`;let r=i=>i.kind.startsWith("furniture")?qe(t.hass,i.name)||i.name:i.kind.startsWith("device")?String(t.hass?.states[i.name]?.attributes.friendly_name??i.name):i.kind.startsWith("opening")?n(i.name==="door"?"opening_door":i.name==="garage"?"opening_garage":"opening_window"):i.name,o=[...new Set(e.map(i=>i.floor))];return m`
+`,My={added:"\uFF0B",removed:"\u2212",renamed:"\u270E",reshaped:"\u2922",moved:"\u2194"};function Ry(t,e){let n=t.t;if(!e.length)return m`

${n("version_same")}

`;let r=i=>i.kind.startsWith("furniture")?qe(t.hass,i.name)||i.name:i.kind.startsWith("device")?String(t.hass?.states[i.name]?.attributes.friendly_name??i.name):i.kind.startsWith("opening")?n(i.name==="door"?"opening_door":i.name==="garage"?"opening_garage":"opening_window"):i.name,o=[...new Set(e.map(i=>i.floor))];return m`
${M(n("version_diff_n",{n:e.length}))} ${o.map(i=>m`

${i}

    - ${e.filter(s=>s.floor===i).map(s=>{let l=s.kind.slice(s.kind.indexOf("_")+1),a=typeof s.detail=="number"?`${s.detail>0?"+":""}${j(t.hass,s.detail,1)}`:s.detail??"";return m`
  • ${n(`diff_${s.kind}`,{name:r(s),detail:a})}
  • `})} + ${e.filter(s=>s.floor===i).map(s=>{let l=s.kind.slice(s.kind.indexOf("_")+1),a=typeof s.detail=="number"?`${s.detail>0?"+":""}${j(t.hass,s.detail,1)}`:s.detail??"";return m`
  • ${n(`diff_${s.kind}`,{name:r(s),detail:a})}
  • `})}
`)}
`}function Xu(t,e){let n=t.t,r=e.history,o=r===null?M(n("loading")):r.length===0?M(n("backup_none")):m`
${r.map(i=>m`
@@ -615,7 +615,7 @@ ${i}`}else o=ju(s)}}catch(s){let l=s.message,a={not_json:"import_error_not_json" ${i.name?m``:_}
- ${e.compare?.snapshot.id===i.id?My(t,e.compare.entries):_}`)} + ${e.compare?.snapshot.id===i.id?Ry(t,e.compare.entries):_}`)}
`;return m`
i.target.open&&void e.loadHistory()}> ${n("backup")}

${n("backup_history")}

@@ -627,7 +627,7 @@ ${i}`}else o=ju(s)}}catch(s){let l=s.message,a={not_json:"import_error_not_json"

${n("backup_full")}

${Y(m``,Yu(n("backup_full_import"),i=>{e.importFull(i)}))} ${M(n("backup_full_hint"))} -
`}function Qu(t,e){return e&&t.states[e]?e:Object.keys(t.states).filter(n=>n.startsWith("weather.")).sort()[0]??null}var Ju=["body","wood","fabric","white","metal","dark"],eh={body:"#172238",wood:"#19233c",fabric:"#1a2644",white:"#1d2946",metal:"#2a3a60",dark:"#0b111f"};var dn=(t,e,n)=>Math.min(n,Math.max(e,t)),Ry=t=>(Math.round(t)%360+360)%360,_a=(t,e)=>Ry(t+e);function th(t,e,n){return n?[...new Set([...t,e])]:t.filter(r=>r!==e)}function nh(t,e,n){let r=t.t,o=s=>()=>n(_a(e,s)),i=R` + `}function Qu(t,e){return e&&t.states[e]?e:Object.keys(t.states).filter(n=>n.startsWith("weather.")).sort()[0]??null}var Ju=["body","wood","fabric","white","metal","dark"],eh={body:"#172238",wood:"#19233c",fabric:"#1a2644",white:"#1d2946",metal:"#2a3a60",dark:"#0b111f"};var dn=(t,e,n)=>Math.min(n,Math.max(e,t)),Ey=t=>(Math.round(t)%360+360)%360,_a=(t,e)=>Ey(t+e);function th(t,e,n){return n?[...new Set([...t,e])]:t.filter(r=>r!==e)}function nh(t,e,n){let r=t.t,o=s=>()=>n(_a(e,s)),i=R` @@ -648,14 +648,14 @@ ${i}`}else o=ju(s)}}catch(s){let l=s.message,a={not_json:"import_error_not_json"
${r("compass_hint")}
-
`}var Ey="https://tile.openstreetmap.org/{z}/{x}/{y}.png";var Ay=40075016686e-3,ba=Math.PI/180,Xr=18,Qr=.5,Fy=160;function Ty(t,e,n){let r=2**n,o=(e+180)/360*r,i=(1-Math.log(Math.tan(t*ba)+1/Math.cos(t*ba))/Math.PI)/2*r;return[o,i]}var zy=(t,e)=>Ay*Math.cos(t*ba)/2**e;function rh(t,e,n,r=Fy){let[o,i]=Ty(t,e,n),s=zy(t,n),l=r/s,a=2**n-1,c=[];for(let d=Math.floor(i-l);d<=Math.floor(i+l);d++)for(let u=Math.floor(o-l);u<=Math.floor(o+l);u++){if(d<0||d>a)continue;let p=(u%(a+1)+a+1)%(a+1);c.push({x:p,y:d,z:n,east:(u-o)*s,north:-(d-i)*s,size:s})}return c}function oh(t,e){return t.replace("{z}",String(e.z)).replace("{x}",String(e.x)).replace("{y}",String(e.y)).replace("{s}","abc"[(e.x+e.y)%3])}var ih=t=>t.url&&t.url.startsWith("https://")?t.url:Ey;var pi=t=>!!t&&t.on===!0&&Number.isFinite(t.lat)&&Number.isFinite(t.lon),sh=t=>({x:t.x??0,z:t.z??0,opacity:t.opacity??Qr,zoom:t.zoom??Xr});function Py(t){let e=[],n=[];for(let o of t.floors){for(let i of o.rooms)for(let[s,l]of i.points)e.push(s),n.push(l);for(let i of o.outdoor??[])for(let[s,l]of i.points)e.push(s),n.push(l)}if(!e.length)return[0,0];let r=o=>Math.round((Math.min(...o)+Math.max(...o))/2*100)/100;return[r(e),r(n)]}function ah(t,e){let[n,r]=Py(t);return{on:!0,lat:e?.lat??0,lon:e?.lon??0,x:n,z:r,opacity:Qr,zoom:Xr,url:null}}function lh(t,e,n){let r=o=>Math.round(o*100)/100;return{...t,x:r((t.x??0)+e),z:r((t.z??0)+n)}}function ch(t){let e=t.trim();return e===""?null:/^https:\/\/\S+$/.test(e)&&["{z}","{x}","{y}"].every(n=>e.includes(n))?e:void 0}var Iy=["15","16","17","18","19"],Dy=["1","5","20"],fi="5";function dh(t,e,n){let r=t.t,o=e.settings.map??null,i=t.hass?.config,s=pi(o),l=d=>{if(!d)return n(o?{...o,on:!1}:null);n(o?{...o,on:!0}:ah(e,{lat:i?.latitude,lon:i?.longitude}))},a=d=>o&&n({...o,...d}),c=(d,u)=>()=>o&&n(lh(o,d*Number(fi),u*Number(fi)));return m`
+
`}var Ay="https://tile.openstreetmap.org/{z}/{x}/{y}.png";var Fy=40075016686e-3,ba=Math.PI/180,Xr=18,Qr=.5,Ty=160;function zy(t,e,n){let r=2**n,o=(e+180)/360*r,i=(1-Math.log(Math.tan(t*ba)+1/Math.cos(t*ba))/Math.PI)/2*r;return[o,i]}var Py=(t,e)=>Fy*Math.cos(t*ba)/2**e;function rh(t,e,n,r=Ty){let[o,i]=zy(t,e,n),s=Py(t,n),l=r/s,a=2**n-1,c=[];for(let d=Math.floor(i-l);d<=Math.floor(i+l);d++)for(let u=Math.floor(o-l);u<=Math.floor(o+l);u++){if(d<0||d>a)continue;let p=(u%(a+1)+a+1)%(a+1);c.push({x:p,y:d,z:n,east:(u-o)*s,north:-(d-i)*s,size:s})}return c}function oh(t,e){return t.replace("{z}",String(e.z)).replace("{x}",String(e.x)).replace("{y}",String(e.y)).replace("{s}","abc"[(e.x+e.y)%3])}var ih=t=>t.url&&t.url.startsWith("https://")?t.url:Ay;var pi=t=>!!t&&t.on===!0&&Number.isFinite(t.lat)&&Number.isFinite(t.lon),sh=t=>({x:t.x??0,z:t.z??0,opacity:t.opacity??Qr,zoom:t.zoom??Xr});function Iy(t){let e=[],n=[];for(let o of t.floors){for(let i of o.rooms)for(let[s,l]of i.points)e.push(s),n.push(l);for(let i of o.outdoor??[])for(let[s,l]of i.points)e.push(s),n.push(l)}if(!e.length)return[0,0];let r=o=>Math.round((Math.min(...o)+Math.max(...o))/2*100)/100;return[r(e),r(n)]}function ah(t,e){let[n,r]=Iy(t);return{on:!0,lat:e?.lat??0,lon:e?.lon??0,x:n,z:r,opacity:Qr,zoom:Xr,url:null}}function lh(t,e,n){let r=o=>Math.round(o*100)/100;return{...t,x:r((t.x??0)+e),z:r((t.z??0)+n)}}function ch(t){let e=t.trim();return e===""?null:/^https:\/\/\S+$/.test(e)&&["{z}","{x}","{y}"].every(n=>e.includes(n))?e:void 0}var Dy=["15","16","17","18","19"],Oy=["1","5","20"],fi="5";function dh(t,e,n){let r=t.t,o=e.settings.map??null,i=t.hass?.config,s=pi(o),l=d=>{if(!d)return n(o?{...o,on:!1}:null);n(o?{...o,on:!0}:ah(e,{lat:i?.latitude,lon:i?.longitude}))},a=d=>o&&n({...o,...d}),c=(d,u)=>()=>o&&n(lh(o,d*Number(fi),u*Number(fi)));return m`
${H(t,r("map_on"),s,l,{title:r("map_hint")})} ${o&&o.on?m`
${E(t,r("map_lat"),o.lat,d=>a({lat:Math.max(-85,Math.min(85,d))}),1e-4)} ${E(t,r("map_lon"),o.lon,d=>a({lon:Math.max(-180,Math.min(180,d))}),1e-4)} ${i?.latitude!==void 0&&i.longitude!==void 0?m``:_} ${E(t,r("map_opacity"),Math.round((o.opacity??Qr)*100),d=>a({opacity:Math.max(5,Math.min(100,d))/100}),5,5)} - ${O(t,r("map_zoom"),String(o.zoom??Xr),Iy.map(d=>[d,d==="15"?`${d} \xB7 ${r("map_zoom_coarse")}`:d==="19"?`${d} \xB7 ${r("map_zoom_fine")}`:d]),d=>a({zoom:Number(d)}))} + ${O(t,r("map_zoom"),String(o.zoom??Xr),Dy.map(d=>[d,d==="15"?`${d} \xB7 ${r("map_zoom_coarse")}`:d==="19"?`${d} \xB7 ${r("map_zoom_fine")}`:d]),d=>a({zoom:Number(d)}))}
${r("map_move")}
@@ -664,12 +664,12 @@ ${i}`}else o=ju(s)}}catch(s){let l=s.message,a={not_json:"import_error_not_json"
- ${O(t,r("map_step"),fi,Dy.map(d=>[d,`${d} m`]),d=>fi=d,{wide:!1})} + ${O(t,r("map_step"),fi,Oy.map(d=>[d,`${d} m`]),d=>fi=d,{wide:!1})}
${Z(t,r("map_url"),o.url??"",d=>{let u=ch(d);u!==void 0&&a({url:u})},{wide:!0,placeholder:"https://\u2026/{z}/{x}/{y}.png",maxlength:300})} ${M(r("map_hint"),"nf-wide")}
`:_} -
`}var Oy=["none","flat","gable","custom"];function Hy(t,e,n){let r=t.t,o=!!e,i=s=>n({color:null,image:null,dim:.35,...e??{},...s});return m`
${r("backdrop")}
+
`}var Hy=["none","flat","gable","custom"];function Ly(t,e,n){let r=t.t,o=!!e,i=s=>n({color:null,image:null,dim:.35,...e??{},...s});return m`
${r("backdrop")}
${H(t,r("backdrop"),o,s=>n(s?{color:"#101828",image:null,dim:.35}:null))} ${o?m` ${E(t,r("backdrop_dim"),Math.round((e?.dim??.35)*100),s=>i({dim:dn(s,0,80)/100}),5,0)} ${Z(t,r("backdrop_image"),e?.image??"",s=>i({image:s||null}),{wide:!0,placeholder:"/local/hintergrund.jpg"})} - ${M(r("backdrop_hint"),"nf-wide")}`:_}`}function Ly(t,e,n){let r=t.t,o=L(t.hass,i=>!e.includes(i)&&/^(sensor|binary_sensor|alarm_control_panel|weather|input_|counter|lock|climate|person|sun)\b/.test(i));return m`
${r("status_entities")}
+ ${M(r("backdrop_hint"),"nf-wide")}`:_}`}function Cy(t,e,n){let r=t.t,o=L(t.hass,i=>!e.includes(i)&&/^(sensor|binary_sensor|alarm_control_panel|weather|input_|counter|lock|climate|person|sun)\b/.test(i));return m`
${r("status_entities")}
${e.length?m`
${e.map(i=>m`${W(t.hass,i)} ${t.admin?m``:_}`)}
`:_} ${e.length<12?P(t,r("status_add"),null,void 0,o,i=>i&&i!=="none"&&n([...e,i])):_} - ${M(r("status_entities_hint"),"nf-wide")}`}function uh(t,e){let n=t.t,r=t.doc.settings,o=c=>t.replace({...structuredClone(t.doc),settings:{...structuredClone(t.doc.settings),...c}}),i=c=>o({roof:{...r.roof,...c}}),s=Oy.map(c=>[c,n(`roof_${c}`)]),l=r.weather_effects??Oc,a=r.roof.type==="gable";return m`
+ ${M(r("status_entities_hint"),"nf-wide")}`}function uh(t,e){let n=t.t,r=t.doc.settings,o=c=>t.replace({...structuredClone(t.doc),settings:{...structuredClone(t.doc.settings),...c}}),i=c=>o({roof:{...r.roof,...c}}),s=Hy.map(c=>[c,n(`roof_${c}`)]),l=r.weather_effects??Oc,a=r.roof.type==="gable";return m`
${n("settings")}
${E(t,n("wall_exterior"),r.wall_exterior,c=>o({wall_exterior:dn(c,.02,1)}),.01,.02)} @@ -714,7 +714,7 @@ ${i}`}else o=ju(s)}}catch(s){let l=s.message,a={not_json:"import_error_not_json" ${H(t,n("night_lock_warning"),!!r.night_lock_warning,c=>o({night_lock_warning:c||void 0}),{title:n("night_lock_warning_hint")})} ${O(t,n("room_double_tap"),r.room_double_tap??"area",[["area",n("room_double_tap_area")],["plan",n("room_double_tap_plan")],["off",n("room_double_tap_off")]],c=>o({room_double_tap:c==="plan"||c==="off"?c:null}),{title:n("room_double_tap_hint")})} ${H(t,n("motion_markers_active"),!!r.motion_markers_active,c=>o({motion_markers_active:c||void 0}),{title:n("motion_markers_active_hint")})} - ${t.hass?Ly(t,r.status_entities??[],c=>o({status_entities:c.length?c:null})):_} + ${t.hass?Cy(t,r.status_entities??[],c=>o({status_entities:c.length?c:null})):_} ${t.hass?P(t,n("announce_tts"),r.announce_tts??null,void 0,L(t.hass,c=>c.startsWith("tts.")),c=>o({announce_tts:c==="none"?null:c})):_}
${M(`${n("north_hint")} ${n("weather_entity_hint")}`)} -
`}var Jr=t=>t&&t!=="none"?t:null,eo=(t,e)=>{e&&!t.includes(e)&&t.push(e)},ya=t=>new Map(t.floors.flatMap(e=>e.furniture.filter(n=>n.type==="meter").map(n=>[n.id,n])));function un(t,e){if(!t.energy.advanced||e.type!=="meter"||!e.parent_meter)return null;let n=ya(t),r=new Set([e.id]);for(let o=n.get(e.parent_meter);o;o=n.get(o.parent_meter??"")){if(r.has(o.id))return null;r.add(o.id)}return n.has(e.parent_meter)?e.parent_meter:null}function Vn(t){return new Set([...ya(t).values()].filter(e=>un(t,e)).map(e=>e.id))}function to(t,e){return!t.energy.advanced||!e.parent_meter?null:Vn(t).has(e.parent_meter)?e.parent_meter:null}function hh(t,e,n){if(n.type!=="meter"||n.id===e.id)return!1;let r=ya(t),o=new Set;for(let i=n;i&&!o.has(i.id);i=r.get(i.parent_meter??"")){if(i.id===e.id)return!1;o.add(i.id)}return!0}function gi(t,e=n=>Jr(n.power)){let n={grid:null,gridExport:null,solar:[],battery:[],charge:[],batteries:[],soc:[]};for(let r of t.floors.flatMap(o=>o.furniture)){let o=e(r),i=r.type==="meter"?un(t,r):null;if(i)(n.subMeters??=[]).push({id:r.id,parent:i,power:o,invert:!!r.meter_invert,floors:r.meter_floors??[],solar:[],batteries:[]});else if(r.type==="meter")n.grid??=o,n.gridExport??=Jr(r.export);else if(r.type==="inverter")eo(n.solar,o);else if(r.type==="home_battery"){let s=Jr(r.charge);eo(n.battery,o),eo(n.charge,s),eo(n.soc,Jr(r.soc)),(o||s)&&n.batteries.push({power:o,charge:s})}}for(let r of n.subMeters?t.floors.flatMap(o=>o.furniture):[]){let o=r.type==="inverter"||r.type==="home_battery"?n.subMeters?.find(l=>l.id===to(t,r)):void 0,i=o?e(r):null;o&&r.type==="inverter"&&eo(o.solar,i);let s=Jr(r.charge);o&&r.type==="home_battery"&&(i||s)&&o.batteries.push({power:i,charge:s})}return n}function Cy(t){for(let e of t.floors){let n=e.furniture.find(r=>r.type==="meter"&&!un(t,r));if(n)return{floor_id:e.id,x:n.x,z:n.z}}return t.energy.meter}var Ny=/(phase|_l[123]\b|_[abc]$|today|daily|heute)/,By=/_?(energy|energie|total|today|daily|kwh|import|export|consumption|production)/g;function mi(t,e,n="power"){let r=e?t.entities?.[e]?.device_id:void 0;if(!e||!r)return null;let o=Object.keys(t.states).filter(l=>l.startsWith("sensor.")&&t.entities?.[l]?.device_id===r&&t.states[l]?.attributes.device_class===n);if(o.length<=1)return o[0]??null;let i=o.filter(l=>!Ny.test(l)),s=e.replace(/^sensor\./,"").replace(By,"");return i.find(l=>s&&l.includes(s))??i[0]??o[0]}function ph(t,e){let n={},r=(o,i)=>{i&&!n[o]&&(n[o]=i)};for(let o of e.energy_sources??[])if(o.type==="grid")r("grid",mi(t,o.flow_from?.[0]?.stat_energy_from??o.flow_to?.[0]?.stat_energy_to));else if(o.type==="solar")r("solar",mi(t,o.stat_energy_from));else if(o.type==="battery"){let i=o.stat_energy_from??o.stat_energy_to;r("battery",mi(t,i)),r("battery_soc",mi(t,i,"battery"))}return n}function Ee(t,e=!1){let n=t?Number(t.state):NaN;if(!Number.isFinite(n))return null;let r={kW:1e3,MW:1e6}[String(t.attributes.unit_of_measurement??"W")]??1;return e?-n*r:n*r}var Wy=(t,e)=>e.startsWith("sensor.")&&t.states[e]?.attributes.device_class==="power";function fh(t,e){if(Wy(t,e))return e;let n=t.entities?.[e]?.device_id;if(!n)return null;let r=Ss(t,n),o=r?Tt(t,e):null,i=jo(t,n).filter(s=>s!==e);return(r?i.find(s=>o!==null&&Tt(t,s)===o):i[0])??null}var mh=t=>{let e=t.filter(n=>n!==null);return e.length?e.reduce((n,r)=>n+r,0):null};function Vy(t,e,n){let r=e.grid??n.grid,o=r?Ee(t.states[r],e.grid_invert):null;if(!e.grid&&n.gridExport){let i=Math.max(0,Ee(t.states[n.gridExport])??0);return Math.max(0,o??0)-i}return o}function Ky(t,e,n){return e.solar?Ee(t.states[e.solar]):n.solar.length?mh(n.solar.map(r=>Ee(t.states[r]))):null}function wa(t,e,n){return e.charge?(e.power?Math.max(0,Ee(t.states[e.power])??0):0)-Math.max(0,Ee(t.states[e.charge])??0):e.power?Ee(t.states[e.power],n):null}function Gy(t,e,n){return e.battery?Ee(t.states[e.battery],e.battery_invert):mh(n.batteries.map(r=>wa(t,r,e.battery_invert)))}function va(t,e,n,r=gi(e)){let o=e.energy,i=Vy(t,o,r),s=Ky(t,o,r),l=Gy(t,o,r),a=(o.battery_soc?[o.battery_soc]:r.soc).map(f=>Number(t.states[f]?.state)).filter(Number.isFinite),c=a.length?a.reduce((f,g)=>f+g,0)/a.length:null,d=o.tariff?t.states[o.tariff]:void 0,u=Number(d?.state),p=o.consumption?Ee(t.states[o.consumption]):null;p===null&&(i!==null||s!==null||l!==null)&&(p=(i??0)+Math.max(0,s??0)+(l??0)),p===null&&n.length>0&&(p=n.reduce((f,g)=>f+g.power,0));let h={grid:i,solar:s===null?null:Math.max(0,s),battery:l,soc:c,tariff:d&&Number.isFinite(u)?{value:u,unit:String(d.attributes.unit_of_measurement??"")}:null,consumption:p===null?null:Math.max(0,p)};return r.subMeters?{...h,...jy(t,r,h.consumption,o.battery_invert,n)}:h}function jy(t,e,n,r,o){let i=e.subMeters??[],s=new Map;for(let p of i)for(let h of p.floors)s.has(h)||s.set(h,p.id);let l=new Set([e.grid,e.gridExport,...e.solar,...e.battery,...e.charge,...i.flatMap(p=>[p.power,...p.solar,...p.batteries.flatMap(h=>[h.power,h.charge])])]),a=p=>o.filter(h=>s.get(h.floorId)===p&&!l.has(h.powerEntity)).reduce((h,f)=>h+f.power,0),c=new Map(i.map(p=>[p.id,p.power?Ee(t.states[p.power],p.invert):null])),d=i.map(p=>{let h=c.get(p.id)??null,f=p.solar.reduce((v,w)=>v+Math.max(0,Ee(t.states[w])??0),0),g=p.batteries.reduce((v,w)=>v+(wa(t,w,r)??0),0),y=i.filter(v=>v.parent===p.id).reduce((v,w)=>v+(c.get(w.id)??0),0),b=h===null?null:Math.max(0,h+f+g-y);return{id:p.id,parent:p.parent,power:h,solar:f,battery:g,use:b,unmetered:b===null?null:Math.max(0,b-a(p.id))}}),u=d.reduce((p,h)=>p+(h.use??0),0);return{subMeters:d,rest:n===null?null:Math.max(0,n-u)}}function Uy(t,e,n){let r=t.b[0]-t.a[0],o=t.b[1]-t.a[1],i=Math.hypot(r,o)||1,s=Math.min(1,Math.max(0,((e.x-t.a[0])*r+(e.z-t.a[1])*o)/(i*i))),l=t.a[0]+r*s,a=t.a[1]+o*s,c=o/i*(l-n.x)+-r/i*(a-n.z)<0?-1:1;return{x:l,z:a,nx:c*o/i,nz:-c*r/i,distance:Math.hypot(e.x-l,e.z-a)}}function gh(t){let e=Cy(t),n=e?t.floors.find(c=>c.id===e.floor_id):void 0;if(!e||!n)return null;let r={exterior:t.settings.wall_exterior,interior:t.settings.wall_interior},o=fe(n.rooms,r,n.walls??[]).walls.filter(c=>c.exterior),i=n.rooms.flatMap(c=>c.points);if(o.length===0||i.length===0)return null;let s={x:i.reduce((c,d)=>c+d[0],0)/i.length,z:i.reduce((c,d)=>c+d[1],0)/i.length},l=o.map(c=>Uy(c,e,s)).reduce((c,d)=>d.distancef.furniture.map(g=>({floor:f,item:g}))),r=f=>n.filter(g=>g.item.type===f),o=f=>!!si(f.item,e),i=f=>({kind:"device",...f}),[s,l,a,c,d]=[t.settings.roof.solar??[],r("meter"),r("inverter"),r("home_battery"),r("grid_point")],u=!!t.energy.grid||l.some(o),p=!!t.energy.solar||a.length>0&&a.every(o),h=!!t.energy.battery||c.every(f=>o(f)&&f.item.soc&&f.item.soc!=="none");return[s.length>0?{state:"ok",label:"chk_solar",target:{kind:"solar-field",id:s[0].id}}:{state:"todo",label:"chk_solar_add",target:{kind:"add-solar-field"}},l.length>0?{state:u?"ok":"todo",label:u?"chk_meter":"chk_meter_sensor",target:i(l[0])}:{state:"todo",label:"chk_meter_add",target:{kind:"add-device",type:"meter"}},a.length>0?{state:p?"ok":"todo",label:p?"chk_inverter":"chk_inverter_sensor",target:i(a.find(f=>!o(f))??a[0])}:{state:"todo",label:"chk_inverter_add",target:{kind:"add-device",type:"inverter"}},c.length>0?{state:h?"ok":"todo",label:h?"chk_battery":"chk_battery_sensor",target:i(c[0])}:{state:"opt",label:"chk_battery_opt",target:{kind:"add-device",type:"home_battery"}},d.length>0?{state:"ok",label:"chk_grid",target:i(d[0])}:{state:"opt",label:"chk_grid_opt",target:{kind:"add-device",type:"grid_point"}}]}function no(t,e){let n=[];for(let r of t.floors)for(let o of r.furniture)o.type===e&&n.push({id:o.id,floorId:r.id,x:o.x,z:o.z,y:Math.max(.4,Math.min(1.4,o.h*.8))});return n}function Zy(t){if(!t?.rooms.length)return null;let e=0,n=0,r=0;for(let o of t.rooms)for(let[i,s]of o.points)e+=i,n+=s,r++;return r?{floorId:t.id,x:e/r,z:n/r,y:1}:null}function qy(t){let e=Vn(t);return no(t,"meter").find(n=>!e.has(n.id))??no(t,"inverter")[0]??Zy(Xo(t))}function Yy(t,e){let n=no(t,"grid_point")[0];if(n)return n;let r=t.floors.find(l=>l.id===e.floorId);if(!r?.rooms.length)return null;let o=1/0,i=-1/0,s=-1/0;for(let l of r.rooms)for(let[a,c]of l.points)o=Math.min(o,a),i=Math.max(i,a),s=Math.max(s,c);return{floorId:e.floorId,x:Math.max(o,Math.min(i,e.x)),z:s+3,y:.2}}function bh(t){let e=[],n=qy(t);if(!n)return e;let r=new Set(t.floors.flatMap(i=>i.furniture).filter(i=>to(t,i)).map(i=>i.id)),o=no(t,"inverter").find(i=>!r.has(i.id));for(let i of t.settings.roof.solar??[])e.push({key:`solar:${i.id}`,kind:"solar",id:i.id});no(t,"home_battery").some(i=>!r.has(i.id))&&e.push({key:"battery",kind:"battery",id:null}),o&&(o.floorId!==n.floorId||o.x!==n.x||o.z!==n.z)&&e.push({key:"inverter",kind:"inverter",id:null}),Yy(t,n)&&e.push({key:"grid",kind:"grid",id:null});for(let i of t.floors.flatMap(s=>s.furniture))r.has(i.id)&&(i.type==="inverter"?e.push({key:`inverter:${i.id}`,kind:"inverter",id:i.id}):i.type==="home_battery"&&e.push({key:`battery:${i.id}`,kind:"battery",id:i.id}));for(let i of Vn(t))e.push({key:`meter:${i}`,kind:"meter",id:i});return e}var yh=(t,e)=>t.energy.routes?.find(n=>n.key===e&&n.points.length>0);var Xy={ok:"\u2713",todo:"\u25CB",opt:"\xB7"},vh=t=>t.hass?Be(t.hass,t.doc.floors):new Map,Qy=Ce,kh=(t,e)=>e.name||t.t(`furn_${e.type}`);function xh(t,e){let n=_h(t.doc,vh(t)),r=n.filter(o=>o.state==="ok").length;return m`
+
`}var Jr=t=>t&&t!=="none"?t:null,eo=(t,e)=>{e&&!t.includes(e)&&t.push(e)},ya=t=>new Map(t.floors.flatMap(e=>e.furniture.filter(n=>n.type==="meter").map(n=>[n.id,n])));function un(t,e){if(!t.energy.advanced||e.type!=="meter"||!e.parent_meter)return null;let n=ya(t),r=new Set([e.id]);for(let o=n.get(e.parent_meter);o;o=n.get(o.parent_meter??"")){if(r.has(o.id))return null;r.add(o.id)}return n.has(e.parent_meter)?e.parent_meter:null}function Vn(t){return new Set([...ya(t).values()].filter(e=>un(t,e)).map(e=>e.id))}function to(t,e){return!t.energy.advanced||!e.parent_meter?null:Vn(t).has(e.parent_meter)?e.parent_meter:null}function hh(t,e,n){if(n.type!=="meter"||n.id===e.id)return!1;let r=ya(t),o=new Set;for(let i=n;i&&!o.has(i.id);i=r.get(i.parent_meter??"")){if(i.id===e.id)return!1;o.add(i.id)}return!0}function gi(t,e=n=>Jr(n.power)){let n={grid:null,gridExport:null,solar:[],battery:[],charge:[],batteries:[],soc:[]};for(let r of t.floors.flatMap(o=>o.furniture)){let o=e(r),i=r.type==="meter"?un(t,r):null;if(i)(n.subMeters??=[]).push({id:r.id,parent:i,power:o,invert:!!r.meter_invert,floors:r.meter_floors??[],solar:[],batteries:[]});else if(r.type==="meter")n.grid??=o,n.gridExport??=Jr(r.export);else if(r.type==="inverter")eo(n.solar,o);else if(r.type==="home_battery"){let s=Jr(r.charge);eo(n.battery,o),eo(n.charge,s),eo(n.soc,Jr(r.soc)),(o||s)&&n.batteries.push({power:o,charge:s})}}for(let r of n.subMeters?t.floors.flatMap(o=>o.furniture):[]){let o=r.type==="inverter"||r.type==="home_battery"?n.subMeters?.find(l=>l.id===to(t,r)):void 0,i=o?e(r):null;o&&r.type==="inverter"&&eo(o.solar,i);let s=Jr(r.charge);o&&r.type==="home_battery"&&(i||s)&&o.batteries.push({power:i,charge:s})}return n}function Ny(t){for(let e of t.floors){let n=e.furniture.find(r=>r.type==="meter"&&!un(t,r));if(n)return{floor_id:e.id,x:n.x,z:n.z}}return t.energy.meter}var By=/(phase|_l[123]\b|_[abc]$|today|daily|heute)/,Wy=/_?(energy|energie|total|today|daily|kwh|import|export|consumption|production)/g;function mi(t,e,n="power"){let r=e?t.entities?.[e]?.device_id:void 0;if(!e||!r)return null;let o=Object.keys(t.states).filter(l=>l.startsWith("sensor.")&&t.entities?.[l]?.device_id===r&&t.states[l]?.attributes.device_class===n);if(o.length<=1)return o[0]??null;let i=o.filter(l=>!By.test(l)),s=e.replace(/^sensor\./,"").replace(Wy,"");return i.find(l=>s&&l.includes(s))??i[0]??o[0]}function ph(t,e){let n={},r=(o,i)=>{i&&!n[o]&&(n[o]=i)};for(let o of e.energy_sources??[])if(o.type==="grid")r("grid",mi(t,o.flow_from?.[0]?.stat_energy_from??o.flow_to?.[0]?.stat_energy_to));else if(o.type==="solar")r("solar",mi(t,o.stat_energy_from));else if(o.type==="battery"){let i=o.stat_energy_from??o.stat_energy_to;r("battery",mi(t,i)),r("battery_soc",mi(t,i,"battery"))}return n}function Ee(t,e=!1){let n=t?Number(t.state):NaN;if(!Number.isFinite(n))return null;let r={kW:1e3,MW:1e6}[String(t.attributes.unit_of_measurement??"W")]??1;return e?-n*r:n*r}var Vy=(t,e)=>e.startsWith("sensor.")&&t.states[e]?.attributes.device_class==="power";function fh(t,e){if(Vy(t,e))return e;let n=t.entities?.[e]?.device_id;if(!n)return null;let r=Ss(t,n),o=r?Tt(t,e):null,i=jo(t,n).filter(s=>s!==e);return(r?i.find(s=>o!==null&&Tt(t,s)===o):i[0])??null}var mh=t=>{let e=t.filter(n=>n!==null);return e.length?e.reduce((n,r)=>n+r,0):null};function Ky(t,e,n){let r=e.grid??n.grid,o=r?Ee(t.states[r],e.grid_invert):null;if(!e.grid&&n.gridExport){let i=Math.max(0,Ee(t.states[n.gridExport])??0);return Math.max(0,o??0)-i}return o}function Gy(t,e,n){return e.solar?Ee(t.states[e.solar]):n.solar.length?mh(n.solar.map(r=>Ee(t.states[r]))):null}function wa(t,e,n){return e.charge?(e.power?Math.max(0,Ee(t.states[e.power])??0):0)-Math.max(0,Ee(t.states[e.charge])??0):e.power?Ee(t.states[e.power],n):null}function jy(t,e,n){return e.battery?Ee(t.states[e.battery],e.battery_invert):mh(n.batteries.map(r=>wa(t,r,e.battery_invert)))}function va(t,e,n,r=gi(e)){let o=e.energy,i=Ky(t,o,r),s=Gy(t,o,r),l=jy(t,o,r),a=(o.battery_soc?[o.battery_soc]:r.soc).map(f=>Number(t.states[f]?.state)).filter(Number.isFinite),c=a.length?a.reduce((f,g)=>f+g,0)/a.length:null,d=o.tariff?t.states[o.tariff]:void 0,u=Number(d?.state),p=o.consumption?Ee(t.states[o.consumption]):null;p===null&&(i!==null||s!==null||l!==null)&&(p=(i??0)+Math.max(0,s??0)+(l??0)),p===null&&n.length>0&&(p=n.reduce((f,g)=>f+g.power,0));let h={grid:i,solar:s===null?null:Math.max(0,s),battery:l,soc:c,tariff:d&&Number.isFinite(u)?{value:u,unit:String(d.attributes.unit_of_measurement??"")}:null,consumption:p===null?null:Math.max(0,p)};return r.subMeters?{...h,...Uy(t,r,h.consumption,o.battery_invert,n)}:h}function Uy(t,e,n,r,o){let i=e.subMeters??[],s=new Map;for(let p of i)for(let h of p.floors)s.has(h)||s.set(h,p.id);let l=new Set([e.grid,e.gridExport,...e.solar,...e.battery,...e.charge,...i.flatMap(p=>[p.power,...p.solar,...p.batteries.flatMap(h=>[h.power,h.charge])])]),a=p=>o.filter(h=>s.get(h.floorId)===p&&!l.has(h.powerEntity)).reduce((h,f)=>h+f.power,0),c=new Map(i.map(p=>[p.id,p.power?Ee(t.states[p.power],p.invert):null])),d=i.map(p=>{let h=c.get(p.id)??null,f=p.solar.reduce((v,w)=>v+Math.max(0,Ee(t.states[w])??0),0),g=p.batteries.reduce((v,w)=>v+(wa(t,w,r)??0),0),y=i.filter(v=>v.parent===p.id).reduce((v,w)=>v+(c.get(w.id)??0),0),b=h===null?null:Math.max(0,h+f+g-y);return{id:p.id,parent:p.parent,power:h,solar:f,battery:g,use:b,unmetered:b===null?null:Math.max(0,b-a(p.id))}}),u=d.reduce((p,h)=>p+(h.use??0),0);return{subMeters:d,rest:n===null?null:Math.max(0,n-u)}}function Zy(t,e,n){let r=t.b[0]-t.a[0],o=t.b[1]-t.a[1],i=Math.hypot(r,o)||1,s=Math.min(1,Math.max(0,((e.x-t.a[0])*r+(e.z-t.a[1])*o)/(i*i))),l=t.a[0]+r*s,a=t.a[1]+o*s,c=o/i*(l-n.x)+-r/i*(a-n.z)<0?-1:1;return{x:l,z:a,nx:c*o/i,nz:-c*r/i,distance:Math.hypot(e.x-l,e.z-a)}}function gh(t){let e=Ny(t),n=e?t.floors.find(c=>c.id===e.floor_id):void 0;if(!e||!n)return null;let r={exterior:t.settings.wall_exterior,interior:t.settings.wall_interior},o=pe(n.rooms,r,n.walls??[]).walls.filter(c=>c.exterior),i=n.rooms.flatMap(c=>c.points);if(o.length===0||i.length===0)return null;let s={x:i.reduce((c,d)=>c+d[0],0)/i.length,z:i.reduce((c,d)=>c+d[1],0)/i.length},l=o.map(c=>Zy(c,e,s)).reduce((c,d)=>d.distancef.furniture.map(g=>({floor:f,item:g}))),r=f=>n.filter(g=>g.item.type===f),o=f=>!!si(f.item,e),i=f=>({kind:"device",...f}),[s,l,a,c,d]=[t.settings.roof.solar??[],r("meter"),r("inverter"),r("home_battery"),r("grid_point")],u=!!t.energy.grid||l.some(o),p=!!t.energy.solar||a.length>0&&a.every(o),h=!!t.energy.battery||c.every(f=>o(f)&&f.item.soc&&f.item.soc!=="none");return[s.length>0?{state:"ok",label:"chk_solar",target:{kind:"solar-field",id:s[0].id}}:{state:"todo",label:"chk_solar_add",target:{kind:"add-solar-field"}},l.length>0?{state:u?"ok":"todo",label:u?"chk_meter":"chk_meter_sensor",target:i(l[0])}:{state:"todo",label:"chk_meter_add",target:{kind:"add-device",type:"meter"}},a.length>0?{state:p?"ok":"todo",label:p?"chk_inverter":"chk_inverter_sensor",target:i(a.find(f=>!o(f))??a[0])}:{state:"todo",label:"chk_inverter_add",target:{kind:"add-device",type:"inverter"}},c.length>0?{state:h?"ok":"todo",label:h?"chk_battery":"chk_battery_sensor",target:i(c[0])}:{state:"opt",label:"chk_battery_opt",target:{kind:"add-device",type:"home_battery"}},d.length>0?{state:"ok",label:"chk_grid",target:i(d[0])}:{state:"opt",label:"chk_grid_opt",target:{kind:"add-device",type:"grid_point"}}]}function no(t,e){let n=[];for(let r of t.floors)for(let o of r.furniture)o.type===e&&n.push({id:o.id,floorId:r.id,x:o.x,z:o.z,y:Math.max(.4,Math.min(1.4,o.h*.8))});return n}function qy(t){if(!t?.rooms.length)return null;let e=0,n=0,r=0;for(let o of t.rooms)for(let[i,s]of o.points)e+=i,n+=s,r++;return r?{floorId:t.id,x:e/r,z:n/r,y:1}:null}function Yy(t){let e=Vn(t);return no(t,"meter").find(n=>!e.has(n.id))??no(t,"inverter")[0]??qy(Xo(t))}function Xy(t,e){let n=no(t,"grid_point")[0];if(n)return n;let r=t.floors.find(l=>l.id===e.floorId);if(!r?.rooms.length)return null;let o=1/0,i=-1/0,s=-1/0;for(let l of r.rooms)for(let[a,c]of l.points)o=Math.min(o,a),i=Math.max(i,a),s=Math.max(s,c);return{floorId:e.floorId,x:Math.max(o,Math.min(i,e.x)),z:s+3,y:.2}}function bh(t){let e=[],n=Yy(t);if(!n)return e;let r=new Set(t.floors.flatMap(i=>i.furniture).filter(i=>to(t,i)).map(i=>i.id)),o=no(t,"inverter").find(i=>!r.has(i.id));for(let i of t.settings.roof.solar??[])e.push({key:`solar:${i.id}`,kind:"solar",id:i.id});no(t,"home_battery").some(i=>!r.has(i.id))&&e.push({key:"battery",kind:"battery",id:null}),o&&(o.floorId!==n.floorId||o.x!==n.x||o.z!==n.z)&&e.push({key:"inverter",kind:"inverter",id:null}),Xy(t,n)&&e.push({key:"grid",kind:"grid",id:null});for(let i of t.floors.flatMap(s=>s.furniture))r.has(i.id)&&(i.type==="inverter"?e.push({key:`inverter:${i.id}`,kind:"inverter",id:i.id}):i.type==="home_battery"&&e.push({key:`battery:${i.id}`,kind:"battery",id:i.id}));for(let i of Vn(t))e.push({key:`meter:${i}`,kind:"meter",id:i});return e}var yh=(t,e)=>t.energy.routes?.find(n=>n.key===e&&n.points.length>0);var Qy={ok:"\u2713",todo:"\u25CB",opt:"\xB7"},vh=t=>t.hass?Be(t.hass,t.doc.floors):new Map,Jy=Ce,kh=(t,e)=>e.name||t.t(`furn_${e.type}`);function xh(t,e){let n=_h(t.doc,vh(t)),r=n.filter(o=>o.state==="ok").length;return m`

☑ ${t.t("chk_title")} ${r}/${n.length}

${M(t.t("chk_hint"))} ${n.map(o=>m``)} -
`}function $h(t,e){let n=t.doc.floors.flatMap(r=>r.furniture.filter(o=>Qy.includes(o.type)).map(o=>({floor:r,item:o})));return m`
+
`}function $h(t,e){let n=t.doc.floors.flatMap(r=>r.furniture.filter(o=>Jy.includes(o.type)).map(o=>({floor:r,item:o})));return m`

⚡ ${t.t("energy_devices")}

${M(t.t("energy_devices_hint"))} ${n.length>0?m`
@@ -752,7 +752,7 @@ ${i}`}else o=ju(s)}}catch(s){let l=s.message,a={not_json:"import_error_not_json"
${Ce.map(r=>m``)}
-
`}var wh=(t,e,n)=>m`

${t.t(e)}

`;function Sh(t,e){let{energy:n}=t.doc,r=(b,v)=>t.hass?.states[b]?.attributes[v],o=L(t.hass,b=>On(t.hass,b)),i=L(t.hass,b=>he(b)&&r(b,"device_class")==="battery"),s=L(t.hass,b=>he(b)&&(r(b,"device_class")==="monetary"||/\/(kWh|MWh)$/.test(r(b,"unit_of_measurement")??""))),l=vh(t),a=gi(t.doc,b=>si(b,l)),c=b=>t.replace({...structuredClone(t.doc),energy:{...t.doc.energy,...b}}),d=L(t.hass,b=>he(b)&&["gas","water","volume_flow_rate"].includes(r(b,"device_class")??"")),u=b=>v=>c({[b]:v==="none"?null:v}),p=t.hass?va(t.hass,t.doc,[],a):null,h=!!p&&(p.solar??0)<20,f=h&&p.grid!==null&&p.grid<-50,g=h&&p.battery!==null&&p.battery<-50&&(p.grid??0)<=0,y=(b,v)=>H(t,t.t("energy_invert"),b,w=>c(v(w)));return m`
+
`}var wh=(t,e,n)=>m`

${t.t(e)}

`;function Sh(t,e){let{energy:n}=t.doc,r=(b,v)=>t.hass?.states[b]?.attributes[v],o=L(t.hass,b=>On(t.hass,b)),i=L(t.hass,b=>me(b)&&r(b,"device_class")==="battery"),s=L(t.hass,b=>me(b)&&(r(b,"device_class")==="monetary"||/\/(kWh|MWh)$/.test(r(b,"unit_of_measurement")??""))),l=vh(t),a=gi(t.doc,b=>si(b,l)),c=b=>t.replace({...structuredClone(t.doc),energy:{...t.doc.energy,...b}}),d=L(t.hass,b=>me(b)&&["gas","water","volume_flow_rate"].includes(r(b,"device_class")??"")),u=b=>v=>c({[b]:v==="none"?null:v}),p=t.hass?va(t.hass,t.doc,[],a):null,h=!!p&&(p.solar??0)<20,f=h&&p.grid!==null&&p.grid<-50,g=h&&p.battery!==null&&p.battery<-50&&(p.grid??0)<=0,y=(b,v)=>H(t,t.t("energy_invert"),b,w=>c(v(w)));return m`

⚖ ${t.t("energy_balance")}

${M(t.t("energy_balance_hint"))} ${f?wh(t,"energy_sign_grid",()=>c({grid_invert:!n.grid_invert})):_} @@ -788,12 +788,12 @@ ${i}`}else o=ju(s)}}catch(s){let l=s.message,a={not_json:"import_error_not_json"

${t.t("help_title")}

${M(t.t("help_hint"))}
${e("issues/new/choose","\u{1F41E}","help_issue")}${e("discussions/categories/ideas","\u{1F4A1}","help_idea")}
-
`}function Jy(t,e){let n=t.t,r=t.doc.floors.flatMap(i=>i.furniture).find(i=>i.id===e.id),o=r?kh(t,r):"";switch(e.kind){case"solar":{let i=t.doc.settings.roof.solar??[],s=i.findIndex(l=>l.id===e.id);return n("route_conn_solar",{name:i[s]?.name||`${n("solar_field")} ${s+1}`})}case"battery":return e.id?n("route_conn_device",{name:o}):n("route_conn_battery");case"inverter":return e.id?n("route_conn_device",{name:o}):n("route_conn_inverter");case"grid":return n("route_conn_grid");case"meter":return n("route_conn_meter",{name:o})}}function Eh(t,e){let n=bh(t.doc);if(!n.length)return _;let r=t.t,o=e.draft;return m`
+
`}function e0(t,e){let n=t.t,r=t.doc.floors.flatMap(i=>i.furniture).find(i=>i.id===e.id),o=r?kh(t,r):"";switch(e.kind){case"solar":{let i=t.doc.settings.roof.solar??[],s=i.findIndex(l=>l.id===e.id);return n("route_conn_solar",{name:i[s]?.name||`${n("solar_field")} ${s+1}`})}case"battery":return e.id?n("route_conn_device",{name:o}):n("route_conn_battery");case"inverter":return e.id?n("route_conn_device",{name:o}):n("route_conn_inverter");case"grid":return n("route_conn_grid");case"meter":return n("route_conn_meter",{name:o})}}function Eh(t,e){let n=bh(t.doc);if(!n.length)return _;let r=t.t,o=e.draft;return m`

〰 ${r("energy_routes")}

${M(r("energy_routes_hint"))}
${n.map(i=>{let s=yh(t.doc,i.key),l=o?.key===i.key;return m`
- ${Jy(t,i)} · ${s?r("route_points",{n:s.points.length}):r("route_none")} + ${e0(t,i)} · ${s?r("route_points",{n:s.points.length}):r("route_none")} ${l?m`

${r("route_drawing",{n:o.points.length})}

@@ -806,37 +806,37 @@ ${i}`}else o=ju(s)}}catch(s){let l=s.message,a={not_json:"import_error_not_json" ${s?H(t,r("route_cable"),!!s.cable,a=>e.setCable(i.key,a),{title:r("route_cable_hint")}):_}`}
`})}
-
`}var it=(t,e)=>e.map(n=>t.toScreen(n).join(",")).join(" ");function _i(t,e,n,r,o,i){let[[s,l],[a,c]]=[t.toScreen(e),t.toScreen(n)];if(Math.hypot(a-s,c-l)<=36)return _;let[d,u]=[(s+a)/2,(l+c)/2];return R``}var Ah=(t,e)=>R``,e0=(t,e,n)=>R`${Ah(...t.toScreen(e))}`,t0=(t,e,n)=>R`${Ah(...t.toScreen(e))}`;function n0(t,e,n,r){let{t:o,hass:i}=t.host,s=n.dormer?o("roof_dormer"):n.open?o("roof_open_short"):o(`roof_shape_${n.shape}`);return`${e.isFixed(n)?"\u{1F512} ":""}${r+1} \xB7 ${s} \xB7 ${j(i,Yt(n),1)} m`}function ka(t,e){let n=t.host.doc.settings.roof,r=n.type==="custom"?n.sections??[]:[],o=t.host.admin,i=(s,l)=>{let a=s.id===e.sectionId,c=ve(s),d=(s.shape==="flat"||s.shape==="parapet")&&s.points&&s.points.length>=3?s.points:null,u=Yo(r,s),p=u?ve(Hs(u,s)):c,h=d??[p.at(p.u0,0),p.at(p.u1,0),p.at(p.u1,p.w),p.at(p.u0,p.w)],g=((s.shape==="flat"||s.shape==="parapet"?null:Xt(s,{u0:0,u1:0,a:0,b:0}))?.ridges??[]).map(([C,B])=>{let[q,ye]=t.toScreen(c.at(C[0],C[1])),[$t,V]=t.toScreen(c.at(B[0],B[1]));return R``}),[y,b]=t.toScreen(c.at((c.u0+c.u1)/2,c.w/2)),v=a&&o&&!e.isFixed(s),w=[[0,0],[1,0],[1,1],[0,1]],x=s.shape==="flat"||s.shape==="parapet",[k,$,A,F]=[Math.min(s.x0,s.x1),Math.max(s.x0,s.x1),Math.min(s.z0,s.z1),Math.max(s.z0,s.z1)],T=d??(s.rotation?$r(s):[[k,A],[$,A],[$,F],[k,F]]),I=v&&x?T.map((C,B)=>_i(t,C,T[(B+1)%T.length],"roof",s.id,B)):_,z=v?R`${I}${d?d.map((C,B)=>e0(t,C,`${s.id}:${B}`)):w.map(([C,B])=>t0(t,[C?$:k,B?F:A],`${s.id}:${C}:${B}`))}`:_;return R` + `}var it=(t,e)=>e.map(n=>t.toScreen(n).join(",")).join(" ");function _i(t,e,n,r,o,i){let[[s,l],[a,c]]=[t.toScreen(e),t.toScreen(n)];if(Math.hypot(a-s,c-l)<=36)return _;let[d,u]=[(s+a)/2,(l+c)/2];return R``}var Ah=(t,e)=>R``,t0=(t,e,n)=>R`${Ah(...t.toScreen(e))}`,n0=(t,e,n)=>R`${Ah(...t.toScreen(e))}`;function r0(t,e,n,r){let{t:o,hass:i}=t.host,s=n.dormer?o("roof_dormer"):n.open?o("roof_open_short"):o(`roof_shape_${n.shape}`);return`${e.isFixed(n)?"\u{1F512} ":""}${r+1} \xB7 ${s} \xB7 ${j(i,Yt(n),1)} m`}function ka(t,e){let n=t.host.doc.settings.roof,r=n.type==="custom"?n.sections??[]:[],o=t.host.admin,i=(s,l)=>{let a=s.id===e.sectionId,c=ve(s),d=(s.shape==="flat"||s.shape==="parapet")&&s.points&&s.points.length>=3?s.points:null,u=Yo(r,s),p=u?ve(Hs(u,s)):c,h=d??[p.at(p.u0,0),p.at(p.u1,0),p.at(p.u1,p.w),p.at(p.u0,p.w)],g=((s.shape==="flat"||s.shape==="parapet"?null:Xt(s,{u0:0,u1:0,a:0,b:0}))?.ridges??[]).map(([C,B])=>{let[q,ye]=t.toScreen(c.at(C[0],C[1])),[$t,V]=t.toScreen(c.at(B[0],B[1]));return R``}),[y,b]=t.toScreen(c.at((c.u0+c.u1)/2,c.w/2)),v=a&&o&&!e.isFixed(s),w=[[0,0],[1,0],[1,1],[0,1]],x=s.shape==="flat"||s.shape==="parapet",[k,$,A,F]=[Math.min(s.x0,s.x1),Math.max(s.x0,s.x1),Math.min(s.z0,s.z1),Math.max(s.z0,s.z1)],T=d??(s.rotation?$r(s):[[k,A],[$,A],[$,F],[k,F]]),I=v&&x?T.map((C,B)=>_i(t,C,T[(B+1)%T.length],"roof",s.id,B)):_,z=v?R`${I}${d?d.map((C,B)=>t0(t,C,`${s.id}:${B}`)):w.map(([C,B])=>n0(t,[C?$:k,B?F:A],`${s.id}:${C}:${B}`))}`:_;return R` ${g} - ${n0(t,e,s,l)} - ${z}`};return R`${r.map(i)}`}function r0(t,e,n,r,o){let i=r*Math.PI/180,[s,l]=t.toScreen(n),[a,c]=t.toScreen([n[0]+Math.sin(i)*o,n[1]-Math.cos(i)*o]);return R` + ${r0(t,e,s,l)} + ${z}`};return R`${r.map(i)}`}function o0(t,e,n,r,o){let i=r*Math.PI/180,[s,l]=t.toScreen(n),[a,c]=t.toScreen([n[0]+Math.sin(i)*o,n[1]-Math.cos(i)*o]);return R` - `}function Fh(t,e){let{doc:n,admin:r}=t.host,o=n.settings.roof.solar??[];if(o.length===0)return _;let i=U(n),s=l=>{let a=ke(n,l,i);if(!a||a.wall&&a.wall.floorId!==t.floorId)return _;let c=l.id===e.solarId,d=_;if(c&&a.unbounded&&r&&!l.locked){let h=Dr(a,l),f=Math.max(...je(a,l,!0).flatMap(g=>g.corners.map(y=>Math.hypot(y[0]-h[0],y[2]-h[1]))));d=r0(t,l.id,h,l.rotation??0,.9+f*.5)}let u=h=>{let f;if(a.wall){let g=Math.max(.3,...h.corners.map(w=>(w[0]-a.o[0])*a.n[0]+(w[2]-a.o[2])*a.n[2])),[y,b]=[h.corners[0],h.corners[1]],v=w=>[w[0]+a.n[0]*g,w[2]+a.n[2]*g];f=[[y[0],y[2]],v(y),v(b),[b[0],b[2]]]}else f=h.corners.map(g=>[g[0],g[2]]);return R``},p=`nf-solar${c?" nf-solar-sel":""}${c&&e.picking?" nf-solar-pick":""}`;return R`${je(a,l,c).map(u)}${d}`};return R`${o.map(s)}`}function Th(t,e){let n=t.host.doc.settings.roof.windows??[];if(n.length===0)return _;let r=new Map(U(t.host.doc).map(i=>[i.key,i])),o=i=>{let s=r.get(i.face),l=s?js(s,i):null;return l?R`[a[0],a[2]]))} />`:_};return R`${n.map(o)}`}var o0={inverter:"\u26A1",home_battery:"\u{1F50B}",wallbox:"\u{1F50C}",meter:"\u{1F4DF}",grid_point:"\u{1F3C1}"};function zh(t,e,n){if(!e)return _;let r=e.furniture.filter(i=>Ce.includes(i.type)),o=i=>{let[s,l]=t.toScreen([i.x,i.z]),a=i.id===n,c=t.host.t(`furn_${i.type}`);return R` + `}function Fh(t,e){let{doc:n,admin:r}=t.host,o=n.settings.roof.solar??[];if(o.length===0)return _;let i=U(n),s=l=>{let a=ke(n,l,i);if(!a||a.wall&&a.wall.floorId!==t.floorId)return _;let c=l.id===e.solarId,d=_;if(c&&a.unbounded&&r&&!l.locked){let h=Dr(a,l),f=Math.max(...je(a,l,!0).flatMap(g=>g.corners.map(y=>Math.hypot(y[0]-h[0],y[2]-h[1]))));d=o0(t,l.id,h,l.rotation??0,.9+f*.5)}let u=h=>{let f;if(a.wall){let g=Math.max(.3,...h.corners.map(w=>(w[0]-a.o[0])*a.n[0]+(w[2]-a.o[2])*a.n[2])),[y,b]=[h.corners[0],h.corners[1]],v=w=>[w[0]+a.n[0]*g,w[2]+a.n[2]*g];f=[[y[0],y[2]],v(y),v(b),[b[0],b[2]]]}else f=h.corners.map(g=>[g[0],g[2]]);return R``},p=`nf-solar${c?" nf-solar-sel":""}${c&&e.picking?" nf-solar-pick":""}`;return R`${je(a,l,c).map(u)}${d}`};return R`${o.map(s)}`}function Th(t,e){let n=t.host.doc.settings.roof.windows??[];if(n.length===0)return _;let r=new Map(U(t.host.doc).map(i=>[i.key,i])),o=i=>{let s=r.get(i.face),l=s?js(s,i):null;return l?R`[a[0],a[2]]))} />`:_};return R`${n.map(o)}`}var i0={inverter:"\u26A1",home_battery:"\u{1F50B}",wallbox:"\u{1F50C}",meter:"\u{1F4DF}",grid_point:"\u{1F3C1}"};function zh(t,e,n){if(!e)return _;let r=e.furniture.filter(i=>Ce.includes(i.type)),o=i=>{let[s,l]=t.toScreen([i.x,i.z]),a=i.id===n,c=t.host.t(`furn_${i.type}`);return R` - ${o0[i.type]??"\u26A1"} + ${i0[i.type]??"\u26A1"} ${a?R`${c}`:_} ${c} `};return R`${r.map(o)}`}function Ph(t,e){let{doc:n,hass:r}=t.host;if(!(n.settings.roof.sections??[]).some(s=>Cs(s,e.elevation+e.height)))return _;let i=[1.5,2].flatMap(s=>Ns({settings:n.settings},e.elevation,s).map(([l,a])=>{let[c,d]=t.toScreen(l),[u,p]=t.toScreen(a);return R` - ${j(r,s,1)} m`}));return R`${i}`}function Ih(t,e,n,r){if(!e)return _;let o=(i,s)=>{let l=[];return i.forEach((a,c)=>{if(a.floor_id!==e.id)return;let[d,u]=t.toScreen([a.x,a.z]),p=i[c+1];if(p?.floor_id===e.id){let[f,g]=t.toScreen([p.x,p.z]);l.push(R``)}let h=p&&p.floor_id!==e.id||c>0&&i[c-1].floor_id!==e.id;l.push(R``),s&&l.push(R`${c+1}`)}),R`${l}`};return R`${n.filter(i=>i.key!==r?.key).map(i=>o(i.points,!1))}${r?o(r.points,!0):_}`}function Dh(t,e){let n=t.host.doc.settings.roof.chimneys??[];if(n.length===0)return _;let r=new Map(U(t.host.doc).map(i=>[i.key,i])),o=i=>{let s=r.get(i.face);if(!s)return _;let{shape:l,w:a,d:c}=rn(i),{center:d,along:u,across:p}=Us(s,i),h=l==="round"||l==="steel"?Array.from({length:16},(f,g)=>[d[0]+Math.cos(g/16*2*Math.PI)*Math.min(a,c)/2,d[1]+Math.sin(g/16*2*Math.PI)*Math.min(a,c)/2]):[[-1,-1],[1,-1],[1,1],[-1,1]].map(([f,g])=>[d[0]+u[0]*a*f/2+p[0]*c*g/2,d[1]+u[1]*a*f/2+p[1]*c*g/2]);return R``};return R`${n.map(o)}`}function i0(t,e,n){let[r,o]=[t+n/2,e-30];return R` + ${j(r,s,1)} m`}));return R`${i}`}function Ih(t,e,n,r){if(!e)return _;let o=(i,s)=>{let l=[];return i.forEach((a,c)=>{if(a.floor_id!==e.id)return;let[d,u]=t.toScreen([a.x,a.z]),p=i[c+1];if(p?.floor_id===e.id){let[f,g]=t.toScreen([p.x,p.z]);l.push(R``)}let h=p&&p.floor_id!==e.id||c>0&&i[c-1].floor_id!==e.id;l.push(R``),s&&l.push(R`${c+1}`)}),R`${l}`};return R`${n.filter(i=>i.key!==r?.key).map(i=>o(i.points,!1))}${r?o(r.points,!0):_}`}function Dh(t,e){let n=t.host.doc.settings.roof.chimneys??[];if(n.length===0)return _;let r=new Map(U(t.host.doc).map(i=>[i.key,i])),o=i=>{let s=r.get(i.face);if(!s)return _;let{shape:l,w:a,d:c}=rn(i),{center:d,along:u,across:p}=Us(s,i),h=l==="round"||l==="steel"?Array.from({length:16},(f,g)=>[d[0]+Math.cos(g/16*2*Math.PI)*Math.min(a,c)/2,d[1]+Math.sin(g/16*2*Math.PI)*Math.min(a,c)/2]):[[-1,-1],[1,-1],[1,1],[-1,1]].map(([f,g])=>[d[0]+u[0]*a*f/2+p[0]*c*g/2,d[1]+u[1]*a*f/2+p[1]*c*g/2]);return R``};return R`${n.map(o)}`}function s0(t,e,n){let[r,o]=[t+n/2,e-30];return R` - `}function s0(t,e){let n=e.level?.length?e.level:e.ruler;if(!n?.length)return _;let r=n.map(o=>t.toScreen(o));return R` + `}function a0(t,e){let n=e.level?.length?e.level:e.ruler;if(!n?.length)return _;let r=n.map(o=>t.toScreen(o));return R` ${r.length===2?R``:_} ${r.map(([o,i])=>R``)} `}function Oh(t,e,n){let r=n?.background,o=e.picture(r?.image_id);if(!r||!o)return _;let[i,s]=t.toScreen([r.x,r.z]),l=r.width*t.scale,a=l*o.aspect,c=e.handlesShown;return R` ${c?R` - ${i0(i,s,l)}`:_} - ${s0(t,e)}`}var a0="strict-origin-when-cross-origin",xa=new Map,Hh=new Map,bi=new Map;function l0(t){let e=xa.get(t);return e||(e=fetch(t,{referrerPolicy:a0,mode:"cors",credentials:"omit"}).then(async n=>n.ok&&(n.headers.get("content-type")??"").startsWith("image/")?await n.blob():null).catch(()=>null).then(n=>(n||setTimeout(()=>xa.delete(t),6e4),n)),xa.set(t,e)),e}function Lh(t,e){let n=Hh.get(t);if(n)return n;let r=bi.get(t);return r||(r=new Set,bi.set(t,r),l0(t).then(o=>{o&&Hh.set(t,URL.createObjectURL(o));let i=bi.get(t)??new Set;if(bi.delete(t),o)for(let s of i)s()})),r.add(e),null}function Ch(t,e){let n=e.map;if(!pi(n))return _;let r=sh(n),o=ih(n),[i,s]=t.toScreen([r.x,r.z]),l=t.scale;return R` + ${s0(i,s,l)}`:_} + ${a0(t,e)}`}var l0="strict-origin-when-cross-origin",xa=new Map,Hh=new Map,bi=new Map;function c0(t){let e=xa.get(t);return e||(e=fetch(t,{referrerPolicy:l0,mode:"cors",credentials:"omit"}).then(async n=>n.ok&&(n.headers.get("content-type")??"").startsWith("image/")?await n.blob():null).catch(()=>null).then(n=>(n||setTimeout(()=>xa.delete(t),6e4),n)),xa.set(t,e)),e}function Lh(t,e){let n=Hh.get(t);if(n)return n;let r=bi.get(t);return r||(r=new Set,bi.set(t,r),c0(t).then(o=>{o&&Hh.set(t,URL.createObjectURL(o));let i=bi.get(t)??new Set;if(bi.delete(t),o)for(let s of i)s()})),r.add(e),null}function Ch(t,e){let n=e.map;if(!pi(n))return _;let r=sh(n),o=ih(n),[i,s]=t.toScreen([r.x,r.z]),l=t.scale;return R` ${rh(n.lat,n.lon,r.zoom).map(a=>({tile:a,href:Lh(oh(o,a),t.redraw)})).filter(a=>a.href).map(({tile:a,href:c})=>R``)} - `}var $a=t=>Math.round(t*1e3)/1e3,Sa=(t,e)=>t.width*e,Kn=(t,e)=>[t.x+t.width/2,t.z+Sa(t,e)/2];function Nh(t,e,n){let[r,o]=[t[0]-e[0],t[1]-e[1]];return[e[0]+r*Math.cos(n)-o*Math.sin(n),e[1]+r*Math.sin(n)+o*Math.cos(n)]}var Bh=t=>((t+180)%360+360)%360-180;function Wh(t,e,n){return{x:$a(t[0]-e/2),z:$a(t[1]-n/2)}}function Vh(t,e,n,r){if(Math.hypot(r[0]-n[0],r[1]-n[1])<.05)return null;let o=Math.atan2(r[1]-n[1],r[0]-n[0]),i=Math.round(o/(Math.PI/2))*(Math.PI/2)-o;if(Math.abs(i)<1e-4)return null;let s=Nh(Kn(t,e),n,i),l=Math.round(Bh((t.rotation??0)+i*180/Math.PI)*100)/100;return{...t,rotation:l,...Wh(s,t.width,Sa(t,e))}}function Kh(t,e,n,r,o){let i=Math.hypot(r[0]-n[0],r[1]-n[1]);if(!(o>0)||i<1e-4)return null;let s=o/i,[l,a]=Kn(t,e),c=[n[0]+s*(l-n[0]),n[1]+s*(a-n[1])],d=t.width*s;return{...t,width:$a(d),...Wh(c,d,Sa(t,e)*s)}}function Gh(t,e,n){let r=Nh(n,Kn(t,e),-(t.rotation??0)*Math.PI/180);return[r[0]-t.x,r[1]-t.z]}function jh(t,e,n,r){let o=t+(n-e)*180/Math.PI;return Bh(r?Math.round(o/15)*15:Math.round(o*10)/10)}var c0=2048;async function Gn(t){let e=await createImageBitmap(t),n=Math.min(1,c0/Math.max(e.width,e.height)),r=document.createElement("canvas");return r.width=Math.round(e.width*n),r.height=Math.round(e.height*n),r.getContext("2d").drawImage(e,0,0,r.width,r.height),{data:r.toDataURL("image/jpeg",.85),aspect:r.height/r.width}}var yi=class{deps;editMode=!1;levelPoints=null;rulerPoints=null;rulerMetres=0;sectionOpen=!1;pictures={};loading=new Set;constructor(e){this.deps=e}get edit(){return this.editMode}set edit(e){this.editMode=e,this.deps.refresh()}get level(){return this.levelPoints}set level(e){this.levelPoints=e,this.deps.refresh()}get ruler(){return this.rulerPoints}set ruler(e){this.rulerPoints=e,this.deps.refresh()}get rulerLength(){return this.rulerMetres}set rulerLength(e){this.rulerMetres=e,this.deps.refresh()}get open(){return this.sectionOpen}set open(e){this.sectionOpen=e,this.deps.refresh()}get handlesShown(){let{host:e}=this.deps;return!!e.floor?.background&&e.admin&&this.deps.currentTool()==="select"&&this.editMode}picture(e){return e?this.pictures[e]:void 0}ensureLoaded(e){!this.pictures[e]&&!this.loading.has(e)&&this.load(e)}async load(e){let{host:n,api:r}=this.deps;if(n.hass){this.loading.add(e);try{let o=await r.fetchImage(n.hass,e),i=await this.aspectOf(o);this.pictures={...this.pictures,[e]:{url:o,aspect:i}},this.deps.refresh()}catch{}}}async aspectOf(e){let n=new Image;return n.src=e,await n.decode(),n.naturalHeight/n.naturalWidth}async upload(e){let{host:n,api:r}=this.deps;if(!e||!n.hass)return;let{data:o,aspect:i}=await this.deps.readPicture(e),s=D("img");await r.storeImage(n.hass,s,o),this.pictures={...this.pictures,[s]:{url:o,aspect:i}};let l=n.floor?.rooms??[],a=l.length>0?de(l.flatMap(d=>d.points)):null,c={image_id:s,x:a?a.x0:0,z:a?a.z0:0,width:a?Math.max(4,Math.round((a.x1-a.x0)*1e3)/1e3):12,opacity:.5};this.setBackground(c)}setBackground(e){this.deps.host.change((n,r)=>Object.assign(r,{background:e}))}toggleLevel(){this.levelPoints=this.levelPoints?null:[],this.rulerPoints=null,this.editMode=!1,this.deps.refresh()}toggleRuler(){this.rulerPoints=this.rulerPoints?null:[],this.levelPoints=null,this.editMode=!1,this.deps.refresh()}toggleEdit(){this.edit=!this.editMode,this.editMode&&this.deps.useSelectTool()}tapLevel(e){let n=[...this.levelPoints??[],e];if(n.length<2){this.level=n;return}this.level=null,this.straighten(n[0],n[1])}tapRuler(e){this.rulerPoints&&this.rulerPoints.length<2&&(this.ruler=[...this.rulerPoints,e])}straighten(e,n){let r=this.deps.host.floor?.background,o=this.picture(r?.image_id),i=r&&o?Vh(r,o.aspect,e,n):null;i&&this.setBackground(i)}applyRuler(){let e=this.deps.host.floor?.background,n=this.picture(e?.image_id),r=this.rulerPoints;if(!e||!n||!r||r.length<2)return;let o=Kh(e,n.aspect,r[0],r[1],this.rulerMetres);o&&(this.setBackground(o),this.rulerPoints=null,this.rulerMetres=0,this.deps.refresh())}};var Uh=.1,Ma=(t,e,n)=>m``;function d0(t,e){let n=e.ruler;if(!n)return _;if(n.length<2)return M(t.t(n.length>0?"bg_ruler_second":"bg_ruler_first"),"nf-wide");let r=Math.hypot(n[1][0]-n[0][0],n[1][1]-n[0][1]),o=()=>e.applyRuler();return m`${M(t.t("bg_ruler_length_hint",{m:j(t.hass,r,2)}),"nf-wide")} + `}var $a=t=>Math.round(t*1e3)/1e3,Sa=(t,e)=>t.width*e,Kn=(t,e)=>[t.x+t.width/2,t.z+Sa(t,e)/2];function Nh(t,e,n){let[r,o]=[t[0]-e[0],t[1]-e[1]];return[e[0]+r*Math.cos(n)-o*Math.sin(n),e[1]+r*Math.sin(n)+o*Math.cos(n)]}var Bh=t=>((t+180)%360+360)%360-180;function Wh(t,e,n){return{x:$a(t[0]-e/2),z:$a(t[1]-n/2)}}function Vh(t,e,n,r){if(Math.hypot(r[0]-n[0],r[1]-n[1])<.05)return null;let o=Math.atan2(r[1]-n[1],r[0]-n[0]),i=Math.round(o/(Math.PI/2))*(Math.PI/2)-o;if(Math.abs(i)<1e-4)return null;let s=Nh(Kn(t,e),n,i),l=Math.round(Bh((t.rotation??0)+i*180/Math.PI)*100)/100;return{...t,rotation:l,...Wh(s,t.width,Sa(t,e))}}function Kh(t,e,n,r,o){let i=Math.hypot(r[0]-n[0],r[1]-n[1]);if(!(o>0)||i<1e-4)return null;let s=o/i,[l,a]=Kn(t,e),c=[n[0]+s*(l-n[0]),n[1]+s*(a-n[1])],d=t.width*s;return{...t,width:$a(d),...Wh(c,d,Sa(t,e)*s)}}function Gh(t,e,n){let r=Nh(n,Kn(t,e),-(t.rotation??0)*Math.PI/180);return[r[0]-t.x,r[1]-t.z]}function jh(t,e,n,r){let o=t+(n-e)*180/Math.PI;return Bh(r?Math.round(o/15)*15:Math.round(o*10)/10)}var d0=2048;async function Gn(t){let e=await createImageBitmap(t),n=Math.min(1,d0/Math.max(e.width,e.height)),r=document.createElement("canvas");return r.width=Math.round(e.width*n),r.height=Math.round(e.height*n),r.getContext("2d").drawImage(e,0,0,r.width,r.height),{data:r.toDataURL("image/jpeg",.85),aspect:r.height/r.width}}var yi=class{deps;editMode=!1;levelPoints=null;rulerPoints=null;rulerMetres=0;sectionOpen=!1;pictures={};loading=new Set;constructor(e){this.deps=e}get edit(){return this.editMode}set edit(e){this.editMode=e,this.deps.refresh()}get level(){return this.levelPoints}set level(e){this.levelPoints=e,this.deps.refresh()}get ruler(){return this.rulerPoints}set ruler(e){this.rulerPoints=e,this.deps.refresh()}get rulerLength(){return this.rulerMetres}set rulerLength(e){this.rulerMetres=e,this.deps.refresh()}get open(){return this.sectionOpen}set open(e){this.sectionOpen=e,this.deps.refresh()}get handlesShown(){let{host:e}=this.deps;return!!e.floor?.background&&e.admin&&this.deps.currentTool()==="select"&&this.editMode}picture(e){return e?this.pictures[e]:void 0}ensureLoaded(e){!this.pictures[e]&&!this.loading.has(e)&&this.load(e)}async load(e){let{host:n,api:r}=this.deps;if(n.hass){this.loading.add(e);try{let o=await r.fetchImage(n.hass,e),i=await this.aspectOf(o);this.pictures={...this.pictures,[e]:{url:o,aspect:i}},this.deps.refresh()}catch{}}}async aspectOf(e){let n=new Image;return n.src=e,await n.decode(),n.naturalHeight/n.naturalWidth}async upload(e){let{host:n,api:r}=this.deps;if(!e||!n.hass)return;let{data:o,aspect:i}=await this.deps.readPicture(e),s=D("img");await r.storeImage(n.hass,s,o),this.pictures={...this.pictures,[s]:{url:o,aspect:i}};let l=n.floor?.rooms??[],a=l.length>0?de(l.flatMap(d=>d.points)):null,c={image_id:s,x:a?a.x0:0,z:a?a.z0:0,width:a?Math.max(4,Math.round((a.x1-a.x0)*1e3)/1e3):12,opacity:.5};this.setBackground(c)}setBackground(e){this.deps.host.change((n,r)=>Object.assign(r,{background:e}))}toggleLevel(){this.levelPoints=this.levelPoints?null:[],this.rulerPoints=null,this.editMode=!1,this.deps.refresh()}toggleRuler(){this.rulerPoints=this.rulerPoints?null:[],this.levelPoints=null,this.editMode=!1,this.deps.refresh()}toggleEdit(){this.edit=!this.editMode,this.editMode&&this.deps.useSelectTool()}tapLevel(e){let n=[...this.levelPoints??[],e];if(n.length<2){this.level=n;return}this.level=null,this.straighten(n[0],n[1])}tapRuler(e){this.rulerPoints&&this.rulerPoints.length<2&&(this.ruler=[...this.rulerPoints,e])}straighten(e,n){let r=this.deps.host.floor?.background,o=this.picture(r?.image_id),i=r&&o?Vh(r,o.aspect,e,n):null;i&&this.setBackground(i)}applyRuler(){let e=this.deps.host.floor?.background,n=this.picture(e?.image_id),r=this.rulerPoints;if(!e||!n||!r||r.length<2)return;let o=Kh(e,n.aspect,r[0],r[1],this.rulerMetres);o&&(this.setBackground(o),this.rulerPoints=null,this.rulerMetres=0,this.deps.refresh())}};var Uh=.1,Ma=(t,e,n)=>m``;function u0(t,e){let n=e.ruler;if(!n)return _;if(n.length<2)return M(t.t(n.length>0?"bg_ruler_second":"bg_ruler_first"),"nf-wide");let r=Math.hypot(n[1][0]-n[0][0],n[1][1]-n[0][1]),o=()=>e.applyRuler();return m`${M(t.t("bg_ruler_length_hint",{m:j(t.hass,r,2)}),"nf-wide")} - `}function u0(t,e){if(!t.admin)return _;let n=t.t,r=e.level;return m`${Ma(e.edit,n(e.edit?"background_edit_done":"background_edit"),()=>e.toggleEdit())} + `}function h0(t,e){if(!t.admin)return _;let n=t.t,r=e.level;return m`${Ma(e.edit,n(e.edit?"background_edit_done":"background_edit"),()=>e.toggleEdit())} ${M(n(e.edit?"background_handles_hint":"background_fixed_hint"),"nf-wide")} ${Ma(!!r,`\u{1F4D0} ${n(r?"bg_level_cancel":"bg_level")}`,()=>e.toggleLevel())} ${r?M(n(r.length>0?"bg_level_second":"bg_level_first"),"nf-wide"):_} ${Ma(!!e.ruler,`\u{1F4CF} ${n(e.ruler?"bg_ruler_cancel":"bg_ruler")}`,()=>e.toggleRuler())} - ${d0(t,e)}`}function Zh(t,e,n){let r=n.background,o=t.t,i=s=>r&&e.setBackground({...r,...s});return m`
e.open=s.target.open}> + ${u0(t,e)}`}function Zh(t,e,n){let r=n.background,o=t.t,i=s=>r&&e.setBackground({...r,...s});return m`
e.open=s.target.open}> ${o("background")}
-
`}var h0=t=>t.map((e,n)=>[e,t[(n+1)%t.length]]);function p0(t,e,n){let r=K(n,e),o=Q(r,r),i=o?Math.max(0,Math.min(1,Q(K(t,e),r)/o)):0;return me(K(t,[e[0]+r[0]*i,e[1]+r[1]*i]))}function qh(t,e,n=.03){return t.every(r=>N(r,e)||h0(e).some(([o,i])=>p0(r,o,i)<=n))}var Ra=["straight","quarter","l","half","u","spiral"],Ea=["solid","stringer","mono","cantilever"],Aa=["none","left","right","both"],Fa=["headroom","full","none"],pt={shape:"straight",turn:"right",build:"solid",risers:!0,steps:null,run_width:null,down:!1,rail:"none",opening:"headroom",landing_after:null},Ta={straight:[1,3.2],quarter:[2.2,2.6],l:[2.2,2.8],half:[2,2.6],u:[2.2,2.6],spiral:[1.6,1.6]},ep=2,tp=40;var wi=(t,e)=>typeof e=="string"&&t.includes(e);function so(t){let e=t.stair??{},n=typeof e.steps=="number"&&Number.isFinite(e.steps)?Math.round(Math.min(tp,Math.max(ep,e.steps))):null,r=typeof e.run_width=="number"&&Number.isFinite(e.run_width)&&e.run_width>.2?e.run_width:null;return{shape:wi(Ra,e.shape)?e.shape:pt.shape,turn:e.turn==="left"?"left":"right",build:wi(Ea,e.build)?e.build:pt.build,risers:e.risers!==!1,steps:n,run_width:r,down:e.down===!0,rail:wi(Aa,e.rail)?e.rail:pt.rail,opening:wi(Fa,e.opening)?e.opening:pt.opening,landing_after:typeof e.landing_after=="number"&&Number.isFinite(e.landing_after)?Math.max(1,Math.round(e.landing_after)):null}}var oo=(t,e,n)=>[t[0]+(e[0]-t[0])*n,t[1]+(e[1]-t[1])*n],Yh=(t,e)=>Math.abs(t[0]-e[0])<1e-6&&Math.abs(t[1]-e[1])<1e-6;function np(t){let e=[];for(let n of t)(!e.length||!Yh(e[e.length-1],n))&&e.push(n);for(;e.length>1&&Yh(e[0],e[e.length-1]);)e.pop();return e}function io(t,e,n=!1){return{poly:np([...t,...[...e].reverse()]),landing:n,left:t,right:e}}function ro(t,e,n,r,o){let i=[];for(let s=0;se+1e-6&&ot.reduce((e,n,r)=>r?e+Math.hypot(n[0]-t[r-1][0],n[1]-t[r-1][1]):e,0);function Qh(t,e,n,r,o){let i=m0(t),s=[];for(let l=0;l=8?3:2),[p,h]=t.shape==="l"?Jh(t,r)??vi(r-u,n-a,e-a):vi(r-u,n-a,e-a),f=ro([o,l],[o+a,l],[o,s+a],c,p),g=t.shape==="l"?[io(d,[c],!0)]:Qh(d,c,c,c,u),y=ro([o+a,s],c,[i,s],[i,s+a],h);return{treads:[...f,...g,...y],flight:a,column:0}}case"half":case"u":{let a=Math.min(t.run_width??Math.min(1.1,(e-.1)/2),(e-.02)/2),c=s+a,d=[[o,c],[o,s],[i,s],[i,c]],[u,p]=[[o+a,c],[i-a,c]],h=t.shape==="u"?1:Math.min(r,r>=12?6:r>=8?4:2),[f,g]=t.shape==="u"?Jh(t,r)??vi(r-h,n-a,n-a):vi(r-h,n-a,n-a),y=ro([o,l],[o+a,l],[o,c],u,f),b=t.shape==="u"?[io(d,[u,p],!0)]:Qh(d,u,[0,c],p,h),v=ro([i,c],p,[i,l],[i-a,l],g);return{treads:[...y,...b,...v],flight:a,column:0}}case"spiral":{let a=Math.min(e,n)/2,c=Math.min(.08,a*.12),d=Math.min(.75,Math.max(.3,.22/(a*.6))),u=(h,f)=>[Math.cos(f)*h,Math.sin(f)*h],p=[];for(let h=0;hu(a,f+(g-f)*b));p.push(io(y,[u(c,f),u(c,g)]))}return{treads:p,flight:a-c,column:c}}default:return{treads:ro([o,l],[i,l],[o,s],[i,s],r),flight:e,column:0}}}var _0=(t,e)=>t.steps??Math.min(tp,Math.max(ep,Math.round(Math.abs(e)/.18)));function hn(t,e,n,r){let o=_0(t,r),i=Math.abs(r)/o,s=g0(t,Math.max(.3,e),Math.max(.3,n),o),l=c=>[-c[0],c[1]];return{treads:s.treads.map((c,d)=>{let u=t.down?-i*(d+1):i*(d+1);return t.turn==="right"?{...c,top:u}:{poly:c.poly.map(l).reverse(),top:u,landing:c.landing,left:c.right.map(l),right:c.left.map(l)}}),rise:i,steps:o,column:s.column,flight:s.flight}}function ki(t){let e=t.poly.reduce((n,r)=>[n[0]+r[0],n[1]+r[1]],[0,0]);return[e[0]/t.poly.length,e[1]/t.poly.length]}var J=t=>Math.round(t*1e3)/1e3,b0=(t,e)=>((t+e)%360+360)%360;function rp(t,e){return{id:D("wall"),a:[J(t[0]),J(t[1])],b:[J(e[0]),J(e[1])],thickness:null}}function op(t,e){let n=Math.hypot(t.b[0]-t.a[0],t.b[1]-t.a[1])||1,r=Math.max(.1,e)/n;return[J(t.a[0]+(t.b[0]-t.a[0])*r),J(t.a[1]+(t.b[1]-t.a[1])*r)]}var ip=(t,e)=>({height:t>=e-.005?null:Math.max(.05,t)});function sp(t,e){return{id:D("hole"),type:"stairwell",x:J((t[0]+e[0])/2),z:J((t[1]+e[1])/2),w:J(e[0]-t[0]),d:J(e[1]-t[1]),h:.02,rotation:0,variant:null}}var ap=t=>({id:D("outdoor"),type:"lawn",points:t.map(([e,n])=>[J(e),J(n)])});function lp(t,e,n){t.points.splice(e+1,0,[J(n[0]),J(n[1])])}function cp(t,e){return t.points.length<=3||e<0||e>=t.points.length?!1:(t.points.splice(e,1),!0)}var dp=t=>({...t,id:D("outdoor"),points:t.points.map(([e,n])=>[J(e+.5),J(n+.5)])});function za(t,e,n,r){let[o,i,s]=at(t),l=e.floors.filter(d=>d.elevation>n.elevation).sort((d,u)=>d.elevation-u.elevation)[0],a=t==="stairs"?J(l?l.elevation-n.elevation:n.height+.25):s,c={id:D("furniture"),type:t,x:J(r[0]),z:J(r[1]),rotation:0,w:o,d:i,h:a,variant:null};return t==="stairs"&&(c.stair={...pt}),c}var up=t=>({...structuredClone(t),id:D("furniture"),x:J(t.x+.3),z:J(t.z+.3)}),hp=(t,e)=>b0(t,e);function pp(t){let[e,n,r]=at("parking");return{id:D("furniture"),type:"parking",x:t.x,z:t.z,rotation:t.rotation,w:Math.max(e,J(t.w+.5)),d:Math.max(n,J(t.d+.4)),h:r,variant:null,vehicle:t.type,...t.name?{name:t.name}:{}}}function fp(t,e){let[n,r,o]=at(e);return{id:D("furniture"),type:e,x:t.x,z:t.z,rotation:t.rotation??0,w:n,d:r,h:o,variant:null,entity:t.entity_id,name:t.name??null,animations_enabled:t.animations_enabled,effect_animations:structuredClone(t.effect_animations),...t.locked?{locked:!0}:{}}}var mp=(t,e)=>({entity_id:e,x:t.x,z:t.z,y:null,rotation:t.rotation,animations_enabled:t.animations_enabled,effect_animations:structuredClone(t.effect_animations),...t.name?{name:t.name}:{}});function gp(t,e){for(let n of t.floors)n.placements=n.placements.filter(r=>r.entity_id!==e),n.furniture=n.furniture.filter(r=>!(ce(r.type)&&r.entity===e))}function Pa(t,e,n,r){let o=new Set(r);for(let s of t.floors)s.placements=s.placements.filter(l=>!o.has(l.entity_id)),s.furniture=s.furniture.filter(l=>!(ce(l.type)&&l.entity&&o.has(l.entity)));let i=[...e.placements.map(s=>[s.x,s.z]),...e.furniture.filter(s=>ce(s.type)).map(s=>[s.x,s.z])];for(let s of xd(n,r,i)){if(!s.entity_id.startsWith("light.")){e.placements.push(s);continue}let[l,a,c]=et.lamp_ceiling;e.furniture.push({id:D("furniture"),type:"lamp_ceiling",x:s.x,z:s.z,rotation:0,w:l,d:a,h:c,variant:null,entity:s.entity_id,power:null})}}function _p(t){let[e,n]=_e(t.points);return[J(e),J(n)]}function bp(t,e,n,r){let o=Math.min(n,t)/2,i=r>0?Math.round(e/r)*r:e;return J(Math.min(t-o,Math.max(o,i)))}function yp(t,e){let n=vn[e],r=kn(t)===e?{}:{width:n.width};return{type:n.type,leaves:n.leaves,sill:n.sill,height:n.height,style:n.style??null,opens:n.opens??null,...r}}function wp(t,e,n){let r=de(t.points),{x0:o,z0:i,x1:s,z1:l}=r;return e==="x"?[o,s]=[n,n+(s-o)]:e==="z"?[i,l]=[n,n+(l-i)]:e==="w"?s=o+Math.max(.1,n):l=i+Math.max(.1,n),[[o,i],[s,i],[s,l],[o,l]].map(([a,c])=>[J(a),J(c)])}function vp(t){return t.furniture.map((e,n)=>({item:e,index:n,base:At(t,e)})).sort((e,n)=>e.base-n.base||e.index-n.index).map(e=>e.item)}function xi(t,e,n){if(!t.admin)return _;let r=n.edit?.key===e;return m`
`}var p0=t=>t.map((e,n)=>[e,t[(n+1)%t.length]]);function f0(t,e,n){let r=K(n,e),o=Q(r,r),i=o?Math.max(0,Math.min(1,Q(K(t,e),r)/o)):0;return fe(K(t,[e[0]+r[0]*i,e[1]+r[1]*i]))}function qh(t,e,n=.03){return t.every(r=>N(r,e)||p0(e).some(([o,i])=>f0(r,o,i)<=n))}var Ra=["straight","quarter","l","half","u","spiral"],Ea=["solid","stringer","mono","cantilever"],Aa=["none","left","right","both"],Fa=["headroom","full","none"],pt={shape:"straight",turn:"right",build:"solid",risers:!0,steps:null,run_width:null,down:!1,rail:"none",opening:"headroom",landing_after:null},Ta={straight:[1,3.2],quarter:[2.2,2.6],l:[2.2,2.8],half:[2,2.6],u:[2.2,2.6],spiral:[1.6,1.6]},ep=2,tp=40;var wi=(t,e)=>typeof e=="string"&&t.includes(e);function so(t){let e=t.stair??{},n=typeof e.steps=="number"&&Number.isFinite(e.steps)?Math.round(Math.min(tp,Math.max(ep,e.steps))):null,r=typeof e.run_width=="number"&&Number.isFinite(e.run_width)&&e.run_width>.2?e.run_width:null;return{shape:wi(Ra,e.shape)?e.shape:pt.shape,turn:e.turn==="left"?"left":"right",build:wi(Ea,e.build)?e.build:pt.build,risers:e.risers!==!1,steps:n,run_width:r,down:e.down===!0,rail:wi(Aa,e.rail)?e.rail:pt.rail,opening:wi(Fa,e.opening)?e.opening:pt.opening,landing_after:typeof e.landing_after=="number"&&Number.isFinite(e.landing_after)?Math.max(1,Math.round(e.landing_after)):null}}var oo=(t,e,n)=>[t[0]+(e[0]-t[0])*n,t[1]+(e[1]-t[1])*n],Yh=(t,e)=>Math.abs(t[0]-e[0])<1e-6&&Math.abs(t[1]-e[1])<1e-6;function np(t){let e=[];for(let n of t)(!e.length||!Yh(e[e.length-1],n))&&e.push(n);for(;e.length>1&&Yh(e[0],e[e.length-1]);)e.pop();return e}function io(t,e,n=!1){return{poly:np([...t,...[...e].reverse()]),landing:n,left:t,right:e}}function ro(t,e,n,r,o){let i=[];for(let s=0;se+1e-6&&ot.reduce((e,n,r)=>r?e+Math.hypot(n[0]-t[r-1][0],n[1]-t[r-1][1]):e,0);function Qh(t,e,n,r,o){let i=g0(t),s=[];for(let l=0;l=8?3:2),[p,h]=t.shape==="l"?Jh(t,r)??vi(r-u,n-a,e-a):vi(r-u,n-a,e-a),f=ro([o,l],[o+a,l],[o,s+a],c,p),g=t.shape==="l"?[io(d,[c],!0)]:Qh(d,c,c,c,u),y=ro([o+a,s],c,[i,s],[i,s+a],h);return{treads:[...f,...g,...y],flight:a,column:0}}case"half":case"u":{let a=Math.min(t.run_width??Math.min(1.1,(e-.1)/2),(e-.02)/2),c=s+a,d=[[o,c],[o,s],[i,s],[i,c]],[u,p]=[[o+a,c],[i-a,c]],h=t.shape==="u"?1:Math.min(r,r>=12?6:r>=8?4:2),[f,g]=t.shape==="u"?Jh(t,r)??vi(r-h,n-a,n-a):vi(r-h,n-a,n-a),y=ro([o,l],[o+a,l],[o,c],u,f),b=t.shape==="u"?[io(d,[u,p],!0)]:Qh(d,u,[0,c],p,h),v=ro([i,c],p,[i,l],[i-a,l],g);return{treads:[...y,...b,...v],flight:a,column:0}}case"spiral":{let a=Math.min(e,n)/2,c=Math.min(.08,a*.12),d=Math.min(.75,Math.max(.3,.22/(a*.6))),u=(h,f)=>[Math.cos(f)*h,Math.sin(f)*h],p=[];for(let h=0;hu(a,f+(g-f)*b));p.push(io(y,[u(c,f),u(c,g)]))}return{treads:p,flight:a-c,column:c}}default:return{treads:ro([o,l],[i,l],[o,s],[i,s],r),flight:e,column:0}}}var b0=(t,e)=>t.steps??Math.min(tp,Math.max(ep,Math.round(Math.abs(e)/.18)));function hn(t,e,n,r){let o=b0(t,r),i=Math.abs(r)/o,s=_0(t,Math.max(.3,e),Math.max(.3,n),o),l=c=>[-c[0],c[1]];return{treads:s.treads.map((c,d)=>{let u=t.down?-i*(d+1):i*(d+1);return t.turn==="right"?{...c,top:u}:{poly:c.poly.map(l).reverse(),top:u,landing:c.landing,left:c.right.map(l),right:c.left.map(l)}}),rise:i,steps:o,column:s.column,flight:s.flight}}function ki(t){let e=t.poly.reduce((n,r)=>[n[0]+r[0],n[1]+r[1]],[0,0]);return[e[0]/t.poly.length,e[1]/t.poly.length]}var J=t=>Math.round(t*1e3)/1e3,y0=(t,e)=>((t+e)%360+360)%360;function rp(t,e){return{id:D("wall"),a:[J(t[0]),J(t[1])],b:[J(e[0]),J(e[1])],thickness:null}}function op(t,e){let n=Math.hypot(t.b[0]-t.a[0],t.b[1]-t.a[1])||1,r=Math.max(.1,e)/n;return[J(t.a[0]+(t.b[0]-t.a[0])*r),J(t.a[1]+(t.b[1]-t.a[1])*r)]}var ip=(t,e)=>({height:t>=e-.005?null:Math.max(.05,t)});function sp(t,e){return{id:D("hole"),type:"stairwell",x:J((t[0]+e[0])/2),z:J((t[1]+e[1])/2),w:J(e[0]-t[0]),d:J(e[1]-t[1]),h:.02,rotation:0,variant:null}}var ap=t=>({id:D("outdoor"),type:"lawn",points:t.map(([e,n])=>[J(e),J(n)])});function lp(t,e,n){t.points.splice(e+1,0,[J(n[0]),J(n[1])])}function cp(t,e){return t.points.length<=3||e<0||e>=t.points.length?!1:(t.points.splice(e,1),!0)}var dp=t=>({...t,id:D("outdoor"),points:t.points.map(([e,n])=>[J(e+.5),J(n+.5)])});function za(t,e,n,r){let[o,i,s]=at(t),l=e.floors.filter(d=>d.elevation>n.elevation).sort((d,u)=>d.elevation-u.elevation)[0],a=t==="stairs"?J(l?l.elevation-n.elevation:n.height+.25):s,c={id:D("furniture"),type:t,x:J(r[0]),z:J(r[1]),rotation:0,w:o,d:i,h:a,variant:null};return t==="stairs"&&(c.stair={...pt}),c}var up=t=>({...structuredClone(t),id:D("furniture"),x:J(t.x+.3),z:J(t.z+.3)}),hp=(t,e)=>y0(t,e);function pp(t){let[e,n,r]=at("parking");return{id:D("furniture"),type:"parking",x:t.x,z:t.z,rotation:t.rotation,w:Math.max(e,J(t.w+.5)),d:Math.max(n,J(t.d+.4)),h:r,variant:null,vehicle:t.type,...t.name?{name:t.name}:{}}}function fp(t,e){let[n,r,o]=at(e);return{id:D("furniture"),type:e,x:t.x,z:t.z,rotation:t.rotation??0,w:n,d:r,h:o,variant:null,entity:t.entity_id,name:t.name??null,animations_enabled:t.animations_enabled,effect_animations:structuredClone(t.effect_animations),...t.locked?{locked:!0}:{}}}var mp=(t,e)=>({entity_id:e,x:t.x,z:t.z,y:null,rotation:t.rotation,animations_enabled:t.animations_enabled,effect_animations:structuredClone(t.effect_animations),...t.name?{name:t.name}:{}});function gp(t,e){for(let n of t.floors)n.placements=n.placements.filter(r=>r.entity_id!==e),n.furniture=n.furniture.filter(r=>!(ce(r.type)&&r.entity===e))}function Pa(t,e,n,r){let o=new Set(r);for(let s of t.floors)s.placements=s.placements.filter(l=>!o.has(l.entity_id)),s.furniture=s.furniture.filter(l=>!(ce(l.type)&&l.entity&&o.has(l.entity)));let i=[...e.placements.map(s=>[s.x,s.z]),...e.furniture.filter(s=>ce(s.type)).map(s=>[s.x,s.z])];for(let s of xd(n,r,i)){if(!s.entity_id.startsWith("light.")){e.placements.push(s);continue}let[l,a,c]=et.lamp_ceiling;e.furniture.push({id:D("furniture"),type:"lamp_ceiling",x:s.x,z:s.z,rotation:0,w:l,d:a,h:c,variant:null,entity:s.entity_id,power:null})}}function _p(t){let[e,n]=_e(t.points);return[J(e),J(n)]}function bp(t,e,n,r){let o=Math.min(n,t)/2,i=r>0?Math.round(e/r)*r:e;return J(Math.min(t-o,Math.max(o,i)))}function yp(t,e){let n=vn[e],r=kn(t)===e?{}:{width:n.width};return{type:n.type,leaves:n.leaves,sill:n.sill,height:n.height,style:n.style??null,opens:n.opens??null,...r}}function wp(t,e,n){let r=de(t.points),{x0:o,z0:i,x1:s,z1:l}=r;return e==="x"?[o,s]=[n,n+(s-o)]:e==="z"?[i,l]=[n,n+(l-i)]:e==="w"?s=o+Math.max(.1,n):l=i+Math.max(.1,n),[[o,i],[s,i],[s,l],[o,l]].map(([a,c])=>[J(a),J(c)])}function vp(t){return t.furniture.map((e,n)=>({item:e,index:n,base:At(t,e)})).sort((e,n)=>e.base-n.base||e.index-n.index).map(e=>e.item)}function xi(t,e,n){if(!t.admin)return _;let r=n.edit?.key===e;return m``}function $i(t,e,n){let r=n.edit;if(!t.admin||r?.key!==e)return _;let o=t.t;return m`${E(t,o("arc_bulge"),r.bulge,i=>n.setEdit({...r,bulge:i,error:null}),.05)} @@ -898,14 +898,14 @@ ${i}`}else o=ju(s)}}catch(s){let l=s.message,a={not_json:"import_error_not_json" ${e.type==="pergola"?H(t,r("outdoor_bracing"),!!e.bracing,a=>o({bracing:a||void 0})):_} ${H(t,r("outdoor_cut"),Bc(e),a=>o({cut:a===(e.type==="pool")?void 0:a}),{title:r("outdoor_cut_hint")})} - ${e.type==="fence"?y0(t,e,o):_} + ${e.type==="fence"?w0(t,e,o):_} ${t.admin?m`
${e.points.map((a,c)=>m``)}
${M(r("outdoor_corners_hint"))}`:_} ${e.slope?M(r("outdoor_slope_hint")):_} ${M(r("outdoor_hint"))} ${t.admin?m`
`:_} - `}function y0(t,e,n){let r=t.t,o=e.gates??[],i=h=>n({gates:h.length?h:void 0}),s=e.points.map((h,f)=>[String(f),`${f+1} \u2192 ${(f+1)%e.points.length+1}`]),l=h=>{let[f,g]=[e.points[h],e.points[(h+1)%e.points.length]];return f&&g?Math.hypot(g[0]-f[0],g[1]-f[1]):0},a=(h,f)=>i(o.map((g,y)=>y===h?{...g,...f}:g)),c=L(t.hass,h=>/^(cover|switch|input_boolean|lock)\./.test(h)),d=L(t.hass,h=>h.startsWith("binary_sensor.")),u=[["single",r("gate_single")],["double",r("gate_double")],["sliding",r("gate_sliding")]],p=()=>{let f=l(0);i([...o,{id:D("gate"),edge:0,offset:ie(f/2),width:Math.min(1.2,Math.max(.5,ie(f*.4))),kind:"single"}])};return m`

${r("fence_gates")}

+ `}function w0(t,e,n){let r=t.t,o=e.gates??[],i=h=>n({gates:h.length?h:void 0}),s=e.points.map((h,f)=>[String(f),`${f+1} \u2192 ${(f+1)%e.points.length+1}`]),l=h=>{let[f,g]=[e.points[h],e.points[(h+1)%e.points.length]];return f&&g?Math.hypot(g[0]-f[0],g[1]-f[1]):0},a=(h,f)=>i(o.map((g,y)=>y===h?{...g,...f}:g)),c=L(t.hass,h=>/^(cover|switch|input_boolean|lock)\./.test(h)),d=L(t.hass,h=>h.startsWith("binary_sensor.")),u=[["single",r("gate_single")],["double",r("gate_double")],["sliding",r("gate_sliding")]],p=()=>{let f=l(0);i([...o,{id:D("gate"),edge:0,offset:ie(f/2),width:Math.min(1.2,Math.max(.5,ie(f*.4))),kind:"single"}])};return m`

${r("fence_gates")}

${o.map((h,f)=>m`
${O(t,r("gate_edge"),String(h.edge),s,g=>a(f,{edge:Number(g)}))} ${O(t,r("gate_kind"),h.kind,u,g=>a(f,{kind:g,width:g==="single"&&h.width>1.6?1:h.width}))} @@ -916,13 +916,13 @@ ${i}`}else o=ju(s)}}catch(s){let l=s.message,a={not_json:"import_error_not_json" ${t.admin?m``:_}
`)} ${t.admin&&o.length<20?m``:_} - ${M(r("fence_gates_hint"))}`}var w0=[["up","\u2191"],["left","\u2190"],["right","\u2192"],["down","\u2193"]],v0={ArrowRight:"right",ArrowLeft:"left",ArrowUp:"up",ArrowDown:"down"};function kp(t,e,n){let r=t.t,{draft:o}=e,i=u=>j(t.hass,u,2),[s,l]=[o[0],o[o.length-1]],a=s&&o.length>1?Math.hypot(l[0]-s[0],l[1]-s[1]):0,c=u=>{let p=v0[u.key];p?(u.preventDefault(),n.step(p)):u.key==="Enter"&&n.close()},d=s?m`${M(r("measure_from",{x:i(s[0]),z:i(s[1])}))} + ${M(r("fence_gates_hint"))}`}var v0=[["up","\u2191"],["left","\u2190"],["right","\u2192"],["down","\u2193"]],k0={ArrowRight:"right",ArrowLeft:"left",ArrowUp:"up",ArrowDown:"down"};function kp(t,e,n){let r=t.t,{draft:o}=e,i=u=>j(t.hass,u,2),[s,l]=[o[0],o[o.length-1]],a=s&&o.length>1?Math.hypot(l[0]-s[0],l[1]-s[1]):0,c=u=>{let p=k0[u.key];p?(u.preventDefault(),n.step(p)):u.key==="Enter"&&n.close()},d=s?m`${M(r("measure_from",{x:i(s[0]),z:i(s[1])}))}
-
${w0.map(([u,p])=>m``)}
+
${v0.map(([u,p])=>m``)}
${o.length>1?m`
    ${o.slice(1).map((u,p)=>m`
  1. ${i(Math.hypot(u[0]-o[p][0],u[1]-o[p][1]))} m
  2. `)}
`:_}
@@ -951,7 +951,7 @@ ${i}`}else o=ju(s)}}catch(s){let l=s.message,a={not_json:"import_error_not_json" ${t.admin?m`
${xi(t,`wall:${e.id}`,n.arc)}
`:_}
${$i(t,`wall:${e.id}`,n.arc)}
${M(r("free_wall_hint"))} - `}var Ct=t=>Math.round(t*1e3)/1e3,k0=2.4;function xp(t,e,n){let r=Bs(t,e[0],e[1],n[0],n[1]),o=r===null,i=Math.min(...t.floors.map(a=>a.elevation)),s=Ct(r??i+k0),l=o?6:t.settings.roof.pitch||35;return{id:D("roof"),x0:Ct(e[0]),z0:Ct(e[1]),x1:Ct(n[0]),z1:Ct(n[1]),shape:o?"pent":"gable",axis:n[0]-e[0]>=n[1]-e[1]?"x":"z",eave_a:s,eave_b:s,pitch_a:l,pitch_b:l,base:s,overhang:o?.15:null,...o?{open:!0}:{}}}function $p(t){let e=n=>Ct(n+1);return{...structuredClone(t),id:D("roof"),x0:e(t.x0),x1:e(t.x1),z0:e(t.z0),z1:e(t.z1)}}var Sp=(t,e)=>t.findIndex(n=>n.id===e)+1;function Oa(t){return t.points&&t.points.length>=3?t.points.map(([e,n])=>[e,n]):t.rotation?$r(t):[[t.x0,t.z0],[t.x1,t.z0],[t.x1,t.z1],[t.x0,t.z1]]}function Mp(t,e,n){let r=Oa(t);r.splice(e+1,0,[Ct(n[0]),Ct(n[1])]),t.points=r,Object.assign(t,Pt(r))}function Rp(t,e){return!t.points||t.points.length<=3||e<0||e>=t.points.length?!1:(t.points.splice(e,1),Object.assign(t,Pt(t.points)),!0)}var x0={light:"M8.5 17.5h7M9.5 20.5h5M12 2.5a6.5 6.5 0 0 0-3.5 12v1.5h7V14.5A6.5 6.5 0 0 0 12 2.5z",switch:"M6 5h12a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V7a2 2 0 0 1 2-2zM12 7.5v9M9 12h6",fan:"M12 11.5c-1-3.5 0-7 2.5-7s2 4-2.5 7zm.5.5c3.5-1 7 0 7 2.5s-4 2-7-2.5zm-.5.5c1 3.5 0 7-2.5 7s-2-4 2.5-7zm-.5-.5c-3.5 1-7 0-7-2.5s4-2 7 2.5z",cover:"M3.5 3.5h17v3h-17zM6 6.5v12M18 6.5v12M8.5 9.5h7M8.5 12.5h7M8.5 15.5h7",climate:"M12 15V5.5a2.5 2.5 0 0 0-5 0V15a4.5 4.5 0 1 0 5 0zM9.5 9v7M15 5.5h5M15 9.5h4",media:"M3.5 5.5h17v11h-17zM8 20.5h8M12 16.5v4M10 8.5v5l4.5-2.5z",lock:"M5.5 10.5h13v9.5h-13zM8 10.5V7.5a4 4 0 0 1 8 0v3M12 14v3",sensor:"M12 3.5a8.5 8.5 0 1 0 0 17 8.5 8.5 0 0 0 0-17zM12 7.5v4.5l3.5 2",binary:"M5.5 20.5v-17h10v17M3.5 20.5h14M9 20.5v-13h4.5v13M12.5 14h.01",scene:"M5.5 18.5l8-8M14 3.5l1 2.5 2.5 1-2.5 1-1 2.5-1-2.5-2.5-1 2.5-1zM18.5 12l.7 1.8 1.8.7-1.8.7-.7 1.8-.7-1.8-1.8-.7 1.8-.7z",script:"M8.5 3.5h8.5a2 2 0 0 1 2 2v13a2 2 0 0 1-2 2H7.5a2 2 0 0 1-2-2v-2h9M8.5 3.5a2 2 0 0 0-2 2v10M9.5 8.5h6M9.5 11.5h4"},Nt=t=>x0[t];function Mi(t,e){let n=new Set;for(let r of t?.placements??[])N([r.x,r.z],e.points)&&n.add(r.entity_id);for(let r of t?.furniture??[])ce(r.type)&&r.entity&&N([r.x,r.z],e.points)&&n.add(r.entity);return n}function Ep(t,e){let n=new Map;for(let r of t.floors){let o=[...r.placements.map(i=>[i.entity_id,i.x,i.z]),...r.furniture.filter(i=>ce(i.type)&&i.entity).map(i=>[i.entity,i.x,i.z])];for(let[i,s,l]of o){let a=r.rooms.find(c=>N([s,l],c.points));a&&a.id!==e.id&&n.set(i,a.name)}}return n}var Ap=(t,e)=>(t??[]).includes(e)?(t??[]).filter(n=>n!==e):[...t??[],e];function Ri(t,...e){let n=t.trim().toLowerCase();return!n||e.some(r=>(r??"").toLowerCase().includes(n))}function Fp(t,e){return t.map(n=>({o:n,r:e(n.id)})).sort((n,r)=>n.r-r.r).map(({o:n})=>n)}function Tp(t,e){let n=e,r=0;return{taken:t.map(i=>{let s=i.ids.slice(0,Math.max(0,n));return n-=s.length,r+=i.ids.length-s.length,[...s]}),left:r}}var Ha=50;function La(t,e,n,r,o,i,s){let l=e.includes(n);return m``}function $0(t,e,n,r,o,i){let[s,l,a]=[e.hidden??[],e.no_state??[],e.panel??[]];return(c,d=!1,u=o)=>{let p=n.has(c),h=p?void 0:r.get(c),f=s.includes(c),g=Cn(t,c);return m`
+ `}var Ct=t=>Math.round(t*1e3)/1e3,x0=2.4;function xp(t,e,n){let r=Bs(t,e[0],e[1],n[0],n[1]),o=r===null,i=Math.min(...t.floors.map(a=>a.elevation)),s=Ct(r??i+x0),l=o?6:t.settings.roof.pitch||35;return{id:D("roof"),x0:Ct(e[0]),z0:Ct(e[1]),x1:Ct(n[0]),z1:Ct(n[1]),shape:o?"pent":"gable",axis:n[0]-e[0]>=n[1]-e[1]?"x":"z",eave_a:s,eave_b:s,pitch_a:l,pitch_b:l,base:s,overhang:o?.15:null,...o?{open:!0}:{}}}function $p(t){let e=n=>Ct(n+1);return{...structuredClone(t),id:D("roof"),x0:e(t.x0),x1:e(t.x1),z0:e(t.z0),z1:e(t.z1)}}var Sp=(t,e)=>t.findIndex(n=>n.id===e)+1;function Oa(t){return t.points&&t.points.length>=3?t.points.map(([e,n])=>[e,n]):t.rotation?$r(t):[[t.x0,t.z0],[t.x1,t.z0],[t.x1,t.z1],[t.x0,t.z1]]}function Mp(t,e,n){let r=Oa(t);r.splice(e+1,0,[Ct(n[0]),Ct(n[1])]),t.points=r,Object.assign(t,Pt(r))}function Rp(t,e){return!t.points||t.points.length<=3||e<0||e>=t.points.length?!1:(t.points.splice(e,1),Object.assign(t,Pt(t.points)),!0)}var $0={light:"M8.5 17.5h7M9.5 20.5h5M12 2.5a6.5 6.5 0 0 0-3.5 12v1.5h7V14.5A6.5 6.5 0 0 0 12 2.5z",switch:"M6 5h12a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V7a2 2 0 0 1 2-2zM12 7.5v9M9 12h6",fan:"M12 11.5c-1-3.5 0-7 2.5-7s2 4-2.5 7zm.5.5c3.5-1 7 0 7 2.5s-4 2-7-2.5zm-.5.5c1 3.5 0 7-2.5 7s-2-4 2.5-7zm-.5-.5c-3.5 1-7 0-7-2.5s4-2 7 2.5z",cover:"M3.5 3.5h17v3h-17zM6 6.5v12M18 6.5v12M8.5 9.5h7M8.5 12.5h7M8.5 15.5h7",climate:"M12 15V5.5a2.5 2.5 0 0 0-5 0V15a4.5 4.5 0 1 0 5 0zM9.5 9v7M15 5.5h5M15 9.5h4",media:"M3.5 5.5h17v11h-17zM8 20.5h8M12 16.5v4M10 8.5v5l4.5-2.5z",lock:"M5.5 10.5h13v9.5h-13zM8 10.5V7.5a4 4 0 0 1 8 0v3M12 14v3",sensor:"M12 3.5a8.5 8.5 0 1 0 0 17 8.5 8.5 0 0 0 0-17zM12 7.5v4.5l3.5 2",binary:"M5.5 20.5v-17h10v17M3.5 20.5h14M9 20.5v-13h4.5v13M12.5 14h.01",scene:"M5.5 18.5l8-8M14 3.5l1 2.5 2.5 1-2.5 1-1 2.5-1-2.5-2.5-1 2.5-1zM18.5 12l.7 1.8 1.8.7-1.8.7-.7 1.8-.7-1.8-1.8-.7 1.8-.7z",script:"M8.5 3.5h8.5a2 2 0 0 1 2 2v13a2 2 0 0 1-2 2H7.5a2 2 0 0 1-2-2v-2h9M8.5 3.5a2 2 0 0 0-2 2v10M9.5 8.5h6M9.5 11.5h4"},Nt=t=>$0[t];function Mi(t,e){let n=new Set;for(let r of t?.placements??[])N([r.x,r.z],e.points)&&n.add(r.entity_id);for(let r of t?.furniture??[])ce(r.type)&&r.entity&&N([r.x,r.z],e.points)&&n.add(r.entity);return n}function Ep(t,e){let n=new Map;for(let r of t.floors){let o=[...r.placements.map(i=>[i.entity_id,i.x,i.z]),...r.furniture.filter(i=>ce(i.type)&&i.entity).map(i=>[i.entity,i.x,i.z])];for(let[i,s,l]of o){let a=r.rooms.find(c=>N([s,l],c.points));a&&a.id!==e.id&&n.set(i,a.name)}}return n}var Ap=(t,e)=>(t??[]).includes(e)?(t??[]).filter(n=>n!==e):[...t??[],e];function Ri(t,...e){let n=t.trim().toLowerCase();return!n||e.some(r=>(r??"").toLowerCase().includes(n))}function Fp(t,e){return t.map(n=>({o:n,r:e(n.id)})).sort((n,r)=>n.r-r.r).map(({o:n})=>n)}function Tp(t,e){let n=e,r=0;return{taken:t.map(i=>{let s=i.ids.slice(0,Math.max(0,n));return n-=s.length,r+=i.ids.length-s.length,[...s]}),left:r}}var Ha=50;function La(t,e,n,r,o,i,s){let l=e.includes(n);return m``}function S0(t,e,n,r,o,i){let[s,l,a]=[e.hidden??[],e.no_state??[],e.panel??[]];return(c,d=!1,u=o)=>{let p=n.has(c),h=p?void 0:r.get(c),f=s.includes(c),g=Cn(t,c);return m`
`:m``:_} -
`}}function S0(t,e,n,r,o){let{hass:i}=t;if(!i)return m``;let s=d=>d>0?M(t.t("devices_narrow",{n:d})):_,l=M(t.t("devices_none")),a=e.deviceQuery;if(o==="other"){let d=ud(i,n.area_id).map(f=>({...f,ids:f.ids.filter(g=>Ri(a,`${W(i,g,f.name)} ${g} ${f.name}`))})),{taken:u,left:p}=Tp(d,Ha),h=d.map((f,g)=>u[g].length>0?m`
${f.name}
${u[g].map(y=>r(y,!1,f.name))}`:_);return u.some(f=>f.length>0)?m`
${h}
${s(p)}`:l}let c=hd(i).filter(d=>Ri(a,`${W(i,d)} ${d} `));return c.length>0?m`
${c.slice(0,Ha).map(d=>r(d))}
${s(c.length-Math.min(c.length,Ha))}`:l}function M0(t,e,n,r,o,i,s){let{hass:l}=t,a=l?be(l,n).filter(b=>Mt(Ne(l,b))):[];if(!n.area_id)return M(t.t("devices_none_area"));if(a.length===0)return M(t.t("devices_none"));let c=l?Sn(l,a):[],d=c.map(b=>b.primary).filter(b=>!o.has(b)),u=e.deviceQuery,p=(t.floor?.placements??[]).filter(b=>X(b.entity_id)==="light"&&(b.mount??"ceiling")==="ceiling"&&N([b.x,b.z],n.points)).length,h=m`e.deviceQuery=b.target.value} />`,f=b=>Ri(u,W(l,b,i),b),g=b=>{let v=b.others.filter(f),w=e.isUnfolded(b.primary)||!!u.trim()&&v.length>0;return!f(b.primary)&&v.length===0?_:m`${r(b.primary)} +
`}}function M0(t,e,n,r,o){let{hass:i}=t;if(!i)return m``;let s=d=>d>0?M(t.t("devices_narrow",{n:d})):_,l=M(t.t("devices_none")),a=e.deviceQuery;if(o==="other"){let d=ud(i,n.area_id).map(f=>({...f,ids:f.ids.filter(g=>Ri(a,`${W(i,g,f.name)} ${g} ${f.name}`))})),{taken:u,left:p}=Tp(d,Ha),h=d.map((f,g)=>u[g].length>0?m`
${f.name}
${u[g].map(y=>r(y,!1,f.name))}`:_);return u.some(f=>f.length>0)?m`
${h}
${s(p)}`:l}let c=hd(i).filter(d=>Ri(a,`${W(i,d)} ${d} `));return c.length>0?m`
${c.slice(0,Ha).map(d=>r(d))}
${s(c.length-Math.min(c.length,Ha))}`:l}function R0(t,e,n,r,o,i,s){let{hass:l}=t,a=l?be(l,n).filter(b=>Mt(Ne(l,b))):[];if(!n.area_id)return M(t.t("devices_none_area"));if(a.length===0)return M(t.t("devices_none"));let c=l?Sn(l,a):[],d=c.map(b=>b.primary).filter(b=>!o.has(b)),u=e.deviceQuery,p=(t.floor?.placements??[]).filter(b=>X(b.entity_id)==="light"&&(b.mount??"ceiling")==="ceiling"&&N([b.x,b.z],n.points)).length,h=m`e.deviceQuery=b.target.value} />`,f=b=>Ri(u,W(l,b,i),b),g=b=>{let v=b.others.filter(f),w=e.isUnfolded(b.primary)||!!u.trim()&&v.length>0;return!f(b.primary)&&v.length===0?_:m`${r(b.primary)} ${b.others.length>0?m``:_} ${w?(u.trim()?v:b.others).map(x=>r(x,!0)):_}`},y=()=>s.confirm(t.t("devices_place_all_confirm",{n:d.length}))&&s.place(d);return m`${t.admin&&p>=2?m``:_} ${a.length>8?h:_}
${c.map(g)}
${t.admin&&d.length>1?m``:_} - ${M(t.t("devices_hint"))}`}function Ca(t,e,n,r){let{hass:o}=t,i=n.area_id?o?.areas?.[n.area_id]?.name:void 0,s=Mi(t.floor,n),l=$0(t,n,s,Ep(t.doc,n),i,r),a=t.admin?e.deviceSource:"area",c=o?Sn(o,be(o,n).filter(p=>Mt(Ne(o,p)))).length:0,d=[["area",`${t.t("devices_src_area")}${c>0?` (${c})`:""}`],["other",t.t("devices_src_other")],["none",t.t("devices_src_none")]],u=m`e.deviceQuery=p.target.value} />`;return m`
+ ${M(t.t("devices_hint"))}`}function Ca(t,e,n,r){let{hass:o}=t,i=n.area_id?o?.areas?.[n.area_id]?.name:void 0,s=Mi(t.floor,n),l=S0(t,n,s,Ep(t.doc,n),i,r),a=t.admin?e.deviceSource:"area",c=o?Sn(o,be(o,n).filter(p=>Mt(Ne(o,p)))).length:0,d=[["area",`${t.t("devices_src_area")}${c>0?` (${c})`:""}`],["other",t.t("devices_src_other")],["none",t.t("devices_src_none")]],u=m`e.deviceQuery=p.target.value} />`;return m`

${t.t("devices")}

${M(t.t("devices_panel_hint"))} ${t.admin?m`
${d.map(([p,h])=>m``)}
`:_} - ${a!=="area"?m`${u}${S0(t,e,n,l,a)}`:M0(t,e,n,l,s,i,r)} -
`}function zp(t,e,n){let{hass:r}=t;if(!r)return _;let o=!!e.climate&&Object.values(e.climate).some(l=>l!=null),i=(l,a)=>{let c={...e.climate??{},[l]:a};n({climate:Object.values(c).every(d=>d==null)?null:c})},s=(l,a)=>{let c=pd(r,t.floor??null,{...e,climate:null},l),d=L(r,y=>he(y)&&r.states[y]?.attributes.device_class===Ms[l]),u=Fp(d,y=>(Tt(r,y)===e.area_id?0:1)+(Rs(r,y)?0:2)),p=[e.climate?.[l]??null].flat(),h=y=>{let b=y.filter(v=>!!v&&v!=="none");i(l,y[0]==="none"?"none":b.length>1?b:b[0]??null)},g=p[0]&&p[0]!=="none"?[...p,null]:p;return g.map((y,b)=>P(t,b?t.t("climate_more"):a,y,b?void 0:c[0]??null,u,v=>h(g.map((w,x)=>x===b?v:w))))};return m`
+ ${a!=="area"?m`${u}${M0(t,e,n,l,a)}`:R0(t,e,n,l,s,i,r)} +
`}function zp(t,e,n){let{hass:r}=t;if(!r)return _;let o=!!e.climate&&Object.values(e.climate).some(l=>l!=null),i=(l,a)=>{let c={...e.climate??{},[l]:a};n({climate:Object.values(c).every(d=>d==null)?null:c})},s=(l,a)=>{let c=pd(r,t.floor??null,{...e,climate:null},l),d=L(r,y=>Ms(r,y,l)),u=Fp(d,y=>(Tt(r,y)===e.area_id?0:1)+(Rs(r,y)?0:2)),p=[e.climate?.[l]??null].flat(),h=y=>{let b=y.filter(v=>!!v&&v!=="none");i(l,y[0]==="none"?"none":b.length>1?b:b[0]??null)},g=p[0]&&p[0]!=="none"?[...p,null]:p;return g.map((y,b)=>P(t,b?t.t("climate_more"):a,y,b?void 0:c[0]??null,u,v=>h(g.map((w,x)=>x===b?v:w))))};return m`
${t.t("climate")}
${s("temperature",t.t("climate_temperature"))} ${s("humidity",t.t("climate_humidity"))} ${s("co2",t.t("climate_co2"))}
${M(t.t("climate_hint"))} -
`}var Na="metric",Ip=t=>{Na=t==="imperial"?"imperial":"metric"};var Pp=.3048;function pe(t,e,n=2,r=Na){if(r==="metric")return`${j(t,e,n)} m`;let o=e<0?"\u2212":"",i=Math.round(Math.abs(e)/.0254*2),s=Math.floor(i/24),l=i-s*24,a=`${Math.floor(l/2)}${l%2?"\xBD":""}`;return s?`${o}${s}\u2032 ${a}\u2033`:`${o}${a}\u2033`}function Ae(t,e,n=Na){return n==="metric"?`${j(t,e,1)} m\xB2`:`${j(t,e/(Pp*Pp),0)} ft\xB2`}var R0=.15,E0=(t,e)=>Math.abs((t-e+540)%360-180);function A0(t,e,n,r){return t.rooms.some(o=>o.id!==e.id&&o.points.some((i,s)=>{let l=o.points[(s+1)%o.points.length];return Math.abs(Q(K(i,n),r))<.02&&Math.abs(Q(K(l,n),r))<.02}))}function Wa(t,e,n,r){let o=e.points,[i,s]=[o[n],o[(n+1)%o.length]],l=me(K(s,i)),a=ge(o)>=0?1:-1,c=[(s[0]-i[0])/l,(s[1]-i[1])/l],d=[-c[1]*a||0,c[0]*a||0],u=c[0]*d[1]-c[1]*d[0]>0,p=e.wall_heights?.[n],h=e.ceiling??t.height,f=typeof p=="number"?p:Array.isArray(p)?Math.max(...p.map(b=>b??h)):h,g=e.wall_slopes?.[n],y=typeof g=="number"&&typeof p=="number"?g:f;return{origin:u?i:s,along:u?c:[-c[0],-c[1]],normal:d,length:l,face:A0(t,e,i,d)?r/2:0,heightLeft:u?f:y,heightRight:u?y:f}}function Ba(t,e){let n=K(e,t.origin);return{u:Q(n,t.along),depth:Q(n,t.normal)-t.face}}function F0(t,e){let n=t.rooms.find(s=>s.id===e.room_id);if(!n||e.wall)return null;let[r,o]=[n.points[e.edge],n.points[(e.edge+1)%n.points.length]];if(!r||!o)return null;let i=me(K(o,r))||1;return[r[0]+(o[0]-r[0])*e.offset/i,r[1]+(o[1]-r[1])*e.offset/i]}var Dp=t=>G(t.type)?.mount==="wall"||t.type==="lamp_wall"||t.mount_y!=null;function Op(t,e,n){let r=[];for(let i of t.openings){let s=F0(t,i);if(!s)continue;let{u:l,depth:a}=Ba(n,s);Math.abs(a+n.face)>.3||l<-.01||l>n.length+.01||r.push({id:i.id,kind:"opening",type:i.type,x0:l-i.width/2,x1:l+i.width/2,y0:i.sill,y1:i.sill+i.height,lifts:i.type==="window"})}let o=Math.atan2(-n.normal[0],n.normal[1])*180/Math.PI;for(let i of t.furniture){if(!N([i.x,i.z],e.points)||E0(i.rotation,o)>20)continue;let{u:s,depth:l}=Ba(n,[i.x,i.z]);if(l-i.d/2>R0||s<0||s>n.length)continue;let a=At(t,i);r.push({id:i.id,kind:"furniture",type:i.type,x0:s-i.w/2,x1:s+i.w/2,y0:a,y1:a+i.h,lifts:Dp(i)})}return r.sort((i,s)=>+(i.kind==="furniture")-+(s.kind==="furniture")||i.x0-s.x0)}var ao=t=>Math.round(t*1e3)/1e3;function Hp(t,e,n,r){let o=Ba(t,[e.x,e.z]).depth,i=Math.min(t.length-e.w/2,Math.max(e.w/2,n+e.w/2)),s=[t.origin[0]+t.along[0]*i+t.normal[0]*(o+t.face),t.origin[1]+t.along[1]*i+t.normal[1]*(o+t.face)];return{x:ao(s[0]),z:ao(s[1]),...r!==null&&Dp(e)?{mount_y:ao(Math.max(0,r))}:{}}}function Lp(t,e,n,r,o){let[i]=[e.points[n.edge]],s=Math.min(t.length-n.width/2,Math.max(n.width/2,r+n.width/2)),l=me(K(i,t.origin))<1e-6?s:t.length-s;return{offset:ao(l),...o!==null&&n.type==="window"?{sill:ao(Math.max(0,o))}:{}}}var Cp=.01,Np=t=>Math.round(t/Cp)*Cp,Va=class extends ne{static properties={host:{attribute:!1},doc:{attribute:!1},roomId:{},edge:{type:Number},_sel:{state:!0},_drag:{state:!0}};constructor(){super(),this._sel=null,this._drag=null}get room(){return this.host.floor?.rooms.find(e=>e.id===this.roomId)}frame(){let e=this.room;return e&&this.host.floor?Wa(this.host.floor,e,this.edge,this.host.doc.settings.wall_interior):null}boxes(){let e=this.room,n=this.frame();return e&&n&&this.host.floor?Op(this.host.floor,e,n):[]}place(e,n,r){let o=this.room,i=this.frame();!o||!i||this.host.change((s,l)=>{if(e.kind==="furniture"){let a=l.furniture.find(c=>c.id===e.id);a&&Object.assign(a,Hp(i,a,n,e.lifts?r:null))}else{let a=l.openings.find(d=>d.id===e.id),c=l.rooms.find(d=>d.id===a?.room_id);a&&c&&Object.assign(a,Lp(c.id===o.id?i:Wa(l,c,a.edge,this.host.doc.settings.wall_interior),c,a,n,e.lifts?r:null))}})}toWall(e){let r=this.renderRoot.querySelector("svg").getScreenCTM()?.inverse();if(!r)return[0,0];let o=new DOMPoint(e.clientX,e.clientY).matrixTransform(r);return[o.x,-o.y]}down(e,n){if(this._sel=n.id,!this.host.admin)return;e.currentTarget.setPointerCapture(e.pointerId);let[r,o]=this.toWall(e);this._drag={id:n.id,x0:n.x0,y0:n.y0,startU:r,startY:o,fromX:n.x0,fromY:n.y0}}move(e,n){let r=this._drag;if(!r||r.id!==n.id)return;let[o,i]=this.toWall(e),s=this.frame(),l=n.x1-n.x0,a=Math.min((s?.length??0)-l,Math.max(0,Np(r.fromX+o-r.startU))),c=n.lifts?Math.max(0,Np(r.fromY+i-r.startY)):r.fromY;this._drag={...r,x0:a,y0:c}}up(e){let n=this._drag;this._drag=null,!(!n||n.id!==e.id||Math.abs(n.x0-n.fromX)<1e-6&&Math.abs(n.y0-n.fromY)<1e-6)&&this.place(e,n.x0,n.y0)}nameOf(e){if(e.kind==="furniture")return this.host.floor?.furniture.find(o=>o.id===e.id)?.name||qe(this.host.hass,e.type);let n=this.host.floor?.openings.find(r=>r.id===e.id);return n?this.host.t(`preset_${kn(n)}`):e.type}updated(e){(e.has("edge")||e.has("roomId"))&&(this._sel=null)}render(){let e=this.host.t,n=this.room,r=this.frame();if(!n||!r)return _;let o=n.points.length,i=h=>pe(this.host.hass,h),s=this.boxes().map(h=>this._drag?.id===h.id?{...h,x1:this._drag.x0+(h.x1-h.x0),y1:this._drag.y0+(h.y1-h.y0),x0:this._drag.x0,y0:this._drag.y0}:h),l=Math.max(r.heightLeft,r.heightRight,...s.map(h=>h.y1)),a=.35,c=`${-a} ${-(l+a)} ${r.length+2*a} ${l+2*a+.25}`,d=s.find(h=>h.id===this._sel)??null,u=h=>{let f=Math.min(.14,Math.max(.07,(h.x1-h.x0)/7));return R`${this.nameOf(h)}`},p=d?R` + `}var Na="metric",Ip=t=>{Na=t==="imperial"?"imperial":"metric"};var Pp=.3048;function he(t,e,n=2,r=Na){if(r==="metric")return`${j(t,e,n)} m`;let o=e<0?"\u2212":"",i=Math.round(Math.abs(e)/.0254*2),s=Math.floor(i/24),l=i-s*24,a=`${Math.floor(l/2)}${l%2?"\xBD":""}`;return s?`${o}${s}\u2032 ${a}\u2033`:`${o}${a}\u2033`}function Ae(t,e,n=Na){return n==="metric"?`${j(t,e,1)} m\xB2`:`${j(t,e/(Pp*Pp),0)} ft\xB2`}var E0=.15,A0=(t,e)=>Math.abs((t-e+540)%360-180);function F0(t,e,n,r){return t.rooms.some(o=>o.id!==e.id&&o.points.some((i,s)=>{let l=o.points[(s+1)%o.points.length];return Math.abs(Q(K(i,n),r))<.02&&Math.abs(Q(K(l,n),r))<.02}))}function Wa(t,e,n,r){let o=e.points,[i,s]=[o[n],o[(n+1)%o.length]],l=fe(K(s,i)),a=ge(o)>=0?1:-1,c=[(s[0]-i[0])/l,(s[1]-i[1])/l],d=[-c[1]*a||0,c[0]*a||0],u=c[0]*d[1]-c[1]*d[0]>0,p=e.wall_heights?.[n],h=e.ceiling??t.height,f=typeof p=="number"?p:Array.isArray(p)?Math.max(...p.map(b=>b??h)):h,g=e.wall_slopes?.[n],y=typeof g=="number"&&typeof p=="number"?g:f;return{origin:u?i:s,along:u?c:[-c[0],-c[1]],normal:d,length:l,face:F0(t,e,i,d)?r/2:0,heightLeft:u?f:y,heightRight:u?y:f}}function Ba(t,e){let n=K(e,t.origin);return{u:Q(n,t.along),depth:Q(n,t.normal)-t.face}}function T0(t,e){let n=t.rooms.find(s=>s.id===e.room_id);if(!n||e.wall)return null;let[r,o]=[n.points[e.edge],n.points[(e.edge+1)%n.points.length]];if(!r||!o)return null;let i=fe(K(o,r))||1;return[r[0]+(o[0]-r[0])*e.offset/i,r[1]+(o[1]-r[1])*e.offset/i]}var Dp=t=>G(t.type)?.mount==="wall"||t.type==="lamp_wall"||t.mount_y!=null;function Op(t,e,n){let r=[];for(let i of t.openings){let s=T0(t,i);if(!s)continue;let{u:l,depth:a}=Ba(n,s);Math.abs(a+n.face)>.3||l<-.01||l>n.length+.01||r.push({id:i.id,kind:"opening",type:i.type,x0:l-i.width/2,x1:l+i.width/2,y0:i.sill,y1:i.sill+i.height,lifts:i.type==="window"})}let o=Math.atan2(-n.normal[0],n.normal[1])*180/Math.PI;for(let i of t.furniture){if(!N([i.x,i.z],e.points)||A0(i.rotation,o)>20)continue;let{u:s,depth:l}=Ba(n,[i.x,i.z]);if(l-i.d/2>E0||s<0||s>n.length)continue;let a=At(t,i);r.push({id:i.id,kind:"furniture",type:i.type,x0:s-i.w/2,x1:s+i.w/2,y0:a,y1:a+i.h,lifts:Dp(i)})}return r.sort((i,s)=>+(i.kind==="furniture")-+(s.kind==="furniture")||i.x0-s.x0)}var ao=t=>Math.round(t*1e3)/1e3;function Hp(t,e,n,r){let o=Ba(t,[e.x,e.z]).depth,i=Math.min(t.length-e.w/2,Math.max(e.w/2,n+e.w/2)),s=[t.origin[0]+t.along[0]*i+t.normal[0]*(o+t.face),t.origin[1]+t.along[1]*i+t.normal[1]*(o+t.face)];return{x:ao(s[0]),z:ao(s[1]),...r!==null&&Dp(e)?{mount_y:ao(Math.max(0,r))}:{}}}function Lp(t,e,n,r,o){let[i]=[e.points[n.edge]],s=Math.min(t.length-n.width/2,Math.max(n.width/2,r+n.width/2)),l=fe(K(i,t.origin))<1e-6?s:t.length-s;return{offset:ao(l),...o!==null&&n.type==="window"?{sill:ao(Math.max(0,o))}:{}}}var Cp=.01,Np=t=>Math.round(t/Cp)*Cp,Va=class extends ne{static properties={host:{attribute:!1},doc:{attribute:!1},roomId:{},edge:{type:Number},_sel:{state:!0},_drag:{state:!0}};constructor(){super(),this._sel=null,this._drag=null}get room(){return this.host.floor?.rooms.find(e=>e.id===this.roomId)}frame(){let e=this.room;return e&&this.host.floor?Wa(this.host.floor,e,this.edge,this.host.doc.settings.wall_interior):null}boxes(){let e=this.room,n=this.frame();return e&&n&&this.host.floor?Op(this.host.floor,e,n):[]}place(e,n,r){let o=this.room,i=this.frame();!o||!i||this.host.change((s,l)=>{if(e.kind==="furniture"){let a=l.furniture.find(c=>c.id===e.id);a&&Object.assign(a,Hp(i,a,n,e.lifts?r:null))}else{let a=l.openings.find(d=>d.id===e.id),c=l.rooms.find(d=>d.id===a?.room_id);a&&c&&Object.assign(a,Lp(c.id===o.id?i:Wa(l,c,a.edge,this.host.doc.settings.wall_interior),c,a,n,e.lifts?r:null))}})}toWall(e){let r=this.renderRoot.querySelector("svg").getScreenCTM()?.inverse();if(!r)return[0,0];let o=new DOMPoint(e.clientX,e.clientY).matrixTransform(r);return[o.x,-o.y]}down(e,n){if(this._sel=n.id,!this.host.admin)return;e.currentTarget.setPointerCapture(e.pointerId);let[r,o]=this.toWall(e);this._drag={id:n.id,x0:n.x0,y0:n.y0,startU:r,startY:o,fromX:n.x0,fromY:n.y0}}move(e,n){let r=this._drag;if(!r||r.id!==n.id)return;let[o,i]=this.toWall(e),s=this.frame(),l=n.x1-n.x0,a=Math.min((s?.length??0)-l,Math.max(0,Np(r.fromX+o-r.startU))),c=n.lifts?Math.max(0,Np(r.fromY+i-r.startY)):r.fromY;this._drag={...r,x0:a,y0:c}}up(e){let n=this._drag;this._drag=null,!(!n||n.id!==e.id||Math.abs(n.x0-n.fromX)<1e-6&&Math.abs(n.y0-n.fromY)<1e-6)&&this.place(e,n.x0,n.y0)}nameOf(e){if(e.kind==="furniture")return this.host.floor?.furniture.find(o=>o.id===e.id)?.name||qe(this.host.hass,e.type);let n=this.host.floor?.openings.find(r=>r.id===e.id);return n?this.host.t(`preset_${kn(n)}`):e.type}updated(e){(e.has("edge")||e.has("roomId"))&&(this._sel=null)}render(){let e=this.host.t,n=this.room,r=this.frame();if(!n||!r)return _;let o=n.points.length,i=h=>he(this.host.hass,h),s=this.boxes().map(h=>this._drag?.id===h.id?{...h,x1:this._drag.x0+(h.x1-h.x0),y1:this._drag.y0+(h.y1-h.y0),x0:this._drag.x0,y0:this._drag.y0}:h),l=Math.max(r.heightLeft,r.heightRight,...s.map(h=>h.y1)),a=.35,c=`${-a} ${-(l+a)} ${r.length+2*a} ${l+2*a+.25}`,d=s.find(h=>h.id===this._sel)??null,u=h=>{let f=Math.min(.14,Math.max(.07,(h.x1-h.x0)/7));return R`${this.nameOf(h)}`},p=d?R` ${i(d.x0)} @@ -1124,7 +1124,7 @@ ${i}`}else o=ju(s)}}catch(s){let l=s.message,a={not_json:"import_error_not_json" color: inherit; font: inherit; } - `};customElements.get("nf-wall-view")||customElements.define("nf-wall-view",Va);function T0(t,e){let n=new Set([...Object.keys(t),...Object.keys(e)]);if(n.size===0)return 1/0;let r=0;for(let o of n)r+=Math.min(Math.abs((t[o]??-100)-(e[o]??-100)),40)**2;return Math.sqrt(r/n.size)}function Bp(t,e){if(Object.keys(e).length===0)return{room:null,distance:1/0,margin:0};let n=new Map;for(let s of t){let l=T0(s.rssi,e);l<(n.get(s.room)??1/0)&&n.set(s.room,l)}let r=[...n].sort((s,l)=>s[1]-l[1]);if(r.length===0)return{room:null,distance:1/0,margin:0};let[o,i]=r[0];return i>18?{room:null,distance:i,margin:0}:{room:o,distance:i,margin:r.length>1?r[1][1]-i:18}}var z0=t=>{let e=[...t].sort((r,o)=>r-o),n=e.length>>1;return e.length%2?e[n]:(e[n-1]+e[n])/2};function P0(t){let e={},n=new Set(t.flatMap(r=>Object.keys(r)));for(let r of n){let o=t.filter(i=>r in i).map(i=>i[r]);o.length*2>t.length&&(e[r]=Math.round(z0(o)*10)/10)}return e}function Wp(t,e,n=3){let r=e.filter(s=>Object.keys(s).length>0);if(r.length===0)return[];let o=Math.max(1,Math.min(n,Math.floor(r.length/3))),i=[];for(let s=0;s0&&i.push({room:t,rssi:a})}return i}var Vp=(t,e,n)=>[...t.filter(r=>r.room!==e),...n],Kp=t=>Math.max(0,Math.min(1,(t+95)/50));var I0=1500,Ga=class extends ne{static properties={host:{attribute:!1},doc:{attribute:!1},_found:{state:!0},_pick:{state:!0},_name:{state:!0},_tag:{state:!0},_room:{state:!0},_scan:{state:!0},_samples:{state:!0},_error:{state:!0}};timer=0;recordStarted=0;constructor(){super(),this._found=null,this._pick="",this._name="",this._tag=null,this._room="",this._scan=null,this._samples=null,this._error=""}createRenderRoot(){return this}get tags(){return this.host.doc.settings.ble?.tags??[]}get rooms(){let e=this.host.doc.floors;return e.flatMap(n=>n.rooms.map(r=>({id:r.id,label:e.length>1?`${n.name} \xB7 ${r.name}`:r.name})))}connectedCallback(){super.connectedCallback(),this.loadDevices()}disconnectedCallback(){super.disconnectedCallback(),window.clearInterval(this.timer)}updated(e){e.has("_tag")&&this.restartPolling()}async loadDevices(){try{this._found=await this.host.hass.callWS({type:"nextfloor/ble/devices"})}catch(e){this._error=String(e?.message??e)}}restartPolling(){if(window.clearInterval(this.timer),this._scan=null,!this._tag)return;let e=()=>{this.pollOnce()};e(),this.timer=window.setInterval(e,I0)}async pollOnce(){let e=this.tags.find(n=>n.id===this._tag);if(!(!e||!this.host.hass))try{let n=await this.host.hass.callWS({type:"nextfloor/ble/scan",...e.entity?{entity:e.entity}:{address:e.address}});this._scan=n,this._error="",this._samples&&(this._samples=[...this._samples,Object.fromEntries(Object.entries(n.readings).map(([r,o])=>[r,o.rssi]))],Date.now()-this.recordStarted>=30*1e3&&this.finishRecording(e,n))}catch(n){this._error=String(n?.message??n)}}reading(){return Object.fromEntries(Object.entries(this._scan?.readings??{}).map(([e,n])=>[e,n.rssi]))}startRecording(){this._room&&(this.recordStarted=Date.now(),this._samples=[])}finishRecording(e,n){let r=this._samples??[];this._samples=null;let o=Wp(this._room,r);if(o.length===0)return;let i=Object.fromEntries(Object.entries(n.readings).map(([s,l])=>[s,l.name]));this.update2(e.id,s=>{s.prints=Vp(s.prints,this._room,o),s.scanners={...s.scanners??{},...i}})}update2(e,n){this.host.change(r=>{let o=r.settings.ble?.tags.find(i=>i.id===e);o&&n(o)})}addTag(){let e=this._pick;if(!e)return;let n=e.startsWith("device_tracker."),r=this._found?.devices.find(s=>s.address===e),o=this._name.trim()||r?.name||this.host.hass?.states[e]?.attributes.friendly_name||e,i={id:D("ble"),name:String(o).slice(0,60),prints:[],...n?{entity:e}:{address:e}};this.host.change(s=>{s.settings.ble={tags:[...s.settings.ble?.tags??[],i]}}),this._tag=i.id,this._pick="",this._name=""}removeTag(e){this.host.change(n=>{let r=(n.settings.ble?.tags??[]).filter(o=>o.id!==e);n.settings.ble=r.length?{tags:r}:null}),this._tag===e&&(this._tag=null)}bars(e){let n=this.host.t,r=this._scan,o=Object.entries(r?.readings??{}).sort((i,s)=>s[1].rssi-i[1].rssi);return m`
+ `};customElements.get("nf-wall-view")||customElements.define("nf-wall-view",Va);function z0(t,e){let n=new Set([...Object.keys(t),...Object.keys(e)]);if(n.size===0)return 1/0;let r=0;for(let o of n)r+=Math.min(Math.abs((t[o]??-100)-(e[o]??-100)),40)**2;return Math.sqrt(r/n.size)}function Bp(t,e){if(Object.keys(e).length===0)return{room:null,distance:1/0,margin:0};let n=new Map;for(let s of t){let l=z0(s.rssi,e);l<(n.get(s.room)??1/0)&&n.set(s.room,l)}let r=[...n].sort((s,l)=>s[1]-l[1]);if(r.length===0)return{room:null,distance:1/0,margin:0};let[o,i]=r[0];return i>18?{room:null,distance:i,margin:0}:{room:o,distance:i,margin:r.length>1?r[1][1]-i:18}}var P0=t=>{let e=[...t].sort((r,o)=>r-o),n=e.length>>1;return e.length%2?e[n]:(e[n-1]+e[n])/2};function I0(t){let e={},n=new Set(t.flatMap(r=>Object.keys(r)));for(let r of n){let o=t.filter(i=>r in i).map(i=>i[r]);o.length*2>t.length&&(e[r]=Math.round(P0(o)*10)/10)}return e}function Wp(t,e,n=3){let r=e.filter(s=>Object.keys(s).length>0);if(r.length===0)return[];let o=Math.max(1,Math.min(n,Math.floor(r.length/3))),i=[];for(let s=0;s0&&i.push({room:t,rssi:a})}return i}var Vp=(t,e,n)=>[...t.filter(r=>r.room!==e),...n],Kp=t=>Math.max(0,Math.min(1,(t+95)/50));var D0=1500,Ga=class extends ne{static properties={host:{attribute:!1},doc:{attribute:!1},_found:{state:!0},_pick:{state:!0},_name:{state:!0},_tag:{state:!0},_room:{state:!0},_scan:{state:!0},_samples:{state:!0},_error:{state:!0}};timer=0;recordStarted=0;constructor(){super(),this._found=null,this._pick="",this._name="",this._tag=null,this._room="",this._scan=null,this._samples=null,this._error=""}createRenderRoot(){return this}get tags(){return this.host.doc.settings.ble?.tags??[]}get rooms(){let e=this.host.doc.floors;return e.flatMap(n=>n.rooms.map(r=>({id:r.id,label:e.length>1?`${n.name} \xB7 ${r.name}`:r.name})))}connectedCallback(){super.connectedCallback(),this.loadDevices()}disconnectedCallback(){super.disconnectedCallback(),window.clearInterval(this.timer)}updated(e){e.has("_tag")&&this.restartPolling()}async loadDevices(){try{this._found=await this.host.hass.callWS({type:"nextfloor/ble/devices"})}catch(e){this._error=String(e?.message??e)}}restartPolling(){if(window.clearInterval(this.timer),this._scan=null,!this._tag)return;let e=()=>{this.pollOnce()};e(),this.timer=window.setInterval(e,D0)}async pollOnce(){let e=this.tags.find(n=>n.id===this._tag);if(!(!e||!this.host.hass))try{let n=await this.host.hass.callWS({type:"nextfloor/ble/scan",...e.entity?{entity:e.entity}:{address:e.address}});this._scan=n,this._error="",this._samples&&(this._samples=[...this._samples,Object.fromEntries(Object.entries(n.readings).map(([r,o])=>[r,o.rssi]))],Date.now()-this.recordStarted>=30*1e3&&this.finishRecording(e,n))}catch(n){this._error=String(n?.message??n)}}reading(){return Object.fromEntries(Object.entries(this._scan?.readings??{}).map(([e,n])=>[e,n.rssi]))}startRecording(){this._room&&(this.recordStarted=Date.now(),this._samples=[])}finishRecording(e,n){let r=this._samples??[];this._samples=null;let o=Wp(this._room,r);if(o.length===0)return;let i=Object.fromEntries(Object.entries(n.readings).map(([s,l])=>[s,l.name]));this.update2(e.id,s=>{s.prints=Vp(s.prints,this._room,o),s.scanners={...s.scanners??{},...i}})}update2(e,n){this.host.change(r=>{let o=r.settings.ble?.tags.find(i=>i.id===e);o&&n(o)})}addTag(){let e=this._pick;if(!e)return;let n=e.startsWith("device_tracker."),r=this._found?.devices.find(s=>s.address===e),o=this._name.trim()||r?.name||this.host.hass?.states[e]?.attributes.friendly_name||e,i={id:D("ble"),name:String(o).slice(0,60),prints:[],...n?{entity:e}:{address:e}};this.host.change(s=>{s.settings.ble={tags:[...s.settings.ble?.tags??[],i]}}),this._tag=i.id,this._pick="",this._name=""}removeTag(e){this.host.change(n=>{let r=(n.settings.ble?.tags??[]).filter(o=>o.id!==e);n.settings.ble=r.length?{tags:r}:null}),this._tag===e&&(this._tag=null)}bars(e){let n=this.host.t,r=this._scan,o=Object.entries(r?.readings??{}).sort((i,s)=>s[1].rssi-i[1].rssi);return m`
${o.length===0?m`

${r&&!r.available?n("ble_unavailable"):r?.address===null&&e.entity?n("ble_no_address"):n("ble_none_heard")}

`:o.map(([i,s])=>m`
${s.name} @@ -1171,7 +1171,7 @@ ${i}`}else o=ju(s)}}catch(s){let l=s.message,a={not_json:"import_error_not_json"
-
`}};customElements.get("nf-ble-locate")||customElements.define("nf-ble-locate",Ga);var D0=new URL(import.meta.url),O0=new URL("./nextfloor-3d.js?v=473b84f8bac7",D0).href,Gp;function pn(){return Gp??=import(O0),Gp}var jp=["lights","seating","tables","storage","beds","kitchen","appliances","bath","media","office","tech","climate","energy","garden","plants","kids","fitness","pets","workshop","music","season","pictures","vehicles","building","decor"],H0={sofa:"seating",armchair:"seating",stool:"seating",chair:"seating",bench:"seating",corner_bench:"seating",bar_stool:"seating",office_chair:"office",coffee_table:"tables",table:"tables",table_round:"tables",desk:"office",worktop:"kitchen",tv_board:"media",tv_wall:"media",sideboard:"storage",shelf:"storage",tall_cabinet:"storage",wardrobe:"storage",dresser:"storage",nightstand:"beds",coat_rack:"storage",plant:"plants",rug:"decor",kitchen:"kitchen",kitchen_wall:"kitchen",kitchen_tall:"kitchen",island:"kitchen",sink:"kitchen",stove:"kitchen",dishwasher:"appliances",fridge:"appliances",washer:"appliances",dryer:"appliances",robot_vacuum:"appliances",bed:"beds",bunk_bed:"beds",bathtub:"bath",shower:"bath",wc:"bath",washbasin:"bath",radiator:"climate",stairs:"building",parking:"vehicles",ceiling_fan:"lights"},L0=[[/xmas|advent|window_star|candle_arch|reindeer|pumpkin|easter|snowman|gift_pile|lights_outdoor/,"season"],[/^frame_|^canvas$|^poster$|picture_ledge/,"pictures"],[/piano|drum_kit|guitar|synth|mic_stand|vinyl|easel|studio_monitor|mixing_desk/,"music"],[/lamp|pendant|light_pillar|light_bars|mood_spot|ceiling_panel|garden_spots|wall_light|light_cove|niche_led|shelf_led|monitor_light|workshop_light|painting_light|cabinet_light|moon_light|torch|lantern|ceiling_fan_light/,"lights"],[/cat_|dog_|pet_|litter|scratch|hamster|rabbit|bird_cage|small_animal|aquarium|terrarium/,"pets"],[/stairs|steps|landing|rail_|column|pilaster|beam|chimney|glass_wall|sliding_wall|half_wall|platform|niche_shelf|window_seat|divider_slats|gallery/,"building"],[/tree|shrub|conifer|hedge|brush|monstera|plant|herb_garden|herb_planter|flower|raised_bed|greenhouse|ficus|cactus|bonsai|living_wall|vertical_garden/,"plants"],[/kids|toy|teepee|(^|_)play_|rocking_horse|ball_pit|house_bed|cot\b|^cot|crib|changing_table|baby|loft_bed|star_projector|moon_light/,"kids"],[/treadmill|fitness|power_rack|rowing|rower|spin_bike|dumbbell|punching|yoga|elliptical|gym|exercise|wall_bars|bike_trainer|kettlebell|weight_bench|massage_chair/,"fitness"],[/heat_pump|boiler|buffer_tank|manifold|ventilation|radiator|towel_heater|thermostat|air_purifier|humidifier|dehumidifier|tower_fan|ceiling_fan|hot_water|water_softener|water_pump|fireplace|wood_stove|patio_heater|sauna|oil_|expansion_vessel|water_tank|infrared|cold_bath/,"climate"],[/wallbox|inverter|battery|solar|meter|fuse_box|grid/,"energy"],[/workbench|tool_|compressor|drill|tyre|paint_cabinet|heavy_shelf|shelf_rack|garage_opener|workshop|bike_stand|bike_holder|bike_rack|lawn_mower|mower|welder|ev_bike_charger|tool_chest|parts_cabinet/,"workshop"],[/speaker|subwoofer|soundbar|receiver|turntable|record|game_console|multiroom|hifi|cinema|acoustic|bass_trap|popcorn|projector|projection|screen|display_|smart_display|media|tv|arcade|star_ceiling|av_/,"media"],[/desk|office|filing|whiteboard|monitor|bookcase|phone_booth|sim_cockpit|chair_gaming|gaming/,"office"],[/server|nas|router|wifi|access_point|network|printer|filament|tower_pc|smoke_detector|siren|baby_monitor|sunrise_clock|light_switch|socket|co_detector|presence_|water_leak|air_quality|doorbell/,"tech"],[/grill|lounge|lounger|parasol|pergola|hot_tub|fire_bowl|torch|lantern|play_tower|garden|trampoline|sprinkler|valve|rain_barrel|outdoor|hammock|(^|_)pool|swing|bin_box|^bin_|mailbox|rotary_line|kamado|pizza_oven|fire_pit|sandbox|wood_pile|bird_house|cistern|pond|water_feature|beach_chair/,"garden"],[/vanity_\d|vanity_double|double_vanity|basin|bath|shower|toilet|bidet|towel|mirror_cabinet|mirror_round|mirror_80|mirror_led|whirlpool|washer_under|laundry|urinal|wt_\d|handtuch|seife|wc/,"bath"],[/fridge|freezer|dishwasher|washer|dryer|microwave|coffee_machine|kettle|toaster|mixer|oven|steam|vacuum|ironing|drying_rack|trash|water_cooler|drip_tray|espresso|air_fryer|water_bar|thermo_cooker/,"appliances"],[/base_|drawer_|sink|hob|cooker|hood|pantry|kitchen|island|breakfast_bar|wall_\d|wall_glass|wall_corner|row_|spice|cabinet_light|trolley|bar_cart|utility_sink/,"kitchen"],[/bed|boxspring|futon|nightstand|canopy|mattress/,"beds"],[/sofa|chair|armchair|stool|bench|pouf|bean_bag|recliner|wingback|chaise|seat|ektorp|poang|cosy_corner|swing_bench|hanging_chair|nook|floor_cushion|tatami/,"seating"],[/table|dining|coffee_|side_round|lack_|^console$|bekant|alex/,"tables"],[/wardrobe|closet|clothes_rail|chest|dresser|shelf|cabinet|sideboard|lowboard|highboard|kallax|billy|ivar|pax|besta|cube_|coat_stand|shoe_bench|divider|display_cabinet|wall_unit|malm_chest|locker/,"storage"]];function C0(t){if(t.vehicle)return"vehicles";if(t.climate)return"climate";if(!t.type.startsWith("pack:"))return t.lamp?"lights":H0[t.type]??"decor";let e=L0.find(([n])=>n.test(t.id));return e?e[1]:t.lamp?"lights":"decor"}var Up=[[/k(u|ü)che|kitchen|kochen/,["kitchen","appliances","tables","seating","storage","plants","decor"]],[/wohn|living|lounge|salon/,["seating","tables","storage","media","plants","decor","climate","tech"]],[/\bess|dining/,["tables","seating","storage","plants","decor","media"]],[/schlaf|bed|gast|guest/,["beds","storage","seating","tables","decor","plants","climate","media"]],[/kind|kids|child|baby|spiel|play|nursery/,["kids","beds","storage","seating","tables","decor"]],[/bad|bath|wc|toilet|dusch|shower|sauna/,["bath","appliances","storage","climate","plants"]],[/b(u|ü)ro|office|arbeit|study|work/,["office","tech","storage","seating","tables","plants"]],[/kino|cinema|media|game|gaming|hifi/,["media","seating","tables","storage","office"]],[/fitness|gym|sport|training/,["fitness","media","storage","climate"]],[/garage|carport|stellplatz|parking/,["vehicles","workshop","energy","storage","garden"]],[/werkstatt|workshop|hobby|keller|cellar|basement|lager|storage/,["workshop","storage","appliances","energy","climate","fitness","tech"]],[/hauswirtschaft|hwr|utility|laundry|wasch|technik|heiz|boiler/,["appliances","climate","energy","storage","tech","bath"]],[/flur|diele|hall|entr|eingang|corridor|treppe|stair/,["storage","seating","decor","plants","building"]],[/garten|garden|terrass|terrace|balkon|balcony|patio|hof|yard|pool/,["garden","plants","seating","tables","pets","kids"]]];function ja(t){let e=(t??"").toLowerCase(),n=Up.find(([r])=>r.test(e));return n?new Set(["lights",...n[1]]):null}function Ua(t){let e=(t??"").toLowerCase();return Up.find(([n])=>n.test(e))?.[1][0]??null}var Zp=t=>t==="garden"||t==="plants"||t==="vehicles",qp=/_(\d+(?:x\d+)?)$/;function Yp(t){let e=new Map;for(let n of t){let r=C0(n),o=n.type.startsWith("pack:")&&!n.vehicle?n.id.replace(qp,""):n.id,i=`${n.source}:${o}`,s=e.get(i);s&&s.category===r?s.entries.push(n):e.set(s?`${i}:${n.id}`:i,{key:s?`${i}:${n.id}`:i,category:r,entries:[n]})}for(let n of e.values())n.entries.sort((r,o)=>r.size[0]-o.size[0]||r.size[1]-o.size[1]);return[...e.values()]}function Xp(t,e){let n=o=>Math.round(o*100);return e.some(o=>o!==t&&n(o.size[0])===n(t.size[0]))?qp.exec(t.id)?.[1]??`${n(t.size[0])}\xD7${n(t.size[2])}`:`${n(t.size[0])}`}function Qp(t,e,n=12){return[e,...t.filter(r=>r!==e)].slice(0,n)}var Jp=t=>t.toLowerCase().normalize("NFD").replace(new RegExp("\\p{M}","gu"),""),ef=t=>Jp(t).split(/\s+/).filter(Boolean),tf=(t,e)=>{let n=Jp(e);return t.every(r=>n.includes(r))};function nf(){let e=navigator.deviceMemory??8,n=navigator.hardwareConcurrency||8;return e<=3||n<=4||/Silk|KF[A-Z]{2,4}\b/.test(navigator.userAgent)}var rf=112,N0="nextfloor-thumbs";function B0(t){let e=2166136261;for(let n=0;n>>0).toString(36)}function Za(t){let e=G(t);return`${t}|${e?B0(JSON.stringify(e)):"b"}|${rf}`}function W0(){return new Promise(t=>{try{let e=indexedDB.open(N0,1);e.onupgradeneeded=()=>e.result.createObjectStore("thumbs"),e.onsuccess=()=>t(e.result),e.onerror=()=>t(null)}catch{t(null)}})}var qa=class{enabled=!nf();memory=new Map;waiting=new Map;queue=[];db=null;running=!1;packs=[];cached(e){return this.memory.get(Za(e))}get(e){let n=Za(e),r=this.memory.get(n);return r?Promise.resolve(r):new Promise(o=>{let i=this.waiting.get(n);if(i)return void i.push(o);this.waiting.set(n,[o]),this.lookUp(e,n)})}settle(e,n){n&&this.memory.set(e,n);for(let r of this.waiting.get(e)??[])r(n);this.waiting.delete(e)}async lookUp(e,n){this.db??=W0();let r=await this.db,o=r?await new Promise(i=>{try{let s=r.transaction("thumbs").objectStore("thumbs").get(n);s.onsuccess=()=>i(typeof s.result=="string"?s.result:null),s.onerror=()=>i(null)}catch{i(null)}}):null;if(o)return this.settle(n,o);this.queue.push(e),this.pump()}pump(){if(this.running)return;let e=this.queue.shift();if(!e)return;this.running=!0;let n=window.requestIdleCallback;(o=>n?n(o,{timeout:300}):setTimeout(o,16))(async()=>{let o=Za(e),i=null;try{let[s,l,a]=at(e);i=(await pn()).furniturePreview({type:e,w:s,d:l,h:a,variant:null,lamp:Co[e]??null},rf,[...this.packs]),this.keep(o,i)}catch{i=null}this.settle(o,i),this.running=!1,this.pump()})}async keep(e,n){let r=await this.db;try{r?.transaction("thumbs","readwrite").objectStore("thumbs").put(n,e)}catch{}}},Bt=new qa,lo=null,V0=t=>{for(let e of t)e.isIntersecting&&e.target.visible()},Ya=class extends ne{static properties={type:{},_url:{state:!0}};static styles=se` +
`}};customElements.get("nf-ble-locate")||customElements.define("nf-ble-locate",Ga);var O0=new URL(import.meta.url),H0=new URL("./nextfloor-3d.js?v=473b84f8bac7",O0).href,Gp;function pn(){return Gp??=import(H0),Gp}var jp=["lights","seating","tables","storage","beds","kitchen","appliances","bath","media","office","tech","climate","energy","garden","plants","kids","fitness","pets","workshop","music","season","pictures","vehicles","building","decor"],L0={sofa:"seating",armchair:"seating",stool:"seating",chair:"seating",bench:"seating",corner_bench:"seating",bar_stool:"seating",office_chair:"office",coffee_table:"tables",table:"tables",table_round:"tables",desk:"office",worktop:"kitchen",tv_board:"media",tv_wall:"media",sideboard:"storage",shelf:"storage",tall_cabinet:"storage",wardrobe:"storage",dresser:"storage",nightstand:"beds",coat_rack:"storage",plant:"plants",rug:"decor",kitchen:"kitchen",kitchen_wall:"kitchen",kitchen_tall:"kitchen",island:"kitchen",sink:"kitchen",stove:"kitchen",dishwasher:"appliances",fridge:"appliances",washer:"appliances",dryer:"appliances",robot_vacuum:"appliances",bed:"beds",bunk_bed:"beds",bathtub:"bath",shower:"bath",wc:"bath",washbasin:"bath",radiator:"climate",stairs:"building",parking:"vehicles",ceiling_fan:"lights"},C0=[[/xmas|advent|window_star|candle_arch|reindeer|pumpkin|easter|snowman|gift_pile|lights_outdoor/,"season"],[/^frame_|^canvas$|^poster$|picture_ledge/,"pictures"],[/piano|drum_kit|guitar|synth|mic_stand|vinyl|easel|studio_monitor|mixing_desk/,"music"],[/lamp|pendant|light_pillar|light_bars|mood_spot|ceiling_panel|garden_spots|wall_light|light_cove|niche_led|shelf_led|monitor_light|workshop_light|painting_light|cabinet_light|moon_light|torch|lantern|ceiling_fan_light/,"lights"],[/cat_|dog_|pet_|litter|scratch|hamster|rabbit|bird_cage|small_animal|aquarium|terrarium/,"pets"],[/stairs|steps|landing|rail_|column|pilaster|beam|chimney|glass_wall|sliding_wall|half_wall|platform|niche_shelf|window_seat|divider_slats|gallery/,"building"],[/tree|shrub|conifer|hedge|brush|monstera|plant|herb_garden|herb_planter|flower|raised_bed|greenhouse|ficus|cactus|bonsai|living_wall|vertical_garden/,"plants"],[/kids|toy|teepee|(^|_)play_|rocking_horse|ball_pit|house_bed|cot\b|^cot|crib|changing_table|baby|loft_bed|star_projector|moon_light/,"kids"],[/treadmill|fitness|power_rack|rowing|rower|spin_bike|dumbbell|punching|yoga|elliptical|gym|exercise|wall_bars|bike_trainer|kettlebell|weight_bench|massage_chair/,"fitness"],[/heat_pump|boiler|buffer_tank|manifold|ventilation|radiator|towel_heater|thermostat|air_purifier|humidifier|dehumidifier|tower_fan|ceiling_fan|hot_water|water_softener|water_pump|fireplace|wood_stove|patio_heater|sauna|oil_|expansion_vessel|water_tank|infrared|cold_bath/,"climate"],[/wallbox|inverter|battery|solar|meter|fuse_box|grid/,"energy"],[/workbench|tool_|compressor|drill|tyre|paint_cabinet|heavy_shelf|shelf_rack|garage_opener|workshop|bike_stand|bike_holder|bike_rack|lawn_mower|mower|welder|ev_bike_charger|tool_chest|parts_cabinet/,"workshop"],[/speaker|subwoofer|soundbar|receiver|turntable|record|game_console|multiroom|hifi|cinema|acoustic|bass_trap|popcorn|projector|projection|screen|display_|smart_display|media|tv|arcade|star_ceiling|av_/,"media"],[/desk|office|filing|whiteboard|monitor|bookcase|phone_booth|sim_cockpit|chair_gaming|gaming/,"office"],[/server|nas|router|wifi|access_point|network|printer|filament|tower_pc|smoke_detector|siren|baby_monitor|sunrise_clock|light_switch|socket|co_detector|presence_|water_leak|air_quality|doorbell/,"tech"],[/grill|lounge|lounger|parasol|pergola|hot_tub|fire_bowl|torch|lantern|play_tower|garden|trampoline|sprinkler|valve|rain_barrel|outdoor|hammock|(^|_)pool|swing|bin_box|^bin_|mailbox|rotary_line|kamado|pizza_oven|fire_pit|sandbox|wood_pile|bird_house|cistern|pond|water_feature|beach_chair/,"garden"],[/vanity_\d|vanity_double|double_vanity|basin|bath|shower|toilet|bidet|towel|mirror_cabinet|mirror_round|mirror_80|mirror_led|whirlpool|washer_under|laundry|urinal|wt_\d|handtuch|seife|wc/,"bath"],[/fridge|freezer|dishwasher|washer|dryer|microwave|coffee_machine|kettle|toaster|mixer|oven|steam|vacuum|ironing|drying_rack|trash|water_cooler|drip_tray|espresso|air_fryer|water_bar|thermo_cooker/,"appliances"],[/base_|drawer_|sink|hob|cooker|hood|pantry|kitchen|island|breakfast_bar|wall_\d|wall_glass|wall_corner|row_|spice|cabinet_light|trolley|bar_cart|utility_sink/,"kitchen"],[/bed|boxspring|futon|nightstand|canopy|mattress/,"beds"],[/sofa|chair|armchair|stool|bench|pouf|bean_bag|recliner|wingback|chaise|seat|ektorp|poang|cosy_corner|swing_bench|hanging_chair|nook|floor_cushion|tatami/,"seating"],[/table|dining|coffee_|side_round|lack_|^console$|bekant|alex/,"tables"],[/wardrobe|closet|clothes_rail|chest|dresser|shelf|cabinet|sideboard|lowboard|highboard|kallax|billy|ivar|pax|besta|cube_|coat_stand|shoe_bench|divider|display_cabinet|wall_unit|malm_chest|locker/,"storage"]];function N0(t){if(t.vehicle)return"vehicles";if(t.climate)return"climate";if(!t.type.startsWith("pack:"))return t.lamp?"lights":L0[t.type]??"decor";let e=C0.find(([n])=>n.test(t.id));return e?e[1]:t.lamp?"lights":"decor"}var Up=[[/k(u|ü)che|kitchen|kochen/,["kitchen","appliances","tables","seating","storage","plants","decor"]],[/wohn|living|lounge|salon/,["seating","tables","storage","media","plants","decor","climate","tech"]],[/\bess|dining/,["tables","seating","storage","plants","decor","media"]],[/schlaf|bed|gast|guest/,["beds","storage","seating","tables","decor","plants","climate","media"]],[/kind|kids|child|baby|spiel|play|nursery/,["kids","beds","storage","seating","tables","decor"]],[/bad|bath|wc|toilet|dusch|shower|sauna/,["bath","appliances","storage","climate","plants"]],[/b(u|ü)ro|office|arbeit|study|work/,["office","tech","storage","seating","tables","plants"]],[/kino|cinema|media|game|gaming|hifi/,["media","seating","tables","storage","office"]],[/fitness|gym|sport|training/,["fitness","media","storage","climate"]],[/garage|carport|stellplatz|parking/,["vehicles","workshop","energy","storage","garden"]],[/werkstatt|workshop|hobby|keller|cellar|basement|lager|storage/,["workshop","storage","appliances","energy","climate","fitness","tech"]],[/hauswirtschaft|hwr|utility|laundry|wasch|technik|heiz|boiler/,["appliances","climate","energy","storage","tech","bath"]],[/flur|diele|hall|entr|eingang|corridor|treppe|stair/,["storage","seating","decor","plants","building"]],[/garten|garden|terrass|terrace|balkon|balcony|patio|hof|yard|pool/,["garden","plants","seating","tables","pets","kids"]]];function ja(t){let e=(t??"").toLowerCase(),n=Up.find(([r])=>r.test(e));return n?new Set(["lights",...n[1]]):null}function Ua(t){let e=(t??"").toLowerCase();return Up.find(([n])=>n.test(e))?.[1][0]??null}var Zp=t=>t==="garden"||t==="plants"||t==="vehicles",qp=/_(\d+(?:x\d+)?)$/;function Yp(t){let e=new Map;for(let n of t){let r=N0(n),o=n.type.startsWith("pack:")&&!n.vehicle?n.id.replace(qp,""):n.id,i=`${n.source}:${o}`,s=e.get(i);s&&s.category===r?s.entries.push(n):e.set(s?`${i}:${n.id}`:i,{key:s?`${i}:${n.id}`:i,category:r,entries:[n]})}for(let n of e.values())n.entries.sort((r,o)=>r.size[0]-o.size[0]||r.size[1]-o.size[1]);return[...e.values()]}function Xp(t,e){let n=o=>Math.round(o*100);return e.some(o=>o!==t&&n(o.size[0])===n(t.size[0]))?qp.exec(t.id)?.[1]??`${n(t.size[0])}\xD7${n(t.size[2])}`:`${n(t.size[0])}`}function Qp(t,e,n=12){return[e,...t.filter(r=>r!==e)].slice(0,n)}var Jp=t=>t.toLowerCase().normalize("NFD").replace(new RegExp("\\p{M}","gu"),""),ef=t=>Jp(t).split(/\s+/).filter(Boolean),tf=(t,e)=>{let n=Jp(e);return t.every(r=>n.includes(r))};function nf(){let e=navigator.deviceMemory??8,n=navigator.hardwareConcurrency||8;return e<=3||n<=4||/Silk|KF[A-Z]{2,4}\b/.test(navigator.userAgent)}var rf=112,B0="nextfloor-thumbs";function W0(t){let e=2166136261;for(let n=0;n>>0).toString(36)}function Za(t){let e=G(t);return`${t}|${e?W0(JSON.stringify(e)):"b"}|${rf}`}function V0(){return new Promise(t=>{try{let e=indexedDB.open(B0,1);e.onupgradeneeded=()=>e.result.createObjectStore("thumbs"),e.onsuccess=()=>t(e.result),e.onerror=()=>t(null)}catch{t(null)}})}var qa=class{enabled=!nf();memory=new Map;waiting=new Map;queue=[];db=null;running=!1;packs=[];cached(e){return this.memory.get(Za(e))}get(e){let n=Za(e),r=this.memory.get(n);return r?Promise.resolve(r):new Promise(o=>{let i=this.waiting.get(n);if(i)return void i.push(o);this.waiting.set(n,[o]),this.lookUp(e,n)})}settle(e,n){n&&this.memory.set(e,n);for(let r of this.waiting.get(e)??[])r(n);this.waiting.delete(e)}async lookUp(e,n){this.db??=V0();let r=await this.db,o=r?await new Promise(i=>{try{let s=r.transaction("thumbs").objectStore("thumbs").get(n);s.onsuccess=()=>i(typeof s.result=="string"?s.result:null),s.onerror=()=>i(null)}catch{i(null)}}):null;if(o)return this.settle(n,o);this.queue.push(e),this.pump()}pump(){if(this.running)return;let e=this.queue.shift();if(!e)return;this.running=!0;let n=window.requestIdleCallback;(o=>n?n(o,{timeout:300}):setTimeout(o,16))(async()=>{let o=Za(e),i=null;try{let[s,l,a]=at(e);i=(await pn()).furniturePreview({type:e,w:s,d:l,h:a,variant:null,lamp:Co[e]??null},rf,[...this.packs]),this.keep(o,i)}catch{i=null}this.settle(o,i),this.running=!1,this.pump()})}async keep(e,n){let r=await this.db;try{r?.transaction("thumbs","readwrite").objectStore("thumbs").put(n,e)}catch{}}},Bt=new qa,lo=null,K0=t=>{for(let e of t)e.isIntersecting&&e.target.visible()},Ya=class extends ne{static properties={type:{},_url:{state:!0}};static styles=se` :host { display: block; aspect-ratio: 4 / 3; @@ -1185,7 +1185,7 @@ ${i}`}else o=ju(s)}}catch(s){let l=s.message,a={not_json:"import_error_not_json" height: 100%; object-fit: contain; } - `;constructor(){super(),this.type="",this._url=null}connectedCallback(){super.connectedCallback(),Bt.enabled&&(this._url=Bt.cached(this.type)??null,!this._url&&(lo??=new IntersectionObserver(V0,{rootMargin:"120px"}),lo.observe(this)))}disconnectedCallback(){super.disconnectedCallback(),lo?.unobserve(this)}updated(e){e.has("type")&&e.get("type")!==void 0&&(this._url=Bt.cached(this.type)??null,!this._url&&Bt.enabled&&lo?.observe(this))}visible(){lo?.unobserve(this);let e=this.type;Bt.get(e).then(n=>{this.type===e&&(this._url=n)})}render(){return this._url?m``:_}};customElements.get("nf-thumb")||customElements.define("nf-thumb",Ya);var of="nextfloor.library2",K0={language:"en"},Ei=class{onChange;text="";saved;shown=null;picked=new Map;constructor(e){this.onChange=e,this.saved={folded:{},favourites:[],recent:[],flags:["room"]};try{let n=localStorage.getItem(of);n&&(this.saved={...this.saved,...JSON.parse(n)})}catch{}}store(e){this.saved={...this.saved,...e},this.onChange();try{localStorage.setItem(of,JSON.stringify(this.saved))}catch{}}get query(){return this.text}set query(e){this.text=e,this.onChange()}isOpen(e,n){return this.saved.folded[e]??n}toggle(e,n){this.store({folded:{...this.saved.folded,[e]:!this.isOpen(e,n)}})}has(e){return this.saved.flags.includes(e)}flip(e){this.store({flags:this.has(e)?this.saved.flags.filter(n=>n!==e):[...this.saved.flags,e]})}get favourites(){return this.saved.favourites}isFavourite(e){return this.saved.favourites.includes(e)}toggleFavourite(e){this.store({favourites:this.isFavourite(e)?this.saved.favourites.filter(n=>n!==e):[e,...this.saved.favourites]})}get recent(){return this.saved.recent}used(e){this.store({recent:Qp(this.saved.recent,e)})}pickedOf(e){let n=this.picked.get(e.key);return e.entries.find(r=>r.type===n)??e.entries[0]}pick(e,n){this.picked.set(e.key,n),this.onChange()}get preview(){return this.shown}hidePreview(){this.shown=null,this.onChange()}async showPreview(e,n,r){let o=n.getBoundingClientRect(),i={left:Math.max(8,o.left-196),top:Math.max(8,Math.min(window.innerHeight-200,o.top+o.height/2-95))};this.shown={type:e,url:null,...i},this.onChange();try{let[s,l,a]=at(e),c=(await pn()).furniturePreview({type:e,w:s,d:l,h:a,variant:null,lamp:Co[e]??null},180,[...r]);this.shown?.type===e&&(this.shown={type:e,url:c,...i})}catch{this.shown=null}this.onChange()}};function G0(t,e){let n=t.hass?.language??"en",o=[...[...new Set(Object.values(Yc).flat())].map(l=>({type:l,source:"builtin",id:l,size:et[l],lamp:ce(l),electric:Et(l)})),...e.flatMap(l=>l.items.map(a=>({type:ue(l.id,a.id),source:l.id,id:a.id,size:a.size,lamp:!!a.light,electric:!!a.electric,vehicle:!!a.vehicle,climate:!!a.climate})))],i=new Map(e.map(l=>[l.id,Oe(l,n)])),s=new Map(e.flatMap(l=>l.items.map(a=>[ue(l.id,a.id),a])));return Yp(o).map(l=>{let a=l.entries[0],c=s.get(a.type),d=c?Ye(c,a.type,n):t.t(`furn_${a.type}`),u=l.entries.length>1&&d.replace(/\s*\(?\d+([.,]\d+)?\s*(cm|x\s*\d+|×\s*\d+)?\)?\s*$/i,"").trim()||d,p=l.entries.map(h=>{let f=s.get(h.type);return f?[...Object.values(f.name),Ye(f,h.type,n)].join(" "):xe(K0,`furn_${h.type}`)}).join(" ");return{card:l,label:u,search:`${p} ${t.t(`lib_cat_${l.category}`)}`,from:i.get(a.source)??"NextFloor"}})}var j0=(t,e)=>tf(e,`${t.label} ${t.search} ${t.from} ${t.card.entries.map(n=>n.id.replace(/_/g," ")).join(" ")}`),U0=t=>t.lamp?"light":t.electric?"switch":null;function Z0(t,e,n,r){let o=t.t,i=e.pickedOf(n.card),[s,l]=i.size,a=U0(i),c=p=>{e.showPreview(i.type,p.currentTarget,r.packs)},d=()=>{e.used(i.type),r.add(i.type)},u=e.isFavourite(i.type);return m`
+ `;constructor(){super(),this.type="",this._url=null}connectedCallback(){super.connectedCallback(),Bt.enabled&&(this._url=Bt.cached(this.type)??null,!this._url&&(lo??=new IntersectionObserver(K0,{rootMargin:"120px"}),lo.observe(this)))}disconnectedCallback(){super.disconnectedCallback(),lo?.unobserve(this)}updated(e){e.has("type")&&e.get("type")!==void 0&&(this._url=Bt.cached(this.type)??null,!this._url&&Bt.enabled&&lo?.observe(this))}visible(){lo?.unobserve(this);let e=this.type;Bt.get(e).then(n=>{this.type===e&&(this._url=n)})}render(){return this._url?m``:_}};customElements.get("nf-thumb")||customElements.define("nf-thumb",Ya);var of="nextfloor.library2",G0={language:"en"},Ei=class{onChange;text="";saved;shown=null;picked=new Map;constructor(e){this.onChange=e,this.saved={folded:{},favourites:[],recent:[],flags:["room"]};try{let n=localStorage.getItem(of);n&&(this.saved={...this.saved,...JSON.parse(n)})}catch{}}store(e){this.saved={...this.saved,...e},this.onChange();try{localStorage.setItem(of,JSON.stringify(this.saved))}catch{}}get query(){return this.text}set query(e){this.text=e,this.onChange()}isOpen(e,n){return this.saved.folded[e]??n}toggle(e,n){this.store({folded:{...this.saved.folded,[e]:!this.isOpen(e,n)}})}has(e){return this.saved.flags.includes(e)}flip(e){this.store({flags:this.has(e)?this.saved.flags.filter(n=>n!==e):[...this.saved.flags,e]})}get favourites(){return this.saved.favourites}isFavourite(e){return this.saved.favourites.includes(e)}toggleFavourite(e){this.store({favourites:this.isFavourite(e)?this.saved.favourites.filter(n=>n!==e):[e,...this.saved.favourites]})}get recent(){return this.saved.recent}used(e){this.store({recent:Qp(this.saved.recent,e)})}pickedOf(e){let n=this.picked.get(e.key);return e.entries.find(r=>r.type===n)??e.entries[0]}pick(e,n){this.picked.set(e.key,n),this.onChange()}get preview(){return this.shown}hidePreview(){this.shown=null,this.onChange()}async showPreview(e,n,r){let o=n.getBoundingClientRect(),i={left:Math.max(8,o.left-196),top:Math.max(8,Math.min(window.innerHeight-200,o.top+o.height/2-95))};this.shown={type:e,url:null,...i},this.onChange();try{let[s,l,a]=at(e),c=(await pn()).furniturePreview({type:e,w:s,d:l,h:a,variant:null,lamp:Co[e]??null},180,[...r]);this.shown?.type===e&&(this.shown={type:e,url:c,...i})}catch{this.shown=null}this.onChange()}};function j0(t,e){let n=t.hass?.language??"en",o=[...[...new Set(Object.values(Yc).flat())].map(l=>({type:l,source:"builtin",id:l,size:et[l],lamp:ce(l),electric:Et(l)})),...e.flatMap(l=>l.items.map(a=>({type:ue(l.id,a.id),source:l.id,id:a.id,size:a.size,lamp:!!a.light,electric:!!a.electric,vehicle:!!a.vehicle,climate:!!a.climate})))],i=new Map(e.map(l=>[l.id,Oe(l,n)])),s=new Map(e.flatMap(l=>l.items.map(a=>[ue(l.id,a.id),a])));return Yp(o).map(l=>{let a=l.entries[0],c=s.get(a.type),d=c?Ye(c,a.type,n):t.t(`furn_${a.type}`),u=l.entries.length>1&&d.replace(/\s*\(?\d+([.,]\d+)?\s*(cm|x\s*\d+|×\s*\d+)?\)?\s*$/i,"").trim()||d,p=l.entries.map(h=>{let f=s.get(h.type);return f?[...Object.values(f.name),Ye(f,h.type,n)].join(" "):xe(G0,`furn_${h.type}`)}).join(" ");return{card:l,label:u,search:`${p} ${t.t(`lib_cat_${l.category}`)}`,from:i.get(a.source)??"NextFloor"}})}var U0=(t,e)=>tf(e,`${t.label} ${t.search} ${t.from} ${t.card.entries.map(n=>n.id.replace(/_/g," ")).join(" ")}`),Z0=t=>t.lamp?"light":t.electric?"switch":null;function q0(t,e,n,r){let o=t.t,i=e.pickedOf(n.card),[s,l]=i.size,a=Z0(i),c=p=>{e.showPreview(i.type,p.currentTarget,r.packs)},d=()=>{e.used(i.type),r.add(i.type)},u=e.isFavourite(i.type);return m`
`)}
`:_} -
`}function af(t,e,n,r){return m`
${n.map(o=>Z0(t,e,o,r))}
`}function Xa(t,e,n,r,o,i,s){if(o.length===0)return _;let l=e.isOpen(n,s);return m`
`}function af(t,e,n,r){return m`
${n.map(o=>q0(t,e,o,r))}
`}function Xa(t,e,n,r,o,i,s){if(o.length===0)return _;let l=e.isOpen(n,s);return m` - ${l?af(t,e,o,i):_}`}function sf(t,e){return t.flatMap(n=>{let r=e.find(o=>o.card.entries.some(i=>i.type===n));return r?[{...r,card:{...r.card,key:`one:${n}`,entries:r.card.entries.filter(o=>o.type===n)}}]:[]})}function q0(t){let e=Ua(t),n=ja(t),r=o=>o===e?0:n?.has(o)?1:2;return[...jp].sort((o,i)=>r(o)-r(i))}function lf(t,e,n,r){let o=t.t;Bt.packs=r.packs;let i=G0(t,r.packs),s=ef(e.query),l=ja(n),a=!!l&&e.has("room")&&s.length===0,c=i.filter(p=>{let h=p.card.entries[0];return a&&!l.has(p.card.category)||e.has("linkable")&&!h.lamp&&!h.electric||e.has("lit")&&!h.lamp||e.has("outdoor")&&!Zp(p.card.category)?!1:s.length===0||j0(p,s)}),d=(p,h)=>m``,u=s.length>0;return m`
+ ${l?af(t,e,o,i):_}`}function sf(t,e){return t.flatMap(n=>{let r=e.find(o=>o.card.entries.some(i=>i.type===n));return r?[{...r,card:{...r.card,key:`one:${n}`,entries:r.card.entries.filter(o=>o.type===n)}}]:[]})}function Y0(t){let e=Ua(t),n=ja(t),r=o=>o===e?0:n?.has(o)?1:2;return[...jp].sort((o,i)=>r(o)-r(i))}function lf(t,e,n,r){let o=t.t;Bt.packs=r.packs;let i=j0(t,r.packs),s=ef(e.query),l=ja(n),a=!!l&&e.has("room")&&s.length===0,c=i.filter(p=>{let h=p.card.entries[0];return a&&!l.has(p.card.category)||e.has("linkable")&&!h.lamp&&!h.electric||e.has("lit")&&!h.lamp||e.has("outdoor")&&!Zp(p.card.category)?!1:s.length===0||U0(p,s)}),d=(p,h)=>m``,u=s.length>0;return m`

${o("furniture_add")}

${n?o("furniture_into",{room:n}):o("furniture_pick_room")}

@@ -1227,18 +1227,18 @@ ${i}`}else o=ju(s)}}catch(s){let l=s.message,a={not_json:"import_error_not_json" ${u&&c.length===0?m`

${o("furniture_search_none")}

`:_} ${u?af(t,e,c,r):m`${Xa(t,e,"favourites",`\u2605 ${o("lib_favourites")}`,sf(e.favourites,i),r,!0)} ${Xa(t,e,"recent",`\u{1F558} ${o("lib_recent")}`,sf(e.recent.slice(0,6),i),r,!1)} - ${q0(n).map(p=>Xa(t,e,p,o(`lib_cat_${p}`),c.filter(h=>h.card.category===p),r,p===(Ua(n)??"lights")))} + ${Y0(n).map(p=>Xa(t,e,p,o(`lib_cat_${p}`),c.filter(h=>h.card.category===p),r,p===(Ua(n)??"lights")))} ${a?m``:_}`}
`}function cf(t,e){return e?m``:_}function Qa(t,e,n,r=24){let o=Math.hypot(e[0]-t[0],e[1]-t[1]);if(o<1e-6||Math.abs(n)<1e-4)return[];let i=Math.max(-o*2,Math.min(o*2,n)),s=[(e[0]-t[0])/o,(e[1]-t[1])/o],l=[s[1],-s[0]],a=o*o/4/(2*Math.abs(i))+Math.abs(i)/2,c=2*Math.atan(2*Math.abs(i)/o),d=Math.max(2,Math.min(r,Math.ceil(2*c/Math.PI*180/11.25))),u=[l[0]*Math.sign(i),l[1]*Math.sign(i)],p=[(t[0]+e[0])/2,(t[1]+e[1])/2],h=[p[0]-u[0]*(a-Math.abs(i)),p[1]-u[1]*(a-Math.abs(i))],f=[];for(let g=1;gt.reduce((e,n,r)=>r?e+Math.hypot(n[0]-t[r-1][0],n[1]-t[r-1][1]):e,0);function el(t,e){let n=Math.max(0,e);for(let r=0;r+1Math.round(t*1e3)/1e3,tl=t=>t.map(([e,n])=>[Fe(e),Fe(n)]);function df(t,e){return{id:D("room"),name:e,area_id:null,points:tl(t),floor_material:"wood"}}function uf(t){return{...structuredClone(t),id:D("room"),points:tl(t.points.map(([e,n])=>[e+.5,n+.5]))}}function hf(t,e){let n=t.rooms.find(r=>r.id===e);t.rooms=t.rooms.filter(r=>r.id!==e),t.openings=t.openings.filter(r=>r.room_id!==e||r.wall),n&&(t.placements=t.placements.filter(r=>!N([r.x,r.z],n.points)))}function pf(t,e,n){let r=t.rooms.find(s=>s.id===e);if(!r||r.points.length<=3)return!1;let o=(n-1+r.points.length)%r.points.length;r.points.splice(n,1),r.wall_heights?.splice(n,1),r.wall_slopes?.splice(n,1),r.wall_thickness?.splice(n,1);let i=s=>s.room_id===e&&!s.wall;return t.openings=t.openings.filter(s=>!(i(s)&&(s.edge===n||s.edge===o))).map(s=>i(s)&&s.edge>n?{...s,edge:s.edge-1}:s),!0}function ff(t,e,n){if(!Number.isFinite(n))return null;let r=de(t.points),{x0:o,z0:i,x1:s,z1:l}=r;return e==="x"?[o,s]=[n,n+(s-o)]:e==="z"?[i,l]=[n,n+(l-i)]:n>.05&&(e==="w"?s=o+n:l=i+n),tl([[o,i],[s,i],[s,l],[o,l]])}function mf(t,e,n,r){return!Number.isFinite(r)||e<0||e>=t.points.length?null:t.points.map((o,i)=>i===e?n===0?[Fe(r),o[1]]:[o[0],Fe(r)]:[o[0],o[1]])}var Y0=/^(Raum|Room) \d+$/;function nl(t,e,n){let r=e?n[e]:void 0,o=!t.name||Y0.test(t.name)||Object.values(n).some(i=>i.name===t.name);return{area_id:e||null,...r&&o?{name:r.name}:{}}}function gf(t,e){let n=e.filter(a=>X(a.entity_id)==="light"&&(a.mount??"ceiling")==="ceiling"&&N([a.x,a.z],t.points));if(n.length<2)return[];let r=de(t.points),[o,i]=[r.x1-r.x0,r.z1-r.z0],s=Math.max(1,Math.round(Math.sqrt(n.length*o/Math.max(.1,i)))),l=Math.ceil(n.length/s);return n.map((a,c)=>{let d=Math.floor(c/s),u=d===l-1?n.length-s*(l-1):s,p=c-d*s;return{entityId:a.entity_id,x:Fe(r.x0+o/u*(p+.5)),z:Fe(r.z0+i/l*(d+.5))}})}function rl(t,e,n,r){let o=t.rooms.find(d=>d.id===e);if(!o)return;let i=o.points[n],s=o.points[(n+1)%o.points.length];o.points.splice(n+1,0,r);let[l,a]=[o.wall_heights?.[n],o.wall_slopes?.[n]];if(typeof l=="number"&&typeof a=="number"&&o.wall_slopes){let d=Math.hypot(s[0]-i[0],s[1]-i[1]),u=Fe(l+(a-l)*Math.min(1,Math.hypot(r[0]-i[0],r[1]-i[1])/(d||1)));o.wall_slopes.splice(n,1,u,a),o.wall_heights.splice(n+1,0,u)}else o.wall_heights?.splice(n+1,0,o.wall_heights[n]??null),o.wall_slopes?.splice(n+1,0,null);o.wall_thickness?.splice(n+1,0,o.wall_thickness[n]??null);let c=Math.hypot(r[0]-i[0],r[1]-i[1]);for(let d of t.openings)d.room_id!==e||d.wall||(d.edge>n?d.edge+=1:d.edge===n&&d.offset>c&&(d.edge=n+1,d.offset=Fe(d.offset-c)))}var X0=22.5;function _f(t,e,n){let r=Math.min(Math.abs(e),t*2),o=t*(1+8/3*(r/Math.max(1e-6,t))**2),i=4*Math.atan(2*r/Math.max(1e-6,t))*180/Math.PI,s=Math.max(2,Math.ceil(i/X0));if(n<=0)return 24;let l=Math.floor(o/(n+.1));return l>=s?l:0}function Q0(t,e,n,r){let o=Ja(n);t.forEach((i,s)=>{let{piece:l,offset:a}=el(n,e[s]*o),c=Math.hypot(n[l+1][0]-n[l][0],n[l+1][1]-n[l][1]);i.edge=r+l,i.offset=Fe(c>i.width?Math.min(c-i.width/2,Math.max(i.width/2,a)):c/2)})}function bf(t,e,n,r){let o=t.rooms.find(v=>v.id===e);if(!o||n<0||n>=o.points.length||Math.abs(r)<.01)return!1;let i=o.points[n],s=o.points[(n+1)%o.points.length],l=Math.hypot(s[0]-i[0],s[1]-i[1]);if(l<.2)return!1;let[a,c]=[(s[0]-i[0])/l,(s[1]-i[1])/l],d=[(i[0]+s[0])/2+c*.02,(i[1]+s[1])/2-a*.02],p=N(d,o.points)?-r:r,h=(v,w)=>t.openings.filter(x=>x.room_id===v.id&&!x.wall&&x.edge===w),f=t.rooms.flatMap(v=>v.points.map((w,x)=>{let k=v.points[(x+1)%v.points.length],$=(A,F)=>Math.abs(A[0]-F[0])<.001&&Math.abs(A[1]-F[1])<.001;return $(w,i)&&$(k,s)?[v,x,!1]:$(w,s)&&$(k,i)?[v,x,!0]:null}).filter(w=>!!w)),g=Math.max(0,...f.flatMap(([v,w])=>h(v,w).map(x=>x.width))),y=_f(l,r,g);if(!y)return!1;let b=Qa(i,s,p,y).map(([v,w])=>[Fe(v),Fe(w)]);if(!b.length)return!1;for(let[v,w,x]of f){let k=x?[...b].reverse():b,$=h(v,w),A=v.points[w],F=$.map(T=>Math.min(1,Math.max(0,T.offset/l)));for(let T of $)T.edge=-1;k.forEach((T,I)=>rl(t,v.id,w+I,T)),v.wall_splits?.splice(w+1,0,...k.map(()=>null)),v.wall_splits?.[w]&&(v.wall_splits[w]=null),Q0($,F,[A,...k,v.points[(w+k.length+1)%v.points.length]],w)}return!0}function yf(t,e,n){let r=t.walls??[],o=r.findIndex(f=>f.id===e);if(o<0||Math.abs(n)<.01)return[];let i=r[o],s=Math.hypot(i.b[0]-i.a[0],i.b[1]-i.a[1]),l=t.openings.filter(f=>f.wall===e),a=Math.max(0,...l.map(f=>f.width)),c=_f(s,n,a);if(!c)return[];let d=Qa(i.a,i.b,n,c).map(([f,g])=>[Fe(f),Fe(g)]);if(!d.length)return[];let u=[i.a,...d,i.b],p=u.slice(1).map((f,g)=>({...i,id:g===0?i.id:D("wall"),a:u[g],b:f}));r.splice(o,1,...p),t.walls=r;let h=Ja(u);for(let f of l){let{piece:g,offset:y}=el(u,f.offset/s*h),b=Math.hypot(u[g+1][0]-u[g][0],u[g+1][1]-u[g][1]);f.wall=p[g].id,f.offset=Fe(b>f.width?Math.min(b-f.width/2,Math.max(f.width/2,y)):b/2)}return p.map(f=>f.id)}var jn=t=>Math.round(t*1e3)/1e3;function Ai(t,e,n){return[Math.round((e[0]-t[0])/n)*n,Math.round((e[1]-t[1])/n)*n]}var fn=(t,e)=>e?.01:t,Un=(t,e,n=5)=>Math.hypot(t[0]-e[0],t[1]-e[1])>=n;function wf(t,e,n){return n?Math.abs(e[0]-t[0])>Math.abs(e[1]-t[1])?[e[0],t[1]]:[t[0],e[1]]:e}var Xe=(t,e)=>[jn(t[0]+e[0]),jn(t[1]+e[1])];function ol(t,e,n,r){return[jn(Math.round((t[0]+n[0]-e[0])/r)*r),jn(Math.round((t[1]+n[1]-e[1])/r)*r)]}function il(t,e,n){let r=Math.atan2(-(e[0]-t[0]),e[1]-t[1])*180/Math.PI;return(Math.round(r/n)*n%360+360)%360}function vf(t,e,n){let r=Math.atan2(e[0]-t[0],-(e[1]-t[1]))*180/Math.PI;return Math.round(r/n)*n}function kf(t,e,n){let r=xn([...t]),o=t[e],i=[jn(n[0]),jn(n[1])];return t.map((s,l)=>l===e?i:r?[Math.abs(s[0]-o[0])<1e-6?i[0]:s[0],Math.abs(s[1]-o[1])<1e-6?i[1]:s[1]]:[s[0],s[1]])}var Fi=t=>Math.round(t*1e3)/1e3,xf=(t,e)=>Math.hypot(t[0]-e[0],t[1]-e[1]);function J0(t,e,n){let r=null,o=n;for(let i of t){let s=xf(i,e);s{let a=i.points[(l+1)%i.points.length],[c,d]=[a[0]-s[0],a[1]-s[1]],u=c*c+d*d;if(u<1e-9)return;let p=((e[0]-s[0])*c+(e[1]-s[1])*d)/u;if(p<=0||p>=1)return;let h=[s[0]+p*c,s[1]+p*d],f=xf(h,e),g=(y,b,v)=>Math.min(Math.max(y,Math.min(b,v)),Math.max(b,v));Math.abs(d)<1e-9&&(h[0]=g(Math.round(h[0]/n.grid)*n.grid,s[0],a[0])),Math.abs(c)<1e-9&&(h[1]=g(Math.round(h[1]/n.grid)*n.grid,s[1],a[1])),fi.points.filter((s,l)=>!(e.skip&&i.id===e.skip.roomId&&(e.skip.index===void 0||e.skip.index===l)))),r=J0(n,t,e.reach);if(r)return{point:[r[0],r[1]],guides:{point:r}};let o=ew(e.rooms,t,e);return o?{point:[Fi(o[0]),Fi(o[1])],guides:{point:o}}:tw(n,t,e)}var Ti=(t,e)=>pe(t.host.hass,e);function nw(t,e){let[n,r]=[t.toScreen(e.start),t.toScreen(e.end)];if(e.kind==="freewall"){let s=Math.hypot(e.end[0]-e.start[0],e.end[1]-e.start[1]);return R` +
`:_}function Qa(t,e,n,r=24){let o=Math.hypot(e[0]-t[0],e[1]-t[1]);if(o<1e-6||Math.abs(n)<1e-4)return[];let i=Math.max(-o*2,Math.min(o*2,n)),s=[(e[0]-t[0])/o,(e[1]-t[1])/o],l=[s[1],-s[0]],a=o*o/4/(2*Math.abs(i))+Math.abs(i)/2,c=2*Math.atan(2*Math.abs(i)/o),d=Math.max(2,Math.min(r,Math.ceil(2*c/Math.PI*180/11.25))),u=[l[0]*Math.sign(i),l[1]*Math.sign(i)],p=[(t[0]+e[0])/2,(t[1]+e[1])/2],h=[p[0]-u[0]*(a-Math.abs(i)),p[1]-u[1]*(a-Math.abs(i))],f=[];for(let g=1;gt.reduce((e,n,r)=>r?e+Math.hypot(n[0]-t[r-1][0],n[1]-t[r-1][1]):e,0);function el(t,e){let n=Math.max(0,e);for(let r=0;r+1Math.round(t*1e3)/1e3,tl=t=>t.map(([e,n])=>[Fe(e),Fe(n)]);function df(t,e){return{id:D("room"),name:e,area_id:null,points:tl(t),floor_material:"wood"}}function uf(t){return{...structuredClone(t),id:D("room"),points:tl(t.points.map(([e,n])=>[e+.5,n+.5]))}}function hf(t,e){let n=t.rooms.find(r=>r.id===e);t.rooms=t.rooms.filter(r=>r.id!==e),t.openings=t.openings.filter(r=>r.room_id!==e||r.wall),n&&(t.placements=t.placements.filter(r=>!N([r.x,r.z],n.points)))}function pf(t,e,n){let r=t.rooms.find(s=>s.id===e);if(!r||r.points.length<=3)return!1;let o=(n-1+r.points.length)%r.points.length;r.points.splice(n,1),r.wall_heights?.splice(n,1),r.wall_slopes?.splice(n,1),r.wall_thickness?.splice(n,1);let i=s=>s.room_id===e&&!s.wall;return t.openings=t.openings.filter(s=>!(i(s)&&(s.edge===n||s.edge===o))).map(s=>i(s)&&s.edge>n?{...s,edge:s.edge-1}:s),!0}function ff(t,e,n){if(!Number.isFinite(n))return null;let r=de(t.points),{x0:o,z0:i,x1:s,z1:l}=r;return e==="x"?[o,s]=[n,n+(s-o)]:e==="z"?[i,l]=[n,n+(l-i)]:n>.05&&(e==="w"?s=o+n:l=i+n),tl([[o,i],[s,i],[s,l],[o,l]])}function mf(t,e,n,r){return!Number.isFinite(r)||e<0||e>=t.points.length?null:t.points.map((o,i)=>i===e?n===0?[Fe(r),o[1]]:[o[0],Fe(r)]:[o[0],o[1]])}var X0=/^(Raum|Room) \d+$/;function nl(t,e,n){let r=e?n[e]:void 0,o=!t.name||X0.test(t.name)||Object.values(n).some(i=>i.name===t.name);return{area_id:e||null,...r&&o?{name:r.name}:{}}}function gf(t,e){let n=e.filter(a=>X(a.entity_id)==="light"&&(a.mount??"ceiling")==="ceiling"&&N([a.x,a.z],t.points));if(n.length<2)return[];let r=de(t.points),[o,i]=[r.x1-r.x0,r.z1-r.z0],s=Math.max(1,Math.round(Math.sqrt(n.length*o/Math.max(.1,i)))),l=Math.ceil(n.length/s);return n.map((a,c)=>{let d=Math.floor(c/s),u=d===l-1?n.length-s*(l-1):s,p=c-d*s;return{entityId:a.entity_id,x:Fe(r.x0+o/u*(p+.5)),z:Fe(r.z0+i/l*(d+.5))}})}function rl(t,e,n,r){let o=t.rooms.find(d=>d.id===e);if(!o)return;let i=o.points[n],s=o.points[(n+1)%o.points.length];o.points.splice(n+1,0,r);let[l,a]=[o.wall_heights?.[n],o.wall_slopes?.[n]];if(typeof l=="number"&&typeof a=="number"&&o.wall_slopes){let d=Math.hypot(s[0]-i[0],s[1]-i[1]),u=Fe(l+(a-l)*Math.min(1,Math.hypot(r[0]-i[0],r[1]-i[1])/(d||1)));o.wall_slopes.splice(n,1,u,a),o.wall_heights.splice(n+1,0,u)}else o.wall_heights?.splice(n+1,0,o.wall_heights[n]??null),o.wall_slopes?.splice(n+1,0,null);o.wall_thickness?.splice(n+1,0,o.wall_thickness[n]??null);let c=Math.hypot(r[0]-i[0],r[1]-i[1]);for(let d of t.openings)d.room_id!==e||d.wall||(d.edge>n?d.edge+=1:d.edge===n&&d.offset>c&&(d.edge=n+1,d.offset=Fe(d.offset-c)))}var Q0=22.5;function _f(t,e,n){let r=Math.min(Math.abs(e),t*2),o=t*(1+8/3*(r/Math.max(1e-6,t))**2),i=4*Math.atan(2*r/Math.max(1e-6,t))*180/Math.PI,s=Math.max(2,Math.ceil(i/Q0));if(n<=0)return 24;let l=Math.floor(o/(n+.1));return l>=s?l:0}function J0(t,e,n,r){let o=Ja(n);t.forEach((i,s)=>{let{piece:l,offset:a}=el(n,e[s]*o),c=Math.hypot(n[l+1][0]-n[l][0],n[l+1][1]-n[l][1]);i.edge=r+l,i.offset=Fe(c>i.width?Math.min(c-i.width/2,Math.max(i.width/2,a)):c/2)})}function bf(t,e,n,r){let o=t.rooms.find(v=>v.id===e);if(!o||n<0||n>=o.points.length||Math.abs(r)<.01)return!1;let i=o.points[n],s=o.points[(n+1)%o.points.length],l=Math.hypot(s[0]-i[0],s[1]-i[1]);if(l<.2)return!1;let[a,c]=[(s[0]-i[0])/l,(s[1]-i[1])/l],d=[(i[0]+s[0])/2+c*.02,(i[1]+s[1])/2-a*.02],p=N(d,o.points)?-r:r,h=(v,w)=>t.openings.filter(x=>x.room_id===v.id&&!x.wall&&x.edge===w),f=t.rooms.flatMap(v=>v.points.map((w,x)=>{let k=v.points[(x+1)%v.points.length],$=(A,F)=>Math.abs(A[0]-F[0])<.001&&Math.abs(A[1]-F[1])<.001;return $(w,i)&&$(k,s)?[v,x,!1]:$(w,s)&&$(k,i)?[v,x,!0]:null}).filter(w=>!!w)),g=Math.max(0,...f.flatMap(([v,w])=>h(v,w).map(x=>x.width))),y=_f(l,r,g);if(!y)return!1;let b=Qa(i,s,p,y).map(([v,w])=>[Fe(v),Fe(w)]);if(!b.length)return!1;for(let[v,w,x]of f){let k=x?[...b].reverse():b,$=h(v,w),A=v.points[w],F=$.map(T=>Math.min(1,Math.max(0,T.offset/l)));for(let T of $)T.edge=-1;k.forEach((T,I)=>rl(t,v.id,w+I,T)),v.wall_splits?.splice(w+1,0,...k.map(()=>null)),v.wall_splits?.[w]&&(v.wall_splits[w]=null),J0($,F,[A,...k,v.points[(w+k.length+1)%v.points.length]],w)}return!0}function yf(t,e,n){let r=t.walls??[],o=r.findIndex(f=>f.id===e);if(o<0||Math.abs(n)<.01)return[];let i=r[o],s=Math.hypot(i.b[0]-i.a[0],i.b[1]-i.a[1]),l=t.openings.filter(f=>f.wall===e),a=Math.max(0,...l.map(f=>f.width)),c=_f(s,n,a);if(!c)return[];let d=Qa(i.a,i.b,n,c).map(([f,g])=>[Fe(f),Fe(g)]);if(!d.length)return[];let u=[i.a,...d,i.b],p=u.slice(1).map((f,g)=>({...i,id:g===0?i.id:D("wall"),a:u[g],b:f}));r.splice(o,1,...p),t.walls=r;let h=Ja(u);for(let f of l){let{piece:g,offset:y}=el(u,f.offset/s*h),b=Math.hypot(u[g+1][0]-u[g][0],u[g+1][1]-u[g][1]);f.wall=p[g].id,f.offset=Fe(b>f.width?Math.min(b-f.width/2,Math.max(f.width/2,y)):b/2)}return p.map(f=>f.id)}var jn=t=>Math.round(t*1e3)/1e3;function Ai(t,e,n){return[Math.round((e[0]-t[0])/n)*n,Math.round((e[1]-t[1])/n)*n]}var fn=(t,e)=>e?.01:t,Un=(t,e,n=5)=>Math.hypot(t[0]-e[0],t[1]-e[1])>=n;function wf(t,e,n){return n?Math.abs(e[0]-t[0])>Math.abs(e[1]-t[1])?[e[0],t[1]]:[t[0],e[1]]:e}var Xe=(t,e)=>[jn(t[0]+e[0]),jn(t[1]+e[1])];function ol(t,e,n,r){return[jn(Math.round((t[0]+n[0]-e[0])/r)*r),jn(Math.round((t[1]+n[1]-e[1])/r)*r)]}function il(t,e,n){let r=Math.atan2(-(e[0]-t[0]),e[1]-t[1])*180/Math.PI;return(Math.round(r/n)*n%360+360)%360}function vf(t,e,n){let r=Math.atan2(e[0]-t[0],-(e[1]-t[1]))*180/Math.PI;return Math.round(r/n)*n}function kf(t,e,n){let r=xn([...t]),o=t[e],i=[jn(n[0]),jn(n[1])];return t.map((s,l)=>l===e?i:r?[Math.abs(s[0]-o[0])<1e-6?i[0]:s[0],Math.abs(s[1]-o[1])<1e-6?i[1]:s[1]]:[s[0],s[1]])}var Fi=t=>Math.round(t*1e3)/1e3,xf=(t,e)=>Math.hypot(t[0]-e[0],t[1]-e[1]);function ew(t,e,n){let r=null,o=n;for(let i of t){let s=xf(i,e);s{let a=i.points[(l+1)%i.points.length],[c,d]=[a[0]-s[0],a[1]-s[1]],u=c*c+d*d;if(u<1e-9)return;let p=((e[0]-s[0])*c+(e[1]-s[1])*d)/u;if(p<=0||p>=1)return;let h=[s[0]+p*c,s[1]+p*d],f=xf(h,e),g=(y,b,v)=>Math.min(Math.max(y,Math.min(b,v)),Math.max(b,v));Math.abs(d)<1e-9&&(h[0]=g(Math.round(h[0]/n.grid)*n.grid,s[0],a[0])),Math.abs(c)<1e-9&&(h[1]=g(Math.round(h[1]/n.grid)*n.grid,s[1],a[1])),fi.points.filter((s,l)=>!(e.skip&&i.id===e.skip.roomId&&(e.skip.index===void 0||e.skip.index===l)))),r=ew(n,t,e.reach);if(r)return{point:[r[0],r[1]],guides:{point:r}};let o=tw(e.rooms,t,e);return o?{point:[Fi(o[0]),Fi(o[1])],guides:{point:o}}:nw(n,t,e)}var Ti=(t,e)=>he(t.host.hass,e);function rw(t,e){let[n,r]=[t.toScreen(e.start),t.toScreen(e.end)];if(e.kind==="freewall"){let s=Math.hypot(e.end[0]-e.start[0],e.end[1]-e.start[1]);return R` ${Ti(t,s)} `}let[o,i]=[Math.abs(e.end[0]-e.start[0]),Math.abs(e.end[1]-e.start[1])];return R` ${Ti(t,o)} × ${Ti(t,i)} - `}function rw(t,e,n,r){let o=[...e,...n?[n]:[]].map(d=>t.toScreen(d)),i=e.length>=3,s=r?e.slice(1).map((d,u)=>{let[p,h]=[t.toScreen(e[u]),t.toScreen(d)];return R`${Ti(t,Math.hypot(d[0]-e[u][0],d[1]-e[u][1]))}`}):_,l=e.map((d,u)=>{let[p,h]=t.toScreen(d),f=u===0&&i;return R``}),[a,c]=n?t.toScreen(n):[0,0];return R` + `}function ow(t,e,n,r){let o=[...e,...n?[n]:[]].map(d=>t.toScreen(d)),i=e.length>=3,s=r?e.slice(1).map((d,u)=>{let[p,h]=[t.toScreen(e[u]),t.toScreen(d)];return R`${Ti(t,Math.hypot(d[0]-e[u][0],d[1]-e[u][1]))}`}):_,l=e.map((d,u)=>{let[p,h]=t.toScreen(d),f=u===0&&i;return R``}),[a,c]=n?t.toScreen(n):[0,0];return R` ${o.length>1?R`d.join(",")).join(" ")} />`:_} ${s}${l} ${n?R``:_} @@ -1246,7 +1246,7 @@ ${i}`}else o=ju(s)}}catch(s){let l=s.message,a={not_json:"import_error_not_json" ${r!==null?R``:_} ${o!==null?R``:_} ${e.point?R``:_} - `}function Mf(t,e,n,r,o){return e?nw(t,e):n!=="polygon"&&n!=="measure"?_:rw(t,r,o,n==="measure")}var ae=(t,e,n,r,o="")=>R``,te=(t,e,n,r,o="")=>R``,Ef=(t,e="")=>R`n.join(",")).join(" ")} />`,oe=(t,e,n,r="")=>R``,sl=(t,e,n,r,o="")=>R``;function al(t,e,n){let r=[];for(let o=1;o1.2?2:1,i=(e-.2)/o,s=[ae(-e/2,-n/2,e/2,-n/2+.07,"nf-sym-fill"),te(-e/2,-n/2+(n-.1)*.36,e/2,-n/2+(n-.1)*.36)];for(let l=0;lEf(a.poly,a.landing?`nf-sym-fill ${i}`:i));o.column>0&&s.push(oe(0,0,o.column,"nf-sym-fill"));let l=o.treads.map(ki);for(let a=1;a=2){let[a,c]=[l[l.length-2],l[l.length-1]],d=Math.hypot(c[0]-a[0],c[1]-a[1])||1,[u,p]=[(c[0]-a[0])/d,(c[1]-a[1])/d],h=Math.min(.2,o.flight*.3);for(let f of[-1,1])s.push(te(c[0],c[1],c[0]-u*h+p*h*.6*f,c[1]-p*h-u*h*.6*f,"nf-sym-strong"))}return s}function iw(t,e,n){return t.symbol?.length?t.symbol.map(r=>r.shape==="rect"?ae((r.x-r.w/2)*e,(r.z-r.d/2)*n,(r.x+r.w/2)*e,(r.z+r.d/2)*n,r.fill?"nf-sym-fill":""):r.shape==="circle"?oe(r.x*e,r.z*n,r.r*Math.min(e,n)):te(r.x1*e,r.z1*n,r.x2*e,r.z2*n)):yc(t,e,n,t.size[2]).filter(r=>r.shape==="sweep"||r.w<.98||r.d<.98).map(r=>r.shape==="sweep"&&r.stations?.length?Ef([...r.stations.map(o=>[(r.x+o[3]/2)*e,o[0]*n]),...[...r.stations].reverse().map(o=>[(r.x-o[3]/2)*e,o[0]*n])]):r.shape==="cyl"&&(r.axis??"y")==="y"?oe(r.x*e,r.z*n,Math.min(r.w*e,r.d*n)/2):ae((r.x-r.w/2)*e,(r.z-r.d/2)*n,(r.x+r.w/2)*e,(r.z+r.d/2)*n))}var ll=Math.PI/180,Tf=(t,e,n,r)=>{let[o,i]=r,s=R``,l=R`${s}`;return t==="data-rotate"?R`${l}`:R`${l}`};function sw(t,e){let n=e.rotation*ll;return[[-1,-1],[1,-1],[1,1],[-1,1]].map(([r,o])=>{let[i,s]=t.toScreen([e.x+r*e.w*Math.cos(n)/2-o*e.d*Math.sin(n)/2,e.z+r*e.w*Math.sin(n)/2+o*e.d*Math.cos(n)/2]);return R``})}var Ff=new WeakMap;function aw(t,e){let n=Ff.get(e);if(n&&n.states===t.states)return n.links;let r=Be(t,[e]);return Ff.set(e,{states:t.states,links:r}),r}function lw(t,e,n){if(!t||!ce(n.type))return!1;let r=aw(t,e).get(n.id)?.entity;return!!fc(r?t.states[r]:void 0,(n.extra_lights??[]).map(o=>t.states[o]))}function zf(t,e,n){let{host:r,scale:o}=t,i=s=>{let l=s.id===n,a=l&&r.admin&&!s.locked,[c,d]=t.toScreen([s.x,s.z]),u=s.rotation*ll,p=Math.min(s.w,s.d)*o>44,h=lw(r.hass,e,s),f=Ce.includes(s.type),g=`nf-furn${l?" nf-furn-sel":""}${h?" nf-furn-lit":""}${f?" nf-energy-item":""}`,y=s.d/2+Math.max(.3,26/o),b=t.toScreen([s.x-Math.sin(u)*y,s.z+Math.cos(u)*y]),v=t.toScreen([s.x-Math.sin(u)*(s.d/2),s.z+Math.cos(u)*(s.d/2)]),[w,x]=t.toScreen([s.x+Math.sin(u)*(s.d/2+18/o),s.z-Math.cos(u)*(s.d/2+18/o)]);return R` + `}function Mf(t,e,n,r,o){return e?rw(t,e):n!=="polygon"&&n!=="measure"?_:ow(t,r,o,n==="measure")}var ae=(t,e,n,r,o="")=>R``,te=(t,e,n,r,o="")=>R``,Ef=(t,e="")=>R`n.join(",")).join(" ")} />`,oe=(t,e,n,r="")=>R``,sl=(t,e,n,r,o="")=>R``;function al(t,e,n){let r=[];for(let o=1;o1.2?2:1,i=(e-.2)/o,s=[ae(-e/2,-n/2,e/2,-n/2+.07,"nf-sym-fill"),te(-e/2,-n/2+(n-.1)*.36,e/2,-n/2+(n-.1)*.36)];for(let l=0;lEf(a.poly,a.landing?`nf-sym-fill ${i}`:i));o.column>0&&s.push(oe(0,0,o.column,"nf-sym-fill"));let l=o.treads.map(ki);for(let a=1;a=2){let[a,c]=[l[l.length-2],l[l.length-1]],d=Math.hypot(c[0]-a[0],c[1]-a[1])||1,[u,p]=[(c[0]-a[0])/d,(c[1]-a[1])/d],h=Math.min(.2,o.flight*.3);for(let f of[-1,1])s.push(te(c[0],c[1],c[0]-u*h+p*h*.6*f,c[1]-p*h-u*h*.6*f,"nf-sym-strong"))}return s}function sw(t,e,n){return t.symbol?.length?t.symbol.map(r=>r.shape==="rect"?ae((r.x-r.w/2)*e,(r.z-r.d/2)*n,(r.x+r.w/2)*e,(r.z+r.d/2)*n,r.fill?"nf-sym-fill":""):r.shape==="circle"?oe(r.x*e,r.z*n,r.r*Math.min(e,n)):te(r.x1*e,r.z1*n,r.x2*e,r.z2*n)):yc(t,e,n,t.size[2]).filter(r=>r.shape==="sweep"||r.w<.98||r.d<.98).map(r=>r.shape==="sweep"&&r.stations?.length?Ef([...r.stations.map(o=>[(r.x+o[3]/2)*e,o[0]*n]),...[...r.stations].reverse().map(o=>[(r.x-o[3]/2)*e,o[0]*n])]):r.shape==="cyl"&&(r.axis??"y")==="y"?oe(r.x*e,r.z*n,Math.min(r.w*e,r.d*n)/2):ae((r.x-r.w/2)*e,(r.z-r.d/2)*n,(r.x+r.w/2)*e,(r.z+r.d/2)*n))}var ll=Math.PI/180,Tf=(t,e,n,r)=>{let[o,i]=r,s=R``,l=R`${s}`;return t==="data-rotate"?R`${l}`:R`${l}`};function aw(t,e){let n=e.rotation*ll;return[[-1,-1],[1,-1],[1,1],[-1,1]].map(([r,o])=>{let[i,s]=t.toScreen([e.x+r*e.w*Math.cos(n)/2-o*e.d*Math.sin(n)/2,e.z+r*e.w*Math.sin(n)/2+o*e.d*Math.cos(n)/2]);return R``})}var Ff=new WeakMap;function lw(t,e){let n=Ff.get(e);if(n&&n.states===t.states)return n.links;let r=Be(t,[e]);return Ff.set(e,{states:t.states,links:r}),r}function cw(t,e,n){if(!t||!ce(n.type))return!1;let r=lw(t,e).get(n.id)?.entity;return!!fc(r?t.states[r]:void 0,(n.extra_lights??[]).map(o=>t.states[o]))}function zf(t,e,n){let{host:r,scale:o}=t,i=s=>{let l=s.id===n,a=l&&r.admin&&!s.locked,[c,d]=t.toScreen([s.x,s.z]),u=s.rotation*ll,p=Math.min(s.w,s.d)*o>44,h=cw(r.hass,e,s),f=Ce.includes(s.type),g=`nf-furn${l?" nf-furn-sel":""}${h?" nf-furn-lit":""}${f?" nf-energy-item":""}`,y=s.d/2+Math.max(.3,26/o),b=t.toScreen([s.x-Math.sin(u)*y,s.z+Math.cos(u)*y]),v=t.toScreen([s.x-Math.sin(u)*(s.d/2),s.z+Math.cos(u)*(s.d/2)]),[w,x]=t.toScreen([s.x+Math.sin(u)*(s.d/2+18/o),s.z-Math.cos(u)*(s.d/2+18/o)]);return R` ${Af(s.type,s.w,s.d,s)} @@ -1254,8 +1254,8 @@ ${i}`}else o=ju(s)}}catch(s){let l=s.message,a={not_json:"import_error_not_json" ${p?R`${qe(r.hass,s.type)}`:_} - ${a?sw(t,s):_} - ${l?R`${pe(r.hass,s.w)} × ${pe(r.hass,s.d)}`:_} + ${a?aw(t,s):_} + ${l?R`${he(r.hass,s.w)} × ${he(r.hass,s.d)}`:_} ${l&&s.locked?R`🔒`:_} ${a?Tf("data-rotate",s.id,v,b):_}`};return R`${vp(e).map(i)}`}function Pf(t,e,n){let{host:r}=t,o=i=>{let s=X(i.entity_id)??(r.hass?Ne(r.hass,i.entity_id):null);if(!s)return _;let[l,a]=t.toScreen([i.x,i.z]),c=r.hass?.states[i.entity_id]?.state==="on",d=i.entity_id===n,u=(i.rotation??0)*ll,p=d&&r.admin&&!i.locked&&ld(i.entity_id,r.hass?.states[i.entity_id]),h=[l-Math.sin(u)*46,a+Math.cos(u)*46],f=Cn(r,i.entity_id,i.icon);return R`${p?Tf("data-aim",i.entity_id,[l,a],h):_} ${W(r.hass,i.entity_id)} @@ -1278,8 +1278,8 @@ ${i}`}else o=ju(s)}}catch(s){let l=s.message,a={not_json:"import_error_not_json" - ${c?R`${zi(s[0],s[1])}${zi(l[0],l[1])}`:_}`};return R`${(e.walls??[]).map(o)}`}function Vf(t,e){let n=e.points,r=(e.wall_splits??[]).flatMap((o,i)=>{if(!o||i>=n.length)return[];let[s,l]=[n[i],n[(i+1)%n.length]],a=Math.hypot(l[0]-s[0],l[1]-s[1])||1,[c,d]=[(l[0]-s[0])/a,(l[1]-s[1])/a];return o.map(u=>{let[p,h]=t.toScreen([s[0]+c*u,s[1]+d*u]);return R``})});return R`${r}`}function Kf(t,e,n){let r=e.points,[o,i]=t.toScreen(_e(r)),s=(a,c,d)=>{let[[u,p],[h,f]]=[t.toScreen(a),t.toScreen(c)],[g,y]=[(u+h)/2,(p+f)/2],b=Math.hypot(h-u,f-p),[v,w]=[-(f-p),h-u],x=Math.hypot(v,w)||1;return[v,w]=[v/x,w/x],v*(g-o)+w*(y-i)<0&&([v,w]=[-v,-w]),R`${b>50?R`${pe(t.host.hass,Math.hypot(c[0]-a[0],c[1]-a[1]))}`:_} - ${b>36?R``:_}`},l=(a,c)=>{let[d,u]=t.toScreen(a);return R`${zi(d,u)}${c+1}`};return R`${r.map((a,c)=>s(a,r[(c+1)%r.length],c))}${r.map(l)}`}function Gf(t,e){let n=e.rooms.flatMap(r=>{if(r.points.length<3)return[];let[o,i]=_e(r.points);return r.points.map((s,l)=>{let a=r.points[(l+1)%r.points.length],c=Math.hypot(a[0]-s[0],a[1]-s[1]);if(c<.4)return _;let d=[(s[0]+a[0])/2,(s[1]+a[1])/2],u=Math.hypot(o-d[0],i-d[1])||1,p=Math.min(.35,u/2),h=[d[0]+(o-d[0])/u*p,d[1]+(i-d[1])/u*p],[f,g]=t.toScreen(h),y=Math.atan2(a[1]-s[1],a[0]-s[0])*180/Math.PI;return y>90&&(y-=180),y<-90&&(y+=180),R`${pe(t.host.hass,c)}`})});return R`${n}`}function jf(t,e,n){let r=t.t;return m`
+ ${c?R`${zi(s[0],s[1])}${zi(l[0],l[1])}`:_}`};return R`${(e.walls??[]).map(o)}`}function Vf(t,e){let n=e.points,r=(e.wall_splits??[]).flatMap((o,i)=>{if(!o||i>=n.length)return[];let[s,l]=[n[i],n[(i+1)%n.length]],a=Math.hypot(l[0]-s[0],l[1]-s[1])||1,[c,d]=[(l[0]-s[0])/a,(l[1]-s[1])/a];return o.map(u=>{let[p,h]=t.toScreen([s[0]+c*u,s[1]+d*u]);return R``})});return R`${r}`}function Kf(t,e,n){let r=e.points,[o,i]=t.toScreen(_e(r)),s=(a,c,d)=>{let[[u,p],[h,f]]=[t.toScreen(a),t.toScreen(c)],[g,y]=[(u+h)/2,(p+f)/2],b=Math.hypot(h-u,f-p),[v,w]=[-(f-p),h-u],x=Math.hypot(v,w)||1;return[v,w]=[v/x,w/x],v*(g-o)+w*(y-i)<0&&([v,w]=[-v,-w]),R`${b>50?R`${he(t.host.hass,Math.hypot(c[0]-a[0],c[1]-a[1]))}`:_} + ${b>36?R``:_}`},l=(a,c)=>{let[d,u]=t.toScreen(a);return R`${zi(d,u)}${c+1}`};return R`${r.map((a,c)=>s(a,r[(c+1)%r.length],c))}${r.map(l)}`}function Gf(t,e){let n=e.rooms.flatMap(r=>{if(r.points.length<3)return[];let[o,i]=_e(r.points);return r.points.map((s,l)=>{let a=r.points[(l+1)%r.points.length],c=Math.hypot(a[0]-s[0],a[1]-s[1]);if(c<.4)return _;let d=[(s[0]+a[0])/2,(s[1]+a[1])/2],u=Math.hypot(o-d[0],i-d[1])||1,p=Math.min(.35,u/2),h=[d[0]+(o-d[0])/u*p,d[1]+(i-d[1])/u*p],[f,g]=t.toScreen(h),y=Math.atan2(a[1]-s[1],a[0]-s[0])*180/Math.PI;return y>90&&(y-=180),y<-90&&(y+=180),R`${he(t.host.hass,c)}`})});return R`${n}`}function jf(t,e,n){let r=t.t;return m`

✎ ${r("note")}

${Y(m``)} -
`}function cw(t,e,n){let r=t.t,o=!!e.photo?.startsWith("image:"),i=async s=>{let l=s.target,a=l.files?.[0];if(l.value="",!a||!t.hass)return;let{data:c}=await Gn(a),d=D("img");await St(t.hass,d,c),n.patch({photo:`image:${d}`})};return m`${t.admin?m``:_} +
`}function dw(t,e,n){let r=t.t,o=!!e.photo?.startsWith("image:"),i=async s=>{let l=s.target,a=l.files?.[0];if(l.value="",!a||!t.hass)return;let{data:c}=await Gn(a),d=D("img");await St(t.hass,d,c),n.patch({photo:`image:${d}`})};return m`${t.admin?m``:_} ${o?m`

${r("picture_stored")}

`:Z(t,r("picture_url"),e.photo??"",s=>n.patch({photo:s.trim()||null}),{wide:!0,placeholder:"/local/valve.jpg"})} - ${M(r("note_photo_hint"),"nf-wide")}`}function dw(t,e,n,r){let o=Ie(e,n.rooms,n.walls??[]);if(!o)return null;let{room:i,edge:s}=o,l=zt(r,e,o),a=An(i,s,e.offset-e.width/2),c=An(i,s,e.offset+e.width/2),d=[(c[0]-a[0])/(e.width||1),(c[1]-a[1])/(e.width||1)],u=ge(i.points)>=0?1:-1,p=[-d[1]*u,d[0]*u],h=[.06,.06];return l&&(h=l.wall.free||l.wall.roomLeft===i.id?[l.wall.left,l.wall.right]:[l.wall.right,l.wall.left]),{room:i,edge:s,p0:a,p1:c,inward:p,direction:u,across:h,exterior:l?.wall.exterior??!1,at:(f,g)=>t.toScreen([f[0]+p[0]*g,f[1]+p[1]*g])}}var wt=(t,e,n="")=>R``;function uw(t,e){let n=t.across[0]-.04,r=t.across[0]+Math.min(2,e.height),[o,i,s,l]=[t.at(t.p0,n),t.at(t.p1,n),t.at(t.p0,r),t.at(t.p1,r)];return R`${wt(o,i)}`}function hw(t,e,n){let r=n.swing==="out",o=r?-e.across[1]:e.across[0],i=(e.across[0]-e.across[1])/2,s=n.hinge==="left"==e.direction>0,l=qt(n,e.exterior),a=n.leaves===2,[c,d]=[e.p0,e.p1],u=[],p=ed(n.width,l,s,n);if(p){let v=w=>w<=.02?e.p0:w>=n.width-.02?e.p1:An(e.room,e.edge,n.offset-n.width/2+w);[c,d]=[v(p.x0),v(p.x1)],u=p.panels.map(([w,x])=>[v(w),v(x)])}let h=[(c[0]+d[0])/2,(c[1]+d[1])/2],f=(a?.5:1)*Math.hypot(d[0]-c[0],d[1]-c[1]),g=u.map(([v,w])=>R`${wt(e.at(v,i+.035),e.at(w,i+.035),"nf-open-pane")}${wt(e.at(v,i-.035),e.at(w,i-.035),"nf-open-pane")}`),y=(v,w)=>{let[x,k]=e.at(v,o),[$,A]=e.at(w,o),F=e.at(v,o+(r?-f:f)),T=f*t.scale,I=(F[0]-x)*(A-k)-(F[1]-k)*($-x)>0?1:0;return R``},b;return l==="passage"?b=wt(e.at(e.p0,i),e.at(e.p1,i),"nf-open-passage"):l==="sliding"?b=wt(e.at(c,o),e.at(d,o)):a?b=R`${y(c,h)}${y(d,h)}`:b=s?y(c,d):y(d,c),R`${g}${b}`}function pw(t,e){let n=(t.across[0]-t.across[1])/2;if(e.opens==="slide"){let o=e.leaves===2?4:2,i=l=>[t.p0[0]+(t.p1[0]-t.p0[0])*l,t.p0[1]+(t.p1[1]-t.p0[1])*l],s=Array.from({length:o},(l,a)=>{let c=e.leaves===2?a===1||a===2?.035:-.035:a===0?.035:-.035;return wt(t.at(i(Math.max(0,a/o-.03)),n+c),t.at(i(Math.min(1,(a+1)/o+.03)),n+c))});return R`${s}`}let r=e.leaves===2?wt(t.at([(t.p0[0]+t.p1[0])/2,(t.p0[1]+t.p1[1])/2],t.across[0]),t.at([(t.p0[0]+t.p1[0])/2,(t.p0[1]+t.p1[1])/2],-t.across[1])):_;return R`${wt(t.at(t.p0,n+.035),t.at(t.p1,n+.035))}${wt(t.at(t.p0,n-.035),t.at(t.p1,n-.035))}${r}`}function Uf(t,e,n,r){let o=e.openings.find(s=>s.id===r)?.front??null,i=s=>{let l=dw(t,s,e,n);if(!l)return _;let a=[l.at(l.p0,l.across[0]+.01),l.at(l.p1,l.across[0]+.01),l.at(l.p1,-l.across[1]-.01),l.at(l.p0,-l.across[1]-.01)],c=s.type==="door"&&_s(qt(s,l.exterior)),d=s.id===r||!!s.front&&s.front===o,u=`nf-open nf-open-${s.type}${c?" nf-open-front":""}${d?" nf-open-sel":""}`,p=s.type==="garage"?uw(l,s):s.type==="door"?hw(t,l,s):pw(l,s);return R`h.join(",")).join(" ")} />${p}`};return R`${e.openings.map(i)}`}var Zf=t=>Math.round(t*1e3)/1e3,qf=t=>Math.round(t*100)/100;function Zn(t,e){let n=[...t??[]].slice(0,e);for(;n.lengtht.every(e=>e===null);function co(t,e){let[n,r]=[t.points[e],t.points[(e+1)%t.points.length]];return Math.hypot(r[0]-n[0],r[1]-n[1])}function cl(t,e,n){let r=Zn(t.wall_heights,t.points.length);r[e]=n,t.wall_heights=Pi(r)?void 0:r,Ii(t,e,null)}function Ii(t,e,n){if(n===null&&!t.wall_slopes)return;let r=Zn(t.wall_slopes,t.points.length);r[e]=n,t.wall_slopes=Pi(r)?void 0:r}function Yf(t,e,n,r){let[o,i]=[n,r].map(l=>Math.min(30,Math.max(.05,Zf(l)))),s=Zn(t.wall_heights,t.points.length);s[e]=o,t.wall_heights=s,Ii(t,e,i)}function Xf(t,e,n){let r=t.wall_heights?.[e];Ii(t,e,null),typeof r=="number"&&r>=n-.005&&cl(t,e,null)}function Qf(t,e,n,r,o){let i=Zn(t.wall_heights,t.points.length),s=i[e],l=Array.isArray(s)?[...s]:new Array(o).fill(typeof s=="number"?s:null);for(;l.lengtha===l[0])?l[0]:l,t.wall_heights=Pi(i)?void 0:i,Ii(t,e,null)}function Jf(t,e,n,r){let o=co(t,e),i=n===void 0?0:r[n],s=n===void 0?o:r[n+1]??o;if(s-i<.4)return!1;let l=qf((i+s)/2),a=Zn(t.wall_splits,t.points.length);a[e]=[...a[e]??[],l].sort((d,u)=>d-u),t.wall_splits=a;let c=t.wall_heights?.[e];return Array.isArray(c)&&c.splice((n??0)+1,0,c[n??0]??null),!0}function em(t,e,n,r,o){let i=co(t,e),s=o.filter(d=>Math.abs(d-n)>.001&&d>0),l=Math.max(.1,Math.min(i-.1,qf(r)));s.some(d=>Math.abs(d-l)<.1)&&(l=n);let a=t.wall_splits?.[e];if(!a)return;let c=a.findIndex(d=>Math.abs(d-n)<.001);c>=0&&(a[c]=l),a.sort((d,u)=>d-u)}function tm(t,e,n,r){let o=t.wall_splits;if(!o?.[e])return;let i=o[e].filter(l=>Math.abs(l-n)>.001);o[e]=i.length>0?i:null,o.every(l=>!l)&&(t.wall_splits=void 0);let s=t.wall_heights?.[e];Array.isArray(s)&&(s.splice(r,1),s.every(l=>l===s[0])&&(t.wall_heights[e]=s[0]??null))}function nm(t,e,n,r,o=1){let i=Zn(t.wall_thickness,t.points.length);if(r===void 0||o<2)i[e]=n;else{let s=i[e],l=Array.isArray(s)?[...s]:new Array(o).fill(typeof s=="number"?s:null);for(;l.lengtha===l[0])?l[0]:l}t.wall_thickness=Pi(i)?void 0:i}function rm(t,e){let n=Math.min(1.5,Math.max(.02,Zf(t)));return Math.abs(n-e)<5e-4?null:n}var om=.005,im=(t,e)=>`room:${t.id}:${e}`;function sm(t,e,n){let r=t.t,o=e.ceiling??t.floor.height,i=e.points.length,{wall_exterior:s,wall_interior:l}=t.doc.settings,a=c=>{let d=e.wall_heights?.[c]??null,u=n.partsOf(e,c);return(u.length>1?u.map((h,f)=>f):[void 0]).map(h=>{let f=Array.isArray(d)?d[h??0]??null:d,g=e.wall_thickness?.[c]??null,y=Array.isArray(g)?g[h??0]??null:g,b=h===void 0?co(e,c):(u[h+1]??co(e,c))-u[h],v=z=>n.setHeight(e,c,h,z),w=n.isOuter(e,c)?s:l,x=`${r("wall_n",{a:c+1,b:(c+1)%i+1})}${h===void 0?"":` \xB7 ${r("wall_part",{n:h+1})}`}`,k=h!==void 0&&h>0&&(e.wall_splits?.[c]??[]).some(z=>Math.abs(z-u[h])<.001),$=e.wall_slopes?.[c],A=h===void 0&&typeof $=="number"&&typeof d=="number",F=f??o,T=()=>n.light(c),I=()=>n.light(null);return m`
- ${x}
${pe(t.hass,b)}
+ ${M(r("note_photo_hint"),"nf-wide")}`}function uw(t,e,n,r){let o=Ie(e,n.rooms,n.walls??[]);if(!o)return null;let{room:i,edge:s}=o,l=zt(r,e,o),a=An(i,s,e.offset-e.width/2),c=An(i,s,e.offset+e.width/2),d=[(c[0]-a[0])/(e.width||1),(c[1]-a[1])/(e.width||1)],u=ge(i.points)>=0?1:-1,p=[-d[1]*u,d[0]*u],h=[.06,.06];return l&&(h=l.wall.free||l.wall.roomLeft===i.id?[l.wall.left,l.wall.right]:[l.wall.right,l.wall.left]),{room:i,edge:s,p0:a,p1:c,inward:p,direction:u,across:h,exterior:l?.wall.exterior??!1,at:(f,g)=>t.toScreen([f[0]+p[0]*g,f[1]+p[1]*g])}}var wt=(t,e,n="")=>R``;function hw(t,e){let n=t.across[0]-.04,r=t.across[0]+Math.min(2,e.height),[o,i,s,l]=[t.at(t.p0,n),t.at(t.p1,n),t.at(t.p0,r),t.at(t.p1,r)];return R`${wt(o,i)}`}function pw(t,e,n){let r=n.swing==="out",o=r?-e.across[1]:e.across[0],i=(e.across[0]-e.across[1])/2,s=n.hinge==="left"==e.direction>0,l=qt(n,e.exterior),a=n.leaves===2,[c,d]=[e.p0,e.p1],u=[],p=ed(n.width,l,s,n);if(p){let v=w=>w<=.02?e.p0:w>=n.width-.02?e.p1:An(e.room,e.edge,n.offset-n.width/2+w);[c,d]=[v(p.x0),v(p.x1)],u=p.panels.map(([w,x])=>[v(w),v(x)])}let h=[(c[0]+d[0])/2,(c[1]+d[1])/2],f=(a?.5:1)*Math.hypot(d[0]-c[0],d[1]-c[1]),g=u.map(([v,w])=>R`${wt(e.at(v,i+.035),e.at(w,i+.035),"nf-open-pane")}${wt(e.at(v,i-.035),e.at(w,i-.035),"nf-open-pane")}`),y=(v,w)=>{let[x,k]=e.at(v,o),[$,A]=e.at(w,o),F=e.at(v,o+(r?-f:f)),T=f*t.scale,I=(F[0]-x)*(A-k)-(F[1]-k)*($-x)>0?1:0;return R``},b;return l==="passage"?b=wt(e.at(e.p0,i),e.at(e.p1,i),"nf-open-passage"):l==="sliding"?b=wt(e.at(c,o),e.at(d,o)):a?b=R`${y(c,h)}${y(d,h)}`:b=s?y(c,d):y(d,c),R`${g}${b}`}function fw(t,e){let n=(t.across[0]-t.across[1])/2;if(e.opens==="slide"){let o=e.leaves===2?4:2,i=l=>[t.p0[0]+(t.p1[0]-t.p0[0])*l,t.p0[1]+(t.p1[1]-t.p0[1])*l],s=Array.from({length:o},(l,a)=>{let c=e.leaves===2?a===1||a===2?.035:-.035:a===0?.035:-.035;return wt(t.at(i(Math.max(0,a/o-.03)),n+c),t.at(i(Math.min(1,(a+1)/o+.03)),n+c))});return R`${s}`}let r=e.leaves===2?wt(t.at([(t.p0[0]+t.p1[0])/2,(t.p0[1]+t.p1[1])/2],t.across[0]),t.at([(t.p0[0]+t.p1[0])/2,(t.p0[1]+t.p1[1])/2],-t.across[1])):_;return R`${wt(t.at(t.p0,n+.035),t.at(t.p1,n+.035))}${wt(t.at(t.p0,n-.035),t.at(t.p1,n-.035))}${r}`}function Uf(t,e,n,r){let o=e.openings.find(s=>s.id===r)?.front??null,i=s=>{let l=uw(t,s,e,n);if(!l)return _;let a=[l.at(l.p0,l.across[0]+.01),l.at(l.p1,l.across[0]+.01),l.at(l.p1,-l.across[1]-.01),l.at(l.p0,-l.across[1]-.01)],c=s.type==="door"&&_s(qt(s,l.exterior)),d=s.id===r||!!s.front&&s.front===o,u=`nf-open nf-open-${s.type}${c?" nf-open-front":""}${d?" nf-open-sel":""}`,p=s.type==="garage"?hw(l,s):s.type==="door"?pw(t,l,s):fw(l,s);return R`h.join(",")).join(" ")} />${p}`};return R`${e.openings.map(i)}`}var Zf=t=>Math.round(t*1e3)/1e3,qf=t=>Math.round(t*100)/100;function Zn(t,e){let n=[...t??[]].slice(0,e);for(;n.lengtht.every(e=>e===null);function co(t,e){let[n,r]=[t.points[e],t.points[(e+1)%t.points.length]];return Math.hypot(r[0]-n[0],r[1]-n[1])}function cl(t,e,n){let r=Zn(t.wall_heights,t.points.length);r[e]=n,t.wall_heights=Pi(r)?void 0:r,Ii(t,e,null)}function Ii(t,e,n){if(n===null&&!t.wall_slopes)return;let r=Zn(t.wall_slopes,t.points.length);r[e]=n,t.wall_slopes=Pi(r)?void 0:r}function Yf(t,e,n,r){let[o,i]=[n,r].map(l=>Math.min(30,Math.max(.05,Zf(l)))),s=Zn(t.wall_heights,t.points.length);s[e]=o,t.wall_heights=s,Ii(t,e,i)}function Xf(t,e,n){let r=t.wall_heights?.[e];Ii(t,e,null),typeof r=="number"&&r>=n-.005&&cl(t,e,null)}function Qf(t,e,n,r,o){let i=Zn(t.wall_heights,t.points.length),s=i[e],l=Array.isArray(s)?[...s]:new Array(o).fill(typeof s=="number"?s:null);for(;l.lengtha===l[0])?l[0]:l,t.wall_heights=Pi(i)?void 0:i,Ii(t,e,null)}function Jf(t,e,n,r){let o=co(t,e),i=n===void 0?0:r[n],s=n===void 0?o:r[n+1]??o;if(s-i<.4)return!1;let l=qf((i+s)/2),a=Zn(t.wall_splits,t.points.length);a[e]=[...a[e]??[],l].sort((d,u)=>d-u),t.wall_splits=a;let c=t.wall_heights?.[e];return Array.isArray(c)&&c.splice((n??0)+1,0,c[n??0]??null),!0}function em(t,e,n,r,o){let i=co(t,e),s=o.filter(d=>Math.abs(d-n)>.001&&d>0),l=Math.max(.1,Math.min(i-.1,qf(r)));s.some(d=>Math.abs(d-l)<.1)&&(l=n);let a=t.wall_splits?.[e];if(!a)return;let c=a.findIndex(d=>Math.abs(d-n)<.001);c>=0&&(a[c]=l),a.sort((d,u)=>d-u)}function tm(t,e,n,r){let o=t.wall_splits;if(!o?.[e])return;let i=o[e].filter(l=>Math.abs(l-n)>.001);o[e]=i.length>0?i:null,o.every(l=>!l)&&(t.wall_splits=void 0);let s=t.wall_heights?.[e];Array.isArray(s)&&(s.splice(r,1),s.every(l=>l===s[0])&&(t.wall_heights[e]=s[0]??null))}function nm(t,e,n,r,o=1){let i=Zn(t.wall_thickness,t.points.length);if(r===void 0||o<2)i[e]=n;else{let s=i[e],l=Array.isArray(s)?[...s]:new Array(o).fill(typeof s=="number"?s:null);for(;l.lengtha===l[0])?l[0]:l}t.wall_thickness=Pi(i)?void 0:i}function rm(t,e){let n=Math.min(1.5,Math.max(.02,Zf(t)));return Math.abs(n-e)<5e-4?null:n}var om=.005,im=(t,e)=>`room:${t.id}:${e}`;function sm(t,e,n){let r=t.t,o=e.ceiling??t.floor.height,i=e.points.length,{wall_exterior:s,wall_interior:l}=t.doc.settings,a=c=>{let d=e.wall_heights?.[c]??null,u=n.partsOf(e,c);return(u.length>1?u.map((h,f)=>f):[void 0]).map(h=>{let f=Array.isArray(d)?d[h??0]??null:d,g=e.wall_thickness?.[c]??null,y=Array.isArray(g)?g[h??0]??null:g,b=h===void 0?co(e,c):(u[h+1]??co(e,c))-u[h],v=z=>n.setHeight(e,c,h,z),w=n.isOuter(e,c)?s:l,x=`${r("wall_n",{a:c+1,b:(c+1)%i+1})}${h===void 0?"":` \xB7 ${r("wall_part",{n:h+1})}`}`,k=h!==void 0&&h>0&&(e.wall_splits?.[c]??[]).some(z=>Math.abs(z-u[h])<.001),$=e.wall_slopes?.[c],A=h===void 0&&typeof $=="number"&&typeof d=="number",F=f??o,T=()=>n.light(c),I=()=>n.light(null);return m`
+ ${x}
${he(t.hass,b)}
${f===0?m`${r("wall_none")}`:A?m`${E(t,r("wall_slope_start"),d,z=>n.setSlope(e,c,z,$),.05,.05)} ${E(t,r("wall_slope_end"),$,z=>n.setSlope(e,c,d,z),.05,.05)}${E(t,r("wall_split_at"),u[h],z=>n.moveCut(e,c,u[h],z),.05,.1)} ${t.admin?m``:_}`:_} -
`})};return m`
-

${r("wall_heights")}

+
`})};return m`
+ ${r("wall_heights")} ${e.points.flatMap((c,d)=>a(d))} ${M(r("room_wall_hint"))} -
`}function am(t,e,n){let r=e.color_entity&&e.color_entity!=="none"?e.color_entity:n;return r?t.states[r]:void 0}var dl=["none","rainbow","pulse","flicker"];function Di(t,e,n,r){let o=e.effect_animations??{},i=od(),s=c=>dl.includes(c)||i.includes(c),l=[...new Set([...Object.keys(o),...Array.isArray(n)?n.filter(c=>typeof c=="string"):[]])],a=(c,d,u,p=!1)=>{let h=Object.prototype.hasOwnProperty.call(o,c),f=Array.from(c).length,g=p&&h?"light_effect_exists":d!==""&&(f<1||f>255)?"light_effect_name_limit":d!==""&&!h&&Object.keys(o).length>=100?"light_effect_count_limit":void 0;if(u.setCustomValidity?.(g?t.t(g):""),g){let b=u.closest?.("details")?.querySelector("[data-effect-feedback]");return b&&(b.textContent=t.t(g)),u.reportValidity?.(),p||(u.value=h?o[c]:""),!1}let y={...o};return d===""?delete y[c]:Object.defineProperty(y,c,{value:d,enumerable:!0,configurable:!0,writable:!0}),r({effect_animations:y}),!0};return m`
+
`}function am(t,e,n){let r=e.color_entity&&e.color_entity!=="none"?e.color_entity:n;return r?t.states[r]:void 0}var dl=["none","rainbow","pulse","flicker"];function Di(t,e,n,r){let o=e.effect_animations??{},i=od(),s=c=>dl.includes(c)||i.includes(c),l=[...new Set([...Object.keys(o),...Array.isArray(n)?n.filter(c=>typeof c=="string"):[]])],a=(c,d,u,p=!1)=>{let h=Object.prototype.hasOwnProperty.call(o,c),f=Array.from(c).length,g=p&&h?"light_effect_exists":d!==""&&(f<1||f>255)?"light_effect_name_limit":d!==""&&!h&&Object.keys(o).length>=100?"light_effect_count_limit":void 0;if(u.setCustomValidity?.(g?t.t(g):""),g){let b=u.closest?.("details")?.querySelector("[data-effect-feedback]");return b&&(b.textContent=t.t(g)),u.reportValidity?.(),p||(u.value=h?o[c]:""),!1}let y={...o};return d===""?delete y[c]:Object.defineProperty(y,c,{value:d,enumerable:!0,configurable:!0,writable:!0}),r({effect_animations:y}),!0};return m`
${t.t("light_effects")}

${t.t("light_effects_hint")}

${t.t("light_effect_name_limit")} ${t.t("light_effect_count_limit")}

-
`}var fw=/speaker|sound|subwoofer|receiver|smart_|display|tv|media|turntable|projector|console/;function mw(t,e,n){let r=X(e),o=t.hass?.language??"en",i=[...Oo.map(l=>({type:l,label:t.t(`furn_${l}`)})),...n.flatMap(l=>l.items.map(a=>({type:ue(l.id,a.id),label:`${Ye(a,ue(l.id,a.id),o)} \xB7 ${Oe(l,o)}`})))],s=l=>r==="light"?ce(l):r==="climate"?l==="radiator"||yn(l):e.startsWith("vacuum.")?l==="robot_vacuum"||gt(l)&&l.endsWith(":robot_vacuum"):r==="media"?wr(l)||Et(l)&&fw.test(l):Et(l)&&!ce(l);return i.filter(l=>s(l.type)).sort((l,a)=>l.label.localeCompare(a.label))}function gw(t,e,n){if(!t.admin)return _;let r=mw(t,e.entity_id,n.packs);return r.length===0?_:m`
${t.admin?m`
${e.y!==null?m``:_} - ${gw(t,e,n)} + ${_w(t,e,n)}
`:_} - `}var uo=t=>Number(t);function Oi(t){if(Array.isArray(t)){let[i,s]=[uo(t[0]),uo(t[1])];return Number.isFinite(i)&&Number.isFinite(s)?[i,s]:null}if(!t||typeof t!="object")return null;let{x:e,y:n}=t,[r,o]=[uo(e),uo(n)];return Number.isFinite(r)&&Number.isFinite(o)?[r,o]:null}function dm(t){return t?Oi(t.charger)??Oi(t.charger_position):null}function Hi(t){for(let[e,n]of Object.entries(t.states))if(e.startsWith("camera.")&&(Oi(n.attributes?.vacuum_position)??dm(n.attributes)))return e;return null}var hl=(t,e)=>e?[t[0],-t[1]]:t;var um=5e-4,hm=2,bw=1.5;function pl(t,e){let n=e?t.states[e]?.attributes:void 0;return{at:n?Oi(n.vacuum_position):null,dock:dm(n)}}function pm(t,e,n=!1){let r=Math.hypot(e.plan[0]-t.plan[0],e.plan[1]-t.plan[1]),o=Math.hypot(e.grid[0]-t.grid[0],e.grid[1]-t.grid[1]);if(!(o>1e-6)||!(r>=bw))return{cal:null,reason:"close"};let i=r/o;return i>=um&&i<=hm?{cal:{a:t.plan,ga:t.grid,b:e.plan,gb:e.grid,mirror:n}}:{cal:null,reason:"scale"}}function fm(t,e){let n=e?t.states[e]?.attributes?.rooms:void 0;if(!n||typeof n!="object")return[];let r=[];for(let o of Object.values(n)){if(!o||typeof o!="object")continue;let i=o,s=typeof i.name=="string"?i.name.trim():"",l=[i.x0,i.y0,i.x1,i.y1].map(uo);!s||!l.every(Number.isFinite)||r.push({name:s,center:[(l[0]+l[2])/2,(l[1]+l[3])/2]})}return r}var lm=t=>t.toLocaleLowerCase().normalize("NFKD").replace(/[̀-ͯ]/g,"").replace(/[^\p{L}\p{N}]+/gu,"");function yw(t){let e=t.length,[n,r]=t.reduce((h,f)=>[h[0]+f.seen[0]/e,h[1]+f.seen[1]/e],[0,0]),[o,i]=t.reduce((h,f)=>[h[0]+f.plan[0]/e,h[1]+f.plan[1]/e],[0,0]),[s,l,a]=[0,0,0];for(let h of t){let[f,g]=[h.seen[0]-n,h.seen[1]-r],[y,b]=[h.plan[0]-o,h.plan[1]-i];s+=f*y+g*b,l+=f*b-g*y,a+=f*f+g*g}if(!(a>1e-9))return null;let[c,d]=[s/a,l/a],u=h=>{let[f,g]=[h[0]-n,h[1]-r];return[o+c*f-d*g,i+d*f+c*g]},p=Math.sqrt(t.reduce((h,f)=>h+Math.hypot(u(f.seen)[0]-f.plan[0],u(f.seen)[1]-f.plan[1])**2,0)/e);return{map:u,scale:Math.hypot(c,d),rms:p}}function mm(t,e,n=!1){let r=new Map(e.map(g=>[lm(g.name),g])),o=[],i=new Set;for(let g of t){let y=lm(g.name),b=r.get(y);if(!b||i.has(y)||g.points.length<3)continue;i.add(y);let v=g.points.map(x=>x[0]),w=g.points.map(x=>x[1]);o.push({name:g.name,plan:[(Math.min(...v)+Math.max(...v))/2,(Math.min(...w)+Math.max(...w))/2],grid:b.center})}let s=o.map(g=>g.name);if(o.length<2)return{cal:null,reason:"rooms",matched:s};let a=(o.length>=3?[!1,!0]:[n]).flatMap(g=>{let y=yw(o.map(b=>({plan:b.plan,seen:hl(b.grid,g)})));return y?[{mirror:g,...y}]:[]}).sort((g,y)=>g.rms-y.rms)[0];if(!a)return{cal:null,reason:"rooms",matched:s};if(!(a.scale>=um&&a.scale<=hm))return{cal:null,reason:"scale",matched:s};let c=Math.max(...o.map(g=>Math.hypot(g.plan[0]-o[0].plan[0],g.plan[1]-o[0].plan[1])));if(!(a.rms<=Math.max(1,c/4)))return{cal:null,reason:"fit",matched:s};let[d,u,p]=[0,1,-1];for(let g=0;gp&&([d,u,p]=[g,y,b])}let[h,f]=[o[d].grid,o[u].grid];return{cal:{a:a.map(hl(h,a.mirror)),ga:h,b:a.map(hl(f,a.mirror)),gb:f,mirror:a.mirror},matched:s,rms:a.rms}}function gm(t,e){let[n,r]=[(t.a[0]+t.b[0])/2,(t.a[1]+t.b[1])/2],o=(e.turn??0)*Math.PI/180,[i,s,l]=[Math.cos(o),Math.sin(o),e.grow??1],[a,c]=e.move??[0,0],d=u=>{let[p,h]=[(u[0]-n)*l,(u[1]-r)*l];return[cm(n+p*i-h*s+a),cm(r+p*s+h*i+c)]};return{...t,a:d(t.a),b:d(t.b)}}var cm=t=>Math.round(t*1e3)/1e3;var ww=/^(binary_sensor|switch|input_boolean|light|fan|person|device_tracker|sensor)\./,vt=t=>t==="none"?null:t;function fl(t,e,n){let r=t.t,o=L(t.hass,a=>ww.test(a)),i=!!e.state_entity&&e.state_entity!=="none",s=i&&!!e.state_entity2&&e.state_entity2!=="none",l=[["left_right",r("furn_state_left_right")],["top_bottom",r("furn_state_top_bottom")]];return m`${P(t,r("furn_state_entity"),e.state_entity??null,void 0,o,a=>n.update({state_entity:vt(a)}))} + `}var uo=t=>Number(t);function Oi(t){if(Array.isArray(t)){let[i,s]=[uo(t[0]),uo(t[1])];return Number.isFinite(i)&&Number.isFinite(s)?[i,s]:null}if(!t||typeof t!="object")return null;let{x:e,y:n}=t,[r,o]=[uo(e),uo(n)];return Number.isFinite(r)&&Number.isFinite(o)?[r,o]:null}function dm(t){return t?Oi(t.charger)??Oi(t.charger_position):null}function Hi(t){for(let[e,n]of Object.entries(t.states))if(e.startsWith("camera.")&&(Oi(n.attributes?.vacuum_position)??dm(n.attributes)))return e;return null}var hl=(t,e)=>e?[t[0],-t[1]]:t;var um=5e-4,hm=2,yw=1.5;function pl(t,e){let n=e?t.states[e]?.attributes:void 0;return{at:n?Oi(n.vacuum_position):null,dock:dm(n)}}function pm(t,e,n=!1){let r=Math.hypot(e.plan[0]-t.plan[0],e.plan[1]-t.plan[1]),o=Math.hypot(e.grid[0]-t.grid[0],e.grid[1]-t.grid[1]);if(!(o>1e-6)||!(r>=yw))return{cal:null,reason:"close"};let i=r/o;return i>=um&&i<=hm?{cal:{a:t.plan,ga:t.grid,b:e.plan,gb:e.grid,mirror:n}}:{cal:null,reason:"scale"}}function fm(t,e){let n=e?t.states[e]?.attributes?.rooms:void 0;if(!n||typeof n!="object")return[];let r=[];for(let o of Object.values(n)){if(!o||typeof o!="object")continue;let i=o,s=typeof i.name=="string"?i.name.trim():"",l=[i.x0,i.y0,i.x1,i.y1].map(uo);!s||!l.every(Number.isFinite)||r.push({name:s,center:[(l[0]+l[2])/2,(l[1]+l[3])/2]})}return r}var lm=t=>t.toLocaleLowerCase().normalize("NFKD").replace(/[̀-ͯ]/g,"").replace(/[^\p{L}\p{N}]+/gu,"");function ww(t){let e=t.length,[n,r]=t.reduce((h,f)=>[h[0]+f.seen[0]/e,h[1]+f.seen[1]/e],[0,0]),[o,i]=t.reduce((h,f)=>[h[0]+f.plan[0]/e,h[1]+f.plan[1]/e],[0,0]),[s,l,a]=[0,0,0];for(let h of t){let[f,g]=[h.seen[0]-n,h.seen[1]-r],[y,b]=[h.plan[0]-o,h.plan[1]-i];s+=f*y+g*b,l+=f*b-g*y,a+=f*f+g*g}if(!(a>1e-9))return null;let[c,d]=[s/a,l/a],u=h=>{let[f,g]=[h[0]-n,h[1]-r];return[o+c*f-d*g,i+d*f+c*g]},p=Math.sqrt(t.reduce((h,f)=>h+Math.hypot(u(f.seen)[0]-f.plan[0],u(f.seen)[1]-f.plan[1])**2,0)/e);return{map:u,scale:Math.hypot(c,d),rms:p}}function mm(t,e,n=!1){let r=new Map(e.map(g=>[lm(g.name),g])),o=[],i=new Set;for(let g of t){let y=lm(g.name),b=r.get(y);if(!b||i.has(y)||g.points.length<3)continue;i.add(y);let v=g.points.map(x=>x[0]),w=g.points.map(x=>x[1]);o.push({name:g.name,plan:[(Math.min(...v)+Math.max(...v))/2,(Math.min(...w)+Math.max(...w))/2],grid:b.center})}let s=o.map(g=>g.name);if(o.length<2)return{cal:null,reason:"rooms",matched:s};let a=(o.length>=3?[!1,!0]:[n]).flatMap(g=>{let y=ww(o.map(b=>({plan:b.plan,seen:hl(b.grid,g)})));return y?[{mirror:g,...y}]:[]}).sort((g,y)=>g.rms-y.rms)[0];if(!a)return{cal:null,reason:"rooms",matched:s};if(!(a.scale>=um&&a.scale<=hm))return{cal:null,reason:"scale",matched:s};let c=Math.max(...o.map(g=>Math.hypot(g.plan[0]-o[0].plan[0],g.plan[1]-o[0].plan[1])));if(!(a.rms<=Math.max(1,c/4)))return{cal:null,reason:"fit",matched:s};let[d,u,p]=[0,1,-1];for(let g=0;gp&&([d,u,p]=[g,y,b])}let[h,f]=[o[d].grid,o[u].grid];return{cal:{a:a.map(hl(h,a.mirror)),ga:h,b:a.map(hl(f,a.mirror)),gb:f,mirror:a.mirror},matched:s,rms:a.rms}}function gm(t,e){let[n,r]=[(t.a[0]+t.b[0])/2,(t.a[1]+t.b[1])/2],o=(e.turn??0)*Math.PI/180,[i,s,l]=[Math.cos(o),Math.sin(o),e.grow??1],[a,c]=e.move??[0,0],d=u=>{let[p,h]=[(u[0]-n)*l,(u[1]-r)*l];return[cm(n+p*i-h*s+a),cm(r+p*s+h*i+c)]};return{...t,a:d(t.a),b:d(t.b)}}var cm=t=>Math.round(t*1e3)/1e3;var vw=/^(binary_sensor|switch|input_boolean|light|fan|person|device_tracker|sensor)\./,vt=t=>t==="none"?null:t;function fl(t,e,n){let r=t.t,o=L(t.hass,a=>vw.test(a)),i=!!e.state_entity&&e.state_entity!=="none",s=i&&!!e.state_entity2&&e.state_entity2!=="none",l=[["left_right",r("furn_state_left_right")],["top_bottom",r("furn_state_top_bottom")]];return m`${P(t,r("furn_state_entity"),e.state_entity??null,void 0,o,a=>n.update({state_entity:vt(a)}))} ${i?P(t,r("furn_state_entity2"),e.state_entity2??null,void 0,o,a=>n.update({state_entity2:vt(a)})):_} ${s?O(t,r("furn_state_split"),e.state_split==="top_bottom"?"top_bottom":"left_right",l,a=>n.update({state_split:a})):_} - ${M(r("furn_state_hint"),"nf-wide")}`}function vw(t,e){let r=Rn(t.type)&&(!gt(t.type)||vc(t.type));return ce(t.type)?{accept:o=>/^(light|switch|input_boolean)\./.test(o),label:"furn_entity_light"}:t.type==="radiator"||yn(t.type)?{accept:o=>o.startsWith("climate."),label:"furn_entity_climate"}:r?{accept:o=>/^(media_player|switch|input_boolean|light)\./.test(o),label:"furn_entity_tv"}:t.type==="robot_vacuum"?{accept:o=>o.startsWith("vacuum."),label:"furn_entity_vacuum"}:/:(robot_mower|mower_dock)$/.test(t.type)?{accept:o=>o.startsWith("lawn_mower."),label:"furn_entity_mower"}:/:(sprinkler|valve_box)$/.test(t.type)?{accept:o=>/^(valve|switch|input_boolean)\./.test(o),label:"furn_entity_water"}:{accept:o=>/^(switch|media_player|fan|input_boolean|climate|vacuum|cover|valve)\./.test(o)||hc(e?.states[o]),label:"furn_entity"}}function Li(t,e,n){if(!t.hass)return null;let r=structuredClone(t.doc.floors);for(let o of r)for(let i of o.furniture)i.id===e.id&&(i[n==="fan"?"fan_entity":n]=null);return Be(t.hass,r).get(e.id)?.[n]??null}var kw=t=>t==="meter"?"energy_grid":t==="inverter"?"energy_solar_sensor":t==="home_battery"?"energy_battery_sensor":"furn_power",st=(...t)=>m``;async function xw(t){let e=t.hass?Hi(t.hass):null;if(!t.hass||!e)return{at:null,dock:null};let n=()=>{let o=t.hass?.states[e]?.attributes??{};return`${String(o.render_count??"")}|${JSON.stringify(o.vacuum_position??null)}`},r=n();try{await t.hass.fetchWithAuth?.(`/api/camera_proxy/${e}`)}catch{}for(let o=0;o<8&&n()===r;o++)await new Promise(i=>setTimeout(i,100));return pl(t.hass,e)}function $w(t,e){let n=t.t,r=a=>t.change(c=>{c.settings.vacuum_map=gm(e,a)}),o=(a,c,d)=>m``,[i,s,l]=[n("robot_cal_nudge_move"),n("robot_cal_nudge_turn"),n("robot_cal_nudge_grow")];return m`${M(n("robot_cal_nudge"),"nf-wide")} + ${M(r("furn_state_hint"),"nf-wide")}`}function kw(t,e){let r=Rn(t.type)&&(!gt(t.type)||vc(t.type));return ce(t.type)?{accept:o=>/^(light|switch|input_boolean)\./.test(o),label:"furn_entity_light"}:t.type==="radiator"||yn(t.type)?{accept:o=>o.startsWith("climate."),label:"furn_entity_climate"}:r?{accept:o=>/^(media_player|switch|input_boolean|light)\./.test(o),label:"furn_entity_tv"}:t.type==="robot_vacuum"?{accept:o=>o.startsWith("vacuum."),label:"furn_entity_vacuum"}:/:(robot_mower|mower_dock)$/.test(t.type)?{accept:o=>o.startsWith("lawn_mower."),label:"furn_entity_mower"}:/:(sprinkler|valve_box)$/.test(t.type)?{accept:o=>/^(valve|switch|input_boolean)\./.test(o),label:"furn_entity_water"}:{accept:o=>/^(switch|media_player|fan|input_boolean|climate|vacuum|cover|valve)\./.test(o)||hc(e?.states[o]),label:"furn_entity"}}function Li(t,e,n){if(!t.hass)return null;let r=structuredClone(t.doc.floors);for(let o of r)for(let i of o.furniture)i.id===e.id&&(i[n==="fan"?"fan_entity":n]=null);return Be(t.hass,r).get(e.id)?.[n]??null}var xw=t=>t==="meter"?"energy_grid":t==="inverter"?"energy_solar_sensor":t==="home_battery"?"energy_battery_sensor":"furn_power",st=(...t)=>m``;async function $w(t){let e=t.hass?Hi(t.hass):null;if(!t.hass||!e)return{at:null,dock:null};let n=()=>{let o=t.hass?.states[e]?.attributes??{};return`${String(o.render_count??"")}|${JSON.stringify(o.vacuum_position??null)}`},r=n();try{await t.hass.fetchWithAuth?.(`/api/camera_proxy/${e}`)}catch{}for(let o=0;o<8&&n()===r;o++)await new Promise(i=>setTimeout(i,100));return pl(t.hass,e)}function Sw(t,e){let n=t.t,r=a=>t.change(c=>{c.settings.vacuum_map=gm(e,a)}),o=(a,c,d)=>m``,[i,s,l]=[n("robot_cal_nudge_move"),n("robot_cal_nudge_turn"),n("robot_cal_nudge_grow")];return m`${M(n("robot_cal_nudge"),"nf-wide")}
${o("\u2190",i,{move:[-.1,0]})}${o("\u2192",i,{move:[.1,0]})}${o("\u2191",i,{move:[0,-.1]})}${o("\u2193",i,{move:[0,.1]})} ${o("\u27F2",s,{turn:-1})}${o("\u27F3",s,{turn:1})}${o("\u2212",l,{grow:.99})}${o("+",l,{grow:1.01})} -
`}function Sw(t,e){let n=t.t,r=t.doc.settings.vacuum_map??null,o=t.hass?pl(t.hass,Hi(t.hass)):{at:null,dock:null},i=r?Math.hypot(r.gb[0]-r.ga[0],r.gb[1]-r.ga[1]):0,s=r&&i>0?Math.hypot(r.b[0]-r.a[0],r.b[1]-r.a[1])/i:0,l=()=>{t.pickPoint(p=>{p&&xw(t).then(h=>{if(!h.at||!h.dock)return;let f={plan:[e.x,e.z],grid:h.dock},g=pm(f,{plan:p,grid:h.at},r?.mirror??!1);g.cal&&t.change(y=>{y.settings.vacuum_map=g.cal})})})},a=t.hass?Hi(t.hass):null,c=t.hass?fm(t.hass,a):[],d=t.doc.floors.find(p=>p.furniture.some(h=>h.id===e.id)),u=()=>{if(!d)return;let p=mm(d.rooms,c,r?.mirror??!1);if(p.cal){let h=p.cal;t.change(f=>{f.settings.vacuum_map=h})}else alert(n(p.reason==="rooms"?"robot_cal_rooms_none":"robot_cal_rooms_bad",{n:p.matched.length}))};return st(M(o.at&&o.dock?r?n("robot_cal_done",{m:s.toFixed(2)}):n("robot_cal_none"):n("robot_cal_need"),"nf-wide"),c.length>=2?m``:_,m``,r?H(t,n("robot_cal_mirror"),!!r.mirror,p=>t.change(h=>{h.settings.vacuum_map={...r,mirror:p}})):_,r?$w(t,r):_,r?m``:_,M(n("robot_cal_hint"),"nf-wide"))}function Mw(t,e,n){let r=t.t,o=t.doc;if(!o.energy.advanced)return _;let i=Vn(o),s=o.floors.flatMap(l=>l.furniture.filter(a=>i.has(a.id)).map(a=>[a.id,`${a.name||r("furn_meter")} \xB7 ${l.name}`]));return st(O(t,r("meter_parent"),to(o,e)??"",[["",r("meter_main")],...s],l=>n.update({parent_meter:l||null}),{wide:!0}),M(r("meter_device_hint"),"nf-wide"))}function Rw(t,e,n){let r=t.t,o=t.doc;if(!o.energy.advanced)return _;let i=o.floors.flatMap(c=>c.furniture.filter(d=>hh(o,e,d)).map(d=>[d.id,`${d.name||r("furn_meter")} \xB7 ${c.name}`])),s=!!un(o,e),l=e.meter_floors??[],a=(c,d)=>n.update({meter_floors:d?[...l.filter(u=>u!==c),c]:l.filter(u=>u!==c)});return st(O(t,r("meter_parent"),s?e.parent_meter:"",[["",r("meter_parent_none")],...i],c=>n.update({parent_meter:c||null}),{wide:!0}),s?H(t,r("energy_invert"),!!e.meter_invert,c=>n.update({meter_invert:c})):_,s?m`
${r("meter_floors")}
${o.floors.map(c=>H(t,c.name,l.includes(c.id),d=>a(c.id,d)))}`:_,M(r("meter_sub_hint"),"nf-wide"))}function _m(t,e,n,r){let o=t.t,i=n==="mail"?s=>/^(binary_sensor|sensor|input_boolean)\./.test(s):s=>/^(sensor|binary_sensor|calendar)\./.test(s);return m``}function Mw(t,e){let n=t.t,r=t.doc.settings.vacuum_map??null,o=t.hass?pl(t.hass,Hi(t.hass)):{at:null,dock:null},i=r?Math.hypot(r.gb[0]-r.ga[0],r.gb[1]-r.ga[1]):0,s=r&&i>0?Math.hypot(r.b[0]-r.a[0],r.b[1]-r.a[1])/i:0,l=()=>{t.pickPoint(p=>{p&&$w(t).then(h=>{if(!h.at||!h.dock)return;let f={plan:[e.x,e.z],grid:h.dock},g=pm(f,{plan:p,grid:h.at},r?.mirror??!1);g.cal&&t.change(y=>{y.settings.vacuum_map=g.cal})})})},a=t.hass?Hi(t.hass):null,c=t.hass?fm(t.hass,a):[],d=t.doc.floors.find(p=>p.furniture.some(h=>h.id===e.id)),u=()=>{if(!d)return;let p=mm(d.rooms,c,r?.mirror??!1);if(p.cal){let h=p.cal;t.change(f=>{f.settings.vacuum_map=h})}else alert(n(p.reason==="rooms"?"robot_cal_rooms_none":"robot_cal_rooms_bad",{n:p.matched.length}))};return st(M(o.at&&o.dock?r?n("robot_cal_done",{m:s.toFixed(2)}):n("robot_cal_none"):n("robot_cal_need"),"nf-wide"),c.length>=2?m``:_,m``,r?H(t,n("robot_cal_mirror"),!!r.mirror,p=>t.change(h=>{h.settings.vacuum_map={...r,mirror:p}})):_,r?Sw(t,r):_,r?m``:_,M(n("robot_cal_hint"),"nf-wide"))}function Rw(t,e,n){let r=t.t,o=t.doc;if(!o.energy.advanced)return _;let i=Vn(o),s=o.floors.flatMap(l=>l.furniture.filter(a=>i.has(a.id)).map(a=>[a.id,`${a.name||r("furn_meter")} \xB7 ${l.name}`]));return st(O(t,r("meter_parent"),to(o,e)??"",[["",r("meter_main")],...s],l=>n.update({parent_meter:l||null}),{wide:!0}),M(r("meter_device_hint"),"nf-wide"))}function Ew(t,e,n){let r=t.t,o=t.doc;if(!o.energy.advanced)return _;let i=o.floors.flatMap(c=>c.furniture.filter(d=>hh(o,e,d)).map(d=>[d.id,`${d.name||r("furn_meter")} \xB7 ${c.name}`])),s=!!un(o,e),l=e.meter_floors??[],a=(c,d)=>n.update({meter_floors:d?[...l.filter(u=>u!==c),c]:l.filter(u=>u!==c)});return st(O(t,r("meter_parent"),s?e.parent_meter:"",[["",r("meter_parent_none")],...i],c=>n.update({parent_meter:c||null}),{wide:!0}),s?H(t,r("energy_invert"),!!e.meter_invert,c=>n.update({meter_invert:c})):_,s?m`
${r("meter_floors")}
${o.floors.map(c=>H(t,c.name,l.includes(c.id),d=>a(c.id,d)))}`:_,M(r("meter_sub_hint"),"nf-wide"))}function _m(t,e,n,r){let o=t.t,i=n==="mail"?s=>/^(binary_sensor|sensor|input_boolean)\./.test(s):s=>/^(sensor|binary_sensor|calendar)\./.test(s);return m``}function ym(t,e,n,r){let o=t.t,i=/socket/.test(e.type),s=L(t.hass,c=>/^(light|switch|input_boolean|fan)\./.test(c)),l=e.gang_entities??[],a=c=>d=>{let u=Array.from({length:n},(p,h)=>l[h]??null);u[c]=vt(d),r.update({gang_entities:u})};return m``}function Ew(t,e,n){let r=t.t,o=L(t.hass,i=>{let s=t.hass?.states[i]?.attributes;return i.startsWith("sensor.")&&(s?.device_class==="temperature"||s?.unit_of_measurement==="\xB0C"||s?.unit_of_measurement==="\xB0F")});return st(P(t,r("fridge_temp"),e.temp_entity??null,void 0,o,i=>n.update({temp_entity:vt(i)})),P(t,r("freezer_temp"),e.temp_entity2??null,void 0,o,i=>n.update({temp_entity2:vt(i)})),M(r("fridge_temp_hint"),"nf-wide"))}function Aw(t,e,n){let r=t.t,o=L(t.hass,i=>{let s=t.hass?.states[i]?.attributes;return i.startsWith("sensor.")&&(s?.device_class==="temperature"||s?.unit_of_measurement==="\xB0C"||s?.unit_of_measurement==="\xB0F")});return st(P(t,r("device_temp"),e.temp_entity??null,void 0,o,i=>n.update({temp_entity:vt(i)})),M(r("device_temp_hint"),"nf-wide"))}function Fw(t,e,n){let r=t.t,o=e.extra_lights??[],i=L(t.hass,a=>a.startsWith("light.")&&a!==e.entity&&a!==e.color_entity),s=a=>c=>{let d=[...o];c&&c!=="none"?d[a]=c:d.splice(a,1),n.update({extra_lights:d.filter(Boolean).length?d.filter(Boolean):void 0})},l=Math.min(4,o.length+1);return m`${Array.from({length:l},(a,c)=>P(t,r("lamp_extra_light",{n:c+2}),o[c]??null,void 0,i,s(c)))}${M(r("lamp_extra_hint"),"nf-wide")}`}function wm(t,e,n){let{hass:r}=t;if(!r)return _;let o=t.t,i=ce(e.type),s=vw(e,r),l=L(r,f=>On(r,f)),a=f=>g=>n.update({[f]:vt(g)}),c=f=>L(r,f),d=(t.doc.settings.roof.strings??[]).filter(f=>f.inverter===e.id).map(f=>f.name),u=!!e.entity&&e.entity!=="none",p=e.type==="fridge_smart"?c(f=>f.startsWith("binary_sensor.")):[],h=e.type==="ceiling_fan"?"fan_hint":i?e.type==="lamp_pendant"?"lamp_hint_pendant":"lamp_hint":Rn(e.type)?"furn_links_hint_tv":e.type==="robot_vacuum"?"robot_hint":"furn_links_hint";return m`${st(e.type==="grid_point"?M(o("grid_point_hint"),"nf-wide"):P(t,o(s.label),e.entity??null,Li(t,e,"entity"),c(s.accept),f=>n.update({entity:f})),e.type==="ceiling_fan"?P(t,o("furn_fan_entity"),e.fan_entity??null,Li(t,e,"fan"),c(f=>f.startsWith("fan.")),f=>n.update({fan_entity:f})):_,!i&&!Ce.includes(e.type)&&!wr(e.type)?fl(t,e,n):_,i&&u?m`${P(t,o("furn_color_entity"),e.color_entity??null,void 0,c(f=>f.startsWith("light.")&&f!==e.entity),a("color_entity"))}${M(o("furn_color_entity_hint"),"nf-wide")}`:_,i&&u?Fw(t,e,n):_,i?an(t,e.glow_scale,f=>n.update({glow_scale:f})):_,i?Di(t,e,am(r,e,e.entity&&e.entity!=="none"?e.entity:Li(t,e,"entity"))?.attributes.effect_list,n.update):_,wr(e.type)?an(t,e.ambilight,f=>n.update({ambilight:f}),{label:"ambilight",hint:"ambilight_hint",lowest:0}):_,Rn(e.type)||Zo(e.type)?an(t,e.sound_rings,f=>n.update({sound_rings:f}),{label:"sound_rings",hint:"sound_rings_hint",lowest:0}):_,e.type==="grid_point"?_:P(t,o(un(t.doc,e)?"meter_sub_power":kw(e.type)),e.power??null,Li(t,e,"power"),l,f=>n.update({power:f})))} - ${wd(e.type)?Ew(t,e,n):i||e.type==="grid_point"?_:Aw(t,e,n)} - ${e.type==="meter"?Rw(t,e,n):_} - ${e.type==="inverter"||e.type==="home_battery"?Mw(t,e,n):_} + `}function Aw(t,e,n){let r=t.t,o=L(t.hass,i=>{let s=t.hass?.states[i]?.attributes;return i.startsWith("sensor.")&&(s?.device_class==="temperature"||s?.unit_of_measurement==="\xB0C"||s?.unit_of_measurement==="\xB0F")});return st(P(t,r("fridge_temp"),e.temp_entity??null,void 0,o,i=>n.update({temp_entity:vt(i)})),P(t,r("freezer_temp"),e.temp_entity2??null,void 0,o,i=>n.update({temp_entity2:vt(i)})),M(r("fridge_temp_hint"),"nf-wide"))}function Fw(t,e,n){let r=t.t,o=L(t.hass,i=>{let s=t.hass?.states[i]?.attributes;return i.startsWith("sensor.")&&(s?.device_class==="temperature"||s?.unit_of_measurement==="\xB0C"||s?.unit_of_measurement==="\xB0F")});return st(P(t,r("device_temp"),e.temp_entity??null,void 0,o,i=>n.update({temp_entity:vt(i)})),M(r("device_temp_hint"),"nf-wide"))}function Tw(t,e,n){let r=t.t,o=e.extra_lights??[],i=L(t.hass,a=>a.startsWith("light.")&&a!==e.entity&&a!==e.color_entity),s=a=>c=>{let d=[...o];c&&c!=="none"?d[a]=c:d.splice(a,1),n.update({extra_lights:d.filter(Boolean).length?d.filter(Boolean):void 0})},l=Math.min(4,o.length+1);return m`${Array.from({length:l},(a,c)=>P(t,r("lamp_extra_light",{n:c+2}),o[c]??null,void 0,i,s(c)))}${M(r("lamp_extra_hint"),"nf-wide")}`}function wm(t,e,n){let{hass:r}=t;if(!r)return _;let o=t.t,i=ce(e.type),s=kw(e,r),l=L(r,f=>On(r,f)),a=f=>g=>n.update({[f]:vt(g)}),c=f=>L(r,f),d=(t.doc.settings.roof.strings??[]).filter(f=>f.inverter===e.id).map(f=>f.name),u=!!e.entity&&e.entity!=="none",p=e.type==="fridge_smart"?c(f=>f.startsWith("binary_sensor.")):[],h=e.type==="ceiling_fan"?"fan_hint":i?e.type==="lamp_pendant"?"lamp_hint_pendant":"lamp_hint":Rn(e.type)?"furn_links_hint_tv":e.type==="robot_vacuum"?"robot_hint":"furn_links_hint";return m`${st(e.type==="grid_point"?M(o("grid_point_hint"),"nf-wide"):P(t,o(s.label),e.entity??null,Li(t,e,"entity"),c(s.accept),f=>n.update({entity:f})),e.type==="ceiling_fan"?P(t,o("furn_fan_entity"),e.fan_entity??null,Li(t,e,"fan"),c(f=>f.startsWith("fan.")),f=>n.update({fan_entity:f})):_,!i&&!Ce.includes(e.type)&&!wr(e.type)?fl(t,e,n):_,i&&u?m`${P(t,o("furn_color_entity"),e.color_entity??null,void 0,c(f=>f.startsWith("light.")&&f!==e.entity),a("color_entity"))}${M(o("furn_color_entity_hint"),"nf-wide")}`:_,i&&u?Tw(t,e,n):_,i?an(t,e.glow_scale,f=>n.update({glow_scale:f})):_,i?Di(t,e,am(r,e,e.entity&&e.entity!=="none"?e.entity:Li(t,e,"entity"))?.attributes.effect_list,n.update):_,wr(e.type)?an(t,e.ambilight,f=>n.update({ambilight:f}),{label:"ambilight",hint:"ambilight_hint",lowest:0}):_,Rn(e.type)||Zo(e.type)?an(t,e.sound_rings,f=>n.update({sound_rings:f}),{label:"sound_rings",hint:"sound_rings_hint",lowest:0}):_,e.type==="grid_point"?_:P(t,o(un(t.doc,e)?"meter_sub_power":xw(e.type)),e.power??null,Li(t,e,"power"),l,f=>n.update({power:f})))} + ${wd(e.type)?Aw(t,e,n):i||e.type==="grid_point"?_:Fw(t,e,n)} + ${e.type==="meter"?Ew(t,e,n):_} + ${e.type==="inverter"||e.type==="home_battery"?Rw(t,e,n):_} ${e.type==="meter"&&!un(t.doc,e)?st(P(t,o("furn_export"),e.export??null,void 0,l,a("export")),M(o("furn_export_hint"),"nf-wide")):_} ${e.type==="inverter"&&(t.doc.settings.roof.solar??[]).length>0?M(d.length>0?o("inverter_strings",{names:d.join(", ")}):o("inverter_strings_none"),"nf-wide"):_} - ${e.type==="home_battery"?st(P(t,o("furn_soc"),e.soc??null,void 0,c(f=>he(f)&&(r.states[f]?.attributes.device_class==="battery"||r.states[f]?.attributes.unit_of_measurement==="%")),a("soc")),P(t,o("furn_charge"),e.charge??null,void 0,l,a("charge")),M(o("furn_charge_hint"),"nf-wide")):_} - ${e.type==="wallbox"?st(P(t,o("furn_wallbox_status"),e.status??null,void 0,c(f=>ii(f)||he(f)),a("status"))):_} + ${e.type==="home_battery"?st(P(t,o("furn_soc"),e.soc??null,void 0,c(f=>me(f)&&(r.states[f]?.attributes.device_class==="battery"||r.states[f]?.attributes.unit_of_measurement==="%")),a("soc")),P(t,o("furn_charge"),e.charge??null,void 0,l,a("charge")),M(o("furn_charge_hint"),"nf-wide")):_} + ${e.type==="wallbox"?st(P(t,o("furn_wallbox_status"),e.status??null,void 0,c(f=>ii(f)||me(f)),a("status"))):_} ${!i||e.entity?m`${H(t,o("device_confirm"),!!e.confirm,f=>n.update({confirm:f}),{title:o("device_confirm_hint")})}
${Nn(t,e.marker??null,f=>n.update({marker:f}))}${Ht(t,e.icon,f=>n.update({icon:f}))}${i?_:Bn(t,e.pin_offset,f=>n.update({pin_offset:f}))}
`:_} - ${e.type==="robot_vacuum"?st(P(t,o("furn_robot_room"),e.room_sensor??null,$d(r,Be(r,t.doc.floors).get(e.id)?.entity??null,null),c(he),f=>n.update({room_sensor:f}))):_} - ${e.type==="robot_vacuum"&&u?Sw(t,e):_} + ${e.type==="robot_vacuum"?st(P(t,o("furn_robot_room"),e.room_sensor??null,$d(r,Be(r,t.doc.floors).get(e.id)?.entity??null,null),c(me),f=>n.update({room_sensor:f}))):_} + ${e.type==="robot_vacuum"&&u?Mw(t,e):_} ${e.type==="fridge_smart"?m`${st(P(t,o("furn_door_left"),e.door_left??null,void 0,p,f=>n.update({door_left:f})),P(t,o("furn_door_right"),e.door_right??null,void 0,p,f=>n.update({door_right:f})))} ${M(o("fridge_hint"))}`:_} - ${M(o(h))}`}var Tw=/^(binary_sensor|device_tracker|input_boolean|switch|sensor)\./,zw=/^(sensor|input_select|select|input_text)\./,Pw=/^(device_tracker|sensor|binary_sensor|lock|climate)\./,Iw=(t,e)=>t.flatMap(n=>n.items.filter(r=>r.vehicle).map(r=>({id:ue(n.id,r.id),label:`${Ye(r,ue(n.id,r.id),e)} \xB7 ${Oe(n,e)}`})));function vm(t,e){return e.startsWith("device_tracker.")?t.hass?.states[e]?.attributes.source_type==="router"?2:0:1}function km(t,e,n,r){return m`r(o.target.value||null)}> ${e.map(o=>m``)} - `}function Dw(t,e,n,r){let o=t.t,i=e.type_entity?t.hass?.states[e.type_entity]:void 0,s=Array.isArray(i?.attributes.options)?i.attributes.options:[],l=e.types??[],a=d=>r.update({types:d}),c=(d,u)=>a(l.map((p,h)=>h===d?{...p,...u}:p));return m`
+ `}function Ow(t,e,n,r){let o=t.t,i=e.type_entity?t.hass?.states[e.type_entity]:void 0,s=Array.isArray(i?.attributes.options)?i.attributes.options:[],l=e.types??[],a=d=>r.update({types:d}),c=(d,u)=>a(l.map((p,h)=>h===d?{...p,...u}:p));return m`
${o("parking_types")}
${l.map((d,u)=>m`
c(u,{state:p.target.value})} /> @@ -1419,26 +1419,26 @@ ${i}`}else o=ju(s)}}catch(s){let l=s.message,a={not_json:"import_error_not_json"
`)} ${s.map(d=>m``)} ${t.admin?m``:_} -
`}function xm(t,e,n,r){let o=t.t,i=Iw(n,t.hass?.language??"en"),s=L(t.hass,f=>Tw.test(f)).sort((f,g)=>vm(t,f.id)-vm(t,g.id)),l=L(t.hass,f=>zw.test(f)),a=e.car??{},c=t.floor,d=c?.rooms.find(f=>f.points.length>=3&&N([e.x,e.z],f.points)),u=e.vehicle?G(e.vehicle):void 0,p=u?u.size[2]*(e.scale??1):0,h=!!d&&!!c&&p>c.height+1e-6;return m``}function xm(t,e,n,r){let o=t.t,i=Dw(n,t.hass?.language??"en"),s=L(t.hass,f=>zw.test(f)).sort((f,g)=>vm(t,f.id)-vm(t,g.id)),l=L(t.hass,f=>Pw.test(f)),a=e.car??{},c=t.floor,d=c?.rooms.find(f=>f.points.length>=3&&N([e.x,e.z],f.points)),u=e.vehicle?G(e.vehicle):void 0,p=u?u.size[2]*(e.scale??1):0,h=!!d&&!!c&&p>c.height+1e-6;return m` ${h?m`

${o("parking_too_tall",{car:j(t.hass,p,2),room:j(t.hass,c.height,2)})}

`:_} ${M(o("parking_hint"))} - ${t.hass?m`${P(t,o("live_car_device"),a.device??null,null,L(t.hass,f=>Pw.test(f)),f=>r.update({car:{...a,device:f}}))} + ${t.hass?m`${P(t,o("live_car_device"),a.device??null,null,L(t.hass,f=>Iw.test(f)),f=>r.update({car:{...a,device:f}}))} ${M(o("live_car_device_hint"),"nf-wide")} - ${P(t,o("live_car_departure_entity"),a.departure??null,void 0,L(t.hass,f=>/^(sensor|input_datetime|time|datetime)\./.test(f)),f=>r.update({car:{...a,departure:f==="none"?null:f}}))}`:_}`}function $m(t,e){let r=hn(t,e.w,e.d,e.h).treads.findIndex(o=>o.landing);return r>=0?r+1:1}function Ow(t){let e=hn(so(t),t.w,t.d,t.h),n=e.treads.map(ki),r=0;for(let i=1;i1?r/(n.length-1):0;return{rise:e.rise,going:o,measure:2*e.rise+o,steps:e.steps}}function Hw(t){let[e,n]=Ta[t],r=hn({...pt,shape:t},e,n,2.8),o=26/Math.max(e,n);return m`
+ `}function Sm(t,e,n){let r=t.t,o=so(e),i=f=>n.update({stair:{...o,...f}}),s=o.shape!=="straight",l=f=>{let[g,y]=Ta[f];n.update({stair:{...o,shape:f,run_width:null},w:g,d:y})},a=t.floor?t.doc.floors.filter(f=>f.elevationg.elevation-f.elevation)[0]:void 0,c=t.floor?t.doc.floors.filter(f=>f.elevation>t.floor.elevation).sort((f,g)=>f.elevation-g.elevation)[0]:void 0,d=f=>{let g=f?a&&t.floor?t.floor.elevation-a.elevation:null:c&&t.floor?c.elevation-t.floor.elevation:null;n.update({stair:{...o,down:f},...g?{h:Math.round(g*1e3)/1e3}:{}})},u=Hw(e),p=f=>j(t.hass,f*100,1),h=u.measure>=.59&&u.measure<=.65&&u.rise<=.21;return m`
${r("stair_shape")}
${Ra.map(f=>m``)}
@@ -1459,7 +1459,7 @@ ${i}`}else o=ju(s)}}catch(s){let l=s.message,a={not_json:"import_error_not_json" ${r("stair_measures",{steps:u.steps,rise:p(u.rise),going:p(u.going),measure:p(u.measure)})} ${h?"\u2713":`\u2013 ${r("stair_uncomfortable")}`}

${M(r(o.down?"stair_down_note":o.opening==="headroom"?"stair_up_note":"stair_up_note_plain"),"nf-wide")} -
`}var Lw=new Set(["parking","stairwell","rug","grid_point"]),Cw={inverter:{label:"furn_model",values:["","slim","hybrid"],text:t=>`inverter_${t||"std"}`},home_battery:{label:"furn_model",values:["","wall","cube"],text:t=>`battery_${t||"std"}`},lamp_pendant:{label:"pendant_shape",values:["","globe","cone","drum"],text:t=>`pendant_${t||"shade"}`},sofa:{label:"sofa_shape",values:["","l","u"],text:t=>`sofa_${t||"straight"}`}};function Nw(t,e,n,r){let o=t.hass?.language??"en",i=n.some(s=>e.type.startsWith(`pack:${s.id}:`));return m`