PageSourceSearch

https://cabinetos.web.app/assets/wall-outline-CNTpxwzA.js

js cabinetos.web.app collected 2026-10-03 12:19:31 UTC 52,510 bytes, 1 lines download raw bytes

1import{$n as e,$r as t,An as n,Br as r,Cr as i,Ct as a,Gr as o,Hr as s,Ir as c,Jr as l,Kr as u,Mr as d,Nr as f,Or as p,Qr as m,Si as h,Sr as g,Ur as _,Vr as v,Wr as y,Zr as b,dr as x,fr as ee,hi as te,hr as S,jr as ne,li as re,lt as ie,mi as ae,nt as oe,wr as se,xr as ce}from"./room-layout-BAk0nD0n.js";var C=e=>!!(e&&e.startPoint&&e.endPoint);function le(e){return Math.hypot(e.endPoint.x-e.startPoint.x,e.endPoint.z-e.startPoint.z)}function ue(e,t){let n=new Map;for(let r of e){let e=!!t.get(r.id)&&!t.stored.has(r.id);if(!e&&s(r.thicknessSide)){n.set(r.id,{side:r.thicknessSide,source:`stored`});continue}let i=u(r,c(r,t));n.set(r.id,{side:i,source:e?`traced`:`derived`})}return n}function w(e){let t=Array.isArray(e)?e.filter(C):[];return ue(t,y(t))}function de(e,{skip:t=null}={}){if(!Array.isArray(e)||e.length===0)return e;let n=w(e),r=!1,i=e.map(e=>{let i=n.get(e?.id)?.side;return!i||e.thicknessSide===i||t?.has(e.id)?e:(r=!0,{...e,thicknessSide:i})});return r?i:e}var fe=`left`;function pe(e,t,{holdHeal:n=!1}={}){if(!Array.isArray(t)||t.length===0)return t;let r=new Set((Array.isArray(e)?e:[]).map(e=>e?.id)),i=!1,a=t.map(e=>!C(e)||r.has(e.id)||s(e.thicknessSide)?e:(i=!0,{...e,thicknessSide:fe})),o=i?a:t;if(!n)return de(o);let c=ye(o);return de(o,{skip:new Set([...c.changed.map(e=>e.id),...c.reseat])})}var me=180*Math.PI/180-1e-9;function he(e){let t=[],n=e=>{for(let n=0;n<t.length;n++)if(Math.hypot(t[n].x-e.x,t[n].z-e.z)<=10)return n;return t.push({x:e.x,z:e.z}),t.length-1},r=e.map(e=>({a:n(e.startPoint),b:n(e.endPoint)})),i=t.map((e,t)=>t),a=e=>{for(;i[e]!==e;)i[e]=i[i[e]],e=i[e];return e};r.forEach(({a:e,b:t})=>{i[a(e)]=a(t)});let o=new Map;return e.forEach((e,t)=>{let n=a(r[t].a);o.has(n)||o.set(n,[]),o.get(n).push({wall:e,a:r[t].a,b:r[t].b})}),[...o.values()].map(e=>({members:e,verts:t}))}function ge(e,t=null){let n=new Map,r=new Map;for(let t of e)r.set(t.a,(r.get(t.a)??0)+1),r.set(t.b,(r.get(t.b)??0)+1);if([...r.values()].some(e=>e>=3)){for(let t of e)n.set(t.wall.id,`left`);return n}let i=null;for(let t of e){if(r.get(t.a)===1){i=t.a;break}if(r.get(t.b)===1){i=t.b;break}}i===null&&(i=e[0].a);let a=new Set,o=new Map,s=i;for(let t=0;t<e.length;t++){let t=e.find(e=>!a.has(e)&&(e.a===s||e.b===s));if(!t)break;a.add(t),o.set(t.wall.id,t.a===s?1:-1),s=t.a===s?t.b:t.a}let c=0,l=0;for(let t of e){let e=o.get(t.wall.id);e===1?c+=le(t.wall):e===-1&&(l+=le(t.wall))}let u=o.get(e[0].wall.id)??1,d=l>c||l===c&&u===-1?-1:1,f=0;if(t){let n=[],r=i,a=new Set;for(let t=0;t<e.length;t++){let t=e.find(e=>!a.has(e)&&(e.a===r||e.b===r));if(!t)break;a.add(t),n.push(r),r=t.a===r?t.b:t.a}n.push(r);let o=0;for(let e=0;e<n.length;e++){let r=t[n[e]],i=t[n[(e+1)%n.length]];if(!r||!i){o=0;break}o+=r.x*i.z-i.x*r.z}let s=0;for(let e=1;e+1<n.length;e++){let r=t[n[e-1]],i=t[n[e]],a=t[n[e+1]];if(!r||!i||!a)continue;let o={x:i.x-r.x,z:i.z-r.z},c={x:a.x-i.x,z:a.z-i.z};s+=Math.atan2(o.x*c.z-o.z*c.x,o.x*c.x+o.z*c.z)}let c=Math.abs(s)>=me,l=o/2*d;c&&Math.abs(l)>1e4&&(f=l>0?1:-1)}for(let t of e){let e=(o.get(t.wall.id)??1)*d,r=f===-1?-e:e;n.set(t.wall.id,r===1?`left`:`right`)}return n}function _e(e,t){let n=le(e);return n>1e-6?a(e,n/2,0,`inner`,0,t).normal:null}function ve(e,t){if(!(le(e)>1e-6))return null;let{normal1:n,normal2:r}=i(e),a={x:(e.startPoint.x+e.endPoint.x)/2,z:(e.startPoint.z+e.endPoint.z)/2},o=v(t,e);if(o){let e=o.x-a.x,t=o.z-a.z,i=n.x*e+n.z*t,s=r.x*e+r.z*t;if(Math.abs(i-s)>1e-6)return i>=s?n:r}return Math.hypot(a.x+n.x,a.z+n.z)<=Math.hypot(a.x+r.x,a.z+r.z)?n:r}function T(e,t,{legacyBefore:n=!1}={}){let r=Array.isArray(e)?e.filter(C):[],i=Array.isArray(t)?t.filter(C):[],a=y(r),o=y(i),s=new Map(r.map(e=>[e.id,e])),c=n?ve:_e,l=[];for(let e of i){let t=s.get(e.id);if(!t)continue;let n=c(t,a),r=_e(e,o);n&&r&&n.x*r.x+n.z*r.z<0&&l.push(e.id)}return l}function ye(e){if(!Array.isArray(e)||e.length===0)return{walls:e,changed:[],reseat:[]};let t=e.filter(C),n=y(t),r=ue(t,n),i=new Map,a=[];for(let e of t){let t=r.get(e.id);i.set(e.id,t.side),!(!t.side||t.source===`traced`||n.partition.has(e.id))&&a.push(e)}for(let{members:e,verts:t}of he(a)){if(e.length<2)continue;let n=ge(e,t),a=0,o=0;for(let t of e)r.get(t.wall.id).side===n.get(t.wall.id)?a+=1:o+=1;if(a!==0&&o!==0)for(let t of e)r.get(t.wall.id).source!==`stored`&&i.set(t.wall.id,n.get(t.wall.id))}let o=[],s=!1,c=e.map(e=>{if(!C(e))return e;let t=i.get(e.id),n=r.get(e.id)?.side;return t&&n&&t!==n&&o.push({id:e.id,from:n,to:t}),!t||e.thicknessSide===t?e:(s=!0,{...e,thicknessSide:t})}),l=s?c:e;return{walls:l,changed:o,reseat:s?T(e,l,{legacyBefore:!0}):[]}}function be(e,t){if(!Array.isArray(e))return null;let n=e.find(e=>e?.id===t);if(!C(n))return null;let r=w(e).get(t);if(!r?.side||r.source===`traced`)return null;let i=_(r.side);return e.map(e=>e===n?{...e,thicknessSide:i}:e)}var xe=Object.freeze([`cabinets`,`objects`,`structures`]);function E(e,t){let n=t instanceof Set?t:new Set(Array.isArray(t)?t:[]);if(!e||n.size===0)return e;let r=!1,i={};for(let t of xe){let a=e[t];if(!Array.isArray(a))continue;let o=!1,s=a.map(e=>{let t=e?.anchor;if(!t||!n.has(t.wallId))return e;o=!0;let r=(t.side??`inner`)===`inner`?`outer`:`inner`;return{...e,anchor:{...t,side:r}}});o&&(i[t]=s,r=!0)}return r?{...e,...i}:e}var Se=e=>e instanceof Set?e:new Set(Array.isArray(e)?e:[]);function D(e,t,{finishOpts:r}={}){let i=Se(t);if(!e||i.size===0)return e;let a=Array.isArray(e.walls)?e.walls:[],o=e=>!!e?.anchor&&(i.has(e.anchor.wallId)||i.has(e.anchor.wallBId)),s={},c=e.cabinets,l=new Set;if(Array.isArray(c)&&c.some(o)&&(c=c.map(e=>o(e)?(l.add(e.id),oe(e,a)):e),s.cabinets=c),Array.isArray(e.objects)){let t=e=>e?.host?l.has(e.host.cabinetId):o(e);e.objects.some(t)&&(s.objects=e.objects.map(e=>t(e)?ie(e,a,Array.isArray(c)?c:[],r??{}):e))}return Array.isArray(e.structures)&&e.structures.some(o)&&(s.structures=e.structures.map(e=>
1o(e)?n(e,a):e)),Object.keys(s).length?{...e,...s}:e}function Ce(e,t){let n=Se(t),r=0;for(let t of Array.isArray(e)?e:[])if(n.has(t?.id))for(let e of t.openings??[])ae(e)===`door`&&te(e)!==`pocket`&&(r+=1);return r}function we(e,t){let n=Se(t),r=0;for(let t of Array.isArray(e)?e:[])if(n.has(t?.id)){r+=(t.fixtures??[]).length;for(let e of t.openings??[])re(e)&&(r+=1)}return r}function Te(e,t){let n=Se(t),r=0;for(let t of xe)for(let i of e?.[t]??[])i?.anchor&&n.has(i.anchor.wallId)&&(r+=1);return r}function Ee(e,{finishOpts:t}={}){let n=e?.walls;if(!Array.isArray(n)||n.length===0)return{zone:e,heal:null};let r=ye(n);if(r.walls===n)return{zone:e,heal:null};let i={...e,walls:r.walls};if(r.changed.length===0&&r.reseat.length===0)return{zone:i,heal:null};let a=new Set([...r.reseat,...r.changed.map(e=>e.id)]),o=D(E(i,r.reseat),a,{finishOpts:t}),s={walls:n};for(let t of xe)o[t]!==e[t]&&(s[t]=e[t]);let c={};for(let e of r.walls)a.has(e?.id)&&(c[e.id]=e.thicknessSide);let l=new Set(r.changed.map(e=>e.id));return{zone:o,heal:{before:s,changed:r.changed,reseat:r.reseat,healedSides:c,doors:Ce(r.walls,l),items:Te(e,r.reseat.filter(e=>l.has(e))),inside:Te(e,r.reseat.filter(e=>!l.has(e))),faces:we(r.walls,l)}}}function De(e,t,{finishOpts:n}={}){let r=e?.walls;if(!t||!Array.isArray(r))return e;let i=new Map((t.changed??[]).map(e=>[e.id,e])),a=!1,o=r.map(e=>{let t=i.get(e?.id);return!t||e.thicknessSide===t.from?e:(a=!0,{...e,thicknessSide:t.from})}),s=de(a?o:r);if(s===r)return e;let c=T(r,s),l=new Set([...c,...i.keys()]);return D(E({...e,walls:s},c),l,{finishOpts:n})}function Oe(e,t,{finishOpts:n}={}){let r=e?.walls;if(!t||!Array.isArray(r))return e;let i=new Map((t.before?.walls??[]).map(e=>[e?.id,e])),a=t.healedSides??{},o=new Set,c=r.map(e=>{if(!e||!Object.prototype.hasOwnProperty.call(a,e.id)||e.thicknessSide!==a[e.id])return e;let t=i.get(e.id)?.thicknessSide;if(t===e.thicknessSide)return e;if(o.add(e.id),s(t))return{...e,thicknessSide:t};let{thicknessSide:n,...r}=e;return r}),l=o.size?{...e,walls:c}:e,u=(t.reseat??[]).filter(e=>o.has(e));if(u.length&&Array.isArray(l.structures)){let e=E({walls:l.walls,structures:l.structures},u);e.structures!==l.structures&&(l={...l,structures:D(e,o,{finishOpts:n}).structures})}let d={};return t.before&&`cabinets`in t.before&&(d.cabinets=t.before.cabinets),t.before&&`objects`in t.before&&(d.objects=t.before.objects),Object.keys(d).length?{...l,...d}:l}function ke(e,t){let n=w(e).get(t);return!n||!n.side?`degenerate`:n.source===`traced`?`shell`:null}function Ae(e,t,{finishOpts:n}={}){let r=e?.walls,i=be(r,t);if(!i)return null;let a=T(r,i),o=D(E({...e,walls:i},a),new Set([t,...a]),{finishOpts:n}),s={walls:i};for(let t of xe)o[t]!==e[t]&&(s[t]=o[t]);return s}var je=new WeakMap;function Me(e,t){let n=e?.walls;if(!Array.isArray(n)||n.length===0||!Array.isArray(t))return e;let r=new Map;for(let e of t)e?.id&&s(e.thicknessSide)&&r.set(e.id,e.thicknessSide);if(r.size===0)return e;let i=!1,a=n.map(e=>{let t=r.get(e?.id);return!t||e.thicknessSide===t?e:(i=!0,{...e,thicknessSide:t})});if(!i)return e;let o=a.map(e=>`${e?.id}:${e?.thicknessSide??``}`).join(`|`),c=je.get(e);if(c?.key===o)return c.result;let l=T(n,a,{legacyBefore:!0}),u=w(n),d=w(a),f=new Set(l);for(let e of a)u.get(e?.id)?.side!==d.get(e?.id)?.side&&f.add(e.id);let p=D(E({...e,walls:a},l),f);return je.set(e,{key:o,result:p}),p}var O=Object.freeze({joinTolMm:10,collinearSin:Math.sin(15*Math.PI/180),parallelRailSin:Math.sin(1*Math.PI/180),snapPullPx:10,dragThresholdPx:6,dragThresholdTouchPx:10,holdMs:350,coarseRoundMm:10,fineRoundMm:1,fineBelowMmPerPx:2,bisectSteps:24,minTypedMm:S.MIN_WALL_LENGTH,maxTypedMm:3e4}),Ne=S.MIN_WALL_LENGTH,k=1e-6,Pe=.01,Fe=1e-6,Ie=.05,A=Object.freeze({x:0,z:0}),Le=.03,Re=Math.sin(5*Math.PI/180),ze=.5,Be=Object.freeze({wall:0,point:1,equal:2,original:3}),j=(e,t)=>({x:e.x-t.x,z:e.z-t.z}),M=(e,t)=>({x:e.x+t.x,z:e.z+t.z}),N=(e,t)=>({x:e.x*t,z:e.z*t}),P=(e,t)=>e.x*t.x+e.z*t.z,F=(e,t)=>e.x*t.z-e.z*t.x,I=e=>Math.hypot(e.x,e.z),L=(e,t)=>Math.hypot(e.x-t.x,e.z-t.z),Ve=e=>{let t=I(e);return t>k?{x:e.x/t,z:e.z/t}:null},R=e=>({x:e.x,z:e.z}),He=e=>Math.abs(e)<1e-9?0:e,z=(e,t)=>t===`start`?e.startPoint:e.endPoint,Ue=e=>e===`start`?`end`:`start`,B=e=>g(e.startPoint,e.endPoint),V=e=>Ve(j(e.endPoint,e.startPoint)),H=e=>({x:-e.z,z:e.x}),We=(e,t)=>
1Ve(j(z(e,Ue(t)),z(e,t))),U=(e,t)=>Array.isArray(e)?e.find(e=>e?.id===t):null,W=e=>!!(e?.startPoint&&e?.endPoint),G=(e,t)=>t>0?Math.round(e/t)*t:e;function Ge(e,t,n,r){let i=[t],a=[],o=new Set;for(let t=!0;t;){t=!1;for(let s of e)if(!(!W(s)||s.id===n))for(let e of[`start`,`end`]){let n=`${s.id}:${e}`;if(o.has(n))continue;let c=z(s,e);i.some(e=>L(e,c)<=r)&&(o.add(n),a.push({wallId:s.id,which:e}),i.push(c),t=!0)}}return a}function K(e,t,n,r=O.joinTolMm){let i=U(e,t);return W(i)?Ge(e,z(i,n),t,r):[]}function q(e,t,n=O.joinTolMm){let r=U(e,t);if(!W(r))return[];let i=V(r);if(!i)return[];let a=H(i),o=B(r),s=[];for(let c of e){if(!W(c)||c.id===t)continue;let e=V(c);if(!(!e||Math.abs(P(e,a))<O.collinearSin))for(let e of[`start`,`end`]){let t=j(z(c,e),r.startPoint),l=P(t,i);Math.abs(P(t,a))<=n&&l>n&&l<o-n&&s.push({wallId:c.id,which:e,t:l})}}return s}function J(e,t,n,r=O.joinTolMm){return Ke(e,t,n,r)[0]??null}function Ke(e,t,n,r){let i=U(e,t);if(!W(i))return[];let a=V(i);if(!a)return[];let o=z(i,n),s=[];for(let n of e){if(!W(n)||n.id===t)continue;let e=V(n);if(!e)continue;let i=H(e);if(Math.abs(P(a,i))<O.collinearSin)continue;let c=j(o,n.startPoint),l=P(c,e),u=Math.abs(P(c,i));u<=r&&l>r&&l<B(n)-r&&s.push({hostId:n.id,t:l,off:u})}return s.sort((e,t)=>e.off-t.off).map(({hostId:e,t})=>({hostId:e,t}))}function qe(e,t,n,r){let i=e=>P(e,r)<0?N(e,-1):e;if(n){let t=U(e,n.hostId),a=t?V(t):null;if(a&&Math.abs(P(a,r))>=O.collinearSin)return i(a)}let a=[];for(let n of t){let t=U(e,n.wallId),i=t?We(t,n.which):null;i&&Math.abs(P(i,r))>=O.collinearSin&&a.push(i)}return a.length===1?i(a[0]):null}function Je(e,t,n){return K(e,t.id,`start`,n).length>0||K(e,t.id,`end`,n).length>0||!!J(e,t.id,`start`,n)||!!J(e,t.id,`end`,n)||q(e,t.id,n).length>0}function Ye(e,t,n,r,i,a){let c=t.startPoint,l=B(t),u=O.joinTolMm,d=a?.get(t.id)?.side??(s(t.thicknessSide)?t.thicknessSide:null),f=d?o(t,d):null,p=f&&Math.sign(-P(f,r))||null,m=[null,null,null,null];for(let a of e){if(!W(a)||a.id===t.id||i.has(a.id))continue;let o=V(a);if(!o||Math.abs(F(n,o))>Le)continue;let s=P(j(a.startPoint,c),n),d=P(j(a.endPoint,c),n),f=Math.max(0,Math.min(s,d)),h=Math.min(l,Math.max(s,d));if(h-f<=1)continue;let g=((f+h)/2-s)/(d-s),_=P(j(M(a.startPoint,N(j(a.endPoint,a.startPoint),g)),c),r);if(Math.abs(_)<=u)continue;let v={wallId:a.id,s0:_},y=!!p&&Math.sign(_)===p,b=Je(e,a,u),x=e=>{(!m[e]||Math.abs(_)<Math.abs(m[e].s0))&&(m[e]=v)};y&&b&&x(0),y&&x(1),b&&x(2),x(3)}return m.find(Boolean)??null}function Xe(e,t,n,r,i){let a=[];for(let o of t)if(!i.has(o))for(let t of q(e,o,r))n.has(`${t.wallId}:${t.which}`)||a.push({hostId:o,wallId:t.wallId,which:t.which});return a}function Ze(e,t,n,r,i){let a=[],o=new Set;for(let s of t)for(let t of s.which===`both`?[`start`,`end`]:[s.which]){let c=`${s.wallId}:${t}`;if(!o.has(c)){o.add(c);for(let o of Ke(e,s.wallId,t,i))n.has(o.hostId)||a.push({hostId:o.hostId,wallId:s.wallId,which:t,...r.has(c)&&{detachOnly:!0}})}}return a}function Qe(e){let t=new Set;return e.filter(e=>{let n=`${e.wallId}:${e.which}`;return!t.has(n)&&(t.add(n),!0)})}function $e(e,t,n){let r=new Map;for(let i of t){let t=U(e,i);if(!t||s(t.thicknessSide))continue;let a=n?.get(i)?.side;a&&r.set(i,a)}return r}var et=(e,t)=>[...t].some(t=>{let n=U(e,t);return!!n&&!s(n.thicknessSide)});function tt(e,t,n={}){let r=U(e,t);if(!W(r))return{ok:!1,reason:`missing`,wallId:t};let i=V(r);if(!i)return{ok:!1,reason:`degenerate`,wallId:t};if(r.locked)return{ok:!1,reason:`locked`,wallId:t};let a=H(i),o=O.joinTolMm,s=B(r),c={start:K(e,t,`start`,o),end:K(e,t,`end`,o)},l={start:J(e,t,`start`,o),end:J(e,t,`end`,o)},u=q(e,t,o),d=!c.start.length&&!c.end.length&&!l.start&&!l.end&&!u.length,f,p=null,m=null;if(n.free||d)f=`free`;else{let t=qe(e,c.start,l.start,a),n=qe(e,c.end,l.end,a);if(t&&n){let e=Math.abs(F(t,n));e<1e-9?(f=`rail`,p=t):e<O.parallelRailSin?(f=`offset`,p=t,m={start:{r:t,rn:P(t,a)},end:{r:n,rn:P(n,a)}}):(f=`normal`,p=a)}else t||n?(f=`rail`,p=t??n):(f=`normal`,p=a)}let h=[];for(let e of[`start`,`end`])for(let t of c[e])h.push({wallId:t.wallId,which:t.which,kind:`join`,end:e});for(let n of u){let r=U(e,n.wallId),i=Ge(e,z(r,n.which),t,o);if(i.length>1){for(let e of i)h.push({wallId:e.wallId,which:e.which,kind:`teeJoin`,at:n.t/s});continue}let c=V(r);c&&h.push({wallId:n.wallId,which:n.which,kind:`tee`,p:c,pn:P(c,a)})}let g=Qe(h),_=[...new Set(g.map(e=>e.wallId))];if(_.some(t=>U(e,t)?.locked))return{ok:!1,reason:`neighbourLocked`,wallId:t};let v=new Set([t,..._]),y=[`start`,`end`].filter(e=>l[e]).map(e=>({which:e,hostId:l[e].hostId})),b=w(e);return{ok:!0,kind:`move`,wallId:t,mode:f,u:i,n:a,rail:p,railDot:p?P(p,a):1,rails:m,base:e,index:it(e),len0:s,start0:R(r.startPoint),end0:R(r.endPoint),followers:g,followerIds:_,hosts:y,tees:u.map(e=>({wallId:e.wallId,which:e.which,hostId:t})),followerTees:Xe(e,_,rt(t,[`start`,`end`],g),o,new Set),endHosts:[...[`start`,`end`].flatMap(n=>Ke(e,t,n,o).slice(1).map(e=>({hostId:e.hostId,wallId:t,which:n}))),...Ze(e,g,new Set([t]),new Set,o)],movingIds:v,movingPoints:rt(t,[`start`,`end`],g),pinSides:$e(e,v,b),opposite:Ye(e,r,i,a,v,b),detaches:!1}}function nt(e,t,n,r={}){let i=U(e,t);if(!W(i))return{ok:!1,reason:`missing`,wallId:t};
1if(!V(i))return{ok:!1,reason:`degenerate`,wallId:t};if(i.locked)return{ok:!1,reason:`locked`,wallId:t};let a=n===`start`?`start`:`end`,o=Ue(a),s=O.joinTolMm,c=z(i,a),l=z(i,o),u=Ve(j(c,l)),d=H(V(i)),f=[],p=[],m=null,h=[],g=[],_=K(e,t,a,s);for(let t of _){let n=U(e,t.wallId),r=n?We(n,t.which):null;!r||Math.abs(P(r,d))<O.collinearSin?f.push({wallId:t.wallId,which:t.which,kind:`end`}):h.push(t)}if(h.length===1&&!r.pivot){let n=h[0],r=U(e,n.wallId),i=Ue(n.which),a=K(e,r.id,i,s);if(a.some(e=>e.wallId===t&&e.which===o))p.push(n);else{m={wallId:r.id,which:n.which},f.push({wallId:r.id,which:`both`,kind:`whole`});for(let e of a)e.wallId!==t&&f.push({wallId:e.wallId,which:e.which,kind:`end`});let i=H(V(r));for(let n of q(e,r.id,s)){if(n.wallId===t)continue;let a=U(e,n.wallId),o=Ge(e,z(a,n.which),r.id,s);if(o.length>1){for(let e of o)e.wallId!==t&&f.push({wallId:e.wallId,which:e.which,kind:`end`});continue}let c=V(a);c&&(f.push({wallId:n.wallId,which:n.which,kind:`tee`,p:c,pn:P(c,i),n:i}),g.push({wallId:n.wallId,which:n.which,hostId:r.id}))}}}else p.push(...h);for(let e of p)f.push({wallId:e.wallId,which:e.which,kind:`end`});let v=Qe(f),y=[...new Set(v.map(e=>e.wallId))];if(y.some(t=>U(e,t)?.locked))return{ok:!1,reason:`neighbourLocked`,wallId:t};let b=new Set([t,...y]),x=0;for(let n of q(e,t,s)){let e=o===`start`?n.t:B(i)-n.t;e>x&&(x=e)}let ee=m?Ue(m.which):null,te=m?J(e,m.wallId,ee,s):null,S=et(e,b)?w(e):null;return{ok:!0,kind:`stretch`,wallId:t,which:a,fixedWhich:o,u:V(i),n:d,dir:u,base:e,index:it(e),len0:L(c,l),fixedPoint:R(l),end0:R(c),pivot:!!r.pivot||!m,carriedId:m?.wallId??null,carriedHost:te?{hostId:te.hostId,wallId:m.wallId,which:ee}:null,followers:v,followerIds:y,followerTees:Xe(e,y,rt(t,[a],v),s,new Set(m?[m.wallId]:[])),tees:g,endHosts:Ze(e,v,new Set([t,m?.wallId]),new Set([..._.map(e=>
1`${e.wallId}:${e.which}`),m?`${m.wallId}:${ee}`:``]),s),teeLimit:x,movingIds:b,movingPoints:rt(t,[a],v),pinSides:$e(e,b,S),detaches:!!J(e,t,a,s)}}function rt(e,t,n){let r=new Set(t.map(t=>`${e}:${t}`));for(let e of n)e.which===`both`?(r.add(`${e.wallId}:start`),r.add(`${e.wallId}:end`)):r.add(`${e.wallId}:${e.which}`);return r}function it(e){let t=new Map;for(let n of Array.isArray(e)?e:[])W(n)&&t.set(n.id,n);return t}function at(e){return e?.kind===`stretch`?e.len0:e?.kind===`move`&&e.mode===`free`?{x:0,z:0}:0}function ot(e,t,n){let r=j(n,t);return e?.kind===`stretch`?e.len0+P(r,e.dir):e?.kind===`move`&&e.mode===`free`?r:P(r,e?.n??{x:0,z:0})}function st(e){return O.snapPullPx*(Number.isFinite(e)&&e>0?e:1)}function ct(e){return Number.isFinite(e)&&e>=O.fineBelowMmPerPx?O.coarseRoundMm:O.fineRoundMm}var lt=e=>!!e&&Number.isFinite(e.x)&&Number.isFinite(e.z);function ut(e,t){return e.kind===`move`&&e.mode===`free`?lt(t):Number.isFinite(t)}function dt(e,t){if(e.mode===`free`){let e={x:t.x,z:t.z};return{start:e,end:e}}if(e.rails)return{start:N(e.rails.start.r,t/e.rails.start.rn),end:N(e.rails.end.r,t/e.rails.end.rn)};let n=N(e.rail,t/e.railDot);return{start:n,end:n}}function ft(e,t){let n=new Map,r=(e,t,r)=>{let i=n.get(e)??{start:null,end:null};t===`both`?(i.start??=r,i.end??=r):i[t]??=r,n.set(e,i)};if(e.kind===`move`){let n=dt(e,t);r(e.wallId,`start`,n.start),r(e.wallId,`end`,n.end);let i=e.mode===`free`?P(t,e.n):t;for(let t of e.followers)t.kind===`tee`?r(t.wallId,t.which,N(t.p,i/t.pn)):t.kind===`teeJoin`?r(t.wallId,t.which,n.start===n.end?n.start:M(n.start,N(j(n.end,n.start),t.at))):r(t.wallId,t.which,n[t.end]??n.start)}else{let n=N(e.dir,t-e.len0);r(e.wallId,e.which,n);for(let t of e.followers)t.kind===`tee`?r(t.wallId,t.which,N(t.p,P(n,t.n)/t.pn)):r(t.wallId,t.which,n)}return n}var pt=(e,t)=>t===A?e:{...e,x:e.x+t.x,z:e.z+t.z},mt=(e,t)=>t===e.base&&e.index?e.index:it(t);function ht(e,t,n){let r=mt(e,n),i=new Map;for(let[n,a]of ft(e,t)){let e=a.start&&I(a.start)>k?a.start:A,t=a.end&&I(a.end)>k?a.end:A,o=r.get(n);o&&(e!==A||t!==A)&&i.set(n,{w:o,dS:e,dE:t})}return{index:r,moves:i}}function gt(e,t,n){let r=e.moves.get(t),i=r?.w??e.index.get(t);return i?{p0:z(i,n),d:r?n===`start`?r.dS:r.dE:A}:null}function _t(e,t,n,r){if(!(e>=0))return null;let i=Math.abs(e)+Math.abs(t)+Math.abs(n);if(i===0)return null;if(e===0){if(t<0||t===0&&n<0)return 0;if(n<0){let e=-t/n;return e<=r?e:null}return null}if(Math.abs(n)<=1e-12*i){if(t>=0)return null;let n=-e/t;return n<=r?n:null}let a=t*t-4*n*e;if(a<=0)return null;let o=Math.sqrt(a),s=-.5*(t+(t>=0?o:-o)),c=Math.min(s/n,e/s),l=Math.max(s/n,e/s),u=n>0?l>0?Math.max(0,c):null:l;return u!=null&&u<=r?u:null}function vt(e,t,n){let r=[],i=[...n.moves.keys()],a=i.includes(e.wallId)?[e.wallId,...i.filter(t=>t!==e.wallId)]:i;for(let t of a){let{w:i,dS:a,dE:o}=n.moves.get(t),s=t===e.wallId,c=j(i.endPoint,i.startPoint),l=I(c);if(l<k)continue;let u=j(o,a),d=P(c,u),f=s?`tooShort`:`neighbourTooShort`;if(r.push({c0:l*l*(1-1e-9),c1:d,c2:0,reason:s&&e.kind===`stretch`?`tooShort`:`reversed`}),l<Ne)d/l<-1e-6&&r.push({immediate:!0,reason:f});else{let e=Math.min(Ne,l-Pe);r.push({c0:l*l-e*e,c1:2*d,c2:P(u,u),reason:f})}}e.kind===`stretch`&&e.teeLimit>0&&r.push({c0:e.len0-e.teeLimit+k,c1:t-e.len0,c2:0,reason:`tJoin`});let o=(e,t,n,i)=>{if(!e||!t||!n||e.d===A&&t.d===A&&n.d===A)return;let a=j(n.p0,t.p0),o=j(n.d,t.d),s=j(e.p0,t.p0),c=j(e.d,t.d),l=j(n.p0,e.p0),u=j(n.d,e.d),d=1e-12*P(a,a);r.push({c0:P(s,a)+d,c1:P(s,o)+P(c,a),c2:P(c,o),reason:i}),r.push({c0:P(l,a)+d,c1:P(l,o)+P(u,a),c2:P(u,o),reason:i})},s=(e,t)=>gt(n,e,t);for(let t of e.tees??[])o(s(t.wallId,t.which),s(t.hostId,`start`),s(t.hostId,`end`),`tJoin`);if(e.kind===`move`)for(let t of e.hosts)o(s(e.wallId,t.which),s(t.hostId,`start`),s(t.hostId,`end`),`offHost`);let c=e.carriedHost;c&&o(s(c.wallId,c.which),s(c.hostId,`start`),s(c.hostId,`end`),`offHost`);for(let t of e.endHosts??[])t.detachOnly||o(s(t.wallId,t.which),s(t.hostId,`start`),s(t.hostId,`end`),`offHost`);for(let t of e.followerTees??[])n.moves.has(t.hostId)&&o(s(t.wallId,t.which),s(t.hostId,`start`),s(t.hostId,`end`),`tJoin`);return r}function yt(e,t,n){let r=null,i=null;for(let a of vt(e,t,n)){let e=a.immediate?0:_t(a.c0,a.c1,a.c2,1);e!=null&&((!r||e<r.t)&&(r={t:e,reason:a.reason}),!i&&(a.immediate||a.c0+a.c1+a.c2<0)&&(i=a.reason))}return r?{t:r.t,reason:i??r.reason,firstReason:r.reason}:null}function bt(e,t,n){let r=ht(e,t,n);return!r.moves.size||!yt(e,t,r)}function xt(e,t){let n=j(t.startPoint,e.startPoint),r=j(t.endPoint,e.endPoint);if(I(n)<k&&I(r)<k)return null;let i;if(I(n)<k)i=0;else if(I(r)<k)i=B(t)-B(e);else if(I(j(n,r))<k)i=0;else{let t=V(e);
1i=t?-P(n,t):0}return He(i)}function St(e,t,n=null){let r=new Map,i=n?new Set(n):null,a=it(e);for(let e of Array.isArray(t)?t:[]){if(!W(e)||i&&!i.has(e.id))continue;let t=a.get(e.id),n=t?xt(t,e):null;n!=null&&r.set(e.id,n)}return r}function Y(e,t,n=e?.base){let i=Array.isArray(n)?n:[],a=e=>({ok:!1,reason:e,walls:i,offsetShift:new Map,touchedWallIds:[],detaches:!1,lengthChangeMm:0});if(!e?.ok)return a(e?.reason??`noPlan`);if(!ut(e,t))return a(`invalid`);let o=ht(e,t,i);if(!o.moves.size)return{ok:!0,reason:null,walls:i,offsetShift:new Map,touchedWallIds:[],detaches:!1,lengthChangeMm:0};let c=yt(e,t,o);if(c)return a(c.reason);let l=[...o.moves.keys()],u=new Map,f=i.map(t=>{let n=t&&o.moves.get(t.id);if(!n||u.has(t.id))return t;let r={...t,startPoint:pt(t.startPoint,n.dS),endPoint:pt(t.endPoint,n.dE)},i=e.pinSides?.get(t.id);i&&!s(t.thicknessSide)&&(r.thicknessSide=i);let a=d(r);return u.set(t.id,a),a}),p=e=>u.get(e)??o.index.get(e),m=O.joinTolMm,h=(e,t)=>{let n=t?V(t):null;return!!n&&!!e&&Math.abs(F(n,j(e,t.startPoint)))>m},g=!!e.detaches;if(e.kind===`move`){let t=p(e.wallId);for(let n of e.hosts)h(z(t,n.which),p(n.hostId))&&(g=!0)}let _=e.carriedHost;_&&h(z(p(_.wallId),_.which),p(_.hostId))&&(g=!0);for(let t of e.endHosts??[])u.has(t.wallId)&&h(z(p(t.wallId),t.which),p(t.hostId))&&(g=!0);for(let t of e.followerTees??[]){let e=p(t.wallId);u.has(t.hostId)&&e&&h(z(e,t.which),p(t.hostId))&&(g=!0)}let v=r(i,f),y=new Map,b=v===f?e=>u.get(e):e=>U(v,e);for(let e of l){let t=xt(o.index.get(e),b(e));t!=null&&y.set(e,t)}let x=b(e.wallId);return{ok:!0,reason:null,walls:v,offsetShift:y,touchedWallIds:l,detaches:g,lengthChangeMm:x?He(B(x)-e.len0):0}}function Ct(e,t,n=e?.base){let r=at(e);if(!e?.ok||!ut(e,t))return{value:r,result:Y(e,r,n),clampedReason:e?.ok?`invalid`:e?.reason??`noPlan`};let i=Array.isArray(n)?n:[],a=e.kind===`move`&&e.mode===`free`,o=e=>a?{x:r.x+e*(t.x-r.x),z:r.z+e*(t.z-r.z)}:r+e*(t-r),s=ht(e,t,i),c=s.moves.size?yt(e,t,s):null;if(!c)return{value:t,result:Y(e,t,n),clampedReason:null};let l=a?L(t,r):Math.abs(t-r),u=Math.max(0,c.t-Fe/Math.max(l,k));if(u>0&&!bt(e,o(u),i)){let t=0,n=u;for(let r=0;r<O.bisectSteps;r++){let r=(t+n)/2;bt(e,o(r),i)?t=r:n=r}u=t}let d=u*l<=Ie?r:o(u);return{value:d,result:Y(e,d,n),clampedReason:c.firstReason}}var wt=(e,t)=>{if(!e||t==null)return 0;let n=e instanceof Map?e.get(t):e[t];return Number.isFinite(n)?n:0};function Tt(e,t){if(!Array.isArray(e))return e;let n=!1,r=e.map(e=>{let r=wt(t,e?.id);if(!r)return e;let i=e=>Array.isArray(e)?e.map(e=>Number.isFinite(e?.offsetAlong)?{...e,offsetAlong:e.offsetAlong+r}:e):e;if(!((e.openings??[]).some(e=>Number.isFinite(e?.offsetAlong))||(e.fixtures??[]).some(e=>Number.isFinite(e?.offsetAlong))))return e;n=!0;let a={...e};return Array.isArray(e.openings)&&(a.openings=i(e.openings)),Array.isArray(e.fixtures)&&(a.fixtures=i(e.fixtures)),a});return n?r:e}function Et(e){let t=e?.anchor;return!t||t.kind===`corner`||e.spanWall||e.host?null:t.wallId!=null&&Number.isFinite(t.offsetAlong)?t:null}function Dt(e,t){if(!Array.isArray(e))return e;let n=!1,r=e.map(e=>{let r=Et(e),i=r?wt(t,r.wallId):0;return i?(n=!0,{...e,anchor:{...r,offsetAlong:r.offsetAlong+i}}):e});return n?r:e}function Ot(e,t,n,{resolve:r=!0,finishOpts:i}={}){let a=Array.isArray(e?.walls)?e.walls:[],o=Y(t,n,a);if(!o.ok)return{ok:!1,reason:o.reason,walls:a,cabinets:e?.cabinets,objects:e?.objects,structures:e?.structures,overflow:[],touchedWallIds:[],offsetShift:o.offsetShift,detaches:!1,lengthChangeMm:0};let s={walls:Tt(o.walls,o.offsetShift),cabinets:Dt(e?.cabinets,o.offsetShift),objects:Dt(e?.objects,o.offsetShift),structures:Dt(e?.structures,o.offsetShift)};if(r&&o.touchedWallIds.length){let e=s;s=l(()=>D(e,o.touchedWallIds,{finishOpts:i}))}let c=zt(s.walls,s,{wallIds:o.touchedWallIds});return{ok:!0,reason:null,walls:s.walls,cabinets:s.cabinets,objects:s.objects,structures:s.structures,overflow:c,touchedWallIds:o.touchedWallIds,offsetShift:o.offsetShift,detaches:o.detaches,lengthChangeMm:o.lengthChangeMm}}var kt=new WeakMap;function At(e,t){let n=kt.get(t);if(n&&n.walls===e)return n.verts;let r=[];for(let n of e)if(W(n))for(let e of[`start`,`end`])t.movingPoints.has(`${n.id}:${e}`)||r.push(R(z(n,e)));return kt.set(t,{walls:e,verts:r}),r}function jt(e,t,n,r,i){let a=n.map(e=>({...e,d:i(e.value,r)})).filter(e=>Number.isFinite(e.d)&&e.d<=e.pull).sort((e,t)=>
1Math.abs(e.d-t.d)>1e-6?e.d-t.d:Be[e.kind]-Be[t.kind]);for(let n of a)if(bt(e,n.value,t))return n;return null}function Mt(e,t,n,{pullMm:r=0,roundMm:i=O.fineRoundMm,free:a=!1}={}){if(!t?.ok||t.kind!==`stretch`||!Number.isFinite(n))return{length:n,snap:null};if(a)return{length:G(n,O.fineRoundMm),snap:null};let o=Array.isArray(e)?e:[],s=t.fixedPoint,c=t.dir,l=O.joinTolMm,u=e=>M(s,N(c,e)),d=[];for(let e of o){if(!W(e)||t.movingIds.has(e.id))continue;let n=R(e.startPoint),i=R(e.endPoint),a=j(i,n),o=I(a);if(o<k)continue;let f=N(a,1/o),p=F(c,f);if(Math.abs(p)>=Re){let e=F(j(n,s),f)/p,t=F(j(n,s),c)/p;e>=Ne&&t>=-l&&t<=o+l&&d.push({kind:`wall`,value:e,point:u(e),guide:[n,i],pull:r})}Math.abs(p)<=Le&&o>=Ne&&d.push({kind:`equal`,value:o,point:u(o),guide:[n,i],pull:r})}for(let e of At(o,t)){let t=P(j(e,s),c);t>=Ne&&d.push({kind:`point`,value:t,point:u(t),guide:[u(t),e],pull:r})}d.push({kind:`original`,value:t.len0,point:R(t.end0),guide:[s,R(t.end0)],pull:r});let f=jt(t,o,d,n,(e,t)=>Math.abs(e-t));return f?{length:f.value,snap:{kind:f.kind,point:f.point,guide:f.guide}}:{length:G(n,i),snap:null}}function Nt(e,t,n,{pullMm:r=0,roundMm:i=O.fineRoundMm,free:a=!1}={}){if(!t?.ok||t.kind!==`move`||!ut(t,n))return{value:n,snap:null};let o=t.mode===`free`,s=a?O.fineRoundMm:i,c=e=>o?{x:G(e.x,s),z:G(e.z,s)}:G(e,s);if(a)return{value:c(n),snap:null};let l=Array.isArray(e)?e:[],u=t.start0,d=t.end0,f=[];if(o){for(let e of At(l,t))for(let t of[u,d])f.push({kind:`point`,value:j(e,t),point:e,guide:[t,e],pull:r});f.push({kind:`original`,value:{x:0,z:0},point:u,guide:[u,d],pull:r})}else{for(let e of At(l,t)){let n=P(j(e,u),t.n),i=dt(t,n),a=M(u,i.start),o=M(d,i.end),s=L(e,a)<=L(e,o)?a:o;f.push({kind:`point`,value:n,point:e,guide:[e,s],pull:r})}f.push({kind:`original`,value:0,point:u,guide:[u,d],pull:r})}let p=jt(t,l,f,n,o?(e,t)=>L(e,t):(e,t)=>Math.abs(e-t));return p?{value:p.value,snap:{kind:p.kind,point:p.point,guide:p.guide}}:{value:c(n),snap:null}}function Pt(e,t,n){let r=lt(n)?P(n,t?.n??{x:0,z:0}):Number.isFinite(n)?n:0,i=t?.kind===`move`?t.opposite:null;return{clearMm:i?Math.abs(i.s0-r):null,clearDeltaMm:i?He(Math.abs(i.s0-r)-Math.abs(i.s0)):null,oppositeWallId:i?.wallId??null,offsetMm:He(r)}}function Ft(e,t,n){let r=e?.kind===`move`?e.opposite:null;if(!r)return t;let i=lt(n)?P(n,e.n):n,a=Number.isFinite(i)?Math.sign(r.s0-i):0;return r.s0-(a||Math.sign(r.s0))*t}var It=Object.freeze([[`cabinets`,`cabinet`],[`objects`,`object`],[`structures`,`structure`]]);function Lt(e,t,n){let r=-e,i=t-n;return r<=ze&&i<=ze?null:r>=i?{overMm:r,end:`start`}:{overMm:i,end:`end`}}var Rt=(e,t,n)=>2*t>n&&Math.abs(e-n/2)<=ze;function zt(e,t={},{wallIds:n=null}={}){let r=n?new Set(n):null,i=[],a=new Map;for(let t of Array.isArray(e)?e:[]){if(!W(t)||r&&!r.has(t.id))continue;let e=B(t);if(!(e<k)){a.set(t.id,e);for(let n of t.openings??[]){let r=Number(n?.width)||0;if(!Number.isFinite(n?.offsetAlong)||r>e)continue;let a=Lt(n.offsetAlong,n.offsetAlong+r,e);a&&i.push({wallId:t.id,itemId:n.id,itemKind:`opening`,...a})}for(let n of t.fixtures??[]){if(!Number.isFinite(n?.offsetAlong))continue;let r=Lt(n.offsetAlong,n.offsetAlong,e);r&&i.push({wallId:t.id,itemId:n.id,itemKind:`fixture`,...r})}}}for(let[e,n]of It)for(let r of Array.isArray(t?.[e])?t[e]:[]){let e=Et(r),t=e?a.get(e.wallId):void 0;if(t==null)continue;let o=(Number(r.dimensions?.width)||0)/2,s=Rt(e.offsetAlong,o,t)?null:Lt(e.offsetAlong-o,e.offsetAlong+o,t);s&&i.push({wallId:e.wallId,itemId:r.id,itemKind:n,...s})}return i}function Bt(e){let t=Array.isArray(e)?e:[];if(!t.length)return[];let n=[];for(let e of t)n.includes(e.wallId)||n.push(e.wallId);return[{kind:`item_past_wall_end`,count:t.length,wallIds:n}]}var Vt=(e,t,n)=>Math.max(t,Math.min(n,e));function Ht(e){let t=Array.isArray(e?.walls)?e.walls:[],n=zt(t,e);if(!n.length)return e;let r=new Set(n.map(e=>`${e.itemKind}:${e.wallId}:${e.itemId}`)),i=new Map(t.filter(W).map(e=>[e.id,B(e)])),a=(e,t,n)=>n>=2*t?Vt(e,t,n-t):n/2,o={walls:t.map(e=>{if(!W(e))return e;let t=i.get(e.id),n=!1,a=(e.openings??[]).map(t=>r.has(`opening:${e.id}:${t.id}`)?(n=!0,{...t,offsetAlong:ne(e,t).along}):t),o=(e.fixtures??[]).map(i=>r.has(`fixture:${e.id}:${i.id}`)?(n=!0,{...i,offsetAlong:Vt(i.offsetAlong,0,t)}):i);return n?{...e,openings:a,fixtures:o}:e})};for(let[t,n]of It){if(!Array.isArray(e?.[t]))continue;let s=!1,c=e[t].map(e=>{let t=Et(e);if(!t||!r.has(`${n}:${t.wallId}:${e.id}`))return e;s=!0;let o=(Number(e.dimensions?.width)||0)/2;return{...e,anchor:{...t,offsetAlong:a(t.offsetAlong,o,i.get(t.wallId))}}});s&&(o[t]=c)}return{...e,...o}}var X=Math.SQRT1_2,Ut=Object.freeze({right:{x:1,z:0},left:{x:-1,z:0},up:{x:0,z:-1},down:{x:0,z:1},E:{x:1,z:0},W:{x:-1,z:0},N:{x:0,z:-1},S:{x:0,z:1},NE:{x:X,z:-X},SE:{x:X,z:X},SW:{x:-X,z:X},NW:{x:-X,z:-X}}),Wt=Object.freeze({he:`חזית`,en:`Wall`}),Gt=/^חזית\s*(\d+)$/;function Kt(e,t=`he`){return`${Wt[t]??Wt.en} ${e}`}function qt(e){let t=String(e?.name??``).trim();if(Number.isFinite(e?.nameIndex))return{custom:t||null,index:e.nameIndex};let n=Gt.exec(t);return n?{custom:null,index:Number(n[1])}:{custom:t||null,index:null}}function Jt(e,t=`he`,n=null){let{custom:r,index:i}=qt(e);if(r)return r;let a=i??n;return a==null?``:Kt(a,t)}function Yt(e){let t=0;for(let n of Array.isArray(e)?e:[]){Number.isFinite(n?.nameIndex)&&n.nameIndex>t&&(t=n.nameIndex);let e=/(\d+)\s*$/.exec(String(n?.name??``));if(e){let n=Number(e[1]);n>t&&(t=n)}}return t+1}function Xt(e,t,n,r,i={}){let a=Ut[n];return!a||!Number.isFinite(r)||r<S.MIN_WALL_LENGTH?null:Qt(e,t,{x:t.x+a.x*r,z:t.z+a.z*r},i)}function Zt(e,t,n,r={}){if(!Array.isArray(e)||e.length===0||!t||!n)return null;let i=n.x-t.x,a=n.z-t.z,o=Math.hypot(i,a);if(!(o>1e-6))return null;let s=i/o,c=a/o,l=e[e.length-1];if(!l?.startPoint||!l?.endPoint||Number.isFinite(r.thickness)&&r.thickness!==l.thickness||Number.isFinite(r.height)&&r.height!==l.height||Math.hypot(t.x-l.endPoint.x,t.z-l.endPoint.z)>.5)return null;let u=l.endPoint.x-l.startPoint.x,d=l.endPoint.z-l.startPoint.z,f=Math.hypot(u,d);return f>1e-6&&Math.abs(u/f-s)<1e-6&&Math.abs(d/f-c)<1e-6?l:null}function Qt(e,t,n,r={}){let i=n.x-t.x,a=n.z-t.z,o=Math.hypot(i,a);if(!Number.isFinite(o)||o<S.MIN_WALL_LENGTH)return null;let s=Zt(e,t,n,r);if(s){let t={x:n.x,y:0,z:n.z},r=d({...s,endPoint:t});return{walls:[...e.slice(0,-1),r],pen:{x:t.x,z:t.z}}}let c=se({x:t.x,y:0,z:t.z},{x:n.x,y:0,z:n.z},{nameIndex:Yt(e),thickness:r.thickness,height:r.height});return{walls:[...e,c],pen:{x:n.x,z:n.z}}}function $t(e,t,n={}){if(!Number.isFinite(e)||e<S.MIN_WALL_LENGTH||!Number.isFinite(t)||t<S.MIN_WALL_LENGTH)return null;let r={walls:[],pen:{x:0,z:0}};for(let[i,a]of[[`right`,e],[`down`,t],[`left`,e],[`up`,t]])if(r=Xt(r.walls,r.pen,i,a,n),!r)return null;return r}function en(e){if(!Array.isArray(e)||e.length===0)return null;let t=e[e.length-1];return{walls:e.slice(0,-1),pen:{x:t.startPoint.x,z:t.startPoint.z}}}function tn(e){if(!Array.isArray(e)||e.length===0)return{x:0,z:0};let t=e[e.length-1];return{x:t.endPoint.x,z:t.endPoint.z}}function nn(e,t,n=[],r={}){let{angleStep:i=Math.PI/4,lengthRound:a=10,minLength:o=100,vertexPull:s=200,equalTol:c=250,parallelEps:l=.03}=r,u=Array.isArray(n)?n:[],d=[],f=(e,t)=>Math.hypot(e.x-t.x,e.z-t.z)<1e-6,p=null;for(let n of u)for(let r of[n.startPoint,n.endPoint]){if(f(r,e))continue;let n=Math.hypot(r.x-t.x,r.z-t.z);n<=s&&(!p||n<p.d)&&(p={v:r,d:n})}if(p){let t=p.v.x-e.x,n=p.v.z-e.z,r=Math.round(Math.hypot(t,n));if(r>=o)return d.push({kind:`vertex`,at:{x:p.v.x,z:p.v.z}}),{x:p.v.x,z:p.v.z,length:r,angleDeg:Math.round(Math.atan2(n,t)*180/Math.PI),guides:d}}let m=t.x-e.x,h=t.z-e.z,g=Math.hypot(m,h);if(!Number.isFinite(g)||g<o)return null;let _=Math.round(Math.atan2(h,m)/i)*i,v=Math.round(g/a)*a,y=Math.cos(_),b=Math.sin(_);for(let e of u){let t=e.endPoint.x-e.startPoint.x,n=e.endPoint.z-e.startPoint.z,r=Math.hypot(t,n);if(!(r<1e-6)&&!(Math.abs(n/r*y-t/r*b)>l)&&Math.abs(v-r)<=c){v=Math.round(r/a)*a,d.push({kind:`equalLength`,length:v,a:{x:e.startPoint.x,z:e.startPoint.z},b:{x:e.endPoint.x,z:e.endPoint.z}});break}}return{x:e.x+Math.cos(_)*v,z:e.z+Math.sin(_)*v,length:v,angleDeg:Math.round(_*180/Math.PI),guides:d}}function rn(e,t=[],n={}){let{vertexPull:r=200,wallPull:i=120}=n;
1if(!e||!Array.isArray(t)||t.length===0)return e;let a=null;for(let n of t)for(let t of[n.startPoint,n.endPoint]){let n=Math.hypot(t.x-e.x,t.z-e.z);n<=r&&(!a||n<a.d)&&(a={v:t,d:n})}if(a)return{x:a.v.x,z:a.v.z};let o=null;for(let n of t){let t=n.endPoint.x-n.startPoint.x,r=n.endPoint.z-n.startPoint.z,a=Math.hypot(t,r);if(a<1e-6)continue;let s=((e.x-n.startPoint.x)*t+(e.z-n.startPoint.z)*r)/a,c=Math.max(0,Math.min(a,s)),l=n.startPoint.x+t/a*c,u=n.startPoint.z+r/a*c,d=Math.hypot(e.x-l,e.z-u);d<=Math.max(i,h(n))&&(!o||d<o.d)&&(o={x:l,z:u,d})}return o?{x:o.x,z:o.z}:e}var an=.5,on=(e,t)=>Math.hypot(e.x-t.x,e.z-t.z)<=an;function sn(e,t,n){return K(e,t,n===`start`?`start`:`end`)}function cn(e,t,n,r,i,a){let o=a.x-i.x,s=a.z-i.z,c=new Map;for(let e of r)c.has(e.wallId)||c.set(e.wallId,new Set),c.get(e.wallId).add(e.which);let l=e=>({...e,x:e.x+o,z:e.z+s});return e.map(e=>{if(e.id===t)return d(n===`start`?{...e,startPoint:a}:{...e,endPoint:a});let r=c.get(e.id);return r?d({...e,...r.has(`start`)?{startPoint:l(e.startPoint)}:{},...r.has(`end`)?{endPoint:l(e.endPoint)}:{}}):e})}function ln(e,t,n=`start`){let r=Array.isArray(e)?e:[],i=r.find(e=>e.id===t),a=n===`end`?i?.endPoint:i?.startPoint;return!a||!Number.isFinite(a.x)||!Number.isFinite(a.z)?null:r.find(e=>e.id!==t&&(e?.startPoint&&Number.isFinite(e.startPoint.x)&&on(e.startPoint,a)||e?.endPoint&&Number.isFinite(e.endPoint.x)&&on(e.endPoint,a)))??null}function un(t,n,r={}){let i=Array.isArray(t)?t.find(e=>e.id===n):null;if(!i)return null;let a={...i};return i.locked&&r.locked!==!1||(r.thickness!=null&&Number.isFinite(r.thickness)&&r.thickness>0&&(a.thickness=r.thickness),r.heightStart===null||r.heightEnd===null?a=e(a):r.heightStart!==void 0||r.heightEnd!==void 0?a=ee(a,{start:r.heightStart,end:r.heightEnd}):r.height!=null&&Number.isFinite(r.height)&&r.height>0&&(a=x(a,r.height)),s(r.thicknessSide)&&(a.thicknessSide=r.thicknessSide)),r.name!=null&&(a.name=String(r.name)),r.locked!=null&&(a.locked=!!r.locked),a.thickness!==i.thickness&&Array.isArray(a.openings)&&(a.openings=a.openings.map(e=>re(e)?{...e,depth:b(e.depth,a)}:e)),t.map(e=>e.id===n?a:e)}function dn(e,t,n,i={}){let a=Array.isArray(e)?e.find(e=>e.id===t):null;if(!a||a.locked||!Number.isFinite(n))return null;let o=i.anchor===`end`?`end`:`start`,s=Z(a);if(s<S.MIN_WALL_LENGTH)return null;let c=n*Math.PI/180,l={x:Math.cos(c),z:Math.sin(c)},u=o===`end`?a.endPoint:a.startPoint,d=o===`end`?a.startPoint:a.endPoint,f=o===`end`?{x:u.x-l.x*s,y:d.y??0,z:u.z-l.z*s}:{x:u.x+l.x*s,y:d.y??0,z:u.z+l.z*s},p=o===`end`?`start`:`end`,m=sn(e,t,p);if(gn(e,m)||hn(e,m,d,f))return null;let h=cn(e,t,p,m,d,f);return r(e,h)}function fn(e,t,n,i,a={}){let o=Array.isArray(e)?e.find(e=>e.id===t):null;if(!o||o.locked||!i)return null;let s=n===`start`?`start`:`end`,c=s===`start`?o.startPoint:o.endPoint,l=s===`start`?o.endPoint:o.startPoint,u={x:i.x,y:c.y??0,z:i.z};if(Math.hypot(u.x-l.x,u.z-l.z)<S.MIN_WALL_LENGTH)return null;let d=sn(e,t,s);if(gn(e,d)||hn(e,d,c,u))return null;let f=cn(e,t,s,d,c,u);return r(e,f)}function pn(e,t){let n=Array.isArray(e)?e.find(e=>e.id===t):null;return!n||n.locked?null:e.filter(e=>e.id!==t)}function mn(e,t,n,r){let i=Array.isArray(e)?e.find(e=>e.id===t):null;if(!i||i.locked||!Number.isFinite(r))return null;let a=n===`start`?`start`:`end`,o=a===`start`?i.startPoint:i.endPoint,s=a===`start`?i.endPoint:i.startPoint,c=sn(e,t,a)[0]||null,l=c?e.find(e=>e.id===c.wallId):null;if(!l||l.locked)return null;let u=c.which===`start`?l.endPoint:l.startPoint,d=s.x-o.x,f=s.z-o.z,p=u.x-o.x,m=u.z-o.z;if(Math.hypot(d,f)<1e-6||Math.hypot(p,m)<1e-6)return null;let h=p*f-m*d>=0?1:-1,g=Math.atan2(m,p)+r*Math.PI*h/180;return dn(e,t,(a===`start`?g:g+Math.PI)*180/Math.PI,{anchor:a})}function hn(e,t,n,r){let i=r.x-n.x,a=r.z-n.z;for(let n of t){if(t.some(e=>e.wallId===n.wallId&&e.which!==n.which))continue;let r=e.find(e=>e.id===n.wallId);if(!r)continue;let o=n.which===`start`?r.startPoint:r.endPoint,s=n.which===`start`?r.endPoint:r.startPoint;if(Math.hypot(o.x+i-s.x,o.z+a-s.z)<S.MIN_WALL_LENGTH)return!0}return!1}function gn(e,t){return t.some(t=>e.some(e=>e.id===t.wallId&&e.locked))}function _n(e,t,n,r,i={}){let a=i.pull??40,o=Array.isArray(e)?e.find(e=>e.id===t):null;if(!o||!r)return null;let s=n===`start`?o.endPoint:o.startPoint,c=[];for(let i of sn(e,t,n)){let t=e.find(e=>e.id===i.wallId),n=t?i.which===`start`?t.endPoint:t.startPoint:null;if(!n)continue;let o=(s.x+n.x)/2,l=(s.z+n.z)/2,u=Math.hypot(s.x-n.x,s.z-n.z)/2;if(u<1e-6)continue;let d=r.x-o,f=r.z-l,p=Math.hypot(d,f);if(p<1e-6)continue;
1let m={x:o+d/p*u,z:l+f/p*u},h=Math.hypot(m.x-r.x,m.z-r.z);h<=a&&c.push({point:m,kind:`perp`,dist:h})}if(Math.abs(r.x-s.x)<=a&&c.push({point:{x:s.x,z:r.z},kind:`axis`,axis:`v`,dist:Math.abs(r.x-s.x)}),Math.abs(r.z-s.z)<=a&&c.push({point:{x:r.x,z:s.z},kind:`axis`,axis:`h`,dist:Math.abs(r.z-s.z)}),!c.length)return null;c.sort((e,t)=>(e.kind===`perp`?0:1)-(t.kind===`perp`?0:1)||e.dist-t.dist);let l=c[0];return{point:l.point,kind:l.kind,axis:l.axis??null}}function Z(e){return Number.isFinite(e?.length)?e.length:Math.hypot((e?.endPoint?.x??0)-(e?.startPoint?.x??0),(e?.endPoint?.z??0)-(e?.startPoint?.z??0))}function vn(e,t,n,r=null){return e.some(e=>e.id!==r&&t<e.offsetAlong+e.width-.5&&e.offsetAlong+.5<n)}function yn(e,t,n,r={}){let i=Array.isArray(e)?e.find(e=>e.id===t):null;if(!i||!n||!(n.width>0))return null;let a=Z(i);if(n.width>a)return null;let o=Number.isFinite(r.centerAlong)?r.centerAlong-n.width/2:n.offsetAlong??0,s=Math.max(0,Math.min(a-n.width,o)),c=i.openings??[];if(vn(c,s,s+n.width))return null;let l=xn({...n,offsetAlong:s},i);return e.map(e=>e.id===t?{...e,openings:[...c,l]}:e)}function bn(e,t,n,r={}){let i=Array.isArray(e)?e.find(e=>e.id===t):null,a=i?.openings??[],o=a.find(e=>e.id===n);if(!o)return null;let s=Z(i),c={...o,...r};if(!(c.width>0))return null;let l=c.width>s;if(l&&c.width>(o.width??0)||(c.offsetAlong=r.offsetAlong!==void 0||r.width!==void 0?l?0:Math.max(0,Math.min(s-c.width,c.offsetAlong??0)):o.offsetAlong??0,Number.isFinite(c.sill)&&(c.sill=Math.max(0,c.sill)),vn(a,c.offsetAlong,c.offsetAlong+c.width,n)))return null;let u=xn(c,i);return e.map(e=>e.id===t?{...e,openings:a.map(e=>e.id===n?u:e)}:e)}function xn(e,t){let n=te(e),r=re(e)?b(e.depth,t):null,i=Number.isFinite(e.sill)?m(e.sill,{...e,style:n}):e.sill;return n===e.style&&r===(e.depth??null)&&i===e.sill?e:{...e,style:n,depth:r,sill:i}}function Sn(e,t){let n=ne(e,t),r=Number.isFinite(t?.offsetAlong)?t.offsetAlong:0;return{start:n.along,end:Math.max(0,n.len-n.along-n.width),overhangs:!n.fits||Math.abs(r-n.along)>.5}}function Cn(e,t,n){let r=Number(n);return Number.isFinite(r)?Z(e)-(t?.width??0)-Math.max(0,r):t?.offsetAlong??0}function wn(e,t,n){let r=Array.isArray(e)?e.find(e=>e.id===t):null;if(!r)return null;let i=r.openings??[];return i.some(e=>e.id===n)?e.map(e=>e.id===t?{...e,openings:i.filter(e=>e.id!==n)}:e):null}function Tn(e,t,n,r={}){let i=Array.isArray(e)?e.find(e=>e.id===t):null;if(!i||!n)return null;let a=Z(i),o=Number.isFinite(r.centerAlong)?r.centerAlong:n.offsetAlong??a/2,s=Math.max(0,Math.min(a,o)),c={...n,offsetAlong:s},l=i.fixtures??[];return e.map(e=>e.id===t?{...e,fixtures:[...l,c]}:e)}function En(e,t,n,r={}){let i=Array.isArray(e)?e.find(e=>e.id===t):null,a=i?.fixtures??[],o=a.find(e=>e.id===n);if(!o)return null;let s=Z(i),c={...o,...r};return c.offsetAlong=Math.max(0,Math.min(s,c.offsetAlong??0)),Number.isFinite(c.height)&&(c.height=Math.max(0,c.height)),e.map(e=>e.id===t?{...e,fixtures:a.map(e=>e.id===n?c:e)}:e)}function Dn(e,t,n){let r=Array.isArray(e)?e.find(e=>e.id===t):null;if(!r)return null;let i=r.fixtures??[];return i.some(e=>e.id===n)?e.map(e=>e.id===t?{...e,fixtures:i.filter(e=>e.id!==n)}:e):null}function On(e){let t=Number.isFinite(e?.length)?e.length:Math.hypot((e?.endPoint?.x??0)-(e?.startPoint?.x??0),(e?.endPoint?.z??0)-(e?.startPoint?.z??0)),n={from:0,to:t,length:t},r=(Array.isArray(e?.openings)?e.openings:[]).filter(e=>Number.isFinite(e?.offsetAlong)&&Number.isFinite(e?.width)&&e.width>0).map(e=>({kind:e.kind??`opening`,a:Math.max(0,Math.min(t,e.offsetAlong)),b:Math.max(0,Math.min(t,e.offsetAlong+e.width))})).filter(e=>e.b-e.a>.5).sort((e,t)=>e.a-t.a);if(r.length===0)return{overall:n,segments:null};let i=[],a=0;for(let e of r)e.a-a>.5&&i.push({from:a,to:e.a,length:e.a-a,kind:`solid`}),i.push({from:e.a,to:e.b,length:e.b-e.a,kind:e.kind}),a=Math.max(a,e.b);return t-a>.5&&i.push({from:a,to:t,length:t-a,kind:`solid`}),{overall:n,segments:i}}function kn(e,t=null){let n=e.endPoint.x-e.startPoint.x,r=e.endPoint.z-e.startPoint.z,i=Math.hypot(n,r)||1,a=c(e,t);return{ux:n/i,uz:r/i,nx:a.x,nz:a.z,len:i,thickness:h(e)}}function An(e,t={}){let n=Array.isArray(e)?e:[],r=t.interiors??y(n),i=t.neighbors??p(n);return n.map((e,t)=>{let n=i.get(e.id)??{prev:null,next:null};return{w:e,i:t,...kn(e,r),footprint:ce(e,n.prev,n.next,r)}})}var jn=`__draft-wall__`;function Mn(e,t,n,r,i={}){if(!t||!n||![t.x,t.z,n.x,n.z].every(Number.isFinite)||Math.hypot(n.x-t.x,n.z-t.z)<1)return null;let a=h({thickness:r}),o=(Array.isArray(e)?e:[]).filter(e=>e&&e.id!==`__draft-wall__`),s=Zt(o,t,n,{thickness:r,height:i.height});if(s){let e={...s,endPoint:{...s.endPoint,x:n.x,z:n.z}},r=c(e,y([...o.slice(0,-1),e])),i=h(s);return{polygon:[{x:t.x,z:t.z},{x:n.x,z:n.z},{x:n.x+r.x*i,z:n.z+r.z*i},{x:t.x+r.x*i,z:t.z+r.z*i}],normal:{x:r.x,z:r.z},thickness:i}}let l={id:jn,startPoint:{x:t.x,z:t.z},endPoint:{x:n.x,z:n.z},thickness:a,thicknessSide:`left`},u=c(l,y([...o,l]));return{polygon:[{x:t.x,z:t.z},{x:n.x,z:n.z},{x:n.x+u.x*a,z:n.z+u.z*a},{x:t.x+u.x*a,z:t.z+u.z*a}],normal:{x:u.x,z:u.z},thickness:a}}function Nn(e,t,n){let r=e?.startPoint,i=e?.endPoint;if(!r||!i)return null;let a=Math.hypot(i.x-r.x,i.z-r.z);if(a<1)return null;let o=kn(e,t),s=o.thickness+(Number.isFinite(n)?n:0);return{a:{x:r.x+o.nx*s,z:r.z+o.nz*s},b:{x:i.x+o.nx*s,z:i.z+o.nz*s},normal:{x:o.nx,z:o.nz},length:a}}var Q=.5,Pn=e=>!!(e&&e.startPoint&&e.endPoint&&Math.hypot((e.endPoint.x??0)-(e.startPoint.x??0),(e.endPoint.z??0)-(e.startPoint.z??0))>.5);function Fn(e,t){let n=Array.isArray(e)?e.filter(Pn):[];if(n.length<2)return[];let r=t===void 0?y(n):t,i=p(n),a=new Set,o=[];for(let e of n){let t=i.get(e.id);for(let[n,i]of[[t?.prev,e.startPoint],[t?.next,e.endPoint]]){if(!n)continue;let t=f(e,n,i,r);if(!t.bevel)continue;let s=`${t.wallIds[0]}|${t.wallIds[1]}|${t.vertex.x}|${t.vertex.z}`;a.has(s)||(a.add(s),o.push({wallIds:t.wallIds,vertex:{x:t.vertex.x,z:t.vertex.z},polygon:t.bevel.map(e=>({x:e.x,z:e.z}))}))}}return o}var $=(e,t,n,r)=>e*r-t*n;function In(e){if(!Array.isArray(e))return null;let t=[];for(let n of e){if(!n||!Number.isFinite(n.x)||!Number.isFinite(n.z))return null;let e=t[t.length-1];e&&Math.hypot(n.x-e.x,n.z-e.z)<1e-9||t.push({x:n.x,z:n.z})}for(;t.length>1&&Math.hypot(t[0].x-t[t.length-1].x,t[0].z-t[t.length-1].z)<1e-9;)t.pop();if(t.length<3)return null;let n=0;for(let e=0;e<t.length;e++){let r=t[e],i=t[(e+1)%t.length];n+=r.x*i.z-i.x*r.z}if(!(Math.abs(n)/2>1e-6))return null;let r=1/0,i=-1/0,a=1/0,o=-1/0;for(let e of t)e.x<r&&(r=e.x),e.x>i&&(i=e.x),e.z<a&&(a=e.z),e.z>o&&(o=e.z);return{pts:t,minX:r,maxX:i,minZ:a,maxZ:o}}function Ln(e,t,n){if(t<e.minX||t>e.maxX||n<e.minZ||n>e.maxZ)return!1;let r=e.pts,i=!1;for(let e=0,a=r.length-1;e<r.length;a=e++){let o=r[e],s=r[a];o.z>n!=s.z>n&&t<o.x+(n-o.z)*(s.x-o.x)/(s.z-o.z)&&(i=!i)}return i}function Rn(e,t=Q){let n=(Array.isArray(e)?e:[]).map(In).filter(
1Boolean);if(n.length===0)return[];let r=Number.isFinite(t)&&t>0?t:Q,i=(e,t)=>n.some(n=>Ln(n,e,t)),a=[];n.forEach((e,t)=>{let o=e.pts;for(let e=0;e<o.length;e++){let s=o[e],c=o[(e+1)%o.length],l=c.x-s.x,u=c.z-s.z,d=l*l+u*u,f=Math.sqrt(d);if(!(f>1e-9))continue;let p=[];n.forEach((e,n)=>{if(n===t||Math.max(s.x,c.x)+r<e.minX||Math.min(s.x,c.x)-r>e.maxX||Math.max(s.z,c.z)+r<e.minZ||Math.min(s.z,c.z)-r>e.maxZ)return;let i=e.pts;for(let e=0;e<i.length;e++){let t=i[e],n=i[(e+1)%i.length],a=n.x-t.x,o=n.z-t.z,c=$(l,u,a,o),m=Math.hypot(a,o);if(m>1e-9&&Math.abs(c)>1e-12*f*m){let e=$(t.x-s.x,t.z-s.z,a,o)/c,n=$(t.x-s.x,t.z-s.z,l,u)/c;e>0&&e<1&&n>=0&&n<=1&&p.push(e)}let h=((t.x-s.x)*l+(t.z-s.z)*u)/d;h>0&&h<1&&Math.abs($(t.x-s.x,t.z-s.z,l,u))/f<=r&&p.push(h)}}),p.sort((e,t)=>e-t);let m=[0],h=r/f;for(let e of p)e-m[m.length-1]<h||1-e<h||m.push(e);m.push(1);let g=-u/f,_=l/f,v=`${t}:${e}`;for(let e=0;e+1<m.length;e++){let t=m[e],n=m[e+1],o=(n-t)*f,c=s.x+l*((t+n)/2),d=s.z+u*((t+n)/2),p=Math.max(1e-6,Math.min(r,o/4));i(c+g*p,d+_*p)!==i(c-g*p,d-_*p)&&a.push({edge:v,seq:e,a:{x:s.x+l*t,z:s.z+u*t},b:{x:s.x+l*n,z:s.z+u*n}})}}});let o=(e,t)=>Math.hypot(e.x-t.x,e.z-t.z)<=r,s=[];for(let e of a)s.some(t=>o(t.a,e.a)&&o(t.b,e.b)||o(t.a,e.b)&&o(t.b,e.a))||s.push(e);let c=[],l=null;for(let e of s){if(l&&l.edge===e.edge&&l.seq+1===e.seq){l.seg.b=e.b,l.seq=e.seq;continue}let t={a:e.a,b:e.b};c.push(t),l={edge:e.edge,seq:e.seq,seg:t}}return c}function zn(e,t,n,r){let i=r.x-n.x,a=r.z-n.z,o=i*i+a*a,s=o>0?((e-n.x)*i+(t-n.z)*a)/o:0;return s=Math.max(0,Math.min(1,s)),Math.hypot(e-(n.x+i*s),t-(n.z+a*s))}function Bn(e,t,n,r){if(t<e.minX-r||t>e.maxX+r||n<e.minZ-r||n>e.maxZ+r)return!1;if(Ln(e,t,n))return!0;let i=e.pts;for(let e=0;e<i.length;e++)if(zn(t,n,i[e],i[(e+1)%i.length])<=r)return!0;return!1}function Vn(e,n){let r=Array.isArray(e)?e.filter(Pn):[],i=n===void 0?y(r):n,a=[];for(let e of r){let n=Array.isArray(e.openings)?e.openings:[];if(n.length===0||!(Math.hypot(e.endPoint.x-e.startPoint.x,e.endPoint.z-e.startPoint.z)>=1))continue;let r=kn(e,i),o=r.thickness,s=e.startPoint;for(let i of n){let n=Number(i?.width);if(!(n>0))continue;let c=ne(e,i).along,l=re(i)?Math.min(o,t(i,e)):o,u=(e,t)=>({x:s.x+r.ux*e+r.nx*t,z:s.z+r.uz*e+r.nz*t});a.push({wallId:e.id,openingId:i.id,through:l>=o-Q,depth:l,polygon:[u(c,0),u(c+n,0),u(c+n,l),u(c,l)]})}}return a}function Hn(e,t,n){let r=Array.isArray(t)?t:[];if(r.length<3||!Pn(e))return r.length>=3?[r]:[];let i=e.startPoint,a=e.endPoint,o=Math.hypot(a.x-i.x,a.z-i.z);if(!(o>0))return[r];let s=(a.x-i.x)/o,c=(a.z-i.z)/o,l=e=>(e.x-i.x)*s+(e.z-i.z)*c,u=(Array.isArray(n)?n:[]).filter(t=>t&&t.through&&t.wallId===e.id&&Array.isArray(t.polygon)&&t.polygon.length>=3).map(e=>{let t=e.polygon.map(l);return{a:Math.min(...t),b:Math.max(...t)}}).filter(e=>e.b-e.a>Q).sort((e,t)=>e.a-t.a);if(u.length===0)return[r];let d=r.map(l),f=Math.min(...d),p=Math.max(...d),m=[],h=f;for(let e of u)e.a>h&&m.push({a:h,b:Math.min(e.a,p)}),h=Math.max(h,e.b);h<p&&m.push({a:h,b:p});let g=[];for(let e of m){if(e.b-e.a<=.5)continue;let t=Un(r,t=>l(t)-e.a);t=Un(t,t=>e.b-l(t)),t.length>=3&&g.push(t)}return g.length?g:[]}function Un(e,t){let n=[];for(let r=0;r<e.length;r++){let i=e[r],a=e[(r+1)%e.length],o=t(i),s=t(a);if(o>=0&&n.push(i),o>=0!=s>=0){let e=o/(o-s);n.push({x:i.x+(a.x-i.x)*e,z:i.z+(a.z-i.z)*e})}}return n}function Wn(e,t,n=Q){let r=Array.isArray(e)?e:[],i=(Array.isArray(t)?t:[]).map(In).filter(Boolean),a=Number.isFinite(n)&&n>0?n:Q,o=[];for(let e of r){let t=e?.a,n=e?.b;if(!t||!n||![t.x,t.z,n.x,n.z].every(Number.isFinite))continue;let r=n.x-t.x,s=n.z-t.z,c=r*r+s*s,l=Math.sqrt(c);if(!(l>1e-9))continue;let u=i.filter(e=>!(Math.max(t.x,n.x)+a<e.minX||Math.min(t.x,n.x)-a>e.maxX||Math.max(t.z,n.z)+a<e.minZ||Math.min(t.z,n.z)-a>e.maxZ));if(u.length===0){o.push({a:{x:t.x,z:t.z},b:{x:n.x,z:n.z}});continue}let d=[];for(let e of u){let n=e.pts;for(let e=0;e<n.length;e++){let i=n[e],o=n[(e+1)%n.length],u=o.x-i.x,f=o.z-i.z,p=$(r,s,u,f),m=Math.hypot(u,f);if(m>1e-9&&Math.abs(p)>1e-12*l*m){let e=$(i.x-t.x,i.z-t.z,u,f)/p,n=$(i.x-t.x,i.z-t.z,r,s)/p;e>0&&e<1&&n>=0&&n<=1&&d.push(e)}let h=((i.x-t.x)*r+(i.z-t.z)*s)/c;h>0&&h<1&&Math.abs($(i.x-t.x,i.z-t.z,r,s))/l<=a&&d.push(h)}}d.sort((e,t)=>
1e-t);let f=[0],p=a/l;for(let e of d)e-f[f.length-1]<p||1-e<p||f.push(e);f.push(1);let m=null;for(let e=0;e+1<f.length;e++){let n=f[e],i=f[e+1],c=(n+i)/2,l=t.x+r*c,d=t.z+s*c;if(u.some(e=>Bn(e,l,d,a))){m=null;continue}let p={x:t.x+r*n,z:t.z+s*n},h={x:t.x+r*i,z:t.z+s*i};if(m){m.b=h;continue}m={a:p,b:h},o.push(m)}}return o}function Gn(e,t=Q){let n=Number.isFinite(t)&&t>0?t:Q,r=(Array.isArray(e)?e:[]).filter(e=>e?.a&&e?.b&&[e.a.x,e.a.z,e.b.x,e.b.z].every(Number.isFinite)&&Math.hypot(e.b.x-e.a.x,e.b.z-e.a.z)>1e-9),i=Array(r.length).fill(!1),a=(e,t)=>Math.hypot(e.x-t.x,e.z-t.z)<=n,o=e=>{for(let t=0;t<r.length;t++)if(!i[t]){if(a(r[t].a,e))return i[t]=!0,{x:r[t].b.x,z:r[t].b.z};if(a(r[t].b,e))return i[t]=!0,{x:r[t].a.x,z:r[t].a.z}}return null},s=[];for(let e=0;e<r.length;e++){if(i[e])continue;i[e]=!0;let t=[{x:r[e].a.x,z:r[e].a.z},{x:r[e].b.x,z:r[e].b.z}],n=!1;for(;;){if(t.length>2&&a(t[t.length-1],t[0])){n=!0,t.pop();break}let e=o(t[t.length-1]);if(!e)break;t.push(e)}if(!n)for(;;){let e=o(t[0]);if(!e)break;if(t.unshift(e),a(t[0],t[t.length-1])){n=!0,t.shift();break}}s.push({points:Kn(t,n),closed:n})}return s}function Kn(e,t){if(e.length<3)return e;let n=[],r=e.length;for(let i=0;i<r;i++){if(!t&&(i===0||i===r-1)){n.push(e[i]);continue}let a=e[(i-1+r)%r],o=e[i],s=e[(i+1)%r],c=s.x-a.x,l=s.z-a.z,u=Math.hypot(c,l),d=u>1e-9?Math.abs($(o.x-a.x,o.z-a.z,c,l))/u:1/0,f=(o.x-a.x)*c+(o.z-a.z)*l>0&&(s.x-o.x)*c+(s.z-o.z)*l>0;d<=1e-6&&f||n.push(o)}return n.length>=(t?3:2)?n:e}function qn(e,t={}){let n=Array.isArray(e)?e:[],r=n.map(Pn),i=n.filter((e,t)=>r[t]),a=Number.isFinite(t.eps)&&t.eps>0?t.eps:Q,o=t.interiors===void 0?y(i):t.interiors,s=t.footprints;if(Array.isArray(s)&&s.length===n.length&&(s=s.filter((e,t)=>r[t])),!Array.isArray(s)){let e=t.neighbors??p(i);s=i.map(t=>{let n=e.get(t.id)??{prev:null,next:null};return ce(t,n.prev,n.next,o)})}let c=Fn(i,o),l=Rn([...s,...c.map(e=>e.polygon)],a),u=(t.cuts===void 0?Vn(i,o):t.cuts??[]).map(e=>Array.isArray(e)?e:e?.polygon).filter(Array.isArray),d=u.length?Wn(l,u,a):l;return{fillers:c,segments:d,paths:Gn(d,a)}}export{Pt as $,On as A,Y as B,dn as C,En as D,en as E,O as F,tt as G,Ft as H,Dt as I,Mt as J,nt as K,Tt as L,qt as M,Z as N,bn as O,ln as P,ot as Q,Ht as R,mn as S,nn as T,St as U,Bt as V,Ot as W,st as X,zt as Y,ct as Z,vn as _,Nn as a,Oe as at,wn as b,Tn as c,T as ct,Qt as d,Me as et,$t as f,Cn as g,Sn as h,qn as i,De as it,Jt as j,_n as k,yn as l,de as lt,fn as m,Fn as n,Ee as nt,Mn as o,ke as ot,tn as p,Nt as q,Vn as r,D as rt,An as s,E as st,Hn as t,Ae as tt,Xt as u,pe as ut,un as v,rn as w,pn as x,Dn as y,Ct as z};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.