diff --git a/CHANGELOG.md b/CHANGELOG.md index 511b47b..737664c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,8 @@ All notable changes to NextFloor, newest first. Every release lists what is **Ad ### Fixed +- **IP-Symcon dimmers and venetian blinds:** Numeric variables can be explicitly linked as dimmers or blind controls independently of inferred names. Native integer/float ranges and steps are respected in both directions. Separate blind-height and slat-position variables can be selected in the object tree and controlled independently in the room panel and quick menu; dimmer sliders stay available while off. + - **IP-Symcon KNX room temperatures:** Current Symcon presentation units are read alongside legacy profiles. Numeric temperature variables remain selectable and readable even when a parent name caused an actuator classification; saved mappings stay intact. - **IP-Symcon “HTTP 200” / output-buffer overflow:** Large API responses use bounded response chunks instead of exceeding the kernel's 1 MiB output limit. The full variable/object tree, packs, plans, images and backups are reassembled without data loss, polling cannot overlap, and malformed responses receive a useful error message. diff --git a/custom_components/nextfloor/frontend/nextfloor-3d.js b/custom_components/nextfloor/frontend/nextfloor-3d.js index 6cc489c..1d34c79 100644 --- a/custom_components/nextfloor/frontend/nextfloor-3d.js +++ b/custom_components/nextfloor/frontend/nextfloor-3d.js @@ -4296,7 +4296,7 @@ vNfTile = tile;`,xR=`#ifdef USE_MAP vec4 sampledDiffuseColor = textureGrad(map, nfUv, dFdx(vMapUv) / vec2(3.0, 2.0), dFdy(vMapUv) / vec2(3.0, 2.0)); diffuseColor *= sampledDiffuseColor; #endif`;function bR(i){let e=new Ke({map:i,transparent:!0,blending:Ft,depthWrite:!1,polygonOffset:!0,polygonOffsetFactor:-2});return e.onBeforeCompile=t=>{t.vertexShader=t.vertexShader.replace("#include ",mR).replace("#include ",gR),t.fragmentShader=t.fragmentShader.replace("#include ",`#include -varying vec2 vNfTile;`).replace("#include ",xR)},e.customProgramCacheKey=()=>"nf-pattern",e}var qu=(i={})=>new Ke({vertexColors:!0,transparent:!0,blending:Ft,depthWrite:!1,...i});function Ty({mask:i,look:e,theme:t,textures:n}){let r=(o={})=>new Ke({vertexColors:!0,...o}),s=(o,a)=>My(o,i,a);return{floor:Zn(r(),e),pattern:bR(n.pattern),wall:Zn(s(r(),"solid"),e),glassWall:s(r({transparent:!0,depthWrite:!1}),"glass"),shadow:r({blending:za,premultipliedAlpha:!0,transparent:!0,depthWrite:!1,side:ut,polygonOffset:!0,polygonOffsetFactor:-1}),lines:Zn(s(new Lt({vertexColors:!0,transparent:!0,blending:xl(t),depthWrite:!1})),e,!0),glow:s(qu({side:ut,polygonOffset:!0,polygonOffsetFactor:-3}),"solid"),frames:Zn(s(r({side:ut})),e),glass:s(qu({side:ut})),blinds:Zn(s(r({map:n.blinds,side:ut})),e),lamps:Zn(r(),e),halos:new cn({map:n.halo,size:.9,sizeAttenuation:!0,vertexColors:!0,transparent:!0,blending:Ft,depthWrite:!1}),cones:qu({side:ut}),screens:qu({side:ut}),ghosts:[]}}var $u=i=>Object.assign(document.createElement("span"),{className:i});function Ay(i,e){let t=Object.assign(document.createElement("button"),{className:"nf-dev"});t.dataset.entity=i,t.append($u("nf-dev-icon"),$u("nf-dev-text"),$u("nf-dev-watt"),$u("nf-dev-name"));let n,r=!1,s=a=>{let{x:l,y:c}=e.centre(t);a(i,l,c)},o=()=>clearTimeout(n);t.addEventListener("pointerdown",a=>{if(e.furnishing())return e.pressedWhileFurnishing(i);a.stopPropagation(),r=!1,o(),n=setTimeout(()=>{r=!0,s(e.hold)},500)});for(let a of["pointerleave","pointercancel","pointerup"])t.addEventListener(a,o);return t.addEventListener("contextmenu",a=>a.preventDefault()),t.addEventListener("click",a=>{if(a.stopPropagation(),e.furnishing())return e.selectWhileFurnishing(i);r||s(e.tap)}),t.addEventListener("keydown",a=>{(a.key==="Enter"&&a.shiftKey||a.key==="ContextMenu")&&(a.preventDefault(),s(e.hold))}),t}function Ey(i,e=10,t="NextFloor"){let n=[];for(let{positions:o,lift:a}of i)for(let l=0;l+8[o[l+x]*e,-o[l+x+2]*e,(o[l+x+1]+a)*e]),[u,h,f]=c,d=[(h[1]-u[1])*(f[2]-u[2])-(h[2]-u[2])*(f[1]-u[1]),(h[2]-u[2])*(f[0]-u[0])-(h[0]-u[0])*(f[2]-u[2]),(h[0]-u[0])*(f[1]-u[1])-(h[1]-u[1])*(f[0]-u[0])],p=Math.hypot(d[0],d[1],d[2]);p<1e-9||n.push([d[0]/p,d[1]/p,d[2]/p,...u,...h,...f])}let r=new Uint8Array(84+n.length*50),s=new DataView(r.buffer);return r.set(new TextEncoder().encode(`${t} STL`.slice(0,79)),0),s.setUint32(80,n.length,!0),n.forEach((o,a)=>{let l=84+a*50;o.forEach((c,u)=>s.setFloat32(l+u*4,c,!0))}),r}var Rs=Math.PI/180;function Ry(i,e,t){let n=i.getTime()/864e5-10957.5,r=(357.529+.98560028*n)*Rs,o=(280.459+.98564736*n+1.915*Math.sin(r)+.02*Math.sin(2*r))*Rs,a=(23.439-36e-8*n)*Rs,l=Math.atan2(Math.cos(a)*Math.sin(o),Math.cos(o)),c=Math.asin(Math.sin(a)*Math.sin(o)),h=(((18.697374558+24.06570982441908*n)%24+24)%24*15+t)*Rs-l,f=e*Rs,d=Math.asin(Math.sin(f)*Math.sin(c)+Math.cos(f)*Math.cos(c)*Math.cos(h)),p=Math.atan2(Math.sin(h),Math.cos(h)*Math.sin(f)-Math.tan(c)*Math.cos(f))/Rs+180;return{elevation:d/Rs,azimuth:(p%360+360)%360}}function fp(i,e){let t=Object.fromEntries(new Intl.DateTimeFormat("en-US",{timeZone:e,hourCycle:"h23",year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric"}).formatToParts(new Date(i)).map(n=>[n.type,Number(n.value)]));return Date.UTC(t.year,t.month-1,t.day,t.hour,t.minute,t.second)}function Cy(i,e,t=new Date){let[n,r]=[Math.floor(i),Math.round(i%1*60)];if(e)try{let o=new Date(fp(t.getTime(),e)),a=Date.UTC(o.getUTCFullYear(),o.getUTCMonth(),o.getUTCDate(),n,r),l=a-(fp(a,e)-a);return l=a-(fp(l,e)-l),new Date(l)}catch{}let s=new Date(t);return s.setHours(n,r,0,0),s}function yR(i,e=new Date){let t=[];for(let n=0;n<=24;n+=.25){let r=Ry(Cy(Math.min(n,23.99),i.zone,e),i.latitude,i.longitude);r.elevation<0||t.push(Py(i,r))}return t}function Py(i,e){let[t,n]=Lo(e.azimuth,i.north),r=Math.max(0,e.elevation)*Math.PI/180;return[i.centre[0]+t*i.radius*Math.cos(r),Math.sin(r)*i.radius*.9,i.centre[1]+n*i.radius*Math.cos(r)]}function _R(i,e){let t=document.createElement("canvas");t.width=t.height=64;let n=t.getContext("2d");n&&(n.font="bold 44px system-ui, sans-serif",n.fillStyle=e,n.textAlign="center",n.textBaseline="middle",n.fillText(i,32,34));let r=new ji(new vi({map:new zt(t),transparent:!0,depthWrite:!1,depthTest:!1}));return r.renderOrder=20,r}var Ku=class{group=new ct;key="";constructor(){this.group.visible=!1,this.group.renderOrder=15}update(e,t,n){let r=e?`${e.centre},${e.radius.toFixed(1)},${e.north},${e.latitude.toFixed(2)},${e.longitude.toFixed(2)},${new Date().toDateString()},${n},${t?`${t.elevation.toFixed(0)},${t.azimuth.toFixed(0)}`:"-"}`:"off";if(r===this.key)return;if(this.key=r,this.clear(),!e){this.group.visible=!1;return}this.group.visible=!0;let s=n+.05,o=[];for(let h=0;h<=96;h++){let f=h/96*Math.PI*2;o.push(e.centre[0]+Math.cos(f)*e.radius,s,e.centre[1]+Math.sin(f)*e.radius)}let a=new Fe;a.setAttribute("position",new ke(o,3)),this.group.add(new Pn(a,new Lt({color:7311304,transparent:!0,opacity:.55,depthWrite:!1})));let l=[];[["N",0],["E",90],["S",180],["W",270]].forEach(([h,f])=>{let[d,p]=Lo(f,e.north);l.push(e.centre[0]+d*e.radius*.94,s,e.centre[1]+p*e.radius*.94,e.centre[0]+d*e.radius*1.04,s,e.centre[1]+p*e.radius*1.04);let x=_R(h,h==="N"?"#ff6b6b":"#9fb4d8");x.position.set(e.centre[0]+d*e.radius*1.12,s+.4,e.centre[1]+p*e.radius*1.12),x.scale.setScalar(Math.max(1.2,e.radius*.12)),this.group.add(x)});let c=new Fe;c.setAttribute("position",new ke(l,3)),this.group.add(new gn(c,new Lt({color:10466520,transparent:!0,opacity:.8,depthWrite:!1})));let u=yR(e).map(([h,f,d])=>[h,n+f,d]);if(u.length>1){let h=new Fe;h.setAttribute("position",new ke(u.flat(),3)),this.group.add(new Pn(h,new Lt({color:16761415,transparent:!0,opacity:.85,depthWrite:!1})))}if(t&&t.elevation>0){let[h,f,d]=Py(e,t),p=new we(new Ca(Math.max(.35,e.radius*.035),12,8),new Ke({color:16765530}));p.position.set(h,n+f,d),this.group.add(p)}}clear(){for(let e of[...this.group.children]){this.group.remove(e);let t=e;t.geometry?.dispose();let n=t.material;n?.map?.dispose(),n?.dispose()}}dispose(){this.clear()}};var vR=["straight","quarter","l","half","u","spiral"],MR=["solid","stringer","mono","cantilever"],SR=["none","left","right","both"],wR=["headroom","full","none"],Zu={shape:"straight",turn:"right",build:"solid",risers:!0,steps:null,run_width:null,down:!1,rail:"none",opening:"headroom",landing_after:null};var Ny=2,Dy=40,TR=2.2,Ju=(i,e)=>typeof e=="string"&&i.includes(e);function dp(i){let e=i.stair??{},t=typeof e.steps=="number"&&Number.isFinite(e.steps)?Math.round(Math.min(Dy,Math.max(Ny,e.steps))):null,n=typeof e.run_width=="number"&&Number.isFinite(e.run_width)&&e.run_width>.2?e.run_width:null;return{shape:Ju(vR,e.shape)?e.shape:Zu.shape,turn:e.turn==="left"?"left":"right",build:Ju(MR,e.build)?e.build:Zu.build,risers:e.risers!==!1,steps:t,run_width:n,down:e.down===!0,rail:Ju(SR,e.rail)?e.rail:Zu.rail,opening:Ju(wR,e.opening)?e.opening:Zu.opening,landing_after:typeof e.landing_after=="number"&&Number.isFinite(e.landing_after)?Math.max(1,Math.round(e.landing_after)):null}}var Qu=i=>i.type==="stairs"&&!!i.stair,yl=(i,e,t)=>[i[0]+(e[0]-i[0])*t,i[1]+(e[1]-i[1])*t],Iy=(i,e)=>Math.abs(i[0]-e[0])<1e-6&&Math.abs(i[1]-e[1])<1e-6;function Uy(i){let e=[];for(let t of i)(!e.length||!Iy(e[e.length-1],t))&&e.push(t);for(;e.length>1&&Iy(e[0],e[e.length-1]);)e.pop();return e}function _l(i,e,t=!1){return{poly:Uy([...i,...[...e].reverse()]),landing:t,left:i,right:e}}function bl(i,e,t,n,r){let s=[];for(let o=0;oe+1e-6&&ri.reduce((e,t,n)=>n?e+Math.hypot(t[0]-i[n-1][0],t[1]-i[n-1][1]):e,0);function Fy(i,e,t,n,r){let s=ER(i),o=[];for(let a=0;a=8?3:2),[f,d]=i.shape==="l"?Oy(i,n)??ju(n-h,t-l,e-l):ju(n-h,t-l,e-l),p=bl([r,a],[r+l,a],[r,o+l],c,f),x=i.shape==="l"?[_l(u,[c],!0)]:Fy(u,c,c,c,h),g=bl([r+l,o],c,[s,o],[s,o+l],d);return{treads:[...p,...x,...g],flight:l,column:0}}case"half":case"u":{let l=Math.min(i.run_width??Math.min(1.1,(e-.1)/2),(e-.02)/2),c=o+l,u=[[r,c],[r,o],[s,o],[s,c]],[h,f]=[[r+l,c],[s-l,c]],d=i.shape==="u"?1:Math.min(n,n>=12?6:n>=8?4:2),[p,x]=i.shape==="u"?Oy(i,n)??ju(n-d,t-l,t-l):ju(n-d,t-l,t-l),g=bl([r,a],[r+l,a],[r,c],h,p),m=i.shape==="u"?[_l(u,[h,f],!0)]:Fy(u,h,[0,c],f,d),b=bl([s,c],f,[s,a],[s-l,a],x);return{treads:[...g,...m,...b],flight:l,column:0}}case"spiral":{let l=Math.min(e,t)/2,c=Math.min(.08,l*.12),u=Math.min(.75,Math.max(.3,.22/(l*.6))),h=(d,p)=>[Math.cos(p)*d,Math.sin(p)*d],f=[];for(let d=0;dh(l,p+(x-p)*m));f.push(_l(g,[h(c,p),h(c,x)]))}return{treads:f,flight:l-c,column:c}}default:return{treads:bl([r,a],[s,a],[r,o],[s,o],n),flight:e,column:0}}}var CR=(i,e)=>i.steps??Math.min(Dy,Math.max(Ny,Math.round(Math.abs(e)/.18)));function pp(i,e,t,n){let r=CR(i,n),s=Math.abs(n)/r,o=RR(i,Math.max(.3,e),Math.max(.3,t),r),a=c=>[-c[0],c[1]];return{treads:o.treads.map((c,u)=>{let h=i.down?-s*(u+1):s*(u+1);return i.turn==="right"?{...c,top:h}:{poly:c.poly.map(a).reverse(),top:h,landing:c.landing,left:c.right.map(a),right:c.left.map(a)}}),rise:s,steps:r,column:o.column,flight:o.flight}}function By(i){let e=i.poly.reduce((t,n)=>[t[0]+n[0],t[1]+n[1]],[0,0]);return[e[0]/i.poly.length,e[1]/i.poly.length]}function PR(i,e,t,n="headroom"){if(n==="none")return[];let r=t?0:Math.abs(e),s=n==="full"?i.treads:i.treads.filter((o,a)=>o.top>r-TR||!t&&a===i.treads.length-1||t&&a===0);return fr(s.map(o=>o.poly).filter(o=>o.length>=3))}function mp(i){let e=dp(i),t=PR(pp(e,i.w,i.d,i.h),i.h,e.down,e.opening),n=i.rotation*Math.PI/180,[r,s]=[Math.cos(n),Math.sin(n)],o=i.mirror?-1:1;return t.map(a=>a.map(([l,c])=>[i.x+o*l*r-c*s,i.z+o*l*s+c*r]))}function Ni(i,e,t,n,r,s,o=Pe.metal,a=!1){let[l,c]=[e/2-s-r,t/2-s-r],u=mt(o);for(let h of[-1,1])for(let f of[-1,1]){let[d,p]=[h*l,f*c];a?i.loft([d-r*.3,d+r*.3,p-r*.3,p+r*.3],[d-r/2,d+r/2,p-r/2,p+r/2],0,n,u):i.block({x:[d-r/2,d+r/2],y:[0,n],z:[p-r/2,p+r/2]},u)}}function Cs(i,e,t,n,r,s,o,a=null,l=!1){let c=(t-e)/o;for(let u=1;u1?h+(u%2?-c/2+.06:c/2-.06):h+c/2-.06;i.seg(d,f-.08,s+.012,d,f+.08,s+.012,qe)}}}function fi(i,e,t,n,r,s=null,o=!1,a=Z.body){i.block({x:[-e/2,e/2],y:[.02,n],z:[-t/2,t/2-.02]},a,pe),i.block({x:[-e/2+.02,e/2-.02],y:[0,.08],z:[-t/2+.02,t/2-.06]},mt(Pe.dark)),Cs(i,-e/2,e/2,.08,n,t/2-.02,r,s,o)}function gp(i,e,t,n,r){let[s,o,a,l]=[-e/2,e/2,-t/2,t/2],c=Math.min(.2,e*.12),u=n*.5,h=Math.min(.24,t*.28);Ni(i,e,t,.07,.05,.05,Pe.wood,!0),i.pad({x:[s,o],y:[.07,u-.08],z:[a+.02,l]},Z.fabric,.04,pe),i.loft([s,o,a,a+h],[s+.01,o-.01,a,a+h*.5],u-.08,n,Z.fabric,pe);for(let[d,p]of[[s,s+c],[o-c,o]])i.pad({x:[d,p],y:[u-.08,n*.72],z:[a+.02,l-.02]},Z.fabric,.04,pe);let f=(o-c-(s+c))/r;for(let d=0;d1.2?2:1,f=(e-.2)/h;for(let d=0;d0?.05:0),o*(e/2)+(o<0?.05:0)],y:[0,n],z:[a*(t/2)-(a>0?.05:0),a*(t/2)+(a<0?.05:0)]},Z.wood);for(let o of[.25,n-.55])i.block({x:[-e/2,e/2],y:[o,o+.08],z:[-t/2,t/2]},Z.wood,pe),i.block({x:[-e/2+.04,e/2-.04],y:[o+.08,o+.24],z:[-t/2+.05,t/2-.05]},Z.bedding,Je),i.block({x:[-e/2+.05,e/2-.05],y:[o+.24,o+.33],z:[-t/2+.08,-t/2+.4]},Z.pillow);i.block({x:[-e/2,e/2],y:[n-.2,n-.15],z:[t/2-.05,t/2]},Z.wood);let s=e/2-.35;for(let o of[s-.18,s+.18])i.seg(o,0,t/2+.02,o,n-.15,t/2+.02,pe);for(let o=.3;oi.block({x:[-e/2,e/2],y:[n-.04,n],z:[-t/2,t/2]},Z.worktop,pe);function Yy(i,e,t,n){fi(i,e,t-.02,n-.04,Math.max(1,Math.round(e/.6)),n-.2),yp(i,e,t,n)}function qy(i,e,t,n){i.block({x:[-e/2,e/2],y:[Math.max(0,n-.04),n],z:[-t/2,t/2]},Z.worktop,pe)}function $y(i,e,t,n){i.block({x:[-e/2,e/2],y:[0,n],z:[-t/2,t/2]},Z.white,pe);let r=n*.62;i.seg(-e/2,r,t/2,e/2,r,t/2,Je);let s=e/2-.06;i.seg(s,r+.08,t/2+.015,s,r+.4,t/2+.015,qe),i.seg(s,r-.4,t/2+.015,s,r-.08,t/2+.015,qe)}var _p=.06;function Ky(i,e,t,n){let r=t/2-_p;i.block({x:[-e/2,e/2],y:[.02,n],z:[-t/2,r]},Z.body,pe),i.block({x:[-e/2+.05,e/2-.05],y:[0,.02],z:[-t/2+.05,r-.05]},Z.dark);for(let s of[.35,.7,1.05,1.4])s>n-.15||(i.seg(-e/2+.03,s,r+.001,-.03,s,r+.001,Je),i.seg(.03,s,r+.001,e/2-.03,s,r+.001,Je))}var bp=1.83;function IR(i,e,t,n,r){let[s,o]=[Math.cos(e.rotation*pt),Math.sin(e.rotation*pt)],a=e.mirror?-1:1,l=(b,v)=>[e.x+a*b*s-v*o,e.z+a*b*o+v*s],[c,u]=[t+.05,t+e.h-.02],h=new W(.75,.1,.14),f=new W(Pe.dark),d=new W(Pe.accent),p=e.w/2-.006,x=(b,v,y)=>{let M=y/bp,S=new W(2043212).lerp(h,M),_=new W(Pe.body).lerp(h,M*.8),[w,R]=[Math.cos(y),Math.sin(y)],A=(D,P)=>l(b+v*(D*w-P*R),e.d/2+D*R+P*w),C=(D,P,I,N)=>{let[F,H,B,X]=D;i.tri([F[0],P,F[1]],[H[0],P,H[1]],[B[0],I,B[1]],N),i.tri([F[0],P,F[1]],[B[0],I,B[1]],[X[0],I,X[1]],N)},O=(D,P,I,N,F,H,B,X=B)=>{let V=[A(D,H),A(P,H),A(P,F),A(D,F)];C([V[0],V[1],V[1],V[0]],I,N,X),C([V[3],V[2],V[2],V[3]],I,N,B),C([V[0],V[3],V[3],V[0]],I,N,B),C([V[1],V[2],V[2],V[1]],I,N,B),C([V[0],V[1],V[2],V[3]],N,N,B),C([V[3],V[2],V[1],V[0]],I,I,B)};return O(0,p,c,u,-_p,0,_,S),O(p-.05,p-.03,t+e.h*.45,t+e.h*.75,.005,.025,d),O};x(-e.w/2,1,n*bp)(.12,.3,t+e.h*.5,t+e.h*.68,.001,.005,f),x(e.w/2,-1,r*bp)(.06,p-.06,t+e.h*.52,t+e.h*.86,.001,.005,f)}function vp(i,e,t,n,r){let s=i.p.length;IR(i,e,t,n,r),e.mirror&&vs(i,s)}function Zy(i,e,t,n){fi(i,e,t-.02,n-.04,1,n-.24,!0),i.block({x:[-e/2,e/2],y:[n-.04,n],z:[-t/2,t/2]},Z.dark,pe);let r=[[-.14,-.13,.09],[.14,-.13,.07],[-.14,.13,.07],[.14,.13,.09]];for(let[s,o,a]of r)i.cylinder(s*e/.6,o*t/.62,a,n,n+.004,mt(Pe.dark,1451583),12,qe)}function Jy(i,e,t,n){fi(i,e,t-.02,n-.04,Math.max(1,Math.round(e/.45)),n-.2);let r=Math.min(.5,e-.2),s=(o,a,l,c,u=!1)=>i.block({x:[o,a],y:[n-.04,n],z:[l,c]},Z.worktop,u?pe:null);s(-e/2,-r/2,-t/2,t/2,!0),s(r/2,e/2,-t/2,t/2,!0),s(-r/2,r/2,-t/2,-t/2+.1),s(-r/2,r/2,t/2-.08,t/2),i.block({x:[-r/2,r/2],y:[n-.2,n-.17],z:[-t/2+.1,t/2-.08]},Z.metal,qe),i.cylinder(0,-t/2+.05,.02,n,n+.28,Z.metal,8),i.block({x:[-.015,.015],y:[n+.24,n+.28],z:[-t/2+.05,-t/2+.22]},Z.metal)}function jy(i,e,t,n){i.block({x:[-e/2,e/2],y:[1.45,1.45+n],z:[-t/2,t/2-.02]},Z.body,pe),Cs(i,-e/2,e/2,1.45,1.45+n,t/2-.02,Math.max(1,Math.round(e/.5)),1.45+.08)}function Qy(i,e,t,n){i.block({x:[-e/2,e/2],y:[.02,n],z:[-t/2,t/2-.02]},Z.body,pe),i.block({x:[-e/2+.02,e/2-.02],y:[0,.08],z:[-t/2+.02,t/2-.06]},Z.dark);let r=t/2-.02;i.block({x:[-e/2+.03,e/2-.03],y:[.85,1.45],z:[r,r+.01]},Z.dark,qe),i.seg(-e/2+.08,1.4,r+.02,e/2-.08,1.4,r+.02,qe);for(let s of[.85,1.45])i.seg(-e/2,s,r,e/2,s,r,Je);i.seg(e/2-.06,.5,r+.012,e/2-.06,.7,r+.012,qe),i.seg(e/2-.06,1.6,r+.012,e/2-.06,1.8,r+.012,qe)}function e_(i,e,t,n){let r=t-.3;i.block({x:[-e/2+.05,e/2-.05],y:[.08,n-.04],z:[-t/2+.02,-t/2+r]},Z.body,pe),i.block({x:[-e/2+.07,e/2-.07],y:[0,.08],z:[-t/2+.04,-t/2+r-.04]},Z.dark),Cs(i,-e/2+.05,e/2-.05,.08,n-.04,-t/2+r,Math.max(2,Math.round(e/.6)),n-.2),yp(i,e,t,n)}function t_(i,e,t,n){i.block({x:[-e/2,e/2],y:[.02,n-.04],z:[-t/2,t/2-.02]},Z.body,pe),i.block({x:[-e/2+.02,e/2-.02],y:[0,.08],z:[-t/2+.02,t/2-.06]},Z.dark),i.seg(-e/2+.08,n-.12,t/2-.008,e/2-.08,n-.12,t/2-.008,qe),yp(i,e,t,n)}function Mp(i,e,t,n,r){i.block({x:[-e/2,e/2],y:[0,n],z:[-t/2,t/2-.02]},Z.white,pe);let s=t/2-.012;i.seg(-e/2,n-.14,s,e/2,n-.14,s,Je),i.seg(e/2-.16,n-.07,s,e/2-.08,n-.07,s,qe);let o=(n-.14)/2+.04,a=Math.min(e*.36,(n-.2)*.42),l=20;for(let c=0;ci.seg(Math.cos(u)*a*d,o+Math.sin(u)*a*d,s,Math.cos(h)*a*d,o+Math.sin(h)*a*d,s,p);f(1,qe),r||f(.72,Je)}}function n_(i,e,t,n){i.block({x:[-e/2,e/2],y:[0,n-.02],z:[-t/2,t/2]},Z.white,pe);let s=(o,a,l,c)=>i.block({x:[o,a],y:[n-.02,n],z:[l,c]},Z.worktop);s(-e/2,e/2,-t/2,-t/2+.07),s(-e/2,e/2,t/2-.07,t/2),s(-e/2,-e/2+.07,-t/2+.07,t/2-.07),s(e/2-.07,e/2,-t/2+.07,t/2-.07),i.block({x:[-e/2+.07,e/2-.07],y:[n-.03,n-.02],z:[-t/2+.07,t/2-.07]},Z.glass,qe),i.cylinder(-e/2+.04,0,.02,n,n+.12,Z.metal,8)}function i_(i,e,t,n){i.block({x:[-e/2,e/2],y:[0,.05],z:[-t/2,t/2]},Z.worktop,pe),i.cylinder(0,0,.04,.05,.052,Z.metal,8);for(let[r,s,o,a]of[[-e/2,t/2,e/2,t/2],[e/2,-t/2,e/2,t/2]])i.seg(r,.05,s,o,.05,a,qe),i.seg(r,n,s,o,n,a,qe),i.seg(o,.05,a,o,n,a,qe);i.cylinder(-e/2+.06,-t/2+.06,.015,.05,n-.05,Z.metal,6),i.cylinder(-e/2+.2,-t/2+.2,.1,n-.08,n-.06,Z.metal,12,qe)}function r_(i,e,t,n){let r=Math.min(.18,t*.3);i.block({x:[-e/2,e/2],y:[.45,n],z:[-t/2,-t/2+r]},Z.white,pe),i.block({x:[-e*.3,e*.3],y:[0,.36],z:[-t/2+r-.02,t/2-.12]},Z.white),i.cylinder(0,t/2-.26,Math.min(e/2,.19),.36,.41,Z.white,12,pe),i.block({x:[-e/2+.02,e/2-.02],y:[.41,.43],z:[-t/2+r,-t/2+r+.05]},Z.worktop)}function s_(i,e,t,n){fi(i,e,t-.02,n-.12,e>.8?2:1,n-.3),i.block({x:[-e/2,e/2],y:[n-.12,n],z:[-t/2,t/2]},Z.white,pe),i.block({x:[-e/2+.07,e/2-.07],y:[n-.005,n],z:[-t/2+.12,t/2-.06]},Z.glass,qe),i.cylinder(0,-t/2+.06,.018,n,n+.2,Z.metal,8),i.block({x:[-e/2+.04,e/2-.04],y:[n+.35,n+1],z:[-t/2,-t/2+.02]},Z.glass,qe)}var vl=.12;function o_(i,e,t,n){let r=vl;i.block({x:[-e/2+.05,-e/2+.08],y:[0,r],z:[-t/2,-t/2+.03]},Z.metal),i.block({x:[e/2-.08,e/2-.05],y:[0,r],z:[-t/2,-t/2+.03]},Z.metal),i.block({x:[-e/2,e/2],y:[r,r+n],z:[-t/2+.02,t/2]},Z.white,pe);let s=Math.max(3,Math.round(e/.1));for(let o=1;oi.block({x:[-e/2,e/2],y:[1.1,1.1+n],z:[-t/2,t/2]},l,pe);if(r==="slim"){a(Z.darkBody),i.seg(-e*.25,1.1+n*.15,o+.004,-e*.25,1.1+n*.85,o+.004,qe),i.block({x:[-e*.1,e*.3],y:[1.1+n*.7,1.1+n*.85],z:[o,o+.005]},Z.dark);return}if(a(Z.white),r==="hybrid"){i.ring(0,1.1+n*.66,Math.min(e,n)*.22,o+.004,20,qe),i.seg(-e*.08,1.1+n*.66,o+.005,e*.08,1.1+n*.66,o+.005,qe);for(let l of[-1,1])i.ring(l*e*.22,1.1+n*.2,Math.min(e,n)*.1,-t/2-.002,12,qe);return}i.block({x:[-e*.28,e*.28],y:[1.1+n*.58,1.1+n*.82],z:[t/2,t/2+.006]},Z.dark),i.seg(-e*.3,1.1+n*.45,t/2+.004,e*.3,1.1+n*.45,t/2+.004,qe);for(let l of[-1,1])for(let c=1;c<6;c++)i.seg(l*e/2+l*.002,1.1+n*c/6,-t/2+.03,l*e/2+l*.002,1.1+n*c/6,t/2-.03,Je)}function M_(i,e,t,n){i.block({x:[-e/2,e/2],y:[0,n],z:[-t/2,t/2]},Z.darkBody,pe),i.block({x:[-e/2-.01,e/2+.01],y:[n,n+.03],z:[-t/2-.01,t/2+.01]},Z.darkBody),i.seg(-e/2,n+.032,t/2+.01,e/2,n+.032,t/2+.01,qe),i.seg(-e*.3,n*.55,t/2+.003,e*.3,n*.55,t/2+.003,Je)}function S_(i,e,t,n){i.block({x:[-e/2,e/2],y:[1,1+n],z:[-t/2,t/2]},Z.darkBody,pe),i.ring(0,1+n*.58,Math.min(e,n)*.28,t/2+.003,16,qe),i.block({x:[-.015,.015],y:[1-.35,1],z:[t/2-.03,t/2]},Z.dark),i.block({x:[-.06,.06],y:[1-.42,1-.35],z:[t/2-.05,t/2]},Z.darkBody)}function w_(i,e,t,n){i.block({x:[-e/2,e/2],y:[.4,.4+n],z:[-t/2,t/2]},Z.white,pe),i.seg(-e/2+.025,.4+.025,t/2+.003,-e/2+.025,.4+n-.025,t/2+.003,Je),i.seg(-e/2+.025,.4+n-.025,t/2+.003,e/2-.025,.4+n-.025,t/2+.003,Je),i.block({x:[e/2-.06,e/2-.035],y:[.4+n*.5-.05,.4+n*.5+.05],z:[t/2,t/2+.012]},Z.dark),i.block({x:[-e*.3,e*.3],y:[.4+n*.6,.4+n*.8],z:[t/2,t/2+.005]},Z.dark),i.seg(-e*.22,.4+n*.7,t/2+.008,e*.22,.4+n*.7,t/2+.008,qe)}function T_(i,e,t,n,r){if(r==="wall"){i.block({x:[-e/2,e/2],y:[.5,.5+n],z:[-t/2,t/2]},Z.white,pe),i.seg(-e*.3,.5+n*.9,t/2+.004,e*.3,.5+n*.9,t/2+.004,qe),i.seg(-e*.3,.5+n*.08,t/2+.003,e*.3,.5+n*.08,t/2+.003,Je);return}if(r==="cube"){i.block({x:[-e/2+.01,e/2-.01],y:[0,.03],z:[-t/2+.01,t/2-.01]},Z.dark),i.block({x:[-e/2,e/2],y:[.03,n],z:[-t/2,t/2]},Z.darkBody,pe),i.seg(-e*.35,n*.85,t/2+.004,e*.35,n*.85,t/2+.004,qe),i.block({x:[-e*.15,e*.15],y:[n,n+.025],z:[-.012,.012]},Z.dark);return}i.block({x:[-e/2+.02,e/2-.02],y:[0,.06],z:[-t/2+.02,t/2-.02]},Z.dark);let s=Math.max(2,Math.round((n-.06)/.3)),o=(n-.06)/s;for(let a=0;a[x[0]+h*g,x[1]+f*g];i.prism([e,t,p(t,o),p(e,o)],r,s,a,Je)}var LR=i=>i.slice(1).map((e,t)=>[i[t],e]).filter(([e,t])=>Math.hypot(t[0]-e[0],t[1]-e[1])>.01);function FR(i,e,t,n,r){let s=e.build==="cantilever"?.07:.05;t.forEach((o,a)=>{let l=By(o),c=a===0?0:t[a-1].top;if(e.build==="solid"){i.prism(o.poly,Math.min(r,o.top),o.top,Z.body,pe);return}if(i.prism(o.poly,o.top-s,o.top,Z.wood,pe),e.risers&&!o.landing){let[u,h]=[Math.min(c,o.top),Math.max(c,o.top)-s];A_(i,o.left[0],o.right[0],l,u,h,.02)}if(e.build==="stringer")for(let u of[o.left,o.right])for(let[h,f]of LR(u))A_(i,h,f,l,o.top-n-.2,o.top+.05,.04);else e.build==="mono"&&i.block({x:[l[0]-.07,l[0]+.07],y:[o.top-n-.12,o.top-s],z:[l[1]-.07,l[1]+.07]},Z.metal)})}function OR(i,e,t){let n=e.rail==="both"?["left","right"]:e.rail==="none"?[]:[e.rail];for(let r of n){let s=[];for(let o of t)for(let a of o[r])s.push([a[0],o.top+eh,a[1]]);for(let[o,a]of t.entries()){if(o%2&&o!==t.length-1)continue;let l=a[r][0];i.cylinder(l[0],l[1],.012,a.top,a.top+eh,Z.metal,6)}for(let o=1;o0&&i.cylinder(0,0,o.column,Math.min(0,a),s.down?0:r,Z.metal,12,pe),FR(i,s,o.treads,o.rise,a),OR(i,s,o.treads)}function NR(i,e,t,n,r,s){switch(e.type){case"sofa":return e.variant==="l"||e.variant==="u"?ky(i,t,n,r,e.variant):gp(i,t,n,r,Math.max(1,Math.round((t-.4)/.62))),"yes";case"armchair":return gp(i,t,n,r,1),"yes";case"bed":return zy(i,t,n,r),"yes";case"chair":return Vy(i,t,n,r),"yes";case"table":return a_(i,t,n,r),"yes";case"desk":return u_(i,t,n,r),"yes";case"nightstand":return h_(i,t,n,r),"yes";case"wardrobe":return fi(i,t,n,r,Math.max(2,Math.round(t/.5)),r*.5),"yes";case"tall_cabinet":return fi(i,t,n,r,1,r*.5),"yes";case"shelf":return f_(i,t,n,r),"yes";case"kitchen":return Yy(i,t,n,r),"yes";case"fridge":return $y(i,t,n,r),"yes";case"fridge_smart":return Ky(i,t,n,r),"yes";case"stove":return Zy(i,t,n,r),"yes";case"sink":return Jy(i,t,n,r),"yes";case"bathtub":return n_(i,t,n,r),"yes";case"shower":return i_(i,t,n,r),"yes";case"wc":return r_(i,t,n,r),"yes";case"washbasin":return s_(i,t,n,r),"yes";case"tv_board":return y_(i,t,n,r,e.ambilight===0?pe:void 0),"yes";case"plant":return g_(i,t,n,r),"yes";case"rug":return x_(i,t,n),"no";case"stairs":return e.stair?(E_(i,e,t,n,r),e.stair.down?"no":"yes"):(b_(i,t,n,r),"yes");case"stairwell":return"no";case"sideboard":return d_(i,t,n,r),"yes";case"dresser":return p_(i,t,n,r),"yes";case"coat_rack":return m_(i,t,n,r),"yes";case"bench":return xp(i,t,n,r,!1),"yes";case"corner_bench":return xp(i,t,n,r,!0),"yes";case"bar_stool":return Gy(i,t,n,r),"yes";case"office_chair":return Hy(i,t,n,r),"yes";case"stool":return Wy(i,t,n,r),"yes";case"kitchen_wall":return jy(i,t,n,r),"no";case"kitchen_tall":return Qy(i,t,n,r),"yes";case"island":return e_(i,t,n,r),"yes";case"worktop":return qy(i,t,n,r),"no";case"dishwasher":return t_(i,t,n,r),"yes";case"washer":return Mp(i,t,n,r,!1),"yes";case"dryer":return Mp(i,t,n,r,!0),"yes";case"bunk_bed":return Xy(i,t,n,r),"yes";case"table_round":return l_(i,t,n,r),"yes";case"coffee_table":return c_(i,t,n,r),"yes";case"tv_wall":return __(i,t,n,r,e.ambilight===0?pe:void 0),"no";case"parking":{let a=[[-t/2,-n/2],[t/2,-n/2],[t/2,n/2],[-t/2,n/2]];return a.forEach(([l,c],u)=>i.seg(l,.012,c,a[(u+1)%4][0],.012,a[(u+1)%4][1],Je)),i.seg(-t*.15,.012,n/2-.45,0,.012,n/2-.2,pe),i.seg(0,.012,n/2-.2,t*.15,.012,n/2-.45,pe),"no"}case"robot_vacuum":return i.block({x:[-t*.45,t*.45],y:[0,r],z:[-n/2,-n/2+n*.3]},Z.white,pe),i.block({x:[-t*.2,t*.2],y:[r*.5,r*.62],z:[-n/2+n*.3,-n/2+n*.31]},Z.accent),"no";case"radiator":return o_(i,t,n,r),"no";case"inverter":return v_(i,t,n,r,e.variant??null),"no";case"grid_point":return M_(i,t,n,r),"yes";case"wallbox":return S_(i,t,n,r),"no";case"meter":return w_(i,t,n,r),"no";case"home_battery":return T_(i,t,n,r,e.variant??null),e.variant==="wall"?"no":"yes";default:{let o=vt(e.type);return o?o.pet?"no":(Ms(i,o,t,n,r,s,null,null,e.variant??null),s>.05?"no":"yes"):(i.block({x:[-t/2,t/2],y:[0,r],z:[-n/2,n/2]},Z.body,pe),"yes")}}}function R_(i,e,t,n,r){let s=Ss(n),o=new Li(i,e,s),[a,l,c]=[Math.max(.05,n.w),Math.max(.05,n.d),Math.max(.005,n.h)];NR(o,n,a,l,c,r)==="yes"&&pb(t,s,a,l,n.type==="plant"?.35:.5)}function C_(i,e,t){let[n,r]=[Math.cos(t),Math.sin(t)],s=e[0]*i[0]+e[1]*i[1]+e[2]*i[2],o=[e[1]*i[2]-e[2]*i[1],e[2]*i[0]-e[0]*i[2],e[0]*i[1]-e[1]*i[0]];return[i[0]*n+o[0]*r+e[0]*s*(1-n),i[1]*n+o[1]*r+e[1]*s*(1-n),i[2]*n+o[2]*r+e[2]*s*(1-n)]}function DR(i,e,t,n,r){let[s,o]=[n.tilt_x??0,n.tilt_z??0];if(!s&&!o)return;let a=n.rotation*Math.PI/180,l=[Math.cos(a),0,Math.sin(a)],c=[-Math.sin(a),0,Math.cos(a)],u=(h,f)=>{for(let d=f;d+2c.screen);if(o){let c=e?Gt(e,i):0,[u,h]=[(o.x-o.w/2)*t,(o.x+o.w/2)*t],f=Math.min(.02,(h-u)*.05);return{x0:u+f,x1:h-f,y0:c+o.y*r+f,y1:c+(o.y+o.h)*r-f,z:(o.z+o.d/2)*n}}let a=e&&i.type!=="fridge_smart"?Gt(e,i)-jr(i):0,l=BR(i,t,n,r,e);return l&&{...l,y0:l.y0+a,y1:l.y1+a}}function th(i,e){let t=kR(i,e);return t&&i.mirror?{...t,x0:-t.x1,x1:-t.x0}:t}function Sp(i,e){let[t,n,r]=[Math.max(.05,i.w),Math.max(.05,i.d),Math.max(.005,i.h)],s=vt(i.type),o=s&&jo(s,t,n,r).find(h=>h.picture);if(!o)return null;let a=e?Gt(e,i):0,[l,c]=[(o.x-o.w/2)*t,(o.x+o.w/2)*t],u={x0:l,x1:c,y0:a+o.y*r,y1:a+(o.y+o.h)*r,z:(o.z+o.d/2)*n};return i.mirror?{...u,x0:-u.x1,x1:-u.x0}:u}function wp(i,e){if(i.type!=="home_battery")return null;let[t,n,r]=[Math.max(.05,i.w),Math.max(.05,i.d),Math.max(.05,i.h)],s=e?Gt(e,i)-jr(i):0,o=n/2+.005;return i.variant==="wall"?{rect:{x0:-t*.3,x1:t*.3,y0:s+.5+r*.84,y1:s+.5+r*.9,z:o},vertical:!1}:i.variant==="cube"?{rect:{x0:-t*.35,x1:t*.35,y0:s+r*.8,y1:s+r*.86,z:o},vertical:!1}:{rect:{x0:-t*.05,x1:t*.05,y0:s+.06+r*.16,y1:s+r-.12,z:o},vertical:!0}}var Jn=Math.PI/180,dr=(i,e)=>[i[0]-e[0],i[1]-e[1],i[2]-e[2]];var Fo=i=>Math.hypot(i[0],i[1],i[2]),Ps=i=>{let e=Fo(i)||1;return[i[0]/e,i[1]/e,i[2]/e]},P_=(i,e)=>[i[1]*e[2]-i[2]*e[1],i[2]*e[0]-i[0]*e[2],i[0]*e[1]-i[1]*e[0]];var L_=.25;function F_(i,e,t,n,r,s,o){let a=r-t>=s-n,l=a?r-t:s-n;return{key:`${i}:top`,section:e,side:"top",flat:!0,o:[t,o,n],eu:a?[1,0,0]:[0,0,1],es:a?[0,0,1]:[1,0,0],n:[0,1,0],lu:l,ls:a?s-n:r-t,pitch:0,span:()=>[0,l],facing:a?[0,1]:[1,0]}}function O_(i,e){let t=Ps(P_(i,e));return t[1]<0?[-t[0],-t[1],-t[2]]:t}var N_=i=>{let e=Ps([-i[0],0,-i[2]]);return[e[0],e[2]]};function pr(i,e,t,n,r,s,o,a){let l=Ps(dr(r,n)),c=Ps(dr(s,n));return{key:i,section:e,side:t,flat:!1,o:n,eu:l,es:c,n:O_(l,c),lu:Fo(dr(r,n)),ls:Fo(dr(s,n)),pitch:o,span:a,facing:N_(c)}}function I_(i,e,t,n,r,s){let o=Fo(dr(r,n));if(o<.3)return null;let a=Ps(dr(r,n)),l=dr(s,n),c=l[0]*a[0]+l[1]*a[1]+l[2]*a[2],u=[l[0]-a[0]*c,l[1]-a[1]*c,l[2]-a[2]*c],h=Fo(u);if(h<.3)return null;let f=Ps(u),d=p=>{let x=Math.min(1,Math.max(0,p/h));return[c*x,o-(o-c)*x]};return{key:i,section:e,side:t,flat:!1,o:n,eu:a,es:f,n:O_(a,f),lu:o,ls:h,pitch:Math.atan2(f[1],Math.hypot(f[0],f[2]))/Jn,span:d,facing:N_(f)}}function zR(i,e){let t=Dn(i),n=En(i),r=(b,v,y)=>{let[M,S]=t.at(b,v);return[M,y,S]},[s,o]=[Math.max(0,e.a),Math.max(0,e.b)],a=t.u0-Math.max(0,e.u0),l=t.u1+Math.max(0,e.u1),c=l-a,u=n.y(-s),h=n.y(t.w+o);if(i.shape==="flat"||i.shape==="parapet"){let[b,v]=[t.at(a,-s),t.at(l,t.w+o)];return[F_(i.id,i.id,Math.min(b[0],v[0]),Math.min(b[1],v[1]),Math.max(b[0],v[0]),Math.max(b[1],v[1]),i.eave_a+L_)]}if(i.shape==="pent")return[pr(`${i.id}:a`,i.id,"a",r(a,-s,u),r(l,-s,u),r(a,t.w+o,h),i.pitch_a,()=>[0,c])];if(i.shape==="mansard")return VR(i,t,a,l,s,o);let f=i.shape==="hip"||i.shape==="pyramid",d=(t.u1-t.u0)/2,p=i.shape==="pyramid"?d:f?Math.min(d,Math.min(n.vr,t.w-n.vr)||t.w/2):0,x=f?t.u0+p-a:0,g=f?l-(t.u1-p):0,m=[];if(n.vr>.3){let b=Math.hypot(n.vr+s,n.rh-u);m.push(pr(`${i.id}:a`,i.id,"a",r(a,-s,u),r(l,-s,u),r(a,n.vr,n.rh),i.pitch_a,v=>[x*(v/b),c-g*(v/b)]))}if(t.w-n.vr>.3){let b=Math.hypot(t.w+o-n.vr,n.rh-h);m.push(pr(`${i.id}:b`,i.id,"b",r(l,t.w+o,h),r(a,t.w+o,h),r(l,n.vr,n.rh),i.pitch_b,v=>[g*(v/b),c-x*(v/b)]))}if(f){let b=I_(`${i.id}:c`,i.id,"c",r(a,t.w+o,h),r(a,-s,u),r(t.u0+p,n.vr,n.rh)),v=I_(`${i.id}:d`,i.id,"d",r(l,-s,u),r(l,t.w+o,h),r(t.u1-p,n.vr,n.rh));m.push(...[b,v].filter(y=>y!==null))}return m}function VR(i,e,t,n,r,s){let o=ol(e.w,i.eave_a,i.eave_b,ur(i.pitch_a),ur(i.pitch_b)),a=(p,x)=>{let[g,m]=e.at(p,x);return[g,o.y(x),m]},l=n-t,c=()=>[0,l],u=(p,x)=>Math.atan2(p,x)/Jn,h=[],[f,d]=[e.w+s,e.w-o.vlb];return o.vla+r>.3&&h.push(pr(`${i.id}:a`,i.id,"a",a(t,-r),a(n,-r),a(t,o.vla),i.pitch_a,c)),o.vr-o.vla>.3&&h.push(pr(`${i.id}:au`,i.id,"a",a(t,o.vla),a(n,o.vla),a(t,o.vr),u(o.rh-o.yla,o.vr-o.vla),c)),o.vlb+s>.3&&h.push(pr(`${i.id}:b`,i.id,"b",a(n,f),a(t,f),a(n,d),i.pitch_b,c)),d-o.vr>.3&&h.push(pr(`${i.id}:bu`,i.id,"b",a(n,d),a(t,d),a(n,o.vr),u(o.rh-o.ylb,d-o.vr),c)),h}function D_(i){return i.floors.filter(t=>t.rooms.some(n=>n.points.length>=3)).sort((t,n)=>n.elevation-t.elevation)[0]??null}function Is(i){let e=i.settings.roof;if(!e||e.type==="none")return[];if(e.type==="custom")return(e.sections??[]).flatMap(v=>zR(v,ll(i,v,v.overhang??e.overhang)));let t=D_(i);if(!t)return[];let n=t.rooms.flatMap(v=>v.points.map(y=>y[0])),r=t.rooms.flatMap(v=>v.points.map(y=>y[1])),s=i.settings.wall_exterior+e.overhang,[o,a]=[Math.min(...n)-s,Math.max(...n)+s],[l,c]=[Math.min(...r)-s,Math.max(...r)+s],u=t.elevation+t.height;if(e.type==="flat")return[F_("main",null,o,l,a,c,u+L_)];let h=a-o>=c-l,f=e.ridge==="short"?!h:h,d=(f?c-l:a-o)/2,p=d*Math.tan(e.pitch*Jn),x=(v,y,M)=>f?[v,u+M,(l+c)/2+y]:[(o+a)/2+y,u+M,v],[g,m]=f?[o,a]:[l,c],b=()=>[0,m-g];return[pr("main:a",null,"a",x(g,-d,0),x(m,-d,0),x(g,0,p),e.pitch,b),pr("main:b",null,"b",x(g,d,0),x(m,d,0),x(g,0,p),e.pitch,b)]}function nh(i,e){let t=[];for(let n of i.floors.filter(r=>!e||r.id===e)){let{walls:r}=al(n.rooms,{exterior:i.settings.wall_exterior,interior:i.settings.wall_interior},n.walls??[]);for(let s of r){if(!s.exterior&&!s.free)continue;let[o,a]=[s.b[0]-s.a[0],s.b[1]-s.a[1]],l=Math.hypot(o,a);if(l<1.2)continue;let[c,u]=[a/l,-o/l],h=Math.min(n.height,s.height??n.height,s.heightEnd??1/0),f=(d,p,x,g)=>t.push({key:d,section:null,side:"top",flat:!1,o:p,eu:x,es:[0,1,0],n:g,lu:l,ls:h,pitch:90,span:()=>[0,l],facing:[g[0],g[2]],wall:{floorId:n.id}});f(`wall:${n.id}:${s.id}`,[s.a[0]+c*s.right,n.elevation,s.a[1]+u*s.right],[o/l,0,a/l],[c,0,u]),s.free&&f(`wall:${n.id}:${s.id}:back`,[s.b[0]-c*s.left,n.elevation,s.b[1]-u*s.left],[-o/l,0,-a/l],[-c,0,-u])}}return t}var Sl="ground";function ih(i){let e=i.floors.filter(t=>t.rooms.some(n=>n.points.length>=3)).sort((t,n)=>t.elevation-n.elevation);return e.find(t=>t.elevation>-.5)??e[0]??i.floors[0]??null}function rh(i,e){let t=(e.rotation??0)*Jn,n=[Math.cos(t),0,Math.sin(t)],r=[-Math.sin(t),0,Math.cos(t)],s=ih(i),o=n[0]*e.u+r[0]*e.v,a=n[2]*e.u+r[2]*e.v,l=s?s.elevation+(e.base!=null?e.base:p0(s,o,a)):e.base??0;return{key:Sl,section:null,side:"top",flat:!0,o:[0,l,0],eu:n,es:r,n:[0,1,0],lu:1e4,ls:1e4,pitch:0,span:()=>[-1e4,1e4],facing:[r[0],r[2]],unbounded:!0}}var Tp=1.13,Ap=1.72,Oo=.025,di=.07;function wl(i){let e=i.module_w||Tp,t=i.module_h||Ap;return i.portrait===!1?[t,e]:[e,t]}function Ep(i){return i.layout?.length?i.layout.map(e=>Math.max(0,Math.min(60,Math.round(e)))):Array.from({length:Math.max(1,i.rows)},()=>Math.max(1,i.cols))}function Rp(i,e){return i.flat?Math.min(45,Math.max(0,e.tilt??15))*Jn:i.wall?Math.min(90,Math.max(0,e.tilt??0))*Jn:Math.min(45,Math.max(0,e.tilt??0))*Jn}function oh(i,e){let[,t]=wl(e),n=Rp(i,e);return i.wall?t*Math.cos(n)+Oo:!i.flat&&n<.001?t+Oo:i.flat&&e.rack==="ew"?t*Math.cos(n)+.08:t*Math.cos(n)+Math.max(.3,2*t*Math.sin(n))}function Cp(i,e){let[t,n]=wl(e),r=Ep(e),s=Math.max(1,...r);return[s*t+(s-1)*Oo,(r.length-1)*oh(i,e)+n*Math.cos(Rp(i,e))]}var GR=i=>i.flat&&!i.unbounded&&!i.wall;function HR(i,e){if(!GR(i)||!e.rotation)return null;let t=e.rotation*Jn,[n,r]=Cp(i,e);return{cos:Math.cos(t),sin:Math.sin(t),u:e.u+n/2,s:e.v+r/2}}function No(i,e,t=!1){let[n,r]=wl(e),s=Rp(i,e),o=r*Math.cos(s),a=oh(i,e),l=Ep(e),c=Math.max(1,...l),u=new Set(e.skip??[]),h=HR(i,e),f=(g,m)=>h?[h.u+(g-h.u)*h.cos-(m-h.s)*h.sin,h.s+(g-h.u)*h.sin+(m-h.s)*h.cos]:[g,m],d=(g,m,b)=>{let[v,y]=f(g,m);return[0,1,2].map(M=>i.o[M]+i.eu[M]*v+i.es[M]*y+i.n[M]*b)},p=(g,m)=>{let[b,v]=f(g,m);if(i.unbounded)return!0;if(v<-1e-6||v>i.ls+1e-6)return!1;let[y,M]=i.span(v);return b>=y-1e-6&&b<=M+1e-6},x=[];return l.forEach((g,m)=>{let b=e.align==="right"?c-g:e.align==="center"?(c-g)/2:0;for(let v=0;v.001?o:r);if([[S,w],[_,w],[_,R],[S,R]].every(([A,C])=>p(A,C)))if(i.wall&&s>.001){let A=di+r*Math.sin(s),[C,O]=e.flip?[A,di]:[di,A],D=[d(S,w,C),d(_,w,C),d(_,R,O),d(S,R,O)],P=e.flip?w:R;x.push({corners:D,posts:[S+.05,_-.05].map(I=>[d(I,P,0),d(I,P,A)]),cell:y,skipped:M})}else if(!i.flat&&s>.001){let A=di+r*Math.sin(s),C=[d(S,w,di),d(_,w,di),d(_,R,A),d(S,R,A)];x.push({corners:C,posts:[S+.05,_-.05].map(O=>[d(O,R,0),d(O,R,A)]),cell:y,skipped:M})}else if(!i.flat)x.push({corners:[d(S,w,di),d(_,w,di),d(_,R,di),d(S,R,di)],posts:[],cell:y,skipped:M});else{let C=.15+r*Math.sin(s),O=e.rack==="ew"&&m%2===1?!e.flip:!!e.flip,[D,P]=O?[R,w]:[w,R],I=[d(S,D,.15),d(_,D,.15),d(_,P,C),d(S,P,C)],N=[S+.05,_-.05].flatMap(F=>[[d(F,D,0),d(F,D,.15)],[d(F,P,0),d(F,P,C)]]);x.push({corners:I,posts:N,cell:y,skipped:M})}}}),x}var Pp=.78,Ip=1.18,U_=i=>({id:i.id,face:i.face,u:i.u,v:i.v,rows:1,cols:1,portrait:!0,module_w:i.w||Pp,module_h:i.h||Ip});function Tl(i,e){let t=No(i,U_(e))[0];if(!t)return null;let n=r=>[r[0]-i.n[0]*.05,r[1]-i.n[1]*.05,r[2]-i.n[2]*.05];return t.corners.map(n)}var sh={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 ah(i){let e=i.shape??"brick",t=sh[e]??sh.brick;return{shape:e,w:i.w||t.w,d:i.d||t.d,h:i.h||t.h}}function Lp(i,e){let{w:t,d:n}=ah(i),r=e&&!e.flat?Math.cos(e.pitch*Jn):1;return{id:i.id,face:i.face,u:i.u,v:i.v,rows:1,cols:1,portrait:!0,module_w:t,module_h:n/Math.max(.2,r),tilt:0}}function Fp(i,e){let t=Lp(e,i),[n,r]=[t.module_w,t.module_h],s=(u,h)=>[i.o[0]+i.eu[0]*u+i.es[0]*h,i.o[1]+i.eu[1]*u+i.es[1]*h,i.o[2]+i.eu[2]*u+i.es[2]*h],[o,a]=[s(e.u+n/2,e.v),s(e.u+n/2,e.v+r)],l=s(e.u+n/2,e.v+r/2),c=u=>{let h=Math.hypot(u[0],u[2])||1;return[u[0]/h,u[2]/h]};return{center:[l[0],l[2]],along:c(i.eu),across:c(i.es),low:Math.min(o[1],a[1]),high:Math.max(o[1],a[1])}}var Ls=1712952,Fs=2239816,lh=1318193,mr=Ue(3662079,.9),gr=Ue(5995775,.45),Xt=.14,B_=9427199,k_=13226982,z_=14936565,V_={black:{glass:new W(329483),edge:Ue(9082544,.32),cells:Ue(2766160,.22)},blue:{glass:new W(1386842),edge:Ue(10467583,.55),cells:Ue(4025599,.35)}},G_=Ue(13226982,.5),H_=Ue(13226982,.85),W_=Ue(16757575,.95),Op=new W(2845583),Np=new W(3818072),Dp=3812144,Up=4864064,ch=2765896,Do=329483,uh=9148333,hh=11845844,X_=Ue(5995775,.4);var Uo=(i,e,t)=>[i[0]+(e[0]-i[0])*t,i[1]+(e[1]-i[1])*t,i[2]+(e[2]-i[2])*t],fh=(i,e,t)=>[i[0]+e[0]*t,i[1]+e[1]*t,i[2]+e[2]*t],Bp=(i,e)=>e.section?i.find(t=>t.sections?.includes(e.section)):i[0];function Y_(i,e,t){let n=i.settings.roof?.windows??[];if(n.length===0||e.length===0)return;let r=new Map(Is(i).map(s=>[s.key,s]));for(let s of n){let o=r.get(s.face),a=o?Tl(o,s):null,l=o&&a?Bp(e,o):void 0;if(!o||!a||!l)continue;let c=l.floor.elevation+l.base,[u,h,f,d]=a.map(R=>[R[0],R[1]-c,R[2]]),p=t.get(s.id)??{open:0,tilt:0,cover:0},x=(R,A)=>fh(R,o.n,A),g=p.open>.02||p.tilt>.02?W_:H_,m=[u,h,f,d].map(R=>x(R,.06));m.forEach((R,A)=>l.lines.seg(R,m[(A+1)%4],g));let b=(p.open>.02?30*Math.min(1,p.open):p.tilt>.5?12:0)*pt,v=Math.hypot(f[0]-h[0],f[1]-h[1],f[2]-h[2]),y=R=>fh(fh(R,o.es,-v*Math.cos(b)),o.n,v*Math.sin(b)),[M,S]=[x(d,.065),x(f,.065)],[_,w]=[y(M),y(S)];l.solid.tri(_,w,S,Op),l.solid.tri(_,S,M,Op);for(let[R,A]of[[_,w],[w,S],[S,M],[M,_]])l.lines.seg(R,A,g);if(p.cover>.02){let R=Math.min(1,p.cover),[A,C]=[x(Uo(M,_,R),.01),x(Uo(S,w,R),.01)],[O,D]=[x(M,.01),x(S,.01)];l.solid.tri(A,C,D,Np),l.solid.tri(A,D,O,Np)}}}function dh(i,e,t,n,r){let s=c=>[c[0],c[1]-r,c[2]],o=V_[n.look==="blue"?"blue":"black"],[a,l]=n.portrait===!1?[10,6]:[6,10];for(let c of No(t,n)){let[u,h,f,d]=c.corners.map(s);for(let[g,m,b]of[[u,h,f],[u,f,d],[u,f,h],[u,d,f]])i.tri(g,m,b,o.glass);let p=g=>fh(g,t.n,.004),x=[u,h,f,d].map(p);x.forEach((g,m)=>e.seg(g,x[(m+1)%4],o.edge));for(let g=1;g[r.key,r]));for(let r of t){let s=n.get(r.face),o=s?Bp(e,s):void 0;s&&o&&dh(o.solid,o.lines,s,r,o.floor.elevation+o.base)}}function $_(i,e){let t=i.settings.roof?.chimneys??[];if(t.length===0||e.length===0)return;let n=new Map(Is(i).map(r=>[r.key,r]));for(let r of t){let s=n.get(r.face),o=s?Bp(e,s):void 0;if(!s||!o)continue;let a=o.floor.elevation+o.base,{shape:l,w:c,d:u,h}=ah(r),f=Fp(s,r),[d,p]=[f.low-a-.1,f.high-a+h],x=(_,w)=>{let{center:R,along:A,across:C}=f,O=(D,P)=>[R[0]+A[0]*_*D+C[0]*w*P,R[1]+A[1]*_*D+C[1]*w*P];return[O(-1,-1),O(1,-1),O(1,1),O(-1,1)]},g=(_,w=16)=>Array.from({length:w},(R,A)=>[f.center[0]+Math.cos(A/w*2*Math.PI)*_,f.center[1]+Math.sin(A/w*2*Math.PI)*_]),m=(_,w)=>_.forEach((R,A)=>o.lines.seg([R[0],w,R[1]],[_[(A+1)%_.length][0],w,_[(A+1)%_.length][1]],X_)),b=(_,w,R,A,C)=>Tt(o.solid,YR(_),w,R,A,C);if(l==="steel"){let _=Math.min(c,u)/2;b(g(_,12),d,p,uh,hh),b(g(_*.75,12),p,p+.001,Do,Do),b(g(_*.25,6),p,p+.1,uh,hh);let w=g(_*1.9,12);b(w,p+.1,p+.13,uh,hh),m(w,p+.13);continue}if(l==="round"){let _=Math.min(c,u)/2,w=g(_);b(w,d,p,Dp,Up),b(g(_*.55),p,p+.002,Do,Do),m(w,p);continue}let v=x(c/2,u/2);b(v,d,p,Dp,Up);let y=x(c/2+.04,u/2+.04);b(y,p,p+.06,ch,ch),m(y,p+.06),m(v,p-.25);let M=Math.min(c,u)*.25,S=l==="wide"?[-c/4,c/4]:[0];for(let _ of S){let w=[f.center[0]+f.along[0]*_,f.center[1]+f.along[1]*_],R=[[-1,-1],[1,-1],[1,1],[-1,1]].map(([A,C])=>[w[0]+f.along[0]*M*A+f.across[0]*M*C,w[1]+f.along[1]*M*A+f.across[1]*M*C]);b(R,p+.06,p+.16,ch,Do)}}}function YR(i){let e=0;for(let t=0;t0,r.b>0,r.u0>0,r.u1>0],f=(p,x,g,m,b,v)=>{let y=[t.at(p,g),t.at(x,g),t.at(x,m),t.at(p,m)],M=(y[1][0]-y[0][0])*(y[2][1]-y[0][1])-(y[2][0]-y[0][0])*(y[1][1]-y[0][1]);Tt(i,M<0?[...y].reverse():y,b-o,v-o,k_,z_,{bottom:!0})};for(let[p,x]of[[0,l],[a,c]]){if(!x)continue;let g=n.y(p)-.03,m=p===0?0:a-jn;f(t.u0,t.u1,m,m+jn,g-Al,g),e.seg(s(t.u0,p,g-Al),s(t.u1,p,g-Al),gr)}for(let[p,x]of[[t.u0,u],[t.u1-jn,h]])if(x)for(let g=0;g<6;g++){let[m,b]=[a*g/6,a*(g+1)/6],v=Math.min(n.y(m),n.y(b))-.03;f(p,p+jn,m,b,v-Al,v)}let d=[];for(let[p,x]of[[0,l],[a-jn,c]]){if(!x)continue;let g=t.u1-t.u0-jn,m=Math.max(1,Math.ceil(g/3.5));for(let b=0;b<=m;b++)b===0&&!u||b===m&&!h||d.push([t.u0+g*b/m,p])}!l&&!c&&(u&&d.push([t.u0,a/2-jn/2]),h&&d.push([t.u1-jn,a/2-jn/2]));for(let[p,x]of d)f(p,p+jn,x,x+jn,o,n.y(x+jn/2)-.03-Al)}function qR(i,e){let t=[];if(i.forEach(([s,o],a)=>{o>=e&&t.push([s,o]);let l=i[a+1];if(l&&(o-e)*(l[1]-e)<0){let c=(e-o)/(l[1]-o);t.push([s+(l[0]-s)*c,e])}}),t.length<2)return[];let[n,r]=[t[0],t[t.length-1]];return r[1]>e&&t.push([r[0],e]),n[1]>e&&t.unshift([n[0],e]),t}var Z_=i=>vr(i)>=0?i:[...i].reverse();function J_(i,e,t,n,r,s=i,o=!1,a=[],l=null){let c=Dn(t),u=En(t),h=typeof n=="number"?{u0:n,u1:n,a:n,b:n}:n,[f,d]=[Math.max(0,h.a),Math.max(0,h.b)],p=c.w,x=c.u0-Math.max(0,h.u0),g=c.u1+Math.max(0,h.u1),m=(I,N,F)=>{let[H,B]=c.at(I,N);return[H,F-r,B]},b=new W(Fs),v=new W(Ls),y=new W(lh),M=(I,N)=>{for(let F=1;F+1m(I,N,F-H),_=[],w=[],R=[],A=null,C=null;if(t.shape==="flat"||t.shape==="parapet"){let I=t.eave_a-r,N=t.shape==="parapet",F=t.points&&t.points.length>=3?qd(t,N?0:Math.max(0,Math.min(h.a,h.b,h.u0,h.u1))):N?[c.at(c.u0,0),c.at(c.u1,0),c.at(c.u1,p),c.at(c.u0,p)]:[c.at(x,-f),c.at(g,-f),c.at(g,p+d),c.at(x,p+d)];if(Tt(i,F,I,I+.25,Ls,Fs,{bottom:!0}),F.forEach((H,B)=>{let X=F[(B+1)%F.length];e.seg([H[0],I+.252,H[1]],[X[0],I+.252,X[1]],mr),e.seg([H[0],I,H[1]],[X[0],I,X[1]],gr)}),N){let H=Z_(F),B=Ou(H,-.2);H.forEach((X,V)=>{let re=(V+1)%H.length;Tt(i,Z_([X,H[re],B[re],B[V]]),I+.25,I+.65,Ls,Fs),e.seg([X[0],I+.652,X[1]],[H[re][0],I+.652,H[re][1]],mr),e.seg([B[V][0],I+.652,B[V][1]],[B[re][0],I+.652,B[re][1]],mr)})}}else{let I=Hr(t,h);_=a.reduce((N,F)=>N.flatMap(H=>Nu(H,F)),I.faces),w=I.rim,R=I.ridges,A=I.gable,C=I.endProfiles??null}let O=!!t.open,D=new W(B_);for(let I of _)if(O)for(let N=1;N+1S(N)),b),M(I.map(N=>S(N,Xt)),v);if(w.forEach((I,N)=>{let F=w[(N+1)%w.length];O||M([S(I),S(F),S(F,Xt),S(I,Xt)],v),e.seg(S(I),S(F),O?mr:gr)}),O){K_(i,e,c,u,h,(I,N,F)=>m(I,N,F),r);return}for(let[I,N]of R)e.seg(S([I[0],I[1],I[2]+.004]),S([N[0],N[1],N[2]+.004]),mr);let P=t.base;if(!o){if(A){let I=l===null?[c.u0,c.u1]:[l===0?c.u0:c.u1];for(let N of I){let F=C?C[N===c.u0?0:1]:A,H=F?qR(F,P-Xt):[];H.length>=3&&M(H.map(([B,X])=>m(N,B,X)),y)}}if(t.shape!=="flat"&&t.shape!=="parapet")for(let I of[0,p]){let N=u.y(I)-Xt;N>P+.02&&M([m(c.u0,I,P),m(c.u1,I,P),m(c.u1,I,N),m(c.u0,I,N)],y)}else if(t.eave_a>P+.02){let I=[[c.u0,0],[c.u1,0],[c.u1,p],[c.u0,p]];I.forEach(([N,F],H)=>{let[B,X]=I[(H+1)%4];M([m(N,F,P),m(B,X,P),m(B,X,t.eave_a),m(N,F,t.eave_a)],y)})}}}function j_(i,e,t){let n=i.floors.filter(o=>o.rooms.length>0).sort((o,a)=>o.elevation-a.elevation);if(n.length===0)return[];let r=new Map,s=new Map(Is(i).map(o=>[o.key,o]));for(let o of e){if(Math.abs(o.x1-o.x0)<.1||Math.abs(o.z1-o.z0)<.1)continue;let a=Zd(i,o)??n[0],l=o.open?`${a.id}:open`:a.id,c=r.get(l);c||r.set(l,c={floor:a,base:0,solid:new lt,lines:new Wt,glass:new lt,sections:[],lift:!o.open}),c.sections.push(o.id);let u=ul(e,o),h=As(e,o)??u?.parent??null,f=a.elevation+a.height>o.base+.05&&!o.dormer&&!h,d=e.filter(g=>g!==o).flatMap(g=>As(e,g)===o?Uu(o,g):ul(e,g)?.parent===o?Uu(o,ul(e,g).extended):[]);for(let g of i.settings.roof.windows??[]){let m=s.get(g.face),b=m&&m.section===o.id?Tl(m,g):null;if(!b)continue;let v=b.map(y=>Fi(o,y[0],y[2]));d.push({u0:Math.min(...v.map(y=>y[0])),u1:Math.max(...v.map(y=>y[0])),v0:Math.min(...v.map(y=>y[1])),v1:Math.max(...v.map(y=>y[1]))})}let p=u?u.extended:h?cl(h,o):o,x=null;if(h){let g=Dn(p),m=Hr(h,{u0:0,u1:0,a:0,b:0}),b=v=>{let[y,M]=g.at(v,g.w/2),[S,_]=Fi(h,y,M);return Ts(m,S,_)??En(h).y(_)};x=b(g.u0)<=b(g.u1)?0:1}J_(c.solid,c.lines,p,ll(i,p,p.overhang??t),a.elevation,c.glass,f,d,x)}return[...r.values()].sort((o,a)=>+(o.lift===!1)-+(a.lift===!1))}function Q_(i){return i.floors.filter(e=>e.rooms.some(t=>t.points.length>=3)).sort((e,t)=>t.elevation-e.elevation)[0]??null}function ev(i){let e=i.settings.roof,t=Q_(i);if(!t||!e||e.type==="none"||e.type==="custom")return null;let n=t.rooms.flatMap(O=>O.points.map(D=>D[0])),r=t.rooms.flatMap(O=>O.points.map(D=>D[1])),s=i.settings.wall_exterior+e.overhang,[o,a]=[Math.min(...n)-s,Math.max(...n)+s],[l,c]=[Math.min(...r)-s,Math.max(...r)+s],u=new lt,h=new Wt,f={floor:t,base:t.height,solid:u,lines:h,glass:new lt};if(e.type==="flat"){let O=[[o,l],[a,l],[a,c],[o,c]];return Tt(u,O,0,.25,Ls,Fs,{bottom:!0}),O.forEach(([D,P],I)=>{let[N,F]=O[(I+1)%4];h.seg([D,.252,P],[N,.252,F],mr),h.seg([D,0,P],[N,0,F],gr)}),f}let d=a-o>=c-l,p=e.ridge==="short"?!d:d,x=(p?c-l:a-o)/2,g=Math.tan(e.pitch*pt),m=x*g,b=(O,D,P)=>p?[O,P,(l+c)/2+D]:[(o+a)/2+D,P,O],[v,y]=p?[o,a]:[l,c],M=new W(Fs),S=new W(Ls),_=(O,D,P,I,N)=>{u.tri(O,D,P,N),u.tri(O,P,I,N)};for(let O of[-1,1]){_(b(v,O*x,0),b(y,O*x,0),b(y,0,m),b(v,0,m),M),_(b(v,O*x,-Xt),b(v,0,m-Xt),b(y,0,m-Xt),b(y,O*x,-Xt),S),_(b(v,O*x,-Xt),b(y,O*x,-Xt),b(y,O*x,0),b(v,O*x,0),S);for(let D of[v,y])_(b(D,O*x,-Xt),b(D,O*x,0),b(D,0,m),b(D,0,m-Xt),S);h.seg(b(v,O*x,0),b(y,O*x,0),gr);for(let D of[v,y])h.seg(b(D,O*x,0),b(D,0,m),gr)}let w=e.overhang,R=new W(lh),A=x-w,C=A*g;for(let O of[v+w,y-w])u.tri(b(O,-A,-Xt),b(O,A,-Xt),b(O,0,C-Xt),R),u.tri(b(O,A,-Xt),b(O,-A,-Xt),b(O,0,C-Xt),R);return h.seg(b(v,0,m+.004),b(y,0,m+.004),mr),f}function kp(i,e=new Map){let t=i.settings.roof,n=t?.type==="custom"?null:ev(i),r=t?.type==="custom"?j_(i,t.sections??[],t.overhang):n?[n]:[];return q_(i,r),Y_(i,r,e),$_(i,r),r}function ph(i){let{start:e,axis:t,width:n}=i.info;return[[e[0],e[1]],[e[0]+t[0]*n,e[1]+t[1]*n]]}var tv=(i,e)=>`${i}|${Math.round(e[0]*50)},${Math.round(e[1]*50)}`;function nv(i,e){let t=[];for(let n of i){let r=n.info.opening.front;if(!r)continue;let[s,o]=ph(n);e.at(r,s)&&t.push(n.s0),e.at(r,o)&&t.push(n.s1)}return t}function iv(i,e){let t=Math.hypot(i.b[0]-i.a[0],i.b[1]-i.a[1])||1;return((e[0]-i.a[0])*(i.b[0]-i.a[0])+(e[1]-i.a[1])*(i.b[1]-i.a[1]))/t}function mh(i){let e=new Map,t=new Map;for(let r of i)for(let s of r){let o=s.info.opening.front;if(o)for(let a of ph(s)){let l=tv(o,a);e.set(l,(e.get(l)??0)+1),t.has(l)||t.set(l,[a[0],a[1]])}}return{points:[...e].filter(([,r])=>r>1).map(([r])=>t.get(r)).filter(r=>!!r),at:(r,s)=>(e.get(tv(r,s))??0)>1}}var Os={floor:923177,slab:659744,wall:1252657,wallTop:1323071,edge:3662079,edgeSoft:5995775},gh={wood:{color:1120814,tile:[0,0]},oak:{color:1252141,tile:[1,0]},tiles:{color:923695,tile:[2,0]},carpet:{color:1053995,tile:[0,1]},stone:{color:988971,tile:[1,1]},concrete:{color:1120295,tile:[2,1]}},pi=.2,Bo=8;var rv=(i,e)=>i.heightEnd===void 0?i.height??e:Math.max(i.height??e,i.heightEnd);function sv(i){let e=new Map,t=[],n=new Map;for(let r of i){let s="interior",o=null;if(r.exterior){let[a,l]=[r.b[0]-r.a[0],r.b[1]-r.a[1]],c=Math.hypot(a,l)||1,u=[l/c,-a/c],h=(Math.round(Math.atan2(u[1],u[0])/(2*Math.PI)*Bo)%Bo+Bo)%Bo;s=`s${h}`;let f=h/Bo*2*Math.PI;o=[Math.cos(f),Math.sin(f)]}e.has(s)||(e.set(s,t.length),t.push(o)),n.set(r,e.get(s))}return{buckets:t,wallBucket:n}}function ov(i){let e=(n,r,s)=>{let o=i?i(n,r):null;return o===null?s:Math.max(.05,Math.min(s,o))};return{topAt:e,lowestTop:(n,r,s,o,a)=>{if(!i)return a;let l=Math.max(2,Math.ceil((o-s)/.25)+1),c=a;for(let u=0;ut.topAt(h,f,n),lowestTop:(h,f)=>t.lowestTop(i.a,s,h,f,n)};let[o,a]=[i.height??e,i.heightEnd],l=(h,f)=>{let d=r>1e-9?((h-i.a[0])*s[0]+(f-i.a[1])*s[1])/r:0;return o+(a-o)*Math.max(0,Math.min(1,d))},c=(h,f)=>t.topAt(h,f,l(h,f));return{H:n,varies:!0,topAt:c,lowestTop:(h,f)=>{let d=Math.max(2,Math.ceil((f-h)/.25)+1),p=1/0;for(let x=0;x0:c.roomLeft===o.room_id,m=[-h[1],h[0]],b=g?m:[-m[0],-m[1]],v=Qr(i.rooms.find(R=>R.id===o.room_id)),y=Math.min(ko(c,i.height,n).lowestTop(p,p+d)-.02,v+o.sill+o.height),M=Math.max(Math.min(0,v),Math.min(v+o.sill,y-.1)),S=[b[1],-b[0]],_=h[0]*S[0]+h[1]*S[1]>0,w={opening:o,bucket:t.get(c),start:[c.a[0]+h[0]*p,c.a[1]+h[1]*p],axis:h,width:d,toRoom:b,faceRoom:g?c.left:c.right,faceOut:g?c.right:c.left,sill:M,top:y,hingeAtStart:o.hinge==="left"===_,exterior:c.exterior};s.push(w),r.set(c,[...r.get(c)??[],{s0:p,s1:p+d,sill:M,top:y,info:w}])}return{openings:s,spans:r}}var lv=i=>`${Math.round(i[0]*50)},${Math.round(i[1]*50)}`;function $R(i,e,t,n=!1,r=!1){let{info:s}=e,o=s.bucket,a=(u,h,f)=>[s.start[0]+s.axis[0]*(u-e.s0)+s.toRoom[0]*h,f,s.start[1]+s.axis[1]*(u-e.s0)+s.toRoom[1]*h],l=u=>u>t+1e-6?o:Xe,c=e.sill<0?e.sill+.004:Math.max(e.sill,.004);for(let u of[s.faceRoom,-s.faceOut])n||i.segSplit(a(e.s0,u,c),a(e.s0,u,e.top),ci,t,o),r||i.segSplit(a(e.s1,u,c),a(e.s1,u,e.top),ci,t,o),i.seg(a(e.s0,u,e.top),a(e.s1,u,e.top),ci,l(e.top)),e.sill>.01&&i.seg(a(e.s0,u,e.sill),a(e.s1,u,e.sill),ci,l(e.sill));for(let[u,h]of[[e.s0,n],[e.s1,r]])h||(i.seg(a(u,s.faceRoom,e.top),a(u,-s.faceOut,e.top),ci,l(e.top)),e.sill>.01&&i.seg(a(u,s.faceRoom,e.sill),a(u,-s.faceOut,e.sill),ci,l(e.sill)),e.sillt&&i.seg(a(u,s.faceRoom,t),a(u,-s.faceOut,t),Pu,tl+o))}function cv(i,e,t,n,r,s,o){let a=Math.min(e.cut_height,e.height),l=(f,d)=>(r.get(f)??[]).filter(d);for(let f of t.edges){let d=n.get(f.wall);for(let[m,b]of Eo(f,l(f.wall,v=>v.sill<=.005)))i.seg([m[0],.004,m[1]],[b[0],.004,b[1]],Ad);for(let[m,b]of Eo(f,l(f.wall,v=>v.silla)))i.seg([m[0],a,m[1]],[b[0],a,b[1]],Pu,tl+d);let p=ko(f.wall,e.height,s),{H:x,topAt:g}=p;for(let[m,b]of Eo(f,l(f.wall,v=>v.top>=x-.021))){if(!o&&!p.varies){i.seg([m[0],x,m[1]],[b[0],x,b[1]],Ii,x<=a+1e-6?cr+d:d);continue}let v=Math.max(1,Math.ceil(Math.hypot(b[0]-m[0],b[1]-m[1])/.3)),y=M=>[m[0]+(b[0]-m[0])*M/v,m[1]+(b[1]-m[1])*M/v];for(let M=0;M!!b.info.opening.front&&d>b.s0+.05&&dMath.abs(b-d)<.06);if(x||g||u.has(lv(f.p)))continue;let m=ko(f.wall,e.height,s).topAt(f.p[0],f.p[1]);i.segSplit([f.p[0],.004,f.p[1]],[f.p[0],m,f.p[1]],ci,Math.min(a,m),n.get(f.wall))}for(let f of r.values())for(let d of f){let p=d.info.opening.front,[x,g]=ph(d);$R(i,d,a,p?c.at(p,x):!1,p?c.at(p,g):!1)}}function uv(i,e){let t=new lt(!0,!0),n=[],r=new Wt,s=[],o=new W(Os.slab),a=(l,c=0,u=c-pi)=>{l.forEach((h,f)=>{let d=l[(f+1)%l.length];t.tri([h[0],u,h[1]],[h[0],c,h[1]],[d[0],c,d[1]],o),t.tri([h[0],u,h[1]],[d[0],c,d[1]],[d[0],u,d[1]],o)})};for(let l of i.rooms){if(l.points.length<3)continue;let c=Gr(l.points),u=gh[l.floor_material]??gh.wood,h=new W(u.color),f=e.filter(g=>ly(g,c)).map(g=>cy(g,.003));s.push(...f);let d=[...c,...f.flat()],p=t.count,x=Qr(l);for(let[g,m,b]of Vr(c,f)){let[v,y,M]=[d[g],d[m],d[b]];t.tri([v[0],x,v[1]],[M[0],x,M[1]],[y[0],x,y[1]],h,h,h,[v[0],v[1],M[0],M[1],y[0],y[1]],Xe,u.tile)}n.push({roomId:l.id,start:p,end:t.count,color:u.color}),a(c,x),Math.abs(x)>.005&&(a(c,Math.max(0,x),Math.min(0,x)),a([...c].reverse(),Math.max(0,x),Math.min(0,x)));for(let g of f)a([...Gr(g)].reverse()),g.forEach((m,b)=>{let v=g[(b+1)%g.length];r.seg([m[0],x+.006,m[1]],[v[0],x+.006,v[1]],Ii),r.seg([m[0],x-pi,m[1]],[v[0],x-pi,v[1]],ci)})}return{buffer:t,roomTris:n,holeLines:r,cutHoles:s}}var xh=.42,zp=.42;function hv(i,e,t){let n=new lt,r=new W(zp,zp,zp),s=new W(1,1,1),o=.002;for(let a of i)for(let[l,c]of Eo(a,(t.get(a.wall)??[]).filter(u=>u.sill<=.005))){let[u,h]=[c[0]-l[0],c[1]-l[1]],f=Math.hypot(u,h);if(f<.05)continue;let d=[h/f,-u/f],p=[(l[0]+c[0])/2+d[0]*.05,(l[1]+c[1])/2+d[1]*.05];if(!e.some(m=>m.points.length>=3&&Ve(p,m.points)))continue;let x=[l[0]+d[0]*xh,l[1]+d[1]*xh],g=[c[0]+d[0]*xh,c[1]+d[1]*xh];n.tri([l[0],o,l[1]],[x[0],o,x[1]],[g[0],o,g[1]],r,s,s),n.tri([l[0],o,l[1]],[g[0],o,g[1]],[c[0],o,c[1]],r,s,r)}return n}var Vp=(i,e)=>Number.parseInt(/^#?([0-9a-f]{6})$/i.exec(i?.trim()??"")?.[1]??e.slice(1),16),KR=i=>/^#?[0-9a-f]{6}$/i.test(i?.trim()??"");function Gp(i,e){return{outside:Vp(KR(e.wall_paint_outside)?e.wall_paint_outside:i.wall_paint_outside,g0),inside:Vp(i.wall_paint_inside,Vh),rooms:e.rooms.filter(t=>t.wall_paint&&t.points.length>=3).map(t=>({points:t.points,color:Vp(t.wall_paint,Vh)}))}}var ZR=14276045;function JR(i,e,t,n,r){let s=Math.hypot(t[0]-e[0],t[1]-e[1])||1,o=[(e[0]+t[0])/2,(e[1]+t[1])/2],a=[(t[1]-e[1])/s,-(t[0]-e[0])/s];Ve([o[0]+a[0]*.01,o[1]+a[1]*.01],i)&&(a=[-a[0],-a[1]]);let l=[o[0]+a[0]*.06,o[1]+a[1]*.06],c=n.rooms.find(u=>Ve(l,u.points));return c?c.color:r.some(u=>u.points.length>=3&&Ve(l,u.points))?n.inside:n.outside}function jR(i,e,t=-pi){let n=[-1/0,...new Set(i.flatMap(s=>[s.s0,s.s1])).values(),1/0].sort((s,o)=>s-o),r=[];for(let s=0;s+1f.s0l).map(f=>[f.sill,f.top]).sort((f,d)=>f[0]-d[0]),u=[],h=t;for(let[f,d]of c)f>h+1e-4&&u.push([h,f]),h=Math.max(h,d);e>h+1e-4&&u.push([h,e]),r.push({t0:o,t1:a,ranges:u})}return r}function fv(i,e,t,n,r,s,o,a){let l=Math.min(e.cut_height,e.height),c=a?Cd:0,u=a?g=>(m,b)=>JR(g,m,b,a,e.rooms):null,h=a?ZR:Os.wallTop,f=mh(r.values()),d=g=>f.points.some(m=>Math.hypot(m[0]-g[0],m[1]-g[1])<.03),p=g=>g&&g.info.opening.front?[g.sill,g.top]:null,x=(g,m)=>{let b=[];for(let[v,y]of g)m[0]>v+1e-4&&b.push([v,Math.min(y,m[0])]),y>m[1]+1e-4&&b.push([Math.max(v,m[1]),y]);return b};for(let g of t){let m=n.get(g),b=_s([g.b[0]-g.a[0],g.b[1]-g.a[1]]),v=(r.get(g)??[]).sort((I,N)=>I.s0-N.s0),y=ko(g,e.height,s),{H:M,topAt:S}=y,_=Math.min(0,...[g.roomLeft,g.roomRight].map(I=>Qr(e.rooms.find(N=>N.id===I)))),w=jR(v,M,_-pi),R=Math.hypot(g.b[0]-g.a[0],g.b[1]-g.a[1]),A=(o||y.varies)&&y.lowestTop(0,R){let N=Math.max(I.t0,-.5),F=Math.min(I.t1,R+.5),H=Math.max(1,Math.ceil((F-N)/.3));return Array.from({length:H},(B,X)=>({t0:X===0?I.t0:N+(F-N)*X/H,t1:X===H-1?I.t1:N+(F-N)*(X+1)/H,ranges:I.ranges,inner0:X>0,inner1:X({...I,inner0:!1,inner1:!1})),O=I=>(I[0]-g.a[0])*b[0]+(I[1]-g.a[1])*b[1],D=d(g.a)?p(v[0]):null,P=d(g.b)?p(v[v.length-1]):null;for(let I of C){let N=Ud(g.footprint,g.a,b,I.t0,I.t1);if(N.length<3)continue;let F=I.t1<=1e-6&&I.t0<0?D:I.t0>=R-1e-6?P:null,H=F?x(I.ranges,F):I.ranges,B=(Y,Q)=>Math.abs(O(Y)-Q)<1e-4,X=(Y,Q)=>I.inner0&&B(Y,I.t0)&&B(Q,I.t0)||I.inner1&&B(Y,I.t1)&&B(Q,I.t1),V=(Y,Q)=>!f.points.length||Math.hypot(Y[0]-Q[0],Y[1]-Q[1])>.5?!1:f.points.some(se=>Math.min(Math.hypot(se[0]-Y[0],se[1]-Y[1]),Math.hypot(se[0]-Q[0],se[1]-Q[1]))<.05),re=(Y,Q)=>X(Y,Q)||V(Y,Q),be=A?Math.min(...N.map(([Y,Q])=>S(Y,Q))):M;for(let[Y,Q]of H){let se=Math.min(Q,A?Math.max(...N.map(([st,Te])=>S(st,Te))):Q);if(se-Y<1e-4||be-Y<.01)continue;let Se=Y>.01,le=A&&Q>be,Ie=(st,Te)=>Math.min(Q,S(st,Te));if(Yl+1e-6?Rd+m:cr+m,Te=le&&beMath.min(l,Ie(ht,bt)):Math.min(se,l);Tt(i,N,Y,Te,Os.wall,h,{aoFrom:0,bottom:Se,fold:c+cr+m,topFold:c+st,skipSide:re,sideColor:u?.(N)})}se>l+1e-6&&be>l+1e-6&&Tt(i,N,Math.max(Y,l),le?Ie:se,Os.wall,h,{aoFrom:0,fold:c+m,bottom:Se&&Y>=l,skipSide:re,sideColor:u?.(N)})}}}}function Hp(i,e,t,n=[],r=[],s,o){let{walls:a,open:l}=al(i.rooms,{exterior:e,interior:t},i.walls??[]),c=ov(s),u=!!s,h=uv(i,n),{buckets:f,wallBucket:d}=sv(a),{openings:p,spans:x}=av(i,a,d,c),g=new lt;fv(g,i,a,d,x,c,u,o);let m=Bd(a,a.flatMap(_=>_.footprint)),b=new Wt;b.p.push(...h.holeLines.p),b.c.push(...h.holeLines.c),b.f.push(...h.holeLines.f),cv(b,i,m,d,x,c,u);let v=hv(m.edges,i.rooms,x),y=new Map;op(g,b,i,y,()=>new lt);for(let _ of r)dh(g,b,_.face,_.field,i.elevation);let M=Math.min(i.cut_height,i.height),S=[];for(let _ of i.furniture.filter(w=>!b0(w.type))){let w=g.count,R=b.p.length/6,A=Gt(i,_);Dl(_.type)||Ml(g,b,v,_,A),A+_.h>M+.05&&(Id(g,w,M,Iu),Ld(b,R,M,Iu)),S.push({id:_.id,start:w,end:g.count})}return{floor:h.buffer.geometry(),roomTris:h.roomTris,holes:h.cutHoles,walls:g.geometry(),ghosts:[...y].map(([_,w])=>({opacity:_,geometry:w.geometry()})),lines:b.geometry(),shadow:v.geometry(),buckets:f,openings:p,walls2d:a,openRooms:l,wallBuckets:a.map(_=>d.get(_)),furnitureTris:S,roofUnder:s}}function Wp(i,e){let t=_0(i,e),n=[...e.furniture.filter(a=>a.type==="stairwell").map(ts),...e.furniture.filter(a=>Qu(a)&&a.stair?.down).flatMap(mp)].filter(a=>a.length>=3),r=i.filter(a=>a.elevationl.elevation-a.elevation)[0];if(!r)return fr([...n,...t]);let o=r.furniture.filter(a=>(a.type==="stairs"||vt(a.type)?.hole)&&!(Qu(a)&&a.stair?.down)&&r.elevation+a.h>=e.elevation-.3).flatMap(a=>Qu(a)?mp(a):[ts(a)]).filter(a=>a.length>=3);return fr([...n,...o,...t])}var dv=.12,pv=1.35,Di=(i,e,t)=>Math.min(t,Math.max(e,i)),QR=i=>i<.5?4*i*i*i:1-(-2*i+2)**3/2,mv=i=>({...i,target:i.target.clone()});function gv({target:i,radius:e,theta:t,phi:n}){return new U(i.x+e*Math.sin(n)*Math.sin(t),i.y+e*Math.cos(n),i.z+e*Math.sin(n)*Math.cos(t))}function xv(i,e,t){let n=QR(t);return{target:new U().lerpVectors(i.target,e.target,n),radius:i.radius+(e.radius-i.radius)*n,theta:i.theta+(e.theta-i.theta)*n,phi:i.phi+(e.phi-i.phi)*n}}function bv(i,e){let t=e.theta??i.theta;for(;t-i.theta>Math.PI;)t-=2*Math.PI;for(;t-i.theta<-Math.PI;)t+=2*Math.PI;return{target:(e.target??i.target).clone(),radius:e.radius??i.radius,theta:t,phi:e.phi??i.phi}}function Xp(i,e,t,n,r){let s=2*i.radius*Math.tan(r*Math.PI/360)/(n||1),o=new U(Math.cos(i.theta),0,-Math.sin(i.theta)),a=new U(-Math.sin(i.theta),0,-Math.cos(i.theta));i.target.addScaledVector(o,-e*s),i.target.addScaledVector(a,t*s/Math.max(.35,Math.cos(i.phi)))}function yv(i,e,t,n){let r=n||1,s={theta:-e/r*3.2,phi:-t/r*2.4};return i.theta+=s.theta,i.phi=Di(i.phi+s.phi,dv,pv),s}function _v(i,e){return Math.abs(e.theta)<=1e-4&&Math.abs(e.phi)<=1e-4?!1:(i.theta+=e.theta,i.phi=Di(i.phi+e.phi,dv,pv),e.theta*=.9,e.phi*=.9,!0)}var eC={KeyW:"w",KeyA:"a",KeyS:"s",KeyD:"d",KeyQ:"q",KeyE:"e"},tC=new Set(["w","a","s","d","q","e","arrowup","arrowdown","arrowleft","arrowright"]);function nC(i){let e=i.code?.startsWith("Key")?eC[i.code]??null:i.key.toLowerCase();return e&&tC.has(e)?e:null}var iC=500,rC=400,sC=320,oC=6,vv=1.5,aC=1.8;function lC(i,e){let t=i.keys,n=(t.has("w")||t.has("arrowup")?1:0)-(t.has("s")||t.has("arrowdown")?1:0)-i.stick[1],r=(t.has("d")?1:0)-(t.has("a")?1:0),s=(t.has("arrowleft")||t.has("q")?1:0)-(t.has("arrowright")||t.has("e")?1:0)-i.stick[0];if(!n&&!r&&!s)return!1;let o=e/1e3;i.yaw+=s*aC*o;let[a,l]=[-Math.sin(i.yaw),-Math.cos(i.yaw)],[c,u]=[Math.cos(i.yaw),-Math.sin(i.yaw)];return i.eye.x=Di(i.eye.x+(a*n+c*r)*vv*o,i.bounds.x0,i.bounds.x1),i.eye.z=Di(i.eye.z+(l*n+u*r)*vv*o,i.bounds.z0,i.bounds.z1),!0}var El=class{view={target:new U,radius:16,theta:-.6,phi:.85};minRadius=2;maxRadius=80;locked=!1;walk=null;pointers=new Map;velocity={theta:0,phi:0};flight=null;press=null;lastTap=0;holdTimer;held=!1;grabbing=!1;swiping=null;pinch=null;listeners=[];el;camera;events;constructor(e,t,n){this.el=e,this.camera=t,this.events=n;let r=(l,c,u)=>{e.addEventListener(l,c,u),this.listeners.push([l,c])};r("pointerdown",l=>this.onDown(l)),r("pointermove",l=>this.onMove(l)),r("pointerup",l=>this.onUp(l)),r("pointercancel",l=>this.onUp(l)),r("wheel",l=>this.onWheel(l),{passive:!1}),r("contextmenu",l=>l.preventDefault());let s=l=>c=>{if(!this.walk||c.target?.closest?.("input, textarea, select"))return;let u=nC(c);u&&(c.preventDefault(),l?this.walk.keys.add(u):this.walk.keys.delete(u),this.events.change())},o=s(!0),a=s(!1);window.addEventListener("keydown",o),window.addEventListener("keyup",a),this.listeners.push(["__window_keydown",o],["__window_keyup",a])}dispose(){clearTimeout(this.holdTimer);for(let[e,t]of this.listeners)e.startsWith("__window_")?window.removeEventListener(e.slice(9),t):this.el.removeEventListener(e,t)}get active(){return this.pointers.size>0||this.flight!==null}get busy(){return this.active}update(e){if(this.walk){let n=this.walk,r=lC(n,n.last?Math.min(100,e-n.last):16);n.last=r?e:0;let s=new U(-Math.sin(n.yaw)*Math.cos(n.pitch),Math.sin(n.pitch),-Math.cos(n.yaw)*Math.cos(n.pitch));return this.view.target.copy(n.eye).add(s),this.camera.position.copy(n.eye),this.camera.lookAt(this.view.target),r}let t=!1;if(this.flight){let{from:n,to:r,start:s,duration:o}=this.flight,a=Math.min(1,(e-s)/o);this.view=xv(n,r,a),a>=1&&(this.flight=null),t=!0}else this.pointers.size===0&&(t=_v(this.view,this.velocity));return this.camera.position.copy(gv(this.view)),this.camera.lookAt(this.view.target),t}flyTo(e,t=700){let n=bv(this.view,e),r=mv(this.view);this.velocity={theta:0,phi:0},t<=0||matchMedia("(prefers-reduced-motion: reduce)").matches?(this.view=n,this.flight=null):this.flight={from:r,to:n,start:performance.now(),duration:t},this.events.change()}local(e){let t=this.el.getBoundingClientRect();return[e.clientX-t.left,e.clientY-t.top]}stopMotion(){this.flight=null,this.velocity={theta:0,phi:0}}onDown(e){this.el.setPointerCapture(e.pointerId);let t=this.pointers.size===0;if(this.pointers.set(e.pointerId,{x:e.clientX,y:e.clientY,button:e.button}),this.stopMotion(),t&&e.button===0&&this.events.grab?.(...this.local(e))){this.grabbing=!0;return}if(clearTimeout(this.holdTimer),this.held=!1,this.pointers.size===1){this.press={x:e.clientX,y:e.clientY,time:performance.now(),moved:!1};let[n,r]=this.local(e);this.holdTimer=setTimeout(()=>{!this.press||this.press.moved||this.pointers.size!==1||(this.held=!0,this.events.hold(n,r))},iC)}else this.press=null,this.pinch=this.pinchState()}onMove(e){let t=this.pointers.get(e.pointerId);if(!t)return;if(this.grabbing)return void this.events.drag?.(...this.local(e));if(this.swiping)return void this.events.swipeMove?.(e.clientY-this.swiping.startY);let[n,r]=[e.clientX-t.x,e.clientY-t.y];if(this.press&&!this.press.moved&&Math.hypot(e.clientX-this.press.x,e.clientY-this.press.y)>oC){this.press.moved=!0,clearTimeout(this.holdTimer);let[s,o]=this.local({clientX:this.press.x,clientY:this.press.y});if(this.pointers.size===1&&t.button===0&&!e.shiftKey&&this.events.swipeStart?.(s,o,e.clientX-this.press.x,e.clientY-this.press.y))return this.swiping={startY:this.press.y},this.velocity={theta:0,phi:0},void this.events.swipeMove?.(e.clientY-this.press.y)}if(this.locked){[t.x,t.y]=[e.clientX,e.clientY];return}if(this.walk){if(!(this.press&&!this.press.moved)&&this.pointers.size===1){let s=this.el.clientHeight||1;this.walk.yaw+=n/s*2.4,this.walk.pitch=Di(this.walk.pitch+r/s*1.8,-1.1,1.1),this.events.change()}[t.x,t.y]=[e.clientX,e.clientY];return}if(this.pointers.size===1)this.press&&!this.press.moved||(t.button===1||t.button===2||e.shiftKey?Xp(this.view,n,r,this.el.clientHeight,this.camera.fov):this.velocity=yv(this.view,n,r,this.el.clientHeight)),[t.x,t.y]=[e.clientX,e.clientY];else{[t.x,t.y]=[e.clientX,e.clientY];let s=this.pinchState();this.pinch&&s&&(this.zoom(this.pinch.dist/Math.max(1,s.dist)),Xp(this.view,s.mid[0]-this.pinch.mid[0],s.mid[1]-this.pinch.mid[1],this.el.clientHeight,this.camera.fov)),this.pinch=s}this.pointers.size===1&&this.press&&!this.press.moved||this.events.change()}onUp(e){if(this.pointers.has(e.pointerId)){if(this.pointers.delete(e.pointerId),this.grabbing)return this.grabbing=!1,void this.events.drop?.();if(this.swiping)return this.swiping=null,this.press=null,void this.events.swipeEnd?.();if(this.pointers.size<2&&(this.pinch=null),clearTimeout(this.holdTimer),this.held)this.held=!1,this.press=null;else if(this.press&&!this.press.moved&&e.type==="pointerup"&&performance.now()-this.press.timea*n);return{id:`${i.id}:vehicle`,type:e,x:i.x,z:i.z,rotation:i.rotation,w:r,d:s,h:o,variant:i.variant??null,entity:null,power:null}}function bh(i,e){let t=[],n=!1;for(let r of i.furniture){t.push(r);let s=r.type==="parking"?e.get(r.id):void 0,o=s?cC(r,s):null;o&&(t.push(o),n=!0)}return n?{...i,furniture:t}:i}var uC="https://tile.openstreetmap.org/{z}/{x}/{y}.png";var hC=40075016686e-3,yh=Math.PI/180,fC=18,dC=.5,pC=160;function mC(i,e,t){let n=2**t,r=(e+180)/360*n,s=(1-Math.log(Math.tan(i*yh)+1/Math.cos(i*yh))/Math.PI)/2*n;return[r,s]}var gC=(i,e)=>hC*Math.cos(i*yh)/2**e;function Mv(i,e,t,n=pC){let[r,s]=mC(i,e,t),o=gC(i,t),a=n/o,l=2**t-1,c=[];for(let u=Math.floor(s-a);u<=Math.floor(s+a);u++)for(let h=Math.floor(r-a);h<=Math.floor(r+a);h++){if(u<0||u>l)continue;let f=(h%(l+1)+l+1)%(l+1);c.push({x:f,y:u,z:t,east:(h-r)*o,north:-(u-s)*o,size:o})}return c}function Sv(i,e){return i.replace("{z}",String(e.z)).replace("{x}",String(e.x)).replace("{y}",String(e.y)).replace("{s}","abc"[(e.x+e.y)%3])}var wv=i=>i.url&&i.url.startsWith("https://")?i.url:uC;function Tv(i,e,t,n){let r=t*yh;return[n.x+i*Math.cos(r)+e*Math.sin(r),n.z+i*Math.sin(r)-e*Math.cos(r)]}var Av=i=>!!i&&i.on===!0&&Number.isFinite(i.lat)&&Number.isFinite(i.lon),Ev=i=>({x:i.x??0,z:i.z??0,opacity:i.opacity??dC,zoom:i.zoom??fC});var xC="strict-origin-when-cross-origin",Yp=new Map;function Rv(i){let e=Yp.get(i);return e||(e=fetch(i,{referrerPolicy:xC,mode:"cors",credentials:"omit"}).then(async t=>t.ok&&(t.headers.get("content-type")??"").startsWith("image/")?await t.blob():null).catch(()=>null).then(t=>(t||setTimeout(()=>Yp.delete(i),6e4),t)),Yp.set(i,e)),e}var zo=256,bC=Math.PI/180,_h=class{mesh=new we(new sn(1,1),new Ke({transparent:!0,depthWrite:!1,side:ut}));canvas=null;texture=null;key="";generation=0;centre=[0,0];onChange=()=>{};scene;constructor(e){this.scene=e,this.mesh.rotation.order="YXZ",this.mesh.renderOrder=-2,this.mesh.visible=!1,this.mesh.name="live-map",e.add(this.mesh)}set(e,t,n,r=1){if(!Av(e)){this.mesh.visible=!1,this.generation++,this.key="";return}let s=Ev(e),o=wv(e),a=`${e.lat},${e.lon},${s.zoom},${o}`;a!==this.key&&this.load(a,e,s.zoom,o);let[l,c]=this.centre,[u,h]=Tv(l,c,t,s);this.mesh.position.set(u,n,h),this.mesh.rotation.set(-Math.PI/2,-t*bC,0);let f=this.mesh.material;f.opacity=s.opacity,f.color.setScalar(r),this.mesh.visible=this.canvas!==null}load(e,t,n,r){this.key=e;let s=++this.generation,o=Mv(t.lat,t.lon,n);if(!o.length)return;let a=o[0].size,l=Math.min(...o.map(x=>x.east)),c=Math.max(...o.map(x=>x.north)),u=Math.round((Math.max(...o.map(x=>x.east))-l)/a)+1,h=Math.round((c-Math.min(...o.map(x=>x.north)))/a)+1,f=document.createElement("canvas");f.width=u*zo,f.height=h*zo,this.canvas=f,this.texture?.dispose(),this.texture=new zt(f),this.texture.colorSpace=ft,this.texture.anisotropy=4;let d=this.mesh.material;d.map=this.texture,d.needsUpdate=!0,this.mesh.geometry.dispose(),this.mesh.geometry=new sn(u*a,h*a),this.centre=[l+u*a/2,c-h*a/2];let p=f.getContext("2d");if(p)for(let x of o)this.draw(p,x,r,s,Math.round((x.east-l)/a),Math.round((c-x.north)/a))}draw(e,t,n,r,s,o){Rv(Sv(n,t)).then(a=>a?createImageBitmap(a):null).then(a=>{!a||r!==this.generation||(e.drawImage(a,s*zo,o*zo,zo,zo),this.texture&&(this.texture.needsUpdate=!0),this.onChange())})}dispose(){this.generation++,this.scene.remove(this.mesh),this.mesh.geometry.dispose(),this.mesh.material.dispose(),this.texture?.dispose()}};var yC=globalThis,Cv=yC.__nextfloorPluginStore??={plugins:new Map,listeners:new Set},_C=Cv.plugins,XB=Cv.listeners;var vC=5;function MC(i,e){i.errors.lengthNumber.isFinite(a))&&Number.isFinite(r.level)))return i;let o=a=>Math.max(0,Math.min(1,a));return{color:[o(r.color[0]),o(r.color[1]),o(r.color[2])],level:o(r.level)}}catch(r){return MC(n.status,r),i}}var Iv={rainbow:(i,e)=>{let t=(e*.08%1+1)%1,n=r=>Math.max(0,Math.min(1,Math.abs((t*6+r)%6-3)-1));return{color:[n(0),n(4),n(2)],level:i.level}},flicker:(i,e)=>({...i,level:i.level*(.75+.15*Math.sin(e*17)+.1*Math.sin(e*31+1))}),pulse:(i,e)=>({...i,level:i.level*(.65+.35*Math.sin(e*Math.PI))})};function Lv(i,e,t){return!i||!e?i:Object.prototype.hasOwnProperty.call(Iv,e)?Iv[e]?.(i,t)??i:Pv(i,e,t)}var Vo=2043986,Wr=2769520,Fv=2242399,vh=1845831,Ov=1450554,mi=16758087,Nv=1846349,Dv=2572395,Uv=1120816,Bv=1845831,kv=3662079,zv=5995775,Vv=9085695,Xr=Ue(3662079,.08),Gv=1.2,Hv=1.5,Wv=.2,Xv=.52;function Mh(i,e,t,n,r,s){let o=(x,g,m)=>e(x,g,m),{x0:a,x1:l,n0:c,n1:u,y0:h,y1:f}=t,d=x=>Ue(n.getHex(),x),p=[[o(a,c,f),o(l,c,f),o(l,u,f),o(a,u,f),r],[o(a,c,h),o(l,c,h),o(l,u,h),o(a,u,h),d(.6)],[o(a,u,h),o(l,u,h),o(l,u,f),o(a,u,f),n],[o(a,c,h),o(l,c,h),o(l,c,f),o(a,c,f),d(.85)],[o(a,c,h),o(a,u,h),o(a,u,f),o(a,c,f),d(.92)],[o(l,c,h),o(l,u,h),o(l,u,f),o(l,c,f),d(.92)]];for(let[x,g,m,b,v]of p)i.tri(x,g,m,v,v,v,void 0,s),i.tri(x,m,b,v,v,v,void 0,s)}function Vt(i,e,t,n,r,{cut:s,bucket:o}){if(t.y1<=s+1e-6)return Mh(i,e,t,n,r,Xe);if(t.y0>=s-1e-6)return Mh(i,e,t,n,r,o);Mh(i,e,{...t,y1:s},n,r,Xe),Mh(i,e,{...t,y0:s},n,r,o)}function Qn(i,e,t,n,r,s,o,a,{cut:l,bucket:c},u=0){let h=(f,d,p)=>{let x=y=>u?(o-y)/u:.5,[g,m,b,v]=[e(t,r,f),e(n,r,f),e(n,r,d),e(t,r,d)];i.tri(g,m,b,a,a,a,[0,x(f),1,x(f),1,x(d)],p),i.tri(g,b,v,a,a,a,[0,x(f),1,x(d),0,x(d)],p)};o<=l+1e-6?h(s,o,Xe):s>=l-1e-6?h(s,o,c):(h(s,l,Xe),h(l,o,c))}function Yv(i,e,t,n,r,s,o,a,l,c){let[u,h,f,d]=[e(t,r,o),e(n,r,o),e(n,s,o),e(t,s,o)],p=(s-r)/c;i.tri(u,h,f,a,a,a,[0,0,1,0,1,p],l),i.tri(u,f,d,a,a,a,[0,0,1,p,0,p],l)}var wC=16777215,TC=13225686,AC=15722456,qv=.08,$v=.085;function Kv(i){let{info:e,state:t,frame:n,fold:r}=i;if(t.cover===null)return;let[s,o,a]=[e.width,e.sill,e.top],l=e.opening.blind??"roller",c=-e.faceOut,u=e.faceRoom;l==="inside"?Vt(i.frames,n,{x0:-.03,x1:s+.03,n0:u,n1:u+.07,y0:a-.02,y1:a+.07},new W(15921906),new W(16250871),r):Vt(i.frames,n,{x0:-.05,x1:s+.05,n0:c-.15,n1:c,y0:a,y1:a+.2},new W(Ov),new W(Wr),r);let h=t.cover2!=null?[[0,s/2,t.cover],[s/2,s,t.cover2]]:[[0,s,t.cover]];for(let[f,d,p]of h){let x=Math.min(1,Math.max(0,p));if(x<=.01)continue;let g=a-x*(a-o);l==="inside"?Qn(i.blinds,n,f+.01,d-.01,u+.04,g,a-.02,new W(AC),r):l==="venetian"?EC(i,f,d,c-.07,g,a,t.slats??0):Qn(i.blinds,n,f,d,c-.07,g,a,new W(wC),r,.045)}}function EC(i,e,t,n,r,s,o){let{frame:a,fold:l}=i,c=new W(TC),u=Math.PI/2*(.12+.88*Math.min(1,Math.max(0,o))),h=Math.sin(u)*$v/2,f=Math.cos(u)*$v/2;for(let d=s-qv/2;d>r;d-=qv){let p=d>=l.cut?l.bucket:Xe,[x,g,m,b]=[a(e,n-h,d+f),a(t,n-h,d+f),a(t,n+h,d-f),a(e,n+h,d-f)];i.blinds.tri(x,g,m,c,c,c,[0,.5,1,.5,1,.5],p),i.blinds.tri(x,m,b,c,c,c,[0,.5,1,.5,0,.5],p)}}function Zv(i){let{info:e,state:t,frame:n,fold:r}=i,[s,o,a]=[e.width,e.top,Math.min(0,e.sill)],l=e.opening.type==="garage"&&(i.markClosed?!!t.sensed&&(t.cover??1)>=.95:(t.cover??1)<.95),c=l?Ue(mi,.8):new W(Vo),u=l?Ue(mi,1):new W(Wr),[h,f]=[-e.faceOut-.012,e.faceRoom+.012],d=(p,x,g)=>Vt(i.frames,n,{x0:p,x1:x,n0:h,n1:f,y0:g,y1:o+.045},c,u,r);d(-.045,.02,a),d(s-.02,s+.045,a),d(.02,s-.02,o-.02)}function Jv(i){let{info:e,state:t,frame:n,fold:r,mid:s}=i,[o,a,l]=[e.width,e.top,Math.min(0,e.sill)],c=a-l,u=_r(e.opening,e.exterior),h=u==="passage",f=w0(u),d=e.opening.swing==="out"?-1:1,p=d>0?e.faceRoom:-e.faceOut,x=e.opening.leaves===2,g=new W(Vo),m=new W(Wr),b=.02,v=o-.02,y=S0(o,u,e.hingeAtStart,e.opening);if(y){for(let[R,A]of y.panels){let C=(O,D,P,I)=>Vt(i.frames,n,{x0:O,x1:D,n0:s-.03,n1:s+.03,y0:P,y1:I},g,m,r);C(R,R+.04,l+.02,a-.02),C(A-.04,A,l+.02,a-.02),C(R,A,l+.02,l+.1),Qn(i.glass,n,R+.04,A-.04,s,l+.1,a-.02,Xr,r)}b=y.x0,v=y.x1}let M=x?(v-b)/2-.004:v-b,S=f?.06:.04;f&&(Vt(i.frames,n,{x0:.02,x1:o-.02,n0:-e.faceOut-.02,n1:e.faceRoom,y0:l,y1:l+.02},new W(vh),m,r),e.exterior&&Vt(i.frames,n,{x0:o/2-.08,x1:o/2+.08,n0:-e.faceOut-.1,n1:-e.faceOut,y0:a+.1,y1:a+.17},Ue(mi,.55),Ue(mi,.85),{cut:r.cut,bucket:Xe}));let _=e.opening.open_angle?Math.min(180,Math.max(5,e.opening.open_angle))*pt:Hv,w=h?[]:[[e.hingeAtStart,t.open]];x&&!h&&w.push([!e.hingeAtStart,t.open2??0]);for(let[R,A]of w){let C=Math.min(1,Math.max(0,A)),O=u==="sliding"?0:C*_,D=u==="sliding"?C*M:0,P=(Q,se,Se)=>{let le=Q*Math.cos(O)-se*Math.sin(O)-D,Ie=p+d*(se*Math.cos(O)+Q*Math.sin(O)+(D?.05:0));return n(R?b+le:v-le,Ie,Se)},I={cut:r.cut,bucket:C>.05?Xe:r.bucket},N=i.markClosed?!!t.sensed&&C<.05:C>.9&&!(R===e.hingeAtStart&&t.assumed),F=N?Ue(mi,.7):new W(f?Uv:Nv),H=N?Ue(mi,.9):new W(f?Bv:Dv),B=(Q,se,Se,le,Ie=-S,st=0)=>Vt(i.frames,P,{x0:Q,x1:se,n0:Ie,n1:st,y0:Se,y1:le},F,H,I);u==="glass"?(B(0,.05,l+.01,a-.01),B(M-.05,M,l+.01,a-.01),B(.05,M-.05,l+.01,l+.12),B(.05,M-.05,a-.08,a-.01),Qn(i.glass,P,.05,M-.05,-S/2,l+.12,a-.08,Xr,I)):B(0,M,l+.01,a-.01),u==="front_glass"?Qn(i.glass,P,.12,M-.12,.001,l+c*.55,a-.18,Xr,I):f&&Qn(i.glass,P,.1,.18,.001,l+.3,a-.3,Xr,I);let X=l+Math.min(1.05,c*.5),V=f?.3:.012,[re,be]=f?[M-.11,M-.08]:[M-.16,M-.05],Y=(Q,se)=>Vt(i.frames,P,{x0:re,x1:be,n0:Q,n1:se,y0:X-V,y1:X+V},new W(zv),new W(Vv),I);if(Y(.004,.05),Y(-S-.05,-S-.004),t.unlocked){let Q=new W(kv);Vt(i.frames,P,{x0:M-.012,x1:M+.004,n0:-S-.004,n1:.004,y0:l+.06,y1:a-.06},Q,Q,{cut:r.cut,bucket:Xe})}}}function jv(i){let{info:e,state:t,frame:n,fold:r}=i,[s,o,a]=[e.width,e.top,Math.min(0,e.sill)],l=Math.min(1,Math.max(0,t.cover??1)),c=new W(13951231),u=e.faceRoom-.03;l>.01&&Qn(i.blinds,n,.02,s-.02,u,a+(o-a)*(1-l),o,c,r,.5);let h=(1-l)*(o-a);h>.01&&Yv(i.blinds,n,.02,s-.02,u,u+h,o+.03,c,r.bucket,.5)}var RC=4936290,CC=7041926,Qv=2764860,eM=9082024;function tM(i,e){let{info:t}=i;return t.opening.type!=="window"||!t.exterior||t.opening.light_well===!1?!1:t.opening.light_well===!0||t.sillVt(i.frames,n,{x0:m,x1:b,n0:v,n1:y,y0:c,y1:u},h,f,r);p(s-d,s,a-l,a),p(o,o+d,a-l,a),p(s-d,o+d,a-l-d,a-l),Vt(i.frames,n,{x0:s,x1:o,n0:a-l,n1:a,y0:c-d,y1:c},h,f,r);let x=(m,b)=>Vt(i.frames,n,{x0:m,x1:b,n0:a-l,n1:a,y0:u-.025,y1:u},new W(Qv),new W(eM),r),g=Math.max(3,Math.round((o-s)/.06));for(let m=0;m<=g;m++){let b=s+(o-s)*m/g;x(b-.008,b+.008)}Vt(i.frames,n,{x0:s,x1:o,n0:a-l-.01,n1:a-l+.02,y0:u-.03,y1:u},new W(Qv),new W(eM),r)}var Ns={open:0,open2:0,tilt:0,tilt2:0,cover:null};function iM(i){let{info:e,frame:t,fold:n,mid:r}=i,[s,o,a]=[e.width,e.sill,e.top],[l,c]=[.04,.025],u=new W(Vo),h=new W(Wr),f=(b,v,y,M)=>Vt(i.frames,t,{x0:b,x1:v,n0:r-c,n1:r+c,y0:y,y1:M},u,h,n);i.first&&f(0,l,o,a),i.last&&f(s-l,s,o,a);let[d,p]=[i.first?l:-i.over[0],i.last?s-l:s+i.over[1]];f(d,p,o,o+.03),f(d,p,a-l,a);let x=e.opening.front?0:e.opening.panes,g=Math.max(1,x==null?Math.max(1,Math.round((p-d)/.9)):Math.round(x)),m=(p-d)/g;for(let b=1;bVt(i.frames,n,{x0:A,x1:C,n0:s-u,n1:s+u,y0:O,y1:D},h,f,r),x=a+(a>.05?c:.03);p(0,c,a,l),p(o-c,o,a,l),p(c,o-c,a,x),p(c,o-c,l-c,l);let g=e.opening.sill_boards??"auto";g!=="none"&&(g!=="auto"||a>.3)&&(g!=="outside"&&Vt(i.frames,n,{x0:-.04,x1:o+.04,n0:s+u,n1:e.faceRoom+.07,y0:a-.03,y1:a},d,f,r),e.exterior&&g!=="inside"&&Vt(i.frames,n,{x0:-.03,x1:o+.03,n0:-e.faceOut-.06,n1:s-u,y0:a-.04,y1:a-.02},d,f,r));let m=.055,[b,v]=[x,l-c],[y,M]=[s+u,s+u+.06],S=e.hingeAtStart,_=e.opening.opens??"turn",w=_==="slide"?PC(o,c,S,e.opening.leaves,t.open,t.open2??0):e.opening.leaves===2?[{atStart:S,x0:S?c:o/2,x1:S?o/2:o-c,open:t.open,tilt:t.tilt},{atStart:!S,x0:S?o/2:c,x1:S?o-c:o/2,open:t.open2??0,tilt:t.tilt2??0}]:[{atStart:S,x0:c,x1:o-c,open:t.open,tilt:t.tilt}],R=_r(e.opening,e.exterior);for(let A of w){let C=_==="top"?Math.max(A.open,A.tilt)*Xv:0,D=(_!=="slide"||!!A.slide)&&(A.open>.02||A.tilt>.02),P=i.markClosed?!!t.sensed&&!D:D,I=P?Ue(mi,.75):new W(Fv),N=P?Ue(mi,.95):f,F=A.x1-A.x0,H=_==="turn",B=H?A.open*Gv:0,X=H?A.tilt*Wv:0,V=(A.slide??0)*A.open,re=_==="slide"&&A.track===0?-.065:0,be=(se,Se,le)=>{if(C>0){let[et,Yt]=[Se-y,le-v],[kt,on]=[Math.cos(C),Math.sin(C)];return n(A.atStart?A.x0+se:A.x1-se,y+et*kt+Yt*on,v-et*on+Yt*kt)}let Ie=le-b,st=Se+Ie*Math.sin(X)+re,Te=b+Ie*Math.cos(X),ht=se*Math.cos(B)-(st-y)*Math.sin(B),bt=y+(st-y)*Math.cos(B)+se*Math.sin(B);return n((A.atStart?A.x0+ht:A.x1-ht)+V,bt,Te)},Y={cut:r.cut,bucket:B>.05||C>.05?Xe:r.bucket},Q=(se,Se,le,Ie,st=y,Te=M)=>Vt(i.frames,be,{x0:se,x1:Se,n0:st,n1:Te,y0:le,y1:Ie},I,N,Y);if(Q(0,m,b,v),Q(F-m,F,b,v),Q(m,F-m,b,b+m),Q(m,F-m,v-m,v),Qn(i.glass,be,m,F-m,(y+M)/2,b+m,v-m,P?Ue(mi,.16):Xr,Y),R==="bars"){let[se,Se]=[(b+v)/2,(y+M)/2];Q(m,F-m,se-.012,se+.012,Se-.012,Se+.012),Q(F/2-.012,F/2+.012,b+m,v-m,Se-.012,Se+.012)}}}var qp=i=>i.opening.front??i.opening.id;function $p(i,e,t,n=-1/0){let r=new lt,s=new lt,o=new lt(!0),a=[],l=[],c=[],u=new Map;i.forEach((x,g)=>{let m=qp(x);u.set(m,[...u.get(m)??[],g])});let h=x=>[[x.start[0],x.start[1]],[x.start[0]+x.axis[0]*x.width,x.start[1]+x.axis[1]*x.width]],f=x=>`${Math.round(x[0]*50)},${Math.round(x[1]*50)}`,d=new Map,p=new Map;for(let x of u.values()){let g=new Map,m=new Map;for(let v of x){let[y,M]=h(i[v]);g.set(f(y),[...g.get(f(y))??[],v]),m.set(f(M),[...m.get(f(M))??[],v])}let b=(v,y)=>{if(y==null||y===v)return 0;let M=Math.abs((i[v].faceRoom-i[v].faceOut)/2),[S,_]=[i[v].axis,i[y].axis],w=Math.max(-1,Math.min(1,S[0]*_[0]+S[1]*_[1])),R=Math.acos(w);return Rw!==v),_=(g.get(f(M))??[]).find(w=>w!==v);d.set(v,[S==null,_==null]),p.set(v,[b(v,S),b(v,_)])}}for(let x=0;x[g.start[0]+g.axis[0]*w+g.toRoom[0]*R,A,g.start[1]+g.axis[1]*w+g.toRoom[1]*R],mid:(g.faceRoom-g.faceOut)/2,markClosed:g.opening.mark==="closed",fold:{cut:t,bucket:g.bucket},frames:r,glass:s,blinds:o,first:y,last:M,over:p.get(x)??[0,0]};(b==="door"&&v!=="passage"||b==="garage")&&Zv(S),b==="door"?Jv(S):b==="garage"?jv(S):v==="glass_wall"?iM(S):rM(S),tM(S,n)&&nM(S,n),b!=="garage"&&Kv(S);let _=qp(g);a.push({id:_,start:m.frames,end:r.count}),l.push({id:_,start:m.glass,end:s.count}),c.push({id:_,start:m.blinds,end:o.count})}return{frames:r.geometry(),glass:s.geometry(),blinds:o.geometry(),frameTris:a,glassTris:l,blindTris:c}}var Kp=Math.PI/180,Rl=2400,Go=1600,Zp=9,sM=360;function Sh(i,e=64){let t=document.createElement("canvas");t.width=t.height=e;let n=t.getContext("2d"),r=n.createRadialGradient(e/2,e/2,0,e/2,e/2,e/2);for(let[s,o]of i)r.addColorStop(s,o);return n.fillStyle=r,n.fillRect(0,0,e,e),new zt(t)}function IC(i){let t=document.createElement("canvas");t.width=128,t.height=128/2;let n=t.getContext("2d"),r=i*9301+49297,s=()=>(r=(r*9301+49297)%233280)/233280;for(let o=0;o<7;o++){let a=128*(.2+.6*s()),l=128/2*(.45+.25*s()),c=128*(.12+.14*s()),u=n.createRadialGradient(a,l,0,a,l,c);u.addColorStop(0,"rgba(255,255,255,0.9)"),u.addColorStop(.6,"rgba(255,255,255,0.45)"),u.addColorStop(1,"rgba(255,255,255,0)"),n.fillStyle=u,n.fillRect(0,0,128,128/2)}return new zt(t)}var wh=class{group=new ct;scene;bounds={x0:-10,x1:10,z0:-10,z1:10,y0:0,y1:8};view=null;rain;rainVel=new Float32Array(Rl*3);snow;snowPhase=new Float32Array(Go);hail;clouds=[];bolt;disc;halo;stars;cover;last=0;nextBolt=0;boltUntil=0;onFlash=null;constructor(e){this.scene=e,this.group.name="live-weather",this.group.renderOrder=5;let t=new Fe;t.setAttribute("position",new ke(new Float32Array(Rl*6),3)),this.rain=new gn(t,new Lt({color:11128309,transparent:!0,opacity:.5,depthWrite:!1}));let n=Sh([[0,"rgba(255,255,255,1)"],[.5,"rgba(255,255,255,0.6)"],[1,"rgba(255,255,255,0)"]],32),r=new Fe;r.setAttribute("position",new ke(new Float32Array(Go*3),3)),this.snow=new xn(r,new cn({color:16185855,size:.16,map:n,transparent:!0,opacity:.9,depthWrite:!1}));for(let h=0;h.02,this.stars.position.set((n.x0+n.x1)/2,n.y0,(n.z0+n.z1)/2),this.stars.scale.setScalar(r*3);let a=this.cover.material,l=(t?.snow??0)+(t?.hail??0)*.5,c=t?.rain??0;a.color.setHex(l>.05?16054527:1848656),a.opacity=l>.05?.3+.45*Math.min(1,l):c>.1?.25*Math.min(1,c):0,this.cover.visible=a.opacity>.02,this.cover.position.set((n.x0+n.x1)/2,n.y0-.18,(n.z0+n.z1)/2),this.cover.scale.set(n.x1-n.x0,n.z1-n.z0,1)}set(e){let t=this.view;this.view=e,this.group.visible=!!e;let n=e?.weather??null;if(e&&n&&n.fog>.02&&!e.low){let r=new W(e.sky[0]/255,e.sky[1]/255,e.sky[2]/255);this.scene.fog=new ls(r,.008+.04*n.fog)}else this.scene.fog instanceof ls&&(this.scene.fog=null);(!t||t.low!==e?.low||!!t.weather!=!!n)&&this.seed(),this.placeDisc(),this.placeNight(),n?.lightning||this.endBolt()}windVector(){let e=this.view?.weather;if(!e)return[0,0];let n=((e.windFrom??270)+(this.view?.north??0)+180)*Kp,r=.4+7*e.wind;return[Math.sin(n)*r,-Math.cos(n)*r]}count(e,t){let n=this.view?.low??!1;return Math.round(Math.min(1,e)*t*(n?.3:1))}seed(){let e=this.bounds,t=this.view?.weather,n=()=>e.x0+Math.random()*(e.x1-e.x0),r=()=>e.z0+Math.random()*(e.z1-e.z0),s=()=>e.y0+Math.random()*(e.y1-e.y0),o=this.rain.geometry.getAttribute("position");for(let c=0;c.01,this.snow.visible=!!t&&t.snow>.01,this.hail.visible=!!t&&t.hail>.01,this.clouds.forEach((c,u)=>{c.angle=u/Zp*Math.PI*2+Math.random()*.5,c.ring=1.7+Math.random()*.9,c.lift=.35+Math.random()*.35,c.scale=.55+Math.random()*.45,c.sx=e.x0+Math.random()*(e.x1-e.x0),c.sz=e.z0+Math.random()*(e.z1-e.z0)}),this.placeClouds(0)}placeClouds(e){let t=this.view,n=t?.weather,r=n?.cloud??0,s=this.bounds,o=(s.x0+s.x1)/2,a=(s.z0+s.z1)/2,l=Math.max(s.x1-s.x0,s.z1-s.z0),[c,u]=this.windVector(),h=Math.round(r*Zp),f=t?.sky??[20,28,44],d=(f[0]+f[1]+f[2])/765,p=n?.rain||n?.lightning?.3:0,x=Math.max(.12,Math.min(1,.28+d*.9-p-.25*Math.max(0,r-.6))),g=Math.hypot(c,u)/Math.max(20,l*4)*e*Math.sign(c||1);this.clouds.forEach((m,b)=>{let v=bs.x1+S&&(m.sx=s.x0-S),m.sxs.z1+S&&(m.sz=s.z0-S),m.sz.9||!r&&t.elevation<.5){this.disc.visible=this.halo.visible=!1;return}let s=this.bounds,o=new U((s.x0+s.x1)/2,s.y0,(s.z0+s.z1)/2),a=Math.max(70,Math.max(s.x1-s.x0,s.z1-s.z0)*3.5),l=((r?t.azimuth+180:t.azimuth)+e.north)*Kp,c=Math.max(8,Math.abs(t.elevation))*Kp,u=new U(Math.sin(l)*Math.cos(c),Math.sin(c),-Math.cos(l)*Math.cos(c)),h=o.addScaledVector(u,a),f=a*(r?.07:.1);this.disc.position.copy(h),this.halo.position.copy(h),this.disc.scale.setScalar(f),this.halo.scale.setScalar(f*3.2);let d=this.disc.material,p=this.halo.material,x=r?0:Math.max(0,1-t.elevation/20);d.color.set(r?14016242:new W(1,.9-.25*x,.6-.35*x)),p.color.copy(d.color),d.opacity=(r?.7:.95)*(1-n),p.opacity=(r?.35:.6)*(1-n),this.disc.visible=this.halo.visible=!0}endBolt(){this.bolt.visible&&(this.bolt.visible=!1,this.onFlash?.(!1))}strike(e){let t=this.bounds,r=(Math.random()<.5?-1:1)<0?t.x0-2-Math.random()*6:t.x1+2+Math.random()*6,s=t.z0+Math.random()*(t.z1-t.z0),o=t.y1+4,a=this.bolt.geometry.getAttribute("position"),l=24,c=o;for(let u=0;u.01&&this.placeClouds(r),n.lightning&&!t.low?(this.nextBolt||(this.nextBolt=e+2500+Math.random()*6e3),e>=this.nextBolt&&(this.strike(e),this.nextBolt=e+3500+Math.random()*9e3),this.bolt.visible&&e>this.boltUntil&&this.endBolt()):this.nextBolt=0,this.rain.visible||this.snow.visible||this.hail.visible||n.cloud>.01||n.lightning}dispose(){this.endBolt(),this.group.traverse(e=>{let t=e;t.geometry?.dispose();let n=t.material;n?.map?.dispose(),n?.dispose()}),this.scene.remove(this.group),this.scene.fog instanceof ls&&(this.scene.fog=null)}};var Th=46,Ah=33,Ds=900;function Jp(){let i=document.createElement("canvas");i.width=i.height=32;let e=i.getContext("2d"),t=e.createRadialGradient(16,16,0,16,16,16);return t.addColorStop(0,"rgba(255,255,255,1)"),t.addColorStop(.35,"rgba(255,255,255,0.7)"),t.addColorStop(1,"rgba(255,255,255,0)"),e.fillStyle=t,e.fillRect(0,0,32,32),new zt(i)}var Eh=class{group=new ct;scene;lift;tex=Jp();arcs=new Map;sparkFields=[];sparks;sparkBase=new Float32Array(Ds*3);sparkField=new Int16Array(Ds);sparkPhase=new Float32Array(Ds);sparkCount=0;last=0;constructor(e,t){this.scene=e,this.lift=t,this.group.name="live-energy";let n=new Fe;n.setAttribute("position",new ke(new Float32Array(Ds*3),3)),n.setAttribute("color",new ke(new Float32Array(Ds*3),3)),this.sparks=new xn(n,new cn({size:.4,map:this.tex,vertexColors:!0,transparent:!0,depthWrite:!1,blending:Ft})),this.sparks.frustumCulled=!1,this.group.add(this.sparks),e.add(this.group)}get active(){return this.arcs.size>0||this.sparkCount>0}setArcs(e){let t=new Set(e.map(n=>n.key));for(let[n,r]of this.arcs)t.has(n)||(this.group.remove(r.line,r.points),r.line.geometry.dispose(),r.line.material.dispose(),r.points.geometry.dispose(),r.points.material.dispose(),this.arcs.delete(n));for(let n of e){let r=this.arcs.get(n.key);if(!r){let o=new Fe;o.setAttribute("position",new ke(new Float32Array(Ah*3),3));let a=new Pn(o,new Lt({transparent:!0,opacity:.4,depthWrite:!1,blending:Ft})),l=new Fe;l.setAttribute("position",new ke(new Float32Array(Th*3),3));let c=new xn(l,new cn({size:.55,map:this.tex,transparent:!0,depthWrite:!1,blending:Ft}));a.frustumCulled=c.frustumCulled=!1;let u=new Float32Array(Th);for(let h=0;hnew U):null,r.points.material.color.copy(s),r.count=n.power<=0?0:Math.max(3,Math.min(Th,Math.round(3+Math.sqrt(n.power)/2.2))),r.speed=.18+Math.min(.5,Math.log10(1+n.power)*.1),r.points.geometry.setDrawRange(0,r.count)}this.place()}setSparks(e){this.sparkFields=e;let t=e.reduce((r,s)=>r+s.quads.length*s.level,0),n=0;t>0&&e.forEach((r,s)=>{if(r.level<=0)return;let o=Math.round(Ds*r.quads.length*r.level/Math.max(t,e.reduce((a,l)=>a+l.quads.length,0)));for(let a=0;a0}world(e,t){let n=this.lift(e.floorId);return t.set(e.x,n.y+e.y,e.z),n.visible}place(){for(let e of this.arcs.values()){if(e.path){this.placeRoute(e,e.path);continue}let t=this.world(e.arc.from,e.a),n=this.world(e.arc.to,e.b),r=e.a.distanceTo(e.b);e.c.copy(e.a).add(e.b).multiplyScalar(.5),e.c.y=Math.max(e.a.y,e.b.y)+.6+r*.22;let s=t&&n;e.line.visible=e.points.visible=s;let o=e.line.geometry.getAttribute("position");for(let a=0;ar=this.world(o,t[a])&&r),e.line.visible=e.points.visible=r,e.along=[0];for(let o=1;os.setXYZ(a,o.x,o.y,o.z)),e.line.geometry.setDrawRange(0,t.length),s.needsUpdate=!0}at(e,t){if(!e.path)return this.bezier(e,t);let n=e.along[e.along.length-1]||1,r=t*n,s=1;for(;s0}set(e,t){let n=new Set(e.map(r=>r.id));for(let[r,s]of this.spots)if(!n.has(r)){for(let o of s.rings)this.group.remove(o),o.material.dispose();this.spots.delete(r)}for(let r of e){let s=this.spots.get(r.id);if(!s){let a=Array.from({length:oM},()=>{let l=new we(this.ringGeo,new Ke({transparent:!0,opacity:0,depthWrite:!1,blending:Ft,side:ut}));return l.rotation.x=-Math.PI/2,l.frustumCulled=!1,this.group.add(l),l});s={spot:r,rings:a},this.spots.set(r.id,s)}s.spot=r;let o=new W(r.color[0]/255,r.color[1]/255,r.color[2]/255);for(let a of s.rings)a.material.color.copy(o)}for(let r of this.links)this.group.remove(r.line),r.line.geometry.dispose(),r.line.material.dispose();this.links=t.map(([r,s])=>{let o=new Fe;o.setAttribute("position",new ke(new Float32Array(51),3));let a=new Pn(o,new Lt({color:12616956,transparent:!0,opacity:.55,depthWrite:!1,blending:Ft}));return a.frustumCulled=!1,this.group.add(a),{a:r,b:s,line:a}})}step(e){if(!this.spots.size&&!this.links.length)return!1;let t=e/1e3;for(let n of this.spots.values()){let r=this.lift(n.spot.at.floorId),s=.9+1.6*n.spot.level;n.rings.forEach((o,a)=>{let l=(t*.55+a/oM)%1;o.visible=r.visible,o.position.set(n.spot.at.x,r.y+n.spot.at.y,n.spot.at.z),o.scale.setScalar((.25+l*s)*(n.spot.size??1)),o.material.opacity=(1-l)*(.35+.5*n.spot.level)})}for(let n of this.links){let r=this.lift(n.a.floorId),s=this.lift(n.b.floorId);n.line.visible=r.visible&&s.visible;let o=n.line.geometry.getAttribute("position"),a=r.y+n.a.y,l=s.y+n.b.y,c=Math.hypot(n.a.x-n.b.x,n.a.z-n.b.z);for(let u=0;u<=16;u++){let h=u/16,f=Math.sin(Math.PI*h)*(.3+c*.12)+Math.sin(t*3+h*12)*.03;o.setXYZ(u,n.a.x+(n.b.x-n.a.x)*h,a+(l-a)*h+f,n.a.z+(n.b.z-n.a.z)*h)}o.needsUpdate=!0}return!0}dispose(){this.set([],[]),this.ringGeo.dispose(),this.scene.remove(this.group)}};var Ch=6,lM=24,aM=Ch*lM;function LC(i,e,t){let n=i%Ch,r=Math.floor(i/Ch),s=(r/lM+e*.7)%1,o=n/Ch*Math.PI*2+e*.35+(r*7%5-2)*.012,a=s*t,l=Math.min(1.2,t/3);return[Math.cos(o)*a,4*l*s*(1-s),Math.sin(o)*a]}var Ph=class{group=new ct;scene;lift;tex=Jp();material=new cn({color:11068159,size:.09,map:this.tex,transparent:!0,opacity:.9,depthWrite:!1});sprays=new Map;constructor(e,t){this.scene=e,this.lift=t,this.group.name="live-water",e.add(this.group)}get active(){return this.sprays.size>0}set(e){let t=new Set(e.map(n=>n.id));for(let[n,r]of this.sprays)t.has(n)||(this.group.remove(r.points),r.points.geometry.dispose(),this.sprays.delete(n));for(let n of e){let r=this.sprays.get(n.id);if(r){r.spot=n;continue}let s=new Fe;s.setAttribute("position",new ke(new Float32Array(aM*3),3));let o=new xn(s,this.material);o.frustumCulled=!1,this.group.add(o),this.sprays.set(n.id,{spot:n,points:o})}}step(e){if(!this.sprays.size)return!1;let t=e/1e3;for(let n of this.sprays.values()){let r=this.lift(n.spot.at.floorId);n.points.visible=r.visible,n.points.position.set(n.spot.at.x,r.y+n.spot.at.y,n.spot.at.z);let s=n.points.geometry.getAttribute("position");for(let o=0;oe.s.playing)}set(e){let t=new Set(e.map(n=>n.id));for(let[n,r]of this.views)t.has(n)||this.drop(n,r);for(let n of e){let r=this.views.get(n.id);if(!r){let o=document.createElement("canvas");o.width=512,o.height=288;let a=new zt(o);a.colorSpace=ft;let l=new we(new sn(1,1),new Ke({map:a,transparent:!0,toneMapped:!1}));l.renderOrder=6;let c=new we(new sn(1,1),new Ke({map:this.glowTex,transparent:!0,depthWrite:!1,blending:Ft,side:ut}));c.renderOrder=2,this.group.add(l,c),r={s:n,sig:"",screen:l,glow:c,canvas:o,texture:a,image:null},this.views.set(n.id,r)}r.s=n;let s=[n.title,n.subtitle,n.app,n.picture,n.color.join(","),n.playing].join("|");if(s!==r.sig){let o=r.sig.split("|")[3]!==(n.picture??"");r.sig=s,o&&this.loadPicture(r),this.draw(r)}this.place(r)}}loadPicture(e){e.image=null;let t=e.s.picture;if(!t)return;let n=new Image;n.crossOrigin="anonymous",n.onload=()=>{e.s.picture!==t||!this.views.has(e.s.id)||(e.image=n,this.draw(e),this.onChange?.())},n.src=t}draw(e){let t=e.s,n=e.canvas.getContext("2d"),r=e.canvas.width,s=e.canvas.height,[o,a,l]=t.color,c=n.createLinearGradient(0,0,r,s);c.addColorStop(0,`rgb(${Math.round(o*.35)},${Math.round(a*.35)},${Math.round(l*.35)})`),c.addColorStop(1,"rgb(6,9,18)"),n.fillStyle=c,n.fillRect(0,0,r,s);let u=22,h=u;if(e.image){let f=s-u*2-30;n.save(),n.shadowColor=`rgba(${o},${a},${l},0.7)`,n.shadowBlur=24;let d=e.image.naturalWidth||1,p=e.image.naturalHeight||1,x=Math.max(f/d,f/p),g=f/x,m=f/x;n.drawImage(e.image,(d-g)/2,(p-m)/2,g,m,u,u,f,f),n.restore(),h=u*2+f}n.fillStyle="#ffffff",n.font="600 34px Figtree, Roboto, sans-serif",this.text(n,t.title||t.app||"",h,s/2-18,r-h-u),n.fillStyle="rgba(230,240,255,0.75)",n.font="26px Figtree, Roboto, sans-serif",this.text(n,t.subtitle,h,s/2+22,r-h-u),t.app&&(n.fillStyle=`rgb(${o},${a},${l})`,n.font="700 22px Figtree, Roboto, sans-serif",this.text(n,(t.playing?"\u25B6 ":"\u275A\u275A ")+t.app,h,s-u-14,r-h-u)),n.fillStyle=`rgba(${o},${a},${l},0.9)`,n.fillRect(0,s-6,r*(t.playing?1:.4),6),e.texture.needsUpdate=!0}text(e,t,n,r,s){let o=t;for(;o.length>1&&e.measureText(o).width>s;)o=o.slice(0,-2);e.fillText(o===t?o:`${o}\u2026`,n,r)}place(e){let t=e.s,n=t.rect,r=t.rotation*FC,s=this.lift(t.floorId),o=(n.x0+n.x1)/2,a=(p,x)=>[t.x+p*Math.cos(r)-x*Math.sin(r),t.z+p*Math.sin(r)+x*Math.cos(r)],l=n.x1-n.x0,c=n.y1-n.y0,[u,h]=a(o,n.z+.012);e.screen.position.set(u,s.y+(n.y0+n.y1)/2,h),e.screen.rotation.set(0,-r,0),e.screen.scale.set(l,c,1);let[f,d]=a(o,n.z-.18);e.glow.position.set(f,s.y+(n.y0+n.y1)/2,d),e.glow.rotation.set(0,-r,0),e.glow.scale.set(l*2.4,c*2.6,1),e.glow.material.color=new W(t.color[0]/255,t.color[1]/255,t.color[2]/255),e.screen.visible=s.visible,e.glow.visible=s.visible&&(t.ambilight??1)>0}step(e){let t=!1;for(let n of this.views.values()){this.place(n);let r=n.glow.material;r.opacity=(n.s.playing?.55+.25*Math.sin(e/900+n.s.x):.25)*Math.min(1.5,n.s.ambilight??1),t||=n.s.playing}return t}drop(e,t){this.group.remove(t.screen,t.glow),t.screen.geometry.dispose(),t.screen.material.dispose(),t.texture.dispose(),t.glow.geometry.dispose(),t.glow.material.dispose(),this.views.delete(e)}dispose(){for(let[e,t]of this.views)this.drop(e,t);this.glowTex.dispose(),this.scene.remove(this.group)}};var NC=Math.PI/180,DC="#f4f1ea",Lh=class{group=new ct;scene;lift;views=new Map;onChange=null;constructor(e,t){this.scene=e,this.lift=t,this.group.name="live-pictures",e.add(this.group)}set(e){let t=new Set(e.map(n=>n.id));for(let[n,r]of this.views)t.has(n)||this.drop(n,r);for(let n of e){let r=this.views.get(n.id);if(!r){let c=document.createElement("canvas"),u=new zt(c);u.colorSpace=ft;let h=new we(new sn(1,1),new Ke({map:u,toneMapped:!1}));h.renderOrder=5,this.group.add(h),r={p:n,sig:"",mesh:h,canvas:c,texture:u,image:null},this.views.set(n.id,r)}let s=r.p.url!==n.url||!r.sig;r.p=n;let o=n.rect.x1-n.rect.x0,a=n.rect.y1-n.rect.y0,l=[n.url,n.border,n.fit,o.toFixed(3),a.toFixed(3)].join("|");l!==r.sig&&(r.sig=l,s&&this.load(r),this.draw(r)),this.place(r)}}load(e){e.image=null;let t=e.p.url,n=new Image;n.crossOrigin="anonymous",n.onload=()=>{e.p.url!==t||!this.views.has(e.p.id)||(e.image=n,this.draw(e),this.onChange?.())},n.src=t}draw(e){let t=e.p,n=Math.max(.01,t.rect.x1-t.rect.x0),r=Math.max(.01,t.rect.y1-t.rect.y0),s=600/Math.max(n,r),o=e.canvas.width=Math.max(16,Math.round(n*s)),a=e.canvas.height=Math.max(16,Math.round(r*s)),l=e.canvas.getContext("2d");l.fillStyle=t.border>0?DC:"#20242c",l.fillRect(0,0,o,a);let c=Math.round(Math.min(o,a)*Math.min(40,Math.max(0,t.border))/100),[u,h,f,d]=[c,c,o-2*c,a-2*c];if(e.image&&f>4&&d>4){let p=e.image.naturalWidth||1,x=e.image.naturalHeight||1;if(t.fit==="contain"){let g=Math.min(f/p,d/x);l.drawImage(e.image,u+(f-p*g)/2,h+(d-x*g)/2,p*g,x*g)}else{let g=Math.max(f/p,d/x),m=f/g,b=d/g;l.drawImage(e.image,(p-m)/2,(x-b)/2,m,b,u,h,f,d)}c>0&&(l.strokeStyle="rgba(0,0,0,0.25)",l.lineWidth=Math.max(1,c*.04),l.strokeRect(u,h,f,d))}else f>4&&d>4&&(l.fillStyle="#3a4250",l.fillRect(u,h,f,d));e.texture.needsUpdate=!0}place(e){let t=e.p,n=t.rect,r=t.rotation*NC,s=this.lift(t.floorId),o=(n.x0+n.x1)/2,a=n.z+.004;e.mesh.position.set(t.x+o*Math.cos(r)-a*Math.sin(r),s.y+(n.y0+n.y1)/2,t.z+o*Math.sin(r)+a*Math.cos(r)),e.mesh.rotation.set(0,-r,0),e.mesh.scale.set(n.x1-n.x0,n.y1-n.y0,1),e.mesh.visible=s.visible}step(){for(let e of this.views.values())this.place(e);return!1}drop(e,t){this.group.remove(t.mesh),t.mesh.geometry.dispose(),t.mesh.material.dispose(),t.texture.dispose(),this.views.delete(e)}dispose(){for(let[e,t]of this.views)this.drop(e,t);this.scene.remove(this.group)}};var Fh=class extends Tn{constructor(){super(),this.name="RoomEnvironment",this.position.y=-3.5;let e=new Fr;e.deleteAttribute("uv");let t=new In({side:un}),n=new In,r=new ps(16777215,900,28,2);r.position.set(.418,16.199,.3),this.add(r);let s=new we(e,t);s.position.set(-.757,13.219,.717),s.scale.set(31.713,28.305,28.591),this.add(s);let o=new hs(e,n,6),a=new Et;a.position.set(-10.906,2.009,1.846),a.rotation.set(0,-.195,0),a.scale.set(2.328,7.905,4.651),a.updateMatrix(),o.setMatrixAt(0,a.matrix),a.position.set(-5.607,-.754,-.758),a.rotation.set(0,.994,0),a.scale.set(1.97,1.534,3.955),a.updateMatrix(),o.setMatrixAt(1,a.matrix),a.position.set(6.167,.857,7.803),a.rotation.set(0,.561,0),a.scale.set(3.927,6.285,3.687),a.updateMatrix(),o.setMatrixAt(2,a.matrix),a.position.set(-2.017,.018,6.124),a.rotation.set(0,.333,0),a.scale.set(2.002,4.566,2.064),a.updateMatrix(),o.setMatrixAt(3,a.matrix),a.position.set(2.291,-.756,-2.621),a.rotation.set(0,-.286,0),a.scale.set(1.546,1.552,1.496),a.updateMatrix(),o.setMatrixAt(4,a.matrix),a.position.set(-2.193,-.369,-5.547),a.rotation.set(0,.516,0),a.scale.set(3.875,3.487,2.986),a.updateMatrix(),o.setMatrixAt(5,a.matrix),this.add(o);let l=new we(e,Ho(50));l.position.set(-16.116,14.37,8.208),l.scale.set(.1,2.428,2.739),this.add(l);let c=new we(e,Ho(50));c.position.set(-16.109,18.021,-8.207),c.scale.set(.1,2.425,2.751),this.add(c);let u=new we(e,Ho(17));u.position.set(14.904,12.198,-1.832),u.scale.set(.15,4.265,6.331),this.add(u);let h=new we(e,Ho(43));h.position.set(-.462,8.89,14.52),h.scale.set(4.38,5.441,.088),this.add(h);let f=new we(e,Ho(20));f.position.set(3.235,11.486,-12.541),f.scale.set(2.5,2,.1),this.add(f);let d=new we(e,Ho(100));d.position.set(0,20,0),d.scale.set(1,.1,1),this.add(d)}dispose(){let e=new Set;this.traverse(t=>{t.isMesh&&(e.add(t.geometry),e.add(t.material))});for(let t of e)t.dispose()}};function Ho(i){return new Pa({color:0,emissive:16777215,emissiveIntensity:i})}function jp(i,e){if(e===Kf)return console.warn("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles."),i;if(e===Mo||e===qa){let t=i.getIndex();if(t===null){let s=[],o=i.getAttribute("position");if(o!==void 0){for(let a=0;ao&&(O+=B,D+=X,P+=V)}let I=1/(Math.sqrt(O*O+D*D+P*P)||1);v[3*A+0]=O*I,v[3*A+1]=D*I,v[3*A+2]=P*I}}return t.setAttribute("normal",new wt(v,3,!1)),t}function uM(i){let e=new Map,t=new Map,n=i.clone();return hM(i,n,function(r,s){e.set(s,r),t.set(r,s)}),n.traverse(function(r){if(!r.isSkinnedMesh)return;let s=r,o=e.get(r),a=o.skeleton.bones;s.skeleton=o.skeleton.clone(),s.bindMatrix.copy(o.bindMatrix),s.skeleton.bones=a.map(function(l){return t.get(l)}),s.bind(s.skeleton,s.bindMatrix)}),n}function hM(i,e,t){t(i,e);for(let n=0;n=2.0 are supported."));return}let c=new Em(s,{path:t||this.resourcePath||"",crossOrigin:this.crossOrigin,priority:this.priority,cache:this.cache,withCredentials:this.withCredentials,requestHeader:this.requestHeader,manager:this.manager,ktx2Loader:this.ktx2Loader,meshoptDecoder:this.meshoptDecoder});c.fileLoader.setRequestHeader(this.requestHeader);for(let u=0;u=0&&a[h]===void 0&&console.warn('THREE.GLTFLoader: Unknown extension "'+h+'".')}}c.setExtensions(o),c.setPlugins(a),c.parse(n,r)}parseAsync(e,t){let n=this;return new Promise(function(r,s){n.parse(e,t,r,s)})}};function UC(){let i={};return{get:function(e){return i[e]},add:function(e,t){i[e]=t},remove:function(e){delete i[e]},removeAll:function(){i={}}}}function Bt(i,e,t){let n=i.json.materials[e];return n.extensions&&n.extensions[t]?n.extensions[t]:null}var nt={KHR_BINARY_GLTF:"KHR_binary_glTF",KHR_DRACO_MESH_COMPRESSION:"KHR_draco_mesh_compression",KHR_LIGHTS_PUNCTUAL:"KHR_lights_punctual",KHR_MATERIALS_CLEARCOAT:"KHR_materials_clearcoat",KHR_MATERIALS_DIFFUSE_ROUGHNESS:"KHR_materials_diffuse_roughness",KHR_MATERIALS_DISPERSION:"KHR_materials_dispersion",KHR_MATERIALS_IOR:"KHR_materials_ior",KHR_MATERIALS_SHEEN:"KHR_materials_sheen",KHR_MATERIALS_SPECULAR:"KHR_materials_specular",KHR_MATERIALS_TRANSMISSION:"KHR_materials_transmission",KHR_MATERIALS_IRIDESCENCE:"KHR_materials_iridescence",KHR_MATERIALS_ANISOTROPY:"KHR_materials_anisotropy",KHR_MATERIALS_UNLIT:"KHR_materials_unlit",KHR_MATERIALS_VOLUME:"KHR_materials_volume",KHR_TEXTURE_BASISU:"KHR_texture_basisu",KHR_TEXTURE_TRANSFORM:"KHR_texture_transform",KHR_MESH_QUANTIZATION:"KHR_mesh_quantization",KHR_MATERIALS_EMISSIVE_STRENGTH:"KHR_materials_emissive_strength",EXT_MATERIALS_BUMP:"EXT_materials_bump",EXT_TEXTURE_WEBP:"EXT_texture_webp",EXT_TEXTURE_AVIF:"EXT_texture_avif",EXT_MESHOPT_COMPRESSION:"EXT_meshopt_compression",KHR_MESHOPT_COMPRESSION:"KHR_meshopt_compression",EXT_MESH_GPU_INSTANCING:"EXT_mesh_gpu_instancing"},nm=class{constructor(e){this.parser=e,this.name=nt.KHR_LIGHTS_PUNCTUAL,this.cache={refs:{},uses:{}}}_markDefs(){let e=this.parser,t=this.parser.json.nodes||[];for(let n=0,r=t.length;n=0)throw new Error("THREE.GLTFLoader: setKTX2Loader must be called before loading KTX2 textures");return null}return t.loadTextureImage(e,s.source,o)}},xm=class{constructor(e){this.parser=e,this.name=nt.EXT_TEXTURE_WEBP}loadTexture(e){let t=this.name,n=this.parser,r=n.json,s=r.textures[e];if(!s.extensions||!s.extensions[t])return null;let o=s.extensions[t],a=r.images[o.source],l=n.textureLoader;if(a.uri){let c=n.options.manager.getHandler(a.uri);c!==null&&(l=c)}return n.loadTextureImage(e,o.source,l)}},bm=class{constructor(e){this.parser=e,this.name=nt.EXT_TEXTURE_AVIF}loadTexture(e){let t=this.name,n=this.parser,r=n.json,s=r.textures[e];if(!s.extensions||!s.extensions[t])return null;let o=s.extensions[t],a=r.images[o.source],l=n.textureLoader;if(a.uri){let c=n.options.manager.getHandler(a.uri);c!==null&&(l=c)}return n.loadTextureImage(e,o.source,l)}},Oh=class{constructor(e,t){this.name=t,this.parser=e}loadBufferView(e){let t=this.parser.json,n=t.bufferViews[e];if(n.extensions&&n.extensions[this.name]){let r=n.extensions[this.name],s=this.parser.getDependency("buffer",r.buffer),o=this.parser.options.meshoptDecoder;if(!o||!o.supported){if(t.extensionsRequired&&t.extensionsRequired.indexOf(this.name)>=0)throw new Error("THREE.GLTFLoader: setMeshoptDecoder must be called before loading compressed files");return null}return s.then(function(a){let l=r.byteOffset||0,c=r.byteLength||0,u=r.count,h=r.byteStride,f=new Uint8Array(a,l,c);return o.decodeGltfBufferAsync?o.decodeGltfBufferAsync(u,h,f,r.mode,r.filter).then(function(d){return d.buffer}):o.ready.then(function(){let d=new ArrayBuffer(u*h);return o.decodeGltfBuffer(new Uint8Array(d),u,h,f,r.mode,r.filter),d})})}else return null}},ym=class{constructor(e){this.name=nt.EXT_MESH_GPU_INSTANCING,this.parser=e}createNodeMesh(e){let t=this.parser.json,n=t.nodes[e];if(!n.extensions||!n.extensions[this.name]||n.mesh===void 0)return null;let r=t.meshes[n.mesh];for(let c of r.primitives)if(c.mode!==ei.TRIANGLES&&c.mode!==ei.TRIANGLE_STRIP&&c.mode!==ei.TRIANGLE_FAN&&c.mode!==void 0)return null;let o=n.extensions[this.name].attributes,a=[],l={};for(let c in o)a.push(this.parser.getDependency("accessor",o[c]).then(u=>(l[c]=u,l[c])));return a.length<1?null:(a.push(this.parser.createNodeMesh(e)),Promise.all(a).then(c=>{let u=c.pop(),h=u.isGroup?u.children:[u],f=c[0].count,d=[];for(let p of h){let x=new Be,g=new U,m=new Sn,b=new U(1,1,1),v=new hs(p.geometry,p.material,f);for(let M=0;M0||i.search(/^data\:image\/jpeg/)===0?"image/jpeg":i.search(/\.webp($|\?)/i)>0||i.search(/^data\:image\/webp/)===0?"image/webp":i.search(/\.ktx2($|\?)/i)>0||i.search(/^data\:image\/ktx2/)===0?"image/ktx2":"image/png"}var XC=new Be,Em=class{constructor(e={},t={}){this.json=e,this.extensions={},this.plugins={},this.options=t,this.cache=new UC,this.associations=new Map,this.primitiveCache={},this.nodeCache={},this.meshCache={refs:{},uses:{}},this.cameraCache={refs:{},uses:{}},this.lightCache={refs:{},uses:{}},this.sourceCache={},this.textureCache={},this.nodeNamesUsed={};let n=!1,r=-1,s=!1,o=-1;if(typeof navigator<"u"&&typeof navigator.userAgent<"u"){let a=navigator.userAgent;n=/^((?!chrome|android).)*safari/i.test(a)===!0;let l=a.match(/Version\/(\d+)/);r=n&&l?parseInt(l[1],10):-1,s=a.indexOf("Firefox")>-1,o=s?a.match(/Firefox\/([0-9]+)\./)[1]:-1}typeof createImageBitmap>"u"||n&&r<17||s&&o<98?(this.textureLoader=new Fa(this.options.manager),this.textureLoader.setPriority(this.options.priority),this.textureLoader.setCache(this.options.cache)):(this.textureLoader=new Ua(this.options.manager),this.textureLoader.setPriority(this.options.priority),this.textureLoader.setCache(this.options.cache)),this.textureLoader.setCrossOrigin(this.options.crossOrigin),this.textureLoader.setWithCredentials(this.options.withCredentials),this.textureLoader.setRequestHeader(this.options.requestHeader),this.fileLoader=new mo(this.options.manager),this.fileLoader.setPriority(this.options.priority),this.fileLoader.setCache(this.options.cache),this.fileLoader.setResponseType("arraybuffer"),(this.options.withCredentials||this.options.crossOrigin==="use-credentials")&&this.fileLoader.setWithCredentials(!0)}setExtensions(e){this.extensions=e}setPlugins(e){this.plugins=e}parse(e,t){let n=this,r=this.json,s=this.extensions;this.cache.removeAll(),this.nodeCache={},this._invokeAll(function(o){return o._markDefs&&o._markDefs()}),Promise.all(this._invokeAll(function(o){return o.beforeRoot&&o.beforeRoot()})).then(function(){return Promise.all([n.getDependencies("scene"),n.getDependencies("animation"),n.getDependencies("camera")])}).then(function(o){let a={scene:o[0][r.scene||0],scenes:o[0],animations:o[1],cameras:o[2],asset:r.asset,parser:n,userData:{}};return Us(s,a,r),Ui(a,r),Promise.all(n._invokeAll(function(l){return l.afterRoot&&l.afterRoot(a)})).then(function(){for(let l of a.scenes)l.updateMatrixWorld();e(a)})}).catch(t)}_markDefs(){let e=this.json.nodes||[],t=this.json.skins||[],n=this.json.meshes||[];for(let r=0,s=t.length;r{let l=this.associations.get(o);l!=null&&this.associations.set(a,l);for(let[c,u]of o.children.entries())s(u,a.children[c])};return s(n,r),r.name+="_instance_"+e.uses[t]++,r}_invokeOne(e){let t=Object.values(this.plugins);t.push(this);for(let n=0;n=2&&g.setY(R,S[_*l+1]),l>=3&&g.setZ(R,S[_*l+2]),l>=4&&g.setW(R,S[_*l+3]),l>=5)throw new Error("THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.")}g.normalized=p}return g})}loadTexture(e){let t=this.json,n=this.options,s=t.textures[e].source,o=t.images[s],a=this.textureLoader;if(o.uri){let l=n.manager.getHandler(o.uri);l!==null&&(a=l)}return this.loadTextureImage(e,s,a)}loadTextureImage(e,t,n){let r=this,s=this.json,o=s.textures[e],a=s.images[t],l=(a.uri||a.bufferView)+":"+o.sampler;if(this.textureCache[l])return this.textureCache[l];let c=this.loadImageSource(t,n).then(function(u){u.flipY=!1,u.name=o.name||a.name||"",u.name===""&&typeof a.uri=="string"&&a.uri.startsWith("data:image/")===!1&&(u.name=a.uri);let f=(s.samplers||{})[o.sampler]||{};return u.magFilter=dM[f.magFilter]||Ht,u.minFilter=dM[f.minFilter]||Fn,u.wrapS=pM[f.wrapS]||kn,u.wrapT=pM[f.wrapT]||kn,u.generateMipmaps=!u.isCompressedTexture&&u.minFilter!==Ut&&u.minFilter!==Ht,r.associations.set(u,{textures:e}),u}).catch(function(){return null});return this.textureCache[l]=c,c}loadImageSource(e,t){let n=this,r=this.json,s=this.options;if(this.sourceCache[e]!==void 0)return this.sourceCache[e].then(f=>f.clone());let o=r.images[e],a=self.URL||self.webkitURL,l=o.uri||"",c=!1,u;if(t.isKTX2Loader===!0&&o.bufferView!==void 0)u=n.getDependency("bufferView",o.bufferView).then(function(f){return new Promise(function(d,p){t.parse(f,d,p)})});else{if(o.bufferView!==void 0)l=n.getDependency("bufferView",o.bufferView).then(function(f){c=!0;let d=new Blob([f],{type:o.mimeType});return l=a.createObjectURL(d),l});else if(o.uri===void 0)throw new Error("THREE.GLTFLoader: Image "+e+" is missing URI and bufferView");u=Promise.resolve(l).then(function(f){return new Promise(function(d,p){let x=d;t.isImageBitmapLoader===!0&&(x=function(g){let m=new Kt(g);m.needsUpdate=!0,d(m)}),t.load(or.resolveURL(f,s.path),x,void 0,p)})})}let h=u.then(function(f){return c===!0&&a.revokeObjectURL(l),Ui(f,o),f.userData.mimeType=o.mimeType||WC(o.uri),f}).catch(function(f){throw console.error("THREE.GLTFLoader: Couldn't load texture",l),f});return this.sourceCache[e]=h,h}assignTexture(e,t,n,r){let s=this;return this.getDependency("texture",n.index).then(function(o){if(!o)return null;if(n.texCoord!==void 0&&n.texCoord>0&&(o=o.clone(),o.channel=n.texCoord),s.extensions[nt.KHR_TEXTURE_TRANSFORM]){let a=n.extensions!==void 0?n.extensions[nt.KHR_TEXTURE_TRANSFORM]:void 0;if(a){let l=s.associations.get(o);o=s.extensions[nt.KHR_TEXTURE_TRANSFORM].extendTexture(o,a),s.associations.set(o,l)}}return r!==void 0&&(o.colorSpace=r),e[t]=o,o})}assignFinalMaterial(e){let t=e.geometry,n=e.material,r=t.attributes.tangent===void 0,s=t.attributes.color!==void 0,o=t.attributes.normal===void 0;if(e.isPoints){let a="PointsMaterial:"+n.uuid,l=this.cache.get(a);l||(l=new cn,mn.prototype.copy.call(l,n),l.color.copy(n.color),l.map=n.map,l.sizeAttenuation=!1,this.cache.add(a,l)),n=l}else if(e.isLine){let a="LineBasicMaterial:"+n.uuid,l=this.cache.get(a);l||(l=new Lt,mn.prototype.copy.call(l,n),l.color.copy(n.color),l.map=n.map,this.cache.add(a,l)),n=l}if(r||s||o){let a="ClonedMaterial:"+n.uuid+":";r&&(a+="derivative-tangents:"),s&&(a+="vertex-colors:"),o&&(a+="flat-shading:");let l=this.cache.get(a);l||(l=n.clone(),s&&(l.vertexColors=!0),o&&(l.flatShading=!0),r&&(l.normalScale&&(l.normalScale.y*=-1),l.clearcoatNormalScale&&(l.clearcoatNormalScale.y*=-1)),this.cache.add(a,l),this.associations.set(l,this.associations.get(n))),n=l}e.material=n}getMaterialType(){return In}loadMaterial(e){let t=this,n=this.json,r=this.extensions,s=n.materials[e],o,a={},l=s.extensions||{},c=[];if(l[nt.KHR_MATERIALS_UNLIT]){let h=r[nt.KHR_MATERIALS_UNLIT];o=h.getMaterialType(),c.push(h.extendParams(a,s,t))}else{let h=s.pbrMetallicRoughness||{};if(a.color=new W(1,1,1),a.opacity=1,Array.isArray(h.baseColorFactor)){let f=h.baseColorFactor;a.color.setRGB(f[0],f[1],f[2],Mn),a.opacity=f[3]}h.baseColorTexture!==void 0&&c.push(t.assignTexture(a,"map",h.baseColorTexture,ft)),a.metalness=h.metallicFactor!==void 0?h.metallicFactor:1,a.roughness=h.roughnessFactor!==void 0?h.roughnessFactor:1,h.metallicRoughnessTexture!==void 0&&(c.push(t.assignTexture(a,"metalnessMap",h.metallicRoughnessTexture)),c.push(t.assignTexture(a,"roughnessMap",h.metallicRoughnessTexture))),o=this._invokeOne(function(f){return f.getMaterialType&&f.getMaterialType(e)}),c.push(Promise.all(this._invokeAll(function(f){return f.extendMaterialParams&&f.extendMaterialParams(e,a)})))}s.doubleSided===!0&&(a.side=ut);let u=s.alphaMode||em.OPAQUE;if(u===em.BLEND?(a.transparent=!0,a.depthWrite=!1):(a.transparent=!1,u===em.MASK&&(a.alphaTest=s.alphaCutoff!==void 0?s.alphaCutoff:.5)),s.normalTexture!==void 0&&o!==Ke&&(c.push(t.assignTexture(a,"normalMap",s.normalTexture)),a.normalScale=new De(1,1),s.normalTexture.scale!==void 0)){let h=s.normalTexture.scale;a.normalScale.set(h,h)}if(s.occlusionTexture!==void 0&&o!==Ke&&(c.push(t.assignTexture(a,"aoMap",s.occlusionTexture)),s.occlusionTexture.strength!==void 0&&(a.aoMapIntensity=s.occlusionTexture.strength)),s.emissiveFactor!==void 0&&o!==Ke){let h=s.emissiveFactor;a.emissive=new W().setRGB(h[0],h[1],h[2],Mn)}return s.emissiveTexture!==void 0&&o!==Ke&&c.push(t.assignTexture(a,"emissiveMap",s.emissiveTexture,ft)),Promise.all(c).then(function(){let h=new o(a);return s.name&&(h.name=s.name),Ui(h,s),t.associations.set(h,{materials:e}),s.extensions&&Us(r,h,s),h})}createUniqueName(e){let t=gt.sanitizeNodeName(e||"");return t in this.nodeNamesUsed?t+"_"+ ++this.nodeNamesUsed[t]:(this.nodeNamesUsed[t]=0,t)}loadGeometries(e){let t=this,n=this.extensions,r=this.primitiveCache;function s(a){return n[nt.KHR_DRACO_MESH_COMPRESSION].decodePrimitive(a,t).then(function(l){return mM(l,a,t)})}let o=[];for(let a=0,l=e.length;ajp(d,qa)):c.mode===ei.TRIANGLE_FAN&&(f=f.then(d=>jp(d,Mo))),r[u]={primitive:c,promise:f},o.push(f)}}return Promise.all(o)}loadMesh(e){let t=this,n=this.json,r=this.extensions,s=n.meshes[e],o=s.primitives,a=[];for(let l=0,c=o.length;l0&&GC(m,s),m.name=t.createUniqueName(s.name||"mesh_"+e),Ui(m,s),g.extensions&&Us(r,m,g),t.assignFinalMaterial(m),h.push(m)}for(let d=0,p=h.length;d0){let d=u.userData.pivot,p=h[0];u.pivot=new U().fromArray(d),u.position.x-=d[0],u.position.y-=d[1],u.position.z-=d[2],p.position.set(0,0,0),delete u.userData.pivot}return u})}_loadNodeShallow(e){let t=this.json,n=this.extensions,r=this;if(this.nodeCache[e]!==void 0)return this.nodeCache[e];let s=t.nodes[e],o=s.name?r.createUniqueName(s.name):"",a=[],l=r._invokeOne(function(c){return c.createNodeMesh&&c.createNodeMesh(e)});return l&&a.push(l),s.camera!==void 0&&a.push(r.getDependency("camera",s.camera).then(function(c){return r._getNodeRef(r.cameraCache,s.camera,c)})),r._invokeAll(function(c){return c.createNodeAttachment&&c.createNodeAttachment(e)}).forEach(function(c){a.push(c)}),this.nodeCache[e]=Promise.all(a).then(function(c){let u;if(s.isBone===!0?u=new ho:c.length>1?u=new ct:c.length===1?u=c[0]:u=new Et,u!==c[0])for(let h=0,f=c.length;h1){let h=r.associations.get(u);r.associations.set(u,{...h})}return r.associations.get(u).nodes=e,u}),this.nodeCache[e]}loadScene(e){let t=this.extensions,n=this.json.scenes[e],r=this,s=new ct;n.name&&(s.name=r.createUniqueName(n.name)),Ui(s,n),n.extensions&&Us(t,s,n);let o=n.nodes||[],a=[];for(let l=0,c=o.length;l{let h=new Map;for(let[f,d]of r.associations)(f instanceof mn||f instanceof Kt)&&h.set(f,d);return u.traverse(f=>{let d=r.associations.get(f);d!=null&&h.set(f,d)}),h};return r.associations=c(s),s})}_createAnimationTracks(e,t,n,r,s){let o=[],a=e.name?e.name:e.uuid,l=[];function c(d){d.morphTargetInfluences&&l.push(d.name?d.name:d.uuid)}Yr[s.path]===Yr.weights?(c(e),e.isGroup&&e.children.forEach(c)):l.push(a);let u;switch(Yr[s.path]){case Yr.weights:u=nr;break;case Yr.rotation:u=ir;break;case Yr.translation:case Yr.scale:u=Or;break;default:n.itemSize===1?u=nr:u=Or;break}let h=r.interpolation!==void 0?kC[r.interpolation]:Zi,f=this._getArrayFromAccessor(n);for(let d=0,p=l.length;d{let t=e;if(!t.isMesh)return;let n=t.geometry,r=t.material,s=r.name??"";t.userData.paint=!!r.userData?.paint||/^Paint/.test(s),n.getAttribute("normal")||(t.userData.paint?n.computeVertexNormals():t.geometry=cM(n,qC)),r.flatShading=!1;let o=/glass/i.test(s);r.metalness=t.userData.paint?.55:o?0:Math.min(r.metalness??0,.4),r.roughness=t.userData.paint?.28:o?.05:Math.max(r.roughness??.6,.45),o&&(r.transparent=!0,r.depthWrite=!1,r.opacity=Math.max(r.opacity,.9))})}function yM(i){let e=xM.get(i);if(!e){let t=D0();if(!t)return Promise.resolve(!1);e=t(i).then(n=>n&&new Promise(r=>{new Xo().parse(n,"",s=>{$C(s.scene);let o=new Ct().setFromObject(s.scene),a=[o.max.x-o.min.x,o.max.y-o.min.y,o.max.z-o.min.z];s.scene.position.set(-(o.max.x+o.min.x)/2,-o.min.y,-(o.max.z+o.min.z)/2);let l=new ct;l.add(s.scene),bM.set(i,{root:l,size:a}),U0(i),r({root:l,size:a})},()=>r(null))})).catch(()=>null),xM.set(i,e)}return e.then(t=>!!t)}function _M(i,e){let t=bM.get(i);if(!t)return null;let n=t.root.clone(!0),r=[];n.traverse(o=>{let a=o;if(!a.isMesh)return;let l=a.material.clone();a.userData.paint&&e.paint&&(l.color=new W(e.paint)),a.material=l,r.push(l)});let s=new ct;return s.add(n),s.scale.set((e.mirror?-1:1)*(e.w/t.size[0]),e.h/t.size[1],e.d/t.size[2]),s.position.set(e.x,e.y,e.z),s.rotation.y=-e.rotation*Math.PI/180,s.userData.own=r,s}function Rm(i){for(let e of i.userData.own??[])e.dispose()}function vM(i,e){let t=new wo(e),n=t.fromScene(new Fh,.04).texture;t.dispose();let r=new ds(16777215,9081766,.9),s=new sr(16777215,1.6);return s.position.set(-4,9,6),i.add(r,s),{env:n,dispose:()=>{n.dispose(),r.removeFromParent(),s.removeFromParent()}}}function MM(i,e){for(let t of i.userData.own??[])t.envMap=e,t.envMapIntensity=.9}var KC=.3,SM=2.6,Dh=.05;function ZC(i,e,t,n){let r=n*.7071,s=[i,[i[0]+n,i[1]],[i[0]-n,i[1]],[i[0],i[1]+n],[i[0],i[1]-n]],o=[[i[0]+r,i[1]+r],[i[0]-r,i[1]+r],[i[0]+r,i[1]-r],[i[0]-r,i[1]-r]];return s.every(a=>Ve(a,e))&&!t.some(a=>[...s,...o].some(l=>Ve(l,a)))}function wM(i,e,t){let n=Math.ceil(Math.hypot(e[0]-i[0],e[1]-i[1])/Dh);for(let r=1;rt+1e-6)&&r!==null){let a=o?s:s-Dh;(!n||a-r>n[1]-n[0])&&(n=[r,a]),r=null}}return n}function TM(i,e=.32,t=.22,n=[]){let r=i.map(v=>v[0]),s=i.map(v=>v[1]),[o,a,l,c]=[Math.min(...r),Math.max(...r),Math.min(...s),Math.max(...s)],u=c-l>=a-o,h=v=>ZC(v,i,n,t),f=(v,y)=>u?[v,y]:[y,v],[d,p,x,g]=u?[o,a,l,c]:[l,c,o,a],m=[],b=!0;for(let v=d+t;v<=p-t+1e-6;v+=e){let y=JC(w=>h(f(v,w)),x,g);if(!y||y[1]-y[0]<.2)continue;let M=w=>w?[f(v,y[0]),f(v,y[1])]:[f(v,y[1]),f(v,y[0])],S=M(b),_=m[m.length-1];if(_&&n.length>0&&!wM(_,S[0],h)){let w=M(!b);if(!wM(_,w[0],h))continue;S=w,b=!b}m.push(...S),b=!b}return m}function Pm(i,e=.7,t=12){return Array.from({length:t},(n,r)=>[i[0]+Math.cos(r/t*Math.PI*2)*e,i[1]+Math.sin(r/t*Math.PI*2)*e])}var Cm=i=>Math.atan2(Math.sin(i),Math.cos(i));function AM(i,e,t){let n;if(e.mode==="cleaning"){if(i.path.length===0)return!1;n=i.path[i.next%i.path.length]}else if(e.mode==="returning"||e.mode==="docked")n=e.rest;else return!1;let[r,s]=[n[0]-i.pos[0],n[1]-i.pos[1]],o=Math.hypot(r,s);if(o<.02){if(e.mode==="cleaning")return i.next=(i.next+1)%i.path.length,!0;let l=Cm(e.restHeading-i.heading);return Math.abs(l)<.02?!1:(i.heading+=Math.sign(l)*Math.min(Math.abs(l),SM*t),!0)}let a=Cm(Math.atan2(r,s)-i.heading);if(i.heading=Cm(i.heading+Math.sign(a)*Math.min(Math.abs(a),SM*t)),Math.abs(a)<.35){let l=Math.min(o,KC*t);i.pos=[i.pos[0]+r/o*l,i.pos[1]+s/o*l]}return!0}var Uh=600*1e3,jC=3e3;function EM(i,e){if(i==null)return 1;let t=e-i;return t>Uh?Math.max(0,1-(t-Uh)/jC):1}function Im(i,e,t){let n=e/2,r=[],s=(a,l,c)=>r.push(a[0],t,a[1],l[0],t,l[1],c[0],t,c[1]);for(let a of i){for(let c=0;c+14?o=i.array[r*i.itemSize+s]:(s===0?o=i.getX(r):s===1?o=i.getY(r):s===2?o=i.getZ(r):s===3&&(o=i.getW(r)),i.normalized===!0&&(o=Br.normalize(o,i.array))),n.min[s]=Math.min(n.min[s],o),n.max[s]=Math.max(n.max[s],o)}return n}function FM(i){return Math.ceil(i/4)*4}function Fm(i,e=0){let t=FM(i.byteLength);if(t!==i.byteLength){let n=new Uint8Array(t);if(n.set(new Uint8Array(i)),e!==0)for(let r=i.byteLength;r"u"&&typeof OffscreenCanvas<"u"?new OffscreenCanvas(1,1):document.createElement("canvas")}function aP(i,e){if(typeof OffscreenCanvas<"u"&&i instanceof OffscreenCanvas){let t;return e==="image/jpeg"?t=.92:e==="image/webp"&&(t=.8),i.convertToBlob({type:e,quality:t})}else return new Promise(t=>i.toBlob(t,e))}var Nm=class{constructor(){this.plugins=[],this.options={},this.pending=[],this.buffers=[],this.byteOffset=0,this.buffers=[],this.nodeMap=new Map,this.skins=[],this.extensionsUsed={},this.extensionsRequired={},this.uids=new Map,this.uid=0,this.json={asset:{version:"2.0",generator:"THREE.GLTFExporter r187"}},this.cache={meshes:new Map,attributes:new Map,attributesNormalized:new Map,materials:new Map,textures:new Map,images:new Map,normalMaps:new Map},this.textureUtils=null}setPlugins(e){this.plugins=e}setTextureUtils(e){this.textureUtils=e}async writeAsync(e,t,n={}){this.options=Object.assign({binary:!1,trs:!1,onlyVisible:!0,maxTextureSize:1/0,animations:[],includeCustomExtensions:!1,copyright:null},n),this.options.animations.length>0&&(this.options.trs=!0),await this.processInputAsync(e),await Promise.all(this.pending);let r=this,s=r.buffers,o=r.json;n=r.options;let a=r.extensionsUsed,l=r.extensionsRequired,c=new Blob(s,{type:"application/octet-stream"}),u=Object.keys(a),h=Object.keys(l);if(u.length>0&&(o.extensionsUsed=u),h.length>0&&(o.extensionsRequired=h),o.buffers&&o.buffers.length>0&&(o.buffers[0].byteLength=c.size),n.copyright&&(o.asset.copyright=n.copyright),n.binary===!0){let f=new FileReader;f.readAsArrayBuffer(c),f.onloadend=function(){let d=Fm(f.result),p=new DataView(new ArrayBuffer(LM));p.setUint32(0,d.byteLength,!0),p.setUint32(4,iP,!0);let x=Fm(rP(JSON.stringify(o)),32),g=new DataView(new ArrayBuffer(LM));g.setUint32(0,x.byteLength,!0),g.setUint32(4,nP,!0);let m=new ArrayBuffer(IM),b=new DataView(m);b.setUint32(0,eP,!0),b.setUint32(4,tP,!0);let v=IM+g.byteLength+x.byteLength+p.byteLength+d.byteLength;b.setUint32(8,v,!0);let y=new Blob([m,g,x,p,d],{type:"application/octet-stream"}),M=new FileReader;M.readAsArrayBuffer(y),M.onloadend=function(){t(M.result)}}}else if(o.buffers&&o.buffers.length>0){let f=new FileReader;f.readAsDataURL(c),f.onloadend=function(){let d=f.result;o.buffers[0].uri=d,t(o)}}else t(o)}serializeUserData(e,t){if(Object.keys(e.userData).length===0)return;let n=this.options,r=this.extensionsUsed;try{let s=JSON.parse(JSON.stringify(e.userData));if(n.includeCustomExtensions&&s.gltfExtensions){t.extensions===void 0&&(t.extensions={});for(let o in s.gltfExtensions)t.extensions[o]=s.gltfExtensions[o],r[o]=!0;delete s.gltfExtensions}Object.keys(s).length>0&&(t.extras=s)}catch(s){console.warn("THREE.GLTFExporter: userData of '"+e.name+"' won't be serialized because of JSON.stringify error - "+s.message)}}getUID(e,t=!1){if(this.uids.has(e)===!1){let r=new Map;r.set(!0,this.uid++),r.set(!1,this.uid++),this.uids.set(e,r)}return this.uids.get(e).get(t)}isNormalizedNormalAttribute(e){if(this.cache.attributesNormalized.has(e))return!1;let n=new U;for(let r=0,s=e.count;r5e-4)return!1;return!0}createNormalizedNormalAttribute(e){let t=this.cache;if(t.attributesNormalized.has(e))return t.attributesNormalized.get(e);let n=e.clone(),r=new U;for(let s=0,o=n.count;s4?g=e.array[p*e.itemSize+x]:(x===0?g=e.getX(p):x===1?g=e.getY(p):x===2?g=e.getZ(p):x===3&&(g=e.getW(p)),e.normalized===!0&&(g=Br.normalize(g,e.array))),t===rt.FLOAT?u.setFloat32(h,g,!0):t===rt.INT?u.setInt32(h,g,!0):t===rt.UNSIGNED_INT?u.setUint32(h,g,!0):t===rt.SHORT?u.setInt16(h,g,!0):t===rt.UNSIGNED_SHORT?u.setUint16(h,g,!0):t===rt.BYTE?u.setInt8(h,g):t===rt.UNSIGNED_BYTE&&u.setUint8(h,g),h+=a}h%l!==0&&(h+=l-h%l)}let f={buffer:this.processBuffer(u.buffer),byteOffset:this.byteOffset,byteLength:c};return s!==void 0&&(f.target=s),s===rt.ARRAY_BUFFER&&(f.byteStride=l),this.byteOffset+=c,o.bufferViews.push(f),{id:o.bufferViews.length-1,byteLength:0}}processBufferViewImage(e){let t=this,n=t.json;return n.bufferViews||(n.bufferViews=[]),new Promise(function(r){let s=new FileReader;s.readAsArrayBuffer(e),s.onloadend=function(){let o=Fm(s.result),a={buffer:t.processBuffer(o),byteOffset:t.byteOffset,byteLength:o.byteLength};t.byteOffset+=o.byteLength,r(n.bufferViews.push(a)-1)}})}processAccessor(e,t,n,r){let s=this.json,o={1:"SCALAR",2:"VEC2",3:"VEC3",4:"VEC4",9:"MAT3",16:"MAT4"},a;if(e.array.constructor===Float32Array)a=rt.FLOAT;else if(e.array.constructor===Int32Array)a=rt.INT;else if(e.array.constructor===Uint32Array)a=rt.UNSIGNED_INT;else if(e.array.constructor===Int16Array)a=rt.SHORT;else if(e.array.constructor===Uint16Array)a=rt.UNSIGNED_SHORT;else if(e.array.constructor===Int8Array)a=rt.BYTE;else if(e.array.constructor===Uint8Array)a=rt.UNSIGNED_BYTE;else throw new Error("THREE.GLTFExporter: Unsupported bufferAttribute component type: "+e.array.constructor.name);if(n===void 0&&(n=0),(r===void 0||r===1/0)&&(r=e.count),r===0)return null;let l=oP(e,n,r),c;t!==void 0&&(c=e===t.index?rt.ELEMENT_ARRAY_BUFFER:rt.ARRAY_BUFFER);let u=this.processBufferView(e,a,n,r,c),h={bufferView:u.id,byteOffset:u.byteOffset,componentType:a,count:r,max:l.max,min:l.min,type:o[e.itemSize]};return e.normalized===!0&&(h.normalized=!0),s.accessors||(s.accessors=[]),s.accessors.push(h)-1}processImage(e,t,n,r="image/png"){if(e!==null){let s=this,o=s.cache,a=s.json,l=s.options,c=s.pending;o.images.has(e)||o.images.set(e,{});let u=o.images.get(e),h=r+":flipY/"+n.toString();if(u[h]!==void 0)return u[h];a.images||(a.images=[]);let f={mimeType:r},d=Om();d.width=Math.min(e.width,l.maxTextureSize),d.height=Math.min(e.height,l.maxTextureSize);let p=d.getContext("2d",{willReadFrequently:!0});if(n===!0&&(p.translate(0,d.height),p.scale(1,-1)),e.data!==void 0){t!==Nn&&console.error("GLTFExporter: Only RGBAFormat is supported.",t),(e.width>l.maxTextureSize||e.height>l.maxTextureSize)&&console.warn("GLTFExporter: Image size is bigger than maxTextureSize",e);let g=new Uint8ClampedArray(e.height*e.width*4);for(let m=0;ms.processBufferViewImage(g)).then(g=>{f.bufferView=g})):f.uri=lo.getDataURL(d,r);let x=a.images.push(f)-1;return u[h]=x,x}else throw new Error("THREE.GLTFExporter: No valid image data found. Unable to process texture.")}processSampler(e){let t=this.json;t.samplers||(t.samplers=[]);let n={magFilter:Gn[e.magFilter],minFilter:Gn[e.minFilter],wrapS:Gn[e.wrapS],wrapT:Gn[e.wrapT]};return t.samplers.push(n)-1}async processTextureAsync(e){let n=this.options,r=this.cache,s=this.json;if(r.textures.has(e))return r.textures.get(e);s.textures||(s.textures=[]),e instanceof Lr&&(e=await this.decompressTextureAsync(e,n.maxTextureSize));let o=e.userData.mimeType,a=this.processImage(e.image,e.format,e.flipY,o),l={sampler:this.processSampler(e)};o==="image/webp"?(l.extensions=l.extensions||{},l.extensions.EXT_texture_webp={source:a},this.extensionsUsed.EXT_texture_webp=!0,this.extensionsRequired.EXT_texture_webp=!0):l.source=a,e.name&&(l.name=e.name),await this._invokeAllAsync(async function(u){u.writeTexture&&await u.writeTexture(e,l)});let c=s.textures.push(l)-1;return r.textures.set(e,c),c}async processMaterialAsync(e,t){let n=this.cache,r=this.json,s=t!==void 0&&t.hasAttribute("tangent"),o=e.normalMap?e.uuid+":"+s:e.uuid;if(n.materials.has(o))return n.materials.get(o);if(e.isShaderMaterial)return console.warn("GLTFExporter: THREE.ShaderMaterial not supported."),null;r.materials||(r.materials=[]);let a={pbrMetallicRoughness:{}};e.isMeshStandardMaterial!==!0&&e.isMeshBasicMaterial!==!0&&console.warn("GLTFExporter: Use MeshStandardMaterial or MeshBasicMaterial for best results.");let l=e.color.toArray().concat([e.opacity]);if(xr(l,[1,1,1,1])||(a.pbrMetallicRoughness.baseColorFactor=l),e.isMeshStandardMaterial?(a.pbrMetallicRoughness.metallicFactor=e.metalness,a.pbrMetallicRoughness.roughnessFactor=e.roughness):(a.pbrMetallicRoughness.metallicFactor=0,a.pbrMetallicRoughness.roughnessFactor=1),e.metalnessMap||e.roughnessMap){let u=await this.buildMetalRoughTextureAsync(e.metalnessMap,e.roughnessMap),h={index:await this.processTextureAsync(u),texCoord:u.channel};this.applyTextureTransform(h,u),a.pbrMetallicRoughness.metallicRoughnessTexture=h}if(e.map){let u={index:await this.processTextureAsync(e.map),texCoord:e.map.channel};this.applyTextureTransform(u,e.map),a.pbrMetallicRoughness.baseColorTexture=u}if(e.emissive){let u=e.emissive;if(Math.max(u.r,u.g,u.b)>0&&(a.emissiveFactor=e.emissive.toArray()),e.emissiveMap){let f={index:await this.processTextureAsync(e.emissiveMap),texCoord:e.emissiveMap.channel};this.applyTextureTransform(f,e.emissiveMap),a.emissiveTexture=f}}if(e.normalMap){let u=e.normalScale,h=u.x<0,f=s?u.y<0:u.y>0,d=e.normalMap;if(h||f){n.normalMaps.has(e.normalMap)===!1&&n.normalMaps.set(e.normalMap,{});let x=n.normalMaps.get(e.normalMap),g=`${h}:${f}`;x[g]===void 0&&(x[g]=await this.buildNormalMapTextureAsync(e.normalMap,h,f)),d=x[g]}let p={index:await this.processTextureAsync(d),texCoord:e.normalMap.channel};Math.abs(u.x)!==1&&(p.scale=Math.abs(u.x)),this.applyTextureTransform(p,e.normalMap),a.normalTexture=p}if(e.aoMap){let u={index:await this.processTextureAsync(e.aoMap),texCoord:e.aoMap.channel};e.aoMapIntensity!==1&&(u.strength=e.aoMapIntensity),this.applyTextureTransform(u,e.aoMap),a.occlusionTexture=u}e.transparent?a.alphaMode="BLEND":e.alphaTest>0&&(a.alphaMode="MASK",a.alphaCutoff=e.alphaTest),e.side===ut&&(a.doubleSided=!0),e.name!==""&&(a.name=e.name),this.serializeUserData(e,a),await this._invokeAllAsync(async function(u){u.writeMaterialAsync&&await u.writeMaterialAsync(e,a)});let c=r.materials.push(a)-1;return n.materials.set(o,c),c}async processMeshAsync(e){let t=this.cache,n=this.json,r=[e.geometry.uuid];if(Array.isArray(e.material))for(let y=0,M=e.material.length;y0){let y=[],M=[],S={};if(e.morphTargetDictionary!==void 0)for(let _ in e.morphTargetDictionary)S[e.morphTargetDictionary[_]]=_;for(let _=0;_0&&(l.extras={},l.extras.targetNames=M)}let x=Array.isArray(e.material);if(x&&o.groups.length===0)return null;let g=!1;if(x&&o.index===null){let y=[];for(let M=0,S=o.attributes.position.count;M0&&(S.targets=h),o.index!==null){let w=this.getUID(o.index);(b[y].start!==void 0||b[y].count!==void 0)&&(w+=":"+b[y].start+":"+b[y].count),t.attributes.has(w)?S.indices=t.attributes.get(w):(S.indices=this.processAccessor(o.index,o,b[y].start,b[y].count),t.attributes.set(w,S.indices)),S.indices===null&&delete S.indices}let _=await this.processMaterialAsync(m[b[y].materialIndex],o);_!==null&&(S.material=_),u.push(S)}g===!0&&o.setIndex(null),l.primitives=u,n.meshes||(n.meshes=[]),await this._invokeAllAsync(function(y){y.writeMesh&&y.writeMesh(e,l)});let v=n.meshes.push(l)-1;return t.meshes.set(s,v),v}detectMeshQuantization(e,t){if(this.extensionsUsed[Lm])return;let n;switch(t.array.constructor){case Int8Array:n="byte";break;case Uint8Array:n="unsigned byte";break;case Int16Array:n="short";break;case Uint16Array:n="unsigned short";break;default:return}t.normalized&&(n+=" normalized");let r=e.split("_",1)[0];CM[r]&&CM[r].includes(n)&&(this.extensionsUsed[Lm]=!0,this.extensionsRequired[Lm]=!0)}processCamera(e){let t=this.json;t.cameras||(t.cameras=[]);let n=e.isOrthographicCamera,r={type:n?"orthographic":"perspective"};return n?r.orthographic={xmag:e.right,ymag:e.top,zfar:e.far<=0?.001:e.far,znear:e.near<0?0:e.near}:r.perspective={aspectRatio:e.aspect,yfov:Br.degToRad(e.fov),zfar:e.far<=0?.001:e.far,znear:e.near<0?0:e.near},e.name!==""&&(r.name=e.type),t.cameras.push(r)-1}processAnimation(e,t){let n=this.json,r=this.nodeMap;n.animations||(n.animations=[]),e=qr.Utils.mergeMorphTargetTracks(e.clone(),t);let s=e.tracks,o=[],a=[];for(let c=0;c0){let a=[];for(let l=0,c=e.children.length;l0&&(s.children=a)}return await this._invokeAllAsync(function(a){a.writeNode&&a.writeNode(e,s)}),o}async _processNodeWithPivotAsync(e){let t=this.json,n=this.options,r=this.nodeMap,s=e.pivot,o={},a=e.quaternion.toArray(),l=[e.position.x+s.x,e.position.y+s.y,e.position.z+s.z],c=e.scale.toArray();xr(a,[0,0,0,1])||(o.rotation=a),xr(l,[0,0,0])||(o.translation=l),xr(c,[1,1,1])||(o.scale=c),o.extras={pivot:s.toArray()},e.name!==""&&(o.name=String(e.name)),this.serializeUserData(e,o);let u=t.nodes.push(o)-1;r.set(e,u);let h={},f=[-s.x,-s.y,-s.z];if(xr(f,[0,0,0])||(h.translation=f),e.isMesh||e.isLine||e.isPoints){let x=await this.processMeshAsync(e);x!==null&&(h.mesh=x)}else e.isCamera&&(h.camera=this.processCamera(e));e.isSkinnedMesh&&this.skins.push(e);let p=[t.nodes.push(h)-1];if(e.children.length>0){let x=[];for(let g=0,m=e.children.length;g0&&(h.children=x)}return o.children=p,await this._invokeAllAsync(function(x){x.writeNode&&x.writeNode(e,o)}),u}async processSceneAsync(e){let t=this.json,n=this.options;t.scenes||(t.scenes=[],t.scene=0);let r={};e.name!==""&&(r.name=e.name),t.scenes.push(r);let s=[];for(let o=0,a=e.children.length;o0&&(r.nodes=s),this.serializeUserData(e,r)}async processObjectsAsync(e){let t=new Tn;t.name="AuxScene";for(let n=0;n0&&await this.processObjectsAsync(n);for(let r=0;r0&&(o.range=e.distance)):e.isSpotLight&&(o.type="spot",e.distance>0&&(o.range=e.distance),o.spot={},o.spot.innerConeAngle=(1-e.penumbra)*e.angle,o.spot.outerConeAngle=e.angle),e.decay!==void 0&&e.decay!==2&&console.warn("THREE.GLTFExporter: Light decay may be lost. glTF is physically-based, and expects light.decay=2."),e.target&&(e.target.parent!==e||e.target.position.x!==0||e.target.position.y!==0||e.target.position.z!==-1)&&console.warn("THREE.GLTFExporter: Light direction may be lost. For best results, make light.target a child of the light with position 0,0,-1."),s[this.name]||(r.extensions=r.extensions||{},r.extensions[this.name]={lights:[]},s[this.name]=!0);let a=r.extensions[this.name].lights;a.push(o),t.extensions=t.extensions||{},t.extensions[this.name]={light:a.length-1}}},Um=class{constructor(e){this.writer=e,this.name="KHR_materials_unlit"}async writeMaterialAsync(e,t){if(!e.isMeshBasicMaterial)return;let r=this.writer.extensionsUsed;t.extensions=t.extensions||{},t.extensions[this.name]={},r[this.name]=!0,t.pbrMetallicRoughness.metallicFactor=0,t.pbrMetallicRoughness.roughnessFactor=.9}},Bm=class{constructor(e){this.writer=e,this.name="KHR_materials_clearcoat"}async writeMaterialAsync(e,t){if(!e.isMeshPhysicalMaterial||e.clearcoat===0)return;let n=this.writer,r=n.extensionsUsed,s={};if(s.clearcoatFactor=e.clearcoat,e.clearcoatMap){let o={index:await n.processTextureAsync(e.clearcoatMap),texCoord:e.clearcoatMap.channel};n.applyTextureTransform(o,e.clearcoatMap),s.clearcoatTexture=o}if(s.clearcoatRoughnessFactor=e.clearcoatRoughness,e.clearcoatRoughnessMap){let o={index:await n.processTextureAsync(e.clearcoatRoughnessMap),texCoord:e.clearcoatRoughnessMap.channel};n.applyTextureTransform(o,e.clearcoatRoughnessMap),s.clearcoatRoughnessTexture=o}if(e.clearcoatNormalMap){let o={index:await n.processTextureAsync(e.clearcoatNormalMap),texCoord:e.clearcoatNormalMap.channel};e.clearcoatNormalScale.x!==1&&(o.scale=e.clearcoatNormalScale.x),n.applyTextureTransform(o,e.clearcoatNormalMap),s.clearcoatNormalTexture=o}t.extensions=t.extensions||{},t.extensions[this.name]=s,r[this.name]=!0}},km=class{constructor(e){this.writer=e,this.name="KHR_materials_dispersion"}async writeMaterialAsync(e,t){if(!e.isMeshPhysicalMaterial||e.dispersion===0)return;let r=this.writer.extensionsUsed,s={};s.dispersion=e.dispersion,t.extensions=t.extensions||{},t.extensions[this.name]=s,r[this.name]=!0}},zm=class{constructor(e){this.writer=e,this.name="KHR_materials_iridescence"}async writeMaterialAsync(e,t){if(!e.isMeshPhysicalMaterial||e.iridescence===0)return;let n=this.writer,r=n.extensionsUsed,s={};if(s.iridescenceFactor=e.iridescence,e.iridescenceMap){let o={index:await n.processTextureAsync(e.iridescenceMap),texCoord:e.iridescenceMap.channel};n.applyTextureTransform(o,e.iridescenceMap),s.iridescenceTexture=o}if(s.iridescenceIor=e.iridescenceIOR,s.iridescenceThicknessMinimum=e.iridescenceThicknessMinimum,s.iridescenceThicknessMaximum=e.iridescenceThicknessMaximum,e.iridescenceThicknessMap){let o={index:await n.processTextureAsync(e.iridescenceThicknessMap),texCoord:e.iridescenceThicknessMap.channel};n.applyTextureTransform(o,e.iridescenceThicknessMap),s.iridescenceThicknessTexture=o}t.extensions=t.extensions||{},t.extensions[this.name]=s,r[this.name]=!0}},Vm=class{constructor(e){this.writer=e,this.name="KHR_materials_transmission"}async writeMaterialAsync(e,t){if(!e.isMeshPhysicalMaterial||e.transmission===0)return;let n=this.writer,r=n.extensionsUsed,s={};if(s.transmissionFactor=e.transmission,e.transmissionMap){let o={index:await n.processTextureAsync(e.transmissionMap),texCoord:e.transmissionMap.channel};n.applyTextureTransform(o,e.transmissionMap),s.transmissionTexture=o}t.extensions=t.extensions||{},t.extensions[this.name]=s,r[this.name]=!0}},Gm=class{constructor(e){this.writer=e,this.name="KHR_materials_volume"}async writeMaterialAsync(e,t){if(!e.isMeshPhysicalMaterial||e.transmission===0)return;let n=this.writer,r=n.extensionsUsed,s={};if(s.thicknessFactor=e.thickness,e.thicknessMap){let o={index:await n.processTextureAsync(e.thicknessMap),texCoord:e.thicknessMap.channel};n.applyTextureTransform(o,e.thicknessMap),s.thicknessTexture=o}e.attenuationDistance!==1/0&&(s.attenuationDistance=e.attenuationDistance),s.attenuationColor=e.attenuationColor.toArray(),t.extensions=t.extensions||{},t.extensions[this.name]=s,r[this.name]=!0}},Hm=class{constructor(e){this.writer=e,this.name="KHR_materials_ior"}async writeMaterialAsync(e,t){if(!e.isMeshPhysicalMaterial||e.ior===1.5)return;let r=this.writer.extensionsUsed,s={};s.ior=e.ior,t.extensions=t.extensions||{},t.extensions[this.name]=s,r[this.name]=!0}},Wm=class{constructor(e){this.writer=e,this.name="KHR_materials_specular"}async writeMaterialAsync(e,t){if(!e.isMeshPhysicalMaterial||e.specularIntensity===1&&e.specularColor.equals(QC)&&!e.specularIntensityMap&&!e.specularColorMap)return;let n=this.writer,r=n.extensionsUsed,s={};if(e.specularIntensityMap){let o={index:await n.processTextureAsync(e.specularIntensityMap),texCoord:e.specularIntensityMap.channel};n.applyTextureTransform(o,e.specularIntensityMap),s.specularTexture=o}if(e.specularColorMap){let o={index:await n.processTextureAsync(e.specularColorMap),texCoord:e.specularColorMap.channel};n.applyTextureTransform(o,e.specularColorMap),s.specularColorTexture=o}s.specularFactor=e.specularIntensity,s.specularColorFactor=e.specularColor.toArray(),t.extensions=t.extensions||{},t.extensions[this.name]=s,r[this.name]=!0}},Xm=class{constructor(e){this.writer=e,this.name="KHR_materials_sheen"}async writeMaterialAsync(e,t){if(!e.isMeshPhysicalMaterial||e.sheen==0)return;let n=this.writer,r=n.extensionsUsed,s={};if(e.sheenRoughnessMap){let o={index:await n.processTextureAsync(e.sheenRoughnessMap),texCoord:e.sheenRoughnessMap.channel};n.applyTextureTransform(o,e.sheenRoughnessMap),s.sheenRoughnessTexture=o}if(e.sheenColorMap){let o={index:await n.processTextureAsync(e.sheenColorMap),texCoord:e.sheenColorMap.channel};n.applyTextureTransform(o,e.sheenColorMap),s.sheenColorTexture=o}s.sheenRoughnessFactor=e.sheenRoughness,s.sheenColorFactor=e.sheenColor.toArray(),t.extensions=t.extensions||{},t.extensions[this.name]=s,r[this.name]=!0}},Ym=class{constructor(e){this.writer=e,this.name="KHR_materials_anisotropy"}async writeMaterialAsync(e,t){if(!e.isMeshPhysicalMaterial||e.anisotropy==0)return;let n=this.writer,r=n.extensionsUsed,s={};if(e.anisotropyMap){let o={index:await n.processTextureAsync(e.anisotropyMap)};n.applyTextureTransform(o,e.anisotropyMap),s.anisotropyTexture=o}s.anisotropyStrength=e.anisotropy,s.anisotropyRotation=e.anisotropyRotation,t.extensions=t.extensions||{},t.extensions[this.name]=s,r[this.name]=!0}},qm=class{constructor(e){this.writer=e,this.name="KHR_materials_emissive_strength"}async writeMaterialAsync(e,t){if(!e.isMeshStandardMaterial||e.emissiveIntensity===1)return;let r=this.writer.extensionsUsed,s={};s.emissiveStrength=e.emissiveIntensity,t.extensions=t.extensions||{},t.extensions[this.name]=s,r[this.name]=!0}},$m=class{constructor(e){this.writer=e,this.name="EXT_materials_bump"}async writeMaterialAsync(e,t){if(!e.isMeshStandardMaterial||e.bumpScale===1&&!e.bumpMap)return;let n=this.writer,r=n.extensionsUsed,s={};if(e.bumpMap){let o={index:await n.processTextureAsync(e.bumpMap),texCoord:e.bumpMap.channel};n.applyTextureTransform(o,e.bumpMap),s.bumpTexture=o}s.bumpFactor=e.bumpScale,t.extensions=t.extensions||{},t.extensions[this.name]=s,r[this.name]=!0}},Km=class{constructor(e){this.writer=e,this.name="EXT_mesh_gpu_instancing"}writeNode(e,t){if(!e.isInstancedMesh)return;let n=this.writer,r=e,s=new Float32Array(r.count*3),o=new Float32Array(r.count*4),a=new Float32Array(r.count*3),l=new Be,c=new U,u=new Sn,h=new U;for(let d=0;di.times[i.times.length-1]){if(Math.abs(i.times[i.times.length-1]-e)<.001)return i.times.length-1;r[r.length-1]=e,r.set(i.times,0),s.set(i.values,0),s.set(o.evaluate(e),i.values.length),a=r.length-1}else for(let l=0;le){r.set(i.times.slice(0,l+1),0),r[l+1]=e,r.set(i.times.slice(l+1),l+2),s.set(i.values.slice(0,(l+1)*n),0),s.set(o.evaluate(e),(l+1)*n),s.set(i.values.slice((l+1)*n),(l+2)*n),a=l+1;break}}return i.times=r,i.values=s,a},mergeMorphTargetTracks:function(i,e){let t=[],n={},r=i.tracks;for(let s=0;slP.test(r.name)).map(r=>r.name);if(e.length>0)return e;let n=[...i.filter(r=>r.opacity>=.9&&r.lightness>.12&&!/glass|window|light|lamp/i.test(r.name))].sort((r,s)=>s.area-r.area)[0];return n?[n.name]:[]}function NM(i,e){let t=i.reduce((r,s)=>r+s,0);if(t<=e)return[...i];let n=e/t;return i.map(r=>Math.max(1,Math.floor(r*n)))}var DM=i=>/^Paint/.test(i)?i:`Paint_${i||"body"}`;var Yo=i=>i.indices.length/3;function cP(i){let e=[1/0,1/0,1/0],t=[-1/0,-1/0,-1/0];for(let n=0;nMath.floor(o/t)+1),s=new Float64Array(n);for(let o=0;oe?r=l:(s=l,o=c)}return hP(i,o)}var Bi=class extends Error{reason;constructor(e,t){super(t),this.reason=e}},fP=1179937895;function dP(i){if(i.byteLength<20||new DataView(i).getUint32(0,!0)!==fP)throw new Bi("not_glb","not a binary glTF (.glb) file")}async function Zm(i){return dP(i),new Promise((e,t)=>{new Xo().parse(i,"",n=>e(n.scene),n=>{let r=String(n?.message??n);t(/draco|meshopt|ktx/i.test(r)?new Bi("compressed",r):new Bi("unreadable",r))})})}var pP=i=>i instanceof In?i:Object.assign(new In,{color:i.color?.clone()??new W(8947848),name:i.name,opacity:i.opacity,transparent:i.transparent});function kM(i,e){i.updateMatrixWorld(!0);let t=new Map;return i.traverse(n=>{let r=n;if(!r.isMesh)return;let s=r.geometry,o=s.getAttribute("position");if(!o)return;let a=pP(Array.isArray(r.material)?r.material[0]:r.material),l=t.get(a)??{positions:[],indices:[]};t.set(a,l);let c=new Be().multiplyMatrices(e,r.matrixWorld),u=l.positions.length/3,h=new U;for(let p=0;p({material:n,mesh:{positions:Float32Array.from(r.positions),indices:Uint32Array.from(r.indices)}}))}var mP=i=>{let e=0,[t,n,r]=[new U,new U,new U];for(let s=0;s.299*i.r+.587*i.g+.114*i.b;async function xP(i){let e=kM(await Zm(i),new Be);if(e.length===0)throw new Bi("empty","the file has no 3D parts");let t=new Ct;for(let s of e)t.union(new Ct().setFromArray(s.mesh.positions));let n=t.getSize(new U),r=e.map(s=>({name:s.material.name||"material",area:mP(s.mesh),opacity:s.material.opacity,lightness:gP(s.material.color)}));return{triangles:e.reduce((s,o)=>s+Yo(o.mesh),0),size:[n.x,n.y,n.z],materials:r,paint:OM(r)}}async function bP(i,e){let t=new Be().makeRotationY(e.turns*Math.PI/2),n=kM(await Zm(i),t);if(n.length===0)throw new Bi("empty","the file has no 3D parts");let r=NM(n.map(l=>Yo(l.mesh)),e.maxTriangles),s=new Tn,o=0;return n.forEach((l,c)=>{let u=BM(l.mesh,r[c]);if(Yo(u)===0)return;o+=Yo(u);let h=new Fe;h.setAttribute("position",new wt(u.positions,3)),h.setIndex(new wt(u.indices,1));let f=l.material.name||"material",d=e.paint.includes(f),p=new In({color:l.material.color.clone(),name:d?DM(f):f,metalness:l.material.metalness,roughness:l.material.roughness,opacity:l.material.opacity,transparent:l.material.opacity<1});d&&(p.userData.paint=!0),s.add(new we(h,p))}),{glb:await new Promise((l,c)=>{new qr().parse(s,u=>u instanceof ArrayBuffer?l(u):c(new Bi("unreadable","export gave no binary")),u=>c(new Bi("unreadable",String(u))),{binary:!0})}),triangles:o}}async function yP(i,e,t=220){let n=await Zm(i),r=new Ct().setFromObject(n),s=r.getCenter(new U),o=r.getSize(new U);n.traverse(d=>{let p=d;if(!p.isMesh)return;let x=p.material;(x.userData?.paint||/^Paint/.test(x.name))&&x.color.set(e),x.metalness=Math.min(x.metalness??0,.5)});let a=new Tn,l=new sr(16777215,1.6);l.position.set(-4,9,6),a.add(n,new Da(16777215,.5),new ds(16777215,6713480,1.1),l);let c=Math.max(o.x,o.y,o.z)*.75,u=new zn(-c,c,c,-c,.01,100);u.position.copy(s).add(new U(.9,.7,1.2).normalize().multiplyScalar(20)),u.lookAt(s);let h=new kr({alpha:!0,antialias:!0,preserveDrawingBuffer:!0});h.setSize(t,t,!1),h.render(a,u);let f=h.domElement.toDataURL("image/png");return h.dispose(),a.traverse(d=>{let p=d;p.isMesh&&p.geometry.dispose()}),f}var qo=null,zM=new Map,VM=16758087;function _P(i,e,t){let n=vt(i.type);if(n?.light)rl(e,n,{x:0,z:0,rotation:0,w:i.w,d:i.d,h:i.h},0,VM);else if(i.lamp)Jm(e,{x:0,z:0,size:[i.w,i.d,i.h],base:0,rotation:0,variant:i.variant??null,lamp:i.lamp},Math.max(i.h+.15,.6),VM);else{let r={id:"preview",type:i.type,x:0,z:0,rotation:0,w:i.w,d:i.d,h:i.h,variant:i.variant??null,entity:null,power:null};Ml(e,t,new lt,r)}}function vP(i){let e=i.getCenter(new U),t=new zn(-1,1,1,-1,.01,100);t.position.copy(e).add(new U(.9,.75,1.3).normalize().multiplyScalar(20)),t.lookAt(e),t.updateMatrixWorld();let n=.05;for(let s of[i.min.x,i.max.x])for(let o of[i.min.y,i.max.y])for(let a of[i.min.z,i.max.z]){let l=new U(s,o,a).applyMatrix4(t.matrixWorldInverse);n=Math.max(n,Math.abs(l.x),Math.abs(l.y))}let r=n*1.12;return Object.assign(t,{left:-r,right:r,top:r,bottom:-r}),t.updateProjectionMatrix(),t}function MP(i,e=180,t,n=1.3){let r=[i.type,i.w,i.d,i.h,i.variant??"",e,n].join("|"),s=zM.get(r);if(s)return s;t&&Nl(t),qo??=new kr({alpha:!0,antialias:!0,preserveDrawingBuffer:!0}),qo.setPixelRatio(Math.min(2,window.devicePixelRatio||1)),qo.setSize(e,e,!1),qo.setClearColor(0,0);let[o,a]=[new lt,new Wt];_P(i,o,a);let l=new we(o.geometry(),new Ke({vertexColors:!0,color:new W(n,n,n)})),c=new gn(a.geometry(),new Lt({vertexColors:!0,color:new W(n*1.8,n*1.8,n*1.8)})),u=new Tn;u.add(l,c),qo.render(u,vP(new Ct().setFromObject(l)));let h=qo.domElement.toDataURL("image/png");for(let f of[l,c])f.geometry.dispose(),f.material.dispose();return zM.set(r,h),h}var HM={cleaning:3662079,returning:16758087,docked:4310123,idle:5995775,error:16726863},SP=1.4,Qm=32,$e=2767456,WM=4873352,wP=1911110,jm=450,XM=125,TP=1.6,YM=3e4,$M=5,KM=360/$M,AP=new W(1714765),qM=.94;var e0=class{host;options;renderer;scene=new Tn;camera=new Jt(38,1,.1,400);controls;labels;root=new ct;patternTexture;blindTexture;openingTargets=new Map;fridges=new Map;covers=new Map;screens=new Map;pickFurniture=new Map;pickOpenings=new Map;pickOpenings2=new Map;flashes=new Map;surfaceGrab=null;surfaceDragging=!1;furnishTypes=null;roofWindows=new Map;roofWindowsKey="";persons=[];personPins=new Map;floorInfo=new Map;roomInfo=new Map;groundTexture=null;devices=[];devicePins=new Map;ground;floors=[];building=null;furnitureColors=null;notePhoto=null;floorId=null;roomId=null;wallMode="auto";painted=!1;explode;frame=0;lastFrame=0;qualityMode="auto";governor=null;disposed=!1;resizeObserver;fpsFrames=0;worstFrame=0;lastStatsFrame=0;lowQuality=!1;highQuality=!1;effectTime=0;effectTick=!1;tintTick=!1;effectTimer;awakeUntil=0;deviceLook="";haloTexture;roof=null;roofO=0;keepRoof=!1;robots=new Map;pets=new Map;petMat=null;petTimer;robotGeo=null;robotTrails=new Map;trailTimers=new Map;robotMat=null;mowerMat=null;robotLedGeo=null;robotLast=0;petLast=0;meshes=[];meshLight=null;meshAsked=new Set;robotTimer;floorStack="dim";floorMap=new Map;labelsDirty=!0;viewKey=new Float64Array(6);pinMode=new WeakMap;size={w:1,h:1};labelInset=0;effectFloors=new Set;deviceFloor=new Map;statsOn=!1;parked=new Map;parkedSig="";plain=!1;rightBack=!1;rightDown=null;gateOpen=new Map;gateSig="";orbitSpeed=0;orbitLast=0;orbitTimer;onScreen=!0;intersection=null;swipe=null;furnish=!1;selectedFurniture=null;selectedDevice=null;pendingDevice=null;labelPlacer=new Bu;pinHooks={furnishing:()=>this.furnish,pressedWhileFurnishing:e=>this.pendingDevice=e,selectWhileFurnishing:e=>{this.selectDevice(e),this.options.onDeviceSelect?.(e)},centre:e=>{let[t,n]=[e.getBoundingClientRect(),this.host.getBoundingClientRect()];return{x:t.left+t.width/2-n.left,y:t.top+t.height/2-n.top}},tap:(e,t,n)=>{let r=this.tapInRoom?this.devices.find(s=>s.id===e):void 0;if(r&&!this.deviceInReach(r.floorId,r.roomId))return this.options.onRoomTap?.(r.floorId,r.roomId);this.options.onDeviceTap?.(e,t,n)},hold:(e,t,n)=>this.options.onDeviceHold?.(e,t,n)};tapInRoom=!1;deviceGrab=null;grab=null;ghost=null;theme="neon";themeUniform={value:0};sun=null;weatherLayer;houseShadow=new Vu;sunArc=new Ku;sunArcLocation=null;shadowKey="";footprint={key:"",rings:[]};mapLayer;mapSettings=null;mapNorth=0;groundY=0;skyView=null;weatherTimer;energyLayer;soundLayer;waterLayer;glassAlpha={value:.2};screenLayer;pictureLayer;liveAnchors=[];liveAnchorCb=null;roomTint=null;houseRadius=20;startView=null;fpsStart=0;constructor(e,t={}){this.host=e,this.options=t,this.explode=t.explode??!0,this.qualityMode=t.quality??"auto",this.renderer=this.makeRenderer(this.qualityMode),this.labels=document.createElement("div"),this.labels.className="nf-labels",e.append(this.labels),this.patternTexture=EP(),this.blindTexture=RP(),this.haloTexture=PP(),this.ground=new we(new sn(1,1),new Ke({transparent:!0,blending:Ft,depthWrite:!1})),this.ground.rotation.x=-Math.PI/2,this.ground.renderOrder=-1,this.scene.add(this.ground,this.root),this.weatherLayer=new wh(this.scene),this.scene.add(this.houseShadow.mesh),this.scene.add(this.sunArc.group),this.mapLayer=new _h(this.scene),this.mapLayer.onChange=()=>this.invalidate(),this.energyLayer=new Eh(this.scene,this.liftOf),this.soundLayer=new Rh(this.scene,this.liftOf),this.waterLayer=new Ph(this.scene,this.liftOf),this.screenLayer=new Ih(this.scene,this.liftOf),this.screenLayer.onChange=()=>this.invalidate(),this.pictureLayer=new Lh(this.scene,this.liftOf),this.pictureLayer.onChange=()=>this.invalidate(),this.weatherLayer.onFlash=n=>this.host.classList.toggle("live-flash",n),this.controls=this.makeControls(),this.resizeObserver=new ResizeObserver(()=>this.resize()),this.resizeObserver.observe(e),document.addEventListener("visibilitychange",this.onVisibility),this.host.addEventListener("pointerdown",this.onTouch,{passive:!0}),this.renderer.domElement.addEventListener("pointerdown",this.onRightDown),this.renderer.domElement.addEventListener("pointerup",this.onRightUp),this.renderer.domElement.addEventListener("contextmenu",this.onContext),this.awakeUntil=performance.now()+YM,typeof IntersectionObserver=="function"&&(this.intersection=new IntersectionObserver(n=>{let r=n.some(s=>s.isIntersecting);r!==this.onScreen&&(this.onScreen=r,r||(clearTimeout(this.effectTimer),this.effectTimer=void 0),r&&this.invalidate())}),this.intersection.observe(e)),this.resize()}get low(){return this.lowQuality}setRightBack(e){this.rightBack=e}onRightDown=e=>{this.rightDown=this.rightBack&&e.button===2?{x:e.clientX,y:e.clientY,at:performance.now()}:null};onRightUp=e=>{let t=this.rightDown;this.rightDown=null,!(!this.rightBack||!t||e.button!==2)&&Math.hypot(e.clientX-t.x,e.clientY-t.y)<6&&performance.now()-t.at<400&&this.options.onBack?.()};onContext=e=>{this.rightBack&&e.preventDefault()};setPlain(e){e!==this.plain&&(this.plain=e,this.building&&(this.rebuild(),this.invalidate()))}exportStl(e=10){let t=[];for(let n of this.floors)for(let r of[n.wallMesh,n.floorMesh]){let s=r.geometry.getAttribute("position");s&&t.push({positions:s.array,lift:n.floor.elevation})}return Ey(t,e)}setGateStates(e){let t=[...e].map(([n,r])=>`${n}=${r?1:0}`).sort().join("|");t!==this.gateSig&&(this.gateSig=t,this.gateOpen=e,this.building&&(this.rebuild(),this.invalidate()))}setParked(e){let t=[...e].map(([n,r])=>`${n}=${r}`).sort().join("|");t!==this.parkedSig&&(this.parkedSig=t,this.parked=e,this.building&&(this.rebuild(),this.invalidate()))}setStats(e){this.statsOn=e}setLabelInset(e){this.labelInset!==e&&(this.labelInset=e,this.labelsDirty=!0,this.invalidate())}setAutoOrbit(e){this.orbitSpeed=e,this.orbitLast=0,this.invalidate()}setQuality(e){this.qualityMode=e,this.swapRenderer(e)}dropToLow(){this.disposed||this.lowQuality||this.swapRenderer("low")}swapRenderer(e){let t=this.renderer.domElement,n=this.makeRenderer(e);this.rebuildTier(),this.applyTierFlags(),t.replaceWith(n.domElement),this.renderer.dispose(),this.renderer.forceContextLoss(),this.renderer=n;let{view:r,locked:s}=this.controls;this.controls.dispose(),this.controls=this.makeControls(),this.controls.view=r,this.controls.locked=s,this.resize()}setMeshSource(e){N0(e)}setPacks(e){Nl(e),this.building&&(this.rebuild(),this.invalidate())}setBuilding(e){let t=this.building===null;this.building=e,this.rebuild(),t&&this.fit(0),this.invalidate()}get walking(){return this.controls.walk!==null}startWalk(){let e=this.floors.filter(l=>l.floor.rooms.some(c=>c.points.length>=3)),t=(this.floorId?this.floorMap.get(this.floorId):void 0)??[...e].sort((l,c)=>Math.abs(l.floor.elevation)-Math.abs(c.floor.elevation))[0];if(!t||!t.bbox)return null;let n=t.floor.rooms.filter(l=>l.points.length>=3),r=n.find(l=>l.id===this.roomId)??[...n].sort((l,c)=>vr(c.points)-vr(l.points))[0],[s,o]=r?Bs(r.points):[(t.bbox.x0+t.bbox.x1)/2,(t.bbox.z0+t.bbox.z1)/2];this.floorId!==t.floor.id&&this.setFloor(t.floor.id,!1);let a=.3;return this.controls.walk={eye:new U(s,t.floor.elevation+t.ty+TP,o),yaw:this.controls.view.theta,pitch:-.05,stick:[0,0],keys:new Set,bounds:{x0:t.bbox.x0-a,x1:t.bbox.x1+a,z0:t.bbox.z0-a,z1:t.bbox.z1+a},last:0},this.labelsDirty=!0,this.wake(),t.floor.id}stopWalk(){this.controls.walk&&(this.controls.walk=null,this.labelsDirty=!0,this.fit(700))}setWalkStick(e,t){this.controls.walk&&(this.controls.walk.stick=[e,t],this.wake())}setFloor(e,t=!0){let n=this.keepCamera&&this.floorId!==null&&e!==null&&e!==this.floorId?{theta:this.controls.view.theta,phi:this.controls.view.phi,radius:this.controls.view.radius}:null;this.floorId=e,this.roomId=null,this.labelsDirty=!0,this.applyTargets(!t),this.applyHighlight(),this.fit(t?700:0,n)}setKeepCamera(e){this.keepCamera=e}setZoom(e){let t=Math.min(3,Math.max(.5,e||1));t!==this.zoom&&(this.zoom=t,this.building&&this.fit(400))}setFloorStack(e){e!==this.floorStack&&(this.floorStack=e,this.applyTargets(!1))}setKeepRoof(e){e!==this.keepRoof&&(this.keepRoof=e,this.invalidate())}setExplode(e){e!==this.explode&&(this.explode=e,this.applyTargets(!1),this.floorId===null&&this.fit(700))}selectRoom(e){if(this.roomId=e,this.labelsDirty=!0,this.applyHighlight(),!e){this.fit(700);return}let t=this.floors.find(u=>u.floor.rooms.some(h=>h.id===e)),n=t?.floor.rooms.find(u=>u.id===e);if(!t||!n)return;let r=n.start_view;if(r){let u=t.floor.elevation+t.ty,[h,f]=Bs(n.points),d=r.target??{x:h,y:.3,z:f};this.controls.flyTo({target:new U(d.x,d.y+u,d.z),radius:r.radius,phi:r.phi,theta:r.theta});return}let[s,o]=Bs(n.points),a=n.points.map(u=>u[0]),l=n.points.map(u=>u[1]),c=new U(Math.max(...a)-Math.min(...a),t.floor.cut_height,Math.max(...l)-Math.min(...l));this.controls.flyTo({target:new U(s,t.floor.elevation+t.ty+.3,o),radius:Math.max(4,this.distanceFor(c)*1.05),phi:.72})}get lowered(){return this.wallMode!=="auto"}setPaintedWalls(e){e!==this.painted&&(this.painted=e,this.rebuild(),this.invalidate())}wallPaint(e){return this.painted&&this.building?Gp(this.building.settings,e):void 0}setWallMode(e){this.wallMode=e;for(let t of this.floors)this.buildLamps(t);this.invalidate()}setDevices(e){let t=e.map(r=>`${r.id}:${r.active?1:0}:${r.glow?r.glow.level.toFixed(1):"-"}`).join(";");t!==this.deviceLook&&(this.deviceLook=t,this.wake()),this.devices=e,this.labelsDirty=!0,this.effectFloors=new Set(e.filter(r=>r.effect&&r.glow||(r.spin??0)>0).map(r=>r.floorId)),this.deviceFloor=new Map(e.map(r=>[r.id,r.floorId]));let n=new Set;for(let r of e){n.add(r.id);let s=this.devicePins.get(r.id);s||(s={el:Ay(r.id,this.pinHooks),icon:"",text:"",watt:"",label:"",active:!1,unavailable:!1,glow:"",caption:""},this.devicePins.set(r.id,s),this.labels.append(s.el));let o=s.el;s.icon!==r.icon&&(s.icon=r.icon,o.querySelector(".nf-dev-icon").innerHTML=r.icon),s.text!==r.text&&(s.text=r.text,o.querySelector(".nf-dev-text").textContent=r.text);let a=r.caption??"";s.caption!==a&&(s.caption=a,o.querySelector(".nf-dev-name").textContent=a);let l=r.power!==null&&r.power!==void 0&&r.power>=1?r.powerText??`${Math.round(r.power)} W`:"";s.watt!==l&&(s.watt=l,o.querySelector(".nf-dev-watt").textContent=l);let c=`${r.name}: ${r.text}`;s.label!==c&&(s.label=c,o.title=r.name,o.setAttribute("aria-label",c)),s.active!==r.active&&(s.active=r.active,o.classList.toggle("nf-dev-on",r.active)),s.unavailable!==r.unavailable&&(s.unavailable=r.unavailable,o.classList.toggle("nf-dev-na",r.unavailable));let u=r.glow?`rgb(${r.glow.color.map(h=>Math.round(h*255)).join(", ")})`:"";s.glow!==u&&(s.glow=u,u?o.style.setProperty("--nf-glow",u):o.style.removeProperty("--nf-glow"))}for(let[r,s]of this.devicePins)n.has(r)||(s.el.remove(),this.devicePins.delete(r));for(let r of this.floors)this.buildGlow(r),this.buildLamps(r);this.invalidate()}setRoofWindows(e){let t=JSON.stringify([...e]);t!==this.roofWindowsKey&&(this.roofWindowsKey=t,this.roofWindows=e,this.buildRoofMesh(),this.invalidate())}setPersons(e){this.labelsDirty=!0,this.persons=e;let t=new Set;for(let n of e){t.add(n.id);let r=this.personPins.get(n.id);if(r||(r=document.createElement("div"),r.className="nf-person",r.dataset.entity=n.id,this.personPins.set(n.id,r),this.labels.append(r)),r.title=n.name,r.setAttribute("aria-label",n.name),r.dataset.picture!==(n.picture??"")||r.dataset.initials!==n.initials)if(r.dataset.picture=n.picture??"",r.dataset.initials=n.initials,r.replaceChildren(),n.picture){let s=document.createElement("img");s.src=n.picture,s.alt="",s.addEventListener("error",()=>s.replaceWith(document.createTextNode(n.initials))),r.append(s)}else r.textContent=n.initials}for(let[n,r]of this.personPins)t.has(n)||(r.remove(),this.personPins.delete(n));this.invalidate()}setNavigationLocked(e){this.controls.locked=e}setPickTargets(e,t,n=new Map){this.pickFurniture=e,this.pickOpenings=t,this.pickOpenings2=n}setNotePhotos(e){this.notePhoto=e}setFurnitureColors(e){JSON.stringify(e??{})!==JSON.stringify(this.furnitureColors??{})&&(this.furnitureColors=e,this.building&&(this.rebuild(),this.invalidate()))}setAccent(e){let t=wy(e),n=t?1:0;n===Yu.value&&(!t||Xu.value.equals(new U(...t)))||(Yu.value=n,t&&Xu.value.set(...t),this.invalidate())}setTheme(e){if(e===this.theme)return;this.theme=e,this.placeMap(),this.themeUniform.value=Sy(e);let t=xl(e),n=[...this.floors.map(r=>r.materials.lines),...this.roof?[this.roof.lines]:[]];for(let r of n)r.blending=t,r.needsUpdate=!0;this.placeGround(),this.invalidate()}setFurnishMode(e){this.furnish=e,e||this.selectFurniture(null),this.invalidate()}selectFurniture(e){e&&this.selectedDevice&&this.selectDevice(null),this.selectedFurniture=e,this.updateGhost(),this.invalidate()}setSun(e){this.sun=e;for(let t of this.floors)this.buildSun(t);this.buildHouseShadow(),this.buildSunArc(),this.invalidate()}setLocation(e){this.sunArcLocation=e,this.buildSunArc(),this.invalidate()}buildSunArc(){let e=this.building,t=this.sunArcLocation,n=(e?.floors??[]).flatMap(c=>[...c.rooms.flatMap(u=>u.points),...(c.outdoor??[]).flatMap(u=>u.points)]);if(!e||!e.settings.sun_arc||!t||!n.length)return void this.sunArc.update(null,null,0);let r=n.map(c=>c[0]),s=n.map(c=>c[1]),o=[(Math.min(...r)+Math.max(...r))/2,(Math.min(...s)+Math.max(...s))/2],a=Math.max(6,Math.hypot(Math.max(...r)-Math.min(...r),Math.max(...s)-Math.min(...s))/2+3),l=Math.min(0,...e.floors.map(c=>c.elevation));this.sunArc.update({centre:o,radius:a,north:e.settings.north??0,...t},this.sun,l)}buildHouseShadow(){if(!this.houseShadow)return;let e=this.building,t=(e?.floors??[]).filter(u=>u.elevation>=-.01&&u.rooms.length),n=!e||!t.length||e.settings.sun_patches===!1||this.lowQuality,r=this.weatherLayer?.cloud??0,s=e?.settings.north??0,o=t.map(u=>`${u.elevation}:${u.height}:${JSON.stringify(u.rooms.map(h=>h.points))}`).join("|"),a=n?"off":`${this.sun?.elevation.toFixed(1)},${this.sun?.azimuth.toFixed(1)},${s},${r.toFixed(2)},${o}`;if(a===this.shadowKey)return;if(this.shadowKey=a,n){this.houseShadow.update([],0,0,null,0,0,!0);return}let l=Math.min(...t.map(u=>u.elevation)),c=Math.max(...t.map(u=>u.elevation+u.height));this.footprint.key!==o&&(this.footprint={key:o,rings:fr(t.flatMap(u=>u.rooms.map(h=>h.points)))}),this.houseShadow.update(this.footprint.rings,c-l,l+.03,this.sun,s,r,!1)}liftOf=e=>{if(!e)return{y:0,dy:0,visible:!0};let t=this.floorMap.get(e);return t?{y:t.floor.elevation+t.y,dy:t.y,visible:t.group.visible}:{y:0,dy:0,visible:!1}};setLiveEnergy(e,t){this.energyLayer.setArcs(e),this.energyLayer.setSparks(t),this.invalidate()}setLiveSound(e,t){this.soundLayer.set(e,t),this.invalidate()}setGlassWalls(e){let t=Math.min(1,Math.max(0,e));t!==this.glassAlpha.value&&(this.glassAlpha.value=t,this.invalidate())}setLiveWater(e){this.waterLayer.set(e),this.invalidate()}setLiveScreens(e){let t=[];for(let n of e){let r=this.building?.floors.find(a=>a.id===n.floorId),s=r?.furniture.find(a=>a.id===n.furnitureId),o=s&&r?th(s,r):null;!s||!o||t.push({...n,x:s.x,z:s.z,rotation:s.rotation,rect:o})}this.screenLayer.set(t),this.invalidate()}setPictures(e){let t=[];for(let n of e){let r=this.building?.floors.find(a=>a.id===n.floorId),s=r?.furniture.find(a=>a.id===n.furnitureId),o=s&&r?Sp(s,r):null;!s||!o||t.push({id:n.furnitureId,floorId:n.floorId,url:n.url,border:n.border,fit:n.fit,x:s.x,z:s.z,rotation:s.rotation,rect:o})}this.pictureLayer.set(t),this.invalidate()}setLiveAnchors(e,t){this.liveAnchors=e,this.liveAnchorCb=t,this.invalidate()}placeLhAnchors(){let e=this.liveAnchorCb;if(!e||!this.liveAnchors.length)return;let t=new U;this.liveAnchors.forEach((n,r)=>{let s=this.liftOf(n.floorId);t.set(n.x,s.y+n.y,n.z).project(this.camera);let o=s.visible&&t.z<1&&Math.abs(t.x)<1.15&&Math.abs(t.y)<1.15;e(r,(t.x+1)/2*this.size.w,(1-t.y)/2*this.size.h,o)})}setSky(e){this.skyView=e,this.weatherLayer.set(e?{...e,low:e.low||this.lowQuality}:null),this.buildHouseShadow();for(let t of this.floors)this.buildSun(t);this.invalidate()}setRoomTint(e){let t=!!e!=!!this.roomTint;if(this.roomTint=e,this.tintTick=!0,this.applyHighlight(),t)for(let n of this.floors)n.glowSig="",this.buildGlow(n)}setScreens(e){this.screens=e;for(let t of this.floors)this.buildScreens(t);this.invalidate()}fillRoomPin(e,t,n){if(e.textContent=t||"\u2013",n){let r=document.createElement("small");r.textContent=n,e.append(r),e.classList.add("nf-pin-info")}else e.classList.remove("nf-pin-info")}setRoomInfo(e){if(!(e.size===this.roomInfo.size&&[...e].every(([n,r])=>this.roomInfo.get(n)===r))){this.roomInfo=e;for(let n of this.floors)for(let r of n.roomPins)this.fillRoomPin(r.pin,r.room.name,e.get(r.room.id))}}setFloorInfo(e){this.floorInfo=e;for(let t of this.floors){let n=t.label.querySelector("span"),r=e.get(t.floor.id)??this.options.floorInfo?.(t.floor)??"";n&&n.textContent!==r&&(n.textContent=r,t.labelSize=null,this.labelsDirty=!0)}this.invalidate()}setOpeningStates(e){let t=this.openingTargets;this.openingTargets=e,[...e].some(([n,r])=>!tp(t.get(n)??Ns,r))&&this.wake(),this.invalidate()}wake(){this.awakeUntil=performance.now()+YM,this.invalidate()}get resting(){return this.lowQuality&&performance.now()>this.awakeUntil}setFridgeDoors(e){for(let[t,n]of e){let r=this.fridges.get(t)??{l:n.left?1:0,r:n.right?1:0,tl:0,tr:0};r.tl=n.left?1:0,r.tr=n.right?1:0,this.fridges.set(t,r)}for(let t of[...this.fridges.keys()])e.has(t)||this.fridges.delete(t);this.invalidate()}setCovers(e){let t=!1;for(let[n,r]of e){let s=this.covers.get(n);s?s.t!==r&&(s.t=r,t=!0):(this.covers.set(n,{k:r,t:r}),t=!0)}for(let n of[...this.covers.keys()])e.has(n)||this.covers.delete(n);if(t){for(let n of this.floors)this.buildFridges(n);this.wake()}}stepCovers(e){let t=Math.min(1,e/4e3),n=!1;for(let r of this.covers.values()){if(r.k===r.t)continue;let s=r.t-r.k;r.k=Math.abs(s)<=t?r.t:r.k+Math.sign(s)*t,n=!0}if(n)for(let r of this.floors)this.buildFridges(r);return n}stepFridges(e){let t=ep(e),n=new Set;for(let[r,s]of this.fridges)for(let[o,a]of[["l","tl"],["r","tr"]]){let l=s[a]-s[o];if(Math.abs(l)<.004){l!==0&&(s[o]=s[a],n.add(r));continue}s[o]+=l*t,n.add(r)}if(!n.size)return!1;for(let r of this.floors)r.floor.furniture.some(s=>n.has(s.id))&&this.buildFridges(r);return!0}buildFridges(e){let t=new lt;for(let n of e.floor.furniture){let r=vt(n.type);if(r&&P0(r)){Gd(t,r,n,Gt(e.floor,n),this.covers.get(n.id)?.k??I0(r,null));continue}if(n.type!=="fridge_smart")continue;let s=this.fridges.get(n.id);vp(t,n,Gt(e.floor,n),s?.l??0,s?.r??0)}e.fridgeMesh.geometry.dispose(),e.fridgeMesh.geometry=t.geometry(),e.fridgeMesh.visible=t.count>0}resetView(){this.fit(700)}setStartView(e){this.startView=e}currentView(){let e=this.controls.view,t=this.floorBase(this.floorId);return{theta:e.theta,phi:e.phi,radius:e.radius,target:{x:e.target.x,y:e.target.y-t,z:e.target.z}}}floorBase(e){let t=e===null?void 0:this.floorMap.get(e);return t?t.floor.elevation+t.ty:0}dispose(){this.disposed=!0,cancelAnimationFrame(this.frame),clearTimeout(this.effectTimer),clearTimeout(this.robotTimer),clearTimeout(this.orbitTimer),clearTimeout(this.weatherTimer),this.weatherLayer.dispose(),this.sunArc?.dispose(),this.houseShadow?.dispose(),this.mapLayer.dispose(),this.energyLayer.dispose(),this.soundLayer.dispose(),this.waterLayer.dispose(),this.screenLayer.dispose(),this.pictureLayer.dispose(),this.resizeObserver.disconnect(),this.intersection?.disconnect(),document.removeEventListener("visibilitychange",this.onVisibility),this.host?.removeEventListener("pointerdown",this.onTouch),this.renderer?.domElement?.removeEventListener?.("pointerdown",this.onRightDown),this.renderer?.domElement?.removeEventListener?.("pointerup",this.onRightUp),this.renderer?.domElement?.removeEventListener?.("contextmenu",this.onContext),clearTimeout(this.petTimer),this.controls.dispose(),this.clear(),this.building=null,this.buildRoofMesh(),this.ground.geometry.dispose(),this.ground.material.dispose(),this.patternTexture.dispose(),this.blindTexture.dispose(),this.groundTexture?.dispose(),this.haloTexture.dispose();for(let e of this.robots.values())e.led.dispose();this.robots.clear();for(let e of this.robotTrails.values())e.removeFromParent(),e.geometry.dispose(),e.material.dispose();this.robotTrails.clear();for(let e of this.trailTimers.values())clearTimeout(e);this.trailTimers.clear(),this.robotGeo?.dispose(),this.robotLedGeo?.dispose(),this.robotMat?.dispose(),this.mowerMat?.dispose(),this.meshLight?.dispose(),this.renderer.dispose(),this.renderer.forceContextLoss(),this.renderer.domElement.remove(),this.labels.remove()}invalidate(){this.frame||this.disposed||document.hidden||!this.onScreen||(this.frame=requestAnimationFrame(e=>this.render(e)))}makeRenderer(e){let t=e==="low"||e==="auto"&&xb();this.lowQuality=t,this.weatherLayer&&this.skyView&&this.weatherLayer.set({...this.skyView,low:this.skyView.low||t}),this.weatherLayer&&this.buildHouseShadow(),this.highQuality=e==="high";let n=new kr({antialias:!t,alpha:!0,powerPreference:t?"low-power":"default"}),r=Math.min(window.devicePixelRatio||1,t?1:e==="high"?2.5:2);return n.setPixelRatio(r),this.governor=e==="auto"&&!t?new Lu(r,Math.min(1,r)):null,n.setClearColor(0,0),n.outputColorSpace=ft,n.domElement.className="nf-canvas",this.host.prepend(n.domElement),n}makeControls(){return new El(this.renderer.domElement,this.camera,{change:()=>this.wake(),tap:(e,t)=>this.onTap(e,t),hold:(e,t)=>this.onHold(e,t),swipeStart:(e,t,n,r)=>this.swipeStart(e,t,n,r),swipeMove:e=>this.swipe&&this.options.onDeviceSwipe?.(this.swipe.entity,"move",e,this.swipe.x,this.swipe.y),swipeEnd:()=>{this.swipe&&this.options.onDeviceSwipe?.(this.swipe.entity,"end",0,this.swipe.x,this.swipe.y),this.swipe=null},grab:(e,t)=>this.grabFurniture(e,t),drag:(e,t)=>this.dragFurniture(e,t),drop:()=>this.dropFurniture(),doubleTap:(e,t)=>{let n=this.floorId&&this.options.onRoomDoubleTap?this.pick(e,t):null;n&&!("entity"in n)&&n.roomId?this.options.onRoomDoubleTap(n.floorId,n.roomId):this.options.onBack?.()}})}onTouch=()=>this.wake();onVisibility=()=>{document.hidden&&(clearTimeout(this.effectTimer),this.effectTimer=void 0),document.hidden||this.invalidate()};scheduleEffects(){if(!this.hasVisibleEffects(document.hidden)||this.resting){clearTimeout(this.effectTimer),this.effectTimer=void 0;return}if(this.effectTimer!==void 0)return;let e=this.lowQuality?2*XM:XM;this.effectTimer=setTimeout(()=>{if(this.effectTimer=void 0,!!this.hasVisibleEffects(document.hidden)){this.effectTime=performance.now()/1e3,this.effectTick=!0;for(let t of this.floors)t.o<.02||!this.effectFloors.has(t.floor.id)||(this.buildLamps(t),this.buildGlow(t));this.invalidate()}},e)}hasVisibleEffects(e){return!e&&!this.disposed&&this.onScreen&&this.floors.some(t=>t.o>=.02&&this.effectFloors.has(t.floor.id))}resize(){let e=this.host.clientWidth||1,t=this.host.clientHeight||1;this.size={w:e,h:t},this.labelsDirty=!0,this.renderer.setSize(e,t,!1),this.camera.aspect=e/t,this.camera.updateProjectionMatrix(),this.invalidate()}clear(){for(let e of this.robots.values())e.group.removeFromParent();for(let e of this.meshes)e.group.removeFromParent(),Rm(e.group);this.meshes=[];for(let e of this.floors){e.group.traverse(t=>{t.geometry?.dispose()});for(let t of Object.values(e.materials))Array.isArray(t)||t.dispose();for(let t of e.materials.ghosts)t.material.dispose();this.root.remove(e.group)}this.floors=[],this.floorMap=new Map;for(let e of[...this.labels.children])e.dataset.entity||e.remove()}buildLightSurface(e){let t=this.lowQuality?.5:.25,n=ap(e.floor,e.geo.walls2d,e.geo.wallBuckets,e.geo.openings,t,e.geo.holes,e.geo.roofUnder),r=CP(e.floor,e.geo.openRooms);if(e.lightZones=r.some((a,l)=>a!==l)?r:null,e.lightZones){for(let a=0;a=0&&l=0&&a.a=0&&a.bthis.glowOf(h)),r=t.doors.map(h=>{let f=e.geo.openings.find(p=>p.opening.id===h.id);if(f&&_r(f.opening,f.exterior)==="passage")return 1;let d=e.openings.get(h.id);return d?Math.max(d.open,d.open2??0):.5}),s=n.map(h=>`${h.x.toFixed(2)},${h.y.toFixed(2)},${h.z.toFixed(2)},${h.kind},${h.level.toFixed(3)},${h.color.map(f=>f.toFixed(3)).join("/")}`).join(";")+"|"+r.map(h=>h.toFixed(1)).join(",");if(s===e.glowSig)return;e.glowSig=s;let o=e.glowMesh.geometry,a=o.getAttribute("color");if(!n.length){e.glowMesh.visible=!1,o.setDrawRange(0,0);return}let l=lp(t,n,.42,r);if(this.roomTint){let h=e.floor.rooms.length;for(let f=0;f.004;if(f)for(let d=0;d<6;d++)c[u++]=h*6+d}o.index.needsUpdate=!0,o.setDrawRange(0,u),e.glowMesh.visible=u>0}withoutFurniture(e){if(this.gateOpen.size&&(e.outdoor??[]).some(n=>n.gates?.length)&&(e={...e,outdoor:e.outdoor.map(n=>n.gates?.length?{...n,gates:n.gates.map(r=>({...r,open:this.gateOpen.get(r.id)??!1}))}:n)}),!this.plain)return e;let t=n=>n.type==="stairs"||n.type==="stairwell"||!!vt(n.type)?.hole;return{...e,furniture:e.furniture.filter(t)}}rebuild(){let e=new Map(this.floors.map(s=>[s.floor.id,{y:s.y,o:s.o}])),t=new Map(this.floors.map(s=>[s.floor.id,s.openings]));this.clear();let n=this.building;if(!n)return;fb({...n.settings.furniture_colors,...this.furnitureColors});let r=[...n.floors].sort((s,o)=>s.elevation-o.elevation);for(let s of n.floors){let o=n.settings.roof?.solar??[],a=ih(n)?.id===s.id?o.filter(V=>V.face===Sl).map(V=>({field:V,face:rh(n,V)})):[],l=o.filter(V=>V.face.startsWith(`wall:${s.id}:`));if(l.length){let V=new Map(nh(n,s.id).map(re=>[re.key,re]));for(let re of l){let be=V.get(re.face);be&&a.push({field:re,face:be})}}let u=(n.settings.roof.sections??[]).some(V=>$d(V,s.elevation+s.height))?(V,re)=>{let be=Kd(n,V,re);return be===null?null:be-s.elevation}:void 0,h=Hp(this.withoutFurniture(bh(s,this.parked)),n.settings.wall_exterior,n.settings.wall_interior,Wp(n.floors,s),a,u,this.wallPaint(s)),f={standing:{value:65535},glass:{value:0},slope:{value:new _t},slopeY:{value:new De},glassAlpha:this.glassAlpha},d=Ty({mask:f,look:this.themeUniform,theme:this.theme,textures:{pattern:this.patternTexture,blinds:this.blindTexture,halo:this.haloTexture}}),p=new ct,x=new we(h.floor,d.floor),g=new we(h.shadow,d.shadow);g.renderOrder=1;let m=new we(h.floor,d.pattern);m.renderOrder=2;let b=new we(new Fe,d.glow);b.renderOrder=3,b.visible=!1;let v=new we(new Fe,d.frames),y=new we(new Fe,d.blinds),M=new we(new Fe,d.glass);M.renderOrder=4;let S=new we(new Fe,d.lamps);S.visible=!1;let _=new we(new Fe,d.cones);_.visible=!1,_.renderOrder=3;let w=new xn(new Fe,d.halos);w.visible=!1,w.renderOrder=7;let R=new we(new Fe,d.cones);R.visible=!1,R.renderOrder=7;let A=new we(new Fe,d.lamps);A.visible=!1;let C=new we(new Fe,d.screens);C.visible=!1,C.renderOrder=5;for(let V of[v,y,M])V.frustumCulled=!1;let O=new we(h.walls,d.glassWall),D=new we(h.walls,d.wall);O.renderOrder=6,p.add(x,g,m,b,D,new gn(h.lines,d.lines),v,y,M,S,_,w,R,A,C,O);for(let V of h.ghosts){let re=Zn(new Ke({vertexColors:!0,transparent:!0,opacity:V.opacity,depthWrite:!1,side:ut}),this.themeUniform);d.ghosts.push({material:re,base:V.opacity});let be=new we(V.geometry,re);be.renderOrder=2,p.add(be)}this.root.add(p);let P=document.createElement("button");P.className="nf-pin nf-pin-floor",P.dataset.floor=s.id;let I=document.createElement("b");I.textContent=s.name||"\u2013";let N=document.createElement("span");N.textContent=this.floorInfo.get(s.id)??this.options.floorInfo?.(s)??"",P.append(I,N),P.addEventListener("click",()=>this.options.onFloorTap?.(s.id)),this.labels.append(P);let F=e.get(s.id),H=[],B=null;for(let V of s.rooms){let re=document.createElement("button");re.className="nf-pin",re.dataset.room=V.id,re.dataset.floor=s.id,this.fillRoomPin(re,V.name,this.roomInfo.get(V.id)),re.addEventListener("click",()=>this.options.onRoomTap?.(s.id,V.id)),this.labels.append(re);let[be,Y]=Bs(V.points);H.push({pin:re,room:V,cx:be,cz:Y});for(let[Q,se]of V.points)B??={x0:Q,x1:Q,z0:se,z1:se},B.x0=Math.min(B.x0,Q),B.x1=Math.max(B.x1,Q),B.z0=Math.min(B.z0,se),B.z1=Math.max(B.z1,se)}let X=[];for(let V of s.notes??[]){if(!V.text)continue;let re=document.createElement("button");re.className=`nf-pin nf-note-pin${d0(V)?" nf-note-due":""}`,re.title=V.text;let be=V.text.length>28?`${V.text.slice(0,27)}\u2026`:V.text;re.textContent=`${V.photo?"\u{1F4F7} ":"\u270E "}${be}`,re.addEventListener("click",()=>{let Y=re.classList.toggle("nf-note-open");re.textContent=`${V.photo?"\u{1F4F7} ":"\u270E "}${Y?V.text:be}`;let Q=Y&&V.photo?this.notePhoto?.(V.photo):null;if(Q){let se=document.createElement("img");se.className="nf-note-photo",se.alt="",se.src=Q,se.addEventListener("load",()=>{this.labelsDirty=!0,this.invalidate()}),re.append(se)}this.labelsDirty=!0,this.invalidate()}),this.labels.append(re),X.push({pin:re,note:V})}this.floors.push({floor:s,rank:r.indexOf(s),group:p,geo:h,floorMesh:x,shadowMesh:g,patternMesh:m,glowMesh:b,lightSurface:null,lightZones:null,framesMesh:v,glassMesh:M,blindsMesh:y,lampMesh:S,sunMesh:_,sunSig:"",haloMesh:w,coneMesh:R,wedgeTris:[],fridgeMesh:A,lampTris:[],lampFurnTris:[],frameTris:[],glassTris:[],blindTris:[],wallMesh:D,screenMesh:C,screenSig:"",flowLayout:"",glowSig:"",lampShapeSig:"",lampColorSig:"",lampShade:new Float32Array(0),lampRanges:new Map,bbox:B,roomPins:H,notePins:X,labelSize:null,materials:d,mask:f,openings:new Map,y:F?.y??0,o:F?.o??1,ty:0,to:1,appliedO:-1,label:P})}this.floorMap=new Map(this.floors.map(s=>[s.floor.id,s])),this.buildPets();for(let s of this.floors)this.buildFridges(s);this.labelsDirty=!0,this.floorId&&!n.floors.some(s=>s.id===this.floorId)&&(this.floorId=null);for(let s of this.floors){this.buildLamps(s),this.buildScreens(s);let o=t.get(s.floor.id);for(let a of s.geo.openings)s.openings.set(a.opening.id,o?.get(a.opening.id)??this.openingTargets.get(a.opening.id)??Ns);this.buildOpenings(s),this.buildLightSurface(s),this.buildSun(s)}this.applyTargets(e.size===0),this.applyHighlight(),this.applyTierFlags(),this.buildRoofMesh(),this.updateGhost(),this.placeMeshes()}placeMeshes(){for(let e of this.meshes)e.group.removeFromParent(),Rm(e.group);this.meshes=[];for(let e of this.floors)for(let t of bh(e.floor,this.parked).furniture){let n=vt(t.type);if(!n?.mesh)continue;let r=n.mesh;if(!Dl(t.type)){this.meshAsked.has(r)||(this.meshAsked.add(r),yM(r).then(a=>{a&&!this.disposed&&this.rebuild()}));continue}let s=n.colors?.length?(n.colors.find(a=>a.id===t.variant)??n.colors[0]).hex:null,o=_M(r,{x:t.x,z:t.z,y:Gt(e.floor,t),rotation:t.rotation,mirror:t.mirror,w:t.w,d:t.d,h:t.h,paint:s});o&&(this.meshLight||(this.meshLight=vM(this.root,this.renderer)),MM(o,this.meshLight.env),e.group.add(o),this.meshes.push({group:o,furnitureId:t.id}))}this.invalidate()}buildRoofMesh(){this.roof&&(this.roof.group.traverse(a=>a.geometry?.dispose()),this.roof.solid.dispose(),this.roof.lines.dispose(),this.roof.glass.dispose(),this.scene.remove(this.roof.group),this.roof=null);let e=this.building?kp(this.building,this.roofWindows):[];if(!e.length)return;let t=new ct,n=Zn(new Ke({vertexColors:!0,transparent:!0,side:ut}),this.themeUniform),r=Zn(new Lt({vertexColors:!0,transparent:!0,blending:xl(this.theme),depthWrite:!1}),this.themeUniform,!0),s=Zn(new Ke({vertexColors:!0,transparent:!0,side:ut,depthWrite:!1}),this.themeUniform),o=e.map(a=>{let l=new ct;return l.add(new we(a.solid.geometry(),n),new gn(a.lines.geometry(),r)),a.glass.count&&l.add(new we(a.glass.geometry(),s)),l.renderOrder=8,t.add(l),{group:l,floorId:a.floor.id,rideId:Jd(this.building,a.floor,a.sections??[]),base:a.base,lift:a.lift!==!1}});t.renderOrder=8,this.scene.add(t),this.roof={group:t,parts:o,solid:n,lines:r,glass:s},this.placeRoof()}placeRoof(e=1e3){let t=this.roof;if(!t)return!1;let n=this.keepRoof?1:Math.min(1,Math.max(0,(this.controls.view.radius/this.houseRadius-.62)/.3)),s=(this.floorId===null||this.floors.length===1)&&!this.lowered?qM*n:0,o=Qd(e),a=this.roofO;this.roofO+=(s-this.roofO)*o,Math.abs(s-this.roofO)<.004&&(this.roofO=s),t.group.visible=this.roofO>.02;for(let l of t.parts){let c=this.floorMap.get(l.floorId);if(!c)continue;let u=this.floorMap.get(l.rideId)??c,h=u.ty>0?Math.min(1,u.y/u.ty):this.explode&&this.floorId===null?1:0,f=Math.max(0,1-this.roofO/qM);l.group.position.y=c.floor.elevation+u.y+l.base+f*2.2+(l.lift?h*SP:0)}return t.solid.opacity=this.roofO,t.solid.depthWrite=this.roofO>.5,t.lines.opacity=this.roofO,t.glass.opacity=this.roofO*.28,this.roofO!==a&&this.roofO!==s}applyTierFlags(){let e=this.lowQuality;this.ground.visible=!e&&this.theme!=="day"&&this.floors.some(t=>t.floor.rooms.length>0);for(let t of this.floors)t.patternMesh.visible=!e,t.shadowMesh.visible=!e&&t.o>.98;this.invalidate()}rebuildTier(){for(let e of this.floors)e.flowLayout="",this.buildLightSurface(e),e.lampShapeSig="",this.buildLamps(e)}get houseView(){return this.floorId===null&&this.floors.length>1}applyTargets(e){let t=this.floorId?this.floorMap.get(this.floorId):void 0;for(let n of this.floors){let r=Vb(n.rank,t?.rank,this.explode,this.floorStack);[n.ty,n.to]=[r.y,r.opacity],e&&([n.y,n.o]=[r.y,r.opacity]),this.applyFloor(n)}this.invalidate()}applyFloor(e){e.group.position.y=e.floor.elevation+e.y,e.group.visible=e.o>.02,e.shadowMesh.visible=e.o>.98&&!this.lowQuality,!(Math.abs(e.appliedO-e.o)<.001)&&(e.appliedO=e.o,Hb(e.materials,e.o))}stepFloors(e){let t=!1,n=Qd(e);for(let r of this.floors){let s=Gb(r,n);s.settled&&(this.labelsDirty=!0),(s.moving||s.settled)&&this.applyFloor(r),t||=s.moving}return t}stepOpenings(e){let t=!1,n=ep(e);for(let r of this.floors){let s=!1;for(let[o,a]of r.openings){let l=this.openingTargets.get(o)??Ns;if(tp(a,l))continue;let c=Yb(a,l,n);r.openings.set(o,c.state),s=!0,t||=c.moving}s&&(this.buildOpenings(r),this.buildGlow(r),this.buildSun(r))}return t}fanPhase(e){return e.lamp!=="fan"||!e.spin?0:Math.round(this.effectTime*e.spin*360%KM*10)/10}glowOf(e){return Lv(e.glow,e.effect,this.effectTime)}buildLamps(e){let t=performance.now(),n=h=>{let f=this.flashes.get(h);if(!f||f<=t)return 0;let d=f-t,p=d>jm?.5+.5*Math.sin(d/140):d/jm;return Math.round(p*10)/10},r=this.devices.filter(h=>h.floorId===e.floor.id&&h.lamp),s=this.wallMode+(this.lowQuality?"L":this.highQuality?"H":"M")+r.map(h=>`${h.id},${h.lamp},${h.variant},${h.x},${h.z},${h.y},${h.rotation??0},${h.roll??0},${h.upright?1:0},${h.rise??0},${h.size?.join("/")},${h.base??0},${h.pack??""},${h.mirror?1:0},${h.ceiling??""},${this.fanPhase(h)}`).join(";"),o=r.map(h=>this.glowOf(h)),a=this.devices.filter(h=>h.floorId===e.floor.id&&h.wedge),l=r.map((h,f)=>`${n(h.id)},${o[f]?`${o[f].level.toFixed(3)},${o[f].color.map(d=>d.toFixed(3)).join("/")}`:"off"}`).join(";")+"|"+a.map(h=>`${h.id},${h.x},${h.z},${h.rotation??0},${JSON.stringify(h.wedge)}`).join(";");if(s!==e.lampShapeSig||!e.lampMesh.geometry.getAttribute("position")){e.lampShapeSig=s,e.lampColorSig="";let h=new lt,f=[],d=[],p=new Map,x=e.floor.height;for(let g of r){let m=g.lamp==="strip"?(g.base??x)>Math.min(e.floor.cut_height,g.ceiling??x):g.lamp?ku.has(g.lamp):!1;if(!g.lamp||m&&this.lowered)continue;let b=h.count,v=g.pack?vt(g.pack):void 0,[y,M,S]=g.size??[.3,.3,.3];v?rl(h,v,{x:g.x,z:g.z,rotation:g.rotation??0,w:y,d:M,h:S,mirror:g.mirror},g.base??0,65280):Jm(h,{...g,lamp:g.lamp,phase:this.fanPhase(g)},g.ceiling??x,65280),p.set(g.furnitureId??g.id,{start:b,end:h.count}),g.pickable!==!1&&f.push({id:g.id,start:b,end:h.count}),g.furnitureId&&d.push({id:g.furnitureId,start:b,end:h.count})}e.lampTris=f,e.lampFurnTris=d,e.lampRanges=p,e.lampShade=bb(h.c),e.lampMesh.geometry.dispose(),e.lampMesh.geometry=h.geometry(),e.lampMesh.visible=h.count>0}if(l===e.lampColorSig)return;e.lampColorSig=l;let c=e.lampMesh.geometry.getAttribute("color"),u=c.array;r.forEach((h,f)=>{let d=e.lampRanges.get(h.furnitureId??h.id);if(!d)return;let p=o[f],x=p?.55+.45*p.level:0,g=p?new W(...p.color.map(v=>Math.min(1,v*x))):new W(wP),m=n(h.id);m>0&&g.lerp(new W(1,1,1),.7*m);let b=new W(g.getHex());yb(u,e.lampShade,d,[b.r,b.g,b.b])}),c.needsUpdate=!0,this.buildHalos(e)}buildSun(e){let t=this.building?.settings.sun_patches===!1?null:this.sun,n=this.building?.settings.north??0,r=this.weatherLayer?.cloud??0,s=iy(t,n,r,e.openings.values());if(s===e.sunSig)return;e.sunSig=s;let o=ry({floor:e.floor,openings:e.geo.openings,states:e.openings,sun:t,northDegrees:n,cloud:r});e.sunMesh.geometry.dispose(),e.sunMesh.geometry=o.geometry(),e.sunMesh.visible=o.count>0}buildHalos(e){let t={positions:[],colours:[]},n=new lt,r=[];for(let a of this.devices)if(a.floorId===e.floor.id&&a.wedge){let l=Jb(n,a,e.geo.walls2d);a.wedge.through||r.push({id:a.id,...l})}e.wedgeTris=r;let s=this.lowered;for(let a of this.lowQuality?[]:this.devices){let l=this.glowOf(a);if(a.floorId!==e.floor.id||!a.lamp||!l||s&&ty(a.lamp))continue;let c=a;Qb(t,c,l,a.ceiling??e.floor.height),this.highQuality&&(a.lamp==="downlight"||a.lamp==="spot")&&ey(n,c,l,a.ceiling??e.floor.height)}let o=new Fe;o.setAttribute("position",new ke(t.positions,3)),o.setAttribute("color",new ke(t.colours,3)),e.haloMesh.geometry.dispose(),e.haloMesh.geometry=o,e.haloMesh.visible=!this.lowQuality&&t.positions.length>0,e.coneMesh.geometry.dispose(),e.coneMesh.geometry=n.geometry(),e.coneMesh.visible=n.count>0}buildScreens(e){let t=bh(e.floor,this.parked).furniture.filter(s=>this.screens.has(s.id)),n=t.map(s=>`${s.id}:${s.x},${s.z},${s.rotation},${s.w},${s.d},${s.h},${s.mount_y??""},${s.mirror?1:0}:${JSON.stringify(this.screens.get(s.id))}`).join(";");if(n===e.screenSig&&e.screenMesh.geometry.getAttribute("position"))return;e.screenSig=n;let r=new lt;for(let s of t){let o=this.screens.get(s.id),a=s.rotation*pt,l=Math.cos(a),c=Math.sin(a),u=(y,M,S)=>[s.x+y*l-S*c,M,s.z+y*c+S*l];if(o.gangs){let y=vt(s.type);if(!y)continue;for(let M of o.gangs){let S=new W(...M.color.map(_=>Math.min(1,_*(.45+.55*M.level))));il(r,y,s,Gt(e.floor,s),S.getHex(),_=>_.gang===M.gang)}continue}if(o.print!==void 0){let y=Gt(e.floor,s)+s.h*.2,M=Math.min(s.w,s.d)*.16,S=y+s.h*.38*Math.min(1,Math.max(0,o.print)),_=new W(...o.color.map(C=>Math.min(1,C*(.35+.65*o.level)))),w=_.clone().multiplyScalar(.7),R=[u(-M,y,-M),u(M,y,-M),u(M,y,M),u(-M,y,M)],A=[u(-M,S,-M),u(M,S,-M),u(M,S,M),u(-M,S,M)];r.tri(A[0],A[2],A[1],_),r.tri(A[0],A[3],A[2],_);for(let C=0;C<4;C++){let O=(C+1)%4;r.tri(R[C],R[O],A[O],w),r.tri(R[C],A[O],A[C],w)}continue}if(o.fill!==void 0){let y=wp(s,e.floor);if(!y)continue;let M=y.rect,S=Math.min(1,Math.max(0,o.fill)),_=new W(...o.color.map(C=>Math.min(1,C*(.35+.65*o.level)))),w=new W(.08,.1,.13),R=M.z,A=(C,O,D,P,I)=>{r.tri(u(C,D,R),u(O,D,R),u(O,P,R),I),r.tri(u(C,D,R),u(O,P,R),u(C,P,R),I)};if(y.vertical){let C=M.y0+(M.y1-M.y0)*S;S>0&&A(M.x0,M.x1,M.y0,C,_),S<1&&A(M.x0,M.x1,C,M.y1,w)}else{let C=M.x0+(M.x1-M.x0)*S;S>0&&A(M.x0,C,M.y0,M.y1,_),S<1&&A(C,M.x1,M.y0,M.y1,w)}continue}if(o.leds){let y=vt(s.type);if(!y)continue;let M=new W(...o.color.map(S=>Math.min(1,S*(.35+.65*o.level))));il(r,y,s,Gt(e.floor,s),M.getHex(),S=>!!S.glow||!!S.screen);continue}if(o.heat){let y=vt(s.type);if(!y)continue;let M=new W(...o.color.map(S=>Math.min(1,S*(.35+.65*o.level))));il(r,y,s,Gt(e.floor,s),M.getHex(),()=>!0);continue}if(o.faces){let y=Math.max(.05,s.w)*(s.mirror?-1:1),M=Math.max(.05,s.d),S=Math.max(.005,s.h),_=Gt(e.floor,s);for(let w of o.faces){let R=w.part==="right"?.03:-Math.abs(y)/2+.03,A=w.part==="left"?-.03:Math.abs(y)/2-.03,C=_+(w.part==="bottom"?S*.45:S)+.006,O=new W(...w.color.map(B=>Math.min(1,B*(.35+.65*w.level)))),D=new W(0,0,0),P=(B,X,V=C)=>u(B*Math.sign(y),V,X),I=[P(R,-M/2+.03),P(A,-M/2+.03),P(A,M/2-.03),P(R,M/2-.03)];r.tri(I[0],I[2],I[1],O),r.tri(I[0],I[3],I[2],O);let N=.12+.1*w.level,F=O.clone().multiplyScalar(.5),H=[P(R-N,-M/2-N,C+.004),P(A+N,-M/2-N,C+.004),P(A+N,M/2+N,C+.004),P(R-N,M/2+N,C+.004)];for(let B=0;B<4;B++){let X=(B+1)%4;r.tri(I[B],H[X],H[B],F,D,D),r.tri(I[B],I[X],H[X],F,F,D)}}continue}let h=th(s,e.floor);if(!h)continue;let f=new W(...o.color.map(y=>Math.min(1,y*(.35+.65*o.level)))),d=new W(0,0,0),p=h.z+.004;r.tri(u(h.x0,h.y0,p),u(h.x1,h.y0,p),u(h.x1,h.y1,p),f),r.tri(u(h.x0,h.y0,p),u(h.x1,h.y1,p),u(h.x0,h.y1,p),f);let x=Math.min(1.5,o.halo??1);if(x<=0)continue;let g=(.18+.12*o.level)*Math.min(1,x),m=f.clone().multiplyScalar(.5*x),b=[u(h.x0,h.y0,p),u(h.x1,h.y0,p),u(h.x1,h.y1,p),u(h.x0,h.y1,p)],v=[u(h.x0-g,h.y0-g,p+.01),u(h.x1+g,h.y0-g,p+.01),u(h.x1+g,h.y1+g,p+.01),u(h.x0-g,h.y1+g,p+.01)];for(let y=0;y<4;y++){let M=(y+1)%4;r.tri(b[y],v[y],v[M],m,d,d),r.tri(b[y],v[M],b[M],m,d,m)}}e.screenMesh.geometry.dispose(),e.screenMesh.geometry=r.geometry(),e.screenMesh.visible=r.count>0}buildOpenings(e){let t=$p(e.geo.openings,e.openings,Math.min(e.floor.cut_height,e.floor.height),-.2-e.floor.elevation);e.frameTris=t.frameTris,e.glassTris=t.glassTris,e.blindTris=t.blindTris;for(let[n,r]of[[e.framesMesh,t.frames],[e.glassMesh,t.glass],[e.blindsMesh,t.blinds]])n.geometry.dispose(),n.geometry=r,n.visible=r.getAttribute("position").count>0}activeFloors(){return this.floors.filter(e=>e.to>.99)}applyHighlight(){for(let e of this.floors){let t=e.geo.floor.getAttribute("color");for(let n of e.geo.roomTris){let r=new W(n.color),s=this.roomTint?.get(n.roomId);s&&r.lerp(new W(...s).multiplyScalar(.6),.9),n.roomId===this.roomId&&r.lerp(AP,s?.3:.75);for(let o=n.start*3;oc.group),!0)[0];if(l){let c=l.object;for(;c&&!this.meshes.some(h=>h.group===c);)c=c.parent;let u=c?this.pickFurniture.get(this.meshes.find(h=>h.group===c).furnitureId):void 0;if(u)return{entity:u}}}let o=s.flatMap(l=>[l.lampMesh,l.coneMesh,l.framesMesh,l.glassMesh,l.blindsMesh,l.wallMesh,l.floorMesh].filter(c=>c.visible)),a=(l,c)=>l.find(u=>c>=u.start&&ch.group===l.object.parent);if(!(!n&&(l.object===u.lampMesh||l.object===u.coneMesh||l.object===u.framesMesh||l.object===u.blindsMesh||l.object===u.glassMesh))){if(l.object===u.lampMesh||l.object===u.coneMesh){let h=a(l.object===u.lampMesh?u.lampTris:u.wedgeTris,c);if(h)return{entity:h}}else if(l.object===u.framesMesh||l.object===u.blindsMesh||l.object===u.glassMesh){if(this.lowered&&l.face){let x=l.object.geometry.getAttribute("fold")?.getX(l.face.a)??Xe;if(x!==Xe&&Math.floor(x/16)%8===0)continue}let h=a(l.object===u.framesMesh?u.frameTris:l.object===u.glassMesh?u.glassTris:u.blindTris,c),f=h?this.pickOpenings.get(h):void 0,d=h?this.pickOpenings2.get(h):void 0,p=d?u.geo.openings.find(x=>x.opening.id===h):void 0;if(d&&p&&(l.point.x-p.start[0])*p.axis[0]+(l.point.z-p.start[1])*p.axis[1]>p.width/2&&(f=d),f)return{entity:f}}else if(l.object===u.wallMesh){let h=a(u.geo.furnitureTris,c),f=h&&n?this.pickFurniture.get(h):void 0;if(f)return{entity:f};if(l.face&&!h){let d=u.wallMesh.geometry.getAttribute("fold")?.getX(l.face.a)??32,p=Math.floor(d/16)%8,x=d%16,g=this.lowered&&p===0,m=(u.mask.glass.value&1<S.points.length>=3&&Ve(y,S.points))?.id??null;if(this.roomId!==null){if(M===this.roomId)return{floorId:u.floor.id,roomId:M}}else if(!m&&M)return{floorId:u.floor.id,roomId:M}}}}else if(l.object===u.floorMesh)return{floorId:u.floor.id,roomId:a(u.geo.roomTris.map(h=>({id:h.roomId,start:h.start,end:h.end})),c)??null}}}return null}onTap(e,t){let n=this.furnish?this.pick(e,t):this.pickInReach(e,t);if(n&&"entity"in n&&this.furnish){this.selectDevice(n.entity),this.options.onDeviceSelect?.(n.entity);return}if(n&&"entity"in n){this.flashes.set(n.entity,performance.now()+jm),this.invalidate(),this.options.onDeviceTap?.(n.entity,e,t);return}this.options.onRoomTap?.(n?.floorId??this.floorId??"",n?.roomId??null)}furnitureAt(e,t){let n=this.rayAt(e,t),r=this.activeFloors(),s=r.flatMap(o=>[o.lampMesh,o.wallMesh].filter(a=>a.visible));for(let o of n.intersectObjects(s,!1)){if(o.faceIndex==null)continue;let a=r.find(u=>u.group===o.object.parent),c=(o.object===a.lampMesh?a.lampFurnTris:a.geo.furnitureTris).find(u=>o.faceIndex>=u.start&&o.faceIndexh.id===n)?.furnitureId:void 0,a=o?null:this.furnitureAt(e,t),l=o??a?.id,c=l?this.floors.find(h=>h.floor.furniture.some(f=>f.id===l)):void 0,u=c?.floor.furniture.find(h=>h.id===l)?.type;return!!(c&&l&&u&&r.has(u))&&this.grabItem(c,l,e,t)}if(n){let o=this.devices.find(l=>l.id===n)?.furnitureId,a=o?this.floors.find(l=>l.floor.furniture.some(c=>c.id===o)):void 0;return!o||!a?this.grabDevice(n,e,t):this.grabItem(a,o,e,t)}let s=this.furnitureAt(e,t);if(!s){let o=this.pick(e,t);return o&&"entity"in o?this.grabDevice(o.entity,e,t):(this.selectedFurniture&&(this.selectFurniture(null),this.options.onFurnitureSelect?.(null)),this.selectedDevice&&(this.selectDevice(null),this.options.onDeviceSelect?.(null)),!1)}return this.grabItem(s.fv,s.id,e,t)}grabItem(e,t,n,r){let s=e.floor.furniture.find(a=>a.id===t),o=this.floorPoint(e,n,r);return!s||!o?!1:s.locked?(this.selectFurniture(s.id),this.options.onFurnitureSelect?.(s.id),!1):(this.grab={floorId:e.floor.id,id:s.id,offset:[s.x-o[0],s.z-o[1]],x:s.x,z:s.z,moved:!1},this.selectFurniture(s.id),this.options.onFurnitureSelect?.(s.id),!0)}grabDevice(e,t,n){let r=this.devices.find(a=>a.id===e),s=r&&this.floorMap.get(r.floorId),o=s&&this.floorPoint(s,t,n);return!r||!s||!o?!1:r.fixed?(this.selectDevice(e),this.options.onDeviceSelect?.(e),!1):(this.deviceGrab={id:e,floorId:s.floor.id,offset:[r.x-o[0],r.z-o[1]],x:r.x,z:r.z,moved:!1},this.selectDevice(e),this.options.onDeviceSelect?.(e),!0)}setSelectedDevice(e){e!==this.selectedDevice&&this.selectDevice(e)}selectDevice(e){e&&this.selectedFurniture&&(this.selectFurniture(null),this.options.onFurnitureSelect?.(null)),this.selectedDevice=e;for(let[t,n]of this.devicePins)n.el.classList.toggle("nf-dev-sel",t===e)}dragFurniture(e,t){if(this.surfaceDragging){this.surfaceGrab?.move(this.surfaceRay(e,t));return}let n=this.deviceGrab;if(n){let l=this.floorMap.get(n.floorId),c=this.devices.find(f=>f.id===n.id),u=l&&this.floorPoint(l,e,t);if(!l||!c||!u)return;let h=this.building?.settings.grid??.05;n.x=c.x=Math.round((u[0]+n.offset[0])/h)*h,n.z=c.z=Math.round((u[1]+n.offset[1])/h)*h,n.moved=!0,this.labelsDirty=!0,this.invalidate();return}let r=this.grab,s=r&&this.floorMap.get(r.floorId);if(!r||!s)return;let o=this.floorPoint(s,e,t);if(!o)return;let a=this.building?.settings.grid??.05;r.x=Math.round((o[0]+r.offset[0])/a)*a,r.z=Math.round((o[1]+r.offset[1])/a)*a,r.moved=!0,this.updateGhost(),this.invalidate()}dropFurniture(){if(this.surfaceDragging){this.surfaceDragging=!1,this.surfaceGrab?.end();return}let e=this.deviceGrab;this.deviceGrab=null,e?.moved&&this.options.onDeviceMove?.(e.id,Math.round(e.x*1e3)/1e3,Math.round(e.z*1e3)/1e3);let t=this.grab;this.grab=null,t?.moved&&this.options.onFurnitureMove?.(t.id,Math.round(t.x*1e3)/1e3,Math.round(t.z*1e3)/1e3),this.updateGhost()}updateGhost(){this.ghost&&(this.ghost.geometry.dispose(),this.ghost.material.dispose(),this.scene.remove(this.ghost),this.ghost=null);let e=this.selectedFurniture,t=e?this.floors.find(m=>m.floor.furniture.some(b=>b.id===e)):void 0,n=t?.floor.furniture.find(m=>m.id===e);if(!t||!n)return;let r=this.grab?.id===n.id?this.grab.x:n.x,s=this.grab?.id===n.id?this.grab.z:n.z,o=Ol(t.floor,{...n,x:r,z:s}),a=y0.has(n.type),l=Math.max(.1,n.type==="lamp_pendant"?.3:n.h),c=vt(n.type)||n.type==="lamp_wall"||n.type==="led_strip"?Gt(t.floor,n):a?n.type==="lamp_pendant"||n.type==="ceiling_fan"?o-n.h-.1:o-l:Gt(t.floor,n),u=n.rotation*pt,h=Math.cos(u),f=Math.sin(u),d=(m,b,v)=>[r+m*h-b*f,v,s+m*f+b*h],p=new Wt,x=[[-n.w/2,-n.d/2],[n.w/2,-n.d/2],[n.w/2,n.d/2],[-n.w/2,n.d/2]],g=new W(.25,.9,1);for(let m=0;m<4;m++){let[b,v]=x[m],[y,M]=x[(m+1)%4];p.seg(d(b,v,c+.01),d(y,M,c+.01),g),p.seg(d(b,v,c+l),d(y,M,c+l),g),p.seg(d(b,v,c+.01),d(b,v,c+l),g)}p.seg(d(-n.w/2,n.d/2+.03,c+.02),d(n.w/2,n.d/2+.03,c+.02),new W(1,1,1)),this.ghost=new gn(p.geometry(),new Lt({vertexColors:!0,depthTest:!1,transparent:!0})),this.ghost.position.y=t.floor.elevation+t.y,this.ghost.renderOrder=20,this.scene.add(this.ghost)}onHold(e,t){let n=this.pick(e,t);n&&"entity"in n&&this.options.onDeviceHold?.(n.entity,e,t)}swipeStart(e,t,n,r){if(this.furnish||Math.abs(r)m.floor.rooms.some(b=>b.points.length>=3));if(!n.length)return[];let r=this.lowQuality?1:Math.min(2,window.devicePixelRatio||1),s=Math.round(e*r),o=Math.round(t*r),a=new wn(s,o);a.texture.colorSpace=ft;let l=new zn(-1,1,1,-1,.1,400),c=this.floors.map(m=>({fv:m,visible:m.group.visible,y:m.y,o:m.o,standing:m.mask.standing.value,glass:m.mask.glass.value})),u=this.roof?.group.visible??!1,h=this.ghost?.visible??!1,f=this.renderer.getClearAlpha(),d=new Uint8Array(s*o*4),p=document.createElement("canvas");p.width=s,p.height=o;let x=p.getContext("2d"),g=[];try{this.roof&&(this.roof.group.visible=!1),this.ghost&&(this.ghost.visible=!1),this.renderer.setClearAlpha(0);for(let m of n){for(let D of this.floors)D.group.visible=D===m;m.y=0,m.o=1,this.applyFloor(m),m.group.visible=!0,m.mask.standing.value=0,m.mask.glass.value=0;let b=m.floor.rooms.flatMap(D=>D.points),v=m.floor.elevation,y=new Ct(new U(Math.min(...b.map(D=>D[0]))-.3,v,Math.min(...b.map(D=>D[1]))-.3),new U(Math.max(...b.map(D=>D[0]))+.3,v+Math.min(m.floor.cut_height,m.floor.height),Math.max(...b.map(D=>D[1]))+.3)),M=y.getCenter(new U),S=-.6,_=.8,w=new U(Math.sin(_)*Math.sin(S),Math.cos(_),Math.sin(_)*Math.cos(S));l.position.copy(M).addScaledVector(w,100),l.lookAt(M),l.updateMatrixWorld();let R=.5,A=.5;for(let D of[y.min.x,y.max.x])for(let P of[y.min.y,y.max.y])for(let I of[y.min.z,y.max.z]){let N=new U(D,P,I).applyMatrix4(l.matrixWorldInverse);R=Math.max(R,Math.abs(N.x)),A=Math.max(A,Math.abs(N.y))}let C=s/o;R/A>C?A=R/C:R=A*C,l.left=-R*1.05,l.right=R*1.05,l.top=A*1.05,l.bottom=-A*1.05,l.updateProjectionMatrix(),this.renderer.setRenderTarget(a),this.renderer.clear(),this.renderer.render(this.scene,l),this.renderer.readRenderTargetPixels(a,0,0,s,o,d);let O=x.createImageData(s,o);for(let D=0;D{Math.hypot(u[0]-r.motion.pos[0],u[1]-r.motion.pos[1])o.length?`${o.length}:${o[0].map(a=>a.toFixed(2))}/${o[o.length-1].map(a=>a.toFixed(2))}`:"").join("|"),r=this.robotTrails.get(e.id);if(r&&r.userData.key===n){this.showRobotTrail(e);return}let s=r;if(!s){let o=new Ke({color:3590399,transparent:!0,opacity:.34,depthWrite:!1,side:ut});s=new we(Im([],.16,0),o),s.renderOrder=3,s.name=`robot-trail:${e.id}`,this.robotTrails.set(e.id,s);let a=this.robots.get(e.id)?.group.parent;a&&a.add(s)}s.geometry.dispose(),s.geometry=Im(t,.16,(e.y??0)+.012),s.userData.key=n,this.showRobotTrail(e)}showRobotTrail(e){let t=this.robotTrails.get(e.id);if(!t)return;let n=this.trailTimers.get(e.id);n!==void 0&&(clearTimeout(n),this.trailTimers.delete(e.id));let r=Date.now(),s=EM(e.settledAt,r);if(t.material.opacity=.34*s,t.visible=(e.track?.length??0)>0&&s>.01,s<=0||s>=1&&e.settledAt==null)return;let o=s>=1?Math.max(0,(e.settledAt??r)+Uh-r):250;this.trailTimers.set(e.id,setTimeout(()=>{this.showRobotTrail(e),this.invalidate()},o))}makeRobot(e){if(!this.robotGeo){let s=new lt,o=(l,c,u,h,f)=>{let d=[];for(let p=0;p<20;p++)d.push([Math.cos(p/20*Math.PI*2)*l,Math.sin(p/20*Math.PI*2)*l]);Tt(s,d,c,u,h,f,{aoFrom:0,bottom:!1})};o(.17,.012,.08,2371657,3424863),o(.055,.08,.1,3820138,5070726),this.robotGeo=s.geometry(),this.robotMat=new Ke({vertexColors:!0});let a=new lt;Tt(a,[[-.05,.1],[.05,.1],[.05,.14],[-.05,.14]],.08,.085,16777215,16777215,{aoFrom:0,bottom:!1}),this.robotLedGeo=a.geometry()}let t=new ct,n=new Ke({color:HM[e.mode]}),r=e.mower?this.mowerMat??=new Ke({color:4164170}):this.robotMat;return t.add(new we(this.robotGeo,r),new we(this.robotLedGeo,n)),e.mower&&t.scale.set(1.7,1.6,1.7),{info:e,motion:{pos:[...e.rest],heading:e.restHeading,path:[],next:0},group:t,led:n}}buildPets(){let e=new Map(this.pets);this.pets.clear(),this.petMat??=new Ke({vertexColors:!0});for(let t of this.floors)for(let n of t.floor.furniture){let r=vt(n.type);if(!r?.pet)continue;let s=t.floor.rooms.find(f=>f.points.length>=3&&Ve([n.x,n.z],f.points)),o=e.get(n.id),a=new lt;Ms(new Li(a,new Wt,Ss({x:0,z:0,rotation:0,mirror:n.mirror})),r,Math.max(.05,n.w),Math.max(.05,n.d),Math.max(.05,n.h),0,null,null,n.variant??null),o?.group.removeFromParent();let l=new ct;l.add(new we(a.geometry(),this.petMat));let c=s?t.floor.furniture.filter(f=>f.id!==n.id&&!vt(f.type)?.pet&&f.type!=="rug"&&Gt(t.floor,f)<.5&&Ve([f.x,f.z],s.points)).map(f=>ts(f)):[],u={points:s?.points??[[n.x-.5,n.z-.5],[n.x+.5,n.z-.5],[n.x+.5,n.z+.5],[n.x-.5,n.z+.5]],obstacles:c,speed:n.type.endsWith(":pet_dog")?.7:.45},h=o&&s&&Ve(o.motion.pos,s.points)?o.motion:{pos:[n.x,n.z],heading:n.rotation*Math.PI/180,target:null,rest:1};this.pets.set(n.id,{motion:h,room:u,random:mb(n.id),group:l,floorId:t.floor.id})}for(let[t,n]of e)this.pets.has(t)||n.group.removeFromParent()}setPetRooms(e){for(let[t,n]of this.pets){let r=this.floorMap.get(n.floorId),s=e.get(t);if(!r||s===void 0)continue;let o=s?r.floor.rooms.find(l=>l.id===s&&l.points.length>=3):void 0;if(!o||n.room.points===o.points)continue;let a=r.floor.furniture.filter(l=>!vt(l.type)?.pet&&l.type!=="rug"&&Gt(r.floor,l)<.5&&Ve([l.x,l.z],o.points)).map(l=>ts(l));n.room={...n.room,points:o.points,obstacles:a},Ve(n.motion.pos,o.points)||(n.motion={...n.motion,pos:Bs(o.points),target:null,rest:.5})}this.invalidate()}stepRobots(e){if(!this.robots.size&&!this.pets.size)return!1;let t=this.robotLast?Math.min(.2,(e-this.robotLast)/1e3):0;this.robotLast=e;let n=!1,r=1/0,s=this.petLast?(e-this.petLast)/1e3:0;this.petLast=e;for(let o of this.pets.values()){let a=this.floorMap.get(o.floorId);if(!a)continue;o.group.parent!==a.group&&a.group.add(o.group),gb(o.motion,o.room,s,o.random)||!!o.motion.target?n=!0:r=Math.min(r,Math.max(0,o.motion.rest)),o.group.position.set(o.motion.pos[0],0,o.motion.pos[1]),o.group.rotation.y=o.motion.heading}clearTimeout(this.petTimer),!n&&Number.isFinite(r)&&(this.petTimer=setTimeout(()=>this.invalidate(),r*1e3+50));for(let o of this.robots.values()){let a=this.floorMap.get(o.info.floorId);if(!a)continue;o.group.parent!==a.group&&a.group.add(o.group);let l=this.robotTrails.get(o.info.id);l&&l.parent!==a.group&&a.group.add(l),t>0?n=AM(o.motion,o.info,t)||n:n||=o.info.mode==="cleaning"||o.info.mode==="returning",o.group.position.set(o.motion.pos[0],o.info.y??0,o.motion.pos[1]),o.group.rotation.y=o.motion.heading}return n||(this.robotLast=0),n}getView(){return{...this.controls.view,target:this.controls.view.target.clone()}}showView(e,t=900){let n=e.target??{x:0,y:0,z:0};this.controls.maxRadius=Math.max(this.controls.maxRadius,e.radius*1.5),this.controls.flyTo({target:new U(n.x,n.y,n.z),radius:e.radius,phi:e.phi,theta:e.theta},t)}flyTo(e,t=900){this.controls.flyTo(e,t)}focus(e,t,n,r,s){let o=this.floorMap.get(e);if(o){if(this.controls.flyTo({target:new U(t,o.floor.elevation+o.ty+r,n),radius:5.5,phi:.78},900),s){this.flashes.set(s,performance.now()+2400);let a=this.host.querySelector(`.nf-dev[data-entity="${CSS.escape(s)}"]`);a?.classList.add("nf-dev-found"),setTimeout(()=>a?.classList.remove("nf-dev-found"),2600)}this.invalidate()}}render(e){if(this.frame=0,this.disposed)return;let t=this.lastFrame?Math.min(100,e-this.lastFrame):16,n=!1;this.orbitSpeed&&!this.controls.active?(this.orbitLast&&(this.controls.view.theta+=this.orbitSpeed*Math.min(100,e-this.orbitLast)/1e3),this.orbitLast=e,n=!0):this.orbitLast=0;let r=this.controls.update(e),s=this.stepFloors(t),a=[this.stepOpenings(t),this.stepFridges(t),this.stepCovers(t)].some(Boolean),l=!1;if(this.flashes.size){let g=new Set;for(let[m,b]of this.flashes){let v=this.deviceFloor.get(m);v&&g.add(v),b<=e&&this.flashes.delete(m)}l=this.flashes.size>0;for(let m of this.floors)g.has(m.floor.id)&&this.buildLamps(m)}let c=this.placeRoof(t),u=this.stepRobots(e);this.pictureLayer.step();let f=[this.weatherLayer,this.energyLayer,this.soundLayer,this.screenLayer,this.waterLayer].map(g=>g.step(e)).some(Boolean),d=r||s||a||l||c,p=[];if(r&&p.push("camera"),s&&p.push("floors"),a&&p.push("openings"),l&&p.push("flash"),c&&p.push("roof"),this.effectTick&&p.push("effect"),u&&p.push("robot"),n&&p.push("orbit"),this.tintTick&&p.push("tint"),this.effectTick=this.tintTick=!1,this.lastFrame=d?e:0,d&&this.governor){let g=this.governor.frame(t,e);g&&"ratio"in g?(this.renderer.setPixelRatio(g.ratio),this.resize()):g&&setTimeout(()=>this.dropToLow(),0)}this.updateWalls(),this.renderer.render(this.scene,this.camera),this.placeLhAnchors(),(this.viewChanged()||s||this.labelsDirty)&&(this.labelsDirty=!1,this.updateLabels()),this.reportStats(e,p),d&&this.invalidate(),this.scheduleEffects(),!d&&n&&!this.orbitTimer&&(this.orbitTimer=setTimeout(()=>{this.orbitTimer=void 0,this.invalidate()},this.lowQuality?66:33));let x=this.resting;!d&&f&&!this.weatherTimer&&!x&&(this.weatherTimer=setTimeout(()=>{this.weatherTimer=void 0,this.invalidate()},33)),!d&&u&&!this.robotTimer&&!x&&(this.robotTimer=setTimeout(()=>{this.robotTimer=void 0,this.invalidate()},this.lowQuality?66:33))}updateWalls(){if(this.controls.walk){for(let o of this.floors)o.mask.standing.value=65535,o.mask.glass.value=0,o.mask.slope?.value.set(0,0,0,0);return}let e=this.camera.position,t=this.controls.view.target,n=e.x-t.x,r=e.z-t.z,s=Math.hypot(n,r)||1;for(let o of this.floors){let a=this.roomId!==null&&o.floor.rooms.some(h=>h.id===this.roomId),l=this.wallMode==="cut",c=0,u=0;o.geo.buckets.forEach((h,f)=>{let d=h?h[0]*n/s+h[1]*r/s>=.25:a;this.wallMode!=="auto"||!d||(this.painted?a&&(u|=1<.5&&r)){this.labelPlacer.place(n.label,null);continue}let s=n.floor.elevation+n.y+n.floor.cut_height*.5,o=[r.x0,r.x1].flatMap(l=>[r.z0,r.z1].map(c=>this.screenPoint([l,s,c],1/0)));n.label.hidden&&(n.label.hidden=!1),n.labelSize??={w:n.label.offsetWidth,h:n.label.offsetHeight};let a=kb(o,n.labelSize.w,{width:this.size.w,inset:this.labelInset});t.push({fv:n,rank:n.rank,left:a.left,y:a.y,height:n.labelSize.h})}for(let n of Bb(t))this.labelPlacer.place(n.fv.label,Ub(n.left,n.y));this.updateDevicePins();for(let n of this.floors){let r=n.to<.99||n.o<.9||e||this.roomId!==null||this.otherFloor(n),s=n.floor.elevation+n.y+.05;for(let a of n.roomPins){let l=r?null:this.screenPoint([a.cx,s,a.cz],1.1);this.labelPlacer.place(a.pin,l&&!l.off?hl(l):null)}let o=e||n.o<.9||this.otherFloor(n);for(let{pin:a,note:l}of n.notePins){let c=o?null:this.screenPoint([l.x,n.floor.elevation+n.y+(l.y??f0),l.z]);this.labelPlacer.place(a,c&&!c.off?hl(c):null)}}}otherFloor(e){return this.floorId!==null&&e.floor.id!==this.floorId}updateDevicePins(){let e=this.houseView;for(let t of this.persons){let n=this.personPins.get(t.id),r=this.floorMap.get(t.floorId);if(!n)continue;let s=r&&!e&&jd(r,this.otherFloor(r))?this.screenPoint([t.x,r.floor.elevation+r.y+.9,t.z]):null;this.labelPlacer.place(n,s&&!s.off?hl(s):null)}for(let t of this.devices){let n=this.devicePins.get(t.id)?.el;if(!n)continue;let r=this.floorMap.get(t.floorId),s=t.id.startsWith("detect:"),o=!!t.full&&t.roomId===null,a=!!r&&(o?zb(r):(!e||s)&&jd(r,this.otherFloor(r))),c=!!r&&a&&t.pin!==!1?this.screenPoint([t.x,r.floor.elevation+r.y+t.y,t.z]):null;if(!c||c.off){this.labelPlacer.place(n,null);continue}let u=this.roomId===null?t.full?"full":"":t.roomId===this.roomId?"full":"dim";this.pinMode.get(n)!==u&&(this.pinMode.set(n,u),n.classList.toggle("nf-dev-full",u==="full"),n.classList.toggle("nf-dev-dim",u==="dim")),this.labelPlacer.place(n,hl(c))}}reportStats(e,t){if(!this.statsOn||!this.options.onStats)return;let n=t.length>0;this.fpsStart||(this.fpsStart=e),this.lastStatsFrame&&n&&(this.worstFrame=Math.max(this.worstFrame,e-this.lastStatsFrame)),this.lastStatsFrame=n?e:0,this.fpsFrames++;let r=e-this.fpsStart;if(r>500||!n){let s=this.renderer.info.render;this.options.onStats({fps:n?Math.round(this.fpsFrames*1e3/r):0,busy:t,worstMs:Math.round(this.worstFrame),calls:s.calls,triangles:s.triangles,low:this.lowQuality,pixelRatio:this.renderer.getPixelRatio()}),this.fpsFrames=0,this.fpsStart=e,this.worstFrame=0}}};function EP(){let e=document.createElement("canvas");e.width=256*3,e.height=256*2;let t=e.getContext("2d"),n=(o,a,l,c,u)=>{t.strokeStyle=`rgba(55,224,255,${u})`,t.beginPath(),t.moveTo(o,a),t.lineTo(l,c),t.stroke()};t.lineWidth=1.5;let r=(o,a,l)=>{t.save(),t.beginPath(),t.rect(o*256,a*256,256,256),t.clip(),l(o*256,a*256),t.restore()};r(0,0,(o,a)=>{for(let l=0;l<5;l++){let c=a+l*256/5+.75;n(o,c,o+256,c,.09);let u=o+l*.37%1*256;n(u,c,u,c+256/5,.07)}}),r(1,0,(o,a)=>{for(let l=0;l<7;l++){let c=o+l*256/7+.75;n(c,a,c,a+256,.08);let u=a+l*.53%1*256;n(c,u,c+256/7,u,.06)}}),r(2,0,(o,a)=>{for(let l=0;l<4;l++){let c=l*256/4+.75;n(o+c,a,o+c,a+256,.1),n(o,a+c,o+256,a+c,.1)}}),r(1,1,(o,a)=>{for(let l=0;l<2;l++){let c=a+l*256/2+.75;n(o,c,o+256,c,.09);let u=l?256/4:0;for(let h of[u,u+256/2])n(o+h+.75,c,o+h+.75,c+256/2,.09)}}),r(2,1,(o,a)=>{n(o+.75,a,o+.75,a+256,.08),n(o,a+.75,o+256,a+.75,.08),t.fillStyle="rgba(55,224,255,0.05)";for(let l=0;l<90;l++)t.fillRect(o+l*97%256,a+(l*61+l*l%37)%256,2,2)});let s=new zt(e);return s.flipY=!1,s.wrapS=ln,s.wrapT=ln,s.anisotropy=4,s.colorSpace=ft,s}function RP(){let i=document.createElement("canvas");i.width=8,i.height=32;let e=i.getContext("2d");e.fillStyle="#1a2742",e.fillRect(0,0,8,32),e.fillStyle="#223556",e.fillRect(0,4,8,14),e.fillStyle="rgba(55,224,255,0.45)",e.fillRect(0,29,8,2);let t=new zt(i);return t.wrapS=kn,t.wrapT=kn,t.colorSpace=ft,t}function CP(i,e){let t=i.rooms.map((r,s)=>s),n=r=>t[r]===r?r:t[r]=n(t[r]);for(let[r,s]of e){let o=i.rooms.findIndex(u=>u.id===r),a=i.rooms.findIndex(u=>u.id===s);if(o<0||a<0)continue;let l=n(o),c=n(a);l!==c&&(t[Math.max(l,c)]=Math.min(l,c))}return t.map((r,s)=>n(s))}function PP(){let e=document.createElement("canvas");e.width=64,e.height=64;let t=e.getContext("2d"),n=t.createRadialGradient(64/2,64/2,0,64/2,64/2,64/2);n.addColorStop(0,"rgba(255,255,255,0.9)"),n.addColorStop(.2,"rgba(255,255,255,0.45)"),n.addColorStop(.55,"rgba(255,255,255,0.1)"),n.addColorStop(1,"rgba(255,255,255,0)"),t.fillStyle=n,t.fillRect(0,0,64,64);let r=new zt(e);return r.colorSpace=ft,r}function IP(){let e=Qm,t=document.createElement("canvas");t.width=1024,t.height=1024;let n=t.getContext("2d");n.strokeStyle="rgba(91,124,255,0.16)",n.lineWidth=1;for(let o=0;o<=e;o++){let a=Math.round(o/e*1024)+.5;n.beginPath(),n.moveTo(a,0),n.lineTo(a,1024),n.moveTo(0,a),n.lineTo(1024,a),n.stroke()}n.globalCompositeOperation="destination-in";let r=n.createRadialGradient(1024/2,1024/2,1024*.12,1024/2,1024/2,1024/2);r.addColorStop(0,"rgba(0,0,0,1)"),r.addColorStop(1,"rgba(0,0,0,0)"),n.fillStyle=r,n.fillRect(0,0,1024,1024);let s=new zt(t);return s.anisotropy=4,s.colorSpace=ft,s}function w5(i,e){return new e0(i,e)}function Jm(i,e,t,n){let[r,s,o]=e.size??Es[e.lamp],a=e.base??0,l=(e.rotation??0)*pt,c=Math.cos(l),u=Math.sin(l),h=(x,g)=>[e.x+x*c-g*u,e.z+x*u+g*c],f=(x,g,m,b,v,y=14)=>{let M=[];for(let S=0;STt(i,[h(x,m),h(g,m),h(g,b),h(x,b)],v,y,M,S,{aoFrom:0,bottom:!0}),p=Math.max(.05,Math.min(r,s)/2);switch(e.lamp){case"ceiling":f(p*.25,t-.04,t,$e,$e,8),f(p,t-Math.max(.04,o)-.035,t-.04,n,n);break;case"pendant":{let x=Math.max(.4,t-o);f(.06,t-.02,t,$e,$e,8);let g=e.variant==="globe"?x+2*p:e.variant==="drum"?x+.24:x+.2;if(f(.008,g,t-.02,$e,$e,5),e.variant==="globe")for(let b=0;b<7;b++){let v=Math.PI*(b/7),y=Math.PI*((b+1)/7);f(p*Math.max(.2,Math.sin((v+y)/2)),x+p-p*Math.cos(v),x+p-p*Math.cos(y),n,n,14)}else if(e.variant==="cone")for(let b=0;b<4;b++)f(p*(.25+.75*(4-b)/4),x+.06*b,x+.06*(b+1),n,n,16);else e.variant==="drum"?f(p,x,x+.24,n,n,18):(f(p*.35,x+.14,x+.2,n,n,12),f(p,x,x+.14,n,n,16));break}case"fan":{let x=Math.max(.05,t-Math.max(.22,o)),g=x+.16;f(.07,t-.05,t,$e,$e,10),g[e.x+w*M-R*S,e.z+w*S+R*M];Tt(i,[_(.1,-.035),_(m,-.075),_(m,.075),_(.1,.035)],b,b+.012,WM,WM,{aoFrom:0,bottom:!0})}break}case"downlight":f(p,t-.012,t,$e,$e,12),f(p*.7,t-.02,t-.012,n,n,12);break;case"spot":f(p*.6,t-.02,t,$e,$e,10),f(p,t-Math.max(.06,o),t-.02,$e,$e,12),f(p*.8,t-Math.max(.06,o)-.008,t-Math.max(.06,o),n,n,12);break;case"panel":d(-r/2,r/2,-s/2,s/2,t-Math.max(.015,o),t,$e,$e),d(-r/2+.02,r/2-.02,-s/2+.02,s/2-.02,t-Math.max(.015,o)-.004,t-Math.max(.015,o),n);break;case"uplight":f(Math.max(.1,p*.6),a,a+.03,$e,$e),f(.014,a+.03,a+o-.12,$e,$e,6),f(p,a+o-.14,a+o-.02,$e,$e),f(p*.92,a+o-.02,a+o,n,n);break;case"bollard":f(p,a,a+o-.14,$e,$e,10),f(p*.9,a+o-.14,a+o-.03,n,n,10),f(p*1.1,a+o-.03,a+o,$e,$e,10);break;case"garden":f(.012,a,a+o-.08,$e,$e,5),f(p,a+o-.08,a+o-.01,$e,$e,10),f(p*.8,a+o-.01,a+o,n,n,10);break;case"floor":f(Math.max(.1,p*.7),a,a+.03,$e,$e),f(.014,a+.03,a+o-.28,$e,$e,6),f(p,a+o-.3,a+o,n,n);break;case"table":f(Math.max(.05,p*.55),a,a+.03,$e,$e),f(.012,a+.03,a+o-.16,$e,$e,6),f(p,a+o-.18,a+o,n,n);break;case"wall":{let x=e.base??Fl;d(-r/2+.03,r/2-.03,-s/2,-s/2+.02,x,x+o,$e),d(-r/2,r/2,-s/2+.02,s/2,x+o*.15,x+o*.85,n);break}case"strip":{let x=Math.max(.02,o),g=e.base!=null?e.base+x:t-.04,m=e.upright?0:(e.rise??0)*pt;if(!e.roll&&!e.upright&&!m){d(-r/2,r/2,-s/2,s/2,g-x,g,n);break}let b=(e.roll??0)*pt,v=Math.cos(b),y=Math.sin(b),[M,S]=[Math.cos(m),Math.sin(m)],_=e.upright?a+r/2:g-x/2+Io(e.base,r,e.rise),w=(D,P,I)=>{let N=D,F=P*v-I*y,H=P*y+I*v;return e.upright?[N,F]=[-F,N]:m&&([N,F]=[N*M-F*S,N*S+F*M]),[e.x+N*c-H*u,_+F,e.z+N*u+H*c]},R=[w(-r/2,-x/2,-s/2),w(r/2,-x/2,-s/2),w(r/2,-x/2,s/2),w(-r/2,-x/2,s/2),w(-r/2,x/2,-s/2),w(r/2,x/2,-s/2),w(r/2,x/2,s/2),w(-r/2,x/2,s/2)],A=new W(n),C=[e.x,_,e.z],O=(D,P,I,N)=>{let[F,H,B]=[R[D],R[P],R[I]],X=[(H[1]-F[1])*(B[2]-F[2])-(H[2]-F[2])*(B[1]-F[1]),(H[2]-F[2])*(B[0]-F[0])-(H[0]-F[0])*(B[2]-F[2]),(H[0]-F[0])*(B[1]-F[1])-(H[1]-F[1])*(B[0]-F[0])],V=[F[0]-C[0],F[1]-C[1],F[2]-C[2]],re=X[0]*V[0]+X[1]*V[1]+X[2]*V[2]<0,[be,Y,Q,se]=re?[R[N],R[I],R[P],R[D]]:[R[D],R[P],R[I],R[N]];i.tri(be,Y,Q,A,A,A),i.tri(be,Q,se,A,A,A)};O(0,1,2,3),O(4,5,6,7),O(0,1,5,4),O(1,2,6,5),O(2,3,7,6),O(3,0,4,7);break}}}export{Bi as ModelError,e0 as NextFloorViewer,w5 as createViewer,MP as furniturePreview,xP as inspectModel,xb as isLowEnd,bP as prepareModel,yP as previewModel,Jm as pushLampModel}; +varying vec2 vNfTile;`).replace("#include ",xR)},e.customProgramCacheKey=()=>"nf-pattern",e}var qu=(i={})=>new Ke({vertexColors:!0,transparent:!0,blending:Ft,depthWrite:!1,...i});function Ty({mask:i,look:e,theme:t,textures:n}){let r=(o={})=>new Ke({vertexColors:!0,...o}),s=(o,a)=>My(o,i,a);return{floor:Zn(r(),e),pattern:bR(n.pattern),wall:Zn(s(r(),"solid"),e),glassWall:s(r({transparent:!0,depthWrite:!1}),"glass"),shadow:r({blending:za,premultipliedAlpha:!0,transparent:!0,depthWrite:!1,side:ut,polygonOffset:!0,polygonOffsetFactor:-1}),lines:Zn(s(new Lt({vertexColors:!0,transparent:!0,blending:xl(t),depthWrite:!1})),e,!0),glow:s(qu({side:ut,polygonOffset:!0,polygonOffsetFactor:-3}),"solid"),frames:Zn(s(r({side:ut})),e),glass:s(qu({side:ut})),blinds:Zn(s(r({map:n.blinds,side:ut})),e),lamps:Zn(r(),e),halos:new cn({map:n.halo,size:.9,sizeAttenuation:!0,vertexColors:!0,transparent:!0,blending:Ft,depthWrite:!1}),cones:qu({side:ut}),screens:qu({side:ut}),ghosts:[]}}var $u=i=>Object.assign(document.createElement("span"),{className:i});function Ay(i,e){let t=Object.assign(document.createElement("button"),{className:"nf-dev"});t.dataset.entity=i,t.append($u("nf-dev-icon"),$u("nf-dev-text"),$u("nf-dev-watt"),$u("nf-dev-name"));let n,r=!1,s=a=>{let{x:l,y:c}=e.centre(t);a(i,l,c)},o=()=>clearTimeout(n);t.addEventListener("pointerdown",a=>{if(e.furnishing())return e.pressedWhileFurnishing(i);a.stopPropagation(),r=!1,o(),n=setTimeout(()=>{r=!0,s(e.hold)},500)});for(let a of["pointerleave","pointercancel","pointerup"])t.addEventListener(a,o);return t.addEventListener("contextmenu",a=>a.preventDefault()),t.addEventListener("click",a=>{if(a.stopPropagation(),e.furnishing())return e.selectWhileFurnishing(i);r||s(e.tap)}),t.addEventListener("keydown",a=>{(a.key==="Enter"&&a.shiftKey||a.key==="ContextMenu")&&(a.preventDefault(),s(e.hold))}),t}function Ey(i,e=10,t="NextFloor"){let n=[];for(let{positions:o,lift:a}of i)for(let l=0;l+8[o[l+x]*e,-o[l+x+2]*e,(o[l+x+1]+a)*e]),[u,h,f]=c,d=[(h[1]-u[1])*(f[2]-u[2])-(h[2]-u[2])*(f[1]-u[1]),(h[2]-u[2])*(f[0]-u[0])-(h[0]-u[0])*(f[2]-u[2]),(h[0]-u[0])*(f[1]-u[1])-(h[1]-u[1])*(f[0]-u[0])],p=Math.hypot(d[0],d[1],d[2]);p<1e-9||n.push([d[0]/p,d[1]/p,d[2]/p,...u,...h,...f])}let r=new Uint8Array(84+n.length*50),s=new DataView(r.buffer);return r.set(new TextEncoder().encode(`${t} STL`.slice(0,79)),0),s.setUint32(80,n.length,!0),n.forEach((o,a)=>{let l=84+a*50;o.forEach((c,u)=>s.setFloat32(l+u*4,c,!0))}),r}var Rs=Math.PI/180;function Ry(i,e,t){let n=i.getTime()/864e5-10957.5,r=(357.529+.98560028*n)*Rs,o=(280.459+.98564736*n+1.915*Math.sin(r)+.02*Math.sin(2*r))*Rs,a=(23.439-36e-8*n)*Rs,l=Math.atan2(Math.cos(a)*Math.sin(o),Math.cos(o)),c=Math.asin(Math.sin(a)*Math.sin(o)),h=(((18.697374558+24.06570982441908*n)%24+24)%24*15+t)*Rs-l,f=e*Rs,d=Math.asin(Math.sin(f)*Math.sin(c)+Math.cos(f)*Math.cos(c)*Math.cos(h)),p=Math.atan2(Math.sin(h),Math.cos(h)*Math.sin(f)-Math.tan(c)*Math.cos(f))/Rs+180;return{elevation:d/Rs,azimuth:(p%360+360)%360}}function fp(i,e){let t=Object.fromEntries(new Intl.DateTimeFormat("en-US",{timeZone:e,hourCycle:"h23",year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric"}).formatToParts(new Date(i)).map(n=>[n.type,Number(n.value)]));return Date.UTC(t.year,t.month-1,t.day,t.hour,t.minute,t.second)}function Cy(i,e,t=new Date){let[n,r]=[Math.floor(i),Math.round(i%1*60)];if(e)try{let o=new Date(fp(t.getTime(),e)),a=Date.UTC(o.getUTCFullYear(),o.getUTCMonth(),o.getUTCDate(),n,r),l=a-(fp(a,e)-a);return l=a-(fp(l,e)-l),new Date(l)}catch{}let s=new Date(t);return s.setHours(n,r,0,0),s}function yR(i,e=new Date){let t=[];for(let n=0;n<=24;n+=.25){let r=Ry(Cy(Math.min(n,23.99),i.zone,e),i.latitude,i.longitude);r.elevation<0||t.push(Py(i,r))}return t}function Py(i,e){let[t,n]=Lo(e.azimuth,i.north),r=Math.max(0,e.elevation)*Math.PI/180;return[i.centre[0]+t*i.radius*Math.cos(r),Math.sin(r)*i.radius*.9,i.centre[1]+n*i.radius*Math.cos(r)]}function _R(i,e){let t=document.createElement("canvas");t.width=t.height=64;let n=t.getContext("2d");n&&(n.font="bold 44px system-ui, sans-serif",n.fillStyle=e,n.textAlign="center",n.textBaseline="middle",n.fillText(i,32,34));let r=new ji(new vi({map:new zt(t),transparent:!0,depthWrite:!1,depthTest:!1}));return r.renderOrder=20,r}var Ku=class{group=new ct;key="";constructor(){this.group.visible=!1,this.group.renderOrder=15}update(e,t,n){let r=e?`${e.centre},${e.radius.toFixed(1)},${e.north},${e.latitude.toFixed(2)},${e.longitude.toFixed(2)},${new Date().toDateString()},${n},${t?`${t.elevation.toFixed(0)},${t.azimuth.toFixed(0)}`:"-"}`:"off";if(r===this.key)return;if(this.key=r,this.clear(),!e){this.group.visible=!1;return}this.group.visible=!0;let s=n+.05,o=[];for(let h=0;h<=96;h++){let f=h/96*Math.PI*2;o.push(e.centre[0]+Math.cos(f)*e.radius,s,e.centre[1]+Math.sin(f)*e.radius)}let a=new Fe;a.setAttribute("position",new ke(o,3)),this.group.add(new Pn(a,new Lt({color:7311304,transparent:!0,opacity:.55,depthWrite:!1})));let l=[];[["N",0],["E",90],["S",180],["W",270]].forEach(([h,f])=>{let[d,p]=Lo(f,e.north);l.push(e.centre[0]+d*e.radius*.94,s,e.centre[1]+p*e.radius*.94,e.centre[0]+d*e.radius*1.04,s,e.centre[1]+p*e.radius*1.04);let x=_R(h,h==="N"?"#ff6b6b":"#9fb4d8");x.position.set(e.centre[0]+d*e.radius*1.12,s+.4,e.centre[1]+p*e.radius*1.12),x.scale.setScalar(Math.max(1.2,e.radius*.12)),this.group.add(x)});let c=new Fe;c.setAttribute("position",new ke(l,3)),this.group.add(new gn(c,new Lt({color:10466520,transparent:!0,opacity:.8,depthWrite:!1})));let u=yR(e).map(([h,f,d])=>[h,n+f,d]);if(u.length>1){let h=new Fe;h.setAttribute("position",new ke(u.flat(),3)),this.group.add(new Pn(h,new Lt({color:16761415,transparent:!0,opacity:.85,depthWrite:!1})))}if(t&&t.elevation>0){let[h,f,d]=Py(e,t),p=new we(new Ca(Math.max(.35,e.radius*.035),12,8),new Ke({color:16765530}));p.position.set(h,n+f,d),this.group.add(p)}}clear(){for(let e of[...this.group.children]){this.group.remove(e);let t=e;t.geometry?.dispose();let n=t.material;n?.map?.dispose(),n?.dispose()}}dispose(){this.clear()}};var vR=["straight","quarter","l","half","u","spiral"],MR=["solid","stringer","mono","cantilever"],SR=["none","left","right","both"],wR=["headroom","full","none"],Zu={shape:"straight",turn:"right",build:"solid",risers:!0,steps:null,run_width:null,down:!1,rail:"none",opening:"headroom",landing_after:null};var Ny=2,Dy=40,TR=2.2,Ju=(i,e)=>typeof e=="string"&&i.includes(e);function dp(i){let e=i.stair??{},t=typeof e.steps=="number"&&Number.isFinite(e.steps)?Math.round(Math.min(Dy,Math.max(Ny,e.steps))):null,n=typeof e.run_width=="number"&&Number.isFinite(e.run_width)&&e.run_width>.2?e.run_width:null;return{shape:Ju(vR,e.shape)?e.shape:Zu.shape,turn:e.turn==="left"?"left":"right",build:Ju(MR,e.build)?e.build:Zu.build,risers:e.risers!==!1,steps:t,run_width:n,down:e.down===!0,rail:Ju(SR,e.rail)?e.rail:Zu.rail,opening:Ju(wR,e.opening)?e.opening:Zu.opening,landing_after:typeof e.landing_after=="number"&&Number.isFinite(e.landing_after)?Math.max(1,Math.round(e.landing_after)):null}}var Qu=i=>i.type==="stairs"&&!!i.stair,yl=(i,e,t)=>[i[0]+(e[0]-i[0])*t,i[1]+(e[1]-i[1])*t],Iy=(i,e)=>Math.abs(i[0]-e[0])<1e-6&&Math.abs(i[1]-e[1])<1e-6;function Uy(i){let e=[];for(let t of i)(!e.length||!Iy(e[e.length-1],t))&&e.push(t);for(;e.length>1&&Iy(e[0],e[e.length-1]);)e.pop();return e}function _l(i,e,t=!1){return{poly:Uy([...i,...[...e].reverse()]),landing:t,left:i,right:e}}function bl(i,e,t,n,r){let s=[];for(let o=0;oe+1e-6&&ri.reduce((e,t,n)=>n?e+Math.hypot(t[0]-i[n-1][0],t[1]-i[n-1][1]):e,0);function Fy(i,e,t,n,r){let s=ER(i),o=[];for(let a=0;a=8?3:2),[f,d]=i.shape==="l"?Oy(i,n)??ju(n-h,t-l,e-l):ju(n-h,t-l,e-l),p=bl([r,a],[r+l,a],[r,o+l],c,f),x=i.shape==="l"?[_l(u,[c],!0)]:Fy(u,c,c,c,h),g=bl([r+l,o],c,[s,o],[s,o+l],d);return{treads:[...p,...x,...g],flight:l,column:0}}case"half":case"u":{let l=Math.min(i.run_width??Math.min(1.1,(e-.1)/2),(e-.02)/2),c=o+l,u=[[r,c],[r,o],[s,o],[s,c]],[h,f]=[[r+l,c],[s-l,c]],d=i.shape==="u"?1:Math.min(n,n>=12?6:n>=8?4:2),[p,x]=i.shape==="u"?Oy(i,n)??ju(n-d,t-l,t-l):ju(n-d,t-l,t-l),g=bl([r,a],[r+l,a],[r,c],h,p),m=i.shape==="u"?[_l(u,[h,f],!0)]:Fy(u,h,[0,c],f,d),b=bl([s,c],f,[s,a],[s-l,a],x);return{treads:[...g,...m,...b],flight:l,column:0}}case"spiral":{let l=Math.min(e,t)/2,c=Math.min(.08,l*.12),u=Math.min(.75,Math.max(.3,.22/(l*.6))),h=(d,p)=>[Math.cos(p)*d,Math.sin(p)*d],f=[];for(let d=0;dh(l,p+(x-p)*m));f.push(_l(g,[h(c,p),h(c,x)]))}return{treads:f,flight:l-c,column:c}}default:return{treads:bl([r,a],[s,a],[r,o],[s,o],n),flight:e,column:0}}}var CR=(i,e)=>i.steps??Math.min(Dy,Math.max(Ny,Math.round(Math.abs(e)/.18)));function pp(i,e,t,n){let r=CR(i,n),s=Math.abs(n)/r,o=RR(i,Math.max(.3,e),Math.max(.3,t),r),a=c=>[-c[0],c[1]];return{treads:o.treads.map((c,u)=>{let h=i.down?-s*(u+1):s*(u+1);return i.turn==="right"?{...c,top:h}:{poly:c.poly.map(a).reverse(),top:h,landing:c.landing,left:c.right.map(a),right:c.left.map(a)}}),rise:s,steps:r,column:o.column,flight:o.flight}}function By(i){let e=i.poly.reduce((t,n)=>[t[0]+n[0],t[1]+n[1]],[0,0]);return[e[0]/i.poly.length,e[1]/i.poly.length]}function PR(i,e,t,n="headroom"){if(n==="none")return[];let r=t?0:Math.abs(e),s=n==="full"?i.treads:i.treads.filter((o,a)=>o.top>r-TR||!t&&a===i.treads.length-1||t&&a===0);return fr(s.map(o=>o.poly).filter(o=>o.length>=3))}function mp(i){let e=dp(i),t=PR(pp(e,i.w,i.d,i.h),i.h,e.down,e.opening),n=i.rotation*Math.PI/180,[r,s]=[Math.cos(n),Math.sin(n)],o=i.mirror?-1:1;return t.map(a=>a.map(([l,c])=>[i.x+o*l*r-c*s,i.z+o*l*s+c*r]))}function Ni(i,e,t,n,r,s,o=Pe.metal,a=!1){let[l,c]=[e/2-s-r,t/2-s-r],u=mt(o);for(let h of[-1,1])for(let f of[-1,1]){let[d,p]=[h*l,f*c];a?i.loft([d-r*.3,d+r*.3,p-r*.3,p+r*.3],[d-r/2,d+r/2,p-r/2,p+r/2],0,n,u):i.block({x:[d-r/2,d+r/2],y:[0,n],z:[p-r/2,p+r/2]},u)}}function Cs(i,e,t,n,r,s,o,a=null,l=!1){let c=(t-e)/o;for(let u=1;u1?h+(u%2?-c/2+.06:c/2-.06):h+c/2-.06;i.seg(d,f-.08,s+.012,d,f+.08,s+.012,qe)}}}function fi(i,e,t,n,r,s=null,o=!1,a=Z.body){i.block({x:[-e/2,e/2],y:[.02,n],z:[-t/2,t/2-.02]},a,pe),i.block({x:[-e/2+.02,e/2-.02],y:[0,.08],z:[-t/2+.02,t/2-.06]},mt(Pe.dark)),Cs(i,-e/2,e/2,.08,n,t/2-.02,r,s,o)}function gp(i,e,t,n,r){let[s,o,a,l]=[-e/2,e/2,-t/2,t/2],c=Math.min(.2,e*.12),u=n*.5,h=Math.min(.24,t*.28);Ni(i,e,t,.07,.05,.05,Pe.wood,!0),i.pad({x:[s,o],y:[.07,u-.08],z:[a+.02,l]},Z.fabric,.04,pe),i.loft([s,o,a,a+h],[s+.01,o-.01,a,a+h*.5],u-.08,n,Z.fabric,pe);for(let[d,p]of[[s,s+c],[o-c,o]])i.pad({x:[d,p],y:[u-.08,n*.72],z:[a+.02,l-.02]},Z.fabric,.04,pe);let f=(o-c-(s+c))/r;for(let d=0;d1.2?2:1,f=(e-.2)/h;for(let d=0;d0?.05:0),o*(e/2)+(o<0?.05:0)],y:[0,n],z:[a*(t/2)-(a>0?.05:0),a*(t/2)+(a<0?.05:0)]},Z.wood);for(let o of[.25,n-.55])i.block({x:[-e/2,e/2],y:[o,o+.08],z:[-t/2,t/2]},Z.wood,pe),i.block({x:[-e/2+.04,e/2-.04],y:[o+.08,o+.24],z:[-t/2+.05,t/2-.05]},Z.bedding,Je),i.block({x:[-e/2+.05,e/2-.05],y:[o+.24,o+.33],z:[-t/2+.08,-t/2+.4]},Z.pillow);i.block({x:[-e/2,e/2],y:[n-.2,n-.15],z:[t/2-.05,t/2]},Z.wood);let s=e/2-.35;for(let o of[s-.18,s+.18])i.seg(o,0,t/2+.02,o,n-.15,t/2+.02,pe);for(let o=.3;oi.block({x:[-e/2,e/2],y:[n-.04,n],z:[-t/2,t/2]},Z.worktop,pe);function Yy(i,e,t,n){fi(i,e,t-.02,n-.04,Math.max(1,Math.round(e/.6)),n-.2),yp(i,e,t,n)}function qy(i,e,t,n){i.block({x:[-e/2,e/2],y:[Math.max(0,n-.04),n],z:[-t/2,t/2]},Z.worktop,pe)}function $y(i,e,t,n){i.block({x:[-e/2,e/2],y:[0,n],z:[-t/2,t/2]},Z.white,pe);let r=n*.62;i.seg(-e/2,r,t/2,e/2,r,t/2,Je);let s=e/2-.06;i.seg(s,r+.08,t/2+.015,s,r+.4,t/2+.015,qe),i.seg(s,r-.4,t/2+.015,s,r-.08,t/2+.015,qe)}var _p=.06;function Ky(i,e,t,n){let r=t/2-_p;i.block({x:[-e/2,e/2],y:[.02,n],z:[-t/2,r]},Z.body,pe),i.block({x:[-e/2+.05,e/2-.05],y:[0,.02],z:[-t/2+.05,r-.05]},Z.dark);for(let s of[.35,.7,1.05,1.4])s>n-.15||(i.seg(-e/2+.03,s,r+.001,-.03,s,r+.001,Je),i.seg(.03,s,r+.001,e/2-.03,s,r+.001,Je))}var bp=1.83;function IR(i,e,t,n,r){let[s,o]=[Math.cos(e.rotation*pt),Math.sin(e.rotation*pt)],a=e.mirror?-1:1,l=(b,v)=>[e.x+a*b*s-v*o,e.z+a*b*o+v*s],[c,u]=[t+.05,t+e.h-.02],h=new W(.75,.1,.14),f=new W(Pe.dark),d=new W(Pe.accent),p=e.w/2-.006,x=(b,v,y)=>{let M=y/bp,S=new W(2043212).lerp(h,M),_=new W(Pe.body).lerp(h,M*.8),[w,R]=[Math.cos(y),Math.sin(y)],A=(D,P)=>l(b+v*(D*w-P*R),e.d/2+D*R+P*w),C=(D,P,I,N)=>{let[F,H,B,X]=D;i.tri([F[0],P,F[1]],[H[0],P,H[1]],[B[0],I,B[1]],N),i.tri([F[0],P,F[1]],[B[0],I,B[1]],[X[0],I,X[1]],N)},O=(D,P,I,N,F,H,B,X=B)=>{let V=[A(D,H),A(P,H),A(P,F),A(D,F)];C([V[0],V[1],V[1],V[0]],I,N,X),C([V[3],V[2],V[2],V[3]],I,N,B),C([V[0],V[3],V[3],V[0]],I,N,B),C([V[1],V[2],V[2],V[1]],I,N,B),C([V[0],V[1],V[2],V[3]],N,N,B),C([V[3],V[2],V[1],V[0]],I,I,B)};return O(0,p,c,u,-_p,0,_,S),O(p-.05,p-.03,t+e.h*.45,t+e.h*.75,.005,.025,d),O};x(-e.w/2,1,n*bp)(.12,.3,t+e.h*.5,t+e.h*.68,.001,.005,f),x(e.w/2,-1,r*bp)(.06,p-.06,t+e.h*.52,t+e.h*.86,.001,.005,f)}function vp(i,e,t,n,r){let s=i.p.length;IR(i,e,t,n,r),e.mirror&&vs(i,s)}function Zy(i,e,t,n){fi(i,e,t-.02,n-.04,1,n-.24,!0),i.block({x:[-e/2,e/2],y:[n-.04,n],z:[-t/2,t/2]},Z.dark,pe);let r=[[-.14,-.13,.09],[.14,-.13,.07],[-.14,.13,.07],[.14,.13,.09]];for(let[s,o,a]of r)i.cylinder(s*e/.6,o*t/.62,a,n,n+.004,mt(Pe.dark,1451583),12,qe)}function Jy(i,e,t,n){fi(i,e,t-.02,n-.04,Math.max(1,Math.round(e/.45)),n-.2);let r=Math.min(.5,e-.2),s=(o,a,l,c,u=!1)=>i.block({x:[o,a],y:[n-.04,n],z:[l,c]},Z.worktop,u?pe:null);s(-e/2,-r/2,-t/2,t/2,!0),s(r/2,e/2,-t/2,t/2,!0),s(-r/2,r/2,-t/2,-t/2+.1),s(-r/2,r/2,t/2-.08,t/2),i.block({x:[-r/2,r/2],y:[n-.2,n-.17],z:[-t/2+.1,t/2-.08]},Z.metal,qe),i.cylinder(0,-t/2+.05,.02,n,n+.28,Z.metal,8),i.block({x:[-.015,.015],y:[n+.24,n+.28],z:[-t/2+.05,-t/2+.22]},Z.metal)}function jy(i,e,t,n){i.block({x:[-e/2,e/2],y:[1.45,1.45+n],z:[-t/2,t/2-.02]},Z.body,pe),Cs(i,-e/2,e/2,1.45,1.45+n,t/2-.02,Math.max(1,Math.round(e/.5)),1.45+.08)}function Qy(i,e,t,n){i.block({x:[-e/2,e/2],y:[.02,n],z:[-t/2,t/2-.02]},Z.body,pe),i.block({x:[-e/2+.02,e/2-.02],y:[0,.08],z:[-t/2+.02,t/2-.06]},Z.dark);let r=t/2-.02;i.block({x:[-e/2+.03,e/2-.03],y:[.85,1.45],z:[r,r+.01]},Z.dark,qe),i.seg(-e/2+.08,1.4,r+.02,e/2-.08,1.4,r+.02,qe);for(let s of[.85,1.45])i.seg(-e/2,s,r,e/2,s,r,Je);i.seg(e/2-.06,.5,r+.012,e/2-.06,.7,r+.012,qe),i.seg(e/2-.06,1.6,r+.012,e/2-.06,1.8,r+.012,qe)}function e_(i,e,t,n){let r=t-.3;i.block({x:[-e/2+.05,e/2-.05],y:[.08,n-.04],z:[-t/2+.02,-t/2+r]},Z.body,pe),i.block({x:[-e/2+.07,e/2-.07],y:[0,.08],z:[-t/2+.04,-t/2+r-.04]},Z.dark),Cs(i,-e/2+.05,e/2-.05,.08,n-.04,-t/2+r,Math.max(2,Math.round(e/.6)),n-.2),yp(i,e,t,n)}function t_(i,e,t,n){i.block({x:[-e/2,e/2],y:[.02,n-.04],z:[-t/2,t/2-.02]},Z.body,pe),i.block({x:[-e/2+.02,e/2-.02],y:[0,.08],z:[-t/2+.02,t/2-.06]},Z.dark),i.seg(-e/2+.08,n-.12,t/2-.008,e/2-.08,n-.12,t/2-.008,qe),yp(i,e,t,n)}function Mp(i,e,t,n,r){i.block({x:[-e/2,e/2],y:[0,n],z:[-t/2,t/2-.02]},Z.white,pe);let s=t/2-.012;i.seg(-e/2,n-.14,s,e/2,n-.14,s,Je),i.seg(e/2-.16,n-.07,s,e/2-.08,n-.07,s,qe);let o=(n-.14)/2+.04,a=Math.min(e*.36,(n-.2)*.42),l=20;for(let c=0;ci.seg(Math.cos(u)*a*d,o+Math.sin(u)*a*d,s,Math.cos(h)*a*d,o+Math.sin(h)*a*d,s,p);f(1,qe),r||f(.72,Je)}}function n_(i,e,t,n){i.block({x:[-e/2,e/2],y:[0,n-.02],z:[-t/2,t/2]},Z.white,pe);let s=(o,a,l,c)=>i.block({x:[o,a],y:[n-.02,n],z:[l,c]},Z.worktop);s(-e/2,e/2,-t/2,-t/2+.07),s(-e/2,e/2,t/2-.07,t/2),s(-e/2,-e/2+.07,-t/2+.07,t/2-.07),s(e/2-.07,e/2,-t/2+.07,t/2-.07),i.block({x:[-e/2+.07,e/2-.07],y:[n-.03,n-.02],z:[-t/2+.07,t/2-.07]},Z.glass,qe),i.cylinder(-e/2+.04,0,.02,n,n+.12,Z.metal,8)}function i_(i,e,t,n){i.block({x:[-e/2,e/2],y:[0,.05],z:[-t/2,t/2]},Z.worktop,pe),i.cylinder(0,0,.04,.05,.052,Z.metal,8);for(let[r,s,o,a]of[[-e/2,t/2,e/2,t/2],[e/2,-t/2,e/2,t/2]])i.seg(r,.05,s,o,.05,a,qe),i.seg(r,n,s,o,n,a,qe),i.seg(o,.05,a,o,n,a,qe);i.cylinder(-e/2+.06,-t/2+.06,.015,.05,n-.05,Z.metal,6),i.cylinder(-e/2+.2,-t/2+.2,.1,n-.08,n-.06,Z.metal,12,qe)}function r_(i,e,t,n){let r=Math.min(.18,t*.3);i.block({x:[-e/2,e/2],y:[.45,n],z:[-t/2,-t/2+r]},Z.white,pe),i.block({x:[-e*.3,e*.3],y:[0,.36],z:[-t/2+r-.02,t/2-.12]},Z.white),i.cylinder(0,t/2-.26,Math.min(e/2,.19),.36,.41,Z.white,12,pe),i.block({x:[-e/2+.02,e/2-.02],y:[.41,.43],z:[-t/2+r,-t/2+r+.05]},Z.worktop)}function s_(i,e,t,n){fi(i,e,t-.02,n-.12,e>.8?2:1,n-.3),i.block({x:[-e/2,e/2],y:[n-.12,n],z:[-t/2,t/2]},Z.white,pe),i.block({x:[-e/2+.07,e/2-.07],y:[n-.005,n],z:[-t/2+.12,t/2-.06]},Z.glass,qe),i.cylinder(0,-t/2+.06,.018,n,n+.2,Z.metal,8),i.block({x:[-e/2+.04,e/2-.04],y:[n+.35,n+1],z:[-t/2,-t/2+.02]},Z.glass,qe)}var vl=.12;function o_(i,e,t,n){let r=vl;i.block({x:[-e/2+.05,-e/2+.08],y:[0,r],z:[-t/2,-t/2+.03]},Z.metal),i.block({x:[e/2-.08,e/2-.05],y:[0,r],z:[-t/2,-t/2+.03]},Z.metal),i.block({x:[-e/2,e/2],y:[r,r+n],z:[-t/2+.02,t/2]},Z.white,pe);let s=Math.max(3,Math.round(e/.1));for(let o=1;oi.block({x:[-e/2,e/2],y:[1.1,1.1+n],z:[-t/2,t/2]},l,pe);if(r==="slim"){a(Z.darkBody),i.seg(-e*.25,1.1+n*.15,o+.004,-e*.25,1.1+n*.85,o+.004,qe),i.block({x:[-e*.1,e*.3],y:[1.1+n*.7,1.1+n*.85],z:[o,o+.005]},Z.dark);return}if(a(Z.white),r==="hybrid"){i.ring(0,1.1+n*.66,Math.min(e,n)*.22,o+.004,20,qe),i.seg(-e*.08,1.1+n*.66,o+.005,e*.08,1.1+n*.66,o+.005,qe);for(let l of[-1,1])i.ring(l*e*.22,1.1+n*.2,Math.min(e,n)*.1,-t/2-.002,12,qe);return}i.block({x:[-e*.28,e*.28],y:[1.1+n*.58,1.1+n*.82],z:[t/2,t/2+.006]},Z.dark),i.seg(-e*.3,1.1+n*.45,t/2+.004,e*.3,1.1+n*.45,t/2+.004,qe);for(let l of[-1,1])for(let c=1;c<6;c++)i.seg(l*e/2+l*.002,1.1+n*c/6,-t/2+.03,l*e/2+l*.002,1.1+n*c/6,t/2-.03,Je)}function M_(i,e,t,n){i.block({x:[-e/2,e/2],y:[0,n],z:[-t/2,t/2]},Z.darkBody,pe),i.block({x:[-e/2-.01,e/2+.01],y:[n,n+.03],z:[-t/2-.01,t/2+.01]},Z.darkBody),i.seg(-e/2,n+.032,t/2+.01,e/2,n+.032,t/2+.01,qe),i.seg(-e*.3,n*.55,t/2+.003,e*.3,n*.55,t/2+.003,Je)}function S_(i,e,t,n){i.block({x:[-e/2,e/2],y:[1,1+n],z:[-t/2,t/2]},Z.darkBody,pe),i.ring(0,1+n*.58,Math.min(e,n)*.28,t/2+.003,16,qe),i.block({x:[-.015,.015],y:[1-.35,1],z:[t/2-.03,t/2]},Z.dark),i.block({x:[-.06,.06],y:[1-.42,1-.35],z:[t/2-.05,t/2]},Z.darkBody)}function w_(i,e,t,n){i.block({x:[-e/2,e/2],y:[.4,.4+n],z:[-t/2,t/2]},Z.white,pe),i.seg(-e/2+.025,.4+.025,t/2+.003,-e/2+.025,.4+n-.025,t/2+.003,Je),i.seg(-e/2+.025,.4+n-.025,t/2+.003,e/2-.025,.4+n-.025,t/2+.003,Je),i.block({x:[e/2-.06,e/2-.035],y:[.4+n*.5-.05,.4+n*.5+.05],z:[t/2,t/2+.012]},Z.dark),i.block({x:[-e*.3,e*.3],y:[.4+n*.6,.4+n*.8],z:[t/2,t/2+.005]},Z.dark),i.seg(-e*.22,.4+n*.7,t/2+.008,e*.22,.4+n*.7,t/2+.008,qe)}function T_(i,e,t,n,r){if(r==="wall"){i.block({x:[-e/2,e/2],y:[.5,.5+n],z:[-t/2,t/2]},Z.white,pe),i.seg(-e*.3,.5+n*.9,t/2+.004,e*.3,.5+n*.9,t/2+.004,qe),i.seg(-e*.3,.5+n*.08,t/2+.003,e*.3,.5+n*.08,t/2+.003,Je);return}if(r==="cube"){i.block({x:[-e/2+.01,e/2-.01],y:[0,.03],z:[-t/2+.01,t/2-.01]},Z.dark),i.block({x:[-e/2,e/2],y:[.03,n],z:[-t/2,t/2]},Z.darkBody,pe),i.seg(-e*.35,n*.85,t/2+.004,e*.35,n*.85,t/2+.004,qe),i.block({x:[-e*.15,e*.15],y:[n,n+.025],z:[-.012,.012]},Z.dark);return}i.block({x:[-e/2+.02,e/2-.02],y:[0,.06],z:[-t/2+.02,t/2-.02]},Z.dark);let s=Math.max(2,Math.round((n-.06)/.3)),o=(n-.06)/s;for(let a=0;a[x[0]+h*g,x[1]+f*g];i.prism([e,t,p(t,o),p(e,o)],r,s,a,Je)}var LR=i=>i.slice(1).map((e,t)=>[i[t],e]).filter(([e,t])=>Math.hypot(t[0]-e[0],t[1]-e[1])>.01);function FR(i,e,t,n,r){let s=e.build==="cantilever"?.07:.05;t.forEach((o,a)=>{let l=By(o),c=a===0?0:t[a-1].top;if(e.build==="solid"){i.prism(o.poly,Math.min(r,o.top),o.top,Z.body,pe);return}if(i.prism(o.poly,o.top-s,o.top,Z.wood,pe),e.risers&&!o.landing){let[u,h]=[Math.min(c,o.top),Math.max(c,o.top)-s];A_(i,o.left[0],o.right[0],l,u,h,.02)}if(e.build==="stringer")for(let u of[o.left,o.right])for(let[h,f]of LR(u))A_(i,h,f,l,o.top-n-.2,o.top+.05,.04);else e.build==="mono"&&i.block({x:[l[0]-.07,l[0]+.07],y:[o.top-n-.12,o.top-s],z:[l[1]-.07,l[1]+.07]},Z.metal)})}function OR(i,e,t){let n=e.rail==="both"?["left","right"]:e.rail==="none"?[]:[e.rail];for(let r of n){let s=[];for(let o of t)for(let a of o[r])s.push([a[0],o.top+eh,a[1]]);for(let[o,a]of t.entries()){if(o%2&&o!==t.length-1)continue;let l=a[r][0];i.cylinder(l[0],l[1],.012,a.top,a.top+eh,Z.metal,6)}for(let o=1;o0&&i.cylinder(0,0,o.column,Math.min(0,a),s.down?0:r,Z.metal,12,pe),FR(i,s,o.treads,o.rise,a),OR(i,s,o.treads)}function NR(i,e,t,n,r,s){switch(e.type){case"sofa":return e.variant==="l"||e.variant==="u"?ky(i,t,n,r,e.variant):gp(i,t,n,r,Math.max(1,Math.round((t-.4)/.62))),"yes";case"armchair":return gp(i,t,n,r,1),"yes";case"bed":return zy(i,t,n,r),"yes";case"chair":return Vy(i,t,n,r),"yes";case"table":return a_(i,t,n,r),"yes";case"desk":return u_(i,t,n,r),"yes";case"nightstand":return h_(i,t,n,r),"yes";case"wardrobe":return fi(i,t,n,r,Math.max(2,Math.round(t/.5)),r*.5),"yes";case"tall_cabinet":return fi(i,t,n,r,1,r*.5),"yes";case"shelf":return f_(i,t,n,r),"yes";case"kitchen":return Yy(i,t,n,r),"yes";case"fridge":return $y(i,t,n,r),"yes";case"fridge_smart":return Ky(i,t,n,r),"yes";case"stove":return Zy(i,t,n,r),"yes";case"sink":return Jy(i,t,n,r),"yes";case"bathtub":return n_(i,t,n,r),"yes";case"shower":return i_(i,t,n,r),"yes";case"wc":return r_(i,t,n,r),"yes";case"washbasin":return s_(i,t,n,r),"yes";case"tv_board":return y_(i,t,n,r,e.ambilight===0?pe:void 0),"yes";case"plant":return g_(i,t,n,r),"yes";case"rug":return x_(i,t,n),"no";case"stairs":return e.stair?(E_(i,e,t,n,r),e.stair.down?"no":"yes"):(b_(i,t,n,r),"yes");case"stairwell":return"no";case"sideboard":return d_(i,t,n,r),"yes";case"dresser":return p_(i,t,n,r),"yes";case"coat_rack":return m_(i,t,n,r),"yes";case"bench":return xp(i,t,n,r,!1),"yes";case"corner_bench":return xp(i,t,n,r,!0),"yes";case"bar_stool":return Gy(i,t,n,r),"yes";case"office_chair":return Hy(i,t,n,r),"yes";case"stool":return Wy(i,t,n,r),"yes";case"kitchen_wall":return jy(i,t,n,r),"no";case"kitchen_tall":return Qy(i,t,n,r),"yes";case"island":return e_(i,t,n,r),"yes";case"worktop":return qy(i,t,n,r),"no";case"dishwasher":return t_(i,t,n,r),"yes";case"washer":return Mp(i,t,n,r,!1),"yes";case"dryer":return Mp(i,t,n,r,!0),"yes";case"bunk_bed":return Xy(i,t,n,r),"yes";case"table_round":return l_(i,t,n,r),"yes";case"coffee_table":return c_(i,t,n,r),"yes";case"tv_wall":return __(i,t,n,r,e.ambilight===0?pe:void 0),"no";case"parking":{let a=[[-t/2,-n/2],[t/2,-n/2],[t/2,n/2],[-t/2,n/2]];return a.forEach(([l,c],u)=>i.seg(l,.012,c,a[(u+1)%4][0],.012,a[(u+1)%4][1],Je)),i.seg(-t*.15,.012,n/2-.45,0,.012,n/2-.2,pe),i.seg(0,.012,n/2-.2,t*.15,.012,n/2-.45,pe),"no"}case"robot_vacuum":return i.block({x:[-t*.45,t*.45],y:[0,r],z:[-n/2,-n/2+n*.3]},Z.white,pe),i.block({x:[-t*.2,t*.2],y:[r*.5,r*.62],z:[-n/2+n*.3,-n/2+n*.31]},Z.accent),"no";case"radiator":return o_(i,t,n,r),"no";case"inverter":return v_(i,t,n,r,e.variant??null),"no";case"grid_point":return M_(i,t,n,r),"yes";case"wallbox":return S_(i,t,n,r),"no";case"meter":return w_(i,t,n,r),"no";case"home_battery":return T_(i,t,n,r,e.variant??null),e.variant==="wall"?"no":"yes";default:{let o=vt(e.type);return o?o.pet?"no":(Ms(i,o,t,n,r,s,null,null,e.variant??null),s>.05?"no":"yes"):(i.block({x:[-t/2,t/2],y:[0,r],z:[-n/2,n/2]},Z.body,pe),"yes")}}}function R_(i,e,t,n,r){let s=Ss(n),o=new Li(i,e,s),[a,l,c]=[Math.max(.05,n.w),Math.max(.05,n.d),Math.max(.005,n.h)];NR(o,n,a,l,c,r)==="yes"&&pb(t,s,a,l,n.type==="plant"?.35:.5)}function C_(i,e,t){let[n,r]=[Math.cos(t),Math.sin(t)],s=e[0]*i[0]+e[1]*i[1]+e[2]*i[2],o=[e[1]*i[2]-e[2]*i[1],e[2]*i[0]-e[0]*i[2],e[0]*i[1]-e[1]*i[0]];return[i[0]*n+o[0]*r+e[0]*s*(1-n),i[1]*n+o[1]*r+e[1]*s*(1-n),i[2]*n+o[2]*r+e[2]*s*(1-n)]}function DR(i,e,t,n,r){let[s,o]=[n.tilt_x??0,n.tilt_z??0];if(!s&&!o)return;let a=n.rotation*Math.PI/180,l=[Math.cos(a),0,Math.sin(a)],c=[-Math.sin(a),0,Math.cos(a)],u=(h,f)=>{for(let d=f;d+2c.screen);if(o){let c=e?Gt(e,i):0,[u,h]=[(o.x-o.w/2)*t,(o.x+o.w/2)*t],f=Math.min(.02,(h-u)*.05);return{x0:u+f,x1:h-f,y0:c+o.y*r+f,y1:c+(o.y+o.h)*r-f,z:(o.z+o.d/2)*n}}let a=e&&i.type!=="fridge_smart"?Gt(e,i)-jr(i):0,l=BR(i,t,n,r,e);return l&&{...l,y0:l.y0+a,y1:l.y1+a}}function th(i,e){let t=kR(i,e);return t&&i.mirror?{...t,x0:-t.x1,x1:-t.x0}:t}function Sp(i,e){let[t,n,r]=[Math.max(.05,i.w),Math.max(.05,i.d),Math.max(.005,i.h)],s=vt(i.type),o=s&&jo(s,t,n,r).find(h=>h.picture);if(!o)return null;let a=e?Gt(e,i):0,[l,c]=[(o.x-o.w/2)*t,(o.x+o.w/2)*t],u={x0:l,x1:c,y0:a+o.y*r,y1:a+(o.y+o.h)*r,z:(o.z+o.d/2)*n};return i.mirror?{...u,x0:-u.x1,x1:-u.x0}:u}function wp(i,e){if(i.type!=="home_battery")return null;let[t,n,r]=[Math.max(.05,i.w),Math.max(.05,i.d),Math.max(.05,i.h)],s=e?Gt(e,i)-jr(i):0,o=n/2+.005;return i.variant==="wall"?{rect:{x0:-t*.3,x1:t*.3,y0:s+.5+r*.84,y1:s+.5+r*.9,z:o},vertical:!1}:i.variant==="cube"?{rect:{x0:-t*.35,x1:t*.35,y0:s+r*.8,y1:s+r*.86,z:o},vertical:!1}:{rect:{x0:-t*.05,x1:t*.05,y0:s+.06+r*.16,y1:s+r-.12,z:o},vertical:!0}}var Jn=Math.PI/180,dr=(i,e)=>[i[0]-e[0],i[1]-e[1],i[2]-e[2]];var Fo=i=>Math.hypot(i[0],i[1],i[2]),Ps=i=>{let e=Fo(i)||1;return[i[0]/e,i[1]/e,i[2]/e]},P_=(i,e)=>[i[1]*e[2]-i[2]*e[1],i[2]*e[0]-i[0]*e[2],i[0]*e[1]-i[1]*e[0]];var L_=.25;function F_(i,e,t,n,r,s,o){let a=r-t>=s-n,l=a?r-t:s-n;return{key:`${i}:top`,section:e,side:"top",flat:!0,o:[t,o,n],eu:a?[1,0,0]:[0,0,1],es:a?[0,0,1]:[1,0,0],n:[0,1,0],lu:l,ls:a?s-n:r-t,pitch:0,span:()=>[0,l],facing:a?[0,1]:[1,0]}}function O_(i,e){let t=Ps(P_(i,e));return t[1]<0?[-t[0],-t[1],-t[2]]:t}var N_=i=>{let e=Ps([-i[0],0,-i[2]]);return[e[0],e[2]]};function pr(i,e,t,n,r,s,o,a){let l=Ps(dr(r,n)),c=Ps(dr(s,n));return{key:i,section:e,side:t,flat:!1,o:n,eu:l,es:c,n:O_(l,c),lu:Fo(dr(r,n)),ls:Fo(dr(s,n)),pitch:o,span:a,facing:N_(c)}}function I_(i,e,t,n,r,s){let o=Fo(dr(r,n));if(o<.3)return null;let a=Ps(dr(r,n)),l=dr(s,n),c=l[0]*a[0]+l[1]*a[1]+l[2]*a[2],u=[l[0]-a[0]*c,l[1]-a[1]*c,l[2]-a[2]*c],h=Fo(u);if(h<.3)return null;let f=Ps(u),d=p=>{let x=Math.min(1,Math.max(0,p/h));return[c*x,o-(o-c)*x]};return{key:i,section:e,side:t,flat:!1,o:n,eu:a,es:f,n:O_(a,f),lu:o,ls:h,pitch:Math.atan2(f[1],Math.hypot(f[0],f[2]))/Jn,span:d,facing:N_(f)}}function zR(i,e){let t=Dn(i),n=En(i),r=(b,v,y)=>{let[M,S]=t.at(b,v);return[M,y,S]},[s,o]=[Math.max(0,e.a),Math.max(0,e.b)],a=t.u0-Math.max(0,e.u0),l=t.u1+Math.max(0,e.u1),c=l-a,u=n.y(-s),h=n.y(t.w+o);if(i.shape==="flat"||i.shape==="parapet"){let[b,v]=[t.at(a,-s),t.at(l,t.w+o)];return[F_(i.id,i.id,Math.min(b[0],v[0]),Math.min(b[1],v[1]),Math.max(b[0],v[0]),Math.max(b[1],v[1]),i.eave_a+L_)]}if(i.shape==="pent")return[pr(`${i.id}:a`,i.id,"a",r(a,-s,u),r(l,-s,u),r(a,t.w+o,h),i.pitch_a,()=>[0,c])];if(i.shape==="mansard")return VR(i,t,a,l,s,o);let f=i.shape==="hip"||i.shape==="pyramid",d=(t.u1-t.u0)/2,p=i.shape==="pyramid"?d:f?Math.min(d,Math.min(n.vr,t.w-n.vr)||t.w/2):0,x=f?t.u0+p-a:0,g=f?l-(t.u1-p):0,m=[];if(n.vr>.3){let b=Math.hypot(n.vr+s,n.rh-u);m.push(pr(`${i.id}:a`,i.id,"a",r(a,-s,u),r(l,-s,u),r(a,n.vr,n.rh),i.pitch_a,v=>[x*(v/b),c-g*(v/b)]))}if(t.w-n.vr>.3){let b=Math.hypot(t.w+o-n.vr,n.rh-h);m.push(pr(`${i.id}:b`,i.id,"b",r(l,t.w+o,h),r(a,t.w+o,h),r(l,n.vr,n.rh),i.pitch_b,v=>[g*(v/b),c-x*(v/b)]))}if(f){let b=I_(`${i.id}:c`,i.id,"c",r(a,t.w+o,h),r(a,-s,u),r(t.u0+p,n.vr,n.rh)),v=I_(`${i.id}:d`,i.id,"d",r(l,-s,u),r(l,t.w+o,h),r(t.u1-p,n.vr,n.rh));m.push(...[b,v].filter(y=>y!==null))}return m}function VR(i,e,t,n,r,s){let o=ol(e.w,i.eave_a,i.eave_b,ur(i.pitch_a),ur(i.pitch_b)),a=(p,x)=>{let[g,m]=e.at(p,x);return[g,o.y(x),m]},l=n-t,c=()=>[0,l],u=(p,x)=>Math.atan2(p,x)/Jn,h=[],[f,d]=[e.w+s,e.w-o.vlb];return o.vla+r>.3&&h.push(pr(`${i.id}:a`,i.id,"a",a(t,-r),a(n,-r),a(t,o.vla),i.pitch_a,c)),o.vr-o.vla>.3&&h.push(pr(`${i.id}:au`,i.id,"a",a(t,o.vla),a(n,o.vla),a(t,o.vr),u(o.rh-o.yla,o.vr-o.vla),c)),o.vlb+s>.3&&h.push(pr(`${i.id}:b`,i.id,"b",a(n,f),a(t,f),a(n,d),i.pitch_b,c)),d-o.vr>.3&&h.push(pr(`${i.id}:bu`,i.id,"b",a(n,d),a(t,d),a(n,o.vr),u(o.rh-o.ylb,d-o.vr),c)),h}function D_(i){return i.floors.filter(t=>t.rooms.some(n=>n.points.length>=3)).sort((t,n)=>n.elevation-t.elevation)[0]??null}function Is(i){let e=i.settings.roof;if(!e||e.type==="none")return[];if(e.type==="custom")return(e.sections??[]).flatMap(v=>zR(v,ll(i,v,v.overhang??e.overhang)));let t=D_(i);if(!t)return[];let n=t.rooms.flatMap(v=>v.points.map(y=>y[0])),r=t.rooms.flatMap(v=>v.points.map(y=>y[1])),s=i.settings.wall_exterior+e.overhang,[o,a]=[Math.min(...n)-s,Math.max(...n)+s],[l,c]=[Math.min(...r)-s,Math.max(...r)+s],u=t.elevation+t.height;if(e.type==="flat")return[F_("main",null,o,l,a,c,u+L_)];let h=a-o>=c-l,f=e.ridge==="short"?!h:h,d=(f?c-l:a-o)/2,p=d*Math.tan(e.pitch*Jn),x=(v,y,M)=>f?[v,u+M,(l+c)/2+y]:[(o+a)/2+y,u+M,v],[g,m]=f?[o,a]:[l,c],b=()=>[0,m-g];return[pr("main:a",null,"a",x(g,-d,0),x(m,-d,0),x(g,0,p),e.pitch,b),pr("main:b",null,"b",x(g,d,0),x(m,d,0),x(g,0,p),e.pitch,b)]}function nh(i,e){let t=[];for(let n of i.floors.filter(r=>!e||r.id===e)){let{walls:r}=al(n.rooms,{exterior:i.settings.wall_exterior,interior:i.settings.wall_interior},n.walls??[]);for(let s of r){if(!s.exterior&&!s.free)continue;let[o,a]=[s.b[0]-s.a[0],s.b[1]-s.a[1]],l=Math.hypot(o,a);if(l<1.2)continue;let[c,u]=[a/l,-o/l],h=Math.min(n.height,s.height??n.height,s.heightEnd??1/0),f=(d,p,x,g)=>t.push({key:d,section:null,side:"top",flat:!1,o:p,eu:x,es:[0,1,0],n:g,lu:l,ls:h,pitch:90,span:()=>[0,l],facing:[g[0],g[2]],wall:{floorId:n.id}});f(`wall:${n.id}:${s.id}`,[s.a[0]+c*s.right,n.elevation,s.a[1]+u*s.right],[o/l,0,a/l],[c,0,u]),s.free&&f(`wall:${n.id}:${s.id}:back`,[s.b[0]-c*s.left,n.elevation,s.b[1]-u*s.left],[-o/l,0,-a/l],[-c,0,-u])}}return t}var Sl="ground";function ih(i){let e=i.floors.filter(t=>t.rooms.some(n=>n.points.length>=3)).sort((t,n)=>t.elevation-n.elevation);return e.find(t=>t.elevation>-.5)??e[0]??i.floors[0]??null}function rh(i,e){let t=(e.rotation??0)*Jn,n=[Math.cos(t),0,Math.sin(t)],r=[-Math.sin(t),0,Math.cos(t)],s=ih(i),o=n[0]*e.u+r[0]*e.v,a=n[2]*e.u+r[2]*e.v,l=s?s.elevation+(e.base!=null?e.base:p0(s,o,a)):e.base??0;return{key:Sl,section:null,side:"top",flat:!0,o:[0,l,0],eu:n,es:r,n:[0,1,0],lu:1e4,ls:1e4,pitch:0,span:()=>[-1e4,1e4],facing:[r[0],r[2]],unbounded:!0}}var Tp=1.13,Ap=1.72,Oo=.025,di=.07;function wl(i){let e=i.module_w||Tp,t=i.module_h||Ap;return i.portrait===!1?[t,e]:[e,t]}function Ep(i){return i.layout?.length?i.layout.map(e=>Math.max(0,Math.min(60,Math.round(e)))):Array.from({length:Math.max(1,i.rows)},()=>Math.max(1,i.cols))}function Rp(i,e){return i.flat?Math.min(45,Math.max(0,e.tilt??15))*Jn:i.wall?Math.min(90,Math.max(0,e.tilt??0))*Jn:Math.min(45,Math.max(0,e.tilt??0))*Jn}function oh(i,e){let[,t]=wl(e),n=Rp(i,e);return i.wall?t*Math.cos(n)+Oo:!i.flat&&n<.001?t+Oo:i.flat&&e.rack==="ew"?t*Math.cos(n)+.08:t*Math.cos(n)+Math.max(.3,2*t*Math.sin(n))}function Cp(i,e){let[t,n]=wl(e),r=Ep(e),s=Math.max(1,...r);return[s*t+(s-1)*Oo,(r.length-1)*oh(i,e)+n*Math.cos(Rp(i,e))]}var GR=i=>i.flat&&!i.unbounded&&!i.wall;function HR(i,e){if(!GR(i)||!e.rotation)return null;let t=e.rotation*Jn,[n,r]=Cp(i,e);return{cos:Math.cos(t),sin:Math.sin(t),u:e.u+n/2,s:e.v+r/2}}function No(i,e,t=!1){let[n,r]=wl(e),s=Rp(i,e),o=r*Math.cos(s),a=oh(i,e),l=Ep(e),c=Math.max(1,...l),u=new Set(e.skip??[]),h=HR(i,e),f=(g,m)=>h?[h.u+(g-h.u)*h.cos-(m-h.s)*h.sin,h.s+(g-h.u)*h.sin+(m-h.s)*h.cos]:[g,m],d=(g,m,b)=>{let[v,y]=f(g,m);return[0,1,2].map(M=>i.o[M]+i.eu[M]*v+i.es[M]*y+i.n[M]*b)},p=(g,m)=>{let[b,v]=f(g,m);if(i.unbounded)return!0;if(v<-1e-6||v>i.ls+1e-6)return!1;let[y,M]=i.span(v);return b>=y-1e-6&&b<=M+1e-6},x=[];return l.forEach((g,m)=>{let b=e.align==="right"?c-g:e.align==="center"?(c-g)/2:0;for(let v=0;v.001?o:r);if([[S,w],[_,w],[_,R],[S,R]].every(([A,C])=>p(A,C)))if(i.wall&&s>.001){let A=di+r*Math.sin(s),[C,O]=e.flip?[A,di]:[di,A],D=[d(S,w,C),d(_,w,C),d(_,R,O),d(S,R,O)],P=e.flip?w:R;x.push({corners:D,posts:[S+.05,_-.05].map(I=>[d(I,P,0),d(I,P,A)]),cell:y,skipped:M})}else if(!i.flat&&s>.001){let A=di+r*Math.sin(s),C=[d(S,w,di),d(_,w,di),d(_,R,A),d(S,R,A)];x.push({corners:C,posts:[S+.05,_-.05].map(O=>[d(O,R,0),d(O,R,A)]),cell:y,skipped:M})}else if(!i.flat)x.push({corners:[d(S,w,di),d(_,w,di),d(_,R,di),d(S,R,di)],posts:[],cell:y,skipped:M});else{let C=.15+r*Math.sin(s),O=e.rack==="ew"&&m%2===1?!e.flip:!!e.flip,[D,P]=O?[R,w]:[w,R],I=[d(S,D,.15),d(_,D,.15),d(_,P,C),d(S,P,C)],N=[S+.05,_-.05].flatMap(F=>[[d(F,D,0),d(F,D,.15)],[d(F,P,0),d(F,P,C)]]);x.push({corners:I,posts:N,cell:y,skipped:M})}}}),x}var Pp=.78,Ip=1.18,U_=i=>({id:i.id,face:i.face,u:i.u,v:i.v,rows:1,cols:1,portrait:!0,module_w:i.w||Pp,module_h:i.h||Ip});function Tl(i,e){let t=No(i,U_(e))[0];if(!t)return null;let n=r=>[r[0]-i.n[0]*.05,r[1]-i.n[1]*.05,r[2]-i.n[2]*.05];return t.corners.map(n)}var sh={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 ah(i){let e=i.shape??"brick",t=sh[e]??sh.brick;return{shape:e,w:i.w||t.w,d:i.d||t.d,h:i.h||t.h}}function Lp(i,e){let{w:t,d:n}=ah(i),r=e&&!e.flat?Math.cos(e.pitch*Jn):1;return{id:i.id,face:i.face,u:i.u,v:i.v,rows:1,cols:1,portrait:!0,module_w:t,module_h:n/Math.max(.2,r),tilt:0}}function Fp(i,e){let t=Lp(e,i),[n,r]=[t.module_w,t.module_h],s=(u,h)=>[i.o[0]+i.eu[0]*u+i.es[0]*h,i.o[1]+i.eu[1]*u+i.es[1]*h,i.o[2]+i.eu[2]*u+i.es[2]*h],[o,a]=[s(e.u+n/2,e.v),s(e.u+n/2,e.v+r)],l=s(e.u+n/2,e.v+r/2),c=u=>{let h=Math.hypot(u[0],u[2])||1;return[u[0]/h,u[2]/h]};return{center:[l[0],l[2]],along:c(i.eu),across:c(i.es),low:Math.min(o[1],a[1]),high:Math.max(o[1],a[1])}}var Ls=1712952,Fs=2239816,lh=1318193,mr=Ue(3662079,.9),gr=Ue(5995775,.45),Xt=.14,B_=9427199,k_=13226982,z_=14936565,V_={black:{glass:new W(329483),edge:Ue(9082544,.32),cells:Ue(2766160,.22)},blue:{glass:new W(1386842),edge:Ue(10467583,.55),cells:Ue(4025599,.35)}},G_=Ue(13226982,.5),H_=Ue(13226982,.85),W_=Ue(16757575,.95),Op=new W(2845583),Np=new W(3818072),Dp=3812144,Up=4864064,ch=2765896,Do=329483,uh=9148333,hh=11845844,X_=Ue(5995775,.4);var Uo=(i,e,t)=>[i[0]+(e[0]-i[0])*t,i[1]+(e[1]-i[1])*t,i[2]+(e[2]-i[2])*t],fh=(i,e,t)=>[i[0]+e[0]*t,i[1]+e[1]*t,i[2]+e[2]*t],Bp=(i,e)=>e.section?i.find(t=>t.sections?.includes(e.section)):i[0];function Y_(i,e,t){let n=i.settings.roof?.windows??[];if(n.length===0||e.length===0)return;let r=new Map(Is(i).map(s=>[s.key,s]));for(let s of n){let o=r.get(s.face),a=o?Tl(o,s):null,l=o&&a?Bp(e,o):void 0;if(!o||!a||!l)continue;let c=l.floor.elevation+l.base,[u,h,f,d]=a.map(R=>[R[0],R[1]-c,R[2]]),p=t.get(s.id)??{open:0,tilt:0,cover:0},x=(R,A)=>fh(R,o.n,A),g=p.open>.02||p.tilt>.02?W_:H_,m=[u,h,f,d].map(R=>x(R,.06));m.forEach((R,A)=>l.lines.seg(R,m[(A+1)%4],g));let b=(p.open>.02?30*Math.min(1,p.open):p.tilt>.5?12:0)*pt,v=Math.hypot(f[0]-h[0],f[1]-h[1],f[2]-h[2]),y=R=>fh(fh(R,o.es,-v*Math.cos(b)),o.n,v*Math.sin(b)),[M,S]=[x(d,.065),x(f,.065)],[_,w]=[y(M),y(S)];l.solid.tri(_,w,S,Op),l.solid.tri(_,S,M,Op);for(let[R,A]of[[_,w],[w,S],[S,M],[M,_]])l.lines.seg(R,A,g);if(p.cover>.02){let R=Math.min(1,p.cover),[A,C]=[x(Uo(M,_,R),.01),x(Uo(S,w,R),.01)],[O,D]=[x(M,.01),x(S,.01)];l.solid.tri(A,C,D,Np),l.solid.tri(A,D,O,Np)}}}function dh(i,e,t,n,r){let s=c=>[c[0],c[1]-r,c[2]],o=V_[n.look==="blue"?"blue":"black"],[a,l]=n.portrait===!1?[10,6]:[6,10];for(let c of No(t,n)){let[u,h,f,d]=c.corners.map(s);for(let[g,m,b]of[[u,h,f],[u,f,d],[u,f,h],[u,d,f]])i.tri(g,m,b,o.glass);let p=g=>fh(g,t.n,.004),x=[u,h,f,d].map(p);x.forEach((g,m)=>e.seg(g,x[(m+1)%4],o.edge));for(let g=1;g[r.key,r]));for(let r of t){let s=n.get(r.face),o=s?Bp(e,s):void 0;s&&o&&dh(o.solid,o.lines,s,r,o.floor.elevation+o.base)}}function $_(i,e){let t=i.settings.roof?.chimneys??[];if(t.length===0||e.length===0)return;let n=new Map(Is(i).map(r=>[r.key,r]));for(let r of t){let s=n.get(r.face),o=s?Bp(e,s):void 0;if(!s||!o)continue;let a=o.floor.elevation+o.base,{shape:l,w:c,d:u,h}=ah(r),f=Fp(s,r),[d,p]=[f.low-a-.1,f.high-a+h],x=(_,w)=>{let{center:R,along:A,across:C}=f,O=(D,P)=>[R[0]+A[0]*_*D+C[0]*w*P,R[1]+A[1]*_*D+C[1]*w*P];return[O(-1,-1),O(1,-1),O(1,1),O(-1,1)]},g=(_,w=16)=>Array.from({length:w},(R,A)=>[f.center[0]+Math.cos(A/w*2*Math.PI)*_,f.center[1]+Math.sin(A/w*2*Math.PI)*_]),m=(_,w)=>_.forEach((R,A)=>o.lines.seg([R[0],w,R[1]],[_[(A+1)%_.length][0],w,_[(A+1)%_.length][1]],X_)),b=(_,w,R,A,C)=>Tt(o.solid,YR(_),w,R,A,C);if(l==="steel"){let _=Math.min(c,u)/2;b(g(_,12),d,p,uh,hh),b(g(_*.75,12),p,p+.001,Do,Do),b(g(_*.25,6),p,p+.1,uh,hh);let w=g(_*1.9,12);b(w,p+.1,p+.13,uh,hh),m(w,p+.13);continue}if(l==="round"){let _=Math.min(c,u)/2,w=g(_);b(w,d,p,Dp,Up),b(g(_*.55),p,p+.002,Do,Do),m(w,p);continue}let v=x(c/2,u/2);b(v,d,p,Dp,Up);let y=x(c/2+.04,u/2+.04);b(y,p,p+.06,ch,ch),m(y,p+.06),m(v,p-.25);let M=Math.min(c,u)*.25,S=l==="wide"?[-c/4,c/4]:[0];for(let _ of S){let w=[f.center[0]+f.along[0]*_,f.center[1]+f.along[1]*_],R=[[-1,-1],[1,-1],[1,1],[-1,1]].map(([A,C])=>[w[0]+f.along[0]*M*A+f.across[0]*M*C,w[1]+f.along[1]*M*A+f.across[1]*M*C]);b(R,p+.06,p+.16,ch,Do)}}}function YR(i){let e=0;for(let t=0;t0,r.b>0,r.u0>0,r.u1>0],f=(p,x,g,m,b,v)=>{let y=[t.at(p,g),t.at(x,g),t.at(x,m),t.at(p,m)],M=(y[1][0]-y[0][0])*(y[2][1]-y[0][1])-(y[2][0]-y[0][0])*(y[1][1]-y[0][1]);Tt(i,M<0?[...y].reverse():y,b-o,v-o,k_,z_,{bottom:!0})};for(let[p,x]of[[0,l],[a,c]]){if(!x)continue;let g=n.y(p)-.03,m=p===0?0:a-jn;f(t.u0,t.u1,m,m+jn,g-Al,g),e.seg(s(t.u0,p,g-Al),s(t.u1,p,g-Al),gr)}for(let[p,x]of[[t.u0,u],[t.u1-jn,h]])if(x)for(let g=0;g<6;g++){let[m,b]=[a*g/6,a*(g+1)/6],v=Math.min(n.y(m),n.y(b))-.03;f(p,p+jn,m,b,v-Al,v)}let d=[];for(let[p,x]of[[0,l],[a-jn,c]]){if(!x)continue;let g=t.u1-t.u0-jn,m=Math.max(1,Math.ceil(g/3.5));for(let b=0;b<=m;b++)b===0&&!u||b===m&&!h||d.push([t.u0+g*b/m,p])}!l&&!c&&(u&&d.push([t.u0,a/2-jn/2]),h&&d.push([t.u1-jn,a/2-jn/2]));for(let[p,x]of d)f(p,p+jn,x,x+jn,o,n.y(x+jn/2)-.03-Al)}function qR(i,e){let t=[];if(i.forEach(([s,o],a)=>{o>=e&&t.push([s,o]);let l=i[a+1];if(l&&(o-e)*(l[1]-e)<0){let c=(e-o)/(l[1]-o);t.push([s+(l[0]-s)*c,e])}}),t.length<2)return[];let[n,r]=[t[0],t[t.length-1]];return r[1]>e&&t.push([r[0],e]),n[1]>e&&t.unshift([n[0],e]),t}var Z_=i=>vr(i)>=0?i:[...i].reverse();function J_(i,e,t,n,r,s=i,o=!1,a=[],l=null){let c=Dn(t),u=En(t),h=typeof n=="number"?{u0:n,u1:n,a:n,b:n}:n,[f,d]=[Math.max(0,h.a),Math.max(0,h.b)],p=c.w,x=c.u0-Math.max(0,h.u0),g=c.u1+Math.max(0,h.u1),m=(I,N,F)=>{let[H,B]=c.at(I,N);return[H,F-r,B]},b=new W(Fs),v=new W(Ls),y=new W(lh),M=(I,N)=>{for(let F=1;F+1m(I,N,F-H),_=[],w=[],R=[],A=null,C=null;if(t.shape==="flat"||t.shape==="parapet"){let I=t.eave_a-r,N=t.shape==="parapet",F=t.points&&t.points.length>=3?qd(t,N?0:Math.max(0,Math.min(h.a,h.b,h.u0,h.u1))):N?[c.at(c.u0,0),c.at(c.u1,0),c.at(c.u1,p),c.at(c.u0,p)]:[c.at(x,-f),c.at(g,-f),c.at(g,p+d),c.at(x,p+d)];if(Tt(i,F,I,I+.25,Ls,Fs,{bottom:!0}),F.forEach((H,B)=>{let X=F[(B+1)%F.length];e.seg([H[0],I+.252,H[1]],[X[0],I+.252,X[1]],mr),e.seg([H[0],I,H[1]],[X[0],I,X[1]],gr)}),N){let H=Z_(F),B=Ou(H,-.2);H.forEach((X,V)=>{let re=(V+1)%H.length;Tt(i,Z_([X,H[re],B[re],B[V]]),I+.25,I+.65,Ls,Fs),e.seg([X[0],I+.652,X[1]],[H[re][0],I+.652,H[re][1]],mr),e.seg([B[V][0],I+.652,B[V][1]],[B[re][0],I+.652,B[re][1]],mr)})}}else{let I=Hr(t,h);_=a.reduce((N,F)=>N.flatMap(H=>Nu(H,F)),I.faces),w=I.rim,R=I.ridges,A=I.gable,C=I.endProfiles??null}let O=!!t.open,D=new W(B_);for(let I of _)if(O)for(let N=1;N+1S(N)),b),M(I.map(N=>S(N,Xt)),v);if(w.forEach((I,N)=>{let F=w[(N+1)%w.length];O||M([S(I),S(F),S(F,Xt),S(I,Xt)],v),e.seg(S(I),S(F),O?mr:gr)}),O){K_(i,e,c,u,h,(I,N,F)=>m(I,N,F),r);return}for(let[I,N]of R)e.seg(S([I[0],I[1],I[2]+.004]),S([N[0],N[1],N[2]+.004]),mr);let P=t.base;if(!o){if(A){let I=l===null?[c.u0,c.u1]:[l===0?c.u0:c.u1];for(let N of I){let F=C?C[N===c.u0?0:1]:A,H=F?qR(F,P-Xt):[];H.length>=3&&M(H.map(([B,X])=>m(N,B,X)),y)}}if(t.shape!=="flat"&&t.shape!=="parapet")for(let I of[0,p]){let N=u.y(I)-Xt;N>P+.02&&M([m(c.u0,I,P),m(c.u1,I,P),m(c.u1,I,N),m(c.u0,I,N)],y)}else if(t.eave_a>P+.02){let I=[[c.u0,0],[c.u1,0],[c.u1,p],[c.u0,p]];I.forEach(([N,F],H)=>{let[B,X]=I[(H+1)%4];M([m(N,F,P),m(B,X,P),m(B,X,t.eave_a),m(N,F,t.eave_a)],y)})}}}function j_(i,e,t){let n=i.floors.filter(o=>o.rooms.length>0).sort((o,a)=>o.elevation-a.elevation);if(n.length===0)return[];let r=new Map,s=new Map(Is(i).map(o=>[o.key,o]));for(let o of e){if(Math.abs(o.x1-o.x0)<.1||Math.abs(o.z1-o.z0)<.1)continue;let a=Zd(i,o)??n[0],l=o.open?`${a.id}:open`:a.id,c=r.get(l);c||r.set(l,c={floor:a,base:0,solid:new lt,lines:new Wt,glass:new lt,sections:[],lift:!o.open}),c.sections.push(o.id);let u=ul(e,o),h=As(e,o)??u?.parent??null,f=a.elevation+a.height>o.base+.05&&!o.dormer&&!h,d=e.filter(g=>g!==o).flatMap(g=>As(e,g)===o?Uu(o,g):ul(e,g)?.parent===o?Uu(o,ul(e,g).extended):[]);for(let g of i.settings.roof.windows??[]){let m=s.get(g.face),b=m&&m.section===o.id?Tl(m,g):null;if(!b)continue;let v=b.map(y=>Fi(o,y[0],y[2]));d.push({u0:Math.min(...v.map(y=>y[0])),u1:Math.max(...v.map(y=>y[0])),v0:Math.min(...v.map(y=>y[1])),v1:Math.max(...v.map(y=>y[1]))})}let p=u?u.extended:h?cl(h,o):o,x=null;if(h){let g=Dn(p),m=Hr(h,{u0:0,u1:0,a:0,b:0}),b=v=>{let[y,M]=g.at(v,g.w/2),[S,_]=Fi(h,y,M);return Ts(m,S,_)??En(h).y(_)};x=b(g.u0)<=b(g.u1)?0:1}J_(c.solid,c.lines,p,ll(i,p,p.overhang??t),a.elevation,c.glass,f,d,x)}return[...r.values()].sort((o,a)=>+(o.lift===!1)-+(a.lift===!1))}function Q_(i){return i.floors.filter(e=>e.rooms.some(t=>t.points.length>=3)).sort((e,t)=>t.elevation-e.elevation)[0]??null}function ev(i){let e=i.settings.roof,t=Q_(i);if(!t||!e||e.type==="none"||e.type==="custom")return null;let n=t.rooms.flatMap(O=>O.points.map(D=>D[0])),r=t.rooms.flatMap(O=>O.points.map(D=>D[1])),s=i.settings.wall_exterior+e.overhang,[o,a]=[Math.min(...n)-s,Math.max(...n)+s],[l,c]=[Math.min(...r)-s,Math.max(...r)+s],u=new lt,h=new Wt,f={floor:t,base:t.height,solid:u,lines:h,glass:new lt};if(e.type==="flat"){let O=[[o,l],[a,l],[a,c],[o,c]];return Tt(u,O,0,.25,Ls,Fs,{bottom:!0}),O.forEach(([D,P],I)=>{let[N,F]=O[(I+1)%4];h.seg([D,.252,P],[N,.252,F],mr),h.seg([D,0,P],[N,0,F],gr)}),f}let d=a-o>=c-l,p=e.ridge==="short"?!d:d,x=(p?c-l:a-o)/2,g=Math.tan(e.pitch*pt),m=x*g,b=(O,D,P)=>p?[O,P,(l+c)/2+D]:[(o+a)/2+D,P,O],[v,y]=p?[o,a]:[l,c],M=new W(Fs),S=new W(Ls),_=(O,D,P,I,N)=>{u.tri(O,D,P,N),u.tri(O,P,I,N)};for(let O of[-1,1]){_(b(v,O*x,0),b(y,O*x,0),b(y,0,m),b(v,0,m),M),_(b(v,O*x,-Xt),b(v,0,m-Xt),b(y,0,m-Xt),b(y,O*x,-Xt),S),_(b(v,O*x,-Xt),b(y,O*x,-Xt),b(y,O*x,0),b(v,O*x,0),S);for(let D of[v,y])_(b(D,O*x,-Xt),b(D,O*x,0),b(D,0,m),b(D,0,m-Xt),S);h.seg(b(v,O*x,0),b(y,O*x,0),gr);for(let D of[v,y])h.seg(b(D,O*x,0),b(D,0,m),gr)}let w=e.overhang,R=new W(lh),A=x-w,C=A*g;for(let O of[v+w,y-w])u.tri(b(O,-A,-Xt),b(O,A,-Xt),b(O,0,C-Xt),R),u.tri(b(O,A,-Xt),b(O,-A,-Xt),b(O,0,C-Xt),R);return h.seg(b(v,0,m+.004),b(y,0,m+.004),mr),f}function kp(i,e=new Map){let t=i.settings.roof,n=t?.type==="custom"?null:ev(i),r=t?.type==="custom"?j_(i,t.sections??[],t.overhang):n?[n]:[];return q_(i,r),Y_(i,r,e),$_(i,r),r}function ph(i){let{start:e,axis:t,width:n}=i.info;return[[e[0],e[1]],[e[0]+t[0]*n,e[1]+t[1]*n]]}var tv=(i,e)=>`${i}|${Math.round(e[0]*50)},${Math.round(e[1]*50)}`;function nv(i,e){let t=[];for(let n of i){let r=n.info.opening.front;if(!r)continue;let[s,o]=ph(n);e.at(r,s)&&t.push(n.s0),e.at(r,o)&&t.push(n.s1)}return t}function iv(i,e){let t=Math.hypot(i.b[0]-i.a[0],i.b[1]-i.a[1])||1;return((e[0]-i.a[0])*(i.b[0]-i.a[0])+(e[1]-i.a[1])*(i.b[1]-i.a[1]))/t}function mh(i){let e=new Map,t=new Map;for(let r of i)for(let s of r){let o=s.info.opening.front;if(o)for(let a of ph(s)){let l=tv(o,a);e.set(l,(e.get(l)??0)+1),t.has(l)||t.set(l,[a[0],a[1]])}}return{points:[...e].filter(([,r])=>r>1).map(([r])=>t.get(r)).filter(r=>!!r),at:(r,s)=>(e.get(tv(r,s))??0)>1}}var Os={floor:923177,slab:659744,wall:1252657,wallTop:1323071,edge:3662079,edgeSoft:5995775},gh={wood:{color:1120814,tile:[0,0]},oak:{color:1252141,tile:[1,0]},tiles:{color:923695,tile:[2,0]},carpet:{color:1053995,tile:[0,1]},stone:{color:988971,tile:[1,1]},concrete:{color:1120295,tile:[2,1]}},pi=.2,Bo=8;var rv=(i,e)=>i.heightEnd===void 0?i.height??e:Math.max(i.height??e,i.heightEnd);function sv(i){let e=new Map,t=[],n=new Map;for(let r of i){let s="interior",o=null;if(r.exterior){let[a,l]=[r.b[0]-r.a[0],r.b[1]-r.a[1]],c=Math.hypot(a,l)||1,u=[l/c,-a/c],h=(Math.round(Math.atan2(u[1],u[0])/(2*Math.PI)*Bo)%Bo+Bo)%Bo;s=`s${h}`;let f=h/Bo*2*Math.PI;o=[Math.cos(f),Math.sin(f)]}e.has(s)||(e.set(s,t.length),t.push(o)),n.set(r,e.get(s))}return{buckets:t,wallBucket:n}}function ov(i){let e=(n,r,s)=>{let o=i?i(n,r):null;return o===null?s:Math.max(.05,Math.min(s,o))};return{topAt:e,lowestTop:(n,r,s,o,a)=>{if(!i)return a;let l=Math.max(2,Math.ceil((o-s)/.25)+1),c=a;for(let u=0;ut.topAt(h,f,n),lowestTop:(h,f)=>t.lowestTop(i.a,s,h,f,n)};let[o,a]=[i.height??e,i.heightEnd],l=(h,f)=>{let d=r>1e-9?((h-i.a[0])*s[0]+(f-i.a[1])*s[1])/r:0;return o+(a-o)*Math.max(0,Math.min(1,d))},c=(h,f)=>t.topAt(h,f,l(h,f));return{H:n,varies:!0,topAt:c,lowestTop:(h,f)=>{let d=Math.max(2,Math.ceil((f-h)/.25)+1),p=1/0;for(let x=0;x0:c.roomLeft===o.room_id,m=[-h[1],h[0]],b=g?m:[-m[0],-m[1]],v=Qr(i.rooms.find(R=>R.id===o.room_id)),y=Math.min(ko(c,i.height,n).lowestTop(p,p+d)-.02,v+o.sill+o.height),M=Math.max(Math.min(0,v),Math.min(v+o.sill,y-.1)),S=[b[1],-b[0]],_=h[0]*S[0]+h[1]*S[1]>0,w={opening:o,bucket:t.get(c),start:[c.a[0]+h[0]*p,c.a[1]+h[1]*p],axis:h,width:d,toRoom:b,faceRoom:g?c.left:c.right,faceOut:g?c.right:c.left,sill:M,top:y,hingeAtStart:o.hinge==="left"===_,exterior:c.exterior};s.push(w),r.set(c,[...r.get(c)??[],{s0:p,s1:p+d,sill:M,top:y,info:w}])}return{openings:s,spans:r}}var lv=i=>`${Math.round(i[0]*50)},${Math.round(i[1]*50)}`;function $R(i,e,t,n=!1,r=!1){let{info:s}=e,o=s.bucket,a=(u,h,f)=>[s.start[0]+s.axis[0]*(u-e.s0)+s.toRoom[0]*h,f,s.start[1]+s.axis[1]*(u-e.s0)+s.toRoom[1]*h],l=u=>u>t+1e-6?o:Xe,c=e.sill<0?e.sill+.004:Math.max(e.sill,.004);for(let u of[s.faceRoom,-s.faceOut])n||i.segSplit(a(e.s0,u,c),a(e.s0,u,e.top),ci,t,o),r||i.segSplit(a(e.s1,u,c),a(e.s1,u,e.top),ci,t,o),i.seg(a(e.s0,u,e.top),a(e.s1,u,e.top),ci,l(e.top)),e.sill>.01&&i.seg(a(e.s0,u,e.sill),a(e.s1,u,e.sill),ci,l(e.sill));for(let[u,h]of[[e.s0,n],[e.s1,r]])h||(i.seg(a(u,s.faceRoom,e.top),a(u,-s.faceOut,e.top),ci,l(e.top)),e.sill>.01&&i.seg(a(u,s.faceRoom,e.sill),a(u,-s.faceOut,e.sill),ci,l(e.sill)),e.sillt&&i.seg(a(u,s.faceRoom,t),a(u,-s.faceOut,t),Pu,tl+o))}function cv(i,e,t,n,r,s,o){let a=Math.min(e.cut_height,e.height),l=(f,d)=>(r.get(f)??[]).filter(d);for(let f of t.edges){let d=n.get(f.wall);for(let[m,b]of Eo(f,l(f.wall,v=>v.sill<=.005)))i.seg([m[0],.004,m[1]],[b[0],.004,b[1]],Ad);for(let[m,b]of Eo(f,l(f.wall,v=>v.silla)))i.seg([m[0],a,m[1]],[b[0],a,b[1]],Pu,tl+d);let p=ko(f.wall,e.height,s),{H:x,topAt:g}=p;for(let[m,b]of Eo(f,l(f.wall,v=>v.top>=x-.021))){if(!o&&!p.varies){i.seg([m[0],x,m[1]],[b[0],x,b[1]],Ii,x<=a+1e-6?cr+d:d);continue}let v=Math.max(1,Math.ceil(Math.hypot(b[0]-m[0],b[1]-m[1])/.3)),y=M=>[m[0]+(b[0]-m[0])*M/v,m[1]+(b[1]-m[1])*M/v];for(let M=0;M!!b.info.opening.front&&d>b.s0+.05&&dMath.abs(b-d)<.06);if(x||g||u.has(lv(f.p)))continue;let m=ko(f.wall,e.height,s).topAt(f.p[0],f.p[1]);i.segSplit([f.p[0],.004,f.p[1]],[f.p[0],m,f.p[1]],ci,Math.min(a,m),n.get(f.wall))}for(let f of r.values())for(let d of f){let p=d.info.opening.front,[x,g]=ph(d);$R(i,d,a,p?c.at(p,x):!1,p?c.at(p,g):!1)}}function uv(i,e){let t=new lt(!0,!0),n=[],r=new Wt,s=[],o=new W(Os.slab),a=(l,c=0,u=c-pi)=>{l.forEach((h,f)=>{let d=l[(f+1)%l.length];t.tri([h[0],u,h[1]],[h[0],c,h[1]],[d[0],c,d[1]],o),t.tri([h[0],u,h[1]],[d[0],c,d[1]],[d[0],u,d[1]],o)})};for(let l of i.rooms){if(l.points.length<3)continue;let c=Gr(l.points),u=gh[l.floor_material]??gh.wood,h=new W(u.color),f=e.filter(g=>ly(g,c)).map(g=>cy(g,.003));s.push(...f);let d=[...c,...f.flat()],p=t.count,x=Qr(l);for(let[g,m,b]of Vr(c,f)){let[v,y,M]=[d[g],d[m],d[b]];t.tri([v[0],x,v[1]],[M[0],x,M[1]],[y[0],x,y[1]],h,h,h,[v[0],v[1],M[0],M[1],y[0],y[1]],Xe,u.tile)}n.push({roomId:l.id,start:p,end:t.count,color:u.color}),a(c,x),Math.abs(x)>.005&&(a(c,Math.max(0,x),Math.min(0,x)),a([...c].reverse(),Math.max(0,x),Math.min(0,x)));for(let g of f)a([...Gr(g)].reverse()),g.forEach((m,b)=>{let v=g[(b+1)%g.length];r.seg([m[0],x+.006,m[1]],[v[0],x+.006,v[1]],Ii),r.seg([m[0],x-pi,m[1]],[v[0],x-pi,v[1]],ci)})}return{buffer:t,roomTris:n,holeLines:r,cutHoles:s}}var xh=.42,zp=.42;function hv(i,e,t){let n=new lt,r=new W(zp,zp,zp),s=new W(1,1,1),o=.002;for(let a of i)for(let[l,c]of Eo(a,(t.get(a.wall)??[]).filter(u=>u.sill<=.005))){let[u,h]=[c[0]-l[0],c[1]-l[1]],f=Math.hypot(u,h);if(f<.05)continue;let d=[h/f,-u/f],p=[(l[0]+c[0])/2+d[0]*.05,(l[1]+c[1])/2+d[1]*.05];if(!e.some(m=>m.points.length>=3&&Ve(p,m.points)))continue;let x=[l[0]+d[0]*xh,l[1]+d[1]*xh],g=[c[0]+d[0]*xh,c[1]+d[1]*xh];n.tri([l[0],o,l[1]],[x[0],o,x[1]],[g[0],o,g[1]],r,s,s),n.tri([l[0],o,l[1]],[g[0],o,g[1]],[c[0],o,c[1]],r,s,r)}return n}var Vp=(i,e)=>Number.parseInt(/^#?([0-9a-f]{6})$/i.exec(i?.trim()??"")?.[1]??e.slice(1),16),KR=i=>/^#?[0-9a-f]{6}$/i.test(i?.trim()??"");function Gp(i,e){return{outside:Vp(KR(e.wall_paint_outside)?e.wall_paint_outside:i.wall_paint_outside,g0),inside:Vp(i.wall_paint_inside,Vh),rooms:e.rooms.filter(t=>t.wall_paint&&t.points.length>=3).map(t=>({points:t.points,color:Vp(t.wall_paint,Vh)}))}}var ZR=14276045;function JR(i,e,t,n,r){let s=Math.hypot(t[0]-e[0],t[1]-e[1])||1,o=[(e[0]+t[0])/2,(e[1]+t[1])/2],a=[(t[1]-e[1])/s,-(t[0]-e[0])/s];Ve([o[0]+a[0]*.01,o[1]+a[1]*.01],i)&&(a=[-a[0],-a[1]]);let l=[o[0]+a[0]*.06,o[1]+a[1]*.06],c=n.rooms.find(u=>Ve(l,u.points));return c?c.color:r.some(u=>u.points.length>=3&&Ve(l,u.points))?n.inside:n.outside}function jR(i,e,t=-pi){let n=[-1/0,...new Set(i.flatMap(s=>[s.s0,s.s1])).values(),1/0].sort((s,o)=>s-o),r=[];for(let s=0;s+1f.s0l).map(f=>[f.sill,f.top]).sort((f,d)=>f[0]-d[0]),u=[],h=t;for(let[f,d]of c)f>h+1e-4&&u.push([h,f]),h=Math.max(h,d);e>h+1e-4&&u.push([h,e]),r.push({t0:o,t1:a,ranges:u})}return r}function fv(i,e,t,n,r,s,o,a){let l=Math.min(e.cut_height,e.height),c=a?Cd:0,u=a?g=>(m,b)=>JR(g,m,b,a,e.rooms):null,h=a?ZR:Os.wallTop,f=mh(r.values()),d=g=>f.points.some(m=>Math.hypot(m[0]-g[0],m[1]-g[1])<.03),p=g=>g&&g.info.opening.front?[g.sill,g.top]:null,x=(g,m)=>{let b=[];for(let[v,y]of g)m[0]>v+1e-4&&b.push([v,Math.min(y,m[0])]),y>m[1]+1e-4&&b.push([Math.max(v,m[1]),y]);return b};for(let g of t){let m=n.get(g),b=_s([g.b[0]-g.a[0],g.b[1]-g.a[1]]),v=(r.get(g)??[]).sort((I,N)=>I.s0-N.s0),y=ko(g,e.height,s),{H:M,topAt:S}=y,_=Math.min(0,...[g.roomLeft,g.roomRight].map(I=>Qr(e.rooms.find(N=>N.id===I)))),w=jR(v,M,_-pi),R=Math.hypot(g.b[0]-g.a[0],g.b[1]-g.a[1]),A=(o||y.varies)&&y.lowestTop(0,R){let N=Math.max(I.t0,-.5),F=Math.min(I.t1,R+.5),H=Math.max(1,Math.ceil((F-N)/.3));return Array.from({length:H},(B,X)=>({t0:X===0?I.t0:N+(F-N)*X/H,t1:X===H-1?I.t1:N+(F-N)*(X+1)/H,ranges:I.ranges,inner0:X>0,inner1:X({...I,inner0:!1,inner1:!1})),O=I=>(I[0]-g.a[0])*b[0]+(I[1]-g.a[1])*b[1],D=d(g.a)?p(v[0]):null,P=d(g.b)?p(v[v.length-1]):null;for(let I of C){let N=Ud(g.footprint,g.a,b,I.t0,I.t1);if(N.length<3)continue;let F=I.t1<=1e-6&&I.t0<0?D:I.t0>=R-1e-6?P:null,H=F?x(I.ranges,F):I.ranges,B=(Y,Q)=>Math.abs(O(Y)-Q)<1e-4,X=(Y,Q)=>I.inner0&&B(Y,I.t0)&&B(Q,I.t0)||I.inner1&&B(Y,I.t1)&&B(Q,I.t1),V=(Y,Q)=>!f.points.length||Math.hypot(Y[0]-Q[0],Y[1]-Q[1])>.5?!1:f.points.some(se=>Math.min(Math.hypot(se[0]-Y[0],se[1]-Y[1]),Math.hypot(se[0]-Q[0],se[1]-Q[1]))<.05),re=(Y,Q)=>X(Y,Q)||V(Y,Q),be=A?Math.min(...N.map(([Y,Q])=>S(Y,Q))):M;for(let[Y,Q]of H){let se=Math.min(Q,A?Math.max(...N.map(([st,Te])=>S(st,Te))):Q);if(se-Y<1e-4||be-Y<.01)continue;let Se=Y>.01,le=A&&Q>be,Ie=(st,Te)=>Math.min(Q,S(st,Te));if(Yl+1e-6?Rd+m:cr+m,Te=le&&beMath.min(l,Ie(ht,bt)):Math.min(se,l);Tt(i,N,Y,Te,Os.wall,h,{aoFrom:0,bottom:Se,fold:c+cr+m,topFold:c+st,skipSide:re,sideColor:u?.(N)})}se>l+1e-6&&be>l+1e-6&&Tt(i,N,Math.max(Y,l),le?Ie:se,Os.wall,h,{aoFrom:0,fold:c+m,bottom:Se&&Y>=l,skipSide:re,sideColor:u?.(N)})}}}}function Hp(i,e,t,n=[],r=[],s,o){let{walls:a,open:l}=al(i.rooms,{exterior:e,interior:t},i.walls??[]),c=ov(s),u=!!s,h=uv(i,n),{buckets:f,wallBucket:d}=sv(a),{openings:p,spans:x}=av(i,a,d,c),g=new lt;fv(g,i,a,d,x,c,u,o);let m=Bd(a,a.flatMap(_=>_.footprint)),b=new Wt;b.p.push(...h.holeLines.p),b.c.push(...h.holeLines.c),b.f.push(...h.holeLines.f),cv(b,i,m,d,x,c,u);let v=hv(m.edges,i.rooms,x),y=new Map;op(g,b,i,y,()=>new lt);for(let _ of r)dh(g,b,_.face,_.field,i.elevation);let M=Math.min(i.cut_height,i.height),S=[];for(let _ of i.furniture.filter(w=>!b0(w.type))){let w=g.count,R=b.p.length/6,A=Gt(i,_);Dl(_.type)||Ml(g,b,v,_,A),A+_.h>M+.05&&(Id(g,w,M,Iu),Ld(b,R,M,Iu)),S.push({id:_.id,start:w,end:g.count})}return{floor:h.buffer.geometry(),roomTris:h.roomTris,holes:h.cutHoles,walls:g.geometry(),ghosts:[...y].map(([_,w])=>({opacity:_,geometry:w.geometry()})),lines:b.geometry(),shadow:v.geometry(),buckets:f,openings:p,walls2d:a,openRooms:l,wallBuckets:a.map(_=>d.get(_)),furnitureTris:S,roofUnder:s}}function Wp(i,e){let t=_0(i,e),n=[...e.furniture.filter(a=>a.type==="stairwell").map(ts),...e.furniture.filter(a=>Qu(a)&&a.stair?.down).flatMap(mp)].filter(a=>a.length>=3),r=i.filter(a=>a.elevationl.elevation-a.elevation)[0];if(!r)return fr([...n,...t]);let o=r.furniture.filter(a=>(a.type==="stairs"||vt(a.type)?.hole)&&!(Qu(a)&&a.stair?.down)&&r.elevation+a.h>=e.elevation-.3).flatMap(a=>Qu(a)?mp(a):[ts(a)]).filter(a=>a.length>=3);return fr([...n,...o,...t])}var dv=.12,pv=1.35,Di=(i,e,t)=>Math.min(t,Math.max(e,i)),QR=i=>i<.5?4*i*i*i:1-(-2*i+2)**3/2,mv=i=>({...i,target:i.target.clone()});function gv({target:i,radius:e,theta:t,phi:n}){return new U(i.x+e*Math.sin(n)*Math.sin(t),i.y+e*Math.cos(n),i.z+e*Math.sin(n)*Math.cos(t))}function xv(i,e,t){let n=QR(t);return{target:new U().lerpVectors(i.target,e.target,n),radius:i.radius+(e.radius-i.radius)*n,theta:i.theta+(e.theta-i.theta)*n,phi:i.phi+(e.phi-i.phi)*n}}function bv(i,e){let t=e.theta??i.theta;for(;t-i.theta>Math.PI;)t-=2*Math.PI;for(;t-i.theta<-Math.PI;)t+=2*Math.PI;return{target:(e.target??i.target).clone(),radius:e.radius??i.radius,theta:t,phi:e.phi??i.phi}}function Xp(i,e,t,n,r){let s=2*i.radius*Math.tan(r*Math.PI/360)/(n||1),o=new U(Math.cos(i.theta),0,-Math.sin(i.theta)),a=new U(-Math.sin(i.theta),0,-Math.cos(i.theta));i.target.addScaledVector(o,-e*s),i.target.addScaledVector(a,t*s/Math.max(.35,Math.cos(i.phi)))}function yv(i,e,t,n){let r=n||1,s={theta:-e/r*3.2,phi:-t/r*2.4};return i.theta+=s.theta,i.phi=Di(i.phi+s.phi,dv,pv),s}function _v(i,e){return Math.abs(e.theta)<=1e-4&&Math.abs(e.phi)<=1e-4?!1:(i.theta+=e.theta,i.phi=Di(i.phi+e.phi,dv,pv),e.theta*=.9,e.phi*=.9,!0)}var eC={KeyW:"w",KeyA:"a",KeyS:"s",KeyD:"d",KeyQ:"q",KeyE:"e"},tC=new Set(["w","a","s","d","q","e","arrowup","arrowdown","arrowleft","arrowright"]);function nC(i){let e=i.code?.startsWith("Key")?eC[i.code]??null:i.key.toLowerCase();return e&&tC.has(e)?e:null}var iC=500,rC=400,sC=320,oC=6,vv=1.5,aC=1.8;function lC(i,e){let t=i.keys,n=(t.has("w")||t.has("arrowup")?1:0)-(t.has("s")||t.has("arrowdown")?1:0)-i.stick[1],r=(t.has("d")?1:0)-(t.has("a")?1:0),s=(t.has("arrowleft")||t.has("q")?1:0)-(t.has("arrowright")||t.has("e")?1:0)-i.stick[0];if(!n&&!r&&!s)return!1;let o=e/1e3;i.yaw+=s*aC*o;let[a,l]=[-Math.sin(i.yaw),-Math.cos(i.yaw)],[c,u]=[Math.cos(i.yaw),-Math.sin(i.yaw)];return i.eye.x=Di(i.eye.x+(a*n+c*r)*vv*o,i.bounds.x0,i.bounds.x1),i.eye.z=Di(i.eye.z+(l*n+u*r)*vv*o,i.bounds.z0,i.bounds.z1),!0}var El=class{view={target:new U,radius:16,theta:-.6,phi:.85};minRadius=2;maxRadius=80;locked=!1;walk=null;pointers=new Map;velocity={theta:0,phi:0};flight=null;press=null;lastTap=0;holdTimer;held=!1;grabbing=!1;swiping=null;pinch=null;listeners=[];el;camera;events;constructor(e,t,n){this.el=e,this.camera=t,this.events=n;let r=(l,c,u)=>{e.addEventListener(l,c,u),this.listeners.push([l,c])};r("pointerdown",l=>this.onDown(l)),r("pointermove",l=>this.onMove(l)),r("pointerup",l=>this.onUp(l)),r("pointercancel",l=>this.onUp(l)),r("wheel",l=>this.onWheel(l),{passive:!1}),r("contextmenu",l=>l.preventDefault());let s=l=>c=>{if(!this.walk||c.target?.closest?.("input, textarea, select"))return;let u=nC(c);u&&(c.preventDefault(),l?this.walk.keys.add(u):this.walk.keys.delete(u),this.events.change())},o=s(!0),a=s(!1);window.addEventListener("keydown",o),window.addEventListener("keyup",a),this.listeners.push(["__window_keydown",o],["__window_keyup",a])}dispose(){clearTimeout(this.holdTimer);for(let[e,t]of this.listeners)e.startsWith("__window_")?window.removeEventListener(e.slice(9),t):this.el.removeEventListener(e,t)}get active(){return this.pointers.size>0||this.flight!==null}get busy(){return this.active}update(e){if(this.walk){let n=this.walk,r=lC(n,n.last?Math.min(100,e-n.last):16);n.last=r?e:0;let s=new U(-Math.sin(n.yaw)*Math.cos(n.pitch),Math.sin(n.pitch),-Math.cos(n.yaw)*Math.cos(n.pitch));return this.view.target.copy(n.eye).add(s),this.camera.position.copy(n.eye),this.camera.lookAt(this.view.target),r}let t=!1;if(this.flight){let{from:n,to:r,start:s,duration:o}=this.flight,a=Math.min(1,(e-s)/o);this.view=xv(n,r,a),a>=1&&(this.flight=null),t=!0}else this.pointers.size===0&&(t=_v(this.view,this.velocity));return this.camera.position.copy(gv(this.view)),this.camera.lookAt(this.view.target),t}flyTo(e,t=700){let n=bv(this.view,e),r=mv(this.view);this.velocity={theta:0,phi:0},t<=0||matchMedia("(prefers-reduced-motion: reduce)").matches?(this.view=n,this.flight=null):this.flight={from:r,to:n,start:performance.now(),duration:t},this.events.change()}local(e){let t=this.el.getBoundingClientRect();return[e.clientX-t.left,e.clientY-t.top]}stopMotion(){this.flight=null,this.velocity={theta:0,phi:0}}onDown(e){this.el.setPointerCapture(e.pointerId);let t=this.pointers.size===0;if(this.pointers.set(e.pointerId,{x:e.clientX,y:e.clientY,button:e.button}),this.stopMotion(),t&&e.button===0&&this.events.grab?.(...this.local(e))){this.grabbing=!0;return}if(clearTimeout(this.holdTimer),this.held=!1,this.pointers.size===1){this.press={x:e.clientX,y:e.clientY,time:performance.now(),moved:!1};let[n,r]=this.local(e);this.holdTimer=setTimeout(()=>{!this.press||this.press.moved||this.pointers.size!==1||(this.held=!0,this.events.hold(n,r))},iC)}else this.press=null,this.pinch=this.pinchState()}onMove(e){let t=this.pointers.get(e.pointerId);if(!t)return;if(this.grabbing)return void this.events.drag?.(...this.local(e));if(this.swiping)return void this.events.swipeMove?.(e.clientY-this.swiping.startY);let[n,r]=[e.clientX-t.x,e.clientY-t.y];if(this.press&&!this.press.moved&&Math.hypot(e.clientX-this.press.x,e.clientY-this.press.y)>oC){this.press.moved=!0,clearTimeout(this.holdTimer);let[s,o]=this.local({clientX:this.press.x,clientY:this.press.y});if(this.pointers.size===1&&t.button===0&&!e.shiftKey&&this.events.swipeStart?.(s,o,e.clientX-this.press.x,e.clientY-this.press.y))return this.swiping={startY:this.press.y},this.velocity={theta:0,phi:0},void this.events.swipeMove?.(e.clientY-this.press.y)}if(this.locked){[t.x,t.y]=[e.clientX,e.clientY];return}if(this.walk){if(!(this.press&&!this.press.moved)&&this.pointers.size===1){let s=this.el.clientHeight||1;this.walk.yaw+=n/s*2.4,this.walk.pitch=Di(this.walk.pitch+r/s*1.8,-1.1,1.1),this.events.change()}[t.x,t.y]=[e.clientX,e.clientY];return}if(this.pointers.size===1)this.press&&!this.press.moved||(t.button===1||t.button===2||e.shiftKey?Xp(this.view,n,r,this.el.clientHeight,this.camera.fov):this.velocity=yv(this.view,n,r,this.el.clientHeight)),[t.x,t.y]=[e.clientX,e.clientY];else{[t.x,t.y]=[e.clientX,e.clientY];let s=this.pinchState();this.pinch&&s&&(this.zoom(this.pinch.dist/Math.max(1,s.dist)),Xp(this.view,s.mid[0]-this.pinch.mid[0],s.mid[1]-this.pinch.mid[1],this.el.clientHeight,this.camera.fov)),this.pinch=s}this.pointers.size===1&&this.press&&!this.press.moved||this.events.change()}onUp(e){if(this.pointers.has(e.pointerId)){if(this.pointers.delete(e.pointerId),this.grabbing)return this.grabbing=!1,void this.events.drop?.();if(this.swiping)return this.swiping=null,this.press=null,void this.events.swipeEnd?.();if(this.pointers.size<2&&(this.pinch=null),clearTimeout(this.holdTimer),this.held)this.held=!1,this.press=null;else if(this.press&&!this.press.moved&&e.type==="pointerup"&&performance.now()-this.press.timea*n);return{id:`${i.id}:vehicle`,type:e,x:i.x,z:i.z,rotation:i.rotation,w:r,d:s,h:o,variant:i.variant??null,entity:null,power:null}}function bh(i,e){let t=[],n=!1;for(let r of i.furniture){t.push(r);let s=r.type==="parking"?e.get(r.id):void 0,o=s?cC(r,s):null;o&&(t.push(o),n=!0)}return n?{...i,furniture:t}:i}var uC="https://tile.openstreetmap.org/{z}/{x}/{y}.png";var hC=40075016686e-3,yh=Math.PI/180,fC=18,dC=.5,pC=160;function mC(i,e,t){let n=2**t,r=(e+180)/360*n,s=(1-Math.log(Math.tan(i*yh)+1/Math.cos(i*yh))/Math.PI)/2*n;return[r,s]}var gC=(i,e)=>hC*Math.cos(i*yh)/2**e;function Mv(i,e,t,n=pC){let[r,s]=mC(i,e,t),o=gC(i,t),a=n/o,l=2**t-1,c=[];for(let u=Math.floor(s-a);u<=Math.floor(s+a);u++)for(let h=Math.floor(r-a);h<=Math.floor(r+a);h++){if(u<0||u>l)continue;let f=(h%(l+1)+l+1)%(l+1);c.push({x:f,y:u,z:t,east:(h-r)*o,north:-(u-s)*o,size:o})}return c}function Sv(i,e){return i.replace("{z}",String(e.z)).replace("{x}",String(e.x)).replace("{y}",String(e.y)).replace("{s}","abc"[(e.x+e.y)%3])}var wv=i=>i.url&&i.url.startsWith("https://")?i.url:uC;function Tv(i,e,t,n){let r=t*yh;return[n.x+i*Math.cos(r)+e*Math.sin(r),n.z+i*Math.sin(r)-e*Math.cos(r)]}var Av=i=>!!i&&i.on===!0&&Number.isFinite(i.lat)&&Number.isFinite(i.lon),Ev=i=>({x:i.x??0,z:i.z??0,opacity:i.opacity??dC,zoom:i.zoom??fC});var xC="strict-origin-when-cross-origin",Yp=new Map;function Rv(i){let e=Yp.get(i);return e||(e=fetch(i,{referrerPolicy:xC,mode:"cors",credentials:"omit"}).then(async t=>t.ok&&(t.headers.get("content-type")??"").startsWith("image/")?await t.blob():null).catch(()=>null).then(t=>(t||setTimeout(()=>Yp.delete(i),6e4),t)),Yp.set(i,e)),e}var zo=256,bC=Math.PI/180,_h=class{mesh=new we(new sn(1,1),new Ke({transparent:!0,depthWrite:!1,side:ut}));canvas=null;texture=null;key="";generation=0;centre=[0,0];onChange=()=>{};scene;constructor(e){this.scene=e,this.mesh.rotation.order="YXZ",this.mesh.renderOrder=-2,this.mesh.visible=!1,this.mesh.name="live-map",e.add(this.mesh)}set(e,t,n,r=1){if(!Av(e)){this.mesh.visible=!1,this.generation++,this.key="";return}let s=Ev(e),o=wv(e),a=`${e.lat},${e.lon},${s.zoom},${o}`;a!==this.key&&this.load(a,e,s.zoom,o);let[l,c]=this.centre,[u,h]=Tv(l,c,t,s);this.mesh.position.set(u,n,h),this.mesh.rotation.set(-Math.PI/2,-t*bC,0);let f=this.mesh.material;f.opacity=s.opacity,f.color.setScalar(r),this.mesh.visible=this.canvas!==null}load(e,t,n,r){this.key=e;let s=++this.generation,o=Mv(t.lat,t.lon,n);if(!o.length)return;let a=o[0].size,l=Math.min(...o.map(x=>x.east)),c=Math.max(...o.map(x=>x.north)),u=Math.round((Math.max(...o.map(x=>x.east))-l)/a)+1,h=Math.round((c-Math.min(...o.map(x=>x.north)))/a)+1,f=document.createElement("canvas");f.width=u*zo,f.height=h*zo,this.canvas=f,this.texture?.dispose(),this.texture=new zt(f),this.texture.colorSpace=ft,this.texture.anisotropy=4;let d=this.mesh.material;d.map=this.texture,d.needsUpdate=!0,this.mesh.geometry.dispose(),this.mesh.geometry=new sn(u*a,h*a),this.centre=[l+u*a/2,c-h*a/2];let p=f.getContext("2d");if(p)for(let x of o)this.draw(p,x,r,s,Math.round((x.east-l)/a),Math.round((c-x.north)/a))}draw(e,t,n,r,s,o){Rv(Sv(n,t)).then(a=>a?createImageBitmap(a):null).then(a=>{!a||r!==this.generation||(e.drawImage(a,s*zo,o*zo,zo,zo),this.texture&&(this.texture.needsUpdate=!0),this.onChange())})}dispose(){this.generation++,this.scene.remove(this.mesh),this.mesh.geometry.dispose(),this.mesh.material.dispose(),this.texture?.dispose()}};var yC=globalThis,Cv=yC.__nextfloorPluginStore??={plugins:new Map,listeners:new Set},_C=Cv.plugins,XB=Cv.listeners;var vC=5;function MC(i,e){i.errors.lengthNumber.isFinite(a))&&Number.isFinite(r.level)))return i;let o=a=>Math.max(0,Math.min(1,a));return{color:[o(r.color[0]),o(r.color[1]),o(r.color[2])],level:o(r.level)}}catch(r){return MC(n.status,r),i}}var Iv={rainbow:(i,e)=>{let t=(e*.08%1+1)%1,n=r=>Math.max(0,Math.min(1,Math.abs((t*6+r)%6-3)-1));return{color:[n(0),n(4),n(2)],level:i.level}},flicker:(i,e)=>({...i,level:i.level*(.75+.15*Math.sin(e*17)+.1*Math.sin(e*31+1))}),pulse:(i,e)=>({...i,level:i.level*(.65+.35*Math.sin(e*Math.PI))})};function Lv(i,e,t){return!i||!e?i:Object.prototype.hasOwnProperty.call(Iv,e)?Iv[e]?.(i,t)??i:Pv(i,e,t)}var Vo=2043986,Wr=2769520,Fv=2242399,vh=1845831,Ov=1450554,mi=16758087,Nv=1846349,Dv=2572395,Uv=1120816,Bv=1845831,kv=3662079,zv=5995775,Vv=9085695,Xr=Ue(3662079,.08),Gv=1.2,Hv=1.5,Wv=.2,Xv=.52;function Mh(i,e,t,n,r,s){let o=(x,g,m)=>e(x,g,m),{x0:a,x1:l,n0:c,n1:u,y0:h,y1:f}=t,d=x=>Ue(n.getHex(),x),p=[[o(a,c,f),o(l,c,f),o(l,u,f),o(a,u,f),r],[o(a,c,h),o(l,c,h),o(l,u,h),o(a,u,h),d(.6)],[o(a,u,h),o(l,u,h),o(l,u,f),o(a,u,f),n],[o(a,c,h),o(l,c,h),o(l,c,f),o(a,c,f),d(.85)],[o(a,c,h),o(a,u,h),o(a,u,f),o(a,c,f),d(.92)],[o(l,c,h),o(l,u,h),o(l,u,f),o(l,c,f),d(.92)]];for(let[x,g,m,b,v]of p)i.tri(x,g,m,v,v,v,void 0,s),i.tri(x,m,b,v,v,v,void 0,s)}function Vt(i,e,t,n,r,{cut:s,bucket:o}){if(t.y1<=s+1e-6)return Mh(i,e,t,n,r,Xe);if(t.y0>=s-1e-6)return Mh(i,e,t,n,r,o);Mh(i,e,{...t,y1:s},n,r,Xe),Mh(i,e,{...t,y0:s},n,r,o)}function Qn(i,e,t,n,r,s,o,a,{cut:l,bucket:c},u=0){let h=(f,d,p)=>{let x=y=>u?(o-y)/u:.5,[g,m,b,v]=[e(t,r,f),e(n,r,f),e(n,r,d),e(t,r,d)];i.tri(g,m,b,a,a,a,[0,x(f),1,x(f),1,x(d)],p),i.tri(g,b,v,a,a,a,[0,x(f),1,x(d),0,x(d)],p)};o<=l+1e-6?h(s,o,Xe):s>=l-1e-6?h(s,o,c):(h(s,l,Xe),h(l,o,c))}function Yv(i,e,t,n,r,s,o,a,l,c){let[u,h,f,d]=[e(t,r,o),e(n,r,o),e(n,s,o),e(t,s,o)],p=(s-r)/c;i.tri(u,h,f,a,a,a,[0,0,1,0,1,p],l),i.tri(u,f,d,a,a,a,[0,0,1,p,0,p],l)}var wC=16777215,TC=13225686,AC=15722456,qv=.08,$v=.085;function Kv(i){let{info:e,state:t,frame:n,fold:r}=i;if(t.cover===null)return;let[s,o,a]=[e.width,e.sill,e.top],l=e.opening.blind??"roller",c=-e.faceOut,u=e.faceRoom;l==="inside"?Vt(i.frames,n,{x0:-.03,x1:s+.03,n0:u,n1:u+.07,y0:a-.02,y1:a+.07},new W(15921906),new W(16250871),r):Vt(i.frames,n,{x0:-.05,x1:s+.05,n0:c-.15,n1:c,y0:a,y1:a+.2},new W(Ov),new W(Wr),r);let h=t.cover2!=null?[[0,s/2,t.cover,t.slats??0],[s/2,s,t.cover2,t.slats2??t.slats??0]]:[[0,s,t.cover,t.slats??0]];for(let[f,d,p,x]of h){let g=Math.min(1,Math.max(0,p));if(g<=.01)continue;let m=a-g*(a-o);l==="inside"?Qn(i.blinds,n,f+.01,d-.01,u+.04,m,a-.02,new W(AC),r):l==="venetian"?EC(i,f,d,c-.07,m,a,x):Qn(i.blinds,n,f,d,c-.07,m,a,new W(wC),r,.045)}}function EC(i,e,t,n,r,s,o){let{frame:a,fold:l}=i,c=new W(TC),u=Math.PI/2*(.12+.88*Math.min(1,Math.max(0,o))),h=Math.sin(u)*$v/2,f=Math.cos(u)*$v/2;for(let d=s-qv/2;d>r;d-=qv){let p=d>=l.cut?l.bucket:Xe,[x,g,m,b]=[a(e,n-h,d+f),a(t,n-h,d+f),a(t,n+h,d-f),a(e,n+h,d-f)];i.blinds.tri(x,g,m,c,c,c,[0,.5,1,.5,1,.5],p),i.blinds.tri(x,m,b,c,c,c,[0,.5,1,.5,0,.5],p)}}function Zv(i){let{info:e,state:t,frame:n,fold:r}=i,[s,o,a]=[e.width,e.top,Math.min(0,e.sill)],l=e.opening.type==="garage"&&(i.markClosed?!!t.sensed&&(t.cover??1)>=.95:(t.cover??1)<.95),c=l?Ue(mi,.8):new W(Vo),u=l?Ue(mi,1):new W(Wr),[h,f]=[-e.faceOut-.012,e.faceRoom+.012],d=(p,x,g)=>Vt(i.frames,n,{x0:p,x1:x,n0:h,n1:f,y0:g,y1:o+.045},c,u,r);d(-.045,.02,a),d(s-.02,s+.045,a),d(.02,s-.02,o-.02)}function Jv(i){let{info:e,state:t,frame:n,fold:r,mid:s}=i,[o,a,l]=[e.width,e.top,Math.min(0,e.sill)],c=a-l,u=_r(e.opening,e.exterior),h=u==="passage",f=w0(u),d=e.opening.swing==="out"?-1:1,p=d>0?e.faceRoom:-e.faceOut,x=e.opening.leaves===2,g=new W(Vo),m=new W(Wr),b=.02,v=o-.02,y=S0(o,u,e.hingeAtStart,e.opening);if(y){for(let[R,A]of y.panels){let C=(O,D,P,I)=>Vt(i.frames,n,{x0:O,x1:D,n0:s-.03,n1:s+.03,y0:P,y1:I},g,m,r);C(R,R+.04,l+.02,a-.02),C(A-.04,A,l+.02,a-.02),C(R,A,l+.02,l+.1),Qn(i.glass,n,R+.04,A-.04,s,l+.1,a-.02,Xr,r)}b=y.x0,v=y.x1}let M=x?(v-b)/2-.004:v-b,S=f?.06:.04;f&&(Vt(i.frames,n,{x0:.02,x1:o-.02,n0:-e.faceOut-.02,n1:e.faceRoom,y0:l,y1:l+.02},new W(vh),m,r),e.exterior&&Vt(i.frames,n,{x0:o/2-.08,x1:o/2+.08,n0:-e.faceOut-.1,n1:-e.faceOut,y0:a+.1,y1:a+.17},Ue(mi,.55),Ue(mi,.85),{cut:r.cut,bucket:Xe}));let _=e.opening.open_angle?Math.min(180,Math.max(5,e.opening.open_angle))*pt:Hv,w=h?[]:[[e.hingeAtStart,t.open]];x&&!h&&w.push([!e.hingeAtStart,t.open2??0]);for(let[R,A]of w){let C=Math.min(1,Math.max(0,A)),O=u==="sliding"?0:C*_,D=u==="sliding"?C*M:0,P=(Q,se,Se)=>{let le=Q*Math.cos(O)-se*Math.sin(O)-D,Ie=p+d*(se*Math.cos(O)+Q*Math.sin(O)+(D?.05:0));return n(R?b+le:v-le,Ie,Se)},I={cut:r.cut,bucket:C>.05?Xe:r.bucket},N=i.markClosed?!!t.sensed&&C<.05:C>.9&&!(R===e.hingeAtStart&&t.assumed),F=N?Ue(mi,.7):new W(f?Uv:Nv),H=N?Ue(mi,.9):new W(f?Bv:Dv),B=(Q,se,Se,le,Ie=-S,st=0)=>Vt(i.frames,P,{x0:Q,x1:se,n0:Ie,n1:st,y0:Se,y1:le},F,H,I);u==="glass"?(B(0,.05,l+.01,a-.01),B(M-.05,M,l+.01,a-.01),B(.05,M-.05,l+.01,l+.12),B(.05,M-.05,a-.08,a-.01),Qn(i.glass,P,.05,M-.05,-S/2,l+.12,a-.08,Xr,I)):B(0,M,l+.01,a-.01),u==="front_glass"?Qn(i.glass,P,.12,M-.12,.001,l+c*.55,a-.18,Xr,I):f&&Qn(i.glass,P,.1,.18,.001,l+.3,a-.3,Xr,I);let X=l+Math.min(1.05,c*.5),V=f?.3:.012,[re,be]=f?[M-.11,M-.08]:[M-.16,M-.05],Y=(Q,se)=>Vt(i.frames,P,{x0:re,x1:be,n0:Q,n1:se,y0:X-V,y1:X+V},new W(zv),new W(Vv),I);if(Y(.004,.05),Y(-S-.05,-S-.004),t.unlocked){let Q=new W(kv);Vt(i.frames,P,{x0:M-.012,x1:M+.004,n0:-S-.004,n1:.004,y0:l+.06,y1:a-.06},Q,Q,{cut:r.cut,bucket:Xe})}}}function jv(i){let{info:e,state:t,frame:n,fold:r}=i,[s,o,a]=[e.width,e.top,Math.min(0,e.sill)],l=Math.min(1,Math.max(0,t.cover??1)),c=new W(13951231),u=e.faceRoom-.03;l>.01&&Qn(i.blinds,n,.02,s-.02,u,a+(o-a)*(1-l),o,c,r,.5);let h=(1-l)*(o-a);h>.01&&Yv(i.blinds,n,.02,s-.02,u,u+h,o+.03,c,r.bucket,.5)}var RC=4936290,CC=7041926,Qv=2764860,eM=9082024;function tM(i,e){let{info:t}=i;return t.opening.type!=="window"||!t.exterior||t.opening.light_well===!1?!1:t.opening.light_well===!0||t.sillVt(i.frames,n,{x0:m,x1:b,n0:v,n1:y,y0:c,y1:u},h,f,r);p(s-d,s,a-l,a),p(o,o+d,a-l,a),p(s-d,o+d,a-l-d,a-l),Vt(i.frames,n,{x0:s,x1:o,n0:a-l,n1:a,y0:c-d,y1:c},h,f,r);let x=(m,b)=>Vt(i.frames,n,{x0:m,x1:b,n0:a-l,n1:a,y0:u-.025,y1:u},new W(Qv),new W(eM),r),g=Math.max(3,Math.round((o-s)/.06));for(let m=0;m<=g;m++){let b=s+(o-s)*m/g;x(b-.008,b+.008)}Vt(i.frames,n,{x0:s,x1:o,n0:a-l-.01,n1:a-l+.02,y0:u-.03,y1:u},new W(Qv),new W(eM),r)}var Ns={open:0,open2:0,tilt:0,tilt2:0,cover:null};function iM(i){let{info:e,frame:t,fold:n,mid:r}=i,[s,o,a]=[e.width,e.sill,e.top],[l,c]=[.04,.025],u=new W(Vo),h=new W(Wr),f=(b,v,y,M)=>Vt(i.frames,t,{x0:b,x1:v,n0:r-c,n1:r+c,y0:y,y1:M},u,h,n);i.first&&f(0,l,o,a),i.last&&f(s-l,s,o,a);let[d,p]=[i.first?l:-i.over[0],i.last?s-l:s+i.over[1]];f(d,p,o,o+.03),f(d,p,a-l,a);let x=e.opening.front?0:e.opening.panes,g=Math.max(1,x==null?Math.max(1,Math.round((p-d)/.9)):Math.round(x)),m=(p-d)/g;for(let b=1;bVt(i.frames,n,{x0:A,x1:C,n0:s-u,n1:s+u,y0:O,y1:D},h,f,r),x=a+(a>.05?c:.03);p(0,c,a,l),p(o-c,o,a,l),p(c,o-c,a,x),p(c,o-c,l-c,l);let g=e.opening.sill_boards??"auto";g!=="none"&&(g!=="auto"||a>.3)&&(g!=="outside"&&Vt(i.frames,n,{x0:-.04,x1:o+.04,n0:s+u,n1:e.faceRoom+.07,y0:a-.03,y1:a},d,f,r),e.exterior&&g!=="inside"&&Vt(i.frames,n,{x0:-.03,x1:o+.03,n0:-e.faceOut-.06,n1:s-u,y0:a-.04,y1:a-.02},d,f,r));let m=.055,[b,v]=[x,l-c],[y,M]=[s+u,s+u+.06],S=e.hingeAtStart,_=e.opening.opens??"turn",w=_==="slide"?PC(o,c,S,e.opening.leaves,t.open,t.open2??0):e.opening.leaves===2?[{atStart:S,x0:S?c:o/2,x1:S?o/2:o-c,open:t.open,tilt:t.tilt},{atStart:!S,x0:S?o/2:c,x1:S?o-c:o/2,open:t.open2??0,tilt:t.tilt2??0}]:[{atStart:S,x0:c,x1:o-c,open:t.open,tilt:t.tilt}],R=_r(e.opening,e.exterior);for(let A of w){let C=_==="top"?Math.max(A.open,A.tilt)*Xv:0,D=(_!=="slide"||!!A.slide)&&(A.open>.02||A.tilt>.02),P=i.markClosed?!!t.sensed&&!D:D,I=P?Ue(mi,.75):new W(Fv),N=P?Ue(mi,.95):f,F=A.x1-A.x0,H=_==="turn",B=H?A.open*Gv:0,X=H?A.tilt*Wv:0,V=(A.slide??0)*A.open,re=_==="slide"&&A.track===0?-.065:0,be=(se,Se,le)=>{if(C>0){let[et,Yt]=[Se-y,le-v],[kt,on]=[Math.cos(C),Math.sin(C)];return n(A.atStart?A.x0+se:A.x1-se,y+et*kt+Yt*on,v-et*on+Yt*kt)}let Ie=le-b,st=Se+Ie*Math.sin(X)+re,Te=b+Ie*Math.cos(X),ht=se*Math.cos(B)-(st-y)*Math.sin(B),bt=y+(st-y)*Math.cos(B)+se*Math.sin(B);return n((A.atStart?A.x0+ht:A.x1-ht)+V,bt,Te)},Y={cut:r.cut,bucket:B>.05||C>.05?Xe:r.bucket},Q=(se,Se,le,Ie,st=y,Te=M)=>Vt(i.frames,be,{x0:se,x1:Se,n0:st,n1:Te,y0:le,y1:Ie},I,N,Y);if(Q(0,m,b,v),Q(F-m,F,b,v),Q(m,F-m,b,b+m),Q(m,F-m,v-m,v),Qn(i.glass,be,m,F-m,(y+M)/2,b+m,v-m,P?Ue(mi,.16):Xr,Y),R==="bars"){let[se,Se]=[(b+v)/2,(y+M)/2];Q(m,F-m,se-.012,se+.012,Se-.012,Se+.012),Q(F/2-.012,F/2+.012,b+m,v-m,Se-.012,Se+.012)}}}var qp=i=>i.opening.front??i.opening.id;function $p(i,e,t,n=-1/0){let r=new lt,s=new lt,o=new lt(!0),a=[],l=[],c=[],u=new Map;i.forEach((x,g)=>{let m=qp(x);u.set(m,[...u.get(m)??[],g])});let h=x=>[[x.start[0],x.start[1]],[x.start[0]+x.axis[0]*x.width,x.start[1]+x.axis[1]*x.width]],f=x=>`${Math.round(x[0]*50)},${Math.round(x[1]*50)}`,d=new Map,p=new Map;for(let x of u.values()){let g=new Map,m=new Map;for(let v of x){let[y,M]=h(i[v]);g.set(f(y),[...g.get(f(y))??[],v]),m.set(f(M),[...m.get(f(M))??[],v])}let b=(v,y)=>{if(y==null||y===v)return 0;let M=Math.abs((i[v].faceRoom-i[v].faceOut)/2),[S,_]=[i[v].axis,i[y].axis],w=Math.max(-1,Math.min(1,S[0]*_[0]+S[1]*_[1])),R=Math.acos(w);return Rw!==v),_=(g.get(f(M))??[]).find(w=>w!==v);d.set(v,[S==null,_==null]),p.set(v,[b(v,S),b(v,_)])}}for(let x=0;x[g.start[0]+g.axis[0]*w+g.toRoom[0]*R,A,g.start[1]+g.axis[1]*w+g.toRoom[1]*R],mid:(g.faceRoom-g.faceOut)/2,markClosed:g.opening.mark==="closed",fold:{cut:t,bucket:g.bucket},frames:r,glass:s,blinds:o,first:y,last:M,over:p.get(x)??[0,0]};(b==="door"&&v!=="passage"||b==="garage")&&Zv(S),b==="door"?Jv(S):b==="garage"?jv(S):v==="glass_wall"?iM(S):rM(S),tM(S,n)&&nM(S,n),b!=="garage"&&Kv(S);let _=qp(g);a.push({id:_,start:m.frames,end:r.count}),l.push({id:_,start:m.glass,end:s.count}),c.push({id:_,start:m.blinds,end:o.count})}return{frames:r.geometry(),glass:s.geometry(),blinds:o.geometry(),frameTris:a,glassTris:l,blindTris:c}}var Kp=Math.PI/180,Rl=2400,Go=1600,Zp=9,sM=360;function Sh(i,e=64){let t=document.createElement("canvas");t.width=t.height=e;let n=t.getContext("2d"),r=n.createRadialGradient(e/2,e/2,0,e/2,e/2,e/2);for(let[s,o]of i)r.addColorStop(s,o);return n.fillStyle=r,n.fillRect(0,0,e,e),new zt(t)}function IC(i){let t=document.createElement("canvas");t.width=128,t.height=128/2;let n=t.getContext("2d"),r=i*9301+49297,s=()=>(r=(r*9301+49297)%233280)/233280;for(let o=0;o<7;o++){let a=128*(.2+.6*s()),l=128/2*(.45+.25*s()),c=128*(.12+.14*s()),u=n.createRadialGradient(a,l,0,a,l,c);u.addColorStop(0,"rgba(255,255,255,0.9)"),u.addColorStop(.6,"rgba(255,255,255,0.45)"),u.addColorStop(1,"rgba(255,255,255,0)"),n.fillStyle=u,n.fillRect(0,0,128,128/2)}return new zt(t)}var wh=class{group=new ct;scene;bounds={x0:-10,x1:10,z0:-10,z1:10,y0:0,y1:8};view=null;rain;rainVel=new Float32Array(Rl*3);snow;snowPhase=new Float32Array(Go);hail;clouds=[];bolt;disc;halo;stars;cover;last=0;nextBolt=0;boltUntil=0;onFlash=null;constructor(e){this.scene=e,this.group.name="live-weather",this.group.renderOrder=5;let t=new Fe;t.setAttribute("position",new ke(new Float32Array(Rl*6),3)),this.rain=new gn(t,new Lt({color:11128309,transparent:!0,opacity:.5,depthWrite:!1}));let n=Sh([[0,"rgba(255,255,255,1)"],[.5,"rgba(255,255,255,0.6)"],[1,"rgba(255,255,255,0)"]],32),r=new Fe;r.setAttribute("position",new ke(new Float32Array(Go*3),3)),this.snow=new xn(r,new cn({color:16185855,size:.16,map:n,transparent:!0,opacity:.9,depthWrite:!1}));for(let h=0;h.02,this.stars.position.set((n.x0+n.x1)/2,n.y0,(n.z0+n.z1)/2),this.stars.scale.setScalar(r*3);let a=this.cover.material,l=(t?.snow??0)+(t?.hail??0)*.5,c=t?.rain??0;a.color.setHex(l>.05?16054527:1848656),a.opacity=l>.05?.3+.45*Math.min(1,l):c>.1?.25*Math.min(1,c):0,this.cover.visible=a.opacity>.02,this.cover.position.set((n.x0+n.x1)/2,n.y0-.18,(n.z0+n.z1)/2),this.cover.scale.set(n.x1-n.x0,n.z1-n.z0,1)}set(e){let t=this.view;this.view=e,this.group.visible=!!e;let n=e?.weather??null;if(e&&n&&n.fog>.02&&!e.low){let r=new W(e.sky[0]/255,e.sky[1]/255,e.sky[2]/255);this.scene.fog=new ls(r,.008+.04*n.fog)}else this.scene.fog instanceof ls&&(this.scene.fog=null);(!t||t.low!==e?.low||!!t.weather!=!!n)&&this.seed(),this.placeDisc(),this.placeNight(),n?.lightning||this.endBolt()}windVector(){let e=this.view?.weather;if(!e)return[0,0];let n=((e.windFrom??270)+(this.view?.north??0)+180)*Kp,r=.4+7*e.wind;return[Math.sin(n)*r,-Math.cos(n)*r]}count(e,t){let n=this.view?.low??!1;return Math.round(Math.min(1,e)*t*(n?.3:1))}seed(){let e=this.bounds,t=this.view?.weather,n=()=>e.x0+Math.random()*(e.x1-e.x0),r=()=>e.z0+Math.random()*(e.z1-e.z0),s=()=>e.y0+Math.random()*(e.y1-e.y0),o=this.rain.geometry.getAttribute("position");for(let c=0;c.01,this.snow.visible=!!t&&t.snow>.01,this.hail.visible=!!t&&t.hail>.01,this.clouds.forEach((c,u)=>{c.angle=u/Zp*Math.PI*2+Math.random()*.5,c.ring=1.7+Math.random()*.9,c.lift=.35+Math.random()*.35,c.scale=.55+Math.random()*.45,c.sx=e.x0+Math.random()*(e.x1-e.x0),c.sz=e.z0+Math.random()*(e.z1-e.z0)}),this.placeClouds(0)}placeClouds(e){let t=this.view,n=t?.weather,r=n?.cloud??0,s=this.bounds,o=(s.x0+s.x1)/2,a=(s.z0+s.z1)/2,l=Math.max(s.x1-s.x0,s.z1-s.z0),[c,u]=this.windVector(),h=Math.round(r*Zp),f=t?.sky??[20,28,44],d=(f[0]+f[1]+f[2])/765,p=n?.rain||n?.lightning?.3:0,x=Math.max(.12,Math.min(1,.28+d*.9-p-.25*Math.max(0,r-.6))),g=Math.hypot(c,u)/Math.max(20,l*4)*e*Math.sign(c||1);this.clouds.forEach((m,b)=>{let v=bs.x1+S&&(m.sx=s.x0-S),m.sxs.z1+S&&(m.sz=s.z0-S),m.sz.9||!r&&t.elevation<.5){this.disc.visible=this.halo.visible=!1;return}let s=this.bounds,o=new U((s.x0+s.x1)/2,s.y0,(s.z0+s.z1)/2),a=Math.max(70,Math.max(s.x1-s.x0,s.z1-s.z0)*3.5),l=((r?t.azimuth+180:t.azimuth)+e.north)*Kp,c=Math.max(8,Math.abs(t.elevation))*Kp,u=new U(Math.sin(l)*Math.cos(c),Math.sin(c),-Math.cos(l)*Math.cos(c)),h=o.addScaledVector(u,a),f=a*(r?.07:.1);this.disc.position.copy(h),this.halo.position.copy(h),this.disc.scale.setScalar(f),this.halo.scale.setScalar(f*3.2);let d=this.disc.material,p=this.halo.material,x=r?0:Math.max(0,1-t.elevation/20);d.color.set(r?14016242:new W(1,.9-.25*x,.6-.35*x)),p.color.copy(d.color),d.opacity=(r?.7:.95)*(1-n),p.opacity=(r?.35:.6)*(1-n),this.disc.visible=this.halo.visible=!0}endBolt(){this.bolt.visible&&(this.bolt.visible=!1,this.onFlash?.(!1))}strike(e){let t=this.bounds,r=(Math.random()<.5?-1:1)<0?t.x0-2-Math.random()*6:t.x1+2+Math.random()*6,s=t.z0+Math.random()*(t.z1-t.z0),o=t.y1+4,a=this.bolt.geometry.getAttribute("position"),l=24,c=o;for(let u=0;u.01&&this.placeClouds(r),n.lightning&&!t.low?(this.nextBolt||(this.nextBolt=e+2500+Math.random()*6e3),e>=this.nextBolt&&(this.strike(e),this.nextBolt=e+3500+Math.random()*9e3),this.bolt.visible&&e>this.boltUntil&&this.endBolt()):this.nextBolt=0,this.rain.visible||this.snow.visible||this.hail.visible||n.cloud>.01||n.lightning}dispose(){this.endBolt(),this.group.traverse(e=>{let t=e;t.geometry?.dispose();let n=t.material;n?.map?.dispose(),n?.dispose()}),this.scene.remove(this.group),this.scene.fog instanceof ls&&(this.scene.fog=null)}};var Th=46,Ah=33,Ds=900;function Jp(){let i=document.createElement("canvas");i.width=i.height=32;let e=i.getContext("2d"),t=e.createRadialGradient(16,16,0,16,16,16);return t.addColorStop(0,"rgba(255,255,255,1)"),t.addColorStop(.35,"rgba(255,255,255,0.7)"),t.addColorStop(1,"rgba(255,255,255,0)"),e.fillStyle=t,e.fillRect(0,0,32,32),new zt(i)}var Eh=class{group=new ct;scene;lift;tex=Jp();arcs=new Map;sparkFields=[];sparks;sparkBase=new Float32Array(Ds*3);sparkField=new Int16Array(Ds);sparkPhase=new Float32Array(Ds);sparkCount=0;last=0;constructor(e,t){this.scene=e,this.lift=t,this.group.name="live-energy";let n=new Fe;n.setAttribute("position",new ke(new Float32Array(Ds*3),3)),n.setAttribute("color",new ke(new Float32Array(Ds*3),3)),this.sparks=new xn(n,new cn({size:.4,map:this.tex,vertexColors:!0,transparent:!0,depthWrite:!1,blending:Ft})),this.sparks.frustumCulled=!1,this.group.add(this.sparks),e.add(this.group)}get active(){return this.arcs.size>0||this.sparkCount>0}setArcs(e){let t=new Set(e.map(n=>n.key));for(let[n,r]of this.arcs)t.has(n)||(this.group.remove(r.line,r.points),r.line.geometry.dispose(),r.line.material.dispose(),r.points.geometry.dispose(),r.points.material.dispose(),this.arcs.delete(n));for(let n of e){let r=this.arcs.get(n.key);if(!r){let o=new Fe;o.setAttribute("position",new ke(new Float32Array(Ah*3),3));let a=new Pn(o,new Lt({transparent:!0,opacity:.4,depthWrite:!1,blending:Ft})),l=new Fe;l.setAttribute("position",new ke(new Float32Array(Th*3),3));let c=new xn(l,new cn({size:.55,map:this.tex,transparent:!0,depthWrite:!1,blending:Ft}));a.frustumCulled=c.frustumCulled=!1;let u=new Float32Array(Th);for(let h=0;hnew U):null,r.points.material.color.copy(s),r.count=n.power<=0?0:Math.max(3,Math.min(Th,Math.round(3+Math.sqrt(n.power)/2.2))),r.speed=.18+Math.min(.5,Math.log10(1+n.power)*.1),r.points.geometry.setDrawRange(0,r.count)}this.place()}setSparks(e){this.sparkFields=e;let t=e.reduce((r,s)=>r+s.quads.length*s.level,0),n=0;t>0&&e.forEach((r,s)=>{if(r.level<=0)return;let o=Math.round(Ds*r.quads.length*r.level/Math.max(t,e.reduce((a,l)=>a+l.quads.length,0)));for(let a=0;a0}world(e,t){let n=this.lift(e.floorId);return t.set(e.x,n.y+e.y,e.z),n.visible}place(){for(let e of this.arcs.values()){if(e.path){this.placeRoute(e,e.path);continue}let t=this.world(e.arc.from,e.a),n=this.world(e.arc.to,e.b),r=e.a.distanceTo(e.b);e.c.copy(e.a).add(e.b).multiplyScalar(.5),e.c.y=Math.max(e.a.y,e.b.y)+.6+r*.22;let s=t&&n;e.line.visible=e.points.visible=s;let o=e.line.geometry.getAttribute("position");for(let a=0;ar=this.world(o,t[a])&&r),e.line.visible=e.points.visible=r,e.along=[0];for(let o=1;os.setXYZ(a,o.x,o.y,o.z)),e.line.geometry.setDrawRange(0,t.length),s.needsUpdate=!0}at(e,t){if(!e.path)return this.bezier(e,t);let n=e.along[e.along.length-1]||1,r=t*n,s=1;for(;s0}set(e,t){let n=new Set(e.map(r=>r.id));for(let[r,s]of this.spots)if(!n.has(r)){for(let o of s.rings)this.group.remove(o),o.material.dispose();this.spots.delete(r)}for(let r of e){let s=this.spots.get(r.id);if(!s){let a=Array.from({length:oM},()=>{let l=new we(this.ringGeo,new Ke({transparent:!0,opacity:0,depthWrite:!1,blending:Ft,side:ut}));return l.rotation.x=-Math.PI/2,l.frustumCulled=!1,this.group.add(l),l});s={spot:r,rings:a},this.spots.set(r.id,s)}s.spot=r;let o=new W(r.color[0]/255,r.color[1]/255,r.color[2]/255);for(let a of s.rings)a.material.color.copy(o)}for(let r of this.links)this.group.remove(r.line),r.line.geometry.dispose(),r.line.material.dispose();this.links=t.map(([r,s])=>{let o=new Fe;o.setAttribute("position",new ke(new Float32Array(51),3));let a=new Pn(o,new Lt({color:12616956,transparent:!0,opacity:.55,depthWrite:!1,blending:Ft}));return a.frustumCulled=!1,this.group.add(a),{a:r,b:s,line:a}})}step(e){if(!this.spots.size&&!this.links.length)return!1;let t=e/1e3;for(let n of this.spots.values()){let r=this.lift(n.spot.at.floorId),s=.9+1.6*n.spot.level;n.rings.forEach((o,a)=>{let l=(t*.55+a/oM)%1;o.visible=r.visible,o.position.set(n.spot.at.x,r.y+n.spot.at.y,n.spot.at.z),o.scale.setScalar((.25+l*s)*(n.spot.size??1)),o.material.opacity=(1-l)*(.35+.5*n.spot.level)})}for(let n of this.links){let r=this.lift(n.a.floorId),s=this.lift(n.b.floorId);n.line.visible=r.visible&&s.visible;let o=n.line.geometry.getAttribute("position"),a=r.y+n.a.y,l=s.y+n.b.y,c=Math.hypot(n.a.x-n.b.x,n.a.z-n.b.z);for(let u=0;u<=16;u++){let h=u/16,f=Math.sin(Math.PI*h)*(.3+c*.12)+Math.sin(t*3+h*12)*.03;o.setXYZ(u,n.a.x+(n.b.x-n.a.x)*h,a+(l-a)*h+f,n.a.z+(n.b.z-n.a.z)*h)}o.needsUpdate=!0}return!0}dispose(){this.set([],[]),this.ringGeo.dispose(),this.scene.remove(this.group)}};var Ch=6,lM=24,aM=Ch*lM;function LC(i,e,t){let n=i%Ch,r=Math.floor(i/Ch),s=(r/lM+e*.7)%1,o=n/Ch*Math.PI*2+e*.35+(r*7%5-2)*.012,a=s*t,l=Math.min(1.2,t/3);return[Math.cos(o)*a,4*l*s*(1-s),Math.sin(o)*a]}var Ph=class{group=new ct;scene;lift;tex=Jp();material=new cn({color:11068159,size:.09,map:this.tex,transparent:!0,opacity:.9,depthWrite:!1});sprays=new Map;constructor(e,t){this.scene=e,this.lift=t,this.group.name="live-water",e.add(this.group)}get active(){return this.sprays.size>0}set(e){let t=new Set(e.map(n=>n.id));for(let[n,r]of this.sprays)t.has(n)||(this.group.remove(r.points),r.points.geometry.dispose(),this.sprays.delete(n));for(let n of e){let r=this.sprays.get(n.id);if(r){r.spot=n;continue}let s=new Fe;s.setAttribute("position",new ke(new Float32Array(aM*3),3));let o=new xn(s,this.material);o.frustumCulled=!1,this.group.add(o),this.sprays.set(n.id,{spot:n,points:o})}}step(e){if(!this.sprays.size)return!1;let t=e/1e3;for(let n of this.sprays.values()){let r=this.lift(n.spot.at.floorId);n.points.visible=r.visible,n.points.position.set(n.spot.at.x,r.y+n.spot.at.y,n.spot.at.z);let s=n.points.geometry.getAttribute("position");for(let o=0;oe.s.playing)}set(e){let t=new Set(e.map(n=>n.id));for(let[n,r]of this.views)t.has(n)||this.drop(n,r);for(let n of e){let r=this.views.get(n.id);if(!r){let o=document.createElement("canvas");o.width=512,o.height=288;let a=new zt(o);a.colorSpace=ft;let l=new we(new sn(1,1),new Ke({map:a,transparent:!0,toneMapped:!1}));l.renderOrder=6;let c=new we(new sn(1,1),new Ke({map:this.glowTex,transparent:!0,depthWrite:!1,blending:Ft,side:ut}));c.renderOrder=2,this.group.add(l,c),r={s:n,sig:"",screen:l,glow:c,canvas:o,texture:a,image:null},this.views.set(n.id,r)}r.s=n;let s=[n.title,n.subtitle,n.app,n.picture,n.color.join(","),n.playing].join("|");if(s!==r.sig){let o=r.sig.split("|")[3]!==(n.picture??"");r.sig=s,o&&this.loadPicture(r),this.draw(r)}this.place(r)}}loadPicture(e){e.image=null;let t=e.s.picture;if(!t)return;let n=new Image;n.crossOrigin="anonymous",n.onload=()=>{e.s.picture!==t||!this.views.has(e.s.id)||(e.image=n,this.draw(e),this.onChange?.())},n.src=t}draw(e){let t=e.s,n=e.canvas.getContext("2d"),r=e.canvas.width,s=e.canvas.height,[o,a,l]=t.color,c=n.createLinearGradient(0,0,r,s);c.addColorStop(0,`rgb(${Math.round(o*.35)},${Math.round(a*.35)},${Math.round(l*.35)})`),c.addColorStop(1,"rgb(6,9,18)"),n.fillStyle=c,n.fillRect(0,0,r,s);let u=22,h=u;if(e.image){let f=s-u*2-30;n.save(),n.shadowColor=`rgba(${o},${a},${l},0.7)`,n.shadowBlur=24;let d=e.image.naturalWidth||1,p=e.image.naturalHeight||1,x=Math.max(f/d,f/p),g=f/x,m=f/x;n.drawImage(e.image,(d-g)/2,(p-m)/2,g,m,u,u,f,f),n.restore(),h=u*2+f}n.fillStyle="#ffffff",n.font="600 34px Figtree, Roboto, sans-serif",this.text(n,t.title||t.app||"",h,s/2-18,r-h-u),n.fillStyle="rgba(230,240,255,0.75)",n.font="26px Figtree, Roboto, sans-serif",this.text(n,t.subtitle,h,s/2+22,r-h-u),t.app&&(n.fillStyle=`rgb(${o},${a},${l})`,n.font="700 22px Figtree, Roboto, sans-serif",this.text(n,(t.playing?"\u25B6 ":"\u275A\u275A ")+t.app,h,s-u-14,r-h-u)),n.fillStyle=`rgba(${o},${a},${l},0.9)`,n.fillRect(0,s-6,r*(t.playing?1:.4),6),e.texture.needsUpdate=!0}text(e,t,n,r,s){let o=t;for(;o.length>1&&e.measureText(o).width>s;)o=o.slice(0,-2);e.fillText(o===t?o:`${o}\u2026`,n,r)}place(e){let t=e.s,n=t.rect,r=t.rotation*FC,s=this.lift(t.floorId),o=(n.x0+n.x1)/2,a=(p,x)=>[t.x+p*Math.cos(r)-x*Math.sin(r),t.z+p*Math.sin(r)+x*Math.cos(r)],l=n.x1-n.x0,c=n.y1-n.y0,[u,h]=a(o,n.z+.012);e.screen.position.set(u,s.y+(n.y0+n.y1)/2,h),e.screen.rotation.set(0,-r,0),e.screen.scale.set(l,c,1);let[f,d]=a(o,n.z-.18);e.glow.position.set(f,s.y+(n.y0+n.y1)/2,d),e.glow.rotation.set(0,-r,0),e.glow.scale.set(l*2.4,c*2.6,1),e.glow.material.color=new W(t.color[0]/255,t.color[1]/255,t.color[2]/255),e.screen.visible=s.visible,e.glow.visible=s.visible&&(t.ambilight??1)>0}step(e){let t=!1;for(let n of this.views.values()){this.place(n);let r=n.glow.material;r.opacity=(n.s.playing?.55+.25*Math.sin(e/900+n.s.x):.25)*Math.min(1.5,n.s.ambilight??1),t||=n.s.playing}return t}drop(e,t){this.group.remove(t.screen,t.glow),t.screen.geometry.dispose(),t.screen.material.dispose(),t.texture.dispose(),t.glow.geometry.dispose(),t.glow.material.dispose(),this.views.delete(e)}dispose(){for(let[e,t]of this.views)this.drop(e,t);this.glowTex.dispose(),this.scene.remove(this.group)}};var NC=Math.PI/180,DC="#f4f1ea",Lh=class{group=new ct;scene;lift;views=new Map;onChange=null;constructor(e,t){this.scene=e,this.lift=t,this.group.name="live-pictures",e.add(this.group)}set(e){let t=new Set(e.map(n=>n.id));for(let[n,r]of this.views)t.has(n)||this.drop(n,r);for(let n of e){let r=this.views.get(n.id);if(!r){let c=document.createElement("canvas"),u=new zt(c);u.colorSpace=ft;let h=new we(new sn(1,1),new Ke({map:u,toneMapped:!1}));h.renderOrder=5,this.group.add(h),r={p:n,sig:"",mesh:h,canvas:c,texture:u,image:null},this.views.set(n.id,r)}let s=r.p.url!==n.url||!r.sig;r.p=n;let o=n.rect.x1-n.rect.x0,a=n.rect.y1-n.rect.y0,l=[n.url,n.border,n.fit,o.toFixed(3),a.toFixed(3)].join("|");l!==r.sig&&(r.sig=l,s&&this.load(r),this.draw(r)),this.place(r)}}load(e){e.image=null;let t=e.p.url,n=new Image;n.crossOrigin="anonymous",n.onload=()=>{e.p.url!==t||!this.views.has(e.p.id)||(e.image=n,this.draw(e),this.onChange?.())},n.src=t}draw(e){let t=e.p,n=Math.max(.01,t.rect.x1-t.rect.x0),r=Math.max(.01,t.rect.y1-t.rect.y0),s=600/Math.max(n,r),o=e.canvas.width=Math.max(16,Math.round(n*s)),a=e.canvas.height=Math.max(16,Math.round(r*s)),l=e.canvas.getContext("2d");l.fillStyle=t.border>0?DC:"#20242c",l.fillRect(0,0,o,a);let c=Math.round(Math.min(o,a)*Math.min(40,Math.max(0,t.border))/100),[u,h,f,d]=[c,c,o-2*c,a-2*c];if(e.image&&f>4&&d>4){let p=e.image.naturalWidth||1,x=e.image.naturalHeight||1;if(t.fit==="contain"){let g=Math.min(f/p,d/x);l.drawImage(e.image,u+(f-p*g)/2,h+(d-x*g)/2,p*g,x*g)}else{let g=Math.max(f/p,d/x),m=f/g,b=d/g;l.drawImage(e.image,(p-m)/2,(x-b)/2,m,b,u,h,f,d)}c>0&&(l.strokeStyle="rgba(0,0,0,0.25)",l.lineWidth=Math.max(1,c*.04),l.strokeRect(u,h,f,d))}else f>4&&d>4&&(l.fillStyle="#3a4250",l.fillRect(u,h,f,d));e.texture.needsUpdate=!0}place(e){let t=e.p,n=t.rect,r=t.rotation*NC,s=this.lift(t.floorId),o=(n.x0+n.x1)/2,a=n.z+.004;e.mesh.position.set(t.x+o*Math.cos(r)-a*Math.sin(r),s.y+(n.y0+n.y1)/2,t.z+o*Math.sin(r)+a*Math.cos(r)),e.mesh.rotation.set(0,-r,0),e.mesh.scale.set(n.x1-n.x0,n.y1-n.y0,1),e.mesh.visible=s.visible}step(){for(let e of this.views.values())this.place(e);return!1}drop(e,t){this.group.remove(t.mesh),t.mesh.geometry.dispose(),t.mesh.material.dispose(),t.texture.dispose(),this.views.delete(e)}dispose(){for(let[e,t]of this.views)this.drop(e,t);this.scene.remove(this.group)}};var Fh=class extends Tn{constructor(){super(),this.name="RoomEnvironment",this.position.y=-3.5;let e=new Fr;e.deleteAttribute("uv");let t=new In({side:un}),n=new In,r=new ps(16777215,900,28,2);r.position.set(.418,16.199,.3),this.add(r);let s=new we(e,t);s.position.set(-.757,13.219,.717),s.scale.set(31.713,28.305,28.591),this.add(s);let o=new hs(e,n,6),a=new Et;a.position.set(-10.906,2.009,1.846),a.rotation.set(0,-.195,0),a.scale.set(2.328,7.905,4.651),a.updateMatrix(),o.setMatrixAt(0,a.matrix),a.position.set(-5.607,-.754,-.758),a.rotation.set(0,.994,0),a.scale.set(1.97,1.534,3.955),a.updateMatrix(),o.setMatrixAt(1,a.matrix),a.position.set(6.167,.857,7.803),a.rotation.set(0,.561,0),a.scale.set(3.927,6.285,3.687),a.updateMatrix(),o.setMatrixAt(2,a.matrix),a.position.set(-2.017,.018,6.124),a.rotation.set(0,.333,0),a.scale.set(2.002,4.566,2.064),a.updateMatrix(),o.setMatrixAt(3,a.matrix),a.position.set(2.291,-.756,-2.621),a.rotation.set(0,-.286,0),a.scale.set(1.546,1.552,1.496),a.updateMatrix(),o.setMatrixAt(4,a.matrix),a.position.set(-2.193,-.369,-5.547),a.rotation.set(0,.516,0),a.scale.set(3.875,3.487,2.986),a.updateMatrix(),o.setMatrixAt(5,a.matrix),this.add(o);let l=new we(e,Ho(50));l.position.set(-16.116,14.37,8.208),l.scale.set(.1,2.428,2.739),this.add(l);let c=new we(e,Ho(50));c.position.set(-16.109,18.021,-8.207),c.scale.set(.1,2.425,2.751),this.add(c);let u=new we(e,Ho(17));u.position.set(14.904,12.198,-1.832),u.scale.set(.15,4.265,6.331),this.add(u);let h=new we(e,Ho(43));h.position.set(-.462,8.89,14.52),h.scale.set(4.38,5.441,.088),this.add(h);let f=new we(e,Ho(20));f.position.set(3.235,11.486,-12.541),f.scale.set(2.5,2,.1),this.add(f);let d=new we(e,Ho(100));d.position.set(0,20,0),d.scale.set(1,.1,1),this.add(d)}dispose(){let e=new Set;this.traverse(t=>{t.isMesh&&(e.add(t.geometry),e.add(t.material))});for(let t of e)t.dispose()}};function Ho(i){return new Pa({color:0,emissive:16777215,emissiveIntensity:i})}function jp(i,e){if(e===Kf)return console.warn("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles."),i;if(e===Mo||e===qa){let t=i.getIndex();if(t===null){let s=[],o=i.getAttribute("position");if(o!==void 0){for(let a=0;ao&&(O+=B,D+=X,P+=V)}let I=1/(Math.sqrt(O*O+D*D+P*P)||1);v[3*A+0]=O*I,v[3*A+1]=D*I,v[3*A+2]=P*I}}return t.setAttribute("normal",new wt(v,3,!1)),t}function uM(i){let e=new Map,t=new Map,n=i.clone();return hM(i,n,function(r,s){e.set(s,r),t.set(r,s)}),n.traverse(function(r){if(!r.isSkinnedMesh)return;let s=r,o=e.get(r),a=o.skeleton.bones;s.skeleton=o.skeleton.clone(),s.bindMatrix.copy(o.bindMatrix),s.skeleton.bones=a.map(function(l){return t.get(l)}),s.bind(s.skeleton,s.bindMatrix)}),n}function hM(i,e,t){t(i,e);for(let n=0;n=2.0 are supported."));return}let c=new Em(s,{path:t||this.resourcePath||"",crossOrigin:this.crossOrigin,priority:this.priority,cache:this.cache,withCredentials:this.withCredentials,requestHeader:this.requestHeader,manager:this.manager,ktx2Loader:this.ktx2Loader,meshoptDecoder:this.meshoptDecoder});c.fileLoader.setRequestHeader(this.requestHeader);for(let u=0;u=0&&a[h]===void 0&&console.warn('THREE.GLTFLoader: Unknown extension "'+h+'".')}}c.setExtensions(o),c.setPlugins(a),c.parse(n,r)}parseAsync(e,t){let n=this;return new Promise(function(r,s){n.parse(e,t,r,s)})}};function UC(){let i={};return{get:function(e){return i[e]},add:function(e,t){i[e]=t},remove:function(e){delete i[e]},removeAll:function(){i={}}}}function Bt(i,e,t){let n=i.json.materials[e];return n.extensions&&n.extensions[t]?n.extensions[t]:null}var nt={KHR_BINARY_GLTF:"KHR_binary_glTF",KHR_DRACO_MESH_COMPRESSION:"KHR_draco_mesh_compression",KHR_LIGHTS_PUNCTUAL:"KHR_lights_punctual",KHR_MATERIALS_CLEARCOAT:"KHR_materials_clearcoat",KHR_MATERIALS_DIFFUSE_ROUGHNESS:"KHR_materials_diffuse_roughness",KHR_MATERIALS_DISPERSION:"KHR_materials_dispersion",KHR_MATERIALS_IOR:"KHR_materials_ior",KHR_MATERIALS_SHEEN:"KHR_materials_sheen",KHR_MATERIALS_SPECULAR:"KHR_materials_specular",KHR_MATERIALS_TRANSMISSION:"KHR_materials_transmission",KHR_MATERIALS_IRIDESCENCE:"KHR_materials_iridescence",KHR_MATERIALS_ANISOTROPY:"KHR_materials_anisotropy",KHR_MATERIALS_UNLIT:"KHR_materials_unlit",KHR_MATERIALS_VOLUME:"KHR_materials_volume",KHR_TEXTURE_BASISU:"KHR_texture_basisu",KHR_TEXTURE_TRANSFORM:"KHR_texture_transform",KHR_MESH_QUANTIZATION:"KHR_mesh_quantization",KHR_MATERIALS_EMISSIVE_STRENGTH:"KHR_materials_emissive_strength",EXT_MATERIALS_BUMP:"EXT_materials_bump",EXT_TEXTURE_WEBP:"EXT_texture_webp",EXT_TEXTURE_AVIF:"EXT_texture_avif",EXT_MESHOPT_COMPRESSION:"EXT_meshopt_compression",KHR_MESHOPT_COMPRESSION:"KHR_meshopt_compression",EXT_MESH_GPU_INSTANCING:"EXT_mesh_gpu_instancing"},nm=class{constructor(e){this.parser=e,this.name=nt.KHR_LIGHTS_PUNCTUAL,this.cache={refs:{},uses:{}}}_markDefs(){let e=this.parser,t=this.parser.json.nodes||[];for(let n=0,r=t.length;n=0)throw new Error("THREE.GLTFLoader: setKTX2Loader must be called before loading KTX2 textures");return null}return t.loadTextureImage(e,s.source,o)}},xm=class{constructor(e){this.parser=e,this.name=nt.EXT_TEXTURE_WEBP}loadTexture(e){let t=this.name,n=this.parser,r=n.json,s=r.textures[e];if(!s.extensions||!s.extensions[t])return null;let o=s.extensions[t],a=r.images[o.source],l=n.textureLoader;if(a.uri){let c=n.options.manager.getHandler(a.uri);c!==null&&(l=c)}return n.loadTextureImage(e,o.source,l)}},bm=class{constructor(e){this.parser=e,this.name=nt.EXT_TEXTURE_AVIF}loadTexture(e){let t=this.name,n=this.parser,r=n.json,s=r.textures[e];if(!s.extensions||!s.extensions[t])return null;let o=s.extensions[t],a=r.images[o.source],l=n.textureLoader;if(a.uri){let c=n.options.manager.getHandler(a.uri);c!==null&&(l=c)}return n.loadTextureImage(e,o.source,l)}},Oh=class{constructor(e,t){this.name=t,this.parser=e}loadBufferView(e){let t=this.parser.json,n=t.bufferViews[e];if(n.extensions&&n.extensions[this.name]){let r=n.extensions[this.name],s=this.parser.getDependency("buffer",r.buffer),o=this.parser.options.meshoptDecoder;if(!o||!o.supported){if(t.extensionsRequired&&t.extensionsRequired.indexOf(this.name)>=0)throw new Error("THREE.GLTFLoader: setMeshoptDecoder must be called before loading compressed files");return null}return s.then(function(a){let l=r.byteOffset||0,c=r.byteLength||0,u=r.count,h=r.byteStride,f=new Uint8Array(a,l,c);return o.decodeGltfBufferAsync?o.decodeGltfBufferAsync(u,h,f,r.mode,r.filter).then(function(d){return d.buffer}):o.ready.then(function(){let d=new ArrayBuffer(u*h);return o.decodeGltfBuffer(new Uint8Array(d),u,h,f,r.mode,r.filter),d})})}else return null}},ym=class{constructor(e){this.name=nt.EXT_MESH_GPU_INSTANCING,this.parser=e}createNodeMesh(e){let t=this.parser.json,n=t.nodes[e];if(!n.extensions||!n.extensions[this.name]||n.mesh===void 0)return null;let r=t.meshes[n.mesh];for(let c of r.primitives)if(c.mode!==ei.TRIANGLES&&c.mode!==ei.TRIANGLE_STRIP&&c.mode!==ei.TRIANGLE_FAN&&c.mode!==void 0)return null;let o=n.extensions[this.name].attributes,a=[],l={};for(let c in o)a.push(this.parser.getDependency("accessor",o[c]).then(u=>(l[c]=u,l[c])));return a.length<1?null:(a.push(this.parser.createNodeMesh(e)),Promise.all(a).then(c=>{let u=c.pop(),h=u.isGroup?u.children:[u],f=c[0].count,d=[];for(let p of h){let x=new Be,g=new U,m=new Sn,b=new U(1,1,1),v=new hs(p.geometry,p.material,f);for(let M=0;M0||i.search(/^data\:image\/jpeg/)===0?"image/jpeg":i.search(/\.webp($|\?)/i)>0||i.search(/^data\:image\/webp/)===0?"image/webp":i.search(/\.ktx2($|\?)/i)>0||i.search(/^data\:image\/ktx2/)===0?"image/ktx2":"image/png"}var XC=new Be,Em=class{constructor(e={},t={}){this.json=e,this.extensions={},this.plugins={},this.options=t,this.cache=new UC,this.associations=new Map,this.primitiveCache={},this.nodeCache={},this.meshCache={refs:{},uses:{}},this.cameraCache={refs:{},uses:{}},this.lightCache={refs:{},uses:{}},this.sourceCache={},this.textureCache={},this.nodeNamesUsed={};let n=!1,r=-1,s=!1,o=-1;if(typeof navigator<"u"&&typeof navigator.userAgent<"u"){let a=navigator.userAgent;n=/^((?!chrome|android).)*safari/i.test(a)===!0;let l=a.match(/Version\/(\d+)/);r=n&&l?parseInt(l[1],10):-1,s=a.indexOf("Firefox")>-1,o=s?a.match(/Firefox\/([0-9]+)\./)[1]:-1}typeof createImageBitmap>"u"||n&&r<17||s&&o<98?(this.textureLoader=new Fa(this.options.manager),this.textureLoader.setPriority(this.options.priority),this.textureLoader.setCache(this.options.cache)):(this.textureLoader=new Ua(this.options.manager),this.textureLoader.setPriority(this.options.priority),this.textureLoader.setCache(this.options.cache)),this.textureLoader.setCrossOrigin(this.options.crossOrigin),this.textureLoader.setWithCredentials(this.options.withCredentials),this.textureLoader.setRequestHeader(this.options.requestHeader),this.fileLoader=new mo(this.options.manager),this.fileLoader.setPriority(this.options.priority),this.fileLoader.setCache(this.options.cache),this.fileLoader.setResponseType("arraybuffer"),(this.options.withCredentials||this.options.crossOrigin==="use-credentials")&&this.fileLoader.setWithCredentials(!0)}setExtensions(e){this.extensions=e}setPlugins(e){this.plugins=e}parse(e,t){let n=this,r=this.json,s=this.extensions;this.cache.removeAll(),this.nodeCache={},this._invokeAll(function(o){return o._markDefs&&o._markDefs()}),Promise.all(this._invokeAll(function(o){return o.beforeRoot&&o.beforeRoot()})).then(function(){return Promise.all([n.getDependencies("scene"),n.getDependencies("animation"),n.getDependencies("camera")])}).then(function(o){let a={scene:o[0][r.scene||0],scenes:o[0],animations:o[1],cameras:o[2],asset:r.asset,parser:n,userData:{}};return Us(s,a,r),Ui(a,r),Promise.all(n._invokeAll(function(l){return l.afterRoot&&l.afterRoot(a)})).then(function(){for(let l of a.scenes)l.updateMatrixWorld();e(a)})}).catch(t)}_markDefs(){let e=this.json.nodes||[],t=this.json.skins||[],n=this.json.meshes||[];for(let r=0,s=t.length;r{let l=this.associations.get(o);l!=null&&this.associations.set(a,l);for(let[c,u]of o.children.entries())s(u,a.children[c])};return s(n,r),r.name+="_instance_"+e.uses[t]++,r}_invokeOne(e){let t=Object.values(this.plugins);t.push(this);for(let n=0;n=2&&g.setY(R,S[_*l+1]),l>=3&&g.setZ(R,S[_*l+2]),l>=4&&g.setW(R,S[_*l+3]),l>=5)throw new Error("THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.")}g.normalized=p}return g})}loadTexture(e){let t=this.json,n=this.options,s=t.textures[e].source,o=t.images[s],a=this.textureLoader;if(o.uri){let l=n.manager.getHandler(o.uri);l!==null&&(a=l)}return this.loadTextureImage(e,s,a)}loadTextureImage(e,t,n){let r=this,s=this.json,o=s.textures[e],a=s.images[t],l=(a.uri||a.bufferView)+":"+o.sampler;if(this.textureCache[l])return this.textureCache[l];let c=this.loadImageSource(t,n).then(function(u){u.flipY=!1,u.name=o.name||a.name||"",u.name===""&&typeof a.uri=="string"&&a.uri.startsWith("data:image/")===!1&&(u.name=a.uri);let f=(s.samplers||{})[o.sampler]||{};return u.magFilter=dM[f.magFilter]||Ht,u.minFilter=dM[f.minFilter]||Fn,u.wrapS=pM[f.wrapS]||kn,u.wrapT=pM[f.wrapT]||kn,u.generateMipmaps=!u.isCompressedTexture&&u.minFilter!==Ut&&u.minFilter!==Ht,r.associations.set(u,{textures:e}),u}).catch(function(){return null});return this.textureCache[l]=c,c}loadImageSource(e,t){let n=this,r=this.json,s=this.options;if(this.sourceCache[e]!==void 0)return this.sourceCache[e].then(f=>f.clone());let o=r.images[e],a=self.URL||self.webkitURL,l=o.uri||"",c=!1,u;if(t.isKTX2Loader===!0&&o.bufferView!==void 0)u=n.getDependency("bufferView",o.bufferView).then(function(f){return new Promise(function(d,p){t.parse(f,d,p)})});else{if(o.bufferView!==void 0)l=n.getDependency("bufferView",o.bufferView).then(function(f){c=!0;let d=new Blob([f],{type:o.mimeType});return l=a.createObjectURL(d),l});else if(o.uri===void 0)throw new Error("THREE.GLTFLoader: Image "+e+" is missing URI and bufferView");u=Promise.resolve(l).then(function(f){return new Promise(function(d,p){let x=d;t.isImageBitmapLoader===!0&&(x=function(g){let m=new Kt(g);m.needsUpdate=!0,d(m)}),t.load(or.resolveURL(f,s.path),x,void 0,p)})})}let h=u.then(function(f){return c===!0&&a.revokeObjectURL(l),Ui(f,o),f.userData.mimeType=o.mimeType||WC(o.uri),f}).catch(function(f){throw console.error("THREE.GLTFLoader: Couldn't load texture",l),f});return this.sourceCache[e]=h,h}assignTexture(e,t,n,r){let s=this;return this.getDependency("texture",n.index).then(function(o){if(!o)return null;if(n.texCoord!==void 0&&n.texCoord>0&&(o=o.clone(),o.channel=n.texCoord),s.extensions[nt.KHR_TEXTURE_TRANSFORM]){let a=n.extensions!==void 0?n.extensions[nt.KHR_TEXTURE_TRANSFORM]:void 0;if(a){let l=s.associations.get(o);o=s.extensions[nt.KHR_TEXTURE_TRANSFORM].extendTexture(o,a),s.associations.set(o,l)}}return r!==void 0&&(o.colorSpace=r),e[t]=o,o})}assignFinalMaterial(e){let t=e.geometry,n=e.material,r=t.attributes.tangent===void 0,s=t.attributes.color!==void 0,o=t.attributes.normal===void 0;if(e.isPoints){let a="PointsMaterial:"+n.uuid,l=this.cache.get(a);l||(l=new cn,mn.prototype.copy.call(l,n),l.color.copy(n.color),l.map=n.map,l.sizeAttenuation=!1,this.cache.add(a,l)),n=l}else if(e.isLine){let a="LineBasicMaterial:"+n.uuid,l=this.cache.get(a);l||(l=new Lt,mn.prototype.copy.call(l,n),l.color.copy(n.color),l.map=n.map,this.cache.add(a,l)),n=l}if(r||s||o){let a="ClonedMaterial:"+n.uuid+":";r&&(a+="derivative-tangents:"),s&&(a+="vertex-colors:"),o&&(a+="flat-shading:");let l=this.cache.get(a);l||(l=n.clone(),s&&(l.vertexColors=!0),o&&(l.flatShading=!0),r&&(l.normalScale&&(l.normalScale.y*=-1),l.clearcoatNormalScale&&(l.clearcoatNormalScale.y*=-1)),this.cache.add(a,l),this.associations.set(l,this.associations.get(n))),n=l}e.material=n}getMaterialType(){return In}loadMaterial(e){let t=this,n=this.json,r=this.extensions,s=n.materials[e],o,a={},l=s.extensions||{},c=[];if(l[nt.KHR_MATERIALS_UNLIT]){let h=r[nt.KHR_MATERIALS_UNLIT];o=h.getMaterialType(),c.push(h.extendParams(a,s,t))}else{let h=s.pbrMetallicRoughness||{};if(a.color=new W(1,1,1),a.opacity=1,Array.isArray(h.baseColorFactor)){let f=h.baseColorFactor;a.color.setRGB(f[0],f[1],f[2],Mn),a.opacity=f[3]}h.baseColorTexture!==void 0&&c.push(t.assignTexture(a,"map",h.baseColorTexture,ft)),a.metalness=h.metallicFactor!==void 0?h.metallicFactor:1,a.roughness=h.roughnessFactor!==void 0?h.roughnessFactor:1,h.metallicRoughnessTexture!==void 0&&(c.push(t.assignTexture(a,"metalnessMap",h.metallicRoughnessTexture)),c.push(t.assignTexture(a,"roughnessMap",h.metallicRoughnessTexture))),o=this._invokeOne(function(f){return f.getMaterialType&&f.getMaterialType(e)}),c.push(Promise.all(this._invokeAll(function(f){return f.extendMaterialParams&&f.extendMaterialParams(e,a)})))}s.doubleSided===!0&&(a.side=ut);let u=s.alphaMode||em.OPAQUE;if(u===em.BLEND?(a.transparent=!0,a.depthWrite=!1):(a.transparent=!1,u===em.MASK&&(a.alphaTest=s.alphaCutoff!==void 0?s.alphaCutoff:.5)),s.normalTexture!==void 0&&o!==Ke&&(c.push(t.assignTexture(a,"normalMap",s.normalTexture)),a.normalScale=new De(1,1),s.normalTexture.scale!==void 0)){let h=s.normalTexture.scale;a.normalScale.set(h,h)}if(s.occlusionTexture!==void 0&&o!==Ke&&(c.push(t.assignTexture(a,"aoMap",s.occlusionTexture)),s.occlusionTexture.strength!==void 0&&(a.aoMapIntensity=s.occlusionTexture.strength)),s.emissiveFactor!==void 0&&o!==Ke){let h=s.emissiveFactor;a.emissive=new W().setRGB(h[0],h[1],h[2],Mn)}return s.emissiveTexture!==void 0&&o!==Ke&&c.push(t.assignTexture(a,"emissiveMap",s.emissiveTexture,ft)),Promise.all(c).then(function(){let h=new o(a);return s.name&&(h.name=s.name),Ui(h,s),t.associations.set(h,{materials:e}),s.extensions&&Us(r,h,s),h})}createUniqueName(e){let t=gt.sanitizeNodeName(e||"");return t in this.nodeNamesUsed?t+"_"+ ++this.nodeNamesUsed[t]:(this.nodeNamesUsed[t]=0,t)}loadGeometries(e){let t=this,n=this.extensions,r=this.primitiveCache;function s(a){return n[nt.KHR_DRACO_MESH_COMPRESSION].decodePrimitive(a,t).then(function(l){return mM(l,a,t)})}let o=[];for(let a=0,l=e.length;ajp(d,qa)):c.mode===ei.TRIANGLE_FAN&&(f=f.then(d=>jp(d,Mo))),r[u]={primitive:c,promise:f},o.push(f)}}return Promise.all(o)}loadMesh(e){let t=this,n=this.json,r=this.extensions,s=n.meshes[e],o=s.primitives,a=[];for(let l=0,c=o.length;l0&&GC(m,s),m.name=t.createUniqueName(s.name||"mesh_"+e),Ui(m,s),g.extensions&&Us(r,m,g),t.assignFinalMaterial(m),h.push(m)}for(let d=0,p=h.length;d0){let d=u.userData.pivot,p=h[0];u.pivot=new U().fromArray(d),u.position.x-=d[0],u.position.y-=d[1],u.position.z-=d[2],p.position.set(0,0,0),delete u.userData.pivot}return u})}_loadNodeShallow(e){let t=this.json,n=this.extensions,r=this;if(this.nodeCache[e]!==void 0)return this.nodeCache[e];let s=t.nodes[e],o=s.name?r.createUniqueName(s.name):"",a=[],l=r._invokeOne(function(c){return c.createNodeMesh&&c.createNodeMesh(e)});return l&&a.push(l),s.camera!==void 0&&a.push(r.getDependency("camera",s.camera).then(function(c){return r._getNodeRef(r.cameraCache,s.camera,c)})),r._invokeAll(function(c){return c.createNodeAttachment&&c.createNodeAttachment(e)}).forEach(function(c){a.push(c)}),this.nodeCache[e]=Promise.all(a).then(function(c){let u;if(s.isBone===!0?u=new ho:c.length>1?u=new ct:c.length===1?u=c[0]:u=new Et,u!==c[0])for(let h=0,f=c.length;h1){let h=r.associations.get(u);r.associations.set(u,{...h})}return r.associations.get(u).nodes=e,u}),this.nodeCache[e]}loadScene(e){let t=this.extensions,n=this.json.scenes[e],r=this,s=new ct;n.name&&(s.name=r.createUniqueName(n.name)),Ui(s,n),n.extensions&&Us(t,s,n);let o=n.nodes||[],a=[];for(let l=0,c=o.length;l{let h=new Map;for(let[f,d]of r.associations)(f instanceof mn||f instanceof Kt)&&h.set(f,d);return u.traverse(f=>{let d=r.associations.get(f);d!=null&&h.set(f,d)}),h};return r.associations=c(s),s})}_createAnimationTracks(e,t,n,r,s){let o=[],a=e.name?e.name:e.uuid,l=[];function c(d){d.morphTargetInfluences&&l.push(d.name?d.name:d.uuid)}Yr[s.path]===Yr.weights?(c(e),e.isGroup&&e.children.forEach(c)):l.push(a);let u;switch(Yr[s.path]){case Yr.weights:u=nr;break;case Yr.rotation:u=ir;break;case Yr.translation:case Yr.scale:u=Or;break;default:n.itemSize===1?u=nr:u=Or;break}let h=r.interpolation!==void 0?kC[r.interpolation]:Zi,f=this._getArrayFromAccessor(n);for(let d=0,p=l.length;d{let t=e;if(!t.isMesh)return;let n=t.geometry,r=t.material,s=r.name??"";t.userData.paint=!!r.userData?.paint||/^Paint/.test(s),n.getAttribute("normal")||(t.userData.paint?n.computeVertexNormals():t.geometry=cM(n,qC)),r.flatShading=!1;let o=/glass/i.test(s);r.metalness=t.userData.paint?.55:o?0:Math.min(r.metalness??0,.4),r.roughness=t.userData.paint?.28:o?.05:Math.max(r.roughness??.6,.45),o&&(r.transparent=!0,r.depthWrite=!1,r.opacity=Math.max(r.opacity,.9))})}function yM(i){let e=xM.get(i);if(!e){let t=D0();if(!t)return Promise.resolve(!1);e=t(i).then(n=>n&&new Promise(r=>{new Xo().parse(n,"",s=>{$C(s.scene);let o=new Ct().setFromObject(s.scene),a=[o.max.x-o.min.x,o.max.y-o.min.y,o.max.z-o.min.z];s.scene.position.set(-(o.max.x+o.min.x)/2,-o.min.y,-(o.max.z+o.min.z)/2);let l=new ct;l.add(s.scene),bM.set(i,{root:l,size:a}),U0(i),r({root:l,size:a})},()=>r(null))})).catch(()=>null),xM.set(i,e)}return e.then(t=>!!t)}function _M(i,e){let t=bM.get(i);if(!t)return null;let n=t.root.clone(!0),r=[];n.traverse(o=>{let a=o;if(!a.isMesh)return;let l=a.material.clone();a.userData.paint&&e.paint&&(l.color=new W(e.paint)),a.material=l,r.push(l)});let s=new ct;return s.add(n),s.scale.set((e.mirror?-1:1)*(e.w/t.size[0]),e.h/t.size[1],e.d/t.size[2]),s.position.set(e.x,e.y,e.z),s.rotation.y=-e.rotation*Math.PI/180,s.userData.own=r,s}function Rm(i){for(let e of i.userData.own??[])e.dispose()}function vM(i,e){let t=new wo(e),n=t.fromScene(new Fh,.04).texture;t.dispose();let r=new ds(16777215,9081766,.9),s=new sr(16777215,1.6);return s.position.set(-4,9,6),i.add(r,s),{env:n,dispose:()=>{n.dispose(),r.removeFromParent(),s.removeFromParent()}}}function MM(i,e){for(let t of i.userData.own??[])t.envMap=e,t.envMapIntensity=.9}var KC=.3,SM=2.6,Dh=.05;function ZC(i,e,t,n){let r=n*.7071,s=[i,[i[0]+n,i[1]],[i[0]-n,i[1]],[i[0],i[1]+n],[i[0],i[1]-n]],o=[[i[0]+r,i[1]+r],[i[0]-r,i[1]+r],[i[0]+r,i[1]-r],[i[0]-r,i[1]-r]];return s.every(a=>Ve(a,e))&&!t.some(a=>[...s,...o].some(l=>Ve(l,a)))}function wM(i,e,t){let n=Math.ceil(Math.hypot(e[0]-i[0],e[1]-i[1])/Dh);for(let r=1;rt+1e-6)&&r!==null){let a=o?s:s-Dh;(!n||a-r>n[1]-n[0])&&(n=[r,a]),r=null}}return n}function TM(i,e=.32,t=.22,n=[]){let r=i.map(v=>v[0]),s=i.map(v=>v[1]),[o,a,l,c]=[Math.min(...r),Math.max(...r),Math.min(...s),Math.max(...s)],u=c-l>=a-o,h=v=>ZC(v,i,n,t),f=(v,y)=>u?[v,y]:[y,v],[d,p,x,g]=u?[o,a,l,c]:[l,c,o,a],m=[],b=!0;for(let v=d+t;v<=p-t+1e-6;v+=e){let y=JC(w=>h(f(v,w)),x,g);if(!y||y[1]-y[0]<.2)continue;let M=w=>w?[f(v,y[0]),f(v,y[1])]:[f(v,y[1]),f(v,y[0])],S=M(b),_=m[m.length-1];if(_&&n.length>0&&!wM(_,S[0],h)){let w=M(!b);if(!wM(_,w[0],h))continue;S=w,b=!b}m.push(...S),b=!b}return m}function Pm(i,e=.7,t=12){return Array.from({length:t},(n,r)=>[i[0]+Math.cos(r/t*Math.PI*2)*e,i[1]+Math.sin(r/t*Math.PI*2)*e])}var Cm=i=>Math.atan2(Math.sin(i),Math.cos(i));function AM(i,e,t){let n;if(e.mode==="cleaning"){if(i.path.length===0)return!1;n=i.path[i.next%i.path.length]}else if(e.mode==="returning"||e.mode==="docked")n=e.rest;else return!1;let[r,s]=[n[0]-i.pos[0],n[1]-i.pos[1]],o=Math.hypot(r,s);if(o<.02){if(e.mode==="cleaning")return i.next=(i.next+1)%i.path.length,!0;let l=Cm(e.restHeading-i.heading);return Math.abs(l)<.02?!1:(i.heading+=Math.sign(l)*Math.min(Math.abs(l),SM*t),!0)}let a=Cm(Math.atan2(r,s)-i.heading);if(i.heading=Cm(i.heading+Math.sign(a)*Math.min(Math.abs(a),SM*t)),Math.abs(a)<.35){let l=Math.min(o,KC*t);i.pos=[i.pos[0]+r/o*l,i.pos[1]+s/o*l]}return!0}var Uh=600*1e3,jC=3e3;function EM(i,e){if(i==null)return 1;let t=e-i;return t>Uh?Math.max(0,1-(t-Uh)/jC):1}function Im(i,e,t){let n=e/2,r=[],s=(a,l,c)=>r.push(a[0],t,a[1],l[0],t,l[1],c[0],t,c[1]);for(let a of i){for(let c=0;c+14?o=i.array[r*i.itemSize+s]:(s===0?o=i.getX(r):s===1?o=i.getY(r):s===2?o=i.getZ(r):s===3&&(o=i.getW(r)),i.normalized===!0&&(o=Br.normalize(o,i.array))),n.min[s]=Math.min(n.min[s],o),n.max[s]=Math.max(n.max[s],o)}return n}function FM(i){return Math.ceil(i/4)*4}function Fm(i,e=0){let t=FM(i.byteLength);if(t!==i.byteLength){let n=new Uint8Array(t);if(n.set(new Uint8Array(i)),e!==0)for(let r=i.byteLength;r"u"&&typeof OffscreenCanvas<"u"?new OffscreenCanvas(1,1):document.createElement("canvas")}function aP(i,e){if(typeof OffscreenCanvas<"u"&&i instanceof OffscreenCanvas){let t;return e==="image/jpeg"?t=.92:e==="image/webp"&&(t=.8),i.convertToBlob({type:e,quality:t})}else return new Promise(t=>i.toBlob(t,e))}var Nm=class{constructor(){this.plugins=[],this.options={},this.pending=[],this.buffers=[],this.byteOffset=0,this.buffers=[],this.nodeMap=new Map,this.skins=[],this.extensionsUsed={},this.extensionsRequired={},this.uids=new Map,this.uid=0,this.json={asset:{version:"2.0",generator:"THREE.GLTFExporter r187"}},this.cache={meshes:new Map,attributes:new Map,attributesNormalized:new Map,materials:new Map,textures:new Map,images:new Map,normalMaps:new Map},this.textureUtils=null}setPlugins(e){this.plugins=e}setTextureUtils(e){this.textureUtils=e}async writeAsync(e,t,n={}){this.options=Object.assign({binary:!1,trs:!1,onlyVisible:!0,maxTextureSize:1/0,animations:[],includeCustomExtensions:!1,copyright:null},n),this.options.animations.length>0&&(this.options.trs=!0),await this.processInputAsync(e),await Promise.all(this.pending);let r=this,s=r.buffers,o=r.json;n=r.options;let a=r.extensionsUsed,l=r.extensionsRequired,c=new Blob(s,{type:"application/octet-stream"}),u=Object.keys(a),h=Object.keys(l);if(u.length>0&&(o.extensionsUsed=u),h.length>0&&(o.extensionsRequired=h),o.buffers&&o.buffers.length>0&&(o.buffers[0].byteLength=c.size),n.copyright&&(o.asset.copyright=n.copyright),n.binary===!0){let f=new FileReader;f.readAsArrayBuffer(c),f.onloadend=function(){let d=Fm(f.result),p=new DataView(new ArrayBuffer(LM));p.setUint32(0,d.byteLength,!0),p.setUint32(4,iP,!0);let x=Fm(rP(JSON.stringify(o)),32),g=new DataView(new ArrayBuffer(LM));g.setUint32(0,x.byteLength,!0),g.setUint32(4,nP,!0);let m=new ArrayBuffer(IM),b=new DataView(m);b.setUint32(0,eP,!0),b.setUint32(4,tP,!0);let v=IM+g.byteLength+x.byteLength+p.byteLength+d.byteLength;b.setUint32(8,v,!0);let y=new Blob([m,g,x,p,d],{type:"application/octet-stream"}),M=new FileReader;M.readAsArrayBuffer(y),M.onloadend=function(){t(M.result)}}}else if(o.buffers&&o.buffers.length>0){let f=new FileReader;f.readAsDataURL(c),f.onloadend=function(){let d=f.result;o.buffers[0].uri=d,t(o)}}else t(o)}serializeUserData(e,t){if(Object.keys(e.userData).length===0)return;let n=this.options,r=this.extensionsUsed;try{let s=JSON.parse(JSON.stringify(e.userData));if(n.includeCustomExtensions&&s.gltfExtensions){t.extensions===void 0&&(t.extensions={});for(let o in s.gltfExtensions)t.extensions[o]=s.gltfExtensions[o],r[o]=!0;delete s.gltfExtensions}Object.keys(s).length>0&&(t.extras=s)}catch(s){console.warn("THREE.GLTFExporter: userData of '"+e.name+"' won't be serialized because of JSON.stringify error - "+s.message)}}getUID(e,t=!1){if(this.uids.has(e)===!1){let r=new Map;r.set(!0,this.uid++),r.set(!1,this.uid++),this.uids.set(e,r)}return this.uids.get(e).get(t)}isNormalizedNormalAttribute(e){if(this.cache.attributesNormalized.has(e))return!1;let n=new U;for(let r=0,s=e.count;r5e-4)return!1;return!0}createNormalizedNormalAttribute(e){let t=this.cache;if(t.attributesNormalized.has(e))return t.attributesNormalized.get(e);let n=e.clone(),r=new U;for(let s=0,o=n.count;s4?g=e.array[p*e.itemSize+x]:(x===0?g=e.getX(p):x===1?g=e.getY(p):x===2?g=e.getZ(p):x===3&&(g=e.getW(p)),e.normalized===!0&&(g=Br.normalize(g,e.array))),t===rt.FLOAT?u.setFloat32(h,g,!0):t===rt.INT?u.setInt32(h,g,!0):t===rt.UNSIGNED_INT?u.setUint32(h,g,!0):t===rt.SHORT?u.setInt16(h,g,!0):t===rt.UNSIGNED_SHORT?u.setUint16(h,g,!0):t===rt.BYTE?u.setInt8(h,g):t===rt.UNSIGNED_BYTE&&u.setUint8(h,g),h+=a}h%l!==0&&(h+=l-h%l)}let f={buffer:this.processBuffer(u.buffer),byteOffset:this.byteOffset,byteLength:c};return s!==void 0&&(f.target=s),s===rt.ARRAY_BUFFER&&(f.byteStride=l),this.byteOffset+=c,o.bufferViews.push(f),{id:o.bufferViews.length-1,byteLength:0}}processBufferViewImage(e){let t=this,n=t.json;return n.bufferViews||(n.bufferViews=[]),new Promise(function(r){let s=new FileReader;s.readAsArrayBuffer(e),s.onloadend=function(){let o=Fm(s.result),a={buffer:t.processBuffer(o),byteOffset:t.byteOffset,byteLength:o.byteLength};t.byteOffset+=o.byteLength,r(n.bufferViews.push(a)-1)}})}processAccessor(e,t,n,r){let s=this.json,o={1:"SCALAR",2:"VEC2",3:"VEC3",4:"VEC4",9:"MAT3",16:"MAT4"},a;if(e.array.constructor===Float32Array)a=rt.FLOAT;else if(e.array.constructor===Int32Array)a=rt.INT;else if(e.array.constructor===Uint32Array)a=rt.UNSIGNED_INT;else if(e.array.constructor===Int16Array)a=rt.SHORT;else if(e.array.constructor===Uint16Array)a=rt.UNSIGNED_SHORT;else if(e.array.constructor===Int8Array)a=rt.BYTE;else if(e.array.constructor===Uint8Array)a=rt.UNSIGNED_BYTE;else throw new Error("THREE.GLTFExporter: Unsupported bufferAttribute component type: "+e.array.constructor.name);if(n===void 0&&(n=0),(r===void 0||r===1/0)&&(r=e.count),r===0)return null;let l=oP(e,n,r),c;t!==void 0&&(c=e===t.index?rt.ELEMENT_ARRAY_BUFFER:rt.ARRAY_BUFFER);let u=this.processBufferView(e,a,n,r,c),h={bufferView:u.id,byteOffset:u.byteOffset,componentType:a,count:r,max:l.max,min:l.min,type:o[e.itemSize]};return e.normalized===!0&&(h.normalized=!0),s.accessors||(s.accessors=[]),s.accessors.push(h)-1}processImage(e,t,n,r="image/png"){if(e!==null){let s=this,o=s.cache,a=s.json,l=s.options,c=s.pending;o.images.has(e)||o.images.set(e,{});let u=o.images.get(e),h=r+":flipY/"+n.toString();if(u[h]!==void 0)return u[h];a.images||(a.images=[]);let f={mimeType:r},d=Om();d.width=Math.min(e.width,l.maxTextureSize),d.height=Math.min(e.height,l.maxTextureSize);let p=d.getContext("2d",{willReadFrequently:!0});if(n===!0&&(p.translate(0,d.height),p.scale(1,-1)),e.data!==void 0){t!==Nn&&console.error("GLTFExporter: Only RGBAFormat is supported.",t),(e.width>l.maxTextureSize||e.height>l.maxTextureSize)&&console.warn("GLTFExporter: Image size is bigger than maxTextureSize",e);let g=new Uint8ClampedArray(e.height*e.width*4);for(let m=0;ms.processBufferViewImage(g)).then(g=>{f.bufferView=g})):f.uri=lo.getDataURL(d,r);let x=a.images.push(f)-1;return u[h]=x,x}else throw new Error("THREE.GLTFExporter: No valid image data found. Unable to process texture.")}processSampler(e){let t=this.json;t.samplers||(t.samplers=[]);let n={magFilter:Gn[e.magFilter],minFilter:Gn[e.minFilter],wrapS:Gn[e.wrapS],wrapT:Gn[e.wrapT]};return t.samplers.push(n)-1}async processTextureAsync(e){let n=this.options,r=this.cache,s=this.json;if(r.textures.has(e))return r.textures.get(e);s.textures||(s.textures=[]),e instanceof Lr&&(e=await this.decompressTextureAsync(e,n.maxTextureSize));let o=e.userData.mimeType,a=this.processImage(e.image,e.format,e.flipY,o),l={sampler:this.processSampler(e)};o==="image/webp"?(l.extensions=l.extensions||{},l.extensions.EXT_texture_webp={source:a},this.extensionsUsed.EXT_texture_webp=!0,this.extensionsRequired.EXT_texture_webp=!0):l.source=a,e.name&&(l.name=e.name),await this._invokeAllAsync(async function(u){u.writeTexture&&await u.writeTexture(e,l)});let c=s.textures.push(l)-1;return r.textures.set(e,c),c}async processMaterialAsync(e,t){let n=this.cache,r=this.json,s=t!==void 0&&t.hasAttribute("tangent"),o=e.normalMap?e.uuid+":"+s:e.uuid;if(n.materials.has(o))return n.materials.get(o);if(e.isShaderMaterial)return console.warn("GLTFExporter: THREE.ShaderMaterial not supported."),null;r.materials||(r.materials=[]);let a={pbrMetallicRoughness:{}};e.isMeshStandardMaterial!==!0&&e.isMeshBasicMaterial!==!0&&console.warn("GLTFExporter: Use MeshStandardMaterial or MeshBasicMaterial for best results.");let l=e.color.toArray().concat([e.opacity]);if(xr(l,[1,1,1,1])||(a.pbrMetallicRoughness.baseColorFactor=l),e.isMeshStandardMaterial?(a.pbrMetallicRoughness.metallicFactor=e.metalness,a.pbrMetallicRoughness.roughnessFactor=e.roughness):(a.pbrMetallicRoughness.metallicFactor=0,a.pbrMetallicRoughness.roughnessFactor=1),e.metalnessMap||e.roughnessMap){let u=await this.buildMetalRoughTextureAsync(e.metalnessMap,e.roughnessMap),h={index:await this.processTextureAsync(u),texCoord:u.channel};this.applyTextureTransform(h,u),a.pbrMetallicRoughness.metallicRoughnessTexture=h}if(e.map){let u={index:await this.processTextureAsync(e.map),texCoord:e.map.channel};this.applyTextureTransform(u,e.map),a.pbrMetallicRoughness.baseColorTexture=u}if(e.emissive){let u=e.emissive;if(Math.max(u.r,u.g,u.b)>0&&(a.emissiveFactor=e.emissive.toArray()),e.emissiveMap){let f={index:await this.processTextureAsync(e.emissiveMap),texCoord:e.emissiveMap.channel};this.applyTextureTransform(f,e.emissiveMap),a.emissiveTexture=f}}if(e.normalMap){let u=e.normalScale,h=u.x<0,f=s?u.y<0:u.y>0,d=e.normalMap;if(h||f){n.normalMaps.has(e.normalMap)===!1&&n.normalMaps.set(e.normalMap,{});let x=n.normalMaps.get(e.normalMap),g=`${h}:${f}`;x[g]===void 0&&(x[g]=await this.buildNormalMapTextureAsync(e.normalMap,h,f)),d=x[g]}let p={index:await this.processTextureAsync(d),texCoord:e.normalMap.channel};Math.abs(u.x)!==1&&(p.scale=Math.abs(u.x)),this.applyTextureTransform(p,e.normalMap),a.normalTexture=p}if(e.aoMap){let u={index:await this.processTextureAsync(e.aoMap),texCoord:e.aoMap.channel};e.aoMapIntensity!==1&&(u.strength=e.aoMapIntensity),this.applyTextureTransform(u,e.aoMap),a.occlusionTexture=u}e.transparent?a.alphaMode="BLEND":e.alphaTest>0&&(a.alphaMode="MASK",a.alphaCutoff=e.alphaTest),e.side===ut&&(a.doubleSided=!0),e.name!==""&&(a.name=e.name),this.serializeUserData(e,a),await this._invokeAllAsync(async function(u){u.writeMaterialAsync&&await u.writeMaterialAsync(e,a)});let c=r.materials.push(a)-1;return n.materials.set(o,c),c}async processMeshAsync(e){let t=this.cache,n=this.json,r=[e.geometry.uuid];if(Array.isArray(e.material))for(let y=0,M=e.material.length;y0){let y=[],M=[],S={};if(e.morphTargetDictionary!==void 0)for(let _ in e.morphTargetDictionary)S[e.morphTargetDictionary[_]]=_;for(let _=0;_0&&(l.extras={},l.extras.targetNames=M)}let x=Array.isArray(e.material);if(x&&o.groups.length===0)return null;let g=!1;if(x&&o.index===null){let y=[];for(let M=0,S=o.attributes.position.count;M0&&(S.targets=h),o.index!==null){let w=this.getUID(o.index);(b[y].start!==void 0||b[y].count!==void 0)&&(w+=":"+b[y].start+":"+b[y].count),t.attributes.has(w)?S.indices=t.attributes.get(w):(S.indices=this.processAccessor(o.index,o,b[y].start,b[y].count),t.attributes.set(w,S.indices)),S.indices===null&&delete S.indices}let _=await this.processMaterialAsync(m[b[y].materialIndex],o);_!==null&&(S.material=_),u.push(S)}g===!0&&o.setIndex(null),l.primitives=u,n.meshes||(n.meshes=[]),await this._invokeAllAsync(function(y){y.writeMesh&&y.writeMesh(e,l)});let v=n.meshes.push(l)-1;return t.meshes.set(s,v),v}detectMeshQuantization(e,t){if(this.extensionsUsed[Lm])return;let n;switch(t.array.constructor){case Int8Array:n="byte";break;case Uint8Array:n="unsigned byte";break;case Int16Array:n="short";break;case Uint16Array:n="unsigned short";break;default:return}t.normalized&&(n+=" normalized");let r=e.split("_",1)[0];CM[r]&&CM[r].includes(n)&&(this.extensionsUsed[Lm]=!0,this.extensionsRequired[Lm]=!0)}processCamera(e){let t=this.json;t.cameras||(t.cameras=[]);let n=e.isOrthographicCamera,r={type:n?"orthographic":"perspective"};return n?r.orthographic={xmag:e.right,ymag:e.top,zfar:e.far<=0?.001:e.far,znear:e.near<0?0:e.near}:r.perspective={aspectRatio:e.aspect,yfov:Br.degToRad(e.fov),zfar:e.far<=0?.001:e.far,znear:e.near<0?0:e.near},e.name!==""&&(r.name=e.type),t.cameras.push(r)-1}processAnimation(e,t){let n=this.json,r=this.nodeMap;n.animations||(n.animations=[]),e=qr.Utils.mergeMorphTargetTracks(e.clone(),t);let s=e.tracks,o=[],a=[];for(let c=0;c0){let a=[];for(let l=0,c=e.children.length;l0&&(s.children=a)}return await this._invokeAllAsync(function(a){a.writeNode&&a.writeNode(e,s)}),o}async _processNodeWithPivotAsync(e){let t=this.json,n=this.options,r=this.nodeMap,s=e.pivot,o={},a=e.quaternion.toArray(),l=[e.position.x+s.x,e.position.y+s.y,e.position.z+s.z],c=e.scale.toArray();xr(a,[0,0,0,1])||(o.rotation=a),xr(l,[0,0,0])||(o.translation=l),xr(c,[1,1,1])||(o.scale=c),o.extras={pivot:s.toArray()},e.name!==""&&(o.name=String(e.name)),this.serializeUserData(e,o);let u=t.nodes.push(o)-1;r.set(e,u);let h={},f=[-s.x,-s.y,-s.z];if(xr(f,[0,0,0])||(h.translation=f),e.isMesh||e.isLine||e.isPoints){let x=await this.processMeshAsync(e);x!==null&&(h.mesh=x)}else e.isCamera&&(h.camera=this.processCamera(e));e.isSkinnedMesh&&this.skins.push(e);let p=[t.nodes.push(h)-1];if(e.children.length>0){let x=[];for(let g=0,m=e.children.length;g0&&(h.children=x)}return o.children=p,await this._invokeAllAsync(function(x){x.writeNode&&x.writeNode(e,o)}),u}async processSceneAsync(e){let t=this.json,n=this.options;t.scenes||(t.scenes=[],t.scene=0);let r={};e.name!==""&&(r.name=e.name),t.scenes.push(r);let s=[];for(let o=0,a=e.children.length;o0&&(r.nodes=s),this.serializeUserData(e,r)}async processObjectsAsync(e){let t=new Tn;t.name="AuxScene";for(let n=0;n0&&await this.processObjectsAsync(n);for(let r=0;r0&&(o.range=e.distance)):e.isSpotLight&&(o.type="spot",e.distance>0&&(o.range=e.distance),o.spot={},o.spot.innerConeAngle=(1-e.penumbra)*e.angle,o.spot.outerConeAngle=e.angle),e.decay!==void 0&&e.decay!==2&&console.warn("THREE.GLTFExporter: Light decay may be lost. glTF is physically-based, and expects light.decay=2."),e.target&&(e.target.parent!==e||e.target.position.x!==0||e.target.position.y!==0||e.target.position.z!==-1)&&console.warn("THREE.GLTFExporter: Light direction may be lost. For best results, make light.target a child of the light with position 0,0,-1."),s[this.name]||(r.extensions=r.extensions||{},r.extensions[this.name]={lights:[]},s[this.name]=!0);let a=r.extensions[this.name].lights;a.push(o),t.extensions=t.extensions||{},t.extensions[this.name]={light:a.length-1}}},Um=class{constructor(e){this.writer=e,this.name="KHR_materials_unlit"}async writeMaterialAsync(e,t){if(!e.isMeshBasicMaterial)return;let r=this.writer.extensionsUsed;t.extensions=t.extensions||{},t.extensions[this.name]={},r[this.name]=!0,t.pbrMetallicRoughness.metallicFactor=0,t.pbrMetallicRoughness.roughnessFactor=.9}},Bm=class{constructor(e){this.writer=e,this.name="KHR_materials_clearcoat"}async writeMaterialAsync(e,t){if(!e.isMeshPhysicalMaterial||e.clearcoat===0)return;let n=this.writer,r=n.extensionsUsed,s={};if(s.clearcoatFactor=e.clearcoat,e.clearcoatMap){let o={index:await n.processTextureAsync(e.clearcoatMap),texCoord:e.clearcoatMap.channel};n.applyTextureTransform(o,e.clearcoatMap),s.clearcoatTexture=o}if(s.clearcoatRoughnessFactor=e.clearcoatRoughness,e.clearcoatRoughnessMap){let o={index:await n.processTextureAsync(e.clearcoatRoughnessMap),texCoord:e.clearcoatRoughnessMap.channel};n.applyTextureTransform(o,e.clearcoatRoughnessMap),s.clearcoatRoughnessTexture=o}if(e.clearcoatNormalMap){let o={index:await n.processTextureAsync(e.clearcoatNormalMap),texCoord:e.clearcoatNormalMap.channel};e.clearcoatNormalScale.x!==1&&(o.scale=e.clearcoatNormalScale.x),n.applyTextureTransform(o,e.clearcoatNormalMap),s.clearcoatNormalTexture=o}t.extensions=t.extensions||{},t.extensions[this.name]=s,r[this.name]=!0}},km=class{constructor(e){this.writer=e,this.name="KHR_materials_dispersion"}async writeMaterialAsync(e,t){if(!e.isMeshPhysicalMaterial||e.dispersion===0)return;let r=this.writer.extensionsUsed,s={};s.dispersion=e.dispersion,t.extensions=t.extensions||{},t.extensions[this.name]=s,r[this.name]=!0}},zm=class{constructor(e){this.writer=e,this.name="KHR_materials_iridescence"}async writeMaterialAsync(e,t){if(!e.isMeshPhysicalMaterial||e.iridescence===0)return;let n=this.writer,r=n.extensionsUsed,s={};if(s.iridescenceFactor=e.iridescence,e.iridescenceMap){let o={index:await n.processTextureAsync(e.iridescenceMap),texCoord:e.iridescenceMap.channel};n.applyTextureTransform(o,e.iridescenceMap),s.iridescenceTexture=o}if(s.iridescenceIor=e.iridescenceIOR,s.iridescenceThicknessMinimum=e.iridescenceThicknessMinimum,s.iridescenceThicknessMaximum=e.iridescenceThicknessMaximum,e.iridescenceThicknessMap){let o={index:await n.processTextureAsync(e.iridescenceThicknessMap),texCoord:e.iridescenceThicknessMap.channel};n.applyTextureTransform(o,e.iridescenceThicknessMap),s.iridescenceThicknessTexture=o}t.extensions=t.extensions||{},t.extensions[this.name]=s,r[this.name]=!0}},Vm=class{constructor(e){this.writer=e,this.name="KHR_materials_transmission"}async writeMaterialAsync(e,t){if(!e.isMeshPhysicalMaterial||e.transmission===0)return;let n=this.writer,r=n.extensionsUsed,s={};if(s.transmissionFactor=e.transmission,e.transmissionMap){let o={index:await n.processTextureAsync(e.transmissionMap),texCoord:e.transmissionMap.channel};n.applyTextureTransform(o,e.transmissionMap),s.transmissionTexture=o}t.extensions=t.extensions||{},t.extensions[this.name]=s,r[this.name]=!0}},Gm=class{constructor(e){this.writer=e,this.name="KHR_materials_volume"}async writeMaterialAsync(e,t){if(!e.isMeshPhysicalMaterial||e.transmission===0)return;let n=this.writer,r=n.extensionsUsed,s={};if(s.thicknessFactor=e.thickness,e.thicknessMap){let o={index:await n.processTextureAsync(e.thicknessMap),texCoord:e.thicknessMap.channel};n.applyTextureTransform(o,e.thicknessMap),s.thicknessTexture=o}e.attenuationDistance!==1/0&&(s.attenuationDistance=e.attenuationDistance),s.attenuationColor=e.attenuationColor.toArray(),t.extensions=t.extensions||{},t.extensions[this.name]=s,r[this.name]=!0}},Hm=class{constructor(e){this.writer=e,this.name="KHR_materials_ior"}async writeMaterialAsync(e,t){if(!e.isMeshPhysicalMaterial||e.ior===1.5)return;let r=this.writer.extensionsUsed,s={};s.ior=e.ior,t.extensions=t.extensions||{},t.extensions[this.name]=s,r[this.name]=!0}},Wm=class{constructor(e){this.writer=e,this.name="KHR_materials_specular"}async writeMaterialAsync(e,t){if(!e.isMeshPhysicalMaterial||e.specularIntensity===1&&e.specularColor.equals(QC)&&!e.specularIntensityMap&&!e.specularColorMap)return;let n=this.writer,r=n.extensionsUsed,s={};if(e.specularIntensityMap){let o={index:await n.processTextureAsync(e.specularIntensityMap),texCoord:e.specularIntensityMap.channel};n.applyTextureTransform(o,e.specularIntensityMap),s.specularTexture=o}if(e.specularColorMap){let o={index:await n.processTextureAsync(e.specularColorMap),texCoord:e.specularColorMap.channel};n.applyTextureTransform(o,e.specularColorMap),s.specularColorTexture=o}s.specularFactor=e.specularIntensity,s.specularColorFactor=e.specularColor.toArray(),t.extensions=t.extensions||{},t.extensions[this.name]=s,r[this.name]=!0}},Xm=class{constructor(e){this.writer=e,this.name="KHR_materials_sheen"}async writeMaterialAsync(e,t){if(!e.isMeshPhysicalMaterial||e.sheen==0)return;let n=this.writer,r=n.extensionsUsed,s={};if(e.sheenRoughnessMap){let o={index:await n.processTextureAsync(e.sheenRoughnessMap),texCoord:e.sheenRoughnessMap.channel};n.applyTextureTransform(o,e.sheenRoughnessMap),s.sheenRoughnessTexture=o}if(e.sheenColorMap){let o={index:await n.processTextureAsync(e.sheenColorMap),texCoord:e.sheenColorMap.channel};n.applyTextureTransform(o,e.sheenColorMap),s.sheenColorTexture=o}s.sheenRoughnessFactor=e.sheenRoughness,s.sheenColorFactor=e.sheenColor.toArray(),t.extensions=t.extensions||{},t.extensions[this.name]=s,r[this.name]=!0}},Ym=class{constructor(e){this.writer=e,this.name="KHR_materials_anisotropy"}async writeMaterialAsync(e,t){if(!e.isMeshPhysicalMaterial||e.anisotropy==0)return;let n=this.writer,r=n.extensionsUsed,s={};if(e.anisotropyMap){let o={index:await n.processTextureAsync(e.anisotropyMap)};n.applyTextureTransform(o,e.anisotropyMap),s.anisotropyTexture=o}s.anisotropyStrength=e.anisotropy,s.anisotropyRotation=e.anisotropyRotation,t.extensions=t.extensions||{},t.extensions[this.name]=s,r[this.name]=!0}},qm=class{constructor(e){this.writer=e,this.name="KHR_materials_emissive_strength"}async writeMaterialAsync(e,t){if(!e.isMeshStandardMaterial||e.emissiveIntensity===1)return;let r=this.writer.extensionsUsed,s={};s.emissiveStrength=e.emissiveIntensity,t.extensions=t.extensions||{},t.extensions[this.name]=s,r[this.name]=!0}},$m=class{constructor(e){this.writer=e,this.name="EXT_materials_bump"}async writeMaterialAsync(e,t){if(!e.isMeshStandardMaterial||e.bumpScale===1&&!e.bumpMap)return;let n=this.writer,r=n.extensionsUsed,s={};if(e.bumpMap){let o={index:await n.processTextureAsync(e.bumpMap),texCoord:e.bumpMap.channel};n.applyTextureTransform(o,e.bumpMap),s.bumpTexture=o}s.bumpFactor=e.bumpScale,t.extensions=t.extensions||{},t.extensions[this.name]=s,r[this.name]=!0}},Km=class{constructor(e){this.writer=e,this.name="EXT_mesh_gpu_instancing"}writeNode(e,t){if(!e.isInstancedMesh)return;let n=this.writer,r=e,s=new Float32Array(r.count*3),o=new Float32Array(r.count*4),a=new Float32Array(r.count*3),l=new Be,c=new U,u=new Sn,h=new U;for(let d=0;di.times[i.times.length-1]){if(Math.abs(i.times[i.times.length-1]-e)<.001)return i.times.length-1;r[r.length-1]=e,r.set(i.times,0),s.set(i.values,0),s.set(o.evaluate(e),i.values.length),a=r.length-1}else for(let l=0;le){r.set(i.times.slice(0,l+1),0),r[l+1]=e,r.set(i.times.slice(l+1),l+2),s.set(i.values.slice(0,(l+1)*n),0),s.set(o.evaluate(e),(l+1)*n),s.set(i.values.slice((l+1)*n),(l+2)*n),a=l+1;break}}return i.times=r,i.values=s,a},mergeMorphTargetTracks:function(i,e){let t=[],n={},r=i.tracks;for(let s=0;slP.test(r.name)).map(r=>r.name);if(e.length>0)return e;let n=[...i.filter(r=>r.opacity>=.9&&r.lightness>.12&&!/glass|window|light|lamp/i.test(r.name))].sort((r,s)=>s.area-r.area)[0];return n?[n.name]:[]}function NM(i,e){let t=i.reduce((r,s)=>r+s,0);if(t<=e)return[...i];let n=e/t;return i.map(r=>Math.max(1,Math.floor(r*n)))}var DM=i=>/^Paint/.test(i)?i:`Paint_${i||"body"}`;var Yo=i=>i.indices.length/3;function cP(i){let e=[1/0,1/0,1/0],t=[-1/0,-1/0,-1/0];for(let n=0;nMath.floor(o/t)+1),s=new Float64Array(n);for(let o=0;oe?r=l:(s=l,o=c)}return hP(i,o)}var Bi=class extends Error{reason;constructor(e,t){super(t),this.reason=e}},fP=1179937895;function dP(i){if(i.byteLength<20||new DataView(i).getUint32(0,!0)!==fP)throw new Bi("not_glb","not a binary glTF (.glb) file")}async function Zm(i){return dP(i),new Promise((e,t)=>{new Xo().parse(i,"",n=>e(n.scene),n=>{let r=String(n?.message??n);t(/draco|meshopt|ktx/i.test(r)?new Bi("compressed",r):new Bi("unreadable",r))})})}var pP=i=>i instanceof In?i:Object.assign(new In,{color:i.color?.clone()??new W(8947848),name:i.name,opacity:i.opacity,transparent:i.transparent});function kM(i,e){i.updateMatrixWorld(!0);let t=new Map;return i.traverse(n=>{let r=n;if(!r.isMesh)return;let s=r.geometry,o=s.getAttribute("position");if(!o)return;let a=pP(Array.isArray(r.material)?r.material[0]:r.material),l=t.get(a)??{positions:[],indices:[]};t.set(a,l);let c=new Be().multiplyMatrices(e,r.matrixWorld),u=l.positions.length/3,h=new U;for(let p=0;p({material:n,mesh:{positions:Float32Array.from(r.positions),indices:Uint32Array.from(r.indices)}}))}var mP=i=>{let e=0,[t,n,r]=[new U,new U,new U];for(let s=0;s.299*i.r+.587*i.g+.114*i.b;async function xP(i){let e=kM(await Zm(i),new Be);if(e.length===0)throw new Bi("empty","the file has no 3D parts");let t=new Ct;for(let s of e)t.union(new Ct().setFromArray(s.mesh.positions));let n=t.getSize(new U),r=e.map(s=>({name:s.material.name||"material",area:mP(s.mesh),opacity:s.material.opacity,lightness:gP(s.material.color)}));return{triangles:e.reduce((s,o)=>s+Yo(o.mesh),0),size:[n.x,n.y,n.z],materials:r,paint:OM(r)}}async function bP(i,e){let t=new Be().makeRotationY(e.turns*Math.PI/2),n=kM(await Zm(i),t);if(n.length===0)throw new Bi("empty","the file has no 3D parts");let r=NM(n.map(l=>Yo(l.mesh)),e.maxTriangles),s=new Tn,o=0;return n.forEach((l,c)=>{let u=BM(l.mesh,r[c]);if(Yo(u)===0)return;o+=Yo(u);let h=new Fe;h.setAttribute("position",new wt(u.positions,3)),h.setIndex(new wt(u.indices,1));let f=l.material.name||"material",d=e.paint.includes(f),p=new In({color:l.material.color.clone(),name:d?DM(f):f,metalness:l.material.metalness,roughness:l.material.roughness,opacity:l.material.opacity,transparent:l.material.opacity<1});d&&(p.userData.paint=!0),s.add(new we(h,p))}),{glb:await new Promise((l,c)=>{new qr().parse(s,u=>u instanceof ArrayBuffer?l(u):c(new Bi("unreadable","export gave no binary")),u=>c(new Bi("unreadable",String(u))),{binary:!0})}),triangles:o}}async function yP(i,e,t=220){let n=await Zm(i),r=new Ct().setFromObject(n),s=r.getCenter(new U),o=r.getSize(new U);n.traverse(d=>{let p=d;if(!p.isMesh)return;let x=p.material;(x.userData?.paint||/^Paint/.test(x.name))&&x.color.set(e),x.metalness=Math.min(x.metalness??0,.5)});let a=new Tn,l=new sr(16777215,1.6);l.position.set(-4,9,6),a.add(n,new Da(16777215,.5),new ds(16777215,6713480,1.1),l);let c=Math.max(o.x,o.y,o.z)*.75,u=new zn(-c,c,c,-c,.01,100);u.position.copy(s).add(new U(.9,.7,1.2).normalize().multiplyScalar(20)),u.lookAt(s);let h=new kr({alpha:!0,antialias:!0,preserveDrawingBuffer:!0});h.setSize(t,t,!1),h.render(a,u);let f=h.domElement.toDataURL("image/png");return h.dispose(),a.traverse(d=>{let p=d;p.isMesh&&p.geometry.dispose()}),f}var qo=null,zM=new Map,VM=16758087;function _P(i,e,t){let n=vt(i.type);if(n?.light)rl(e,n,{x:0,z:0,rotation:0,w:i.w,d:i.d,h:i.h},0,VM);else if(i.lamp)Jm(e,{x:0,z:0,size:[i.w,i.d,i.h],base:0,rotation:0,variant:i.variant??null,lamp:i.lamp},Math.max(i.h+.15,.6),VM);else{let r={id:"preview",type:i.type,x:0,z:0,rotation:0,w:i.w,d:i.d,h:i.h,variant:i.variant??null,entity:null,power:null};Ml(e,t,new lt,r)}}function vP(i){let e=i.getCenter(new U),t=new zn(-1,1,1,-1,.01,100);t.position.copy(e).add(new U(.9,.75,1.3).normalize().multiplyScalar(20)),t.lookAt(e),t.updateMatrixWorld();let n=.05;for(let s of[i.min.x,i.max.x])for(let o of[i.min.y,i.max.y])for(let a of[i.min.z,i.max.z]){let l=new U(s,o,a).applyMatrix4(t.matrixWorldInverse);n=Math.max(n,Math.abs(l.x),Math.abs(l.y))}let r=n*1.12;return Object.assign(t,{left:-r,right:r,top:r,bottom:-r}),t.updateProjectionMatrix(),t}function MP(i,e=180,t,n=1.3){let r=[i.type,i.w,i.d,i.h,i.variant??"",e,n].join("|"),s=zM.get(r);if(s)return s;t&&Nl(t),qo??=new kr({alpha:!0,antialias:!0,preserveDrawingBuffer:!0}),qo.setPixelRatio(Math.min(2,window.devicePixelRatio||1)),qo.setSize(e,e,!1),qo.setClearColor(0,0);let[o,a]=[new lt,new Wt];_P(i,o,a);let l=new we(o.geometry(),new Ke({vertexColors:!0,color:new W(n,n,n)})),c=new gn(a.geometry(),new Lt({vertexColors:!0,color:new W(n*1.8,n*1.8,n*1.8)})),u=new Tn;u.add(l,c),qo.render(u,vP(new Ct().setFromObject(l)));let h=qo.domElement.toDataURL("image/png");for(let f of[l,c])f.geometry.dispose(),f.material.dispose();return zM.set(r,h),h}var HM={cleaning:3662079,returning:16758087,docked:4310123,idle:5995775,error:16726863},SP=1.4,Qm=32,$e=2767456,WM=4873352,wP=1911110,jm=450,XM=125,TP=1.6,YM=3e4,$M=5,KM=360/$M,AP=new W(1714765),qM=.94;var e0=class{host;options;renderer;scene=new Tn;camera=new Jt(38,1,.1,400);controls;labels;root=new ct;patternTexture;blindTexture;openingTargets=new Map;fridges=new Map;covers=new Map;screens=new Map;pickFurniture=new Map;pickOpenings=new Map;pickOpenings2=new Map;flashes=new Map;surfaceGrab=null;surfaceDragging=!1;furnishTypes=null;roofWindows=new Map;roofWindowsKey="";persons=[];personPins=new Map;floorInfo=new Map;roomInfo=new Map;groundTexture=null;devices=[];devicePins=new Map;ground;floors=[];building=null;furnitureColors=null;notePhoto=null;floorId=null;roomId=null;wallMode="auto";painted=!1;explode;frame=0;lastFrame=0;qualityMode="auto";governor=null;disposed=!1;resizeObserver;fpsFrames=0;worstFrame=0;lastStatsFrame=0;lowQuality=!1;highQuality=!1;effectTime=0;effectTick=!1;tintTick=!1;effectTimer;awakeUntil=0;deviceLook="";haloTexture;roof=null;roofO=0;keepRoof=!1;robots=new Map;pets=new Map;petMat=null;petTimer;robotGeo=null;robotTrails=new Map;trailTimers=new Map;robotMat=null;mowerMat=null;robotLedGeo=null;robotLast=0;petLast=0;meshes=[];meshLight=null;meshAsked=new Set;robotTimer;floorStack="dim";floorMap=new Map;labelsDirty=!0;viewKey=new Float64Array(6);pinMode=new WeakMap;size={w:1,h:1};labelInset=0;effectFloors=new Set;deviceFloor=new Map;statsOn=!1;parked=new Map;parkedSig="";plain=!1;rightBack=!1;rightDown=null;gateOpen=new Map;gateSig="";orbitSpeed=0;orbitLast=0;orbitTimer;onScreen=!0;intersection=null;swipe=null;furnish=!1;selectedFurniture=null;selectedDevice=null;pendingDevice=null;labelPlacer=new Bu;pinHooks={furnishing:()=>this.furnish,pressedWhileFurnishing:e=>this.pendingDevice=e,selectWhileFurnishing:e=>{this.selectDevice(e),this.options.onDeviceSelect?.(e)},centre:e=>{let[t,n]=[e.getBoundingClientRect(),this.host.getBoundingClientRect()];return{x:t.left+t.width/2-n.left,y:t.top+t.height/2-n.top}},tap:(e,t,n)=>{let r=this.tapInRoom?this.devices.find(s=>s.id===e):void 0;if(r&&!this.deviceInReach(r.floorId,r.roomId))return this.options.onRoomTap?.(r.floorId,r.roomId);this.options.onDeviceTap?.(e,t,n)},hold:(e,t,n)=>this.options.onDeviceHold?.(e,t,n)};tapInRoom=!1;deviceGrab=null;grab=null;ghost=null;theme="neon";themeUniform={value:0};sun=null;weatherLayer;houseShadow=new Vu;sunArc=new Ku;sunArcLocation=null;shadowKey="";footprint={key:"",rings:[]};mapLayer;mapSettings=null;mapNorth=0;groundY=0;skyView=null;weatherTimer;energyLayer;soundLayer;waterLayer;glassAlpha={value:.2};screenLayer;pictureLayer;liveAnchors=[];liveAnchorCb=null;roomTint=null;houseRadius=20;startView=null;fpsStart=0;constructor(e,t={}){this.host=e,this.options=t,this.explode=t.explode??!0,this.qualityMode=t.quality??"auto",this.renderer=this.makeRenderer(this.qualityMode),this.labels=document.createElement("div"),this.labels.className="nf-labels",e.append(this.labels),this.patternTexture=EP(),this.blindTexture=RP(),this.haloTexture=PP(),this.ground=new we(new sn(1,1),new Ke({transparent:!0,blending:Ft,depthWrite:!1})),this.ground.rotation.x=-Math.PI/2,this.ground.renderOrder=-1,this.scene.add(this.ground,this.root),this.weatherLayer=new wh(this.scene),this.scene.add(this.houseShadow.mesh),this.scene.add(this.sunArc.group),this.mapLayer=new _h(this.scene),this.mapLayer.onChange=()=>this.invalidate(),this.energyLayer=new Eh(this.scene,this.liftOf),this.soundLayer=new Rh(this.scene,this.liftOf),this.waterLayer=new Ph(this.scene,this.liftOf),this.screenLayer=new Ih(this.scene,this.liftOf),this.screenLayer.onChange=()=>this.invalidate(),this.pictureLayer=new Lh(this.scene,this.liftOf),this.pictureLayer.onChange=()=>this.invalidate(),this.weatherLayer.onFlash=n=>this.host.classList.toggle("live-flash",n),this.controls=this.makeControls(),this.resizeObserver=new ResizeObserver(()=>this.resize()),this.resizeObserver.observe(e),document.addEventListener("visibilitychange",this.onVisibility),this.host.addEventListener("pointerdown",this.onTouch,{passive:!0}),this.renderer.domElement.addEventListener("pointerdown",this.onRightDown),this.renderer.domElement.addEventListener("pointerup",this.onRightUp),this.renderer.domElement.addEventListener("contextmenu",this.onContext),this.awakeUntil=performance.now()+YM,typeof IntersectionObserver=="function"&&(this.intersection=new IntersectionObserver(n=>{let r=n.some(s=>s.isIntersecting);r!==this.onScreen&&(this.onScreen=r,r||(clearTimeout(this.effectTimer),this.effectTimer=void 0),r&&this.invalidate())}),this.intersection.observe(e)),this.resize()}get low(){return this.lowQuality}setRightBack(e){this.rightBack=e}onRightDown=e=>{this.rightDown=this.rightBack&&e.button===2?{x:e.clientX,y:e.clientY,at:performance.now()}:null};onRightUp=e=>{let t=this.rightDown;this.rightDown=null,!(!this.rightBack||!t||e.button!==2)&&Math.hypot(e.clientX-t.x,e.clientY-t.y)<6&&performance.now()-t.at<400&&this.options.onBack?.()};onContext=e=>{this.rightBack&&e.preventDefault()};setPlain(e){e!==this.plain&&(this.plain=e,this.building&&(this.rebuild(),this.invalidate()))}exportStl(e=10){let t=[];for(let n of this.floors)for(let r of[n.wallMesh,n.floorMesh]){let s=r.geometry.getAttribute("position");s&&t.push({positions:s.array,lift:n.floor.elevation})}return Ey(t,e)}setGateStates(e){let t=[...e].map(([n,r])=>`${n}=${r?1:0}`).sort().join("|");t!==this.gateSig&&(this.gateSig=t,this.gateOpen=e,this.building&&(this.rebuild(),this.invalidate()))}setParked(e){let t=[...e].map(([n,r])=>`${n}=${r}`).sort().join("|");t!==this.parkedSig&&(this.parkedSig=t,this.parked=e,this.building&&(this.rebuild(),this.invalidate()))}setStats(e){this.statsOn=e}setLabelInset(e){this.labelInset!==e&&(this.labelInset=e,this.labelsDirty=!0,this.invalidate())}setAutoOrbit(e){this.orbitSpeed=e,this.orbitLast=0,this.invalidate()}setQuality(e){this.qualityMode=e,this.swapRenderer(e)}dropToLow(){this.disposed||this.lowQuality||this.swapRenderer("low")}swapRenderer(e){let t=this.renderer.domElement,n=this.makeRenderer(e);this.rebuildTier(),this.applyTierFlags(),t.replaceWith(n.domElement),this.renderer.dispose(),this.renderer.forceContextLoss(),this.renderer=n;let{view:r,locked:s}=this.controls;this.controls.dispose(),this.controls=this.makeControls(),this.controls.view=r,this.controls.locked=s,this.resize()}setMeshSource(e){N0(e)}setPacks(e){Nl(e),this.building&&(this.rebuild(),this.invalidate())}setBuilding(e){let t=this.building===null;this.building=e,this.rebuild(),t&&this.fit(0),this.invalidate()}get walking(){return this.controls.walk!==null}startWalk(){let e=this.floors.filter(l=>l.floor.rooms.some(c=>c.points.length>=3)),t=(this.floorId?this.floorMap.get(this.floorId):void 0)??[...e].sort((l,c)=>Math.abs(l.floor.elevation)-Math.abs(c.floor.elevation))[0];if(!t||!t.bbox)return null;let n=t.floor.rooms.filter(l=>l.points.length>=3),r=n.find(l=>l.id===this.roomId)??[...n].sort((l,c)=>vr(c.points)-vr(l.points))[0],[s,o]=r?Bs(r.points):[(t.bbox.x0+t.bbox.x1)/2,(t.bbox.z0+t.bbox.z1)/2];this.floorId!==t.floor.id&&this.setFloor(t.floor.id,!1);let a=.3;return this.controls.walk={eye:new U(s,t.floor.elevation+t.ty+TP,o),yaw:this.controls.view.theta,pitch:-.05,stick:[0,0],keys:new Set,bounds:{x0:t.bbox.x0-a,x1:t.bbox.x1+a,z0:t.bbox.z0-a,z1:t.bbox.z1+a},last:0},this.labelsDirty=!0,this.wake(),t.floor.id}stopWalk(){this.controls.walk&&(this.controls.walk=null,this.labelsDirty=!0,this.fit(700))}setWalkStick(e,t){this.controls.walk&&(this.controls.walk.stick=[e,t],this.wake())}setFloor(e,t=!0){let n=this.keepCamera&&this.floorId!==null&&e!==null&&e!==this.floorId?{theta:this.controls.view.theta,phi:this.controls.view.phi,radius:this.controls.view.radius}:null;this.floorId=e,this.roomId=null,this.labelsDirty=!0,this.applyTargets(!t),this.applyHighlight(),this.fit(t?700:0,n)}setKeepCamera(e){this.keepCamera=e}setZoom(e){let t=Math.min(3,Math.max(.5,e||1));t!==this.zoom&&(this.zoom=t,this.building&&this.fit(400))}setFloorStack(e){e!==this.floorStack&&(this.floorStack=e,this.applyTargets(!1))}setKeepRoof(e){e!==this.keepRoof&&(this.keepRoof=e,this.invalidate())}setExplode(e){e!==this.explode&&(this.explode=e,this.applyTargets(!1),this.floorId===null&&this.fit(700))}selectRoom(e){if(this.roomId=e,this.labelsDirty=!0,this.applyHighlight(),!e){this.fit(700);return}let t=this.floors.find(u=>u.floor.rooms.some(h=>h.id===e)),n=t?.floor.rooms.find(u=>u.id===e);if(!t||!n)return;let r=n.start_view;if(r){let u=t.floor.elevation+t.ty,[h,f]=Bs(n.points),d=r.target??{x:h,y:.3,z:f};this.controls.flyTo({target:new U(d.x,d.y+u,d.z),radius:r.radius,phi:r.phi,theta:r.theta});return}let[s,o]=Bs(n.points),a=n.points.map(u=>u[0]),l=n.points.map(u=>u[1]),c=new U(Math.max(...a)-Math.min(...a),t.floor.cut_height,Math.max(...l)-Math.min(...l));this.controls.flyTo({target:new U(s,t.floor.elevation+t.ty+.3,o),radius:Math.max(4,this.distanceFor(c)*1.05),phi:.72})}get lowered(){return this.wallMode!=="auto"}setPaintedWalls(e){e!==this.painted&&(this.painted=e,this.rebuild(),this.invalidate())}wallPaint(e){return this.painted&&this.building?Gp(this.building.settings,e):void 0}setWallMode(e){this.wallMode=e;for(let t of this.floors)this.buildLamps(t);this.invalidate()}setDevices(e){let t=e.map(r=>`${r.id}:${r.active?1:0}:${r.glow?r.glow.level.toFixed(1):"-"}`).join(";");t!==this.deviceLook&&(this.deviceLook=t,this.wake()),this.devices=e,this.labelsDirty=!0,this.effectFloors=new Set(e.filter(r=>r.effect&&r.glow||(r.spin??0)>0).map(r=>r.floorId)),this.deviceFloor=new Map(e.map(r=>[r.id,r.floorId]));let n=new Set;for(let r of e){n.add(r.id);let s=this.devicePins.get(r.id);s||(s={el:Ay(r.id,this.pinHooks),icon:"",text:"",watt:"",label:"",active:!1,unavailable:!1,glow:"",caption:""},this.devicePins.set(r.id,s),this.labels.append(s.el));let o=s.el;s.icon!==r.icon&&(s.icon=r.icon,o.querySelector(".nf-dev-icon").innerHTML=r.icon),s.text!==r.text&&(s.text=r.text,o.querySelector(".nf-dev-text").textContent=r.text);let a=r.caption??"";s.caption!==a&&(s.caption=a,o.querySelector(".nf-dev-name").textContent=a);let l=r.power!==null&&r.power!==void 0&&r.power>=1?r.powerText??`${Math.round(r.power)} W`:"";s.watt!==l&&(s.watt=l,o.querySelector(".nf-dev-watt").textContent=l);let c=`${r.name}: ${r.text}`;s.label!==c&&(s.label=c,o.title=r.name,o.setAttribute("aria-label",c)),s.active!==r.active&&(s.active=r.active,o.classList.toggle("nf-dev-on",r.active)),s.unavailable!==r.unavailable&&(s.unavailable=r.unavailable,o.classList.toggle("nf-dev-na",r.unavailable));let u=r.glow?`rgb(${r.glow.color.map(h=>Math.round(h*255)).join(", ")})`:"";s.glow!==u&&(s.glow=u,u?o.style.setProperty("--nf-glow",u):o.style.removeProperty("--nf-glow"))}for(let[r,s]of this.devicePins)n.has(r)||(s.el.remove(),this.devicePins.delete(r));for(let r of this.floors)this.buildGlow(r),this.buildLamps(r);this.invalidate()}setRoofWindows(e){let t=JSON.stringify([...e]);t!==this.roofWindowsKey&&(this.roofWindowsKey=t,this.roofWindows=e,this.buildRoofMesh(),this.invalidate())}setPersons(e){this.labelsDirty=!0,this.persons=e;let t=new Set;for(let n of e){t.add(n.id);let r=this.personPins.get(n.id);if(r||(r=document.createElement("div"),r.className="nf-person",r.dataset.entity=n.id,this.personPins.set(n.id,r),this.labels.append(r)),r.title=n.name,r.setAttribute("aria-label",n.name),r.dataset.picture!==(n.picture??"")||r.dataset.initials!==n.initials)if(r.dataset.picture=n.picture??"",r.dataset.initials=n.initials,r.replaceChildren(),n.picture){let s=document.createElement("img");s.src=n.picture,s.alt="",s.addEventListener("error",()=>s.replaceWith(document.createTextNode(n.initials))),r.append(s)}else r.textContent=n.initials}for(let[n,r]of this.personPins)t.has(n)||(r.remove(),this.personPins.delete(n));this.invalidate()}setNavigationLocked(e){this.controls.locked=e}setPickTargets(e,t,n=new Map){this.pickFurniture=e,this.pickOpenings=t,this.pickOpenings2=n}setNotePhotos(e){this.notePhoto=e}setFurnitureColors(e){JSON.stringify(e??{})!==JSON.stringify(this.furnitureColors??{})&&(this.furnitureColors=e,this.building&&(this.rebuild(),this.invalidate()))}setAccent(e){let t=wy(e),n=t?1:0;n===Yu.value&&(!t||Xu.value.equals(new U(...t)))||(Yu.value=n,t&&Xu.value.set(...t),this.invalidate())}setTheme(e){if(e===this.theme)return;this.theme=e,this.placeMap(),this.themeUniform.value=Sy(e);let t=xl(e),n=[...this.floors.map(r=>r.materials.lines),...this.roof?[this.roof.lines]:[]];for(let r of n)r.blending=t,r.needsUpdate=!0;this.placeGround(),this.invalidate()}setFurnishMode(e){this.furnish=e,e||this.selectFurniture(null),this.invalidate()}selectFurniture(e){e&&this.selectedDevice&&this.selectDevice(null),this.selectedFurniture=e,this.updateGhost(),this.invalidate()}setSun(e){this.sun=e;for(let t of this.floors)this.buildSun(t);this.buildHouseShadow(),this.buildSunArc(),this.invalidate()}setLocation(e){this.sunArcLocation=e,this.buildSunArc(),this.invalidate()}buildSunArc(){let e=this.building,t=this.sunArcLocation,n=(e?.floors??[]).flatMap(c=>[...c.rooms.flatMap(u=>u.points),...(c.outdoor??[]).flatMap(u=>u.points)]);if(!e||!e.settings.sun_arc||!t||!n.length)return void this.sunArc.update(null,null,0);let r=n.map(c=>c[0]),s=n.map(c=>c[1]),o=[(Math.min(...r)+Math.max(...r))/2,(Math.min(...s)+Math.max(...s))/2],a=Math.max(6,Math.hypot(Math.max(...r)-Math.min(...r),Math.max(...s)-Math.min(...s))/2+3),l=Math.min(0,...e.floors.map(c=>c.elevation));this.sunArc.update({centre:o,radius:a,north:e.settings.north??0,...t},this.sun,l)}buildHouseShadow(){if(!this.houseShadow)return;let e=this.building,t=(e?.floors??[]).filter(u=>u.elevation>=-.01&&u.rooms.length),n=!e||!t.length||e.settings.sun_patches===!1||this.lowQuality,r=this.weatherLayer?.cloud??0,s=e?.settings.north??0,o=t.map(u=>`${u.elevation}:${u.height}:${JSON.stringify(u.rooms.map(h=>h.points))}`).join("|"),a=n?"off":`${this.sun?.elevation.toFixed(1)},${this.sun?.azimuth.toFixed(1)},${s},${r.toFixed(2)},${o}`;if(a===this.shadowKey)return;if(this.shadowKey=a,n){this.houseShadow.update([],0,0,null,0,0,!0);return}let l=Math.min(...t.map(u=>u.elevation)),c=Math.max(...t.map(u=>u.elevation+u.height));this.footprint.key!==o&&(this.footprint={key:o,rings:fr(t.flatMap(u=>u.rooms.map(h=>h.points)))}),this.houseShadow.update(this.footprint.rings,c-l,l+.03,this.sun,s,r,!1)}liftOf=e=>{if(!e)return{y:0,dy:0,visible:!0};let t=this.floorMap.get(e);return t?{y:t.floor.elevation+t.y,dy:t.y,visible:t.group.visible}:{y:0,dy:0,visible:!1}};setLiveEnergy(e,t){this.energyLayer.setArcs(e),this.energyLayer.setSparks(t),this.invalidate()}setLiveSound(e,t){this.soundLayer.set(e,t),this.invalidate()}setGlassWalls(e){let t=Math.min(1,Math.max(0,e));t!==this.glassAlpha.value&&(this.glassAlpha.value=t,this.invalidate())}setLiveWater(e){this.waterLayer.set(e),this.invalidate()}setLiveScreens(e){let t=[];for(let n of e){let r=this.building?.floors.find(a=>a.id===n.floorId),s=r?.furniture.find(a=>a.id===n.furnitureId),o=s&&r?th(s,r):null;!s||!o||t.push({...n,x:s.x,z:s.z,rotation:s.rotation,rect:o})}this.screenLayer.set(t),this.invalidate()}setPictures(e){let t=[];for(let n of e){let r=this.building?.floors.find(a=>a.id===n.floorId),s=r?.furniture.find(a=>a.id===n.furnitureId),o=s&&r?Sp(s,r):null;!s||!o||t.push({id:n.furnitureId,floorId:n.floorId,url:n.url,border:n.border,fit:n.fit,x:s.x,z:s.z,rotation:s.rotation,rect:o})}this.pictureLayer.set(t),this.invalidate()}setLiveAnchors(e,t){this.liveAnchors=e,this.liveAnchorCb=t,this.invalidate()}placeLhAnchors(){let e=this.liveAnchorCb;if(!e||!this.liveAnchors.length)return;let t=new U;this.liveAnchors.forEach((n,r)=>{let s=this.liftOf(n.floorId);t.set(n.x,s.y+n.y,n.z).project(this.camera);let o=s.visible&&t.z<1&&Math.abs(t.x)<1.15&&Math.abs(t.y)<1.15;e(r,(t.x+1)/2*this.size.w,(1-t.y)/2*this.size.h,o)})}setSky(e){this.skyView=e,this.weatherLayer.set(e?{...e,low:e.low||this.lowQuality}:null),this.buildHouseShadow();for(let t of this.floors)this.buildSun(t);this.invalidate()}setRoomTint(e){let t=!!e!=!!this.roomTint;if(this.roomTint=e,this.tintTick=!0,this.applyHighlight(),t)for(let n of this.floors)n.glowSig="",this.buildGlow(n)}setScreens(e){this.screens=e;for(let t of this.floors)this.buildScreens(t);this.invalidate()}fillRoomPin(e,t,n){if(e.textContent=t||"\u2013",n){let r=document.createElement("small");r.textContent=n,e.append(r),e.classList.add("nf-pin-info")}else e.classList.remove("nf-pin-info")}setRoomInfo(e){if(!(e.size===this.roomInfo.size&&[...e].every(([n,r])=>this.roomInfo.get(n)===r))){this.roomInfo=e;for(let n of this.floors)for(let r of n.roomPins)this.fillRoomPin(r.pin,r.room.name,e.get(r.room.id))}}setFloorInfo(e){this.floorInfo=e;for(let t of this.floors){let n=t.label.querySelector("span"),r=e.get(t.floor.id)??this.options.floorInfo?.(t.floor)??"";n&&n.textContent!==r&&(n.textContent=r,t.labelSize=null,this.labelsDirty=!0)}this.invalidate()}setOpeningStates(e){let t=this.openingTargets;this.openingTargets=e,[...e].some(([n,r])=>!tp(t.get(n)??Ns,r))&&this.wake(),this.invalidate()}wake(){this.awakeUntil=performance.now()+YM,this.invalidate()}get resting(){return this.lowQuality&&performance.now()>this.awakeUntil}setFridgeDoors(e){for(let[t,n]of e){let r=this.fridges.get(t)??{l:n.left?1:0,r:n.right?1:0,tl:0,tr:0};r.tl=n.left?1:0,r.tr=n.right?1:0,this.fridges.set(t,r)}for(let t of[...this.fridges.keys()])e.has(t)||this.fridges.delete(t);this.invalidate()}setCovers(e){let t=!1;for(let[n,r]of e){let s=this.covers.get(n);s?s.t!==r&&(s.t=r,t=!0):(this.covers.set(n,{k:r,t:r}),t=!0)}for(let n of[...this.covers.keys()])e.has(n)||this.covers.delete(n);if(t){for(let n of this.floors)this.buildFridges(n);this.wake()}}stepCovers(e){let t=Math.min(1,e/4e3),n=!1;for(let r of this.covers.values()){if(r.k===r.t)continue;let s=r.t-r.k;r.k=Math.abs(s)<=t?r.t:r.k+Math.sign(s)*t,n=!0}if(n)for(let r of this.floors)this.buildFridges(r);return n}stepFridges(e){let t=ep(e),n=new Set;for(let[r,s]of this.fridges)for(let[o,a]of[["l","tl"],["r","tr"]]){let l=s[a]-s[o];if(Math.abs(l)<.004){l!==0&&(s[o]=s[a],n.add(r));continue}s[o]+=l*t,n.add(r)}if(!n.size)return!1;for(let r of this.floors)r.floor.furniture.some(s=>n.has(s.id))&&this.buildFridges(r);return!0}buildFridges(e){let t=new lt;for(let n of e.floor.furniture){let r=vt(n.type);if(r&&P0(r)){Gd(t,r,n,Gt(e.floor,n),this.covers.get(n.id)?.k??I0(r,null));continue}if(n.type!=="fridge_smart")continue;let s=this.fridges.get(n.id);vp(t,n,Gt(e.floor,n),s?.l??0,s?.r??0)}e.fridgeMesh.geometry.dispose(),e.fridgeMesh.geometry=t.geometry(),e.fridgeMesh.visible=t.count>0}resetView(){this.fit(700)}setStartView(e){this.startView=e}currentView(){let e=this.controls.view,t=this.floorBase(this.floorId);return{theta:e.theta,phi:e.phi,radius:e.radius,target:{x:e.target.x,y:e.target.y-t,z:e.target.z}}}floorBase(e){let t=e===null?void 0:this.floorMap.get(e);return t?t.floor.elevation+t.ty:0}dispose(){this.disposed=!0,cancelAnimationFrame(this.frame),clearTimeout(this.effectTimer),clearTimeout(this.robotTimer),clearTimeout(this.orbitTimer),clearTimeout(this.weatherTimer),this.weatherLayer.dispose(),this.sunArc?.dispose(),this.houseShadow?.dispose(),this.mapLayer.dispose(),this.energyLayer.dispose(),this.soundLayer.dispose(),this.waterLayer.dispose(),this.screenLayer.dispose(),this.pictureLayer.dispose(),this.resizeObserver.disconnect(),this.intersection?.disconnect(),document.removeEventListener("visibilitychange",this.onVisibility),this.host?.removeEventListener("pointerdown",this.onTouch),this.renderer?.domElement?.removeEventListener?.("pointerdown",this.onRightDown),this.renderer?.domElement?.removeEventListener?.("pointerup",this.onRightUp),this.renderer?.domElement?.removeEventListener?.("contextmenu",this.onContext),clearTimeout(this.petTimer),this.controls.dispose(),this.clear(),this.building=null,this.buildRoofMesh(),this.ground.geometry.dispose(),this.ground.material.dispose(),this.patternTexture.dispose(),this.blindTexture.dispose(),this.groundTexture?.dispose(),this.haloTexture.dispose();for(let e of this.robots.values())e.led.dispose();this.robots.clear();for(let e of this.robotTrails.values())e.removeFromParent(),e.geometry.dispose(),e.material.dispose();this.robotTrails.clear();for(let e of this.trailTimers.values())clearTimeout(e);this.trailTimers.clear(),this.robotGeo?.dispose(),this.robotLedGeo?.dispose(),this.robotMat?.dispose(),this.mowerMat?.dispose(),this.meshLight?.dispose(),this.renderer.dispose(),this.renderer.forceContextLoss(),this.renderer.domElement.remove(),this.labels.remove()}invalidate(){this.frame||this.disposed||document.hidden||!this.onScreen||(this.frame=requestAnimationFrame(e=>this.render(e)))}makeRenderer(e){let t=e==="low"||e==="auto"&&xb();this.lowQuality=t,this.weatherLayer&&this.skyView&&this.weatherLayer.set({...this.skyView,low:this.skyView.low||t}),this.weatherLayer&&this.buildHouseShadow(),this.highQuality=e==="high";let n=new kr({antialias:!t,alpha:!0,powerPreference:t?"low-power":"default"}),r=Math.min(window.devicePixelRatio||1,t?1:e==="high"?2.5:2);return n.setPixelRatio(r),this.governor=e==="auto"&&!t?new Lu(r,Math.min(1,r)):null,n.setClearColor(0,0),n.outputColorSpace=ft,n.domElement.className="nf-canvas",this.host.prepend(n.domElement),n}makeControls(){return new El(this.renderer.domElement,this.camera,{change:()=>this.wake(),tap:(e,t)=>this.onTap(e,t),hold:(e,t)=>this.onHold(e,t),swipeStart:(e,t,n,r)=>this.swipeStart(e,t,n,r),swipeMove:e=>this.swipe&&this.options.onDeviceSwipe?.(this.swipe.entity,"move",e,this.swipe.x,this.swipe.y),swipeEnd:()=>{this.swipe&&this.options.onDeviceSwipe?.(this.swipe.entity,"end",0,this.swipe.x,this.swipe.y),this.swipe=null},grab:(e,t)=>this.grabFurniture(e,t),drag:(e,t)=>this.dragFurniture(e,t),drop:()=>this.dropFurniture(),doubleTap:(e,t)=>{let n=this.floorId&&this.options.onRoomDoubleTap?this.pick(e,t):null;n&&!("entity"in n)&&n.roomId?this.options.onRoomDoubleTap(n.floorId,n.roomId):this.options.onBack?.()}})}onTouch=()=>this.wake();onVisibility=()=>{document.hidden&&(clearTimeout(this.effectTimer),this.effectTimer=void 0),document.hidden||this.invalidate()};scheduleEffects(){if(!this.hasVisibleEffects(document.hidden)||this.resting){clearTimeout(this.effectTimer),this.effectTimer=void 0;return}if(this.effectTimer!==void 0)return;let e=this.lowQuality?2*XM:XM;this.effectTimer=setTimeout(()=>{if(this.effectTimer=void 0,!!this.hasVisibleEffects(document.hidden)){this.effectTime=performance.now()/1e3,this.effectTick=!0;for(let t of this.floors)t.o<.02||!this.effectFloors.has(t.floor.id)||(this.buildLamps(t),this.buildGlow(t));this.invalidate()}},e)}hasVisibleEffects(e){return!e&&!this.disposed&&this.onScreen&&this.floors.some(t=>t.o>=.02&&this.effectFloors.has(t.floor.id))}resize(){let e=this.host.clientWidth||1,t=this.host.clientHeight||1;this.size={w:e,h:t},this.labelsDirty=!0,this.renderer.setSize(e,t,!1),this.camera.aspect=e/t,this.camera.updateProjectionMatrix(),this.invalidate()}clear(){for(let e of this.robots.values())e.group.removeFromParent();for(let e of this.meshes)e.group.removeFromParent(),Rm(e.group);this.meshes=[];for(let e of this.floors){e.group.traverse(t=>{t.geometry?.dispose()});for(let t of Object.values(e.materials))Array.isArray(t)||t.dispose();for(let t of e.materials.ghosts)t.material.dispose();this.root.remove(e.group)}this.floors=[],this.floorMap=new Map;for(let e of[...this.labels.children])e.dataset.entity||e.remove()}buildLightSurface(e){let t=this.lowQuality?.5:.25,n=ap(e.floor,e.geo.walls2d,e.geo.wallBuckets,e.geo.openings,t,e.geo.holes,e.geo.roofUnder),r=CP(e.floor,e.geo.openRooms);if(e.lightZones=r.some((a,l)=>a!==l)?r:null,e.lightZones){for(let a=0;a=0&&l=0&&a.a=0&&a.bthis.glowOf(h)),r=t.doors.map(h=>{let f=e.geo.openings.find(p=>p.opening.id===h.id);if(f&&_r(f.opening,f.exterior)==="passage")return 1;let d=e.openings.get(h.id);return d?Math.max(d.open,d.open2??0):.5}),s=n.map(h=>`${h.x.toFixed(2)},${h.y.toFixed(2)},${h.z.toFixed(2)},${h.kind},${h.level.toFixed(3)},${h.color.map(f=>f.toFixed(3)).join("/")}`).join(";")+"|"+r.map(h=>h.toFixed(1)).join(",");if(s===e.glowSig)return;e.glowSig=s;let o=e.glowMesh.geometry,a=o.getAttribute("color");if(!n.length){e.glowMesh.visible=!1,o.setDrawRange(0,0);return}let l=lp(t,n,.42,r);if(this.roomTint){let h=e.floor.rooms.length;for(let f=0;f.004;if(f)for(let d=0;d<6;d++)c[u++]=h*6+d}o.index.needsUpdate=!0,o.setDrawRange(0,u),e.glowMesh.visible=u>0}withoutFurniture(e){if(this.gateOpen.size&&(e.outdoor??[]).some(n=>n.gates?.length)&&(e={...e,outdoor:e.outdoor.map(n=>n.gates?.length?{...n,gates:n.gates.map(r=>({...r,open:this.gateOpen.get(r.id)??!1}))}:n)}),!this.plain)return e;let t=n=>n.type==="stairs"||n.type==="stairwell"||!!vt(n.type)?.hole;return{...e,furniture:e.furniture.filter(t)}}rebuild(){let e=new Map(this.floors.map(s=>[s.floor.id,{y:s.y,o:s.o}])),t=new Map(this.floors.map(s=>[s.floor.id,s.openings]));this.clear();let n=this.building;if(!n)return;fb({...n.settings.furniture_colors,...this.furnitureColors});let r=[...n.floors].sort((s,o)=>s.elevation-o.elevation);for(let s of n.floors){let o=n.settings.roof?.solar??[],a=ih(n)?.id===s.id?o.filter(V=>V.face===Sl).map(V=>({field:V,face:rh(n,V)})):[],l=o.filter(V=>V.face.startsWith(`wall:${s.id}:`));if(l.length){let V=new Map(nh(n,s.id).map(re=>[re.key,re]));for(let re of l){let be=V.get(re.face);be&&a.push({field:re,face:be})}}let u=(n.settings.roof.sections??[]).some(V=>$d(V,s.elevation+s.height))?(V,re)=>{let be=Kd(n,V,re);return be===null?null:be-s.elevation}:void 0,h=Hp(this.withoutFurniture(bh(s,this.parked)),n.settings.wall_exterior,n.settings.wall_interior,Wp(n.floors,s),a,u,this.wallPaint(s)),f={standing:{value:65535},glass:{value:0},slope:{value:new _t},slopeY:{value:new De},glassAlpha:this.glassAlpha},d=Ty({mask:f,look:this.themeUniform,theme:this.theme,textures:{pattern:this.patternTexture,blinds:this.blindTexture,halo:this.haloTexture}}),p=new ct,x=new we(h.floor,d.floor),g=new we(h.shadow,d.shadow);g.renderOrder=1;let m=new we(h.floor,d.pattern);m.renderOrder=2;let b=new we(new Fe,d.glow);b.renderOrder=3,b.visible=!1;let v=new we(new Fe,d.frames),y=new we(new Fe,d.blinds),M=new we(new Fe,d.glass);M.renderOrder=4;let S=new we(new Fe,d.lamps);S.visible=!1;let _=new we(new Fe,d.cones);_.visible=!1,_.renderOrder=3;let w=new xn(new Fe,d.halos);w.visible=!1,w.renderOrder=7;let R=new we(new Fe,d.cones);R.visible=!1,R.renderOrder=7;let A=new we(new Fe,d.lamps);A.visible=!1;let C=new we(new Fe,d.screens);C.visible=!1,C.renderOrder=5;for(let V of[v,y,M])V.frustumCulled=!1;let O=new we(h.walls,d.glassWall),D=new we(h.walls,d.wall);O.renderOrder=6,p.add(x,g,m,b,D,new gn(h.lines,d.lines),v,y,M,S,_,w,R,A,C,O);for(let V of h.ghosts){let re=Zn(new Ke({vertexColors:!0,transparent:!0,opacity:V.opacity,depthWrite:!1,side:ut}),this.themeUniform);d.ghosts.push({material:re,base:V.opacity});let be=new we(V.geometry,re);be.renderOrder=2,p.add(be)}this.root.add(p);let P=document.createElement("button");P.className="nf-pin nf-pin-floor",P.dataset.floor=s.id;let I=document.createElement("b");I.textContent=s.name||"\u2013";let N=document.createElement("span");N.textContent=this.floorInfo.get(s.id)??this.options.floorInfo?.(s)??"",P.append(I,N),P.addEventListener("click",()=>this.options.onFloorTap?.(s.id)),this.labels.append(P);let F=e.get(s.id),H=[],B=null;for(let V of s.rooms){let re=document.createElement("button");re.className="nf-pin",re.dataset.room=V.id,re.dataset.floor=s.id,this.fillRoomPin(re,V.name,this.roomInfo.get(V.id)),re.addEventListener("click",()=>this.options.onRoomTap?.(s.id,V.id)),this.labels.append(re);let[be,Y]=Bs(V.points);H.push({pin:re,room:V,cx:be,cz:Y});for(let[Q,se]of V.points)B??={x0:Q,x1:Q,z0:se,z1:se},B.x0=Math.min(B.x0,Q),B.x1=Math.max(B.x1,Q),B.z0=Math.min(B.z0,se),B.z1=Math.max(B.z1,se)}let X=[];for(let V of s.notes??[]){if(!V.text)continue;let re=document.createElement("button");re.className=`nf-pin nf-note-pin${d0(V)?" nf-note-due":""}`,re.title=V.text;let be=V.text.length>28?`${V.text.slice(0,27)}\u2026`:V.text;re.textContent=`${V.photo?"\u{1F4F7} ":"\u270E "}${be}`,re.addEventListener("click",()=>{let Y=re.classList.toggle("nf-note-open");re.textContent=`${V.photo?"\u{1F4F7} ":"\u270E "}${Y?V.text:be}`;let Q=Y&&V.photo?this.notePhoto?.(V.photo):null;if(Q){let se=document.createElement("img");se.className="nf-note-photo",se.alt="",se.src=Q,se.addEventListener("load",()=>{this.labelsDirty=!0,this.invalidate()}),re.append(se)}this.labelsDirty=!0,this.invalidate()}),this.labels.append(re),X.push({pin:re,note:V})}this.floors.push({floor:s,rank:r.indexOf(s),group:p,geo:h,floorMesh:x,shadowMesh:g,patternMesh:m,glowMesh:b,lightSurface:null,lightZones:null,framesMesh:v,glassMesh:M,blindsMesh:y,lampMesh:S,sunMesh:_,sunSig:"",haloMesh:w,coneMesh:R,wedgeTris:[],fridgeMesh:A,lampTris:[],lampFurnTris:[],frameTris:[],glassTris:[],blindTris:[],wallMesh:D,screenMesh:C,screenSig:"",flowLayout:"",glowSig:"",lampShapeSig:"",lampColorSig:"",lampShade:new Float32Array(0),lampRanges:new Map,bbox:B,roomPins:H,notePins:X,labelSize:null,materials:d,mask:f,openings:new Map,y:F?.y??0,o:F?.o??1,ty:0,to:1,appliedO:-1,label:P})}this.floorMap=new Map(this.floors.map(s=>[s.floor.id,s])),this.buildPets();for(let s of this.floors)this.buildFridges(s);this.labelsDirty=!0,this.floorId&&!n.floors.some(s=>s.id===this.floorId)&&(this.floorId=null);for(let s of this.floors){this.buildLamps(s),this.buildScreens(s);let o=t.get(s.floor.id);for(let a of s.geo.openings)s.openings.set(a.opening.id,o?.get(a.opening.id)??this.openingTargets.get(a.opening.id)??Ns);this.buildOpenings(s),this.buildLightSurface(s),this.buildSun(s)}this.applyTargets(e.size===0),this.applyHighlight(),this.applyTierFlags(),this.buildRoofMesh(),this.updateGhost(),this.placeMeshes()}placeMeshes(){for(let e of this.meshes)e.group.removeFromParent(),Rm(e.group);this.meshes=[];for(let e of this.floors)for(let t of bh(e.floor,this.parked).furniture){let n=vt(t.type);if(!n?.mesh)continue;let r=n.mesh;if(!Dl(t.type)){this.meshAsked.has(r)||(this.meshAsked.add(r),yM(r).then(a=>{a&&!this.disposed&&this.rebuild()}));continue}let s=n.colors?.length?(n.colors.find(a=>a.id===t.variant)??n.colors[0]).hex:null,o=_M(r,{x:t.x,z:t.z,y:Gt(e.floor,t),rotation:t.rotation,mirror:t.mirror,w:t.w,d:t.d,h:t.h,paint:s});o&&(this.meshLight||(this.meshLight=vM(this.root,this.renderer)),MM(o,this.meshLight.env),e.group.add(o),this.meshes.push({group:o,furnitureId:t.id}))}this.invalidate()}buildRoofMesh(){this.roof&&(this.roof.group.traverse(a=>a.geometry?.dispose()),this.roof.solid.dispose(),this.roof.lines.dispose(),this.roof.glass.dispose(),this.scene.remove(this.roof.group),this.roof=null);let e=this.building?kp(this.building,this.roofWindows):[];if(!e.length)return;let t=new ct,n=Zn(new Ke({vertexColors:!0,transparent:!0,side:ut}),this.themeUniform),r=Zn(new Lt({vertexColors:!0,transparent:!0,blending:xl(this.theme),depthWrite:!1}),this.themeUniform,!0),s=Zn(new Ke({vertexColors:!0,transparent:!0,side:ut,depthWrite:!1}),this.themeUniform),o=e.map(a=>{let l=new ct;return l.add(new we(a.solid.geometry(),n),new gn(a.lines.geometry(),r)),a.glass.count&&l.add(new we(a.glass.geometry(),s)),l.renderOrder=8,t.add(l),{group:l,floorId:a.floor.id,rideId:Jd(this.building,a.floor,a.sections??[]),base:a.base,lift:a.lift!==!1}});t.renderOrder=8,this.scene.add(t),this.roof={group:t,parts:o,solid:n,lines:r,glass:s},this.placeRoof()}placeRoof(e=1e3){let t=this.roof;if(!t)return!1;let n=this.keepRoof?1:Math.min(1,Math.max(0,(this.controls.view.radius/this.houseRadius-.62)/.3)),s=(this.floorId===null||this.floors.length===1)&&!this.lowered?qM*n:0,o=Qd(e),a=this.roofO;this.roofO+=(s-this.roofO)*o,Math.abs(s-this.roofO)<.004&&(this.roofO=s),t.group.visible=this.roofO>.02;for(let l of t.parts){let c=this.floorMap.get(l.floorId);if(!c)continue;let u=this.floorMap.get(l.rideId)??c,h=u.ty>0?Math.min(1,u.y/u.ty):this.explode&&this.floorId===null?1:0,f=Math.max(0,1-this.roofO/qM);l.group.position.y=c.floor.elevation+u.y+l.base+f*2.2+(l.lift?h*SP:0)}return t.solid.opacity=this.roofO,t.solid.depthWrite=this.roofO>.5,t.lines.opacity=this.roofO,t.glass.opacity=this.roofO*.28,this.roofO!==a&&this.roofO!==s}applyTierFlags(){let e=this.lowQuality;this.ground.visible=!e&&this.theme!=="day"&&this.floors.some(t=>t.floor.rooms.length>0);for(let t of this.floors)t.patternMesh.visible=!e,t.shadowMesh.visible=!e&&t.o>.98;this.invalidate()}rebuildTier(){for(let e of this.floors)e.flowLayout="",this.buildLightSurface(e),e.lampShapeSig="",this.buildLamps(e)}get houseView(){return this.floorId===null&&this.floors.length>1}applyTargets(e){let t=this.floorId?this.floorMap.get(this.floorId):void 0;for(let n of this.floors){let r=Vb(n.rank,t?.rank,this.explode,this.floorStack);[n.ty,n.to]=[r.y,r.opacity],e&&([n.y,n.o]=[r.y,r.opacity]),this.applyFloor(n)}this.invalidate()}applyFloor(e){e.group.position.y=e.floor.elevation+e.y,e.group.visible=e.o>.02,e.shadowMesh.visible=e.o>.98&&!this.lowQuality,!(Math.abs(e.appliedO-e.o)<.001)&&(e.appliedO=e.o,Hb(e.materials,e.o))}stepFloors(e){let t=!1,n=Qd(e);for(let r of this.floors){let s=Gb(r,n);s.settled&&(this.labelsDirty=!0),(s.moving||s.settled)&&this.applyFloor(r),t||=s.moving}return t}stepOpenings(e){let t=!1,n=ep(e);for(let r of this.floors){let s=!1;for(let[o,a]of r.openings){let l=this.openingTargets.get(o)??Ns;if(tp(a,l))continue;let c=Yb(a,l,n);r.openings.set(o,c.state),s=!0,t||=c.moving}s&&(this.buildOpenings(r),this.buildGlow(r),this.buildSun(r))}return t}fanPhase(e){return e.lamp!=="fan"||!e.spin?0:Math.round(this.effectTime*e.spin*360%KM*10)/10}glowOf(e){return Lv(e.glow,e.effect,this.effectTime)}buildLamps(e){let t=performance.now(),n=h=>{let f=this.flashes.get(h);if(!f||f<=t)return 0;let d=f-t,p=d>jm?.5+.5*Math.sin(d/140):d/jm;return Math.round(p*10)/10},r=this.devices.filter(h=>h.floorId===e.floor.id&&h.lamp),s=this.wallMode+(this.lowQuality?"L":this.highQuality?"H":"M")+r.map(h=>`${h.id},${h.lamp},${h.variant},${h.x},${h.z},${h.y},${h.rotation??0},${h.roll??0},${h.upright?1:0},${h.rise??0},${h.size?.join("/")},${h.base??0},${h.pack??""},${h.mirror?1:0},${h.ceiling??""},${this.fanPhase(h)}`).join(";"),o=r.map(h=>this.glowOf(h)),a=this.devices.filter(h=>h.floorId===e.floor.id&&h.wedge),l=r.map((h,f)=>`${n(h.id)},${o[f]?`${o[f].level.toFixed(3)},${o[f].color.map(d=>d.toFixed(3)).join("/")}`:"off"}`).join(";")+"|"+a.map(h=>`${h.id},${h.x},${h.z},${h.rotation??0},${JSON.stringify(h.wedge)}`).join(";");if(s!==e.lampShapeSig||!e.lampMesh.geometry.getAttribute("position")){e.lampShapeSig=s,e.lampColorSig="";let h=new lt,f=[],d=[],p=new Map,x=e.floor.height;for(let g of r){let m=g.lamp==="strip"?(g.base??x)>Math.min(e.floor.cut_height,g.ceiling??x):g.lamp?ku.has(g.lamp):!1;if(!g.lamp||m&&this.lowered)continue;let b=h.count,v=g.pack?vt(g.pack):void 0,[y,M,S]=g.size??[.3,.3,.3];v?rl(h,v,{x:g.x,z:g.z,rotation:g.rotation??0,w:y,d:M,h:S,mirror:g.mirror},g.base??0,65280):Jm(h,{...g,lamp:g.lamp,phase:this.fanPhase(g)},g.ceiling??x,65280),p.set(g.furnitureId??g.id,{start:b,end:h.count}),g.pickable!==!1&&f.push({id:g.id,start:b,end:h.count}),g.furnitureId&&d.push({id:g.furnitureId,start:b,end:h.count})}e.lampTris=f,e.lampFurnTris=d,e.lampRanges=p,e.lampShade=bb(h.c),e.lampMesh.geometry.dispose(),e.lampMesh.geometry=h.geometry(),e.lampMesh.visible=h.count>0}if(l===e.lampColorSig)return;e.lampColorSig=l;let c=e.lampMesh.geometry.getAttribute("color"),u=c.array;r.forEach((h,f)=>{let d=e.lampRanges.get(h.furnitureId??h.id);if(!d)return;let p=o[f],x=p?.55+.45*p.level:0,g=p?new W(...p.color.map(v=>Math.min(1,v*x))):new W(wP),m=n(h.id);m>0&&g.lerp(new W(1,1,1),.7*m);let b=new W(g.getHex());yb(u,e.lampShade,d,[b.r,b.g,b.b])}),c.needsUpdate=!0,this.buildHalos(e)}buildSun(e){let t=this.building?.settings.sun_patches===!1?null:this.sun,n=this.building?.settings.north??0,r=this.weatherLayer?.cloud??0,s=iy(t,n,r,e.openings.values());if(s===e.sunSig)return;e.sunSig=s;let o=ry({floor:e.floor,openings:e.geo.openings,states:e.openings,sun:t,northDegrees:n,cloud:r});e.sunMesh.geometry.dispose(),e.sunMesh.geometry=o.geometry(),e.sunMesh.visible=o.count>0}buildHalos(e){let t={positions:[],colours:[]},n=new lt,r=[];for(let a of this.devices)if(a.floorId===e.floor.id&&a.wedge){let l=Jb(n,a,e.geo.walls2d);a.wedge.through||r.push({id:a.id,...l})}e.wedgeTris=r;let s=this.lowered;for(let a of this.lowQuality?[]:this.devices){let l=this.glowOf(a);if(a.floorId!==e.floor.id||!a.lamp||!l||s&&ty(a.lamp))continue;let c=a;Qb(t,c,l,a.ceiling??e.floor.height),this.highQuality&&(a.lamp==="downlight"||a.lamp==="spot")&&ey(n,c,l,a.ceiling??e.floor.height)}let o=new Fe;o.setAttribute("position",new ke(t.positions,3)),o.setAttribute("color",new ke(t.colours,3)),e.haloMesh.geometry.dispose(),e.haloMesh.geometry=o,e.haloMesh.visible=!this.lowQuality&&t.positions.length>0,e.coneMesh.geometry.dispose(),e.coneMesh.geometry=n.geometry(),e.coneMesh.visible=n.count>0}buildScreens(e){let t=bh(e.floor,this.parked).furniture.filter(s=>this.screens.has(s.id)),n=t.map(s=>`${s.id}:${s.x},${s.z},${s.rotation},${s.w},${s.d},${s.h},${s.mount_y??""},${s.mirror?1:0}:${JSON.stringify(this.screens.get(s.id))}`).join(";");if(n===e.screenSig&&e.screenMesh.geometry.getAttribute("position"))return;e.screenSig=n;let r=new lt;for(let s of t){let o=this.screens.get(s.id),a=s.rotation*pt,l=Math.cos(a),c=Math.sin(a),u=(y,M,S)=>[s.x+y*l-S*c,M,s.z+y*c+S*l];if(o.gangs){let y=vt(s.type);if(!y)continue;for(let M of o.gangs){let S=new W(...M.color.map(_=>Math.min(1,_*(.45+.55*M.level))));il(r,y,s,Gt(e.floor,s),S.getHex(),_=>_.gang===M.gang)}continue}if(o.print!==void 0){let y=Gt(e.floor,s)+s.h*.2,M=Math.min(s.w,s.d)*.16,S=y+s.h*.38*Math.min(1,Math.max(0,o.print)),_=new W(...o.color.map(C=>Math.min(1,C*(.35+.65*o.level)))),w=_.clone().multiplyScalar(.7),R=[u(-M,y,-M),u(M,y,-M),u(M,y,M),u(-M,y,M)],A=[u(-M,S,-M),u(M,S,-M),u(M,S,M),u(-M,S,M)];r.tri(A[0],A[2],A[1],_),r.tri(A[0],A[3],A[2],_);for(let C=0;C<4;C++){let O=(C+1)%4;r.tri(R[C],R[O],A[O],w),r.tri(R[C],A[O],A[C],w)}continue}if(o.fill!==void 0){let y=wp(s,e.floor);if(!y)continue;let M=y.rect,S=Math.min(1,Math.max(0,o.fill)),_=new W(...o.color.map(C=>Math.min(1,C*(.35+.65*o.level)))),w=new W(.08,.1,.13),R=M.z,A=(C,O,D,P,I)=>{r.tri(u(C,D,R),u(O,D,R),u(O,P,R),I),r.tri(u(C,D,R),u(O,P,R),u(C,P,R),I)};if(y.vertical){let C=M.y0+(M.y1-M.y0)*S;S>0&&A(M.x0,M.x1,M.y0,C,_),S<1&&A(M.x0,M.x1,C,M.y1,w)}else{let C=M.x0+(M.x1-M.x0)*S;S>0&&A(M.x0,C,M.y0,M.y1,_),S<1&&A(C,M.x1,M.y0,M.y1,w)}continue}if(o.leds){let y=vt(s.type);if(!y)continue;let M=new W(...o.color.map(S=>Math.min(1,S*(.35+.65*o.level))));il(r,y,s,Gt(e.floor,s),M.getHex(),S=>!!S.glow||!!S.screen);continue}if(o.heat){let y=vt(s.type);if(!y)continue;let M=new W(...o.color.map(S=>Math.min(1,S*(.35+.65*o.level))));il(r,y,s,Gt(e.floor,s),M.getHex(),()=>!0);continue}if(o.faces){let y=Math.max(.05,s.w)*(s.mirror?-1:1),M=Math.max(.05,s.d),S=Math.max(.005,s.h),_=Gt(e.floor,s);for(let w of o.faces){let R=w.part==="right"?.03:-Math.abs(y)/2+.03,A=w.part==="left"?-.03:Math.abs(y)/2-.03,C=_+(w.part==="bottom"?S*.45:S)+.006,O=new W(...w.color.map(B=>Math.min(1,B*(.35+.65*w.level)))),D=new W(0,0,0),P=(B,X,V=C)=>u(B*Math.sign(y),V,X),I=[P(R,-M/2+.03),P(A,-M/2+.03),P(A,M/2-.03),P(R,M/2-.03)];r.tri(I[0],I[2],I[1],O),r.tri(I[0],I[3],I[2],O);let N=.12+.1*w.level,F=O.clone().multiplyScalar(.5),H=[P(R-N,-M/2-N,C+.004),P(A+N,-M/2-N,C+.004),P(A+N,M/2+N,C+.004),P(R-N,M/2+N,C+.004)];for(let B=0;B<4;B++){let X=(B+1)%4;r.tri(I[B],H[X],H[B],F,D,D),r.tri(I[B],I[X],H[X],F,F,D)}}continue}let h=th(s,e.floor);if(!h)continue;let f=new W(...o.color.map(y=>Math.min(1,y*(.35+.65*o.level)))),d=new W(0,0,0),p=h.z+.004;r.tri(u(h.x0,h.y0,p),u(h.x1,h.y0,p),u(h.x1,h.y1,p),f),r.tri(u(h.x0,h.y0,p),u(h.x1,h.y1,p),u(h.x0,h.y1,p),f);let x=Math.min(1.5,o.halo??1);if(x<=0)continue;let g=(.18+.12*o.level)*Math.min(1,x),m=f.clone().multiplyScalar(.5*x),b=[u(h.x0,h.y0,p),u(h.x1,h.y0,p),u(h.x1,h.y1,p),u(h.x0,h.y1,p)],v=[u(h.x0-g,h.y0-g,p+.01),u(h.x1+g,h.y0-g,p+.01),u(h.x1+g,h.y1+g,p+.01),u(h.x0-g,h.y1+g,p+.01)];for(let y=0;y<4;y++){let M=(y+1)%4;r.tri(b[y],v[y],v[M],m,d,d),r.tri(b[y],v[M],b[M],m,d,m)}}e.screenMesh.geometry.dispose(),e.screenMesh.geometry=r.geometry(),e.screenMesh.visible=r.count>0}buildOpenings(e){let t=$p(e.geo.openings,e.openings,Math.min(e.floor.cut_height,e.floor.height),-.2-e.floor.elevation);e.frameTris=t.frameTris,e.glassTris=t.glassTris,e.blindTris=t.blindTris;for(let[n,r]of[[e.framesMesh,t.frames],[e.glassMesh,t.glass],[e.blindsMesh,t.blinds]])n.geometry.dispose(),n.geometry=r,n.visible=r.getAttribute("position").count>0}activeFloors(){return this.floors.filter(e=>e.to>.99)}applyHighlight(){for(let e of this.floors){let t=e.geo.floor.getAttribute("color");for(let n of e.geo.roomTris){let r=new W(n.color),s=this.roomTint?.get(n.roomId);s&&r.lerp(new W(...s).multiplyScalar(.6),.9),n.roomId===this.roomId&&r.lerp(AP,s?.3:.75);for(let o=n.start*3;oc.group),!0)[0];if(l){let c=l.object;for(;c&&!this.meshes.some(h=>h.group===c);)c=c.parent;let u=c?this.pickFurniture.get(this.meshes.find(h=>h.group===c).furnitureId):void 0;if(u)return{entity:u}}}let o=s.flatMap(l=>[l.lampMesh,l.coneMesh,l.framesMesh,l.glassMesh,l.blindsMesh,l.wallMesh,l.floorMesh].filter(c=>c.visible)),a=(l,c)=>l.find(u=>c>=u.start&&ch.group===l.object.parent);if(!(!n&&(l.object===u.lampMesh||l.object===u.coneMesh||l.object===u.framesMesh||l.object===u.blindsMesh||l.object===u.glassMesh))){if(l.object===u.lampMesh||l.object===u.coneMesh){let h=a(l.object===u.lampMesh?u.lampTris:u.wedgeTris,c);if(h)return{entity:h}}else if(l.object===u.framesMesh||l.object===u.blindsMesh||l.object===u.glassMesh){if(this.lowered&&l.face){let x=l.object.geometry.getAttribute("fold")?.getX(l.face.a)??Xe;if(x!==Xe&&Math.floor(x/16)%8===0)continue}let h=a(l.object===u.framesMesh?u.frameTris:l.object===u.glassMesh?u.glassTris:u.blindTris,c),f=h?this.pickOpenings.get(h):void 0,d=h?this.pickOpenings2.get(h):void 0,p=d?u.geo.openings.find(x=>x.opening.id===h):void 0;if(d&&p&&(l.point.x-p.start[0])*p.axis[0]+(l.point.z-p.start[1])*p.axis[1]>p.width/2&&(f=d),f)return{entity:f}}else if(l.object===u.wallMesh){let h=a(u.geo.furnitureTris,c),f=h&&n?this.pickFurniture.get(h):void 0;if(f)return{entity:f};if(l.face&&!h){let d=u.wallMesh.geometry.getAttribute("fold")?.getX(l.face.a)??32,p=Math.floor(d/16)%8,x=d%16,g=this.lowered&&p===0,m=(u.mask.glass.value&1<S.points.length>=3&&Ve(y,S.points))?.id??null;if(this.roomId!==null){if(M===this.roomId)return{floorId:u.floor.id,roomId:M}}else if(!m&&M)return{floorId:u.floor.id,roomId:M}}}}else if(l.object===u.floorMesh)return{floorId:u.floor.id,roomId:a(u.geo.roomTris.map(h=>({id:h.roomId,start:h.start,end:h.end})),c)??null}}}return null}onTap(e,t){let n=this.furnish?this.pick(e,t):this.pickInReach(e,t);if(n&&"entity"in n&&this.furnish){this.selectDevice(n.entity),this.options.onDeviceSelect?.(n.entity);return}if(n&&"entity"in n){this.flashes.set(n.entity,performance.now()+jm),this.invalidate(),this.options.onDeviceTap?.(n.entity,e,t);return}this.options.onRoomTap?.(n?.floorId??this.floorId??"",n?.roomId??null)}furnitureAt(e,t){let n=this.rayAt(e,t),r=this.activeFloors(),s=r.flatMap(o=>[o.lampMesh,o.wallMesh].filter(a=>a.visible));for(let o of n.intersectObjects(s,!1)){if(o.faceIndex==null)continue;let a=r.find(u=>u.group===o.object.parent),c=(o.object===a.lampMesh?a.lampFurnTris:a.geo.furnitureTris).find(u=>o.faceIndex>=u.start&&o.faceIndexh.id===n)?.furnitureId:void 0,a=o?null:this.furnitureAt(e,t),l=o??a?.id,c=l?this.floors.find(h=>h.floor.furniture.some(f=>f.id===l)):void 0,u=c?.floor.furniture.find(h=>h.id===l)?.type;return!!(c&&l&&u&&r.has(u))&&this.grabItem(c,l,e,t)}if(n){let o=this.devices.find(l=>l.id===n)?.furnitureId,a=o?this.floors.find(l=>l.floor.furniture.some(c=>c.id===o)):void 0;return!o||!a?this.grabDevice(n,e,t):this.grabItem(a,o,e,t)}let s=this.furnitureAt(e,t);if(!s){let o=this.pick(e,t);return o&&"entity"in o?this.grabDevice(o.entity,e,t):(this.selectedFurniture&&(this.selectFurniture(null),this.options.onFurnitureSelect?.(null)),this.selectedDevice&&(this.selectDevice(null),this.options.onDeviceSelect?.(null)),!1)}return this.grabItem(s.fv,s.id,e,t)}grabItem(e,t,n,r){let s=e.floor.furniture.find(a=>a.id===t),o=this.floorPoint(e,n,r);return!s||!o?!1:s.locked?(this.selectFurniture(s.id),this.options.onFurnitureSelect?.(s.id),!1):(this.grab={floorId:e.floor.id,id:s.id,offset:[s.x-o[0],s.z-o[1]],x:s.x,z:s.z,moved:!1},this.selectFurniture(s.id),this.options.onFurnitureSelect?.(s.id),!0)}grabDevice(e,t,n){let r=this.devices.find(a=>a.id===e),s=r&&this.floorMap.get(r.floorId),o=s&&this.floorPoint(s,t,n);return!r||!s||!o?!1:r.fixed?(this.selectDevice(e),this.options.onDeviceSelect?.(e),!1):(this.deviceGrab={id:e,floorId:s.floor.id,offset:[r.x-o[0],r.z-o[1]],x:r.x,z:r.z,moved:!1},this.selectDevice(e),this.options.onDeviceSelect?.(e),!0)}setSelectedDevice(e){e!==this.selectedDevice&&this.selectDevice(e)}selectDevice(e){e&&this.selectedFurniture&&(this.selectFurniture(null),this.options.onFurnitureSelect?.(null)),this.selectedDevice=e;for(let[t,n]of this.devicePins)n.el.classList.toggle("nf-dev-sel",t===e)}dragFurniture(e,t){if(this.surfaceDragging){this.surfaceGrab?.move(this.surfaceRay(e,t));return}let n=this.deviceGrab;if(n){let l=this.floorMap.get(n.floorId),c=this.devices.find(f=>f.id===n.id),u=l&&this.floorPoint(l,e,t);if(!l||!c||!u)return;let h=this.building?.settings.grid??.05;n.x=c.x=Math.round((u[0]+n.offset[0])/h)*h,n.z=c.z=Math.round((u[1]+n.offset[1])/h)*h,n.moved=!0,this.labelsDirty=!0,this.invalidate();return}let r=this.grab,s=r&&this.floorMap.get(r.floorId);if(!r||!s)return;let o=this.floorPoint(s,e,t);if(!o)return;let a=this.building?.settings.grid??.05;r.x=Math.round((o[0]+r.offset[0])/a)*a,r.z=Math.round((o[1]+r.offset[1])/a)*a,r.moved=!0,this.updateGhost(),this.invalidate()}dropFurniture(){if(this.surfaceDragging){this.surfaceDragging=!1,this.surfaceGrab?.end();return}let e=this.deviceGrab;this.deviceGrab=null,e?.moved&&this.options.onDeviceMove?.(e.id,Math.round(e.x*1e3)/1e3,Math.round(e.z*1e3)/1e3);let t=this.grab;this.grab=null,t?.moved&&this.options.onFurnitureMove?.(t.id,Math.round(t.x*1e3)/1e3,Math.round(t.z*1e3)/1e3),this.updateGhost()}updateGhost(){this.ghost&&(this.ghost.geometry.dispose(),this.ghost.material.dispose(),this.scene.remove(this.ghost),this.ghost=null);let e=this.selectedFurniture,t=e?this.floors.find(m=>m.floor.furniture.some(b=>b.id===e)):void 0,n=t?.floor.furniture.find(m=>m.id===e);if(!t||!n)return;let r=this.grab?.id===n.id?this.grab.x:n.x,s=this.grab?.id===n.id?this.grab.z:n.z,o=Ol(t.floor,{...n,x:r,z:s}),a=y0.has(n.type),l=Math.max(.1,n.type==="lamp_pendant"?.3:n.h),c=vt(n.type)||n.type==="lamp_wall"||n.type==="led_strip"?Gt(t.floor,n):a?n.type==="lamp_pendant"||n.type==="ceiling_fan"?o-n.h-.1:o-l:Gt(t.floor,n),u=n.rotation*pt,h=Math.cos(u),f=Math.sin(u),d=(m,b,v)=>[r+m*h-b*f,v,s+m*f+b*h],p=new Wt,x=[[-n.w/2,-n.d/2],[n.w/2,-n.d/2],[n.w/2,n.d/2],[-n.w/2,n.d/2]],g=new W(.25,.9,1);for(let m=0;m<4;m++){let[b,v]=x[m],[y,M]=x[(m+1)%4];p.seg(d(b,v,c+.01),d(y,M,c+.01),g),p.seg(d(b,v,c+l),d(y,M,c+l),g),p.seg(d(b,v,c+.01),d(b,v,c+l),g)}p.seg(d(-n.w/2,n.d/2+.03,c+.02),d(n.w/2,n.d/2+.03,c+.02),new W(1,1,1)),this.ghost=new gn(p.geometry(),new Lt({vertexColors:!0,depthTest:!1,transparent:!0})),this.ghost.position.y=t.floor.elevation+t.y,this.ghost.renderOrder=20,this.scene.add(this.ghost)}onHold(e,t){let n=this.pick(e,t);n&&"entity"in n&&this.options.onDeviceHold?.(n.entity,e,t)}swipeStart(e,t,n,r){if(this.furnish||Math.abs(r)m.floor.rooms.some(b=>b.points.length>=3));if(!n.length)return[];let r=this.lowQuality?1:Math.min(2,window.devicePixelRatio||1),s=Math.round(e*r),o=Math.round(t*r),a=new wn(s,o);a.texture.colorSpace=ft;let l=new zn(-1,1,1,-1,.1,400),c=this.floors.map(m=>({fv:m,visible:m.group.visible,y:m.y,o:m.o,standing:m.mask.standing.value,glass:m.mask.glass.value})),u=this.roof?.group.visible??!1,h=this.ghost?.visible??!1,f=this.renderer.getClearAlpha(),d=new Uint8Array(s*o*4),p=document.createElement("canvas");p.width=s,p.height=o;let x=p.getContext("2d"),g=[];try{this.roof&&(this.roof.group.visible=!1),this.ghost&&(this.ghost.visible=!1),this.renderer.setClearAlpha(0);for(let m of n){for(let D of this.floors)D.group.visible=D===m;m.y=0,m.o=1,this.applyFloor(m),m.group.visible=!0,m.mask.standing.value=0,m.mask.glass.value=0;let b=m.floor.rooms.flatMap(D=>D.points),v=m.floor.elevation,y=new Ct(new U(Math.min(...b.map(D=>D[0]))-.3,v,Math.min(...b.map(D=>D[1]))-.3),new U(Math.max(...b.map(D=>D[0]))+.3,v+Math.min(m.floor.cut_height,m.floor.height),Math.max(...b.map(D=>D[1]))+.3)),M=y.getCenter(new U),S=-.6,_=.8,w=new U(Math.sin(_)*Math.sin(S),Math.cos(_),Math.sin(_)*Math.cos(S));l.position.copy(M).addScaledVector(w,100),l.lookAt(M),l.updateMatrixWorld();let R=.5,A=.5;for(let D of[y.min.x,y.max.x])for(let P of[y.min.y,y.max.y])for(let I of[y.min.z,y.max.z]){let N=new U(D,P,I).applyMatrix4(l.matrixWorldInverse);R=Math.max(R,Math.abs(N.x)),A=Math.max(A,Math.abs(N.y))}let C=s/o;R/A>C?A=R/C:R=A*C,l.left=-R*1.05,l.right=R*1.05,l.top=A*1.05,l.bottom=-A*1.05,l.updateProjectionMatrix(),this.renderer.setRenderTarget(a),this.renderer.clear(),this.renderer.render(this.scene,l),this.renderer.readRenderTargetPixels(a,0,0,s,o,d);let O=x.createImageData(s,o);for(let D=0;D{Math.hypot(u[0]-r.motion.pos[0],u[1]-r.motion.pos[1])o.length?`${o.length}:${o[0].map(a=>a.toFixed(2))}/${o[o.length-1].map(a=>a.toFixed(2))}`:"").join("|"),r=this.robotTrails.get(e.id);if(r&&r.userData.key===n){this.showRobotTrail(e);return}let s=r;if(!s){let o=new Ke({color:3590399,transparent:!0,opacity:.34,depthWrite:!1,side:ut});s=new we(Im([],.16,0),o),s.renderOrder=3,s.name=`robot-trail:${e.id}`,this.robotTrails.set(e.id,s);let a=this.robots.get(e.id)?.group.parent;a&&a.add(s)}s.geometry.dispose(),s.geometry=Im(t,.16,(e.y??0)+.012),s.userData.key=n,this.showRobotTrail(e)}showRobotTrail(e){let t=this.robotTrails.get(e.id);if(!t)return;let n=this.trailTimers.get(e.id);n!==void 0&&(clearTimeout(n),this.trailTimers.delete(e.id));let r=Date.now(),s=EM(e.settledAt,r);if(t.material.opacity=.34*s,t.visible=(e.track?.length??0)>0&&s>.01,s<=0||s>=1&&e.settledAt==null)return;let o=s>=1?Math.max(0,(e.settledAt??r)+Uh-r):250;this.trailTimers.set(e.id,setTimeout(()=>{this.showRobotTrail(e),this.invalidate()},o))}makeRobot(e){if(!this.robotGeo){let s=new lt,o=(l,c,u,h,f)=>{let d=[];for(let p=0;p<20;p++)d.push([Math.cos(p/20*Math.PI*2)*l,Math.sin(p/20*Math.PI*2)*l]);Tt(s,d,c,u,h,f,{aoFrom:0,bottom:!1})};o(.17,.012,.08,2371657,3424863),o(.055,.08,.1,3820138,5070726),this.robotGeo=s.geometry(),this.robotMat=new Ke({vertexColors:!0});let a=new lt;Tt(a,[[-.05,.1],[.05,.1],[.05,.14],[-.05,.14]],.08,.085,16777215,16777215,{aoFrom:0,bottom:!1}),this.robotLedGeo=a.geometry()}let t=new ct,n=new Ke({color:HM[e.mode]}),r=e.mower?this.mowerMat??=new Ke({color:4164170}):this.robotMat;return t.add(new we(this.robotGeo,r),new we(this.robotLedGeo,n)),e.mower&&t.scale.set(1.7,1.6,1.7),{info:e,motion:{pos:[...e.rest],heading:e.restHeading,path:[],next:0},group:t,led:n}}buildPets(){let e=new Map(this.pets);this.pets.clear(),this.petMat??=new Ke({vertexColors:!0});for(let t of this.floors)for(let n of t.floor.furniture){let r=vt(n.type);if(!r?.pet)continue;let s=t.floor.rooms.find(f=>f.points.length>=3&&Ve([n.x,n.z],f.points)),o=e.get(n.id),a=new lt;Ms(new Li(a,new Wt,Ss({x:0,z:0,rotation:0,mirror:n.mirror})),r,Math.max(.05,n.w),Math.max(.05,n.d),Math.max(.05,n.h),0,null,null,n.variant??null),o?.group.removeFromParent();let l=new ct;l.add(new we(a.geometry(),this.petMat));let c=s?t.floor.furniture.filter(f=>f.id!==n.id&&!vt(f.type)?.pet&&f.type!=="rug"&&Gt(t.floor,f)<.5&&Ve([f.x,f.z],s.points)).map(f=>ts(f)):[],u={points:s?.points??[[n.x-.5,n.z-.5],[n.x+.5,n.z-.5],[n.x+.5,n.z+.5],[n.x-.5,n.z+.5]],obstacles:c,speed:n.type.endsWith(":pet_dog")?.7:.45},h=o&&s&&Ve(o.motion.pos,s.points)?o.motion:{pos:[n.x,n.z],heading:n.rotation*Math.PI/180,target:null,rest:1};this.pets.set(n.id,{motion:h,room:u,random:mb(n.id),group:l,floorId:t.floor.id})}for(let[t,n]of e)this.pets.has(t)||n.group.removeFromParent()}setPetRooms(e){for(let[t,n]of this.pets){let r=this.floorMap.get(n.floorId),s=e.get(t);if(!r||s===void 0)continue;let o=s?r.floor.rooms.find(l=>l.id===s&&l.points.length>=3):void 0;if(!o||n.room.points===o.points)continue;let a=r.floor.furniture.filter(l=>!vt(l.type)?.pet&&l.type!=="rug"&&Gt(r.floor,l)<.5&&Ve([l.x,l.z],o.points)).map(l=>ts(l));n.room={...n.room,points:o.points,obstacles:a},Ve(n.motion.pos,o.points)||(n.motion={...n.motion,pos:Bs(o.points),target:null,rest:.5})}this.invalidate()}stepRobots(e){if(!this.robots.size&&!this.pets.size)return!1;let t=this.robotLast?Math.min(.2,(e-this.robotLast)/1e3):0;this.robotLast=e;let n=!1,r=1/0,s=this.petLast?(e-this.petLast)/1e3:0;this.petLast=e;for(let o of this.pets.values()){let a=this.floorMap.get(o.floorId);if(!a)continue;o.group.parent!==a.group&&a.group.add(o.group),gb(o.motion,o.room,s,o.random)||!!o.motion.target?n=!0:r=Math.min(r,Math.max(0,o.motion.rest)),o.group.position.set(o.motion.pos[0],0,o.motion.pos[1]),o.group.rotation.y=o.motion.heading}clearTimeout(this.petTimer),!n&&Number.isFinite(r)&&(this.petTimer=setTimeout(()=>this.invalidate(),r*1e3+50));for(let o of this.robots.values()){let a=this.floorMap.get(o.info.floorId);if(!a)continue;o.group.parent!==a.group&&a.group.add(o.group);let l=this.robotTrails.get(o.info.id);l&&l.parent!==a.group&&a.group.add(l),t>0?n=AM(o.motion,o.info,t)||n:n||=o.info.mode==="cleaning"||o.info.mode==="returning",o.group.position.set(o.motion.pos[0],o.info.y??0,o.motion.pos[1]),o.group.rotation.y=o.motion.heading}return n||(this.robotLast=0),n}getView(){return{...this.controls.view,target:this.controls.view.target.clone()}}showView(e,t=900){let n=e.target??{x:0,y:0,z:0};this.controls.maxRadius=Math.max(this.controls.maxRadius,e.radius*1.5),this.controls.flyTo({target:new U(n.x,n.y,n.z),radius:e.radius,phi:e.phi,theta:e.theta},t)}flyTo(e,t=900){this.controls.flyTo(e,t)}focus(e,t,n,r,s){let o=this.floorMap.get(e);if(o){if(this.controls.flyTo({target:new U(t,o.floor.elevation+o.ty+r,n),radius:5.5,phi:.78},900),s){this.flashes.set(s,performance.now()+2400);let a=this.host.querySelector(`.nf-dev[data-entity="${CSS.escape(s)}"]`);a?.classList.add("nf-dev-found"),setTimeout(()=>a?.classList.remove("nf-dev-found"),2600)}this.invalidate()}}render(e){if(this.frame=0,this.disposed)return;let t=this.lastFrame?Math.min(100,e-this.lastFrame):16,n=!1;this.orbitSpeed&&!this.controls.active?(this.orbitLast&&(this.controls.view.theta+=this.orbitSpeed*Math.min(100,e-this.orbitLast)/1e3),this.orbitLast=e,n=!0):this.orbitLast=0;let r=this.controls.update(e),s=this.stepFloors(t),a=[this.stepOpenings(t),this.stepFridges(t),this.stepCovers(t)].some(Boolean),l=!1;if(this.flashes.size){let g=new Set;for(let[m,b]of this.flashes){let v=this.deviceFloor.get(m);v&&g.add(v),b<=e&&this.flashes.delete(m)}l=this.flashes.size>0;for(let m of this.floors)g.has(m.floor.id)&&this.buildLamps(m)}let c=this.placeRoof(t),u=this.stepRobots(e);this.pictureLayer.step();let f=[this.weatherLayer,this.energyLayer,this.soundLayer,this.screenLayer,this.waterLayer].map(g=>g.step(e)).some(Boolean),d=r||s||a||l||c,p=[];if(r&&p.push("camera"),s&&p.push("floors"),a&&p.push("openings"),l&&p.push("flash"),c&&p.push("roof"),this.effectTick&&p.push("effect"),u&&p.push("robot"),n&&p.push("orbit"),this.tintTick&&p.push("tint"),this.effectTick=this.tintTick=!1,this.lastFrame=d?e:0,d&&this.governor){let g=this.governor.frame(t,e);g&&"ratio"in g?(this.renderer.setPixelRatio(g.ratio),this.resize()):g&&setTimeout(()=>this.dropToLow(),0)}this.updateWalls(),this.renderer.render(this.scene,this.camera),this.placeLhAnchors(),(this.viewChanged()||s||this.labelsDirty)&&(this.labelsDirty=!1,this.updateLabels()),this.reportStats(e,p),d&&this.invalidate(),this.scheduleEffects(),!d&&n&&!this.orbitTimer&&(this.orbitTimer=setTimeout(()=>{this.orbitTimer=void 0,this.invalidate()},this.lowQuality?66:33));let x=this.resting;!d&&f&&!this.weatherTimer&&!x&&(this.weatherTimer=setTimeout(()=>{this.weatherTimer=void 0,this.invalidate()},33)),!d&&u&&!this.robotTimer&&!x&&(this.robotTimer=setTimeout(()=>{this.robotTimer=void 0,this.invalidate()},this.lowQuality?66:33))}updateWalls(){if(this.controls.walk){for(let o of this.floors)o.mask.standing.value=65535,o.mask.glass.value=0,o.mask.slope?.value.set(0,0,0,0);return}let e=this.camera.position,t=this.controls.view.target,n=e.x-t.x,r=e.z-t.z,s=Math.hypot(n,r)||1;for(let o of this.floors){let a=this.roomId!==null&&o.floor.rooms.some(h=>h.id===this.roomId),l=this.wallMode==="cut",c=0,u=0;o.geo.buckets.forEach((h,f)=>{let d=h?h[0]*n/s+h[1]*r/s>=.25:a;this.wallMode!=="auto"||!d||(this.painted?a&&(u|=1<.5&&r)){this.labelPlacer.place(n.label,null);continue}let s=n.floor.elevation+n.y+n.floor.cut_height*.5,o=[r.x0,r.x1].flatMap(l=>[r.z0,r.z1].map(c=>this.screenPoint([l,s,c],1/0)));n.label.hidden&&(n.label.hidden=!1),n.labelSize??={w:n.label.offsetWidth,h:n.label.offsetHeight};let a=kb(o,n.labelSize.w,{width:this.size.w,inset:this.labelInset});t.push({fv:n,rank:n.rank,left:a.left,y:a.y,height:n.labelSize.h})}for(let n of Bb(t))this.labelPlacer.place(n.fv.label,Ub(n.left,n.y));this.updateDevicePins();for(let n of this.floors){let r=n.to<.99||n.o<.9||e||this.roomId!==null||this.otherFloor(n),s=n.floor.elevation+n.y+.05;for(let a of n.roomPins){let l=r?null:this.screenPoint([a.cx,s,a.cz],1.1);this.labelPlacer.place(a.pin,l&&!l.off?hl(l):null)}let o=e||n.o<.9||this.otherFloor(n);for(let{pin:a,note:l}of n.notePins){let c=o?null:this.screenPoint([l.x,n.floor.elevation+n.y+(l.y??f0),l.z]);this.labelPlacer.place(a,c&&!c.off?hl(c):null)}}}otherFloor(e){return this.floorId!==null&&e.floor.id!==this.floorId}updateDevicePins(){let e=this.houseView;for(let t of this.persons){let n=this.personPins.get(t.id),r=this.floorMap.get(t.floorId);if(!n)continue;let s=r&&!e&&jd(r,this.otherFloor(r))?this.screenPoint([t.x,r.floor.elevation+r.y+.9,t.z]):null;this.labelPlacer.place(n,s&&!s.off?hl(s):null)}for(let t of this.devices){let n=this.devicePins.get(t.id)?.el;if(!n)continue;let r=this.floorMap.get(t.floorId),s=t.id.startsWith("detect:"),o=!!t.full&&t.roomId===null,a=!!r&&(o?zb(r):(!e||s)&&jd(r,this.otherFloor(r))),c=!!r&&a&&t.pin!==!1?this.screenPoint([t.x,r.floor.elevation+r.y+t.y,t.z]):null;if(!c||c.off){this.labelPlacer.place(n,null);continue}let u=this.roomId===null?t.full?"full":"":t.roomId===this.roomId?"full":"dim";this.pinMode.get(n)!==u&&(this.pinMode.set(n,u),n.classList.toggle("nf-dev-full",u==="full"),n.classList.toggle("nf-dev-dim",u==="dim")),this.labelPlacer.place(n,hl(c))}}reportStats(e,t){if(!this.statsOn||!this.options.onStats)return;let n=t.length>0;this.fpsStart||(this.fpsStart=e),this.lastStatsFrame&&n&&(this.worstFrame=Math.max(this.worstFrame,e-this.lastStatsFrame)),this.lastStatsFrame=n?e:0,this.fpsFrames++;let r=e-this.fpsStart;if(r>500||!n){let s=this.renderer.info.render;this.options.onStats({fps:n?Math.round(this.fpsFrames*1e3/r):0,busy:t,worstMs:Math.round(this.worstFrame),calls:s.calls,triangles:s.triangles,low:this.lowQuality,pixelRatio:this.renderer.getPixelRatio()}),this.fpsFrames=0,this.fpsStart=e,this.worstFrame=0}}};function EP(){let e=document.createElement("canvas");e.width=256*3,e.height=256*2;let t=e.getContext("2d"),n=(o,a,l,c,u)=>{t.strokeStyle=`rgba(55,224,255,${u})`,t.beginPath(),t.moveTo(o,a),t.lineTo(l,c),t.stroke()};t.lineWidth=1.5;let r=(o,a,l)=>{t.save(),t.beginPath(),t.rect(o*256,a*256,256,256),t.clip(),l(o*256,a*256),t.restore()};r(0,0,(o,a)=>{for(let l=0;l<5;l++){let c=a+l*256/5+.75;n(o,c,o+256,c,.09);let u=o+l*.37%1*256;n(u,c,u,c+256/5,.07)}}),r(1,0,(o,a)=>{for(let l=0;l<7;l++){let c=o+l*256/7+.75;n(c,a,c,a+256,.08);let u=a+l*.53%1*256;n(c,u,c+256/7,u,.06)}}),r(2,0,(o,a)=>{for(let l=0;l<4;l++){let c=l*256/4+.75;n(o+c,a,o+c,a+256,.1),n(o,a+c,o+256,a+c,.1)}}),r(1,1,(o,a)=>{for(let l=0;l<2;l++){let c=a+l*256/2+.75;n(o,c,o+256,c,.09);let u=l?256/4:0;for(let h of[u,u+256/2])n(o+h+.75,c,o+h+.75,c+256/2,.09)}}),r(2,1,(o,a)=>{n(o+.75,a,o+.75,a+256,.08),n(o,a+.75,o+256,a+.75,.08),t.fillStyle="rgba(55,224,255,0.05)";for(let l=0;l<90;l++)t.fillRect(o+l*97%256,a+(l*61+l*l%37)%256,2,2)});let s=new zt(e);return s.flipY=!1,s.wrapS=ln,s.wrapT=ln,s.anisotropy=4,s.colorSpace=ft,s}function RP(){let i=document.createElement("canvas");i.width=8,i.height=32;let e=i.getContext("2d");e.fillStyle="#1a2742",e.fillRect(0,0,8,32),e.fillStyle="#223556",e.fillRect(0,4,8,14),e.fillStyle="rgba(55,224,255,0.45)",e.fillRect(0,29,8,2);let t=new zt(i);return t.wrapS=kn,t.wrapT=kn,t.colorSpace=ft,t}function CP(i,e){let t=i.rooms.map((r,s)=>s),n=r=>t[r]===r?r:t[r]=n(t[r]);for(let[r,s]of e){let o=i.rooms.findIndex(u=>u.id===r),a=i.rooms.findIndex(u=>u.id===s);if(o<0||a<0)continue;let l=n(o),c=n(a);l!==c&&(t[Math.max(l,c)]=Math.min(l,c))}return t.map((r,s)=>n(s))}function PP(){let e=document.createElement("canvas");e.width=64,e.height=64;let t=e.getContext("2d"),n=t.createRadialGradient(64/2,64/2,0,64/2,64/2,64/2);n.addColorStop(0,"rgba(255,255,255,0.9)"),n.addColorStop(.2,"rgba(255,255,255,0.45)"),n.addColorStop(.55,"rgba(255,255,255,0.1)"),n.addColorStop(1,"rgba(255,255,255,0)"),t.fillStyle=n,t.fillRect(0,0,64,64);let r=new zt(e);return r.colorSpace=ft,r}function IP(){let e=Qm,t=document.createElement("canvas");t.width=1024,t.height=1024;let n=t.getContext("2d");n.strokeStyle="rgba(91,124,255,0.16)",n.lineWidth=1;for(let o=0;o<=e;o++){let a=Math.round(o/e*1024)+.5;n.beginPath(),n.moveTo(a,0),n.lineTo(a,1024),n.moveTo(0,a),n.lineTo(1024,a),n.stroke()}n.globalCompositeOperation="destination-in";let r=n.createRadialGradient(1024/2,1024/2,1024*.12,1024/2,1024/2,1024/2);r.addColorStop(0,"rgba(0,0,0,1)"),r.addColorStop(1,"rgba(0,0,0,0)"),n.fillStyle=r,n.fillRect(0,0,1024,1024);let s=new zt(t);return s.anisotropy=4,s.colorSpace=ft,s}function w5(i,e){return new e0(i,e)}function Jm(i,e,t,n){let[r,s,o]=e.size??Es[e.lamp],a=e.base??0,l=(e.rotation??0)*pt,c=Math.cos(l),u=Math.sin(l),h=(x,g)=>[e.x+x*c-g*u,e.z+x*u+g*c],f=(x,g,m,b,v,y=14)=>{let M=[];for(let S=0;STt(i,[h(x,m),h(g,m),h(g,b),h(x,b)],v,y,M,S,{aoFrom:0,bottom:!0}),p=Math.max(.05,Math.min(r,s)/2);switch(e.lamp){case"ceiling":f(p*.25,t-.04,t,$e,$e,8),f(p,t-Math.max(.04,o)-.035,t-.04,n,n);break;case"pendant":{let x=Math.max(.4,t-o);f(.06,t-.02,t,$e,$e,8);let g=e.variant==="globe"?x+2*p:e.variant==="drum"?x+.24:x+.2;if(f(.008,g,t-.02,$e,$e,5),e.variant==="globe")for(let b=0;b<7;b++){let v=Math.PI*(b/7),y=Math.PI*((b+1)/7);f(p*Math.max(.2,Math.sin((v+y)/2)),x+p-p*Math.cos(v),x+p-p*Math.cos(y),n,n,14)}else if(e.variant==="cone")for(let b=0;b<4;b++)f(p*(.25+.75*(4-b)/4),x+.06*b,x+.06*(b+1),n,n,16);else e.variant==="drum"?f(p,x,x+.24,n,n,18):(f(p*.35,x+.14,x+.2,n,n,12),f(p,x,x+.14,n,n,16));break}case"fan":{let x=Math.max(.05,t-Math.max(.22,o)),g=x+.16;f(.07,t-.05,t,$e,$e,10),g[e.x+w*M-R*S,e.z+w*S+R*M];Tt(i,[_(.1,-.035),_(m,-.075),_(m,.075),_(.1,.035)],b,b+.012,WM,WM,{aoFrom:0,bottom:!0})}break}case"downlight":f(p,t-.012,t,$e,$e,12),f(p*.7,t-.02,t-.012,n,n,12);break;case"spot":f(p*.6,t-.02,t,$e,$e,10),f(p,t-Math.max(.06,o),t-.02,$e,$e,12),f(p*.8,t-Math.max(.06,o)-.008,t-Math.max(.06,o),n,n,12);break;case"panel":d(-r/2,r/2,-s/2,s/2,t-Math.max(.015,o),t,$e,$e),d(-r/2+.02,r/2-.02,-s/2+.02,s/2-.02,t-Math.max(.015,o)-.004,t-Math.max(.015,o),n);break;case"uplight":f(Math.max(.1,p*.6),a,a+.03,$e,$e),f(.014,a+.03,a+o-.12,$e,$e,6),f(p,a+o-.14,a+o-.02,$e,$e),f(p*.92,a+o-.02,a+o,n,n);break;case"bollard":f(p,a,a+o-.14,$e,$e,10),f(p*.9,a+o-.14,a+o-.03,n,n,10),f(p*1.1,a+o-.03,a+o,$e,$e,10);break;case"garden":f(.012,a,a+o-.08,$e,$e,5),f(p,a+o-.08,a+o-.01,$e,$e,10),f(p*.8,a+o-.01,a+o,n,n,10);break;case"floor":f(Math.max(.1,p*.7),a,a+.03,$e,$e),f(.014,a+.03,a+o-.28,$e,$e,6),f(p,a+o-.3,a+o,n,n);break;case"table":f(Math.max(.05,p*.55),a,a+.03,$e,$e),f(.012,a+.03,a+o-.16,$e,$e,6),f(p,a+o-.18,a+o,n,n);break;case"wall":{let x=e.base??Fl;d(-r/2+.03,r/2-.03,-s/2,-s/2+.02,x,x+o,$e),d(-r/2,r/2,-s/2+.02,s/2,x+o*.15,x+o*.85,n);break}case"strip":{let x=Math.max(.02,o),g=e.base!=null?e.base+x:t-.04,m=e.upright?0:(e.rise??0)*pt;if(!e.roll&&!e.upright&&!m){d(-r/2,r/2,-s/2,s/2,g-x,g,n);break}let b=(e.roll??0)*pt,v=Math.cos(b),y=Math.sin(b),[M,S]=[Math.cos(m),Math.sin(m)],_=e.upright?a+r/2:g-x/2+Io(e.base,r,e.rise),w=(D,P,I)=>{let N=D,F=P*v-I*y,H=P*y+I*v;return e.upright?[N,F]=[-F,N]:m&&([N,F]=[N*M-F*S,N*S+F*M]),[e.x+N*c-H*u,_+F,e.z+N*u+H*c]},R=[w(-r/2,-x/2,-s/2),w(r/2,-x/2,-s/2),w(r/2,-x/2,s/2),w(-r/2,-x/2,s/2),w(-r/2,x/2,-s/2),w(r/2,x/2,-s/2),w(r/2,x/2,s/2),w(-r/2,x/2,s/2)],A=new W(n),C=[e.x,_,e.z],O=(D,P,I,N)=>{let[F,H,B]=[R[D],R[P],R[I]],X=[(H[1]-F[1])*(B[2]-F[2])-(H[2]-F[2])*(B[1]-F[1]),(H[2]-F[2])*(B[0]-F[0])-(H[0]-F[0])*(B[2]-F[2]),(H[0]-F[0])*(B[1]-F[1])-(H[1]-F[1])*(B[0]-F[0])],V=[F[0]-C[0],F[1]-C[1],F[2]-C[2]],re=X[0]*V[0]+X[1]*V[1]+X[2]*V[2]<0,[be,Y,Q,se]=re?[R[N],R[I],R[P],R[D]]:[R[D],R[P],R[I],R[N]];i.tri(be,Y,Q,A,A,A),i.tri(be,Q,se,A,A,A)};O(0,1,2,3),O(4,5,6,7),O(0,1,5,4),O(1,2,6,5),O(2,3,7,6),O(3,0,4,7);break}}}export{Bi as ModelError,e0 as NextFloorViewer,w5 as createViewer,MP as furniturePreview,xP as inspectModel,xb as isLowEnd,bP as prepareModel,yP as previewModel,Jm as pushLampModel}; /*! Bundled license information: three/build/three.core.js: diff --git a/custom_components/nextfloor/frontend/nextfloor-editor.js b/custom_components/nextfloor/frontend/nextfloor-editor.js index 526a08c..56f51bd 100644 --- a/custom_components/nextfloor/frontend/nextfloor-editor.js +++ b/custom_components/nextfloor/frontend/nextfloor-editor.js @@ -1,7 +1,7 @@ /*! NextFloor, MIT licence. Includes three.js (MIT) and Lit (BSD-3-Clause); see LICENSE and THIRD_PARTY_NOTICES.md */ -var S={cs:"4be67fcd522e",da:"0fe66a82bf2a",es:"bd89dffd1355",fi:"9a17bc084f56",fr:"6312d0f61ebf",hu:"27ba348531dc",it:"1b705e76dd00",nb:"c5ea24fb9ef6",nl:"b64142c67c2e",pl:"8527a4930402",pt:"31857a2d2277",ro:"e3cb5f449f0f",sk:"320611594db0",sl:"8071691ceda3",sv:"711b911ec8da",tr:"7c83ce1c3372",zh:"50518d9f494e"};var bo=globalThis,yo=bo.ShadowRoot&&(bo.ShadyCSS===void 0||bo.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,qi=Symbol(),Ll=new WeakMap,lr=class{constructor(e,n,r){if(this._$cssResult$=!0,r!==qi)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=e,this.t=n}get styleSheet(){let e=this.o,n=this.t;if(yo&&e===void 0){let r=n!==void 0&&n.length===1;r&&(e=Ll.get(n)),e===void 0&&((this.o=e=new CSSStyleSheet).replaceSync(this.cssText),r&&Ll.set(n,e))}return e}toString(){return this.cssText}},Cl=t=>new lr(typeof t=="string"?t:t+"",void 0,qi),se=(t,...e)=>{let n=t.length===1?t[0]:e.reduce((r,o,i)=>r+(s=>{if(s._$cssResult$===!0)return s.cssText;if(typeof s=="number")return s;throw Error("Value passed to 'css' function must be a 'css' function result: "+s+". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.")})(o)+t[i+1],t[0]);return new lr(n,t,qi)},Nl=(t,e)=>{if(yo)t.adoptedStyleSheets=e.map(n=>n instanceof CSSStyleSheet?n:n.styleSheet);else for(let n of e){let r=document.createElement("style"),o=bo.litNonce;o!==void 0&&r.setAttribute("nonce",o),r.textContent=n.cssText,t.appendChild(r)}},Yi=yo?t=>t:t=>t instanceof CSSStyleSheet?(e=>{let n="";for(let r of e.cssRules)n+=r.cssText;return Cl(n)})(t):t;var{is:Xg,defineProperty:Qg,getOwnPropertyDescriptor:Jg,getOwnPropertyNames:e_,getOwnPropertySymbols:t_,getPrototypeOf:n_}=Object,wo=globalThis,Bl=wo.trustedTypes,r_=Bl?Bl.emptyScript:"",o_=wo.reactiveElementPolyfillSupport,cr=(t,e)=>t,Xi={toAttribute(t,e){switch(e){case Boolean:t=t?r_:null;break;case Object:case Array:t=t==null?t:JSON.stringify(t)}return t},fromAttribute(t,e){let n=t;switch(e){case Boolean:n=t!==null;break;case Number:n=t===null?null:Number(t);break;case Object:case Array:try{n=JSON.parse(t)}catch{n=null}}return n}},Vl=(t,e)=>!Xg(t,e),Wl={attribute:!0,type:String,converter:Xi,reflect:!1,useDefault:!1,hasChanged:Vl};Symbol.metadata??=Symbol("metadata"),wo.litPropertyMetadata??=new WeakMap;var ft=class extends HTMLElement{static addInitializer(e){this._$Ei(),(this.l??=[]).push(e)}static get observedAttributes(){return this.finalize(),this._$Eh&&[...this._$Eh.keys()]}static createProperty(e,n=Wl){if(n.state&&(n.attribute=!1),this._$Ei(),this.prototype.hasOwnProperty(e)&&((n=Object.create(n)).wrapped=!0),this.elementProperties.set(e,n),!n.noAccessor){let r=Symbol(),o=this.getPropertyDescriptor(e,r,n);o!==void 0&&Qg(this.prototype,e,o)}}static getPropertyDescriptor(e,n,r){let{get:o,set:i}=Jg(this.prototype,e)??{get(){return this[n]},set(s){this[n]=s}};return{get:o,set(s){let l=o?.call(this);i?.call(this,s),this.requestUpdate(e,l,r)},configurable:!0,enumerable:!0}}static getPropertyOptions(e){return this.elementProperties.get(e)??Wl}static _$Ei(){if(this.hasOwnProperty(cr("elementProperties")))return;let e=n_(this);e.finalize(),e.l!==void 0&&(this.l=[...e.l]),this.elementProperties=new Map(e.elementProperties)}static finalize(){if(this.hasOwnProperty(cr("finalized")))return;if(this.finalized=!0,this._$Ei(),this.hasOwnProperty(cr("properties"))){let n=this.properties,r=[...e_(n),...t_(n)];for(let o of r)this.createProperty(o,n[o])}let e=this[Symbol.metadata];if(e!==null){let n=litPropertyMetadata.get(e);if(n!==void 0)for(let[r,o]of n)this.elementProperties.set(r,o)}this._$Eh=new Map;for(let[n,r]of this.elementProperties){let o=this._$Eu(n,r);o!==void 0&&this._$Eh.set(o,n)}this.elementStyles=this.finalizeStyles(this.styles)}static finalizeStyles(e){let n=[];if(Array.isArray(e)){let r=new Set(e.flat(1/0).reverse());for(let o of r)n.unshift(Yi(o))}else e!==void 0&&n.push(Yi(e));return n}static _$Eu(e,n){let r=n.attribute;return r===!1?void 0:typeof r=="string"?r:typeof e=="string"?e.toLowerCase():void 0}constructor(){super(),this._$Ep=void 0,this.isUpdatePending=!1,this.hasUpdated=!1,this._$Em=null,this._$Ev()}_$Ev(){this._$ES=new Promise(e=>this.enableUpdating=e),this._$AL=new Map,this._$E_(),this.requestUpdate(),this.constructor.l?.forEach(e=>e(this))}addController(e){(this._$EO??=new Set).add(e),this.renderRoot!==void 0&&this.isConnected&&e.hostConnected?.()}removeController(e){this._$EO?.delete(e)}_$E_(){let e=new Map,n=this.constructor.elementProperties;for(let r of n.keys())this.hasOwnProperty(r)&&(e.set(r,this[r]),delete this[r]);e.size>0&&(this._$Ep=e)}createRenderRoot(){let e=this.shadowRoot??this.attachShadow(this.constructor.shadowRootOptions);return Nl(e,this.constructor.elementStyles),e}connectedCallback(){this.renderRoot??=this.createRenderRoot(),this.enableUpdating(!0),this._$EO?.forEach(e=>e.hostConnected?.())}enableUpdating(e){}disconnectedCallback(){this._$EO?.forEach(e=>e.hostDisconnected?.())}attributeChangedCallback(e,n,r){this._$AK(e,r)}_$ET(e,n){let r=this.constructor.elementProperties.get(e),o=this.constructor._$Eu(e,r);if(o!==void 0&&r.reflect===!0){let i=(r.converter?.toAttribute!==void 0?r.converter:Xi).toAttribute(n,r.type);this._$Em=e,i==null?this.removeAttribute(o):this.setAttribute(o,i),this._$Em=null}}_$AK(e,n){let r=this.constructor,o=r._$Eh.get(e);if(o!==void 0&&this._$Em!==o){let i=r.getPropertyOptions(o),s=typeof i.converter=="function"?{fromAttribute:i.converter}:i.converter?.fromAttribute!==void 0?i.converter:Xi;this._$Em=o;let l=s.fromAttribute(n,i.type);this[o]=l??this._$Ej?.get(o)??l,this._$Em=null}}requestUpdate(e,n,r,o=!1,i){if(e!==void 0){let s=this.constructor;if(o===!1&&(i=this[e]),r??=s.getPropertyOptions(e),!((r.hasChanged??Vl)(i,n)||r.useDefault&&r.reflect&&i===this._$Ej?.get(e)&&!this.hasAttribute(s._$Eu(e,r))))return;this.C(e,n,r)}this.isUpdatePending===!1&&(this._$ES=this._$EP())}C(e,n,{useDefault:r,reflect:o,wrapped:i},s){r&&!(this._$Ej??=new Map).has(e)&&(this._$Ej.set(e,s??n??this[e]),i!==!0||s!==void 0)||(this._$AL.has(e)||(this.hasUpdated||r||(n=void 0),this._$AL.set(e,n)),o===!0&&this._$Em!==e&&(this._$Eq??=new Set).add(e))}async _$EP(){this.isUpdatePending=!0;try{await this._$ES}catch(n){Promise.reject(n)}let e=this.scheduleUpdate();return e!=null&&await e,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){if(!this.isUpdatePending)return;if(!this.hasUpdated){if(this.renderRoot??=this.createRenderRoot(),this._$Ep){for(let[o,i]of this._$Ep)this[o]=i;this._$Ep=void 0}let r=this.constructor.elementProperties;if(r.size>0)for(let[o,i]of r){let{wrapped:s}=i,l=this[o];s!==!0||this._$AL.has(o)||l===void 0||this.C(o,void 0,i,l)}}let e=!1,n=this._$AL;try{e=this.shouldUpdate(n),e?(this.willUpdate(n),this._$EO?.forEach(r=>r.hostUpdate?.()),this.update(n)):this._$EM()}catch(r){throw e=!1,this._$EM(),r}e&&this._$AE(n)}willUpdate(e){}_$AE(e){this._$EO?.forEach(n=>n.hostUpdated?.()),this.hasUpdated||(this.hasUpdated=!0,this.firstUpdated(e)),this.updated(e)}_$EM(){this._$AL=new Map,this.isUpdatePending=!1}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$ES}shouldUpdate(e){return!0}update(e){this._$Eq&&=this._$Eq.forEach(n=>this._$ET(n,this[n])),this._$EM()}updated(e){}firstUpdated(e){}};ft.elementStyles=[],ft.shadowRootOptions={mode:"open"},ft[cr("elementProperties")]=new Map,ft[cr("finalized")]=new Map,o_?.({ReactiveElement:ft}),(wo.reactiveElementVersions??=[]).push("2.1.2");var Ji=globalThis,Kl=t=>t,vo=Ji.trustedTypes,Gl=vo?vo.createPolicy("lit-html",{createHTML:t=>t}):void 0,es="$lit$",mt=`lit$${Math.random().toFixed(9).slice(2)}$`,ts="?"+mt,i_=`<${ts}>`,jt=document,ur=()=>jt.createComment(""),hr=t=>t===null||typeof t!="object"&&typeof t!="function",ns=Array.isArray,Xl=t=>ns(t)||typeof t?.[Symbol.iterator]=="function",Qi=`[ -\f\r]`,dr=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,jl=/-->/g,Ul=/>/g,Kt=RegExp(`>|${Qi}(?:([^\\s"'>=/]+)(${Qi}*=${Qi}*(?:[^ -\f\r"'\`<>=]|("|')|))|$)`,"g"),Zl=/'/g,ql=/"/g,Ql=/^(?:script|style|textarea|title)$/i,rs=t=>(e,...n)=>({_$litType$:t,strings:e,values:n}),m=rs(1),R=rs(2),Ak=rs(3),Qe=Symbol.for("lit-noChange"),_=Symbol.for("lit-nothing"),Yl=new WeakMap,Gt=jt.createTreeWalker(jt,129);function Jl(t,e){if(!ns(t)||!t.hasOwnProperty("raw"))throw Error("invalid template strings array");return Gl!==void 0?Gl.createHTML(e):e}var ec=(t,e)=>{let n=t.length-1,r=[],o,i=e===2?"":e===3?"":"",s=dr;for(let l=0;l"?(s=o??dr,u=-1):d[1]===void 0?u=-2:(u=s.lastIndex-d[2].length,c=d[1],s=d[3]===void 0?Kt:d[3]==='"'?ql:Zl):s===ql||s===Zl?s=Kt:s===jl||s===Ul?s=dr:(s=Kt,o=void 0);let h=s===Kt&&t[l+1].startsWith("/>")?" ":"";i+=s===dr?a+i_:u>=0?(r.push(c),a.slice(0,u)+es+a.slice(u)+mt+h):a+mt+(u===-2?l:h)}return[Jl(t,i+(t[n]||"")+(e===2?"":e===3?"":"")),r]},pr=class t{constructor({strings:e,_$litType$:n},r){let o;this.parts=[];let i=0,s=0,l=e.length-1,a=this.parts,[c,d]=ec(e,n);if(this.el=t.createElement(c,r),Gt.currentNode=this.el.content,n===2||n===3){let u=this.el.content.firstChild;u.replaceWith(...u.childNodes)}for(;(o=Gt.nextNode())!==null&&a.length0){o.textContent=vo?vo.emptyScript:"";for(let h=0;h2||r[0]!==""||r[1]!==""?(this._$AH=Array(r.length-1).fill(new String),this.strings=r):this._$AH=_}_$AI(e,n=this,r,o){let i=this.strings,s=!1;if(i===void 0)e=Ut(this,e,n,0),s=!hr(e)||e!==this._$AH&&e!==Qe,s&&(this._$AH=e);else{let l=e,a,c;for(e=i[0],a=0;a{let r=n?.renderBefore??e,o=r._$litPart$;if(o===void 0){let i=n?.renderBefore??null;r._$litPart$=o=new bn(e.insertBefore(ur(),i),i,void 0,n??{})}return o._$AI(t),o};var os=globalThis,ne=class extends ft{constructor(){super(...arguments),this.renderOptions={host:this},this._$Do=void 0}createRenderRoot(){let e=super.createRenderRoot();return this.renderOptions.renderBefore??=e.firstChild,e}update(e){let n=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(e),this._$Do=nc(n,this.renderRoot,this.renderOptions)}connectedCallback(){super.connectedCallback(),this._$Do?.setConnected(!0)}disconnectedCallback(){super.disconnectedCallback(),this._$Do?.setConnected(!1)}render(){return Qe}};ne._$litElement$=!0,ne.finalized=!0,os.litElementHydrateSupport?.({LitElement:ne});var a_=os.litElementPolyfillSupport;a_?.({LitElement:ne});(os.litElementVersions??=[]).push("4.2.2");var Je=(t,e,n={})=>t.callWS({type:`nextfloor/${e}`,...n});async function Ro(t,e){return(await Je(t,"image/get",{image_id:e})).data}async function St(t,e,n){await Je(t,"image/set",{image_id:e,data:n})}async function rc(t){return(await Je(t,"history/list")).snapshots}async function oc(t,e){return(await Je(t,"history/snapshot",e?{name:e}:{})).id}async function ic(t,e){return(await Je(t,"history/get",{snapshot_id:e})).building}async function sc(t,e){await Je(t,"history/delete",{snapshot_id:e})}async function ac(t,e){return(await Je(t,"history/restore",{snapshot_id:e})).revision}var fr=(t,e)=>Je(t,"packs/import",{pack:e});async function lc(t,e){await Je(t,"packs/remove",{pack_id:e})}var cc=t=>Je(t,"backup/export"),dc=(t,e,n)=>Je(t,"backup/import",{building:e,packs:n});var ss=t=>t.slice(0,t.indexOf(".")),l_={light:"light",switch:"switch",input_boolean:"switch",valve:"switch",fan:"fan",cover:"cover",climate:"climate",media_player:"media",lock:"lock",sensor:"sensor",binary_sensor:"binary",event:"sensor",scene:"scene",script:"script"},X=t=>l_[ss(t)]??null,as=["light","cover","climate","media","switch","fan","lock","binary","sensor","scene","script"];var uc=new Set(["light","switch","fan"]),Mt=t=>t!==null&&t!=="scene"&&t!=="script",Rt=t=>!t||t.state==="unavailable"||t.state==="unknown"&&!t.entity_id.startsWith("event.");function W(t,e,n){let r=String(t?.states[e]?.attributes.friendly_name??t?.entities?.[e]?.name??e);if(!n||r.length<=n.length+1||!r.toLowerCase().startsWith(`${n.toLowerCase()} `))return r;let o=r.slice(n.length+1);return o[0].toUpperCase()+o.slice(1)}var hc=t=>!!t&&t.entity_id.startsWith("sensor.")&&t.attributes.device_class==="enum";var pc=t=>Math.min(1,Math.max(0,t));function c_(t){let e=pc((t-2200)/4300),n=[1,.66,.26],r=[.78,.9,1];return[0,1,2].map(o=>n[o]+(r[o]-n[o])*e)}function is(t,e){if(!t||t.state!=="on")return null;let n=e&&!["unavailable","unknown"].includes(e.state)?e.attributes:t.attributes,r=typeof n.brightness=="number"?.2+.8*Math.sqrt(pc(n.brightness/255)):1,o=n.rgb_color;return o&&!["color_temp","brightness","onoff"].includes(String(n.color_mode))?{color:[o[0]/255,o[1]/255,o[2]/255],level:r}:typeof n.color_temp_kelvin=="number"?{color:c_(n.color_temp_kelvin),level:r}:{color:[1,.71,.28],level:r}}function fc(t,e,n){let r=is(t,n);if(r)return r;for(let o of e){let i=is(o);if(i)return{color:i.color,level:i.level*.6}}return null}function Eo(t,e,n=null){if(t==="light"&&n==="floor")return 1.95;if(t==="light"&&n==="table")return 1.25;if(t==="light"&&n==="wall")return 1.95;switch(t){case"light":return Math.max(.5,e-.25);case"cover":return Math.min(2,e-.3);case"climate":return .6;case"media":return .9;case"binary":case"sensor":return 1.4;default:return 1.05}}var bc=[],Ao=new Map,d_=0,ue=(t,e)=>`pack:${t}:${e}`,gt=t=>t.startsWith("pack:");function ls(t){bc=t,Ao=new Map;for(let e of t)for(let n of e.items)Ao.set(ue(e.id,n.id),n);d_+=1}var gr=()=>bc;var u_={};function G(t){if(!gt(t))return;let e=Ao.get(t);if(e)return e;let[,n,...r]=t.split(":"),o=u_[n];return o?Ao.get(ue(o,r.join(":"))):void 0}var h_=.22;function mc(t,e,n,r){let o=Math.min(h_,n/3);if(r<=o*2.4||Math.abs(r-n)<1e-6)return e*(r/n)+(t-e)*(r/n);let i=e*(r/n),s=t-e;return s<=o?i+s:s>=n-o?i+r-(n-s):i+o+(s-o)*(r-2*o)/(n-2*o)}function mr(t,e,n,r,o){return[mc(t*r,n*r,r,o)/o,mc(e*r,n*r,r,o)/o]}var gc=new WeakMap;function yc(t,e,n,r){let[o,i,s]=t.size;if(t.vehicle||t.stretch||Math.abs(e-o)<1e-4&&Math.abs(n-i)<1e-4&&Math.abs(r-s)<1e-4)return t.parts;let l=`${e.toFixed(4)}|${n.toFixed(4)}|${r.toFixed(4)}`,a=gc.get(t),c=a?.get(l);if(c)return c;let d=t.parts.map(u=>{if(u.shape==="sweep")return u;let[p,h]=mr(u.x-u.w/2,u.x+u.w/2,-.5,o,e),[f,g]=mr(u.z-u.d/2,u.z+u.d/2,-.5,i,n),[y,b]=mr(u.y,u.y+u.h,0,s,r);if(u.rot)return{...u,x:(p+h)/2,z:(f+g)/2,w:u.w*o/e,d:u.d*i/n,y,h:b-y};let v={...u,x:(p+h)/2,z:(f+g)/2,w:h-p,d:g-f,y,h:b-y};if(u.shape==="loft"){let[w,x,k,$]=[u.tx??u.x,u.tz??u.z,u.tw??u.w,u.td??u.d],[A,F]=mr(w-k/2,w+k/2,-.5,o,e),[T,I]=mr(x-$/2,x+$/2,-.5,i,n);Object.assign(v,{tx:(A+F)/2,tz:(T+I)/2,tw:F-A,td:I-T})}return v});return a||gc.set(t,a=new Map),a.size>32&&a.clear(),a.set(l,d),d}var cs=t=>!!t?.parts.some(e=>e.move);var wc=t=>G(t)?.parts.find(e=>e.screen),_c=.06;function vc(t){let e=G(t);if(!e)return!1;let[n,r,o]=e.size;return e.parts.filter(i=>i.screen).some(i=>{let[s,l]=[i.w*n,i.d*r,i.h*o].sort((a,c)=>c-a);return l>=_c&&s>=_c})}function at(t){return et[t]??G(t)?.size??[.6,.6,.8]}function Et(t){let e=G(t);return Ac.has(t)||!!e?.electric||!!e?.light||!!e?.climate}var kc=t=>!!G(t)?.parts.some(e=>e.picture),yn=t=>!!G(t)?.climate;function xc(t,e){return t.name[e.split("-")[0]]??t.name.en??Object.values(t.name)[0]??t.id}var p_={wohnen:"Living & Pets",kino:"Home Cinema & Gaming",kueche:"Kitchen Extras",bad:"Bathroom Extras",schlafen:"Bedroom & Kids",technik:"Office & Homelab",energie:"Energy & Building Services",garten:"Garden & Terrace (older)",fitness:"Fitness (older)",fahrzeuge:"Vehicles",ikea:"IKEA sizes",treppen:"Stairs & railings",ausbau:"Architecture & fit-out",werkstatt:"Garage & workshop",a_wohnzimmer:"Living room",a_schlafzimmer:"Bedroom",a_kueche:"Kitchen",a_bad:"Bathroom",a_kinderzimmer:"Kids' room",a_buero:"Office & gaming",a_fitness:"Fitness",a_haustiere:"Pets",a_garten:"Garden & patio",a_kino:"Home cinema & hi-fi",a_smart:"Smart home & tech",a_haustechnik:"Utility & building services",a_saison:"Season & decoration",a_smart2:"Smart home 2",a_haustechnik2:"Building services 2",a_wellness:"Wellness",a_garten2:"Garden 2",a_kueche2:"Kitchen 2",a_fahrzeuge2:"Vehicles 2",a_aussenkueche:"Outdoor kitchen & terrace",a_werkstatt2:"Workshop 2",a_japandi:"Japandi & Scandi",a_loft:"Loft & industrial",a_gruen:"Indoor greenery",a_musik:"Music & studio",a_bilder:"Pictures & frames"};function $c(t,e){if(e.split("-")[0]==="de")return t.name;let n=/^nextfloor\.(.+)$/.exec(t.id)?.[1];return n&&p_[n]||t.name}function At(t,e){return e.mount_y!=null?e.mount_y:m_(t,e)+(f_(e)?0:Rc(t,e.x,e.z))}var f_=t=>t.type==="led_strip"||G(t.type)?.mount==="ceiling";function m_(t,e){if(e.type==="lamp_wall")return Sc;if(e.type==="led_strip")return Math.max(0,lt(t,e.x,e.z)-.04-Math.max(.02,e.h));let n=G(e.type);if(!n)return Mc(e);switch(n.mount){case"surface":return Ec(t,e.x,e.z);case"wall":return n.wall_y??1;case"ceiling":return Math.max(0,Fo(t,e)-e.h);default:return 0}}function ds(t){if(t==="plant")return"plant";let e=G(t);return e?e.household?e.household:/monstera|plant|herb_garden|flower_pots|bonsai|ficus|cactus|kaktus/.test(e.id)?"plant":null:null}var Fc=["turn","slide","top"],Tc=["always","active","no_power","never"],zc=1.3,To=(t,e=new Date().toISOString().slice(0,10))=>!!t.due&&t.due<=e,Pc=["gable","hip","halfhip","pyramid","mansard","pent","flat","parapet"],Ic=["brick","round","wide","steel"],zo=["navigate","more_info","service","fire_dom_event"];function Po(t,e,n){return t?e?!!n.lock_plan:!!t.locked:!1}var Dc=["rain","snow","fog","clouds","lightning","sky"],Oc=["rain","snow","clouds","lightning","sky"],Hc=["lawn","terrace","path","driveway","pool","bed","wild","hedge","fence","pergola"],us={lawn:.012,terrace:.12,path:.02,driveway:.02,pool:-.25,bed:.15,wild:.03,hedge:1.2,fence:1,pergola:2.2};function hs(t){return t==="hedge"||t==="fence"||t==="pergola"}var Lc=["x","-x","z","-z"];function g_(t,e,n){let r=t.slope??0;if(!r||t.type==="pool")return 0;let o=t.slope_dir??"x",i=(c,d)=>o==="x"?c:o==="-x"?-c:o==="z"?d:-d,s=1/0,l=-1/0;for(let[c,d]of t.points){let u=i(c,d);s=Math.min(s,u),l=Math.max(l,u)}if(l-s<1e-6)return 0;let a=Math.min(1,Math.max(0,(i(e,n)-s)/(l-s)));return r*a}function __(t,e,n,r){return Cc(t)+(e.offset??0)+us[e.type]-g_(e,n,r)}function Cc(t){return t.elevation>.3?0:-.2}function Nc(t,e,n){let r=(t.outdoor??[]).filter(i=>!hs(i.type)&&i.type!=="pool"&&N([e,n],i.points)),o=[...r].reverse().find(i=>i.cut)??r[0];return o?__(t,o,e,n):Cc(t)}var Bc=t=>t.cut??t.type==="pool",Wc=30,Vc={meter:null,grid:null,grid_invert:!1,solar:null,battery:null,battery_invert:!1,battery_soc:null,consumption:null,tariff:null},Kc=["wood","oak","tiles","carpet","stone","concrete"],Gc={type:"none",pitch:35,overhang:.4},Io="#d6cfc2",Do="#e8e3da",jc={wall_exterior:.24,wall_interior:.12,grid:.05,north:0,roof:{...Gc}};function Ft(){return{version:1,floors:[],settings:{...jc},energy:{...Vc},presence:[]}}function Le(t,e,n){return{id:t,name:e,elevation:n,height:2.5,cut_height:1.15,rooms:[],openings:[],furniture:[],placements:[],background:null,outdoor:[],walls:[],ha_floor:null}}var b_=2.75;function Uc(t,e){if(e!=null&&Number.isFinite(e))return Math.round(e*b_*100)/100;let n=t.reduce((r,o)=>!r||o.elevation>r.elevation?o:r,null);return n?Math.round((n.elevation+n.height+.25)*100)/100:0}function Zc(t,e,n){let r=t.rooms.flatMap(l=>l.points.map(a=>a[0])),o=t.rooms.flatMap(l=>l.points.map(a=>a[1])),i=r.length?Math.ceil(Math.max(...r))+1:0,s=o.length?Math.floor(Math.min(...o)):0;return e.map((l,a)=>{let c=i+a%3*4.5,d=s+Math.floor(a/3)*3.5;return{id:n(),name:l.name,area_id:l.area_id,points:[[c,d],[c+4,d],[c+4,d+3],[c,d+3]],floor_material:"wood"}})}function qc(t,e,n,r){let o=t.rotation*Math.PI/180,i=Math.cos(o),s=Math.sin(o),[l,a]=e,c=t.x-l*(t.w/2)*i+a*(t.d/2)*s,d=t.z-l*(t.w/2)*s-a*(t.d/2)*i,u=n[0]-c,p=n[1]-d,h=b=>Math.max(.1,Math.round(b/r)*r),f=h((u*i+p*s)*l),g=h((-u*s+p*i)*a),y=b=>Math.round(b*1e3)/1e3;return{x:y(c+l*(f/2)*i-a*(g/2)*s),z:y(d+l*(f/2)*s+a*(g/2)*i),w:y(f),d:y(g)}}var Oo=["lamp_ceiling","lamp_downlight","lamp_spot","lamp_panel","lamp_pendant","ceiling_fan","lamp_floor","lamp_table","lamp_wall","led_strip","lamp_uplight","lamp_bollard","lamp_garden","radiator","sofa","armchair","stool","coffee_table","tv_board","tv_wall","sideboard","shelf","plant","rug","table","table_round","chair","bench","corner_bench","bar_stool","kitchen","kitchen_wall","kitchen_tall","island","worktop","sink","stove","dishwasher","fridge","bed","bunk_bed","nightstand","wardrobe","dresser","bathtub","shower","wc","washbasin","washer","dryer","desk","office_chair","tall_cabinet","coat_rack","stairs","robot_vacuum","inverter","home_battery","wallbox","meter","grid_point","parking","fridge_smart","stairwell"],Yc={lights:["lamp_ceiling","lamp_downlight","lamp_spot","lamp_panel","lamp_pendant","ceiling_fan","lamp_floor","lamp_uplight","lamp_table","lamp_wall","led_strip","lamp_bollard","lamp_garden"],living:["sofa","armchair","stool","coffee_table","tv_board","tv_wall","sideboard","shelf","plant","rug"],dining:["table","table_round","chair","bench","corner_bench","bar_stool"],kitchen:["kitchen","kitchen_wall","kitchen_tall","island","worktop","sink","stove","dishwasher","fridge"],sleeping:["bed","bunk_bed","nightstand","wardrobe","dresser"],bath:["bathtub","shower","wc","washbasin","washer","dryer"],work:["desk","worktop","office_chair","tall_cabinet","coat_rack","radiator","stairs","robot_vacuum"],vehicles:["parking"]},Ce=["meter","inverter","home_battery","wallbox","grid_point"],Xc=new Set(["lamp_ceiling","lamp_downlight","lamp_spot","lamp_panel","lamp_pendant","ceiling_fan","lamp_floor","lamp_uplight","lamp_table","lamp_wall","led_strip","lamp_bollard","lamp_garden"]),Sc=1.75;function Ho(t){return ps.has(t.type)||["stairwell","parking"].includes(t.type)?!1:G(t.type)?.mount!=="ceiling"}function ce(t){return Xc.has(t)||!!G(t)?.light}var y_=new Set(["table","table_round","coffee_table","desk","nightstand","sideboard","dresser","kitchen","island","worktop","tv_board","dishwasher","washer","dryer"]);function Qc(t,e,n,r=0){let o=de(t.points),i=o.x1-o.x0-2*r,s=o.z1-o.z0-2*r,l=[];for(let a=0;aMath.round(s*1e3)/1e3,[o,i]={right:[1,0],down:[0,1],left:[-1,0],up:[0,-1]}[n];return[r(t[0]+o*e),r(t[1]+i*e)]}function Mc(t){switch(t.type){case"home_battery":return t.variant==="wall"?.5:0;case"kitchen_wall":return 1.45;case"tv_wall":return Math.max(0,1.3-t.h/2);case"radiator":return .12;case"inverter":return 1.1;case"wallbox":return 1;case"meter":return .4;default:return 0}}var ps=new Set(["lamp_ceiling","lamp_downlight","lamp_spot","lamp_panel","lamp_pendant","ceiling_fan"]);function Jc(t,e){return t.filter(n=>n.elevationn.rooms.filter(r=>r.points.length>=3&&r.ceiling!=null&&r.ceiling>n.height+.005&&n.elevation+r.ceiling>e.elevation+.05)).map(n=>n.points)}var fs=t=>t?.floor_offset&&Number.isFinite(t.floor_offset)?t.floor_offset:0;function Rc(t,e,n){let r=t.rooms.find(o=>o.points.length>=3&&o.floor_offset&&N([e,n],o.points));return fs(r)}function lt(t,e,n){let r=t.rooms.find(o=>o.points.length>=3&&N([e,n],o.points));return r?.ceiling!=null&&r.ceiling>0?r.ceiling:t.height}var Fo=(t,e)=>e.ceiling_y!=null&&e.ceiling_y>0?e.ceiling_y:lt(t,e.x,e.z);function Ec(t,e,n){let r=0;for(let o of t.furniture)!(y_.has(o.type)||G(o.type)?.surface)||!N([e,n],bs(o))||(r=Math.max(r,o.h));return r}var Ac=new Set([...Xc,"radiator","robot_vacuum","inverter","home_battery","wallbox","meter","tv_board","tv_wall","desk","fridge","fridge_smart","stove","kitchen_tall","dishwasher","washer","dryer","kitchen","island","sink"]),et={sofa:[2.2,.9,.82],armchair:[.85,.85,.8],table:[1.6,.9,.75],chair:[.46,.5,.9],bed:[1.6,2.05,.9],nightstand:[.45,.4,.5],wardrobe:[1.8,.6,2.1],shelf:[.9,.35,1.9],kitchen:[2.4,.62,.92],worktop:[1.2,.62,.91],inverter:[.5,.2,.65],home_battery:[.6,.25,1.1],wallbox:[.3,.15,.42],meter:[.55,.21,1.1],grid_point:[.4,.22,.6],fridge:[.6,.65,1.8],fridge_smart:[.91,.73,1.78],stairwell:[1,2.6,.02],stove:[.6,.62,.92],sink:[.9,.62,.92],bathtub:[1.7,.75,.58],shower:[.9,.9,2],wc:[.38,.6,.8],washbasin:[.6,.46,.85],desk:[1.4,.7,.75],tv_board:[1.8,.42,.5],plant:[.45,.45,1.1],rug:[2,1.4,.01],stairs:[1,3.2,2.75],stool:[.55,.55,.42],lamp_ceiling:[.4,.4,.08],lamp_downlight:[.1,.1,.02],lamp_spot:[.1,.1,.14],lamp_panel:[.6,.6,.03],lamp_uplight:[.35,.35,1.8],lamp_bollard:[.16,.16,.8],lamp_garden:[.12,.12,.3],radiator:[1,.1,.6],robot_vacuum:[.36,.5,.1],parking:[2.6,5.2,.02],lamp_pendant:[.4,.4,.8],ceiling_fan:[1.32,1.32,.32],lamp_floor:[.4,.4,1.7],lamp_table:[.28,.28,.45],lamp_wall:[.22,.12,.2],led_strip:[2,.04,.03],coffee_table:[1.1,.6,.42],tv_wall:[1.3,.08,.75],sideboard:[1.6,.45,.8],table_round:[1.1,1.1,.75],bench:[1.4,.45,.85],corner_bench:[2,1.6,.9],bar_stool:[.42,.42,.75],kitchen_wall:[.8,.35,.7],kitchen_tall:[.6,.62,2.1],island:[1.8,.9,.92],dishwasher:[.6,.62,.92],bunk_bed:[1,2.05,1.65],dresser:[1,.5,.9],washer:[.6,.6,.85],dryer:[.6,.6,.85],office_chair:[.65,.65,1.1],tall_cabinet:[.6,.6,2.1],coat_rack:[1,.35,1.9]};var ms=["interior","front","front_glass","sidelight","sidelights","glass","sliding","passage"],gs=["standard","bars","glass_wall"],Lo=new Set(["interior","front"]);function qt(t,e){return t.type==="door"?t.style&&ms.includes(t.style)?t.style:e?"front":"interior":t.style&&gs.includes(t.style)?t.style:"standard"}function ed(t,e,n,r){if(e!=="sidelight"&&e!=="sidelights")return null;let o=e==="sidelights",i=t-.04,s=Math.min(1.05,Math.max(.6,i-(o?.6:.3))),l=(i-s)/(o?2:1),a=r.sidelight_width??l,c=o?r.sidelight_width2??r.sidelight_width??l:0;a=Math.max(.1,a),c=o?Math.max(.1,c):0;let d=i-.5;if(a+c>d){let p=Math.max(0,d)/(a+c);a*=p,c*=p}return o?{panels:[[.02,.02+a],[t-.02-c,t-.02]],x0:.02+a,x1:t-.02-c}:(n?!!r.sidelight_hinge:!r.sidelight_hinge)?{panels:[[.02,.02+a]],x0:.02+a,x1:t-.02}:{panels:[[t-.02-a,t-.02]],x0:.02,x1:t-.02-a}}function _s(t){return t==="front"||t==="front_glass"||t==="sidelight"||t==="sidelights"}var vn={door:{type:"door",leaves:1,width:.9,sill:0,height:2.05,style:"interior"},front:{type:"door",leaves:1,width:1,sill:0,height:2.1,style:"front"},door_double:{type:"door",leaves:2,width:1.6,sill:0,height:2.05},window:{type:"window",leaves:1,width:1.2,sill:.9,height:1.3},window_double:{type:"window",leaves:2,width:1.6,sill:.9,height:1.3},terrace:{type:"window",leaves:1,width:1,sill:0,height:2.1},terrace_double:{type:"window",leaves:2,width:1.8,sill:0,height:2.1},lift_slide:{type:"window",leaves:1,width:2.4,sill:0,height:2.15,opens:"slide"},garage:{type:"garage",leaves:1,width:2.5,sill:0,height:2.1},glass_wall:{type:"window",leaves:1,width:2,sill:0,height:2.4,style:"glass_wall"}};function kn(t){if(t.type==="garage")return"garage";if(t.type==="window"&&t.style==="glass_wall")return"glass_wall";if(t.type==="window"&&t.opens==="slide"&&t.sill<.1)return"lift_slide";let e=t.leaves===2;return t.type==="door"?!e&&t.style&&_s(t.style)?"front":e?"door_double":"door":t.sill<.1?e?"terrace_double":"terrace":e?"window_double":"window"}function ze(t){t.energy={...Vc,...t.energy??{}},t.presence=t.presence??[],t.version=1,t.settings={...jc,...t.settings,roof:{...Gc,...t.settings?.roof??{}}},t.floors.forEach((e,n)=>{let r=Le(e.id,e.name??`Floor ${n+1}`,e.elevation??n*2.8);for(let o of Object.keys(r))e[o]===void 0&&(e[o]=r[o])});for(let e of t.floors){e.outdoor=e.outdoor??[],e.walls=e.walls??[],e.rooms=e.rooms.map(r=>({...r,name:r.name??"",area_id:r.area_id??null,floor_material:r.floor_material??"wood",panel:r.panel??[]})),e.ha_floor=e.ha_floor??null,e.placements=e.placements.map(r=>({...r,mount:r.mount??null,rotation:r.rotation??0})),e.furniture=e.furniture.map(r=>({...r,entity:r.entity??null,power:r.power??null}));let n=e.placements.filter(r=>r.entity_id.startsWith("light."));if(n.length){let r={ceiling:"lamp_ceiling",floor:"lamp_floor",table:"lamp_table",wall:"lamp_wall"};for(let o of n){let i=r[o.mount??"ceiling"],[s,l,a]=et[i],c=`lamp_${o.entity_id.slice(6).replace(/[^A-Za-z0-9_\-.]/g,"_")}`.slice(0,54),d=c,u=1;for(;e.furniture.some(p=>p.id===d);)d=`${c}_${u++}`;e.furniture.push({id:d,type:i,x:o.x,z:o.z,rotation:0,w:s,d:l,h:a,variant:null,entity:o.entity_id,power:null,animations_enabled:o.animations_enabled,effect_animations:structuredClone(o.effect_animations)})}e.placements=e.placements.filter(o=>!o.entity_id.startsWith("light."))}e.openings=e.openings.map(r=>({...r,type:["door","window","garage"].includes(r.type)?r.type:"door",edge:Number.isInteger(r.edge)?r.edge:0,offset:Number.isFinite(r.offset)?r.offset:.5,width:Number.isFinite(r.width)&&r.width>0?r.width:r.type==="garage"?2.5:r.type==="window"?1.2:.9,height:Number.isFinite(r.height)&&r.height>0?r.height:r.type==="window"?1.3:r.type==="garage"?2.1:2.05,sill:Number.isFinite(r.sill)?r.sill:r.type==="window"?.9:0,hinge:r.hinge??"left",leaves:r.leaves??1,swing:r.swing??"in",style:r.style??null,cover:r.cover??null,contact:r.contact??null,contact2:r.contact2??null,tilt:r.tilt??null}))}return w_(t),t}function w_(t){let e=(n,r)=>{let o=new Set;for(let i of n)(typeof i.id!="string"||!i.id||o.has(i.id))&&(i.id=D(r)),o.add(i.id)};e(t.floors,"floor");for(let n of t.floors){for(let r of n.rooms)(typeof r.id!="string"||!r.id)&&(r.id=D("room"));e(n.openings,"op"),e(n.furniture,"furn"),e(n.outdoor,"out")}}function D(t){return`${t}_${Math.random().toString(36).slice(2,10)}`}function ge(t){let e=0;for(let n=0;ni+s[0],0)/o,t.reduce((i,s)=>i+s[1],0)/o]}let n=0,r=0;for(let o=0;o1e-6&&Math.abs(r-i)>1e-6)return!1}return!0}function de(t){let e=1/0,n=1/0,r=-1/0,o=-1/0;for(let[i,s]of t)e=Math.min(e,i),n=Math.min(n,s),r=Math.max(r,i),o=Math.max(o,s);return{x0:e,z0:n,x1:r,z1:o}}function bs(t){let e=t.rotation*Math.PI/180,n=Math.cos(e),r=Math.sin(e),o=t.w/2,i=t.d/2;return[[-o,-i],[o,-i],[o,i],[-o,i]].map(([s,l])=>[t.x+s*n-l*r,t.z+s*r+l*n])}function N(t,e){let n=!1;for(let r=0,o=e.length-1;rt[1]!=a>t[1]&&t[0]<(l-i)*(t[1]-s)/(a-s)+i&&(n=!n)}return n}var Co={lamp_ceiling:"ceiling",lamp_downlight:"downlight",lamp_spot:"spot",lamp_panel:"panel",lamp_uplight:"uplight",lamp_bollard:"bollard",lamp_garden:"garden",lamp_pendant:"pendant",ceiling_fan:"fan",lamp_floor:"floor",lamp_table:"table",lamp_wall:"wall",led_strip:"strip"};var ys=t=>t.trim().replace(/^\/local\/www\//i,"/local/"),ws=t=>/^(https:\/\/|\/local\/|\/hacsfiles\/)\S+\.m?js(\?\S*)?$/i.test(t.trim());var k_=globalThis,nd=k_.__nextfloorPluginStore??={plugins:new Map,listeners:new Set},vs=nd.plugins,td=nd.listeners;var x_=5;function rd(t,e){t.errors.lengthtd.delete(t)}var ks=()=>[...vs.values()].map(t=>t.status),od=()=>[...vs.values()].flatMap(t=>Object.keys(t.plugin.lightAnimations??{}));function*Bo(t,e){for(let{plugin:n,status:r}of vs.values())for(let o of n.devices??[]){let i=!1;try{i=o.match(t,e)}catch(s){rd(r,s)}i&&(yield{device:o,status:r})}}function Wo(t,e){for(let{device:n}of Bo(t,e))return n.kind??"sensor";return null}function id(t,e){let n=t.states[e];if(!n)return null;let r=$_({hass:t,entityId:e,state:n})?.icon?.trim();return r&&/^mdi:[a-z0-9-]+$/i.test(r)?r:null}function $_(t){let e=null;for(let{device:n,status:r}of Bo(t.entityId,t.state))if(n.marker)try{let o=n.marker(t);if(!o)continue;e={...e??{}},typeof o.icon=="string"&&o.icon&&(e.icon=o.icon),typeof o.text=="string"&&(e.text=o.text.slice(0,60)),typeof o.active=="boolean"&&(e.active=o.active)}catch(o){rd(r,o)}return e}function Vo(t,e){return t?typeof t=="string"?t:t[e]??t[e.split("-")[0]]??t.en??Object.values(t)[0]??"":""}function sd(t,e){let n=[];for(let{device:r,status:o}of Bo(t,e))r.settings?.length&&n.push({pluginId:o.id,name:o.name,settings:r.settings});return n}function ad(t,e){let n={};for(let r of t??[]){let o=e?.[r.key],i=r.type==="number"?typeof o=="number"&&Number.isFinite(o):r.type==="boolean"?typeof o=="boolean":typeof o=="string"&&(r.options??[]).some(([s])=>s===o);n[r.key]=i?o:r.default}return n}function ld(t,e){for(let{device:n}of Bo(t,e))if(n.floorWedge)return!0;return!1}var S_=new Set(["temperature","humidity","power","carbon_dioxide","energy","gas","water","volume","volume_storage","volume_flow_rate","illuminance","pressure","atmospheric_pressure","pm1","pm25","pm10","volatile_organic_compounds","volatile_organic_compounds_parts","carbon_monoxide","nitrogen_dioxide","moisture","sound_pressure"]),M_=new Set(["m\xB3","m3","L","l","kWh","Wh","MWh","lx"]),R_=new Set(["door","window","opening","garage_door","motion","occupancy","presence","smoke","moisture","gas","carbon_monoxide"]),E_=new Set(["battery","signal_strength","timestamp","date","duration","data_rate","data_size","frequency","enum"]);function Tt(t,e){let n=t.entities?.[e];return n&&(n.area_id||(n.device_id?t.devices?.[n.device_id]?.area_id:null))||null}var dd=(t,e)=>{let n=t.entities?.[e];return!!(n?.hidden||n?.entity_category)},Ne=(t,e)=>X(e)??Wo(e,t.states[e]);function cd(t,e){let n=t.states[e];if(!n||dd(t,e))return!1;if(Wo(e,n)!==null)return!0;let r=X(e);if(!r)return!1;let o=n.attributes.device_class;return e.startsWith("event.")?!o||o==="button"||o==="doorbell":r==="sensor"?o?S_.has(o):M_.has(String(n.attributes.unit_of_measurement??"")):r==="binary"?o?R_.has(o):!!t.entities?.[e]?.area_id:!0}function A_(t,e){let n=t.states[e];return X(e)!=="sensor"||!n?.attributes.unit_of_measurement||dd(t,e)||E_.has(String(n.attributes.device_class??""))?!1:Number.isFinite(Number(n.state))||Rt(n)}var Go=(t,e)=>e.startsWith("sensor.")&&t.states[e]?.attributes.device_class==="power",xs=null;No(()=>xs=null);function $s(t,e){let n=t.get(e);return n||t.set(e,n=[]),n}function F_(t){let e=new Map,n=new Map,r=new Map,o=new Map,i=[],s=d=>{(cd(t,d)||A_(t,d))&&Mt(Ne(t,d))&&i.push(d)};for(let[d,u]of Object.entries(t.entities??{})){let p=u.device_id;p&&u.area_id&&(o.get(p)??o.set(p,new Set).get(p)).add(u.area_id),p&&Go(t,d)&&$s(n,p).push(d),p&&!u.hidden&&!u.entity_category&&(r.get(p)??r.set(p,new Set).get(p)).add(ss(d));let h=Tt(t,d);h===null?s(d):cd(t,d)&&$s(e,h).push(d)}if(t.entities)for(let d of Object.keys(t.states))t.entities[d]||s(d);let l=as.indexOf("binary")-.5,a=d=>{let u=X(d),p=u?as.indexOf(u):l;return p>l&&Wo(d,t.states[d])!==null?l:p};i.sort((d,u)=>a(d)-a(u)||W(t,d).localeCompare(W(t,u)));for(let[d,u]of e){let p=t.areas?.[d]?.name;u.sort((h,f)=>a(h)-a(f)||W(t,h,p).localeCompare(W(t,f,p)))}let c=new Set;for(let[d,u]of o)u.size>1&&c.add(d);return{entities:t.entities,devices:t.devices,states:t.states,stateCount:Object.keys(t.states).length,byArea:e,powerByDevice:n,withoutArea:i,domainsByDevice:r,hubs:c}}function $n(t){let e=xs;return e&&e.entities===t.entities&&e.devices===t.devices&&(e.states===t.states||(e.states=t.states,Object.keys(t.states).length===e.stateCount))?e:xs=F_(t)}function be(t,e){let n=Ko(t,e.area_id);return e.sub_areas?.length?[...new Set([...n,...e.sub_areas.flatMap(r=>Ko(t,r))])]:n}function Ko(t,e){return!e||!t.entities?[]:$n(t).byArea.get(e)??[]}function ud(t,e){if(!t.entities)return[];let n=[];for(let[r,o]of $n(t).byArea){let i=o.filter(s=>Mt(Ne(t,s)));r!==e&&i.length>0&&n.push({areaId:r,name:t.areas?.[r]?.name??r,ids:i})}return n.sort((r,o)=>r.name.localeCompare(o.name))}var hd=t=>t.entities?$n(t).withoutArea:[],Ss=(t,e)=>!!t.entities&&$n(t).hubs.has(e),jo=(t,e)=>t.entities?$n(t).powerByDevice.get(e)??[]:[];function Sn(t,e){let n=new Map;for(let o of e)$s(n,t.entities?.[o]?.device_id??`entity:${o}`).push(o);let r=new Map(e.map((o,i)=>[o,i]));return[...n.values()].map(o=>{let i=o.find(s=>!t.entities?.[s]?.name)??o[0];return{primary:i,others:o.filter(s=>s!==i)}}).sort((o,i)=>r.get(o.primary)-r.get(i.primary))}var Uo=(t,e)=>Sn(t,e).map(n=>n.primary),T_={temperature:"temperature",humidity:"humidity",co2:"carbon_dioxide"};function Ms(t,e,n){let r=t.states[e]?.attributes;if(!r||!((r.symcon_variable_type===1||r.symcon_variable_type===2)&&typeof r.symcon_id=="number")&&!/^(sensor|input_number|number)\./.test(e))return!1;let i=String(r.unit_of_measurement??"").replace(/\s/g,"").toLowerCase();return n==="temperature"&&["\xB0c","\xB0f","\u2103","\u2109","k"].includes(i)?!0:r.device_class===T_[n]}var z_=new Set(["climate","water_heater","switch","button","camera","media_player","vacuum","light","fan","lawn_mower"]),P_=["vorlauf","r(\xFC|ue)cklauf","flow","return","d(\xFC|ue)se","nozzle","hotend","extruder","druckbett","heatbed","(^|[^a-z])bed($|[^a-z])","chamber","cpu","gpu","chip","soc","akku","batter","wasser","water","kessel","boiler","au(\xDF|ss)en","outdoor","outside","abgas","exhaust","sole","brine","verdampfer","kondensat","verdichter","compressor","motor","k(\xFC|ue)hl","freezer","fridge","gefrier"],I_=new RegExp(`(${P_.join("|")})`,"i");function Rs(t,e){let n=t.entities?.[e]?.device_id,r=n&&!Ss(t,n)?$n(t).domainsByDevice.get(n):void 0;return r&&[...r].some(o=>z_.has(o))?!1:!I_.test(`${e} ${t.states[e]?.attributes.friendly_name??""}`)}function pd(t,e,n,r){let o=n.climate?.[r];if(o==="none")return[];if(o)return[o].flat().filter(c=>t.states[c]);let i=(e?.placements??[]).filter(c=>c.entity_id.startsWith("sensor.")),s=i.filter(c=>N([c.x,c.z],n.points)).map(c=>c.entity_id),l=new Set(i.filter(c=>!N([c.x,c.z],n.points)).map(c=>c.entity_id));return[...new Set([...be(t,n).filter(c=>!l.has(c)),...s])].filter(c=>c.startsWith("sensor.")&&Ms(t,c,r)&&Rs(t,c))}var D_=new Set([void 0,"shutter","blind","awning","shade","curtain","window"]),O_=new Set(["garage","gate"]),H_=new Set(["window","opening"]);function _r(t,e,n=!1){let r=new Map;return t.forEach((o,i)=>{let s=n&&e.length===1?e[0]:e[i];s&&r.set(o.id,s)}),r}var fd=(t,e)=>t==="none"?null:t??e??null,Mn=t=>t&&t!=="none"?t:null;function br(t,e){let n=new Map;for(let r of e)for(let o of r.rooms){let i=r.openings.filter(g=>g.room_id===o.id).sort((g,y)=>g.edge-y.edge||g.offset-y.offset);if(i.length===0)continue;let s=be(t,o),l=g=>t.states[g]?.attributes.device_class,a=g=>s.filter(y=>X(y)==="binary"&&g(l(y)??"")),c=g=>i.filter(y=>y.type===g),d=_r(c("window"),s.filter(g=>X(g)==="cover"&&D_.has(l(g))),!0),u=_r(c("window"),a(g=>H_.has(g))),p=_r(c("door"),a(g=>g==="door")),h=_r(c("garage"),s.filter(g=>X(g)==="cover"&&O_.has(l(g)??""))),f=_r(c("garage"),a(g=>g==="garage_door"));for(let g of i){let y=g.type==="window"?d:g.type==="garage"?h:null,b=g.type==="window"?u:g.type==="garage"?f:p,v=g.leaves===2;n.set(g.id,{cover:fd(g.cover,y?.get(g.id)),contact:g.sensor==="handle"&&g.contact==null?null:fd(g.contact,b.get(g.id)),tilt:g.tilt==="none"?null:g.tilt,contact2:v?Mn(g.contact2):null,tilt2:v?Mn(g.tilt2):null,position:Mn(g.position),positionInverted:!!g.position_inverted,tiltAngle:Mn(g.tilt_angle),tiltMax:g.tilt_max??null,tiltOffset:g.tilt_offset??null,tiltInvert:!!g.tilt_invert,shut:!!g.shut,angled:g.type==="door"&&!!g.open_angle,lock:g.type==="door"?Mn(g.lock):null,cover2:g.type==="garage"?null:Mn(g.cover2)})}}return n}var L_=[[/^(tilted|tilt|gekippt|kipp)/i,"tilted"],[/^(open|opened|offen|geöffnet|on)$/i,"open"],[/^(closed|close|geschlossen|zu|off)$/i,"closed"]];function Es(t){if(!t||Rt(t))return null;let e=t.attributes.window_state;for(let n of[typeof e=="string"?e:"",t.state]){let r=n.trim(),o=r&&L_.find(([i])=>i.test(r));if(o)return o[1]}return null}var md=/\b(tv|fernseh|television|fire ?tv|apple ?tv|chromecast|shield)/i,gd=/(kühl|fridge|gefrier|freezer)/i,_d=/(spülmaschine|geschirrspül|dishwasher)/i,C_=/(kochfeld|herd|induktion|cooktop)/i,N_={robot_vacuum:/(saug|vacuum|robo|roomba|roborock|dreame|ecovacs|deebot)/i,tv_board:md,tv_wall:md,desk:/\b(pc|computer|rechner|desktop|monitor|workstation)/i,fridge:gd,fridge_smart:gd,stove:/(herd|kochfeld|cooktop|stove|induktion)/i,kitchen_tall:/(backofen|oven|ofen)/i,dishwasher:_d,washer:/(waschmaschine|washer|washing)/i,dryer:/(trockner|dryer)/i,kitchen:/(kaffee|coffee|wasserkocher|kettle)/i,island:C_,sink:_d,radiator:/(heiz|radiator|thermostat|climate|hk|trv)/i},bd={lamp_ceiling:/(decke|ceiling|haupt|main)/i,lamp_downlight:/(spot|strahler|downlight|einbau)/i,lamp_spot:/(spot|strahler)/i,lamp_panel:/(panel|decke|ceiling)/i,lamp_uplight:/(fluter|uplight|steh)/i,lamp_bollard:/(weg|garten|garden|path|poller|außen|aussen|outdoor)/i,lamp_garden:/(garten|garden|spot|außen|aussen|outdoor|baum|tree)/i,lamp_pendant:/(pendel|pendant|hänge|esstisch|dining)/i,ceiling_fan:/(ventilator|fan)/i,lamp_floor:/(steh|floor)/i,lamp_table:/(tisch|nacht|table|bedside|lese|reading)/i,lamp_wall:/(wand|wall)/i,led_strip:/(led|strip|streifen|leiste|band)/i},yd=new Set(["tv_board","tv_wall"]);var Rn=t=>yd.has(t)||!!wc(t),Zo=t=>!!G(t)?.electric&&/speaker|multiroom|soundbar/.test(t.split(":").pop()??t),wr=t=>Rn(t)||t==="desk"||t==="fridge_smart",B_=t=>!!t&&t!=="none";function W_(t,e){if(Go(t,e))return e;let n=t.entities?.[e]?.device_id;return n?jo(t,n).find(r=>r!==e)??null:null}var V_=(t,e,n)=>t.rooms.find(r=>r.points.length>=3&&N([e,n],r.points));function yr(t,e,n,r){return t.find(o=>e?.test(n(o)))??(r?t[0]??null:null)}function Be(t,e){let n=new Map;for(let r of e){let o=new Set([...r.furniture.flatMap(i=>[i.entity,i.power,i.fan_entity]),...r.placements.map(i=>i.entity_id)].filter(B_));for(let i of r.furniture){let s=i.type in bd,l=yn(i.type),a=s?bd[i.type]:N_[i.type];if(!a&&!l&&!Zo(i.type)&&i.entity==null&&i.power==null)continue;let c=V_(r,i.x,i.z),d=(c?Uo(t,be(t,c)):[]).filter(y=>!o.has(y)),u=y=>`${y} ${W(t,y)}`,p=y=>d.filter(b=>X(b)===y),h=i.entity==="none"?null:i.entity??null;if(i.entity==null){if(i.type==="ceiling_fan"){let y=(c?be(t,c):[]).filter(v=>!o.has(v)),b=new Set(y.filter(v=>X(v)==="fan").map(v=>t.entities?.[v]?.device_id).filter(Boolean));h=y.find(v=>X(v)==="light"&&b.has(t.entities?.[v]?.device_id))??yr(p("light"),a,u,!1)}else if(s)h=yr(p("light"),a,u,!0);else if(i.type==="robot_vacuum"){let y=c?.area_id??null;h=Object.keys(t.entities??{}).find(b=>b.startsWith("vacuum.")&&!o.has(b)&&Tt(t,b)===y)??null}else if(i.type==="radiator"||l)h=yr(p("climate"),a,u,!0);else if(Rn(i.type)){let y=p("media");h=y.find(b=>t.states[b]?.attributes.device_class==="tv")??yr(y,a,u,yd.has(i.type))}else if(Zo(i.type)){let y=p("media").filter(b=>t.states[b]?.attributes.device_class!=="tv");h=yr(y,a,u,!1)??(y.length===1?y[0]:null)}else a&&(h=d.find(y=>["switch","media","fan"].includes(X(y)??"")&&a.test(u(y)))??null);h&&o.add(h)}let f=i.power==="none"?null:i.power??null;i.power==null&&(f=h?W_(t,h):null,!f&&a&&c&&!s&&(f=be(t,c).find(y=>Go(t,y)&&!o.has(y)&&a.test(u(y)))??null),f&&o.add(f));let g=null;if(i.type==="ceiling_fan"&&(g=i.fan_entity==="none"?null:i.fan_entity??null,i.fan_entity==null)){let y=(c?be(t,c):[]).filter(v=>X(v)==="fan"&&!o.has(v)),b=h?t.entities?.[h]?.device_id:void 0;g=(b?y.find(v=>t.entities?.[v]?.device_id===b):void 0)??y[0]??null,g&&o.add(g)}(h||f||g)&&n.set(i.id,{entity:h,power:f,...i.type==="ceiling_fan"?{fan:g}:{}})}}return n}var wd=t=>t==="fridge"||t==="fridge_smart"||/(fridge|freezer|kuehl|gefrier|chest_freezer)/.test(t.slice(t.lastIndexOf(":")+1));function vd(t,e,n=[]){let r=[];for(let o of e){let i=(l,a)=>o.rooms.some(c=>c.points.length>=3&&N([l,a],c.points)),s=Be(t,[o]);r.push(...o.placements.filter(l=>l.outside||!i(l.x,l.z)).map(l=>l.entity_id)),r.push(...o.furniture.filter(l=>!i(l.x,l.z)).flatMap(l=>[s.get(l.id)?.entity,s.get(l.id)?.power]));for(let l of o.outdoor??[])l.area_id&&r.push(...Uo(t,Ko(t,l.area_id))),r.push(l.pump_entity,l.temp_entity)}return[...new Set(r.filter(o=>!!o&&!!t.states[o]&&!n.includes(o)))]}function K_(t,e){return Math.min(...e.map((n,r)=>{let o=e[(r+1)%e.length],[i,s]=[o[0]-n[0],o[1]-n[1]],l=Math.min(1,Math.max(0,((t[0]-n[0])*i+(t[1]-n[1])*s)/(i*i+s*s||1)));return Math.hypot(t[0]-n[0]-i*l,t[1]-n[1]-s*l)}))}function xd(t,e,n=[]){let r=t.points;if(r.length<3||e.length===0)return[];let o=r.map(b=>b[0]),i=r.map(b=>b[1]),[s,l,a,c]=[Math.min(...o),Math.max(...o),Math.min(...i),Math.max(...i)],d=Math.min(l-s,c-a),u=Math.max(.1,Math.min(.25,d/8)),p=Math.min(.35,d/5),h=Math.min(.7,d/4),f=_e(r),g=[];for(let b=s+u/2;b=p&&g.push({at:w,wallDistance:x})}g.length===0&&g.push({at:f,wallDistance:0});let y=[...n];return e.map(b=>{let v=X(b)==="light",w=g[0].at,x=-1/0;for(let{at:$,wallDistance:A}of g){let F=y.length?Math.min(...y.map(z=>Math.hypot($[0]-z[0],$[1]-z[1]))):3,T=Math.hypot($[0]-f[0],$[1]-f[1]),I=Math.min(F,3)*2;Tx+1e-9&&(x=I,w=$)}let k=[Math.round(w[0]*100)/100,Math.round(w[1]*100)/100];return y.push(k),{entity_id:b,x:k[0],z:k[1],y:null,mount:null}})}var kd=/(^|_)(current_room|current_segment|aktueller_raum|current_area)($|_)/;function $d(t,e,n){if(n==="none")return null;if(n)return n;let r=e?t.entities?.[e]?.device_id:null;return!r||!t.entities?null:Object.values(t.entities).find(i=>i.device_id===r&&i.entity_id.startsWith("sensor.")&&(kd.test(i.translation_key??"")||kd.test(i.entity_id.split(".")[1])))?.entity_id??null}var K=(t,e)=>[t[0]-e[0],t[1]-e[1]],ct=(t,e)=>[t[0]+e[0],t[1]+e[1]],tt=(t,e)=>[t[0]*e,t[1]*e],Q=(t,e)=>t[0]*e[0]+t[1]*e[1],$e=(t,e)=>t[0]*e[1]-t[1]*e[0],fe=t=>Math.hypot(t[0],t[1]),nt=t=>{let e=fe(t)||1;return[t[0]/e,t[1]/e]},As=t=>[-t[1],t[0]],Fs=t=>[t[1],-t[0]];var G_=.05,j_=.2,U_=.12;function Z_(t){let e=[];return t.forEach((n,r)=>{let o=n.points;if(o.length<3)return;let i=ge(o)>=0;o.forEach((s,l)=>{let a=o[(l+1)%o.length],c=fe(K(a,s));if(c<.05)return;let d=[(a[0]-s[0])/c,(a[1]-s[1])/c],u=i?[d[1],-d[0]]:[-d[1],d[0]];(d[1]<-1e-9||Math.abs(d[1])<=1e-9&&d[0]<0)&&(d=[-d[0],-d[1]]);let p=[-d[1],d[0]],[h,f]=[Q(s,d),Q(a,d)];e.push({room:r,index:l,dir:d,normal:p,offset:Q(s,p),outside:Q(u,p)>0?1:-1,from:Math.min(h,f),to:Math.max(h,f)})})}),e}function q_(t,e,n){if(t.room===e.room||Math.abs($e(t.dir,e.dir))>G_||t.outside===e.outside)return null;let r=(e.offset-t.offset)*t.outside;return r>n||r<-U_||Math.abs(r)<1e-4||Math.min(t.to,e.to)-Math.max(t.from,e.from)Math.round(t*1e3)/1e3;function Sd(t,e=.6){let n=Z_(t),r=n.map((g,y)=>y),o=g=>r[g]===g?g:r[g]=o(r[g]),i=[],s=new Set,l=[];for(let g=0;gMath.abs(g[2])-Math.abs(y[2]));let a=new Map(n.map((g,y)=>[y,[y]])),c=(g,y)=>g.some(b=>y.some(v=>n[b].room===n[v].room&&Math.abs(n[b].offset-n[v].offset)>=.002));for(let[g,y,b]of l){let[v,w]=[o(g),o(y)];if(v!==w){if(c(a.get(v),a.get(w)))continue;r[v]=w,a.set(w,[...a.get(w),...a.get(v)]),a.delete(v)}i.push(Ts(b)),s.add(g).add(y)}let d=new Map(n.map((g,y)=>[`${g.room}:${g.index}`,y]));for(let g=s.size>0;g;)g=!1,n.forEach((y,b)=>{let v=d.get(`${y.room}:${(y.index+1)%t[y.room].points.length}`);if(v===void 0||v===b)return;let w=n[v];!(Math.abs($e(y.dir,w.dir))<1e-6&&Math.abs(y.offset-w.offset)<.002&&y.outside===w.outside)||s.has(b)===s.has(v)||(s.add(b).add(v),g=!0)});n.forEach((g,y)=>{let b=d.get(`${g.room}:${(g.index+1)%t[g.room].points.length}`);if(b===void 0||b===y||!s.has(y)||!s.has(b))return;let v=n[b];Math.abs($e(g.dir,v.dir))<1e-6&&Math.abs(g.offset-v.offset)<.002&&g.outside===v.outside&&(r[o(y)]=o(b))});let u=()=>t.map(g=>({...g,points:g.points.map(y=>[y[0],y[1]])}));if(i.length===0)return{rooms:u(),gaps:i};let p=new Map;for(let g of s)p.set(o(g),[...p.get(o(g))??[],g]);let h=t.map(g=>g.points.map(()=>new Map));for(let[g,y]of p){let b=new Map(y.map(w=>[`${n[w].room}:${Math.round(n[w].offset*500)}`,n[w].offset])),v=[...b.values()].reduce((w,x)=>w+x,0)/b.size;for(let w of y){let x=n[w],k=[x.normal[0]*(v-x.offset),x.normal[1]*(v-x.offset)];h[x.room][x.index].set(g,k),h[x.room][(x.index+1)%t[x.room].points.length].set(g,k)}}return{rooms:t.map((g,y)=>({...g,points:g.points.map((b,v)=>{let w=[...h[y][v].values()].reduce((x,k)=>[x[0]+k[0],x[1]+k[1]],[b[0],b[1]]);return[Ts(w[0]),Ts(w[1])]})})),gaps:i}}function Md(t){let e=t.filter(n=>n>.04).sort((n,r)=>n-r);return e.length===0?null:Math.min(.5,Math.max(.08,Math.round(e[Math.floor(e.length/2)]*100)/100))}var Y_=.25,Rd=t=>Math.round(t*1e3)/1e3,Ed=(t,e,n)=>t.rooms.find(r=>r.points.length>=3&&N([e,n],r.points));function Ps(t,e,n,r,o){let i=Ed(t,e,n);if(!i)return[r,o];let s=(l,a)=>N([l,a],i.points);return s(r,o)?[r,o]:s(r,n)?[r,n]:s(e,o)?[e,o]:[e,n]}function X_(t,e,n,r){return t.rooms.some(o=>o.id!==e.id&&o.points.some((i,s)=>{let l=o.points[(s+1)%o.points.length];return Math.abs(Q(K(i,n),r))<.02&&Math.abs(Q(K(l,n),r))<.02}))}var zs=(t,e)=>Math.abs((t-e+540)%360-180);function vr(t,e,n,r=Y_){let o=Ed(t,e.x,e.z);if(!o)return null;let i=o.points,s=ge(i)>=0?1:-1,l=null;return i.forEach((a,c)=>{let d=i[(c+1)%i.length],u=fe(K(d,a));if(u<.3)return;let p=[(d[0]-a[0])/u,(d[1]-a[1])/u],h=[-p[1]*s,p[0]*s],f=Q(K([e.x,e.z],a),p);if(f<0||f>u)return;let g=X_(t,o,a,h)?n/2:0,y=Q(K([e.x,e.z],a),h)-g,b=Math.atan2(-h[0],h[1])*180/Math.PI,w=[{rotation:b,extent:e.d/2},{rotation:b+90,extent:e.w/2},{rotation:b-90,extent:e.w/2}].reduce((k,$)=>zs(e.rotation,$.rotation)50)return;let x=y-w.extent;Math.abs(x)>r||l&&Math.abs(x)>=Math.abs(l.gap)||(l={x:Rd(e.x-h[0]*x),z:Rd(e.z-h[1]*x),rotation:(Math.round(w.rotation)%360+360)%360,gap:x})}),l&&{x:l.x,z:l.z,rotation:l.rotation}}var En=Math.PI/180,rt=t=>Math.tan(Math.min(80,Math.max(0,t))*En);function xr(t){return{x0:Math.min(t.x0,t.x1),x1:Math.max(t.x0,t.x1),z0:Math.min(t.z0,t.z1),z1:Math.max(t.z0,t.z1)}}function Ad(t){if(!t.rotation)return null;let e=t.rotation*En;return{cx:(t.x0+t.x1)/2,cz:(t.z0+t.z1)/2,c:Math.cos(e),sn:Math.sin(e)}}function Fd(t,e){let n=Ad(t);if(!n)return e;let[r,o]=[e[0]-n.cx,e[1]-n.cz];return[n.cx+r*n.c-o*n.sn,n.cz+r*n.sn+o*n.c]}function Is(t,e,n){let r=Ad(t);if(!r)return[e,n];let[o,i]=[e-r.cx,n-r.cz];return[r.cx+o*r.c+i*r.sn,r.cz-o*r.sn+i*r.c]}function $r(t,e=0){let{x0:n,x1:r,z0:o,z1:i}=xr(t);return[[n-e,o-e],[r+e,o-e],[r+e,i+e],[n-e,i+e]].map(s=>Fd(t,s))}function ve(t){let{x0:e,x1:n,z0:r,z1:o}=xr(t),i=s=>Fd(t,s);return t.axis==="x"?{u0:e,u1:n,w:o-r,at:(s,l)=>i([s,t.flip?o-l:r+l])}:{u0:r,u1:o,w:n-e,at:(s,l)=>i([t.flip?n-l:e+l,s])}}function Sr(t,e,n){let{x0:r,x1:o,z0:i,z1:s}=xr(t),[l,a]=Is(t,e,n);return t.axis==="x"?[l,t.flip?s-a:a-i]:[a,t.flip?o-l:l-r]}var kr=Math.tan(30*En);function Mr(t,e,n,r,o){let i=Math.min(t*.3,r>1e-6?2.4/r:t*.3),s=Math.min(t*.3,o>1e-6?2.4/o:t*.3),l=e+i*r,a=n+s*o,c=Math.min(t-s,Math.max(i,(a-l+kr*(t-s+i))/(2*kr))),d=l+(c-i)*kr;return{vla:i,vlb:s,yla:l,ylb:a,vr:c,rh:d,y:p=>p<=i?e+p*r:p<=c?l+(p-i)*kr:p<=t-s?a+(t-s-p)*kr:n+(t-p)*o}}function Pe(t){let e=ve(t).w,[n,r]=[t.eave_a,t.eave_b],[o,i]=[rt(t.pitch_a),rt(t.pitch_b)];switch(t.shape){case"flat":case"parapet":return{vr:e/2,rh:n,y:()=>n};case"pent":return{vr:e,rh:n+e*o,y:s=>n+s*o};case"mansard":{let s=Mr(e,n,r,o,i);return{vr:s.vr,rh:s.rh,y:s.y}}default:{let s=o+i>1e-6?Math.min(e,Math.max(0,(r-n+e*i)/(o+i))):e/2;return{vr:s,rh:n+s*o,y:l=>l<=s?n+l*o:r+(e-l)*i}}}}var Yt=t=>Pe(t).rh;function Td(t){let e=t.heightEnd!==void 0;return{...t,a:t.b,b:t.a,left:t.right,right:t.left,roomLeft:t.roomRight,roomRight:t.roomLeft,height:e?t.heightEnd:t.height,heightEnd:e?t.height:void 0}}function Q_(t,e){let n=t.map(r=>({...r}));for(let r of e){let o=n.find(i=>i.room_id===r.room_id&&i.edge===r.edge&&(Math.abs(i.t1-r.t0)<1e-6||Math.abs(r.t1-i.t0)<1e-6));o?(o.t0=Math.min(o.t0,r.t0),o.t1=Math.max(o.t1,r.t1)):n.push({...r})}return n}function J_(t,e,n){if(t.a===e.b)return!1;let r=nt(K(n[t.b],n[t.a])),o=nt(K(n[e.b],n[e.a]));return Math.abs($e(r,o))>1e-6||Q(r,o)<=0||t.free||e.free||t.heightEnd!==void 0||e.heightEnd!==void 0?!1:t.height===e.height&&t.exterior===e.exterior&&t.roomLeft===e.roomLeft&&t.roomRight===e.roomRight&&Math.abs(t.left-e.left)<=1e-9&&Math.abs(t.right-e.right)<=1e-9}function zd(t,e,n=new Set){let r=t.slice();for(;;){let o=new Map;r.forEach((s,l)=>{for(let a of[s.a,s.b])o.set(a,[...o.get(a)??[],l])});let i=null;for(let[s,l]of o){if(l.length!==2||n.has(s))continue;let a=r[l[0]].b===s?r[l[0]]:Td(r[l[0]]),c=r[l[1]].a===s?r[l[1]]:Td(r[l[1]]);if(!J_(a,c,e))continue;let d={...a,b:c.b,sources:Q_(a.sources,c.sources)};i=[...r.filter((u,p)=>p!==l[0]&&p!==l[1]),d];break}if(!i)return r;r=i}}function Pd(t,e){let n=new Map;t.forEach((o,i)=>{let s=nt(K(e[o.b],e[o.a])),l=[[o.a,{key:`${i}:a`,d:s,left:o.left,right:o.right,angle:Math.atan2(s[1],s[0])}],[o.b,{key:`${i}:b`,d:tt(s,-1),left:o.right,right:o.left,angle:Math.atan2(-s[1],-s[0])}]];for(let[a,c]of l)n.set(a,[...n.get(a)??[],c])});let r=new Map;for(let[o,i]of n){let s=e[o];i.sort((a,c)=>a.angle-c.angle);for(let a of i)r.set(a.key,{left:ct(s,tt(As(a.d),a.left)),right:ct(s,tt(Fs(a.d),a.right))});if(i.length<2)continue;let l=4*Math.max(...i.map(a=>Math.max(a.left,a.right)))+1e-9;i.forEach((a,c)=>{let d=i[(c+1)%i.length],u=ct(s,tt(As(a.d),a.left)),p=ct(s,tt(Fs(d.d),d.right)),h=$e(a.d,d.d);if(Math.abs(h)<1e-4)return;let f=ct(u,tt(a.d,$e(K(p,u),d.d)/h));fe(K(f,s))>l||(r.get(a.key).left=f,r.get(d.key).right=f)})}return r}function Id(t,e){let n=t.filter((r,o)=>fe(K(r,t[(o+1)%t.length]))>e);for(;;){if(n.length<=3)return n;let r=n.findIndex((o,i)=>{let s=n[(i+n.length-1)%n.length],l=n[(i+1)%n.length],[a,c]=[K(o,s),K(l,o)];return Math.abs($e(nt(a),nt(c)))<1e-7&&Q(a,c)>0});if(r===-1)return n;n=n.filter((o,i)=>i!==r)}}function eb(t){let e=[];return{points:e,idOf(n){let r=e.findIndex(o=>Math.abs(o[0]-n[0])<=t&&Math.abs(o[1]-n[1])<=t);return r>=0?r:(e.push([n[0],n[1]]),e.length-1)}}}function tb(t,e){let n=[];for(let r of t){let o=r.points;if(o.length<3||Math.abs(ge(o))<1e-6)continue;let i=ge(o)>0,s=o.map(l=>e.idOf(l));s.forEach((l,a)=>{let c=s[(a+1)%s.length];l!==c&&n.push(i?{u:l,v:c,room:r.id,edge:a,forward:!0}:{u:c,v:l,room:r.id,edge:a,forward:!1})})}return n}function nb(t,e,n){let r=[];for(let o of t){let[i,s]=[e[o.u],e[o.v]],l=K(s,i),a=fe(l),c=tt(l,1/a),d=e.map((p,h)=>({id:h,rel:K(p,i)})).filter(({id:p,rel:h})=>p!==o.u&&p!==o.v&&Q(h,c)>n&&Q(h,c)({t:Q(h,c),id:p})).sort((p,h)=>p.t-h.t),u=[{t:0,id:o.u},...d,{t:a,id:o.v}];for(let p=0;p+1({room_id:t.room,edge:t.edge,t0:t.t0,t1:t.t1});function rb(t,e){let n=new Map(t.map(l=>[l.id,l])),r=new Map;for(let l of e){let a=`${l.room}:${l.edge}`;r.set(a,[...r.get(a)??[],l.t0].sort((c,d)=>c-d))}let o=l=>{let a=n.get(l.room)?.wall_heights?.[l.edge];return Array.isArray(a)?a[(r.get(`${l.room}:${l.edge}`)??[]).indexOf(l.t0)]??null:a},i=l=>{let a=n.get(l.room),[c,d]=[a?.wall_heights?.[l.edge],a?.wall_slopes?.[l.edge]];if(!a||typeof c!="number"||typeof d!="number"||c<=0||d<=0)return null;let[u,p]=[a.points[l.edge],a.points[(l.edge+1)%a.points.length]];return{from:c,to:d,length:Math.hypot(p[0]-u[0],p[1]-u[1])}},s=l=>{let a=i(l);if(!a||a.length<1e-9){let d=o(l);return typeof d=="number"&&d>0?[d,d]:[null,null]}let c=d=>a.from+(a.to-a.from)*d/a.length;return l.forward?[c(l.t0),c(l.t1)]:[c(l.t1),c(l.t0)]};return{heightsOf(l){let[a,c]=[1/0,1/0];for(let u of l){let[p,h]=s(u),[f,g]=u===l[0]?[p,h]:[h,p];f!==null&&(a=Math.min(a,f)),g!==null&&(c=Math.min(c,g))}let d=l.map(u=>n.get(u.room)?.ceiling);if(d.every(u=>typeof u=="number"&&u>0)){let u=Math.max(...d);a===1/0&&(a=u),c===1/0&&(c=u)}return{...a<1/0?{a}:{},...c<1/0?{b:c}:{}}},thicknessOf(l){let a=l.map(c=>{let d=n.get(c.room)?.wall_thickness?.[c.edge];return Array.isArray(d)?d[(r.get(`${c.room}:${c.edge}`)??[]).indexOf(c.t0)]:d}).filter(c=>typeof c=="number"&&c>0);return a.length?Math.max(...a):void 0},hasNoWall:l=>l.some(a=>o(a)===0)}}function Od(t){let e=n=>Math.round(n*1e6)/1e6;return t.a===void 0||t.b===void 0?t.a!==void 0?{height:e(t.a)}:t.b!==void 0?{height:e(t.b)}:{}:Math.abs(t.a-t.b)<1e-6?{height:e(t.a)}:{height:e(t.a),heightEnd:e(t.b)}}function ob(t,e,n,r){let o=rb(e,t),i=new Map;for(let a of t){let c=a.up!==c&&p.u===c.v&&p.v===c.u&&p.room!==c.room);for(let p of a)p!==c&&p!==d&&p.room!==c.room&&r.push(`overlap:${c.room}:${p.room}`);let u=d?[c,d]:[c];if(o.hasNoWall(u)){d&&l.push([c.room,d.room]);continue}if(d){let p=o.thicknessOf(u)??n.interior;s.push({a:c.u,b:c.v,left:p/2,right:p/2,exterior:!1,roomLeft:c.room,roomRight:d.room,sources:u.map(Dd),...Od(o.heightsOf(u))})}else s.push({a:c.u,b:c.v,left:0,right:o.thicknessOf(u)??n.exterior,exterior:!0,roomLeft:c.room,roomRight:null,sources:[Dd(c)],...Od(o.heightsOf(u))})}return{drafts:s,open:l}}function ib(t,e){let n=i=>nt(K(e[i.b],e[i.a])),r=t.filter(i=>!i.exterior&&!i.free),o=new Map;for(let i of r){if(o.has(i))continue;let s=[i];o.set(i,s);for(let l=0;l1e-6||a.add(Q(s,h)>0?"left":"right")}if(a.size!==1)continue;let c=[...a][0];for(let d of i){let u=d.left+d.right,p=Q(n(d),s)>0,h=c==="left"===p;[d.left,d.right]=h?[0,u]:[u,0]}}}var sb=(t,e)=>{let n=i=>Math.round(i*100),[r,o]=t[0]Math.hypot(b.b[0]-b.a[0],b.b[1]-b.a[1])>.05),a=l.map(b=>[i.idOf(b.a),i.idOf(b.b)]),c=new Set;for(let b of t){let v=b.points;v.length<3||(b.wall_splits??[]).forEach((w,x)=>{if(!w||x>=v.length)return;let k=v[x],$=K(v[(x+1)%v.length],k),A=fe($);for(let F of w)F>r&&F{let[w,x]=a[v];if(w===x)return;let k=[(b.a[0]+b.b[0])/2,(b.a[1]+b.b[1])/2],$=t.find(F=>F.points.length>=3&&N(k,F.points))?.id??null,A=(b.thickness??e.interior)/2;h.push({free:b.id,a:w,b:x,left:A,right:A,exterior:!1,roomLeft:$,roomRight:$,sources:[],height:typeof b.height=="number"&&b.height>0?b.height:void 0,...typeof b.height=="number"&&b.height>0&&typeof b.height_end=="number"&&b.height_end>0&&Math.abs(b.height_end-b.height)>1e-6?{heightEnd:b.height_end}:{}})});let f=zd(h,i.points,c),g=Pd(f,i.points);return{walls:f.map((b,v)=>{let[w,x]=[i.points[b.a],i.points[b.b]],[k,$]=[g.get(`${v}:a`),g.get(`${v}:b`)],A=Id([k.right,$.left,x,$.right,k.left,w],1e-6);return{id:sb(w,x),a:[w[0],w[1]],b:[x[0],x[1]],left:b.left,right:b.right,exterior:b.exterior,roomLeft:b.roomLeft,roomRight:b.roomRight,sources:b.sources,footprint:A,...b.free?{free:b.free}:{},...b.height!==void 0?{height:b.height}:{},...b.heightEnd!==void 0?{heightEnd:b.heightEnd}:{}}}),warnings:[...new Set(o)],open:p}}function An(t,e,n){let r=t.points[e];return ct(r,tt(nt(K(t.points[(e+1)%t.points.length],r)),n))}function Ie(t,e,n){if(t.wall){let o=n.find(l=>l.id===t.wall);if(!o||Math.hypot(o.b[0]-o.a[0],o.b[1]-o.a[1])<.05)return null;let i=nt(K(o.b,o.a));return{room:{id:t.room_id,name:"",area_id:null,points:[o.a,o.b,ct(o.a,[-i[1],i[0]])]},edge:0}}let r=e.find(o=>o.id===t.room_id);return r&&t.edgeQ(K(e,t.a),nt(K(t.b,t.a)));function zt(t,e,n){if(!e.wall)return ab(t,n.room,n.edge,e.offset);let r=t.find(o=>o.free===e.wall);return r?{wall:r,s:Hd(r,An(n.room,0,e.offset))}:null}function ab(t,e,n,r){for(let o of t)if(o.sources.some(s=>s.room_id===e.id&&s.edge===n&&r>=s.t0-1e-6&&r<=s.t1+1e-6))return{wall:o,s:Hd(o,An(e,n,r))};return null}function Ld(t,e){let n=t.points.map(h=>h[0]),r=t.points.map(h=>h[1]);if(t.points.length!==4||new Set(n.map(h=>h.toFixed(3))).size!==2||new Set(r.map(h=>h.toFixed(3))).size!==2)return null;let[o,i,s,l]=[Math.min(...n),Math.max(...n),Math.min(...r),Math.max(...r)],a=h=>Math.max(0,...e.filter(f=>(f.roomLeft===t.id||f.roomRight===t.id)&&h(f)).map(f=>f.roomLeft===t.id?f.left:f.right)),c=(h,f)=>Math.abs(h-f)<.001,d=(h,f,g)=>c(h.a[f],g)&&c(h.b[f],g),u=i-o-a(h=>d(h,0,o))-a(h=>d(h,0,i)),p=l-s-a(h=>d(h,1,s))-a(h=>d(h,1,l));return[Math.round(u*1e3)/1e3,Math.round(p*1e3)/1e3]}var Cd=([t,e])=>{let n=Math.hypot(t,e)||1;return[t/n,e/n]};function lb(t){return t.reduce((e,n,r)=>e+(n[0]*t[(r+1)%t.length][1]-t[(r+1)%t.length][0]*n[1]),0)/2}function Nd(t,e){let n=t.length;if(n<3||Math.abs(e)<1e-9)return t.map(([o,i])=>[o,i]);let r=lb(t)>=0?1:-1;return t.map((o,i)=>{let s=t[(i+n-1)%n],l=t[(i+1)%n],[a,c]=Cd([o[0]-s[0],o[1]-s[1]]),[d,u]=Cd([l[0]-o[0],l[1]-o[1]]),p=[c*r,-a*r],h=[u*r,-d*r],f=[p[0]+h[0],p[1]+h[1]],g=Math.hypot(f[0],f[1]);if(g<1e-6)return[o[0]+p[0]*e,o[1]+p[1]*e];let y=(f[0]*p[0]+f[1]*p[1])/g,b=Math.min(4,1/Math.max(.25,y));return[o[0]+f[0]/g*e*b,o[1]+f[1]/g*e*b]})}function Pt(t){let e=t.map(r=>r[0]),n=t.map(r=>r[1]);return{x0:Math.min(...e),z0:Math.min(...n),x1:Math.max(...e),z1:Math.max(...n)}}function cb(t){let e=([i,s])=>`${Math.round(i*1e3)}:${Math.round(s*1e3)}`,n=new Map;for(let i of t)for(let s of[i.a,i.b])n.set(e(s),[...n.get(e(s))??[],i]);let r=new Set,o=null;for(let i of t){if(r.has(i))continue;r.add(i);let s=[i.a,i.b],l=i.b;for(;;){let c=(n.get(e(l))??[]).find(d=>!r.has(d));if(!c||(r.add(c),l=e(c.a)===e(l)?c.b:c.a,e(l)===e(s[0])))break;s.push(l)}s.length>=3&&e(l)===e(s[0])&&(!o||Math.abs(we(s))>Math.abs(we(o)))&&(o=s)}return o}function Ds(t,e,n,r){let o=pe(t,{exterior:n,interior:r},e).walls.filter(l=>l.exterior&&!l.free),i=o.length?cb(o.map(l=>({a:l.a,b:l.b}))):null;if(!i)return null;let s=i.filter((l,a)=>{let c=i[(a+i.length-1)%i.length],d=i[(a+1)%i.length];return Math.abs((l[0]-c[0])*(d[1]-l[1])-(l[1]-c[1])*(d[0]-l[0]))>1e-6});return s.length>=3?Nd(s,n):null}function Xt(t,e){let n=ve(t),r=Pe(t),o=n.w,[i,s]=[Math.max(0,e.a),Math.max(0,e.b)],l=n.u0-Math.max(0,e.u0),a=n.u1+Math.max(0,e.u1),c=(b,v)=>[b,v,r.y(v)],d=c(l,-i),u=c(a,-i),p=c(a,o+s),h=c(l,o+s),[f,g]=[rt(t.pitch_a),rt(t.pitch_b)],y=b=>[b,r.vr,r.rh];if(t.ends&&(t.shape==="gable"||t.shape==="hip"||t.shape==="halfhip")){let b=(n.u1-n.u0)/2,v=Math.min(b,Math.min(r.vr,o-r.vr)||o/2),w=Math.min(r.y(0),r.y(o)),x=w+(r.rh-w)*Math.min(.9,Math.max(.2,t.halfhip??.55)),k=f>1e-6?Math.min(r.vr,(x-t.eave_a)/f):r.vr,$=g>1e-6?Math.max(r.vr,o-(x-t.eave_b)/g):r.vr,A=Math.min(b-.1,(r.rh-x)/Math.max(.2,f)),F=[[0,r.y(0)],[r.vr,r.rh],[o,r.y(o)]],T=[[0,r.y(0)],[k,x],[$,x],[o,r.y(o)]],I=(V,Vt,_o)=>{if(V==="hip")return{upA:[],upB:[],ridge:y(Vt===l?n.u0+v*_o:n.u1-v*_o),profile:null};if(V==="halfhip"){let qg=y(Vt===l?n.u0+A:n.u1-A);return{upA:[[Vt,k,x]],upB:[[Vt,$,x]],ridge:qg,profile:T}}return{upA:[],upB:[],ridge:y(Vt),profile:F}},z=I(t.ends[0],l,1),C=I(t.ends[1],a,1),B=[[d,u,...C.upA,C.ridge,z.ridge,...[...z.upA].reverse()],[z.ridge,C.ridge,...[...C.upB].reverse(),p,h,...z.upB]],q=[[z.ridge,C.ridge]];for(let[V,Vt,_o]of[[z,d,h],[C,u,p]])V.profile===null?(B.push(V===z?[h,d,V.ridge]:[u,p,V.ridge]),q.push([Vt,V.ridge],[_o,V.ridge])):V.upA.length&&(B.push(V===z?[V.upB[0],V.upA[0],V.ridge]:[V.upA[0],V.upB[0],V.ridge]),q.push([V.upA[0],V.ridge],[V.upB[0],V.ridge]));let ye=V=>V.profile===null?[]:V.upA.length?[V.upA[0],V.upB[0]]:[V.ridge],$t=[d,u,...ye(C),p,h,...[...ye(z)].reverse()];return{faces:B,rim:$t,ridges:q,gable:F,endProfiles:[z.profile,C.profile]}}switch(t.shape){case"pent":return{faces:[[d,u,p,h]],rim:[d,u,p,h],ridges:[[p,h]],gable:[[0,r.y(0)],[o,r.y(o)]]};case"hip":case"pyramid":{let b=(n.u1-n.u0)/2,v=t.shape==="pyramid"?b:Math.min(b,Math.min(r.vr,o-r.vr)||o/2),w=y(n.u0+v),x=y(n.u1-v);return t.shape==="pyramid"?{faces:[[d,u,w],[u,p,w],[p,h,w],[h,d,w]],rim:[d,u,p,h],ridges:[[d,w],[h,w],[u,w],[p,w]],gable:null}:{faces:[[d,u,x,w],[w,x,p,h],[h,d,w],[u,p,x]],rim:[d,u,p,h],ridges:[[w,x],[d,w],[h,w],[u,x],[p,x]],gable:null}}case"halfhip":{let b=Math.min(r.y(0),r.y(o)),v=b+(r.rh-b)*Math.min(.9,Math.max(.2,t.halfhip??.55)),w=f>1e-6?Math.min(r.vr,(v-t.eave_a)/f):r.vr,x=g>1e-6?Math.max(r.vr,o-(v-t.eave_b)/g):r.vr,k=Math.min((n.u1-n.u0)/2-.1,(r.rh-v)/Math.max(.2,f)),$=y(n.u0+k),A=y(n.u1-k),F=[l,w,v],T=[l,x,v],I=[a,w,v],z=[a,x,v];return{faces:[[d,u,I,A,$,F],[$,A,z,p,h,T],[T,F,$],[I,z,A]],rim:[d,u,I,z,p,h,T,F],ridges:[[$,A],[F,$],[T,$],[I,A],[z,A]],gable:[[0,r.y(0)],[w,v],[x,v],[o,r.y(o)]]}}case"mansard":{let b=Mr(o,t.eave_a,t.eave_b,f,g),v=[l,b.vla,b.yla],w=[a,b.vla,b.yla],x=[l,o-b.vlb,b.ylb],k=[a,o-b.vlb,b.ylb],$=[l,b.vr,b.rh],A=[a,b.vr,b.rh];return{faces:[[d,u,w,v],[v,w,A,$],[$,A,k,x],[x,k,p,h]],rim:[d,u,w,A,k,p,h,x,$,v],ridges:[[$,A],[v,w],[x,k]],gable:[[0,r.y(0)],[b.vla,b.yla],[b.vr,b.rh],[o-b.vlb,b.ylb],[o,r.y(o)]]}}default:{let b=y(l),v=y(a);return{faces:[[d,u,v,b],[b,v,p,h]],rim:[d,u,v,p,h,b],ridges:[[b,v]],gable:[[0,r.y(0)],[r.vr,r.rh],[o,r.y(o)]]}}}}function Rr(t,e,n){let r=null;for(let o of t.faces){if(!N([e,n],o.map(([p,h])=>[p,h])))continue;let[i,s]=o,l=o.slice(2).find(p=>Math.abs((s[0]-i[0])*(p[1]-i[1])-(s[1]-i[1])*(p[0]-i[0]))>1e-9);if(!l)continue;let a=[s[0]-i[0],s[2]-i[2],s[1]-i[1]],c=[l[0]-i[0],l[2]-i[2],l[1]-i[1]],d=[a[1]*c[2]-a[2]*c[1],a[2]*c[0]-a[0]*c[2],a[0]*c[1]-a[1]*c[0]];if(Math.abs(d[1])<1e-9)continue;let u=i[2]-(d[0]*(e-i[0])+d[2]*(n-i[1]))/d[1];r=r===null?u:Math.min(r,u)}return r}function Er(t,e,n){let r=ve(e),o=t.floors.flatMap(u=>u.rooms.filter(p=>p.points.length>=3&&u.elevation+u.height>e.base+.05)),i=u=>u.some(p=>o.some(h=>N(p,h.points))),s=.35,l=[.15,.5,.85].map(u=>r.u0+(r.u1-r.u0)*u),a=[.15,.5,.85].map(u=>r.w*u),c=u=>u?0:n,d=(u,p)=>{let h=e.overhang_sides?.[u];return typeof h=="number"&&Number.isFinite(h)?Math.min(2,Math.max(0,h)):p};return{a:d("a",c(i(l.map(u=>r.at(u,-s))))),b:d("b",c(i(l.map(u=>r.at(u,r.w+s))))),u0:d("u0",c(i(a.map(u=>r.at(r.u0-s,u))))),u1:d("u1",c(i(a.map(u=>r.at(r.u1+s,u)))))}}var qo=t=>Math.abs((t.x1-t.x0)*(t.z1-t.z0)),Bd=t=>t.shape==="flat"||t.shape==="parapet",Qt=t=>Math.round(t*100)/100;function Yo(t,e){let[n,r]=[(e.x0+e.x1)/2,(e.z0+e.z1)/2];return t.filter(i=>{if(i===e||i.dormer||i.open||Bd(i)||qo(i)=s.x0&&n<=s.x1&&r>=s.z0&&r<=s.z1}).reduce((i,s)=>i===null||qo(s){let[i,s]=e.at(o,e.w/2),[l,a]=Sr(t,i,s);return Rr(n,l,a)??r.y(a)}}function Hs(t,e){if(Bd(e))return e;let n=ve(e),r=Pe(e).rh,o=ub(t,n),i=o(n.u0)<=o(n.u1),[s,l]=i?[n.u0,n.u1]:[n.u1,n.u0],a=i?1:-1,c=l;for(let p=.5;p=r-.02){c=s+a*p;break}if(Math.abs(c-l)<.05)return e;let d={...e},u=l===n.u1;return e.axis==="x"?d[u?"x1":"x0"]=c:d[u?"z1":"z0"]=c,d}var Ls=.14,Wd=t=>t.shape==="flat"||t.shape==="parapet";function Cs(t,e){return!t.open&&Math.min(t.base,t.eave_a,t.eave_b)a+o||pd+o||s.points&&s.points.length>=3&&!N([e,n],s.points))continue;let[h,f]=Sr(s,e,n),g=Math.max(0,s.overhang??r),y=Wd(s)?null:Rr(Xt(s,{u0:g,u1:g,a:g,b:g}),h,f);i.push((y??Pe(s).y(f))-Ls)}return i.length?Math.max(...i):null}function Ns(t,e,n){let r=[],o=e+n+Ls;for(let i of t.settings.roof.sections??[]){if(i.open||Wd(i)||i.shape==="mansard")continue;let s=ve(i),l=Pe(i),[a,c]=[rt(i.pitch_a),rt(i.pitch_b)],d=[];a>1e-6&&d.push((o-i.eave_a)/a),i.shape==="gable"&&c>1e-6&&d.push(s.w-(o-i.eave_b)/c);for(let u of d)u<=.01||u>=s.w-.01||i.shape==="gable"&&Math.abs(l.y(u)-o)>1e-6||r.push([s.at(s.u0,u),s.at(s.u1,u)])}return r}function Bs(t,e,n,r,o){let i=[];for(let l of[.2,.5,.8])for(let a of[.2,.5,.8])i.push([e+(r-e)*l,n+(o-n)*a]);let s=t.floors.filter(l=>l.rooms.some(a=>a.points.length>=3&&i.some(c=>N(c,a.points)))).map(l=>l.elevation+l.height);return s.length?Math.max(...s):null}function Ws(t,e){let n=t.floors.filter(a=>a.rooms.length>0).sort((a,c)=>a.elevation-c.elevation),r=n.filter(a=>a.elevationd.rooms.some(u=>u.points.length>=3&&a.some(p=>N(p,u.points))));if(c)return c}return r.at(-1)??n[0]}var _t=t=>Math.round(t*1e3)/1e3;function Vs(t,e=n=>`roof_${n+1}`){let n=t.settings.roof?.pitch??35,r=t.settings.wall_exterior,o=t.floors.filter(a=>a.rooms.some(c=>c.points.length>=3)).sort((a,c)=>c.elevation-a.elevation),i=[],s=[],l=(a,c)=>a.some(d=>N(c,d.points));for(let a of o){let c=a.rooms.filter(y=>y.points.length>=3),d=[...new Set(c.flatMap(y=>y.points.map(b=>_t(b[0]))))].sort((y,b)=>y-b),u=[...new Set(c.flatMap(y=>y.points.map(b=>_t(b[1]))))].sort((y,b)=>y-b),p=u.slice(0,-1).map((y,b)=>d.slice(0,-1).map((v,w)=>{let x=[(d[w]+d[w+1])/2,(u[b]+u[b+1])/2];return l(c,x)&&!l(s,x)})),h=p.map(y=>y.map(()=>!1)),f=(y,b)=>p[b][y]&&!h[b][y],g=a.elevation+a.height;for(let y=0;yf(b+T,w+1)).every(Boolean);)w++;for(let F=y;F<=w;F++)for(let T=b;T<=v;T++)h[F][T]=!0;let[x,k]=[d[b]-r,d[v+1]+r],[$,A]=[u[y]-r,u[w+1]+r];Math.min(k-x,A-$)<.8||i.push({id:e(i.length),x0:_t(x),z0:_t($),x1:_t(k),z1:_t(A),shape:"gable",axis:k-x>=A-$?"x":"z",eave_a:_t(g),eave_b:_t(g),pitch_a:n,pitch_b:n,base:_t(g),overhang:null})}s.push(...c)}return i}var Se=Math.PI/180,We=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],Jt=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2],Fn=t=>Math.hypot(t[0],t[1],t[2]),en=t=>{let e=Fn(t)||1;return[t[0]/e,t[1]/e,t[2]/e]},Vd=(t,e)=>[t[1]*e[2]-t[2]*e[1],t[2]*e[0]-t[0]*e[2],t[0]*e[1]-t[1]*e[0]],Ve=t=>Math.round(t*100)/100,Fr=([t,e],n)=>(Math.atan2(t,-e)/Se-n+720)%360;var Gd=.25;function jd(t,e,n,r,o,i,s){let l=o-n>=i-r,a=l?o-n:i-r;return{key:`${t}:top`,section:e,side:"top",flat:!0,o:[n,s,r],eu:l?[1,0,0]:[0,0,1],es:l?[0,0,1]:[1,0,0],n:[0,1,0],lu:a,ls:l?i-r:o-n,pitch:0,span:()=>[0,a],facing:l?[0,1]:[1,0]}}function Ud(t,e){let n=en(Vd(t,e));return n[1]<0?[-n[0],-n[1],-n[2]]:n}var Zd=t=>{let e=en([-t[0],0,-t[2]]);return[e[0],e[2]]};function bt(t,e,n,r,o,i,s,l){let a=en(We(o,r)),c=en(We(i,r));return{key:t,section:e,side:n,flat:!1,o:r,eu:a,es:c,n:Ud(a,c),lu:Fn(We(o,r)),ls:Fn(We(i,r)),pitch:s,span:l,facing:Zd(c)}}function Kd(t,e,n,r,o,i){let s=Fn(We(o,r));if(s<.3)return null;let l=en(We(o,r)),a=We(i,r),c=a[0]*l[0]+a[1]*l[1]+a[2]*l[2],d=[a[0]-l[0]*c,a[1]-l[1]*c,a[2]-l[2]*c],u=Fn(d);if(u<.3)return null;let p=en(d),h=f=>{let g=Math.min(1,Math.max(0,f/u));return[c*g,s-(s-c)*g]};return{key:t,section:e,side:n,flat:!1,o:r,eu:l,es:p,n:Ud(l,p),lu:s,ls:u,pitch:Math.atan2(p[1],Math.hypot(p[0],p[2]))/Se,span:h,facing:Zd(p)}}function hb(t,e){let n=ve(t),r=Pe(t),o=(v,w,x)=>{let[k,$]=n.at(v,w);return[k,x,$]},[i,s]=[Math.max(0,e.a),Math.max(0,e.b)],l=n.u0-Math.max(0,e.u0),a=n.u1+Math.max(0,e.u1),c=a-l,d=r.y(-i),u=r.y(n.w+s);if(t.shape==="flat"||t.shape==="parapet"){let[v,w]=[n.at(l,-i),n.at(a,n.w+s)];return[jd(t.id,t.id,Math.min(v[0],w[0]),Math.min(v[1],w[1]),Math.max(v[0],w[0]),Math.max(v[1],w[1]),t.eave_a+Gd)]}if(t.shape==="pent")return[bt(`${t.id}:a`,t.id,"a",o(l,-i,d),o(a,-i,d),o(l,n.w+s,u),t.pitch_a,()=>[0,c])];if(t.shape==="mansard")return pb(t,n,l,a,i,s);let p=t.shape==="hip"||t.shape==="pyramid",h=(n.u1-n.u0)/2,f=t.shape==="pyramid"?h:p?Math.min(h,Math.min(r.vr,n.w-r.vr)||n.w/2):0,g=p?n.u0+f-l:0,y=p?a-(n.u1-f):0,b=[];if(r.vr>.3){let v=Math.hypot(r.vr+i,r.rh-d);b.push(bt(`${t.id}:a`,t.id,"a",o(l,-i,d),o(a,-i,d),o(l,r.vr,r.rh),t.pitch_a,w=>[g*(w/v),c-y*(w/v)]))}if(n.w-r.vr>.3){let v=Math.hypot(n.w+s-r.vr,r.rh-u);b.push(bt(`${t.id}:b`,t.id,"b",o(a,n.w+s,u),o(l,n.w+s,u),o(a,r.vr,r.rh),t.pitch_b,w=>[y*(w/v),c-g*(w/v)]))}if(p){let v=Kd(`${t.id}:c`,t.id,"c",o(l,n.w+s,u),o(l,-i,d),o(n.u0+f,r.vr,r.rh)),w=Kd(`${t.id}:d`,t.id,"d",o(a,-i,d),o(a,n.w+s,u),o(n.u1-f,r.vr,r.rh));b.push(...[v,w].filter(x=>x!==null))}return b}function pb(t,e,n,r,o,i){let s=Mr(e.w,t.eave_a,t.eave_b,rt(t.pitch_a),rt(t.pitch_b)),l=(f,g)=>{let[y,b]=e.at(f,g);return[y,s.y(g),b]},a=r-n,c=()=>[0,a],d=(f,g)=>Math.atan2(f,g)/Se,u=[],[p,h]=[e.w+i,e.w-s.vlb];return s.vla+o>.3&&u.push(bt(`${t.id}:a`,t.id,"a",l(n,-o),l(r,-o),l(n,s.vla),t.pitch_a,c)),s.vr-s.vla>.3&&u.push(bt(`${t.id}:au`,t.id,"a",l(n,s.vla),l(r,s.vla),l(n,s.vr),d(s.rh-s.yla,s.vr-s.vla),c)),s.vlb+i>.3&&u.push(bt(`${t.id}:b`,t.id,"b",l(r,p),l(n,p),l(r,h),t.pitch_b,c)),h-s.vr>.3&&u.push(bt(`${t.id}:bu`,t.id,"b",l(r,h),l(n,h),l(r,s.vr),d(s.rh-s.ylb,h-s.vr),c)),u}function Ks(t){return t.floors.filter(n=>n.rooms.some(r=>r.points.length>=3)).sort((n,r)=>r.elevation-n.elevation)[0]??null}function U(t){let e=t.settings.roof;if(!e||e.type==="none")return[];if(e.type==="custom")return(e.sections??[]).flatMap(w=>hb(w,Er(t,w,w.overhang??e.overhang)));let n=Ks(t);if(!n)return[];let r=n.rooms.flatMap(w=>w.points.map(x=>x[0])),o=n.rooms.flatMap(w=>w.points.map(x=>x[1])),i=t.settings.wall_exterior+e.overhang,[s,l]=[Math.min(...r)-i,Math.max(...r)+i],[a,c]=[Math.min(...o)-i,Math.max(...o)+i],d=n.elevation+n.height;if(e.type==="flat")return[jd("main",null,s,a,l,c,d+Gd)];let u=l-s>=c-a,p=e.ridge==="short"?!u:u,h=(p?c-a:l-s)/2,f=h*Math.tan(e.pitch*Se),g=(w,x,k)=>p?[w,d+k,(a+c)/2+x]:[(s+l)/2+x,d+k,w],[y,b]=p?[s,l]:[a,c],v=()=>[0,b-y];return[bt("main:a",null,"a",g(y,-h,0),g(b,-h,0),g(y,0,f),e.pitch,v),bt("main:b",null,"b",g(y,h,0),g(b,h,0),g(y,0,f),e.pitch,v)]}function Ke(t,e){let n=[];for(let r of t.floors.filter(o=>!e||o.id===e)){let{walls:o}=pe(r.rooms,{exterior:t.settings.wall_exterior,interior:t.settings.wall_interior},r.walls??[]);for(let i of o){if(!i.exterior&&!i.free)continue;let[s,l]=[i.b[0]-i.a[0],i.b[1]-i.a[1]],a=Math.hypot(s,l);if(a<1.2)continue;let[c,d]=[l/a,-s/a],u=Math.min(r.height,i.height??r.height,i.heightEnd??1/0),p=(h,f,g,y)=>n.push({key:h,section:null,side:"top",flat:!1,o:f,eu:g,es:[0,1,0],n:y,lu:a,ls:u,pitch:90,span:()=>[0,a],facing:[y[0],y[2]],wall:{floorId:r.id}});p(`wall:${r.id}:${i.id}`,[i.a[0]+c*i.right,r.elevation,i.a[1]+d*i.right],[s/a,0,l/a],[c,0,d]),i.free&&p(`wall:${r.id}:${i.id}:back`,[i.b[0]-c*i.left,r.elevation,i.b[1]-d*i.left],[-s/a,0,-l/a],[-c,0,-d])}}return n}var De="ground";function Xo(t){let e=t.floors.filter(n=>n.rooms.some(r=>r.points.length>=3)).sort((n,r)=>n.elevation-r.elevation);return e.find(n=>n.elevation>-.5)??e[0]??t.floors[0]??null}function Qo(t,e){let n=(e.rotation??0)*Se,r=[Math.cos(n),0,Math.sin(n)],o=[-Math.sin(n),0,Math.cos(n)],i=Xo(t),s=r[0]*e.u+o[0]*e.v,l=r[2]*e.u+o[2]*e.v,a=i?i.elevation+(e.base!=null?e.base:Nc(i,s,l)):e.base??0;return{key:De,section:null,side:"top",flat:!0,o:[0,a,0],eu:r,es:o,n:[0,1,0],lu:1e4,ls:1e4,pitch:0,span:()=>[-1e4,1e4],facing:[o[0],o[2]],unbounded:!0}}function ke(t,e,n=U(t)){return e.face===De?Qo(t,e):e.face.startsWith("wall:")?Ke(t,e.face.split(":")[1]).find(r=>r.key===e.face)??null:n.find(r=>r.key===e.face)??null}var Jo=1.13,zr=1.72,Ge=.025,ot=.07;function tn(t){let e=t.module_w||Jo,n=t.module_h||zr;return t.portrait===!1?[n,e]:[e,n]}function Pr(t){return t.layout?.length?t.layout.map(e=>Math.max(0,Math.min(60,Math.round(e)))):Array.from({length:Math.max(1,t.rows)},()=>Math.max(1,t.cols))}function Gs(t,e){return t.flat?Math.min(45,Math.max(0,e.tilt??15))*Se:t.wall?Math.min(90,Math.max(0,e.tilt??0))*Se:Math.min(45,Math.max(0,e.tilt??0))*Se}function Ir(t,e){let[,n]=tn(e),r=Gs(t,e);return t.wall?n*Math.cos(r)+Ge:!t.flat&&r<.001?n+Ge:t.flat&&e.rack==="ew"?n*Math.cos(r)+.08:n*Math.cos(r)+Math.max(.3,2*n*Math.sin(r))}function Tn(t,e){let[n,r]=tn(e),o=Pr(e),i=Math.max(1,...o);return[i*n+(i-1)*Ge,(o.length-1)*Ir(t,e)+r*Math.cos(Gs(t,e))]}var fb=t=>t.flat&&!t.unbounded&&!t.wall;function qd(t,e){if(!fb(t)||!e.rotation)return null;let n=e.rotation*Se,[r,o]=Tn(t,e);return{cos:Math.cos(n),sin:Math.sin(n),u:e.u+r/2,s:e.v+o/2}}function je(t,e,n=!1){let[r,o]=tn(e),i=Gs(t,e),s=o*Math.cos(i),l=Ir(t,e),a=Pr(e),c=Math.max(1,...a),d=new Set(e.skip??[]),u=qd(t,e),p=(y,b)=>u?[u.u+(y-u.u)*u.cos-(b-u.s)*u.sin,u.s+(y-u.u)*u.sin+(b-u.s)*u.cos]:[y,b],h=(y,b,v)=>{let[w,x]=p(y,b);return[0,1,2].map(k=>t.o[k]+t.eu[k]*w+t.es[k]*x+t.n[k]*v)},f=(y,b)=>{let[v,w]=p(y,b);if(t.unbounded)return!0;if(w<-1e-6||w>t.ls+1e-6)return!1;let[x,k]=t.span(w);return v>=x-1e-6&&v<=k+1e-6},g=[];return a.forEach((y,b)=>{let v=e.align==="right"?c-y:e.align==="center"?(c-y)/2:0;for(let w=0;w.001?s:o);if([[$,F],[A,F],[A,T],[$,T]].every(([I,z])=>f(I,z)))if(t.wall&&i>.001){let I=ot+o*Math.sin(i),[z,C]=e.flip?[I,ot]:[ot,I],B=[h($,F,z),h(A,F,z),h(A,T,C),h($,T,C)],q=e.flip?F:T;g.push({corners:B,posts:[$+.05,A-.05].map(ye=>[h(ye,q,0),h(ye,q,I)]),cell:x,skipped:k})}else if(!t.flat&&i>.001){let I=ot+o*Math.sin(i),z=[h($,F,ot),h(A,F,ot),h(A,T,I),h($,T,I)];g.push({corners:z,posts:[$+.05,A-.05].map(C=>[h(C,T,0),h(C,T,I)]),cell:x,skipped:k})}else if(!t.flat)g.push({corners:[h($,F,ot),h(A,F,ot),h(A,T,ot),h($,T,ot)],posts:[],cell:x,skipped:k});else{let z=.15+o*Math.sin(i),C=e.rack==="ew"&&b%2===1?!e.flip:!!e.flip,[B,q]=C?[T,F]:[F,T],ye=[h($,B,.15),h(A,B,.15),h(A,q,z),h($,q,z)],$t=[$+.05,A-.05].flatMap(V=>[[h(V,B,0),h(V,B,.15)],[h(V,q,0),h(V,q,z)]]);g.push({corners:ye,posts:$t,cell:x,skipped:k})}}}),g}function dt(t,e){if(t.unbounded)return{u:e.u,v:e.v};let[n,r]=Tn(t,e),o=qd(t,e);if(o){let[s,l]=[(n*Math.abs(o.cos)+r*Math.abs(o.sin))/2,(n*Math.abs(o.sin)+r*Math.abs(o.cos))/2],a=(u,p,h)=>Math.floor(Math.max(p,Math.min(u,h-p))*100+1e-6)/100,[c,d]=[e.u+n/2,e.v+r/2];return{u:Math.round((a(c,s,t.lu)-n/2)*100)/100,v:Math.round((a(d,l,t.ls)-r/2)*100)/100}}let i=s=>Math.floor(s*100+1e-6)/100;return{u:i(Math.min(Math.max(0,e.u),Math.max(0,t.lu-n))),v:i(Math.min(Math.max(0,e.v),Math.max(0,t.ls-r)))}}function Dr(t,e){let[n,r]=Tn(t,e),[o,i]=[e.u+n/2,e.v+r/2];return[t.o[0]+t.eu[0]*o+t.es[0]*i,t.o[2]+t.eu[2]*o+t.es[2]*i]}var ei=.78,Or=1.18,nn=t=>({id:t.id,face:t.face,u:t.u,v:t.v,rows:1,cols:1,portrait:!0,module_w:t.w||ei,module_h:t.h||Or});function js(t,e){let n=je(t,nn(e))[0];if(!n)return null;let r=o=>[o[0]-t.n[0]*.05,o[1]-t.n[1]*.05,o[2]-t.n[2]*.05];return n.corners.map(r)}var Tr={brick:{w:.5,d:.5,h:1},round:{w:.4,d:.4,h:1},wide:{w:1,d:.5,h:1},steel:{w:.2,d:.2,h:1.2}};function rn(t){let e=t.shape??"brick",n=Tr[e]??Tr.brick;return{shape:e,w:t.w||n.w,d:t.d||n.d,h:t.h||n.h}}function yt(t,e){let{w:n,d:r}=rn(t),o=e&&!e.flat?Math.cos(e.pitch*Se):1;return{id:t.id,face:t.face,u:t.u,v:t.v,rows:1,cols:1,portrait:!0,module_w:n,module_h:r/Math.max(.2,o),tilt:0}}function Us(t,e){let n=yt(e,t),[r,o]=[n.module_w,n.module_h],i=(d,u)=>[t.o[0]+t.eu[0]*d+t.es[0]*u,t.o[1]+t.eu[1]*d+t.es[1]*u,t.o[2]+t.eu[2]*d+t.es[2]*u],[s,l]=[i(e.u+r/2,e.v),i(e.u+r/2,e.v+o)],a=i(e.u+r/2,e.v+o/2),c=d=>{let u=Math.hypot(d[0],d[2])||1;return[d[0]/u,d[2]/u]};return{center:[a[0],a[2]],along:c(t.eu),across:c(t.es),low:Math.min(s[1],l[1]),high:Math.max(s[1],l[1])}}function Zs(t,e){let[n]=tn(e);return Ve((t.lu-(e.cols*n+(e.cols-1)*Ge))/2)}var Hr=.4;function zn(t,e){let n={id:e,face:t.key,u:0,v:0,rows:1,cols:1,portrait:!0,tilt:t.flat?15:null,flip:!1,entity:null,look:"black"},[r]=tn(n),[o,i]=t.span(t.ls/2);for(n.cols=Math.max(1,Math.floor((i-o-2*Hr+Ge)/(r+Ge))),n.rows=Math.max(1,Math.min(4,Math.floor((t.ls-2*Hr)/Ir(t,n))));n.cols>1&&je(t,{...n,u:Zs(t,n),v:Hr}).lengthl.lu*(1.3+Math.cos((Fr(l.facing,r)-180)*Math.PI/180)),i=Ke(t,n).sort((l,a)=>o(a)-o(l))[0];if(!i)return null;let s={...zn(i,e),portrait:!1,rows:1};return s.cols=Math.max(1,Math.floor((i.lu-.8+Ge)/(zr+Ge))),s.u=Ve((i.lu-(s.cols*zr+(s.cols-1)*Ge))/2),s.v=Ve(Math.max(0,i.ls-Jo-.3)),s}function Lr(t,e){let n=t.floors.flatMap(i=>i.rooms.flatMap(s=>s.points)),r=n.length?Math.max(...n.map(i=>i[0]))+3:0,o=n.length?Math.min(...n.map(i=>i[1])):0;return{id:e,face:De,u:Ve(r),v:Ve(o),rows:2,cols:4,portrait:!0,tilt:25,flip:!0,rotation:(t.settings.north??0)||0,look:"black",entity:null}}function Cr(t,e,n){let r=Qo(t,e),[o,i]=Tn(r,e),[s,l]=[e.u+o/2,e.v+i/2],a=[r.eu[0]*s+r.es[0]*l,r.eu[2]*s+r.es[2]*l],c=n*Se,d=a[0]*Math.cos(c)+a[1]*Math.sin(c)-o/2,u=a[0]*-Math.sin(c)+a[1]*Math.cos(c)-i/2;return{u:Ve(d),v:Ve(u),rotation:(Math.round(n)%360+360)%360}}function Nr(t,e){let[n,r]=t.span(t.ls/2);return{id:e,face:t.key,u:Ve((n+r-ei)/2),v:Ve(Math.max(0,Math.min(t.ls-Or,t.ls*.45-Or/2))),w:null,h:null,cover:null,contact:null,tilt:null}}function Br(t,e){let n=Tr.brick,[r,o]=t.span(t.ls*.8),i=yt({id:e,face:t.key,u:0,v:0},t).module_h;return{id:e,face:t.key,u:Ve((r+o-n.w)/2),v:Ve(Math.max(0,Math.min(t.ls-i,t.ls*.8-i/2))),shape:"brick",w:null,d:null,h:null}}function Pn(t,e){let[n,r]=[e[0]-t.o[0],e[1]-t.o[2]],[o,i,s,l]=[t.eu[0],t.eu[2],t.es[0],t.es[2]],a=o*l-i*s;if(Math.abs(a)<1e-9)return null;let c=(n*l-r*s)/a,d=(o*r-i*n)/a;if(d<0||d>t.ls)return null;let[u,p]=t.span(d);return c>=u&&c<=p?{u:c,s:d}:null}function Ys(t,e){let n=null;for(let r of t){if(r.wall){let[s,l]=[e[0]-r.o[0],e[1]-r.o[2]],a=s*r.eu[0]+l*r.eu[2],c=s*r.n[0]+l*r.n[2],d=a>=0&&a<=r.lu;if(d&&c>=-.05&&c<=.35)return{face:r,u:a,s:Number.NaN};d&&c>.35&&c<=.8&&!n&&(n={face:r,u:a,s:Number.NaN,y:-1/0});continue}let o=Pn(r,e);if(!o)continue;let i=r.o[1]+r.es[1]*o.s;(!n||i>n.y)&&(n={face:r,...o,y:i})}return n&&{face:n.face,u:n.u,s:n.s}}function ni(t,e,n){let r=Jt(n,t.n);if(Math.abs(r)<1e-6)return null;let o=Jt(We(t.o,e),t.n)/r;if(o<=0)return null;let i=We([e[0]+n[0]*o,e[1]+n[1]*o,e[2]+n[2]*o],t.o);return{t:o,u:Jt(i,t.eu),s:Jt(i,t.es)}}function Xs(t,e,n){if(t.unbounded)return!0;if(n<0||n>t.ls)return!1;let[r,o]=t.span(n);return e>=r&&e<=o}function Qs(t,e,n,r){return je(t,e).some(i=>{let s=i.corners.map(c=>{let d=We(c,t.o);return[Jt(d,t.eu),Jt(d,t.es)]}),l=s.map(c=>c[0]),a=s.map(c=>c[1]);return n>=Math.min(...l)-.05&&n<=Math.max(...l)+.05&&r>=Math.min(...a)-.05&&r<=Math.max(...a)+.05})}var mb=["n","ne","e","se","s","sw","w","nw"],Js=(t,e)=>mb[Math.round(Fr(t.facing,e)/45)%8];function Wr(t,e){let n=r=>{if(r.flat)return r.lu*r.ls*.8;let o=Math.cos((Fr(r.facing,e)-180)*Math.PI/180);return r.lu*r.ls*(1.2+o)};return[...t].sort((r,o)=>n(o)-n(r))[0]??null}var Jd=["kitchen_row","kitchen_l","bath","bedroom","living","dining","office","kids","hall"],Yd={kitchen_row:{rows:[["back","start",["fridge","kitchen_tall",["kitchen",[.9,.62,.92]],"sink","dishwasher","stove",["kitchen",[.6,.62,.92]]]],["back","start",[["kitchen_wall",[1.2,.35,.7]]]]],spots:[[["table",[1.2,.8,.75]],.5,.72,0],["lamp_pendant",.5,.72,0],["lamp_ceiling",.5,.3,0]]},kitchen_l:{rows:[["back","start",["fridge",["kitchen",[.9,.62,.92]],"sink","dishwasher","stove"]],["right","start",[["kitchen",[.9,.62,.92]],["kitchen",[.6,.62,.92]],"kitchen_tall"]],["back","start",[["kitchen_wall",[1.2,.35,.7]]]]],spots:[["table",.4,.68,0],["bar_stool",.72,.86,180],["lamp_ceiling",.5,.35,0]]},bath:{rows:[["back","center",["washbasin"]],["back","end",["wc"]],["front","start",["bathtub"]],["left","start",["washer"]]],spots:[["lamp_downlight",.5,.5,0]]},bedroom:{rows:[["back","center",["nightstand","bed","nightstand"]],["left","center",[["wardrobe",[2,.6,2.1]]]],["front","end",["dresser"]]],spots:[["lamp_ceiling",.5,.55,0]]},living:{rows:[["back","center",["tv_board"]],["right","start",["shelf"]]],spots:[["sofa",.5,.72,180],["coffee_table",.5,.52,0],[["rug",[2.2,1.6,.01]],.5,.55,0],["armchair",.14,.5,270],["lamp_floor",.86,.8,0],["plant",.9,.12,0],["lamp_ceiling",.5,.45,0]]},dining:{rows:[["back","center",["sideboard"]]],spots:[["table",.5,.55,0],["chair",.4,.35,0],["chair",.6,.35,0],["chair",.4,.75,180],["chair",.6,.75,180],["lamp_pendant",.5,.55,0]]},office:{rows:[["back","center",["desk"]],["left","center",["shelf","shelf"]]],spots:[["office_chair",.5,.38,180],["lamp_ceiling",.5,.55,0]]},kids:{rows:[["left","start",[["bed",[.9,2,.8]]]],["back","end",[["desk",[1.2,.6,.75]]]],["right","end",["shelf"]]],spots:[[["rug",[1.6,1.2,.01]],.55,.6,0],["lamp_ceiling",.5,.5,0]]},hall:{rows:[["left","start",["coat_rack"]]],spots:[["lamp_downlight",.5,.3,0],["lamp_downlight",.5,.7,0]]}},Xd=t=>typeof t=="string"?t:t[0],ri=t=>typeof t=="string"?et[t]:t[1],In=.05,gb=.02,Qd=t=>Math.round(t*1e3)/1e3;function _b(t,e,n,r){switch(e){case"back":return{x:t.x0+n,z:t.z0+r,turn:0};case"right":return{x:t.x1-r,z:t.z0+n,turn:90};case"front":return{x:t.x1-n,z:t.z1-r,turn:180};case"left":return{x:t.x0+r,z:t.z1-n,turn:270}}}function eu(t,e,n){let r=de(t.points),o=r.x1-r.x0,i=r.z1-r.z0,s=[],l=(a,c,d,u,[p,h,f])=>{s.push({id:n(),type:a,x:Qd(c),z:Qd(d),rotation:u,w:p,d:h,h:f,variant:null,entity:null,power:null})};for(let[a,c,d]of Yd[e].rows){let u=a==="back"||a==="front"?o:i,p=0,h=[];for(let g of d){if(p+ri(g)[0]>u-.1)break;h.push(g),p+=ri(g)[0]}let f=c==="start"?In:c==="end"?u-p-In:(u-p)/2;for(let g of h){let y=ri(g),b=_b(r,a,f+y[0]/2,y[1]/2+gb);l(Xd(g),b.x,b.z,b.turn,y),f+=y[0]}}for(let[a,c,d,u]of Yd[e].spots){let p=ri(a),h=(y,b,v)=>Math.min(v,Math.max(b,y)),f=h(r.x0+o*c,r.x0+p[0]/2+In,r.x1-p[0]/2-In),g=h(r.z0+i*d,r.z0+p[1]/2+In,r.z1-p[1]/2-In);l(Xd(a),f,g,u,p)}return s}var bb=30*Math.PI/180,tu=.05;function ea(t){let e=t.points.length;return t.points.map((n,r)=>{let o=t.points[(r+1)%e];return Math.hypot(o[0]-n[0],o[1]-n[1])})}function Vr(t){return ea(t).reduce((e,n)=>e+n,0)}function yb(t,e){let n=ea(t),r=0;for(let o=0;oh+f,0);if(o<3||!(i>0)||!(n>0))return null;let s=Math.min(n,i),l=(e%i+i)%i,a=0,c=0;for(;a=c+r[a];)c+=r[a],a++;let d=l-c,u=s,p=[];for(let h=0;h<=o&&u>1e-9;h++){let f=r[a]-d,g=Math.min(u,f);g>1e-9&&p.push({edge:a,t0:d,t1:d+g}),u-=g,d=0;let y=(a+1)%o;if(u>1e-9&&wb(t,a)>bb)break;a=y}for(;p.length>1&&p[0].t1-p[0].t01&&p[p.length-1].t1-p[p.length-1].t0({edge:h.edge,offset:(h.t0+h.t1)/2,width:h.t1-h.t0})):null}function Dn(t,e){let n=e[0];return n?{from:yb(t,n.edge)+n.offset-n.width/2,width:e.reduce((r,o)=>r+o.width,0)}:null}function It(t,e){return e.front?t.filter(n=>n.front===e.front):[e]}function na(t,e){let n=t.points.length,r=1/0,o=0,i=0;for(let s=0;sD("opening")){let s=ta(e,r,o);if(!s)return null;let l=It(t,n),a=new Set(l.map(h=>h.id)),c=s.length>1?l[0].front??`front-${l[0].id}`:null,d=s.map((h,f)=>({...n,id:f===0?l[0].id:i(),edge:h.edge,offset:h.offset,width:h.width,front:c})),u=[],p=!1;for(let h of t){if(!a.has(h.id)){u.push(h);continue}p||(u.push(...d),p=!0)}return u}var ia=globalThis,ra=ia.__nextfloorBuiltin?.de??{},oa=ia.__nextfloorBuiltin?.en??{};ia.__nextfloorBuiltin??={de:ra,en:oa};var vb=()=>typeof S=="object"&&S||{},kb=globalThis,xb=kb.__nextfloorTexts??=new Map;function $b(t){let e=t.toLowerCase().split("-")[0];return e!=="de"&&e!=="en"&&e in vb()?e:void 0}function nu(t){let e=$b(t),n=e===void 0?void 0:xb.get(e);return n instanceof Promise?void 0:n}function oi(t,e){return nu(t)?.[e]}function xe(t,e,n={}){let r=t?.language??navigator.language,o=r.startsWith("de"),i=(o?void 0:nu(r)?.[e])??(o?ra:oa)[e]??oa[e]??ra[e]??e;for(let[s,l]of Object.entries(n))i=i.replace(`{${s}}`,String(l));return i}function j(t,e,n=2){return e.toLocaleString(t?.language??void 0,{maximumFractionDigits:n})}var Me=se` +var S={cs:"4be67fcd522e",da:"0fe66a82bf2a",es:"bd89dffd1355",fi:"9a17bc084f56",fr:"6312d0f61ebf",hu:"27ba348531dc",it:"1b705e76dd00",nb:"c5ea24fb9ef6",nl:"b64142c67c2e",pl:"8527a4930402",pt:"31857a2d2277",ro:"e3cb5f449f0f",sk:"320611594db0",sl:"8071691ceda3",sv:"711b911ec8da",tr:"7c83ce1c3372",zh:"50518d9f494e"};var bo=globalThis,yo=bo.ShadowRoot&&(bo.ShadyCSS===void 0||bo.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,qi=Symbol(),Ll=new WeakMap,cr=class{constructor(e,n,r){if(this._$cssResult$=!0,r!==qi)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=e,this.t=n}get styleSheet(){let e=this.o,n=this.t;if(yo&&e===void 0){let r=n!==void 0&&n.length===1;r&&(e=Ll.get(n)),e===void 0&&((this.o=e=new CSSStyleSheet).replaceSync(this.cssText),r&&Ll.set(n,e))}return e}toString(){return this.cssText}},Cl=t=>new cr(typeof t=="string"?t:t+"",void 0,qi),se=(t,...e)=>{let n=t.length===1?t[0]:e.reduce((r,o,i)=>r+(s=>{if(s._$cssResult$===!0)return s.cssText;if(typeof s=="number")return s;throw Error("Value passed to 'css' function must be a 'css' function result: "+s+". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.")})(o)+t[i+1],t[0]);return new cr(n,t,qi)},Nl=(t,e)=>{if(yo)t.adoptedStyleSheets=e.map(n=>n instanceof CSSStyleSheet?n:n.styleSheet);else for(let n of e){let r=document.createElement("style"),o=bo.litNonce;o!==void 0&&r.setAttribute("nonce",o),r.textContent=n.cssText,t.appendChild(r)}},Yi=yo?t=>t:t=>t instanceof CSSStyleSheet?(e=>{let n="";for(let r of e.cssRules)n+=r.cssText;return Cl(n)})(t):t;var{is:Xg,defineProperty:Qg,getOwnPropertyDescriptor:Jg,getOwnPropertyNames:e_,getOwnPropertySymbols:t_,getPrototypeOf:n_}=Object,wo=globalThis,Bl=wo.trustedTypes,r_=Bl?Bl.emptyScript:"",o_=wo.reactiveElementPolyfillSupport,dr=(t,e)=>t,Xi={toAttribute(t,e){switch(e){case Boolean:t=t?r_:null;break;case Object:case Array:t=t==null?t:JSON.stringify(t)}return t},fromAttribute(t,e){let n=t;switch(e){case Boolean:n=t!==null;break;case Number:n=t===null?null:Number(t);break;case Object:case Array:try{n=JSON.parse(t)}catch{n=null}}return n}},Vl=(t,e)=>!Xg(t,e),Wl={attribute:!0,type:String,converter:Xi,reflect:!1,useDefault:!1,hasChanged:Vl};Symbol.metadata??=Symbol("metadata"),wo.litPropertyMetadata??=new WeakMap;var mt=class extends HTMLElement{static addInitializer(e){this._$Ei(),(this.l??=[]).push(e)}static get observedAttributes(){return this.finalize(),this._$Eh&&[...this._$Eh.keys()]}static createProperty(e,n=Wl){if(n.state&&(n.attribute=!1),this._$Ei(),this.prototype.hasOwnProperty(e)&&((n=Object.create(n)).wrapped=!0),this.elementProperties.set(e,n),!n.noAccessor){let r=Symbol(),o=this.getPropertyDescriptor(e,r,n);o!==void 0&&Qg(this.prototype,e,o)}}static getPropertyDescriptor(e,n,r){let{get:o,set:i}=Jg(this.prototype,e)??{get(){return this[n]},set(s){this[n]=s}};return{get:o,set(s){let l=o?.call(this);i?.call(this,s),this.requestUpdate(e,l,r)},configurable:!0,enumerable:!0}}static getPropertyOptions(e){return this.elementProperties.get(e)??Wl}static _$Ei(){if(this.hasOwnProperty(dr("elementProperties")))return;let e=n_(this);e.finalize(),e.l!==void 0&&(this.l=[...e.l]),this.elementProperties=new Map(e.elementProperties)}static finalize(){if(this.hasOwnProperty(dr("finalized")))return;if(this.finalized=!0,this._$Ei(),this.hasOwnProperty(dr("properties"))){let n=this.properties,r=[...e_(n),...t_(n)];for(let o of r)this.createProperty(o,n[o])}let e=this[Symbol.metadata];if(e!==null){let n=litPropertyMetadata.get(e);if(n!==void 0)for(let[r,o]of n)this.elementProperties.set(r,o)}this._$Eh=new Map;for(let[n,r]of this.elementProperties){let o=this._$Eu(n,r);o!==void 0&&this._$Eh.set(o,n)}this.elementStyles=this.finalizeStyles(this.styles)}static finalizeStyles(e){let n=[];if(Array.isArray(e)){let r=new Set(e.flat(1/0).reverse());for(let o of r)n.unshift(Yi(o))}else e!==void 0&&n.push(Yi(e));return n}static _$Eu(e,n){let r=n.attribute;return r===!1?void 0:typeof r=="string"?r:typeof e=="string"?e.toLowerCase():void 0}constructor(){super(),this._$Ep=void 0,this.isUpdatePending=!1,this.hasUpdated=!1,this._$Em=null,this._$Ev()}_$Ev(){this._$ES=new Promise(e=>this.enableUpdating=e),this._$AL=new Map,this._$E_(),this.requestUpdate(),this.constructor.l?.forEach(e=>e(this))}addController(e){(this._$EO??=new Set).add(e),this.renderRoot!==void 0&&this.isConnected&&e.hostConnected?.()}removeController(e){this._$EO?.delete(e)}_$E_(){let e=new Map,n=this.constructor.elementProperties;for(let r of n.keys())this.hasOwnProperty(r)&&(e.set(r,this[r]),delete this[r]);e.size>0&&(this._$Ep=e)}createRenderRoot(){let e=this.shadowRoot??this.attachShadow(this.constructor.shadowRootOptions);return Nl(e,this.constructor.elementStyles),e}connectedCallback(){this.renderRoot??=this.createRenderRoot(),this.enableUpdating(!0),this._$EO?.forEach(e=>e.hostConnected?.())}enableUpdating(e){}disconnectedCallback(){this._$EO?.forEach(e=>e.hostDisconnected?.())}attributeChangedCallback(e,n,r){this._$AK(e,r)}_$ET(e,n){let r=this.constructor.elementProperties.get(e),o=this.constructor._$Eu(e,r);if(o!==void 0&&r.reflect===!0){let i=(r.converter?.toAttribute!==void 0?r.converter:Xi).toAttribute(n,r.type);this._$Em=e,i==null?this.removeAttribute(o):this.setAttribute(o,i),this._$Em=null}}_$AK(e,n){let r=this.constructor,o=r._$Eh.get(e);if(o!==void 0&&this._$Em!==o){let i=r.getPropertyOptions(o),s=typeof i.converter=="function"?{fromAttribute:i.converter}:i.converter?.fromAttribute!==void 0?i.converter:Xi;this._$Em=o;let l=s.fromAttribute(n,i.type);this[o]=l??this._$Ej?.get(o)??l,this._$Em=null}}requestUpdate(e,n,r,o=!1,i){if(e!==void 0){let s=this.constructor;if(o===!1&&(i=this[e]),r??=s.getPropertyOptions(e),!((r.hasChanged??Vl)(i,n)||r.useDefault&&r.reflect&&i===this._$Ej?.get(e)&&!this.hasAttribute(s._$Eu(e,r))))return;this.C(e,n,r)}this.isUpdatePending===!1&&(this._$ES=this._$EP())}C(e,n,{useDefault:r,reflect:o,wrapped:i},s){r&&!(this._$Ej??=new Map).has(e)&&(this._$Ej.set(e,s??n??this[e]),i!==!0||s!==void 0)||(this._$AL.has(e)||(this.hasUpdated||r||(n=void 0),this._$AL.set(e,n)),o===!0&&this._$Em!==e&&(this._$Eq??=new Set).add(e))}async _$EP(){this.isUpdatePending=!0;try{await this._$ES}catch(n){Promise.reject(n)}let e=this.scheduleUpdate();return e!=null&&await e,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){if(!this.isUpdatePending)return;if(!this.hasUpdated){if(this.renderRoot??=this.createRenderRoot(),this._$Ep){for(let[o,i]of this._$Ep)this[o]=i;this._$Ep=void 0}let r=this.constructor.elementProperties;if(r.size>0)for(let[o,i]of r){let{wrapped:s}=i,l=this[o];s!==!0||this._$AL.has(o)||l===void 0||this.C(o,void 0,i,l)}}let e=!1,n=this._$AL;try{e=this.shouldUpdate(n),e?(this.willUpdate(n),this._$EO?.forEach(r=>r.hostUpdate?.()),this.update(n)):this._$EM()}catch(r){throw e=!1,this._$EM(),r}e&&this._$AE(n)}willUpdate(e){}_$AE(e){this._$EO?.forEach(n=>n.hostUpdated?.()),this.hasUpdated||(this.hasUpdated=!0,this.firstUpdated(e)),this.updated(e)}_$EM(){this._$AL=new Map,this.isUpdatePending=!1}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$ES}shouldUpdate(e){return!0}update(e){this._$Eq&&=this._$Eq.forEach(n=>this._$ET(n,this[n])),this._$EM()}updated(e){}firstUpdated(e){}};mt.elementStyles=[],mt.shadowRootOptions={mode:"open"},mt[dr("elementProperties")]=new Map,mt[dr("finalized")]=new Map,o_?.({ReactiveElement:mt}),(wo.reactiveElementVersions??=[]).push("2.1.2");var Ji=globalThis,Kl=t=>t,vo=Ji.trustedTypes,Gl=vo?vo.createPolicy("lit-html",{createHTML:t=>t}):void 0,es="$lit$",gt=`lit$${Math.random().toFixed(9).slice(2)}$`,ts="?"+gt,i_=`<${ts}>`,Ut=document,hr=()=>Ut.createComment(""),pr=t=>t===null||typeof t!="object"&&typeof t!="function",ns=Array.isArray,Xl=t=>ns(t)||typeof t?.[Symbol.iterator]=="function",Qi=`[ +\f\r]`,ur=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,jl=/-->/g,Ul=/>/g,Gt=RegExp(`>|${Qi}(?:([^\\s"'>=/]+)(${Qi}*=${Qi}*(?:[^ +\f\r"'\`<>=]|("|')|))|$)`,"g"),Zl=/'/g,ql=/"/g,Ql=/^(?:script|style|textarea|title)$/i,rs=t=>(e,...n)=>({_$litType$:t,strings:e,values:n}),m=rs(1),R=rs(2),Ak=rs(3),Qe=Symbol.for("lit-noChange"),_=Symbol.for("lit-nothing"),Yl=new WeakMap,jt=Ut.createTreeWalker(Ut,129);function Jl(t,e){if(!ns(t)||!t.hasOwnProperty("raw"))throw Error("invalid template strings array");return Gl!==void 0?Gl.createHTML(e):e}var ec=(t,e)=>{let n=t.length-1,r=[],o,i=e===2?"":e===3?"":"",s=ur;for(let l=0;l"?(s=o??ur,u=-1):d[1]===void 0?u=-2:(u=s.lastIndex-d[2].length,c=d[1],s=d[3]===void 0?Gt:d[3]==='"'?ql:Zl):s===ql||s===Zl?s=Gt:s===jl||s===Ul?s=ur:(s=Gt,o=void 0);let h=s===Gt&&t[l+1].startsWith("/>")?" ":"";i+=s===ur?a+i_:u>=0?(r.push(c),a.slice(0,u)+es+a.slice(u)+gt+h):a+gt+(u===-2?l:h)}return[Jl(t,i+(t[n]||"")+(e===2?"":e===3?"":"")),r]},fr=class t{constructor({strings:e,_$litType$:n},r){let o;this.parts=[];let i=0,s=0,l=e.length-1,a=this.parts,[c,d]=ec(e,n);if(this.el=t.createElement(c,r),jt.currentNode=this.el.content,n===2||n===3){let u=this.el.content.firstChild;u.replaceWith(...u.childNodes)}for(;(o=jt.nextNode())!==null&&a.length0){o.textContent=vo?vo.emptyScript:"";for(let h=0;h2||r[0]!==""||r[1]!==""?(this._$AH=Array(r.length-1).fill(new String),this.strings=r):this._$AH=_}_$AI(e,n=this,r,o){let i=this.strings,s=!1;if(i===void 0)e=Zt(this,e,n,0),s=!pr(e)||e!==this._$AH&&e!==Qe,s&&(this._$AH=e);else{let l=e,a,c;for(e=i[0],a=0;a{let r=n?.renderBefore??e,o=r._$litPart$;if(o===void 0){let i=n?.renderBefore??null;r._$litPart$=o=new yn(e.insertBefore(hr(),i),i,void 0,n??{})}return o._$AI(t),o};var os=globalThis,ne=class extends mt{constructor(){super(...arguments),this.renderOptions={host:this},this._$Do=void 0}createRenderRoot(){let e=super.createRenderRoot();return this.renderOptions.renderBefore??=e.firstChild,e}update(e){let n=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(e),this._$Do=nc(n,this.renderRoot,this.renderOptions)}connectedCallback(){super.connectedCallback(),this._$Do?.setConnected(!0)}disconnectedCallback(){super.disconnectedCallback(),this._$Do?.setConnected(!1)}render(){return Qe}};ne._$litElement$=!0,ne.finalized=!0,os.litElementHydrateSupport?.({LitElement:ne});var a_=os.litElementPolyfillSupport;a_?.({LitElement:ne});(os.litElementVersions??=[]).push("4.2.2");var Je=(t,e,n={})=>t.callWS({type:`nextfloor/${e}`,...n});async function Ro(t,e){return(await Je(t,"image/get",{image_id:e})).data}async function St(t,e,n){await Je(t,"image/set",{image_id:e,data:n})}async function rc(t){return(await Je(t,"history/list")).snapshots}async function oc(t,e){return(await Je(t,"history/snapshot",e?{name:e}:{})).id}async function ic(t,e){return(await Je(t,"history/get",{snapshot_id:e})).building}async function sc(t,e){await Je(t,"history/delete",{snapshot_id:e})}async function ac(t,e){return(await Je(t,"history/restore",{snapshot_id:e})).revision}var mr=(t,e)=>Je(t,"packs/import",{pack:e});async function lc(t,e){await Je(t,"packs/remove",{pack_id:e})}var cc=t=>Je(t,"backup/export"),dc=(t,e,n)=>Je(t,"backup/import",{building:e,packs:n});var ss=t=>t.slice(0,t.indexOf(".")),l_={light:"light",switch:"switch",input_boolean:"switch",valve:"switch",fan:"fan",cover:"cover",climate:"climate",media_player:"media",lock:"lock",sensor:"sensor",binary_sensor:"binary",event:"sensor",scene:"scene",script:"script"},X=t=>l_[ss(t)]??null,as=["light","cover","climate","media","switch","fan","lock","binary","sensor","scene","script"];var uc=new Set(["light","switch","fan"]),Mt=t=>t!==null&&t!=="scene"&&t!=="script",Rt=t=>!t||t.state==="unavailable"||t.state==="unknown"&&!t.entity_id.startsWith("event.");function W(t,e,n){let r=String(t?.states[e]?.attributes.friendly_name??t?.entities?.[e]?.name??e);if(!n||r.length<=n.length+1||!r.toLowerCase().startsWith(`${n.toLowerCase()} `))return r;let o=r.slice(n.length+1);return o[0].toUpperCase()+o.slice(1)}var hc=t=>!!t&&t.entity_id.startsWith("sensor.")&&t.attributes.device_class==="enum";var pc=t=>Math.min(1,Math.max(0,t));function c_(t){let e=pc((t-2200)/4300),n=[1,.66,.26],r=[.78,.9,1];return[0,1,2].map(o=>n[o]+(r[o]-n[o])*e)}function is(t,e){if(!t||t.state!=="on")return null;let n=e&&!["unavailable","unknown"].includes(e.state)?e.attributes:t.attributes,r=typeof n.brightness=="number"?.2+.8*Math.sqrt(pc(n.brightness/255)):1,o=n.rgb_color;return o&&!["color_temp","brightness","onoff"].includes(String(n.color_mode))?{color:[o[0]/255,o[1]/255,o[2]/255],level:r}:typeof n.color_temp_kelvin=="number"?{color:c_(n.color_temp_kelvin),level:r}:{color:[1,.71,.28],level:r}}function fc(t,e,n){let r=is(t,n);if(r)return r;for(let o of e){let i=is(o);if(i)return{color:i.color,level:i.level*.6}}return null}function Eo(t,e,n=null){if(t==="light"&&n==="floor")return 1.95;if(t==="light"&&n==="table")return 1.25;if(t==="light"&&n==="wall")return 1.95;switch(t){case"light":return Math.max(.5,e-.25);case"cover":return Math.min(2,e-.3);case"climate":return .6;case"media":return .9;case"binary":case"sensor":return 1.4;default:return 1.05}}var bc=[],Ao=new Map,d_=0,ue=(t,e)=>`pack:${t}:${e}`,_t=t=>t.startsWith("pack:");function ls(t){bc=t,Ao=new Map;for(let e of t)for(let n of e.items)Ao.set(ue(e.id,n.id),n);d_+=1}var _r=()=>bc;var u_={};function G(t){if(!_t(t))return;let e=Ao.get(t);if(e)return e;let[,n,...r]=t.split(":"),o=u_[n];return o?Ao.get(ue(o,r.join(":"))):void 0}var h_=.22;function mc(t,e,n,r){let o=Math.min(h_,n/3);if(r<=o*2.4||Math.abs(r-n)<1e-6)return e*(r/n)+(t-e)*(r/n);let i=e*(r/n),s=t-e;return s<=o?i+s:s>=n-o?i+r-(n-s):i+o+(s-o)*(r-2*o)/(n-2*o)}function gr(t,e,n,r,o){return[mc(t*r,n*r,r,o)/o,mc(e*r,n*r,r,o)/o]}var gc=new WeakMap;function yc(t,e,n,r){let[o,i,s]=t.size;if(t.vehicle||t.stretch||Math.abs(e-o)<1e-4&&Math.abs(n-i)<1e-4&&Math.abs(r-s)<1e-4)return t.parts;let l=`${e.toFixed(4)}|${n.toFixed(4)}|${r.toFixed(4)}`,a=gc.get(t),c=a?.get(l);if(c)return c;let d=t.parts.map(u=>{if(u.shape==="sweep")return u;let[p,h]=gr(u.x-u.w/2,u.x+u.w/2,-.5,o,e),[f,g]=gr(u.z-u.d/2,u.z+u.d/2,-.5,i,n),[y,b]=gr(u.y,u.y+u.h,0,s,r);if(u.rot)return{...u,x:(p+h)/2,z:(f+g)/2,w:u.w*o/e,d:u.d*i/n,y,h:b-y};let v={...u,x:(p+h)/2,z:(f+g)/2,w:h-p,d:g-f,y,h:b-y};if(u.shape==="loft"){let[w,x,k,$]=[u.tx??u.x,u.tz??u.z,u.tw??u.w,u.td??u.d],[A,F]=gr(w-k/2,w+k/2,-.5,o,e),[T,I]=gr(x-$/2,x+$/2,-.5,i,n);Object.assign(v,{tx:(A+F)/2,tz:(T+I)/2,tw:F-A,td:I-T})}return v});return a||gc.set(t,a=new Map),a.size>32&&a.clear(),a.set(l,d),d}var cs=t=>!!t?.parts.some(e=>e.move);var wc=t=>G(t)?.parts.find(e=>e.screen),_c=.06;function vc(t){let e=G(t);if(!e)return!1;let[n,r,o]=e.size;return e.parts.filter(i=>i.screen).some(i=>{let[s,l]=[i.w*n,i.d*r,i.h*o].sort((a,c)=>c-a);return l>=_c&&s>=_c})}function lt(t){return et[t]??G(t)?.size??[.6,.6,.8]}function Et(t){let e=G(t);return Ac.has(t)||!!e?.electric||!!e?.light||!!e?.climate}var kc=t=>!!G(t)?.parts.some(e=>e.picture),wn=t=>!!G(t)?.climate;function xc(t,e){return t.name[e.split("-")[0]]??t.name.en??Object.values(t.name)[0]??t.id}var p_={wohnen:"Living & Pets",kino:"Home Cinema & Gaming",kueche:"Kitchen Extras",bad:"Bathroom Extras",schlafen:"Bedroom & Kids",technik:"Office & Homelab",energie:"Energy & Building Services",garten:"Garden & Terrace (older)",fitness:"Fitness (older)",fahrzeuge:"Vehicles",ikea:"IKEA sizes",treppen:"Stairs & railings",ausbau:"Architecture & fit-out",werkstatt:"Garage & workshop",a_wohnzimmer:"Living room",a_schlafzimmer:"Bedroom",a_kueche:"Kitchen",a_bad:"Bathroom",a_kinderzimmer:"Kids' room",a_buero:"Office & gaming",a_fitness:"Fitness",a_haustiere:"Pets",a_garten:"Garden & patio",a_kino:"Home cinema & hi-fi",a_smart:"Smart home & tech",a_haustechnik:"Utility & building services",a_saison:"Season & decoration",a_smart2:"Smart home 2",a_haustechnik2:"Building services 2",a_wellness:"Wellness",a_garten2:"Garden 2",a_kueche2:"Kitchen 2",a_fahrzeuge2:"Vehicles 2",a_aussenkueche:"Outdoor kitchen & terrace",a_werkstatt2:"Workshop 2",a_japandi:"Japandi & Scandi",a_loft:"Loft & industrial",a_gruen:"Indoor greenery",a_musik:"Music & studio",a_bilder:"Pictures & frames"};function $c(t,e){if(e.split("-")[0]==="de")return t.name;let n=/^nextfloor\.(.+)$/.exec(t.id)?.[1];return n&&p_[n]||t.name}function At(t,e){return e.mount_y!=null?e.mount_y:m_(t,e)+(f_(e)?0:Rc(t,e.x,e.z))}var f_=t=>t.type==="led_strip"||G(t.type)?.mount==="ceiling";function m_(t,e){if(e.type==="lamp_wall")return Sc;if(e.type==="led_strip")return Math.max(0,ct(t,e.x,e.z)-.04-Math.max(.02,e.h));let n=G(e.type);if(!n)return Mc(e);switch(n.mount){case"surface":return Ec(t,e.x,e.z);case"wall":return n.wall_y??1;case"ceiling":return Math.max(0,Fo(t,e)-e.h);default:return 0}}function ds(t){if(t==="plant")return"plant";let e=G(t);return e?e.household?e.household:/monstera|plant|herb_garden|flower_pots|bonsai|ficus|cactus|kaktus/.test(e.id)?"plant":null:null}var Fc=["turn","slide","top"],Tc=["always","active","no_power","never"],zc=1.3,To=(t,e=new Date().toISOString().slice(0,10))=>!!t.due&&t.due<=e,Pc=["gable","hip","halfhip","pyramid","mansard","pent","flat","parapet"],Ic=["brick","round","wide","steel"],zo=["navigate","more_info","service","fire_dom_event"];function Po(t,e,n){return t?e?!!n.lock_plan:!!t.locked:!1}var Dc=["rain","snow","fog","clouds","lightning","sky"],Oc=["rain","snow","clouds","lightning","sky"],Hc=["lawn","terrace","path","driveway","pool","bed","wild","hedge","fence","pergola"],us={lawn:.012,terrace:.12,path:.02,driveway:.02,pool:-.25,bed:.15,wild:.03,hedge:1.2,fence:1,pergola:2.2};function hs(t){return t==="hedge"||t==="fence"||t==="pergola"}var Lc=["x","-x","z","-z"];function g_(t,e,n){let r=t.slope??0;if(!r||t.type==="pool")return 0;let o=t.slope_dir??"x",i=(c,d)=>o==="x"?c:o==="-x"?-c:o==="z"?d:-d,s=1/0,l=-1/0;for(let[c,d]of t.points){let u=i(c,d);s=Math.min(s,u),l=Math.max(l,u)}if(l-s<1e-6)return 0;let a=Math.min(1,Math.max(0,(i(e,n)-s)/(l-s)));return r*a}function __(t,e,n,r){return Cc(t)+(e.offset??0)+us[e.type]-g_(e,n,r)}function Cc(t){return t.elevation>.3?0:-.2}function Nc(t,e,n){let r=(t.outdoor??[]).filter(i=>!hs(i.type)&&i.type!=="pool"&&N([e,n],i.points)),o=[...r].reverse().find(i=>i.cut)??r[0];return o?__(t,o,e,n):Cc(t)}var Bc=t=>t.cut??t.type==="pool",Wc=30,Vc={meter:null,grid:null,grid_invert:!1,solar:null,battery:null,battery_invert:!1,battery_soc:null,consumption:null,tariff:null},Kc=["wood","oak","tiles","carpet","stone","concrete"],Gc={type:"none",pitch:35,overhang:.4},Io="#d6cfc2",Do="#e8e3da",jc={wall_exterior:.24,wall_interior:.12,grid:.05,north:0,roof:{...Gc}};function Ft(){return{version:1,floors:[],settings:{...jc},energy:{...Vc},presence:[]}}function Le(t,e,n){return{id:t,name:e,elevation:n,height:2.5,cut_height:1.15,rooms:[],openings:[],furniture:[],placements:[],background:null,outdoor:[],walls:[],ha_floor:null}}var b_=2.75;function Uc(t,e){if(e!=null&&Number.isFinite(e))return Math.round(e*b_*100)/100;let n=t.reduce((r,o)=>!r||o.elevation>r.elevation?o:r,null);return n?Math.round((n.elevation+n.height+.25)*100)/100:0}function Zc(t,e,n){let r=t.rooms.flatMap(l=>l.points.map(a=>a[0])),o=t.rooms.flatMap(l=>l.points.map(a=>a[1])),i=r.length?Math.ceil(Math.max(...r))+1:0,s=o.length?Math.floor(Math.min(...o)):0;return e.map((l,a)=>{let c=i+a%3*4.5,d=s+Math.floor(a/3)*3.5;return{id:n(),name:l.name,area_id:l.area_id,points:[[c,d],[c+4,d],[c+4,d+3],[c,d+3]],floor_material:"wood"}})}function qc(t,e,n,r){let o=t.rotation*Math.PI/180,i=Math.cos(o),s=Math.sin(o),[l,a]=e,c=t.x-l*(t.w/2)*i+a*(t.d/2)*s,d=t.z-l*(t.w/2)*s-a*(t.d/2)*i,u=n[0]-c,p=n[1]-d,h=b=>Math.max(.1,Math.round(b/r)*r),f=h((u*i+p*s)*l),g=h((-u*s+p*i)*a),y=b=>Math.round(b*1e3)/1e3;return{x:y(c+l*(f/2)*i-a*(g/2)*s),z:y(d+l*(f/2)*s+a*(g/2)*i),w:y(f),d:y(g)}}var Oo=["lamp_ceiling","lamp_downlight","lamp_spot","lamp_panel","lamp_pendant","ceiling_fan","lamp_floor","lamp_table","lamp_wall","led_strip","lamp_uplight","lamp_bollard","lamp_garden","radiator","sofa","armchair","stool","coffee_table","tv_board","tv_wall","sideboard","shelf","plant","rug","table","table_round","chair","bench","corner_bench","bar_stool","kitchen","kitchen_wall","kitchen_tall","island","worktop","sink","stove","dishwasher","fridge","bed","bunk_bed","nightstand","wardrobe","dresser","bathtub","shower","wc","washbasin","washer","dryer","desk","office_chair","tall_cabinet","coat_rack","stairs","robot_vacuum","inverter","home_battery","wallbox","meter","grid_point","parking","fridge_smart","stairwell"],Yc={lights:["lamp_ceiling","lamp_downlight","lamp_spot","lamp_panel","lamp_pendant","ceiling_fan","lamp_floor","lamp_uplight","lamp_table","lamp_wall","led_strip","lamp_bollard","lamp_garden"],living:["sofa","armchair","stool","coffee_table","tv_board","tv_wall","sideboard","shelf","plant","rug"],dining:["table","table_round","chair","bench","corner_bench","bar_stool"],kitchen:["kitchen","kitchen_wall","kitchen_tall","island","worktop","sink","stove","dishwasher","fridge"],sleeping:["bed","bunk_bed","nightstand","wardrobe","dresser"],bath:["bathtub","shower","wc","washbasin","washer","dryer"],work:["desk","worktop","office_chair","tall_cabinet","coat_rack","radiator","stairs","robot_vacuum"],vehicles:["parking"]},Ce=["meter","inverter","home_battery","wallbox","grid_point"],Xc=new Set(["lamp_ceiling","lamp_downlight","lamp_spot","lamp_panel","lamp_pendant","ceiling_fan","lamp_floor","lamp_uplight","lamp_table","lamp_wall","led_strip","lamp_bollard","lamp_garden"]),Sc=1.75;function Ho(t){return ps.has(t.type)||["stairwell","parking"].includes(t.type)?!1:G(t.type)?.mount!=="ceiling"}function ce(t){return Xc.has(t)||!!G(t)?.light}var y_=new Set(["table","table_round","coffee_table","desk","nightstand","sideboard","dresser","kitchen","island","worktop","tv_board","dishwasher","washer","dryer"]);function Qc(t,e,n,r=0){let o=de(t.points),i=o.x1-o.x0-2*r,s=o.z1-o.z0-2*r,l=[];for(let a=0;aMath.round(s*1e3)/1e3,[o,i]={right:[1,0],down:[0,1],left:[-1,0],up:[0,-1]}[n];return[r(t[0]+o*e),r(t[1]+i*e)]}function Mc(t){switch(t.type){case"home_battery":return t.variant==="wall"?.5:0;case"kitchen_wall":return 1.45;case"tv_wall":return Math.max(0,1.3-t.h/2);case"radiator":return .12;case"inverter":return 1.1;case"wallbox":return 1;case"meter":return .4;default:return 0}}var ps=new Set(["lamp_ceiling","lamp_downlight","lamp_spot","lamp_panel","lamp_pendant","ceiling_fan"]);function Jc(t,e){return t.filter(n=>n.elevationn.rooms.filter(r=>r.points.length>=3&&r.ceiling!=null&&r.ceiling>n.height+.005&&n.elevation+r.ceiling>e.elevation+.05)).map(n=>n.points)}var fs=t=>t?.floor_offset&&Number.isFinite(t.floor_offset)?t.floor_offset:0;function Rc(t,e,n){let r=t.rooms.find(o=>o.points.length>=3&&o.floor_offset&&N([e,n],o.points));return fs(r)}function ct(t,e,n){let r=t.rooms.find(o=>o.points.length>=3&&N([e,n],o.points));return r?.ceiling!=null&&r.ceiling>0?r.ceiling:t.height}var Fo=(t,e)=>e.ceiling_y!=null&&e.ceiling_y>0?e.ceiling_y:ct(t,e.x,e.z);function Ec(t,e,n){let r=0;for(let o of t.furniture)!(y_.has(o.type)||G(o.type)?.surface)||!N([e,n],bs(o))||(r=Math.max(r,o.h));return r}var Ac=new Set([...Xc,"radiator","robot_vacuum","inverter","home_battery","wallbox","meter","tv_board","tv_wall","desk","fridge","fridge_smart","stove","kitchen_tall","dishwasher","washer","dryer","kitchen","island","sink"]),et={sofa:[2.2,.9,.82],armchair:[.85,.85,.8],table:[1.6,.9,.75],chair:[.46,.5,.9],bed:[1.6,2.05,.9],nightstand:[.45,.4,.5],wardrobe:[1.8,.6,2.1],shelf:[.9,.35,1.9],kitchen:[2.4,.62,.92],worktop:[1.2,.62,.91],inverter:[.5,.2,.65],home_battery:[.6,.25,1.1],wallbox:[.3,.15,.42],meter:[.55,.21,1.1],grid_point:[.4,.22,.6],fridge:[.6,.65,1.8],fridge_smart:[.91,.73,1.78],stairwell:[1,2.6,.02],stove:[.6,.62,.92],sink:[.9,.62,.92],bathtub:[1.7,.75,.58],shower:[.9,.9,2],wc:[.38,.6,.8],washbasin:[.6,.46,.85],desk:[1.4,.7,.75],tv_board:[1.8,.42,.5],plant:[.45,.45,1.1],rug:[2,1.4,.01],stairs:[1,3.2,2.75],stool:[.55,.55,.42],lamp_ceiling:[.4,.4,.08],lamp_downlight:[.1,.1,.02],lamp_spot:[.1,.1,.14],lamp_panel:[.6,.6,.03],lamp_uplight:[.35,.35,1.8],lamp_bollard:[.16,.16,.8],lamp_garden:[.12,.12,.3],radiator:[1,.1,.6],robot_vacuum:[.36,.5,.1],parking:[2.6,5.2,.02],lamp_pendant:[.4,.4,.8],ceiling_fan:[1.32,1.32,.32],lamp_floor:[.4,.4,1.7],lamp_table:[.28,.28,.45],lamp_wall:[.22,.12,.2],led_strip:[2,.04,.03],coffee_table:[1.1,.6,.42],tv_wall:[1.3,.08,.75],sideboard:[1.6,.45,.8],table_round:[1.1,1.1,.75],bench:[1.4,.45,.85],corner_bench:[2,1.6,.9],bar_stool:[.42,.42,.75],kitchen_wall:[.8,.35,.7],kitchen_tall:[.6,.62,2.1],island:[1.8,.9,.92],dishwasher:[.6,.62,.92],bunk_bed:[1,2.05,1.65],dresser:[1,.5,.9],washer:[.6,.6,.85],dryer:[.6,.6,.85],office_chair:[.65,.65,1.1],tall_cabinet:[.6,.6,2.1],coat_rack:[1,.35,1.9]};var ms=["interior","front","front_glass","sidelight","sidelights","glass","sliding","passage"],gs=["standard","bars","glass_wall"],Lo=new Set(["interior","front"]);function Yt(t,e){return t.type==="door"?t.style&&ms.includes(t.style)?t.style:e?"front":"interior":t.style&&gs.includes(t.style)?t.style:"standard"}function ed(t,e,n,r){if(e!=="sidelight"&&e!=="sidelights")return null;let o=e==="sidelights",i=t-.04,s=Math.min(1.05,Math.max(.6,i-(o?.6:.3))),l=(i-s)/(o?2:1),a=r.sidelight_width??l,c=o?r.sidelight_width2??r.sidelight_width??l:0;a=Math.max(.1,a),c=o?Math.max(.1,c):0;let d=i-.5;if(a+c>d){let p=Math.max(0,d)/(a+c);a*=p,c*=p}return o?{panels:[[.02,.02+a],[t-.02-c,t-.02]],x0:.02+a,x1:t-.02-c}:(n?!!r.sidelight_hinge:!r.sidelight_hinge)?{panels:[[.02,.02+a]],x0:.02+a,x1:t-.02}:{panels:[[t-.02-a,t-.02]],x0:.02,x1:t-.02-a}}function _s(t){return t==="front"||t==="front_glass"||t==="sidelight"||t==="sidelights"}var kn={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 xn(t){if(t.type==="garage")return"garage";if(t.type==="window"&&t.style==="glass_wall")return"glass_wall";if(t.type==="window"&&t.opens==="slide"&&t.sill<.1)return"lift_slide";let e=t.leaves===2;return t.type==="door"?!e&&t.style&&_s(t.style)?"front":e?"door_double":"door":t.sill<.1?e?"terrace_double":"terrace":e?"window_double":"window"}function ze(t){t.energy={...Vc,...t.energy??{}},t.presence=t.presence??[],t.version=1,t.settings={...jc,...t.settings,roof:{...Gc,...t.settings?.roof??{}}},t.floors.forEach((e,n)=>{let r=Le(e.id,e.name??`Floor ${n+1}`,e.elevation??n*2.8);for(let o of Object.keys(r))e[o]===void 0&&(e[o]=r[o])});for(let e of t.floors){e.outdoor=e.outdoor??[],e.walls=e.walls??[],e.rooms=e.rooms.map(r=>({...r,name:r.name??"",area_id:r.area_id??null,floor_material:r.floor_material??"wood",panel:r.panel??[]})),e.ha_floor=e.ha_floor??null,e.placements=e.placements.map(r=>({...r,mount:r.mount??null,rotation:r.rotation??0})),e.furniture=e.furniture.map(r=>({...r,entity:r.entity??null,power:r.power??null}));let n=e.placements.filter(r=>r.entity_id.startsWith("light."));if(n.length){let r={ceiling:"lamp_ceiling",floor:"lamp_floor",table:"lamp_table",wall:"lamp_wall"};for(let o of n){let i=r[o.mount??"ceiling"],[s,l,a]=et[i],c=`lamp_${o.entity_id.slice(6).replace(/[^A-Za-z0-9_\-.]/g,"_")}`.slice(0,54),d=c,u=1;for(;e.furniture.some(p=>p.id===d);)d=`${c}_${u++}`;e.furniture.push({id:d,type:i,x:o.x,z:o.z,rotation:0,w:s,d:l,h:a,variant:null,entity:o.entity_id,power:null,animations_enabled:o.animations_enabled,effect_animations:structuredClone(o.effect_animations)})}e.placements=e.placements.filter(o=>!o.entity_id.startsWith("light."))}e.openings=e.openings.map(r=>({...r,type:["door","window","garage"].includes(r.type)?r.type:"door",edge:Number.isInteger(r.edge)?r.edge:0,offset:Number.isFinite(r.offset)?r.offset:.5,width:Number.isFinite(r.width)&&r.width>0?r.width:r.type==="garage"?2.5:r.type==="window"?1.2:.9,height:Number.isFinite(r.height)&&r.height>0?r.height:r.type==="window"?1.3:r.type==="garage"?2.1:2.05,sill:Number.isFinite(r.sill)?r.sill:r.type==="window"?.9:0,hinge:r.hinge??"left",leaves:r.leaves??1,swing:r.swing??"in",style:r.style??null,cover:r.cover??null,contact:r.contact??null,contact2:r.contact2??null,tilt:r.tilt??null}))}return w_(t),t}function w_(t){let e=(n,r)=>{let o=new Set;for(let i of n)(typeof i.id!="string"||!i.id||o.has(i.id))&&(i.id=D(r)),o.add(i.id)};e(t.floors,"floor");for(let n of t.floors){for(let r of n.rooms)(typeof r.id!="string"||!r.id)&&(r.id=D("room"));e(n.openings,"op"),e(n.furniture,"furn"),e(n.outdoor,"out")}}function D(t){return`${t}_${Math.random().toString(36).slice(2,10)}`}function ge(t){let e=0;for(let n=0;ni+s[0],0)/o,t.reduce((i,s)=>i+s[1],0)/o]}let n=0,r=0;for(let o=0;o1e-6&&Math.abs(r-i)>1e-6)return!1}return!0}function de(t){let e=1/0,n=1/0,r=-1/0,o=-1/0;for(let[i,s]of t)e=Math.min(e,i),n=Math.min(n,s),r=Math.max(r,i),o=Math.max(o,s);return{x0:e,z0:n,x1:r,z1:o}}function bs(t){let e=t.rotation*Math.PI/180,n=Math.cos(e),r=Math.sin(e),o=t.w/2,i=t.d/2;return[[-o,-i],[o,-i],[o,i],[-o,i]].map(([s,l])=>[t.x+s*n-l*r,t.z+s*r+l*n])}function N(t,e){let n=!1;for(let r=0,o=e.length-1;rt[1]!=a>t[1]&&t[0]<(l-i)*(t[1]-s)/(a-s)+i&&(n=!n)}return n}var Co={lamp_ceiling:"ceiling",lamp_downlight:"downlight",lamp_spot:"spot",lamp_panel:"panel",lamp_uplight:"uplight",lamp_bollard:"bollard",lamp_garden:"garden",lamp_pendant:"pendant",ceiling_fan:"fan",lamp_floor:"floor",lamp_table:"table",lamp_wall:"wall",led_strip:"strip"};var ys=t=>t.trim().replace(/^\/local\/www\//i,"/local/"),ws=t=>/^(https:\/\/|\/local\/|\/hacsfiles\/)\S+\.m?js(\?\S*)?$/i.test(t.trim());var k_=globalThis,nd=k_.__nextfloorPluginStore??={plugins:new Map,listeners:new Set},vs=nd.plugins,td=nd.listeners;var x_=5;function rd(t,e){t.errors.lengthtd.delete(t)}var ks=()=>[...vs.values()].map(t=>t.status),od=()=>[...vs.values()].flatMap(t=>Object.keys(t.plugin.lightAnimations??{}));function*Bo(t,e){for(let{plugin:n,status:r}of vs.values())for(let o of n.devices??[]){let i=!1;try{i=o.match(t,e)}catch(s){rd(r,s)}i&&(yield{device:o,status:r})}}function Wo(t,e){for(let{device:n}of Bo(t,e))return n.kind??"sensor";return null}function id(t,e){let n=t.states[e];if(!n)return null;let r=$_({hass:t,entityId:e,state:n})?.icon?.trim();return r&&/^mdi:[a-z0-9-]+$/i.test(r)?r:null}function $_(t){let e=null;for(let{device:n,status:r}of Bo(t.entityId,t.state))if(n.marker)try{let o=n.marker(t);if(!o)continue;e={...e??{}},typeof o.icon=="string"&&o.icon&&(e.icon=o.icon),typeof o.text=="string"&&(e.text=o.text.slice(0,60)),typeof o.active=="boolean"&&(e.active=o.active)}catch(o){rd(r,o)}return e}function Vo(t,e){return t?typeof t=="string"?t:t[e]??t[e.split("-")[0]]??t.en??Object.values(t)[0]??"":""}function sd(t,e){let n=[];for(let{device:r,status:o}of Bo(t,e))r.settings?.length&&n.push({pluginId:o.id,name:o.name,settings:r.settings});return n}function ad(t,e){let n={};for(let r of t??[]){let o=e?.[r.key],i=r.type==="number"?typeof o=="number"&&Number.isFinite(o):r.type==="boolean"?typeof o=="boolean":typeof o=="string"&&(r.options??[]).some(([s])=>s===o);n[r.key]=i?o:r.default}return n}function ld(t,e){for(let{device:n}of Bo(t,e))if(n.floorWedge)return!0;return!1}var S_=new Set(["temperature","humidity","power","carbon_dioxide","energy","gas","water","volume","volume_storage","volume_flow_rate","illuminance","pressure","atmospheric_pressure","pm1","pm25","pm10","volatile_organic_compounds","volatile_organic_compounds_parts","carbon_monoxide","nitrogen_dioxide","moisture","sound_pressure"]),M_=new Set(["m\xB3","m3","L","l","kWh","Wh","MWh","lx"]),R_=new Set(["door","window","opening","garage_door","motion","occupancy","presence","smoke","moisture","gas","carbon_monoxide"]),E_=new Set(["battery","signal_strength","timestamp","date","duration","data_rate","data_size","frequency","enum"]);function Tt(t,e){let n=t.entities?.[e];return n&&(n.area_id||(n.device_id?t.devices?.[n.device_id]?.area_id:null))||null}var dd=(t,e)=>{let n=t.entities?.[e];return!!(n?.hidden||n?.entity_category)},Ne=(t,e)=>X(e)??Wo(e,t.states[e]);function cd(t,e){let n=t.states[e];if(!n||dd(t,e))return!1;if(Wo(e,n)!==null)return!0;let r=X(e);if(!r)return!1;let o=n.attributes.device_class;return e.startsWith("event.")?!o||o==="button"||o==="doorbell":r==="sensor"?o?S_.has(o):M_.has(String(n.attributes.unit_of_measurement??"")):r==="binary"?o?R_.has(o):!!t.entities?.[e]?.area_id:!0}function A_(t,e){let n=t.states[e];return X(e)!=="sensor"||!n?.attributes.unit_of_measurement||dd(t,e)||E_.has(String(n.attributes.device_class??""))?!1:Number.isFinite(Number(n.state))||Rt(n)}var Go=(t,e)=>e.startsWith("sensor.")&&t.states[e]?.attributes.device_class==="power",xs=null;No(()=>xs=null);function $s(t,e){let n=t.get(e);return n||t.set(e,n=[]),n}function F_(t){let e=new Map,n=new Map,r=new Map,o=new Map,i=[],s=d=>{(cd(t,d)||A_(t,d))&&Mt(Ne(t,d))&&i.push(d)};for(let[d,u]of Object.entries(t.entities??{})){let p=u.device_id;p&&u.area_id&&(o.get(p)??o.set(p,new Set).get(p)).add(u.area_id),p&&Go(t,d)&&$s(n,p).push(d),p&&!u.hidden&&!u.entity_category&&(r.get(p)??r.set(p,new Set).get(p)).add(ss(d));let h=Tt(t,d);h===null?s(d):cd(t,d)&&$s(e,h).push(d)}if(t.entities)for(let d of Object.keys(t.states))t.entities[d]||s(d);let l=as.indexOf("binary")-.5,a=d=>{let u=X(d),p=u?as.indexOf(u):l;return p>l&&Wo(d,t.states[d])!==null?l:p};i.sort((d,u)=>a(d)-a(u)||W(t,d).localeCompare(W(t,u)));for(let[d,u]of e){let p=t.areas?.[d]?.name;u.sort((h,f)=>a(h)-a(f)||W(t,h,p).localeCompare(W(t,f,p)))}let c=new Set;for(let[d,u]of o)u.size>1&&c.add(d);return{entities:t.entities,devices:t.devices,states:t.states,stateCount:Object.keys(t.states).length,byArea:e,powerByDevice:n,withoutArea:i,domainsByDevice:r,hubs:c}}function Sn(t){let e=xs;return e&&e.entities===t.entities&&e.devices===t.devices&&(e.states===t.states||(e.states=t.states,Object.keys(t.states).length===e.stateCount))?e:xs=F_(t)}function be(t,e){let n=Ko(t,e.area_id);return e.sub_areas?.length?[...new Set([...n,...e.sub_areas.flatMap(r=>Ko(t,r))])]:n}function Ko(t,e){return!e||!t.entities?[]:Sn(t).byArea.get(e)??[]}function ud(t,e){if(!t.entities)return[];let n=[];for(let[r,o]of Sn(t).byArea){let i=o.filter(s=>Mt(Ne(t,s)));r!==e&&i.length>0&&n.push({areaId:r,name:t.areas?.[r]?.name??r,ids:i})}return n.sort((r,o)=>r.name.localeCompare(o.name))}var hd=t=>t.entities?Sn(t).withoutArea:[],Ss=(t,e)=>!!t.entities&&Sn(t).hubs.has(e),jo=(t,e)=>t.entities?Sn(t).powerByDevice.get(e)??[]:[];function Mn(t,e){let n=new Map;for(let o of e)$s(n,t.entities?.[o]?.device_id??`entity:${o}`).push(o);let r=new Map(e.map((o,i)=>[o,i]));return[...n.values()].map(o=>{let i=o.find(s=>!t.entities?.[s]?.name)??o[0];return{primary:i,others:o.filter(s=>s!==i)}}).sort((o,i)=>r.get(o.primary)-r.get(i.primary))}var Uo=(t,e)=>Mn(t,e).map(n=>n.primary),T_={temperature:"temperature",humidity:"humidity",co2:"carbon_dioxide"};function Ms(t,e,n){let r=t.states[e]?.attributes;if(!r||!((r.symcon_variable_type===1||r.symcon_variable_type===2)&&typeof r.symcon_id=="number")&&!/^(sensor|input_number|number)\./.test(e))return!1;let i=String(r.unit_of_measurement??"").replace(/\s/g,"").toLowerCase();return n==="temperature"&&["\xB0c","\xB0f","\u2103","\u2109","k"].includes(i)?!0:r.device_class===T_[n]}var z_=new Set(["climate","water_heater","switch","button","camera","media_player","vacuum","light","fan","lawn_mower"]),P_=["vorlauf","r(\xFC|ue)cklauf","flow","return","d(\xFC|ue)se","nozzle","hotend","extruder","druckbett","heatbed","(^|[^a-z])bed($|[^a-z])","chamber","cpu","gpu","chip","soc","akku","batter","wasser","water","kessel","boiler","au(\xDF|ss)en","outdoor","outside","abgas","exhaust","sole","brine","verdampfer","kondensat","verdichter","compressor","motor","k(\xFC|ue)hl","freezer","fridge","gefrier"],I_=new RegExp(`(${P_.join("|")})`,"i");function Rs(t,e){let n=t.entities?.[e]?.device_id,r=n&&!Ss(t,n)?Sn(t).domainsByDevice.get(n):void 0;return r&&[...r].some(o=>z_.has(o))?!1:!I_.test(`${e} ${t.states[e]?.attributes.friendly_name??""}`)}function pd(t,e,n,r){let o=n.climate?.[r];if(o==="none")return[];if(o)return[o].flat().filter(c=>t.states[c]);let i=(e?.placements??[]).filter(c=>c.entity_id.startsWith("sensor.")),s=i.filter(c=>N([c.x,c.z],n.points)).map(c=>c.entity_id),l=new Set(i.filter(c=>!N([c.x,c.z],n.points)).map(c=>c.entity_id));return[...new Set([...be(t,n).filter(c=>!l.has(c)),...s])].filter(c=>c.startsWith("sensor.")&&Ms(t,c,r)&&Rs(t,c))}var D_=new Set([void 0,"shutter","blind","awning","shade","curtain","window"]),O_=new Set(["garage","gate"]),H_=new Set(["window","opening"]);function br(t,e,n=!1){let r=new Map;return t.forEach((o,i)=>{let s=n&&e.length===1?e[0]:e[i];s&&r.set(o.id,s)}),r}var fd=(t,e)=>t==="none"?null:t??e??null,zt=t=>t&&t!=="none"?t:null;function Rn(t,e){let n=new Map;for(let r of e)for(let o of r.rooms){let i=r.openings.filter(g=>g.room_id===o.id).sort((g,y)=>g.edge-y.edge||g.offset-y.offset);if(i.length===0)continue;let s=be(t,o),l=g=>t.states[g]?.attributes.device_class,a=g=>s.filter(y=>X(y)==="binary"&&g(l(y)??"")),c=g=>i.filter(y=>y.type===g),d=br(c("window"),s.filter(g=>X(g)==="cover"&&D_.has(l(g))),!0),u=br(c("window"),a(g=>H_.has(g))),p=br(c("door"),a(g=>g==="door")),h=br(c("garage"),s.filter(g=>X(g)==="cover"&&O_.has(l(g)??""))),f=br(c("garage"),a(g=>g==="garage_door"));for(let g of i){let y=g.type==="window"?d:g.type==="garage"?h:null,b=g.type==="window"?u:g.type==="garage"?f:p,v=g.leaves===2;n.set(g.id,{cover:fd(g.cover,y?.get(g.id)),contact:g.sensor==="handle"&&g.contact==null?null:fd(g.contact,b.get(g.id)),tilt:g.tilt==="none"?null:g.tilt,contact2:v?zt(g.contact2):null,tilt2:v?zt(g.tilt2):null,position:zt(g.position),positionInverted:!!g.position_inverted,tiltAngle:zt(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"?zt(g.lock):null,cover2:g.type==="garage"?null:zt(g.cover2),coverTilt:zt(g.cover_tilt),cover2Tilt:zt(g.cover2_tilt)})}}return n}var L_=[[/^(tilted|tilt|gekippt|kipp)/i,"tilted"],[/^(open|opened|offen|geöffnet|on)$/i,"open"],[/^(closed|close|geschlossen|zu|off)$/i,"closed"]];function Es(t){if(!t||Rt(t))return null;let e=t.attributes.window_state;for(let n of[typeof e=="string"?e:"",t.state]){let r=n.trim(),o=r&&L_.find(([i])=>i.test(r));if(o)return o[1]}return null}var md=/\b(tv|fernseh|television|fire ?tv|apple ?tv|chromecast|shield)/i,gd=/(kühl|fridge|gefrier|freezer)/i,_d=/(spülmaschine|geschirrspül|dishwasher)/i,C_=/(kochfeld|herd|induktion|cooktop)/i,N_={robot_vacuum:/(saug|vacuum|robo|roomba|roborock|dreame|ecovacs|deebot)/i,tv_board:md,tv_wall:md,desk:/\b(pc|computer|rechner|desktop|monitor|workstation)/i,fridge:gd,fridge_smart:gd,stove:/(herd|kochfeld|cooktop|stove|induktion)/i,kitchen_tall:/(backofen|oven|ofen)/i,dishwasher:_d,washer:/(waschmaschine|washer|washing)/i,dryer:/(trockner|dryer)/i,kitchen:/(kaffee|coffee|wasserkocher|kettle)/i,island:C_,sink:_d,radiator:/(heiz|radiator|thermostat|climate|hk|trv)/i},bd={lamp_ceiling:/(decke|ceiling|haupt|main)/i,lamp_downlight:/(spot|strahler|downlight|einbau)/i,lamp_spot:/(spot|strahler)/i,lamp_panel:/(panel|decke|ceiling)/i,lamp_uplight:/(fluter|uplight|steh)/i,lamp_bollard:/(weg|garten|garden|path|poller|außen|aussen|outdoor)/i,lamp_garden:/(garten|garden|spot|außen|aussen|outdoor|baum|tree)/i,lamp_pendant:/(pendel|pendant|hänge|esstisch|dining)/i,ceiling_fan:/(ventilator|fan)/i,lamp_floor:/(steh|floor)/i,lamp_table:/(tisch|nacht|table|bedside|lese|reading)/i,lamp_wall:/(wand|wall)/i,led_strip:/(led|strip|streifen|leiste|band)/i},yd=new Set(["tv_board","tv_wall"]);var En=t=>yd.has(t)||!!wc(t),Zo=t=>!!G(t)?.electric&&/speaker|multiroom|soundbar/.test(t.split(":").pop()??t),wr=t=>En(t)||t==="desk"||t==="fridge_smart",B_=t=>!!t&&t!=="none";function W_(t,e){if(Go(t,e))return e;let n=t.entities?.[e]?.device_id;return n?jo(t,n).find(r=>r!==e)??null:null}var V_=(t,e,n)=>t.rooms.find(r=>r.points.length>=3&&N([e,n],r.points));function yr(t,e,n,r){return t.find(o=>e?.test(n(o)))??(r?t[0]??null:null)}function Be(t,e){let n=new Map;for(let r of e){let o=new Set([...r.furniture.flatMap(i=>[i.entity,i.power,i.fan_entity]),...r.placements.map(i=>i.entity_id)].filter(B_));for(let i of r.furniture){let s=i.type in bd,l=wn(i.type),a=s?bd[i.type]:N_[i.type];if(!a&&!l&&!Zo(i.type)&&i.entity==null&&i.power==null)continue;let c=V_(r,i.x,i.z),d=(c?Uo(t,be(t,c)):[]).filter(y=>!o.has(y)),u=y=>`${y} ${W(t,y)}`,p=y=>d.filter(b=>X(b)===y),h=i.entity==="none"?null:i.entity??null;if(i.entity==null){if(i.type==="ceiling_fan"){let y=(c?be(t,c):[]).filter(v=>!o.has(v)),b=new Set(y.filter(v=>X(v)==="fan").map(v=>t.entities?.[v]?.device_id).filter(Boolean));h=y.find(v=>X(v)==="light"&&b.has(t.entities?.[v]?.device_id))??yr(p("light"),a,u,!1)}else if(s)h=yr(p("light"),a,u,!0);else if(i.type==="robot_vacuum"){let y=c?.area_id??null;h=Object.keys(t.entities??{}).find(b=>b.startsWith("vacuum.")&&!o.has(b)&&Tt(t,b)===y)??null}else if(i.type==="radiator"||l)h=yr(p("climate"),a,u,!0);else if(En(i.type)){let y=p("media");h=y.find(b=>t.states[b]?.attributes.device_class==="tv")??yr(y,a,u,yd.has(i.type))}else if(Zo(i.type)){let y=p("media").filter(b=>t.states[b]?.attributes.device_class!=="tv");h=yr(y,a,u,!1)??(y.length===1?y[0]:null)}else a&&(h=d.find(y=>["switch","media","fan"].includes(X(y)??"")&&a.test(u(y)))??null);h&&o.add(h)}let f=i.power==="none"?null:i.power??null;i.power==null&&(f=h?W_(t,h):null,!f&&a&&c&&!s&&(f=be(t,c).find(y=>Go(t,y)&&!o.has(y)&&a.test(u(y)))??null),f&&o.add(f));let g=null;if(i.type==="ceiling_fan"&&(g=i.fan_entity==="none"?null:i.fan_entity??null,i.fan_entity==null)){let y=(c?be(t,c):[]).filter(v=>X(v)==="fan"&&!o.has(v)),b=h?t.entities?.[h]?.device_id:void 0;g=(b?y.find(v=>t.entities?.[v]?.device_id===b):void 0)??y[0]??null,g&&o.add(g)}(h||f||g)&&n.set(i.id,{entity:h,power:f,...i.type==="ceiling_fan"?{fan:g}:{}})}}return n}var wd=t=>t==="fridge"||t==="fridge_smart"||/(fridge|freezer|kuehl|gefrier|chest_freezer)/.test(t.slice(t.lastIndexOf(":")+1));function vd(t,e,n=[]){let r=[];for(let o of e){let i=(l,a)=>o.rooms.some(c=>c.points.length>=3&&N([l,a],c.points)),s=Be(t,[o]);r.push(...o.placements.filter(l=>l.outside||!i(l.x,l.z)).map(l=>l.entity_id)),r.push(...o.furniture.filter(l=>!i(l.x,l.z)).flatMap(l=>[s.get(l.id)?.entity,s.get(l.id)?.power]));for(let l of o.outdoor??[])l.area_id&&r.push(...Uo(t,Ko(t,l.area_id))),r.push(l.pump_entity,l.temp_entity)}return[...new Set(r.filter(o=>!!o&&!!t.states[o]&&!n.includes(o)))]}function K_(t,e){return Math.min(...e.map((n,r)=>{let o=e[(r+1)%e.length],[i,s]=[o[0]-n[0],o[1]-n[1]],l=Math.min(1,Math.max(0,((t[0]-n[0])*i+(t[1]-n[1])*s)/(i*i+s*s||1)));return Math.hypot(t[0]-n[0]-i*l,t[1]-n[1]-s*l)}))}function xd(t,e,n=[]){let r=t.points;if(r.length<3||e.length===0)return[];let o=r.map(b=>b[0]),i=r.map(b=>b[1]),[s,l,a,c]=[Math.min(...o),Math.max(...o),Math.min(...i),Math.max(...i)],d=Math.min(l-s,c-a),u=Math.max(.1,Math.min(.25,d/8)),p=Math.min(.35,d/5),h=Math.min(.7,d/4),f=_e(r),g=[];for(let b=s+u/2;b=p&&g.push({at:w,wallDistance:x})}g.length===0&&g.push({at:f,wallDistance:0});let y=[...n];return e.map(b=>{let v=X(b)==="light",w=g[0].at,x=-1/0;for(let{at:$,wallDistance:A}of g){let F=y.length?Math.min(...y.map(z=>Math.hypot($[0]-z[0],$[1]-z[1]))):3,T=Math.hypot($[0]-f[0],$[1]-f[1]),I=Math.min(F,3)*2;Tx+1e-9&&(x=I,w=$)}let k=[Math.round(w[0]*100)/100,Math.round(w[1]*100)/100];return y.push(k),{entity_id:b,x:k[0],z:k[1],y:null,mount:null}})}var kd=/(^|_)(current_room|current_segment|aktueller_raum|current_area)($|_)/;function $d(t,e,n){if(n==="none")return null;if(n)return n;let r=e?t.entities?.[e]?.device_id:null;return!r||!t.entities?null:Object.values(t.entities).find(i=>i.device_id===r&&i.entity_id.startsWith("sensor.")&&(kd.test(i.translation_key??"")||kd.test(i.entity_id.split(".")[1])))?.entity_id??null}var K=(t,e)=>[t[0]-e[0],t[1]-e[1]],dt=(t,e)=>[t[0]+e[0],t[1]+e[1]],tt=(t,e)=>[t[0]*e,t[1]*e],Q=(t,e)=>t[0]*e[0]+t[1]*e[1],$e=(t,e)=>t[0]*e[1]-t[1]*e[0],fe=t=>Math.hypot(t[0],t[1]),nt=t=>{let e=fe(t)||1;return[t[0]/e,t[1]/e]},As=t=>[-t[1],t[0]],Fs=t=>[t[1],-t[0]];var G_=.05,j_=.2,U_=.12;function Z_(t){let e=[];return t.forEach((n,r)=>{let o=n.points;if(o.length<3)return;let i=ge(o)>=0;o.forEach((s,l)=>{let a=o[(l+1)%o.length],c=fe(K(a,s));if(c<.05)return;let d=[(a[0]-s[0])/c,(a[1]-s[1])/c],u=i?[d[1],-d[0]]:[-d[1],d[0]];(d[1]<-1e-9||Math.abs(d[1])<=1e-9&&d[0]<0)&&(d=[-d[0],-d[1]]);let p=[-d[1],d[0]],[h,f]=[Q(s,d),Q(a,d)];e.push({room:r,index:l,dir:d,normal:p,offset:Q(s,p),outside:Q(u,p)>0?1:-1,from:Math.min(h,f),to:Math.max(h,f)})})}),e}function q_(t,e,n){if(t.room===e.room||Math.abs($e(t.dir,e.dir))>G_||t.outside===e.outside)return null;let r=(e.offset-t.offset)*t.outside;return r>n||r<-U_||Math.abs(r)<1e-4||Math.min(t.to,e.to)-Math.max(t.from,e.from)Math.round(t*1e3)/1e3;function Sd(t,e=.6){let n=Z_(t),r=n.map((g,y)=>y),o=g=>r[g]===g?g:r[g]=o(r[g]),i=[],s=new Set,l=[];for(let g=0;gMath.abs(g[2])-Math.abs(y[2]));let a=new Map(n.map((g,y)=>[y,[y]])),c=(g,y)=>g.some(b=>y.some(v=>n[b].room===n[v].room&&Math.abs(n[b].offset-n[v].offset)>=.002));for(let[g,y,b]of l){let[v,w]=[o(g),o(y)];if(v!==w){if(c(a.get(v),a.get(w)))continue;r[v]=w,a.set(w,[...a.get(w),...a.get(v)]),a.delete(v)}i.push(Ts(b)),s.add(g).add(y)}let d=new Map(n.map((g,y)=>[`${g.room}:${g.index}`,y]));for(let g=s.size>0;g;)g=!1,n.forEach((y,b)=>{let v=d.get(`${y.room}:${(y.index+1)%t[y.room].points.length}`);if(v===void 0||v===b)return;let w=n[v];!(Math.abs($e(y.dir,w.dir))<1e-6&&Math.abs(y.offset-w.offset)<.002&&y.outside===w.outside)||s.has(b)===s.has(v)||(s.add(b).add(v),g=!0)});n.forEach((g,y)=>{let b=d.get(`${g.room}:${(g.index+1)%t[g.room].points.length}`);if(b===void 0||b===y||!s.has(y)||!s.has(b))return;let v=n[b];Math.abs($e(g.dir,v.dir))<1e-6&&Math.abs(g.offset-v.offset)<.002&&g.outside===v.outside&&(r[o(y)]=o(b))});let u=()=>t.map(g=>({...g,points:g.points.map(y=>[y[0],y[1]])}));if(i.length===0)return{rooms:u(),gaps:i};let p=new Map;for(let g of s)p.set(o(g),[...p.get(o(g))??[],g]);let h=t.map(g=>g.points.map(()=>new Map));for(let[g,y]of p){let b=new Map(y.map(w=>[`${n[w].room}:${Math.round(n[w].offset*500)}`,n[w].offset])),v=[...b.values()].reduce((w,x)=>w+x,0)/b.size;for(let w of y){let x=n[w],k=[x.normal[0]*(v-x.offset),x.normal[1]*(v-x.offset)];h[x.room][x.index].set(g,k),h[x.room][(x.index+1)%t[x.room].points.length].set(g,k)}}return{rooms:t.map((g,y)=>({...g,points:g.points.map((b,v)=>{let w=[...h[y][v].values()].reduce((x,k)=>[x[0]+k[0],x[1]+k[1]],[b[0],b[1]]);return[Ts(w[0]),Ts(w[1])]})})),gaps:i}}function Md(t){let e=t.filter(n=>n>.04).sort((n,r)=>n-r);return e.length===0?null:Math.min(.5,Math.max(.08,Math.round(e[Math.floor(e.length/2)]*100)/100))}var Y_=.25,Rd=t=>Math.round(t*1e3)/1e3,Ed=(t,e,n)=>t.rooms.find(r=>r.points.length>=3&&N([e,n],r.points));function Ps(t,e,n,r,o){let i=Ed(t,e,n);if(!i)return[r,o];let s=(l,a)=>N([l,a],i.points);return s(r,o)?[r,o]:s(r,n)?[r,n]:s(e,o)?[e,o]:[e,n]}function X_(t,e,n,r){return t.rooms.some(o=>o.id!==e.id&&o.points.some((i,s)=>{let l=o.points[(s+1)%o.points.length];return Math.abs(Q(K(i,n),r))<.02&&Math.abs(Q(K(l,n),r))<.02}))}var zs=(t,e)=>Math.abs((t-e+540)%360-180);function vr(t,e,n,r=Y_){let o=Ed(t,e.x,e.z);if(!o)return null;let i=o.points,s=ge(i)>=0?1:-1,l=null;return i.forEach((a,c)=>{let d=i[(c+1)%i.length],u=fe(K(d,a));if(u<.3)return;let p=[(d[0]-a[0])/u,(d[1]-a[1])/u],h=[-p[1]*s,p[0]*s],f=Q(K([e.x,e.z],a),p);if(f<0||f>u)return;let g=X_(t,o,a,h)?n/2:0,y=Q(K([e.x,e.z],a),h)-g,b=Math.atan2(-h[0],h[1])*180/Math.PI,w=[{rotation:b,extent:e.d/2},{rotation:b+90,extent:e.w/2},{rotation:b-90,extent:e.w/2}].reduce((k,$)=>zs(e.rotation,$.rotation)50)return;let x=y-w.extent;Math.abs(x)>r||l&&Math.abs(x)>=Math.abs(l.gap)||(l={x:Rd(e.x-h[0]*x),z:Rd(e.z-h[1]*x),rotation:(Math.round(w.rotation)%360+360)%360,gap:x})}),l&&{x:l.x,z:l.z,rotation:l.rotation}}var An=Math.PI/180,rt=t=>Math.tan(Math.min(80,Math.max(0,t))*An);function xr(t){return{x0:Math.min(t.x0,t.x1),x1:Math.max(t.x0,t.x1),z0:Math.min(t.z0,t.z1),z1:Math.max(t.z0,t.z1)}}function Ad(t){if(!t.rotation)return null;let e=t.rotation*An;return{cx:(t.x0+t.x1)/2,cz:(t.z0+t.z1)/2,c:Math.cos(e),sn:Math.sin(e)}}function Fd(t,e){let n=Ad(t);if(!n)return e;let[r,o]=[e[0]-n.cx,e[1]-n.cz];return[n.cx+r*n.c-o*n.sn,n.cz+r*n.sn+o*n.c]}function Is(t,e,n){let r=Ad(t);if(!r)return[e,n];let[o,i]=[e-r.cx,n-r.cz];return[r.cx+o*r.c+i*r.sn,r.cz-o*r.sn+i*r.c]}function $r(t,e=0){let{x0:n,x1:r,z0:o,z1:i}=xr(t);return[[n-e,o-e],[r+e,o-e],[r+e,i+e],[n-e,i+e]].map(s=>Fd(t,s))}function ve(t){let{x0:e,x1:n,z0:r,z1:o}=xr(t),i=s=>Fd(t,s);return t.axis==="x"?{u0:e,u1:n,w:o-r,at:(s,l)=>i([s,t.flip?o-l:r+l])}:{u0:r,u1:o,w:n-e,at:(s,l)=>i([t.flip?n-l:e+l,s])}}function Sr(t,e,n){let{x0:r,x1:o,z0:i,z1:s}=xr(t),[l,a]=Is(t,e,n);return t.axis==="x"?[l,t.flip?s-a:a-i]:[a,t.flip?o-l:l-r]}var kr=Math.tan(30*An);function Mr(t,e,n,r,o){let i=Math.min(t*.3,r>1e-6?2.4/r:t*.3),s=Math.min(t*.3,o>1e-6?2.4/o:t*.3),l=e+i*r,a=n+s*o,c=Math.min(t-s,Math.max(i,(a-l+kr*(t-s+i))/(2*kr))),d=l+(c-i)*kr;return{vla:i,vlb:s,yla:l,ylb:a,vr:c,rh:d,y:p=>p<=i?e+p*r:p<=c?l+(p-i)*kr:p<=t-s?a+(t-s-p)*kr:n+(t-p)*o}}function Pe(t){let e=ve(t).w,[n,r]=[t.eave_a,t.eave_b],[o,i]=[rt(t.pitch_a),rt(t.pitch_b)];switch(t.shape){case"flat":case"parapet":return{vr:e/2,rh:n,y:()=>n};case"pent":return{vr:e,rh:n+e*o,y:s=>n+s*o};case"mansard":{let s=Mr(e,n,r,o,i);return{vr:s.vr,rh:s.rh,y:s.y}}default:{let s=o+i>1e-6?Math.min(e,Math.max(0,(r-n+e*i)/(o+i))):e/2;return{vr:s,rh:n+s*o,y:l=>l<=s?n+l*o:r+(e-l)*i}}}}var Xt=t=>Pe(t).rh;function Td(t){let e=t.heightEnd!==void 0;return{...t,a:t.b,b:t.a,left:t.right,right:t.left,roomLeft:t.roomRight,roomRight:t.roomLeft,height:e?t.heightEnd:t.height,heightEnd:e?t.height:void 0}}function Q_(t,e){let n=t.map(r=>({...r}));for(let r of e){let o=n.find(i=>i.room_id===r.room_id&&i.edge===r.edge&&(Math.abs(i.t1-r.t0)<1e-6||Math.abs(r.t1-i.t0)<1e-6));o?(o.t0=Math.min(o.t0,r.t0),o.t1=Math.max(o.t1,r.t1)):n.push({...r})}return n}function J_(t,e,n){if(t.a===e.b)return!1;let r=nt(K(n[t.b],n[t.a])),o=nt(K(n[e.b],n[e.a]));return Math.abs($e(r,o))>1e-6||Q(r,o)<=0||t.free||e.free||t.heightEnd!==void 0||e.heightEnd!==void 0?!1:t.height===e.height&&t.exterior===e.exterior&&t.roomLeft===e.roomLeft&&t.roomRight===e.roomRight&&Math.abs(t.left-e.left)<=1e-9&&Math.abs(t.right-e.right)<=1e-9}function zd(t,e,n=new Set){let r=t.slice();for(;;){let o=new Map;r.forEach((s,l)=>{for(let a of[s.a,s.b])o.set(a,[...o.get(a)??[],l])});let i=null;for(let[s,l]of o){if(l.length!==2||n.has(s))continue;let a=r[l[0]].b===s?r[l[0]]:Td(r[l[0]]),c=r[l[1]].a===s?r[l[1]]:Td(r[l[1]]);if(!J_(a,c,e))continue;let d={...a,b:c.b,sources:Q_(a.sources,c.sources)};i=[...r.filter((u,p)=>p!==l[0]&&p!==l[1]),d];break}if(!i)return r;r=i}}function Pd(t,e){let n=new Map;t.forEach((o,i)=>{let s=nt(K(e[o.b],e[o.a])),l=[[o.a,{key:`${i}:a`,d:s,left:o.left,right:o.right,angle:Math.atan2(s[1],s[0])}],[o.b,{key:`${i}:b`,d:tt(s,-1),left:o.right,right:o.left,angle:Math.atan2(-s[1],-s[0])}]];for(let[a,c]of l)n.set(a,[...n.get(a)??[],c])});let r=new Map;for(let[o,i]of n){let s=e[o];i.sort((a,c)=>a.angle-c.angle);for(let a of i)r.set(a.key,{left:dt(s,tt(As(a.d),a.left)),right:dt(s,tt(Fs(a.d),a.right))});if(i.length<2)continue;let l=4*Math.max(...i.map(a=>Math.max(a.left,a.right)))+1e-9;i.forEach((a,c)=>{let d=i[(c+1)%i.length],u=dt(s,tt(As(a.d),a.left)),p=dt(s,tt(Fs(d.d),d.right)),h=$e(a.d,d.d);if(Math.abs(h)<1e-4)return;let f=dt(u,tt(a.d,$e(K(p,u),d.d)/h));fe(K(f,s))>l||(r.get(a.key).left=f,r.get(d.key).right=f)})}return r}function Id(t,e){let n=t.filter((r,o)=>fe(K(r,t[(o+1)%t.length]))>e);for(;;){if(n.length<=3)return n;let r=n.findIndex((o,i)=>{let s=n[(i+n.length-1)%n.length],l=n[(i+1)%n.length],[a,c]=[K(o,s),K(l,o)];return Math.abs($e(nt(a),nt(c)))<1e-7&&Q(a,c)>0});if(r===-1)return n;n=n.filter((o,i)=>i!==r)}}function eb(t){let e=[];return{points:e,idOf(n){let r=e.findIndex(o=>Math.abs(o[0]-n[0])<=t&&Math.abs(o[1]-n[1])<=t);return r>=0?r:(e.push([n[0],n[1]]),e.length-1)}}}function tb(t,e){let n=[];for(let r of t){let o=r.points;if(o.length<3||Math.abs(ge(o))<1e-6)continue;let i=ge(o)>0,s=o.map(l=>e.idOf(l));s.forEach((l,a)=>{let c=s[(a+1)%s.length];l!==c&&n.push(i?{u:l,v:c,room:r.id,edge:a,forward:!0}:{u:c,v:l,room:r.id,edge:a,forward:!1})})}return n}function nb(t,e,n){let r=[];for(let o of t){let[i,s]=[e[o.u],e[o.v]],l=K(s,i),a=fe(l),c=tt(l,1/a),d=e.map((p,h)=>({id:h,rel:K(p,i)})).filter(({id:p,rel:h})=>p!==o.u&&p!==o.v&&Q(h,c)>n&&Q(h,c)({t:Q(h,c),id:p})).sort((p,h)=>p.t-h.t),u=[{t:0,id:o.u},...d,{t:a,id:o.v}];for(let p=0;p+1({room_id:t.room,edge:t.edge,t0:t.t0,t1:t.t1});function rb(t,e){let n=new Map(t.map(l=>[l.id,l])),r=new Map;for(let l of e){let a=`${l.room}:${l.edge}`;r.set(a,[...r.get(a)??[],l.t0].sort((c,d)=>c-d))}let o=l=>{let a=n.get(l.room)?.wall_heights?.[l.edge];return Array.isArray(a)?a[(r.get(`${l.room}:${l.edge}`)??[]).indexOf(l.t0)]??null:a},i=l=>{let a=n.get(l.room),[c,d]=[a?.wall_heights?.[l.edge],a?.wall_slopes?.[l.edge]];if(!a||typeof c!="number"||typeof d!="number"||c<=0||d<=0)return null;let[u,p]=[a.points[l.edge],a.points[(l.edge+1)%a.points.length]];return{from:c,to:d,length:Math.hypot(p[0]-u[0],p[1]-u[1])}},s=l=>{let a=i(l);if(!a||a.length<1e-9){let d=o(l);return typeof d=="number"&&d>0?[d,d]:[null,null]}let c=d=>a.from+(a.to-a.from)*d/a.length;return l.forward?[c(l.t0),c(l.t1)]:[c(l.t1),c(l.t0)]};return{heightsOf(l){let[a,c]=[1/0,1/0];for(let u of l){let[p,h]=s(u),[f,g]=u===l[0]?[p,h]:[h,p];f!==null&&(a=Math.min(a,f)),g!==null&&(c=Math.min(c,g))}let d=l.map(u=>n.get(u.room)?.ceiling);if(d.every(u=>typeof u=="number"&&u>0)){let u=Math.max(...d);a===1/0&&(a=u),c===1/0&&(c=u)}return{...a<1/0?{a}:{},...c<1/0?{b:c}:{}}},thicknessOf(l){let a=l.map(c=>{let d=n.get(c.room)?.wall_thickness?.[c.edge];return Array.isArray(d)?d[(r.get(`${c.room}:${c.edge}`)??[]).indexOf(c.t0)]:d}).filter(c=>typeof c=="number"&&c>0);return a.length?Math.max(...a):void 0},hasNoWall:l=>l.some(a=>o(a)===0)}}function Od(t){let e=n=>Math.round(n*1e6)/1e6;return t.a===void 0||t.b===void 0?t.a!==void 0?{height:e(t.a)}:t.b!==void 0?{height:e(t.b)}:{}:Math.abs(t.a-t.b)<1e-6?{height:e(t.a)}:{height:e(t.a),heightEnd:e(t.b)}}function ob(t,e,n,r){let o=rb(e,t),i=new Map;for(let a of t){let c=a.up!==c&&p.u===c.v&&p.v===c.u&&p.room!==c.room);for(let p of a)p!==c&&p!==d&&p.room!==c.room&&r.push(`overlap:${c.room}:${p.room}`);let u=d?[c,d]:[c];if(o.hasNoWall(u)){d&&l.push([c.room,d.room]);continue}if(d){let p=o.thicknessOf(u)??n.interior;s.push({a:c.u,b:c.v,left:p/2,right:p/2,exterior:!1,roomLeft:c.room,roomRight:d.room,sources:u.map(Dd),...Od(o.heightsOf(u))})}else s.push({a:c.u,b:c.v,left:0,right:o.thicknessOf(u)??n.exterior,exterior:!0,roomLeft:c.room,roomRight:null,sources:[Dd(c)],...Od(o.heightsOf(u))})}return{drafts:s,open:l}}function ib(t,e){let n=i=>nt(K(e[i.b],e[i.a])),r=t.filter(i=>!i.exterior&&!i.free),o=new Map;for(let i of r){if(o.has(i))continue;let s=[i];o.set(i,s);for(let l=0;l1e-6||a.add(Q(s,h)>0?"left":"right")}if(a.size!==1)continue;let c=[...a][0];for(let d of i){let u=d.left+d.right,p=Q(n(d),s)>0,h=c==="left"===p;[d.left,d.right]=h?[0,u]:[u,0]}}}var sb=(t,e)=>{let n=i=>Math.round(i*100),[r,o]=t[0]Math.hypot(b.b[0]-b.a[0],b.b[1]-b.a[1])>.05),a=l.map(b=>[i.idOf(b.a),i.idOf(b.b)]),c=new Set;for(let b of t){let v=b.points;v.length<3||(b.wall_splits??[]).forEach((w,x)=>{if(!w||x>=v.length)return;let k=v[x],$=K(v[(x+1)%v.length],k),A=fe($);for(let F of w)F>r&&F{let[w,x]=a[v];if(w===x)return;let k=[(b.a[0]+b.b[0])/2,(b.a[1]+b.b[1])/2],$=t.find(F=>F.points.length>=3&&N(k,F.points))?.id??null,A=(b.thickness??e.interior)/2;h.push({free:b.id,a:w,b:x,left:A,right:A,exterior:!1,roomLeft:$,roomRight:$,sources:[],height:typeof b.height=="number"&&b.height>0?b.height:void 0,...typeof b.height=="number"&&b.height>0&&typeof b.height_end=="number"&&b.height_end>0&&Math.abs(b.height_end-b.height)>1e-6?{heightEnd:b.height_end}:{}})});let f=zd(h,i.points,c),g=Pd(f,i.points);return{walls:f.map((b,v)=>{let[w,x]=[i.points[b.a],i.points[b.b]],[k,$]=[g.get(`${v}:a`),g.get(`${v}:b`)],A=Id([k.right,$.left,x,$.right,k.left,w],1e-6);return{id:sb(w,x),a:[w[0],w[1]],b:[x[0],x[1]],left:b.left,right:b.right,exterior:b.exterior,roomLeft:b.roomLeft,roomRight:b.roomRight,sources:b.sources,footprint:A,...b.free?{free:b.free}:{},...b.height!==void 0?{height:b.height}:{},...b.heightEnd!==void 0?{heightEnd:b.heightEnd}:{}}}),warnings:[...new Set(o)],open:p}}function Fn(t,e,n){let r=t.points[e];return dt(r,tt(nt(K(t.points[(e+1)%t.points.length],r)),n))}function Ie(t,e,n){if(t.wall){let o=n.find(l=>l.id===t.wall);if(!o||Math.hypot(o.b[0]-o.a[0],o.b[1]-o.a[1])<.05)return null;let i=nt(K(o.b,o.a));return{room:{id:t.room_id,name:"",area_id:null,points:[o.a,o.b,dt(o.a,[-i[1],i[0]])]},edge:0}}let r=e.find(o=>o.id===t.room_id);return r&&t.edgeQ(K(e,t.a),nt(K(t.b,t.a)));function Pt(t,e,n){if(!e.wall)return ab(t,n.room,n.edge,e.offset);let r=t.find(o=>o.free===e.wall);return r?{wall:r,s:Hd(r,Fn(n.room,0,e.offset))}:null}function ab(t,e,n,r){for(let o of t)if(o.sources.some(s=>s.room_id===e.id&&s.edge===n&&r>=s.t0-1e-6&&r<=s.t1+1e-6))return{wall:o,s:Hd(o,Fn(e,n,r))};return null}function Ld(t,e){let n=t.points.map(h=>h[0]),r=t.points.map(h=>h[1]);if(t.points.length!==4||new Set(n.map(h=>h.toFixed(3))).size!==2||new Set(r.map(h=>h.toFixed(3))).size!==2)return null;let[o,i,s,l]=[Math.min(...n),Math.max(...n),Math.min(...r),Math.max(...r)],a=h=>Math.max(0,...e.filter(f=>(f.roomLeft===t.id||f.roomRight===t.id)&&h(f)).map(f=>f.roomLeft===t.id?f.left:f.right)),c=(h,f)=>Math.abs(h-f)<.001,d=(h,f,g)=>c(h.a[f],g)&&c(h.b[f],g),u=i-o-a(h=>d(h,0,o))-a(h=>d(h,0,i)),p=l-s-a(h=>d(h,1,s))-a(h=>d(h,1,l));return[Math.round(u*1e3)/1e3,Math.round(p*1e3)/1e3]}var Cd=([t,e])=>{let n=Math.hypot(t,e)||1;return[t/n,e/n]};function lb(t){return t.reduce((e,n,r)=>e+(n[0]*t[(r+1)%t.length][1]-t[(r+1)%t.length][0]*n[1]),0)/2}function Nd(t,e){let n=t.length;if(n<3||Math.abs(e)<1e-9)return t.map(([o,i])=>[o,i]);let r=lb(t)>=0?1:-1;return t.map((o,i)=>{let s=t[(i+n-1)%n],l=t[(i+1)%n],[a,c]=Cd([o[0]-s[0],o[1]-s[1]]),[d,u]=Cd([l[0]-o[0],l[1]-o[1]]),p=[c*r,-a*r],h=[u*r,-d*r],f=[p[0]+h[0],p[1]+h[1]],g=Math.hypot(f[0],f[1]);if(g<1e-6)return[o[0]+p[0]*e,o[1]+p[1]*e];let y=(f[0]*p[0]+f[1]*p[1])/g,b=Math.min(4,1/Math.max(.25,y));return[o[0]+f[0]/g*e*b,o[1]+f[1]/g*e*b]})}function It(t){let e=t.map(r=>r[0]),n=t.map(r=>r[1]);return{x0:Math.min(...e),z0:Math.min(...n),x1:Math.max(...e),z1:Math.max(...n)}}function cb(t){let e=([i,s])=>`${Math.round(i*1e3)}:${Math.round(s*1e3)}`,n=new Map;for(let i of t)for(let s of[i.a,i.b])n.set(e(s),[...n.get(e(s))??[],i]);let r=new Set,o=null;for(let i of t){if(r.has(i))continue;r.add(i);let s=[i.a,i.b],l=i.b;for(;;){let c=(n.get(e(l))??[]).find(d=>!r.has(d));if(!c||(r.add(c),l=e(c.a)===e(l)?c.b:c.a,e(l)===e(s[0])))break;s.push(l)}s.length>=3&&e(l)===e(s[0])&&(!o||Math.abs(we(s))>Math.abs(we(o)))&&(o=s)}return o}function Ds(t,e,n,r){let o=pe(t,{exterior:n,interior:r},e).walls.filter(l=>l.exterior&&!l.free),i=o.length?cb(o.map(l=>({a:l.a,b:l.b}))):null;if(!i)return null;let s=i.filter((l,a)=>{let c=i[(a+i.length-1)%i.length],d=i[(a+1)%i.length];return Math.abs((l[0]-c[0])*(d[1]-l[1])-(l[1]-c[1])*(d[0]-l[0]))>1e-6});return s.length>=3?Nd(s,n):null}function Qt(t,e){let n=ve(t),r=Pe(t),o=n.w,[i,s]=[Math.max(0,e.a),Math.max(0,e.b)],l=n.u0-Math.max(0,e.u0),a=n.u1+Math.max(0,e.u1),c=(b,v)=>[b,v,r.y(v)],d=c(l,-i),u=c(a,-i),p=c(a,o+s),h=c(l,o+s),[f,g]=[rt(t.pitch_a),rt(t.pitch_b)],y=b=>[b,r.vr,r.rh];if(t.ends&&(t.shape==="gable"||t.shape==="hip"||t.shape==="halfhip")){let b=(n.u1-n.u0)/2,v=Math.min(b,Math.min(r.vr,o-r.vr)||o/2),w=Math.min(r.y(0),r.y(o)),x=w+(r.rh-w)*Math.min(.9,Math.max(.2,t.halfhip??.55)),k=f>1e-6?Math.min(r.vr,(x-t.eave_a)/f):r.vr,$=g>1e-6?Math.max(r.vr,o-(x-t.eave_b)/g):r.vr,A=Math.min(b-.1,(r.rh-x)/Math.max(.2,f)),F=[[0,r.y(0)],[r.vr,r.rh],[o,r.y(o)]],T=[[0,r.y(0)],[k,x],[$,x],[o,r.y(o)]],I=(V,Kt,_o)=>{if(V==="hip")return{upA:[],upB:[],ridge:y(Kt===l?n.u0+v*_o:n.u1-v*_o),profile:null};if(V==="halfhip"){let qg=y(Kt===l?n.u0+A:n.u1-A);return{upA:[[Kt,k,x]],upB:[[Kt,$,x]],ridge:qg,profile:T}}return{upA:[],upB:[],ridge:y(Kt),profile:F}},z=I(t.ends[0],l,1),C=I(t.ends[1],a,1),B=[[d,u,...C.upA,C.ridge,z.ridge,...[...z.upA].reverse()],[z.ridge,C.ridge,...[...C.upB].reverse(),p,h,...z.upB]],q=[[z.ridge,C.ridge]];for(let[V,Kt,_o]of[[z,d,h],[C,u,p]])V.profile===null?(B.push(V===z?[h,d,V.ridge]:[u,p,V.ridge]),q.push([Kt,V.ridge],[_o,V.ridge])):V.upA.length&&(B.push(V===z?[V.upB[0],V.upA[0],V.ridge]:[V.upA[0],V.upB[0],V.ridge]),q.push([V.upA[0],V.ridge],[V.upB[0],V.ridge]));let ye=V=>V.profile===null?[]:V.upA.length?[V.upA[0],V.upB[0]]:[V.ridge],$t=[d,u,...ye(C),p,h,...[...ye(z)].reverse()];return{faces:B,rim:$t,ridges:q,gable:F,endProfiles:[z.profile,C.profile]}}switch(t.shape){case"pent":return{faces:[[d,u,p,h]],rim:[d,u,p,h],ridges:[[p,h]],gable:[[0,r.y(0)],[o,r.y(o)]]};case"hip":case"pyramid":{let b=(n.u1-n.u0)/2,v=t.shape==="pyramid"?b:Math.min(b,Math.min(r.vr,o-r.vr)||o/2),w=y(n.u0+v),x=y(n.u1-v);return t.shape==="pyramid"?{faces:[[d,u,w],[u,p,w],[p,h,w],[h,d,w]],rim:[d,u,p,h],ridges:[[d,w],[h,w],[u,w],[p,w]],gable:null}:{faces:[[d,u,x,w],[w,x,p,h],[h,d,w],[u,p,x]],rim:[d,u,p,h],ridges:[[w,x],[d,w],[h,w],[u,x],[p,x]],gable:null}}case"halfhip":{let b=Math.min(r.y(0),r.y(o)),v=b+(r.rh-b)*Math.min(.9,Math.max(.2,t.halfhip??.55)),w=f>1e-6?Math.min(r.vr,(v-t.eave_a)/f):r.vr,x=g>1e-6?Math.max(r.vr,o-(v-t.eave_b)/g):r.vr,k=Math.min((n.u1-n.u0)/2-.1,(r.rh-v)/Math.max(.2,f)),$=y(n.u0+k),A=y(n.u1-k),F=[l,w,v],T=[l,x,v],I=[a,w,v],z=[a,x,v];return{faces:[[d,u,I,A,$,F],[$,A,z,p,h,T],[T,F,$],[I,z,A]],rim:[d,u,I,z,p,h,T,F],ridges:[[$,A],[F,$],[T,$],[I,A],[z,A]],gable:[[0,r.y(0)],[w,v],[x,v],[o,r.y(o)]]}}case"mansard":{let b=Mr(o,t.eave_a,t.eave_b,f,g),v=[l,b.vla,b.yla],w=[a,b.vla,b.yla],x=[l,o-b.vlb,b.ylb],k=[a,o-b.vlb,b.ylb],$=[l,b.vr,b.rh],A=[a,b.vr,b.rh];return{faces:[[d,u,w,v],[v,w,A,$],[$,A,k,x],[x,k,p,h]],rim:[d,u,w,A,k,p,h,x,$,v],ridges:[[$,A],[v,w],[x,k]],gable:[[0,r.y(0)],[b.vla,b.yla],[b.vr,b.rh],[o-b.vlb,b.ylb],[o,r.y(o)]]}}default:{let b=y(l),v=y(a);return{faces:[[d,u,v,b],[b,v,p,h]],rim:[d,u,v,p,h,b],ridges:[[b,v]],gable:[[0,r.y(0)],[r.vr,r.rh],[o,r.y(o)]]}}}}function Rr(t,e,n){let r=null;for(let o of t.faces){if(!N([e,n],o.map(([p,h])=>[p,h])))continue;let[i,s]=o,l=o.slice(2).find(p=>Math.abs((s[0]-i[0])*(p[1]-i[1])-(s[1]-i[1])*(p[0]-i[0]))>1e-9);if(!l)continue;let a=[s[0]-i[0],s[2]-i[2],s[1]-i[1]],c=[l[0]-i[0],l[2]-i[2],l[1]-i[1]],d=[a[1]*c[2]-a[2]*c[1],a[2]*c[0]-a[0]*c[2],a[0]*c[1]-a[1]*c[0]];if(Math.abs(d[1])<1e-9)continue;let u=i[2]-(d[0]*(e-i[0])+d[2]*(n-i[1]))/d[1];r=r===null?u:Math.min(r,u)}return r}function Er(t,e,n){let r=ve(e),o=t.floors.flatMap(u=>u.rooms.filter(p=>p.points.length>=3&&u.elevation+u.height>e.base+.05)),i=u=>u.some(p=>o.some(h=>N(p,h.points))),s=.35,l=[.15,.5,.85].map(u=>r.u0+(r.u1-r.u0)*u),a=[.15,.5,.85].map(u=>r.w*u),c=u=>u?0:n,d=(u,p)=>{let h=e.overhang_sides?.[u];return typeof h=="number"&&Number.isFinite(h)?Math.min(2,Math.max(0,h)):p};return{a:d("a",c(i(l.map(u=>r.at(u,-s))))),b:d("b",c(i(l.map(u=>r.at(u,r.w+s))))),u0:d("u0",c(i(a.map(u=>r.at(r.u0-s,u))))),u1:d("u1",c(i(a.map(u=>r.at(r.u1+s,u)))))}}var qo=t=>Math.abs((t.x1-t.x0)*(t.z1-t.z0)),Bd=t=>t.shape==="flat"||t.shape==="parapet",Jt=t=>Math.round(t*100)/100;function Yo(t,e){let[n,r]=[(e.x0+e.x1)/2,(e.z0+e.z1)/2];return t.filter(i=>{if(i===e||i.dormer||i.open||Bd(i)||qo(i)=s.x0&&n<=s.x1&&r>=s.z0&&r<=s.z1}).reduce((i,s)=>i===null||qo(s){let[i,s]=e.at(o,e.w/2),[l,a]=Sr(t,i,s);return Rr(n,l,a)??r.y(a)}}function Hs(t,e){if(Bd(e))return e;let n=ve(e),r=Pe(e).rh,o=ub(t,n),i=o(n.u0)<=o(n.u1),[s,l]=i?[n.u0,n.u1]:[n.u1,n.u0],a=i?1:-1,c=l;for(let p=.5;p=r-.02){c=s+a*p;break}if(Math.abs(c-l)<.05)return e;let d={...e},u=l===n.u1;return e.axis==="x"?d[u?"x1":"x0"]=c:d[u?"z1":"z0"]=c,d}var Ls=.14,Wd=t=>t.shape==="flat"||t.shape==="parapet";function Cs(t,e){return!t.open&&Math.min(t.base,t.eave_a,t.eave_b)a+o||pd+o||s.points&&s.points.length>=3&&!N([e,n],s.points))continue;let[h,f]=Sr(s,e,n),g=Math.max(0,s.overhang??r),y=Wd(s)?null:Rr(Qt(s,{u0:g,u1:g,a:g,b:g}),h,f);i.push((y??Pe(s).y(f))-Ls)}return i.length?Math.max(...i):null}function Ns(t,e,n){let r=[],o=e+n+Ls;for(let i of t.settings.roof.sections??[]){if(i.open||Wd(i)||i.shape==="mansard")continue;let s=ve(i),l=Pe(i),[a,c]=[rt(i.pitch_a),rt(i.pitch_b)],d=[];a>1e-6&&d.push((o-i.eave_a)/a),i.shape==="gable"&&c>1e-6&&d.push(s.w-(o-i.eave_b)/c);for(let u of d)u<=.01||u>=s.w-.01||i.shape==="gable"&&Math.abs(l.y(u)-o)>1e-6||r.push([s.at(s.u0,u),s.at(s.u1,u)])}return r}function Bs(t,e,n,r,o){let i=[];for(let l of[.2,.5,.8])for(let a of[.2,.5,.8])i.push([e+(r-e)*l,n+(o-n)*a]);let s=t.floors.filter(l=>l.rooms.some(a=>a.points.length>=3&&i.some(c=>N(c,a.points)))).map(l=>l.elevation+l.height);return s.length?Math.max(...s):null}function Ws(t,e){let n=t.floors.filter(a=>a.rooms.length>0).sort((a,c)=>a.elevation-c.elevation),r=n.filter(a=>a.elevationd.rooms.some(u=>u.points.length>=3&&a.some(p=>N(p,u.points))));if(c)return c}return r.at(-1)??n[0]}var bt=t=>Math.round(t*1e3)/1e3;function Vs(t,e=n=>`roof_${n+1}`){let n=t.settings.roof?.pitch??35,r=t.settings.wall_exterior,o=t.floors.filter(a=>a.rooms.some(c=>c.points.length>=3)).sort((a,c)=>c.elevation-a.elevation),i=[],s=[],l=(a,c)=>a.some(d=>N(c,d.points));for(let a of o){let c=a.rooms.filter(y=>y.points.length>=3),d=[...new Set(c.flatMap(y=>y.points.map(b=>bt(b[0]))))].sort((y,b)=>y-b),u=[...new Set(c.flatMap(y=>y.points.map(b=>bt(b[1]))))].sort((y,b)=>y-b),p=u.slice(0,-1).map((y,b)=>d.slice(0,-1).map((v,w)=>{let x=[(d[w]+d[w+1])/2,(u[b]+u[b+1])/2];return l(c,x)&&!l(s,x)})),h=p.map(y=>y.map(()=>!1)),f=(y,b)=>p[b][y]&&!h[b][y],g=a.elevation+a.height;for(let y=0;yf(b+T,w+1)).every(Boolean);)w++;for(let F=y;F<=w;F++)for(let T=b;T<=v;T++)h[F][T]=!0;let[x,k]=[d[b]-r,d[v+1]+r],[$,A]=[u[y]-r,u[w+1]+r];Math.min(k-x,A-$)<.8||i.push({id:e(i.length),x0:bt(x),z0:bt($),x1:bt(k),z1:bt(A),shape:"gable",axis:k-x>=A-$?"x":"z",eave_a:bt(g),eave_b:bt(g),pitch_a:n,pitch_b:n,base:bt(g),overhang:null})}s.push(...c)}return i}var Se=Math.PI/180,We=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],en=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2],Tn=t=>Math.hypot(t[0],t[1],t[2]),tn=t=>{let e=Tn(t)||1;return[t[0]/e,t[1]/e,t[2]/e]},Vd=(t,e)=>[t[1]*e[2]-t[2]*e[1],t[2]*e[0]-t[0]*e[2],t[0]*e[1]-t[1]*e[0]],Ve=t=>Math.round(t*100)/100,Fr=([t,e],n)=>(Math.atan2(t,-e)/Se-n+720)%360;var Gd=.25;function jd(t,e,n,r,o,i,s){let l=o-n>=i-r,a=l?o-n:i-r;return{key:`${t}:top`,section:e,side:"top",flat:!0,o:[n,s,r],eu:l?[1,0,0]:[0,0,1],es:l?[0,0,1]:[1,0,0],n:[0,1,0],lu:a,ls:l?i-r:o-n,pitch:0,span:()=>[0,a],facing:l?[0,1]:[1,0]}}function Ud(t,e){let n=tn(Vd(t,e));return n[1]<0?[-n[0],-n[1],-n[2]]:n}var Zd=t=>{let e=tn([-t[0],0,-t[2]]);return[e[0],e[2]]};function yt(t,e,n,r,o,i,s,l){let a=tn(We(o,r)),c=tn(We(i,r));return{key:t,section:e,side:n,flat:!1,o:r,eu:a,es:c,n:Ud(a,c),lu:Tn(We(o,r)),ls:Tn(We(i,r)),pitch:s,span:l,facing:Zd(c)}}function Kd(t,e,n,r,o,i){let s=Tn(We(o,r));if(s<.3)return null;let l=tn(We(o,r)),a=We(i,r),c=a[0]*l[0]+a[1]*l[1]+a[2]*l[2],d=[a[0]-l[0]*c,a[1]-l[1]*c,a[2]-l[2]*c],u=Tn(d);if(u<.3)return null;let p=tn(d),h=f=>{let g=Math.min(1,Math.max(0,f/u));return[c*g,s-(s-c)*g]};return{key:t,section:e,side:n,flat:!1,o:r,eu:l,es:p,n:Ud(l,p),lu:s,ls:u,pitch:Math.atan2(p[1],Math.hypot(p[0],p[2]))/Se,span:h,facing:Zd(p)}}function hb(t,e){let n=ve(t),r=Pe(t),o=(v,w,x)=>{let[k,$]=n.at(v,w);return[k,x,$]},[i,s]=[Math.max(0,e.a),Math.max(0,e.b)],l=n.u0-Math.max(0,e.u0),a=n.u1+Math.max(0,e.u1),c=a-l,d=r.y(-i),u=r.y(n.w+s);if(t.shape==="flat"||t.shape==="parapet"){let[v,w]=[n.at(l,-i),n.at(a,n.w+s)];return[jd(t.id,t.id,Math.min(v[0],w[0]),Math.min(v[1],w[1]),Math.max(v[0],w[0]),Math.max(v[1],w[1]),t.eave_a+Gd)]}if(t.shape==="pent")return[yt(`${t.id}:a`,t.id,"a",o(l,-i,d),o(a,-i,d),o(l,n.w+s,u),t.pitch_a,()=>[0,c])];if(t.shape==="mansard")return pb(t,n,l,a,i,s);let p=t.shape==="hip"||t.shape==="pyramid",h=(n.u1-n.u0)/2,f=t.shape==="pyramid"?h:p?Math.min(h,Math.min(r.vr,n.w-r.vr)||n.w/2):0,g=p?n.u0+f-l:0,y=p?a-(n.u1-f):0,b=[];if(r.vr>.3){let v=Math.hypot(r.vr+i,r.rh-d);b.push(yt(`${t.id}:a`,t.id,"a",o(l,-i,d),o(a,-i,d),o(l,r.vr,r.rh),t.pitch_a,w=>[g*(w/v),c-y*(w/v)]))}if(n.w-r.vr>.3){let v=Math.hypot(n.w+s-r.vr,r.rh-u);b.push(yt(`${t.id}:b`,t.id,"b",o(a,n.w+s,u),o(l,n.w+s,u),o(a,r.vr,r.rh),t.pitch_b,w=>[y*(w/v),c-g*(w/v)]))}if(p){let v=Kd(`${t.id}:c`,t.id,"c",o(l,n.w+s,u),o(l,-i,d),o(n.u0+f,r.vr,r.rh)),w=Kd(`${t.id}:d`,t.id,"d",o(a,-i,d),o(a,n.w+s,u),o(n.u1-f,r.vr,r.rh));b.push(...[v,w].filter(x=>x!==null))}return b}function pb(t,e,n,r,o,i){let s=Mr(e.w,t.eave_a,t.eave_b,rt(t.pitch_a),rt(t.pitch_b)),l=(f,g)=>{let[y,b]=e.at(f,g);return[y,s.y(g),b]},a=r-n,c=()=>[0,a],d=(f,g)=>Math.atan2(f,g)/Se,u=[],[p,h]=[e.w+i,e.w-s.vlb];return s.vla+o>.3&&u.push(yt(`${t.id}:a`,t.id,"a",l(n,-o),l(r,-o),l(n,s.vla),t.pitch_a,c)),s.vr-s.vla>.3&&u.push(yt(`${t.id}:au`,t.id,"a",l(n,s.vla),l(r,s.vla),l(n,s.vr),d(s.rh-s.yla,s.vr-s.vla),c)),s.vlb+i>.3&&u.push(yt(`${t.id}:b`,t.id,"b",l(r,p),l(n,p),l(r,h),t.pitch_b,c)),h-s.vr>.3&&u.push(yt(`${t.id}:bu`,t.id,"b",l(r,h),l(n,h),l(r,s.vr),d(s.rh-s.ylb,h-s.vr),c)),u}function Ks(t){return t.floors.filter(n=>n.rooms.some(r=>r.points.length>=3)).sort((n,r)=>r.elevation-n.elevation)[0]??null}function U(t){let e=t.settings.roof;if(!e||e.type==="none")return[];if(e.type==="custom")return(e.sections??[]).flatMap(w=>hb(w,Er(t,w,w.overhang??e.overhang)));let n=Ks(t);if(!n)return[];let r=n.rooms.flatMap(w=>w.points.map(x=>x[0])),o=n.rooms.flatMap(w=>w.points.map(x=>x[1])),i=t.settings.wall_exterior+e.overhang,[s,l]=[Math.min(...r)-i,Math.max(...r)+i],[a,c]=[Math.min(...o)-i,Math.max(...o)+i],d=n.elevation+n.height;if(e.type==="flat")return[jd("main",null,s,a,l,c,d+Gd)];let u=l-s>=c-a,p=e.ridge==="short"?!u:u,h=(p?c-a:l-s)/2,f=h*Math.tan(e.pitch*Se),g=(w,x,k)=>p?[w,d+k,(a+c)/2+x]:[(s+l)/2+x,d+k,w],[y,b]=p?[s,l]:[a,c],v=()=>[0,b-y];return[yt("main:a",null,"a",g(y,-h,0),g(b,-h,0),g(y,0,f),e.pitch,v),yt("main:b",null,"b",g(y,h,0),g(b,h,0),g(y,0,f),e.pitch,v)]}function Ke(t,e){let n=[];for(let r of t.floors.filter(o=>!e||o.id===e)){let{walls:o}=pe(r.rooms,{exterior:t.settings.wall_exterior,interior:t.settings.wall_interior},r.walls??[]);for(let i of o){if(!i.exterior&&!i.free)continue;let[s,l]=[i.b[0]-i.a[0],i.b[1]-i.a[1]],a=Math.hypot(s,l);if(a<1.2)continue;let[c,d]=[l/a,-s/a],u=Math.min(r.height,i.height??r.height,i.heightEnd??1/0),p=(h,f,g,y)=>n.push({key:h,section:null,side:"top",flat:!1,o:f,eu:g,es:[0,1,0],n:y,lu:a,ls:u,pitch:90,span:()=>[0,a],facing:[y[0],y[2]],wall:{floorId:r.id}});p(`wall:${r.id}:${i.id}`,[i.a[0]+c*i.right,r.elevation,i.a[1]+d*i.right],[s/a,0,l/a],[c,0,d]),i.free&&p(`wall:${r.id}:${i.id}:back`,[i.b[0]-c*i.left,r.elevation,i.b[1]-d*i.left],[-s/a,0,-l/a],[-c,0,-d])}}return n}var De="ground";function Xo(t){let e=t.floors.filter(n=>n.rooms.some(r=>r.points.length>=3)).sort((n,r)=>n.elevation-r.elevation);return e.find(n=>n.elevation>-.5)??e[0]??t.floors[0]??null}function Qo(t,e){let n=(e.rotation??0)*Se,r=[Math.cos(n),0,Math.sin(n)],o=[-Math.sin(n),0,Math.cos(n)],i=Xo(t),s=r[0]*e.u+o[0]*e.v,l=r[2]*e.u+o[2]*e.v,a=i?i.elevation+(e.base!=null?e.base:Nc(i,s,l)):e.base??0;return{key:De,section:null,side:"top",flat:!0,o:[0,a,0],eu:r,es:o,n:[0,1,0],lu:1e4,ls:1e4,pitch:0,span:()=>[-1e4,1e4],facing:[o[0],o[2]],unbounded:!0}}function ke(t,e,n=U(t)){return e.face===De?Qo(t,e):e.face.startsWith("wall:")?Ke(t,e.face.split(":")[1]).find(r=>r.key===e.face)??null:n.find(r=>r.key===e.face)??null}var Jo=1.13,zr=1.72,Ge=.025,ot=.07;function nn(t){let e=t.module_w||Jo,n=t.module_h||zr;return t.portrait===!1?[n,e]:[e,n]}function Pr(t){return t.layout?.length?t.layout.map(e=>Math.max(0,Math.min(60,Math.round(e)))):Array.from({length:Math.max(1,t.rows)},()=>Math.max(1,t.cols))}function Gs(t,e){return t.flat?Math.min(45,Math.max(0,e.tilt??15))*Se:t.wall?Math.min(90,Math.max(0,e.tilt??0))*Se:Math.min(45,Math.max(0,e.tilt??0))*Se}function Ir(t,e){let[,n]=nn(e),r=Gs(t,e);return t.wall?n*Math.cos(r)+Ge:!t.flat&&r<.001?n+Ge:t.flat&&e.rack==="ew"?n*Math.cos(r)+.08:n*Math.cos(r)+Math.max(.3,2*n*Math.sin(r))}function zn(t,e){let[n,r]=nn(e),o=Pr(e),i=Math.max(1,...o);return[i*n+(i-1)*Ge,(o.length-1)*Ir(t,e)+r*Math.cos(Gs(t,e))]}var fb=t=>t.flat&&!t.unbounded&&!t.wall;function qd(t,e){if(!fb(t)||!e.rotation)return null;let n=e.rotation*Se,[r,o]=zn(t,e);return{cos:Math.cos(n),sin:Math.sin(n),u:e.u+r/2,s:e.v+o/2}}function je(t,e,n=!1){let[r,o]=nn(e),i=Gs(t,e),s=o*Math.cos(i),l=Ir(t,e),a=Pr(e),c=Math.max(1,...a),d=new Set(e.skip??[]),u=qd(t,e),p=(y,b)=>u?[u.u+(y-u.u)*u.cos-(b-u.s)*u.sin,u.s+(y-u.u)*u.sin+(b-u.s)*u.cos]:[y,b],h=(y,b,v)=>{let[w,x]=p(y,b);return[0,1,2].map(k=>t.o[k]+t.eu[k]*w+t.es[k]*x+t.n[k]*v)},f=(y,b)=>{let[v,w]=p(y,b);if(t.unbounded)return!0;if(w<-1e-6||w>t.ls+1e-6)return!1;let[x,k]=t.span(w);return v>=x-1e-6&&v<=k+1e-6},g=[];return a.forEach((y,b)=>{let v=e.align==="right"?c-y:e.align==="center"?(c-y)/2:0;for(let w=0;w.001?s:o);if([[$,F],[A,F],[A,T],[$,T]].every(([I,z])=>f(I,z)))if(t.wall&&i>.001){let I=ot+o*Math.sin(i),[z,C]=e.flip?[I,ot]:[ot,I],B=[h($,F,z),h(A,F,z),h(A,T,C),h($,T,C)],q=e.flip?F:T;g.push({corners:B,posts:[$+.05,A-.05].map(ye=>[h(ye,q,0),h(ye,q,I)]),cell:x,skipped:k})}else if(!t.flat&&i>.001){let I=ot+o*Math.sin(i),z=[h($,F,ot),h(A,F,ot),h(A,T,I),h($,T,I)];g.push({corners:z,posts:[$+.05,A-.05].map(C=>[h(C,T,0),h(C,T,I)]),cell:x,skipped:k})}else if(!t.flat)g.push({corners:[h($,F,ot),h(A,F,ot),h(A,T,ot),h($,T,ot)],posts:[],cell:x,skipped:k});else{let z=.15+o*Math.sin(i),C=e.rack==="ew"&&b%2===1?!e.flip:!!e.flip,[B,q]=C?[T,F]:[F,T],ye=[h($,B,.15),h(A,B,.15),h(A,q,z),h($,q,z)],$t=[$+.05,A-.05].flatMap(V=>[[h(V,B,0),h(V,B,.15)],[h(V,q,0),h(V,q,z)]]);g.push({corners:ye,posts:$t,cell:x,skipped:k})}}}),g}function ut(t,e){if(t.unbounded)return{u:e.u,v:e.v};let[n,r]=zn(t,e),o=qd(t,e);if(o){let[s,l]=[(n*Math.abs(o.cos)+r*Math.abs(o.sin))/2,(n*Math.abs(o.sin)+r*Math.abs(o.cos))/2],a=(u,p,h)=>Math.floor(Math.max(p,Math.min(u,h-p))*100+1e-6)/100,[c,d]=[e.u+n/2,e.v+r/2];return{u:Math.round((a(c,s,t.lu)-n/2)*100)/100,v:Math.round((a(d,l,t.ls)-r/2)*100)/100}}let i=s=>Math.floor(s*100+1e-6)/100;return{u:i(Math.min(Math.max(0,e.u),Math.max(0,t.lu-n))),v:i(Math.min(Math.max(0,e.v),Math.max(0,t.ls-r)))}}function Dr(t,e){let[n,r]=zn(t,e),[o,i]=[e.u+n/2,e.v+r/2];return[t.o[0]+t.eu[0]*o+t.es[0]*i,t.o[2]+t.eu[2]*o+t.es[2]*i]}var ei=.78,Or=1.18,rn=t=>({id:t.id,face:t.face,u:t.u,v:t.v,rows:1,cols:1,portrait:!0,module_w:t.w||ei,module_h:t.h||Or});function js(t,e){let n=je(t,rn(e))[0];if(!n)return null;let r=o=>[o[0]-t.n[0]*.05,o[1]-t.n[1]*.05,o[2]-t.n[2]*.05];return n.corners.map(r)}var Tr={brick:{w:.5,d:.5,h:1},round:{w:.4,d:.4,h:1},wide:{w:1,d:.5,h:1},steel:{w:.2,d:.2,h:1.2}};function on(t){let e=t.shape??"brick",n=Tr[e]??Tr.brick;return{shape:e,w:t.w||n.w,d:t.d||n.d,h:t.h||n.h}}function wt(t,e){let{w:n,d:r}=on(t),o=e&&!e.flat?Math.cos(e.pitch*Se):1;return{id:t.id,face:t.face,u:t.u,v:t.v,rows:1,cols:1,portrait:!0,module_w:n,module_h:r/Math.max(.2,o),tilt:0}}function Us(t,e){let n=wt(e,t),[r,o]=[n.module_w,n.module_h],i=(d,u)=>[t.o[0]+t.eu[0]*d+t.es[0]*u,t.o[1]+t.eu[1]*d+t.es[1]*u,t.o[2]+t.eu[2]*d+t.es[2]*u],[s,l]=[i(e.u+r/2,e.v),i(e.u+r/2,e.v+o)],a=i(e.u+r/2,e.v+o/2),c=d=>{let u=Math.hypot(d[0],d[2])||1;return[d[0]/u,d[2]/u]};return{center:[a[0],a[2]],along:c(t.eu),across:c(t.es),low:Math.min(s[1],l[1]),high:Math.max(s[1],l[1])}}function Zs(t,e){let[n]=nn(e);return Ve((t.lu-(e.cols*n+(e.cols-1)*Ge))/2)}var Hr=.4;function Pn(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]=nn(n),[o,i]=t.span(t.ls/2);for(n.cols=Math.max(1,Math.floor((i-o-2*Hr+Ge)/(r+Ge))),n.rows=Math.max(1,Math.min(4,Math.floor((t.ls-2*Hr)/Ir(t,n))));n.cols>1&&je(t,{...n,u:Zs(t,n),v:Hr}).lengthl.lu*(1.3+Math.cos((Fr(l.facing,r)-180)*Math.PI/180)),i=Ke(t,n).sort((l,a)=>o(a)-o(l))[0];if(!i)return null;let s={...Pn(i,e),portrait:!1,rows:1};return s.cols=Math.max(1,Math.floor((i.lu-.8+Ge)/(zr+Ge))),s.u=Ve((i.lu-(s.cols*zr+(s.cols-1)*Ge))/2),s.v=Ve(Math.max(0,i.ls-Jo-.3)),s}function Lr(t,e){let n=t.floors.flatMap(i=>i.rooms.flatMap(s=>s.points)),r=n.length?Math.max(...n.map(i=>i[0]))+3:0,o=n.length?Math.min(...n.map(i=>i[1])):0;return{id:e,face:De,u:Ve(r),v:Ve(o),rows:2,cols:4,portrait:!0,tilt:25,flip:!0,rotation:(t.settings.north??0)||0,look:"black",entity:null}}function Cr(t,e,n){let r=Qo(t,e),[o,i]=zn(r,e),[s,l]=[e.u+o/2,e.v+i/2],a=[r.eu[0]*s+r.es[0]*l,r.eu[2]*s+r.es[2]*l],c=n*Se,d=a[0]*Math.cos(c)+a[1]*Math.sin(c)-o/2,u=a[0]*-Math.sin(c)+a[1]*Math.cos(c)-i/2;return{u:Ve(d),v:Ve(u),rotation:(Math.round(n)%360+360)%360}}function Nr(t,e){let[n,r]=t.span(t.ls/2);return{id:e,face:t.key,u:Ve((n+r-ei)/2),v:Ve(Math.max(0,Math.min(t.ls-Or,t.ls*.45-Or/2))),w:null,h:null,cover:null,contact:null,tilt:null}}function Br(t,e){let n=Tr.brick,[r,o]=t.span(t.ls*.8),i=wt({id:e,face:t.key,u:0,v:0},t).module_h;return{id:e,face:t.key,u:Ve((r+o-n.w)/2),v:Ve(Math.max(0,Math.min(t.ls-i,t.ls*.8-i/2))),shape:"brick",w:null,d:null,h:null}}function In(t,e){let[n,r]=[e[0]-t.o[0],e[1]-t.o[2]],[o,i,s,l]=[t.eu[0],t.eu[2],t.es[0],t.es[2]],a=o*l-i*s;if(Math.abs(a)<1e-9)return null;let c=(n*l-r*s)/a,d=(o*r-i*n)/a;if(d<0||d>t.ls)return null;let[u,p]=t.span(d);return c>=u&&c<=p?{u:c,s:d}:null}function Ys(t,e){let n=null;for(let r of t){if(r.wall){let[s,l]=[e[0]-r.o[0],e[1]-r.o[2]],a=s*r.eu[0]+l*r.eu[2],c=s*r.n[0]+l*r.n[2],d=a>=0&&a<=r.lu;if(d&&c>=-.05&&c<=.35)return{face:r,u:a,s:Number.NaN};d&&c>.35&&c<=.8&&!n&&(n={face:r,u:a,s:Number.NaN,y:-1/0});continue}let o=In(r,e);if(!o)continue;let i=r.o[1]+r.es[1]*o.s;(!n||i>n.y)&&(n={face:r,...o,y:i})}return n&&{face:n.face,u:n.u,s:n.s}}function ni(t,e,n){let r=en(n,t.n);if(Math.abs(r)<1e-6)return null;let o=en(We(t.o,e),t.n)/r;if(o<=0)return null;let i=We([e[0]+n[0]*o,e[1]+n[1]*o,e[2]+n[2]*o],t.o);return{t:o,u:en(i,t.eu),s:en(i,t.es)}}function Xs(t,e,n){if(t.unbounded)return!0;if(n<0||n>t.ls)return!1;let[r,o]=t.span(n);return e>=r&&e<=o}function Qs(t,e,n,r){return je(t,e).some(i=>{let s=i.corners.map(c=>{let d=We(c,t.o);return[en(d,t.eu),en(d,t.es)]}),l=s.map(c=>c[0]),a=s.map(c=>c[1]);return n>=Math.min(...l)-.05&&n<=Math.max(...l)+.05&&r>=Math.min(...a)-.05&&r<=Math.max(...a)+.05})}var mb=["n","ne","e","se","s","sw","w","nw"],Js=(t,e)=>mb[Math.round(Fr(t.facing,e)/45)%8];function Wr(t,e){let n=r=>{if(r.flat)return r.lu*r.ls*.8;let o=Math.cos((Fr(r.facing,e)-180)*Math.PI/180);return r.lu*r.ls*(1.2+o)};return[...t].sort((r,o)=>n(o)-n(r))[0]??null}var Jd=["kitchen_row","kitchen_l","bath","bedroom","living","dining","office","kids","hall"],Yd={kitchen_row:{rows:[["back","start",["fridge","kitchen_tall",["kitchen",[.9,.62,.92]],"sink","dishwasher","stove",["kitchen",[.6,.62,.92]]]],["back","start",[["kitchen_wall",[1.2,.35,.7]]]]],spots:[[["table",[1.2,.8,.75]],.5,.72,0],["lamp_pendant",.5,.72,0],["lamp_ceiling",.5,.3,0]]},kitchen_l:{rows:[["back","start",["fridge",["kitchen",[.9,.62,.92]],"sink","dishwasher","stove"]],["right","start",[["kitchen",[.9,.62,.92]],["kitchen",[.6,.62,.92]],"kitchen_tall"]],["back","start",[["kitchen_wall",[1.2,.35,.7]]]]],spots:[["table",.4,.68,0],["bar_stool",.72,.86,180],["lamp_ceiling",.5,.35,0]]},bath:{rows:[["back","center",["washbasin"]],["back","end",["wc"]],["front","start",["bathtub"]],["left","start",["washer"]]],spots:[["lamp_downlight",.5,.5,0]]},bedroom:{rows:[["back","center",["nightstand","bed","nightstand"]],["left","center",[["wardrobe",[2,.6,2.1]]]],["front","end",["dresser"]]],spots:[["lamp_ceiling",.5,.55,0]]},living:{rows:[["back","center",["tv_board"]],["right","start",["shelf"]]],spots:[["sofa",.5,.72,180],["coffee_table",.5,.52,0],[["rug",[2.2,1.6,.01]],.5,.55,0],["armchair",.14,.5,270],["lamp_floor",.86,.8,0],["plant",.9,.12,0],["lamp_ceiling",.5,.45,0]]},dining:{rows:[["back","center",["sideboard"]]],spots:[["table",.5,.55,0],["chair",.4,.35,0],["chair",.6,.35,0],["chair",.4,.75,180],["chair",.6,.75,180],["lamp_pendant",.5,.55,0]]},office:{rows:[["back","center",["desk"]],["left","center",["shelf","shelf"]]],spots:[["office_chair",.5,.38,180],["lamp_ceiling",.5,.55,0]]},kids:{rows:[["left","start",[["bed",[.9,2,.8]]]],["back","end",[["desk",[1.2,.6,.75]]]],["right","end",["shelf"]]],spots:[[["rug",[1.6,1.2,.01]],.55,.6,0],["lamp_ceiling",.5,.5,0]]},hall:{rows:[["left","start",["coat_rack"]]],spots:[["lamp_downlight",.5,.3,0],["lamp_downlight",.5,.7,0]]}},Xd=t=>typeof t=="string"?t:t[0],ri=t=>typeof t=="string"?et[t]:t[1],Dn=.05,gb=.02,Qd=t=>Math.round(t*1e3)/1e3;function _b(t,e,n,r){switch(e){case"back":return{x:t.x0+n,z:t.z0+r,turn:0};case"right":return{x:t.x1-r,z:t.z0+n,turn:90};case"front":return{x:t.x1-n,z:t.z1-r,turn:180};case"left":return{x:t.x0+r,z:t.z1-n,turn:270}}}function eu(t,e,n){let r=de(t.points),o=r.x1-r.x0,i=r.z1-r.z0,s=[],l=(a,c,d,u,[p,h,f])=>{s.push({id:n(),type:a,x:Qd(c),z:Qd(d),rotation:u,w:p,d:h,h:f,variant:null,entity:null,power:null})};for(let[a,c,d]of Yd[e].rows){let u=a==="back"||a==="front"?o:i,p=0,h=[];for(let g of d){if(p+ri(g)[0]>u-.1)break;h.push(g),p+=ri(g)[0]}let f=c==="start"?Dn:c==="end"?u-p-Dn:(u-p)/2;for(let g of h){let y=ri(g),b=_b(r,a,f+y[0]/2,y[1]/2+gb);l(Xd(g),b.x,b.z,b.turn,y),f+=y[0]}}for(let[a,c,d,u]of Yd[e].spots){let p=ri(a),h=(y,b,v)=>Math.min(v,Math.max(b,y)),f=h(r.x0+o*c,r.x0+p[0]/2+Dn,r.x1-p[0]/2-Dn),g=h(r.z0+i*d,r.z0+p[1]/2+Dn,r.z1-p[1]/2-Dn);l(Xd(a),f,g,u,p)}return s}var bb=30*Math.PI/180,tu=.05;function ea(t){let e=t.points.length;return t.points.map((n,r)=>{let o=t.points[(r+1)%e];return Math.hypot(o[0]-n[0],o[1]-n[1])})}function Vr(t){return ea(t).reduce((e,n)=>e+n,0)}function yb(t,e){let n=ea(t),r=0;for(let o=0;oh+f,0);if(o<3||!(i>0)||!(n>0))return null;let s=Math.min(n,i),l=(e%i+i)%i,a=0,c=0;for(;a=c+r[a];)c+=r[a],a++;let d=l-c,u=s,p=[];for(let h=0;h<=o&&u>1e-9;h++){let f=r[a]-d,g=Math.min(u,f);g>1e-9&&p.push({edge:a,t0:d,t1:d+g}),u-=g,d=0;let y=(a+1)%o;if(u>1e-9&&wb(t,a)>bb)break;a=y}for(;p.length>1&&p[0].t1-p[0].t01&&p[p.length-1].t1-p[p.length-1].t0({edge:h.edge,offset:(h.t0+h.t1)/2,width:h.t1-h.t0})):null}function On(t,e){let n=e[0];return n?{from:yb(t,n.edge)+n.offset-n.width/2,width:e.reduce((r,o)=>r+o.width,0)}:null}function Dt(t,e){return e.front?t.filter(n=>n.front===e.front):[e]}function na(t,e){let n=t.points.length,r=1/0,o=0,i=0;for(let s=0;sD("opening")){let s=ta(e,r,o);if(!s)return null;let l=Dt(t,n),a=new Set(l.map(h=>h.id)),c=s.length>1?l[0].front??`front-${l[0].id}`:null,d=s.map((h,f)=>({...n,id:f===0?l[0].id:i(),edge:h.edge,offset:h.offset,width:h.width,front:c})),u=[],p=!1;for(let h of t){if(!a.has(h.id)){u.push(h);continue}p||(u.push(...d),p=!0)}return u}var ia=globalThis,ra=ia.__nextfloorBuiltin?.de??{},oa=ia.__nextfloorBuiltin?.en??{};ia.__nextfloorBuiltin??={de:ra,en:oa};var vb=()=>typeof S=="object"&&S||{},kb=globalThis,xb=kb.__nextfloorTexts??=new Map;function $b(t){let e=t.toLowerCase().split("-")[0];return e!=="de"&&e!=="en"&&e in vb()?e:void 0}function nu(t){let e=$b(t),n=e===void 0?void 0:xb.get(e);return n instanceof Promise?void 0:n}function oi(t,e){return nu(t)?.[e]}function xe(t,e,n={}){let r=t?.language??navigator.language,o=r.startsWith("de"),i=(o?void 0:nu(r)?.[e])??(o?ra:oa)[e]??oa[e]??ra[e]??e;for(let[s,l]of Object.entries(n))i=i.replace(`{${s}}`,String(l));return i}function j(t,e,n=2){return e.toLocaleString(t?.language??void 0,{maximumFractionDigits:n})}var Me=se` :host { --nf-text: var(--primary-text-color, #e1e1e1); --nf-muted: var(--secondary-text-color, #9b9b9b); @@ -29,7 +29,7 @@ var S={cs:"4be67fcd522e",da:"0fe66a82bf2a",es:"bd89dffd1355",fi:"9a17bc084f56",f font-family: var(--nf-font); color: var(--nf-text); } -`,H$=se` +`,L$=se` :host([readable]) { --secondary-text-color: var(--primary-text-color, #e1e1e1); --divider-color: color-mix(in srgb, var(--primary-text-color, #e1e1e1) 40%, transparent); @@ -40,7 +40,7 @@ var S={cs:"4be67fcd522e",da:"0fe66a82bf2a",es:"bd89dffd1355",fi:"9a17bc084f56",f :host([readable]) .nf-overlay { zoom: 1.2; } -`,ut=se` +`,ht=se` /* a group of switches: one rounded pill, the active one tinted with the accent */ .nf-seg { display: inline-flex; @@ -203,23 +203,23 @@ var S={cs:"4be67fcd522e",da:"0fe66a82bf2a",es:"bd89dffd1355",fi:"9a17bc084f56",f min-height: 40px; } } -`;var me=t=>/^(sensor|input_number|number)\./.test(t),ii=t=>/^(binary_sensor|input_boolean)\./.test(t);function On(t,e){if(!me(e))return!1;let n=t?.states[e]?.attributes;return n?.device_class==="power"||n?.unit_of_measurement==="W"||n?.unit_of_measurement==="kW"}function Sb(t,e){let n=t?.entities?.[e],r=n?.area_id??(n?.device_id?t?.devices?.[n.device_id]?.area_id:null);return r?t?.areas?.[r]?.name:void 0}function L(t,e){return Object.keys(t?.states??{}).filter(e).map(n=>{let r=Sb(t,n),o=t?.states[n],i=typeof o?.attributes.symcon_path=="string"?o.attributes.symcon_path:void 0,s={id:n,label:r?`${W(t,n)} \xB7 ${r}`:W(t,n)};return i&&(s.detail=`Objektbaum: ${i}`),s}).sort((n,r)=>n.label.localeCompare(r.label))}function si(t,e){return t.power&&t.power!=="none"?t.power:e.get(t.id)?.power??null}var Hn={ATTRIBUTE:1,CHILD:2,PROPERTY:3,BOOLEAN_ATTRIBUTE:4,EVENT:5,ELEMENT:6},on=t=>(...e)=>({_$litDirective$:t,values:e}),Dt=class{constructor(e){}get _$AU(){return this._$AM._$AU}_$AT(e,n,r){this._$Ct=e,this._$AM=n,this._$Ci=r}_$AS(e,n){return this.update(e,n)}update(e,n){return this.render(...n)}};var Gr=class extends Dt{constructor(e){if(super(e),this.it=_,e.type!==Hn.CHILD)throw Error(this.constructor.directiveName+"() can only be used in child bindings")}render(e){if(e===_||e==null)return this._t=void 0,this.it=e;if(e===Qe)return e;if(typeof e!="string")throw Error(this.constructor.directiveName+"() called with a non-string value");if(e===this.it)return this._t;this.it=e;let n=[e];return n.raw=n,this._t={_$litType$:this.constructor.resultType,strings:n,values:[]}}};Gr.directiveName="unsafeHTML",Gr.resultType=1;var ru=on(Gr);var{I:Mb}=tc,ou=t=>t;var su=t=>t.strings===void 0,iu=()=>document.createComment(""),Ln=(t,e,n)=>{let r=t._$AA.parentNode,o=e===void 0?t._$AB:e._$AA;if(n===void 0){let i=r.insertBefore(iu(),o),s=r.insertBefore(iu(),o);n=new Mb(i,s,t,t.options)}else{let i=n._$AB.nextSibling,s=n._$AM,l=s!==t;if(l){let a;n._$AQ?.(t),n._$AM=t,n._$AP!==void 0&&(a=t._$AU)!==s._$AU&&n._$AP(a)}if(i!==o||l){let a=n._$AA;for(;a!==i;){let c=ou(a).nextSibling;ou(r).insertBefore(a,o),a=c}}}return n},Ot=(t,e,n=t)=>(t._$AI(e,n),t),Rb={},au=(t,e=Rb)=>t._$AH=e,lu=t=>t._$AH,ai=t=>{t._$AR(),t._$AA.remove()};var cu=(t,e,n)=>{let r=new Map;for(let o=e;o<=n;o++)r.set(t[o],o);return r},du=on(class extends Dt{constructor(t){if(super(t),t.type!==Hn.CHILD)throw Error("repeat() can only be used in text expressions")}dt(t,e,n){let r;n===void 0?n=e:e!==void 0&&(r=e);let o=[],i=[],s=0;for(let l of t)o[s]=r?r(l,s):s,i[s]=n(l,s),s++;return{values:i,keys:o}}render(t,e,n){return this.dt(t,e,n).values}update(t,[e,n,r]){let o=lu(t),{values:i,keys:s}=this.dt(e,n,r);if(!Array.isArray(o))return this.ut=s,i;let l=this.ut??=[],a=[],c,d,u=0,p=o.length-1,h=0,f=i.length-1;for(;u<=p&&h<=f;)if(o[u]===null)u++;else if(o[p]===null)p--;else if(l[u]===s[h])a[h]=Ot(o[u],i[h]),u++,h++;else if(l[p]===s[f])a[f]=Ot(o[p],i[f]),p--,f--;else if(l[u]===s[f])a[f]=Ot(o[u],i[f]),Ln(t,a[f+1],o[u]),u++,f--;else if(l[p]===s[h])a[h]=Ot(o[p],i[h]),Ln(t,o[u],o[p]),p--,h++;else if(c===void 0&&(c=cu(s,h,f),d=cu(l,u,p)),c.has(l[u]))if(c.has(l[p])){let g=d.get(s[h]),y=g!==void 0?o[g]:null;if(y===null){let b=Ln(t,o[u]);Ot(b,i[h]),a[h]=b}else a[h]=Ot(y,i[h]),Ln(t,o[u],y),o[g]=null;h++}else ai(o[p]),p--;else ai(o[u]),u++;for(;h<=f;){let g=Ln(t,a[f+1]);Ot(g,i[h]),a[h++]=g}for(;u<=p;){let g=o[u++];g!==null&&ai(g)}return this.ut=s,au(t,a),Qe}});var Eb=new Intl.Collator("de",{numeric:!0,sensitivity:"base"}),sa=-1,hu=[{type:1,name:"I/O"},{type:2,name:"Splitter"},{type:0,name:"Kerninstanzen"},{type:4,name:"Konfiguratoren"},{type:5,name:"Discovery"},{type:6,name:"Visualisierungen"}],uu=t=>t.object_type===1&&hu.some(e=>e.type===t.module_type);function Ab(t){let e=new Map(t.map(a=>[a.object_id,a])),n=t.filter(a=>{if(!uu(a))return!1;let c=new Set([a.object_id]),d=e.get(a.parent_id);for(;d&&!c.has(d.object_id);){if(uu(d))return!1;c.add(d.object_id),d=e.get(d.parent_id)}return!0});if(!n.length)return t;let r=new Map(e),o=new Map;for(let a of t){let c=o.get(a.parent_id)??[];c.push(a),o.set(a.parent_id,c)}let i=(a,c,d,u,p)=>({object_id:a,parent_id:c,name:d,path:u,position:p,object_type:0,hidden:!1,icon:"",virtual:!0});r.set(sa,i(sa,0,"System","System",Number.MAX_SAFE_INTEGER));let s=new Set,l=(a,c,d)=>{if(s.has(a.object_id))return;s.add(a.object_id);let u={...a,parent_id:c,path:`${d} / ${a.name}`};r.set(a.object_id,u);for(let p of o.get(a.object_id)??[])l(p,a.object_id,u.path)};return hu.forEach((a,c)=>{let d=n.filter(h=>h.module_type===a.type);if(!d.length)return;let u=-10-a.type,p=`System / ${a.name}`;r.set(u,i(u,sa,a.name,p,c));for(let h of d)l(h,u,p)}),[...r.values()]}function aa(t){let e=Ab(t),n=new Map(e.map(o=>[o.object_id,o])),r=new Map;for(let o of e){let i=n.has(o.parent_id)?o.parent_id:0,s=r.get(i)??[];s.push(o),r.set(i,s)}for(let o of r.values())o.sort((i,s)=>i.position-s.position||i.object_type-s.object_type||Eb.compare(i.name,s.name));return{nodes:n,children:r}}function la(t,e){let n=[],r=new Set([e]),o=t.nodes.get(e)?.parent_id;for(;o&&!r.has(o)&&t.nodes.has(o);)n.push(o),r.add(o),o=t.nodes.get(o)?.parent_id;return n}function ca(t,e,n=""){let r=n.trim().toLocaleLowerCase("de").split(/\s+/).filter(Boolean),o=r.length?new Set:null;if(o){for(let a of t.nodes.values())if(r.every(c=>`${a.name} ${a.path}`.toLocaleLowerCase("de").includes(c))){o.add(a.object_id);for(let c of la(t,a.object_id))o.add(c)}}let i=[],s=new Set,l=(a,c)=>{let d=(t.children.get(a)??[]).filter(u=>!o||o.has(u.object_id));d.forEach((u,p)=>{if(s.has(u.object_id))return;s.add(u.object_id);let h=(t.children.get(u.object_id)?.length??0)>0,f=h&&(!!o||e.has(u.object_id));i.push({node:u,depth:c,hasChildren:h,expanded:f,index:p+1,siblings:d.length}),f&&l(u.object_id,c+1)})};return l(0,0),i}var Fb=["Kategorie","Instanz","Variable","Skript","Ereignis","Medium","Link"],da=class extends ne{static properties={objects:{attribute:!1},options:{attribute:!1},fixed:{attribute:!1},value:{attribute:!1},disabled:{type:Boolean},placeholder:{attribute:!1},_query:{state:!0},_expanded:{state:!0},_pending:{state:!0},_active:{state:!0},_selected:{state:!0}};tree=aa([]);allowed=new Map;constructor(){super(),this.objects=[],this.options=[],this.fixed=[],this.value=null,this.disabled=!1,this.placeholder="Datenpunkt ausw\xE4hlen",this._query="",this._expanded=new Set,this._pending=null,this._active=null,this._selected=null}willUpdate(e){e.has("objects")&&(this.tree=aa(this.objects)),(e.has("options")||e.has("fixed"))&&(this.allowed=new Map([...this.fixed,...this.options].map(n=>[n.id,n])))}get dialog(){return this.renderRoot.querySelector("dialog")}variableNode(e){let n=this.objects.find(r=>r.entity_id===e&&r.object_type===2);return n?this.tree.nodes.get(n.object_id):void 0}async open(){if(this.disabled)return;this._pending=this.allowed.has(this.value??"")?this.value:null,this._query="";let e=this.variableNode(this.value)??this.objects.find(r=>r.entity_id===this.value);this._active=e?.object_id??null,this._selected=e?.object_id??null;let n=new Set(this._expanded);if(e)for(let r of la(this.tree,e.object_id))n.add(r);this._expanded=n,await this.updateComplete,this.isConnected&&(this.dialog?.open||this.dialog?.showModal(),this.renderRoot.querySelector(".search")?.focus(),this.renderRoot.querySelector("[aria-selected=true]")?.scrollIntoView({block:"nearest"}))}close(){this.dialog?.close()}commit(){this.disabled||!this._pending||!this.allowed.has(this._pending)||(this.value=this._pending,this.close(),this.dispatchEvent(new CustomEvent("change",{detail:{value:this.value},bubbles:!0,composed:!0})))}toggle(e){let n=new Set(this._expanded);n.has(e)?n.delete(e):n.add(e),this._expanded=n}select(e){this._active=e.object_id,e.entity_id&&this.allowed.has(e.entity_id)&&(this._pending=e.entity_id,this._selected=e.object_id)}async onTreeKey(e){let n=ca(this.tree,this._expanded,this._query),r=Math.max(0,n.findIndex(s=>s.node.object_id===this._active)),o=n[r];if(!o)return;let i=r;if(e.key==="ArrowDown")i=Math.min(n.length-1,r+1);else if(e.key==="ArrowUp")i=Math.max(0,r-1);else if(e.key==="Home")i=0;else if(e.key==="End")i=n.length-1;else if(e.key==="ArrowRight")o.hasChildren&&!o.expanded?this.toggle(o.node.object_id):o.hasChildren&&(i=Math.min(n.length-1,r+1));else if(e.key==="ArrowLeft")o.expanded&&!this._query?this.toggle(o.node.object_id):i=Math.max(0,n.findIndex(s=>s.node.object_id===o.node.parent_id));else if(e.key===" "||e.key==="Enter")this.select(o.node),e.key==="Enter"&&o.node.entity_id&&this.allowed.has(o.node.entity_id)&&this.commit();else return;e.preventDefault(),(i!==r||this._active===null)&&(this._active=n[i].node.object_id),await this.updateComplete,this.renderRoot.querySelector(`#object-${this._active}`)?.scrollIntoView({block:"nearest"})}icon(e){let n=[R``,R``,R``,R``,R``,R``,R``];return R``}renderRow(e){let{node:n}=e,r=!!n.entity_id&&this.allowed.has(n.entity_id);return m`
/^(sensor|input_number|number)\./.test(t),ii=t=>/^(binary_sensor|input_boolean)\./.test(t);function Hn(t,e){if(!me(e))return!1;let n=t?.states[e]?.attributes;return n?.device_class==="power"||n?.unit_of_measurement==="W"||n?.unit_of_measurement==="kW"}function Sb(t,e){let n=t?.entities?.[e],r=n?.area_id??(n?.device_id?t?.devices?.[n.device_id]?.area_id:null);return r?t?.areas?.[r]?.name:void 0}function L(t,e){return Object.keys(t?.states??{}).filter(e).map(n=>{let r=Sb(t,n),o=t?.states[n],i=typeof o?.attributes.symcon_path=="string"?o.attributes.symcon_path:void 0,s={id:n,label:r?`${W(t,n)} \xB7 ${r}`:W(t,n)};return i&&(s.detail=`Objektbaum: ${i}`),typeof o?.attributes.symcon_source_entity=="string"&&(s.sourceEntity=o.attributes.symcon_source_entity),s}).sort((n,r)=>n.label.localeCompare(r.label))}function si(t,e){return t.power&&t.power!=="none"?t.power:e.get(t.id)?.power??null}var Ln={ATTRIBUTE:1,CHILD:2,PROPERTY:3,BOOLEAN_ATTRIBUTE:4,EVENT:5,ELEMENT:6},sn=t=>(...e)=>({_$litDirective$:t,values:e}),Ot=class{constructor(e){}get _$AU(){return this._$AM._$AU}_$AT(e,n,r){this._$Ct=e,this._$AM=n,this._$Ci=r}_$AS(e,n){return this.update(e,n)}update(e,n){return this.render(...n)}};var Gr=class extends Ot{constructor(e){if(super(e),this.it=_,e.type!==Ln.CHILD)throw Error(this.constructor.directiveName+"() can only be used in child bindings")}render(e){if(e===_||e==null)return this._t=void 0,this.it=e;if(e===Qe)return e;if(typeof e!="string")throw Error(this.constructor.directiveName+"() called with a non-string value");if(e===this.it)return this._t;this.it=e;let n=[e];return n.raw=n,this._t={_$litType$:this.constructor.resultType,strings:n,values:[]}}};Gr.directiveName="unsafeHTML",Gr.resultType=1;var ru=sn(Gr);var{I:Mb}=tc,ou=t=>t;var su=t=>t.strings===void 0,iu=()=>document.createComment(""),Cn=(t,e,n)=>{let r=t._$AA.parentNode,o=e===void 0?t._$AB:e._$AA;if(n===void 0){let i=r.insertBefore(iu(),o),s=r.insertBefore(iu(),o);n=new Mb(i,s,t,t.options)}else{let i=n._$AB.nextSibling,s=n._$AM,l=s!==t;if(l){let a;n._$AQ?.(t),n._$AM=t,n._$AP!==void 0&&(a=t._$AU)!==s._$AU&&n._$AP(a)}if(i!==o||l){let a=n._$AA;for(;a!==i;){let c=ou(a).nextSibling;ou(r).insertBefore(a,o),a=c}}}return n},Ht=(t,e,n=t)=>(t._$AI(e,n),t),Rb={},au=(t,e=Rb)=>t._$AH=e,lu=t=>t._$AH,ai=t=>{t._$AR(),t._$AA.remove()};var cu=(t,e,n)=>{let r=new Map;for(let o=e;o<=n;o++)r.set(t[o],o);return r},du=sn(class extends Ot{constructor(t){if(super(t),t.type!==Ln.CHILD)throw Error("repeat() can only be used in text expressions")}dt(t,e,n){let r;n===void 0?n=e:e!==void 0&&(r=e);let o=[],i=[],s=0;for(let l of t)o[s]=r?r(l,s):s,i[s]=n(l,s),s++;return{values:i,keys:o}}render(t,e,n){return this.dt(t,e,n).values}update(t,[e,n,r]){let o=lu(t),{values:i,keys:s}=this.dt(e,n,r);if(!Array.isArray(o))return this.ut=s,i;let l=this.ut??=[],a=[],c,d,u=0,p=o.length-1,h=0,f=i.length-1;for(;u<=p&&h<=f;)if(o[u]===null)u++;else if(o[p]===null)p--;else if(l[u]===s[h])a[h]=Ht(o[u],i[h]),u++,h++;else if(l[p]===s[f])a[f]=Ht(o[p],i[f]),p--,f--;else if(l[u]===s[f])a[f]=Ht(o[u],i[f]),Cn(t,a[f+1],o[u]),u++,f--;else if(l[p]===s[h])a[h]=Ht(o[p],i[h]),Cn(t,o[u],o[p]),p--,h++;else if(c===void 0&&(c=cu(s,h,f),d=cu(l,u,p)),c.has(l[u]))if(c.has(l[p])){let g=d.get(s[h]),y=g!==void 0?o[g]:null;if(y===null){let b=Cn(t,o[u]);Ht(b,i[h]),a[h]=b}else a[h]=Ht(y,i[h]),Cn(t,o[u],y),o[g]=null;h++}else ai(o[p]),p--;else ai(o[u]),u++;for(;h<=f;){let g=Cn(t,a[f+1]);Ht(g,i[h]),a[h++]=g}for(;u<=p;){let g=o[u++];g!==null&&ai(g)}return this.ut=s,au(t,a),Qe}});var Eb=new Intl.Collator("de",{numeric:!0,sensitivity:"base"}),sa=-1,hu=[{type:1,name:"I/O"},{type:2,name:"Splitter"},{type:0,name:"Kerninstanzen"},{type:4,name:"Konfiguratoren"},{type:5,name:"Discovery"},{type:6,name:"Visualisierungen"}],uu=t=>t.object_type===1&&hu.some(e=>e.type===t.module_type);function Ab(t){let e=new Map(t.map(a=>[a.object_id,a])),n=t.filter(a=>{if(!uu(a))return!1;let c=new Set([a.object_id]),d=e.get(a.parent_id);for(;d&&!c.has(d.object_id);){if(uu(d))return!1;c.add(d.object_id),d=e.get(d.parent_id)}return!0});if(!n.length)return t;let r=new Map(e),o=new Map;for(let a of t){let c=o.get(a.parent_id)??[];c.push(a),o.set(a.parent_id,c)}let i=(a,c,d,u,p)=>({object_id:a,parent_id:c,name:d,path:u,position:p,object_type:0,hidden:!1,icon:"",virtual:!0});r.set(sa,i(sa,0,"System","System",Number.MAX_SAFE_INTEGER));let s=new Set,l=(a,c,d)=>{if(s.has(a.object_id))return;s.add(a.object_id);let u={...a,parent_id:c,path:`${d} / ${a.name}`};r.set(a.object_id,u);for(let p of o.get(a.object_id)??[])l(p,a.object_id,u.path)};return hu.forEach((a,c)=>{let d=n.filter(h=>h.module_type===a.type);if(!d.length)return;let u=-10-a.type,p=`System / ${a.name}`;r.set(u,i(u,sa,a.name,p,c));for(let h of d)l(h,u,p)}),[...r.values()]}function aa(t){let e=Ab(t),n=new Map(e.map(o=>[o.object_id,o])),r=new Map;for(let o of e){let i=n.has(o.parent_id)?o.parent_id:0,s=r.get(i)??[];s.push(o),r.set(i,s)}for(let o of r.values())o.sort((i,s)=>i.position-s.position||i.object_type-s.object_type||Eb.compare(i.name,s.name));return{nodes:n,children:r}}function la(t,e){let n=[],r=new Set([e]),o=t.nodes.get(e)?.parent_id;for(;o&&!r.has(o)&&t.nodes.has(o);)n.push(o),r.add(o),o=t.nodes.get(o)?.parent_id;return n}function ca(t,e,n=""){let r=n.trim().toLocaleLowerCase("de").split(/\s+/).filter(Boolean),o=r.length?new Set:null;if(o){for(let a of t.nodes.values())if(r.every(c=>`${a.name} ${a.path}`.toLocaleLowerCase("de").includes(c))){o.add(a.object_id);for(let c of la(t,a.object_id))o.add(c)}}let i=[],s=new Set,l=(a,c)=>{let d=(t.children.get(a)??[]).filter(u=>!o||o.has(u.object_id));d.forEach((u,p)=>{if(s.has(u.object_id))return;s.add(u.object_id);let h=(t.children.get(u.object_id)?.length??0)>0,f=h&&(!!o||e.has(u.object_id));i.push({node:u,depth:c,hasChildren:h,expanded:f,index:p+1,siblings:d.length}),f&&l(u.object_id,c+1)})};return l(0,0),i}var Fb=["Kategorie","Instanz","Variable","Skript","Ereignis","Medium","Link"],da=class extends ne{static properties={objects:{attribute:!1},options:{attribute:!1},fixed:{attribute:!1},value:{attribute:!1},disabled:{type:Boolean},placeholder:{attribute:!1},_query:{state:!0},_expanded:{state:!0},_pending:{state:!0},_active:{state:!0},_selected:{state:!0}};tree=aa([]);allowed=new Map;allowedSources=new Map;constructor(){super(),this.objects=[],this.options=[],this.fixed=[],this.value=null,this.disabled=!1,this.placeholder="Datenpunkt ausw\xE4hlen",this._query="",this._expanded=new Set,this._pending=null,this._active=null,this._selected=null}willUpdate(e){e.has("objects")&&(this.tree=aa(this.objects)),(e.has("options")||e.has("fixed"))&&(this.allowed=new Map([...this.fixed,...this.options].map(n=>[n.id,n])),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(o=>o.entity_id===n&&o.object_type===2);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="";let e=this.variableNode(this.value)??this.objects.find(r=>r.entity_id===this.value);this._active=e?.object_id??null,this._selected=e?.object_id??null;let n=new Set(this._expanded);if(e)for(let r of la(this.tree,e.object_id))n.add(r);this._expanded=n,await this.updateComplete,this.isConnected&&(this.dialog?.open||this.dialog?.showModal(),this.renderRoot.querySelector(".search")?.focus(),this.renderRoot.querySelector("[aria-selected=true]")?.scrollIntoView({block:"nearest"}))}close(){this.dialog?.close()}commit(){this.disabled||!this._pending||!this.allowed.has(this._pending)||(this.value=this._pending,this.close(),this.dispatchEvent(new CustomEvent("change",{detail:{value:this.value},bubbles:!0,composed:!0})))}toggle(e){let n=new Set(this._expanded);n.has(e)?n.delete(e):n.add(e),this._expanded=n}select(e){this._active=e.object_id;let n=this.entityFor(e);n&&(this._pending=n,this._selected=e.object_id)}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=ca(this.tree,this._expanded,this._query),r=Math.max(0,n.findIndex(s=>s.node.object_id===this._active)),o=n[r];if(!o)return;let i=r;if(e.key==="ArrowDown")i=Math.min(n.length-1,r+1);else if(e.key==="ArrowUp")i=Math.max(0,r-1);else if(e.key==="Home")i=0;else if(e.key==="End")i=n.length-1;else if(e.key==="ArrowRight")o.hasChildren&&!o.expanded?this.toggle(o.node.object_id):o.hasChildren&&(i=Math.min(n.length-1,r+1));else if(e.key==="ArrowLeft")o.expanded&&!this._query?this.toggle(o.node.object_id):i=Math.max(0,n.findIndex(s=>s.node.object_id===o.node.parent_id));else if(e.key===" "||e.key==="Enter")this.select(o.node),e.key==="Enter"&&this.entityFor(o.node)&&this.commit();else return;e.preventDefault(),(i!==r||this._active===null)&&(this._active=n[i].node.object_id),await this.updateComplete,this.renderRoot.querySelector(`#object-${this._active}`)?.scrollIntoView({block:"nearest"})}icon(e){let n=[R``,R``,R``,R``,R``,R``,R``];return R``}renderRow(e){let{node:n}=e,r=this.entityFor(n),o=!!r;return m`
{this.select(n),this.renderRoot.querySelector(".tree")?.focus()}} - @dblclick=${()=>{r?(this.select(n),this.commit()):e.hasChildren&&this.toggle(n.object_id)}}> + @dblclick=${()=>{o?(this.select(n),this.commit()):e.hasChildren&&this.toggle(n.object_id)}}> ${this.icon(n.object_type)}${n.name||"(Ohne Namen)"} ${n.virtual?"Systembereich":Fb[n.object_type]??"Objekt"}${n.hidden?" \xB7 ausgeblendet":""} - ${r&&n.object_id===this._selected&&n.entity_id===this._pending?m``:_} -
`}render(){let e=this.allowed.get(this.value??""),n=this.variableNode(this.value),r=this.allowed.get(this._pending??""),o=this._selected===null?void 0:this.tree.nodes.get(this._selected),i=(o?.entity_id===this._pending?o:void 0)??this.variableNode(this._pending),s=ca(this.tree,this._expanded,this._query),l=s.find(a=>a.node.object_id===this._active);return m`
`}render(){let e=this.allowed.get(this.value??""),n=this.variableNode(this.value),r=this.allowed.get(this._pending??""),o=this._selected===null?void 0:this.tree.nodes.get(this._selected),i=(o&&this.entityFor(o)===this._pending?o:void 0)??this.variableNode(this._pending),s=ca(this.tree,this._expanded,this._query),l=s.find(a=>a.node.object_id===this._active);return m` @@ -384,7 +384,7 @@ var S={cs:"4be67fcd522e",da:"0fe66a82bf2a",es:"bd89dffd1355",fi:"9a17bc084f56",f color: var(--nf-muted); cursor: default; } - `]};customElements.get("nf-entity-picker")||customElements.define("nf-entity-picker",ua);var sn=t=>t.target.value,ha=t=>Number.parseFloat(t.replace(",",".")),ie=t=>Math.round(t*1e3)/1e3,fu=t=>t.wide?"nf-field nf-wide":"nf-field";function E(t,e,n,r,o=.01,i){return m`