`,S=(t,e="")=>m``;function rn(t,e,n,r={}){let o=r.lowest??10;return m``}var nt=(t,e,n={})=>t.callWS({type:`nextfloor/${e}`,...n});async function oi(t,e){return(await nt(t,"image/get",{image_id:e})).data}async function Lt(t,e,n){await nt(t,"image/set",{image_id:e,data:n})}async function sd(t){return(await nt(t,"history/list")).snapshots}async function ad(t,e){return(await nt(t,"history/snapshot",e?{name:e}:{})).id}async function ld(t,e){return(await nt(t,"history/get",{snapshot_id:e})).building}async function cd(t,e){await nt(t,"history/delete",{snapshot_id:e})}async function ud(t,e){return(await nt(t,"history/restore",{snapshot_id:e})).revision}var Er=(t,e)=>nt(t,"packs/import",{pack:e});async function dd(t,e){await nt(t,"packs/remove",{pack_id:e})}var hd=t=>nt(t,"backup/export"),pd=(t,e,n)=>nt(t,"backup/import",{building:e,packs:n});var G=(t,e)=>[t[0]-e[0],t[1]-e[1]],ft=(t,e)=>[t[0]+e[0],t[1]+e[1]],rt=(t,e)=>[t[0]*e,t[1]*e],ee=(t,e)=>t[0]*e[0]+t[1]*e[1],Me=(t,e)=>t[0]*e[1]-t[1]*e[0],me=t=>Math.hypot(t[0],t[1]),ot=t=>{let e=me(t)||1;return[t[0]/e,t[1]/e]},Zs=t=>[-t[1],t[0]],qs=t=>[t[1],-t[0]];var Wb=.05,Vb=.2,Kb=.12;function jb(t){let e=[];return t.forEach((n,r)=>{let o=n.points;if(o.length<3)return;let i=_e(o)>=0;o.forEach((s,l)=>{let a=o[(l+1)%o.length],c=me(G(a,s));if(c<.05)return;let u=[(a[0]-s[0])/c,(a[1]-s[1])/c],d=i?[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]=[ee(s,u),ee(a,u)];e.push({room:r,index:l,dir:u,normal:p,offset:ee(s,p),outside:ee(d,p)>0?1:-1,from:Math.min(h,f),to:Math.max(h,f)})})}),e}function Gb(t,e,n){if(t.room===e.room||Math.abs(Me(t.dir,e.dir))>Wb||t.outside===e.outside)return null;let r=(e.offset-t.offset)*t.outside;return r>n||r<-Kb||Math.abs(r)<1e-4||Math.min(t.to,e.to)-Math.max(t.from,e.from)Math.round(t*1e3)/1e3;function fd(t,e=.6){let n=jb(t),r=n.map((g,b)=>b),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(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]=[o(g),o(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)}i.push(Ys(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(Me(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(Me(g.dir,v.dir))<1e-6&&Math.abs(g.offset-v.offset)<.002&&g.outside===v.outside&&(r[o(b)]=o(y))});let d=()=>t.map(g=>({...g,points:g.points.map(b=>[b[0],b[1]])}));if(i.length===0)return{rooms:d(),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,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[Ys(w[0]),Ys(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 Ub=.25,gd=t=>Math.round(t*1e3)/1e3,_d=(t,e,n)=>t.rooms.find(r=>r.points.length>=3&&N([e,n],r.points));function Qs(t,e,n,r,o){let i=_d(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 Zb(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(ee(G(i,n),r))<.02&&Math.abs(ee(G(l,n),r))<.02}))}var Xs=(t,e)=>Math.abs((t-e+540)%360-180);function Ar(t,e,n,r=Ub){let o=_d(t,e.x,e.z);if(!o)return null;let i=o.points,s=_e(i)>=0?1:-1,l=null;return i.forEach((a,c)=>{let u=i[(c+1)%i.length],d=me(G(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=ee(G([e.x,e.z],a),p);if(f<0||f>d)return;let g=Zb(t,o,a,h)?n/2:0,b=ee(G([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)=>Xs(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:gd(e.x-h[0]*x),z:gd(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 Cn=Math.PI/180,it=t=>Math.tan(Math.min(80,Math.max(0,t))*Cn);function Tr(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 bd(t){if(!t.rotation)return null;let e=t.rotation*Cn;return{cx:(t.x0+t.x1)/2,cz:(t.z0+t.z1)/2,c:Math.cos(e),sn:Math.sin(e)}}function yd(t,e){let n=bd(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 Js(t,e,n){let r=bd(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 zr(t,e=0){let{x0:n,x1:r,z0:o,z1:i}=Tr(t);return[[n-e,o-e],[r+e,o-e],[r+e,i+e],[n-e,i+e]].map(s=>yd(t,s))}function xe(t){let{x0:e,x1:n,z0:r,z1:o}=Tr(t),i=s=>yd(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 Pr(t,e,n){let{x0:r,x1:o,z0:i,z1:s}=Tr(t),[l,a]=Js(t,e,n);return t.axis==="x"?[l,t.flip?s-a:a-i]:[a,t.flip?o-l:l-r]}var Fr=Math.tan(30*Cn);function Ir(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+Fr*(t-s+i))/(2*Fr))),u=l+(c-i)*Fr;return{vla:i,vlb:s,yla:l,ylb:a,vr:c,rh:u,y:p=>p<=i?e+p*r:p<=c?l+(p-i)*Fr:p<=t-s?a+(t-s-p)*Fr:n+(t-p)*o}}function Ie(t){let e=xe(t).w,[n,r]=[t.eave_a,t.eave_b],[o,i]=[it(t.pitch_a),it(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=Ir(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 on=t=>Ie(t).rh;function vd(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 qb(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 Yb(t,e,n){if(t.a===e.b)return!1;let r=ot(G(n[t.b],n[t.a])),o=ot(G(n[e.b],n[e.a]));return Math.abs(Me(r,o))>1e-6||ee(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 wd(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]]:vd(r[l[0]]),c=r[l[1]].a===s?r[l[1]]:vd(r[l[1]]);if(!Yb(a,c,e))continue;let u={...a,b:c.b,sources:qb(a.sources,c.sources)};i=[...r.filter((d,p)=>p!==l[0]&&p!==l[1]),u];break}if(!i)return r;r=i}}function kd(t,e){let n=new Map;t.forEach((o,i)=>{let s=ot(G(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:rt(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:ft(s,rt(Zs(a.d),a.left)),right:ft(s,rt(qs(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 u=i[(c+1)%i.length],d=ft(s,rt(Zs(a.d),a.left)),p=ft(s,rt(qs(u.d),u.right)),h=Me(a.d,u.d);if(Math.abs(h)<1e-4)return;let f=ft(d,rt(a.d,Me(G(p,d),u.d)/h));me(G(f,s))>l||(r.get(a.key).left=f,r.get(u.key).right=f)})}return r}function xd(t,e){let n=t.filter((r,o)=>me(G(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]=[G(o,s),G(l,o)];return Math.abs(Me(ot(a),ot(c)))<1e-7&&ee(a,c)>0});if(r===-1)return n;n=n.filter((o,i)=>i!==r)}}function Xb(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 Qb(t,e){let n=[];for(let r of t){let o=r.points;if(o.length<3||Math.abs(_e(o))<1e-6)continue;let i=_e(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 Jb(t,e,n){let r=[];for(let o of t){let[i,s]=[e[o.u],e[o.v]],l=G(s,i),a=me(l),c=rt(l,1/a),u=e.map((p,h)=>({id:h,rel:G(p,i)})).filter(({id:p,rel:h})=>p!==o.u&&p!==o.v&&ee(h,c)>n&&ee(h,c)({t:ee(h,c),id:p})).sort((p,h)=>p.t-h.t),d=[{t:0,id:o.u},...u,{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 ey(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 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,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=i(l);if(!a||a.length<1e-9){let u=o(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=>o(a)===0)}}function Sd(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 ty(t,e,n,r){let o=ey(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!==u&&p.room!==c.room&&r.push(`overlap:${c.room}:${p.room}`);let d=u?[c,u]:[c];if(o.hasNoWall(d)){u&&l.push([c.room,u.room]);continue}if(u){let p=o.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($d),...Sd(o.heightsOf(d))})}else s.push({a:c.u,b:c.v,left:0,right:o.thicknessOf(d)??n.exterior,exterior:!0,roomLeft:c.room,roomRight:null,sources:[$d(c)],...Sd(o.heightsOf(d))})}return{drafts:s,open:l}}function ny(t,e){let n=i=>ot(G(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(ee(s,h)>0?"left":"right")}if(a.size!==1)continue;let c=[...a][0];for(let u of i){let d=u.left+u.right,p=ee(n(u),s)>0,h=c==="left"===p;[u.left,u.right]=h?[0,d]:[d,0]}}}var ry=(t,e)=>{let n=i=>Math.round(i*100),[r,o]=t[0]Math.hypot(y.b[0]-y.a[0],y.b[1]-y.a[1])>.05),a=l.map(y=>[i.idOf(y.a),i.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=G(v[(x+1)%v.length],k),E=me(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&&N(k,T.points))?.id??null,E=(y.thickness??e.interior)/2;h.push({free:y.id,a:w,b:x,left:E,right:E,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=wd(h,i.points,c),g=kd(f,i.points);return{walls:f.map((y,v)=>{let[w,x]=[i.points[y.a],i.points[y.b]],[k,M]=[g.get(`${v}:a`),g.get(`${v}:b`)],E=xd([k.right,M.left,x,M.right,k.left,w],1e-6);return{id:ry(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:E,...y.free?{free:y.free}:{},...y.height!==void 0?{height:y.height}:{},...y.heightEnd!==void 0?{heightEnd:y.heightEnd}:{}}}),warnings:[...new Set(o)],open:p}}function Nn(t,e,n){let r=t.points[e];return ft(r,rt(ot(G(t.points[(e+1)%t.points.length],r)),n))}function De(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=ot(G(o.b,o.a));return{room:{id:t.room_id,name:"",area_id:null,points:[o.a,o.b,ft(o.a,[-i[1],i[0]])]},edge:0}}let r=e.find(o=>o.id===t.room_id);return r&&t.edgeee(G(e,t.a),ot(G(t.b,t.a)));function Ct(t,e,n){if(!e.wall)return oy(t,n.room,n.edge,e.offset);let r=t.find(o=>o.free===e.wall);return r?{wall:r,s:Md(r,Nn(n.room,0,e.offset))}:null}function oy(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:Md(o,Nn(e,n,r))};return null}function Rd(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,u=(h,f,g)=>c(h.a[f],g)&&c(h.b[f],g),d=i-o-a(h=>u(h,0,o))-a(h=>u(h,0,i)),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 Ed=([t,e])=>{let n=Math.hypot(t,e)||1;return[t/n,e/n]};function iy(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 Ad(t,e){let n=t.length;if(n<3||Math.abs(e)<1e-9)return t.map(([o,i])=>[o,i]);let r=iy(t)>=0?1:-1;return t.map((o,i)=>{let s=t[(i+n-1)%n],l=t[(i+1)%n],[a,c]=Ed([o[0]-s[0],o[1]-s[1]]),[u,d]=Ed([l[0]-o[0],l[1]-o[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[o[0]+p[0]*e,o[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[o[0]+f[0]/g*e*y,o[1]+f[1]/g*e*y]})}function Nt(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 sy(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(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])&&(!o||Math.abs(ke(s))>Math.abs(ke(o)))&&(o=s)}return o}function ea(t,e,n,r){let o=fe(t,{exterior:n,interior:r},e).walls.filter(l=>l.exterior&&!l.free),i=o.length?sy(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],u=i[(a+1)%i.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?Ad(s,n):null}function sn(t,e){let n=xe(t),r=Ie(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=(y,v)=>[y,v,r.y(v)],u=c(l,-i),d=c(a,-i),p=c(a,o+s),h=c(l,o+s),[f,g]=[it(t.pitch_a),it(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,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,M=g>1e-6?Math.max(r.vr,o-(x-t.eave_b)/g):r.vr,E=Math.min(y-.1,(r.rh-x)/Math.max(.2,f)),T=[[0,r.y(0)],[r.vr,r.rh],[o,r.y(o)]],F=[[0,r.y(0)],[k,x],[M,x],[o,r.y(o)]],O=(j,Ut,$o)=>{if(j==="hip")return{upA:[],upB:[],ridge:b(Ut===l?n.u0+v*$o:n.u1-v*$o),profile:null};if(j==="halfhip"){let N_=b(Ut===l?n.u0+E:n.u1-E);return{upA:[[Ut,k,x]],upB:[[Ut,M,x]],ridge:N_,profile:F}}return{upA:[],upB:[],ridge:b(Ut),profile:T}},P=O(t.ends[0],l,1),C=O(t.ends[1],a,1),B=[[u,d,...C.upA,C.ridge,P.ridge,...[...P.upA].reverse()],[P.ridge,C.ridge,...[...C.upB].reverse(),p,h,...P.upB]],q=[[P.ridge,C.ridge]];for(let[j,Ut,$o]of[[P,u,h],[C,d,p]])j.profile===null?(B.push(j===P?[h,u,j.ridge]:[d,p,j.ridge]),q.push([Ut,j.ridge],[$o,j.ridge])):j.upA.length&&(B.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 we=j=>j.profile===null?[]:j.upA.length?[j.upA[0],j.upB[0]]:[j.ridge],Rt=[u,d,...we(C),p,h,...[...we(P)].reverse()];return{faces:B,rim:Rt,ridges:q,gable:T,endProfiles:[P.profile,C.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)],[o,r.y(o)]]};case"hip":case"pyramid":{let y=(n.u1-n.u0)/2,v=t.shape==="pyramid"?y:Math.min(y,Math.min(r.vr,o-r.vr)||o/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(o)),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,o-(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),E=b(n.u1-k),T=[l,w,v],F=[l,x,v],O=[a,w,v],P=[a,x,v];return{faces:[[u,d,O,E,M,T],[M,E,P,p,h,F],[F,T,M],[O,P,E]],rim:[u,d,O,P,p,h,F,T],ridges:[[M,E],[T,M],[F,M],[O,E],[P,E]],gable:[[0,r.y(0)],[w,v],[x,v],[o,r.y(o)]]}}case"mansard":{let y=Ir(o,t.eave_a,t.eave_b,f,g),v=[l,y.vla,y.yla],w=[a,y.vla,y.yla],x=[l,o-y.vlb,y.ylb],k=[a,o-y.vlb,y.ylb],M=[l,y.vr,y.rh],E=[a,y.vr,y.rh];return{faces:[[u,d,w,v],[v,w,E,M],[M,E,k,x],[x,k,p,h]],rim:[u,d,w,E,k,p,h,x,M,v],ridges:[[M,E],[v,w],[x,k]],gable:[[0,r.y(0)],[y.vla,y.yla],[y.vr,y.rh],[o-y.vlb,y.ylb],[o,r.y(o)]]}}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],[o,r.y(o)]]}}}}function Dr(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]],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=i[2]-(u[0]*(e-i[0])+u[2]*(n-i[1]))/u[1];r=r===null?d:Math.min(r,d)}return r}function Or(t,e,n){let r=xe(e),o=t.floors.flatMap(d=>d.rooms.filter(p=>p.points.length>=3&&d.elevation+d.height>e.base+.05)),i=d=>d.some(p=>o.some(h=>N(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(i(l.map(d=>r.at(d,-s))))),b:u("b",c(i(l.map(d=>r.at(d,r.w+s))))),u0:u("u0",c(i(a.map(d=>r.at(r.u0-s,d))))),u1:u("u1",c(i(a.map(d=>r.at(r.u1+s,d)))))}}var ii=t=>Math.abs((t.x1-t.x0)*(t.z1-t.z0)),Fd=t=>t.shape==="flat"||t.shape==="parapet",an=t=>Math.round(t*100)/100;function si(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||Fd(i)||ii(i)=s.x0&&n<=s.x1&&r>=s.z0&&r<=s.z1}).reduce((i,s)=>i===null||ii(s){let[i,s]=e.at(o,e.w/2),[l,a]=Pr(t,i,s);return Dr(n,l,a)??r.y(a)}}function na(t,e){if(Fd(e))return e;let n=xe(e),r=Ie(e).rh,o=ly(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 u={...e},d=l===n.u1;return e.axis==="x"?u[d?"x1":"x0"]=c:u[d?"z1":"z0"]=c,u}var ra=.14,Td=t=>t.shape==="flat"||t.shape==="parapet";function oa(t,e){return!t.open&&Math.min(t.base,t.eave_a,t.eave_b)a+o||pu+o||s.points&&s.points.length>=3&&!N([e,n],s.points))continue;let[h,f]=Pr(s,e,n),g=Math.max(0,s.overhang??r),b=Td(s)?null:Dr(sn(s,{u0:g,u1:g,a:g,b:g}),h,f);i.push((b??Ie(s).y(f))-ra)}return i.length?Math.max(...i):null}function ia(t,e,n){let r=[],o=e+n+ra;for(let i of t.settings.roof.sections??[]){if(i.open||Td(i)||i.shape==="mansard")continue;let s=xe(i),l=Ie(i),[a,c]=[it(i.pitch_a),it(i.pitch_b)],u=[];a>1e-6&&u.push((o-i.eave_a)/a),i.shape==="gable"&&c>1e-6&&u.push(s.w-(o-i.eave_b)/c);for(let d of u)d<=.01||d>=s.w-.01||i.shape==="gable"&&Math.abs(l.y(d)-o)>1e-6||r.push([s.at(s.u0,d),s.at(s.u1,d)])}return r}function sa(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 aa(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=>N(p,d.points))));if(c)return c}return r.at(-1)??n[0]}var wt=t=>Math.round(t*1e3)/1e3;function la(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(u=>N(c,u.points));for(let a of o){let c=a.rooms.filter(b=>b.points.length>=3),u=[...new Set(c.flatMap(b=>b.points.map(y=>wt(y[0]))))].sort((b,y)=>b-y),d=[...new Set(c.flatMap(b=>b.points.map(y=>wt(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,E]=[d[b]-r,d[w+1]+r];Math.min(k-x,E-M)<.8||i.push({id:e(i.length),x0:wt(x),z0:wt(M),x1:wt(k),z1:wt(E),shape:"gable",axis:k-x>=E-M?"x":"z",eave_a:wt(g),eave_b:wt(g),pitch_a:n,pitch_b:n,base:wt(g),overhang:null})}s.push(...c)}return i}var Re=Math.PI/180,Ke=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],ln=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2],Bn=t=>Math.hypot(t[0],t[1],t[2]),cn=t=>{let e=Bn(t)||1;return[t[0]/e,t[1]/e,t[2]/e]},zd=(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]],je=t=>Math.round(t*100)/100,Lr=([t,e],n)=>(Math.atan2(t,-e)/Re-n+720)%360;var Id=.25;function Dd(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 Od(t,e){let n=cn(zd(t,e));return n[1]<0?[-n[0],-n[1],-n[2]]:n}var Hd=t=>{let e=cn([-t[0],0,-t[2]]);return[e[0],e[2]]};function kt(t,e,n,r,o,i,s,l){let a=cn(Ke(o,r)),c=cn(Ke(i,r));return{key:t,section:e,side:n,flat:!1,o:r,eu:a,es:c,n:Od(a,c),lu:Bn(Ke(o,r)),ls:Bn(Ke(i,r)),pitch:s,span:l,facing:Hd(c)}}function Pd(t,e,n,r,o,i){let s=Bn(Ke(o,r));if(s<.3)return null;let l=cn(Ke(o,r)),a=Ke(i,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=Bn(u);if(d<.3)return null;let p=cn(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:Od(l,p),lu:s,ls:d,pitch:Math.atan2(p[1],Math.hypot(p[0],p[2]))/Re,span:h,facing:Hd(p)}}function cy(t,e){let n=xe(t),r=Ie(t),o=(v,w,x)=>{let[k,M]=n.at(v,w);return[k,x,M]},[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,u=r.y(-i),d=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[Dd(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+Id)]}if(t.shape==="pent")return[kt(`${t.id}:a`,t.id,"a",o(l,-i,u),o(a,-i,u),o(l,n.w+s,d),t.pitch_a,()=>[0,c])];if(t.shape==="mansard")return uy(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,b=p?a-(n.u1-f):0,y=[];if(r.vr>.3){let v=Math.hypot(r.vr+i,r.rh-u);y.push(kt(`${t.id}:a`,t.id,"a",o(l,-i,u),o(a,-i,u),o(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(kt(`${t.id}:b`,t.id,"b",o(a,n.w+s,d),o(l,n.w+s,d),o(a,r.vr,r.rh),t.pitch_b,w=>[b*(w/v),c-g*(w/v)]))}if(p){let v=Pd(`${t.id}:c`,t.id,"c",o(l,n.w+s,d),o(l,-i,u),o(n.u0+f,r.vr,r.rh)),w=Pd(`${t.id}:d`,t.id,"d",o(a,-i,u),o(a,n.w+s,d),o(n.u1-f,r.vr,r.rh));y.push(...[v,w].filter(x=>x!==null))}return y}function uy(t,e,n,r,o,i){let s=Ir(e.w,t.eave_a,t.eave_b,it(t.pitch_a),it(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)/Re,d=[],[p,h]=[e.w+i,e.w-s.vlb];return s.vla+o>.3&&d.push(kt(`${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&&d.push(kt(`${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+i>.3&&d.push(kt(`${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(kt(`${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 ca(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=>cy(w,Or(t,w,w.overhang??e.overhang)));let n=ca(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],u=n.elevation+n.height;if(e.type==="flat")return[Dd("main",null,s,a,l,c,u+Id)];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*Re),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[kt("main:a",null,"a",g(b,-h,0),g(y,-h,0),g(b,0,f),e.pitch,v),kt("main:b",null,"b",g(b,h,0),g(y,h,0),g(b,0,f),e.pitch,v)]}function Ge(t,e){let n=[];for(let r of t.floors.filter(o=>!e||o.id===e)){let{walls:o}=fe(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,u]=[l/a,-s/a],d=Math.min(r.height,i.height??r.height,i.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}:${i.id}`,[i.a[0]+c*i.right,r.elevation,i.a[1]+u*i.right],[s/a,0,l/a],[c,0,u]),i.free&&p(`wall:${r.id}:${i.id}:back`,[i.b[0]-c*i.left,r.elevation,i.b[1]-u*i.left],[-s/a,0,-l/a],[-c,0,-u])}}return n}var Oe="ground";function ai(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 li(t,e){let n=(e.rotation??0)*Re,r=[Math.cos(n),0,Math.sin(n)],o=[-Math.sin(n),0,Math.cos(n)],i=ai(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:Jc(i,s,l)):e.base??0;return{key:Oe,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 $e(t,e,n=Z(t)){return e.face===Oe?li(t,e):e.face.startsWith("wall:")?Ge(t,e.face.split(":")[1]).find(r=>r.key===e.face)??null:n.find(r=>r.key===e.face)??null}var ci=1.13,Nr=1.72,Ue=.025,st=.07;function un(t){let e=t.module_w||ci,n=t.module_h||Nr;return t.portrait===!1?[n,e]:[e,n]}function Br(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 ua(t,e){return t.flat?Math.min(45,Math.max(0,e.tilt??15))*Re:t.wall?Math.min(90,Math.max(0,e.tilt??0))*Re:Math.min(45,Math.max(0,e.tilt??0))*Re}function Wr(t,e){let[,n]=un(e),r=ua(t,e);return t.wall?n*Math.cos(r)+Ue:!t.flat&&r<.001?n+Ue:t.flat&&e.rack==="ew"?n*Math.cos(r)+.08:n*Math.cos(r)+Math.max(.3,2*n*Math.sin(r))}function Wn(t,e){let[n,r]=un(e),o=Br(e),i=Math.max(1,...o);return[i*n+(i-1)*Ue,(o.length-1)*Wr(t,e)+r*Math.cos(ua(t,e))]}var dy=t=>t.flat&&!t.unbounded&&!t.wall;function Ld(t,e){if(!dy(t)||!e.rotation)return null;let n=e.rotation*Re,[r,o]=Wn(t,e);return{cos:Math.cos(n),sin:Math.sin(n),u:e.u+r/2,s:e.v+o/2}}function Ze(t,e,n=!1){let[r,o]=un(e),i=ua(t,e),s=o*Math.cos(i),l=Wr(t,e),a=Br(e),c=Math.max(1,...a),u=new Set(e.skip??[]),d=Ld(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:o);if([[M,T],[E,T],[E,F],[M,F]].every(([O,P])=>f(O,P)))if(t.wall&&i>.001){let O=st+o*Math.sin(i),[P,C]=e.flip?[O,st]:[st,O],B=[h(M,T,P),h(E,T,P),h(E,F,C),h(M,F,C)],q=e.flip?T:F;g.push({corners:B,posts:[M+.05,E-.05].map(we=>[h(we,q,0),h(we,q,O)]),cell:x,skipped:k})}else if(!t.flat&&i>.001){let O=st+o*Math.sin(i),P=[h(M,T,st),h(E,T,st),h(E,F,O),h(M,F,O)];g.push({corners:P,posts:[M+.05,E-.05].map(C=>[h(C,F,0),h(C,F,O)]),cell:x,skipped:k})}else if(!t.flat)g.push({corners:[h(M,T,st),h(E,T,st),h(E,F,st),h(M,F,st)],posts:[],cell:x,skipped:k});else{let P=.15+o*Math.sin(i),C=e.rack==="ew"&&y%2===1?!e.flip:!!e.flip,[B,q]=C?[F,T]:[T,F],we=[h(M,B,.15),h(E,B,.15),h(E,q,P),h(M,q,P)],Rt=[M+.05,E-.05].flatMap(j=>[[h(j,B,0),h(j,B,.15)],[h(j,q,0),h(j,q,P)]]);g.push({corners:we,posts:Rt,cell:x,skipped:k})}}}),g}function mt(t,e){if(t.unbounded)return{u:e.u,v:e.v};let[n,r]=Wn(t,e),o=Ld(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=(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 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 Vr(t,e){let[n,r]=Wn(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 ui=.78,Kr=1.18,dn=t=>({id:t.id,face:t.face,u:t.u,v:t.v,rows:1,cols:1,portrait:!0,module_w:t.w||ui,module_h:t.h||Kr});function da(t,e){let n=Ze(t,dn(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 Cr={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 hn(t){let e=t.shape??"brick",n=Cr[e]??Cr.brick;return{shape:e,w:t.w||n.w,d:t.d||n.d,h:t.h||n.h}}function xt(t,e){let{w:n,d:r}=hn(t),o=e&&!e.flat?Math.cos(e.pitch*Re):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 ha(t,e){let n=xt(e,t),[r,o]=[n.module_w,n.module_h],i=(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]=[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=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 pa(t,e){let[n]=un(e);return je((t.lu-(e.cols*n+(e.cols-1)*Ue))/2)}var jr=.4;function Vn(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]=un(n),[o,i]=t.span(t.ls/2);for(n.cols=Math.max(1,Math.floor((i-o-2*jr+Ue)/(r+Ue))),n.rows=Math.max(1,Math.min(4,Math.floor((t.ls-2*jr)/Wr(t,n))));n.cols>1&&Ze(t,{...n,u:pa(t,n),v:jr}).lengthl.lu*(1.3+Math.cos((Lr(l.facing,r)-180)*Math.PI/180)),i=Ge(t,n).sort((l,a)=>o(a)-o(l))[0];if(!i)return null;let s={...Vn(i,e),portrait:!1,rows:1};return s.cols=Math.max(1,Math.floor((i.lu-.8+Ue)/(Nr+Ue))),s.u=je((i.lu-(s.cols*Nr+(s.cols-1)*Ue))/2),s.v=je(Math.max(0,i.ls-ci-.3)),s}function Gr(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:Oe,u:je(r),v:je(o),rows:2,cols:4,portrait:!0,tilt:25,flip:!0,rotation:(t.settings.north??0)||0,look:"black",entity:null}}function Ur(t,e,n){let r=li(t,e),[o,i]=Wn(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*Re,u=a[0]*Math.cos(c)+a[1]*Math.sin(c)-o/2,d=a[0]*-Math.sin(c)+a[1]*Math.cos(c)-i/2;return{u:je(u),v:je(d),rotation:(Math.round(n)%360+360)%360}}function Zr(t,e){let[n,r]=t.span(t.ls/2);return{id:e,face:t.key,u:je((n+r-ui)/2),v:je(Math.max(0,Math.min(t.ls-Kr,t.ls*.45-Kr/2))),w:null,h:null,cover:null,contact:null,tilt:null}}function qr(t,e){let n=Cr.brick,[r,o]=t.span(t.ls*.8),i=xt({id:e,face:t.key,u:0,v:0},t).module_h;return{id:e,face:t.key,u:je((r+o-n.w)/2),v:je(Math.max(0,Math.min(t.ls-i,t.ls*.8-i/2))),shape:"brick",w:null,d:null,h:null}}function Kn(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,u=(o*r-i*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 ma(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 o=Kn(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 hi(t,e,n){let r=ln(n,t.n);if(Math.abs(r)<1e-6)return null;let o=ln(Ke(t.o,e),t.n)/r;if(o<=0)return null;let i=Ke([e[0]+n[0]*o,e[1]+n[1]*o,e[2]+n[2]*o],t.o);return{t:o,u:ln(i,t.eu),s:ln(i,t.es)}}function ga(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 _a(t,e,n,r){return Ze(t,e).some(i=>{let s=i.corners.map(c=>{let u=Ke(c,t.o);return[ln(u,t.eu),ln(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 hy=["n","ne","e","se","s","sw","w","nw"],ba=(t,e)=>hy[Math.round(Lr(t.facing,e)/45)%8];function Yr(t,e){let n=r=>{if(r.flat)return r.lu*r.ls*.8;let o=Math.cos((Lr(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 Wd=["kitchen_row","kitchen_l","bath","bedroom","living","dining","office","kids","hall"],Cd={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]]}},Nd=t=>typeof t=="string"?t:t[0],pi=t=>typeof t=="string"?tt[t]:t[1],jn=.05,py=.02,Bd=t=>Math.round(t*1e3)/1e3;function fy(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 Vd(t,e,n){let r=de(t.points),o=r.x1-r.x0,i=r.z1-r.z0,s=[],l=(a,c,u,d,[p,h,f])=>{s.push({id:n(),type:a,x:Bd(c),z:Bd(u),rotation:d,w:p,d:h,h:f,variant:null,entity:null,power:null})};for(let[a,c,u]of Cd[e].rows){let d=a==="back"||a==="front"?o:i,p=0,h=[];for(let g of u){if(p+pi(g)[0]>d-.1)break;h.push(g),p+=pi(g)[0]}let f=c==="start"?jn:c==="end"?d-p-jn:(d-p)/2;for(let g of h){let b=pi(g),y=fy(r,a,f+b[0]/2,b[1]/2+py);l(Nd(g),y.x,y.z,y.turn,b),f+=b[0]}}for(let[a,c,u,d]of Cd[e].spots){let p=pi(a),h=(b,y,v)=>Math.min(v,Math.max(y,b)),f=h(r.x0+o*c,r.x0+p[0]/2+jn,r.x1-p[0]/2-jn),g=h(r.z0+i*u,r.z0+p[1]/2+jn,r.z1-p[1]/2-jn);l(Nd(a),f,g,d,p)}return s}var my=30*Math.PI/180,Kd=.05;function ya(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 Xr(t){return ya(t).reduce((e,n)=>e+n,0)}function gy(t,e){let n=ya(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 u=l-c,d=s,p=[];for(let h=0;h<=o&&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)%o;if(d>1e-9&&_y(t,a)>my)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 Gn(t,e){let n=e[0];return n?{from:gy(t,n.edge)+n.offset-n.width/2,width:e.reduce((r,o)=>r+o.width,0)}:null}function Bt(t,e){return e.front?t.filter(n=>n.front===e.front):[e]}function wa(t,e){let n=t.points.length,r=1/0,o=0,i=0;for(let s=0;sI("opening")){let s=va(e,r,o);if(!s)return null;let l=Bt(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:i(),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 $a=globalThis,ka=$a.__nextfloorBuiltin?.de??{},xa=$a.__nextfloorBuiltin?.en??{};$a.__nextfloorBuiltin??={de:ka,en:xa};var by=()=>typeof $=="object"&&$||{},yy=globalThis,vy=yy.__nextfloorTexts??=new Map;function wy(t){let e=t.toLowerCase().split("-")[0];return e!=="de"&&e!=="en"&&e in by()?e:void 0}function jd(t){let e=wy(t),n=e===void 0?void 0:vy.get(e);return n instanceof Promise?void 0:n}function fi(t,e){return jd(t)?.[e]}function Se(t,e,n={}){let r=t?.language??navigator.language,o=r.startsWith("de"),i=(o?void 0:jd(r)?.[e])??(o?ka:xa)[e]??xa[e]??ka[e]??e;for(let[s,l]of Object.entries(n))i=i.replace(`{${s}}`,String(l));return i}function K(t,e,n=2){return e.toLocaleString(t?.language??void 0,{maximumFractionDigits:n})}var ge=t=>/^(sensor|input_number|number)\./.test(t),mi=t=>/^(binary_sensor|input_boolean)\./.test(t);function Un(t,e){if(!ge(e))return!1;let n=t?.states[e]?.attributes;return n?.device_class==="power"||n?.unit_of_measurement==="W"||n?.unit_of_measurement==="kW"}function ky(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 H(t,e){return Object.keys(t?.states??{}).filter(e).map(n=>{let r=ky(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 gi(t,e){return t.power&&t.power!=="none"?t.power:e.get(t.id)?.power??null}var Gd=[{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 Ud(t,e,n){let r=s=>n({hvac:{...e.hvac,...s}}),o=e.hvac?.schedules??[],i=H(t.hass,s=>!!t.hass?.states[s]?.attributes.symcon_schedule);return m`
${z(t,t.t("floor_heating"),e.floor_heating??null,void 0,H(t.hass,s=>ht(t.hass,s,[0,1,2])),s=>n({floor_heating:s==="none"?null:s}))}
${Gd.map(s=>z(t,s.label,e.hvac?.[s.key]??null,void 0,H(t.hass,l=>ht(t.hass,l,s.types)),l=>r({[s.key]:l==="none"?null:l})))}
${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")}
${o.map((s,l)=>z(t,`Schaltuhr ${l+1}`,s,void 0,i.filter(a=>a.id===s||!o.includes(a.id)),a=>r({schedules:a&&a!=="none"?o.map((c,u)=>l===u?a:c):o.filter((c,u)=>l!==u)})))}
${z(t,"Schaltuhr hinzuf\xFCgen",null,void 0,i.filter(s=>!o.includes(s.id)),s=>s&&s!=="none"&&r({schedules:[...o,s]}))}`}function Zd(t,e,n){return m`Wettervariablen
${Wc.map(r=>z(t,Ou[r],e.weather_variables?.[r]??null,void 0,H(t.hass,o=>ht(t.hass,o,r==="condition"?[0,1,2,3]:r==="wind_bearing"?[1,2,3]:["snow","fog","lightning"].includes(r)?[0,1,2]:[1,2])),o=>n({weather_variables:{...e.weather_variables,[r]:o==="none"?null:o}})))}
${z(t,t.t("rain_sensor"),e.rain_sensor??null,void 0,H(t.hass,r=>ht(t.hass,r,[0,1,2])),r=>n({rain_sensor:r==="none"?null:r}))}
${e.rain_sensor?D(t,t.t("rain_sensor_inverted"),!!e.rain_sensor_inverted,r=>n({rain_sensor_inverted:r||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")}
`:_}
`}var vi=.05,By=(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),pn=t=>new Map(t.map(e=>[e.id,e]));function Wy(t,e,n,r){let o=e.name,[i,s]=[pn(t.rooms),pn(e.rooms)];for(let h of e.rooms){let f=i.get(h.id);f?(f.name!==h.name&&n.push({kind:"room_renamed",floor:o,name:h.name,detail:f.name}),By(f.points,h.points)||n.push({kind:"room_reshaped",floor:o,name:h.name,detail:Math.round((ke(h.points)-ke(f.points))*10)/10})):n.push({kind:"room_added",floor:o,name:h.name})}for(let h of t.rooms)s.has(h.id)||n.push({kind:"room_removed",floor:o,name:h.name});let[l,a]=[pn(t.openings),pn(e.openings)];for(let h of e.openings)l.has(h.id)||n.push({kind:"opening_added",floor:o,name:h.type,detail:r(h.room_id)});for(let h of t.openings)a.has(h.id)||n.push({kind:"opening_removed",floor:o,name:h.type,detail:r(h.room_id)});let[c,u]=[pn(t.furniture),pn(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)>vi||Math.abs(h.rotation-f.rotation)>1||Math.abs(h.w-f.w)>vi||Math.abs(h.d-f.d)>vi)&&n.push({kind:"furniture_moved",floor:o,name:h.name||h.type}):n.push({kind:"furniture_added",floor:o,name:h.name||h.type})}for(let h of t.furniture)u.has(h.id)||n.push({kind:"furniture_removed",floor:o,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)>vi&&n.push({kind:"device_moved",floor:o,name:h.entity_id}):n.push({kind:"device_added",floor:o,name:h.entity_id})}for(let h of t.placements)p.has(h.entity_id)||n.push({kind:"device_removed",floor:o,name:h.entity_id})}function ch(t,e){let n=[],r=pn(t.floors),o=new Map([...t.floors,...e.floors].flatMap(l=>l.rooms.map(a=>[a.id,a.name]))),i=l=>o.get(l)??"";for(let l of e.floors){let a=r.get(l.id);a?Wy(a,l,n,i):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 fn=(t,e)=>t.getUint16(e,!0),no=(t,e)=>t.getUint32(e,!0);function uh(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(no(e,l)===101010256){n=l;break}if(n<0)throw new Error("not_zip");let r=fn(e,n+10),o=no(e,n+16),i=[],s=new TextDecoder;for(let l=0;l",quot:'"',apos:"'"},Ky=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)):Vy[n]??e);function jy(t){let e={};for(let n of t.matchAll(/([\w:.-]+)\s*=\s*(?:"([^"]*)"|'([^']*)')/g))e[n[1]]=Ky(n[2]??n[3]);return e}function Gy(t){let e=[],n=null;for(let r of t.matchAll(/<(\/?)(level|room|point|wall|doorOrWindow|pieceOfFurniture)\b([^>]*?)(\/?)>/g)){let[,o,i,s,l]=r;if(o){i==="room"&&(n=null);continue}let a=jy(s);if(i==="point"){n&&n.points.push([Number(a.x)/100,Number(a.y)/100]);continue}let c={name:i,attrs:a,...i==="room"?{points:[]}:{}};e.push(c),i==="room"&&!l&&(n=c)}return e}var ie=(t,e,n)=>Number.isFinite(Number(t[e]))&&t[e]!==void 0?Number(t[e]):n,Ee=t=>Math.round(t*1e3)/1e3;function hh(t,e,n){let[r,o]=[n[0]-e[0],n[1]-e[1]],i=Math.hypot(r,o)||1e-9,s=Math.max(0,Math.min(i,((t[0]-e[0])*r+(t[1]-e[1])*o)/i)),l=[e[0]+r*s/i,e[1]+o*s/i];return{dist:Math.hypot(t[0]-l[0],t[1]-l[1]),along:s,length:i}}function Uy(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 Zy(t,e){let n=t.length,r=t.map((o,i)=>{let s=t[(i+1)%n],[l,a]=[s[0]-o[0],s[1]-o[1]],c=Math.hypot(l,a)||1e-9,u=[l/c,a/c],d=[(o[0]+s[0])/2,(o[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:[o[0]+p[0],o[1]+p[1]],dir:u}});return r.map((o,i)=>{let s=r[(i-1+n)%n],l=s.dir[0]*o.dir[1]-s.dir[1]*o.dir[0];if(Math.abs(l)<1e-6)return o.p;let a=((o.p[0]-s.p[0])*o.dir[1]-(o.p[1]-s.p[1])*o.dir[0])/l;return[s.p[0]+s.dir[0]*a,s.p[1]+s.dir[1]*a]})}function qy(t){let e=Tt(),n={floors:0,rooms:0,openings:0,walls:0,furniture:0},r=t.filter(a=>a.name==="level"),o=r.length?r.map(a=>a.attrs.id??""):[""],i=t.filter(a=>a.name==="wall"),s=i.length?Math.max(...i.map(a=>ie(a.attrs,"height",250)))/100:2.5;return(r.length?[...r].sort((a,c)=>ie(a.attrs,"elevation",0)-ie(c.attrs,"elevation",0)||ie(a.attrs,"elevationIndex",0)-ie(c.attrs,"elevationIndex",0)):[{name:"level",attrs:{id:""}}]).forEach((a,c)=>{let u=a.attrs.id??"",d=b=>r.length?(b.attrs.level??o[0])===u:!0,p=Ce(I("floor"),a.attrs.name||(c===0?"Erdgeschoss":`Etage ${c+1}`),Ee(ie(a.attrs,"elevation",0)/100));p.height=Ee(ie(a.attrs,"height",s*100)/100);let h=i.filter(d).map(b=>({a:[ie(b.attrs,"xStart",0)/100,ie(b.attrs,"yStart",0)/100],b:[ie(b.attrs,"xEnd",0)/100,ie(b.attrs,"yEnd",0)/100],thickness:ie(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:Zy(b.points,h).map(([v,w])=>[Ee(v),Ee(w)]),floor_material:"wood",panel:[]}));p.rooms=f;for(let b of t.filter(y=>y.name==="doorOrWindow"&&d(y))){let y=[ie(b.attrs,"x",0)/100,ie(b.attrs,"y",0)/100],v=Math.max(.6,ie(b.attrs,"depth",30)/100+.3),w=null;for(let O of f)O.points.forEach((P,C)=>{let B=hh(y,P,O.points[(C+1)%O.points.length]);B.dist<=v&&(!w||B.dist1.4?2:1,swing:"in",cover:null,contact:null,contact2:null,tilt:null})}let g=[];for(let b of i.filter(d)){let y=[ie(b.attrs,"xStart",0)/100,ie(b.attrs,"yStart",0)/100],v=[ie(b.attrs,"xEnd",0)/100,ie(b.attrs,"yEnd",0)/100];if(Math.hypot(v[0]-y[0],v[1]-y[1])<.1)continue;let w=Math.max(.15,ie(b.attrs,"thickness",10)/100),x=F=>f.some(O=>O.points.some((P,C)=>hh(F,P,O.points[(C+1)%O.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,O)=>!x(E(O)));for(let F=0;F<=M;){if(!T[F]){F++;continue}let O=F;for(;O+1<=M&&T[O+1];)O++;let[P,C]=[E(Math.max(0,F-1)),E(Math.min(M,O+1))];Math.hypot(C[0]-P[0],C[1]-P[1])>=.3&&g.push({id:I("wall"),a:[Ee(P[0]),Ee(P[1])],b:[Ee(C[0]),Ee(C[1])],thickness:Ee(ie(b.attrs,"thickness",10)/100),height:b.attrs.height?Ee(ie(b.attrs,"height",250)/100):null}),F=O+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:Pe(e),report:n}}async function ph(t){let e=uh(t).find(o=>o.name==="Home.xml");if(!e)throw new Error("sh3d_no_xml");let n=new TextDecoder().decode(await dh(t,e)),r=qy(Gy(n));if(r.report.rooms===0&&r.report.walls===0)throw new Error("sh3d_empty");return r}function Yy(t){let e=t.split(/\r?\n/),n=[];for(let r=0;r+1r===9&&o==="$INSUNITS"),n=e>=0?Number(t[e+1]?.[1]):NaN;return{1:.0254,2:.3048,4:.001,5:.01,6:1}[n]??null}function Qy(t){let e=Yy(t),n=Xy(e),r=e.findIndex(([s,l],a)=>s===2&&l==="ENTITIES"&&e[a-1]?.[1]==="SECTION"),o=[];if(r<0)return{shapes:o,unit:n};let i=r+1;for(;iNumber(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))&&o.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&&o.push({points:h,closed:(p&1)===1})}i=a}return{shapes:o,unit:n}}var fh=t=>Math.round(t*1e3)/1e3;function mh(t){let{shapes:e,unit:n}=Qy(t);if(!e.length)throw new Error("dxf_empty");let r=e.flatMap(h=>h.points),o=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]))),i=n??(o>2e3?.001:o>200?.01:1),s=Math.min(...r.map(h=>h[0])),l=Math.max(...r.map(h=>h[1])),a=([h,f])=>[fh((h-s)*i),fh((l-f)*i)],c=Ce(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=Tt();return p.floors=[c],{building:Pe(p),report:{floors:1,rooms:u.length,openings:0,walls:d.length,furniture:0}}}var qe=t=>Math.round(t*100)/100;function Jy(t,e){let n=t.category;return typeof n=="string"?n:n&&typeof n=="object"?Object.keys(n)[0]??e:e}function ev(t,e){let n=t,r=n?.transform,o=n?.dimensions;if(!n||!Array.isArray(r)||r.length<16||!Array.isArray(o)||o.length<3)return null;let i=l=>Number(l),s=Math.hypot(i(r[0]),i(r[2]));return![...r.slice(0,16),...o.slice(0,3)].every(l=>Number.isFinite(i(l)))||s<1e-6?null:{centre:[i(r[12]),i(r[13]),i(r[14])],dir:[i(r[0])/s,i(r[2])/s],size:[i(o[0]),i(o[1]),i(o[2])],kind:Jy(n,e)}}var Zn=(t,e,n)=>(Array.isArray(t[e])?t[e]:[]).map(r=>ev(r,n)).filter(r=>!!r);function tv(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,o=new Set([0]),i=[e[0][0]],s=[0],l=e[0][1];for(;o.sizer?null:(i[0]=[(l[0]+i[0][0])/2,(l[1]+i[0][1])/2],{points:i,edgeWall:s})}function gh(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,o,i,s]=[Math.min(...e),Math.max(...e),Math.min(...n),Math.max(...n)];return[[r,i],[o,i],[o,s],[r,s]]}function nv(t,e,n){let[r,o]=[n[0]-e[0],n[1]-e[1]],i=Math.hypot(r,o)||1e-9,s=Math.min(i,Math.max(0,((t[0]-e[0])*r+(t[1]-e[1])*o)/i));return{dist:Math.hypot(t[0]-(e[0]+r/i*s),t[1]-(e[1]+o/i*s)),along:s,length:i}}var rv={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 _h(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)&&Zn(r,"walls","wall").length>0)}function bh(t){let e=t,r=(Array.isArray(e.rooms)?e.rooms:[e]).filter(b=>b&&typeof b=="object").map(b=>({walls:Zn(b,"walls","wall"),doors:[...Zn(b,"doors","door"),...Zn(b,"openings","opening")],windows:Zn(b,"windows","window"),objects:Zn(b,"objects","object")})).filter(b=>b.walls.length);if(!r.length)throw new Error("roomplan_empty");let o=r.flatMap(b=>b.walls),i=Math.min(...o.map(b=>b.centre[1]-b.size[1]/2)),s=r.map(b=>tv(b.walls)),l=r.flatMap((b,y)=>s[y]?.points??gh(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=Ce(I("floor"),"Erdgeschoss",0);d.height=qe(Math.max(2.2,Math.min(4,Math.max(...o.map(b=>b.size[1])))));let p=[],h=[];r.forEach((b,y)=>{let w=(s[y]?.points??gh(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],E=null;if(w.forEach((P,C)=>{let B=nv(M,P,w[(C+1)%w.length]);B.dist<=.6&&(!E||B.dist1.4?2:1,swing:"in",...O?{style:"passage"}:{},cover:null,contact:null,contact2:null,tilt:null})}for(let k of b.objects){let M=rv[k.kind];if(!M)continue;let[E,T,F]=[k.size[0],k.size[2],k.size[1]];E<.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(E),d:qe(T),h:qe(F),variant:null,entity:null,power:null})}}),d.rooms=p,d.furniture=h;let f=Tt();f.floors=[d];let g=r.reduce((b,y)=>b+y.objects.length,0)-h.length;return{building:Pe(f),report:{floors:1,rooms:p.length,openings:d.openings.length,walls:0,furniture:g}}}var ro=t=>typeof t=="object"&&t!==null&&!Array.isArray(t)&&"ref"in t;function ov(t){let e=0,n=()=>{for(;t[e]===" ";)e++;let o=t[e];if(o==="("){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 sv(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:ov(r[3])});return e}var yh={x:0,y:0,z:0,c:1,s:0},vh=(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 wh(t){let e=sv(t);if(!e.size)throw new Error("ifc_empty");let n=k=>ro(k)?e.get(k.ref):void 0,r=k=>typeof k=="number"?k:NaN,o=k=>(n(k)?.args[0]??[]).map(M=>r(M)),i=[...e.values()].find(k=>k.type==="IFCSIUNIT"&&k.args[1]===".LENGTHUNIT."),s=i?{".MILLI.":.001,".CENTI.":.01,".DECI.":.1}[String(i.args[2])]??1:1,l=k=>{let M=n(k);if(!M)return yh;let[E=0,T=0,F=0]=o(M.args[0]),O=n(M.type==="IFCAXIS2PLACEMENT3D"?M.args[2]:M.args[1]),[P=1,C=0]=(O?.args[0]??[]).map(q=>r(q)),B=Math.hypot(P,C)||1;return{x:E||0,y:T||0,z:F||0,c:P/B,s:C/B}},a=(k,M=0)=>{let E=n(k);return!E||E.type!=="IFCLOCALPLACEMENT"||M>30?yh:vh(a(E.args[0],M+1),l(E.args[1]))},c=k=>{for(let M of n(k)?.args[2]??[])for(let E of n(M)?.args[3]??[]){let T=n(E);if(T?.type!=="IFCEXTRUDEDAREASOLID")continue;let F=n(T.args[0]),O=vh(l(T.args[1]),l(F?.args[2])),P=[];if(F?.type==="IFCRECTANGLEPROFILEDEF"){let[C,B]=[r(F.args[3])/2,r(F.args[4])/2];P=[[-C,-B],[C,-B],[C,B],[-C,B]]}else if(F?.type==="IFCARBITRARYCLOSEDPROFILEDEF"){let C=n(F.args[2]);C?.type==="IFCPOLYLINE"&&(P=(C.args[0]??[]).map(B=>o(B)))}if(P=P.filter(C=>Number.isFinite(C[0])&&Number.isFinite(C[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(([C,B])=>[O.x+O.c*C-O.s*B,O.y+O.s*C+O.c*B])}return null},u=new Map;for(let[,k]of e){if(k.type==="IFCRELAGGREGATES"&&ro(k.args[4]))for(let M of k.args[5]??[])ro(M)&&u.set(M.ref,k.args[4].ref);if(k.type==="IFCRELCONTAINEDINSPATIALSTRUCTURE"&&ro(k.args[5]))for(let M of k.args[4]??[])ro(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 E=c(M.args[6]);if(!E)continue;let T=a(M.args[5]),F=E.map(([P,C])=>[(T.x+T.c*P-T.s*C)*s,(T.y+T.s*P+T.c*C)*s]),O=String(M.args[7]||M.args[2]||"")||`Raum ${p.length+1}`;p.push({storey:u.get(k)??null,name:O,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 E=Ce(I("floor"),k.name??`Etage ${M+1}`,Number.isFinite(k.elevation)?b(k.elevation):M*2.8);y.push(E),v.set(k.id,E)}),p.some(k=>k.storey===null||!v.has(k.storey))){let k=Ce(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 E=y[M+1];E&&E.elevation-k.elevation>1.8&&(k.height=b(E.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(([E,T])=>[b(E-f),b(g-T)]),floor_material:"wood",panel:[]});let x=Tt();return x.floors=y,{building:Pe(x),report:{floors:y.length,rooms:p.length,openings:0,walls:0,furniture:0}}}var xh="nextfloor",av="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",kh=new RegExp(`^(?:${av})\\.[a-z0-9_]+$`),lv=/^[0-9a-f]{32}$/,cv=new Set(["area_id","ha_floor"]),uv=new Set(["sub_areas"]),dv=new Set(["tap","show_when","pictures","moods"]);function Ea(t){if(typeof t=="string")return kh.test(t)||lv.test(t)?null:t;if(Array.isArray(t))return t.map(e=>Ea(e)).filter(e=>e!==null);if(t&&typeof t=="object"){let e={};for(let[n,r]of Object.entries(t))kh.test(n)||dv.has(n)||(cv.has(n)||uv.has(n)?e[n]=null:e[n]=Ea(r));return e}return t}var hv=["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 $h(t){let e=structuredClone(t),n={};for(let o of hv)e.settings?.[o]!==void 0&&(n[o]=e.settings[o]);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 o of e.floors){o.background=null,o.placements=[],o.power_entity=null,o.utility_meters=null,o.ha_floor=null;for(let i of o.rooms)Object.assign(i,{area_id:null,sub_areas:null,panel:[],hidden:[],no_state:[]});o.furniture.forEach(i=>{Object.assign(i,{entity:null,power:null}),delete i.effect_animations,i.picture&&!(i.picture.startsWith("image:")||i.picture.startsWith("https://"))&&(i.picture=null)}),o.openings.forEach(i=>Object.assign(i,{cover:null,contact:null,tilt:null}))}return Ea(e)}function Sh(t,e){return{format:xh,version:1,exported_at:new Date().toISOString(),building:e?$h(t):structuredClone(t)}}var pv=t=>!!t&&(t.version===1||t.version===void 0)&&Array.isArray(t.floors)&&t.floors.every(e=>!!e&&typeof e=="object"),fv="https://therealmrbk.github.io/NextFloor/preview/?shared&noshowcase";function Mh(t,e,n,r,o=fv){let i=new Set(t.floors.flatMap(c=>c.furniture.map(u=>u.type)).filter(c=>c.startsWith("pack:")).map(c=>c.split(":")[1])),s={building:$h(t),packs:e.filter(c=>!c.builtin&&i.has(c.id))},l=JSON.stringify(s).replace(/c.replace(/[&<>"]/g,u=>({"&":"&","<":"<",">":">",'"':"""})[u]);return`
${a(n)}