Files
NextFloor/custom_components/nextfloor/frontend/nextfloor-editor.js
T

4850 lines
645 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*! NextFloor, MIT licence. Includes three.js (MIT) and Lit (BSD-3-Clause); see LICENSE and THIRD_PARTY_NOTICES.md */
var $={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 An=t=>t?`${t.kind}:${t.id}`:"";function As(t){return t?t.outdoor_location_id?{kind:"outside",id:t.outdoor_location_id}:t.building_id?{kind:"building",id:t.building_id}:null:null}function Fs(t,e){return!!e&&!!t.topology&&(e.kind==="building"?t.topology.buildings.some(n=>n.id===e.id):t.topology.locations.some(n=>n.id===e.id)&&t.floors.some(n=>n.outdoor_location_id===e.id))}function $r(t,e){return t.topology?Fs(t,e)?t.floors.filter(n=>e.kind==="outside"?n.outdoor_location_id===e.id:!n.outdoor_location_id&&n.building_id===e.id):[]:t.floors}function Hc(t,e){return{scope:e,floorId:$r(t,e)[0]?.id??null}}function Lc(t,e){if(!t.topology)return{scope:null,floorId:t.floors.some(i=>i.id===e.floorId)?e.floorId:t.floors[0]?.id??null};let n=Fs(t,e.scope)?e.scope:As(t.floors.find(i=>i.id===e.floorId)??t.floors[0])??(t.topology.buildings[0]?{kind:"building",id:t.topology.buildings[0].id}:null),r=$r(t,n);return{scope:n,floorId:r.some(i=>i.id===e.floorId)?e.floorId:r[0]?.id??null}}function Ts(t){let e=t.topology;return e?[...e.buildings.map(n=>{let r=e.branches.find(o=>o.id===n.branch_id),i=e.locations.find(o=>o.id===r?.location_id);return[`building:${n.id}`,[i?.name,r?.name,n.name].filter(Boolean).join(" / ")]}),...e.locations.filter(n=>t.floors.some(r=>r.outdoor_location_id===n.id)).map(n=>[`outside:${n.id}`,`${n.name} / Au\xDFen`])]:[]}function zs(t,e){let n=e.indexOf(":"),r=e.slice(0,n),i=e.slice(n+1),o=r==="building"||r==="outside"?{kind:r,id:i}:null;return Fs(t,o)?o:null}function Cc(t,e,n,r){let i=t.floors.find(o=>o.id===n);return e!==n||!i||i.outdoor_location_id||!t.topology?.buildings.some(o=>o.id===r)||i.building_id===r?!1:(i.building_id=r,!0)}var Ni=globalThis,Bi=Ni.ShadowRoot&&(Ni.ShadyCSS===void 0||Ni.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,Ps=Symbol(),Nc=new WeakMap,Sr=class{constructor(e,n,r){if(this._$cssResult$=!0,r!==Ps)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(Bi&&e===void 0){let r=n!==void 0&&n.length===1;r&&(e=Nc.get(n)),e===void 0&&((this.o=e=new CSSStyleSheet).replaceSync(this.cssText),r&&Nc.set(n,e))}return e}toString(){return this.cssText}},Bc=t=>new Sr(typeof t=="string"?t:t+"",void 0,Ps),J=(t,...e)=>{let n=t.length===1?t[0]:e.reduce((r,i,o)=>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.")})(i)+t[o+1],t[0]);return new Sr(n,t,Ps)},Vc=(t,e)=>{if(Bi)t.adoptedStyleSheets=e.map(n=>n instanceof CSSStyleSheet?n:n.styleSheet);else for(let n of e){let r=document.createElement("style"),i=Ni.litNonce;i!==void 0&&r.setAttribute("nonce",i),r.textContent=n.cssText,t.appendChild(r)}},Is=Bi?t=>t:t=>t instanceof CSSStyleSheet?(e=>{let n="";for(let r of e.cssRules)n+=r.cssText;return Bc(n)})(t):t;var{is:Ib,defineProperty:Db,getOwnPropertyDescriptor:Ob,getOwnPropertyNames:Hb,getOwnPropertySymbols:Lb,getPrototypeOf:Cb}=Object,Vi=globalThis,Wc=Vi.trustedTypes,Nb=Wc?Wc.emptyScript:"",Bb=Vi.reactiveElementPolyfillSupport,Mr=(t,e)=>t,Ds={toAttribute(t,e){switch(e){case Boolean:t=t?Nb: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}},jc=(t,e)=>!Ib(t,e),Kc={attribute:!0,type:String,converter:Ds,reflect:!1,useDefault:!1,hasChanged:jc};Symbol.metadata??=Symbol("metadata"),Vi.litPropertyMetadata??=new WeakMap;var yt=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=Kc){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(),i=this.getPropertyDescriptor(e,r,n);i!==void 0&&Db(this.prototype,e,i)}}static getPropertyDescriptor(e,n,r){let{get:i,set:o}=Ob(this.prototype,e)??{get(){return this[n]},set(s){this[n]=s}};return{get:i,set(s){let a=i?.call(this);o?.call(this,s),this.requestUpdate(e,a,r)},configurable:!0,enumerable:!0}}static getPropertyOptions(e){return this.elementProperties.get(e)??Kc}static _$Ei(){if(this.hasOwnProperty(Mr("elementProperties")))return;let e=Cb(this);e.finalize(),e.l!==void 0&&(this.l=[...e.l]),this.elementProperties=new Map(e.elementProperties)}static finalize(){if(this.hasOwnProperty(Mr("finalized")))return;if(this.finalized=!0,this._$Ei(),this.hasOwnProperty(Mr("properties"))){let n=this.properties,r=[...Hb(n),...Lb(n)];for(let i of r)this.createProperty(i,n[i])}let e=this[Symbol.metadata];if(e!==null){let n=litPropertyMetadata.get(e);if(n!==void 0)for(let[r,i]of n)this.elementProperties.set(r,i)}this._$Eh=new Map;for(let[n,r]of this.elementProperties){let i=this._$Eu(n,r);i!==void 0&&this._$Eh.set(i,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 i of r)n.unshift(Is(i))}else e!==void 0&&n.push(Is(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 Vc(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),i=this.constructor._$Eu(e,r);if(i!==void 0&&r.reflect===!0){let o=(r.converter?.toAttribute!==void 0?r.converter:Ds).toAttribute(n,r.type);this._$Em=e,o==null?this.removeAttribute(i):this.setAttribute(i,o),this._$Em=null}}_$AK(e,n){let r=this.constructor,i=r._$Eh.get(e);if(i!==void 0&&this._$Em!==i){let o=r.getPropertyOptions(i),s=typeof o.converter=="function"?{fromAttribute:o.converter}:o.converter?.fromAttribute!==void 0?o.converter:Ds;this._$Em=i;let a=s.fromAttribute(n,o.type);this[i]=a??this._$Ej?.get(i)??a,this._$Em=null}}requestUpdate(e,n,r,i=!1,o){if(e!==void 0){let s=this.constructor;if(i===!1&&(o=this[e]),r??=s.getPropertyOptions(e),!((r.hasChanged??jc)(o,n)||r.useDefault&&r.reflect&&o===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:i,wrapped:o},s){r&&!(this._$Ej??=new Map).has(e)&&(this._$Ej.set(e,s??n??this[e]),o!==!0||s!==void 0)||(this._$AL.has(e)||(this.hasUpdated||r||(n=void 0),this._$AL.set(e,n)),i===!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[i,o]of this._$Ep)this[i]=o;this._$Ep=void 0}let r=this.constructor.elementProperties;if(r.size>0)for(let[i,o]of r){let{wrapped:s}=o,a=this[i];s!==!0||this._$AL.has(i)||a===void 0||this.C(i,void 0,o,a)}}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){}};yt.elementStyles=[],yt.shadowRootOptions={mode:"open"},yt[Mr("elementProperties")]=new Map,yt[Mr("finalized")]=new Map,Bb?.({ReactiveElement:yt}),(Vi.reactiveElementVersions??=[]).push("2.1.2");var Hs=globalThis,Gc=t=>t,Wi=Hs.trustedTypes,Uc=Wi?Wi.createPolicy("lit-html",{createHTML:t=>t}):void 0,Ls="$lit$",vt=`lit$${Math.random().toFixed(9).slice(2)}$`,Cs="?"+vt,Vb=`<${Cs}>`,tn=document,Rr=()=>tn.createComment(""),Ar=t=>t===null||typeof t!="object"&&typeof t!="function",Ns=Array.isArray,Qc=t=>Ns(t)||typeof t?.[Symbol.iterator]=="function",Os=`[
\f\r]`,Er=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,Zc=/-->/g,qc=/>/g,Qt=RegExp(`>|${Os}(?:([^\\s"'>=/]+)(${Os}*=${Os}*(?:[^
\f\r"'\`<>=]|("|')|))|$)`,"g"),Yc=/'/g,Xc=/"/g,ed=/^(?:script|style|textarea|title)$/i,Bs=t=>(e,...n)=>({_$litType$:t,strings:e,values:n}),m=Bs(1),E=Bs(2),E1=Bs(3),tt=Symbol.for("lit-noChange"),_=Symbol.for("lit-nothing"),Jc=new WeakMap,en=tn.createTreeWalker(tn,129);function td(t,e){if(!Ns(t)||!t.hasOwnProperty("raw"))throw Error("invalid template strings array");return Uc!==void 0?Uc.createHTML(e):e}var nd=(t,e)=>{let n=t.length-1,r=[],i,o=e===2?"<svg>":e===3?"<math>":"",s=Er;for(let a=0;a<n;a++){let l=t[a],c,d,u=-1,p=0;for(;p<l.length&&(s.lastIndex=p,d=s.exec(l),d!==null);)p=s.lastIndex,s===Er?d[1]==="!--"?s=Zc:d[1]!==void 0?s=qc:d[2]!==void 0?(ed.test(d[2])&&(i=RegExp("</"+d[2],"g")),s=Qt):d[3]!==void 0&&(s=Qt):s===Qt?d[0]===">"?(s=i??Er,u=-1):d[1]===void 0?u=-2:(u=s.lastIndex-d[2].length,c=d[1],s=d[3]===void 0?Qt:d[3]==='"'?Xc:Yc):s===Xc||s===Yc?s=Qt:s===Zc||s===qc?s=Er:(s=Qt,i=void 0);let h=s===Qt&&t[a+1].startsWith("/>")?" ":"";o+=s===Er?l+Vb:u>=0?(r.push(c),l.slice(0,u)+Ls+l.slice(u)+vt+h):l+vt+(u===-2?a:h)}return[td(t,o+(t[n]||"<?>")+(e===2?"</svg>":e===3?"</math>":"")),r]},Fr=class t{constructor({strings:e,_$litType$:n},r){let i;this.parts=[];let o=0,s=0,a=e.length-1,l=this.parts,[c,d]=nd(e,n);if(this.el=t.createElement(c,r),en.currentNode=this.el.content,n===2||n===3){let u=this.el.content.firstChild;u.replaceWith(...u.childNodes)}for(;(i=en.nextNode())!==null&&l.length<a;){if(i.nodeType===1){if(i.hasAttributes())for(let u of i.getAttributeNames())if(u.endsWith(Ls)){let p=d[s++],h=i.getAttribute(u).split(vt),f=/([.?@])?(.*)/.exec(p);l.push({type:1,index:o,name:f[2],strings:h,ctor:f[1]==="."?ji:f[1]==="?"?Gi:f[1]==="@"?Ui:rn}),i.removeAttribute(u)}else u.startsWith(vt)&&(l.push({type:6,index:o}),i.removeAttribute(u));if(ed.test(i.tagName)){let u=i.textContent.split(vt),p=u.length-1;if(p>0){i.textContent=Wi?Wi.emptyScript:"";for(let h=0;h<p;h++)i.append(u[h],Rr()),en.nextNode(),l.push({type:2,index:++o});i.append(u[p],Rr())}}}else if(i.nodeType===8)if(i.data===Cs)l.push({type:2,index:o});else{let u=-1;for(;(u=i.data.indexOf(vt,u+1))!==-1;)l.push({type:7,index:o}),u+=vt.length-1}o++}}static createElement(e,n){let r=tn.createElement("template");return r.innerHTML=e,r}};function nn(t,e,n=t,r){if(e===tt)return e;let i=r!==void 0?n._$Co?.[r]:n._$Cl,o=Ar(e)?void 0:e._$litDirective$;return i?.constructor!==o&&(i?._$AO?.(!1),o===void 0?i=void 0:(i=new o(t),i._$AT(t,n,r)),r!==void 0?(n._$Co??=[])[r]=i:n._$Cl=i),i!==void 0&&(e=nn(t,i._$AS(t,e.values),i,r)),e}var Ki=class{constructor(e,n){this._$AV=[],this._$AN=void 0,this._$AD=e,this._$AM=n}get parentNode(){return this._$AM.parentNode}get _$AU(){return this._$AM._$AU}u(e){let{el:{content:n},parts:r}=this._$AD,i=(e?.creationScope??tn).importNode(n,!0);en.currentNode=i;let o=en.nextNode(),s=0,a=0,l=r[0];for(;l!==void 0;){if(s===l.index){let c;l.type===2?c=new Fn(o,o.nextSibling,this,e):l.type===1?c=new l.ctor(o,l.name,l.strings,this,e):l.type===6&&(c=new Zi(o,this,e)),this._$AV.push(c),l=r[++a]}s!==l?.index&&(o=en.nextNode(),s++)}return en.currentNode=tn,i}p(e){let n=0;for(let r of this._$AV)r!==void 0&&(r.strings!==void 0?(r._$AI(e,r,n),n+=r.strings.length-2):r._$AI(e[n])),n++}},Fn=class t{get _$AU(){return this._$AM?._$AU??this._$Cv}constructor(e,n,r,i){this.type=2,this._$AH=_,this._$AN=void 0,this._$AA=e,this._$AB=n,this._$AM=r,this.options=i,this._$Cv=i?.isConnected??!0}get parentNode(){let e=this._$AA.parentNode,n=this._$AM;return n!==void 0&&e?.nodeType===11&&(e=n.parentNode),e}get startNode(){return this._$AA}get endNode(){return this._$AB}_$AI(e,n=this){e=nn(this,e,n),Ar(e)?e===_||e==null||e===""?(this._$AH!==_&&this._$AR(),this._$AH=_):e!==this._$AH&&e!==tt&&this._(e):e._$litType$!==void 0?this.$(e):e.nodeType!==void 0?this.T(e):Qc(e)?this.k(e):this._(e)}O(e){return this._$AA.parentNode.insertBefore(e,this._$AB)}T(e){this._$AH!==e&&(this._$AR(),this._$AH=this.O(e))}_(e){this._$AH!==_&&Ar(this._$AH)?this._$AA.nextSibling.data=e:this.T(tn.createTextNode(e)),this._$AH=e}$(e){let{values:n,_$litType$:r}=e,i=typeof r=="number"?this._$AC(e):(r.el===void 0&&(r.el=Fr.createElement(td(r.h,r.h[0]),this.options)),r);if(this._$AH?._$AD===i)this._$AH.p(n);else{let o=new Ki(i,this),s=o.u(this.options);o.p(n),this.T(s),this._$AH=o}}_$AC(e){let n=Jc.get(e.strings);return n===void 0&&Jc.set(e.strings,n=new Fr(e)),n}k(e){Ns(this._$AH)||(this._$AH=[],this._$AR());let n=this._$AH,r,i=0;for(let o of e)i===n.length?n.push(r=new t(this.O(Rr()),this.O(Rr()),this,this.options)):r=n[i],r._$AI(o),i++;i<n.length&&(this._$AR(r&&r._$AB.nextSibling,i),n.length=i)}_$AR(e=this._$AA.nextSibling,n){for(this._$AP?.(!1,!0,n);e!==this._$AB;){let r=Gc(e).nextSibling;Gc(e).remove(),e=r}}setConnected(e){this._$AM===void 0&&(this._$Cv=e,this._$AP?.(e))}},rn=class{get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}constructor(e,n,r,i,o){this.type=1,this._$AH=_,this._$AN=void 0,this.element=e,this.name=n,this._$AM=i,this.options=o,r.length>2||r[0]!==""||r[1]!==""?(this._$AH=Array(r.length-1).fill(new String),this.strings=r):this._$AH=_}_$AI(e,n=this,r,i){let o=this.strings,s=!1;if(o===void 0)e=nn(this,e,n,0),s=!Ar(e)||e!==this._$AH&&e!==tt,s&&(this._$AH=e);else{let a=e,l,c;for(e=o[0],l=0;l<o.length-1;l++)c=nn(this,a[r+l],n,l),c===tt&&(c=this._$AH[l]),s||=!Ar(c)||c!==this._$AH[l],c===_?e=_:e!==_&&(e+=(c??"")+o[l+1]),this._$AH[l]=c}s&&!i&&this.j(e)}j(e){e===_?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,e??"")}},ji=class extends rn{constructor(){super(...arguments),this.type=3}j(e){this.element[this.name]=e===_?void 0:e}},Gi=class extends rn{constructor(){super(...arguments),this.type=4}j(e){this.element.toggleAttribute(this.name,!!e&&e!==_)}},Ui=class extends rn{constructor(e,n,r,i,o){super(e,n,r,i,o),this.type=5}_$AI(e,n=this){if((e=nn(this,e,n,0)??_)===tt)return;let r=this._$AH,i=e===_&&r!==_||e.capture!==r.capture||e.once!==r.once||e.passive!==r.passive,o=e!==_&&(r===_||i);i&&this.element.removeEventListener(this.name,this,r),o&&this.element.addEventListener(this.name,this,e),this._$AH=e}handleEvent(e){typeof this._$AH=="function"?this._$AH.call(this.options?.host??this.element,e):this._$AH.handleEvent(e)}},Zi=class{constructor(e,n,r){this.element=e,this.type=6,this._$AN=void 0,this._$AM=n,this.options=r}get _$AU(){return this._$AM._$AU}_$AI(e){nn(this,e)}},rd={M:Ls,P:vt,A:Cs,C:1,L:nd,R:Ki,D:Qc,V:nn,I:Fn,H:rn,N:Gi,U:Ui,B:ji,F:Zi},Wb=Hs.litHtmlPolyfillSupport;Wb?.(Fr,Fn),(Hs.litHtmlVersions??=[]).push("3.3.3");var id=(t,e,n)=>{let r=n?.renderBefore??e,i=r._$litPart$;if(i===void 0){let o=n?.renderBefore??null;r._$litPart$=i=new Fn(e.insertBefore(Rr(),o),o,void 0,n??{})}return i._$AI(t),i};var Vs=globalThis,q=class extends yt{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=id(n,this.renderRoot,this.renderOptions)}connectedCallback(){super.connectedCallback(),this._$Do?.setConnected(!0)}disconnectedCallback(){super.disconnectedCallback(),this._$Do?.setConnected(!1)}render(){return tt}};q._$litElement$=!0,q.finalized=!0,Vs.litElementHydrateSupport?.({LitElement:q});var Kb=Vs.litElementPolyfillSupport;Kb?.({LitElement:q});(Vs.litElementVersions??=[]).push("4.2.2");var ld=[],qi=new Map,jb=0,he=(t,e)=>`pack:${t}:${e}`,wt=t=>t.startsWith("pack:");function Ws(t){ld=t,qi=new Map;for(let e of t)for(let n of e.items)qi.set(he(e.id,n.id),n);jb+=1}var zr=()=>ld;var Gb={};function U(t){if(!wt(t))return;let e=qi.get(t);if(e)return e;let[,n,...r]=t.split(":"),i=Gb[n];return i?qi.get(he(i,r.join(":"))):void 0}var Ub=.22;function od(t,e,n,r){let i=Math.min(Ub,n/3);if(r<=i*2.4||Math.abs(r-n)<1e-6)return e*(r/n)+(t-e)*(r/n);let o=e*(r/n),s=t-e;return s<=i?o+s:s>=n-i?o+r-(n-s):o+i+(s-i)*(r-2*i)/(n-2*i)}function Tr(t,e,n,r,i){return[od(t*r,n*r,r,i)/i,od(e*r,n*r,r,i)/i]}var sd=new WeakMap;function cd(t,e,n,r){let[i,o,s]=t.size;if(t.vehicle||t.stretch||Math.abs(e-i)<1e-4&&Math.abs(n-o)<1e-4&&Math.abs(r-s)<1e-4)return t.parts;let a=`${e.toFixed(4)}|${n.toFixed(4)}|${r.toFixed(4)}`,l=sd.get(t),c=l?.get(a);if(c)return c;let d=t.parts.map(u=>{if(u.shape==="sweep")return u;let[p,h]=Tr(u.x-u.w/2,u.x+u.w/2,-.5,i,e),[f,g]=Tr(u.z-u.d/2,u.z+u.d/2,-.5,o,n),[b,y]=Tr(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*i/e,d:u.d*o/n,y:b,h:y-b};let v={...u,x:(p+h)/2,z:(f+g)/2,w:h-p,d:g-f,y:b,h:y-b};if(u.shape==="loft"){let[w,k,x,M]=[u.tx??u.x,u.tz??u.z,u.tw??u.w,u.td??u.d],[A,T]=Tr(w-x/2,w+x/2,-.5,i,e),[F,L]=Tr(k-M/2,k+M/2,-.5,o,n);Object.assign(v,{tx:(A+T)/2,tz:(F+L)/2,tw:T-A,td:L-F})}return v});return l||sd.set(t,l=new Map),l.size>32&&l.clear(),l.set(a,d),d}var Ks=t=>!!t?.parts.some(e=>e.move);var dd=t=>U(t)?.parts.find(e=>e.screen),ad=.06;function ud(t){let e=U(t);if(!e)return!1;let[n,r,i]=e.size;return e.parts.filter(o=>o.screen).some(o=>{let[s,a]=[o.w*n,o.d*r,o.h*i].sort((l,c)=>c-l);return a>=ad&&s>=ad})}function ut(t){return nt[t]??U(t)?.size??[.6,.6,.8]}function Tt(t){let e=U(t);return yd.has(t)||!!e?.electric||!!e?.light||!!e?.climate}var hd=t=>!!U(t)?.parts.some(e=>e.picture),Tn=t=>!!U(t)?.climate;function pd(t,e){return t.name[e.split("-")[0]]??t.name.en??Object.values(t.name)[0]??t.id}var Zb={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 fd(t,e){if(e.split("-")[0]==="de")return t.name;let n=/^nextfloor\.(.+)$/.exec(t.id)?.[1];return n&&Zb[n]||t.name}function zt(t,e){return e.mount_y!=null?e.mount_y:Yb(t,e)+(qb(e)?0:_d(t,e.x,e.z))}var qb=t=>t.type==="led_strip"||U(t.type)?.mount==="ceiling";function Yb(t,e){if(e.type==="lamp_wall")return md;if(e.type==="led_strip")return Math.max(0,ht(t,e.x,e.z)-.04-Math.max(.02,e.h));let n=U(e.type);if(!n)return gd(e);switch(n.mount){case"surface":return bd(t,e.x,e.z);case"wall":return n.wall_y??1;case"ceiling":return Math.max(0,Yi(t,e)-e.h);default:return 0}}function js(t){if(t==="plant")return"plant";let e=U(t);return e?e.household?e.household:/monstera|plant|herb_garden|flower_pots|bonsai|ficus|cactus|kaktus/.test(e.id)?"plant":null:null}var vd=t=>[t.kind,t.floorId,t.id].filter(Boolean).join(":");function wd(t,e="Geb\xE4ude 1"){if(t.topology)return;let n=P("location"),r=P("branch"),i=P("building");t.topology={locations:[{id:n,name:"Ort 1"}],branches:[{id:r,name:"Niederlassung 1",location_id:n}],buildings:[{id:i,name:e,branch_id:r}]};for(let o of t.floors)o.building_id=i}function Xi(t){let e=t.topology;e.locations??=[],e.branches??=[],e.buildings??=[];let n=o=>(o||=e.locations[0]?.id||P("location"),e.locations.some(s=>s.id===o)||e.locations.push({id:o,name:"Ort"}),o),r=o=>(o||=e.branches[0]?.id||P("branch"),e.branches.some(s=>s.id===o)||e.branches.push({id:o,name:"Niederlassung",location_id:n()}),o),i=o=>(o||=e.buildings[0]?.id||P("building"),e.buildings.some(s=>s.id===o)||e.buildings.push({id:o,name:"Geb\xE4ude",branch_id:r()}),o);for(let o of e.branches)o.location_id=n(o.location_id);for(let o of e.buildings)o.branch_id=r(o.branch_id);for(let o of t.floors)o.outdoor_location_id?(o.outdoor_location_id=n(o.outdoor_location_id),o.building_id=null):o.building_id=i(o.building_id)}function xd(t,e){let n=t.floors.find(i=>i.outdoor_location_id===e);if(n)return n;let r={...Ee(P("outside"),"Au\xDFen",0),outdoor_location_id:e,building_id:null};return t.floors.push(r),r}function Gs(t,e,n){let r=t.floors.find(i=>i.id===e);return n?{kind:"room",id:n,floorId:e}:r?.outdoor_location_id?{kind:"outside",id:r.outdoor_location_id}:{kind:"floor",id:e}}function Xb(t){let e=(i,o,s,a=[],l=a.flatMap(d=>d.floorIds),c)=>{let d={kind:i,...o?{id:o}:{},...c?{floorId:c.floorId}:{}};return{key:vd(d),name:s,selection:d,floorIds:[...new Set(l)],children:a,...c?{room:c}:{}}},n=i=>e("floor",i.id,i.name,i.rooms.map(o=>e("room",o.id,o.name,[],[i.id],{floorId:i.id,roomId:o.id})),[i.id]);if(!t.topology)return e("all",void 0,"Alle Etagen",[...t.floors].sort((i,o)=>o.elevation-i.elevation).map(n));let r=t.topology;return e("all",void 0,"Alle Orte",r.locations.map(i=>{let o=r.branches.filter(a=>a.location_id===i.id).map(a=>e("branch",a.id,a.name,r.buildings.filter(l=>l.branch_id===a.id).map(l=>e("building",l.id,l.name,t.floors.filter(c=>!c.outdoor_location_id&&c.building_id===l.id).sort((c,d)=>d.elevation-c.elevation).map(n))))),s=t.floors.filter(a=>a.outdoor_location_id===i.id);return s.length&&o.push(e("outside",i.id,"Au\xDFen",s.flatMap(a=>a.rooms.map(l=>e("room",l.id,l.name,[],[a.id],{floorId:a.id,roomId:l.id}))),s.map(a=>a.id))),e("location",i.id,i.name,o)}))}function kd(t,e){let n=Xb(t),r=vd(e),i=o=>{if(o.key===r)return[o];for(let s of o.children){let a=i(s);if(a)return[o,...a]}return null};return i(n)??[n]}function $d(t,e,n=!1){if(!t.topology||e.kind==="all")return t.floors;let r=kd(t,e),i=(n&&(e.kind==="floor"||e.kind==="room")?r.find(s=>s.selection.kind==="building"):null)??r.at(-1),o=new Set(i.floorIds);return t.floors.filter(s=>o.has(s.id))}function Pr(t,e){return t.topology?kd(t,Gs(t,e.id)).slice(1).map(n=>n.name).join(" / "):e.name}var xt=["electricity","water","gas","heating","cooling"],Sd=["condition","temperature","humidity","pressure","wind_speed","wind_gust_speed","wind_bearing","cloud_coverage","precipitation","precipitation_total","illuminance","uv_index","visibility","snow","fog","lightning"],Md=["turn","slide","top"],Ed=["always","active","no_power","never"],Rd=1.3,Ji=(t,e=new Date().toISOString().slice(0,10))=>!!t.due&&t.due<=e,Ad=["gable","hip","halfhip","pyramid","mansard","pent","flat","parapet"],Fd=["brick","round","wide","steel"],Qi=["navigate","more_info","service","fire_dom_event"];function eo(t,e,n){return t?e?!!n.lock_plan:!!t.locked:!1}var Td=["rain","snow","fog","clouds","lightning","sky"],zd=["rain","snow","clouds","lightning","sky"],Pd=["lawn","terrace","path","driveway","pavers","stepping_stones","natural_stone","street","sidewalk","gravel","river","stream","pool","bed","wild","hedge","fence","pergola"],Us={lawn:.012,terrace:.12,path:.02,driveway:.02,pavers:.025,stepping_stones:.025,natural_stone:.03,street:.02,sidewalk:.12,gravel:.018,river:.008,stream:.006,pool:-.25,bed:.15,wild:.03,hedge:1.2,fence:1,pergola:2.2};function Zs(t){return t==="hedge"||t==="fence"||t==="pergola"}var Id=["x","-x","z","-z"];function Jb(t,e,n){let r=t.slope??0;if(!r||t.type==="pool")return 0;let i=t.slope_dir??"x",o=(c,d)=>i==="x"?c:i==="-x"?-c:i==="z"?d:-d,s=1/0,a=-1/0;for(let[c,d]of t.points){let u=o(c,d);s=Math.min(s,u),a=Math.max(a,u)}if(a-s<1e-6)return 0;let l=Math.min(1,Math.max(0,(o(e,n)-s)/(a-s)));return r*l}function Qb(t,e,n,r){return Dd(t)+(e.offset??0)+Us[e.type]-Jb(e,n,r)}function Dd(t){return t.elevation>.3?0:-.2}function Od(t,e,n){let r=(t.outdoor??[]).filter(o=>!Zs(o.type)&&o.type!=="pool"&&C([e,n],o.points)),i=[...r].reverse().find(o=>o.cut)??r[0];return i?Qb(t,i,e,n):Dd(t)}var qs=t=>t.cut??(t.type==="pool"||t.type==="river"||t.type==="stream");function to(t){let e=Number.isFinite(t.texture_scale)?Math.max(.05,Math.min(20,t.texture_scale)):1,n=Number.isFinite(t.texture_rotation)?(t.texture_rotation%360+360)%360:0;return{scale:e,rotation:n}}var Hd=30,Ld={meter:null,grid:null,grid_invert:!1,solar:null,battery:null,battery_invert:!1,battery_soc:null,consumption:null,tariff:null},Cd=["wood","oak","tiles","carpet","stone","concrete"],Nd={type:"none",pitch:35,overhang:.4},no="#d6cfc2",ro="#e8e3da",Bd={wall_exterior:.24,wall_interior:.12,grid:.05,north:0,roof:{...Nd}};function Pt(){return{version:1,floors:[],settings:{...Bd},energy:{...Ld},presence:[]}}function Ee(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 ey=2.75;function Vd(t,e){if(e!=null&&Number.isFinite(e))return Math.round(e*ey*100)/100;let n=t.reduce((r,i)=>!r||i.elevation>r.elevation?i:r,null);return n?Math.round((n.elevation+n.height+.25)*100)/100:0}function Wd(t,e,n){let r=t.rooms.flatMap(a=>a.points.map(l=>l[0])),i=t.rooms.flatMap(a=>a.points.map(l=>l[1])),o=r.length?Math.ceil(Math.max(...r))+1:0,s=i.length?Math.floor(Math.min(...i)):0;return e.map((a,l)=>{let c=o+l%3*4.5,d=s+Math.floor(l/3)*3.5;return{id:n(),name:a.name,area_id:a.area_id,points:[[c,d],[c+4,d],[c+4,d+3],[c,d+3]],floor_material:"wood"}})}function Kd(t,e,n,r){let i=t.rotation*Math.PI/180,o=Math.cos(i),s=Math.sin(i),[a,l]=e,c=t.x-a*(t.w/2)*o+l*(t.d/2)*s,d=t.z-a*(t.w/2)*s-l*(t.d/2)*o,u=n[0]-c,p=n[1]-d,h=y=>Math.max(.1,Math.round(y/r)*r),f=h((u*o+p*s)*a),g=h((-u*s+p*o)*l),b=y=>Math.round(y*1e3)/1e3;return{x:b(c+a*(f/2)*o-l*(g/2)*s),z:b(d+a*(f/2)*s+l*(g/2)*o),w:b(f),d:b(g)}}var io=["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","heating_manifold","buffer_tank","freshwater_station","stairwell"],jd={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","heating_manifold","buffer_tank","freshwater_station"],vehicles:["parking"]},Ke=["meter","inverter","home_battery","wallbox","grid_point"],Gd=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"]),md=1.75;function oo(t){return Ys.has(t.type)||["stairwell","parking"].includes(t.type)?!1:U(t.type)?.mount!=="ceiling"}function de(t){return Gd.has(t)||!!U(t)?.light}var ty=new Set(["table","table_round","coffee_table","desk","nightstand","sideboard","dresser","kitchen","island","worktop","tv_board","dishwasher","washer","dryer"]);function Ud(t,e,n,r=0){let i=ue(t.points),o=i.x1-i.x0-2*r,s=i.z1-i.z0-2*r,a=[];for(let l=0;l<e;l++)for(let c=0;c<n;c++){let d=[Math.round((i.x0+r+o/n*(c+.5))*1e3)/1e3,Math.round((i.z0+r+s/e*(l+.5))*1e3)/1e3];C(d,t.points)&&a.push(d)}return a}function zn(t,e,n){let r=s=>Math.round(s*1e3)/1e3,[i,o]={right:[1,0],down:[0,1],left:[-1,0],up:[0,-1]}[n];return[r(t[0]+i*e),r(t[1]+o*e)]}function gd(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 Ys=new Set(["lamp_ceiling","lamp_downlight","lamp_spot","lamp_panel","lamp_pendant","ceiling_fan"]);function Zd(t,e){return t.filter(n=>n.elevation<e.elevation).flatMap(n=>n.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 Xs=t=>t?.floor_offset&&Number.isFinite(t.floor_offset)?t.floor_offset:0;function _d(t,e,n){let r=t.rooms.find(i=>i.points.length>=3&&i.floor_offset&&C([e,n],i.points));return Xs(r)}function ht(t,e,n){let r=t.rooms.find(i=>i.points.length>=3&&C([e,n],i.points));return r?.ceiling!=null&&r.ceiling>0?r.ceiling:t.height}var Yi=(t,e)=>e.ceiling_y!=null&&e.ceiling_y>0?e.ceiling_y:ht(t,e.x,e.z);function bd(t,e,n){let r=0;for(let i of t.furniture)!(ty.has(i.type)||U(i.type)?.surface)||!C([e,n],ta(i))||(r=Math.max(r,i.h));return r}var yd=new Set([...Gd,"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"]),nt={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],heating_manifold:[1.5,.35,1.1],buffer_tank:[.85,.85,1.85],freshwater_station:[.65,.28,.9],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 Js=["interior","front","front_glass","sidelight","sidelights","glass","sliding","passage"],Qs=["standard","bars","glass_wall"],so=new Set(["interior","front"]);function on(t,e){return t.type==="door"?t.style&&Js.includes(t.style)?t.style:e?"front":"interior":t.style&&Qs.includes(t.style)?t.style:"standard"}function qd(t,e,n,r){if(e!=="sidelight"&&e!=="sidelights")return null;let i=e==="sidelights",o=t-.04,s=Math.min(1.05,Math.max(.6,o-(i?.6:.3))),a=(o-s)/(i?2:1),l=r.sidelight_width??a,c=i?r.sidelight_width2??r.sidelight_width??a:0;l=Math.max(.1,l),c=i?Math.max(.1,c):0;let d=o-.5;if(l+c>d){let p=Math.max(0,d)/(l+c);l*=p,c*=p}return i?{panels:[[.02,.02+l],[t-.02-c,t-.02]],x0:.02+l,x1:t-.02-c}:(n?!!r.sidelight_hinge:!r.sidelight_hinge)?{panels:[[.02,.02+l]],x0:.02+l,x1:t-.02}:{panels:[[t-.02-l,t-.02]],x0:.02,x1:t-.02-l}}function ea(t){return t==="front"||t==="front_glass"||t==="sidelight"||t==="sidelights"}var Pn={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 In(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&&ea(t.style)?"front":e?"door_double":"door":t.sill<.1?e?"terrace_double":"terrace":e?"window_double":"window"}function Oe(t){t.energy={...Ld,...t.energy??{}},t.presence=t.presence??[],t.version=1,t.settings={...Bd,...t.settings,roof:{...Nd,...t.settings?.roof??{}}},t.floors.forEach((e,n)=>{let r=Ee(e.id,e.name??`Floor ${n+1}`,e.elevation??n*2.8);for(let i of Object.keys(r))e[i]===void 0&&(e[i]=r[i])});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 i of n){let o=r[i.mount??"ceiling"],[s,a,l]=nt[o],c=`lamp_${i.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:o,x:i.x,z:i.z,rotation:0,w:s,d:a,h:l,variant:null,entity:i.entity_id,power:null,animations_enabled:i.animations_enabled,effect_animations:structuredClone(i.effect_animations)})}e.placements=e.placements.filter(i=>!i.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 ny(t),t.topology&&Xi(t),t}function ny(t){let e=(n,r)=>{let i=new Set;for(let o of n)(typeof o.id!="string"||!o.id||i.has(o.id))&&(o.id=P(r)),i.add(o.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=P("room"));e(n.openings,"op"),e(n.furniture,"furn"),e(n.outdoor,"out")}}function P(t){return`${t}_${Math.random().toString(36).slice(2,10)}`}function be(t){let e=0;for(let n=0;n<t.length;n++){let[r,i]=t[n],[o,s]=t[(n+1)%t.length];e+=r*s-o*i}return e/2}function ye(t){return Math.abs(be(t))}function ve(t){let e=be(t);if(Math.abs(e)<1e-9){let i=t.length||1;return[t.reduce((o,s)=>o+s[0],0)/i,t.reduce((o,s)=>o+s[1],0)/i]}let n=0,r=0;for(let i=0;i<t.length;i++){let[o,s]=t[i],[a,l]=t[(i+1)%t.length],c=o*l-a*s;n+=(o+a)*c,r+=(s+l)*c}return[n/(6*e),r/(6*e)]}function Dn(t){if(t.length!==4)return!1;for(let e=0;e<4;e++){let[n,r]=t[e],[i,o]=t[(e+1)%4];if(Math.abs(n-i)>1e-6&&Math.abs(r-o)>1e-6)return!1}return!0}function ue(t){let e=1/0,n=1/0,r=-1/0,i=-1/0;for(let[o,s]of t)e=Math.min(e,o),n=Math.min(n,s),r=Math.max(r,o),i=Math.max(i,s);return{x0:e,z0:n,x1:r,z1:i}}function ta(t){let e=t.rotation*Math.PI/180,n=Math.cos(e),r=Math.sin(e),i=t.w/2,o=t.d/2;return[[-i,-o],[i,-o],[i,o],[-i,o]].map(([s,a])=>[t.x+s*n-a*r,t.z+s*r+a*n])}function C(t,e){let n=!1;for(let r=0,i=e.length-1;r<e.length;i=r++){let[o,s]=e[r],[a,l]=e[i];s>t[1]!=l>t[1]&&t[0]<(a-o)*(t[1]-s)/(l-s)+o&&(n=!n)}return n}var ao={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 fe=J`
:host {
--nf-text: var(--primary-text-color, #e1e1e1);
--nf-muted: var(--secondary-text-color, #9b9b9b);
--nf-accent: var(--primary-color, #03a9f4);
--nf-accent-text: var(--text-primary-color, #ffffff);
--nf-surface: var(--ha-card-background, var(--card-background-color, #1c1c1c));
--nf-bg: var(--primary-background-color, #111111);
--nf-bg2: var(--secondary-background-color, #1c1c1c);
/* floating bars and cards over the 3D view: the card colour, a little see-through */
--nf-chrome: color-mix(in srgb, var(--nf-surface) var(--nf-chrome-mix, 84%), transparent);
--nf-chrome-solid: var(--nf-surface);
--nf-line: var(--divider-color, rgba(255, 255, 255, 0.12));
/* quiet fills for buttons and fields, and the tonal accent of an active control */
--nf-fill: color-mix(in srgb, var(--nf-text) 7%, transparent);
--nf-fill-strong: color-mix(in srgb, var(--nf-text) 13%, transparent);
--nf-tonal: color-mix(in srgb, var(--nf-accent) 20%, transparent);
--nf-soft: var(--info-color, #4a90e2);
--nf-warm: var(--state-light-active-color, #ffa726);
--nf-danger: var(--error-color, #db4437);
--nf-good: var(--success-color, #43a047);
--nf-radius: var(--ha-card-border-radius, 12px);
--nf-shadow: var(--ha-card-box-shadow, 0 1px 2px rgba(0, 0, 0, 0.18), 0 6px 20px rgba(0, 0, 0, 0.2));
--nf-font: var(--primary-font-family, Roboto, "Noto Sans", system-ui, -apple-system, "Segoe UI", sans-serif);
--nf-title-font: var(--nf-font);
font-family: var(--nf-font);
color: var(--nf-text);
}
`,t$=J`
:host([readable]) {
--secondary-text-color: var(--primary-text-color, #e1e1e1);
--divider-color: color-mix(in srgb, var(--primary-text-color, #e1e1e1) 40%, transparent);
--nf-chrome-mix: 97%;
}
:host([readable]) nf-room-panel,
:host([readable]) .nf-nav,
:host([readable]) .nf-overlay {
zoom: 1.2;
}
`,pt=J`
/* a group of switches: one rounded pill, the active one tinted with the accent */
.nf-seg {
display: inline-flex;
padding: 4px;
gap: 2px;
border-radius: 999px;
background: var(--nf-chrome);
box-shadow: var(--nf-shadow);
backdrop-filter: blur(10px);
}
.nf-seg button,
.nf-chip {
font: inherit;
font-size: 14px;
font-weight: 500;
border: none;
background: none;
color: var(--nf-muted);
padding: 7px 14px;
border-radius: 999px;
cursor: pointer;
white-space: nowrap;
min-height: 36px;
transition:
background 0.15s,
color 0.15s;
}
.nf-seg button:hover:not(:disabled),
.nf-chip:hover {
background: var(--nf-fill);
color: var(--nf-text);
}
/* on a small stage (a small window, a zoomed browser, a dashboard column) the switches at the bottom take less room */
@container nf ((max-width: 1360px) or (max-height: 640px)) {
:is(.nf-overlay, .nf-card-controls) .nf-seg {
padding: 3px;
}
:is(.nf-overlay, .nf-card-controls) :is(.nf-seg button, .nf-chip) {
font-size: 12.5px;
padding: 5px 10px;
}
}
.nf-time-slider {
display: inline-flex;
align-items: center;
padding: 4px 10px;
}
.nf-time-slider input {
width: 160px;
accent-color: var(--nf-accent);
}
.nf-seg button[aria-pressed="true"],
.nf-chip[aria-pressed="true"] {
background: color-mix(in srgb, var(--nf-accent) 24%, var(--nf-chrome-solid));
color: var(--nf-accent);
font-weight: 600;
}
.nf-seg button:disabled {
opacity: 0.4;
cursor: default;
}
/* a single pill, like the chips of the Mushroom cards */
.nf-chip {
background: var(--nf-chrome);
color: var(--nf-text);
box-shadow: var(--nf-shadow);
backdrop-filter: blur(10px);
}
button:focus-visible,
input:focus-visible,
select:focus-visible {
outline: 2px solid var(--nf-accent);
outline-offset: 2px;
}
/* the round icon badge every row and card starts with */
.nf-ico {
display: inline-flex;
align-items: center;
justify-content: center;
flex: none;
width: 38px;
height: 38px;
border-radius: 50%;
background: var(--nf-tonal);
color: var(--nf-accent);
--mdc-icon-size: 20px;
}
.nf-ico.nf-warm {
background: color-mix(in srgb, var(--nf-warm) 22%, transparent);
color: var(--nf-warm);
}
.nf-ico.nf-off {
background: var(--nf-fill);
color: var(--nf-muted);
}
.nf-btn {
font: inherit;
font-size: 14px;
font-weight: 500;
border: none;
background: var(--nf-fill);
color: var(--nf-text);
border-radius: var(--nf-radius);
padding: 7px 14px;
cursor: pointer;
min-height: 36px;
transition: background 0.15s;
}
.nf-btn:hover {
background: var(--nf-fill-strong);
}
.nf-btn.nf-danger {
color: var(--nf-danger);
}
.nf-btn.nf-primary {
background: var(--nf-accent);
color: var(--nf-accent-text);
}
.nf-btn.nf-primary:hover {
background: color-mix(in srgb, var(--nf-accent) 88%, var(--nf-text));
}
.nf-field {
display: grid;
gap: 4px;
font-size: 12px;
color: var(--nf-muted);
}
.nf-field input,
.nf-field select,
.nf-field textarea {
font: inherit;
font-size: 14px;
color: var(--nf-text);
background: var(--nf-fill);
border: none;
border-bottom: 1px solid var(--nf-line);
border-radius: 10px 10px 4px 4px;
padding: 8px 10px;
min-width: 0;
}
.nf-field input:focus,
.nf-field select:focus,
.nf-field textarea:focus {
border-bottom-color: var(--nf-accent);
}
.nf-field input[type="range"] {
padding: 0;
accent-color: var(--nf-accent);
}
.nf-field select option {
background: var(--nf-chrome-solid);
color: var(--nf-text);
}
/* fingers need 40 px */
@media (pointer: coarse) {
.nf-seg button,
.nf-chip,
.nf-btn {
min-height: 40px;
}
}
`;var On={ATTRIBUTE:1,CHILD:2,PROPERTY:3,BOOLEAN_ATTRIBUTE:4,EVENT:5,ELEMENT:6},sn=t=>(...e)=>({_$litDirective$:t,values:e}),It=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 Ir=class extends It{constructor(e){if(super(e),this.it=_,e.type!==On.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===tt)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:[]}}};Ir.directiveName="unsafeHTML",Ir.resultType=1;var Yd=sn(Ir);var ra=t=>t.slice(0,t.indexOf(".")),ry={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"},ee=t=>ry[ra(t)]??null,ia=["light","cover","climate","media","switch","fan","lock","binary","sensor","scene","script"];var Xd=new Set(["light","switch","fan"]),Dt=t=>t!==null&&t!=="scene"&&t!=="script",He=t=>!t||t.state==="unavailable"||t.state==="unknown"&&!t.entity_id.startsWith("event.");function B(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 i=r.slice(n.length+1);return i[0].toUpperCase()+i.slice(1)}var Jd=t=>!!t&&t.entity_id.startsWith("sensor.")&&t.attributes.device_class==="enum";var Qd=t=>Math.min(1,Math.max(0,t));function iy(t){let e=Qd((t-2200)/4300),n=[1,.66,.26],r=[.78,.9,1];return[0,1,2].map(i=>n[i]+(r[i]-n[i])*e)}function na(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(Qd(n.brightness/255)):1,i=n.rgb_color;return i&&!["color_temp","brightness","onoff"].includes(String(n.color_mode))?{color:[i[0]/255,i[1]/255,i[2]/255],level:r}:typeof n.color_temp_kelvin=="number"?{color:iy(n.color_temp_kelvin),level:r}:{color:[1,.71,.28],level:r}}function eu(t,e,n){let r=na(t,n);if(r)return r;for(let i of e){let o=na(i);if(o)return{color:o.color,level:o.level*.6}}return null}function lo(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 oa=t=>t.trim().replace(/^\/local\/www\//i,"/local/"),sa=t=>/^(https:\/\/|\/local\/|\/hacsfiles\/)\S+\.m?js(\?\S*)?$/i.test(t.trim());var sy=globalThis,nu=sy.__nextfloorPluginStore??={plugins:new Map,listeners:new Set},aa=nu.plugins,tu=nu.listeners;var ay=5;function ru(t,e){t.errors.length<ay&&t.errors.push(e instanceof Error?e.message:String(e))}function co(t){return tu.add(t),()=>tu.delete(t)}var la=()=>[...aa.values()].map(t=>t.status),iu=()=>[...aa.values()].flatMap(t=>Object.keys(t.plugin.lightAnimations??{}));function*uo(t,e){for(let{plugin:n,status:r}of aa.values())for(let i of n.devices??[]){let o=!1;try{o=i.match(t,e)}catch(s){ru(r,s)}o&&(yield{device:i,status:r})}}function ho(t,e){for(let{device:n}of uo(t,e))return n.kind??"sensor";return null}function ou(t,e){let n=t.states[e];if(!n)return null;let r=ly({hass:t,entityId:e,state:n})?.icon?.trim();return r&&/^mdi:[a-z0-9-]+$/i.test(r)?r:null}function ly(t){let e=null;for(let{device:n,status:r}of uo(t.entityId,t.state))if(n.marker)try{let i=n.marker(t);if(!i)continue;e={...e??{}},typeof i.icon=="string"&&i.icon&&(e.icon=i.icon),typeof i.text=="string"&&(e.text=i.text.slice(0,60)),typeof i.active=="boolean"&&(e.active=i.active)}catch(i){ru(r,i)}return e}function po(t,e){return t?typeof t=="string"?t:t[e]??t[e.split("-")[0]]??t.en??Object.values(t)[0]??"":""}function su(t,e){let n=[];for(let{device:r,status:i}of uo(t,e))r.settings?.length&&n.push({pluginId:i.id,name:i.name,settings:r.settings});return n}function au(t,e){let n={};for(let r of t??[]){let i=e?.[r.key],o=r.type==="number"?typeof i=="number"&&Number.isFinite(i):r.type==="boolean"?typeof i=="boolean":typeof i=="string"&&(r.options??[]).some(([s])=>s===i);n[r.key]=o?i:r.default}return n}function lu(t,e){for(let{device:n}of uo(t,e))if(n.floorWedge)return!0;return!1}var cy=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"]),dy=new Set(["m\xB3","m3","L","l","kWh","Wh","MWh","lx"]),uy=new Set(["door","window","opening","garage_door","motion","occupancy","presence","smoke","moisture","gas","carbon_monoxide"]),hy=new Set(["battery","signal_strength","timestamp","date","duration","data_rate","data_size","frequency","enum"]);function Ot(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 du=(t,e)=>{let n=t.entities?.[e];return!!(n?.hidden||n?.entity_category)},je=(t,e)=>ee(e)??ho(e,t.states[e]);function cu(t,e){let n=t.states[e];if(!n||du(t,e))return!1;if(ho(e,n)!==null)return!0;let r=ee(e);if(!r)return!1;let i=n.attributes.device_class;return e.startsWith("event.")?!i||i==="button"||i==="doorbell":r==="sensor"?i?cy.has(i):dy.has(String(n.attributes.unit_of_measurement??"")):r==="binary"?i?uy.has(i):!!t.entities?.[e]?.area_id:!0}function py(t,e){let n=t.states[e];return ee(e)!=="sensor"||!n?.attributes.unit_of_measurement||du(t,e)||hy.has(String(n.attributes.device_class??""))?!1:Number.isFinite(Number(n.state))||He(n)}var mo=(t,e)=>e.startsWith("sensor.")&&t.states[e]?.attributes.device_class==="power",ca=null;co(()=>ca=null);function da(t,e){let n=t.get(e);return n||t.set(e,n=[]),n}function fy(t){let e=new Map,n=new Map,r=new Map,i=new Map,o=[],s=d=>{(cu(t,d)||py(t,d))&&Dt(je(t,d))&&o.push(d)};for(let[d,u]of Object.entries(t.entities??{})){let p=u.device_id;p&&u.area_id&&(i.get(p)??i.set(p,new Set).get(p)).add(u.area_id),p&&mo(t,d)&&da(n,p).push(d),p&&!u.hidden&&!u.entity_category&&(r.get(p)??r.set(p,new Set).get(p)).add(ra(d));let h=Ot(t,d);h===null?s(d):cu(t,d)&&da(e,h).push(d)}if(t.entities)for(let d of Object.keys(t.states))t.entities[d]||s(d);let a=ia.indexOf("binary")-.5,l=d=>{let u=ee(d),p=u?ia.indexOf(u):a;return p>a&&ho(d,t.states[d])!==null?a:p};o.sort((d,u)=>l(d)-l(u)||B(t,d).localeCompare(B(t,u)));for(let[d,u]of e){let p=t.areas?.[d]?.name;u.sort((h,f)=>l(h)-l(f)||B(t,h,p).localeCompare(B(t,f,p)))}let c=new Set;for(let[d,u]of i)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:o,domainsByDevice:r,hubs:c}}function Hn(t){let e=ca;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:ca=fy(t)}function we(t,e){let n=fo(t,e.area_id);return e.sub_areas?.length?[...new Set([...n,...e.sub_areas.flatMap(r=>fo(t,r))])]:n}function fo(t,e){return!e||!t.entities?[]:Hn(t).byArea.get(e)??[]}function uu(t,e){if(!t.entities)return[];let n=[];for(let[r,i]of Hn(t).byArea){let o=i.filter(s=>Dt(je(t,s)));r!==e&&o.length>0&&n.push({areaId:r,name:t.areas?.[r]?.name??r,ids:o})}return n.sort((r,i)=>r.name.localeCompare(i.name))}var hu=t=>t.entities?Hn(t).withoutArea:[],ua=(t,e)=>!!t.entities&&Hn(t).hubs.has(e),go=(t,e)=>t.entities?Hn(t).powerByDevice.get(e)??[]:[];function Ln(t,e){let n=new Map;for(let i of e)da(n,t.entities?.[i]?.device_id??`entity:${i}`).push(i);let r=new Map(e.map((i,o)=>[i,o]));return[...n.values()].map(i=>{let o=i.find(s=>!t.entities?.[s]?.name)??i[0];return{primary:o,others:i.filter(s=>s!==o)}}).sort((i,o)=>r.get(i.primary)-r.get(o.primary))}var _o=(t,e)=>Ln(t,e).map(n=>n.primary),my={temperature:"temperature",humidity:"humidity",co2:"carbon_dioxide",illuminance:"illuminance"};function ha(t,e,n,r=!1){let i=t.states[e]?.attributes;if(!i)return!1;let o=(i.symcon_variable_type===1||i.symcon_variable_type===2)&&typeof i.symcon_id=="number";if(typeof i.symcon_id=="number"&&!o||!o&&!/^(sensor|input_number|number)\./.test(e))return!1;if(r&&o)return!0;let s=String(i.unit_of_measurement??"").replace(/\s/g,"").toLowerCase();return n==="temperature"&&["\xB0c","\xB0f","\u2103","\u2109","k"].includes(s)||n==="humidity"&&!i.device_class&&["%","%rh","%r.h.","%rf","%r.f."].includes(s)||n==="co2"&&s==="ppm"&&/co[₂2]/i.test(String(i.friendly_name??""))||n==="illuminance"&&["lx","lux"].includes(s)?!0:i.device_class===my[n]}var gy=new Set(["climate","water_heater","switch","button","camera","media_player","vacuum","light","fan","lawn_mower"]),_y=["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"],by=new RegExp(`(${_y.join("|")})`,"i");function pa(t,e){let n=t.entities?.[e]?.device_id,r=n&&!ua(t,n)?Hn(t).domainsByDevice.get(n):void 0;return r&&[...r].some(i=>gy.has(i))?!1:!by.test(`${e} ${t.states[e]?.attributes.friendly_name??""}`)}function pu(t,e,n,r){let i=n.climate?.[r];if(i==="none")return[];if(i)return[i].flat().filter(c=>t.states[c]);let o=(e?.placements??[]).filter(c=>c.entity_id.startsWith("sensor.")),s=o.filter(c=>C([c.x,c.z],n.points)).map(c=>c.entity_id),a=new Set(o.filter(c=>!C([c.x,c.z],n.points)).map(c=>c.entity_id));return[...new Set([...we(t,n).filter(c=>!a.has(c)),...s])].filter(c=>c.startsWith("sensor.")&&ha(t,c,r)&&pa(t,c))}function fu(t){let e=t.attributes;if(typeof e.symcon_numeric_value!="number")return null;let n=typeof e.symcon_min=="number"?e.symcon_min:0,r=typeof e.symcon_max=="number"&&e.symcon_max>n?e.symcon_max:100;return Math.max(0,Math.min(100,(e.symcon_numeric_value-n)/(r-n)*100))}function bo(t,e){let n=t?.states[e];if(!n)return!1;let r=n.attributes;return typeof r.symcon_id=="number"?r.symcon_variable_type===1||r.symcon_variable_type===2:typeof r.current_position=="number"||/^(sensor|number|input_number)\./.test(e)&&!!n.state.trim()&&Number.isFinite(Number(n.state))}function yo(t,e){let n=e?t.states[e]:void 0;if(!n||He(n))return null;let r=n.attributes;if(r.nf_cover_control&&typeof r.current_position=="number")return r.current_position;let i=fu(n);if(i!==null)return i;if(typeof r.current_position=="number")return Math.max(0,Math.min(100,r.current_position));if(!n.state.trim())return null;let o=Number(n.state);if(!Number.isFinite(o))return null;let s=r.unit_of_measurement==="%"||o>1||o<0?o:o*100;return Math.max(0,Math.min(100,s))}var yy=new Set([void 0,"shutter","blind","awning","shade","curtain","window"]),vy=new Set(["garage","gate"]),wy=new Set(["window","opening"]);function Dr(t,e,n=!1){let r=new Map;return t.forEach((i,o)=>{let s=n&&e.length===1?e[0]:e[o];s&&r.set(i.id,s)}),r}var mu=(t,e)=>t==="none"?null:t??e??null,Ht=t=>t&&t!=="none"?t:null;function Lt(t,e){let n=new Map;for(let r of e)for(let i of r.rooms){let o=r.openings.filter(g=>g.room_id===i.id).sort((g,b)=>g.edge-b.edge||g.offset-b.offset);if(o.length===0)continue;let s=we(t,i),a=g=>t.states[g]?.attributes.device_class,l=g=>s.filter(b=>ee(b)==="binary"&&g(a(b)??"")),c=g=>o.filter(b=>b.type===g),d=Dr(c("window"),s.filter(g=>ee(g)==="cover"&&yy.has(a(g))),!0),u=Dr(c("window"),l(g=>wy.has(g))),p=Dr(c("door"),l(g=>g==="door")),h=Dr(c("garage"),s.filter(g=>ee(g)==="cover"&&vy.has(a(g)??""))),f=Dr(c("garage"),l(g=>g==="garage_door"));for(let g of o){let b=g.type==="window"?d:g.type==="garage"?h:null,y=g.type==="window"?u:g.type==="garage"?f:p,v=g.leaves===2;n.set(g.id,{cover:mu(g.cover,b?.get(g.id)),contact:g.sensor==="handle"&&g.contact==null?null:mu(g.contact,y.get(g.id)),tilt:g.tilt==="none"?null:g.tilt,contact2:v?Ht(g.contact2):null,tilt2:v?Ht(g.tilt2):null,position:Ht(g.position),positionInverted:!!g.position_inverted,tiltAngle:Ht(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"?Ht(g.lock):null,cover2:g.type==="garage"?null:Ht(g.cover2),coverTilt:Ht(g.cover_tilt),cover2Tilt:Ht(g.cover2_tilt),coverInverted:!!g.cover_inverted,coverTiltInverted:!!g.cover_tilt_inverted,cover2Inverted:!!g.cover2_inverted,cover2TiltInverted:!!g.cover2_tilt_inverted})}}return n}var xy=[[/^(tilted|tilt|gekippt|kipp)/i,"tilted"],[/^(open|opened|offen|geöffnet|on)$/i,"open"],[/^(closed|close|geschlossen|zu|off)$/i,"closed"]];function fa(t){if(!t||He(t))return null;let e=t.attributes.window_state;for(let n of[typeof e=="string"?e:"",t.state]){let r=n.trim(),i=r&&xy.find(([o])=>o.test(r));if(i)return i[1]}return null}var gu=/\b(tv|fernseh|television|fire ?tv|apple ?tv|chromecast|shield)/i,_u=/(kühl|fridge|gefrier|freezer)/i,bu=/(spülmaschine|geschirrspül|dishwasher)/i,ky=/(kochfeld|herd|induktion|cooktop)/i,$y={robot_vacuum:/(saug|vacuum|robo|roomba|roborock|dreame|ecovacs|deebot)/i,tv_board:gu,tv_wall:gu,desk:/\b(pc|computer|rechner|desktop|monitor|workstation)/i,fridge:_u,fridge_smart:_u,stove:/(herd|kochfeld|cooktop|stove|induktion)/i,kitchen_tall:/(backofen|oven|ofen)/i,dishwasher:bu,washer:/(waschmaschine|washer|washing)/i,dryer:/(trockner|dryer)/i,kitchen:/(kaffee|coffee|wasserkocher|kettle)/i,island:ky,sink:bu,radiator:/(heiz|radiator|thermostat|climate|hk|trv)/i},yu={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},vu=new Set(["tv_board","tv_wall"]);var Cn=t=>vu.has(t)||!!dd(t),vo=t=>!!U(t)?.electric&&/speaker|multiroom|soundbar/.test(t.split(":").pop()??t),Hr=t=>Cn(t)||t==="desk"||t==="fridge_smart",Sy=t=>!!t&&t!=="none";function My(t,e){if(mo(t,e))return e;let n=t.entities?.[e]?.device_id;return n?go(t,n).find(r=>r!==e)??null:null}var Ey=(t,e,n)=>t.rooms.find(r=>r.points.length>=3&&C([e,n],r.points));function Or(t,e,n,r){return t.find(i=>e?.test(n(i)))??(r?t[0]??null:null)}function Re(t,e){let n=new Map;for(let r of e){let i=new Set([...r.furniture.flatMap(o=>[o.entity,o.power,o.fan_entity]),...r.placements.map(o=>o.entity_id)].filter(Sy));for(let o of r.furniture){let s=o.type in yu,a=Tn(o.type),l=s?yu[o.type]:$y[o.type];if(!l&&!a&&!vo(o.type)&&o.entity==null&&o.power==null)continue;let c=Ey(r,o.x,o.z),d=(c?_o(t,we(t,c)):[]).filter(b=>!i.has(b)),u=b=>`${b} ${B(t,b)}`,p=b=>d.filter(y=>ee(y)===b),h=o.entity==="none"?null:o.entity??null;if(o.entity==null){if(o.type==="ceiling_fan"){let b=(c?we(t,c):[]).filter(v=>!i.has(v)),y=new Set(b.filter(v=>ee(v)==="fan").map(v=>t.entities?.[v]?.device_id).filter(Boolean));h=b.find(v=>ee(v)==="light"&&y.has(t.entities?.[v]?.device_id))??Or(p("light"),l,u,!1)}else if(s)h=Or(p("light"),l,u,!0);else if(o.type==="robot_vacuum"){let b=c?.area_id??null;h=Object.keys(t.entities??{}).find(y=>y.startsWith("vacuum.")&&!i.has(y)&&Ot(t,y)===b)??null}else if(o.type==="radiator"||a)h=Or(p("climate"),l,u,!0);else if(Cn(o.type)){let b=p("media");h=b.find(y=>t.states[y]?.attributes.device_class==="tv")??Or(b,l,u,vu.has(o.type))}else if(vo(o.type)){let b=p("media").filter(y=>t.states[y]?.attributes.device_class!=="tv");h=Or(b,l,u,!1)??(b.length===1?b[0]:null)}else l&&(h=d.find(b=>["switch","media","fan"].includes(ee(b)??"")&&l.test(u(b)))??null);h&&i.add(h)}let f=o.power==="none"?null:o.power??null;o.power==null&&(f=h?My(t,h):null,!f&&l&&c&&!s&&(f=we(t,c).find(b=>mo(t,b)&&!i.has(b)&&l.test(u(b)))??null),f&&i.add(f));let g=null;if(o.type==="ceiling_fan"&&(g=o.fan_entity==="none"?null:o.fan_entity??null,o.fan_entity==null)){let b=(c?we(t,c):[]).filter(v=>ee(v)==="fan"&&!i.has(v)),y=h?t.entities?.[h]?.device_id:void 0;g=(y?b.find(v=>t.entities?.[v]?.device_id===y):void 0)??b[0]??null,g&&i.add(g)}(h||f||g)&&n.set(o.id,{entity:h,power:f,...o.type==="ceiling_fan"?{fan:g}:{}})}}return n}var wu=t=>t==="fridge"||t==="fridge_smart"||/(fridge|freezer|kuehl|gefrier|chest_freezer)/.test(t.slice(t.lastIndexOf(":")+1));function xu(t,e,n=[]){let r=[];for(let i of e){let o=(a,l)=>i.rooms.some(c=>c.points.length>=3&&C([a,l],c.points)),s=Re(t,[i]);r.push(...i.placements.filter(a=>a.outside||!o(a.x,a.z)).map(a=>a.entity_id)),r.push(...i.furniture.filter(a=>!o(a.x,a.z)).flatMap(a=>[s.get(a.id)?.entity,s.get(a.id)?.power]));for(let a of i.outdoor??[])a.area_id&&r.push(..._o(t,fo(t,a.area_id))),r.push(a.pump_entity,a.temp_entity)}return[...new Set(r.filter(i=>!!i&&!!t.states[i]&&!n.includes(i)))]}function Ry(t,e){return Math.min(...e.map((n,r)=>{let i=e[(r+1)%e.length],[o,s]=[i[0]-n[0],i[1]-n[1]],a=Math.min(1,Math.max(0,((t[0]-n[0])*o+(t[1]-n[1])*s)/(o*o+s*s||1)));return Math.hypot(t[0]-n[0]-o*a,t[1]-n[1]-s*a)}))}function $u(t,e,n=[]){let r=t.points;if(r.length<3||e.length===0)return[];let i=r.map(y=>y[0]),o=r.map(y=>y[1]),[s,a,l,c]=[Math.min(...i),Math.max(...i),Math.min(...o),Math.max(...o)],d=Math.min(a-s,c-l),u=Math.max(.1,Math.min(.25,d/8)),p=Math.min(.35,d/5),h=Math.min(.7,d/4),f=ve(r),g=[];for(let y=s+u/2;y<a;y+=u)for(let v=l+u/2;v<c;v+=u){let w=[y,v];if(!C(w,r))continue;let k=Ry(w,r);k>=p&&g.push({at:w,wallDistance:k})}g.length===0&&g.push({at:f,wallDistance:0});let b=[...n];return e.map(y=>{let v=ee(y)==="light",w=g[0].at,k=-1/0;for(let{at:M,wallDistance:A}of g){let T=b.length?Math.min(...b.map(I=>Math.hypot(M[0]-I[0],M[1]-I[1]))):3,F=Math.hypot(M[0]-f[0],M[1]-f[1]),L=Math.min(T,3)*2;F<h&&!v&&(L-=10),L-=v?F*.35:A*1.2,L>k+1e-9&&(k=L,w=M)}let x=[Math.round(w[0]*100)/100,Math.round(w[1]*100)/100];return b.push(x),{entity_id:y,x:x[0],z:x[1],y:null,mount:null}})}var ku=/(^|_)(current_room|current_segment|aktueller_raum|current_area)($|_)/;function Su(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(o=>o.device_id===r&&o.entity_id.startsWith("sensor.")&&(ku.test(o.translation_key??"")||ku.test(o.entity_id.split(".")[1])))?.entity_id??null}var Z=t=>t?.symconObjects!==void 0;function Le(t,e,n=[0,1,2,3]){let r=t?.states[e]?.attributes;return!!r?.symcon_id&&!r.symcon_source_entity&&n.includes(Number(r.symcon_variable_type))}function an(t){return!t||t.state==="unknown"||t.state==="unavailable"?null:t.attributes.symcon_value??t.attributes.symcon_numeric_value??t.state}function Ct(t){let e=an(t);if(e===null||typeof e=="boolean"||e==="")return null;let n=Number(e);return Number.isFinite(n)?n:null}function Lr(t){let e=an(t);if(e===null)return null;if(typeof e=="boolean")return e;if(typeof e=="number")return e>0;let n=String(e).trim().toLowerCase();if(["on","true","1","home","open","an","ein","ja","regen","rain","wet","nass"].includes(n))return!0;if(["off","false","0","not_home","closed","aus","nein","trocken","dry"].includes(n))return!1;let r=Number(n);return n!==""&&Number.isFinite(r)?r>0:null}function ma(t){return an(t)===null?"\u2013":String(t?.attributes.symcon_formatted??an(t))}var ge=t=>/^(sensor|input_number|number)\./.test(t),wo=t=>/^(binary_sensor|input_boolean)\./.test(t);function Nn(t,e){if(!ge(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 Ay(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 O(t,e){return Object.keys(t?.states??{}).filter(e).map(n=>{let r=Ay(t,n),i=t?.states[n],o=typeof i?.attributes.symcon_path=="string"?i.attributes.symcon_path:void 0,s={id:n,label:r?`${B(t,n)} \xB7 ${r}`:B(t,n)};return o&&(s.detail=`Objektbaum: ${o}`),typeof i?.attributes.symcon_source_entity=="string"&&(s.sourceEntity=i.attributes.symcon_source_entity),s}).sort((n,r)=>n.label.localeCompare(r.label))}function Mu(t,e,n){return e.unsupported?[]:O(t,r=>Le(t,r,e.types)&&!e.excluded?.(r)).map(r=>{if(!e.role)return r;let i=t.states[r.id],o=`${e.role}.${i.attributes.symcon_id}`,s=n?t.states[n]:void 0,a=n&&(n===r.id||s?.attributes.symcon_source_entity===r.id)?n:t.states[o]?o:r.id;return a===r.id?r:{...r,id:a,sourceEntity:r.id}})}function xo(t,e){return t.power&&t.power!=="none"?t.power:e.get(t.id)?.power??null}var{I:Fy}=rd,Eu=t=>t;var Au=t=>t.strings===void 0,Ru=()=>document.createComment(""),Bn=(t,e,n)=>{let r=t._$AA.parentNode,i=e===void 0?t._$AB:e._$AA;if(n===void 0){let o=r.insertBefore(Ru(),i),s=r.insertBefore(Ru(),i);n=new Fy(o,s,t,t.options)}else{let o=n._$AB.nextSibling,s=n._$AM,a=s!==t;if(a){let l;n._$AQ?.(t),n._$AM=t,n._$AP!==void 0&&(l=t._$AU)!==s._$AU&&n._$AP(l)}if(o!==i||a){let l=n._$AA;for(;l!==o;){let c=Eu(l).nextSibling;Eu(r).insertBefore(l,i),l=c}}}return n},Nt=(t,e,n=t)=>(t._$AI(e,n),t),Ty={},Fu=(t,e=Ty)=>t._$AH=e,Tu=t=>t._$AH,ko=t=>{t._$AR(),t._$AA.remove()};var zu=(t,e,n)=>{let r=new Map;for(let i=e;i<=n;i++)r.set(t[i],i);return r},ln=sn(class extends It{constructor(t){if(super(t),t.type!==On.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 i=[],o=[],s=0;for(let a of t)i[s]=r?r(a,s):s,o[s]=n(a,s),s++;return{values:o,keys:i}}render(t,e,n){return this.dt(t,e,n).values}update(t,[e,n,r]){let i=Tu(t),{values:o,keys:s}=this.dt(e,n,r);if(!Array.isArray(i))return this.ut=s,o;let a=this.ut??=[],l=[],c,d,u=0,p=i.length-1,h=0,f=o.length-1;for(;u<=p&&h<=f;)if(i[u]===null)u++;else if(i[p]===null)p--;else if(a[u]===s[h])l[h]=Nt(i[u],o[h]),u++,h++;else if(a[p]===s[f])l[f]=Nt(i[p],o[f]),p--,f--;else if(a[u]===s[f])l[f]=Nt(i[u],o[f]),Bn(t,l[f+1],i[u]),u++,f--;else if(a[p]===s[h])l[h]=Nt(i[p],o[h]),Bn(t,i[u],i[p]),p--,h++;else if(c===void 0&&(c=zu(s,h,f),d=zu(a,u,p)),c.has(a[u]))if(c.has(a[p])){let g=d.get(s[h]),b=g!==void 0?i[g]:null;if(b===null){let y=Bn(t,i[u]);Nt(y,o[h]),l[h]=y}else l[h]=Nt(b,o[h]),Bn(t,i[u],b),i[g]=null;h++}else ko(i[p]),p--;else ko(i[u]),u++;for(;h<=f;){let g=Bn(t,l[f+1]);Nt(g,o[h]),l[h++]=g}for(;u<=p;){let g=i[u++];g!==null&&ko(g)}return this.ut=s,Fu(t,l),tt}});var zy=new Intl.Collator("de",{numeric:!0,sensitivity:"base"}),ga=-1,Iu=[{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"}],Pu=t=>t.object_type===1&&Iu.some(e=>e.type===t.module_type);function Py(t){let e=new Map(t.map(l=>[l.object_id,l])),n=t.filter(l=>{if(!Pu(l))return!1;let c=new Set([l.object_id]),d=e.get(l.parent_id);for(;d&&!c.has(d.object_id);){if(Pu(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),i=new Map;for(let l of t){let c=i.get(l.parent_id)??[];c.push(l),i.set(l.parent_id,c)}let o=(l,c,d,u,p)=>({object_id:l,parent_id:c,name:d,path:u,position:p,object_type:0,hidden:!1,icon:"",virtual:!0});r.set(ga,o(ga,0,"System","System",Number.MAX_SAFE_INTEGER));let s=new Set,a=(l,c,d)=>{if(s.has(l.object_id))return;s.add(l.object_id);let u={...l,parent_id:c,path:`${d} / ${l.name}`};r.set(l.object_id,u);for(let p of i.get(l.object_id)??[])a(p,l.object_id,u.path)};return Iu.forEach((l,c)=>{let d=n.filter(h=>h.module_type===l.type);if(!d.length)return;let u=-10-l.type,p=`System / ${l.name}`;r.set(u,o(u,ga,l.name,p,c));for(let h of d)a(h,u,p)}),[...r.values()]}function _a(t){let e=Py(t),n=new Map(e.map(i=>[i.object_id,i])),r=new Map;for(let i of e){let o=n.has(i.parent_id)?i.parent_id:0,s=r.get(o)??[];s.push(i),r.set(o,s)}for(let i of r.values())i.sort((o,s)=>o.position-s.position||o.object_type-s.object_type||zy.compare(o.name,s.name));return{nodes:n,children:r}}function ba(t,e){let n=[],r=new Set([e]),i=t.nodes.get(e)?.parent_id;for(;i&&!r.has(i)&&t.nodes.has(i);)n.push(i),r.add(i),i=t.nodes.get(i)?.parent_id;return n}function ya(t,e,n=""){let r=n.trim().toLocaleLowerCase("de").split(/\s+/).filter(Boolean),i=r.length?new Set:null;if(i){for(let l of t.nodes.values())if(r.every(c=>`${l.name} ${l.path}`.toLocaleLowerCase("de").includes(c))){i.add(l.object_id);for(let c of ba(t,l.object_id))i.add(c)}}let o=[],s=new Set,a=(l,c)=>{let d=(t.children.get(l)??[]).filter(u=>!i||i.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&&(!!i||e.has(u.object_id));o.push({node:u,depth:c,hasChildren:h,expanded:f,index:p+1,siblings:d.length}),f&&a(u.object_id,c+1)})};return a(0,0),o}var Du=["Boolean","Integer","Float","String"],Iy={light:"Licht",cover:"Jalousie/Tor",switch:"Schalter",binary_sensor:"Bin\xE4rsensor",sensor:"Sensor",climate:"Heizung",lock:"Schloss",script:"Skript",schedule:"Schaltuhr",media_player:"Medienger\xE4t",fan:"L\xFCfter"};function Ou(t,e={}){if(t.virtual||t.object_type===0)return"Das ist eine Kategorie. Klappe sie auf und w\xE4hle den Datenpunkt darunter aus.";if(t.object_type===1)return"Das ist eine Instanz. Klappe sie auf und w\xE4hle ihre Variable aus, zum Beispiel \u201EValue\u201C.";if(e.schedule&&t.object_type!==4)return"Hier wird eine klassische Symcon-Schaltuhr (Wochenplan-Ereignis) erwartet, keine Variable.";if(e.unsupported)return e.unsupported;if(!t.entity_id)return t.object_type===2?"Diese Variable wurde noch nicht geladen. Lade die Variablen oben in der Titelleiste neu und \xF6ffne die Auswahl erneut.":t.object_type===6?"Dieser Link verweist auf keinen unterst\xFCtzten Datenpunkt. W\xE4hle die Variable direkt im Objektbaum aus.":t.object_type===4?"Dieses Ereignis ist keine unterst\xFCtzte klassische Symcon-Schaltuhr (Wochenplan).":"Dieser Objekttyp kann in diesem Feld nicht verkn\xFCpft werden. W\xE4hle eine passende Variable aus.";let n=e.states?.[t.entity_id];if(e.states&&!n)return"Diese Variable ist im aktuellen Datenbestand nicht mehr vorhanden. Lade die Variablen oben in der Titelleiste neu.";let r=n?.attributes.symcon_variable_type,i=r===void 0?void 0:Du[Number(r)];if(n&&!n.attributes.symcon_schedule&&!i)return"Der native Datentyp dieser Variable ist nicht verf\xFCgbar. Lade die Variablen oben in der Titelleiste neu.";if(i&&e.types&&!e.types.includes(Number(r)))return`Datentyp ${i} passt hier nicht. F\xFCr \u201E${e.label||"dieses Feld"}\u201C wird ${e.types.map(c=>Du[c]).join(" oder ")} ben\xF6tigt.`;let o=e.excluded?.(t.entity_id);if(o)return o;let s=Iy[t.entity_id.split(".")[0]],a=n?.attributes.unit_of_measurement,l=[i&&`Datentyp: ${i}`,a&&`Einheit: ${a}`,s&&`erkannte Funktion: ${s}`].filter(Boolean).join(" \xB7 ");return`Dieser Datenpunkt erf\xFCllt den Filter${e.label?` f\xFCr \u201E${e.label}\u201C`:" dieses Feldes"} nicht.${l?` ${l}.`:""}`}var Dy=["Kategorie","Instanz","Variable","Skript","Ereignis","Medium","Link"],va=class extends q{static properties={objects:{attribute:!1},options:{attribute:!1},fixed:{attribute:!1},value:{attribute:!1},disabled:{type:Boolean},placeholder:{attribute:!1},context:{attribute:!1},_notice:{state:!0},_query:{state:!0},_expanded:{state:!0},_pending:{state:!0},_active:{state:!0},_selected:{state:!0}};tree=_a([]);allowed=new Map;allowedSources=new Map;constructor(){super(),this.objects=[],this.options=[],this.fixed=[],this.value=null,this.disabled=!1,this.placeholder="Datenpunkt ausw\xE4hlen",this._notice="",this._query="",this._expanded=new Set,this._pending=null,this._active=null,this._selected=null}willUpdate(e){e.has("objects")&&(this.tree=_a(this.objects)),(e.has("options")||e.has("fixed"))&&(this.allowed=new Map([...this.fixed,...this.options].map(n=>[n.id,n])),this.allowedSources=new Map(this.options.filter(n=>n.sourceEntity).map(n=>[n.sourceEntity,n.id])))}get dialog(){return this.renderRoot.querySelector("dialog")}variableNode(e){let n=this.allowed.get(e??"")?.sourceEntity??e,r=this.objects.find(i=>i.entity_id===n&&(i.object_type===2||i.object_type===4));return r?this.tree.nodes.get(r.object_id):void 0}async open(){if(this.disabled)return;this._pending=this.allowed.has(this.value??"")?this.value:null,this._query="",this._notice="";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 ba(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()}clear(e){e.preventDefault(),e.stopPropagation(),!this.disabled&&(this.value=this.fixed.some(n=>n.id==="none")?"none":null,this._pending=this.value,this._selected=null,this._active=null,this.close(),this.dispatchEvent(new CustomEvent("change",{detail:{value:this.value},bubbles:!0,composed:!0})))}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;let n=this.entityFor(e);n?(this._pending=n,this._selected=e.object_id,this._notice=""):(this._pending=null,this._selected=null,this._notice=Ou(e,this.context))}entityFor(e){if(e.entity_id)return this.allowed.has(e.entity_id)?e.entity_id:this.allowedSources.get(e.entity_id)}async onTreeKey(e){let n=ya(this.tree,this._expanded,this._query),r=Math.max(0,n.findIndex(s=>s.node.object_id===this._active)),i=n[r];if(!i)return;let o=r;if(e.key==="ArrowDown")o=Math.min(n.length-1,r+1);else if(e.key==="ArrowUp")o=Math.max(0,r-1);else if(e.key==="Home")o=0;else if(e.key==="End")o=n.length-1;else if(e.key==="ArrowRight")i.hasChildren&&!i.expanded?this.toggle(i.node.object_id):i.hasChildren&&(o=Math.min(n.length-1,r+1));else if(e.key==="ArrowLeft")i.expanded&&!this._query?this.toggle(i.node.object_id):o=Math.max(0,n.findIndex(s=>s.node.object_id===i.node.parent_id));else if(e.key===" "||e.key==="Enter")this.select(i.node),e.key==="Enter"&&this.entityFor(i.node)&&this.commit();else return;e.preventDefault(),(o!==r||this._active===null)&&(this._active=n[o].node.object_id),await this.updateComplete,this.renderRoot.querySelector(`#object-${this._active}`)?.scrollIntoView({block:"nearest"})}icon(e){let n=[E`<path d="M3 6h7l2 2h9v12H3z"/>`,E`<path d="m12 3 9 5v9l-9 5-9-5V8zM3 8l9 5 9-5M12 13v9"/>`,E`<circle cx="12" cy="12" r="8"/><path d="m9 9 6 6m0-6-6 6"/>`,E`<path d="m8 7-5 5 5 5m8-10 5 5-5 5m-3-12-2 14"/>`,E`<circle cx="12" cy="12" r="9"/><path d="M12 6v6l4 2"/>`,E`<rect x="3" y="4" width="18" height="16" rx="2"/><path d="m4 17 5-5 4 4 3-3 5 4"/>`,E`<path d="m10 14 4-4m-6 2-2 2a4 4 0 0 0 6 6l3-3m-6-9 3-3a4 4 0 0 1 6 6l-2 2"/>`];return E`<svg class="icon type-${e}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.6" aria-hidden="true">${n[e]??n[1]}</svg>`}renderRow(e){let{node:n}=e,r=this.entityFor(n),i=!!r;return m`<div id="object-${n.object_id}" role="treeitem"
aria-level=${e.depth+1} aria-posinset=${e.index} aria-setsize=${e.siblings}
aria-expanded=${e.hasChildren?String(e.expanded):_}
aria-selected=${i?String(n.object_id===this._selected&&r===this._pending):_}
aria-disabled=${!i&&[2,4,6].includes(n.object_type)?"true":_}
class="node ${i?"selectable":""} ${n.hidden?"hidden-object":""} ${this._active===n.object_id?"active":""}"
style=${`--depth:${e.depth}`} title=${n.path}
@click=${()=>{this.select(n),this.renderRoot.querySelector(".tree")?.focus()}}
@dblclick=${()=>{i?(this.select(n),this.commit()):e.hasChildren&&this.toggle(n.object_id)}}>
<button class="twisty" type="button" tabindex="-1" aria-label=${e.expanded?"Zuklappen":"Aufklappen"}
?disabled=${!e.hasChildren} @click=${o=>{o.stopPropagation(),this._active=n.object_id,this.toggle(n.object_id)}}>
${e.hasChildren?e.expanded?"\u25BE":"\u25B8":_}
</button>
${this.icon(n.object_type)}<span class="node-name">${n.name||"(Ohne Namen)"}</span>
<small>${n.virtual?"Systembereich":Dy[n.object_type]??"Objekt"}${n.hidden?" \xB7 ausgeblendet":""}</small>
${i&&n.object_id===this._selected&&r===this._pending?m`<span class="selected-mark" aria-hidden="true">✓</span>`:_}
</div>`}render(){let e=this.allowed.get(this.value??""),n=this.variableNode(this.value),r=this.allowed.get(this._pending??""),i=this._selected===null?void 0:this.tree.nodes.get(this._selected),o=(i&&this.entityFor(i)===this._pending?i:void 0)??this.variableNode(this._pending),s=ya(this.tree,this._expanded,this._query),a=s.find(c=>c.node.object_id===this._active),l=!!this.value&&!this.fixed.some(c=>c.id===this.value);return m`<div class="field"><button type="button" class="trigger" ?disabled=${this.disabled} aria-haspopup="dialog" @click=${this.open}>
<span class="trigger-text"><strong>${n?.name??e?.label??"Datenpunkt ausw\xE4hlen"}</strong>
${n?m`<small title=${n.path}>${n.path}</small>`:_}</span><span class="picker-icon" aria-hidden="true">⌘</span>
</button>${l?m`<button class="clear" type="button" ?disabled=${this.disabled} aria-label="Verknüpfung entfernen" title="Verknüpfung entfernen" @click=${this.clear}>×</button>`:_}</div>
<dialog aria-labelledby="picker-title" @click=${c=>{if(c.stopPropagation(),c.target===this.dialog){let d=this.dialog.getBoundingClientRect();(c.clientX<d.left||c.clientX>d.right||c.clientY<d.top||c.clientY>d.bottom)&&this.close()}}} @keydown=${c=>c.stopPropagation()} @change=${c=>c.stopPropagation()}>
<header><div><h2 id="picker-title">Datenpunkt auswählen</h2><p>IP-Symcon · ${this.context?.label||"Objektbaum"}</p></div>
<button class="close" type="button" aria-label="Schließen" @click=${this.close}>×</button></header>
<div class="search-bar"><input class="search" type="search" placeholder="Im Objektbaum suchen …" aria-label="Objektbaum durchsuchen"
.value=${this._query} @input=${c=>{this._query=c.target.value,this._active=null,this._notice=""}}>
<button class="text-button" type="button" @click=${()=>{this._query="",this._expanded=new Set,this._active=null}}>Alles zuklappen</button>
</div>
${this.fixed.length?m`<div class="fixed" aria-label="Weitere Auswahlmöglichkeiten">${this.fixed.map(c=>m`
<button type="button" aria-pressed=${c.id===this._pending} @click=${()=>{this._pending=c.id,this._active=null,this._selected=null,this._notice=""}}>${c.label}</button>`)}</div>`:_}
<div class="tree" role="tree" tabindex="0" aria-label="Symcon-Objektbaum" aria-activedescendant=${a?`object-${a.node.object_id}`:_}
@keydown=${this.onTreeKey}>
${ln(s,c=>c.node.object_id,c=>this.renderRow(c))}
${s.length?_:m`<p class="empty">${this.objects.length?"Keine Objekte gefunden.":"Kein Objektbaum verf\xFCgbar. Bitte das Symcon-Modul aktualisieren und den Designer neu laden."}</p>`}
</div>
${this._notice?m`<div class="rejection" role="status" aria-live="polite">${this._notice}</div>`:_}
<footer><div class="selection"><strong>${o?.name??r?.label??"Noch kein Datenpunkt ausgew\xE4hlt"}</strong>
<small>${o?.path??"Nur passende Datenpunkte k\xF6nnen ausgew\xE4hlt werden."}</small></div>
<div class="actions"><button type="button" @click=${this.close}>Abbrechen</button>
<button class="apply" type="button" ?disabled=${this.disabled||!r} @click=${this.commit}>Übernehmen</button></div>
</footer>
</dialog>`}static styles=[fe,J`
:host { display:block; min-width:0; max-width:100%; font:inherit; color:var(--nf-text); }
button,input { font:inherit; box-sizing:border-box; }
button { cursor:pointer; color:var(--nf-text); border:1px solid var(--nf-line); background:var(--nf-chrome-solid); border-radius:9px; padding:8px 12px; }
button:disabled { opacity:.45; cursor:default; }
button:focus-visible,input:focus-visible { outline:2px solid var(--nf-accent); outline-offset:2px; }
.field { display:flex; gap:6px; min-width:0; }
.trigger { flex:1; min-width:0; width:100%; display:flex; align-items:center; justify-content:space-between; text-align:left; gap:12px; padding:9px 11px; }
.trigger-text { flex:1; min-width:0; overflow:hidden; }
.trigger strong { display:block; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.picker-icon { flex:none; }
.clear { flex:none; width:32px; padding:0; font-size:22px; }
strong { font-weight:500; } small { display:block; color:var(--nf-muted); font-size:11px; }
.trigger small { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; margin-top:3px; }
dialog { width:min(780px,calc(100vw - 32px)); max-width:none; height:min(690px,calc(100dvh - 32px)); max-height:none; box-sizing:border-box; padding:0; border:1px solid var(--nf-line); border-radius:16px; color:var(--nf-text); background:var(--nf-chrome-solid); box-shadow:0 24px 80px #0008; font:14px system-ui,sans-serif; }
dialog[open] { display:flex; flex-direction:column; }
dialog::backdrop { background:#050b16a6; backdrop-filter:blur(3px); }
header { display:flex; align-items:center; justify-content:space-between; padding:20px 22px 16px; border-bottom:1px solid var(--nf-line); }
h2 { font-size:18px; font-weight:600; margin:0 0 4px; } header p { margin:0; color:var(--nf-muted); font-size:12px; }
.close { font-size:25px; padding:0; width:32px; height:32px; border-color:transparent; }
.search-bar { display:flex; align-items:center; gap:12px; padding:16px 20px 10px; }
.search { flex:1; min-width:0; border:1px solid var(--nf-line); border-radius:9px; padding:10px 12px; background:var(--nf-bg); color:var(--nf-text); }
.text-button { border:0; background:transparent; color:var(--nf-muted); font-size:12px; padding:6px 0; white-space:nowrap; }
.fixed { display:flex; flex-wrap:wrap; gap:6px; padding:0 20px 10px; }
.fixed button { padding:5px 10px; font-size:12px; }
.fixed [aria-pressed=true] { color:var(--nf-accent); border-color:var(--nf-accent); }
.tree { flex:1; min-height:80px; overflow:auto; overscroll-behavior:contain; margin:0 12px; padding:4px 0 12px; outline-offset:-2px; }
.node { display:flex; align-items:center; gap:8px; min-height:34px; border-radius:6px; padding:2px 10px 2px calc(4px + var(--depth)*22px); box-sizing:border-box; width:max-content; min-width:100%; }
.node:hover { background:color-mix(in srgb,var(--nf-accent) 8%,transparent); }
.node.active { outline:1px solid color-mix(in srgb,var(--nf-accent) 40%,transparent); outline-offset:-1px; }
.node[aria-selected=true] { background:color-mix(in srgb,var(--nf-accent) 16%,transparent); color:var(--nf-accent); }
.node.selectable { cursor:pointer; }
.node[aria-disabled=true] .node-name { color:var(--nf-muted); }
.node.hidden-object .node-name { font-style:italic; }
.node-name { flex:1; white-space:nowrap; }
.node small { margin-left:20px; white-space:nowrap; }
.twisty { border:0; background:transparent; border-radius:4px; padding:0; width:20px; height:26px; flex:none; font-size:18px; }
.icon { flex:none; width:17px; height:17px; color:#8796a9; } .type-0 { color:#c69a42; } .type-1 { color:#8d9ac6; } .type-2 { color:#55a58c; }
.selected-mark { margin-left:8px; }
.empty { padding:20px; color:var(--nf-muted); }
.rejection { flex:none; margin:0 20px 12px; padding:8px 10px; border-left:2px solid #e5b56d; border-radius:4px; background:#e5b56d0c; color:var(--nf-text); font-size:12px; line-height:1.4; overflow-wrap:anywhere; }
footer { display:flex; align-items:center; justify-content:space-between; gap:16px; border-top:1px solid var(--nf-line); padding:15px 20px; }
.selection { min-width:0; } .selection small { margin-top:4px; overflow-wrap:anywhere; }
.actions { display:flex; gap:8px; flex-shrink:0; }
.apply { color:white; background:var(--nf-accent); border-color:transparent; }
@media(max-width:580px) {
dialog { width:calc(100vw - 16px); height:calc(100dvh - 32px); border-radius:12px; }
header { padding:16px; } .search-bar { padding:12px; gap:8px; } .fixed { padding:0 12px 8px; }
.tree { margin:0 8px; } .node { gap:6px; padding-left:calc(2px + var(--depth)*18px); }
.node small { display:none; } footer { padding:12px; flex-direction:column; align-items:stretch; } .actions { justify-content:flex-end; }
}
`]};customElements.get("nf-symcon-object-picker")||customElements.define("nf-symcon-object-picker",va);var Hu=40,wa=class extends q{static properties={options:{attribute:!1},objectTree:{attribute:!1},context:{attribute:!1},fixed:{attribute:!1},value:{attribute:!1},disabled:{type:Boolean},placeholder:{attribute:!1},_query:{state:!0},_open:{state:!0},_cursor:{state:!0}};blurTimer;constructor(){super(),this.options=[],this.objectTree=void 0,this.fixed=[],this.value=null,this.disabled=!1,this.placeholder="",this._query="",this._open=!1,this._cursor=0}get current(){return[...this.fixed,...this.options].find(e=>e.id===this.value)}get hits(){let e=this._query.trim().toLowerCase(),n=e.split(/\s+/).filter(Boolean),r=s=>{let a=`${s.label} ${s.detail??s.id}`.toLowerCase();return n.every(l=>a.includes(l))},i=this.fixed.filter(s=>!e||r(s)),o=e?this.options.filter(r):this.options;return[...i,...o.slice(0,Hu)]}get leftOut(){let e=this._query.trim().toLowerCase(),n=e.split(/\s+/).filter(Boolean),r=e?this.options.filter(i=>n.every(o=>`${i.label} ${i.detail??i.id}`.toLowerCase().includes(o))).length:this.options.length;return Math.max(0,r-Hu)}choose(e){this.value=e,this._query="",this._open=!1,this.dispatchEvent(new CustomEvent("change",{detail:{value:e},bubbles:!0,composed:!0}))}onKey(e){let n=this.hits;e.key==="ArrowDown"?(this._open=!0,this._cursor=Math.min(n.length-1,this._cursor+1),e.preventDefault()):e.key==="ArrowUp"?(this._cursor=Math.max(0,this._cursor-1),e.preventDefault()):e.key==="Enter"?(this._open&&n[this._cursor]&&this.choose(n[this._cursor].id),e.preventDefault()):e.key==="Escape"&&(this._open=!1,this._query="")}render(){if(this.objectTree!==void 0)return m`<nf-symcon-object-picker
.objects=${this.objectTree} .options=${this.options} .fixed=${this.fixed} .value=${this.value}
.context=${this.context}
.disabled=${this.disabled} .placeholder=${this.placeholder}
@change=${r=>{this.value=r.detail.value}}
></nf-symcon-object-picker>`;let e=this.current,n=this._open?this.hits:[];return m`<div class="wrap">
<input
type="text"
role="combobox"
aria-expanded=${this._open}
?disabled=${this.disabled}
placeholder=${e?e.label:this.placeholder}
.value=${this._open?this._query:e?.label??""}
@focus=${()=>{clearTimeout(this.blurTimer),this._open=!0,this._query="",this._cursor=0}}
@blur=${()=>{this.blurTimer=setTimeout(()=>this._open=!1,150)}}
@input=${r=>{this._query=r.target.value,this._cursor=0,this._open=!0}}
@keydown=${this.onKey}
/>
${this._open?m`<ul class="list" role="listbox">
${n.length?_:m`<li class="empty">–</li>`}
${n.map((r,i)=>m`<li
role="option"
aria-selected=${r.id===this.value}
class="${i===this._cursor?"cursor":""} ${r.id===this.value?"chosen":""}"
@mousedown=${o=>o.preventDefault()}
@click=${()=>this.choose(r.id)}
>
<span>${r.label}</span>${r.detail||r.id.includes(".")?m`<small>${r.detail??r.id}</small>`:_}
</li>`)}
${this.leftOut>0?m`<li class="empty">… +${this.leftOut} · ${this.placeholder}</li>`:_}
</ul>`:_}
</div>`}static styles=[fe,J`
:host {
display: block;
position: relative;
min-width: 0;
max-width: 100%;
}
input {
width: 100%;
box-sizing: border-box;
font: inherit;
color: var(--nf-text);
background: var(--nf-chrome-solid);
border: 1px solid var(--nf-line);
border-radius: 10px;
padding: 8px 10px;
}
input::placeholder {
color: var(--nf-text);
opacity: 0.9;
}
input:focus::placeholder {
color: var(--nf-muted);
}
input:focus {
outline: 2px solid var(--nf-accent);
outline-offset: -1px;
}
.list {
position: absolute;
left: 0;
right: 0;
top: calc(100% + 4px);
z-index: 20;
margin: 0;
padding: 4px;
list-style: none;
max-height: 280px;
overflow-y: auto;
background: var(--nf-chrome-solid);
border: 1px solid var(--nf-line);
border-radius: 10px;
box-shadow: var(--nf-shadow);
}
li {
display: flex;
flex-direction: column;
gap: 1px;
padding: 6px 8px;
border-radius: 6px;
cursor: pointer;
font-size: 13.5px;
}
li small {
color: var(--nf-muted);
font-size: 11px;
}
li.cursor,
li:hover {
background: color-mix(in srgb, var(--nf-accent) 18%, transparent);
}
li.chosen {
color: var(--nf-accent);
}
li.empty {
color: var(--nf-muted);
cursor: default;
}
`]};customElements.get("nf-entity-picker")||customElements.define("nf-entity-picker",wa);var xa=class extends q{static properties={text:{attribute:!1}};constructor(){super(),this.text=""}get dialog(){return this.renderRoot.querySelector("dialog")}render(){return m`<button class="info" type="button" aria-label="Information anzeigen" aria-haspopup="dialog" title="Information" @click=${()=>this.dialog?.showModal()}>ⓘ</button>
<dialog aria-label="Information" @keydown=${e=>e.stopPropagation()} @click=${e=>{if(e.target!==e.currentTarget)return;let n=this.dialog.getBoundingClientRect();(e.clientX<n.left||e.clientX>n.right||e.clientY<n.top||e.clientY>n.bottom)&&this.dialog?.close()}}>
<header><b>Information</b><button class="close" type="button" aria-label="Schließen" @click=${()=>this.dialog?.close()}>×</button></header>
<p>${this.text}</p>
</dialog>`}static styles=[fe,J`
:host { display:inline-block; margin:4px 0; vertical-align:middle; }
button { font:inherit; cursor:pointer; color:var(--nf-muted); background:transparent; border:1px solid var(--nf-line); border-radius:50%; pointer-events:auto; }
.info { width:26px; height:26px; padding:0; font-size:18px; line-height:24px; }
button:hover { color:var(--nf-accent); }
button:focus-visible { outline:2px solid var(--nf-accent); outline-offset:2px; }
dialog { box-sizing:border-box; width:min(560px,calc(100vw - 32px)); max-height:80vh; max-height:80dvh; overflow:auto; padding:18px 22px; border:1px solid var(--nf-line); border-radius:14px; background:var(--nf-chrome-solid); color:var(--nf-text); font:14px/1.5 system-ui,sans-serif; box-shadow:var(--nf-shadow); pointer-events:auto; }
dialog::backdrop { background:#050b16a6; }
header { display:flex; align-items:center; justify-content:space-between; gap:20px; font-size:16px; }
.close { width:30px; height:30px; padding:0; font-size:23px; }
p { white-space:pre-wrap; overflow-wrap:anywhere; margin:16px 0 4px; }
`]};customElements.get("nf-help-popup")||customElements.define("nf-help-popup",xa);var cn=t=>t.target.value,ka=t=>Number.parseFloat(t.replace(",",".")),ae=t=>Math.round(t*1e3)/1e3,Lu=t=>t.wide?"nf-field nf-wide":"nf-field";function R(t,e,n,r,i=.01,o){return m`<label class="nf-field"
>${e}
<input
type="number"
inputmode="decimal"
step=${i}
min=${o??_}
.value=${String(ae(n))}
?disabled=${!t.admin}
@change=${s=>{let a=ka(cn(s));Number.isFinite(a)&&r(a)}}
/>
</label>`}function W(t,e,n,r,i={}){return m`<label class=${Lu(i)} title=${i.title??_}
>${e}
<input type="text" .value=${n} placeholder=${i.placeholder??_} maxlength=${i.maxlength??_} ?disabled=${!t.admin} @change=${o=>r(cn(o).trim())} />
</label>`}function H(t,e,n,r,i,o={}){return m`<label class=${Lu(o)} title=${o.title??_}
>${e}
<select ?disabled=${!t.admin} @change=${s=>i(cn(s))}>
${r.map(([s,a])=>m`<option value=${s} ?selected=${s===n}>${a}</option>`)}
</select>
</label>`}function D(t,e,n,r,i={}){return m`<label class="nf-check ${i.wide===!1?"":"nf-wide"}" title=${i.title??_}
><input type="checkbox" .checked=${n} ?disabled=${!t.admin} @change=${o=>r(o.target.checked)} />
${e}</label
>`}function Ge(t,e,n,r,i){return m`<label class="nf-field"
>${e}
<span class="nf-color-row"
><input type="color" .value=${n??r} ?disabled=${!t.admin} @change=${o=>i(o.target.value)} />
${n?m`<button type="button" class="nf-link" ?disabled=${!t.admin} @click=${()=>i(null)}>${t.t("wall_paint_default")}</button>`:_}</span
></label
>`}function z(t,e,n,r,i,o,s={}){let a=r===void 0?null:r?t.t("entity_auto",{name:B(t.hass,r)}):t.t("entity_auto_none"),l=[...a!==null?[{id:"__auto",label:a}]:[],{id:"none",label:t.t("entity_none")}],c=n??(a!==null?"__auto":"none"),d=t.hass?.symconObjects!==void 0&&!s.schedule?Mu(t.hass,s,n):i;return m`<label class="nf-field nf-wide"
>${e}
<nf-entity-picker
.options=${d}
.objectTree=${t.hass?.symconObjects}
.context=${{...s,label:e,states:t.hass?.states}}
.fixed=${l}
.value=${c}
.placeholder=${t.t("entity_search")}
?disabled=${!t.admin}
@change=${u=>{u.stopPropagation(),o(u.detail.value==="__auto"?null:u.detail.value)}}
></nf-entity-picker>
</label>`}function Vn(t,e,n){return n?(n.startsWith("mdi:")?n:`mdi:${n}`).replace(/[^a-z0-9:-]/gi,""):t.hass?ou(t.hass,e):null}function Bt(t,e,n){let r=e?(e.startsWith("mdi:")?e:`mdi:${e}`).replace(/[^a-z0-9:-]/gi,""):"";return m`<label class="nf-field nf-wide" title=${t.t("marker_icon_hint")}
>${t.t("marker_icon")}
<span class="nf-icon-row">
<input type="text" placeholder="mdi:thermometer" .value=${e??""} ?disabled=${!t.admin} @change=${i=>n(cn(i).trim().replace(/^mdi:/,"")||null)} />
${r?Yd(`<ha-icon icon="${r}"></ha-icon>`):_}
</span>
</label>`}function Wn(t,e,n){return m`<label class="nf-field nf-wide" title=${t.t("marker_show_hint")}
>${t.t("marker_show")}
<select ?disabled=${!t.admin} @change=${r=>n(cn(r)||null)}>
<option value="" ?selected=${!e}>${t.t("marker_show_auto")}</option>
${Ed.map(r=>m`<option value=${r} ?selected=${r===e}>${t.t(`marker_show_${r}`)}</option>`)}
</select>
</label>`}function Vt(t,e,n){let r=e??{},i=o=>s=>{let a={...r,[o]:Math.round(Math.max(-5,Math.min(5,s))*100)/100};n(a.x||a.z||a.y?a:null)};return m`<details class="nf-wide nf-pin-shift" ?open=${!!e}>
<summary>${t.t("pin_shift")}</summary>
<div class="nf-form">
${R(t,"\u2194 x",r.x??0,i("x"),.05)} ${R(t,"\u2195 z",r.z??0,i("z"),.05)} ${R(t,t.t("pin_shift_up"),r.y??0,i("y"),.05)}
${e?m`<button class="nf-btn nf-field-btn" ?disabled=${!t.admin} @click=${()=>n(null)}>${t.t("height_auto")}</button>`:_}
${S(t.t("pin_shift_hint"),"nf-wide")}
</div>
</details>`}var Q=(...t)=>m`<div class="nf-actions">${t}</div>`,S=(t,e="")=>m`<nf-help-popup class=${e} .text=${t}></nf-help-popup>`;function dn(t,e,n,r={}){let i=r.lowest??10;return m`<label class="nf-field" title=${t.t(r.hint??"glow_scale_hint")}
>${t.t(r.label??"glow_scale")}
<input
type="number"
min=${i}
max="150"
step="5"
.value=${String(Math.round((e??1)*100))}
?disabled=${!t.admin}
@change=${o=>{let s=Number(cn(o)),a=Math.min(150,Math.max(i,cn(o).trim()===""||Number.isNaN(s)?100:s))/100;n(Math.abs(a-1)<.001?null:a)}}
/>
</label>`}var $a=class extends q{static properties={doc:{attribute:!1},admin:{type:Boolean},suggestedName:{attribute:!1},locationId:{state:!0},branchId:{state:!0},buildingId:{state:!0}};constructor(){super(),this.admin=!1,this.suggestedName="Geb\xE4ude 1",this.locationId="",this.branchId="",this.buildingId=""}willUpdate(e){let n=this.doc?.topology;if(!n)return;n.locations.some(o=>o.id===this.locationId)||(this.locationId=n.locations[0]?.id??"");let r=n.branches.filter(o=>o.location_id===this.locationId);r.some(o=>o.id===this.branchId)||(this.branchId=r[0]?.id??"");let i=n.buildings.filter(o=>o.branch_id===this.branchId);i.some(o=>o.id===this.buildingId)||(this.buildingId=i[0]?.id??"")}edit(e){if(!this.admin||!this.doc?.topology)return;let n=structuredClone(this.doc);e(n,n.topology),this.publish(n)}publish(e){this.doc=e,this.dispatchEvent(new CustomEvent("hierarchy-change",{detail:{building:e},bubbles:!0,composed:!0}))}open(e){this.dispatchEvent(new CustomEvent("hierarchy-open",{detail:e,bubbles:!0,composed:!0}))}name(e,n,r){return m`<label>${e}<input maxlength="100" .value=${n} ?disabled=${!this.admin} @change=${i=>r(i.target.value.trim())}/></label>`}render(){let e=this.doc?.topology;if(!e)return m`<div class="setup">${S("Vorhandene Etagen werden einem ersten Ort, einer Niederlassung und einem Geb\xE4ude zugeordnet. Geometrie, Raumverkn\xFCpfungen und Benutzerrechte bleiben erhalten.")}
<button class="setup-button" ?disabled=${!this.admin} @click=${()=>{let o=structuredClone(this.doc);wd(o,this.suggestedName),this.publish(o)}}>Hierarchie einrichten</button></div>`;let n=e.locations.find(o=>o.id===this.locationId),r=e.branches.find(o=>o.id===this.branchId),i=e.buildings.find(o=>o.id===this.buildingId);return m`<div class="help">${S("Hier pflegst du Ort, Niederlassung und Geb\xE4ude. Die Listen wechseln nur die Auswahl. Etagen legst du anschlie\xDFend oben im Editor im gew\xE4hlten Geb\xE4ude an. R\xE4ume und ihre Symcon-Bereichskategorie bearbeitest du rechts auf der ausgew\xE4hlten Etage.")}</div>
<div class="columns">
<section aria-label="Orte"><h3>Orte</h3><div class="items">${e.locations.map(o=>m`<button class="pick" data-location=${o.id} aria-pressed=${o.id===this.locationId} @click=${()=>{this.locationId=o.id,this.branchId="",this.buildingId=""}}>${o.name}</button>`)}</div>
<button class="add-location" ?disabled=${!this.admin} @click=${()=>{let o=P("location");this.edit((s,a)=>a.locations.push({id:o,name:`Ort ${a.locations.length+1}`})),this.locationId=o,this.branchId="",this.buildingId=""}}>+ Ort</button>
${n?m`<div class="details">${this.name("Name des Ortes",n.name,o=>{this.locationId===n.id&&this.edit((s,a)=>{a.locations.find(l=>l.id===n.id).name=o})})}
<button class="outside" ?disabled=${!this.admin&&!this.doc.floors.some(o=>o.outdoor_location_id===n.id)} @click=${()=>{this.doc.floors.some(o=>o.outdoor_location_id===n.id)||this.edit(o=>{xd(o,n.id)}),this.open({kind:"outside",id:n.id})}}>🌳 ${this.doc.floors.some(o=>o.outdoor_location_id===n.id)?"Au\xDFenplan \xF6ffnen":"Au\xDFenplan anlegen"}</button>
<button class="delete" ?disabled=${!this.admin||e.branches.some(o=>o.location_id===n.id)||this.doc.floors.some(o=>o.outdoor_location_id===n.id)} @click=${()=>this.edit((o,s)=>{s.locations=s.locations.filter(a=>a.id!==n.id)})}>Ort entfernen</button>
</div>`:_}
</section>
<section aria-label="Niederlassungen"><h3>Niederlassungen</h3><div class="items">${e.branches.filter(o=>o.location_id===this.locationId).map(o=>m`<button class="pick" data-branch=${o.id} aria-pressed=${o.id===this.branchId} @click=${()=>{this.branchId=o.id,this.buildingId=""}}>${o.name}</button>`)}</div>
<button class="add-branch" ?disabled=${!this.admin||!n} @click=${()=>{if(!n)return;let o=P("branch");this.edit((s,a)=>a.branches.push({id:o,name:`Niederlassung ${a.branches.length+1}`,location_id:n.id})),this.branchId=o,this.buildingId=""}}>+ Niederlassung</button>
${r?m`<div class="details">${this.name("Name der Niederlassung",r.name,o=>{this.branchId===r.id&&this.edit((s,a)=>{a.branches.find(l=>l.id===r.id).name=o})})}
<label>Ort der Niederlassung<select ?disabled=${!this.admin} .value=${r.location_id} @change=${o=>{let s=o.target.value;this.branchId!==r.id||!e.locations.some(a=>a.id===s)||(this.edit((a,l)=>{l.branches.find(c=>c.id===r.id).location_id=s}),this.locationId=s)}}>${e.locations.map(o=>m`<option value=${o.id} .selected=${o.id===r.location_id}>${o.name}</option>`)}</select></label>
<button class="delete" ?disabled=${!this.admin||e.buildings.some(o=>o.branch_id===r.id)} @click=${()=>this.edit((o,s)=>{s.branches=s.branches.filter(a=>a.id!==r.id)})}>Niederlassung entfernen</button>
</div>`:_}
</section>
<section aria-label="Gebäude"><h3>Gebäude</h3><div class="items">${e.buildings.filter(o=>o.branch_id===this.branchId).map(o=>m`<button class="pick" data-building=${o.id} aria-pressed=${o.id===this.buildingId} @click=${()=>this.buildingId=o.id}>${o.name}<small>${this.doc.floors.filter(s=>!s.outdoor_location_id&&s.building_id===o.id).length} Etagen</small></button>`)}</div>
<button class="add-building" ?disabled=${!this.admin||!r} @click=${()=>{if(!r)return;let o=P("building");this.edit((s,a)=>a.buildings.push({id:o,name:`Geb\xE4ude ${a.buildings.length+1}`,branch_id:r.id})),this.buildingId=o}}>+ Gebäude</button>
${i?m`<div class="details">${this.name("Name des Geb\xE4udes",i.name,o=>{this.buildingId===i.id&&this.edit((s,a)=>{a.buildings.find(l=>l.id===i.id).name=o})})}
<label>Niederlassung des Gebäudes<select ?disabled=${!this.admin} .value=${i.branch_id} @change=${o=>{let s=o.target.value,a=e.branches.find(l=>l.id===s);this.buildingId!==i.id||!a||(this.edit((l,c)=>{c.buildings.find(d=>d.id===i.id).branch_id=s}),this.branchId=s,this.locationId=a.location_id)}}>${e.branches.map(o=>m`<option value=${o.id} .selected=${o.id===i.branch_id}>${e.locations.find(s=>s.id===o.location_id)?.name} / ${o.name}</option>`)}</select></label>
<button class="open-building primary" @click=${()=>this.open({kind:"building",id:i.id})}>Im Editor auswählen</button>
<button class="delete" ?disabled=${!this.admin||this.doc.floors.some(o=>o.building_id===i.id)} @click=${()=>this.edit((o,s)=>{s.buildings=s.buildings.filter(a=>a.id!==i.id)})}>Gebäude entfernen</button>
</div>`:_}
</section>
</div>`}static styles=[fe,J`
:host{display:block;font:13px/1.4 system-ui;color:var(--nf-text)}button,input,select{box-sizing:border-box;font:inherit;color:inherit;background:var(--nf-fill,#ffffff08);border:1px solid var(--nf-line);border-radius:8px;padding:8px 10px;min-width:0}button{cursor:pointer}button:disabled,input:disabled,select:disabled{opacity:.45;cursor:default}button:focus-visible,input:focus-visible,select:focus-visible{outline:2px solid var(--nf-accent);outline-offset:2px}.columns{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:16px}.help{margin-bottom:8px}section{min-width:0;border:1px solid var(--nf-line);border-radius:12px;padding:12px}h3{font-size:14px;margin:0 0 10px}.items{display:grid;align-content:start;gap:5px;min-height:100px;max-height:240px;overflow:auto;margin-bottom:10px}.pick{text-align:left;display:flex;justify-content:space-between;gap:8px;overflow-wrap:anywhere}.pick[aria-pressed=true]{border-color:var(--nf-accent);background:color-mix(in srgb,var(--nf-accent) 15%,transparent)}small{white-space:nowrap;color:var(--nf-muted)}.details{display:grid;gap:10px;margin-top:18px;padding-top:12px;border-top:1px solid var(--nf-line)}label{display:grid;gap:5px;font-size:12px;color:var(--nf-muted)}input,select{width:100%;color:var(--nf-text)}.delete{color:var(--nf-muted)}.primary{border-color:var(--nf-accent)}.setup{display:flex;gap:10px;align-items:center}@media(max-width:720px){.columns{grid-template-columns:1fr}.items{min-height:0;max-height:140px}.details{margin-top:10px}section{padding:10px}}
`]};customElements.get("nf-hierarchy-manager")||customElements.define("nf-hierarchy-manager",$a);var Cu=new WeakMap,Nu=new WeakMap;function Bu(t,e){let n=Nu.get(t)??t,r=Cu.get(n)??new WeakMap;Cu.set(n,r);let i=r.get(e);if(i)return i;let o=new Map;for(let l of e)for(let c of l.placements)c.entity_id.startsWith("cover.")&&o.set(c.entity_id,{tilt:c.cover_tilt==="none"?null:c.cover_tilt,position:c.position});for(let l of Lt(n,e).values())l.cover&&!o.has(l.cover)&&o.set(l.cover,{tilt:l.coverTilt,position:l.position}),l.cover2&&!o.has(l.cover2)&&o.set(l.cover2,{tilt:l.cover2Tilt});let s={...n.states};for(let[l,c]of o){let d=n.states[l];if(!d)continue;let u={...d.attributes,nf_cover_control:!0},p=yo(n,c.position);p===null&&(p=typeof d.attributes.current_position=="number"?d.attributes.current_position:null),p!==null&&(u.current_position=p);let h=c.tilt?n.states[c.tilt]:d,f=typeof h?.attributes.current_tilt_position=="number"?h.attributes.current_tilt_position:c.tilt?yo(n,c.tilt):null;f!==null&&(u.current_tilt_position=f,u.supported_features=Number(u.supported_features??0)|128);let g=d.state;typeof u.current_position=="number"&&g!=="unavailable"&&g!=="unknown"&&g!=="opening"&&g!=="closing"&&(g=u.current_position>0?"open":"closed"),s[l]={...d,state:g,attributes:u}}let a={...n,states:s,callService:async(l,c,d={})=>{if(l!=="cover")return n.callService(l,c,d);let u=Array.isArray(d.entity_id)?d.entity_id:[d.entity_id],p=async h=>{let f=typeof h=="string"?o.get(h):void 0;if(!f)return n.callService(l,c,{...d,entity_id:h});let g={...d,entity_id:h},b=c;(b==="toggle"||b==="toggle_cover")&&(b=s[String(h)]?.state==="closed"?"open_cover":"close_cover");let y=b.includes("tilt");y&&f.tilt&&(g.entity_id=f.tilt);let v=f.tilt?n.states[f.tilt]:void 0;return y&&f.tilt&&!v?.attributes.symcon_id&&typeof v?.attributes.current_tilt_position!="number"&&(b==="set_cover_tilt_position"?(b="set_cover_position",g.position=g.tilt_position,delete g.tilt_position):b==="open_cover_tilt"?b="open_cover":b==="close_cover_tilt"&&(b="close_cover")),n.callService(l,b,g)};return Array.isArray(d.entity_id)?Promise.all(u.map(p)):p(u[0])}};return Nu.set(a,n),r.set(e,a),a}function Vu(t,e){switch(e){case"m/s":return t*3.6;case"mph":return t*1.609;case"kn":return t*1.852;case"ft/s":return t*1.097;default:return t}}var Wu="weather.nextfloor_symcon",ju={condition:"Wetterzustand",temperature:"Au\xDFentemperatur",humidity:"Au\xDFenluftfeuchte",pressure:"Luftdruck",wind_speed:"Windgeschwindigkeit",wind_gust_speed:"Windb\xF6en",wind_bearing:"Windrichtung",cloud_coverage:"Bew\xF6lkung",precipitation:"Niederschlagsrate",precipitation_total:"Niederschlagsmenge",illuminance:"Au\xDFenhelligkeit",uv_index:"UV-Index",visibility:"Sichtweite",snow:"Schnee",fog:"Nebel",lightning:"Gewitter"},Ku=new WeakMap;function Oy(t){let e=t.toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g,"").trim();return["sunny","clear-night","partlycloudy","cloudy","fog","rainy","pouring","lightning-rainy","lightning","hail","snowy","snowy-rainy","windy","windy-variant"].includes(e)?e:/kein regen|trocken|wolkenlos|klar|sonnig/.test(e)?"sunny":/gewitter|blitz/.test(e)?"lightning-rainy":/schneeregen/.test(e)?"snowy-rainy":/schnee/.test(e)?"snowy":/hagel/.test(e)?"hail":/starkregen/.test(e)?"pouring":/regen|niesel/.test(e)?"rainy":/nebel/.test(e)?"fog":/teil.*wolk|heiter|leicht.*wolk/.test(e)?"partlycloudy":/wolk|bedeckt/.test(e)?"cloudy":/wind|sturm/.test(e)?"windy":null}function Gu(t,e){if(!Z(t))return t;let n=e.weather_variables??{};if(!e.rain_sensor&&!Object.values(n).some(h=>h&&h!=="none"))return t;let r=Ku.get(t)??new WeakMap;Ku.set(t,r);let i=r.get(e);if(i)return i;let o={friendly_name:"Wetter",nf_symcon_weather:!0},s=h=>n[h]&&n[h]!=="none"?t.states[n[h]]:void 0;for(let h of["temperature","humidity","pressure","cloud_coverage","precipitation","precipitation_total","illuminance","uv_index","visibility"]){let f=s(h),g=Ct(f);g!==null&&(o[h]=h==="cloud_coverage"&&f?.attributes.symcon_max===1?g*100:g),f?.attributes.unit_of_measurement&&(o[`${h}_unit`]=f.attributes.unit_of_measurement)}for(let h of["wind_speed","wind_gust_speed"]){let f=s(h),g=Ct(f);g!==null&&(o[h]=Vu(g,f?.attributes.unit_of_measurement))}o.wind_speed_unit="km/h";let a=an(s("wind_bearing"));a!==null&&(o.wind_bearing=a);let l=Oy(ma(s("condition"))),c=e.rain_sensor?t.states[e.rain_sensor]:void 0,d=Lr(c);d!==null&&e.rain_sensor_inverted&&(d=!d),d===null&&typeof o.precipitation=="number"&&(d=o.precipitation>0),Lr(s("lightning"))?l=d?"lightning-rainy":"lightning":Lr(s("snow"))?l=d?"snowy-rainy":"snowy":Lr(s("fog"))?l="fog":d===!0?l=Number(o.precipitation??0)>=8?"pouring":"rainy":d===!1&&l&&/rain|pouring/.test(l)&&(l=null),!l&&typeof o.cloud_coverage=="number"&&(l=o.cloud_coverage>70?"cloudy":o.cloud_coverage>20?"partlycloudy":"sunny"),!l&&d===!1&&(l="sunny");let u={entity_id:Wu,state:l??"unknown",attributes:o},p={...t,states:{...t.states,[Wu]:u}};return r.set(e,p),p}var rt=(t,e,n={})=>t.callWS({type:`nextfloor/${e}`,...n});async function $o(t,e){return(await rt(t,"image/get",{image_id:e})).data}async function Wt(t,e,n){await rt(t,"image/set",{image_id:e,data:n})}async function Uu(t){return(await rt(t,"history/list")).snapshots}async function Zu(t,e){return(await rt(t,"history/snapshot",e?{name:e}:{})).id}async function qu(t,e){return(await rt(t,"history/get",{snapshot_id:e})).building}async function Yu(t,e){await rt(t,"history/delete",{snapshot_id:e})}async function Xu(t,e){return(await rt(t,"history/restore",{snapshot_id:e})).revision}var Cr=(t,e)=>rt(t,"packs/import",{pack:e});async function Ju(t,e){await rt(t,"packs/remove",{pack_id:e})}var Qu=t=>rt(t,"backup/export"),eh=(t,e,n)=>rt(t,"backup/import",{building:e,packs:n});var G=(t,e)=>[t[0]-e[0],t[1]-e[1]],ft=(t,e)=>[t[0]+e[0],t[1]+e[1]],it=(t,e)=>[t[0]*e,t[1]*e],te=(t,e)=>t[0]*e[0]+t[1]*e[1],Ae=(t,e)=>t[0]*e[1]-t[1]*e[0],_e=t=>Math.hypot(t[0],t[1]),ot=t=>{let e=_e(t)||1;return[t[0]/e,t[1]/e]},Sa=t=>[-t[1],t[0]],Ma=t=>[t[1],-t[0]];var Hy=.05,Ly=.2,Cy=.12;function Ny(t){let e=[];return t.forEach((n,r)=>{let i=n.points;if(i.length<3)return;let o=be(i)>=0;i.forEach((s,a)=>{let l=i[(a+1)%i.length],c=_e(G(l,s));if(c<.05)return;let d=[(l[0]-s[0])/c,(l[1]-s[1])/c],u=o?[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]=[te(s,d),te(l,d)];e.push({room:r,index:a,dir:d,normal:p,offset:te(s,p),outside:te(u,p)>0?1:-1,from:Math.min(h,f),to:Math.max(h,f)})})}),e}function By(t,e,n){if(t.room===e.room||Math.abs(Ae(t.dir,e.dir))>Hy||t.outside===e.outside)return null;let r=(e.offset-t.offset)*t.outside;return r>n||r<-Cy||Math.abs(r)<1e-4||Math.min(t.to,e.to)-Math.max(t.from,e.from)<Ly?null:r}var Ea=t=>Math.round(t*1e3)/1e3;function th(t,e=.6){let n=Ny(t),r=n.map((g,b)=>b),i=g=>r[g]===g?g:r[g]=i(r[g]),o=[],s=new Set,a=[];for(let g=0;g<n.length;g++)for(let b=g+1;b<n.length;b++){let y=By(n[g],n[b],e);y!==null&&a.push([g,b,y])}a.sort((g,b)=>Math.abs(g[2])-Math.abs(b[2]));let l=new Map(n.map((g,b)=>[b,[b]])),c=(g,b)=>g.some(y=>b.some(v=>n[y].room===n[v].room&&Math.abs(n[y].offset-n[v].offset)>=.002));for(let[g,b,y]of a){let[v,w]=[i(g),i(b)];if(v!==w){if(c(l.get(v),l.get(w)))continue;r[v]=w,l.set(w,[...l.get(w),...l.get(v)]),l.delete(v)}o.push(Ea(y)),s.add(g).add(b)}let d=new Map(n.map((g,b)=>[`${g.room}:${g.index}`,b]));for(let g=s.size>0;g;)g=!1,n.forEach((b,y)=>{let v=d.get(`${b.room}:${(b.index+1)%t[b.room].points.length}`);if(v===void 0||v===y)return;let w=n[v];!(Math.abs(Ae(b.dir,w.dir))<1e-6&&Math.abs(b.offset-w.offset)<.002&&b.outside===w.outside)||s.has(y)===s.has(v)||(s.add(y).add(v),g=!0)});n.forEach((g,b)=>{let y=d.get(`${g.room}:${(g.index+1)%t[g.room].points.length}`);if(y===void 0||y===b||!s.has(b)||!s.has(y))return;let v=n[y];Math.abs(Ae(g.dir,v.dir))<1e-6&&Math.abs(g.offset-v.offset)<.002&&g.outside===v.outside&&(r[i(b)]=i(y))});let u=()=>t.map(g=>({...g,points:g.points.map(b=>[b[0],b[1]])}));if(o.length===0)return{rooms:u(),gaps:o};let p=new Map;for(let g of s)p.set(i(g),[...p.get(i(g))??[],g]);let h=t.map(g=>g.points.map(()=>new Map));for(let[g,b]of p){let y=new Map(b.map(w=>[`${n[w].room}:${Math.round(n[w].offset*500)}`,n[w].offset])),v=[...y.values()].reduce((w,k)=>w+k,0)/y.size;for(let w of b){let k=n[w],x=[k.normal[0]*(v-k.offset),k.normal[1]*(v-k.offset)];h[k.room][k.index].set(g,x),h[k.room][(k.index+1)%t[k.room].points.length].set(g,x)}}return{rooms:t.map((g,b)=>({...g,points:g.points.map((y,v)=>{let w=[...h[b][v].values()].reduce((k,x)=>[k[0]+x[0],k[1]+x[1]],[y[0],y[1]]);return[Ea(w[0]),Ea(w[1])]})})),gaps:o}}function nh(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 Vy=.25,rh=t=>Math.round(t*1e3)/1e3,ih=(t,e,n)=>t.rooms.find(r=>r.points.length>=3&&C([e,n],r.points));function Aa(t,e,n,r,i){let o=ih(t,e,n);if(!o)return[r,i];let s=(a,l)=>C([a,l],o.points);return s(r,i)?[r,i]:s(r,n)?[r,n]:s(e,i)?[e,i]:[e,n]}function Wy(t,e,n,r){return t.rooms.some(i=>i.id!==e.id&&i.points.some((o,s)=>{let a=i.points[(s+1)%i.points.length];return Math.abs(te(G(o,n),r))<.02&&Math.abs(te(G(a,n),r))<.02}))}var Ra=(t,e)=>Math.abs((t-e+540)%360-180);function Nr(t,e,n,r=Vy){let i=ih(t,e.x,e.z);if(!i)return null;let o=i.points,s=be(o)>=0?1:-1,a=null;return o.forEach((l,c)=>{let d=o[(c+1)%o.length],u=_e(G(d,l));if(u<.3)return;let p=[(d[0]-l[0])/u,(d[1]-l[1])/u],h=[-p[1]*s,p[0]*s],f=te(G([e.x,e.z],l),p);if(f<0||f>u)return;let g=Wy(t,i,l,h)?n/2:0,b=te(G([e.x,e.z],l),h)-g,y=Math.atan2(-h[0],h[1])*180/Math.PI,w=[{rotation:y,extent:e.d/2},{rotation:y+90,extent:e.w/2},{rotation:y-90,extent:e.w/2}].reduce((x,M)=>Ra(e.rotation,M.rotation)<Ra(e.rotation,x.rotation)?M:x);if(Ra(e.rotation,w.rotation)>50)return;let k=b-w.extent;Math.abs(k)>r||a&&Math.abs(k)>=Math.abs(a.gap)||(a={x:rh(e.x-h[0]*k),z:rh(e.z-h[1]*k),rotation:(Math.round(w.rotation)%360+360)%360,gap:k})}),a&&{x:a.x,z:a.z,rotation:a.rotation}}var Kn=Math.PI/180,st=t=>Math.tan(Math.min(80,Math.max(0,t))*Kn);function Vr(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 oh(t){if(!t.rotation)return null;let e=t.rotation*Kn;return{cx:(t.x0+t.x1)/2,cz:(t.z0+t.z1)/2,c:Math.cos(e),sn:Math.sin(e)}}function sh(t,e){let n=oh(t);if(!n)return e;let[r,i]=[e[0]-n.cx,e[1]-n.cz];return[n.cx+r*n.c-i*n.sn,n.cz+r*n.sn+i*n.c]}function Fa(t,e,n){let r=oh(t);if(!r)return[e,n];let[i,o]=[e-r.cx,n-r.cz];return[r.cx+i*r.c+o*r.sn,r.cz-i*r.sn+o*r.c]}function Wr(t,e=0){let{x0:n,x1:r,z0:i,z1:o}=Vr(t);return[[n-e,i-e],[r+e,i-e],[r+e,o+e],[n-e,o+e]].map(s=>sh(t,s))}function $e(t){let{x0:e,x1:n,z0:r,z1:i}=Vr(t),o=s=>sh(t,s);return t.axis==="x"?{u0:e,u1:n,w:i-r,at:(s,a)=>o([s,t.flip?i-a:r+a])}:{u0:r,u1:i,w:n-e,at:(s,a)=>o([t.flip?n-a:e+a,s])}}function Kr(t,e,n){let{x0:r,x1:i,z0:o,z1:s}=Vr(t),[a,l]=Fa(t,e,n);return t.axis==="x"?[a,t.flip?s-l:l-o]:[l,t.flip?i-a:a-r]}var Br=Math.tan(30*Kn);function jr(t,e,n,r,i){let o=Math.min(t*.3,r>1e-6?2.4/r:t*.3),s=Math.min(t*.3,i>1e-6?2.4/i:t*.3),a=e+o*r,l=n+s*i,c=Math.min(t-s,Math.max(o,(l-a+Br*(t-s+o))/(2*Br))),d=a+(c-o)*Br;return{vla:o,vlb:s,yla:a,ylb:l,vr:c,rh:d,y:p=>p<=o?e+p*r:p<=c?a+(p-o)*Br:p<=t-s?l+(t-s-p)*Br:n+(t-p)*i}}function Ce(t){let e=$e(t).w,[n,r]=[t.eave_a,t.eave_b],[i,o]=[st(t.pitch_a),st(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*i,y:s=>n+s*i};case"mansard":{let s=jr(e,n,r,i,o);return{vr:s.vr,rh:s.rh,y:s.y}}default:{let s=i+o>1e-6?Math.min(e,Math.max(0,(r-n+e*o)/(i+o))):e/2;return{vr:s,rh:n+s*i,y:a=>a<=s?n+a*i:r+(e-a)*o}}}}var un=t=>Ce(t).rh;function ah(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 Ky(t,e){let n=t.map(r=>({...r}));for(let r of e){let i=n.find(o=>o.room_id===r.room_id&&o.edge===r.edge&&(Math.abs(o.t1-r.t0)<1e-6||Math.abs(r.t1-o.t0)<1e-6));i?(i.t0=Math.min(i.t0,r.t0),i.t1=Math.max(i.t1,r.t1)):n.push({...r})}return n}function jy(t,e,n){if(t.a===e.b)return!1;let r=ot(G(n[t.b],n[t.a])),i=ot(G(n[e.b],n[e.a]));return Math.abs(Ae(r,i))>1e-6||te(r,i)<=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 lh(t,e,n=new Set){let r=t.slice();for(;;){let i=new Map;r.forEach((s,a)=>{for(let l of[s.a,s.b])i.set(l,[...i.get(l)??[],a])});let o=null;for(let[s,a]of i){if(a.length!==2||n.has(s))continue;let l=r[a[0]].b===s?r[a[0]]:ah(r[a[0]]),c=r[a[1]].a===s?r[a[1]]:ah(r[a[1]]);if(!jy(l,c,e))continue;let d={...l,b:c.b,sources:Ky(l.sources,c.sources)};o=[...r.filter((u,p)=>p!==a[0]&&p!==a[1]),d];break}if(!o)return r;r=o}}function ch(t,e){let n=new Map;t.forEach((i,o)=>{let s=ot(G(e[i.b],e[i.a])),a=[[i.a,{key:`${o}:a`,d:s,left:i.left,right:i.right,angle:Math.atan2(s[1],s[0])}],[i.b,{key:`${o}:b`,d:it(s,-1),left:i.right,right:i.left,angle:Math.atan2(-s[1],-s[0])}]];for(let[l,c]of a)n.set(l,[...n.get(l)??[],c])});let r=new Map;for(let[i,o]of n){let s=e[i];o.sort((l,c)=>l.angle-c.angle);for(let l of o)r.set(l.key,{left:ft(s,it(Sa(l.d),l.left)),right:ft(s,it(Ma(l.d),l.right))});if(o.length<2)continue;let a=4*Math.max(...o.map(l=>Math.max(l.left,l.right)))+1e-9;o.forEach((l,c)=>{let d=o[(c+1)%o.length],u=ft(s,it(Sa(l.d),l.left)),p=ft(s,it(Ma(d.d),d.right)),h=Ae(l.d,d.d);if(Math.abs(h)<1e-4)return;let f=ft(u,it(l.d,Ae(G(p,u),d.d)/h));_e(G(f,s))>a||(r.get(l.key).left=f,r.get(d.key).right=f)})}return r}function dh(t,e){let n=t.filter((r,i)=>_e(G(r,t[(i+1)%t.length]))>e);for(;;){if(n.length<=3)return n;let r=n.findIndex((i,o)=>{let s=n[(o+n.length-1)%n.length],a=n[(o+1)%n.length],[l,c]=[G(i,s),G(a,i)];return Math.abs(Ae(ot(l),ot(c)))<1e-7&&te(l,c)>0});if(r===-1)return n;n=n.filter((i,o)=>o!==r)}}function Gy(t){let e=[];return{points:e,idOf(n){let r=e.findIndex(i=>Math.abs(i[0]-n[0])<=t&&Math.abs(i[1]-n[1])<=t);return r>=0?r:(e.push([n[0],n[1]]),e.length-1)}}}function Uy(t,e){let n=[];for(let r of t){let i=r.points;if(i.length<3||Math.abs(be(i))<1e-6)continue;let o=be(i)>0,s=i.map(a=>e.idOf(a));s.forEach((a,l)=>{let c=s[(l+1)%s.length];a!==c&&n.push(o?{u:a,v:c,room:r.id,edge:l,forward:!0}:{u:c,v:a,room:r.id,edge:l,forward:!1})})}return n}function Zy(t,e,n){let r=[];for(let i of t){let[o,s]=[e[i.u],e[i.v]],a=G(s,o),l=_e(a),c=it(a,1/l),d=e.map((p,h)=>({id:h,rel:G(p,o)})).filter(({id:p,rel:h})=>p!==i.u&&p!==i.v&&te(h,c)>n&&te(h,c)<l-n&&Math.abs(Ae(c,h))<=n).map(({id:p,rel:h})=>({t:te(h,c),id:p})).sort((p,h)=>p.t-h.t),u=[{t:0,id:i.u},...d,{t:l,id:i.v}];for(let p=0;p+1<u.length;p++){let[h,f]=[u[p],u[p+1]];r.push({u:h.id,v:f.id,room:i.room,edge:i.edge,t0:i.forward?h.t:l-f.t,t1:i.forward?f.t:l-h.t,forward:i.forward})}}return r}var uh=t=>({room_id:t.room,edge:t.edge,t0:t.t0,t1:t.t1});function qy(t,e){let n=new Map(t.map(a=>[a.id,a])),r=new Map;for(let a of e){let l=`${a.room}:${a.edge}`;r.set(l,[...r.get(l)??[],a.t0].sort((c,d)=>c-d))}let i=a=>{let l=n.get(a.room)?.wall_heights?.[a.edge];return Array.isArray(l)?l[(r.get(`${a.room}:${a.edge}`)??[]).indexOf(a.t0)]??null:l},o=a=>{let l=n.get(a.room),[c,d]=[l?.wall_heights?.[a.edge],l?.wall_slopes?.[a.edge]];if(!l||typeof c!="number"||typeof d!="number"||c<=0||d<=0)return null;let[u,p]=[l.points[a.edge],l.points[(a.edge+1)%l.points.length]];return{from:c,to:d,length:Math.hypot(p[0]-u[0],p[1]-u[1])}},s=a=>{let l=o(a);if(!l||l.length<1e-9){let d=i(a);return typeof d=="number"&&d>0?[d,d]:[null,null]}let c=d=>l.from+(l.to-l.from)*d/l.length;return a.forward?[c(a.t0),c(a.t1)]:[c(a.t1),c(a.t0)]};return{heightsOf(a){let[l,c]=[1/0,1/0];for(let u of a){let[p,h]=s(u),[f,g]=u===a[0]?[p,h]:[h,p];f!==null&&(l=Math.min(l,f)),g!==null&&(c=Math.min(c,g))}let d=a.map(u=>n.get(u.room)?.ceiling);if(d.every(u=>typeof u=="number"&&u>0)){let u=Math.max(...d);l===1/0&&(l=u),c===1/0&&(c=u)}return{...l<1/0?{a:l}:{},...c<1/0?{b:c}:{}}},thicknessOf(a){let l=a.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 l.length?Math.max(...l):void 0},hasNoWall:a=>a.some(l=>i(l)===0)}}function hh(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 Yy(t,e,n,r){let i=qy(e,t),o=new Map;for(let l of t){let c=l.u<l.v?`${l.u}-${l.v}`:`${l.v}-${l.u}`;o.set(c,[...o.get(c)??[],l])}let s=[],a=[];for(let l of o.values()){let c=l[0],d=l.find(p=>p!==c&&p.u===c.v&&p.v===c.u&&p.room!==c.room);for(let p of l)p!==c&&p!==d&&p.room!==c.room&&r.push(`overlap:${c.room}:${p.room}`);let u=d?[c,d]:[c];if(i.hasNoWall(u)){d&&a.push([c.room,d.room]);continue}if(d){let p=i.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(uh),...hh(i.heightsOf(u))})}else s.push({a:c.u,b:c.v,left:0,right:i.thicknessOf(u)??n.exterior,exterior:!0,roomLeft:c.room,roomRight:null,sources:[uh(c)],...hh(i.heightsOf(u))})}return{drafts:s,open:a}}function Xy(t,e){let n=o=>ot(G(e[o.b],e[o.a])),r=t.filter(o=>!o.exterior&&!o.free),i=new Map;for(let o of r){if(i.has(o))continue;let s=[o];i.set(o,s);for(let a=0;a<s.length;a++){let l=s[a];for(let c of r){if(i.has(c))continue;(c.a===l.a||c.a===l.b||c.b===l.a||c.b===l.b)&&Math.abs(Ae(n(l),n(c)))<1e-6&&(s.push(c),i.set(c,s))}}}for(let o of new Set(i.values())){let s=n(o[0]),a=new Map;for(let d of o)for(let u of[d.a,d.b])a.set(u,(a.get(u)??0)+1);let l=new Set;for(let[d,u]of a)if(u===1)for(let p of t){if(!p.exterior||p.free||p.a!==d&&p.b!==d)continue;let h=n(p);Math.abs(Ae(s,h))>1e-6||l.add(te(s,h)>0?"left":"right")}if(l.size!==1)continue;let c=[...l][0];for(let d of o){let u=d.left+d.right,p=te(n(d),s)>0,h=c==="left"===p;[d.left,d.right]=h?[0,u]:[u,0]}}}var Jy=(t,e)=>{let n=o=>Math.round(o*100),[r,i]=t[0]<e[0]||t[0]===e[0]&&t[1]<=e[1]?[t,e]:[e,t];return`w_${n(r[0])}_${n(r[1])}_${n(i[0])}_${n(i[1])}`};function me(t,e,n=[]){let r=e.eps??.005,i=[],o=Gy(r),s=Uy(t,o),a=n.filter(y=>Math.hypot(y.b[0]-y.a[0],y.b[1]-y.a[1])>.05),l=a.map(y=>[o.idOf(y.a),o.idOf(y.b)]),c=new Set;for(let y of t){let v=y.points;v.length<3||(y.wall_splits??[]).forEach((w,k)=>{if(!w||k>=v.length)return;let x=v[k],M=G(v[(k+1)%v.length],x),A=_e(M);for(let T of w)T>r&&T<A-r&&c.add(o.idOf(ft(x,it(M,T/A))))})}let d=Zy(s,o.points,r),{drafts:u,open:p}=Yy(d,t,e,i);Xy(u,o.points);let h=u;a.forEach((y,v)=>{let[w,k]=l[v];if(w===k)return;let x=[(y.a[0]+y.b[0])/2,(y.a[1]+y.b[1])/2],M=t.find(T=>T.points.length>=3&&C(x,T.points))?.id??null,A=(y.thickness??e.interior)/2;h.push({free:y.id,a:w,b:k,left:A,right:A,exterior:!1,roomLeft:M,roomRight:M,sources:[],height:typeof y.height=="number"&&y.height>0?y.height:void 0,...typeof y.height=="number"&&y.height>0&&typeof y.height_end=="number"&&y.height_end>0&&Math.abs(y.height_end-y.height)>1e-6?{heightEnd:y.height_end}:{}})});let f=lh(h,o.points,c),g=ch(f,o.points);return{walls:f.map((y,v)=>{let[w,k]=[o.points[y.a],o.points[y.b]],[x,M]=[g.get(`${v}:a`),g.get(`${v}:b`)],A=dh([x.right,M.left,k,M.right,x.left,w],1e-6);return{id:Jy(w,k),a:[w[0],w[1]],b:[k[0],k[1]],left:y.left,right:y.right,exterior:y.exterior,roomLeft:y.roomLeft,roomRight:y.roomRight,sources:y.sources,footprint:A,...y.free?{free:y.free}:{},...y.height!==void 0?{height:y.height}:{},...y.heightEnd!==void 0?{heightEnd:y.heightEnd}:{}}}),warnings:[...new Set(i)],open:p}}function jn(t,e,n){let r=t.points[e];return ft(r,it(ot(G(t.points[(e+1)%t.points.length],r)),n))}function Ne(t,e,n){if(t.wall){let i=n.find(a=>a.id===t.wall);if(!i||Math.hypot(i.b[0]-i.a[0],i.b[1]-i.a[1])<.05)return null;let o=ot(G(i.b,i.a));return{room:{id:t.room_id,name:"",area_id:null,points:[i.a,i.b,ft(i.a,[-o[1],o[0]])]},edge:0}}let r=e.find(i=>i.id===t.room_id);return r&&t.edge<r.points.length?{room:r,edge:t.edge}:null}var ph=(t,e)=>te(G(e,t.a),ot(G(t.b,t.a)));function Kt(t,e,n){if(!e.wall)return Qy(t,n.room,n.edge,e.offset);let r=t.find(i=>i.free===e.wall);return r?{wall:r,s:ph(r,jn(n.room,0,e.offset))}:null}function Qy(t,e,n,r){for(let i of t)if(i.sources.some(s=>s.room_id===e.id&&s.edge===n&&r>=s.t0-1e-6&&r<=s.t1+1e-6))return{wall:i,s:ph(i,jn(e,n,r))};return null}function fh(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[i,o,s,a]=[Math.min(...n),Math.max(...n),Math.min(...r),Math.max(...r)],l=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=o-i-l(h=>d(h,0,i))-l(h=>d(h,0,o)),p=a-s-l(h=>d(h,1,s))-l(h=>d(h,1,a));return[Math.round(u*1e3)/1e3,Math.round(p*1e3)/1e3]}var mh=([t,e])=>{let n=Math.hypot(t,e)||1;return[t/n,e/n]};function ev(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 gh(t,e){let n=t.length;if(n<3||Math.abs(e)<1e-9)return t.map(([i,o])=>[i,o]);let r=ev(t)>=0?1:-1;return t.map((i,o)=>{let s=t[(o+n-1)%n],a=t[(o+1)%n],[l,c]=mh([i[0]-s[0],i[1]-s[1]]),[d,u]=mh([a[0]-i[0],a[1]-i[1]]),p=[c*r,-l*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[i[0]+p[0]*e,i[1]+p[1]*e];let b=(f[0]*p[0]+f[1]*p[1])/g,y=Math.min(4,1/Math.max(.25,b));return[i[0]+f[0]/g*e*y,i[1]+f[1]/g*e*y]})}function jt(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 tv(t){let e=([o,s])=>`${Math.round(o*1e3)}:${Math.round(s*1e3)}`,n=new Map;for(let o of t)for(let s of[o.a,o.b])n.set(e(s),[...n.get(e(s))??[],o]);let r=new Set,i=null;for(let o of t){if(r.has(o))continue;r.add(o);let s=[o.a,o.b],a=o.b;for(;;){let c=(n.get(e(a))??[]).find(d=>!r.has(d));if(!c||(r.add(c),a=e(c.a)===e(a)?c.b:c.a,e(a)===e(s[0])))break;s.push(a)}s.length>=3&&e(a)===e(s[0])&&(!i||Math.abs(ye(s))>Math.abs(ye(i)))&&(i=s)}return i}function Ta(t,e,n,r){let i=me(t,{exterior:n,interior:r},e).walls.filter(a=>a.exterior&&!a.free),o=i.length?tv(i.map(a=>({a:a.a,b:a.b}))):null;if(!o)return null;let s=o.filter((a,l)=>{let c=o[(l+o.length-1)%o.length],d=o[(l+1)%o.length];return Math.abs((a[0]-c[0])*(d[1]-a[1])-(a[1]-c[1])*(d[0]-a[0]))>1e-6});return s.length>=3?gh(s,n):null}function hn(t,e){let n=$e(t),r=Ce(t),i=n.w,[o,s]=[Math.max(0,e.a),Math.max(0,e.b)],a=n.u0-Math.max(0,e.u0),l=n.u1+Math.max(0,e.u1),c=(y,v)=>[y,v,r.y(v)],d=c(a,-o),u=c(l,-o),p=c(l,i+s),h=c(a,i+s),[f,g]=[st(t.pitch_a),st(t.pitch_b)],b=y=>[y,r.vr,r.rh];if(t.ends&&(t.shape==="gable"||t.shape==="hip"||t.shape==="halfhip")){let y=(n.u1-n.u0)/2,v=Math.min(y,Math.min(r.vr,i-r.vr)||i/2),w=Math.min(r.y(0),r.y(i)),k=w+(r.rh-w)*Math.min(.9,Math.max(.2,t.halfhip??.55)),x=f>1e-6?Math.min(r.vr,(k-t.eave_a)/f):r.vr,M=g>1e-6?Math.max(r.vr,i-(k-t.eave_b)/g):r.vr,A=Math.min(y-.1,(r.rh-k)/Math.max(.2,f)),T=[[0,r.y(0)],[r.vr,r.rh],[i,r.y(i)]],F=[[0,r.y(0)],[x,k],[M,k],[i,r.y(i)]],L=(j,Jt,Ci)=>{if(j==="hip")return{upA:[],upB:[],ridge:b(Jt===a?n.u0+v*Ci:n.u1-v*Ci),profile:null};if(j==="halfhip"){let zb=b(Jt===a?n.u0+A:n.u1-A);return{upA:[[Jt,x,k]],upB:[[Jt,M,k]],ridge:zb,profile:F}}return{upA:[],upB:[],ridge:b(Jt),profile:T}},I=L(t.ends[0],a,1),N=L(t.ends[1],l,1),V=[[d,u,...N.upA,N.ridge,I.ridge,...[...I.upA].reverse()],[I.ridge,N.ridge,...[...N.upB].reverse(),p,h,...I.upB]],X=[[I.ridge,N.ridge]];for(let[j,Jt,Ci]of[[I,d,h],[N,u,p]])j.profile===null?(V.push(j===I?[h,d,j.ridge]:[u,p,j.ridge]),X.push([Jt,j.ridge],[Ci,j.ridge])):j.upA.length&&(V.push(j===I?[j.upB[0],j.upA[0],j.ridge]:[j.upA[0],j.upB[0],j.ridge]),X.push([j.upA[0],j.ridge],[j.upB[0],j.ridge]));let ke=j=>j.profile===null?[]:j.upA.length?[j.upA[0],j.upB[0]]:[j.ridge],Ft=[d,u,...ke(N),p,h,...[...ke(I)].reverse()];return{faces:V,rim:Ft,ridges:X,gable:T,endProfiles:[I.profile,N.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)],[i,r.y(i)]]};case"hip":case"pyramid":{let y=(n.u1-n.u0)/2,v=t.shape==="pyramid"?y:Math.min(y,Math.min(r.vr,i-r.vr)||i/2),w=b(n.u0+v),k=b(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,k,w],[w,k,p,h],[h,d,w],[u,p,k]],rim:[d,u,p,h],ridges:[[w,k],[d,w],[h,w],[u,k],[p,k]],gable:null}}case"halfhip":{let y=Math.min(r.y(0),r.y(i)),v=y+(r.rh-y)*Math.min(.9,Math.max(.2,t.halfhip??.55)),w=f>1e-6?Math.min(r.vr,(v-t.eave_a)/f):r.vr,k=g>1e-6?Math.max(r.vr,i-(v-t.eave_b)/g):r.vr,x=Math.min((n.u1-n.u0)/2-.1,(r.rh-v)/Math.max(.2,f)),M=b(n.u0+x),A=b(n.u1-x),T=[a,w,v],F=[a,k,v],L=[l,w,v],I=[l,k,v];return{faces:[[d,u,L,A,M,T],[M,A,I,p,h,F],[F,T,M],[L,I,A]],rim:[d,u,L,I,p,h,F,T],ridges:[[M,A],[T,M],[F,M],[L,A],[I,A]],gable:[[0,r.y(0)],[w,v],[k,v],[i,r.y(i)]]}}case"mansard":{let y=jr(i,t.eave_a,t.eave_b,f,g),v=[a,y.vla,y.yla],w=[l,y.vla,y.yla],k=[a,i-y.vlb,y.ylb],x=[l,i-y.vlb,y.ylb],M=[a,y.vr,y.rh],A=[l,y.vr,y.rh];return{faces:[[d,u,w,v],[v,w,A,M],[M,A,x,k],[k,x,p,h]],rim:[d,u,w,A,x,p,h,k,M,v],ridges:[[M,A],[v,w],[k,x]],gable:[[0,r.y(0)],[y.vla,y.yla],[y.vr,y.rh],[i-y.vlb,y.ylb],[i,r.y(i)]]}}default:{let y=b(a),v=b(l);return{faces:[[d,u,v,y],[y,v,p,h]],rim:[d,u,v,p,h,y],ridges:[[y,v]],gable:[[0,r.y(0)],[r.vr,r.rh],[i,r.y(i)]]}}}}function Gr(t,e,n){let r=null;for(let i of t.faces){if(!C([e,n],i.map(([p,h])=>[p,h])))continue;let[o,s]=i,a=i.slice(2).find(p=>Math.abs((s[0]-o[0])*(p[1]-o[1])-(s[1]-o[1])*(p[0]-o[0]))>1e-9);if(!a)continue;let l=[s[0]-o[0],s[2]-o[2],s[1]-o[1]],c=[a[0]-o[0],a[2]-o[2],a[1]-o[1]],d=[l[1]*c[2]-l[2]*c[1],l[2]*c[0]-l[0]*c[2],l[0]*c[1]-l[1]*c[0]];if(Math.abs(d[1])<1e-9)continue;let u=o[2]-(d[0]*(e-o[0])+d[2]*(n-o[1]))/d[1];r=r===null?u:Math.min(r,u)}return r}function Ur(t,e,n){let r=$e(e),i=t.floors.flatMap(u=>u.rooms.filter(p=>p.points.length>=3&&u.elevation+u.height>e.base+.05)),o=u=>u.some(p=>i.some(h=>C(p,h.points))),s=.35,a=[.15,.5,.85].map(u=>r.u0+(r.u1-r.u0)*u),l=[.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(o(a.map(u=>r.at(u,-s))))),b:d("b",c(o(a.map(u=>r.at(u,r.w+s))))),u0:d("u0",c(o(l.map(u=>r.at(r.u0-s,u))))),u1:d("u1",c(o(l.map(u=>r.at(r.u1+s,u)))))}}var So=t=>Math.abs((t.x1-t.x0)*(t.z1-t.z0)),_h=t=>t.shape==="flat"||t.shape==="parapet",pn=t=>Math.round(t*100)/100;function Mo(t,e){let[n,r]=[(e.x0+e.x1)/2,(e.z0+e.z1)/2];return t.filter(o=>{if(o===e||o.dormer||o.open||_h(o)||So(o)<So(e)*1.5)return!1;let s=Vr(o);return n>=s.x0&&n<=s.x1&&r>=s.z0&&r<=s.z1}).reduce((o,s)=>o===null||So(s)<So(o)?s:o,null)}function za(t,e,n,r){let i=$e(t),o=Ce(t),s=2,a=Math.max(i.u0+.3,Math.min(i.u1-s-.3,(r??(i.u0+i.u1)/2)-s/2)),[l,c]=e==="a"?[t.eave_a,t.pitch_a]:[t.eave_b,t.pitch_b],d=l+1.4,u=d+s/2*Math.tan(35*Kn),p=Math.max(.8,Math.min(i.w/2-.2,(u-l)/Math.max(.15,Math.tan(Math.min(80,c)*Kn)))),[h,f]=e==="a"?[0,p]:[i.w-p,i.w],g=i.at(a,h),b=i.at(a+s,f);return{id:n,x0:pn(Math.min(g[0],b[0])),z0:pn(Math.min(g[1],b[1])),x1:pn(Math.max(g[0],b[0])),z1:pn(Math.max(g[1],b[1])),shape:"gable",axis:t.axis==="x"?"z":"x",eave_a:pn(d),eave_b:pn(d),pitch_a:35,pitch_b:35,base:pn(o.y(e==="a"?0:i.w)),overhang:.15,dormer:!0}}function rv(t,e){let n=hn(t,{u0:0,u1:0,a:0,b:0}),r=Ce(t);return i=>{let[o,s]=e.at(i,e.w/2),[a,l]=Kr(t,o,s);return Gr(n,a,l)??r.y(l)}}function Pa(t,e){if(_h(e))return e;let n=$e(e),r=Ce(e).rh,i=rv(t,n),o=i(n.u0)<=i(n.u1),[s,a]=o?[n.u0,n.u1]:[n.u1,n.u0],l=o?1:-1,c=a;for(let p=.5;p<Math.abs(a-s);p+=.05)if(i(s+l*p)>=r-.02){c=s+l*p;break}if(Math.abs(c-a)<.05)return e;let d={...e},u=a===n.u1;return e.axis==="x"?d[u?"x1":"x0"]=c:d[u?"z1":"z0"]=c,d}var Ia=.14,bh=t=>t.shape==="flat"||t.shape==="parapet";function Da(t,e){return!t.open&&Math.min(t.base,t.eave_a,t.eave_b)<e-.05}function Zr(t,e,n){let r=Math.max(0,t.settings.roof.overhang??0),i=1e-6,o=[];for(let s of t.settings.roof.sections??[]){if(s.open)continue;let[a,l,c,d]=[Math.min(s.x0,s.x1),Math.max(s.x0,s.x1),Math.min(s.z0,s.z1),Math.max(s.z0,s.z1)],[u,p]=Fa(s,e,n);if(u<a-i||u>l+i||p<c-i||p>d+i||s.points&&s.points.length>=3&&!C([e,n],s.points))continue;let[h,f]=Kr(s,e,n),g=Math.max(0,s.overhang??r),b=bh(s)?null:Gr(hn(s,{u0:g,u1:g,a:g,b:g}),h,f);o.push((b??Ce(s).y(f))-Ia)}return o.length?Math.max(...o):null}function Oa(t,e,n){let r=[],i=e+n+Ia;for(let o of t.settings.roof.sections??[]){if(o.open||bh(o)||o.shape==="mansard")continue;let s=$e(o),a=Ce(o),[l,c]=[st(o.pitch_a),st(o.pitch_b)],d=[];l>1e-6&&d.push((i-o.eave_a)/l),o.shape==="gable"&&c>1e-6&&d.push(s.w-(i-o.eave_b)/c);for(let u of d)u<=.01||u>=s.w-.01||o.shape==="gable"&&Math.abs(a.y(u)-i)>1e-6||r.push([s.at(s.u0,u),s.at(s.u1,u)])}return r}function Ha(t,e,n,r,i){let o=[];for(let a of[.2,.5,.8])for(let l of[.2,.5,.8])o.push([e+(r-e)*a,n+(i-n)*l]);let s=t.floors.filter(a=>a.rooms.some(l=>l.points.length>=3&&o.some(c=>C(c,l.points)))).map(a=>a.elevation+a.height);return s.length?Math.max(...s):null}function La(t,e){let n=t.floors.filter(l=>l.rooms.length>0).sort((l,c)=>l.elevation-c.elevation),r=n.filter(l=>l.elevation<e.base-.05),{x0:i,z0:o,x1:s,z1:a}=e;if(i!==void 0&&o!==void 0&&s!==void 0&&a!==void 0){let l=[];for(let d of[.2,.5,.8])for(let u of[.2,.5,.8])l.push([i+(s-i)*d,o+(a-o)*u]);let c=r.findLast(d=>d.rooms.some(u=>u.points.length>=3&&l.some(p=>C(p,u.points))));if(c)return c}return r.at(-1)??n[0]}var kt=t=>Math.round(t*1e3)/1e3;function Ca(t,e=n=>`roof_${n+1}`){let n=t.settings.roof?.pitch??35,r=t.settings.wall_exterior,i=t.floors.filter(l=>l.rooms.some(c=>c.points.length>=3)).sort((l,c)=>c.elevation-l.elevation),o=[],s=[],a=(l,c)=>l.some(d=>C(c,d.points));for(let l of i){let c=l.rooms.filter(b=>b.points.length>=3),d=[...new Set(c.flatMap(b=>b.points.map(y=>kt(y[0]))))].sort((b,y)=>b-y),u=[...new Set(c.flatMap(b=>b.points.map(y=>kt(y[1]))))].sort((b,y)=>b-y),p=u.slice(0,-1).map((b,y)=>d.slice(0,-1).map((v,w)=>{let k=[(d[w]+d[w+1])/2,(u[y]+u[y+1])/2];return a(c,k)&&!a(s,k)})),h=p.map(b=>b.map(()=>!1)),f=(b,y)=>p[y][b]&&!h[y][b],g=l.elevation+l.height;for(let b=0;b<p.length;b++)for(let y=0;y<(p[b]?.length??0);y++){if(!f(y,b))continue;let v=y;for(;v+1<p[b].length&&f(v+1,b);)v++;let w=b;for(;w+1<p.length&&Array.from({length:v-y+1},(T,F)=>f(y+F,w+1)).every(Boolean);)w++;for(let T=b;T<=w;T++)for(let F=y;F<=v;F++)h[T][F]=!0;let[k,x]=[d[y]-r,d[v+1]+r],[M,A]=[u[b]-r,u[w+1]+r];Math.min(x-k,A-M)<.8||o.push({id:e(o.length),x0:kt(k),z0:kt(M),x1:kt(x),z1:kt(A),shape:"gable",axis:x-k>=A-M?"x":"z",eave_a:kt(g),eave_b:kt(g),pitch_a:n,pitch_b:n,base:kt(g),overhang:null})}s.push(...c)}return o}var Fe=Math.PI/180,Ue=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],fn=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2],Gn=t=>Math.hypot(t[0],t[1],t[2]),mn=t=>{let e=Gn(t)||1;return[t[0]/e,t[1]/e,t[2]/e]},yh=(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]],Ze=t=>Math.round(t*100)/100,qr=([t,e],n)=>(Math.atan2(t,-e)/Fe-n+720)%360;var wh=.25;function xh(t,e,n,r,i,o,s){let a=i-n>=o-r,l=a?i-n:o-r;return{key:`${t}:top`,section:e,side:"top",flat:!0,o:[n,s,r],eu:a?[1,0,0]:[0,0,1],es:a?[0,0,1]:[1,0,0],n:[0,1,0],lu:l,ls:a?o-r:i-n,pitch:0,span:()=>[0,l],facing:a?[0,1]:[1,0]}}function kh(t,e){let n=mn(yh(t,e));return n[1]<0?[-n[0],-n[1],-n[2]]:n}var $h=t=>{let e=mn([-t[0],0,-t[2]]);return[e[0],e[2]]};function $t(t,e,n,r,i,o,s,a){let l=mn(Ue(i,r)),c=mn(Ue(o,r));return{key:t,section:e,side:n,flat:!1,o:r,eu:l,es:c,n:kh(l,c),lu:Gn(Ue(i,r)),ls:Gn(Ue(o,r)),pitch:s,span:a,facing:$h(c)}}function vh(t,e,n,r,i,o){let s=Gn(Ue(i,r));if(s<.3)return null;let a=mn(Ue(i,r)),l=Ue(o,r),c=l[0]*a[0]+l[1]*a[1]+l[2]*a[2],d=[l[0]-a[0]*c,l[1]-a[1]*c,l[2]-a[2]*c],u=Gn(d);if(u<.3)return null;let p=mn(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:a,es:p,n:kh(a,p),lu:s,ls:u,pitch:Math.atan2(p[1],Math.hypot(p[0],p[2]))/Fe,span:h,facing:$h(p)}}function iv(t,e){let n=$e(t),r=Ce(t),i=(v,w,k)=>{let[x,M]=n.at(v,w);return[x,k,M]},[o,s]=[Math.max(0,e.a),Math.max(0,e.b)],a=n.u0-Math.max(0,e.u0),l=n.u1+Math.max(0,e.u1),c=l-a,d=r.y(-o),u=r.y(n.w+s);if(t.shape==="flat"||t.shape==="parapet"){let[v,w]=[n.at(a,-o),n.at(l,n.w+s)];return[xh(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+wh)]}if(t.shape==="pent")return[$t(`${t.id}:a`,t.id,"a",i(a,-o,d),i(l,-o,d),i(a,n.w+s,u),t.pitch_a,()=>[0,c])];if(t.shape==="mansard")return ov(t,n,a,l,o,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-a:0,b=p?l-(n.u1-f):0,y=[];if(r.vr>.3){let v=Math.hypot(r.vr+o,r.rh-d);y.push($t(`${t.id}:a`,t.id,"a",i(a,-o,d),i(l,-o,d),i(a,r.vr,r.rh),t.pitch_a,w=>[g*(w/v),c-b*(w/v)]))}if(n.w-r.vr>.3){let v=Math.hypot(n.w+s-r.vr,r.rh-u);y.push($t(`${t.id}:b`,t.id,"b",i(l,n.w+s,u),i(a,n.w+s,u),i(l,r.vr,r.rh),t.pitch_b,w=>[b*(w/v),c-g*(w/v)]))}if(p){let v=vh(`${t.id}:c`,t.id,"c",i(a,n.w+s,u),i(a,-o,d),i(n.u0+f,r.vr,r.rh)),w=vh(`${t.id}:d`,t.id,"d",i(l,-o,d),i(l,n.w+s,u),i(n.u1-f,r.vr,r.rh));y.push(...[v,w].filter(k=>k!==null))}return y}function ov(t,e,n,r,i,o){let s=jr(e.w,t.eave_a,t.eave_b,st(t.pitch_a),st(t.pitch_b)),a=(f,g)=>{let[b,y]=e.at(f,g);return[b,s.y(g),y]},l=r-n,c=()=>[0,l],d=(f,g)=>Math.atan2(f,g)/Fe,u=[],[p,h]=[e.w+o,e.w-s.vlb];return s.vla+i>.3&&u.push($t(`${t.id}:a`,t.id,"a",a(n,-i),a(r,-i),a(n,s.vla),t.pitch_a,c)),s.vr-s.vla>.3&&u.push($t(`${t.id}:au`,t.id,"a",a(n,s.vla),a(r,s.vla),a(n,s.vr),d(s.rh-s.yla,s.vr-s.vla),c)),s.vlb+o>.3&&u.push($t(`${t.id}:b`,t.id,"b",a(r,p),a(n,p),a(r,h),t.pitch_b,c)),h-s.vr>.3&&u.push($t(`${t.id}:bu`,t.id,"b",a(r,h),a(n,h),a(r,s.vr),d(s.rh-s.ylb,h-s.vr),c)),u}function Na(t){return t.floors.filter(n=>n.rooms.some(r=>r.points.length>=3)).sort((n,r)=>r.elevation-n.elevation)[0]??null}function Y(t){let e=t.settings.roof;if(!e||e.type==="none")return[];if(e.type==="custom")return(e.sections??[]).flatMap(w=>iv(w,Ur(t,w,w.overhang??e.overhang)));let n=Na(t);if(!n)return[];let r=n.rooms.flatMap(w=>w.points.map(k=>k[0])),i=n.rooms.flatMap(w=>w.points.map(k=>k[1])),o=t.settings.wall_exterior+e.overhang,[s,a]=[Math.min(...r)-o,Math.max(...r)+o],[l,c]=[Math.min(...i)-o,Math.max(...i)+o],d=n.elevation+n.height;if(e.type==="flat")return[xh("main",null,s,l,a,c,d+wh)];let u=a-s>=c-l,p=e.ridge==="short"?!u:u,h=(p?c-l:a-s)/2,f=h*Math.tan(e.pitch*Fe),g=(w,k,x)=>p?[w,d+x,(l+c)/2+k]:[(s+a)/2+k,d+x,w],[b,y]=p?[s,a]:[l,c],v=()=>[0,y-b];return[$t("main:a",null,"a",g(b,-h,0),g(y,-h,0),g(b,0,f),e.pitch,v),$t("main:b",null,"b",g(b,h,0),g(y,h,0),g(b,0,f),e.pitch,v)]}function qe(t,e){let n=[];for(let r of t.floors.filter(i=>!e||i.id===e)){let{walls:i}=me(r.rooms,{exterior:t.settings.wall_exterior,interior:t.settings.wall_interior},r.walls??[]);for(let o of i){if(!o.exterior&&!o.free)continue;let[s,a]=[o.b[0]-o.a[0],o.b[1]-o.a[1]],l=Math.hypot(s,a);if(l<1.2)continue;let[c,d]=[a/l,-s/l],u=Math.min(r.height,o.height??r.height,o.heightEnd??1/0),p=(h,f,g,b)=>n.push({key:h,section:null,side:"top",flat:!1,o:f,eu:g,es:[0,1,0],n:b,lu:l,ls:u,pitch:90,span:()=>[0,l],facing:[b[0],b[2]],wall:{floorId:r.id}});p(`wall:${r.id}:${o.id}`,[o.a[0]+c*o.right,r.elevation,o.a[1]+d*o.right],[s/l,0,a/l],[c,0,d]),o.free&&p(`wall:${r.id}:${o.id}:back`,[o.b[0]-c*o.left,r.elevation,o.b[1]-d*o.left],[-s/l,0,-a/l],[-c,0,-d])}}return n}var Be="ground";function Eo(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 Ro(t,e){let n=(e.rotation??0)*Fe,r=[Math.cos(n),0,Math.sin(n)],i=[-Math.sin(n),0,Math.cos(n)],o=Eo(t),s=r[0]*e.u+i[0]*e.v,a=r[2]*e.u+i[2]*e.v,l=o?o.elevation+(e.base!=null?e.base:Od(o,s,a)):e.base??0;return{key:Be,section:null,side:"top",flat:!0,o:[0,l,0],eu:r,es:i,n:[0,1,0],lu:1e4,ls:1e4,pitch:0,span:()=>[-1e4,1e4],facing:[i[0],i[2]],unbounded:!0}}function Se(t,e,n=Y(t)){return e.face===Be?Ro(t,e):e.face.startsWith("wall:")?qe(t,e.face.split(":")[1]).find(r=>r.key===e.face)??null:n.find(r=>r.key===e.face)??null}var Ao=1.13,Xr=1.72,Ye=.025,at=.07;function gn(t){let e=t.module_w||Ao,n=t.module_h||Xr;return t.portrait===!1?[n,e]:[e,n]}function Jr(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 Ba(t,e){return t.flat?Math.min(45,Math.max(0,e.tilt??15))*Fe:t.wall?Math.min(90,Math.max(0,e.tilt??0))*Fe:Math.min(45,Math.max(0,e.tilt??0))*Fe}function Qr(t,e){let[,n]=gn(e),r=Ba(t,e);return t.wall?n*Math.cos(r)+Ye:!t.flat&&r<.001?n+Ye:t.flat&&e.rack==="ew"?n*Math.cos(r)+.08:n*Math.cos(r)+Math.max(.3,2*n*Math.sin(r))}function Un(t,e){let[n,r]=gn(e),i=Jr(e),o=Math.max(1,...i);return[o*n+(o-1)*Ye,(i.length-1)*Qr(t,e)+r*Math.cos(Ba(t,e))]}var sv=t=>t.flat&&!t.unbounded&&!t.wall;function Sh(t,e){if(!sv(t)||!e.rotation)return null;let n=e.rotation*Fe,[r,i]=Un(t,e);return{cos:Math.cos(n),sin:Math.sin(n),u:e.u+r/2,s:e.v+i/2}}function Xe(t,e,n=!1){let[r,i]=gn(e),o=Ba(t,e),s=i*Math.cos(o),a=Qr(t,e),l=Jr(e),c=Math.max(1,...l),d=new Set(e.skip??[]),u=Sh(t,e),p=(b,y)=>u?[u.u+(b-u.u)*u.cos-(y-u.s)*u.sin,u.s+(b-u.u)*u.sin+(y-u.s)*u.cos]:[b,y],h=(b,y,v)=>{let[w,k]=p(b,y);return[0,1,2].map(x=>t.o[x]+t.eu[x]*w+t.es[x]*k+t.n[x]*v)},f=(b,y)=>{let[v,w]=p(b,y);if(t.unbounded)return!0;if(w<-1e-6||w>t.ls+1e-6)return!1;let[k,x]=t.span(w);return v>=k-1e-6&&v<=x+1e-6},g=[];return l.forEach((b,y)=>{let v=e.align==="right"?c-b:e.align==="center"?(c-b)/2:0;for(let w=0;w<b;w++){let k=`${y}:${w}`,x=d.has(k);if(x&&!n)continue;let M=e.u+(w+v)*(r+Ye),A=M+r,T=e.v+y*a,F=T+(t.flat||t.wall||o>.001?s:i);if([[M,T],[A,T],[A,F],[M,F]].every(([L,I])=>f(L,I)))if(t.wall&&o>.001){let L=at+i*Math.sin(o),[I,N]=e.flip?[L,at]:[at,L],V=[h(M,T,I),h(A,T,I),h(A,F,N),h(M,F,N)],X=e.flip?T:F;g.push({corners:V,posts:[M+.05,A-.05].map(ke=>[h(ke,X,0),h(ke,X,L)]),cell:k,skipped:x})}else if(!t.flat&&o>.001){let L=at+i*Math.sin(o),I=[h(M,T,at),h(A,T,at),h(A,F,L),h(M,F,L)];g.push({corners:I,posts:[M+.05,A-.05].map(N=>[h(N,F,0),h(N,F,L)]),cell:k,skipped:x})}else if(!t.flat)g.push({corners:[h(M,T,at),h(A,T,at),h(A,F,at),h(M,F,at)],posts:[],cell:k,skipped:x});else{let I=.15+i*Math.sin(o),N=e.rack==="ew"&&y%2===1?!e.flip:!!e.flip,[V,X]=N?[F,T]:[T,F],ke=[h(M,V,.15),h(A,V,.15),h(A,X,I),h(M,X,I)],Ft=[M+.05,A-.05].flatMap(j=>[[h(j,V,0),h(j,V,.15)],[h(j,X,0),h(j,X,I)]]);g.push({corners:ke,posts:Ft,cell:k,skipped:x})}}}),g}function mt(t,e){if(t.unbounded)return{u:e.u,v:e.v};let[n,r]=Un(t,e),i=Sh(t,e);if(i){let[s,a]=[(n*Math.abs(i.cos)+r*Math.abs(i.sin))/2,(n*Math.abs(i.sin)+r*Math.abs(i.cos))/2],l=(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((l(c,s,t.lu)-n/2)*100)/100,v:Math.round((l(d,a,t.ls)-r/2)*100)/100}}let o=s=>Math.floor(s*100+1e-6)/100;return{u:o(Math.min(Math.max(0,e.u),Math.max(0,t.lu-n))),v:o(Math.min(Math.max(0,e.v),Math.max(0,t.ls-r)))}}function ei(t,e){let[n,r]=Un(t,e),[i,o]=[e.u+n/2,e.v+r/2];return[t.o[0]+t.eu[0]*i+t.es[0]*o,t.o[2]+t.eu[2]*i+t.es[2]*o]}var Fo=.78,ti=1.18,_n=t=>({id:t.id,face:t.face,u:t.u,v:t.v,rows:1,cols:1,portrait:!0,module_w:t.w||Fo,module_h:t.h||ti});function Va(t,e){let n=Xe(t,_n(e))[0];if(!n)return null;let r=i=>[i[0]-t.n[0]*.05,i[1]-t.n[1]*.05,i[2]-t.n[2]*.05];return n.corners.map(r)}var Yr={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 bn(t){let e=t.shape??"brick",n=Yr[e]??Yr.brick;return{shape:e,w:t.w||n.w,d:t.d||n.d,h:t.h||n.h}}function St(t,e){let{w:n,d:r}=bn(t),i=e&&!e.flat?Math.cos(e.pitch*Fe):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,i),tilt:0}}function Wa(t,e){let n=St(e,t),[r,i]=[n.module_w,n.module_h],o=(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,a]=[o(e.u+r/2,e.v),o(e.u+r/2,e.v+i)],l=o(e.u+r/2,e.v+i/2),c=d=>{let u=Math.hypot(d[0],d[2])||1;return[d[0]/u,d[2]/u]};return{center:[l[0],l[2]],along:c(t.eu),across:c(t.es),low:Math.min(s[1],a[1]),high:Math.max(s[1],a[1])}}function Ka(t,e){let[n]=gn(e);return Ze((t.lu-(e.cols*n+(e.cols-1)*Ye))/2)}var ni=.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]=gn(n),[i,o]=t.span(t.ls/2);for(n.cols=Math.max(1,Math.floor((o-i-2*ni+Ye)/(r+Ye))),n.rows=Math.max(1,Math.min(4,Math.floor((t.ls-2*ni)/Qr(t,n))));n.cols>1&&Xe(t,{...n,u:Ka(t,n),v:ni}).length<n.rows*n.cols;)n.cols--;return n.u=Ka(t,n),n.v=ni,n}function To(t,e){let n={...e,face:t.key,tilt:t.flat?e.tilt??15:null,rotation:null,flip:!1};return n.u=Ka(t,n),n.v=ni,{...n,...mt(t,n)}}function ja(t,e,n){let r=t.settings.north??0,i=a=>a.lu*(1.3+Math.cos((qr(a.facing,r)-180)*Math.PI/180)),o=qe(t,n).sort((a,l)=>i(l)-i(a))[0];if(!o)return null;let s={...Zn(o,e),portrait:!1,rows:1};return s.cols=Math.max(1,Math.floor((o.lu-.8+Ye)/(Xr+Ye))),s.u=Ze((o.lu-(s.cols*Xr+(s.cols-1)*Ye))/2),s.v=Ze(Math.max(0,o.ls-Ao-.3)),s}function ri(t,e){let n=t.floors.flatMap(o=>o.rooms.flatMap(s=>s.points)),r=n.length?Math.max(...n.map(o=>o[0]))+3:0,i=n.length?Math.min(...n.map(o=>o[1])):0;return{id:e,face:Be,u:Ze(r),v:Ze(i),rows:2,cols:4,portrait:!0,tilt:25,flip:!0,rotation:(t.settings.north??0)||0,look:"black",entity:null}}function ii(t,e,n){let r=Ro(t,e),[i,o]=Un(r,e),[s,a]=[e.u+i/2,e.v+o/2],l=[r.eu[0]*s+r.es[0]*a,r.eu[2]*s+r.es[2]*a],c=n*Fe,d=l[0]*Math.cos(c)+l[1]*Math.sin(c)-i/2,u=l[0]*-Math.sin(c)+l[1]*Math.cos(c)-o/2;return{u:Ze(d),v:Ze(u),rotation:(Math.round(n)%360+360)%360}}function oi(t,e){let[n,r]=t.span(t.ls/2);return{id:e,face:t.key,u:Ze((n+r-Fo)/2),v:Ze(Math.max(0,Math.min(t.ls-ti,t.ls*.45-ti/2))),w:null,h:null,cover:null,contact:null,tilt:null}}function si(t,e){let n=Yr.brick,[r,i]=t.span(t.ls*.8),o=St({id:e,face:t.key,u:0,v:0},t).module_h;return{id:e,face:t.key,u:Ze((r+i-n.w)/2),v:Ze(Math.max(0,Math.min(t.ls-o,t.ls*.8-o/2))),shape:"brick",w:null,d:null,h:null}}function qn(t,e){let[n,r]=[e[0]-t.o[0],e[1]-t.o[2]],[i,o,s,a]=[t.eu[0],t.eu[2],t.es[0],t.es[2]],l=i*a-o*s;if(Math.abs(l)<1e-9)return null;let c=(n*a-r*s)/l,d=(i*r-o*n)/l;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 Ga(t,e){let n=null;for(let r of t){if(r.wall){let[s,a]=[e[0]-r.o[0],e[1]-r.o[2]],l=s*r.eu[0]+a*r.eu[2],c=s*r.n[0]+a*r.n[2],d=l>=0&&l<=r.lu;if(d&&c>=-.05&&c<=.35)return{face:r,u:l,s:Number.NaN};d&&c>.35&&c<=.8&&!n&&(n={face:r,u:l,s:Number.NaN,y:-1/0});continue}let i=qn(r,e);if(!i)continue;let o=r.o[1]+r.es[1]*i.s;(!n||o>n.y)&&(n={face:r,...i,y:o})}return n&&{face:n.face,u:n.u,s:n.s}}function zo(t,e,n){let r=fn(n,t.n);if(Math.abs(r)<1e-6)return null;let i=fn(Ue(t.o,e),t.n)/r;if(i<=0)return null;let o=Ue([e[0]+n[0]*i,e[1]+n[1]*i,e[2]+n[2]*i],t.o);return{t:i,u:fn(o,t.eu),s:fn(o,t.es)}}function Ua(t,e,n){if(t.unbounded)return!0;if(n<0||n>t.ls)return!1;let[r,i]=t.span(n);return e>=r&&e<=i}function Za(t,e,n,r){return Xe(t,e).some(o=>{let s=o.corners.map(c=>{let d=Ue(c,t.o);return[fn(d,t.eu),fn(d,t.es)]}),a=s.map(c=>c[0]),l=s.map(c=>c[1]);return n>=Math.min(...a)-.05&&n<=Math.max(...a)+.05&&r>=Math.min(...l)-.05&&r<=Math.max(...l)+.05})}var av=["n","ne","e","se","s","sw","w","nw"],qa=(t,e)=>av[Math.round(qr(t.facing,e)/45)%8];function ai(t,e){let n=r=>{if(r.flat)return r.lu*r.ls*.8;let i=Math.cos((qr(r.facing,e)-180)*Math.PI/180);return r.lu*r.ls*(1.2+i)};return[...t].sort((r,i)=>n(i)-n(r))[0]??null}var Ah=["kitchen_row","kitchen_l","bath","bedroom","living","dining","office","kids","hall"],Mh={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]]}},Eh=t=>typeof t=="string"?t:t[0],Po=t=>typeof t=="string"?nt[t]:t[1],Yn=.05,lv=.02,Rh=t=>Math.round(t*1e3)/1e3;function cv(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 Fh(t,e,n){let r=ue(t.points),i=r.x1-r.x0,o=r.z1-r.z0,s=[],a=(l,c,d,u,[p,h,f])=>{s.push({id:n(),type:l,x:Rh(c),z:Rh(d),rotation:u,w:p,d:h,h:f,variant:null,entity:null,power:null})};for(let[l,c,d]of Mh[e].rows){let u=l==="back"||l==="front"?i:o,p=0,h=[];for(let g of d){if(p+Po(g)[0]>u-.1)break;h.push(g),p+=Po(g)[0]}let f=c==="start"?Yn:c==="end"?u-p-Yn:(u-p)/2;for(let g of h){let b=Po(g),y=cv(r,l,f+b[0]/2,b[1]/2+lv);a(Eh(g),y.x,y.z,y.turn,b),f+=b[0]}}for(let[l,c,d,u]of Mh[e].spots){let p=Po(l),h=(b,y,v)=>Math.min(v,Math.max(y,b)),f=h(r.x0+i*c,r.x0+p[0]/2+Yn,r.x1-p[0]/2-Yn),g=h(r.z0+o*d,r.z0+p[1]/2+Yn,r.z1-p[1]/2-Yn);a(Eh(l),f,g,u,p)}return s}var dv=30*Math.PI/180,Th=.05;function Ya(t){let e=t.points.length;return t.points.map((n,r)=>{let i=t.points[(r+1)%e];return Math.hypot(i[0]-n[0],i[1]-n[1])})}function li(t){return Ya(t).reduce((e,n)=>e+n,0)}function uv(t,e){let n=Ya(t),r=0;for(let i=0;i<e&&i<n.length;i++)r+=n[i];return r}function hv(t,e){let n=t.points.length,[r,i,o]=[t.points[e],t.points[(e+1)%n],t.points[(e+2)%n]],s=[i[0]-r[0],i[1]-r[1]],a=[o[0]-i[0],o[1]-i[1]],[l,c]=[Math.hypot(s[0],s[1]),Math.hypot(a[0],a[1])];return l<1e-9||c<1e-9?0:Math.acos(Math.max(-1,Math.min(1,(s[0]*a[0]+s[1]*a[1])/(l*c))))}function Xa(t,e,n){let r=Ya(t),i=r.length,o=r.reduce((h,f)=>h+f,0);if(i<3||!(o>0)||!(n>0))return null;let s=Math.min(n,o),a=(e%o+o)%o,l=0,c=0;for(;l<i-1&&a>=c+r[l];)c+=r[l],l++;let d=a-c,u=s,p=[];for(let h=0;h<=i&&u>1e-9;h++){let f=r[l]-d,g=Math.min(u,f);g>1e-9&&p.push({edge:l,t0:d,t1:d+g}),u-=g,d=0;let b=(l+1)%i;if(u>1e-9&&hv(t,l)>dv)break;l=b}for(;p.length>1&&p[0].t1-p[0].t0<Th;)p.shift();for(;p.length>1&&p[p.length-1].t1-p[p.length-1].t0<Th;)p.pop();return p.length?p.map(h=>({edge:h.edge,offset:(h.t0+h.t1)/2,width:h.t1-h.t0})):null}function Xn(t,e){let n=e[0];return n?{from:uv(t,n.edge)+n.offset-n.width/2,width:e.reduce((r,i)=>r+i.width,0)}:null}function Gt(t,e){return e.front?t.filter(n=>n.front===e.front):[e]}function Ja(t,e){let n=t.points.length,r=1/0,i=0,o=0;for(let s=0;s<n;s++){let a=t.points[s],l=t.points[(s+1)%n],c=l[0]-a[0],d=l[1]-a[1],u=Math.hypot(c,d);if(u<1e-6)continue;let p=Math.max(0,Math.min(u,((e[0]-a[0])*c+(e[1]-a[1])*d)/u)),h=Math.hypot(e[0]-(a[0]+c*p/u),e[1]-(a[1]+d*p/u));h<r&&(r=h,i=o+p),o+=u}return i}function ci(t,e,n,r,i,o=()=>P("opening")){let s=Xa(e,r,i);if(!s)return null;let a=Gt(t,n),l=new Set(a.map(h=>h.id)),c=s.length>1?a[0].front??`front-${a[0].id}`:null,d=s.map((h,f)=>({...n,id:f===0?a[0].id:o(),edge:h.edge,offset:h.offset,width:h.width,front:c})),u=[],p=!1;for(let h of t){if(!l.has(h.id)){u.push(h);continue}p||(u.push(...d),p=!0)}return u}var tl=globalThis,Qa=tl.__nextfloorBuiltin?.de??{},el=tl.__nextfloorBuiltin?.en??{};tl.__nextfloorBuiltin??={de:Qa,en:el};var pv=()=>typeof $=="object"&&$||{},fv=globalThis,mv=fv.__nextfloorTexts??=new Map;function gv(t){let e=t.toLowerCase().split("-")[0];return e!=="de"&&e!=="en"&&e in pv()?e:void 0}function zh(t){let e=gv(t),n=e===void 0?void 0:mv.get(e);return n instanceof Promise?void 0:n}function Io(t,e){return zh(t)?.[e]}function xe(t,e,n={}){let r=t?.language??navigator.language,i=r.startsWith("de"),o=(i?void 0:zh(r)?.[e])??(i?Qa:el)[e]??el[e]??Qa[e]??e;for(let[s,a]of Object.entries(n))o=o.replace(`{${s}}`,String(a));return o}function K(t,e,n=2){return e.toLocaleString(t?.language??void 0,{maximumFractionDigits:n})}var _v=new Set(["on","home","open","true","active","playing","heat","heating"]);function Ph(t,e){let n=e.show_when;if(!n?.entity||!t)return!0;let r=t.states[n.entity];if(!r||He(r))return!0;let i=String(r.state).toLowerCase(),o=(n.state??"").split(",").map(a=>a.trim().toLowerCase()).filter(Boolean),s=o.length?o.includes(i):_v.has(i)||Number.isFinite(Number(i))&&Number(i)>0;return n.invert?!s:s}function Te(t,e){if(!wt(e))return xe(t,`furn_${e}`);let n=U(e);return n?Je(n,e,t?.language??navigator.language):xe(t,"pack_missing_item")}function Je(t,e,n){return t.name[n.split("-")[0]]??Io(n,e)??pd(t,n)}function Ve(t,e){return Io(e,`packname:${t.id}`)??fd(t,e)}function Ih(t,e){return t.name[e.split("-")[0]]??Io(e,`color:${t.id}`)??t.name.en??Object.values(t.name)[0]}var di=t=>t&&t!=="none"?t:null,ui=(t,e)=>{e&&!t.includes(e)&&t.push(e)},nl=t=>new Map(t.floors.flatMap(e=>e.furniture.filter(n=>n.type==="meter").map(n=>[n.id,n])));function yn(t,e){if(!t.energy.advanced||e.type!=="meter"||!e.parent_meter)return null;let n=nl(t),r=new Set([e.id]);for(let i=n.get(e.parent_meter);i;i=n.get(i.parent_meter??"")){if(r.has(i.id))return null;r.add(i.id)}return n.has(e.parent_meter)?e.parent_meter:null}function Jn(t){return new Set([...nl(t).values()].filter(e=>yn(t,e)).map(e=>e.id))}function hi(t,e){return!t.energy.advanced||!e.parent_meter?null:Jn(t).has(e.parent_meter)?e.parent_meter:null}function Dh(t,e,n){if(n.type!=="meter"||n.id===e.id)return!1;let r=nl(t),i=new Set;for(let o=n;o&&!i.has(o.id);o=r.get(o.parent_meter??"")){if(o.id===e.id)return!1;i.add(o.id)}return!0}function Oo(t,e=n=>di(n.power)){let n={grid:null,gridExport:null,solar:[],battery:[],charge:[],batteries:[],soc:[]};for(let r of t.floors.flatMap(i=>i.furniture)){let i=e(r),o=r.type==="meter"?yn(t,r):null;if(o)(n.subMeters??=[]).push({id:r.id,parent:o,power:i,invert:!!r.meter_invert,floors:r.meter_floors??[],solar:[],batteries:[]});else if(r.type==="meter")n.grid??=i,n.gridExport??=di(r.export);else if(r.type==="inverter")ui(n.solar,i);else if(r.type==="home_battery"){let s=di(r.charge);ui(n.battery,i),ui(n.charge,s),ui(n.soc,di(r.soc)),(i||s)&&n.batteries.push({power:i,charge:s})}}for(let r of n.subMeters?t.floors.flatMap(i=>i.furniture):[]){let i=r.type==="inverter"||r.type==="home_battery"?n.subMeters?.find(a=>a.id===hi(t,r)):void 0,o=i?e(r):null;i&&r.type==="inverter"&&ui(i.solar,o);let s=di(r.charge);i&&r.type==="home_battery"&&(o||s)&&i.batteries.push({power:o,charge:s})}return n}function bv(t){for(let e of t.floors){let n=e.furniture.find(r=>r.type==="meter"&&!yn(t,r));if(n)return{floor_id:e.id,x:n.x,z:n.z}}return t.energy.meter}var yv=/(phase|_l[123]\b|_[abc]$|today|daily|heute)/,vv=/_?(energy|energie|total|today|daily|kwh|import|export|consumption|production)/g;function Do(t,e,n="power"){let r=e?t.entities?.[e]?.device_id:void 0;if(!e||!r)return null;let i=Object.keys(t.states).filter(a=>a.startsWith("sensor.")&&t.entities?.[a]?.device_id===r&&t.states[a]?.attributes.device_class===n);if(i.length<=1)return i[0]??null;let o=i.filter(a=>!yv.test(a)),s=e.replace(/^sensor\./,"").replace(vv,"");return o.find(a=>s&&a.includes(s))??o[0]??i[0]}function Oh(t,e){let n={},r=(i,o)=>{o&&!n[i]&&(n[i]=o)};for(let i of e.energy_sources??[])if(i.type==="grid")r("grid",Do(t,i.flow_from?.[0]?.stat_energy_from??i.flow_to?.[0]?.stat_energy_to));else if(i.type==="solar")r("solar",Do(t,i.stat_energy_from));else if(i.type==="battery"){let o=i.stat_energy_from??i.stat_energy_to;r("battery",Do(t,o)),r("battery_soc",Do(t,o,"battery"))}return n}function ze(t,e=!1){let n=t?.attributes.symcon_id?Ct(t):t?Number(t.state):null;if(n===null||!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 wv=(t,e)=>e.startsWith("sensor.")&&t.states[e]?.attributes.device_class==="power";function pi(t,e){if(wv(t,e))return e;let n=t.entities?.[e]?.device_id;if(!n)return null;let r=ua(t,n),i=r?Ot(t,e):null,o=go(t,n).filter(s=>s!==e);return(r?o.find(s=>i!==null&&Ot(t,s)===i):o[0])??null}var Hh=t=>{let e=t.filter(n=>n!==null);return e.length?e.reduce((n,r)=>n+r,0):null};function xv(t,e,n){let r=e.grid??n.grid,i=r?ze(t.states[r],e.grid_invert):null;if(!e.grid&&n.gridExport){let o=Math.max(0,ze(t.states[n.gridExport])??0);return Math.max(0,i??0)-o}return i}function kv(t,e,n){return e.solar?ze(t.states[e.solar]):n.solar.length?Hh(n.solar.map(r=>ze(t.states[r]))):null}function rl(t,e,n){return e.charge?(e.power?Math.max(0,ze(t.states[e.power])??0):0)-Math.max(0,ze(t.states[e.charge])??0):e.power?ze(t.states[e.power],n):null}function $v(t,e,n){return e.battery?ze(t.states[e.battery],e.battery_invert):Hh(n.batteries.map(r=>rl(t,r,e.battery_invert)))}function il(t,e,n,r=Oo(e)){let i=e.energy,o=xv(t,i,r),s=kv(t,i,r),a=$v(t,i,r),l=(i.battery_soc?[i.battery_soc]:r.soc).map(f=>Number(t.states[f]?.state)).filter(Number.isFinite),c=l.length?l.reduce((f,g)=>f+g,0)/l.length:null,d=i.tariff?t.states[i.tariff]:void 0,u=Number(d?.state),p=i.consumption?ze(t.states[i.consumption]):null;p===null&&(o!==null||s!==null||a!==null)&&(p=(o??0)+Math.max(0,s??0)+(a??0)),p===null&&n.length>0&&(p=n.reduce((f,g)=>f+g.power,0));let h={grid:o,solar:s===null?null:Math.max(0,s),battery:a,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,...Sv(t,r,h.consumption,i.battery_invert,n)}:h}function Sv(t,e,n,r,i){let o=e.subMeters??[],s=new Map;for(let p of o)for(let h of p.floors)s.has(h)||s.set(h,p.id);let a=new Set([e.grid,e.gridExport,...e.solar,...e.battery,...e.charge,...o.flatMap(p=>[p.power,...p.solar,...p.batteries.flatMap(h=>[h.power,h.charge])])]),l=p=>i.filter(h=>s.get(h.floorId)===p&&!a.has(h.powerEntity)).reduce((h,f)=>h+f.power,0),c=new Map(o.map(p=>[p.id,p.power?ze(t.states[p.power],p.invert):null])),d=o.map(p=>{let h=c.get(p.id)??null,f=p.solar.reduce((v,w)=>v+Math.max(0,ze(t.states[w])??0),0),g=p.batteries.reduce((v,w)=>v+(rl(t,w,r)??0),0),b=o.filter(v=>v.parent===p.id).reduce((v,w)=>v+(c.get(w.id)??0),0),y=h===null?null:Math.max(0,h+f+g-b);return{id:p.id,parent:p.parent,power:h,solar:f,battery:g,use:y,unmetered:y===null?null:Math.max(0,y-l(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 Mv(t,e,n){let r=t.b[0]-t.a[0],i=t.b[1]-t.a[1],o=Math.hypot(r,i)||1,s=Math.min(1,Math.max(0,((e.x-t.a[0])*r+(e.z-t.a[1])*i)/(o*o))),a=t.a[0]+r*s,l=t.a[1]+i*s,c=i/o*(a-n.x)+-r/o*(l-n.z)<0?-1:1;return{x:a,z:l,nx:c*i/o,nz:-c*r/o,distance:Math.hypot(e.x-a,e.z-l)}}function Lh(t){let e=bv(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},i=me(n.rooms,r,n.walls??[]).walls.filter(c=>c.exterior),o=n.rooms.flatMap(c=>c.points);if(i.length===0||o.length===0)return null;let s={x:o.reduce((c,d)=>c+d[0],0)/o.length,z:o.reduce((c,d)=>c+d[1],0)/o.length},a=i.map(c=>Mv(c,e,s)).reduce((c,d)=>d.distance<c.distance?d:c),l=r.exterior/2+3;return{floorId:n.id,x:a.x+a.nx*l,z:a.z+a.nz*l}}var ol=(t,e="Station 1")=>({id:t,name:e,has_valve:!0}),Ho=t=>t.has_valve!==!1;function fi(t){let e=t.hydronic??{};return e.stations?.length?e.stations.slice(0,16):[{...ol("station-1"),flow:e.flow,return:e.return,hot_water:e.hot_water,cold_water:e.cold_water,pump:e.pump}]}function Ch(t,e){let n={...t,stations:e};for(let r of["flow","return","hot_water","cold_water","pump"])delete n[r];return n}var Ev=["heating_manifold","buffer_tank","freshwater_station"],Qn=t=>Ev.includes(t),sl=(t,e="Heizkreis")=>({id:t,name:e,kind:"heating",has_pump:!0,has_valve:!0});function al(t){return{card:!0,...t==="heating_manifold"?{circuits:[sl("c1","Heizkreis 1")]}:{},...t==="buffer_tank"?{sensors:Array.from({length:7},(e,n)=>({id:`s${n+1}`,name:`F\xFChler ${n+1}`,entity:null,level:1-n/6}))}:{}}}function er(t){return{...al(t.type),...t.hydronic}}var tr=t=>t.has_pump!==!1,Lo=t=>t.kind!=="pump"&&t.has_valve!==!1;var mi=t=>!!t&&t!=="none";var No=(t,e)=>String(t.states[e]?.attributes.symcon_source_entity||e);function Co(t,e){let n=t.states[No(t,e)]?.attributes;return n?.device_class==="power"||/^[km]?w$/i.test(String(n?.unit_of_measurement??"").trim())}function Nh(t,e){let n=new Map;if(!Z(t))return n;let r=Re(t,[e]),i=(o,s,a,l,c)=>{if(!mi(c))return;let d=e.rooms.find(p=>p.points.length>=3&&C([a,l],p.points));if(!d)return;let u=n.get(d.id)??[];u.push({id:o,name:s,source:No(t,c)}),n.set(d.id,u)};for(let o of e.furniture){if(!Ph(t,o))continue;let s=o.name||Te(t,o.type),a=(o.values??[]).find(d=>mi(d.entity)&&Co(t,d.entity)),l=r.get(o.id)?.entity,c=o.power==="none"?null:o.power||r.get(o.id)?.power||(l&&Co(t,l)?l:null);if(i(`furniture:${o.id}`,s,o.x,o.z,c||a?.entity),!c&&!a){let d=new Set;for(let u of o.gang_entities??[]){if(!mi(u))continue;let p=pi(t,u);!p||d.has(No(t,p))||(d.add(No(t,p)),i(`furniture:${o.id}:${u}`,`${s} \xB7 ${B(t,u)}`,o.x,o.z,p))}}if(Qn(o.type))for(let d of er(o).circuits??[])tr(d)&&i(`furniture:${o.id}:${d.id}`,`${s} \xB7 ${d.name||"Pumpe"}`,o.x,o.z,d.power);if(o.type==="freshwater_station")for(let d of fi(o))i(`furniture:${o.id}:station:${d.id}`,`${s} \xB7 ${d.name}`,o.x,o.z,d.power)}for(let o of e.placements){if(o.outside)continue;let s=(o.values??[]).find(l=>mi(l.entity)&&Co(t,l.entity)),a=Co(t,o.entity_id)?o.entity_id:pi(t,o.entity_id);i(`device:${o.entity_id}`,o.name||B(t,o.entity_id),o.x,o.z,a||s?.entity)}return n}var Mt={electricity:"Strom",water:"Wasser",gas:"Gas",heating:"Heizen",cooling:"K\xFChlen"},nr={electricity:"\u26A1",water:"\u{1F4A7}",gas:"\u{1F525}",heating:"\u2668",cooling:"\u2744"},Vo=t=>t.normalize("NFD").replace(/[\u0300-\u036f]/g,"").toLowerCase().replace(/ß/g,"ss").replace(/[^a-z0-9]+/g," ").trim(),Rv="{485D0419-BE97-4548-AA9C-C083EB82E61E}",Av=t=>t.object_type!==0&&!(t.object_type===1&&t.module_id?.toUpperCase()===Rv)?null:{elektro:"electricity",strom:"electricity","elektro strom":"electricity","strom elektro":"electricity",wasser:"water",gas:"gas",heizen:"heating",heizung:"heating",warme:"heating",waerme:"heating",kuhlen:"cooling",kuehlen:"cooling",kuhlung:"cooling",kuehlung:"cooling",kalte:"cooling",kaelte:"cooling"}[Vo(t.name)]??null,Bo=t=>/^symcon-category-(\d+)$/.exec(t??"")?.[1],cl=t=>/\b(heute|tag|tagesverbrauch|today|daily)\b/.test(t)?"day":/monat|month/.test(t)?"month":/jahr|year/.test(t)?"year":"total",Wo=(t,e)=>String(t.states[e]?.attributes.symcon_source_entity||e);function Wh(t){let e=String(t?.attributes.unit_of_measurement??"").trim(),n=e.replace(/[³]/g,"3").replace(/[²]/g,"2").replace(/\s+/g,"").toLowerCase();return["w","kw","mw"].includes(n)?{metric:"power",unit:"W",factor:e==="mW"?.001:n==="kw"?1e3:n==="mw"?1e6:1}:["wh","kwh","mwh","j","kj","mj","gj"].includes(n)?{metric:"energy",unit:"kWh",factor:{wh:.001,kwh:1,mwh:1e3,j:1/36e5,kj:1/3600,mj:1/3.6,gj:1e3/3.6}[n]}:["m3/h","m3h","m3/min","m3/s","l/h","l/min","l/s","liter/h","liter/min"].includes(n)?{metric:"power",unit:"m\xB3/h",factor:{"m3/h":1,m3h:1,"m3/min":60,"m3/s":3600,"l/h":.001,"l/min":.06,"l/s":3.6,"liter/h":.001,"liter/min":.06}[n]}:["m3","l","liter"].includes(n)?{metric:"energy",unit:"m\xB3",factor:n==="m3"?1:.001}:null}function Fv(t,e){if(!e.entity_id||e.object_type!==2&&e.object_type!==6)return null;let n=Wo(t,e.entity_id),r=t.states[n];if(!r||![1,2].includes(Number(r.attributes.symcon_variable_type)))return null;let i=Vo(e.name),o=Wh(r),s=/^(leistung|wirkleistung|gesamtleistung|aktuelle leistung|durchfluss|volumenstrom)(\b|$)/.test(i),a=/^(verbrauch|energie|energieverbrauch|gesamtverbrauch|gesamtenergie|zahlerstand|zaehlerstand|arbeit)(\b|$)/.test(i),l=o?.metric??(s?"power":a?"energy":null);if(!l)return null;let c=l==="power"?/^(leistung|wirkleistung|gesamtleistung|durchfluss|volumenstrom)$/.test(i):/^(verbrauch|energie|energieverbrauch|gesamtverbrauch|gesamtenergie|zahlerstand|zaehlerstand|arbeit)$/.test(i),d=l==="energy"?cl(i):"total";return{metric:l,source:n,period:d,group:`${l}|${o?.unit??String(r.attributes.unit_of_measurement??"")}|${d}`,score:/^gesamt(leistung|verbrauch|energie)$/.test(i)?110:c?100:(l==="power"?s:a)?70:20}}var Bh=new WeakMap,Vh=new WeakMap;function Kh(t){let e=Bh.get(t);if(e)return e;let n={nodes:new Map(t.map(r=>[r.object_id,r])),children:new Map};for(let r of t){let i=n.children.get(r.parent_id)??[];i.push(r),n.children.set(r.parent_id,i)}return Bh.set(t,n),n}function Tv(t,e,n){if(!Z(t))return[];let r=[e.area_id,...e.sub_areas??[]].map(Bo).filter(p=>!!p);if(!r.length)return[];let i=new Set(n.filter(p=>p.id!==e.id).flatMap(p=>[p.area_id,...p.sub_areas??[]]).map(Bo).filter(p=>!!p&&!r.includes(p))),o=`${r.join(",")}|${[...i].sort().join(",")}`,s=Vh.get(t)??new Map;Vh.set(t,s);let a=s.get(o);if(a)return a;let l=Kh(t.symconObjects),c=[],d=new Set,u=(p,h,f)=>{if(d.has(p)||i.has(String(p)))return;d.add(p);let g=l.nodes.get(p);if(!g)return;let b=Av(g),y=b??h,v=new Set(b&&b!==h?[]:f),w=l.children.get(p)??[];if(y){let k=w.map(x=>Fv(t,x)).filter(x=>x!==null);for(let x of new Set(k.map(M=>M.group))){if(v.has(x))continue;let M=k.filter(F=>F.group===x),A=Math.max(...M.map(F=>F.score)),T=M.filter(F=>F.score===A);for(let F of A>=100?T.slice(0,1):T)c.push({kind:y,metric:F.metric,id:F.source,period:F.period});v.add(x)}}for(let k of w)(k.object_type===0||k.object_type===1)&&u(k.object_id,y,v)};for(let p of r)u(Number(p),null,new Set);return s.set(o,c),c}function gi(t,e,n=!1){let r=new Map,i=new Set;for(let o of e){let s=Wo(t,o.id),a=`${o.kind}|${o.metric}|${s}`;if(i.has(a))continue;i.add(a);let l=t.states[s],c=Wh(l),d=c?.metric===o.metric?c.unit:String(l?.attributes.unit_of_measurement??"").trim(),u=`${o.kind}|${o.metric}|${d}|${o.period}`,p=r.get(u)??{kind:o.kind,metric:o.metric,unit:d,value:null,period:o.period,sources:[],manual:n,incomplete:!1},h=Ct(l);h===null?p.incomplete=!0:p.value=(p.value??0)+h*(c?.metric===o.metric?c.factor:1),p.sources.push(s),r.set(u,p)}return[...r.values()]}function ll(t,e){return xt.flatMap(n=>["power","energy"].flatMap(r=>{let i=e.utility_meters?.[n]?.[r];if(!i||i==="none")return[];let o=Wo(t,i);return[{kind:n,metric:r,id:o,period:r==="energy"?cl(Vo(String(t.states[o]?.attributes.friendly_name??""))):"total"}]}))}function zv(t,e){return Z(t)?gi(t,ll(t,e),!0):[]}function Pv(t,e,n=e.rooms,r=!1){if(!Z(t))return[];let i=r?Nh(t,e):new Map,o=new Map;for(let a of e.rooms){let l=[...new Set([a.area_id,...a.sub_areas??[]].filter(c=>!!Bo(c)))];!l.length&&(ll(t,a).length||i.get(a.id)?.length)&&l.push("unassigned");for(let c of l){let d=o.get(c)??{seed:a,members:[]};c===l[0]&&d.members.push(a),o.set(c,d)}}let s=Kh(t.symconObjects).nodes;return[...o].map(([a,l])=>{let c=s.get(Number(Bo(a))),d=a==="unassigned"?[]:gi(t,Tv(t,{...l.seed,area_id:a,sub_areas:null},n)),u=gi(t,l.members.flatMap(f=>ll(t,f)),!0),p=f=>d.some(g=>g.kind===f.kind&&g.metric===f.metric&&g.unit===f.unit&&g.period===f.period),h=l.members.map(f=>({id:f.id,name:f.name,readings:zv(t,f),devices:(i.get(f.id)??[]).map(g=>({id:g.id,name:g.name,readings:gi(t,[{kind:"electricity",metric:"power",id:g.source,period:"total"}],!0)}))})).filter(f=>f.readings.length||f.devices.length);return{id:a,name:a==="unassigned"?"Nicht zugeordnet":c?.name||t.areas?.[a]?.name||"Bereich nicht verf\xFCgbar",path:c?.path||"",readings:[...d,...u.filter(f=>!p(f))],rooms:h}}).filter(a=>a.readings.length||a.rooms.length)}function dl(t,e,n,r){let i=e.utility_meters?.[n],o=i&&Object.prototype.hasOwnProperty.call(i,r)?i[r]:n==="electricity"&&r==="power"?e.power_entity:null;return o&&o!=="none"?Wo(t,o):null}function jh(t,e,n=e.rooms){let r=Pv(t,e,n).flatMap(o=>o.readings.flatMap(s=>s.sources.map(a=>({kind:s.kind,metric:s.metric,period:s.period,id:a})))),i=[];for(let o of xt)for(let s of["power","energy"]){let a=dl(t,e,o,s);i.push(...gi(t,a?[{kind:o,metric:s,id:a,period:s==="energy"?cl(Vo(String(t.states[a]?.attributes.friendly_name??""))):"total"}]:r.filter(l=>l.kind===o&&l.metric===s),!!a))}return i}function ul(t){return t.metric==="power"?t.unit==="m\xB3/h"?"Durchfluss":"Leistung":{total:"Verbrauch",day:"Verbrauch heute",month:"Verbrauch Monat",year:"Verbrauch Jahr"}[t.period]}function Gh(t,e){let n=e.incomplete?"Err: ":"";if(e.value===null)return`${n}\u2013`;let r=e.unit==="W"&&Math.abs(e.value)>=1e3?e.value/1e3:e.value,i=e.unit==="W"&&Math.abs(e.value)>=1e3?"kW":e.unit,o=Number.isInteger(r)?0:Math.min(6,Math.max(2,1-Math.floor(Math.log10(Math.abs(r)))));return`${n}${K(t,r,o)}${i?` ${i}`:""}`}var Uh=[{key:"supply_vsr",label:"Zuluft-VSR",types:[0,1,2],control:!0},{key:"extract_vsr",label:"Abluft-VSR",types:[0,1,2],control:!0},{key:"supply_temperature",label:"Zulufttemperatur",types:[1,2]},{key:"extract_temperature",label:"Ablufttemperatur",types:[1,2]},{key:"reheat",label:"NHR (Nachheizregister)",types:[0,1,2],control:!0},{key:"status",label:"Raumstatus",types:[1]}];function Zh(t,e,n){let r=O(t.hass,i=>Le(t.hass,i,[1,2]));return m`<details class="nf-room-utility-meters"><summary>Eigene Raumzähler</summary><div class="nf-form">
${S("Nur direkt zugewiesene Raumz\xE4hler erscheinen als einger\xFCckte Raumzeile unter dem verkn\xFCpften Bereich. Die Bereichswerte stehen einmal beim Bereich; vorhandene Bereichssummen enthalten die Raumwerte bereits. Fehlt dem Bereich ein passender Z\xE4hler, werden daf\xFCr die eigenen Raumz\xE4hler summiert.","nf-wide")}
${xt.map(i=>m`<b class="nf-wide">${nr[i]} ${Mt[i]}</b>${["power","energy"].map(o=>z(t,o==="power"?"Leistung / Durchfluss":"Energie / Verbrauch",e.utility_meters?.[i]?.[o]??null,void 0,r,s=>{let a={...e.utility_meters,[i]:{...e.utility_meters?.[i],[o]:s==="none"?null:s}};Object.values(a[i]).some(l=>l&&l!=="none")||delete a[i],n({utility_meters:Object.keys(a).length?a:null})},{types:[1,2]}))}`)}
</div></details>`}function qh(t,e,n){let r=s=>n({hvac:{...e.hvac,...s}}),i=e.hvac?.schedules??[],o=O(t.hass,s=>!!t.hass?.states[s]?.attributes.symcon_schedule);return m`
${z(t,t.t("floor_heating"),e.floor_heating??null,void 0,O(t.hass,s=>Le(t.hass,s,[0,1,2])),s=>n({floor_heating:s==="none"?null:s}),{types:[0,1,2]})}
${Uh.map(s=>z(t,s.label,e.hvac?.[s.key]??null,void 0,O(t.hass,a=>Le(t.hass,a,s.types)),a=>r({[s.key]:a==="none"?null:a}),{types:s.types}))}
${S("Raumstatus zeigt den in Symcon hinterlegten Alias der Integer-Variable. Beschreibbare Heizungs- und L\xFCftungswerte k\xF6nnen im Raummen\xFC bedient werden.","nf-wide")}
${i.map((s,a)=>z(t,`Schaltuhr ${a+1}`,s,void 0,o.filter(l=>l.id===s||!i.includes(l.id)),l=>r({schedules:l&&l!=="none"?i.map((c,d)=>a===d?l:c):i.filter((c,d)=>a!==d)}),{schedule:!0,excluded:l=>i.includes(l)?"Diese Schaltuhr ist in diesem Raum bereits verkn\xFCpft.":void 0}))}
${z(t,"Schaltuhr hinzuf\xFCgen",null,void 0,o.filter(s=>!i.includes(s.id)),s=>s&&s!=="none"&&r({schedules:[...i,s]}),{schedule:!0,excluded:s=>i.includes(s)?"Diese Schaltuhr ist in diesem Raum bereits verkn\xFCpft.":void 0})}`}function Yh(t,e,n){let r=i=>i==="condition"?[0,1,2,3]:i==="wind_bearing"?[1,2,3]:["snow","fog","lightning"].includes(i)?[0,1,2]:[1,2];return m`<details class="nf-wide nf-symcon-weather"><summary>Wettervariablen</summary><div class="nf-form">
${Sd.map(i=>z(t,ju[i],e.weather_variables?.[i]??null,void 0,O(t.hass,o=>Le(t.hass,o,r(i))),o=>n({weather_variables:{...e.weather_variables,[i]:o==="none"?null:o}}),{types:r(i)}))}
${z(t,t.t("rain_sensor"),e.rain_sensor??null,void 0,O(t.hass,i=>Le(t.hass,i,[0,1,2])),i=>n({rain_sensor:i==="none"?null:i}),{types:[0,1,2]})}
${e.rain_sensor?D(t,t.t("rain_sensor_inverted"),!!e.rain_sensor_inverted,i=>n({rain_sensor_inverted:i||void 0})):_}
${S("W\xE4hle die Wetterwerte einzeln aus dem Symcon-Objektbaum. Einheiten werden aus den Variablen \xFCbernommen. Der Regensensor kann Boolean oder eine numerische Regenrate sein.","nf-wide")}
</div></details>`}function Xh(t){let e=t.doc.presence,n=s=>t.replace({...structuredClone(t.doc),presence:s}),r=(s,a)=>n(e.map((l,c)=>c===s?{...l,...a,sensor:null}:l)),i=t.doc.floors.flatMap(s=>s.rooms.map(a=>({id:a.id,name:`${s.name} \xB7 ${a.name}`}))),o=O(t.hass,s=>Le(t.hass,s,[0]));return m`<details class="nf-section nf-symcon-presence"><summary>${t.t("presence")}</summary>
${e.map((s,a)=>m`<div class="nf-form">
${W(t,"Person",s.name??B(t.hass,s.person),l=>r(a,{name:l}),{wide:!0,maxlength:100})}
${z(t,"Anwesenheit (Boolean)",s.person,void 0,o.filter(l=>l.id===s.person||!e.some(c=>c.person===l.id)),l=>l&&l!=="none"?r(a,{person:l}):n(e.filter((c,d)=>d!==a)),{types:[0],excluded:l=>e.some(c=>c.person===l)?"Diese Anwesenheitsvariable ist bereits mit einer Person verkn\xFCpft.":void 0})}
<label class="nf-field nf-wide">Raum für die 3D-Anzeige<select ?disabled=${!t.admin} .value=${s.room??""} @change=${l=>r(a,{room:l.target.value||null})}><option value="">Kein Raum</option>${i.map(l=>m`<option value=${l.id}>${l.name}</option>`)}</select></label>
<button class="nf-link nf-wide" ?disabled=${!t.admin} @click=${()=>n(e.filter((l,c)=>c!==a))}>× Person entfernen</button>
</div>`)}
<div class="nf-form">${z(t,"Person hinzuf\xFCgen (Boolean)",null,void 0,o.filter(s=>!e.some(a=>a.person===s.id)),s=>s&&s!=="none"&&n([...e,{person:s,sensor:null}]),{types:[0],excluded:s=>e.some(a=>a.person===s)?"Diese Anwesenheitsvariable ist bereits mit einer Person verkn\xFCpft.":void 0})}</div>
${S("Jede Person wird mit einer beliebigen Boolean-Variable verkn\xFCpft: true bedeutet anwesend, false abwesend. Ein Raum ist optional und bestimmt die Position der Person in 3D.")}
</details>`}function Jh(t,e,n){let r=t.find(l=>l.person===e),i="sensor"in n?n.sensor&&n.sensor!=="none"?n.sensor:null:r?.sensor??null,o="room"in n?n.room||null:r?.room??null,s=t.filter(l=>l.person!==e);if(!i&&!o)return s;let a=o?{person:e,sensor:i,room:o}:{person:e,sensor:i};return r?t.map(l=>l.person===e?a:l):[...s,a]}function Qh(t,e){let n=e.slice(e.indexOf(".")+1),r=i=>i.id.includes(n)&&/(area|room|raum|bermuda|espresense)/.test(i.id);return[...t.filter(r),...t.filter(i=>!r(i))]}function ep(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 tp(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 Ko(t,e,n){let r=[...t],[i]=r.splice(e,1);return r.splice(Math.max(0,Math.min(r.length,e+n)),0,i),r}var Ut=(t,e)=>t.filter((n,r)=>r!==e),_i=(t,e,n)=>t.map((r,i)=>i===e?{...r,...n}:r),gt=t=>t.length>0?t:void 0;var Iv=["scene","script","automation","button","input_button","switch","input_boolean","light","fan","cover","lock"],Dv=40,Ov=20,Hv=30,Lv=["music","url","playlist","SPOTIFY","AMAZON_MUSIC","TUNEIN","APPLE_MUSIC"],hl={navigate:"/lovelace/rollos",more_info:"cover.wohnzimmer",service:"script.turn_on",fire_dom_event:""},bi=(t,e,n,r=!1)=>m`<button class="nf-pin" title=${t} ?disabled=${r} @click=${n}>${e}</button>`;function Cv(t){let e=t.doc.settings.favorites??[],n=a=>t.change(l=>l.settings.favorites=gt(a)),r=t.doc.floors,i=t.doc.settings.favorite_floors??{},o=O(t.hass,a=>Iv.includes(a.split(".")[0])&&!e.includes(a)),s=(a,l)=>m`<div class="nf-row nf-dev-row">
<span class="nf-dev-name"><span>${B(t.hass,a)}</span></span>
${r.length>1?m`<select title=${t.t("favorite_floor")} .value=${i[a]??""} @change=${c=>{let d=c.target.value,u={...i};d?u[a]=d:delete u[a],t.change(p=>p.settings.favorite_floors=Object.keys(u).length?u:void 0)}}>
<option value="">${t.t("favorite_all_floors")}</option>
${r.map(c=>m`<option value=${c.id} ?selected=${i[a]===c.id}>${c.name}</option>`)}
</select>`:_}
${bi(t.t("move_up"),"\u2191",()=>n(Ko(e,l,-1)),l===0)}
${bi(t.t("move_down"),"\u2193",()=>n(Ko(e,l,1)),l===e.length-1)}
${bi(t.t("delete"),"\u2715",()=>n(Ut(e,l)))}
</div>`;return m`<summary>${t.t("favorites")}${e.length>0?m` <span class="nf-lib-count">${e.length}</span>`:_}</summary>
${S(t.t("favorites_hint"))} ${e.map(s)}
${e.length<Dv?m`<div class="nf-form">${z(t,t.t("favorites_add"),null,void 0,o,a=>a&&a!=="none"&&!e.includes(a)&&n([...e,a]),{excluded:a=>e.includes(a)?"Diese Variable ist bereits als Favorit verkn\xFCpft.":void 0})}</div>`:_}`}function Nv(t,e){let n=t.doc.settings.outside_hidden??[],r=s=>t.change(a=>a.settings.outside_hidden=gt(s)),i=new Set(t.hass?xu(t.hass,t.doc.floors):[]),o=O(t.hass,s=>!n.includes(s)&&i.has(s));return m`${e?Bv(t,e):_}
<h4>${t.t("outside_hidden")}${n.length>0?m` <span class="nf-lib-count">${n.length}</span>`:_}</h4>
${S(t.t("outside_hidden_hint"))}
${n.map((s,a)=>m`<div class="nf-row nf-dev-row"><span class="nf-dev-name"><span>${B(t.hass,s)}</span></span>${bi(t.t("delete"),"\u2715",()=>r(Ut(n,a)))}</div>`)}
<div class="nf-form">${z(t,t.t("outside_hidden_add"),null,void 0,o,s=>s&&s!=="none"&&!n.includes(s)&&r([...n,s]),{excluded:s=>n.includes(s)?"Diese Variable ist hier bereits eingetragen.":void 0})}</div>`}function Bv(t,e){let n=t.doc.settings.outside_view??null,r=()=>{let i=e();i&&t.change(o=>o.settings.outside_view=i)};return m`${S(t.t("outside_view_hint"))}
${Q(m`<button class="nf-btn" @click=${r}>${t.t("outside_view_set")}</button>`,n?m`<button class="nf-btn" @click=${()=>t.change(i=>i.settings.outside_view=null)}>${t.t("outside_view_reset")}</button>`:_)}`}function Vv(t){let e=t.doc.settings.own_alerts??[],n=s=>t.change(a=>a.settings.own_alerts=gt(s)),r=(s,a)=>n(_i(e,s,a)),i=[["",t.t("own_alert_house")],...t.doc.floors.flatMap(s=>s.rooms.map(a=>[a.id,`${a.name} \xB7 ${s.name}`]))],o=(s,a)=>m`<div class="nf-form nf-own-button">
${z(t,t.t("own_alert_entity"),s.entity||null,void 0,O(t.hass,()=>!0),l=>r(a,{entity:l&&l!=="none"?l:""}))}
${W(t,t.t("own_alert_state"),s.state??"",l=>r(a,{state:l||null}),{placeholder:t.hass?.states[s.entity]?.state??"on \xB7 <20 \xB7 >80"})}
${W(t,t.t("own_alert_text"),s.text,l=>r(a,{text:l||t.t("own_alert_new")}),{wide:!0,maxlength:120})}
${H(t,t.t("room"),s.room_id??"",i,l=>r(a,{room_id:l||null}),{wide:!0})}
${Ge(t,t.t("own_alert_color"),s.color??null,"#ffb547",l=>r(a,{color:l}))}
${H(t,t.t("own_alert_tap"),s.tap??"",[["",t.t("own_alert_tap_info")],["toggle",t.t("own_alert_tap_toggle")],["room",t.t("own_alert_tap_room")]],l=>r(a,{tap:l||null}))}
<div class="nf-actions nf-wide"><button class="nf-btn nf-danger" @click=${()=>n(Ut(e,a))}>${t.t("delete")}</button></div>
</div>`;return m`<h4>⚠ ${t.t("own_alerts")}</h4>
${S(t.t("own_alerts_hint"))} ${e.map(o)}
${e.length<40?Q(m`<button class="nf-btn" @click=${()=>n([...e,{id:P("alert"),entity:"",state:null,text:t.t("own_alert_new")}])}>+ ${t.t("own_alert_add")}</button>`):_}`}function Wv(t){let e=t.doc.settings.circuits??[],n=a=>t.change(l=>l.settings.circuits=gt(a)),r=(a,l)=>n(_i(e,a,l)),i=t.doc.floors.flatMap(a=>a.rooms.map(l=>({id:l.id,label:t.doc.floors.length>1?`${l.name} \xB7 ${a.name}`:l.name}))),o=a=>i.find(l=>l.id===a)?.label??a,s=(a,l)=>m`<div class="nf-form nf-own-button">
${W(t,t.t("circuit_name"),a.name,c=>r(l,{name:c||t.t("circuit_new")}),{wide:!0,maxlength:80})}
<div class="nf-wide">${a.rooms.map(c=>m`<span class="nf-chip">${o(c)} <button class="nf-btn nf-field-btn" title=${t.t("delete")} @click=${()=>r(l,{rooms:a.rooms.filter(d=>d!==c)})}>✕</button></span>`)}</div>
${H(t,t.t("circuit_add_room"),"",[["","\u2013"],...i.filter(c=>!a.rooms.includes(c.id)).map(c=>[c.id,c.label])],c=>c&&r(l,{rooms:[...a.rooms,c]}),{wide:!0})}
<div class="nf-actions nf-wide"><button class="nf-btn nf-danger" @click=${()=>n(Ut(e,l))}>${t.t("delete")}</button></div>
</div>`;return m`<h4>🔌 ${t.t("circuits")}</h4>
${S(t.t("circuits_hint"))} ${e.map(s)}
${e.length<120?Q(m`<button class="nf-btn" @click=${()=>n([...e,{id:P("circuit"),name:t.t("circuit_new"),rooms:[]}])}>+ ${t.t("circuit_add")}</button>`):_}`}function Kv(t){let e=t.doc.settings.calendars??[],n=a=>t.change(l=>l.settings.calendars=gt(a)),r=O(t.hass,a=>a.startsWith("calendar.")&&!e.includes(a)),i=(a,l)=>m`<div class="nf-row nf-dev-row">
<span class="nf-dev-name"><span>${B(t.hass,a)}</span></span>
${bi(t.t("delete"),"\u2715",()=>n(Ut(e,l)))}
</div>`,o=t.t,s=t.doc.settings.today_days??1;return m`<h4>📅 ${o("today_calendars")}</h4>
${S(o("today_calendars_hint"))} ${e.map(i)}
${e.length<12?m`<div class="nf-form">${z(t,o("favorites_add"),null,void 0,r,a=>a&&a!=="none"&&!e.includes(a)&&n([...e,a]),{unsupported:"Dieses Feld ben\xF6tigt eine Kalenderquelle mit Terminen. Eine Symcon-Variable ist kein Kalender; Kalenderquellen werden vom Symcon-Modul derzeit nicht bereitgestellt."})}</div>`:_}
${e.length?m`<div class="nf-form">
${H(t,o("today_days"),String(s),[1,2,3,5,7].map(a=>[String(a),o(a===1?"today_days_one":"today_days_n",{n:a})]),a=>t.change(l=>l.settings.today_days=Number(a)>1?Number(a):void 0))}
</div>`:_}
${jv(t)}`}function jv(t){let e=t.t,n=t.doc.settings.forecast??null,r=i=>t.change(o=>o.settings.forecast=i??void 0);return m`<h4>🌦 ${e("forecast")}</h4>
${S(e("forecast_hint"))}
<div class="nf-form">
${H(t,e("forecast_days"),n?String(n.days):"0",[0,3,5,7].map(i=>[String(i),i?e("today_days_n",{n:i}):e("forecast_off")]),i=>r(Number(i)>0?{days:Number(i),corner:n?.corner??"top_right"}:null))}
${n?H(t,e("forecast_corner"),n.corner,[["top_right",e("clock_top_right")],["top_left",e("clock_top_left")]],i=>r({...n,corner:i==="top_left"?"top_left":"top_right"})):_}
</div>`}function Gv(t){let e=t.doc.settings.media_presets??[],n=s=>t.change(a=>a.settings.media_presets=gt(s)),r=(s,a)=>n(_i(e,s,a)),i=[...new Set(t.doc.floors.flatMap(s=>[...s.placements.map(a=>a.entity_id),...s.furniture.map(a=>a.entity??"")]).filter(s=>s.startsWith("media_player.")))],o=(s,a)=>m`<div class="nf-form nf-own-button">
${W(t,t.t("own_button_label"),s.label,l=>r(a,{label:l||"Radio"}),{maxlength:60})}
${W(t,t.t("preset_type"),s.type,l=>r(a,{type:l||"music"}),{title:t.t("preset_type_hint")})}
${W(t,t.t("preset_content"),s.content,l=>r(a,{content:l}),{wide:!0,title:t.t("preset_content_hint"),placeholder:"https://\u2026 \xB7 spotify:playlist:\u2026 \xB7 Rock Antenne"})}
${i.length>1?m`<div class="nf-sub nf-wide">${t.t("preset_speakers")}</div>
${i.map(l=>D(t,B(t.hass,l),!!s.speakers?.includes(l),c=>r(a,{speakers:gt(c?[...s.speakers??[],l]:(s.speakers??[]).filter(d=>d!==l))}),{wide:!1}))}`:_}
<div class="nf-actions nf-wide"><button class="nf-btn nf-danger" @click=${()=>n(Ut(e,a))}>${t.t("delete")}</button></div>
</div>`;return m`<h4>${t.t("presets")}</h4>
${S(t.t("presets_hint"))}
<datalist id="nf-preset-types">${Lv.map(s=>m`<option value=${s}></option>`)}</datalist>
${e.map(o)}
${e.length<Hv?Q(m`<button class="nf-btn" @click=${()=>n([...e,{id:P("preset"),label:"Radio",type:"music",content:""}])}>+ ${t.t("preset_add")}</button>`):_}`}function pl(t,e,n){let r=e.action==="fire_dom_event"?'{"browser_mod": {"service": "browser_mod.popup", "data": {"title": "Rollos", "content": {"type": "custom:my-cover-card"}}}}':'{"entity_id": "script.party"}',i=o=>{let s=o.target;s.setCustomValidity("");let a=tp(s.value);if(a.ok)return n(a.value);s.setCustomValidity(t.t("own_data_bad")),s.reportValidity()};return m`<label class="nf-field nf-wide" title=${t.t("own_data_hint")}
>${t.t("own_data")}
<textarea rows="4" spellcheck="false" placeholder=${r} .value=${e.data?JSON.stringify(e.data,null,1):""} @change=${i}></textarea>
</label>`}function Uv(t){let e=t.doc.settings.buttons??[],n=s=>t.change(a=>a.settings.buttons=gt(s)),r=(s,a)=>n(_i(e,s,a)),i=Qi.map(s=>[s,t.t(`own_action_${s}`)]),o=(s,a)=>m`<div class="nf-form nf-own-button">
${W(t,t.t("own_button_label"),s.label,l=>r(a,{label:l||t.t("own_button_new")}),{maxlength:60})}
${H(t,t.t("own_button_action"),s.action,i,l=>r(a,{action:l}))} ${Bt(t,s.icon??null,l=>r(a,{icon:l}))}
${s.action!=="fire_dom_event"?W(t,t.t(`own_target_${s.action}`),s.target??"",l=>r(a,{target:l||null}),{wide:!0,placeholder:hl[s.action]}):_}
${s.action==="service"||s.action==="fire_dom_event"?pl(t,s,l=>r(a,{data:l})):_}
${z(t,t.t("own_button_state"),s.state_entity??null,void 0,O(t.hass,l=>/^(switch|light|input_boolean|binary_sensor|fan|cover|media_player|climate|lock|person|device_tracker)\./.test(l)),l=>r(a,{state_entity:l&&l!=="none"?l:null}))}
<div class="nf-actions nf-wide">
<button class="nf-btn" ?disabled=${a===0} @click=${()=>n(Ko(e,a,-1))}>↑</button>
<button class="nf-btn nf-danger" @click=${()=>n(Ut(e,a))}>${t.t("delete")}</button>
</div>
</div>`;return m`<h4>${t.t("own_buttons")}</h4>
${S(t.t("own_buttons_hint"))} ${e.map(o)}
${e.length<Ov?Q(m`<button class="nf-btn" @click=${()=>n([...e,{id:P("btn"),label:t.t("own_button_new"),action:"navigate",target:null}])}>+ ${t.t("own_button_add")}</button>`):_}`}function Zv(t){let e=t.doc.settings.room_facts_off??[],n=["sun","comfort","air","circuits"].map(r=>D(t,t.t(`room_fact_${r}`),!e.includes(r),i=>t.change(o=>o.settings.room_facts_off=gt(i?e.filter(s=>s!==r):[...e,r]))));return m`<h4>${t.t("room_facts")}</h4><div class="nf-form">${n}</div>`}function np(t){return m`<details class="nf-section">${Cv(t)} ${Uv(t)} ${Vv(t)} ${Wv(t)} ${Kv(t)} ${Gv(t)} ${Zv(t)}</details>`}function rp(t,e){return m`<details class="nf-section">
<summary>🌳 ${t.t("outside_area")}</summary>
${Nv(t,e)}
</details>`}function ip(t,e){let n=t.doc.settings.start_view??null,r=()=>{let i=e();i&&t.change(o=>o.settings.start_view=i)};return m`<details class="nf-section">
<summary>${t.t("start_view")}</summary>
${S(t.t("start_view_hint"))}
${Q(m`<button class="nf-btn nf-primary" @click=${r}>${t.t("start_view_set")}</button>`,n?m`<button class="nf-btn" @click=${()=>t.change(i=>i.settings.start_view=null)}>${t.t("start_view_reset")}</button>`:_)}
${n?m`${S(t.t("start_view_saved"))} ${S(t.t("start_view_card"))}<code class="nf-code">${ep(n)}</code>`:_}
</details>`}function op(t){if(Z(t.hass))return Xh(t);let e=t.doc.presence.map(l=>l.person),n=[...new Set([...Object.keys(t.hass?.states??{}).filter(l=>l.startsWith("person.")).sort(),...e])],r=O(t.hass,ge),i=t.doc.floors.flatMap(l=>l.rooms.map(c=>({id:c.id,label:t.doc.floors.length>1?`${l.name} \xB7 ${c.name}`:c.name}))),o=(l,c)=>t.replace({...structuredClone(t.doc),presence:Jh(t.doc.presence,l,c)}),s=l=>{let c=t.doc.presence.find(u=>u.person===l),d=!l.startsWith("person.");return m`${z(t,`${B(t.hass,l)} \xB7 ${t.t("presence_sensor")}`,c?.sensor??null,void 0,Qh(r,l),u=>o(l,{sensor:u}))}
<label class="nf-field">${t.t("presence_room")}
<select ?disabled=${!t.admin} .value=${c?.room??""} @change=${u=>o(l,{room:u.target.value||null})}>
<option value="">${t.t("presence_room_none")}</option>
${i.map(u=>m`<option value=${u.id} ?selected=${c?.room===u.id}>${u.label}</option>`)}
</select>
</label>
${d?m`<button class="nf-btn" ?disabled=${!t.admin} @click=${()=>t.replace({...structuredClone(t.doc),presence:t.doc.presence.filter(u=>u.person!==l)})}>${t.t("delete")}</button>`:_}`},a=O(t.hass,l=>/^(input_boolean|binary_sensor|device_tracker)\./.test(l)&&!n.includes(l));return m`<details class="nf-section">
<summary>${t.t("presence")}</summary>
<div class="nf-form">${n.length>0?n.map(s):m`<p class="nf-sub nf-wide">${t.t("no_persons")}</p>`}</div>
<div class="nf-form">${z(t,t.t("presence_add"),null,void 0,a,l=>l&&l!=="none"&&t.replace({...structuredClone(t.doc),presence:[...t.doc.presence,{person:l,sensor:null}]}))}</div>
${S(t.t("presence_hint"))}
</details>`}function sp(t,e){return Z(t.hass)?m``:m`<details class="nf-section">
<summary>${t.t("ble")}</summary>
${S(t.t("ble_hint"))}
<nf-ble-locate .host=${t} .doc=${e}></nf-ble-locate>
</details>`}var yi=(t,e)=>{let n=t._$AN;if(n===void 0)return!1;for(let r of n)r._$AO?.(e,!1),yi(r,e);return!0},jo=t=>{let e,n;do{if((e=t._$AM)===void 0)break;n=e._$AN,n.delete(t),t=e}while(n?.size===0)},ap=t=>{for(let e;e=t._$AM;t=e){let n=e._$AN;if(n===void 0)e._$AN=n=new Set;else if(n.has(t))break;n.add(t),Xv(e)}};function qv(t){this._$AN!==void 0?(jo(this),this._$AM=t,ap(this)):this._$AM=t}function Yv(t,e=!1,n=0){let r=this._$AH,i=this._$AN;if(i!==void 0&&i.size!==0)if(e)if(Array.isArray(r))for(let o=n;o<r.length;o++)yi(r[o],!1),jo(r[o]);else r!=null&&(yi(r,!1),jo(r));else yi(this,t)}var Xv=t=>{t.type==On.CHILD&&(t._$AP??=Yv,t._$AQ??=qv)},Go=class extends It{constructor(){super(...arguments),this._$AN=void 0}_$AT(e,n,r){super._$AT(e,n,r),ap(this),this.isConnected=e._$AU}_$AO(e,n=!0){e!==this.isConnected&&(this.isConnected=e,e?this.reconnected?.():this.disconnected?.()),n&&(yi(this,e),jo(this))}setValue(e){if(Au(this._$Ct))this._$Ct._$AI(e,this);else{let n=[...this._$Ct._$AH];n[this._$Ci]=e,this._$Ct._$AI(n,this,0)}}disconnected(){}reconnected(){}};var fl=new WeakMap,lp=sn(class extends Go{render(t){return _}update(t,[e]){let n=e!==this.G;return n&&this.rt(void 0),(n||this.lt!==this.ct)&&(this.G=e,this.ht=t.options?.host,this.rt(this.ct=t.element)),_}rt(t){if(this.G!==void 0)if(this.isConnected||(t=void 0),typeof this.G=="function"){let e=this.ht??globalThis,n=fl.get(e);n===void 0&&(n=new WeakMap,fl.set(e,n)),n.get(this.G)!==void 0&&this.G.call(this.ht,void 0),n.set(this.G,t),t!==void 0&&this.G.call(this.ht,t)}else this.G.value=t}get lt(){return typeof this.G=="function"?fl.get(this.ht??globalThis)?.get(this.G):this.G?.value}disconnected(){this.lt===this.ct&&this.rt(void 0)}reconnected(){this.rt(this.ct)}});var cp=t=>t.trim().toLowerCase().replace(/ä/g,"ae").replace(/ö/g,"oe").replace(/ü/g,"ue").replace(/ß/g,"ss").replace(/[^a-z0-9_-]+/g,"_").replace(/^_+|_+$/g,"").slice(0,40);function dp(t){let e=t.t,n=t.doc.settings.card_templates??{},r=Object.keys(n),i=a=>t.change(l=>{l.settings.card_templates=Object.keys(a).length?a:void 0});t.loadCardEditor?.();let o=a=>{t.hass?.callService("nextfloor","reload_screens",a?{template:a}:{})},s=a=>{let l=cp(a.value);!l||l in n||r.length>=20||(a.value="",i({...n,[l]:{}}))};return m`<details class="nf-section">
<summary>${e("card_templates")}${r.length?m` <span class="nf-lib-count">${r.length}</span>`:_}</summary>
${S(e("card_templates_hint"))}
${r.map(a=>m`<details class="nf-section">
<summary>${a}</summary>
<nextfloor-card-editor
.hass=${t.hass}
${lp(l=>l&&l.setConfig({type:"custom:nextfloor-card",...n[a]}))}
@config-changed=${l=>{l.stopPropagation();let{type:c,template:d,...u}=l.detail.config;i({...n,[a]:u})}}
></nextfloor-card-editor>
${t.admin?m`<div class="nf-actions">
<button class="nf-btn" @click=${()=>o(a)}>${e("template_reload")}</button>
<button class="nf-btn nf-danger" @click=${()=>i(Object.fromEntries(Object.entries(n).filter(([l])=>l!==a)))}>${e("delete")}</button>
</div>`:_}
${S(e("template_use",{name:a}))}
</details>`)}
${t.admin?m`<div class="nf-form">
<label class="nf-field nf-wide">${e("template_name")}<input type="text" maxlength="40" placeholder="kitchen_tablet" @keydown=${a=>a.key==="Enter"&&s(a.target)} /></label>
</div>
<div class="nf-actions">
<button class="nf-btn" @click=${a=>s(a.target.closest("details")?.querySelector("input[type=text]")??document.createElement("input"))}>${e("template_add")}</button>
<button class="nf-btn" @click=${()=>o()}>${e("template_reload_all")}</button>
</div>`:_}
</details>`}var Uo=.05,Jv=(t,e)=>t.length===e.length&&t.every((n,r)=>Math.abs(n[0]-e[r][0])<.001&&Math.abs(n[1]-e[r][1])<.001),vn=t=>new Map(t.map(e=>[e.id,e]));function Qv(t,e,n,r){let i=e.name,[o,s]=[vn(t.rooms),vn(e.rooms)];for(let h of e.rooms){let f=o.get(h.id);f?(f.name!==h.name&&n.push({kind:"room_renamed",floor:i,name:h.name,detail:f.name}),Jv(f.points,h.points)||n.push({kind:"room_reshaped",floor:i,name:h.name,detail:Math.round((ye(h.points)-ye(f.points))*10)/10})):n.push({kind:"room_added",floor:i,name:h.name})}for(let h of t.rooms)s.has(h.id)||n.push({kind:"room_removed",floor:i,name:h.name});let[a,l]=[vn(t.openings),vn(e.openings)];for(let h of e.openings)a.has(h.id)||n.push({kind:"opening_added",floor:i,name:h.type,detail:r(h.room_id)});for(let h of t.openings)l.has(h.id)||n.push({kind:"opening_removed",floor:i,name:h.type,detail:r(h.room_id)});let[c,d]=[vn(t.furniture),vn(e.furniture)];for(let h of e.furniture){let f=c.get(h.id);f?(Math.hypot(h.x-f.x,h.z-f.z)>Uo||Math.abs(h.rotation-f.rotation)>1||Math.abs(h.w-f.w)>Uo||Math.abs(h.d-f.d)>Uo)&&n.push({kind:"furniture_moved",floor:i,name:h.name||h.type}):n.push({kind:"furniture_added",floor:i,name:h.name||h.type})}for(let h of t.furniture)d.has(h.id)||n.push({kind:"furniture_removed",floor:i,name:h.name||h.type});let[u,p]=[new Map(t.placements.map(h=>[h.entity_id,h])),new Map(e.placements.map(h=>[h.entity_id,h]))];for(let h of e.placements){let f=u.get(h.entity_id);f?Math.hypot(h.x-f.x,h.z-f.z)>Uo&&n.push({kind:"device_moved",floor:i,name:h.entity_id}):n.push({kind:"device_added",floor:i,name:h.entity_id})}for(let h of t.placements)p.has(h.entity_id)||n.push({kind:"device_removed",floor:i,name:h.entity_id})}function up(t,e){let n=[],r=vn(t.floors),i=new Map([...t.floors,...e.floors].flatMap(a=>a.rooms.map(l=>[l.id,l.name]))),o=a=>i.get(a)??"";for(let a of e.floors){let l=r.get(a.id);l?Qv(l,a,n,o):n.push({kind:"floor_added",floor:a.name,name:a.name})}let s=new Set(e.floors.map(a=>a.id));for(let a of t.floors)s.has(a.id)||n.push({kind:"floor_removed",floor:a.name,name:a.name});return n}var wn=(t,e)=>t.getUint16(e,!0),vi=(t,e)=>t.getUint32(e,!0);function hp(t){let e=new DataView(t.buffer,t.byteOffset,t.byteLength),n=-1;for(let a=t.length-22;a>=Math.max(0,t.length-65557);a--)if(vi(e,a)===101010256){n=a;break}if(n<0)throw new Error("not_zip");let r=wn(e,n+10),i=vi(e,n+16),o=[],s=new TextDecoder;for(let a=0;a<r;a++){if(vi(e,i)!==33639248)throw new Error("not_zip");let l=wn(e,i+10),c=vi(e,i+20),d=wn(e,i+28),u=wn(e,i+30),p=wn(e,i+32),h=vi(e,i+42),f=s.decode(t.subarray(i+46,i+46+d)),g=h+30+wn(e,h+26)+wn(e,h+28);o.push({name:f,method:l,compressedSize:c,offset:g}),i+=46+d+u+p}return o}async function pp(t,e){let n=t.subarray(e.offset,e.offset+e.compressedSize);if(e.method===0)return n;if(e.method!==8)throw new Error("zip_method");let r=new Blob([n.slice()]).stream().pipeThrough(new DecompressionStream("deflate-raw"));return new Uint8Array(await new Response(r).arrayBuffer())}var ew={amp:"&",lt:"<",gt:">",quot:'"',apos:"'"},tw=t=>t.replace(/&(#x?[0-9a-f]+|\w+);/gi,(e,n)=>n[0]==="#"?String.fromCodePoint(Number.parseInt(n.slice(n[1]==="x"?2:1),n[1]==="x"?16:10)):ew[n]??e);function nw(t){let e={};for(let n of t.matchAll(/([\w:.-]+)\s*=\s*(?:"([^"]*)"|'([^']*)')/g))e[n[1]]=tw(n[2]??n[3]);return e}function rw(t){let e=[],n=null;for(let r of t.matchAll(/<(\/?)(level|room|point|wall|doorOrWindow|pieceOfFurniture)\b([^>]*?)(\/?)>/g)){let[,i,o,s,a]=r;if(i){o==="room"&&(n=null);continue}let l=nw(s);if(o==="point"){n&&n.points.push([Number(l.x)/100,Number(l.y)/100]);continue}let c={name:o,attrs:l,...o==="room"?{points:[]}:{}};e.push(c),o==="room"&&!a&&(n=c)}return e}var oe=(t,e,n)=>Number.isFinite(Number(t[e]))&&t[e]!==void 0?Number(t[e]):n,Pe=t=>Math.round(t*1e3)/1e3;function fp(t,e,n){let[r,i]=[n[0]-e[0],n[1]-e[1]],o=Math.hypot(r,i)||1e-9,s=Math.max(0,Math.min(o,((t[0]-e[0])*r+(t[1]-e[1])*i)/o)),a=[e[0]+r*s/o,e[1]+i*s/o];return{dist:Math.hypot(t[0]-a[0],t[1]-a[1]),along:s,length:o}}function iw(t){let e=`${t.name??""} ${t.catalogId??""}`.toLowerCase();return/garage|sectional|rolltor/.test(e)?"garage":/door|tür|tuer|porte|puerta|deur|haustür/.test(e)&&!/window|fenster/.test(e)?"door":"window"}function ow(t,e){let n=t.length,r=t.map((i,o)=>{let s=t[(o+1)%n],[a,l]=[s[0]-i[0],s[1]-i[1]],c=Math.hypot(a,l)||1e-9,d=[a/c,l/c],u=[(i[0]+s[0])/2,(i[1]+s[1])/2],p=[0,0];for(let h of e){let[f,g]=[h.b[0]-h.a[0],h.b[1]-h.a[1]],b=Math.hypot(f,g)||1e-9;if(Math.abs((d[0]*g-d[1]*f)/b)>.05)continue;let y=(h.a[0]-u[0])*-d[1]+(h.a[1]-u[1])*d[0],v=((u[0]-h.a[0])*f+(u[1]-h.a[1])*g)/b;if(!(Math.abs(y)>h.thickness/2+.06||v<-.05||v>b+.05)){p=[-d[1]*y,d[0]*y];break}}return{p:[i[0]+p[0],i[1]+p[1]],dir:d}});return r.map((i,o)=>{let s=r[(o-1+n)%n],a=s.dir[0]*i.dir[1]-s.dir[1]*i.dir[0];if(Math.abs(a)<1e-6)return i.p;let l=((i.p[0]-s.p[0])*i.dir[1]-(i.p[1]-s.p[1])*i.dir[0])/a;return[s.p[0]+s.dir[0]*l,s.p[1]+s.dir[1]*l]})}function sw(t){let e=Pt(),n={floors:0,rooms:0,openings:0,walls:0,furniture:0},r=t.filter(l=>l.name==="level"),i=r.length?r.map(l=>l.attrs.id??""):[""],o=t.filter(l=>l.name==="wall"),s=o.length?Math.max(...o.map(l=>oe(l.attrs,"height",250)))/100:2.5;return(r.length?[...r].sort((l,c)=>oe(l.attrs,"elevation",0)-oe(c.attrs,"elevation",0)||oe(l.attrs,"elevationIndex",0)-oe(c.attrs,"elevationIndex",0)):[{name:"level",attrs:{id:""}}]).forEach((l,c)=>{let d=l.attrs.id??"",u=b=>r.length?(b.attrs.level??i[0])===d:!0,p=Ee(P("floor"),l.attrs.name||(c===0?"Erdgeschoss":`Etage ${c+1}`),Pe(oe(l.attrs,"elevation",0)/100));p.height=Pe(oe(l.attrs,"height",s*100)/100);let h=o.filter(u).map(b=>({a:[oe(b.attrs,"xStart",0)/100,oe(b.attrs,"yStart",0)/100],b:[oe(b.attrs,"xEnd",0)/100,oe(b.attrs,"yEnd",0)/100],thickness:oe(b.attrs,"thickness",10)/100})),f=t.filter(b=>b.name==="room"&&u(b)&&(b.points?.length??0)>=3).map((b,y)=>({id:P("room"),name:b.attrs.name||`Raum ${y+1}`,area_id:null,points:ow(b.points,h).map(([v,w])=>[Pe(v),Pe(w)]),floor_material:"wood",panel:[]}));p.rooms=f;for(let b of t.filter(y=>y.name==="doorOrWindow"&&u(y))){let y=[oe(b.attrs,"x",0)/100,oe(b.attrs,"y",0)/100],v=Math.max(.6,oe(b.attrs,"depth",30)/100+.3),w=null;for(let L of f)L.points.forEach((I,N)=>{let V=fp(y,I,L.points[(N+1)%L.points.length]);V.dist<=v&&(!w||V.dist<w.dist)&&(w={room:L,edge:N,...V})});if(!w)continue;let{room:k,edge:x,along:M,length:A}=w,T=iw(b.attrs),F=Math.min(A,Math.max(.3,oe(b.attrs,"width",90)/100));p.openings.push({id:P("op"),room_id:k.id,edge:x,offset:Pe(Math.min(A-F/2,Math.max(F/2,M))),width:Pe(F),type:T,sill:T==="window"?Pe(oe(b.attrs,"elevation",90)/100):0,height:Pe(oe(b.attrs,"height",T==="window"?130:205)/100),hinge:"left",leaves:F>1.4?2:1,swing:"in",cover:null,contact:null,contact2:null,tilt:null})}let g=[];for(let b of o.filter(u)){let y=[oe(b.attrs,"xStart",0)/100,oe(b.attrs,"yStart",0)/100],v=[oe(b.attrs,"xEnd",0)/100,oe(b.attrs,"yEnd",0)/100];if(Math.hypot(v[0]-y[0],v[1]-y[1])<.1)continue;let w=Math.max(.15,oe(b.attrs,"thickness",10)/100),k=F=>f.some(L=>L.points.some((I,N)=>fp(F,I,L.points[(N+1)%L.points.length]).dist<w)),x=Math.hypot(v[0]-y[0],v[1]-y[1]),M=Math.max(12,Math.ceil(x/.1)),A=F=>[y[0]+(v[0]-y[0])*F/M,y[1]+(v[1]-y[1])*F/M],T=Array.from({length:M+1},(F,L)=>!k(A(L)));for(let F=0;F<=M;){if(!T[F]){F++;continue}let L=F;for(;L+1<=M&&T[L+1];)L++;let[I,N]=[A(Math.max(0,F-1)),A(Math.min(M,L+1))];Math.hypot(N[0]-I[0],N[1]-I[1])>=.3&&g.push({id:P("wall"),a:[Pe(I[0]),Pe(I[1])],b:[Pe(N[0]),Pe(N[1])],thickness:Pe(oe(b.attrs,"thickness",10)/100),height:b.attrs.height?Pe(oe(b.attrs,"height",250)/100):null}),F=L+1}}p.walls=g,n.rooms+=f.length,n.openings+=p.openings.length,n.walls+=g.length,(f.length||g.length)&&e.floors.push(p)}),n.floors=e.floors.length,n.furniture=t.filter(l=>l.name==="pieceOfFurniture").length,{building:Oe(e),report:n}}async function mp(t){let e=hp(t).find(i=>i.name==="Home.xml");if(!e)throw new Error("sh3d_no_xml");let n=new TextDecoder().decode(await pp(t,e)),r=sw(rw(n));if(r.report.rooms===0&&r.report.walls===0)throw new Error("sh3d_empty");return r}function aw(t){let e=t.split(/\r?\n/),n=[];for(let r=0;r+1<e.length;r+=2){let i=Number(e[r].trim());Number.isFinite(i)&&n.push([i,e[r+1].trim()])}return n}function lw(t){let e=t.findIndex(([r,i])=>r===9&&i==="$INSUNITS"),n=e>=0?Number(t[e+1]?.[1]):NaN;return{1:.0254,2:.3048,4:.001,5:.01,6:1}[n]??null}function cw(t){let e=aw(t),n=lw(e),r=e.findIndex(([s,a],l)=>s===2&&a==="ENTITIES"&&e[l-1]?.[1]==="SECTION"),i=[];if(r<0)return{shapes:i,unit:n};let o=r+1;for(;o<e.length&&!(e[o][0]===0&&e[o][1]==="ENDSEC");){let[s,a]=e[o];if(s!==0){o++;continue}let l=o+1;for(;l<e.length&&e[l][0]!==0;)l++;let c=e.slice(o+1,l);if(a==="LINE"){let d=p=>Number(c.find(([h])=>h===p)?.[1]??NaN),u=[[d(10),d(20)],[d(11),d(21)]];u.every(([p,h])=>Number.isFinite(p)&&Number.isFinite(h))&&i.push({points:u,closed:!1})}else if(a==="LWPOLYLINE"){let d=c.filter(([f])=>f===10).map(([,f])=>Number(f)),u=c.filter(([f])=>f===20).map(([,f])=>Number(f)),p=Number(c.find(([f])=>f===70)?.[1]??0),h=d.map((f,g)=>[f,u[g]]).filter(([f,g])=>Number.isFinite(f)&&Number.isFinite(g));h.length>=2&&i.push({points:h,closed:(p&1)===1})}o=l}return{shapes:i,unit:n}}var gp=t=>Math.round(t*1e3)/1e3;function _p(t){let{shapes:e,unit:n}=cw(t);if(!e.length)throw new Error("dxf_empty");let r=e.flatMap(h=>h.points),i=Math.max(Math.max(...r.map(h=>h[0]))-Math.min(...r.map(h=>h[0])),Math.max(...r.map(h=>h[1]))-Math.min(...r.map(h=>h[1]))),o=n??(i>2e3?.001:i>200?.01:1),s=Math.min(...r.map(h=>h[0])),a=Math.max(...r.map(h=>h[1])),l=([h,f])=>[gp((h-s)*o),gp((a-f)*o)],c=Ee(P("floor"),"Erdgeschoss",0),d=[],u=[];for(let h of e){let f=h.points.map(l);if(h.closed&&f.length>=3)d.push({id:P("room"),name:`Raum ${d.length+1}`,area_id:null,points:f,floor_material:"wood",panel:[]});else for(let g=0;g+1<f.length;g++)Math.hypot(f[g+1][0]-f[g][0],f[g+1][1]-f[g][1])>.05&&u.push({id:P("wall"),a:f[g],b:f[g+1]})}c.rooms=d,c.walls=u;let p=Pt();return p.floors=[c],{building:Oe(p),report:{floors:1,rooms:d.length,openings:0,walls:u.length,furniture:0}}}var Qe=t=>Math.round(t*100)/100;function dw(t,e){let n=t.category;return typeof n=="string"?n:n&&typeof n=="object"?Object.keys(n)[0]??e:e}function uw(t,e){let n=t,r=n?.transform,i=n?.dimensions;if(!n||!Array.isArray(r)||r.length<16||!Array.isArray(i)||i.length<3)return null;let o=a=>Number(a),s=Math.hypot(o(r[0]),o(r[2]));return![...r.slice(0,16),...i.slice(0,3)].every(a=>Number.isFinite(o(a)))||s<1e-6?null:{centre:[o(r[12]),o(r[13]),o(r[14])],dir:[o(r[0])/s,o(r[2])/s],size:[o(i[0]),o(i[1]),o(i[2])],kind:dw(n,e)}}var rr=(t,e,n)=>(Array.isArray(t[e])?t[e]:[]).map(r=>uw(r,n)).filter(r=>!!r);function hw(t){if(t.length<3)return null;let e=t.map(l=>{let c=l.size[0]/2;return[[l.centre[0]-l.dir[0]*c,l.centre[2]-l.dir[1]*c],[l.centre[0]+l.dir[0]*c,l.centre[2]+l.dir[1]*c]]}),n=(l,c)=>Math.hypot(l[0]-c[0],l[1]-c[1]),r=.4,i=new Set([0]),o=[e[0][0]],s=[0],a=e[0][1];for(;i.size<t.length;){let l=null;for(let u=0;u<t.length;u++)if(!i.has(u))for(let p of[!1,!0]){let h=n(a,e[u][p?1:0]);h<=r&&(!l||h<l.d)&&(l={i:u,flip:p,d:h})}if(!l)break;let[c,d]=l.flip?[e[l.i][1],e[l.i][0]]:[e[l.i][0],e[l.i][1]];o.push([(a[0]+c[0])/2,(a[1]+c[1])/2]),s.push(l.i),i.add(l.i),a=d}return i.size<t.length||n(a,o[0])>r?null:(o[0]=[(a[0]+o[0][0])/2,(a[1]+o[0][1])/2],{points:o,edgeWall:s})}function bp(t){let e=[],n=[];for(let a of t){let l=a.size[0]/2;for(let c of[-1,1])e.push(a.centre[0]+c*a.dir[0]*l),n.push(a.centre[2]+c*a.dir[1]*l)}let[r,i,o,s]=[Math.min(...e),Math.max(...e),Math.min(...n),Math.max(...n)];return[[r,o],[i,o],[i,s],[r,s]]}function pw(t,e,n){let[r,i]=[n[0]-e[0],n[1]-e[1]],o=Math.hypot(r,i)||1e-9,s=Math.min(o,Math.max(0,((t[0]-e[0])*r+(t[1]-e[1])*i)/o));return{dist:Math.hypot(t[0]-(e[0]+r/o*s),t[1]-(e[1]+i/o*s)),along:s,length:o}}var fw={sofa:"sofa",bed:"bed",table:"table",chair:"chair",bathtub:"bathtub",toilet:"wc",sink:"sink",refrigerator:"fridge",stove:"stove",oven:"stove",dishwasher:"dishwasher",washerDryer:"washer",storage:"tall_cabinet",television:"tv_board"};function yp(t){let e=t;return!e||typeof e!="object"||"floors"in e||"settings"in e?!1:(Array.isArray(e.rooms)?e.rooms:[e]).some(r=>r&&Array.isArray(r.walls)&&rr(r,"walls","wall").length>0)}function vp(t){let e=t,r=(Array.isArray(e.rooms)?e.rooms:[e]).filter(b=>b&&typeof b=="object").map(b=>({walls:rr(b,"walls","wall"),doors:[...rr(b,"doors","door"),...rr(b,"openings","opening")],windows:rr(b,"windows","window"),objects:rr(b,"objects","object")})).filter(b=>b.walls.length);if(!r.length)throw new Error("roomplan_empty");let i=r.flatMap(b=>b.walls),o=Math.min(...i.map(b=>b.centre[1]-b.size[1]/2)),s=r.map(b=>hw(b.walls)),a=r.flatMap((b,y)=>s[y]?.points??bp(b.walls)),[l,c]=[Math.min(...a.map(b=>b[0]))-.5,Math.min(...a.map(b=>b[1]))-.5],d=([b,y])=>[Qe(b-l),Qe(y-c)],u=Ee(P("floor"),"Erdgeschoss",0);u.height=Qe(Math.max(2.2,Math.min(4,Math.max(...i.map(b=>b.size[1])))));let p=[],h=[];r.forEach((b,y)=>{let w=(s[y]?.points??bp(b.walls)).map(d),k={id:P("room"),name:`Raum ${y+1}`,area_id:null,points:w,floor_material:"wood",panel:[]};p.push(k);for(let x of[...b.doors.map(M=>({v:M,window:!1})),...b.windows.map(M=>({v:M,window:!0}))]){let M=[x.v.centre[0]-l,x.v.centre[2]-c],A=null;if(w.forEach((I,N)=>{let V=pw(M,I,w[(N+1)%w.length]);V.dist<=.6&&(!A||V.dist<A.dist)&&(A={edge:N,...V})}),!A)continue;let T=A,F=Math.min(T.length,Math.max(.3,x.v.size[0])),L=x.v.kind==="opening";u.openings.push({id:P("op"),room_id:k.id,edge:T.edge,offset:Qe(Math.min(T.length-F/2,Math.max(F/2,T.along))),width:Qe(F),type:x.window?"window":"door",sill:x.window?Qe(Math.max(0,x.v.centre[1]-x.v.size[1]/2-o)):0,height:Qe(x.v.size[1]),hinge:"left",leaves:F>1.4?2:1,swing:"in",...L?{style:"passage"}:{},cover:null,contact:null,contact2:null,tilt:null})}for(let x of b.objects){let M=fw[x.kind];if(!M)continue;let[A,T,F]=[x.size[0],x.size[2],x.size[1]];A<.1||T<.1||h.push({id:P("f"),type:M,x:Qe(x.centre[0]-l),z:Qe(x.centre[2]-c),rotation:Math.round((Math.atan2(x.dir[1],x.dir[0])*180/Math.PI+360)%360),w:Qe(A),d:Qe(T),h:Qe(F),variant:null,entity:null,power:null})}}),u.rooms=p,u.furniture=h;let f=Pt();f.floors=[u];let g=r.reduce((b,y)=>b+y.objects.length,0)-h.length;return{building:Oe(f),report:{floors:1,rooms:p.length,openings:u.openings.length,walls:0,furniture:g}}}var wi=t=>typeof t=="object"&&t!==null&&!Array.isArray(t)&&"ref"in t;function mw(t){let e=0,n=()=>{for(;t[e]===" ";)e++;let i=t[e];if(i==="("){e++;let l=[];for(;e<t.length&&t[e]!==")";){for(l.push(n());t[e]===" ";)e++;t[e]===","&&e++}return e++,l}if(i==="'"){let l="";for(e++;e<t.length;)if(t[e]==="'"&&t[e+1]==="'")l+="'",e+=2;else if(t[e]==="'"){e++;break}else l+=t[e++];return gw(l)}if(i==="#"){let l=/^#(\d+)/.exec(t.slice(e));return e+=l[0].length,{ref:Number(l[1])}}if(i==="$"||i==="*")return e++,null;let o=/^[^,()]+/.exec(t.slice(e)),s=o?o[0].trim():"";if(e+=o?o[0].length:1,t[e]==="(")return n();let a=Number(s);return Number.isFinite(a)&&s!==""?a:s},r=[];for(;e<t.length;){for(r.push(n());t[e]===" ";)e++;if(t[e]===",")e++;else break}return r}function gw(t){return t.replace(/\\X2\\([0-9A-Fa-f]+)\\X0\\/g,(e,n)=>String.fromCharCode(...(n.match(/.{4}/g)??[]).map(r=>parseInt(r,16)))).replace(/\\S\\(.)/g,(e,n)=>String.fromCharCode(n.charCodeAt(0)+128))}function _w(t){let e=new Map,n=t.slice(Math.max(0,t.indexOf("DATA;")));for(let r of n.matchAll(/#(\d+)\s*=\s*([A-Z0-9_]+)\s*\(([\s\S]*?)\)\s*;(?=\s*(?:#|ENDSEC))/g))e.set(Number(r[1]),{type:r[2],args:mw(r[3])});return e}var wp={x:0,y:0,z:0,c:1,s:0},xp=(t,e)=>({x:t.x+t.c*e.x-t.s*e.y,y:t.y+t.s*e.x+t.c*e.y,z:t.z+e.z,c:t.c*e.c-t.s*e.s,s:t.s*e.c+t.c*e.s});function kp(t){let e=_w(t);if(!e.size)throw new Error("ifc_empty");let n=x=>wi(x)?e.get(x.ref):void 0,r=x=>typeof x=="number"?x:NaN,i=x=>(n(x)?.args[0]??[]).map(M=>r(M)),o=[...e.values()].find(x=>x.type==="IFCSIUNIT"&&x.args[1]===".LENGTHUNIT."),s=o?{".MILLI.":.001,".CENTI.":.01,".DECI.":.1}[String(o.args[2])]??1:1,a=x=>{let M=n(x);if(!M)return wp;let[A=0,T=0,F=0]=i(M.args[0]),L=n(M.type==="IFCAXIS2PLACEMENT3D"?M.args[2]:M.args[1]),[I=1,N=0]=(L?.args[0]??[]).map(X=>r(X)),V=Math.hypot(I,N)||1;return{x:A||0,y:T||0,z:F||0,c:I/V,s:N/V}},l=(x,M=0)=>{let A=n(x);return!A||A.type!=="IFCLOCALPLACEMENT"||M>30?wp:xp(l(A.args[0],M+1),a(A.args[1]))},c=x=>{for(let M of n(x)?.args[2]??[])for(let A of n(M)?.args[3]??[]){let T=n(A);if(T?.type!=="IFCEXTRUDEDAREASOLID")continue;let F=n(T.args[0]),L=xp(a(T.args[1]),a(F?.args[2])),I=[];if(F?.type==="IFCRECTANGLEPROFILEDEF"){let[N,V]=[r(F.args[3])/2,r(F.args[4])/2];I=[[-N,-V],[N,-V],[N,V],[-N,V]]}else if(F?.type==="IFCARBITRARYCLOSEDPROFILEDEF"){let N=n(F.args[2]);N?.type==="IFCPOLYLINE"&&(I=(N.args[0]??[]).map(V=>i(V)))}if(I=I.filter(N=>Number.isFinite(N[0])&&Number.isFinite(N[1])),I.length>3&&Math.hypot(I[0][0]-I[I.length-1][0],I[0][1]-I[I.length-1][1])<1e-6&&I.pop(),I.length>=3)return I.map(([N,V])=>[L.x+L.c*N-L.s*V,L.y+L.s*N+L.c*V])}return null},d=new Map;for(let[,x]of e){if(x.type==="IFCRELAGGREGATES"&&wi(x.args[4]))for(let M of x.args[5]??[])wi(M)&&d.set(M.ref,x.args[4].ref);if(x.type==="IFCRELCONTAINEDINSPATIALSTRUCTURE"&&wi(x.args[5]))for(let M of x.args[4]??[])wi(M)&&d.set(M.ref,x.args[5].ref)}let u=[...e].filter(([,x])=>x.type==="IFCBUILDINGSTOREY").map(([x,M])=>({id:x,name:String(M.args[7]||M.args[2]||"")||null,elevation:r(M.args[9])*s}));u.sort((x,M)=>(x.elevation||0)-(M.elevation||0));let p=[];for(let[x,M]of e){if(M.type!=="IFCSPACE")continue;let A=c(M.args[6]);if(!A)continue;let T=l(M.args[5]),F=A.map(([I,N])=>[(T.x+T.c*I-T.s*N)*s,(T.y+T.s*I+T.c*N)*s]),L=String(M.args[7]||M.args[2]||"")||`Raum ${p.length+1}`;p.push({storey:d.get(x)??null,name:L,ring:F})}if(!p.length)throw new Error("ifc_empty");let h=p.flatMap(x=>x.ring),f=Math.min(...h.map(x=>x[0])),g=Math.max(...h.map(x=>x[1])),b=x=>Math.round(x*1e3)/1e3,y=[],v=new Map;if(u.filter(x=>p.some(M=>M.storey===x.id)).forEach((x,M)=>{let A=Ee(P("floor"),x.name??`Etage ${M+1}`,Number.isFinite(x.elevation)?b(x.elevation):M*2.8);y.push(A),v.set(x.id,A)}),p.some(x=>x.storey===null||!v.has(x.storey))){let x=Ee(P("floor"),y.length?"Weitere R\xE4ume":"Erdgeschoss",y.length?y[y.length-1].elevation+2.8:0);y.push(x),v.set(null,x)}y.forEach((x,M)=>{let A=y[M+1];A&&A.elevation-x.elevation>1.8&&(x.height=b(A.elevation-x.elevation-.2))});for(let x of p)v.get(x.storey!==null&&v.has(x.storey)?x.storey:null).rooms.push({id:P("room"),name:x.name,area_id:null,points:x.ring.map(([A,T])=>[b(A-f),b(g-T)]),floor_material:"wood",panel:[]});let k=Pt();return k.floors=y,{building:Oe(k),report:{floors:y.length,rooms:p.length,openings:0,walls:0,furniture:0}}}var Sp="nextfloor",bw="alarm_control_panel|automation|binary_sensor|button|calendar|camera|climate|conversation|cover|date|datetime|device_tracker|event|fan|group|humidifier|image|input_boolean|input_button|input_datetime|input_number|input_select|input_text|lawn_mower|light|lock|media_player|notify|number|person|remote|scene|script|select|sensor|siren|stt|sun|switch|text|time|timer|todo|tts|update|vacuum|valve|water_heater|weather|zone",$p=new RegExp(`^(?:${bw})\\.[a-z0-9_]+$`),yw=/^[0-9a-f]{32}$/,vw=new Set(["area_id","ha_floor"]),ww=new Set(["sub_areas"]),xw=new Set(["tap","show_when","pictures","moods"]);function ml(t){if(typeof t=="string")return $p.test(t)||yw.test(t)?null:t;if(Array.isArray(t))return t.map(e=>ml(e)).filter(e=>e!==null);if(t&&typeof t=="object"){let e={};for(let[n,r]of Object.entries(t))$p.test(n)||xw.has(n)||(vw.has(n)||ww.has(n)?e[n]=null:e[n]=ml(r));return e}return t}var kw=["wall_exterior","wall_interior","wall_paint_outside","wall_paint_inside","grid","north","roof","weather_effects","rain_warning","sun_patches","lock_plan","start_view","units","motion_markers_active","room_double_tap"];function Mp(t){let e=structuredClone(t),n={};for(let i of kw)e.settings?.[i]!==void 0&&(n[i]=e.settings[i]);let r=e.settings?.backdrop;r&&(r.color||r.dim!=null)&&(n.backdrop={color:r.color??null,dim:r.dim??null}),e.settings=n,e.energy={...e.energy,grid:null,solar:null,battery:null,battery_soc:null,tariff:null,consumption:null,gas:null,water:null},e.presence=[];for(let i of e.floors){i.background=null,i.placements=[],i.power_entity=null,i.utility_meters=null,i.ha_floor=null;for(let o of i.rooms)Object.assign(o,{area_id:null,sub_areas:null,panel:[],hidden:[],no_state:[]});i.furniture.forEach(o=>{Object.assign(o,{entity:null,power:null}),delete o.effect_animations,o.picture&&!(o.picture.startsWith("image:")||o.picture.startsWith("https://"))&&(o.picture=null)}),i.openings.forEach(o=>Object.assign(o,{cover:null,contact:null,tilt:null}))}return ml(e)}function Ep(t,e){return{format:Sp,version:1,exported_at:new Date().toISOString(),building:e?Mp(t):structuredClone(t)}}var $w=t=>!!t&&(t.version===1||t.version===void 0)&&Array.isArray(t.floors)&&t.floors.every(e=>!!e&&typeof e=="object"),Sw="https://therealmrbk.github.io/NextFloor/preview/?shared&noshowcase";function Rp(t,e,n,r,i=Sw){let o=new Set(t.floors.flatMap(c=>c.furniture.map(d=>d.type)).filter(c=>c.startsWith("pack:")).map(c=>c.split(":")[1])),s={building:Mp(t),packs:e.filter(c=>!c.builtin&&o.has(c.id))},a=JSON.stringify(s).replace(/</g,"\\u003c"),l=c=>c.replace(/[&<>"]/g,d=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;"})[d]);return`<!doctype html>
<html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>${l(n)}</title>
<style>html,body{margin:0;height:100%;background:#111;color:#ddd;font-family:system-ui,sans-serif}iframe{border:0;width:100%;height:100%;display:block}noscript p{padding:2em}</style></head>
<body><iframe id="nf" src="${l(i)}" allow="fullscreen" title="${l(n)}"></iframe>
<noscript><p>${l(r)}</p></noscript>
<script id="nf-plan" type="application/json">${a}<\/script>
<script>
const data = JSON.parse(document.getElementById("nf-plan").textContent);
const frame = document.getElementById("nf");
addEventListener("message", (e) => {
if (e.source === frame.contentWindow && e.data && e.data.type === "nextfloor-share-ready") frame.contentWindow.postMessage({ type: "nextfloor-share", building: data.building, packs: data.packs }, "*");
});
<\/script></body></html>
`}function Ap(t){let e;try{e=JSON.parse(t)}catch{throw new Error("not_json")}let n=e,r=n?.format===Sp?n.building:e;if(!$w(r))throw new Error("not_plan");return r.floors.forEach(i=>i.background=null),Oe(r)}var Mw=t=>!/^https?:\/\//.test(t)&&!t.startsWith("camera:");function Fp(t){let e=new Set;for(let n of t.floors){n.background?.image_id&&e.add(n.background.image_id);let r=n.furniture.flatMap(i=>i.pictures??[]);for(let{image:i}of r)i&&Mw(i)&&e.add(i)}return[...e]}function Tp(t,e,n="application/json"){let r=document.createElement("a"),i=URL.createObjectURL(new Blob([e],{type:n}));Object.assign(r,{href:i,download:t}),r.click(),setTimeout(()=>URL.revokeObjectURL(i),1e3)}var Ew={api:{listHistory:Uu,restoreSnapshot:Xu,takeSnapshot:Zu,getSnapshot:qu,deleteSnapshot:Yu,fetchBackup:Qu,restoreBackup:eh,fetchImage:$o,storeImage:Wt},alert:t=>alert(t),confirm:t=>confirm(t),prompt:t=>prompt(t),download:Tp,today:()=>new Date().toISOString().slice(0,10)},Rw=t=>String(t?.message??t),Zo=class{host;deps;history=null;busy=!1;compare=null;constructor(e,n=Ew){this.host=e,this.deps=n}async loadHistory(){let{hass:e}=this.host;e&&(this.history=await this.deps.api.listHistory(e).catch(()=>[]),this.host.refresh())}timeOf(e){return new Date(e.saved_at*1e3).toLocaleString(this.host.hass?.language,{dateStyle:"short",timeStyle:"short"})}async restorePoint(e){let{hass:n,t:r}=this.host;!n||!this.deps.confirm(r("backup_restore_confirm",{time:this.timeOf(e)}))||(await this.deps.api.restoreSnapshot(n,e.id),this.host.say(r("backup_restored")),await this.loadHistory())}async saveVersion(){let{hass:e,t:n}=this.host,r=e?this.deps.prompt?.(n("version_name_prompt"))?.trim():null;!e||!r||(await this.deps.api.takeSnapshot(e,r.slice(0,60)),this.host.say(n("version_saved",{name:r})),await this.loadHistory())}async compareWith(e){let{hass:n}=this.host,r=this.deps.api.getSnapshot;if(!n||!r)return;if(this.compare?.snapshot.id===e.id)return this.compare=null,this.host.refresh();let i=Oe(await r(n,e.id));this.compare={snapshot:e,entries:up(i,this.host.doc)},this.host.refresh()}async deleteVersion(e){let{hass:n,t:r}=this.host,i=this.deps.api.deleteSnapshot;!n||!i||!this.deps.confirm(r("version_delete_confirm",{name:e.name??this.timeOf(e)}))||(await i(n,e.id),this.compare?.snapshot.id===e.id&&(this.compare=null),await this.loadHistory())}exportShareView(){let e=this.host.t,n=Rp(this.host.doc,zr(),e("share_view_title"),e("share_view_needs_js"));this.deps.download(`nextfloor-${e("share_view_file")}-${this.deps.today()}.html`,n,"text/html"),this.host.say(e("share_view_done"))}exportPlan(e){let n=this.host.t(e?"export_name_template":"export_name_backup");this.deps.download(`nextfloor-${n}-${this.deps.today()}.json`,JSON.stringify(Ep(this.host.doc,e),null,2))}async importPlan(e){let{hass:n,t:r}=this.host;if(!e||!n)return;let i,o=r("backup_import_confirm");try{if(/\.sh3d$/i.test(e.name)){let s=await mp(new Uint8Array(await e.arrayBuffer()));i=s.building,o=`${r("import_sh3d_found",{...s.report})}
${o}`}else if(/\.ifc$/i.test(e.name)){let s=kp(await e.text());i=s.building,o=`${r("import_ifc_found",{floors:s.report.floors,rooms:s.report.rooms})}
${o}`}else if(/\.dxf$/i.test(e.name)){let s=_p(await e.text());i=s.building,o=`${r("import_dxf_found",{rooms:s.report.rooms,walls:s.report.walls})}
${o}`}else{let s=await e.text(),a=null;try{a=JSON.parse(s)}catch{}if(yp(a)){let l=vp(a);i=l.building,o=`${r("import_roomplan_found",{rooms:l.report.rooms,openings:l.report.openings,skipped:l.report.furniture})}
${o}`}else i=Ap(s)}}catch(s){let a=s.message,l={not_json:"import_error_not_json",not_plan:"import_error_not_plan",not_zip:"import_error_sh3d",sh3d_no_xml:"import_error_sh3d",sh3d_empty:"import_error_sh3d_empty",dxf_empty:"import_error_dxf_empty",ifc_empty:"import_error_ifc_empty",roomplan_empty:"import_error_roomplan_empty"};this.deps.alert(l[a]?r(l[a]):r("backup_import_error",{error:a}));return}this.deps.confirm(o)&&(await this.deps.api.takeSnapshot(n).catch(()=>{}),this.host.adopt(i),this.host.say(r("backup_imported")))}async exportFull(){let{hass:e,t:n}=this.host;if(e){this.busy=!0,this.host.refresh();try{let r=await this.deps.api.fetchBackup(e),i={};for(let o of Fp(r.building))await this.deps.api.fetchImage(e,o).then(s=>i[o]=s,()=>{});this.deps.download(`nextfloor-${n("export_name_full")}-${this.deps.today()}.json`,JSON.stringify({...r,exported_at:new Date().toISOString(),images:i}))}catch(r){this.deps.alert(n("backup_import_error",{error:Rw(r)}))}finally{this.busy=!1,this.host.refresh()}}}async importFull(e){let{hass:n,t:r}=this.host;if(!e||!n)return;let i;try{i=JSON.parse(await e.text())}catch{this.deps.alert(r("import_error_not_json"));return}if(i?.format!=="nextfloor-backup"||!i.building){this.deps.alert(r("backup_full_not_backup"));return}if(this.deps.confirm(r("backup_full_confirm"))){this.busy=!0,this.host.refresh();try{let o=await this.deps.api.restoreBackup(n,i.building,i.packs??[]),s=0;for(let[l,c]of Object.entries(i.images??{}))await this.deps.api.storeImage(n,l,c).then(()=>s++,()=>{});this.host.adopt(Oe(o.building)),this.host.packsChanged();let a=o.skipped.length>0?` ${r("backup_full_skipped",{packs:o.skipped.map(l=>l.id).join(", ")})}`:"";this.host.say(r("backup_full_restored",{packs:o.packs,pictures:s})+a)}catch(o){let{code:s,message:a}=o??{};this.deps.alert(r("backup_import_error",{error:a??s??String(o)}))}finally{this.busy=!1,this.host.refresh()}}}};var zp=(t,e,n="application/json,.json")=>m`<label class="nf-btn nf-upload"
>${t}<input
type="file"
accept=${n}
@change=${r=>{let i=r.target,o=i.files?.[0];i.value="",e(o)}}
/>
</label>`,Aw={added:"\uFF0B",removed:"\u2212",renamed:"\u270E",reshaped:"\u2922",moved:"\u2194"};function Fw(t,e){let n=t.t;if(!e.length)return m`<p class="nf-sub nf-diff">${n("version_same")}</p>`;let r=o=>o.kind.startsWith("furniture")?Te(t.hass,o.name)||o.name:o.kind.startsWith("device")?String(t.hass?.states[o.name]?.attributes.friendly_name??o.name):o.kind.startsWith("opening")?n(o.name==="door"?"opening_door":o.name==="garage"?"opening_garage":"opening_window"):o.name,i=[...new Set(e.map(o=>o.floor))];return m`<div class="nf-diff">
${S(n("version_diff_n",{n:e.length}))}
${i.map(o=>m`<h4 class="nf-check-floor">${o}</h4>
<ul class="nf-diff-list">
${e.filter(s=>s.floor===o).map(s=>{let a=s.kind.slice(s.kind.indexOf("_")+1),l=typeof s.detail=="number"?`${s.detail>0?"+":""}${K(t.hass,s.detail,1)}`:s.detail??"";return m`<li><span aria-hidden="true">${Aw[a]??"\u2022"}</span> ${n(`diff_${s.kind}`,{name:r(s),detail:l})}</li>`})}
</ul>`)}
</div>`}function Pp(t,e){let n=t.t,r=e.history,i=r===null?S(n("loading")):r.length===0?S(n("backup_none")):m`<div class="nf-room-list">
${r.map(o=>m`<div class="nf-row nf-dev-row">
<span>${o.name?m`<b>📌 ${o.name}</b> · `:_}${e.timeOf(o)} <span class="nf-muted">· ${n("backup_summary",{rooms:o.rooms,furniture:o.furniture})}</span></span>
<span class="nf-version-actions">
<button class="nf-link" aria-pressed=${e.compare?.snapshot.id===o.id} @click=${()=>{e.compareWith(o)}}>${n("version_compare")}</button>
<button class="nf-link" @click=${()=>e.restorePoint(o)}>${n("backup_restore")}</button>
${o.name?m`<button class="nf-link" title=${n("delete")} @click=${()=>{e.deleteVersion(o)}}>✕</button>`:_}
</span>
</div>
${e.compare?.snapshot.id===o.id?Fw(t,e.compare.entries):_}`)}
</div>`;return m`<details class="nf-section" @toggle=${o=>o.target.open&&void e.loadHistory()}>
<summary>${n("backup")}</summary>
<h4 class="nf-lib-head">${n("backup_history")}</h4>
${Q(m`<button class="nf-btn" title=${n("version_save_hint")} @click=${()=>{e.saveVersion()}}>📌 ${n("version_save")}</button>`)}
${i}
<h4 class="nf-lib-head">${n("backup_file")}</h4>
${Q(m`<button class="nf-btn" @click=${()=>e.exportPlan(!1)}>${n("backup_export")}</button>`,m`<button class="nf-btn" title=${n("backup_export_share_hint")} @click=${()=>e.exportPlan(!0)}>${n("backup_export_share")}</button>`,m`<button class="nf-btn" title=${n("share_view_hint")} @click=${()=>e.exportShareView()}>🔗 ${n("share_view")}</button>`,zp(n("backup_import"),o=>{e.importPlan(o)},"application/json,.json,.sh3d,.dxf,.ifc"))}
${S(n("backup_hint"))} ${S(n("import_other_hint"))}
<h4 class="nf-lib-head">${n("backup_full")}</h4>
${Q(m`<button class="nf-btn" ?disabled=${e.busy} @click=${()=>e.exportFull()}>${e.busy?"\u2026":n("backup_full_export")}</button>`,zp(n("backup_full_import"),o=>{e.importFull(o)}))}
${S(n("backup_full_hint"))}
</details>`}function Ip(t,e){return t.states["weather.nextfloor_symcon"]?"weather.nextfloor_symcon":e&&t.states[e]?e:Object.keys(t.states).filter(n=>n.startsWith("weather.")).sort()[0]??null}var Dp=["body","wood","fabric","white","metal","dark"],Op={body:"#172238",wood:"#19233c",fabric:"#1a2644",white:"#1d2946",metal:"#2a3a60",dark:"#0b111f"};var xn=(t,e,n)=>Math.min(n,Math.max(e,t)),Tw=t=>(Math.round(t)%360+360)%360,gl=(t,e)=>Tw(t+e);function Hp(t,e,n){return n?[...new Set([...t,e])]:t.filter(r=>r!==e)}function Lp(t,e,n){let r=t.t,i=s=>()=>n(gl(e,s)),o=E`<svg class="nf-compass-dial" viewBox="-50 -50 100 100" role="img" aria-label=${r("compass_title")}>
<circle r="46" class="nf-compass-ring" />
<path d="M0 -50l3 6h-6z" class="nf-compass-up" />
<g transform="rotate(${e})">
<path d="M0 -38L8 0H-8z" class="nf-compass-n" />
<path d="M0 38L8 0H-8z" class="nf-compass-s" />
<text y="-27" class="nf-compass-label">${r("compass_n_short")}</text>
<text y="36" class="nf-compass-label nf-compass-label-s">${r("compass_s_short")}</text>
</g>
</svg>`;return m`<div class="nf-compass nf-wide">
${o}
<div class="nf-compass-side">
<b>${r("compass_title")}</b>
${R(t,r("north"),e,s=>n(gl(s,0)),1)}
<div class="nf-actions">
<button class="nf-btn" ?disabled=${!t.admin} title=${r("compass_swap_hint")} @click=${i(180)}>⇅ ${r("compass_swap")}</button>
<button class="nf-btn" ?disabled=${!t.admin} @click=${i(-90)}>↺ 90°</button>
<button class="nf-btn" ?disabled=${!t.admin} @click=${i(90)}>↻ 90°</button>
</div>
${S(r("compass_hint"))}
</div>
</div>`}var zw="https://tile.openstreetmap.org/{z}/{x}/{y}.png";var Pw=40075016686e-3,_l=Math.PI/180,xi=18,ki=.5,Iw=160;function Dw(t,e,n){let r=2**n,i=(e+180)/360*r,o=(1-Math.log(Math.tan(t*_l)+1/Math.cos(t*_l))/Math.PI)/2*r;return[i,o]}var Ow=(t,e)=>Pw*Math.cos(t*_l)/2**e;function Cp(t,e,n,r=Iw){let[i,o]=Dw(t,e,n),s=Ow(t,n),a=r/s,l=2**n-1,c=[];for(let d=Math.floor(o-a);d<=Math.floor(o+a);d++)for(let u=Math.floor(i-a);u<=Math.floor(i+a);u++){if(d<0||d>l)continue;let p=(u%(l+1)+l+1)%(l+1);c.push({x:p,y:d,z:n,east:(u-i)*s,north:-(d-o)*s,size:s})}return c}function Np(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 Bp=t=>t.url&&t.url.startsWith("https://")?t.url:zw;var qo=t=>!!t&&t.on===!0&&Number.isFinite(t.lat)&&Number.isFinite(t.lon),Vp=t=>({x:t.x??0,z:t.z??0,opacity:t.opacity??ki,zoom:t.zoom??xi});function Hw(t){let e=[],n=[];for(let i of t.floors){for(let o of i.rooms)for(let[s,a]of o.points)e.push(s),n.push(a);for(let o of i.outdoor??[])for(let[s,a]of o.points)e.push(s),n.push(a)}if(!e.length)return[0,0];let r=i=>Math.round((Math.min(...i)+Math.max(...i))/2*100)/100;return[r(e),r(n)]}function Wp(t,e){let[n,r]=Hw(t);return{on:!0,lat:e?.lat??0,lon:e?.lon??0,x:n,z:r,opacity:ki,zoom:xi,url:null}}function Kp(t,e,n){let r=i=>Math.round(i*100)/100;return{...t,x:r((t.x??0)+e),z:r((t.z??0)+n)}}function jp(t){let e=t.trim();return e===""?null:/^https:\/\/\S+$/.test(e)&&["{z}","{x}","{y}"].every(n=>e.includes(n))?e:void 0}var Lw=["15","16","17","18","19"],Cw=["1","5","20"],Yo="5";function Gp(t,e,n){let r=t.t,i=e.settings.map??null,o=t.hass?.config,s=qo(i),a=d=>{if(!d)return n(i?{...i,on:!1}:null);n(i?{...i,on:!0}:Wp(e,{lat:o?.latitude,lon:o?.longitude}))},l=d=>i&&n({...i,...d}),c=(d,u)=>()=>i&&n(Kp(i,d*Number(Yo),u*Number(Yo)));return m`<div class="nf-map-settings nf-wide">
${D(t,r("map_on"),s,a,{title:r("map_hint")})}
${i&&i.on?m`<div class="nf-form">
${R(t,r("map_lat"),i.lat,d=>l({lat:Math.max(-85,Math.min(85,d))}),1e-4)}
${R(t,r("map_lon"),i.lon,d=>l({lon:Math.max(-180,Math.min(180,d))}),1e-4)}
${o?.latitude!==void 0&&o.longitude!==void 0?m`<button class="nf-btn nf-wide" ?disabled=${!t.admin} @click=${()=>l({lat:o.latitude,lon:o.longitude})}>${r("map_use_ha")}</button>`:_}
${R(t,r("map_opacity"),Math.round((i.opacity??ki)*100),d=>l({opacity:Math.max(5,Math.min(100,d))/100}),5,5)}
${H(t,r("map_zoom"),String(i.zoom??xi),Lw.map(d=>[d,d==="15"?`${d} \xB7 ${r("map_zoom_coarse")}`:d==="19"?`${d} \xB7 ${r("map_zoom_fine")}`:d]),d=>l({zoom:Number(d)}))}
<div class="nf-wide nf-map-move">
<span class="nf-sub">${r("map_move")}</span>
<div class="nf-map-arrows">
<button class="nf-btn" ?disabled=${!t.admin} title=${r("map_move")} @click=${c(0,-1)}>▲</button>
<button class="nf-btn" ?disabled=${!t.admin} title=${r("map_move")} @click=${c(-1,0)}>◀</button>
<button class="nf-btn" ?disabled=${!t.admin} title=${r("map_move")} @click=${c(1,0)}>▶</button>
<button class="nf-btn" ?disabled=${!t.admin} title=${r("map_move")} @click=${c(0,1)}>▼</button>
</div>
${H(t,r("map_step"),Yo,Cw.map(d=>[d,`${d} m`]),d=>Yo=d,{wide:!1})}
</div>
${W(t,r("map_url"),i.url??"",d=>{let u=jp(d);u!==void 0&&l({url:u})},{wide:!0,placeholder:"https://\u2026/{z}/{x}/{y}.png",maxlength:300})}
${S(r("map_hint"),"nf-wide")}
</div>`:_}
</div>`}var Nw=["none","flat","gable","custom"];function Bw(t,e,n){let r=t.t,i=!!e,o=s=>n({color:null,image:null,dim:.35,...e??{},...s});return m`<div class="nf-sub nf-wide">${r("backdrop")}</div>
${D(t,r("backdrop"),i,s=>n(s?{color:"#101828",image:null,dim:.35}:null))}
${i?m`<label class="nf-field"
>${r("backdrop_color")}
<input type="color" .value=${e?.color??"#101828"} ?disabled=${!t.admin} @change=${s=>o({color:s.target.value})}
/></label>
${R(t,r("backdrop_dim"),Math.round((e?.dim??.35)*100),s=>o({dim:xn(s,0,80)/100}),5,0)}
${W(t,r("backdrop_image"),e?.image??"",s=>o({image:s||null}),{wide:!0,placeholder:"/local/hintergrund.jpg"})}
${S(r("backdrop_hint"),"nf-wide")}`:_}`}function Vw(t,e,n){let r=t.t,i=O(t.hass,o=>!e.includes(o)&&/^(sensor|binary_sensor|alarm_control_panel|weather|input_|counter|lock|climate|person|sun)\b/.test(o));return m`<div class="nf-sub nf-wide">${r("status_entities")}</div>
${e.length?m`<div class="nf-chips nf-wide">
${e.map(o=>m`<span class="nf-chip">${B(t.hass,o)}
${t.admin?m`<button class="nf-chip-x" title=${r("delete")} aria-label=${`${r("delete")}: ${B(t.hass,o)}`} @click=${()=>n(e.filter(s=>s!==o))}>×</button>`:_}</span
>`)}
</div>`:_}
${e.length<12?z(t,r("status_add"),null,void 0,i,o=>o&&o!=="none"&&n([...e,o]),{excluded:o=>e.includes(o)?"Diese Variable ist in der Statusanzeige bereits verkn\xFCpft.":void 0}):_}
${S(r("status_entities_hint"),"nf-wide")}`}function Up(t,e){let n=t.t,r=t.doc.settings,i=c=>t.replace({...structuredClone(t.doc),settings:{...structuredClone(t.doc.settings),...c}}),o=c=>i({roof:{...r.roof,...c}}),s=Nw.map(c=>[c,n(`roof_${c}`)]),a=r.weather_effects??zd,l=r.roof.type==="gable";return m`<details class="nf-section">
<summary>${n("settings")}</summary>
<div class="nf-form">
${R(t,n("wall_exterior"),r.wall_exterior,c=>i({wall_exterior:xn(c,.02,1)}),.01,.02)}
${R(t,n("wall_interior"),r.wall_interior,c=>i({wall_interior:xn(c,.02,1)}),.01,.02)}
${Ge(t,n("wall_paint_outside"),r.wall_paint_outside,no,c=>i({wall_paint_outside:c}))}
${Ge(t,n("wall_paint_inside"),r.wall_paint_inside,ro,c=>i({wall_paint_inside:c}))}
${S(n("wall_paint_hint"),"nf-wide")}
${Dp.map(c=>Ge(t,n(`furn_color_${c}`),r.furniture_colors?.[c],Op[c],d=>{let u={...r.furniture_colors,[c]:d};d||delete u[c],i({furniture_colors:Object.keys(u).length?u:null})}))}
${S(n("furn_color_hint"),"nf-wide")}
${R(t,n("grid"),r.grid,c=>i({grid:xn(c,.01,1)}),.01,.01)}
${H(t,n("units"),r.units==="imperial"?"imperial":"metric",[["metric",n("units_metric")],["imperial",n("units_imperial")]],c=>i({units:c==="imperial"?"imperial":null}),{title:n("units_hint")})}
${Lp(t,r.north,c=>i({north:c}))}
${Gp(t,t.doc,c=>i({map:c}))}
${H(t,n("roof"),r.roof.type,s,c=>c==="custom"?e.useRoofSections():o({type:c}),{wide:!0})}
${l?H(t,n("roof_ridge"),r.roof.ridge==="short"?"short":"long",[["long",n("roof_ridge_long")],["short",n("roof_ridge_short")]],c=>o({ridge:c==="short"?"short":null}),{wide:!0}):_}
${l?R(t,n("roof_pitch"),r.roof.pitch,c=>o({pitch:xn(c,5,60)}),1,5):_}
${r.roof.type!=="none"?R(t,n("roof_overhang"),r.roof.overhang,c=>o({overhang:xn(c,0,2)}),.05,0):_}
${Z(t.hass)?Yh(t,r,i):t.hass?z(t,n("weather_entity"),r.weather_entity??null,Ip(t.hass,null),O(t.hass,c=>c.startsWith("weather.")),c=>i({weather_entity:c})):_}
<div class="nf-sub nf-wide">${n("weather_effects")}</div>
${Td.map(c=>D(t,n(`weather_effect_${c}`),a.includes(c),d=>i({weather_effects:Hp(a,c,d)}),{wide:!1}))}
${D(t,n("rain_warning"),r.rain_warning!==!1,c=>i({rain_warning:c}))}
${t.hass&&!Z(t.hass)&&r.rain_warning!==!1?z(t,n("rain_sensor"),r.rain_sensor??null,void 0,O(t.hass,c=>/^(binary_sensor|sensor)\./.test(c)),c=>i({rain_sensor:c==="none"?null:c})):_}
${t.hass&&!Z(t.hass)&&r.rain_warning!==!1&&r.rain_sensor&&r.rain_sensor!=="none"?D(t,n("rain_sensor_inverted"),!!r.rain_sensor_inverted,c=>i({rain_sensor_inverted:c||void 0}),{title:n("rain_sensor_inverted_hint")}):_}
${t.hass?z(t,n("outage_sensor"),r.outage_sensor??null,void 0,O(t.hass,c=>/^(binary_sensor|sensor)\./.test(c)),c=>i({outage_sensor:c==="none"?null:c})):_}
${S(n("outage_hint"),"nf-wide")}
${D(t,n("contact_warning"),!!r.contact_warning,c=>i({contact_warning:c||void 0}),{title:n("contact_warning_hint")})}
${D(t,n("night_lock_warning"),!!r.night_lock_warning,c=>i({night_lock_warning:c||void 0}),{title:n("night_lock_warning_hint")})}
${H(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=>i({room_double_tap:c==="plan"||c==="off"?c:null}),{title:n("room_double_tap_hint")})}
${D(t,n("motion_markers_active"),!!r.motion_markers_active,c=>i({motion_markers_active:c||void 0}),{title:n("motion_markers_active_hint")})}
${t.hass?Vw(t,r.status_entities??[],c=>i({status_entities:c.length?c:null})):_}
${Z(t.hass)?_:m`${t.hass?z(t,n("announce_tts"),r.announce_tts??null,void 0,O(t.hass,c=>c.startsWith("tts.")),c=>i({announce_tts:c==="none"?null:c})):_}
<label class="nf-field nf-wide"
>${n("announce_phrases")}
<textarea
rows="4"
?disabled=${!t.admin}
.value=${(r.announce_phrases??[]).join(`
`)}
placeholder=${[1,2,3,4,5].map(c=>n(`announce_phrase_${c}`)).join(`
`)}
@change=${c=>{let d=c.target.value.split(`
`).map(u=>u.trim().slice(0,200)).filter(Boolean).slice(0,30);i({announce_phrases:d.length?d:null})}}
></textarea>
</label>
${S(n("announce_phrases_hint"),"nf-wide")}`}
${D(t,n("sun_patches"),r.sun_patches!==!1,c=>i({sun_patches:c}),{title:n("sun_patches_hint")})}
${D(t,n("sun_arc"),r.sun_arc===!0,c=>i({sun_arc:c}),{title:n("sun_arc_hint")})}
${Bw(t,r.backdrop??null,c=>i({backdrop:c}))}
</div>
${S(Z(t.hass)?n("north_hint"):`${n("north_hint")} ${n("weather_entity_hint")}`)}
</details>`}function Zp(t,e){let n=t.floors.flatMap(f=>f.furniture.map(g=>({floor:f,item:g}))),r=f=>n.filter(g=>g.item.type===f),i=f=>!!xo(f.item,e),o=f=>({kind:"device",...f}),[s,a,l,c,d]=[t.settings.roof.solar??[],r("meter"),r("inverter"),r("home_battery"),r("grid_point")],u=!!t.energy.grid||a.some(i),p=!!t.energy.solar||l.length>0&&l.every(i),h=!!t.energy.battery||c.every(f=>i(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"}},a.length>0?{state:u?"ok":"todo",label:u?"chk_meter":"chk_meter_sensor",target:o(a[0])}:{state:"todo",label:"chk_meter_add",target:{kind:"add-device",type:"meter"}},l.length>0?{state:p?"ok":"todo",label:p?"chk_inverter":"chk_inverter_sensor",target:o(l.find(f=>!i(f))??l[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:o(c[0])}:{state:"opt",label:"chk_battery_opt",target:{kind:"add-device",type:"home_battery"}},d.length>0?{state:"ok",label:"chk_grid",target:o(d[0])}:{state:"opt",label:"chk_grid_opt",target:{kind:"add-device",type:"grid_point"}}]}function $i(t,e){let n=[];for(let r of t.floors)for(let i of r.furniture)i.type===e&&n.push({id:i.id,floorId:r.id,x:i.x,z:i.z,y:Math.max(.4,Math.min(1.4,i.h*.8))});return n}function Ww(t){if(!t?.rooms.length)return null;let e=0,n=0,r=0;for(let i of t.rooms)for(let[o,s]of i.points)e+=o,n+=s,r++;return r?{floorId:t.id,x:e/r,z:n/r,y:1}:null}function Kw(t){let e=Jn(t);return $i(t,"meter").find(n=>!e.has(n.id))??$i(t,"inverter")[0]??Ww(Eo(t))}function jw(t,e){let n=$i(t,"grid_point")[0];if(n)return n;let r=t.floors.find(a=>a.id===e.floorId);if(!r?.rooms.length)return null;let i=1/0,o=-1/0,s=-1/0;for(let a of r.rooms)for(let[l,c]of a.points)i=Math.min(i,l),o=Math.max(o,l),s=Math.max(s,c);return{floorId:e.floorId,x:Math.max(i,Math.min(o,e.x)),z:s+3,y:.2}}function qp(t){let e=[],n=Kw(t);if(!n)return e;let r=new Set(t.floors.flatMap(o=>o.furniture).filter(o=>hi(t,o)).map(o=>o.id)),i=$i(t,"inverter").find(o=>!r.has(o.id));for(let o of t.settings.roof.solar??[])e.push({key:`solar:${o.id}`,kind:"solar",id:o.id});$i(t,"home_battery").some(o=>!r.has(o.id))&&e.push({key:"battery",kind:"battery",id:null}),i&&(i.floorId!==n.floorId||i.x!==n.x||i.z!==n.z)&&e.push({key:"inverter",kind:"inverter",id:null}),jw(t,n)&&e.push({key:"grid",kind:"grid",id:null});for(let o of t.floors.flatMap(s=>s.furniture))r.has(o.id)&&(o.type==="inverter"?e.push({key:`inverter:${o.id}`,kind:"inverter",id:o.id}):o.type==="home_battery"&&e.push({key:`battery:${o.id}`,kind:"battery",id:o.id}));for(let o of Jn(t))e.push({key:`meter:${o}`,kind:"meter",id:o});return e}var Yp=(t,e)=>t.energy.routes?.find(n=>n.key===e&&n.points.length>0);var Gw={ok:"\u2713",todo:"\u25CB",opt:"\xB7"},Jp=t=>t.hass?Re(t.hass,t.doc.floors):new Map,Uw=Ke,Qp=(t,e)=>e.name||t.t(`furn_${e.type}`);function ef(t,e){let n=Zp(t.doc,Jp(t)),r=n.filter(i=>i.state==="ok").length;return m`<section class="nf-checklist">
<h3>☑ ${t.t("chk_title")} <span class="nf-sub">${r}/${n.length}</span></h3>
${S(t.t("chk_hint"))}
${n.map(i=>m`<button class="nf-chk nf-chk-${i.state}" ?disabled=${!t.admin&&i.state!=="ok"} @click=${()=>e.follow(i.target)}>
<span>${Gw[i.state]}</span>${t.t(i.label)}
</button>`)}
</section>`}function tf(t,e){let n=t.doc.floors.flatMap(r=>r.furniture.filter(i=>Uw.includes(i.type)).map(i=>({floor:r,item:i})));return m`<section>
<h3>⚡ ${t.t("energy_devices")}</h3>
${S(t.t("energy_devices_hint"))}
${n.length>0?m`<div class="nf-room-list">
${n.map(({floor:r,item:i})=>m`<div class="nf-row">
<button class="nf-dev-name" @click=${()=>e.openDevice(r,i)}><span>${Qp(t,i)} · ${r.name}</span></button>
</div>`)}
</div>`:_}
<div class="nf-actions">
${Ke.map(r=>m`<button class="nf-btn" ?disabled=${!t.admin||!t.floor} @click=${()=>e.addDevice(r)}>+ ${t.t(`furn_${r}`)}</button>`)}
</div>
</section>`}var Xp=(t,e,n)=>m`<p class="nf-sub nf-pack-error">${t.t(e)} <button class="nf-btn" ?disabled=${!t.admin} @click=${n}>${t.t("energy_sign_flip")}</button></p>`;function nf(t,e){let{energy:n}=t.doc,r=(y,v)=>t.hass?.states[y]?.attributes[v],i=O(t.hass,y=>Nn(t.hass,y)),o=O(t.hass,y=>ge(y)&&r(y,"device_class")==="battery"),s=O(t.hass,y=>ge(y)&&(r(y,"device_class")==="monetary"||/\/(kWh|MWh)$/.test(r(y,"unit_of_measurement")??""))),a=Jp(t),l=Oo(t.doc,y=>xo(y,a)),c=y=>t.replace({...structuredClone(t.doc),energy:{...t.doc.energy,...y}}),d=O(t.hass,y=>ge(y)&&["gas","water","volume_flow_rate"].includes(r(y,"device_class")??"")),u=y=>v=>c({[y]:v==="none"?null:v}),p=t.hass?il(t.hass,t.doc,[],l):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,b=(y,v)=>D(t,t.t("energy_invert"),y,w=>c(v(w)));return m`<section>
<h3>⚖ ${t.t("energy_balance")}</h3>
${S(t.t("energy_balance_hint"))}
${f?Xp(t,"energy_sign_grid",()=>c({grid_invert:!n.grid_invert})):_}
${g?Xp(t,"energy_sign_battery",()=>c({battery_invert:!n.battery_invert})):_}
<div class="nf-form">
${z(t,t.t("energy_grid"),n.grid,l.grid,i,u("grid"))}
${b(n.grid_invert,y=>({grid_invert:y}))}
${z(t,t.t("energy_solar_sensor"),n.solar,l.solar[0]??null,i,u("solar"))}
${z(t,t.t("energy_battery_sensor"),n.battery,l.battery[0]??null,i,u("battery"))}
${b(n.battery_invert,y=>({battery_invert:y}))}
${z(t,t.t("energy_battery_soc"),n.battery_soc,l.soc[0]??null,o,u("battery_soc"))}
${z(t,t.t("energy_consumption_sensor"),n.consumption,null,i,u("consumption"))}
${z(t,t.t("energy_tariff_sensor"),n.tariff,void 0,s,u("tariff"))}
${z(t,t.t("energy_gas"),n.gas??null,void 0,d,u("gas"))}
${z(t,t.t("energy_water"),n.water??null,void 0,d,u("water"))}
${S(t.t("energy_meters_hint"),"nf-wide")}
</div>
<div class="nf-actions"><button class="nf-btn" ?disabled=${!t.admin||!t.hass} @click=${()=>e.importPrefs()}>${t.t("energy_import_prefs")}</button></div>
${e.note?S(e.note):_} ${S(t.t("energy_hint"))}
</section>
<section>
<h3>⚙ ${t.t("energy_advanced")}</h3>
${S(t.t("energy_advanced_hint"))}
<div class="nf-form">
${D(t,t.t("energy_advanced_on"),!!n.advanced,y=>c({advanced:y}))}
${n.advanced?D(t,t.t("energy_show_unmetered"),!!n.show_unmetered,y=>c({show_unmetered:y})):_}
</div>
${n.advanced?S(t.t("energy_show_unmetered_hint")):_}
</section>`}var rf=t=>m`<section class="nf-teaser nf-teaser-on">
<div class="nf-teaser-head"><b>⚡ ${t.t("feature_name_energy")}</b></div>
${S(t.t("feature_text_energy"))}
</section>`;function of(t){let e=(n,r,i)=>m`<a class="nf-btn" href="https://github.com/therealMRBK/NextFloor/${n}" target="_blank" rel="noopener">${r} ${t.t(i)}</a>`;return m`<section class="nf-help">
<h3>${t.t("help_title")}</h3>
${S(t.t("help_hint"))}
<div class="nf-actions">${e("issues/new/choose","\u{1F41E}","help_issue")}${e("discussions/categories/ideas","\u{1F4A1}","help_idea")}</div>
</section>`}function Zw(t,e){let n=t.t,r=t.doc.floors.flatMap(o=>o.furniture).find(o=>o.id===e.id),i=r?Qp(t,r):"";switch(e.kind){case"solar":{let o=t.doc.settings.roof.solar??[],s=o.findIndex(a=>a.id===e.id);return n("route_conn_solar",{name:o[s]?.name||`${n("solar_field")} ${s+1}`})}case"battery":return e.id?n("route_conn_device",{name:i}):n("route_conn_battery");case"inverter":return e.id?n("route_conn_device",{name:i}):n("route_conn_inverter");case"grid":return n("route_conn_grid");case"meter":return n("route_conn_meter",{name:i})}}function sf(t,e){let n=qp(t.doc);if(!n.length)return _;let r=t.t,i=e.draft;return m`<section>
<h3>〰 ${r("energy_routes")}</h3>
${S(r("energy_routes_hint"))}
<div class="nf-room-list">
${n.map(o=>{let s=Yp(t.doc,o.key),a=i?.key===o.key;return m`<div class="nf-row nf-route-row">
<span class="nf-dev-name"><span>${Zw(t,o)} · ${s?r("route_points",{n:s.points.length}):r("route_none")}</span></span>
${a?m`<p class="nf-sub nf-wide">${r("route_drawing",{n:i.points.length})}</p>
<div class="nf-actions nf-wide">
<button class="nf-btn" ?disabled=${!i.points.length} @click=${()=>e.undoPoint()}>↶ ${r("route_undo")}</button>
<button class="nf-btn nf-primary" @click=${()=>e.finish()}>${r("route_done")}</button>
<button class="nf-btn" @click=${()=>e.cancel()}>${r("cancel")}</button>
</div>`:m`<div class="nf-actions">
<button class="nf-btn" ?disabled=${!t.admin||!!i} @click=${()=>e.start(o.key)}>✎ ${r(s?"route_redraw":"route_draw")}</button>
${s?m`<button class="nf-btn" ?disabled=${!t.admin||!!i} @click=${()=>e.clear(o.key)}>⨉</button>`:_}
</div>
${s?D(t,r("route_cable"),!!s.cable,l=>e.setCable(o.key,l),{title:r("route_cable_hint")}):_}`}
</div>`})}
</div>
</section>`}var lt=(t,e)=>e.map(n=>t.toScreen(n).join(",")).join(" ");function Xo(t,e,n,r,i,o){let[[s,a],[l,c]]=[t.toScreen(e),t.toScreen(n)];if(Math.hypot(l-s,c-a)<=36)return _;let[d,u]=[(s+l)/2,(a+c)/2];return E`<g data-plus=${`${r}:${i}:${o}`} class="nf-mid"><circle cx=${d} cy=${u} r="14" class="nf-hit" /><circle cx=${d} cy=${u} r="6" /><path d="M${d-3} ${u}h6M${d} ${u-3}v6" /></g>`}var af=(t,e)=>E`<circle cx=${t} cy=${e} r="16" class="nf-hit" /><circle cx=${t} cy=${e} r="6" />`,qw=(t,e,n)=>E`<g class="nf-vertex" data-roof-vertex=${n}>${af(...t.toScreen(e))}</g>`,Yw=(t,e,n)=>E`<g class="nf-vertex" data-roof-corner=${n}>${af(...t.toScreen(e))}</g>`;function Xw(t,e,n,r){let{t:i,hass:o}=t.host,s=n.dormer?i("roof_dormer"):n.open?i("roof_open_short"):i(`roof_shape_${n.shape}`);return`${e.isFixed(n)?"\u{1F512} ":""}${r+1} \xB7 ${s} \xB7 ${K(o,un(n),1)} m`}function bl(t,e){let n=t.host.doc.settings.roof,r=n.type==="custom"?n.sections??[]:[],i=t.host.admin,o=(s,a)=>{let l=s.id===e.sectionId,c=$e(s),d=(s.shape==="flat"||s.shape==="parapet")&&s.points&&s.points.length>=3?s.points:null,u=Mo(r,s),p=u?$e(Pa(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:hn(s,{u0:0,u1:0,a:0,b:0}))?.ridges??[]).map(([N,V])=>{let[X,ke]=t.toScreen(c.at(N[0],N[1])),[Ft,j]=t.toScreen(c.at(V[0],V[1]));return E`<line x1=${X} y1=${ke} x2=${Ft} y2=${j} />`}),[b,y]=t.toScreen(c.at((c.u0+c.u1)/2,c.w/2)),v=l&&i&&!e.isFixed(s),w=[[0,0],[1,0],[1,1],[0,1]],k=s.shape==="flat"||s.shape==="parapet",[x,M,A,T]=[Math.min(s.x0,s.x1),Math.max(s.x0,s.x1),Math.min(s.z0,s.z1),Math.max(s.z0,s.z1)],F=d??(s.rotation?Wr(s):[[x,A],[M,A],[M,T],[x,T]]),L=v&&k?F.map((N,V)=>Xo(t,N,F[(V+1)%F.length],"roof",s.id,V)):_,I=v?E`${L}${d?d.map((N,V)=>qw(t,N,`${s.id}:${V}`)):w.map(([N,V])=>Yw(t,[N?M:x,V?T:A],`${s.id}:${N}:${V}`))}`:_;return E`<g data-roof=${s.id} class=${`nf-roof-sec${l?" nf-roof-sel":""}`}>
<polygon points=${lt(t,h)} />
<g class="nf-roof-ridge">${g}</g>
<text x=${b} y=${y-14}>${Xw(t,e,s,a)}</text>
</g>${I}`};return E`<g class="nf-roof-layer">${r.map(o)}</g>`}function Jw(t,e,n,r,i){let o=r*Math.PI/180,[s,a]=t.toScreen(n),[l,c]=t.toScreen([n[0]+Math.sin(o)*i,n[1]-Math.cos(o)*i]);return E`<g class="nf-rotate" data-solar-turn=${e}>
<line x1=${s} y1=${a} x2=${l} y2=${c} />
<circle cx=${l} cy=${c} r="16" class="nf-hit" />
<circle cx=${l} cy=${c} r="8" />
<path d="M${l-4} ${c-1}a4 4 0 1 1 2 3.5" />
</g>`}function lf(t,e){let{doc:n,admin:r}=t.host,i=n.settings.roof.solar??[];if(i.length===0)return _;let o=Y(n),s=a=>{let l=Se(n,a,o);if(!l||l.wall&&l.wall.floorId!==t.floorId)return _;let c=a.id===e.solarId,d=_;if(c&&l.unbounded&&r&&!a.locked){let h=ei(l,a),f=Math.max(...Xe(l,a,!0).flatMap(g=>g.corners.map(b=>Math.hypot(b[0]-h[0],b[2]-h[1]))));d=Jw(t,a.id,h,a.rotation??0,.9+f*.5)}let u=h=>{let f;if(l.wall){let g=Math.max(.3,...h.corners.map(w=>(w[0]-l.o[0])*l.n[0]+(w[2]-l.o[2])*l.n[2])),[b,y]=[h.corners[0],h.corners[1]],v=w=>[w[0]+l.n[0]*g,w[2]+l.n[2]*g];f=[[b[0],b[2]],v(b),v(y),[y[0],y[2]]]}else f=h.corners.map(g=>[g[0],g[2]]);return E`<polygon data-cell=${h.cell} class=${h.skipped?"nf-solar-off":""} points=${lt(t,f)} />`},p=`nf-solar${c?" nf-solar-sel":""}${c&&e.picking?" nf-solar-pick":""}`;return E`<g data-solar=${a.id} class=${p}>${Xe(l,a,c).map(u)}</g>${d}`};return E`<g class="nf-solar-layer">${i.map(s)}</g>`}function cf(t,e){let n=t.host.doc.settings.roof.windows??[];if(n.length===0)return _;let r=new Map(Y(t.host.doc).map(o=>[o.key,o])),i=o=>{let s=r.get(o.face),a=s?Va(s,o):null;return a?E`<g data-roofwin=${o.id} class=${`nf-roofwin${o.id===e.windowId?" nf-roofwin-sel":""}`}><polygon points=${lt(t,a.map(l=>[l[0],l[2]]))} /></g>`:_};return E`<g class="nf-roofwin-layer">${n.map(i)}</g>`}var Qw={inverter:"\u26A1",home_battery:"\u{1F50B}",wallbox:"\u{1F50C}",meter:"\u{1F4DF}",grid_point:"\u{1F3C1}"};function df(t,e,n){if(!e)return _;let r=e.furniture.filter(o=>Ke.includes(o.type)),i=o=>{let[s,a]=t.toScreen([o.x,o.z]),l=o.id===n,c=t.host.t(`furn_${o.type}`);return E`<g data-energy-device=${o.id} class=${`nf-energy-marker${l?" nf-energy-marker-sel":""}`}>
<circle cx=${s} cy=${a} r="17" />
<text x=${s} y=${a+6} class="nf-energy-icon">${Qw[o.type]??"\u26A1"}</text>
${l?E`<text x=${s} y=${a+32} class="nf-energy-name">${c}</text>`:_}
<title>${c}</title>
</g>`};return E`<g class="nf-energy-markers">${r.map(i)}</g>`}function uf(t,e){let{doc:n,hass:r}=t.host;if(!(n.settings.roof.sections??[]).some(s=>Da(s,e.elevation+e.height)))return _;let o=[1.5,2].flatMap(s=>Oa({settings:n.settings},e.elevation,s).map(([a,l])=>{let[c,d]=t.toScreen(a),[u,p]=t.toScreen(l);return E`<line class="nf-headroom" x1=${c} y1=${d} x2=${u} y2=${p} />
<text class="nf-headroom-label" x=${(c+u)/2} y=${(d+p)/2-4}>${K(r,s,1)} m</text>`}));return E`${o}`}function hf(t,e,n,r){if(!e)return _;let i=(o,s)=>{let a=[];return o.forEach((l,c)=>{if(l.floor_id!==e.id)return;let[d,u]=t.toScreen([l.x,l.z]),p=o[c+1];if(p?.floor_id===e.id){let[f,g]=t.toScreen([p.x,p.z]);a.push(E`<line x1=${d} y1=${u} x2=${f} y2=${g} />`)}let h=p&&p.floor_id!==e.id||c>0&&o[c-1].floor_id!==e.id;a.push(E`<circle cx=${d} cy=${u} r=${h?7:4} class=${h?"nf-route-riser":""} />`),s&&a.push(E`<text x=${d+8} y=${u-8}>${c+1}</text>`)}),E`<g class=${`nf-route${s?" nf-route-drawing":""}`}>${a}</g>`};return E`<g class="nf-routes">${n.filter(o=>o.key!==r?.key).map(o=>i(o.points,!1))}${r?i(r.points,!0):_}</g>`}function pf(t,e){let n=t.host.doc.settings.roof.chimneys??[];if(n.length===0)return _;let r=new Map(Y(t.host.doc).map(o=>[o.key,o])),i=o=>{let s=r.get(o.face);if(!s)return _;let{shape:a,w:l,d:c}=bn(o),{center:d,along:u,across:p}=Wa(s,o),h=a==="round"||a==="steel"?Array.from({length:16},(f,g)=>[d[0]+Math.cos(g/16*2*Math.PI)*Math.min(l,c)/2,d[1]+Math.sin(g/16*2*Math.PI)*Math.min(l,c)/2]):[[-1,-1],[1,-1],[1,1],[-1,1]].map(([f,g])=>[d[0]+u[0]*l*f/2+p[0]*c*g/2,d[1]+u[1]*l*f/2+p[1]*c*g/2]);return E`<g data-chimney=${o.id} class=${`nf-chimney${o.id===e.chimneyId?" nf-roofwin-sel":""}`}><polygon points=${lt(t,h)} /></g>`};return E`<g class="nf-roofwin-layer">${n.map(i)}</g>`}function e0(t,e,n){let[r,i]=[t+n/2,e-30];return E`<g class="nf-rotate" data-bg-rotate="1">
<line x1=${r} y1=${e} x2=${r} y2=${i} />
<circle cx=${r} cy=${i} r="16" class="nf-hit" />
<circle cx=${r} cy=${i} r="8" />
<path d="M${r-4} ${i-1}a4 4 0 1 1 2 3.5" />
</g>`}function t0(t,e){let n=e.level?.length?e.level:e.ruler;if(!n?.length)return _;let r=n.map(i=>t.toScreen(i));return E`<g class="nf-bg-ruler">
${r.length===2?E`<line x1=${r[0][0]} y1=${r[0][1]} x2=${r[1][0]} y2=${r[1][1]} />`:_}
${r.map(([i,o])=>E`<circle cx=${i} cy=${o} r="6" />`)}
</g>`}function ff(t,e,n){let r=n?.background,i=e.picture(r?.image_id);if(!r||!i)return _;let[o,s]=t.toScreen([r.x,r.z]),a=r.width*t.scale,l=a*i.aspect,c=e.handlesShown;return E`<g transform="rotate(${r.rotation??0} ${o+a/2} ${s+l/2})">
<image href=${i.url} x=${o} y=${s} width=${a} height=${l} opacity=${r.opacity} preserveAspectRatio="none" pointer-events=${c?"auto":"none"} data-bg="1" style=${c?"cursor:move":""} />
${c?E`<rect class="nf-bg-frame" x=${o} y=${s} width=${a} height=${l} />
<circle class="nf-bg-handle" data-bg-handle="1" cx=${o+a} cy=${s+l} r="9" />
${e0(o,s,a)}`:_}
</g>${t0(t,e)}`}var n0="strict-origin-when-cross-origin",yl=new Map,mf=new Map,Jo=new Map;function r0(t){let e=yl.get(t);return e||(e=fetch(t,{referrerPolicy:n0,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(()=>yl.delete(t),6e4),n)),yl.set(t,e)),e}function gf(t,e){let n=mf.get(t);if(n)return n;let r=Jo.get(t);return r||(r=new Set,Jo.set(t,r),r0(t).then(i=>{i&&mf.set(t,URL.createObjectURL(i));let o=Jo.get(t)??new Set;if(Jo.delete(t),i)for(let s of o)s()})),r.add(e),null}function _f(t,e){let n=e.map;if(!qo(n))return _;let r=Vp(n),i=Bp(n),[o,s]=t.toScreen([r.x,r.z]),a=t.scale;return E`<g class="nf-map" opacity=${r.opacity} pointer-events="none" transform="translate(${o} ${s}) rotate(${e.north??0})">
${Cp(n.lat,n.lon,r.zoom).map(l=>({tile:l,href:gf(Np(i,l),t.redraw)})).filter(l=>l.href).map(({tile:l,href:c})=>E`<image href=${c} x=${l.east*a} y=${-l.north*a} width=${l.size*a+.6} height=${l.size*a+.6} preserveAspectRatio="none" />`)}
</g>`}var vl=t=>Math.round(t*1e3)/1e3,wl=(t,e)=>t.width*e,ir=(t,e)=>[t.x+t.width/2,t.z+wl(t,e)/2];function bf(t,e,n){let[r,i]=[t[0]-e[0],t[1]-e[1]];return[e[0]+r*Math.cos(n)-i*Math.sin(n),e[1]+r*Math.sin(n)+i*Math.cos(n)]}var yf=t=>((t+180)%360+360)%360-180;function vf(t,e,n){return{x:vl(t[0]-e/2),z:vl(t[1]-n/2)}}function wf(t,e,n,r){if(Math.hypot(r[0]-n[0],r[1]-n[1])<.05)return null;let i=Math.atan2(r[1]-n[1],r[0]-n[0]),o=Math.round(i/(Math.PI/2))*(Math.PI/2)-i;if(Math.abs(o)<1e-4)return null;let s=bf(ir(t,e),n,o),a=Math.round(yf((t.rotation??0)+o*180/Math.PI)*100)/100;return{...t,rotation:a,...vf(s,t.width,wl(t,e))}}function xf(t,e,n,r,i){let o=Math.hypot(r[0]-n[0],r[1]-n[1]);if(!(i>0)||o<1e-4)return null;let s=i/o,[a,l]=ir(t,e),c=[n[0]+s*(a-n[0]),n[1]+s*(l-n[1])],d=t.width*s;return{...t,width:vl(d),...vf(c,d,wl(t,e)*s)}}function kf(t,e,n){let r=bf(n,ir(t,e),-(t.rotation??0)*Math.PI/180);return[r[0]-t.x,r[1]-t.z]}function $f(t,e,n,r){let i=t+(n-e)*180/Math.PI;return yf(r?Math.round(i/15)*15:Math.round(i*10)/10)}var i0=2048;async function or(t){let e=await createImageBitmap(t),n=Math.min(1,i0/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 Qo=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 i=await r.fetchImage(n.hass,e),o=await this.aspectOf(i);this.pictures={...this.pictures,[e]:{url:i,aspect:o}},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:i,aspect:o}=await this.deps.readPicture(e),s=P("img");await r.storeImage(n.hass,s,i),this.pictures={...this.pictures,[s]:{url:i,aspect:o}};let a=n.floor?.rooms??[],l=a.length>0?ue(a.flatMap(d=>d.points)):null,c={image_id:s,x:l?l.x0:0,z:l?l.z0:0,width:l?Math.max(4,Math.round((l.x1-l.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,i=this.picture(r?.image_id),o=r&&i?wf(r,i.aspect,e,n):null;o&&this.setBackground(o)}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 i=xf(e,n.aspect,r[0],r[1],this.rulerMetres);i&&(this.setBackground(i),this.rulerPoints=null,this.rulerMetres=0,this.deps.refresh())}};var Sf=.1,xl=(t,e,n)=>m`<button class="nf-btn nf-wide ${t?"nf-primary":""}" aria-pressed=${t} @click=${n}>${e}</button>`;function o0(t,e){let n=e.ruler;if(!n)return _;if(n.length<2)return S(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]),i=()=>e.applyRuler();return m`${S(t.t("bg_ruler_length_hint",{m:K(t.hass,r,2)}),"nf-wide")}
<label class="nf-field"
>${t.t("bg_ruler_length")}
<input
type="number"
min="0.01"
step="0.01"
.value=${e.rulerLength?String(e.rulerLength):""}
@input=${o=>e.rulerLength=ka(o.target.value)||0}
@keydown=${o=>o.key==="Enter"&&i()}
/>
</label>
<button class="nf-btn nf-primary" ?disabled=${!(e.rulerLength>0)} @click=${i}>${t.t("bg_ruler_apply")}</button>`}function s0(t,e){if(!t.admin)return _;let n=t.t,r=e.level;return m`${xl(e.edit,n(e.edit?"background_edit_done":"background_edit"),()=>e.toggleEdit())}
${S(n(e.edit?"background_handles_hint":"background_fixed_hint"),"nf-wide")}
${xl(!!r,`\u{1F4D0} ${n(r?"bg_level_cancel":"bg_level")}`,()=>e.toggleLevel())}
${r?S(n(r.length>0?"bg_level_second":"bg_level_first"),"nf-wide"):_}
${xl(!!e.ruler,`\u{1F4CF} ${n(e.ruler?"bg_ruler_cancel":"bg_ruler")}`,()=>e.toggleRuler())}
${o0(t,e)}`}function Mf(t,e,n){let r=n.background,i=t.t,o=s=>r&&e.setBackground({...r,...s});return m`<details class="nf-section" ?open=${e.open} @toggle=${s=>e.open=s.target.open}>
<summary>${i("background")}</summary>
<div class="nf-form">
<label class="nf-btn nf-wide nf-upload"
>${i("background_upload")}<input
type="file"
accept="image/png,image/jpeg,image/webp"
@change=${s=>{let a=s.target,l=a.files?.[0];a.value="",e.upload(l)}}
/>
</label>
${r?m`${R(t,i("x"),r.x,s=>o({x:s}))} ${R(t,i("z"),r.z,s=>o({z:s}))}
${R(t,i("background_width"),r.width,s=>o({width:Math.max(Sf,s)}),.01,Sf)}
${R(t,i("background_rotation"),r.rotation??0,s=>o({rotation:Math.round(s*10)/10}),.5)}
${s0(t,e)}
<label class="nf-field"
>${i("background_opacity")}
<input type="range" min="0.05" max="1" step="0.05" .value=${String(ae(r.opacity))} @change=${s=>o({opacity:Number.parseFloat(s.target.value)})} />
</label>
<button class="nf-btn nf-danger nf-wide" @click=${()=>e.setBackground(null)}>${i("background_remove")}</button>`:_}
</div>
</details>`}var a0=t=>t.map((e,n)=>[e,t[(n+1)%t.length]]);function l0(t,e,n){let r=G(n,e),i=te(r,r),o=i?Math.max(0,Math.min(1,te(G(t,e),r)/i)):0;return _e(G(t,[e[0]+r[0]*o,e[1]+r[1]*o]))}function Ef(t,e,n=.03){return t.every(r=>C(r,e)||a0(e).some(([i,o])=>l0(r,i,o)<=n))}var kl=["straight","quarter","l","half","u","spiral"],$l=["solid","stringer","mono","cantilever"],Sl=["none","left","right","both"],Ml=["headroom","full","none"],_t={shape:"straight",turn:"right",build:"solid",risers:!0,steps:null,run_width:null,down:!1,rail:"none",opening:"headroom",landing_after:null},El={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]},zf=2,Pf=40;var es=(t,e)=>typeof e=="string"&&t.includes(e);function Ri(t){let e=t.stair??{},n=typeof e.steps=="number"&&Number.isFinite(e.steps)?Math.round(Math.min(Pf,Math.max(zf,e.steps))):null,r=typeof e.run_width=="number"&&Number.isFinite(e.run_width)&&e.run_width>.2?e.run_width:null;return{shape:es(kl,e.shape)?e.shape:_t.shape,turn:e.turn==="left"?"left":"right",build:es($l,e.build)?e.build:_t.build,risers:e.risers!==!1,steps:n,run_width:r,down:e.down===!0,rail:es(Sl,e.rail)?e.rail:_t.rail,opening:es(Ml,e.opening)?e.opening:_t.opening,landing_after:typeof e.landing_after=="number"&&Number.isFinite(e.landing_after)?Math.max(1,Math.round(e.landing_after)):null}}var Mi=(t,e,n)=>[t[0]+(e[0]-t[0])*n,t[1]+(e[1]-t[1])*n],Rf=(t,e)=>Math.abs(t[0]-e[0])<1e-6&&Math.abs(t[1]-e[1])<1e-6;function If(t){let e=[];for(let n of t)(!e.length||!Rf(e[e.length-1],n))&&e.push(n);for(;e.length>1&&Rf(e[0],e[e.length-1]);)e.pop();return e}function Ei(t,e,n=!1){return{poly:If([...t,...[...e].reverse()]),landing:n,left:t,right:e}}function Si(t,e,n,r,i){let o=[];for(let s=0;s<i;s++){let[a,l]=[s/i,(s+1)/i];o.push(Ei([Mi(t,n,a),Mi(t,n,l)],[Mi(e,r,a),Mi(e,r,l)]))}return o}function Af(t,e){let n=e;for(let r=0;r+1<t.length;r++){let i=Math.hypot(t[r+1][0]-t[r][0],t[r+1][1]-t[r][1]);if(n<=i||r+2===t.length)return Mi(t[r],t[r+1],i?Math.min(1,n/i):0);n-=i}return t[t.length-1]}function c0(t,e,n){let r=[Af(t,e)],i=0;for(let o=0;o+1<t.length;o++)i+=Math.hypot(t[o+1][0]-t[o][0],t[o+1][1]-t[o][1]),i>e+1e-6&&i<n-1e-6&&r.push(t[o+1]);return r.push(Af(t,n)),r}var d0=t=>t.reduce((e,n,r)=>r?e+Math.hypot(n[0]-t[r-1][0],n[1]-t[r-1][1]):e,0);function Ff(t,e,n,r,i){let o=d0(t),s=[];for(let a=0;a<i;a++){let l=If([...a===0?[e]:[],n,...a===i-1?[r]:[]]);s.push(Ei(c0(t,o*a/i,o*(a+1)/i),l.length?l:[n]))}return s}function ts(t,e,n){if(t<=0)return[0,0];if(e<=.001)return[0,t];if(n<=.001)return[t,0];let r=Math.min(t,Math.max(0,Math.round(t*e/(e+n))));return[r,t-r]}function Tf(t,e){if(t.landing_after==null)return null;let n=Math.min(e-1,Math.max(1,Math.round(t.landing_after)))-1;return[n,e-1-n]}function u0(t,e,n,r){let[i,o,s,a]=[-e/2,e/2,-n/2,n/2];switch(t.shape){case"quarter":case"l":{let l=Math.min(t.run_width??Math.min(1,Math.min(e,n)/2),Math.min(e,n)-.05),c=[i+l,s+l],d=[[i,s+l],[i,s],[i+l,s]],u=t.shape==="l"?1:Math.min(r,r>=8?3:2),[p,h]=t.shape==="l"?Tf(t,r)??ts(r-u,n-l,e-l):ts(r-u,n-l,e-l),f=Si([i,a],[i+l,a],[i,s+l],c,p),g=t.shape==="l"?[Ei(d,[c],!0)]:Ff(d,c,c,c,u),b=Si([i+l,s],c,[o,s],[o,s+l],h);return{treads:[...f,...g,...b],flight:l,column:0}}case"half":case"u":{let l=Math.min(t.run_width??Math.min(1.1,(e-.1)/2),(e-.02)/2),c=s+l,d=[[i,c],[i,s],[o,s],[o,c]],[u,p]=[[i+l,c],[o-l,c]],h=t.shape==="u"?1:Math.min(r,r>=12?6:r>=8?4:2),[f,g]=t.shape==="u"?Tf(t,r)??ts(r-h,n-l,n-l):ts(r-h,n-l,n-l),b=Si([i,a],[i+l,a],[i,c],u,f),y=t.shape==="u"?[Ei(d,[u,p],!0)]:Ff(d,u,[0,c],p,h),v=Si([o,c],p,[o,a],[o-l,a],g);return{treads:[...b,...y,...v],flight:l,column:0}}case"spiral":{let l=Math.min(e,n)/2,c=Math.min(.08,l*.12),d=Math.min(.75,Math.max(.3,.22/(l*.6))),u=(h,f)=>[Math.cos(f)*h,Math.sin(f)*h],p=[];for(let h=0;h<r;h++){let[f,g]=[Math.PI+d*h,Math.PI+d*(h+1)],b=[0,.5,1].map(y=>u(l,f+(g-f)*y));p.push(Ei(b,[u(c,f),u(c,g)]))}return{treads:p,flight:l-c,column:c}}default:return{treads:Si([i,a],[o,a],[i,s],[o,s],r),flight:e,column:0}}}var h0=(t,e)=>t.steps??Math.min(Pf,Math.max(zf,Math.round(Math.abs(e)/.18)));function kn(t,e,n,r){let i=h0(t,r),o=Math.abs(r)/i,s=u0(t,Math.max(.3,e),Math.max(.3,n),i),a=c=>[-c[0],c[1]];return{treads:s.treads.map((c,d)=>{let u=t.down?-o*(d+1):o*(d+1);return t.turn==="right"?{...c,top:u}:{poly:c.poly.map(a).reverse(),top:u,landing:c.landing,left:c.right.map(a),right:c.left.map(a)}}),rise:o,steps:i,column:s.column,flight:s.flight}}function ns(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 ne=t=>Math.round(t*1e3)/1e3,p0=(t,e)=>((t+e)%360+360)%360;function Df(t,e){return{id:P("wall"),a:[ne(t[0]),ne(t[1])],b:[ne(e[0]),ne(e[1])],thickness:null}}function Of(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[ne(t.a[0]+(t.b[0]-t.a[0])*r),ne(t.a[1]+(t.b[1]-t.a[1])*r)]}var Hf=(t,e)=>({height:t>=e-.005?null:Math.max(.05,t)});function Lf(t,e){return{id:P("hole"),type:"stairwell",x:ne((t[0]+e[0])/2),z:ne((t[1]+e[1])/2),w:ne(e[0]-t[0]),d:ne(e[1]-t[1]),h:.02,rotation:0,variant:null}}var Cf=t=>({id:P("outdoor"),type:"lawn",points:t.map(([e,n])=>[ne(e),ne(n)])});function Nf(t,e,n){t.points.splice(e+1,0,[ne(n[0]),ne(n[1])])}function Bf(t,e){return t.points.length<=3||e<0||e>=t.points.length?!1:(t.points.splice(e,1),!0)}var Vf=t=>({...t,id:P("outdoor"),points:t.points.map(([e,n])=>[ne(e+.5),ne(n+.5)])});function Rl(t,e,n,r){let[i,o,s]=ut(t),a=e.floors.filter(d=>d.elevation>n.elevation).sort((d,u)=>d.elevation-u.elevation)[0],l=t==="stairs"?ne(a?a.elevation-n.elevation:n.height+.25):s,c={id:P("furniture"),type:t,x:ne(r[0]),z:ne(r[1]),rotation:0,w:i,d:o,h:l,variant:null};return Qn(t)&&(c.hydronic=al(t)),t==="stairs"&&(c.stair={..._t}),c}var Wf=t=>({...structuredClone(t),id:P("furniture"),x:ne(t.x+.3),z:ne(t.z+.3)}),Kf=(t,e)=>p0(t,e);function jf(t){let[e,n,r]=ut("parking");return{id:P("furniture"),type:"parking",x:t.x,z:t.z,rotation:t.rotation,w:Math.max(e,ne(t.w+.5)),d:Math.max(n,ne(t.d+.4)),h:r,variant:null,vehicle:t.type,...t.name?{name:t.name}:{}}}function Gf(t,e){let[n,r,i]=ut(e);return{id:P("furniture"),type:e,x:t.x,z:t.z,rotation:t.rotation??0,w:n,d:r,h:i,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 Uf=(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 Zf(t,e){for(let n of t.floors)n.placements=n.placements.filter(r=>r.entity_id!==e),n.furniture=n.furniture.filter(r=>!(de(r.type)&&r.entity===e))}function Al(t,e,n,r){let i=new Set(r);for(let s of t.floors)s.placements=s.placements.filter(a=>!i.has(a.entity_id)),s.furniture=s.furniture.filter(a=>!(de(a.type)&&a.entity&&i.has(a.entity)));let o=[...e.placements.map(s=>[s.x,s.z]),...e.furniture.filter(s=>de(s.type)).map(s=>[s.x,s.z])];for(let s of $u(n,r,o)){if(!s.entity_id.startsWith("light.")){e.placements.push(s);continue}let[a,l,c]=nt.lamp_ceiling;e.furniture.push({id:P("furniture"),type:"lamp_ceiling",x:s.x,z:s.z,rotation:0,w:a,d:l,h:c,variant:null,entity:s.entity_id,power:null})}}function qf(t){let[e,n]=ve(t.points);return[ne(e),ne(n)]}function Yf(t,e,n,r){let i=Math.min(n,t)/2,o=r>0?Math.round(e/r)*r:e;return ne(Math.min(t-i,Math.max(i,o)))}function Xf(t,e){let n=Pn[e],r=In(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 Jf(t,e,n){let r=ue(t.points),{x0:i,z0:o,x1:s,z1:a}=r;return e==="x"?[i,s]=[n,n+(s-i)]:e==="z"?[o,a]=[n,n+(a-o)]:e==="w"?s=i+Math.max(.1,n):a=o+Math.max(.1,n),[[i,o],[s,o],[s,a],[i,a]].map(([l,c])=>[ne(l),ne(c)])}function Qf(t){return t.furniture.map((e,n)=>({item:e,index:n,base:zt(t,e)})).sort((e,n)=>e.base-n.base||e.index-n.index).map(e=>e.item)}function rs(t,e,n){if(!t.admin)return _;let r=n.edit?.key===e;return m`<button class="nf-btn" aria-pressed=${r} title=${t.t("arc_hint")} @click=${()=>n.setEdit(r?null:{key:e,bulge:.5,error:null})}>
◠ ${t.t("arc")}
</button>`}function is(t,e,n){let r=n.edit;if(!t.admin||r?.key!==e)return _;let i=t.t;return m`<span class="nf-wide nf-split-row" title=${i("arc_bulge_hint")}
>${R(t,i("arc_bulge"),r.bulge,o=>n.setEdit({...r,bulge:o,error:null}),.05)}
<button class="nf-btn nf-primary" ?disabled=${Math.abs(r.bulge)<.01} @click=${()=>n.apply(r)}>${i("arc_apply")}</button></span
>
${r.error?m`<p class="nf-sub nf-wide nf-notice">${r.error}</p>`:_}`}var os=(t,e,n)=>Math.min(e,Math.max(t,ae(n)));function Fl(t,e,n){let r=t.t,i=c=>n.update(c),o=ue(e.points),s=to(e),a=Pd.map(c=>[c,r(`out_${c}`)]),l=Id.map(c=>[c,r(`slope_${c.replace("-","n")}`)]);return m`<section>
<div class="nf-h3row"><h3>${r("outdoor")}</h3>${n.lockButton}</div>
<div class="nf-form">
${H(t,r("outdoor_type"),e.type,a,c=>i({type:c}),{wide:!0})}
${R(t,r("outdoor_texture_scale"),s.scale*100,c=>{let{scale:d}=to({texture_scale:c/100});i({texture_scale:d===1?null:d})},5,5)}
${R(t,r("outdoor_texture_rotation"),s.rotation,c=>{let{rotation:d}=to({texture_rotation:c});i({texture_rotation:d||null})},5)}
${S(r("outdoor_texture_hint"))}
${H(t,r("area"),e.area_id??"",[["",r("no_area")],...Object.values(t.hass?.areas??{}).sort((c,d)=>c.name.localeCompare(d.name)).map(c=>[c.area_id,c.name])],c=>i({area_id:c||null}),{wide:!0,title:r("outdoor_area_hint")})}
${e.type==="pool"||e.type==="wild"||e.type==="bed"?m`${z(t,r("pool_temp"),e.temp_entity??null,void 0,O(t.hass,c=>c.startsWith("sensor.")&&t.hass?.states[c]?.attributes.device_class==="temperature"),c=>i({temp_entity:c&&c!=="none"?c:null}))}
${z(t,r("pool_pump"),e.pump_entity??null,void 0,O(t.hass,c=>/^(switch|fan|valve|input_boolean|binary_sensor)\./.test(c)),c=>i({pump_entity:c&&c!=="none"?c:null}))}`:_}
${Dn(e.points)?m`${R(t,r("x"),o.x0,c=>n.setRectangle("x",c))} ${R(t,r("z"),o.z0,c=>n.setRectangle("z",c))}
${R(t,r("width"),o.x1-o.x0,c=>n.setRectangle("w",c),.01,.1)} ${R(t,r("depth"),o.z1-o.z0,c=>n.setRectangle("d",c),.01,.1)}`:_}
${Zs(e.type)?R(t,r("outdoor_height"),e.height??Us[e.type],c=>i({height:os(.1,6,c)}),.05,.1):_}
${R(t,r("outdoor_offset"),e.offset??0,c=>i({offset:os(-10,10,c)||null}),.05)}
${e.type!=="pool"?m`${R(t,r("outdoor_slope"),e.slope??0,c=>i({slope:os(0,20,c)||null}),.05,0)}
${H(t,r("outdoor_slope_dir"),e.slope_dir??"x",l,c=>i({slope_dir:c}))}`:_}
${R(t,r("outdoor_opacity"),Math.round((e.opacity??1)*100),c=>i({opacity:c>=100||!(c>0)?null:Math.max(10,Math.min(95,c))/100}),5,10)}
${D(t,r("outdoor_outline"),e.outline!==!1,c=>i({outline:c?void 0:!1}),{title:r("outdoor_outline_hint")})}
${e.type==="fence"||e.type==="pergola"?D(t,r("outdoor_open"),!!e.open,c=>i({open:c||void 0}),{title:r("outdoor_open_hint")}):_}
${e.type==="pergola"?D(t,r("outdoor_bracing"),!!e.bracing,c=>i({bracing:c||void 0})):_}
${D(t,r("outdoor_cut"),qs(e),c=>i({cut:c===qs({...e,cut:void 0})?void 0:c}),{title:r("outdoor_cut_hint")})}
</div>
${e.type==="fence"?f0(t,e,i):_}
${t.admin?m`<div class="nf-actions">
${e.points.map((c,d)=>m`<button class="nf-chip" title=${r("delete_point")} ?disabled=${e.points.length<=3} @click=${()=>n.removeCorner(d)}>${d+1} ×</button>`)}
</div>
${S(r("outdoor_corners_hint"))}`:_}
${e.slope?S(r("outdoor_slope_hint")):_} ${S(r("outdoor_hint"))}
${t.admin?m`<div class="nf-actions"><button class="nf-btn" @click=${()=>n.duplicate()}>${r("duplicate")}</button><button class="nf-btn nf-danger" @click=${()=>n.remove()}>${r("delete")}</button></div>`:_}
</section>`}function f0(t,e,n){let r=t.t,i=e.gates??[],o=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}`]),a=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},l=(h,f)=>o(i.map((g,b)=>b===h?{...g,...f}:g)),c=O(t.hass,h=>/^(cover|switch|input_boolean|lock)\./.test(h)),d=O(t.hass,h=>h.startsWith("binary_sensor.")),u=[["single",r("gate_single")],["double",r("gate_double")],["sliding",r("gate_sliding")]],p=()=>{let f=a(0);o([...i,{id:P("gate"),edge:0,offset:ae(f/2),width:Math.min(1.2,Math.max(.5,ae(f*.4))),kind:"single"}])};return m`<h4 class="nf-lib-head">${r("fence_gates")}</h4>
${i.map((h,f)=>m`<div class="nf-form">
${H(t,r("gate_edge"),String(h.edge),s,g=>l(f,{edge:Number(g)}))}
${H(t,r("gate_kind"),h.kind,u,g=>l(f,{kind:g,width:g==="single"&&h.width>1.6?1:h.width}))}
${R(t,r("gate_offset"),h.offset,g=>l(f,{offset:Math.max(0,Math.min(a(h.edge),ae(g)))}),.05,0)}
${R(t,r("gate_width"),h.width,g=>l(f,{width:Math.max(.3,Math.min(12,ae(g)))}),.05,.3)}
${z(t,r("gate_entity"),h.entity??null,void 0,c,g=>l(f,{entity:g&&g!=="none"?g:null}))}
${z(t,r("gate_contact"),h.contact??null,void 0,d,g=>l(f,{contact:g&&g!=="none"?g:null}))}
${t.admin?m`<button class="nf-btn nf-danger nf-wide" @click=${()=>o(i.filter((g,b)=>b!==f))}>${r("delete")}</button>`:_}
</div>`)}
${t.admin&&i.length<20?m`<button class="nf-btn" @click=${p}>${r("gate_add")}</button>`:_}
${S(r("fence_gates_hint"))}`}var m0=[["up","\u2191"],["left","\u2190"],["right","\u2192"],["down","\u2193"]],g0={ArrowRight:"right",ArrowLeft:"left",ArrowUp:"up",ArrowDown:"down"};function em(t,e,n){let r=t.t,{draft:i}=e,o=u=>K(t.hass,u,2),[s,a]=[i[0],i[i.length-1]],l=s&&i.length>1?Math.hypot(a[0]-s[0],a[1]-s[1]):0,c=u=>{let p=g0[u.key];p?(u.preventDefault(),n.step(p)):u.key==="Enter"&&n.close()},d=s?m`${S(r("measure_from",{x:o(s[0]),z:o(s[1])}))}
<div class="nf-form">
<label class="nf-field nf-wide"
>${r("measure_length")}
<input class="nf-measure-input" type="number" inputmode="decimal" step="0.01" min="0.05" .value=${String(e.length)} @input=${u=>n.setLength(Number.parseFloat(u.target.value.replace(",","."))||0)} @keydown=${c} />
</label>
<div class="nf-arrows nf-wide">${m0.map(([u,p])=>m`<button class="nf-btn nf-arrow-${u}" title=${r(`dir_${u}`)} @click=${()=>n.step(u)}>${p}</button>`)}</div>
</div>
${i.length>1?m`<ol class="nf-measure-list">${i.slice(1).map((u,p)=>m`<li>${o(Math.hypot(u[0]-i[p][0],u[1]-i[p][1]))} m</li>`)}</ol>`:_}
<div class="nf-actions">
<button class="nf-btn nf-primary" ?disabled=${i.length<3} @click=${()=>n.close()}>${r("measure_close")}</button>
<button class="nf-btn" ?disabled=${i.length<2} @click=${()=>n.undo()}>${r("measure_undo")}</button>
</div>
${i.length>=3?S(r("measure_gap",{gap:o(l)})):_}`:S(r("measure_start"));return m`<section>
<h3>${r("measure")}</h3>
${d}
<h4 class="nf-lib-head">${r("rect_by_size")}</h4>
<div class="nf-form">
${R(t,r("width"),e.rectSize[0],u=>n.setRectSize([Math.max(.1,u),e.rectSize[1]]),.01,.1)}
${R(t,r("depth"),e.rectSize[1],u=>n.setRectSize([e.rectSize[0],Math.max(.1,u)]),.01,.1)}
<button class="nf-btn nf-wide" @click=${()=>n.addRectangle()}>${r("rect_add")}</button>
</div>
${S(r("measure_hint"))}
</section>`}function Tl(t,e,n){let r=t.t,i=t.floor?.height??2.5,o=Math.hypot(e.b[0]-e.a[0],e.b[1]-e.a[1]);return m`<section>
<div class="nf-h3row"><h3>${r("free_wall")}</h3>${n.lockButton}</div>
<div class="nf-form">
${R(t,r("wall_length"),o,s=>n.update({b:Of(e,s)}),.01,.1)}
${R(t,r("wall_thickness"),e.thickness??t.doc.settings.wall_interior,s=>n.update({thickness:os(.02,1,s)}),.01,.02)}
${R(t,r("wall_height"),e.height??i,s=>n.update(Hf(s,i)),.05,.05)}
${D(t,r("free_wall_slope"),e.height_end!=null,s=>n.update(s?{height:e.height??i,height_end:Math.max(.2,(e.height??i)/2)}:{height_end:null}),{title:r("free_wall_slope_hint")})}
${e.height_end!=null?R(t,r("free_wall_height_end"),e.height_end,s=>n.update({height_end:Math.max(.05,s)}),.05,.05):_}
</div>
${t.admin?m`<div class="nf-actions">${rs(t,`wall:${e.id}`,n.arc)}<button class="nf-btn nf-danger" @click=${()=>n.remove()}>${r("delete")}</button></div>`:_}
<div class="nf-form">${is(t,`wall:${e.id}`,n.arc)}</div>
${S(r("free_wall_hint"))}
</section>`}var Zt=t=>Math.round(t*1e3)/1e3,_0=2.4;function tm(t,e,n){let r=Ha(t,e[0],e[1],n[0],n[1]),i=r===null,o=Math.min(...t.floors.map(l=>l.elevation)),s=Zt(r??o+_0),a=i?6:t.settings.roof.pitch||35;return{id:P("roof"),x0:Zt(e[0]),z0:Zt(e[1]),x1:Zt(n[0]),z1:Zt(n[1]),shape:i?"pent":"gable",axis:n[0]-e[0]>=n[1]-e[1]?"x":"z",eave_a:s,eave_b:s,pitch_a:a,pitch_b:a,base:s,overhang:i?.15:null,...i?{open:!0}:{}}}function nm(t){let e=n=>Zt(n+1);return{...structuredClone(t),id:P("roof"),x0:e(t.x0),x1:e(t.x1),z0:e(t.z0),z1:e(t.z1)}}var rm=(t,e)=>t.findIndex(n=>n.id===e)+1;function zl(t){return t.points&&t.points.length>=3?t.points.map(([e,n])=>[e,n]):t.rotation?Wr(t):[[t.x0,t.z0],[t.x1,t.z0],[t.x1,t.z1],[t.x0,t.z1]]}function im(t,e,n){let r=zl(t);r.splice(e+1,0,[Zt(n[0]),Zt(n[1])]),t.points=r,Object.assign(t,jt(r))}function om(t,e){return!t.points||t.points.length<=3||e<0||e>=t.points.length?!1:(t.points.splice(e,1),Object.assign(t,jt(t.points)),!0)}var b0={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"},qt=t=>b0[t];function ss(t,e){let n=new Set;for(let r of t?.placements??[])C([r.x,r.z],e.points)&&n.add(r.entity_id);for(let r of t?.furniture??[])de(r.type)&&r.entity&&C([r.x,r.z],e.points)&&n.add(r.entity);return n}function sm(t,e){let n=new Map;for(let r of t.floors){let i=[...r.placements.map(o=>[o.entity_id,o.x,o.z]),...r.furniture.filter(o=>de(o.type)&&o.entity).map(o=>[o.entity,o.x,o.z])];for(let[o,s,a]of i){let l=r.rooms.find(c=>C([s,a],c.points));l&&l.id!==e.id&&n.set(o,l.name)}}return n}var am=(t,e)=>(t??[]).includes(e)?(t??[]).filter(n=>n!==e):[...t??[],e];function as(t,...e){let n=t.trim().toLowerCase();return!n||e.some(r=>(r??"").toLowerCase().includes(n))}function lm(t,e){return t.map(n=>({o:n,r:e(n.id)})).sort((n,r)=>n.r-r.r).map(({o:n})=>n)}function cm(t,e){let n=e,r=0;return{taken:t.map(o=>{let s=o.ids.slice(0,Math.max(0,n));return n-=s.length,r+=o.ids.length-s.length,[...s]}),left:r}}var Pl=50;function Il(t,e,n,r,i,o,s){let a=e.includes(n);return m`<button class="nf-pin ${a?"nf-pin-on":""}" aria-pressed=${a} title=${t.t(a?o[0]:o[1])} @click=${()=>s.patchRoom({[r]:am(e,n)})}>${a?i[0]:i[1]}</button>`}function y0(t,e,n,r,i,o){let[s,a,l]=[e.hidden??[],e.no_state??[],e.panel??[]];return(c,d=!1,u=i)=>{let p=n.has(c),h=p?void 0:r.get(c),f=s.includes(c),g=Vn(t,c);return m`<div class="nf-row nf-dev-row ${d?"nf-dev-extra":""} ${f?"nf-dev-hidden":""}">
<button class="nf-dev-name ${p?"":"nf-muted"}" ?disabled=${!p} @click=${()=>o.select(c)}>
${g?m`<ha-icon class="nf-dev-icon" style="--mdc-icon-size:16px" .icon=${g}></ha-icon>`:m`<svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d=${qt((t.hass?je(t.hass,c):ee(c))??"sensor")} /></svg>`}
<span>${B(t.hass,c,u)}${h?m`<small class="nf-muted"> · ${t.t("devices_placed_in",{room:h})}</small>`:_}</span>
</button>
${t.admin?Il(t,s,c,"hidden",["\u{1F648}","\u{1F441}"],["panel_unhide","panel_hide"],o):_}
${t.admin&&!f?Il(t,a,c,"no_state",["\u2205","Aa"],["panel_state_show","panel_state_hide"],o):_}
${t.admin&&!p?Il(t,l,c,"panel",["\u2605","\u2606"],["panel_unpin","panel_pin"],o):_}
${t.admin?p?m`<button class="nf-link" @click=${()=>o.remove(c)}>${t.t("devices_remove")}</button>`:m`<button class="nf-link" @click=${()=>o.place([c])}>${t.t("devices_place")}</button>`:_}
</div>`}}function v0(t,e,n,r,i){let{hass:o}=t;if(!o)return m``;let s=d=>d>0?S(t.t("devices_narrow",{n:d})):_,a=S(t.t("devices_none")),l=e.deviceQuery;if(i==="other"){let d=uu(o,n.area_id).map(f=>({...f,ids:f.ids.filter(g=>as(l,`${B(o,g,f.name)} ${g} ${f.name}`))})),{taken:u,left:p}=cm(d,Pl),h=d.map((f,g)=>u[g].length>0?m`<div class="nf-dev-area">${f.name}</div>${u[g].map(b=>r(b,!1,f.name))}`:_);return u.some(f=>f.length>0)?m`<div class="nf-room-list">${h}</div>${s(p)}`:a}let c=hu(o).filter(d=>as(l,`${B(o,d)} ${d} `));return c.length>0?m`<div class="nf-room-list">${c.slice(0,Pl).map(d=>r(d))}</div>${s(c.length-Math.min(c.length,Pl))}`:a}function w0(t,e,n,r,i,o,s){let{hass:a}=t,l=a?we(a,n).filter(y=>Dt(je(a,y))):[];if(!n.area_id)return S(t.t("devices_none_area"));if(l.length===0)return S(t.t("devices_none"));let c=a?Ln(a,l):[],d=c.map(y=>y.primary).filter(y=>!i.has(y)),u=e.deviceQuery,p=(t.floor?.placements??[]).filter(y=>ee(y.entity_id)==="light"&&(y.mount??"ceiling")==="ceiling"&&C([y.x,y.z],n.points)).length,h=m`<input class="nf-search" type="search" placeholder=${t.t("devices_search")} .value=${u} @input=${y=>e.deviceQuery=y.target.value} />`,f=y=>as(u,B(a,y,o),y),g=y=>{let v=y.others.filter(f),w=e.isUnfolded(y.primary)||!!u.trim()&&v.length>0;return!f(y.primary)&&v.length===0?_:m`${r(y.primary)}
${y.others.length>0?m`<button class="nf-more" @click=${()=>e.toggleUnfolded(y.primary)}>${w?t.t("devices_less"):t.t("devices_more",{n:y.others.length})}</button>`:_}
${w?(u.trim()?v:y.others).map(k=>r(k,!0)):_}`},b=()=>s.confirm(t.t("devices_place_all_confirm",{n:d.length}))&&s.place(d);return m`${t.admin&&p>=2?m`<button class="nf-btn nf-wide-btn" @click=${()=>s.spreadLights(n)}>${t.t("lights_spread")}</button>`:_}
${l.length>8?h:_}
<div class="nf-room-list">${c.map(g)}</div>
${t.admin&&d.length>1?m`<button class="nf-link nf-place-all" @click=${b}>${t.t("devices_place_all_n",{n:d.length})}</button>`:_}
${S(t.t("devices_hint"))}`}function Dl(t,e,n,r){let{hass:i}=t,o=n.area_id?i?.areas?.[n.area_id]?.name:void 0,s=ss(t.floor,n),a=y0(t,n,s,sm(t.doc,n),o,r),l=t.admin?e.deviceSource:"area",c=i?Ln(i,we(i,n).filter(p=>Dt(je(i,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`<input class="nf-search" type="search" placeholder=${t.t("devices_search")} .value=${e.deviceQuery} @input=${p=>e.deviceQuery=p.target.value} />`;return m`<section>
<h3>${t.t("devices")}</h3>
${S(t.t("devices_panel_hint"))}
${t.admin?m`<div class="nf-seg nf-dev-source">${d.map(([p,h])=>m`<button aria-pressed=${l===p} @click=${()=>e.deviceSource=p}>${h}</button>`)}</div>`:_}
${l!=="area"?m`${u}${v0(t,e,n,a,l)}`:w0(t,e,n,a,s,o,r)}
</section>`}function dm(t,e,n){let{hass:r}=t;if(!r)return _;let i=!!e.floor_heating||!!e.hvac||!!e.climate&&Object.values(e.climate).some(a=>a!=null),o=(a,l)=>{let c={...e.climate??{},[a]:l};n({climate:Object.values(c).every(d=>d==null)?null:c})},s=(a,l)=>{let c=pu(r,t.floor??null,{...e,climate:null},a),d=[e.climate?.[a]??null].flat(),u=O(r,b=>ha(r,b,a,!0)&&(!r.states[b]?.attributes.symcon_source_entity||d.includes(b))),p=lm(u,b=>(Ot(r,b)===e.area_id?0:1)+(pa(r,b)?0:2)),h=b=>{let y=b.filter(v=>!!v&&v!=="none");o(a,y.length>1?y:y[0]??(b.includes("none")?"none":null))},g=d[0]&&d[0]!=="none"?[...d,null]:d;return g.map((b,y)=>z(t,y?t.t("climate_more"):l,b,y?void 0:c[0]??null,p,v=>h(g.map((w,k)=>k===y?v:w)),{types:[1,2]}))};return m`<details class="nf-points" ?open=${i||!!e.climate_card}>
<summary>${t.t("climate")}</summary>
<div class="nf-form">${s("temperature",t.t("climate_temperature"))} ${s("humidity",t.t("climate_humidity"))} ${s("co2",t.t("climate_co2"))} ${s("illuminance",t.t("climate_illuminance"))}${Z(r)?qh(t,e,n):_}</div>
${D(t,t.t("climate_card"),!!e.climate_card,a=>n({climate_card:a||void 0}))}
${S(t.t("climate_card_hint"))}
${S(t.t("climate_hint"))}
</details>`}var Ol="metric",hm=t=>{Ol=t==="imperial"?"imperial":"metric"};var um=.3048;function pe(t,e,n=2,r=Ol){if(r==="metric")return`${K(t,e,n)} m`;let i=e<0?"\u2212":"",o=Math.round(Math.abs(e)/.0254*2),s=Math.floor(o/24),a=o-s*24,l=`${Math.floor(a/2)}${a%2?"\xBD":""}`;return s?`${i}${s}\u2032 ${l}\u2033`:`${i}${l}\u2033`}function Me(t,e,n=Ol){return n==="metric"?`${K(t,e,1)} m\xB2`:`${K(t,e/(um*um),0)} ft\xB2`}var x0=.15,k0=(t,e)=>Math.abs((t-e+540)%360-180);function $0(t,e,n,r){return t.rooms.some(i=>i.id!==e.id&&i.points.some((o,s)=>{let a=i.points[(s+1)%i.points.length];return Math.abs(te(G(o,n),r))<.02&&Math.abs(te(G(a,n),r))<.02}))}function Ll(t,e,n,r){let i=e.points,[o,s]=[i[n],i[(n+1)%i.length]],a=_e(G(s,o)),l=be(i)>=0?1:-1,c=[(s[0]-o[0])/a,(s[1]-o[1])/a],d=[-c[1]*l||0,c[0]*l||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(y=>y??h)):h,g=e.wall_slopes?.[n],b=typeof g=="number"&&typeof p=="number"?g:f;return{origin:u?o:s,along:u?c:[-c[0],-c[1]],normal:d,length:a,face:$0(t,e,o,d)?r/2:0,heightLeft:u?f:b,heightRight:u?b:f}}function Hl(t,e){let n=G(e,t.origin);return{u:te(n,t.along),depth:te(n,t.normal)-t.face}}function S0(t,e){let n=t.rooms.find(s=>s.id===e.room_id);if(!n||e.wall)return null;let[r,i]=[n.points[e.edge],n.points[(e.edge+1)%n.points.length]];if(!r||!i)return null;let o=_e(G(i,r))||1;return[r[0]+(i[0]-r[0])*e.offset/o,r[1]+(i[1]-r[1])*e.offset/o]}var pm=t=>U(t.type)?.mount==="wall"||t.type==="lamp_wall"||t.mount_y!=null;function fm(t,e,n){let r=[];for(let o of t.openings){let s=S0(t,o);if(!s)continue;let{u:a,depth:l}=Hl(n,s);Math.abs(l+n.face)>.3||a<-.01||a>n.length+.01||r.push({id:o.id,kind:"opening",type:o.type,x0:a-o.width/2,x1:a+o.width/2,y0:o.sill,y1:o.sill+o.height,lifts:o.type==="window"})}let i=Math.atan2(-n.normal[0],n.normal[1])*180/Math.PI;for(let o of t.furniture){if(!C([o.x,o.z],e.points)||k0(o.rotation,i)>20)continue;let{u:s,depth:a}=Hl(n,[o.x,o.z]);if(a-o.d/2>x0||s<0||s>n.length)continue;let l=zt(t,o);r.push({id:o.id,kind:"furniture",type:o.type,x0:s-o.w/2,x1:s+o.w/2,y0:l,y1:l+o.h,lifts:pm(o)})}return r.sort((o,s)=>+(o.kind==="furniture")-+(s.kind==="furniture")||o.x0-s.x0)}var Ai=t=>Math.round(t*1e3)/1e3;function mm(t,e,n,r){let i=Hl(t,[e.x,e.z]).depth,o=Math.min(t.length-e.w/2,Math.max(e.w/2,n+e.w/2)),s=[t.origin[0]+t.along[0]*o+t.normal[0]*(i+t.face),t.origin[1]+t.along[1]*o+t.normal[1]*(i+t.face)];return{x:Ai(s[0]),z:Ai(s[1]),...r!==null&&pm(e)?{mount_y:Ai(Math.max(0,r))}:{}}}function gm(t,e,n,r,i){let[o]=[e.points[n.edge]],s=Math.min(t.length-n.width/2,Math.max(n.width/2,r+n.width/2)),a=_e(G(o,t.origin))<1e-6?s:t.length-s;return{offset:Ai(a),...i!==null&&n.type==="window"?{sill:Ai(Math.max(0,i))}:{}}}var _m=.01,bm=t=>Math.round(t/_m)*_m,Cl=class extends q{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?Ll(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?fm(this.host.floor,e,n):[]}place(e,n,r){let i=this.room,o=this.frame();!i||!o||this.host.change((s,a)=>{if(e.kind==="furniture"){let l=a.furniture.find(c=>c.id===e.id);l&&Object.assign(l,mm(o,l,n,e.lifts?r:null))}else{let l=a.openings.find(d=>d.id===e.id),c=a.rooms.find(d=>d.id===l?.room_id);l&&c&&Object.assign(l,gm(c.id===i.id?o:Ll(a,c,l.edge,this.host.doc.settings.wall_interior),c,l,n,e.lifts?r:null))}})}toWall(e){let r=this.renderRoot.querySelector("svg").getScreenCTM()?.inverse();if(!r)return[0,0];let i=new DOMPoint(e.clientX,e.clientY).matrixTransform(r);return[i.x,-i.y]}down(e,n){if(this._sel=n.id,!this.host.admin)return;e.currentTarget.setPointerCapture(e.pointerId);let[r,i]=this.toWall(e);this._drag={id:n.id,x0:n.x0,y0:n.y0,startU:r,startY:i,fromX:n.x0,fromY:n.y0}}move(e,n){let r=this._drag;if(!r||r.id!==n.id)return;let[i,o]=this.toWall(e),s=this.frame(),a=n.x1-n.x0,l=Math.min((s?.length??0)-a,Math.max(0,bm(r.fromX+i-r.startU))),c=n.lifts?Math.max(0,bm(r.fromY+o-r.startY)):r.fromY;this._drag={...r,x0:l,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(i=>i.id===e.id)?.name||Te(this.host.hass,e.type);let n=this.host.floor?.openings.find(r=>r.id===e.id);return n?this.host.t(`preset_${In(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 i=n.points.length,o=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),a=Math.max(r.heightLeft,r.heightRight,...s.map(h=>h.y1)),l=.35,c=`${-l} ${-(a+l)} ${r.length+2*l} ${a+2*l+.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 E`<text x=${(h.x0+h.x1)/2} y=${-(h.y0+h.y1)/2} font-size=${f} text-anchor="middle" dominant-baseline="middle">${this.nameOf(h)}</text>`},p=d?E`<g class="dim">
<line x1="0" x2=${d.x0} y1=${-(d.y0+d.y1)/2} y2=${-(d.y0+d.y1)/2} />
<text x=${d.x0/2} y=${-(d.y0+d.y1)/2-.06} text-anchor="middle" font-size="0.11">${o(d.x0)}</text>
<line x1=${d.x1} x2=${r.length} y1=${-(d.y0+d.y1)/2} y2=${-(d.y0+d.y1)/2} />
<text x=${(d.x1+r.length)/2} y=${-(d.y0+d.y1)/2-.06} text-anchor="middle" font-size="0.11">${o(r.length-d.x1)}</text>
${d.y0>.005?E`<line x1=${(d.x0+d.x1)/2} x2=${(d.x0+d.x1)/2} y1="0" y2=${-d.y0} /><text x=${(d.x0+d.x1)/2+.05} y=${-d.y0/2} font-size="0.11">${o(d.y0)}</text>`:_}
</g>`:_;return m`<div class="backdrop" @click=${h=>h.target===h.currentTarget&&this.close()}>
<div class="sheet" role="dialog" aria-label=${e("wall_view")}>
<header>
<b>${e("wall_view")} · ${n.name||e("room")} · ${e("wall_n",{a:this.edge+1,b:(this.edge+1)%i+1})}</b>
<span class="muted">${o(r.length)}</span>
<span class="grow"></span>
<button aria-label=${e("wall_view_prev")} title=${e("wall_view_prev")} @click=${()=>this.edge=(this.edge-1+i)%i}>‹</button>
<button aria-label=${e("wall_view_next")} title=${e("wall_view_next")} @click=${()=>this.edge=(this.edge+1)%i}>›</button>
<button aria-label=${e("close")} @click=${()=>this.close()}>✕</button>
</header>
<svg viewBox=${c} preserveAspectRatio="xMidYMid meet" @pointerdown=${h=>h.target===h.currentTarget&&(this._sel=null)}>
<polygon class="wall" points=${`0,0 ${r.length},0 ${r.length},${-r.heightRight} 0,${-r.heightLeft}`} />
<line class="floor" x1=${-l} x2=${r.length+l} y1="0" y2="0" />
${s.map(h=>E`<g class="box ${h.kind} ${h.type} ${h.id===this._sel?"sel":""} ${this.host.admin?"movable":""}"
@pointerdown=${f=>this.down(f,h)}
@pointermove=${f=>this.move(f,h)}
@pointerup=${()=>this.up(h)}
@pointercancel=${()=>this._drag=null}>
<rect x=${h.x0} y=${-h.y1} width=${Math.max(.01,h.x1-h.x0)} height=${Math.max(.01,h.y1-h.y0)} rx="0.02" />
${u(h)}
</g>`)}
${p}
</svg>
<footer>
${d?m`<b>${this.nameOf(d)}</b>
<label
>${e("wall_view_left")}
<input type="number" step="0.01" min="0" .value=${d.x0.toFixed(2)} ?disabled=${!this.host.admin} @change=${h=>this.place(d,Number(h.target.value),d.y0)}
/></label>
${d.lifts?m`<label
>${e(d.kind==="opening"?"sill":"wall_view_height")}
<input type="number" step="0.01" min="0" .value=${d.y0.toFixed(2)} ?disabled=${!this.host.admin} @change=${h=>this.place(d,d.x0,Number(h.target.value))}
/></label>`:_}`:S(e("wall_view_hint"))}
</footer>
</div>
</div>`}close(){this.dispatchEvent(new CustomEvent("close"))}static styles=J`
.backdrop {
position: fixed;
inset: 0;
z-index: 30;
display: grid;
place-items: center;
background: rgba(0, 0, 0, 0.45);
}
.sheet {
width: min(1100px, calc(100vw - 32px));
max-height: calc(100vh - 32px);
display: flex;
flex-direction: column;
border-radius: 20px;
background: var(--nf-bg2, #1b2030);
color: var(--nf-text, #e8eeff);
box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
overflow: hidden;
}
header,
footer {
display: flex;
align-items: center;
gap: 10px;
padding: 10px 16px;
flex-wrap: wrap;
}
header button {
min-width: 36px;
height: 36px;
border: 0;
border-radius: 50%;
background: rgba(127, 127, 127, 0.16);
color: inherit;
font: inherit;
font-size: 18px;
cursor: pointer;
}
.grow {
flex: 1;
}
.muted {
color: var(--nf-muted, #9aa5bd);
font-size: 13px;
}
svg {
width: 100%;
height: min(60vh, 560px);
touch-action: none;
user-select: none;
}
.wall {
fill: rgba(127, 140, 170, 0.12);
stroke: var(--nf-accent, #37e0ff);
stroke-width: 0.015;
}
.floor {
stroke: var(--nf-muted, #9aa5bd);
stroke-width: 0.02;
}
.box rect {
fill: rgba(91, 124, 255, 0.28);
stroke: #8aa2ff;
stroke-width: 0.012;
}
.box.opening rect {
fill: rgba(10, 14, 24, 0.85);
stroke: var(--nf-muted, #9aa5bd);
}
.box.window rect {
fill: rgba(55, 224, 255, 0.16);
}
.box.sel rect {
stroke: var(--nf-accent, #37e0ff);
stroke-width: 0.025;
}
.box.movable {
cursor: grab;
}
.box text {
fill: var(--nf-text, #e8eeff);
pointer-events: none;
}
.dim line {
stroke: var(--nf-accent, #37e0ff);
stroke-width: 0.01;
stroke-dasharray: 0.04 0.03;
}
.dim text {
fill: var(--nf-accent, #37e0ff);
}
footer label {
display: inline-flex;
align-items: center;
gap: 6px;
font-size: 13px;
color: var(--nf-muted, #9aa5bd);
}
footer input {
width: 80px;
padding: 6px 8px;
border-radius: 10px;
border: 1px solid rgba(127, 127, 127, 0.35);
background: rgba(0, 0, 0, 0.2);
color: inherit;
font: inherit;
}
`};customElements.get("nf-wall-view")||customElements.define("nf-wall-view",Cl);function M0(t,e){let n=new Set([...Object.keys(t),...Object.keys(e)]);if(n.size===0)return 1/0;let r=0;for(let i of n)r+=Math.min(Math.abs((t[i]??-100)-(e[i]??-100)),40)**2;return Math.sqrt(r/n.size)}function ym(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 a=M0(s.rssi,e);a<(n.get(s.room)??1/0)&&n.set(s.room,a)}let r=[...n].sort((s,a)=>s[1]-a[1]);if(r.length===0)return{room:null,distance:1/0,margin:0};let[i,o]=r[0];return o>18?{room:null,distance:o,margin:0}:{room:i,distance:o,margin:r.length>1?r[1][1]-o:18}}var E0=t=>{let e=[...t].sort((r,i)=>r-i),n=e.length>>1;return e.length%2?e[n]:(e[n-1]+e[n])/2};function R0(t){let e={},n=new Set(t.flatMap(r=>Object.keys(r)));for(let r of n){let i=t.filter(o=>r in o).map(o=>o[r]);i.length*2>t.length&&(e[r]=Math.round(E0(i)*10)/10)}return e}function vm(t,e,n=3){let r=e.filter(s=>Object.keys(s).length>0);if(r.length===0)return[];let i=Math.max(1,Math.min(n,Math.floor(r.length/3))),o=[];for(let s=0;s<i;s++){let a=r.slice(Math.floor(s*r.length/i),Math.floor((s+1)*r.length/i)),l=R0(a);Object.keys(l).length>0&&o.push({room:t,rssi:l})}return o}var wm=(t,e,n)=>[...t.filter(r=>r.room!==e),...n],xm=t=>Math.max(0,Math.min(1,(t+95)/50));var A0=1500,Bl=class extends q{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,A0)}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,i])=>[r,i.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 i=vm(this._room,r);if(i.length===0)return;let o=Object.fromEntries(Object.entries(n.readings).map(([s,a])=>[s,a.name]));this.update2(e.id,s=>{s.prints=wm(s.prints,this._room,i),s.scanners={...s.scanners??{},...o}})}update2(e,n){this.host.change(r=>{let i=r.settings.ble?.tags.find(o=>o.id===e);i&&n(i)})}addTag(){let e=this._pick;if(!e)return;let n=e.startsWith("device_tracker."),r=this._found?.devices.find(s=>s.address===e),i=this._name.trim()||r?.name||this.host.hass?.states[e]?.attributes.friendly_name||e,o={id:P("ble"),name:String(i).slice(0,60),prints:[],...n?{entity:e}:{address:e}};this.host.change(s=>{s.settings.ble={tags:[...s.settings.ble?.tags??[],o]}}),this._tag=o.id,this._pick="",this._name=""}removeTag(e){this.host.change(n=>{let r=(n.settings.ble?.tags??[]).filter(i=>i.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,i=Object.entries(r?.readings??{}).sort((o,s)=>s[1].rssi-o[1].rssi);return m`<div class="nf-ble-bars">
${i.length===0?m`<p class="nf-sub">${r&&!r.available?n("ble_unavailable"):r?.address===null&&e.entity?n("ble_no_address"):n("ble_none_heard")}</p>`:i.map(([o,s])=>m`<div class="nf-ble-row" title=${o}>
<span class="nf-ble-name">${s.name}</span>
<span class="nf-ble-track"><span class="nf-ble-fill" style="width:${Math.round(xm(s.rssi)*100)}%"></span></span>
<span class="nf-ble-db">${Math.round(s.rssi)}</span>
</div>`)}
${i.length===1?S(n("ble_one_scanner")):_}
</div>`}learn(e){let n=this.host.t,r=this.rooms,i=ym(e.prints,this.reading()),o=c=>r.find(d=>d.id===c)?.label??null,s=c=>e.prints.filter(d=>d.room===c).length,a=this._samples!==null,l=a?Math.max(0,30-Math.round((Date.now()-this.recordStarted)/1e3)):0;return m`${this.bars(e)}
<p class="nf-ble-now"><b>${n("ble_now")}:</b> ${i.room?o(i.room):n("ble_unknown")}</p>
<div class="nf-form">
<label class="nf-field nf-wide">${n("ble_learn_room")}
<select ?disabled=${a} .value=${this._room} @change=${c=>this._room=c.target.value}>
<option value="">–</option>
${r.map(c=>m`<option value=${c.id} ?selected=${this._room===c.id}>${c.label}${s(c.id)?` \u2713 ${s(c.id)}`:""}</option>`)}
</select>
</label>
</div>
<div class="nf-actions">
<button class="nf-btn nf-primary" ?disabled=${!this._room||a||Object.keys(this._scan?.readings??{}).length===0} @click=${()=>this.startRecording()}>
${a?n("ble_recording",{s:l}):n("ble_record",{s:30})}
</button>
${this._room&&s(this._room)?m`<button class="nf-btn" ?disabled=${a} @click=${()=>this.update2(e.id,c=>c.prints=c.prints.filter(d=>d.room!==this._room))}>${n("ble_forget_room")}</button>`:_}
</div>
${S(n("ble_learn_hint"))}`}render(){let e=this.host.t,n=this.tags,r=new Set(n.flatMap(l=>[l.address??"",l.entity??""])),i=Object.entries(this.host.hass?.states??{}).filter(([l,c])=>l.startsWith("device_tracker.")&&typeof c.attributes.current_address=="string"&&!r.has(l)).map(([l,c])=>[l,String(c.attributes.friendly_name??l)]),o=(this._found?.devices??[]).filter(l=>!r.has(l.address)),s=this._found?.scanners.length??0,a=n.find(l=>l.id===this._tag)??null;return m`
${this._found&&!this._found.available?m`<p class="nf-sub">${e("ble_unavailable")}</p>`:m`<p class="nf-sub">${e("ble_scanners",{n:s})}</p>`}
${this._error?m`<p class="nf-sub">${this._error}</p>`:_}
${n.map(l=>m`<div class="nf-row nf-dev-row">
<span class="nf-dev-name"><span>${l.name}</span><small>${l.entity??l.address} · ${e("ble_spots",{n:l.prints.length})}</small></span>
<button class="nf-btn" @click=${()=>this._tag=this._tag===l.id?null:l.id}>${this._tag===l.id?e("ble_close"):e("ble_learn")}</button>
<button class="nf-btn" title=${e("delete")} @click=${()=>this.removeTag(l.id)}>✕</button>
</div>`)}
${a?m`<div class="nf-ble-learn">${this.learn(a)}${S(e("ble_sensor_hint",{name:a.name}))}</div>`:_}
<div class="nf-form">
<label class="nf-field nf-wide">${e("ble_add")}
<select .value=${this._pick} @change=${l=>this._pick=l.target.value}>
<option value="">–</option>
${i.length?m`<optgroup label=${e("ble_trackers")}>${i.map(([l,c])=>m`<option value=${l}>${c}</option>`)}</optgroup>`:_}
<optgroup label=${e("ble_devices")}>${o.map(l=>m`<option value=${l.address}>${l.named?l.name:l.address} · ${l.address} · ${l.rssi} dBm</option>`)}</optgroup>
</select>
</label>
<label class="nf-field nf-wide">${e("ble_name")}
<input type="text" maxlength="60" .value=${this._name} @input=${l=>this._name=l.target.value} />
</label>
</div>
<div class="nf-actions">
<button class="nf-btn" @click=${()=>{this.loadDevices()}}>${e("ble_refresh")}</button>
<button class="nf-btn nf-primary" ?disabled=${!this._pick||n.length>=10} @click=${()=>this.addTag()}>${e("ble_add_button")}</button>
</div>`}};customElements.get("nf-ble-locate")||customElements.define("nf-ble-locate",Bl);var F0=new URL(import.meta.url),T0=new URL("./nextfloor-3d.js?v=2aa97dea1ed8",F0).href,km;function $n(){return km??=import(T0),km}var $m=["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"],z0={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"},P0=[[/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 I0(t){if(t.vehicle)return"vehicles";if(t.climate)return"climate";if(!t.type.startsWith("pack:"))return t.lamp?"lights":z0[t.type]??"decor";let e=P0.find(([n])=>n.test(t.id));return e?e[1]:t.lamp?"lights":"decor"}var Sm=[[/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 Vl(t){let e=(t??"").toLowerCase(),n=Sm.find(([r])=>r.test(e));return n?new Set(["lights",...n[1]]):null}function Wl(t){let e=(t??"").toLowerCase();return Sm.find(([n])=>n.test(e))?.[1][0]??null}var Mm=t=>t==="garden"||t==="plants"||t==="vehicles",Em=/_(\d+(?:x\d+)?)$/;function Rm(t){let e=new Map;for(let n of t){let r=I0(n),i=n.type.startsWith("pack:")&&!n.vehicle?n.id.replace(Em,""):n.id,o=`${n.source}:${i}`,s=e.get(o);s&&s.category===r?s.entries.push(n):e.set(s?`${o}:${n.id}`:o,{key:s?`${o}:${n.id}`:o,category:r,entries:[n]})}for(let n of e.values())n.entries.sort((r,i)=>r.size[0]-i.size[0]||r.size[1]-i.size[1]);return[...e.values()]}function Am(t,e){let n=i=>Math.round(i*100);return e.some(i=>i!==t&&n(i.size[0])===n(t.size[0]))?Em.exec(t.id)?.[1]??`${n(t.size[0])}\xD7${n(t.size[2])}`:`${n(t.size[0])}`}function Fm(t,e,n=12){return[e,...t.filter(r=>r!==e)].slice(0,n)}var Tm=t=>t.toLowerCase().normalize("NFD").replace(new RegExp("\\p{M}","gu"),""),zm=t=>Tm(t).split(/\s+/).filter(Boolean),Pm=(t,e)=>{let n=Tm(e);return t.every(r=>n.includes(r))};function Im(){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 Dm=112,D0="nextfloor-thumbs";function O0(t){let e=2166136261;for(let n=0;n<t.length;n++)e=Math.imul(e^t.charCodeAt(n),16777619);return(e>>>0).toString(36)}function Kl(t){let e=U(t);return`${t}|${e?O0(JSON.stringify(e)):"b"}|${Dm}`}function H0(){return new Promise(t=>{try{let e=indexedDB.open(D0,1);e.onupgradeneeded=()=>e.result.createObjectStore("thumbs"),e.onsuccess=()=>t(e.result),e.onerror=()=>t(null)}catch{t(null)}})}var jl=class{enabled=!Im();memory=new Map;waiting=new Map;queue=[];db=null;running=!1;packs=[];cached(e){return this.memory.get(Kl(e))}get(e){let n=Kl(e),r=this.memory.get(n);return r?Promise.resolve(r):new Promise(i=>{let o=this.waiting.get(n);if(o)return void o.push(i);this.waiting.set(n,[i]),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??=H0();let r=await this.db,i=r?await new Promise(o=>{try{let s=r.transaction("thumbs").objectStore("thumbs").get(n);s.onsuccess=()=>o(typeof s.result=="string"?s.result:null),s.onerror=()=>o(null)}catch{o(null)}}):null;if(i)return this.settle(n,i);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;(i=>n?n(i,{timeout:300}):setTimeout(i,16))(async()=>{let i=Kl(e),o=null;try{let[s,a,l]=ut(e);o=(await $n()).furniturePreview({type:e,w:s,d:a,h:l,variant:null,lamp:ao[e]??null},Dm,[...this.packs]),this.keep(i,o)}catch{o=null}this.settle(i,o),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{}}},Yt=new jl,Fi=null,L0=t=>{for(let e of t)e.isIntersecting&&e.target.visible()},Gl=class extends q{static properties={type:{},_url:{state:!0}};static styles=J`
:host {
display: block;
aspect-ratio: 4 / 3;
border-radius: 10px;
background: rgba(127, 127, 127, 0.08);
overflow: hidden;
}
img {
display: block;
width: 100%;
height: 100%;
object-fit: contain;
}
`;constructor(){super(),this.type="",this._url=null}connectedCallback(){super.connectedCallback(),Yt.enabled&&(this._url=Yt.cached(this.type)??null,!this._url&&(Fi??=new IntersectionObserver(L0,{rootMargin:"120px"}),Fi.observe(this)))}disconnectedCallback(){super.disconnectedCallback(),Fi?.unobserve(this)}updated(e){e.has("type")&&e.get("type")!==void 0&&(this._url=Yt.cached(this.type)??null,!this._url&&Yt.enabled&&Fi?.observe(this))}visible(){Fi?.unobserve(this);let e=this.type;Yt.get(e).then(n=>{this.type===e&&(this._url=n)})}render(){return this._url?m`<img src=${this._url} alt="" />`:_}};customElements.get("nf-thumb")||customElements.define("nf-thumb",Gl);var Om="nextfloor.library2",C0={language:"en"},ls=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(Om);n&&(this.saved={...this.saved,...JSON.parse(n)})}catch{}}store(e){this.saved={...this.saved,...e},this.onChange();try{localStorage.setItem(Om,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:Fm(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 i=n.getBoundingClientRect(),o={left:Math.max(8,i.left-196),top:Math.max(8,Math.min(window.innerHeight-200,i.top+i.height/2-95))};this.shown={type:e,url:null,...o},this.onChange();try{let[s,a,l]=ut(e),c=(await $n()).furniturePreview({type:e,w:s,d:a,h:l,variant:null,lamp:ao[e]??null},180,[...r]);this.shown?.type===e&&(this.shown={type:e,url:c,...o})}catch{this.shown=null}this.onChange()}};function N0(t,e){let n=t.hass?.language??"en",i=[...[...new Set(Object.values(jd).flat())].map(a=>({type:a,source:"builtin",id:a,size:nt[a],lamp:de(a),electric:Tt(a)})),...e.flatMap(a=>a.items.map(l=>({type:he(a.id,l.id),source:a.id,id:l.id,size:l.size,lamp:!!l.light,electric:!!l.electric,vehicle:!!l.vehicle,climate:!!l.climate})))],o=new Map(e.map(a=>[a.id,Ve(a,n)])),s=new Map(e.flatMap(a=>a.items.map(l=>[he(a.id,l.id),l])));return Rm(i).map(a=>{let l=a.entries[0],c=s.get(l.type),d=c?Je(c,l.type,n):t.t(`furn_${l.type}`),u=a.entries.length>1&&d.replace(/\s*\(?\d+([.,]\d+)?\s*(cm|x\s*\d+|×\s*\d+)?\)?\s*$/i,"").trim()||d,p=a.entries.map(h=>{let f=s.get(h.type);return f?[...Object.values(f.name),Je(f,h.type,n)].join(" "):xe(C0,`furn_${h.type}`)}).join(" ");return{card:a,label:u,search:`${p} ${t.t(`lib_cat_${a.category}`)}`,from:o.get(l.source)??"NextFloor"}})}var B0=(t,e)=>Pm(e,`${t.label} ${t.search} ${t.from} ${t.card.entries.map(n=>n.id.replace(/_/g," ")).join(" ")}`),V0=t=>t.lamp?"light":t.electric?"switch":null;function W0(t,e,n,r){let i=t.t,o=e.pickedOf(n.card),[s,a]=o.size,l=V0(o),c=p=>{e.showPreview(o.type,p.currentTarget,r.packs)},d=()=>{e.used(o.type),r.add(o.type)},u=e.isFavourite(o.type);return m`<div class="nf-card">
<button
class="nf-card-main"
title=${l?i(l==="light"?"lib_badge_light":"lib_badge_electric"):n.label}
@click=${d}
@mouseenter=${c}
@focus=${c}
@mouseleave=${()=>e.hidePreview()}
@blur=${()=>e.hidePreview()}
>
${Yt.enabled?m`<nf-thumb .type=${o.type}></nf-thumb>`:_}
<span class="nf-card-name"
>${n.label}${l?m`<svg class="nf-lib-badge" viewBox="0 0 24 24" width="12" height="12" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d=${qt(l)} /></svg>`:_}</span
>
<span class="nf-card-meta">${Math.round(s*100)} × ${Math.round(a*100)} cm · ${n.from}</span>
</button>
<button class="nf-card-star" aria-pressed=${u} title=${i(u?"lib_fav_remove":"lib_fav_add")} @click=${()=>e.toggleFavourite(o.type)}>${u?"\u2605":"\u2606"}</button>
${n.card.entries.length>1?m`<div class="nf-card-sizes" role="group" aria-label=${i("lib_sizes")}>
${n.card.entries.map(p=>m`<button class="nf-size" aria-pressed=${p===o} @click=${()=>e.pick(n.card,p.type)}>${Am(p,n.card.entries)}</button>`)}
</div>`:_}
</div>`}function Lm(t,e,n,r){return m`<div class="nf-cards">${n.map(i=>W0(t,e,i,r))}</div>`}function Ul(t,e,n,r,i,o,s){if(i.length===0)return _;let a=e.isOpen(n,s);return m`<button class="nf-lib-head nf-lib-toggle" aria-expanded=${a} @click=${()=>e.toggle(n,s)}>
<span class="nf-lib-caret">${a?"\u25BE":"\u25B8"}</span>${r} <span class="nf-lib-count">${i.length}</span>
</button>
${a?Lm(t,e,i,o):_}`}function Hm(t,e){return t.flatMap(n=>{let r=e.find(i=>i.card.entries.some(o=>o.type===n));return r?[{...r,card:{...r.card,key:`one:${n}`,entries:r.card.entries.filter(i=>i.type===n)}}]:[]})}function K0(t){let e=Wl(t),n=Vl(t),r=i=>i===e?0:n?.has(i)?1:2;return[...$m].sort((i,o)=>r(i)-r(o))}function Cm(t,e,n,r){let i=t.t;Yt.packs=r.packs;let o=N0(t,r.packs),s=zm(e.query),a=Vl(n),l=!!a&&e.has("room")&&s.length===0,c=o.filter(p=>{let h=p.card.entries[0];return l&&!a.has(p.card.category)||e.has("linkable")&&!h.lamp&&!h.electric||e.has("lit")&&!h.lamp||e.has("outdoor")&&!Mm(p.card.category)?!1:s.length===0||B0(p,s)}),d=(p,h)=>m`<button class="nf-chip nf-lib-chip" aria-pressed=${e.has(p)} @click=${()=>e.flip(p)}>${h}</button>`,u=s.length>0;return m`<section>
<h3>${i("furniture_add")}</h3>
<p class="nf-sub">${n?i("furniture_into",{room:n}):i("furniture_pick_room")}</p>
<button class="nf-btn nf-lib-studio" title=${i("studio_hint")} @click=${()=>r.studio()}>🛠️ ${i("studio_new")}</button>
<input
class="nf-search"
type="search"
placeholder=${i("furniture_search")}
.value=${e.query}
@input=${p=>e.query=p.target.value}
@keydown=${p=>p.key==="Escape"&&(e.query="")}
/>
<div class="nf-lib-chips">
${a?d("room",i("lib_for_room",{room:n??""})):_} ${d("linkable",`\u26A1 ${i("lib_linkable")}`)} ${d("lit",`\u{1F4A1} ${i("lib_lit")}`)}
${d("outdoor",`\u{1F333} ${i("lib_outdoor")}`)}
</div>
${u&&c.length===0?m`<p class="nf-sub">${i("furniture_search_none")}</p>`:_}
${u?Lm(t,e,c,r):m`${Ul(t,e,"favourites",`\u2605 ${i("lib_favourites")}`,Hm(e.favourites,o),r,!0)}
${Ul(t,e,"recent",`\u{1F558} ${i("lib_recent")}`,Hm(e.recent.slice(0,6),o),r,!1)}
${K0(n).map(p=>Ul(t,e,p,i(`lib_cat_${p}`),c.filter(h=>h.card.category===p),r,p===(Wl(n)??"lights")))}
${l?m`<button class="nf-btn nf-lib-all" @click=${()=>e.flip("room")}>${i("lib_all_rooms")}</button>`:_}`}
</section>`}function Nm(t,e){return e?m`<div class="nf-preview" style="left:${e.left}px;top:${e.top}px" aria-hidden="true">
${e.url?m`<img src=${e.url} alt="" />`:m`<span class="nf-preview-wait"></span>`}
<b>${Te(t.hass,e.type)}</b>
</div>`:_}function Zl(t,e,n,r=24){let i=Math.hypot(e[0]-t[0],e[1]-t[1]);if(i<1e-6||Math.abs(n)<1e-4)return[];let o=Math.max(-i*2,Math.min(i*2,n)),s=[(e[0]-t[0])/i,(e[1]-t[1])/i],a=[s[1],-s[0]],l=i*i/4/(2*Math.abs(o))+Math.abs(o)/2,c=2*Math.atan(2*Math.abs(o)/i),d=Math.max(2,Math.min(r,Math.ceil(2*c/Math.PI*180/11.25))),u=[a[0]*Math.sign(o),a[1]*Math.sign(o)],p=[(t[0]+e[0])/2,(t[1]+e[1])/2],h=[p[0]-u[0]*(l-Math.abs(o)),p[1]-u[1]*(l-Math.abs(o))],f=[];for(let g=1;g<d;g++){let b=-c+2*c*g/d;f.push([h[0]+l*(u[0]*Math.cos(b)+s[0]*Math.sin(b)),h[1]+l*(u[1]*Math.cos(b)+s[1]*Math.sin(b))])}return f}var ql=t=>t.reduce((e,n,r)=>r?e+Math.hypot(n[0]-t[r-1][0],n[1]-t[r-1][1]):e,0);function Yl(t,e){let n=Math.max(0,e);for(let r=0;r+1<t.length;r++){let i=Math.hypot(t[r+1][0]-t[r][0],t[r+1][1]-t[r][1]);if(n<=i||r+2===t.length)return{piece:r,offset:Math.min(n,i)};n-=i}return{piece:0,offset:0}}var Ie=t=>Math.round(t*1e3)/1e3,Xl=t=>t.map(([e,n])=>[Ie(e),Ie(n)]);function Bm(t,e){return{id:P("room"),name:e,area_id:null,points:Xl(t),floor_material:"wood"}}function Vm(t){return{...structuredClone(t),id:P("room"),points:Xl(t.points.map(([e,n])=>[e+.5,n+.5]))}}function Wm(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=>!C([r.x,r.z],n.points)))}function Km(t,e,n){let r=t.rooms.find(s=>s.id===e);if(!r||r.points.length<=3)return!1;let i=(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 o=s=>s.room_id===e&&!s.wall;return t.openings=t.openings.filter(s=>!(o(s)&&(s.edge===n||s.edge===i))).map(s=>o(s)&&s.edge>n?{...s,edge:s.edge-1}:s),!0}function jm(t,e,n){if(!Number.isFinite(n))return null;let r=ue(t.points),{x0:i,z0:o,x1:s,z1:a}=r;return e==="x"?[i,s]=[n,n+(s-i)]:e==="z"?[o,a]=[n,n+(a-o)]:n>.05&&(e==="w"?s=i+n:a=o+n),Xl([[i,o],[s,o],[s,a],[i,a]])}function Gm(t,e,n,r){return!Number.isFinite(r)||e<0||e>=t.points.length?null:t.points.map((i,o)=>o===e?n===0?[Ie(r),i[1]]:[i[0],Ie(r)]:[i[0],i[1]])}var j0=/^(Raum|Room) \d+$/;function Jl(t,e,n,r=!0){let i=e?n[e]:void 0,o=!t.name||j0.test(t.name)||Object.values(n).some(s=>s.name===t.name);return{area_id:e||null,...r&&i&&o?{name:i.name}:{}}}function cs(t,e){let n=/^symcon-category-(\d+)$/.exec(e)?.[1];return(n?t?.symconObjects?.find(r=>r.object_id===Number(n))?.name:void 0)??t?.areas?.[e]?.name.split(" / ").at(-1)?.trim()??""}function Um(t,e){let n=e.filter(l=>ee(l.entity_id)==="light"&&(l.mount??"ceiling")==="ceiling"&&C([l.x,l.z],t.points));if(n.length<2)return[];let r=ue(t.points),[i,o]=[r.x1-r.x0,r.z1-r.z0],s=Math.max(1,Math.round(Math.sqrt(n.length*i/Math.max(.1,o)))),a=Math.ceil(n.length/s);return n.map((l,c)=>{let d=Math.floor(c/s),u=d===a-1?n.length-s*(a-1):s,p=c-d*s;return{entityId:l.entity_id,x:Ie(r.x0+i/u*(p+.5)),z:Ie(r.z0+o/a*(d+.5))}})}function Ql(t,e,n,r){let i=t.rooms.find(d=>d.id===e);if(!i)return;let o=i.points[n],s=i.points[(n+1)%i.points.length];i.points.splice(n+1,0,r);let[a,l]=[i.wall_heights?.[n],i.wall_slopes?.[n]];if(typeof a=="number"&&typeof l=="number"&&i.wall_slopes){let d=Math.hypot(s[0]-o[0],s[1]-o[1]),u=Ie(a+(l-a)*Math.min(1,Math.hypot(r[0]-o[0],r[1]-o[1])/(d||1)));i.wall_slopes.splice(n,1,u,l),i.wall_heights.splice(n+1,0,u)}else i.wall_heights?.splice(n+1,0,i.wall_heights[n]??null),i.wall_slopes?.splice(n+1,0,null);i.wall_thickness?.splice(n+1,0,i.wall_thickness[n]??null);let c=Math.hypot(r[0]-o[0],r[1]-o[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=Ie(d.offset-c)))}var G0=22.5;function Zm(t,e,n){let r=Math.min(Math.abs(e),t*2),i=t*(1+8/3*(r/Math.max(1e-6,t))**2),o=4*Math.atan(2*r/Math.max(1e-6,t))*180/Math.PI,s=Math.max(2,Math.ceil(o/G0));if(n<=0)return 24;let a=Math.floor(i/(n+.1));return a>=s?a:0}function U0(t,e,n,r){let i=ql(n);t.forEach((o,s)=>{let{piece:a,offset:l}=Yl(n,e[s]*i),c=Math.hypot(n[a+1][0]-n[a][0],n[a+1][1]-n[a][1]);o.edge=r+a,o.offset=Ie(c>o.width?Math.min(c-o.width/2,Math.max(o.width/2,l)):c/2)})}function qm(t,e,n,r){let i=t.rooms.find(v=>v.id===e);if(!i||n<0||n>=i.points.length||Math.abs(r)<.01)return!1;let o=i.points[n],s=i.points[(n+1)%i.points.length],a=Math.hypot(s[0]-o[0],s[1]-o[1]);if(a<.2)return!1;let[l,c]=[(s[0]-o[0])/a,(s[1]-o[1])/a],d=[(o[0]+s[0])/2+c*.02,(o[1]+s[1])/2-l*.02],p=C(d,i.points)?-r:r,h=(v,w)=>t.openings.filter(k=>k.room_id===v.id&&!k.wall&&k.edge===w),f=t.rooms.flatMap(v=>v.points.map((w,k)=>{let x=v.points[(k+1)%v.points.length],M=(A,T)=>Math.abs(A[0]-T[0])<.001&&Math.abs(A[1]-T[1])<.001;return M(w,o)&&M(x,s)?[v,k,!1]:M(w,s)&&M(x,o)?[v,k,!0]:null}).filter(w=>!!w)),g=Math.max(0,...f.flatMap(([v,w])=>h(v,w).map(k=>k.width))),b=Zm(a,r,g);if(!b)return!1;let y=Zl(o,s,p,b).map(([v,w])=>[Ie(v),Ie(w)]);if(!y.length)return!1;for(let[v,w,k]of f){let x=k?[...y].reverse():y,M=h(v,w),A=v.points[w],T=M.map(F=>Math.min(1,Math.max(0,F.offset/a)));for(let F of M)F.edge=-1;x.forEach((F,L)=>Ql(t,v.id,w+L,F)),v.wall_splits?.splice(w+1,0,...x.map(()=>null)),v.wall_splits?.[w]&&(v.wall_splits[w]=null),U0(M,T,[A,...x,v.points[(w+x.length+1)%v.points.length]],w)}return!0}function Ym(t,e,n){let r=t.walls??[],i=r.findIndex(f=>f.id===e);if(i<0||Math.abs(n)<.01)return[];let o=r[i],s=Math.hypot(o.b[0]-o.a[0],o.b[1]-o.a[1]),a=t.openings.filter(f=>f.wall===e),l=Math.max(0,...a.map(f=>f.width)),c=Zm(s,n,l);if(!c)return[];let d=Zl(o.a,o.b,n,c).map(([f,g])=>[Ie(f),Ie(g)]);if(!d.length)return[];let u=[o.a,...d,o.b],p=u.slice(1).map((f,g)=>({...o,id:g===0?o.id:P("wall"),a:u[g],b:f}));r.splice(i,1,...p),t.walls=r;let h=ql(u);for(let f of a){let{piece:g,offset:b}=Yl(u,f.offset/s*h),y=Math.hypot(u[g+1][0]-u[g][0],u[g+1][1]-u[g][1]);f.wall=p[g].id,f.offset=Ie(y>f.width?Math.min(y-f.width/2,Math.max(f.width/2,b)):y/2)}return p.map(f=>f.id)}var sr=t=>Math.round(t*1e3)/1e3;function ds(t,e,n){return[Math.round((e[0]-t[0])/n)*n,Math.round((e[1]-t[1])/n)*n]}var Sn=(t,e)=>e?.01:t,ar=(t,e,n=5)=>Math.hypot(t[0]-e[0],t[1]-e[1])>=n;function Xm(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 et=(t,e)=>[sr(t[0]+e[0]),sr(t[1]+e[1])];function ec(t,e,n,r){return[sr(Math.round((t[0]+n[0]-e[0])/r)*r),sr(Math.round((t[1]+n[1]-e[1])/r)*r)]}function tc(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 Jm(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 Qm(t,e,n){let r=Dn([...t]),i=t[e],o=[sr(n[0]),sr(n[1])];return t.map((s,a)=>a===e?o:r?[Math.abs(s[0]-i[0])<1e-6?o[0]:s[0],Math.abs(s[1]-i[1])<1e-6?o[1]:s[1]]:[s[0],s[1]])}var bt=t=>Math.round(t*1e3)/1e3,us=(t,e)=>Math.hypot(t[0]-e[0],t[1]-e[1]);function Z0(t,e,n){let r=null,i=n;for(let o of t){let s=us(o,e);s<i&&([r,i]=[o,s])}return r}function q0(t,e,n){let r=null,i=n.reach;for(let o of t)o.points.forEach((s,a)=>{if(o.open&&a===o.points.length-1)return;let l=o.points[(a+1)%o.points.length],[c,d]=[l[0]-s[0],l[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=us(h,e),g=(b,y,v)=>Math.min(Math.max(b,Math.min(y,v)),Math.max(y,v));Math.abs(d)<1e-9&&(h[0]=g(Math.round(h[0]/n.grid)*n.grid,s[0],l[0])),Math.abs(c)<1e-9&&(h[1]=g(Math.round(h[1]/n.grid)*n.grid,s[1],l[1])),f<i&&([r,i]=[h,f])});return r}function Y0(t,e,n){let r=[bt(Math.round(e[0]/n.grid)*n.grid),bt(Math.round(e[1]/n.grid)*n.grid)],i={},[o,s]=[n.reach,n.reach];for(let a of t)Math.abs(a[0]-e[0])<o&&(o=Math.abs(a[0]-e[0]),r[0]=a[0],i.x=a[0]),Math.abs(a[1]-e[1])<s&&(s=Math.abs(a[1]-e[1]),r[1]=a[1],i.z=a[1]);return{point:r,guides:i}}function eg(t,e){let n=(e.outdoor??[]).filter(s=>s.id!==e.skip?.outdoorId),r=[...e.rooms.flatMap(s=>s.points.filter((a,l)=>!(e.skip&&s.id===e.skip.roomId&&(e.skip.index===void 0||e.skip.index===l)))),...n.flatMap(s=>s.points)],i=Z0(r,t,e.reach);if(i)return{point:[i[0],i[1]],guides:{point:i}};let o=q0([...e.rooms.filter(s=>s.id!==e.skip?.roomId),...n],t,{...e,skip:void 0});return o?{point:[bt(o[0]),bt(o[1])],guides:{point:o}}:Y0(r,t,e)}function tg(t,e,n){let r=[...n.rooms.filter(h=>h.id!==n.skip?.roomId),...(n.outdoor??[]).filter(h=>h.id!==n.skip?.outdoorId)],i=t.map(h=>[h[0]+e[0],h[1]+e[1]]),o=n.outdoor?.find(h=>h.id===n.skip?.outdoorId)?.open,s=e.map(h=>bt(Math.round(h/n.grid)*n.grid)),a,l=n.reach;for(let h of i)for(let f of r)for(let g of f.points){let b=us(h,g);b<l&&(l=b,a={by:[e[0]+g[0]-h[0],e[1]+g[1]-h[1]],point:g})}if(a)return{by:a.by.map(bt),guides:{point:a.point}};let c,d,u,p=(h,f,g,b=!1)=>{let y=g[0]-f[0],v=g[1]-f[1],w=y*y+v*v;if(w<1e-9)return;let k=((h[0]-f[0])*y+(h[1]-f[1])*v)/w;if(k<0||k>1)return;let x=[f[0]+k*y,f[1]+k*v],M=us(h,x);if(M>=n.reach)return;let A=b?-1:1,T=[A*(x[0]-h[0]),A*(x[1]-h[1])];Math.abs(y)<1e-9?(!c||M<Math.abs(c.offset))&&(c={offset:T[0],at:b?h[0]:f[0]}):Math.abs(v)<1e-9?(!d||M<Math.abs(d.offset))&&(d={offset:T[1],at:b?h[1]:f[1]}):(!u||M<u.d)&&(u={correction:T,point:b?h:x,d:M})};for(let h of r){let f="open"in h&&h.open;for(let g=0;g<h.points.length-(f?1:0);g++){let b=h.points[g],y=h.points[(g+1)%h.points.length];for(let v of i)p(v,b,y)}for(let g of h.points)for(let b=0;b<i.length-(o?1:0);b++)p(g,i[b],i[(b+1)%i.length],!0)}return!c&&!d&&u?{by:[bt(e[0]+u.correction[0]),bt(e[1]+u.correction[1])],guides:{point:u.point}}:{by:[c?bt(e[0]+c.offset):s[0],d?bt(e[1]+d.offset):s[1]],guides:{...c?{x:c.at}:{},...d?{z:d.at}:{}}}}var hs=(t,e)=>pe(t.host.hass,e);function X0(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 E`<g pointer-events="none">
<line class="nf-draft nf-draft-wall" x1=${n[0]} y1=${n[1]} x2=${r[0]} y2=${r[1]} />
<text class="nf-dim" x=${(n[0]+r[0])/2} y=${(n[1]+r[1])/2-10}>${hs(t,s)}</text>
</g>`}let[i,o]=[Math.abs(e.end[0]-e.start[0]),Math.abs(e.end[1]-e.start[1])];return E`<g pointer-events="none">
<rect class="nf-draft" x=${Math.min(n[0],r[0])} y=${Math.min(n[1],r[1])} width=${Math.abs(r[0]-n[0])} height=${Math.abs(r[1]-n[1])} />
<text class="nf-dim" x=${(n[0]+r[0])/2} y=${Math.min(n[1],r[1])-8}>${hs(t,i)} × ${hs(t,o)}</text>
</g>`}function J0(t,e,n,r){let i=[...e,...n?[n]:[]].map(d=>t.toScreen(d)),o=e.length>=3,s=r?e.slice(1).map((d,u)=>{let[p,h]=[t.toScreen(e[u]),t.toScreen(d)];return E`<text class="nf-dim" x=${(p[0]+h[0])/2} y=${(p[1]+h[1])/2-6}>${hs(t,Math.hypot(d[0]-e[u][0],d[1]-e[u][1]))}</text>`}):_,a=e.map((d,u)=>{let[p,h]=t.toScreen(d),f=u===0&&o;return E`<circle class=${f?"nf-draft-pt nf-draft-first":"nf-draft-pt"} cx=${p} cy=${h} r=${f?9:5} />`}),[l,c]=n?t.toScreen(n):[0,0];return E`<g pointer-events="none">
${i.length>1?E`<polyline class="nf-draft" points=${i.map(d=>d.join(",")).join(" ")} />`:_}
${s}${a}
${n?E`<circle class="nf-cursor" cx=${l} cy=${c} r="4" />`:_}
</g>`}function ng(t,e,n){let r=e.x!==void 0?t.toScreen([e.x,0])[0]:null,i=e.z!==void 0?t.toScreen([0,e.z])[1]:null,[o,s]=e.point?t.toScreen(e.point):[0,0];return E`<g pointer-events="none">
${r!==null?E`<line class="nf-guide" x1=${r} y1="0" x2=${r} y2=${n.h} />`:_}
${i!==null?E`<line class="nf-guide" x1="0" y1=${i} x2=${n.w} y2=${i} />`:_}
${e.point?E`<circle class="nf-snap" cx=${o} cy=${s} r="9" />`:_}
</g>`}function rg(t,e,n,r,i){return e?X0(t,e):n!=="polygon"&&n!=="measure"?_:J0(t,r,i,n==="measure")}var le=(t,e,n,r,i="")=>E`<rect class=${i} x=${Math.min(t,n)} y=${Math.min(e,r)} width=${Math.abs(n-t)} height=${Math.abs(r-e)} />`,ie=(t,e,n,r,i="")=>E`<line class=${i} x1=${t} y1=${e} x2=${n} y2=${r} />`,og=(t,e="")=>E`<polygon class=${e} points=${t.map(n=>n.join(",")).join(" ")} />`,se=(t,e,n,r="")=>E`<circle class=${r} cx=${t} cy=${e} r=${n} />`,nc=(t,e,n,r,i="")=>E`<ellipse class=${i} cx=${t} cy=${e} rx=${n} ry=${r} />`;function rc(t,e,n){let r=[];for(let i=1;i<n;i++){let o=-t/2+t/n*i;r.push(ie(o,e/2,o,e/2-Math.min(.12,e*.3)))}return r}function ig(t,e,n,r){let i=Math.min(.24,e*.28),o=r?Math.min(.2,t*.12):0,s=[le(-t/2,-e/2,t/2,-e/2+i,"nf-sym-fill")];r&&s.push(le(-t/2,-e/2,-t/2+o,e/2,"nf-sym-fill"),le(t/2-o,-e/2,t/2,e/2,"nf-sym-fill"));let a=t-2*o;for(let l=1;l<n;l++){let c=-t/2+o+a/n*l;s.push(ie(c,-e/2+i,c,e/2-.02))}return s}function sg(t,e,n,r){if(t==="stairs"&&r?.stair)return Q0(r,e,n);switch(t){case"sofa":return ig(e,n,Math.max(1,Math.round((e-.4)/.62)),!0);case"armchair":return ig(e,n,1,!0);case"bench":return[le(-e/2,-n/2,e/2,-n/2+.08,"nf-sym-fill")];case"corner_bench":{let i=Math.min(.5,n*.4);return[le(-e/2,-n/2,e/2,-n/2+.08,"nf-sym-fill"),le(-e/2,-n/2,-e/2+.08,n/2,"nf-sym-fill"),ie(-e/2+i,-n/2+i,e/2,-n/2+i),ie(-e/2+i,-n/2+i,-e/2+i,n/2)]}case"chair":return[le(-e/2,-n/2,e/2,-n/2+.06,"nf-sym-fill")];case"office_chair":return[se(0,.03,Math.min(e,n)*.36),le(-e*.35,-n/2+.02,e*.35,-n/2+.1,"nf-sym-fill")];case"bar_stool":case"table_round":return[se(0,0,Math.min(e,n)*.42)];case"stool":return[le(-e/2+.04,-n/2+.04,e/2-.04,n/2-.04)];case"table":case"coffee_table":case"desk":{let i=[le(-e/2+.05,-n/2+.05,e/2-.05,n/2-.05)];return t==="desk"&&i.push(ie(-.3,-n/2+.1,.3,-n/2+.1,"nf-sym-strong")),i}case"bed":case"bunk_bed":{let i=e>1.2?2:1,o=(e-.2)/i,s=[le(-e/2,-n/2,e/2,-n/2+.07,"nf-sym-fill"),ie(-e/2,-n/2+(n-.1)*.36,e/2,-n/2+(n-.1)*.36)];for(let a=0;a<i;a++)s.push(le(-e/2+.13+o*a,-n/2+.12,-e/2+.07+o*(a+1),-n/2+.12+Math.min(.4,n*.18)));return s}case"nightstand":case"wardrobe":case"dresser":case"sideboard":case"tall_cabinet":case"kitchen":case"kitchen_wall":case"kitchen_tall":case"shelf":return rc(e,n,t==="nightstand"||t==="tall_cabinet"||t==="kitchen_tall"?1:Math.max(2,Math.round(e/.5)));case"coat_rack":return[le(-e/2,-n/2,e/2,-n/2+.03,"nf-sym-fill"),...rc(e,n,Math.max(2,Math.round(e/.5)))];case"island":return[ie(-e/2,n/2-.3,e/2,n/2-.3)];case"fridge":return[ie(-e/2+.06,n/2-.04,e/2-.06,n/2-.04,"nf-sym-strong")];case"stove":{let i=Math.min(e,n)*.14;return[se(-e*.22,-n*.2,i),se(e*.22,-n*.2,i*.8),se(-e*.22,n*.2,i*.8),se(e*.22,n*.2,i)]}case"sink":{let i=Math.min(.5,e-.2);return[le(-i/2,-n/2+.1,i/2,n/2-.08),se(0,-n/2+.06,.025,"nf-sym-fill")]}case"dishwasher":return[ie(-e/2+.08,n/2-.05,e/2-.08,n/2-.05,"nf-sym-strong")];case"washer":case"dryer":return[se(0,.05,Math.min(e,n)*.3),ie(-e/2,-n/2+.1,e/2,-n/2+.1)];case"bathtub":return[le(-e/2+.07,-n/2+.07,e/2-.07,n/2-.07),se(-e/2+.14,0,.03,"nf-sym-fill")];case"shower":return[ie(-e/2,-n/2,e/2,n/2),ie(e/2,-n/2,-e/2,n/2),se(0,0,.04)];case"wc":return[le(-e/2,-n/2,e/2,-n/2+Math.min(.18,n*.3),"nf-sym-fill"),nc(0,n*.1,e*.36,n*.3)];case"washbasin":return[nc(0,.03,e*.34,n*.3)];case"tv_board":return[ie(-Math.min(e*.4,.72),-n/2+.14,Math.min(e*.4,.72),-n/2+.14,"nf-sym-strong"),...rc(e,n,Math.max(2,Math.round(e/.6)))];case"tv_wall":return[ie(-e/2,0,e/2,0,"nf-sym-strong")];case"lamp_downlight":case"lamp_spot":return[se(0,0,Math.min(e,n)*.45,"nf-sym-fill"),se(0,0,Math.min(e,n)*1.4)];case"lamp_bollard":case"lamp_garden":return[se(0,0,Math.min(e,n)*.5,"nf-sym-fill"),se(0,0,Math.min(e,n)*1.6)];case"parking":return[le(-e/2+.08,-n/2+.08,e/2-.08,n/2-.08),ie(-e*.15,n/2-.5,0,n/2-.22,"nf-sym-strong"),ie(0,n/2-.22,e*.15,n/2-.5,"nf-sym-strong")];case"robot_vacuum":return[le(-e*.45,-n/2,e*.45,-n/2+n*.3,"nf-sym-fill"),se(0,n*.14,Math.min(e,n)*.47)];case"radiator":{let i=[],o=Math.max(3,Math.round(e/.1));for(let s=1;s<o;s++)i.push(ie(-e/2+e/o*s,-n/2,-e/2+e/o*s,n/2));return i}case"lamp_panel":return[le(-e/2+.03,-n/2+.03,e/2-.03,n/2-.03,"nf-sym-fill")];case"lamp_uplight":case"lamp_ceiling":case"lamp_pendant":case"lamp_floor":case"lamp_table":{let i=Math.min(e,n)/2,o=[se(0,0,i*.9,"nf-sym-fill"),se(0,0,i*.3)];if(t==="lamp_ceiling"||t==="lamp_pendant")for(let s=0;s<8;s++){let a=s/8*Math.PI*2;o.push(ie(Math.cos(a)*i*1.05,Math.sin(a)*i*1.05,Math.cos(a)*i*1.35,Math.sin(a)*i*1.35))}return o}case"ceiling_fan":{let i=Math.min(e,n)/2,o=[se(0,0,.11,"nf-sym-fill")];for(let s=0;s<5;s++){let a=s/5*Math.PI*2;o.push(ie(Math.cos(a)*.12,Math.sin(a)*.12,Math.cos(a)*i*.97,Math.sin(a)*i*.97,"nf-sym-strong"))}return[...o,se(0,0,i)]}case"lamp_wall":return[le(-e/2,-n/2,e/2,-n/2+.03,"nf-sym-fill"),nc(0,.01,e*.4,n*.4)];case"led_strip":return[ie(-e/2,0,e/2,0,"nf-sym-strong")];case"plant":return[se(0,0,Math.min(e,n)*.46),se(0,0,Math.min(e,n)*.25)];case"rug":return[le(-e/2+.1,-n/2+.1,e/2-.1,n/2-.1)];case"stairs":{let i=Math.max(3,Math.round(n/.26)),o=[];for(let s=1;s<i;s++)o.push(ie(-e/2,n/2-n/i*s,e/2,n/2-n/i*s));return o.push(ie(0,n/2-.1,0,-n/2+.25,"nf-sym-strong"),ie(-.15,-n/2+.45,0,-n/2+.25,"nf-sym-strong"),ie(.15,-n/2+.45,0,-n/2+.25,"nf-sym-strong")),o}default:{let i=U(t);return i?ex(i,e,n):_}}}function Q0(t,e,n){let r=Ri(t),i=kn(r,e,n,t.h),o=r.down?"nf-sym-dash":"",s=i.treads.map(l=>og(l.poly,l.landing?`nf-sym-fill ${o}`:o));i.column>0&&s.push(se(0,0,i.column,"nf-sym-fill"));let a=i.treads.map(ns);for(let l=1;l<a.length;l++)s.push(ie(a[l-1][0],a[l-1][1],a[l][0],a[l][1],"nf-sym-strong"));if(a.length&&s.unshift(se(a[0][0],a[0][1],.05,"nf-sym-fill")),a.length>=2){let[l,c]=[a[a.length-2],a[a.length-1]],d=Math.hypot(c[0]-l[0],c[1]-l[1])||1,[u,p]=[(c[0]-l[0])/d,(c[1]-l[1])/d],h=Math.min(.2,i.flight*.3);for(let f of[-1,1])s.push(ie(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 ex(t,e,n){return t.symbol?.length?t.symbol.map(r=>r.shape==="rect"?le((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"?se(r.x*e,r.z*n,r.r*Math.min(e,n)):ie(r.x1*e,r.z1*n,r.x2*e,r.z2*n)):cd(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?og([...r.stations.map(i=>[(r.x+i[3]/2)*e,i[0]*n]),...[...r.stations].reverse().map(i=>[(r.x-i[3]/2)*e,i[0]*n])]):r.shape==="cyl"&&(r.axis??"y")==="y"?se(r.x*e,r.z*n,Math.min(r.w*e,r.d*n)/2):le((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 ic=Math.PI/180,lg=(t,e,n,r)=>{let[i,o]=r,s=E`<path d="M${i-4} ${o-1}a4 4 0 1 1 2 3.5" />`,a=E`<line x1=${n[0]} y1=${n[1]} x2=${i} y2=${o} /><circle cx=${i} cy=${o} r="16" class="nf-hit" /><circle cx=${i} cy=${o} r="8" />${s}`;return t==="data-rotate"?E`<g class="nf-rotate" data-rotate=${e}>${a}</g>`:E`<g class="nf-rotate" data-aim=${e}>${a}</g>`};function tx(t,e){let n=e.rotation*ic;return[[-1,-1],[1,-1],[1,1],[-1,1]].map(([r,i])=>{let[o,s]=t.toScreen([e.x+r*e.w*Math.cos(n)/2-i*e.d*Math.sin(n)/2,e.z+r*e.w*Math.sin(n)/2+i*e.d*Math.cos(n)/2]);return E`<g class="nf-resize" data-resize=${`${e.id}:${r}:${i}`}><circle cx=${o} cy=${s} r="14" class="nf-hit" /><rect x=${o-5} y=${s-5} width="10" height="10" rx="2" /></g>`})}var ag=new WeakMap;function nx(t,e){let n=ag.get(e);if(n&&n.states===t.states)return n.links;let r=Re(t,[e]);return ag.set(e,{states:t.states,links:r}),r}function rx(t,e,n){if(!t||!de(n.type))return!1;let r=nx(t,e).get(n.id)?.entity;return!!eu(r?t.states[r]:void 0,(n.extra_lights??[]).map(i=>t.states[i]))}function cg(t,e,n){let{host:r,scale:i}=t,o=s=>{let a=s.id===n,l=a&&r.admin&&!s.locked,[c,d]=t.toScreen([s.x,s.z]),u=s.rotation*ic,p=Math.min(s.w,s.d)*i>44,h=rx(r.hass,e,s),f=Ke.includes(s.type),g=`nf-furn${a?" nf-furn-sel":""}${h?" nf-furn-lit":""}${f?" nf-energy-item":""}`,b=s.d/2+Math.max(.3,26/i),y=t.toScreen([s.x-Math.sin(u)*b,s.z+Math.cos(u)*b]),v=t.toScreen([s.x-Math.sin(u)*(s.d/2),s.z+Math.cos(u)*(s.d/2)]),[w,k]=t.toScreen([s.x+Math.sin(u)*(s.d/2+18/i),s.z-Math.cos(u)*(s.d/2+18/i)]);return E`<g data-furniture=${s.id} class=${g}>
<g transform="translate(${c} ${d}) rotate(${s.rotation}) scale(${s.mirror?-i:i} ${i})">
<rect class="nf-furn-body" x=${-s.w/2} y=${-s.d/2} width=${s.w} height=${s.d} />
<g class="nf-furn-sym">${sg(s.type,s.w,s.d,s)}</g>
<line class="nf-furn-front" x1=${-s.w/2} y1=${s.d/2} x2=${s.w/2} y2=${s.d/2} />
</g>
${p?E`<text x=${c} y=${d+4}>${Te(r.hass,s.type)}</text>`:_}
</g>
${l?tx(t,s):_}
${a?E`<text class="nf-dim" x=${w} y=${k+4}>${pe(r.hass,s.w)} × ${pe(r.hass,s.d)}</text>`:_}
${a&&s.locked?E`<text class="nf-lock" x=${y[0]} y=${y[1]+5}>🔒</text>`:_}
${l?lg("data-rotate",s.id,v,y):_}`};return E`<g>${Qf(e).map(o)}</g>`}function dg(t,e,n){let{host:r}=t,i=o=>{let s=ee(o.entity_id)??(r.hass?je(r.hass,o.entity_id):null);if(!s)return _;let[a,l]=t.toScreen([o.x,o.z]),c=r.hass?.states[o.entity_id]?.state==="on",d=o.entity_id===n,u=(o.rotation??0)*ic,p=d&&r.admin&&!o.locked&&lu(o.entity_id,r.hass?.states[o.entity_id]),h=[a-Math.sin(u)*46,l+Math.cos(u)*46],f=Vn(r,o.entity_id,o.icon);return E`${p?lg("data-aim",o.entity_id,[a,l],h):_}<g data-device=${o.entity_id} class=${`nf-device${c?" nf-device-on":""}${d?" nf-device-sel":""}`} transform="translate(${a} ${l})">
<title>${B(r.hass,o.entity_id)}</title>
<circle r="18" class="nf-hit" /><circle r="12" />
${f?E`<foreignObject class="nf-device-icon" x="-8" y="-8" width="16" height="16"><ha-icon icon=${f}></ha-icon></foreignObject>`:E`<path d=${qt(s)} transform="translate(-7.2 -7.2) scale(0.6)" />`}
</g>
${d&&o.locked?E`<text class="nf-lock" x=${a+16} y=${l-12}>🔒</text>`:_}`};return E`<g>${e.placements.map(i)}</g>`}function ug(t,e,n){return E`${(e.notes??[]).map(r=>{let[i,o]=t.toScreen([r.x,r.z]);return E`<g data-note=${r.id} class=${`nf-note${Ji(r)?" nf-note-due":""}${r.id===n?" nf-note-sel":""}`} transform="translate(${i} ${o})">
<title>${r.text}</title>
<rect x="-11" y="-11" width="22" height="22" rx="4" /><text y="5" text-anchor="middle">✎</text>
</g>`})}`}var ps=(t,e,n=6)=>E`<circle cx=${t} cy=${e} r="16" class="nf-hit" /><circle cx=${t} cy=${e} r=${n} />`;function hg(t,e){let{scale:n}=t,r=n>=90?.1:n>=30?.5:1,i=n>=20?1:5,o=t.toWorld(0,0),s=t.toWorld(e.w,e.h),a=[],l=(u,p)=>{for(let h=Math.ceil(o[0]/u)*u;h<=s[0];h+=u){let f=t.toScreen([h,0])[0];a.push(E`<line class=${p} x1=${f} y1="0" x2=${f} y2=${e.h} />`)}for(let h=Math.ceil(o[1]/u)*u;h<=s[1];h+=u){let f=t.toScreen([0,h])[1];a.push(E`<line class=${p} x1="0" y1=${f} x2=${e.w} y2=${f} />`)}};r<i&&l(r,"nf-grid-minor"),l(i,"nf-grid-major");let[c,d]=t.toScreen([0,0]);return a.push(E`<circle class="nf-origin" cx=${c} cy=${d} r="3" />`),E`<g pointer-events="none">${a}</g>`}function pg(t){let e=t.host.doc.floors.find(s=>s.id===t.floorId),n=t.host.doc.topology?t.host.doc.floors.filter(s=>e?.outdoor_location_id?s.outdoor_location_id===e.outdoor_location_id:!s.outdoor_location_id&&s.building_id===e?.building_id):t.host.doc.floors,r=n.findIndex(s=>s.id===t.floorId),i=r>0?n[r-1]:void 0;if(!i)return _;let o=Zd(n,n[r]);return E`<g pointer-events="none">${i.rooms.map(s=>E`<polygon class="nf-ghost" points=${lt(t,s.points)} />`)}${o.map(s=>E`<polygon class="nf-void" points=${lt(t,s)} />`)}</g>`}function fg(t,e){let n=t.host.floor?.height??2.5;return E`<g pointer-events="none">${e.map(r=>{let i=r.height!==void 0&&r.height<n-.01;return E`<polygon class=${`nf-wall${r.exterior?" nf-wall-ext":""}${i?" nf-wall-low":""}`} points=${lt(t,r.footprint)} />`})}</g>`}function mg(t,e,n){let r=i=>{let[o,s]=t.toScreen(ve(i.points)),a=ue(i.points),l=Math.min(a.x1-a.x0,a.z1-a.z0)*t.scale>40;return E`<g data-outdoor=${i.id} class=${`nf-out nf-out-${i.type}${i.id===n?" nf-out-sel":""}`}>
<polygon points=${lt(t,i.points)} />
${l?E`<text x=${o} y=${s+4}>${t.host.t(`out_${i.type}`)}</text>`:_}
</g>`};return E`<g>${e.outdoor.map(r)}</g>`}function gg(t,e,n){let{host:r}=t;if(!e||!r.admin||n!=="select"||r.doc.settings.lock_plan)return _;let i=e.points;return E`${i.map((o,s)=>Xo(t,o,i[(s+1)%i.length],"out",e.id,s))}${i.map((o,s)=>E`<g class="nf-vertex" data-out-vertex=${`${e.id}:${s}`}>${ps(...t.toScreen(o))}</g>`)}`}function _g(t,e,n,r){let i=e.rooms.find(s=>s.id===n),o=i&&r!==null&&r<i.points.length?[t.toScreen(i.points[r]),t.toScreen(i.points[(r+1)%i.points.length])]:null;return E`<g>${e.rooms.map(s=>E`<polygon data-room=${s.id} class=${s.id===n?"nf-room nf-room-sel":"nf-room"} points=${lt(t,s.points)} />`)}</g>
${o?E`<line class="nf-edge-hi" pointer-events="none" x1=${o[0][0]} y1=${o[0][1]} x2=${o[1][0]} y2=${o[1][1]} />`:_}
<g pointer-events="none">${e.rooms.map(s=>{let[a,l]=t.toScreen(ve(s.points));return E`<text class="nf-room-name" x=${a} y=${l-2}>${s.name}</text>
<text class="nf-room-area" x=${a} y=${l+14}>${Me(t.host.hass,ye(s.points))}</text>`})}</g>`}function bg(t,e){let n=t.host.doc.energy?.meter;if(!n||n.floor_id!==e.id)return _;let[r,i]=t.toScreen([n.x,n.z]);return E`<g class="nf-meter" transform="translate(${r} ${i})" pointer-events="none">
<rect x="-11" y="-11" width="22" height="22" rx="5" />
<path d="M1.5 -7 L-4 1 H0 L-1.5 7 L4 -1 H0 Z" />
</g>`}function yg(t,e,n){let{host:r}=t,i=o=>{let[s,a]=[t.toScreen(o.a),t.toScreen(o.b)],l=o.id===n,c=l&&r.admin&&!eo(o,!0,r.doc.settings);return E`<g data-free-wall=${o.id} class=${`nf-free-wall${l?" nf-free-wall-sel":""}`}>
<line class="nf-hit" x1=${s[0]} y1=${s[1]} x2=${a[0]} y2=${a[1]} />
<line class="nf-free-wall-line" x1=${s[0]} y1=${s[1]} x2=${a[0]} y2=${a[1]} />
</g>
${c?E`<g class="nf-vertex" data-wall-end=${`${o.id}:a`}>${ps(s[0],s[1])}</g><g class="nf-vertex" data-wall-end=${`${o.id}:b`}>${ps(a[0],a[1])}</g>`:_}`};return E`<g>${(e.walls??[]).map(i)}</g>`}function vg(t,e){let n=e.points,r=(e.wall_splits??[]).flatMap((i,o)=>{if(!i||o>=n.length)return[];let[s,a]=[n[o],n[(o+1)%n.length]],l=Math.hypot(a[0]-s[0],a[1]-s[1])||1,[c,d]=[(a[0]-s[0])/l,(a[1]-s[1])/l];return i.map(u=>{let[p,h]=t.toScreen([s[0]+c*u,s[1]+d*u]);return E`<line class="nf-split-mark" x1=${p-d*7} y1=${h+c*7} x2=${p+d*7} y2=${h-c*7} />`})});return E`${r}`}function wg(t,e,n){let r=e.points,[i,o]=t.toScreen(ve(r)),s=(l,c,d)=>{let[[u,p],[h,f]]=[t.toScreen(l),t.toScreen(c)],[g,b]=[(u+h)/2,(p+f)/2],y=Math.hypot(h-u,f-p),[v,w]=[-(f-p),h-u],k=Math.hypot(v,w)||1;return[v,w]=[v/k,w/k],v*(g-i)+w*(b-o)<0&&([v,w]=[-v,-w]),E`${y>50?E`<text class="nf-dim" x=${g+v*16} y=${b+w*16+4}>${pe(t.host.hass,Math.hypot(c[0]-l[0],c[1]-l[1]))}</text>`:_}
${y>36?E`<g data-mid=${d} class="nf-mid"><circle cx=${g} cy=${b} r="14" class="nf-hit" /><circle cx=${g} cy=${b} r="6" /><path d="M${g-3} ${b}h6M${g} ${b-3}v6" /></g>`:_}`},a=(l,c)=>{let[d,u]=t.toScreen(l);return E`<g data-vertex=${c} class=${c===n?"nf-vertex nf-vertex-sel":"nf-vertex"}>${ps(d,u)}</g><text class="nf-vertex-no" x=${d+9} y=${u-9}>${c+1}</text>`};return E`<g>${r.map((l,c)=>s(l,r[(c+1)%r.length],c))}${r.map(a)}</g>`}function xg(t,e){let n=e.rooms.flatMap(r=>{if(r.points.length<3)return[];let[i,o]=ve(r.points);return r.points.map((s,a)=>{let l=r.points[(a+1)%r.points.length],c=Math.hypot(l[0]-s[0],l[1]-s[1]);if(c<.4)return _;let d=[(s[0]+l[0])/2,(s[1]+l[1])/2],u=Math.hypot(i-d[0],o-d[1])||1,p=Math.min(.35,u/2),h=[d[0]+(i-d[0])/u*p,d[1]+(o-d[1])/u*p],[f,g]=t.toScreen(h),b=Math.atan2(l[1]-s[1],l[0]-s[0])*180/Math.PI;return b>90&&(b-=180),b<-90&&(b+=180),E`<text class="nf-dim" x=${f} y=${g} transform=${`rotate(${b.toFixed(1)} ${f} ${g})`} text-anchor="middle" dominant-baseline="middle">${pe(t.host.hass,c)}</text>`})});return E`<g pointer-events="none">${n}</g>`}function kg(t,e,n){let r=t.t;return m`<section>
<h3>✎ ${r("note")}</h3>
<div class="nf-form">
<label class="nf-field nf-wide"
>${r("note_text")}
<textarea rows="4" maxlength="500" .value=${e.text} ?disabled=${!t.admin} placeholder=${r("note_placeholder")} @change=${i=>n.patch({text:i.target.value.trim()})}></textarea>
</label>
<label class="nf-field"
>${r("note_due")}
<input type="date" .value=${e.due??""} ?disabled=${!t.admin} @change=${i=>n.patch({due:i.target.value||null})} />
</label>
${Ji(e)?m`<p class="nf-sub nf-warn nf-wide">${r("note_is_due")}</p>`:S(r("note_due_hint"),"nf-wide")}
${R(t,r("x"),e.x,i=>n.patch({x:i}))} ${R(t,r("z"),e.z,i=>n.patch({z:i}))}
${R(t,r("note_height"),e.y??Rd,i=>n.patch({y:Math.max(0,Math.min(20,Math.round(i*100)/100))}),.1,0)}
${S(r("note_height_hint"),"nf-wide")}
${ix(t,e,n)}
</div>
${Q(m`<button class="nf-btn nf-danger" ?disabled=${!t.admin} @click=${()=>n.remove()}>${r("delete")}</button>`)}
</section>`}function ix(t,e,n){let r=t.t,i=!!e.photo?.startsWith("image:"),o=async s=>{let a=s.target,l=a.files?.[0];if(a.value="",!l||!t.hass)return;let{data:c}=await or(l),d=P("img");await Wt(t.hass,d,c),n.patch({photo:`image:${d}`})};return m`${t.admin?m`<label class="nf-btn nf-wide nf-upload">📷 ${r(i?"picture_replace":"note_photo_upload")}<input type="file" accept="image/*" hidden @change=${o} /></label>`:_}
${i?m`<p class="nf-sub nf-wide">${r("picture_stored")} <button class="nf-btn nf-field-btn" ?disabled=${!t.admin} @click=${()=>n.patch({photo:null})}>${r("delete")}</button></p>`:W(t,r("picture_url"),e.photo??"",s=>n.patch({photo:s.trim()||null}),{wide:!0,placeholder:"/local/valve.jpg"})}
${S(r("note_photo_hint"),"nf-wide")}`}function ox(t,e,n,r){let i=Ne(e,n.rooms,n.walls??[]);if(!i)return null;let{room:o,edge:s}=i,a=Kt(r,e,i),l=jn(o,s,e.offset-e.width/2),c=jn(o,s,e.offset+e.width/2),d=[(c[0]-l[0])/(e.width||1),(c[1]-l[1])/(e.width||1)],u=be(o.points)>=0?1:-1,p=[-d[1]*u,d[0]*u],h=[.06,.06];return a&&(h=a.wall.free||a.wall.roomLeft===o.id?[a.wall.left,a.wall.right]:[a.wall.right,a.wall.left]),{room:o,edge:s,p0:l,p1:c,inward:p,direction:u,across:h,exterior:a?.wall.exterior??!1,at:(f,g)=>t.toScreen([f[0]+p[0]*g,f[1]+p[1]*g])}}var Et=(t,e,n="")=>E`<line class=${n} x1=${t[0]} y1=${t[1]} x2=${e[0]} y2=${e[1]} />`;function sx(t,e){let n=t.across[0]-.04,r=t.across[0]+Math.min(2,e.height),[i,o,s,a]=[t.at(t.p0,n),t.at(t.p1,n),t.at(t.p0,r),t.at(t.p1,r)];return E`${Et(i,o)}<path class="nf-open-track" d="M${i[0]} ${i[1]}L${s[0]} ${s[1]}M${o[0]} ${o[1]}L${a[0]} ${a[1]}" />`}function ax(t,e,n){let r=n.swing==="out",i=r?-e.across[1]:e.across[0],o=(e.across[0]-e.across[1])/2,s=n.hinge==="left"==e.direction>0,a=on(n,e.exterior),l=n.leaves===2,[c,d]=[e.p0,e.p1],u=[],p=qd(n.width,a,s,n);if(p){let v=w=>w<=.02?e.p0:w>=n.width-.02?e.p1:jn(e.room,e.edge,n.offset-n.width/2+w);[c,d]=[v(p.x0),v(p.x1)],u=p.panels.map(([w,k])=>[v(w),v(k)])}let h=[(c[0]+d[0])/2,(c[1]+d[1])/2],f=(l?.5:1)*Math.hypot(d[0]-c[0],d[1]-c[1]),g=u.map(([v,w])=>E`${Et(e.at(v,o+.035),e.at(w,o+.035),"nf-open-pane")}${Et(e.at(v,o-.035),e.at(w,o-.035),"nf-open-pane")}`),b=(v,w)=>{let[k,x]=e.at(v,i),[M,A]=e.at(w,i),T=e.at(v,i+(r?-f:f)),F=f*t.scale,L=(T[0]-k)*(A-x)-(T[1]-x)*(M-k)>0?1:0;return E`<path d="M${k} ${x}L${T[0]} ${T[1]}A${F} ${F} 0 0 ${L} ${M} ${A}" />`},y;return a==="passage"?y=Et(e.at(e.p0,o),e.at(e.p1,o),"nf-open-passage"):a==="sliding"?y=Et(e.at(c,i),e.at(d,i)):l?y=E`${b(c,h)}${b(d,h)}`:y=s?b(c,d):b(d,c),E`${g}${y}`}function lx(t,e){let n=(t.across[0]-t.across[1])/2;if(e.opens==="slide"){let i=e.leaves===2?4:2,o=a=>[t.p0[0]+(t.p1[0]-t.p0[0])*a,t.p0[1]+(t.p1[1]-t.p0[1])*a],s=Array.from({length:i},(a,l)=>{let c=e.leaves===2?l===1||l===2?.035:-.035:l===0?.035:-.035;return Et(t.at(o(Math.max(0,l/i-.03)),n+c),t.at(o(Math.min(1,(l+1)/i+.03)),n+c))});return E`${s}`}let r=e.leaves===2?Et(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 E`${Et(t.at(t.p0,n+.035),t.at(t.p1,n+.035))}${Et(t.at(t.p0,n-.035),t.at(t.p1,n-.035))}${r}`}function $g(t,e,n,r){let i=e.openings.find(s=>s.id===r)?.front??null,o=s=>{let a=ox(t,s,e,n);if(!a)return _;let l=[a.at(a.p0,a.across[0]+.01),a.at(a.p1,a.across[0]+.01),a.at(a.p1,-a.across[1]-.01),a.at(a.p0,-a.across[1]-.01)],c=s.type==="door"&&ea(on(s,a.exterior)),d=s.id===r||!!s.front&&s.front===i,u=`nf-open nf-open-${s.type}${c?" nf-open-front":""}${d?" nf-open-sel":""}`,p=s.type==="garage"?sx(a,s):s.type==="door"?ax(t,a,s):lx(a,s);return E`<g data-opening=${s.id} class=${u}><polygon class="nf-open-gap" points=${l.map(h=>h.join(",")).join(" ")} />${p}</g>`};return E`<g>${e.openings.map(o)}</g>`}var Sg=t=>Math.round(t*1e3)/1e3,Mg=t=>Math.round(t*100)/100;function lr(t,e){let n=[...t??[]].slice(0,e);for(;n.length<e;)n.push(null);return n}var fs=t=>t.every(e=>e===null);function Ti(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 oc(t,e,n){let r=lr(t.wall_heights,t.points.length);r[e]=n,t.wall_heights=fs(r)?void 0:r,ms(t,e,null)}function ms(t,e,n){if(n===null&&!t.wall_slopes)return;let r=lr(t.wall_slopes,t.points.length);r[e]=n,t.wall_slopes=fs(r)?void 0:r}function Eg(t,e,n,r){let[i,o]=[n,r].map(a=>Math.min(30,Math.max(.05,Sg(a)))),s=lr(t.wall_heights,t.points.length);s[e]=i,t.wall_heights=s,ms(t,e,o)}function Rg(t,e,n){let r=t.wall_heights?.[e];ms(t,e,null),typeof r=="number"&&r>=n-.005&&oc(t,e,null)}function Ag(t,e,n,r,i){let o=lr(t.wall_heights,t.points.length),s=o[e],a=Array.isArray(s)?[...s]:new Array(i).fill(typeof s=="number"?s:null);for(;a.length<i;)a.push(null);a[n]=r,o[e]=a.every(l=>l===a[0])?a[0]:a,t.wall_heights=fs(o)?void 0:o,ms(t,e,null)}function Fg(t,e,n,r){let i=Ti(t,e),o=n===void 0?0:r[n],s=n===void 0?i:r[n+1]??i;if(s-o<.4)return!1;let a=Mg((o+s)/2),l=lr(t.wall_splits,t.points.length);l[e]=[...l[e]??[],a].sort((d,u)=>d-u),t.wall_splits=l;let c=t.wall_heights?.[e];return Array.isArray(c)&&c.splice((n??0)+1,0,c[n??0]??null),!0}function Tg(t,e,n,r,i){let o=Ti(t,e),s=i.filter(d=>Math.abs(d-n)>.001&&d>0),a=Math.max(.1,Math.min(o-.1,Mg(r)));s.some(d=>Math.abs(d-a)<.1)&&(a=n);let l=t.wall_splits?.[e];if(!l)return;let c=l.findIndex(d=>Math.abs(d-n)<.001);c>=0&&(l[c]=a),l.sort((d,u)=>d-u)}function zg(t,e,n,r){let i=t.wall_splits;if(!i?.[e])return;let o=i[e].filter(a=>Math.abs(a-n)>.001);i[e]=o.length>0?o:null,i.every(a=>!a)&&(t.wall_splits=void 0);let s=t.wall_heights?.[e];Array.isArray(s)&&(s.splice(r,1),s.every(a=>a===s[0])&&(t.wall_heights[e]=s[0]??null))}function Pg(t,e,n,r,i=1){let o=lr(t.wall_thickness,t.points.length);if(r===void 0||i<2)o[e]=n;else{let s=o[e],a=Array.isArray(s)?[...s]:new Array(i).fill(typeof s=="number"?s:null);for(;a.length<i;)a.push(null);a[r]=n,o[e]=a.every(l=>l===a[0])?a[0]:a}t.wall_thickness=fs(o)?void 0:o}function Ig(t,e){let n=Math.min(1.5,Math.max(.02,Sg(t)));return Math.abs(n-e)<5e-4?null:n}var Dg=.005,Og=(t,e)=>`room:${t.id}:${e}`;function Hg(t,e,n){let r=t.t,i=e.ceiling??t.floor.height,o=e.points.length,{wall_exterior:s,wall_interior:a}=t.doc.settings,l=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,b=Array.isArray(g)?g[h??0]??null:g,y=h===void 0?Ti(e,c):(u[h+1]??Ti(e,c))-u[h],v=I=>n.setHeight(e,c,h,I),w=n.isOuter(e,c)?s:a,k=`${r("wall_n",{a:c+1,b:(c+1)%o+1})}${h===void 0?"":` \xB7 ${r("wall_part",{n:h+1})}`}`,x=h!==void 0&&h>0&&(e.wall_splits?.[c]??[]).some(I=>Math.abs(I-u[h])<.001),M=e.wall_slopes?.[c],A=h===void 0&&typeof M=="number"&&typeof d=="number",T=f??i,F=()=>n.light(c),L=()=>n.light(null);return m`<div class="nf-edge-height${c===n.lit?" nf-edge-on":""}${f!==null?" nf-edge-low":""}" @mouseenter=${F} @mouseleave=${L} @focusin=${F} @focusout=${L}>
<span><b>${k}</b><br /><span class="nf-muted">${pe(t.hass,y)}</span></span>
${f===0?m`<span class="nf-muted">${r("wall_none")}</span>`:A?m`<span class="nf-wide nf-split-row" title=${r("wall_slope_hint")}
>${R(t,r("wall_slope_start"),d,I=>n.setSlope(e,c,I,M),.05,.05)}
${R(t,r("wall_slope_end"),M,I=>n.setSlope(e,c,d,I),.05,.05)}</span
>`:R(t,r("wall_height"),T,I=>v(I>=i-Dg?null:Math.max(.05,I)),.05,.05)}
${t.admin&&A?m`<button class="nf-btn" title=${r("wall_slope_off")} @click=${()=>n.clearSlope(e,c)}>▭</button>`:_}
${t.admin&&f!==null&&!A?m`<button class="nf-btn" title=${r("wall_height_full")} @click=${()=>v(null)}>↥</button>`:_}
${t.admin&&h===void 0&&f!==0&&!A?m`<button class="nf-btn" title=${r("wall_slope_hint")} @click=${()=>n.setSlope(e,c,T,T>=i-Dg?T+1:i)}>∠ ${r("wall_slope")}</button>`:_}
${t.admin&&f!==0?m`<button class="nf-btn" title=${r("wall_none_hint")} @click=${()=>v(0)}>${r("wall_none")}</button>`:_}
${t.admin&&y>=.4?m`<button class="nf-btn" title=${r("wall_split_hint")} @click=${()=>n.cut(e,c,h)}>✂</button>`:_}
${h===void 0&&y>=.4?rs(t,Og(e,c),n.arc):_}
${(h===void 0||h===0)&&f!==0?m`<button class="nf-btn" title=${r("wall_view_hint")} @click=${()=>n.openWall(e,c)}>▣ ${r("wall_view")}</button>`:_}
${f!==0?m`<span class="nf-wide nf-split-row" title=${r("wall_thickness_hint")}
>${R(t,r("edge_thickness"),b??w,I=>n.setThickness(e,c,Ig(I,w),h,u.length),.01,.02)}
${t.admin&&b!=null?m`<button class="nf-btn" title=${r("wall_thickness_reset")} @click=${()=>n.setThickness(e,c,null,h,u.length)}>↺</button>`:_}</span
>`:_}
${h===void 0?is(t,Og(e,c),n.arc):_}
${x?m`<span class="nf-wide nf-split-row"
>${R(t,r("wall_split_at"),u[h],I=>n.moveCut(e,c,u[h],I),.05,.1)}
${t.admin?m`<button class="nf-btn" title=${r("wall_join_hint")} @click=${()=>n.join(e,c,u[h],h)}>⨉</button>`:_}</span
>`:_}
</div>`})};return m`<details class="nf-edge-box">
<summary>${r("wall_heights")}</summary>
${e.points.flatMap((c,d)=>l(d))} ${S(r("room_wall_hint"))}
</details>`}function Lg(t){let e=t?.attributes;return{temperature:"\u{1F321}",humidity:"\u{1F4A7}",carbon_dioxide:"\u2601",illuminance:"\u2600",power:"\u26A1",energy:"\u26A1"}[String(e?.device_class)]??(e?.unit_of_measurement==="\xB0C"?"\u{1F321}":"\u25C9")}function cr(t,e=[],n){let r=O(t.hass,o=>!t.hass?.states[o]?.attributes.symcon_source_entity||e.some(s=>s.entity===o)),i=(o,s)=>n(e.map(a=>a.id===o?{...a,...s}:a));return m`<div class="nf-value-links nf-wide">
<div class="nf-h3row"><h4>${t.t("device_values")}</h4><button class="nf-btn nf-value-add" title=${t.t("device_value_add")} aria-label=${t.t("device_value_add")} ?disabled=${!t.admin} @click=${()=>n([...e,{id:P("value"),entity:null}])}>+</button></div>
${e.map((o,s)=>m`<div class="nf-form nf-value-link" data-value=${o.id}>
${z(t,`${t.t("device_value")} ${s+1}`,o.entity,void 0,r,a=>i(o.id,{entity:a==="none"?null:a}))}
${W(t,t.t("device_value_icon"),o.icon??"",a=>i(o.id,{icon:a||null}),{maxlength:16,placeholder:Lg(o.entity?t.hass?.states[o.entity]:void 0)})}
${W(t,t.t("device_value_label"),o.label??"",a=>i(o.id,{label:a||null}),{maxlength:60})}
<button class="nf-link nf-value-remove nf-wide" ?disabled=${!t.admin} @click=${()=>{let a=e.filter(l=>l.id!==o.id);n(a.length?a:void 0)}}>× ${t.t("device_value_remove")}</button>
</div>`)}
${S(t.t("device_values_hint"))}
</div>`}function Cg(t,e,n){let r=e.color_entity&&e.color_entity!=="none"?e.color_entity:n;return r?t.states[r]:void 0}var sc=["none","rainbow","pulse","flicker"];function gs(t,e,n,r){let i=e.effect_animations??{},o=iu(),s=c=>sc.includes(c)||o.includes(c),a=[...new Set([...Object.keys(i),...Array.isArray(n)?n.filter(c=>typeof c=="string"):[]])],l=(c,d,u,p=!1)=>{let h=Object.prototype.hasOwnProperty.call(i,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(i).length>=100?"light_effect_count_limit":void 0;if(u.setCustomValidity?.(g?t.t(g):""),g){let y=u.closest?.("details")?.querySelector("[data-effect-feedback]");return y&&(y.textContent=t.t(g)),u.reportValidity?.(),p||(u.value=h?i[c]:""),!1}let b={...i};return d===""?delete b[c]:Object.defineProperty(b,c,{value:d,enumerable:!0,configurable:!0,writable:!0}),r({effect_animations:b}),!0};return m`<details class="nf-wide">
<summary>${t.t("light_effects")}</summary>
${S(t.t("light_effects_hint"))}
<label class="nf-check"><input type="checkbox" .checked=${e.animations_enabled!==!1} ?disabled=${!t.admin}
@change=${c=>r({animations_enabled:c.target.checked})} />${t.t("light_effects_enabled")}</label>
${a.map(c=>m`<label class="nf-field nf-wide">${c}
<select ?disabled=${!t.admin} @change=${d=>{let u=d.target;l(c,u.value,u)}}>
<option value="" ?selected=${!Object.prototype.hasOwnProperty.call(i,c)}>${t.t("light_effect_unmapped")}</option>
${Object.prototype.hasOwnProperty.call(i,c)&&!s(i[c])?m`<option selected value=${i[c]}>${i[c]} (${t.t("light_effect_unmapped")})</option>`:_}
${sc.map(d=>m`<option value=${d} ?selected=${Object.prototype.hasOwnProperty.call(i,c)&&i[c]===d}>${t.t(`light_animation_${d}`)}</option>`)}
${o.map(d=>m`<option value=${d} ?selected=${Object.prototype.hasOwnProperty.call(i,c)&&i[c]===d}>${d} (${t.t("plugin")})</option>`)}
</select></label>`)}
<label class="nf-field nf-wide">${t.t("light_effect_add")}<input type="text" ?disabled=${!t.admin} placeholder="Regenbogen"
@input=${c=>c.target.setCustomValidity("")}
@change=${c=>{let d=c.target;l(d.value,"none",d,!0)&&(d.value="")}} /></label>
${S(`${t.t("light_effect_name_limit")} ${t.t("light_effect_count_limit")}`)}
<p class="nf-sub" data-effect-feedback role="status" aria-live="polite"></p>
</details>`}var cx=/speaker|sound|subwoofer|receiver|smart_|display|tv|media|turntable|projector|console/;function dx(t,e,n){let r=ee(e),i=t.hass?.language??"en",o=[...io.map(a=>({type:a,label:t.t(`furn_${a}`)})),...n.flatMap(a=>a.items.map(l=>({type:he(a.id,l.id),label:`${Je(l,he(a.id,l.id),i)} \xB7 ${Ve(a,i)}`})))],s=a=>r==="light"?de(a):r==="climate"?a==="radiator"||Tn(a):e.startsWith("vacuum.")?a==="robot_vacuum"||wt(a)&&a.endsWith(":robot_vacuum"):r==="media"?Hr(a)||Tt(a)&&cx.test(a):Tt(a)&&!de(a);return o.filter(a=>s(a.type)).sort((a,l)=>a.label.localeCompare(l.label))}function ux(t,e,n){if(!t.admin)return _;let r=dx(t,e.entity_id,n.packs);return r.length===0?_:m`<label class="nf-field nf-wide" title=${t.t("as_furniture_hint")}
>${t.t("as_furniture")}
<select @change=${i=>i.target.value&&n.asFurniture(e,i.target.value)}>
<option value="" selected>${t.t("as_furniture_pick")}</option>
${r.map(i=>m`<option value=${i.type}>${i.label}</option>`)}
</select>
</label>`}function hx(t,e,n){let r=t.hass?.language??"en";return su(e.entity_id,t.hass?.states[e.entity_id]).map(({pluginId:i,name:o,settings:s})=>{let a=au(s,e.plugin?.[i]),l=(d,u)=>n({plugin:{...e.plugin??{},[i]:{...e.plugin?.[i]??{},[d]:u}}}),c=s.map(d=>{let u=po(d.label,r),p=d.hint?po(d.hint,r):void 0;if(d.type==="boolean")return D(t,u,a[d.key]===!0,f=>l(d.key,f),{title:p});if(d.type==="select"){let f=(d.options??[]).map(([g,b])=>[g,po(b,r)]);return H(t,u,String(a[d.key]),f,g=>l(d.key,g),{wide:!0,title:p})}let h=f=>Math.min(d.max??1/0,Math.max(d.min??-1/0,f));return R(t,u,Number(a[d.key]),f=>l(d.key,h(f)),d.step??1,d.min)});return m`<h4 class="nf-lib-head nf-wide">🔌 ${o}</h4>${c}`})}function ac(t,e,n){let r=t.t,i=ee(e.entity_id)??(t.hass?je(t.hass,e.entity_id):null),o=i==="light",s=e.mount??"ceiling",a=i?lo(i,t.floor?ht(t.floor,e.x,e.z):2.5,o?s:null):1,l=p=>n.update(p),c=Vn(t,e.entity_id,e.icon),d=p=>l({mount:p,y:null}),u=["ceiling","floor","table","wall"].map(p=>[p,r(`lamp_${p}`)]);return m`<section>
<div class="nf-h3row"><h3>${r("device")}</h3>${n.lockButton}</div>
<p class="nf-dev-title">
${c?m`<ha-icon class="nf-dev-icon" .icon=${c}></ha-icon>`:m`<svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d=${i?qt(i):""} /></svg>`}
${B(t.hass,e.entity_id)}
</p>
<div class="nf-form">
${i==="cover"?z(t,r("cover_tilt_entity"),e.cover_tilt??null,void 0,O(t.hass,p=>p.startsWith("cover.")),p=>l({cover_tilt:p&&p!=="none"?p:null}),{types:[1,2],role:"cover"}):_}
${i==="cover"?m`
${D(t,r("cover_direction_invert"),!!e.cover_inverted,p=>l({cover_inverted:p||void 0}))}
${D(t,r("cover_tilt_direction_invert"),!!e.cover_tilt_inverted,p=>l({cover_tilt_inverted:p||void 0}))}
${z(t,r("cover_position_entity"),e.position??null,void 0,O(t.hass,p=>bo(t.hass,p)),p=>l({position:p&&p!=="none"?p:null}),{types:[1,2]})}
${e.position?D(t,r("cover_position_invert"),!!e.position_inverted,p=>l({position_inverted:p||void 0})):_}
${S(r("cover_direction_hint"),"nf-wide")}`:_}
${o?m`${H(t,r("lamp_mount"),s,u,d,{wide:!0})}${dn(t,e.glow_scale,p=>l({glow_scale:p}))}`:_}
${o?gs(t,e,t.hass?.states[e.entity_id]?.attributes.effect_list,l):_}
${e.entity_id.startsWith("media_player.")?dn(t,e.sound_rings,p=>l({sound_rings:p}),{label:"sound_rings",hint:"sound_rings_hint",lowest:0}):_}
${R(t,r("x"),e.x,p=>l({x:p}))} ${R(t,r("z"),e.z,p=>l({z:p}))}
${R(t,r("marker_height"),e.y??a,p=>l({y:Math.max(0,p)}),.05,0)}
${R(t,r("rotation"),e.rotation??0,p=>l({rotation:(p%360+360)%360}),1)}
${o?D(t,r("device_simple"),!!e.simple,p=>l({simple:p||void 0}),{title:r("device_simple_hint")}):_}
${i&&Xd.has(i)?D(t,r("device_confirm"),!!e.confirm,p=>l({confirm:p}),{title:r("device_confirm_hint")}):_}
${D(t,r("device_outside"),!!e.outside,p=>l({outside:p||void 0}),{title:r("device_outside_hint")})}
${Wn(t,e.marker??null,p=>l({marker:p}))}
${Vt(t,e.pin_offset,p=>l({pin_offset:p}))}
${W(t,r("device_name"),e.name??"",p=>l({name:p||null}),{wide:!0,maxlength:60,title:r("device_name_hint"),placeholder:B(t.hass,e.entity_id)})}
${e.name?D(t,r("show_name"),!!e.show_name,p=>l({show_name:p||void 0})):_}
${Bt(t,e.icon,p=>l({icon:p}))}
${hx(t,e,l)}
${cr(t,e.values,p=>l({values:p}))}
</div>
${t.admin?m`<div class="nf-actions">
<button class="nf-btn" @click=${()=>n.centre()}>${r("device_centre")}</button>
${e.y!==null?m`<button class="nf-btn" @click=${()=>l({y:null})}>${r("height_auto")}</button>`:_}
${ux(t,e,n)}
<button class="nf-btn nf-danger" @click=${()=>n.remove()}>${r("devices_remove")}</button>
</div>`:_}
</section>`}var dr=t=>t==="wallbox"||/^pack:[^:]+:(wallbox|ev_charger|ev_bike_charger|charging_station)$/.test(t);function Ng(t,e,n){if(!dr(e.type))return _;let r=t.t,i=e.charging??{},o=O(t.hass,()=>!0),s=d=>{let u={...i,...d};n({charging:Object.values(u).some(p=>p!=null)?u:null})},a=[["auto",r("charging_auto")],["value",r("charging_value")],["seconds",r("charging_unix_seconds")],["milliseconds",r("charging_unix_ms")]],l=[["auto",r("charging_auto")],["value",r("charging_value")],["seconds",r("charging_seconds")],["minutes",r("charging_minutes")],["hours",r("charging_hours")]],c=(d,u,p)=>z(t,u,i[d]??null,void 0,o,h=>s({[d]:h==="none"?null:h}),{types:p});return m`<div class="nf-form nf-links nf-charging-links">
<b class="nf-wide">${r("charging_data")}</b>
${S(r("charging_hint"),"nf-wide")}
${c("soc",r("furn_soc"),[1,2])}
${c("start",r("charging_start"),[1,2,3])}
${i.start&&i.start!=="none"?H(t,`${r("charging_start")} \xB7 ${r("charging_time_format")}`,i.start_format??"auto",a,d=>s({start_format:d}),{wide:!0}):_}
${c("end",r("charging_end"),[1,2,3])}
${i.end&&i.end!=="none"?H(t,`${r("charging_end")} \xB7 ${r("charging_time_format")}`,i.end_format??"auto",a,d=>s({end_format:d}),{wide:!0}):_}
${c("duration",r("charging_duration"),[1,2,3])}
${i.duration&&i.duration!=="none"?H(t,r("charging_duration_unit"),i.duration_unit??"auto",l,d=>s({duration_unit:d}),{wide:!0}):_}
${c("energy",r("charging_energy"),[1,2])}
${c("lock",r("charging_lock"),[1])}
</div>`}var zi=t=>Number(t);function _s(t){if(Array.isArray(t)){let[o,s]=[zi(t[0]),zi(t[1])];return Number.isFinite(o)&&Number.isFinite(s)?[o,s]:null}if(!t||typeof t!="object")return null;let{x:e,y:n}=t,[r,i]=[zi(e),zi(n)];return Number.isFinite(r)&&Number.isFinite(i)?[r,i]:null}function Wg(t){return t?_s(t.charger)??_s(t.charger_position):null}function bs(t){for(let[e,n]of Object.entries(t.states))if(e.startsWith("camera.")&&(_s(n.attributes?.vacuum_position)??Wg(n.attributes)))return e;return null}var lc=(t,e)=>e?[t[0],-t[1]]:t;var Kg=5e-4,jg=2,px=1.5;function cc(t,e){let n=e?t.states[e]?.attributes:void 0;return{at:n?_s(n.vacuum_position):null,dock:Wg(n)}}function Gg(t,e,n=!1){let r=Math.hypot(e.plan[0]-t.plan[0],e.plan[1]-t.plan[1]),i=Math.hypot(e.grid[0]-t.grid[0],e.grid[1]-t.grid[1]);if(!(i>1e-6)||!(r>=px))return{cal:null,reason:"close"};let o=r/i;return o>=Kg&&o<=jg?{cal:{a:t.plan,ga:t.grid,b:e.plan,gb:e.grid,mirror:n}}:{cal:null,reason:"scale"}}function Ug(t,e){let n=e?t.states[e]?.attributes?.rooms:void 0;if(!n||typeof n!="object")return[];let r=[];for(let i of Object.values(n)){if(!i||typeof i!="object")continue;let o=i,s=typeof o.name=="string"?o.name.trim():"",a=[o.x0,o.y0,o.x1,o.y1].map(zi);!s||!a.every(Number.isFinite)||r.push({name:s,center:[(a[0]+a[2])/2,(a[1]+a[3])/2]})}return r}var Bg=t=>t.toLocaleLowerCase().normalize("NFKD").replace(/[̀-ͯ]/g,"").replace(/[^\p{L}\p{N}]+/gu,"");function fx(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]),[i,o]=t.reduce((h,f)=>[h[0]+f.plan[0]/e,h[1]+f.plan[1]/e],[0,0]),[s,a,l]=[0,0,0];for(let h of t){let[f,g]=[h.seen[0]-n,h.seen[1]-r],[b,y]=[h.plan[0]-i,h.plan[1]-o];s+=f*b+g*y,a+=f*y-g*b,l+=f*f+g*g}if(!(l>1e-9))return null;let[c,d]=[s/l,a/l],u=h=>{let[f,g]=[h[0]-n,h[1]-r];return[i+c*f-d*g,o+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 Zg(t,e,n=!1){let r=new Map(e.map(g=>[Bg(g.name),g])),i=[],o=new Set;for(let g of t){let b=Bg(g.name),y=r.get(b);if(!y||o.has(b)||g.points.length<3)continue;o.add(b);let v=g.points.map(k=>k[0]),w=g.points.map(k=>k[1]);i.push({name:g.name,plan:[(Math.min(...v)+Math.max(...v))/2,(Math.min(...w)+Math.max(...w))/2],grid:y.center})}let s=i.map(g=>g.name);if(i.length<2)return{cal:null,reason:"rooms",matched:s};let l=(i.length>=3?[!1,!0]:[n]).flatMap(g=>{let b=fx(i.map(y=>({plan:y.plan,seen:lc(y.grid,g)})));return b?[{mirror:g,...b}]:[]}).sort((g,b)=>g.rms-b.rms)[0];if(!l)return{cal:null,reason:"rooms",matched:s};if(!(l.scale>=Kg&&l.scale<=jg))return{cal:null,reason:"scale",matched:s};let c=Math.max(...i.map(g=>Math.hypot(g.plan[0]-i[0].plan[0],g.plan[1]-i[0].plan[1])));if(!(l.rms<=Math.max(1,c/4)))return{cal:null,reason:"fit",matched:s};let[d,u,p]=[0,1,-1];for(let g=0;g<i.length;g++)for(let b=g+1;b<i.length;b++){let y=Math.hypot(i[g].grid[0]-i[b].grid[0],i[g].grid[1]-i[b].grid[1]);y>p&&([d,u,p]=[g,b,y])}let[h,f]=[i[d].grid,i[u].grid];return{cal:{a:l.map(lc(h,l.mirror)),ga:h,b:l.map(lc(f,l.mirror)),gb:f,mirror:l.mirror},matched:s,rms:l.rms}}function qg(t,e){let[n,r]=[(t.a[0]+t.b[0])/2,(t.a[1]+t.b[1])/2],i=(e.turn??0)*Math.PI/180,[o,s,a]=[Math.cos(i),Math.sin(i),e.grow??1],[l,c]=e.move??[0,0],d=u=>{let[p,h]=[(u[0]-n)*a,(u[1]-r)*a];return[Vg(n+p*o-h*s+l),Vg(r+p*s+h*o+c)]};return{...t,a:d(t.a),b:d(t.b)}}var Vg=t=>Math.round(t*1e3)/1e3;var mx=/^(binary_sensor|switch|input_boolean|light|fan|person|device_tracker|sensor)\./,Rt=t=>t==="none"?null:t;function dc(t,e,n){let r=t.t,i=O(t.hass,l=>mx.test(l)),o=!!e.state_entity&&e.state_entity!=="none",s=o&&!!e.state_entity2&&e.state_entity2!=="none",a=[["left_right",r("furn_state_left_right")],["top_bottom",r("furn_state_top_bottom")]];return m`${z(t,r("furn_state_entity"),e.state_entity??null,void 0,i,l=>n.update({state_entity:Rt(l)}))}
${o?z(t,r("furn_state_entity2"),e.state_entity2??null,void 0,i,l=>n.update({state_entity2:Rt(l)})):_}
${s?H(t,r("furn_state_split"),e.state_split==="top_bottom"?"top_bottom":"left_right",a,l=>n.update({state_split:l})):_}
${S(r("furn_state_hint"),"nf-wide")}`}function gx(t,e){let r=Cn(t.type)&&(!wt(t.type)||ud(t.type));return de(t.type)?{accept:i=>/^(light|switch|input_boolean)\./.test(i),label:"furn_entity_light"}:t.type==="radiator"||Tn(t.type)?{accept:i=>i.startsWith("climate."),label:"furn_entity_climate"}:r?{accept:i=>/^(media_player|switch|input_boolean|light)\./.test(i),label:"furn_entity_tv"}:t.type==="robot_vacuum"?{accept:i=>i.startsWith("vacuum."),label:"furn_entity_vacuum"}:/:(robot_mower|mower_dock)$/.test(t.type)?{accept:i=>i.startsWith("lawn_mower."),label:"furn_entity_mower"}:/:(sprinkler|valve_box)$/.test(t.type)?{accept:i=>/^(valve|switch|input_boolean)\./.test(i),label:"furn_entity_water"}:{accept:i=>/^(switch|media_player|fan|input_boolean|climate|vacuum|cover|valve)\./.test(i)||Jd(e?.states[i]),label:"furn_entity"}}function ys(t,e,n){if(!t.hass)return null;let r=structuredClone(t.doc.floors);for(let i of r)for(let o of i.furniture)o.id===e.id&&(o[n==="fan"?"fan_entity":n]=null);return Re(t.hass,r).get(e.id)?.[n]??null}var _x=t=>t==="meter"?"energy_grid":t==="inverter"?"energy_solar_sensor":t==="home_battery"?"energy_battery_sensor":"furn_power",ct=(...t)=>m`<div class="nf-form nf-links">${t}</div>`;async function bx(t){let e=t.hass?bs(t.hass):null;if(!t.hass||!e)return{at:null,dock:null};let n=()=>{let i=t.hass?.states[e]?.attributes??{};return`${String(i.render_count??"")}|${JSON.stringify(i.vacuum_position??null)}`},r=n();try{await t.hass.fetchWithAuth?.(`/api/camera_proxy/${e}`)}catch{}for(let i=0;i<8&&n()===r;i++)await new Promise(o=>setTimeout(o,100));return cc(t.hass,e)}function yx(t,e){let n=t.t,r=l=>t.change(c=>{c.settings.vacuum_map=qg(e,l)}),i=(l,c,d)=>m`<button class="nf-btn" title=${c} aria-label=${c} ?disabled=${!t.admin} @click=${()=>r(d)}>${l}</button>`,[o,s,a]=[n("robot_cal_nudge_move"),n("robot_cal_nudge_turn"),n("robot_cal_nudge_grow")];return m`${S(n("robot_cal_nudge"),"nf-wide")}
<div class="nf-wide" style="display:flex;flex-wrap:wrap;gap:6px">
${i("\u2190",o,{move:[-.1,0]})}${i("\u2192",o,{move:[.1,0]})}${i("\u2191",o,{move:[0,-.1]})}${i("\u2193",o,{move:[0,.1]})}
${i("\u27F2",s,{turn:-1})}${i("\u27F3",s,{turn:1})}${i("\u2212",a,{grow:.99})}${i("+",a,{grow:1.01})}
</div>`}function vx(t,e){let n=t.t,r=t.doc.settings.vacuum_map??null,i=t.hass?cc(t.hass,bs(t.hass)):{at:null,dock:null},o=r?Math.hypot(r.gb[0]-r.ga[0],r.gb[1]-r.ga[1]):0,s=r&&o>0?Math.hypot(r.b[0]-r.a[0],r.b[1]-r.a[1])/o:0,a=()=>{t.pickPoint(p=>{p&&bx(t).then(h=>{if(!h.at||!h.dock)return;let f={plan:[e.x,e.z],grid:h.dock},g=Gg(f,{plan:p,grid:h.at},r?.mirror??!1);g.cal&&t.change(b=>{b.settings.vacuum_map=g.cal})})})},l=t.hass?bs(t.hass):null,c=t.hass?Ug(t.hass,l):[],d=t.doc.floors.find(p=>p.furniture.some(h=>h.id===e.id)),u=()=>{if(!d)return;let p=Zg(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 ct(S(i.at&&i.dock?r?n("robot_cal_done",{m:s.toFixed(2)}):n("robot_cal_none"):n("robot_cal_need"),"nf-wide"),c.length>=2?m`<button class="nf-btn nf-wide" ?disabled=${!t.admin||!d} @click=${u}>${n("robot_cal_rooms",{n:c.length})}</button>`:_,m`<button class="nf-btn nf-wide" ?disabled=${!t.admin||!i.at||!i.dock} @click=${a}>${n("robot_cal_do")}</button>`,r?D(t,n("robot_cal_mirror"),!!r.mirror,p=>t.change(h=>{h.settings.vacuum_map={...r,mirror:p}})):_,r?yx(t,r):_,r?m`<button class="nf-btn nf-wide" ?disabled=${!t.admin} @click=${()=>t.change(p=>{p.settings.vacuum_map=null})}>${n("robot_cal_forget")}</button>`:_,S(n("robot_cal_hint"),"nf-wide"))}function wx(t,e,n){let r=t.t,i=t.doc;if(!i.energy.advanced)return _;let o=Jn(i),s=i.floors.flatMap(a=>a.furniture.filter(l=>o.has(l.id)).map(l=>[l.id,`${l.name||r("furn_meter")} \xB7 ${a.name}`]));return ct(H(t,r("meter_parent"),hi(i,e)??"",[["",r("meter_main")],...s],a=>n.update({parent_meter:a||null}),{wide:!0}),S(r("meter_device_hint"),"nf-wide"))}function xx(t,e,n){let r=t.t,i=t.doc;if(!i.energy.advanced)return _;let o=i.floors.flatMap(c=>c.furniture.filter(d=>Dh(i,e,d)).map(d=>[d.id,`${d.name||r("furn_meter")} \xB7 ${c.name}`])),s=!!yn(i,e),a=e.meter_floors??[],l=(c,d)=>n.update({meter_floors:d?[...a.filter(u=>u!==c),c]:a.filter(u=>u!==c)});return ct(H(t,r("meter_parent"),s?e.parent_meter:"",[["",r("meter_parent_none")],...o],c=>n.update({parent_meter:c||null}),{wide:!0}),s?D(t,r("energy_invert"),!!e.meter_invert,c=>n.update({meter_invert:c})):_,s?m`<div class="nf-sub nf-wide">${r("meter_floors")}</div>${i.floors.map(c=>D(t,c.name,a.includes(c.id),d=>l(c.id,d)))}`:_,S(r("meter_sub_hint"),"nf-wide"))}function Yg(t,e,n,r){let i=t.t,o=n==="mail"?s=>/^(binary_sensor|sensor|input_boolean)\./.test(s):s=>/^(sensor|binary_sensor|calendar)\./.test(s);return m`<div class="nf-form nf-links">
${z(t,i(`care_entity_${n}`),e.care_entity??null,void 0,O(t.hass,o),s=>r.update({care_entity:Rt(s)}))}
${n==="plant"?R(t,i("care_thirsty_below"),e.thirsty_below??20,s=>r.update({thirsty_below:Math.min(90,Math.max(1,Math.round(s)))}),1,1):_}
${S(i(`care_hint_${n}`),"nf-wide")}
</div>`}function Xg(t,e,n){let r=t.t;return m`<div class="nf-form nf-links">
${z(t,r("furn_cover_entity"),e.cover_entity??null,void 0,O(t.hass,i=>i.startsWith("cover.")),i=>n.update({cover_entity:Rt(i)}),{types:[1,2],role:"cover"})}
${D(t,r("furn_cover_inverted"),!!e.cover_inverted,i=>n.update({cover_inverted:i||void 0}),{title:r("furn_cover_inverted_hint")})}
${S(r("furn_cover_hint"),"nf-wide")}
</div>`}function Jg(t,e,n,r){let i=t.t,o=/socket/.test(e.type),s=O(t.hass,c=>/^(light|switch|input_boolean|fan)\./.test(c)),a=e.gang_entities??[],l=c=>d=>{let u=Array.from({length:n},(p,h)=>a[h]??null);u[c]=Rt(d),r.update({gang_entities:u})};return m`<div class="nf-form nf-links">
${Array.from({length:n},(c,d)=>z(t,n===1?i(o?"gang_socket_one":"gang_switch_one"):i(o?"gang_socket":"gang_switch",{n:d+1}),a[d]??null,void 0,s,l(d),{types:[0,1,2],role:"light"}))}
${S(i(o?"gang_socket_hint":"gang_switch_hint"),"nf-wide")}
</div>`}function kx(t,e,n){let r=t.t,i=O(t.hass,o=>{let s=t.hass?.states[o]?.attributes;return o.startsWith("sensor.")&&(s?.device_class==="temperature"||s?.unit_of_measurement==="\xB0C"||s?.unit_of_measurement==="\xB0F")});return ct(z(t,r("fridge_temp"),e.temp_entity??null,void 0,i,o=>n.update({temp_entity:Rt(o)}),{types:[1,2]}),z(t,r("freezer_temp"),e.temp_entity2??null,void 0,i,o=>n.update({temp_entity2:Rt(o)}),{types:[1,2]}),S(r("fridge_temp_hint"),"nf-wide"))}function $x(t,e,n){let r=t.t,i=O(t.hass,o=>{let s=t.hass?.states[o]?.attributes;return o.startsWith("sensor.")&&(s?.device_class==="temperature"||s?.unit_of_measurement==="\xB0C"||s?.unit_of_measurement==="\xB0F")});return ct(z(t,r("device_temp"),e.temp_entity??null,void 0,i,o=>n.update({temp_entity:Rt(o)}),{types:[1,2]}),S(r("device_temp_hint"),"nf-wide"))}function Sx(t,e,n){let r=t.t,i=e.extra_lights??[],o=O(t.hass,l=>l.startsWith("light.")&&l!==e.entity&&l!==e.color_entity),s=l=>c=>{let d=[...i];c&&c!=="none"?d[l]=c:d.splice(l,1),n.update({extra_lights:d.filter(Boolean).length?d.filter(Boolean):void 0})},a=Math.min(4,i.length+1);return m`${Array.from({length:a},(l,c)=>z(t,r("lamp_extra_light",{n:c+2}),i[c]??null,void 0,o,s(c),{types:[0,1,2],role:"light"}))}${S(r("lamp_extra_hint"),"nf-wide")}`}function Qg(t,e,n){let{hass:r}=t;if(!r)return _;let i=t.t,o=de(e.type),s=gx(e,r),a=O(r,b=>Z(r)?Le(r,b,[1,2]):Nn(r,b)),l=b=>y=>n.update({[b]:Rt(y)}),c=b=>O(r,b),d=(t.doc.settings.roof.strings??[]).filter(b=>b.inverter===e.id).map(b=>b.name),u=!!e.entity&&e.entity!=="none",p=ys(t,e,"power"),h=e.power==="none"?null:e.power||p,f=e.type==="fridge_smart"?c(b=>b.startsWith("binary_sensor.")):[],g=e.type==="ceiling_fan"?"fan_hint":o?e.type==="lamp_pendant"?"lamp_hint_pendant":"lamp_hint":Cn(e.type)?"furn_links_hint_tv":e.type==="robot_vacuum"?"robot_hint":"furn_links_hint";return m`${ct(e.type==="grid_point"?S(i("grid_point_hint"),"nf-wide"):z(t,i(s.label),e.entity??null,ys(t,e,"entity"),c(s.accept),b=>n.update({entity:b}),o?{types:[0,1,2],role:"light"}:{}),e.type==="ceiling_fan"?z(t,i("furn_fan_entity"),e.fan_entity??null,ys(t,e,"fan"),c(b=>b.startsWith("fan.")),b=>n.update({fan_entity:b}),{types:[0,1,2]}):_,!o&&!Ke.includes(e.type)&&!Hr(e.type)?dc(t,e,n):_,o&&u?m`${z(t,i("furn_color_entity"),e.color_entity??null,void 0,c(b=>b.startsWith("light.")&&b!==e.entity),l("color_entity"),{types:[0,1,2],role:"light"})}${S(i("furn_color_entity_hint"),"nf-wide")}`:_,o&&u?Sx(t,e,n):_,o?dn(t,e.glow_scale,b=>n.update({glow_scale:b})):_,o?gs(t,e,Cg(r,e,e.entity&&e.entity!=="none"?e.entity:ys(t,e,"entity"))?.attributes.effect_list,n.update):_,Hr(e.type)?dn(t,e.ambilight,b=>n.update({ambilight:b}),{label:"ambilight",hint:"ambilight_hint",lowest:0}):_,Cn(e.type)||vo(e.type)?dn(t,e.sound_rings,b=>n.update({sound_rings:b}),{label:"sound_rings",hint:"sound_rings_hint",lowest:0}):_,e.type==="grid_point"?_:m`${z(t,i(yn(t.doc,e)?"meter_sub_power":_x(e.type)),e.power??null,p,a,b=>n.update({power:b}),{types:[1,2]})}
${D(t,i(dr(e.type)?"charging_card":"furniture_power_card"),!!e.power_card,b=>n.update({power_card:b||void 0}))}${S(i(dr(e.type)?"charging_hint":"furniture_power_card_hint"),"nf-wide")}`)}
${wu(e.type)?kx(t,e,n):o||e.type==="grid_point"?_:$x(t,e,n)}
${e.type==="meter"?xx(t,e,n):_}
${e.type==="inverter"||e.type==="home_battery"?wx(t,e,n):_}
${e.type==="meter"&&!yn(t.doc,e)?ct(z(t,i("furn_export"),e.export??null,void 0,a,l("export"),{types:[1,2]}),S(i("furn_export_hint"),"nf-wide")):_}
${e.type==="inverter"&&(t.doc.settings.roof.solar??[]).length>0?S(d.length>0?i("inverter_strings",{names:d.join(", ")}):i("inverter_strings_none"),"nf-wide"):_}
${e.type==="home_battery"?ct(z(t,i("furn_soc"),e.soc??null,void 0,c(b=>ge(b)&&(r.states[b]?.attributes.device_class==="battery"||r.states[b]?.attributes.unit_of_measurement==="%")),l("soc"),{types:[1,2]}),z(t,i("furn_charge"),e.charge??null,void 0,a,l("charge"),{types:[1,2]}),S(i("furn_charge_hint"),"nf-wide")):_}
${dr(e.type)?ct(z(t,i("furn_wallbox_status"),e.status??null,void 0,c(b=>wo(b)||ge(b)),l("status"),{types:[0,1,2,3]})):_}
${Ng(t,e,n.update)}
${!o||u||h?m`${D(t,i("device_confirm"),!!e.confirm,b=>n.update({confirm:b}),{title:i("device_confirm_hint")})}
<div class="nf-form">${Wn(t,e.marker??null,b=>n.update({marker:b}))}${Bt(t,e.icon,b=>n.update({icon:b}))}${o?_:Vt(t,e.pin_offset,b=>n.update({pin_offset:b}))}</div>`:_}
${e.type==="robot_vacuum"?ct(z(t,i("furn_robot_room"),e.room_sensor??null,Su(r,Re(r,t.doc.floors).get(e.id)?.entity??null,null),c(ge),b=>n.update({room_sensor:b}),{types:[1,2]})):_}
${e.type==="robot_vacuum"&&u?vx(t,e):_}
${e.type==="fridge_smart"?m`${ct(z(t,i("furn_door_left"),e.door_left??null,void 0,f,b=>n.update({door_left:b}),{types:[0]}),z(t,i("furn_door_right"),e.door_right??null,void 0,f,b=>n.update({door_right:b}),{types:[0]}))}
${S(i("fridge_hint"))}`:_}
${cr(t,e.values,b=>n.update({values:b}))}
${S(i(g))}`}var Mx=/^(binary_sensor|device_tracker|input_boolean|switch|sensor)\./,Ex=/^(sensor|input_select|select|input_text)\./,Rx=/^(device_tracker|sensor|binary_sensor|lock|climate)\./,Ax=(t,e)=>t.flatMap(n=>n.items.filter(r=>r.vehicle).map(r=>({id:he(n.id,r.id),label:`${Je(r,he(n.id,r.id),e)} \xB7 ${Ve(n,e)}`})));function e_(t,e){return e.startsWith("device_tracker.")?t.hass?.states[e]?.attributes.source_type==="router"?2:0:1}function t_(t,e,n,r){return m`<select ?disabled=${!t.admin} @change=${i=>r(i.target.value||null)}>
<option value="" ?selected=${!n}>${t.t("parking_vehicle_none")}</option>
${e.map(i=>m`<option value=${i.id} ?selected=${i.id===n}>${i.label}</option>`)}
</select>`}function Fx(t,e,n,r){let i=t.t,o=e.type_entity?t.hass?.states[e.type_entity]:void 0,s=Array.isArray(o?.attributes.options)?o.attributes.options:[],a=e.types??[],l=d=>r.update({types:d}),c=(d,u)=>l(a.map((p,h)=>h===d?{...p,...u}:p));return m`<div class="nf-wide">
<div class="nf-sub">${i("parking_types")}</div>
${a.map((d,u)=>m`<div class="nf-parking-row">
<input type="text" list="nf-parking-states" placeholder=${i("parking_type_state")} .value=${d.state} ?disabled=${!t.admin} @change=${p=>c(u,{state:p.target.value})} />
${t_(t,n,d.vehicle,p=>c(u,{vehicle:p??""}))}
<button class="nf-btn" ?disabled=${!t.admin} title=${i("delete")} @click=${()=>l(a.filter((p,h)=>h!==u))}>✕</button>
</div>`)}
<datalist id="nf-parking-states">${s.map(d=>m`<option value=${d}></option>`)}</datalist>
${t.admin?m`<button class="nf-btn" @click=${()=>l([...a,{state:s[a.length]??"",vehicle:n[0]?.id??""}])}>${i("parking_add_type")}</button>`:_}
</div>`}function n_(t,e,n,r){let i=t.t,o=Ax(n,t.hass?.language??"en"),s=O(t.hass,f=>Mx.test(f)).sort((f,g)=>e_(t,f.id)-e_(t,g.id)),a=O(t.hass,f=>Ex.test(f)),l=e.car??{},c=t.floor,d=c?.rooms.find(f=>f.points.length>=3&&C([e.x,e.z],f.points)),u=e.vehicle?U(e.vehicle):void 0,p=u?u.size[2]*(e.scale??1):0,h=!!d&&!!c&&p>c.height+1e-6;return m`<div class="nf-form nf-links">
${z(t,i("parking_entity"),e.entity??null,void 0,s,f=>r.update({entity:f==="none"?null:f}))}
<label class="nf-field nf-wide">${i("parking_vehicle")} ${t_(t,o,e.vehicle??null,f=>r.update({vehicle:f}))}</label>
${o.length>0?_:S(i("parking_no_pack"),"nf-wide")}
${R(t,i("parking_scale"),Math.round((e.scale??1)*100),f=>r.update({scale:Math.min(150,Math.max(30,f))/100}),5,30)}
${z(t,i("parking_type_entity"),e.type_entity??null,void 0,a,f=>r.update({type_entity:f==="none"?null:f}))}
${e.type_entity?Fx(t,e,o,r):_}
</div>
${h?m`<p class="nf-sub nf-warn">${i("parking_too_tall",{car:K(t.hass,p,2),room:K(t.hass,c.height,2)})}</p>`:_}
${S(i("parking_hint"))}
${t.hass?m`${z(t,i("live_car_device"),l.device??null,null,O(t.hass,f=>Rx.test(f)),f=>r.update({car:{...l,device:f}}))}
${S(i("live_car_device_hint"),"nf-wide")}
${z(t,i("live_car_departure_entity"),l.departure??null,void 0,O(t.hass,f=>/^(sensor|input_datetime|time|datetime)\./.test(f)),f=>r.update({car:{...l,departure:f==="none"?null:f}}))}`:_}`}function r_(t,e){let r=kn(t,e.w,e.d,e.h).treads.findIndex(i=>i.landing);return r>=0?r+1:1}function Tx(t){let e=kn(Ri(t),t.w,t.d,t.h),n=e.treads.map(ns),r=0;for(let o=1;o<n.length;o++)r+=Math.hypot(n[o][0]-n[o-1][0],n[o][1]-n[o-1][1]);let i=n.length>1?r/(n.length-1):0;return{rise:e.rise,going:i,measure:2*e.rise+i,steps:e.steps}}function zx(t){let[e,n]=El[t],r=kn({..._t,shape:t},e,n,2.8),i=26/Math.max(e,n);return m`<svg viewBox="-14 -14 28 28" width="28" height="28" aria-hidden="true">
${r.treads.map(o=>E`<polygon points=${o.poly.map(([s,a])=>`${s*i},${a*i}`).join(" ")} fill=${o.landing?"currentColor":"none"} fill-opacity="0.25" stroke="currentColor" stroke-width="0.8" />`)}
</svg>`}function i_(t,e,n){let r=t.t,i=Ri(e),o=f=>n.update({stair:{...i,...f}}),s=i.shape!=="straight",a=f=>{let[g,b]=El[f];n.update({stair:{...i,shape:f,run_width:null},w:g,d:b})},l=t.floor?t.doc.floors.filter(f=>f.elevation<t.floor.elevation).sort((f,g)=>g.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?l&&t.floor?t.floor.elevation-l.elevation:null:c&&t.floor?c.elevation-t.floor.elevation:null;n.update({stair:{...i,down:f},...g?{h:Math.round(g*1e3)/1e3}:{}})},u=Tx(e),p=f=>K(t.hass,f*100,1),h=u.measure>=.59&&u.measure<=.65&&u.rise<=.21;return m`<div class="nf-form">
<div class="nf-field nf-wide">
<span>${r("stair_shape")}</span>
<div class="nf-swatches nf-stair-shapes" role="radiogroup" aria-label=${r("stair_shape")}>
${kl.map(f=>m`<button type="button" class="nf-btn nf-stair-shape" role="radio" aria-checked=${f===i.shape} title=${r(`stair_shape_${f}`)} ?disabled=${!t.admin} @click=${()=>a(f)}>
${zx(f)}<span>${r(`stair_shape_${f}`)}</span>
</button>`)}
</div>
</div>
${s?H(t,r("stair_turn"),i.turn,[["left",r("stair_turn_left")],["right",r("stair_turn_right")]],f=>o({turn:f})):""}
${H(t,r("stair_build"),i.build,$l.map(f=>[f,r(`stair_build_${f}`)]),f=>o({build:f}))}
${i.build!=="solid"?D(t,r("stair_risers"),i.risers,f=>o({risers:f}),{wide:!1}):""}
${R(t,r("stair_steps"),i.steps??u.steps,f=>o({steps:Math.round(Math.min(40,Math.max(2,f)))}),1,2)}
${i.steps!=null?m`<button class="nf-btn nf-field-btn" ?disabled=${!t.admin} @click=${()=>o({steps:null})}>${r("height_auto")}</button>`:""}
${s&&i.shape!=="spiral"?m`${R(t,r("stair_run_width"),i.run_width??kn(i,e.w,e.d,e.h).flight,f=>o({run_width:Math.max(.4,f)}),.01,.4)}
${i.run_width!=null?m`<button class="nf-btn nf-field-btn" ?disabled=${!t.admin} @click=${()=>o({run_width:null})}>${r("height_auto")}</button>`:""}`:""}
${i.shape==="l"||i.shape==="u"?m`${R(t,r("stair_landing_after"),i.landing_after??r_(i,e),f=>o({landing_after:Math.round(Math.min(u.steps-1,Math.max(1,f)))}),1,1)}
${i.landing_after!=null?m`<button class="nf-btn nf-field-btn" ?disabled=${!t.admin} @click=${()=>o({landing_after:null})}>${r("height_auto")}</button>`:""}
${S(r("stair_landing_hint",{h:p((i.landing_after??r_(i,e))*Math.abs(e.h)/u.steps)}),"nf-wide")}`:""}
${H(t,r("stair_rail"),i.rail,Sl.map(f=>[f,r(`stair_rail_${f}`)]),f=>o({rail:f}))}
${D(t,r("stair_down"),i.down,d,{title:r("stair_down_hint")})}
${H(t,r("stair_opening"),i.opening,Ml.map(f=>[f,r(`stair_opening_${f}`)]),f=>o({opening:f}),{wide:!0,title:r("stair_opening_hint")})}
<p class="nf-sub nf-wide ${h?"":"nf-pack-error"}">
${r("stair_measures",{steps:u.steps,rise:p(u.rise),going:p(u.going),measure:p(u.measure)})} ${h?"\u2713":`\u2013 ${r("stair_uncomfortable")}`}
</p>
${S(r(i.down?"stair_down_note":i.opening==="headroom"?"stair_up_note":"stair_up_note_plain"),"nf-wide")}
</div>`}function o_(t,e,n){let r=er(e),i=fi(e),o=O(t.hass,()=>!0),s=(h,f=!1)=>n({hydronic:Ch(r,h),...f?{w:Math.round(e.w/i.length*h.length*1e3)/1e3}:{}}),a=(h,f,g,b)=>z(t,h,f??null,void 0,o,y=>b(y==="none"?null:y),{types:g}),l=(h,f,g)=>a(h,f,[1,2],g),c=(h,f,g)=>m`<details class="nf-wide nf-hydronic-control"><summary>${h}</summary><div class="nf-form">
${a("R\xFCckmeldung / Istwert",f?.feedback,[0,1,2],b=>g({...f,feedback:b}))}
${a("Befehl / Sollwert (optional)",f?.command,[0,1,2],b=>g({...f,command:b}))}
${S("Eine zugewiesene R\xFCckmeldung bestimmt die Anzeige auch bei Ausfall. Nur ohne R\xFCckmeldung wird der Sollwert verwendet. Bedienbare Variablen verwenden ihre native Symcon-Schaltaktion und ihren unver\xE4nderten Wertebereich.","nf-wide")}
</div></details>`,u=(t.doc.floors.find(h=>h.furniture.some(f=>f.id===e.id))?.furniture??[]).filter(h=>h.type==="buffer_tank"),p=[["","Keiner"],...u.map((h,f)=>[h.id,h.name||`Pufferspeicher ${f+1}`])];return r.buffer_id&&!u.some(h=>h.id===r.buffer_id)&&p.push([r.buffer_id,"Verkn\xFCpfter Puffer nicht im Stockwerk vorhanden"]),m`<section class="nf-freshwater-form">
<div class="nf-form">${H(t,"Pufferspeicher im Plan",r.buffer_id??"",p,h=>n({hydronic:{...r,buffer_id:h||null}}),{wide:!0})}
${S("Die Zuordnung zeichnet Vorlauf und R\xFCcklauf zum platzierten Puffer im selben Stockwerk. Datenpunkte werden f\xFCr jede Station separat aus dem Objektbaum gew\xE4hlt. Eine Kaskade teilt sich die Sammelleitungen; die Zirkulationspumpe geh\xF6rt zur gemeinsamen Leitung. Das Hinzuf\xFCgen einer Station verbreitert das Bauteil, neue Stationen starten ohne Datenpunkt-Verkn\xFCpfungen.","nf-wide")}
</div>
${ln(i,h=>h.id,(h,f)=>{let g=b=>s(i.map(y=>y.id===h.id?{...y,...b}:y));return m`<details class="nf-freshwater-station" data-station=${h.id} ?open=${f===0}><summary>K${f+1} · ${h.name||`Station ${f+1}`}</summary><div class="nf-form">
${W(t,"Name",h.name,b=>g({name:b}),{wide:!0,maxlength:100})}
${a("Status (optional)",h.status,[0,1,2,3],b=>g({status:b}))}
${l("Vorlauf",h.flow,b=>g({flow:b}))}${l("R\xFCcklauf",h.return,b=>g({return:b}))}
${l("Trinkwarmwasser",h.hot_water,b=>g({hot_water:b}))}${l("Kaltwasser",h.cold_water,b=>g({cold_water:b}))}
${c("Ladepumpe",h.pump,b=>g({pump:b}))}
${l("Pumpenleistung (optional)",h.power,b=>g({power:b}))}
${D(t,"Kaskadenventil vorhanden",Ho(h),b=>g({has_valve:b}))}
${Ho(h)?c("Kaskadenventil (Kaltwasser)",h.valve,b=>g({valve:b})):_}
${i.length>1?m`<button class="nf-link nf-wide nf-freshwater-remove" ?disabled=${!t.admin} @click=${()=>s(i.filter(b=>b.id!==h.id),!0)}>× Station entfernen</button>`:_}
</div></details>`})}
<button class="nf-btn nf-freshwater-add" ?disabled=${!t.admin||i.length>=16} @click=${()=>s([...i,ol(P("station"),`Station ${i.length+1}`)],!0)}>+ Station hinzufügen</button>
<div class="nf-form">${l("Zirkulationstemperatur",r.circulation_temperature,h=>n({hydronic:{...r,circulation_temperature:h}}))}
${c("Zirkulationspumpe",r.circulation,h=>n({hydronic:{...r,circulation:h}}))}
</div>
</section>`}function s_(t,e,n){let r=er(e),i=O(t.hass,()=>!0),o=u=>n({hydronic:{...r,...u}}),s=(u,p,h,f)=>z(t,u,p??null,void 0,i,g=>f(g==="none"?null:g),{types:h}),a=(u,p,h)=>s(u,p,[1,2],h),l=(u,p,h,f=!1)=>m`<details class="nf-wide nf-hydronic-control"><summary>${u}</summary><div class="nf-form">
${s("R\xFCckmeldung / Istwert",p?.feedback,[0,1,2],g=>h({...p,feedback:g}))}
${s("Befehl / Sollwert (optional)",p?.command,[0,1,2],g=>h({...p,command:g}))}
${f?D(t,"Ventil nur in 3D umkehren",!!p?.inverted,g=>h({...p,inverted:g})):_}
${S("Eine zugewiesene R\xFCckmeldung bestimmt die 3D-Anzeige, auch wenn sie gerade nicht verf\xFCgbar ist. Ohne R\xFCckmeldung wird der verkn\xFCpfte Sollwert verwendet. Befehle werden \xFCber die Symcon-Schaltaktion in ihrem nativen Wertebereich gesendet. Die 3D-Umkehrung ver\xE4ndert weder Anzeige- noch Schreibwerte.","nf-wide")}
</div></details>`,c=m`${a("Vorlauf",r.flow,u=>o({flow:u}))}${a("R\xFCcklauf",r.return,u=>o({return:u}))}`,d=(u,p)=>{let h=f=>o({circuits:(r.circuits??[]).map(g=>g.id===u.id?{...g,...f}:g)});return m`<details class="nf-hydronic-circuit" data-circuit=${u.id} ?open=${p===0}><summary>${u.name||`Kreis ${p+1}`}</summary><div class="nf-form">
${W(t,"Name",u.name,f=>h({name:f}),{wide:!0,maxlength:100})}
${H(t,"Kreisart",u.kind,[["heating","Heizkreis"],["cooling","K\xFChlkreis"],["changeover","Heizen / K\xFChlen"],["pump","Einspeise- / Vorschubpumpe (ohne Ventil)"]],f=>h({kind:f,...f==="pump"?{has_pump:!0,has_valve:!1}:{}}),{wide:!0})}
${s("Status (optional)",u.status,[0,1,2,3],f=>h({status:f}))}
${u.kind!=="pump"?m`${D(t,"Pumpe vorhanden",tr(u),f=>h({has_pump:f}))}${D(t,"Ventil vorhanden",Lo(u),f=>h({has_valve:f}))}`:_}
${tr(u)?l("Pumpe",u.pump,f=>h({pump:f})):_}
${Lo(u)?H(t,"Ventilbauart",u.valve_type??"mixing",[["mixing","Mischer (Dreiwegeventil)"],["two_way","Durchgangsventil (Zweiwege)"]],f=>h({valve_type:f}),{wide:!0}):_}
${Lo(u)?l("Ventil",u.valve,f=>h({valve:f}),!0):_}
${a("Vorlauf",u.flow,f=>h({flow:f}))}${a("R\xFCcklauf",u.return,f=>h({return:f}))}
${tr(u)?a("Pumpenleistung (optional)",u.power,f=>h({power:f})):_}
${u.kind==="changeover"?m`${s("Umschaltung Heizen / K\xFChlen",u.mode_entity,[0,1],f=>h({mode_entity:f}))}${R(t,"K\xFChlbetrieb bei Wert",u.cooling_value??1,f=>h({cooling_value:Math.round(f)}),1)}`:_}
<button class="nf-link nf-wide nf-hydronic-remove" ?disabled=${!t.admin} @click=${()=>o({circuits:(r.circuits??[]).filter(f=>f.id!==u.id)})}>× Kreis entfernen</button>
</div></details>`};return m`<section class="nf-hydronic-form">
<div class="nf-form">${s("Anlagenstatus (optional)",r.status,[0,1,2,3],u=>o({status:u}))}</div>
<div class="nf-form">${D(t,"Schwebende 3D-Kachel",r.card!==!1,u=>o({card:u}))}${Vt(t,e.pin_offset,u=>n({pin_offset:u}))}${S("Verkn\xFCpfe jeden Datenpunkt \xFCber den Objektbaum. Namen und Pfade schr\xE4nken die Auswahl nicht ein. Nicht verkn\xFCpfte Werte bleiben in der 3D-Kachel ausgeblendet. Das Bauteil \xF6ffnet beim Antippen seine Werte und Bedienung.","nf-wide")}</div>
${e.type==="heating_manifold"?m`${ln(r.circuits??[],u=>u.id,d)}<button class="nf-btn nf-hydronic-add" title="Bis zu 32 Kreise" ?disabled=${!t.admin||(r.circuits?.length??0)>=32} @click=${()=>o({circuits:[...r.circuits??[],sl(P("circuit"),`Kreis ${(r.circuits?.length??0)+1}`)]})}>+ Kreis hinzufügen</button>`:_}
${e.type==="buffer_tank"?m`<div class="nf-form">${c}${S("Die sieben Startpl\xE4tze liegen von oben nach unten. H\xF6he 100 % liegt oben, 0 % unten. F\xFChlerpl\xE4tze k\xF6nnen erg\xE4nzt, entfernt und frei in der H\xF6he positioniert werden; die Anzeige sortiert sie von oben nach unten.","nf-wide")}</div>
${ln([...r.sensors??[]].sort((u,p)=>p.level-u.level),u=>u.id,u=>{let p=h=>o({sensors:(r.sensors??[]).map(f=>f.id===u.id?{...f,...h}:f)});return m`<details class="nf-hydronic-probe" data-probe=${u.id}><summary>${u.name||"F\xFChler"} · ${Math.round(u.level*100)} %</summary><div class="nf-form">
${W(t,"Bezeichnung",u.name,h=>p({name:h}),{wide:!0,maxlength:100})}${a("Temperatur",u.entity,h=>p({entity:h}))}
${R(t,"H\xF6he (%) \xB7 100 = oben",Math.round(u.level*1e3)/10,h=>p({level:Math.max(0,Math.min(1,h/100))}),.1,0)}
<button class="nf-link nf-wide" ?disabled=${!t.admin} @click=${()=>o({sensors:(r.sensors??[]).filter(h=>h.id!==u.id)})}>× Fühlerplatz entfernen</button>
</div></details>`})}<button class="nf-btn nf-hydronic-add-probe" title="Bis zu 64 Fühlerplätze" ?disabled=${!t.admin||(r.sensors?.length??0)>=64} @click=${()=>o({sensors:[...r.sensors??[],{id:P("probe"),name:`F\xFChler ${(r.sensors?.length??0)+1}`,entity:null,level:.5}]})}>+ Fühlerplatz hinzufügen</button>`:_}
${e.type==="freshwater_station"?o_(t,e,n):_}
${cr(t,e.values,u=>n({values:u}))}
</section>`}var Ix=new Set(["parking","stairwell","rug","grid_point"]),Dx={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 Ox(t,e,n,r){let i=t.hass?.language??"en",o=n.some(s=>e.type.startsWith(`pack:${s.id}:`));return m`<label class="nf-field nf-wide"
>${t.t("furniture_type")}
<select ?disabled=${!t.admin} @change=${s=>r.update({type:s.target.value})}>
${io.map(s=>m`<option value=${s} ?selected=${s===e.type}>${t.t(`furn_${s}`)}</option>`)}
${n.map(s=>m`<optgroup label=${Ve(s,t.hass?.language??"de")}>
${s.items.map(a=>m`<option value=${he(s.id,a.id)} ?selected=${he(s.id,a.id)===e.type}>${Je(a,he(s.id,a.id),i)}</option>`)}
</optgroup>`)}
${e.type.startsWith("pack:")&&!o?m`<option value=${e.type} selected>${Te(t.hass,e.type)}</option>`:_}
</select>
</label>`}function Hx(t,e,n){let r=U(e.type==="parking"?e.vehicle??"":e.type)?.colors;if(!r?.length)return _;let i=t.hass?.language??"en",o=r.find(a=>a.id===e.variant)??r[0],s=a=>Ih(a,i);return m`<div class="nf-form">
<div class="nf-field nf-wide">
<span>${t.t("paint_colour")}: ${s(o)}</span>
<div class="nf-swatches" role="radiogroup" aria-label=${t.t("paint_colour")}>
${r.map((a,l)=>m`<button type="button" class="nf-swatch" role="radio" aria-checked=${a.id===o.id} title=${s(a)} style=${`--sw:${a.hex}`} ?disabled=${!t.admin} @click=${()=>n.update({variant:l===0?null:a.id})}></button>`)}
</div>
</div>
</div>`}function Lx(t,e,n){let r=Dx[e.type];if(!r)return _;let i=r.values.map(o=>[o,t.t(r.text(o))]);return m`<div class="nf-form">${H(t,t.t(r.label),e.variant??"",i,o=>n.update({variant:o||null,...e.type==="sofa"&&o&&e.d<1.4?{d:1.7,w:Math.max(e.w,o==="u"?3:2.4)}:{}}),{wide:!0})}</div>`}function Cx(t,e,n){let r=t.t(`furn_${e.type}`),i=r===`furn_${e.type}`?"":r;return m`<label class="nf-field nf-wide"
>${t.t("furn_name")}
<input type="text" maxlength="60" .value=${e.name??""} ?disabled=${!t.admin} placeholder=${i} @change=${o=>n.update({name:o.target.value.trim()||null})} />
</label>
${e.name?D(t,t.t("show_name"),!!e.show_name,o=>n.update({show_name:o||void 0})):_}`}function Nx(t,e,n){let r=t.t,i=s=>n.update(s),o=t.floor;return m`${R(t,r("x"),e.x,s=>i({x:s}))} ${R(t,r("z"),e.z,s=>i({z:s}))}
${R(t,r("width"),e.w,s=>i({w:Math.max(.05,s)}),.01,.05)} ${R(t,r("depth"),e.d,s=>i({d:Math.max(.05,s)}),.01,.05)}
${R(t,r("height_m"),e.h,s=>i({h:Math.max(.005,s)}),.01,0)}
${R(t,r("rotation"),e.rotation,s=>i({rotation:(s%360+360)%360}),1)}
${R(t,r("tilt_x"),e.tilt_x??0,s=>i({tilt_x:Math.max(-90,Math.min(90,Math.round(s)))||null}),1,-90)}
${R(t,r("tilt_z"),e.tilt_z??0,s=>i({tilt_z:Math.max(-90,Math.min(90,Math.round(s)))||null}),1,-90)}
${de(e.type)?_:D(t,r("furn_mirror"),!!e.mirror,s=>i({mirror:s}),{wide:!1,title:r("furn_mirror_hint")})}
${e.type==="led_strip"?m`${R(t,r("strip_tilt"),e.tilt??0,s=>i({tilt:Math.max(-90,Math.min(90,Math.round(s)))}),5)}
${e.upright?_:R(t,r("strip_rise"),e.rise??0,s=>i({rise:Math.max(-80,Math.min(80,Math.round(s)))}),5)}
${D(t,r("strip_upright"),!!e.upright,s=>i({upright:s}),{wide:!1,title:r("strip_upright_hint")})}`:_}
${oo(e)&&o?m`${R(t,r("mount_height"),e.mount_y??zt(o,e),s=>i({mount_y:Math.max(0,s)}),.01,0)}
${e.mount_y!=null?m`<button class="nf-btn nf-field-btn" ?disabled=${!t.admin} @click=${()=>i({mount_y:null})}>${r("height_auto")}</button>`:_}`:_}
${Bx(e)&&o?m`${R(t,r("ceiling_here"),Yi(o,e),s=>i({ceiling_y:Math.abs(s-ht(o,e.x,e.z))<.005?null:Math.max(.5,s)}),.01,.5)}
${e.ceiling_y!=null?m`<button class="nf-btn nf-field-btn" ?disabled=${!t.admin} @click=${()=>i({ceiling_y:null})}>${r("height_auto")}</button>`:_}
${a_(t,e)!==null?m`<button class="nf-btn nf-field-btn" ?disabled=${!t.admin} title=${r("ceiling_slope_hint")} @click=${()=>i({ceiling_y:a_(t,e)})}>📐 ${r("ceiling_slope")}</button>`:_}
${S(r("ceiling_here_hint"),"nf-wide")}`:_}`}function a_(t,e){let n=t.floor;if(!n)return null;let r=Zr(t.doc,e.x,e.z);if(r===null)return null;let i=Math.round((r-n.elevation)*1e3)/1e3;return i>.5&&i<ht(n,e.x,e.z)-.02?i:null}var Bx=t=>Ys.has(t.type)||U(t.type)?.mount==="ceiling";function Vx(t,e,n){if(e.type==="stairs"&&e.stair)return _;if(e.type==="stairs")return m`${S(t.t("stairs_hint"))}${t.admin?m`<div class="nf-actions"><button class="nf-btn nf-primary" title=${t.t("stair_upgrade_hint")} @click=${()=>n.update({stair:{..._t}})}>${t.t("stair_upgrade")}</button></div>`:_}`;if(e.type!=="stairwell")return _;let r=t.floor&&!t.floor.rooms.some(i=>i.points.length>=3&&Ef(ta(e),i.points));return m`${S(t.t("stairwell_hint"))}${r?m`<p class="nf-sub nf-pack-error">${t.t("stairwell_outside")}</p>`:_}`}function Wx(t,e,n){if(!t.admin)return _;let r=t.t,i=!!e.entity&&e.entity!=="none"&&e.type!=="parking",o=t.doc.floors.filter(s=>s.id!==t.floor?.id);return m`<div class="nf-actions">
<button class="nf-btn" @click=${()=>n.rotate(-90)}>${r("rotate_left")}</button>
<button class="nf-btn" @click=${()=>n.rotate(90)}>${r("rotate_right")}</button>
${i?m`<button class="nf-btn" title=${r("as_device_hint")} @click=${()=>n.toDevice(e)}>${r("as_device")}</button>`:_}
<button class="nf-btn" @click=${()=>n.duplicate()}>${r("duplicate")}</button>
<button class="nf-btn nf-danger" @click=${()=>n.remove()}>${r("delete")}</button>
</div>
${o.length?m`<div class="nf-form">${H(t,r("furn_to_floor"),"",[["","\u2013"],...o.map(s=>[s.id,s.name])],s=>s&&n.toFloor(s),{wide:!0,title:r("furn_to_floor_hint")})}</div>`:_}`}function Kx(t,e,n){let r=e.tap??null,i=[["",t.t("furn_tap_default")],...Qi.map(s=>[s,t.t(`own_action_${s}`)])],o=s=>n.update({tap:{action:r?.action??"navigate",target:r?.target??null,data:r?.data??null,...s}});return m`<div class="nf-form">
${H(t,t.t("furn_tap"),r?.action??"",i,s=>s?o({action:s}):n.update({tap:null}),{wide:!0,title:t.t("furn_tap_hint")})}
${r&&r.action!=="fire_dom_event"?W(t,t.t(`own_target_${r.action}`),r.target??"",s=>o({target:s||null}),{wide:!0,placeholder:hl[r.action]}):_}
${r&&(r.action==="service"||r.action==="fire_dom_event")?pl(t,r,s=>o({data:s})):_}
${r&&!Tt(e.type)&&!U(e.type)?.gangs?m`${Wn(t,e.marker??null,s=>n.update({marker:s}))}${Bt(t,e.icon,s=>n.update({icon:s}))}${Vt(t,e.pin_offset,s=>n.update({pin_offset:s}))}`:_}
</div>`}function jx(t,e,n){let r=t.t,i=e.picture??"",o=i.startsWith("image:"),s=async l=>{let c=l.target,d=c.files?.[0];if(c.value="",!d||!t.hass)return;let{data:u}=await or(d),p=P("img");await Wt(t.hass,p,u),n.update({picture:`image:${p}`})},a=O(t.hass,l=>/^(image|camera|media_player)\./.test(l));return m`<div class="nf-form nf-links">
${t.admin?m`<label class="nf-btn nf-wide nf-upload">📷 ${r(o?"picture_replace":"picture_upload")}<input type="file" accept="image/*" hidden @change=${s} /></label>`:_}
${o?m`<p class="nf-sub nf-wide">${r("picture_stored")} <button class="nf-btn nf-field-btn" ?disabled=${!t.admin} @click=${()=>n.update({picture:null})}>${r("delete")}</button></p>`:m`${W(t,r("picture_url"),/^[a-z_]+\.[a-z0-9_]+$/.test(i)?"":i,l=>n.update({picture:l||null}),{wide:!0,placeholder:"/local/holiday.jpg"})}
${z(t,r("picture_entity"),/^[a-z_]+\.[a-z0-9_]+$/.test(i)?i:null,void 0,a,l=>n.update({picture:l&&l!=="none"?l:null}))}`}
${R(t,r("picture_border"),e.picture_border??0,l=>n.update({picture_border:Math.max(0,Math.min(40,Math.round(l)))||null}),1,0)}
${H(t,r("picture_fit"),e.picture_fit??"cover",[["cover",r("picture_fit_cover")],["contain",r("picture_fit_contain")]],l=>n.update({picture_fit:l==="contain"?"contain":null}))}
${S(r("picture_hint"),"nf-wide")}
</div>`}var Gx=/^(input_boolean|input_select|switch|binary_sensor|sensor|calendar|schedule|sun|person|device_tracker|input_text|select)\./;function Ux(t,e,n){let r=t.t,i=e.show_when??null,o=s=>n.update({show_when:{entity:i?.entity??"",state:i?.state??null,invert:i?.invert||void 0,...s}});return m`<div class="nf-form">
${z(t,r("furn_show_when"),i?.entity||null,void 0,O(t.hass,s=>Gx.test(s)),s=>s&&s!=="none"?o({entity:s}):n.update({show_when:null}))}
${i?.entity?m`${W(t,r("furn_show_when_state"),i.state??"",s=>o({state:s||null}),{wide:!0,placeholder:t.hass?.states[i.entity]?.state??"on"})}
${D(t,r("furn_show_when_invert"),!!i.invert,s=>o({invert:s||void 0}))}`:_}
${S(r("furn_show_when_hint"),"nf-wide")}
</div>`}function Pi(t,e,n){let r=U(e.type)?.gangs??0,i=r?Jg(t,e,r,n):Tt(e.type)?Qg(t,e,n):Ix.has(e.type)?_:m`<div class="nf-form nf-links">${dc(t,e,n)}</div>`;return m`<section>
<div class="nf-h3row"><h3>${e.name||t.t("furniture")}</h3>${n.lockButton}</div>
<div class="nf-form">${Cx(t,e,n)} ${Ox(t,e,n.packs,n)} ${Nx(t,e,n)}</div>
${Vx(t,e,n)} ${e.type==="stairs"&&e.stair?i_(t,e,n):_} ${Lx(t,e,n)} ${Hx(t,e,n)}
${Qn(e.type)?s_(t,e,o=>n.update(o)):i} ${e.type.endsWith(":sprinkler")?m`<div class="nf-form">${R(t,t.t("spray_reach"),e.spray??3,o=>n.update({spray:Math.min(15,Math.max(.5,o))}),.5,.5)}${S(t.t("spray_hint"),"nf-wide")}</div>`:_}
${hd(e.type)?jx(t,e,n):_}
${U(e.type)?.pet?m`<div class="nf-form nf-links">${z(t,t.t("pet_room_sensor"),e.room_sensor??null,void 0,O(t.hass,o=>/^(sensor|device_tracker|input_select|select)\./.test(o)),o=>n.update({room_sensor:o&&o!=="none"?o:null}))}${S(t.t("pet_room_hint"),"nf-wide")}</div>`:_}
${js(e.type)?Yg(t,e,js(e.type),n):_} ${Ks(U(e.type))?Xg(t,e,n):_} ${e.type==="parking"?n_(t,e,n.packs,n):_}
${e.type.startsWith("pack:nextfloor.fahrzeuge:")&&t.admin?m`<section>${S(t.t("vehicle_to_spot_hint"))}<div class="nf-actions"><button class="nf-btn nf-primary" @click=${()=>n.toSpot(e)}>🅿 ${t.t("vehicle_to_spot")}</button></div></section>`:_}
${t.admin?Kx(t,e,n):_} ${Ux(t,e,n)} ${Wx(t,e,n)}
</section>`}var Zx=["door","window","opening","garage_door"],qx=/griff|handle|fenster|window|drehgriff/i;function Yx(t){let e=[null,15,30,45,60,90,120,180];return t&&!e.includes(t)&&e.push(t),e.sort((n,r)=>(n??0)-(r??0))}function Xx(t){let{hass:e}=t,n=o=>e?.states[o],r=o=>n(o)?.attributes.device_class,i=o=>o.startsWith("binary_sensor.")&&Zx.includes(r(o)??"");return{covers:O(e,o=>o.startsWith("cover.")),positions:O(e,o=>bo(e,o)),contacts:O(e,o=>i(o)||ge(o)&&fa(n(o))!==null),plainContacts:O(e,i),handles:O(e,o=>o.startsWith("binary_sensor.")?typeof n(o)?.attributes.window_state=="string":ge(o)&&(fa(n(o))!==null||qx.test(`${o} ${B(e,o)}`))),numbers:O(e,ge),locks:O(e,o=>o.startsWith("lock."))}}function hc(t,e,n){if(!t.hass)return null;let r=structuredClone(t.doc.floors);for(let i of r)for(let o of i.openings)o.id===e.id&&(o[n]=null);return Lt(t.hass,r).get(e.id)?.[n]??null}var dt=t=>t==="none"?null:t;function Jx(t,e,n){let r=e.type==="door"?Js:Qs,i=on({type:e.type,style:null},n.isExterior(e)),o=e.style&&r.includes(e.style)?e.style:"",s=[["",t.t("style_auto",{style:t.t(`style_${i}`)})],...r.map(a=>[a,t.t(`style_${a}`)])];return H(t,t.t("opening_style"),o,s,a=>n.update({style:a||null}),{wide:!0})}function uc(t,e,n,r,i){return m`<label class="nf-field"
>${t.t(r)}
<input
type="number"
step="0.05"
min="0.1"
max="3"
placeholder=${t.t("sidelight_auto")}
.value=${e[n]==null?"":String(e[n])}
?disabled=${!t.admin}
@change=${o=>{let s=Number(o.target.value);i.update({[n]:Number.isFinite(s)&&s>0?Math.min(3,Math.max(.1,Math.round(s*100)/100)):null})}}
/>
</label>`}function Qx(t,e,n){if(e.type!=="door")return _;let r=on(e,n.isExterior(e));return r==="sidelight"?m`${D(t,t.t("sidelight_hinge"),!!e.sidelight_hinge,i=>n.update({sidelight_hinge:i}),{wide:!1,title:t.t("sidelight_hinge_hint")})}
${uc(t,e,"sidelight_width","sidelight_width",n)}`:r==="sidelights"?m`${uc(t,e,"sidelight_width","sidelight_width_left",n)} ${uc(t,e,"sidelight_width2","sidelight_width_right",n)}`:_}function ek(t,e,n){return e.type!=="window"||on(e,n.isExterior(e))!=="glass_wall"?_:m`<label class="nf-field"
>${t.t("glass_panes")}
<input
type="number"
step="1"
min="0"
max="40"
placeholder=${t.t("glass_panes_auto")}
.value=${e.panes==null?"":String(e.panes)}
?disabled=${!t.admin}
@change=${r=>{let i=r.target.value.trim(),o=Number(i);n.update({panes:i===""||!Number.isFinite(o)?null:Math.min(40,Math.max(0,Math.round(o)))})}}
/>
</label>
${S(t.t("glass_panes_hint"),"nf-wide")}`}function l_(t,e,n,r,i){let o=n===1,s=t.t,a=o?e.tilt:e.tilt2??null,l=o?e.contact:e.contact2,c=(o?e.sensor:e.sensor2)??(a&&a!=="none"?"contact_tilt":"contact"),d=["contact","handle","contact_tilt"].map(f=>[f,s(`sensor_kind_${f}`)]),u=f=>{let g=f==="contact_tilt"?{}:o?{tilt:null}:{tilt2:null};r.update({...o?{sensor:f}:{sensor2:f},...g})},p=f=>r.update(o?{contact:f}:{contact2:dt(f)}),h=e.tilt_angle&&e.tilt_angle!=="none";return m`${H(t,s("sensor_kind"),c,d,u,{wide:!0})}
${c==="handle"?z(t,s("handle_entity"),l,void 0,i.handles,f=>p(f==="none"?o?"none":null:f)):z(t,s("contact_entity"),l,o?hc(t,e,"contact"):void 0,i.plainContacts,p)}
${c==="contact_tilt"?z(t,s("tilt_entity"),a,void 0,i.contacts,f=>r.update(o?{tilt:dt(f)}:{tilt2:dt(f)})):_}
${o?m`${z(t,s("tilt_angle_entity"),e.tilt_angle??null,void 0,i.numbers,f=>r.update({tilt_angle:dt(f)}))}
${h?m`${R(t,s("tilt_angle_max"),e.tilt_max??15,f=>r.update({tilt_max:Math.min(90,Math.max(1,f))}),1,1)}
${R(t,s("tilt_angle_offset"),e.tilt_offset??0,f=>r.update({tilt_offset:f}),.5)}
${D(t,s("tilt_angle_invert"),!!e.tilt_invert,f=>r.update({tilt_invert:f}))}`:_}`:_}`}function tk(t,e,n,r){let i=t.t,o=e.type==="window",s=hc(t,e,"cover"),a=e.cover!=="none"&&(e.cover||s),l=t.hass?.symconObjects!==void 0;return m`${z(t,i(l?"symcon_cover_position":o?"cover_entity":"door_cover"),e.cover,s,r.covers,c=>n.update({cover:c}),{types:[1,2],role:"cover"})}
${l||a&&e.blind==="venetian"?z(t,i("cover_tilt_entity"),e.cover_tilt??null,void 0,r.covers,c=>n.update({cover_tilt:dt(c)}),{types:[1,2],role:"cover"}):_}
${a?m`${D(t,i("cover_direction_invert"),!!e.cover_inverted,c=>n.update({cover_inverted:c||void 0}))}
${e.cover_tilt||e.blind==="venetian"?D(t,i("cover_tilt_direction_invert"),!!e.cover_tilt_inverted,c=>n.update({cover_tilt_inverted:c||void 0})):_}
${z(t,i("cover_position_entity"),e.position??null,void 0,r.positions,c=>n.update({position:dt(c)}),{types:[1,2]})}
${e.position?D(t,i("cover_position_invert"),!!e.position_inverted,c=>n.update({position_inverted:c})):_}
${D(t,i("device_confirm"),!!e.confirm,c=>n.update({confirm:c}),{title:i("cover_confirm_hint")})}
${o?m`${H(t,i("blind_kind"),e.blind??"roller",[["roller",i("blind_roller")],["venetian",i("blind_venetian")],["inside",i("blind_inside")]],c=>n.update({blind:c==="roller"?null:c}))}
${z(t,i("cover2_entity"),e.cover2??null,void 0,r.covers,c=>n.update({cover2:dt(c)}))}`:_}
${!o&&e.type!=="garage"?z(t,i("cover2_entity"),e.cover2??null,void 0,r.covers,c=>n.update({cover2:dt(c)})):_}
${e.cover2&&e.cover2!=="none"?z(t,i("cover2_tilt_entity"),e.cover2_tilt??null,void 0,r.covers,c=>n.update({cover2_tilt:dt(c)})):_}
${e.cover2&&e.cover2!=="none"?m`${D(t,i("cover2_direction_invert"),!!e.cover2_inverted,c=>n.update({cover2_inverted:c||void 0}))}${D(t,i("cover2_tilt_direction_invert"),!!e.cover2_tilt_inverted,c=>n.update({cover2_tilt_inverted:c||void 0}))}`:_}
${R(t,i("cover_my"),e.my_position??0,c=>n.update({my_position:c>0?Math.min(100,Math.round(c)):null}),5,0)}
${S(i("cover_direction_hint"),"nf-wide")}
${S(i("blind_hint"),"nf-wide")}`:_}`}function nk(t,e,n,r){let i=t.t,o=e.leaves===2;return m`${z(t,i(o?"contact_main":"contact_entity"),e.contact,hc(t,e,"contact"),r.contacts,s=>n.update({contact:s}))}
${o&&e.type!=="garage"?z(t,i("contact_second"),e.contact2,void 0,r.contacts,s=>n.update({contact2:dt(s)})):_}
${e.type==="door"?D(t,i("door_shut"),!!e.shut,s=>n.update({shut:s}),{title:i("door_shut_hint")}):_}
${e.type==="door"&&e.style!=="sliding"&&e.style!=="passage"?H(t,i("door_angle"),String(e.open_angle??""),Yx(e.open_angle).map(s=>[String(s??""),s?`${s}\xB0`:i("door_angle_default")]),s=>n.update({open_angle:s?Number(s):null}),{title:i("door_angle_hint")}):_}
${e.type==="door"?m`${z(t,i("opening_lock"),e.lock??null,void 0,r.locks,s=>n.update({lock:dt(s)}))}${S(i("opening_lock_hint"),"nf-wide")}`:_}`}function pc(t,e,n){let r=t.t,i=Xx(t),o=In(e),[s,a,l]=[e.type==="window",e.type==="garage",e.type==="door"],c=h=>n.update(h),d=Object.keys(Pn).map(h=>m`<button class="nf-chip" aria-pressed=${h===o} @click=${()=>n.setPreset(e,h)}>${r(`preset_${h}`)}</button>`),u=[["left",r("hinge_left")],["right",r("hinge_right")]],p=[["",r("opening_mark_open")],["closed",r("opening_mark_closed")]];return m`<section>
<div class="nf-h3row"><h3>${r(`preset_${o}`)}</h3>${n.lockButton}</div>
${t.admin?m`<div class="nf-presets" role="group" aria-label=${r("opening_type")}>${d}</div>`:_}
${t.admin&&!a?m`<div class="nf-actions">
<button class="nf-btn" title=${r("flip_hinge_hint")} @click=${()=>c({hinge:e.hinge==="left"?"right":"left"})}>⇆ ${r(e.leaves===2?"flip_main_leaf":"flip_hinge")}</button>
${l?m`<button class="nf-btn" title=${r("flip_swing_hint")} @click=${()=>c({swing:e.swing==="out"?"in":"out"})}>⇅ ${r("flip_swing")}</button>`:_}
</div>`:_}
<div class="nf-form">
${R(t,r("width"),e.width,h=>c({width:Math.max(.3,h)}),.01,.3)}
${R(t,r("opening_position"),e.offset,h=>c({offset:Math.max(0,h)}),.01,0)}
${s?R(t,r("sill"),e.sill,h=>c({sill:Math.max(0,h)}),.01,0):_}
${R(t,r("opening_height"),e.height,h=>c({height:Math.max(.3,h)}),.01,.3)}
${a?_:Jx(t,e,n)} ${Qx(t,e,n)} ${ek(t,e,n)}
${s&&e.style!=="glass_wall"?H(t,r("window_opens"),e.opens??"turn",Md.map(h=>[h,r(`window_opens_${h}`)]),h=>c({opens:h==="turn"?null:h}),{wide:!0,title:r("window_opens_hint")}):_}
${H(t,r("opening_mark"),e.mark==="closed"?"closed":"",p,h=>c({mark:h==="closed"?"closed":null}),{wide:!0,title:r("opening_mark_hint")})}
${a?_:H(t,r(e.leaves===2?"main_leaf":"hinge"),e.hinge,u,h=>c({hinge:h}),{wide:!0})}
${s?H(t,r("sill_boards"),e.sill_boards??"auto",[["auto",r("sill_boards_auto")],["none",r("sill_boards_none")],["inside",r("sill_boards_inside")],["outside",r("sill_boards_outside")]],h=>c({sill_boards:h==="auto"?null:h}),{wide:!0}):_}
${s?D(t,r("opening_rain_warning"),e.rain_warning!==!1,h=>c({rain_warning:h?void 0:!1}),{wide:!0}):_}
${s&&n.isBelowGround?.(e)?D(t,r("opening_light_well"),e.light_well!==!1,h=>c({light_well:h?null:!1}),{wide:!0}):_}
${tk(t,e,n,i)}
${s?m`${e.leaves===2?m`<h4 class="nf-lib-head nf-wide">${r("leaf_main")}</h4>`:_}${l_(t,e,1,n,i)}
${e.leaves===2?m`<h4 class="nf-lib-head nf-wide">${r("leaf_second")}</h4>${l_(t,e,2,n,i)}`:_}`:nk(t,e,n,i)}
</div>
${S(r(s?"opening_hint":a?"garage_hint":"door_hint"))}
${t.admin?m`<div class="nf-actions"><button class="nf-btn nf-danger" @click=${()=>n.remove()}>${r("delete")}</button></div>`:_}
</section>`}function ur(t){let e=t.roof.floorsTopDown();return e.length<2?_:m`<div class="nf-seg nf-dev-source">${e.map(n=>m`<button aria-pressed=${n.id===t.floorId} @click=${()=>t.setFloorId(n.id)}>${n.name}</button>`)}</div>`}function hr(t,e,n){return t.admin?m`<button class="nf-btn nf-fix" aria-pressed=${e} title=${t.t("fix_hint")} @click=${n}>${e?`\u{1F512} ${t.t("unfix")}`:`\u{1F513} ${t.t("fix")}`}</button>`:_}function pr(t,e,n,r){return m`<div class="nf-seg nf-dev-source">${e.map(([i,o])=>m`<button aria-pressed=${i===n} ?disabled=${!t.admin} @click=${()=>r(i)}>${o}</button>`)}</div>`}function At(t,e){let{t:n,doc:r,hass:i}=t,o=n(`compass_${qa(e,r.settings.north??0)}`);if(e.key===Be)return n("solar_ground");if(e.wall){let l=r.floors.find(c=>c.id===e.wall.floorId);return`${n("solar_wall")} ${l?.name??""} \xB7 ${o} \xB7 ${K(i,e.lu,1)} m`}let s=r.settings.roof.sections??[],a=e.section?n("solar_section",{n:s.findIndex(l=>l.id===e.section)+1}):n("solar_main");return e.flat?`${a} \xB7 ${n("solar_flat")}`:`${a} \xB7 ${o} \xB7 ${Math.round(e.pitch)}\xB0`}var fc=(t,e)=>m`<div class="nf-h3row"><h3>${t}</h3>${e}</div>`,mc=(t,e)=>m`<button class="nf-btn nf-back" @click=${e}>‹ ${t}</button>`,Mn=(t,e)=>n=>Math.max(t,Math.min(e,ae(n)));function rk(t,e){let{host:n,roof:r}=t,i=n.t,o=w=>r.patchSection(w),s=e.shape==="flat"||e.shape==="parapet",a=e.shape==="pent",l=e.axis==="x"?[i("roof_side_top"),i("roof_side_bottom")]:[i("roof_side_left"),i("roof_side_right")],[c,d]=e.flip?[l[1],l[0]]:l,u=!!n.doc.settings.lock_plan,p=(w,k,x,M=.05,A=0)=>R(n,w,k,T=>x(Math.max(A,ae(T))),M,A),h=[...n.doc.floors].filter(w=>w.rooms.length>0).sort((w,k)=>k.elevation-w.elevation),f=La(n.doc,e)?.id,g=w=>{let k=n.doc.floors.find(A=>A.id===w);if(!k)return;let x=ae(k.elevation+k.height),M=x-e.base;o({base:x,eave_a:ae(e.eave_a+M),eave_b:ae(e.eave_b+M)})},b=u?m`<button class="nf-btn nf-fix" aria-pressed="true" title=${i("lock_plan_hint")} @click=${()=>t.toggleLockPlan()}>🔒 ${i("plan_locked")}</button>`:hr(n,!!e.locked,()=>o({locked:!e.locked})),y=Ad.map(w=>[w,i(`roof_shape_${w}`)]),v=(w,k)=>m`<button class="nf-btn" title=${i("roof_dormer_hint")} @click=${()=>r.addDormer(w)}>+ ${i("roof_dormer")} ${k}</button>`;return m`${mc(i("roof_sections"),()=>r.sectionId=null)}
<section>
${ur(t)}
${fc(`${e.dormer?i("roof_dormer"):i("roof_section")} ${rm(n.doc.settings.roof.sections??[],e.id)}`,n.admin?b:_)}
${H(n,i("roof_shape"),e.shape,y,w=>o({shape:w,...w==="gable"||w==="hip"||w==="halfhip"?{}:{ends:null}}),{wide:!0})}
${e.shape==="gable"||e.shape==="hip"||e.shape==="halfhip"?lk(n,e,o):_}
${s?_:pr(n,[["x",i("roof_axis_x")],["z",i("roof_axis_z")]],e.axis,w=>o({axis:w}))}
${D(n,i("roof_open"),!!e.open,w=>o({open:w}),{title:i("roof_open_hint")})}
<div class="nf-form">
${s?p(i("roof_height"),e.eave_a,w=>o({eave_a:w,eave_b:w})):m`${p(`${i("roof_eave")} ${a?"":c}`,e.eave_a,w=>o({eave_a:w}))}
${a?_:p(`${i("roof_eave")} ${d}`,e.eave_b,w=>o({eave_b:w}))}
${p(`${i("roof_pitch_short")} ${a?"":c}`,e.pitch_a,w=>o({pitch_a:Math.min(75,w)}),1)}
${a?_:p(`${i("roof_pitch_short")} ${d}`,e.pitch_b,w=>o({pitch_b:Math.min(75,w)}),1)}`}
${p(i("roof_base"),e.base,w=>o({base:w}))}
${e.points?.length?_:R(n,i("roof_rotation"),e.rotation??0,w=>o({rotation:(Math.round(w)%360+540)%360-180||null}),1)}
${H(n,i("roof_on_floor"),f??"",h.map(w=>[w.id,w.name]),g,{title:i("roof_on_floor_hint")})}
${S(i("roof_base_hint"),"nf-wide")}
${p(i("roof_overhang"),e.overhang??n.doc.settings.roof.overhang,w=>o({overhang:Math.min(2,w)}))}
</div>
<details class="nf-section" ?open=${!!e.overhang_sides}>
<summary>${i("roof_overhang_sides")}</summary>
<div class="nf-form">
${["a","b","u0","u1"].map(w=>p(i(`roof_overhang_${w}`),Ur(n.doc,e,e.overhang??n.doc.settings.roof.overhang)[w],k=>o({overhang_sides:{...e.overhang_sides??{},[w]:Math.min(2,Math.max(0,k))}})))}
${n.admin&&e.overhang_sides?m`<button class="nf-btn" @click=${()=>o({overhang_sides:null})}>${i("roof_overhang_auto")}</button>`:_}
</div>
${S(i("roof_overhang_sides_hint"))}
</details>
${s&&n.admin?m`${Q(m`<button class="nf-btn" title=${i("roof_outline_hint")} @click=${()=>r.takeOutline()}>${i("roof_outline")}</button>`,e.points?m`<button class="nf-btn" @click=${()=>o({points:null})}>${i("roof_rect")}</button>`:_)}
${e.points?Q(...e.points.map((w,k)=>m`<button class="nf-chip" title=${i("delete_point")} ?disabled=${(e.points?.length??0)<=3} @click=${()=>r.removeCorner(k)}>${k+1} ×</button>`)):_}
${S(i(e.points?"roof_points_hint":"roof_outline_hint"))}`:_}
${S(`${i("roof_ridge_height")}: ${pe(n.hass,un(e))} \xB7 ${i("roof_section_hint")}`)}
${n.admin?Q(s?_:m`<button class="nf-btn" title=${i("roof_swap_hint")} @click=${()=>o({flip:!e.flip})}>⇅ ${i("roof_swap")}</button>`,!s&&!e.dormer&&!e.open?m`${v("a",c)}${a?_:v("b",d)}`:_,m`<button class="nf-btn" @click=${()=>r.duplicateSection()}>${i("duplicate")}</button>`,m`<button class="nf-btn nf-danger" @click=${()=>r.removeSection()}>${i("delete")}</button>`):_}
</section>`}function ik(t,e){let{host:n,roof:r}=t,i=n.t,o=Y(n.doc),s=p=>r.patchWindow(p),a=O(n.hass,p=>p.startsWith("cover.")),l=O(n.hass,p=>wo(p)||ge(p)),c=(p,h,f,g)=>z(n,i(p),h??null,void 0,f,b=>s({[g]:b==="none"?null:b}),g==="cover"||g==="window"?{types:[1,2],role:"cover"}:{types:[0,1,2]}),d=p=>{let h=o.find(f=>f.key===p);h&&s({...oi(h,e.id),w:e.w,h:e.h,cover:e.cover,contact:e.contact,tilt:e.tilt,window:e.window,name:e.name})},u=(n.doc.settings.roof.windows??[]).findIndex(p=>p.id===e.id)+1;return m`${mc(i("roof_sections"),()=>r.windowId=null)}
<section>
${fc(`\u{1FA9F} ${i("roof_window")} ${u}`,hr(n,!!e.locked,()=>s({locked:!e.locked})))}
<div class="nf-form">
${H(n,i("solar_face"),e.face,o.map(p=>[p.key,At(n,p)]),d,{wide:!0})}
${R(n,i("width"),e.w??.78,p=>s({w:Mn(.3,4)(p)}),.01,.3)}
${R(n,i("height_m"),e.h??1.18,p=>s({h:Mn(.3,4)(p)}),.01,.3)}
${R(n,i("solar_u"),e.u,p=>s({u:ae(p)}),.05)} ${R(n,i("solar_v"),e.v,p=>s({v:ae(p)}),.05)}
${c("cover_entity",e.cover,a,"cover")} ${c("contact_entity",e.contact,l,"contact")}
${c("roof_window_tilt",e.tilt,l,"tilt")} ${c("roof_window_motor",e.window,a,"window")}
${W(n,i("roof_window_name"),e.name??"",p=>s({name:p||null}),{wide:!0,maxlength:64})}
</div>
${S(i("roof_window_motor_hint"))} ${S(i("roof_window_hint"))}
${n.admin?Q(m`<button class="nf-btn nf-danger" @click=${()=>r.removeWindow()}>${i("delete")}</button>`):_}
</section>`}function ok(t){let{host:e,roof:n}=t,r=e.doc.settings.roof.windows??[],i=new Map(Y(e.doc).map(s=>[s.key,s])),o=s=>{n.windowId=s,n.sectionId=null};return m`<section>
<h3>🪟 ${e.t("roof_windows")}</h3>
${S(e.t(i.size>0?"roof_windows_hint":"solar_no_roof"))}
${r.length>0?m`<div class="nf-room-list">
${r.map((s,a)=>{let l=i.get(s.face);return m`<div class="nf-row"><button class="nf-dev-name" @click=${()=>o(s.id)}><span>${e.t("roof_window")} ${a+1} · ${l?At(e,l):e.t("solar_face_gone")}</span></button></div>`})}
</div>`:_}
${Q(m`<button class="nf-btn" ?disabled=${!e.admin||i.size===0} @click=${()=>n.addWindow()}>+ ${e.t("roof_window")}</button>`)}
</section>`}function sk(t,e){let{host:n,roof:r}=t,i=n.t,o=Y(n.doc),s=u=>r.patchChimney(u),a=bn(e),l=u=>{let p=o.find(h=>h.key===u);p&&s({...si(p,e.id),shape:e.shape,w:e.w,d:e.d,h:e.h,name:e.name})},c=a.shape==="round"||a.shape==="steel",d=(n.doc.settings.roof.chimneys??[]).findIndex(u=>u.id===e.id)+1;return m`${mc(i("roof_sections"),()=>r.chimneyId=null)}
<section>
${fc(`\u{1F9F1} ${i("chimney")} ${d}`,hr(n,!!e.locked,()=>s({locked:!e.locked})))}
<div class="nf-form">
${H(n,i("chimney_shape"),a.shape,Fd.map(u=>[u,i(`chimney_${u}`)]),u=>s({shape:u,w:null,d:null,h:null}),{wide:!0})}
${H(n,i("solar_face"),e.face,o.map(u=>[u.key,At(n,u)]),l,{wide:!0})}
${c?R(n,i("chimney_diameter"),a.w,u=>s({w:Mn(.1,3)(u),d:Mn(.1,3)(u)}),.01,.1):m`${R(n,i("width"),a.w,u=>s({w:Mn(.1,3)(u)}),.01,.1)} ${R(n,i("chimney_depth"),a.d,u=>s({d:Mn(.1,3)(u)}),.01,.1)}`}
${R(n,i("chimney_height"),a.h,u=>s({h:Mn(.2,5)(u)}),.05,.2)}
${R(n,i("solar_u"),e.u,u=>s({u:ae(u)}),.05)} ${R(n,i("solar_v"),e.v,u=>s({v:ae(u)}),.05)}
${W(n,i("roof_window_name"),e.name??"",u=>s({name:u||null}),{wide:!0,maxlength:64})}
</div>
${S(i("chimney_hint"))}
${n.admin?Q(m`<button class="nf-btn nf-danger" @click=${()=>r.removeChimney()}>${i("delete")}</button>`):_}
</section>`}function ak(t){let{host:e,roof:n}=t,r=e.doc.settings.roof.chimneys??[],i=new Map(Y(e.doc).map(s=>[s.key,s])),o=s=>{n.chimneyId=s,n.sectionId=null};return m`<section>
<h3>🧱 ${e.t("chimneys")}</h3>
${i.size>0?_:S(e.t("solar_no_roof"))}
${r.length>0?m`<div class="nf-room-list">
${r.map((s,a)=>{let l=i.get(s.face);return m`<div class="nf-row"><button class="nf-dev-name" @click=${()=>o(s.id)}><span>${e.t("chimney")} ${a+1} · ${e.t(`chimney_${bn(s).shape}`)} · ${l?At(e,l):e.t("solar_face_gone")}</span></button></div>`})}
</div>`:_}
${Q(m`<button class="nf-btn" ?disabled=${!e.admin||i.size===0} @click=${()=>n.addChimney()}>+ ${e.t("chimney")}</button>`)}
</section>`}function lk(t,e,n){let r=t.t,i=e.shape,[o,s]=e.ends??[i,i],a=["gable","hip","halfhip"].map(d=>[d,r(`roof_shape_${d}`)]),l=d=>n({ends:d[0]===i&&d[1]===i?null:d}),c=o==="halfhip"||s==="halfhip";return m`<div class="nf-form">
${H(t,r("roof_end_start"),o,a,d=>l([d,s]))}
${H(t,r("roof_end_end"),s,a,d=>l([o,d]))}
${c?m`<label class="nf-field nf-wide" title=${r("roof_halfhip_hint")}
>${r("roof_halfhip")} · ${Math.round((e.halfhip??.55)*100)} %
<input type="range" min="20" max="90" step="5" .value=${String(Math.round((e.halfhip??.55)*100))} ?disabled=${!t.admin} @change=${d=>n({halfhip:Number(d.target.value)/100})} />
</label>`:_}
</div>`}function c_(t){let{host:e,roof:n}=t,r=e.doc.settings.roof,i=r.type==="custom";if(n.window)return ik(t,n.window);if(n.chimney)return sk(t,n.chimney);if(i&&n.section)return rk(t,n.section);let o=i?r.sections??[]:[],s=e.t,a=(l,c)=>`${c+1} \xB7 ${l.dormer?s("roof_dormer"):s(`roof_shape_${l.shape}`)} \xB7 ${K(e.hass,Math.abs(l.x1-l.x0),1)} \xD7 ${K(e.hass,Math.abs(l.z1-l.z0),1)} m \xB7 ${s("roof_ridge_height")} ${K(e.hass,un(l),1)} m`;return m`<section>
${ur(t)}
<h3>${s("roof_sections")}</h3>
${S(s("roof_sections_hint"))}
${i?m`<div class="nf-room-list">${o.map((l,c)=>m`<div class="nf-row"><button class="nf-dev-name" @click=${()=>n.sectionId=l.id}><span>${a(l,c)}</span></button></div>`)}</div>
${Q(m`<button class="nf-btn" ?disabled=${!e.admin} @click=${()=>n.useSections(!0)}>${s("roof_sections_regen")}</button>`,m`<button class="nf-btn" ?disabled=${!e.admin} @click=${()=>e.change(l=>l.settings.roof.type="gable")}>${s("roof_sections_off")}</button>`)}`:Q(m`<button class="nf-btn nf-primary" ?disabled=${!e.admin} @click=${()=>n.useSections()}>${s("roof_sections_start")}</button>`)}
</section>
${ok(t)} ${ak(t)}`}var gc=40,d_=60;function _c(t){let e=new Set((t.solar??[]).map(n=>n.string).filter(Boolean));t.strings=(t.strings??[]).filter(n=>e.has(n.id))}function u_(t,e,n,r){let i=t.solar?.find(o=>o.id===e);if(i){if(n==="new"){let o=t.strings??[],s={id:r.id,name:r.name(o.length+1),entity:i.entity??null,inverter:null};t.strings=[...o,s],i.string=s.id}else i.string=n;_c(t)}}function h_(t,e){let n=new Set(t??[]);return n.delete(e)||n.add(e),n.size>0?[...n].sort():null}function p_(t){let e=t.split(/[,;\s]+/).map(r=>Number.parseInt(r,10)).filter(r=>Number.isFinite(r)&&r>=0);return e.length===0?null:e.length===1?{cols:Math.max(1,Math.min(d_,e[0])),layout:null,skip:null}:{layout:e.slice(0,gc).map(r=>Math.min(d_,r)),rows:Math.min(gc,e.length),cols:Math.max(1,...e),skip:null}}function f_(t,e){let n=Math.max(1,Math.min(gc,Math.round(e))),r=t.layout;return r?.length?{rows:n,layout:Array.from({length:n},(i,o)=>r[o]??r[r.length-1])}:{rows:n}}var m_=t=>t.layout?.length?t.layout.join(", "):String(t.cols),ck=["portrait","look","name","string","entity","module_w","module_h","wp"];function dk(t){let e={};for(let n of ck)e[n]=t[n];return e}function g_(t,e,n){let r=dk(e);if(n===Be)return{...ri(t,e.id),...r,rows:e.rows,cols:e.cols};let i=Y(t).find(s=>s.key===n);if(i)return To(i,{...e,...r});let o=qe(t).find(s=>s.key===n);return o?To(o,{...e,...r,rows:1}):null}var __=400;function bc(t,e){let n=t?Xe(t,e).length:0;return{modules:n,kwp:n*(e.wp??__)/1e3}}function b_(t){let{host:e,roof:n}=t,r=e.t,i=e.doc.settings.roof.solar??[],o=e.doc.settings.roof.strings??[],s=Y(e.doc),a=new Map(i.map(d=>[d.id,Se(e.doc,d,s)])),l=(d,u)=>{let p=a.get(d.id),h=bc(p,d),f=r("solar_summary",{n:h.modules,kwp:K(e.hass,h.kwp,1)});return m`<div class="nf-row">
<button class="nf-dev-name" @click=${()=>n.selectField(d.id)}>
<span>${d.name||`${r("solar_field")} ${u+1}`} · ${p?At(e,p):r("solar_face_gone")} · ${f}</span>
</button>
</div>`},c=d=>{let u=i.filter(g=>g.string===d.id),p=u.map(g=>bc(a.get(g.id),g)),h=p.reduce((g,b)=>g+b.modules,0),f=p.reduce((g,b)=>g+b.kwp,0);return m`<p class="nf-sub">🔗 <b>${d.name}</b> · ${r("solar_string_sum",{fields:u.length,n:h,kwp:K(e.hass,f,1)})}</p>`};return m`<section>
${ur(t)}
<h3>☀ ${r("solar_fields")}</h3>
${S(r(s.length>0?"solar_hint":"solar_no_roof"))}
${i.length>0?m`<div class="nf-room-list">${i.map(l)}</div>`:_}
${Q(m`<button class="nf-btn nf-primary" ?disabled=${!e.admin||s.length===0} @click=${()=>n.addField()}>+ ${r("solar_add")}</button>`,m`<button class="nf-btn" ?disabled=${!e.admin} @click=${()=>n.addGroundField()}>+ ${r("solar_add_ground")}</button>`,m`<button class="nf-btn" ?disabled=${!e.admin||!t.floorId} @click=${()=>n.addWallField()}>+ ${r("solar_add_wall")}</button>`)}
${o.length>0?m`<h4 class="nf-lib-head">${r("solar_strings")}</h4>${o.map(c)}`:_}
</section>`}function uk(t,e){let{host:n,roof:r}=t,i=n.t,o=O(n.hass,p=>Nn(n.hass,p)),s=n.doc.settings.roof.strings??[],a=s.find(p=>p.id===e.string),l=[["",i("solar_string_none")],...s.map(p=>[p.id,p.name]),["new",`+ ${i("solar_string_new")}`]],c=H(n,i("solar_string"),e.string??"",l,p=>r.setString(p===""?null:p),{wide:!0});if(!a)return m`${c}${z(n,i("solar_entity"),e.entity??null,void 0,o,p=>r.patchField({entity:p==="none"?null:p}))}`;let d=n.hass?Re(n.hass,n.doc.floors):null,u=n.doc.floors.flatMap(p=>p.furniture.filter(h=>h.type==="inverter").map(h=>({item:h,floor:p}))).map(({item:p,floor:h},f)=>{let g=d?.get(p.id)?.entity,b=p.name?.trim()||(g?B(n.hass,g):"");return[p.id,`${b||`${i("furn_inverter")} ${f+1}`} \xB7 ${h.name}`]});return m`${c}
${W(n,i("solar_string_name"),a.name,p=>r.patchString({name:p||a.name}),{wide:!0})}
${z(n,i("solar_string_entity"),a.entity??null,void 0,o,p=>r.patchString({entity:p==="none"?null:p}))}
${H(n,i("solar_string_inverter"),a.inverter??"",[["",i(u.length>0?"solar_string_inverter_none":"solar_string_inverter_missing")],...u],p=>r.patchString({inverter:p||null}),{wide:!0})}`}function y_(t,e){let{host:n,roof:r}=t,i=n.t,o=x=>r.patchField(x),s=Y(n.doc),a=Se(n.doc,e,s),l=e.face===Be,c=Jr(e),d=bc(a,e),u=c.reduce((x,M)=>x+M,0)-(e.skip?.length??0),p=(n.doc.settings.roof.solar??[]).findIndex(x=>x.id===e.id)+1,h=[...a?[]:[["",i("solar_face_gone")]],...s.map(x=>[x.key,At(n,x)]),[Be,i("solar_ground")],...qe(n.doc).map(x=>[x.key,At(n,x)])],f=x=>{let M=g_(n.doc,e,x);M&&o(M)},g=(x,M,A=ae)=>T=>Math.max(x,Math.min(M,A(T))),b=x=>o(ii(n.doc,e,x)),y=x=>o({rotation:(Math.round(x)%360+360)%360||null}),v=a?.wall?"solar_flip_wall":"solar_flip",w=(x,M,A)=>R(n,i(M),e[x]??A,T=>o({[x]:g(.3,3)(T)}),.01,.3),k=!!e.layout?.length&&new Set(e.layout).size>1;return m`<button class="nf-btn nf-back" @click=${()=>r.solarId=null}>‹ ${i("solar_fields")}</button>
<section>
${ur(t)}
<div class="nf-h3row">
<h3>☀ ${e.name||`${i("solar_field")} ${p}`}</h3>
${hr(n,!!e.locked,()=>o({locked:!e.locked}))}
</div>
<div class="nf-form">
${W(n,i("solar_name"),e.name??"",x=>o({name:x||null}),{wide:!0,placeholder:i("solar_name_hint")})}
${H(n,i("solar_face"),a?e.face:"",h,f,{wide:!0})}
${R(n,i("solar_rows"),c.length,x=>o(f_(e,x)),1,1)}
<label class="nf-field" title=${i("solar_cols_hint")}
>${i("solar_cols")}
<input
type="text"
inputmode="numeric"
?disabled=${!n.admin}
.value=${m_(e)}
@change=${x=>{let M=p_(x.target.value);M&&o(M)}}
/>
</label>
</div>
${S(`${a&&!a.unbounded?`${i("solar_face_size",{w:K(n.hass,a.lu,1),h:K(n.hass,a.ls,1)})} \xB7 `:""}${i("solar_cols_hint")}`)}
${k?pr(n,["left","center","right"].map(x=>[x,i(`solar_align_${x}`)]),e.align??"left",x=>o({align:x})):_}
${pr(n,[[!0,i("solar_portrait")],[!1,i("solar_landscape")]],e.portrait!==!1,x=>o({portrait:x}))}
${pr(n,[["black",i("solar_look_black")],["blue",i("solar_look_blue")]],e.look==="blue"?"blue":"black",x=>o({look:x}))}
<div class="nf-form">
${w("module_w","solar_module_w",1.13)} ${w("module_h","solar_module_h",1.72)}
${R(n,i("solar_wp"),e.wp??__,x=>o({wp:g(50,1500,Math.round)(x)}),5,50)}
</div>
${Q(m`<button class="nf-btn" aria-pressed=${r.picking} ?disabled=${!n.admin} @click=${()=>r.picking=!r.picking}>${r.picking?"\u2713 ":""}${i("solar_pick")}</button>`,e.skip?.length?m`<button class="nf-btn" ?disabled=${!n.admin} @click=${()=>o({skip:null})}>${i("solar_pick_all")}</button>`:_)}
${r.picking?S(i("solar_pick_hint")):_}
<div class="nf-form">
${l?m`${R(n,i("solar_base"),e.base??0,x=>o({base:x>.001?Math.min(60,ae(x)):null}),.05,0)}
${R(n,i("solar_rotation"),e.rotation??0,b,5)}
${Q(m`<button class="nf-chip" ?disabled=${!n.admin} @click=${()=>b((e.rotation??0)-15)}>↺ 15°</button>`,m`<button class="nf-chip" ?disabled=${!n.admin} @click=${()=>b((e.rotation??0)+15)}>↻ 15°</button>`)}`:m`${R(n,i("solar_u"),e.u,x=>o({u:ae(x)}),.05)} ${R(n,i(a?.wall?"solar_v_wall":"solar_v"),e.v,x=>o({v:ae(x)}),.05)}`}
${a?.flat&&!l?R(n,i("solar_rotation"),e.rotation??0,y,5):_}
${a?.wall?R(n,i("solar_tilt_wall"),e.tilt??0,x=>o({tilt:g(0,90,Math.round)(x)}),5,0):_}
${a?.flat?R(n,i("solar_tilt"),e.tilt??15,x=>o({tilt:g(0,45,Math.round)(x)}),1,0):_}
${a?.flat&&!a.unbounded?D(n,i("solar_rack_ew"),e.rack==="ew",x=>o({rack:x?"ew":null}),{title:i("solar_rack_ew_hint")}):_}
${a&&!a.flat&&!a.wall?R(n,i("solar_rack_tilt"),e.tilt??0,x=>o({tilt:g(0,45,Math.round)(x)||null}),1,0):_}
${a?.wall||a?.flat?D(n,i(v),!!e.flip,x=>o({flip:x})):_}
</div>
${a?.flat&&!l?Q(m`<button class="nf-chip" ?disabled=${!n.admin} @click=${()=>y((e.rotation??0)-90)}>↺ 90°</button>`,m`<button class="nf-chip" ?disabled=${!n.admin} @click=${()=>y((e.rotation??0)+90)}>↻ 90°</button>`):_}
<p class="nf-sub">
${i("solar_summary",{n:d.modules,kwp:K(n.hass,d.kwp,1)})}${d.modules<u?m` · <b>${i("solar_partial",{n:d.modules,total:u})}</b>`:_}
</p>
<h4 class="nf-lib-head">🔗 ${i("solar_string")}</h4>
<div class="nf-form">${uk(t,e)}</div>
${S(i("solar_string_hint"))} ${S(i("solar_form_hint"))}
${n.admin?Q(m`<button class="nf-btn" ?disabled=${!a} @click=${()=>a&&o({...Zn(a,e.id),portrait:e.portrait})}>${i("solar_fit")}</button>`,m`<button class="nf-btn nf-danger" @click=${()=>r.removeField()}>${i("delete")}</button>`):_}
</section>`}var v_=t=>Math.round(t*1e3)/1e3,vs=class{ctx;sectionSel=null;windowSel=null;chimneySel=null;fieldSel=null;pickMode=!1;constructor(e){this.ctx=e}get sectionId(){return this.sectionSel}set sectionId(e){this.sectionSel=e,this.ctx.refresh()}get windowId(){return this.windowSel}set windowId(e){this.windowSel=e,this.ctx.refresh()}get chimneyId(){return this.chimneySel}set chimneyId(e){this.chimneySel=e,e&&(this.windowSel=null),this.ctx.refresh()}get solarId(){return this.fieldSel}set solarId(e){this.fieldSel=e,this.ctx.refresh()}get picking(){return this.pickMode}set picking(e){this.pickMode=e,this.ctx.refresh()}get doc(){return this.ctx.host.doc}get settings(){return this.doc.settings.roof}get admin(){return this.ctx.host.admin}get section(){return this.sectionSel?this.settings.sections?.find(e=>e.id===this.sectionSel):void 0}get window(){return this.windowSel?this.settings.windows?.find(e=>e.id===this.windowSel):void 0}get chimney(){return this.chimneySel?this.settings.chimneys?.find(e=>e.id===this.chimneySel):void 0}get field(){return this.fieldSel?this.settings.solar?.find(e=>e.id===this.fieldSel):void 0}isFixed(e){return!!e&&(!!e.locked||!!this.doc.settings.lock_plan)}useSections(e=!1){if(!this.admin)return;let n=(this.settings.sections??[]).length>0;e&&n&&!this.ctx.confirm(this.ctx.host.t("roof_regen_confirm"))||(this.ctx.host.change(r=>{r.settings.roof.type="custom",(e||!n)&&(r.settings.roof.sections=Ca(r,()=>P("roof")))}),this.sectionId=null)}addSection(e,n){if(!this.admin)return;let r=tm(this.doc,e,n);this.ctx.host.change(i=>{i.settings.roof.type="custom",i.settings.roof.sections=[...i.settings.roof.sections??[],r]}),this.sectionId=r.id}takeOutline(){let e=this.ctx.host.floor;if(!e||!this.sectionSel||!this.admin)return;let{wall_exterior:n,wall_interior:r}=this.doc.settings,i=Ta(e.rooms,e.walls??[],n,r);if(!i)return;let o=i.map(([s,a])=>[v_(s),v_(a)]);this.patchSection({shape:"flat",points:o,...jt(o)})}addDormer(e){let n=this.section;if(!n||!this.admin)return;let r=za(n,e,P("roof"));this.ctx.host.change(i=>{i.settings.roof.sections=[...i.settings.roof.sections??[],r]}),this.sectionId=r.id}patchSection(e){let n=this.sectionSel;!n||!this.admin||this.ctx.host.change(r=>{let i=r.settings.roof.sections?.find(o=>o.id===n);i&&Object.assign(i,e)})}removeCorner(e){let n=this.sectionSel;!n||!this.admin||this.ctx.host.change(r=>{let i=r.settings.roof.sections?.find(o=>o.id===n);i&&om(i,e)})}removeSection(){let e=this.sectionSel;!e||!this.admin||(this.ctx.host.change(n=>n.settings.roof.sections=(n.settings.roof.sections??[]).filter(r=>r.id!==e)),this.sectionId=null)}duplicateSection(){let e=this.section;if(!e||!this.admin)return;let n=nm(e);this.ctx.host.change(r=>r.settings.roof.sections=[...r.settings.roof.sections??[],n]),this.sectionId=n.id}addWindow(){if(!this.admin)return;let e=this.doc.settings.north??0,n=ai(Y(this.doc).filter(i=>!i.flat),e)??Y(this.doc)[0];if(!n)return;let r=oi(n,P("rwin"));this.ctx.host.change(i=>i.settings.roof.windows=[...i.settings.roof.windows??[],r]),this.windowSel=r.id,this.sectionId=null}patchWindow(e){let n=this.windowSel;!n||!this.admin||this.ctx.host.change(r=>{let i=r.settings.roof.windows?.find(s=>s.id===n);if(!i)return;Object.assign(i,e);let o=Y(r).find(s=>s.key===i.face);o&&Object.assign(i,mt(o,_n(i)))})}removeWindow(){let e=this.windowSel;!e||!this.admin||(this.ctx.host.change(n=>n.settings.roof.windows=(n.settings.roof.windows??[]).filter(r=>r.id!==e)),this.windowId=null)}addChimney(){if(!this.admin)return;let e=Y(this.doc),n=e.find(i=>!i.flat)??e[0];if(!n)return;let r=si(n,P("chim"));this.ctx.host.change(i=>i.settings.roof.chimneys=[...i.settings.roof.chimneys??[],r]),this.chimneySel=r.id,this.windowSel=null,this.sectionId=null}patchChimney(e){let n=this.chimneySel;!n||!this.admin||this.ctx.host.change(r=>{let i=r.settings.roof.chimneys?.find(s=>s.id===n);if(!i)return;Object.assign(i,e);let o=Y(r).find(s=>s.key===i.face);o&&Object.assign(i,mt(o,St(i,o)))})}removeChimney(){let e=this.chimneySel;!e||!this.admin||(this.ctx.host.change(n=>n.settings.roof.chimneys=(n.settings.roof.chimneys??[]).filter(r=>r.id!==e)),this.chimneyId=null)}addField(){if(!this.admin)return;let e=Y(this.doc),n=new Set((this.settings.solar??[]).map(o=>o.face)),r=this.doc.settings.north??0,i=ai(e.filter(o=>!n.has(o.key)),r)??ai(e,r);i&&(this.appendField(Zn(i,P("pv"))),this.sectionSel=null)}addWallField(){let e=this.ctx.floorId()??this.doc.floors[0]?.id,n=this.admin&&e?ja(this.doc,P("pv"),e):null;n&&this.appendField(n)}addGroundField(){this.admin&&this.appendField(ri(this.doc,P("pv")))}appendField(e){this.ctx.host.change(n=>n.settings.roof.solar=[...n.settings.roof.solar??[],e]),this.solarId=e.id}selectField(e){this.fieldSel=e,this.sectionSel=null;let n=this.settings.solar?.find(r=>r.id===e);n?.face.startsWith("wall:")&&this.ctx.setFloorId(n.face.split(":")[1]),this.ctx.refresh()}patchField(e){this.editField((n,r)=>{Object.assign(n,e);let i=Se(r,n);i&&Object.assign(n,mt(i,n))})}toggleCell(e){this.editField(n=>n.skip=h_(n.skip,e))}editField(e){let n=this.fieldSel;!n||!this.admin||this.ctx.host.change(r=>{let i=r.settings.roof.solar?.find(o=>o.id===n);i&&e(i,r)})}setString(e){let n=this.fieldSel;!n||!this.admin||this.ctx.host.change(r=>u_(r.settings.roof,n,e,{id:P("str"),name:i=>this.ctx.host.t("solar_string_n",{n:i})}))}patchString(e){let n=this.field?.string;!n||!this.admin||this.ctx.host.change(r=>{let i=r.settings.roof.strings?.find(o=>o.id===n);i&&Object.assign(i,e)})}removeField(){let e=this.fieldSel;!e||!this.admin||(this.ctx.host.change(n=>{n.settings.roof.solar=(n.settings.roof.solar??[]).filter(r=>r.id!==e),_c(n.settings.roof)}),this.solarId=null)}floorsTopDown(){return[...this.doc.floors].sort((e,n)=>n.elevation-e.elevation)}};var w_=(t,e)=>t.floors.flatMap(n=>n.furniture).find(n=>n.type===e),hk=t=>!t||t==="none";async function x_(t){let e;try{e=await t.hass.callWS({type:"energy/get_prefs"})}catch{return{kind:"failed"}}let n=Oh(t.hass,e),r=0,i=(o,s,a)=>{if(!a)return;let l=w_(t.doc(),o);!l&&t.canAdd()&&(t.addDevice(o),l=w_(t.doc(),o)),!(!l||!hk(l[s]))&&(t.setField(l.id,s,a),r++)};return i("meter","power",n.grid),i("inverter","power",n.solar),i("home_battery","power",n.battery),i("home_battery","soc",n.battery_soc),{kind:"done",filled:r}}var pk=/garage|carport/,fk=/hwr|hauswirt|technik|keller|abstell|utility|basement|boiler|heiz/,mk=/flur|diele|eingang|hall|entr|lobby/,k_=.25,fr=t=>Math.round(t*1e3)/1e3;function gk(t,e,n){let r=e.rooms.filter(d=>d.points.length>=3),i=d=>r.find(u=>d.test(n.roomLabel(u).toLowerCase())),o=r.find(d=>e.furniture.some(u=>u.type==="parking"&&C([u.x,u.z],d.points))),s=i(pk)??o,a=i(fk),l=t==="wallbox"?s:t==="meter"?a??i(mk)??s:a??s,c=[...r].sort((d,u)=>Math.abs(be(u.points))-Math.abs(be(d.points)))[0];return l??n.selected??c}function _k(t,e){let[n,r]=ve(t.points),i=t.points.some((s,a)=>!e.has(a)),o=null;return t.points.forEach((s,a)=>{if(i&&e.has(a))return;let l=t.points[(a+1)%t.points.length],c=Math.hypot(l[0]-s[0],l[1]-s[1]);if(o&&c<=o.length)return;let d=[(s[0]+l[0])/2,(s[1]+l[1])/2],u=[-(l[1]-s[1])/c+0,(l[0]-s[0])/c+0];(n-d[0])*u[0]+(r-d[1])*u[1]<0&&(u=[0-u[0],0-u[1]]),o={mid:d,inward:u,length:c}}),o}function $_(t,e,n,r){let[i,o,s]=ut(t),a={id:P("furniture"),type:t,rotation:0,w:i,d:o,h:s,variant:null};if(t==="grid_point"){let h=Lh(e),[f,g]=h?[h.x,h.z]:r.fallback;return{...a,x:fr(f),z:fr(g)}}let l=gk(t,n,r),[c,d]=l?ve(l.points):r.fallback;if(l){let h=new Set(n.openings.filter(g=>g.room_id===l.id).map(g=>g.edge)),f=_k(l,h);f&&([c,d]=[f.mid[0]+f.inward[0]*(o/2+k_),f.mid[1]+f.inward[1]*(o/2+k_)])}let u={...a,x:fr(c),z:fr(d)},p=l?Nr({...n,furniture:[...n.furniture,u]},u,e.settings.wall_interior):null;return p?{...u,x:fr(p.x),z:fr(p.z),rotation:p.rotation}:u}var ws=class{limit;undoStack=[];redoStack=[];constructor(e=100){this.limit=e}get canUndo(){return this.undoStack.length>0}get canRedo(){return this.redoStack.length>0}record(e){this.undoStack.push(JSON.stringify(e)),this.undoStack.length>this.limit&&this.undoStack.shift(),this.redoStack=[]}undo(e){let n=this.undoStack.pop();return n===void 0?null:(this.redoStack.push(JSON.stringify(e)),JSON.parse(n))}redo(e){let n=this.redoStack.pop();return n===void 0?null:(this.undoStack.push(JSON.stringify(e)),JSON.parse(n))}};var yc=t=>Math.round(t*1e3)/1e3,mr="unmovable",xs="no change";function S_(t,e,n,r){let i=o=>[yc(o[0]+n),yc(o[1]+r)];switch(e.kind){case"device":return t.placements.some(o=>o.entity_id===e.id)?{apply(o){let s=o.placements.find(a=>a.entity_id===e.id);s&&([s.x,s.z]=i([s.x,s.z]))}}:mr;case"furniture":return{apply(o){let s=o.furniture.find(a=>a.id===e.id);s&&([s.x,s.z]=i([s.x,s.z]))}};case"wall":return{apply(o){let s=(o.walls??[]).find(a=>a.id===e.id);s&&([s.a,s.b]=[i(s.a),i(s.b)])}};case"outdoor":return{apply(o){let s=o.outdoor.find(a=>a.id===e.id);s&&(s.points=s.points.map(i))}};case"opening":{let o=t.openings.find(g=>g.id===e.id),s=o?Ne(o,t.rooms,t.walls??[]):null;if(!o||!s)return mr;let a=s.room.points[s.edge],l=s.room.points[(s.edge+1)%s.room.points.length],c=Math.hypot(l[0]-a[0],l[1]-a[1])||1,d=(n*(l[0]-a[0])+r*(l[1]-a[1]))/c;if(Math.abs(d)<1e-9)return xs;let u=Gt(t.openings,o),p=!o.wall&&u.length>1?Xn(s.room,u):null;if(p){let g=Math.max(0,Math.min(li(s.room)-p.width,p.from+d));return Math.abs(g-p.from)<1e-9?xs:{apply(b){let y=b.openings.find(w=>w.id===e.id),v=y?ci(b.openings,s.room,y,g,p.width):null;v&&(b.openings=v)}}}let h=Math.min(o.width,c)/2,f=yc(Math.min(c-h,Math.max(h,o.offset+d)));return{apply(g){let b=g.openings.find(y=>y.id===e.id);b&&(b.offset=f)}}}case"room":{let o=t.rooms.find(a=>a.id===e.id);if(!o)return mr;let s=new Set(t.placements.filter(a=>C([a.x,a.z],o.points)).map(a=>a.entity_id));return{apply(a){let l=a.rooms.find(c=>c.id===e.id);if(l){if(e.corner!==null&&e.corner<l.points.length){l.points[e.corner]=i(l.points[e.corner]);return}l.points=l.points.map(i);for(let c of a.placements)s.has(c.entity_id)&&([c.x,c.z]=i([c.x,c.z]))}}}}}}var ks=t=>Math.round(t*1e3)/1e3,vc=t=>(t+90)%360;function M_(t,e,n){let r=i=>[i.x,i.z]=e([i.x,i.z]);for(let i of t.rooms)i.points=i.points.map(e);for(let i of t.furniture)r(i),n&&(i.rotation=vc(i.rotation));for(let i of t.placements)r(i),n&&(i.rotation=vc(i.rotation??0));for(let i of t.outdoor)i.points=i.points.map(e);for(let i of t.walls??[])[i.a,i.b]=[e(i.a),e(i.b)];t.background&&(r(t.background),n&&(t.background.rotation=vc(t.background.rotation??0)))}function bk(t,e){for(let r of t.settings.roof.sections??[]){let i=[e([r.x0,r.z0]),e([r.x1,r.z0]),e([r.x1,r.z1]),e([r.x0,r.z1])],[o,s]=[i.map(a=>a[0]),i.map(a=>a[1])];[r.x0,r.x1,r.z0,r.z1]=[Math.min(...o),Math.max(...o),Math.min(...s),Math.max(...s)],r.points&&(r.points=r.points.map(e))}let n=t.energy.meter;n&&([n.x,n.z]=e([n.x,n.z]))}function E_(t,e,n,r){if(e.allFloors){for(let i of t.floors)(!e.floorIds||e.floorIds.includes(i.id))&&M_(i,n,r);(!e.floorIds||t.floors.every(i=>e.floorIds.includes(i.id)))&&bk(t,n)}else{let i=t.floors.find(o=>o.id===e.floorId);i&&M_(i,n,r)}}function R_(t,e,n,r){E_(t,e,([i,o])=>[ks(i+n),ks(o+r)],!1)}function yk(t,e){let r=(e.allFloors?t.floors.filter(s=>!e.floorIds||e.floorIds.includes(s.id)):t.floors.filter(s=>s.id===e.floorId)).flatMap(s=>s.rooms.flatMap(a=>a.points));if(r.length===0)return null;let[i,o]=[r.map(s=>s[0]),r.map(s=>s[1])];return[(Math.min(...i)+Math.max(...i))/2,(Math.min(...o)+Math.max(...o))/2]}function A_(t,e){let n=yk(t,e);if(!n)return!1;let[r,i]=n;return E_(t,e,([o,s])=>[ks(r-(s-i)),ks(i+(o-r))],!0),!0}var $s=class{onChange;ids={room:null,opening:null,furniture:null,device:null,outdoor:null,wall:null};cornerSel=null;edgeSel=null;constructor(e){this.onChange=e}set(e,n){this.ids[e]=n,this.onChange()}get room(){return this.ids.room}set room(e){this.set("room",e)}get opening(){return this.ids.opening}set opening(e){this.set("opening",e)}get furniture(){return this.ids.furniture}set furniture(e){this.set("furniture",e)}get device(){return this.ids.device}set device(e){this.set("device",e)}get outdoor(){return this.ids.outdoor}set outdoor(e){this.set("outdoor",e)}get wall(){return this.ids.wall}set wall(e){this.set("wall",e)}get corner(){return this.cornerSel}set corner(e){this.cornerSel=e,this.onChange()}get edge(){return this.edgeSel}set edge(e){this.edgeSel=e,this.onChange()}select(e,n,r){let i=this.ids.room,o={room:null,opening:null,furniture:null,device:null,outdoor:null,wall:null};o[e]=n,e==="room"?o.room=n:e!=="outdoor"&&e!=="wall"&&(o.room=i),e==="device"&&n&&(o.room=r.roomOfDevice(n)??o.room),e==="opening"&&n&&(o.room=r.roomOfOpening(n)??o.room),(e!=="room"||n!==i)&&(this.cornerSel=null),this.edgeSel=null,this.ids=o,this.onChange()}get target(){for(let e of["device","opening","furniture","wall","outdoor","room"]){let n=this.ids[e];if(n)return{kind:e,id:n}}return null}};var Ss=class{onChange;menuOpen=!1;packagesOpen=!1;draft=null;shiftXMetres=0;shiftZMetres=0;wholeHouse=!1;line=null;query="";source="area";unfolded=new Set;copyChoice=null;constructor(e){this.onChange=e}get floorMenu(){return this.menuOpen}set floorMenu(e){this.menuOpen=e,this.onChange()}get floorCopy(){return this.copyChoice}set floorCopy(e){this.copyChoice=e,this.onChange()}get packages(){return this.packagesOpen}set packages(e){this.packagesOpen=e,this.onChange()}get spots(){return this.draft}set spots(e){this.draft=e,this.onChange()}get shiftX(){return this.shiftXMetres}set shiftX(e){this.shiftXMetres=e,this.onChange()}get shiftZ(){return this.shiftZMetres}set shiftZ(e){this.shiftZMetres=e,this.onChange()}get shiftAll(){return this.wholeHouse}set shiftAll(e){this.wholeHouse=e,this.onChange()}get notice(){return this.line}set notice(e){this.line=e,this.onChange()}get deviceQuery(){return this.query}set deviceQuery(e){this.query=e,this.onChange()}get deviceSource(){return this.source}set deviceSource(e){this.source=e,this.query="",this.onChange()}isUnfolded(e){return this.unfolded.has(e)}toggleUnfolded(e){let n=new Set(this.unfolded);n.delete(e)||n.add(e),this.unfolded=n,this.onChange()}};function wc(t,e){let n=new Set;return e.flatMap(r=>{let i=String(t?.states[r]?.attributes.symcon_source_entity||r),o=t?.states[i]?.attributes,s=Number(o?.symcon_id);return!s||!o?.symcon_archive||n.has(s)?[]:(n.add(s),[i])})}var F_,xc=class extends q{static properties={hass:{attribute:!1},ids:{attribute:!1},label:{attribute:!1},busy:{state:!0},error:{state:!0}};constructor(){super(),this.ids=[],this.label="",this.busy=!1,this.error=""}async open(e){e.stopPropagation(),this.busy=!0,this.error="";try{let n=new URL("./nextfloor-trend.js?v=84417e0b2573",import.meta.url).href;await(await(F_??=import(n).catch(i=>{throw F_=void 0,i}))).openTrend(this.hass,this.ids,this.label)}catch(n){this.error=n instanceof Error?n.message:String(n)}finally{this.busy=!1}}render(){if(!wc(this.hass,this.ids).length)return _;let e=this.label?`Trend anzeigen: ${this.label}`:"Trend anzeigen";return m`<button type="button" title=${e} aria-label=${e} aria-haspopup="dialog" ?disabled=${this.busy} @pointerdown=${n=>n.stopPropagation()} @click=${n=>{this.open(n)}}>
<svg width="12" height="12" viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.5" aria-hidden="true"><path d="M3 2v15h15M5 13l4-5 4 2 4-6"/></svg>
</button>${this.error?m`<span role="alert">${this.error}</span>`:_}`}static styles=J`:host{position:relative;display:inline-flex;flex:0 0 18px;width:18px;height:18px;vertical-align:middle;margin-left:3px;font-weight:normal;line-height:0}button{display:inline-flex;align-items:center;justify-content:center;box-sizing:border-box;width:18px;height:18px;padding:2px;border:0;border-radius:3px;background:transparent;color:var(--nf-accent,#40c8ff);opacity:.8;cursor:pointer}svg{display:block;flex-shrink:0}button:hover,button:focus-visible{opacity:1;background:#40c8ff18}button:focus-visible{outline:1px solid currentColor;outline-offset:1px}button:disabled{opacity:.4}span{position:absolute;right:0;top:22px;z-index:10;box-sizing:border-box;width:200px;padding:8px;border:1px solid #ff9b9b50;border-radius:6px;background:var(--nf-chrome-solid,#1c1c1c);font:12px/1.4 system-ui;color:#ff9b9b;white-space:normal}`};customElements.get("nf-trend-button")||customElements.define("nf-trend-button",xc);function T_(t,e,n=""){let r=wc(t,e);return r.length?m`<nf-trend-button .hass=${t} .ids=${r} .label=${n}></nf-trend-button>`:_}var kc=class extends q{static properties={hass:{attribute:!1},readings:{attribute:!1}};constructor(){super(),this.readings=[]}render(){return m`${xt.filter(e=>this.readings.some(n=>n.kind===e)).map(e=>m`<section aria-label=${Mt[e]}>
<h4>${nr[e]} ${Mt[e]}</h4>
${this.readings.filter(n=>n.kind===e).map(n=>m`<div class="reading" title=${`${n.manual?"Eigener Z\xE4hler":"Bereichsz\xE4hler"}${n.incomplete?" \xB7 Err: Mindestens ein Wert fehlt; angezeigt wird die Summe der verf\xFCgbaren Werte.":""}
${n.sources.map(r=>this.hass.states[r]?.attributes.symcon_path||this.hass.states[r]?.attributes.friendly_name||r).join(`
`)}`}>
<span>${ul(n)}${n.manual?m` <small>· Zähler</small>`:""}</span><b>${Gh(this.hass,n)}${T_(this.hass,n.sources,`${Mt[n.kind]} \xB7 ${ul(n)}`)}</b>
</div>`)}
</section>`)}`}static styles=J`
:host { display:block; color:var(--nf-text); font:inherit; }
section { padding:10px 0; border-bottom:1px solid var(--nf-line,#ffffff20); }
section:last-child { border:0; }
h4 { font:inherit; font-weight:600; margin:0 0 6px; }
.reading { display:flex; justify-content:space-between; gap:16px; margin:4px 0; }
.reading span { color:var(--nf-muted,#aaa); }
b { white-space:nowrap; font-variant-numeric:tabular-nums; }
small { font-size:.85em; }
`};customElements.get("nf-utility-report")||customElements.define("nf-utility-report",kc);var vk=/garage|carport|keller|cellar|basement|technik|heizung|heizraum|boiler|utility|werkstatt|schuppen|shed|dachboden|attic/i,Ii=t=>t.living??!vk.test(t.name),wk=.1,z_=t=>({x0:Math.min(...t.map(e=>e[0])),x1:Math.max(...t.map(e=>e[0])),z0:Math.min(...t.map(e=>e[1])),z1:Math.max(...t.map(e=>e[1]))});function $c(t,e,n,r,i=wk){if(n.points.length<3)return{roomId:n.id,floor:0,living:0,low:0};let o=z_(n.points),s=r.filter(f=>{let g=z_(f.footprint);return g.x1>=o.x0&&g.x0<=o.x1&&g.z1>=o.z0&&g.z0<=o.z1}),a=e.elevation+(n.ceiling!=null&&n.ceiling>0?n.ceiling:e.height),l=(t.settings.roof?.sections??[]).some(f=>!f.open),c=Xs(n),d=0,u=0,p=0;for(let f=o.x0+i/2;f<o.x1;f+=i)for(let g=o.z0+i/2;g<o.z1;g+=i){if(!C([f,g],n.points)||s.some(v=>C([f,g],v.footprint)))continue;let b=l?Zr(t,f,g):null,y=Math.min(a,b??1/0)-e.elevation-c;y>=2?d++:y>=1?u++:p++}let h=i*i;return{roomId:n.id,floor:(d+u+p)*h,living:Ii(n)?(d+u/2)*h:0,low:(u+p)*h}}var P_=new WeakMap;function Di(t,e){if(e.layer)return[];let n=P_.get(e);if(n&&n.roof===t.settings.roof)return n.areas;let r=xk(t,e);return P_.set(e,{roof:t.settings.roof,areas:r}),r}function xk(t,e){let n=me(e.rooms,{exterior:t.settings.wall_exterior,interior:t.settings.wall_interior},e.walls??[]).walls;return e.rooms.map(r=>$c(t,e,r,n))}var gr=t=>t.reduce((e,n)=>({floor:e.floor+n.floor,living:e.living+n.living,low:e.low+n.low}),{floor:0,living:0,low:0});function I_(t,e,n,r){let i=t.topology?r||t.topology.buildings[0]?.id:void 0,o=t.topology?t.floors.filter(l=>!l.outdoor_location_id&&l.building_id===i):t.floors,s=o.length,a=e?.name??(s===0?n.first:n.next(s));return{...Ee(P("floor"),a,Vd(o,e?.level)),ha_floor:e?.floor_id??null,...i?{building_id:i}:{}}}function Sc(t,e){let n=t.findIndex(i=>i.elevation>e.elevation),r=n<0?t.length:n;return[...t.slice(0,r),e,...t.slice(r)]}function D_(t,e,n){let r=t.findIndex(s=>s.id===e),i=r+n;if(r<0||i<0||i>=t.length)return[...t];let o=[...t];return[o[r],o[i]]=[o[i],o[r]],o}function O_(t,e){let n=new Set(t.floors.map(r=>r.ha_floor));return Object.values(e??{}).filter(r=>!n.has(r.floor_id)).sort((r,i)=>(r.level??99)-(i.level??99)||r.name.localeCompare(i.name))}function _r(t,e,n){if(!e.ha_floor)return[];let r=new Set(t.floors.flatMap(i=>i.rooms.map(o=>o.area_id)));return Object.values(n??{}).filter(i=>i.floor_id===e.ha_floor&&!r.has(i.area_id)).sort((i,o)=>i.name.localeCompare(o.name))}function H_(t,e,n){return Object.values(n??{}).filter(r=>r.floor_id===e.ha_floor||!t.floors.some(i=>i.ha_floor===r.floor_id))}function L_(t,e,n,r,i=P){let o=structuredClone(e),s=t.floors.filter(d=>!t.topology||d.building_id===e.building_id).reduce((d,u)=>Math.max(d,u.elevation+u.height),e.elevation+e.height),a=new Map,l=new Map;o.id=i("floor"),o.name=n,o.elevation=Math.round(s*1e3)/1e3,o.ha_floor=null,o.start_view=null,o.rooms=o.rooms.map(d=>{let u=i("room");return a.set(d.id,u),{...d,id:u,area_id:null}}),o.walls=(o.walls??[]).map(d=>{let u=i("wall");return l.set(d.id,u),{...d,id:u}}),o.openings=o.openings.filter(d=>a.has(d.room_id)).map(d=>({...d,id:i("opening"),room_id:a.get(d.room_id),wall:d.wall?l.get(d.wall)??null:d.wall}));let c=new Set(["meter","inverter","home_battery","wallbox","grid_point"]);return o.furniture=r.furniture?o.furniture.filter(d=>!c.has(d.type)).map(d=>Mk({...d,id:i("furniture")})):[],o.placements=r.devices?o.placements:[],o.outdoor=r.outdoor?o.outdoor.map(d=>({...d,id:i("outdoor")})):[],o}var kk=["entity","power","fan_entity","room_sensor"],$k=["door_left","door_right","soc","charge","export","status","temp_entity","temp_entity2","state_entity","state_entity2","color_entity","care_entity","cover_entity","type_entity","parent_meter","car","tap"],Sk=["gang_entities","pictures","types","meter_floors","show_when","extra_lights"];function Mk(t){let e={...t};for(let n of kk)(n==="entity"||n==="power"||e[n]!=null)&&(e[n]="none");for(let n of $k)e[n]!=null&&(e[n]=null);for(let n of Sk)delete e[n];return e}function C_(t,e,n,r){let i=t.floors.find(l=>l.id===e),o=t.floors.find(l=>l.id===r);if(!i||!o||i===o)return!1;let s=i.furniture.findIndex(l=>l.id===n);if(s<0)return!1;let[a]=i.furniture.splice(s,1);return o.furniture.push(a),!0}function Ek(t,e,n){if(e.layer||!e.rooms.length)return _;let r=t.t,i=gr(Di(t.doc,e)).living,o=gr(t.doc.floors.flatMap(s=>Di(t.doc,s))).living;return m`<p class="nf-sub nf-wide" title=${r("living_area_hint")}>
${r(t.doc.floors.length>1?"living_area_floor_house":"living_area_floor",{floor:Me(t.hass,i),house:Me(t.hass,o)})}
</p>
<div class="nf-actions nf-wide"><button class="nf-btn" title=${r("print_plan_hint")} @click=${()=>n.print()}>🖨️ ${r("print_plan")}</button></div>`}function Rk(t,e,n,r){let i=O_(t.doc,t.hass?.floors),o=t.doc.floors.filter(a=>!t.doc.topology||!t.floor||(t.floor.outdoor_location_id?a.outdoor_location_id===t.floor.outdoor_location_id:a.building_id===t.floor.building_id&&!a.outdoor_location_id)),s=()=>i.length>0?e.floorMenu=!e.floorMenu:n.addFloor(null);return m`<div class="nf-floor-list">
${[...o].reverse().map(a=>m`<button class="nf-chip" aria-pressed=${a.id===r} @click=${()=>n.openFloor(a.id)}>${a.name}</button>`)}
${t.admin?m`<button class="nf-btn" aria-expanded=${e.floorMenu} @click=${s}>+ ${t.t("add_floor")}</button>`:_}
</div>
${t.admin&&e.floorMenu?m`<div class="nf-floor-menu">
${S(t.t("floor_from_ha"))}
${i.map(a=>m`<button class="nf-btn" @click=${()=>n.addFloor(a)}>${a.name}${a.level!=null?m` <span class="nf-sub">· ${t.t("level",{n:a.level})}</span>`:_}</button>`)}
<button class="nf-btn" @click=${()=>n.addFloor(null)}>${t.t("floor_empty")}</button>
</div>`:_}`}function Ak(t,e,n,r){let i=(o,s,a)=>m`<input type="number" step="0.05" .value=${String(s)} aria-label=${o} @change=${l=>a(Number(l.target.value)||0)} />`;return m`<div class="nf-field nf-wide nf-shift" title=${t.t("floor_shift_hint")}>
<span>${t.t("floor_shift")}</span>
${i("X",e.shiftX,o=>e.shiftX=o)} ${i("Z",e.shiftZ,o=>e.shiftZ=o)}
<button class="nf-btn" ?disabled=${!e.shiftX&&!e.shiftZ} @click=${()=>n.shift()}>${t.t("floor_shift_apply")}</button>
<button class="nf-btn" title=${t.t("floor_turn_hint")} @click=${()=>n.turn()}>${t.t("floor_turn")}</button>
<button class="nf-btn" title=${t.t("floor_start_view_hint")} @click=${()=>n.rememberView()}>${t.t("floor_start_view")}</button>
${r.start_view?m`<button class="nf-btn" title=${t.t("floor_start_view_reset")} @click=${()=>t.change((o,s)=>s.start_view=null)}>↺</button>`:_}
<label class="nf-check nf-wide" title=${t.t("floor_shift_all_hint")}
><input type="checkbox" .checked=${e.shiftAll} @change=${o=>e.shiftAll=o.target.checked} />
${t.doc.topology?r.outdoor_location_id?"Gesamten Au\xDFenplan mitnehmen":"Alle Stockwerke dieses Geb\xE4udes mitnehmen":t.t("floor_shift_all")}</label
>
</div>`}function Fk(t,e,n,r){let i=t.t,o=s=>e.floorCopy={...r,...s};return m`<div class="nf-form nf-wide nf-copy-floor">
${S(i("floor_copy_hint"),"nf-wide")}
${D(t,i("floor_copy_furniture"),r.furniture,s=>o({furniture:s}))}
${D(t,i("floor_copy_devices"),r.devices,s=>o({devices:s}),{title:i("floor_copy_devices_hint")})}
${D(t,i("floor_copy_outdoor"),r.outdoor,s=>o({outdoor:s}))}
<div class="nf-actions nf-wide">
<button class="nf-btn nf-primary" @click=${()=>n.duplicateFloor(r)}>${i("floor_copy_make")}</button>
<button class="nf-btn" @click=${()=>e.floorCopy=null}>${i("cancel")}</button>
</div>
</div>`}function Tk(t,e){let n=O(t.hass,r=>Le(t.hass,r,[1,2]));return m`<details class="nf-wide nf-utility-meters"><summary>Stockwerkszähler</summary><div class="nf-form">
${S("Ohne eigenen Stockwerksz\xE4hler werden die Bereichsz\xE4hler der R\xE4ume summiert. In der verkn\xFCpften Bereichskategorie werden Kategorien oder Dummy-Module namens Elektro/Strom, Wasser, Gas, Heizen und K\xFChlen durchsucht. Darin werden Leistung bzw. Durchfluss und Verbrauch bzw. Energie erkannt. Ein eigener Stockwerksz\xE4hler ersetzt nur die zugeh\xF6rige Raumsumme. \xD7 stellt die automatische Raumsumme wieder her. Einheiten und Verbrauchszeitr\xE4ume werden getrennt ausgewertet.","nf-wide")}
${xt.map(r=>m`<b class="nf-wide">${nr[r]} ${Mt[r]}</b>${["power","energy"].map(i=>m`<label class="nf-field nf-wide">${i==="power"?"Leistung / Durchfluss":"Energie / Verbrauch"}
<nf-entity-picker .options=${n} .objectTree=${t.hass?.symconObjects} .fixed=${[{id:"__auto",label:"Raumsumme (automatisch)"}]} .value=${dl(t.hass,e,r,i)??"__auto"} ?disabled=${!t.admin}
.context=${{label:`${Mt[r]}: ${i==="power"?"Leistung / Durchfluss":"Energie / Verbrauch"}`,types:[1,2],states:t.hass?.states}}
@change=${o=>{o.stopPropagation();let s=o.detail.value;t.change((a,l)=>{l.utility_meters={...l.utility_meters,[r]:{...l.utility_meters?.[r],[i]:s&&s!=="__auto"&&s!=="none"?s:null}}})}}></nf-entity-picker>
</label>`)}`)}
<nf-utility-report class="nf-wide" .hass=${t.hass} .readings=${jh(t.hass,e,t.doc.floors.flatMap(r=>r.rooms))}></nf-utility-report>
</div></details>`}function zk(t,e,n,r){let i=t.t,o=c=>{t.floor?.id===r.id&&t.change((d,u)=>Object.assign(u,c))},s=H_(t.doc,r,t.hass?.floors),a=_r(t.doc,r,t.hass?.areas),l=[["",i("no_ha_floor")],...s.map(c=>[c.floor_id,c.name])];return m`<div class="nf-form">
${W(t,i("floor_name"),r.name,c=>o({name:c}),{wide:!0})}
${R(t,i("elevation"),r.elevation,c=>o({elevation:c}))}
${t.admin?Ak(t,e,n,r):_}
${R(t,i("height"),r.height,c=>o({height:Math.max(1,c)}),.05,1)}
${Object.keys(t.hass?.floors??{}).length>0?H(t,i("ha_floor"),r.ha_floor??"",l,c=>o({ha_floor:c||null}),{wide:!0}):_}
${D(t,i("floor_layer"),!!r.layer,c=>o({layer:c||void 0}),{title:i("floor_layer_hint")})}
${Z(t.hass)?Tk(t,r):m`${z(t,i("floor_power"),r.power_entity??null,void 0,O(t.hass,c=>c.startsWith("sensor.")&&t.hass?.states[c]?.attributes.device_class==="power"),c=>o({power_entity:c&&c!=="none"?c:null}))}${r.power_entity?S(i("floor_power_hint"),"nf-wide"):_}`}
${r.layer?_:Ge(t,i("wall_paint_floor"),r.wall_paint_outside,t.doc.settings.wall_paint_outside??no,c=>o({wall_paint_outside:c}))}
${Ek(t,r,n)}
${t.admin&&a.length>0?m`<div class="nf-actions nf-wide"><button class="nf-btn nf-primary" title=${i("area_rooms_hint")} @click=${()=>n.addAreaRooms(r)}>${i("area_rooms",{n:a.length})}</button></div>`:_}
${t.admin?m`<div class="nf-actions nf-wide">
<button class="nf-btn" @click=${()=>n.moveFloor(1)}>${i("move_up")}</button>
<button class="nf-btn" @click=${()=>n.moveFloor(-1)}>${i("move_down")}</button>
<button class="nf-btn" @click=${()=>e.floorCopy=e.floorCopy?null:{furniture:!0,devices:!1,outdoor:!1}}>${i("floor_copy")}</button>
<button class="nf-btn nf-danger" @click=${()=>n.deleteFloor()}>${i("delete_floor")}</button>
</div>
${e.floorCopy?Fk(t,e,n,e.floorCopy):_}
<div class="nf-actions nf-wide"><button class="nf-btn" title=${i("gaps_hint")} ?disabled=${r.rooms.length<2} @click=${()=>n.closeGaps()}>${i("gaps_close")}</button></div>
${e.notice?m`<p class="nf-sub nf-wide nf-notice">${e.notice}</p>`:_}`:_}
</div>`}function N_(t,e,n,r,i){return m`<section>
<h3>${t.doc.topology&&r?`${t.t("floor")} \xB7 ${r.name}`:t.t("floors")}</h3>
${t.doc.topology?_:Rk(t,e,n,i)} ${r?zk(t,e,n,r):_}
</section>`}var B_=["lamp_downlight","lamp_spot","lamp_panel","lamp_ceiling"];function V_(t,e){let n=ue(t.points);return{type:"lamp_downlight",rows:Math.max(1,Math.round((n.z1-n.z0)/1.2)),cols:Math.max(1,Math.round((n.x1-n.x0)/1.2)),entity:e[0]??null}}function Ms(t,e){let[n,r,i]=nt[e.type];return Ud(t,e.rows,e.cols).map(([o,s])=>({id:P("furniture"),type:e.type,x:o,z:s,rotation:0,w:n,d:r,h:i,variant:null,entity:e.entity??"none",power:null}))}var Mc=t=>Math.max(1,Math.min(12,Math.round(t)));var Pk=globalThis.__nfAnnounced??new Set;globalThis.__nfAnnounced=Pk;var W_=/^(media_player|assist_satellite)\./;function Ik(t,e){return e?Object.values(t.entities??{}).filter(n=>!n.hidden&&(n.area_id??(n.device_id?t.devices?.[n.device_id]?.area_id:null))===e).map(n=>n.entity_id):[]}function K_(t,e){let n=t.states[e];return!n||n.state==="unavailable"?!1:e.startsWith("notify.")?t.entities?.[e]?.platform==="alexa_devices"&&e.endsWith("_announce"):n.state==="off"||n.state==="unknown"?!1:n.attributes.device_class!=="tv"}function j_(t,e,n){if(n.announce_speaker==="none")return null;if(n.announce_speaker)return n.announce_speaker;if(e&&n.points.length>=3){let o=[...e.placements.filter(s=>W_.test(s.entity_id)).map(s=>({id:s.entity_id,x:s.x,z:s.z})),...e.furniture.filter(s=>s.entity&&W_.test(s.entity)).map(s=>({id:s.entity,x:s.x,z:s.z}))].find(s=>C([s.x,s.z],n.points)&&K_(t,s.id));if(o)return o.id}let r=Ik(t,n.area_id);for(let i of["assist_satellite.","notify.","media_player."]){let o=r.filter(s=>s.startsWith(i)&&K_(t,s)).sort()[0];if(o)return o}return null}function G_(t,e,n){return e.rooms.length===0?_:m`<section>
<h3>${t.t("rooms")}</h3>
<div class="nf-room-list">
${Z(t.hass)?[...new Set(e.rooms.map(r=>r.area_id??""))].map(r=>m`<div class="nf-room-area-group" data-area-id=${r}>
<h4>${r?cs(t.hass,r)||t.hass?.areas?.[r]?.name||"Verkn\xFCpfter Bereich":"Ohne verkn\xFCpften Bereich"}</h4>
${e.rooms.filter(i=>(i.area_id??"")===r).map(i=>m`<button class="nf-row" @click=${()=>n.select(i.id)}><span>${i.name}</span><span class="nf-muted">${Me(t.hass,ye(i.points))}</span></button>`)}
</div>`):e.rooms.map(r=>m`<button class="nf-row" @click=${()=>n.select(r.id)}>
<span>${r.name}</span><span class="nf-muted">${Me(t.hass,ye(r.points))}</span>
</button>`)}
</div>
</section>`}function Dk(t,e,n,r){let i=e.spots,o=c=>e.spots={...i,...c},s=Ms(n,i).length,a=O(t.hass,c=>/^(light|switch|input_boolean)\./.test(c)),l=B_.map(c=>[c,t.t(`furn_${c}`)]);return m`<div class="nf-form nf-spot-form">
${H(t,t.t("spots_type"),i.type,l,c=>o({type:c}),{wide:!0})}
${R(t,t.t("spots_cols"),i.cols,c=>o({cols:Mc(c)}),1,1)}
${R(t,t.t("spots_rows"),i.rows,c=>o({rows:Mc(c)}),1,1)}
${z(t,t.t("furn_entity_light"),i.entity,void 0,a,c=>o({entity:c==="none"?null:c}),{types:[0,1,2],role:"light"})}
<div class="nf-actions nf-wide">
<button class="nf-btn nf-primary" ?disabled=${s===0} @click=${()=>r.placeSpots()}>${t.t("spots_add",{n:s})}</button>
<button class="nf-btn" @click=${()=>e.spots=null}>${t.t("cancel")}</button>
</div>
${S(t.t("spots_hint"),"nf-wide")}
</div>`}function Ok(t,e,n,r){return m`<details class="nf-points" ?open=${!n}>
<summary>${t.t("points")} (${e.points.length})</summary>
${e.points.map((i,o)=>m`<div class="nf-point ${o===r.corner?"nf-point-sel":""}">
<span class="nf-muted">${o+1}</span>
${R(t,t.t("x"),i[0],s=>r.setCorner(o,0,s))} ${R(t,t.t("z"),i[1],s=>r.setCorner(o,1,s))}
${t.admin?m`<button class="nf-btn" title=${t.t("delete_point")} ?disabled=${e.points.length<=3} @click=${()=>r.removeCorner(o)}>×</button>`:_}
</div>`)}
</details>`}function Hk(t,e,n){let r=t.floor,i=r?$c(t.doc,r,e,n):void 0;if(!i||i.floor<=0)return _;let o=t.t;return Ii(e)?m`<p class="nf-sub nf-wide" title=${o("living_area_hint")}>
${i.low>.05?o("living_area_low",{living:Me(t.hass,i.living),floor:Me(t.hass,i.floor),low:Me(t.hass,i.low)}):o("living_area",{living:Me(t.hass,i.living)})}
</p>`:m`<p class="nf-sub nf-wide">${o("living_area_none",{floor:Me(t.hass,i.floor)})}</p>`}function Lk(t,e,n,r){let i=t.t,o=s=>r.patch({ceiling:Math.abs(s-n.height)<.005?null:Math.min(20,Math.max(1,Math.round(s*1e3)/1e3))});return m`${R(t,i("room_ceiling"),e.ceiling??n.height,o,.01,1)}
${e.ceiling!=null?m`<button class="nf-btn nf-field-btn" ?disabled=${!t.admin} @click=${()=>r.patch({ceiling:null})}>${i("height_auto")}</button>`:_}
${S(i("room_ceiling_tip"),"nf-wide")}
${e.ceiling!=null&&e.ceiling>n.height+.005?S(i("room_ceiling_through",{ceiling:K(t.hass,e.ceiling,2),floor:K(t.hass,n.height,2)}),"nf-wide"):_}`}function Ck(t,e,n,r){let i=t.t;if(!t.hass||Z(t.hass))return m``;let o=j_(t.hass,n,{...e,announce_speaker:null}),s=O(t.hass,c=>/^(media_player|assist_satellite)\./.test(c)||c.startsWith("notify.")&&c.endsWith("_announce")),a=e.announce_quiet??null,l=(c,d)=>{if(!d)return r.patch({announce_quiet:null});r.patch({announce_quiet:{from:a?.from??"20:00",to:a?.to??"07:00",[c]:d}})};return m`${z(t,i("room_announce_speaker"),e.announce_speaker??null,o,s,c=>r.patch({announce_speaker:c}))}
<div class="nf-field nf-wide nf-quiet-time">
${i("room_announce_quiet")}
<span>
<input type="time" .value=${a?.from??""} ?disabled=${!t.admin} aria-label=${`${i("room_announce_quiet")} 1`} @change=${c=>l("from",c.target.value)} />
–
<input type="time" .value=${a?.to??""} ?disabled=${!t.admin} aria-label=${`${i("room_announce_quiet")} 2`} @change=${c=>l("to",c.target.value)} />
${a?m`<button class="nf-btn nf-field-btn" ?disabled=${!t.admin} @click=${()=>r.patch({announce_quiet:null})}>×</button>`:_}
</span>
</div>
${S(i("room_announce_hint"),"nf-wide")}`}function Ec(t,e,n,r){let i=t.t,o=Dn(n.points),s=ue(n.points),a=Object.values(t.hass?.areas??{}).sort((h,f)=>h.name.localeCompare(f.name)),l=[["",i("no_area")],...a.map(h=>[h.area_id,h.name])],c=t.floor?me(t.floor.rooms,{exterior:t.doc.settings.wall_exterior,interior:t.doc.settings.wall_interior},t.floor.walls??[]).walls:[],d=t.floor?fh(n,c):null,u=Cd.map(h=>[h,i(`mat_${h}`)]),p=h=>m`<button class="nf-btn" @click=${()=>r.applyPackage(h)}><b>${i(`pkg_${h}`)}</b><span>${i(`pkg_${h}_desc`)}</span></button>`;return m`<section>
<div class="nf-h3row"><h3>${i("room")}</h3>${r.lockButton}</div>
${t.doc.topology&&t.floor?m`<div class="nf-room-context" title=${Pr(t.doc,t.floor)}>${Pr(t.doc,t.floor)}</div>`:_}
<div class="nf-form">
${W(t,i("room_name"),n.name,h=>r.patch({name:h}),{wide:!0})}
${H(t,Z(t.hass)?"Bereich (Symcon)":i("area"),n.area_id??"",l,h=>r.setArea(h),{wide:!0})}
${Z(t.hass)?S("Der Raum geh\xF6rt zur oben gew\xE4hlten Etage und damit zu deren Geb\xE4ude. Hier verkn\xFCpfst du seine Symcon-Bereichskategorie. Mehrere R\xE4ume derselben Etage k\xF6nnen dieselbe Kategorie verwenden. Der Objektbaum und der Raumname werden dadurch nicht ver\xE4ndert.","nf-wide"):_}
${Z(t.hass)&&n.area_id?m`<button type="button" class="nf-btn nf-wide nf-take-area-name" ?disabled=${!t.admin||!cs(t.hass,n.area_id)} @click=${()=>r.patch({name:cs(t.hass,n.area_id)})}>Bereichsnamen übernehmen</button>`:_}
${(n.sub_areas??[]).map(h=>m`<span class="nf-chip nf-wide">${t.hass?.areas?.[h]?.name??h} <button class="nf-btn nf-field-btn" ?disabled=${!t.admin} title=${i("delete")} @click=${()=>r.patch({sub_areas:(n.sub_areas??[]).filter(f=>f!==h).length?(n.sub_areas??[]).filter(f=>f!==h):null})}>✕</button></span>`)}
${n.area_id?H(t,i("sub_area_add"),"",l.filter(([h])=>h!==n.area_id&&!(n.sub_areas??[]).includes(h)),h=>h&&r.patch({sub_areas:[...n.sub_areas??[],h]}),{wide:!0,title:i("sub_area_hint")}):_}
${H(t,i("material"),n.floor_material,u,h=>r.patch({floor_material:h}),{wide:!0})}
${Ge(t,i("wall_paint_room"),n.wall_paint,t.doc.settings.wall_paint_inside??ro,h=>r.patch({wall_paint:h}))}
${t.floor?Lk(t,n,t.floor,r):_}
${R(t,i("room_floor_offset"),n.floor_offset??0,h=>r.patch({floor_offset:Math.abs(h)<.005?null:Math.max(-2,Math.min(2,Math.round(h*1e3)/1e3))}),.01)}
${S(i("room_floor_offset_hint"),"nf-wide")}
${z(t,i("room_clean"),n.clean_entity??null,void 0,O(t.hass,h=>/^(script|button|input_button)\./.test(h)),h=>r.patch({clean_entity:h&&h!=="none"?h:null}))}
${n.clean_entity?_:S(i("room_clean_hint"),"nf-wide")}
${Z(t.hass)?_:z(t,i("floor_heating"),n.floor_heating??null,void 0,O(t.hass,h=>/^(climate|switch|valve|binary_sensor|input_boolean)\./.test(h)),h=>r.patch({floor_heating:h&&h!=="none"?h:null}))}
${n.floor_heating&&!Z(t.hass)?S(i("floor_heating_hint"),"nf-wide"):_}
${Ck(t,n,t.floor??null,r)}
${d?m`<p class="nf-sub nf-wide" title=${i("room_inner_hint")}>${i("room_inner",{w:pe(t.hass,d[0]),d:pe(t.hass,d[1])})}</p>`:_}
${Hk(t,n,c)}
${D(t,i("room_living"),Ii(n),h=>r.patch({living:h===Ii({name:n.name,living:null})?null:h}),{title:i("living_area_hint")})}
${o?m`${R(t,i("x"),s.x0,h=>r.setRect("x",h))} ${R(t,i("z"),s.z0,h=>r.setRect("z",h))}
${R(t,i("width"),s.x1-s.x0,h=>r.setRect("w",h),.01,.05)}
${R(t,i("depth"),s.z1-s.z0,h=>r.setRect("d",h),.01,.05)}`:_}
</div>
<div class="nf-actions">
<button class="nf-btn" title=${i("room_start_view_hint")} ?disabled=${!t.admin} @click=${()=>r.rememberView()}>${i("room_start_view")}</button>
${n.start_view?m`<button class="nf-btn" title=${i("room_start_view_reset")} ?disabled=${!t.admin} @click=${()=>r.patch({start_view:null})}>↺</button>`:_}
</div>
${r.wallHeights} ${r.climate} ${Z(t.hass)?Zh(t,n,h=>r.patch(h)):_} ${Ok(t,n,o,r)}
${t.admin?m`<div class="nf-actions">
<button class="nf-btn nf-primary" @click=${()=>e.packages=!e.packages}>${i("pkg_open")}</button>
<button class="nf-btn" @click=${()=>r.openSpots()}>${i("spots_place")}</button>
<button class="nf-btn" @click=${()=>r.duplicate()}>${i("duplicate")}</button>
<button class="nf-btn nf-danger" @click=${()=>r.remove()}>${i("delete")}</button>
</div>`:_}
${e.spots?Dk(t,e,n,r):_}
${e.packages?m`<div class="nf-packages">${Ah.map(p)}${S(i("pkg_hint"))}</div>`:_}
</section>`}var U_=J`
.nf-editor-context{display:grid;gap:8px;padding:10px 12px;border-bottom:1px solid var(--nf-line)}
.nf-editor-building-row,.nf-editor-floor-nav{display:flex;gap:8px;align-items:center;flex-wrap:wrap;min-width:0}
.nf-editor-building-row>label{display:flex;gap:8px;align-items:center;font-size:12px;min-width:0;flex:1}
.nf-editor-building-select{font:inherit;color:var(--nf-text);background:var(--nf-chrome-solid);border:1px solid var(--nf-line);border-radius:8px;padding:7px 10px;min-width:0;width:min(100%,480px)}
.nf-editor-floor-nav{font-size:12px}.nf-editor-floor-nav .nf-editor-move-floor{margin-left:auto;font-size:11px}
.nf-hierarchy-dialog,.nf-floor-move-dialog{box-sizing:border-box;width:min(1050px,calc(100vw - 24px));max-height:calc(100dvh - 24px);overflow:auto;padding:18px;border:1px solid var(--nf-line);border-radius:14px;color:var(--nf-text);background:var(--nf-chrome-solid,#1c1c1c);box-shadow:0 20px 70px #0008;font:13px/1.4 system-ui}
.nf-hierarchy-dialog::backdrop,.nf-floor-move-dialog::backdrop{background:#050b16a6;backdrop-filter:blur(3px)}
.nf-hierarchy-dialog>header,.nf-floor-move-dialog>header{display:flex;align-items:center;justify-content:space-between;gap:12px;margin-bottom:16px}.nf-hierarchy-dialog h2,.nf-floor-move-dialog h2{font-size:17px;margin:0}
.nf-floor-move-dialog{width:min(650px,calc(100vw - 24px))}.nf-floor-move-source{overflow-wrap:anywhere}.nf-floor-move-dialog>.nf-btn{margin-top:16px}
.nf-room-area-group h4{font-size:11px;color:var(--nf-muted);margin:12px 0 4px}.nf-room-context{font-size:11px;color:var(--nf-muted);margin:4px 0 12px;overflow-wrap:anywhere}
.nf-value-links h4 { margin: 12px 0; }
.nf-value-add { min-width: 30px; font-size: 18px; padding: 3px 8px; }
.nf-value-link { padding: 8px 0; border-bottom: 1px solid var(--nf-line); }
:host {
display: block;
height: 100%;
}
.nf-editor {
position: relative;
display: grid;
grid-template-columns: minmax(0, 1fr) 320px;
height: 100%;
min-height: 0;
}
.nf-editor:has(> .nf-side-strip) {
grid-template-columns: minmax(0, 1fr) 52px;
}
.nf-side-strip {
padding: 10px 6px;
gap: 8px;
align-items: center;
}
.nf-strip-btn {
width: 40px;
height: 40px;
border: 1px solid var(--nf-line);
border-radius: 12px;
background: var(--nf-chrome);
color: var(--nf-text);
font-size: 18px;
cursor: pointer;
}
.nf-strip-hot {
border-color: var(--nf-accent);
color: var(--nf-accent);
}
.nf-side-overlay {
position: absolute;
top: 0;
right: 0;
bottom: 0;
width: min(340px, 60%);
z-index: 6;
box-shadow: -12px 0 32px rgba(0, 0, 0, 0.45);
}
.nf-pin-row {
display: flex;
gap: 8px;
justify-content: flex-end;
}
.nf-3d-size {
display: inline-flex;
align-items: center;
gap: 4px;
color: var(--nf-muted);
font-size: 12px;
}
.nf-3d-size input {
width: 58px;
padding: 4px 6px;
font: inherit;
color: var(--nf-text);
background: var(--nf-chrome-solid);
border: 1px solid var(--nf-line);
border-radius: 8px;
}
.nf-3d-select {
font: inherit;
color: var(--nf-text);
background: var(--nf-chrome-solid);
border: 1px solid var(--nf-line);
border-radius: 999px;
padding: 4px 10px;
}
.nf-editor.nf-narrow {
grid-template-columns: 1fr;
grid-template-rows: minmax(360px, 62vh) auto;
height: auto;
}
.nf-main {
display: grid;
grid-template-columns: minmax(0, 1fr);
grid-template-rows: auto 1fr;
min-height: 0;
min-width: 0;
}
/* a row of tools wider than the plan scrolls inside its pill instead of pushing the plan over the side bar (#67) */
.nf-toolbar .nf-seg {
max-width: 100%;
overflow-x: auto;
scrollbar-width: none;
}
.nf-toolbar .nf-seg > button {
flex: none;
}
.nf-toolbar {
display: flex;
flex-wrap: wrap;
gap: 8px;
align-items: center;
padding: 10px 12px;
}
/* phones: the tools as one dropdown instead of a row of eleven buttons */
.nf-tool-select {
font: inherit;
padding: 8px 10px;
border-radius: 10px;
border: 1px solid var(--nf-line);
background: var(--nf-bg2);
color: var(--nf-text);
}
.nf-warn {
color: var(--nf-warm);
font-size: 12.5px;
}
.nf-picture-group {
display: grid;
gap: 6px;
margin: 6px 0 10px;
padding: 8px;
border: 1px solid var(--nf-line);
border-radius: 10px;
}
.nf-picture-group > select {
min-width: 0;
}
.nf-picture-row {
display: grid;
grid-template-columns: 1fr auto auto;
gap: 6px;
align-items: center;
padding: 6px;
border-radius: 8px;
background: color-mix(in srgb, var(--nf-line) 40%, transparent);
}
.nf-picture-row input[type="url"] {
grid-column: 1 / -1;
min-width: 0;
}
.nf-picture-row > .nf-sub,
.nf-picture-row > .nf-picture-camera {
grid-column: 1 / -1;
}
.nf-picture-row.nf-rule-hit {
outline: 1px solid var(--nf-accent);
}
.nf-rule-now {
grid-column: 1 / -1;
}
.nf-rule-hit {
color: var(--nf-accent);
}
.nf-picture-reuse {
grid-column: 1 / -1;
display: flex;
flex-wrap: wrap;
gap: 4px;
}
.nf-picture-reuse-btn {
padding: 2px;
border: 1px solid var(--nf-line);
border-radius: 6px;
background: var(--nf-chrome-solid);
cursor: pointer;
}
.nf-picture-reuse-btn img {
display: block;
height: 28px;
max-width: 60px;
object-fit: contain;
}
.nf-picture-reuse-btn:hover {
border-color: var(--nf-accent);
}
.nf-picture-thumb {
max-height: 60px;
max-width: 100%;
border-radius: 6px;
justify-self: start;
}
.nf-picture-pick {
justify-self: start;
}
.nf-parking-row {
display: flex;
gap: 6px;
align-items: center;
margin: 4px 0;
}
.nf-parking-row input,
.nf-parking-row select {
flex: 1;
min-width: 0;
}
.nf-stage-pair {
display: flex;
min-height: 0;
min-width: 0;
}
.nf-stage-pair > .nf-canvas-wrap {
flex: 1 1 var(--nf-split, 55%);
min-width: 0;
}
.nf-split > .nf-canvas-wrap {
flex: 0 0 var(--nf-split, 55%);
}
.nf-split-handle {
flex: 0 0 8px;
cursor: col-resize;
background: var(--nf-line);
touch-action: none;
}
.nf-split-handle:hover {
background: var(--nf-accent);
}
.nf-editor-3d {
position: relative;
flex: 1 1 0;
min-width: 240px;
min-height: 0;
border-left: 1px solid var(--nf-line);
container-type: size;
container-name: nf;
}
.nf-editor-3d nf-view3d {
display: block;
height: 100%;
}
.nf-3d-walls {
position: absolute;
top: 10px;
left: 10px;
z-index: 3;
}
.nf-3d-bar {
position: absolute;
left: 50%;
bottom: 12px;
transform: translateX(-50%);
z-index: 3;
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: center;
gap: 8px;
max-width: calc(100% - 24px);
padding: 6px 8px 6px 14px;
border-radius: 999px;
background: var(--nf-chrome);
box-shadow: var(--nf-shadow);
font-size: 13px;
}
.nf-danger-chip {
color: var(--nf-danger, #ff6b7a);
}
.nf-narrow .nf-stage-pair.nf-split {
flex-direction: column;
}
.nf-narrow .nf-split > .nf-canvas-wrap {
flex: 1 1 auto;
}
.nf-narrow .nf-editor-3d {
flex: 0 0 42%;
min-width: 0;
border-left: none;
border-top: 1px solid var(--nf-line);
}
.nf-canvas-wrap {
position: relative;
min-height: 0;
overflow: hidden;
background: radial-gradient(ellipse at 50% 35%, var(--nf-bg2), var(--nf-bg) 75%);
}
svg.nf-plan {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
touch-action: none;
user-select: none;
-webkit-user-select: none;
cursor: default;
}
svg.nf-tool-rect,
svg.nf-tool-polygon {
cursor: crosshair;
}
.nf-grid-minor {
stroke: color-mix(in srgb, var(--nf-accent) 5%, transparent);
stroke-width: 1;
}
.nf-grid-major {
stroke: color-mix(in srgb, var(--nf-soft) 16%, transparent);
stroke-width: 1;
}
.nf-origin {
fill: color-mix(in srgb, var(--nf-soft) 50%, transparent);
}
.nf-ghost {
fill: none;
stroke: rgba(138, 155, 184, 0.35);
stroke-dasharray: 4 4;
}
.nf-void {
fill: rgba(138, 155, 184, 0.12);
stroke: rgba(138, 155, 184, 0.55);
stroke-dasharray: 2 3;
}
.nf-wall {
fill: #1b2a47;
}
.nf-wall-ext {
fill: #22345a;
}
.nf-room {
fill: color-mix(in srgb, var(--nf-accent) 5%, transparent);
stroke: color-mix(in srgb, var(--nf-accent) 75%, transparent);
stroke-width: 1.5;
stroke-linejoin: round;
cursor: pointer;
}
.nf-room:hover {
fill: color-mix(in srgb, var(--nf-accent) 9%, transparent);
}
.nf-room-sel {
fill: color-mix(in srgb, var(--nf-accent) 14%, transparent);
stroke: var(--nf-accent);
stroke-width: 2.5;
}
.nf-room-name {
fill: var(--nf-text);
font: 600 13px var(--nf-title-font);
text-anchor: middle;
}
.nf-room-area {
fill: var(--nf-muted);
font: 500 11.5px var(--nf-font);
text-anchor: middle;
font-variant-numeric: tabular-nums;
}
.nf-dim {
fill: var(--nf-accent);
font: 600 11.5px var(--nf-font);
text-anchor: middle;
font-variant-numeric: tabular-nums;
paint-order: stroke;
stroke: var(--nf-bg);
stroke-width: 3px;
}
.nf-vertex circle:not(.nf-hit) {
fill: var(--nf-bg);
stroke: var(--nf-accent);
stroke-width: 2;
}
.nf-vertex-sel circle:not(.nf-hit) {
fill: var(--nf-accent);
}
.nf-vertex,
.nf-mid {
cursor: grab;
}
.nf-hit {
fill: transparent;
}
.nf-mid circle:not(.nf-hit) {
fill: color-mix(in srgb, var(--nf-soft) 35%, transparent);
stroke: var(--nf-soft);
}
.nf-mid path {
stroke: var(--nf-text);
stroke-width: 1.5;
}
.nf-draft {
fill: rgba(255, 181, 71, 0.08);
stroke: var(--nf-warm);
stroke-width: 2;
stroke-dasharray: 6 4;
}
polyline.nf-draft {
fill: none;
}
.nf-draft-pt {
fill: var(--nf-warm);
}
.nf-draft-first {
fill: transparent;
stroke: var(--nf-warm);
stroke-width: 2;
}
.nf-cursor {
fill: var(--nf-warm);
}
.nf-guide {
stroke: rgba(255, 95, 210, 0.55);
stroke-dasharray: 3 5;
}
.nf-snap {
fill: none;
stroke: #ff5fd2;
stroke-width: 2;
}
.nf-dim {
font: 600 10px var(--nf-font);
fill: var(--nf-text);
paint-order: stroke;
stroke: rgba(10, 16, 32, 0.85);
stroke-width: 3px;
}
.nf-note rect {
fill: #ffe58a;
stroke: #8a6d00;
stroke-width: 1;
}
.nf-note text {
fill: #3a2e00;
font: 700 13px var(--nf-font);
pointer-events: none;
}
.nf-note-due rect {
fill: #ffa726;
}
.nf-note-sel rect {
stroke: var(--nf-accent, #03a9f4);
stroke-width: 3;
}
.nf-note {
cursor: pointer;
}
.nf-keys-open {
position: absolute;
right: 12px;
bottom: 30px;
width: 30px;
height: 30px;
border-radius: 50%;
border: 1px solid var(--nf-line);
background: var(--nf-chrome, rgba(20, 28, 48, 0.8));
color: var(--nf-text);
font: 700 15px var(--nf-font);
cursor: pointer;
}
.nf-keys {
position: absolute;
inset: 0;
display: grid;
place-items: center;
background: rgba(0, 0, 0, 0.35);
z-index: 20;
}
.nf-keys-card {
max-width: min(520px, 92%);
max-height: 85%;
overflow: auto;
padding: 14px 18px;
border-radius: 14px;
background: var(--nf-surface, #1c1c1c);
box-shadow: var(--nf-shadow);
}
.nf-keys dl {
display: grid;
grid-template-columns: auto 1fr;
gap: 6px 14px;
margin: 8px 0 0;
font-size: 13px;
}
.nf-keys dt {
white-space: nowrap;
}
.nf-keys dd {
margin: 0;
color: var(--nf-muted);
}
.nf-keys kbd {
display: inline-block;
padding: 1px 6px;
border-radius: 5px;
border: 1px solid var(--nf-line);
font: 600 12px var(--nf-font);
}
.nf-tour {
position: absolute;
left: 16px;
bottom: 36px;
max-width: 340px;
padding: 12px 16px;
border-radius: 14px;
background: var(--nf-surface, #1c1c1c);
border: 1px solid var(--nf-accent, #03a9f4);
box-shadow: var(--nf-shadow);
z-index: 15;
}
.nf-tour h3 {
margin: 2px 0 6px;
}
.nf-tour p {
margin: 0 0 10px;
font-size: 13px;
line-height: 1.45;
}
.nf-tour-step {
font-size: 11px;
color: var(--nf-muted);
}
.nf-hint {
position: absolute;
left: 12px;
right: 12px;
bottom: 8px;
margin: 0;
font-size: 12px;
color: var(--nf-muted);
pointer-events: none;
}
.nf-side {
border-left: 1px solid var(--nf-line);
background: var(--nf-chrome-solid);
overflow-y: auto;
padding: 12px 14px 24px;
display: flex;
flex-direction: column;
gap: 18px;
min-height: 0;
}
.nf-narrow .nf-side {
border-left: none;
border-top: 1px solid var(--nf-line);
}
h3,
summary {
margin: 0 0 8px;
font-size: 11.5px;
text-transform: uppercase;
letter-spacing: 0.06em;
color: var(--nf-muted);
font-weight: 600;
}
summary {
cursor: pointer;
margin: 0;
}
details[open] > summary {
margin-bottom: 8px;
}
.nf-floor-list,
.nf-compass {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 14px;
padding: 10px 12px;
border: 1px solid var(--nf-line);
border-radius: 12px;
}
.nf-compass-dial {
width: 96px;
height: 96px;
flex: none;
}
.nf-compass-ring {
fill: none;
stroke: var(--nf-line);
stroke-width: 1.5;
}
.nf-compass-up {
fill: var(--nf-soft);
}
.nf-compass-n {
fill: var(--nf-accent);
}
.nf-compass-s {
fill: color-mix(in srgb, var(--nf-soft) 55%, transparent);
}
.nf-compass-label {
fill: var(--nf-text);
font-size: 12px;
font-weight: 700;
text-anchor: middle;
}
.nf-compass-label-s {
fill: var(--nf-soft);
}
.nf-map-settings {
display: grid;
gap: 8px;
}
.nf-map-move {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 10px;
}
.nf-map-arrows {
display: flex;
gap: 6px;
}
.nf-compass-side {
display: grid;
gap: 6px;
flex: 1 1 200px;
}
.nf-actions {
display: flex;
flex-wrap: wrap;
gap: 6px;
}
.nf-floor-list .nf-chip {
box-shadow: none;
border: 1px solid var(--nf-line);
}
.nf-version-actions {
display: inline-flex;
gap: 8px;
white-space: nowrap;
}
.nf-diff {
margin: 2px 0 10px 8px;
padding-left: 8px;
border-left: 2px solid color-mix(in srgb, var(--nf-soft, #8a9bb8) 35%, transparent);
}
.nf-diff-list {
list-style: none;
margin: 0;
padding: 0;
font-size: 0.9em;
line-height: 1.5;
}
.nf-check-open {
width: 100%;
margin: 0 0 8px;
}
.nf-check-floor {
margin: 10px 0 4px;
font-size: 0.85em;
color: var(--nf-muted, #8d9bbd);
}
.nf-check-list {
list-style: none;
margin: 0;
padding: 0;
display: grid;
gap: 6px;
}
.nf-check-list li {
display: grid;
grid-template-columns: auto 1fr auto;
gap: 8px;
align-items: center;
padding: 6px 8px;
border-radius: 8px;
background: color-mix(in srgb, var(--nf-soft, #8a9bb8) 10%, transparent);
}
.nf-check-names {
grid-column: 1 / -1;
font-size: 0.85em;
}
.nf-check-names ul {
list-style: none;
margin: 6px 0;
padding: 0;
display: grid;
gap: 4px;
}
.nf-check-names li {
display: flex;
gap: 6px;
align-items: center;
padding: 2px 0;
background: none;
}
.nf-check-names li small {
flex: 1;
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
color: var(--nf-muted, #8d9bbd);
}
.nf-check-text {
font-size: 0.9em;
line-height: 1.3;
}
.nf-check-ok {
font-size: 1em;
}
.nf-studio-view {
display: block;
width: 100%;
max-height: 200px;
margin: 6px 0 10px;
background: color-mix(in srgb, var(--nf-soft, #8a9bb8) 10%, transparent);
border-radius: 8px;
}
.nf-studio-glow {
filter: drop-shadow(0 0 4px rgba(255, 214, 120, 0.8));
}
.nf-lib-studio {
width: 100%;
margin: 4px 0 8px;
}
.nf-form {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
margin-top: 10px;
}
.nf-wide {
grid-column: 1 / -1;
}
.nf-room-list {
display: grid;
gap: 2px;
}
.nf-row {
display: flex;
justify-content: space-between;
gap: 8px;
font: inherit;
color: var(--nf-text);
background: none;
border: none;
border-bottom: 1px solid var(--nf-line);
padding: 9px 2px;
cursor: pointer;
text-align: left;
}
.nf-row:hover {
color: var(--nf-accent);
}
.nf-check {
display: flex;
align-items: center;
gap: 8px;
font-size: 13px;
color: var(--nf-muted);
}
.nf-check input {
accent-color: var(--nf-accent);
}
.nf-meter rect {
fill: #2a2a10;
stroke: #ffc633;
stroke-width: 1.5;
}
.nf-meter path {
fill: #ffc633;
}
.nf-packages {
display: grid;
gap: 6px;
margin-top: 10px;
}
.nf-packages .nf-btn {
display: grid;
text-align: left;
gap: 2px;
}
.nf-packages .nf-btn span {
font-weight: 400;
font-size: 12px;
color: var(--nf-muted);
}
.nf-arrows {
display: grid;
grid-template-columns: repeat(3, 52px);
grid-template-areas: ". up ." "left . right" ". down .";
gap: 6px;
justify-content: center;
}
.nf-arrows .nf-btn {
font-size: 20px;
padding: 6px 0;
}
.nf-arrow-up {
grid-area: up;
}
.nf-arrow-left {
grid-area: left;
}
.nf-arrow-right {
grid-area: right;
}
.nf-arrow-down {
grid-area: down;
}
.nf-measure-list {
margin: 8px 0;
padding-left: 22px;
color: var(--nf-muted);
font-size: 13px;
font-variant-numeric: tabular-nums;
}
.nf-library {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(118px, 1fr));
gap: 6px;
margin-top: 8px;
}
.nf-library .nf-btn {
font-weight: 500;
font-size: 13px;
}
/* the library cards: a picture, the name, size and source, a star, and size chips for a model in several sizes */
.nf-cards {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(86px, 1fr));
gap: 8px;
margin-top: 8px;
}
.nf-card {
position: relative;
display: flex;
flex-direction: column;
border-radius: 14px;
background: var(--nf-chrome);
box-shadow: 0 0 0 1px var(--nf-line);
}
.nf-card-main {
display: flex;
flex-direction: column;
gap: 3px;
padding: 6px 6px 8px;
border: 0;
border-radius: 14px;
background: none;
color: var(--nf-text);
font: inherit;
text-align: left;
cursor: pointer;
}
.nf-card-main:hover,
.nf-card-main:focus-visible {
background: rgba(127, 127, 127, 0.1);
outline: none;
}
.nf-card-name {
font-size: 12px;
font-weight: 500;
line-height: 1.25;
overflow-wrap: anywhere;
hyphens: auto;
}
.nf-card-meta {
font-size: 11px;
color: var(--nf-muted);
line-height: 1.25;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.nf-card-star {
position: absolute;
top: 3px;
right: 3px;
width: 24px;
height: 24px;
border: 0;
border-radius: 50%;
background: rgba(0, 0, 0, 0.25);
color: var(--nf-muted);
font-size: 15px;
line-height: 1;
cursor: pointer;
}
.nf-card-star[aria-pressed="true"] {
color: var(--nf-warm, #ffb547);
}
.nf-card-sizes {
display: flex;
flex-wrap: wrap;
gap: 4px;
padding: 0 6px 8px;
}
.nf-size {
min-width: 34px;
padding: 3px 6px;
border: 1px solid var(--nf-line);
border-radius: 999px;
background: none;
color: var(--nf-muted);
font: inherit;
font-size: 11px;
font-variant-numeric: tabular-nums;
cursor: pointer;
}
.nf-size[aria-pressed="true"] {
border-color: var(--nf-accent);
color: var(--nf-accent);
}
.nf-lib-chips {
display: flex;
flex-wrap: wrap;
gap: 6px;
margin-top: 8px;
}
.nf-lib-chip {
min-height: 30px;
padding: 4px 10px;
font-size: 12px;
box-shadow: 0 0 0 1px var(--nf-line);
}
.nf-lib-chip[aria-pressed="true"] {
color: var(--nf-accent);
box-shadow: 0 0 0 1px var(--nf-accent);
}
.nf-lib-all {
width: 100%;
margin-top: 12px;
}
/* the background picture while it is edited: a dashed frame and a corner handle */
.nf-bg-frame {
fill: none;
stroke: var(--nf-accent);
stroke-width: 1.5;
stroke-dasharray: 6 4;
pointer-events: none;
}
.nf-bg-handle {
fill: var(--nf-accent);
stroke: #041018;
stroke-width: 2;
cursor: nwse-resize;
}
.nf-furn-body {
fill: color-mix(in srgb, var(--nf-soft) 10%, transparent);
stroke: color-mix(in srgb, var(--nf-soft) 55%, transparent);
stroke-width: 1.2;
vector-effect: non-scaling-stroke;
cursor: grab;
}
.nf-furn-sym * {
fill: none;
stroke: rgba(150, 175, 255, 0.55);
stroke-width: 1;
vector-effect: non-scaling-stroke;
pointer-events: none;
}
.nf-furn-sym .nf-sym-fill {
fill: color-mix(in srgb, var(--nf-soft) 28%, transparent);
}
.nf-furn-sym .nf-sym-dash {
stroke-dasharray: 6 4;
}
.nf-furn-sym .nf-sym-strong {
stroke: var(--nf-accent);
stroke-width: 2;
}
.nf-out polygon {
fill: color-mix(in srgb, var(--nf-soft) 6%, transparent);
stroke: color-mix(in srgb, var(--nf-soft) 40%, transparent);
stroke-width: 1;
stroke-dasharray: 4 3;
cursor: grab;
}
.nf-out-lawn polygon,
.nf-out-bed polygon,
.nf-out-wild polygon,
.nf-out-hedge polygon {
fill: rgba(61, 224, 160, 0.1);
stroke: rgba(61, 224, 160, 0.5);
}
.nf-out-pool polygon,
.nf-out-river polygon,
.nf-out-stream polygon {
fill: color-mix(in srgb, var(--nf-accent) 18%, transparent);
stroke: var(--nf-accent);
}
.nf-out-terrace polygon {
fill: rgba(150, 130, 255, 0.12);
}
.nf-out-street polygon {
fill: rgba(100, 110, 125, 0.28);
}
.nf-out-sidewalk polygon {
fill: rgba(175, 185, 200, 0.24);
}
.nf-out-gravel polygon {
fill: rgba(184, 163, 130, 0.24);
stroke: rgba(184, 163, 130, 0.65);
}
.nf-out-pavers polygon,
.nf-out-natural_stone polygon {
fill: rgba(170, 160, 135, 0.22);
stroke: rgba(170, 160, 135, 0.6);
}
.nf-out-stepping_stones polygon {
fill: rgba(130, 170, 110, 0.18);
stroke: rgba(160, 190, 140, 0.55);
}
.nf-free-wall {
cursor: grab;
}
.nf-vertex-no {
fill: var(--nf-accent);
font-size: 11px;
font-weight: 700;
pointer-events: none;
}
.nf-edge-box {
margin: 12px 0;
padding: 10px 12px;
border: 1px solid color-mix(in srgb, var(--nf-accent) 45%, transparent);
border-radius: 12px;
background: color-mix(in srgb, var(--nf-accent) 6%, transparent);
}
.nf-edge-box > summary {
cursor: pointer;
color: var(--nf-accent);
font-size: 13px;
font-weight: 700;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.nf-edge-box[open] > summary {
margin-bottom: 8px;
}
/* a wall row: name and length, the height, then the buttons (full height, no wall, cut) in one line;
a split point gets a line of its own below */
.nf-edge-height {
display: flex;
flex-wrap: wrap;
gap: 6px;
align-items: end;
padding: 4px 6px;
margin: 0 -6px;
border-radius: 8px;
}
.nf-edge-height > span:first-child {
flex: 1 1 84px;
min-width: 84px;
}
.nf-ble-bars {
display: grid;
gap: 6px;
margin: 10px 0;
}
.nf-ble-row {
display: grid;
grid-template-columns: minmax(80px, 1fr) 2fr 36px;
align-items: center;
gap: 8px;
font-size: 12px;
}
.nf-ble-name {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
color: var(--nf-text);
}
.nf-ble-track {
height: 8px;
border-radius: 4px;
background: rgba(127, 127, 127, 0.25);
overflow: hidden;
}
.nf-ble-fill {
display: block;
height: 100%;
border-radius: 4px;
background: var(--nf-accent, #00e5ff);
transition: width 0.4s ease-out;
}
.nf-ble-db {
text-align: right;
font-variant-numeric: tabular-nums;
color: var(--nf-muted);
}
.nf-ble-now {
margin: 4px 0 10px;
color: var(--nf-text);
}
.nf-ble-learn {
margin: 8px 0 14px;
padding: 10px 12px;
border: 1px solid var(--nf-border, rgba(127, 127, 127, 0.3));
border-radius: 10px;
}
.nf-chips {
display: flex;
flex-wrap: wrap;
gap: 6px;
}
.nf-chips .nf-chip {
display: inline-flex;
align-items: center;
gap: 4px;
cursor: default;
color: var(--nf-text);
}
.nf-chip-x {
border: 0;
background: none;
color: var(--nf-muted);
font: inherit;
font-size: 16px;
line-height: 1;
padding: 0 2px;
cursor: pointer;
}
.nf-quiet-time > span {
display: flex;
align-items: center;
gap: 6px;
}
.nf-quiet-time input {
flex: 1 1 0;
}
.nf-edge-height > .nf-field {
flex: 1 1 90px;
min-width: 0;
}
.nf-edge-height > .nf-muted {
flex: 1 1 90px;
align-self: center;
}
.nf-edge-height > .nf-btn {
flex: 0 0 auto;
white-space: nowrap;
padding-left: 10px;
padding-right: 10px;
}
.nf-edge-height > .nf-split-row {
flex: 1 1 100%;
display: flex;
gap: 6px;
align-items: end;
}
.nf-edge-height > .nf-split-row > .nf-field {
flex: 1;
}
.nf-edge-on {
background: color-mix(in srgb, var(--nf-accent) 14%, transparent);
}
.nf-edge-low b {
color: var(--nf-accent);
}
.nf-wall-low {
opacity: 0.55;
}
.nf-dev-source {
display: flex;
margin: 8px 0;
}
.nf-dev-source button {
flex: 1 1 0;
min-width: 0;
padding: 6px 4px;
font-size: 12px;
line-height: 1.2;
white-space: normal;
text-align: center;
border-radius: 10px;
}
.nf-place-all {
margin: 10px 0 0;
}
.nf-roof-sec polygon {
fill: color-mix(in srgb, #ffb547 10%, transparent);
stroke: #ffb547;
stroke-width: 2;
stroke-dasharray: 8 6;
cursor: move;
}
.nf-roof-sel polygon {
fill: color-mix(in srgb, var(--nf-accent) 14%, transparent);
stroke: var(--nf-accent);
stroke-dasharray: none;
}
/* solar modules: dark blue panes with a light frame, so they do not look like a selected room */
.nf-roofwin polygon {
fill: color-mix(in srgb, #2b6b8f 70%, transparent);
stroke: #e3e9f5;
stroke-width: 2;
cursor: move;
}
.nf-chimney polygon {
fill: color-mix(in srgb, #7a4a4a 75%, transparent);
stroke: #e3e9f5;
stroke-width: 2;
cursor: move;
}
.nf-roofwin-sel polygon {
stroke: #ffd75a;
}
.nf-tool-energy .nf-roof-layer {
opacity: 0.45;
}
.nf-tool-energy .nf-energy-item {
pointer-events: auto;
}
.nf-swatches {
display: flex;
flex-wrap: wrap;
gap: 8px;
padding-top: 4px;
}
.nf-stair-shapes {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 6px;
}
.nf-stair-shape {
display: flex;
flex-direction: column;
align-items: center;
gap: 2px;
padding: 6px 4px;
font-size: 11px;
line-height: 1.2;
text-align: center;
}
.nf-stair-shape[aria-checked="true"] {
border-color: var(--nf-accent);
color: var(--nf-accent);
box-shadow: 0 0 0 1px var(--nf-accent) inset;
}
.nf-swatch {
width: 30px;
height: 30px;
padding: 0;
border-radius: 50%;
border: 2px solid var(--nf-line);
background: var(--sw);
cursor: pointer;
}
.nf-swatch[aria-checked="true"] {
border-color: var(--nf-text);
outline: 2px solid var(--nf-accent);
outline-offset: 2px;
}
.nf-energy-marker {
cursor: move;
}
.nf-checklist .nf-chk {
display: flex;
align-items: center;
gap: 8px;
width: 100%;
margin: 2px 0;
padding: 6px 8px;
border: 0;
border-radius: 8px;
background: transparent;
color: inherit;
font: inherit;
text-align: left;
text-decoration: none;
cursor: pointer;
}
.nf-checklist .nf-chk:hover {
background: rgba(127, 127, 127, 0.12);
}
.nf-checklist .nf-chk span {
width: 18px;
text-align: center;
font-weight: 700;
}
.nf-chk-ok span {
color: #59ff8c;
}
.nf-chk-todo span {
color: #ffc633;
}
.nf-chk-opt {
opacity: 0.75;
}
.nf-teaser-on {
border-color: rgba(89, 255, 140, 0.5);
}
.nf-teaser {
margin-top: 12px;
padding: 12px;
border-radius: 14px;
border: 1px solid color-mix(in srgb, #ffd75a 45%, transparent);
background: linear-gradient(160deg, color-mix(in srgb, #ffd75a 10%, transparent), transparent 60%);
}
.nf-teaser-head {
display: flex;
justify-content: space-between;
align-items: center;
gap: 8px;
margin-bottom: 8px;
}
.nf-teaser-soon {
font-size: 11px;
font-weight: 700;
letter-spacing: 0.06em;
text-transform: uppercase;
color: var(--nf-chrome-solid);
background: #ffd75a;
border-radius: 999px;
padding: 2px 8px;
white-space: nowrap;
}
.nf-teaser img {
display: block;
width: 100%;
border-radius: 10px;
border: 1px solid color-mix(in srgb, var(--nf-accent) 40%, transparent);
}
.nf-teaser ul {
margin: 8px 0 4px;
padding-left: 18px;
font-size: 13px;
}
/* the roof and energy tools say what can be moved there (everything else is locked) */
.nf-tool-note {
position: absolute;
top: 8px;
left: 50%;
transform: translateX(-50%);
z-index: 2;
max-width: calc(100% - 24px);
padding: 5px 12px;
border-radius: 999px;
background: color-mix(in srgb, var(--nf-chrome-solid) 85%, transparent);
border: 1px solid color-mix(in srgb, #ffd75a 60%, transparent);
color: #ffe7a3;
font-size: 12px;
text-align: center;
pointer-events: none;
}
.nf-route line {
stroke: var(--nf-warm);
stroke-width: 2;
stroke-dasharray: 6 4;
opacity: 0.7;
}
.nf-route circle {
fill: var(--nf-warm);
opacity: 0.8;
}
.nf-route circle.nf-route-riser {
fill: none;
stroke: var(--nf-warm);
stroke-width: 2;
}
.nf-route-drawing line {
stroke: var(--nf-accent);
stroke-dasharray: none;
opacity: 1;
}
.nf-route-drawing circle {
fill: var(--nf-accent);
opacity: 1;
}
.nf-route-drawing circle.nf-route-riser {
fill: none;
stroke: var(--nf-accent);
}
.nf-route text {
fill: var(--nf-text);
font-size: 11px;
pointer-events: none;
}
.nf-routes {
pointer-events: none;
}
.nf-energy-marker circle {
fill: color-mix(in srgb, var(--nf-chrome-solid) 80%, transparent);
stroke: #ffd75a;
stroke-width: 2;
}
.nf-energy-marker-sel circle {
stroke: var(--nf-accent);
stroke-width: 3;
fill: color-mix(in srgb, var(--nf-accent) 25%, var(--nf-chrome-solid));
}
.nf-energy-marker text {
text-anchor: middle;
pointer-events: none;
}
.nf-energy-icon {
font-size: 17px;
}
.nf-energy-name {
font-size: 11px;
font-weight: 700;
fill: #ffd75a;
paint-order: stroke;
stroke: rgba(0, 0, 0, 0.65);
stroke-width: 3px;
}
.nf-solar polygon {
fill: color-mix(in srgb, #1b3a8f 75%, transparent);
stroke: #9fb8ff;
stroke-width: 1.5;
cursor: move;
}
.nf-solar-sel polygon {
fill: color-mix(in srgb, #1b3a8f 80%, transparent);
stroke: #ffd75a;
stroke-width: 2;
}
.nf-solar polygon.nf-solar-off {
fill: transparent;
stroke-dasharray: 4 4;
stroke-width: 1.5;
}
.nf-solar-pick polygon {
cursor: pointer;
}
.nf-roof-ridge line {
stroke: #ffb547;
stroke-width: 2.5;
pointer-events: none;
}
.nf-roof-sel .nf-roof-ridge line {
stroke: var(--nf-accent);
}
.nf-roof-sec text {
fill: #ffd28a;
font-size: 12px;
font-weight: 700;
text-anchor: middle;
paint-order: stroke;
stroke: rgba(0, 0, 0, 0.6);
stroke-width: 3px;
pointer-events: none;
}
.nf-tool-energy .nf-room,
.nf-tool-energy [data-furniture],
.nf-tool-energy [data-device],
.nf-tool-energy [data-opening],
.nf-tool-energy [data-free-wall],
.nf-tool-energy [data-outdoor],
.nf-tool-energy .nf-roof-layer,
.nf-tool-roof .nf-room,
.nf-tool-roof [data-furniture],
.nf-tool-roof [data-device],
.nf-tool-roof [data-opening],
.nf-tool-roof [data-free-wall],
.nf-tool-roof [data-outdoor] {
pointer-events: none;
}
.nf-dev-area {
margin: 10px 0 2px;
color: var(--nf-muted);
font-size: 12px;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.nf-h3row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
}
.nf-h3row h3 {
margin-bottom: 0;
}
.nf-fix {
min-height: 30px;
padding: 4px 10px;
font-size: 13px;
}
.nf-fix[aria-pressed="true"] {
border-color: var(--nf-accent);
color: var(--nf-accent);
}
.nf-lock {
font-size: 13px;
text-anchor: middle;
pointer-events: none;
}
.nf-hint-fixed {
color: var(--nf-accent);
}
.nf-ctx {
position: absolute;
z-index: 5;
display: flex;
flex-direction: column;
min-width: 170px;
padding: 4px;
border: 1px solid var(--nf-line);
border-radius: 10px;
background: var(--nf-panel, #111a2e);
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}
.nf-ctx button {
padding: 8px 12px;
border: none;
border-radius: 7px;
background: none;
color: inherit;
font: inherit;
text-align: left;
cursor: pointer;
}
.nf-ctx button:hover:not(:disabled) {
background: color-mix(in srgb, var(--nf-accent) 16%, transparent);
}
.nf-ctx button:disabled {
opacity: 0.45;
cursor: default;
}
.nf-ctx-danger {
color: var(--nf-danger, #ff6b7a) !important;
}
.nf-edge-hi {
stroke: var(--nf-accent);
stroke-width: 6;
stroke-linecap: round;
filter: drop-shadow(0 0 6px var(--nf-accent));
}
.nf-free-wall .nf-hit {
stroke: transparent;
stroke-width: 18;
}
.nf-free-wall-line {
stroke: transparent;
stroke-width: 1;
}
.nf-free-wall-sel .nf-free-wall-line {
stroke: var(--nf-accent);
stroke-width: 2;
stroke-dasharray: 6 4;
}
.nf-draft-wall {
stroke-width: 4;
}
.nf-open-passage {
stroke-dasharray: 4 4;
}
.nf-out-sel polygon {
stroke: var(--nf-accent);
stroke-width: 2;
stroke-dasharray: none;
}
.nf-out text {
fill: var(--nf-muted);
font-size: 11px;
text-anchor: middle;
pointer-events: none;
}
.nf-furn-lit .nf-furn-body {
fill: rgba(255, 181, 71, 0.35);
stroke: var(--nf-warm);
}
.nf-rotate {
cursor: grab;
}
.nf-preview {
position: fixed;
z-index: 20;
width: 180px;
padding: 8px 8px 10px;
border-radius: 16px;
background: var(--nf-bg2);
box-shadow: var(--nf-shadow), 0 0 0 1px var(--nf-line);
text-align: center;
pointer-events: none;
animation: nf-pop 120ms ease-out;
}
@keyframes nf-pop {
from {
opacity: 0;
transform: translateX(8px);
}
}
.nf-preview img,
.nf-preview-wait {
display: block;
width: 164px;
height: 164px;
}
.nf-preview-wait {
margin: 0 auto;
border-radius: 12px;
background: rgba(127, 127, 127, 0.1);
}
.nf-preview b {
display: block;
margin-top: 2px;
font-size: 13px;
color: #e8eeff;
}
.nf-lib-badge {
margin-left: 4px;
color: var(--nf-accent);
vertical-align: -2px;
}
.nf-pin {
border: 0;
background: none;
padding: 2px 6px;
font-size: 17px;
line-height: 1;
color: var(--nf-muted);
cursor: pointer;
}
.nf-pin-on {
color: var(--nf-warm);
}
.nf-back {
margin-bottom: 12px;
}
.nf-presets {
display: flex;
flex-wrap: wrap;
gap: 6px;
margin-bottom: 10px;
}
.nf-resize {
cursor: nwse-resize;
}
.nf-resize rect {
fill: var(--nf-accent);
stroke: var(--nf-chrome-solid);
stroke-width: 1.5;
}
.nf-code {
display: block;
font: 12px/1.4 ui-monospace, Menlo, Consolas, monospace;
padding: 6px 8px;
border-radius: 8px;
background: rgba(127, 127, 127, 0.12);
user-select: all;
word-break: break-all;
}
.nf-shift {
display: flex;
align-items: center;
gap: 6px;
flex-wrap: wrap;
}
.nf-shift input {
width: 5.5em;
}
.nf-headroom {
stroke: rgba(255, 214, 90, 0.55);
stroke-width: 1;
stroke-dasharray: 6 4;
pointer-events: none;
}
.nf-headroom-label {
font-size: 10px;
fill: rgba(255, 214, 90, 0.75);
text-anchor: middle;
pointer-events: none;
}
.nf-split-mark {
stroke: color-mix(in srgb, var(--nf-accent) 90%, transparent);
stroke-width: 2;
pointer-events: none;
}
.nf-floor-menu {
display: flex;
flex-direction: column;
gap: 6px;
margin: 8px 0;
padding: 10px;
border-radius: 12px;
background: rgba(127, 127, 127, 0.1);
max-width: 100%;
box-sizing: border-box;
}
.nf-icon-row {
display: flex;
align-items: center;
gap: 8px;
}
.nf-icon-row input {
flex: 1;
min-width: 0;
}
.nf-icon-row ha-icon {
--mdc-icon-size: 22px;
color: var(--nf-accent);
}
.nf-floor-menu .nf-btn {
text-align: left;
width: 100%;
min-width: 0;
white-space: normal;
overflow-wrap: anywhere;
}
.nf-rotate line {
stroke: var(--nf-accent);
stroke-dasharray: 3 3;
}
.nf-rotate circle:not(.nf-hit) {
fill: var(--nf-chrome-solid);
stroke: var(--nf-accent);
stroke-width: 2;
}
.nf-rotate path {
fill: none;
stroke: var(--nf-accent);
stroke-width: 1.5;
stroke-linecap: round;
}
.nf-lib-toggle {
display: flex;
align-items: center;
gap: 6px;
width: 100%;
padding: 6px 0;
border: 0;
background: none;
font: inherit;
cursor: pointer;
text-align: left;
}
.nf-lib-toggle:hover {
color: var(--nf-text);
}
.nf-lib-caret {
width: 12px;
color: var(--nf-accent);
}
.nf-lib-count {
margin-left: auto;
font-weight: 500;
letter-spacing: 0;
text-transform: none;
opacity: 0.7;
}
.nf-lib-head {
margin: 10px 0 0;
font-size: 11px;
font-weight: 600;
letter-spacing: 0.05em;
text-transform: uppercase;
color: var(--nf-muted);
}
.nf-furn-front {
stroke: var(--nf-accent);
stroke-width: 2.5;
vector-effect: non-scaling-stroke;
opacity: 0.8;
pointer-events: none;
}
.nf-furn text {
fill: var(--nf-muted);
font-size: 11px;
text-anchor: middle;
pointer-events: none;
}
.nf-furn-sel .nf-furn-body {
fill: color-mix(in srgb, var(--nf-accent) 16%, transparent);
stroke: var(--nf-accent);
stroke-width: 2;
}
.nf-open {
cursor: grab;
}
.nf-open-gap {
fill: var(--nf-chrome-solid);
stroke: none;
}
.nf-open path,
.nf-open line {
fill: none;
stroke-width: 1.6;
stroke-linecap: round;
}
.nf-open-door path {
stroke: var(--nf-warm);
stroke-dasharray: 3 3;
}
.nf-open-front path,
.nf-open-door line {
stroke: var(--nf-warm);
stroke-width: 3;
stroke-dasharray: none;
}
.nf-open-door line.nf-open-pane {
stroke: var(--nf-accent);
stroke-width: 2;
}
.nf-open-garage line {
stroke: var(--nf-warm);
stroke-width: 3;
}
.nf-open-track {
stroke: var(--nf-warm);
stroke-dasharray: 4 4;
opacity: 0.6;
}
.nf-open-window line {
stroke: var(--nf-accent);
stroke-width: 2;
}
.nf-open-sel .nf-open-gap {
fill: color-mix(in srgb, var(--nf-accent) 25%, transparent);
}
.nf-open-sel path,
.nf-open-sel line {
stroke-width: 2.4;
}
.nf-bg-rotate {
cursor: grab;
}
.nf-bg-ruler line {
stroke: #ffb020;
stroke-width: 2.5;
stroke-dasharray: 6 4;
}
.nf-bg-ruler circle {
fill: #ffb020;
stroke: #1a1000;
stroke-width: 1.5;
}
.nf-own-button {
padding: 10px 0;
border-top: 1px solid var(--nf-line);
}
.nf-own-button textarea {
font: 12px/1.4 ui-monospace, monospace;
width: 100%;
box-sizing: border-box;
padding: 6px 8px;
color: var(--nf-text);
background: color-mix(in srgb, var(--nf-text) 4%, transparent);
border: 1px solid var(--nf-line);
border-radius: 8px;
}
.nf-search {
position: sticky;
top: 0;
z-index: 2;
background-color: var(--nf-panel, #0d1424);
width: 100%;
box-sizing: border-box;
font: inherit;
font-size: 14px;
color: var(--nf-text);
background: color-mix(in srgb, var(--nf-text) 4%, transparent);
border: 1px solid var(--nf-line);
border-radius: 8px;
padding: 7px 9px;
margin: 2px 0 6px;
}
.nf-more {
font: inherit;
font-size: 12px;
color: var(--nf-muted);
background: none;
border: none;
text-align: left;
padding: 2px 26px 8px;
cursor: pointer;
}
.nf-more:hover {
color: var(--nf-accent);
}
.nf-dev-hidden .nf-dev-name {
opacity: 0.45;
text-decoration: line-through;
}
.nf-dev-extra {
padding-left: 18px;
font-size: 13px;
}
.nf-dev-title {
display: flex;
align-items: center;
gap: 8px;
margin: 0 0 8px;
font-weight: 600;
}
.nf-notice {
color: var(--nf-accent);
}
.nf-device-sel circle:not(.nf-hit) {
stroke: var(--nf-accent);
stroke-width: 3;
}
.nf-dev-row {
align-items: center;
cursor: default;
}
.nf-dev-row:hover {
color: var(--nf-text);
}
.nf-dev-name {
display: inline-flex;
align-items: center;
gap: 8px;
min-width: 0;
font: inherit;
color: inherit;
background: none;
border: none;
padding: 0;
text-align: left;
cursor: pointer;
}
.nf-dev-name:disabled {
cursor: default;
}
.nf-dev-name span {
overflow: hidden;
text-overflow: ellipsis;
}
.nf-dev-name svg {
flex: none;
}
.nf-color-row {
display: flex;
align-items: center;
gap: 8px;
}
.nf-color-row input[type="color"] {
width: 48px;
height: 32px;
padding: 0;
border: none;
background: none;
}
.nf-link {
font: inherit;
font-size: 13px;
font-weight: 600;
color: var(--nf-accent);
background: none;
border: none;
padding: 4px 2px;
cursor: pointer;
white-space: nowrap;
}
.nf-wide-btn {
width: 100%;
margin-bottom: 6px;
}
.nf-device {
cursor: grab;
}
.nf-wedge path,
.nf-wedge circle:not(.nf-hit) {
fill: color-mix(in srgb, var(--nf-accent) 12%, transparent);
stroke: color-mix(in srgb, var(--nf-accent) 45%, transparent);
stroke-width: 1;
pointer-events: none;
}
.nf-wedge-sel path,
.nf-wedge-sel > circle {
fill: color-mix(in srgb, var(--nf-accent) 20%, transparent);
stroke: var(--nf-accent);
}
.nf-wedge .nf-rotate circle {
pointer-events: auto;
}
.nf-device circle:not(.nf-hit) {
fill: #111a2e;
stroke: var(--nf-soft);
stroke-width: 1.5;
vector-effect: non-scaling-stroke;
}
.nf-device path {
fill: none;
stroke: var(--nf-text);
stroke-width: 2.6;
stroke-linecap: round;
stroke-linejoin: round;
}
.nf-device-on circle:not(.nf-hit) {
fill: var(--nf-warm);
stroke: var(--nf-warm);
}
.nf-device-on path {
stroke: #2a1a00;
}
.nf-device-icon {
pointer-events: none;
overflow: visible;
}
.nf-device-icon ha-icon {
display: block;
--mdc-icon-size: 16px;
color: var(--nf-text);
}
.nf-device-on .nf-device-icon ha-icon {
color: #2a1a00;
}
.nf-dev-icon {
--mdc-icon-size: 18px;
flex: none;
}
.nf-muted {
color: var(--nf-muted);
font-variant-numeric: tabular-nums;
}
.nf-points {
margin: 12px 0;
}
.nf-point {
display: grid;
grid-template-columns: 18px 1fr 1fr auto;
gap: 6px;
align-items: end;
padding: 4px 0;
}
.nf-point-sel .nf-muted {
color: var(--nf-accent);
}
.nf-point .nf-btn {
min-height: 34px;
padding: 4px 10px;
}
.nf-upload {
position: relative;
text-align: center;
overflow: hidden;
}
.nf-upload input {
position: absolute;
inset: 0;
opacity: 0;
cursor: pointer;
}
.nf-sub {
margin: 8px 0 0;
font-size: 12.5px;
color: var(--nf-muted);
}
.nf-note {
margin: 0;
font-size: 12.5px;
color: var(--nf-warm);
}
.nf-hydronic-form>details { border:1px solid var(--nf-line); border-radius:10px; padding:10px; margin:8px 0; }
.nf-hydronic-form summary { cursor:pointer; font-weight:500; }
.nf-hydronic-form details[open]>.nf-form { margin-top:9px; }
.nf-hydronic-control { border-top:1px solid var(--nf-line); padding-top:7px; }
`;var Z_=["cabinet","shelf","lamp","device"],En="own_studio";var Nk={cabinet:{w:120,d:45,h:80,doors:2,drawers:1,shelves:2,base:"plinth",handle:"bar",back:!0,lamp:"floor",display:!1,mount:"floor",body:"white",front:"wood"},shelf:{w:80,d:35,h:180,doors:0,drawers:0,shelves:4,base:"none",handle:"none",back:!0,lamp:"floor",display:!1,mount:"floor",body:"wood",front:"wood"},lamp:{w:40,d:40,h:160,doors:0,drawers:0,shelves:0,base:"none",handle:"none",back:!1,lamp:"floor",display:!1,mount:"floor",body:"metal",front:"white"},device:{w:60,d:60,h:85,doors:0,drawers:0,shelves:0,base:"none",handle:"none",back:!1,lamp:"floor",display:!0,mount:"floor",body:"white",front:"dark"}},Rc=(t,e)=>({kind:t,name:e,...Nk[t]}),q_=(t,e)=>({...Rc(e,t.name),body:t.body,front:t.front}),br=(t,e,n)=>Math.min(n,Math.max(e,Number.isFinite(t)?t:e)),yr=t=>Math.round(t*1e4)/1e4;function Ac(t){return{...t,name:t.name.trim().slice(0,60),w:br(Math.round(t.w),5,400),d:br(Math.round(t.d),2,200),h:br(Math.round(t.h),2,300),doors:br(Math.round(t.doors),0,6),drawers:br(Math.round(t.drawers),0,6),shelves:br(Math.round(t.shelves),0,12)}}function ce(t,e,n,r,i,o,s,a,l={}){let[c,d,u]=t,p=(k,x,M)=>{let A=Math.max(-M,k-x/2),T=Math.min(M,k+x/2);return T-A<1e-4?[Math.max(-M,Math.min(M,k)),.001*M*2]:[(A+T)/2,T-A]},[h,f]=p(e,r,c/2),[g,b]=p(n,i,d/2),y=Math.max(0,Math.min(u*.999,o)),v=Math.max(u*.001,Math.min(u-y,s)),w=k=>yr(Math.max(.001,Math.min(1,k)));return{shape:"box",x:yr(h/c),z:yr(g/d),w:w(f/c),d:w(b/d),y:yr(y/u),h:w(v/u),color:a,...l}}function Y_(t,e,n){let[r,i,o]=t;if(e==="legs"){let s=Math.min(.1,o*.25),a=Math.min(.04,r/6,i/6);for(let[l,c]of[[-1,-1],[1,-1],[-1,1],[1,1]])n.push(ce(t,l*(r/2-a),c*(i/2-a),a,a,0,s,"metal"));return s}if(e==="plinth"){let s=Math.min(.08,o*.2);return n.push(ce(t,0,-.02,r-.02,i-.04,0,s,"dark")),s}return 0}function Bk(t,e){let[n,r,i]=e,o=[],s=Y_(e,t.base,o),a=t.doors+t.drawers>0,l=t.handle==="none"||!a?0:Math.min(.025,r*.08),c=a?Math.min(.02,r*.1):0,d=r-c-l,u=-r/2+d/2,p=i-s;if(!a){let v=Math.min(.018,n/10,p/10);o.push(ce(e,-n/2+v/2,0,v,r,s,p,t.body,{edges:!0})),o.push(ce(e,n/2-v/2,0,v,r,s,p,t.body,{edges:!0})),o.push(ce(e,0,-r/2+.005,n-2*v,.01,s,p,t.body));for(let w=0;w<=t.shelves+1;w++)o.push(ce(e,0,.005,n-2*v,r-.01,s+(p-v)*w/(t.shelves+1),v,t.front,{edges:"faint"}));return o}o.push(ce(e,0,u,n,d,s,p,t.body,{edges:!0}));let h=.004,f=-r/2+d+c/2,g=t.doors>0?Math.min(.18,Math.max(.08,(p-.3)/Math.max(1,t.drawers))):p/t.drawers,b=s+(t.drawers>0?g*t.drawers:0),y=(v,w,k)=>{if(t.handle==="none")return;let x=r/2-l/2;t.handle==="knob"?o.push(ce(e,v,x,.025,l,w-.0125,.025,"metal")):k?o.push(ce(e,v,x,.015,l,w-.08,.16,"metal")):o.push(ce(e,v,x,Math.min(.16,n*.4),l,w-.0075,.015,"metal"))};for(let v=0;v<t.drawers;v++){let w=s+g*v;o.push(ce(e,0,f,n-2*h,c,w+h,g-2*h,t.front,{edges:"faint"})),y(0,w+g*(t.drawers===1&&t.doors===0?.5:.7),!1)}if(t.doors>0){let v=n/t.doors,w=i-b;for(let k=0;k<t.doors;k++){let x=-n/2+v*(k+.5);o.push(ce(e,x,f,v-2*h,c,b+h,w-2*h,t.front,{edges:"faint"}));let M=t.doors===1||k%2===0?1:-1,A=b+w*(i>1.2?.45:.8);y(x+M*(v/2-.04),Math.min(A,i-.1),!0)}}return o}function Vk(t,e){let[n,r,i]=e,o=Math.min(.02,n/10,i/10),s=[ce(e,-n/2+o/2,0,o,r,0,i,t.body,{edges:!0}),ce(e,n/2-o/2,0,o,r,0,i,t.body,{edges:!0})];t.back&&s.push(ce(e,0,-r/2+.005,n-2*o,.01,0,i,t.body));let a=t.shelves+2;for(let l=0;l<a;l++)s.push(ce(e,0,t.back?.005:0,n-2*o,t.back?r-.01:r,(i-o)*l/(a-1),o,t.front,{edges:!0}));return s}function Wk(t,e){let[n,r,i]=e,o=Math.min(n,r),s=(l,c,d,u,p,h,f={})=>({...ce(e,l,c,d,d,u,p,h,f),shape:"cyl"}),a=(l,c,d)=>({...ce(e,0,0,o,o,l,c,t.front,{glow:!0,edges:"faint"}),shape:"loft",tw:yr(Math.min(1,o*d/n)),td:yr(Math.min(1,o*d/r))});switch(t.lamp){case"pendant":{let l=Math.min(.3,i*.4);return[s(0,0,Math.min(.12,o),i-.03,.03,t.body),s(0,0,Math.min(.01,o/4),l,i-l-.03,"dark"),a(0,l,.35)]}case"wall":{let l=Math.min(.02,r*.2);return[ce(e,0,-r/2+l/2,Math.min(.1,n),l,i*.3,i*.4,t.body),ce(e,0,0,Math.min(.02,n),r-l,i*.45,Math.min(.02,i*.1),t.body),a(i*.15,i*.7,.7)]}default:{let l=Math.min(t.lamp==="table"?.25:.35,i*.4);return[s(0,0,o*.6,0,Math.min(.03,i*.05),t.body,{edges:!0}),s(0,0,Math.min(.03,o/6),.02,i-l-.02,t.body),a(i-l,l,.7)]}}}function Kk(t,e){let[n,r,i]=e,o=[],s=t.mount==="floor"?Y_(e,t.base,o):0,a=t.display?Math.min(.01,r*.1):0;if(o.push(ce(e,0,-a/2,n,r-a,s,i-s,t.body,{edges:!0})),t.display){let l=Math.min(.02,n*.08,(i-s)*.08);o.push(ce(e,0,r/2-a/2,n-2*l,a,s+l,i-s-2*l,t.front,{screen:!0}))}return o}function Es(t,e,n){let r=Ac(t),i=[r.w/100,r.d/100,r.h/100],o=r.name||e,s=n==="en"?{en:o}:{[n.slice(0,5)]:o,en:o},a={id:e,name:s,size:i,parts:[],recipe:r};switch(r.kind){case"cabinet":a.parts=Bk(r,i),a.surface=!0;break;case"shelf":a.parts=Vk(r,i);break;case"lamp":a.parts=Wk(r,i),a.light=r.lamp,a.mount=r.lamp==="pendant"?"ceiling":r.lamp==="wall"?"wall":r.lamp==="table"?"surface":"floor",r.lamp==="wall"&&(a.wall_y=1.6);break;case"device":a.parts=Kk(r,i),a.electric=!0,a.mount=r.mount,r.mount==="wall"&&(a.wall_y=1.2);break}return a}function X_(t,e){let n=t.toLowerCase().normalize("NFKD").replace(/[̀-ͯ]/g,"").replace(/ß/g,"ss").replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,"").slice(0,32)||"piece",r=/^[a-z0-9]/.test(n)?n:`p${n}`;if(!e.includes(r))return r;for(let i=2;;i++)if(!e.includes(`${r}_${i}`))return`${r}_${i}`}var J_=["white","wood","body","metal","dark","glass","accent"],jk={white:"#dfe6f2",wood:"#8a6a4a",body:"#3a4a6a",metal:"#9aa7bf",dark:"#1e2638",glass:"#7fd0e8",accent:"#37e0ff",fabric:"#4b5d8c",cushion:"#6a7fb3"},eb=t=>jk[t]??t;function Gk(t){let e=Es(t,"preview","en"),[n,,r]=e.size,i=180/Math.max(n,r),[o,s]=[n*i,r*i],a=[...e.parts].sort((l,c)=>l.z+l.d/2-(c.z+c.d/2));return m`<svg class="nf-studio-view" viewBox="-4 -4 ${o+8} ${s+8}" role="img" aria-hidden="true">
${a.map(l=>{let c=l.w*o,d=l.h*s,u=(l.x+.5)*o-c/2,p=s-(l.y+l.h)*s,h=l.shape==="cyl"?Math.min(c,d)/2:l.shape==="loft"?3:1;return E`<rect x=${u} y=${p} width=${Math.max(.6,c)} height=${Math.max(.6,d)} rx=${h} fill=${l.screen?"#0b1020":eb(l.color)} stroke="rgba(10,16,32,0.55)" stroke-width="0.8" class=${l.glow?"nf-studio-glow":""} />`})}
</svg>`}function Q_(t,e,n,r){let i=t.t,o=!J_.includes(n),s=[...J_.map(a=>[a,i(a==="body"?"studio_color_plan":`studio_color_${a}`)]),["own",i("studio_color_own")]];return m`${H(t,e,o?"own":n,s,a=>r(a==="own"?eb(n):a))}
${o?Ge(t,i("studio_color_own"),n,"#8a6a4a",a=>r(a??"wood")):_}`}function tb(t,e,n){let r=t.t,i=e.recipe,o=c=>n.change(Ac({...i,...c})),s=(c,d,u)=>R(t,r(c),d,p=>o({[u]:p}),1,1),a=(c,d,u)=>R(t,r(c),d,p=>o({[u]:p}),1,0),l=()=>{switch(i.kind){case"cabinet":return m`${a("studio_doors",i.doors,"doors")} ${a("studio_drawers",i.drawers,"drawers")}
${i.doors+i.drawers===0?a("studio_shelves",i.shelves,"shelves"):_}
${H(t,r("studio_handle"),i.handle,[["bar",r("studio_handle_bar")],["knob",r("studio_handle_knob")],["none",r("studio_handle_none")]],c=>o({handle:c}))}
${H(t,r("studio_base"),i.base,[["plinth",r("studio_base_plinth")],["legs",r("studio_base_legs")],["none",r("studio_base_none")]],c=>o({base:c}))}`;case"shelf":return m`${a("studio_shelves",i.shelves,"shelves")} ${D(t,r("studio_back"),i.back,c=>o({back:c}))}`;case"lamp":return H(t,r("studio_lamp"),i.lamp,[["floor",r("studio_lamp_floor")],["table",r("studio_lamp_table")],["pendant",r("studio_lamp_pendant")],["wall",r("studio_lamp_wall")]],c=>o({lamp:c}));case"device":return m`${D(t,r("studio_display"),i.display,c=>o({display:c}))}
${H(t,r("studio_mount"),i.mount,[["floor",r("studio_mount_floor")],["surface",r("studio_mount_surface")],["wall",r("studio_mount_wall")]],c=>o({mount:c}))}
${i.mount==="floor"?H(t,r("studio_base"),i.base,[["none",r("studio_base_none")],["legs",r("studio_base_legs")],["plinth",r("studio_base_plinth")]],c=>o({base:c})):_}`}};return m`<section class="nf-studio">
<h3>🛠️ ${r(e.itemId?"studio_title_edit":"studio_title")}</h3>
${S(r("studio_hint"))}
<div class="nf-lib-chips" role="group" aria-label=${r("studio_kind")}>
${Z_.map(c=>m`<button class="nf-chip" aria-pressed=${i.kind===c} ?disabled=${!!e.itemId&&i.kind!==c} @click=${()=>i.kind!==c&&n.change(q_(i,c))}>${r(`studio_kind_${c}`)}</button>`)}
</div>
${Gk(i)}
<div class="nf-form">
${W(t,r("studio_name"),i.name,c=>o({name:c}),{wide:!0,maxlength:60,placeholder:r(`studio_kind_${i.kind}`)})}
${s("studio_width",i.w,"w")} ${s("studio_depth",i.d,"d")} ${s("studio_height",i.h,"h")} ${l()}
${Q_(t,r(i.kind==="lamp"?"studio_color_lamp_body":"studio_color_body"),i.body,c=>o({body:c}))}
${i.kind==="cabinet"||i.kind==="shelf"||i.kind==="lamp"||i.display?Q_(t,r(i.kind==="lamp"?"studio_color_shade":i.kind==="device"?"studio_color_display":i.kind==="shelf"?"studio_color_boards":"studio_color_front"),i.front,c=>o({front:c})):_}
</div>
${e.error?m`<p class="nf-sub nf-warn">${e.error}</p>`:_}
${Q(m`<button class="nf-btn nf-primary" ?disabled=${e.busy||!t.admin} @click=${()=>n.save()}>${r(e.itemId?"studio_save":"studio_place")}</button>`,m`<button class="nf-btn" ?disabled=${e.busy} @click=${()=>n.close()}>${r("cancel")}</button>`)}
</section>`}var Uk={room_no_area:"\u{1F3F7}\uFE0F",areas_unplaced:"\u2795",devices_unplaced:"\u{1F4CD}",rooms_overlap:"\u29C9",opening_off_wall:"\u{1F6AA}",entity_missing:"\u2753",furniture_entity_missing:"\u2753",standby:"\u{1F50C}",battery_low:"\u{1FAAB}"};function Zk(t,e){let n=e.kind==="room_no_area"&&e.vars.area?"check_room_no_area_named":`check_${e.kind}`;return t.t(n,e.vars)}function qk(t,e){let n=t.t;switch(e.fix.do){case"set_area":return n("check_fix_set_area",{area:String(e.vars.area)});case"add_area_rooms":return n("check_fix_add_rooms");case"place_devices":return n("check_fix_place",{n:e.fix.entityIds.length});case"ignore_devices":return n("check_fix_ignore");case"remove_placements":return n("check_fix_remove",{n:e.fix.entityIds.length});default:return n("check_fix_show")}}function nb(t,e,n){let r=t.t,i=t.doc.floors.filter(o=>e.some(s=>s.floorId===o.id));return m`<section class="nf-check-panel">
<div class="nf-h3row"><h3>✓ ${r("check_title")}</h3><button class="nf-btn nf-field-btn" title=${r("close")} @click=${()=>n.close()}>✕</button></div>
${e.length===0?m`<p class="nf-sub nf-check-ok">✅ ${r("check_all_good")}</p>`:m`${S(r("check_hint",{n:e.length}))}
${i.map(o=>m`<h4 class="nf-check-floor">${o.name}</h4>
<ul class="nf-check-list">
${e.filter(s=>s.floorId===o.id).map(s=>m`<li>
<span class="nf-check-icon" aria-hidden="true">${Uk[s.kind]}</span><span class="nf-check-text">${Zk(t,s)}</span>
<button class="nf-btn ${s.changes?"nf-primary":""}" ?disabled=${s.changes&&!t.admin} @click=${()=>n.fix(s)}>${qk(t,s)}</button>
${s.entityIds?Yk(t,s.entityIds,n):_}
</li>`)}
</ul>`)}`}
${(t.doc.settings.check_ignore??[]).length>0?m`<p class="nf-sub"><button class="nf-btn" ?disabled=${!t.admin} @click=${()=>n.resetIgnored()}>${r("check_reset_ignored",{n:t.doc.settings.check_ignore.length})}</button></p>`:_}
</section>`}function Yk(t,e,n){let r=t.t;return m`<details class="nf-check-names">
<summary>${r("check_show_devices",{n:e.length})}</summary>
<ul>
${e.map(i=>m`<li><span title=${i}>${t.hass?B(t.hass,i):i}</span> <small>${i}</small>
<button class="nf-btn" ?disabled=${!t.admin} @click=${()=>n.ignore([i])}>${r("check_fix_ignore")}</button></li>`)}
</ul>
<button class="nf-btn" ?disabled=${!t.admin} @click=${()=>n.ignore(e)}>${r("check_ignore_all",{n:e.length})}</button>
</details>`}var rb=(t,e)=>m`<button class="nf-btn nf-check-open" title=${t.t("check_open_hint")} @click=${e}>✓ ${t.t("check_open")}</button>`;function ib(t,e){if(!e||!Number.isFinite(e.value))return null;let n=/^\s*([^/\s]+)\s*\/\s*kWh\s*$/i.exec(e.unit);if(!n)return null;let r=/^(ct|cent|cents|c)$/i.test(n[1]),i=r||/^eur$/i.test(n[1])?"\u20AC":n[1];return{value:Math.round(t*e.value*(r?1:100))/100,currency:i}}var sb=20,ob=new WeakMap;function Xk(t){let e=t.entities??{},n=ob.get(e);if(!n){n=new Map;for(let[r,i]of Object.entries(e))i.device_id&&r.startsWith("sensor.")&&t.states[r]?.attributes.device_class==="battery"&&!n.has(i.device_id)&&n.set(i.device_id,r);ob.set(e,n)}return n}function Jk(t,e){let n=t.entities?.[e]?.device_id,r=n?Xk(t).get(n):void 0;if(r){let s=Number(t.states[r]?.state);if(Number.isFinite(s))return s}let i=t.states[e]?.attributes;if(!i||i.battery_level===void 0&&i.battery===void 0)return null;let o=Number(i.battery_level??i.battery);return Number.isFinite(o)?o:null}function Qk(t){let e=[],n=r=>typeof r=="string"&&/^[a-z_]+\.[a-z0-9_]+$/.test(r);for(let r of t.placements)e.push({entity:r.entity_id,x:r.x,z:r.z,room:null});for(let r of t.furniture)for(let i of[r.entity,r.power])n(i)&&e.push({entity:i,x:r.x,z:r.z,room:null});for(let r of t.openings)for(let i of[r.contact,r.contact2,r.tilt,r.tilt2,r.cover,r.cover2,r.lock])n(i)&&e.push({entity:i,x:NaN,z:NaN,room:r.room_id});return e}var e1=(t,e,n)=>t.rooms.find(r=>r.points.length>=3&&C([e,n],r.points));function ab(t,e){let n=new Set,r=[];for(let i of e.floors)for(let o of Qk(i)){let s=t.entities?.[o.entity]?.device_id??o.entity;if(n.has(s))continue;let a=Jk(t,o.entity);a!==null&&(n.add(s),r.push({entity:o.entity,level:a,floorId:i.id,roomId:o.room??e1(i,o.x,o.z)?.id??null}))}return r.sort((i,o)=>i.level-o.level)}var vr=.08;function lb(t,e){let n=1/0;for(let r=0;r<e.length;r++){let i=e[r],o=e[(r+1)%e.length],[s,a]=[o[0]-i[0],o[1]-i[1]],l=s*s+a*a,c=l>0?Math.max(0,Math.min(1,((t[0]-i[0])*s+(t[1]-i[1])*a)/l)):0;n=Math.min(n,Math.hypot(t[0]-(i[0]+s*c),t[1]-(i[1]+a*c)))}return n}var cb=t=>({x0:Math.min(...t.map(e=>e[0])),x1:Math.max(...t.map(e=>e[0])),z0:Math.min(...t.map(e=>e[1])),z1:Math.max(...t.map(e=>e[1]))});function t1(t,e,n=.2){if(t.points.length<3||e.points.length<3)return!1;let[r,i]=[cb(t.points),cb(e.points)],o=Math.max(r.x0,i.x0)+vr,s=Math.min(r.x1,i.x1)-vr,a=Math.max(r.z0,i.z0)+vr,l=Math.min(r.z1,i.z1)-vr;if(s<=o||l<=a)return!1;for(let c=o;c<=s+1e-9;c+=Math.min(n,s-o||n))for(let d=a;d<=l+1e-9;d+=Math.min(n,l-a||n)){let u=[c,d];if(C(u,t.points)&&C(u,e.points)&&lb(u,t.points)>vr&&lb(u,e.points)>vr)return!0}return!1}function ub(t){let e=new Set(["id","type","variant","name","icon","picture","vehicle","room_id","wall"]),n=r=>typeof r=="string"&&/^[a-z_]+\.[a-z0-9_]+$/.test(r);return Object.entries(t).flatMap(([r,i])=>e.has(r)?[]:Array.isArray(i)?i.filter(n):n(i)?[i]:[])}var db=t=>ub(t),n1=3,r1=new Set(["off","standby","idle"]);function i1(t,e,n,r){let i=e.energy.tariff,o=i?t.states[i]:void 0,s=o?{value:Number(o.state),unit:String(o.attributes.unit_of_measurement??"")}:null,a=new Set,l=(c,d)=>{if(!c||c==="none"||a.has(c))return;a.add(c);let u=t.states[c]?.state;if(!u||!r1.has(u)||c.startsWith("light."))return;let p=pi(t,c),h=p?ze(t.states[p]):null;if(h===null||h<=n1)return;let f=ib(h*24*365/1e3,s);r.push({kind:"standby",floorId:n.id,vars:{name:B(t,c),w:Math.round(h),cost:f?`${f.value.toFixed(0)} ${f.currency}`:`${Math.round(h*24*365/1e3)} kWh`},fix:d,changes:!1})};for(let c of n.furniture)l(c.entity,{do:"show_furniture",furnitureId:c.id});for(let c of n.placements){let d=n.rooms.find(u=>u.points.length>=3&&C([c.x,c.z],u.points));d&&l(c.entity_id,{do:"show_room",roomId:d.id})}}function hb(t,e){let n=[],r=e?.areas,i=new Set(t.settings.check_ignore??[]),o=new Set(t.floors.flatMap(s=>s.rooms.map(a=>a.area_id)).filter(s=>!!s));for(let s of t.floors){if(s.layer)continue;for(let l of s.rooms){if(l.area_id)continue;let c=Object.values(r??{}).find(d=>d.name.trim().toLowerCase()===l.name.trim().toLowerCase()&&!o.has(d.area_id));n.push(c?{kind:"room_no_area",floorId:s.id,vars:{room:l.name,area:c.name},fix:{do:"set_area",roomId:l.id,areaId:c.area_id},changes:!0}:{kind:"room_no_area",floorId:s.id,vars:{room:l.name,area:""},fix:{do:"show_room",roomId:l.id},changes:!1})}let a=_r(t,s,r);if(a.length&&n.push({kind:"areas_unplaced",floorId:s.id,vars:{n:a.length,names:a.map(l=>l.name).join(", ")},fix:{do:"add_area_rooms"},changes:!0}),e){let l=Re(e,[s]),c=Lt(e,[s]);for(let d of s.rooms){if(!d.area_id)continue;let u=ss(s,d);for(let f of s.furniture)if(C([f.x,f.z],d.points))for(let g of db(f))u.add(g);for(let f of s.openings)if(f.room_id===d.id){for(let g of ub(f))u.add(g);for(let g of Object.values(c.get(f.id)??{}))typeof g=="string"&&u.add(g)}for(let f of s.furniture){let g=l.get(f.id);if(g&&C([f.x,f.z],d.points))for(let b of[g.entity,g.power])typeof b=="string"&&u.add(b)}let p=we(e,d).filter(f=>Dt(je(e,f))),h=Ln(e,p).map(f=>f.primary).filter(f=>!u.has(f)&&!i.has(f));h.length&&n.push({kind:"devices_unplaced",floorId:s.id,vars:{room:d.name,n:h.length},fix:{do:"place_devices",roomId:d.id,entityIds:h},entityIds:h,changes:!0})}}for(let l=0;l<s.rooms.length;l++)for(let c=l+1;c<s.rooms.length;c++){let[d,u]=[s.rooms[l],s.rooms[c]];t1(d,u)&&n.push({kind:"rooms_overlap",floorId:s.id,vars:{a:d.name,b:u.name},fix:{do:"show_room",roomId:u.id},changes:!1})}if(s.openings.length){let l=me(s.rooms,{exterior:t.settings.wall_exterior,interior:t.settings.wall_interior},s.walls??[]).walls;for(let c of s.openings){let d=Ne(c,s.rooms,s.walls??[]);(!d||!Kt(l,c,d))&&n.push({kind:"opening_off_wall",floorId:s.id,vars:{room:s.rooms.find(u=>u.id===c.room_id)?.name??""},fix:{do:"show_opening",openingId:c.id},changes:!1})}}if(e&&i1(e,t,s,n),e&&Object.keys(e.states).length){let l=s.placements.map(c=>c.entity_id).filter(c=>!e.states[c]);l.length&&n.push({kind:"entity_missing",floorId:s.id,vars:{n:l.length,ids:l.slice(0,3).join(", ")},fix:{do:"remove_placements",entityIds:l},changes:!0});for(let c of s.furniture){let d=db(c).filter(u=>u!=="none"&&!e.states[u]);d.length&&!(de(c.type)&&!c.entity)&&n.push({kind:"furniture_entity_missing",floorId:s.id,vars:{id:d[0]},fix:{do:"show_furniture",furnitureId:c.id},changes:!1})}}}if(e)for(let s of ab(e,t)){if(s.level>=sb)break;n.push({kind:"battery_low",floorId:s.floorId,vars:{name:B(e,s.entity),level:Math.round(s.level)},fix:s.roomId?{do:"show_room",roomId:s.roomId}:{do:"show_floor"},changes:!1})}return n}var re=t=>t.replace(/[&<>"]/g,e=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;"})[e]),Rn=t=>t.map(([e,n])=>`${e.toFixed(3)},${n.toFixed(3)}`).join(" ");function o1(t,e,n,r){let i=me(e.rooms,{exterior:t.settings.wall_exterior,interior:t.settings.wall_interior},e.walls??[]).walls,o=[...e.rooms.flatMap(y=>y.points),...i.flatMap(y=>y.footprint)];if(!o.length)return"";let[s,a]=[Math.min(...o.map(y=>y[0])),Math.max(...o.map(y=>y[0]))],[l,c]=[Math.min(...o.map(y=>y[1])),Math.max(...o.map(y=>y[1]))],d=1.2,u=[];for(let y of e.rooms)u.push(`<polygon points="${Rn(y.points)}" fill="#f4f4f4" stroke="none"/>`);for(let y of i)u.push(`<polygon points="${Rn(y.footprint)}" fill="#222" stroke="#222" stroke-width="0.01"/>`);for(let y of e.openings){let v=Ne(y,e.rooms,e.walls??[]),w=v?Kt(i,y,v):null;if(!w)continue;let{wall:k,s:x}=w,M=Math.hypot(k.b[0]-k.a[0],k.b[1]-k.a[1]);if(M<1e-6)continue;let A=[(k.b[0]-k.a[0])/M,(k.b[1]-k.a[1])/M],T=[-A[1],A[0]],F=(X,ke)=>[k.a[0]+A[0]*X+T[0]*ke,k.a[1]+A[1]*X+T[1]*ke],[L,I]=[x-y.width/2,x+y.width/2],[N,V]=[k.left+.01,-(k.right+.01)];if(u.push(`<polygon points="${Rn([F(L,N),F(I,N),F(I,V),F(L,V)])}" fill="#fff"/>`),y.type==="garage"){let X=(k.left-k.right)/2;u.push(`<polyline points="${Rn([F(L,X),F(I,X)])}" fill="none" stroke="#555" stroke-width="0.02" stroke-dasharray="0.12 0.08"/>`)}else if(y.type==="window"){let X=(k.left-k.right)/2;u.push(`<polyline points="${Rn([F(L,X),F(I,X)])}" fill="none" stroke="#222" stroke-width="0.03"/>`),u.push(`<polyline points="${Rn([F(L,N-.01),F(I,N-.01)])}" fill="none" stroke="#222" stroke-width="0.015"/><polyline points="${Rn([F(L,V+.01),F(I,V+.01)])}" fill="none" stroke="#222" stroke-width="0.015"/>`)}else{let X=y.room_id===k.roomRight?-1:1,ke=F(L,X*(X>0?k.left:k.right)),Ft=F(L,X*((X>0?k.left:k.right)+y.width)),j=F(I,X*(X>0?k.left:k.right));u.push(`<path d="M ${ke[0]} ${ke[1]} L ${Ft[0]} ${Ft[1]} A ${y.width} ${y.width} 0 0 ${X>0?1:0} ${j[0]} ${j[1]}" fill="none" stroke="#555" stroke-width="0.015"/>`)}}let p=new Map(n.map(y=>[y.roomId,y]));for(let y of e.rooms){if(y.points.length<3)continue;let[v,w]=ve(y.points),k=p.get(y.id);u.push(`<text x="${v}" y="${w-.08}" font-size="0.32" text-anchor="middle" font-weight="600">${re(y.name)}</text>`),k&&u.push(`<text x="${v}" y="${w+.32}" font-size="0.24" text-anchor="middle" fill="#444">${re(r.area(k.living>0?k.living:k.floor))}</text>`)}let h=(y,v,w,k,x,M)=>{let T=(y+w)/2,F=(v+k)/2,L=M?`M ${y-.15} ${v} L ${y+.15} ${v} M ${w-.15} ${k} L ${w+.15} ${k}`:`M ${y} ${v-.15} L ${y} ${v+.15} M ${w} ${k-.15} L ${w} ${k+.15}`,I=M?`<text x="${T-.25}" y="${F}" font-size="0.26" text-anchor="middle" transform="rotate(-90 ${T-.25} ${F})">${re(x)}</text>`:`<text x="${T}" y="${F+.4}" font-size="0.26" text-anchor="middle">${re(x)}</text>`;return`<path d="M ${y} ${v} L ${w} ${k} ${L}" stroke="#222" stroke-width="0.015" fill="none"/>${I}`};u.push(h(s,c+.5,a,c+.5,r.length(a-s),!1)),u.push(h(s-.5,l,s-.5,c,r.length(c-l),!0)),u.push(`<path d="M ${a-1} ${l-.7} L ${a} ${l-.7}" stroke="#222" stroke-width="0.06"/><text x="${a-.5}" y="${l-.85}" font-size="0.22" text-anchor="middle">${re(r.length(1))}</text>`);let[f,g]=[a-s+2*d,c-l+2*d];return`<svg xmlns="http://www.w3.org/2000/svg" viewBox="${`${s-d} ${l-d} ${f} ${g}`}" style="width:${(f*10).toFixed(1)}mm" font-family="system-ui, sans-serif">${u.join("")}</svg>`}function pb(t,e){let n=t.floors.filter(l=>!l.layer&&l.rooms.length),r=[],i=[],o=[];for(let l of[...n].sort((c,d)=>c.elevation-d.elevation)){let c=Di(t,l);o.push(...c);let d=gr(c);r.push(`<section class="page"><h1>${re(l.name)}</h1><div class="sub">${re(e.living)}: ${re(e.area(d.living))}</div>${o1(t,l,c,e)}</section>`),i.push(`<tr class="floor"><th colspan="4">${re(l.name)}</th></tr>`);for(let u of c){let p=l.rooms.find(h=>h.id===u.roomId);i.push(`<tr><td>${re(p.name)}</td><td>${re(e.area(u.floor))}</td><td>${u.low>.05?re(e.area(u.low)):""}</td><td><b>${re(e.area(u.living))}</b></td></tr>`)}i.push(`<tr class="sum"><td>${re(e.total)}</td><td>${re(e.area(d.floor))}</td><td>${d.low>.05?re(e.area(d.low)):""}</td><td><b>${re(e.area(d.living))}</b></td></tr>`)}let s=gr(o),a=`<section class="page"><h1>${re(e.living)}</h1><table><thead><tr><th>${re(e.room)}</th><th>${re(e.floorArea)}</th><th>${re(e.low)}</th><th>${re(e.living)}</th></tr></thead><tbody>${i.join("")}<tr class="grand"><td>${re(e.total)}</td><td>${re(e.area(s.floor))}</td><td>${s.low>.05?re(e.area(s.low)):""}</td><td><b>${re(e.area(s.living))}</b></td></tr></tbody></table><p class="note">${re(e.note)}</p></section>`;return`<!doctype html><html><head><meta charset="utf-8"><title>${re(e.title)}</title><style>
body { font-family: system-ui, sans-serif; color: #111; margin: 0; background: #fff; }
.page { page-break-after: always; padding: 12mm; }
.page:last-child { page-break-after: auto; }
h1 { font-size: 18pt; margin: 0 0 2mm; }
.sub { color: #555; margin-bottom: 4mm; }
svg { display: block; max-width: 100%; max-height: 240mm; height: auto; }
table { border-collapse: collapse; width: 100%; font-size: 11pt; }
th, td { text-align: left; padding: 1.5mm 2mm; border-bottom: 0.2mm solid #ccc; }
td:not(:first-child), th:not(:first-child) { text-align: right; }
tr.floor th { background: #eee; }
tr.sum td { border-bottom: 0.4mm solid #888; }
tr.grand td { font-size: 12pt; border-top: 0.6mm solid #222; }
.note { color: #666; font-size: 9pt; margin-top: 4mm; }
@media print { .page { padding: 0; } }
</style></head><body>${r.join("")}${a}<script>window.addEventListener("load", () => setTimeout(() => window.print(), 300));<\/script></body></html>`}var fb="nextfloor.tour_done",s1=[["Ctrl Z","keys_undo"],["Ctrl Shift Z \xB7 Ctrl Y","keys_redo"],["Ctrl D","keys_duplicate"],["Entf / Delete","keys_delete"],["\u2190 \u2191 \u2192 \u2193","keys_nudge"],["Shift + \u2190\u2191\u2192\u2193","keys_nudge_10"],["Alt + \u2190\u2191\u2192\u2193","keys_nudge_1"],["R \xB7 Shift R","keys_rotate"],["L","keys_lock"],["Enter","keys_close_shape"],["Esc","keys_escape"],["Shift","keys_straight"],["?","keys_sheet"]],Rs=[["tour_1_title","tour_1"],["tour_2_title","tour_2"],["tour_3_title","tour_3"],["tour_4_title","tour_4"]];function mb(){try{return localStorage.getItem(fb)!=="1"}catch{return!1}}function gb(){try{localStorage.setItem(fb,"1")}catch{}}function _b(t,e){return m`<div class="nf-keys" role="dialog" aria-label=${t("keys_title")} @click=${n=>n.target===n.currentTarget&&e()}>
<div class="nf-keys-card">
<div class="nf-h3row"><h3>⌨ ${t("keys_title")}</h3><button class="nf-btn nf-field-btn" aria-label=${t("close")} @click=${e}>✕</button></div>
<dl>
${s1.map(([n,r])=>m`<dt>${n.split(" \xB7 ").map((i,o)=>m`${o?" \xB7 ":""}<kbd>${i}</kbd>`)}</dt><dd>${t(r)}</dd>`)}
</dl>
</div>
</div>`}function a1(t){return{rect:t("tool_rect"),free:t("tool_polygon"),rooms:t("area_rooms",{n:"\u2026"}).replace(/\s*\(…\)\s*$/,""),opening:t("tool_opening"),furniture:t("tool_furniture"),split:t("split_3d"),check:t("check_open")}}function bb(t,e,n){if(e===null||e>=Rs.length)return _;let[r,i]=Rs[e],o=e===Rs.length-1;return m`<div class="nf-tour" role="dialog" aria-label=${t("tour_title")}>
<div class="nf-tour-step">${e+1} / ${Rs.length}</div>
<h3>${t(r)}</h3>
<p>${t(i,a1(t))}</p>
<div class="nf-actions">
${e>0?m`<button class="nf-btn" @click=${()=>n(e-1)}>‹ ${t("tour_back")}</button>`:_}
<button class="nf-btn nf-primary" @click=${()=>n(o?null:e+1)}>${t(o?"tour_done":"tour_next")}</button>
${o?_:m`<button class="nf-link" @click=${()=>n(null)}>${t("tour_skip")}</button>`}
</div>
</div>`}var Xt="https://github.com/therealMRBK/NextFloor";var Oi=t=>`/api/nextfloor/mesh/${encodeURIComponent(t)}`,wr=12*1024*1024;function yb(t,e){let n=new Map;for(let r of t)for(let i of r.items){if(!i.mesh)continue;let o=n.get(i.mesh)??[];n.set(i.mesh,[...o,`${Je(i,he(r.id,i.id),e)} \xB7 ${Ve(r,e)}`])}return[...n].map(([r,i])=>({id:r,items:i})).sort((r,i)=>r.items[0].localeCompare(i.items[0]))}function xr(t){return t<1024*1024?`${Math.max(1,Math.round(t/1024))} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}function Fc(t){return t===201||t===200||t===204?null:t===401||t===403?"forbidden":t===413?"too_large":t===400?"not_glb":t===404?"bad_id":"other"}var l1=40,c1=(t=wr)=>Math.floor(t*.8/l1),Tc=[{key:"light",triangles:3e4},{key:"normal",triangles:8e4},{key:"fine",triangles:15e4}];function vb(t){return Math.min(Tc.find(e=>e.key===t).triangles,c1())}var zc=class extends q{static properties={hass:{attribute:!1},packs:{attribute:!1},_present:{state:!0},_draft:{state:!0},_busy:{state:!0},_message:{state:!0}};checked=new Set;run=0;constructor(){super(),this._present={},this._draft=null,this._busy=!1,this._message=null}t(e,n){return xe(this.hass,e,n)}get slots(){return yb(this.packs??[],this.hass?.language??"en")}willUpdate(){for(let e of this.slots)this.checked.has(e.id)||!this.hass?.fetchWithAuth||(this.checked.add(e.id),this.askPresence(e.id))}async askPresence(e){let n=await this.hass.fetchWithAuth(Oi(e),{method:"HEAD"}).catch(()=>null),r=n&&n.status!==405?n.ok:await this.hass.fetchWithAuth(Oi(e)).then(i=>i.ok,()=>!1);this._present={...this._present,[e]:r?"yes":"no"}}async choose(e,n){if(n){this._message=null,this._busy=!0;try{let r=await n.arrayBuffer(),o=await(await $n()).inspectModel(r);this._draft={slot:e,fileName:n.name,data:r,info:o,turns:0,paint:o.paint,detail:"normal",colour:"#1d5bd6",result:null},await this.refresh()}catch(r){this._draft=null,this._message={ok:!1,text:this.readError(r)}}finally{this._busy=!1}}}readError(e){let r=`model_error_${e?.reason}`,i=this.t(r);return i===r?this.t("model_error_unreadable",{detail:String(e?.message??e)}):i}async refresh(){let e=this._draft;if(!e)return;let n=++this.run;this._busy=!0;try{let r=await $n(),{glb:i,triangles:o}=await r.prepareModel(e.data,{turns:e.turns,paint:e.paint,maxTriangles:vb(e.detail)}),s=await r.previewModel(i,e.colour);n===this.run&&this._draft===e&&(this._draft={...e,result:{glb:i,triangles:o,picture:s}})}catch(r){n===this.run&&(this._message={ok:!1,text:this.readError(r)})}finally{n===this.run&&(this._busy=!1)}}change(e){this._draft&&(this._draft={...this._draft,...e},this.refresh())}turn(e){this._draft&&this.change({turns:(this._draft.turns+e+4)%4})}togglePaint(e,n){if(!this._draft)return;let r=this._draft.paint.filter(i=>i!==e);this.change({paint:n?[...r,e]:r})}async upload(){let e=this._draft;if(!(!e?.result||!this.hass?.fetchWithAuth)){if(e.result.glb.byteLength>wr){this._message={ok:!1,text:this.t("model_error_too_large",{max:xr(wr)})};return}this._busy=!0;try{let n=await this.hass.fetchWithAuth(Oi(e.slot.id),{method:"POST",body:e.result.glb}),r=Fc(n.status);if(r){this._message={ok:!1,text:this.t(`model_upload_${r}`,{max:xr(wr)})};return}this._present={...this._present,[e.slot.id]:"yes"},this._message={ok:!0,text:this.t("model_uploaded",{id:e.slot.id,size:xr(e.result.glb.byteLength)})},this._draft=null}catch(n){this._message={ok:!1,text:this.t("model_upload_other",{detail:String(n?.message??n)})}}finally{this._busy=!1}}}async removeModel(e){if(!this.hass?.fetchWithAuth||!confirm(this.t("model_remove_confirm",{id:e.id})))return;let n=await this.hass.fetchWithAuth(Oi(e.id),{method:"DELETE"}),r=Fc(n.status);this._present={...this._present,[e.id]:r?this._present[e.id]:"no"},this._message=r?{ok:!1,text:this.t(`model_upload_${r}`,{max:xr(wr)})}:{ok:!0,text:this.t("model_removed",{id:e.id})}}row(e){let n=this._present[e.id]??"unknown",r=n==="yes"?this.t("model_present"):n==="no"?this.t("model_missing"):"\u2026";return m`<div class="nf-model">
<div>
<b>${e.items[0]}</b>${e.items.length>1?m` <span class="nf-sub">+${e.items.length-1}</span>`:_}
<span class="nf-sub">${e.id}.glb · <span class="nf-model-${n}">${r}</span></span>
</div>
<div class="nf-model-actions">
<label class="nf-btn nf-primary">
${this.t(n==="yes"?"model_replace":"model_add")}
<input type="file" accept=".glb,model/gltf-binary" hidden @change=${i=>this.picked(e,i)} />
</label>
${n==="yes"?m`<button class="nf-btn nf-danger" @click=${()=>this.removeModel(e)}>${this.t("model_remove")}</button>`:_}
</div>
</div>`}picked(e,n){let r=n.target,i=r.files?.[0];r.value="",this.choose(e,i)}editor(e){let{info:n,result:r}=e,i=n.size.map(o=>o.toFixed(2)).join(" \xD7 ");return m`<section class="nf-model-edit">
<h4>${e.slot.items[0]}</h4>
<p class="nf-sub">${e.fileName} · ${this.t("model_info",{triangles:n.triangles.toLocaleString(this.hass?.language),size:i})}</p>
<div class="nf-model-body">
<div class="nf-model-picture">${r?m`<img src=${r.picture} alt="" />`:m`<span class="nf-sub">${this.t("loading")}</span>`}</div>
<div class="nf-model-options">
<div class="nf-field">
<span>${this.t("model_front")}</span>
<div class="nf-actions">
<button class="nf-btn" @click=${()=>this.turn(-1)}>↺ 90°</button>
<button class="nf-btn" @click=${()=>this.turn(1)}>↻ 90°</button>
</div>
${S(this.t("model_front_hint"))}
</div>
<div class="nf-field">
<span>${this.t("model_paint")}</span>
${n.materials.map(o=>m`<label class="nf-check"><input type="checkbox" .checked=${e.paint.includes(o.name)} @change=${s=>this.togglePaint(o.name,s.target.checked)} /> ${o.name}</label>`)}
<label class="nf-check"><input type="color" .value=${e.colour} @change=${o=>this.change({colour:o.target.value})} /> ${this.t("model_paint_preview")}</label>
</div>
<div class="nf-field">
<span>${this.t("model_detail")}</span>
<div class="nf-seg">${Tc.map(o=>m`<button aria-pressed=${e.detail===o.key} @click=${()=>this.change({detail:o.key})}>${this.t(`model_detail_${o.key}`)}</button>`)}</div>
${r?m`<small class="nf-sub">${this.t("model_result",{triangles:r.triangles.toLocaleString(this.hass?.language),size:xr(r.glb.byteLength)})}</small>`:_}
</div>
</div>
</div>
<div class="nf-actions">
<button class="nf-btn nf-primary" ?disabled=${!r||this._busy} @click=${()=>this.upload()}>${this.t("model_upload")}</button>
<button class="nf-btn" @click=${()=>this._draft=null}>${this.t("cancel")}</button>
</div>
</section>`}render(){let e=this.slots;return e.length===0||!(this.hass?.user?.is_admin??!1)?_:m`<section class="nf-ext-card">
<h3>${this.t("models")}</h3>
${S(this.t("models_hint"))}
${e.map(n=>this.row(n))}
${this._draft?this.editor(this._draft):_}
${this._busy&&!this._draft?m`<p class="nf-sub">${this.t("loading")}</p>`:_}
${this._message?m`<p class="nf-sub ${this._message.ok?"nf-notice":"nf-pack-error"}">${this._message.text}</p>`:_}
${S(this.t("models_licence"))}
</section>`}static styles=[fe,pt,J`
:host {
display: block;
}
.nf-model {
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: space-between;
gap: 8px 12px;
padding: 8px 0;
border-top: 1px solid var(--nf-line);
}
.nf-model > div:first-child {
display: grid;
gap: 2px;
}
.nf-model-actions {
display: flex;
gap: 8px;
}
.nf-model-yes {
color: #41c46b;
}
.nf-model-no {
color: var(--nf-muted);
}
.nf-model-edit {
margin-top: 10px;
padding: 12px;
border: 1px solid var(--nf-line);
border-radius: 12px;
}
.nf-model-body {
display: flex;
flex-wrap: wrap;
gap: 14px;
}
.nf-model-picture {
display: grid;
place-items: center;
width: 220px;
height: 220px;
border-radius: 12px;
background: var(--nf-chrome-solid);
}
.nf-model-picture img {
width: 220px;
height: 220px;
}
.nf-model-options {
display: grid;
flex: 1;
min-width: 220px;
gap: 10px;
align-content: start;
}
.nf-field {
display: grid;
gap: 4px;
}
`]};customElements.get("nf-model-upload")||customElements.define("nf-model-upload",zc);var kr="therealMRBK/NextFloor-Plugins",wb=`https://raw.githubusercontent.com/${kr}/main/index.json`,d1=t=>/^https:\/\/raw\.githubusercontent\.com\/[\w.-]+\/[\w.-]+\/[0-9a-f]{40}\/[\w./-]+\.m?js$/.test(t),De=(t,e)=>typeof t=="string"?t.trim().slice(0,e):"";function u1(t){let e=t?.plugins;if(!Array.isArray(e))return[];let n=new Set,r=[];for(let i of e){if(!i||typeof i!="object")continue;let o=De(i.id,64),s=De(i.url,300),a=De(i.sha256,64).toLowerCase(),l=De(i.name,60),c=De(i.version,40),d=De(i.homepage,200);!/^[\w.-]+$/.test(o)||n.has(o)||!l||!c||!d1(s)||!/^[0-9a-f]{64}$/.test(a)||(n.add(o),r.push({id:o,name:l,description:De(i.description,300),author:De(i.author,60),version:c,homepage:/^https:\/\//.test(d)?d:"",url:s,sha256:a}))}return r}async function xb(t=(...e)=>fetch(...e)){let e=await t(wb,{cache:"no-store"});if(!e.ok)throw new Error(`HTTP ${e.status}`);return u1(await e.json())}function kb(t,e){let n=(e??[]).find(r=>r.id===t.id);return n?n.sha256===t.sha256&&n.url===t.url?"installed":"update":"available"}function $b(t,e){let n=t??[],r={url:e.url,enabled:!0,id:e.id,version:e.version,sha256:e.sha256},i=n.findIndex(o=>o.id===e.id);return i<0?[...n,r]:n.map((o,s)=>s===i?{...r,enabled:o.enabled}:o)}var h1=(t,e)=>t===`https://raw.githubusercontent.com/${kr}/main/packs/${e}.json`;function p1(t){let e=t?.packs;if(!Array.isArray(e))return[];let n=new Set,r=[];for(let i of e){if(!i||typeof i!="object")continue;let o=De(i.id,40),s=De(i.url,300),a=De(i.sha256,64).toLowerCase(),l=De(i.name,80);if(!/^[a-z0-9][a-z0-9_.-]{0,39}$/.test(o)||o.startsWith("nextfloor.")||n.has(o)||!l||!h1(s,o)||!/^[0-9a-f]{64}$/.test(a))continue;n.add(o);let c=(d,u)=>typeof d=="number"&&Number.isInteger(d)&&d>0?d:u;r.push({id:o,name:l,description:De(i.description,400),author:De(i.author,80),release:c(i.release,1),items:c(i.items,0),url:s,sha256:a})}return r.sort((i,o)=>i.name.localeCompare(o.name))}async function Sb(t=(...e)=>fetch(...e)){let e=await t(wb,{cache:"no-store"});if(!e.ok)throw new Error(`HTTP ${e.status}`);return p1(await e.json())}function Mb(t,e){let n=e.find(r=>r.id===t.id);return n?(n.release??1)>=t.release?"installed":"update":"available"}var f1=t=>[...new Uint8Array(t)].map(e=>e.toString(16).padStart(2,"0")).join("");async function Eb(t,e=(...n)=>fetch(...n)){let n=await e(t.url,{cache:"no-store"});if(!n.ok)throw new Error(`HTTP ${n.status}`);let r=await n.arrayBuffer(),i=globalThis.crypto?.subtle;if(i&&f1(await i.digest("SHA-256",r))!==t.sha256)throw new Error("checksum mismatch: the file is not the one that was reviewed");return new TextDecoder().decode(r)}var m1="https://therealmrbk.github.io/NextFloor/builder/",Pc=class extends q{static properties={hass:{attribute:!1},packs:{attribute:!1},_msg:{state:!0},_busy:{state:!0},_store:{state:!0},_storeError:{state:!0}};constructor(){super(),this._msg=null,this._busy=!1,this._store=null,this._storeError=null}async loadStore(){this._store="loading",this._storeError=null;try{this._store=await Sb()}catch(e){this._store=null,this._storeError=this.t("community_failed",{detail:e?.message??String(e)})}}async installStore(e){this._busy=!0,this._msg=null;try{let n=await Cr(this.hass,await Eb(e));this._msg={ok:!0,text:this.t("pack_imported",{name:n.name,publisher:n.publisher,n:n.items})},this.changed()}catch(n){this._msg={ok:!1,text:this.errorText(n)}}finally{this._busy=!1}}renderStore(){let e=this.packs??[],n=this._store;return m`<h4>${this.t("community_title")}</h4>
<p class="nf-sub">
${this.t("community_intro")} <a href=${m1} target="_blank" rel="noopener">${this.t("community_builder")}</a> ·
<a href=${`https://github.com/${kr}#community-furniture`} target="_blank" rel="noopener">${this.t("community_how")}</a>
</p>
${n===null?m`<div><button class="nf-btn" @click=${()=>{this.loadStore()}}>${this.t("community_load")}</button></div>`:n==="loading"?m`<p class="nf-sub">${this.t("loading")}</p>`:n.length?m`<ul>
${n.map(r=>{let i=Mb(r,e);return m`<li>
<div class="nf-pack-main">
<strong>${r.name}</strong>
<span class="nf-detail">${r.id} · ${this.t("pack_by",{publisher:r.author,n:r.items})}</span>
${r.description?m`<span class="nf-detail">${r.description}</span>`:_}
</div>
<button class="nf-btn ${i==="installed"?"":"nf-primary"}" ?disabled=${this._busy||i==="installed"} @click=${()=>{this.installStore(r)}}>
${this.t(i==="installed"?"community_installed":i==="update"?"community_update":"community_install")}
</button>
</li>`})}
</ul>`:m`<p class="nf-sub">${this.t("community_none")}</p>`}
${this._storeError?m`<p class="nf-error" role="alert">${this._storeError}</p>`:_}`}t(e,n){return xe(this.hass,e,n)}changed(){this.dispatchEvent(new CustomEvent("packs-changed",{bubbles:!0,composed:!0}))}errorText(e){let{code:n,message:r}=e??{},i=r??String(e),o=`pack_error_${n}`,s=this.t(o,{detail:i});return s===o?this.t("pack_error_other",{detail:i}):s}async importTexts(e){if(!this.hass||!e.length)return 0;this._busy=!0;let n=[],r=[];for(let{label:o,text:s}of e)try{let a=await Cr(this.hass,s);n.push(this.t("pack_imported",{name:a.name,publisher:a.publisher,n:a.items}))}catch(a){r.push(o?`${o}: ${this.errorText(a)}`:this.errorText(a))}this._busy=!1,n.length&&this.changed();let i=e.length>1?[this.t("packs_imported_n",{n:n.length,total:e.length})]:[];return this._msg={ok:r.length===0,text:[...i,...n,...r].join(" \xB7 ")},n.length}async importFiles(e){let n=e.target,r=[...n.files??[]];n.value="",await this.importTexts(await Promise.all(r.map(async i=>({label:i.name,text:await i.text()}))))}async importPasted(){let e=this.renderRoot.querySelector("textarea"),n=e?.value.trim()??"";if(!e||!n)return void(this._msg={ok:!1,text:this.t("pack_paste_empty")});try{JSON.parse(n)}catch(r){return void(this._msg={ok:!1,text:this.t("pack_paste_not_json",{detail:r instanceof Error?r.message:String(r)})})}await this.importTexts([{label:"",text:n}])>0&&(e.value="")}async deletePack(e){if(!(!this.hass||!confirm(this.t("pack_remove_confirm",{name:Ve(e,this.hass.language??"de")}))))try{await Ju(this.hass,e.id),this._msg=null,this.changed()}catch(n){this._msg={ok:!1,text:this.errorText(n)}}}render(){let e=(this.packs??[]).filter(i=>!i.builtin),n=(this.packs??[]).length-e.length,r=this.hass?.language??"de";return m`<section class="nf-packs">
<h3>${this.t("packs_title")}</h3>
<p class="nf-sub">${this.t("packs_intro",{n})} <a href="${Xt}/blob/main/docs/packs.md" target="_blank" rel="noopener">${this.t("packs_docs")}</a></p>
${e.length?m`<ul>
${e.map(i=>m`<li>
<div class="nf-pack-main">
<strong>${Ve(i,r)}</strong>
<span class="nf-detail">${i.id} · ${this.t("pack_by",{publisher:i.publisher,n:i.items.length})}</span>
${i.description?m`<span class="nf-detail">${i.description}</span>`:_}
</div>
<button class="nf-btn" ?disabled=${this._busy} @click=${()=>this.deletePack(i)}>${this.t("pack_remove")}</button>
</li>`)}
</ul>`:m`<p class="nf-sub">${this.t("packs_none")}</p>`}
<label class="nf-btn nf-file">
${this.t("pack_import")}
<input type="file" accept=".nfpack,.json,application/json" multiple hidden ?disabled=${this._busy} @change=${i=>this.importFiles(i)} />
</label>
<textarea rows="6" spellcheck="false" aria-label=${this.t("pack_paste")} placeholder=${'{ "format": "nfpack", "version": 1, "id": "myname.kitchen", \u2026 }'}></textarea>
<div>
<button class="nf-btn nf-primary" ?disabled=${this._busy} @click=${()=>this.importPasted()}>${this.t("pack_paste")}</button>
</div>
${this._msg?m`<p class=${this._msg.ok?"nf-ok":"nf-error"} role=${this._msg.ok?"status":"alert"}>${this._msg.text}</p>`:_}
${this.hass?this.renderStore():_}
</section>`}static styles=[fe,pt,J`
.nf-packs {
display: grid;
gap: 10px;
padding: 16px;
border: 1px solid var(--nf-line);
border-radius: 12px;
}
h3 {
margin: 0;
font-size: 17px;
}
.nf-sub,
.nf-ok,
.nf-error {
margin: 0;
font-size: 13px;
}
.nf-sub {
color: var(--nf-soft);
}
.nf-ok {
color: var(--success-color, #2e7d32);
}
.nf-error {
color: var(--error-color, #c62828);
overflow-wrap: anywhere;
}
h4 {
margin: 14px 0 0;
font-size: 15px;
}
ul {
list-style: none;
margin: 0;
padding: 0;
display: grid;
gap: 8px;
}
li {
display: flex;
gap: 10px;
align-items: center;
}
.nf-pack-main {
flex: 1;
min-width: 0;
display: grid;
gap: 2px;
}
.nf-detail {
font-size: 12px;
color: var(--nf-soft);
overflow-wrap: anywhere;
}
.nf-file {
justify-self: start;
cursor: pointer;
}
textarea {
box-sizing: border-box;
width: 100%;
min-height: 110px;
resize: vertical;
padding: 8px 10px;
border: 1px solid var(--nf-line);
border-radius: 8px;
background: transparent;
color: inherit;
font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
}
`]};customElements.get("nf-pack-manager")||customElements.define("nf-pack-manager",Pc);var XC=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]);var g1=new Map;var Rb=()=>[...g1.values()];var Ic=class extends q{static properties={hass:{attribute:!1},plugins:{attribute:!1},_error:{state:!0},_store:{state:!0},_storeError:{state:!0},_storeOpen:{state:!0}};stop=null;constructor(){super(),this._error="",this._storeError="",this._storeOpen=!1}connectedCallback(){super.connectedCallback(),this.stop=co(()=>this.requestUpdate())}disconnectedCallback(){super.disconnectedCallback(),this.stop?.()}t(e,n){return xe(this.hass,e,n)}emit(e){this.dispatchEvent(new CustomEvent("plugins-changed",{detail:e,bubbles:!0,composed:!0}))}add(e){let n=oa(e.value),r=this.plugins??[];if(!sa(n))return void(this._error=this.t("plugins_url_invalid"));if(r.some(i=>i.url===n))return void(this._error=this.t("plugins_exists"));if(r.length>=20)return void(this._error=this.t("plugins_limit"));this._error="",e.value="",this.emit([...r,{url:n,enabled:!0}])}async toggleStore(){if(this._storeOpen=!this._storeOpen,!(!this._storeOpen||this._store)){this._storeError="";try{this._store=await xb()}catch(e){this._storeError=this.t("store_failed",{error:e instanceof Error?e.message:String(e)})}}}install(e){let n=this.plugins??[],r=n.some(i=>i.id===e.id);if(!r&&n.length>=20)return void(this._error=this.t("plugins_limit"));if(!r&&n.some(i=>i.url===e.url))return void(this._error=this.t("plugins_exists"));window.confirm(this.t("store_confirm",{name:e.name,author:e.author||"?",url:e.url}))&&(this._error="",this.emit($b(n,e)))}renderStore(){return m`<div class="nf-store">
<button class="nf-btn" @click=${()=>this.toggleStore()}>${this._storeOpen?this.t("store_close"):this.t("store_open")}</button>
${this._storeOpen?m`<p class="nf-sub">${this.t("store_intro")} <a href="https://github.com/${kr}" target="_blank" rel="noopener">${this.t("store_submit")}</a></p>
${this._storeError?m`<p class="nf-error" role="alert">${this._storeError}</p>`:_}
${!this._store&&!this._storeError?m`<p class="nf-sub">${this.t("plugins_loading")}</p>`:_}
${this._store&&!this._store.length?m`<p class="nf-sub">${this.t("store_empty")}</p>`:_}
<ul>
${(this._store??[]).map(e=>{let n=kb(e,this.plugins);return m`<li>
<div class="nf-plugin-main">
<span><strong>${e.name}</strong> <span class="nf-detail">${e.version}${e.author?` \xB7 ${e.author}`:""}</span></span>
${e.description?m`<span class="nf-detail">${e.description}</span>`:_}
${e.homepage?m`<a class="nf-detail" href=${e.homepage} target="_blank" rel="noopener">${e.homepage}</a>`:_}
</div>
${n==="installed"?m`<span class="nf-state ok">${this.t("store_installed")}</span>`:m`<button class="nf-btn" @click=${()=>this.install(e)}>${n==="update"?this.t("store_update"):this.t("store_install")}</button>`}
</li>`})}
</ul>`:_}
</div>`}stateOf(e){let n=Rb().find(o=>o.url===e),r=la().filter(o=>o.source===e),i=[...n?.error?[n.error]:[],...r.flatMap(o=>o.errors)];if(n?.state==="error")return{label:this.t("plugins_error"),tone:"err",detail:i.join(" \xB7 ")};if(n?.state==="loading")return{label:this.t("plugins_loading"),tone:"warn",detail:""};if(n?.state==="loaded"&&!r.length)return{label:this.t("plugins_nothing_registered"),tone:"warn",detail:""};if(r.length){let o=r.map(s=>`${s.name}${s.version?` ${s.version}`:""}`).join(", ");return{label:this.t("plugins_loaded"),tone:i.length?"warn":"ok",detail:i.length?`${o} \xB7 ${i.join(" \xB7 ")}`:o}}return{label:this.t("plugins_reload_hint"),tone:"warn",detail:""}}render(){let e=this.plugins??[],n=la().filter(r=>!r.source);return m`<section class="nf-plugins">
<h3>${this.t("plugins_title")}</h3>
<p class="nf-sub">${this.t("plugins_intro")} <a href="${Xt}/blob/main/docs/plugins.md" target="_blank" rel="noopener">${this.t("plugins_docs")}</a></p>
<p class="nf-warn">⚠️ ${this.t("plugins_warning")}</p>
${e.length?m`<ul>
${e.map((r,i)=>{let o=r.enabled?this.stateOf(r.url):{label:this.t("plugins_off"),tone:"warn",detail:""};return m`<li>
<label class="nf-check" title=${this.t("plugins_reload_hint")}>
<input type="checkbox" .checked=${r.enabled}
@change=${s=>this.emit(e.map((a,l)=>l===i?{...a,enabled:s.target.checked}:a))} />
</label>
<div class="nf-plugin-main">
<code>${r.id?`${r.id}${r.version?` ${r.version}`:""}`:r.url}</code>
<span class="nf-state ${o.tone}">${o.label}</span>
${o.detail?m`<span class="nf-detail">${o.detail}</span>`:_}
</div>
<button class="nf-btn" @click=${()=>this.emit(e.filter((s,a)=>a!==i))}>${this.t("plugins_remove")}</button>
</li>`})}
</ul>`:m`<p class="nf-sub">${this.t("plugins_none")}</p>`}
${n.length?m`<p class="nf-sub">${this.t("plugins_from_dashboard")}: ${n.map(r=>`${r.name}${r.version?` ${r.version}`:""}`).join(", ")}</p>`:_}
${this.renderStore()}
<div class="nf-add">
<input type="text" placeholder="/local/nextfloor/my-plugin.js" aria-label=${this.t("plugins_add")}
@keydown=${r=>r.key==="Enter"&&this.add(r.target)} />
<button class="nf-btn" @click=${r=>this.add(r.target.previousElementSibling)}>${this.t("plugins_add")}</button>
</div>
${this._error?m`<p class="nf-error" role="alert">${this._error}</p>`:_}
</section>`}static styles=[fe,pt,J`
.nf-plugins {
display: grid;
gap: 10px;
padding: 16px;
border: 1px solid var(--nf-line);
border-radius: 12px;
}
h3 {
margin: 0;
font-size: 17px;
}
.nf-sub,
.nf-warn,
.nf-error {
margin: 0;
font-size: 13px;
}
.nf-sub {
color: var(--nf-soft);
}
.nf-warn {
color: var(--warning-color, #b26b00);
}
.nf-error {
color: var(--error-color, #c62828);
}
ul {
list-style: none;
margin: 0;
padding: 0;
display: grid;
gap: 8px;
}
li {
display: flex;
gap: 10px;
align-items: center;
}
.nf-plugin-main {
flex: 1;
min-width: 0;
display: grid;
gap: 2px;
}
code {
overflow-wrap: anywhere;
font-size: 13px;
}
.nf-state {
font-size: 12px;
}
.nf-state.ok {
color: var(--success-color, #2e7d32);
}
.nf-state.warn {
color: var(--nf-soft);
}
.nf-state.err {
color: var(--error-color, #c62828);
}
.nf-detail {
font-size: 12px;
color: var(--nf-soft);
overflow-wrap: anywhere;
}
.nf-store {
display: grid;
gap: 8px;
}
.nf-add {
display: flex;
gap: 8px;
}
.nf-add input {
flex: 1;
min-width: 0;
}
`]};customElements.get("nf-plugin-manager")||customElements.define("nf-plugin-manager",Ic);var Dc=class extends q{static properties={hass:{attribute:!1},packs:{attribute:!1},plugins:{attribute:!1}};t(e,n){return xe(this.hass,e,n)}render(){return m`<div class="nf-ext">
<header class="nf-ext-head">
<h2>${this.t("ext_title")}</h2>
<p class="nf-sub">${this.t("ext_intro")}</p>
<div class="nf-ext-actions">
<a class="nf-btn" href="${Xt}/issues/new/choose" target="_blank" rel="noopener">🐞 ${this.t("help_issue")}</a>
<a class="nf-btn" href="${Xt}/discussions" target="_blank" rel="noopener">💡 ${this.t("help_idea")}</a>
<a class="nf-btn" href="${Xt}#readme" target="_blank" rel="noopener">📖 ${this.t("manual")}</a>
</div>
</header>
<nf-pack-manager .hass=${this.hass} .packs=${this.packs}></nf-pack-manager>
<nf-model-upload .hass=${this.hass} .packs=${this.packs}></nf-model-upload>
<nf-plugin-manager .hass=${this.hass} .plugins=${this.plugins}></nf-plugin-manager>
</div>`}static styles=[fe,pt,J`
:host {
display: block;
overflow: auto;
}
.nf-ext {
max-width: 920px;
margin: 0 auto;
padding: 20px 16px 40px;
display: grid;
gap: 16px;
}
.nf-ext-head {
display: grid;
gap: 8px;
justify-items: start;
}
.nf-ext-head a {
text-decoration: none;
}
.nf-ext-actions,
.nf-ext-links {
display: flex;
flex-wrap: wrap;
gap: 12px;
align-items: center;
}
.nf-ext-head h2 {
margin: 0;
font-size: 22px;
}
.nf-sub {
color: var(--nf-soft);
font-size: 13px;
}
`]};customElements.get("nf-extensions")||customElements.define("nf-extensions",Dc);var Hi="handled",Ab=["select","rect","polygon","wall","opening","furniture","stairs","outdoor","hole","roof","energy"],Fb=new Set(["vertex","room","device","opening","furniture","rotate","resize","outdoor","roofmove","roofcorner","roofvertex","outvertex","solarmove","solarturn","bgmove","bgscale","bgrotate"]),Li=10,We=t=>Math.round(t*1e3)/1e3,Tb={ArrowLeft:[-1,0],ArrowRight:[1,0],ArrowUp:[0,-1],ArrowDown:[0,1]},Oc=class extends q{static properties={hass:{attribute:!1},building:{attribute:!1},narrow:{type:Boolean},roomLabels:{attribute:!1},packs:{attribute:!1},loadCardEditor:{attribute:!1},_doc:{state:!0},_doc3d:{state:!0},_split:{state:!0},_splitRatio:{state:!0},_wall3d:{state:!0},_solid3d:{state:!0},_sidePinned:{state:!0},_studio:{state:!0},_check:{state:!0},_keys:{state:!0},_note:{state:!0},_dims:{state:!0},_tour:{state:!0},_sideOpen:{state:!0},_floorId:{state:!0},_editorScope:{state:!0},_floorMove:{state:!0},_energyNote:{state:!0},_ctx:{state:!0},_fixedHint:{state:!0},_openingPreset:{state:!0},_measureLen:{state:!0},_rectSize:{state:!0},_tool:{state:!0},_wallView:{state:!0},_draft:{state:!0},_cursor:{state:!0},_guides:{state:!0},_view:{state:!0},_size:{state:!0},_canUndo:{state:!0},_canRedo:{state:!0},_arcEdit:{state:!0},_routeDraft:{state:!0}};doc3dTimer;tourChecked=!1;_pick=null;_pickTimer;fixedPan=!1;reframe3d=!1;pressTimer=0;pressStart=null;history=new ws(100);lib=new ls(()=>this.requestUpdate());side=new Ss(()=>this.requestUpdate());sel=new $s(()=>this.requestUpdate());host=this.makeHost();backup=this.makeBackup();roof=this.makeRoof();bg=this.makeBackground();settingsActions={useRoofSections:()=>{this.roof.useSections(),this._tool="roof"}};drag=null;pointers=new Map;pinch=null;fitted=!1;resizeObserver;constructor(){super(),this.narrow=!1,this.roomLabels=!0,this._floorId=null,this._editorScope=null,this._floorMove=null,this._arcEdit=null,this._routeDraft=null,this.roof.sectionId=null,this.roof.solarId=null,this.roof.picking=!1,this.roof.windowId=null,this.roof.chimneyId=null,this._energyNote=null,this._openingPreset="door";let e=!1;try{e=localStorage.getItem("nextfloor.editor3d")==="1"}catch{}this._split=e,this._splitRatio=.55;try{let r=Number(localStorage.getItem("nextfloor.editorSplit"));r>=20&&r<=80&&(this._splitRatio=r/100)}catch{}this._wall3d="cut",this._solid3d=!1,this._doc3d=this._doc,this._sideOpen=!1;let n=!0;try{n=localStorage.getItem("nextfloor.sidePinned")!=="0"}catch{}this._sidePinned=n,this._studio=null,this._check=!1,this._keys=!1,this._note=null,this._dims=(()=>{try{return localStorage.getItem("nextfloor.plan_dims")==="1"}catch{return!1}})(),this._tour=null,this._measureLen=3,this._rectSize=[4,3],this._tool="select",this._wallView=null,this._draft=[],this._cursor=null,this._guides={},this._view={scale:50,ox:40,oy:40},this._size={w:800,h:600},this._canUndo=!1,this._canRedo=!1}t(e,n){return xe(this.hass,e,n)}measureState(){return{draft:this._draft,length:this._measureLen,rectSize:this._rectSize}}measureActions(){return{setLength:e=>this._measureLen=e,step:e=>this.measureStep(e),close:()=>this.closeDraft(),undo:()=>this._draft=this._draft.slice(0,-1),setRectSize:e=>this._rectSize=e,addRectangle:()=>this.rectBySize()}}arcActions(){return{edit:this._arcEdit,setEdit:e=>this._arcEdit=e,apply:e=>{if(!this.isAdmin||Math.abs(e.bulge)<.01)return;let n=this._doc,r=structuredClone(n),i=r.floors.find(c=>c.id===this._floorId);if(!i)return;let[o,s,a]=e.key.split(":");if(!(o==="wall"?Ym(i,s,e.bulge).length>0:qm(i,s,Number(a),e.bulge))){this._arcEdit={...e,error:this.t("arc_too_wide")};return}this._arcEdit=null,this.setDoc(r,n)}}}freeWallActions(){return{update:e=>this.updateFreeWall(e),remove:()=>this.deleteFreeWall(),arc:this.arcActions(),lockButton:this.fixButton("wall",this.sel.wall??"")}}outdoorActions(){return{update:e=>this.updateOutdoor(e),setRectangle:(e,n)=>{let r=this.outdoorArea;r&&this.updateOutdoor({points:Jf(r,e,n)})},duplicate:()=>this.duplicateOutdoor(),remove:()=>this.deleteOutdoor(),removeCorner:e=>{let n=this.sel.outdoor;n&&this.change((r,i)=>{Bf(i.outdoor.find(o=>o.id===n),e)})},lockButton:this.fixButton("outdoor",this.sel.outdoor??"")}}libraryActions(){return{add:e=>this.addFurniture(e),studio:()=>this.openStudio(null),packs:this.packs??[]}}openStudio(e){let n=e?U(e):void 0,r=n?.recipe&&e?.startsWith(`pack:${En}:`)?n.id:null;this._studio={recipe:r&&n?.recipe?{...n.recipe}:Rc("cabinet",""),itemId:r,busy:!1,error:null},this._tool="furniture"}async saveStudio(){let e=this._studio;if(!e||!this.hass||!this.isAdmin)return;let n=this.hass.language??"en",r=zr().find(d=>d.id===En),i=r?.items??[],o={...e.recipe,name:e.recipe.name||this.t(`studio_kind_${e.recipe.kind}`)},s=e.itemId??X_(o.name,i.map(d=>d.id)),a=Es(o,s,n),l={id:En,name:r?.name??this.t("studio_pack_name"),publisher:r?.publisher??this.t("studio_pack_publisher"),release:(r?.release??0)+1,items:e.itemId?i.map(d=>d.id===s?a:d):[...i,a]};this._studio={...e,busy:!0,error:null};try{let{builtin:d,imported_at:u,...p}=l;await Cr(this.hass,JSON.stringify({format:"nfpack",version:1,...p}))}catch(d){this._studio={...e,busy:!1,error:this.t("studio_error",{detail:d.message??String(d)})};return}Ws([...zr().filter(d=>d.id!==En),l]),this.dispatchEvent(new CustomEvent("packs-changed",{bubbles:!0,composed:!0})),this._studio=null;let c=he(En,s);if(e.itemId){let[d,u,p]=a.size;this.change(h=>h.floors.forEach(f=>f.furniture.forEach(g=>g.type===c&&Object.assign(g,{w:d,d:u,h:p}))))}else this.addFurniture(c)}printPlan(){let e=i=>this.t(i),n=pb(this._doc,{title:this.t("print_title"),room:e("print_room"),floorArea:e("print_floor_area"),living:e("print_living"),low:e("print_low"),total:e("print_total"),note:e("living_area_hint"),area:i=>Me(this.hass,i),length:i=>pe(this.hass,i)}),r=window.open("","_blank");if(!r)return void alert(this.t("print_blocked"));r.document.open(),r.document.write(n),r.document.close()}fixFinding(e){e.floorId!==this._floorId&&this.floorActions().openFloor(e.floorId);let n=i=>i.floors.find(o=>o.id===e.floorId),r=e.fix;switch(r.do){case"show_floor":return;case"show_room":return this.selectItem("room",r.roomId);case"show_opening":return this.selectItem("opening",r.openingId);case"show_furniture":return this.selectItem("furniture",r.furnitureId);case"set_area":return this.change(i=>{let o=n(i)?.rooms.find(s=>s.id===r.roomId);o&&Object.assign(o,Jl(o,r.areaId,this.hass?.areas??{},!Z(this.hass)))});case"add_area_rooms":{let i=n(this._doc);i&&this.addAreaRooms(i);return}case"place_devices":return this.change(i=>{let o=n(i),s=o?.rooms.find(a=>a.id===r.roomId);o&&s&&Al(i,o,s,r.entityIds)});case"remove_placements":return this.change(i=>{let o=n(i);o&&(o.placements=o.placements.filter(s=>!r.entityIds.includes(s.entity_id)))});case"ignore_devices":return this.ignoreDevices(r.entityIds)}}ignoreDevices(e){this.change(n=>{n.settings.check_ignore=[...new Set([...n.settings.check_ignore??[],...e])]})}setDims(e){this._dims=e;try{localStorage.setItem("nextfloor.plan_dims",e?"1":"0")}catch{}}addNote(e){if(!this.isAdmin||!this.floor)return;let n=P("note");this.change((r,i)=>i.notes=[...i.notes??[],{id:n,x:Math.round(e[0]*100)/100,z:Math.round(e[1]*100)/100,text:""}]),this._note=n,this._sideOpen=!0}studioButton(){let e=this.furnitureItem?.type;return!e||!wt(e)||!U(e)?.recipe||!e.startsWith(`pack:${En}:`)||!this.isAdmin?_:m`<button class="nf-btn nf-lib-studio" @click=${()=>this.openStudio(e)}>🛠️ ${this.t("studio_open")}</button>`}deviceActions(){return{update:e=>this.updateDevice(e),centre:()=>this.centreDevice(),remove:()=>{this.removeDevice(this.sel.device??""),this.sel.device=null},asFurniture:(e,n)=>this.deviceToFurniture(e,n),packs:this.packs??[],lockButton:this.fixButton("device",this.sel.device??"")}}deviceListActions(){return{select:e=>this.selectItem("device",e),place:e=>this.placeDevices(e),remove:e=>this.removeDevice(e),patchRoom:e=>this.updateRoom(e),spreadLights:e=>this.spreadCeilingLights(e),confirm:e=>confirm(e)}}furnitureToFloor(e){let[n,r]=[this._floorId,this.sel.furniture];if(!n||!r||!this.isAdmin)return;let i=structuredClone(this._doc);C_(i,n,r,e)&&(this.setDoc(i),this.adoptFloor(e),this.selectItem("furniture",r))}furnitureActions(){return{update:e=>this.updateFurniture(e),rotate:e=>this.rotateFurniture(e),duplicate:()=>this.duplicateFurniture(),remove:()=>this.deleteFurniture(),toDevice:e=>this.furnitureToDevice(e),toSpot:e=>this.vehicleToSpot(e),toFloor:e=>this.furnitureToFloor(e),packs:this.packs??[],lockButton:this.fixButton("furniture",this.sel.furniture??"")}}openingActions(){return{update:e=>this.updateOpening(e),setPreset:(e,n)=>this.setOpeningPreset(e,n),remove:()=>this.deleteOpening(),isExterior:e=>this.openingIsExterior(e),isBelowGround:e=>e.type==="window"&&this.openingIsExterior(e)&&(this.floor?.elevation??0)+e.sill<-.22,lockButton:this.fixButton("opening",this.sel.opening??"")}}makeBackground(){let e=this;return new Qo({host:this.host,refresh:()=>e.requestUpdate(),api:{fetchImage:$o,storeImage:Wt},readPicture:or,useSelectTool:()=>e._tool="select",currentTool:()=>e._tool})}makeRoof(){let e=this;return new vs({host:this.host,floorId:()=>e._floorId,setFloorId:n=>e.adoptFloor(n),confirm:n=>confirm(n),refresh:()=>e.requestUpdate()})}redrawQueued=!1;redrawSoon=()=>{this.redrawQueued||(this.redrawQueued=!0,setTimeout(()=>{this.redrawQueued=!1,this.requestUpdate()},30))};canvasContext(){return{host:this.host,toScreen:e=>this.toScreen(e),toWorld:(e,n)=>this.toWorld(e,n),scale:this._view.scale,floorId:this._floorId,redraw:this.redrawSoon}}roofDeps(){return{host:this.host,roof:this.roof,floorId:this._floorId,setFloorId:e=>this.adoptFloor(e),toggleLockPlan:()=>this.toggleLockPlan()}}makeBackup(){let e=this;return new Zo({get hass(){return e.hass},get doc(){return e._doc},t:(n,r)=>e.t(n,r),adopt:n=>{e.setDoc(n),e._editorScope=null,e.adoptFloor(n.floors[0]?.id??null),e.selectItem("room",null),e.fit()},say:n=>e.side.notice=n,refresh:()=>e.requestUpdate(),packsChanged:()=>e.dispatchEvent(new CustomEvent("packs-changed",{bubbles:!0,composed:!0}))})}makeHost(){let e=this;return{get hass(){return e.hass},get doc(){return e._doc},get floor(){return e.floor},get admin(){return e.isAdmin},t:(n,r)=>e.t(n,r),change:n=>e.change(n),replace:n=>e.setDoc(n),pickPoint:n=>e.pickPoint(n),get loadCardEditor(){return e.loadCardEditor}}}connectedCallback(){super.connectedCallback(),window.addEventListener("keydown",this.onKey)}disconnectedCallback(){super.disconnectedCallback(),window.removeEventListener("keydown",this.onKey),this.resizeObserver?.disconnect()}willUpdate(e){e.has("packs")&&Ws(this.packs??[]),e.has("_doc")&&this._split&&this.queue3d(),e.has("_split")&&this._split&&(this._doc3d=this._doc),e.has("_tool")&&this.houseTool&&!this._split&&!this.narrow&&(this._split=!0),e.has("_tool")&&(this.houseTool||e.get("_tool")==="roof"||e.get("_tool")==="energy")&&(this.reframe3d=!0),e.has("building")&&this.building!==this._doc&&(!this.tourChecked&&this.building&&(this.tourChecked=!0,!this.building.floors.some(n=>n.rooms.length)&&mb()&&(this._tour=0)),this._doc=this.building,this._doc3d=this.building,this.syncEditorContext(),this.floor?.rooms.some(n=>n.id===this.sel.room)||(this.sel.room=null)),e.has("_doc")&&this.syncEditorContext()}firstUpdated(){let e=this.renderRoot.querySelector(".nf-canvas-wrap");this.resizeObserver=new ResizeObserver(()=>{this._size={w:e.clientWidth,h:e.clientHeight},!this.fitted&&this._size.w>0&&(this.fitted=!0,this.fit())}),this.resizeObserver.observe(e)}queue3d(){clearTimeout(this.doc3dTimer),this.doc3dTimer=setTimeout(()=>this._doc3d=this._doc,150)}onSplitDown(e){let n=e.currentTarget.parentElement,r=e.currentTarget;r.setPointerCapture(e.pointerId);let i=n.getBoundingClientRect(),o=a=>{this._splitRatio=Math.min(.8,Math.max(.2,(a.clientX-i.left)/i.width))},s=()=>{r.removeEventListener("pointermove",o),r.removeEventListener("pointerup",s),r.removeEventListener("pointercancel",s);try{localStorage.setItem("nextfloor.editorSplit",String(Math.round(this._splitRatio*100)))}catch{}};r.addEventListener("pointermove",o),r.addEventListener("pointerup",s),r.addEventListener("pointercancel",s),e.preventDefault()}toggleSplit(){this._split=!this._split;try{localStorage.setItem("nextfloor.editor3d",this._split?"1":"0")}catch{}}onFurnitureMoved3d(e){let{id:n,x:r,z:i}=e.detail,o=this._doc.settings.wall_interior;this.change(s=>{for(let a of s.floors){let l=a.furniture.find(p=>p.id===n);if(!l)continue;let[c,d]=Aa(a,l.x,l.z,r,i);Object.assign(l,{x:c,z:d});let u=Nr(a,l,o);u&&Object.assign(l,u)}})}onDeviceMoved3d(e){let{id:n,x:r,z:i}=e.detail;this.change(o=>{for(let s of o.floors){let a=s.placements.find(d=>d.entity_id===n);if(!a)continue;let[l,c]=Aa(s,a.x,a.z,r,i);Object.assign(a,{x:l,z:c})}})}render3dBar(){if(!this.isAdmin)return _;let e=this.furnitureItem,n=this.device;if(e){let r=oo(e),i=(o,s,a=.05)=>m`<label class="nf-3d-size" title=${this.t(`size_${o}`)}
>${s}
<input
type="number"
inputmode="decimal"
step="0.05"
min=${a}
.value=${String(Math.round(e[o]*100)/100)}
@change=${l=>{let c=parseFloat(l.target.value.replace(",","."));Number.isFinite(c)&&c>=a&&this.updateFurniture({[o]:Math.round(c*1e3)/1e3})}}
/>
</label>`;return m`<div class="nf-3d-bar">
<span>${Te(this.hass,e.type)}</span>
${i("w",this.t("size_short_w"))} ${i("d",this.t("size_short_d"))} ${i("h",this.t("size_short_h"))}
${r?m`<label class="nf-3d-size" title=${this.t("mount_height")}
>↕
<input
type="number"
inputmode="decimal"
step="0.05"
min="0"
.value=${String(Math.round((e.mount_y??zt(this.floor,e))*100)/100)}
@change=${o=>{let s=parseFloat(o.target.value.replace(",","."));Number.isFinite(s)&&s>=0&&this.updateFurniture({mount_y:Math.round(s*1e3)/1e3})}}
/>
</label>`:_}
<button class="nf-chip" @click=${()=>this.rotateFurniture(-45)}>↺ 45°</button>
<button class="nf-chip" @click=${()=>this.rotateFurniture(45)}>↻ 45°</button>
${this.fixButton("furniture",e.id)}
<button class="nf-chip nf-danger-chip" @click=${()=>this.deleteFurniture()}>${this.t("delete")}</button>
</div>`}if(n){let r=ee(n.entity_id),i=r==="light",o=r?lo(r,this.floor?ht(this.floor,n.x,n.z):2.5,i?n.mount??"ceiling":null):1;return m`<div class="nf-3d-bar">
<span>${B(this.hass,n.entity_id)}</span>
${i?m`<select class="nf-3d-select" title=${this.t("lamp_mount")} @change=${s=>this.updateDevice({mount:s.target.value,y:null})}>
${["ceiling","floor","table","wall"].map(s=>m`<option value=${s} ?selected=${s===(n.mount??"ceiling")}>${this.t(`lamp_${s}`)}</option>`)}
</select>`:_}
<label class="nf-3d-size" title=${this.t("marker_height")}
>${this.t("size_short_h")}
<input
type="number"
inputmode="decimal"
step="0.05"
min="0"
.value=${String(Math.round((n.y??o)*100)/100)}
@change=${s=>{let a=parseFloat(s.target.value.replace(",","."));Number.isFinite(a)&&a>=0&&this.updateDevice({y:Math.round(a*1e3)/1e3})}}
/>
</label>
<button class="nf-chip" @click=${()=>this.updateDevice({rotation:(((n.rotation??0)-45)%360+360)%360})}>↺ 45°</button>
<button class="nf-chip" @click=${()=>this.updateDevice({rotation:((n.rotation??0)+45)%360%360})}>↻ 45°</button>
${this.fixButton("device",n.entity_id)}
<button class="nf-chip nf-danger-chip" @click=${()=>this.deleteItem("device",n.entity_id)}>${this.t("delete")}</button>
</div>`}return _}grab3d=null;surfaceGrabber={start:e=>this.grab3dStart(e),move:e=>this.grab3dMove(e),end:()=>{let e=this.grab3d;this.grab3d=null,e?.moved&&this.pushHistory(e.base)}};fittingField(e,n,r){if(r==="field")return e.settings.roof.solar?.find(o=>o.id===n);if(r==="win"){let o=e.settings.roof.windows?.find(s=>s.id===n);return o?_n(o):void 0}let i=e.settings.roof.chimneys?.find(o=>o.id===n);return i?St(i,Y(e).find(o=>o.key===i.face)):void 0}grab3dStart(e){let n=this._doc,r=Y(n),i=null,o=(a,l,c,d,u=!1,p=!1)=>{if(!c||u)return;let h=zo(c,e.o,e.d);!h||!Za(c,d,h.u,h.s)||i&&i.t<=h.t||(i={id:a,win:l,chimney:p,t:h.t,du:h.u-d.u,ds:h.s-d.v})};if(this._tool==="energy")for(let a of n.settings.roof.solar??[])o(a.id,!1,Se(n,a,r),a,!!a.locked);if(this._tool==="roof")for(let a of n.settings.roof.windows??[])o(a.id,!0,r.find(l=>l.key===a.face)??null,_n(a),!!a.locked);if(this._tool==="roof")for(let a of n.settings.roof.chimneys??[]){let l=r.find(c=>c.key===a.face)??null;o(a.id,!1,l,St(a,l),!!a.locked,!0)}if(!i)return!1;let s=i;return this.grab3d={id:s.id,win:s.win,chimney:s.chimney,du:s.du,ds:s.ds,base:n,moved:!1},s.chimney?this.roof.chimneyId=s.id:s.win?this.roof.windowId=s.id:this.roof.selectField(s.id),!0}grab3dMove(e){let n=this.grab3d;if(!n)return;let r=n.base,i=this.fittingField(r,n.id,n.win?"win":n.chimney?"chimney":"field");if(!i)return;let o=Se(r,i),s=o?.unbounded?[o]:n.win||n.chimney?Y(r):[...Y(r),...qe(r)],a=null;for(let p of s){let h=zo(p,e.o,e.d);h&&Ua(p,h.u,h.s)&&(!a||h.t<a.t)&&(a={face:p,...h})}if(!a)return;let l=a.face,c=.05,d=p=>We(Math.round(p/c)*c),u=mt(l,{...i,face:l.key,u:d(a.u-n.du),v:d(a.s-n.ds),tilt:l.flat?i.tilt??15:i.tilt});n.moved=!0,this.change(p=>{if(n.win||n.chimney){let f=n.win?p.settings.roof.windows?.find(g=>g.id===n.id):p.settings.roof.chimneys?.find(g=>g.id===n.id);f&&Object.assign(f,{face:l.key,...u});return}let h=p.settings.roof.solar?.find(f=>f.id===n.id);h&&Object.assign(h,{face:l.key,...u},l.flat&&h.tilt==null?{tilt:15}:{})},n.base,!1)}get houseTool(){return this._tool==="roof"||this._tool==="energy"}render3d(){return m`<div class="nf-editor-3d">
${this.houseTool?_:m`<div class="nf-seg nf-3d-walls">
<button aria-pressed=${this._wall3d==="auto"} @click=${()=>this._wall3d="auto"}>${this.t("walls_auto")}</button>
<button aria-pressed=${this._wall3d==="cut"} @click=${()=>this._wall3d="cut"}>${this.t("walls_cut")}</button>
<button aria-pressed=${this._wall3d==="slope"} title=${this.t("walls_slope_hint")} @click=${()=>this._wall3d="slope"}>${this.t("walls_slope")}</button>
<button aria-pressed=${this._solid3d} title=${this.t("walls_solid_hint")} @click=${()=>this._solid3d=!this._solid3d}>${this.t("walls_solid")}</button>
</div>`}
${this.render3dBar()}
<nf-view3d
.hass=${this.hass?Gu(Bu(this.hass,this._doc3d.floors),this._doc3d.settings):void 0}
.building=${this._doc3d}
.floorId=${this.houseTool?null:this._floorId}
.roomId=${null}
.wallMode=${this.houseTool?"auto":this._wall3d}
.solidWalls=${!this.houseTool&&this._solid3d}
.explode=${!1}
.keepRoof=${this._tool==="roof"||this._tool==="energy"}
.markerMode=${"important"}
.heatMode=${"none"}
.theme=${"neon"}
.packs=${this.packs}
.showEnergy=${!1}
.holograms=${this._tool==="energy"?!0:null}
.flows=${!1}
?furnish=${this.isAdmin}
.surfaceGrab=${this.isAdmin&&this.houseTool?this.surfaceGrabber:null}
.furnishTypes=${this._tool==="energy"?Ke:this._tool==="roof"?[]:null}
.selectedFurniture=${this.sel.furniture}
.selectedDevice=${this.sel.device}
.quality=${"auto"}
.floorThumbs=${!1}
.roomLabels=${this.roomLabels}
.floorStack=${this.houseTool?"stacked":"single"}
.panelOpen=${!1}
.alerts=${!1}
.scenes=${!1}
@furniture-select=${e=>{e.detail.id?this.selectFrom3d("furniture",e.detail.id):this.sel.furniture&&this.selectFrom3d("furniture",null)}}
@furniture-move=${this.onFurnitureMoved3d}
@device-select=${e=>{e.detail.id?this.selectFrom3d("device",e.detail.id):this.sel.device&&this.selectFrom3d("device",null)}}
@device-move=${this.onDeviceMoved3d}
@floor-tap=${e=>{e.detail.floorId&&this.adoptFloor(e.detail.floorId),this._sideOpen=!1}}
@room-tap=${e=>{e.detail.floorId&&this.adoptFloor(e.detail.floorId),e.detail.roomId?this.selectFrom3d("room",e.detail.roomId):this._sideOpen=!1}}
></nf-view3d>
</div>`}updated(){for(let n of this.renderRoot.querySelectorAll("select option[selected]"))n.selected||(n.selected=!0);this.reframe3d&&(this.reframe3d=!1,setTimeout(()=>this.renderRoot.querySelector("nf-view3d")?.resetView(),250));let e=this.floor?.background;if(e&&this.bg.ensureLoaded(e.image_id),this.furnitureItem?.pictures)for(let n of this.storedPictures())this.bg.ensureLoaded(n)}clearPlanSelection(){this.cancelPick(),this.selectItem("room",null),this._note=null,this._draft=[],this._cursor=null,this._ctx=null,this._wallView=null,this.drag=null,this._fixedHint=!1,this.side.floorCopy=null,this.side.floorMenu=!1,this.side.shiftX=0,this.side.shiftZ=0}syncEditorContext(){let e=Lc(this._doc,{scope:this._editorScope,floorId:this._floorId});e.floorId===this._floorId&&An(e.scope)===An(this._editorScope)||(this._editorScope=e.scope,this._floorId=e.floorId,this.clearPlanSelection())}adoptFloor(e){let n=e?this._doc.floors.find(r=>r.id===e):void 0;e&&!n||(this._floorId=n?.id??null,n&&(this._editorScope=this._doc.topology?As(n):null),this.clearPlanSelection())}selectBuilding(e){let n=zs(this._doc,An(e));if(!n)return;let r=Hc(this._doc,n);this._editorScope=r.scope,this._floorId=r.floorId,this.clearPlanSelection(),this.fit()}openHierarchy(){let e=this.renderRoot.querySelector(".nf-hierarchy-dialog");e&&!e.open&&e.showModal()}async openFloorMove(){if(!this.isAdmin||!this.floor||this.floor.outdoor_location_id||!this._doc.topology)return;this._floorMove={floorId:this.floor.id,targetId:""},await this.updateComplete;let e=this.renderRoot.querySelector(".nf-floor-move-dialog");e&&!e.open&&e.showModal()}applyFloorMove(){if(!this.isAdmin||!this._floorMove)return;let{floorId:e,targetId:n}=this._floorMove,r=structuredClone(this._doc);Cc(r,this.floor?.id??null,e,n)&&(this.setDoc(r),this.adoptFloor(e),this.fit(),this.renderRoot.querySelector(".nf-floor-move-dialog")?.close())}renderEditorNavigation(){if(!this._doc.topology)return Z(this.hass)?m`<div class="nf-editor-context"><button class="nf-btn nf-hierarchy-open" @click=${()=>this.openHierarchy()}>Hierarchie</button></div>`:_;let e=this._editorScope,n=Ts(this._doc),r=$r(this._doc,e),i=n.find(([o])=>o===An(e))?.[1]??"Geb\xE4ude ausw\xE4hlen";return m`<div class="nf-editor-context">
<div class="nf-editor-building-row"><label>Gebäude<select class="nf-editor-building-select" aria-label="Gebäude" title=${i} @change=${o=>{let s=zs(this._doc,o.target.value);s&&this.selectBuilding(s)}}>
${e?_:m`<option value="">Gebäude auswählen</option>`}
${n.map(([o,s])=>m`<option value=${o} .selected=${o===An(e)}>${s}</option>`)}
</select></label><button class="nf-btn nf-hierarchy-open" @click=${()=>this.openHierarchy()}>Hierarchie</button></div>
<nav class="nf-editor-floor-nav" aria-label="Etagen des gewählten Gebäudes">
<span class="nf-muted">${e?.kind==="outside"?"Au\xDFenplan":"Etagen"}</span>
${[...r].reverse().map(o=>m`<button class="nf-chip" data-editor-floor=${o.id} aria-pressed=${o.id===this._floorId} @click=${()=>{this.adoptFloor(o.id),this.fit()}}>${o.name}</button>`)}
${e?.kind==="building"?m`<button class="nf-btn nf-editor-add-floor" ?disabled=${!this.isAdmin} @click=${()=>this.addFloor(null)}>+ Etage</button>`:_}
${this.floor&&!this.floor.outdoor_location_id?m`<button class="nf-link nf-editor-move-floor" ?disabled=${!this.isAdmin} @click=${()=>{this.openFloorMove()}}>Ausgewählte Etage verschieben…</button>`:_}
</nav>
</div>`}renderHierarchyDialogs(){let e=this._floorMove,n=e?this._doc.floors.find(i=>i.id===e.floorId):void 0,r=Ts(this._doc).filter(([i])=>i.startsWith("building:")&&i!==`building:${n?.building_id}`);return m`<dialog class="nf-hierarchy-dialog" aria-label="Hierarchie verwalten" @keydown=${i=>i.stopPropagation()}>
<header><h2>Hierarchie verwalten</h2><button class="nf-btn" aria-label="Schließen" @click=${()=>this.renderRoot.querySelector(".nf-hierarchy-dialog")?.close()}>×</button></header>
<nf-hierarchy-manager .doc=${this._doc} .admin=${this.isAdmin} .suggestedName=${this.hass?.symconTitle?.trim()||"Geb\xE4ude 1"}
@hierarchy-change=${i=>{i.stopPropagation(),this.isAdmin&&this.setDoc(i.detail.building)}}
@hierarchy-open=${i=>{i.stopPropagation(),this.selectBuilding(i.detail),this.renderRoot.querySelector(".nf-hierarchy-dialog")?.close()}}></nf-hierarchy-manager>
</dialog>
<dialog class="nf-floor-move-dialog" aria-label="Ausgewählte Etage verschieben" @close=${()=>this._floorMove=null} @keydown=${i=>i.stopPropagation()}>
<header><h2>Ausgewählte Etage verschieben</h2><button class="nf-btn" aria-label="Schließen" @click=${()=>this.renderRoot.querySelector(".nf-floor-move-dialog")?.close()}>×</button></header>
${e&&n?m`<p class="nf-floor-move-source">${Pr(this._doc,n)}</p>
<label class="nf-field">Zielgebäude<select class="nf-floor-move-target" @change=${i=>this._floorMove={...e,targetId:i.target.value}}>
<option value="" .selected=${!e.targetId}>Zielgebäude auswählen</option>
${r.map(([i,o])=>m`<option value=${i.slice(9)} .selected=${e.targetId===i.slice(9)}>${o}</option>`)}
</select></label>
<button class="nf-btn nf-primary nf-floor-move-apply" ?disabled=${!this.isAdmin||!e.targetId||n.id!==this.floor?.id||!r.some(([i])=>i===`building:${e.targetId}`)} @click=${()=>this.applyFloorMove()}>Etage „${n.name}“ verschieben</button>`:_}
</dialog>`}get floor(){return this._doc?.floors.find(e=>e.id===this._floorId)}get room(){return this.floor?.rooms.find(e=>e.id===this.sel.room)}get isAdmin(){return this.hass?.user?.is_admin??!0}setDoc(e,n=this._doc){n&&this.history.record(n),e.topology&&Xi(e),this._doc=e,this.syncEditorContext(),this.syncHistoryButtons(),this.dispatchEvent(new CustomEvent("building-changed",{detail:{building:e},bubbles:!0,composed:!0}))}change(e,n=this._doc,r=!0){let i=structuredClone(n),o=i.floors.find(s=>s.id===this._floorId);!o&&this._floorId||(e(i,o),this.setDoc(i,r?n:null))}syncHistoryButtons(){this._canUndo=this.history.canUndo,this._canRedo=this.history.canRedo}undo(){let e=this.history.undo(this._doc);e&&this.restore(e)}redo(){let e=this.history.redo(this._doc);e&&this.restore(e)}restore(e){this._doc=e,this.syncEditorContext(),this.floor?.rooms.some(n=>n.id===this.sel.room)||(this.sel.room=null),this.sel.corner=null,this.syncHistoryButtons(),this.dispatchEvent(new CustomEvent("building-changed",{detail:{building:e},bubbles:!0,composed:!0}))}toScreen(e){let{scale:n,ox:r,oy:i}=this._view;return[e[0]*n+r,e[1]*n+i]}pickPoint(e){this._pick?.(null),this._pick=e,clearTimeout(this._pickTimer),this._pickTimer=window.setTimeout(()=>this.cancelPick(),6e4),this.requestUpdate()}cancelPick(){clearTimeout(this._pickTimer),this._pick&&(this._pick=null,this.requestUpdate())}toWorld(e,n){let{scale:r,ox:i,oy:o}=this._view;return[(e-i)/r,(n-o)/r]}localPoint(e){let n=this.renderRoot.querySelector("svg").getBoundingClientRect();return[e.clientX-n.left,e.clientY-n.top]}fit(){let e=this.floor?.rooms.flatMap(a=>a.points)??[],n=e.length?ue(e):{x0:0,z0:0,x1:10,z1:8},r=1.5,i=n.x1-n.x0+2*r,o=n.z1-n.z0+2*r,s=Math.max(8,Math.min(400,Math.min(this._size.w/i,this._size.h/o)));this._view={scale:s,ox:this._size.w/2-(n.x0+n.x1)/2*s,oy:this._size.h/2-(n.z0+n.z1)/2*s}}showPoint(e,n){let r=Math.max(this._view.scale,70);this._view={scale:r,ox:this._size.w/2-e*r,oy:this._size.h/2-n*r}}zoomAt(e,n,r){let{scale:i,ox:o,oy:s}=this._view,a=Math.max(8,Math.min(600,i*e)),l=a/i;this._view={scale:a,ox:n-(n-o)*l,oy:r-(r-s)*l}}snap(e,n,r=!1,i=!1){if(this._guides={},r)return e;let o=eg(e,{rooms:this.floor?.rooms??[],outdoor:i?this.floor?.outdoor:void 0,grid:this._doc.settings.grid,reach:Li/this._view.scale,skip:n});return this._guides=o.guides,o.point}onPointerDown(e){if(this._pick){let[r,i]=this.localPoint(e),o=this._pick;this.cancelPick(),o(this.toWorld(r,i));return}this._ctx=null;let n=e.target?.closest?.("[data-note]")?.getAttribute("data-note");if(n&&this._tool==="select"){this._note=n,this._sideOpen=!0;return}if(this._note&&(this._note=null),this._fixedHint=!1,this.fixedPan=!1,this.pointerDown(e),this.pointers.size!==1){clearTimeout(this.pressTimer);return}if(this.guardFixed(this.localPoint(e)),clearTimeout(this.pressTimer),this.pressStart=null,e.pointerType==="touch"&&(this._tool==="select"||this._tool==="furniture")){let r=this.localPoint(e),i=e.target;this.pressStart=r,this.pressTimer=window.setTimeout(()=>{let o=this.drag;o&&"moved"in o&&o.moved||(this.drag=null,this.openContext(i,r))},550)}}guardFixed(e){let n=this.drag;if(!n)return;let r=null;n.kind==="vertex"||n.kind==="room"?r=["room",n.roomId]:n.kind==="device"||n.kind==="aim"?r=["device",n.entityId]:n.kind==="opening"?r=["opening",n.id]:n.kind==="furniture"||n.kind==="rotate"||n.kind==="resize"?r=["furniture",n.id]:n.kind==="wallmove"?r=["wall",n.id]:n.kind==="outdoor"&&(r=["outdoor",n.id]),!(!r||!this.isFixedItem(...r))&&("moved"in n&&n.moved&&"base"in n&&this.restoreLive(n.base),this.drag={kind:"pan",last:e},this.fixedPan=!0)}pointerDown(e){e.currentTarget.setPointerCapture(e.pointerId);let n=this.localPoint(e);if(this.pointers.set(e.pointerId,n),this.pointers.size===2){let o=this.drag;o&&Fb.has(o.kind)&&"moved"in o&&o.moved&&"base"in o&&this.restoreLive(o.base),this.drag=null,this.pinch=this.pinchState();return}if(this.pointers.size>2)return;if(e.button===1||e.button===2||!this.floor){this.drag={kind:"pan",last:n};return}let r={local:n,world:this.toWorld(...n),target:e.target,fine:e.altKey},i=this.pressRoute(r)??this.pressBackground(r)??this.pressWallTool(r)??this.pressRoofTools(r)??this.pressDrawingTool(r)??this.pressItem(r)??this.pressRoom(r);i!==Hi&&(this.drag=i)}pan(e){return{kind:"pan",last:e.local}}moves(e,n){return this.isAdmin?n:this.pan(e)}pressBackground(e){let{world:n,target:r}=e,i=this.floor?.background;if(this.bg.level&&this.isAdmin&&i)return this.bg.tapLevel(n),Hi;if(this.bg.handlesShown&&i&&r.closest("[data-bg-rotate]")){let s=ir(i,this.bg.picture(i.image_id)?.aspect??1);return{kind:"bgrotate",base:this._doc,moved:!1,start:Math.atan2(n[1]-s[1],n[0]-s[0]),rot:i.rotation??0}}if(this.bg.ruler&&this.bg.ruler.length<2&&this.isAdmin&&i)return this.bg.tapRuler(n),Hi;let o=!!r.closest("[data-bg-handle]")||!!r.closest("[data-bg]");if(i&&this.bg.handlesShown&&!this.bg.edit&&o)return this.pictureGesture(e,i);if(this.bg.edit&&this.isAdmin&&i){if(o)return this.pictureGesture(e,i);this.bg.edit=!1}}pictureGesture(e,n){return e.target.closest("[data-bg-handle]")?{kind:"bgscale",base:this._doc,moved:!1}:{kind:"bgmove",start:e.world,bx:n.x,bz:n.z,base:this._doc,moved:!1}}pressWallTool(e){if(this._tool!=="wall")return;let n=this.snap(e.world,void 0,e.fine);return{kind:"freewall",start:n,end:n}}pressRoofTools(e){if(this._tool!=="roof"&&this._tool!=="energy")return;let{local:n,world:r,target:i}=e,o=(v,w)=>i.closest(v)?.getAttribute(w)??null,s=this._tool==="energy",a=s?o("[data-energy-device]","data-energy-device"):null;if(a)return this.pressEnergyDevice(e,a);let l=s?o("[data-solar-turn]","data-solar-turn"):null;if(l&&this.isAdmin)return{kind:"solarturn",id:l,base:this._doc,moved:!1};let c=s?o("[data-solar]","data-solar"):null;if(c)return this.pressSolarField(e,c);let d=this._tool==="roof"?o("[data-roofwin]","data-roofwin"):null;if(d)return this.pressRoofWindow(e,d);let u=this._tool==="roof"?o("[data-chimney]","data-chimney"):null;if(u)return this.pressChimney(e,u);this._tool==="roof"&&(this.roof.windowId=null,this.roof.chimneyId=null);let p=s?o(".nf-energy-item","data-furniture"):null;if(p)return this.pressEnergyDevice(e,p);if(s)return this.selectItem("furniture",null),this.roof.solarId=null,this.pan(e);let h=o("[data-plus]","data-plus");if(h?.startsWith("roof:")&&this.isAdmin)return this.splitRoofEdgeGesture(...h.split(":").slice(1));let f=o("[data-roof-vertex]","data-roof-vertex"),g=o("[data-roof-corner]","data-roof-corner"),b=o("[data-roof]","data-roof");if(f&&this.isAdmin){let[v,w]=f.split(":");return{kind:"roofvertex",id:v,index:Number(w),base:this._doc,moved:!1}}if(g&&this.isAdmin){let[v,w,k]=g.split(":");return{kind:"roofcorner",id:v,corner:[w==="1"?1:0,k==="1"?1:0],base:this._doc,moved:!1}}if(b){let v=this.roof.isFixed(this._doc.settings.roof.sections?.find(w=>w.id===b));return v&&this.roof.sectionId===b&&(this._fixedHint=!0),this.roof.sectionId=b,this.isAdmin&&!v?{kind:"roofmove",id:b,start:r,startScreen:n,base:this._doc,moved:!1}:this.pan(e)}if(!this.isAdmin)return this.pan(e);this.roof.sectionId=null;let y=this.snap(r,void 0,e.fine);return{kind:"rect",start:y,end:y,roof:!0}}pressEnergyDevice(e,n){return this.roof.solarId=null,this.selectItem("furniture",n),this.moves(e,{kind:"furniture",id:n,start:e.world,startScreen:e.local,base:this._doc,moved:!1})}pressSolarField(e,n){let{local:r,world:i,target:o}=e,s=o.closest("[data-cell]")?.getAttribute("data-cell");if(this.roof.picking&&n===this.roof.solarId&&s&&this.isAdmin)return this.roof.toggleCell(s),this.pan(e);n!==this.roof.solarId&&(this.roof.picking=!1),this.roof.solarId=n,this.roof.sectionId=null;let a=this._doc.settings.roof.solar?.find(u=>u.id===n),l=a?Se(this._doc,a)??void 0:void 0,c=l?this.faceHit(l,i):null,d=a&&c?{du:c.u-a.u,ds:Number.isNaN(c.s)?0:c.s-a.v}:null;return this.isAdmin&&!a?.locked?{kind:"solarmove",id:n,start:i,startScreen:r,base:this._doc,moved:!1,grab:d}:this.pan(e)}pressRoofWindow(e,n){this.roof.windowId=n,this.roof.sectionId=null;let r=this._doc.settings.roof.windows?.find(a=>a.id===n),i=r?Y(this._doc).find(a=>a.key===r.face):void 0,o=i?qn(i,e.world):null,s=r&&o?{du:o.u-r.u,ds:o.s-r.v}:null;return this.isAdmin&&!r?.locked?{kind:"solarmove",id:n,start:e.world,startScreen:e.local,base:this._doc,moved:!1,grab:s,win:!0}:this.pan(e)}pressChimney(e,n){this.roof.chimneyId=n,this.roof.sectionId=null;let r=this._doc.settings.roof.chimneys?.find(a=>a.id===n),i=r?Y(this._doc).find(a=>a.key===r.face):void 0,o=i?qn(i,e.world):null,s=r&&o?{du:o.u-r.u,ds:o.s-r.v}:null;return this.isAdmin&&!r?.locked?{kind:"solarmove",id:n,start:e.world,startScreen:e.local,base:this._doc,moved:!1,grab:s,chimney:!0}:this.pan(e)}pressDrawingTool(e){let n=this._tool;if(n==="rect"||n==="outdoor"||n==="hole"||n==="stairs"){let r=this.snap(e.world,void 0,e.fine,n==="outdoor");return{kind:"rect",start:r,end:r,outdoor:n==="outdoor",hole:n==="hole",stairs:n==="stairs"}}if(n==="polygon"||n==="measure")return{kind:"tap",startScreen:e.local,last:e.local,panning:!1};if(n==="opening")return this.placeOpening(this._openingPreset,e.local)?Hi:this.pan(e)}pressItem(e){let{local:n,world:r,target:i}=e,o=(k,x)=>i.closest(k)?.getAttribute(x)??null,s=this._doc,a=o("[data-device]","data-device");if(a&&this.isAdmin)return{kind:"device",entityId:a,start:r,startScreen:n,base:s,moved:!1};let l=o("[data-opening]","data-opening");if(l)return this.selectItem("opening",l),this.moves(e,{kind:"opening",id:l,startScreen:n,base:s,moved:!1});let c=o("[data-resize]","data-resize");if(c&&this.isAdmin){let[k,x,M]=c.split(":");return{kind:"resize",id:k,corner:[x==="1"?1:-1,M==="1"?1:-1],base:s,moved:!1}}let d=o("[data-rotate]","data-rotate");if(d&&this.isAdmin)return{kind:"rotate",id:d,base:s,moved:!1};let u=o("[data-aim]","data-aim");if(u&&this.isAdmin)return{kind:"aim",entityId:u,base:s,moved:!1};let p=i.closest("[data-vertex], [data-mid]")?null:o("[data-furniture]","data-furniture");if(p)return this.selectItem("furniture",p),this.moves(e,{kind:"furniture",id:p,start:r,startScreen:n,base:s,moved:!1});let h=o("[data-vertex]","data-vertex"),f=o("[data-mid]","data-mid");if(h!==null&&this.room&&this.isAdmin)return this.sel.corner=Number(h),{kind:"vertex",roomId:this.room.id,index:this.sel.corner,base:s,moved:!1};if(f!==null&&this.room&&this.isAdmin)return this.splitEdgeGesture(this.room,Number(f));let g=o("[data-wall-end]","data-wall-end");if(g&&this.isAdmin){let[k,x]=g.split(":");return{kind:"wallmove",id:k,end:x,start:r,startScreen:n,base:s,moved:!1}}let b=o("[data-free-wall]","data-free-wall");if(b)return this.selectItem("wall",b),this.moves(e,{kind:"wallmove",id:b,end:null,start:r,startScreen:n,base:s,moved:!1});let y=o("[data-plus]","data-plus");if(y?.startsWith("out:")&&this.isAdmin)return this.splitOutdoorEdgeGesture(...y.split(":").slice(1));let v=o("[data-out-vertex]","data-out-vertex");if(v&&this.isAdmin){let[k,x]=v.split(":");return{kind:"outvertex",id:k,index:Number(x),base:s,moved:!1}}let w=o("[data-outdoor]","data-outdoor");if(w&&!i.closest("[data-room]")&&!this.roomAt(r))return this.selectItem("outdoor",w),this.moves(e,{kind:"outdoor",id:w,start:r,startScreen:n,base:s,moved:!1})}splitEdgeGesture(e,n){let[r,i]=[e.points[n],e.points[(n+1)%e.points.length]],o=et([(r[0]+i[0])/2,(r[1]+i[1])/2],[0,0]),s=this._doc;return this.change((a,l)=>Ql(l,e.id,n,o),s,!1),this.sel.corner=n+1,{kind:"vertex",roomId:e.id,index:n+1,base:s,moved:!0}}splitOutdoorEdgeGesture(e,n){let r=Number(n),i=this._doc,o=this.floorOf({base:i})?.outdoor.find(l=>l.id===e);if(!o)return;let[s,a]=[o.points[r],o.points[(r+1)%o.points.length]];return this.change((l,c)=>Nf(c.outdoor.find(d=>d.id===e),r,[(s[0]+a[0])/2,(s[1]+a[1])/2]),i,!1),{kind:"outvertex",id:e,index:r+1,base:i,moved:!0}}splitRoofEdgeGesture(e,n){let r=Number(n),i=this._doc;return this.change(o=>{let s=o.settings.roof.sections?.find(d=>d.id===e);if(!s)return;let a=zl(s),[l,c]=[a[r],a[(r+1)%a.length]];im(s,r,[(l[0]+c[0])/2,(l[1]+c[1])/2])},i,!1),{kind:"roofvertex",id:e,index:r+1,base:i,moved:!0}}pressRoom(e){let n=e.target.closest("[data-room]")?.getAttribute("data-room")??this.roomAt(e.world);return n?(n!==this.sel.room&&(this.sel.corner=null),this.selectItem("room",n),!this.isAdmin||this._tool==="furniture"?this.pan(e):{kind:"room",roomId:n,start:e.world,startScreen:e.local,base:this._doc,moved:!1}):(this.selectItem("room",null),this.pan(e))}onPointerMove(e){let n=this.localPoint(e);if(this.pressStart?ar(n,this.pressStart,8)&&(clearTimeout(this.pressTimer),this.pressStart=null,this.fixedPan&&(this._fixedHint=!0)):this.fixedPan&&!this._fixedHint&&this.drag?.kind==="pan"&&(this._fixedHint=!0),this.pointers.has(e.pointerId)&&this.pointers.set(e.pointerId,n),this.pinch){this.pinchMove();return}let r=this.toWorld(...n),i=this.drag;if(!i){this._tool!=="select"&&this._tool!=="furniture"&&this.floor&&(this._cursor=this.snap(r,void 0,e.altKey,this._tool==="outdoor"));return}this.moveDrag(i,{local:n,world:r,fine:e.altKey,straight:e.shiftKey})}pinchMove(){let e=this.pinchState();!e||!this.pinch||(this.zoomAt(e.dist/Math.max(1,this.pinch.dist),...e.mid),this._view={...this._view,ox:this._view.ox+e.mid[0]-this.pinch.mid[0],oy:this._view.oy+e.mid[1]-this.pinch.mid[1]},this.pinch=e)}panBy(e,n){this._view={...this._view,ox:this._view.ox+n[0]-e[0],oy:this._view.oy+n[1]-e[1]}}live(e,n){this.change(n,e.base,!1)}floorOf(e){return e.base.floors.find(n=>n.id===this._floorId)}moveDrag(e,n){let{local:r,world:i,fine:o}=n,s=this._doc.settings.grid,a=l=>l.moved||ar(r,l.startScreen);switch(e.kind){case"pan":this.panBy(e.last,r),e.last=r;return;case"tap":(e.panning||ar(r,e.startScreen,6))&&(e.panning=!0,this.panBy(e.last,r)),e.last=r;return;case"rect":e.end=this.snap(i,void 0,o,!!e.outdoor),this.requestUpdate();return;case"freewall":e.end=Xm(e.start,this.snap(i,void 0,o),n.straight),this.requestUpdate();return;case"wallmove":{if(!a(e))return;e.moved=!0;let l=(this.floorOf(e)?.walls??[]).find(d=>d.id===e.id);if(!l)return;let c;if(e.end){let d=this.snap(i,void 0,o);c=e.end==="a"?{a:d,b:l.b}:{a:l.a,b:d}}else{let d=ds(e.start,i,Sn(s,o));c={a:et(l.a,d),b:et(l.b,d)}}this.live(e,(d,u)=>Object.assign((u.walls??[]).find(p=>p.id===e.id),c));return}case"vertex":{let l=this.snap(i,{roomId:e.roomId,index:e.index},o);e.moved=!0,this.live(e,(c,d)=>{d.rooms.find(u=>u.id===e.roomId).points[e.index]=l});return}case"room":{if(!a(e))return;e.moved=!0;let l=this.floorOf(e),c=l?.rooms.find(p=>p.id===e.roomId);if(!l||!c)return;let d=this.roomDelta(c,[i[0]-e.start[0],i[1]-e.start[1]],o),u=new Set(l.placements.filter(p=>C([p.x,p.z],c.points)).map(p=>p.entity_id));this.live(e,(p,h)=>{h.rooms.find(f=>f.id===e.roomId).points=c.points.map(f=>et(f,d)),h.placements=l.placements.map(f=>{if(!u.has(f.entity_id))return f;let[g,b]=et([f.x,f.z],d);return{...f,x:g,z:b}})});return}case"opening":{if(!a(e))return;e.moved=!0;let l=this.floorOf(e),c=l?.openings.find(f=>f.id===e.id),d=c&&l?Ne(c,l.rooms,l.walls??[]):null;if(!c||!d)return;let u=l?Gt(l.openings,c):[c],p=!c.wall&&u.length>1&&l?Xn(d.room,u):null;if(p){let f=o?.01:this._doc.settings.grid,g=Ja(d.room,i)-p.width/2,b=f>0?Math.round(g/f)*f:g,y=Math.max(0,Math.min(li(d.room)-p.width,b));this.live(e,(v,w)=>{let k=w.openings.find(M=>M.id===e.id),x=k?ci(w.openings,d.room,k,y,p.width,()=>P("opening")):null;x&&(w.openings=x)});return}let h=this.dropOffset(d.room,d.edge,i,c.width,o);this.live(e,(f,g)=>{g.openings.find(b=>b.id===e.id).offset=h});return}case"furniture":{if(!a(e))return;e.moved=!0;let l=this.floorOf(e)?.furniture.find(h=>h.id===e.id);if(!l)return;let[c,d]=ec([l.x,l.z],e.start,i,Sn(s,o)),p=(o?null:this.snapToWall({...l,x:c,z:d}))??{x:c,z:d,rotation:l.rotation};this.live(e,(h,f)=>{Object.assign(f.furniture.find(g=>g.id===e.id),p)});return}case"resize":{e.moved=!0;let l=this.floorOf(e)?.furniture.find(d=>d.id===e.id);if(!l)return;let c=Kd(l,e.corner,i,Sn(s,o));this.live(e,(d,u)=>{Object.assign(u.furniture.find(p=>p.id===e.id),c)});return}case"rotate":{e.moved=!0;let l=this.floorOf(e)?.furniture.find(d=>d.id===e.id);if(!l)return;let c=tc([l.x,l.z],i,o?1:15);this.live(e,(d,u)=>{u.furniture.find(p=>p.id===e.id).rotation=c});return}case"aim":{e.moved=!0;let l=this.floorOf(e)?.placements.find(d=>d.entity_id===e.entityId);if(!l)return;let c={rotation:tc([l.x,l.z],i,o?1:5)};this.live(e,(d,u)=>{Object.assign(u.placements.find(p=>p.entity_id===e.entityId),c)});return}case"device":{if(!a(e))return;e.moved=!0;let l=this.floorOf(e)?.placements.find(u=>u.entity_id===e.entityId);if(!l)return;let[c,d]=ec([l.x,l.z],e.start,i,Sn(s,o));this.live(e,(u,p)=>{Object.assign(p.placements.find(h=>h.entity_id===e.entityId),{x:c,z:d})});return}case"outdoor":{if(!a(e))return;e.moved=!0;let l=this.floorOf(e)?.outdoor.find(p=>p.id===e.id);if(!l)return;let c=this.floorOf(e),d=o?{by:ds(e.start,i,Sn(s,!0)),guides:{}}:tg(l.points,[i[0]-e.start[0],i[1]-e.start[1]],{rooms:c.rooms,outdoor:c.outdoor,grid:s,reach:Li/this._view.scale,skip:{outdoorId:e.id}}),{by:u}=d;this._guides=d.guides,this.live(e,(p,h)=>{h.outdoor.find(f=>f.id===e.id).points=l.points.map(f=>et(f,u))});return}case"outvertex":{e.moved=!0;let l=this.snap(i,{outdoorId:e.id},o,!0),c=this.floorOf(e)?.outdoor.find(d=>d.id===e.id);if(!c)return;this.live(e,(d,u)=>{let p=u.outdoor.find(h=>h.id===e.id);p&&(p.points=Qm(c.points,e.index,l))});return}case"bgmove":e.moved=!0,this.live(e,(l,c)=>{c.background&&([c.background.x,c.background.z]=et([e.bx,e.bz],[i[0]-e.start[0],i[1]-e.start[1]]))});return;case"bgrotate":{e.moved=!0;let l=this.floor?.background,c=l?this.bg.picture(l.image_id):void 0;if(!l||!c)return;let d=ir(l,c.aspect),u=$f(e.rot,e.start,Math.atan2(i[1]-d[1],i[0]-d[0]),n.straight);this.live(e,(p,h)=>{h.background&&(h.background.rotation=u)});return}case"bgscale":{e.moved=!0;let l=this.floor?.background,c=l?this.bg.picture(l.image_id):void 0;if(!l||!c)return;let d=Math.max(.5,We(kf(l,c.aspect,i)[0]));this.live(e,(u,p)=>{p.background&&(p.background.width=d)});return}default:this.moveRoofDrag(e,n)}}moveRoofDrag(e,n){let{local:r,world:i,fine:o}=n,s=this._doc.settings.grid;switch(e.kind){case"roofmove":{if(!e.moved&&!ar(r,e.startScreen))return;e.moved=!0;let a=ds(e.start,i,Sn(s,o)),l=e.base.settings.roof.sections?.find(c=>c.id===e.id);if(!l)return;this.live(e,c=>{let d=c.settings.roof.sections?.find(g=>g.id===e.id);if(!d)return;let[u,p]=et([l.x0,l.z0],a),[h,f]=et([l.x1,l.z1],a);Object.assign(d,{x0:u,x1:h,z0:p,z1:f}),l.points&&(d.points=l.points.map(g=>et(g,a)))});return}case"roofvertex":{e.moved=!0;let a=this.snap(i,void 0,o);this.live(e,l=>{let c=l.settings.roof.sections?.find(d=>d.id===e.id);!c?.points||e.index>=c.points.length||(c.points[e.index]=et(a,[0,0]),Object.assign(c,jt(c.points)))});return}case"roofcorner":{e.moved=!0;let a=this.snap(i,void 0,o);this.live(e,l=>{let c=l.settings.roof.sections?.find(d=>d.id===e.id);c&&(c[e.corner[0]?"x1":"x0"]=We(a[0]),c[e.corner[1]?"z1":"z0"]=We(a[1]))});return}case"solarturn":{e.moved=!0;let a=e.base.settings.roof.solar?.find(d=>d.id===e.id),l=a?Se(e.base,a):null;if(!a||!l)return;let c=ii(e.base,a,Jm(ei(l,a),i,o?1:15));this.live(e,d=>{let u=d.settings.roof.solar?.find(p=>p.id===e.id);u&&Object.assign(u,c)});return}case"solarmove":this.moveSolar(e,n);return;default:return}}moveSolar(e,n){let{local:r,world:i,fine:o}=n;if(!e.moved&&!ar(r,e.startScreen))return;e.moved=!0;let s=this.fittingField(e.base,e.id,e.win?"win":e.chimney?"chimney":"field"),a=e.win||e.chimney?Y(e.base):[...Y(e.base),...this._floorId?qe(e.base,this._floorId):[]],l=s?Se(e.base,s,a):null;if(!s||!l)return;let c=o?.01:.05,d=b=>We(Math.round(b/c)*c),u=l.unbounded?null:Ga(a,i),p=l,h,f;if(u&&e.grab)p=u.face,h=d(u.u-e.grab.du),f=Number.isNaN(u.s)?u.face.key===s.face?s.v:Math.max(0,u.face.ls-1.5):d(u.s-e.grab.ds);else{let[b,y]=[i[0]-e.start[0],i[1]-e.start[1]],v=[l.es[0],l.es[2]];h=d(s.u+b*l.eu[0]+y*l.eu[2]),f=d(s.v+(b*v[0]+y*v[1])/(v[0]*v[0]+v[1]*v[1]||1))}let g=mt(p,{...s,face:p.key,u:h,v:f,tilt:p.flat?s.tilt??15:s.tilt});this.live(e,b=>{if(e.win||e.chimney){let v=e.win?b.settings.roof.windows?.find(w=>w.id===e.id):b.settings.roof.chimneys?.find(w=>w.id===e.id);v&&Object.assign(v,{face:p.key,...g});return}let y=b.settings.roof.solar?.find(v=>v.id===e.id);y&&Object.assign(y,{face:p.key,...g},p.flat&&y.tilt==null?{tilt:15}:{})})}onPointerUp(e){if(clearTimeout(this.pressTimer),this.pressStart=null,this.fixedPan=!1,this.pointers.delete(e.pointerId),this.pinch){this.pointers.size<2&&(this.pinch=null);return}let n=this.drag;if(this.drag=null,!n||e.type==="pointercancel"){n&&Fb.has(n.kind)&&"moved"in n&&n.moved&&"base"in n&&this.restoreLive(n.base);return}let r=this.localPoint(e);switch(n.kind){case"freewall":{Math.hypot(n.end[0]-n.start[0],n.end[1]-n.start[1])>=.2&&this.addFreeWall(n.start,n.end),this._guides={};break}case"wallmove":n.moved&&this.pushHistory(n.base),this._guides={};break;case"rect":{let[i,o]=n.start,[s,a]=n.end;if(Math.abs(s-i)>=.2&&Math.abs(a-o)>=.2){let l=[Math.min(i,s),Math.min(o,a)],c=[Math.max(i,s),Math.max(o,a)],d=[l,[c[0],l[1]],c,[l[0],c[1]]];n.outdoor?this.addOutdoor(d):n.hole?this.addHole(l,c):n.stairs?this.addStairs(l,c):n.roof?this.roof.addSection(l,c):this.addRoom(d)}this._guides={};break}case"tap":if(n.panning)break;this._tool==="measure"?this._draft=[this.snap(this.toWorld(...r),void 0,e.altKey)]:this.addDraftPoint(this.snap(this.toWorld(...r),void 0,e.altKey),r);break;case"opening":case"furniture":case"rotate":case"aim":case"resize":case"outdoor":case"solarmove":case"solarturn":case"roofmove":case"roofcorner":case"roofvertex":case"bgmove":case"bgscale":case"bgrotate":n.moved&&this.pushHistory(n.base);break;case"device":n.moved?this.pushHistory(n.base):this.selectItem("device",n.entityId);break;case"vertex":case"room":n.moved&&this.pushHistory(n.base),this._guides={};break;default:break}}onWheel(e){e.preventDefault();let[n,r]=this.localPoint(e);this.zoomAt(Math.exp(-e.deltaY*(e.deltaMode===1?.05:.0015)),n,r)}pinchState(){let e=[...this.pointers.values()];if(e.length<2)return null;let[n,r]=e;return{dist:Math.hypot(n[0]-r[0],n[1]-r[1]),mid:[(n[0]+r[0])/2,(n[1]+r[1])/2]}}pushHistory(e){this.history.record(e),this.syncHistoryButtons()}restoreLive(e){this._doc=e,this.dispatchEvent(new CustomEvent("building-changed",{detail:{building:e},bubbles:!0,composed:!0}))}roomDelta(e,n,r){if(r)return n;let i=this._doc.settings.grid,o=[Math.round(n[0]/i)*i,Math.round(n[1]/i)*i],a=Li/this._view.scale;this._guides={};for(let l of this.floor?.rooms??[])if(l.id!==e.id)for(let c of l.points)for(let d of e.points){let u=Math.hypot(d[0]+n[0]-c[0],d[1]+n[1]-c[1]);u<a&&(a=u,o=[c[0]-d[0],c[1]-d[1]],this._guides={point:c})}return o}roomAt(e){return(this.floor?.rooms??[]).filter(i=>C(e,i.points)).sort((i,o)=>ye(i.points)-ye(o.points))[0]?.id??null}addDraftPoint(e,n){let r=this._draft;if(r.length>=3){let[o,s]=this.toScreen(r[0]);if(Math.hypot(o-n[0],s-n[1])<14){this.closeDraft();return}}let i=r[r.length-1];i&&Math.hypot(i[0]-e[0],i[1]-e[1])<1e-6||(this._draft=[...r,e])}closeDraft(){this._draft.length>=3&&ye(this._draft)>.05&&this.addRoom(this._draft),this._draft=[],this._cursor=null,this._guides={}}measureStep(e){let n=this._draft[this._draft.length-1];if(!n||!(this._measureLen>0))return;let r=zn(n,this._measureLen,e),i=this._draft[0];if(this._draft.length>=3&&Math.hypot(r[0]-i[0],r[1]-i[1])<.01){this.closeDraft();return}this._draft=[...this._draft,r]}rectBySize(){let e=this._draft[0]??[0,0],[n,r]=this._rectSize;n>.1&&r>.1&&(this.addRoom([e,zn(e,n,"right"),zn(zn(e,n,"right"),r,"down"),zn(e,r,"down")]),this._draft=[])}get freeWall(){return this.sel.wall?(this.floor?.walls??[]).find(e=>e.id===this.sel.wall):void 0}updateFreeWall(e){let n=this.sel.wall;n&&this.change((r,i)=>Object.assign((i.walls??[]).find(o=>o.id===n),e))}deleteFreeWall(){let e=this.sel.wall;!e||!this.isAdmin||!this.confirmFixedDelete("wall",e)||(this.change((n,r)=>{r.walls=(r.walls??[]).filter(i=>i.id!==e),r.openings=r.openings.filter(i=>i.wall!==e)}),this.sel.wall=null)}get outdoorArea(){return this.sel.outdoor?this.floor?.outdoor.find(e=>e.id===this.sel.outdoor):void 0}updateOutdoor(e){let n=this.sel.outdoor;this.change((r,i)=>Object.assign(i.outdoor.find(o=>o.id===n),e))}deleteOutdoor(){let e=this.sel.outdoor;!e||!this.isAdmin||!this.confirmFixedDelete("outdoor",e)||(this.change((n,r)=>r.outdoor=r.outdoor.filter(i=>i.id!==e)),this.sel.outdoor=null)}onKey=e=>{if(e.composedPath().some(i=>i instanceof HTMLInputElement||i instanceof HTMLSelectElement||i instanceof HTMLTextAreaElement)||!this.isConnected||!this.offsetParent)return;if(e.key==="Escape"&&this._pick){e.preventDefault(),this.cancelPick();return}let r=e.ctrlKey||e.metaKey;if(r&&e.key.toLowerCase()==="z")e.preventDefault(),e.shiftKey?this.redo():this.undo();else if(r&&e.key.toLowerCase()==="y")e.preventDefault(),this.redo();else if(r&&e.key.toLowerCase()==="d")e.preventDefault(),this.duplicateRoom();else if(e.key==="Delete"||e.key==="Backspace"&&(this._tool==="select"||this._tool==="furniture"))this.sel.device?this.deleteItem("device",this.sel.device):this.sel.outdoor?this.deleteOutdoor():this.sel.wall?this.deleteFreeWall():this.sel.opening?this.deleteOpening():this.sel.furniture?this.deleteFurniture():this.sel.corner!==null?this.deleteVertex(this.sel.corner):this.deleteRoom();else if(e.key.toLowerCase()==="l"&&!r&&this._tool==="roof"&&this.roof.section&&!this._doc.settings.lock_plan)this.roof.patchSection({locked:!this.roof.section.locked});else if(e.key.toLowerCase()==="l"&&!r&&(this.sel.furniture||this.sel.device)){let i=this.sel.target;this.toggleFixed(i.kind,i.id)}else if(Object.hasOwn(Tb,e.key)&&!r&&(this._tool==="select"||this._tool==="furniture")){let i=e.altKey?.01:e.shiftKey?.1:this._doc.settings.grid,[o,s]=Tb[e.key];this.nudgeSelection(o*i,s*i)&&e.preventDefault()}else if(e.key.toLowerCase()==="r"&&!r&&this.sel.furniture)this.rotateFurniture(e.shiftKey?-90:90);else if(e.key==="Backspace"&&this._tool==="polygon")this._draft=this._draft.slice(0,-1);else if(e.key==="Enter"&&this._tool==="polygon")this.closeDraft();else if(e.key==="?"&&!r)this._keys=!this._keys;else if(e.key==="Escape"){if(this._keys){this._keys=!1;return}if(this._ctx){this._ctx=null;return}this._draft.length?this._draft=[]:this._tool!=="select"?this._tool="select":this.selectItem("room",null),this._cursor=null}};deleteFloor(){let e=this.floor;if(!e||!confirm(this.t("delete_floor_confirm",{name:e.name})))return;let n=structuredClone(this._doc);n.floors=n.floors.filter(r=>r.id!==e.id),this.setDoc(n),this.syncEditorContext(),this.clearPlanSelection()}faceHit(e,n){return e.wall?{u:(n[0]-e.o[0])*e.eu[0]+(n[1]-e.o[2])*e.eu[2],s:Number.NaN}:qn(e,n)}planLayers(e,n){let r=this.canvasContext(),i=this.room,o=!!i&&this.isAdmin&&this._tool==="select"&&!this.sel.opening&&!this.sel.furniture&&!this.isFixedItem("room",i.id),s=this.drag?.kind==="freewall"||this.drag?.kind==="rect"?this.drag:null;return E`${_f(r,this._doc.settings)} ${ff(r,this.bg,e)} ${hg(r,this._size)} ${pg(r)} ${n?fg(r,n):_}
${e?E`${mg(r,e,this.sel.outdoor)} ${_g(r,e,this.sel.room,this.sel.edge)} ${cg(r,e,this.sel.furniture)}
${yg(r,e,this.sel.wall)} ${n?$g(r,e,n,this.sel.opening):_} ${bg(r,e)}
${this._tool==="select"?dg(r,e,this.sel.device):_}
${this._tool==="select"?ug(r,e,this._note):_}
${this._dims?xg(r,e):_}
${o?wg(r,i,this.sel.corner):_}
${gg(r,this.outdoorArea,this._tool)}
${i&&this._tool==="select"?vg(r,i):_}
${uf(r,e)}`:_}
${this._tool==="roof"?E`${bl(r,this.roof)}${cf(r,this.roof)}${pf(r,this.roof)}`:this._tool==="energy"?E`${bl(r,this.roof)}${lf(r,this.roof)}${hf(r,this.floor,this._doc.energy.routes??[],this._routeDraft)}${df(r,this.floor,this.sel.furniture)}`:_}
${rg(r,s,this._tool,this._draft,this._cursor)} ${ng(r,this._guides,this._size)}`}wallsOfFloor(){let e=this.floor,{wall_exterior:n,wall_interior:r}=this._doc.settings;return e?me(e.rooms,{exterior:n,interior:r},e.walls??[]).walls:[]}edgeParts(e,n){let r=this.wallsOfFloor().flatMap(i=>i.sources.filter(o=>o.room_id===e.id&&o.edge===n).map(o=>o.t0));return r.length>0?[...new Set(r)].sort((i,o)=>i-o):[0]}changeRoom(e,n){this.isAdmin&&this.change((r,i)=>{let o=i.rooms.find(s=>s.id===e.id);o&&n(o)})}edgeActions(){return{openWall:(e,n)=>this._wallView={roomId:e.id,edge:n},partsOf:(e,n)=>this.edgeParts(e,n),isOuter:(e,n)=>this.wallsOfFloor().some(r=>r.exterior&&r.sources.some(i=>i.room_id===e.id&&i.edge===n)),setHeight:(e,n,r,i)=>{if(r!==void 0){let s=this.edgeParts(e,n).length;this.changeRoom(e,a=>Ag(a,n,r,i,s));return}let o=this.wallsOfFloor().filter(s=>s.sources.some(a=>a.room_id===e.id&&a.edge===n)).flatMap(s=>s.sources);o.some(s=>s.room_id===e.id&&s.edge===n)||o.push({room_id:e.id,edge:n,t0:0,t1:0}),this.isAdmin&&this.change((s,a)=>{for(let l of o){let c=a.rooms.find(d=>d.id===l.room_id);c&&oc(c,l.edge,i)}})},setSlope:(e,n,r,i)=>this.changeRoom(e,o=>Eg(o,n,r,i)),clearSlope:(e,n)=>this.changeRoom(e,r=>Rg(r,n,this.floor?.height??2.5)),setThickness:(e,n,r,i,o)=>this.changeRoom(e,s=>Pg(s,n,r,i,o)),arc:this.arcActions(),cut:(e,n,r)=>{let i=this.edgeParts(e,n);this.changeRoom(e,o=>Fg(o,n,r,i))},moveCut:(e,n,r,i)=>{let o=this.edgeParts(e,n);this.changeRoom(e,s=>Tg(s,n,r,i,o))},join:(e,n,r,i)=>this.changeRoom(e,o=>zg(o,n,r,i)),lit:this.sel.edge,light:e=>this.sel.edge=e}}addFloor(e=null,n){if(!this.isAdmin)return;let r=n??(this._editorScope?.kind==="building"?this._editorScope.id:void 0);if(this._doc.topology&&(!r||!this._doc.topology.buildings.some(s=>s.id===r)))return;let i=I_(this._doc,e,{first:this.t("default_floor"),next:s=>this.t("new_floor",{n:s})},r),o=structuredClone(this._doc);o.floors=Sc(o.floors,i),this.setDoc(o),this.adoptFloor(i.id),this.side.floorMenu=!1,this.fit()}addAreaRooms(e){let n=_r(this._doc,e,this.hass?.areas);if(n.length===0)return;let r=Wd(e,n,()=>P("room"));this.change((i,o)=>o.rooms.push(...r)),this.fit()}duplicateFloor(e){let n=this.floor;if(!n||!this.isAdmin)return;let r=L_(this._doc,n,this.t("floor_copy_name",{name:n.name}),e),i=structuredClone(this._doc);i.floors=Sc(i.floors,r),this.setDoc(i),this.adoptFloor(r.id),this.side.floorCopy=null,this.fit()}moveFloor(e){let n=this._floorId;if(!n)return;let r=$r(this._doc,this._editorScope),i=D_(r,n,e),o=new Set(r.map(c=>c.id)),s=0,a=this._doc.floors.map(c=>o.has(c.id)?i[s++]:c);if(a.every((c,d)=>c.id===this._doc.floors[d].id))return;let l=structuredClone(this._doc);l.floors=a.map(c=>l.floors.find(d=>d.id===c.id)),this.setDoc(l)}floorActions(){return{openFloor:e=>{this.adoptFloor(e),this.fit()},print:()=>this.printPlan(),addFloor:e=>this.addFloor(e),moveFloor:e=>this.moveFloor(e),deleteFloor:()=>this.deleteFloor(),duplicateFloor:e=>this.duplicateFloor(e),addAreaRooms:e=>this.addAreaRooms(e),closeGaps:()=>this.closeFloorGaps(),shift:()=>this.shiftFloor(this.side.shiftX,this.side.shiftZ),turn:()=>this.turnFloor(),rememberView:()=>this.rememberFloorView()}}roomActions(e){return{select:n=>this.selectItem("room",n),patch:n=>{this.room?.id===e.id&&this.updateRoom(n)},setArea:n=>{this.room?.id===e.id&&this.setArea(n)},setRect:(n,r)=>this.setRect(n,r),setCorner:(n,r,i)=>this.setPoint(n,r,i),removeCorner:n=>this.deleteVertex(n),duplicate:()=>this.duplicateRoom(),remove:()=>this.deleteRoom(),rememberView:()=>this.rememberRoomView(),applyPackage:n=>this.applyPackage(e,n),openSpots:()=>{let n=this.hass?we(this.hass,e).filter(r=>r.startsWith("light.")):[];this.side.spots=V_(e,n)},placeSpots:()=>this.placeSpots(e),lockButton:this.fixButton("room",e.id),wallHeights:Hg(this.host,e,this.edgeActions()),climate:dm(this.host,e,n=>this.updateRoom(n)),corner:this.sel.corner}}applyPackage(e,n){if(!this.isAdmin)return;let r=Fh(e,n,()=>P("furniture"));this.change((i,o)=>o.furniture.push(...r)),this.side.packages=!1,this.side.notice=this.t("pkg_done",{n:r.length})}placeSpots(e){let n=this.side.spots;if(!n||!this.isAdmin)return;let r=Ms(e,n);this.change((i,o)=>o.furniture.push(...r)),this.side.spots=null,this.side.notice=this.t("spots_placed",{n:r.length})}viewCentre(){return this.toWorld(this._size.w/2,this._size.h/2)}addFreeWall(e,n){if(!this.floor)return;let r=Df(e,n);this.change((i,o)=>o.walls=[...o.walls??[],r]),this.selectItem("wall",r.id)}addHole(e,n){if(!this.floor)return;let r=Lf(e,n);this.change((i,o)=>o.furniture.push(r)),this.selectItem("furniture",r.id),this._tool="select"}addStairs(e,n){let r=this.floor;if(!r)return;let[i,o]=[n[0]-e[0],n[1]-e[1]],s=Rl("stairs",this._doc,r,[(e[0]+n[0])/2,(e[1]+n[1])/2]),a=i>o*1.2;Object.assign(s,{w:Math.round((a?o:i)*1e3)/1e3,d:Math.round((a?i:o)*1e3)/1e3,rotation:a?90:0}),this.change((l,c)=>c.furniture.push(s)),this.selectItem("furniture",s.id),this._tool="select"}addOutdoor(e){if(!this.floor)return;let n=Cf(e);this.change((r,i)=>i.outdoor.push(n)),this.selectItem("outdoor",n.id),this._tool="select"}duplicateOutdoor(){let e=this.outdoorArea;if(!e||!this.isAdmin)return;let n=Vf(e);this.change((r,i)=>i.outdoor.push(n)),this.selectItem("outdoor",n.id)}addRoom(e){if(!this.floor)return;let n=Bm(e,this.t("new_room",{n:this.floor.rooms.length+1}));this.change((r,i)=>i.rooms.push(n)),this.sel.room=n.id,this.sel.corner=null,this._tool="select"}deleteRoom(){let e=this.sel.room;!e||!this.isAdmin||!this.confirmFixedDelete("room",e)||(this.change((n,r)=>Wm(r,e)),this.sel.room=null,this.sel.corner=null)}duplicateRoom(){let e=this.room;if(!e||!this.isAdmin)return;let n=Vm(e);this.change((r,i)=>i.rooms.push(n)),this.sel.room=n.id}deleteVertex(e){let n=this.room;n&&(this.change((r,i)=>Km(i,n.id,e)),this.sel.corner=null)}nudgeSelection(e,n){let r=this.floor;if(!r||!this.isAdmin)return!1;let i=this.sel.target;if(i&&this.isFixedItem(i.kind,i.id))return this._fixedHint=!0,!0;let o=i?i.kind==="room"?{kind:"room",id:i.id,corner:this.sel.corner}:{kind:i.kind,id:i.id}:null,s=o?S_(r,o,e,n):mr;return s===mr?!1:(s!==xs&&this.change((a,l)=>s.apply(l)),!0)}addFurniture(e){let n=this.floor;if(!n||!this.isAdmin)return;let r=this.room,i=Rl(e,this._doc,n,r?ve(r.points):this.viewCentre());this.change((o,s)=>s.furniture.push(i)),this.selectItem("furniture",i.id),this.showPoint(i.x,i.z)}rotateFurniture(e){let n=this.furnitureItem;n&&this.isAdmin&&this.updateFurniture({rotation:Kf(n.rotation,e)})}duplicateFurniture(){let e=this.furnitureItem;if(!e||!this.isAdmin)return;let n=Wf(e);this.change((r,i)=>i.furniture.push(n)),this.selectItem("furniture",n.id)}vehicleToSpot(e){if(!this.isAdmin)return;let n=jf(e);this.change((r,i)=>{i.furniture=i.furniture.filter(o=>o.id!==e.id),i.furniture.push(n)}),this.selectItem("furniture",n.id)}deviceToFurniture(e,n){if(!this.isAdmin)return;let r=Gf(e,n);this.change((i,o)=>{o.placements=o.placements.filter(s=>s.entity_id!==e.entity_id),o.furniture.push(r)}),this.sel.device=null,this.selectItem("furniture",r.id)}furnitureToDevice(e){let n=e.entity;if(!this.isAdmin||!n||n==="none")return;let r=Uf(e,n);this.change((i,o)=>{o.furniture=o.furniture.filter(s=>s.id!==e.id),o.placements.some(s=>s.entity_id===n)||o.placements.push(r)}),this.sel.furniture=null,this.selectItem("device",n)}placeDevices(e){let n=this.room;!n||e.length===0||!this.isAdmin||this.change((r,i)=>Al(r,i,n,e))}removeDevice(e){this.change(n=>Zf(n,e))}centreDevice(){let e=this.device,n=e?this.floor?.rooms.find(o=>o.id===this.roomAt([e.x,e.z])):void 0;if(!e||!n)return;let[r,i]=qf(n);this.updateDevice({x:r,z:i})}spreadCeilingLights(e){let n=this.floor;if(!n)return;let r=Um(e,n.placements);r.length!==0&&this.change((i,o)=>{for(let s of r)Object.assign(o.placements.find(a=>a.entity_id===s.entityId),{x:s.x,z:s.z})})}shiftScope(){return{floorId:this._floorId,allFloors:this.side.shiftAll,...this._doc.topology&&this._floorId?{floorIds:$d(this._doc,Gs(this._doc,this._floorId),!0).map(e=>e.id)}:{}}}shiftFloor(e,n){!this.isAdmin||!e&&!n||(this.change(r=>R_(r,this.shiftScope(),e,n)),this.side.shiftX=0,this.side.shiftZ=0)}turnFloor(){!this.floor||!this.isAdmin||this.change(e=>A_(e,this.shiftScope()))}setArea(e){let n=this.room;n&&this.updateRoom(Jl(n,e,this.hass?.areas??{},!Z(this.hass)))}setRect(e,n){let r=this.room,i=r?jm(r,e,n):null;i&&this.updateRoom({points:i})}setPoint(e,n,r){let i=this.room,o=i?Gm(i,e,n,r):null;o&&this.updateRoom({points:o})}setOpeningPreset(e,n){this._openingPreset=n,this.updateOpening(Xf(e,n))}pressRoute(e){let n=this._routeDraft;if(!n||this._tool!=="energy"||!this._floorId||n.points.length>=Hd)return;let[r,i]=this.snap(e.world,void 0,e.fine).map(o=>Math.round(o*1e3)/1e3);return this._routeDraft={...n,points:[...n.points,{floor_id:this._floorId,x:r,z:i}]},Hi}routeActions(){let e=n=>this.change(r=>{r.energy.routes=n(r.energy.routes??[]),r.energy.routes.length||delete r.energy.routes});return{draft:this._routeDraft,start:n=>this._routeDraft={key:n,points:[...this._doc.energy.routes?.find(r=>r.key===n)?.points??[]]},undoPoint:()=>this._routeDraft&&(this._routeDraft={...this._routeDraft,points:this._routeDraft.points.slice(0,-1)}),cancel:()=>this._routeDraft=null,finish:()=>{let n=this._routeDraft;this._routeDraft=null,!(!n||!this.isAdmin)&&e(r=>{let i=r.find(s=>s.key===n.key),o=r.filter(s=>s.key!==n.key);return n.points.length?[...o,{key:n.key,points:n.points,...i?.cable?{cable:!0}:{}}]:o})},clear:n=>this.isAdmin&&e(r=>r.filter(i=>i.key!==n)),setCable:(n,r)=>this.isAdmin&&e(i=>i.map(o=>o.key===n?{...o,cable:r}:o))}}energyActions(){return{follow:e=>{e.kind==="solar-field"?this.roof.solarId=e.id:e.kind==="add-solar-field"?this.roof.addField():e.kind==="add-device"?this.addEnergyDevice(e.type):this.openEnergyDevice(e.floor,e.item)},addDevice:e=>{this.roof.solarId=null,this.addEnergyDevice(e)},openDevice:(e,n)=>this.openEnergyDevice(e,n),importPrefs:()=>{this.importEnergy()},note:this._energyNote}}openEnergyDevice(e,n){this.adoptFloor(e.id),this.roof.solarId=null,this.selectItem("furniture",n.id),this.showPoint(n.x,n.z)}addEnergyDevice(e){let n=this.floor;if(!n||!this.isAdmin)return;let r=o=>o.area_id&&this.hass?.areas?.[o.area_id]?.name||"",i=$_(e,this._doc,n,{roomLabel:o=>`${o.name} ${r(o)} ${o.area_id??""}`,selected:this.room,fallback:this.toWorld(this._size.w/2,this._size.h/2)});this.change((o,s)=>s.furniture.push(i)),this.selectItem("furniture",i.id),this.showPoint(i.x,i.z)}async importEnergy(){if(!this.hass)return;let e=await x_({hass:this.hass,doc:()=>this._doc,canAdd:()=>!!this.floor,addDevice:n=>this.addEnergyDevice(n),setField:(n,r,i)=>this.change(o=>{let s=o.floors.flatMap(a=>a.furniture).find(a=>a.id===n);s&&(s[r]=i)})});if(e.kind==="failed"){this._energyNote=this.t("energy_import_failed");return}this.selectItem("furniture",null),this._energyNote=e.filled>0?this.t("energy_import_done",{n:e.filled}):this.t("energy_import_none")}renderEnergyPanel(){let e=this.roof.solarId?this._doc.settings.roof.solar?.find(i=>i.id===this.roof.solarId):void 0;if(e)return y_(this.roofDeps(),e);let n=this.sel.furniture?this.floor?.furniture.find(i=>i.id===this.sel.furniture&&Ke.includes(i.type)):void 0;if(n)return m`<button class="nf-btn nf-back" @click=${()=>this.selectItem("furniture",null)}>‹ ${this.t("tool_energy")}</button>
${Pi(this.host,n,this.furnitureActions())}`;let r=this.energyActions();return m`${ef(this.host,r)}${b_(this.roofDeps())}${tf(this.host,r)}${sf(this.host,this.routeActions())}${nf(this.host,r)}${rf(this.host)}`}fixItem(e,n,r){if(e)switch(n){case"room":return e.rooms.find(i=>i.id===r);case"opening":return e.openings.find(i=>i.id===r);case"furniture":return e.furniture.find(i=>i.id===r);case"device":return e.placements.find(i=>i.entity_id===r);case"wall":return(e.walls??[]).find(i=>i.id===r);case"outdoor":return e.outdoor.find(i=>i.id===r)}}isFixedItem(e,n){return eo(this.fixItem(this.floor,e,n),e!=="furniture"&&e!=="device",this._doc.settings)}toggleFixed(e,n){if(!this.isAdmin||e!=="furniture"&&e!=="device")return;let r=!this.isFixedItem(e,n);this.change((i,o)=>{let s=this.fixItem(o,e,n);s&&(s.locked=r)})}toggleLockPlan(){this.isAdmin&&this.change(e=>e.settings.lock_plan=!e.settings.lock_plan)}confirmFixedDelete(e,n){return!this.isFixedItem(e,n)||confirm(this.t("fixed_delete_confirm"))}onContextMenu(e){e.preventDefault(),!(this._tool!=="select"&&this._tool!=="furniture")&&(this.drag=null,this.openContext(e.target,this.localPoint(e)))}openContext(e,n){if(!this.isAdmin||!this.floor)return;let r=this.toWorld(...n),i=f=>e.closest(`[${f}]`)?.getAttribute(f)??null,o=null,s=i("data-device"),a=i("data-opening"),l=e.closest("[data-vertex], [data-mid]")?null:i("data-furniture"),c=i("data-free-wall"),d=i("data-outdoor"),u=i("data-room")??this.roomAt(r);if(s?o=["device",s]:a?o=["opening",a]:l?o=["furniture",l]:c?o=["wall",c]:d&&!u?o=["outdoor",d]:u&&(o=["room",u]),!o){this._ctx=null;return}let[p,h]=o;this.selectItem(p,h),(p==="opening"||p==="furniture")&&(this.sel.room=this.sel.room??u),this._ctx={x:n[0],y:n[1],kind:p,id:h,at:r}}deleteItem(e,n){if(e==="device"){if(!this.confirmFixedDelete(e,n))return;this.removeDevice(n),this.sel.device=null;return}e==="room"?this.deleteRoom():e==="opening"?this.deleteOpening():e==="furniture"?this.deleteFurniture():e==="wall"?this.deleteFreeWall():this.deleteOutdoor()}renderContext(){let e=this._ctx;if(!e)return _;let n=this.isFixedItem(e.kind,e.id),r=this.renderRoot.querySelector(".nf-canvas-wrap"),i=Math.max(4,Math.min(e.x,(r?.clientWidth??800)-190)),o=Math.max(4,Math.min(e.y,(r?.clientHeight??600)-190)),s=a=>()=>{this._ctx=null,a()};return m`<div class="nf-ctx" style=${`left:${i}px;top:${o}px`} @pointerdown=${a=>a.stopPropagation()} @contextmenu=${a=>a.preventDefault()}>
${e.kind==="furniture"||e.kind==="device"?m`<button title=${this.t("fix_hint")} @click=${s(()=>this.toggleFixed(e.kind,e.id))}>${n?`\u{1F513} ${this.t("unfix")}`:`\u{1F512} ${this.t("fix")}`}</button>`:m`<button title=${this.t("lock_plan_hint")} @click=${s(()=>this.toggleLockPlan())}>${this._doc.settings.lock_plan?`\u{1F513} ${this.t("plan_unlock")}`:`\u{1F512} ${this.t("plan_lock")}`}</button>`}
${e.kind==="room"?m`<button @click=${s(()=>this.duplicateRoom())}>⧉ ${this.t("duplicate")}</button>`:_}
${e.kind==="furniture"?m`<button @click=${s(()=>this.duplicateFurniture())}>⧉ ${this.t("duplicate")}</button>
<button ?disabled=${n} @click=${s(()=>this.rotateFurniture(90))}>↻ ${this.t("ctx_rotate")}</button>
<button ?disabled=${n} @click=${s(()=>this.mirrorFurniture())}>⇋ ${this.t("furn_mirror")}</button>`:_}
${e.at?m`<button @click=${s(()=>this.addNote(e.at))}>✎ ${this.t("note_add")}</button>`:_}
<button class="nf-ctx-danger" @click=${s(()=>this.deleteItem(e.kind,e.id))}>✕ ${this.t("delete")}</button>
</div>`}fixButton(e,n){if(!this.isAdmin)return _;if(e!=="furniture"&&e!=="device")return this._doc.settings.lock_plan?m`<button class="nf-btn nf-fix" aria-pressed="true" title=${this.t("lock_plan_hint")} @click=${()=>this.toggleLockPlan()}>
🔒 ${this.t("plan_locked")}
</button>`:_;let r=this.isFixedItem(e,n);return m`<button class="nf-btn nf-fix" aria-pressed=${r} title=${this.t("fix_hint")} @click=${()=>this.toggleFixed(e,n)}>
${r?`\u{1F512} ${this.t("unfix")}`:`\u{1F513} ${this.t("fix")}`}
</button>`}dropOffset(e,n,r,i,o){let s=e.points[n],a=e.points[(n+1)%e.points.length],l=Math.hypot(a[0]-s[0],a[1]-s[1])||1,c=((r[0]-s[0])*(a[0]-s[0])+(r[1]-s[1])*(a[1]-s[1]))/l;return Yf(l,c,i,o?.01:this._doc.settings.grid)}selectItem(e,n){this.side.notice=null,n&&(this._sideOpen=!0),this.sel.select(e,n,{roomOfDevice:r=>{let i=this.floor?.placements.find(o=>o.entity_id===r);return(i&&this.roomAt([i.x,i.z]))??null},roomOfOpening:r=>this.floor?.openings.find(i=>i.id===r)?.room_id??null})}get opening(){let e=this.sel.opening?this.floor?.openings.find(i=>i.id===this.sel.opening):void 0;if(!e?.front||!this.floor)return e;let n=this.floor.rooms.find(i=>i.id===e.room_id),r=n?Xn(n,Gt(this.floor.openings,e)):null;return r?{...e,width:r.width}:e}get furnitureItem(){return this.sel.furniture?this.floor?.furniture.find(e=>e.id===this.sel.furniture):void 0}placeOpening(e,n){let r=this.floor;if(!r||!this.isAdmin)return!1;let i=null;for(let g of r.walls??[]){let b=Ne({room_id:"",edge:0,wall:g.id},r.rooms,r.walls??[]);if(!b)continue;let[y,v]=this.toScreen(g.a),[w,k]=this.toScreen(g.b),x=(w-y)**2+(k-v)**2||1,M=Math.min(1,Math.max(0,((n[0]-y)*(w-y)+(n[1]-v)*(k-v))/x)),A=Math.hypot(n[0]-y-(w-y)*M,n[1]-v-(k-v)*M),T=[(g.a[0]+g.b[0])/2,(g.a[1]+g.b[1])/2],F=r.rooms.find(L=>L.points.length>=3&&C(T,L.points));A<Li*2.2&&(!i||A-1<i.d)&&(i={room:b.room,edge:0,d:A-1,wall:g.id,roomId:F?.id??g.id})}for(let g of r.rooms)for(let b=0;b<g.points.length;b++){let[y,v]=this.toScreen(g.points[b]),[w,k]=this.toScreen(g.points[(b+1)%g.points.length]),x=(w-y)**2+(k-v)**2||1,M=Math.min(1,Math.max(0,((n[0]-y)*(w-y)+(n[1]-v)*(k-v))/x)),A=Math.hypot(n[0]-y-(w-y)*M,n[1]-v-(k-v)*M),T=A-(g.id===this.sel.room?.5:0);A<Li*2.2&&(!i||T<i.d)&&(i={room:g,edge:b,d:T})}if(!i)return!1;let{room:o,edge:s,wall:a}=i,l=o.points[s],c=o.points[(s+1)%o.points.length],d=Math.hypot(c[0]-l[0],c[1]-l[1]),u=Pn[e],p=u.type;if(u.style==="glass_wall"&&!a){let g=Ja(o,this.toWorld(...n)),b=Xa(o,g-u.width/2,u.width);if(b&&b.length>1){let y=P("front"),v=b.map(w=>({id:P("opening"),room_id:i.roomId??o.id,edge:w.edge,offset:w.offset,width:w.width,front:y,type:p,sill:u.sill,height:u.height,hinge:"left",leaves:u.leaves,swing:"in",...so.has(u.style)?{}:{style:u.style},...u.opens?{opens:u.opens}:{},cover:null,contact:null,contact2:null,tilt:null}));return this.change((w,k)=>k.openings.push(...v)),this._tool="select",this.selectItem("opening",v[0].id),!0}}let h=We(Math.min(u.width,Math.max(.3,d-.1))),f={id:P("opening"),room_id:i.roomId??o.id,edge:s,...a?{wall:a}:{},offset:this.dropOffset(o,s,this.toWorld(...n),h,!1),width:h,type:p,sill:u.sill,height:u.height,hinge:"left",leaves:u.leaves,swing:"in",...u.style&&!so.has(u.style)?{style:u.style}:{},...u.opens?{opens:u.opens}:{},cover:null,contact:null,contact2:null,tilt:null};return this.change((g,b)=>b.openings.push(f)),this._tool="select",this.selectItem("opening",f.id),!0}updateOpening(e){let n=this.sel.opening;this.change((r,i)=>{let o=i.openings.find(d=>d.id===n);if(!o)return;let s=Gt(i.openings,o),a=o.wall?null:i.rooms.find(d=>d.id===o.room_id),l=a&&o.type==="window"&&o.style==="glass_wall"&&(e.width!=null||e.offset!=null),c=l&&a?Xn(a,s):null;if(l&&a&&c){let d=Math.max(.3,e.width??c.width),u=c.from;e.width!=null&&(u+=(c.width-d)/2),e.offset!=null&&(u+=e.offset-o.offset),u=Math.max(0,Math.min(li(a)-d,u));let p=ci(i.openings,a,{...o,...e},u,d,()=>P("opening"));p&&(i.openings=p);return}for(let d of s)Object.assign(d,e)})}deleteOpening(){let e=this.sel.opening;!e||!this.isAdmin||!this.confirmFixedDelete("opening",e)||(this.change((n,r)=>{let i=r.openings.find(s=>s.id===e),o=new Set((i?Gt(r.openings,i):[i]).map(s=>s?.id));r.openings=r.openings.filter(s=>!o.has(s.id))}),this.sel.opening=null)}snapToWall(e){return this.floor?Nr(this.floor,e,this._doc.settings.wall_interior):null}updateFurniture(e){let n=this.sel.furniture;this.change((r,i)=>Object.assign(i.furniture.find(o=>o.id===n),e))}mirrorFurniture(){let e=this.furnitureItem;!e||!this.isAdmin||this.updateFurniture({mirror:!e.mirror})}deleteFurniture(){let e=this.sel.furniture;!e||!this.isAdmin||!this.confirmFixedDelete("furniture",e)||(this.change((n,r)=>r.furniture=r.furniture.filter(i=>i.id!==e)),this.sel.furniture=null)}get device(){return this.sel.device?this.floor?.placements.find(e=>e.entity_id===this.sel.device):void 0}updateDevice(e){let n=this.sel.device;this.change((r,i)=>Object.assign(i.placements.find(o=>o.entity_id===n),e))}closeFloorGaps(){let e=this.floor;if(!e||!this.isAdmin)return;let{rooms:n,gaps:r}=th(e.rooms);if(!r.length){this.side.notice=this.t("gaps_none");return}let i=nh(r);this.change((o,s)=>{s.rooms=n,i&&(o.settings.wall_interior=i)}),this.side.notice=i?this.t("gaps_closed_wall",{n:r.length,t:K(this.hass,i,2)}):this.t("gaps_closed",{n:r.length})}updateFloor(e){this.change((n,r)=>Object.assign(r,e))}updateRoom(e){let n=this.sel.room;this.change((r,i)=>Object.assign(i.rooms.find(o=>o.id===n),e))}render(){hm(this._doc.settings.units);let e=this.floor,n=e?me(e.rooms,{exterior:this._doc.settings.wall_exterior,interior:this._doc.settings.wall_interior},e.walls??[]):null;return m`
${this.renderHierarchyDialogs()}
${Nm(this.host,this.lib.preview)}
${this._wallView?m`<nf-wall-view .host=${this.host} .doc=${this._doc} .roomId=${this._wallView.roomId} .edge=${this._wallView.edge} @close=${()=>this._wallView=null}></nf-wall-view>`:_}
<div class="nf-editor ${this.narrow?"nf-narrow":""}">
<div class="nf-main">
<div class="nf-editor-head">
${this.renderEditorNavigation()}
<div class="nf-toolbar">
${this.narrow?m`<select class="nf-tool-select" aria-label=${this.t("tool_select")} ?disabled=${!e} @change=${r=>{this._tool=r.target.value,this._draft=[],this._cursor=null,this._sideOpen=this._tool!=="select"}}>
${Ab.filter(r=>this.isAdmin||r==="select").map(r=>m`<option value=${r} ?selected=${this._tool===r}>${this.t(`tool_${r}`)}</option>`)}
</select>`:_}
<div class="nf-seg" role="group" aria-label=${this.t("tool_select")} ?hidden=${this.narrow}>
${Ab.map(r=>m`<button
aria-pressed=${this._tool===r}
?disabled=${!e||!this.isAdmin&&r!=="select"}
@click=${()=>{this._tool=r,this._draft=[],this._cursor=null,this._sideOpen=r!=="select"}}
>
${this.t(`tool_${r}`)}
</button>`)}
</div>
<button class="nf-chip nf-room-names-toggle" aria-pressed=${this.roomLabels} title=${this.t("room_names_toggle_hint")} @click=${()=>{this.roomLabels=!this.roomLabels,this.dispatchEvent(new CustomEvent("room-names-change",{detail:{value:this.roomLabels},bubbles:!0,composed:!0}))}}>${this.t("room_names_short")}</button>
<div class="nf-seg">
<button ?disabled=${!this._canUndo} @click=${()=>this.undo()} title="Ctrl+Z">${this.t("undo")}</button>
<button ?disabled=${!this._canRedo} @click=${()=>this.redo()} title="Ctrl+Y">${this.t("redo")}</button>
<button @click=${()=>this.fit()}>${this.t("fit")}</button>
<button aria-pressed=${this._split} title=${this.t("split_3d_hint")} @click=${()=>this.toggleSplit()}>${this.t("split_3d")}</button>
${this.isAdmin?m`<button aria-pressed=${!!this._doc.settings.lock_plan} title=${this.t("lock_plan_hint")} @click=${()=>this.toggleLockPlan()}>${this.t("lock_plan")}</button>`:_}
<button aria-pressed=${this._dims} title=${this.t("plan_dims_hint")} @click=${()=>this.setDims(!this._dims)}>📏 ${this.t("plan_dims")}</button>
</div>
${n?.warnings.length?m`<span class="nf-warn">${this.t("overlap_warning")}</span>`:_}
</div>
</div>
<div class="nf-stage-pair ${this._split?"nf-split":""}" style=${this._split&&!this.narrow?`--nf-split:${Math.round(this._splitRatio*100)}%`:""}>
<div class="nf-canvas-wrap">
${this.houseTool?m`<div class="nf-tool-note">${this.t(this._tool==="energy"?"energy_only_note":"roof_only_note")}</div>`:_}
<svg
class="nf-plan nf-tool-${this._tool}"
@pointerdown=${this.onPointerDown}
@pointermove=${this.onPointerMove}
@pointerup=${this.onPointerUp}
@pointercancel=${this.onPointerUp}
@pointerleave=${()=>{this.drag||(this._cursor=null)}}
@wheel=${this.onWheel}
@contextmenu=${this.onContextMenu}
>
${this.planLayers(e,n?.walls??null)}
</svg>
${this.renderContext()}
${this._pick||this._fixedHint?m`<p class="nf-hint ${this._fixedHint?"nf-hint-fixed":""}">${this._pick?this.t("robot_cal_doing"):this.t("fixed_drag_hint")}</p>`:m`<div class="nf-hint">${S(e?this.t(`hint_${this._tool}`):this._doc.topology?"W\xE4hle oben ein Geb\xE4ude und lege dort mit + Etage ein Stockwerk an. Ort, Niederlassung und Geb\xE4ude verwaltest du \xFCber Hierarchie.":this.t("hint_empty"))}</div>`}
<button class="nf-keys-open" title=${this.t("keys_title")} aria-label=${this.t("keys_title")} @click=${()=>this._keys=!0}>?</button>
${this.isAdmin?bb((r,i)=>this.t(r,i),this._tour,r=>{this._tour=r,r===null&&gb()}):_}
${this._keys?_b(r=>this.t(r),()=>this._keys=!1):_}
</div>
${this._split&&!this.narrow?m`<div class="nf-split-handle" title=${this.t("split_handle_hint")} @pointerdown=${this.onSplitDown}></div>`:_}
${this._split?this.render3d():_}
</div>
</div>
${this.renderAside(e)}
</div>
`}selectFrom3d(e,n){this.selectItem(e,n),this._sideOpen=!1}setSidePinned(e){this._sidePinned=e,this._sideOpen=!1;try{localStorage.setItem("nextfloor.sidePinned",e?"1":"0")}catch{}}renderAside(e){return this._split&&!this._sidePinned&&!this.narrow?this._sideOpen?m`<aside class="nf-side nf-side-strip"></aside>
<aside class="nf-side nf-side-overlay">
${this.renderPinRow(!0)}
${this.safeSide(e)}
</aside>`:m`<aside class="nf-side nf-side-strip">
<button class="nf-strip-btn" title=${this.t("side_open")} @click=${()=>this._sideOpen=!0}>☰</button>
${this.sel.furniture||this.sel.device||this.sel.opening?m`<button class="nf-strip-btn nf-strip-hot" title=${this.t("side_details")} @click=${()=>this._sideOpen=!0}>⚙</button>`:_}
<button class="nf-strip-btn" title=${this.t("tool_furniture")} @click=${()=>(this._tool="furniture",this._draft=[],this._sideOpen=!0)}>🛋</button>
<button class="nf-strip-btn" title=${this.t("tool_opening")} @click=${()=>(this._tool="opening",this._draft=[],this._sideOpen=!0)}>🚪</button>
</aside>`:m`<aside class="nf-side">${this.renderPinRow()}${this.safeSide(e)}</aside>`}safeSide(e){try{return this.renderSide(e)}catch(n){return console.error("NextFloor: the side bar could not be drawn",n),m`<button class="nf-btn nf-back" @click=${()=>this.selectItem("room",null)}>‹ ${this.t("back_to_floor")}</button>
<p class="nf-note">${this.t("side_failed",{error:n instanceof Error?n.message:String(n)})}</p>`}}renderPinRow(e=!1){return!this._split||this.narrow?_:m`<div class="nf-pin-row">
${e?m`<button class="nf-btn" @click=${()=>this._sideOpen=!1}>${this.t("side_close")}</button>`:_}
<button class="nf-btn" aria-pressed=${this._sidePinned} title=${this.t("side_pin_hint")} @click=${()=>this.setSidePinned(!this._sidePinned)}>
📌 ${this.t(this._sidePinned?"side_pinned":"side_pin")}
</button>
</div>`}renderSide(e){let n=this.room,r=this.isAdmin;if(this._tool==="roof")return c_(this.roofDeps());if(this._tool==="energy")return this.renderEnergyPanel();if(this._tool==="furniture"&&e&&r)return this._studio?tb(this.host,this._studio,{change:s=>this._studio&&(this._studio={...this._studio,recipe:s,error:null}),save:()=>{this.saveStudio()},close:()=>this._studio=null}):m`${this.furnitureItem?m`${Pi(this.host,this.furnitureItem,this.furnitureActions())}${this.studioButton()}`:_} ${Cm(this.host,this.lib,this.room?.name,this.libraryActions())}`;let i=this._tool==="measure"?null:this.furnitureItem?Pi(this.host,this.furnitureItem,this.furnitureActions()):this.opening?pc(this.host,this.opening,this.openingActions()):this.device?ac(this.host,this.device,this.deviceActions()):this.outdoorArea?Fl(this.host,this.outdoorArea,this.outdoorActions()):this.freeWall?Tl(this.host,this.freeWall,this.freeWallActions()):null,o=this._note?e?.notes?.find(s=>s.id===this._note):void 0;return o?m`<button class="nf-btn nf-back" @click=${()=>this._note=null}>‹ ${this.t("back_to_floor")}</button>
${kg(this.host,o,{patch:s=>this.change((a,l)=>Object.assign(l.notes.find(c=>c.id===o.id),s)),remove:()=>{this.change((s,a)=>a.notes=(a.notes??[]).filter(l=>l.id!==o.id)),this._note=null}})}`:i?m`<button class="nf-btn nf-back" @click=${()=>this.selectItem("room",this.sel.room)}>‹ ${this.t(n?"back_to_room":"back_to_floor",{room:n?.name??""})}</button>
${i}`:n&&this._tool!=="measure"?m`<button class="nf-btn nf-back" @click=${()=>this.selectItem("room",null)}>‹ ${this.t("back_to_floor")}</button>
${Ec(this.host,this.side,n,this.roomActions(n))} ${Dl(this.host,this.side,n,this.deviceListActions())}`:m`
${r?_:m`<p class="nf-note">${this.t("read_only")}</p>`}
${this._check?nb(this.host,hb(this._doc,this.hass),{fix:s=>this.fixFinding(s),ignore:s=>this.ignoreDevices(s),resetIgnored:()=>this.change(s=>s.settings.check_ignore=null),close:()=>this._check=!1}):r?rb(this.host,()=>this._check=!0):_}
${N_(this.host,this.side,this.floorActions(),e,this._floorId)}
${this._tool==="measure"&&e?em(this.host,this.measureState(),this.measureActions()):this.freeWall?Tl(this.host,this.freeWall,this.freeWallActions()):this.outdoorArea?Fl(this.host,this.outdoorArea,this.outdoorActions()):this.opening?pc(this.host,this.opening,this.openingActions()):this.furnitureItem?Pi(this.host,this.furnitureItem,this.furnitureActions()):this.device?ac(this.host,this.device,this.deviceActions()):n?m`${Ec(this.host,this.side,n,this.roomActions(n))} ${Dl(this.host,this.side,n,this.deviceListActions())}`:e?G_(this.host,e,{select:s=>this.selectItem("room",s)}):_}
${r?ip(this.host,()=>this.paneView()):_} ${r?rp(this.host,()=>this.groundView()):_} ${r?np(this.host):_}
${of(this.host)}
${r&&!0?op(this.host):_} ${r?sp(this.host,this._doc):_} ${r?dp(this.host):_}
${e&&r?Mf(this.host,this.bg,e):_} ${r?Up(this.host,this.settingsActions):_}
${r?Pp(this.host,this.backup):_}
`}openingIsExterior(e){let n=this.floor,r=n?Ne(e,n.rooms,n.walls??[]):null;if(!n||!r)return!1;let i=me(n.rooms,{exterior:this._doc.settings.wall_exterior,interior:this._doc.settings.wall_interior},n.walls??[]);return Kt(i.walls,e,r)?.wall.exterior??!1}groundView(){let e=this.paneView();if(!e)return alert(this.t("floor_start_view_need_pane")),null;let n=this.floor?.elevation??0;return e.target?{...e,target:{...e.target,y:We(e.target.y+n)}}:e}paneView(){let n=this.renderRoot.querySelector("nf-view3d")?.currentView();if(!n)return null;let r=n.target;return{theta:We(n.theta),phi:We(n.phi),radius:We(n.radius),...r?{target:{x:We(r.x),y:We(r.y),z:We(r.z)}}:{}}}rememberFloorView(){let e=this.paneView();if(!e){alert(this.t("floor_start_view_need_pane"));return}this.updateFloor({start_view:e})}rememberRoomView(){let e=this.paneView();if(!e){alert(this.t("room_start_view_need_pane"));return}this.updateRoom({start_view:e})}storedPictures(){let e=[];for(let n of this._doc.floors)for(let r of n.furniture)for(let i of r.pictures??[])i.image&&!/^https?:\/\//.test(i.image)&&!i.image.startsWith("camera:")&&!e.includes(i.image)&&e.push(i.image);return e}static styles=[fe,pt,U_]};customElements.get("nf-editor")||customElements.define("nf-editor",Oc);export{Oc as NfEditor};
/*! Bundled license information:
@lit/reactive-element/css-tag.js:
(**
* @license
* Copyright 2019 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*)
@lit/reactive-element/reactive-element.js:
lit-html/lit-html.js:
lit-element/lit-element.js:
lit-html/directive.js:
lit-html/directives/unsafe-html.js:
lit-html/directives/repeat.js:
lit-html/async-directive.js:
(**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*)
lit-html/is-server.js:
(**
* @license
* Copyright 2022 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*)
lit-html/directive-helpers.js:
lit-html/directives/ref.js:
(**
* @license
* Copyright 2020 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*)
*/