Files
houseplan-card/dist/houseplan-assets/live-interaction-runtime-DjzpPNim.js
T
2026-09-23 02:00:48 +03:00

2 lines
8.0 KiB
JavaScript

globalThis.__HOUSEPLAN_BUILD_FINGERPRINT__="2c4a9a013205eef84710c72e2eae1f8c307d94c84078490ecded141d206dd07d";import{ec as e}from"./houseplan-card-eH_pY1mf.js";const t=new WeakMap,o=e=>{let o=t.get(e);return o||(o={painted:null,pending:null,raf:0,anchor:null},t.set(e,o)),o},n=e=>`${e.x} ${e.y} ${e.w} ${e.h}`;function r(e,t){return{translateXPercent:(e.x-t.x)/t.w*100,translateYPercent:(e.y-t.y)/t.h*100,scaleX:e.w/t.w,scaleY:e.h/t.h}}const a=e=>0===e.translateXPercent&&0===e.translateYPercent&&1===e.scaleX&&1===e.scaleY,i=.15;const s=e=>[e.x,e.y,e.w,e.h].every(Number.isFinite)&&e.w>0&&e.h>0,l=(e,t,o={})=>{const n=e.style;if(!t)return o.exposeSceneOverflow&&"visible"===n.overflow&&n.removeProperty("overflow"),void(n.transform&&(n.removeProperty("transform"),n.removeProperty("transform-origin"),n.removeProperty("will-change")));o.exposeSceneOverflow&&"visible"!==n.overflow&&(n.overflow="visible");const r=(e=>`translate(${e.translateXPercent}%,${e.translateYPercent}%) scale(${e.scaleX},${e.scaleY})`)(t);"0 0"!==n.transformOrigin&&"0px 0px"!==n.transformOrigin&&(n.transformOrigin="0 0"),"transform"!==n.willChange&&(n.willChange="transform"),n.transform!==r&&(n.transform=r)},c=(e,t)=>{e.getAttribute("viewBox")!==t&&e.setAttribute("viewBox",t)};function d(e,t,o,d,f={}){const u=f.now??("undefined"!=typeof performance?performance.now():Date.now()),h=d??{frame:t,at:-1/0};if(!s(t.view)||!s(o.view)||!s(o.floor))return h;const m=!0===f.force||!s(h.frame.view)||!s(h.frame.floor)||function(e,t,o){if(o-e.at>=100)return!0;const n=e.frame.view,r=t.view;if(Math.abs(r.x-n.x)>=r.w*i)return!0;if(Math.abs(r.y-n.y)>=r.h*i)return!0;const a=n.w/r.w;return Math.abs(1-a)>=i}(h,o,u),p=m?{frame:o,at:u}:h;if(m){const t=n(o.view),r=n(o.floor);for(const o of e.querySelectorAll('[data-hp-live-viewbox="camera"]'))c(o,t);for(const t of e.querySelectorAll('[data-hp-live-viewbox="floor"]'))c(t,r)}const v=r(p.frame.view,o.view),_=r(p.frame.floor,o.floor),g=!0===f.keepSceneLayer;for(const t of e.querySelectorAll('[data-hp-live-viewbox="camera"]'))l(t,a(v)&&!g?null:v,{exposeSceneOverflow:!0});for(const t of e.querySelectorAll('[data-hp-live-viewbox="floor"]'))l(t,a(_)&&!g?null:_,{exposeSceneOverflow:!0});const w=r(t.view,o.view);for(const t of e.querySelectorAll('[data-hp-live-layer="camera"]'))l(t,a(w)?null:w);const y=e.querySelector("[data-hp-live-zoom]");if(y){const e=o.zoom<=1;y.hidden!==e&&(y.hidden=e);const t=y.querySelector("[data-hp-live-zoom-value]"),n=`${Math.round(100*o.zoom)}%`;t&&t.textContent!==n&&(t.textContent=n)}return p}const f=e=>{const t=e._viewOr(e._baseVb());return{view:{...t},floor:{...e._floorView(t)},zoom:e._zoom}};const u=new WeakMap,h=new WeakMap,m=(e,t)=>{const o=e._spaceDisplayForRender().showLqi??e._config?.show_signal??!0,n=e._devicePresentation(t,o),r=n.haDisabled?e._t(`marker.ha_disabled_${n.disabledReason}`):t.userHidden?e._t("marker.hidden_ghost"):t.name,a=[t.model,n.valueBadge?.fullText||"",null!=n.lqiText?`LQI ${n.lqiText}`:""].filter(Boolean).join(" · ");return{title:t.name,meta:n.haDisabled?r:a}};const p=e=>{h.delete(e)},v=(e,t,o,n)=>{if(!o)return;const r=document.createElement("span");if(r.className="m",t){r.append(`${t} `);const e=document.createElement("b");e.textContent=o,n&&(e.style.color=n),r.append(e)}else r.textContent=o;e.append(r)},_=(t,o)=>{const n=o.querySelector("[data-hp-live-tip]");if(!n)return;const r=t._tip;if(!r)return n.hidden=!0,void n.replaceChildren();n.style.left=`${r.x+12}px`,n.style.top=`${r.y+12}px`,n.replaceChildren();const a=document.createElement("b");a.textContent=r.title,n.append(a),v(n,"",r.meta),v(n,t._t("tip.temp_avg"),null==r.temp?"":`${r.temp}°`),v(n,t._t("tip.hum_avg"),null==r.hum?"":`${r.hum}%`),v(n,t._t("tip.lqi"),null==r.lqi?"":String(r.lqi),null==r.lqi?void 0:e(r.lqi)),n.hidden=!1;const i=n.getBoundingClientRect(),s=Math.max(8,window.innerWidth-i.width-8),l=Math.max(8,window.innerHeight-i.height-8);n.style.left=`${Math.min(s,Math.max(8,r.x+12))}px`,n.style.top=`${Math.min(l,Math.max(8,r.y+12))}px`},g=(e,t,o)=>{const n=e.querySelector(t);n&&(n.setAttribute("d",o),n.toggleAttribute("hidden",!o))};function w(e){const t=e,o=t.renderRoot;if(!o)return;_(t,o);const n=t._hoverRoom,r=u.get(e),a=n?.space||"",i=n?.room||null;if(r?.room===i&&r?.space===a)return;u.set(e,{room:i,space:a});const s=n&&t._spaceModel(),l=s?t._roomHoverPaths(s):null;g(o,'[data-hp-live-room-hover="fill"]',l?.fillD||""),g(o,'[data-hp-live-room-hover="halo"]',l?.outlineD||""),g(o,'[data-hp-live-room-hover="outline"]',l?.outlineD||"")}function y(e){u.delete(e)}class x{constructor(e){this.host=e,this.deferredHass=!1}hass(e,t,o,n){const r=function(e,t,o){if(e===t)return"none";if(!e||!t||!o)return"structural";if(e.connection!==t.connection||e.entities!==t.entities||e.devices!==t.devices||e.areas!==t.areas||e.themes!==t.themes||e.user!==t.user||e.config!==t.config||e.floors!==t.floors||e.services!==t.services||e.panels!==t.panels||e.language!==t.language||e.locale?.language!==t.locale?.language||e.locale?.number_format!==t.locale?.number_format||e.locale?.time_format!==t.locale?.time_format||e.locale?.date_format!==t.locale?.date_format)return"structural";const n=new Set(["states","connection","entities","devices","areas","themes","user","config","floors","services","panels","language","locale"]);for(const o of new Set([...Object.keys(e),...Object.keys(t)]))if(!n.has(o)&&e[o]!==t[o])return"structural";for(const n of o.entityIds)if(e.states?.[n]!==t.states?.[n])return"state";return"none"}(e,t,o),a="state"===r&&this.active();a&&(this.deferredHass=!0);const i="none"!==r&&!a;return i||this.host._renderLife.observe(e,t,o,n),i}clear(){this.deferredHass=!1}take(){const e=this.deferredHass;return this.deferredHass=!1,e}viewport(e=!1){!function(e,t=!1){const n=e,r=o(e),a=f(n);if(t)return r.raf&&"function"==typeof cancelAnimationFrame&&cancelAnimationFrame(r.raf),r.raf=0,r.pending=null,r.painted||(r.painted=a),void(r.anchor=d(n.renderRoot,r.painted,a,r.anchor,{keepSceneLayer:!0}));r.pending=a,r.raf||"function"!=typeof requestAnimationFrame||(r.raf=requestAnimationFrame(()=>{r.raf=0;const e=r.pending;r.pending=null;const t=n.renderRoot;e&&t&&(r.painted||(r.painted=e),r.anchor=d(t,r.painted,e,r.anchor,{keepSceneLayer:!0}))}))}(this.host,e)}hover(){w(this.host)}devicePointerTip(e,t){!function(e,t,o){const n=e;if(n._notePointer(t),!n._pointerModality.hoverEnabled||n._drag||n._deviceDrag)return void n._deviceHits.hover(n.renderRoot,null);const r=m(n,o);n._deviceHits.hover(n.renderRoot,o.id),n._showTip(t,r.title,r.meta)}(this.host,e,t)}deviceFocusTip(e,t){!function(e,t,o){const n=e;if("view"!==n._mode||n._drag||n._deviceDrag||!t?.matches(":focus-visible"))return;const r=t.getBoundingClientRect(),a={x:r.right,y:r.top,...m(n,o),source:"focus",deviceId:o.id};h.set(e,a),n._tip=a,w(n)}(this.host,e,t)}deviceBlur(e){!function(e,t){const o=e;h.get(e)?.deviceId===t&&(h.delete(e),"focus"===o._tip?.source&&(o._tip=null),w(o))}(this.host,e)}pointerLeave(){!function(e){const t=e;t._deviceHits.hover(t.renderRoot,null),t._tip=h.get(e)||null,t._hoverRoom=null,w(t)}(this.host)}deviceFocusActive(){return e=this.host,h.has(e);var e}clearDeviceFocus(){p(this.host)}active(){const e=this.host;return e._pointers.size>0||e._cameraTransition.active||!!e._deviceDrag||!!e._physicalDrag||!!e._physicalRotate||!!e._decorMove||!!e._decorDraft||!!e._dtDrag||!!e._bdDrag||!!e._opDrag||!!e._resize?.dragging}commit(){!function(e,t=!1){const n=e,r=o(e);r.raf&&"function"==typeof cancelAnimationFrame&&cancelAnimationFrame(r.raf),r.raf=0,r.pending=null,r.painted=f(n);const a=n.renderRoot;if(a){for(const e of a.querySelectorAll('[data-hp-live-layer="camera"]'))l(e,null);r.anchor=d(a,r.painted,r.painted,r.anchor,{force:!0,keepSceneLayer:t})}}(this.host,this.active()),function(e){const t=e,o=h.get(e);if(!o)return;const n=[...t.renderRoot.querySelectorAll('[data-hp="device"]')].find(e=>e.dataset.id===o.deviceId);n?.matches(":focus-visible")||(h.delete(e),"focus"===t._tip?.source&&(t._tip=null))}(this.host),y(this.host),w(this.host)}dispose(){!function(e){const o=t.get(e);o?.raf&&"function"==typeof cancelAnimationFrame&&cancelAnimationFrame(o.raf),t.delete(e)}(this.host),p(this.host),y(this.host)}}export{x as LiveRuntime};