`,S=(t,e="")=>m``;function ln(t,e,n,r={}){let i=r.lowest??10;return m``}var rt=(t,e,n={})=>t.callWS({type:`nextfloor/${e}`,...n});async function mo(t,e){return(await rt(t,"image/get",{image_id:e})).data}async function Wt(t,e,n){await rt(t,"image/set",{image_id:e,data:n})}async function $d(t){return(await rt(t,"history/list")).snapshots}async function Sd(t,e){return(await rt(t,"history/snapshot",e?{name:e}:{})).id}async function Md(t,e){return(await rt(t,"history/get",{snapshot_id:e})).building}async function Rd(t,e){await rt(t,"history/delete",{snapshot_id:e})}async function Ed(t,e){return(await rt(t,"history/restore",{snapshot_id:e})).revision}var Dr=(t,e)=>rt(t,"packs/import",{pack:e});async function Ad(t,e){await rt(t,"packs/remove",{pack_id:e})}var Fd=t=>rt(t,"backup/export"),Td=(t,e,n)=>rt(t,"backup/import",{building:e,packs:n});var U=(t,e)=>[t[0]-e[0],t[1]-e[1]],ft=(t,e)=>[t[0]+e[0],t[1]+e[1]],it=(t,e)=>[t[0]*e,t[1]*e],te=(t,e)=>t[0]*e[0]+t[1]*e[1],Re=(t,e)=>t[0]*e[1]-t[1]*e[0],ge=t=>Math.hypot(t[0],t[1]),ot=t=>{let e=ge(t)||1;return[t[0]/e,t[1]/e]},la=t=>[-t[1],t[0]],ca=t=>[t[1],-t[0]];var dy=.05,hy=.2,py=.12;function fy(t){let e=[];return t.forEach((n,r)=>{let i=n.points;if(i.length<3)return;let o=_e(i)>=0;i.forEach((s,l)=>{let a=i[(l+1)%i.length],c=ge(U(a,s));if(c<.05)return;let u=[(a[0]-s[0])/c,(a[1]-s[1])/c],d=o?[u[1],-u[0]]:[-u[1],u[0]];(u[1]<-1e-9||Math.abs(u[1])<=1e-9&&u[0]<0)&&(u=[-u[0],-u[1]]);let p=[-u[1],u[0]],[h,f]=[te(s,u),te(a,u)];e.push({room:r,index:l,dir:u,normal:p,offset:te(s,p),outside:te(d,p)>0?1:-1,from:Math.min(h,f),to:Math.max(h,f)})})}),e}function my(t,e,n){if(t.room===e.room||Math.abs(Re(t.dir,e.dir))>dy||t.outside===e.outside)return null;let r=(e.offset-t.offset)*t.outside;return r>n||r<-py||Math.abs(r)<1e-4||Math.min(t.to,e.to)-Math.max(t.from,e.from)Math.round(t*1e3)/1e3;function zd(t,e=.6){let n=fy(t),r=n.map((g,b)=>b),i=g=>r[g]===g?g:r[g]=i(r[g]),o=[],s=new Set,l=[];for(let g=0;gMath.abs(g[2])-Math.abs(b[2]));let a=new Map(n.map((g,b)=>[b,[b]])),c=(g,b)=>g.some(y=>b.some(v=>n[y].room===n[v].room&&Math.abs(n[y].offset-n[v].offset)>=.002));for(let[g,b,y]of l){let[v,w]=[i(g),i(b)];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)}o.push(ua(y)),s.add(g).add(b)}let u=new Map(n.map((g,b)=>[`${g.room}:${g.index}`,b]));for(let g=s.size>0;g;)g=!1,n.forEach((b,y)=>{let v=u.get(`${b.room}:${(b.index+1)%t[b.room].points.length}`);if(v===void 0||v===y)return;let w=n[v];!(Math.abs(Re(b.dir,w.dir))<1e-6&&Math.abs(b.offset-w.offset)<.002&&b.outside===w.outside)||s.has(y)===s.has(v)||(s.add(y).add(v),g=!0)});n.forEach((g,b)=>{let y=u.get(`${g.room}:${(g.index+1)%t[g.room].points.length}`);if(y===void 0||y===b||!s.has(b)||!s.has(y))return;let v=n[y];Math.abs(Re(g.dir,v.dir))<1e-6&&Math.abs(g.offset-v.offset)<.002&&g.outside===v.outside&&(r[i(b)]=i(y))});let d=()=>t.map(g=>({...g,points:g.points.map(b=>[b[0],b[1]])}));if(o.length===0)return{rooms:d(),gaps:o};let p=new Map;for(let g of s)p.set(i(g),[...p.get(i(g))??[],g]);let h=t.map(g=>g.points.map(()=>new Map));for(let[g,b]of p){let y=new Map(b.map(w=>[`${n[w].room}:${Math.round(n[w].offset*500)}`,n[w].offset])),v=[...y.values()].reduce((w,x)=>w+x,0)/y.size;for(let w of b){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,b)=>({...g,points:g.points.map((y,v)=>{let w=[...h[b][v].values()].reduce((x,k)=>[x[0]+k[0],x[1]+k[1]],[y[0],y[1]]);return[ua(w[0]),ua(w[1])]})})),gaps:o}}function Pd(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 gy=.25,Dd=t=>Math.round(t*1e3)/1e3,Id=(t,e,n)=>t.rooms.find(r=>r.points.length>=3&&C([e,n],r.points));function ha(t,e,n,r,i){let o=Id(t,e,n);if(!o)return[r,i];let s=(l,a)=>C([l,a],o.points);return s(r,i)?[r,i]:s(r,n)?[r,n]:s(e,i)?[e,i]:[e,n]}function _y(t,e,n,r){return t.rooms.some(i=>i.id!==e.id&&i.points.some((o,s)=>{let l=i.points[(s+1)%i.points.length];return Math.abs(te(U(o,n),r))<.02&&Math.abs(te(U(l,n),r))<.02}))}var da=(t,e)=>Math.abs((t-e+540)%360-180);function Ir(t,e,n,r=gy){let i=Id(t,e.x,e.z);if(!i)return null;let o=i.points,s=_e(o)>=0?1:-1,l=null;return o.forEach((a,c)=>{let u=o[(c+1)%o.length],d=ge(U(u,a));if(d<.3)return;let p=[(u[0]-a[0])/d,(u[1]-a[1])/d],h=[-p[1]*s,p[0]*s],f=te(U([e.x,e.z],a),p);if(f<0||f>d)return;let g=_y(t,i,a,h)?n/2:0,b=te(U([e.x,e.z],a),h)-g,y=Math.atan2(-h[0],h[1])*180/Math.PI,w=[{rotation:y,extent:e.d/2},{rotation:y+90,extent:e.w/2},{rotation:y-90,extent:e.w/2}].reduce((k,M)=>da(e.rotation,M.rotation)50)return;let x=b-w.extent;Math.abs(x)>r||l&&Math.abs(x)>=Math.abs(l.gap)||(l={x:Dd(e.x-h[0]*x),z:Dd(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 Bn=Math.PI/180,st=t=>Math.tan(Math.min(80,Math.max(0,t))*Bn);function Hr(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 Od(t){if(!t.rotation)return null;let e=t.rotation*Bn;return{cx:(t.x0+t.x1)/2,cz:(t.z0+t.z1)/2,c:Math.cos(e),sn:Math.sin(e)}}function Hd(t,e){let n=Od(t);if(!n)return e;let[r,i]=[e[0]-n.cx,e[1]-n.cz];return[n.cx+r*n.c-i*n.sn,n.cz+r*n.sn+i*n.c]}function pa(t,e,n){let r=Od(t);if(!r)return[e,n];let[i,o]=[e-r.cx,n-r.cz];return[r.cx+i*r.c+o*r.sn,r.cz-i*r.sn+o*r.c]}function Lr(t,e=0){let{x0:n,x1:r,z0:i,z1:o}=Hr(t);return[[n-e,i-e],[r+e,i-e],[r+e,o+e],[n-e,o+e]].map(s=>Hd(t,s))}function $e(t){let{x0:e,x1:n,z0:r,z1:i}=Hr(t),o=s=>Hd(t,s);return t.axis==="x"?{u0:e,u1:n,w:i-r,at:(s,l)=>o([s,t.flip?i-l:r+l])}:{u0:r,u1:i,w:n-e,at:(s,l)=>o([t.flip?n-l:e+l,s])}}function Cr(t,e,n){let{x0:r,x1:i,z0:o,z1:s}=Hr(t),[l,a]=pa(t,e,n);return t.axis==="x"?[l,t.flip?s-a:a-o]:[a,t.flip?i-l:l-r]}var Or=Math.tan(30*Bn);function Nr(t,e,n,r,i){let o=Math.min(t*.3,r>1e-6?2.4/r:t*.3),s=Math.min(t*.3,i>1e-6?2.4/i:t*.3),l=e+o*r,a=n+s*i,c=Math.min(t-s,Math.max(o,(a-l+Or*(t-s+o))/(2*Or))),u=l+(c-o)*Or;return{vla:o,vlb:s,yla:l,ylb:a,vr:c,rh:u,y:p=>p<=o?e+p*r:p<=c?l+(p-o)*Or:p<=t-s?a+(t-s-p)*Or:n+(t-p)*i}}function Le(t){let e=$e(t).w,[n,r]=[t.eave_a,t.eave_b],[i,o]=[st(t.pitch_a),st(t.pitch_b)];switch(t.shape){case"flat":case"parapet":return{vr:e/2,rh:n,y:()=>n};case"pent":return{vr:e,rh:n+e*i,y:s=>n+s*i};case"mansard":{let s=Nr(e,n,r,i,o);return{vr:s.vr,rh:s.rh,y:s.y}}default:{let s=i+o>1e-6?Math.min(e,Math.max(0,(r-n+e*o)/(i+o))):e/2;return{vr:s,rh:n+s*i,y:l=>l<=s?n+l*i:r+(e-l)*o}}}}var cn=t=>Le(t).rh;function Ld(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 by(t,e){let n=t.map(r=>({...r}));for(let r of e){let i=n.find(o=>o.room_id===r.room_id&&o.edge===r.edge&&(Math.abs(o.t1-r.t0)<1e-6||Math.abs(r.t1-o.t0)<1e-6));i?(i.t0=Math.min(i.t0,r.t0),i.t1=Math.max(i.t1,r.t1)):n.push({...r})}return n}function yy(t,e,n){if(t.a===e.b)return!1;let r=ot(U(n[t.b],n[t.a])),i=ot(U(n[e.b],n[e.a]));return Math.abs(Re(r,i))>1e-6||te(r,i)<=0||t.free||e.free||t.heightEnd!==void 0||e.heightEnd!==void 0?!1:t.height===e.height&&t.exterior===e.exterior&&t.roomLeft===e.roomLeft&&t.roomRight===e.roomRight&&Math.abs(t.left-e.left)<=1e-9&&Math.abs(t.right-e.right)<=1e-9}function Cd(t,e,n=new Set){let r=t.slice();for(;;){let i=new Map;r.forEach((s,l)=>{for(let a of[s.a,s.b])i.set(a,[...i.get(a)??[],l])});let o=null;for(let[s,l]of i){if(l.length!==2||n.has(s))continue;let a=r[l[0]].b===s?r[l[0]]:Ld(r[l[0]]),c=r[l[1]].a===s?r[l[1]]:Ld(r[l[1]]);if(!yy(a,c,e))continue;let u={...a,b:c.b,sources:by(a.sources,c.sources)};o=[...r.filter((d,p)=>p!==l[0]&&p!==l[1]),u];break}if(!o)return r;r=o}}function Nd(t,e){let n=new Map;t.forEach((i,o)=>{let s=ot(U(e[i.b],e[i.a])),l=[[i.a,{key:`${o}:a`,d:s,left:i.left,right:i.right,angle:Math.atan2(s[1],s[0])}],[i.b,{key:`${o}:b`,d:it(s,-1),left:i.right,right:i.left,angle:Math.atan2(-s[1],-s[0])}]];for(let[a,c]of l)n.set(a,[...n.get(a)??[],c])});let r=new Map;for(let[i,o]of n){let s=e[i];o.sort((a,c)=>a.angle-c.angle);for(let a of o)r.set(a.key,{left:ft(s,it(la(a.d),a.left)),right:ft(s,it(ca(a.d),a.right))});if(o.length<2)continue;let l=4*Math.max(...o.map(a=>Math.max(a.left,a.right)))+1e-9;o.forEach((a,c)=>{let u=o[(c+1)%o.length],d=ft(s,it(la(a.d),a.left)),p=ft(s,it(ca(u.d),u.right)),h=Re(a.d,u.d);if(Math.abs(h)<1e-4)return;let f=ft(d,it(a.d,Re(U(p,d),u.d)/h));ge(U(f,s))>l||(r.get(a.key).left=f,r.get(u.key).right=f)})}return r}function Bd(t,e){let n=t.filter((r,i)=>ge(U(r,t[(i+1)%t.length]))>e);for(;;){if(n.length<=3)return n;let r=n.findIndex((i,o)=>{let s=n[(o+n.length-1)%n.length],l=n[(o+1)%n.length],[a,c]=[U(i,s),U(l,i)];return Math.abs(Re(ot(a),ot(c)))<1e-7&&te(a,c)>0});if(r===-1)return n;n=n.filter((i,o)=>o!==r)}}function vy(t){let e=[];return{points:e,idOf(n){let r=e.findIndex(i=>Math.abs(i[0]-n[0])<=t&&Math.abs(i[1]-n[1])<=t);return r>=0?r:(e.push([n[0],n[1]]),e.length-1)}}}function wy(t,e){let n=[];for(let r of t){let i=r.points;if(i.length<3||Math.abs(_e(i))<1e-6)continue;let o=_e(i)>0,s=i.map(l=>e.idOf(l));s.forEach((l,a)=>{let c=s[(a+1)%s.length];l!==c&&n.push(o?{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 ky(t,e,n){let r=[];for(let i of t){let[o,s]=[e[i.u],e[i.v]],l=U(s,o),a=ge(l),c=it(l,1/a),u=e.map((p,h)=>({id:h,rel:U(p,o)})).filter(({id:p,rel:h})=>p!==i.u&&p!==i.v&&te(h,c)>n&&te(h,c)({t:te(h,c),id:p})).sort((p,h)=>p.t-h.t),d=[{t:0,id:i.u},...u,{t:a,id:i.v}];for(let p=0;p+1({room_id:t.room,edge:t.edge,t0:t.t0,t1:t.t1});function xy(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,u)=>c-u))}let i=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},o=l=>{let a=n.get(l.room),[c,u]=[a?.wall_heights?.[l.edge],a?.wall_slopes?.[l.edge]];if(!a||typeof c!="number"||typeof u!="number"||c<=0||u<=0)return null;let[d,p]=[a.points[l.edge],a.points[(l.edge+1)%a.points.length]];return{from:c,to:u,length:Math.hypot(p[0]-d[0],p[1]-d[1])}},s=l=>{let a=o(l);if(!a||a.length<1e-9){let u=i(l);return typeof u=="number"&&u>0?[u,u]:[null,null]}let c=u=>a.from+(a.to-a.from)*u/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 d of l){let[p,h]=s(d),[f,g]=d===l[0]?[p,h]:[h,p];f!==null&&(a=Math.min(a,f)),g!==null&&(c=Math.min(c,g))}let u=l.map(d=>n.get(d.room)?.ceiling);if(u.every(d=>typeof d=="number"&&d>0)){let d=Math.max(...u);a===1/0&&(a=d),c===1/0&&(c=d)}return{...a<1/0?{a}:{},...c<1/0?{b:c}:{}}},thicknessOf(l){let a=l.map(c=>{let u=n.get(c.room)?.wall_thickness?.[c.edge];return Array.isArray(u)?u[(r.get(`${c.room}:${c.edge}`)??[]).indexOf(c.t0)]:u}).filter(c=>typeof c=="number"&&c>0);return a.length?Math.max(...a):void 0},hasNoWall:l=>l.some(a=>i(a)===0)}}function Vd(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 $y(t,e,n,r){let i=xy(e,t),o=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!==u&&p.room!==c.room&&r.push(`overlap:${c.room}:${p.room}`);let d=u?[c,u]:[c];if(i.hasNoWall(d)){u&&l.push([c.room,u.room]);continue}if(u){let p=i.thicknessOf(d)??n.interior;s.push({a:c.u,b:c.v,left:p/2,right:p/2,exterior:!1,roomLeft:c.room,roomRight:u.room,sources:d.map(Wd),...Vd(i.heightsOf(d))})}else s.push({a:c.u,b:c.v,left:0,right:i.thicknessOf(d)??n.exterior,exterior:!0,roomLeft:c.room,roomRight:null,sources:[Wd(c)],...Vd(i.heightsOf(d))})}return{drafts:s,open:l}}function Sy(t,e){let n=o=>ot(U(e[o.b],e[o.a])),r=t.filter(o=>!o.exterior&&!o.free),i=new Map;for(let o of r){if(i.has(o))continue;let s=[o];i.set(o,s);for(let l=0;l1e-6||a.add(te(s,h)>0?"left":"right")}if(a.size!==1)continue;let c=[...a][0];for(let u of o){let d=u.left+u.right,p=te(n(u),s)>0,h=c==="left"===p;[u.left,u.right]=h?[0,d]:[d,0]}}}var My=(t,e)=>{let n=o=>Math.round(o*100),[r,i]=t[0]Math.hypot(y.b[0]-y.a[0],y.b[1]-y.a[1])>.05),a=l.map(y=>[o.idOf(y.a),o.idOf(y.b)]),c=new Set;for(let y of t){let v=y.points;v.length<3||(y.wall_splits??[]).forEach((w,x)=>{if(!w||x>=v.length)return;let k=v[x],M=U(v[(x+1)%v.length],k),A=ge(M);for(let T of w)T>r&&T{let[w,x]=a[v];if(w===x)return;let k=[(y.a[0]+y.b[0])/2,(y.a[1]+y.b[1])/2],M=t.find(T=>T.points.length>=3&&C(k,T.points))?.id??null,A=(y.thickness??e.interior)/2;h.push({free:y.id,a:w,b:x,left:A,right:A,exterior:!1,roomLeft:M,roomRight:M,sources:[],height:typeof y.height=="number"&&y.height>0?y.height:void 0,...typeof y.height=="number"&&y.height>0&&typeof y.height_end=="number"&&y.height_end>0&&Math.abs(y.height_end-y.height)>1e-6?{heightEnd:y.height_end}:{}})});let f=Cd(h,o.points,c),g=Nd(f,o.points);return{walls:f.map((y,v)=>{let[w,x]=[o.points[y.a],o.points[y.b]],[k,M]=[g.get(`${v}:a`),g.get(`${v}:b`)],A=Bd([k.right,M.left,x,M.right,k.left,w],1e-6);return{id:My(w,x),a:[w[0],w[1]],b:[x[0],x[1]],left:y.left,right:y.right,exterior:y.exterior,roomLeft:y.roomLeft,roomRight:y.roomRight,sources:y.sources,footprint:A,...y.free?{free:y.free}:{},...y.height!==void 0?{height:y.height}:{},...y.heightEnd!==void 0?{heightEnd:y.heightEnd}:{}}}),warnings:[...new Set(i)],open:p}}function Wn(t,e,n){let r=t.points[e];return ft(r,it(ot(U(t.points[(e+1)%t.points.length],r)),n))}function Ce(t,e,n){if(t.wall){let i=n.find(l=>l.id===t.wall);if(!i||Math.hypot(i.b[0]-i.a[0],i.b[1]-i.a[1])<.05)return null;let o=ot(U(i.b,i.a));return{room:{id:t.room_id,name:"",area_id:null,points:[i.a,i.b,ft(i.a,[-o[1],o[0]])]},edge:0}}let r=e.find(i=>i.id===t.room_id);return r&&t.edgete(U(e,t.a),ot(U(t.b,t.a)));function Vt(t,e,n){if(!e.wall)return Ry(t,n.room,n.edge,e.offset);let r=t.find(i=>i.free===e.wall);return r?{wall:r,s:Kd(r,Wn(n.room,0,e.offset))}:null}function Ry(t,e,n,r){for(let i of t)if(i.sources.some(s=>s.room_id===e.id&&s.edge===n&&r>=s.t0-1e-6&&r<=s.t1+1e-6))return{wall:i,s:Kd(i,Wn(e,n,r))};return null}function jd(t,e){let n=t.points.map(h=>h[0]),r=t.points.map(h=>h[1]);if(t.points.length!==4||new Set(n.map(h=>h.toFixed(3))).size!==2||new Set(r.map(h=>h.toFixed(3))).size!==2)return null;let[i,o,s,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,u=(h,f,g)=>c(h.a[f],g)&&c(h.b[f],g),d=o-i-a(h=>u(h,0,i))-a(h=>u(h,0,o)),p=l-s-a(h=>u(h,1,s))-a(h=>u(h,1,l));return[Math.round(d*1e3)/1e3,Math.round(p*1e3)/1e3]}var Ud=([t,e])=>{let n=Math.hypot(t,e)||1;return[t/n,e/n]};function Ey(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 Gd(t,e){let n=t.length;if(n<3||Math.abs(e)<1e-9)return t.map(([i,o])=>[i,o]);let r=Ey(t)>=0?1:-1;return t.map((i,o)=>{let s=t[(o+n-1)%n],l=t[(o+1)%n],[a,c]=Ud([i[0]-s[0],i[1]-s[1]]),[u,d]=Ud([l[0]-i[0],l[1]-i[1]]),p=[c*r,-a*r],h=[d*r,-u*r],f=[p[0]+h[0],p[1]+h[1]],g=Math.hypot(f[0],f[1]);if(g<1e-6)return[i[0]+p[0]*e,i[1]+p[1]*e];let b=(f[0]*p[0]+f[1]*p[1])/g,y=Math.min(4,1/Math.max(.25,b));return[i[0]+f[0]/g*e*y,i[1]+f[1]/g*e*y]})}function Kt(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 Ay(t){let e=([o,s])=>`${Math.round(o*1e3)}:${Math.round(s*1e3)}`,n=new Map;for(let o of t)for(let s of[o.a,o.b])n.set(e(s),[...n.get(e(s))??[],o]);let r=new Set,i=null;for(let o of t){if(r.has(o))continue;r.add(o);let s=[o.a,o.b],l=o.b;for(;;){let c=(n.get(e(l))??[]).find(u=>!r.has(u));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])&&(!i||Math.abs(xe(s))>Math.abs(xe(i)))&&(i=s)}return i}function fa(t,e,n,r){let i=fe(t,{exterior:n,interior:r},e).walls.filter(l=>l.exterior&&!l.free),o=i.length?Ay(i.map(l=>({a:l.a,b:l.b}))):null;if(!o)return null;let s=o.filter((l,a)=>{let c=o[(a+o.length-1)%o.length],u=o[(a+1)%o.length];return Math.abs((l[0]-c[0])*(u[1]-l[1])-(l[1]-c[1])*(u[0]-l[0]))>1e-6});return s.length>=3?Gd(s,n):null}function un(t,e){let n=$e(t),r=Le(t),i=n.w,[o,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=(y,v)=>[y,v,r.y(v)],u=c(l,-o),d=c(a,-o),p=c(a,i+s),h=c(l,i+s),[f,g]=[st(t.pitch_a),st(t.pitch_b)],b=y=>[y,r.vr,r.rh];if(t.ends&&(t.shape==="gable"||t.shape==="hip"||t.shape==="halfhip")){let y=(n.u1-n.u0)/2,v=Math.min(y,Math.min(r.vr,i-r.vr)||i/2),w=Math.min(r.y(0),r.y(i)),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,M=g>1e-6?Math.max(r.vr,i-(x-t.eave_b)/g):r.vr,A=Math.min(y-.1,(r.rh-x)/Math.max(.2,f)),T=[[0,r.y(0)],[r.vr,r.rh],[i,r.y(i)]],F=[[0,r.y(0)],[k,x],[M,x],[i,r.y(i)]],L=(j,Xt,zi)=>{if(j==="hip")return{upA:[],upB:[],ridge:b(Xt===l?n.u0+v*zi:n.u1-v*zi),profile:null};if(j==="halfhip"){let ab=b(Xt===l?n.u0+A:n.u1-A);return{upA:[[Xt,k,x]],upB:[[Xt,M,x]],ridge:ab,profile:F}}return{upA:[],upB:[],ridge:b(Xt),profile:T}},P=L(t.ends[0],l,1),N=L(t.ends[1],a,1),W=[[u,d,...N.upA,N.ridge,P.ridge,...[...P.upA].reverse()],[P.ridge,N.ridge,...[...N.upB].reverse(),p,h,...P.upB]],q=[[P.ridge,N.ridge]];for(let[j,Xt,zi]of[[P,u,h],[N,d,p]])j.profile===null?(W.push(j===P?[h,u,j.ridge]:[d,p,j.ridge]),q.push([Xt,j.ridge],[zi,j.ridge])):j.upA.length&&(W.push(j===P?[j.upB[0],j.upA[0],j.ridge]:[j.upA[0],j.upB[0],j.ridge]),q.push([j.upA[0],j.ridge],[j.upB[0],j.ridge]));let ke=j=>j.profile===null?[]:j.upA.length?[j.upA[0],j.upB[0]]:[j.ridge],At=[u,d,...ke(N),p,h,...[...ke(P)].reverse()];return{faces:W,rim:At,ridges:q,gable:T,endProfiles:[P.profile,N.profile]}}switch(t.shape){case"pent":return{faces:[[u,d,p,h]],rim:[u,d,p,h],ridges:[[p,h]],gable:[[0,r.y(0)],[i,r.y(i)]]};case"hip":case"pyramid":{let y=(n.u1-n.u0)/2,v=t.shape==="pyramid"?y:Math.min(y,Math.min(r.vr,i-r.vr)||i/2),w=b(n.u0+v),x=b(n.u1-v);return t.shape==="pyramid"?{faces:[[u,d,w],[d,p,w],[p,h,w],[h,u,w]],rim:[u,d,p,h],ridges:[[u,w],[h,w],[d,w],[p,w]],gable:null}:{faces:[[u,d,x,w],[w,x,p,h],[h,u,w],[d,p,x]],rim:[u,d,p,h],ridges:[[w,x],[u,w],[h,w],[d,x],[p,x]],gable:null}}case"halfhip":{let y=Math.min(r.y(0),r.y(i)),v=y+(r.rh-y)*Math.min(.9,Math.max(.2,t.halfhip??.55)),w=f>1e-6?Math.min(r.vr,(v-t.eave_a)/f):r.vr,x=g>1e-6?Math.max(r.vr,i-(v-t.eave_b)/g):r.vr,k=Math.min((n.u1-n.u0)/2-.1,(r.rh-v)/Math.max(.2,f)),M=b(n.u0+k),A=b(n.u1-k),T=[l,w,v],F=[l,x,v],L=[a,w,v],P=[a,x,v];return{faces:[[u,d,L,A,M,T],[M,A,P,p,h,F],[F,T,M],[L,P,A]],rim:[u,d,L,P,p,h,F,T],ridges:[[M,A],[T,M],[F,M],[L,A],[P,A]],gable:[[0,r.y(0)],[w,v],[x,v],[i,r.y(i)]]}}case"mansard":{let y=Nr(i,t.eave_a,t.eave_b,f,g),v=[l,y.vla,y.yla],w=[a,y.vla,y.yla],x=[l,i-y.vlb,y.ylb],k=[a,i-y.vlb,y.ylb],M=[l,y.vr,y.rh],A=[a,y.vr,y.rh];return{faces:[[u,d,w,v],[v,w,A,M],[M,A,k,x],[x,k,p,h]],rim:[u,d,w,A,k,p,h,x,M,v],ridges:[[M,A],[v,w],[x,k]],gable:[[0,r.y(0)],[y.vla,y.yla],[y.vr,y.rh],[i-y.vlb,y.ylb],[i,r.y(i)]]}}default:{let y=b(l),v=b(a);return{faces:[[u,d,v,y],[y,v,p,h]],rim:[u,d,v,p,h,y],ridges:[[y,v]],gable:[[0,r.y(0)],[r.vr,r.rh],[i,r.y(i)]]}}}}function Br(t,e,n){let r=null;for(let i of t.faces){if(!C([e,n],i.map(([p,h])=>[p,h])))continue;let[o,s]=i,l=i.slice(2).find(p=>Math.abs((s[0]-o[0])*(p[1]-o[1])-(s[1]-o[1])*(p[0]-o[0]))>1e-9);if(!l)continue;let a=[s[0]-o[0],s[2]-o[2],s[1]-o[1]],c=[l[0]-o[0],l[2]-o[2],l[1]-o[1]],u=[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(u[1])<1e-9)continue;let d=o[2]-(u[0]*(e-o[0])+u[2]*(n-o[1]))/u[1];r=r===null?d:Math.min(r,d)}return r}function Wr(t,e,n){let r=$e(e),i=t.floors.flatMap(d=>d.rooms.filter(p=>p.points.length>=3&&d.elevation+d.height>e.base+.05)),o=d=>d.some(p=>i.some(h=>C(p,h.points))),s=.35,l=[.15,.5,.85].map(d=>r.u0+(r.u1-r.u0)*d),a=[.15,.5,.85].map(d=>r.w*d),c=d=>d?0:n,u=(d,p)=>{let h=e.overhang_sides?.[d];return typeof h=="number"&&Number.isFinite(h)?Math.min(2,Math.max(0,h)):p};return{a:u("a",c(o(l.map(d=>r.at(d,-s))))),b:u("b",c(o(l.map(d=>r.at(d,r.w+s))))),u0:u("u0",c(o(a.map(d=>r.at(r.u0-s,d))))),u1:u("u1",c(o(a.map(d=>r.at(r.u1+s,d)))))}}var go=t=>Math.abs((t.x1-t.x0)*(t.z1-t.z0)),Zd=t=>t.shape==="flat"||t.shape==="parapet",dn=t=>Math.round(t*100)/100;function _o(t,e){let[n,r]=[(e.x0+e.x1)/2,(e.z0+e.z1)/2];return t.filter(o=>{if(o===e||o.dormer||o.open||Zd(o)||go(o)=s.x0&&n<=s.x1&&r>=s.z0&&r<=s.z1}).reduce((o,s)=>o===null||go(s){let[o,s]=e.at(i,e.w/2),[l,a]=Cr(t,o,s);return Br(n,l,a)??r.y(a)}}function ga(t,e){if(Zd(e))return e;let n=$e(e),r=Le(e).rh,i=Ty(t,n),o=i(n.u0)<=i(n.u1),[s,l]=o?[n.u0,n.u1]:[n.u1,n.u0],a=o?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 u={...e},d=l===n.u1;return e.axis==="x"?u[d?"x1":"x0"]=c:u[d?"z1":"z0"]=c,u}var _a=.14,qd=t=>t.shape==="flat"||t.shape==="parapet";function ba(t,e){return!t.open&&Math.min(t.base,t.eave_a,t.eave_b)a+i||pu+i||s.points&&s.points.length>=3&&!C([e,n],s.points))continue;let[h,f]=Cr(s,e,n),g=Math.max(0,s.overhang??r),b=qd(s)?null:Br(un(s,{u0:g,u1:g,a:g,b:g}),h,f);o.push((b??Le(s).y(f))-_a)}return o.length?Math.max(...o):null}function ya(t,e,n){let r=[],i=e+n+_a;for(let o of t.settings.roof.sections??[]){if(o.open||qd(o)||o.shape==="mansard")continue;let s=$e(o),l=Le(o),[a,c]=[st(o.pitch_a),st(o.pitch_b)],u=[];a>1e-6&&u.push((i-o.eave_a)/a),o.shape==="gable"&&c>1e-6&&u.push(s.w-(i-o.eave_b)/c);for(let d of u)d<=.01||d>=s.w-.01||o.shape==="gable"&&Math.abs(l.y(d)-i)>1e-6||r.push([s.at(s.u0,d),s.at(s.u1,d)])}return r}function va(t,e,n,r,i){let o=[];for(let l of[.2,.5,.8])for(let a of[.2,.5,.8])o.push([e+(r-e)*l,n+(i-n)*a]);let s=t.floors.filter(l=>l.rooms.some(a=>a.points.length>=3&&o.some(c=>C(c,a.points)))).map(l=>l.elevation+l.height);return s.length?Math.max(...s):null}function wa(t,e){let n=t.floors.filter(a=>a.rooms.length>0).sort((a,c)=>a.elevation-c.elevation),r=n.filter(a=>a.elevationu.rooms.some(d=>d.points.length>=3&&a.some(p=>C(p,d.points))));if(c)return c}return r.at(-1)??n[0]}var kt=t=>Math.round(t*1e3)/1e3;function ka(t,e=n=>`roof_${n+1}`){let n=t.settings.roof?.pitch??35,r=t.settings.wall_exterior,i=t.floors.filter(a=>a.rooms.some(c=>c.points.length>=3)).sort((a,c)=>c.elevation-a.elevation),o=[],s=[],l=(a,c)=>a.some(u=>C(c,u.points));for(let a of i){let c=a.rooms.filter(b=>b.points.length>=3),u=[...new Set(c.flatMap(b=>b.points.map(y=>kt(y[0]))))].sort((b,y)=>b-y),d=[...new Set(c.flatMap(b=>b.points.map(y=>kt(y[1]))))].sort((b,y)=>b-y),p=d.slice(0,-1).map((b,y)=>u.slice(0,-1).map((v,w)=>{let x=[(u[w]+u[w+1])/2,(d[y]+d[y+1])/2];return l(c,x)&&!l(s,x)})),h=p.map(b=>b.map(()=>!1)),f=(b,y)=>p[y][b]&&!h[y][b],g=a.elevation+a.height;for(let b=0;bf(y+F,w+1)).every(Boolean);)w++;for(let T=b;T<=w;T++)for(let F=y;F<=v;F++)h[T][F]=!0;let[x,k]=[u[y]-r,u[v+1]+r],[M,A]=[d[b]-r,d[w+1]+r];Math.min(k-x,A-M)<.8||o.push({id:e(o.length),x0:kt(x),z0:kt(M),x1:kt(k),z1:kt(A),shape:"gable",axis:k-x>=A-M?"x":"z",eave_a:kt(g),eave_b:kt(g),pitch_a:n,pitch_b:n,base:kt(g),overhang:null})}s.push(...c)}return o}var Ee=Math.PI/180,Ge=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],hn=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2],Vn=t=>Math.hypot(t[0],t[1],t[2]),pn=t=>{let e=Vn(t)||1;return[t[0]/e,t[1]/e,t[2]/e]},Yd=(t,e)=>[t[1]*e[2]-t[2]*e[1],t[2]*e[0]-t[0]*e[2],t[0]*e[1]-t[1]*e[0]],Ze=t=>Math.round(t*100)/100,Kr=([t,e],n)=>(Math.atan2(t,-e)/Ee-n+720)%360;var Jd=.25;function Qd(t,e,n,r,i,o,s){let l=i-n>=o-r,a=l?i-n:o-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?o-r:i-n,pitch:0,span:()=>[0,a],facing:l?[0,1]:[1,0]}}function eh(t,e){let n=pn(Yd(t,e));return n[1]<0?[-n[0],-n[1],-n[2]]:n}var th=t=>{let e=pn([-t[0],0,-t[2]]);return[e[0],e[2]]};function xt(t,e,n,r,i,o,s,l){let a=pn(Ge(i,r)),c=pn(Ge(o,r));return{key:t,section:e,side:n,flat:!1,o:r,eu:a,es:c,n:eh(a,c),lu:Vn(Ge(i,r)),ls:Vn(Ge(o,r)),pitch:s,span:l,facing:th(c)}}function Xd(t,e,n,r,i,o){let s=Vn(Ge(i,r));if(s<.3)return null;let l=pn(Ge(i,r)),a=Ge(o,r),c=a[0]*l[0]+a[1]*l[1]+a[2]*l[2],u=[a[0]-l[0]*c,a[1]-l[1]*c,a[2]-l[2]*c],d=Vn(u);if(d<.3)return null;let p=pn(u),h=f=>{let g=Math.min(1,Math.max(0,f/d));return[c*g,s-(s-c)*g]};return{key:t,section:e,side:n,flat:!1,o:r,eu:l,es:p,n:eh(l,p),lu:s,ls:d,pitch:Math.atan2(p[1],Math.hypot(p[0],p[2]))/Ee,span:h,facing:th(p)}}function zy(t,e){let n=$e(t),r=Le(t),i=(v,w,x)=>{let[k,M]=n.at(v,w);return[k,x,M]},[o,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,u=r.y(-o),d=r.y(n.w+s);if(t.shape==="flat"||t.shape==="parapet"){let[v,w]=[n.at(l,-o),n.at(a,n.w+s)];return[Qd(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+Jd)]}if(t.shape==="pent")return[xt(`${t.id}:a`,t.id,"a",i(l,-o,u),i(a,-o,u),i(l,n.w+s,d),t.pitch_a,()=>[0,c])];if(t.shape==="mansard")return Py(t,n,l,a,o,s);let p=t.shape==="hip"||t.shape==="pyramid",h=(n.u1-n.u0)/2,f=t.shape==="pyramid"?h:p?Math.min(h,Math.min(r.vr,n.w-r.vr)||n.w/2):0,g=p?n.u0+f-l:0,b=p?a-(n.u1-f):0,y=[];if(r.vr>.3){let v=Math.hypot(r.vr+o,r.rh-u);y.push(xt(`${t.id}:a`,t.id,"a",i(l,-o,u),i(a,-o,u),i(l,r.vr,r.rh),t.pitch_a,w=>[g*(w/v),c-b*(w/v)]))}if(n.w-r.vr>.3){let v=Math.hypot(n.w+s-r.vr,r.rh-d);y.push(xt(`${t.id}:b`,t.id,"b",i(a,n.w+s,d),i(l,n.w+s,d),i(a,r.vr,r.rh),t.pitch_b,w=>[b*(w/v),c-g*(w/v)]))}if(p){let v=Xd(`${t.id}:c`,t.id,"c",i(l,n.w+s,d),i(l,-o,u),i(n.u0+f,r.vr,r.rh)),w=Xd(`${t.id}:d`,t.id,"d",i(a,-o,u),i(a,n.w+s,d),i(n.u1-f,r.vr,r.rh));y.push(...[v,w].filter(x=>x!==null))}return y}function Py(t,e,n,r,i,o){let s=Nr(e.w,t.eave_a,t.eave_b,st(t.pitch_a),st(t.pitch_b)),l=(f,g)=>{let[b,y]=e.at(f,g);return[b,s.y(g),y]},a=r-n,c=()=>[0,a],u=(f,g)=>Math.atan2(f,g)/Ee,d=[],[p,h]=[e.w+o,e.w-s.vlb];return s.vla+i>.3&&d.push(xt(`${t.id}:a`,t.id,"a",l(n,-i),l(r,-i),l(n,s.vla),t.pitch_a,c)),s.vr-s.vla>.3&&d.push(xt(`${t.id}:au`,t.id,"a",l(n,s.vla),l(r,s.vla),l(n,s.vr),u(s.rh-s.yla,s.vr-s.vla),c)),s.vlb+o>.3&&d.push(xt(`${t.id}:b`,t.id,"b",l(r,p),l(n,p),l(r,h),t.pitch_b,c)),h-s.vr>.3&&d.push(xt(`${t.id}:bu`,t.id,"b",l(r,h),l(n,h),l(r,s.vr),u(s.rh-s.ylb,h-s.vr),c)),d}function xa(t){return t.floors.filter(n=>n.rooms.some(r=>r.points.length>=3)).sort((n,r)=>r.elevation-n.elevation)[0]??null}function Z(t){let e=t.settings.roof;if(!e||e.type==="none")return[];if(e.type==="custom")return(e.sections??[]).flatMap(w=>zy(w,Wr(t,w,w.overhang??e.overhang)));let n=xa(t);if(!n)return[];let r=n.rooms.flatMap(w=>w.points.map(x=>x[0])),i=n.rooms.flatMap(w=>w.points.map(x=>x[1])),o=t.settings.wall_exterior+e.overhang,[s,l]=[Math.min(...r)-o,Math.max(...r)+o],[a,c]=[Math.min(...i)-o,Math.max(...i)+o],u=n.elevation+n.height;if(e.type==="flat")return[Qd("main",null,s,a,l,c,u+Jd)];let d=l-s>=c-a,p=e.ridge==="short"?!d:d,h=(p?c-a:l-s)/2,f=h*Math.tan(e.pitch*Ee),g=(w,x,k)=>p?[w,u+k,(a+c)/2+x]:[(s+l)/2+x,u+k,w],[b,y]=p?[s,l]:[a,c],v=()=>[0,y-b];return[xt("main:a",null,"a",g(b,-h,0),g(y,-h,0),g(b,0,f),e.pitch,v),xt("main:b",null,"b",g(b,h,0),g(y,h,0),g(b,0,f),e.pitch,v)]}function qe(t,e){let n=[];for(let r of t.floors.filter(i=>!e||i.id===e)){let{walls:i}=fe(r.rooms,{exterior:t.settings.wall_exterior,interior:t.settings.wall_interior},r.walls??[]);for(let o of i){if(!o.exterior&&!o.free)continue;let[s,l]=[o.b[0]-o.a[0],o.b[1]-o.a[1]],a=Math.hypot(s,l);if(a<1.2)continue;let[c,u]=[l/a,-s/a],d=Math.min(r.height,o.height??r.height,o.heightEnd??1/0),p=(h,f,g,b)=>n.push({key:h,section:null,side:"top",flat:!1,o:f,eu:g,es:[0,1,0],n:b,lu:a,ls:d,pitch:90,span:()=>[0,a],facing:[b[0],b[2]],wall:{floorId:r.id}});p(`wall:${r.id}:${o.id}`,[o.a[0]+c*o.right,r.elevation,o.a[1]+u*o.right],[s/a,0,l/a],[c,0,u]),o.free&&p(`wall:${r.id}:${o.id}:back`,[o.b[0]-c*o.left,r.elevation,o.b[1]-u*o.left],[-s/a,0,-l/a],[-c,0,-u])}}return n}var Ne="ground";function bo(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 yo(t,e){let n=(e.rotation??0)*Ee,r=[Math.cos(n),0,Math.sin(n)],i=[-Math.sin(n),0,Math.cos(n)],o=bo(t),s=r[0]*e.u+i[0]*e.v,l=r[2]*e.u+i[2]*e.v,a=o?o.elevation+(e.base!=null?e.base:gu(o,s,l)):e.base??0;return{key:Ne,section:null,side:"top",flat:!0,o:[0,a,0],eu:r,es:i,n:[0,1,0],lu:1e4,ls:1e4,pitch:0,span:()=>[-1e4,1e4],facing:[i[0],i[2]],unbounded:!0}}function Se(t,e,n=Z(t)){return e.face===Ne?yo(t,e):e.face.startsWith("wall:")?qe(t,e.face.split(":")[1]).find(r=>r.key===e.face)??null:n.find(r=>r.key===e.face)??null}var vo=1.13,Ur=1.72,Ye=.025,at=.07;function fn(t){let e=t.module_w||vo,n=t.module_h||Ur;return t.portrait===!1?[n,e]:[e,n]}function Gr(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 $a(t,e){return t.flat?Math.min(45,Math.max(0,e.tilt??15))*Ee:t.wall?Math.min(90,Math.max(0,e.tilt??0))*Ee:Math.min(45,Math.max(0,e.tilt??0))*Ee}function Zr(t,e){let[,n]=fn(e),r=$a(t,e);return t.wall?n*Math.cos(r)+Ye:!t.flat&&r<.001?n+Ye:t.flat&&e.rack==="ew"?n*Math.cos(r)+.08:n*Math.cos(r)+Math.max(.3,2*n*Math.sin(r))}function Kn(t,e){let[n,r]=fn(e),i=Gr(e),o=Math.max(1,...i);return[o*n+(o-1)*Ye,(i.length-1)*Zr(t,e)+r*Math.cos($a(t,e))]}var Dy=t=>t.flat&&!t.unbounded&&!t.wall;function nh(t,e){if(!Dy(t)||!e.rotation)return null;let n=e.rotation*Ee,[r,i]=Kn(t,e);return{cos:Math.cos(n),sin:Math.sin(n),u:e.u+r/2,s:e.v+i/2}}function Xe(t,e,n=!1){let[r,i]=fn(e),o=$a(t,e),s=i*Math.cos(o),l=Zr(t,e),a=Gr(e),c=Math.max(1,...a),u=new Set(e.skip??[]),d=nh(t,e),p=(b,y)=>d?[d.u+(b-d.u)*d.cos-(y-d.s)*d.sin,d.s+(b-d.u)*d.sin+(y-d.s)*d.cos]:[b,y],h=(b,y,v)=>{let[w,x]=p(b,y);return[0,1,2].map(k=>t.o[k]+t.eu[k]*w+t.es[k]*x+t.n[k]*v)},f=(b,y)=>{let[v,w]=p(b,y);if(t.unbounded)return!0;if(w<-1e-6||w>t.ls+1e-6)return!1;let[x,k]=t.span(w);return v>=x-1e-6&&v<=k+1e-6},g=[];return a.forEach((b,y)=>{let v=e.align==="right"?c-b:e.align==="center"?(c-b)/2:0;for(let w=0;w.001?s:i);if([[M,T],[A,T],[A,F],[M,F]].every(([L,P])=>f(L,P)))if(t.wall&&o>.001){let L=at+i*Math.sin(o),[P,N]=e.flip?[L,at]:[at,L],W=[h(M,T,P),h(A,T,P),h(A,F,N),h(M,F,N)],q=e.flip?T:F;g.push({corners:W,posts:[M+.05,A-.05].map(ke=>[h(ke,q,0),h(ke,q,L)]),cell:x,skipped:k})}else if(!t.flat&&o>.001){let L=at+i*Math.sin(o),P=[h(M,T,at),h(A,T,at),h(A,F,L),h(M,F,L)];g.push({corners:P,posts:[M+.05,A-.05].map(N=>[h(N,F,0),h(N,F,L)]),cell:x,skipped:k})}else if(!t.flat)g.push({corners:[h(M,T,at),h(A,T,at),h(A,F,at),h(M,F,at)],posts:[],cell:x,skipped:k});else{let P=.15+i*Math.sin(o),N=e.rack==="ew"&&y%2===1?!e.flip:!!e.flip,[W,q]=N?[F,T]:[T,F],ke=[h(M,W,.15),h(A,W,.15),h(A,q,P),h(M,q,P)],At=[M+.05,A-.05].flatMap(j=>[[h(j,W,0),h(j,W,.15)],[h(j,q,0),h(j,q,P)]]);g.push({corners:ke,posts:At,cell:x,skipped:k})}}}),g}function mt(t,e){if(t.unbounded)return{u:e.u,v:e.v};let[n,r]=Kn(t,e),i=nh(t,e);if(i){let[s,l]=[(n*Math.abs(i.cos)+r*Math.abs(i.sin))/2,(n*Math.abs(i.sin)+r*Math.abs(i.cos))/2],a=(d,p,h)=>Math.floor(Math.max(p,Math.min(d,h-p))*100+1e-6)/100,[c,u]=[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(u,l,t.ls)-r/2)*100)/100}}let o=s=>Math.floor(s*100+1e-6)/100;return{u:o(Math.min(Math.max(0,e.u),Math.max(0,t.lu-n))),v:o(Math.min(Math.max(0,e.v),Math.max(0,t.ls-r)))}}function qr(t,e){let[n,r]=Kn(t,e),[i,o]=[e.u+n/2,e.v+r/2];return[t.o[0]+t.eu[0]*i+t.es[0]*o,t.o[2]+t.eu[2]*i+t.es[2]*o]}var wo=.78,Yr=1.18,mn=t=>({id:t.id,face:t.face,u:t.u,v:t.v,rows:1,cols:1,portrait:!0,module_w:t.w||wo,module_h:t.h||Yr});function Sa(t,e){let n=Xe(t,mn(e))[0];if(!n)return null;let r=i=>[i[0]-t.n[0]*.05,i[1]-t.n[1]*.05,i[2]-t.n[2]*.05];return n.corners.map(r)}var jr={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 gn(t){let e=t.shape??"brick",n=jr[e]??jr.brick;return{shape:e,w:t.w||n.w,d:t.d||n.d,h:t.h||n.h}}function $t(t,e){let{w:n,d:r}=gn(t),i=e&&!e.flat?Math.cos(e.pitch*Ee):1;return{id:t.id,face:t.face,u:t.u,v:t.v,rows:1,cols:1,portrait:!0,module_w:n,module_h:r/Math.max(.2,i),tilt:0}}function Ma(t,e){let n=$t(e,t),[r,i]=[n.module_w,n.module_h],o=(u,d)=>[t.o[0]+t.eu[0]*u+t.es[0]*d,t.o[1]+t.eu[1]*u+t.es[1]*d,t.o[2]+t.eu[2]*u+t.es[2]*d],[s,l]=[o(e.u+r/2,e.v),o(e.u+r/2,e.v+i)],a=o(e.u+r/2,e.v+i/2),c=u=>{let d=Math.hypot(u[0],u[2])||1;return[u[0]/d,u[2]/d]};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 Ra(t,e){let[n]=fn(e);return Ze((t.lu-(e.cols*n+(e.cols-1)*Ye))/2)}var Xr=.4;function jn(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]=fn(n),[i,o]=t.span(t.ls/2);for(n.cols=Math.max(1,Math.floor((o-i-2*Xr+Ye)/(r+Ye))),n.rows=Math.max(1,Math.min(4,Math.floor((t.ls-2*Xr)/Zr(t,n))));n.cols>1&&Xe(t,{...n,u:Ra(t,n),v:Xr}).lengthl.lu*(1.3+Math.cos((Kr(l.facing,r)-180)*Math.PI/180)),o=qe(t,n).sort((l,a)=>i(a)-i(l))[0];if(!o)return null;let s={...jn(o,e),portrait:!1,rows:1};return s.cols=Math.max(1,Math.floor((o.lu-.8+Ye)/(Ur+Ye))),s.u=Ze((o.lu-(s.cols*Ur+(s.cols-1)*Ye))/2),s.v=Ze(Math.max(0,o.ls-vo-.3)),s}function Jr(t,e){let n=t.floors.flatMap(o=>o.rooms.flatMap(s=>s.points)),r=n.length?Math.max(...n.map(o=>o[0]))+3:0,i=n.length?Math.min(...n.map(o=>o[1])):0;return{id:e,face:Ne,u:Ze(r),v:Ze(i),rows:2,cols:4,portrait:!0,tilt:25,flip:!0,rotation:(t.settings.north??0)||0,look:"black",entity:null}}function Qr(t,e,n){let r=yo(t,e),[i,o]=Kn(r,e),[s,l]=[e.u+i/2,e.v+o/2],a=[r.eu[0]*s+r.es[0]*l,r.eu[2]*s+r.es[2]*l],c=n*Ee,u=a[0]*Math.cos(c)+a[1]*Math.sin(c)-i/2,d=a[0]*-Math.sin(c)+a[1]*Math.cos(c)-o/2;return{u:Ze(u),v:Ze(d),rotation:(Math.round(n)%360+360)%360}}function ei(t,e){let[n,r]=t.span(t.ls/2);return{id:e,face:t.key,u:Ze((n+r-wo)/2),v:Ze(Math.max(0,Math.min(t.ls-Yr,t.ls*.45-Yr/2))),w:null,h:null,cover:null,contact:null,tilt:null}}function ti(t,e){let n=jr.brick,[r,i]=t.span(t.ls*.8),o=$t({id:e,face:t.key,u:0,v:0},t).module_h;return{id:e,face:t.key,u:Ze((r+i-n.w)/2),v:Ze(Math.max(0,Math.min(t.ls-o,t.ls*.8-o/2))),shape:"brick",w:null,d:null,h:null}}function Un(t,e){let[n,r]=[e[0]-t.o[0],e[1]-t.o[2]],[i,o,s,l]=[t.eu[0],t.eu[2],t.es[0],t.es[2]],a=i*l-o*s;if(Math.abs(a)<1e-9)return null;let c=(n*l-r*s)/a,u=(i*r-o*n)/a;if(u<0||u>t.ls)return null;let[d,p]=t.span(u);return c>=d&&c<=p?{u:c,s:u}:null}function Aa(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],u=a>=0&&a<=r.lu;if(u&&c>=-.05&&c<=.35)return{face:r,u:a,s:Number.NaN};u&&c>.35&&c<=.8&&!n&&(n={face:r,u:a,s:Number.NaN,y:-1/0});continue}let i=Un(r,e);if(!i)continue;let o=r.o[1]+r.es[1]*i.s;(!n||o>n.y)&&(n={face:r,...i,y:o})}return n&&{face:n.face,u:n.u,s:n.s}}function xo(t,e,n){let r=hn(n,t.n);if(Math.abs(r)<1e-6)return null;let i=hn(Ge(t.o,e),t.n)/r;if(i<=0)return null;let o=Ge([e[0]+n[0]*i,e[1]+n[1]*i,e[2]+n[2]*i],t.o);return{t:i,u:hn(o,t.eu),s:hn(o,t.es)}}function Fa(t,e,n){if(t.unbounded)return!0;if(n<0||n>t.ls)return!1;let[r,i]=t.span(n);return e>=r&&e<=i}function Ta(t,e,n,r){return Xe(t,e).some(o=>{let s=o.corners.map(c=>{let u=Ge(c,t.o);return[hn(u,t.eu),hn(u,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 Iy=["n","ne","e","se","s","sw","w","nw"],za=(t,e)=>Iy[Math.round(Kr(t.facing,e)/45)%8];function ni(t,e){let n=r=>{if(r.flat)return r.lu*r.ls*.8;let i=Math.cos((Kr(r.facing,e)-180)*Math.PI/180);return r.lu*r.ls*(1.2+i)};return[...t].sort((r,i)=>n(i)-n(r))[0]??null}var sh=["kitchen_row","kitchen_l","bath","bedroom","living","dining","office","kids","hall"],rh={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]]}},ih=t=>typeof t=="string"?t:t[0],$o=t=>typeof t=="string"?nt[t]:t[1],Gn=.05,Oy=.02,oh=t=>Math.round(t*1e3)/1e3;function Hy(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 ah(t,e,n){let r=de(t.points),i=r.x1-r.x0,o=r.z1-r.z0,s=[],l=(a,c,u,d,[p,h,f])=>{s.push({id:n(),type:a,x:oh(c),z:oh(u),rotation:d,w:p,d:h,h:f,variant:null,entity:null,power:null})};for(let[a,c,u]of rh[e].rows){let d=a==="back"||a==="front"?i:o,p=0,h=[];for(let g of u){if(p+$o(g)[0]>d-.1)break;h.push(g),p+=$o(g)[0]}let f=c==="start"?Gn:c==="end"?d-p-Gn:(d-p)/2;for(let g of h){let b=$o(g),y=Hy(r,a,f+b[0]/2,b[1]/2+Oy);l(ih(g),y.x,y.z,y.turn,b),f+=b[0]}}for(let[a,c,u,d]of rh[e].spots){let p=$o(a),h=(b,y,v)=>Math.min(v,Math.max(y,b)),f=h(r.x0+i*c,r.x0+p[0]/2+Gn,r.x1-p[0]/2-Gn),g=h(r.z0+o*u,r.z0+p[1]/2+Gn,r.z1-p[1]/2-Gn);l(ih(a),f,g,d,p)}return s}var Ly=30*Math.PI/180,lh=.05;function Pa(t){let e=t.points.length;return t.points.map((n,r)=>{let i=t.points[(r+1)%e];return Math.hypot(i[0]-n[0],i[1]-n[1])})}function ri(t){return Pa(t).reduce((e,n)=>e+n,0)}function Cy(t,e){let n=Pa(t),r=0;for(let i=0;ih+f,0);if(i<3||!(o>0)||!(n>0))return null;let s=Math.min(n,o),l=(e%o+o)%o,a=0,c=0;for(;a=c+r[a];)c+=r[a],a++;let u=l-c,d=s,p=[];for(let h=0;h<=i&&d>1e-9;h++){let f=r[a]-u,g=Math.min(d,f);g>1e-9&&p.push({edge:a,t0:u,t1:u+g}),d-=g,u=0;let b=(a+1)%i;if(d>1e-9&&Ny(t,a)>Ly)break;a=b}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 Zn(t,e){let n=e[0];return n?{from:Cy(t,n.edge)+n.offset-n.width/2,width:e.reduce((r,i)=>r+i.width,0)}:null}function jt(t,e){return e.front?t.filter(n=>n.front===e.front):[e]}function Ia(t,e){let n=t.points.length,r=1/0,i=0,o=0;for(let s=0;sI("opening")){let s=Da(e,r,i);if(!s)return null;let l=jt(t,n),a=new Set(l.map(h=>h.id)),c=s.length>1?l[0].front??`front-${l[0].id}`:null,u=s.map((h,f)=>({...n,id:f===0?l[0].id:o(),edge:h.edge,offset:h.offset,width:h.width,front:c})),d=[],p=!1;for(let h of t){if(!a.has(h.id)){d.push(h);continue}p||(d.push(...u),p=!0)}return d}var La=globalThis,Oa=La.__nextfloorBuiltin?.de??{},Ha=La.__nextfloorBuiltin?.en??{};La.__nextfloorBuiltin??={de:Oa,en:Ha};var By=()=>typeof $=="object"&&$||{},Wy=globalThis,Vy=Wy.__nextfloorTexts??=new Map;function Ky(t){let e=t.toLowerCase().split("-")[0];return e!=="de"&&e!=="en"&&e in By()?e:void 0}function ch(t){let e=Ky(t),n=e===void 0?void 0:Vy.get(e);return n instanceof Promise?void 0:n}function So(t,e){return ch(t)?.[e]}function we(t,e,n={}){let r=t?.language??navigator.language,i=r.startsWith("de"),o=(i?void 0:ch(r)?.[e])??(i?Oa:Ha)[e]??Ha[e]??Oa[e]??e;for(let[s,l]of Object.entries(n))o=o.replace(`{${s}}`,String(l));return o}function K(t,e,n=2){return e.toLocaleString(t?.language??void 0,{maximumFractionDigits:n})}var jy=new Set(["on","home","open","true","active","playing","heat","heating"]);function uh(t,e){let n=e.show_when;if(!n?.entity||!t)return!0;let r=t.states[n.entity];if(!r||Ie(r))return!0;let i=String(r.state).toLowerCase(),o=(n.state??"").split(",").map(l=>l.trim().toLowerCase()).filter(Boolean),s=o.length?o.includes(i):jy.has(i)||Number.isFinite(Number(i))&&Number(i)>0;return n.invert?!s:s}function Ae(t,e){if(!vt(e))return we(t,`furn_${e}`);let n=G(e);return n?Je(n,e,t?.language??navigator.language):we(t,"pack_missing_item")}function Je(t,e,n){return t.name[n.split("-")[0]]??So(n,e)??Jc(t,n)}function Be(t,e){return So(e,`packname:${t.id}`)??Qc(t,e)}function dh(t,e){return t.name[e.split("-")[0]]??So(e,`color:${t.id}`)??t.name.en??Object.values(t.name)[0]}var oi=t=>t&&t!=="none"?t:null,si=(t,e)=>{e&&!t.includes(e)&&t.push(e)},Ca=t=>new Map(t.floors.flatMap(e=>e.furniture.filter(n=>n.type==="meter").map(n=>[n.id,n])));function _n(t,e){if(!t.energy.advanced||e.type!=="meter"||!e.parent_meter)return null;let n=Ca(t),r=new Set([e.id]);for(let i=n.get(e.parent_meter);i;i=n.get(i.parent_meter??"")){if(r.has(i.id))return null;r.add(i.id)}return n.has(e.parent_meter)?e.parent_meter:null}function qn(t){return new Set([...Ca(t).values()].filter(e=>_n(t,e)).map(e=>e.id))}function ai(t,e){return!t.energy.advanced||!e.parent_meter?null:qn(t).has(e.parent_meter)?e.parent_meter:null}function hh(t,e,n){if(n.type!=="meter"||n.id===e.id)return!1;let r=Ca(t),i=new Set;for(let o=n;o&&!i.has(o.id);o=r.get(o.parent_meter??"")){if(o.id===e.id)return!1;i.add(o.id)}return!0}function Ro(t,e=n=>oi(n.power)){let n={grid:null,gridExport:null,solar:[],battery:[],charge:[],batteries:[],soc:[]};for(let r of t.floors.flatMap(i=>i.furniture)){let i=e(r),o=r.type==="meter"?_n(t,r):null;if(o)(n.subMeters??=[]).push({id:r.id,parent:o,power:i,invert:!!r.meter_invert,floors:r.meter_floors??[],solar:[],batteries:[]});else if(r.type==="meter")n.grid??=i,n.gridExport??=oi(r.export);else if(r.type==="inverter")si(n.solar,i);else if(r.type==="home_battery"){let s=oi(r.charge);si(n.battery,i),si(n.charge,s),si(n.soc,oi(r.soc)),(i||s)&&n.batteries.push({power:i,charge:s})}}for(let r of n.subMeters?t.floors.flatMap(i=>i.furniture):[]){let i=r.type==="inverter"||r.type==="home_battery"?n.subMeters?.find(l=>l.id===ai(t,r)):void 0,o=i?e(r):null;i&&r.type==="inverter"&&si(i.solar,o);let s=oi(r.charge);i&&r.type==="home_battery"&&(o||s)&&i.batteries.push({power:o,charge:s})}return n}function Uy(t){for(let e of t.floors){let n=e.furniture.find(r=>r.type==="meter"&&!_n(t,r));if(n)return{floor_id:e.id,x:n.x,z:n.z}}return t.energy.meter}var Gy=/(phase|_l[123]\b|_[abc]$|today|daily|heute)/,Zy=/_?(energy|energie|total|today|daily|kwh|import|export|consumption|production)/g;function Mo(t,e,n="power"){let r=e?t.entities?.[e]?.device_id:void 0;if(!e||!r)return null;let i=Object.keys(t.states).filter(l=>l.startsWith("sensor.")&&t.entities?.[l]?.device_id===r&&t.states[l]?.attributes.device_class===n);if(i.length<=1)return i[0]??null;let o=i.filter(l=>!Gy.test(l)),s=e.replace(/^sensor\./,"").replace(Zy,"");return o.find(l=>s&&l.includes(s))??o[0]??i[0]}function ph(t,e){let n={},r=(i,o)=>{o&&!n[i]&&(n[i]=o)};for(let i of e.energy_sources??[])if(i.type==="grid")r("grid",Mo(t,i.flow_from?.[0]?.stat_energy_from??i.flow_to?.[0]?.stat_energy_to));else if(i.type==="solar")r("solar",Mo(t,i.stat_energy_from));else if(i.type==="battery"){let o=i.stat_energy_from??i.stat_energy_to;r("battery",Mo(t,o)),r("battery_soc",Mo(t,o,"battery"))}return n}function Fe(t,e=!1){let n=t?.attributes.symcon_id?Ht(t):t?Number(t.state):null;if(n===null||!Number.isFinite(n))return null;let r={kW:1e3,MW:1e6}[String(t.attributes.unit_of_measurement??"W")]??1;return e?-n*r:n*r}var qy=(t,e)=>e.startsWith("sensor.")&&t.states[e]?.attributes.device_class==="power";function li(t,e){if(qy(t,e))return e;let n=t.entities?.[e]?.device_id;if(!n)return null;let r=qs(t,n),i=r?Dt(t,e):null,o=so(t,n).filter(s=>s!==e);return(r?o.find(s=>i!==null&&Dt(t,s)===i):o[0])??null}var fh=t=>{let e=t.filter(n=>n!==null);return e.length?e.reduce((n,r)=>n+r,0):null};function Yy(t,e,n){let r=e.grid??n.grid,i=r?Fe(t.states[r],e.grid_invert):null;if(!e.grid&&n.gridExport){let o=Math.max(0,Fe(t.states[n.gridExport])??0);return Math.max(0,i??0)-o}return i}function Xy(t,e,n){return e.solar?Fe(t.states[e.solar]):n.solar.length?fh(n.solar.map(r=>Fe(t.states[r]))):null}function Na(t,e,n){return e.charge?(e.power?Math.max(0,Fe(t.states[e.power])??0):0)-Math.max(0,Fe(t.states[e.charge])??0):e.power?Fe(t.states[e.power],n):null}function Jy(t,e,n){return e.battery?Fe(t.states[e.battery],e.battery_invert):fh(n.batteries.map(r=>Na(t,r,e.battery_invert)))}function Ba(t,e,n,r=Ro(e)){let i=e.energy,o=Yy(t,i,r),s=Xy(t,i,r),l=Jy(t,i,r),a=(i.battery_soc?[i.battery_soc]:r.soc).map(f=>Number(t.states[f]?.state)).filter(Number.isFinite),c=a.length?a.reduce((f,g)=>f+g,0)/a.length:null,u=i.tariff?t.states[i.tariff]:void 0,d=Number(u?.state),p=i.consumption?Fe(t.states[i.consumption]):null;p===null&&(o!==null||s!==null||l!==null)&&(p=(o??0)+Math.max(0,s??0)+(l??0)),p===null&&n.length>0&&(p=n.reduce((f,g)=>f+g.power,0));let h={grid:o,solar:s===null?null:Math.max(0,s),battery:l,soc:c,tariff:u&&Number.isFinite(d)?{value:d,unit:String(u.attributes.unit_of_measurement??"")}:null,consumption:p===null?null:Math.max(0,p)};return r.subMeters?{...h,...Qy(t,r,h.consumption,i.battery_invert,n)}:h}function Qy(t,e,n,r,i){let o=e.subMeters??[],s=new Map;for(let p of o)for(let h of p.floors)s.has(h)||s.set(h,p.id);let l=new Set([e.grid,e.gridExport,...e.solar,...e.battery,...e.charge,...o.flatMap(p=>[p.power,...p.solar,...p.batteries.flatMap(h=>[h.power,h.charge])])]),a=p=>i.filter(h=>s.get(h.floorId)===p&&!l.has(h.powerEntity)).reduce((h,f)=>h+f.power,0),c=new Map(o.map(p=>[p.id,p.power?Fe(t.states[p.power],p.invert):null])),u=o.map(p=>{let h=c.get(p.id)??null,f=p.solar.reduce((v,w)=>v+Math.max(0,Fe(t.states[w])??0),0),g=p.batteries.reduce((v,w)=>v+(Na(t,w,r)??0),0),b=o.filter(v=>v.parent===p.id).reduce((v,w)=>v+(c.get(w.id)??0),0),y=h===null?null:Math.max(0,h+f+g-b);return{id:p.id,parent:p.parent,power:h,solar:f,battery:g,use:y,unmetered:y===null?null:Math.max(0,y-a(p.id))}}),d=u.reduce((p,h)=>p+(h.use??0),0);return{subMeters:u,rest:n===null?null:Math.max(0,n-d)}}function ev(t,e,n){let r=t.b[0]-t.a[0],i=t.b[1]-t.a[1],o=Math.hypot(r,i)||1,s=Math.min(1,Math.max(0,((e.x-t.a[0])*r+(e.z-t.a[1])*i)/(o*o))),l=t.a[0]+r*s,a=t.a[1]+i*s,c=i/o*(l-n.x)+-r/o*(a-n.z)<0?-1:1;return{x:l,z:a,nx:c*i/o,nz:-c*r/o,distance:Math.hypot(e.x-l,e.z-a)}}function mh(t){let e=Uy(t),n=e?t.floors.find(c=>c.id===e.floor_id):void 0;if(!e||!n)return null;let r={exterior:t.settings.wall_exterior,interior:t.settings.wall_interior},i=fe(n.rooms,r,n.walls??[]).walls.filter(c=>c.exterior),o=n.rooms.flatMap(c=>c.points);if(i.length===0||o.length===0)return null;let s={x:o.reduce((c,u)=>c+u[0],0)/o.length,z:o.reduce((c,u)=>c+u[1],0)/o.length},l=i.map(c=>ev(c,e,s)).reduce((c,u)=>u.distancetv.includes(t),Wa=(t,e="Heizkreis")=>({id:t,name:e,kind:"heating",has_pump:!0,has_valve:!0});function Va(t){return{card:!0,...t==="heating_manifold"?{circuits:[Wa("c1","Heizkreis 1")]}:{},...t==="buffer_tank"?{sensors:Array.from({length:7},(e,n)=>({id:`s${n+1}`,name:`F\xFChler ${n+1}`,entity:null,level:1-n/6}))}:{}}}function Eo(t){return{...Va(t.type),...t.hydronic}}var Xn=t=>t.has_pump!==!1,Ka=t=>t.kind!=="pump"&&t.has_valve!==!1;var ci=t=>!!t&&t!=="none";var Fo=(t,e)=>String(t.states[e]?.attributes.symcon_source_entity||e);function Ao(t,e){let n=t.states[Fo(t,e)]?.attributes;return n?.device_class==="power"||/^[km]?w$/i.test(String(n?.unit_of_measurement??"").trim())}function gh(t,e){let n=new Map;if(!X(t))return n;let r=Me(t,[e]),i=(o,s,l,a,c)=>{if(!ci(c))return;let u=e.rooms.find(p=>p.points.length>=3&&C([l,a],p.points));if(!u)return;let d=n.get(u.id)??[];d.push({id:o,name:s,source:Fo(t,c)}),n.set(u.id,d)};for(let o of e.furniture){if(!uh(t,o))continue;let s=o.name||Ae(t,o.type),l=(o.values??[]).find(u=>ci(u.entity)&&Ao(t,u.entity)),a=r.get(o.id)?.entity,c=o.power==="none"?null:o.power||r.get(o.id)?.power||(a&&Ao(t,a)?a:null);if(i(`furniture:${o.id}`,s,o.x,o.z,c||l?.entity),!c&&!l){let u=new Set;for(let d of o.gang_entities??[]){if(!ci(d))continue;let p=li(t,d);!p||u.has(Fo(t,p))||(u.add(Fo(t,p)),i(`furniture:${o.id}:${d}`,`${s} \xB7 ${B(t,d)}`,o.x,o.z,p))}}if(Yn(o.type))for(let u of Eo(o).circuits??[])Xn(u)&&i(`furniture:${o.id}:${u.id}`,`${s} \xB7 ${u.name||"Pumpe"}`,o.x,o.z,u.power)}for(let o of e.placements){if(o.outside)continue;let s=(o.values??[]).find(a=>ci(a.entity)&&Ao(t,a.entity)),l=Ao(t,o.entity_id)?o.entity_id:li(t,o.entity_id);i(`device:${o.entity_id}`,o.name||B(t,o.entity_id),o.x,o.z,l||s?.entity)}return n}var St={electricity:"Strom",water:"Wasser",gas:"Gas",heating:"Heizen",cooling:"K\xFChlen"},Jn={electricity:"\u26A1",water:"\u{1F4A7}",gas:"\u{1F525}",heating:"\u2668",cooling:"\u2744"},zo=t=>t.normalize("NFD").replace(/[\u0300-\u036f]/g,"").toLowerCase().replace(/ß/g,"ss").replace(/[^a-z0-9]+/g," ").trim(),nv="{485D0419-BE97-4548-AA9C-C083EB82E61E}",rv=t=>t.object_type!==0&&!(t.object_type===1&&t.module_id?.toUpperCase()===nv)?null:{elektro:"electricity",strom:"electricity","elektro strom":"electricity","strom elektro":"electricity",wasser:"water",gas:"gas",heizen:"heating",heizung:"heating",warme:"heating",waerme:"heating",kuhlen:"cooling",kuehlen:"cooling",kuhlung:"cooling",kuehlung:"cooling",kalte:"cooling",kaelte:"cooling"}[zo(t.name)]??null,To=t=>/^symcon-category-(\d+)$/.exec(t??"")?.[1],Ua=t=>/\b(heute|tag|tagesverbrauch|today|daily)\b/.test(t)?"day":/monat|month/.test(t)?"month":/jahr|year/.test(t)?"year":"total",Po=(t,e)=>String(t.states[e]?.attributes.symcon_source_entity||e);function yh(t){let e=String(t?.attributes.unit_of_measurement??"").trim(),n=e.replace(/[³]/g,"3").replace(/[²]/g,"2").replace(/\s+/g,"").toLowerCase();return["w","kw","mw"].includes(n)?{metric:"power",unit:"W",factor:e==="mW"?.001:n==="kw"?1e3:n==="mw"?1e6:1}:["wh","kwh","mwh","j","kj","mj","gj"].includes(n)?{metric:"energy",unit:"kWh",factor:{wh:.001,kwh:1,mwh:1e3,j:1/36e5,kj:1/3600,mj:1/3.6,gj:1e3/3.6}[n]}:["m3/h","m3h","m3/min","m3/s","l/h","l/min","l/s","liter/h","liter/min"].includes(n)?{metric:"power",unit:"m\xB3/h",factor:{"m3/h":1,m3h:1,"m3/min":60,"m3/s":3600,"l/h":.001,"l/min":.06,"l/s":3.6,"liter/h":.001,"liter/min":.06}[n]}:["m3","l","liter"].includes(n)?{metric:"energy",unit:"m\xB3",factor:n==="m3"?1:.001}:null}function iv(t,e){if(!e.entity_id||e.object_type!==2&&e.object_type!==6)return null;let n=Po(t,e.entity_id),r=t.states[n];if(!r||![1,2].includes(Number(r.attributes.symcon_variable_type)))return null;let i=zo(e.name),o=yh(r),s=/^(leistung|wirkleistung|gesamtleistung|aktuelle leistung|durchfluss|volumenstrom)(\b|$)/.test(i),l=/^(verbrauch|energie|energieverbrauch|gesamtverbrauch|gesamtenergie|zahlerstand|zaehlerstand|arbeit)(\b|$)/.test(i),a=o?.metric??(s?"power":l?"energy":null);if(!a)return null;let c=a==="power"?/^(leistung|wirkleistung|gesamtleistung|durchfluss|volumenstrom)$/.test(i):/^(verbrauch|energie|energieverbrauch|gesamtverbrauch|gesamtenergie|zahlerstand|zaehlerstand|arbeit)$/.test(i),u=a==="energy"?Ua(i):"total";return{metric:a,source:n,period:u,group:`${a}|${o?.unit??String(r.attributes.unit_of_measurement??"")}|${u}`,score:/^gesamt(leistung|verbrauch|energie)$/.test(i)?110:c?100:(a==="power"?s:l)?70:20}}var _h=new WeakMap,bh=new WeakMap;function vh(t){let e=_h.get(t);if(e)return e;let n={nodes:new Map(t.map(r=>[r.object_id,r])),children:new Map};for(let r of t){let i=n.children.get(r.parent_id)??[];i.push(r),n.children.set(r.parent_id,i)}return _h.set(t,n),n}function ov(t,e,n){if(!X(t))return[];let r=[e.area_id,...e.sub_areas??[]].map(To).filter(p=>!!p);if(!r.length)return[];let i=new Set(n.filter(p=>p.id!==e.id).flatMap(p=>[p.area_id,...p.sub_areas??[]]).map(To).filter(p=>!!p&&!r.includes(p))),o=`${r.join(",")}|${[...i].sort().join(",")}`,s=bh.get(t)??new Map;bh.set(t,s);let l=s.get(o);if(l)return l;let a=vh(t.symconObjects),c=[],u=new Set,d=(p,h,f)=>{if(u.has(p)||i.has(String(p)))return;u.add(p);let g=a.nodes.get(p);if(!g)return;let b=rv(g),y=b??h,v=new Set(b&&b!==h?[]:f),w=a.children.get(p)??[];if(y){let x=w.map(k=>iv(t,k)).filter(k=>k!==null);for(let k of new Set(x.map(M=>M.group))){if(v.has(k))continue;let M=x.filter(F=>F.group===k),A=Math.max(...M.map(F=>F.score)),T=M.filter(F=>F.score===A);for(let F of A>=100?T.slice(0,1):T)c.push({kind:y,metric:F.metric,id:F.source,period:F.period});v.add(k)}}for(let x of w)(x.object_type===0||x.object_type===1)&&d(x.object_id,y,v)};for(let p of r)d(Number(p),null,new Set);return s.set(o,c),c}function ui(t,e,n=!1){let r=new Map,i=new Set;for(let o of e){let s=Po(t,o.id),l=`${o.kind}|${o.metric}|${s}`;if(i.has(l))continue;i.add(l);let a=t.states[s],c=yh(a),u=c?.metric===o.metric?c.unit:String(a?.attributes.unit_of_measurement??"").trim(),d=`${o.kind}|${o.metric}|${u}|${o.period}`,p=r.get(d)??{kind:o.kind,metric:o.metric,unit:u,value:null,period:o.period,sources:[],manual:n,incomplete:!1},h=Ht(a);h===null?p.incomplete=!0:p.value=(p.value??0)+h*(c?.metric===o.metric?c.factor:1),p.sources.push(s),r.set(d,p)}return[...r.values()]}function ja(t,e){return wt.flatMap(n=>["power","energy"].flatMap(r=>{let i=e.utility_meters?.[n]?.[r];if(!i||i==="none")return[];let o=Po(t,i);return[{kind:n,metric:r,id:o,period:r==="energy"?Ua(zo(String(t.states[o]?.attributes.friendly_name??""))):"total"}]}))}function sv(t,e){return X(t)?ui(t,ja(t,e),!0):[]}function av(t,e,n=e.rooms,r=!1){if(!X(t))return[];let i=r?gh(t,e):new Map,o=new Map;for(let l of e.rooms){let a=[...new Set([l.area_id,...l.sub_areas??[]].filter(c=>!!To(c)))];!a.length&&(ja(t,l).length||i.get(l.id)?.length)&&a.push("unassigned");for(let c of a){let u=o.get(c)??{seed:l,members:[]};c===a[0]&&u.members.push(l),o.set(c,u)}}let s=vh(t.symconObjects).nodes;return[...o].map(([l,a])=>{let c=s.get(Number(To(l))),u=l==="unassigned"?[]:ui(t,ov(t,{...a.seed,area_id:l,sub_areas:null},n)),d=ui(t,a.members.flatMap(f=>ja(t,f)),!0),p=f=>u.some(g=>g.kind===f.kind&&g.metric===f.metric&&g.unit===f.unit&&g.period===f.period),h=a.members.map(f=>({id:f.id,name:f.name,readings:sv(t,f),devices:(i.get(f.id)??[]).map(g=>({id:g.id,name:g.name,readings:ui(t,[{kind:"electricity",metric:"power",id:g.source,period:"total"}],!0)}))})).filter(f=>f.readings.length||f.devices.length);return{id:l,name:l==="unassigned"?"Nicht zugeordnet":c?.name||t.areas?.[l]?.name||"Bereich nicht verf\xFCgbar",path:c?.path||"",readings:[...u,...d.filter(f=>!p(f))],rooms:h}}).filter(l=>l.readings.length||l.rooms.length)}function Ga(t,e,n,r){let i=e.utility_meters?.[n],o=i&&Object.prototype.hasOwnProperty.call(i,r)?i[r]:n==="electricity"&&r==="power"?e.power_entity:null;return o&&o!=="none"?Po(t,o):null}function wh(t,e,n=e.rooms){let r=av(t,e,n).flatMap(o=>o.readings.flatMap(s=>s.sources.map(l=>({kind:s.kind,metric:s.metric,period:s.period,id:l})))),i=[];for(let o of wt)for(let s of["power","energy"]){let l=Ga(t,e,o,s);i.push(...ui(t,l?[{kind:o,metric:s,id:l,period:s==="energy"?Ua(zo(String(t.states[l]?.attributes.friendly_name??""))):"total"}]:r.filter(a=>a.kind===o&&a.metric===s),!!l))}return i}function Za(t){return t.metric==="power"?t.unit==="m\xB3/h"?"Durchfluss":"Leistung":{total:"Verbrauch",day:"Verbrauch heute",month:"Verbrauch Monat",year:"Verbrauch Jahr"}[t.period]}function kh(t,e){let n=e.incomplete?"Err: ":"";if(e.value===null)return`${n}\u2013`;let r=e.unit==="W"&&Math.abs(e.value)>=1e3?e.value/1e3:e.value,i=e.unit==="W"&&Math.abs(e.value)>=1e3?"kW":e.unit,o=Number.isInteger(r)?0:Math.min(6,Math.max(2,1-Math.floor(Math.log10(Math.abs(r)))));return`${n}${K(t,r,o)}${i?` ${i}`:""}`}var xh=[{key:"supply_vsr",label:"Zuluft-VSR",types:[0,1,2],control:!0},{key:"extract_vsr",label:"Abluft-VSR",types:[0,1,2],control:!0},{key:"supply_temperature",label:"Zulufttemperatur",types:[1,2]},{key:"extract_temperature",label:"Ablufttemperatur",types:[1,2]},{key:"reheat",label:"NHR (Nachheizregister)",types:[0,1,2],control:!0},{key:"status",label:"Raumstatus",types:[1]}];function $h(t,e,n){let r=O(t.hass,i=>He(t.hass,i,[1,2]));return m`Eigene Raumzähler
${S("Nur direkt zugewiesene Raumz\xE4hler erscheinen als einger\xFCckte Raumzeile unter dem verkn\xFCpften Bereich. Die Bereichswerte stehen einmal beim Bereich; vorhandene Bereichssummen enthalten die Raumwerte bereits. Fehlt dem Bereich ein passender Z\xE4hler, werden daf\xFCr die eigenen Raumz\xE4hler summiert.","nf-wide")}
${wt.map(i=>m`${Jn[i]} ${St[i]}${["power","energy"].map(o=>z(t,o==="power"?"Leistung / Durchfluss":"Energie / Verbrauch",e.utility_meters?.[i]?.[o]??null,void 0,r,s=>{let l={...e.utility_meters,[i]:{...e.utility_meters?.[i],[o]:s==="none"?null:s}};Object.values(l[i]).some(a=>a&&a!=="none")||delete l[i],n({utility_meters:Object.keys(l).length?l:null})},{types:[1,2]}))}`)}
`}function Sh(t,e,n){let r=s=>n({hvac:{...e.hvac,...s}}),i=e.hvac?.schedules??[],o=O(t.hass,s=>!!t.hass?.states[s]?.attributes.symcon_schedule);return m`
${z(t,t.t("floor_heating"),e.floor_heating??null,void 0,O(t.hass,s=>He(t.hass,s,[0,1,2])),s=>n({floor_heating:s==="none"?null:s}),{types:[0,1,2]})}
${xh.map(s=>z(t,s.label,e.hvac?.[s.key]??null,void 0,O(t.hass,l=>He(t.hass,l,s.types)),l=>r({[s.key]:l==="none"?null:l}),{types:s.types}))}
${S("Raumstatus zeigt den in Symcon hinterlegten Alias der Integer-Variable. Beschreibbare Heizungs- und L\xFCftungswerte k\xF6nnen im Raummen\xFC bedient werden.","nf-wide")}
${i.map((s,l)=>z(t,`Schaltuhr ${l+1}`,s,void 0,o.filter(a=>a.id===s||!i.includes(a.id)),a=>r({schedules:a&&a!=="none"?i.map((c,u)=>l===u?a:c):i.filter((c,u)=>l!==u)}),{schedule:!0,excluded:a=>i.includes(a)?"Diese Schaltuhr ist in diesem Raum bereits verkn\xFCpft.":void 0}))}
${z(t,"Schaltuhr hinzuf\xFCgen",null,void 0,o.filter(s=>!i.includes(s.id)),s=>s&&s!=="none"&&r({schedules:[...i,s]}),{schedule:!0,excluded:s=>i.includes(s)?"Diese Schaltuhr ist in diesem Raum bereits verkn\xFCpft.":void 0})}`}function Mh(t,e,n){let r=i=>i==="condition"?[0,1,2,3]:i==="wind_bearing"?[1,2,3]:["snow","fog","lightning"].includes(i)?[0,1,2]:[1,2];return m`Wettervariablen
${ou.map(i=>z(t,Ju[i],e.weather_variables?.[i]??null,void 0,O(t.hass,o=>He(t.hass,o,r(i))),o=>n({weather_variables:{...e.weather_variables,[i]:o==="none"?null:o}}),{types:r(i)}))}
${z(t,t.t("rain_sensor"),e.rain_sensor??null,void 0,O(t.hass,i=>He(t.hass,i,[0,1,2])),i=>n({rain_sensor:i==="none"?null:i}),{types:[0,1,2]})}
${e.rain_sensor?D(t,t.t("rain_sensor_inverted"),!!e.rain_sensor_inverted,i=>n({rain_sensor_inverted:i||void 0})):_}
${S("W\xE4hle die Wetterwerte einzeln aus dem Symcon-Objektbaum. Einheiten werden aus den Variablen \xFCbernommen. Der Regensensor kann Boolean oder eine numerische Regenrate sein.","nf-wide")}
${V(t,"Person",s.name??B(t.hass,s.person),a=>r(l,{name:a}),{wide:!0,maxlength:100})}
${z(t,"Anwesenheit (Boolean)",s.person,void 0,o.filter(a=>a.id===s.person||!e.some(c=>c.person===a.id)),a=>a&&a!=="none"?r(l,{person:a}):n(e.filter((c,u)=>u!==l)),{types:[0],excluded:a=>e.some(c=>c.person===a)?"Diese Anwesenheitsvariable ist bereits mit einer Person verkn\xFCpft.":void 0})}
`)}
${z(t,"Person hinzuf\xFCgen (Boolean)",null,void 0,o.filter(s=>!e.some(l=>l.person===s.id)),s=>s&&s!=="none"&&n([...e,{person:s,sensor:null}]),{types:[0],excluded:s=>e.some(l=>l.person===s)?"Diese Anwesenheitsvariable ist bereits mit einer Person verkn\xFCpft.":void 0})}
${S("Jede Person wird mit einer beliebigen Boolean-Variable verkn\xFCpft: true bedeutet anwesend, false abwesend. Ein Raum ist optional und bestimmt die Position der Person in 3D.")}
`}function Eh(t,e,n){let r=t.find(a=>a.person===e),i="sensor"in n?n.sensor&&n.sensor!=="none"?n.sensor:null:r?.sensor??null,o="room"in n?n.room||null:r?.room??null,s=t.filter(a=>a.person!==e);if(!i&&!o)return s;let l=o?{person:e,sensor:i,room:o}:{person:e,sensor:i};return r?t.map(a=>a.person===e?l:a):[...s,l]}function Ah(t,e){let n=e.slice(e.indexOf(".")+1),r=i=>i.id.includes(n)&&/(area|room|raum|bermuda|espresense)/.test(i.id);return[...t.filter(r),...t.filter(i=>!r(i))]}function Fh(t){let e=t.target?`, target: { x: ${t.target.x}, y: ${t.target.y}, z: ${t.target.z} }`:"";return`start_view: { theta: ${t.theta}, phi: ${t.phi}, radius: ${t.radius}${e} }`}function Th(t){let e=t.trim();if(!e)return{ok:!0,value:null};try{let n=JSON.parse(e);return n&&typeof n=="object"&&!Array.isArray(n)?{ok:!0,value:n}:{ok:!1}}catch{return{ok:!1}}}function Do(t,e,n){let r=[...t],[i]=r.splice(e,1);return r.splice(Math.max(0,Math.min(r.length,e+n)),0,i),r}var Ut=(t,e)=>t.filter((n,r)=>r!==e),di=(t,e,n)=>t.map((r,i)=>i===e?{...r,...n}:r),gt=t=>t.length>0?t:void 0;var lv=["scene","script","automation","button","input_button","switch","input_boolean","light","fan","cover","lock"],cv=40,uv=20,dv=30,hv=["music","url","playlist","SPOTIFY","AMAZON_MUSIC","TUNEIN","APPLE_MUSIC"],qa={navigate:"/lovelace/rollos",more_info:"cover.wohnzimmer",service:"script.turn_on",fire_dom_event:""},hi=(t,e,n,r=!1)=>m``;function pv(t){let e=t.doc.settings.favorites??[],n=l=>t.change(a=>a.settings.favorites=gt(l)),r=t.doc.floors,i=t.doc.settings.favorite_floors??{},o=O(t.hass,l=>lv.includes(l.split(".")[0])&&!e.includes(l)),s=(l,a)=>m`
${z(t,t.t("outside_hidden_add"),null,void 0,o,s=>s&&s!=="none"&&!n.includes(s)&&r([...n,s]),{excluded:s=>n.includes(s)?"Diese Variable ist hier bereits eingetragen.":void 0})}
${z(t,o("favorites_add"),null,void 0,r,l=>l&&l!=="none"&&!e.includes(l)&&n([...e,l]),{unsupported:"Dieses Feld ben\xF6tigt eine Kalenderquelle mit Terminen. Eine Symcon-Variable ist kein Kalender; Kalenderquellen werden vom Symcon-Modul derzeit nicht bereitgestellt."})}
`:_}
`}var Ho=.05,Mv=(t,e)=>t.length===e.length&&t.every((n,r)=>Math.abs(n[0]-e[r][0])<.001&&Math.abs(n[1]-e[r][1])<.001),bn=t=>new Map(t.map(e=>[e.id,e]));function Rv(t,e,n,r){let i=e.name,[o,s]=[bn(t.rooms),bn(e.rooms)];for(let h of e.rooms){let f=o.get(h.id);f?(f.name!==h.name&&n.push({kind:"room_renamed",floor:i,name:h.name,detail:f.name}),Mv(f.points,h.points)||n.push({kind:"room_reshaped",floor:i,name:h.name,detail:Math.round((xe(h.points)-xe(f.points))*10)/10})):n.push({kind:"room_added",floor:i,name:h.name})}for(let h of t.rooms)s.has(h.id)||n.push({kind:"room_removed",floor:i,name:h.name});let[l,a]=[bn(t.openings),bn(e.openings)];for(let h of e.openings)l.has(h.id)||n.push({kind:"opening_added",floor:i,name:h.type,detail:r(h.room_id)});for(let h of t.openings)a.has(h.id)||n.push({kind:"opening_removed",floor:i,name:h.type,detail:r(h.room_id)});let[c,u]=[bn(t.furniture),bn(e.furniture)];for(let h of e.furniture){let f=c.get(h.id);f?(Math.hypot(h.x-f.x,h.z-f.z)>Ho||Math.abs(h.rotation-f.rotation)>1||Math.abs(h.w-f.w)>Ho||Math.abs(h.d-f.d)>Ho)&&n.push({kind:"furniture_moved",floor:i,name:h.name||h.type}):n.push({kind:"furniture_added",floor:i,name:h.name||h.type})}for(let h of t.furniture)u.has(h.id)||n.push({kind:"furniture_removed",floor:i,name:h.name||h.type});let[d,p]=[new Map(t.placements.map(h=>[h.entity_id,h])),new Map(e.placements.map(h=>[h.entity_id,h]))];for(let h of e.placements){let f=d.get(h.entity_id);f?Math.hypot(h.x-f.x,h.z-f.z)>Ho&&n.push({kind:"device_moved",floor:i,name:h.entity_id}):n.push({kind:"device_added",floor:i,name:h.entity_id})}for(let h of t.placements)p.has(h.entity_id)||n.push({kind:"device_removed",floor:i,name:h.entity_id})}function Bh(t,e){let n=[],r=bn(t.floors),i=new Map([...t.floors,...e.floors].flatMap(l=>l.rooms.map(a=>[a.id,a.name]))),o=l=>i.get(l)??"";for(let l of e.floors){let a=r.get(l.id);a?Rv(a,l,n,o):n.push({kind:"floor_added",floor:l.name,name:l.name})}let s=new Set(e.floors.map(l=>l.id));for(let l of t.floors)s.has(l.id)||n.push({kind:"floor_removed",floor:l.name,name:l.name});return n}var yn=(t,e)=>t.getUint16(e,!0),fi=(t,e)=>t.getUint32(e,!0);function Wh(t){let e=new DataView(t.buffer,t.byteOffset,t.byteLength),n=-1;for(let l=t.length-22;l>=Math.max(0,t.length-65557);l--)if(fi(e,l)===101010256){n=l;break}if(n<0)throw new Error("not_zip");let r=yn(e,n+10),i=fi(e,n+16),o=[],s=new TextDecoder;for(let l=0;l",quot:'"',apos:"'"},Av=t=>t.replace(/&(#x?[0-9a-f]+|\w+);/gi,(e,n)=>n[0]==="#"?String.fromCodePoint(Number.parseInt(n.slice(n[1]==="x"?2:1),n[1]==="x"?16:10)):Ev[n]??e);function Fv(t){let e={};for(let n of t.matchAll(/([\w:.-]+)\s*=\s*(?:"([^"]*)"|'([^']*)')/g))e[n[1]]=Av(n[2]??n[3]);return e}function Tv(t){let e=[],n=null;for(let r of t.matchAll(/<(\/?)(level|room|point|wall|doorOrWindow|pieceOfFurniture)\b([^>]*?)(\/?)>/g)){let[,i,o,s,l]=r;if(i){o==="room"&&(n=null);continue}let a=Fv(s);if(o==="point"){n&&n.points.push([Number(a.x)/100,Number(a.y)/100]);continue}let c={name:o,attrs:a,...o==="room"?{points:[]}:{}};e.push(c),o==="room"&&!l&&(n=c)}return e}var oe=(t,e,n)=>Number.isFinite(Number(t[e]))&&t[e]!==void 0?Number(t[e]):n,Te=t=>Math.round(t*1e3)/1e3;function Kh(t,e,n){let[r,i]=[n[0]-e[0],n[1]-e[1]],o=Math.hypot(r,i)||1e-9,s=Math.max(0,Math.min(o,((t[0]-e[0])*r+(t[1]-e[1])*i)/o)),l=[e[0]+r*s/o,e[1]+i*s/o];return{dist:Math.hypot(t[0]-l[0],t[1]-l[1]),along:s,length:o}}function zv(t){let e=`${t.name??""} ${t.catalogId??""}`.toLowerCase();return/garage|sectional|rolltor/.test(e)?"garage":/door|tür|tuer|porte|puerta|deur|haustür/.test(e)&&!/window|fenster/.test(e)?"door":"window"}function Pv(t,e){let n=t.length,r=t.map((i,o)=>{let s=t[(o+1)%n],[l,a]=[s[0]-i[0],s[1]-i[1]],c=Math.hypot(l,a)||1e-9,u=[l/c,a/c],d=[(i[0]+s[0])/2,(i[1]+s[1])/2],p=[0,0];for(let h of e){let[f,g]=[h.b[0]-h.a[0],h.b[1]-h.a[1]],b=Math.hypot(f,g)||1e-9;if(Math.abs((u[0]*g-u[1]*f)/b)>.05)continue;let y=(h.a[0]-d[0])*-u[1]+(h.a[1]-d[1])*u[0],v=((d[0]-h.a[0])*f+(d[1]-h.a[1])*g)/b;if(!(Math.abs(y)>h.thickness/2+.06||v<-.05||v>b+.05)){p=[-u[1]*y,u[0]*y];break}}return{p:[i[0]+p[0],i[1]+p[1]],dir:u}});return r.map((i,o)=>{let s=r[(o-1+n)%n],l=s.dir[0]*i.dir[1]-s.dir[1]*i.dir[0];if(Math.abs(l)<1e-6)return i.p;let a=((i.p[0]-s.p[0])*i.dir[1]-(i.p[1]-s.p[1])*i.dir[0])/l;return[s.p[0]+s.dir[0]*a,s.p[1]+s.dir[1]*a]})}function Dv(t){let e=Pt(),n={floors:0,rooms:0,openings:0,walls:0,furniture:0},r=t.filter(a=>a.name==="level"),i=r.length?r.map(a=>a.attrs.id??""):[""],o=t.filter(a=>a.name==="wall"),s=o.length?Math.max(...o.map(a=>oe(a.attrs,"height",250)))/100:2.5;return(r.length?[...r].sort((a,c)=>oe(a.attrs,"elevation",0)-oe(c.attrs,"elevation",0)||oe(a.attrs,"elevationIndex",0)-oe(c.attrs,"elevationIndex",0)):[{name:"level",attrs:{id:""}}]).forEach((a,c)=>{let u=a.attrs.id??"",d=b=>r.length?(b.attrs.level??i[0])===u:!0,p=Ve(I("floor"),a.attrs.name||(c===0?"Erdgeschoss":`Etage ${c+1}`),Te(oe(a.attrs,"elevation",0)/100));p.height=Te(oe(a.attrs,"height",s*100)/100);let h=o.filter(d).map(b=>({a:[oe(b.attrs,"xStart",0)/100,oe(b.attrs,"yStart",0)/100],b:[oe(b.attrs,"xEnd",0)/100,oe(b.attrs,"yEnd",0)/100],thickness:oe(b.attrs,"thickness",10)/100})),f=t.filter(b=>b.name==="room"&&d(b)&&(b.points?.length??0)>=3).map((b,y)=>({id:I("room"),name:b.attrs.name||`Raum ${y+1}`,area_id:null,points:Pv(b.points,h).map(([v,w])=>[Te(v),Te(w)]),floor_material:"wood",panel:[]}));p.rooms=f;for(let b of t.filter(y=>y.name==="doorOrWindow"&&d(y))){let y=[oe(b.attrs,"x",0)/100,oe(b.attrs,"y",0)/100],v=Math.max(.6,oe(b.attrs,"depth",30)/100+.3),w=null;for(let L of f)L.points.forEach((P,N)=>{let W=Kh(y,P,L.points[(N+1)%L.points.length]);W.dist<=v&&(!w||W.dist1.4?2:1,swing:"in",cover:null,contact:null,contact2:null,tilt:null})}let g=[];for(let b of o.filter(d)){let y=[oe(b.attrs,"xStart",0)/100,oe(b.attrs,"yStart",0)/100],v=[oe(b.attrs,"xEnd",0)/100,oe(b.attrs,"yEnd",0)/100];if(Math.hypot(v[0]-y[0],v[1]-y[1])<.1)continue;let w=Math.max(.15,oe(b.attrs,"thickness",10)/100),x=F=>f.some(L=>L.points.some((P,N)=>Kh(F,P,L.points[(N+1)%L.points.length]).dist[y[0]+(v[0]-y[0])*F/M,y[1]+(v[1]-y[1])*F/M],T=Array.from({length:M+1},(F,L)=>!x(A(L)));for(let F=0;F<=M;){if(!T[F]){F++;continue}let L=F;for(;L+1<=M&&T[L+1];)L++;let[P,N]=[A(Math.max(0,F-1)),A(Math.min(M,L+1))];Math.hypot(N[0]-P[0],N[1]-P[1])>=.3&&g.push({id:I("wall"),a:[Te(P[0]),Te(P[1])],b:[Te(N[0]),Te(N[1])],thickness:Te(oe(b.attrs,"thickness",10)/100),height:b.attrs.height?Te(oe(b.attrs,"height",250)/100):null}),F=L+1}}p.walls=g,n.rooms+=f.length,n.openings+=p.openings.length,n.walls+=g.length,(f.length||g.length)&&e.floors.push(p)}),n.floors=e.floors.length,n.furniture=t.filter(a=>a.name==="pieceOfFurniture").length,{building:Oe(e),report:n}}async function jh(t){let e=Wh(t).find(i=>i.name==="Home.xml");if(!e)throw new Error("sh3d_no_xml");let n=new TextDecoder().decode(await Vh(t,e)),r=Dv(Tv(n));if(r.report.rooms===0&&r.report.walls===0)throw new Error("sh3d_empty");return r}function Iv(t){let e=t.split(/\r?\n/),n=[];for(let r=0;r+1r===9&&i==="$INSUNITS"),n=e>=0?Number(t[e+1]?.[1]):NaN;return{1:.0254,2:.3048,4:.001,5:.01,6:1}[n]??null}function Hv(t){let e=Iv(t),n=Ov(e),r=e.findIndex(([s,l],a)=>s===2&&l==="ENTITIES"&&e[a-1]?.[1]==="SECTION"),i=[];if(r<0)return{shapes:i,unit:n};let o=r+1;for(;oNumber(c.find(([h])=>h===p)?.[1]??NaN),d=[[u(10),u(20)],[u(11),u(21)]];d.every(([p,h])=>Number.isFinite(p)&&Number.isFinite(h))&&i.push({points:d,closed:!1})}else if(l==="LWPOLYLINE"){let u=c.filter(([f])=>f===10).map(([,f])=>Number(f)),d=c.filter(([f])=>f===20).map(([,f])=>Number(f)),p=Number(c.find(([f])=>f===70)?.[1]??0),h=u.map((f,g)=>[f,d[g]]).filter(([f,g])=>Number.isFinite(f)&&Number.isFinite(g));h.length>=2&&i.push({points:h,closed:(p&1)===1})}o=a}return{shapes:i,unit:n}}var Uh=t=>Math.round(t*1e3)/1e3;function Gh(t){let{shapes:e,unit:n}=Hv(t);if(!e.length)throw new Error("dxf_empty");let r=e.flatMap(h=>h.points),i=Math.max(Math.max(...r.map(h=>h[0]))-Math.min(...r.map(h=>h[0])),Math.max(...r.map(h=>h[1]))-Math.min(...r.map(h=>h[1]))),o=n??(i>2e3?.001:i>200?.01:1),s=Math.min(...r.map(h=>h[0])),l=Math.max(...r.map(h=>h[1])),a=([h,f])=>[Uh((h-s)*o),Uh((l-f)*o)],c=Ve(I("floor"),"Erdgeschoss",0),u=[],d=[];for(let h of e){let f=h.points.map(a);if(h.closed&&f.length>=3)u.push({id:I("room"),name:`Raum ${u.length+1}`,area_id:null,points:f,floor_material:"wood",panel:[]});else for(let g=0;g+1.05&&d.push({id:I("wall"),a:f[g],b:f[g+1]})}c.rooms=u,c.walls=d;let p=Pt();return p.floors=[c],{building:Oe(p),report:{floors:1,rooms:u.length,openings:0,walls:d.length,furniture:0}}}var Qe=t=>Math.round(t*100)/100;function Lv(t,e){let n=t.category;return typeof n=="string"?n:n&&typeof n=="object"?Object.keys(n)[0]??e:e}function Cv(t,e){let n=t,r=n?.transform,i=n?.dimensions;if(!n||!Array.isArray(r)||r.length<16||!Array.isArray(i)||i.length<3)return null;let o=l=>Number(l),s=Math.hypot(o(r[0]),o(r[2]));return![...r.slice(0,16),...i.slice(0,3)].every(l=>Number.isFinite(o(l)))||s<1e-6?null:{centre:[o(r[12]),o(r[13]),o(r[14])],dir:[o(r[0])/s,o(r[2])/s],size:[o(i[0]),o(i[1]),o(i[2])],kind:Lv(n,e)}}var Qn=(t,e,n)=>(Array.isArray(t[e])?t[e]:[]).map(r=>Cv(r,n)).filter(r=>!!r);function Nv(t){if(t.length<3)return null;let e=t.map(a=>{let c=a.size[0]/2;return[[a.centre[0]-a.dir[0]*c,a.centre[2]-a.dir[1]*c],[a.centre[0]+a.dir[0]*c,a.centre[2]+a.dir[1]*c]]}),n=(a,c)=>Math.hypot(a[0]-c[0],a[1]-c[1]),r=.4,i=new Set([0]),o=[e[0][0]],s=[0],l=e[0][1];for(;i.sizer?null:(o[0]=[(l[0]+o[0][0])/2,(l[1]+o[0][1])/2],{points:o,edgeWall:s})}function Zh(t){let e=[],n=[];for(let l of t){let a=l.size[0]/2;for(let c of[-1,1])e.push(l.centre[0]+c*l.dir[0]*a),n.push(l.centre[2]+c*l.dir[1]*a)}let[r,i,o,s]=[Math.min(...e),Math.max(...e),Math.min(...n),Math.max(...n)];return[[r,o],[i,o],[i,s],[r,s]]}function Bv(t,e,n){let[r,i]=[n[0]-e[0],n[1]-e[1]],o=Math.hypot(r,i)||1e-9,s=Math.min(o,Math.max(0,((t[0]-e[0])*r+(t[1]-e[1])*i)/o));return{dist:Math.hypot(t[0]-(e[0]+r/o*s),t[1]-(e[1]+i/o*s)),along:s,length:o}}var Wv={sofa:"sofa",bed:"bed",table:"table",chair:"chair",bathtub:"bathtub",toilet:"wc",sink:"sink",refrigerator:"fridge",stove:"stove",oven:"stove",dishwasher:"dishwasher",washerDryer:"washer",storage:"tall_cabinet",television:"tv_board"};function qh(t){let e=t;return!e||typeof e!="object"||"floors"in e||"settings"in e?!1:(Array.isArray(e.rooms)?e.rooms:[e]).some(r=>r&&Array.isArray(r.walls)&&Qn(r,"walls","wall").length>0)}function Yh(t){let e=t,r=(Array.isArray(e.rooms)?e.rooms:[e]).filter(b=>b&&typeof b=="object").map(b=>({walls:Qn(b,"walls","wall"),doors:[...Qn(b,"doors","door"),...Qn(b,"openings","opening")],windows:Qn(b,"windows","window"),objects:Qn(b,"objects","object")})).filter(b=>b.walls.length);if(!r.length)throw new Error("roomplan_empty");let i=r.flatMap(b=>b.walls),o=Math.min(...i.map(b=>b.centre[1]-b.size[1]/2)),s=r.map(b=>Nv(b.walls)),l=r.flatMap((b,y)=>s[y]?.points??Zh(b.walls)),[a,c]=[Math.min(...l.map(b=>b[0]))-.5,Math.min(...l.map(b=>b[1]))-.5],u=([b,y])=>[Qe(b-a),Qe(y-c)],d=Ve(I("floor"),"Erdgeschoss",0);d.height=Qe(Math.max(2.2,Math.min(4,Math.max(...i.map(b=>b.size[1])))));let p=[],h=[];r.forEach((b,y)=>{let w=(s[y]?.points??Zh(b.walls)).map(u),x={id:I("room"),name:`Raum ${y+1}`,area_id:null,points:w,floor_material:"wood",panel:[]};p.push(x);for(let k of[...b.doors.map(M=>({v:M,window:!1})),...b.windows.map(M=>({v:M,window:!0}))]){let M=[k.v.centre[0]-a,k.v.centre[2]-c],A=null;if(w.forEach((P,N)=>{let W=Bv(M,P,w[(N+1)%w.length]);W.dist<=.6&&(!A||W.dist1.4?2:1,swing:"in",...L?{style:"passage"}:{},cover:null,contact:null,contact2:null,tilt:null})}for(let k of b.objects){let M=Wv[k.kind];if(!M)continue;let[A,T,F]=[k.size[0],k.size[2],k.size[1]];A<.1||T<.1||h.push({id:I("f"),type:M,x:Qe(k.centre[0]-a),z:Qe(k.centre[2]-c),rotation:Math.round((Math.atan2(k.dir[1],k.dir[0])*180/Math.PI+360)%360),w:Qe(A),d:Qe(T),h:Qe(F),variant:null,entity:null,power:null})}}),d.rooms=p,d.furniture=h;let f=Pt();f.floors=[d];let g=r.reduce((b,y)=>b+y.objects.length,0)-h.length;return{building:Oe(f),report:{floors:1,rooms:p.length,openings:d.openings.length,walls:0,furniture:g}}}var mi=t=>typeof t=="object"&&t!==null&&!Array.isArray(t)&&"ref"in t;function Vv(t){let e=0,n=()=>{for(;t[e]===" ";)e++;let i=t[e];if(i==="("){e++;let a=[];for(;eString.fromCharCode(...(n.match(/.{4}/g)??[]).map(r=>parseInt(r,16)))).replace(/\\S\\(.)/g,(e,n)=>String.fromCharCode(n.charCodeAt(0)+128))}function jv(t){let e=new Map,n=t.slice(Math.max(0,t.indexOf("DATA;")));for(let r of n.matchAll(/#(\d+)\s*=\s*([A-Z0-9_]+)\s*\(([\s\S]*?)\)\s*;(?=\s*(?:#|ENDSEC))/g))e.set(Number(r[1]),{type:r[2],args:Vv(r[3])});return e}var Xh={x:0,y:0,z:0,c:1,s:0},Jh=(t,e)=>({x:t.x+t.c*e.x-t.s*e.y,y:t.y+t.s*e.x+t.c*e.y,z:t.z+e.z,c:t.c*e.c-t.s*e.s,s:t.s*e.c+t.c*e.s});function Qh(t){let e=jv(t);if(!e.size)throw new Error("ifc_empty");let n=k=>mi(k)?e.get(k.ref):void 0,r=k=>typeof k=="number"?k:NaN,i=k=>(n(k)?.args[0]??[]).map(M=>r(M)),o=[...e.values()].find(k=>k.type==="IFCSIUNIT"&&k.args[1]===".LENGTHUNIT."),s=o?{".MILLI.":.001,".CENTI.":.01,".DECI.":.1}[String(o.args[2])]??1:1,l=k=>{let M=n(k);if(!M)return Xh;let[A=0,T=0,F=0]=i(M.args[0]),L=n(M.type==="IFCAXIS2PLACEMENT3D"?M.args[2]:M.args[1]),[P=1,N=0]=(L?.args[0]??[]).map(q=>r(q)),W=Math.hypot(P,N)||1;return{x:A||0,y:T||0,z:F||0,c:P/W,s:N/W}},a=(k,M=0)=>{let A=n(k);return!A||A.type!=="IFCLOCALPLACEMENT"||M>30?Xh:Jh(a(A.args[0],M+1),l(A.args[1]))},c=k=>{for(let M of n(k)?.args[2]??[])for(let A of n(M)?.args[3]??[]){let T=n(A);if(T?.type!=="IFCEXTRUDEDAREASOLID")continue;let F=n(T.args[0]),L=Jh(l(T.args[1]),l(F?.args[2])),P=[];if(F?.type==="IFCRECTANGLEPROFILEDEF"){let[N,W]=[r(F.args[3])/2,r(F.args[4])/2];P=[[-N,-W],[N,-W],[N,W],[-N,W]]}else if(F?.type==="IFCARBITRARYCLOSEDPROFILEDEF"){let N=n(F.args[2]);N?.type==="IFCPOLYLINE"&&(P=(N.args[0]??[]).map(W=>i(W)))}if(P=P.filter(N=>Number.isFinite(N[0])&&Number.isFinite(N[1])),P.length>3&&Math.hypot(P[0][0]-P[P.length-1][0],P[0][1]-P[P.length-1][1])<1e-6&&P.pop(),P.length>=3)return P.map(([N,W])=>[L.x+L.c*N-L.s*W,L.y+L.s*N+L.c*W])}return null},u=new Map;for(let[,k]of e){if(k.type==="IFCRELAGGREGATES"&&mi(k.args[4]))for(let M of k.args[5]??[])mi(M)&&u.set(M.ref,k.args[4].ref);if(k.type==="IFCRELCONTAINEDINSPATIALSTRUCTURE"&&mi(k.args[5]))for(let M of k.args[4]??[])mi(M)&&u.set(M.ref,k.args[5].ref)}let d=[...e].filter(([,k])=>k.type==="IFCBUILDINGSTOREY").map(([k,M])=>({id:k,name:String(M.args[7]||M.args[2]||"")||null,elevation:r(M.args[9])*s}));d.sort((k,M)=>(k.elevation||0)-(M.elevation||0));let p=[];for(let[k,M]of e){if(M.type!=="IFCSPACE")continue;let A=c(M.args[6]);if(!A)continue;let T=a(M.args[5]),F=A.map(([P,N])=>[(T.x+T.c*P-T.s*N)*s,(T.y+T.s*P+T.c*N)*s]),L=String(M.args[7]||M.args[2]||"")||`Raum ${p.length+1}`;p.push({storey:u.get(k)??null,name:L,ring:F})}if(!p.length)throw new Error("ifc_empty");let h=p.flatMap(k=>k.ring),f=Math.min(...h.map(k=>k[0])),g=Math.max(...h.map(k=>k[1])),b=k=>Math.round(k*1e3)/1e3,y=[],v=new Map;if(d.filter(k=>p.some(M=>M.storey===k.id)).forEach((k,M)=>{let A=Ve(I("floor"),k.name??`Etage ${M+1}`,Number.isFinite(k.elevation)?b(k.elevation):M*2.8);y.push(A),v.set(k.id,A)}),p.some(k=>k.storey===null||!v.has(k.storey))){let k=Ve(I("floor"),y.length?"Weitere R\xE4ume":"Erdgeschoss",y.length?y[y.length-1].elevation+2.8:0);y.push(k),v.set(null,k)}y.forEach((k,M)=>{let A=y[M+1];A&&A.elevation-k.elevation>1.8&&(k.height=b(A.elevation-k.elevation-.2))});for(let k of p)v.get(k.storey!==null&&v.has(k.storey)?k.storey:null).rooms.push({id:I("room"),name:k.name,area_id:null,points:k.ring.map(([A,T])=>[b(A-f),b(g-T)]),floor_material:"wood",panel:[]});let x=Pt();return x.floors=y,{building:Oe(x),report:{floors:y.length,rooms:p.length,openings:0,walls:0,furniture:0}}}var tp="nextfloor",Uv="alarm_control_panel|automation|binary_sensor|button|calendar|camera|climate|conversation|cover|date|datetime|device_tracker|event|fan|group|humidifier|image|input_boolean|input_button|input_datetime|input_number|input_select|input_text|lawn_mower|light|lock|media_player|notify|number|person|remote|scene|script|select|sensor|siren|stt|sun|switch|text|time|timer|todo|tts|update|vacuum|valve|water_heater|weather|zone",ep=new RegExp(`^(?:${Uv})\\.[a-z0-9_]+$`),Gv=/^[0-9a-f]{32}$/,Zv=new Set(["area_id","ha_floor"]),qv=new Set(["sub_areas"]),Yv=new Set(["tap","show_when","pictures","moods"]);function Ja(t){if(typeof t=="string")return ep.test(t)||Gv.test(t)?null:t;if(Array.isArray(t))return t.map(e=>Ja(e)).filter(e=>e!==null);if(t&&typeof t=="object"){let e={};for(let[n,r]of Object.entries(t))ep.test(n)||Yv.has(n)||(Zv.has(n)||qv.has(n)?e[n]=null:e[n]=Ja(r));return e}return t}var Xv=["wall_exterior","wall_interior","wall_paint_outside","wall_paint_inside","grid","north","roof","weather_effects","rain_warning","sun_patches","lock_plan","start_view","units","motion_markers_active","room_double_tap"];function np(t){let e=structuredClone(t),n={};for(let i of Xv)e.settings?.[i]!==void 0&&(n[i]=e.settings[i]);let r=e.settings?.backdrop;r&&(r.color||r.dim!=null)&&(n.backdrop={color:r.color??null,dim:r.dim??null}),e.settings=n,e.energy={...e.energy,grid:null,solar:null,battery:null,battery_soc:null,tariff:null,consumption:null,gas:null,water:null},e.presence=[];for(let i of e.floors){i.background=null,i.placements=[],i.power_entity=null,i.utility_meters=null,i.ha_floor=null;for(let o of i.rooms)Object.assign(o,{area_id:null,sub_areas:null,panel:[],hidden:[],no_state:[]});i.furniture.forEach(o=>{Object.assign(o,{entity:null,power:null}),delete o.effect_animations,o.picture&&!(o.picture.startsWith("image:")||o.picture.startsWith("https://"))&&(o.picture=null)}),i.openings.forEach(o=>Object.assign(o,{cover:null,contact:null,tilt:null}))}return Ja(e)}function rp(t,e){return{format:tp,version:1,exported_at:new Date().toISOString(),building:e?np(t):structuredClone(t)}}var Jv=t=>!!t&&(t.version===1||t.version===void 0)&&Array.isArray(t.floors)&&t.floors.every(e=>!!e&&typeof e=="object"),Qv="https://therealmrbk.github.io/NextFloor/preview/?shared&noshowcase";function ip(t,e,n,r,i=Qv){let o=new Set(t.floors.flatMap(c=>c.furniture.map(u=>u.type)).filter(c=>c.startsWith("pack:")).map(c=>c.split(":")[1])),s={building:np(t),packs:e.filter(c=>!c.builtin&&o.has(c.id))},l=JSON.stringify(s).replace(/c.replace(/[&<>"]/g,u=>({"&":"&","<":"<",">":">",'"':"""})[u]);return`
${a(n)}