`}_valueChanged(t){const e={...this._config,...t.detail.value},i=new Event("config-changed",{bubbles:!0,composed:!0});i.detail={config:e},this.dispatchEvent(i)}}function _l(t){const e=Jr(t.cfg),i={};for(const e of t.cfg.spaces||[])for(const t of e.rooms||[])t.area&&(i[t.area]=e.id);const s=t.cfg.settings?.exclude_integrations?new Set(t.cfg.settings.exclude_integrations):ft,n=yt(t.cfg.settings?.icon_rules?.length?t.cfg.settings.icon_rules:vt);return pn({hass:t.hass,registry:t.registry,areaToSpace:i,markers:t.cfg.markers||[],settings:t.cfg.settings||{},excluded:s,showAll:!!t.cfg.settings?.show_all,firstSpaceId:e[0]?.id||"",loc:e=>On(t.lang,e),iconRules:n})}function ml(t){const e=Jr(t.cfg).find(e=>e.id===t.spaceId);if(!e)return null;const i=Ti(t.cfg.spaces.find(e=>e.id===t.spaceId)),s=t.iconSize??2.5,n=s>8?2.5:s,o=t.registry?Os(t.hass,t.registry):t.hass,r=(t.devices||_l(t)).filter(e=>e.space===t.spaceId),a=r.filter(t=>!t.hidden),l=function(t,e,i){const s={},n=i/100*fa(e)*1.3;for(const i of e.rooms){if(!i.area)continue;const e=t.filter(t=>t.area===i.area);if(!e.length)continue;const o=ba(i),r=.1*Math.min(o.w,o.h),a=o.w-2*r,l=o.h-2*r,c=Math.max(1,Math.round(Math.sqrt(e.length*a/Math.max(l,1)))),h=a/c,d=l/Math.max(Math.ceil(e.length/c),1),p=e.map((t,e)=>({x:o.x+r+h*(e%c+.5),y:o.y+r+d*(Math.floor(e/c)+.5)}));oi(p,o,n,.5*r),e.forEach((t,e)=>s[t.id]=sa(p[e]))}return s}(r,e,n),c=[];for(const e of a){const i=t.layout[e.id];if(i&&i.s===t.spaceId){const t=i.x*jr,e=i.y*jr;c.push({minX:t,minY:e,maxX:t,maxY:e})}}const h=t.cfg.spaces.find(e=>e.id===t.spaceId)||{},d=Array.isArray(h.walls)?h.walls:[],p=Number(h.cell_cm)>0?Number(h.cell_cm):5,u=function(t,e,i){const s=[];for(const n of t.partitions||[]){const t=Ir(n.a,n.b,n.cm,e,i);t&&s.push(t)}for(const n of t.room_drafts||[])s.push(...Or(n,e,i));for(const n of t.wall_columns||[])s.push(Nr(n,e,i));return s}(e,p,ta);for(const t of u){const e=t.map(t=>t[0]),i=t.map(t=>t[1]);e.length&&c.push({minX:Math.min(...e),minY:Math.min(...i),maxX:Math.max(...e),maxY:Math.max(...i)})}const _=ma(e,c),m=[_.x,_.y,_.w,_.h],g=e.rooms.filter(t=>t.area||i.showBorders||"light"===Qi(i.fill,t)).map(s=>{let n="room "+(e.bg?"overlay":"yard"),a="";const l=Qi(i.fill,s);if(i.showBorders||"none"!==l){n+=" styled";const e=[`--room-stroke:${i.color}`,`--room-stroke-op:${i.showBorders?i.opacity:0}`],c="light"===l?Ii("light",null,tn(Qs(o,r,s)),null,i.tempMin,i.tempMax,Ai(t.cfg?.settings)):s.area?Ii(l,"lqi"===l?function(t,e,i){const s=[];for(const n of e){if(n.area!==i||n.virtual)continue;const e=en(t,n.entities);null!=e&&s.push(e)}return si(s)}(o,r,s.area):null,"none","temp"===l?function(t,e,i){const s=[];for(const n of e){if(n.area!==i)continue;if("mdi:thermometer"!==n.icon&&"mdi:air-filter"!==n.icon)continue;const e=sn(t,n.entities);null!=e&&s.push(e)}return s.length?Math.round(s.reduce((t,e)=>t+e,0)/s.length*10)/10:null}(o,r,s.area):null,i.tempMin,i.tempMax,Ai(t.cfg?.settings)):null;c?(n+=" filled",e.push(`--room-fill:${c.c}`,`--room-fill-op:${c.a.toFixed(3)}`)):e.push("--room-fill:transparent","--room-fill-op:0"),a=e.join(";")}const c=!e.bg&&!i.showNames,h=wa(s),d=s.id||G,p=s.area||G,u=s.poly?j`
`:j`
`;return j`${u}${c?j`
${s.name}`:G}`}),f=a.map(s=>{const n=function(t,e,i,s,n){const o=e[t.id];return o&&o.s===t.space?{x:o.x*jr,y:o.y*jr}:s[t.id]?s[t.id]:sa(ga(n))}(s,t.layout,t.cfg,l,e),r=(n.x-m[0])/m[2]*100,a=(n.y-m[1])/m[3]*100,c=xn(o,s,{liveStates:!1!==t.liveStates,showTemperature:!1!==t.showTemperature,showSignal:i.showLqi??!1!==t.showSignal,activityRuntime:t.activityRuntime?.get(s.id),sourceDetails:!1}),h=[`left:${r}%`,`top:${a}%`,...mt(c)];return W`
${gt(c,{})}
-
`}),v=i.showNames?e.rooms.filter(t=>t.name).map(s=>{const n=function(t,e,i){const s=i["rl_"+(t.id||"")];if(s&&s.s===e)return{x:s.x*Lr,y:s.y*Lr};const n=ga(t);return Xr({x:n[0],y:n[1]})}(s,e.id,t.layout,t.cfg),o=(n.x-m[0])/m[2]*100,r=(n.y-m[1])/m[3]*100,a=Math.min(1,i.opacity+.25);return W`
`}),v=i.showNames?e.rooms.filter(t=>t.name).map(s=>{const n=function(t,e,i){const s=i["rl_"+(t.id||"")];if(s&&s.s===e)return{x:s.x*jr,y:s.y*jr};const n=wa(t);return sa({x:n[0],y:n[1]})}(s,e.id,t.layout,t.cfg),o=(n.x-m[0])/m[2]*100,r=(n.y-m[1])/m[3]*100,a=Math.min(1,i.opacity+.25);return W`
${s.name}
`}):[],y=e.bg?t.displayUrl?t.displayUrl(e.bg.href):e.bg.href:"",b=t.cfg.spaces.find(e=>e.id===t.spaceId)?.settings||{};let w="";if("daynight"===yo(t.cfg?.settings,b)&&null!==vo(t.cfg?.settings,b)){const e=wo(t.hass);e&&(w=co(e.elevation).bg)}const k=w||Pi(t.cfg?.settings,i),$=d.length?wr(e.rooms,d,[],Jr,p,Yr,Lr):Ae(e.rooms),x=Ai(t.cfg.settings),S=(d.length||u.length)&&i.showBorders?yr(e.rooms,d,[],[],Jr,p,Yr,Lr,u):null,M=t.stageWidth&&m[2]?t.stageWidth/m[2]:1,C=!!S&&Io(S.depthUnits,M),D=i.color||"#607d8b";return W`
+ style="left:${o}%;top:${r}%;color:${i.color};opacity:${a}">${s.name}
`}):[],y=e.bg?t.displayUrl?t.displayUrl(e.bg.href):e.bg.href:"",b=t.cfg.spaces.find(e=>e.id===t.spaceId)?.settings||{};let w="";if("daynight"===yo(t.cfg?.settings,b)&&null!==vo(t.cfg?.settings,b)){const e=wo(t.hass);e&&(w=co(e.elevation).bg)}const k=w||Pi(t.cfg?.settings,i),$=d.length?wr(e.rooms,d,[],ea,p,ta,jr):Ae(e.rooms),x=Ai(t.cfg.settings),S=(d.length||u.length)&&i.showBorders?yr(e.rooms,d,[],[],ea,p,ta,jr,u):null,M=t.stageWidth&&m[2]?t.stageWidth/m[2]:1,C=!!S&&Io(S.depthUnits,M),D=i.color||"#607d8b";return W`
${""}
-
${f}${v}
+
${f}${v}
- `}ll.properties={hass:{attribute:!1},_config:{state:!0},_spaces:{state:!0}},customElements.get("houseplan-card-editor")||customElements.define("houseplan-card-editor",ll);let dl=null,pl=null,ul=!1;const _l=new Set;function ml(){if(dl)return dl;try{const t=JSON.parse(localStorage.getItem("houseplan_card_cfg_v1")||"null");if(t&&t.config&&Array.isArray(t.config.spaces))return{config:t.config,rev:t.rev||0,layout:t.layout||{}}}catch{}return null}function gl(t){return dl?Promise.resolve(dl):pl||(pl=async function(t){const[e,i]=await Promise.all([t.callWS({type:"houseplan/config/get"}),t.callWS({type:"houseplan/layout/get"})]);if(dl={config:e?.config??null,rev:e?.rev??0,layout:i?.layout??{}},!ul&&t.connection?.subscribeEvents){ul=!0;const e=()=>{dl=null,_l.forEach(t=>t())};try{await t.connection.subscribeEvents(e,"houseplan_config_updated"),await t.connection.subscribeEvents(e,"houseplan_layout_updated")}catch{ul=!1}}return dl}(t).finally(()=>{pl=null}),pl)}class fl extends lt{constructor(){super(...arguments),this._spaces=null,this._spacesLoading=!1}setConfig(t){this._config=t}async _loadSpaces(){if(!this._spaces&&!this._spacesLoading&&this.hass){this._spacesLoading=!0;try{const t=await this.hass.callWS({type:"houseplan/config/get"});this._spaces=(t?.config?.spaces||[]).map(t=>({value:t.id,label:t.title||t.id}))}catch{this._spaces=[]}finally{this._spacesLoading=!1}}}get _lang(){return Nn(this.hass,this._config?.language)}get _schema(){const t=this._spaces||[];return[t.length?{name:"space",selector:{select:{mode:"dropdown",options:t}}}:{name:"space",selector:{text:{}}},{name:"title",selector:{text:{}}},{name:"show_button",selector:{boolean:{}}},{name:"button_label",selector:{text:{}}},{name:"button_target",selector:{text:{}}},{name:"icon_size",selector:{number:{min:1,max:6,step:.1,mode:"box"}}},{name:"show_temperature",selector:{boolean:{}}},{name:"live_states",selector:{boolean:{}}},{name:"show_signal",selector:{boolean:{}}}]}render(){if(!this.hass||!this._config)return G;this._loadSpaces();const t=this._lang,e={space:On(t,"editor.space"),title:On(t,"editor.title"),show_button:On(t,"editor.show_button"),button_label:On(t,"editor.button_label"),button_target:On(t,"editor.button_target"),icon_size:On(t,"editor.icon_size"),show_temperature:On(t,"editor.show_temperature"),live_states:On(t,"editor.live_states"),show_signal:On(t,"editor.show_signal")};return W`
{gl=null,yl.forEach(t=>t())};try{await t.connection.subscribeEvents(e,"houseplan_config_updated"),await t.connection.subscribeEvents(e,"houseplan_layout_updated")}catch{vl=!1}}return gl}(t).finally(()=>{fl=null}),fl)}class kl extends lt{constructor(){super(...arguments),this._spaces=null,this._spacesLoading=!1}setConfig(t){this._config=t}async _loadSpaces(){if(!this._spaces&&!this._spacesLoading&&this.hass){this._spacesLoading=!0;try{const t=await this.hass.callWS({type:"houseplan/config/get"});this._spaces=(t?.config?.spaces||[]).map(t=>({value:t.id,label:t.title||t.id}))}catch{this._spaces=[]}finally{this._spacesLoading=!1}}}get _lang(){return Nn(this.hass,this._config?.language)}get _schema(){const t=this._spaces||[];return[t.length?{name:"space",selector:{select:{mode:"dropdown",options:t}}}:{name:"space",selector:{text:{}}},{name:"title",selector:{text:{}}},{name:"show_button",selector:{boolean:{}}},{name:"button_label",selector:{text:{}}},{name:"button_target",selector:{text:{}}},{name:"icon_size",selector:{number:{min:1,max:6,step:.1,mode:"box"}}},{name:"show_temperature",selector:{boolean:{}}},{name:"live_states",selector:{boolean:{}}},{name:"show_signal",selector:{boolean:{}}}]}render(){if(!this.hass||!this._config)return G;this._loadSpaces();const t=this._lang,e={space:On(t,"editor.space"),title:On(t,"editor.title"),show_button:On(t,"editor.show_button"),button_label:On(t,"editor.button_label"),button_target:On(t,"editor.button_target"),icon_size:On(t,"editor.icon_size"),show_temperature:On(t,"editor.show_temperature"),live_states:On(t,"editor.live_states"),show_signal:On(t,"editor.show_signal")};return W`e[t.name]||t.name}
@value-changed=${this._valueChanged}
- >`}_valueChanged(t){const e={...this._config||{},...t.detail.value};delete e.aspect_ratio;const i=new Event("config-changed",{bubbles:!0,composed:!0});i.detail={config:e},this.dispatchEvent(i)}}fl.properties={hass:{attribute:!1},_config:{state:!0},_spaces:{state:!0}},customElements.get("houseplan-space-card-editor")||customElements.define("houseplan-space-card-editor",fl);const vl=t=>{history.pushState(null,"",t),((t,e,i)=>{const s=new Event(e,{bubbles:!0,composed:!0});s.detail=i??{},t.dispatchEvent(s)})(window,"location-changed",{replace:!1})};class yl extends lt{constructor(){super(...arguments),this._snap=null,this._loading=!1,this._stageWidth=0,this._haRegistryConnection=null,this._haRegistryRevision=-1,this._devices=[],this._activityRuntime=new Map,this._onHaRegistryUpdate=()=>{const t=As(this.hass).revision;t!==this._haRegistryRevision&&(this._haRegistryRevision=t,this.requestUpdate())},this._loadedOnce=!1,this._signer=new Va(()=>this.requestUpdate()),this._goToSpace=()=>{const t=(this._config?.button_target||"/plan-doma").replace(/#.*$/,"");vl(`${t}#space=${encodeURIComponent(this._config.space)}`)}}_ensureHaRegistryAuthority(){const t=this.hass?.connection||null;t&&t!==this._haRegistryConnection&&(this._haRegistryRelease?.(),this._haRegistryConnection=t,this._haRegistryRevision=-1,this._haRegistryRelease=zs(this.hass,this._onHaRegistryUpdate),this._onHaRegistryUpdate())}static getConfigElement(){return document.createElement("houseplan-space-card-editor")}static getStubConfig(t){const e=ml();return{type:"custom:houseplan-space-card",space:jr(e?.config||null)[0]?.id||"",show_button:!0,live_states:!0,show_temperature:!0,show_signal:!0}}setConfig(t){if(!t||!t.space)throw new Error('houseplan-space-card: "space" is required');this._config={show_button:!0,button_target:"/plan-doma",live_states:!0,show_temperature:!0,show_signal:!0,...t},this._snap=this._snap||ml()}connectedCallback(){var t;super.connectedCallback(),this.hass&&this._ensureHaRegistryAuthority(),this._unsub=(t=()=>{this._loading=!1,this._snap=null,this.requestUpdate()},_l.add(t),()=>_l.delete(t)),this._signer.start(()=>this.hass,()=>this._referenced())}disconnectedCallback(){this._unsub?.(),this._unsub=void 0,this._stageObserver?.disconnect(),this._stageObserver=void 0,this._observedStage=void 0,this._signer.dispose(),this._haRegistryRelease?.(),this._haRegistryRelease=void 0,this._haRegistryConnection=null;for(const t of this._activityRuntime.values())window.clearTimeout(t.timer);this._activityRuntime.clear(),super.disconnectedCallback()}willUpdate(t){t.has("hass")&&this.hass&&this._ensureHaRegistryAuthority(),!this.hass||this._loading||this._snap&&!t.has("hass")||this._snap&&this._loadedOnce||this._load(),this._refreshDevices()}_stampActivity(t,e){t.flashTs&&Date.now()-t.flashTs<3300&&"event"===t.flashKind&&"transition"===e||(t.flashTs=Date.now(),t.flashKind=e,t.gen++,window.clearTimeout(t.timer),t.timer=window.setTimeout(()=>this.requestUpdate(),3360))}_syncActivity(t,e){if(!1===this._config?.live_states){for(const t of this._activityRuntime.values())window.clearTimeout(t.timer);return void this._activityRuntime.clear()}const i=new Set;for(const s of t){if(s.hidden)continue;if("static_icon"===li(s.marker?.display))continue;i.add(s.id);const t=yn(e,s),n=t.samples,o=kn(e,s,!1!==this._config?.show_temperature,t);let r=this._activityRuntime.get(s.id);if(!r||r.sources!==o){r&&window.clearTimeout(r.timer),r={sources:o,last:Object.fromEntries(n.map(t=>[t.eid,t.state])),flashTs:0,flashKind:null,timer:0,gen:0},this._activityRuntime.set(s.id,r);continue}"transition"===r.flashKind&&n.some(t=>"transition"===t.activity)&&(window.clearTimeout(r.timer),r.flashTs=0,r.flashKind=null);let a=null;for(const t of n){const e=ws(r.last[t.eid],t);("event"===e||!a&&e)&&(a=e),r.last[t.eid]=t.state}a&&this._stampActivity(r,a)}for(const[t,e]of this._activityRuntime)i.has(t)||(window.clearTimeout(e.timer),this._activityRuntime.delete(t))}_refreshDevices(){if(!this.hass||!this._snap?.config||!this._config)return;const t=As(this.hass),e=cl({hass:this.hass,registry:t,cfg:this._snap.config,lang:this._lang});this._syncActivity(e,Os(this.hass,t)),this._devices=e}updated(){const t=this.renderRoot.querySelector(".hp-static-stage")||void 0;if(t===this._observedStage)return;if(this._stageObserver?.disconnect(),this._observedStage=t,!t)return void(this._stageObserver=void 0);const e=()=>{const e=t.clientWidth;e>0&&Math.abs(e-this._stageWidth)>.5&&(this._stageWidth=e,this.requestUpdate())};this._stageObserver=new ResizeObserver(e),this._stageObserver.observe(t),e()}async _load(){if(this.hass&&!this._loading){this._loading=!0;try{const t=await gl(this.hass);this._snap=t,this._loadedOnce=!0}catch{}finally{this._loading=!1,this.requestUpdate()}}}get _lang(){return Nn(this.hass,this._config?.language)}getCardSize(){const t=jr(this._snap?.config||null).find(t=>t.id===this._config?.space);if(t){const e=t.vb[3]/t.vb[2];return Math.max(3,Math.round(8*e))+(!1===this._config?.show_button?0:1)}return 6}_errorCard(t){return W`${t}
`}_referenced(){return Zi(this._snap?.config)}render(){if(!this._config)return G;const t=this._snap?.config;if(!t)return W`${On(this._lang,"space_card.loading")}
`;const e=this._config.space,i=hl({hass:this.hass,cfg:t,layout:this._snap?.layout||{},spaceId:e,iconSize:this._config.icon_size,stageWidth:this._stageWidth,lang:this._lang,displayUrl:t=>this._signer.display(this.hass,t),registry:As(this.hass),devices:this._devices,activityRuntime:this._activityRuntime,liveStates:!1!==this._config.live_states,showTemperature:!1!==this._config.show_temperature,showSignal:!1!==this._config.show_signal});if(!i)return this._errorCard(On(this._lang,"space_card.not_found",{id:e}));const s=jr(t).find(t=>t.id===e),n=void 0!==this._config.title?this._config.title:s?.title||"",o=!1!==this._config.show_button,r=this._config.button_label||On(this._lang,"space_card.button");return W`
+ >`}_valueChanged(t){const e={...this._config||{},...t.detail.value};delete e.aspect_ratio;const i=new Event("config-changed",{bubbles:!0,composed:!0});i.detail={config:e},this.dispatchEvent(i)}}kl.properties={hass:{attribute:!1},_config:{state:!0},_spaces:{state:!0}},customElements.get("houseplan-space-card-editor")||customElements.define("houseplan-space-card-editor",kl);const $l=t=>{history.pushState(null,"",t),((t,e,i)=>{const s=new Event(e,{bubbles:!0,composed:!0});s.detail=i??{},t.dispatchEvent(s)})(window,"location-changed",{replace:!1})};class xl extends lt{constructor(){super(...arguments),this._snap=null,this._loading=!1,this._stageWidth=0,this._haRegistryConnection=null,this._haRegistryRevision=-1,this._devices=[],this._activityRuntime=new Map,this._onHaRegistryUpdate=()=>{const t=As(this.hass).revision;t!==this._haRegistryRevision&&(this._haRegistryRevision=t,this.requestUpdate())},this._loadedOnce=!1,this._signer=new Qa(()=>this.requestUpdate()),this._goToSpace=()=>{const t=(this._config?.button_target||"/plan-doma").replace(/#.*$/,"");$l(`${t}#space=${encodeURIComponent(this._config.space)}`)}}_ensureHaRegistryAuthority(){const t=this.hass?.connection||null;t&&t!==this._haRegistryConnection&&(this._haRegistryRelease?.(),this._haRegistryConnection=t,this._haRegistryRevision=-1,this._haRegistryRelease=zs(this.hass,this._onHaRegistryUpdate),this._onHaRegistryUpdate())}static getConfigElement(){return document.createElement("houseplan-space-card-editor")}static getStubConfig(t){const e=bl();return{type:"custom:houseplan-space-card",space:Jr(e?.config||null)[0]?.id||"",show_button:!0,live_states:!0,show_temperature:!0,show_signal:!0}}setConfig(t){if(!t||!t.space)throw new Error('houseplan-space-card: "space" is required');this._config={show_button:!0,button_target:"/plan-doma",live_states:!0,show_temperature:!0,show_signal:!0,...t},this._snap=this._snap||bl()}connectedCallback(){var t;super.connectedCallback(),this.hass&&this._ensureHaRegistryAuthority(),this._unsub=(t=()=>{this._loading=!1,this._snap=null,this.requestUpdate()},yl.add(t),()=>yl.delete(t)),this._signer.start(()=>this.hass,()=>this._referenced())}disconnectedCallback(){this._unsub?.(),this._unsub=void 0,this._stageObserver?.disconnect(),this._stageObserver=void 0,this._observedStage=void 0,this._signer.dispose(),this._haRegistryRelease?.(),this._haRegistryRelease=void 0,this._haRegistryConnection=null;for(const t of this._activityRuntime.values())window.clearTimeout(t.timer);this._activityRuntime.clear(),super.disconnectedCallback()}willUpdate(t){t.has("hass")&&this.hass&&this._ensureHaRegistryAuthority(),!this.hass||this._loading||this._snap&&!t.has("hass")||this._snap&&this._loadedOnce||this._load(),this._refreshDevices()}_stampActivity(t,e){t.flashTs&&Date.now()-t.flashTs<3300&&"event"===t.flashKind&&"transition"===e||(t.flashTs=Date.now(),t.flashKind=e,t.gen++,window.clearTimeout(t.timer),t.timer=window.setTimeout(()=>this.requestUpdate(),3360))}_syncActivity(t,e){if(!1===this._config?.live_states){for(const t of this._activityRuntime.values())window.clearTimeout(t.timer);return void this._activityRuntime.clear()}const i=new Set;for(const s of t){if(s.hidden)continue;if("static_icon"===li(s.marker?.display))continue;i.add(s.id);const t=yn(e,s),n=t.samples,o=kn(e,s,!1!==this._config?.show_temperature,t);let r=this._activityRuntime.get(s.id);if(!r||r.sources!==o){r&&window.clearTimeout(r.timer),r={sources:o,last:Object.fromEntries(n.map(t=>[t.eid,t.state])),flashTs:0,flashKind:null,timer:0,gen:0},this._activityRuntime.set(s.id,r);continue}"transition"===r.flashKind&&n.some(t=>"transition"===t.activity)&&(window.clearTimeout(r.timer),r.flashTs=0,r.flashKind=null);let a=null;for(const t of n){const e=ws(r.last[t.eid],t);("event"===e||!a&&e)&&(a=e),r.last[t.eid]=t.state}a&&this._stampActivity(r,a)}for(const[t,e]of this._activityRuntime)i.has(t)||(window.clearTimeout(e.timer),this._activityRuntime.delete(t))}_refreshDevices(){if(!this.hass||!this._snap?.config||!this._config)return;const t=As(this.hass),e=_l({hass:this.hass,registry:t,cfg:this._snap.config,lang:this._lang});this._syncActivity(e,Os(this.hass,t)),this._devices=e}updated(){const t=this.renderRoot.querySelector(".hp-static-stage")||void 0;if(t===this._observedStage)return;if(this._stageObserver?.disconnect(),this._observedStage=t,!t)return void(this._stageObserver=void 0);const e=()=>{const e=t.clientWidth;e>0&&Math.abs(e-this._stageWidth)>.5&&(this._stageWidth=e,this.requestUpdate())};this._stageObserver=new ResizeObserver(e),this._stageObserver.observe(t),e()}async _load(){if(this.hass&&!this._loading){this._loading=!0;try{const t=await wl(this.hass);this._snap=t,this._loadedOnce=!0}catch{}finally{this._loading=!1,this.requestUpdate()}}}get _lang(){return Nn(this.hass,this._config?.language)}getCardSize(){const t=Jr(this._snap?.config||null).find(t=>t.id===this._config?.space);if(t){const e=t.vb[3]/t.vb[2];return Math.max(3,Math.round(8*e))+(!1===this._config?.show_button?0:1)}return 6}_errorCard(t){return W`
${t}
`}_referenced(){return Zi(this._snap?.config)}render(){if(!this._config)return G;const t=this._snap?.config;if(!t)return W`
${On(this._lang,"space_card.loading")}
`;const e=this._config.space,i=ml({hass:this.hass,cfg:t,layout:this._snap?.layout||{},spaceId:e,iconSize:this._config.icon_size,stageWidth:this._stageWidth,lang:this._lang,displayUrl:t=>this._signer.display(this.hass,t),registry:As(this.hass),devices:this._devices,activityRuntime:this._activityRuntime,liveStates:!1!==this._config.live_states,showTemperature:!1!==this._config.show_temperature,showSignal:!1!==this._config.show_signal});if(!i)return this._errorCard(On(this._lang,"space_card.not_found",{id:e}));const s=Jr(t).find(t=>t.id===e),n=void 0!==this._config.title?this._config.title:s?.title||"",o=!1!==this._config.show_button,r=this._config.button_label||On(this._lang,"space_card.button");return W`
${n?W`${n}
`:G}
${i}
@@ -3279,7 +3279,7 @@ const t=globalThis,e=t.ShadowRoot&&(void 0===t.ShadyCSS||t.ShadyCSS.nativeShadow
`:G}
- `}}yl.properties={hass:{attribute:!1},_config:{state:!0},_snap:{state:!0}},yl.styles=[_t,o`
+ `}}xl.properties={hass:{attribute:!1},_config:{state:!0},_snap:{state:!0}},xl.styles=[_t,o`
.hp-static-title {
font-weight: 700;
padding: 10px 14px 6px;
@@ -3354,7 +3354,7 @@ const t=globalThis,e=t.ShadowRoot&&(void 0===t.ShadyCSS||t.ShadyCSS.nativeShadow
text-align: center;
color: var(--secondary-text-color, #9aa4ad);
}
- `],customElements.get("houseplan-space-card")||customElements.define("houseplan-space-card",yl),window.customCards=window.customCards||[],window.customCards.find(t=>"houseplan-space-card"===t.type)||window.customCards.push({type:"houseplan-space-card",name:"House Plan — Space (static)",description:"Read-only live schematic of a single houseplan space, with a deep-link button.",preview:!1,documentation:"https://github.com/Matysh/houseplan-card"});const bl=4.166666666666667e-9;function wl(t){if(!Number.isFinite(t))return t;const e=Math.round(t/Jr)*Jr;return Math.abs(e-t)<=bl?t:e}const kl=(t,e,i,s)=>Math.hypot(i-t,s-e),$l=(t,e,i,s,n,o,r,a)=>Math.hypot(Math.max(Math.abs(n-t),Math.abs(n+r-(t+i))),Math.max(Math.abs(o-e),Math.abs(o+a-(e+s)))),xl=(t,e,i,s,n,o,r)=>{const a=Math.max(Number(s)||0,0)/2,l=Math.PI/180,c=Math.cos(i*l)*a,h=Math.sin(i*l)*a,d=Math.cos(r*l)*a,p=Math.sin(r*l)*a,u=Math.max(kl(t+c,e+h,n+d,o+p),kl(t-c,e-h,n-d,o-p)),_=Math.max(kl(t+c,e+h,n-d,o-p),kl(t-c,e-h,n+d,o+p));return Math.min(u,_)},Sl=t=>{const e=Number(t?.cell_cm);return e>0?e:5};const Ml=t=>JSON.parse(JSON.stringify(t)),Cl=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),Dl=(t,e,i)=>Math.min(i,Math.max(e,t)),Tl=t=>jr({spaces:[t]})[0],Pl=t=>{const e=[];for(const i of t||[]){const t=ze(i);if(t?.length)for(let i=0;i