@hatiolab/things-scene 10.1.70 → 10.1.71

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/things-scene.mjs CHANGED
@@ -47,5 +47,5 @@ import*as t from"three";import{Color as e,LinearSRGBColorSpace as n,SRGBColorSpa
47
47
  </button>`:I}
48
48
  ${n?z`<button class="closable" @click=${this.closeContainer}>close</button>`:I}
49
49
  </div>
50
- `,this.element)}catch(t){}}onchangeMinimized(){const{minimized:t}=this.state;t?this.setState("height",24):this.setState("height",this.get("height"))}}Zm=new WeakMap,Cc.memoize(ng.prototype,"bounds",!0),Cc.register("container",ng);const ig=Math.sqrt(3),sg=2;function rg(t,e,n,i,s){const r=5+s,o=n.x,a=n.y,c=i.x,l=i.y;if(Math.abs(o-c)>r&&Math.abs(a-l)>r){const n=(l-a)/(c-o),i=a-n*o;if(Math.abs(e-(n*t+i))>r)return!1}let h,d,u,p;return o>c?(d=o,h=c):(d=c,h=o),a>l?(p=a,u=l):(p=l,u=a),!(d+5<t)&&(!(h-5>t)&&(!(p+5<e)&&!(u-5>e)))}function og(t,e,n,i=2){for(let s=0;s<n.length-1;s++)if(rg(t,e,n[s],n[s+1],i))return!0;return!1}function ag(t,e,n,i){if("arrow"!=t.slice(-5))return n;const s=Math.atan2(i.y-n.y,i.x-n.x),r=1.5*e;return{x:n.x+Math.cos(s)*r,y:n.y+Math.sin(s)*r}}function cg(t,e,n){let{lineWidth:i=sg,strokeStyle:s="#000000",lineCap:r=!1,alpha:o=1,begin:a="none",end:c="none",beginSize:l="size5",endSize:h="size5"}=n;if(("none"!=a||"none"!=c)&&(i=Number(i)||sg,t.lineCap=r,t.lineWidth=i,t.strokeStyle=s,t.fillStyle=s,t.globalAlpha*=o,"none"!=a&&lg(t,e[0],e[1],i,a,hg(l,i)),"none"!=c)){const n=e.length;lg(t,e[n-1],e[n-2],i,c,hg(h,i))}}function lg(t,e,n,i,s,r){const{x:o,y:a}=e,c=Math.atan2(n.y-a,n.x-o);switch(t.beginPath(),t.translate(o,a),t.rotate(c),s){case"oval":t.ellipse(0,0,r.X,r.Y,0,0,2*Math.PI),t.fill();break;case"diamond":t.moveTo(-r.X,0),t.lineTo(0,-r.Y),t.lineTo(r.X,0),t.lineTo(0,r.Y),t.fill();break;case"arrow":t.moveTo(0,0),t.lineTo(ig*r.X,-r.Y),t.lineTo(ig*r.X,r.Y),t.fill();break;case"sharp-arrow":t.moveTo(0,0),t.lineTo(ig*r.X,-r.Y),t.lineTo(-r.X/1.5+ig*r.X,0),t.lineTo(ig*r.X,r.Y),t.fill();break;case"open-arrow":t.moveTo(ig*r.X+i,-r.Y),t.lineTo(i,0),t.lineTo(ig*r.X+i,r.Y),t.stroke();break;case"cross":t.moveTo(-r.X,-r.Y),t.lineTo(r.X,r.Y),t.moveTo(r.X,-r.Y),t.lineTo(-r.X,r.Y),t.stroke()}t.rotate(-c),t.translate(-o,-a),t.closePath()}function hg(t,e){const n={X:0,Y:0};switch(e*=1.2,t){case"size1":n.X=e,n.Y=e;break;case"size2":n.X=1.5*e,n.Y=e;break;case"size3":n.X=2*e,n.Y=e;break;case"size4":n.X=e,n.Y=1.5*e;break;case"size5":default:n.X=1.5*e,n.Y=1.5*e;break;case"size6":n.X=2*e,n.Y=1.5*e;break;case"size7":n.X=e,n.Y=2*e;break;case"size8":n.X=1.5*e,n.Y=2*e;break;case"size9":n.X=2*e,n.Y=2*e}return n}const dg="N",ug="S",pg="E",fg="W";class mg{constructor({component:t,anchor:e,position:n,self:i}){this.component=t,this._anchorName=e,this._position=n,this.self=i}get position(){const t=this.anchor;if(t){const{position:e}=t,n=this.component.toScene(e.x,e.y);return this.self.transcoordT2P(n.x,n.y)}return this._position}set position({x:t,y:e}){this._position={x:t,y:e}}get anchor(){return this.component?.findAnchor(this._anchorName)}get direction(){const t=this.component.bounds,e=this.anchor;if(!e)return pg;const n=e.position;return n.y<=t.top?dg:n.y>=t.top+t.height?ug:n.x<=t.left?fg:pg}get boundaryPosition(){const t=this.anchor;if(t){let{position:e}=t,n=0,i=0;switch(this.direction){case ug:i=20;break;case dg:i=-20;break;case fg:n=-20;break;default:n=20}e={x:e.x+n,y:e.y+i};const s=this.component.toScene(e.x,e.y);return this.self.transcoordT2P(s.x,s.y)}}}class gg extends Cc{isLine(){return!0}is3dish(){return!0}replaceRefids(t){["from","to"].forEach(e=>{const n=this.get(e);if(n?.component){const i=t.get(n.component)||n.component;this.set(e,{...n,component:i})}})}get fromEnd(){if(this.parent&&!this._fromEnd){const{component:t,anchor:e,position:n}=this.getState("from")||{};if(!t)return;const i=this.root?.findByRefid?.(t);if(!i)return;this._fromEnd=new mg({component:i,fromto:"from",anchor:e,position:n,self:this})}return this._fromEnd}get from(){return this.getState("from")}set from(t){delete this._fromEnd,this.set("from",t)}get toEnd(){if(this.parent&&!this._toEnd){const{component:t,anchor:e,position:n}=this.getState("to")||{};if(!t)return;const i=this.root?.findByRefid?.(t);if(!i)return;this._toEnd=new mg({component:i,fromto:"to",anchor:e,position:n,self:this})}return this._toEnd}get to(){return this.getState("to")}set to(t){delete this._toEnd,this.set("to",t)}move({x:t,y:e},n){n&&(this.from={position:this._fromEnd?.position||this.getState("from")?.position||{x:0,y:0}},this.to={position:this._toEnd?.position||this.getState("to")?.position||{x:0,y:0}}),super.move({x:t,y:e})}render(t){const{begin:e="none",end:n="none",lineWidth:i,round:s=0}=this.state;let r=this.drawPath;cg(t,r,this.state),t.beginPath();const o=ag(e,i,r[0],r[1]),a=ag(n,i,r[r.length-1],r[r.length-2]),c=r[0];r=[o,...r.slice(1,-1),a];let l={x:o.x,y:o.y};if(t.moveTo(o.x,o.y),r.length>=2&&Xr(c)){const e=r[1],n=Jr(e,s),i=Math.sqrt((o.x-e.x)**2+(o.y-e.y)**2),a=0!==i?Math.atan2(o.x-e.x,o.y-e.y):0,l=Math.sin(a)*Math.min(n,i/2)+e.x,h=Math.cos(a)*Math.min(n,i/2)+e.y,d=Kr({x:o.x,y:o.y},{x:l,y:h},c.bulge);d&&t.arc(d.cx,d.cy,d.radius,d.startAngle,d.endAngle,d.clockwise)}for(let e=1;e<r.length;e++){const n=l;l=r[e];const i=r[e+1];if(n.x===l.x&&n.y===l.y)continue;if(!i){t.lineTo(l.x,l.y);break}const o=Jr(l,s);let a=Math.sqrt((n.x-l.x)*(n.x-l.x)+(n.y-l.y)*(n.y-l.y)),c=0!==a?Math.atan2(n.x-l.x,n.y-l.y):0,h=Math.sin(c)*Math.min(o,a/2)+l.x,d=Math.cos(c)*Math.min(o,a/2)+l.y;const u=o>0||0!==a?{x:h,y:d}:l;a=Math.sqrt((i.x-l.x)*(i.x-l.x)+(i.y-l.y)*(i.y-l.y)),c=0!==a?Math.atan2(i.x-l.x,i.y-l.y):0,h=Math.sin(c)*Math.min(o,a/2)+l.x,d=Math.cos(c)*Math.min(o,a/2)+l.y;const p=o>0||0!==a?{x:h,y:d}:l;if(t.lineTo(u.x,u.y),o>0&&t.quadraticCurveTo(l.x,l.y,p.x,p.y),Xr(l)){const e=Jr(i,s),n=Math.sqrt((l.x-i.x)**2+(l.y-i.y)**2),r=0!==n?Math.atan2(l.x-i.x,l.y-i.y):0,o=Math.sin(r)*Math.min(e,n/2)+i.x,a=Math.cos(r)*Math.min(e,n/2)+i.y,c=Kr({x:p.x,y:p.y},{x:o,y:a},l.bulge);c&&t.arc(c.cx,c.cy,c.radius,c.startAngle,c.endAngle,c.clockwise)}}this.drawStroke(t,void 0)}contains(t,e){const{lineWidth:n}=this.state;return og(t,e,this.drawPath,n)}get resizable(){return!1}get mutable(){return!0}get rotatable(){return!1}get path(){const{from:t,to:e}=this.state,{x1:n,y1:i,x2:s,y2:r}=this.state;return[this.fromEnd?.position||t?.position||{x:n,y:i},this.toEnd?.position||e?.position||{x:s,y:r}]}set path(t){const[e,n]=t,{from:i,to:s}=this.state;delete this._fromEnd,delete this._toEnd,this.set({from:{...i,position:e},to:{...s,position:n}})}get textBounds(){const t=this.drawPath;let e,n,i=0;for(let s=1;s<t.length;s++){const r=t[s-1],o=t[s],a=(r.x-o.x)*(r.x-o.x)+(r.y-o.y)*(r.y-o.y);a>i&&(i=Math.ceil(a),e=r,n=o)}let{paddingTop:s,paddingLeft:r,paddingRight:o,paddingBottom:a}=this.state;return a||=0,s||=0,r||=0,o||=0,{left:Math.min(e.x,n.x)+r,top:Math.min(e.y,n.y)+s,width:Math.max(Math.abs(e.x-n.x)-r-o,0),height:Math.max(Math.abs(e.y-n.y)-s-a,0)}}get decorators(){return this.app.isEditMode?["decotag"]:[]}}gg.getTipNeckPos=ag,gg.containedInPath=og,gg.drawEndTips=cg,Cc.register("line",gg);const yg={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"angle",label:"start-angle",name:"startAngle",property:"startAngle"},{type:"angle",label:"end-angle",name:"endAngle",property:"endAngle"}],"value-property":"text"};class bg extends(nm(Tc)){is3dish(){return!0}render(t){const{cx:e,cy:n,rx:i,ry:s,startAngle:r,endAngle:o,anticlockwise:a}=this.state;t.beginPath(),t.ellipse(e,n,Math.abs(i),Math.abs(s),0,r||0,o||2*Math.PI,a),void 0!==r&&void 0!==o&&(t.lineTo(e,n),t.closePath())}get path(){const{cx:t,cy:e,rx:n,ry:i}=this.state;return[{x:t-n,y:e-i},{x:t+n,y:e-i},{x:t+n,y:e+i},{x:t-n,y:e+i}]}set path(t){const e=t[0],n=t[2];this.set({cx:e.x+(n.x-e.x)/2,cy:e.y+(n.y-e.y)/2,rx:(n.x-e.x)/2,ry:(n.y-e.y)/2})}contains(t,e){const{cx:n,cy:i,rx:s,ry:r}=this.state,o=(t-n)/(2*s-.5),a=(e-i)/(2*r-.5);return o*o+a*a<.25}outline(t){return function(t,e){const{cx:n,cy:i,rx:s,ry:r}=t.model,o=2*Math.PI*e,a=n+s*Math.cos(o),c=i+r*Math.sin(o);return t.toScene(a,c)}(this,t)}get anchors(){return function(t){const{left:e,top:n,width:i,height:s}=t.bounds,r=e+i/2,o=n+s/2;return[{name:"TOP",position:{x:r,y:n}},{name:"RIGHT",position:{x:e+i,y:o}},{name:"BOTTOM",position:{x:r,y:n+s}},{name:"LEFT",position:{x:e,y:o}}]}(this)}get nature(){return yg}}Cc.memoize(bg.prototype,"path",!1),Cc.register("ellipse",bg);const _g={object:{fill:"rgba(180,180,180,0.18)",stroke:"#888888",icon:"?",label:"object"},transport:{fill:"rgba(100,180,255,0.18)",stroke:"#3a78c8",icon:"⇄",label:"transport"},facility:{fill:"rgba(160,140,220,0.18)",stroke:"#6b4ec8",icon:"◫",label:"facility"},vehicle:{fill:"rgba(120,200,140,0.18)",stroke:"#3a8c5e",icon:"⊙",label:"vehicle"},region:{fill:"rgba(220,200,100,0.18)",stroke:"#a0892a",icon:"▢",label:"region"},path:{fill:"rgba(200,140,160,0.18)",stroke:"#a0506a",icon:"⌐",label:"path"},"3d-asset":{fill:"rgba(255,180,80,0.18)",stroke:"#c87a2a",icon:"◈",label:"3D asset"}},vg=[{type:"string",label:"placeholder-label",name:"placeholderLabel",description:'사용자에게 표시할 추가 라벨 (예: "Stocker A1")'},{type:"string",label:"hint",name:"placeholderHint",description:"구체화 시 참고 — 도면의 원본 식별자 / VLM 라벨 등"}];function xg(t,e,n,i,s){const{left:r,top:o,width:a,height:c}=e,l=Math.max(a,1),h=Math.max(c,1);t.save(),t.fillStyle=n.fill,t.fillRect(r,o,l,h),t.strokeStyle=n.stroke,t.lineWidth=1.5,t.setLineDash([4,3]),t.strokeRect(r,o,l,h),t.setLineDash([]),t.restore(),Math.min(l,h)>=24&&(t.save(),t.fillStyle=n.stroke,t.font=`bold ${Math.min(20,.4*Math.min(l,h))}px Arial`,t.textAlign="center",t.textBaseline="middle",t.fillText(n.icon,r+l/2,o+h/2),t.restore());const d=i?`${n.label}: ${i}`:n.label;h>=32&&(t.save(),t.fillStyle=n.stroke,t.font="10px Arial",t.textAlign="center",t.textBaseline="bottom",t.fillText(d,r+l/2,o+h-4),t.restore()),s&&h>=40&&(t.save(),t.fillStyle=n.stroke,t.font="9px Arial",t.textAlign="right",t.textBaseline="top",t.fillText(`hint: ${s}`,r+l-4,o+4),t.restore())}const wg={mutable:!1,resizable:!0,rotatable:!0,properties:[...vg,{type:"placeholder-convert",label:"",name:"_convert"}],help:"scene/component/placeholder"};class Mg extends(Oc(Tc)){get nature(){return wg}render(t){const{placeholderLabel:e,placeholderHint:n}=this.state;xg(t,this.bounds,_g.object,e,n)}}Cc.register("placeholder",Mg);const Sg=["placeholder"];function kg(t,e=[]){return!!t&&(!!Sg.includes(t)||e.includes(t))}const Ag={ondragstart:function(t,e,n){n.mutatePath(null,function(n){n.splice(e+1,0,t)})},ondragmove:function(t,e,n){n.mutatePath(null,function(n){const i=n[e+1];n[e+1]={...i||{},x:t.x,y:t.y}})},ondragend:function(t,e,n){}},Eg={mutable:!0,resizable:!1,rotatable:!0,properties:[{type:"number",label:"round",name:"round",property:{min:0,max:100,step:1}}],help:"scene/component/polygon"};class Cg extends Tc{is3dish(){return!0}get mutable(){return!0}get pathExtendable(){return!0}get cornerEditable(){return!0}get path(){return this.state.path??[]}set path(t){this.set("path",t)}contains(t,e){const n=this.path;let i=!1;return n.forEach((s,r)=>{const o=(r+n.length+1)%n.length,a=s.x,c=s.y,l=n[o].x,h=n[o].y;c>e!=h>e&&t<(l-a)*(e-c)/(h-c)+a&&(i=!i)}),i}get controls(){const t=this.path;return t.map((e,n)=>{const i=t[n+1>=t.length?0:n+1];return{x:(e.x+i.x)/2,y:(e.y+i.y)/2,handler:Ag}})}get nature(){return Eg}}Cc.memoize(Cg.prototype,"controls",!1),Cc.register("polygon",Cg);const Tg=[];class Pg extends(Ql(Cg)){constructor(t,e){super(t,e),this._components=[]}replaceRefids(t){this.components.forEach(e=>e.replaceRefids(t))}get showMoveHandle(){return!0}get showOverflow(){return!1}dispose(){this.components.slice().forEach(t=>t.dispose()),super.dispose()}isContainer(){return!0}containable(t){return t.isDescendible(this)}get hasTextProperty(){return!1}get components(){return this._components}get focusible(){return!0}get layout(){return Lc.get(this.get("layout"))||Nc}reflow(){this.layout.reflow(this),this.components&&this.components.forEach(t=>{t.isContainer()&&t.reflow()})}get hierarchy(){const t=super.hierarchy;return this.components?.length&&(t.components=this.components.map(t=>t.hierarchy)),t}reparent(t,e={}){t&&t.parent!==this&&this.addComponent(t,{silent:!0})}addComponent(t,e=!1){const{ghost:n=!1,silent:i=!1}="boolean"==typeof e?{ghost:e}:e,s=t.parent;if(s){if(this===s)return;s.removeComponent(t,n||i)}const r=this._components.push(t)-1;i&&(t._silentAdd=!0),t.parent=this,t.added(this),n||i||this.trigger("add",this,t,r),t.delegate_on(this),i?(s&&this.root?._removeTraverse?.(t),this.trigger("add",this,t,r),t.trigger("added",this,t,r),delete t._silentAdd):n||t.trigger("added",this,t,r),this.root&&this.root.isReady&&t.invokeReady()}removeComponent(t,e=!1){const n=this._components.indexOf(t);-1!=n&&(this._components.splice(n,1),t.parent=null,t.removed(this),e||(this.trigger("remove",this,t),t.trigger("removed",this,t)),t.delegate_off(this))}insertComponentAt(t,e,n=!1){const i=t.parent;i&&i.removeComponent(t,n);const s=this._components.splice(0,e);this._components=s.concat(t,this._components),e=this._components.indexOf(t),t.parent=this,t.added(this),n||this.trigger("add",this,t,e),t.delegate_on(this),n||t.trigger("added",this,t,e)}add(t,e=!1){return t instanceof Array?(t.forEach(t=>{-1==this._components.indexOf(t)&&this.addComponent(t,e)}),this):this.add.call(this,[t],e)}remove(t,e=!1){return t instanceof Array?this._components?(t.forEach(t=>this.removeComponent(t,e)),this):this:this.remove.call(this,[t],e)}getAt(t){if(this._components)return this._components[t]}forEach(t,e){this._components&&this._components.forEach(t,e)}traverse(t,e){t.call(e,this),this._components&&this._components.forEach(n=>{n.isContainer()?n.traverse(t,e):t.call(e,n)})}indexOf(t){return(this._components||Tg).indexOf(t)}size(){return(this._components||Tg).length}moveChildAt(t,e){const n=this.indexOf(e);if(-1==n)return;let i=this._components.splice(0,n);const s=this._components.splice(1);this._components=i.concat(s),t=Math.max(0,t),t=Math.min(t,this._components.length),i=this._components.splice(0,t),this._components=i.concat(e,this._components)}moveChildForward(t){const e=this.indexOf(t);-1!=e&&e!=this.size()-1&&(this._components[e]=this._components[e+1],this._components[e+1]=t)}moveChildBackward(t){const e=this.indexOf(t);-1!=e&&0!=e&&(this._components[e]=this._components[e-1],this._components[e-1]=t)}moveChildToFront(t){const e=this.indexOf(t);if(-1==e||e==this.size()-1)return;const n=this._components.splice(0,e),i=this._components.splice(1);this._components=n.concat(i,this._components)}moveChildToBack(t){const e=this.indexOf(t);if(-1==e||0==e)return;const n=this._components.splice(0,e),i=this._components.splice(1);this._components=this._components.concat(n,i)}symmetryX(t){super.symmetryX(t),this.components.map(t=>{t.symmetryX(0)})}findAll(t,...e){if("string"==typeof t)return ec(t,this,e[0]||this);if("function"!=typeof t)return[];let n=[];for(let i=this.components.length-1;i>=0;i--){const s=this.components[i].findAll(t,...e);s&&(n=n.concat(s))}return t(this,...e)&&n.push(this),n}findFirst(t,...e){if("string"==typeof t)return ec(t,this,e[0])[0];if("function"==typeof t){for(let n=this.components.length-1;n>=0;n--){const i=this.components[n].findFirst(t,...e);if(null!=i)return i}return t(this,...e)?this:void 0}}findById(t){return this.root.findAllById?.(t)?.[0]}findByRefid(t){return this.root.findByRefid?.(t)}capture(t,e,n){if(!this.app.isEditMode&&this.hidden)return!1;const i=this.fromParent(t,e);if(!this.contains(i.x,i.y))return!1;const s=this.bounds;i.x-=s.left,i.y-=s.top;const r=this.layout.capturables(this);for(let s=r.length-1;s>=0;s--){const o=r[s];let a;if(a="static"==o.position?o.capture(i.x,i.y,n):o.capture(t,e,n),a)return a}return this.capturable&&!n?.(this)&&this}capturePath(t,e){if(e){if(e.indexOf(this)>-1)return!1;for(let t=0;t<e.length;t++)if(!this.containable(e[t]))return!1}const n=[],{left:i,top:s,width:r,height:o}=this.bounds;for(let e=0;e<t.length;e++){const a=this.fromParent(t[e].x,t[e].y);if(a.x<i||a.x>i+r||a.y<s||a.y>s+o)return!1;a.x-=i,a.y-=s,n.push(a)}const a=this.layout.capturables(this);for(let t=a.length-1;t>=0;t--){const i=a[t];if(!i.isContainer())continue;const s=i.capturePath(n,e);if(s)return s}return this.focusible&&this}render(t){"popup"!==this.position&&super.render(t)}postrender(t){if("popup"===this.position)return void super.postrender(t);const e=this.layout.drawables(this);if(e.length>0){let{left:n=0,top:i=0,width:s,height:r}=this.bounds;t.save(),this.showOverflow||(t.beginPath(),t.rect(n,i,s,r),t.clip(),t.closePath()),t.translate(n,i),e.forEach(e=>{const n=this.root?.transitionEffect;n?.isReparenting(e)||e.draw(this.position&&"static"!==this.position?t:this.getContext(e))}),t.translate(-n,-i),t.restore()}super.postrender(t)}trim(){this.components.forEach(t=>{t.trim()}),super.trim()}}["layout"].forEach(t=>Cc.memoize(Pg.prototype,t,!1));const Og={ondragstart:function(t,e,n){n.mutatePath(null,function(n){n.splice(e,0,t)})},ondragmove:function(t,e,n){n.mutatePath(null,function(n){const i=n[e];n[e]={...i||{},x:t.x,y:t.y}})},ondragend:function(t,e,n){}},Dg={mutable:!1,resizable:!1,rotatable:!1,properties:[{type:"number",label:"round",name:"round",property:{min:0,max:100,step:1}}],help:"scene/component/polyline"};class Ig extends gg{get pathExtendable(){return!0}get cornerEditable(){return!0}get path(){const{from:t,to:e}=this.state,{path:n}=this.state;return[this.fromEnd?.position||t?.position||n[0],...n.slice(1,-1),this.toEnd?.position||e?.position||n[n.length-1]]}set path(t){const{from:e,to:n}=this.state;delete this._fromEnd,delete this._toEnd,this.set({from:{...e,position:t[0]},to:{...n,position:t[t.length-1]},path:t})}get controls(){const t=this.path,e=[];for(let n=0;n<t.length-1;n++){const i=t[n],s=t[n+1];0==n&&e.push({x:i.x,y:i.y,handler:Og}),e.push({x:(i.x+s.x)/2,y:(i.y+s.y)/2,handler:Og}),n==t.length-2&&e.push({x:s.x,y:s.y,handler:Og})}return e}get nature(){return Dg}}Cc.register("polyline",Ig);const zg={mutable:!1,resizable:!1,rotatable:!1,properties:[{type:"number",label:"round",name:"round",property:{min:0,max:100,step:1}}],help:"scene/component/ortholine"};class Rg extends gg{get pathExtendable(){return!1}get drawPath(){const t=this.path[0],e=this.path[1],{component:n,direction:i,boundaryPosition:s=t}=this.fromEnd||{},{component:r,direction:o,boundaryPosition:a=e}=this.toEnd||{},c=[s,a],l=[];s&&l.push(s);let h,d=n?.bounds;d&&(h=n.toScene(d.left,d.top),h=this.transcoordT2P(h.x,h.y),d={...d,left:h.x,top:h.y});const u=d?{left:d.left-20,top:d.top-20,width:d.width+40,height:d.height+40}:{left:s.x,top:s.y,width:0,height:0};d=d||u;let p=r?.bounds;p&&(h=r.toScene(p.left,p.top),h=this.transcoordT2P(h.x,h.y),p={...p,left:h.x,top:h.y});const f=p?{left:p.left-20,top:p.top-20,width:p.width+40,height:p.height+40}:{left:a.x,top:a.y,width:0,height:0};p=p||f;const m=[u,f],g=u.left>f.left?f.left:u.left,y=u.top>f.top?f.top:u.top,b={left:g,top:y,width:u.left+u.width>f.left+f.width?u.left+u.width-g:f.left+f.width-g,height:u.top+u.height>f.top+f.height?u.top+u.height-y:f.top+f.height-y};let _,v,x,w,M,S,k,A,E,C,T=0,P=0;d.left+d.width<p.left?(w=0,M=1,E=i,C=o,_=(d.left+d.width+p.left)/2,T=p.left-_):p.left+p.width<d.left&&(w=1,M=0,E=o,C=i,_=(d.left+p.width+p.left)/2,T=d.left-_),d.top+d.height<p.top?(x=0,S=1,k=i,A=o,v=(d.top+d.height+p.top)/2,P=p.top-v):p.top+p.height<d.top&&(x=1,S=0,k=o,A=i,v=(d.top+p.height+p.top)/2,P=d.top-v);const O=[];if(_&&T>P){let t,e,n;switch(C){case fg:switch(E){case pg:O.push({x:_,y:c[w].y}),O.push({x:_,y:c[M].y});break;case fg:t=m[w].top+m[w].height/2,e=t>c[M].y?Math.min(m[w].top,c[M].y):Math.max(m[w].top+m[w].height,c[M].y),O.push({x:c[w].x,y:e}),O.push({x:_,y:e}),O.push({x:_,y:c[M].y});break;case dg:case ug:e=E===ug?Math.max(c[w].y,c[M].y):Math.min(c[w].y,c[M].y),O.push({x:c[w].x,y:e}),O.push({x:_,y:e}),O.push({x:_,y:c[M].y});break;default:return this.path}break;case pg:switch(E){case pg:e=c[w].y<c[M].y?Math.min(m[M].top,c[w].y):Math.max(m[M].top+m[M].height,c[w].y),n=e;break;case fg:e=void 0!==v?v:c[w].y<c[M].y?b.top-.5*T:b.top+b.height+.5*T,n=e;break;case ug:e=void 0!==v?Math.max(v,c[w].y):b.top+b.height,n=e;break;case dg:e=v?Math.min(v,m[w].top):b.top,n=e;break;default:return this.path}O.push({x:c[w].x,y:e}),O.push({x:_,y:e}),O.push({x:_,y:n}),O.push({x:c[M].x,y:n});break;case ug:switch(E){case pg:e=c[w].y,n=c[w].y>c[M].y?c[w].y:m[M].top+m[M].height;break;case fg:e=v?Math.max(v,m[M].top+m[M].height):b.top+b.height,n=e;break;case ug:e=b.top+b.height,n=e;break;case dg:e=v?Math.min(v,m[w].top):m[w].top,n=v?Math.max(v,m[M].top+m[M].height):m[M].top+m[M].height;break;default:return this.path}O.push({x:c[w].x,y:e}),O.push({x:_,y:e}),O.push({x:_,y:n}),O.push({x:c[M].x,y:n});break;case dg:switch(E){case pg:e=c[w].y,n=c[w].y<c[M].y?c[w].y:m[M].top;break;case fg:e=v?Math.min(v,m[M].top):b.top,n=e;break;case ug:e=void 0!==v?Math.max(v,c[w].y):c[w].y,n=void 0!==v?Math.min(v,c[M].y):c[M].y;break;case dg:e=b.top,n=e;break;default:return this.path}O.push({x:c[w].x,y:e}),O.push({x:_,y:e}),O.push({x:_,y:n}),O.push({x:c[M].x,y:n});break;default:return this.path}l.push(...0===w?O:O.reverse())}else if(v){let t,e,n;switch(A){case dg:switch(k){case ug:O.push({x:c[x].x,y:v}),O.push({x:c[S].x,y:v});break;case dg:t=m[x].left+m[x].width/2,e=t>c[S].x?Math.min(m[x].left,c[S].x):Math.max(m[x].left+m[x].width,c[S].x),O.push({x:e,y:c[x].y}),O.push({x:e,y:v}),O.push({x:c[S].x,y:v});break;case fg:e=Math.min(c[x].x,c[S].x),O.push({x:e,y:c[x].y}),O.push({x:e,y:v}),O.push({x:c[S].x,y:v});break;case pg:e=Math.max(c[x].x,c[S].x),O.push({x:e,y:c[x].y}),O.push({x:e,y:v}),O.push({x:c[S].x,y:v});break;default:return this.path}break;case ug:switch(k){case fg:e=b.left,n=e;break;case pg:e=void 0!==_?Math.max(_,c[x].x):b.left+b.width,n=e;break;case dg:e=void 0!==_?_:c[x].x<c[S].x?b.left-.5*P:b.left+b.width+.5*P,n=e;break;case ug:e=c[x].x,n=c[x].x<c[S].x?Math.min(m[S].left,c[x].x):Math.max(m[S].left+m[S].width,c[x].x);break;default:return this.path}O.push({x:e,y:c[x].y}),O.push({x:e,y:v}),O.push({x:n,y:v}),O.push({x:n,y:c[S].y});break;case pg:switch(k){case fg:e=void 0!==_?Math.min(_,c[x].x):c[x].x,n=void 0!==_?Math.max(_,c[S].x):c[S].x;break;case pg:e=b.left+b.width,n=e;break;case dg:e=void 0!==_?Math.max(_,c[S].x):b.left+b.width,n=e;break;case ug:e=c[x].x,n=Math.max(m[S].left+m[S].width,c[x].x);break;default:return this.path}O.push({x:e,y:c[x].y}),O.push({x:e,y:v}),O.push({x:n,y:v}),O.push({x:n,y:c[S].y});break;case fg:switch(k){case fg:e=b.left,n=e;break;case pg:e=void 0!==_?Math.max(_,c[x].x):c[x].x,n=void 0!==_?Math.min(_,c[S].x):c[S].x;break;case dg:e=b.left,n=e;break;case ug:e=c[x].x<c[S].x?Math.min(m[S].left,c[x].x):c[x].x,n=Math.min(e,c[S].x);break;default:return this.path}O.push({x:e,y:c[x].y}),O.push({x:e,y:v}),O.push({x:n,y:v}),O.push({x:n,y:c[S].y});break;default:return this.path}l.push(...0===x?O:O.reverse())}else{let t,e;switch(i){case dg:switch(o){case dg:e=b.top,l.push({x:c[0].x,y:e}),l.push({x:c[1].x,y:e});break;case ug:t=b.left+b.width,l.push({x:t,y:c[0].y}),l.push({x:t,y:b.top+b.height}),l.push({x:c[1].x,y:b.top+b.height});break;case pg:t=c[1].y<c[0].y&&c[1].x<c[0].x?c[0].x:b.left+b.width,l.push({x:t,y:c[0].y}),l.push({x:t,y:c[1].y});break;case fg:t=b.left,l.push({x:t,y:c[0].y}),l.push({x:t,y:c[1].y});break;default:return this.path}break;case ug:switch(o){case dg:t=b.left+b.width,l.push({x:t,y:c[0].y}),l.push({x:t,y:b.top}),l.push({x:c[1].x,y:b.top});break;case ug:case pg:case fg:e=b.top+b.height,l.push({x:c[0].x,y:e}),l.push({x:c[1].x,y:e});break;default:return this.path}break;case fg:switch(o){case dg:t=c[0].x>c[1].x&&c[0].y<c[1].y?c[1].x:b.left,e=c[0].x>c[1].x&&c[0].y<c[1].y?c[1].y:Math.min(b.top,c[0].y),l.push({x:t,y:c[0].y}),l.push({x:t,y:e}),l.push({x:c[1].x,y:e});break;case ug:t=b.left,e=Math.max(b.top+b.height,c[0].y),l.push({x:t,y:c[0].y}),l.push({x:t,y:e}),l.push({x:c[1].x,y:e});break;case pg:t=b.left+b.width,l.push({x:c[0].x,y:b.top}),l.push({x:t,y:b.top}),l.push({x:t,y:c[1].y});break;case fg:t=b.left,l.push({x:t,y:c[0].y}),l.push({x:t,y:c[1].y});break;default:return this.path}break;case pg:switch(o){case dg:e=c[0].y<c[1].y&&c[0].x<c[1].x?c[0].y:b.top,l.push({x:c[0].x,y:e}),l.push({x:c[1].x,y:e});break;case ug:e=c[0].y>c[1].y&&c[0].x<c[1].x?c[0].y:b.top+b.height,l.push({x:c[0].x,y:e}),l.push({x:c[1].x,y:e});break;case pg:case fg:e=b.top+b.height,l.push({x:c[0].x,y:e}),l.push({x:c[1].x,y:e});break;default:return this.path}break;default:return this.path}}return a&&l.push(a),[t,...l,e].filter((t,e,n)=>{if(0===e)return!0;const i=n[e-1];return t.x!==i.x||t.y!==i.y}).filter((t,e,n)=>{if(0===e||e>=n.length-1)return!0;const i=n[e-1],s=n[e+1];return!(t.x===i.x&&t.x===s.x||t.y===i.y&&t.y===s.y)})}get nature(){return zg}}Cc.register("ortholine",Rg);const jg={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"image-selector",label:"image-src",name:"src",property:{displayField:"id",displayFullUrl:!0,baseUrlAlias:"$base_url",defaultStorage:"scene-image",storageFilters:{type:Array,value:[{name:"category",value:"image"}]},useUpload:!0}},{type:"select",label:"cross-origin",name:"crossOrigin",property:{options:["","anonymous","use-credentials"]}}],"value-property":"src",help:"scene/component/image-view"};class Lg extends(Oc(Tc)){static get noimage(){return Lg.NOIMAGE||(Lg.NOIMAGE=new Image,Lg.NOIMAGE.src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGAAAABIBAMAAAD7Se1QAAAAIVBMVEUAAABHcEwBAQEREREBAQEEBAQGBgYLCwsDAwMDAwMICAi6HF9tAAAAC3RSTlNNAEAERiMYCS41Eac10lYAAAEgSURBVHhe7dY9asQwEAXgh7DNertNiJy48pIitY3SB7bYdk0ukL1BDDmA9gZecoH4pmFQ3MQayUMguPBrNPD4wD9TCMvJmt3M/AtYwXOlXiWgqADVCUBD46MAnGhMBaCiUQmAm8VA/Eh/eWl9Fn5WcxD+OLuRrUYJDKLluwH2InACUgkoACSdADxQc50Bytadb9RkM0CT13TcvlCT1HFg8UTHvasuUVACCa3El6u2UdD8LFTlKhUFFgA+d3dj10aABkUN72N3jAADCrJq7PIIsPidcxBoTHIIAjMFmyCwmGYIAA1P9gFgfCANAOsDSccCDW+uLDB+kLGg94OkZoAGkwsDDAe2DOg5oPxAg03rBR88OHpBz4N8UVeHFSwma74BTW6Ge4rIRa4AAAAASUVORK5CYII="),Lg.NOIMAGE}dispose(){super.dispose(),this._offcanvas=null,this._image=null}render(t){const{left:e,top:n,width:i,height:s,isGray:r=!1,alpha:o=1,src:a}=this.state;if(this.prepareIf(!this._image&&a),t.beginPath(),t.globalAlpha*=o,this._image&&this._image.complete)if(r&&this._offcanvas)t.drawImage(this._offcanvas,e,n,i,s);else try{t.drawImage(this._image,e,n,i,s)}catch(r){t.drawImage(Lg.noimage,e,n,i,s)}else!this.app.isViewMode&&t.drawImage(Lg.noimage,e,n,i,s)}get nature(){return jg}get hasTextProperty(){return!1}async ready(){await super.ready();const{src:t}=this.state;if(!this._image&&t){const e=this.root?.app?.loadTracker;if(e){const n=new Promise((t,e)=>{this.prepare(()=>t(),t=>e(t))});e.track(`image:${t}`,"image",t,n)}else this.prepareIf(!0)}}prepare(t,e){const{src:n,crossOrigin:i}=this.state;if(n){this._image=new Image;try{i&&(this._image.crossOrigin=i),this._image.src=this.app.url(n)||""}catch(t){return void e(t)}this._image.onload=()=>{if(this.get("isGray")){const t=this._image.width,e=this._image.height;this._offcanvas=Cc.createCanvas(t,e);const n=this._offcanvas.getContext("2d");n.drawImage(this._image,0,0);const i=function(t,e,n){let i;try{i=t.getImageData(0,0,e,n)}catch(t){return Qi("Get Image Data Error: "+(t instanceof Error?t.message:String(t))),null}const s=i.data;for(let t=0;t<e*n*4;t+=4){const e=s[t],n=s[t+1],r=s[t+2],o=Math.floor((e+n+r)/3);i.data[t]=o,i.data[t+1]=o,i.data[t+2]=o}return i}(n,t,e);n.putImageData(i,0,0)}t(this)},this._image.onerror=t=>{this._image&&!this._image.currentSrc&&(this._image=null),e(t)}}else t(this)}get src(){return this.get("src")}set src(t){this.set("src",t)}onchange(t,e){(t.hasOwnProperty("src")||t.hasOwnProperty("isGray"))&&(this._offcanvas=null,this._image=null,this.prepareIf(t.src))}ondropfile(t,e){for(let n=0;n<t.length;n++)if(t[n].type.startsWith("image/"))return void(this.src=e[n])}}Cc.register("image-view",Lg);class Fg extends(Qm(Oc(Cc))){is3dish(){return!0}prerender(){}}var Ng,Hg,Bg={},Yg={},Vg={};function Gg(){if(Hg)return Yg;Hg=1,Object.defineProperty(Yg,"__esModule",{value:!0});var t=function(){if(Ng)return Vg;Ng=1,Object.defineProperty(Vg,"__esModule",{value:!0});var t=function(){function t(){}return t.bitsToNum=function(t){return t.reduce(function(t,e){return 2*t+e},0)},t.byteToBitArr=function(t){for(var e=[],n=7;n>=0;n--)e.push(!!(t&1<<n));return e},t.lzwDecode=function(t,e){for(var n,i,s=0,r=function(t){for(var n=0,i=0;i<t;i++)e.charCodeAt(s>>3)&1<<(7&s)&&(n|=1<<i),s++;return n},o=[],a=1<<t,c=a+1,l=t+1,h=[],d=function(){h=[],l=t+1;for(var e=0;e<a;e++)h[e]=[e];h[a]=[],h[c]=null};;)if(i=n,(n=r(l))!==a){if(n===c)break;if(n<h.length)i!==a&&h.push(h[i].concat(h[n][0]));else{if(n!==h.length)throw new Error("Invalid LZW code.");h.push(h[i].concat(h[i][0]))}o.push.apply(o,h[n]),h.length===1<<l&&l<12&&l++}else d();return o},t}();return Vg.SuperGifUtils=t,Vg}(),e=function(){function e(t,e){this.stream=t,this.handler=e}return e.prototype.parseCT=function(t){for(var e=[],n=0;n<t;n++)e.push(this.stream.readBytes(3));return e},e.prototype.readSubBlocks=function(){var t,e;e="";do{t=this.stream.readByte(),e+=this.stream.read(t)}while(0!==t);return e},e.prototype.parseHeader=function(){var e={};if(e.sig=this.stream.read(3),e.ver=this.stream.read(3),"GIF"!==e.sig)throw new Error("Not a GIF file.");e.width=this.stream.readUnsigned(),e.height=this.stream.readUnsigned();var n=t.SuperGifUtils.byteToBitArr(this.stream.readByte());e.gctFlag=n.shift(),e.colorRes=t.SuperGifUtils.bitsToNum(n.splice(0,3)),e.sorted=n.shift(),e.gctSize=t.SuperGifUtils.bitsToNum(n.splice(0,3)),e.bgColor=this.stream.readByte(),e.pixelAspectRatio=this.stream.readByte(),e.gctFlag&&(e.gct=this.parseCT(1<<e.gctSize+1)),this.handler.hdr&&this.handler.hdr(e)},e.prototype.parseExt=function(e){var n=this;switch(e.label=this.stream.readByte(),e.label){case 249:e.extType="gce",function(e){n.stream.readByte();var i=t.SuperGifUtils.byteToBitArr(n.stream.readByte());e.reserved=i.splice(0,3),e.disposalMethod=t.SuperGifUtils.bitsToNum(i.splice(0,3)),e.userInput=i.shift(),e.transparencyGiven=i.shift(),e.delayTime=n.stream.readUnsigned(),e.transparencyIndex=n.stream.readByte(),e.terminator=n.stream.readByte(),n.handler.gce&&n.handler.gce(e)}(e);break;case 254:e.extType="com",function(t){t.comment=n.readSubBlocks(),n.handler.com&&n.handler.com(t)}(e);break;case 1:e.extType="pte",function(t){n.stream.readByte(),t.ptHeader=n.stream.readBytes(12),t.ptData=n.readSubBlocks(),n.handler.pte&&n.handler.pte(t)}(e);break;case 255:e.extType="app",function(t){n.stream.readByte(),t.identifier=n.stream.read(8),t.authCode=n.stream.read(3),"NETSCAPE"===t.identifier?function(t){n.stream.readByte(),t.unknown=n.stream.readByte(),t.iterations=n.stream.readUnsigned(),t.terminator=n.stream.readByte(),n.handler.app&&n.handler.app.NETSCAPE&&n.handler.app.NETSCAPE(t)}(t):function(t){t.appData=n.readSubBlocks(),n.handler.app&&n.handler.app[t.identifier]&&n.handler.app[t.identifier](t)}(t)}(e);break;default:e.extType="unknown",function(t){t.data=n.readSubBlocks(),n.handler.unknown&&n.handler.unknown(t)}(e)}},e.prototype.parseImg=function(e){e.leftPos=this.stream.readUnsigned(),e.topPos=this.stream.readUnsigned(),e.width=this.stream.readUnsigned(),e.height=this.stream.readUnsigned();var n=t.SuperGifUtils.byteToBitArr(this.stream.readByte());e.lctFlag=n.shift(),e.interlaced=n.shift(),e.sorted=n.shift(),e.reserved=n.splice(0,2),e.lctSize=t.SuperGifUtils.bitsToNum(n.splice(0,3)),e.lctFlag&&(e.lct=this.parseCT(1<<e.lctSize+1)),e.lzwMinCodeSize=this.stream.readByte();var i=this.readSubBlocks();e.pixels=t.SuperGifUtils.lzwDecode(e.lzwMinCodeSize,i),e.interlaced&&(e.pixels=function(t,e){for(var n=new Array(t.length),i=t.length/e,s=function(i,s){var r=t.slice(s*e,(s+1)*e);n.splice.apply(n,[i*e,e].concat(r))},r=[0,4,2,1],o=[8,8,4,2],a=0,c=0;c<4;c++)for(var l=r[c];l<i;l+=o[c])s(l,a),a++;return n}(e.pixels,e.width)),this.handler.img&&this.handler.img(e)},e.prototype.parseBlock=function(){var t={};switch(t.sentinel=this.stream.readByte(),String.fromCharCode(t.sentinel)){case"!":t.type="ext",this.parseExt(t);break;case",":t.type="img",this.parseImg(t);break;case";":t.type="eof",this.handler.eof&&this.handler.eof(t);break;default:throw new Error("Unknown block: 0x"+t.sentinel.toString(16))}"eof"!==t.type&&setTimeout(this.parseBlock.bind(this),0)},e.prototype.parse=function(){this.parseHeader(),setTimeout(this.parseBlock.bind(this),0)},e}();return Yg.SuperGifParser=e,Yg}var $g,Ug,Wg={};var qg=function(){if(Ug)return Bg;Ug=1,Object.defineProperty(Bg,"__esModule",{value:!0});var t=Gg(),e=function(){if($g)return Wg;$g=1,Object.defineProperty(Wg,"__esModule",{value:!0});var t=function(){function t(t){this.data=t,this.position=0}return t.prototype.readByte=function(){if(this.position>=this.data.length)throw new Error("Attempted to read past end of stream.");return this.data instanceof Uint8Array?this.data[this.position++]:255&this.data.charCodeAt(this.position++)},t.prototype.readBytes=function(t){for(var e=[],n=0;n<t;n++)e.push(this.readByte());return e},t.prototype.read=function(t){for(var e="",n=0;n<t;n++)e+=String.fromCharCode(this.readByte());return e},t.prototype.readUnsigned=function(){var t=this.readBytes(2);return(t[1]<<8)+t[0]},t}();return Wg.SuperGifStream=t,Wg}(),n=function(){function n(t,e){var n=this;for(var i in this.gifImgElement=t,this.options={autoPlay:!0},this.loading=!1,this.ready=!1,this.transparency=null,this.delay=null,this.disposalMethod=null,this.disposalRestoreFromIdx=null,this.lastDisposalMethod=null,this.frame=null,this.lastImg=null,this.playing=!0,this.forward=!0,this.ctxScaled=!1,this.frames=[],this.frameOffsets=[],this.initialized=!1,this.currentFrameIndex=-1,this.iterationCount=0,this.stepping=!1,this.handler={hdr:this.withProgress(this.doHdr.bind(this)),gce:this.withProgress(this.doGCE.bind(this)),com:this.withProgress(this.doNothing.bind(this)),app:{NETSCAPE:this.withProgress(this.doNothing.bind(this))},img:this.withProgress(this.doImg.bind(this)),eof:function(){n.pushFrame(),n.canvas.width=n.hdr.width*n.getCanvasScale(),n.canvas.height=n.hdr.height*n.getCanvasScale(),n.playerInit(),n.loading=!1,n.ready=!0,n.loadCallback&&n.loadCallback(n.gifImgElement)}},e)this.options[i]=e[i];this.onEndListener=e.onEnd,this.loopDelay=e.loopDelay||0,this.overrideLoopMode=null!=e.loopMode?e.loopMode:"auto",this.drawWhileLoading=null==e.drawWhileLoading||e.drawWhileLoading}return n.prototype.init=function(){var t=this.gifImgElement.parentNode,e=document.createElement("div");this.canvas=document.createElement("canvas"),this.canvasContext=this.canvas.getContext("2d"),this.tmpCanvas=document.createElement("canvas"),e.className=this.options.enclosingClass||"super-gif",e.appendChild(this.canvas),t&&(t.insertBefore(e,this.gifImgElement),t.removeChild(this.gifImgElement)),this.initialized=!0},n.prototype.loadSetup=function(t){return!this.loading&&(t&&(this.loadCallback=t),this.loading=!0,this.frames=[],this.clear(),this.disposalRestoreFromIdx=null,this.lastDisposalMethod=null,this.frame=null,this.lastImg=null,!0)},n.prototype.completeLoop=function(){this.onEndListener&&this.onEndListener(this.gifImgElement),this.iterationCount++,!1!==this.overrideLoopMode||this.iterationCount<0?this.doStep():(this.stepping=!1,this.playing=!1)},n.prototype.doStep=function(){if(this.stepping=this.playing,this.stepping){this.stepFrame(1);var t=10*this.frames[this.currentFrameIndex].delay;t||(t=100),0===this.getNextFrameNo()?(t+=this.loopDelay,setTimeout(this.completeLoop.bind(this),t)):setTimeout(this.doStep.bind(this),t)}},n.prototype.step=function(){this.stepping||setTimeout(this.doStep.bind(this),0)},n.prototype.putFrame=function(){var t;this.currentFrameIndex=parseInt(this.currentFrameIndex.toString(),10),this.currentFrameIndex>this.frames.length-1&&(this.currentFrameIndex=0),this.currentFrameIndex<0&&(this.currentFrameIndex=0),t=this.frameOffsets[this.currentFrameIndex],this.tmpCanvas.getContext("2d").putImageData(this.frames[this.currentFrameIndex].data,t.x,t.y),this.canvasContext.globalCompositeOperation="copy",this.canvasContext.drawImage(this.tmpCanvas,0,0)},n.prototype.playerInit=function(){this.loadErrorCause||(this.canvasContext.scale(this.getCanvasScale(),this.getCanvasScale()),this.options.autoPlay?this.step():(this.currentFrameIndex=0,this.putFrame()))},n.prototype.clear=function(){this.transparency=null,this.delay=null,this.lastDisposalMethod=this.disposalMethod,this.disposalMethod=null,this.frame=null},n.prototype.parseStream=function(e){try{new t.SuperGifParser(e,this.handler).parse()}catch(t){this.handleError("parse")}},n.prototype.setSizes=function(t,e){this.canvas.width=t*this.getCanvasScale(),this.canvas.height=e*this.getCanvasScale(),this.tmpCanvas.width=t,this.tmpCanvas.height=e,this.tmpCanvas.style.width=t+"px",this.tmpCanvas.style.height=e+"px",this.tmpCanvas.getContext("2d").setTransform(1,0,0,1,0,0)},n.prototype.drawError=function(){this.canvasContext.fillStyle="black",this.canvasContext.fillRect(0,0,this.hdr.width,this.hdr.height),this.canvasContext.strokeStyle="red",this.canvasContext.lineWidth=3,this.canvasContext.moveTo(0,0),this.canvasContext.lineTo(this.hdr.width,this.hdr.height),this.canvasContext.moveTo(0,this.hdr.height),this.canvasContext.lineTo(this.hdr.width,0),this.canvasContext.stroke()},n.prototype.handleError=function(t){this.loadErrorCause=t,this.hdr={width:this.gifImgElement.width,height:this.gifImgElement.height},this.frames=[],this.drawError()},n.prototype.doHdr=function(t){this.hdr=t,this.setSizes(this.hdr.width,this.hdr.height)},n.prototype.doGCE=function(t){this.pushFrame(),this.clear(),this.transparency=t.transparencyGiven?t.transparencyIndex:null,this.delay=t.delayTime,this.disposalMethod=t.disposalMethod},n.prototype.pushFrame=function(){this.frame&&(this.frames.push({data:this.frame.getImageData(0,0,this.hdr.width,this.hdr.height),delay:this.delay}),this.frameOffsets.push({x:0,y:0}))},n.prototype.doImg=function(t){var e=this;this.frame||(this.frame=this.tmpCanvas.getContext("2d"));var n=this.frames.length,i=t.lctFlag?t.lct:this.hdr.gct;n>0&&(3===this.lastDisposalMethod?null!==this.disposalRestoreFromIdx?this.frame.putImageData(frames[this.disposalRestoreFromIdx].data,0,0):this.frame.clearRect(this.lastImg.leftPos,this.lastImg.topPos,this.lastImg.width,this.lastImg.height):this.disposalRestoreFromIdx=n-1,2===this.lastDisposalMethod&&this.frame.clearRect(this.lastImg.leftPos,this.lastImg.topPos,this.lastImg.width,this.lastImg.height));var s=this.frame.getImageData(t.leftPos,t.topPos,t.width,t.height);t.pixels.forEach(function(t,n){t!==e.transparency&&(s.data[4*n+0]=i[t][0],s.data[4*n+1]=i[t][1],s.data[4*n+2]=i[t][2],s.data[4*n+3]=255)}),this.frame.putImageData(s,t.leftPos,t.topPos),this.ctxScaled||(this.canvasContext.scale(this.getCanvasScale(),this.getCanvasScale()),this.ctxScaled=!0),this.drawWhileLoading&&(this.canvasContext.drawImage(this.tmpCanvas,0,0),this.drawWhileLoading=this.options.autoPlay),this.lastImg=t},n.prototype.doNothing=function(){},n.prototype.withProgress=function(t){return function(e){t(e)}},n.prototype.getNextFrameNo=function(){var t=this.forward?1:-1;return(this.currentFrameIndex+t+this.frames.length)%this.frames.length},n.prototype.stepFrame=function(t){this.currentFrameIndex=this.currentFrameIndex+t,this.putFrame()},n.prototype.getCanvasScale=function(){return this.options.maxWidth&&this.hdr&&this.hdr.width>this.options.maxWidth?this.options.maxWidth/this.hdr.width:window.devicePixelRatio||1},n.prototype.play=function(){this.playing=!0,this.step()},n.prototype.pause=function(){this.playing=!1},n.prototype.isPlaying=function(){return this.playing},n.prototype.getCanvas=function(){return this.canvas},n.prototype.isLoading=function(){return this.loading},n.prototype.isReady=function(){return this.ready},n.prototype.isAutoPlay=function(){return this.options.autoPlay},n.prototype.getLength=function(){return this.frames.length},n.prototype.getCurrentFrame=function(){return this.currentFrameIndex},n.prototype.moveTo=function(t){this.currentFrameIndex=t,this.putFrame()},n.prototype.loadURL=function(t,n){var i=this;if(this.loadSetup(n)){var s=new XMLHttpRequest;s.open("GET",t,!0),"overrideMimeType"in s?s.overrideMimeType("text/plain; charset=x-user-defined"):"responseType"in s?s.responseType="arraybuffer":s.setRequestHeader("Accept-Charset","x-user-defined"),s.onloadstart=function(){i.initialized||i.init()},s.onload=function(){if(200===s.status){var t=s.response;t.toString().indexOf("ArrayBuffer")>0&&(t=new Uint8Array(t));var n=new e.SuperGifStream(t);setTimeout(function(){i.parseStream(n)},0)}else i.handleError("xhr - response")},s.onerror=function(){i.handleError("xhr")},s.send()}},n.prototype.load=function(t){this.loadURL(this.gifImgElement.src,t)},n}();return Bg.SuperGif=n,Bg}();const Xg={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"image-selector",label:"src",name:"src"},{type:"checkbox",label:"play",name:"play"}],"value-property":"src",help:"scene/component/gif-view"};class Kg extends Fg{async oncreate_element(t){const{src:e,play:n}=this.state;this.onchangesrc(e),this.onchangeplay(n)}buildImg(){const t=this.element;if(!t)return document.createElement("img");t.replaceChildren();const e=document.createElement("img");return e.style.width="100%",e.style.height="100%",t.appendChild(e),e}onchange(t,e){super.onchange(t,e),"src"in t&&this.onchangesrc(t.src),"play"in t&&this.onchangeplay(t.play)}setElementProperties(t){}onchangeplay(t){const e=this._superGif;e&&e.isReady()&&(t?e.play():e.pause())}onchangesrc(t){const e=this.buildImg();t||(t="data:image/gif;base64,R0lGODlhYABIAPcAAAAAAAEBAQICAgMDAwQEBAUFBQYGBgcHBwgICAkJCQoKCgsLCwwMDA0NDQ4ODg8PDxAQEBERERISEhMTExQUFBUVFRYWFhcXFxgYGBkZGRoaGhsbGxwcHB0dHR4eHh8fHyAgICEhISIiIiMjIyQkJCUlJSYmJicnJygoKCkpKSoqKisrKywsLC0tLS4uLi8vLzAwMDExMTIyMjMzMzQ0NDU1NTY2Njc3Nzg4ODk5OTo6Ojs7Ozw8PD09PT4+Pj8/P0BAQEFBQUJCQkNDQ0REREVFRUZGRkdHR0hISElJSUpKSktLS0xMTE1NTU5OTk9PT1BQUFFRUVJSUlNTU1RUVFVVVVZWVldXV1hYWFlZWVpaWltbW1xcXF1dXV5eXl9fX2BgYGFhYWJiYmNjY2RkZGVlZWZmZmdnZ2hoaGlpaWpqamtra2xsbG1tbW5ubm9vb3BwcHFxcXJycnNzc3R0dHV1dXZ2dnd3d3h4eHl5eXp6ent7e3x8fH19fX5+fn9/f4CAgIGBgYKCgoODg4SEhIWFhYaGhoeHh4iIiImJiYqKio+Pj5iYmKCgoKampqurq66urrCwsLGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrOzs7S0tLa2tre3t7m5ubu7u7+/v8DAwMHBwcPDw8XFxcfHx8vLy8/Pz9LS0tXV1dfX193d3eTk5Onp6fj4+Pz8/P7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v///////////////////////////////////////////////////////////////////////////////yH5BAkAAPUAIf47R2VuZXJhdGVkIGJ5IGpzZ2lmIChodHRwczovL2dpdGh1Yi5jb20vYW50aW1hdHRlcjE1L2pzZ2lmLykALAAAAABgAEgAAAj+AGcJHEiwoMGDCBMqXMiwocOHECNKnEixosWLGDNq3Mixo8ePIEOKHEmypMmR9VKqXMmypcuXMGPKnJkSIs2bOHPqZGlzp8+fQOv1DEq0KMyhRpMmRaq0KVCmTqPmhCq1qkyqLrFRSyYwGTVsVo1iZXmNa8Fk18ISHasSm1mDycCq/ck2JTWF1ObSfTjz7cFken3WFbow8M7BDA3rHOwXruKpfGXeTZg3qDVrUge7RRg3KLZjx+Q2HVyvLNy0QaMJjBaVdD2tZr2K/mmNIObRkR+n9AsYt0Pddg1WXppb8bWDx1CLLW74GcJnSl3TtDY8Zu2Et4tKl7n52eyWnxXvhl7+26jqrspbnlfIWjtz2gWPZV95neH8veU9NxZYfbfD3kFt99J6Bnmn0mQO9XfYezrVxxlmx0GUXIAM4hSeffsxBN1TFd5E4Ef3QZbfTg6CNJ5gHXJ3TEntLThiTh+KFCJNAqZU4kgAitjQTheepOBMNcZI0oQ6JpbTjSZtiNN2PZ400IxHpdiSc07G911M0iFZZYtAStnWilUeBGVLrlEZpmM0elmPlmfO8iOZXl4DZpsGEYmll2bSWWCXLwJXVY1+urhjoGEBSuiSah6K36CKtpZoo4s9CimielZq6aWYZqrpppx26umnoIZ6UkAAOw=="),e.src=t,e.setAttribute("rel:animated_src",t),e.setAttribute("rel:auto_play",String(0)),this._superGif=new qg.SuperGif(e,{autoPlay:!1}),this._superGif.init(),this.element&&Array.from(this.element.children).forEach(t=>{t.style.width="100%",t.style.height="100%"});const n=this._superGif.getCanvas();n.style.width="100%",n.style.height="100%",this._superGif.load(()=>{setTimeout(()=>{this._superGif.moveTo(0),this.play&&this._superGif.play()},100)})}ondropfile(t,e){for(let n=0;n<t.length;n++)if(/\.gif$/.test(t[n].name))return void(this.src=e[n])}get src(){return this.getState("src")}set src(t){this.set("src",t)}get play(){return this.getState("play")}set play(t){this.setState("play",t)}get nature(){return Xg}get tagName(){return"div"}}Cc.register("gif-view",Kg);const Qg={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"attachment-selector",label:"src",name:"src",property:{category:"audio"}},{type:"checkbox",label:"started",name:"started"},{type:"checkbox",label:"loop",name:"loop"}],"value-property":"src",help:"scene/component/audio"};class Zg extends(Oc(Tc)){static get image(){return Zg.IMAGE||(Zg.IMAGE=new Image,Zg.IMAGE.src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAZAAAAGQCAMAAAC3Ycb+AAAAP1BMVEUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACzJYIvAAAAFHRSTlMA8BAwgNBgQKB/wCBwUJDg37CvXyUlBK8AABFYSURBVHja7NsBkqIwFIThTiAQgyBq3/+sm6p1tnamZkaTMhJJf1f4S/JeEIiIiIiIiIiIiIiIiEhD7Hg4BH84TpAKjJ4f3NFCtjVd+InXz2RTs+FXlxGylYHfcVfIJmb+YFWSLUyGVJKKBJJKUo+Rd6w63l/qzLuCkryO5fe0l2xk5mMWbe+v0fNBRqf7S3je6CipQ2ACr+dWcYEpzBFS1plpguatsnomMgdIQSOTuQ5SjmE6/UgK8szgdJIUM/FG41YlFmYJ2kkKsY5ZzAwBurHDk3WGeRY0bvYrGa1+rqNI22f7dS32ZnUK1GMr0eSK3mEc9dhKMxp+ZTo8kT2emOXS5LQ1kCxbJBocSd2k5PaIjMVzjWcdJPk9ooBnmzx1t5XbIxqBKpJ4NGTgzwKiGpK4do72gb+ZUMIYtCPm9WCPMsYTE5k2hq2ZvzujlCE1iRmwf3dvmRyKsT0T7b9I7HEPCpqCiqT2IIqaT1pI0noQZdlFC8l/PbYPAnRORT56VBEE6FXkb49agmByKhJ71BME6FsvEntUFQTdqekisUdlQWCXhovEHtUFAWbTapHYo8YgmFybO3vsUWcQYGmxSOxRbRAMprkisUfFQVKmrX18sxt7VB0ENjT1xir2qDxIwkFi3v89e+xRfxAMzfzzIfZ4hyAYDR9zwVuLPd4jCDrTwoLYGb5LEFi3/+E3rweR6urX20c/Fvls2Pvwm9mDSGIPhv8YPyGf3/eo9Ye7O8B2FIShAAooakEttex/rbODad5/yTHIAjqn505IQPv+Xz06dz+4VXORHEZcgAcB8updM8F6e25jBzwIkE07l+x8amMnPDp6nsNJ+BoZ7Q6F8egqAda9VEuRNlZjBzwYkMskdXR73okd8GBAJiKYjBcZKKqG9OiKDbgdfxJ5VhsBPDiQZhaouD3p4hfw4EAmwxisz3MSHwAPEmQ1TB1N+SmXWoAHC7JbZsWl/IxLLcCDBplNo3lrfMLsmwAPGmShAxX5/1vOEzjEz3iyfQ/hI36W4TctsUesOAifPdrQg8M++KYl95iCBkjI1r8634betBAPHZDTPFAmD3zLiHgogVTziMsahz0eIh5aIGHGRSJ2mFtHPR4iHhQIP2UvWGMf8wk74qEIEib7rLjPiBfxiAcCwp8V+Nae3uMdRhAPDIR/J5f/Q2DTcC+hIB7qIGEq3Ti9bx+sryMeAAgS70OK8G2kBD8L8QBAoLWU3g3vUVIc6D0txAMAsY+4jBWowXHO64gHBGKfYJ2T5qY1BxcL98BB+PQ+XiS9xxh9EQ8ChA6C5UXWIUoE9MBB8LVHQoS7ib8/dRn3sAcJ6bQRSdH96RDxIEH4QEX+AHF4LxHEAwUh12xyr1V8lwjiQYDYF8kuf1jluUQQDwrEvkhW8Wc6LhHUgwfhi4QPlHm7LRHawx4kpE191Dq8lgjhAYDQa1cftYrPEiE8OJDb40uqyzdQCA8WhAzL4G/PT4c3WrgHD2IfllGl53V37zsgHg5ApPNvVvq4Fn4spx4oiH1W3CwtEV+PDhEPJyBSkVX4aa7emkM83ICEKWpGM7wdvYCCeDgCEYpcwhLxczhEPFyBCEUWnRL5T6X59SBASBF+9l28TL5F7uEORCZyCUvEx+S7yT0cgoRVb9JaXLR1qUdfgksQ0fTbgmhFB20d8HAKEha14+F8f1sHPNyCiL6EqK+n20/rgIdjkFC0Ho1s6Gndvcc9ICkr/ey8/rHO6vp9KawL8DAFOV6l9Fyub7IbflsCag1qRfVsXWvxHjxIejU+BHZV6uvHD1XiEb++Bw8i+dNd+Wv0eCQmhcPhRPwUUt2DB5G1sfa1aeyzAuyJj9x2HjyIdKzIKw5SI14ieFtvo3kIQERj3lVhkUOnRD7AnjV5369QkAOJZeCH+Jh41xOLs73dQwAifY6dpxCCbjTDzLf1Bm1Y93tAIDOWXcLPvrHyr2hVoEAceEAgDQzB4jetk0/c2OXRHB48EJCpa4dgpYh2ETxtrshz7zx4ICCzfuTSDn8p/EOS9OTjwgMB+cABP3yWYuOPIofs33LigYCULlpZNXJppVU30Vf14kGAUCLijf1D71lN9FW9eFiA9KgZ8FPpPUsSnufGA+8hvAg2Kpz0nrX//qp+PIgpC3i6xJRITOye9fn1VT15ICCrVlQG5rywo0H8x965bVkNwmCYQ2kR6Gmb939WXV65dFnI/tPdjPBfO7XMN4EkTUJtqZp4sCJ1+8jwkhMu0KpMxFXFA8hlVfQSMxGH5mDK1VKV8QCyvTVtUiYyo7V358VStfGoAEFMhGYhEwloxZy9WKo2Hjwg5iSOvFDXeUYd33+PuVfHgwnEBWLocDJp+IIa2fyvperjwQRiXCKGosyXqoA+YfsIELuYu4HAt+msMknfDK4jfQJIzOZ2IPAQWJtFOhQKivR2IDZ6Awis7V0iLxqBI7uEZo19dakTogLSwKvf8yk8Jq6CGK0GKvWlatG7b7kkUU/Lo1gdXWn7/4E0j0qeJDpqN/ABqQcgJgdqURb4chjQktIugDS6wFFiz3JgaJj7AGJmholAe9YKhoZLJ0Ca6smjwJ4VwVN96gVIE5GM71kHaGKxGyAtRDaB2NBhLVmpHyANRKzDO28W7FS3HQFpaIWa8TrfCXQwegJSL5k+8M9UJ+pm9QTEnCIZrR0MDQeQ9ua0iCcYQaBTV0CqNXQW/yiyYG7W1heQanPaCkciBXuH1BkQJzHcDQxmpgGkPatl4WkbCXO/bW9AqlNg4H0PPMi6A1IxkQmOZ8D0ousNSMVEEuyreTAQ6Q7IRJeCX2YZQHhv6SrBOmpkM+YUzN0BqSRQCupmTeCP9wdkhiOREwtEzgGEsWcF9BhK9R8fQDiN7A8DiR0CKXQlj/q9IM8OgXjIzcKBlAHkD6FulgNzJwPIHwpo8mQAkX3LiPq9dKUMAQk9AqmcqmjuBAJCPQIpA4guIAsKJA0gnwNy3A4kDyBIHCEPxAwgf8gPILqA5AFEF5CxZX0lIHYc6rqADLf380BmFMgxgIzUyf8MJKLTRelKHgKy9wgkjfS7LiA0gKgC8vQn3HUA4RQ5LKPIAQciWbqIEg0YkLNDIHYUyqkCsmKN5vg3+W0AYTRATaPY+uu1IwS6UMGAlO6AFPjSCQMStaNh53cdcPG7Hx1Uupo+rx+Bltn1BuTAj5BptEV/bHAAwbnJMICwRmtUDOSEA8s4Rmtw3nITGD6TwUNoG0Ca7xi2YKSPj2eKXQFxQWKA2QbGMWEMMGseOb7C7T47uJS1JyAzVbTjqZdU3zbHzMXWS+qp4Fgn8Ahy/QCRGqQcwU1vGnN7fylboWn8Bzg//hyjxltvdcl45bwFfYKzFyBy11UU9BnjuoqfWizVlQXulpzBTNbaB5Aid+VRrkBFB630AMS9BC8FK2ggE7u/FGy1kvfcB9TKQufX5uUXNWl3EjvWCi4k/u9A3Ddq1CpTIQGe6VN1qd8ArcvDQNw3S41Kn6qQmOq5e7pRr+8fAYLiIJtFrrvYRMYL0q06vj8EZLXUriJzRY8H1xEagOCK7gkghRg6RQYO0I6aWPwIEAru80AiMWSdzAeuDXUKyr+WqpAID8hMHC1Ct8F4mUsQ6W8pJMICki0JHCBczAFdBl38G3VE6ErQhhWlih4LWrCSLpaqjggHiGe9mVjRY0YPoelyqcqIcIDEe97rqJFFH7FcLlUZEQ6Qg5plvZiBFNhtri1VFREGEC/Eg4nZoU5vqi1VFREGkIXDQ8xAIhzoT/WlKiLCAFIYPOQMxOPdjfWlKiLCADJRm3YGj+pDE2xktmmpaogwgMz8d8GrumZ4xzpbvinqISJ+hiTWm7wEqoJdI9JEV9JChAEkS3xCZzKecLcgN6YwlRBhAGmweTsblg6qKMM7Vmh321UQ4QAp1VfwhqVJIh+Wm03W0qV0EOEAybXtivkCmWrKeH2EZ/xBaSBCV2L9Re+LYSqJJIxDu1ew07U0EGEBcTtmHty4JuPtQhvLh1BAhK7Uvvq0GK484QZST0GvvFDqeSJ1IA0r2mfDljvqBoJ//rVsq7yZCA6kXgVkJ2f4ijIGMjOfMVsCBBORB2Jy+sM6ijNvaBUqmw/cStZ8EiKciHwp6Rp++88qmxXQeTUxDiJWJ9wSISvBicgXW+dypn1PqWTznlwgwdZdfiLHr5OELEAEASKvJFRE5JCPKbh8OxHdQKJU0crEzRXrJ/IEkFms6tGyrUw9kQeALFRXvK2iSzsRAAi6BLxM+60xdsqJAEBuXMAMxDLVp+gmAgC57/UT4qvVj3TVRCAgSAYL91aXtyNLzUQAIFhAiP8m0/NHOp+ILiBtPFKrs6bgSOcT0QTEB8nO3QR1yKslggKRf+m11UB0HOl8IlqAeCvauXuo8HnfIqIDyCw6G8XMcGiplMingMzCnbuHFp/3LSLPA4nUpqm5YkWNzwsQeQxIDsKjH5wVSU5qJPIJIIt4jjpqNBAekQeBfJOeHWS81FQoo4/I7UDcS3wUh0liTzLqiEgDqddx4ZHDrNZAACIAEMw88HPYWb0GAhABgEDmgf9Vb5oNBCByOxD3uqWYbCHVBgIQuRlIsbfwMEG5gQBE7gSyHMDsOayrxJvHBRC5B0hOxJH1nK4SlUE6QOR+IG6ju3iYQEqDdIDIzUDyZu/jMRHpS/OiRG4FkiPRfTw8kbrvIAJEACAIDpyHC1/GQHhEbgKSXwTyqIeEur6kixEBgABHOTr7YSX1MSFAhA0E307wUU76Y0KACAsI/tvCRzkF+iIuL0AEAYLbR2QOfvhKJ/obRESBxNt5rPSFXN4f7dyNdqMgEIbhAXWwJErT/e7/Wreb5HTT07QVgWSAeW5g7b4n8qOSUCRPEId4HP93SXp5dDNGRJFcQTxihSH+NW1Bb1cXKpIryJAwnG/zhl8ZcSP6jiKZghwRaaWLnP/AkcSKKJIniEcUs8QfjFLdEmRvkSxB4lfn0QN6DY+lshQpHiT96Dlr6r5hxRUpHST9ZEY71X7DOmOZQVZLsd5Q8wzrPxYYJDiKNqOBG1ZCkZKzrNXu6lHvkjChSFqQsdTPg45ApXtYaUXKr9TNuPcvqO2pVMkitFXAL2a79/qr3HQvVSTXUtofCl79RDXh5CDpw3pwu6+9kRlvtiI5VtPhmHLltT4EKVQkfb8pcOHrXqk6nBAksUjgpKtuYsskaxGKYT0+84uYgziE4YQgMdx0m8PRfis2MbL33PMXoVjD6PEunI4HSjDjStiJP08vQk9hZzQ7oH/geoLYCUBDW4rf4FqCDFt7THUO6B+4jiDn2XNTW7zf4hqCMND4BOsGyw+yAmh0x+QeFh7EeqD5Ce8nLDrI8NpbDyIWHIQNruo4GyAPlhrEzuixBxHLDDJMnfYgYolBricHNfjIdgMWF+Qyu+pkgX4HCwuymL57ELGkIHZG7z2IWE6Q5VV7vGMhQewbtMcZiwhyHj26ne9+xs8PcvDQHnFFqCD7Au0RW4TK+fOKqw4eoOcqYqgU53HR3/5uShFPCfKey9hFDyJO/vAi7RDZnp7X5igyUH72xSDW1E2Pn4tMRCQgR8vLwbgii4gcmLvqQcSPGtIPX3M08wn6I4qYQ94cM/Yw9Xxhmw+X/59wHrtMlX1AmIkzdyaaAnLg1Nnw8WGYSk40X/BOh4+El6LMSBnN2Cd0tPq4w/LJXGrMbCX06PZ2dcM65yzlNertShSHf3SzRAyPM332IcSAHUKPi8EHmXU0l8Uglmni0yipDoi16s+jJKejhywLooz68yiMEcHr2qM4h81CJ++VPJfTu5UwBpv4Pp9DJSi6MJx0bvUwiw4ewgT8zNR0LHUL+OccOpY/3ElzyGKD5pBlMJpDlsOkMythRoNbXh95PJsdA67MrMtAEYbjeDqNo+7oKqWUUkoppZRSSimllFJKFfMXp4vmSjB8n6sAAAAASUVORK5CYII="),Zg.IMAGE}dispose(){super.dispose(),this.started=!1,delete this._audio}async ready(){super.ready(),this._audio=new Audio;const{src:t="",loop:e=!1,started:n=!1}=this.state;if(t){const e=this.root?.app?.loadTracker;if(e){const n=new Promise((e,n)=>{this._audio.addEventListener("canplay",()=>e(),{once:!0}),this._audio.addEventListener("error",()=>n(new Error(`Audio load failed: ${t}`)),{once:!0})});e.track(`audio:${t}`,"audio",t,n)}}this._audio.addEventListener("canplay",()=>{this.started&&this._audio.play()}),this.onchangeSrc(t),this.onchangeLoop(e),this.onchangeStarted(n)}render(t){const{left:e,top:n,width:i,height:s}=this.state;t.beginPath(),this.drawImage(t,Zg.image,e,n,i,s)}get nature(){return Qg}get hasTextProperty(){return!1}get src(){return this.get("src")}set src(t){this.set("src",t)}get started(){return!!this.get("started")}set started(t){this.set("started",t)}start(){this._audio&&(this._audio.classList.add("active"),this._audio.play())}pause(){this._audio&&(this._audio.classList.remove("active"),this._audio.pause())}onchangeSrc(t){try{"data"!==String(t).substring(0,4)?this._audio.crossOrigin="use-credentials":this._audio.crossOrigin=null,this._audio.src="string"==typeof t?this.app.url(t):t}catch(t){return void Qi(t)}}onchangeStarted(t){const e=this._audio;t?4==e.readyState&&e.play():e.pause()}onchangeLoop(t){this._audio.loop=t}onchange(t,e){"src"in t&&this.onchangeSrc(t.src),"started"in t&&this.onchangeStarted(t.started),"loop"in t&&this.onchangeLoop(t.loop)}ondblclick(t){this.started=!this.started}ondropfile(t,e){for(let n=0;n<t.length;n++)if(t[n].type.startsWith("audio/"))return void(this.src=e[n])}}Cc.register("audio",Zg);class Jg extends(Oc(Cc)){is3dish(){return!0}}Cc.register("text",Jg);const ty=["refid","left","top","width","height","rotation","animation","zPos"];class ey extends ng{isGroup(){return!0}is3dish(){return!0}get showMoveHandle(){return!1}get(t){return this._model[t]}set(t,e){if("string"==typeof t)return this.set({[t]:e});const n=ty.reduce((e,n)=>(t.hasOwnProperty(n)&&(e[n]=t[n]),e),{});return super.set(n,void 0)}capture(t,e,n){const i=super.capture(t,e,n);if(i!==this)return i}set bounds(t){if(this.__MUTATING__)return void(super.bounds=t);const e=this.bounds,n=t.width/e.width,i=t.height/e.height;this.path=this.path.map(s=>({x:t.left+(s.x-e.left)*n,y:t.top+(s.y-e.top)*i})),this.components&&this.components.forEach(t=>{if(t.mutable)t.mutatePath(null,function(t){return t.map(function(t){return{x:t.x*n,y:t.y*i}})});else{const e=t.bounds,s=t.center,r={x:s.x*(1-n),y:s.y*(1-i)},o=e.width*(1-n),a=e.height*(1-i),c=-(r.x-o/2),l=-(r.y-a/2);t.bounds={left:e.left+c,top:e.top+l,width:e.width*n,height:e.height*i}}})}get focusible(){return!1}get bounds(){return super.bounds}get hasTextProperty(){return!1}isIdentifiable(){return!1}calculateBounds(){this.clearCache(),this.__MUTATING__=!0,this.mutateBounds(function(t){const e=Cc.union(this.components.map(t=>t.bounds));return this.components.forEach(t=>{const n=t.bounds;t.bounds={left:n.left-e.left,top:n.top-e.top,width:n.width,height:n.height}}),{left:t.left+e.left,top:t.top+e.top,width:e.width,height:e.height}},this),this.__MUTATING__=!1,this.parent.isGroup()&&this.parent.calculateBounds?.()}render(t){}postrender(t){const{top:e,left:n}=this.state;t.translate(n,e),this.layout.drawables(this).forEach(e=>{e.draw(t)}),t.translate(-n,-e)}}Cc.memoize(ey.prototype,"bounds",!0),Cc.register("group",ey);const ny={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"id-input",label:"ref",name:"ref"},{type:"select",label:"fit",name:"fit",property:{options:["","both","ratio"]}}],"value-property":"ref",help:"scene/component/local-ref"};class iy extends(Oc(Tc)){get ref(){const t=this.getState("ref");return t&&"string"==typeof t?this.root.findById?.(t):null}set ref(t){this.setState("ref",t)}get refScale(){const t=this.ref;if(!t)return{x:1,y:1};const e=t.bounds,n=this.bounds,i=n.width/e.width,s=n.height/e.height;return"both"===this.model.fit?{x:i,y:s}:{x:Math.min(i,s),y:Math.min(i,s)}}draw(t){this._drawing||(this._drawing=!0,super.draw(t),this._drawing=!1)}prerender(t){if(super.prerender(t),this.ref){const e=this.ref.center,n=this.center,i=this.refScale;t.translate(n.x,n.y),t.scale(i.x,i.y),t.translate(-e.x,-e.y)}}postrender(t){if(this.ref)return this.ref.postrender(t);super.postrender(t)}render(t){if(this.ref)return this.ref.render(t);const{left:e,top:n,width:i,height:s}=this.bounds;t.beginPath(),t.rect(e,n,i,s)}get nature(){return ny}get hasTextProperty(){return!1}}Cc.memoize(iy.prototype,"ref",!1),Cc.memoize(iy.prototype,"refScale",!1),Cc.register("local-ref",iy);class sy extends(Qm(Jl)){render(t){}is3dish(){return!0}get layout(){return Lc.get(this.get("layout"))||Fc}}const ry={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"board-selector",label:"scene-number",name:"ref",placeholder:"SCENE-1"},{type:"number",label:"round",name:"round",property:{min:0}},{type:"select",label:"fit",name:"fit",property:{options:["","both","ratio","width","height","none"]}},{type:"select",label:"mode",name:"mode",property:{options:["view","interaction"]}}],"value-property":"ref",help:"scene/component/global-ref"};class oy extends sy{dispose(){this._releaseRef(),super.dispose()}get nature(){return ry}get hasTextProperty(){return!1}get tagName(){return"div"}setElementProperties(t){const{mode:e="view",round:n=0}=this.state;t.style.pointerEvents="view"==e?"none":"inherit",t.style.borderRadius=n+"px"}async ready(){super.ready(),this.fetchRef()}reposition(){if(!this.element)return;super.reposition();const t=this._element_bounds,{offsetWidth:e,offsetHeight:n}=this.element;if(this._element_bounds={offsetWidth:e,offsetHeight:n},(!t||t.offsetWidth!=e||t.offsetHeight!=n)&&this.ref&&this.root.target_element){const{fit:t="ratio"}=this.state;this.ref.fit(t)}}async fetchRef(){this._releaseRef();const{ref:t,fit:e="ratio"}=this.state;if(!t)return;const n=this.app.refProvider;if(n&&t){const i=(async()=>{this.__ref=await n.get(t,!0),this.__ref.target=this.element,this.__ref.fit(e),this.__ref.data=this.data})();this.root?.app?.loadTracker?.track(`ref:${t}`,"ref-board",t,i);try{await i}catch(t){Qi(t)}}}get ref(){return this.__ref}set ref(t){this.setState("ref",t)}_releaseRef(){this.__ref&&this.__ref.release&&this.__ref.release(),delete this.__ref}onchange(t,e,n){super.onchange(t,e),"ref"in t&&this.fetchRef(),"fit"in t&&this.ref&&requestAnimationFrame(()=>{const{fit:t}=this.state;this.ref.fit(t)}),"data"in t&&this.ref&&requestAnimationFrame(()=>{this.ref.data=t.data})}}Cc.register("global-ref",oy);const ay="center-middle",cy={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"board-selector",label:"board",name:"board"},{type:"checkbox",label:"modal",name:"modal"},{type:"checkbox",label:"closable",name:"closable"},{type:"checkbox",label:"draggable",name:"draggable"},{type:"checkbox",label:"minimizable",name:"minimizable"},{type:"checkbox",label:"show",name:"show"},{type:"select",label:"popup-position",name:"popupPosition",property:{options:["static","absolute"]}},{type:"select",label:"popup-origin",name:"origin",property:{options:["left-top","center-top","right-top","left-middle",ay,"right-middle","left-bottom","center-bottom","right-bottom","auto"]}},{type:"string",label:"title",name:"text"},{type:"data",label:"value",name:"value"},{type:"string",label:"container-ref",name:"containerRef",placeholder:"PopupContainer id (same board)"},{type:"textarea",label:"html-template",name:"htmlTemplate",property:{language:"html"}},{type:"string",label:"anchor-ref",name:"anchorRef",placeholder:"component id (3D-tracked anchor)"},{type:"select",label:"anchor-pin",name:"anchorPin",property:{options:[{display:"Top",value:"top"},{display:"Center",value:"center"},{display:"Bottom",value:"bottom"}]}},{type:"number",label:"anchor-offset-x",name:"anchorOffsetX"},{type:"number",label:"anchor-offset-y",name:"anchorOffsetY"},{type:"number",label:"anchor-offset-z",name:"anchorOffsetZ"},{type:"checkbox",label:"constant-size",name:"constantSize"},{type:"checkbox",label:"tether",name:"tether"},{type:"select",label:"off-screen",name:"offScreen",property:{options:[{display:"Hide",value:"hide"},{display:"Edge-pin",value:"edge-pin"},{display:"Keep last",value:"keep-last"}]}}],help:"scene/component/popup"};class ly extends(Oc(Tc)){static get image(){return ly._image||(ly._image=new Image,ly._image.src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEYAAABGCAMAAABG8BK2AAADJmlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPD94cGFja2V0IGJlZ2luPSLvu78iIGlkPSJXNU0wTXBDZWhpSHpyZVN6TlRjemtjOWQiPz4gPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iQWRvYmUgWE1QIENvcmUgNy4xLWMwMDAgNzkuZGFiYWNiYiwgMjAyMS8wNC8xNC0wMDozOTo0NCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIDIzLjAgKE1hY2ludG9zaCkiIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6RkM4QzQxNUMzMzBEMTFFQ0JEMzZDMDUwQUI4MEI3QTAiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6RkM4QzQxNUQzMzBEMTFFQ0JEMzZDMDUwQUI4MEI3QTAiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDpENjlENTQ3RjMzMDkxMUVDQkQzNkMwNTBBQjgwQjdBMCIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDpENjlENTQ4MDMzMDkxMUVDQkQzNkMwNTBBQjgwQjdBMCIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PsiUYSQAAAAZdEVYdFNvZnR3YXJlAEFkb2JlIEltYWdlUmVhZHlxyWU8AAAA51BMVEVHcEwzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzOguTm2AAAATHRSTlMARhB73r9B7YLrsqdE+0cq9Avzeg31eQx4aQ+Ks6aUd5DsYKixEX1w8vyT2VjoZ3YezY/cCEDvl+QTvRwJ0ifwK/5T/aw6+IuFuCImAcS6MQAAAeJJREFUWMPt2FlX2zAQhuHJYmOSFhIggbC0QNn3rS1dKXSH9///Hi58CJLxKIpEWi6YO8c5z4lG/nxGEXmu/1OVLGnhrFaSVQYg1SZetTTvUibqeFZ9QlfmvRWoV1VmCaCRzroXPpsuAjTV7gLUfPahBqD1OQMW/fazAWTKvQRI/ZgUSJR7U8CM/dHZ+/2VcatWdvdEZAaYUhiAwkerJXt0rnzXwdRKmHfDM0fHD5kxjTFyVLzVfvvirn7+cDJWjhy7c7XlYuwc6Urvu2tRhRypyhwAf1sKY+TIxfQA+H39q5wxc+RgVrcBduTmZTlj5khnDgH4IzKpMGaOVCbvyyvRGTNHGtPrKypjXirM5jb910I4k69oQeKY+77EMAcALEsck/+W6f71tyCma/ZFROTrJVwMy7wmf3bv6/MX+Dgkkysblvxps/dhOKZb6IvrTakzXXuPApnpYneDGOeKvJlaSXcDmA7AicQyW84VeTOnY+NdiWcG1uiZksFEHdyAlsJEjEkmkwGNsKHNZCJGSKtVTYC1tO022mnjwUBrMdXg8dreuOBhv7D/62/8lGZ1wLxXyZKOm+iUHIQintyny0TkaATHjYgcjeAoFpEje9R/nGPqIx2aw3NU9odCQI6e6x/VLY32cKQXVBnkAAAAAElFTkSuQmCC"),ly._image}async ready(){await super.ready(),this.show&&this.onchangeShow(!0)}render(t){const{left:e,top:n,width:i,height:s}=this.bounds;t.beginPath(),this.drawImage(t,ly.image,e,n,i,s)}onchange(t,e){"value"in t?this.show?this.onchangeShow(!0):this.show=!0:"show"in t&&this.onchangeShow(this.show)}onchangeShow(t){if(this.app.isEditMode)return;(this.getState("board")||this.getState("containerRef")||this.getState("htmlTemplate"))&&(t?this.openPopup(this.value):this.hidePopup())}openPopup(t,e){if(this.app.isEditMode)return;const n=this.getState("anchorRef"),i=n&&this.rootModel?.findById?this.rootModel.findById(n):void 0;mp.show(this,this.getState("board"),{origin:this.getState("origin")||ay,modal:this.getState("modal"),closable:this.getState("closable")||!1,draggable:this.getState("draggable")||!1,minimizable:this.getState("minimizable")||!1,popupPosition:this.getState("popupPosition"),title:this.text,data:t||this.value,containerRef:this.getState("containerRef"),htmlTemplate:this.getState("htmlTemplate"),anchor:i,anchorPin:this.getState("anchorPin")||"top",anchorOffsetX:this.getState("anchorOffsetX")??0,anchorOffsetY:this.getState("anchorOffsetY")??0,anchorOffsetZ:this.getState("anchorOffsetZ")??0,constantSize:this.getState("constantSize")??!0,tether:this.getState("tether")??!1,offScreen:this.getState("offScreen")||"hide",...e})}hidePopup(){mp.hide(this)}get board(){return this.getState("board")}set board(t){this.set("board",t)}get show(){return this.getState("show")}set show(t){this.setState("show",t)}get started(){return this.getState("show")}set started(t){this.setState("show",t)}get value(){return this.getState("value")}set value(t){this.setState("value",t)}get hasTextProperty(){return!1}get nature(){return cy}}Cc.register("popup",ly);const hy={mutable:!1,resizable:!0,rotatable:!1,properties:[{type:"layout",label:"layout",name:"layoutOption"},{type:"checkbox",label:"constant-size",name:"constantSize"},{type:"checkbox",label:"billboard",name:"billboard"},{type:"checkbox",label:"tether",name:"tether"},{type:"select",label:"off-screen",name:"offScreen",property:{options:[{display:"Hide",value:"hide"},{display:"Edge-pin",value:"edge-pin"},{display:"Keep last",value:"keep-last"}]}}],help:"scene/component/popup-container"};class dy extends ng{get nature(){return hy}isPopupContainer(){return!0}}Cc.register("popup-container",dy);class uy extends Cc{render(t){const{path:e=[]}=this.state;if(!(e.length<=1)){t.beginPath(),t.moveTo(e[0].x,e[0].y);for(let n=1;n<e.length;n++)t.lineTo(e[n].x,e[n].y);t.closePath(),this.drawStroke(t,void 0)}}get path(){return this.model.path}set path(t){this.set("path",t)}contains(t,e){const n=this.state.path;let i=!1;return n.forEach((s,r)=>{const o=(r+n.length+1)%n.length,a=s.x,c=s.y,l=n[o].x,h=n[o].y;c>e!=h>e&&t<(l-a)*(e-c)/(h-c)+a&&(i=!i)}),i}}Cc.register("path",uy);const py={mutable:!0,resizable:!1,rotatable:!0,properties:[{type:"number",label:"round",name:"round",property:{min:0,max:100,step:1}}],help:"scene/component/triangle"};class fy extends Tc{is3dish(){return!0}contains(t,e){const{x1:n,y1:i,x2:s,y2:r,x3:o,y3:a}=this.state,c=[n,i,s,r,o,a];let l=!1;for(let n=0;n<c.length;n+=2){const i=(n+2)%c.length,s=c[n],r=c[n+1],o=c[i+1];r>e!=o>e&&t<(c[i]-s)*(e-r)/(o-r)+s&&(l=!l)}return l}get mutable(){return!0}get path(){const{x1:t,y1:e,x2:n,y2:i,x3:s,y3:r}=this.state;return[{x:t,y:e},{x:n,y:i},{x:s,y:r}]}set path(t){this.set({x1:t[0].x,y1:t[0].y,x2:t[1].x,y2:t[1].y,x3:t[2].x,y3:t[2].y})}get nature(){return py}}Cc.memoize(fy.prototype,"path",!1),Cc.register("triangle",fy);const my={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"number",label:"ratio",name:"ratio",property:"ratio"}],help:"scene/component/donut"},gy={ondragmove:function(t,e,n){let{cx:i,rx:s}=n.model;s=Math.abs(s);let r=(n.fromParent(t.x,t.y).x-i)/s*100;r=r>=100||r<=-100?100:Math.abs(r),n.set({ratio:r})}};class yy extends bg{is3dish(){return!0}render(t){let{ratio:e=50,cx:n,cy:i,rx:s,ry:r,startAngle:o,endAngle:a,anticlockwise:c}=this.state;s=Math.abs(s),r=Math.abs(r),t.beginPath(),t.ellipse(n,i,s,r,0,o||0,a||2*Math.PI,c),t.moveTo(n+s/100*e,i),t.ellipse(n,i,s/100*e,r/100*e,0,o||0,a||2*Math.PI,!0)}contains(t,e){let{cx:n,cy:i,rx:s,ry:r,ratio:o}=this.state;s=Math.abs(s),r=Math.abs(r);const a=(t-n)/(2*s-.5),c=(e-i)/(2*r-.5),l=(t-n)/(s/100*o*2-.5),h=(e-i)/(r/100*o*2-.5);let d=!1;return a*a+c*c<.25&&l*l+h*h>.25&&(d=!d),d}get controls(){let{cx:t,cy:e,rx:n,ratio:i}=this.state;return n=Math.abs(n),[{x:t+n/100*i,y:e,handler:gy}]}get nature(){return my}}Cc.memoize(yy.prototype,"controls",!1),Cc.register("donut",yy);const by={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"number",label:"ratio",name:"ratio",property:"ratio"},{type:"number",label:"wing",name:"wing",property:"wing"}],help:"scene/component/star"},_y={ondragmove:function(t,e,n){const{cy:i,ry:s}=n.model;let r=(n.fromParent(t.x,t.y).y-i)/s*100+100;r>=100?r=100:r<=0&&(r=0),n.set({ratio:r})}};class vy extends bg{is3dish(){return!0}render(t){const{ratio:e=30,wing:n=5,cx:i,cy:s,rx:r,ry:o}=this.state;if(n<3)return;const a=1.5707963267948966,c=2*Math.PI/n,l=r-e/100*r,h=o-e/100*o;t.save(),t.beginPath(),t.translate(i,s),t.moveTo(r*Math.cos(-a),o*Math.sin(-a)),t.lineTo((r-l)*(Math.cos(c-a)+Math.cos(0-a))/2,(o-h)*(Math.sin(c-a)+Math.sin(0-a))/2);for(let e=1;e<n;e++)t.lineTo(r*Math.cos(c*e-a),o*Math.sin(c*e-a)),t.lineTo((r-l)*(Math.cos(c*(e+1)-a)+Math.cos(c*e-a))/2,(o-h)*(Math.sin(c*(e+1)-a)+Math.sin(c*e-a))/2);t.closePath(),t.restore()}get controls(){const{cx:t,cy:e,ry:n,ratio:i}=this.state;return[{x:t,y:e-n+n*(i/100),handler:_y}]}get nature(){return by}}Cc.memoize(vy.prototype,"controls",!1),Cc.register("star",vy);const xy={mutable:!1,resizable:!1,rotatable:!1,properties:[]};class wy extends(nm(Tc)){is3dish(){return!1}isDescendible(){return!1}render(t){const{cx:e,cy:n,anticlockwise:i}=this.state,s=this.app?.scale||1;t.beginPath(),t.scale(1/s,1/s),t.ellipse(e,n,Math.abs(wy.RADIUS),Math.abs(wy.RADIUS),0,0,2*Math.PI,i),t.scale(s,s),t.closePath()}get path(){const{cx:t,cy:e}=this.state;return[{x:t-wy.RADIUS,y:e-wy.RADIUS},{x:t+wy.RADIUS,y:e-wy.RADIUS},{x:t+wy.RADIUS,y:e+wy.RADIUS},{x:t-wy.RADIUS,y:e+wy.RADIUS}]}set path(t){const e=t[0],n=t[2];this.set({cx:e.x+(n.x-e.x)/2,cy:e.y+(n.y-e.y)/2})}contains(t,e){const{cx:n,cy:i}=this.state,s=(t-n)/(2*wy.RADIUS-.5),r=(e-i)/(2*wy.RADIUS-.5);return s*s+r*r<.25}outline(t){const{cx:e,cy:n}=this.state;return this.toScene(e,n)}get nature(){return xy}}wy.RADIUS=5,Cc.memoize(wy.prototype,"path",!1),Cc.register("node",wy);class My extends xu{getObject3dInstance(){return new t.Mesh}build(){super.build();const{width:e,height:n}=this.component.bounds,i=this.component.state.depth||.5*Math.min(e,n),s=.15*Math.min(e,n,i),r=new R(1,1,1,4,s/Math.min(e,n,i));r.scale(e,i,n),this.object3d.geometry=r,this.object3d.material=new t.MeshStandardMaterial({color:"#5090d0",transparent:!0,opacity:.35,roughness:.6,metalness:.1,side:t.FrontSide,depthWrite:!1}),this.object3d.visible=!!this.component.app?.isEditMode}updateAlpha(){const t=this.object3d.material;t&&(t.opacity=this.component.app?.isEditMode?.35:0)}updateHidden(){this.object3d.visible=!!this.component.app?.isEditMode&&!this.component.state.hidden}updateDimension(){const{width:t,height:e}=this.component.bounds,n=this.component.state.depth||.5*Math.min(t,e);this.object3d.geometry.computeBoundingBox();const i=this.object3d.geometry.boundingBox;if(i){const s=i.max.x-i.min.x,r=i.max.y-i.min.y,o=i.max.z-i.min.z;this.setDimensionScale(t/s,n/r,e/o)}}updateFillStyle(){}updateStrokeStyle(){}updateText(){}clear(){return cu(this.object3d),super.clear()}}const Sy="data:image/svg+xml;base64,"+btoa('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" fill="#5090d0">\n <path d="M32 20a12 12 0 1 0 0 24 12 12 0 0 0 0-24zm0 18a6 6 0 1 1 0-12 6 6 0 0 1 0 12z"/>\n <path d="M55.4 27.2l-3.6-.6c-.4-1.2-.8-2.4-1.4-3.4l2.2-3c.6-.8.4-2-.2-2.6l-3-3c-.8-.6-1.8-.8-2.6-.2l-3 2.2c-1.2-.6-2.2-1-3.4-1.4l-.6-3.6c-.2-1-1-1.6-2-1.6h-4.2c-1 0-1.8.6-2 1.6l-.6 3.6c-1.2.4-2.4.8-3.4 1.4l-3-2.2c-.8-.6-2-.4-2.6.2l-3 3c-.6.8-.8 1.8-.2 2.6l2.2 3c-.6 1.2-1 2.2-1.4 3.4l-3.6.6c-1 .2-1.6 1-1.6 2v4.2c0 1 .6 1.8 1.6 2l3.6.6c.4 1.2.8 2.4 1.4 3.4l-2.2 3c-.6.8-.4 2 .2 2.6l3 3c.8.6 1.8.8 2.6.2l3-2.2c1.2.6 2.2 1 3.4 1.4l.6 3.6c.2 1 1 1.6 2 1.6h4.2c1 0 1.8-.6 2-1.6l.6-3.6c1.2-.4 2.4-.8 3.4-1.4l3 2.2c.8.6 2 .4 2.6-.2l3-3c.6-.8.8-1.8.2-2.6l-2.2-3c.6-1.2 1-2.2 1.4-3.4l3.6-.6c1-.2 1.6-1 1.6-2v-4.2c0-1-.6-1.8-1.6-2z"/>\n</svg>');class ky extends(Oc(Cc)){static get icon(){return ky._defaultIcon||(ky._defaultIcon=new Image,ky._defaultIcon.src=Sy),ky._defaultIcon}get serviceName(){}get hasTextProperty(){return!1}is3dish(){return!0}buildRealObject(){return new My(this)}render(t){if(this.app?.isViewMode)return;const{left:e,top:n,width:i,height:s}=this.bounds,r=this.constructor.icon;t.beginPath(),t.globalAlpha=.6,this.drawImage(t,r,e,n,i,s),t.globalAlpha=1}added(t){super.added(t);const e=this.serviceName;e&&(this._registeredRoot=this.root,this._registeredRoot?.registerService?.(e,this))}removed(t){const e=this.serviceName;e&&this._registeredRoot&&(this._registeredRoot.unregisterService?.(e),this._registeredRoot=void 0),super.removed(t)}get controls(){return[]}}function Ay(t){return class extends t{animOnValueChange(t,e=!1,n){if(t==this._lastValue)return;if(this.root?.app?.suppressAnimations)return this._lastValue=t,this._anim_alpha=0,void this.invalidate();let i;i=e?t-(Number(n)||0):t-(this._lastValue||0),this._lastValue=t,this._anim_alpha=-i,this.animate({step:t=>{this._anim_alpha=i*(t-1),this.invalidate()},duration:1e3,delta:"circ",options:{x:1},ease:"out"}).start()}dispose(){super.dispose(),delete this._value_substitutor}onchange(t,e){t.hasOwnProperty("value")&&delete this._value_substitutor}get animAlpha(){return this._anim_alpha||0}get animValue(){return(this._lastValue||0)+(this._anim_alpha||0)}defaultValueSubstitutor(){return this.getState("value")}get valueSubstitutor(){return this._value_substitutor||(this._value_substitutor=$r(this.getState("value"),this,void 0)||this.defaultValueSubstitutor),this._value_substitutor}get value(){return Number(this.valueSubstitutor())||0}set value(t){delete this._value_substitutor,this.setState("value",Number(xi(t)))}}}function Ey(t){return class extends t{_convertDataFormat(t,e){let n;if("json"===e)n=JSON.parse(t);else n=t;return n}isDataSource(){return!0}}}function Cy(t){var e;return(e=class extends t{is3dish(){return!0}get hasTextProperty(){return!1}get capturable(){return!1}render(t){}}).raycastTargetDefault=!1,e.requires3d=!0,e}const Ty="$base_url",Py=[{type:"gltf-preset",label:"preset",name:"preset"},{type:"gltf-selector",label:"url",name:"src",property:{displayField:"id",displayFullUrl:!0,baseUrlAlias:Ty,defaultStorage:"3d-model",storageFilters:{type:Array,value:[{name:"category",value:"image"}]},useUpload:!0,category:"application"},observe:function(t){const e=this.parentNode?.querySelector("[name=gltfInfo]");e&&(e.src=t);const n=this.parentNode?.querySelector("[name=fillStyleTargets]");n&&(n.src=t);const i=this.parentNode?.querySelector("[name=playTargets]");i&&(i.src=t)}},{type:"gltf-info",label:"",name:"gltfInfo",readonly:!0,property:{action:(t,e)=>{t._ratioLocking=!0;try{t.set(e)}finally{t._ratioLocking=!1}}},editor:{fullwidth:!0}},{type:"gltf-fill-targets",label:"fill-targets",name:"fillStyleTargets",editor:{fullwidth:!0}},{type:"gltf-play-targets",label:"play-targets",name:"playTargets",editor:{fullwidth:!0}}];function Oy(t){return class extends t{constructor(){super(...arguments),this._snapshotLoading=!1,this._ratioLocking=!1}is3dish(){return!0}get hasTextProperty(){return!1}get controls(){return[]}render(t){const{left:e,top:n,width:i,height:s}=this.bounds;t.beginPath();const r=this._topViewSnapshot;if(r)return void t.drawImage(r,e,n,i,s);this._ensureTopViewSnapshot(),t.rect(e,n,i,s),t.fillStyle="#f0f0f0",t.fill(),t.strokeStyle="#999",t.lineWidth=1,t.stroke();const o=this.getState("src"),a=o&&o.split("/").pop()?.replace(/\.[^.]+$/,"")||"GLTF",c=Math.max(10,.12*Math.min(i,s));t.fillStyle="#666",t.font=`${c}px sans-serif`,t.textAlign="center",t.textBaseline="middle",t.fillText(a,e+i/2,n+s/2,.9*i)}onchange(t,e){super.onchange?.(t,e),"src"in t&&(this._topViewSnapshot=void 0)}_ensureTopViewSnapshot(){if(this._snapshotLoading)return;const t=this.getState("src");if(!t)return;const e=Cu.getTopViewCache(t);if(e)return this._topViewSnapshot=e,void this.invalidate();this._snapshotLoading=!0;const n=this.app.url(t);Cu.loadGLTF(n).then(e=>{if(this._snapshotLoading=!1,this.getState("src")!==t)return;const n=Cu.getTopViewCache(t);if(n)return this._topViewSnapshot=n,void this.invalidate();const i=Cu.renderTopView(e.scene);Cu.setTopViewCache(t,i),this._topViewSnapshot=i,this.invalidate()}).catch(()=>{this._snapshotLoading=!1})}buildRealObject(){return new Cu(this)}get source(){return this.getState("src")}set source(t){this.setState("src",t)}get play(){return!1!==this.getState("play")}set play(t){this.setState("play",t)}get nodes(){return this.getState("nodes")}set nodes(t){this.setState("nodes",t)}get animations(){return this.getState("animations")}set animations(t){this.setState("animations",t)}get playTargets(){return this.getState("playTargets")}set playTargets(t){this.setState("playTargets",t)}get fillStyleTargets(){return this.getState("fillStyleTargets")}set fillStyleTargets(t){this.setState("fillStyleTargets",t)}get nodeNames(){const t=this.realObject;return t?.nodeNames??[]}get animationNames(){const t=this.realObject;return t?.animationNames??[]}set dimension(t){const{width:e=1,height:n=1,depth:i=1}=t;this.setState({width:e,height:n,depth:i}),this.realObject?.updateDimension()}_applyRatioLock(t){if(!("width"in t||"height"in t||"depth"in t))return t;const e=this.state.width||1,n=this.state.height||1,i=this.state.depth||1,s=Cf([(t.width??e)/e,(t.height??n)/n,(t.depth??i)/i]);return s?{...t,width:Math.round(e*s),height:Math.round(n*s),depth:Math.round(i*s)}:t}set(t,e){if("string"==typeof t&&(t={[t]:e}),this.state?.ratioLock&&!this._ratioLocking){this._ratioLocking=!0;try{t=this._applyRatioLock(t)}finally{}}try{return super.set(t)}finally{this._ratioLocking=!1}}setState(t,e){if("string"==typeof t&&(t={[t]:e}),this.state?.ratioLock&&!this._ratioLocking){this._ratioLocking=!0;try{t=this._applyRatioLock(t)}finally{}}try{return super.setState(t)}finally{this._ratioLocking=!1}}}}function Dy(t){return function(e){return Array.isArray(t)?t.forEach(t=>{Cc.register(t,e)}):Cc.register(t,e),e}}function Iy(t){return!!t&&"function"==typeof t.capacity&&"function"==typeof t.available}function zy(t){if(Iy(t)){const e=t.capacity(),n=t.available();return{capacity:e,available:n,isFull:0===n}}if("function"==typeof t?.slotIds){const e=t.slotIds().length,n="function"==typeof t.emptySlotIds?t.emptySlotIds().length:e;return{capacity:e,available:n,isFull:0===n}}const e=t?.state?.capacity,n=Array.isArray(t?.state?.data)?t.state.data.length:0;if("number"==typeof e){const t=Math.max(0,e-n);return{capacity:e,available:t,isFull:0===t}}return{capacity:1/0,available:1/0,isFull:!1}}class Ry{constructor(){this.wasFull=!1,this.availableListeners=[],this.fullListeners=[]}notify(t){const e=0===t;if(e&&!this.wasFull){this.wasFull=!0;for(const t of this.fullListeners)try{t()}catch(t){}}else if(!e&&this.wasFull){this.wasFull=!1;for(const t of this.availableListeners)try{t()}catch(t){}}}onAvailable(t){return this.availableListeners.push(t),()=>{const e=this.availableListeners.indexOf(t);e>=0&&this.availableListeners.splice(e,1)}}onFull(t){return this.fullListeners.push(t),()=>{const e=this.fullListeners.indexOf(t);e>=0&&this.fullListeners.splice(e,1)}}dispose(){this.availableListeners=[],this.fullListeners=[]}}function jy(t,e){if(!t||!e)return()=>{};if("function"!=typeof t.pauseEmit||"function"!=typeof t.resumeEmit)return()=>{};if("function"!=typeof e.onFull||"function"!=typeof e.onAvailable)return()=>{};const n=e.onFull(()=>t.pauseEmit()),i=e.onAvailable(()=>t.resumeEmit());return zy(e).isFull&&t.pauseEmit(),()=>{n?.(),i?.()}}class Ly{constructor(t,e=1,n="horizontal"){this.owner=t,this.itemSpacing=e,this.axis=n}positionAt(t,e,n,i){const s=e.maxCount??1/0;if(t<0||t>=s)return null;const r=this.owner?.state?.width??0,o=this.owner?.state?.height??0,a=i?.state?.width??0,c=i?.state?.height??0;return"horizontal"===this.axis?{x:t*this.itemSpacing,y:Math.max(0,(o-c)/2),z:0}:{x:Math.max(0,(r-a)/2),y:t*this.itemSpacing,z:0}}capacity(t){return t.maxCount??1/0}}function Fy(t,e,n,i,s,r,o){const a=n.w,c=n.h,l=i.w,h=i.h,d=i.d,u=[],p=l+s,f=h+s,m=Math.max(1,Math.floor((a+s)/p)),g=Math.max(1,Math.floor((c+s)/f)),y=m*g,b=r&&r>0?Math.floor(r):4;if("row"===t||"column"===t){const n=o?.advanceAlongX??!1,i=o?.reverse??!1,s=n?m:g,r=n?g:m,l=(t,e,i)=>((t,e,n)=>u.push({x:-a/2+(t+.5)*p,y:n*d+d/2,z:-c/2+(e+.5)*f}))(n?t:e,n?e:t,i);let h=0;for(let n=0;n<s&&h<e;n++){const o=i?s-1-n:n;if("column"===t)for(let t=0;t<r&&h<e;t++)for(let n=0;n<b&&h<e;n++)l(o,t,n),h++;else for(let t=0;t<b&&h<e;t++)for(let n=0;n<r&&h<e;n++)l(o,n,t),h++}return u}if("pyramid"===t){let t=e,n=0;for(;t>0;){const e=Math.max(1,m-n),i=Math.max(1,g-n),s=e*i,o=Math.min(t,s);for(let t=0;t<o;t++){const s=t%e,r=Math.floor(t/e),o=-a/2+(s+(m-e)/2+.5)*p,l=-c/2+(r+(g-i)/2+.5)*f;u.push({x:o,y:n*d+d/2,z:l})}if(t-=o,n++,1===e&&1===i){for(let e=0;e<t;e++)u.push({x:0,y:(n+e)*d+d/2,z:0});break}if(r&&n>=r)break}return u}if("pile"===t){const t=t=>(43758.5453*Math.sin(12.9898*t)%1+1)%1;for(let n=0;n<e;n++){const e=Math.floor(n/y),i=n%y,s=i%m,o=Math.floor(i/m),g=(t(2*n)-.5)*l*.2,b=(t(2*n+1)-.5)*h*.2,_=-a/2+(s+.5)*p+g,v=-c/2+(o+.5)*f+b;if(u.push({x:_,y:e*d+d/2,z:v}),r&&e>=r-1&&i===y-1)break}return u}for(let n=0;n<e;n++){const e=Math.floor(n/y);if(r&&e>=r)break;const i=n%y,s=i%m,o=Math.floor(i/m);let l=-a/2+(s+.5)*p;const h=-c/2+(o+.5)*f;"staggered"===t&&e%2==1&&(l+=p/2),u.push({x:l,y:e*d+d/2,z:h})}return u}class Ny{constructor(t,e={}){this.pattern=t,this.defaults=e}layout(t,e,n,i={}){const s=i.gap??this.defaults.gap??0,r=i.heightLimit??this.defaults.heightLimit,o=i.fill??this.defaults.fill;return Fy(this.pattern,t,e,n,s,r,o).map(t=>({position:t}))}}class Hy{constructor(t,e,n={}){this.cols=t,this.rows=e,this.defaults=n}layout(t,e,n,i={}){const s=Math.max(1,this.cols),r=Math.max(1,this.rows),o=s*r,a=i.gap??this.defaults.gap??0,c=n.w+a,l=n.h+a,h=[];for(let e=0;e<t;e++){const t=Math.floor(e/o),i=e%o,a=i%s,d=Math.floor(i/s);h.push({position:{x:(a-(s-1)/2)*c,z:(d-(r-1)/2)*l,y:t*n.d+n.d/2}})}return h}}class By{constructor(t=.1,e=!1,n=!1){this.gapRatio=t,this.fillFromFar=e,this.sliceFirst=n}grid(t,e){const n=e.w*this.gapRatio,i=e.h*this.gapRatio;return{cols:Math.max(1,Math.floor((t.w-n)/(e.w+n))),rows:Math.max(1,Math.floor((t.h-i)/(e.h+i))),pitchX:e.w+n,pitchZ:e.h+i}}capacity(t,e,n){const{cols:i,rows:s}=this.grid(t,e);return i*s*Math.max(1,Math.floor(n))}layout(t,e,n,i={}){const{cols:s,rows:r,pitchX:o,pitchZ:a}=this.grid(e,n),c=n.d+n.d*this.gapRatio,l=null!=i.heightLimit?Math.max(1,Math.floor(i.heightLimit)):1/0,h=Number.isFinite(l),d=this.sliceFirst&&h,u=s*r,p=s*(h?l:1),f=s*r*(h?l:t),m=Math.min(t,f),g=[];for(let t=0;t<m;t++){let e,i,l;if(d){const n=Math.floor(t/p),r=t%p;e=r%s,l=Math.floor(r/s),i=n}else{l=Math.floor(t/u);const n=t%u;e=n%s,i=Math.floor(n/s)}this.fillFromFar&&(i=r-1-i),g.push({position:{x:(e-(s-1)/2)*o,z:(i-(r-1)/2)*a,y:l*c+n.d/2}})}return g}}function Yy(t,e,n,i=0){for(let s=0;s<e.length;s++){const r=e[s],o=n[s];r&&o&&(r.parent!==t&&t.attach(r),r.position.set(o.position.x,i+o.position.y,o.position.z),o.rotation?r.quaternion.set(o.rotation.x,o.rotation.y,o.rotation.z,o.rotation.w):r.quaternion.identity())}}function Vy(t,e,n,i=.12){const s=e.left+e.width/2,r=e.top+e.height/2,o=Math.min(n.w,n.h)*i,a=new Map;for(const e of t){const t=`${Math.round(e.position.x)},${Math.round(e.position.z)}`;let i=a.get(t);i||(i={x:s+e.position.x-n.w/2+o,y:r+e.position.z-n.h/2+o,w:n.w-2*o,h:n.h-2*o,count:0},a.set(t,i)),i.count++}return[...a.values()]}function Gy(t){return{id:t?.state?.id??t?.id??t?.refid,type:t?.state?.type??t?.type}}const $y=new t.Euler;function Uy(e,n){$y.setFromQuaternion(new t.Quaternion(n.x,n.y,n.z,n.w),"YXZ"),e.rotationX=$y.x,e.rotation=-$y.y,e.rotationY=$y.z}const Wy="_transferSlotId",qy=new Set(["left","top","width","height","depth","zPos","rotation","rotationX","rotationY","rotationZ","scale","translate","material3d","fillStyle","strokeStyle","lineWidth","lineDash","alpha","opacity","hidden","text","fontColor","fontSize","fontFamily","bold","italic","textAlign","textBaseline","shadow","border","cssText","object3d","_realObject","refid","id"]);function Xy(t){return class extends t{async ready(){await super.ready();const t=this.state?.data;Array.isArray(t)&&0===this._items.length&&!this.isRecordStorage&&this._reconcileItems(t)}set data(t){if(Array.isArray(t)){if(this.isRecordStorage){const e=this.setState;return void("function"==typeof e&&e.call(this,{data:t}))}this._reconcileItems(t)}else this.setState?.({data:t})}get data(){if(this.isRecordStorage)return this.state?.data??[];const t=this._exportSlotRecords();return 0===t.length?this.state?.data:t}_reconcileItems(t){const e=new Map;for(const n of t){const t=this._recordKey(n);t&&e.set(t,n)}const n=new Map;for(const t of this._items){const e=t[Wy];null!=e&&n.set(String(e),t)}for(const[t,i]of n)if(!e.has(t)){try{this.removeItem(i,!0)}catch{}try{i?.dispose?.()}catch{}}for(const[t,i]of e){if(n.has(t))continue;if(null==i.itemId)continue;const e=this._createItemFromRecord(i);if(e){e[Wy]=t;try{this.handoverIn(e)}catch{}}}for(const[t,i]of e){const e=n.get(t);if(e&&(i.itemState&&"function"==typeof e.setState))try{e.setState(i.itemState)}catch{}}}_exportSlotRecords(){const t=this.slotIds?.()??[],e=[],n=new Map,i=[];for(const t of this._items){const e=t[Wy];null!=e?n.set(String(e),t):i.push(t)}for(const i of t){const t=n.get(i)??null;e.push(this._slotRecordOf(i,t))}for(const t of i)e.push(this._slotRecordOf("",t));for(const[i,s]of n)t.includes(i)||e.push(this._slotRecordOf(i,s));return e}_recordKey(t){return t.slotId??t.cellId??""}_slotRecordOf(t,e){if(!e)return{slotId:t,itemId:null};const n=e?.state?.id;return{slotId:t,itemId:null!=n?String(n):null,itemType:e?.state?.type,itemState:this._extractItemState(e)}}_extractItemState(t){const e=t?.state;if(!e||"object"!=typeof e)return;const n=this._businessFields?.();if(Array.isArray(n)){if(0===n.length)return;const t={};for(const i of n)i in e&&void 0!==e[i]&&(t[i]=e[i]);return Object.keys(t).length>0?t:void 0}const i={};for(const t of Object.keys(e))qy.has(t)||t.startsWith("_")||(i[t]=e[t]);return Object.keys(i).length>0?i:void 0}_businessFields(){return null}_createItemFromRecord(t){const e=t.itemType??t.type;if(!e)return null;try{const n=Cc.register?.(e);if(n&&"function"==typeof n){return new n({type:e,...t.itemState??{}})}}catch{}return null}}}class Ky{positionAt(t,e,n){return 0!==t?null:e.localPosition??{x:0,y:0,z:0}}capacity(t){return 1}}const Qy=new Ky,Zy=[{id:"__default__",maxCount:1/0}];function Jy(e){var n;return n=class extends e{get slots(){return[]}get arrangementStrategy(){return Qy}canReceive(t,e){const n=null!==this.findSlot(t);return Yu.log({role:"target",contract:"canReceive",component:this,args:{carrier:Gy(t)},result:n}),n}findSlot(t){const e=this.slots.length?this.slots:Zy;for(const n of e){if(n.allowedTypes?.length){const e=t?.state?.type??t?.type;if(!e||!n.allowedTypes.includes(e))continue}const e=n.maxCount??this.arrangementStrategy.capacity(n),i=this._countOccupied(n.id);if(!(i>=e))return Yu.log({role:"target",contract:"findSlot",component:this,args:{carrier:Gy(t)},result:{slotId:n.id,occupied:i,max:e}}),n}return Yu.log({role:"target",contract:"findSlot",component:this,args:{carrier:Gy(t)},result:null}),null}acceptanceRotation(t,e){}deliveryWorldRotation(e){const n=this.acceptanceRotation?.(e);if(!n)return;const i=this._realObject?.object3d;if(!i)return;i.updateWorldMatrix(!0,!1);const s=new t.Quaternion;i.getWorldQuaternion(s);const r=new t.Quaternion(n.x,n.y,n.z,n.w);return s.clone().multiply(r)}deliveryWorldPosition(e){const n=this._realObject,i=n?.object3d;if(!i)return;i.updateWorldMatrix(!0,!1);const s=new t.Vector3;i.getWorldPosition(s);const r=this._receivingSurfaceLocalY();if(null!==r){const e=new t.Vector3(0,r,0);return i.localToWorld(e),{x:s.x,y:e.y,z:s.z}}return{x:s.x,y:s.y,z:s.z}}attachPointFor(t){const e=t?.[Wy];if(!e)return null;const n=this.slots.find(t=>t.id===e);return n?{position:n.localPosition??{x:0,y:0,z:0},rotation:n.localRotation??{x:0,y:0,z:0},slotId:n.id}:null}placementFor(t,e={}){const n=t&&"object"==typeof t&&"state"in t?t:void 0,i=n?n.state??{}:t??{},s={width:Number(i.width)||0,height:Number(i.height)||0,depth:Number(i.depth)||0},r=e.slot??this.slots.find(t=>{const e=t.maxCount??this.arrangementStrategy.capacity(t);return this._countOccupied(t.id)<e});if(!r)return null;const o=e.index??this._countOccupied(r.id),a=e.occupantCount??o,c=this.arrangementStrategy.positionAt(o,r,a,n??{state:{...s}});if(!c)return null;const l=Number(this.state?.width)||0,h=Number(this.state?.height)||0,d=c.x+s.width/2-l/2,u=c.y+s.height/2-h/2,p=this._realObject,f=p?.placementMode??"floor",m="space"===f?0:"inverted"===f?-s.depth/2:s.depth/2,g=this._receivingSurfaceLocalY();let y;y=null!==g?g+m:r.localPosition&&Number.isFinite(r.localPosition.z)?r.localPosition.z+m:m-(p?.geometricOffsetY??0);const b=this.acceptanceRotation?.(n??s,r)??void 0;return b?{position:{x:d,y:y,z:u},rotation:b}:{position:{x:d,y:y,z:u}}}_zPosFromSeatY(t,e,n){const i=this._realObject,s=i?.receivingSurfaceY??0,r=!(!n.localPosition||!Number.isFinite(n.localPosition.z));if(0===s&&!r)return null;const o=Number(e)||0,a=i?.placementMode??"floor";return t-("space"===a?0:"inverted"===a?-o/2:o/2)+(i?.geometricOffsetY??0)-s}_receivingSurfaceLocalY(){const t=this._realObject,e=t?.receivingSurfaceY;return"number"!=typeof e||0===e?null:e-(t.geometricOffsetY??0)}_countOccupied(t){const e=this._items;if(e)return e.filter(e=>e?.[Wy]===t).length;const n=this.components;return n?n.filter(e=>e.parent===this&&e[Wy]===t).length:0}},n.__hasCapacity=!0,n}function tb(t,e){const n=t.left??0,i=t.top??0,s=t.width??0,r=t.height??0;if(s<=0||r<=0)return[];const o="number"==typeof t.rotation?t.rotation:0,a=Math.cos(o),c=Math.sin(o),l=n+s/2,h=i+r/2,d="inbound"===e?-1:1;return[{lx:-s/2,lz:0,odx:-1,odz:0},{lx:s/2,lz:0,odx:1,odz:0},{lx:0,lz:-r/2,odx:0,odz:-1},{lx:0,lz:r/2,odx:0,odz:1}].map(t=>{var e,n;return{worldPos:(e=t.lx,n=t.lz,{x:l+e*a-n*c,z:h+e*c+n*a}),direction:{x:d*(t.odx*a-t.odz*c),z:d*(t.odx*c+t.odz*a)},halfSpan:0!==t.odx?r/2:s/2}})}function eb(t,e){const n=t.left??0,i=t.top??0,s=t.width??0,r=t.height??0;if(s<=0||r<=0)return{inbounds:[],outbounds:[]};const o="number"==typeof t.rotation?t.rotation:0,a=e??"reverse"===t.status,c="vertical"===t.orientation||"horizontal"!==t.orientation&&s<r,l=n+s/2,h=i+r/2,d=c?r/2:s/2,u=c?0:1,p=c?1:0,f=Math.cos(o),m=Math.sin(o),g=(t,e)=>({x:l+t*f-e*m,z:h+t*m+e*f}),y=c?{lx:0,lz:-d}:{lx:-d,lz:0},b=c?{lx:0,lz:d}:{lx:d,lz:0},_=g(y.lx,y.lz),v=g(b.lx,b.lz),x={x:u*f-p*m,z:u*m+p*f},w=Math.hypot(x.x,x.z)||1,M={x:x.x/w,z:x.z/w},S={x:-M.x,z:-M.z},k=(c?s:r)/2;return a?{inbounds:[{worldPos:v,direction:S,halfSpan:k}],outbounds:[{worldPos:_,direction:S,halfSpan:k}]}:{inbounds:[{worldPos:_,direction:M,halfSpan:k}],outbounds:[{worldPos:v,direction:M,halfSpan:k}]}}function nb(t){const e=t.left??0,n=t.top??0,i=t.width??0,s=t.height??0;if(i<=0||s<=0)return null;const r="number"==typeof t.rotation?t.rotation:0,o="vertical"===t.orientation||"horizontal"!==t.orientation&&i<s,a=e+i/2,c=n+s/2,l=o?s/2:i/2,h=Math.cos(r),d=Math.sin(r),u=(t,e)=>({x:a+t*h-e*d,z:c+t*d+e*h});return{start:o?u(0,-l):u(-l,0),end:o?u(0,l):u(l,0)}}function ib(t){const e=t.cx??0,n=t.cy??0,i=Math.abs(t.rx??100),s=Math.abs(t.ry??100),r=t.ratio??50,o=(i+i*r/100)/2,a=(s+s*r/100)/2,c=t.startAngle??0,l=t.endAngle??Math.PI/2,h="reverse"===t.status;if(i<=0||s<=0)return{inbounds:[],outbounds:[]};const d={x:e+o*Math.sin(c),z:n-a*Math.cos(c)},u={x:e+o*Math.sin(l),z:n-a*Math.cos(l)},p={x:Math.cos(c),z:Math.sin(c)},f={x:Math.cos(l),z:Math.sin(l)};return h?{inbounds:[{worldPos:u,direction:{x:-f.x,z:-f.z}}],outbounds:[{worldPos:d,direction:{x:-p.x,z:-p.z}}]}:{inbounds:[{worldPos:d,direction:p}],outbounds:[{worldPos:u,direction:f}]}}function sb(t){const e=eb(t),n=e.outbounds[0];if(!n)return{inbounds:tb(t,"inbound"),outbounds:[]};const i=tb(t,"inbound").filter(t=>{const e=t.worldPos.x-n.worldPos.x,i=t.worldPos.z-n.worldPos.z;return Math.hypot(e,i)>1}),s=n.direction,r=[];for(const t of i){const e=t.direction.x*s.x+t.direction.z*s.z;if(Math.abs(e)>=.1)continue;const n=t.direction.x+s.x,i=t.direction.z+s.z,o=Math.hypot(n,i)||1;r.push({worldPos:t.worldPos,direction:{x:n/o,z:i/o},halfSpan:t.halfSpan})}return{inbounds:[...i,...r],outbounds:e.outbounds}}function rb(t,e,n={}){const i=n.distance??5,s=n.cosine??.9;if(t.direction.x*e.direction.x+t.direction.z*e.direction.z<s)return!1;const r=t.worldPos.x-e.worldPos.x,o=t.worldPos.z-e.worldPos.z;if("number"==typeof t.halfSpan&&"number"==typeof e.halfSpan){const n=t.direction.x,s=t.direction.z;if(Math.abs(r*n+o*s)>i)return!1;const a=Math.abs(r*-s+o*n);return t.halfSpan+e.halfSpan-a>0}return Math.hypot(r,o)<=i}function ob(t,e,n,i=0){const s=n.width??0,r=n.height??0;if(s<=0||r<=0)return!1;const o=(n.left??0)+s/2,a=(n.top??0)+r/2,c="number"==typeof n.rotation?n.rotation:0,l=Math.cos(-c),h=Math.sin(-c),d=t-o,u=e-a,p=d*l-u*h,f=d*h+u*l;return Math.abs(p)<=s/2+i&&Math.abs(f)<=r/2+i}function ab(t,e,n){const i=n.width??0,s=n.height??0;if(i<=0||s<=0)return 1/0;const r=(n.left??0)+i/2,o=(n.top??0)+s/2;let a=t.x-r,c=t.z-o,l=e.x,h=e.z;const d="number"==typeof n.rotation?n.rotation:0;if(0!==d){const t=Math.cos(-d),e=Math.sin(-d),n=a*e+c*t,i=l*e+h*t;a=a*t-c*e,c=n,l=l*t-h*e,h=i}const u=i/2,p=s/2;let f=-1/0,m=1/0;if(Math.abs(l)<1e-9){if(a<-u||a>u)return 1/0}else{const t=(-u-a)/l,e=(u-a)/l;f=Math.max(f,Math.min(t,e)),m=Math.min(m,Math.max(t,e))}if(Math.abs(h)<1e-9){if(c<-p||c>p)return 1/0}else{const t=(-p-c)/h,e=(p-c)/h;f=Math.max(f,Math.min(t,e)),m=Math.min(m,Math.max(t,e))}return m<f?1/0:f>=0?f:m>=0?Math.min(-f,m):-m}function cb(t,e,n,i=6){return!!ob(t.worldPos.x,t.worldPos.z,e,i)&&(!n||t.direction.x*n.x+t.direction.z*n.z>=0)}function lb(t,e,n){return t.outbounds.map(t=>{const i=[];for(const s of e){let e=null;for(const i of s.topology.inbounds){if(!rb(t,i,n))continue;const s=t.worldPos.x-i.worldPos.x,r=t.worldPos.z-i.worldPos.z,o=Math.hypot(s,r);(null===e||o<e)&&(e=o)}if(null===e&&s.bounds){const i=s.topology.outbounds[0]?.direction,r=!(s.topology.outbounds&&s.topology.outbounds.length)?n?.sinkMargin??30:6;if(cb(t,s.bounds,i,r)){const n=ab(t.worldPos,t.direction,s.bounds);if(Number.isFinite(n))e=n+1e3;else{const n=(s.bounds.left??0)+(s.bounds.width??0)/2,i=(s.bounds.top??0)+(s.bounds.height??0)/2;e=Math.hypot(t.worldPos.x-n,t.worldPos.z-i)+1e3}}}null!==e&&i.push({id:s.id,dist:e})}return 0===i.length?null:(i.sort((t,e)=>t.dist-e.dist||(t.id<e.id?-1:1)),i[0].id)})}function hb(t,e){const n=new Map;for(const e of t)n.set(e.id,e);const i=new Map,s=new Set;for(const n of t){const r=t.filter(t=>t.id!==n.id),o=lb(n.topology,r,e);i.set(n.id,o);for(const t of o)null!=t&&s.add(t)}const r=(t,e)=>{if(!n.has(t)||!n.has(e)||t===e)return;const r=i.get(t)??[];r.includes(e)||(r.push(e),i.set(t,r),s.add(e))};for(const e of t)if(e.links){for(const t of e.links.downstream??[])r(e.id,t);for(const t of e.links.upstream??[])r(t,e.id)}const o=new Set,a=new Set;for(const e of t){(i.get(e.id)??[]).some(t=>null!=t)||o.add(e.id),s.has(e.id)||a.add(e.id)}return{nodes:n,out:i,sinks:o,sources:a}}function db(t,e){const n=new Map;return(t.out.get(e)??[]).map(e=>{if(null==e)return new Set;const i=new Set([e]);for(const s of function(t,e,n){const i=n.get(e);if(i)return i;const s=new Set,r=[e],o=new Set([e]);for(;r.length;){const e=r.shift();for(const n of t.out.get(e)??[])null!=n&&(s.add(n),o.has(n)||(o.add(n),r.push(n)))}return n.set(e,s),s}(t,e,n))i.add(s);return i})}function ub(t,e,n,i){return e===n?0:function(t,e,n){const i=n.get(e);if(i)return i;const s=new Map([[e,0]]),r=[e];for(;r.length;){const e=r.shift(),n=s.get(e);for(const i of t.out.get(e)??[])null==i||s.has(i)||(s.set(i,n+1),r.push(i))}return n.set(e,s),s}(t,e,i).get(n)??1/0}function pb(t,e,n){const i=t.out.get(e)??[],s=new Map,r=[];for(let e=0;e<i.length;e++){const o=i[e];if(null==o)continue;const a=o===n?0:ub(t,o,n,s);a!==1/0&&r.push({i:e,hops:1+a})}return r.sort((t,e)=>t.hops-e.hops||t.i-e.i),r.map(t=>t.i)}function fb(t,e,n){const i=pb(t,e,n);return i.length?i[0]:-1}function mb(t,e,n){return e===n||pb(t,e,n).length>0}function gb(t,e){const n=new Set;for(const i of db(t,e))for(const e of i)t.sinks.has(e)&&n.add(e);return n}function yb(t,e,n){return bb(t,e,n).map(t=>t.index)}function bb(t,e,n){const i=n instanceof Set?n:new Set(n);if(0===i.size)return[];const s=t.out.get(e)??[],r=new Map,o=[...i].sort(),a=[];for(let e=0;e<s.length;e++){const n=s[e];if(null==n)continue;let i=1/0,c="";for(const e of o){const s=1+(n===e?0:ub(t,n,e,r));s<i&&(i=s,c=e)}i!==1/0&&a.push({index:e,hops:i,target:c})}return a.sort((t,e)=>t.hops-e.hops||t.index-e.index),a}function _b(t,e={}){const n=[],i=e.loopCapableIds??new Set,s=e.routingTargetIds??new Set;for(const e of[...t.sources].sort()){const i=t.nodes.get(e);if(!i||!i.topology.outbounds?.length)continue;(t.out.get(e)??[]).some(t=>null!=t)||n.push({severity:"error",code:"orphan-source",nodeId:e,message:`source 노드 "${e}" 가 outgoing edge 0 — 아무 데도 carrier 를 보낼 수 없음`})}for(const e of[...t.nodes.keys()].sort()){(t.out.get(e)??[]).some(t=>null!=t)||(s.has(e)||t.sources.has(e)||n.push({severity:"error",code:"dead-end",nodeId:e,message:`노드 "${e}" 가 outgoing 0 인데 RoutingTarget 자격 없음 — routing 미정의 종착`}))}const r=function(t){const e=[],n=[...t.nodes.keys()].sort(),i=new Set,s=[],r=new Set,o=n=>{i.add(n),s.push(n),r.add(n);for(const a of t.out.get(n)??[])if(null!=a)if(r.has(a)){const t=s.indexOf(a),n=s.slice(t),i=n.indexOf([...n].sort()[0]),r=[...n.slice(i),...n.slice(0,i)],o=r.join("→");e.some(t=>t.join("→")===o)||e.push(r)}else i.has(a)||o(a);s.pop(),r.delete(n)};for(const t of n)i.has(t)||o(t);return e.sort((t,e)=>t[0].localeCompare(e[0])||t.length-e.length),e}(t);for(const t of r){const e=t.some(t=>i.has(t));e||n.push({severity:"error",code:"cycle",cycle:t,message:`의도 cycle 자격 (isLoop) 없는 cycle: ${t.join(" → ")} → ${t[0]}`})}const o=e.routingWeights;if(o)for(const[t,e]of[...o].sort((t,e)=>t[0].localeCompare(e[0])))(!Number.isFinite(e)||e<=0)&&n.push({severity:"warning",code:"invalid-weight",nodeId:t,message:`RoutingTarget "${t}" 의 routingWeight=${e} — weight ≤ 0 비정상, weight 정책에서 제외됨`});const a=new Set;for(const e of t.out.values())for(const t of e)null!=t&&a.add(t);for(const e of[...s].sort())t.nodes.has(e)&&(a.has(e)||n.push({severity:"warning",code:"unreachable-target",nodeId:e,message:`RoutingTarget "${e}" 에 incoming edge 0 — 누구도 이쪽으로 carrier 를 보내지 않음`}));return n.sort((t,e)=>t.code!==e.code?t.code.localeCompare(e.code):(t.nodeId??"").localeCompare(e.nodeId??"")),n}function vb(t,e){if(!t)return[];const n=[],i=new Set,s=t=>{if(!t||i.has(t))return;if(i.add(t),t!==e&&"function"==typeof t?.getSegmentTopology){const e=t.state?.id,i=t.refid??t.state?.refid,s="string"==typeof e&&e.length>0?e:null!=i?String(i):void 0;if(s)try{const e=t.getSegmentTopology(),i=t.state??{},r={left:i.left,top:i.top,width:i.width,height:i.height,rotation:i.rotation};e&&n.push({id:s,topology:e,bounds:r})}catch{}}const r=t?.components;if(Array.isArray(r))for(const t of r)s(t)};return s(t),n}function xb(t,e){const n=t.state?.targetRef??t.state?.downstreamRef;if("string"==typeof n&&n.length>0)return n;if("function"!=typeof t.getSegmentTopology)return null;const i=t.getSegmentTopology();if(!i||0===i.outbounds.length)return null;const s=lb(i,vb(t.parent??t.rootModel??t.root,t).filter(t=>t.topology.inbounds.length>0),e);for(const t of s)if(t)return t;return null}function wb(t){return!!t&&"function"==typeof t.routingConstraints}function Mb(t){return!!t&&"function"==typeof t.acceptedCarrierData}function Sb(t,e=16){const n=[],i=t.parent??t.rootModel??t.root;if(!i)return n;const s=xb(t);if(!s)return n;const r=Eb(i,s);if(!r)return n;const o=[{segment:r,accumulated:{},pathIds:[s],visited:new Set([s])}];for(;o.length>0;){const t=o.shift();if(t.pathIds.length>e)continue;const s=wb(t.segment)?t.segment.routingConstraints():null;if(s&&s.length>0)for(const e of s)for(const s of e.candidates){const r=kb(t.accumulated,s);if(!r)continue;const a=Ab(t.segment,e.portId,i);a&&!t.visited.has(a.state?.id??"")?o.push({segment:a,accumulated:r,pathIds:[...t.pathIds,a.state?.id??"?"],visited:new Set([...t.visited,a.state?.id??""])}):n.push({data:r,weight:1,pathIds:[...t.pathIds,`${e.portId}`],destination:e.portId})}else{if(Mb(t.segment)){const e=t.segment.acceptedCarrierData(),i=t.segment.state?.id;if(0===e.length)n.push({data:t.accumulated,weight:1,pathIds:t.pathIds,destination:i});else for(const s of e){const e=kb(t.accumulated,s);e&&n.push({data:e,weight:1,pathIds:t.pathIds,destination:i})}continue}const e=xb(t.segment);if(!e||t.visited.has(e)){n.push({data:t.accumulated,weight:1,pathIds:t.pathIds,destination:t.pathIds[t.pathIds.length-1]});continue}const s=Eb(i,e);if(!s)continue;o.push({segment:s,accumulated:t.accumulated,pathIds:[...t.pathIds,e],visited:new Set([...t.visited,e])})}}return n}function kb(t,e){const n={...t};for(const[t,i]of Object.entries(e)){if(t in n&&n[t]!==i)return null;n[t]=i}return n}function Ab(t,e,n){if("straight"===e&&t.state?.downstreamRef)return Eb(n,t.state.downstreamRef);const i=Eb(n,e);if(i)return i;const s=xb(t);return s?Eb(n,s):null}function Eb(t,e){if(!t||!e)return null;if("function"==typeof t.findById)return t.findById(e);const n=new Set,i=t=>{if(!t||n.has(t))return null;if(n.add(t),t.state?.id===e)return t;const s=t.components;if(Array.isArray(s))for(const t of s){const e=i(t);if(e)return e}return null};return i(t)}function Cb(t,e){return Math.hypot(t.x-e.x,t.z-e.z)}function Tb(t,e,n=5,i=[],s=n){const r=t.length,o=new Array(r).fill(void 0),a=new Set,c=(e,n)=>"start"===n?t[e].start:t[e].end,l=[],h=new Map,d=[],u=new Map;for(const t of i){const e=Array.isArray(t),n=e?t:t.positions,i=e?void 0:t.kind;if(!n.length)continue;const s=l.length;l.push({pos:n[0],members:[]});for(const t of n)d.push({pos:t,pt:s});i&&u.set(s,i)}const p=(t,e)=>{const i=c(t,e),s=h.get(`${t}:${"end"===e?"start":"end"}`),r=[];for(const t of d)Cb(t.pos,i)<=n&&!r.includes(t.pt)&&r.push(t.pt);for(let t=0;t<l.length;t++)Cb(l[t].pos,i)<=n&&!r.includes(t)&&r.push(t);let o=r.find(t=>t!==s)??-1;o<0&&(o=l.length,l.push({pos:i,members:[]})),l[o].members.push({seg:t,end:e}),h.set(`${t}:${e}`,o)};for(let t=0;t<r;t++)p(t,"start"),p(t,"end");const f=new Set,m=new Set,g=new Set;{const t=t=>{let e=-1,n=1/0;for(let i=0;i<l.length;i++){const s=Cb(l[i].pos,t);s<n&&(n=s,e=i)}for(const i of d){const s=Cb(i.pos,t);s<n&&(n=s,e=i.pt)}return{pt:e,d:n}};for(const n of e){const{pt:e,d:i}=t(n.pos);e>=0&&i<=s&&(f.add(e),("source"===n.kind?m:g).add(e))}}for(const[t,e]of u)f.add(t),("source"===e?m:g).add(t);const y=(t,e)=>"end"===e!==o[t],b=[],_=(e,n)=>{if(void 0===o[e])return o[e]=n,void b.push(e);o[e]!==n&&a.add(t[e].id)},v=t=>{for(const e of["start","end"]){const n=h.get(`${t}:${e}`);if(void 0===n)continue;const i=l[n];if(2!==i.members.length||f.has(n))continue;const s=i.members[0],r=s.seg===t&&s.end===e?i.members[1]:s;if(r.seg===t)continue;const a="end"===e!==o[t],c="end"===r.end!==!a;_(r.seg,c)}},x=()=>{for(;b.length;)v(b.shift())},w=t=>{let e=-1,n="start",i=1/0;for(let s=0;s<r;s++)for(const r of["start","end"]){const o=Cb(c(s,r),t.pos);o<i&&(i=o,e=s,n=r)}if(e<0||i>s)return;const o="source"===t.kind?"end"===n:"start"===n;_(e,o)};for(const t of e)"source"===t.kind&&w(t);x();for(const t of e)"sink"===t.kind&&w(t);x();let M=!0;for(;M;){M=!1;for(const t of l){if(t.members.length<3)continue;const e=t.members.filter(t=>void 0===o[t.seg]);if(1!==e.length)continue;let n=0,i=0;for(const e of t.members)void 0!==o[e.seg]&&(y(e.seg,e.end)?n++:i++);const s=e[0];let r;0===i&&n>0?r="end"===s.end:0===n&&i>0&&(r="start"===s.end),void 0!==r&&(o[s.seg]=r,b.push(s.seg),x(),M=!0)}}if(o.some(t=>void 0===t)&&m.size>0&&g.size>0){const t=t=>{const e=new Array(l.length).fill(1/0),n=[];for(const i of t)e[i]=0,n.push(i);for(;n.length;){const t=n.shift();for(const i of l[t].members){const s=h.get(`${i.seg}:${"start"===i.end?"end":"start"}`);void 0!==s&&e[s]>e[t]+1&&(e[s]=e[t]+1,n.push(s))}}return e},e=t(m),n=t(g);for(let t=0;t<r;t++){if(void 0!==o[t])continue;const i=h.get(`${t}:start`),s=h.get(`${t}:end`);if(void 0===i||void 0===s)continue;if(l[i].members.length<2||l[s].members.length<2)continue;if(e[i]===1/0||e[s]===1/0||n[i]===1/0||n[s]===1/0)continue;let r;e[i]!==e[s]?r=e[i]<e[s]:n[i]!==n[s]&&(r=n[s]<n[i]),void 0!==r&&(o[t]=!r,b.push(t))}x()}const S=new Map;for(let e=0;e<r;e++)S.set(t[e].id,void 0===o[e]?"unknown":o[e]?"reverse":"forward");return{directions:S,conflicts:[...a]}}function Pb(...t){}function Ob(t){return String(t?.state?.id??t?.refid??t?.state?.refid??"?")}function Db(t){const e=t?.state?.id;if("string"==typeof e&&e.length>0)return e;const n=t?.refid??t?.state?.refid;return null!=n?String(n):void 0}function*Ib(t){if(!t)return;("function"==typeof t.getSegmentTopology||t.flowOrientable)&&(yield t);const e=t.components;if(Array.isArray(e))for(const t of e)yield*Ib(t)}function zb(t,e,n){const i=e.width??0,s=e.height??0;if(i<=0||s<=0)return!1;const r=(e.left??0)+i/2,o=(e.top??0)+s/2,a="number"==typeof e.rotation?e.rotation:0,c=t.x-r,l=t.z-o,h=Math.cos(-a),d=Math.sin(-a),u=c*h-l*d,p=c*d+l*h;return Math.abs(u)<=i/2+n&&Math.abs(p)<=s/2+n}function Rb(t){const e=[],n=[],i=[],s=[];for(const r of Ib(t)){const t=Db(r);if(!t)continue;if(r.flowOrientable){const n=nb(r.state??{});n&&e.push({id:t,start:n.start,end:n.end});continue}if("function"==typeof r.openings){const t=r.state??{};(t.width??0)>0&&(t.height??0)>0&&s.push(t);continue}let o;try{o=r.getSegmentTopology()}catch{continue}if(!o)continue;const a=o.inbounds??[],c=o.outbounds??[],l="function"==typeof r.routingDestination;if(0===a.length&&c.length>0)for(const t of c)n.push({pos:{x:t.worldPos.x,z:t.worldPos.z},kind:"source"});else if(a.length>0&&(0===c.length||l))for(const t of a)n.push({pos:{x:t.worldPos.x,z:t.worldPos.z},kind:"sink"});else if(a.length>0||c.length>0){const t=[];for(const e of a)t.push({x:e.worldPos.x,z:e.worldPos.z});for(const e of c)t.push({x:e.worldPos.x,z:e.worldPos.z});t.length&&i.push({positions:t})}}for(const t of s){const s=[];for(const n of e)for(const e of[n.start,n.end])zb(e,t,16)&&s.push(e);let r=!1,o=!1;for(const e of n)zb(e.pos,t,16)&&("sink"===e.kind?r=!0:o=!0);const a=r&&!o?"sink":o&&!r?"source":void 0;(s.length>=2||a&&s.length>=1)&&i.push({positions:s,kind:a})}if(0===e.length||0===n.length)return new Map;return Tb(e,n,8,i,60).directions}function jb(t){const e=t?.root;if(!e)return;if(e.__flowComputing)return;let n=e.__flowOrientation;if(!n){e.__flowComputing=!0;try{n={map:Rb(e)}}finally{e.__flowComputing=!1}e.__flowOrientation=n}const i=Db(t),s=i?n.map.get(i):void 0;return"reverse"===s||"forward"!==s&&void 0}function Lb(t){return!!t&&"function"==typeof t.distanceToBoardPoint}function Fb(t,e,n,i){if(!t||!e)return null;const s=[],r=t=>{if(!t||t===i)return;if(Hm(t,e)&&Lb(t)){const e=function(t){const e=t?.state?.id;if("string"==typeof e&&e.length>0)return e;const n=t?.refid??t?.state?.refid;return null!=n?String(n):void 0}(t);e&&s.push({id:e,component:t,distance:t.distanceToBoardPoint(n.x,n.y)})}const o=t.components;if(Array.isArray(o))for(const t of o)r(t)};return r(t),0===s.length?null:(s.sort((t,e)=>t.distance-e.distance||t.id.localeCompare(e.id)),s[0])}function Nb(t){return!!t&&"function"==typeof t.routingDestination}function Hb(t){const e=t?.state?.id;if("string"==typeof e&&e.length>0)return e;const n=t?.refid??t?.state?.refid;return null!=n?String(n):void 0}function*Bb(t){if(!t)return;yield t;const e=t.components;if(Array.isArray(e))for(const t of e)yield*Bb(t)}function Yb(t){const e=[],n=new Map,i=new Map,s=new Set,r=[];for(const o of Bb(t)){"function"==typeof o?.registerWithHost&&r.push(o);const t="function"==typeof o?.getSegmentTopology,a="function"==typeof o?.routingLinks?o.routingLinks():void 0,c=!(!a||!((a.downstream?.length??0)>0||(a.upstream?.length??0)>0));if(!(t||Nb(o)||c||Lb(o)))continue;const l=Hb(o);if(!l)continue;let h={inbounds:[],outbounds:[]};if(t){try{h=o.getSegmentTopology()}catch{continue}if(!h)continue}const d=o.state??{},u={left:d.left,top:d.top,width:d.width,height:d.height,rotation:d.rotation};if(e.push({id:l,topology:h,bounds:u,links:a}),i.set(l,o),Nb(o)){s.add(l);const t=o.routingDestination();if("string"==typeof t&&t.length>0){const e=n.get(t)??[];e.push(l),n.set(t,e)}}}return{nodes:e,destToSinks:n,components:i,routingTargetIds:s,stationClients:r}}function Vb(t){if(!t)return null;let e=t.__flowGraph;if(!e){const{nodes:n,destToSinks:i,components:s,routingTargetIds:r,stationClients:o}=Yb(t),a=hb(n);!function(t,e){if(!t)return;const n=t=>{if(!t)return;"function"==typeof t.clearStations&&t.clearStations();const e=t.components;if(Array.isArray(e))for(const t of e)n(t)};n(t);const i=[...e].sort((t,e)=>{const n=Hb(t)??"",i=Hb(e)??"";return n.localeCompare(i)});for(const e of i){const n=e.declaredHostRef?.();let i=null;if(n&&(i=t.findById?.(n)??null),!i){const n=e.hostCapability?.(),s=e.hostFacingPoint?.();n&&s&&(i=Fb(t,n,s,e)?.component??null)}i&&"function"==typeof e.registerWithHost&&e.registerWithHost(i)}const s=e=>{if(!e)return;if(Lb(e)&&"function"==typeof e.resolveDownstream&&"function"==typeof e.registerDivertStation)for(const n of e.resolveDownstream()){const i=t.findById?.(n);i&&e.registerDivertStation(n,i)}const n=e.components;if(Array.isArray(n))for(const t of n)s(t)};s(t)}(t,o);const c=new Set;for(const[t,e]of s){((e?.state?.type??e?.model?.type??"").includes("loop")||!0===e?.isLoop)&&c.add(t)}const l=new Map;for(const t of r){const e=s.get(t);if("function"==typeof e?.routingWeight){const n=e.routingWeight();"number"==typeof n&&(!Number.isFinite(n)||n<=0)&&l.set(t,n)}}const h=_b(a,{routingTargetIds:r,loopCapableIds:c,routingWeights:l});if(h.length>0&&"undefined"!=typeof console){const t=h.filter(t=>"error"===t.severity),e=h.filter(t=>"warning"===t.severity);t.length>0?console.warn(`[FlowGraph] ${t.length} error(s) / ${e.length} warning(s):`,h):console.info(`[FlowGraph] ${e.length} warning(s):`,h)}e={graph:a,destToSinks:i,components:s,issues:h},t.__flowGraph=e}return e}function Gb(t){return Vb(t)?.issues??[]}function $b(t){const e=Vb(t);return e&&e.graph.nodes.size>0?e.graph:null}function Ub(t,e){return Vb(t)?.destToSinks.get(e)??[]}function Wb(t,e){return Vb(t)?.components.get(e)}function qb(t){const e=Vb(t);return e?[...e.destToSinks.keys()]:[]}function Xb(t){return Hb(t)}function Kb(t){const e="number"==typeof t?.inventoryCount?t.inventoryCount:"function"==typeof t?.size?t.size():0,n=t?.state?.capacity;return"number"==typeof n&&n>0?e/n:e}function Qb(t,e,n,i,s){if(1===i.length)return i[0];switch(t){case"index":default:return i[0];case"round-robin":{const t=n.counters.get(e)??0;return n.counters.set(e,t+1),i[t%i.length]}case"weight":{const t=i.map(t=>function(t){if("function"==typeof t?.routingWeight){const e=t.routingWeight();if("number"==typeof e&&Number.isFinite(e)&&e>0)return e}return 1}(s.get(t.target))),r=t.reduce((t,e)=>t+e,0);if(r<=0)return i[0];const o=n.counters.get(e)??0;n.counters.set(e,o+1);let a=o%r;for(let e=0;e<i.length;e++){if(a<t[e])return i[e];a-=t[e]}return i[i.length-1]}case"utilization":{let t=1/0,e=i[0];for(const n of i){const i=Kb(s.get(n.target));i<t&&(t=i,e=n)}return e}}}function Zb(t,e,n){const i=t?.root;if(!i)return null;const s=e?.state?.meta?.destination;if("string"!=typeof s||0===s.length)return null;const r=Vb(i);if(!r||0===r.graph.nodes.size)return null;const o=Hb(t);if(!o)return null;let a=r.destToSinks.get(s)??[];0===a.length&&(a=[s]);const c=bb(r.graph,o,a);if(0===c.length)return null;const l=r.graph.out.get(o)??[],h=c.filter(t=>{const n=l[t.index],i=n?r.components.get(n):null;return!i||"function"!=typeof i.canReceive||i.canReceive(e)});if(0===h.length)return l[c[0].index]??null;const d=n?.policy??function(t,e){const n=t?.state?.balancingPolicy;if(n)return n;const i=e?.state?.routingBalancingPolicy;return i||"round-robin"}(t,i),u=Qb(d,o,function(t){return t.__balancingState||(t.__balancingState={counters:new Map}),t.__balancingState}(i),h,r.components);return l[u.index]??null}Vm({name:"Capacity",description:"Item 을 *보유(keep)* 하는 측면 — slot 위상 / 수용 판정(canReceive/findSlot) / 3D 안착(placementFor/attachPointFor/acceptanceRotation) / delivery 좌표 질의 / 점유 수. 이동(receive/dispatch 등)은 Transferable 소관.",methods:["get slots","get arrangementStrategy","canReceive","findSlot","placementFor","attachPointFor","acceptanceRotation","deliveryWorldRotation","deliveryWorldPosition","_countOccupied"],sourceFile:"src/items/capacity-mixin.ts"}),Vm({name:"PlacementSurface",description:"carrier 가 holder 위 *정확히 어디에 앉는가* 의 단일 진입점 — placementFor(carrier, ctx) → SeatingPose (holder object3d local frame, 순수 함수). I1 접촉 (밑면 = 받침 상면) / I2 frame-explicit (parent-child 비가정 — Sovereign handover 와 reparent 양쪽이 같은 값 소비) / I3 순수성 / I4 per-carrier 치수. default 구현은 Capacity(FlowNode) 가 기존 receivingSurfaceY + ArrangementStrategy + acceptanceRotation 합성과 수치 동일하게 제공.",methods:["placementFor"],models:["CarrierDims","PlacementContext","SeatingPose"],sourceFile:"src/items/capacity-mixin.ts"});try{globalThis.__operatoBuildFlowGraph=(t,e)=>{try{return e?.force&&t&&delete t.__flowGraph,$b(t)}catch{return null}}}catch{}function Jb(t,e,n){const i=Zb(t,e,n);if(null==i)return null;const s=t?.root,r=Wb(s,i)??s?.findById?.(i)??null;return r?{targetId:i,component:r,origin:"explicit"}:null}function t_(t){const e=t?.root,n=$b(e),i=Xb(t);if(!n||!i)return null;const s=(n.out.get(i)??[]).find(Boolean);if(!s)return null;const r=Wb(e,s)??e?.findById?.(s)??null;return r?{id:s,component:r}:null}function e_(t){const e=Xb(t);return e?n_(t?.root,e):[]}function n_(t,e){if(!t||!e)return[];const n=$b(t);if(!n)return[];const i=new Set;for(const s of gb(n,e)){const e=Wb(t,s);if(Nb(e)){const t=e.routingDestination();"string"==typeof t&&t.length>0&&i.add(t)}}return[...i]}function i_(t,e){if(!t||!e)return[];const n=$b(t);if(!n)return[];const i=new Map;for(const t of n.out.values())for(const e of t)null!=e&&i.set(e,(i.get(e)??0)+1);const s=new Map;for(const r of gb(n,e)){const e=Wb(t,r);if(!Nb(e))continue;const n=e.routingDestination();if("string"!=typeof n||0===n.length)continue;let o=null;if("function"==typeof e.routingWeight){const t=e.routingWeight();"number"==typeof t&&Number.isFinite(t)&&t>0&&(o=t)}null===o&&(o=i.get(r)??0,0===o&&(o=1)),s.set(n,(s.get(n)??0)+o)}return[...s].map(([t,e])=>({value:t,weight:e}))}function s_(t){return $b(t)}function r_(t){const e=$b(t);if(!e)return[];const n=new Set,i=new Set,s=t=>{if(!t)return;const r=Xb(t);if(r&&e.nodes.has(r)){Nb(t)&&n.add(r);((t?.state?.type??t?.model?.type??"").includes("loop")||!0===t?.isLoop)&&i.add(r)}const o=t.components;if(Array.isArray(o))for(const t of o)s(t)};return s(t),_b(e,{routingTargetIds:n,loopCapableIds:i})}function o_(t){if(0===t.length)return;const e=t.reduce((t,e)=>t+e.weight,0);if(e<=0)return t[Math.floor(Math.random()*t.length)].value;const n=Math.random()*e;let i=0;for(const e of t)if(i+=e.weight,n<i)return e.value;return t[t.length-1].value}const a_={next:Jb,downstream:t_,reachableDestinations:e_,reachableDestinationsFrom:n_,reachableDestinationsWeightedFrom:i_,pickWeightedDestination:o_,graphFor:s_,validate:r_};function c_(t){var e;return e=class extends t{constructor(){super(...arguments),this._items=[]}get items(){return this._items}containsItem(t){return-1!==this._items.indexOf(t)}attachPointFor(e,n){const i=t.prototype?.attachPointFor;return"function"==typeof i?i.call(this,e,n):null}addItem(t,e){if(!t||this.containsItem(t))return;const n=t.parent;if(n&&"function"==typeof n.removeItem&&n!==this&&n.removeItem(t,!0),this._items.push(t),t.parent=this,!e?.silent&&"function"==typeof this.trigger)try{this.trigger("hold",this,t,this._items.length-1)}catch{}t.held?.(this)}removeItem(t,e){if(!t)return;const n=this._items.indexOf(t);if(-1!==n&&(this._items.splice(n,1),t.parent=null,!e)){if("function"==typeof this.trigger)try{this.trigger("release",this,t,n)}catch{}t.released?.(this)}}forEachItem(t,e){this._items.forEach(t,e)}handoverIn(t,e){if(!t)return;const n=t.parent;n&&("function"==typeof n.removeComponent&&-1!==n._components?.indexOf?.(t)&&n.removeComponent(t,!0),n!==this&&"function"==typeof n.removeItem&&-1!==n._items?.indexOf?.(t)&&n.removeItem(t,!0));const i=-1===this._items.indexOf(t);if(i&&this._items.push(t),t.parent=this,i&&"function"==typeof this.trigger)try{this.trigger("hold",this,t,this._items.length-1)}catch{}const s=t._realObject,r=s?.object3d;if(r){let n,i,o=e?.toParent3D,a="world-preserve";if(!o){const s=this.attachPointFor?.(t,{slotId:e?.slotId});s?.attach&&(o=s.attach,n=s.localPosition,i=s.localRotation,a=s.carryPolicy??"world-preserve")}o&&r.parent!==o&&(o.updateWorldMatrix?.(!0,!1),r.updateWorldMatrix?.(!0,!1),o.attach(r),s.suppressTransform=!0),o&&(n&&r.position.set(n.x,n.y,n.z),"world-preserve"!==a?i?r.rotation.set(i.x,i.y,i.z):r.quaternion.identity():i&&r.rotation.set(i.x,i.y,i.z),s?.setTransientPlacement?.({policy:"carried",meta:{carryPolicy:a}}))}t.held?.(this),this._bumpReceived?.(t)}handoverOut(t){this.removeItem(t),this._bumpDispatched?.(t)}dispose(){const t=this._items.slice();this._items.length=0;for(const e of t)try{e.dispose?.()}catch{}super.dispose?.()}_drawItems(t){const e=this.root?.transitionEffect;for(const t of this._items)e?.isReparenting?.(t)||t.draw?.(this.getContext?.(t))}_captureItems(t,e,n,i,s){for(let r=this._items.length-1;r>=0;r--){const o=this._items[r],a="static"===o.position?o.capture?.(t,e,s):o.capture?.(n,i,s);if(a)return a}return null}postrender(t){super.postrender?.(t);const e=this;if("popup"===e.position)return;const n=this._items;if(!n||0===n.length)return;t.save();const i=e.bounds;!e.showOverflow&&i&&(t.beginPath(),t.rect(i.left,i.top,i.width,i.height),t.clip(),t.closePath());const{left:s=0,top:r=0}=e.state??{};t.translate(s,r),this._drawItems(t),t.translate(-s,-r),t.restore()}capture(t,e,n){const i=this,s=this._items;if(s&&s.length>0&&(!i.app||i.app.isEditMode||!i.hidden)){const s=i.fromParent?.(t,e);if(s&&i.contains?.(s.x,s.y)){const r=i.bounds,o=this._captureItems(s.x-r.left,s.y-r.top,t,e,n);if(o)return o}}return super.capture?.(t,e,n)}},e.capabilities=Object.freeze([...t.capabilities??[],"Holdable"]),e}function l_(e){var n;return(n=class extends e{reserve(t,e){const n=this.findSlot(t);return n?{slot:n,token:Symbol("slot-reservation")}:null}release(t){}async receive(t,e={}){Yu.log({role:"target",contract:"receive:enter",component:this,args:{carrier:Gy(t),options:e}});const n=this.reserve(t,e);if(!n){Yu.log({role:"target",contract:"receive:reject",component:this,args:{carrier:Gy(t)},result:{reason:"no-slot"}}),this.trigger("transfer-rejected",{type:"transfer-rejected",component:t,container:this,reason:"no-slot"});const e=new Error("receive rejected: no-slot");throw e.reason="no-slot",e}this.commit(n,t,e)}commit(e,n,i={}){const s=e.slot,r=this._countOccupied(s.id),o=this.arrangementStrategy.positionAt(r,s,r,n);Yu.log({role:"target",contract:"arrangementStrategy.positionAt",component:this,args:{idx:r,slotId:s.id,occupantCount:r,carrier:Gy(n)},result:o}),n[Wy]=s.id;const a=n._realObject;let c,l;a?.object3d&&(a.object3d.updateWorldMatrix(!0,!1),c=new t.Vector3,l=new t.Quaternion,a.object3d.getWorldPosition(c),a.object3d.getWorldQuaternion(l));const{animated:h=!1,duration:d,ease:u}=i;"function"==typeof this.handoverIn?this.handoverIn(n,{slotId:s.id}):this.reparent?.(n,{animated:h,duration:d,ease:u}),!h&&n._realObject&&(n._realObject.suppressTransform=!1);{const t={},e=this.placementFor?.(n,{slot:s,index:r,occupantCount:r})??null;if(Yu.log({role:"target",contract:"placementFor",component:this,args:{carrier:Gy(n),slotId:s.id,index:r},result:e}),e){const i=n.state??{},r=this.state??{};t.left=e.position.x-(Number(i.width)||0)/2+(Number(r.width)||0)/2,t.top=e.position.z-(Number(i.height)||0)/2+(Number(r.height)||0)/2;const o=this._zPosFromSeatY(e.position.y,i.depth,s);null!==o&&(t.zPos=o),e.rotation&&Uy(t,e.rotation)}else{o&&(t.left=o.x,t.top=o.y);if(0!==(this._realObject?.receivingSurfaceY??0))t.zPos=0;else if(s.localPosition&&Number.isFinite(s.localPosition.z)){const e=this._realObject?.geometricOffsetY??0;t.zPos=s.localPosition.z+e}const e=this.acceptanceRotation?.(n,s);Yu.log({role:"target",contract:"acceptanceRotation",component:this,args:{carrier:Gy(n),slotId:s.id},result:e}),e&&Uy(t,e)}const i=this.normalizePose?.(n,s);"function"==typeof this.normalizePose&&Yu.log({role:"target",contract:"normalizePose",component:this,args:{carrier:Gy(n),slotId:s.id},result:i}),i&&Object.assign(t,i),Object.keys(t).length&&(n.setState?.(t),Yu.log({role:"target",contract:"receive:setState",component:this,args:{carrier:Gy(n),keys:Object.keys(t)}}))}this.trigger("transfer-received",{type:"transfer-received",component:n,container:this,slotId:s.id,preReceiveWorldPos:c,preReceiveWorldQuat:l}),Yu.log({role:"target",contract:"receive:done",component:this,args:{carrier:Gy(n),slotId:s.id}})}async dispatch(t,e,n={}){const i=new Uu({source:this,target:e,carrier:t,options:n,physical:async()=>{delete t[Wy]}}),s=await i.execute();"rolled-back"!==s.phase?this.trigger("transfer-dispatched",{type:"transfer-dispatched",component:t,container:this,target:e}):this.trigger("transfer-rejected",{type:"transfer-rejected",component:t,container:this,reason:s.rejectReason??"rejected"})}route(t){return null}resolveRoute(t,e){}rejectRoute(t,e="rejected"){this.trigger("transfer-rejected",{type:"transfer-rejected",component:t,container:this,reason:e})}canAccept(t){const e=(()=>{const e=this.slots;if(!e.length)return{ok:!1,reason:"no-slots-defined"};const n=this.findSlot(t);if(!n){const n=t?.state?.type??t?.type;for(const t of e)if(!t.allowedTypes?.length||!n||t.allowedTypes.includes(n))return{ok:!1,reason:"all-slots-full"};return{ok:!1,reason:"type-not-accepted"}}return{ok:!0,slot:n}})();return Yu.log({role:"target",contract:"canAccept",component:this,args:{carrier:Gy(t)},result:e.ok?{ok:!0,slotId:e.slot.id}:{ok:!1,reason:e.reason}}),e}accept(t,e){return this.receive(t,e)}}).__hasTransferable=!0,n}function h_(t){var e;const n=!!t.__hasCapacity,i=!!t.__hasTransferable,s=n?t:Jy(t),r=i?s:l_(s),o=[...t.capabilities??[]];n||o.push("Capacity","PlacementSurface"),i||o.push("Transferable"),o.push("Holdable","FlowNode");const a=(function(t,e,n){"symbol"==typeof e&&(e=e.description?"[".concat(e.description,"]"):""),Object.defineProperty(t,"name",{configurable:!0,value:n?"".concat(n," ",e):e})}(e=class extends(c_(r)){get isFlowNode(){return!0}containable(t){return!!t&&!0===t.isItem}get showMoveHandle(){return!1}inboundPorts(){return[]}outboundPorts(){return[]}_bumpReceived(t){const e=this.state?.received??0;this.setState?.({received:e+1})}_bumpDispatched(t){const e=this.state?.dispatched??0;this.setState?.({dispatched:e+1})}_bumpRejected(t,e){const n=this.state?.rejected??0;this.setState?.({rejected:n+1})}route(t){return null}resolveRoute(t,e){}rejectRoute(t,e){}resolveDownstream(){const t=this.state?.downstreamRef;if(!t)return[];return(this.root?.findAll?.(t)??[]).map(t=>t?.state?.id).filter(Boolean)}routingLinks(){return{downstream:this.resolveDownstream()}}},"FlowNodeMixed"),e.capabilities=Object.freeze(o),e.isFlowNode=!0,e);return Xy(a)}function d_(t){return!!t&&!0===t.isFlowNode}Vm({name:"Holdable",description:"어떤 Component 든 item(데이타바인딩 동적 물건) 을 보유하는 capability. _items + add/remove/forEach + handover + hold/release event + dispose cascade. Container(정적 _components) 와 직교 — 컨테이너 비의존.",methods:["addItem","removeItem","forEachItem","containsItem","handoverIn","handoverOut","_drawItems","_captureItems","dispose"],sourceFile:"src/components/mixins/holdable.ts"}),Vm({name:"Transferable",description:"Item 을 노드 간에 옮기는 *이동(move)* 측면. 수용 트랜잭션 라이프사이클(reserve → commit → release)과 receive/accept/dispatch/route 를 제공. 보유(keep — slots/findSlot/canReceive 등)는 Capacity 소관.",methods:["reserve","commit","release","receive","accept","canAccept","dispatch","route","resolveRoute","rejectRoute"],sourceFile:"src/transfer/transferable-mixin.ts"}),Vm({name:"FlowNode",description:"Flow graph 의 노드 — 구조 (inbound/outbound port + slot) + flow (route + 5-phase transfer stat). 보유(_items/handover)는 Holdable base 위임. 모든 flow 컴포넌트의 base — Storable/Mobile/Processable 의도가 위에 직교로 적용.",methods:["inboundPorts","outboundPorts","slotIds","slotAt","route","resolveRoute","rejectRoute"],models:["Port","SlotInfo","Vec3"],sourceFile:"src/flow/flow-node.ts"});const u_={x:0,y:0,z:0,w:1};function p_(t){const e=t/2;return{x:0,y:Math.sin(e),z:0,w:Math.cos(e)}}function f_(t,e){const n=t.rotation,i=e.rotation,s=e.position,r=n.w*s.x+n.y*s.z-n.z*s.y,o=n.w*s.y+n.z*s.x-n.x*s.z,a=n.w*s.z+n.x*s.y-n.y*s.x,c=-n.x*s.x-n.y*s.y-n.z*s.z,l=r*n.w+c*-n.x+o*-n.z-a*-n.y,h=o*n.w+c*-n.y+a*-n.x-r*-n.z,d=a*n.w+c*-n.z+r*-n.y-o*-n.x,u={x:n.w*i.x+n.x*i.w+n.y*i.z-n.z*i.y,y:n.w*i.y-n.x*i.z+n.y*i.w+n.z*i.x,z:n.w*i.z+n.x*i.y-n.y*i.x+n.z*i.w,w:n.w*i.w-n.x*i.x-n.y*i.y-n.z*i.z};return{position:{x:t.position.x+l,y:t.position.y+h,z:t.position.z+d},rotation:u}}const m_={east:{axis:{x:1,y:0,z:0},yaw:0,idSuffix:"east"},west:{axis:{x:-1,y:0,z:0},yaw:Math.PI,idSuffix:"west"},south:{axis:{x:0,y:0,z:1},yaw:-Math.PI/2,idSuffix:"south"},north:{axis:{x:0,y:0,z:-1},yaw:Math.PI/2,idSuffix:"north"}};function g_(t){const{carrierWorld:e,width:n,depth:i,entryHeight:s,mountLocalY:r,approachDistance:o,sides:a,toolType:c,tolerance:l,priority:h}=t,d="number"==typeof r?{position:{x:0,y:r,z:0},rotation:{...u_}}:void 0,u=n/2,p=i/2;return a.map(t=>{const n=m_[t],i="string"==typeof c?c:c[t]??"unknown",r={position:{x:n.axis.x*("east"===t||"west"===t?u:0),y:s,z:n.axis.z*("north"===t||"south"===t?p:0)},rotation:p_(n.yaw)},a={position:{x:r.position.x+n.axis.x*o,y:s,z:r.position.z+n.axis.z*o},rotation:p_(n.yaw)};return{id:`entry-${n.idSuffix}`,toolType:i,approach:f_(e,a),engage:f_(e,r),...d?{mount:d}:{},tolerance:l,priority:h}})}function y_(t){const{carrierWorld:e,topY:n,approachDistance:i,toolType:s,mountLocalY:r,tolerance:o,priority:a,id:c}=t,l={position:{x:0,y:n,z:0},rotation:{...u_}};return{id:c??"top",toolType:s,approach:f_(e,{position:{x:0,y:n+i,z:0},rotation:{...u_}}),engage:f_(e,l),..."number"==typeof r?{mount:{position:{x:0,y:r,z:0},rotation:{...u_}}}:{},tolerance:o,priority:a}}function b_(t,e){return t.filter(t=>t.toolType===e.toolType)}function __(t,e){if(0===t.length)return null;const n=t.map(t=>{const n=t.approach.position.x-e.x,i=t.approach.position.y-e.y,s=t.approach.position.z-e.z;return{f:t,dist:Math.sqrt(n*n+i*i+s*s)}});return n.sort((t,e)=>{const n=t.f.priority??0,i=e.f.priority??0;return n!==i?n-i:t.dist-e.dist}),n[0].f}class v_{constructor(t){this.owner=t}positionAt(t,e,n,i){if(0!==t)return null;const s=this.owner?.state?.width??0,r=this.owner?.state?.height??0,o=i?.state?.width??0,a=i?.state?.height??0;return{x:Math.max(0,(s-o)/2),y:Math.max(0,(r-a)/2),z:0}}capacity(t){return t.maxCount??1}}let x_=1;function w_(t,e){return t.startSimMs<e.endSimMs&&e.startSimMs<t.endSimMs}const M_={resolveConflict:(t,e)=>t.priority!==e.priority?t.priority<e.priority?"b-yields":"a-yields":t.id<e.id?"b-yields":"a-yields"};class S_{constructor(t=M_){this._byResource=new Map,this._byReserver=new Map,this._listeners=new Set,this._conflictLog=[],this._maxConflictLog=1e3,this._yieldPolicy=t}add(t){const e={...t,id:"res-"+x_++},n=(this._byResource.get(e.resource)??[]).filter(t=>w_(t.timeWindow,e.timeWindow));if(0===n.length)return this._insert(e),this._emit({kind:"added",reservation:e}),{ok:!0,reservation:e};const i=n.map(t=>{const n=this._yieldPolicy.resolveConflict(e,t);return{a:e,b:t,decision:n}});if(i.every(t=>"b-yields"===t.decision)){const i=n.slice();for(const t of i)this._remove(t),this._emit({kind:"evicted",reservation:t,by:e});return this._insert(e),this._emit({kind:"added",reservation:e}),this._appendConflictLog({simTime:e.timeWindow.startSimMs,resource:e.resource,proposed:t,existing:i,outcome:"preempted"}),{ok:"preempted",reservation:e,evicted:i}}return this._appendConflictLog({simTime:e.timeWindow.startSimMs,resource:e.resource,proposed:t,existing:n.slice(),outcome:"rejected"}),{ok:!1,conflicts:i}}conflictLog(){return[...this._conflictLog]}setMaxConflictLog(t){this._maxConflictLog=Math.max(1,t)}_appendConflictLog(t){this._conflictLog.push(t),this._conflictLog.length>this._maxConflictLog&&this._conflictLog.shift()}conflicts(t,e){return(this._byResource.get(t)??[]).filter(t=>w_(t.timeWindow,e))}release(t){this._remove(t)&&this._emit({kind:"released",reservation:t})}releaseAllOf(t){const e=(this._byReserver.get(t)??[]).slice();for(const t of e)this._remove(t),this._emit({kind:"released",reservation:t});return e}forResource(t){return[...this._byResource.get(t)??[]]}forReserver(t){return[...this._byReserver.get(t)??[]]}all(){const t=[];for(const e of this._byResource.values())t.push(...e);return t}clear(){this._byResource.clear(),this._byReserver.clear(),this._conflictLog.length=0}subscribe(t){return this._listeners.add(t),()=>{this._listeners.delete(t)}}_insert(t){let e=this._byResource.get(t.resource);e||(e=[],this._byResource.set(t.resource,e));const n=e.findIndex(e=>e.timeWindow.startSimMs>t.timeWindow.startSimMs);n<0?e.push(t):e.splice(n,0,t);let i=this._byReserver.get(t.reserverId);i||(i=[],this._byReserver.set(t.reserverId,i)),i.push(t)}_remove(t){const e=this._byResource.get(t.resource);if(!e)return!1;const n=e.findIndex(e=>e.id===t.id);if(n<0)return!1;e.splice(n,1),0===e.length&&this._byResource.delete(t.resource);const i=this._byReserver.get(t.reserverId);if(i){const e=i.findIndex(e=>e.id===t.id);e>=0&&i.splice(e,1),0===i.length&&this._byReserver.delete(t.reserverId)}return!0}_emit(t){this._listeners.forEach(e=>e(t))}}const k_=new S_;"undefined"!=typeof globalThis&&(globalThis.__THINGS_SCENE_RESERVATION_TABLE__=k_);class A_{constructor(){this.nodes=new Map,this.edges=new Map,this.laneEndpoints=new Map}addNode(t){this.nodes.has(t.id)||(this.nodes.set(t.id,t),this.edges.set(t.id,[]))}addEdge(t){const e=this.edges.get(t.fromNode);if(!e)throw new Error(`NavGraph.addEdge: source node not found: ${t.fromNode}`);if(!this.nodes.has(t.toNode))throw new Error(`NavGraph.addEdge: target node not found: ${t.toNode}`);e.push(t)}edgesFrom(t){return this.edges.get(t)??[]}findNearestNode(t){let e=null,n=1/0;for(const i of this.nodes.values()){const s=E_(i.position,t);s<n&&(n=s,e=i)}return e}}function E_(t,e){const n=t.x-e.x,i=t.y-e.y,s=t.z-e.z;return n*n+i*i+s*s}function C_(t,e){return Math.sqrt(E_(t,e))}function T_(t,e,n={}){const i=new A_,s=n.defaultSpeed??100;for(const e of t){const t=e.geometry.centerPoints;if(t.length<2)continue;const n=`${e.id}:start`,r=`${e.id}:end`;i.addNode({id:n,position:t[0],type:"lane-start"}),i.addNode({id:r,position:t[t.length-1],type:"lane-end"}),i.laneEndpoints.set(e.id,{startNodeId:n,endNodeId:r});let o=0;for(let e=1;e<t.length;e++)o+=C_(t[e-1],t[e]);const a=o/(e.speedLimit??s)*1e3;i.addEdge({fromNode:n,toNode:r,resource:e.id,distance:o,durationMs:a,forward:!0}),"twoway"===e.direction&&i.addEdge({fromNode:r,toNode:n,resource:e.id,distance:o,durationMs:a,forward:!1})}for(const t of e){if(t.lanes.length<2)continue;const e=[];for(const n of t.lanes){const s=i.laneEndpoints.get(n);if(!s)continue;const r=i.nodes.get(s.startNodeId).position,o=i.nodes.get(s.endNodeId).position;let a=0,c=0,l=0;for(const e of t.lanes){if(e===n)continue;const t=i.laneEndpoints.get(e);if(!t)continue;const s=i.nodes.get(t.startNodeId).position,h=i.nodes.get(t.endNodeId).position;a+=Math.min(E_(r,s),E_(r,h)),c+=Math.min(E_(o,s),E_(o,h)),l++}if(0===l)continue;const h=a<c?s.startNodeId:s.endNodeId;e.push({laneId:n,nodeId:h,pos:i.nodes.get(h).position})}for(let n=0;n<e.length;n++)for(let s=0;s<e.length;s++){if(n===s)continue;const r=e[n],o=e[s],a=C_(r.pos,o.pos);i.addEdge({fromNode:r.nodeId,toNode:o.nodeId,resource:t.id,distance:a,durationMs:t.crossingTimeMs,forward:!0})}}return i}function P_(t,e,n,i={}){const s=t.nodes.get(e),r=t.nodes.get(n);if(!s||!r)return null;const o=i.speed?.max??100,a=e=>{const n=t.nodes.get(e);var i,s;return(i=n.position,s=r.position,Math.sqrt(function(t,e){const n=t.x-e.x,i=t.y-e.y,s=t.z-e.z;return n*n+i*i+s*s}(i,s)))/o*1e3},c=new Map,l=new Set,h=new Set,d={nodeId:e,gScore:0,fScore:a(e)};c.set(e,d),l.add(e);const u=i.startSimMs??0,p=i.deadlineSimMs;for(;l.size>0;){let e=null,i=null;for(const t of l){const n=c.get(t);(!i||n.fScore<i.fScore||n.fScore===i.fScore&&t<e)&&(i=n,e=t)}if(!i||!e)return null;if(e===n){const t=[];let e=i,n=0;for(;e&&e.cameFromEdge;){const i=e.cameFromEdge,s=u+(e.gScore-i.durationMs);t.unshift({resource:i.resource,timeWindow:{startSimMs:s,endSimMs:s+i.durationMs},fromPos:i.fromPos,toPos:i.toPos}),n+=i.distance,e=c.get(i.fromNodeId)}const s=i.gScore;return void 0!==p&&u+s>p?null:{segments:t,totalDurationMs:s,totalDistance:n}}l.delete(e),h.add(e);for(const n of t.edgesFrom(e)){if(h.has(n.toNode))continue;const e=i.gScore+n.durationMs,s=c.get(n.toNode);if(!s||e<s.gScore){const i=t.nodes.get(n.fromNode),s=t.nodes.get(n.toNode),r={nodeId:n.toNode,gScore:e,fScore:e+a(n.toNode),cameFromEdge:{fromNodeId:n.fromNode,resource:n.resource,distance:n.distance,durationMs:n.durationMs,fromPos:i.position,toPos:s.position}};c.set(n.toNode,r),l.add(n.toNode)}}}return null}function O_(t,e,n=0,i){return t.segments.map(t=>({resource:t.resource,timeWindow:t.timeWindow,reserverId:e,priority:n,metadata:i}))}const D_={closed:!0,round:0,divisions:24};class I_{constructor(t,e){this.points=t,this.closed=e;const n=[0];for(let e=1;e<t.length;e++){const i=t[e].x-t[e-1].x,s=t[e].y-t[e-1].y;n.push(n[e-1]+Math.sqrt(i*i+s*s))}this.cumulative=n,this.length=n[n.length-1]??0}sample(t){const e=this.length;if(0===this.points.length)return{x:0,y:0,theta:0};if(0===e)return{x:this.points[0].x,y:this.points[0].y,theta:0};let n=t;this.closed?n=(t%e+e)%e:n<0?n=0:n>e&&(n=e);const i=this.cumulative;let s=0,r=i.length-2;for(;s<r;){const t=s+r>>1;i[t+1]<=n?s=t+1:r=t}const o=i[s+1]-i[s],a=o>0?(n-i[s])/o:0,c=this.points[s],l=this.points[s+1],h=l.x-c.x,d=l.y-c.y;return{x:c.x+h*a,y:c.y+d*a,theta:0===h&&0===d?0:Math.atan2(d,h)}}}function z_(t,e={}){const n={...D_,...e},i=t.length;if(0===i)return new I_([],n.closed);if(1===i)return new I_([{x:t[0].x,y:t[0].y}],n.closed);const s=[],r=(t,e)=>{if(s.length>0){const n=s[s.length-1];if(Math.abs(n.x-t)<1e-9&&Math.abs(n.y-e)<1e-9)return}s.push({x:t,y:e})},o=(n.closed,i);for(let e=0;e<o;e++){const s=0===e?n.closed?i-1:-1:e-1,o=e===i-1?n.closed?0:-1:e+1,a=s>=0?t[s]:null,c=t[e],l=o>=0?t[o]:null;if(a&&a.x===c.x&&a.y===c.y)continue;const h=a&&l?Jr(c,n.round):0;let d,u,p,f;if(a){const t=Math.sqrt((a.x-c.x)**2+(a.y-c.y)**2),e=0!==t?Math.atan2(a.x-c.x,a.y-c.y):0,n=Math.min(h,t/2);d=Math.sin(e)*n+c.x,u=Math.cos(e)*n+c.y}else d=c.x,u=c.y;if(l){const t=Math.sqrt((l.x-c.x)**2+(l.y-c.y)**2),e=0!==t?Math.atan2(l.x-c.x,l.y-c.y):0,n=Math.min(h,t/2);p=Math.sin(e)*n+c.x,f=Math.cos(e)*n+c.y}else p=c.x,f=c.y;if(r(d,u),h>0&&a&&l)for(let t=1;t<=n.divisions;t++){const e=t/n.divisions,i=1-e;r(i*i*d+2*i*e*c.x+e*e*p,i*i*u+2*i*e*c.y+e*e*f)}else d===p&&u===f||r(p,f);if(l&&Xr(c)){const t=Jr(l,n.round),e=Math.sqrt((c.x-l.x)**2+(c.y-l.y)**2),i=0!==e?Math.atan2(c.x-l.x,c.y-l.y):0,s=Math.min(t,e/2),o=Kr({x:p,y:f},{x:Math.sin(i)*s+l.x,y:Math.cos(i)*s+l.y},c.bulge);if(o){let t=o.endAngle-o.startAngle;if(o.clockwise)for(;t>0;)t-=2*Math.PI;else for(;t<0;)t+=2*Math.PI;for(let e=1;e<=n.divisions;e++){const i=e/n.divisions,s=o.startAngle+t*i;r(o.cx+o.radius*Math.cos(s),o.cy+o.radius*Math.sin(s))}}}}if(n.closed&&s.length>0){const t=s[0],e=s[s.length-1];(Math.abs(e.x-t.x)>1e-9||Math.abs(e.y-t.y)>1e-9)&&s.push({x:t.x,y:t.y})}return new I_(s,n.closed)}function R_(t,e){return z_(t,e).length}function j_(t){return t?/forklift|agv|amr|oht|tugger|worker/i.test(t)?"mobile":/conveyor|sorter|induct|chute|belt/i.test(t)?"flow":/rack|shelf|stocker|cell/i.test(t)?"cell":/pallet|box|parcel|crate|drum|tray/i.test(t)?"atomic":/robot[-_]?arm|crane|lift/i.test(t)?"articulated":/spawn[-_]?point|sink[-_]?point/i.test(t)?"boundary":"":""}function L_(t){const e=[];let n=t.parent;for(;n&&!n.isRootModel?.();){const t=n.state?.id??n.constructor?.name;t&&e.unshift(t),n=n.parent}return e.join(" › ")}function F_(t,e=!0){const n=t.constructor?.name??t.state?.type??"Component",i={type:n,id:t.state?.id??`?${t._id??Math.random().toString(36).slice(2,7)}`,category:j_(n),parentId:t.parent?.state?.id,parentPath:L_(t)},s=t._realObject?.object3d;if(s){s.updateWorldMatrix?.(!0,!1);const t=s.matrixWorld?.elements;t&&(i.pose={position:{x:t[12],y:t[13],z:t[14]},rotation:{x:0,y:0,z:0,w:1}})}if(!0===t.isItem&&(i.isItem=!0),!0===t.isMover&&(i.isMover=!0),"function"!=typeof t.canReceive&&"function"!=typeof t.canAccept||(i.isHolder=!0),"function"==typeof t.pickupFrames)try{i.isPickable=t.pickupFrames().length>0}catch{i.isPickable=!1}if("string"==typeof t.toolType||"function"==typeof t.toolType?i.toolType="function"==typeof t.toolType?t.toolType():t.toolType:void 0!==t.toolType&&(i.toolType=String(t.toolType)),t.state&&"object"==typeof t.state){const e={};for(const[n,i]of Object.entries(t.state))"string"!=typeof i&&"number"!=typeof i&&"boolean"!=typeof i&&null!==i||(e[n]=i);i.state=e}if(e){const e=t.components??[];i.childIds=e.map(t=>t.state?.id).filter(Boolean)}return i}function N_(t){function e(t,n){if(!t)return;n.push(F_(t));const i=t.components??[];for(const t of i)e(t,n)}function n(t,e){if(!e)return null;if(e.state?.id===t)return e;const i=e.components??[];for(const e of i){const i=n(t,e);if(i)return i}return null}return{version:"0.1.0",collectComponents(){const n=[];return e(t?.rootModel??t,n),n},getComponent(e){const i=n(e,t?.rootModel??t);if(!i)return null;const s={...F_(i)};if("function"==typeof i.pickupFrames)try{s.pickupFrames=i.pickupFrames()}catch{}if("object"==typeof i.slots)try{s.slots=Array.isArray(i.slots)?i.slots:"function"==typeof i.slots?i.slots():[]}catch{}if("function"==typeof i.acceptanceRotation)try{s.acceptanceWorldQuat=i.deliveryWorldRotation?.(null)??void 0}catch{}if("function"==typeof i.deliveryWorldPosition)try{s.deliveryWorldPosition=i.deliveryWorldPosition(null)}catch{}return s},simStatus(){let e=0;const n=[t?.rootModel??t];for(;n.length>0;){const t=n.pop();if(!t)continue;!0===t.isItem&&e++;const i=t.components??[];for(const t of i)n.push(t)}return{simTime:Ir.now,realTime:"undefined"!=typeof performance?performance.now():Date.now(),speed:Ir.speed,paused:Ir.isPaused,carrierCount:e}},transferLog(){const t={};Wu.flows().forEach((e,n)=>{t[n]=e});const e={};Wu.targetCounts().forEach((t,n)=>{e[n]=t});const n={};return Wu.rejectReasonCounts().forEach((t,e)=>{n[e]=t}),{entries:Wu.toJSON(),stats:Wu.stats(),flows:t,targetCounts:e,rejectReasonCounts:n}},reservations(){const t=[...k_.all()],e={},n={};for(const i of t)(e[i.resource]??=[]).push(i),(n[i.reserverId]??=[]).push(i);for(const t of Object.values(e))t.sort((t,e)=>t.timeWindow.startSimMs-e.timeWindow.startSimMs);for(const t of Object.values(n))t.sort((t,e)=>t.timeWindow.startSimMs-e.timeWindow.startSimMs);return{simTime:Ir.now,all:t,byResource:e,byReserver:n}},conflicts(){const t=k_.conflictLog(),e={},n={};let i=0,s=0;for(const r of t)e[r.resource]=(e[r.resource]??0)+1,n[r.proposed.reserverId]=(n[r.proposed.reserverId]??0)+1,"rejected"===r.outcome?i++:s++;return{simTime:Ir.now,log:[...t],total:t.length,rejected:i,preempted:s,byResource:e,byReserver:n}}}}function H_(t){const e=N_(t);return"undefined"!=typeof window&&(window.__SCENE_INSPECTOR__=e),e}let B_=0;const Y_=new FinalizationRegistry(()=>{B_--});class V_{static get residents(){return B_}static get residentsCount(){return B_}constructor(t,e){this.counters={},this.references={},this.creator=t,this.disposer=e,B_++,Y_.register(this,B_)}dispose(){if(this.disposer)for(const t in this.references)this.disposer(t,this.references[t]);this.references={},this.counters={}}get ids(){return Object.keys(this.references)}create(t){return new Promise((e,n)=>{this.creator?this.creator(t,n=>{n.release=()=>{this.disposer?.(t,n),delete n.release,Ji("RELEASED",t)},e(n)},n):n(Error("Reference id("+t+") could not be created. Reference creator should be defined."))})}add(t,e){const n=new Promise((n,i)=>{const s=this.references[t];if(s)s===e?i(Error("Reference ID and target duplicate")):e?i(Error("Reference ID duplicate")):n(s);else{const s=e=>{e.release=()=>{this.release(e)},this.references[t]=e,this.counters[t]=1,n(e)};if(e)s(e);else{if(!this.creator)return void i(Error("Reference id("+t+") is not allowed. Reference creator should be defined."));this.creator(t,s,i)}}});return this.references[t]||(this.references[t]=n),n}async get(t,e=!1){let n=this.references[t];if(n){if(!(n instanceof Promise)){if(!(t in this.counters))throw new Error("No Reference Count");return this.counters[t]++,n}if(e)return n=await n,this.counters[t]++,n}if(e)return await this.add(t);throw new Error("No References for "+t)}_id(t){for(const e in this.references){if(this.references[e]===t)return e}}release(t){const e=this._id(t);if(!e)return void Qi("No Referenced ID");const n=this.references[e];n&&(this.counters[e]--,0==this.counters[e]&&(this.disposer?.(e,n),delete this.references[e],delete this.counters[e],delete t.release,Ji("RELEASED",e)))}}const G_={},$_={};let U_=[];function W_(t){const e=t.target,n="SCRIPT"===e.tagName?G_:$_,i=e.src||e.href;n[i]=!0,U_.forEach((t,e)=>{if(!t)return;const{resolve:s,scripts:r,styles:o}=t;if(n===G_){const t=r.indexOf(i);t>-1&&t<r.length-1&&X_(r[t+1])}r.some(t=>!G_[t])||o?.some(t=>!$_[t])||(s(),U_[e]=null)}),U_=U_.filter(Boolean)}function q_(t){if("string"==typeof t)return;const e=t.target,n=e.src,i="SCRIPT"===e.tagName?G_:$_;U_.forEach((e,s)=>{if(!e)return;const{reject:r,scripts:o,styles:a}=e;(i===G_&&o.includes(n)||i===$_&&!!a?.includes(n))&&(r(t),U_[s]=null)}),U_=U_.filter(Boolean),delete i[n],document.head.removeChild(e)}function X_(t){G_[t]=!1;const e=document.createElement("script");e.onload=W_,e.onerror=q_,e.type="text/javascript",e.src=t,document.head.appendChild(e)}class K_{static load(t,e){const n="string"==typeof t?[t]:t,i="string"==typeof e?[e]:e;return new Promise(function(t,e){if(n&&!Array.isArray(n)||i&&!Array.isArray(i))return void e(new Error("invalid sources for load"));let s,r=!0;if(i?.forEach(t=>{t in $_||function(t){$_[t]=!1;const e=document.createElement("link");e.onload=W_,e.onerror=q_,e.type="text/css",e.rel="stylesheet",e.media="screen,print",e.href=t,document.head.appendChild(e)}(t),$_[t]||(r=!1)}),n&&n.length>0)for(const t of n)t in G_?G_[t]||(r=!1):s??=t;if(s)X_(s);else if(r)return void t();U_.push({resolve:t,reject:e,scripts:n,styles:i})})}}const Q_="0.0.0";function Z_(t){if(!(t>0))return 1;let e=0;if(!(t&t-1))return t;for(;0!=t;)t>>=1,e+=1;return 1<<e}function J_(e){const{lineWidth:n=0}=e.state;let{width:i,height:s}=e.bounds;i+=n,s+=n;const r=Z_(2*i),o=Z_(2*s),a=Hp(r,o),c=new t.CanvasTexture(a);return tv(a,e,2),c.needsUpdate=!0,c.wrapS=t.RepeatWrapping,c.wrapT=t.RepeatWrapping,c.offset.set(0,1-2*s/o),c.repeat.set(2*i/r,2*s/o),c.magFilter=t.NearestFilter,c.minFilter=t.LinearFilter,c.colorSpace=t.SRGBColorSpace,c}function tv(t,e,n){const{lineWidth:i=0}=e.state;let{left:s,top:r}=e.bounds;s-=i/2,r-=i/2;const o=t.getContext("2d");o.scale(n,n),o.translate(-s,-r),e.render(o),e.postrender(o)}function ev(t,e,n=2){const i=t.getContext("2d");i&&(i.setTransform(1,0,0,1,0,0),i.clearRect(0,0,t.width,t.height),tv(t,e,n))}const nv=new Set(["cx","cy","cz","zPos","left","top","width","height","depth","lineWidth","rotationX","rotationY","rotation","scale","hidden","alpha","material3d","screenFixed"]);class iv extends xu{get syncZPosOffset(){return this.effectiveDepth}get geometricOffsetY(){return this.effectiveDepth}constructor(t){super(t),this._origInvalidate=t.invalidate.bind(t),t.invalidate=()=>{this._origInvalidate(),this._refreshTextureNow()}}getObject3dInstance(){return new t.Mesh}build(){super.build();const{width:e,height:n}=this.component.bounds;if(!e||!n)return;const i=Pd(this.component.state.material3d),s=new t.PlaneGeometry(1,1);s.rotateX(-Math.PI/2),this.object3d.geometry=s;const r=J_(this.component),o=new t.MeshStandardMaterial({map:r});Id(o,i),o.transparent=!0,this.object3d.material=o,this.object3d.castShadow=i.castShadow,this.object3d.receiveShadow=i.receiveShadow}updateDimension(){const{width:t,height:e}=this.component.bounds;this.setDimensionScale(t,1,e)}updateAlpha(){const{alpha:t=1,fillStyle:e}=this.component.state;tu(this.object3d.material,0,e)}_debouncedRebuild(){this._debounceTimer&&clearTimeout(this._debounceTimer),this._debounceTimer=setTimeout(()=>{this._debounceTimer=void 0,this._rebuildTexture()},100)}_rebuildTexture(){this.clear(),this.build(),this.updateTransform(),this.updateDimension(),this.updateHidden()}_refreshTextureNow(){const t=this.object3d.material,e=t?.map;if(!e)return;const n=e.source?.data;n&&(ev(n,this.component,2),e.needsUpdate=!0)}updateFillStyle(){this._debouncedRebuild()}updateStrokeStyle(){this._debouncedRebuild()}updateText(){this._debouncedRebuild()}onchange(t,e){super.onchange(t,e);for(const e of Object.keys(t))if(!nv.has(e)){this._debouncedRebuild();break}}updateMaterial3d(){super.updateMaterial3d();const t=this.object3d.material;if(!t)return;const e=Pd(this.component.state.material3d);Id(t,e),t.transparent=!0,this.object3d.castShadow=e.castShadow,this.object3d.receiveShadow=e.receiveShadow}clear(){return this._debounceTimer&&(clearTimeout(this._debounceTimer),this._debounceTimer=void 0),cu(this.object3d),super.clear()}dispose(){this._debounceTimer&&(clearTimeout(this._debounceTimer),this._debounceTimer=void 0),this._origInvalidate&&(this.component.invalidate=this._origInvalidate,this._origInvalidate=void 0),super.dispose()}}const sv=new Map;function rv(t){return Math.round(1e3*t)/1e3}function ov(e){return new t.Color(e).getHexString()}const av={material(e,n,i){const s=e+"::"+function(t){const e=[];return null!=t.color&&e.push("c"+ov(t.color)),null!=t.metalness&&e.push("m"+rv(t.metalness)),null!=t.roughness&&e.push("r"+rv(t.roughness)),null!=t.opacity&&e.push("o"+rv(t.opacity)),null!=t.emissive&&e.push("E"+ov(t.emissive)),null!=t.emissiveIntensity&&e.push("I"+rv(t.emissiveIntensity)),null!=t.envMapIntensity&&e.push("e"+rv(t.envMapIntensity)),null!=t.side&&e.push("s"+t.side),t.transparent&&e.push("t"),t.flatShading&&e.push("f"),!1===t.depthWrite&&e.push("dw0"),t.map&&e.push("M"+(t.map.uuid??"")),e.join("|")}(n);let r=sv.get(s);return r||sv.set(s,r=function(e){const n=new t.MeshStandardMaterial;return n.userData.__bankOwned=!0,null!=e.color&&n.color.set(e.color),null!=e.emissive&&n.emissive.set(e.emissive),null!=e.metalness&&(n.metalness=e.metalness),null!=e.roughness&&(n.roughness=e.roughness),null!=e.emissiveIntensity&&(n.emissiveIntensity=e.emissiveIntensity),null!=e.envMapIntensity&&(n.envMapIntensity=e.envMapIntensity),null!=e.side&&(n.side=e.side),null!=e.map&&(n.map=e.map),null!=e.flatShading&&(n.flatShading=e.flatShading),null!=e.depthWrite&&(n.depthWrite=e.depthWrite),null!=e.opacity&&(n.opacity=e.opacity),null!=e.transparent?n.transparent=e.transparent:null!=e.opacity&&e.opacity<1&&(n.transparent=!0),n}(n)),null==i?r:Xd(r,{color:i})},get size(){return sv.size},has(t){const e=t+"::";for(const t of sv.keys())if(t.startsWith(e))return!0;return!1},dispose(){for(const t of sv.values())Qd(t),t.dispose();sv.clear()}};class cv extends xu{getObject3dInstance(){return new t.Mesh}build(){super.build(),this.buildGeometry(),this.buildMaterial(),this.updateDimension()}updateAlpha(){if(this.canShareMaterial)return void super.updateAlpha();const{alpha:t=1,fillStyle:e}=this.component.state;tu(this.object3d.material,0,e)}updateFillStyle(){if(this.canShareMaterial)return this.applyBankMaterial(),void this.applyMaterialOpacity();const{fillStyle:t,alpha:e=1}=this.component.state,n=this.object3d.material;if(!n)return;const i=xu.buildFillStyleTexture(this.component);i?(n.map&&n.map.dispose(),i.needsUpdate=!0,n.map=i,n.needsUpdate=!0):"string"==typeof t&&(n.map&&(n.map.dispose(),n.map=null,n.needsUpdate=!0),"transparent"!==t&&"none"!==t&&n.color.set(eu(t))),tu(n,0,t)}updateStrokeStyle(){const e=this.object3d.getObjectByName("__edgeLines__");e&&(this.object3d.remove(e),cu(e));const{strokeStyle:n}=this.component.state;if(!n||"transparent"===n||"none"===n)return;const i=this.object3d.geometry;if(!i?.getAttribute("position"))return;const s=new t.EdgesGeometry(i),r=new t.LineBasicMaterial({color:n}),o=new t.LineSegments(s,r);o.name="__edgeLines__",this.object3d.add(o)}updateDimension(){const{width:t,height:e}=this.component.bounds,{depth:n=1}=this.component.state;if(!this.object3d)return;this.object3d.geometry.computeBoundingBox();const i=this.object3d.geometry.boundingBox;if(i){const s=i.max.x-i.min.x,r=i.max.y-i.min.y,o=i.max.z-i.min.z;this.setDimensionScale(t/s,n/r,e/o)}}get canShareMaterial(){return void 0===this.materialSharingIssue}get materialSharingIssue(){const{fillStyle:t}=this.component.state;if(!t||"object"!=typeof t)return;const e=t.type;return"pattern"===e?"무늬(pattern) fillStyle 은 인스턴스마다 캔버스 텍스처가 필요하다":"gradient"===e?"그라디언트 fillStyle 은 인스턴스마다 캔버스 텍스처가 필요하다":`fillStyle 이 색 문자열이 아니다 (type: ${String(e)})`}get requiresSharedMaterial(){return!0===this.component.constructor.requiresSharedMaterial}get materialSharing(){const t=this.materialSharingIssue,e=void 0===t,n=this.requiresSharedMaterial,i={shared:e,required:n,violated:n&&!e};return void 0!==t&&(i.reason=t),e&&(i.bankKey=this.materialBankKey),i}get materialBankKey(){return`mesh|${this.component.state.type??"unknown"}`}materialSpec(){const t=Pd(this.component.state.material3d),e=Jd(this.component.state.fillStyle);return{metalness:t.metalness,roughness:t.roughness,emissive:t.emissive,emissiveIntensity:t.emissiveIntensity,envMapIntensity:t.envMapIntensity,side:Dd(t.side),flatShading:t.flatShading,opacity:e,transparent:e<1}}buildMaterial(){if(!this.canShareMaterial){const e=Pd(this.component.state.material3d),n=new t.MeshStandardMaterial({transparent:!0});return Id(n,e),void(this.object3d.material=n)}this.applyBankMaterial()}applyBankMaterial(){const{fillStyle:t}=this.component.state,e=Jd(t)>0&&"string"==typeof t?eu(t):void 0;Kd(this.object3d),this.object3d.material=av.material(this.materialBankKey,this.materialSpec(),e)}updateMaterial3d(){if(super.updateMaterial3d(),this.canShareMaterial)return this.applyBankMaterial(),void this.applyMaterialOpacity();const t=this.object3d.material;t&&Id(t,Pd(this.component.state.material3d))}clear(){return Kd(this.object3d),cu(this.object3d),super.clear()}}function lv(t,e,n,i){return[["bold",t],["italic",e],[n+"px",!0],[i,!0]].filter(t=>t[1]).map(t=>t[0]).join(" ")}function hv(t){let e=0;if(!((t=Math.abs(t)||1)&t-1))return t;for(;0!=t;)t>>=1,e+=1;return 1<<e}function dv(t,e,n){const{bold:i=!1,italic:s=!1,fontFamily:r="Serif",fontSize:o=10,fontColor:a="black",textAlign:c="center",textBaseline:l="middle",width:h=t.width,height:d=t.height,offsetX:u=0,offsetY:p=0}=n||{},f=t.getContext("2d");let m,g;f.imageSmoothingEnabled=!1,f.fillStyle=a,f.strokeStyle=a,f.font=lv(i,s,o,r),"left"===c||"start"===c?(f.textAlign="left",m=u):"right"===c||"end"===c?(f.textAlign="right",m=u+h):(f.textAlign="center",m=u+h/2);const y=1.2*o,b=String(e).split("\n"),_=y*b.length;g="top"===l||"hanging"===l?p+.1*o:"bottom"===l||"alphabetic"===l?p+d-_+.1*o:p+(d-_)/2+.1*o,f.textBaseline="top";for(const t of b)f.fillText(t,m,g),g+=y}function uv(e,n,i,s){const r=hv(2*n),o=hv(2*i),a=Hp(r,o),c=a.getContext("2d"),{fillStyle:l}=s||{};if(l&&"object"==typeof l&&l.colorStops?.length){const t=lu(l,2*n,2*i);t&&c.drawImage(t,0,0)}c.scale(2,2),"string"==typeof l&&""!==l&&"transparent"!==l&&(c.fillStyle=l,c.fillRect(0,0,n,i)),dv(a,e,s);const h=new t.CanvasTexture(a);return h.needsUpdate=!0,h.wrapS=t.RepeatWrapping,h.wrapT=t.RepeatWrapping,h.offset.set(0,1-2*i/o),h.repeat.set(2*n/r,2*i/o),h.minFilter=t.LinearFilter,h.colorSpace=t.SRGBColorSpace,h}function pv(e,n,i,s,r,o,a){const c=new Image;c.crossOrigin="anonymous",c.onload=()=>{const e=2*i,l=2*s,h=hv(e),d=hv(l),u=Hp(h,d),p=u.getContext("2d");if(o.color&&(p.fillStyle=o.color,p.fillRect(0,0,e,l)),o.fitPattern)p.drawImage(c,0,0,e,l);else{const t=2*(o.width||c.naturalWidth),n=2*(o.height||c.naturalHeight),i=2*(o.offsetX||0),s=2*(o.offsetY||0);let r=0,a=0;switch(o.align){case"center":r=(e-t)/2,a=(l-n)/2;break;case"left-top":break;case"left-bottom":a=l-n;break;case"right-top":r=e-t;break;case"right-bottom":r=e-t,a=l-n;break;case"left":a=(l-n)/2;break;case"right":r=e-t,a=(l-n)/2;break;case"top":r=(e-t)/2;break;case"bottom":r=(e-t)/2,a=l-n}const h=i+r,d=s+a;if(o.noRepeat)p.drawImage(c,0,0,c.naturalWidth,c.naturalHeight,h,d,t,n);else{p.save(),p.rect(0,0,e,l),p.clip();const i=h>0?h-Math.ceil(h/t)*t:h;for(let s=d>0?d-Math.ceil(d/n)*n:d;s<l;s+=n)for(let r=i;r<e;r+=t)p.drawImage(c,0,0,c.naturalWidth,c.naturalHeight,r,s,t,n);p.restore()}}n&&(p.scale(2,2),dv(u,n,r));const f=new t.CanvasTexture(u);f.needsUpdate=!0,f.wrapS=t.RepeatWrapping,f.wrapT=t.RepeatWrapping,f.offset.set(0,1-l/d),f.repeat.set(e/h,l/d),f.minFilter=t.LinearFilter,f.colorSpace=t.SRGBColorSpace,a(f)},c.onerror=()=>{const t=uv(n,i,s,r);a(t)},c.src=e}function fv(t,e){let{bold:n=!1,italic:i=!1,fontFamily:s="Serif",fontSize:r=10,lineHeight:o="normal"}=e||{};t=void 0===t||""==t?" ":String(t);const a=document.createElement("span");a.style.font=lv(n,i,r,s),a.style.lineHeight=String(o),a.style.whiteSpace="pre",a.style.position="absolute",a.textContent=t,document.body.appendChild(a);const c=a.getBoundingClientRect();return document.body.removeChild(a),{width:c.width,height:c.height}}class mv extends cv{get zPriority(){return fu.DECAL}get syncZPosOffset(){return this.effectiveDepth}get geometricOffsetY(){return this.effectiveDepth}buildGeometry(){this.updateDimension()}updateStrokeStyle(){}updateFillStyle(){this.updateText()}updateDimension(){const{width:e,height:n}=this.component.state,i=Math.abs(e)||1,s=Math.abs(n)||1;this.object3d.geometry&&this.object3d.geometry.dispose();const r=new t.PlaneGeometry(i,s);r.rotateX(-Math.PI/2),this.object3d.geometry=r}updateText(){const t=this.object3d.material;if(!t)return;const{width:e,height:n,bold:i=!1,italic:s=!1,fontFamily:r="Serif",fontSize:o=10,fontColor:a="black",textAlign:c="center",textBaseline:l="middle",fillStyle:h}=this.component.state,d=Math.abs(e)||1,u=Math.abs(n)||1,p=this.component.text,f=h&&"none"!==h?h:"transparent",m={bold:i,italic:s,fontFamily:r,fontSize:o,fontColor:a,textAlign:c,textBaseline:l,width:d,height:u,fillStyle:f};if("object"==typeof f&&"pattern"===f?.type&&f.image){return void pv(this.component.app.url(h.image),p,d,u,m,h,e=>{t.map&&t.map.dispose(),t.map=e,t.color.set(16777215),t.needsUpdate=!0})}const g=uv(p,d,u,m);g?(t.map&&t.map.dispose(),t.map=g,t.color.set(16777215),g.needsUpdate=!0):"string"==typeof h&&(""!==h&&"transparent"!==h?t.color.set(eu(h)):t.opacity=0)}updateAlpha(){const t=this.object3d.material;t.opacity=1,t.transparent=!0,super.applyMaterialOpacity()}}Kp("text",t=>new mv(t));const gv={input:"css3d",select:"css3d",textarea:"css3d",button:"css3d",iframe:"css3d",video:"css3d",label:"texture",table:"texture",progress:"texture"};function yv(t){const e=t.model?.type??"";return"texture"===(gv[e]??"css3d")?new iv(t):new Wp(t)}Kp("html-overlay-element",yv),Kp("html-overlay-container",yv);class bv{setShape({extrudedShape:e,extrudedOptions:n}){this.extrudedShape=e,this.bb=new t.Box2,this.bb.setFromPoints(this.extrudedShape?.extractPoints(0).shape),this.extrudedOptions=n}generateTopUV(e,n,i,s,r){const o=n[3*i],a=n[3*i+1],c=n[3*s],l=n[3*s+1],h=n[3*r],d=n[3*r+1],u=this.bb,p=u.max.x-u.min.x,f=u.max.y-u.min.y;return[new t.Vector2((o-u.min.x)/p,1-(a-u.min.y)/f),new t.Vector2((c-u.min.x)/p,1-(l-u.min.y)/f),new t.Vector2((h-u.min.x)/p,1-(d-u.min.y)/f)]}generateSideWallUV(e,n,i,s,r,o){const a=n[3*i],c=n[3*i+1],l=n[3*i+2],h=n[3*s],d=n[3*s+1],u=n[3*s+2],p=n[3*r],f=n[3*r+1],m=n[3*r+2],g=n[3*o],y=n[3*o+1],b=n[3*o+2],_=this.extrudedOptions?.depth||100,v=this.bb,x=v.max.x-v.min.x,w=v.max.y-v.min.y;return Math.abs(c-d)<.01?[new t.Vector2(a/x,1-l/_),new t.Vector2(h/x,1-u/_),new t.Vector2(p/x,1-m/_),new t.Vector2(g/x,1-b/_)]:[new t.Vector2(c/w,1-l/_),new t.Vector2(d/w,1-u/_),new t.Vector2(f/w,1-m/_),new t.Vector2(y/w,1-b/_)]}}function _v(t,e){const n=t/2,i=e/2;return{points:[{x:-n,y:-i},{x:n,y:-i},{x:n,y:i},{x:-n,y:i}]}}function vv(t,e,n){const i=Math.max(3,Math.floor(n)),s=[];for(let n=0;n<i;n++){const r=n/i*Math.PI*2;s.push({x:t*Math.cos(r),y:e*Math.sin(r)})}return{points:s,segments:i}}function xv(t){if(0===t.length)return[];let e=1/0,n=1/0,i=-1/0,s=-1/0;for(const r of t)r.x<e&&(e=r.x),r.x>i&&(i=r.x),r.y<n&&(n=r.y),r.y>s&&(s=r.y);const r=(e+i)/2,o=(n+s)/2,a=t.map(t=>({x:t.x-r,y:t.y-o})),c=a[0],l=a[a.length-1];return a.length>1&&Math.abs(c.x-l.x)<1e-9&&Math.abs(c.y-l.y)<1e-9&&a.pop(),a}class wv extends xu{clear(){return this._mesh=void 0,super.clear()}get shape(){return null}topOutline(){const t=this.shape;if(!t||"function"!=typeof t.getPoints)return null;const e=this.outlineDivisions,n=t.getPoints(e);if(!n||n.length<3)return null;const i=xv(n);return i.length<3?null:{points:i}}get outlineDivisions(){return 12}get boundUVGenerator(){return this._boundUVGenerator||(this._boundUVGenerator=new bv),this._boundUVGenerator}build(){super.build();const e=this.effectiveDepth,n=this.shape;if(!n)return;const i=this.boundUVGenerator;i&&i.setShape({extrudedShape:n,extrudedOptions:{depth:e}});const s=this.createGeometry(n),r=this.createMaterials();this._mesh=new t.Mesh(s,r),this._mesh.rotation.x=-Math.PI/2,this._mesh.rotation.y=-Math.PI,this._mesh.rotation.z=-Math.PI,this._mesh.castShadow=!0,this.object3d.add(this._mesh),this.updateFillStyle(),this.updateStrokeStyle()}createGeometry(e){const n=this.effectiveDepth,{lineWidth:i=0}=this.component.state,s={steps:1,depth:n,bevelEnabled:i>0,bevelThickness:0,bevelSize:i,bevelSegments:1,UVGenerator:this.boundUVGenerator},r=new t.ExtrudeGeometry(e,s);return r.center(),r}createMaterials(){const e=Pd(this.component.state.material3d),n=new t.MeshStandardMaterial;Id(n,e);const i=new t.MeshStandardMaterial;return Id(i,e),[n,i]}createTexture(){const{width:e,height:n}=this.component.bounds,i=hv(e),s=hv(n),r=Hp(i,s);this.component.render(r.getContext("2d"));const o=new t.CanvasTexture(r);return o.needsUpdate=!0,o.wrapS=t.RepeatWrapping,o.wrapT=t.RepeatWrapping,o.offset.set(0,1-n/s),o.repeat.set(e/i,n/s),o.minFilter=t.LinearFilter,o}getMaterials(){if(!this._mesh)return;const t=this._mesh.material;return Array.isArray(t)?t:void 0}updateMaterial3d(){super.updateMaterial3d();const t=this.getMaterials();if(!t)return;const e=Pd(this.component.state.material3d);for(const n of t)Id(n,e)}updateAlpha(){const{alpha:t=1,fillStyle:e,strokeStyle:n}=this.component.state,i=this.getMaterials();i&&(tu(i[0],0,e),tu(i[1],0,n))}updateStrokeStyle(){const t=this.getMaterials();if(!t)return;const{strokeStyle:e}=this.component.state;t[1].color.set(eu(e))}updateFillStyle(){this._applyCapTexture()}updateText(){this._applyCapTexture()}_applyCapTexture(){const t=this.getMaterials();if(!t)return;const e=t[0],{fillStyle:n}=this.component.state,i=this.component.hasTextProperty?this.component.text:"";if(!i){const t=xu.buildFillStyleTexture(this.component);return t?(e.map&&e.map.dispose(),e.map=t,e.color.set(16777215)):(e.map&&(e.map.dispose(),e.map=null),e.color.set(eu(n))),void(e.needsUpdate=!0)}const{bold:s=!1,italic:r=!1,fontFamily:o="Serif",fontSize:a=10,fontColor:c="black",textAlign:l="center",textBaseline:h="middle",paddingTop:d=0,paddingLeft:u=0,paddingRight:p=0,paddingBottom:f=0}=this.component.state,{width:m,height:g}=this.component.bounds,y=Math.abs(m)||1,b=Math.abs(g)||1,_={bold:s,italic:r,fontFamily:o,fontSize:a,fontColor:c,textAlign:l,textBaseline:h,width:Math.max(y-u-p,0),height:Math.max(b-d-f,0),fillStyle:n,offsetX:u,offsetY:d};if("object"==typeof n&&"pattern"===n?.type&&n.image){return void pv(this.component.app.url(n.image),i,y,b,_,n,t=>{e.map&&e.map.dispose(),e.map=t,e.color.set(16777215),e.needsUpdate=!0})}e.map&&e.map.dispose();const v=uv(i,y,b,_);e.map=v,e.color.set(16777215),e.needsUpdate=!0}updateDimension(){super.updateDimension()}onchange(t,e){if("path"in t&&this._mesh){const t=this._mesh.geometry,e=this.shape;if(e){const n=this.createGeometry(e);this._mesh.geometry=n,t.dispose()}}super.onchange(t,e)}}class Mv extends wv{get shape(){const{cx:e=0,cy:n=0,rx:i=1,ry:s=1,startAngle:r=0,endAngle:o=2*Math.PI,anticlockwise:a=!1}=this.component.state,c=new t.EllipseCurve(e,n,Math.abs(i),Math.abs(s),r,o,a,0);return new t.Shape(c.getPoints(50))}}Kp("ellipse",t=>new Mv(t));class Sv extends wv{get shape(){const{width:e,height:n,round:i=0}=this.component.state,s=Pc(i,e,n);if(s>0){const i=s,r=new t.Path;return r.moveTo(i,0),r.lineTo(e-i,0),r.quadraticCurveTo(e,0,e,i),r.lineTo(e,n-i),r.quadraticCurveTo(e,n,e-i,n),r.lineTo(i,n),r.quadraticCurveTo(0,n,0,n-i),r.lineTo(0,i),r.quadraticCurveTo(0,0,i,0),new t.Shape(r.getPoints(12))}const r=new t.Shape;return r.moveTo(0,0),r.lineTo(e,0),r.lineTo(e,n),r.lineTo(0,n),r.lineTo(0,0),r}}function kv(e,n={}){const i=n.round??0,s=n.divisions??24;if(!e||0===e.length)return new t.Shape;const r=e.some(t=>Xr(t)),o=i>0||e.some(t=>Jr(t,0)>0);if(r||o){const n=new t.Path;for(let t=0;t<e.length;t++){const s=e[(t-1+e.length)%e.length],r=e[t],o=e[(t+1)%e.length];if(s.x===r.x&&s.y===r.y)continue;const a=Jr(r,i);let c=Math.sqrt((s.x-r.x)**2+(s.y-r.y)**2),l=0!==c?Math.atan2(s.x-r.x,s.y-r.y):0;const h=Math.sin(l)*Math.min(a,c/2)+r.x,d=Math.cos(l)*Math.min(a,c/2)+r.y;c=Math.sqrt((o.x-r.x)**2+(o.y-r.y)**2),l=0!==c?Math.atan2(o.x-r.x,o.y-r.y):0;const u=Math.sin(l)*Math.min(a,c/2)+r.x,p=Math.cos(l)*Math.min(a,c/2)+r.y;if(0===t?n.moveTo(h,d):n.lineTo(h,d),a>0&&n.quadraticCurveTo(r.x,r.y,u,p),Xr(r)){const t=Jr(o,i),e=Math.sqrt((r.x-o.x)**2+(r.y-o.y)**2),s=0!==e?Math.atan2(r.x-o.x,r.y-o.y):0,a=Kr({x:u,y:p},{x:Math.sin(s)*Math.min(t,e/2)+o.x,y:Math.cos(s)*Math.min(t,e/2)+o.y},r.bulge);a&&n.absarc(a.cx,a.cy,a.radius,a.startAngle,a.endAngle,a.clockwise)}}return new t.Shape(n.getPoints(s))}const a=new t.Shape;for(let t=0;t<e.length;t++)0===t?a.moveTo(e[t].x,e[t].y):a.lineTo(e[t].x,e[t].y);return a}Kp("rect",t=>new Sv(t));class Av extends wv{get shape(){const{path:t=[],round:e=0}=this.component.state;return kv(t,{round:e,divisions:24})}build(){Object.getPrototypeOf(wv.prototype).build.call(this);const e=this.effectiveDepth,n=this.shape;if(!n)return;const i=this.boundUVGenerator,s=this.minMax;if(i&&void 0!==s.minX&&void 0!==s.maxX&&void 0!==s.minY&&void 0!==s.maxY){const n=new t.Shape;n.moveTo(s.minX,s.minY),n.lineTo(s.maxX,s.minY),n.lineTo(s.maxX,s.maxY),n.lineTo(s.minX,s.maxY),n.closePath(),i.setShape({extrudedShape:n,extrudedOptions:{depth:e}})}else i&&i.setShape({extrudedShape:n,extrudedOptions:{depth:e}});const r=this.createGeometry(n),o=this.createMaterials();this._mesh=new t.Mesh(r,o),this._mesh.rotation.x=-Math.PI/2,this._mesh.rotation.y=-Math.PI,this._mesh.rotation.z=-Math.PI,this._mesh.castShadow=!0,this.object3d.add(this._mesh),this.updateFillStyle(),this.updateStrokeStyle()}createGeometry(e){const n=this.effectiveDepth,{lineWidth:i=0}=this.component.state,s={steps:1,depth:n,bevelEnabled:i>0,bevelThickness:0,bevelSize:i,bevelSegments:1,UVGenerator:this.boundUVGenerator},r=new t.ExtrudeGeometry(e,s),o=this.minMax;if(void 0!==o.minX&&void 0!==o.maxX&&void 0!==o.minY&&void 0!==o.maxY){const t=(o.minX+o.maxX)/2,e=(o.minY+o.maxY)/2;r.translate(-t,-e,0),r.computeBoundingBox();const n=r.boundingBox;n&&r.translate(0,0,-(n.min.z+n.max.z)/2)}else r.center();return r}get minMax(){if(!this._minMax){const{path:t}=this.component.state;let e,n,i,s;t.forEach((t,r)=>{if(0==r)return e=i=t.x,void(n=s=t.y);e=Math.min(e,t.x),i=Math.max(i,t.x),n=Math.min(n,t.y),s=Math.max(s,t.y)}),this._minMax={minX:e,minY:n,maxX:i,maxY:s}}return this._minMax}}Kp("polygon",t=>new Av(t));class Ev extends wv{get shape(){const{cx:e=0,cy:n=0,rx:i=1,ry:s=1,ratio:r=50,startAngle:o=0,endAngle:a=2*Math.PI,anticlockwise:c=!1}=this.component.state,l=Math.abs(i),h=Math.abs(s),d=new t.EllipseCurve(e,n,l,h,o,a,c,0),u=new t.Shape(d.getPoints(50)),p=l/100*r,f=h/100*r;if(p>0&&f>0){const i=new t.EllipseCurve(e,n,p,f,o,a,c,0),s=new t.Path(i.getPoints(50));u.holes.push(s)}return u}}Kp("donut",t=>new Ev(t));class Cv extends wv{get shape(){const{x1:e=0,y1:n=0,x2:i=0,y2:s=0,x3:r=0,y3:o=0,round:a=0}=this.component.state,c=[{x:e,y:n},{x:i,y:s},{x:r,y:o}];if(a>0){const e=new t.Path;for(let t=0;t<c.length;t++){const n=c[(t-1+c.length)%c.length],i=c[t],s=c[(t+1)%c.length];let r=Math.sqrt((n.x-i.x)**2+(n.y-i.y)**2),o=0!==r?Math.atan2(n.x-i.x,n.y-i.y):0;const l=Math.sin(o)*Math.min(a,r/2)+i.x,h=Math.cos(o)*Math.min(a,r/2)+i.y;r=Math.sqrt((s.x-i.x)**2+(s.y-i.y)**2),o=0!==r?Math.atan2(s.x-i.x,s.y-i.y):0;const d=Math.sin(o)*Math.min(a,r/2)+i.x,u=Math.cos(o)*Math.min(a,r/2)+i.y;0===t?e.moveTo(l,h):e.lineTo(l,h),e.quadraticCurveTo(i.x,i.y,d,u)}return new t.Shape(e.getPoints(12))}const l=new t.Shape;return l.moveTo(e,n),l.lineTo(i,s),l.lineTo(r,o),l.closePath(),l}}Kp("triangle",t=>new Cv(t));class Tv extends wv{get shape(){const{ratio:e=30,wing:n=5,cx:i=0,cy:s=0,rx:r=1,ry:o=1}=this.component.state;if(n<3)return null;const a=Math.PI/2,c=2*Math.PI/n,l=r-e/100*r,h=o-e/100*o,d=new t.Shape;d.moveTo(i+r*Math.cos(-a),s+o*Math.sin(-a)),d.lineTo(i+(r-l)*(Math.cos(c-a)+Math.cos(0-a))/2,s+(o-h)*(Math.sin(c-a)+Math.sin(0-a))/2);for(let t=1;t<n;t++)d.lineTo(i+r*Math.cos(c*t-a),s+o*Math.sin(c*t-a)),d.lineTo(i+(r-l)*(Math.cos(c*(t+1)-a)+Math.cos(c*t-a))/2,s+(o-h)*(Math.sin(c*(t+1)-a)+Math.sin(c*t-a))/2);return d.closePath(),d}}Kp("star",t=>new Tv(t));const Pv=new Map;function Ov(t){return t.userData.__bankOwned=!0,t}const Dv={primitive(e){const n="primitive::"+function(t){switch(t.kind){case"cylinder":return`cylinder|${t.segments??0}`;case"sphere":return`sphere|${t.segments??0}|${t.heightSegments??0}`;default:return t.kind}}(e);let i=Pv.get(n);return i||Pv.set(n,i=Ov(function(e){switch(e.kind){case"box":return new t.BoxGeometry(1,1,1);case"plane":return new t.PlaneGeometry(1,1);case"cylinder":return new t.CylinderGeometry(.5,.5,1,e.segments??16);case"sphere":return new t.SphereGeometry(.5,e.segments??16,e.heightSegments??Math.max(2,Math.round((e.segments??16)/2)))}}(e))),i},shaped(t,e){const n="shaped::"+t;let i=Pv.get(n);return i||Pv.set(n,i=Ov(e())),i},owns:t=>!0===t.userData?.__bankOwned,get size(){return Pv.size},has:t=>Pv.has("primitive::"+t)||Pv.has("shaped::"+t),dispose(){for(const t of Pv.values())t.dispose();Pv.clear()}},Iv=[8,12,16],zv={cylinder:25,sphere:32},Rv=3,jv=128;function Lv(t,e){return"number"==typeof t&&Number.isFinite(t)?Math.min(jv,Math.max(3,Math.floor(t))):e}function Fv(t,e){return"number"==typeof t&&Number.isFinite(t)?Math.min(jv,Math.max(2,Math.floor(t))):Math.max(2,Math.round(e/2))}function Nv(t){return Iv.includes(t)}const Hv={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"number",label:"segments",name:"segments",property:"segments"},{type:"number",label:"height-segments",name:"heightSegments",property:"heightSegments"}],help:"scene/component/sphere"};class Bv extends cv{buildGeometry(){const t=this.component.state,e=Lv(t.segments,zv.sphere),n=Fv(t.heightSegments,e);this.object3d.geometry=Dv.primitive({kind:"sphere",segments:e,heightSegments:n})}updateDimension(){const{rx:t=0,ry:e=0,rz:n}=this.component.state,i=n??t;this.setDimensionScale(2*t,2*i,2*e)}get effectiveDepth(){const{rx:t=0,rz:e}=this.component.state,n=e??t;return Math.max(2*n,1)}topOutline(){const{rx:t=0,ry:e=0}=this.component.state;if(!(t>0&&e>0))return null;return vv(t,e,Lv(this.component.state.segments,zv.sphere))}}let Yv=class extends bg{get hasTextProperty(){return!1}is3dish(){return!0}buildRealObject(){return new Bv(this)}get nature(){return Hv}};Yv=Wm([Dy("sphere")],Yv);class Vv extends xu{getObject3dInstance(){return new t.Sprite}build(){super.build(),this.buildMaterial()}get cz(){const{zPos:t=0}=this.component.state,{height:e}=this.component.bounds,{tz:n=0}=this.component.delta(),i=this.component.parent?._realObject;return t+n+e/2-(i?.geometricOffsetY??0)}get geometricOffsetY(){const{height:t=0}=this.component.bounds;return t/2}updateAlpha(){const{alpha:t=1,fillStyle:e}=this.component.state;tu(this.object3d.material,0,e)}updateFillStyle(){const{fillStyle:t}=this.component.state,e=this.object3d.material;if(!e)return;const n=xu.buildFillStyleTexture(this.component);n?(e.map&&e.map.dispose(),n.needsUpdate=!0,e.map=n):"string"==typeof t&&("transparent"!==t?e.color.set(eu(t)):e.opacity=0)}}class Gv extends Vv{buildMaterial(){const e=this.object3d.material;e&&e.dispose(),this.object3d.material=new t.SpriteMaterial({map:J_(this.component),alphaTest:.01,sizeAttenuation:!1})}get scale(){const{width:t,height:e}=this.component.bounds,n=this.threeContainer,{width:i=1,height:s=1}=n?.bounds??{},{scale:r=1}=this.component.state;return{x:r*t/i,y:r*e/s,z:r}}update(){this.build(),this.updateHidden()}updateFillStyle(){this.update()}updateStrokeStyle(){this.update()}updateAlpha(){this.update()}updateText(){this.update()}}const $v={mutable:!1,resizable:!0,rotatable:!0,properties:[]};let Uv=class extends(Oc(Tc)){get hasTextProperty(){return!1}is3dish(){return!0}buildRealObject(){return new Gv(this)}get nature(){return $v}};Uv=Wm([Dy("sprite")],Uv);const Wv={mutable:!1,resizable:!0,rotatable:!0,properties:[],help:"scene/component/cube"};class qv extends cv{buildGeometry(){this.object3d.geometry=Dv.primitive({kind:"box"})}topOutline(){const{width:t=0,height:e=0}=this.component.state;return t>0&&e>0?_v(t,e):null}}let Xv=class extends(Oc(Tc)){get hasTextProperty(){return!1}is3dish(){return!0}buildRealObject(){return new qv(this)}get nature(){return Wv}};Xv=Wm([Dy("cube")],Xv);const Kv={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"number",label:"segments",name:"segments",property:"segments"}],help:"scene/component/cylinder"};class Qv extends cv{buildGeometry(){const t=Lv(this.component.state.segments,zv.cylinder);this.object3d.geometry=Dv.primitive({kind:"cylinder",segments:t})}updateDimension(){const{rx:t=0,ry:e=0,depth:n=1}=this.component.state;this.setDimensionScale(2*t,n,2*e)}topOutline(){const{rx:t=0,ry:e=0}=this.component.state;if(!(t>0&&e>0))return null;return vv(t,e,Lv(this.component.state.segments,zv.cylinder))}}let Zv=class extends bg{get hasTextProperty(){return!1}is3dish(){return!0}buildRealObject(){return new Qv(this)}get nature(){return Kv}};Zv=Wm([Dy("cylinder")],Zv);const Jv={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"color",label:"box-color",name:"boxColor",property:"boxColor"}],help:"scene/component/banner"};class tx extends xu{get zPriority(){return fu.DECAL}build(){super.build();const{width:t=1,height:e=1,depth:n=1}=this.component.state;this.object3d.add(this.createCube(t,e,n));const i=this.createTextureBoard(t,n);i.position.set(0,0,.5*e+1),this.object3d.add(i)}createCube(e,n,i){const{boxColor:s="#ccaa76"}=this.component.state,r=Pd(this.component.state.material3d),o=new t.BoxGeometry(e,i,n),a=new t.MeshStandardMaterial({color:s,side:t.FrontSide});Id(a,r);const c=new t.Mesh(o,a);return c.castShadow=r.castShadow,c.receiveShadow=r.receiveShadow,c}createTextureBoard(e,n){const i=Pd(this.component.state.material3d),{fillStyle:s="#ccaa76"}=this.component.state,r=xu.buildFillStyleTexture(this.component),o=new t.MeshStandardMaterial(r?{map:r}:{color:s||"#ccaa76",side:t.FrontSide});Id(o,i);const a=new t.PlaneGeometry(e,n,1,1),c=new t.Mesh(a,o);return c.castShadow=i.castShadow,c.receiveShadow=i.receiveShadow,c}updateMaterial3d(){super.updateMaterial3d();const t=Pd(this.component.state.material3d);this.object3d.traverse(e=>{if(e.isMesh){const n=e.material;n&&Id(n,t),e.castShadow=t.castShadow,e.receiveShadow=t.receiveShadow}})}updateFillStyle(){this.update()}onchange(t,e){super.onchange(t,e),"boxColor"in t&&this.update()}}let ex=class extends(Oc(Tc)){get hasTextProperty(){return!1}is3dish(){return!0}get nature(){return Jv}buildRealObject(){return new tx(this)}};var nx;ex=Wm([Dy("banner")],ex);const ix={far:1e5,fov:80,near:1,zoom:1},sx={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"number",label:"near",name:"near"},{type:"number",label:"far",name:"far"},{type:"number",label:"fov",name:"fov"},{type:"number",label:"zoom",name:"zoom"},{type:"checkbox",label:"show-helper",name:"showHelper"}],help:"scene/component/camera"};class rx extends xu{getObject3dInstance(){return new t.Mesh}updateCamera(){const{near:e=ix.near,far:n=ix.far,fov:i=ix.fov,zoom:s=ix.zoom,showHelper:r}=this.component.state;this.camera.far=n,this.camera.fov=i,this.camera.near=e,this.camera.zoom=s,r?this.helper||(this.helper=new t.CameraHelper(this.camera),this.object3d.add(this.helper)):this.helper&&(this.object3d.remove(this.helper),delete this.helper)}build(){super.build();const{width:e=0,height:n=0,depth:i=0,fillStyle:s="lightgray"}=this.component.state;this.object3d.geometry=new t.BoxGeometry(e,i,n);const r=Pd(this.component.state.material3d),o=new t.MeshStandardMaterial({color:s});Id(o,r),this.object3d.material=o,this.object3d.castShadow=r.castShadow,this.object3d.receiveShadow=r.receiveShadow,this.camera=new t.PerspectiveCamera,this.camera.position.set(0,0,0),this.object3d.add(this.camera),this.object3d.lookAt(0,0,0),this.updateCamera()}updateMaterial3d(){super.updateMaterial3d();const t=this.object3d.material;if(!t)return;const e=Pd(this.component.state.material3d);Id(t,e),this.object3d.castShadow=e.castShadow,this.object3d.receiveShadow=e.receiveShadow}}let ox=nx=class extends(Oc(Tc)){get hasTextProperty(){return!1}is3dish(){return!0}static get image(){return nx._image||(nx._image=new Image,nx._image.src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA1IAAANSAQMAAABV6G1EAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAABlBMVEX6+voBAQGV71ZvAAAFO0lEQVR42u3dMZLkNBiGYakUKFRIqKOISxDvETiCTBEQcgQOQE7clyAi8REm7KDXIhgYoMa/7fbIX+2K9w022MCP/25Z28GW5RwRERERERERERERERERERERERERERERERERERERERERERERERHRl9mv7fdPn7879sf8Mcq3J3r5EJXaUy3Wddrcd6qNybx9F2/lZ63H+nVCa9Oe9elZa5ksa/dDbE+3fsm4v27C89bd+i6W3l+XdcnSWtuxyvPW+hqorbWb0Jr7Pl3m4tjfVMIZ625d6L5pxTPWw7rQY9P6pqu1dF8aq5d83cE3rXrGWluIxV6h53eotv4c1FigureLn7Nm66ZvvZf8SSues16sD2jubz2sC839fmvYiz7t//LJna27wsr7VjlnNWtPeHTfNlae2bZvnaTePUd+74fqV2LNxv6zdN8O3z9HSWhlc4F+dOvdsKbe2+F7q+zPddq6W2ts6r31vrN825/rtPWwvvcL5losy11uxQNz5U6fYT4w12mrWf80TUNZdetXal/LtwNW6WOFI1Y9bU3GVnfFXM9bneZKwrmKcK4qnKsK52q6uULTzRWFVjpkta/OykKrCq02puWFVhRaSWjlQa0itJrO8oNaQWgloZWFVhnUqjrLN50VBrWi0MpCqwitOqjVdFYQWlFopUGtLLSq0GpjWl5oRaGVBrWy0KpCq+ksP6gVhFYSWllolUGtqrNW/jvBZVYY1IpCKwutIrTqoFbTWUFoxUGtJLSK0KpCq41peaEVhVYa1MpCqwqtprP8oFYUWklo5UGtIrSazvJCKwxqRaGVhVYZ1Ko664ems34UWj8Nav0stBoWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhbW/9L6RWgp37WofIek8j2cyveLTkqrCq0itLLQSkJL+Q5k5budle/HVr73e/24gAHenZ6FlvK9+srzAoLQUp65oDy3QnoeRxFaWWgpz2pRnncThJbyzCDpuUtVaBWhlYWW8qwx5RlqynPovNBSnuUnPaOwCK0stJLQUp4BqjzbVHk+rFNaVWgVoZWFlvJc6Si0lGdzK88cV57bLj2PvgitLLSS0IpCKwgtL7Sc0qpCqwitLLSS0IpCKwgtL7Sc0qpCqwitLLSS0IpCKwgtL7Sc0qpCqwitLLSS0IpCKwgtL7Sc0qpCqwitLLSS0IpCKwgtL7Sc0qpCqxyyahcrH7JKFysJ54rCuYJwLi+cywnn+vdlLp+rCOfKwrnStXP95zLxiJX7WEFoeaHljO/xEqsaf9/FWqz1bM+VzloP655df2uxrnP9XPHKue7OeMDsuWInyx+Y67T1Yv0gs+cKvay6P5fvZZULrdnYFBbbcr2sdKF1MxbZFdZkLLItq3aay6/vJ102eusD2rJKl633nw/o3n+uxbrpLSv1svL6M95hQ3xYNz33t16sC21Zoc+28Xahm+u+Ic7WhbYs1+dRfrvQ5LpvHOaFNq3SZ8n/faEt6twDtli7wrJpxT6P1183/di0Ti36u3XT903Ld1qGrzf9smmdWhyTddNzf8t8UqdtK/dZGq8P2DZ1ZnHcrQ/osWO5PkvDuby7NE58Yctk7Qq3PSv3+bpc3F0aJ56wF+uLX9xu6eOb4es9z/vWc0vR3oZuByjnf2t/fP/54B/2WvvWEREREREREREREREREREREREREREREREREREREREREREREREREX2J/QlrTpqHD8xO1gAAAABJRU5ErkJggg=="),nx._image}render(t){const{left:e,top:n,width:i,height:s}=this.bounds;t.beginPath(),this.drawImage(t,nx.image,e,n,i,s)}buildRealObject(){return new rx(this)}get nature(){return sx}};ox=nx=Wm([Dy("camera")],ox);const ax={mutable:!1,resizable:!0,rotatable:!0,properties:[...Py],"value-property":"source",help:"scene/component/gltf-object"};let cx=class extends(Oy(Oc(Tc))){get nature(){return ax}};cx=Wm([Dy("gltf-object")],cx);const lx={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"select",label:"light-type",name:"lightType",property:{options:["","point","directional"]}},{type:"number",label:"intensity",name:"intensity"},{type:"number",label:"distance",name:"distance"},{type:"number",label:"decay",name:"decay"},{type:"checkbox",label:"cast-shadow",name:"castShadow"},{type:"number",label:"near",name:"near",placeholder:"0.5"},{type:"number",label:"far",name:"far",placeholder:"1000"},{type:"number",label:"fov",name:"fov",placeholder:"90"},{type:"number",label:"zoom",name:"zoom",placeholder:"1"},{type:"checkbox",label:"show-helper",name:"showHelper"}],help:"scene/component/light"};class hx extends xu{updatePointLight(){const{lightType:e="point",distance:n=0,intensity:i=10,decay:s=1,fillStyle:r="white",castShadow:o,near:a=.5,far:c=1e3,fov:l=90,zoom:h=1,showHelper:d}=this.component.state;if(this.object3d.color=new t.Color(r),"point"==e&&(this.object3d.distance=n,this.object3d.decay=s),this.object3d.intensity=i,this.object3d.castShadow=o,o){const t=this.object3d.shadow?.camera;t.far=c,t.near=a,t.fov=l,t.zoom=h}if(d){const e=this.object3d.shadow?.camera;this.helper||(this.helper=new t.CameraHelper(e),this.object3d.add(this.helper))}else this.helper&&(this.object3d.remove(this.helper),delete this.helper)}getObject3dInstance(){const{lightType:e="point"}=this.component.state;return"point"==e?new t.PointLight:new t.DirectionalLight}update(){this.clear(),this.build(),this.updateDimension(),this.updateHidden(),this.updatePointLight()}}let dx=class extends bg{get hasTextProperty(){return!1}is3dish(){return!0}buildRealObject(){return new hx(this)}get anchors(){return[]}get nature(){return lx}};dx=Wm([Dy("light")],dx);const ux={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"number",label:"depth",name:"depth",property:"depth"}],help:"scene/component/wall"};class px extends cv{buildGeometry(){this.object3d.geometry=Dv.primitive({kind:"box"})}topOutline(){const{width:t=0,height:e=0}=this.component.state;return t>0&&e>0?_v(t,e):null}}let fx=class extends(Oc(Tc)){get hasTextProperty(){return!1}is3dish(){return!0}buildRealObject(){return new px(this)}get nature(){return ux}};fx=Wm([Dy("wall")],fx);const mx={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"number",label:"depth",name:"depth",property:"depth"},{type:"checkbox",label:"hide-in-2d-view",name:"hideIn2DView"},{type:"checkbox",label:"hide-in-3d-view",name:"hideIn3DView"}],help:"scene/component/floor-plate"};class gx extends xu{get zPriority(){return fu.FLOOR}get receivingSurfaceY(){return this.placementSurfaceY()}resolveShadow(){const t=this.component.state,e=t.material3d,{alpha:n=1,fillStyle:i}=t,s=n>=.9&&"none"!==i;return{receive:e?.receiveShadow??!0,cast:e?.castShadow??s}}updateHidden(){const t=this.component.state,e=!!this.component.app?.isViewMode;this.object3d.visible=!(t.hidden||e&&t.hideIn3DView)}clear(){return this._topTexture&&(this._topTexture.dispose(),this._topTexture=void 0),this._mesh=void 0,super.clear()}build(){super.build();const{width:e,height:n,depth:i=1}=this.component.state;if(!e||!n)return;const s=Math.abs(e),r=Math.abs(n),o=Math.max(i,.5),a=new t.BoxGeometry(s,o,r),c=this._buildTopMaterial(),l=this._buildSideMaterial(),h=[l,l,c,l,l,l];this._mesh=new t.Mesh(a,h),this._mesh.position.y=0;const{cast:d,receive:u}=this.resolveShadow();this._mesh.castShadow=d,this._mesh.receiveShadow=u,this.object3d.add(this._mesh)}_buildTopMaterial(){const{alpha:e=1,fillStyle:n}=this.component.state,i=Pd(this.component.state.material3d),s=xu.buildFillStyleTexture(this.component);if(s){this._topTexture=s;const e=new t.MeshStandardMaterial({map:s,side:t.DoubleSide});return tu(e,0,n),e.depthWrite=e.opacity>=.9,Id(e,i),e}const r="string"==typeof n&&"none"!==n?eu(n):"#e0e0e0",o=new t.MeshStandardMaterial({color:r,side:t.DoubleSide});return tu(o,0,n),o.depthWrite=o.opacity>=.9,Id(o,i),o}_buildSideMaterial(){const{strokeStyle:e,alpha:n=1}=this.component.state,i="string"==typeof e&&e?eu(e):"#999999",s=Pd(this.component.state.material3d),r=new t.MeshStandardMaterial({color:i});return Id(r,s),r.side=t.DoubleSide,tu(r,0,e),r.depthWrite=r.opacity>=.9,r}updateAlpha(){if(!this._mesh)return;const{alpha:t=1,fillStyle:e,strokeStyle:n}=this.component.state,i=this._mesh.material;for(let t=0;t<i.length;t++){const s=i[t];tu(s,0,2===t?e:n),s.depthWrite=s.opacity>=.9}}updateFillStyle(){if(!this._mesh)return;this._topTexture&&(this._topTexture.dispose(),this._topTexture=void 0);const t=this._mesh.material;t[2].dispose(),t[2]=this._buildTopMaterial()}updateStrokeStyle(){if(!this._mesh)return;const t=this._mesh.material,e=this._buildSideMaterial();for(let n=0;n<t.length;n++)2!==n&&(t[n].dispose(),t[n]=e)}}let yx=class extends Jl{get hasTextProperty(){return!1}is3dish(){return!0}buildRealObject(){return new gx(this)}get nature(){return mx}get hidden(){return!!this.getState("hideIn2DView")||super.hidden}};yx.requires3d=!0,yx=Wm([Dy("floor-plate")],yx);function bx(e,n={}){const i=n.size??5,s=n.color??4500172,r=n.emissive??2245734,o=new t.SphereGeometry(i,16,12),a=new t.MeshStandardMaterial({color:s,emissive:r,emissiveIntensity:.15,metalness:.3,roughness:.4,transparent:!0,opacity:.35}),c=new t.Mesh(o,a);n.position&&c.position.set(n.position[0],n.position[1],n.position[2]),c.userData.alwaysRaycast=!0,c.scale.setScalar(1),c.visible=n.visible??!(!0===e.app?.isViewMode);const l=()=>{a.emissiveIntensity=.9,a.opacity=.95,c.scale.setScalar(1.35),e.invalidate?.()},h=()=>{a.emissiveIntensity=.15,a.opacity=.35,c.scale.setScalar(1),e.invalidate?.()};return e.on("mouseenter",l),e.on("mouseleave",h),c.userData.dispose=()=>{e.off("mouseenter",l),e.off("mouseleave",h)},c}class _x extends cv{get zPriority(){return fu.DECAL}get syncZPosOffset(){return this.effectiveDepth}get geometricOffsetY(){return this.effectiveDepth}buildGeometry(){const{width:e,height:n}=this.component.state,i=Math.abs(e)||1,s=Math.abs(n)||1,r=new t.PlaneGeometry(i,s);r.rotateX(-Math.PI/2),this.object3d.geometry=r}updateDimension(){this.update()}build(){super.build();const{width:t,height:e}=this.component.state,n=Math.abs(t)||1,i=Math.abs(e)||1,s=Math.max(2,.04*Math.min(n,i));this.object3d.add(bx(this.component,{size:s,position:[n/2-s,s,-i/2+s]}))}}const vx={mutable:!1,resizable:!0,rotatable:!0,properties:[],help:"scene/component/decal"};let xx=class extends(Cy(Oc(Tc))){buildRealObject(){return new _x(this)}get nature(){return vx}};xx=Wm([Dy("decal")],xx);class wx extends xu{getObject3dInstance(){return new t.Group}get allowedGizmoModes(){return this.component.isGroup?.()?["translate"]:null}}const Mx="#dde2e8",Sx="#9c9c9c",kx="#e8e8ec",Ax=.35;function Ex(e,n,i,s,r){if(!n.visible)return new t.MeshStandardMaterial({transparent:!0,opacity:0,depthWrite:!1});const o=n.alpha*i,a="wall"===s?Mx:"floor"===s?Sx:kx,c=new t.MeshStandardMaterial({metalness:0,roughness:"wall"===s?.6:.85,transparent:o<1,opacity:o,side:r?t.BackSide:t.DoubleSide});return function(t,e,n,i,s,r){if("string"==typeof n&&n&&"transparent"!==n)t.color.set(n);else{if(n&&"object"==typeof n){const i=!r,o=xu.buildFillStyleTexture(e,n,{mirror:i,rotation:s});if(o)return t.map&&t.map.dispose(),t.map=o,void t.color.set("#ffffff")}t.color.set(i)}}(c,e,n.fillStyle,a,n.rotation,n.mirror),c}class Cx extends wx{get zPriority(){return fu.BACKDROP}get position(){if(this.component.state.fitToBoard){return{x:0,y:super.position.y,z:0}}return super.position}build(){super.build();const e=this.component.state;let n=e.width,i=e.height;if(e.fitToBoard){const t=this.component.rootModel,e=t?.state;e&&Number.isFinite(e.width)&&Number.isFinite(e.height)&&(n=e.width,i=e.height)}const s=this.effectiveDepth||Math.min(n,i)||200,r=e.alpha??1,o=!1!==e.seeThrough,a={east:this._resolveFace("east",Mx,!0,Ax),west:this._resolveFace("west",Mx,!0,Ax),north:this._resolveFace("north",Mx,!0,Ax),south:this._resolveFace("south",Mx,!0,Ax),floor:this._resolveFace("floor",Sx,!0,1),ceiling:this._resolveFace("ceiling",kx,!0,1)},c=[Ex(this.component,a.east,r,"wall",o),Ex(this.component,a.west,r,"wall",o),Ex(this.component,a.ceiling,r,"ceiling",o),Ex(this.component,a.floor,r,"floor",o),Ex(this.component,a.south,r,"wall",o),Ex(this.component,a.north,r,"wall",o)],l=new t.BoxGeometry(n,s,i),h=new t.Mesh(l,c);if(h.receiveShadow=!0,this.object3d.add(h),this.component.app?.isEditMode){const e=new t.LineBasicMaterial({color:4473941,transparent:!0,opacity:.7}),n=new t.LineSegments(new t.EdgesGeometry(l),e);this.object3d.add(n)}const d=Math.max(2,.04*Math.min(n,i,s));this.object3d.add(bx(this.component,{size:d,position:[n/2,s/2+d,-i/2]}))}_resolveFace(t,e,n,i){const s=this.component.state,r=s.faces?.[t]??{},o=r.visible,a=r.alpha,c=r.rotation,l=90===c||180===c||270===c?c:0;return{fillStyle:r.fillStyle??e,visible:"boolean"==typeof o?o:n,alpha:"number"==typeof a&&Number.isFinite(a)?a:i,rotation:l,mirror:!0===r.mirror}}updateDimension(){}onchange(t,e){["alpha","width","height","depth","fitToBoard","faces","seeThrough"].some(e=>e in t)?this.update():super.onchange(t,e)}updateAlpha(){}}const Tx={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"checkbox",label:"fit-to-board",name:"fitToBoard"},{type:"checkbox",label:"see-through",name:"seeThrough"},{type:"backdrop-faces",label:"",name:"faces"}],help:"scene/component/backdrop"};let Px=class extends(Cy(Oc(Tc))){buildRealObject(){return new Cx(this)}get nature(){return Tx}added(t){super.added?.(t),this.state.fitToBoard&&(this._syncFromRoot(!0),this._attachRootListener())}async ready(){await super.ready(),this.state.fitToBoard&&this._syncFromRoot(!1)}removed(t){this._detachRootListener(),super.removed?.(t)}dispose(){this._detachRootListener(),super.dispose?.()}onchange(t,e){"fitToBoard"in t&&(t.fitToBoard?(this._syncFromRoot(!0),this._attachRootListener()):this._detachRootListener()),super.onchange?.(t,e)}_syncFromRoot(t=!1){const e=this.rootModel;if(!e||e===this)return;const n=e.state;if(!n)return;const i={},s=Number.isFinite(n.width)?n.width:this.state.width,r=Number.isFinite(n.height)?n.height:this.state.height;s!==this.state.width&&(i.width=s),r!==this.state.height&&(i.height=r);const o=Number.isFinite(n.left)?n.left:0,a=Number.isFinite(n.top)?n.top:0;if(o!==this.state.left&&(i.left=o),a!==this.state.top&&(i.top=a),t){const t=this.state.depth;if(!("number"==typeof t&&Number.isFinite(t)&&t>0)){const e=Math.min(s,r);e!==t&&(i.depth=e)}}Object.keys(i).length>0&&this.set(i)}_attachRootListener(){if(this._onRootChange)return;const t=this.rootModel;t&&t!==this&&(this._onRootChange=t=>{("width"in t||"height"in t||"left"in t||"top"in t)&&this._syncFromRoot()},t.on?.("change",this._onRootChange))}_detachRootListener(){if(!this._onRootChange)return;const t=this.rootModel;t?.off?.("change",this._onRootChange),this._onRootChange=void 0}};function Ox(t,e){return"none"===t?0:t.endsWith("arrow")?1.5*e:0}function Dx(e,n,i,s){const r=[];for(let o=1;o<=s;o++){const a=o/s,c=1-a;r.push(new t.Vector3(c*c*e.x+2*c*a*n.x+a*a*i.x,c*c*e.y+2*c*a*n.y+a*a*i.y,c*c*e.z+2*c*a*n.z+a*a*i.z))}return r}Px=Wm([Dy("backdrop")],Px);class Ix extends xu{getObject3dInstance(){return new t.Group}get gizmoTransformable(){return!0}get syncZPosOffset(){return 0}get geometricOffsetY(){return 0}syncFromObject3D(){}applyDimensionFromGizmo(t){}build(){super.build(),this._buildLine()}get smoothedPath(){const e=this.worldPath;if(e.length<2)return e;const{round:n=0}=this.component.state;if(n<=0||e.length<3)return e;const i=[];i.push(e[0]);for(let s=1;s<e.length;s++){const r=e[s-1],o=e[s],a=e[s+1];if(!a){i.push(o);break}const c=r.x-o.x,l=r.y-o.y,h=r.z-o.z,d=Math.sqrt(c*c+l*l+h*h),u=Math.min(n,d/2),p=a.x-o.x,f=a.y-o.y,m=a.z-o.z,g=Math.sqrt(p*p+f*f+m*m),y=Math.min(n,g/2),b=d>0?new t.Vector3(o.x+c/d*u,o.y+l/d*u,o.z+h/d*u):o.clone(),_=g>0?new t.Vector3(o.x+p/g*y,o.y+f/g*y,o.z+m/g*y):o.clone();i.push(b),i.push(...Dx(b,o,_,8))}return i}_buildLine(){const e=this.smoothedPath;if(e.length<2)return;const{strokeStyle:n,lineWidth:i=2,alpha:s=1,lineDash:r,begin:o="none",beginSize:a="size5",end:c="none",endSize:l="size5"}=this.component.state,h=Math.max(i,1),d="string"==typeof n&&"transparent"!==n?eu(n):"#000000",u=new t.Color(d),p=this._getResolution(),f=o,m=c,g=Ox(f,h),y=Ox(m,h),b=e[0],_=e[e.length-1],v=(new t.Vector3).subVectors(e[1],b).normalize(),x=(new t.Vector3).subVectors(e[e.length-2],_).normalize(),k=[...e];g>0&&(k[0]=b.clone().add(v.clone().multiplyScalar(g))),y>0&&(k[k.length-1]=_.clone().add(x.clone().multiplyScalar(y)));const A=new S;A.setPositions(k.flatMap(t=>[t.x,t.y,t.z]));const E=function(t,e){switch(t){case"round-dot":return{dashSize:e,gapSize:e};case"square-dot":return{dashSize:2*e,gapSize:e};case"dash":return{dashSize:4*e,gapSize:1.5*e};case"dash-dot":return{dashSize:4*e,gapSize:2*e};case"long-dash":return{dashSize:6*e,gapSize:3*e};case"long-dash-dot":return{dashSize:6*e,gapSize:2*e};case"long-dash-dot-dot":return{dashSize:6*e,gapSize:e};default:return null}}(r,h),C=new M({color:u.getHex(),linewidth:h,worldUnits:!0,transparent:s<1,opacity:s,resolution:p,dashed:!!E,dashSize:E?.dashSize??1,gapSize:E?.gapSize??1,dashScale:1});if(this._line2=new w(A,C),this._line2.computeLineDistances(),this.object3d.add(this._line2),"none"!==f){const e=Vp(f,Yp(a,h));if(e){const n=(new t.Quaternion).setFromUnitVectors(new t.Vector3(1,0,0),v.clone().negate());this._placeTip(e,b,n,u,s,p)}}if("none"!==m){const e=Vp(m,Yp(l,h));if(e){const n=(new t.Quaternion).setFromUnitVectors(new t.Vector3(1,0,0),x.clone().negate());this._placeTip(e,_,n,u,s,p)}}}_placeTip(t,e,n,i,s,r){const o=t.mesh||t.line2||t.group;if(o){if(o.position.copy(e),o.setRotationFromQuaternion(n),t.mesh){const e=t.mesh.material;e.color.copy(i),e.transparent=s<1,e.opacity=s}else if(t.line2){const e=t.line2.material;e.color.copy(i),e.transparent=s<1,e.opacity=s,e.resolution.copy(r)}else t.group&&t.group.traverse(t=>{if(t.material){const e=t.material;e.color&&e.color.copy(i),e.transparent=s<1,e.opacity=s,e.resolution&&e.resolution.copy(r)}});this.object3d.add(o)}}_getResolution(){const e=this.threeContainer?.renderer3d;if(e){return e.getSize(new t.Vector2)}return new t.Vector2(window.innerWidth,window.innerHeight)}onGizmoDragEnd(t){const e=this._component,n=e.path;if(!n||n.length<2)return;const i=this.object3d,{width:s=0,height:r=0}=e.parent?.bounds??{},{x:o,y:a}=e.center,c=i.position,l=i.rotation,h=i.scale,d=this.position;if(Math.abs(c.x-d.x)<.001&&Math.abs(c.y-d.y)<.001&&Math.abs(c.z-d.z)<.001&&Math.abs(l.x)<.001&&Math.abs(l.y)<.001&&Math.abs(l.z)<.001&&Math.abs(h.x-1)<.001&&Math.abs(h.y-1)<.001&&Math.abs(h.z-1)<.001)return;const u=Ix.computeBakedPath(n,{x:o,y:a},{width:s,height:r},i);this._suppressOnchange=!0,e.set({rotation:0,rotationX:0,rotationY:0,zPos:0}),e.mutatePath(null,()=>u),this._suppressOnchange=!1,this.update()}static computeBakedPath(e,n,i,s){const r=i.width,o=i.height,a=n.x,c=n.y;return s.updateMatrixWorld(!0),e.map(e=>{const n=new t.Vector3(e.x-a,e.z||0,e.y-c).applyMatrix4(s.matrixWorld),i={x:n.x+r/2,y:n.z+o/2};return Math.abs(n.y)>.001&&(i.z=n.y),i})}updateStrokeStyle(){this.updateDimension()}updateAlpha(){this.updateDimension()}updateDimension(){this.clear(),this.build()}onchange(t,e){("path"in t||"from"in t||"to"in t)&&(this.updateDimension(),this.updatePosition()),("round"in t||"lineDash"in t||"lineWidth"in t||"begin"in t||"end"in t||"beginSize"in t||"endSize"in t)&&this.updateDimension(),super.onchange(t,e)}clear(){for(;this.object3d.children.length>0;){const t=this.object3d.children[0];this.object3d.remove(t),cu(t)}return this._line2=void 0,super.clear()}}class zx extends Ix{get worldPath(){const e=this.component.path;if(!e||e.length<2)return[];const{x:n,y:i}=this.component.center,s=this.component,r=s.fromEnd?.component?._realObject?.object3d?.position?.y??0,o=s.toEnd?.component?._realObject?.object3d?.position?.y??0;return e.map((s,a)=>{const c=e.length>1?a/(e.length-1):0;return new t.Vector3(s.x-n,s.z||r+(o-r)*c,s.y-i)})}}Kp("line",t=>new zx(t));class Rx extends Ix{get worldPath(){const e=this.component.path;if(!e||e.length<2)return[];const{x:n,y:i}=this.component.center;return e.map(e=>new t.Vector3(e.x-n,e.z||0,e.y-i))}}Kp("polyline",t=>new Rx(t));class jx extends Ix{get worldPath(){const e=this.component.drawPath;if(!e||e.length<2)return[];const{x:n,y:i}=this.component.center,s=this.component,r=s.fromEnd?.component?._realObject?.object3d?.position?.y??0,o=s.toEnd?.component?._realObject?.object3d?.position?.y??0;return e.map((s,a)=>{const c=e.length>1?a/(e.length-1):0;return new t.Vector3(s.x-n,s.z||r+(o-r)*c,s.y-i)})}}function Lx(t,e=16){let n=Math.max(e,1);for(;n<t;)n*=2;return n}Kp("ortholine",t=>new jx(t)),Kp("group",t=>new wx(t));class Fx{constructor(e){this._count=0,this._placements=[],this._geometry=e.geometry,this._material=e.material,this._capacity=Math.max(1,e.capacity??16),this._name=e.name??"instanced",this._castShadow=e.castShadow??!0,this._receiveShadow=e.receiveShadow??!1,this.object3d=new t.Group,this.object3d.name=this._name,this._mesh=this._makeMesh(this._capacity),this.object3d.add(this._mesh)}_makeMesh(e){const n=new t.InstancedMesh(this._geometry,this._material,e);return n.name=this._name+"__instances",n.castShadow=this._castShadow,n.receiveShadow=this._receiveShadow,n.instanceMatrix.setUsage(t.DynamicDrawUsage),n.count=0,n}get mesh(){return this._mesh}get count(){return this._count}get capacity(){return this._capacity}place(t){const e=t.length;if(e>this._capacity){const t=Lx(e,this._capacity);this.object3d.remove(this._mesh),this._mesh.dispose(),this._capacity=t,this._mesh=this._makeMesh(t),this.object3d.add(this._mesh)}this._placements.length=e;for(let n=0;n<e;n++){const e=t[n];this._placements[n]=e,this._writeMatrix(n,e),void 0!==e.color&&this._writeColor(n,e.color)}this._count=e,this._mesh.count=e,this.commit()}setCount(t){if(t>this._capacity){const e=Lx(t,this._capacity),n=this._mesh.frustumCulled;this.object3d.remove(this._mesh),this._mesh.dispose(),this._capacity=e,this._mesh=this._makeMesh(e),this._mesh.frustumCulled=n,this.object3d.add(this._mesh)}this._placements.length=0,this._count=t,this._mesh.count=t}setMatrix(t,e){t<0||t>=this._count||this._mesh.setMatrixAt(t,e)}update(t,e){t<0||t>=this._count||(this._placements[t]=e,this._writeMatrix(t,e),void 0!==e.color&&this._writeColor(t,e.color),this.commit())}setRotation(t,e){if(t<0||t>=this._count)return;const n=this._placements[t];n&&(n.rotation=e,this._writeMatrix(t,n))}commitMatrices(){this._mesh.instanceMatrix.needsUpdate=!0}setColor(t,e){t<0||t>=this._count||(this._writeColor(t,e),this._mesh.instanceColor&&(this._mesh.instanceColor.needsUpdate=!0))}indexOf(t){return t>=0&&t<this._count?t:-1}commit(){this._mesh.instanceMatrix.needsUpdate=!0,this._mesh.instanceColor&&(this._mesh.instanceColor.needsUpdate=!0),this._mesh.computeBoundingSphere()}dispose(){this.object3d.remove(this._mesh),this._mesh.dispose(),this._placements.length=0,this._count=0}_writeMatrix(t,e){const n=Fx;n._p.set(e.position.x,e.position.y,e.position.z);const i=e.rotation;n._e.set(i?.x??0,i?.y??0,i?.z??0),n._q.setFromEuler(n._e);const s=e.scale;"number"==typeof s?n._s.set(s,s,s):n._s.set(s?.x??1,s?.y??1,s?.z??1),n._m.compose(n._p,n._q,n._s),this._mesh.setMatrixAt(t,n._m)}_writeColor(t,e){Fx._c.set(e),this._mesh.setColorAt(t,Fx._c)}}function Nx(t,e,n){const i=Math.max(1,Math.floor(t.x??1)),s=Math.max(1,Math.floor(t.y??1)),r=Math.max(1,Math.floor(t.z??1)),o=e.x??0,a=e.y??0,c=e.z??0,l=n?.x??0,h=n?.y??0,d=n?.z??0,u=[];for(let t=0;t<s;t++)for(let e=0;e<r;e++)for(let n=0;n<i;n++)u.push({position:{x:l+n*o,y:h+t*a,z:d+e*c}});return u}Fx._m=new t.Matrix4,Fx._p=new t.Vector3,Fx._q=new t.Quaternion,Fx._e=new t.Euler,Fx._s=new t.Vector3,Fx._c=new t.Color;class Hx extends xu{build(){super.build()}update(){}}const Bx={far:1e5,fov:80,near:1,zoom:1};class Yx extends xu{build(){super.build()}update(){super.update(),this.updateCamera()}getObject3dInstance(){return new t.PerspectiveCamera}updateCamera(){const{near:t=Bx.near,far:e=Bx.far,fov:n=Bx.fov,zoom:i=Bx.zoom}=this.component.state;this.object3d.far=e,this.object3d.fov=n,this.object3d.near=t,this.object3d.zoom=i}}class Vx extends cv{buildGeometry(){const{width:e,height:n}=this.component.state.dimension;this.object3d.geometry=new t.PlaneGeometry(e,n)}buildMaterial(){this.object3d.material=new t.MeshStandardMaterial({opacity:0,side:t.DoubleSide,blending:t.NoBlending})}}class Gx extends xu{getObject3dInstance(){return new t.Scene}dispose(){for(const t of this.object3d.children)cu(t);this._animationMixer&&(this._animationMixer.stopAllAction(),this._animationMixer.uncacheRoot(this.object3d),this._animationMixer=void 0),super.dispose()}clear(){return this._floor&&(this.object3d.remove(this._floor),this._floor.material instanceof Array?this._floor.material.forEach(t=>t.dispose()):this._floor.material.dispose(),this._floor.geometry.dispose(),delete this._floor),super.clear()}get floor(){return this._floor}set floor(t){this._floor&&(this.object3d.remove(this._floor),this._floor.clear(),delete this._floor),t&&(this._floor=t,this.object3d.add(t)),this.component.invalidate()}build(){super.build(),this.floor=mf(this.component)}updateTransform(){}updateDimension(){}updatePosition(){}updateRotate(){}updateScale(){}updateAlpha(){}updateHidden(){}get animationMixer(){return this._animationMixer||(this._animationMixer=new t.AnimationMixer(this.object3d)),this._animationMixer}}const $x=new Set(["cx","cy","cz","zPos","left","top","width","height","depth","lineWidth","rotationX","rotationY","rotation","scale","hidden","alpha","material3d","screenFixed"]);class Ux extends xu{get syncZPosOffset(){return this.effectiveDepth}get geometricOffsetY(){return this.effectiveDepth}constructor(t){super(t),this._origInvalidate=t.invalidate.bind(t),t.invalidate=()=>{this._origInvalidate(),this._refreshTextureNow()}}getObject3dInstance(){return new t.Mesh}build(){super.build();const{width:e,height:n}=this.component.bounds;if(!e||!n)return;const i=Pd(this.component.state.material3d),s=new t.PlaneGeometry(1,1);s.rotateX(-Math.PI/2),this.object3d.geometry=s;const r=J_(this.component),o=new t.MeshStandardMaterial({map:r});Id(o,i),o.transparent=!0,this.object3d.material=o,this.object3d.castShadow=i.castShadow,this.object3d.receiveShadow=i.receiveShadow}updateAlpha(){const{alpha:t=1,fillStyle:e}=this.component.state;tu(this.object3d.material,0,e)}get dimension(){const{width:t,height:e}=this.component.bounds;return{width:t||1,height:e||1,depth:1}}get scale(){const t=super.scale,{width:e,height:n}=this.dimension;return{x:t.x*e,y:t.y,z:t.z*n}}updateDimension(){this.updateTransform()}_debouncedRebuild(){this._debounceTimer&&clearTimeout(this._debounceTimer),this._debounceTimer=setTimeout(()=>{this._debounceTimer=void 0,this.update()},100)}_refreshTextureNow(){const t=this.object3d.material,e=t?.map;if(!e)return;const n=e.source?.data;n&&(ev(n,this.component,2),e.needsUpdate=!0)}update(){this.clear(),this.build(),this.updateDimension(),this.updateTransform(),this.updateHidden()}onchange(t,e){super.onchange(t,e);for(const e of Object.keys(t))if(!$x.has(e)){this._debouncedRebuild();break}}updateFillStyle(){this._debouncedRebuild()}updateStrokeStyle(){this._debouncedRebuild()}updateText(){this._debouncedRebuild()}updateMaterial3d(){super.updateMaterial3d();const t=this.object3d.material;if(!t)return;const e=Pd(this.component.state.material3d);Id(t,e),t.transparent=!0,this.object3d.castShadow=e.castShadow,this.object3d.receiveShadow=e.receiveShadow}clear(){return this._debounceTimer&&(clearTimeout(this._debounceTimer),this._debounceTimer=void 0),cu(this.object3d),super.clear()}dispose(){this._debounceTimer&&(clearTimeout(this._debounceTimer),this._debounceTimer=void 0),this._origInvalidate&&(this.component.invalidate=this._origInvalidate,this._origInvalidate=void 0),super.dispose()}}const Wx={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"select",label:"precision",name:"precision",property:{options:[{display:"High",value:"highp"},{display:"Medium",value:"mediump"},{display:"Low",value:"lowp"}]}},{type:"checkbox",label:"anti-alias",name:"antialias",property:"antialias"},{type:"checkbox",label:"3dmode",name:"threed",property:"threed"},{type:"checkbox",label:"auto-rotate",name:"autoRotate",property:"autoRotate"},{type:"checkbox",label:"debug",name:"debug",property:"debug"}],help:"scene/component/three-container"};let qx=class extends ng{constructor(){super(...arguments),this._capability=new Bf}get sceneManager(){return this._capability.sceneManager}get cameraManager(){return this._capability.cameraManager}get rendererManager(){return this._capability.rendererManager}get lightManager(){return this._capability.lightManager}get controlsManager(){return this._capability.controlsManager}get eventManager(){return this._capability.eventManager}get hasEnvironment(){return this._capability.hasEnvironment}containable(t){return!0}is3dContainer(){return!0}getLightingConfig(){return{hemisphere:{skyColor:16777215,groundColor:14540253,intensity:1},directional:{color:16777215,intensity:1.2,attachToCamera:!0,castShadow:!1}}}getCss3DSceneAttribute(){return"three-container:css3d-renderer"}init_scene3d(){this._capability.isInitialized&&this._capability.destroy(),this._capability.init(this,{lightingConfig:this.getLightingConfig(),css3DSceneAttribute:this.getCss3DSceneAttribute(),skipEnvironment:!0,skipPostprocessing:!0,skipShadowMap:!0}),this._capability.buildOverlays(),this._capability.resize(),this.onchangeData&&this.onchangeData(this.data,this.data)}destroy_scene3d(){this.stop(),this._capability.destroy()}stop(){}resize(){this._capability.resize()}get scene3d(){return this._capability.isInitialized||this.init_scene3d(),this._capability.scene3d}get renderer3d(){return this._capability.renderer3d}get mixer(){return this._capability.mixer}get css3DScene(){return this._capability.css3DScene}get css3DRenderer(){return this._capability.css3DRenderer}render_threed(){this._capability.renderThreeD()}get _parentIs3dMode(){return!!this.rootModel?.is3dMode}render(t){this._parentIs3dMode||(this.app.isViewMode&&this.setState("threed",!0),!this.state.threed||this._capability.noSupportWebgl?super.render(t):this._capability.camera&&this._capability.renderCSS3D())}postrender(t){if(this._parentIs3dMode)return;const{left:e,top:n,debug:i,threed:s}=this.state;let{width:r,height:o}=this.bounds;if(r=Math.floor(r),o=Math.floor(o),s){if(this._capability.isInitialized||this.init_scene3d(),this._capability.noSupportWebgl)return void this._capability.showWebglNoSupportText(t,this.state.width,this.state.height);if(!this._capability.renderer3d)return;this._capability.renderThreeD();const s=this._capability.domElement;if(!s||!s.width||!s.height)return;t.drawImage(s,0,0,s.width,s.height,e,n,r,o),i&&this._capability.showDebugFPS(t)}else super.postrender(t)}dispose(){this._capability.dispose(),super.dispose()}get layout(){return Lc.get("three")}get nature(){return Wx}getObjectByRaycast(){return this._capability.getObjectByRaycast()}getObjectsByRaycast(){return this._capability.getObjectsByRaycast()}onchange(t,e){(t.hasOwnProperty("width")||t.hasOwnProperty("height"))&&this._capability.destroy(),this._capability.onchange(t)}onmousedown(t){this._capability.onMouseDown(t)}onmouseup(t){this._capability.onMouseUp(t)}onmousemove(t){this._capability.onMouseMove(t)}onmouseleave(t){this._capability.onMouseLeave(t)}onwheel(t){this._capability.onWheel(t)&&this.invalidate()}ondblclick(t){this._capability.onDblClick(t)&&this.invalidate()}ondragstart(t){this._capability.onDragStart(t)}ondragmove(t){this._capability.onDragMove(t)&&this.invalidate()}ondragend(t){this._capability.onDragEnd(t)&&this.invalidate()}ontouchstart(t){this._capability.onTouchStart(t)}onpan(t){this._capability.onPan(t)&&this.invalidate()}ontouchend(t){this._capability.onTouchEnd(t)}onkeydown(t){this._capability.onKeyDown(t)}onpinch(t){this._capability.onPinch(t)&&this.invalidate()}ondoubletap(){this._capability.onDoubleTap(),this.invalidate()}};qx=Wm([Dy("3d-container")],qx),Qp(t=>new iv(t));const Xx=["x","y","z"],Kx=["Capacity","Holdable","Transferable","FlowNode"],Qx=Object.freeze({Transferable:["Capacity","FlowNode"]}),Zx=["S","M","L","XL"],Jx=Object.freeze({x:"size.x",y:"size.y",z:"size.z"});class tw extends Error{code;path;details;constructor(t,e,n,i){super(`${t}: ${e}: ${n}`),this.name="FigureContractError",this.code=t,this.path=e,void 0!==i&&(this.details=i)}}const ew=Object.freeze({x:["y","z"],y:["z","x"],z:["x","y"]}),nw=1e-6,iw=256,sw=/^[a-zA-Z][a-zA-Z0-9_-]*$/;function rw(t,e){return t<e?`${t}~${e}`:`${e}~${t}`}const ow=t=>ew[t],aw=t=>!!t.corner&&Object.values(t.corner).some(t=>(t??0)>0);function cw(t,e){const[n,i]=ow(e);if("rectangle"===t.kind){const e=[];for(const s of[n,i]){const n=t.size[s];"number"==typeof n&&Number.isFinite(n)?n>0||e.push({code:"SIZE_NOT_POSITIVE",axis:s}):e.push({code:"NON_FINITE",at:`size.${s}`})}if(!t.corner)return e;for(const s of[n,i]){const n=t.corner[s];"number"==typeof n&&Number.isFinite(n)?n<0?e.push({code:"CORNER_NEGATIVE",axis:s}):Number.isFinite(t.size[s])&&n>t.size[s]/2+nw&&e.push({code:"CORNER_TOO_LARGE",axis:s,max:t.size[s]/2}):e.push({code:"NON_FINITE",at:`corner.${s}`})}return e.length||t.corner[n]>0==t.corner[i]>0||e.push({code:"CORNER_ONE_AXIS",axis:t.corner[n]>0?n:i}),e}if("ellipse"===t.kind){const e=[];for(const s of[n,i]){const n=t.radius[s];"number"==typeof n&&Number.isFinite(n)?n>0||e.push({code:"SIZE_NOT_POSITIVE",axis:s}):e.push({code:"NON_FINITE",at:`radius.${s}`})}return e}return function(t,e){const[n,i]=ow(e),s=[],r=new Set;for(const e of t){"string"==typeof e.id&&sw.test(e.id)?r.has(e.id)?s.push({code:"DUPLICATE_POINT_ID",point:e.id}):r.add(e.id):s.push({code:"BAD_POINT_ID",point:String(e.id)});for(const t of[n,i])"number"==typeof e[t]&&Number.isFinite(e[t])||s.push({code:"NON_FINITE",at:`${e.id}.${t}`})}t.length<3&&s.push({code:"TOO_FEW_POINTS",count:t.length});t.length>iw&&s.push({code:"TOO_MANY_POINTS",count:t.length,limit:iw});if(s.length)return s;const o=t.length,a=function(t,e){const[n,i]=ow(e);return t.map(t=>[t[n],t[i]])}(t,e),c=e=>rw(t[e].id,t[(e+1)%o].id),l=nw,h=a.map((t,e)=>Math.hypot(a[(e+1)%o][0]-t[0],a[(e+1)%o][1]-t[1]));if(h.forEach((t,e)=>{t<=l&&s.push({code:"ZERO_LENGTH_SIDE",side:c(e)})}),s.length)return s;for(let t=0;t<o;t++){const e=a[t],n=a[(t+1)%o],i=a[(t+2)%o],r=(n[0]-e[0])*(i[1]-n[1])-(n[1]-e[1])*(i[0]-n[0]),d=(n[0]-e[0])*(i[0]-n[0])+(n[1]-e[1])*(i[1]-n[1]);Math.abs(r)<=l*h[t]&&d<0&&s.push({code:"SIDES_FOLD",sides:[c(t),c((t+1)%o)]})}for(let t=0;t<o;t++)for(let e=t+1;e<o;e++){if(e===t+1||0===t&&e===o-1)continue;const n=dw(a[t],a[(t+1)%o],a[e],a[(e+1)%o],l);n&&s.push({code:"cross"===n?"SIDES_CROSS":"SIDES_TOUCH",sides:[c(t),c(e)]})}if(s.length)return s;Math.abs(function(t){let e=0;for(let n=0;n<t.length;n++){const[i,s]=t[n],[r,o]=t[(n+1)%t.length];e+=i*o-r*s}return e}(a))/2<=l&&s.push({code:"ZERO_AREA"});return s}(t.points,e)}const lw=(t,e,n)=>(e[0]-t[0])*(n[1]-t[1])-(e[1]-t[1])*(n[0]-t[0]);function hw(t,e,n){const i=n[0]-e[0],s=n[1]-e[1],r=i*i+s*s,o=r?Math.max(0,Math.min(1,((t[0]-e[0])*i+(t[1]-e[1])*s)/r)):0;return Math.hypot(t[0]-e[0]-o*i,t[1]-e[1]-o*s)}function dw(t,e,n,i,s){const r=lw(n,i,t),o=lw(n,i,e),a=lw(t,e,n),c=lw(t,e,i),l=Math.hypot(e[0]-t[0],e[1]-t[1]),h=(t,e,n)=>t>s*n&&e<-s*n||t<-s*n&&e>s*n;if(h(r,o,Math.hypot(i[0]-n[0],i[1]-n[1]))&&h(a,c,l))return"cross";return Math.min(hw(t,n,i),hw(e,n,i),hw(n,t,e),hw(i,t,e))<=s?"touch":null}function uw(t,e){const[n,i]=ow(e);if("ellipse"===t.kind)return[{id:"round",shape:"curved"}];if("rectangle"===t.kind){const[e,s]=[n,i].sort(),r=[e,s].flatMap(t=>[`${t}-`,`${t}+`]).map(t=>({id:t,shape:"flat"}));if(!aw(t))return r;const o=["-","+"].flatMap(t=>["-","+"].map(n=>({id:`corner:${e}${t}${s}${n}`,shape:"curved"})));return[...r,...o]}const s=t.points;return s.map((t,e)=>{const n=s[(e+1)%s.length];return{id:rw(t.id,n.id),shape:"flat",from:t.id,to:n.id}})}function pw(t,e,n){const[i,s]=ow(e);if("polygon"===t.kind)return{refused:"SECTION_KIND"};const r=[i,s].flatMap(t=>[`${t}-`,`${t}+`]);for(const t of r){const e=n[t];if("number"!=typeof e||!Number.isFinite(e))return{refused:"NON_FINITE",side:t};if(!(e>0))return{refused:"WALL_NOT_POSITIVE",side:t}}const o=t=>n[t],a=(t,e)=>e-o(`${t}-`)-o(`${t}+`),c={[i]:(o(`${i}-`)-o(`${i}+`))/2,[s]:(o(`${s}-`)-o(`${s}+`))/2};if("rectangle"===t.kind){const e={[i]:a(i,t.size[i]),[s]:a(s,t.size[s])};if(!(e[i]>0&&e[s]>0))return{refused:"NO_ROOM_INSIDE"};if(!aw(t))return{section:{kind:"rectangle",size:e},centre:c};const n=e=>Math.max(t.corner[e]-Math.max(o(`${e}-`),o(`${e}+`)),0),r={[i]:n(i),[s]:n(s)};return{section:{kind:"rectangle",size:e,...r[i]>0&&r[s]>0?{corner:r}:{}},centre:c}}const l={[i]:a(i,2*t.radius[i])/2,[s]:a(s,2*t.radius[s])/2};return l[i]>0&&l[s]>0?{section:{kind:"ellipse",radius:l},centre:c}:{refused:"NO_ROOM_INSIDE"}}const fw=(t,e)=>Object.fromEntries(Xx.map(n=>[n,n===t?e:0]));function mw(t,e,n){const[i,s]=ew[e];if("polygon"!==t.kind){const t=n.id.slice(0,-1);return fw(t,n.id.endsWith("+")?1:-1)}const r=t.points.find(t=>t.id===n.from),o=t.points.find(t=>t.id===n.to),a=o[i]-r[i],c=o[s]-r[s],l=Math.hypot(a,c),h={x:0,y:0,z:0};return h[i]=c/l||0,h[s]=-a/l||0,h}const gw=(t,e,n)=>{throw new tw(t,e,n)},yw=t=>Array.isArray(t)&&3===t.length&&1===t[0]&&0===t[1]&&0===t[2],bw=Object.freeze({x:["left","right"],y:["bottom","top"],z:["back","front"]}),_w=["rectangle","ellipse","polygon","portal"],vw=/^[a-zA-Z][a-zA-Z0-9_-]*$/;function xw(t,e){const n=t??{},i=n.axis;Xx.includes(i)||gw("PARAM",e,`axis is x, y or z, not ${String(n.axis)}`);const s=n.section;_w.includes(s)||gw("PARAM",e,`section is ${_w.join(", ")}, not ${String(n.section)}`);const r=[...ew[i]].sort(),[o,a]=r,c="round"===n.corner;void 0===n.corner||c&&"rectangle"===s||gw("PARAM",e,"corner is `round`, and only a rectangle has corners");const l="polygon"===s?String(n.points??"").split("."):[];"polygon"===s?((l.length<3||l.some(t=>!vw.test(t)))&&gw("PARAM",e,"a drawn section names three points or more, joined by `.`"),new Set(l).size!==l.length&&gw("PARAM",e,"a point is named twice")):void 0!==n.points&&gw("PARAM",e,"only a drawn section has points");let h=2;const d=()=>h++,u={start:0,length:1};let p;if("rectangle"!==s&&"ellipse"!==s&&"portal"!==s||(u.across={[o]:d(),[a]:d()}),c&&(u.corner={[o]:d(),[a]:d()}),"portal"===s&&(u.jamb=d(),u.head=d()),"polygon"===s&&(u.point=Object.fromEntries(l.map(t=>[t,{[o]:d(),[a]:d()}]))),void 0!==n.cavity){"rectangle"!==s&&"ellipse"!==s&&gw("SECTION_KIND",e,`a ${s} section has no inside yet (ADR-0100 stage 4)`);const t=t=>{const i=n[t];return"open"!==i&&"closed"!==i&&gw("PARAM",e,`${t} is open or closed`),i};p={id:n.cavity,start:t("cavity-start"),end:t("cavity-end")},u.wall=Object.fromEntries([o,a].flatMap(t=>[`${t}-`,`${t}+`]).map(t=>[t,d()])),"closed"===p.start&&(u.startClosed=d()),"closed"===p.end&&(u.endClosed=d())}else void 0===n["cavity-start"]&&void 0===n["cavity-end"]||gw("PARAM",e,"the ends of an inside need the inside");return{axis:i,plane:r,section:s,points:l,rounded:c,...p?{cavity:p}:{},arg:u,count:h}}const ww=(t,e=1)=>[{arg:t,k:e}];function Mw(t,e){const n=xw(t.params,t.id),[i,s]=n.plane,r={},o={},a={},[c,l]=bw[n.axis],h={lo:[{arg:0,k:1}],hi:[{arg:0,k:1},{arg:1,k:1}]};if(r[n.axis]=ww(1),o[n.axis]={arg:1,k:1},a[c]={axis:n.axis,normal:-1,plane:h.lo},a[l]={axis:n.axis,normal:1,plane:h.hi},"polygon"===n.section){for(const t of[i,s])r[t]="profile",o[t]={refused:"SECTION_CORNERS"};return{measure:r,edit:o,faces:a,kind:"polygon"}}const d=n.arg.across,u="ellipse"===n.section?2:1;for(const t of[i,s])r[t]=ww(d[t],u),o[t]={arg:d[t],k:u};if(void 0!==t.args?.[d[i]]&&t.args[d[i]]===t.args[d[s]]&&(o[s]={arg:d[s],k:u,sameAs:i}),"portal"===n.section){const[t,e]=bw[i],[c,l]=bw[s];return a[t]={axis:i,normal:-1,plane:[{arg:d[i],k:-.5}]},a[e]={axis:i,normal:1,plane:[{arg:d[i],k:.5}]},a[c]={axis:s,normal:-1,plane:[]},a[l]={axis:s,normal:1,plane:[{arg:d[s],k:1}]},a[`opening-${t}`]={axis:i,normal:1,plane:[{arg:d[i],k:-.5},{arg:n.arg.jamb,k:1}]},a[`opening-${e}`]={axis:i,normal:-1,plane:[{arg:d[i],k:.5},{arg:n.arg.jamb,k:-1}]},a[`opening-${l}`]={axis:s,normal:-1,plane:[{arg:d[s],k:1},{arg:n.arg.head,k:-1}]},{measure:r,edit:o,faces:a,kind:"portal"}}const p="ellipse"===n.section?1:.5,f="ellipse"===n.section?{contact:"line"}:{};for(const t of[i,s]){const[e,n]=bw[t];a[e]={axis:t,normal:-1,plane:[{arg:d[t],k:-p}],...f},a[n]={axis:t,normal:1,plane:[{arg:d[t],k:p}],...f}}if(n.cavity){const t=n.arg.wall;for(const e of[i,s]){const[n,i]=bw[e];a[`inside-${n}`]={axis:e,normal:1,plane:[{arg:d[e],k:-p},{arg:t[`${e}-`],k:1}],...f},a[`inside-${i}`]={axis:e,normal:-1,plane:[{arg:d[e],k:p},{arg:t[`${e}+`],k:-1}],...f}}void 0!==n.arg.startClosed&&(a[`inside-${c}`]={axis:n.axis,normal:1,plane:[...h.lo,{arg:n.arg.startClosed,k:1}]}),void 0!==n.arg.endClosed&&(a[`inside-${l}`]={axis:n.axis,normal:-1,plane:[...h.hi,{arg:n.arg.endClosed,k:-1}]})}return{measure:r,edit:o,faces:a,kind:n.section}}function Sw(t,e){const n=t??{},i=n.axis;return Xx.includes(i)||gw("PARAM",e,`axis is x, y or z, not ${String(n.axis)}`),"half-ellipse"!==n.profile&&"taper"!==n.profile&&gw("PARAM",e,`profile is half-ellipse or taper, not ${String(n.profile)}`),{axis:i,profile:n.profile,count:"taper"===n.profile?4:2}}function kw(t,e){const n=Sw(t.params,t.id),[i,s]=[...ew[n.axis]].sort(),r={},o={};if("half-ellipse"===n.profile)return r[n.axis]=ww(1,2),o[n.axis]={arg:1,k:2},r[i]=r[s]=ww(0,2),o[i]={arg:0,k:2},o[s]={arg:0,k:2,sameAs:i},{measure:r,edit:o,faces:{},kind:"sphere"};const[a,c]=bw[n.axis];r[n.axis]=ww(1),o[n.axis]={arg:1,k:1};r[i]=r[s]=[{arg:2,k:2},{arg:3,k:2}],o[i]={arg:3,k:2,with:[2]},o[s]={arg:3,k:2,with:[2],sameAs:i};const l={lo:[{arg:0,k:1}],hi:[{arg:0,k:1},{arg:1,k:1}]};return{measure:r,edit:o,faces:{[a]:{axis:n.axis,normal:-1,plane:l.lo},[c]:{axis:n.axis,normal:1,plane:l.hi}},kind:"taper"}}function Aw(t,e){const n=t??{};"polygon"!==n.section&&gw("PARAM",e,`a loft starts from a drawn section, not ${String(n.section)}`),void 0===n.corner&&void 0===n.cavity||gw("PARAM",e,"a loft has no corners and no inside");const i=xw(n,e),[s,r]=i.plane;return{...i,apex:{[s]:i.count,[r]:i.count+1},count:i.count+2}}function Ew(t,e){const n=Aw(t.params,t.id),i={},s={},[r]=bw[n.axis];i[n.axis]=ww(1),s[n.axis]={arg:1,k:1};for(const t of n.plane)i[t]="profile",s[t]={refused:"SECTION_CORNERS"};return{measure:i,edit:s,faces:{[r]:{axis:n.axis,normal:-1,plane:[{arg:0,k:1}]}},kind:"pyramid"}}const Cw=(t,e)=>Object.fromEntries(Object.entries(t).map(([t,n])=>[t,{axis:n.axis,normal:n.normal,at:n.plane.reduce((t,n)=>t+n.k*e[n.arg],0)}]));function Tw(t,e,n){const i=Xx.find(t=>t!==e&&t!==n),[s,r]=ew[i];let o=0;for(let e=0;e<t.length;e++){const n=t[e],i=t[(e+1)%t.length];o+=n[s]*i[r]-i[s]*n[r]}return o>0?t:[t[0],...t.slice(1).reverse()]}function Pw(t,e){const[n,i]=ew[e];let s=0;const r=t.points;for(let t=0;t<r.length;t++){const e=r[t],o=r[(t+1)%r.length];s+=e[n]*o[i]-o[n]*e[i]}return s}function Ow(t,e,n){const i=xw(n.params,e),[s,r]=i.plane,o=t[0],a=t[1];a>0||gw("GEOMETRY_DOMAIN",e,`a push of positive length required, not ${a}`);const c={start:o,length:a};let l;if("polygon"===i.section){const e=i.points.map(e=>({id:e,[s]:t[i.arg.point[e][s]],[r]:t[i.arg.point[e][r]]}));e.forEach(t=>{c[`point.${t.id}.${s}`]=t[s],c[`point.${t.id}.${r}`]=t[r]}),l={kind:"polygon",points:e}}else if("portal"===i.section){const n=t[i.arg.across[s]],o=t[i.arg.across[r]],a=t[i.arg.jamb],h=t[i.arg.head];n>0&&o>0&&a>0&&h>0&&2*a<n&&h<o||gw("GEOMETRY_DOMAIN",e,"positive measures, jambs narrower than half the width and a head lower than the height required"),Object.assign(c,{[`size.${s}`]:n,[`size.${r}`]:o,jamb:a,head:h}),l=function(t,e,n,i,s,r){const o=-n/2,a=n/2,c=o+s,l=a-s,h=i-r,d=(n,i,s)=>({id:n,[t]:i,[e]:s});return{kind:"polygon",points:Tw([d("p1",o,0),d("p2",o,i),d("p3",a,i),d("p4",a,0),d("p5",l,0),d("p6",l,h),d("p7",c,h),d("p8",c,0)],t,e)}}(s,r,n,o,a,h)}else{const e={[s]:t[i.arg.across[s]],[r]:t[i.arg.across[r]]},n="ellipse"===i.section?"radius":"size";if(c[`${n}.${s}`]=e[s],c[`${n}.${r}`]=e[r],"ellipse"===i.section)l={kind:"ellipse",radius:e};else if(l={kind:"rectangle",size:e},i.rounded){const n={[s]:t[i.arg.corner[s]],[r]:t[i.arg.corner[r]]};c[`corner.${s}`]=n[s],c[`corner.${r}`]=n[r],(n[s]>0||n[r]>0)&&(l={kind:"rectangle",size:e,corner:n})}}const h=cw(l,i.axis);h.length&&gw("GEOMETRY_DOMAIN",e,`the section is not valid: ${h.map(t=>t.code).join(", ")}`),"polygon"!==l.kind||"polygon"!==i.section||Pw(l,i.axis)>0||gw("SECTION_WINDING",e,"a drawn section runs counter-clockwise seen from its push axis; write it with normalizeFigureSection");const d={axis:i.axis,section:l,start:o,end:o+a};let u;if(i.cavity){const n=Object.fromEntries(Object.entries(i.arg.wall).map(([e,n])=>[e,t[n]]));u={id:i.cavity.id,wall:n,start:"open"===i.cavity.start?"open":{closed:t[i.arg.startClosed]},end:"open"===i.cavity.end?"open":{closed:t[i.arg.endClosed]}};for(const[t,e]of Object.entries(n))c[`wall.${t}`]=e;"open"!==u.start&&(c["closed.start"]=u.start.closed),"open"!==u.end&&(c["closed.end"]=u.end.closed);const s=function(t,e=[]){const{axis:n,section:i,start:s,end:r}=t;if(!(r-s>0))return{refused:{code:"SPAN_NOT_POSITIVE"}};if(e.length>1)return{refused:{code:"CAVITY_COUNT",count:e.length}};const o=e[0];let a;if(o){const t=pw(i,n,o.wall);if("refused"in t)return{refused:{code:"CAVITY",cavity:o.id,refused:t.refused,...t.side?{side:t.side}:{}}};a=t.section;const e=t=>"open"===t?0:t.closed;for(const t of["start","end"]){const e=o[t];if("open"!==e&&!(e.closed>0))return{refused:{code:"CAVITY_END_NOT_POSITIVE",cavity:o.id,end:t}}}if(!(r-s-e(o.start)-e(o.end)>0))return{refused:{code:"CAVITY_NO_LENGTH",cavity:o.id}}}const c=uw(i,n),l=[{id:"start-face",kind:"plane",normal:fw(n,-1),..."open"===o?.start?{open:!0}:{}},{id:"end-face",kind:"plane",normal:fw(n,1),..."open"===o?.end?{open:!0}:{}}];for(const t of c)l.push("flat"===t.shape?{id:`side-face:${t.id}`,kind:"plane",normal:mw(i,n,t)}:{id:`side-face:${t.id}`,kind:"curved"}),l.push({id:`edge:start:${t.id}`,kind:"edge"},{id:`edge:end:${t.id}`,kind:"edge"});if("polygon"===i.kind)for(const t of i.points)l.push({id:`edge:${t.id}`,kind:"edge"});else if("rectangle"===i.kind&&!c.some(t=>"curved"===t.shape)){const[t,e]=[...ew[n]].sort();for(const n of["-","+"])for(const i of["-","+"])l.push({id:`edge:${t}${n}${e}${i}`,kind:"edge"})}if(o&&a){for(const t of uw(a,n)){const e=`cavity-wall:${o.id}:${t.id}`;if("curved"===t.shape)l.push({id:e,kind:"curved"});else{const i=mw(a,n,t);l.push({id:e,kind:"plane",normal:{x:-i.x||0,y:-i.y||0,z:-i.z||0}})}}"open"!==o.start&&l.push({id:`cavity-start:${o.id}`,kind:"plane",normal:fw(n,1)}),"open"!==o.end&&l.push({id:`cavity-end:${o.id}`,kind:"plane",normal:fw(n,-1)})}return l.push({id:"centre",kind:"point"}),{features:l}}(d,[u]);"refused"in s&&gw("GEOMETRY_DOMAIN",e,`the inside is not valid: ${s.refused.code}${"refused"in s.refused?` ${s.refused.refused}`:""}`)}return{provider:"extrude",dimensions:c,extrusion:d,...u?{cavity:u}:{},faces:Cw(Mw(n).faces,t)}}function Dw(t,e,n){const i=Sw(n.params,e),s=Cw(kw(n).faces,t);if("half-ellipse"===i.profile){const[n,r]=t;return n>0&&r>0||gw("GEOMETRY_DOMAIN",e,"positive radii required"),{provider:"revolve",dimensions:{radial:n,axial:r},revolution:{axis:i.axis,profile:{kind:"half-ellipse",radial:n,axial:r}},faces:s}}const[r,o,a,c]=t;return o>0&&a>=0&&c>=0&&a+c>0||gw("GEOMETRY_DOMAIN",e,"a positive length and radii of 0 or more, not both 0, required"),{provider:"revolve",dimensions:{start:r,length:o,startRadius:a,endRadius:c},revolution:{axis:i.axis,profile:{kind:"taper",start:r,end:r+o,startRadius:a,endRadius:c}},faces:s}}function Iw(t,e,n){const i=Aw(n.params,e),[s,r]=i.plane,o=t[0],a=t[1];a>0||gw("GEOMETRY_DOMAIN",e,`a loft of positive length required, not ${a}`);const c={start:o,length:a},l=i.points.map(e=>({id:e,[s]:t[i.arg.point[e][s]],[r]:t[i.arg.point[e][r]]}));l.forEach(t=>{c[`point.${t.id}.${s}`]=t[s],c[`point.${t.id}.${r}`]=t[r]});const h={kind:"polygon",points:l},d=cw(h,i.axis);d.length&&gw("GEOMETRY_DOMAIN",e,`the section is not valid: ${d.map(t=>t.code).join(", ")}`),Pw(h,i.axis)>0||gw("SECTION_WINDING",e,"a drawn section runs counter-clockwise seen from its push axis; write it with normalizeFigureSection");const u={[s]:t[i.apex[s]],[r]:t[i.apex[r]]};return Number.isFinite(u[s])&&Number.isFinite(u[r])||gw("GEOMETRY_DOMAIN",e,"a finite apex required"),c[`apex.${s}`]=u[s],c[`apex.${r}`]=u[r],{provider:"loft",dimensions:c,loft:{axis:i.axis,section:h,start:o,end:o+a,apex:u},faces:Cw(Ew(n).faces,t)}}function zw(t,e,n){return{kind:"shape",provider:t,frame:e.params.frame,faces:Object.fromEntries(Object.entries(n).map(([t,e])=>[t,e.contact?[e.axis,e.normal,e.contact]:[e.axis,e.normal]]))}}const Rw={"extrude@1":{ports:["shape"],params:["frame","axis","section"],optionalParams:["points","corner","cavity","cavity-start","cavity-end"],types(t,e,n){const i=xw(n.params,e);return t.length===i.count&&t.every(yw)||gw("TYPE",e,`a ${i.section} push takes ${i.count} lengths, not ${t.length}`),[zw("extrude",n,Mw(n).faces)]},run:(t,e,n)=>[Ow(t,e,n)]},"revolve@1":{ports:["shape"],params:["frame","axis","profile"],types(t,e,n){const i=Sw(n.params,e);return t.length===i.count&&t.every(yw)||gw("TYPE",e,`a ${i.profile} turn takes ${i.count} lengths, not ${t.length}`),[zw("revolve",n,kw(n).faces)]},run:(t,e,n)=>[Dw(t,e,n)]},"loft@1":{ports:["shape"],params:["frame","axis","section","points"],types(t,e,n){const i=Aw(n.params,e);return t.length===i.count&&t.every(yw)||gw("TYPE",e,`a loft of ${i.points.length} points takes ${i.count} lengths, not ${t.length}`),[zw("loft",n,Ew(n).faces)]},run:(t,e,n)=>[Iw(t,e,n)]}};function jw(t,e){const n=function(t){const e={};if(t.extrusion){const n=t.extrusion,[i,s]=ew[n.axis];e[n.axis]={min:n.start,max:n.end};const r=n.section;for(const t of[i,s])if("rectangle"===r.kind)e[t]={min:-r.size[t]/2,max:r.size[t]/2};else if("ellipse"===r.kind)e[t]={min:-r.radius[t],max:r.radius[t]};else{const n=r.points.map(e=>e[t]);e[t]={min:Math.min(...n),max:Math.max(...n)}}return e}if(t.loft){const n=t.loft;e[n.axis]={min:n.start,max:n.end};for(const t of ew[n.axis]){const i=[...n.section.points.map(e=>e[t]),n.apex[t]];e[t]={min:Math.min(...i),max:Math.max(...i)}}return e}const n=t.revolution,[i,s]=ew[n.axis];if("half-ellipse"===n.profile.kind){e[n.axis]={min:-n.profile.axial,max:n.profile.axial};for(const t of[i,s])e[t]={min:-n.profile.radial,max:n.profile.radial}}else{const t=Math.max(n.profile.startRadius,n.profile.endRadius);e[n.axis]={min:n.profile.start,max:n.profile.end};for(const n of[i,s])e[n]={min:-t,max:t}}return e}(t),i=Xx.map(t=>(n[t].min+n[t].max)/2);if("centre"===e)return i;const s=t.faces[e],r={x:0,y:1,z:2};if(s){const n=[...i];if(n[r[s.axis]]=s.at,t.loft)for(const e of ew[t.loft.axis]){const i=t.loft.section.points.map(t=>t[e]);n[r[e]]=(Math.min(...i)+Math.max(...i))/2}if(e.startsWith("inside-")&&t.cavity&&t.extrusion){const e=t.extrusion,o=t.cavity,a=o.wall;for(const t of ew[e.axis])t!==s.axis&&(n[r[t]]=i[r[t]]+(a[`${t}-`]-a[`${t}+`])/2);if(s.axis!==e.axis){const t=e.start+("open"===o.start?0:o.start.closed),i=e.end-("open"===o.end?0:o.end.closed);n[r[e.axis]]=(t+i)/2}}return n}if("half-ellipse"===t.revolution?.profile.kind){const t=Object.entries(bw).flatMap(([t,[e,n]])=>[[e,t,-1],[n,t,1]]).find(([t])=>t===e);if(!t)return;const s=[...i];return s[r[t[1]]]=t[2]<0?n[t[1]].min:n[t[1]].max,s}}function Lw(t,e){"string"!=typeof t&&Fw("PARAM",e,"layout required"),t.startsWith("L")||Fw("PARAM",e,"layout starts with L");const n=t.slice(1).split(".").map(t=>""===t?[]:t.split("_").map(Number));return(6!==n.length||n.some(t=>!t.length||t.some(t=>!Number.isSafeInteger(t)||t<0)))&&Fw("PARAM",e,"layout is six groups of term counts, each with one candidate or more"),n}const Fw=(t,e,n)=>{throw new tw(t,e,n)},Nw={mm:[[1,0,0],1],cm:[[1,0,0],10],m:[[1,0,0],1e3],rad:[[0,1,0],1],deg:[[0,1,0],Math.PI/180],s:[[0,0,1],1],ratio:[[0,0,0],1],percent:[[0,0,0],.01]},Hw=[1,0,0],Bw=[0,0,0],Yw=[0,1,0],Vw={kind:"count"},Gw={kind:"flag"};Nw.count=[Vw,1];const $w=(t,e)=>Array.isArray(t)&&Array.isArray(e)?t.length===e.length&&t.every((t,n)=>t===e[n]):JSON.stringify(t)===JSON.stringify(e);function Uw(t,e,n,i){t&&"object"==typeof t&&!Array.isArray(t)||Fw("SCHEMA",i,"object required");for(const n of e)Object.hasOwn(t,n)||Fw("SCHEMA",i,`missing ${n}`);for(const s of Object.keys(t))[...e,...n].includes(s)||Fw("SCHEMA",i,`unknown ${s}`)}function Ww(t,e){return"string"==typeof t&&/^[a-zA-Z][a-zA-Z0-9_.-]*$/.test(t)||Fw("ID",e,"invalid id"),t}function qw(t,e){return"number"==typeof t&&Number.isFinite(t)||Fw("NON_FINITE",e,String(t)),t}function Xw(t,e){return Object.hasOwn(Nw,t)||Fw("UNIT",e,String(t)),Nw[t]}function Kw(t,e,n){(t.length!==e.length||t.some((t,n)=>!$w(t,e[n])))&&Fw("TYPE",n,`expected ${JSON.stringify(e)}, got ${JSON.stringify(t)}`)}const Qw={"add@1":{ports:["value"],types:(t,e)=>(2===t.length&&t.every(Array.isArray)&&$w(t[0],t[1])||Fw("TYPE",e,"addition needs same scalar dimensions"),[t[0]]),run:([t,e])=>[t+e]},"mul@1":{ports:["value"],types:(t,e)=>(2===t.length&&t.every(Array.isArray)||Fw("TYPE",e,"two scalar arguments"),[t[0].map((e,n)=>e+t[1][n])]),run:([t,e])=>[t*e]},"div@1":{ports:["value"],types:(t,e)=>(2===t.length&&t.every(Array.isArray)||Fw("TYPE",e,"two scalar arguments"),[t[0].map((e,n)=>e-t[1][n])]),run:([t,e],n)=>(0===e&&Fw("DOMAIN",n,"zero denominator"),[t/e])},"sin@1":{ports:["value"],types:(t,e)=>(Kw(t,[Yw],e),[Bw]),run:([t])=>[Math.sin(t)]},"geomean@1":{ports:["value"],types:(t,e)=>((t.length<2||t.length>3||!t.every(Array.isArray)||!t.every(e=>$w(e,t[0])))&&Fw("TYPE",e,"geometric mean needs two or three scalars of the same dimension"),[t[0]]),run:(t,e)=>(t.some(t=>t<0)&&Fw("DOMAIN",e,"geometric mean of a negative value"),[Math.pow(t.reduce((t,e)=>t*e,1),1/t.length)])},"curve@1":{ports:["value"],types(t,e){(t.length<5||t.length%2==0||!t.every(Array.isArray))&&Fw("TYPE",e,"x and at least two (at, value) key pairs, all scalars");for(let n=1;n<t.length;n+=2)$w(t[n],t[0])||Fw("TYPE",e,`key ${(n-1)/2}: at must have the dimension of x`),$w(t[n+1],t[2])||Fw("TYPE",e,`key ${(n-1)/2}: every value must have one dimension`);return[t[2]]},run:(t,e)=>{const n=t[0],i=(t.length-1)/2,s=e=>t[1+2*e],r=e=>t[2+2*e];for(let t=1;t<i;t++)s(t)>s(t-1)||Fw("DOMAIN",e,`keys out of order: at[${t}] = ${s(t)} is not after at[${t-1}] = ${s(t-1)}`);if(n<=s(0))return[r(0)];if(n>=s(i-1))return[r(i-1)];let o=0;for(;o<i-2&&s(o+1)<=n;)o++;const a=(n-s(o))/(s(o+1)-s(o));return[r(o)+(r(o+1)-r(o))*a]}},"at-least@1":{ports:["value"],types:(t,e)=>(2===t.length&&t.every(Array.isArray)&&$w(t[0],t[1])||Fw("TYPE",e,"at-least compares two scalars of the same dimension"),[Gw]),run:([t,e])=>[t>=e]},"max@1":{ports:["value"],types:(t,e)=>((t.length<2||!t.every(Array.isArray)||!t.every(e=>$w(e,t[0])))&&Fw("TYPE",e,"two or more scalars of the same dimension"),[t[0]]),run:t=>[Math.max(...t)]},"min@1":{ports:["value"],types:(t,e)=>((t.length<2||!t.every(Array.isArray)||!t.every(e=>$w(e,t[0])))&&Fw("TYPE",e,"two or more scalars of the same dimension"),[t[0]]),run:t=>[Math.min(...t)]},"affine-bounds@1":{ports:["xmin","xmax","ymin","ymax","zmin","zmax"],params:["layout"],types(t,e,n){const i=Lw(n.params.layout,e);let s=0;for(const n of i)for(const i of n){$w(t[s++],Hw)||Fw("TYPE",e,`candidate constant ${s-1} is a length`);for(let n=0;n<i;n++)$w(t[s++],Hw)||Fw("TYPE",e,`term value ${s-1} is a length`),$w(t[s++],Bw)||Fw("TYPE",e,`term ratio ${s-1} is a ratio`)}return s!==t.length&&Fw("TYPE",e,`the layout takes ${s} arguments; ${t.length} were given`),Array(6).fill(Hw)},run:(t,e,n)=>{const i=Lw(n.params.layout,e);let s=0;return i.map((e,n)=>{const i=e.map(e=>{let n=t[s++];for(let i=0;i<e;i++)n+=t[s++]*t[s++];return n});return n%2==0?Math.min(...i):Math.max(...i)})}},"between@1":{ports:["length","center"],types:(t,e)=>(Kw(t,[Hw,Hw,Hw,Hw],e),[Hw,Hw]),run:([t,e,n,i],s)=>{(n<0||i<0)&&Fw("DOMAIN",s,"negative margin");const r=e-t-n-i;return r>0||Fw("NO_SPACE",s,`available=${e-t}; margins=${n+i}; deficit=${Math.max(0,-r)}; positive length required`),[r,(t+e+n-i)/2]}},"box@1":{ports:["xMin","xMax","yMin","yMax","zMin","zMax"],types:(t,e)=>(Kw(t,[Hw,Hw,Hw],e),Array(6).fill(Hw)),run:([t,e,n],i)=>([t,e,n].some(t=>!(t>0))&&Fw("GEOMETRY_DOMAIN",i,"positive width,height,depth required"),[-t/2,t/2,-e/2,e/2,-n/2,n/2]),geometry:([t,e,n])=>({provider:"box@1",dimensions:{width:t,height:e,depth:n}})},"cylinder@1":{ports:["start","end","radialMin","radialMax"],types:(t,e)=>(Kw(t,[Hw,Hw],e),Array(4).fill(Hw)),run:([t,e],n)=>(t>0&&e>0||Fw("GEOMETRY_DOMAIN",n,"positive radius,length required"),[-e/2,e/2,-t,t]),geometry:([t,e])=>({provider:"cylinder@1",axis:"Y",dimensions:{radius:t,length:e}})}},Zw=(t,e)=>({kind:"transform",from:t,to:e}),Jw=()=>[[1,0,0],[0,1,0],[0,0,1]],tM=t=>t[0].map((e,n)=>t.map(t=>t[n])),eM=(t,e)=>t.reduce((t,n,i)=>t+n*e[i],0),nM=(t,e,n,i)=>0+t[0]*e+t[1]*n+t[2]*i,iM=(t,e)=>3===t.length&&3===e.length?[nM(t[0],e[0],e[1],e[2]),nM(t[1],e[0],e[1],e[2]),nM(t[2],e[0],e[1],e[2])]:t.map(t=>eM(t,e)),sM=(t,e)=>{if(3!==t.length||3!==e.length||t.some(t=>3!==t.length)||e.some(t=>3!==t.length))return t.map(t=>tM(e).map(e=>eM(t,e)));const[n,i,s]=e;return t.map(t=>[nM(t,n[0],i[0],s[0]),nM(t,n[1],i[1],s[1]),nM(t,n[2],i[2],s[2])])},rM=(t,e)=>3===t.length&&3===e.length?[t[0]+e[0],t[1]+e[1],t[2]+e[2]]:t.map((t,n)=>t+e[n]),oM=(t,e)=>({r:sM(t.r,e.r),t:rM(iM(t.r,e.t),t.t)}),aM=t=>{const e=tM(t.r);return{r:e,t:iM(e,t.t.map(t=>-t))}};function cM(t,e,n=[]){Uw(t.params,e,n,t.id);for(const i of[...e,...n.filter(e=>Object.hasOwn(t.params,e))])Ww(t.params[i],t.id)}function lM(t,e,n){(t.length!==n||t.some(t=>"transform"!==t.kind))&&Fw("TYPE",e,"rigid transforms required")}Object.assign(Qw,{"fit-pitch@1":{ports:["layout"],types:(t,e)=>(Kw(t,[Hw,Hw,Hw,Hw,Hw,Bw,Vw],e),[{kind:"layout"}]),run:([t,e,n,i,s,r,o],a)=>{t>=0&&e>=0&&n>=0&&i>0&&s>0&&r>=0&&r<=1&&Number.isSafeInteger(o)&&o>=0&&o<=1e4||Fw("LAYOUT_DOMAIN",a,"invalid length, margins, extent, pitch, alignment or limit");const c=t-e-n,l=c<i?0:1+Math.floor((c-i)/s);l>o&&Fw("RESOURCE_LIMIT",a,`count=${l}, limit=${o}`);const h=l?c-i-(l-1)*s:0;return[{centers:Array.from({length:l},(t,n)=>e+i/2+r*h+n*s),count:l}]}},"fixed-count@1":{ports:["layout"],types:(t,e)=>(Kw(t,[Vw,Hw,Hw,Hw,Hw,Bw,Vw],e),[{kind:"layout"}]),run:([t,e,n,i,s,r,o],a)=>{if(Number.isSafeInteger(t)&&t>=0&&Number.isSafeInteger(o)&&o>=0&&o<=1e4&&e>=0&&n>=0&&i>=0&&s>0&&r>=0&&r<=1||Fw("LAYOUT_DOMAIN",a,"invalid fixed count layout"),t>o&&Fw("RESOURCE_LIMIT",a,"fixed count exceeds limit"),!t)return[{centers:[],count:0}];const c=e-n-i-s;return(c<0||t>1&&c/(t-1)<s)&&Fw("NO_SPACE",a,"fixed count non-overlapping items do not fit"),[{centers:1===t?[n+s/2+r*c]:Array.from({length:t},(e,i)=>n+s/2+i*c/(t-1)),count:t}]}},"assembly@1":{ports:["assembly"],types:(t,e)=>(t.length&&!t.some(e=>"placed"!==e.kind&&"collection"!==e.kind||e.frame!==t[0].frame)||Fw("FRAME_TYPE",e,"assembly members need one common frame"),[{kind:"assembly",frame:t[0].frame}]),run:(t,e,n)=>[{members:t.flatMap((t,e)=>t.items?t.items.map(t=>({key:t.key,path:t.path,shape:t.shape,pose:t.pose})):[{key:n.args[e],...t}])}]},"repeat@1":{ports:["collection"],params:["axis"],optionalParams:["riseAxis","within"],types(t,e,n){["x","y","z"].includes(n.params.axis)||Fw("AXIS",e,n.params.axis);const i=4===t.length;return!i||["x","y","z"].includes(n.params.riseAxis)&&n.params.riseAxis!==n.params.axis&&$w(t[3],Hw)||Fw("FRAME_TYPE",e,"a rise is a length along an axis other than the row's"),(3!==t.length&&!i||"layout"!==t[0].kind||"assembly"!==t[1].kind||"transform"!==t[2].kind||t[2].from!==t[1].frame)&&Fw("FRAME_TYPE",e,"layout, assembly and compatible placement required"),[{kind:"collection",frame:t[2].to}]},run:([t,e,n,i],s,r)=>{t.count*e.members.length>1e4&&Fw("RESOURCE_LIMIT",s,"expanded geometry count > 10000");const o=["x","y","z"].indexOf(r.params.axis),a=["x","y","z"].indexOf(r.params.riseAxis),c=[];for(let s=0;s<t.count;s++)for(const l of e.members){const e=[0,0,0];e[o]=t.centers[s],void 0!==i&&(e[a]=s*i);const h=[r.id,s,...l.path??[l.key]];c.push({id:JSON.stringify(h),path:h,key:l.key,index:s,shape:l.shape,pose:oM(oM(n,{r:Jw(),t:e}),l.pose)})}return[{items:c}]},geometry:(t,e,n)=>n.params.within?[]:e[0].items},"select-item@1":{ports:["placed"],params:["member"],types:(t,e)=>(2===t.length&&"collection"===t[0].kind&&$w(t[1],Vw)||Fw("TYPE",e,"collection and count index required"),[{kind:"placed",frame:t[0].frame}]),run:([t,e],n,i)=>{const s=t.items.find(t=>t.index===e&&t.key===i.params.member);return s||Fw("TARGET_ABSENT",n,`${i.params.member}[${e}]`),[{shape:s.shape,pose:s.pose}]}},"rigid@1":{ports:["pose"],params:["from","to"],types:(t,e,n)=>(Kw(t,[Hw,Hw,Hw,Yw,Yw,Yw],e),[Zw(n.params.from,n.params.to)]),run:([t,e,n,i,s,r])=>{const o=Math.cos(i),a=Math.sin(i),c=Math.cos(s),l=Math.sin(s),h=Math.cos(r),d=Math.sin(r);return[{r:sM(sM([[1,0,0],[0,o,-a],[0,a,o]],[[c,0,l],[0,1,0],[-l,0,c]]),[[h,-d,0],[d,h,0],[0,0,1]]),t:[t,e,n]}]}},"axis-turn@1":{ports:["pose"],params:["from","to"],types:(t,e,n)=>(Kw(t,[Bw,Bw,Bw,Yw],e),[Zw(n.params.from,n.params.to)]),run:([t,e,n,i],s)=>{const r=Math.hypot(t,e,n);Math.abs(r-1)>1e-6&&Fw("AXIS",s,"unit axis required");const o=t/r,a=e/r,c=n/r,l=Math.cos(i),h=Math.sin(i),d=1-l;return[{r:[[l+o*o*d,o*a*d-c*h,o*c*d+a*h],[a*o*d+c*h,l+a*a*d,a*c*d-o*h],[c*o*d-a*h,c*a*d+o*h,l+c*c*d]],t:[0,0,0]}]}},"axis-slide@1":{ports:["pose"],params:["from","to"],types:(t,e,n)=>(Kw(t,[Bw,Bw,Bw,Hw],e),[Zw(n.params.from,n.params.to)]),run:([t,e,n,i],s)=>{const r=Math.hypot(t,e,n);return Math.abs(r-1)>1e-6&&Fw("AXIS",s,"unit axis required"),[{r:[[1,0,0],[0,1,0],[0,0,1]],t:[t/r*i,e/r*i,n/r*i]}]}},"compose@1":{ports:["pose"],types:(t,e)=>(lM(t,e,2),t[1].to!==t[0].from&&Fw("FRAME_TYPE",e,"composition intermediate frame mismatch"),[Zw(t[1].from,t[0].to)]),run:([t,e])=>[oM(t,e)]},"attach@1":{ports:["pose"],types(t,e){lM(t,e,3);const[n,i,s]=t;return n.from===i.to&&i.from===s.from||Fw("FRAME_TYPE",e,"A O inverse(B) frame mismatch"),[Zw(s.to,n.to)]},run:([t,e,n])=>[oM(oM(t,e),aM(n))]},"point@1":{ports:["point"],params:["frame"],types:(t,e,n)=>(Kw(t,[Hw,Hw,Hw],e),[{kind:"point",frame:n.params.frame}]),run:t=>[t]},"map-point@1":{ports:["point"],types:(t,e)=>(2===t.length&&"transform"===t[0].kind&&"point"===t[1].kind&&t[0].from===t[1].frame||Fw("FRAME_TYPE",e,"point frame must match transform source"),[{kind:"point",frame:t[0].to}]),run:([t,e])=>[rM(iM(t.r,e),t.t)]},"distance@1":{ports:["length"],types:(t,e)=>(2===t.length&&"point"===t[0].kind&&$w(t[0],t[1])||Fw("FRAME_TYPE",e,"distance requires points in same frame"),[Hw]),run:([t,e])=>[Math.hypot(...t.map((t,n)=>t-e[n]))]},"feature@1":{ports:["pose"],params:["frame","name"],types(t,e,n){1===t.length&&"shape"===t[0].kind&&t[0].faces||Fw("TYPE",e,"shape required");const i=Object.keys(t[0].faces);return[...i,"centre",..."revolve"!==t[0].provider||i.length?[]:["left","right","bottom","top","back","front"]].includes(n.params.name)||Fw("UNKNOWN_FEATURE",e,n.params.name),[Zw(n.params.frame,t[0].frame)]},run:([t],e,n)=>{const i=jw(t,n.params.name);return i||Fw("UNKNOWN_FEATURE",e,n.params.name),[{r:[[1,0,0],[0,1,0],[0,0,1]],t:i}]}},"place@1":{ports:["placed"],types:(t,e)=>(2===t.length&&"shape"===t[0].kind&&"transform"===t[1].kind&&t[0].frame===t[1].from||Fw("FRAME_TYPE",e,"shape local frame mismatch"),[{kind:"placed",frame:t[1].to}]),run:([t,e])=>[{shape:t,pose:e}],geometry:([t,e])=>({shape:t,pose:e})}}),Qw["member@1"]={...Qw["place@1"],geometry:void 0},Object.assign(Qw,Rw);for(const[t,e]of Object.entries(Qw))e.state="fit-pitch@1"===t||"fixed-count@1"===t?"refuses":"follows";const hM=[];for(const[t,e]of Object.entries(Qw))e.pure=!hM.includes(t);const dM=["add@1","mul@1","div@1","sin@1","geomean@1","curve@1","at-least@1","max@1","min@1","affine-bounds@1","between@1","assembly@1","repeat@1","select-item@1","rigid@1","axis-turn@1","axis-slide@1","compose@1","attach@1","point@1","map-point@1","distance@1","place@1","member@1"];for(const[t,e]of Object.entries(Qw))e.pure&&dM.includes(t)&&(e.poseForm="run");function uM(t,e,n){return Array.isArray(e)?qw(t,n):"flag"===e.kind?("boolean"!=typeof t&&Fw("FLAG",n,"boolean required"),t):"count"===e.kind?((!Number.isSafeInteger(t)||t<0)&&Fw("COUNT",n,"nonnegative safe integer required"),t):("transform"===e.kind&&fM(t)?gM(t,n):"placed"===e.kind&&pM(t,"shape","pose")&&bM.has(t.shape)&&fM(t.pose)?gM(t.pose,n):(yM(t,n),"shape"===e.kind&&t&&"object"==typeof t&&bM.add(t)),t)}Object.freeze(Object.keys(Qw).filter(t=>!Qw[t].poseForm)),Object.freeze(Object.fromEntries(Object.entries(Qw).map(([t,e])=>[t,e.state]))),Object.freeze(Object.fromEntries(Object.entries(Qw).map(([t,e])=>[t,e.pure]))),Object.freeze(Object.keys(Qw));const pM=(t,e,n)=>{if(!t||"object"!=typeof t||Array.isArray(t))return!1;let i=0;for(const s in t)if(Object.hasOwn(t,s)){if(i>1||s!==(0===i?e:n))return!1;i++}return 2===i},fM=t=>pM(t,"r","t")&&Array.isArray(t.r)&&Array.isArray(t.t);function mM(t,e){for(let n=0;n<t.length;n++){if(!(n in t))continue;const i=t[n];"number"==typeof i?Number.isFinite(i)||Fw("NON_FINITE",e,String(i)):yM(i,e)}}function gM(t,e){for(let n=0;n<t.r.length;n++){if(!(n in t.r))continue;const i=t.r[n];Array.isArray(i)?mM(i,e):yM(i,e)}mM(t.t,e)}function yM(t,e){if("number"==typeof t)Number.isFinite(t)||Fw("NON_FINITE",e,String(t));else if(Array.isArray(t))for(let n=0;n<t.length;n++)n in t&&yM(t[n],e);else if(t&&"object"==typeof t){const n=Object.keys(t);if(!(n.length<=2&&Array.isArray(t[n[0]])&&(n.length<2||Array.isArray(t[n[1]])))&&bM.has(t))return;for(let i=0;i<n.length;i++)yM(t[n[i]],e)}}const bM=new WeakSet,_M=["transform","placed","assembly","collection","point"],vM=t=>Array.isArray(t)||_M.includes(t?.kind)?void 0:String(t?.kind??"value");function xM(t){return function(t){Uw(t,["version","inputs","constants","nodes"],[],"model"),["r3-scalar-1","r3-spatial-1"].includes(t.version)||Fw("VERSION","model",t.version);for(const e of["inputs","constants","nodes"])Array.isArray(t[e])||Fw("SCHEMA",e,"array required");const e=structuredClone(t),n=new Map,i=new Map,s=new Map,r=new Map,o=[],a=[],c=(t,e)=>{Ww(t,e),n.has(t)&&Fw("DUPLICATE_WRITER",t,`${n.get(t)} and ${e}`),n.set(t,e)};for(const t of e.inputs)Uw(t,["id","unit","min","max"],["role"],"input"),c(t.id,"input"),i.set(t.id,Xw(t.unit,t.id)[0]),t.role&&!["design","state"].includes(t.role)&&Fw("SCHEMA",t.id,"unknown input role"),"state"===t.role&&s.set(t.id,new Set([t.id])),qw(t.min,t.id)>qw(t.max,t.id)&&Fw("RANGE",t.id,"min > max"),"count"===t.unit&&(uM(t.min,Vw,t.id),uM(t.max,Vw,t.id));for(const t of e.constants)Uw(t,["id","unit","value"],[],"constant"),c(t.id,"constant"),i.set(t.id,Xw(t.unit,t.id)[0]),uM(t.value,i.get(t.id),t.id);for(const t of e.nodes){Uw(t,["id","op","args","outputs"],["params"],"node"),Ww(t.id,"node"),r.has(t.id)&&Fw("DUPLICATE_NODE",t.id,"node id"),Object.hasOwn(Qw,t.op)||Fw("OPERATOR",t.id,t.op),Qw[t.op].params?cM(t,Qw[t.op].params,Qw[t.op].optionalParams):Object.hasOwn(t,"params")&&Fw("SCHEMA",t.id,"unexpected params"),Array.isArray(t.args)||Fw("SCHEMA",t.id,"args array required"),t.args.forEach(e=>Ww(e,t.id)),Uw(t.outputs,Qw[t.op].ports,[],t.id);for(const e of Object.values(t.outputs))c(e,t.id);r.set(t.id,t)}const l=new Set;function h(t){if(l.has(t))return;a.includes(t)&&Fw("CYCLE",t,[...a,t].join(" -> ")),a.push(t);const e=r.get(t),c=Qw[e.op],d=e.args.map(t=>(n.has(t)||Fw("UNKNOWN_REFERENCE",e.id,t),i.has(t)||h(n.get(t)),i.get(t))),u=c.types(d,e.id,e),p=new Set;for(const t of e.args)for(const e of s.get(t)??[])p.add(e);p.size&&(void 0===c.state&&Fw("STATE_POLICY",e.id,`${e.op} declares no policy for a state-dependent argument (${[...p].join(", ")})`),"refuses"===c.state&&Fw("TOPOLOGY_STATE",e.id,`${e.op} must depend on design inputs only; it depends on ${[...p].join(", ")}`)),c.ports.forEach((t,n)=>i.set(e.outputs[t],u[n])),p.size&&Object.values(e.outputs).forEach(t=>s.set(t,new Set(p))),a.pop(),l.add(t),o.push(e)}for(const t of r.keys())h(t);let d;const u=new Map,p=new Set(e.inputs.map(t=>t.id));function f(t){t&&"object"==typeof t&&!Array.isArray(t)||Fw("SCHEMA","input values","object required");for(const n of e.inputs)Object.hasOwn(t,n.id)||Fw("SCHEMA","input values",`missing ${n.id}`);for(const e of Object.keys(t))p.has(e)||Fw("SCHEMA","input values",`unknown ${e}`)}function m(t,e){const n=qw(e,t.id);return(n<t.min||n>t.max)&&Fw("INPUT_RANGE",t.id,`${n} outside [${t.min},${t.max}]`),uM(n*Xw(t.unit,t.id)[1],i.get(t.id),t.id)}function g(t,n){f(t);const s=new Map,r=[],a=new Map,c=new Set;for(const n of e.inputs)s.set(n.id,m(n,t[n.id])),c.add(n.id);for(const t of e.constants)s.set(t.id,qw(t.value*Xw(t.unit,t.id)[1],t.id));for(const t of o){const e=Qw[t.op],n=t.args.map(t=>s.get(t)),o=e.run(n,t.id,t);if(e.ports.forEach((e,n)=>{s.set(t.outputs[e],uM(o[n],i.get(t.outputs[e]),t.id)),c.add(t.outputs[e])}),e.geometry){const i=e.geometry(n,o,t),s=Array.isArray(i)?i:[{id:t.id,...i}];a.set(t.id,s),r.push(...s)}}return{result:{values:Object.fromEntries(s),geometry:r},kept:{input:{...t},values:s,bodies:a}}}return{outputTypes:Object.fromEntries([...i].map(([t,e])=>[t,structuredClone(e)])),dependence:Object.fromEntries([...s].map(([t,e])=>[t,[...e].sort()])),order:o.map(t=>t.id),evaluate:t=>g(t).result,evaluator(t={}){let e,n,i=0,s=[];const r=(t,e)=>{const n=t.geometry.map(t=>t.id);return(e||n.length!==s.length||n.some((t,e)=>t!==s[e]))&&i++,s=n,t},o=t=>{const n=e;if(e=void 0,!n){const n=g(t);return e=b(n.kept,n.result),r(n.result,!0)}const i=M(t,n);return e=n,r(i,!1)};return{evaluate:o,advance(s,r){if(e&&!r){const r=e;e=void 0;const a=w(s,r,n??=_(t.reads));if(e=r,"result"in a)return{...a.result,generation:i};return{kind:"evaluation",result:o(s),generation:i,why:a.why}}const a=!!e;return{kind:"evaluation",result:o(s),generation:i,why:{code:a?r:"NOT_BOUND"}}},poseInputs:()=>_(t.reads).inputs.map(t=>({...t}))}}};function y(){if(d)return d;const t=new Map,n=[],s=e=>{t.set(e,n.length),n.push(e)};e.inputs.forEach(t=>s(t.id)),e.constants.forEach(t=>s(t.id));const r=o.map((e,n)=>{const r=Qw[e.op];return r.ports.forEach(t=>s(e.outputs[t])),{n:e,op:r,index:n,args:e.args.map(e=>t.get(e)),outs:r.ports.map(n=>t.get(e.outputs[n])),types:r.ports.map(t=>i.get(e.outputs[t]))}}),a=n.map(()=>[]);for(const t of r)for(const e of t.args)a[e].push(t.index);const c=t=>{const e=new Uint8Array(r.length),n=[...t];for(;n.length;){const t=n.pop();for(const i of a[t])e[i]||(e[i]=1,n.push(...r[i].outs))}const i=[];return e.forEach((t,e)=>t&&i.push(e)),i},l=r.filter(t=>!t.op.pure),h=[...new Set([...l.map(t=>t.index),...c(l.flatMap(t=>t.outs))])].sort((t,e)=>t-e);return d={keys:n,slot:t,nodes:r,readers:a,reach:e.inputs.map((t,e)=>c([e])),always:h,shapes:r.filter(t=>t.op.geometry).map(t=>t.index)},d}function b(t,n){const i=y();return{raw:e.inputs.map(e=>t.input[e.id]),slots:i.keys.map(e=>t.values.get(e)),bodies:i.nodes.map(e=>t.bodies.get(e.n.id)),values:{...n.values},geometry:n.geometry.slice(),mark:new Int32Array(i.keys.length),ran:new Int32Array(i.nodes.length),epoch:0}}function _(t={}){const n=JSON.stringify([t.forbidden??{},[...t.external??[]].sort()]),s=u.get(n);if(s)return s;const r=y(),o=t.forbidden??{},a=new Set(t.external??[]),c={inputs:e.inputs.map((t,e)=>{const n=vM(i.get(t.id));if(n)return{fast:!1,code:"INPUT_NOT_POSE",input:t.id,node:t.id,reaches:n};if(Object.hasOwn(o,t.id))return{fast:!1,code:"INPUT_NOT_POSE",input:t.id,node:t.id,reaches:o[t.id]};for(const n of r.reach[e]){const e=r.nodes[n];if(!e.op.poseForm)return{fast:!1,code:"UNSUPPORTED_OPERATOR",input:t.id,node:e.n.id,op:e.n.op};for(const[n,i]of e.outs.entries()){const s=vM(e.types[n]);if(s)return{fast:!1,code:"INPUT_NOT_POSE",input:t.id,node:e.n.id,reaches:s};const a=r.keys[i];if(Object.hasOwn(o,a))return{fast:!1,code:"INPUT_NOT_POSE",input:t.id,node:e.n.id,reaches:o[a]}}}return{fast:!0}}),terminal:r.nodes.map(t=>"repeat@1"===t.n.op&&!t.n.params?.within&&t.outs.every(t=>!r.readers[t].length&&!a.has(r.keys[t]))),visits:new Map};return u.set(n,c),c}function v(t,e){const n=y();if(1===t.length)return n.reach[t[0]];const i=t.join();let s=e.visits.get(i);if(!s){const r=new Set;for(const e of t)for(const t of n.reach[e])r.add(t);s=[...r].sort((t,e)=>t-e),e.visits.size<256&&e.visits.set(i,s)}return s}function x(t){const e=y(),n=new Int32Array(e.nodes.length).fill(-1);let i=0;for(const s of e.shapes)n[s]=i,i+=t.bodies[s]?.length??0;return{raw:t.raw.slice(),slots:t.slots.slice(),mark:new Int32Array(e.keys.length),epoch:0,start:n,bodyCount:i,prefix:new Map}}function w(t,n,i){const s=y();f(t);const r=n.fast??=x(n),o=[],a=[];for(let n=0;n<e.inputs.length;n++){const i=e.inputs[n],s=t[i.id];s!==r.raw[n]&&(a.push(m(i,s)),o.push(n))}for(const t of o)if(!i.inputs[t].fast)return{why:i.inputs[t]};const c=++r.epoch;o.forEach((n,i)=>{r.raw[n]=t[e.inputs[n].id],r.slots[n]=a[i],r.mark[n]=c});const l=v(o,i),h=new Int32Array(r.bodyCount),d=new Float64Array(12*r.bodyCount);let u=0;const p=(t,e)=>{const n=e.r,i=e.t,s=12*u;h[u++]=t,d[s]=n[0][0],d[s+1]=n[0][1],d[s+2]=n[0][2],d[s+3]=n[1][0],d[s+4]=n[1][1],d[s+5]=n[1][2],d[s+6]=n[2][0],d[s+7]=n[2][1],d[s+8]=n[2][2],d[s+9]=i[0],d[s+10]=i[1],d[s+11]=i[2]};for(const t of l){const e=s.nodes[t];let n=!1;for(const t of e.args)if(r.mark[t]===c){n=!0;break}if(!n)continue;const o=new Array(e.args.length);for(let t=0;t<e.args.length;t++)o[t]=r.slots[e.args[t]];if(i.terminal[t]){const[n,i,s,a]=o,l=["x","y","z"].indexOf(e.n.params.axis),h=["x","y","z"].indexOf(e.n.params.riseAxis);let d=r.mark[e.args[2]]!==c&&(void 0===e.args[3]||r.mark[e.args[3]]!==c)?r.prefix.get(t):void 0;if(!d){d=[];for(let t=0;t<n.count;t++){const e=[0,0,0];e[l]=n.centers[t],void 0!==a&&(e[h]=t*a),d.push(oM(s,{r:Jw(),t:e}))}r.prefix.set(t,d)}let u=r.start[t];for(let t=0;t<n.count;t++)for(const n of i.members){const i=oM(d[t],n.pose);yM(i,e.n.id),p(u++,i)}continue}const a=e.op.run(o,e.n.id,e.n);if(e.outs.forEach((t,n)=>{r.slots[t]=uM(a[n],e.types[n],e.n.id),r.mark[t]=c}),e.op.geometry){const n=e.op.geometry(o,a,e.n),i=Array.isArray(n)?n:[n];let s=r.start[t];for(const t of i)p(s++,t.pose)}}return{result:{kind:"poses",generation:0,bodies:h.slice(0,u),poses:d.slice(0,12*u),read:t=>{const e=s.slot.get(t);return void 0===e&&Fw("TARGET_ABSENT",t,"no such value"),r.slots[e]},changed:t=>{const e=s.slot.get(t);return void 0!==e&&r.mark[e]===c}}}}function M(t,n){const i=y();f(t),n.fast=void 0;const s=++n.epoch,r=[];let o,a=-1,c=!1;if(e.inputs.forEach((e,i)=>{const o=t[e.id];o!==n.raw[i]&&(n.slots[i]=m(e,o),n.raw[i]=o,n.mark[i]=s,r.push(i),a>=0&&(c=!0),a=i)}),c||i.always.length){const t=[];for(const e of[...r.map(t=>i.reach[t]),i.always])for(const i of e)n.ran[i]!==s&&(n.ran[i]=s,t.push(i));o=t.sort((t,e)=>t-e)}else o=a>=0?i.reach[a]:[];let l=!1;for(const t of o){const e=i.nodes[t];if(e.op.pure&&!e.args.some(t=>n.mark[t]===s))continue;const o=e.args.map(t=>n.slots[t]),a=e.op.run(o,e.n.id,e.n);if(e.outs.forEach((t,i)=>{n.slots[t]=uM(a[i],e.types[i],e.n.id),n.mark[t]=s,r.push(t)}),e.op.geometry){const i=e.op.geometry(o,a,e.n);n.bodies[t]=Array.isArray(i)?i:[{id:e.n.id,...i}],l=!0}}for(const t of r)n.values[i.keys[t]]=n.slots[t];if(l){const t=[];for(const e of i.shapes){const i=n.bodies[e];i&&t.push(...i)}n.geometry=t}return{values:{...n.values},geometry:n.geometry.slice()}}}(t)}function wM(t,e,n){const i=function(t,e){const n=t.find(t=>t.id===e);if(!n)return{code:"TARGET_ABSENT",message:`${String(e)} is not an input of the figure`};if("state"===n.role)return{code:"PUBLIC_INPUT",message:`${e} is a state input; a board sets it as a parameter`};if(/^(sizing\.)?size\.[xyz]$/.test(e))return{code:"PUBLIC_INPUT",message:`${e} is the figure's size; a board sets it from the instance's bounds`};const i=t=>Number.isFinite(t)&&Math.abs(t)<1e12&&t!==Number.MIN_VALUE;return i(n.min)&&i(n.max)?null:{code:"PUBLIC_INPUT",message:`${e} has no range to hold a board's value to; give it one first`}}(t,e);if(i)throw new tw(i.code,n,i.message)}const MM=(t,e,n)=>{throw new tw(t,e,n)},SM={left:[-1,0,0],right:[1,0,0],bottom:[0,-1,0],top:[0,1,0],back:[0,0,-1],front:[0,0,1]};function kM(t,e,n){const{types:i,writers:s,model:r,assetFrame:o}=t;e&&"object"==typeof e&&!Array.isArray(e)||MM("SCHEMA",n,"object required");for(const t of["placement","feature"])Object.hasOwn(e,t)||MM("SCHEMA",n,`missing ${t}`);for(const t of Object.keys(e))["placement","feature"].includes(t)||MM("SCHEMA",n,`unknown ${t}`);const a=t=>("string"==typeof t&&t.trim()||MM("SCHEMA",n,"nonempty string required"),Object.hasOwn(i,t)||MM("TARGET_ABSENT",n,t),i[t]),c=a(e.placement),l=a(e.feature),h=s.get(e.placement),d=s.get(e.feature);let u,p=h;if("select-item@1"===h?.op){const t=s.get(h.args[0]),e="repeat@1"===t?.op?s.get(t.args[1]):null;"assembly@1"===e?.op&&e.args.includes(h.params.member)||MM("SURFACE_PROVENANCE",n,"selected member must belong to the referenced repeat assembly"),p=s.get(h.params.member),"member@1"!==p?.op&&MM("SURFACE_PROVENANCE",n,"selected source must be a declared template member"),r.inputs.some(t=>t.id===h.args[1]&&"state"===t.role)&&MM("TARGET_STATE",n,"binding target index must not change as animation state"),u={collection:h.args[0],index:h.args[1],member:h.params.member}}else"place@1"!==h?.op&&MM("SURFACE_PROVENANCE",n,"actual placement or selected repeated member required");"feature@1"!==d?.op&&MM("SURFACE_PROVENANCE",n,"provider feature required"),"placed"===c.kind&&c.frame===o&&"transform"===l.kind||MM("FRAME_TYPE",n,"contact must be in asset frame"),p.args[0]!==d.args[0]&&MM("SURFACE_OWNER",n,"feature belongs to a different shape declaration");const f=i[d.args[0]].provider,m=d.params.name,g=i[d.args[0]].faces,y=g?.[m];y||MM("SURFACE_UNSUPPORTED",n,"feature is not a supported planar surface"),"line"===y[2]&&MM("SURFACE_UNSUPPORTED",n,"feature touches a curved side along a line; it is not a surface to hold things on");const b=["x","y","z"].map(t=>t===y[0]?y[1]:0);return{...e,geometryId:u?null:h.id,selection:u,provider:f,face:m,frame:l.from,normal:b}}function AM(t,e,n,i,s={}){const[r,o]=ew[e],a=(t,i)=>{const a={x:0,y:0,z:0};return a[e]=n,a[r]=t+(s[r]??0),a[o]=i+(s[o]??0),[a.x,a.y,a.z]};if("polygon"===t.kind)return t.points.map(t=>a(t[r],t[o]));if("ellipse"===t.kind)return Array.from({length:i},(e,n)=>{const s=2*Math.PI*n/i;return a(t.radius[r]*Math.cos(s),t.radius[o]*Math.sin(s))});const c=t.size[r]/2,l=t.size[o]/2,h=t.corner?.[r]??0,d=t.corner?.[o]??0;if(!(h>0&&d>0))return[a(-c,-l),a(c,-l),a(c,l),a(-c,l)];const u=[];for(const[t,e,n]of[[1,1,0],[-1,1,Math.PI/2],[-1,-1,Math.PI],[1,-1,3*Math.PI/2]])for(let i=0;i<=8;i++){const s=n+i/8*(Math.PI/2);u.push(a(t*(c-h)+h*Math.cos(s),e*(l-d)+d*Math.sin(s)))}return u}function EM(t,e){return function(t,e){const n=t.extrusion;if(n){const i=[...AM(n.section,n.axis,n.start,e),...AM(n.section,n.axis,n.end,e)],s=t.cavity;if(s){const t=pw(n.section,n.axis,s.wall);if("section"in t){const r=n.start+("open"===s.start?0:s.start.closed),o=n.end-("open"===s.end?0:s.end.closed);i.push(...AM(t.section,n.axis,r,e,t.centre),...AM(t.section,n.axis,o,e,t.centre))}}return i}const i=t.loft;if(i){const t={x:0,y:0,z:0,...i.apex,[i.axis]:i.end};return[...AM(i.section,i.axis,i.start,e),[t.x,t.y,t.z]]}const s=t.revolution,[r,o]=ew[s.axis],a=(t,n)=>AM({kind:"ellipse",radius:{[r]:n,[o]:n}},s.axis,t,e);if("taper"===s.profile.kind)return[...a(s.profile.start,Math.max(s.profile.startRadius,1e-9)),...a(s.profile.end,Math.max(s.profile.endRadius,1e-9))];const{radial:c,axial:l}=s.profile,h=[];for(let t=1;t<6;t++){const e=t/6*Math.PI;h.push(...a(l*Math.cos(e),c*Math.sin(e)))}return h.push(...a(l,1e-9).slice(0,1),...a(-l,1e-9).slice(0,1)),h}(t,e??12)}function CM(t,e,n){return t.map(([t,i,s])=>[e[0][0]*t+e[0][1]*i+e[0][2]*s+n[0],e[1][0]*t+e[1][1]*i+e[1][2]*s+n[1],e[2][0]*t+e[2][1]*i+e[2][2]*s+n[2]])}function TM(t){const e=new Map;for(const n of t.document.model.nodes)for(const t of Object.values(n.outputs))e.set(t,n.id);return e}const PM=["floor","ceiling","center","wall"];function OM(t){const[e,n,i]=t.map(t=>t*Math.PI/180),s=t=>Math.round(Math.cos(t)),r=t=>Math.round(Math.sin(t)),o=[[1,0,0],[0,s(e),-r(e)],[0,r(e),s(e)]],a=[[s(n),0,r(n)],[0,1,0],[-r(n),0,s(n)]],c=[[s(i),-r(i),0],[r(i),s(i),0],[0,0,1]];return DM(DM(o,a),c)}const DM=(t,e)=>t.map(t=>e[0].map((n,i)=>t.reduce((t,n,s)=>t+n*e[s][i],0)));function IM(t){const e=t.document.model,n=t=>e.constants.find(e=>e.id===t)?.value;return t.document.capabilities.bindings.map(t=>{const i="string"==typeof t.pose?null:t.pose,s=i?e.nodes.find(t=>"place@1"===t.op&&t.outputs.placed===i.placement):null,r=i?((t,e)=>t.nodes.find(t=>Object.values(t.outputs).includes(e)))(e,i.feature):null,o=(t.region?.dimensions??[]).map(n);return{id:t.id,label:t.label,role:t.role,part:s?.id??null,face:r?.params?.name??null,accepts:[...t.accepts],capacity:t.capacity,region:3===o.length&&o.every(t=>"number"==typeof t)?{x:o[0],y:o[1],z:o[2]}:null}})}(()=>{const t=[];for(const e of[0,90,180,270])for(const n of[0,90,180,270])for(const i of[0,90,180,270]){const s=OM([e,n,i]);t.some(t=>t.every((t,e)=>t.every((t,n)=>t===s[e][n])))||t.push(s)}})();const zM=(t,e,n)=>{throw new tw(t,e,n)};function RM(t,e,n,i){t&&"object"==typeof t&&!Array.isArray(t)||zM("SCHEMA",i,"object required");for(const n of e)Object.hasOwn(t,n)||zM("SCHEMA",i,`missing ${n}`);for(const s of Object.keys(t))[...e,...n].includes(s)||zM("SCHEMA",i,`unknown ${s}`)}const jM=(t,e)=>{"string"==typeof t&&t.trim()||zM("SCHEMA",e,"nonempty string required")};function LM(t,e){return function(t,e){const n=xM(t),i=structuredClone(e),s=n.outputTypes,r=new Map(t.nodes.flatMap(t=>Object.values(t.outputs).map(e=>[e,structuredClone(t)]))),o=new Map;RM(i,["version","assetFrame","bindings"],["names"],"capabilities"),"r3-capability-3"!==i.version&&zM("VERSION","capabilities",i.version);if(jM(i.assetFrame,"assetFrame"),void 0!==i.names){Array.isArray(i.names)||zM("SCHEMA","names","array required");for(const t of i.names)Kx.includes(t)||zM("CAPABILITY_NAME","names",`${String(t)} is not one of ${Kx.join(", ")}`);new Set(i.names).size!==i.names.length&&zM("CAPABILITY_NAME","names","duplicate capability name");for(const[t,e]of Object.entries(Qx))i.names.includes(t)&&!e.some(t=>i.names.includes(t))&&zM("CAPABILITY_NAME","names",`${t} needs one of ${e.join(", ")} with it`)}Array.isArray(i.bindings)||zM("SCHEMA","bindings","array required");const a=new Set,c=(t,e)=>(jM(t,e),Object.hasOwn(s,t)||zM("TARGET_ABSENT",e,t),s[t]),l=(t,e,n)=>{const s=c(t,e);("transform"!==s.kind||s.to!==i.assetFrame||void 0!==n&&s.from!==n)&&zM("FRAME_TYPE",e,"transform must map declared local frame to assetFrame")},h=(e,n)=>kM({types:s,writers:r,model:t,assetFrame:i.assetFrame},e,n),d=new Map;for(const t of i.bindings){RM(t,["id","label","role","frame","pose","accepts","capacity"],["region","contacts"],"binding");for(const e of["id","label","frame"])jM(t[e],e);if(a.has(t.id)&&zM("DUPLICATE_BINDING",t.id,"duplicate id"),a.add(t.id),["seat","grip"].includes(t.role)||zM("ROLE",t.id,"explicit seat or grip required; slot is ambiguous"),"string"==typeof t.pose)l(t.pose,t.id,t.frame);else{const e=h(t.pose,t.id);e.frame!==t.frame&&zM("FRAME_TYPE",t.id,"binding frame must be the selected feature frame"),d.set(t.id,e)}if(Array.isArray(t.accepts)&&t.accepts.length||zM("SCHEMA",t.id,"nonempty accepts required"),t.accepts.forEach(e=>jM(e,t.id)),new Set(t.accepts).size!==t.accepts.length&&zM("SCHEMA",t.id,"duplicate accepted type"),(!Number.isSafeInteger(t.capacity)||t.capacity<1)&&zM("CAPACITY",t.id,"positive integer capacity required"),Object.hasOwn(t,"region")){RM(t.region,["kind","dimensions"],[],t.id+".region"),"centered-box"!==t.region.kind&&zM("REGION",t.id,"only centered-box is specified"),Array.isArray(t.region.dimensions)&&3===t.region.dimensions.length||zM("SCHEMA",t.id,"three dimension references required");for(const e of t.region.dimensions)"[1,0,0]"!==JSON.stringify(c(e,t.id))&&zM("TYPE",t.id,"region dimensions must be lengths")}if(void 0!==t.contacts){Array.isArray(t.contacts)||zM("SCHEMA",t.id,"contact array required");const e=new Set,n=[];for(const i of t.contacts){const s=h(i,t.id),r=JSON.stringify([i.placement,i.feature]);e.has(r)&&zM("DUPLICATE_CONTACT",t.id,r),e.add(r),n.push(s)}o.set(t.id,n)}}function u(t,e,n){const i=t=>function(t,e){const n=t[e.placement],i=t[e.feature],s=n.pose.r,r=s.map(t=>t.reduce((t,n,i)=>t+n*e.normal[i],0)),o=s.map((t,e)=>n.pose.t[e]+t.reduce((t,e,n)=>t+e*i.t[n],0));let a=e.geometryId;if(e.selection){const n=e.selection,i=t[n.collection].items.find(e=>e.index===t[n.index]&&e.key===n.member);i||MM("TARGET_ABSENT",e.placement,"selected repeated item is absent"),a=i.id}return{placement:e.placement,feature:e.feature,geometryId:a,provider:e.provider,face:e.face,pose:{r:s.map(t=>[...t]),t:o},normal:r,provenance:"verified-planar-surface"}}(e,t);let s=null;if(t.region){const n=t.region.dimensions.map(t=>e[t]);n.some(t=>!Number.isFinite(t)||t<=0)&&zM("REGION_DOMAIN",t.id,"positive region dimensions required"),s={kind:t.region.kind,dimensions:n}}let r={status:"unverified",reason:"NO_REQUEST"};if(Object.hasOwn(n,t.id)){const e=n[t.id];RM(e,["type","occupied"],[],t.id+".request"),jM(e.type,t.id),(!Number.isSafeInteger(e.occupied)||e.occupied<0)&&zM("OCCUPANCY",t.id,"nonnegative integer occupancy snapshot required");const i=[];t.accepts.includes(e.type)||i.push("TYPE_NOT_ACCEPTED"),e.occupied>=t.capacity&&i.push("CAPACITY_FULL"),r={status:i.length?"failed":"satisfied",reasons:i}}const a=(o.get(t.id)??[]).map(i),c=d.has(t.id)?i(d.get(t.id)):null;return{id:t.id,label:t.label,role:t.role,frame:t.frame,pose:c?c.pose:e[t.pose],...c?{targetGeometryId:c.geometryId}:{},region:s,contacts:a,checks:{declaration:{status:"satisfied"},eligibility:r,spatial:{status:"unverified",reason:"NO_CONTACT_OR_FIT_SOLVER"},collision:{status:"unverified",reason:"NOT_CHECKED"},safety:{status:"unverified",reason:"NOT_CHECKED"}}}}function p(t,e,n={}){return RM(n,[],[...a],"requests"),f(t.evaluate(e),n)}function f(t,e){const n=i.bindings.map(n=>u(n,t.values,e));return{geometry:t.geometry,bindings:n,values:t.values}}const m=t=>[t.placement,t.feature,...t.selection?[t.selection.collection,t.selection.index]:[]],g=new Map(i.bindings.map(t=>[t.id,[..."string"==typeof t.pose?[t.pose]:m(d.get(t.id)),...(o.get(t.id)??[]).flatMap(m),...t.region?.dimensions??[]]])),y={forbidden:Object.fromEntries(i.bindings.flatMap(t=>(t.region?.dimensions??[]).map(e=>[e,`region of ${t.id}`]))),external:[...new Set([...g.values()].flat())]};return{outputTypes:structuredClone(s),dependence:structuredClone(n.dependence),evaluate:(t,e={})=>p(n,t,e),evaluator(){const t=n.evaluator({reads:y});return{evaluate:(e,n={})=>p(t,e,n),advance:(e,n={})=>{RM(n,[],[...a],"requests");const s=t.advance(e,Object.keys(n).length?"REQUESTS":void 0);if("evaluation"===s.kind)return{...s,result:f(s.result,n)};const r=i.bindings.filter(t=>g.get(t.id).some(t=>s.changed(t))).map(t=>u(t,Object.fromEntries(g.get(t.id).map(t=>[t,s.read(t)])),n));return{kind:"poses",generation:s.generation,bodies:s.bodies,poses:s.poses,places:r}},poseInputs:()=>t.poseInputs()}}}}(t,e)}const FM=1048576;function NM(t,e){throw new tw(t,"document",e)}function HM(t){return(new TextEncoder).encode(t).byteLength}function BM(t){const e=new Set;!function t(n,i){if(i>64&&NM("DOCUMENT_LIMIT","nesting exceeds 64"),null===n||"string"==typeof n||"boolean"==typeof n)return;if("number"==typeof n)return void(Number.isFinite(n)||NM("JSON_VALUE","nonfinite number"));"object"!=typeof n&&NM("JSON_VALUE","only JSON values are allowed"),e.has(n)&&NM("JSON_VALUE","cycle");const s=Array.isArray(n);s||function(t){const e=Object.getPrototypeOf(t);return null===e||null===Object.getPrototypeOf(e)&&"function"==typeof e.hasOwnProperty}(n)||NM("JSON_VALUE","plain objects required"),e.add(n);const r=Object.getOwnPropertyDescriptors(n);for(const e of Reflect.ownKeys(r)){if(s&&"length"===e)continue;"string"!=typeof e&&NM("JSON_VALUE","symbols unsupported");const o=r[e];o.enumerable&&Object.hasOwn(o,"value")||NM("JSON_VALUE","hidden properties and accessors unsupported"),!s||/^(0|[1-9][0-9]*)$/.test(e)&&Number(e)<n.length||NM("JSON_VALUE","extra array property"),t(o.value,i+1)}s&&Object.keys(n).length!==n.length&&NM("JSON_VALUE","sparse array"),e.delete(n)}(t,0)}function YM(t){if(BM(t),!t||Array.isArray(t)||"object"!=typeof t||3!==Object.keys(t).length||!["version","model","capabilities"].every(e=>Object.hasOwn(t,e)))throw new tw("SCHEMA","document","expected version, model, capabilities only");if("figure-prototype-1"!==t.version)throw new tw("VERSION","document","unsupported document version");if(HM(JSON.stringify(t))>FM)throw new tw("DOCUMENT_LIMIT","document","over 1 MiB");const e=t;if(!Array.isArray(e.model?.nodes)||e.model.nodes.length>8192)throw new tw("DOCUMENT_LIMIT","document","maximum 8192 nodes");return LM(e.model,e.capabilities)}const VM=(t,e,n)=>{throw new tw(t,e,n)};function GM(t){return new Map(t.document.model.inputs.filter(t=>"state"===t.role).map(t=>[t.id,t.unit]))}function $M(t,e){const n=t.keys;if(e<=n[0].at)return n[0].value;const i=n[n.length-1];if(e>=i.at)return i.value;let s=0;for(;s<n.length-2&&n[s+1].at<=e;)s++;const r=n[s],o=n[s+1];if("step"===t.interpolation)return r.value;const a=o.at-r.at;return r.value+(e-r.at)/a*(o.value-r.value)}function UM(t,e,n="other"){Number.isFinite(e)||VM("DRIVER_TIME",t.id,"finite time required");const i=Math.max(0,e),s=t.time.duration,r=t.keys[0].value,o=t.keys[t.keys.length-1];let a;if("hold"===t.loop)a=$M(t,Math.min(i/s,1));else{const e=Math.floor(i/s);a=$M(t,(i-e*s)/s),t.accumulates&&(a+=e*(o.value-r))}return t.accumulates?"deg"===n||"rad"===n?function(t,e){const n="deg"===e?360:2*Math.PI,i=n/2,s=((t+i)%n+n)%n-i;return s===i?-i:s}(a,n):VM("DRIVER_STATE",t.id,"an accumulating driver needs an angle unit"):a}const WM=(t,e,n)=>{throw new tw(t,e,n)};function qM(t,e,n,i){t&&"object"==typeof t&&!Array.isArray(t)||WM("ASSET_SCHEMA",i,"object required");for(const n of e)Object.hasOwn(t,n)||WM("ASSET_SCHEMA",i,`missing ${n}`);for(const s of Object.keys(t))[...e,...n].includes(s)||WM("ASSET_SCHEMA",i,`unknown ${s}`)}function XM(t){return function(t){BM(t);const e=KM(t);HM(JSON.stringify(e))>FM&&WM("DOCUMENT_LIMIT","asset","over 1 MiB");qM(e,["version","name","document","designInputs","stateDefaults","palette","appearance"],["occupancy","placement","drivers","stateInputs","sizing","detailLevel","joints","publicInputs"],"asset"),void 0===e.placement||PM.includes(e.placement)||WM("ASSET_SCHEMA","placement",`one of ${PM.join(", ")} required`);"figure-asset-1"!==e.version&&WM("VERSION","asset",e.version);"string"==typeof e.name&&e.name.trim()||WM("ASSET_SCHEMA","name","nonempty name required");const n=structuredClone(e),i=YM(n.document),s=n.document.model,r=s.inputs.filter(t=>"state"!==t.role).map(t=>t.id),o=s.inputs.filter(t=>"state"===t.role).map(t=>t.id);qM(n.designInputs,r,[],"designInputs"),void 0===n.detailLevel||(t=>Zx.includes(t))(n.detailLevel)||WM("ASSET_SCHEMA","detailLevel",`${String(n.detailLevel)} is not a detail level; ${Zx.join(", ")}`);if(void 0!==n.sizing){"uniform"!==n.sizing&&WM("ASSET_SCHEMA","sizing",`${String(n.sizing)} is not a sizing rule; 'uniform' is`);for(const t of["x","y","z"])s.inputs.some(e=>e.id===`size.${t}`&&"design"===e.role)||WM("ASSET_SCHEMA","sizing",`a figure that grows uniformly declares its instance size; size.${t} is missing`)}if(qM(n.stateDefaults,o,[],"stateDefaults"),void 0!==n.publicInputs){Array.isArray(n.publicInputs)||WM("ASSET_SCHEMA","publicInputs","a list of the inputs a board may set");const t=new Set;for(const[e,i]of n.publicInputs.entries()){const n=`publicInputs[${e}]`;qM(i,["input","label"],["hint"],n),wM(s.inputs,i.input,`${n}.input`),"string"==typeof i.label&&i.label.trim()||WM("ASSET_SCHEMA",`${n}.label`,"a name shown on the board"),void 0!==i.hint&&"string"!=typeof i.hint&&WM("ASSET_SCHEMA",`${n}.hint`,"one line"),t.has(i.input)&&WM("PUBLIC_INPUT",`${n}.input`,`${i.input} is listed twice`),t.add(i.input)}}n.palette&&"object"==typeof n.palette&&!Array.isArray(n.palette)||WM("ASSET_SCHEMA","palette","token to hex color map required");for(const[t,e]of Object.entries(n.palette))t.trim()&&"string"==typeof e&&/^#[0-9a-f]{6}$/i.test(e)||WM("PALETTE","palette","six digit hex color required");const a=t=>{"string"==typeof t&&Object.hasOwn(n.palette,t)||WM("PALETTE",String(t),"unresolved color token")},c=new Map(s.nodes.flatMap(t=>Object.values(t.outputs).map(e=>[e,t]))),l=new Map(s.nodes.filter(t=>["place@1","member@1"].includes(t.op)).map(t=>[t.id,t])),h=new Map;Array.isArray(n.appearance)||WM("ASSET_SCHEMA","appearance","array required");for(const t of n.appearance){if(qM(t,["target","material"],["segments","visibility"],"appearance"),void 0!==t.visibility){const e=i.outputTypes[t.visibility];"string"==typeof t.visibility&&e&&"flag"===e.kind||WM("VISIBILITY","appearance.visibility",`${String(t.visibility)} is not a flag value in the graph`)}if(l.has(t.target)&&!h.has(t.target)||WM("APPEARANCE_TARGET",String(t.target),"unknown or duplicate source placement"),qM(t.material,["token"],["preset","transparent","emissive"],"material"),a(t.material.token),void 0===t.material.preset||["default","metal","glass","plastic","wood","ceramic","rubber"].includes(t.material.preset)||WM("MATERIAL","preset","unknown preset"),void 0!==t.material.transparent&&"boolean"!=typeof t.material.transparent&&WM("MATERIAL","transparent","boolean required"),void 0!==t.material.emissive){const e=t.material.emissive;qM(e,["token","intensity","on"],[],"emissive"),a(e.token),("boolean"!=typeof e.on||!Number.isFinite(e.intensity)||e.intensity<0||e.intensity>5)&&WM("MATERIAL","emissive","invalid intensity or switch")}const e=c.get(l.get(t.target).args[0]);"revolve@1"===e?.op||"extrude@1"===e?.op&&"ellipse"===e.params?.section?[8,12,16,24,32,48].includes(t.segments)||WM("QUALITY","segments","explicit supported cylinder segment count required"):void 0!==t.segments&&WM("QUALITY","segments","segments unsupported on this provider"),h.set(t.target,t)}h.size!==l.size&&WM("APPEARANCE_MISSING","appearance","every source placement/member requires appearance");if(void 0!==n.occupancy){if(qM(n.occupancy,["bounds"],["contact"],"occupancy"),void 0!==n.occupancy.contact){const t=n.occupancy.contact;qM(t,["plane","surface"],[],"occupancy.contact"),"mounting-plane"!==t.plane&&WM("OCCUPANCY","occupancy.contact",`${String(t.plane)} is not a plane the figure can be mounted on`),kM({types:i.outputTypes,writers:c,model:s,assetFrame:n.document.capabilities.assetFrame},t.surface,"occupancy.contact.surface")}qM(n.occupancy.bounds,["x","y","z"],[],"occupancy.bounds");const t=JSON.stringify([1,0,0]);for(const e of["x","y","z"]){qM(n.occupancy.bounds[e],["min","max"],[],`occupancy.bounds.${e}`);for(const s of["min","max"]){const r=`occupancy.bounds.${e}.${s}`,o=n.occupancy.bounds[e][s];"string"==typeof o&&JSON.stringify(i.outputTypes[o])===t||WM("OCCUPANCY",r,`${String(o)} is not a length value in the graph`),i.dependence[o]?.length&&WM("OCCUPANCY_STATE",r,`${o} depends on state input ${i.dependence[o].join(", ")}; the occupancy is state-independent`)}}}function d(t={}){qM(t,[],o,"state overrides");const e={...n.designInputs,...n.stateDefaults,...t},s=i.evaluate(e),r=t=>t.key?c.get(t.key)?.id:t.id,a=new Map(n.appearance.map((t,e)=>[t.target,e])),l=s.geometry.map((t,e)=>({g:t,i:e,at:a.get(r(t))??Number.MAX_SAFE_INTEGER})).sort((t,e)=>t.at-e.at||t.i-e.i).map(t=>t.g).map(t=>{const e=r(t),n=h.get(e);return n||WM("APPEARANCE_MISSING",t.id,"no source appearance"),{...t,material:structuredClone(n.material),visible:void 0===n.visibility||s.values[n.visibility],...void 0!==n.segments?{segments:n.segments}:{}}});return{...s,geometry:l,inputs:e,palette:structuredClone(n.palette)}}return function(t){const e=t.drivers;if(void 0===e)return;Array.isArray(e)||VM("DRIVER","drivers","array required");const n=GM(t),i=new Set,s=new Set,r=new Map;for(const t of e){const e=`drivers.${String(t?.id??"?")}`,o=t=>t&&"object"==typeof t?Object.keys(t).sort():null;JSON.stringify(o(t))!==JSON.stringify(["accumulates","clip","id","interpolation","keys","loop","state","time"])&&VM("DRIVER",e,"exactly id, clip, state, time, keys, interpolation, loop, accumulates required"),"string"==typeof t.id&&t.id.trim()||VM("DRIVER",e,"id required"),i.has(t.id)&&VM("DRIVER",e,"duplicate driver id"),i.add(t.id),"string"==typeof t.clip&&t.clip.trim()||VM("DRIVER",e,"clip required; the playback group is declared, not read out of the id"),n.has(t.state)||VM("DRIVER_STATE",e,`${String(t.state)} is not a state input of this asset`),s.has(t.state)&&VM("DRIVER_STATE",e,`two drivers write ${t.state}; one writer per state`),s.add(t.state),JSON.stringify(o(t.time))===JSON.stringify(["duration","unit"])&&"s"===t.time.unit||VM("DRIVER_TIME",e,'time must be { unit: "s", duration }'),Number.isFinite(t.time.duration)&&t.time.duration>0||VM("DRIVER_TIME",e,"positive duration in seconds required");const a=r.get(t.clip);void 0===a?r.set(t.clip,t.time.duration):a!==t.time.duration&&VM("DRIVER_TIME",e,`clip "${t.clip}" already runs for ${a} s; one clip is one clock, so every driver in it shares a duration`),(!Array.isArray(t.keys)||t.keys.length<2)&&VM("DRIVER_KEYS",e,"at least two keys required");let c=-1/0;for(const n of t.keys)JSON.stringify(o(n))!==JSON.stringify(["at","value"])&&VM("DRIVER_KEYS",e,"a key is { at, value }"),Number.isFinite(n.at)&&n.at>=0&&n.at<=1||VM("DRIVER_KEYS",e,"key at must be a fraction of the duration in [0, 1]"),n.at>c||VM("DRIVER_KEYS",e,"key at values must strictly increase"),c=n.at,Number.isFinite(n.value)||VM("DRIVER_KEYS",e,"finite key value required");0!==t.keys[0].at&&VM("DRIVER_KEYS",e,"the first key is at 0"),["linear","step"].includes(t.interpolation)||VM("DRIVER",e,"interpolation is linear or step"),["wrap","hold"].includes(t.loop)||VM("DRIVER",e,"loop is wrap or hold"),"boolean"!=typeof t.accumulates&&VM("DRIVER",e,"accumulates must be a boolean");const l=n.get(t.state);t.accumulates&&"deg"!==l&&"rad"!==l&&VM("DRIVER_STATE",e,`an accumulating driver writes an angle; ${t.state} is in ${l}`)}}(n),function(t){const e=t.stateInputs;if(void 0===e)return;e&&"object"==typeof e&&!Array.isArray(e)||VM("STATE_INPUT","stateInputs","object required");const n=GM(t);for(const[t,i]of Object.entries(e)){const e=`stateInputs.${t}`;n.has(t)||VM("STATE_INPUT",e,`${t} is not a state input of this asset`),i&&"object"==typeof i&&!Array.isArray(i)||VM("STATE_INPUT",e,"object required");for(const t of Object.keys(i))"label"!==t&&"sweep"!==t&&VM("STATE_INPUT",e,`unknown ${t}`);void 0===i.label||"string"==typeof i.label&&i.label.trim()||VM("STATE_INPUT",e,"label must be a nonempty string"),void 0===i.sweep||Number.isFinite(i.sweep)&&i.sweep>=0||VM("STATE_INPUT",e,"sweep must be a number of seconds, zero or more")}}(n),d(),{evaluate:d}}(t)}function KM(t){const e=t,n=e?.occupancy&&"object"==typeof e.occupancy?e.occupancy.placement:void 0;if(void 0===n)return t;void 0!==e.placement&&e.placement!==n&&WM("PLACEMENT_CONFLICT","placement",`the asset says ${String(e.placement)} and its room says ${String(n)}; keep one`);const{placement:i,...s}=e.occupancy;return{...e,placement:n,occupancy:s}}const QM="0.3.0";function ZM(t){const e=t.material,n=e.emissive?.on?`on:${e.emissive.token}:${e.emissive.intensity}`:"off";return`${e.token}|${e.preset??"default"}|${e.transparent?"t":"o"}|${n}`}const JM=t=>JSON.stringify([t.shape.provider,t.shape.dimensions,t.shape.extrusion?[t.shape.extrusion.axis,t.shape.extrusion.section.kind,t.shape.cavity??null]:t.shape.revolution?[t.shape.revolution.axis,t.shape.revolution.profile.kind]:t.shape.loft?[t.shape.loft.axis,"loft"]:null,t.segments??null,ZM(t),!1!==t.visible]);function tS(t,e){const n=function(t,e){const n=e??YM(t.document).dependence,i=new Map(t.document.model.nodes.map(t=>[t.id,t])),s=TM(t),r=t=>{const e=void 0===t?void 0:i.get(t);return!e||Object.values(e.outputs).some(t=>(n[t]?.length??0)>0)};return t=>{const{key:e,path:n}=t;return!!r("string"==typeof n?.[0]?n[0]:t.id)||!!e&&r(s.get(e))}}(t,e),i=TM(t),s=new Set(t.appearance.filter(t=>void 0!==t.visibility).map(t=>t.target));return t=>{const e=new Set;for(const r of t){if(!("pose"in r)||n(r))continue;const t=r.key?i.get(r.key):r.id;void 0!==t&&s.has(t)||e.add(r.id)}return e}}const eS=t=>`${ZM(t)}|${!1!==t.visible?"shown":"hidden"}`;function nS(t,e,n,i={}){const[s,r]=ew[e],o=i[s]??0,a=i[r]??0;let c;if("polygon"===t.kind)c=t.points.map(t=>[t[s],t[r]]);else if("ellipse"===t.kind){const e=t.radius[s],i=t.radius[r];c=Array.from({length:n},(t,s)=>{const r=2*Math.PI*s/n;return[e*Math.cos(r),i*Math.sin(r)]})}else{const e=t.size[s]/2,n=t.size[r]/2,i=t.corner?.[s]??0,o=t.corner?.[r]??0;if(i>0&&o>0){c=[];for(const[t,s,r]of[[1,-1,-Math.PI/2],[1,1,0],[-1,1,Math.PI/2],[-1,-1,Math.PI]])for(let a=0;a<=8;a++){const l=r+a/8*(Math.PI/2);c.push([t*(e-i)+i*Math.cos(l),s*(n-o)+o*Math.sin(l)])}}else c=[[-e,-n],[e,-n],[e,n],[-e,n]]}return c=c.map(([t,e])=>[t+o,e+a]),iS(c)<0?c.reverse():c}const iS=t=>t.reduce((e,n,i)=>e+n[0]*t[(i+1)%t.length][1]-t[(i+1)%t.length][0]*n[1],0)/2;function sS(t){const e=[...t].sort((t,e)=>t[0]-e[0]||t[1]-e[1]).map(([t,e])=>[t,e]);if(e.length<3)return e;const n=(t,e,n)=>(e[0]-t[0])*(n[1]-t[1])-(e[1]-t[1])*(n[0]-t[0]),i=[];for(const t of e){for(;i.length>=2&&n(i[i.length-2],i[i.length-1],t)<=1e-9;)i.pop();i.push(t)}const s=[];for(let t=e.length-1;t>=0;t--){const i=e[t];for(;s.length>=2&&n(s[s.length-2],s[s.length-1],i)<=1e-9;)s.pop();s.push(i)}return i.slice(0,-1).concat(s.slice(0,-1))}const rS=t=>"shape"in t&&"pose"in t&&!!t.shape;function oS(t,e){const n=[];for(const i of t){if(!1===i.visible||!rS(i))continue;let t;try{t=CM(EM(i.shape,i.segments),i.pose.r,i.pose.t)}catch{continue}if(t.length<3)continue;const s=t=>t.map(t=>[t[0],t[2]]),r=Math.abs(i.pose.r[1][1]-1)<1e-6,o=i.shape.extrusion;let a;const c=[];if(r&&"y"===o?.axis){const t=(t,e)=>s(CM(aS(t,o.end,i.segments??12,e),i.pose.r,i.pose.t));a=t(o.section);const e=i.shape.cavity;if(e&&"open"===e.end){const n=pw(o.section,"y",e.wall);"section"in n&&c.push(t(n.section,n.centre))}}else a=sS(s(t));const l=i.material,h=l.emissive?.on?l.emissive.token:l.token;n.push({id:i.id,color:e[h]??"#9a9a9a",outline:a,holes:c,top:Math.max(...t.map(t=>t[1])),transparent:!!l.transparent})}return n.sort((t,e)=>t.top-e.top)}function aS(t,e,n,i={}){const[s,r]=ew.y;return nS(t,"y",n,i).map(([t,n])=>{const i={x:0,y:e,z:0};return i[s]=t,i[r]=n,[i.x,i.y,i.z]})}let cS=null;function lS(t){cS=t}function hS(t,e=[],n){cS?.registerType?.(t,e,n)}function dS(t){if(Array.isArray(t))return`[${t.map(dS).join(",")}]`;if(t&&"object"==typeof t){const e=t;return`{${Object.keys(e).sort().map(t=>`${JSON.stringify(t)}:${dS(e[t])}`).join(",")}}`}return JSON.stringify(t)}const uS=new Map;function pS(t){const e=function(t){const e=dS(t),n=t=>{let n=t>>>0;for(let t=0;t<e.length;t++)n^=e.charCodeAt(t),n=Math.imul(n,16777619)>>>0;return n.toString(16).padStart(8,"0")};return n(2166136261)+n(2538058380)}(t),n=`${e}|${QM}`,i=uS.get(n);if(i)return uS.delete(n),uS.set(n,i),i;const s=KM(structuredClone(t)),r=new Map;for(const t of s.document.model.nodes)for(const e of Object.values(t.outputs))r.set(e,t.id);const o={key:n,fingerprint:e,kernel:QM,compiled:XM(s),document:YM(s.document),looks:new Map(s.appearance.map(t=>[t.target,t])),writers:r,asset:s};return uS.set(n,o),uS.size>256&&uS.delete(uS.keys().next().value),o}const fS=new Map;function mS(t,e){XM(e);const n={type:t,compiled:pS(e)};return fS.set(t,n),hS(t,e.document.capabilities.names??[],KM(e).placement),n}function gS(t){return fS.get(t)??null}function yS(t){return fS.has(t)}function bS(t){return fS.delete(t)}function _S(){fS.clear()}const vS=Math.cos(40*Math.PI/180);function xS(e){const[n,i]=ew[e];return([s,r],o)=>{const a={x:0,y:0,z:0};return a[n]=s,a[i]=r,a[e]=o,new t.Vector3(a.x,a.y,a.z)}}class wS{constructor(){this.positions=[],this.normals=[]}tri(t,e,n,i,s,r){for(const[o,a]of[[t,i],[e,s],[n,r]])this.positions.push(o.x,o.y,o.z),this.normals.push(a.x,a.y,a.z)}facing(e,n,i,s){(new t.Vector3).subVectors(n,e).cross((new t.Vector3).subVectors(i,e)).dot(s)<0?this.tri(e,i,n,s,s,s):this.tri(e,n,i,s,s,s)}geometry(){const e=new t.BufferGeometry;return e.setAttribute("position",new t.Float32BufferAttribute(this.positions,3)),e.setAttribute("normal",new t.Float32BufferAttribute(this.normals,3)),e}}function MS(e,n,i,s,r,o){const a=xS(i),c=n.length,l=n.map((t,e)=>{const i=n[(e+1)%c],s=i[0]-t[0],r=i[1]-t[1],a=Math.hypot(s,r)||1;return[o*r/a,-o*s/a]}),h=t=>a(t,0),d=(t,e)=>{const n=l[t],i=l[e];return n[0]*i[0]+n[1]*i[1]<vS?h(n):h([n[0]+i[0],n[1]+i[1]]).normalize()};for(let i=0;i<c;i++){const o=n[i],u=n[(i+1)%c],p=d(i,(i-1+c)%c),f=d(i,(i+1)%c),m=a(o,s),g=a(u,s),y=a(u,r),b=a(o,r),_=h(l[i]);(new t.Vector3).subVectors(g,m).cross((new t.Vector3).subVectors(y,m)).dot(_)>=0?(e.tri(m,g,y,p,f,f),e.tri(m,y,b,p,f,p)):(e.tri(m,y,g,p,f,f),e.tri(m,b,y,p,p,f))}}function SS(e,n,i,s,r,o){const a=xS(i),c=a([0,0],r),l=n.map(([e,n])=>new t.Vector2(e,n)),h=o?[o.map(([e,n])=>new t.Vector2(e,n))]:[],d=t.ShapeUtils.triangulateShape(l,h),u=[...n,...o??[]];for(const[t,n,i]of d)e.facing(a(u[t],s),a(u[n],s),a(u[i],s),c)}const kS=new Map;function AS(t,e=12){const n=Object.keys(t.dimensions).sort().map(e=>`${e}=${Math.round(1e6*t.dimensions[e])/1e6}`).join(","),i=t.extrusion,s=t.cavity,r=t.revolution,o=t.loft,a=i?`${i.axis}:${i.section.kind}:${s?`${"open"===s.start?"o":"c"}${"open"===s.end?"o":"c"}`:"-"}`:r?`${r.axis}:${r.profile.kind}`:o?`${o.axis}:point`:"";return`${t.provider}|${a}|${n}|s${e}`}function ES(t,e=12){const n=AS(t,e),i=kS.get(n);if(i)return i.users++,i.geometry;const s=TS(t,e);return s.userData.figureKey=n,kS.set(n,{geometry:s,users:1}),s}function CS(t){const e=t.userData.figureKey;if(!e)return;const n=kS.get(e);n&&--n.users<=0&&(kS.delete(e),n.geometry.dispose())}function TS(e,n=12){if("extrude"===e.provider&&e.extrusion)return function(t,e){const n=t.extrusion,i=nS(n.section,n.axis,e),s=new wS;MS(s,i,n.axis,n.start,n.end,1);const r=t.cavity,o=r&&pw(n.section,n.axis,r.wall);if(!r||!o||!("section"in o))return SS(s,i,n.axis,n.start,-1),SS(s,i,n.axis,n.end,1),s.geometry();const a=nS(o.section,n.axis,e,o.centre),c=n.start+("open"===r.start?0:r.start.closed),l=n.end-("open"===r.end?0:r.end.closed);return MS(s,a,n.axis,c,l,-1),"open"===r.start?SS(s,i,n.axis,n.start,-1,a):(SS(s,i,n.axis,n.start,-1),SS(s,a,n.axis,c,1)),"open"===r.end?SS(s,i,n.axis,n.end,1,a):(SS(s,i,n.axis,n.end,1),SS(s,a,n.axis,l,-1)),s.geometry()}(e,n);if("revolve"===e.provider&&e.revolution)return function(e,n){const i=e.profile;let s;return"half-ellipse"===i.kind?s=new t.SphereGeometry(1,n,Math.max(2,Math.round(n/2))).scale(i.radial,i.axial,i.radial):(s=new t.CylinderGeometry(i.endRadius,i.startRadius,i.end-i.start,n),s.translate(0,(i.start+i.end)/2,0)),"x"===e.axis&&s.rotateZ(-Math.PI/2),"z"===e.axis&&s.rotateX(Math.PI/2),s}(e.revolution,n);const i=e.loft;return"loft"===e.provider&&i?function(e){const[n,i]=ew[e.axis],s=xS(e.axis),r=nS(e.section,e.axis,0),o=s([e.apex[n],e.apex[i]],e.end),a=new wS;SS(a,r,e.axis,e.start,e.end>e.start?-1:1);const c=r.length;for(let n=0;n<c;n++){const i=s(r[n],e.start),l=s(r[(n+1)%c],e.start),h=(new t.Vector3).subVectors(l,i).cross((new t.Vector3).subVectors(o,i)).normalize();a.tri(i,l,o,h,h,h)}return a.geometry()}(i):new t.BufferGeometry}const PS=new Map;let OS=0;function DS(e){const n=(t=>t.map(t=>AS(t.shape,t.segments)).join(";"))(e),i=function(t){const e=new Float64Array(12*t.length);return t.forEach((t,n)=>{const i=t.pose.r,s=t.pose.t;e.set([i[0][0],i[0][1],i[0][2],i[1][0],i[1][1],i[1][2],i[2][0],i[2][1],i[2][2],s[0],s[1],s[2]],12*n)}),e}(e),s=PS.get(n),r=s?.find(t=>function(t,e){if(t.length!==e.length)return!1;for(let n=0;n<t.length;n++)if(t[n]!==e[n])return!1;return!0}(t.poses,i));if(r)return r.users++,r;const o=e.map(t=>ES(t.shape,t.segments));try{const r=o.map(t=>t.getAttribute("position")?.count??0),a=r.reduce((t,e)=>t+e,0),c=6*a*4;if(OS+c>67108864)return null;const l=new Float32Array(3*a),h=new Float32Array(3*a),d=new Int32Array(e.length+1),u=new t.Matrix4,p=new t.Matrix3;let f=0;e.forEach((t,e)=>{d[e]=f/3;const{r:n,t:i}=t.pose;u.set(n[0][0],n[0][1],n[0][2],i[0],n[1][0],n[1][1],n[1][2],i[1],n[2][0],n[2][1],n[2][2],i[2],0,0,0,1),p.getNormalMatrix(u);const s=u.elements,a=p.elements,c=o[e].getAttribute("position"),m=o[e].getAttribute("normal");for(let t=0;t<r[e];t++,f++){const e=c.getX(t),n=c.getY(t),i=c.getZ(t);if(l[3*f]=s[0]*e+s[4]*n+s[8]*i+s[12],l[3*f+1]=s[1]*e+s[5]*n+s[9]*i+s[13],l[3*f+2]=s[2]*e+s[6]*n+s[10]*i+s[14],!m)continue;const r=m.getX(t),o=m.getY(t),d=m.getZ(t),u=a[0]*r+a[3]*o+a[6]*d,p=a[1]*r+a[4]*o+a[7]*d,g=a[2]*r+a[5]*o+a[8]*d,y=Math.hypot(u,p,g)||1;h[3*f]=u/y,h[3*f+1]=p/y,h[3*f+2]=g/y}}),d[e.length]=f/3;const m=new t.BufferGeometry;m.setAttribute("position",new t.BufferAttribute(l,3)),m.setAttribute("normal",new t.BufferAttribute(h,3)),m.computeBoundingSphere(),m.computeBoundingBox();const g={geometry:m,starts:d,users:1,bytes:c,poses:i};return m.userData.figureMergedKey=n,m.userData.figureMergedEntry=g,s?s.push(g):PS.set(n,[g]),OS+=c,g}finally{for(const t of o)CS(t)}}function IS(t){const e=t.userData.figureMergedKey,n=t.userData.figureMergedEntry,i=void 0===e?void 0:PS.get(e);!n||!i?.includes(n)||--n.users>0||(i.splice(i.indexOf(n),1),i.length||PS.delete(e),OS-=n.bytes,n.geometry.dispose())}class zS{static stillJudgeOf(t){let e=zS.stillJudges.get(t);return e||zS.stillJudges.set(t,e=tS(t.asset,t.document.dependence)),e}constructor(e,n={}){this.group=new t.Group,this.meshes=new Map,this.batches=new Map,this.merged=new Map,this.places=new Map,this.size=null,this.design={},this.designRefused=[],this.external={},this.clipTimes=new Map,this.materials=new Map,this.dressed=new Map,this.drawnWith=new Map,this.lastEvaluation=null,this.slots=[],this.generation=-1,this.clamped=[],this.compiled=pS(e),this.theme=n.theme??{},this.merge=!1!==n.merge,this.group.name=`figure:${e.name}`}get asset(){return this.compiled.asset}get base(){const t=this.asset.designInputs,e=e=>"number"==typeof t[e];return e(Jx.x)&&e(Jx.y)&&e(Jx.z)?{x:t[Jx.x],y:t[Jx.y],z:t[Jx.z]}:null}setSize(t){if(this.clamped=[],!t)return void(this.size=null);const e=this.asset.document.model.inputs,n={...t};for(const i of["x","y","z"]){const s=e.find(t=>t.id===Jx[i]);if(!s)continue;const r=t[i],o=Math.min(Math.max(r,s.min??-1/0),s.max??1/0);o!==r&&this.clamped.push({axis:i,asked:r,used:o,bound:o>r?"min":"max"}),n[i]=o}this.size=n}get drawnSize(){return this.size?{...this.size}:null}setDesignInputs(t){const e=[],n=new Set((this.asset.publicInputs??[]).map(t=>t.input)),i=new Map(this.asset.document.model.inputs.map(t=>[t.id,t])),s={};for(const[r,o]of Object.entries(t??{})){const t=i.get(r);let a;n.has(r)&&t?"number"==typeof o&&Number.isFinite(o)?(o<t.min||o>t.max)&&(a=`outside ${t.min}…${t.max}`):a="not a number":a="not an input the figure lets a board set",a?(e.push({input:r,value:o,reason:a}),r in this.design&&(s[r]=this.design[r])):s[r]=o}try{this.compiled.document.evaluate({...this.evaluationInputs(),...s}),this.design=s}catch(t){for(const[n,i]of Object.entries(s))e.push({input:n,value:i,reason:t instanceof Error?t.message:String(t)})}this.designRefused=e}get designValues(){return{...this.design}}setState(t){this.external={...t}}static clipOf(t){return t.clip}get clips(){return[...new Set((this.asset.drivers??[]).map(t=>zS.clipOf(t)))]}setClipTime(t,e){this.clipTimes.set(t,e)}clipTime(t){return this.clipTimes.get(t)??0}setTime(t){for(const e of this.clips)this.clipTimes.set(e,t)}stateOverrides(){const{units:t,states:e}=this.inputsRead(),n={};for(const e of this.asset.drivers??[]){if(e.state in this.external)continue;const i=t.get(e.state);n[e.state]=UM(e,this.clipTime(zS.clipOf(e)),"deg"===i||"rad"===i?i:"other")}for(const[t,i]of Object.entries(this.external))e.has(t)&&(n[t]=i);return n}inputsRead(){const t=this.asset.document.model.inputs;return this.inputFacts??={units:new Map(t.map(t=>[t.id,t.unit])),states:new Set(t.filter(t=>"state"===t.role).map(t=>t.id))}}get externalState(){return{...this.external}}update(){const t=this.evaluationInputs();this.evaluator??=this.compiled.document.evaluator();const e=this.evaluator.advance(t);if("poses"===e.kind&&e.generation===this.generation&&!this.movesMerged(e.bodies))return this.movePoses(e);const n="evaluation"===e.kind?e.result:this.evaluator.evaluate(t);this.draw(this.dress(n,t),e.generation)}evaluation(){return this.evaluate()}movesMerged(t){if(!this.merged.size)return!1;for(let e=0;e<t.length;e++){const n=this.slots[t[e]];if(n&&"merged"in n)return!0}return!1}movePoses(t){const e=zS.matrix,n=new Set;for(let i=0;i<t.bodies.length;i++){const s=this.slots[t.bodies[i]];if(!s)continue;const r=t.poses,o=12*i;if(e.set(r[o],r[o+1],r[o+2],r[o+9],r[o+3],r[o+4],r[o+5],r[o+10],r[o+6],r[o+7],r[o+8],r[o+11],0,0,0,1),!("merged"in s))if("mesh"in s){s.mesh.matrix.copy(e),s.mesh.matrixWorldNeedsUpdate=!0;const t=this.drawnWith.get(s.id);t&&(t.pose=void 0)}else s.entry.set.setMatrix(s.index,e),n.add(s.entry)}for(const t of this.batches.values())n.has(t)?(t.settled=!1,t.set.commitMatrices(),t.set.mesh.boundingSphere=null,t.set.mesh.frustumCulled=!1):t.settled||(t.set.commit(),t.set.mesh.frustumCulled=!0,t.settled=!0);for(const e of t.places){const t=this.places.get(e.id);t&&zS.pose(t,e.pose)}}draw(e,n){this.lastEvaluation=e;const i=this.planOf(e.geometry),s=new Map(e.geometry.filter(t=>"pose"in t).map(t=>[t.id,t])),r=this.drawMerged(i,s),o=new Set;for(const e of r){const n=s.get(e);if(!("pose"in n))continue;o.add(e);let i=this.meshes.get(e);const r=!1!==n.visible,a=this.drawnWith.get(e);if(!i||!a||a.shape!==n.shape||a.segments!==n.segments){const s=ES(n.shape,n.segments);i?i.geometry!==s?(CS(i.geometry),i.geometry=s):CS(s):(i=new t.Mesh(s,this.materialFor(n)),i.name=e,i.matrixAutoUpdate=!1,this.meshes.set(e,i),r&&this.group.add(i))}a&&a.pose===n.pose||zS.pose(i,n.pose),this.drawnWith.set(e,{shape:n.shape,segments:n.segments,pose:n.pose}),i.castShadow=r,r&&i.parent!==this.group?this.group.add(i):r||i.parent!==this.group||this.group.remove(i)}for(const[t,e]of this.meshes)o.has(t)||(e.parent===this.group&&this.group.remove(e),CS(e.geometry),this.meshes.delete(t),this.drawnWith.delete(t));const a=new Set;for(const t of i.batches){a.add(t.key);const e=s.get(t.ids[0]);if(!("pose"in e))continue;let n=this.batches.get(t.key);if(!n){const i=ES(e.shape,e.segments);n={set:new Fx({geometry:i,material:this.materialFor(e),capacity:t.ids.length,name:`figure-batch:${t.member}`,castShadow:!0}),ids:[],geometry:i},this.batches.set(t.key,n)}const{set:i}=n,r=i.count!==t.ids.length;i.setCount(t.ids.length);const o=i.mesh.instanceMatrix.array;let c=!1;t.ids.forEach((t,e)=>{const n=s.get(t);if(!("pose"in n))return;zS.matrixOf(n.pose);const r=zS.matrix.elements;for(let t=0;t<16&&!c;t++)o[16*e+t]!==Math.fround(r[t])&&(c=!0);i.setMatrix(e,zS.matrix)}),n.ids=t.ids,r||!c&&!n.settled?(i.commit(),i.mesh.frustumCulled=!0,n.settled=!0):c&&(n.settled=!1,i.commitMatrices(),i.mesh.boundingSphere=null,i.mesh.frustumCulled=!1);const l=!1!==e.visible;l&&i.object3d.parent!==this.group?this.group.add(i.object3d):l||i.object3d.parent!==this.group||this.group.remove(i.object3d)}for(const[t,e]of this.batches)a.has(t)||(e.set.object3d.parent===this.group&&this.group.remove(e.set.object3d),e.set.dispose(),CS(e.geometry),this.batches.delete(t));for(const t of e.bindings){const e=this.places.get(t.id);e&&zS.pose(e,t.pose)}const c=new Map;for(const t of this.batches.values())t.ids.forEach((e,n)=>c.set(e,{entry:t,index:n}));for(const t of this.merged.values())for(const e of t.ids)c.set(e,{merged:t});this.slots=e.geometry.map(t=>{const e=this.meshes.get(t.id);return e?{mesh:e,id:t.id}:c.get(t.id)??null}),this.generation=n}drawMerged(e,n){const i=[...e.alone],s=new Set;for(const r of e.merged){const e=r.ids.map(t=>n.get(t));let o=this.merged.get(r.key);if(!(o&&o.ids.length===e.length&&e.every((t,e)=>t.id===o.ids[e]&&t.shape===o.made[e].shape&&t.segments===o.made[e].segments&&t.pose===o.made[e].pose))){const n=DS(e.map(t=>({shape:t.shape,segments:t.segments,pose:t.pose})));if(!n){i.push(...r.ids);continue}if(o)IS(o.mesh.geometry),o.mesh.geometry=n.geometry,o.ids=r.ids,o.starts=n.starts;else{const i=new t.Mesh(n.geometry,this.materialFor(e[0]));i.name=`figure-merged:${this.merged.size}`,i.matrixAutoUpdate=!1,i.castShadow=!0,o={mesh:i,ids:r.ids,starts:n.starts,made:[]},this.merged.set(r.key,o)}o.made=e.map(t=>({shape:t.shape,segments:t.segments,pose:t.pose}))}s.add(r.key);const a=!1!==e[0].visible;a&&o.mesh.parent!==this.group?this.group.add(o.mesh):a||o.mesh.parent!==this.group||this.group.remove(o.mesh)}for(const[t,e]of this.merged)s.has(t)||(e.mesh.parent===this.group&&this.group.remove(e.mesh),IS(e.mesh.geometry),this.merged.delete(t));return i}placeNode(e){let n=this.places.get(e);if(n)return n;if(!this.asset.document.capabilities.bindings.some(t=>t.id===e))return null;n=new t.Object3D,n.name=`place:${e}`,n.matrixAutoUpdate=!1,this.places.set(e,n),this.group.add(n);const i=this.evaluation().bindings.find(t=>t.id===e);return i&&zS.pose(n,i.pose),n}static pose(t,e){t.matrix.copy(zS.matrixOf(e)),t.matrixWorldNeedsUpdate=!0}planOf(t){const e=this.planned,n=t.filter(t=>"pose"in t);if(e&&e.ids.length===n.length&&n.every((t,n)=>t.id===e.ids[n]&&t.shape===e.shapes[n]&&!1!==t.visible===e.shown[n]))return e.plan;const i=n.map(t=>t.id);!this.merge||e?.still&&e.ids.length===i.length&&i.every((t,n)=>t===e.ids[n])||(this.stillOf=zS.stillJudgeOf(this.compiled)(t));const s=this.merge?this.stillOf:void 0,r=function(t,e={}){const n=[],i=new Map;for(const e of t){if(!("pose"in e))continue;const t="key"in e&&"string"==typeof e.key?e.key:void 0;if(!t){n.push(e.id);continue}const s=i.get(t)??[];s.push(e),i.set(t,s)}const s=[],r=[];for(const[t,e]of i){const i=new Map;for(const t of e){const e=JM(t),n=i.get(e);n?n.push(t.id):i.set(e,[t.id])}for(const[o,a]of i)a.length>1?s.push({key:`${t}|${o}`,member:t,ids:a}):(n.push(...a),r.push({member:t,ids:a,reason:1===e.length?"one-copy":"copies-differ"}))}const o=[];if(e.still?.size){const i=new Map(t.map(t=>[t.id,t])),s=new Map;for(const t of n){const n=i.get(t);if(!n||!e.still.has(t)||n.material.transparent)continue;const r=eS(n),o=s.get(r);o?o.push(t):s.set(r,[t])}const r=new Set;for(const[t,e]of s)e.length<2||(o.push({key:t,ids:e}),e.forEach(t=>r.add(t)));r.size&&n.splice(0,n.length,...n.filter(t=>!r.has(t)))}const a=[];if(e.carried?.size){const i=new Map(t.map(t=>[t.id,t])),s=new Map;for(const t of n){const n=i.get(t),r=e.carried.get(t);if(!n||void 0===r||e.still?.has(t)||n.material.transparent)continue;const o=`${r}|${eS(n)}`,a=s.get(o);a?a.ids.push(t):s.set(o,{carrier:r,ids:[t]})}const r=new Set;for(const[t,{carrier:e,ids:n}]of s)n.length<2||(a.push({key:t,carrier:e,ids:n}),n.forEach(t=>r.add(t)));r.size&&n.splice(0,n.length,...n.filter(t=>!r.has(t)))}return{batches:s,merged:o,carried:a,alone:n,unbatched:r}}(t,s?{still:s}:{});return this.planned={ids:i,shapes:n.map(t=>t.shape),shown:n.map(t=>!1!==t.visible),plan:r,still:s},r}static matrixOf(t){const e=t.r,n=t.t;return zS.matrix.set(e[0][0],e[0][1],e[0][2],n[0],e[1][0],e[1][1],e[1][2],n[1],e[2][0],e[2][1],e[2][2],n[2],0,0,0,1)}bodyAt(t,e,n){if(t.isMesh&&this.meshes.get(t.name)===t)return t.name;for(const n of this.batches.values())if(n.set.mesh===t&&void 0!==e){const t=n.set.indexOf(e);return t>=0?n.ids[t]:void 0}for(const e of this.merged.values()){if(e.mesh!==t||void 0===n)continue;const{starts:i}=e;if(n<0||n>=i[i.length-1])return;let s=0,r=e.ids.length-1;for(;s<r;){const t=s+r+1>>1;i[t]<=n?s=t:r=t-1}return e.ids[s]}}drawOf(t){const e=this.meshes.get(t);if(e)return e.parent===this.group?{kind:"alone",object:e}:void 0;for(const e of this.batches.values()){const n=e.ids.indexOf(t);if(n>=0)return e.set.object3d.parent===this.group?{kind:"copy",object:e.set.mesh,index:n}:void 0}for(const e of this.merged.values()){const n=e.ids.indexOf(t);if(n>=0)return e.mesh.parent===this.group?{kind:"merged",object:e.mesh,triangles:{start:e.starts[n],count:e.starts[n+1]-e.starts[n]}}:void 0}}get draws(){let t=0;for(const e of this.batches.values())e.set.object3d.parent===this.group&&(t+=e.set.count);return{batches:[...this.batches.values()].filter(t=>t.set.object3d.parent===this.group).length,merged:[...this.merged.values()].filter(t=>t.mesh.parent===this.group).length,alone:[...this.meshes.values()].filter(t=>t.parent===this.group).length,instances:t}}evaluationInputs(){const t={...this.asset.designInputs,...this.design,...this.asset.stateDefaults,...this.stateOverrides()};return this.size&&(t[Jx.x]=this.size.x,t[Jx.y]=this.size.y,t[Jx.z]=this.size.z),t}evaluate(){const t=this.evaluationInputs();return this.evaluator??=this.compiled.document.evaluator(),this.dress(this.evaluator.evaluate(t),t)}dress(t,e){const n=this.dressed,i=new Map,s=t.geometry.map(e=>{const s="key"in e&&e.key?this.compiled.writers.get(e.key):e.id,r=this.compiled.looks.get(s);if(!r)throw new Error(`figure: no appearance for ${s}`);const o=void 0===r.visibility||!0===t.values[r.visibility],a=n.get(e.id);if(a&&a.body===e&&a.visible===o)return i.set(e.id,a),a.dressed;let c=this.materials.get(s);c||this.materials.set(s,c=structuredClone(r.material));const l={...e,material:c,visible:o};return void 0!==r.segments&&(l.segments=r.segments),i.set(e.id,{body:e,visible:o,dressed:l}),l});return this.dressed=i,{geometry:s,bindings:t.bindings,inputs:e,palette:{...this.asset.palette}}}colourOf(t){return this.theme[t]??this.asset.palette[t]??"#9a9a9a"}materialFor(t){const e=t.material,n=Td[e.preset??"default"]??Td.default,i=!!e.emissive?.on,s=i&&e.emissive?this.colourOf(e.emissive.token):this.colourOf(e.token),r=i&&e.emissive?e.emissive.intensity:0,o=`figure|${this.compiled.fingerprint}|${e.token}|${e.preset??"default"}|${e.transparent?"t":"o"}|${i?"on":"off"}|${s}|${r}`;return av.material(o,{color:s,metalness:n.metalness,roughness:n.roughness,envMapIntensity:n.envMapIntensity,flatShading:!0,transparent:e.transparent??!1,opacity:e.transparent?n.opacity??.3:1,emissive:s,emissiveIntensity:r})}meshOf(t){return this.meshes.get(t)}drawnIds(){return[...[...this.meshes.values()].filter(t=>t.parent===this.group).map(t=>t.name),...[...this.batches.values()].filter(t=>t.set.object3d.parent===this.group).flatMap(t=>t.ids),...[...this.merged.values()].filter(t=>t.mesh.parent===this.group).flatMap(t=>t.ids)]}dispose(){for(const t of this.meshes.values())t.parent===this.group&&this.group.remove(t),CS(t.geometry);this.meshes.clear(),this.drawnWith.clear(),this.dressed.clear();for(const t of this.batches.values())t.set.object3d.parent===this.group&&this.group.remove(t.set.object3d),t.set.dispose(),CS(t.geometry);this.batches.clear();for(const t of this.merged.values())t.mesh.parent===this.group&&this.group.remove(t.mesh),IS(t.mesh.geometry);this.merged.clear();for(const t of this.places.values())this.group.remove(t);this.places.clear()}}zS.matrix=new t.Matrix4,zS.stillJudges=new WeakMap;class RS extends xu{constructor(){super(...arguments),this.rig=null}get figure(){return gS(this.component.state.type)}getObject3dInstance(){return new t.Group}build(){super.build();const t=this.figure;t&&(this.rig=new zS(t.compiled.asset),this.object3d.add(this.rig.group),this.rig.setSize(this.instanceSize()),this.seat(),this.rig.setDesignInputs(this.designInputs),this.rig.setState(this.parameters),this.rig.update(),this.startTicking())}get designInputs(){const t=this.component.state.designInputs;return t&&"object"==typeof t?t:{}}get parameters(){const t=this.component.state.parameters;return t&&"object"==typeof t?t:{}}get clipSpeeds(){const t=this.component.state.clips;return t&&"object"==typeof t?t:{}}clipTime(t){return this.rig?.clipTime(t)??0}onchange(t,e){super.onchange(t,e),"designInputs"in t&&this.updateDesignInputs(),"parameters"in t&&this.updateParameters(),"clips"in t&&this.updateClips()}instanceSize(){const t=this.rig?.base;if(!t)return null;const{width:e,height:n}=this.component.bounds;return{x:e,y:this.effectiveDepth,z:n}}get effectiveDepth(){const t=this.component.state.depth;if("number"==typeof t&&Number.isFinite(t)&&t>0)return t;const e=this.rig?.base;if(!e)return super.effectiveDepth;const{width:n,height:i}=this.component.bounds,s=e.x>0?n/e.x:1,r=e.z>0?i/e.z:1;return e.y*Math.sqrt(Math.max(s,0)*Math.max(r,0))}get effectiveZPos(){const t=this.component.state.zPos;return"number"==typeof t&&Number.isFinite(t)?t:"ceiling"!==this.figure?.compiled.asset.placement?super.effectiveZPos:function(t,e,n){switch(t){case"inverted":return e;case"space":return e-n/2;default:return e-n}}(this.placementMode,this.sceneHeights.ceiling,this.effectiveDepth)}updateDimension(){this.rig&&(this.rig.setSize(this.instanceSize()),this.seat(),this.refresh())}seat(){if(!this.rig)return;const t=this.figure?.compiled.asset.placement;if("wall"===t)return this.rig.group.position.y=0,void(this.rig.group.position.z=-this.component.bounds.height/2);this.rig.group.position.z=0;const e=this.rig.drawnSize?.y??this.effectiveDepth,n=this.effectiveDepth-e,i="ceiling"===t?n:"center"===t?n/2:0;this.rig.group.position.y=-this.effectiveDepth/2+i}get sizeClamps(){return this.rig?.clamped??[]}updateDesignInputs(){this.rig&&(this.rig.setDesignInputs(this.designInputs),this.refresh())}updateParameters(){this.rig&&(this.rig.setState(this.parameters),this.refresh())}updateClips(){this.rig&&(this.startTicking(),this.refresh())}refresh(){this.rig&&(this.rig.update(),this.component.invalidate?.())}startTicking(){const t=this.rig?.asset.drivers??[];this.unsubscribe||0===t.length||(this.unsubscribe=Rr.subscribe(t=>this.advance(t),{description:`Figure[${this.component.state.type}].drivers`,component:this.component,getTargets:()=>this.rig?[this.rig.group]:[]}))}tick(t){const e=this.rig;if(!e)return;const n=this.clipSpeeds;let i=!1;for(const s of e.clips){const r=n[s]??0;Number.isFinite(r)&&0!==r&&(e.setClipTime(s,e.clipTime(s)+t/1e3*r),i=!0)}i&&(e.update(),this.component.invalidate?.())}advance(t){this.tick(t)}placeAttachment(t,e){const n=this.rig,i=n?.placeNode(t);if(!n||!i)return;const s=IM(n.asset).find(e=>e.id===t)?.face,r=s&&SM[s]||[0,0,0],o=t=>{const n=Number(e?.state?.[t]);return Number.isFinite(n)&&n>0?n/2:0};return{attach:i,localPosition:{x:r[0]*o("width"),y:r[1]*o("depth"),z:r[2]*o("height")}}}clear(){return this.unsubscribe?.(),this.unsubscribe=void 0,this.rig?.dispose(),this.rig=null,super.clear()}}function jS(t,e){const n=new zS(t.compiled.asset);n.setSize(e);const i=n.evaluate();return{shapes:oS(i.geometry,i.palette),size:n.drawnSize}}const LS=Kx,FS=Object.freeze({Capacity:t=>Jy(t),Holdable:t=>c_(t),Transferable:t=>l_(t),FlowNode:t=>h_(t)}),NS=Object.freeze({Capacity:"자리를 갖는다 — 물건이 앉을 곳과 몇 개까지인지를 정한다",Holdable:"물건을 보유한다 — 담긴 것을 함께 들고 그린다",Transferable:"주고받는다 — 자리를 잡아 두고 넘겨받는다. Capacity 가 있어야 자리를 찾는다",FlowNode:"흐름의 마디다 — 담는 것에 더해 문(port)으로 받고 보낸다. 위의 셋을 스스로 포함한다"});function HS(t){return t.map(t=>({id:t.id,maxCount:t.capacity,allowedTypes:[...t.accepts]}))}const BS=new Map;function YS(t,e=[],n){const i=new Set(e),s=[...i].filter(t=>!LS.includes(t));if(s.length>0)throw new Error(`모르는 능력이다: ${s.join(" · ")} — 쓸 수 있는 것은 ${LS.join(" · ")}`);for(const[t,e]of Object.entries(Qx))if(i.has(t)&&!e.some(t=>i.has(t)))throw new Error(`${t} 은 혼자 설 수 없다 — ${e.join(" 이나 ")} 가 함께 있어야 한다`);const r=`${[...i].sort().join("+")}|${n??""}`,o=BS.get(r);if(o)return o;const a=0===i.size?t:(c=function(t,e){const n=t.capabilities??[],i=[...new Set([...n,...e])];return Object.defineProperty(t,"capabilities",{value:Object.freeze(i),configurable:!0}),t}(function(t,e){if(e.has("FlowNode"))return FS.FlowNode(t);let n=t;for(const t of["Capacity","Transferable","Holdable"])e.has(t)&&(n=FS[t](n));return n}(t,i),i),class extends c{get _places(){return gS(this.state?.type)?.compiled.asset.document.capabilities.bindings??null}get slots(){const t=this._places;return t?.length?HS(t):super.slots??[]}attachPointFor(t,e){const n=()=>super.attachPointFor?super.attachPointFor(t,e):null,i=e?.slotId??t?.[Wy],s=this._places;return s&&i&&s.some(t=>t.id===i)?this._realObject?.placeAttachment?.(i,t)??n():n()}});var c;const l=void 0===n?a:function(t,e){const n=class extends t{};return Object.defineProperty(n,"placement",{value:e,enumerable:!0}),Object.defineProperty(n,"name",{value:`${t.name??"Figure"}·${e}`}),n}(a,n);return BS.set(r,l),l}function VS(){BS.clear()}const GS={mutable:!1,resizable:!0,rotatable:!0,properties:[],help:"scene/component/figure"};class $S extends(Oc(Tc)){static registerType(t,e=[],n){const i=Cc.register(t);if(i&&!(i===$S||i.prototype instanceof $S))throw new Error(`figure type '${t}' is already registered by a non-figure component — refusing to replace it`);const s=YS($S,e,n);Cc.register(t,s)}get hasTextProperty(){return!1}is3dish(){return!0}get nature(){const t=gS(this.state.type),e=t?.compiled.asset.publicInputs??[];if(!e.length)return GS;const n=t.compiled.asset,i=e.flatMap(t=>{const e=n.document.model.inputs.find(e=>e.id===t.input);return e?[{key:t.input,label:t.label,unit:e.unit,min:e.min,max:e.max,default:n.designInputs[t.input]}]:[]});return{...GS,properties:[{type:"number-map",label:"design-inputs",name:"designInputs",property:{entries:i}}]}}buildRealObject(){return yS(this.state.type)?new RS(this):void 0}render(t){const{left:e=0,top:n=0,width:i=0,height:s=0}=this.state,r=gS(this.state.type);if(!r)return void this.renderPlace(t,e,n,i,s);const o=this.topView(r,i,s),a=e+i/2,c="wall"===r.compiled.asset.placement?n:n+s/2;for(const e of o.shapes)if(!(e.outline.length<3)){t.save(),t.fillStyle=e.color,e.transparent&&(t.globalAlpha=.35),t.beginPath();for(const n of[e.outline,...e.holes])if(!(n.length<3)){t.moveTo(a+n[0][0],c+n[0][1]);for(let e=1;e<n.length;e++)t.lineTo(a+n[e][0],c+n[e][1]);t.closePath()}t.fill("evenodd"),t.restore()}}topView(t,e,n){const i=t.compiled.asset.designInputs,s=["x","y","z"].every(t=>"number"==typeof i[`size.${t}`])?{x:i["size.x"],y:i["size.y"],z:i["size.z"]}:null,r=this.state.depth,o="number"==typeof r&&Number.isFinite(r)&&r>0?r:s?s.y*Math.sqrt(Math.max(s.x>0?e/s.x:1,0)*Math.max(s.z>0?n/s.z:1,0)):0,a=s?{x:e,y:o,z:n}:null,c=`${t.compiled.fingerprint}|${a?`${a.x}|${a.y}|${a.z}`:"authored"}`;return this._top?.key!==c&&(this._top={key:c,view:jS(t,a)}),this._top.view}renderPlace(t,e,n,i,s){t.save(),t.strokeStyle="#e53935",t.lineWidth=1,t.setLineDash([4,4]),t.beginPath(),t.rect(e,n,i,s),t.stroke(),t.restore()}postrender(t){Cc.prototype.postrender.call(this,t)}}lS($S);const US={"palette.primary":"#154473","palette.accent":"#f79c40","palette.neutral":"#96989b","palette.dark":"#27292c","palette.light":"#d6d7d9","palette.surface":"#56585b","palette.status-danger":"#f61b30","palette.status-warning":"#e68d1a","palette.status-info":"#158bde","palette.status-success":"#1cb648"},WS=new Map([["default",US]]);let qS="default",XS=0;function KS(){return XS}function QS(t,e){WS.set(t,e),t===qS&&XS++}function ZS(t){if(!WS.has(t))throw new Error(`등록되지 않은 팔레트다: '${t}'. 등록된 것 — ${[...WS.keys()].join(", ")}`);t!==qS&&(qS=t,XS++)}function JS(){return qS}function tk(){return WS.get(qS)}function ek(t){const e=tk()[t];if(void 0===e)throw new Error(`팔레트에 없는 토큰이다: '${t}' (팔레트 '${qS}'). 쓸 수 있는 것 — ${Object.keys(tk()).join(", ")}`);return e}const nk=US["palette.neutral"];function ik(){WS.clear(),WS.set("default",US),qS="default",XS++}const sk={mutable:!1,resizable:!0,rotatable:!0,properties:[],help:"scene/component/figure-part"},rk=["shape","segments"],ok=["color","preset","transparent","glow"];function ak(e,n){let i;try{i=TS(e,n)}catch{return null}if(!i?.getAttribute("position"))return null;const s=i.clone();i.dispose(),s.computeBoundingBox();const r=s.boundingBox,o=r.getCenter(new t.Vector3),a=r.getSize(new t.Vector3);return s.translate(-o.x,-o.y,-o.z),s.scale(1/(a.x||1),1/(a.y||1),1/(a.z||1)),s.computeBoundingBox(),s.getAttribute("normal")||s.computeVertexNormals(),{geometry:s,extent:a,centre:o}}class ck extends xu{build(){super.build();const e=this.component.state,n=e.shape?ak(e.shape,e.segments):null;if(!n)return;const i=new t.Mesh(n.geometry,this.material());i.castShadow=!0,i.receiveShadow=!0,this.object3d.add(i),this.mesh=i,this.updateDimension()}clear(){return this.mesh?.geometry.dispose(),this.mesh=void 0,super.clear()}onchange(t,e){const n=e=>e.some(e=>e in t);n(rk)?this.update():(super.onchange(t,e),n(ok)&&this.mesh&&(this.mesh.material=this.material()))}updateDimension(){const{width:t=1,height:e=1}=this.component.bounds;this.setDimensionScale(t||1,this.effectiveDepth||1,e||1)}material(){const t=this.component.state,e=Td[t.preset??"default"]??Td.default,n=t.color??"#9a9a9a",i=t.transparent??!1,s=t.glow,r=s?s.color:n,o=s?s.intensity:0;return av.material(`figure-part|${n}|${t.preset??"default"}|${i}|${s?`${s.color}:${o}`:"-"}`,{color:r,metalness:e.metalness,roughness:e.roughness,envMapIntensity:e.envMapIntensity,flatShading:!0,transparent:i,opacity:i?e.opacity??.3:1,emissive:r,emissiveIntensity:o})}}class lk extends(Oc(Tc)){static registerType(){Cc.register("figure-part",lk)}get hasTextProperty(){return!1}is3dish(){return!0}get nature(){return sk}buildRealObject(){return new ck(this)}render(t){const{left:e=0,top:n=0,width:i=0,height:s=0}=this.state;t.beginPath(),t.rect(e,n,i,s),t.fillStyle=this.state.color??"#9a9a9a",t.fill()}}var hk;lk.registerType(),function(t){t.compile=jl,t.duplicate=Ll,t.select=ec,t.match=Za}(hk||(hk={})),ji.registerResidents(()=>({componentResidentsCount:Cc.residentsCount,sceneResidentsCount:Ku.residentsCount,referenceMapResidentsCount:V_.residentsCount,sceneResidents:Cc.residents}));var dk=Object.freeze({__proto__:null,AbsoluteLayout:Nc,Animation:ka,AudioPlayer:Zg,BULGE_EPSILON:qr,get Banner(){return ex},Banner3D:tx,BoxSelectionManager:Rf,CAPABILITY_MIXINS:FS,COMMON_PLACEHOLDER_PROPERTIES:vg,CORE_PLACEHOLDER_TYPES:Sg,get Camera(){return ox},Camera3D:rx,CameraBookmarkManager:zf,CameraManager:_f,Capacity:Jy,CapacityEventTracker:Ry,CardLayout:Bc,CenteringQueueStrategy:Ly,CenteringSlotStrategy:v_,Component:Cc,Connectable:nm,Container:ng,ContainerAbstract:Jl,ControlsManager:Mf,get Cube(){return Xv},Cube3D:qv,get Cylinder(){return Zv},Cylinder3D:Qv,DEFAULT:Ks,DEFAULT_CEILING:bu,DEFAULT_PALETTE:US,DEFAULT_PLACEMENT:uu,DPPX:Ws,DataLagTracker:sh,DataSource:Ey,DefaultLoadingOverlayRenderer:Vd,Donut:yy,DonutExtrude:Ev,Ellipse:bg,EllipseExtrude:Mv,EventManager3D:Sf,EventMap:fl,FIGURE_CAPABILITIES:LS,FIGURE_CAPABILITY_NOTES:NS,FPS:Fp,FigureInstance:$S,FigurePart:lk,FigurePartRealObject:ck,FixedSlotStrategy:Ky,get FloorPlate(){return yx},FlowEngine:a_,FlowNode:h_,GESTURES:qs,get GLTFObject(){return cx},GLTF_BASE_URL_ALIAS:Ty,GenericObject:Mg,GeometryBank:Dv,GifView:Kg,GizmoManager:Af,GizmoOperationManager:Tf,GlobalRef:oy,GltfComponent:Oy,GridStacking:Hy,Group:ey,HTMLAbsoluteLayout:Fc,HTMLOverlayContainer:sy,HTMLOverlayElement:Fg,Holdable:c_,ImageView:Lg,InfoWindow:Rc,InstancedSet:Fx,InteractionManager:Pf,ItemsDataBinding:Xy,KEYEVENTS:Xs,Layer:gp,Layout:Lc,LightManager:xf,LightObject:hx,Line:gg,Line3D:zx,LinearHorizontalLayout:Vc,LinearVerticalLayout:$c,LoadTracker:ah,LoadingOverlay:Rd,LocalRef:iy,MATERIAL_PRESETS:Td,MAX_SEGMENTS:jv,MAX_UNDO_SIZE:30,MIN_SEGMENTS:3,MODE_ADD:3,MODE_EDIT:1,MODE_PASTE_DATABIND:5,MODE_PASTE_STYLE:4,MODE_SHIFT:2,MODE_VIEW:0,MaterialBank:av,get Model(){return hk},MoveHandle:Ql,NOTHING:Fs,NavGraph:A_,Node:wy,OrthoLine:Rg,OrthoLine3D:jx,PIXEL_RATIO:Np,PLACEHOLDER_THEMES:_g,Path:uy,PatternStacking:Ny,PlacementManager:Of,get PointLight(){return dx},Polygon:Cg,PolygonContainer:Pg,PolygonExtrude:Av,PolygonPathPolyline:I_,Polyline:Ig,Polyline3D:Rx,Popup:ly,PopupContainer:dy,Pose6DOF:vl,RealObject:xu,RealObjectCamera:Yx,RealObjectDomElement:Wp,RealObjectDomTexture:iv,RealObjectDummy:Hx,RealObjectExternalModel:Su,RealObjectExtrude:wv,RealObjectGLTF:Cu,RealObjectGroup:wx,RealObjectLine:Ix,RealObjectMesh:cv,RealObjectPlane:Vx,RealObjectPlane2D:Ux,RealObjectScene:Gx,RealObjectService:My,RealObjectSprite:Vv,RealObjectSprite2D:Gv,RealObjectText:mv,Rect:rm,RectExtrude:Sv,RectPath:Oc,ReferenceMap:V_,RendererManager:vf,ReservationTable:S_,RootContainer:ih,Ruler:am,SCALE_MIN:Zd,SCENE_MODE:$s,SEGMENT_DEFAULTS:zv,SEGMENT_PRESETS:Iv,SHORTCUT_SECTIONS:qf,Scene:Ku,SceneManager:bf,ScenePopup:mp,SceneSearchEngine:Iu,ScriptLoader:K_,SearchOverlay:Ru,ServiceComponent:ky,Shape:Tc,get Sphere(){return Yv},Sphere3D:Bv,get Sprite(){return Uv},Star:vy,StarExtrude:Tv,TRANSFER_SLOT_KEY:Wy,TableLayout:Uc,Text:Jg,ThreeCapability:Bf,get ThreeContainer(){return qx},ThreeDOnly:Cy,Tracker:Lu,Transfer:Uu,TransitionEffect:Kl,Triangle:fy,TriangleExtrude:Cv,UNIT_DIMENSION:nu,UNIT_ROTATE:ru,UNIT_SCALE:iu,UNIT_TRANSLATE:su,UNTOKENED_COLOR:nk,ValueHolder:Ay,VertexGizmoManager:Hf,VolumeStacking:By,get Wall(){return fx},Wall3D:px,Z_PRIORITY:fu,acquireFigureGeometry:ES,activePalette:tk,activePaletteName:JS,allDestinations:qb,anchorsConnect:rb,animate:Sa,applyAlpha:tu,applyMaterial3dProps:Id,applyPolicy:Qb,applySeatingRotation:Uy,applyStackLayout:Yy,applyZPriorityToMaterials:gu,arcSegmentTopology:ib,autoWireBackPressure:jy,buildArrow3D:$p,buildContractInspector:N_,buildCoordinateGround:sf,buildFigureGeometry:TS,buildFlowGraph:hb,buildNavGraph:T_,buildShapeFromPolygonPath:kv,buildTether:op,bulgeFromDrag:Zr,bulgeHandlePosition:Qr,canReach:mb,capability:Bm,centerOnBBox:xv,chooseNearestPickupFrame:__,clearTether:cp,collectAdjacentSegments:vb,compile:Ea,componentForNode:Wb,computeArcParams:Kr,computeFlowMap:Rb,computeStackPositions:Fy,cornerHandlePosition:to,cornerRadiusFromDrag:eo,create:Zu,createCanvas:Hp,createCanvasTexture:J_,createFloor:mf,createRealObjectFor:Zp,createSelectionHandle3D:bx,dataLagTracker:rh,debug:Ji,deliversInto:cb,delta:wa,disposeCoordinateGround:cf,disposeObject3D:cu,disposeTether:lp,downstream:t_,drawTextTexture:dv,effectiveCornerRadius:Jr,ellipseOutline:vv,enumerateDataScenarios:Sb,error:Qi,figureClassFor:YS,figureSectionOutline:nS,fillStyleOpacity:Jd,filterByToolType:b_,filterShortcuts:Xf,findNearestWithCapability:Fb,flattenPolygonPath:z_,flowGraphFor:$b,flowGraphIssues:Gb,flowReverseFor:jb,fontStyle:lv,footprint2D:Vy,frameClock:Rr,ftId:Ob,ftrace:Pb,getAllCapabilityMeta:$m,getCapabilityMeta:Gm,getFigure:gS,getPose:kl,getWorldPose:Al,globalSimClock:Ir,gltfNatureProperties:Py,graphFor:s_,gridPlacements:Nx,hasArc:Xr,hasCapability:Hm,hasCapacity:Iy,hasFigure:yS,inferCapacity:zy,inferDownstreamId:xb,inferFlowDirections:Tb,initFontFamilyWatcher:Zs,inspector:zd,installContractInspector:H_,isFlowNode:d_,isGenericPlaceholder:kg,isGeometricHost:Lb,isParted:wu,isRoutingTarget:Nb,isSegmentPreset:Nv,isStateDriven:pu,isThreedEnabled:Pu,matchOutbounds:lb,metrics:ji,next:Jb,nextHop:fb,nextHops:pb,nextHopsToAny:yb,nextHopsToAnyDetailed:bb,niceGridStep:ef,nodeIdOf:Xb,opaqueColor:eu,paletteVersion:KS,partAtByIndex:Mu,pickWeightedDestination:o_,planPathAStar:P_,planToReservations:O_,pointInRotatedRect:ob,polygonOffsetForPriority:mu,polygonPathLength:R_,projectToScreen:np,quatFromYaw:p_,rayAbsDistanceToRect:ab,reachableByOutbound:db,reachableDestinations:e_,reachableDestinationsFrom:n_,reachableDestinationsWeightedFrom:i_,reachableSinks:gb,receiptToJSON:Gu,recommendsLogarithmicDepthForSky:yf,rectFaceAnchors:tb,rectOutline:_v,rectangularFootprintFrames:g_,registerCapabilityMeta:Vm,registerDefaultRealObjectFactory:Qp,registerFigure:mS,registerFigureType:hS,registerPalette:QS,registerRealObjectFactory:Kp,registerTypeResolver:Rh,releaseFigureGeometry:CS,renderCanvasTexture:tv,renderPlaceholder:xg,reservationTable:k_,resetFigureClasses:VS,resetFigures:_S,resetPalettes:ik,resolveAnchorWorldPosition:rp,resolveHeightSegments:Fv,resolveMaterial3d:Pd,resolveNextHop:Zb,resolveSegments:Lv,resolveToken:ek,resolveUnknownTypes:Lh,resolveVariant:Xd,sceneComponent:Dy,setActivePalette:ZS,setPose:El,setThreedEnabled:Ou,setWorldPose:Cl,sinksForDestination:Ub,slotsFromBindings:HS,standardYieldPolicy:M_,stopFPSMeasure:Lp,straightSegmentEndpoints:nb,straightSegmentMultiInbound:sb,straightSegmentTopology:eb,textBounds:fv,textTexture:uv,toThreeSide:Dd,topApproachFrame:y_,transferLog:Wu,transferTracer:Yu,uniformZ:no,unitFigurePartGeometry:ak,unknownTypesOf:jh,unregisterFigure:bS,updateDefaultFontFamily:Qs,updateTether:ap,useFigureComponent:lS,validate:r_,validateFlowGraph:_b,version:Q_,warn:Zi});const uk=globalThis;"undefined"==typeof globalThis||uk.scene||(uk.scene=dk);export{Nc as AbsoluteLayout,ka as Animation,Zg as AudioPlayer,qr as BULGE_EPSILON,ex as Banner,tx as Banner3D,Rf as BoxSelectionManager,FS as CAPABILITY_MIXINS,vg as COMMON_PLACEHOLDER_PROPERTIES,Sg as CORE_PLACEHOLDER_TYPES,ox as Camera,rx as Camera3D,zf as CameraBookmarkManager,_f as CameraManager,Jy as Capacity,Ry as CapacityEventTracker,Bc as CardLayout,Ly as CenteringQueueStrategy,v_ as CenteringSlotStrategy,Cc as Component,nm as Connectable,ng as Container,Jl as ContainerAbstract,Mf as ControlsManager,Xv as Cube,qv as Cube3D,Zv as Cylinder,Qv as Cylinder3D,Ks as DEFAULT,bu as DEFAULT_CEILING,US as DEFAULT_PALETTE,uu as DEFAULT_PLACEMENT,Ws as DPPX,sh as DataLagTracker,Ey as DataSource,Vd as DefaultLoadingOverlayRenderer,yy as Donut,Ev as DonutExtrude,bg as Ellipse,Mv as EllipseExtrude,Sf as EventManager3D,fl as EventMap,LS as FIGURE_CAPABILITIES,NS as FIGURE_CAPABILITY_NOTES,Fp as FPS,$S as FigureInstance,lk as FigurePart,ck as FigurePartRealObject,Ky as FixedSlotStrategy,yx as FloorPlate,a_ as FlowEngine,h_ as FlowNode,qs as GESTURES,cx as GLTFObject,Ty as GLTF_BASE_URL_ALIAS,Mg as GenericObject,Dv as GeometryBank,Kg as GifView,Af as GizmoManager,Tf as GizmoOperationManager,oy as GlobalRef,Oy as GltfComponent,Hy as GridStacking,ey as Group,Fc as HTMLAbsoluteLayout,sy as HTMLOverlayContainer,Fg as HTMLOverlayElement,c_ as Holdable,Lg as ImageView,Rc as InfoWindow,Fx as InstancedSet,Pf as InteractionManager,Xy as ItemsDataBinding,Xs as KEYEVENTS,gp as Layer,Lc as Layout,xf as LightManager,hx as LightObject,gg as Line,zx as Line3D,Vc as LinearHorizontalLayout,$c as LinearVerticalLayout,ah as LoadTracker,Rd as LoadingOverlay,iy as LocalRef,Td as MATERIAL_PRESETS,jv as MAX_SEGMENTS,Us as MAX_UNDO_SIZE,Rv as MIN_SEGMENTS,Ys as MODE_ADD,Hs as MODE_EDIT,Gs as MODE_PASTE_DATABIND,Vs as MODE_PASTE_STYLE,Bs as MODE_SHIFT,Ns as MODE_VIEW,av as MaterialBank,hk as Model,Ql as MoveHandle,Fs as NOTHING,A_ as NavGraph,wy as Node,Rg as OrthoLine,jx as OrthoLine3D,Np as PIXEL_RATIO,_g as PLACEHOLDER_THEMES,uy as Path,Ny as PatternStacking,Of as PlacementManager,dx as PointLight,Cg as Polygon,Pg as PolygonContainer,Av as PolygonExtrude,I_ as PolygonPathPolyline,Ig as Polyline,Rx as Polyline3D,ly as Popup,dy as PopupContainer,vl as Pose6DOF,xu as RealObject,Yx as RealObjectCamera,Wp as RealObjectDomElement,iv as RealObjectDomTexture,Hx as RealObjectDummy,Su as RealObjectExternalModel,wv as RealObjectExtrude,Cu as RealObjectGLTF,wx as RealObjectGroup,Ix as RealObjectLine,cv as RealObjectMesh,Vx as RealObjectPlane,Ux as RealObjectPlane2D,Gx as RealObjectScene,My as RealObjectService,Vv as RealObjectSprite,Gv as RealObjectSprite2D,mv as RealObjectText,rm as Rect,Sv as RectExtrude,Oc as RectPath,V_ as ReferenceMap,vf as RendererManager,S_ as ReservationTable,ih as RootContainer,am as Ruler,Zd as SCALE_MIN,$s as SCENE_MODE,zv as SEGMENT_DEFAULTS,Iv as SEGMENT_PRESETS,qf as SHORTCUT_SECTIONS,Ku as Scene,bf as SceneManager,mp as ScenePopup,Iu as SceneSearchEngine,K_ as ScriptLoader,Ru as SearchOverlay,ky as ServiceComponent,Tc as Shape,Yv as Sphere,Bv as Sphere3D,Uv as Sprite,vy as Star,Tv as StarExtrude,Wy as TRANSFER_SLOT_KEY,Uc as TableLayout,Jg as Text,Bf as ThreeCapability,qx as ThreeContainer,Cy as ThreeDOnly,Lu as Tracker,Uu as Transfer,Kl as TransitionEffect,fy as Triangle,Cv as TriangleExtrude,nu as UNIT_DIMENSION,ru as UNIT_ROTATE,iu as UNIT_SCALE,su as UNIT_TRANSLATE,nk as UNTOKENED_COLOR,Ay as ValueHolder,Hf as VertexGizmoManager,By as VolumeStacking,fx as Wall,px as Wall3D,fu as Z_PRIORITY,ES as acquireFigureGeometry,tk as activePalette,JS as activePaletteName,qb as allDestinations,rb as anchorsConnect,Sa as animate,tu as applyAlpha,Id as applyMaterial3dProps,Qb as applyPolicy,Uy as applySeatingRotation,Yy as applyStackLayout,gu as applyZPriorityToMaterials,ib as arcSegmentTopology,jy as autoWireBackPressure,$p as buildArrow3D,N_ as buildContractInspector,sf as buildCoordinateGround,TS as buildFigureGeometry,hb as buildFlowGraph,T_ as buildNavGraph,kv as buildShapeFromPolygonPath,op as buildTether,Zr as bulgeFromDrag,Qr as bulgeHandlePosition,mb as canReach,Bm as capability,xv as centerOnBBox,__ as chooseNearestPickupFrame,cp as clearTether,vb as collectAdjacentSegments,Ea as compile,Wb as componentForNode,Kr as computeArcParams,Rb as computeFlowMap,Fy as computeStackPositions,to as cornerHandlePosition,eo as cornerRadiusFromDrag,Zu as create,Hp as createCanvas,J_ as createCanvasTexture,mf as createFloor,Zp as createRealObjectFor,bx as createSelectionHandle3D,rh as dataLagTracker,Ji as debug,cb as deliversInto,wa as delta,cf as disposeCoordinateGround,cu as disposeObject3D,lp as disposeTether,t_ as downstream,dv as drawTextTexture,Jr as effectiveCornerRadius,vv as ellipseOutline,Sb as enumerateDataScenarios,Qi as error,YS as figureClassFor,nS as figureSectionOutline,Jd as fillStyleOpacity,b_ as filterByToolType,Xf as filterShortcuts,Fb as findNearestWithCapability,z_ as flattenPolygonPath,$b as flowGraphFor,Gb as flowGraphIssues,jb as flowReverseFor,lv as fontStyle,Vy as footprint2D,Rr as frameClock,Ob as ftId,Pb as ftrace,$m as getAllCapabilityMeta,Gm as getCapabilityMeta,gS as getFigure,kl as getPose,Al as getWorldPose,Ir as globalSimClock,Py as gltfNatureProperties,s_ as graphFor,Nx as gridPlacements,Xr as hasArc,Hm as hasCapability,Iy as hasCapacity,yS as hasFigure,zy as inferCapacity,xb as inferDownstreamId,Tb as inferFlowDirections,Zs as initFontFamilyWatcher,zd as inspector,H_ as installContractInspector,d_ as isFlowNode,kg as isGenericPlaceholder,Lb as isGeometricHost,wu as isParted,Nb as isRoutingTarget,Nv as isSegmentPreset,pu as isStateDriven,Pu as isThreedEnabled,lb as matchOutbounds,ji as metrics,Jb as next,fb as nextHop,pb as nextHops,yb as nextHopsToAny,bb as nextHopsToAnyDetailed,ef as niceGridStep,Xb as nodeIdOf,eu as opaqueColor,KS as paletteVersion,Mu as partAtByIndex,o_ as pickWeightedDestination,P_ as planPathAStar,O_ as planToReservations,ob as pointInRotatedRect,mu as polygonOffsetForPriority,R_ as polygonPathLength,np as projectToScreen,p_ as quatFromYaw,ab as rayAbsDistanceToRect,db as reachableByOutbound,e_ as reachableDestinations,n_ as reachableDestinationsFrom,i_ as reachableDestinationsWeightedFrom,gb as reachableSinks,Gu as receiptToJSON,yf as recommendsLogarithmicDepthForSky,tb as rectFaceAnchors,_v as rectOutline,g_ as rectangularFootprintFrames,Vm as registerCapabilityMeta,Qp as registerDefaultRealObjectFactory,mS as registerFigure,hS as registerFigureType,QS as registerPalette,Kp as registerRealObjectFactory,Rh as registerTypeResolver,CS as releaseFigureGeometry,tv as renderCanvasTexture,xg as renderPlaceholder,k_ as reservationTable,VS as resetFigureClasses,_S as resetFigures,ik as resetPalettes,rp as resolveAnchorWorldPosition,Fv as resolveHeightSegments,Pd as resolveMaterial3d,Zb as resolveNextHop,Lv as resolveSegments,ek as resolveToken,Lh as resolveUnknownTypes,Xd as resolveVariant,Dy as sceneComponent,ZS as setActivePalette,El as setPose,Ou as setThreedEnabled,Cl as setWorldPose,Ub as sinksForDestination,HS as slotsFromBindings,M_ as standardYieldPolicy,Lp as stopFPSMeasure,nb as straightSegmentEndpoints,sb as straightSegmentMultiInbound,eb as straightSegmentTopology,fv as textBounds,uv as textTexture,Dd as toThreeSide,y_ as topApproachFrame,Wu as transferLog,Yu as transferTracer,no as uniformZ,ak as unitFigurePartGeometry,jh as unknownTypesOf,bS as unregisterFigure,Qs as updateDefaultFontFamily,ap as updateTether,lS as useFigureComponent,r_ as validate,_b as validateFlowGraph,Q_ as version,Zi as warn};
50
+ `,this.element)}catch(t){}}onchangeMinimized(){const{minimized:t}=this.state;t?this.setState("height",24):this.setState("height",this.get("height"))}}Zm=new WeakMap,Cc.memoize(ng.prototype,"bounds",!0),Cc.register("container",ng);const ig=Math.sqrt(3),sg=2;function rg(t,e,n,i,s){const r=5+s,o=n.x,a=n.y,c=i.x,l=i.y;if(Math.abs(o-c)>r&&Math.abs(a-l)>r){const n=(l-a)/(c-o),i=a-n*o;if(Math.abs(e-(n*t+i))>r)return!1}let h,d,u,p;return o>c?(d=o,h=c):(d=c,h=o),a>l?(p=a,u=l):(p=l,u=a),!(d+5<t)&&(!(h-5>t)&&(!(p+5<e)&&!(u-5>e)))}function og(t,e,n,i=2){for(let s=0;s<n.length-1;s++)if(rg(t,e,n[s],n[s+1],i))return!0;return!1}function ag(t,e,n,i){if("arrow"!=t.slice(-5))return n;const s=Math.atan2(i.y-n.y,i.x-n.x),r=1.5*e;return{x:n.x+Math.cos(s)*r,y:n.y+Math.sin(s)*r}}function cg(t,e,n){let{lineWidth:i=sg,strokeStyle:s="#000000",lineCap:r=!1,alpha:o=1,begin:a="none",end:c="none",beginSize:l="size5",endSize:h="size5"}=n;if(("none"!=a||"none"!=c)&&(i=Number(i)||sg,t.lineCap=r,t.lineWidth=i,t.strokeStyle=s,t.fillStyle=s,t.globalAlpha*=o,"none"!=a&&lg(t,e[0],e[1],i,a,hg(l,i)),"none"!=c)){const n=e.length;lg(t,e[n-1],e[n-2],i,c,hg(h,i))}}function lg(t,e,n,i,s,r){const{x:o,y:a}=e,c=Math.atan2(n.y-a,n.x-o);switch(t.beginPath(),t.translate(o,a),t.rotate(c),s){case"oval":t.ellipse(0,0,r.X,r.Y,0,0,2*Math.PI),t.fill();break;case"diamond":t.moveTo(-r.X,0),t.lineTo(0,-r.Y),t.lineTo(r.X,0),t.lineTo(0,r.Y),t.fill();break;case"arrow":t.moveTo(0,0),t.lineTo(ig*r.X,-r.Y),t.lineTo(ig*r.X,r.Y),t.fill();break;case"sharp-arrow":t.moveTo(0,0),t.lineTo(ig*r.X,-r.Y),t.lineTo(-r.X/1.5+ig*r.X,0),t.lineTo(ig*r.X,r.Y),t.fill();break;case"open-arrow":t.moveTo(ig*r.X+i,-r.Y),t.lineTo(i,0),t.lineTo(ig*r.X+i,r.Y),t.stroke();break;case"cross":t.moveTo(-r.X,-r.Y),t.lineTo(r.X,r.Y),t.moveTo(r.X,-r.Y),t.lineTo(-r.X,r.Y),t.stroke()}t.rotate(-c),t.translate(-o,-a),t.closePath()}function hg(t,e){const n={X:0,Y:0};switch(e*=1.2,t){case"size1":n.X=e,n.Y=e;break;case"size2":n.X=1.5*e,n.Y=e;break;case"size3":n.X=2*e,n.Y=e;break;case"size4":n.X=e,n.Y=1.5*e;break;case"size5":default:n.X=1.5*e,n.Y=1.5*e;break;case"size6":n.X=2*e,n.Y=1.5*e;break;case"size7":n.X=e,n.Y=2*e;break;case"size8":n.X=1.5*e,n.Y=2*e;break;case"size9":n.X=2*e,n.Y=2*e}return n}const dg="N",ug="S",pg="E",fg="W";class mg{constructor({component:t,anchor:e,position:n,self:i}){this.component=t,this._anchorName=e,this._position=n,this.self=i}get position(){const t=this.anchor;if(t){const{position:e}=t,n=this.component.toScene(e.x,e.y);return this.self.transcoordT2P(n.x,n.y)}return this._position}set position({x:t,y:e}){this._position={x:t,y:e}}get anchor(){return this.component?.findAnchor(this._anchorName)}get direction(){const t=this.component.bounds,e=this.anchor;if(!e)return pg;const n=e.position;return n.y<=t.top?dg:n.y>=t.top+t.height?ug:n.x<=t.left?fg:pg}get boundaryPosition(){const t=this.anchor;if(t){let{position:e}=t,n=0,i=0;switch(this.direction){case ug:i=20;break;case dg:i=-20;break;case fg:n=-20;break;default:n=20}e={x:e.x+n,y:e.y+i};const s=this.component.toScene(e.x,e.y);return this.self.transcoordT2P(s.x,s.y)}}}class gg extends Cc{isLine(){return!0}is3dish(){return!0}replaceRefids(t){["from","to"].forEach(e=>{const n=this.get(e);if(n?.component){const i=t.get(n.component)||n.component;this.set(e,{...n,component:i})}})}get fromEnd(){if(this.parent&&!this._fromEnd){const{component:t,anchor:e,position:n}=this.getState("from")||{};if(!t)return;const i=this.root?.findByRefid?.(t);if(!i)return;this._fromEnd=new mg({component:i,fromto:"from",anchor:e,position:n,self:this})}return this._fromEnd}get from(){return this.getState("from")}set from(t){delete this._fromEnd,this.set("from",t)}get toEnd(){if(this.parent&&!this._toEnd){const{component:t,anchor:e,position:n}=this.getState("to")||{};if(!t)return;const i=this.root?.findByRefid?.(t);if(!i)return;this._toEnd=new mg({component:i,fromto:"to",anchor:e,position:n,self:this})}return this._toEnd}get to(){return this.getState("to")}set to(t){delete this._toEnd,this.set("to",t)}move({x:t,y:e},n){n&&(this.from={position:this._fromEnd?.position||this.getState("from")?.position||{x:0,y:0}},this.to={position:this._toEnd?.position||this.getState("to")?.position||{x:0,y:0}}),super.move({x:t,y:e})}render(t){const{begin:e="none",end:n="none",lineWidth:i,round:s=0}=this.state;let r=this.drawPath;cg(t,r,this.state),t.beginPath();const o=ag(e,i,r[0],r[1]),a=ag(n,i,r[r.length-1],r[r.length-2]),c=r[0];r=[o,...r.slice(1,-1),a];let l={x:o.x,y:o.y};if(t.moveTo(o.x,o.y),r.length>=2&&Xr(c)){const e=r[1],n=Jr(e,s),i=Math.sqrt((o.x-e.x)**2+(o.y-e.y)**2),a=0!==i?Math.atan2(o.x-e.x,o.y-e.y):0,l=Math.sin(a)*Math.min(n,i/2)+e.x,h=Math.cos(a)*Math.min(n,i/2)+e.y,d=Kr({x:o.x,y:o.y},{x:l,y:h},c.bulge);d&&t.arc(d.cx,d.cy,d.radius,d.startAngle,d.endAngle,d.clockwise)}for(let e=1;e<r.length;e++){const n=l;l=r[e];const i=r[e+1];if(n.x===l.x&&n.y===l.y)continue;if(!i){t.lineTo(l.x,l.y);break}const o=Jr(l,s);let a=Math.sqrt((n.x-l.x)*(n.x-l.x)+(n.y-l.y)*(n.y-l.y)),c=0!==a?Math.atan2(n.x-l.x,n.y-l.y):0,h=Math.sin(c)*Math.min(o,a/2)+l.x,d=Math.cos(c)*Math.min(o,a/2)+l.y;const u=o>0||0!==a?{x:h,y:d}:l;a=Math.sqrt((i.x-l.x)*(i.x-l.x)+(i.y-l.y)*(i.y-l.y)),c=0!==a?Math.atan2(i.x-l.x,i.y-l.y):0,h=Math.sin(c)*Math.min(o,a/2)+l.x,d=Math.cos(c)*Math.min(o,a/2)+l.y;const p=o>0||0!==a?{x:h,y:d}:l;if(t.lineTo(u.x,u.y),o>0&&t.quadraticCurveTo(l.x,l.y,p.x,p.y),Xr(l)){const e=Jr(i,s),n=Math.sqrt((l.x-i.x)**2+(l.y-i.y)**2),r=0!==n?Math.atan2(l.x-i.x,l.y-i.y):0,o=Math.sin(r)*Math.min(e,n/2)+i.x,a=Math.cos(r)*Math.min(e,n/2)+i.y,c=Kr({x:p.x,y:p.y},{x:o,y:a},l.bulge);c&&t.arc(c.cx,c.cy,c.radius,c.startAngle,c.endAngle,c.clockwise)}}this.drawStroke(t,void 0)}contains(t,e){const{lineWidth:n}=this.state;return og(t,e,this.drawPath,n)}get resizable(){return!1}get mutable(){return!0}get rotatable(){return!1}get path(){const{from:t,to:e}=this.state,{x1:n,y1:i,x2:s,y2:r}=this.state;return[this.fromEnd?.position||t?.position||{x:n,y:i},this.toEnd?.position||e?.position||{x:s,y:r}]}set path(t){const[e,n]=t,{from:i,to:s}=this.state;delete this._fromEnd,delete this._toEnd,this.set({from:{...i,position:e},to:{...s,position:n}})}get textBounds(){const t=this.drawPath;let e,n,i=0;for(let s=1;s<t.length;s++){const r=t[s-1],o=t[s],a=(r.x-o.x)*(r.x-o.x)+(r.y-o.y)*(r.y-o.y);a>i&&(i=Math.ceil(a),e=r,n=o)}let{paddingTop:s,paddingLeft:r,paddingRight:o,paddingBottom:a}=this.state;return a||=0,s||=0,r||=0,o||=0,{left:Math.min(e.x,n.x)+r,top:Math.min(e.y,n.y)+s,width:Math.max(Math.abs(e.x-n.x)-r-o,0),height:Math.max(Math.abs(e.y-n.y)-s-a,0)}}get decorators(){return this.app.isEditMode?["decotag"]:[]}}gg.getTipNeckPos=ag,gg.containedInPath=og,gg.drawEndTips=cg,Cc.register("line",gg);const yg={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"angle",label:"start-angle",name:"startAngle",property:"startAngle"},{type:"angle",label:"end-angle",name:"endAngle",property:"endAngle"}],"value-property":"text"};class bg extends(nm(Tc)){is3dish(){return!0}render(t){const{cx:e,cy:n,rx:i,ry:s,startAngle:r,endAngle:o,anticlockwise:a}=this.state;t.beginPath(),t.ellipse(e,n,Math.abs(i),Math.abs(s),0,r||0,o||2*Math.PI,a),void 0!==r&&void 0!==o&&(t.lineTo(e,n),t.closePath())}get path(){const{cx:t,cy:e,rx:n,ry:i}=this.state;return[{x:t-n,y:e-i},{x:t+n,y:e-i},{x:t+n,y:e+i},{x:t-n,y:e+i}]}set path(t){const e=t[0],n=t[2];this.set({cx:e.x+(n.x-e.x)/2,cy:e.y+(n.y-e.y)/2,rx:(n.x-e.x)/2,ry:(n.y-e.y)/2})}contains(t,e){const{cx:n,cy:i,rx:s,ry:r}=this.state,o=(t-n)/(2*s-.5),a=(e-i)/(2*r-.5);return o*o+a*a<.25}outline(t){return function(t,e){const{cx:n,cy:i,rx:s,ry:r}=t.model,o=2*Math.PI*e,a=n+s*Math.cos(o),c=i+r*Math.sin(o);return t.toScene(a,c)}(this,t)}get anchors(){return function(t){const{left:e,top:n,width:i,height:s}=t.bounds,r=e+i/2,o=n+s/2;return[{name:"TOP",position:{x:r,y:n}},{name:"RIGHT",position:{x:e+i,y:o}},{name:"BOTTOM",position:{x:r,y:n+s}},{name:"LEFT",position:{x:e,y:o}}]}(this)}get nature(){return yg}}Cc.memoize(bg.prototype,"path",!1),Cc.register("ellipse",bg);const _g={object:{fill:"rgba(180,180,180,0.18)",stroke:"#888888",icon:"?",label:"object"},transport:{fill:"rgba(100,180,255,0.18)",stroke:"#3a78c8",icon:"⇄",label:"transport"},facility:{fill:"rgba(160,140,220,0.18)",stroke:"#6b4ec8",icon:"◫",label:"facility"},vehicle:{fill:"rgba(120,200,140,0.18)",stroke:"#3a8c5e",icon:"⊙",label:"vehicle"},region:{fill:"rgba(220,200,100,0.18)",stroke:"#a0892a",icon:"▢",label:"region"},path:{fill:"rgba(200,140,160,0.18)",stroke:"#a0506a",icon:"⌐",label:"path"},"3d-asset":{fill:"rgba(255,180,80,0.18)",stroke:"#c87a2a",icon:"◈",label:"3D asset"}},vg=[{type:"string",label:"placeholder-label",name:"placeholderLabel",description:'사용자에게 표시할 추가 라벨 (예: "Stocker A1")'},{type:"string",label:"hint",name:"placeholderHint",description:"구체화 시 참고 — 도면의 원본 식별자 / VLM 라벨 등"}];function xg(t,e,n,i,s){const{left:r,top:o,width:a,height:c}=e,l=Math.max(a,1),h=Math.max(c,1);t.save(),t.fillStyle=n.fill,t.fillRect(r,o,l,h),t.strokeStyle=n.stroke,t.lineWidth=1.5,t.setLineDash([4,3]),t.strokeRect(r,o,l,h),t.setLineDash([]),t.restore(),Math.min(l,h)>=24&&(t.save(),t.fillStyle=n.stroke,t.font=`bold ${Math.min(20,.4*Math.min(l,h))}px Arial`,t.textAlign="center",t.textBaseline="middle",t.fillText(n.icon,r+l/2,o+h/2),t.restore());const d=i?`${n.label}: ${i}`:n.label;h>=32&&(t.save(),t.fillStyle=n.stroke,t.font="10px Arial",t.textAlign="center",t.textBaseline="bottom",t.fillText(d,r+l/2,o+h-4),t.restore()),s&&h>=40&&(t.save(),t.fillStyle=n.stroke,t.font="9px Arial",t.textAlign="right",t.textBaseline="top",t.fillText(`hint: ${s}`,r+l-4,o+4),t.restore())}const wg={mutable:!1,resizable:!0,rotatable:!0,properties:[...vg,{type:"placeholder-convert",label:"",name:"_convert"}],help:"scene/component/placeholder"};class Mg extends(Oc(Tc)){get nature(){return wg}render(t){const{placeholderLabel:e,placeholderHint:n}=this.state;xg(t,this.bounds,_g.object,e,n)}}Cc.register("placeholder",Mg);const Sg=["placeholder"];function kg(t,e=[]){return!!t&&(!!Sg.includes(t)||e.includes(t))}const Ag={ondragstart:function(t,e,n){n.mutatePath(null,function(n){n.splice(e+1,0,t)})},ondragmove:function(t,e,n){n.mutatePath(null,function(n){const i=n[e+1];n[e+1]={...i||{},x:t.x,y:t.y}})},ondragend:function(t,e,n){}},Eg={mutable:!0,resizable:!1,rotatable:!0,properties:[{type:"number",label:"round",name:"round",property:{min:0,max:100,step:1}}],help:"scene/component/polygon"};class Cg extends Tc{is3dish(){return!0}get mutable(){return!0}get pathExtendable(){return!0}get cornerEditable(){return!0}get path(){return this.state.path??[]}set path(t){this.set("path",t)}contains(t,e){const n=this.path;let i=!1;return n.forEach((s,r)=>{const o=(r+n.length+1)%n.length,a=s.x,c=s.y,l=n[o].x,h=n[o].y;c>e!=h>e&&t<(l-a)*(e-c)/(h-c)+a&&(i=!i)}),i}get controls(){const t=this.path;return t.map((e,n)=>{const i=t[n+1>=t.length?0:n+1];return{x:(e.x+i.x)/2,y:(e.y+i.y)/2,handler:Ag}})}get nature(){return Eg}}Cc.memoize(Cg.prototype,"controls",!1),Cc.register("polygon",Cg);const Tg=[];class Pg extends(Ql(Cg)){constructor(t,e){super(t,e),this._components=[]}replaceRefids(t){this.components.forEach(e=>e.replaceRefids(t))}get showMoveHandle(){return!0}get showOverflow(){return!1}dispose(){this.components.slice().forEach(t=>t.dispose()),super.dispose()}isContainer(){return!0}containable(t){return t.isDescendible(this)}get hasTextProperty(){return!1}get components(){return this._components}get focusible(){return!0}get layout(){return Lc.get(this.get("layout"))||Nc}reflow(){this.layout.reflow(this),this.components&&this.components.forEach(t=>{t.isContainer()&&t.reflow()})}get hierarchy(){const t=super.hierarchy;return this.components?.length&&(t.components=this.components.map(t=>t.hierarchy)),t}reparent(t,e={}){t&&t.parent!==this&&this.addComponent(t,{silent:!0})}addComponent(t,e=!1){const{ghost:n=!1,silent:i=!1}="boolean"==typeof e?{ghost:e}:e,s=t.parent;if(s){if(this===s)return;s.removeComponent(t,n||i)}const r=this._components.push(t)-1;i&&(t._silentAdd=!0),t.parent=this,t.added(this),n||i||this.trigger("add",this,t,r),t.delegate_on(this),i?(s&&this.root?._removeTraverse?.(t),this.trigger("add",this,t,r),t.trigger("added",this,t,r),delete t._silentAdd):n||t.trigger("added",this,t,r),this.root&&this.root.isReady&&t.invokeReady()}removeComponent(t,e=!1){const n=this._components.indexOf(t);-1!=n&&(this._components.splice(n,1),t.parent=null,t.removed(this),e||(this.trigger("remove",this,t),t.trigger("removed",this,t)),t.delegate_off(this))}insertComponentAt(t,e,n=!1){const i=t.parent;i&&i.removeComponent(t,n);const s=this._components.splice(0,e);this._components=s.concat(t,this._components),e=this._components.indexOf(t),t.parent=this,t.added(this),n||this.trigger("add",this,t,e),t.delegate_on(this),n||t.trigger("added",this,t,e)}add(t,e=!1){return t instanceof Array?(t.forEach(t=>{-1==this._components.indexOf(t)&&this.addComponent(t,e)}),this):this.add.call(this,[t],e)}remove(t,e=!1){return t instanceof Array?this._components?(t.forEach(t=>this.removeComponent(t,e)),this):this:this.remove.call(this,[t],e)}getAt(t){if(this._components)return this._components[t]}forEach(t,e){this._components&&this._components.forEach(t,e)}traverse(t,e){t.call(e,this),this._components&&this._components.forEach(n=>{n.isContainer()?n.traverse(t,e):t.call(e,n)})}indexOf(t){return(this._components||Tg).indexOf(t)}size(){return(this._components||Tg).length}moveChildAt(t,e){const n=this.indexOf(e);if(-1==n)return;let i=this._components.splice(0,n);const s=this._components.splice(1);this._components=i.concat(s),t=Math.max(0,t),t=Math.min(t,this._components.length),i=this._components.splice(0,t),this._components=i.concat(e,this._components)}moveChildForward(t){const e=this.indexOf(t);-1!=e&&e!=this.size()-1&&(this._components[e]=this._components[e+1],this._components[e+1]=t)}moveChildBackward(t){const e=this.indexOf(t);-1!=e&&0!=e&&(this._components[e]=this._components[e-1],this._components[e-1]=t)}moveChildToFront(t){const e=this.indexOf(t);if(-1==e||e==this.size()-1)return;const n=this._components.splice(0,e),i=this._components.splice(1);this._components=n.concat(i,this._components)}moveChildToBack(t){const e=this.indexOf(t);if(-1==e||0==e)return;const n=this._components.splice(0,e),i=this._components.splice(1);this._components=this._components.concat(n,i)}symmetryX(t){super.symmetryX(t),this.components.map(t=>{t.symmetryX(0)})}findAll(t,...e){if("string"==typeof t)return ec(t,this,e[0]||this);if("function"!=typeof t)return[];let n=[];for(let i=this.components.length-1;i>=0;i--){const s=this.components[i].findAll(t,...e);s&&(n=n.concat(s))}return t(this,...e)&&n.push(this),n}findFirst(t,...e){if("string"==typeof t)return ec(t,this,e[0])[0];if("function"==typeof t){for(let n=this.components.length-1;n>=0;n--){const i=this.components[n].findFirst(t,...e);if(null!=i)return i}return t(this,...e)?this:void 0}}findById(t){return this.root.findAllById?.(t)?.[0]}findByRefid(t){return this.root.findByRefid?.(t)}capture(t,e,n){if(!this.app.isEditMode&&this.hidden)return!1;const i=this.fromParent(t,e);if(!this.contains(i.x,i.y))return!1;const s=this.bounds;i.x-=s.left,i.y-=s.top;const r=this.layout.capturables(this);for(let s=r.length-1;s>=0;s--){const o=r[s];let a;if(a="static"==o.position?o.capture(i.x,i.y,n):o.capture(t,e,n),a)return a}return this.capturable&&!n?.(this)&&this}capturePath(t,e){if(e){if(e.indexOf(this)>-1)return!1;for(let t=0;t<e.length;t++)if(!this.containable(e[t]))return!1}const n=[],{left:i,top:s,width:r,height:o}=this.bounds;for(let e=0;e<t.length;e++){const a=this.fromParent(t[e].x,t[e].y);if(a.x<i||a.x>i+r||a.y<s||a.y>s+o)return!1;a.x-=i,a.y-=s,n.push(a)}const a=this.layout.capturables(this);for(let t=a.length-1;t>=0;t--){const i=a[t];if(!i.isContainer())continue;const s=i.capturePath(n,e);if(s)return s}return this.focusible&&this}render(t){"popup"!==this.position&&super.render(t)}postrender(t){if("popup"===this.position)return void super.postrender(t);const e=this.layout.drawables(this);if(e.length>0){let{left:n=0,top:i=0,width:s,height:r}=this.bounds;t.save(),this.showOverflow||(t.beginPath(),t.rect(n,i,s,r),t.clip(),t.closePath()),t.translate(n,i),e.forEach(e=>{const n=this.root?.transitionEffect;n?.isReparenting(e)||e.draw(this.position&&"static"!==this.position?t:this.getContext(e))}),t.translate(-n,-i),t.restore()}super.postrender(t)}trim(){this.components.forEach(t=>{t.trim()}),super.trim()}}["layout"].forEach(t=>Cc.memoize(Pg.prototype,t,!1));const Og={ondragstart:function(t,e,n){n.mutatePath(null,function(n){n.splice(e,0,t)})},ondragmove:function(t,e,n){n.mutatePath(null,function(n){const i=n[e];n[e]={...i||{},x:t.x,y:t.y}})},ondragend:function(t,e,n){}},Dg={mutable:!1,resizable:!1,rotatable:!1,properties:[{type:"number",label:"round",name:"round",property:{min:0,max:100,step:1}}],help:"scene/component/polyline"};class Ig extends gg{get pathExtendable(){return!0}get cornerEditable(){return!0}get path(){const{from:t,to:e}=this.state,{path:n}=this.state;return[this.fromEnd?.position||t?.position||n[0],...n.slice(1,-1),this.toEnd?.position||e?.position||n[n.length-1]]}set path(t){const{from:e,to:n}=this.state;delete this._fromEnd,delete this._toEnd,this.set({from:{...e,position:t[0]},to:{...n,position:t[t.length-1]},path:t})}get controls(){const t=this.path,e=[];for(let n=0;n<t.length-1;n++){const i=t[n],s=t[n+1];0==n&&e.push({x:i.x,y:i.y,handler:Og}),e.push({x:(i.x+s.x)/2,y:(i.y+s.y)/2,handler:Og}),n==t.length-2&&e.push({x:s.x,y:s.y,handler:Og})}return e}get nature(){return Dg}}Cc.register("polyline",Ig);const zg={mutable:!1,resizable:!1,rotatable:!1,properties:[{type:"number",label:"round",name:"round",property:{min:0,max:100,step:1}}],help:"scene/component/ortholine"};class Rg extends gg{get pathExtendable(){return!1}get drawPath(){const t=this.path[0],e=this.path[1],{component:n,direction:i,boundaryPosition:s=t}=this.fromEnd||{},{component:r,direction:o,boundaryPosition:a=e}=this.toEnd||{},c=[s,a],l=[];s&&l.push(s);let h,d=n?.bounds;d&&(h=n.toScene(d.left,d.top),h=this.transcoordT2P(h.x,h.y),d={...d,left:h.x,top:h.y});const u=d?{left:d.left-20,top:d.top-20,width:d.width+40,height:d.height+40}:{left:s.x,top:s.y,width:0,height:0};d=d||u;let p=r?.bounds;p&&(h=r.toScene(p.left,p.top),h=this.transcoordT2P(h.x,h.y),p={...p,left:h.x,top:h.y});const f=p?{left:p.left-20,top:p.top-20,width:p.width+40,height:p.height+40}:{left:a.x,top:a.y,width:0,height:0};p=p||f;const m=[u,f],g=u.left>f.left?f.left:u.left,y=u.top>f.top?f.top:u.top,b={left:g,top:y,width:u.left+u.width>f.left+f.width?u.left+u.width-g:f.left+f.width-g,height:u.top+u.height>f.top+f.height?u.top+u.height-y:f.top+f.height-y};let _,v,x,w,M,S,k,A,E,C,T=0,P=0;d.left+d.width<p.left?(w=0,M=1,E=i,C=o,_=(d.left+d.width+p.left)/2,T=p.left-_):p.left+p.width<d.left&&(w=1,M=0,E=o,C=i,_=(d.left+p.width+p.left)/2,T=d.left-_),d.top+d.height<p.top?(x=0,S=1,k=i,A=o,v=(d.top+d.height+p.top)/2,P=p.top-v):p.top+p.height<d.top&&(x=1,S=0,k=o,A=i,v=(d.top+p.height+p.top)/2,P=d.top-v);const O=[];if(_&&T>P){let t,e,n;switch(C){case fg:switch(E){case pg:O.push({x:_,y:c[w].y}),O.push({x:_,y:c[M].y});break;case fg:t=m[w].top+m[w].height/2,e=t>c[M].y?Math.min(m[w].top,c[M].y):Math.max(m[w].top+m[w].height,c[M].y),O.push({x:c[w].x,y:e}),O.push({x:_,y:e}),O.push({x:_,y:c[M].y});break;case dg:case ug:e=E===ug?Math.max(c[w].y,c[M].y):Math.min(c[w].y,c[M].y),O.push({x:c[w].x,y:e}),O.push({x:_,y:e}),O.push({x:_,y:c[M].y});break;default:return this.path}break;case pg:switch(E){case pg:e=c[w].y<c[M].y?Math.min(m[M].top,c[w].y):Math.max(m[M].top+m[M].height,c[w].y),n=e;break;case fg:e=void 0!==v?v:c[w].y<c[M].y?b.top-.5*T:b.top+b.height+.5*T,n=e;break;case ug:e=void 0!==v?Math.max(v,c[w].y):b.top+b.height,n=e;break;case dg:e=v?Math.min(v,m[w].top):b.top,n=e;break;default:return this.path}O.push({x:c[w].x,y:e}),O.push({x:_,y:e}),O.push({x:_,y:n}),O.push({x:c[M].x,y:n});break;case ug:switch(E){case pg:e=c[w].y,n=c[w].y>c[M].y?c[w].y:m[M].top+m[M].height;break;case fg:e=v?Math.max(v,m[M].top+m[M].height):b.top+b.height,n=e;break;case ug:e=b.top+b.height,n=e;break;case dg:e=v?Math.min(v,m[w].top):m[w].top,n=v?Math.max(v,m[M].top+m[M].height):m[M].top+m[M].height;break;default:return this.path}O.push({x:c[w].x,y:e}),O.push({x:_,y:e}),O.push({x:_,y:n}),O.push({x:c[M].x,y:n});break;case dg:switch(E){case pg:e=c[w].y,n=c[w].y<c[M].y?c[w].y:m[M].top;break;case fg:e=v?Math.min(v,m[M].top):b.top,n=e;break;case ug:e=void 0!==v?Math.max(v,c[w].y):c[w].y,n=void 0!==v?Math.min(v,c[M].y):c[M].y;break;case dg:e=b.top,n=e;break;default:return this.path}O.push({x:c[w].x,y:e}),O.push({x:_,y:e}),O.push({x:_,y:n}),O.push({x:c[M].x,y:n});break;default:return this.path}l.push(...0===w?O:O.reverse())}else if(v){let t,e,n;switch(A){case dg:switch(k){case ug:O.push({x:c[x].x,y:v}),O.push({x:c[S].x,y:v});break;case dg:t=m[x].left+m[x].width/2,e=t>c[S].x?Math.min(m[x].left,c[S].x):Math.max(m[x].left+m[x].width,c[S].x),O.push({x:e,y:c[x].y}),O.push({x:e,y:v}),O.push({x:c[S].x,y:v});break;case fg:e=Math.min(c[x].x,c[S].x),O.push({x:e,y:c[x].y}),O.push({x:e,y:v}),O.push({x:c[S].x,y:v});break;case pg:e=Math.max(c[x].x,c[S].x),O.push({x:e,y:c[x].y}),O.push({x:e,y:v}),O.push({x:c[S].x,y:v});break;default:return this.path}break;case ug:switch(k){case fg:e=b.left,n=e;break;case pg:e=void 0!==_?Math.max(_,c[x].x):b.left+b.width,n=e;break;case dg:e=void 0!==_?_:c[x].x<c[S].x?b.left-.5*P:b.left+b.width+.5*P,n=e;break;case ug:e=c[x].x,n=c[x].x<c[S].x?Math.min(m[S].left,c[x].x):Math.max(m[S].left+m[S].width,c[x].x);break;default:return this.path}O.push({x:e,y:c[x].y}),O.push({x:e,y:v}),O.push({x:n,y:v}),O.push({x:n,y:c[S].y});break;case pg:switch(k){case fg:e=void 0!==_?Math.min(_,c[x].x):c[x].x,n=void 0!==_?Math.max(_,c[S].x):c[S].x;break;case pg:e=b.left+b.width,n=e;break;case dg:e=void 0!==_?Math.max(_,c[S].x):b.left+b.width,n=e;break;case ug:e=c[x].x,n=Math.max(m[S].left+m[S].width,c[x].x);break;default:return this.path}O.push({x:e,y:c[x].y}),O.push({x:e,y:v}),O.push({x:n,y:v}),O.push({x:n,y:c[S].y});break;case fg:switch(k){case fg:e=b.left,n=e;break;case pg:e=void 0!==_?Math.max(_,c[x].x):c[x].x,n=void 0!==_?Math.min(_,c[S].x):c[S].x;break;case dg:e=b.left,n=e;break;case ug:e=c[x].x<c[S].x?Math.min(m[S].left,c[x].x):c[x].x,n=Math.min(e,c[S].x);break;default:return this.path}O.push({x:e,y:c[x].y}),O.push({x:e,y:v}),O.push({x:n,y:v}),O.push({x:n,y:c[S].y});break;default:return this.path}l.push(...0===x?O:O.reverse())}else{let t,e;switch(i){case dg:switch(o){case dg:e=b.top,l.push({x:c[0].x,y:e}),l.push({x:c[1].x,y:e});break;case ug:t=b.left+b.width,l.push({x:t,y:c[0].y}),l.push({x:t,y:b.top+b.height}),l.push({x:c[1].x,y:b.top+b.height});break;case pg:t=c[1].y<c[0].y&&c[1].x<c[0].x?c[0].x:b.left+b.width,l.push({x:t,y:c[0].y}),l.push({x:t,y:c[1].y});break;case fg:t=b.left,l.push({x:t,y:c[0].y}),l.push({x:t,y:c[1].y});break;default:return this.path}break;case ug:switch(o){case dg:t=b.left+b.width,l.push({x:t,y:c[0].y}),l.push({x:t,y:b.top}),l.push({x:c[1].x,y:b.top});break;case ug:case pg:case fg:e=b.top+b.height,l.push({x:c[0].x,y:e}),l.push({x:c[1].x,y:e});break;default:return this.path}break;case fg:switch(o){case dg:t=c[0].x>c[1].x&&c[0].y<c[1].y?c[1].x:b.left,e=c[0].x>c[1].x&&c[0].y<c[1].y?c[1].y:Math.min(b.top,c[0].y),l.push({x:t,y:c[0].y}),l.push({x:t,y:e}),l.push({x:c[1].x,y:e});break;case ug:t=b.left,e=Math.max(b.top+b.height,c[0].y),l.push({x:t,y:c[0].y}),l.push({x:t,y:e}),l.push({x:c[1].x,y:e});break;case pg:t=b.left+b.width,l.push({x:c[0].x,y:b.top}),l.push({x:t,y:b.top}),l.push({x:t,y:c[1].y});break;case fg:t=b.left,l.push({x:t,y:c[0].y}),l.push({x:t,y:c[1].y});break;default:return this.path}break;case pg:switch(o){case dg:e=c[0].y<c[1].y&&c[0].x<c[1].x?c[0].y:b.top,l.push({x:c[0].x,y:e}),l.push({x:c[1].x,y:e});break;case ug:e=c[0].y>c[1].y&&c[0].x<c[1].x?c[0].y:b.top+b.height,l.push({x:c[0].x,y:e}),l.push({x:c[1].x,y:e});break;case pg:case fg:e=b.top+b.height,l.push({x:c[0].x,y:e}),l.push({x:c[1].x,y:e});break;default:return this.path}break;default:return this.path}}return a&&l.push(a),[t,...l,e].filter((t,e,n)=>{if(0===e)return!0;const i=n[e-1];return t.x!==i.x||t.y!==i.y}).filter((t,e,n)=>{if(0===e||e>=n.length-1)return!0;const i=n[e-1],s=n[e+1];return!(t.x===i.x&&t.x===s.x||t.y===i.y&&t.y===s.y)})}get nature(){return zg}}Cc.register("ortholine",Rg);const jg={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"image-selector",label:"image-src",name:"src",property:{displayField:"id",displayFullUrl:!0,baseUrlAlias:"$base_url",defaultStorage:"scene-image",storageFilters:{type:Array,value:[{name:"category",value:"image"}]},useUpload:!0}},{type:"select",label:"cross-origin",name:"crossOrigin",property:{options:["","anonymous","use-credentials"]}}],"value-property":"src",help:"scene/component/image-view"};class Lg extends(Oc(Tc)){static get noimage(){return Lg.NOIMAGE||(Lg.NOIMAGE=new Image,Lg.NOIMAGE.src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGAAAABIBAMAAAD7Se1QAAAAIVBMVEUAAABHcEwBAQEREREBAQEEBAQGBgYLCwsDAwMDAwMICAi6HF9tAAAAC3RSTlNNAEAERiMYCS41Eac10lYAAAEgSURBVHhe7dY9asQwEAXgh7DNertNiJy48pIitY3SB7bYdk0ukL1BDDmA9gZecoH4pmFQ3MQayUMguPBrNPD4wD9TCMvJmt3M/AtYwXOlXiWgqADVCUBD46MAnGhMBaCiUQmAm8VA/Eh/eWl9Fn5WcxD+OLuRrUYJDKLluwH2InACUgkoACSdADxQc50Bytadb9RkM0CT13TcvlCT1HFg8UTHvasuUVACCa3El6u2UdD8LFTlKhUFFgA+d3dj10aABkUN72N3jAADCrJq7PIIsPidcxBoTHIIAjMFmyCwmGYIAA1P9gFgfCANAOsDSccCDW+uLDB+kLGg94OkZoAGkwsDDAe2DOg5oPxAg03rBR88OHpBz4N8UVeHFSwma74BTW6Ge4rIRa4AAAAASUVORK5CYII="),Lg.NOIMAGE}dispose(){super.dispose(),this._offcanvas=null,this._image=null}render(t){const{left:e,top:n,width:i,height:s,isGray:r=!1,alpha:o=1,src:a}=this.state;if(this.prepareIf(!this._image&&a),t.beginPath(),t.globalAlpha*=o,this._image&&this._image.complete)if(r&&this._offcanvas)t.drawImage(this._offcanvas,e,n,i,s);else try{t.drawImage(this._image,e,n,i,s)}catch(r){t.drawImage(Lg.noimage,e,n,i,s)}else!this.app.isViewMode&&t.drawImage(Lg.noimage,e,n,i,s)}get nature(){return jg}get hasTextProperty(){return!1}async ready(){await super.ready();const{src:t}=this.state;if(!this._image&&t){const e=this.root?.app?.loadTracker;if(e){const n=new Promise((t,e)=>{this.prepare(()=>t(),t=>e(t))});e.track(`image:${t}`,"image",t,n)}else this.prepareIf(!0)}}prepare(t,e){const{src:n,crossOrigin:i}=this.state;if(n){this._image=new Image;try{i&&(this._image.crossOrigin=i),this._image.src=this.app.url(n)||""}catch(t){return void e(t)}this._image.onload=()=>{if(this.get("isGray")){const t=this._image.width,e=this._image.height;this._offcanvas=Cc.createCanvas(t,e);const n=this._offcanvas.getContext("2d");n.drawImage(this._image,0,0);const i=function(t,e,n){let i;try{i=t.getImageData(0,0,e,n)}catch(t){return Qi("Get Image Data Error: "+(t instanceof Error?t.message:String(t))),null}const s=i.data;for(let t=0;t<e*n*4;t+=4){const e=s[t],n=s[t+1],r=s[t+2],o=Math.floor((e+n+r)/3);i.data[t]=o,i.data[t+1]=o,i.data[t+2]=o}return i}(n,t,e);n.putImageData(i,0,0)}t(this)},this._image.onerror=t=>{this._image&&!this._image.currentSrc&&(this._image=null),e(t)}}else t(this)}get src(){return this.get("src")}set src(t){this.set("src",t)}onchange(t,e){(t.hasOwnProperty("src")||t.hasOwnProperty("isGray"))&&(this._offcanvas=null,this._image=null,this.prepareIf(t.src))}ondropfile(t,e){for(let n=0;n<t.length;n++)if(t[n].type.startsWith("image/"))return void(this.src=e[n])}}Cc.register("image-view",Lg);class Fg extends(Qm(Oc(Cc))){is3dish(){return!0}prerender(){}}var Ng,Hg,Bg={},Yg={},Vg={};function Gg(){if(Hg)return Yg;Hg=1,Object.defineProperty(Yg,"__esModule",{value:!0});var t=function(){if(Ng)return Vg;Ng=1,Object.defineProperty(Vg,"__esModule",{value:!0});var t=function(){function t(){}return t.bitsToNum=function(t){return t.reduce(function(t,e){return 2*t+e},0)},t.byteToBitArr=function(t){for(var e=[],n=7;n>=0;n--)e.push(!!(t&1<<n));return e},t.lzwDecode=function(t,e){for(var n,i,s=0,r=function(t){for(var n=0,i=0;i<t;i++)e.charCodeAt(s>>3)&1<<(7&s)&&(n|=1<<i),s++;return n},o=[],a=1<<t,c=a+1,l=t+1,h=[],d=function(){h=[],l=t+1;for(var e=0;e<a;e++)h[e]=[e];h[a]=[],h[c]=null};;)if(i=n,(n=r(l))!==a){if(n===c)break;if(n<h.length)i!==a&&h.push(h[i].concat(h[n][0]));else{if(n!==h.length)throw new Error("Invalid LZW code.");h.push(h[i].concat(h[i][0]))}o.push.apply(o,h[n]),h.length===1<<l&&l<12&&l++}else d();return o},t}();return Vg.SuperGifUtils=t,Vg}(),e=function(){function e(t,e){this.stream=t,this.handler=e}return e.prototype.parseCT=function(t){for(var e=[],n=0;n<t;n++)e.push(this.stream.readBytes(3));return e},e.prototype.readSubBlocks=function(){var t,e;e="";do{t=this.stream.readByte(),e+=this.stream.read(t)}while(0!==t);return e},e.prototype.parseHeader=function(){var e={};if(e.sig=this.stream.read(3),e.ver=this.stream.read(3),"GIF"!==e.sig)throw new Error("Not a GIF file.");e.width=this.stream.readUnsigned(),e.height=this.stream.readUnsigned();var n=t.SuperGifUtils.byteToBitArr(this.stream.readByte());e.gctFlag=n.shift(),e.colorRes=t.SuperGifUtils.bitsToNum(n.splice(0,3)),e.sorted=n.shift(),e.gctSize=t.SuperGifUtils.bitsToNum(n.splice(0,3)),e.bgColor=this.stream.readByte(),e.pixelAspectRatio=this.stream.readByte(),e.gctFlag&&(e.gct=this.parseCT(1<<e.gctSize+1)),this.handler.hdr&&this.handler.hdr(e)},e.prototype.parseExt=function(e){var n=this;switch(e.label=this.stream.readByte(),e.label){case 249:e.extType="gce",function(e){n.stream.readByte();var i=t.SuperGifUtils.byteToBitArr(n.stream.readByte());e.reserved=i.splice(0,3),e.disposalMethod=t.SuperGifUtils.bitsToNum(i.splice(0,3)),e.userInput=i.shift(),e.transparencyGiven=i.shift(),e.delayTime=n.stream.readUnsigned(),e.transparencyIndex=n.stream.readByte(),e.terminator=n.stream.readByte(),n.handler.gce&&n.handler.gce(e)}(e);break;case 254:e.extType="com",function(t){t.comment=n.readSubBlocks(),n.handler.com&&n.handler.com(t)}(e);break;case 1:e.extType="pte",function(t){n.stream.readByte(),t.ptHeader=n.stream.readBytes(12),t.ptData=n.readSubBlocks(),n.handler.pte&&n.handler.pte(t)}(e);break;case 255:e.extType="app",function(t){n.stream.readByte(),t.identifier=n.stream.read(8),t.authCode=n.stream.read(3),"NETSCAPE"===t.identifier?function(t){n.stream.readByte(),t.unknown=n.stream.readByte(),t.iterations=n.stream.readUnsigned(),t.terminator=n.stream.readByte(),n.handler.app&&n.handler.app.NETSCAPE&&n.handler.app.NETSCAPE(t)}(t):function(t){t.appData=n.readSubBlocks(),n.handler.app&&n.handler.app[t.identifier]&&n.handler.app[t.identifier](t)}(t)}(e);break;default:e.extType="unknown",function(t){t.data=n.readSubBlocks(),n.handler.unknown&&n.handler.unknown(t)}(e)}},e.prototype.parseImg=function(e){e.leftPos=this.stream.readUnsigned(),e.topPos=this.stream.readUnsigned(),e.width=this.stream.readUnsigned(),e.height=this.stream.readUnsigned();var n=t.SuperGifUtils.byteToBitArr(this.stream.readByte());e.lctFlag=n.shift(),e.interlaced=n.shift(),e.sorted=n.shift(),e.reserved=n.splice(0,2),e.lctSize=t.SuperGifUtils.bitsToNum(n.splice(0,3)),e.lctFlag&&(e.lct=this.parseCT(1<<e.lctSize+1)),e.lzwMinCodeSize=this.stream.readByte();var i=this.readSubBlocks();e.pixels=t.SuperGifUtils.lzwDecode(e.lzwMinCodeSize,i),e.interlaced&&(e.pixels=function(t,e){for(var n=new Array(t.length),i=t.length/e,s=function(i,s){var r=t.slice(s*e,(s+1)*e);n.splice.apply(n,[i*e,e].concat(r))},r=[0,4,2,1],o=[8,8,4,2],a=0,c=0;c<4;c++)for(var l=r[c];l<i;l+=o[c])s(l,a),a++;return n}(e.pixels,e.width)),this.handler.img&&this.handler.img(e)},e.prototype.parseBlock=function(){var t={};switch(t.sentinel=this.stream.readByte(),String.fromCharCode(t.sentinel)){case"!":t.type="ext",this.parseExt(t);break;case",":t.type="img",this.parseImg(t);break;case";":t.type="eof",this.handler.eof&&this.handler.eof(t);break;default:throw new Error("Unknown block: 0x"+t.sentinel.toString(16))}"eof"!==t.type&&setTimeout(this.parseBlock.bind(this),0)},e.prototype.parse=function(){this.parseHeader(),setTimeout(this.parseBlock.bind(this),0)},e}();return Yg.SuperGifParser=e,Yg}var $g,Ug,Wg={};var qg=function(){if(Ug)return Bg;Ug=1,Object.defineProperty(Bg,"__esModule",{value:!0});var t=Gg(),e=function(){if($g)return Wg;$g=1,Object.defineProperty(Wg,"__esModule",{value:!0});var t=function(){function t(t){this.data=t,this.position=0}return t.prototype.readByte=function(){if(this.position>=this.data.length)throw new Error("Attempted to read past end of stream.");return this.data instanceof Uint8Array?this.data[this.position++]:255&this.data.charCodeAt(this.position++)},t.prototype.readBytes=function(t){for(var e=[],n=0;n<t;n++)e.push(this.readByte());return e},t.prototype.read=function(t){for(var e="",n=0;n<t;n++)e+=String.fromCharCode(this.readByte());return e},t.prototype.readUnsigned=function(){var t=this.readBytes(2);return(t[1]<<8)+t[0]},t}();return Wg.SuperGifStream=t,Wg}(),n=function(){function n(t,e){var n=this;for(var i in this.gifImgElement=t,this.options={autoPlay:!0},this.loading=!1,this.ready=!1,this.transparency=null,this.delay=null,this.disposalMethod=null,this.disposalRestoreFromIdx=null,this.lastDisposalMethod=null,this.frame=null,this.lastImg=null,this.playing=!0,this.forward=!0,this.ctxScaled=!1,this.frames=[],this.frameOffsets=[],this.initialized=!1,this.currentFrameIndex=-1,this.iterationCount=0,this.stepping=!1,this.handler={hdr:this.withProgress(this.doHdr.bind(this)),gce:this.withProgress(this.doGCE.bind(this)),com:this.withProgress(this.doNothing.bind(this)),app:{NETSCAPE:this.withProgress(this.doNothing.bind(this))},img:this.withProgress(this.doImg.bind(this)),eof:function(){n.pushFrame(),n.canvas.width=n.hdr.width*n.getCanvasScale(),n.canvas.height=n.hdr.height*n.getCanvasScale(),n.playerInit(),n.loading=!1,n.ready=!0,n.loadCallback&&n.loadCallback(n.gifImgElement)}},e)this.options[i]=e[i];this.onEndListener=e.onEnd,this.loopDelay=e.loopDelay||0,this.overrideLoopMode=null!=e.loopMode?e.loopMode:"auto",this.drawWhileLoading=null==e.drawWhileLoading||e.drawWhileLoading}return n.prototype.init=function(){var t=this.gifImgElement.parentNode,e=document.createElement("div");this.canvas=document.createElement("canvas"),this.canvasContext=this.canvas.getContext("2d"),this.tmpCanvas=document.createElement("canvas"),e.className=this.options.enclosingClass||"super-gif",e.appendChild(this.canvas),t&&(t.insertBefore(e,this.gifImgElement),t.removeChild(this.gifImgElement)),this.initialized=!0},n.prototype.loadSetup=function(t){return!this.loading&&(t&&(this.loadCallback=t),this.loading=!0,this.frames=[],this.clear(),this.disposalRestoreFromIdx=null,this.lastDisposalMethod=null,this.frame=null,this.lastImg=null,!0)},n.prototype.completeLoop=function(){this.onEndListener&&this.onEndListener(this.gifImgElement),this.iterationCount++,!1!==this.overrideLoopMode||this.iterationCount<0?this.doStep():(this.stepping=!1,this.playing=!1)},n.prototype.doStep=function(){if(this.stepping=this.playing,this.stepping){this.stepFrame(1);var t=10*this.frames[this.currentFrameIndex].delay;t||(t=100),0===this.getNextFrameNo()?(t+=this.loopDelay,setTimeout(this.completeLoop.bind(this),t)):setTimeout(this.doStep.bind(this),t)}},n.prototype.step=function(){this.stepping||setTimeout(this.doStep.bind(this),0)},n.prototype.putFrame=function(){var t;this.currentFrameIndex=parseInt(this.currentFrameIndex.toString(),10),this.currentFrameIndex>this.frames.length-1&&(this.currentFrameIndex=0),this.currentFrameIndex<0&&(this.currentFrameIndex=0),t=this.frameOffsets[this.currentFrameIndex],this.tmpCanvas.getContext("2d").putImageData(this.frames[this.currentFrameIndex].data,t.x,t.y),this.canvasContext.globalCompositeOperation="copy",this.canvasContext.drawImage(this.tmpCanvas,0,0)},n.prototype.playerInit=function(){this.loadErrorCause||(this.canvasContext.scale(this.getCanvasScale(),this.getCanvasScale()),this.options.autoPlay?this.step():(this.currentFrameIndex=0,this.putFrame()))},n.prototype.clear=function(){this.transparency=null,this.delay=null,this.lastDisposalMethod=this.disposalMethod,this.disposalMethod=null,this.frame=null},n.prototype.parseStream=function(e){try{new t.SuperGifParser(e,this.handler).parse()}catch(t){this.handleError("parse")}},n.prototype.setSizes=function(t,e){this.canvas.width=t*this.getCanvasScale(),this.canvas.height=e*this.getCanvasScale(),this.tmpCanvas.width=t,this.tmpCanvas.height=e,this.tmpCanvas.style.width=t+"px",this.tmpCanvas.style.height=e+"px",this.tmpCanvas.getContext("2d").setTransform(1,0,0,1,0,0)},n.prototype.drawError=function(){this.canvasContext.fillStyle="black",this.canvasContext.fillRect(0,0,this.hdr.width,this.hdr.height),this.canvasContext.strokeStyle="red",this.canvasContext.lineWidth=3,this.canvasContext.moveTo(0,0),this.canvasContext.lineTo(this.hdr.width,this.hdr.height),this.canvasContext.moveTo(0,this.hdr.height),this.canvasContext.lineTo(this.hdr.width,0),this.canvasContext.stroke()},n.prototype.handleError=function(t){this.loadErrorCause=t,this.hdr={width:this.gifImgElement.width,height:this.gifImgElement.height},this.frames=[],this.drawError()},n.prototype.doHdr=function(t){this.hdr=t,this.setSizes(this.hdr.width,this.hdr.height)},n.prototype.doGCE=function(t){this.pushFrame(),this.clear(),this.transparency=t.transparencyGiven?t.transparencyIndex:null,this.delay=t.delayTime,this.disposalMethod=t.disposalMethod},n.prototype.pushFrame=function(){this.frame&&(this.frames.push({data:this.frame.getImageData(0,0,this.hdr.width,this.hdr.height),delay:this.delay}),this.frameOffsets.push({x:0,y:0}))},n.prototype.doImg=function(t){var e=this;this.frame||(this.frame=this.tmpCanvas.getContext("2d"));var n=this.frames.length,i=t.lctFlag?t.lct:this.hdr.gct;n>0&&(3===this.lastDisposalMethod?null!==this.disposalRestoreFromIdx?this.frame.putImageData(frames[this.disposalRestoreFromIdx].data,0,0):this.frame.clearRect(this.lastImg.leftPos,this.lastImg.topPos,this.lastImg.width,this.lastImg.height):this.disposalRestoreFromIdx=n-1,2===this.lastDisposalMethod&&this.frame.clearRect(this.lastImg.leftPos,this.lastImg.topPos,this.lastImg.width,this.lastImg.height));var s=this.frame.getImageData(t.leftPos,t.topPos,t.width,t.height);t.pixels.forEach(function(t,n){t!==e.transparency&&(s.data[4*n+0]=i[t][0],s.data[4*n+1]=i[t][1],s.data[4*n+2]=i[t][2],s.data[4*n+3]=255)}),this.frame.putImageData(s,t.leftPos,t.topPos),this.ctxScaled||(this.canvasContext.scale(this.getCanvasScale(),this.getCanvasScale()),this.ctxScaled=!0),this.drawWhileLoading&&(this.canvasContext.drawImage(this.tmpCanvas,0,0),this.drawWhileLoading=this.options.autoPlay),this.lastImg=t},n.prototype.doNothing=function(){},n.prototype.withProgress=function(t){return function(e){t(e)}},n.prototype.getNextFrameNo=function(){var t=this.forward?1:-1;return(this.currentFrameIndex+t+this.frames.length)%this.frames.length},n.prototype.stepFrame=function(t){this.currentFrameIndex=this.currentFrameIndex+t,this.putFrame()},n.prototype.getCanvasScale=function(){return this.options.maxWidth&&this.hdr&&this.hdr.width>this.options.maxWidth?this.options.maxWidth/this.hdr.width:window.devicePixelRatio||1},n.prototype.play=function(){this.playing=!0,this.step()},n.prototype.pause=function(){this.playing=!1},n.prototype.isPlaying=function(){return this.playing},n.prototype.getCanvas=function(){return this.canvas},n.prototype.isLoading=function(){return this.loading},n.prototype.isReady=function(){return this.ready},n.prototype.isAutoPlay=function(){return this.options.autoPlay},n.prototype.getLength=function(){return this.frames.length},n.prototype.getCurrentFrame=function(){return this.currentFrameIndex},n.prototype.moveTo=function(t){this.currentFrameIndex=t,this.putFrame()},n.prototype.loadURL=function(t,n){var i=this;if(this.loadSetup(n)){var s=new XMLHttpRequest;s.open("GET",t,!0),"overrideMimeType"in s?s.overrideMimeType("text/plain; charset=x-user-defined"):"responseType"in s?s.responseType="arraybuffer":s.setRequestHeader("Accept-Charset","x-user-defined"),s.onloadstart=function(){i.initialized||i.init()},s.onload=function(){if(200===s.status){var t=s.response;t.toString().indexOf("ArrayBuffer")>0&&(t=new Uint8Array(t));var n=new e.SuperGifStream(t);setTimeout(function(){i.parseStream(n)},0)}else i.handleError("xhr - response")},s.onerror=function(){i.handleError("xhr")},s.send()}},n.prototype.load=function(t){this.loadURL(this.gifImgElement.src,t)},n}();return Bg.SuperGif=n,Bg}();const Xg={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"image-selector",label:"src",name:"src"},{type:"checkbox",label:"play",name:"play"}],"value-property":"src",help:"scene/component/gif-view"};class Kg extends Fg{async oncreate_element(t){const{src:e,play:n}=this.state;this.onchangesrc(e),this.onchangeplay(n)}buildImg(){const t=this.element;if(!t)return document.createElement("img");t.replaceChildren();const e=document.createElement("img");return e.style.width="100%",e.style.height="100%",t.appendChild(e),e}onchange(t,e){super.onchange(t,e),"src"in t&&this.onchangesrc(t.src),"play"in t&&this.onchangeplay(t.play)}setElementProperties(t){}onchangeplay(t){const e=this._superGif;e&&e.isReady()&&(t?e.play():e.pause())}onchangesrc(t){const e=this.buildImg();t||(t="data:image/gif;base64,R0lGODlhYABIAPcAAAAAAAEBAQICAgMDAwQEBAUFBQYGBgcHBwgICAkJCQoKCgsLCwwMDA0NDQ4ODg8PDxAQEBERERISEhMTExQUFBUVFRYWFhcXFxgYGBkZGRoaGhsbGxwcHB0dHR4eHh8fHyAgICEhISIiIiMjIyQkJCUlJSYmJicnJygoKCkpKSoqKisrKywsLC0tLS4uLi8vLzAwMDExMTIyMjMzMzQ0NDU1NTY2Njc3Nzg4ODk5OTo6Ojs7Ozw8PD09PT4+Pj8/P0BAQEFBQUJCQkNDQ0REREVFRUZGRkdHR0hISElJSUpKSktLS0xMTE1NTU5OTk9PT1BQUFFRUVJSUlNTU1RUVFVVVVZWVldXV1hYWFlZWVpaWltbW1xcXF1dXV5eXl9fX2BgYGFhYWJiYmNjY2RkZGVlZWZmZmdnZ2hoaGlpaWpqamtra2xsbG1tbW5ubm9vb3BwcHFxcXJycnNzc3R0dHV1dXZ2dnd3d3h4eHl5eXp6ent7e3x8fH19fX5+fn9/f4CAgIGBgYKCgoODg4SEhIWFhYaGhoeHh4iIiImJiYqKio+Pj5iYmKCgoKampqurq66urrCwsLGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrOzs7S0tLa2tre3t7m5ubu7u7+/v8DAwMHBwcPDw8XFxcfHx8vLy8/Pz9LS0tXV1dfX193d3eTk5Onp6fj4+Pz8/P7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v///////////////////////////////////////////////////////////////////////////////yH5BAkAAPUAIf47R2VuZXJhdGVkIGJ5IGpzZ2lmIChodHRwczovL2dpdGh1Yi5jb20vYW50aW1hdHRlcjE1L2pzZ2lmLykALAAAAABgAEgAAAj+AGcJHEiwoMGDCBMqXMiwocOHECNKnEixosWLGDNq3Mixo8ePIEOKHEmypMmR9VKqXMmypcuXMGPKnJkSIs2bOHPqZGlzp8+fQOv1DEq0KMyhRpMmRaq0KVCmTqPmhCq1qkyqLrFRSyYwGTVsVo1iZXmNa8Fk18ISHasSm1mDycCq/ck2JTWF1ObSfTjz7cFken3WFbow8M7BDA3rHOwXruKpfGXeTZg3qDVrUge7RRg3KLZjx+Q2HVyvLNy0QaMJjBaVdD2tZr2K/mmNIObRkR+n9AsYt0Pddg1WXppb8bWDx1CLLW74GcJnSl3TtDY8Zu2Et4tKl7n52eyWnxXvhl7+26jqrspbnlfIWjtz2gWPZV95neH8veU9NxZYfbfD3kFt99J6Bnmn0mQO9XfYezrVxxlmx0GUXIAM4hSeffsxBN1TFd5E4Ef3QZbfTg6CNJ5gHXJ3TEntLThiTh+KFCJNAqZU4kgAitjQTheepOBMNcZI0oQ6JpbTjSZtiNN2PZ400IxHpdiSc07G911M0iFZZYtAStnWilUeBGVLrlEZpmM0elmPlmfO8iOZXl4DZpsGEYmll2bSWWCXLwJXVY1+urhjoGEBSuiSah6K36CKtpZoo4s9CimielZq6aWYZqrpppx26umnoIZ6UkAAOw=="),e.src=t,e.setAttribute("rel:animated_src",t),e.setAttribute("rel:auto_play",String(0)),this._superGif=new qg.SuperGif(e,{autoPlay:!1}),this._superGif.init(),this.element&&Array.from(this.element.children).forEach(t=>{t.style.width="100%",t.style.height="100%"});const n=this._superGif.getCanvas();n.style.width="100%",n.style.height="100%",this._superGif.load(()=>{setTimeout(()=>{this._superGif.moveTo(0),this.play&&this._superGif.play()},100)})}ondropfile(t,e){for(let n=0;n<t.length;n++)if(/\.gif$/.test(t[n].name))return void(this.src=e[n])}get src(){return this.getState("src")}set src(t){this.set("src",t)}get play(){return this.getState("play")}set play(t){this.setState("play",t)}get nature(){return Xg}get tagName(){return"div"}}Cc.register("gif-view",Kg);const Qg={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"attachment-selector",label:"src",name:"src",property:{category:"audio"}},{type:"checkbox",label:"started",name:"started"},{type:"checkbox",label:"loop",name:"loop"}],"value-property":"src",help:"scene/component/audio"};class Zg extends(Oc(Tc)){static get image(){return Zg.IMAGE||(Zg.IMAGE=new Image,Zg.IMAGE.src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAZAAAAGQCAMAAAC3Ycb+AAAAP1BMVEUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACzJYIvAAAAFHRSTlMA8BAwgNBgQKB/wCBwUJDg37CvXyUlBK8AABFYSURBVHja7NsBkqIwFIThTiAQgyBq3/+sm6p1tnamZkaTMhJJf1f4S/JeEIiIiIiIiIiIiIiIiEhD7Hg4BH84TpAKjJ4f3NFCtjVd+InXz2RTs+FXlxGylYHfcVfIJmb+YFWSLUyGVJKKBJJKUo+Rd6w63l/qzLuCkryO5fe0l2xk5mMWbe+v0fNBRqf7S3je6CipQ2ACr+dWcYEpzBFS1plpguatsnomMgdIQSOTuQ5SjmE6/UgK8szgdJIUM/FG41YlFmYJ2kkKsY5ZzAwBurHDk3WGeRY0bvYrGa1+rqNI22f7dS32ZnUK1GMr0eSK3mEc9dhKMxp+ZTo8kT2emOXS5LQ1kCxbJBocSd2k5PaIjMVzjWcdJPk9ooBnmzx1t5XbIxqBKpJ4NGTgzwKiGpK4do72gb+ZUMIYtCPm9WCPMsYTE5k2hq2ZvzujlCE1iRmwf3dvmRyKsT0T7b9I7HEPCpqCiqT2IIqaT1pI0noQZdlFC8l/PbYPAnRORT56VBEE6FXkb49agmByKhJ71BME6FsvEntUFQTdqekisUdlQWCXhovEHtUFAWbTapHYo8YgmFybO3vsUWcQYGmxSOxRbRAMprkisUfFQVKmrX18sxt7VB0ENjT1xir2qDxIwkFi3v89e+xRfxAMzfzzIfZ4hyAYDR9zwVuLPd4jCDrTwoLYGb5LEFi3/+E3rweR6urX20c/Fvls2Pvwm9mDSGIPhv8YPyGf3/eo9Ye7O8B2FIShAAooakEttex/rbODad5/yTHIAjqn505IQPv+Xz06dz+4VXORHEZcgAcB8updM8F6e25jBzwIkE07l+x8amMnPDp6nsNJ+BoZ7Q6F8egqAda9VEuRNlZjBzwYkMskdXR73okd8GBAJiKYjBcZKKqG9OiKDbgdfxJ5VhsBPDiQZhaouD3p4hfw4EAmwxisz3MSHwAPEmQ1TB1N+SmXWoAHC7JbZsWl/IxLLcCDBplNo3lrfMLsmwAPGmShAxX5/1vOEzjEz3iyfQ/hI36W4TctsUesOAifPdrQg8M++KYl95iCBkjI1r8634betBAPHZDTPFAmD3zLiHgogVTziMsahz0eIh5aIGHGRSJ2mFtHPR4iHhQIP2UvWGMf8wk74qEIEib7rLjPiBfxiAcCwp8V+Nae3uMdRhAPDIR/J5f/Q2DTcC+hIB7qIGEq3Ti9bx+sryMeAAgS70OK8G2kBD8L8QBAoLWU3g3vUVIc6D0txAMAsY+4jBWowXHO64gHBGKfYJ2T5qY1BxcL98BB+PQ+XiS9xxh9EQ8ChA6C5UXWIUoE9MBB8LVHQoS7ib8/dRn3sAcJ6bQRSdH96RDxIEH4QEX+AHF4LxHEAwUh12xyr1V8lwjiQYDYF8kuf1jluUQQDwrEvkhW8Wc6LhHUgwfhi4QPlHm7LRHawx4kpE191Dq8lgjhAYDQa1cftYrPEiE8OJDb40uqyzdQCA8WhAzL4G/PT4c3WrgHD2IfllGl53V37zsgHg5ApPNvVvq4Fn4spx4oiH1W3CwtEV+PDhEPJyBSkVX4aa7emkM83ICEKWpGM7wdvYCCeDgCEYpcwhLxczhEPFyBCEUWnRL5T6X59SBASBF+9l28TL5F7uEORCZyCUvEx+S7yT0cgoRVb9JaXLR1qUdfgksQ0fTbgmhFB20d8HAKEha14+F8f1sHPNyCiL6EqK+n20/rgIdjkFC0Ho1s6Gndvcc9ICkr/ey8/rHO6vp9KawL8DAFOV6l9Fyub7IbflsCag1qRfVsXWvxHjxIejU+BHZV6uvHD1XiEb++Bw8i+dNd+Wv0eCQmhcPhRPwUUt2DB5G1sfa1aeyzAuyJj9x2HjyIdKzIKw5SI14ieFtvo3kIQERj3lVhkUOnRD7AnjV5369QkAOJZeCH+Jh41xOLs73dQwAifY6dpxCCbjTDzLf1Bm1Y93tAIDOWXcLPvrHyr2hVoEAceEAgDQzB4jetk0/c2OXRHB48EJCpa4dgpYh2ETxtrshz7zx4ICCzfuTSDn8p/EOS9OTjwgMB+cABP3yWYuOPIofs33LigYCULlpZNXJppVU30Vf14kGAUCLijf1D71lN9FW9eFiA9KgZ8FPpPUsSnufGA+8hvAg2Kpz0nrX//qp+PIgpC3i6xJRITOye9fn1VT15ICCrVlQG5rywo0H8x965bVkNwmCYQ2kR6Gmb939WXV65dFnI/tPdjPBfO7XMN4EkTUJtqZp4sCJ1+8jwkhMu0KpMxFXFA8hlVfQSMxGH5mDK1VKV8QCyvTVtUiYyo7V358VStfGoAEFMhGYhEwloxZy9WKo2Hjwg5iSOvFDXeUYd33+PuVfHgwnEBWLocDJp+IIa2fyvperjwQRiXCKGosyXqoA+YfsIELuYu4HAt+msMknfDK4jfQJIzOZ2IPAQWJtFOhQKivR2IDZ6Awis7V0iLxqBI7uEZo19dakTogLSwKvf8yk8Jq6CGK0GKvWlatG7b7kkUU/Lo1gdXWn7/4E0j0qeJDpqN/ABqQcgJgdqURb4chjQktIugDS6wFFiz3JgaJj7AGJmholAe9YKhoZLJ0Ca6smjwJ4VwVN96gVIE5GM71kHaGKxGyAtRDaB2NBhLVmpHyANRKzDO28W7FS3HQFpaIWa8TrfCXQwegJSL5k+8M9UJ+pm9QTEnCIZrR0MDQeQ9ua0iCcYQaBTV0CqNXQW/yiyYG7W1heQanPaCkciBXuH1BkQJzHcDQxmpgGkPatl4WkbCXO/bW9AqlNg4H0PPMi6A1IxkQmOZ8D0ousNSMVEEuyreTAQ6Q7IRJeCX2YZQHhv6SrBOmpkM+YUzN0BqSRQCupmTeCP9wdkhiOREwtEzgGEsWcF9BhK9R8fQDiN7A8DiR0CKXQlj/q9IM8OgXjIzcKBlAHkD6FulgNzJwPIHwpo8mQAkX3LiPq9dKUMAQk9AqmcqmjuBAJCPQIpA4guIAsKJA0gnwNy3A4kDyBIHCEPxAwgf8gPILqA5AFEF5CxZX0lIHYc6rqADLf380BmFMgxgIzUyf8MJKLTRelKHgKy9wgkjfS7LiA0gKgC8vQn3HUA4RQ5LKPIAQciWbqIEg0YkLNDIHYUyqkCsmKN5vg3+W0AYTRATaPY+uu1IwS6UMGAlO6AFPjSCQMStaNh53cdcPG7Hx1Uupo+rx+Bltn1BuTAj5BptEV/bHAAwbnJMICwRmtUDOSEA8s4Rmtw3nITGD6TwUNoG0Ca7xi2YKSPj2eKXQFxQWKA2QbGMWEMMGseOb7C7T47uJS1JyAzVbTjqZdU3zbHzMXWS+qp4Fgn8Ahy/QCRGqQcwU1vGnN7fylboWn8Bzg//hyjxltvdcl45bwFfYKzFyBy11UU9BnjuoqfWizVlQXulpzBTNbaB5Aid+VRrkBFB630AMS9BC8FK2ggE7u/FGy1kvfcB9TKQufX5uUXNWl3EjvWCi4k/u9A3Ddq1CpTIQGe6VN1qd8ArcvDQNw3S41Kn6qQmOq5e7pRr+8fAYLiIJtFrrvYRMYL0q06vj8EZLXUriJzRY8H1xEagOCK7gkghRg6RQYO0I6aWPwIEAru80AiMWSdzAeuDXUKyr+WqpAID8hMHC1Ct8F4mUsQ6W8pJMICki0JHCBczAFdBl38G3VE6ErQhhWlih4LWrCSLpaqjggHiGe9mVjRY0YPoelyqcqIcIDEe97rqJFFH7FcLlUZEQ6Qg5plvZiBFNhtri1VFREGEC/Eg4nZoU5vqi1VFREGkIXDQ8xAIhzoT/WlKiLCAFIYPOQMxOPdjfWlKiLCADJRm3YGj+pDE2xktmmpaogwgMz8d8GrumZ4xzpbvinqISJ+hiTWm7wEqoJdI9JEV9JChAEkS3xCZzKecLcgN6YwlRBhAGmweTsblg6qKMM7Vmh321UQ4QAp1VfwhqVJIh+Wm03W0qV0EOEAybXtivkCmWrKeH2EZ/xBaSBCV2L9Re+LYSqJJIxDu1ew07U0EGEBcTtmHty4JuPtQhvLh1BAhK7Uvvq0GK484QZST0GvvFDqeSJ1IA0r2mfDljvqBoJ//rVsq7yZCA6kXgVkJ2f4ijIGMjOfMVsCBBORB2Jy+sM6ijNvaBUqmw/cStZ8EiKciHwp6Rp++88qmxXQeTUxDiJWJ9wSISvBicgXW+dypn1PqWTznlwgwdZdfiLHr5OELEAEASKvJFRE5JCPKbh8OxHdQKJU0crEzRXrJ/IEkFms6tGyrUw9kQeALFRXvK2iSzsRAAi6BLxM+60xdsqJAEBuXMAMxDLVp+gmAgC57/UT4qvVj3TVRCAgSAYL91aXtyNLzUQAIFhAiP8m0/NHOp+ILiBtPFKrs6bgSOcT0QTEB8nO3QR1yKslggKRf+m11UB0HOl8IlqAeCvauXuo8HnfIqIDyCw6G8XMcGiplMingMzCnbuHFp/3LSLPA4nUpqm5YkWNzwsQeQxIDsKjH5wVSU5qJPIJIIt4jjpqNBAekQeBfJOeHWS81FQoo4/I7UDcS3wUh0liTzLqiEgDqddx4ZHDrNZAACIAEMw88HPYWb0GAhABgEDmgf9Vb5oNBCByOxD3uqWYbCHVBgIQuRlIsbfwMEG5gQBE7gSyHMDsOayrxJvHBRC5B0hOxJH1nK4SlUE6QOR+IG6ju3iYQEqDdIDIzUDyZu/jMRHpS/OiRG4FkiPRfTw8kbrvIAJEACAIDpyHC1/GQHhEbgKSXwTyqIeEur6kixEBgABHOTr7YSX1MSFAhA0E307wUU76Y0KACAsI/tvCRzkF+iIuL0AEAYLbR2QOfvhKJ/obRESBxNt5rPSFXN4f7dyNdqMgEIbhAXWwJErT/e7/Wreb5HTT07QVgWSAeW5g7b4n8qOSUCRPEId4HP93SXp5dDNGRJFcQTxihSH+NW1Bb1cXKpIryJAwnG/zhl8ZcSP6jiKZghwRaaWLnP/AkcSKKJIniEcUs8QfjFLdEmRvkSxB4lfn0QN6DY+lshQpHiT96Dlr6r5hxRUpHST9ZEY71X7DOmOZQVZLsd5Q8wzrPxYYJDiKNqOBG1ZCkZKzrNXu6lHvkjChSFqQsdTPg45ApXtYaUXKr9TNuPcvqO2pVMkitFXAL2a79/qr3HQvVSTXUtofCl79RDXh5CDpw3pwu6+9kRlvtiI5VtPhmHLltT4EKVQkfb8pcOHrXqk6nBAksUjgpKtuYsskaxGKYT0+84uYgziE4YQgMdx0m8PRfis2MbL33PMXoVjD6PEunI4HSjDjStiJP08vQk9hZzQ7oH/geoLYCUBDW4rf4FqCDFt7THUO6B+4jiDn2XNTW7zf4hqCMND4BOsGyw+yAmh0x+QeFh7EeqD5Ce8nLDrI8NpbDyIWHIQNruo4GyAPlhrEzuixBxHLDDJMnfYgYolBricHNfjIdgMWF+Qyu+pkgX4HCwuymL57ELGkIHZG7z2IWE6Q5VV7vGMhQewbtMcZiwhyHj26ne9+xs8PcvDQHnFFqCD7Au0RW4TK+fOKqw4eoOcqYqgU53HR3/5uShFPCfKey9hFDyJO/vAi7RDZnp7X5igyUH72xSDW1E2Pn4tMRCQgR8vLwbgii4gcmLvqQcSPGtIPX3M08wn6I4qYQ94cM/Yw9Xxhmw+X/59wHrtMlX1AmIkzdyaaAnLg1Nnw8WGYSk40X/BOh4+El6LMSBnN2Cd0tPq4w/LJXGrMbCX06PZ2dcM65yzlNertShSHf3SzRAyPM332IcSAHUKPi8EHmXU0l8Uglmni0yipDoi16s+jJKejhywLooz68yiMEcHr2qM4h81CJ++VPJfTu5UwBpv4Pp9DJSi6MJx0bvUwiw4ewgT8zNR0LHUL+OccOpY/3ElzyGKD5pBlMJpDlsOkMythRoNbXh95PJsdA67MrMtAEYbjeDqNo+7oKqWUUkoppZRSSimllFJKFfMXp4vmSjB8n6sAAAAASUVORK5CYII="),Zg.IMAGE}dispose(){super.dispose(),this.started=!1,delete this._audio}async ready(){super.ready(),this._audio=new Audio;const{src:t="",loop:e=!1,started:n=!1}=this.state;if(t){const e=this.root?.app?.loadTracker;if(e){const n=new Promise((e,n)=>{this._audio.addEventListener("canplay",()=>e(),{once:!0}),this._audio.addEventListener("error",()=>n(new Error(`Audio load failed: ${t}`)),{once:!0})});e.track(`audio:${t}`,"audio",t,n)}}this._audio.addEventListener("canplay",()=>{this.started&&this._audio.play()}),this.onchangeSrc(t),this.onchangeLoop(e),this.onchangeStarted(n)}render(t){const{left:e,top:n,width:i,height:s}=this.state;t.beginPath(),this.drawImage(t,Zg.image,e,n,i,s)}get nature(){return Qg}get hasTextProperty(){return!1}get src(){return this.get("src")}set src(t){this.set("src",t)}get started(){return!!this.get("started")}set started(t){this.set("started",t)}start(){this._audio&&(this._audio.classList.add("active"),this._audio.play())}pause(){this._audio&&(this._audio.classList.remove("active"),this._audio.pause())}onchangeSrc(t){try{"data"!==String(t).substring(0,4)?this._audio.crossOrigin="use-credentials":this._audio.crossOrigin=null,this._audio.src="string"==typeof t?this.app.url(t):t}catch(t){return void Qi(t)}}onchangeStarted(t){const e=this._audio;t?4==e.readyState&&e.play():e.pause()}onchangeLoop(t){this._audio.loop=t}onchange(t,e){"src"in t&&this.onchangeSrc(t.src),"started"in t&&this.onchangeStarted(t.started),"loop"in t&&this.onchangeLoop(t.loop)}ondblclick(t){this.started=!this.started}ondropfile(t,e){for(let n=0;n<t.length;n++)if(t[n].type.startsWith("audio/"))return void(this.src=e[n])}}Cc.register("audio",Zg);class Jg extends(Oc(Cc)){is3dish(){return!0}}Cc.register("text",Jg);const ty=["refid","left","top","width","height","rotation","animation","zPos"];class ey extends ng{isGroup(){return!0}is3dish(){return!0}get showMoveHandle(){return!1}get(t){return this._model[t]}set(t,e){if("string"==typeof t)return this.set({[t]:e});const n=ty.reduce((e,n)=>(t.hasOwnProperty(n)&&(e[n]=t[n]),e),{});return super.set(n,void 0)}capture(t,e,n){const i=super.capture(t,e,n);if(i!==this)return i}set bounds(t){if(this.__MUTATING__)return void(super.bounds=t);const e=this.bounds,n=t.width/e.width,i=t.height/e.height;this.path=this.path.map(s=>({x:t.left+(s.x-e.left)*n,y:t.top+(s.y-e.top)*i})),this.components&&this.components.forEach(t=>{if(t.mutable)t.mutatePath(null,function(t){return t.map(function(t){return{x:t.x*n,y:t.y*i}})});else{const e=t.bounds,s=t.center,r={x:s.x*(1-n),y:s.y*(1-i)},o=e.width*(1-n),a=e.height*(1-i),c=-(r.x-o/2),l=-(r.y-a/2);t.bounds={left:e.left+c,top:e.top+l,width:e.width*n,height:e.height*i}}})}get focusible(){return!1}get bounds(){return super.bounds}get hasTextProperty(){return!1}isIdentifiable(){return!1}calculateBounds(){this.clearCache(),this.__MUTATING__=!0,this.mutateBounds(function(t){const e=Cc.union(this.components.map(t=>t.bounds));return this.components.forEach(t=>{const n=t.bounds;t.bounds={left:n.left-e.left,top:n.top-e.top,width:n.width,height:n.height}}),{left:t.left+e.left,top:t.top+e.top,width:e.width,height:e.height}},this),this.__MUTATING__=!1,this.parent.isGroup()&&this.parent.calculateBounds?.()}render(t){}postrender(t){const{top:e,left:n}=this.state;t.translate(n,e),this.layout.drawables(this).forEach(e=>{e.draw(t)}),t.translate(-n,-e)}}Cc.memoize(ey.prototype,"bounds",!0),Cc.register("group",ey);const ny={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"id-input",label:"ref",name:"ref"},{type:"select",label:"fit",name:"fit",property:{options:["","both","ratio"]}}],"value-property":"ref",help:"scene/component/local-ref"};class iy extends(Oc(Tc)){get ref(){const t=this.getState("ref");return t&&"string"==typeof t?this.root.findById?.(t):null}set ref(t){this.setState("ref",t)}get refScale(){const t=this.ref;if(!t)return{x:1,y:1};const e=t.bounds,n=this.bounds,i=n.width/e.width,s=n.height/e.height;return"both"===this.model.fit?{x:i,y:s}:{x:Math.min(i,s),y:Math.min(i,s)}}draw(t){this._drawing||(this._drawing=!0,super.draw(t),this._drawing=!1)}prerender(t){if(super.prerender(t),this.ref){const e=this.ref.center,n=this.center,i=this.refScale;t.translate(n.x,n.y),t.scale(i.x,i.y),t.translate(-e.x,-e.y)}}postrender(t){if(this.ref)return this.ref.postrender(t);super.postrender(t)}render(t){if(this.ref)return this.ref.render(t);const{left:e,top:n,width:i,height:s}=this.bounds;t.beginPath(),t.rect(e,n,i,s)}get nature(){return ny}get hasTextProperty(){return!1}}Cc.memoize(iy.prototype,"ref",!1),Cc.memoize(iy.prototype,"refScale",!1),Cc.register("local-ref",iy);class sy extends(Qm(Jl)){render(t){}is3dish(){return!0}get layout(){return Lc.get(this.get("layout"))||Fc}}const ry={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"board-selector",label:"scene-number",name:"ref",placeholder:"SCENE-1"},{type:"number",label:"round",name:"round",property:{min:0}},{type:"select",label:"fit",name:"fit",property:{options:["","both","ratio","width","height","none"]}},{type:"select",label:"mode",name:"mode",property:{options:["view","interaction"]}}],"value-property":"ref",help:"scene/component/global-ref"};class oy extends sy{dispose(){this._releaseRef(),super.dispose()}get nature(){return ry}get hasTextProperty(){return!1}get tagName(){return"div"}setElementProperties(t){const{mode:e="view",round:n=0}=this.state;t.style.pointerEvents="view"==e?"none":"inherit",t.style.borderRadius=n+"px"}async ready(){super.ready(),this.fetchRef()}reposition(){if(!this.element)return;super.reposition();const t=this._element_bounds,{offsetWidth:e,offsetHeight:n}=this.element;if(this._element_bounds={offsetWidth:e,offsetHeight:n},(!t||t.offsetWidth!=e||t.offsetHeight!=n)&&this.ref&&this.root.target_element){const{fit:t="ratio"}=this.state;this.ref.fit(t)}}async fetchRef(){this._releaseRef();const{ref:t,fit:e="ratio"}=this.state;if(!t)return;const n=this.app.refProvider;if(n&&t){const i=(async()=>{this.__ref=await n.get(t,!0),this.__ref.target=this.element,this.__ref.fit(e),this.__ref.data=this.data})();this.root?.app?.loadTracker?.track(`ref:${t}`,"ref-board",t,i);try{await i}catch(t){Qi(t)}}}get ref(){return this.__ref}set ref(t){this.setState("ref",t)}_releaseRef(){this.__ref&&this.__ref.release&&this.__ref.release(),delete this.__ref}onchange(t,e,n){super.onchange(t,e),"ref"in t&&this.fetchRef(),"fit"in t&&this.ref&&requestAnimationFrame(()=>{const{fit:t}=this.state;this.ref.fit(t)}),"data"in t&&this.ref&&requestAnimationFrame(()=>{this.ref.data=t.data})}}Cc.register("global-ref",oy);const ay="center-middle",cy={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"board-selector",label:"board",name:"board"},{type:"checkbox",label:"modal",name:"modal"},{type:"checkbox",label:"closable",name:"closable"},{type:"checkbox",label:"draggable",name:"draggable"},{type:"checkbox",label:"minimizable",name:"minimizable"},{type:"checkbox",label:"show",name:"show"},{type:"select",label:"popup-position",name:"popupPosition",property:{options:["static","absolute"]}},{type:"select",label:"popup-origin",name:"origin",property:{options:["left-top","center-top","right-top","left-middle",ay,"right-middle","left-bottom","center-bottom","right-bottom","auto"]}},{type:"string",label:"title",name:"text"},{type:"data",label:"value",name:"value"},{type:"string",label:"container-ref",name:"containerRef",placeholder:"PopupContainer id (same board)"},{type:"textarea",label:"html-template",name:"htmlTemplate",property:{language:"html"}},{type:"string",label:"anchor-ref",name:"anchorRef",placeholder:"component id (3D-tracked anchor)"},{type:"select",label:"anchor-pin",name:"anchorPin",property:{options:[{display:"Top",value:"top"},{display:"Center",value:"center"},{display:"Bottom",value:"bottom"}]}},{type:"number",label:"anchor-offset-x",name:"anchorOffsetX"},{type:"number",label:"anchor-offset-y",name:"anchorOffsetY"},{type:"number",label:"anchor-offset-z",name:"anchorOffsetZ"},{type:"checkbox",label:"constant-size",name:"constantSize"},{type:"checkbox",label:"tether",name:"tether"},{type:"select",label:"off-screen",name:"offScreen",property:{options:[{display:"Hide",value:"hide"},{display:"Edge-pin",value:"edge-pin"},{display:"Keep last",value:"keep-last"}]}}],help:"scene/component/popup"};class ly extends(Oc(Tc)){static get image(){return ly._image||(ly._image=new Image,ly._image.src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEYAAABGCAMAAABG8BK2AAADJmlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPD94cGFja2V0IGJlZ2luPSLvu78iIGlkPSJXNU0wTXBDZWhpSHpyZVN6TlRjemtjOWQiPz4gPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iQWRvYmUgWE1QIENvcmUgNy4xLWMwMDAgNzkuZGFiYWNiYiwgMjAyMS8wNC8xNC0wMDozOTo0NCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIDIzLjAgKE1hY2ludG9zaCkiIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6RkM4QzQxNUMzMzBEMTFFQ0JEMzZDMDUwQUI4MEI3QTAiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6RkM4QzQxNUQzMzBEMTFFQ0JEMzZDMDUwQUI4MEI3QTAiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDpENjlENTQ3RjMzMDkxMUVDQkQzNkMwNTBBQjgwQjdBMCIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDpENjlENTQ4MDMzMDkxMUVDQkQzNkMwNTBBQjgwQjdBMCIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PsiUYSQAAAAZdEVYdFNvZnR3YXJlAEFkb2JlIEltYWdlUmVhZHlxyWU8AAAA51BMVEVHcEwzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzOguTm2AAAATHRSTlMARhB73r9B7YLrsqdE+0cq9Avzeg31eQx4aQ+Ks6aUd5DsYKixEX1w8vyT2VjoZ3YezY/cCEDvl+QTvRwJ0ifwK/5T/aw6+IuFuCImAcS6MQAAAeJJREFUWMPt2FlX2zAQhuHJYmOSFhIggbC0QNn3rS1dKXSH9///Hi58CJLxKIpEWi6YO8c5z4lG/nxGEXmu/1OVLGnhrFaSVQYg1SZetTTvUibqeFZ9QlfmvRWoV1VmCaCRzroXPpsuAjTV7gLUfPahBqD1OQMW/fazAWTKvQRI/ZgUSJR7U8CM/dHZ+/2VcatWdvdEZAaYUhiAwkerJXt0rnzXwdRKmHfDM0fHD5kxjTFyVLzVfvvirn7+cDJWjhy7c7XlYuwc6Urvu2tRhRypyhwAf1sKY+TIxfQA+H39q5wxc+RgVrcBduTmZTlj5khnDgH4IzKpMGaOVCbvyyvRGTNHGtPrKypjXirM5jb910I4k69oQeKY+77EMAcALEsck/+W6f71tyCma/ZFROTrJVwMy7wmf3bv6/MX+Dgkkysblvxps/dhOKZb6IvrTakzXXuPApnpYneDGOeKvJlaSXcDmA7AicQyW84VeTOnY+NdiWcG1uiZksFEHdyAlsJEjEkmkwGNsKHNZCJGSKtVTYC1tO022mnjwUBrMdXg8dreuOBhv7D/62/8lGZ1wLxXyZKOm+iUHIQintyny0TkaATHjYgcjeAoFpEje9R/nGPqIx2aw3NU9odCQI6e6x/VLY32cKQXVBnkAAAAAElFTkSuQmCC"),ly._image}async ready(){await super.ready(),this.show&&this.onchangeShow(!0)}render(t){const{left:e,top:n,width:i,height:s}=this.bounds;t.beginPath(),this.drawImage(t,ly.image,e,n,i,s)}onchange(t,e){"value"in t?this.show?this.onchangeShow(!0):this.show=!0:"show"in t&&this.onchangeShow(this.show)}onchangeShow(t){if(this.app.isEditMode)return;(this.getState("board")||this.getState("containerRef")||this.getState("htmlTemplate"))&&(t?this.openPopup(this.value):this.hidePopup())}openPopup(t,e){if(this.app.isEditMode)return;const n=this.getState("anchorRef"),i=n&&this.rootModel?.findById?this.rootModel.findById(n):void 0;mp.show(this,this.getState("board"),{origin:this.getState("origin")||ay,modal:this.getState("modal"),closable:this.getState("closable")||!1,draggable:this.getState("draggable")||!1,minimizable:this.getState("minimizable")||!1,popupPosition:this.getState("popupPosition"),title:this.text,data:t||this.value,containerRef:this.getState("containerRef"),htmlTemplate:this.getState("htmlTemplate"),anchor:i,anchorPin:this.getState("anchorPin")||"top",anchorOffsetX:this.getState("anchorOffsetX")??0,anchorOffsetY:this.getState("anchorOffsetY")??0,anchorOffsetZ:this.getState("anchorOffsetZ")??0,constantSize:this.getState("constantSize")??!0,tether:this.getState("tether")??!1,offScreen:this.getState("offScreen")||"hide",...e})}hidePopup(){mp.hide(this)}get board(){return this.getState("board")}set board(t){this.set("board",t)}get show(){return this.getState("show")}set show(t){this.setState("show",t)}get started(){return this.getState("show")}set started(t){this.setState("show",t)}get value(){return this.getState("value")}set value(t){this.setState("value",t)}get hasTextProperty(){return!1}get nature(){return cy}}Cc.register("popup",ly);const hy={mutable:!1,resizable:!0,rotatable:!1,properties:[{type:"layout",label:"layout",name:"layoutOption"},{type:"checkbox",label:"constant-size",name:"constantSize"},{type:"checkbox",label:"billboard",name:"billboard"},{type:"checkbox",label:"tether",name:"tether"},{type:"select",label:"off-screen",name:"offScreen",property:{options:[{display:"Hide",value:"hide"},{display:"Edge-pin",value:"edge-pin"},{display:"Keep last",value:"keep-last"}]}}],help:"scene/component/popup-container"};class dy extends ng{get nature(){return hy}isPopupContainer(){return!0}}Cc.register("popup-container",dy);class uy extends Cc{render(t){const{path:e=[]}=this.state;if(!(e.length<=1)){t.beginPath(),t.moveTo(e[0].x,e[0].y);for(let n=1;n<e.length;n++)t.lineTo(e[n].x,e[n].y);t.closePath(),this.drawStroke(t,void 0)}}get path(){return this.model.path}set path(t){this.set("path",t)}contains(t,e){const n=this.state.path;let i=!1;return n.forEach((s,r)=>{const o=(r+n.length+1)%n.length,a=s.x,c=s.y,l=n[o].x,h=n[o].y;c>e!=h>e&&t<(l-a)*(e-c)/(h-c)+a&&(i=!i)}),i}}Cc.register("path",uy);const py={mutable:!0,resizable:!1,rotatable:!0,properties:[{type:"number",label:"round",name:"round",property:{min:0,max:100,step:1}}],help:"scene/component/triangle"};class fy extends Tc{is3dish(){return!0}contains(t,e){const{x1:n,y1:i,x2:s,y2:r,x3:o,y3:a}=this.state,c=[n,i,s,r,o,a];let l=!1;for(let n=0;n<c.length;n+=2){const i=(n+2)%c.length,s=c[n],r=c[n+1],o=c[i+1];r>e!=o>e&&t<(c[i]-s)*(e-r)/(o-r)+s&&(l=!l)}return l}get mutable(){return!0}get path(){const{x1:t,y1:e,x2:n,y2:i,x3:s,y3:r}=this.state;return[{x:t,y:e},{x:n,y:i},{x:s,y:r}]}set path(t){this.set({x1:t[0].x,y1:t[0].y,x2:t[1].x,y2:t[1].y,x3:t[2].x,y3:t[2].y})}get nature(){return py}}Cc.memoize(fy.prototype,"path",!1),Cc.register("triangle",fy);const my={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"number",label:"ratio",name:"ratio",property:"ratio"}],help:"scene/component/donut"},gy={ondragmove:function(t,e,n){let{cx:i,rx:s}=n.model;s=Math.abs(s);let r=(n.fromParent(t.x,t.y).x-i)/s*100;r=r>=100||r<=-100?100:Math.abs(r),n.set({ratio:r})}};class yy extends bg{is3dish(){return!0}render(t){let{ratio:e=50,cx:n,cy:i,rx:s,ry:r,startAngle:o,endAngle:a,anticlockwise:c}=this.state;s=Math.abs(s),r=Math.abs(r),t.beginPath(),t.ellipse(n,i,s,r,0,o||0,a||2*Math.PI,c),t.moveTo(n+s/100*e,i),t.ellipse(n,i,s/100*e,r/100*e,0,o||0,a||2*Math.PI,!0)}contains(t,e){let{cx:n,cy:i,rx:s,ry:r,ratio:o}=this.state;s=Math.abs(s),r=Math.abs(r);const a=(t-n)/(2*s-.5),c=(e-i)/(2*r-.5),l=(t-n)/(s/100*o*2-.5),h=(e-i)/(r/100*o*2-.5);let d=!1;return a*a+c*c<.25&&l*l+h*h>.25&&(d=!d),d}get controls(){let{cx:t,cy:e,rx:n,ratio:i}=this.state;return n=Math.abs(n),[{x:t+n/100*i,y:e,handler:gy}]}get nature(){return my}}Cc.memoize(yy.prototype,"controls",!1),Cc.register("donut",yy);const by={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"number",label:"ratio",name:"ratio",property:"ratio"},{type:"number",label:"wing",name:"wing",property:"wing"}],help:"scene/component/star"},_y={ondragmove:function(t,e,n){const{cy:i,ry:s}=n.model;let r=(n.fromParent(t.x,t.y).y-i)/s*100+100;r>=100?r=100:r<=0&&(r=0),n.set({ratio:r})}};class vy extends bg{is3dish(){return!0}render(t){const{ratio:e=30,wing:n=5,cx:i,cy:s,rx:r,ry:o}=this.state;if(n<3)return;const a=1.5707963267948966,c=2*Math.PI/n,l=r-e/100*r,h=o-e/100*o;t.save(),t.beginPath(),t.translate(i,s),t.moveTo(r*Math.cos(-a),o*Math.sin(-a)),t.lineTo((r-l)*(Math.cos(c-a)+Math.cos(0-a))/2,(o-h)*(Math.sin(c-a)+Math.sin(0-a))/2);for(let e=1;e<n;e++)t.lineTo(r*Math.cos(c*e-a),o*Math.sin(c*e-a)),t.lineTo((r-l)*(Math.cos(c*(e+1)-a)+Math.cos(c*e-a))/2,(o-h)*(Math.sin(c*(e+1)-a)+Math.sin(c*e-a))/2);t.closePath(),t.restore()}get controls(){const{cx:t,cy:e,ry:n,ratio:i}=this.state;return[{x:t,y:e-n+n*(i/100),handler:_y}]}get nature(){return by}}Cc.memoize(vy.prototype,"controls",!1),Cc.register("star",vy);const xy={mutable:!1,resizable:!1,rotatable:!1,properties:[]};class wy extends(nm(Tc)){is3dish(){return!1}isDescendible(){return!1}render(t){const{cx:e,cy:n,anticlockwise:i}=this.state,s=this.app?.scale||1;t.beginPath(),t.scale(1/s,1/s),t.ellipse(e,n,Math.abs(wy.RADIUS),Math.abs(wy.RADIUS),0,0,2*Math.PI,i),t.scale(s,s),t.closePath()}get path(){const{cx:t,cy:e}=this.state;return[{x:t-wy.RADIUS,y:e-wy.RADIUS},{x:t+wy.RADIUS,y:e-wy.RADIUS},{x:t+wy.RADIUS,y:e+wy.RADIUS},{x:t-wy.RADIUS,y:e+wy.RADIUS}]}set path(t){const e=t[0],n=t[2];this.set({cx:e.x+(n.x-e.x)/2,cy:e.y+(n.y-e.y)/2})}contains(t,e){const{cx:n,cy:i}=this.state,s=(t-n)/(2*wy.RADIUS-.5),r=(e-i)/(2*wy.RADIUS-.5);return s*s+r*r<.25}outline(t){const{cx:e,cy:n}=this.state;return this.toScene(e,n)}get nature(){return xy}}wy.RADIUS=5,Cc.memoize(wy.prototype,"path",!1),Cc.register("node",wy);class My extends xu{getObject3dInstance(){return new t.Mesh}build(){super.build();const{width:e,height:n}=this.component.bounds,i=this.component.state.depth||.5*Math.min(e,n),s=.15*Math.min(e,n,i),r=new R(1,1,1,4,s/Math.min(e,n,i));r.scale(e,i,n),this.object3d.geometry=r,this.object3d.material=new t.MeshStandardMaterial({color:"#5090d0",transparent:!0,opacity:.35,roughness:.6,metalness:.1,side:t.FrontSide,depthWrite:!1}),this.object3d.visible=!!this.component.app?.isEditMode}updateAlpha(){const t=this.object3d.material;t&&(t.opacity=this.component.app?.isEditMode?.35:0)}updateHidden(){this.object3d.visible=!!this.component.app?.isEditMode&&!this.component.state.hidden}updateDimension(){const{width:t,height:e}=this.component.bounds,n=this.component.state.depth||.5*Math.min(t,e);this.object3d.geometry.computeBoundingBox();const i=this.object3d.geometry.boundingBox;if(i){const s=i.max.x-i.min.x,r=i.max.y-i.min.y,o=i.max.z-i.min.z;this.setDimensionScale(t/s,n/r,e/o)}}updateFillStyle(){}updateStrokeStyle(){}updateText(){}clear(){return cu(this.object3d),super.clear()}}const Sy="data:image/svg+xml;base64,"+btoa('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" fill="#5090d0">\n <path d="M32 20a12 12 0 1 0 0 24 12 12 0 0 0 0-24zm0 18a6 6 0 1 1 0-12 6 6 0 0 1 0 12z"/>\n <path d="M55.4 27.2l-3.6-.6c-.4-1.2-.8-2.4-1.4-3.4l2.2-3c.6-.8.4-2-.2-2.6l-3-3c-.8-.6-1.8-.8-2.6-.2l-3 2.2c-1.2-.6-2.2-1-3.4-1.4l-.6-3.6c-.2-1-1-1.6-2-1.6h-4.2c-1 0-1.8.6-2 1.6l-.6 3.6c-1.2.4-2.4.8-3.4 1.4l-3-2.2c-.8-.6-2-.4-2.6.2l-3 3c-.6.8-.8 1.8-.2 2.6l2.2 3c-.6 1.2-1 2.2-1.4 3.4l-3.6.6c-1 .2-1.6 1-1.6 2v4.2c0 1 .6 1.8 1.6 2l3.6.6c.4 1.2.8 2.4 1.4 3.4l-2.2 3c-.6.8-.4 2 .2 2.6l3 3c.8.6 1.8.8 2.6.2l3-2.2c1.2.6 2.2 1 3.4 1.4l.6 3.6c.2 1 1 1.6 2 1.6h4.2c1 0 1.8-.6 2-1.6l.6-3.6c1.2-.4 2.4-.8 3.4-1.4l3 2.2c.8.6 2 .4 2.6-.2l3-3c.6-.8.8-1.8.2-2.6l-2.2-3c.6-1.2 1-2.2 1.4-3.4l3.6-.6c1-.2 1.6-1 1.6-2v-4.2c0-1-.6-1.8-1.6-2z"/>\n</svg>');class ky extends(Oc(Cc)){static get icon(){return ky._defaultIcon||(ky._defaultIcon=new Image,ky._defaultIcon.src=Sy),ky._defaultIcon}get serviceName(){}get hasTextProperty(){return!1}is3dish(){return!0}buildRealObject(){return new My(this)}render(t){if(this.app?.isViewMode)return;const{left:e,top:n,width:i,height:s}=this.bounds,r=this.constructor.icon;t.beginPath(),t.globalAlpha=.6,this.drawImage(t,r,e,n,i,s),t.globalAlpha=1}added(t){super.added(t);const e=this.serviceName;e&&(this._registeredRoot=this.root,this._registeredRoot?.registerService?.(e,this))}removed(t){const e=this.serviceName;e&&this._registeredRoot&&(this._registeredRoot.unregisterService?.(e),this._registeredRoot=void 0),super.removed(t)}get controls(){return[]}}function Ay(t){return class extends t{animOnValueChange(t,e=!1,n){if(t==this._lastValue)return;if(this.root?.app?.suppressAnimations)return this._lastValue=t,this._anim_alpha=0,void this.invalidate();let i;i=e?t-(Number(n)||0):t-(this._lastValue||0),this._lastValue=t,this._anim_alpha=-i,this.animate({step:t=>{this._anim_alpha=i*(t-1),this.invalidate()},duration:1e3,delta:"circ",options:{x:1},ease:"out"}).start()}dispose(){super.dispose(),delete this._value_substitutor}onchange(t,e){t.hasOwnProperty("value")&&delete this._value_substitutor}get animAlpha(){return this._anim_alpha||0}get animValue(){return(this._lastValue||0)+(this._anim_alpha||0)}defaultValueSubstitutor(){return this.getState("value")}get valueSubstitutor(){return this._value_substitutor||(this._value_substitutor=$r(this.getState("value"),this,void 0)||this.defaultValueSubstitutor),this._value_substitutor}get value(){return Number(this.valueSubstitutor())||0}set value(t){delete this._value_substitutor,this.setState("value",Number(xi(t)))}}}function Ey(t){return class extends t{_convertDataFormat(t,e){let n;if("json"===e)n=JSON.parse(t);else n=t;return n}isDataSource(){return!0}}}function Cy(t){var e;return(e=class extends t{is3dish(){return!0}get hasTextProperty(){return!1}get capturable(){return!1}render(t){}}).raycastTargetDefault=!1,e.requires3d=!0,e}const Ty="$base_url",Py=[{type:"gltf-preset",label:"preset",name:"preset"},{type:"gltf-selector",label:"url",name:"src",property:{displayField:"id",displayFullUrl:!0,baseUrlAlias:Ty,defaultStorage:"3d-model",storageFilters:{type:Array,value:[{name:"category",value:"image"}]},useUpload:!0,category:"application"},observe:function(t){const e=this.parentNode?.querySelector("[name=gltfInfo]");e&&(e.src=t);const n=this.parentNode?.querySelector("[name=fillStyleTargets]");n&&(n.src=t);const i=this.parentNode?.querySelector("[name=playTargets]");i&&(i.src=t)}},{type:"gltf-info",label:"",name:"gltfInfo",readonly:!0,property:{action:(t,e)=>{t._ratioLocking=!0;try{t.set(e)}finally{t._ratioLocking=!1}}},editor:{fullwidth:!0}},{type:"gltf-fill-targets",label:"fill-targets",name:"fillStyleTargets",editor:{fullwidth:!0}},{type:"gltf-play-targets",label:"play-targets",name:"playTargets",editor:{fullwidth:!0}}];function Oy(t){return class extends t{constructor(){super(...arguments),this._snapshotLoading=!1,this._ratioLocking=!1}is3dish(){return!0}get hasTextProperty(){return!1}get controls(){return[]}render(t){const{left:e,top:n,width:i,height:s}=this.bounds;t.beginPath();const r=this._topViewSnapshot;if(r)return void t.drawImage(r,e,n,i,s);this._ensureTopViewSnapshot(),t.rect(e,n,i,s),t.fillStyle="#f0f0f0",t.fill(),t.strokeStyle="#999",t.lineWidth=1,t.stroke();const o=this.getState("src"),a=o&&o.split("/").pop()?.replace(/\.[^.]+$/,"")||"GLTF",c=Math.max(10,.12*Math.min(i,s));t.fillStyle="#666",t.font=`${c}px sans-serif`,t.textAlign="center",t.textBaseline="middle",t.fillText(a,e+i/2,n+s/2,.9*i)}onchange(t,e){super.onchange?.(t,e),"src"in t&&(this._topViewSnapshot=void 0)}_ensureTopViewSnapshot(){if(this._snapshotLoading)return;const t=this.getState("src");if(!t)return;const e=Cu.getTopViewCache(t);if(e)return this._topViewSnapshot=e,void this.invalidate();this._snapshotLoading=!0;const n=this.app.url(t);Cu.loadGLTF(n).then(e=>{if(this._snapshotLoading=!1,this.getState("src")!==t)return;const n=Cu.getTopViewCache(t);if(n)return this._topViewSnapshot=n,void this.invalidate();const i=Cu.renderTopView(e.scene);Cu.setTopViewCache(t,i),this._topViewSnapshot=i,this.invalidate()}).catch(()=>{this._snapshotLoading=!1})}buildRealObject(){return new Cu(this)}get source(){return this.getState("src")}set source(t){this.setState("src",t)}get play(){return!1!==this.getState("play")}set play(t){this.setState("play",t)}get nodes(){return this.getState("nodes")}set nodes(t){this.setState("nodes",t)}get animations(){return this.getState("animations")}set animations(t){this.setState("animations",t)}get playTargets(){return this.getState("playTargets")}set playTargets(t){this.setState("playTargets",t)}get fillStyleTargets(){return this.getState("fillStyleTargets")}set fillStyleTargets(t){this.setState("fillStyleTargets",t)}get nodeNames(){const t=this.realObject;return t?.nodeNames??[]}get animationNames(){const t=this.realObject;return t?.animationNames??[]}set dimension(t){const{width:e=1,height:n=1,depth:i=1}=t;this.setState({width:e,height:n,depth:i}),this.realObject?.updateDimension()}_applyRatioLock(t){if(!("width"in t||"height"in t||"depth"in t))return t;const e=this.state.width||1,n=this.state.height||1,i=this.state.depth||1,s=Cf([(t.width??e)/e,(t.height??n)/n,(t.depth??i)/i]);return s?{...t,width:Math.round(e*s),height:Math.round(n*s),depth:Math.round(i*s)}:t}set(t,e){if("string"==typeof t&&(t={[t]:e}),this.state?.ratioLock&&!this._ratioLocking){this._ratioLocking=!0;try{t=this._applyRatioLock(t)}finally{}}try{return super.set(t)}finally{this._ratioLocking=!1}}setState(t,e){if("string"==typeof t&&(t={[t]:e}),this.state?.ratioLock&&!this._ratioLocking){this._ratioLocking=!0;try{t=this._applyRatioLock(t)}finally{}}try{return super.setState(t)}finally{this._ratioLocking=!1}}}}function Dy(t){return function(e){return Array.isArray(t)?t.forEach(t=>{Cc.register(t,e)}):Cc.register(t,e),e}}function Iy(t){return!!t&&"function"==typeof t.capacity&&"function"==typeof t.available}function zy(t){if(Iy(t)){const e=t.capacity(),n=t.available();return{capacity:e,available:n,isFull:0===n}}if("function"==typeof t?.slotIds){const e=t.slotIds().length,n="function"==typeof t.emptySlotIds?t.emptySlotIds().length:e;return{capacity:e,available:n,isFull:0===n}}const e=t?.state?.capacity,n=Array.isArray(t?.state?.data)?t.state.data.length:0;if("number"==typeof e){const t=Math.max(0,e-n);return{capacity:e,available:t,isFull:0===t}}return{capacity:1/0,available:1/0,isFull:!1}}class Ry{constructor(){this.wasFull=!1,this.availableListeners=[],this.fullListeners=[]}notify(t){const e=0===t;if(e&&!this.wasFull){this.wasFull=!0;for(const t of this.fullListeners)try{t()}catch(t){}}else if(!e&&this.wasFull){this.wasFull=!1;for(const t of this.availableListeners)try{t()}catch(t){}}}onAvailable(t){return this.availableListeners.push(t),()=>{const e=this.availableListeners.indexOf(t);e>=0&&this.availableListeners.splice(e,1)}}onFull(t){return this.fullListeners.push(t),()=>{const e=this.fullListeners.indexOf(t);e>=0&&this.fullListeners.splice(e,1)}}dispose(){this.availableListeners=[],this.fullListeners=[]}}function jy(t,e){if(!t||!e)return()=>{};if("function"!=typeof t.pauseEmit||"function"!=typeof t.resumeEmit)return()=>{};if("function"!=typeof e.onFull||"function"!=typeof e.onAvailable)return()=>{};const n=e.onFull(()=>t.pauseEmit()),i=e.onAvailable(()=>t.resumeEmit());return zy(e).isFull&&t.pauseEmit(),()=>{n?.(),i?.()}}class Ly{constructor(t,e=1,n="horizontal"){this.owner=t,this.itemSpacing=e,this.axis=n}positionAt(t,e,n,i){const s=e.maxCount??1/0;if(t<0||t>=s)return null;const r=this.owner?.state?.width??0,o=this.owner?.state?.height??0,a=i?.state?.width??0,c=i?.state?.height??0;return"horizontal"===this.axis?{x:t*this.itemSpacing,y:Math.max(0,(o-c)/2),z:0}:{x:Math.max(0,(r-a)/2),y:t*this.itemSpacing,z:0}}capacity(t){return t.maxCount??1/0}}function Fy(t,e,n,i,s,r,o){const a=n.w,c=n.h,l=i.w,h=i.h,d=i.d,u=[],p=l+s,f=h+s,m=Math.max(1,Math.floor((a+s)/p)),g=Math.max(1,Math.floor((c+s)/f)),y=m*g,b=r&&r>0?Math.floor(r):4;if("row"===t||"column"===t){const n=o?.advanceAlongX??!1,i=o?.reverse??!1,s=n?m:g,r=n?g:m,l=(t,e,i)=>((t,e,n)=>u.push({x:-a/2+(t+.5)*p,y:n*d+d/2,z:-c/2+(e+.5)*f}))(n?t:e,n?e:t,i);let h=0;for(let n=0;n<s&&h<e;n++){const o=i?s-1-n:n;if("column"===t)for(let t=0;t<r&&h<e;t++)for(let n=0;n<b&&h<e;n++)l(o,t,n),h++;else for(let t=0;t<b&&h<e;t++)for(let n=0;n<r&&h<e;n++)l(o,n,t),h++}return u}if("pyramid"===t){let t=e,n=0;for(;t>0;){const e=Math.max(1,m-n),i=Math.max(1,g-n),s=e*i,o=Math.min(t,s);for(let t=0;t<o;t++){const s=t%e,r=Math.floor(t/e),o=-a/2+(s+(m-e)/2+.5)*p,l=-c/2+(r+(g-i)/2+.5)*f;u.push({x:o,y:n*d+d/2,z:l})}if(t-=o,n++,1===e&&1===i){for(let e=0;e<t;e++)u.push({x:0,y:(n+e)*d+d/2,z:0});break}if(r&&n>=r)break}return u}if("pile"===t){const t=t=>(43758.5453*Math.sin(12.9898*t)%1+1)%1;for(let n=0;n<e;n++){const e=Math.floor(n/y),i=n%y,s=i%m,o=Math.floor(i/m),g=(t(2*n)-.5)*l*.2,b=(t(2*n+1)-.5)*h*.2,_=-a/2+(s+.5)*p+g,v=-c/2+(o+.5)*f+b;if(u.push({x:_,y:e*d+d/2,z:v}),r&&e>=r-1&&i===y-1)break}return u}for(let n=0;n<e;n++){const e=Math.floor(n/y);if(r&&e>=r)break;const i=n%y,s=i%m,o=Math.floor(i/m);let l=-a/2+(s+.5)*p;const h=-c/2+(o+.5)*f;"staggered"===t&&e%2==1&&(l+=p/2),u.push({x:l,y:e*d+d/2,z:h})}return u}class Ny{constructor(t,e={}){this.pattern=t,this.defaults=e}layout(t,e,n,i={}){const s=i.gap??this.defaults.gap??0,r=i.heightLimit??this.defaults.heightLimit,o=i.fill??this.defaults.fill;return Fy(this.pattern,t,e,n,s,r,o).map(t=>({position:t}))}}class Hy{constructor(t,e,n={}){this.cols=t,this.rows=e,this.defaults=n}layout(t,e,n,i={}){const s=Math.max(1,this.cols),r=Math.max(1,this.rows),o=s*r,a=i.gap??this.defaults.gap??0,c=n.w+a,l=n.h+a,h=[];for(let e=0;e<t;e++){const t=Math.floor(e/o),i=e%o,a=i%s,d=Math.floor(i/s);h.push({position:{x:(a-(s-1)/2)*c,z:(d-(r-1)/2)*l,y:t*n.d+n.d/2}})}return h}}class By{constructor(t=.1,e=!1,n=!1){this.gapRatio=t,this.fillFromFar=e,this.sliceFirst=n}grid(t,e){const n=e.w*this.gapRatio,i=e.h*this.gapRatio;return{cols:Math.max(1,Math.floor((t.w-n)/(e.w+n))),rows:Math.max(1,Math.floor((t.h-i)/(e.h+i))),pitchX:e.w+n,pitchZ:e.h+i}}capacity(t,e,n){const{cols:i,rows:s}=this.grid(t,e);return i*s*Math.max(1,Math.floor(n))}layout(t,e,n,i={}){const{cols:s,rows:r,pitchX:o,pitchZ:a}=this.grid(e,n),c=n.d+n.d*this.gapRatio,l=null!=i.heightLimit?Math.max(1,Math.floor(i.heightLimit)):1/0,h=Number.isFinite(l),d=this.sliceFirst&&h,u=s*r,p=s*(h?l:1),f=s*r*(h?l:t),m=Math.min(t,f),g=[];for(let t=0;t<m;t++){let e,i,l;if(d){const n=Math.floor(t/p),r=t%p;e=r%s,l=Math.floor(r/s),i=n}else{l=Math.floor(t/u);const n=t%u;e=n%s,i=Math.floor(n/s)}this.fillFromFar&&(i=r-1-i),g.push({position:{x:(e-(s-1)/2)*o,z:(i-(r-1)/2)*a,y:l*c+n.d/2}})}return g}}function Yy(t,e,n,i=0){for(let s=0;s<e.length;s++){const r=e[s],o=n[s];r&&o&&(r.parent!==t&&t.attach(r),r.position.set(o.position.x,i+o.position.y,o.position.z),o.rotation?r.quaternion.set(o.rotation.x,o.rotation.y,o.rotation.z,o.rotation.w):r.quaternion.identity())}}function Vy(t,e,n,i=.12){const s=e.left+e.width/2,r=e.top+e.height/2,o=Math.min(n.w,n.h)*i,a=new Map;for(const e of t){const t=`${Math.round(e.position.x)},${Math.round(e.position.z)}`;let i=a.get(t);i||(i={x:s+e.position.x-n.w/2+o,y:r+e.position.z-n.h/2+o,w:n.w-2*o,h:n.h-2*o,count:0},a.set(t,i)),i.count++}return[...a.values()]}function Gy(t){return{id:t?.state?.id??t?.id??t?.refid,type:t?.state?.type??t?.type}}const $y=new t.Euler;function Uy(e,n){$y.setFromQuaternion(new t.Quaternion(n.x,n.y,n.z,n.w),"YXZ"),e.rotationX=$y.x,e.rotation=-$y.y,e.rotationY=$y.z}const Wy="_transferSlotId",qy=new Set(["left","top","width","height","depth","zPos","rotation","rotationX","rotationY","rotationZ","scale","translate","material3d","fillStyle","strokeStyle","lineWidth","lineDash","alpha","opacity","hidden","text","fontColor","fontSize","fontFamily","bold","italic","textAlign","textBaseline","shadow","border","cssText","object3d","_realObject","refid","id"]);function Xy(t){return class extends t{async ready(){await super.ready();const t=this.state?.data;Array.isArray(t)&&0===this._items.length&&!this.isRecordStorage&&this._reconcileItems(t)}set data(t){if(Array.isArray(t)){if(this.isRecordStorage){const e=this.setState;return void("function"==typeof e&&e.call(this,{data:t}))}this._reconcileItems(t)}else this.setState?.({data:t})}get data(){if(this.isRecordStorage)return this.state?.data??[];const t=this._exportSlotRecords();return 0===t.length?this.state?.data:t}_reconcileItems(t){const e=new Map;for(const n of t){const t=this._recordKey(n);t&&e.set(t,n)}const n=new Map;for(const t of this._items){const e=t[Wy];null!=e&&n.set(String(e),t)}for(const[t,i]of n)if(!e.has(t)){try{this.removeItem(i,!0)}catch{}try{i?.dispose?.()}catch{}}for(const[t,i]of e){if(n.has(t))continue;if(null==i.itemId)continue;const e=this._createItemFromRecord(i);if(e){e[Wy]=t;try{this.handoverIn(e)}catch{}}}for(const[t,i]of e){const e=n.get(t);if(e&&(i.itemState&&"function"==typeof e.setState))try{e.setState(i.itemState)}catch{}}}_exportSlotRecords(){const t=this.slotIds?.()??[],e=[],n=new Map,i=[];for(const t of this._items){const e=t[Wy];null!=e?n.set(String(e),t):i.push(t)}for(const i of t){const t=n.get(i)??null;e.push(this._slotRecordOf(i,t))}for(const t of i)e.push(this._slotRecordOf("",t));for(const[i,s]of n)t.includes(i)||e.push(this._slotRecordOf(i,s));return e}_recordKey(t){return t.slotId??t.cellId??""}_slotRecordOf(t,e){if(!e)return{slotId:t,itemId:null};const n=e?.state?.id;return{slotId:t,itemId:null!=n?String(n):null,itemType:e?.state?.type,itemState:this._extractItemState(e)}}_extractItemState(t){const e=t?.state;if(!e||"object"!=typeof e)return;const n=this._businessFields?.();if(Array.isArray(n)){if(0===n.length)return;const t={};for(const i of n)i in e&&void 0!==e[i]&&(t[i]=e[i]);return Object.keys(t).length>0?t:void 0}const i={};for(const t of Object.keys(e))qy.has(t)||t.startsWith("_")||(i[t]=e[t]);return Object.keys(i).length>0?i:void 0}_businessFields(){return null}_createItemFromRecord(t){const e=t.itemType??t.type;if(!e)return null;try{const n=Cc.register?.(e);if(n&&"function"==typeof n){return new n({type:e,...t.itemState??{}})}}catch{}return null}}}class Ky{positionAt(t,e,n){return 0!==t?null:e.localPosition??{x:0,y:0,z:0}}capacity(t){return 1}}const Qy=new Ky,Zy=[{id:"__default__",maxCount:1/0}];function Jy(e){var n;return n=class extends e{get slots(){return[]}get arrangementStrategy(){return Qy}canReceive(t,e){const n=null!==this.findSlot(t);return Yu.log({role:"target",contract:"canReceive",component:this,args:{carrier:Gy(t)},result:n}),n}findSlot(t){const e=this.slots.length?this.slots:Zy;for(const n of e){if(n.allowedTypes?.length){const e=t?.state?.type??t?.type;if(!e||!n.allowedTypes.includes(e))continue}const e=n.maxCount??this.arrangementStrategy.capacity(n),i=this._countOccupied(n.id);if(!(i>=e))return Yu.log({role:"target",contract:"findSlot",component:this,args:{carrier:Gy(t)},result:{slotId:n.id,occupied:i,max:e}}),n}return Yu.log({role:"target",contract:"findSlot",component:this,args:{carrier:Gy(t)},result:null}),null}acceptanceRotation(t,e){}deliveryWorldRotation(e){const n=this.acceptanceRotation?.(e);if(!n)return;const i=this._realObject?.object3d;if(!i)return;i.updateWorldMatrix(!0,!1);const s=new t.Quaternion;i.getWorldQuaternion(s);const r=new t.Quaternion(n.x,n.y,n.z,n.w);return s.clone().multiply(r)}deliveryWorldPosition(e){const n=this._realObject,i=n?.object3d;if(!i)return;i.updateWorldMatrix(!0,!1);const s=new t.Vector3;i.getWorldPosition(s);const r=this._receivingSurfaceLocalY();if(null!==r){const e=new t.Vector3(0,r,0);return i.localToWorld(e),{x:s.x,y:e.y,z:s.z}}return{x:s.x,y:s.y,z:s.z}}attachPointFor(t){const e=t?.[Wy];if(!e)return null;const n=this.slots.find(t=>t.id===e);return n?{position:n.localPosition??{x:0,y:0,z:0},rotation:n.localRotation??{x:0,y:0,z:0},slotId:n.id}:null}placementFor(t,e={}){const n=t&&"object"==typeof t&&"state"in t?t:void 0,i=n?n.state??{}:t??{},s={width:Number(i.width)||0,height:Number(i.height)||0,depth:Number(i.depth)||0},r=e.slot??this.slots.find(t=>{const e=t.maxCount??this.arrangementStrategy.capacity(t);return this._countOccupied(t.id)<e});if(!r)return null;const o=e.index??this._countOccupied(r.id),a=e.occupantCount??o,c=this.arrangementStrategy.positionAt(o,r,a,n??{state:{...s}});if(!c)return null;const l=Number(this.state?.width)||0,h=Number(this.state?.height)||0,d=c.x+s.width/2-l/2,u=c.y+s.height/2-h/2,p=this._realObject,f=p?.placementMode??"floor",m="space"===f?0:"inverted"===f?-s.depth/2:s.depth/2,g=this._receivingSurfaceLocalY();let y;y=null!==g?g+m:r.localPosition&&Number.isFinite(r.localPosition.z)?r.localPosition.z+m:m-(p?.geometricOffsetY??0);const b=this.acceptanceRotation?.(n??s,r)??void 0;return b?{position:{x:d,y:y,z:u},rotation:b}:{position:{x:d,y:y,z:u}}}_zPosFromSeatY(t,e,n){const i=this._realObject,s=i?.receivingSurfaceY??0,r=!(!n.localPosition||!Number.isFinite(n.localPosition.z));if(0===s&&!r)return null;const o=Number(e)||0,a=i?.placementMode??"floor";return t-("space"===a?0:"inverted"===a?-o/2:o/2)+(i?.geometricOffsetY??0)-s}_receivingSurfaceLocalY(){const t=this._realObject,e=t?.receivingSurfaceY;return"number"!=typeof e||0===e?null:e-(t.geometricOffsetY??0)}_countOccupied(t){const e=this._items;if(e)return e.filter(e=>e?.[Wy]===t).length;const n=this.components;return n?n.filter(e=>e.parent===this&&e[Wy]===t).length:0}},n.__hasCapacity=!0,n}function tb(t,e){const n=t.left??0,i=t.top??0,s=t.width??0,r=t.height??0;if(s<=0||r<=0)return[];const o="number"==typeof t.rotation?t.rotation:0,a=Math.cos(o),c=Math.sin(o),l=n+s/2,h=i+r/2,d="inbound"===e?-1:1;return[{lx:-s/2,lz:0,odx:-1,odz:0},{lx:s/2,lz:0,odx:1,odz:0},{lx:0,lz:-r/2,odx:0,odz:-1},{lx:0,lz:r/2,odx:0,odz:1}].map(t=>{var e,n;return{worldPos:(e=t.lx,n=t.lz,{x:l+e*a-n*c,z:h+e*c+n*a}),direction:{x:d*(t.odx*a-t.odz*c),z:d*(t.odx*c+t.odz*a)},halfSpan:0!==t.odx?r/2:s/2}})}function eb(t,e){const n=t.left??0,i=t.top??0,s=t.width??0,r=t.height??0;if(s<=0||r<=0)return{inbounds:[],outbounds:[]};const o="number"==typeof t.rotation?t.rotation:0,a=e??"reverse"===t.status,c="vertical"===t.orientation||"horizontal"!==t.orientation&&s<r,l=n+s/2,h=i+r/2,d=c?r/2:s/2,u=c?0:1,p=c?1:0,f=Math.cos(o),m=Math.sin(o),g=(t,e)=>({x:l+t*f-e*m,z:h+t*m+e*f}),y=c?{lx:0,lz:-d}:{lx:-d,lz:0},b=c?{lx:0,lz:d}:{lx:d,lz:0},_=g(y.lx,y.lz),v=g(b.lx,b.lz),x={x:u*f-p*m,z:u*m+p*f},w=Math.hypot(x.x,x.z)||1,M={x:x.x/w,z:x.z/w},S={x:-M.x,z:-M.z},k=(c?s:r)/2;return a?{inbounds:[{worldPos:v,direction:S,halfSpan:k}],outbounds:[{worldPos:_,direction:S,halfSpan:k}]}:{inbounds:[{worldPos:_,direction:M,halfSpan:k}],outbounds:[{worldPos:v,direction:M,halfSpan:k}]}}function nb(t){const e=t.left??0,n=t.top??0,i=t.width??0,s=t.height??0;if(i<=0||s<=0)return null;const r="number"==typeof t.rotation?t.rotation:0,o="vertical"===t.orientation||"horizontal"!==t.orientation&&i<s,a=e+i/2,c=n+s/2,l=o?s/2:i/2,h=Math.cos(r),d=Math.sin(r),u=(t,e)=>({x:a+t*h-e*d,z:c+t*d+e*h});return{start:o?u(0,-l):u(-l,0),end:o?u(0,l):u(l,0)}}function ib(t){const e=t.cx??0,n=t.cy??0,i=Math.abs(t.rx??100),s=Math.abs(t.ry??100),r=t.ratio??50,o=(i+i*r/100)/2,a=(s+s*r/100)/2,c=t.startAngle??0,l=t.endAngle??Math.PI/2,h="reverse"===t.status;if(i<=0||s<=0)return{inbounds:[],outbounds:[]};const d={x:e+o*Math.sin(c),z:n-a*Math.cos(c)},u={x:e+o*Math.sin(l),z:n-a*Math.cos(l)},p={x:Math.cos(c),z:Math.sin(c)},f={x:Math.cos(l),z:Math.sin(l)};return h?{inbounds:[{worldPos:u,direction:{x:-f.x,z:-f.z}}],outbounds:[{worldPos:d,direction:{x:-p.x,z:-p.z}}]}:{inbounds:[{worldPos:d,direction:p}],outbounds:[{worldPos:u,direction:f}]}}function sb(t){const e=eb(t),n=e.outbounds[0];if(!n)return{inbounds:tb(t,"inbound"),outbounds:[]};const i=tb(t,"inbound").filter(t=>{const e=t.worldPos.x-n.worldPos.x,i=t.worldPos.z-n.worldPos.z;return Math.hypot(e,i)>1}),s=n.direction,r=[];for(const t of i){const e=t.direction.x*s.x+t.direction.z*s.z;if(Math.abs(e)>=.1)continue;const n=t.direction.x+s.x,i=t.direction.z+s.z,o=Math.hypot(n,i)||1;r.push({worldPos:t.worldPos,direction:{x:n/o,z:i/o},halfSpan:t.halfSpan})}return{inbounds:[...i,...r],outbounds:e.outbounds}}function rb(t,e,n={}){const i=n.distance??5,s=n.cosine??.9;if(t.direction.x*e.direction.x+t.direction.z*e.direction.z<s)return!1;const r=t.worldPos.x-e.worldPos.x,o=t.worldPos.z-e.worldPos.z;if("number"==typeof t.halfSpan&&"number"==typeof e.halfSpan){const n=t.direction.x,s=t.direction.z;if(Math.abs(r*n+o*s)>i)return!1;const a=Math.abs(r*-s+o*n);return t.halfSpan+e.halfSpan-a>0}return Math.hypot(r,o)<=i}function ob(t,e,n,i=0){const s=n.width??0,r=n.height??0;if(s<=0||r<=0)return!1;const o=(n.left??0)+s/2,a=(n.top??0)+r/2,c="number"==typeof n.rotation?n.rotation:0,l=Math.cos(-c),h=Math.sin(-c),d=t-o,u=e-a,p=d*l-u*h,f=d*h+u*l;return Math.abs(p)<=s/2+i&&Math.abs(f)<=r/2+i}function ab(t,e,n){const i=n.width??0,s=n.height??0;if(i<=0||s<=0)return 1/0;const r=(n.left??0)+i/2,o=(n.top??0)+s/2;let a=t.x-r,c=t.z-o,l=e.x,h=e.z;const d="number"==typeof n.rotation?n.rotation:0;if(0!==d){const t=Math.cos(-d),e=Math.sin(-d),n=a*e+c*t,i=l*e+h*t;a=a*t-c*e,c=n,l=l*t-h*e,h=i}const u=i/2,p=s/2;let f=-1/0,m=1/0;if(Math.abs(l)<1e-9){if(a<-u||a>u)return 1/0}else{const t=(-u-a)/l,e=(u-a)/l;f=Math.max(f,Math.min(t,e)),m=Math.min(m,Math.max(t,e))}if(Math.abs(h)<1e-9){if(c<-p||c>p)return 1/0}else{const t=(-p-c)/h,e=(p-c)/h;f=Math.max(f,Math.min(t,e)),m=Math.min(m,Math.max(t,e))}return m<f?1/0:f>=0?f:m>=0?Math.min(-f,m):-m}function cb(t,e,n,i=6){return!!ob(t.worldPos.x,t.worldPos.z,e,i)&&(!n||t.direction.x*n.x+t.direction.z*n.z>=0)}function lb(t,e,n){return t.outbounds.map(t=>{const i=[];for(const s of e){let e=null;for(const i of s.topology.inbounds){if(!rb(t,i,n))continue;const s=t.worldPos.x-i.worldPos.x,r=t.worldPos.z-i.worldPos.z,o=Math.hypot(s,r);(null===e||o<e)&&(e=o)}if(null===e&&s.bounds){const i=s.topology.outbounds[0]?.direction,r=!(s.topology.outbounds&&s.topology.outbounds.length)?n?.sinkMargin??30:6;if(cb(t,s.bounds,i,r)){const n=ab(t.worldPos,t.direction,s.bounds);if(Number.isFinite(n))e=n+1e3;else{const n=(s.bounds.left??0)+(s.bounds.width??0)/2,i=(s.bounds.top??0)+(s.bounds.height??0)/2;e=Math.hypot(t.worldPos.x-n,t.worldPos.z-i)+1e3}}}null!==e&&i.push({id:s.id,dist:e})}return 0===i.length?null:(i.sort((t,e)=>t.dist-e.dist||(t.id<e.id?-1:1)),i[0].id)})}function hb(t,e){const n=new Map;for(const e of t)n.set(e.id,e);const i=new Map,s=new Set;for(const n of t){const r=t.filter(t=>t.id!==n.id),o=lb(n.topology,r,e);i.set(n.id,o);for(const t of o)null!=t&&s.add(t)}const r=(t,e)=>{if(!n.has(t)||!n.has(e)||t===e)return;const r=i.get(t)??[];r.includes(e)||(r.push(e),i.set(t,r),s.add(e))};for(const e of t)if(e.links){for(const t of e.links.downstream??[])r(e.id,t);for(const t of e.links.upstream??[])r(t,e.id)}const o=new Set,a=new Set;for(const e of t){(i.get(e.id)??[]).some(t=>null!=t)||o.add(e.id),s.has(e.id)||a.add(e.id)}return{nodes:n,out:i,sinks:o,sources:a}}function db(t,e){const n=new Map;return(t.out.get(e)??[]).map(e=>{if(null==e)return new Set;const i=new Set([e]);for(const s of function(t,e,n){const i=n.get(e);if(i)return i;const s=new Set,r=[e],o=new Set([e]);for(;r.length;){const e=r.shift();for(const n of t.out.get(e)??[])null!=n&&(s.add(n),o.has(n)||(o.add(n),r.push(n)))}return n.set(e,s),s}(t,e,n))i.add(s);return i})}function ub(t,e,n,i){return e===n?0:function(t,e,n){const i=n.get(e);if(i)return i;const s=new Map([[e,0]]),r=[e];for(;r.length;){const e=r.shift(),n=s.get(e);for(const i of t.out.get(e)??[])null==i||s.has(i)||(s.set(i,n+1),r.push(i))}return n.set(e,s),s}(t,e,i).get(n)??1/0}function pb(t,e,n){const i=t.out.get(e)??[],s=new Map,r=[];for(let e=0;e<i.length;e++){const o=i[e];if(null==o)continue;const a=o===n?0:ub(t,o,n,s);a!==1/0&&r.push({i:e,hops:1+a})}return r.sort((t,e)=>t.hops-e.hops||t.i-e.i),r.map(t=>t.i)}function fb(t,e,n){const i=pb(t,e,n);return i.length?i[0]:-1}function mb(t,e,n){return e===n||pb(t,e,n).length>0}function gb(t,e){const n=new Set;for(const i of db(t,e))for(const e of i)t.sinks.has(e)&&n.add(e);return n}function yb(t,e,n){return bb(t,e,n).map(t=>t.index)}function bb(t,e,n){const i=n instanceof Set?n:new Set(n);if(0===i.size)return[];const s=t.out.get(e)??[],r=new Map,o=[...i].sort(),a=[];for(let e=0;e<s.length;e++){const n=s[e];if(null==n)continue;let i=1/0,c="";for(const e of o){const s=1+(n===e?0:ub(t,n,e,r));s<i&&(i=s,c=e)}i!==1/0&&a.push({index:e,hops:i,target:c})}return a.sort((t,e)=>t.hops-e.hops||t.index-e.index),a}function _b(t,e={}){const n=[],i=e.loopCapableIds??new Set,s=e.routingTargetIds??new Set;for(const e of[...t.sources].sort()){const i=t.nodes.get(e);if(!i||!i.topology.outbounds?.length)continue;(t.out.get(e)??[]).some(t=>null!=t)||n.push({severity:"error",code:"orphan-source",nodeId:e,message:`source 노드 "${e}" 가 outgoing edge 0 — 아무 데도 carrier 를 보낼 수 없음`})}for(const e of[...t.nodes.keys()].sort()){(t.out.get(e)??[]).some(t=>null!=t)||(s.has(e)||t.sources.has(e)||n.push({severity:"error",code:"dead-end",nodeId:e,message:`노드 "${e}" 가 outgoing 0 인데 RoutingTarget 자격 없음 — routing 미정의 종착`}))}const r=function(t){const e=[],n=[...t.nodes.keys()].sort(),i=new Set,s=[],r=new Set,o=n=>{i.add(n),s.push(n),r.add(n);for(const a of t.out.get(n)??[])if(null!=a)if(r.has(a)){const t=s.indexOf(a),n=s.slice(t),i=n.indexOf([...n].sort()[0]),r=[...n.slice(i),...n.slice(0,i)],o=r.join("→");e.some(t=>t.join("→")===o)||e.push(r)}else i.has(a)||o(a);s.pop(),r.delete(n)};for(const t of n)i.has(t)||o(t);return e.sort((t,e)=>t[0].localeCompare(e[0])||t.length-e.length),e}(t);for(const t of r){const e=t.some(t=>i.has(t));e||n.push({severity:"error",code:"cycle",cycle:t,message:`의도 cycle 자격 (isLoop) 없는 cycle: ${t.join(" → ")} → ${t[0]}`})}const o=e.routingWeights;if(o)for(const[t,e]of[...o].sort((t,e)=>t[0].localeCompare(e[0])))(!Number.isFinite(e)||e<=0)&&n.push({severity:"warning",code:"invalid-weight",nodeId:t,message:`RoutingTarget "${t}" 의 routingWeight=${e} — weight ≤ 0 비정상, weight 정책에서 제외됨`});const a=new Set;for(const e of t.out.values())for(const t of e)null!=t&&a.add(t);for(const e of[...s].sort())t.nodes.has(e)&&(a.has(e)||n.push({severity:"warning",code:"unreachable-target",nodeId:e,message:`RoutingTarget "${e}" 에 incoming edge 0 — 누구도 이쪽으로 carrier 를 보내지 않음`}));return n.sort((t,e)=>t.code!==e.code?t.code.localeCompare(e.code):(t.nodeId??"").localeCompare(e.nodeId??"")),n}function vb(t,e){if(!t)return[];const n=[],i=new Set,s=t=>{if(!t||i.has(t))return;if(i.add(t),t!==e&&"function"==typeof t?.getSegmentTopology){const e=t.state?.id,i=t.refid??t.state?.refid,s="string"==typeof e&&e.length>0?e:null!=i?String(i):void 0;if(s)try{const e=t.getSegmentTopology(),i=t.state??{},r={left:i.left,top:i.top,width:i.width,height:i.height,rotation:i.rotation};e&&n.push({id:s,topology:e,bounds:r})}catch{}}const r=t?.components;if(Array.isArray(r))for(const t of r)s(t)};return s(t),n}function xb(t,e){const n=t.state?.targetRef??t.state?.downstreamRef;if("string"==typeof n&&n.length>0)return n;if("function"!=typeof t.getSegmentTopology)return null;const i=t.getSegmentTopology();if(!i||0===i.outbounds.length)return null;const s=lb(i,vb(t.parent??t.rootModel??t.root,t).filter(t=>t.topology.inbounds.length>0),e);for(const t of s)if(t)return t;return null}function wb(t){return!!t&&"function"==typeof t.routingConstraints}function Mb(t){return!!t&&"function"==typeof t.acceptedCarrierData}function Sb(t,e=16){const n=[],i=t.parent??t.rootModel??t.root;if(!i)return n;const s=xb(t);if(!s)return n;const r=Eb(i,s);if(!r)return n;const o=[{segment:r,accumulated:{},pathIds:[s],visited:new Set([s])}];for(;o.length>0;){const t=o.shift();if(t.pathIds.length>e)continue;const s=wb(t.segment)?t.segment.routingConstraints():null;if(s&&s.length>0)for(const e of s)for(const s of e.candidates){const r=kb(t.accumulated,s);if(!r)continue;const a=Ab(t.segment,e.portId,i);a&&!t.visited.has(a.state?.id??"")?o.push({segment:a,accumulated:r,pathIds:[...t.pathIds,a.state?.id??"?"],visited:new Set([...t.visited,a.state?.id??""])}):n.push({data:r,weight:1,pathIds:[...t.pathIds,`${e.portId}`],destination:e.portId})}else{if(Mb(t.segment)){const e=t.segment.acceptedCarrierData(),i=t.segment.state?.id;if(0===e.length)n.push({data:t.accumulated,weight:1,pathIds:t.pathIds,destination:i});else for(const s of e){const e=kb(t.accumulated,s);e&&n.push({data:e,weight:1,pathIds:t.pathIds,destination:i})}continue}const e=xb(t.segment);if(!e||t.visited.has(e)){n.push({data:t.accumulated,weight:1,pathIds:t.pathIds,destination:t.pathIds[t.pathIds.length-1]});continue}const s=Eb(i,e);if(!s)continue;o.push({segment:s,accumulated:t.accumulated,pathIds:[...t.pathIds,e],visited:new Set([...t.visited,e])})}}return n}function kb(t,e){const n={...t};for(const[t,i]of Object.entries(e)){if(t in n&&n[t]!==i)return null;n[t]=i}return n}function Ab(t,e,n){if("straight"===e&&t.state?.downstreamRef)return Eb(n,t.state.downstreamRef);const i=Eb(n,e);if(i)return i;const s=xb(t);return s?Eb(n,s):null}function Eb(t,e){if(!t||!e)return null;if("function"==typeof t.findById)return t.findById(e);const n=new Set,i=t=>{if(!t||n.has(t))return null;if(n.add(t),t.state?.id===e)return t;const s=t.components;if(Array.isArray(s))for(const t of s){const e=i(t);if(e)return e}return null};return i(t)}function Cb(t,e){return Math.hypot(t.x-e.x,t.z-e.z)}function Tb(t,e,n=5,i=[],s=n){const r=t.length,o=new Array(r).fill(void 0),a=new Set,c=(e,n)=>"start"===n?t[e].start:t[e].end,l=[],h=new Map,d=[],u=new Map;for(const t of i){const e=Array.isArray(t),n=e?t:t.positions,i=e?void 0:t.kind;if(!n.length)continue;const s=l.length;l.push({pos:n[0],members:[]});for(const t of n)d.push({pos:t,pt:s});i&&u.set(s,i)}const p=(t,e)=>{const i=c(t,e),s=h.get(`${t}:${"end"===e?"start":"end"}`),r=[];for(const t of d)Cb(t.pos,i)<=n&&!r.includes(t.pt)&&r.push(t.pt);for(let t=0;t<l.length;t++)Cb(l[t].pos,i)<=n&&!r.includes(t)&&r.push(t);let o=r.find(t=>t!==s)??-1;o<0&&(o=l.length,l.push({pos:i,members:[]})),l[o].members.push({seg:t,end:e}),h.set(`${t}:${e}`,o)};for(let t=0;t<r;t++)p(t,"start"),p(t,"end");const f=new Set,m=new Set,g=new Set;{const t=t=>{let e=-1,n=1/0;for(let i=0;i<l.length;i++){const s=Cb(l[i].pos,t);s<n&&(n=s,e=i)}for(const i of d){const s=Cb(i.pos,t);s<n&&(n=s,e=i.pt)}return{pt:e,d:n}};for(const n of e){const{pt:e,d:i}=t(n.pos);e>=0&&i<=s&&(f.add(e),("source"===n.kind?m:g).add(e))}}for(const[t,e]of u)f.add(t),("source"===e?m:g).add(t);const y=(t,e)=>"end"===e!==o[t],b=[],_=(e,n)=>{if(void 0===o[e])return o[e]=n,void b.push(e);o[e]!==n&&a.add(t[e].id)},v=t=>{for(const e of["start","end"]){const n=h.get(`${t}:${e}`);if(void 0===n)continue;const i=l[n];if(2!==i.members.length||f.has(n))continue;const s=i.members[0],r=s.seg===t&&s.end===e?i.members[1]:s;if(r.seg===t)continue;const a="end"===e!==o[t],c="end"===r.end!==!a;_(r.seg,c)}},x=()=>{for(;b.length;)v(b.shift())},w=t=>{let e=-1,n="start",i=1/0;for(let s=0;s<r;s++)for(const r of["start","end"]){const o=Cb(c(s,r),t.pos);o<i&&(i=o,e=s,n=r)}if(e<0||i>s)return;const o="source"===t.kind?"end"===n:"start"===n;_(e,o)};for(const t of e)"source"===t.kind&&w(t);x();for(const t of e)"sink"===t.kind&&w(t);x();let M=!0;for(;M;){M=!1;for(const t of l){if(t.members.length<3)continue;const e=t.members.filter(t=>void 0===o[t.seg]);if(1!==e.length)continue;let n=0,i=0;for(const e of t.members)void 0!==o[e.seg]&&(y(e.seg,e.end)?n++:i++);const s=e[0];let r;0===i&&n>0?r="end"===s.end:0===n&&i>0&&(r="start"===s.end),void 0!==r&&(o[s.seg]=r,b.push(s.seg),x(),M=!0)}}if(o.some(t=>void 0===t)&&m.size>0&&g.size>0){const t=t=>{const e=new Array(l.length).fill(1/0),n=[];for(const i of t)e[i]=0,n.push(i);for(;n.length;){const t=n.shift();for(const i of l[t].members){const s=h.get(`${i.seg}:${"start"===i.end?"end":"start"}`);void 0!==s&&e[s]>e[t]+1&&(e[s]=e[t]+1,n.push(s))}}return e},e=t(m),n=t(g);for(let t=0;t<r;t++){if(void 0!==o[t])continue;const i=h.get(`${t}:start`),s=h.get(`${t}:end`);if(void 0===i||void 0===s)continue;if(l[i].members.length<2||l[s].members.length<2)continue;if(e[i]===1/0||e[s]===1/0||n[i]===1/0||n[s]===1/0)continue;let r;e[i]!==e[s]?r=e[i]<e[s]:n[i]!==n[s]&&(r=n[s]<n[i]),void 0!==r&&(o[t]=!r,b.push(t))}x()}const S=new Map;for(let e=0;e<r;e++)S.set(t[e].id,void 0===o[e]?"unknown":o[e]?"reverse":"forward");return{directions:S,conflicts:[...a]}}function Pb(...t){}function Ob(t){return String(t?.state?.id??t?.refid??t?.state?.refid??"?")}function Db(t){const e=t?.state?.id;if("string"==typeof e&&e.length>0)return e;const n=t?.refid??t?.state?.refid;return null!=n?String(n):void 0}function*Ib(t){if(!t)return;("function"==typeof t.getSegmentTopology||t.flowOrientable)&&(yield t);const e=t.components;if(Array.isArray(e))for(const t of e)yield*Ib(t)}function zb(t,e,n){const i=e.width??0,s=e.height??0;if(i<=0||s<=0)return!1;const r=(e.left??0)+i/2,o=(e.top??0)+s/2,a="number"==typeof e.rotation?e.rotation:0,c=t.x-r,l=t.z-o,h=Math.cos(-a),d=Math.sin(-a),u=c*h-l*d,p=c*d+l*h;return Math.abs(u)<=i/2+n&&Math.abs(p)<=s/2+n}function Rb(t){const e=[],n=[],i=[],s=[];for(const r of Ib(t)){const t=Db(r);if(!t)continue;if(r.flowOrientable){const n=nb(r.state??{});n&&e.push({id:t,start:n.start,end:n.end});continue}if("function"==typeof r.openings){const t=r.state??{};(t.width??0)>0&&(t.height??0)>0&&s.push(t);continue}let o;try{o=r.getSegmentTopology()}catch{continue}if(!o)continue;const a=o.inbounds??[],c=o.outbounds??[],l="function"==typeof r.routingDestination;if(0===a.length&&c.length>0)for(const t of c)n.push({pos:{x:t.worldPos.x,z:t.worldPos.z},kind:"source"});else if(a.length>0&&(0===c.length||l))for(const t of a)n.push({pos:{x:t.worldPos.x,z:t.worldPos.z},kind:"sink"});else if(a.length>0||c.length>0){const t=[];for(const e of a)t.push({x:e.worldPos.x,z:e.worldPos.z});for(const e of c)t.push({x:e.worldPos.x,z:e.worldPos.z});t.length&&i.push({positions:t})}}for(const t of s){const s=[];for(const n of e)for(const e of[n.start,n.end])zb(e,t,16)&&s.push(e);let r=!1,o=!1;for(const e of n)zb(e.pos,t,16)&&("sink"===e.kind?r=!0:o=!0);const a=r&&!o?"sink":o&&!r?"source":void 0;(s.length>=2||a&&s.length>=1)&&i.push({positions:s,kind:a})}if(0===e.length||0===n.length)return new Map;return Tb(e,n,8,i,60).directions}function jb(t){const e=t?.root;if(!e)return;if(e.__flowComputing)return;let n=e.__flowOrientation;if(!n){e.__flowComputing=!0;try{n={map:Rb(e)}}finally{e.__flowComputing=!1}e.__flowOrientation=n}const i=Db(t),s=i?n.map.get(i):void 0;return"reverse"===s||"forward"!==s&&void 0}function Lb(t){return!!t&&"function"==typeof t.distanceToBoardPoint}function Fb(t,e,n,i){if(!t||!e)return null;const s=[],r=t=>{if(!t||t===i)return;if(Hm(t,e)&&Lb(t)){const e=function(t){const e=t?.state?.id;if("string"==typeof e&&e.length>0)return e;const n=t?.refid??t?.state?.refid;return null!=n?String(n):void 0}(t);e&&s.push({id:e,component:t,distance:t.distanceToBoardPoint(n.x,n.y)})}const o=t.components;if(Array.isArray(o))for(const t of o)r(t)};return r(t),0===s.length?null:(s.sort((t,e)=>t.distance-e.distance||t.id.localeCompare(e.id)),s[0])}function Nb(t){return!!t&&"function"==typeof t.routingDestination}function Hb(t){const e=t?.state?.id;if("string"==typeof e&&e.length>0)return e;const n=t?.refid??t?.state?.refid;return null!=n?String(n):void 0}function*Bb(t){if(!t)return;yield t;const e=t.components;if(Array.isArray(e))for(const t of e)yield*Bb(t)}function Yb(t){const e=[],n=new Map,i=new Map,s=new Set,r=[];for(const o of Bb(t)){"function"==typeof o?.registerWithHost&&r.push(o);const t="function"==typeof o?.getSegmentTopology,a="function"==typeof o?.routingLinks?o.routingLinks():void 0,c=!(!a||!((a.downstream?.length??0)>0||(a.upstream?.length??0)>0));if(!(t||Nb(o)||c||Lb(o)))continue;const l=Hb(o);if(!l)continue;let h={inbounds:[],outbounds:[]};if(t){try{h=o.getSegmentTopology()}catch{continue}if(!h)continue}const d=o.state??{},u={left:d.left,top:d.top,width:d.width,height:d.height,rotation:d.rotation};if(e.push({id:l,topology:h,bounds:u,links:a}),i.set(l,o),Nb(o)){s.add(l);const t=o.routingDestination();if("string"==typeof t&&t.length>0){const e=n.get(t)??[];e.push(l),n.set(t,e)}}}return{nodes:e,destToSinks:n,components:i,routingTargetIds:s,stationClients:r}}function Vb(t){if(!t)return null;let e=t.__flowGraph;if(!e){const{nodes:n,destToSinks:i,components:s,routingTargetIds:r,stationClients:o}=Yb(t),a=hb(n);!function(t,e){if(!t)return;const n=t=>{if(!t)return;"function"==typeof t.clearStations&&t.clearStations();const e=t.components;if(Array.isArray(e))for(const t of e)n(t)};n(t);const i=[...e].sort((t,e)=>{const n=Hb(t)??"",i=Hb(e)??"";return n.localeCompare(i)});for(const e of i){const n=e.declaredHostRef?.();let i=null;if(n&&(i=t.findById?.(n)??null),!i){const n=e.hostCapability?.(),s=e.hostFacingPoint?.();n&&s&&(i=Fb(t,n,s,e)?.component??null)}i&&"function"==typeof e.registerWithHost&&e.registerWithHost(i)}const s=e=>{if(!e)return;if(Lb(e)&&"function"==typeof e.resolveDownstream&&"function"==typeof e.registerDivertStation)for(const n of e.resolveDownstream()){const i=t.findById?.(n);i&&e.registerDivertStation(n,i)}const n=e.components;if(Array.isArray(n))for(const t of n)s(t)};s(t)}(t,o);const c=new Set;for(const[t,e]of s){((e?.state?.type??e?.model?.type??"").includes("loop")||!0===e?.isLoop)&&c.add(t)}const l=new Map;for(const t of r){const e=s.get(t);if("function"==typeof e?.routingWeight){const n=e.routingWeight();"number"==typeof n&&(!Number.isFinite(n)||n<=0)&&l.set(t,n)}}const h=_b(a,{routingTargetIds:r,loopCapableIds:c,routingWeights:l});if(h.length>0&&"undefined"!=typeof console){const t=h.filter(t=>"error"===t.severity),e=h.filter(t=>"warning"===t.severity);t.length>0?console.warn(`[FlowGraph] ${t.length} error(s) / ${e.length} warning(s):`,h):console.info(`[FlowGraph] ${e.length} warning(s):`,h)}e={graph:a,destToSinks:i,components:s,issues:h},t.__flowGraph=e}return e}function Gb(t){return Vb(t)?.issues??[]}function $b(t){const e=Vb(t);return e&&e.graph.nodes.size>0?e.graph:null}function Ub(t,e){return Vb(t)?.destToSinks.get(e)??[]}function Wb(t,e){return Vb(t)?.components.get(e)}function qb(t){const e=Vb(t);return e?[...e.destToSinks.keys()]:[]}function Xb(t){return Hb(t)}function Kb(t){const e="number"==typeof t?.inventoryCount?t.inventoryCount:"function"==typeof t?.size?t.size():0,n=t?.state?.capacity;return"number"==typeof n&&n>0?e/n:e}function Qb(t,e,n,i,s){if(1===i.length)return i[0];switch(t){case"index":default:return i[0];case"round-robin":{const t=n.counters.get(e)??0;return n.counters.set(e,t+1),i[t%i.length]}case"weight":{const t=i.map(t=>function(t){if("function"==typeof t?.routingWeight){const e=t.routingWeight();if("number"==typeof e&&Number.isFinite(e)&&e>0)return e}return 1}(s.get(t.target))),r=t.reduce((t,e)=>t+e,0);if(r<=0)return i[0];const o=n.counters.get(e)??0;n.counters.set(e,o+1);let a=o%r;for(let e=0;e<i.length;e++){if(a<t[e])return i[e];a-=t[e]}return i[i.length-1]}case"utilization":{let t=1/0,e=i[0];for(const n of i){const i=Kb(s.get(n.target));i<t&&(t=i,e=n)}return e}}}function Zb(t,e,n){const i=t?.root;if(!i)return null;const s=e?.state?.meta?.destination;if("string"!=typeof s||0===s.length)return null;const r=Vb(i);if(!r||0===r.graph.nodes.size)return null;const o=Hb(t);if(!o)return null;let a=r.destToSinks.get(s)??[];0===a.length&&(a=[s]);const c=bb(r.graph,o,a);if(0===c.length)return null;const l=r.graph.out.get(o)??[],h=c.filter(t=>{const n=l[t.index],i=n?r.components.get(n):null;return!i||"function"!=typeof i.canReceive||i.canReceive(e)});if(0===h.length)return l[c[0].index]??null;const d=n?.policy??function(t,e){const n=t?.state?.balancingPolicy;if(n)return n;const i=e?.state?.routingBalancingPolicy;return i||"round-robin"}(t,i),u=Qb(d,o,function(t){return t.__balancingState||(t.__balancingState={counters:new Map}),t.__balancingState}(i),h,r.components);return l[u.index]??null}Vm({name:"Capacity",description:"Item 을 *보유(keep)* 하는 측면 — slot 위상 / 수용 판정(canReceive/findSlot) / 3D 안착(placementFor/attachPointFor/acceptanceRotation) / delivery 좌표 질의 / 점유 수. 이동(receive/dispatch 등)은 Transferable 소관.",methods:["get slots","get arrangementStrategy","canReceive","findSlot","placementFor","attachPointFor","acceptanceRotation","deliveryWorldRotation","deliveryWorldPosition","_countOccupied"],sourceFile:"src/items/capacity-mixin.ts"}),Vm({name:"PlacementSurface",description:"carrier 가 holder 위 *정확히 어디에 앉는가* 의 단일 진입점 — placementFor(carrier, ctx) → SeatingPose (holder object3d local frame, 순수 함수). I1 접촉 (밑면 = 받침 상면) / I2 frame-explicit (parent-child 비가정 — Sovereign handover 와 reparent 양쪽이 같은 값 소비) / I3 순수성 / I4 per-carrier 치수. default 구현은 Capacity(FlowNode) 가 기존 receivingSurfaceY + ArrangementStrategy + acceptanceRotation 합성과 수치 동일하게 제공.",methods:["placementFor"],models:["CarrierDims","PlacementContext","SeatingPose"],sourceFile:"src/items/capacity-mixin.ts"});try{globalThis.__operatoBuildFlowGraph=(t,e)=>{try{return e?.force&&t&&delete t.__flowGraph,$b(t)}catch{return null}}}catch{}function Jb(t,e,n){const i=Zb(t,e,n);if(null==i)return null;const s=t?.root,r=Wb(s,i)??s?.findById?.(i)??null;return r?{targetId:i,component:r,origin:"explicit"}:null}function t_(t){const e=t?.root,n=$b(e),i=Xb(t);if(!n||!i)return null;const s=(n.out.get(i)??[]).find(Boolean);if(!s)return null;const r=Wb(e,s)??e?.findById?.(s)??null;return r?{id:s,component:r}:null}function e_(t){const e=Xb(t);return e?n_(t?.root,e):[]}function n_(t,e){if(!t||!e)return[];const n=$b(t);if(!n)return[];const i=new Set;for(const s of gb(n,e)){const e=Wb(t,s);if(Nb(e)){const t=e.routingDestination();"string"==typeof t&&t.length>0&&i.add(t)}}return[...i]}function i_(t,e){if(!t||!e)return[];const n=$b(t);if(!n)return[];const i=new Map;for(const t of n.out.values())for(const e of t)null!=e&&i.set(e,(i.get(e)??0)+1);const s=new Map;for(const r of gb(n,e)){const e=Wb(t,r);if(!Nb(e))continue;const n=e.routingDestination();if("string"!=typeof n||0===n.length)continue;let o=null;if("function"==typeof e.routingWeight){const t=e.routingWeight();"number"==typeof t&&Number.isFinite(t)&&t>0&&(o=t)}null===o&&(o=i.get(r)??0,0===o&&(o=1)),s.set(n,(s.get(n)??0)+o)}return[...s].map(([t,e])=>({value:t,weight:e}))}function s_(t){return $b(t)}function r_(t){const e=$b(t);if(!e)return[];const n=new Set,i=new Set,s=t=>{if(!t)return;const r=Xb(t);if(r&&e.nodes.has(r)){Nb(t)&&n.add(r);((t?.state?.type??t?.model?.type??"").includes("loop")||!0===t?.isLoop)&&i.add(r)}const o=t.components;if(Array.isArray(o))for(const t of o)s(t)};return s(t),_b(e,{routingTargetIds:n,loopCapableIds:i})}function o_(t){if(0===t.length)return;const e=t.reduce((t,e)=>t+e.weight,0);if(e<=0)return t[Math.floor(Math.random()*t.length)].value;const n=Math.random()*e;let i=0;for(const e of t)if(i+=e.weight,n<i)return e.value;return t[t.length-1].value}const a_={next:Jb,downstream:t_,reachableDestinations:e_,reachableDestinationsFrom:n_,reachableDestinationsWeightedFrom:i_,pickWeightedDestination:o_,graphFor:s_,validate:r_};function c_(t){var e;return e=class extends t{constructor(){super(...arguments),this._items=[]}get items(){return this._items}containsItem(t){return-1!==this._items.indexOf(t)}attachPointFor(e,n){const i=t.prototype?.attachPointFor;return"function"==typeof i?i.call(this,e,n):null}addItem(t,e){if(!t||this.containsItem(t))return;const n=t.parent;if(n&&"function"==typeof n.removeItem&&n!==this&&n.removeItem(t,!0),this._items.push(t),t.parent=this,!e?.silent&&"function"==typeof this.trigger)try{this.trigger("hold",this,t,this._items.length-1)}catch{}t.held?.(this)}removeItem(t,e){if(!t)return;const n=this._items.indexOf(t);if(-1!==n&&(this._items.splice(n,1),t.parent=null,!e)){if("function"==typeof this.trigger)try{this.trigger("release",this,t,n)}catch{}t.released?.(this)}}forEachItem(t,e){this._items.forEach(t,e)}handoverIn(t,e){if(!t)return;const n=t.parent;n&&("function"==typeof n.removeComponent&&-1!==n._components?.indexOf?.(t)&&n.removeComponent(t,!0),n!==this&&"function"==typeof n.removeItem&&-1!==n._items?.indexOf?.(t)&&n.removeItem(t,!0));const i=-1===this._items.indexOf(t);if(i&&this._items.push(t),t.parent=this,i&&"function"==typeof this.trigger)try{this.trigger("hold",this,t,this._items.length-1)}catch{}const s=t._realObject,r=s?.object3d;if(r){let n,i,o=e?.toParent3D,a="world-preserve";if(!o){const s=this.attachPointFor?.(t,{slotId:e?.slotId});s?.attach&&(o=s.attach,n=s.localPosition,i=s.localRotation,a=s.carryPolicy??"world-preserve")}o&&r.parent!==o&&(o.updateWorldMatrix?.(!0,!1),r.updateWorldMatrix?.(!0,!1),o.attach(r),s.suppressTransform=!0),o&&(n&&r.position.set(n.x,n.y,n.z),"world-preserve"!==a?i?r.rotation.set(i.x,i.y,i.z):r.quaternion.identity():i&&r.rotation.set(i.x,i.y,i.z),s?.setTransientPlacement?.({policy:"carried",meta:{carryPolicy:a}}))}t.held?.(this),this._bumpReceived?.(t)}handoverOut(t){this.removeItem(t),this._bumpDispatched?.(t)}dispose(){const t=this._items.slice();this._items.length=0;for(const e of t)try{e.dispose?.()}catch{}super.dispose?.()}_drawItems(t){const e=this.root?.transitionEffect;for(const t of this._items)e?.isReparenting?.(t)||t.draw?.(this.getContext?.(t))}_captureItems(t,e,n,i,s){for(let r=this._items.length-1;r>=0;r--){const o=this._items[r],a="static"===o.position?o.capture?.(t,e,s):o.capture?.(n,i,s);if(a)return a}return null}postrender(t){super.postrender?.(t);const e=this;if("popup"===e.position)return;const n=this._items;if(!n||0===n.length)return;t.save();const i=e.bounds;!e.showOverflow&&i&&(t.beginPath(),t.rect(i.left,i.top,i.width,i.height),t.clip(),t.closePath());const{left:s=0,top:r=0}=e.state??{};t.translate(s,r),this._drawItems(t),t.translate(-s,-r),t.restore()}capture(t,e,n){const i=this,s=this._items;if(s&&s.length>0&&(!i.app||i.app.isEditMode||!i.hidden)){const s=i.fromParent?.(t,e);if(s&&i.contains?.(s.x,s.y)){const r=i.bounds,o=this._captureItems(s.x-r.left,s.y-r.top,t,e,n);if(o)return o}}return super.capture?.(t,e,n)}},e.capabilities=Object.freeze([...t.capabilities??[],"Holdable"]),e}function l_(e){var n;return(n=class extends e{reserve(t,e){const n=this.findSlot(t);return n?{slot:n,token:Symbol("slot-reservation")}:null}release(t){}async receive(t,e={}){Yu.log({role:"target",contract:"receive:enter",component:this,args:{carrier:Gy(t),options:e}});const n=this.reserve(t,e);if(!n){Yu.log({role:"target",contract:"receive:reject",component:this,args:{carrier:Gy(t)},result:{reason:"no-slot"}}),this.trigger("transfer-rejected",{type:"transfer-rejected",component:t,container:this,reason:"no-slot"});const e=new Error("receive rejected: no-slot");throw e.reason="no-slot",e}this.commit(n,t,e)}commit(e,n,i={}){const s=e.slot,r=this._countOccupied(s.id),o=this.arrangementStrategy.positionAt(r,s,r,n);Yu.log({role:"target",contract:"arrangementStrategy.positionAt",component:this,args:{idx:r,slotId:s.id,occupantCount:r,carrier:Gy(n)},result:o}),n[Wy]=s.id;const a=n._realObject;let c,l;a?.object3d&&(a.object3d.updateWorldMatrix(!0,!1),c=new t.Vector3,l=new t.Quaternion,a.object3d.getWorldPosition(c),a.object3d.getWorldQuaternion(l));const{animated:h=!1,duration:d,ease:u}=i;"function"==typeof this.handoverIn?this.handoverIn(n,{slotId:s.id}):this.reparent?.(n,{animated:h,duration:d,ease:u}),!h&&n._realObject&&(n._realObject.suppressTransform=!1);{const t={},e=this.placementFor?.(n,{slot:s,index:r,occupantCount:r})??null;if(Yu.log({role:"target",contract:"placementFor",component:this,args:{carrier:Gy(n),slotId:s.id,index:r},result:e}),e){const i=n.state??{},r=this.state??{};t.left=e.position.x-(Number(i.width)||0)/2+(Number(r.width)||0)/2,t.top=e.position.z-(Number(i.height)||0)/2+(Number(r.height)||0)/2;const o=this._zPosFromSeatY(e.position.y,i.depth,s);null!==o&&(t.zPos=o),e.rotation&&Uy(t,e.rotation)}else{o&&(t.left=o.x,t.top=o.y);if(0!==(this._realObject?.receivingSurfaceY??0))t.zPos=0;else if(s.localPosition&&Number.isFinite(s.localPosition.z)){const e=this._realObject?.geometricOffsetY??0;t.zPos=s.localPosition.z+e}const e=this.acceptanceRotation?.(n,s);Yu.log({role:"target",contract:"acceptanceRotation",component:this,args:{carrier:Gy(n),slotId:s.id},result:e}),e&&Uy(t,e)}const i=this.normalizePose?.(n,s);"function"==typeof this.normalizePose&&Yu.log({role:"target",contract:"normalizePose",component:this,args:{carrier:Gy(n),slotId:s.id},result:i}),i&&Object.assign(t,i),Object.keys(t).length&&(n.setState?.(t),Yu.log({role:"target",contract:"receive:setState",component:this,args:{carrier:Gy(n),keys:Object.keys(t)}}))}this.trigger("transfer-received",{type:"transfer-received",component:n,container:this,slotId:s.id,preReceiveWorldPos:c,preReceiveWorldQuat:l}),Yu.log({role:"target",contract:"receive:done",component:this,args:{carrier:Gy(n),slotId:s.id}})}async dispatch(t,e,n={}){const i=new Uu({source:this,target:e,carrier:t,options:n,physical:async()=>{delete t[Wy]}}),s=await i.execute();"rolled-back"!==s.phase?this.trigger("transfer-dispatched",{type:"transfer-dispatched",component:t,container:this,target:e}):this.trigger("transfer-rejected",{type:"transfer-rejected",component:t,container:this,reason:s.rejectReason??"rejected"})}route(t){return null}resolveRoute(t,e){}rejectRoute(t,e="rejected"){this.trigger("transfer-rejected",{type:"transfer-rejected",component:t,container:this,reason:e})}canAccept(t){const e=(()=>{const e=this.slots;if(!e.length)return{ok:!1,reason:"no-slots-defined"};const n=this.findSlot(t);if(!n){const n=t?.state?.type??t?.type;for(const t of e)if(!t.allowedTypes?.length||!n||t.allowedTypes.includes(n))return{ok:!1,reason:"all-slots-full"};return{ok:!1,reason:"type-not-accepted"}}return{ok:!0,slot:n}})();return Yu.log({role:"target",contract:"canAccept",component:this,args:{carrier:Gy(t)},result:e.ok?{ok:!0,slotId:e.slot.id}:{ok:!1,reason:e.reason}}),e}accept(t,e){return this.receive(t,e)}}).__hasTransferable=!0,n}function h_(t){var e;const n=!!t.__hasCapacity,i=!!t.__hasTransferable,s=n?t:Jy(t),r=i?s:l_(s),o=[...t.capabilities??[]];n||o.push("Capacity","PlacementSurface"),i||o.push("Transferable"),o.push("Holdable","FlowNode");const a=(function(t,e,n){"symbol"==typeof e&&(e=e.description?"[".concat(e.description,"]"):""),Object.defineProperty(t,"name",{configurable:!0,value:n?"".concat(n," ",e):e})}(e=class extends(c_(r)){get isFlowNode(){return!0}containable(t){return!!t&&!0===t.isItem}get showMoveHandle(){return!1}inboundPorts(){return[]}outboundPorts(){return[]}_bumpReceived(t){const e=this.state?.received??0;this.setState?.({received:e+1})}_bumpDispatched(t){const e=this.state?.dispatched??0;this.setState?.({dispatched:e+1})}_bumpRejected(t,e){const n=this.state?.rejected??0;this.setState?.({rejected:n+1})}route(t){return null}resolveRoute(t,e){}rejectRoute(t,e){}resolveDownstream(){const t=this.state?.downstreamRef;if(!t)return[];return(this.root?.findAll?.(t)??[]).map(t=>t?.state?.id).filter(Boolean)}routingLinks(){return{downstream:this.resolveDownstream()}}},"FlowNodeMixed"),e.capabilities=Object.freeze(o),e.isFlowNode=!0,e);return Xy(a)}function d_(t){return!!t&&!0===t.isFlowNode}Vm({name:"Holdable",description:"어떤 Component 든 item(데이타바인딩 동적 물건) 을 보유하는 capability. _items + add/remove/forEach + handover + hold/release event + dispose cascade. Container(정적 _components) 와 직교 — 컨테이너 비의존.",methods:["addItem","removeItem","forEachItem","containsItem","handoverIn","handoverOut","_drawItems","_captureItems","dispose"],sourceFile:"src/components/mixins/holdable.ts"}),Vm({name:"Transferable",description:"Item 을 노드 간에 옮기는 *이동(move)* 측면. 수용 트랜잭션 라이프사이클(reserve → commit → release)과 receive/accept/dispatch/route 를 제공. 보유(keep — slots/findSlot/canReceive 등)는 Capacity 소관.",methods:["reserve","commit","release","receive","accept","canAccept","dispatch","route","resolveRoute","rejectRoute"],sourceFile:"src/transfer/transferable-mixin.ts"}),Vm({name:"FlowNode",description:"Flow graph 의 노드 — 구조 (inbound/outbound port + slot) + flow (route + 5-phase transfer stat). 보유(_items/handover)는 Holdable base 위임. 모든 flow 컴포넌트의 base — Storable/Mobile/Processable 의도가 위에 직교로 적용.",methods:["inboundPorts","outboundPorts","slotIds","slotAt","route","resolveRoute","rejectRoute"],models:["Port","SlotInfo","Vec3"],sourceFile:"src/flow/flow-node.ts"});const u_={x:0,y:0,z:0,w:1};function p_(t){const e=t/2;return{x:0,y:Math.sin(e),z:0,w:Math.cos(e)}}function f_(t,e){const n=t.rotation,i=e.rotation,s=e.position,r=n.w*s.x+n.y*s.z-n.z*s.y,o=n.w*s.y+n.z*s.x-n.x*s.z,a=n.w*s.z+n.x*s.y-n.y*s.x,c=-n.x*s.x-n.y*s.y-n.z*s.z,l=r*n.w+c*-n.x+o*-n.z-a*-n.y,h=o*n.w+c*-n.y+a*-n.x-r*-n.z,d=a*n.w+c*-n.z+r*-n.y-o*-n.x,u={x:n.w*i.x+n.x*i.w+n.y*i.z-n.z*i.y,y:n.w*i.y-n.x*i.z+n.y*i.w+n.z*i.x,z:n.w*i.z+n.x*i.y-n.y*i.x+n.z*i.w,w:n.w*i.w-n.x*i.x-n.y*i.y-n.z*i.z};return{position:{x:t.position.x+l,y:t.position.y+h,z:t.position.z+d},rotation:u}}const m_={east:{axis:{x:1,y:0,z:0},yaw:0,idSuffix:"east"},west:{axis:{x:-1,y:0,z:0},yaw:Math.PI,idSuffix:"west"},south:{axis:{x:0,y:0,z:1},yaw:-Math.PI/2,idSuffix:"south"},north:{axis:{x:0,y:0,z:-1},yaw:Math.PI/2,idSuffix:"north"}};function g_(t){const{carrierWorld:e,width:n,depth:i,entryHeight:s,mountLocalY:r,approachDistance:o,sides:a,toolType:c,tolerance:l,priority:h}=t,d="number"==typeof r?{position:{x:0,y:r,z:0},rotation:{...u_}}:void 0,u=n/2,p=i/2;return a.map(t=>{const n=m_[t],i="string"==typeof c?c:c[t]??"unknown",r={position:{x:n.axis.x*("east"===t||"west"===t?u:0),y:s,z:n.axis.z*("north"===t||"south"===t?p:0)},rotation:p_(n.yaw)},a={position:{x:r.position.x+n.axis.x*o,y:s,z:r.position.z+n.axis.z*o},rotation:p_(n.yaw)};return{id:`entry-${n.idSuffix}`,toolType:i,approach:f_(e,a),engage:f_(e,r),...d?{mount:d}:{},tolerance:l,priority:h}})}function y_(t){const{carrierWorld:e,topY:n,approachDistance:i,toolType:s,mountLocalY:r,tolerance:o,priority:a,id:c}=t,l={position:{x:0,y:n,z:0},rotation:{...u_}};return{id:c??"top",toolType:s,approach:f_(e,{position:{x:0,y:n+i,z:0},rotation:{...u_}}),engage:f_(e,l),..."number"==typeof r?{mount:{position:{x:0,y:r,z:0},rotation:{...u_}}}:{},tolerance:o,priority:a}}function b_(t,e){return t.filter(t=>t.toolType===e.toolType)}function __(t,e){if(0===t.length)return null;const n=t.map(t=>{const n=t.approach.position.x-e.x,i=t.approach.position.y-e.y,s=t.approach.position.z-e.z;return{f:t,dist:Math.sqrt(n*n+i*i+s*s)}});return n.sort((t,e)=>{const n=t.f.priority??0,i=e.f.priority??0;return n!==i?n-i:t.dist-e.dist}),n[0].f}class v_{constructor(t){this.owner=t}positionAt(t,e,n,i){if(0!==t)return null;const s=this.owner?.state?.width??0,r=this.owner?.state?.height??0,o=i?.state?.width??0,a=i?.state?.height??0;return{x:Math.max(0,(s-o)/2),y:Math.max(0,(r-a)/2),z:0}}capacity(t){return t.maxCount??1}}let x_=1;function w_(t,e){return t.startSimMs<e.endSimMs&&e.startSimMs<t.endSimMs}const M_={resolveConflict:(t,e)=>t.priority!==e.priority?t.priority<e.priority?"b-yields":"a-yields":t.id<e.id?"b-yields":"a-yields"};class S_{constructor(t=M_){this._byResource=new Map,this._byReserver=new Map,this._listeners=new Set,this._conflictLog=[],this._maxConflictLog=1e3,this._yieldPolicy=t}add(t){const e={...t,id:"res-"+x_++},n=(this._byResource.get(e.resource)??[]).filter(t=>w_(t.timeWindow,e.timeWindow));if(0===n.length)return this._insert(e),this._emit({kind:"added",reservation:e}),{ok:!0,reservation:e};const i=n.map(t=>{const n=this._yieldPolicy.resolveConflict(e,t);return{a:e,b:t,decision:n}});if(i.every(t=>"b-yields"===t.decision)){const i=n.slice();for(const t of i)this._remove(t),this._emit({kind:"evicted",reservation:t,by:e});return this._insert(e),this._emit({kind:"added",reservation:e}),this._appendConflictLog({simTime:e.timeWindow.startSimMs,resource:e.resource,proposed:t,existing:i,outcome:"preempted"}),{ok:"preempted",reservation:e,evicted:i}}return this._appendConflictLog({simTime:e.timeWindow.startSimMs,resource:e.resource,proposed:t,existing:n.slice(),outcome:"rejected"}),{ok:!1,conflicts:i}}conflictLog(){return[...this._conflictLog]}setMaxConflictLog(t){this._maxConflictLog=Math.max(1,t)}_appendConflictLog(t){this._conflictLog.push(t),this._conflictLog.length>this._maxConflictLog&&this._conflictLog.shift()}conflicts(t,e){return(this._byResource.get(t)??[]).filter(t=>w_(t.timeWindow,e))}release(t){this._remove(t)&&this._emit({kind:"released",reservation:t})}releaseAllOf(t){const e=(this._byReserver.get(t)??[]).slice();for(const t of e)this._remove(t),this._emit({kind:"released",reservation:t});return e}forResource(t){return[...this._byResource.get(t)??[]]}forReserver(t){return[...this._byReserver.get(t)??[]]}all(){const t=[];for(const e of this._byResource.values())t.push(...e);return t}clear(){this._byResource.clear(),this._byReserver.clear(),this._conflictLog.length=0}subscribe(t){return this._listeners.add(t),()=>{this._listeners.delete(t)}}_insert(t){let e=this._byResource.get(t.resource);e||(e=[],this._byResource.set(t.resource,e));const n=e.findIndex(e=>e.timeWindow.startSimMs>t.timeWindow.startSimMs);n<0?e.push(t):e.splice(n,0,t);let i=this._byReserver.get(t.reserverId);i||(i=[],this._byReserver.set(t.reserverId,i)),i.push(t)}_remove(t){const e=this._byResource.get(t.resource);if(!e)return!1;const n=e.findIndex(e=>e.id===t.id);if(n<0)return!1;e.splice(n,1),0===e.length&&this._byResource.delete(t.resource);const i=this._byReserver.get(t.reserverId);if(i){const e=i.findIndex(e=>e.id===t.id);e>=0&&i.splice(e,1),0===i.length&&this._byReserver.delete(t.reserverId)}return!0}_emit(t){this._listeners.forEach(e=>e(t))}}const k_=new S_;"undefined"!=typeof globalThis&&(globalThis.__THINGS_SCENE_RESERVATION_TABLE__=k_);class A_{constructor(){this.nodes=new Map,this.edges=new Map,this.laneEndpoints=new Map}addNode(t){this.nodes.has(t.id)||(this.nodes.set(t.id,t),this.edges.set(t.id,[]))}addEdge(t){const e=this.edges.get(t.fromNode);if(!e)throw new Error(`NavGraph.addEdge: source node not found: ${t.fromNode}`);if(!this.nodes.has(t.toNode))throw new Error(`NavGraph.addEdge: target node not found: ${t.toNode}`);e.push(t)}edgesFrom(t){return this.edges.get(t)??[]}findNearestNode(t){let e=null,n=1/0;for(const i of this.nodes.values()){const s=E_(i.position,t);s<n&&(n=s,e=i)}return e}}function E_(t,e){const n=t.x-e.x,i=t.y-e.y,s=t.z-e.z;return n*n+i*i+s*s}function C_(t,e){return Math.sqrt(E_(t,e))}function T_(t,e,n={}){const i=new A_,s=n.defaultSpeed??100;for(const e of t){const t=e.geometry.centerPoints;if(t.length<2)continue;const n=`${e.id}:start`,r=`${e.id}:end`;i.addNode({id:n,position:t[0],type:"lane-start"}),i.addNode({id:r,position:t[t.length-1],type:"lane-end"}),i.laneEndpoints.set(e.id,{startNodeId:n,endNodeId:r});let o=0;for(let e=1;e<t.length;e++)o+=C_(t[e-1],t[e]);const a=o/(e.speedLimit??s)*1e3;i.addEdge({fromNode:n,toNode:r,resource:e.id,distance:o,durationMs:a,forward:!0}),"twoway"===e.direction&&i.addEdge({fromNode:r,toNode:n,resource:e.id,distance:o,durationMs:a,forward:!1})}for(const t of e){if(t.lanes.length<2)continue;const e=[];for(const n of t.lanes){const s=i.laneEndpoints.get(n);if(!s)continue;const r=i.nodes.get(s.startNodeId).position,o=i.nodes.get(s.endNodeId).position;let a=0,c=0,l=0;for(const e of t.lanes){if(e===n)continue;const t=i.laneEndpoints.get(e);if(!t)continue;const s=i.nodes.get(t.startNodeId).position,h=i.nodes.get(t.endNodeId).position;a+=Math.min(E_(r,s),E_(r,h)),c+=Math.min(E_(o,s),E_(o,h)),l++}if(0===l)continue;const h=a<c?s.startNodeId:s.endNodeId;e.push({laneId:n,nodeId:h,pos:i.nodes.get(h).position})}for(let n=0;n<e.length;n++)for(let s=0;s<e.length;s++){if(n===s)continue;const r=e[n],o=e[s],a=C_(r.pos,o.pos);i.addEdge({fromNode:r.nodeId,toNode:o.nodeId,resource:t.id,distance:a,durationMs:t.crossingTimeMs,forward:!0})}}return i}function P_(t,e,n,i={}){const s=t.nodes.get(e),r=t.nodes.get(n);if(!s||!r)return null;const o=i.speed?.max??100,a=e=>{const n=t.nodes.get(e);var i,s;return(i=n.position,s=r.position,Math.sqrt(function(t,e){const n=t.x-e.x,i=t.y-e.y,s=t.z-e.z;return n*n+i*i+s*s}(i,s)))/o*1e3},c=new Map,l=new Set,h=new Set,d={nodeId:e,gScore:0,fScore:a(e)};c.set(e,d),l.add(e);const u=i.startSimMs??0,p=i.deadlineSimMs;for(;l.size>0;){let e=null,i=null;for(const t of l){const n=c.get(t);(!i||n.fScore<i.fScore||n.fScore===i.fScore&&t<e)&&(i=n,e=t)}if(!i||!e)return null;if(e===n){const t=[];let e=i,n=0;for(;e&&e.cameFromEdge;){const i=e.cameFromEdge,s=u+(e.gScore-i.durationMs);t.unshift({resource:i.resource,timeWindow:{startSimMs:s,endSimMs:s+i.durationMs},fromPos:i.fromPos,toPos:i.toPos}),n+=i.distance,e=c.get(i.fromNodeId)}const s=i.gScore;return void 0!==p&&u+s>p?null:{segments:t,totalDurationMs:s,totalDistance:n}}l.delete(e),h.add(e);for(const n of t.edgesFrom(e)){if(h.has(n.toNode))continue;const e=i.gScore+n.durationMs,s=c.get(n.toNode);if(!s||e<s.gScore){const i=t.nodes.get(n.fromNode),s=t.nodes.get(n.toNode),r={nodeId:n.toNode,gScore:e,fScore:e+a(n.toNode),cameFromEdge:{fromNodeId:n.fromNode,resource:n.resource,distance:n.distance,durationMs:n.durationMs,fromPos:i.position,toPos:s.position}};c.set(n.toNode,r),l.add(n.toNode)}}}return null}function O_(t,e,n=0,i){return t.segments.map(t=>({resource:t.resource,timeWindow:t.timeWindow,reserverId:e,priority:n,metadata:i}))}const D_={closed:!0,round:0,divisions:24};class I_{constructor(t,e){this.points=t,this.closed=e;const n=[0];for(let e=1;e<t.length;e++){const i=t[e].x-t[e-1].x,s=t[e].y-t[e-1].y;n.push(n[e-1]+Math.sqrt(i*i+s*s))}this.cumulative=n,this.length=n[n.length-1]??0}sample(t){const e=this.length;if(0===this.points.length)return{x:0,y:0,theta:0};if(0===e)return{x:this.points[0].x,y:this.points[0].y,theta:0};let n=t;this.closed?n=(t%e+e)%e:n<0?n=0:n>e&&(n=e);const i=this.cumulative;let s=0,r=i.length-2;for(;s<r;){const t=s+r>>1;i[t+1]<=n?s=t+1:r=t}const o=i[s+1]-i[s],a=o>0?(n-i[s])/o:0,c=this.points[s],l=this.points[s+1],h=l.x-c.x,d=l.y-c.y;return{x:c.x+h*a,y:c.y+d*a,theta:0===h&&0===d?0:Math.atan2(d,h)}}}function z_(t,e={}){const n={...D_,...e},i=t.length;if(0===i)return new I_([],n.closed);if(1===i)return new I_([{x:t[0].x,y:t[0].y}],n.closed);const s=[],r=(t,e)=>{if(s.length>0){const n=s[s.length-1];if(Math.abs(n.x-t)<1e-9&&Math.abs(n.y-e)<1e-9)return}s.push({x:t,y:e})},o=(n.closed,i);for(let e=0;e<o;e++){const s=0===e?n.closed?i-1:-1:e-1,o=e===i-1?n.closed?0:-1:e+1,a=s>=0?t[s]:null,c=t[e],l=o>=0?t[o]:null;if(a&&a.x===c.x&&a.y===c.y)continue;const h=a&&l?Jr(c,n.round):0;let d,u,p,f;if(a){const t=Math.sqrt((a.x-c.x)**2+(a.y-c.y)**2),e=0!==t?Math.atan2(a.x-c.x,a.y-c.y):0,n=Math.min(h,t/2);d=Math.sin(e)*n+c.x,u=Math.cos(e)*n+c.y}else d=c.x,u=c.y;if(l){const t=Math.sqrt((l.x-c.x)**2+(l.y-c.y)**2),e=0!==t?Math.atan2(l.x-c.x,l.y-c.y):0,n=Math.min(h,t/2);p=Math.sin(e)*n+c.x,f=Math.cos(e)*n+c.y}else p=c.x,f=c.y;if(r(d,u),h>0&&a&&l)for(let t=1;t<=n.divisions;t++){const e=t/n.divisions,i=1-e;r(i*i*d+2*i*e*c.x+e*e*p,i*i*u+2*i*e*c.y+e*e*f)}else d===p&&u===f||r(p,f);if(l&&Xr(c)){const t=Jr(l,n.round),e=Math.sqrt((c.x-l.x)**2+(c.y-l.y)**2),i=0!==e?Math.atan2(c.x-l.x,c.y-l.y):0,s=Math.min(t,e/2),o=Kr({x:p,y:f},{x:Math.sin(i)*s+l.x,y:Math.cos(i)*s+l.y},c.bulge);if(o){let t=o.endAngle-o.startAngle;if(o.clockwise)for(;t>0;)t-=2*Math.PI;else for(;t<0;)t+=2*Math.PI;for(let e=1;e<=n.divisions;e++){const i=e/n.divisions,s=o.startAngle+t*i;r(o.cx+o.radius*Math.cos(s),o.cy+o.radius*Math.sin(s))}}}}if(n.closed&&s.length>0){const t=s[0],e=s[s.length-1];(Math.abs(e.x-t.x)>1e-9||Math.abs(e.y-t.y)>1e-9)&&s.push({x:t.x,y:t.y})}return new I_(s,n.closed)}function R_(t,e){return z_(t,e).length}function j_(t){return t?/forklift|agv|amr|oht|tugger|worker/i.test(t)?"mobile":/conveyor|sorter|induct|chute|belt/i.test(t)?"flow":/rack|shelf|stocker|cell/i.test(t)?"cell":/pallet|box|parcel|crate|drum|tray/i.test(t)?"atomic":/robot[-_]?arm|crane|lift/i.test(t)?"articulated":/spawn[-_]?point|sink[-_]?point/i.test(t)?"boundary":"":""}function L_(t){const e=[];let n=t.parent;for(;n&&!n.isRootModel?.();){const t=n.state?.id??n.constructor?.name;t&&e.unshift(t),n=n.parent}return e.join(" › ")}function F_(t,e=!0){const n=t.constructor?.name??t.state?.type??"Component",i={type:n,id:t.state?.id??`?${t._id??Math.random().toString(36).slice(2,7)}`,category:j_(n),parentId:t.parent?.state?.id,parentPath:L_(t)},s=t._realObject?.object3d;if(s){s.updateWorldMatrix?.(!0,!1);const t=s.matrixWorld?.elements;t&&(i.pose={position:{x:t[12],y:t[13],z:t[14]},rotation:{x:0,y:0,z:0,w:1}})}if(!0===t.isItem&&(i.isItem=!0),!0===t.isMover&&(i.isMover=!0),"function"!=typeof t.canReceive&&"function"!=typeof t.canAccept||(i.isHolder=!0),"function"==typeof t.pickupFrames)try{i.isPickable=t.pickupFrames().length>0}catch{i.isPickable=!1}if("string"==typeof t.toolType||"function"==typeof t.toolType?i.toolType="function"==typeof t.toolType?t.toolType():t.toolType:void 0!==t.toolType&&(i.toolType=String(t.toolType)),t.state&&"object"==typeof t.state){const e={};for(const[n,i]of Object.entries(t.state))"string"!=typeof i&&"number"!=typeof i&&"boolean"!=typeof i&&null!==i||(e[n]=i);i.state=e}if(e){const e=t.components??[];i.childIds=e.map(t=>t.state?.id).filter(Boolean)}return i}function N_(t){function e(t,n){if(!t)return;n.push(F_(t));const i=t.components??[];for(const t of i)e(t,n)}function n(t,e){if(!e)return null;if(e.state?.id===t)return e;const i=e.components??[];for(const e of i){const i=n(t,e);if(i)return i}return null}return{version:"0.1.0",collectComponents(){const n=[];return e(t?.rootModel??t,n),n},getComponent(e){const i=n(e,t?.rootModel??t);if(!i)return null;const s={...F_(i)};if("function"==typeof i.pickupFrames)try{s.pickupFrames=i.pickupFrames()}catch{}if("object"==typeof i.slots)try{s.slots=Array.isArray(i.slots)?i.slots:"function"==typeof i.slots?i.slots():[]}catch{}if("function"==typeof i.acceptanceRotation)try{s.acceptanceWorldQuat=i.deliveryWorldRotation?.(null)??void 0}catch{}if("function"==typeof i.deliveryWorldPosition)try{s.deliveryWorldPosition=i.deliveryWorldPosition(null)}catch{}return s},simStatus(){let e=0;const n=[t?.rootModel??t];for(;n.length>0;){const t=n.pop();if(!t)continue;!0===t.isItem&&e++;const i=t.components??[];for(const t of i)n.push(t)}return{simTime:Ir.now,realTime:"undefined"!=typeof performance?performance.now():Date.now(),speed:Ir.speed,paused:Ir.isPaused,carrierCount:e}},transferLog(){const t={};Wu.flows().forEach((e,n)=>{t[n]=e});const e={};Wu.targetCounts().forEach((t,n)=>{e[n]=t});const n={};return Wu.rejectReasonCounts().forEach((t,e)=>{n[e]=t}),{entries:Wu.toJSON(),stats:Wu.stats(),flows:t,targetCounts:e,rejectReasonCounts:n}},reservations(){const t=[...k_.all()],e={},n={};for(const i of t)(e[i.resource]??=[]).push(i),(n[i.reserverId]??=[]).push(i);for(const t of Object.values(e))t.sort((t,e)=>t.timeWindow.startSimMs-e.timeWindow.startSimMs);for(const t of Object.values(n))t.sort((t,e)=>t.timeWindow.startSimMs-e.timeWindow.startSimMs);return{simTime:Ir.now,all:t,byResource:e,byReserver:n}},conflicts(){const t=k_.conflictLog(),e={},n={};let i=0,s=0;for(const r of t)e[r.resource]=(e[r.resource]??0)+1,n[r.proposed.reserverId]=(n[r.proposed.reserverId]??0)+1,"rejected"===r.outcome?i++:s++;return{simTime:Ir.now,log:[...t],total:t.length,rejected:i,preempted:s,byResource:e,byReserver:n}}}}function H_(t){const e=N_(t);return"undefined"!=typeof window&&(window.__SCENE_INSPECTOR__=e),e}let B_=0;const Y_=new FinalizationRegistry(()=>{B_--});class V_{static get residents(){return B_}static get residentsCount(){return B_}constructor(t,e){this.counters={},this.references={},this.creator=t,this.disposer=e,B_++,Y_.register(this,B_)}dispose(){if(this.disposer)for(const t in this.references)this.disposer(t,this.references[t]);this.references={},this.counters={}}get ids(){return Object.keys(this.references)}create(t){return new Promise((e,n)=>{this.creator?this.creator(t,n=>{n.release=()=>{this.disposer?.(t,n),delete n.release,Ji("RELEASED",t)},e(n)},n):n(Error("Reference id("+t+") could not be created. Reference creator should be defined."))})}add(t,e){const n=new Promise((n,i)=>{const s=this.references[t];if(s)s===e?i(Error("Reference ID and target duplicate")):e?i(Error("Reference ID duplicate")):n(s);else{const s=e=>{e.release=()=>{this.release(e)},this.references[t]=e,this.counters[t]=1,n(e)};if(e)s(e);else{if(!this.creator)return void i(Error("Reference id("+t+") is not allowed. Reference creator should be defined."));this.creator(t,s,i)}}});return this.references[t]||(this.references[t]=n),n}async get(t,e=!1){let n=this.references[t];if(n){if(!(n instanceof Promise)){if(!(t in this.counters))throw new Error("No Reference Count");return this.counters[t]++,n}if(e)return n=await n,this.counters[t]++,n}if(e)return await this.add(t);throw new Error("No References for "+t)}_id(t){for(const e in this.references){if(this.references[e]===t)return e}}release(t){const e=this._id(t);if(!e)return void Qi("No Referenced ID");const n=this.references[e];n&&(this.counters[e]--,0==this.counters[e]&&(this.disposer?.(e,n),delete this.references[e],delete this.counters[e],delete t.release,Ji("RELEASED",e)))}}const G_={},$_={};let U_=[];function W_(t){const e=t.target,n="SCRIPT"===e.tagName?G_:$_,i=e.src||e.href;n[i]=!0,U_.forEach((t,e)=>{if(!t)return;const{resolve:s,scripts:r,styles:o}=t;if(n===G_){const t=r.indexOf(i);t>-1&&t<r.length-1&&X_(r[t+1])}r.some(t=>!G_[t])||o?.some(t=>!$_[t])||(s(),U_[e]=null)}),U_=U_.filter(Boolean)}function q_(t){if("string"==typeof t)return;const e=t.target,n=e.src,i="SCRIPT"===e.tagName?G_:$_;U_.forEach((e,s)=>{if(!e)return;const{reject:r,scripts:o,styles:a}=e;(i===G_&&o.includes(n)||i===$_&&!!a?.includes(n))&&(r(t),U_[s]=null)}),U_=U_.filter(Boolean),delete i[n],document.head.removeChild(e)}function X_(t){G_[t]=!1;const e=document.createElement("script");e.onload=W_,e.onerror=q_,e.type="text/javascript",e.src=t,document.head.appendChild(e)}class K_{static load(t,e){const n="string"==typeof t?[t]:t,i="string"==typeof e?[e]:e;return new Promise(function(t,e){if(n&&!Array.isArray(n)||i&&!Array.isArray(i))return void e(new Error("invalid sources for load"));let s,r=!0;if(i?.forEach(t=>{t in $_||function(t){$_[t]=!1;const e=document.createElement("link");e.onload=W_,e.onerror=q_,e.type="text/css",e.rel="stylesheet",e.media="screen,print",e.href=t,document.head.appendChild(e)}(t),$_[t]||(r=!1)}),n&&n.length>0)for(const t of n)t in G_?G_[t]||(r=!1):s??=t;if(s)X_(s);else if(r)return void t();U_.push({resolve:t,reject:e,scripts:n,styles:i})})}}const Q_="0.0.0";function Z_(t){if(!(t>0))return 1;let e=0;if(!(t&t-1))return t;for(;0!=t;)t>>=1,e+=1;return 1<<e}function J_(e){const{lineWidth:n=0}=e.state;let{width:i,height:s}=e.bounds;i+=n,s+=n;const r=Z_(2*i),o=Z_(2*s),a=Hp(r,o),c=new t.CanvasTexture(a);return tv(a,e,2),c.needsUpdate=!0,c.wrapS=t.RepeatWrapping,c.wrapT=t.RepeatWrapping,c.offset.set(0,1-2*s/o),c.repeat.set(2*i/r,2*s/o),c.magFilter=t.NearestFilter,c.minFilter=t.LinearFilter,c.colorSpace=t.SRGBColorSpace,c}function tv(t,e,n){const{lineWidth:i=0}=e.state;let{left:s,top:r}=e.bounds;s-=i/2,r-=i/2;const o=t.getContext("2d");o.scale(n,n),o.translate(-s,-r),e.render(o),e.postrender(o)}function ev(t,e,n=2){const i=t.getContext("2d");i&&(i.setTransform(1,0,0,1,0,0),i.clearRect(0,0,t.width,t.height),tv(t,e,n))}const nv=new Set(["cx","cy","cz","zPos","left","top","width","height","depth","lineWidth","rotationX","rotationY","rotation","scale","hidden","alpha","material3d","screenFixed"]);class iv extends xu{get syncZPosOffset(){return this.effectiveDepth}get geometricOffsetY(){return this.effectiveDepth}constructor(t){super(t),this._origInvalidate=t.invalidate.bind(t),t.invalidate=()=>{this._origInvalidate(),this._refreshTextureNow()}}getObject3dInstance(){return new t.Mesh}build(){super.build();const{width:e,height:n}=this.component.bounds;if(!e||!n)return;const i=Pd(this.component.state.material3d),s=new t.PlaneGeometry(1,1);s.rotateX(-Math.PI/2),this.object3d.geometry=s;const r=J_(this.component),o=new t.MeshStandardMaterial({map:r});Id(o,i),o.transparent=!0,this.object3d.material=o,this.object3d.castShadow=i.castShadow,this.object3d.receiveShadow=i.receiveShadow}updateDimension(){const{width:t,height:e}=this.component.bounds;this.setDimensionScale(t,1,e)}updateAlpha(){const{alpha:t=1,fillStyle:e}=this.component.state;tu(this.object3d.material,0,e)}_debouncedRebuild(){this._debounceTimer&&clearTimeout(this._debounceTimer),this._debounceTimer=setTimeout(()=>{this._debounceTimer=void 0,this._rebuildTexture()},100)}_rebuildTexture(){this.clear(),this.build(),this.updateTransform(),this.updateDimension(),this.updateHidden()}_refreshTextureNow(){const t=this.object3d.material,e=t?.map;if(!e)return;const n=e.source?.data;n&&(ev(n,this.component,2),e.needsUpdate=!0)}updateFillStyle(){this._debouncedRebuild()}updateStrokeStyle(){this._debouncedRebuild()}updateText(){this._debouncedRebuild()}onchange(t,e){super.onchange(t,e);for(const e of Object.keys(t))if(!nv.has(e)){this._debouncedRebuild();break}}updateMaterial3d(){super.updateMaterial3d();const t=this.object3d.material;if(!t)return;const e=Pd(this.component.state.material3d);Id(t,e),t.transparent=!0,this.object3d.castShadow=e.castShadow,this.object3d.receiveShadow=e.receiveShadow}clear(){return this._debounceTimer&&(clearTimeout(this._debounceTimer),this._debounceTimer=void 0),cu(this.object3d),super.clear()}dispose(){this._debounceTimer&&(clearTimeout(this._debounceTimer),this._debounceTimer=void 0),this._origInvalidate&&(this.component.invalidate=this._origInvalidate,this._origInvalidate=void 0),super.dispose()}}const sv=new Map;function rv(t){return Math.round(1e3*t)/1e3}function ov(e){return new t.Color(e).getHexString()}const av={material(e,n,i){const s=e+"::"+function(t){const e=[];return null!=t.color&&e.push("c"+ov(t.color)),null!=t.metalness&&e.push("m"+rv(t.metalness)),null!=t.roughness&&e.push("r"+rv(t.roughness)),null!=t.opacity&&e.push("o"+rv(t.opacity)),null!=t.emissive&&e.push("E"+ov(t.emissive)),null!=t.emissiveIntensity&&e.push("I"+rv(t.emissiveIntensity)),null!=t.envMapIntensity&&e.push("e"+rv(t.envMapIntensity)),null!=t.side&&e.push("s"+t.side),t.transparent&&e.push("t"),t.flatShading&&e.push("f"),!1===t.depthWrite&&e.push("dw0"),t.map&&e.push("M"+(t.map.uuid??"")),e.join("|")}(n);let r=sv.get(s);return r||sv.set(s,r=function(e){const n=new t.MeshStandardMaterial;return n.userData.__bankOwned=!0,null!=e.color&&n.color.set(e.color),null!=e.emissive&&n.emissive.set(e.emissive),null!=e.metalness&&(n.metalness=e.metalness),null!=e.roughness&&(n.roughness=e.roughness),null!=e.emissiveIntensity&&(n.emissiveIntensity=e.emissiveIntensity),null!=e.envMapIntensity&&(n.envMapIntensity=e.envMapIntensity),null!=e.side&&(n.side=e.side),null!=e.map&&(n.map=e.map),null!=e.flatShading&&(n.flatShading=e.flatShading),null!=e.depthWrite&&(n.depthWrite=e.depthWrite),null!=e.opacity&&(n.opacity=e.opacity),null!=e.transparent?n.transparent=e.transparent:null!=e.opacity&&e.opacity<1&&(n.transparent=!0),n}(n)),null==i?r:Xd(r,{color:i})},get size(){return sv.size},has(t){const e=t+"::";for(const t of sv.keys())if(t.startsWith(e))return!0;return!1},dispose(){for(const t of sv.values())Qd(t),t.dispose();sv.clear()}};class cv extends xu{getObject3dInstance(){return new t.Mesh}build(){super.build(),this.buildGeometry(),this.buildMaterial(),this.updateDimension()}updateAlpha(){if(this.canShareMaterial)return void super.updateAlpha();const{alpha:t=1,fillStyle:e}=this.component.state;tu(this.object3d.material,0,e)}updateFillStyle(){if(this.canShareMaterial)return this.applyBankMaterial(),void this.applyMaterialOpacity();const{fillStyle:t,alpha:e=1}=this.component.state,n=this.object3d.material;if(!n)return;const i=xu.buildFillStyleTexture(this.component);i?(n.map&&n.map.dispose(),i.needsUpdate=!0,n.map=i,n.needsUpdate=!0):"string"==typeof t&&(n.map&&(n.map.dispose(),n.map=null,n.needsUpdate=!0),"transparent"!==t&&"none"!==t&&n.color.set(eu(t))),tu(n,0,t)}updateStrokeStyle(){const e=this.object3d.getObjectByName("__edgeLines__");e&&(this.object3d.remove(e),cu(e));const{strokeStyle:n}=this.component.state;if(!n||"transparent"===n||"none"===n)return;const i=this.object3d.geometry;if(!i?.getAttribute("position"))return;const s=new t.EdgesGeometry(i),r=new t.LineBasicMaterial({color:n}),o=new t.LineSegments(s,r);o.name="__edgeLines__",this.object3d.add(o)}updateDimension(){const{width:t,height:e}=this.component.bounds,{depth:n=1}=this.component.state;if(!this.object3d)return;this.object3d.geometry.computeBoundingBox();const i=this.object3d.geometry.boundingBox;if(i){const s=i.max.x-i.min.x,r=i.max.y-i.min.y,o=i.max.z-i.min.z;this.setDimensionScale(t/s,n/r,e/o)}}get canShareMaterial(){return void 0===this.materialSharingIssue}get materialSharingIssue(){const{fillStyle:t}=this.component.state;if(!t||"object"!=typeof t)return;const e=t.type;return"pattern"===e?"무늬(pattern) fillStyle 은 인스턴스마다 캔버스 텍스처가 필요하다":"gradient"===e?"그라디언트 fillStyle 은 인스턴스마다 캔버스 텍스처가 필요하다":`fillStyle 이 색 문자열이 아니다 (type: ${String(e)})`}get requiresSharedMaterial(){return!0===this.component.constructor.requiresSharedMaterial}get materialSharing(){const t=this.materialSharingIssue,e=void 0===t,n=this.requiresSharedMaterial,i={shared:e,required:n,violated:n&&!e};return void 0!==t&&(i.reason=t),e&&(i.bankKey=this.materialBankKey),i}get materialBankKey(){return`mesh|${this.component.state.type??"unknown"}`}materialSpec(){const t=Pd(this.component.state.material3d),e=Jd(this.component.state.fillStyle);return{metalness:t.metalness,roughness:t.roughness,emissive:t.emissive,emissiveIntensity:t.emissiveIntensity,envMapIntensity:t.envMapIntensity,side:Dd(t.side),flatShading:t.flatShading,opacity:e,transparent:e<1}}buildMaterial(){if(!this.canShareMaterial){const e=Pd(this.component.state.material3d),n=new t.MeshStandardMaterial({transparent:!0});return Id(n,e),void(this.object3d.material=n)}this.applyBankMaterial()}applyBankMaterial(){const{fillStyle:t}=this.component.state,e=Jd(t)>0&&"string"==typeof t?eu(t):void 0;Kd(this.object3d),this.object3d.material=av.material(this.materialBankKey,this.materialSpec(),e)}updateMaterial3d(){if(super.updateMaterial3d(),this.canShareMaterial)return this.applyBankMaterial(),void this.applyMaterialOpacity();const t=this.object3d.material;t&&Id(t,Pd(this.component.state.material3d))}clear(){return Kd(this.object3d),cu(this.object3d),super.clear()}}function lv(t,e,n,i){return[["bold",t],["italic",e],[n+"px",!0],[i,!0]].filter(t=>t[1]).map(t=>t[0]).join(" ")}function hv(t){let e=0;if(!((t=Math.abs(t)||1)&t-1))return t;for(;0!=t;)t>>=1,e+=1;return 1<<e}function dv(t,e,n){const{bold:i=!1,italic:s=!1,fontFamily:r="Serif",fontSize:o=10,fontColor:a="black",textAlign:c="center",textBaseline:l="middle",width:h=t.width,height:d=t.height,offsetX:u=0,offsetY:p=0}=n||{},f=t.getContext("2d");let m,g;f.imageSmoothingEnabled=!1,f.fillStyle=a,f.strokeStyle=a,f.font=lv(i,s,o,r),"left"===c||"start"===c?(f.textAlign="left",m=u):"right"===c||"end"===c?(f.textAlign="right",m=u+h):(f.textAlign="center",m=u+h/2);const y=1.2*o,b=String(e).split("\n"),_=y*b.length;g="top"===l||"hanging"===l?p+.1*o:"bottom"===l||"alphabetic"===l?p+d-_+.1*o:p+(d-_)/2+.1*o,f.textBaseline="top";for(const t of b)f.fillText(t,m,g),g+=y}function uv(e,n,i,s){const r=hv(2*n),o=hv(2*i),a=Hp(r,o),c=a.getContext("2d"),{fillStyle:l}=s||{};if(l&&"object"==typeof l&&l.colorStops?.length){const t=lu(l,2*n,2*i);t&&c.drawImage(t,0,0)}c.scale(2,2),"string"==typeof l&&""!==l&&"transparent"!==l&&(c.fillStyle=l,c.fillRect(0,0,n,i)),dv(a,e,s);const h=new t.CanvasTexture(a);return h.needsUpdate=!0,h.wrapS=t.RepeatWrapping,h.wrapT=t.RepeatWrapping,h.offset.set(0,1-2*i/o),h.repeat.set(2*n/r,2*i/o),h.minFilter=t.LinearFilter,h.colorSpace=t.SRGBColorSpace,h}function pv(e,n,i,s,r,o,a){const c=new Image;c.crossOrigin="anonymous",c.onload=()=>{const e=2*i,l=2*s,h=hv(e),d=hv(l),u=Hp(h,d),p=u.getContext("2d");if(o.color&&(p.fillStyle=o.color,p.fillRect(0,0,e,l)),o.fitPattern)p.drawImage(c,0,0,e,l);else{const t=2*(o.width||c.naturalWidth),n=2*(o.height||c.naturalHeight),i=2*(o.offsetX||0),s=2*(o.offsetY||0);let r=0,a=0;switch(o.align){case"center":r=(e-t)/2,a=(l-n)/2;break;case"left-top":break;case"left-bottom":a=l-n;break;case"right-top":r=e-t;break;case"right-bottom":r=e-t,a=l-n;break;case"left":a=(l-n)/2;break;case"right":r=e-t,a=(l-n)/2;break;case"top":r=(e-t)/2;break;case"bottom":r=(e-t)/2,a=l-n}const h=i+r,d=s+a;if(o.noRepeat)p.drawImage(c,0,0,c.naturalWidth,c.naturalHeight,h,d,t,n);else{p.save(),p.rect(0,0,e,l),p.clip();const i=h>0?h-Math.ceil(h/t)*t:h;for(let s=d>0?d-Math.ceil(d/n)*n:d;s<l;s+=n)for(let r=i;r<e;r+=t)p.drawImage(c,0,0,c.naturalWidth,c.naturalHeight,r,s,t,n);p.restore()}}n&&(p.scale(2,2),dv(u,n,r));const f=new t.CanvasTexture(u);f.needsUpdate=!0,f.wrapS=t.RepeatWrapping,f.wrapT=t.RepeatWrapping,f.offset.set(0,1-l/d),f.repeat.set(e/h,l/d),f.minFilter=t.LinearFilter,f.colorSpace=t.SRGBColorSpace,a(f)},c.onerror=()=>{const t=uv(n,i,s,r);a(t)},c.src=e}function fv(t,e){let{bold:n=!1,italic:i=!1,fontFamily:s="Serif",fontSize:r=10,lineHeight:o="normal"}=e||{};t=void 0===t||""==t?" ":String(t);const a=document.createElement("span");a.style.font=lv(n,i,r,s),a.style.lineHeight=String(o),a.style.whiteSpace="pre",a.style.position="absolute",a.textContent=t,document.body.appendChild(a);const c=a.getBoundingClientRect();return document.body.removeChild(a),{width:c.width,height:c.height}}class mv extends cv{get zPriority(){return fu.DECAL}get syncZPosOffset(){return this.effectiveDepth}get geometricOffsetY(){return this.effectiveDepth}buildGeometry(){this.updateDimension()}updateStrokeStyle(){}updateFillStyle(){this.updateText()}updateDimension(){const{width:e,height:n}=this.component.state,i=Math.abs(e)||1,s=Math.abs(n)||1;this.object3d.geometry&&this.object3d.geometry.dispose();const r=new t.PlaneGeometry(i,s);r.rotateX(-Math.PI/2),this.object3d.geometry=r}updateText(){const t=this.object3d.material;if(!t)return;const{width:e,height:n,bold:i=!1,italic:s=!1,fontFamily:r="Serif",fontSize:o=10,fontColor:a="black",textAlign:c="center",textBaseline:l="middle",fillStyle:h}=this.component.state,d=Math.abs(e)||1,u=Math.abs(n)||1,p=this.component.text,f=h&&"none"!==h?h:"transparent",m={bold:i,italic:s,fontFamily:r,fontSize:o,fontColor:a,textAlign:c,textBaseline:l,width:d,height:u,fillStyle:f};if("object"==typeof f&&"pattern"===f?.type&&f.image){return void pv(this.component.app.url(h.image),p,d,u,m,h,e=>{t.map&&t.map.dispose(),t.map=e,t.color.set(16777215),t.needsUpdate=!0})}const g=uv(p,d,u,m);g?(t.map&&t.map.dispose(),t.map=g,t.color.set(16777215),g.needsUpdate=!0):"string"==typeof h&&(""!==h&&"transparent"!==h?t.color.set(eu(h)):t.opacity=0)}updateAlpha(){const t=this.object3d.material;t.opacity=1,t.transparent=!0,super.applyMaterialOpacity()}}Kp("text",t=>new mv(t));const gv={input:"css3d",select:"css3d",textarea:"css3d",button:"css3d",iframe:"css3d",video:"css3d",label:"texture",table:"texture",progress:"texture"};function yv(t){const e=t.model?.type??"";return"texture"===(gv[e]??"css3d")?new iv(t):new Wp(t)}Kp("html-overlay-element",yv),Kp("html-overlay-container",yv);class bv{setShape({extrudedShape:e,extrudedOptions:n}){this.extrudedShape=e,this.bb=new t.Box2,this.bb.setFromPoints(this.extrudedShape?.extractPoints(0).shape),this.extrudedOptions=n}generateTopUV(e,n,i,s,r){const o=n[3*i],a=n[3*i+1],c=n[3*s],l=n[3*s+1],h=n[3*r],d=n[3*r+1],u=this.bb,p=u.max.x-u.min.x,f=u.max.y-u.min.y;return[new t.Vector2((o-u.min.x)/p,1-(a-u.min.y)/f),new t.Vector2((c-u.min.x)/p,1-(l-u.min.y)/f),new t.Vector2((h-u.min.x)/p,1-(d-u.min.y)/f)]}generateSideWallUV(e,n,i,s,r,o){const a=n[3*i],c=n[3*i+1],l=n[3*i+2],h=n[3*s],d=n[3*s+1],u=n[3*s+2],p=n[3*r],f=n[3*r+1],m=n[3*r+2],g=n[3*o],y=n[3*o+1],b=n[3*o+2],_=this.extrudedOptions?.depth||100,v=this.bb,x=v.max.x-v.min.x,w=v.max.y-v.min.y;return Math.abs(c-d)<.01?[new t.Vector2(a/x,1-l/_),new t.Vector2(h/x,1-u/_),new t.Vector2(p/x,1-m/_),new t.Vector2(g/x,1-b/_)]:[new t.Vector2(c/w,1-l/_),new t.Vector2(d/w,1-u/_),new t.Vector2(f/w,1-m/_),new t.Vector2(y/w,1-b/_)]}}function _v(t,e){const n=t/2,i=e/2;return{points:[{x:-n,y:-i},{x:n,y:-i},{x:n,y:i},{x:-n,y:i}]}}function vv(t,e,n){const i=Math.max(3,Math.floor(n)),s=[];for(let n=0;n<i;n++){const r=n/i*Math.PI*2;s.push({x:t*Math.cos(r),y:e*Math.sin(r)})}return{points:s,segments:i}}function xv(t){if(0===t.length)return[];let e=1/0,n=1/0,i=-1/0,s=-1/0;for(const r of t)r.x<e&&(e=r.x),r.x>i&&(i=r.x),r.y<n&&(n=r.y),r.y>s&&(s=r.y);const r=(e+i)/2,o=(n+s)/2,a=t.map(t=>({x:t.x-r,y:t.y-o})),c=a[0],l=a[a.length-1];return a.length>1&&Math.abs(c.x-l.x)<1e-9&&Math.abs(c.y-l.y)<1e-9&&a.pop(),a}class wv extends xu{clear(){return this._mesh=void 0,super.clear()}get shape(){return null}topOutline(){const t=this.shape;if(!t||"function"!=typeof t.getPoints)return null;const e=this.outlineDivisions,n=t.getPoints(e);if(!n||n.length<3)return null;const i=xv(n);return i.length<3?null:{points:i}}get outlineDivisions(){return 12}get boundUVGenerator(){return this._boundUVGenerator||(this._boundUVGenerator=new bv),this._boundUVGenerator}build(){super.build();const e=this.effectiveDepth,n=this.shape;if(!n)return;const i=this.boundUVGenerator;i&&i.setShape({extrudedShape:n,extrudedOptions:{depth:e}});const s=this.createGeometry(n),r=this.createMaterials();this._mesh=new t.Mesh(s,r),this._mesh.rotation.x=-Math.PI/2,this._mesh.rotation.y=-Math.PI,this._mesh.rotation.z=-Math.PI,this._mesh.castShadow=!0,this.object3d.add(this._mesh),this.updateFillStyle(),this.updateStrokeStyle()}createGeometry(e){const n=this.effectiveDepth,{lineWidth:i=0}=this.component.state,s={steps:1,depth:n,bevelEnabled:i>0,bevelThickness:0,bevelSize:i,bevelSegments:1,UVGenerator:this.boundUVGenerator},r=new t.ExtrudeGeometry(e,s);return r.center(),r}createMaterials(){const e=Pd(this.component.state.material3d),n=new t.MeshStandardMaterial;Id(n,e);const i=new t.MeshStandardMaterial;return Id(i,e),[n,i]}createTexture(){const{width:e,height:n}=this.component.bounds,i=hv(e),s=hv(n),r=Hp(i,s);this.component.render(r.getContext("2d"));const o=new t.CanvasTexture(r);return o.needsUpdate=!0,o.wrapS=t.RepeatWrapping,o.wrapT=t.RepeatWrapping,o.offset.set(0,1-n/s),o.repeat.set(e/i,n/s),o.minFilter=t.LinearFilter,o}getMaterials(){if(!this._mesh)return;const t=this._mesh.material;return Array.isArray(t)?t:void 0}updateMaterial3d(){super.updateMaterial3d();const t=this.getMaterials();if(!t)return;const e=Pd(this.component.state.material3d);for(const n of t)Id(n,e)}updateAlpha(){const{alpha:t=1,fillStyle:e,strokeStyle:n}=this.component.state,i=this.getMaterials();i&&(tu(i[0],0,e),tu(i[1],0,n))}updateStrokeStyle(){const t=this.getMaterials();if(!t)return;const{strokeStyle:e}=this.component.state;t[1].color.set(eu(e))}updateFillStyle(){this._applyCapTexture()}updateText(){this._applyCapTexture()}_applyCapTexture(){const t=this.getMaterials();if(!t)return;const e=t[0],{fillStyle:n}=this.component.state,i=this.component.hasTextProperty?this.component.text:"";if(!i){const t=xu.buildFillStyleTexture(this.component);return t?(e.map&&e.map.dispose(),e.map=t,e.color.set(16777215)):(e.map&&(e.map.dispose(),e.map=null),e.color.set(eu(n))),void(e.needsUpdate=!0)}const{bold:s=!1,italic:r=!1,fontFamily:o="Serif",fontSize:a=10,fontColor:c="black",textAlign:l="center",textBaseline:h="middle",paddingTop:d=0,paddingLeft:u=0,paddingRight:p=0,paddingBottom:f=0}=this.component.state,{width:m,height:g}=this.component.bounds,y=Math.abs(m)||1,b=Math.abs(g)||1,_={bold:s,italic:r,fontFamily:o,fontSize:a,fontColor:c,textAlign:l,textBaseline:h,width:Math.max(y-u-p,0),height:Math.max(b-d-f,0),fillStyle:n,offsetX:u,offsetY:d};if("object"==typeof n&&"pattern"===n?.type&&n.image){return void pv(this.component.app.url(n.image),i,y,b,_,n,t=>{e.map&&e.map.dispose(),e.map=t,e.color.set(16777215),e.needsUpdate=!0})}e.map&&e.map.dispose();const v=uv(i,y,b,_);e.map=v,e.color.set(16777215),e.needsUpdate=!0}updateDimension(){super.updateDimension()}onchange(t,e){if("path"in t&&this._mesh){const t=this._mesh.geometry,e=this.shape;if(e){const n=this.createGeometry(e);this._mesh.geometry=n,t.dispose()}}super.onchange(t,e)}}class Mv extends wv{get shape(){const{cx:e=0,cy:n=0,rx:i=1,ry:s=1,startAngle:r=0,endAngle:o=2*Math.PI,anticlockwise:a=!1}=this.component.state,c=new t.EllipseCurve(e,n,Math.abs(i),Math.abs(s),r,o,a,0);return new t.Shape(c.getPoints(50))}}Kp("ellipse",t=>new Mv(t));class Sv extends wv{get shape(){const{width:e,height:n,round:i=0}=this.component.state,s=Pc(i,e,n);if(s>0){const i=s,r=new t.Path;return r.moveTo(i,0),r.lineTo(e-i,0),r.quadraticCurveTo(e,0,e,i),r.lineTo(e,n-i),r.quadraticCurveTo(e,n,e-i,n),r.lineTo(i,n),r.quadraticCurveTo(0,n,0,n-i),r.lineTo(0,i),r.quadraticCurveTo(0,0,i,0),new t.Shape(r.getPoints(12))}const r=new t.Shape;return r.moveTo(0,0),r.lineTo(e,0),r.lineTo(e,n),r.lineTo(0,n),r.lineTo(0,0),r}}function kv(e,n={}){const i=n.round??0,s=n.divisions??24;if(!e||0===e.length)return new t.Shape;const r=e.some(t=>Xr(t)),o=i>0||e.some(t=>Jr(t,0)>0);if(r||o){const n=new t.Path;for(let t=0;t<e.length;t++){const s=e[(t-1+e.length)%e.length],r=e[t],o=e[(t+1)%e.length];if(s.x===r.x&&s.y===r.y)continue;const a=Jr(r,i);let c=Math.sqrt((s.x-r.x)**2+(s.y-r.y)**2),l=0!==c?Math.atan2(s.x-r.x,s.y-r.y):0;const h=Math.sin(l)*Math.min(a,c/2)+r.x,d=Math.cos(l)*Math.min(a,c/2)+r.y;c=Math.sqrt((o.x-r.x)**2+(o.y-r.y)**2),l=0!==c?Math.atan2(o.x-r.x,o.y-r.y):0;const u=Math.sin(l)*Math.min(a,c/2)+r.x,p=Math.cos(l)*Math.min(a,c/2)+r.y;if(0===t?n.moveTo(h,d):n.lineTo(h,d),a>0&&n.quadraticCurveTo(r.x,r.y,u,p),Xr(r)){const t=Jr(o,i),e=Math.sqrt((r.x-o.x)**2+(r.y-o.y)**2),s=0!==e?Math.atan2(r.x-o.x,r.y-o.y):0,a=Kr({x:u,y:p},{x:Math.sin(s)*Math.min(t,e/2)+o.x,y:Math.cos(s)*Math.min(t,e/2)+o.y},r.bulge);a&&n.absarc(a.cx,a.cy,a.radius,a.startAngle,a.endAngle,a.clockwise)}}return new t.Shape(n.getPoints(s))}const a=new t.Shape;for(let t=0;t<e.length;t++)0===t?a.moveTo(e[t].x,e[t].y):a.lineTo(e[t].x,e[t].y);return a}Kp("rect",t=>new Sv(t));class Av extends wv{get shape(){const{path:t=[],round:e=0}=this.component.state;return kv(t,{round:e,divisions:24})}build(){Object.getPrototypeOf(wv.prototype).build.call(this);const e=this.effectiveDepth,n=this.shape;if(!n)return;const i=this.boundUVGenerator,s=this.minMax;if(i&&void 0!==s.minX&&void 0!==s.maxX&&void 0!==s.minY&&void 0!==s.maxY){const n=new t.Shape;n.moveTo(s.minX,s.minY),n.lineTo(s.maxX,s.minY),n.lineTo(s.maxX,s.maxY),n.lineTo(s.minX,s.maxY),n.closePath(),i.setShape({extrudedShape:n,extrudedOptions:{depth:e}})}else i&&i.setShape({extrudedShape:n,extrudedOptions:{depth:e}});const r=this.createGeometry(n),o=this.createMaterials();this._mesh=new t.Mesh(r,o),this._mesh.rotation.x=-Math.PI/2,this._mesh.rotation.y=-Math.PI,this._mesh.rotation.z=-Math.PI,this._mesh.castShadow=!0,this.object3d.add(this._mesh),this.updateFillStyle(),this.updateStrokeStyle()}createGeometry(e){const n=this.effectiveDepth,{lineWidth:i=0}=this.component.state,s={steps:1,depth:n,bevelEnabled:i>0,bevelThickness:0,bevelSize:i,bevelSegments:1,UVGenerator:this.boundUVGenerator},r=new t.ExtrudeGeometry(e,s),o=this.minMax;if(void 0!==o.minX&&void 0!==o.maxX&&void 0!==o.minY&&void 0!==o.maxY){const t=(o.minX+o.maxX)/2,e=(o.minY+o.maxY)/2;r.translate(-t,-e,0),r.computeBoundingBox();const n=r.boundingBox;n&&r.translate(0,0,-(n.min.z+n.max.z)/2)}else r.center();return r}get minMax(){if(!this._minMax){const{path:t}=this.component.state;let e,n,i,s;t.forEach((t,r)=>{if(0==r)return e=i=t.x,void(n=s=t.y);e=Math.min(e,t.x),i=Math.max(i,t.x),n=Math.min(n,t.y),s=Math.max(s,t.y)}),this._minMax={minX:e,minY:n,maxX:i,maxY:s}}return this._minMax}}Kp("polygon",t=>new Av(t));class Ev extends wv{get shape(){const{cx:e=0,cy:n=0,rx:i=1,ry:s=1,ratio:r=50,startAngle:o=0,endAngle:a=2*Math.PI,anticlockwise:c=!1}=this.component.state,l=Math.abs(i),h=Math.abs(s),d=new t.EllipseCurve(e,n,l,h,o,a,c,0),u=new t.Shape(d.getPoints(50)),p=l/100*r,f=h/100*r;if(p>0&&f>0){const i=new t.EllipseCurve(e,n,p,f,o,a,c,0),s=new t.Path(i.getPoints(50));u.holes.push(s)}return u}}Kp("donut",t=>new Ev(t));class Cv extends wv{get shape(){const{x1:e=0,y1:n=0,x2:i=0,y2:s=0,x3:r=0,y3:o=0,round:a=0}=this.component.state,c=[{x:e,y:n},{x:i,y:s},{x:r,y:o}];if(a>0){const e=new t.Path;for(let t=0;t<c.length;t++){const n=c[(t-1+c.length)%c.length],i=c[t],s=c[(t+1)%c.length];let r=Math.sqrt((n.x-i.x)**2+(n.y-i.y)**2),o=0!==r?Math.atan2(n.x-i.x,n.y-i.y):0;const l=Math.sin(o)*Math.min(a,r/2)+i.x,h=Math.cos(o)*Math.min(a,r/2)+i.y;r=Math.sqrt((s.x-i.x)**2+(s.y-i.y)**2),o=0!==r?Math.atan2(s.x-i.x,s.y-i.y):0;const d=Math.sin(o)*Math.min(a,r/2)+i.x,u=Math.cos(o)*Math.min(a,r/2)+i.y;0===t?e.moveTo(l,h):e.lineTo(l,h),e.quadraticCurveTo(i.x,i.y,d,u)}return new t.Shape(e.getPoints(12))}const l=new t.Shape;return l.moveTo(e,n),l.lineTo(i,s),l.lineTo(r,o),l.closePath(),l}}Kp("triangle",t=>new Cv(t));class Tv extends wv{get shape(){const{ratio:e=30,wing:n=5,cx:i=0,cy:s=0,rx:r=1,ry:o=1}=this.component.state;if(n<3)return null;const a=Math.PI/2,c=2*Math.PI/n,l=r-e/100*r,h=o-e/100*o,d=new t.Shape;d.moveTo(i+r*Math.cos(-a),s+o*Math.sin(-a)),d.lineTo(i+(r-l)*(Math.cos(c-a)+Math.cos(0-a))/2,s+(o-h)*(Math.sin(c-a)+Math.sin(0-a))/2);for(let t=1;t<n;t++)d.lineTo(i+r*Math.cos(c*t-a),s+o*Math.sin(c*t-a)),d.lineTo(i+(r-l)*(Math.cos(c*(t+1)-a)+Math.cos(c*t-a))/2,s+(o-h)*(Math.sin(c*(t+1)-a)+Math.sin(c*t-a))/2);return d.closePath(),d}}Kp("star",t=>new Tv(t));const Pv=new Map;function Ov(t){return t.userData.__bankOwned=!0,t}const Dv={primitive(e){const n="primitive::"+function(t){switch(t.kind){case"cylinder":return`cylinder|${t.segments??0}`;case"sphere":return`sphere|${t.segments??0}|${t.heightSegments??0}`;default:return t.kind}}(e);let i=Pv.get(n);return i||Pv.set(n,i=Ov(function(e){switch(e.kind){case"box":return new t.BoxGeometry(1,1,1);case"plane":return new t.PlaneGeometry(1,1);case"cylinder":return new t.CylinderGeometry(.5,.5,1,e.segments??16);case"sphere":return new t.SphereGeometry(.5,e.segments??16,e.heightSegments??Math.max(2,Math.round((e.segments??16)/2)))}}(e))),i},shaped(t,e){const n="shaped::"+t;let i=Pv.get(n);return i||Pv.set(n,i=Ov(e())),i},owns:t=>!0===t.userData?.__bankOwned,get size(){return Pv.size},has:t=>Pv.has("primitive::"+t)||Pv.has("shaped::"+t),dispose(){for(const t of Pv.values())t.dispose();Pv.clear()}},Iv=[8,12,16],zv={cylinder:25,sphere:32},Rv=3,jv=128;function Lv(t,e){return"number"==typeof t&&Number.isFinite(t)?Math.min(jv,Math.max(3,Math.floor(t))):e}function Fv(t,e){return"number"==typeof t&&Number.isFinite(t)?Math.min(jv,Math.max(2,Math.floor(t))):Math.max(2,Math.round(e/2))}function Nv(t){return Iv.includes(t)}const Hv={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"number",label:"segments",name:"segments",property:"segments"},{type:"number",label:"height-segments",name:"heightSegments",property:"heightSegments"}],help:"scene/component/sphere"};class Bv extends cv{buildGeometry(){const t=this.component.state,e=Lv(t.segments,zv.sphere),n=Fv(t.heightSegments,e);this.object3d.geometry=Dv.primitive({kind:"sphere",segments:e,heightSegments:n})}updateDimension(){const{rx:t=0,ry:e=0,rz:n}=this.component.state,i=n??t;this.setDimensionScale(2*t,2*i,2*e)}get effectiveDepth(){const{rx:t=0,rz:e}=this.component.state,n=e??t;return Math.max(2*n,1)}topOutline(){const{rx:t=0,ry:e=0}=this.component.state;if(!(t>0&&e>0))return null;return vv(t,e,Lv(this.component.state.segments,zv.sphere))}}let Yv=class extends bg{get hasTextProperty(){return!1}is3dish(){return!0}buildRealObject(){return new Bv(this)}get nature(){return Hv}};Yv=Wm([Dy("sphere")],Yv);class Vv extends xu{getObject3dInstance(){return new t.Sprite}build(){super.build(),this.buildMaterial()}get cz(){const{zPos:t=0}=this.component.state,{height:e}=this.component.bounds,{tz:n=0}=this.component.delta(),i=this.component.parent?._realObject;return t+n+e/2-(i?.geometricOffsetY??0)}get geometricOffsetY(){const{height:t=0}=this.component.bounds;return t/2}updateAlpha(){const{alpha:t=1,fillStyle:e}=this.component.state;tu(this.object3d.material,0,e)}updateFillStyle(){const{fillStyle:t}=this.component.state,e=this.object3d.material;if(!e)return;const n=xu.buildFillStyleTexture(this.component);n?(e.map&&e.map.dispose(),n.needsUpdate=!0,e.map=n):"string"==typeof t&&("transparent"!==t?e.color.set(eu(t)):e.opacity=0)}}class Gv extends Vv{buildMaterial(){const e=this.object3d.material;e&&e.dispose(),this.object3d.material=new t.SpriteMaterial({map:J_(this.component),alphaTest:.01,sizeAttenuation:!1})}get scale(){const{width:t,height:e}=this.component.bounds,n=this.threeContainer,{width:i=1,height:s=1}=n?.bounds??{},{scale:r=1}=this.component.state;return{x:r*t/i,y:r*e/s,z:r}}update(){this.build(),this.updateHidden()}updateFillStyle(){this.update()}updateStrokeStyle(){this.update()}updateAlpha(){this.update()}updateText(){this.update()}}const $v={mutable:!1,resizable:!0,rotatable:!0,properties:[]};let Uv=class extends(Oc(Tc)){get hasTextProperty(){return!1}is3dish(){return!0}buildRealObject(){return new Gv(this)}get nature(){return $v}};Uv=Wm([Dy("sprite")],Uv);const Wv={mutable:!1,resizable:!0,rotatable:!0,properties:[],help:"scene/component/cube"};class qv extends cv{buildGeometry(){this.object3d.geometry=Dv.primitive({kind:"box"})}topOutline(){const{width:t=0,height:e=0}=this.component.state;return t>0&&e>0?_v(t,e):null}}let Xv=class extends(Oc(Tc)){get hasTextProperty(){return!1}is3dish(){return!0}buildRealObject(){return new qv(this)}get nature(){return Wv}};Xv=Wm([Dy("cube")],Xv);const Kv={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"number",label:"segments",name:"segments",property:"segments"}],help:"scene/component/cylinder"};class Qv extends cv{buildGeometry(){const t=Lv(this.component.state.segments,zv.cylinder);this.object3d.geometry=Dv.primitive({kind:"cylinder",segments:t})}updateDimension(){const{rx:t=0,ry:e=0,depth:n=1}=this.component.state;this.setDimensionScale(2*t,n,2*e)}topOutline(){const{rx:t=0,ry:e=0}=this.component.state;if(!(t>0&&e>0))return null;return vv(t,e,Lv(this.component.state.segments,zv.cylinder))}}let Zv=class extends bg{get hasTextProperty(){return!1}is3dish(){return!0}buildRealObject(){return new Qv(this)}get nature(){return Kv}};Zv=Wm([Dy("cylinder")],Zv);const Jv={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"color",label:"box-color",name:"boxColor",property:"boxColor"}],help:"scene/component/banner"};class tx extends xu{get zPriority(){return fu.DECAL}build(){super.build();const{width:t=1,height:e=1,depth:n=1}=this.component.state;this.object3d.add(this.createCube(t,e,n));const i=this.createTextureBoard(t,n);i.position.set(0,0,.5*e+1),this.object3d.add(i)}createCube(e,n,i){const{boxColor:s="#ccaa76"}=this.component.state,r=Pd(this.component.state.material3d),o=new t.BoxGeometry(e,i,n),a=new t.MeshStandardMaterial({color:s,side:t.FrontSide});Id(a,r);const c=new t.Mesh(o,a);return c.castShadow=r.castShadow,c.receiveShadow=r.receiveShadow,c}createTextureBoard(e,n){const i=Pd(this.component.state.material3d),{fillStyle:s="#ccaa76"}=this.component.state,r=xu.buildFillStyleTexture(this.component),o=new t.MeshStandardMaterial(r?{map:r}:{color:s||"#ccaa76",side:t.FrontSide});Id(o,i);const a=new t.PlaneGeometry(e,n,1,1),c=new t.Mesh(a,o);return c.castShadow=i.castShadow,c.receiveShadow=i.receiveShadow,c}updateMaterial3d(){super.updateMaterial3d();const t=Pd(this.component.state.material3d);this.object3d.traverse(e=>{if(e.isMesh){const n=e.material;n&&Id(n,t),e.castShadow=t.castShadow,e.receiveShadow=t.receiveShadow}})}updateFillStyle(){this.update()}onchange(t,e){super.onchange(t,e),"boxColor"in t&&this.update()}}let ex=class extends(Oc(Tc)){get hasTextProperty(){return!1}is3dish(){return!0}get nature(){return Jv}buildRealObject(){return new tx(this)}};var nx;ex=Wm([Dy("banner")],ex);const ix={far:1e5,fov:80,near:1,zoom:1},sx={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"number",label:"near",name:"near"},{type:"number",label:"far",name:"far"},{type:"number",label:"fov",name:"fov"},{type:"number",label:"zoom",name:"zoom"},{type:"checkbox",label:"show-helper",name:"showHelper"}],help:"scene/component/camera"};class rx extends xu{getObject3dInstance(){return new t.Mesh}updateCamera(){const{near:e=ix.near,far:n=ix.far,fov:i=ix.fov,zoom:s=ix.zoom,showHelper:r}=this.component.state;this.camera.far=n,this.camera.fov=i,this.camera.near=e,this.camera.zoom=s,r?this.helper||(this.helper=new t.CameraHelper(this.camera),this.object3d.add(this.helper)):this.helper&&(this.object3d.remove(this.helper),delete this.helper)}build(){super.build();const{width:e=0,height:n=0,depth:i=0,fillStyle:s="lightgray"}=this.component.state;this.object3d.geometry=new t.BoxGeometry(e,i,n);const r=Pd(this.component.state.material3d),o=new t.MeshStandardMaterial({color:s});Id(o,r),this.object3d.material=o,this.object3d.castShadow=r.castShadow,this.object3d.receiveShadow=r.receiveShadow,this.camera=new t.PerspectiveCamera,this.camera.position.set(0,0,0),this.object3d.add(this.camera),this.object3d.lookAt(0,0,0),this.updateCamera()}updateMaterial3d(){super.updateMaterial3d();const t=this.object3d.material;if(!t)return;const e=Pd(this.component.state.material3d);Id(t,e),this.object3d.castShadow=e.castShadow,this.object3d.receiveShadow=e.receiveShadow}}let ox=nx=class extends(Oc(Tc)){get hasTextProperty(){return!1}is3dish(){return!0}static get image(){return nx._image||(nx._image=new Image,nx._image.src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA1IAAANSAQMAAABV6G1EAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAABlBMVEX6+voBAQGV71ZvAAAFO0lEQVR42u3dMZLkNBiGYakUKFRIqKOISxDvETiCTBEQcgQOQE7clyAi8REm7KDXIhgYoMa/7fbIX+2K9w022MCP/25Z28GW5RwRERERERERERERERERERERERERERERERERERERERERERERERHRl9mv7fdPn7879sf8Mcq3J3r5EJXaUy3Wddrcd6qNybx9F2/lZ63H+nVCa9Oe9elZa5ksa/dDbE+3fsm4v27C89bd+i6W3l+XdcnSWtuxyvPW+hqorbWb0Jr7Pl3m4tjfVMIZ625d6L5pxTPWw7rQY9P6pqu1dF8aq5d83cE3rXrGWluIxV6h53eotv4c1FigureLn7Nm66ZvvZf8SSues16sD2jubz2sC839fmvYiz7t//LJna27wsr7VjlnNWtPeHTfNlae2bZvnaTePUd+74fqV2LNxv6zdN8O3z9HSWhlc4F+dOvdsKbe2+F7q+zPddq6W2ts6r31vrN825/rtPWwvvcL5losy11uxQNz5U6fYT4w12mrWf80TUNZdetXal/LtwNW6WOFI1Y9bU3GVnfFXM9bneZKwrmKcK4qnKsK52q6uULTzRWFVjpkta/OykKrCq02puWFVhRaSWjlQa0itJrO8oNaQWgloZWFVhnUqjrLN50VBrWi0MpCqwitOqjVdFYQWlFopUGtLLSq0GpjWl5oRaGVBrWy0KpCq+ksP6gVhFYSWllolUGtqrNW/jvBZVYY1IpCKwutIrTqoFbTWUFoxUGtJLSK0KpCq41peaEVhVYa1MpCqwqtprP8oFYUWklo5UGtIrSazvJCKwxqRaGVhVYZ1Ko664ems34UWj8Nav0stBoWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhbW/9L6RWgp37WofIek8j2cyveLTkqrCq0itLLQSkJL+Q5k5budle/HVr73e/24gAHenZ6FlvK9+srzAoLQUp65oDy3QnoeRxFaWWgpz2pRnncThJbyzCDpuUtVaBWhlYWW8qwx5RlqynPovNBSnuUnPaOwCK0stJLQUp4BqjzbVHk+rFNaVWgVoZWFlvJc6Si0lGdzK88cV57bLj2PvgitLLSS0IpCKwgtL7Sc0qpCqwitLLSS0IpCKwgtL7Sc0qpCqwitLLSS0IpCKwgtL7Sc0qpCqwitLLSS0IpCKwgtL7Sc0qpCqwitLLSS0IpCKwgtL7Sc0qpCqxyyahcrH7JKFysJ54rCuYJwLi+cywnn+vdlLp+rCOfKwrnStXP95zLxiJX7WEFoeaHljO/xEqsaf9/FWqz1bM+VzloP655df2uxrnP9XPHKue7OeMDsuWInyx+Y67T1Yv0gs+cKvay6P5fvZZULrdnYFBbbcr2sdKF1MxbZFdZkLLItq3aay6/vJ102eusD2rJKl633nw/o3n+uxbrpLSv1svL6M95hQ3xYNz33t16sC21Zoc+28Xahm+u+Ic7WhbYs1+dRfrvQ5LpvHOaFNq3SZ8n/faEt6twDtli7wrJpxT6P1183/di0Ti36u3XT903Ld1qGrzf9smmdWhyTddNzf8t8UqdtK/dZGq8P2DZ1ZnHcrQ/osWO5PkvDuby7NE58Yctk7Qq3PSv3+bpc3F0aJ56wF+uLX9xu6eOb4es9z/vWc0vR3oZuByjnf2t/fP/54B/2WvvWEREREREREREREREREREREREREREREREREREREREREREREREREX2J/QlrTpqHD8xO1gAAAABJRU5ErkJggg=="),nx._image}render(t){const{left:e,top:n,width:i,height:s}=this.bounds;t.beginPath(),this.drawImage(t,nx.image,e,n,i,s)}buildRealObject(){return new rx(this)}get nature(){return sx}};ox=nx=Wm([Dy("camera")],ox);const ax={mutable:!1,resizable:!0,rotatable:!0,properties:[...Py],"value-property":"source",help:"scene/component/gltf-object"};let cx=class extends(Oy(Oc(Tc))){get nature(){return ax}};cx=Wm([Dy("gltf-object")],cx);const lx={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"select",label:"light-type",name:"lightType",property:{options:["","point","directional"]}},{type:"number",label:"intensity",name:"intensity"},{type:"number",label:"distance",name:"distance"},{type:"number",label:"decay",name:"decay"},{type:"checkbox",label:"cast-shadow",name:"castShadow"},{type:"number",label:"near",name:"near",placeholder:"0.5"},{type:"number",label:"far",name:"far",placeholder:"1000"},{type:"number",label:"fov",name:"fov",placeholder:"90"},{type:"number",label:"zoom",name:"zoom",placeholder:"1"},{type:"checkbox",label:"show-helper",name:"showHelper"}],help:"scene/component/light"};class hx extends xu{updatePointLight(){const{lightType:e="point",distance:n=0,intensity:i=10,decay:s=1,fillStyle:r="white",castShadow:o,near:a=.5,far:c=1e3,fov:l=90,zoom:h=1,showHelper:d}=this.component.state;if(this.object3d.color=new t.Color(r),"point"==e&&(this.object3d.distance=n,this.object3d.decay=s),this.object3d.intensity=i,this.object3d.castShadow=o,o){const t=this.object3d.shadow?.camera;t.far=c,t.near=a,t.fov=l,t.zoom=h}if(d){const e=this.object3d.shadow?.camera;this.helper||(this.helper=new t.CameraHelper(e),this.object3d.add(this.helper))}else this.helper&&(this.object3d.remove(this.helper),delete this.helper)}getObject3dInstance(){const{lightType:e="point"}=this.component.state;return"point"==e?new t.PointLight:new t.DirectionalLight}update(){this.clear(),this.build(),this.updateDimension(),this.updateHidden(),this.updatePointLight()}}let dx=class extends bg{get hasTextProperty(){return!1}is3dish(){return!0}buildRealObject(){return new hx(this)}get anchors(){return[]}get nature(){return lx}};dx=Wm([Dy("light")],dx);const ux={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"number",label:"depth",name:"depth",property:"depth"}],help:"scene/component/wall"};class px extends cv{buildGeometry(){this.object3d.geometry=Dv.primitive({kind:"box"})}topOutline(){const{width:t=0,height:e=0}=this.component.state;return t>0&&e>0?_v(t,e):null}}let fx=class extends(Oc(Tc)){get hasTextProperty(){return!1}is3dish(){return!0}buildRealObject(){return new px(this)}get nature(){return ux}};fx=Wm([Dy("wall")],fx);const mx={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"number",label:"depth",name:"depth",property:"depth"},{type:"checkbox",label:"hide-in-2d-view",name:"hideIn2DView"},{type:"checkbox",label:"hide-in-3d-view",name:"hideIn3DView"}],help:"scene/component/floor-plate"};class gx extends xu{get zPriority(){return fu.FLOOR}get receivingSurfaceY(){return this.placementSurfaceY()}resolveShadow(){const t=this.component.state,e=t.material3d,{alpha:n=1,fillStyle:i}=t,s=n>=.9&&"none"!==i;return{receive:e?.receiveShadow??!0,cast:e?.castShadow??s}}updateHidden(){const t=this.component.state,e=!!this.component.app?.isViewMode;this.object3d.visible=!(t.hidden||e&&t.hideIn3DView)}clear(){return this._topTexture&&(this._topTexture.dispose(),this._topTexture=void 0),this._mesh=void 0,super.clear()}build(){super.build();const{width:e,height:n,depth:i=1}=this.component.state;if(!e||!n)return;const s=Math.abs(e),r=Math.abs(n),o=Math.max(i,.5),a=new t.BoxGeometry(s,o,r),c=this._buildTopMaterial(),l=this._buildSideMaterial(),h=[l,l,c,l,l,l];this._mesh=new t.Mesh(a,h),this._mesh.position.y=0;const{cast:d,receive:u}=this.resolveShadow();this._mesh.castShadow=d,this._mesh.receiveShadow=u,this.object3d.add(this._mesh)}_buildTopMaterial(){const{alpha:e=1,fillStyle:n}=this.component.state,i=Pd(this.component.state.material3d),s=xu.buildFillStyleTexture(this.component);if(s){this._topTexture=s;const e=new t.MeshStandardMaterial({map:s,side:t.DoubleSide});return tu(e,0,n),e.depthWrite=e.opacity>=.9,Id(e,i),e}const r="string"==typeof n&&"none"!==n?eu(n):"#e0e0e0",o=new t.MeshStandardMaterial({color:r,side:t.DoubleSide});return tu(o,0,n),o.depthWrite=o.opacity>=.9,Id(o,i),o}_buildSideMaterial(){const{strokeStyle:e,alpha:n=1}=this.component.state,i="string"==typeof e&&e?eu(e):"#999999",s=Pd(this.component.state.material3d),r=new t.MeshStandardMaterial({color:i});return Id(r,s),r.side=t.DoubleSide,tu(r,0,e),r.depthWrite=r.opacity>=.9,r}updateAlpha(){if(!this._mesh)return;const{alpha:t=1,fillStyle:e,strokeStyle:n}=this.component.state,i=this._mesh.material;for(let t=0;t<i.length;t++){const s=i[t];tu(s,0,2===t?e:n),s.depthWrite=s.opacity>=.9}}updateFillStyle(){if(!this._mesh)return;this._topTexture&&(this._topTexture.dispose(),this._topTexture=void 0);const t=this._mesh.material;t[2].dispose(),t[2]=this._buildTopMaterial()}updateStrokeStyle(){if(!this._mesh)return;const t=this._mesh.material,e=this._buildSideMaterial();for(let n=0;n<t.length;n++)2!==n&&(t[n].dispose(),t[n]=e)}}let yx=class extends Jl{get hasTextProperty(){return!1}is3dish(){return!0}buildRealObject(){return new gx(this)}get nature(){return mx}get hidden(){return!!this.getState("hideIn2DView")||super.hidden}};yx.requires3d=!0,yx=Wm([Dy("floor-plate")],yx);function bx(e,n={}){const i=n.size??5,s=n.color??4500172,r=n.emissive??2245734,o=new t.SphereGeometry(i,16,12),a=new t.MeshStandardMaterial({color:s,emissive:r,emissiveIntensity:.15,metalness:.3,roughness:.4,transparent:!0,opacity:.35}),c=new t.Mesh(o,a);n.position&&c.position.set(n.position[0],n.position[1],n.position[2]),c.userData.alwaysRaycast=!0,c.scale.setScalar(1),c.visible=n.visible??!(!0===e.app?.isViewMode);const l=()=>{a.emissiveIntensity=.9,a.opacity=.95,c.scale.setScalar(1.35),e.invalidate?.()},h=()=>{a.emissiveIntensity=.15,a.opacity=.35,c.scale.setScalar(1),e.invalidate?.()};return e.on("mouseenter",l),e.on("mouseleave",h),c.userData.dispose=()=>{e.off("mouseenter",l),e.off("mouseleave",h)},c}class _x extends cv{get zPriority(){return fu.DECAL}get syncZPosOffset(){return this.effectiveDepth}get geometricOffsetY(){return this.effectiveDepth}buildGeometry(){const{width:e,height:n}=this.component.state,i=Math.abs(e)||1,s=Math.abs(n)||1,r=new t.PlaneGeometry(i,s);r.rotateX(-Math.PI/2),this.object3d.geometry=r}updateDimension(){this.update()}build(){super.build();const{width:t,height:e}=this.component.state,n=Math.abs(t)||1,i=Math.abs(e)||1,s=Math.max(2,.04*Math.min(n,i));this.object3d.add(bx(this.component,{size:s,position:[n/2-s,s,-i/2+s]}))}}const vx={mutable:!1,resizable:!0,rotatable:!0,properties:[],help:"scene/component/decal"};let xx=class extends(Cy(Oc(Tc))){buildRealObject(){return new _x(this)}get nature(){return vx}};xx=Wm([Dy("decal")],xx);class wx extends xu{getObject3dInstance(){return new t.Group}get allowedGizmoModes(){return this.component.isGroup?.()?["translate"]:null}}const Mx="#dde2e8",Sx="#9c9c9c",kx="#e8e8ec",Ax=.35;function Ex(e,n,i,s,r){if(!n.visible)return new t.MeshStandardMaterial({transparent:!0,opacity:0,depthWrite:!1});const o=n.alpha*i,a="wall"===s?Mx:"floor"===s?Sx:kx,c=new t.MeshStandardMaterial({metalness:0,roughness:"wall"===s?.6:.85,transparent:o<1,opacity:o,side:r?t.BackSide:t.DoubleSide});return function(t,e,n,i,s,r){if("string"==typeof n&&n&&"transparent"!==n)t.color.set(n);else{if(n&&"object"==typeof n){const i=!r,o=xu.buildFillStyleTexture(e,n,{mirror:i,rotation:s});if(o)return t.map&&t.map.dispose(),t.map=o,void t.color.set("#ffffff")}t.color.set(i)}}(c,e,n.fillStyle,a,n.rotation,n.mirror),c}class Cx extends wx{get zPriority(){return fu.BACKDROP}get position(){if(this.component.state.fitToBoard){return{x:0,y:super.position.y,z:0}}return super.position}build(){super.build();const e=this.component.state;let n=e.width,i=e.height;if(e.fitToBoard){const t=this.component.rootModel,e=t?.state;e&&Number.isFinite(e.width)&&Number.isFinite(e.height)&&(n=e.width,i=e.height)}const s=this.effectiveDepth||Math.min(n,i)||200,r=e.alpha??1,o=!1!==e.seeThrough,a={east:this._resolveFace("east",Mx,!0,Ax),west:this._resolveFace("west",Mx,!0,Ax),north:this._resolveFace("north",Mx,!0,Ax),south:this._resolveFace("south",Mx,!0,Ax),floor:this._resolveFace("floor",Sx,!0,1),ceiling:this._resolveFace("ceiling",kx,!0,1)},c=[Ex(this.component,a.east,r,"wall",o),Ex(this.component,a.west,r,"wall",o),Ex(this.component,a.ceiling,r,"ceiling",o),Ex(this.component,a.floor,r,"floor",o),Ex(this.component,a.south,r,"wall",o),Ex(this.component,a.north,r,"wall",o)],l=new t.BoxGeometry(n,s,i),h=new t.Mesh(l,c);if(h.receiveShadow=!0,this.object3d.add(h),this.component.app?.isEditMode){const e=new t.LineBasicMaterial({color:4473941,transparent:!0,opacity:.7}),n=new t.LineSegments(new t.EdgesGeometry(l),e);this.object3d.add(n)}const d=Math.max(2,.04*Math.min(n,i,s));this.object3d.add(bx(this.component,{size:d,position:[n/2,s/2+d,-i/2]}))}_resolveFace(t,e,n,i){const s=this.component.state,r=s.faces?.[t]??{},o=r.visible,a=r.alpha,c=r.rotation,l=90===c||180===c||270===c?c:0;return{fillStyle:r.fillStyle??e,visible:"boolean"==typeof o?o:n,alpha:"number"==typeof a&&Number.isFinite(a)?a:i,rotation:l,mirror:!0===r.mirror}}updateDimension(){}onchange(t,e){["alpha","width","height","depth","fitToBoard","faces","seeThrough"].some(e=>e in t)?this.update():super.onchange(t,e)}updateAlpha(){}}const Tx={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"checkbox",label:"fit-to-board",name:"fitToBoard"},{type:"checkbox",label:"see-through",name:"seeThrough"},{type:"backdrop-faces",label:"",name:"faces"}],help:"scene/component/backdrop"};let Px=class extends(Cy(Oc(Tc))){buildRealObject(){return new Cx(this)}get nature(){return Tx}added(t){super.added?.(t),this.state.fitToBoard&&(this._syncFromRoot(!0),this._attachRootListener())}async ready(){await super.ready(),this.state.fitToBoard&&this._syncFromRoot(!1)}removed(t){this._detachRootListener(),super.removed?.(t)}dispose(){this._detachRootListener(),super.dispose?.()}onchange(t,e){"fitToBoard"in t&&(t.fitToBoard?(this._syncFromRoot(!0),this._attachRootListener()):this._detachRootListener()),super.onchange?.(t,e)}_syncFromRoot(t=!1){const e=this.rootModel;if(!e||e===this)return;const n=e.state;if(!n)return;const i={},s=Number.isFinite(n.width)?n.width:this.state.width,r=Number.isFinite(n.height)?n.height:this.state.height;s!==this.state.width&&(i.width=s),r!==this.state.height&&(i.height=r);const o=Number.isFinite(n.left)?n.left:0,a=Number.isFinite(n.top)?n.top:0;if(o!==this.state.left&&(i.left=o),a!==this.state.top&&(i.top=a),t){const t=this.state.depth;if(!("number"==typeof t&&Number.isFinite(t)&&t>0)){const e=Math.min(s,r);e!==t&&(i.depth=e)}}Object.keys(i).length>0&&this.set(i)}_attachRootListener(){if(this._onRootChange)return;const t=this.rootModel;t&&t!==this&&(this._onRootChange=t=>{("width"in t||"height"in t||"left"in t||"top"in t)&&this._syncFromRoot()},t.on?.("change",this._onRootChange))}_detachRootListener(){if(!this._onRootChange)return;const t=this.rootModel;t?.off?.("change",this._onRootChange),this._onRootChange=void 0}};function Ox(t,e){return"none"===t?0:t.endsWith("arrow")?1.5*e:0}function Dx(e,n,i,s){const r=[];for(let o=1;o<=s;o++){const a=o/s,c=1-a;r.push(new t.Vector3(c*c*e.x+2*c*a*n.x+a*a*i.x,c*c*e.y+2*c*a*n.y+a*a*i.y,c*c*e.z+2*c*a*n.z+a*a*i.z))}return r}Px=Wm([Dy("backdrop")],Px);class Ix extends xu{getObject3dInstance(){return new t.Group}get gizmoTransformable(){return!0}get syncZPosOffset(){return 0}get geometricOffsetY(){return 0}syncFromObject3D(){}applyDimensionFromGizmo(t){}build(){super.build(),this._buildLine()}get smoothedPath(){const e=this.worldPath;if(e.length<2)return e;const{round:n=0}=this.component.state;if(n<=0||e.length<3)return e;const i=[];i.push(e[0]);for(let s=1;s<e.length;s++){const r=e[s-1],o=e[s],a=e[s+1];if(!a){i.push(o);break}const c=r.x-o.x,l=r.y-o.y,h=r.z-o.z,d=Math.sqrt(c*c+l*l+h*h),u=Math.min(n,d/2),p=a.x-o.x,f=a.y-o.y,m=a.z-o.z,g=Math.sqrt(p*p+f*f+m*m),y=Math.min(n,g/2),b=d>0?new t.Vector3(o.x+c/d*u,o.y+l/d*u,o.z+h/d*u):o.clone(),_=g>0?new t.Vector3(o.x+p/g*y,o.y+f/g*y,o.z+m/g*y):o.clone();i.push(b),i.push(...Dx(b,o,_,8))}return i}_buildLine(){const e=this.smoothedPath;if(e.length<2)return;const{strokeStyle:n,lineWidth:i=2,alpha:s=1,lineDash:r,begin:o="none",beginSize:a="size5",end:c="none",endSize:l="size5"}=this.component.state,h=Math.max(i,1),d="string"==typeof n&&"transparent"!==n?eu(n):"#000000",u=new t.Color(d),p=this._getResolution(),f=o,m=c,g=Ox(f,h),y=Ox(m,h),b=e[0],_=e[e.length-1],v=(new t.Vector3).subVectors(e[1],b).normalize(),x=(new t.Vector3).subVectors(e[e.length-2],_).normalize(),k=[...e];g>0&&(k[0]=b.clone().add(v.clone().multiplyScalar(g))),y>0&&(k[k.length-1]=_.clone().add(x.clone().multiplyScalar(y)));const A=new S;A.setPositions(k.flatMap(t=>[t.x,t.y,t.z]));const E=function(t,e){switch(t){case"round-dot":return{dashSize:e,gapSize:e};case"square-dot":return{dashSize:2*e,gapSize:e};case"dash":return{dashSize:4*e,gapSize:1.5*e};case"dash-dot":return{dashSize:4*e,gapSize:2*e};case"long-dash":return{dashSize:6*e,gapSize:3*e};case"long-dash-dot":return{dashSize:6*e,gapSize:2*e};case"long-dash-dot-dot":return{dashSize:6*e,gapSize:e};default:return null}}(r,h),C=new M({color:u.getHex(),linewidth:h,worldUnits:!0,transparent:s<1,opacity:s,resolution:p,dashed:!!E,dashSize:E?.dashSize??1,gapSize:E?.gapSize??1,dashScale:1});if(this._line2=new w(A,C),this._line2.computeLineDistances(),this.object3d.add(this._line2),"none"!==f){const e=Vp(f,Yp(a,h));if(e){const n=(new t.Quaternion).setFromUnitVectors(new t.Vector3(1,0,0),v.clone().negate());this._placeTip(e,b,n,u,s,p)}}if("none"!==m){const e=Vp(m,Yp(l,h));if(e){const n=(new t.Quaternion).setFromUnitVectors(new t.Vector3(1,0,0),x.clone().negate());this._placeTip(e,_,n,u,s,p)}}}_placeTip(t,e,n,i,s,r){const o=t.mesh||t.line2||t.group;if(o){if(o.position.copy(e),o.setRotationFromQuaternion(n),t.mesh){const e=t.mesh.material;e.color.copy(i),e.transparent=s<1,e.opacity=s}else if(t.line2){const e=t.line2.material;e.color.copy(i),e.transparent=s<1,e.opacity=s,e.resolution.copy(r)}else t.group&&t.group.traverse(t=>{if(t.material){const e=t.material;e.color&&e.color.copy(i),e.transparent=s<1,e.opacity=s,e.resolution&&e.resolution.copy(r)}});this.object3d.add(o)}}_getResolution(){const e=this.threeContainer?.renderer3d;if(e){return e.getSize(new t.Vector2)}return new t.Vector2(window.innerWidth,window.innerHeight)}onGizmoDragEnd(t){const e=this._component,n=e.path;if(!n||n.length<2)return;const i=this.object3d,{width:s=0,height:r=0}=e.parent?.bounds??{},{x:o,y:a}=e.center,c=i.position,l=i.rotation,h=i.scale,d=this.position;if(Math.abs(c.x-d.x)<.001&&Math.abs(c.y-d.y)<.001&&Math.abs(c.z-d.z)<.001&&Math.abs(l.x)<.001&&Math.abs(l.y)<.001&&Math.abs(l.z)<.001&&Math.abs(h.x-1)<.001&&Math.abs(h.y-1)<.001&&Math.abs(h.z-1)<.001)return;const u=Ix.computeBakedPath(n,{x:o,y:a},{width:s,height:r},i);this._suppressOnchange=!0,e.set({rotation:0,rotationX:0,rotationY:0,zPos:0}),e.mutatePath(null,()=>u),this._suppressOnchange=!1,this.update()}static computeBakedPath(e,n,i,s){const r=i.width,o=i.height,a=n.x,c=n.y;return s.updateMatrixWorld(!0),e.map(e=>{const n=new t.Vector3(e.x-a,e.z||0,e.y-c).applyMatrix4(s.matrixWorld),i={x:n.x+r/2,y:n.z+o/2};return Math.abs(n.y)>.001&&(i.z=n.y),i})}updateStrokeStyle(){this.updateDimension()}updateAlpha(){this.updateDimension()}updateDimension(){this.clear(),this.build()}onchange(t,e){("path"in t||"from"in t||"to"in t)&&(this.updateDimension(),this.updatePosition()),("round"in t||"lineDash"in t||"lineWidth"in t||"begin"in t||"end"in t||"beginSize"in t||"endSize"in t)&&this.updateDimension(),super.onchange(t,e)}clear(){for(;this.object3d.children.length>0;){const t=this.object3d.children[0];this.object3d.remove(t),cu(t)}return this._line2=void 0,super.clear()}}class zx extends Ix{get worldPath(){const e=this.component.path;if(!e||e.length<2)return[];const{x:n,y:i}=this.component.center,s=this.component,r=s.fromEnd?.component?._realObject?.object3d?.position?.y??0,o=s.toEnd?.component?._realObject?.object3d?.position?.y??0;return e.map((s,a)=>{const c=e.length>1?a/(e.length-1):0;return new t.Vector3(s.x-n,s.z||r+(o-r)*c,s.y-i)})}}Kp("line",t=>new zx(t));class Rx extends Ix{get worldPath(){const e=this.component.path;if(!e||e.length<2)return[];const{x:n,y:i}=this.component.center;return e.map(e=>new t.Vector3(e.x-n,e.z||0,e.y-i))}}Kp("polyline",t=>new Rx(t));class jx extends Ix{get worldPath(){const e=this.component.drawPath;if(!e||e.length<2)return[];const{x:n,y:i}=this.component.center,s=this.component,r=s.fromEnd?.component?._realObject?.object3d?.position?.y??0,o=s.toEnd?.component?._realObject?.object3d?.position?.y??0;return e.map((s,a)=>{const c=e.length>1?a/(e.length-1):0;return new t.Vector3(s.x-n,s.z||r+(o-r)*c,s.y-i)})}}function Lx(t,e=16){let n=Math.max(e,1);for(;n<t;)n*=2;return n}Kp("ortholine",t=>new jx(t)),Kp("group",t=>new wx(t));class Fx{constructor(e){this._count=0,this._placements=[],this._geometry=e.geometry,this._material=e.material,this._capacity=Math.max(1,e.capacity??16),this._name=e.name??"instanced",this._castShadow=e.castShadow??!0,this._receiveShadow=e.receiveShadow??!1,this.object3d=new t.Group,this.object3d.name=this._name,this._mesh=this._makeMesh(this._capacity),this.object3d.add(this._mesh)}_makeMesh(e){const n=new t.InstancedMesh(this._geometry,this._material,e);return n.name=this._name+"__instances",n.castShadow=this._castShadow,n.receiveShadow=this._receiveShadow,n.instanceMatrix.setUsage(t.DynamicDrawUsage),n.count=0,n}get mesh(){return this._mesh}get count(){return this._count}get capacity(){return this._capacity}place(t){const e=t.length;if(e>this._capacity){const t=Lx(e,this._capacity);this.object3d.remove(this._mesh),this._mesh.dispose(),this._capacity=t,this._mesh=this._makeMesh(t),this.object3d.add(this._mesh)}this._placements.length=e;for(let n=0;n<e;n++){const e=t[n];this._placements[n]=e,this._writeMatrix(n,e),void 0!==e.color&&this._writeColor(n,e.color)}this._count=e,this._mesh.count=e,this.commit()}setCount(t){if(t>this._capacity){const e=Lx(t,this._capacity),n=this._mesh.frustumCulled;this.object3d.remove(this._mesh),this._mesh.dispose(),this._capacity=e,this._mesh=this._makeMesh(e),this._mesh.frustumCulled=n,this.object3d.add(this._mesh)}this._placements.length=0,this._count=t,this._mesh.count=t}setMatrix(t,e){t<0||t>=this._count||this._mesh.setMatrixAt(t,e)}update(t,e){t<0||t>=this._count||(this._placements[t]=e,this._writeMatrix(t,e),void 0!==e.color&&this._writeColor(t,e.color),this.commit())}setRotation(t,e){if(t<0||t>=this._count)return;const n=this._placements[t];n&&(n.rotation=e,this._writeMatrix(t,n))}commitMatrices(){this._mesh.instanceMatrix.needsUpdate=!0}setColor(t,e){t<0||t>=this._count||(this._writeColor(t,e),this._mesh.instanceColor&&(this._mesh.instanceColor.needsUpdate=!0))}indexOf(t){return t>=0&&t<this._count?t:-1}commit(){this._mesh.instanceMatrix.needsUpdate=!0,this._mesh.instanceColor&&(this._mesh.instanceColor.needsUpdate=!0),this._mesh.computeBoundingSphere()}dispose(){this.object3d.remove(this._mesh),this._mesh.dispose(),this._placements.length=0,this._count=0}_writeMatrix(t,e){const n=Fx;n._p.set(e.position.x,e.position.y,e.position.z);const i=e.rotation;n._e.set(i?.x??0,i?.y??0,i?.z??0),n._q.setFromEuler(n._e);const s=e.scale;"number"==typeof s?n._s.set(s,s,s):n._s.set(s?.x??1,s?.y??1,s?.z??1),n._m.compose(n._p,n._q,n._s),this._mesh.setMatrixAt(t,n._m)}_writeColor(t,e){Fx._c.set(e),this._mesh.setColorAt(t,Fx._c)}}function Nx(t,e,n){const i=Math.max(1,Math.floor(t.x??1)),s=Math.max(1,Math.floor(t.y??1)),r=Math.max(1,Math.floor(t.z??1)),o=e.x??0,a=e.y??0,c=e.z??0,l=n?.x??0,h=n?.y??0,d=n?.z??0,u=[];for(let t=0;t<s;t++)for(let e=0;e<r;e++)for(let n=0;n<i;n++)u.push({position:{x:l+n*o,y:h+t*a,z:d+e*c}});return u}Fx._m=new t.Matrix4,Fx._p=new t.Vector3,Fx._q=new t.Quaternion,Fx._e=new t.Euler,Fx._s=new t.Vector3,Fx._c=new t.Color;class Hx extends xu{build(){super.build()}update(){}}const Bx={far:1e5,fov:80,near:1,zoom:1};class Yx extends xu{build(){super.build()}update(){super.update(),this.updateCamera()}getObject3dInstance(){return new t.PerspectiveCamera}updateCamera(){const{near:t=Bx.near,far:e=Bx.far,fov:n=Bx.fov,zoom:i=Bx.zoom}=this.component.state;this.object3d.far=e,this.object3d.fov=n,this.object3d.near=t,this.object3d.zoom=i}}class Vx extends cv{buildGeometry(){const{width:e,height:n}=this.component.state.dimension;this.object3d.geometry=new t.PlaneGeometry(e,n)}buildMaterial(){this.object3d.material=new t.MeshStandardMaterial({opacity:0,side:t.DoubleSide,blending:t.NoBlending})}}class Gx extends xu{getObject3dInstance(){return new t.Scene}dispose(){for(const t of this.object3d.children)cu(t);this._animationMixer&&(this._animationMixer.stopAllAction(),this._animationMixer.uncacheRoot(this.object3d),this._animationMixer=void 0),super.dispose()}clear(){return this._floor&&(this.object3d.remove(this._floor),this._floor.material instanceof Array?this._floor.material.forEach(t=>t.dispose()):this._floor.material.dispose(),this._floor.geometry.dispose(),delete this._floor),super.clear()}get floor(){return this._floor}set floor(t){this._floor&&(this.object3d.remove(this._floor),this._floor.clear(),delete this._floor),t&&(this._floor=t,this.object3d.add(t)),this.component.invalidate()}build(){super.build(),this.floor=mf(this.component)}updateTransform(){}updateDimension(){}updatePosition(){}updateRotate(){}updateScale(){}updateAlpha(){}updateHidden(){}get animationMixer(){return this._animationMixer||(this._animationMixer=new t.AnimationMixer(this.object3d)),this._animationMixer}}const $x=new Set(["cx","cy","cz","zPos","left","top","width","height","depth","lineWidth","rotationX","rotationY","rotation","scale","hidden","alpha","material3d","screenFixed"]);class Ux extends xu{get syncZPosOffset(){return this.effectiveDepth}get geometricOffsetY(){return this.effectiveDepth}constructor(t){super(t),this._origInvalidate=t.invalidate.bind(t),t.invalidate=()=>{this._origInvalidate(),this._refreshTextureNow()}}getObject3dInstance(){return new t.Mesh}build(){super.build();const{width:e,height:n}=this.component.bounds;if(!e||!n)return;const i=Pd(this.component.state.material3d),s=new t.PlaneGeometry(1,1);s.rotateX(-Math.PI/2),this.object3d.geometry=s;const r=J_(this.component),o=new t.MeshStandardMaterial({map:r});Id(o,i),o.transparent=!0,this.object3d.material=o,this.object3d.castShadow=i.castShadow,this.object3d.receiveShadow=i.receiveShadow}updateAlpha(){const{alpha:t=1,fillStyle:e}=this.component.state;tu(this.object3d.material,0,e)}get dimension(){const{width:t,height:e}=this.component.bounds;return{width:t||1,height:e||1,depth:1}}get scale(){const t=super.scale,{width:e,height:n}=this.dimension;return{x:t.x*e,y:t.y,z:t.z*n}}updateDimension(){this.updateTransform()}_debouncedRebuild(){this._debounceTimer&&clearTimeout(this._debounceTimer),this._debounceTimer=setTimeout(()=>{this._debounceTimer=void 0,this.update()},100)}_refreshTextureNow(){const t=this.object3d.material,e=t?.map;if(!e)return;const n=e.source?.data;n&&(ev(n,this.component,2),e.needsUpdate=!0)}update(){this.clear(),this.build(),this.updateDimension(),this.updateTransform(),this.updateHidden()}onchange(t,e){super.onchange(t,e);for(const e of Object.keys(t))if(!$x.has(e)){this._debouncedRebuild();break}}updateFillStyle(){this._debouncedRebuild()}updateStrokeStyle(){this._debouncedRebuild()}updateText(){this._debouncedRebuild()}updateMaterial3d(){super.updateMaterial3d();const t=this.object3d.material;if(!t)return;const e=Pd(this.component.state.material3d);Id(t,e),t.transparent=!0,this.object3d.castShadow=e.castShadow,this.object3d.receiveShadow=e.receiveShadow}clear(){return this._debounceTimer&&(clearTimeout(this._debounceTimer),this._debounceTimer=void 0),cu(this.object3d),super.clear()}dispose(){this._debounceTimer&&(clearTimeout(this._debounceTimer),this._debounceTimer=void 0),this._origInvalidate&&(this.component.invalidate=this._origInvalidate,this._origInvalidate=void 0),super.dispose()}}const Wx={mutable:!1,resizable:!0,rotatable:!0,properties:[{type:"select",label:"precision",name:"precision",property:{options:[{display:"High",value:"highp"},{display:"Medium",value:"mediump"},{display:"Low",value:"lowp"}]}},{type:"checkbox",label:"anti-alias",name:"antialias",property:"antialias"},{type:"checkbox",label:"3dmode",name:"threed",property:"threed"},{type:"checkbox",label:"auto-rotate",name:"autoRotate",property:"autoRotate"},{type:"checkbox",label:"debug",name:"debug",property:"debug"}],help:"scene/component/three-container"};let qx=class extends ng{constructor(){super(...arguments),this._capability=new Bf}get sceneManager(){return this._capability.sceneManager}get cameraManager(){return this._capability.cameraManager}get rendererManager(){return this._capability.rendererManager}get lightManager(){return this._capability.lightManager}get controlsManager(){return this._capability.controlsManager}get eventManager(){return this._capability.eventManager}get hasEnvironment(){return this._capability.hasEnvironment}containable(t){return!0}is3dContainer(){return!0}getLightingConfig(){return{hemisphere:{skyColor:16777215,groundColor:14540253,intensity:1},directional:{color:16777215,intensity:1.2,attachToCamera:!0,castShadow:!1}}}getCss3DSceneAttribute(){return"three-container:css3d-renderer"}init_scene3d(){this._capability.isInitialized&&this._capability.destroy(),this._capability.init(this,{lightingConfig:this.getLightingConfig(),css3DSceneAttribute:this.getCss3DSceneAttribute(),skipEnvironment:!0,skipPostprocessing:!0,skipShadowMap:!0}),this._capability.buildOverlays(),this._capability.resize(),this.onchangeData&&this.onchangeData(this.data,this.data)}destroy_scene3d(){this.stop(),this._capability.destroy()}stop(){}resize(){this._capability.resize()}get scene3d(){return this._capability.isInitialized||this.init_scene3d(),this._capability.scene3d}get renderer3d(){return this._capability.renderer3d}get mixer(){return this._capability.mixer}get css3DScene(){return this._capability.css3DScene}get css3DRenderer(){return this._capability.css3DRenderer}render_threed(){this._capability.renderThreeD()}get _parentIs3dMode(){return!!this.rootModel?.is3dMode}render(t){this._parentIs3dMode||(this.app.isViewMode&&this.setState("threed",!0),!this.state.threed||this._capability.noSupportWebgl?super.render(t):this._capability.camera&&this._capability.renderCSS3D())}postrender(t){if(this._parentIs3dMode)return;const{left:e,top:n,debug:i,threed:s}=this.state;let{width:r,height:o}=this.bounds;if(r=Math.floor(r),o=Math.floor(o),s){if(this._capability.isInitialized||this.init_scene3d(),this._capability.noSupportWebgl)return void this._capability.showWebglNoSupportText(t,this.state.width,this.state.height);if(!this._capability.renderer3d)return;this._capability.renderThreeD();const s=this._capability.domElement;if(!s||!s.width||!s.height)return;t.drawImage(s,0,0,s.width,s.height,e,n,r,o),i&&this._capability.showDebugFPS(t)}else super.postrender(t)}dispose(){this._capability.dispose(),super.dispose()}get layout(){return Lc.get("three")}get nature(){return Wx}getObjectByRaycast(){return this._capability.getObjectByRaycast()}getObjectsByRaycast(){return this._capability.getObjectsByRaycast()}onchange(t,e){(t.hasOwnProperty("width")||t.hasOwnProperty("height"))&&this._capability.destroy(),this._capability.onchange(t)}onmousedown(t){this._capability.onMouseDown(t)}onmouseup(t){this._capability.onMouseUp(t)}onmousemove(t){this._capability.onMouseMove(t)}onmouseleave(t){this._capability.onMouseLeave(t)}onwheel(t){this._capability.onWheel(t)&&this.invalidate()}ondblclick(t){this._capability.onDblClick(t)&&this.invalidate()}ondragstart(t){this._capability.onDragStart(t)}ondragmove(t){this._capability.onDragMove(t)&&this.invalidate()}ondragend(t){this._capability.onDragEnd(t)&&this.invalidate()}ontouchstart(t){this._capability.onTouchStart(t)}onpan(t){this._capability.onPan(t)&&this.invalidate()}ontouchend(t){this._capability.onTouchEnd(t)}onkeydown(t){this._capability.onKeyDown(t)}onpinch(t){this._capability.onPinch(t)&&this.invalidate()}ondoubletap(){this._capability.onDoubleTap(),this.invalidate()}};qx=Wm([Dy("3d-container")],qx),Qp(t=>new iv(t));const Xx=["x","y","z"],Kx=["Capacity","Holdable","Transferable","FlowNode"],Qx=Object.freeze({Transferable:["Capacity","FlowNode"]}),Zx=["S","M","L","XL"],Jx=Object.freeze({x:"size.x",y:"size.y",z:"size.z"});class tw extends Error{code;path;details;constructor(t,e,n,i){super(`${t}: ${e}: ${n}`),this.name="FigureContractError",this.code=t,this.path=e,void 0!==i&&(this.details=i)}}const ew=Object.freeze({x:["y","z"],y:["z","x"],z:["x","y"]}),nw=1e-6,iw=256,sw=/^[a-zA-Z][a-zA-Z0-9_-]*$/;function rw(t,e){return t<e?`${t}~${e}`:`${e}~${t}`}const ow=t=>ew[t],aw=t=>!!t.corner&&Object.values(t.corner).some(t=>(t??0)>0);function cw(t,e){const[n,i]=ow(e);if("rectangle"===t.kind){const e=[];for(const s of[n,i]){const n=t.size[s];"number"==typeof n&&Number.isFinite(n)?n>0||e.push({code:"SIZE_NOT_POSITIVE",axis:s}):e.push({code:"NON_FINITE",at:`size.${s}`})}if(!t.corner)return e;for(const s of[n,i]){const n=t.corner[s];"number"==typeof n&&Number.isFinite(n)?n<0?e.push({code:"CORNER_NEGATIVE",axis:s}):Number.isFinite(t.size[s])&&n>t.size[s]/2+nw&&e.push({code:"CORNER_TOO_LARGE",axis:s,max:t.size[s]/2}):e.push({code:"NON_FINITE",at:`corner.${s}`})}return e.length||t.corner[n]>0==t.corner[i]>0||e.push({code:"CORNER_ONE_AXIS",axis:t.corner[n]>0?n:i}),e}if("ellipse"===t.kind){const e=[];for(const s of[n,i]){const n=t.radius[s];"number"==typeof n&&Number.isFinite(n)?n>0||e.push({code:"SIZE_NOT_POSITIVE",axis:s}):e.push({code:"NON_FINITE",at:`radius.${s}`})}return e}return function(t,e){const[n,i]=ow(e),s=[],r=new Set;for(const e of t){"string"==typeof e.id&&sw.test(e.id)?r.has(e.id)?s.push({code:"DUPLICATE_POINT_ID",point:e.id}):r.add(e.id):s.push({code:"BAD_POINT_ID",point:String(e.id)});for(const t of[n,i])"number"==typeof e[t]&&Number.isFinite(e[t])||s.push({code:"NON_FINITE",at:`${e.id}.${t}`})}t.length<3&&s.push({code:"TOO_FEW_POINTS",count:t.length});t.length>iw&&s.push({code:"TOO_MANY_POINTS",count:t.length,limit:iw});if(s.length)return s;const o=t.length,a=function(t,e){const[n,i]=ow(e);return t.map(t=>[t[n],t[i]])}(t,e),c=e=>rw(t[e].id,t[(e+1)%o].id),l=nw,h=a.map((t,e)=>Math.hypot(a[(e+1)%o][0]-t[0],a[(e+1)%o][1]-t[1]));if(h.forEach((t,e)=>{t<=l&&s.push({code:"ZERO_LENGTH_SIDE",side:c(e)})}),s.length)return s;for(let t=0;t<o;t++){const e=a[t],n=a[(t+1)%o],i=a[(t+2)%o],r=(n[0]-e[0])*(i[1]-n[1])-(n[1]-e[1])*(i[0]-n[0]),d=(n[0]-e[0])*(i[0]-n[0])+(n[1]-e[1])*(i[1]-n[1]);Math.abs(r)<=l*h[t]&&d<0&&s.push({code:"SIDES_FOLD",sides:[c(t),c((t+1)%o)]})}for(let t=0;t<o;t++)for(let e=t+1;e<o;e++){if(e===t+1||0===t&&e===o-1)continue;const n=dw(a[t],a[(t+1)%o],a[e],a[(e+1)%o],l);n&&s.push({code:"cross"===n?"SIDES_CROSS":"SIDES_TOUCH",sides:[c(t),c(e)]})}if(s.length)return s;Math.abs(function(t){let e=0;for(let n=0;n<t.length;n++){const[i,s]=t[n],[r,o]=t[(n+1)%t.length];e+=i*o-r*s}return e}(a))/2<=l&&s.push({code:"ZERO_AREA"});return s}(t.points,e)}const lw=(t,e,n)=>(e[0]-t[0])*(n[1]-t[1])-(e[1]-t[1])*(n[0]-t[0]);function hw(t,e,n){const i=n[0]-e[0],s=n[1]-e[1],r=i*i+s*s,o=r?Math.max(0,Math.min(1,((t[0]-e[0])*i+(t[1]-e[1])*s)/r)):0;return Math.hypot(t[0]-e[0]-o*i,t[1]-e[1]-o*s)}function dw(t,e,n,i,s){const r=lw(n,i,t),o=lw(n,i,e),a=lw(t,e,n),c=lw(t,e,i),l=Math.hypot(e[0]-t[0],e[1]-t[1]),h=(t,e,n)=>t>s*n&&e<-s*n||t<-s*n&&e>s*n;if(h(r,o,Math.hypot(i[0]-n[0],i[1]-n[1]))&&h(a,c,l))return"cross";return Math.min(hw(t,n,i),hw(e,n,i),hw(n,t,e),hw(i,t,e))<=s?"touch":null}function uw(t,e){const[n,i]=ow(e);if("ellipse"===t.kind)return[{id:"round",shape:"curved"}];if("rectangle"===t.kind){const[e,s]=[n,i].sort(),r=[e,s].flatMap(t=>[`${t}-`,`${t}+`]).map(t=>({id:t,shape:"flat"}));if(!aw(t))return r;const o=["-","+"].flatMap(t=>["-","+"].map(n=>({id:`corner:${e}${t}${s}${n}`,shape:"curved"})));return[...r,...o]}const s=t.points;return s.map((t,e)=>{const n=s[(e+1)%s.length];return{id:rw(t.id,n.id),shape:"flat",from:t.id,to:n.id}})}function pw(t,e,n){const[i,s]=ow(e);if("polygon"===t.kind)return{refused:"SECTION_KIND"};const r=[i,s].flatMap(t=>[`${t}-`,`${t}+`]);for(const t of r){const e=n[t];if("number"!=typeof e||!Number.isFinite(e))return{refused:"NON_FINITE",side:t};if(!(e>0))return{refused:"WALL_NOT_POSITIVE",side:t}}const o=t=>n[t],a=(t,e)=>e-o(`${t}-`)-o(`${t}+`),c={[i]:(o(`${i}-`)-o(`${i}+`))/2,[s]:(o(`${s}-`)-o(`${s}+`))/2};if("rectangle"===t.kind){const e={[i]:a(i,t.size[i]),[s]:a(s,t.size[s])};if(!(e[i]>0&&e[s]>0))return{refused:"NO_ROOM_INSIDE"};if(!aw(t))return{section:{kind:"rectangle",size:e},centre:c};const n=e=>Math.max(t.corner[e]-Math.max(o(`${e}-`),o(`${e}+`)),0),r={[i]:n(i),[s]:n(s)};return{section:{kind:"rectangle",size:e,...r[i]>0&&r[s]>0?{corner:r}:{}},centre:c}}const l={[i]:a(i,2*t.radius[i])/2,[s]:a(s,2*t.radius[s])/2};return l[i]>0&&l[s]>0?{section:{kind:"ellipse",radius:l},centre:c}:{refused:"NO_ROOM_INSIDE"}}const fw=(t,e)=>Object.fromEntries(Xx.map(n=>[n,n===t?e:0]));function mw(t,e,n){const[i,s]=ew[e];if("polygon"!==t.kind){const t=n.id.slice(0,-1);return fw(t,n.id.endsWith("+")?1:-1)}const r=t.points.find(t=>t.id===n.from),o=t.points.find(t=>t.id===n.to),a=o[i]-r[i],c=o[s]-r[s],l=Math.hypot(a,c),h={x:0,y:0,z:0};return h[i]=c/l||0,h[s]=-a/l||0,h}const gw=(t,e,n)=>{throw new tw(t,e,n)},yw=t=>Array.isArray(t)&&3===t.length&&1===t[0]&&0===t[1]&&0===t[2],bw=Object.freeze({x:["left","right"],y:["bottom","top"],z:["back","front"]}),_w=["rectangle","ellipse","polygon","portal"],vw=/^[a-zA-Z][a-zA-Z0-9_-]*$/;function xw(t,e){const n=t??{},i=n.axis;Xx.includes(i)||gw("PARAM",e,`axis is x, y or z, not ${String(n.axis)}`);const s=n.section;_w.includes(s)||gw("PARAM",e,`section is ${_w.join(", ")}, not ${String(n.section)}`);const r=[...ew[i]].sort(),[o,a]=r,c="round"===n.corner;void 0===n.corner||c&&"rectangle"===s||gw("PARAM",e,"corner is `round`, and only a rectangle has corners");const l="polygon"===s?String(n.points??"").split("."):[];"polygon"===s?((l.length<3||l.some(t=>!vw.test(t)))&&gw("PARAM",e,"a drawn section names three points or more, joined by `.`"),new Set(l).size!==l.length&&gw("PARAM",e,"a point is named twice")):void 0!==n.points&&gw("PARAM",e,"only a drawn section has points");let h=2;const d=()=>h++,u={start:0,length:1};let p;if("rectangle"!==s&&"ellipse"!==s&&"portal"!==s||(u.across={[o]:d(),[a]:d()}),c&&(u.corner={[o]:d(),[a]:d()}),"portal"===s&&(u.jamb=d(),u.head=d()),"polygon"===s&&(u.point=Object.fromEntries(l.map(t=>[t,{[o]:d(),[a]:d()}]))),void 0!==n.cavity){"rectangle"!==s&&"ellipse"!==s&&gw("SECTION_KIND",e,`a ${s} section has no inside yet (ADR-0100 stage 4)`);const t=t=>{const i=n[t];return"open"!==i&&"closed"!==i&&gw("PARAM",e,`${t} is open or closed`),i};p={id:n.cavity,start:t("cavity-start"),end:t("cavity-end")},u.wall=Object.fromEntries([o,a].flatMap(t=>[`${t}-`,`${t}+`]).map(t=>[t,d()])),"closed"===p.start&&(u.startClosed=d()),"closed"===p.end&&(u.endClosed=d())}else void 0===n["cavity-start"]&&void 0===n["cavity-end"]||gw("PARAM",e,"the ends of an inside need the inside");return{axis:i,plane:r,section:s,points:l,rounded:c,...p?{cavity:p}:{},arg:u,count:h}}const ww=(t,e=1)=>[{arg:t,k:e}];function Mw(t,e){const n=xw(t.params,t.id),[i,s]=n.plane,r={},o={},a={},[c,l]=bw[n.axis],h={lo:[{arg:0,k:1}],hi:[{arg:0,k:1},{arg:1,k:1}]};if(r[n.axis]=ww(1),o[n.axis]={arg:1,k:1},a[c]={axis:n.axis,normal:-1,plane:h.lo},a[l]={axis:n.axis,normal:1,plane:h.hi},"polygon"===n.section){for(const t of[i,s])r[t]="profile",o[t]={refused:"SECTION_CORNERS"};return{measure:r,edit:o,faces:a,kind:"polygon"}}const d=n.arg.across,u="ellipse"===n.section?2:1;for(const t of[i,s])r[t]=ww(d[t],u),o[t]={arg:d[t],k:u};if(void 0!==t.args?.[d[i]]&&t.args[d[i]]===t.args[d[s]]&&(o[s]={arg:d[s],k:u,sameAs:i}),"portal"===n.section){const[t,e]=bw[i],[c,l]=bw[s];return a[t]={axis:i,normal:-1,plane:[{arg:d[i],k:-.5}]},a[e]={axis:i,normal:1,plane:[{arg:d[i],k:.5}]},a[c]={axis:s,normal:-1,plane:[]},a[l]={axis:s,normal:1,plane:[{arg:d[s],k:1}]},a[`opening-${t}`]={axis:i,normal:1,plane:[{arg:d[i],k:-.5},{arg:n.arg.jamb,k:1}]},a[`opening-${e}`]={axis:i,normal:-1,plane:[{arg:d[i],k:.5},{arg:n.arg.jamb,k:-1}]},a[`opening-${l}`]={axis:s,normal:-1,plane:[{arg:d[s],k:1},{arg:n.arg.head,k:-1}]},{measure:r,edit:o,faces:a,kind:"portal"}}const p="ellipse"===n.section?1:.5,f="ellipse"===n.section?{contact:"line"}:{};for(const t of[i,s]){const[e,n]=bw[t];a[e]={axis:t,normal:-1,plane:[{arg:d[t],k:-p}],...f},a[n]={axis:t,normal:1,plane:[{arg:d[t],k:p}],...f}}if(n.cavity){const t=n.arg.wall;for(const e of[i,s]){const[n,i]=bw[e];a[`inside-${n}`]={axis:e,normal:1,plane:[{arg:d[e],k:-p},{arg:t[`${e}-`],k:1}],...f},a[`inside-${i}`]={axis:e,normal:-1,plane:[{arg:d[e],k:p},{arg:t[`${e}+`],k:-1}],...f}}void 0!==n.arg.startClosed&&(a[`inside-${c}`]={axis:n.axis,normal:1,plane:[...h.lo,{arg:n.arg.startClosed,k:1}]}),void 0!==n.arg.endClosed&&(a[`inside-${l}`]={axis:n.axis,normal:-1,plane:[...h.hi,{arg:n.arg.endClosed,k:-1}]})}return{measure:r,edit:o,faces:a,kind:n.section}}function Sw(t,e){const n=t??{},i=n.axis;return Xx.includes(i)||gw("PARAM",e,`axis is x, y or z, not ${String(n.axis)}`),"half-ellipse"!==n.profile&&"taper"!==n.profile&&gw("PARAM",e,`profile is half-ellipse or taper, not ${String(n.profile)}`),{axis:i,profile:n.profile,count:"taper"===n.profile?4:2}}function kw(t,e){const n=Sw(t.params,t.id),[i,s]=[...ew[n.axis]].sort(),r={},o={};if("half-ellipse"===n.profile)return r[n.axis]=ww(1,2),o[n.axis]={arg:1,k:2},r[i]=r[s]=ww(0,2),o[i]={arg:0,k:2},o[s]={arg:0,k:2,sameAs:i},{measure:r,edit:o,faces:{},kind:"sphere"};const[a,c]=bw[n.axis];r[n.axis]=ww(1),o[n.axis]={arg:1,k:1};r[i]=r[s]=[{arg:2,k:2},{arg:3,k:2}],o[i]={arg:3,k:2,with:[2]},o[s]={arg:3,k:2,with:[2],sameAs:i};const l={lo:[{arg:0,k:1}],hi:[{arg:0,k:1},{arg:1,k:1}]};return{measure:r,edit:o,faces:{[a]:{axis:n.axis,normal:-1,plane:l.lo},[c]:{axis:n.axis,normal:1,plane:l.hi}},kind:"taper"}}function Aw(t,e){const n=t??{};"polygon"!==n.section&&gw("PARAM",e,`a loft starts from a drawn section, not ${String(n.section)}`),void 0===n.corner&&void 0===n.cavity||gw("PARAM",e,"a loft has no corners and no inside");const i=xw(n,e),[s,r]=i.plane;return{...i,apex:{[s]:i.count,[r]:i.count+1},count:i.count+2}}function Ew(t,e){const n=Aw(t.params,t.id),i={},s={},[r]=bw[n.axis];i[n.axis]=ww(1),s[n.axis]={arg:1,k:1};for(const t of n.plane)i[t]="profile",s[t]={refused:"SECTION_CORNERS"};return{measure:i,edit:s,faces:{[r]:{axis:n.axis,normal:-1,plane:[{arg:0,k:1}]}},kind:"pyramid"}}const Cw=(t,e)=>Object.fromEntries(Object.entries(t).map(([t,n])=>[t,{axis:n.axis,normal:n.normal,at:n.plane.reduce((t,n)=>t+n.k*e[n.arg],0)}]));function Tw(t,e,n){const i=Xx.find(t=>t!==e&&t!==n),[s,r]=ew[i];let o=0;for(let e=0;e<t.length;e++){const n=t[e],i=t[(e+1)%t.length];o+=n[s]*i[r]-i[s]*n[r]}return o>0?t:[t[0],...t.slice(1).reverse()]}function Pw(t,e){const[n,i]=ew[e];let s=0;const r=t.points;for(let t=0;t<r.length;t++){const e=r[t],o=r[(t+1)%r.length];s+=e[n]*o[i]-o[n]*e[i]}return s}function Ow(t,e,n){const i=xw(n.params,e),[s,r]=i.plane,o=t[0],a=t[1];a>0||gw("GEOMETRY_DOMAIN",e,`a push of positive length required, not ${a}`);const c={start:o,length:a};let l;if("polygon"===i.section){const e=i.points.map(e=>({id:e,[s]:t[i.arg.point[e][s]],[r]:t[i.arg.point[e][r]]}));e.forEach(t=>{c[`point.${t.id}.${s}`]=t[s],c[`point.${t.id}.${r}`]=t[r]}),l={kind:"polygon",points:e}}else if("portal"===i.section){const n=t[i.arg.across[s]],o=t[i.arg.across[r]],a=t[i.arg.jamb],h=t[i.arg.head];n>0&&o>0&&a>0&&h>0&&2*a<n&&h<o||gw("GEOMETRY_DOMAIN",e,"positive measures, jambs narrower than half the width and a head lower than the height required"),Object.assign(c,{[`size.${s}`]:n,[`size.${r}`]:o,jamb:a,head:h}),l=function(t,e,n,i,s,r){const o=-n/2,a=n/2,c=o+s,l=a-s,h=i-r,d=(n,i,s)=>({id:n,[t]:i,[e]:s});return{kind:"polygon",points:Tw([d("p1",o,0),d("p2",o,i),d("p3",a,i),d("p4",a,0),d("p5",l,0),d("p6",l,h),d("p7",c,h),d("p8",c,0)],t,e)}}(s,r,n,o,a,h)}else{const e={[s]:t[i.arg.across[s]],[r]:t[i.arg.across[r]]},n="ellipse"===i.section?"radius":"size";if(c[`${n}.${s}`]=e[s],c[`${n}.${r}`]=e[r],"ellipse"===i.section)l={kind:"ellipse",radius:e};else if(l={kind:"rectangle",size:e},i.rounded){const n={[s]:t[i.arg.corner[s]],[r]:t[i.arg.corner[r]]};c[`corner.${s}`]=n[s],c[`corner.${r}`]=n[r],(n[s]>0||n[r]>0)&&(l={kind:"rectangle",size:e,corner:n})}}const h=cw(l,i.axis);h.length&&gw("GEOMETRY_DOMAIN",e,`the section is not valid: ${h.map(t=>t.code).join(", ")}`),"polygon"!==l.kind||"polygon"!==i.section||Pw(l,i.axis)>0||gw("SECTION_WINDING",e,"a drawn section runs counter-clockwise seen from its push axis; write it with normalizeFigureSection");const d={axis:i.axis,section:l,start:o,end:o+a};let u;if(i.cavity){const n=Object.fromEntries(Object.entries(i.arg.wall).map(([e,n])=>[e,t[n]]));u={id:i.cavity.id,wall:n,start:"open"===i.cavity.start?"open":{closed:t[i.arg.startClosed]},end:"open"===i.cavity.end?"open":{closed:t[i.arg.endClosed]}};for(const[t,e]of Object.entries(n))c[`wall.${t}`]=e;"open"!==u.start&&(c["closed.start"]=u.start.closed),"open"!==u.end&&(c["closed.end"]=u.end.closed);const s=function(t,e=[]){const{axis:n,section:i,start:s,end:r}=t;if(!(r-s>0))return{refused:{code:"SPAN_NOT_POSITIVE"}};if(e.length>1)return{refused:{code:"CAVITY_COUNT",count:e.length}};const o=e[0];let a;if(o){const t=pw(i,n,o.wall);if("refused"in t)return{refused:{code:"CAVITY",cavity:o.id,refused:t.refused,...t.side?{side:t.side}:{}}};a=t.section;const e=t=>"open"===t?0:t.closed;for(const t of["start","end"]){const e=o[t];if("open"!==e&&!(e.closed>0))return{refused:{code:"CAVITY_END_NOT_POSITIVE",cavity:o.id,end:t}}}if(!(r-s-e(o.start)-e(o.end)>0))return{refused:{code:"CAVITY_NO_LENGTH",cavity:o.id}}}const c=uw(i,n),l=[{id:"start-face",kind:"plane",normal:fw(n,-1),..."open"===o?.start?{open:!0}:{}},{id:"end-face",kind:"plane",normal:fw(n,1),..."open"===o?.end?{open:!0}:{}}];for(const t of c)l.push("flat"===t.shape?{id:`side-face:${t.id}`,kind:"plane",normal:mw(i,n,t)}:{id:`side-face:${t.id}`,kind:"curved"}),l.push({id:`edge:start:${t.id}`,kind:"edge"},{id:`edge:end:${t.id}`,kind:"edge"});if("polygon"===i.kind)for(const t of i.points)l.push({id:`edge:${t.id}`,kind:"edge"});else if("rectangle"===i.kind&&!c.some(t=>"curved"===t.shape)){const[t,e]=[...ew[n]].sort();for(const n of["-","+"])for(const i of["-","+"])l.push({id:`edge:${t}${n}${e}${i}`,kind:"edge"})}if(o&&a){for(const t of uw(a,n)){const e=`cavity-wall:${o.id}:${t.id}`;if("curved"===t.shape)l.push({id:e,kind:"curved"});else{const i=mw(a,n,t);l.push({id:e,kind:"plane",normal:{x:-i.x||0,y:-i.y||0,z:-i.z||0}})}}"open"!==o.start&&l.push({id:`cavity-start:${o.id}`,kind:"plane",normal:fw(n,1)}),"open"!==o.end&&l.push({id:`cavity-end:${o.id}`,kind:"plane",normal:fw(n,-1)})}return l.push({id:"centre",kind:"point"}),{features:l}}(d,[u]);"refused"in s&&gw("GEOMETRY_DOMAIN",e,`the inside is not valid: ${s.refused.code}${"refused"in s.refused?` ${s.refused.refused}`:""}`)}return{provider:"extrude",dimensions:c,extrusion:d,...u?{cavity:u}:{},faces:Cw(Mw(n).faces,t)}}function Dw(t,e,n){const i=Sw(n.params,e),s=Cw(kw(n).faces,t);if("half-ellipse"===i.profile){const[n,r]=t;return n>0&&r>0||gw("GEOMETRY_DOMAIN",e,"positive radii required"),{provider:"revolve",dimensions:{radial:n,axial:r},revolution:{axis:i.axis,profile:{kind:"half-ellipse",radial:n,axial:r}},faces:s}}const[r,o,a,c]=t;return o>0&&a>=0&&c>=0&&a+c>0||gw("GEOMETRY_DOMAIN",e,"a positive length and radii of 0 or more, not both 0, required"),{provider:"revolve",dimensions:{start:r,length:o,startRadius:a,endRadius:c},revolution:{axis:i.axis,profile:{kind:"taper",start:r,end:r+o,startRadius:a,endRadius:c}},faces:s}}function Iw(t,e,n){const i=Aw(n.params,e),[s,r]=i.plane,o=t[0],a=t[1];a>0||gw("GEOMETRY_DOMAIN",e,`a loft of positive length required, not ${a}`);const c={start:o,length:a},l=i.points.map(e=>({id:e,[s]:t[i.arg.point[e][s]],[r]:t[i.arg.point[e][r]]}));l.forEach(t=>{c[`point.${t.id}.${s}`]=t[s],c[`point.${t.id}.${r}`]=t[r]});const h={kind:"polygon",points:l},d=cw(h,i.axis);d.length&&gw("GEOMETRY_DOMAIN",e,`the section is not valid: ${d.map(t=>t.code).join(", ")}`),Pw(h,i.axis)>0||gw("SECTION_WINDING",e,"a drawn section runs counter-clockwise seen from its push axis; write it with normalizeFigureSection");const u={[s]:t[i.apex[s]],[r]:t[i.apex[r]]};return Number.isFinite(u[s])&&Number.isFinite(u[r])||gw("GEOMETRY_DOMAIN",e,"a finite apex required"),c[`apex.${s}`]=u[s],c[`apex.${r}`]=u[r],{provider:"loft",dimensions:c,loft:{axis:i.axis,section:h,start:o,end:o+a,apex:u},faces:Cw(Ew(n).faces,t)}}function zw(t,e,n){return{kind:"shape",provider:t,frame:e.params.frame,faces:Object.fromEntries(Object.entries(n).map(([t,e])=>[t,e.contact?[e.axis,e.normal,e.contact]:[e.axis,e.normal]]))}}const Rw={"extrude@1":{ports:["shape"],params:["frame","axis","section"],optionalParams:["points","corner","cavity","cavity-start","cavity-end"],types(t,e,n){const i=xw(n.params,e);return t.length===i.count&&t.every(yw)||gw("TYPE",e,`a ${i.section} push takes ${i.count} lengths, not ${t.length}`),[zw("extrude",n,Mw(n).faces)]},run:(t,e,n)=>[Ow(t,e,n)]},"revolve@1":{ports:["shape"],params:["frame","axis","profile"],types(t,e,n){const i=Sw(n.params,e);return t.length===i.count&&t.every(yw)||gw("TYPE",e,`a ${i.profile} turn takes ${i.count} lengths, not ${t.length}`),[zw("revolve",n,kw(n).faces)]},run:(t,e,n)=>[Dw(t,e,n)]},"loft@1":{ports:["shape"],params:["frame","axis","section","points"],types(t,e,n){const i=Aw(n.params,e);return t.length===i.count&&t.every(yw)||gw("TYPE",e,`a loft of ${i.points.length} points takes ${i.count} lengths, not ${t.length}`),[zw("loft",n,Ew(n).faces)]},run:(t,e,n)=>[Iw(t,e,n)]}};function jw(t,e){const n=function(t){const e={};if(t.extrusion){const n=t.extrusion,[i,s]=ew[n.axis];e[n.axis]={min:n.start,max:n.end};const r=n.section;for(const t of[i,s])if("rectangle"===r.kind)e[t]={min:-r.size[t]/2,max:r.size[t]/2};else if("ellipse"===r.kind)e[t]={min:-r.radius[t],max:r.radius[t]};else{const n=r.points.map(e=>e[t]);e[t]={min:Math.min(...n),max:Math.max(...n)}}return e}if(t.loft){const n=t.loft;e[n.axis]={min:n.start,max:n.end};for(const t of ew[n.axis]){const i=[...n.section.points.map(e=>e[t]),n.apex[t]];e[t]={min:Math.min(...i),max:Math.max(...i)}}return e}const n=t.revolution,[i,s]=ew[n.axis];if("half-ellipse"===n.profile.kind){e[n.axis]={min:-n.profile.axial,max:n.profile.axial};for(const t of[i,s])e[t]={min:-n.profile.radial,max:n.profile.radial}}else{const t=Math.max(n.profile.startRadius,n.profile.endRadius);e[n.axis]={min:n.profile.start,max:n.profile.end};for(const n of[i,s])e[n]={min:-t,max:t}}return e}(t),i=Xx.map(t=>(n[t].min+n[t].max)/2);if("centre"===e)return i;const s=t.faces[e],r={x:0,y:1,z:2};if(s){const n=[...i];if(n[r[s.axis]]=s.at,t.loft)for(const e of ew[t.loft.axis]){const i=t.loft.section.points.map(t=>t[e]);n[r[e]]=(Math.min(...i)+Math.max(...i))/2}if(e.startsWith("inside-")&&t.cavity&&t.extrusion){const e=t.extrusion,o=t.cavity,a=o.wall;for(const t of ew[e.axis])t!==s.axis&&(n[r[t]]=i[r[t]]+(a[`${t}-`]-a[`${t}+`])/2);if(s.axis!==e.axis){const t=e.start+("open"===o.start?0:o.start.closed),i=e.end-("open"===o.end?0:o.end.closed);n[r[e.axis]]=(t+i)/2}}return n}if("half-ellipse"===t.revolution?.profile.kind){const t=Object.entries(bw).flatMap(([t,[e,n]])=>[[e,t,-1],[n,t,1]]).find(([t])=>t===e);if(!t)return;const s=[...i];return s[r[t[1]]]=t[2]<0?n[t[1]].min:n[t[1]].max,s}}function Lw(t,e){"string"!=typeof t&&Fw("PARAM",e,"layout required"),t.startsWith("L")||Fw("PARAM",e,"layout starts with L");const n=t.slice(1).split(".").map(t=>""===t?[]:t.split("_").map(Number));return(6!==n.length||n.some(t=>!t.length||t.some(t=>!Number.isSafeInteger(t)||t<0)))&&Fw("PARAM",e,"layout is six groups of term counts, each with one candidate or more"),n}const Fw=(t,e,n)=>{throw new tw(t,e,n)},Nw={mm:[[1,0,0],1],cm:[[1,0,0],10],m:[[1,0,0],1e3],rad:[[0,1,0],1],deg:[[0,1,0],Math.PI/180],s:[[0,0,1],1],ratio:[[0,0,0],1],percent:[[0,0,0],.01]},Hw=[1,0,0],Bw=[0,0,0],Yw=[0,1,0],Vw={kind:"count"},Gw={kind:"flag"};Nw.count=[Vw,1];const $w=(t,e)=>Array.isArray(t)&&Array.isArray(e)?t.length===e.length&&t.every((t,n)=>t===e[n]):JSON.stringify(t)===JSON.stringify(e);function Uw(t,e,n,i){t&&"object"==typeof t&&!Array.isArray(t)||Fw("SCHEMA",i,"object required");for(const n of e)Object.hasOwn(t,n)||Fw("SCHEMA",i,`missing ${n}`);for(const s of Object.keys(t))[...e,...n].includes(s)||Fw("SCHEMA",i,`unknown ${s}`)}function Ww(t,e){return"string"==typeof t&&/^[a-zA-Z][a-zA-Z0-9_.-]*$/.test(t)||Fw("ID",e,"invalid id"),t}function qw(t,e){return"number"==typeof t&&Number.isFinite(t)||Fw("NON_FINITE",e,String(t)),t}function Xw(t,e){return Object.hasOwn(Nw,t)||Fw("UNIT",e,String(t)),Nw[t]}function Kw(t,e,n){(t.length!==e.length||t.some((t,n)=>!$w(t,e[n])))&&Fw("TYPE",n,`expected ${JSON.stringify(e)}, got ${JSON.stringify(t)}`)}const Qw={"add@1":{ports:["value"],types:(t,e)=>(2===t.length&&t.every(Array.isArray)&&$w(t[0],t[1])||Fw("TYPE",e,"addition needs same scalar dimensions"),[t[0]]),run:([t,e])=>[t+e]},"mul@1":{ports:["value"],types:(t,e)=>(2===t.length&&t.every(Array.isArray)||Fw("TYPE",e,"two scalar arguments"),[t[0].map((e,n)=>e+t[1][n])]),run:([t,e])=>[t*e]},"div@1":{ports:["value"],types:(t,e)=>(2===t.length&&t.every(Array.isArray)||Fw("TYPE",e,"two scalar arguments"),[t[0].map((e,n)=>e-t[1][n])]),run:([t,e],n)=>(0===e&&Fw("DOMAIN",n,"zero denominator"),[t/e])},"sin@1":{ports:["value"],types:(t,e)=>(Kw(t,[Yw],e),[Bw]),run:([t])=>[Math.sin(t)]},"geomean@1":{ports:["value"],types:(t,e)=>((t.length<2||t.length>3||!t.every(Array.isArray)||!t.every(e=>$w(e,t[0])))&&Fw("TYPE",e,"geometric mean needs two or three scalars of the same dimension"),[t[0]]),run:(t,e)=>(t.some(t=>t<0)&&Fw("DOMAIN",e,"geometric mean of a negative value"),[Math.pow(t.reduce((t,e)=>t*e,1),1/t.length)])},"curve@1":{ports:["value"],types(t,e){(t.length<5||t.length%2==0||!t.every(Array.isArray))&&Fw("TYPE",e,"x and at least two (at, value) key pairs, all scalars");for(let n=1;n<t.length;n+=2)$w(t[n],t[0])||Fw("TYPE",e,`key ${(n-1)/2}: at must have the dimension of x`),$w(t[n+1],t[2])||Fw("TYPE",e,`key ${(n-1)/2}: every value must have one dimension`);return[t[2]]},run:(t,e)=>{const n=t[0],i=(t.length-1)/2,s=e=>t[1+2*e],r=e=>t[2+2*e];for(let t=1;t<i;t++)s(t)>s(t-1)||Fw("DOMAIN",e,`keys out of order: at[${t}] = ${s(t)} is not after at[${t-1}] = ${s(t-1)}`);if(n<=s(0))return[r(0)];if(n>=s(i-1))return[r(i-1)];let o=0;for(;o<i-2&&s(o+1)<=n;)o++;const a=(n-s(o))/(s(o+1)-s(o));return[r(o)+(r(o+1)-r(o))*a]}},"at-least@1":{ports:["value"],types:(t,e)=>(2===t.length&&t.every(Array.isArray)&&$w(t[0],t[1])||Fw("TYPE",e,"at-least compares two scalars of the same dimension"),[Gw]),run:([t,e])=>[t>=e]},"max@1":{ports:["value"],types:(t,e)=>((t.length<2||!t.every(Array.isArray)||!t.every(e=>$w(e,t[0])))&&Fw("TYPE",e,"two or more scalars of the same dimension"),[t[0]]),run:t=>[Math.max(...t)]},"min@1":{ports:["value"],types:(t,e)=>((t.length<2||!t.every(Array.isArray)||!t.every(e=>$w(e,t[0])))&&Fw("TYPE",e,"two or more scalars of the same dimension"),[t[0]]),run:t=>[Math.min(...t)]},"affine-bounds@1":{ports:["xmin","xmax","ymin","ymax","zmin","zmax"],params:["layout"],types(t,e,n){const i=Lw(n.params.layout,e);let s=0;for(const n of i)for(const i of n){$w(t[s++],Hw)||Fw("TYPE",e,`candidate constant ${s-1} is a length`);for(let n=0;n<i;n++)$w(t[s++],Hw)||Fw("TYPE",e,`term value ${s-1} is a length`),$w(t[s++],Bw)||Fw("TYPE",e,`term ratio ${s-1} is a ratio`)}return s!==t.length&&Fw("TYPE",e,`the layout takes ${s} arguments; ${t.length} were given`),Array(6).fill(Hw)},run:(t,e,n)=>{const i=Lw(n.params.layout,e);let s=0;return i.map((e,n)=>{const i=e.map(e=>{let n=t[s++];for(let i=0;i<e;i++)n+=t[s++]*t[s++];return n});return n%2==0?Math.min(...i):Math.max(...i)})}},"between@1":{ports:["length","center"],types:(t,e)=>(Kw(t,[Hw,Hw,Hw,Hw],e),[Hw,Hw]),run:([t,e,n,i],s)=>{(n<0||i<0)&&Fw("DOMAIN",s,"negative margin");const r=e-t-n-i;return r>0||Fw("NO_SPACE",s,`available=${e-t}; margins=${n+i}; deficit=${Math.max(0,-r)}; positive length required`),[r,(t+e+n-i)/2]}},"box@1":{ports:["xMin","xMax","yMin","yMax","zMin","zMax"],types:(t,e)=>(Kw(t,[Hw,Hw,Hw],e),Array(6).fill(Hw)),run:([t,e,n],i)=>([t,e,n].some(t=>!(t>0))&&Fw("GEOMETRY_DOMAIN",i,"positive width,height,depth required"),[-t/2,t/2,-e/2,e/2,-n/2,n/2]),geometry:([t,e,n])=>({provider:"box@1",dimensions:{width:t,height:e,depth:n}})},"cylinder@1":{ports:["start","end","radialMin","radialMax"],types:(t,e)=>(Kw(t,[Hw,Hw],e),Array(4).fill(Hw)),run:([t,e],n)=>(t>0&&e>0||Fw("GEOMETRY_DOMAIN",n,"positive radius,length required"),[-e/2,e/2,-t,t]),geometry:([t,e])=>({provider:"cylinder@1",axis:"Y",dimensions:{radius:t,length:e}})}},Zw=(t,e)=>({kind:"transform",from:t,to:e}),Jw=()=>[[1,0,0],[0,1,0],[0,0,1]],tM=t=>t[0].map((e,n)=>t.map(t=>t[n])),eM=(t,e)=>t.reduce((t,n,i)=>t+n*e[i],0),nM=(t,e,n,i)=>0+t[0]*e+t[1]*n+t[2]*i,iM=(t,e)=>3===t.length&&3===e.length?[nM(t[0],e[0],e[1],e[2]),nM(t[1],e[0],e[1],e[2]),nM(t[2],e[0],e[1],e[2])]:t.map(t=>eM(t,e)),sM=(t,e)=>{if(3!==t.length||3!==e.length||t.some(t=>3!==t.length)||e.some(t=>3!==t.length))return t.map(t=>tM(e).map(e=>eM(t,e)));const[n,i,s]=e;return t.map(t=>[nM(t,n[0],i[0],s[0]),nM(t,n[1],i[1],s[1]),nM(t,n[2],i[2],s[2])])},rM=(t,e)=>3===t.length&&3===e.length?[t[0]+e[0],t[1]+e[1],t[2]+e[2]]:t.map((t,n)=>t+e[n]),oM=(t,e)=>({r:sM(t.r,e.r),t:rM(iM(t.r,e.t),t.t)}),aM=t=>{const e=tM(t.r);return{r:e,t:iM(e,t.t.map(t=>-t))}};function cM(t,e,n=[]){Uw(t.params,e,n,t.id);for(const i of[...e,...n.filter(e=>Object.hasOwn(t.params,e))])Ww(t.params[i],t.id)}function lM(t,e,n){(t.length!==n||t.some(t=>"transform"!==t.kind))&&Fw("TYPE",e,"rigid transforms required")}Object.assign(Qw,{"fit-pitch@1":{ports:["layout"],types:(t,e)=>(Kw(t,[Hw,Hw,Hw,Hw,Hw,Bw,Vw],e),[{kind:"layout"}]),run:([t,e,n,i,s,r,o],a)=>{t>=0&&e>=0&&n>=0&&i>0&&s>0&&r>=0&&r<=1&&Number.isSafeInteger(o)&&o>=0&&o<=1e4||Fw("LAYOUT_DOMAIN",a,"invalid length, margins, extent, pitch, alignment or limit");const c=t-e-n,l=c<i?0:1+Math.floor((c-i)/s);l>o&&Fw("RESOURCE_LIMIT",a,`count=${l}, limit=${o}`);const h=l?c-i-(l-1)*s:0;return[{centers:Array.from({length:l},(t,n)=>e+i/2+r*h+n*s),count:l}]}},"fixed-count@1":{ports:["layout"],types:(t,e)=>(Kw(t,[Vw,Hw,Hw,Hw,Hw,Bw,Vw],e),[{kind:"layout"}]),run:([t,e,n,i,s,r,o],a)=>{if(Number.isSafeInteger(t)&&t>=0&&Number.isSafeInteger(o)&&o>=0&&o<=1e4&&e>=0&&n>=0&&i>=0&&s>0&&r>=0&&r<=1||Fw("LAYOUT_DOMAIN",a,"invalid fixed count layout"),t>o&&Fw("RESOURCE_LIMIT",a,"fixed count exceeds limit"),!t)return[{centers:[],count:0}];const c=e-n-i-s;return(c<0||t>1&&c/(t-1)<s)&&Fw("NO_SPACE",a,"fixed count non-overlapping items do not fit"),[{centers:1===t?[n+s/2+r*c]:Array.from({length:t},(e,i)=>n+s/2+i*c/(t-1)),count:t}]}},"assembly@1":{ports:["assembly"],types:(t,e)=>(t.length&&!t.some(e=>"placed"!==e.kind&&"collection"!==e.kind||e.frame!==t[0].frame)||Fw("FRAME_TYPE",e,"assembly members need one common frame"),[{kind:"assembly",frame:t[0].frame}]),run:(t,e,n)=>[{members:t.flatMap((t,e)=>t.items?t.items.map(t=>({key:t.key,path:t.path,shape:t.shape,pose:t.pose})):[{key:n.args[e],...t}])}]},"repeat@1":{ports:["collection"],params:["axis"],optionalParams:["riseAxis","within"],types(t,e,n){["x","y","z"].includes(n.params.axis)||Fw("AXIS",e,n.params.axis);const i=4===t.length;return!i||["x","y","z"].includes(n.params.riseAxis)&&n.params.riseAxis!==n.params.axis&&$w(t[3],Hw)||Fw("FRAME_TYPE",e,"a rise is a length along an axis other than the row's"),(3!==t.length&&!i||"layout"!==t[0].kind||"assembly"!==t[1].kind||"transform"!==t[2].kind||t[2].from!==t[1].frame)&&Fw("FRAME_TYPE",e,"layout, assembly and compatible placement required"),[{kind:"collection",frame:t[2].to}]},run:([t,e,n,i],s,r)=>{t.count*e.members.length>1e4&&Fw("RESOURCE_LIMIT",s,"expanded geometry count > 10000");const o=["x","y","z"].indexOf(r.params.axis),a=["x","y","z"].indexOf(r.params.riseAxis),c=[];for(let s=0;s<t.count;s++)for(const l of e.members){const e=[0,0,0];e[o]=t.centers[s],void 0!==i&&(e[a]=s*i);const h=[r.id,s,...l.path??[l.key]];c.push({id:JSON.stringify(h),path:h,key:l.key,index:s,shape:l.shape,pose:oM(oM(n,{r:Jw(),t:e}),l.pose)})}return[{items:c}]},geometry:(t,e,n)=>n.params.within?[]:e[0].items},"select-item@1":{ports:["placed"],params:["member"],types:(t,e)=>(2===t.length&&"collection"===t[0].kind&&$w(t[1],Vw)||Fw("TYPE",e,"collection and count index required"),[{kind:"placed",frame:t[0].frame}]),run:([t,e],n,i)=>{const s=t.items.find(t=>t.index===e&&t.key===i.params.member);return s||Fw("TARGET_ABSENT",n,`${i.params.member}[${e}]`),[{shape:s.shape,pose:s.pose}]}},"rigid@1":{ports:["pose"],params:["from","to"],types:(t,e,n)=>(Kw(t,[Hw,Hw,Hw,Yw,Yw,Yw],e),[Zw(n.params.from,n.params.to)]),run:([t,e,n,i,s,r])=>{const o=Math.cos(i),a=Math.sin(i),c=Math.cos(s),l=Math.sin(s),h=Math.cos(r),d=Math.sin(r);return[{r:sM(sM([[1,0,0],[0,o,-a],[0,a,o]],[[c,0,l],[0,1,0],[-l,0,c]]),[[h,-d,0],[d,h,0],[0,0,1]]),t:[t,e,n]}]}},"axis-turn@1":{ports:["pose"],params:["from","to"],types:(t,e,n)=>(Kw(t,[Bw,Bw,Bw,Yw],e),[Zw(n.params.from,n.params.to)]),run:([t,e,n,i],s)=>{const r=Math.hypot(t,e,n);Math.abs(r-1)>1e-6&&Fw("AXIS",s,"unit axis required");const o=t/r,a=e/r,c=n/r,l=Math.cos(i),h=Math.sin(i),d=1-l;return[{r:[[l+o*o*d,o*a*d-c*h,o*c*d+a*h],[a*o*d+c*h,l+a*a*d,a*c*d-o*h],[c*o*d-a*h,c*a*d+o*h,l+c*c*d]],t:[0,0,0]}]}},"axis-slide@1":{ports:["pose"],params:["from","to"],types:(t,e,n)=>(Kw(t,[Bw,Bw,Bw,Hw],e),[Zw(n.params.from,n.params.to)]),run:([t,e,n,i],s)=>{const r=Math.hypot(t,e,n);return Math.abs(r-1)>1e-6&&Fw("AXIS",s,"unit axis required"),[{r:[[1,0,0],[0,1,0],[0,0,1]],t:[t/r*i,e/r*i,n/r*i]}]}},"compose@1":{ports:["pose"],types:(t,e)=>(lM(t,e,2),t[1].to!==t[0].from&&Fw("FRAME_TYPE",e,"composition intermediate frame mismatch"),[Zw(t[1].from,t[0].to)]),run:([t,e])=>[oM(t,e)]},"attach@1":{ports:["pose"],types(t,e){lM(t,e,3);const[n,i,s]=t;return n.from===i.to&&i.from===s.from||Fw("FRAME_TYPE",e,"A O inverse(B) frame mismatch"),[Zw(s.to,n.to)]},run:([t,e,n])=>[oM(oM(t,e),aM(n))]},"point@1":{ports:["point"],params:["frame"],types:(t,e,n)=>(Kw(t,[Hw,Hw,Hw],e),[{kind:"point",frame:n.params.frame}]),run:t=>[t]},"map-point@1":{ports:["point"],types:(t,e)=>(2===t.length&&"transform"===t[0].kind&&"point"===t[1].kind&&t[0].from===t[1].frame||Fw("FRAME_TYPE",e,"point frame must match transform source"),[{kind:"point",frame:t[0].to}]),run:([t,e])=>[rM(iM(t.r,e),t.t)]},"distance@1":{ports:["length"],types:(t,e)=>(2===t.length&&"point"===t[0].kind&&$w(t[0],t[1])||Fw("FRAME_TYPE",e,"distance requires points in same frame"),[Hw]),run:([t,e])=>[Math.hypot(...t.map((t,n)=>t-e[n]))]},"feature@1":{ports:["pose"],params:["frame","name"],types(t,e,n){1===t.length&&"shape"===t[0].kind&&t[0].faces||Fw("TYPE",e,"shape required");const i=Object.keys(t[0].faces);return[...i,"centre",..."revolve"!==t[0].provider||i.length?[]:["left","right","bottom","top","back","front"]].includes(n.params.name)||Fw("UNKNOWN_FEATURE",e,n.params.name),[Zw(n.params.frame,t[0].frame)]},run:([t],e,n)=>{const i=jw(t,n.params.name);return i||Fw("UNKNOWN_FEATURE",e,n.params.name),[{r:[[1,0,0],[0,1,0],[0,0,1]],t:i}]}},"place@1":{ports:["placed"],types:(t,e)=>(2===t.length&&"shape"===t[0].kind&&"transform"===t[1].kind&&t[0].frame===t[1].from||Fw("FRAME_TYPE",e,"shape local frame mismatch"),[{kind:"placed",frame:t[1].to}]),run:([t,e])=>[{shape:t,pose:e}],geometry:([t,e])=>({shape:t,pose:e})}}),Qw["member@1"]={...Qw["place@1"],geometry:void 0},Object.assign(Qw,Rw);for(const[t,e]of Object.entries(Qw))e.state="fit-pitch@1"===t||"fixed-count@1"===t?"refuses":"follows";const hM=[];for(const[t,e]of Object.entries(Qw))e.pure=!hM.includes(t);const dM=["add@1","mul@1","div@1","sin@1","geomean@1","curve@1","at-least@1","max@1","min@1","affine-bounds@1","between@1","assembly@1","repeat@1","select-item@1","rigid@1","axis-turn@1","axis-slide@1","compose@1","attach@1","point@1","map-point@1","distance@1","place@1","member@1"];for(const[t,e]of Object.entries(Qw))e.pure&&dM.includes(t)&&(e.poseForm="run");function uM(t,e,n){return Array.isArray(e)?qw(t,n):"flag"===e.kind?("boolean"!=typeof t&&Fw("FLAG",n,"boolean required"),t):"count"===e.kind?((!Number.isSafeInteger(t)||t<0)&&Fw("COUNT",n,"nonnegative safe integer required"),t):("transform"===e.kind&&fM(t)?gM(t,n):"placed"===e.kind&&pM(t,"shape","pose")&&bM.has(t.shape)&&fM(t.pose)?gM(t.pose,n):(yM(t,n),"shape"===e.kind&&t&&"object"==typeof t&&bM.add(t)),t)}Object.freeze(Object.keys(Qw).filter(t=>!Qw[t].poseForm)),Object.freeze(Object.fromEntries(Object.entries(Qw).map(([t,e])=>[t,e.state]))),Object.freeze(Object.fromEntries(Object.entries(Qw).map(([t,e])=>[t,e.pure]))),Object.freeze(Object.keys(Qw));const pM=(t,e,n)=>{if(!t||"object"!=typeof t||Array.isArray(t))return!1;let i=0;for(const s in t)if(Object.hasOwn(t,s)){if(i>1||s!==(0===i?e:n))return!1;i++}return 2===i},fM=t=>pM(t,"r","t")&&Array.isArray(t.r)&&Array.isArray(t.t);function mM(t,e){for(let n=0;n<t.length;n++){if(!(n in t))continue;const i=t[n];"number"==typeof i?Number.isFinite(i)||Fw("NON_FINITE",e,String(i)):yM(i,e)}}function gM(t,e){for(let n=0;n<t.r.length;n++){if(!(n in t.r))continue;const i=t.r[n];Array.isArray(i)?mM(i,e):yM(i,e)}mM(t.t,e)}function yM(t,e){if("number"==typeof t)Number.isFinite(t)||Fw("NON_FINITE",e,String(t));else if(Array.isArray(t))for(let n=0;n<t.length;n++)n in t&&yM(t[n],e);else if(t&&"object"==typeof t){const n=Object.keys(t);if(!(n.length<=2&&Array.isArray(t[n[0]])&&(n.length<2||Array.isArray(t[n[1]])))&&bM.has(t))return;for(let i=0;i<n.length;i++)yM(t[n[i]],e)}}const bM=new WeakSet,_M=["transform","placed","assembly","collection","point"],vM=t=>Array.isArray(t)||_M.includes(t?.kind)?void 0:String(t?.kind??"value");function xM(t){return function(t){Uw(t,["version","inputs","constants","nodes"],[],"model"),["r3-scalar-1","r3-spatial-1"].includes(t.version)||Fw("VERSION","model",t.version);for(const e of["inputs","constants","nodes"])Array.isArray(t[e])||Fw("SCHEMA",e,"array required");const e=structuredClone(t),n=new Map,i=new Map,s=new Map,r=new Map,o=[],a=[],c=(t,e)=>{Ww(t,e),n.has(t)&&Fw("DUPLICATE_WRITER",t,`${n.get(t)} and ${e}`),n.set(t,e)};for(const t of e.inputs)Uw(t,["id","unit","min","max"],["role"],"input"),c(t.id,"input"),i.set(t.id,Xw(t.unit,t.id)[0]),t.role&&!["design","state"].includes(t.role)&&Fw("SCHEMA",t.id,"unknown input role"),"state"===t.role&&s.set(t.id,new Set([t.id])),qw(t.min,t.id)>qw(t.max,t.id)&&Fw("RANGE",t.id,"min > max"),"count"===t.unit&&(uM(t.min,Vw,t.id),uM(t.max,Vw,t.id));for(const t of e.constants)Uw(t,["id","unit","value"],[],"constant"),c(t.id,"constant"),i.set(t.id,Xw(t.unit,t.id)[0]),uM(t.value,i.get(t.id),t.id);for(const t of e.nodes){Uw(t,["id","op","args","outputs"],["params"],"node"),Ww(t.id,"node"),r.has(t.id)&&Fw("DUPLICATE_NODE",t.id,"node id"),Object.hasOwn(Qw,t.op)||Fw("OPERATOR",t.id,t.op),Qw[t.op].params?cM(t,Qw[t.op].params,Qw[t.op].optionalParams):Object.hasOwn(t,"params")&&Fw("SCHEMA",t.id,"unexpected params"),Array.isArray(t.args)||Fw("SCHEMA",t.id,"args array required"),t.args.forEach(e=>Ww(e,t.id)),Uw(t.outputs,Qw[t.op].ports,[],t.id);for(const e of Object.values(t.outputs))c(e,t.id);r.set(t.id,t)}const l=new Set;function h(t){if(l.has(t))return;a.includes(t)&&Fw("CYCLE",t,[...a,t].join(" -> ")),a.push(t);const e=r.get(t),c=Qw[e.op],d=e.args.map(t=>(n.has(t)||Fw("UNKNOWN_REFERENCE",e.id,t),i.has(t)||h(n.get(t)),i.get(t))),u=c.types(d,e.id,e),p=new Set;for(const t of e.args)for(const e of s.get(t)??[])p.add(e);p.size&&(void 0===c.state&&Fw("STATE_POLICY",e.id,`${e.op} declares no policy for a state-dependent argument (${[...p].join(", ")})`),"refuses"===c.state&&Fw("TOPOLOGY_STATE",e.id,`${e.op} must depend on design inputs only; it depends on ${[...p].join(", ")}`)),c.ports.forEach((t,n)=>i.set(e.outputs[t],u[n])),p.size&&Object.values(e.outputs).forEach(t=>s.set(t,new Set(p))),a.pop(),l.add(t),o.push(e)}for(const t of r.keys())h(t);let d;const u=new Map,p=new Set(e.inputs.map(t=>t.id));function f(t){t&&"object"==typeof t&&!Array.isArray(t)||Fw("SCHEMA","input values","object required");for(const n of e.inputs)Object.hasOwn(t,n.id)||Fw("SCHEMA","input values",`missing ${n.id}`);for(const e of Object.keys(t))p.has(e)||Fw("SCHEMA","input values",`unknown ${e}`)}function m(t,e){const n=qw(e,t.id);return(n<t.min||n>t.max)&&Fw("INPUT_RANGE",t.id,`${n} outside [${t.min},${t.max}]`),uM(n*Xw(t.unit,t.id)[1],i.get(t.id),t.id)}function g(t,n){f(t);const s=new Map,r=[],a=new Map,c=new Set;for(const n of e.inputs)s.set(n.id,m(n,t[n.id])),c.add(n.id);for(const t of e.constants)s.set(t.id,qw(t.value*Xw(t.unit,t.id)[1],t.id));for(const t of o){const e=Qw[t.op],n=t.args.map(t=>s.get(t)),o=e.run(n,t.id,t);if(e.ports.forEach((e,n)=>{s.set(t.outputs[e],uM(o[n],i.get(t.outputs[e]),t.id)),c.add(t.outputs[e])}),e.geometry){const i=e.geometry(n,o,t),s=Array.isArray(i)?i:[{id:t.id,...i}];a.set(t.id,s),r.push(...s)}}return{result:{values:Object.fromEntries(s),geometry:r},kept:{input:{...t},values:s,bodies:a}}}return{outputTypes:Object.fromEntries([...i].map(([t,e])=>[t,structuredClone(e)])),dependence:Object.fromEntries([...s].map(([t,e])=>[t,[...e].sort()])),order:o.map(t=>t.id),evaluate:t=>g(t).result,evaluator(t={}){let e,n,i=0,s=[];const r=(t,e)=>{const n=t.geometry.map(t=>t.id);return(e||n.length!==s.length||n.some((t,e)=>t!==s[e]))&&i++,s=n,t},o=t=>{const n=e;if(e=void 0,!n){const n=g(t);return e=b(n.kept,n.result),r(n.result,!0)}const i=M(t,n);return e=n,r(i,!1)};return{evaluate:o,advance(s,r){if(e&&!r){const r=e;e=void 0;const a=w(s,r,n??=_(t.reads));if(e=r,"result"in a)return{...a.result,generation:i};return{kind:"evaluation",result:o(s),generation:i,why:a.why}}const a=!!e;return{kind:"evaluation",result:o(s),generation:i,why:{code:a?r:"NOT_BOUND"}}},poseInputs:()=>_(t.reads).inputs.map(t=>({...t}))}}};function y(){if(d)return d;const t=new Map,n=[],s=e=>{t.set(e,n.length),n.push(e)};e.inputs.forEach(t=>s(t.id)),e.constants.forEach(t=>s(t.id));const r=o.map((e,n)=>{const r=Qw[e.op];return r.ports.forEach(t=>s(e.outputs[t])),{n:e,op:r,index:n,args:e.args.map(e=>t.get(e)),outs:r.ports.map(n=>t.get(e.outputs[n])),types:r.ports.map(t=>i.get(e.outputs[t]))}}),a=n.map(()=>[]);for(const t of r)for(const e of t.args)a[e].push(t.index);const c=t=>{const e=new Uint8Array(r.length),n=[...t];for(;n.length;){const t=n.pop();for(const i of a[t])e[i]||(e[i]=1,n.push(...r[i].outs))}const i=[];return e.forEach((t,e)=>t&&i.push(e)),i},l=r.filter(t=>!t.op.pure),h=[...new Set([...l.map(t=>t.index),...c(l.flatMap(t=>t.outs))])].sort((t,e)=>t-e);return d={keys:n,slot:t,nodes:r,readers:a,reach:e.inputs.map((t,e)=>c([e])),always:h,shapes:r.filter(t=>t.op.geometry).map(t=>t.index)},d}function b(t,n){const i=y();return{raw:e.inputs.map(e=>t.input[e.id]),slots:i.keys.map(e=>t.values.get(e)),bodies:i.nodes.map(e=>t.bodies.get(e.n.id)),values:{...n.values},geometry:n.geometry.slice(),mark:new Int32Array(i.keys.length),ran:new Int32Array(i.nodes.length),epoch:0}}function _(t={}){const n=JSON.stringify([t.forbidden??{},[...t.external??[]].sort()]),s=u.get(n);if(s)return s;const r=y(),o=t.forbidden??{},a=new Set(t.external??[]),c={inputs:e.inputs.map((t,e)=>{const n=vM(i.get(t.id));if(n)return{fast:!1,code:"INPUT_NOT_POSE",input:t.id,node:t.id,reaches:n};if(Object.hasOwn(o,t.id))return{fast:!1,code:"INPUT_NOT_POSE",input:t.id,node:t.id,reaches:o[t.id]};for(const n of r.reach[e]){const e=r.nodes[n];if(!e.op.poseForm)return{fast:!1,code:"UNSUPPORTED_OPERATOR",input:t.id,node:e.n.id,op:e.n.op};for(const[n,i]of e.outs.entries()){const s=vM(e.types[n]);if(s)return{fast:!1,code:"INPUT_NOT_POSE",input:t.id,node:e.n.id,reaches:s};const a=r.keys[i];if(Object.hasOwn(o,a))return{fast:!1,code:"INPUT_NOT_POSE",input:t.id,node:e.n.id,reaches:o[a]}}}return{fast:!0}}),terminal:r.nodes.map(t=>"repeat@1"===t.n.op&&!t.n.params?.within&&t.outs.every(t=>!r.readers[t].length&&!a.has(r.keys[t]))),visits:new Map};return u.set(n,c),c}function v(t,e){const n=y();if(1===t.length)return n.reach[t[0]];const i=t.join();let s=e.visits.get(i);if(!s){const r=new Set;for(const e of t)for(const t of n.reach[e])r.add(t);s=[...r].sort((t,e)=>t-e),e.visits.size<256&&e.visits.set(i,s)}return s}function x(t){const e=y(),n=new Int32Array(e.nodes.length).fill(-1);let i=0;for(const s of e.shapes)n[s]=i,i+=t.bodies[s]?.length??0;return{raw:t.raw.slice(),slots:t.slots.slice(),mark:new Int32Array(e.keys.length),epoch:0,start:n,bodyCount:i,prefix:new Map}}function w(t,n,i){const s=y();f(t);const r=n.fast??=x(n),o=[],a=[];for(let n=0;n<e.inputs.length;n++){const i=e.inputs[n],s=t[i.id];s!==r.raw[n]&&(a.push(m(i,s)),o.push(n))}for(const t of o)if(!i.inputs[t].fast)return{why:i.inputs[t]};const c=++r.epoch;o.forEach((n,i)=>{r.raw[n]=t[e.inputs[n].id],r.slots[n]=a[i],r.mark[n]=c});const l=v(o,i),h=new Int32Array(r.bodyCount),d=new Float64Array(12*r.bodyCount);let u=0;const p=(t,e)=>{const n=e.r,i=e.t,s=12*u;h[u++]=t,d[s]=n[0][0],d[s+1]=n[0][1],d[s+2]=n[0][2],d[s+3]=n[1][0],d[s+4]=n[1][1],d[s+5]=n[1][2],d[s+6]=n[2][0],d[s+7]=n[2][1],d[s+8]=n[2][2],d[s+9]=i[0],d[s+10]=i[1],d[s+11]=i[2]};for(const t of l){const e=s.nodes[t];let n=!1;for(const t of e.args)if(r.mark[t]===c){n=!0;break}if(!n)continue;const o=new Array(e.args.length);for(let t=0;t<e.args.length;t++)o[t]=r.slots[e.args[t]];if(i.terminal[t]){const[n,i,s,a]=o,l=["x","y","z"].indexOf(e.n.params.axis),h=["x","y","z"].indexOf(e.n.params.riseAxis);let d=r.mark[e.args[2]]!==c&&(void 0===e.args[3]||r.mark[e.args[3]]!==c)?r.prefix.get(t):void 0;if(!d){d=[];for(let t=0;t<n.count;t++){const e=[0,0,0];e[l]=n.centers[t],void 0!==a&&(e[h]=t*a),d.push(oM(s,{r:Jw(),t:e}))}r.prefix.set(t,d)}let u=r.start[t];for(let t=0;t<n.count;t++)for(const n of i.members){const i=oM(d[t],n.pose);yM(i,e.n.id),p(u++,i)}continue}const a=e.op.run(o,e.n.id,e.n);if(e.outs.forEach((t,n)=>{r.slots[t]=uM(a[n],e.types[n],e.n.id),r.mark[t]=c}),e.op.geometry){const n=e.op.geometry(o,a,e.n),i=Array.isArray(n)?n:[n];let s=r.start[t];for(const t of i)p(s++,t.pose)}}return{result:{kind:"poses",generation:0,bodies:h.slice(0,u),poses:d.slice(0,12*u),read:t=>{const e=s.slot.get(t);return void 0===e&&Fw("TARGET_ABSENT",t,"no such value"),r.slots[e]},changed:t=>{const e=s.slot.get(t);return void 0!==e&&r.mark[e]===c}}}}function M(t,n){const i=y();f(t),n.fast=void 0;const s=++n.epoch,r=[];let o,a=-1,c=!1;if(e.inputs.forEach((e,i)=>{const o=t[e.id];o!==n.raw[i]&&(n.slots[i]=m(e,o),n.raw[i]=o,n.mark[i]=s,r.push(i),a>=0&&(c=!0),a=i)}),c||i.always.length){const t=[];for(const e of[...r.map(t=>i.reach[t]),i.always])for(const i of e)n.ran[i]!==s&&(n.ran[i]=s,t.push(i));o=t.sort((t,e)=>t-e)}else o=a>=0?i.reach[a]:[];let l=!1;for(const t of o){const e=i.nodes[t];if(e.op.pure&&!e.args.some(t=>n.mark[t]===s))continue;const o=e.args.map(t=>n.slots[t]),a=e.op.run(o,e.n.id,e.n);if(e.outs.forEach((t,i)=>{n.slots[t]=uM(a[i],e.types[i],e.n.id),n.mark[t]=s,r.push(t)}),e.op.geometry){const i=e.op.geometry(o,a,e.n);n.bodies[t]=Array.isArray(i)?i:[{id:e.n.id,...i}],l=!0}}for(const t of r)n.values[i.keys[t]]=n.slots[t];if(l){const t=[];for(const e of i.shapes){const i=n.bodies[e];i&&t.push(...i)}n.geometry=t}return{values:{...n.values},geometry:n.geometry.slice()}}}(t)}function wM(t,e,n){const i=function(t,e){const n=t.find(t=>t.id===e);if(!n)return{code:"TARGET_ABSENT",message:`${String(e)} is not an input of the figure`};if("state"===n.role)return{code:"PUBLIC_INPUT",message:`${e} is a state input; a board sets it as a parameter`};if(/^(sizing\.)?size\.[xyz]$/.test(e))return{code:"PUBLIC_INPUT",message:`${e} is the figure's size; a board sets it from the instance's bounds`};const i=t=>Number.isFinite(t)&&Math.abs(t)<1e12&&t!==Number.MIN_VALUE;return i(n.min)&&i(n.max)?null:{code:"PUBLIC_INPUT",message:`${e} has no range to hold a board's value to; give it one first`}}(t,e);if(i)throw new tw(i.code,n,i.message)}const MM=(t,e,n)=>{throw new tw(t,e,n)},SM={left:[-1,0,0],right:[1,0,0],bottom:[0,-1,0],top:[0,1,0],back:[0,0,-1],front:[0,0,1]};function kM(t,e,n){const{types:i,writers:s,model:r,assetFrame:o}=t;e&&"object"==typeof e&&!Array.isArray(e)||MM("SCHEMA",n,"object required");for(const t of["placement","feature"])Object.hasOwn(e,t)||MM("SCHEMA",n,`missing ${t}`);for(const t of Object.keys(e))["placement","feature"].includes(t)||MM("SCHEMA",n,`unknown ${t}`);const a=t=>("string"==typeof t&&t.trim()||MM("SCHEMA",n,"nonempty string required"),Object.hasOwn(i,t)||MM("TARGET_ABSENT",n,t),i[t]),c=a(e.placement),l=a(e.feature),h=s.get(e.placement),d=s.get(e.feature);let u,p=h;if("select-item@1"===h?.op){const t=s.get(h.args[0]),e="repeat@1"===t?.op?s.get(t.args[1]):null;"assembly@1"===e?.op&&e.args.includes(h.params.member)||MM("SURFACE_PROVENANCE",n,"selected member must belong to the referenced repeat assembly"),p=s.get(h.params.member),"member@1"!==p?.op&&MM("SURFACE_PROVENANCE",n,"selected source must be a declared template member"),r.inputs.some(t=>t.id===h.args[1]&&"state"===t.role)&&MM("TARGET_STATE",n,"binding target index must not change as animation state"),u={collection:h.args[0],index:h.args[1],member:h.params.member}}else"place@1"!==h?.op&&MM("SURFACE_PROVENANCE",n,"actual placement or selected repeated member required");"feature@1"!==d?.op&&MM("SURFACE_PROVENANCE",n,"provider feature required"),"placed"===c.kind&&c.frame===o&&"transform"===l.kind||MM("FRAME_TYPE",n,"contact must be in asset frame"),p.args[0]!==d.args[0]&&MM("SURFACE_OWNER",n,"feature belongs to a different shape declaration");const f=i[d.args[0]].provider,m=d.params.name,g=i[d.args[0]].faces,y=g?.[m];y||MM("SURFACE_UNSUPPORTED",n,"feature is not a supported planar surface"),"line"===y[2]&&MM("SURFACE_UNSUPPORTED",n,"feature touches a curved side along a line; it is not a surface to hold things on");const b=["x","y","z"].map(t=>t===y[0]?y[1]:0);return{...e,geometryId:u?null:h.id,selection:u,provider:f,face:m,frame:l.from,normal:b}}function AM(t,e,n,i,s={}){const[r,o]=ew[e],a=(t,i)=>{const a={x:0,y:0,z:0};return a[e]=n,a[r]=t+(s[r]??0),a[o]=i+(s[o]??0),[a.x,a.y,a.z]};if("polygon"===t.kind)return t.points.map(t=>a(t[r],t[o]));if("ellipse"===t.kind)return Array.from({length:i},(e,n)=>{const s=2*Math.PI*n/i;return a(t.radius[r]*Math.cos(s),t.radius[o]*Math.sin(s))});const c=t.size[r]/2,l=t.size[o]/2,h=t.corner?.[r]??0,d=t.corner?.[o]??0;if(!(h>0&&d>0))return[a(-c,-l),a(c,-l),a(c,l),a(-c,l)];const u=[];for(const[t,e,n]of[[1,1,0],[-1,1,Math.PI/2],[-1,-1,Math.PI],[1,-1,3*Math.PI/2]])for(let i=0;i<=8;i++){const s=n+i/8*(Math.PI/2);u.push(a(t*(c-h)+h*Math.cos(s),e*(l-d)+d*Math.sin(s)))}return u}function EM(t,e){return function(t,e){const n=t.extrusion;if(n){const i=[...AM(n.section,n.axis,n.start,e),...AM(n.section,n.axis,n.end,e)],s=t.cavity;if(s){const t=pw(n.section,n.axis,s.wall);if("section"in t){const r=n.start+("open"===s.start?0:s.start.closed),o=n.end-("open"===s.end?0:s.end.closed);i.push(...AM(t.section,n.axis,r,e,t.centre),...AM(t.section,n.axis,o,e,t.centre))}}return i}const i=t.loft;if(i){const t={x:0,y:0,z:0,...i.apex,[i.axis]:i.end};return[...AM(i.section,i.axis,i.start,e),[t.x,t.y,t.z]]}const s=t.revolution,[r,o]=ew[s.axis],a=(t,n)=>AM({kind:"ellipse",radius:{[r]:n,[o]:n}},s.axis,t,e);if("taper"===s.profile.kind)return[...a(s.profile.start,Math.max(s.profile.startRadius,1e-9)),...a(s.profile.end,Math.max(s.profile.endRadius,1e-9))];const{radial:c,axial:l}=s.profile,h=[];for(let t=1;t<6;t++){const e=t/6*Math.PI;h.push(...a(l*Math.cos(e),c*Math.sin(e)))}return h.push(...a(l,1e-9).slice(0,1),...a(-l,1e-9).slice(0,1)),h}(t,e??12)}function CM(t,e,n){return t.map(([t,i,s])=>[e[0][0]*t+e[0][1]*i+e[0][2]*s+n[0],e[1][0]*t+e[1][1]*i+e[1][2]*s+n[1],e[2][0]*t+e[2][1]*i+e[2][2]*s+n[2]])}function TM(t){const e=new Map;for(const n of t.document.model.nodes)for(const t of Object.values(n.outputs))e.set(t,n.id);return e}const PM=["floor","ceiling","center","wall"];function OM(t){const[e,n,i]=t.map(t=>t*Math.PI/180),s=t=>Math.round(Math.cos(t)),r=t=>Math.round(Math.sin(t)),o=[[1,0,0],[0,s(e),-r(e)],[0,r(e),s(e)]],a=[[s(n),0,r(n)],[0,1,0],[-r(n),0,s(n)]],c=[[s(i),-r(i),0],[r(i),s(i),0],[0,0,1]];return DM(DM(o,a),c)}const DM=(t,e)=>t.map(t=>e[0].map((n,i)=>t.reduce((t,n,s)=>t+n*e[s][i],0)));function IM(t){const e=t.document.model,n=t=>e.constants.find(e=>e.id===t)?.value;return t.document.capabilities.bindings.map(t=>{const i="string"==typeof t.pose?null:t.pose,s=i?e.nodes.find(t=>"place@1"===t.op&&t.outputs.placed===i.placement):null,r=i?((t,e)=>t.nodes.find(t=>Object.values(t.outputs).includes(e)))(e,i.feature):null,o=(t.region?.dimensions??[]).map(n);return{id:t.id,label:t.label,role:t.role,part:s?.id??null,face:r?.params?.name??null,accepts:[...t.accepts],capacity:t.capacity,region:3===o.length&&o.every(t=>"number"==typeof t)?{x:o[0],y:o[1],z:o[2]}:null}})}(()=>{const t=[];for(const e of[0,90,180,270])for(const n of[0,90,180,270])for(const i of[0,90,180,270]){const s=OM([e,n,i]);t.some(t=>t.every((t,e)=>t.every((t,n)=>t===s[e][n])))||t.push(s)}})();const zM=(t,e,n)=>{throw new tw(t,e,n)};function RM(t,e,n,i){t&&"object"==typeof t&&!Array.isArray(t)||zM("SCHEMA",i,"object required");for(const n of e)Object.hasOwn(t,n)||zM("SCHEMA",i,`missing ${n}`);for(const s of Object.keys(t))[...e,...n].includes(s)||zM("SCHEMA",i,`unknown ${s}`)}const jM=(t,e)=>{"string"==typeof t&&t.trim()||zM("SCHEMA",e,"nonempty string required")};function LM(t,e){return function(t,e){const n=xM(t),i=structuredClone(e),s=n.outputTypes,r=new Map(t.nodes.flatMap(t=>Object.values(t.outputs).map(e=>[e,structuredClone(t)]))),o=new Map;RM(i,["version","assetFrame","bindings"],["names"],"capabilities"),"r3-capability-3"!==i.version&&zM("VERSION","capabilities",i.version);if(jM(i.assetFrame,"assetFrame"),void 0!==i.names){Array.isArray(i.names)||zM("SCHEMA","names","array required");for(const t of i.names)Kx.includes(t)||zM("CAPABILITY_NAME","names",`${String(t)} is not one of ${Kx.join(", ")}`);new Set(i.names).size!==i.names.length&&zM("CAPABILITY_NAME","names","duplicate capability name");for(const[t,e]of Object.entries(Qx))i.names.includes(t)&&!e.some(t=>i.names.includes(t))&&zM("CAPABILITY_NAME","names",`${t} needs one of ${e.join(", ")} with it`)}Array.isArray(i.bindings)||zM("SCHEMA","bindings","array required");const a=new Set,c=(t,e)=>(jM(t,e),Object.hasOwn(s,t)||zM("TARGET_ABSENT",e,t),s[t]),l=(t,e,n)=>{const s=c(t,e);("transform"!==s.kind||s.to!==i.assetFrame||void 0!==n&&s.from!==n)&&zM("FRAME_TYPE",e,"transform must map declared local frame to assetFrame")},h=(e,n)=>kM({types:s,writers:r,model:t,assetFrame:i.assetFrame},e,n),d=new Map;for(const t of i.bindings){RM(t,["id","label","role","frame","pose","accepts","capacity"],["region","contacts"],"binding");for(const e of["id","label","frame"])jM(t[e],e);if(a.has(t.id)&&zM("DUPLICATE_BINDING",t.id,"duplicate id"),a.add(t.id),["seat","grip"].includes(t.role)||zM("ROLE",t.id,"explicit seat or grip required; slot is ambiguous"),"string"==typeof t.pose)l(t.pose,t.id,t.frame);else{const e=h(t.pose,t.id);e.frame!==t.frame&&zM("FRAME_TYPE",t.id,"binding frame must be the selected feature frame"),d.set(t.id,e)}if(Array.isArray(t.accepts)&&t.accepts.length||zM("SCHEMA",t.id,"nonempty accepts required"),t.accepts.forEach(e=>jM(e,t.id)),new Set(t.accepts).size!==t.accepts.length&&zM("SCHEMA",t.id,"duplicate accepted type"),(!Number.isSafeInteger(t.capacity)||t.capacity<1)&&zM("CAPACITY",t.id,"positive integer capacity required"),Object.hasOwn(t,"region")){RM(t.region,["kind","dimensions"],[],t.id+".region"),"centered-box"!==t.region.kind&&zM("REGION",t.id,"only centered-box is specified"),Array.isArray(t.region.dimensions)&&3===t.region.dimensions.length||zM("SCHEMA",t.id,"three dimension references required");for(const e of t.region.dimensions)"[1,0,0]"!==JSON.stringify(c(e,t.id))&&zM("TYPE",t.id,"region dimensions must be lengths")}if(void 0!==t.contacts){Array.isArray(t.contacts)||zM("SCHEMA",t.id,"contact array required");const e=new Set,n=[];for(const i of t.contacts){const s=h(i,t.id),r=JSON.stringify([i.placement,i.feature]);e.has(r)&&zM("DUPLICATE_CONTACT",t.id,r),e.add(r),n.push(s)}o.set(t.id,n)}}function u(t,e,n){const i=t=>function(t,e){const n=t[e.placement],i=t[e.feature],s=n.pose.r,r=s.map(t=>t.reduce((t,n,i)=>t+n*e.normal[i],0)),o=s.map((t,e)=>n.pose.t[e]+t.reduce((t,e,n)=>t+e*i.t[n],0));let a=e.geometryId;if(e.selection){const n=e.selection,i=t[n.collection].items.find(e=>e.index===t[n.index]&&e.key===n.member);i||MM("TARGET_ABSENT",e.placement,"selected repeated item is absent"),a=i.id}return{placement:e.placement,feature:e.feature,geometryId:a,provider:e.provider,face:e.face,pose:{r:s.map(t=>[...t]),t:o},normal:r,provenance:"verified-planar-surface"}}(e,t);let s=null;if(t.region){const n=t.region.dimensions.map(t=>e[t]);n.some(t=>!Number.isFinite(t)||t<=0)&&zM("REGION_DOMAIN",t.id,"positive region dimensions required"),s={kind:t.region.kind,dimensions:n}}let r={status:"unverified",reason:"NO_REQUEST"};if(Object.hasOwn(n,t.id)){const e=n[t.id];RM(e,["type","occupied"],[],t.id+".request"),jM(e.type,t.id),(!Number.isSafeInteger(e.occupied)||e.occupied<0)&&zM("OCCUPANCY",t.id,"nonnegative integer occupancy snapshot required");const i=[];t.accepts.includes(e.type)||i.push("TYPE_NOT_ACCEPTED"),e.occupied>=t.capacity&&i.push("CAPACITY_FULL"),r={status:i.length?"failed":"satisfied",reasons:i}}const a=(o.get(t.id)??[]).map(i),c=d.has(t.id)?i(d.get(t.id)):null;return{id:t.id,label:t.label,role:t.role,frame:t.frame,pose:c?c.pose:e[t.pose],...c?{targetGeometryId:c.geometryId}:{},region:s,contacts:a,checks:{declaration:{status:"satisfied"},eligibility:r,spatial:{status:"unverified",reason:"NO_CONTACT_OR_FIT_SOLVER"},collision:{status:"unverified",reason:"NOT_CHECKED"},safety:{status:"unverified",reason:"NOT_CHECKED"}}}}function p(t,e,n={}){return RM(n,[],[...a],"requests"),f(t.evaluate(e),n)}function f(t,e){const n=i.bindings.map(n=>u(n,t.values,e));return{geometry:t.geometry,bindings:n,values:t.values}}const m=t=>[t.placement,t.feature,...t.selection?[t.selection.collection,t.selection.index]:[]],g=new Map(i.bindings.map(t=>[t.id,[..."string"==typeof t.pose?[t.pose]:m(d.get(t.id)),...(o.get(t.id)??[]).flatMap(m),...t.region?.dimensions??[]]])),y={forbidden:Object.fromEntries(i.bindings.flatMap(t=>(t.region?.dimensions??[]).map(e=>[e,`region of ${t.id}`]))),external:[...new Set([...g.values()].flat())]};return{outputTypes:structuredClone(s),dependence:structuredClone(n.dependence),evaluate:(t,e={})=>p(n,t,e),evaluator(){const t=n.evaluator({reads:y});return{evaluate:(e,n={})=>p(t,e,n),advance:(e,n={})=>{RM(n,[],[...a],"requests");const s=t.advance(e,Object.keys(n).length?"REQUESTS":void 0);if("evaluation"===s.kind)return{...s,result:f(s.result,n)};const r=i.bindings.filter(t=>g.get(t.id).some(t=>s.changed(t))).map(t=>u(t,Object.fromEntries(g.get(t.id).map(t=>[t,s.read(t)])),n));return{kind:"poses",generation:s.generation,bodies:s.bodies,poses:s.poses,places:r}},poseInputs:()=>t.poseInputs()}}}}(t,e)}const FM=1048576;function NM(t,e){throw new tw(t,"document",e)}function HM(t){return(new TextEncoder).encode(t).byteLength}function BM(t){const e=new Set;!function t(n,i){if(i>64&&NM("DOCUMENT_LIMIT","nesting exceeds 64"),null===n||"string"==typeof n||"boolean"==typeof n)return;if("number"==typeof n)return void(Number.isFinite(n)||NM("JSON_VALUE","nonfinite number"));"object"!=typeof n&&NM("JSON_VALUE","only JSON values are allowed"),e.has(n)&&NM("JSON_VALUE","cycle");const s=Array.isArray(n);s||function(t){const e=Object.getPrototypeOf(t);return null===e||null===Object.getPrototypeOf(e)&&"function"==typeof e.hasOwnProperty}(n)||NM("JSON_VALUE","plain objects required"),e.add(n);const r=Object.getOwnPropertyDescriptors(n);for(const e of Reflect.ownKeys(r)){if(s&&"length"===e)continue;"string"!=typeof e&&NM("JSON_VALUE","symbols unsupported");const o=r[e];o.enumerable&&Object.hasOwn(o,"value")||NM("JSON_VALUE","hidden properties and accessors unsupported"),!s||/^(0|[1-9][0-9]*)$/.test(e)&&Number(e)<n.length||NM("JSON_VALUE","extra array property"),t(o.value,i+1)}s&&Object.keys(n).length!==n.length&&NM("JSON_VALUE","sparse array"),e.delete(n)}(t,0)}function YM(t){if(BM(t),!t||Array.isArray(t)||"object"!=typeof t||3!==Object.keys(t).length||!["version","model","capabilities"].every(e=>Object.hasOwn(t,e)))throw new tw("SCHEMA","document","expected version, model, capabilities only");if("figure-prototype-1"!==t.version)throw new tw("VERSION","document","unsupported document version");if(HM(JSON.stringify(t))>FM)throw new tw("DOCUMENT_LIMIT","document","over 1 MiB");const e=t;if(!Array.isArray(e.model?.nodes)||e.model.nodes.length>8192)throw new tw("DOCUMENT_LIMIT","document","maximum 8192 nodes");return LM(e.model,e.capabilities)}const VM=(t,e,n)=>{throw new tw(t,e,n)};function GM(t){return new Map(t.document.model.inputs.filter(t=>"state"===t.role).map(t=>[t.id,t.unit]))}function $M(t,e){const n=t.keys;if(e<=n[0].at)return n[0].value;const i=n[n.length-1];if(e>=i.at)return i.value;let s=0;for(;s<n.length-2&&n[s+1].at<=e;)s++;const r=n[s],o=n[s+1];if("step"===t.interpolation)return r.value;const a=o.at-r.at;return r.value+(e-r.at)/a*(o.value-r.value)}function UM(t,e,n="other"){Number.isFinite(e)||VM("DRIVER_TIME",t.id,"finite time required");const i=Math.max(0,e),s=t.time.duration,r=t.keys[0].value,o=t.keys[t.keys.length-1];let a;if("hold"===t.loop)a=$M(t,Math.min(i/s,1));else{const e=Math.floor(i/s);a=$M(t,(i-e*s)/s),t.accumulates&&(a+=e*(o.value-r))}return t.accumulates?"deg"===n||"rad"===n?function(t,e){const n="deg"===e?360:2*Math.PI,i=n/2,s=((t+i)%n+n)%n-i;return s===i?-i:s}(a,n):VM("DRIVER_STATE",t.id,"an accumulating driver needs an angle unit"):a}const WM=(t,e,n)=>{throw new tw(t,e,n)};function qM(t,e,n,i){t&&"object"==typeof t&&!Array.isArray(t)||WM("ASSET_SCHEMA",i,"object required");for(const n of e)Object.hasOwn(t,n)||WM("ASSET_SCHEMA",i,`missing ${n}`);for(const s of Object.keys(t))[...e,...n].includes(s)||WM("ASSET_SCHEMA",i,`unknown ${s}`)}function XM(t){return function(t){BM(t);const e=KM(t);HM(JSON.stringify(e))>FM&&WM("DOCUMENT_LIMIT","asset","over 1 MiB");qM(e,["version","name","document","designInputs","stateDefaults","palette","appearance"],["occupancy","placement","drivers","stateInputs","sizing","detailLevel","joints","publicInputs"],"asset"),void 0===e.placement||PM.includes(e.placement)||WM("ASSET_SCHEMA","placement",`one of ${PM.join(", ")} required`);"figure-asset-1"!==e.version&&WM("VERSION","asset",e.version);"string"==typeof e.name&&e.name.trim()||WM("ASSET_SCHEMA","name","nonempty name required");const n=structuredClone(e),i=YM(n.document),s=n.document.model,r=s.inputs.filter(t=>"state"!==t.role).map(t=>t.id),o=s.inputs.filter(t=>"state"===t.role).map(t=>t.id);qM(n.designInputs,r,[],"designInputs"),void 0===n.detailLevel||(t=>Zx.includes(t))(n.detailLevel)||WM("ASSET_SCHEMA","detailLevel",`${String(n.detailLevel)} is not a detail level; ${Zx.join(", ")}`);if(void 0!==n.sizing){"uniform"!==n.sizing&&WM("ASSET_SCHEMA","sizing",`${String(n.sizing)} is not a sizing rule; 'uniform' is`);for(const t of["x","y","z"])s.inputs.some(e=>e.id===`size.${t}`&&"design"===e.role)||WM("ASSET_SCHEMA","sizing",`a figure that grows uniformly declares its instance size; size.${t} is missing`)}if(qM(n.stateDefaults,o,[],"stateDefaults"),void 0!==n.publicInputs){Array.isArray(n.publicInputs)||WM("ASSET_SCHEMA","publicInputs","a list of the inputs a board may set");const t=new Set;for(const[e,i]of n.publicInputs.entries()){const n=`publicInputs[${e}]`;qM(i,["input","label"],["hint"],n),wM(s.inputs,i.input,`${n}.input`),"string"==typeof i.label&&i.label.trim()||WM("ASSET_SCHEMA",`${n}.label`,"a name shown on the board"),void 0!==i.hint&&"string"!=typeof i.hint&&WM("ASSET_SCHEMA",`${n}.hint`,"one line"),t.has(i.input)&&WM("PUBLIC_INPUT",`${n}.input`,`${i.input} is listed twice`),t.add(i.input)}}n.palette&&"object"==typeof n.palette&&!Array.isArray(n.palette)||WM("ASSET_SCHEMA","palette","token to hex color map required");for(const[t,e]of Object.entries(n.palette))t.trim()&&"string"==typeof e&&/^#[0-9a-f]{6}$/i.test(e)||WM("PALETTE","palette","six digit hex color required");const a=t=>{"string"==typeof t&&Object.hasOwn(n.palette,t)||WM("PALETTE",String(t),"unresolved color token")},c=new Map(s.nodes.flatMap(t=>Object.values(t.outputs).map(e=>[e,t]))),l=new Map(s.nodes.filter(t=>["place@1","member@1"].includes(t.op)).map(t=>[t.id,t])),h=new Map;Array.isArray(n.appearance)||WM("ASSET_SCHEMA","appearance","array required");for(const t of n.appearance){if(qM(t,["target","material"],["segments","visibility"],"appearance"),void 0!==t.visibility){const e=i.outputTypes[t.visibility];"string"==typeof t.visibility&&e&&"flag"===e.kind||WM("VISIBILITY","appearance.visibility",`${String(t.visibility)} is not a flag value in the graph`)}if(l.has(t.target)&&!h.has(t.target)||WM("APPEARANCE_TARGET",String(t.target),"unknown or duplicate source placement"),qM(t.material,["token"],["preset","transparent","emissive"],"material"),a(t.material.token),void 0===t.material.preset||["default","metal","glass","plastic","wood","ceramic","rubber"].includes(t.material.preset)||WM("MATERIAL","preset","unknown preset"),void 0!==t.material.transparent&&"boolean"!=typeof t.material.transparent&&WM("MATERIAL","transparent","boolean required"),void 0!==t.material.emissive){const e=t.material.emissive;qM(e,["token","intensity","on"],[],"emissive"),a(e.token),("boolean"!=typeof e.on||!Number.isFinite(e.intensity)||e.intensity<0||e.intensity>5)&&WM("MATERIAL","emissive","invalid intensity or switch")}const e=c.get(l.get(t.target).args[0]);"revolve@1"===e?.op||"extrude@1"===e?.op&&"ellipse"===e.params?.section?[8,12,16,24,32,48].includes(t.segments)||WM("QUALITY","segments","explicit supported cylinder segment count required"):void 0!==t.segments&&WM("QUALITY","segments","segments unsupported on this provider"),h.set(t.target,t)}h.size!==l.size&&WM("APPEARANCE_MISSING","appearance","every source placement/member requires appearance");if(void 0!==n.occupancy){if(qM(n.occupancy,["bounds"],["contact"],"occupancy"),void 0!==n.occupancy.contact){const t=n.occupancy.contact;qM(t,["plane","surface"],[],"occupancy.contact"),"mounting-plane"!==t.plane&&WM("OCCUPANCY","occupancy.contact",`${String(t.plane)} is not a plane the figure can be mounted on`),kM({types:i.outputTypes,writers:c,model:s,assetFrame:n.document.capabilities.assetFrame},t.surface,"occupancy.contact.surface")}qM(n.occupancy.bounds,["x","y","z"],[],"occupancy.bounds");const t=JSON.stringify([1,0,0]);for(const e of["x","y","z"]){qM(n.occupancy.bounds[e],["min","max"],[],`occupancy.bounds.${e}`);for(const s of["min","max"]){const r=`occupancy.bounds.${e}.${s}`,o=n.occupancy.bounds[e][s];"string"==typeof o&&JSON.stringify(i.outputTypes[o])===t||WM("OCCUPANCY",r,`${String(o)} is not a length value in the graph`),i.dependence[o]?.length&&WM("OCCUPANCY_STATE",r,`${o} depends on state input ${i.dependence[o].join(", ")}; the occupancy is state-independent`)}}}function d(t={}){qM(t,[],o,"state overrides");const e={...n.designInputs,...n.stateDefaults,...t},s=i.evaluate(e),r=t=>t.key?c.get(t.key)?.id:t.id,a=new Map(n.appearance.map((t,e)=>[t.target,e])),l=s.geometry.map((t,e)=>({g:t,i:e,at:a.get(r(t))??Number.MAX_SAFE_INTEGER})).sort((t,e)=>t.at-e.at||t.i-e.i).map(t=>t.g).map(t=>{const e=r(t),n=h.get(e);return n||WM("APPEARANCE_MISSING",t.id,"no source appearance"),{...t,material:structuredClone(n.material),visible:void 0===n.visibility||s.values[n.visibility],...void 0!==n.segments?{segments:n.segments}:{}}});return{...s,geometry:l,inputs:e,palette:structuredClone(n.palette)}}return function(t){const e=t.drivers;if(void 0===e)return;Array.isArray(e)||VM("DRIVER","drivers","array required");const n=GM(t),i=new Set,s=new Set,r=new Map;for(const t of e){const e=`drivers.${String(t?.id??"?")}`,o=t=>t&&"object"==typeof t?Object.keys(t).sort():null;JSON.stringify(o(t))!==JSON.stringify(["accumulates","clip","id","interpolation","keys","loop","state","time"])&&VM("DRIVER",e,"exactly id, clip, state, time, keys, interpolation, loop, accumulates required"),"string"==typeof t.id&&t.id.trim()||VM("DRIVER",e,"id required"),i.has(t.id)&&VM("DRIVER",e,"duplicate driver id"),i.add(t.id),"string"==typeof t.clip&&t.clip.trim()||VM("DRIVER",e,"clip required; the playback group is declared, not read out of the id"),n.has(t.state)||VM("DRIVER_STATE",e,`${String(t.state)} is not a state input of this asset`),s.has(t.state)&&VM("DRIVER_STATE",e,`two drivers write ${t.state}; one writer per state`),s.add(t.state),JSON.stringify(o(t.time))===JSON.stringify(["duration","unit"])&&"s"===t.time.unit||VM("DRIVER_TIME",e,'time must be { unit: "s", duration }'),Number.isFinite(t.time.duration)&&t.time.duration>0||VM("DRIVER_TIME",e,"positive duration in seconds required");const a=r.get(t.clip);void 0===a?r.set(t.clip,t.time.duration):a!==t.time.duration&&VM("DRIVER_TIME",e,`clip "${t.clip}" already runs for ${a} s; one clip is one clock, so every driver in it shares a duration`),(!Array.isArray(t.keys)||t.keys.length<2)&&VM("DRIVER_KEYS",e,"at least two keys required");let c=-1/0;for(const n of t.keys)JSON.stringify(o(n))!==JSON.stringify(["at","value"])&&VM("DRIVER_KEYS",e,"a key is { at, value }"),Number.isFinite(n.at)&&n.at>=0&&n.at<=1||VM("DRIVER_KEYS",e,"key at must be a fraction of the duration in [0, 1]"),n.at>c||VM("DRIVER_KEYS",e,"key at values must strictly increase"),c=n.at,Number.isFinite(n.value)||VM("DRIVER_KEYS",e,"finite key value required");0!==t.keys[0].at&&VM("DRIVER_KEYS",e,"the first key is at 0"),["linear","step"].includes(t.interpolation)||VM("DRIVER",e,"interpolation is linear or step"),["wrap","hold"].includes(t.loop)||VM("DRIVER",e,"loop is wrap or hold"),"boolean"!=typeof t.accumulates&&VM("DRIVER",e,"accumulates must be a boolean");const l=n.get(t.state);t.accumulates&&"deg"!==l&&"rad"!==l&&VM("DRIVER_STATE",e,`an accumulating driver writes an angle; ${t.state} is in ${l}`)}}(n),function(t){const e=t.stateInputs;if(void 0===e)return;e&&"object"==typeof e&&!Array.isArray(e)||VM("STATE_INPUT","stateInputs","object required");const n=GM(t);for(const[t,i]of Object.entries(e)){const e=`stateInputs.${t}`;n.has(t)||VM("STATE_INPUT",e,`${t} is not a state input of this asset`),i&&"object"==typeof i&&!Array.isArray(i)||VM("STATE_INPUT",e,"object required");for(const t of Object.keys(i))"label"!==t&&"sweep"!==t&&VM("STATE_INPUT",e,`unknown ${t}`);void 0===i.label||"string"==typeof i.label&&i.label.trim()||VM("STATE_INPUT",e,"label must be a nonempty string"),void 0===i.sweep||Number.isFinite(i.sweep)&&i.sweep>=0||VM("STATE_INPUT",e,"sweep must be a number of seconds, zero or more")}}(n),d(),{evaluate:d}}(t)}function KM(t){const e=t,n=e?.occupancy&&"object"==typeof e.occupancy?e.occupancy.placement:void 0;if(void 0===n)return t;void 0!==e.placement&&e.placement!==n&&WM("PLACEMENT_CONFLICT","placement",`the asset says ${String(e.placement)} and its room says ${String(n)}; keep one`);const{placement:i,...s}=e.occupancy;return{...e,placement:n,occupancy:s}}const QM="0.3.2";function ZM(t){const e=t.material,n=e.emissive?.on?`on:${e.emissive.token}:${e.emissive.intensity}`:"off";return`${e.token}|${e.preset??"default"}|${e.transparent?"t":"o"}|${n}`}const JM=t=>JSON.stringify([t.shape.provider,t.shape.dimensions,t.shape.extrusion?[t.shape.extrusion.axis,t.shape.extrusion.section.kind,t.shape.cavity??null]:t.shape.revolution?[t.shape.revolution.axis,t.shape.revolution.profile.kind]:t.shape.loft?[t.shape.loft.axis,"loft"]:null,t.segments??null,ZM(t),!1!==t.visible]);function tS(t,e){const n=function(t,e){const n=e??YM(t.document).dependence,i=new Map(t.document.model.nodes.map(t=>[t.id,t])),s=TM(t),r=t=>{const e=void 0===t?void 0:i.get(t);return!e||Object.values(e.outputs).some(t=>(n[t]?.length??0)>0)};return t=>{const{key:e,path:n}=t;return!!r("string"==typeof n?.[0]?n[0]:t.id)||!!e&&r(s.get(e))}}(t,e),i=TM(t),s=new Set(t.appearance.filter(t=>void 0!==t.visibility).map(t=>t.target));return t=>{const e=new Set;for(const r of t){if(!("pose"in r)||n(r))continue;const t=r.key?i.get(r.key):r.id;void 0!==t&&s.has(t)||e.add(r.id)}return e}}const eS=t=>`${ZM(t)}|${!1!==t.visible?"shown":"hidden"}`;function nS(t,e,n,i={}){const[s,r]=ew[e],o=i[s]??0,a=i[r]??0;let c;if("polygon"===t.kind)c=t.points.map(t=>[t[s],t[r]]);else if("ellipse"===t.kind){const e=t.radius[s],i=t.radius[r];c=Array.from({length:n},(t,s)=>{const r=2*Math.PI*s/n;return[e*Math.cos(r),i*Math.sin(r)]})}else{const e=t.size[s]/2,n=t.size[r]/2,i=t.corner?.[s]??0,o=t.corner?.[r]??0;if(i>0&&o>0){c=[];for(const[t,s,r]of[[1,-1,-Math.PI/2],[1,1,0],[-1,1,Math.PI/2],[-1,-1,Math.PI]])for(let a=0;a<=8;a++){const l=r+a/8*(Math.PI/2);c.push([t*(e-i)+i*Math.cos(l),s*(n-o)+o*Math.sin(l)])}}else c=[[-e,-n],[e,-n],[e,n],[-e,n]]}return c=c.map(([t,e])=>[t+o,e+a]),iS(c)<0?c.reverse():c}const iS=t=>t.reduce((e,n,i)=>e+n[0]*t[(i+1)%t.length][1]-t[(i+1)%t.length][0]*n[1],0)/2;function sS(t){const e=[...t].sort((t,e)=>t[0]-e[0]||t[1]-e[1]).map(([t,e])=>[t,e]);if(e.length<3)return e;const n=(t,e,n)=>(e[0]-t[0])*(n[1]-t[1])-(e[1]-t[1])*(n[0]-t[0]),i=[];for(const t of e){for(;i.length>=2&&n(i[i.length-2],i[i.length-1],t)<=1e-9;)i.pop();i.push(t)}const s=[];for(let t=e.length-1;t>=0;t--){const i=e[t];for(;s.length>=2&&n(s[s.length-2],s[s.length-1],i)<=1e-9;)s.pop();s.push(i)}return i.slice(0,-1).concat(s.slice(0,-1))}const rS=t=>"shape"in t&&"pose"in t&&!!t.shape;function oS(t,e){const n=[];for(const i of t){if(!1===i.visible||!rS(i))continue;let t;try{t=CM(EM(i.shape,i.segments),i.pose.r,i.pose.t)}catch{continue}if(t.length<3)continue;const s=t=>t.map(t=>[t[0],t[2]]),r=Math.abs(i.pose.r[1][1]-1)<1e-6,o=i.shape.extrusion;let a;const c=[];if(r&&"y"===o?.axis){const t=(t,e)=>s(CM(aS(t,o.end,i.segments??12,e),i.pose.r,i.pose.t));a=t(o.section);const e=i.shape.cavity;if(e&&"open"===e.end){const n=pw(o.section,"y",e.wall);"section"in n&&c.push(t(n.section,n.centre))}}else a=sS(s(t));const l=i.material,h=l.emissive?.on?l.emissive.token:l.token;n.push({id:i.id,color:e[h]??"#9a9a9a",outline:a,holes:c,top:Math.max(...t.map(t=>t[1])),transparent:!!l.transparent})}return n.sort((t,e)=>t.top-e.top)}function aS(t,e,n,i={}){const[s,r]=ew.y;return nS(t,"y",n,i).map(([t,n])=>{const i={x:0,y:e,z:0};return i[s]=t,i[r]=n,[i.x,i.y,i.z]})}let cS=null;function lS(t){cS=t}function hS(t,e=[],n){cS?.registerType?.(t,e,n)}function dS(t){if(Array.isArray(t))return`[${t.map(dS).join(",")}]`;if(t&&"object"==typeof t){const e=t;return`{${Object.keys(e).sort().map(t=>`${JSON.stringify(t)}:${dS(e[t])}`).join(",")}}`}return JSON.stringify(t)}const uS=new Map;function pS(t){const e=function(t){const e=dS(t),n=t=>{let n=t>>>0;for(let t=0;t<e.length;t++)n^=e.charCodeAt(t),n=Math.imul(n,16777619)>>>0;return n.toString(16).padStart(8,"0")};return n(2166136261)+n(2538058380)}(t),n=`${e}|${QM}`,i=uS.get(n);if(i)return uS.delete(n),uS.set(n,i),i;const s=KM(structuredClone(t)),r=new Map;for(const t of s.document.model.nodes)for(const e of Object.values(t.outputs))r.set(e,t.id);const o={key:n,fingerprint:e,kernel:QM,compiled:XM(s),document:YM(s.document),looks:new Map(s.appearance.map(t=>[t.target,t])),writers:r,asset:s};return uS.set(n,o),uS.size>256&&uS.delete(uS.keys().next().value),o}const fS=new Map;function mS(t,e){XM(e);const n={type:t,compiled:pS(e)};return fS.set(t,n),hS(t,e.document.capabilities.names??[],KM(e).placement),n}function gS(t){return fS.get(t)??null}function yS(t){return fS.has(t)}function bS(t){return fS.delete(t)}function _S(){fS.clear()}const vS=Math.cos(40*Math.PI/180);function xS(e){const[n,i]=ew[e];return([s,r],o)=>{const a={x:0,y:0,z:0};return a[n]=s,a[i]=r,a[e]=o,new t.Vector3(a.x,a.y,a.z)}}class wS{constructor(){this.positions=[],this.normals=[]}tri(t,e,n,i,s,r){for(const[o,a]of[[t,i],[e,s],[n,r]])this.positions.push(o.x,o.y,o.z),this.normals.push(a.x,a.y,a.z)}facing(e,n,i,s){(new t.Vector3).subVectors(n,e).cross((new t.Vector3).subVectors(i,e)).dot(s)<0?this.tri(e,i,n,s,s,s):this.tri(e,n,i,s,s,s)}geometry(){const e=new t.BufferGeometry;return e.setAttribute("position",new t.Float32BufferAttribute(this.positions,3)),e.setAttribute("normal",new t.Float32BufferAttribute(this.normals,3)),e}}function MS(e,n,i,s,r,o){const a=xS(i),c=n.length,l=n.map((t,e)=>{const i=n[(e+1)%c],s=i[0]-t[0],r=i[1]-t[1],a=Math.hypot(s,r)||1;return[o*r/a,-o*s/a]}),h=t=>a(t,0),d=(t,e)=>{const n=l[t],i=l[e];return n[0]*i[0]+n[1]*i[1]<vS?h(n):h([n[0]+i[0],n[1]+i[1]]).normalize()};for(let i=0;i<c;i++){const o=n[i],u=n[(i+1)%c],p=d(i,(i-1+c)%c),f=d(i,(i+1)%c),m=a(o,s),g=a(u,s),y=a(u,r),b=a(o,r),_=h(l[i]);(new t.Vector3).subVectors(g,m).cross((new t.Vector3).subVectors(y,m)).dot(_)>=0?(e.tri(m,g,y,p,f,f),e.tri(m,y,b,p,f,p)):(e.tri(m,y,g,p,f,f),e.tri(m,b,y,p,p,f))}}function SS(e,n,i,s,r,o){const a=xS(i),c=a([0,0],r),l=n.map(([e,n])=>new t.Vector2(e,n)),h=o?[o.map(([e,n])=>new t.Vector2(e,n))]:[],d=t.ShapeUtils.triangulateShape(l,h),u=[...n,...o??[]];for(const[t,n,i]of d)e.facing(a(u[t],s),a(u[n],s),a(u[i],s),c)}const kS=new Map;function AS(t,e=12){const n=Object.keys(t.dimensions).sort().map(e=>`${e}=${Math.round(1e6*t.dimensions[e])/1e6}`).join(","),i=t.extrusion,s=t.cavity,r=t.revolution,o=t.loft,a=i?`${i.axis}:${i.section.kind}:${s?`${"open"===s.start?"o":"c"}${"open"===s.end?"o":"c"}`:"-"}`:r?`${r.axis}:${r.profile.kind}`:o?`${o.axis}:point`:"";return`${t.provider}|${a}|${n}|s${e}`}function ES(t,e=12){const n=AS(t,e),i=kS.get(n);if(i)return i.users++,i.geometry;const s=TS(t,e);return s.userData.figureKey=n,kS.set(n,{geometry:s,users:1}),s}function CS(t){const e=t.userData.figureKey;if(!e)return;const n=kS.get(e);n&&--n.users<=0&&(kS.delete(e),n.geometry.dispose())}function TS(e,n=12){if("extrude"===e.provider&&e.extrusion)return function(t,e){const n=t.extrusion,i=nS(n.section,n.axis,e),s=new wS;MS(s,i,n.axis,n.start,n.end,1);const r=t.cavity,o=r&&pw(n.section,n.axis,r.wall);if(!r||!o||!("section"in o))return SS(s,i,n.axis,n.start,-1),SS(s,i,n.axis,n.end,1),s.geometry();const a=nS(o.section,n.axis,e,o.centre),c=n.start+("open"===r.start?0:r.start.closed),l=n.end-("open"===r.end?0:r.end.closed);return MS(s,a,n.axis,c,l,-1),"open"===r.start?SS(s,i,n.axis,n.start,-1,a):(SS(s,i,n.axis,n.start,-1),SS(s,a,n.axis,c,1)),"open"===r.end?SS(s,i,n.axis,n.end,1,a):(SS(s,i,n.axis,n.end,1),SS(s,a,n.axis,l,-1)),s.geometry()}(e,n);if("revolve"===e.provider&&e.revolution)return function(e,n){const i=e.profile;let s;return"half-ellipse"===i.kind?s=new t.SphereGeometry(1,n,Math.max(2,Math.round(n/2))).scale(i.radial,i.axial,i.radial):(s=new t.CylinderGeometry(i.endRadius,i.startRadius,i.end-i.start,n),s.translate(0,(i.start+i.end)/2,0)),"x"===e.axis&&s.rotateZ(-Math.PI/2),"z"===e.axis&&s.rotateX(Math.PI/2),s}(e.revolution,n);const i=e.loft;return"loft"===e.provider&&i?function(e){const[n,i]=ew[e.axis],s=xS(e.axis),r=nS(e.section,e.axis,0),o=s([e.apex[n],e.apex[i]],e.end),a=new wS;SS(a,r,e.axis,e.start,e.end>e.start?-1:1);const c=r.length;for(let n=0;n<c;n++){const i=s(r[n],e.start),l=s(r[(n+1)%c],e.start),h=(new t.Vector3).subVectors(l,i).cross((new t.Vector3).subVectors(o,i)).normalize();a.tri(i,l,o,h,h,h)}return a.geometry()}(i):new t.BufferGeometry}const PS=new Map;let OS=0;function DS(e){const n=(t=>t.map(t=>AS(t.shape,t.segments)).join(";"))(e),i=function(t){const e=new Float64Array(12*t.length);return t.forEach((t,n)=>{const i=t.pose.r,s=t.pose.t;e.set([i[0][0],i[0][1],i[0][2],i[1][0],i[1][1],i[1][2],i[2][0],i[2][1],i[2][2],s[0],s[1],s[2]],12*n)}),e}(e),s=PS.get(n),r=s?.find(t=>function(t,e){if(t.length!==e.length)return!1;for(let n=0;n<t.length;n++)if(t[n]!==e[n])return!1;return!0}(t.poses,i));if(r)return r.users++,r;const o=e.map(t=>ES(t.shape,t.segments));try{const r=o.map(t=>t.getAttribute("position")?.count??0),a=r.reduce((t,e)=>t+e,0),c=6*a*4;if(OS+c>67108864)return null;const l=new Float32Array(3*a),h=new Float32Array(3*a),d=new Int32Array(e.length+1),u=new t.Matrix4,p=new t.Matrix3;let f=0;e.forEach((t,e)=>{d[e]=f/3;const{r:n,t:i}=t.pose;u.set(n[0][0],n[0][1],n[0][2],i[0],n[1][0],n[1][1],n[1][2],i[1],n[2][0],n[2][1],n[2][2],i[2],0,0,0,1),p.getNormalMatrix(u);const s=u.elements,a=p.elements,c=o[e].getAttribute("position"),m=o[e].getAttribute("normal");for(let t=0;t<r[e];t++,f++){const e=c.getX(t),n=c.getY(t),i=c.getZ(t);if(l[3*f]=s[0]*e+s[4]*n+s[8]*i+s[12],l[3*f+1]=s[1]*e+s[5]*n+s[9]*i+s[13],l[3*f+2]=s[2]*e+s[6]*n+s[10]*i+s[14],!m)continue;const r=m.getX(t),o=m.getY(t),d=m.getZ(t),u=a[0]*r+a[3]*o+a[6]*d,p=a[1]*r+a[4]*o+a[7]*d,g=a[2]*r+a[5]*o+a[8]*d,y=Math.hypot(u,p,g)||1;h[3*f]=u/y,h[3*f+1]=p/y,h[3*f+2]=g/y}}),d[e.length]=f/3;const m=new t.BufferGeometry;m.setAttribute("position",new t.BufferAttribute(l,3)),m.setAttribute("normal",new t.BufferAttribute(h,3)),m.computeBoundingSphere(),m.computeBoundingBox();const g={geometry:m,starts:d,users:1,bytes:c,poses:i};return m.userData.figureMergedKey=n,m.userData.figureMergedEntry=g,s?s.push(g):PS.set(n,[g]),OS+=c,g}finally{for(const t of o)CS(t)}}function IS(t){const e=t.userData.figureMergedKey,n=t.userData.figureMergedEntry,i=void 0===e?void 0:PS.get(e);!n||!i?.includes(n)||--n.users>0||(i.splice(i.indexOf(n),1),i.length||PS.delete(e),OS-=n.bytes,n.geometry.dispose())}class zS{static carrierJudgeOf(t){let e=zS.carrierJudges.get(t);return e||zS.carrierJudges.set(t,e=function(t,e){const n=e??YM(t.document).dependence,i=new Map(t.document.model.nodes.map(t=>[t.id,t])),s=new Map;for(const e of t.document.model.nodes)for(const t of Object.values(e.outputs))s.set(t,e);const r=new Set(t.appearance.filter(t=>void 0!==t.visibility).map(t=>t.target)),o=t=>"string"==typeof t&&(n[t]?.length??0)>0,a=new Map,c=t=>{const e=a.get(t);if(void 0!==e)return e;const n=s.get(t),i="compose@1"!==n?.op||"string"!=typeof n.args[0]||o(n.args[1])?t:c(n.args[0]);return a.set(t,i),i};return t=>{const e=new Map;for(const n of t){if(!("pose"in n)||n.key||r.has(n.id))continue;const t=i.get(n.id),s="place@1"===t?.op?t.args[1]:void 0;"string"==typeof s&&o(s)&&!o(t.args[0])&&e.set(n.id,c(s))}return e}}(t.asset,t.document.dependence)),e}static stillJudgeOf(t){let e=zS.stillJudges.get(t);return e||zS.stillJudges.set(t,e=tS(t.asset,t.document.dependence)),e}constructor(e,n={}){this.group=new t.Group,this.meshes=new Map,this.batches=new Map,this.merged=new Map,this.carried=new Map,this.places=new Map,this.size=null,this.design={},this.designRefused=[],this.external={},this.clipTimes=new Map,this.materials=new Map,this.dressed=new Map,this.drawnWith=new Map,this.lastEvaluation=null,this.slots=[],this.generation=-1,this.clamped=[],this.compiled=pS(e),this.theme=n.theme??{},this.merge=!1!==n.merge,this.group.name=`figure:${e.name}`}get asset(){return this.compiled.asset}get base(){const t=this.asset.designInputs,e=e=>"number"==typeof t[e];return e(Jx.x)&&e(Jx.y)&&e(Jx.z)?{x:t[Jx.x],y:t[Jx.y],z:t[Jx.z]}:null}setSize(t){if(this.clamped=[],!t)return void(this.size=null);const e=this.asset.document.model.inputs,n={...t};for(const i of["x","y","z"]){const s=e.find(t=>t.id===Jx[i]);if(!s)continue;const r=t[i],o=Math.min(Math.max(r,s.min??-1/0),s.max??1/0);o!==r&&this.clamped.push({axis:i,asked:r,used:o,bound:o>r?"min":"max"}),n[i]=o}this.size=n}get drawnSize(){return this.size?{...this.size}:null}setDesignInputs(t){const e=[],n=new Set((this.asset.publicInputs??[]).map(t=>t.input)),i=new Map(this.asset.document.model.inputs.map(t=>[t.id,t])),s={};for(const[r,o]of Object.entries(t??{})){const t=i.get(r);let a;n.has(r)&&t?"number"==typeof o&&Number.isFinite(o)?(o<t.min||o>t.max)&&(a=`outside ${t.min}…${t.max}`):a="not a number":a="not an input the figure lets a board set",a?(e.push({input:r,value:o,reason:a}),r in this.design&&(s[r]=this.design[r])):s[r]=o}try{this.compiled.document.evaluate({...this.evaluationInputs(),...s}),this.design=s}catch(t){for(const[n,i]of Object.entries(s))e.push({input:n,value:i,reason:t instanceof Error?t.message:String(t)})}this.designRefused=e}get designValues(){return{...this.design}}setState(t){this.external={...t}}static clipOf(t){return t.clip}get clips(){return[...new Set((this.asset.drivers??[]).map(t=>zS.clipOf(t)))]}setClipTime(t,e){this.clipTimes.set(t,e)}clipTime(t){return this.clipTimes.get(t)??0}setTime(t){for(const e of this.clips)this.clipTimes.set(e,t)}stateOverrides(){const{units:t,states:e}=this.inputsRead(),n={};for(const e of this.asset.drivers??[]){if(e.state in this.external)continue;const i=t.get(e.state);n[e.state]=UM(e,this.clipTime(zS.clipOf(e)),"deg"===i||"rad"===i?i:"other")}for(const[t,i]of Object.entries(this.external))e.has(t)&&(n[t]=i);return n}inputsRead(){const t=this.asset.document.model.inputs;return this.inputFacts??={units:new Map(t.map(t=>[t.id,t.unit])),states:new Set(t.filter(t=>"state"===t.role).map(t=>t.id))}}get externalState(){return{...this.external}}update(){const t=this.evaluationInputs();this.evaluator??=this.compiled.document.evaluator();const e=this.evaluator.advance(t),n=this.carried.size>0&&this.carriedAt!==this.designKey();if("poses"===e.kind&&e.generation===this.generation&&!n&&!this.movesMerged(e.bodies))return this.movePoses(e);const i="evaluation"===e.kind?e.result:this.evaluator.evaluate(t);this.draw(this.dress(i,t),e.generation)}evaluation(){return this.evaluate()}movesMerged(t){if(!this.merged.size)return!1;for(let e=0;e<t.length;e++){const n=this.slots[t[e]];if(n&&"merged"in n)return!0}return!1}movePoses(t){const e=zS.matrix,n=new Set;for(let i=0;i<t.bodies.length;i++){const s=this.slots[t.bodies[i]];if(!s)continue;const r=t.poses,o=12*i;if(e.set(r[o],r[o+1],r[o+2],r[o+9],r[o+3],r[o+4],r[o+5],r[o+10],r[o+6],r[o+7],r[o+8],r[o+11],0,0,0,1),!("merged"in s)&&!("rides"in s))if("mesh"in s){s.mesh.matrix.copy(e),s.mesh.matrixWorldNeedsUpdate=!0;const t=this.drawnWith.get(s.id);t&&(t.pose=void 0)}else s.entry.set.setMatrix(s.index,e),n.add(s.entry)}for(const t of this.batches.values())n.has(t)?(t.settled=!1,t.set.commitMatrices(),t.set.mesh.boundingSphere=null,t.set.mesh.frustumCulled=!1):t.settled||(t.set.commit(),t.set.mesh.frustumCulled=!0,t.settled=!0);for(const e of t.places){const t=this.places.get(e.id);t&&zS.pose(t,e.pose)}}draw(e,n){this.lastEvaluation=e;const i=this.planOf(e.geometry),s=new Map(e.geometry.filter(t=>"pose"in t).map(t=>[t.id,t])),r=this.drawCarried(i,s,this.drawMerged(i,s)),o=new Set;for(const e of r){const n=s.get(e);if(!("pose"in n))continue;o.add(e);let i=this.meshes.get(e);const r=!1!==n.visible,a=this.drawnWith.get(e);if(!i||!a||a.shape!==n.shape||a.segments!==n.segments){const s=ES(n.shape,n.segments);i?i.geometry!==s?(CS(i.geometry),i.geometry=s):CS(s):(i=new t.Mesh(s,this.materialFor(n)),i.name=e,i.matrixAutoUpdate=!1,this.meshes.set(e,i),r&&this.group.add(i))}a&&a.pose===n.pose||zS.pose(i,n.pose),this.drawnWith.set(e,{shape:n.shape,segments:n.segments,pose:n.pose}),i.castShadow=r,r&&i.parent!==this.group?this.group.add(i):r||i.parent!==this.group||this.group.remove(i)}for(const[t,e]of this.meshes)o.has(t)||(e.parent===this.group&&this.group.remove(e),CS(e.geometry),this.meshes.delete(t),this.drawnWith.delete(t));const a=new Set;for(const t of i.batches){a.add(t.key);const e=s.get(t.ids[0]);if(!("pose"in e))continue;let n=this.batches.get(t.key);if(!n){const i=ES(e.shape,e.segments);n={set:new Fx({geometry:i,material:this.materialFor(e),capacity:t.ids.length,name:`figure-batch:${t.member}`,castShadow:!0}),ids:[],geometry:i},this.batches.set(t.key,n)}const{set:i}=n,r=i.count!==t.ids.length;i.setCount(t.ids.length);const o=i.mesh.instanceMatrix.array;let c=!1;t.ids.forEach((t,e)=>{const n=s.get(t);if(!("pose"in n))return;zS.matrixOf(n.pose);const r=zS.matrix.elements;for(let t=0;t<16&&!c;t++)o[16*e+t]!==Math.fround(r[t])&&(c=!0);i.setMatrix(e,zS.matrix)}),n.ids=t.ids,r||!c&&!n.settled?(i.commit(),i.mesh.frustumCulled=!0,n.settled=!0):c&&(n.settled=!1,i.commitMatrices(),i.mesh.boundingSphere=null,i.mesh.frustumCulled=!1);const l=!1!==e.visible;l&&i.object3d.parent!==this.group?this.group.add(i.object3d):l||i.object3d.parent!==this.group||this.group.remove(i.object3d)}for(const[t,e]of this.batches)a.has(t)||(e.set.object3d.parent===this.group&&this.group.remove(e.set.object3d),e.set.dispose(),CS(e.geometry),this.batches.delete(t));for(const t of e.bindings){const e=this.places.get(t.id);e&&zS.pose(e,t.pose)}const c=new Map;for(const t of this.batches.values())t.ids.forEach((e,n)=>c.set(e,{entry:t,index:n}));for(const t of this.merged.values())for(const e of t.ids)c.set(e,{merged:t});const l=new Map;for(const t of this.carried.values())t.ids.forEach((e,n)=>0===n?l.set(e,t.mesh):c.set(e,{rides:t}));this.slots=e.geometry.map(t=>{const e=this.meshes.get(t.id)??l.get(t.id);return e?{mesh:e,id:t.id}:c.get(t.id)??null}),this.generation=n}drawMerged(e,n){const i=[...e.alone],s=new Set;for(const r of e.merged){const e=r.ids.map(t=>n.get(t));let o=this.merged.get(r.key);if(!(o&&o.ids.length===e.length&&e.every((t,e)=>t.id===o.ids[e]&&t.shape===o.made[e].shape&&t.segments===o.made[e].segments&&t.pose===o.made[e].pose))){const n=DS(e.map(t=>({shape:t.shape,segments:t.segments,pose:t.pose})));if(!n){i.push(...r.ids);continue}if(o)IS(o.mesh.geometry),o.mesh.geometry=n.geometry,o.ids=r.ids,o.starts=n.starts;else{const i=new t.Mesh(n.geometry,this.materialFor(e[0]));i.name=`figure-merged:${this.merged.size}`,i.matrixAutoUpdate=!1,i.castShadow=!0,o={mesh:i,ids:r.ids,starts:n.starts,made:[]},this.merged.set(r.key,o)}o.made=e.map(t=>({shape:t.shape,segments:t.segments,pose:t.pose}))}s.add(r.key);const a=!1!==e[0].visible;a&&o.mesh.parent!==this.group?this.group.add(o.mesh):a||o.mesh.parent!==this.group||this.group.remove(o.mesh)}for(const[t,e]of this.merged)s.has(t)||(e.mesh.parent===this.group&&this.group.remove(e.mesh),IS(e.mesh.geometry),this.merged.delete(t));return i}drawCarried(e,n,i){const s=new Set,r=new t.Matrix4,o=new t.Matrix4;for(const a of e.carried){const e=a.ids.map(t=>n.get(t));r.copy(zS.matrixOf(e[0].pose)).invert();const c=e.map(t=>{const e=o.multiplyMatrices(r,zS.matrixOf(t.pose)).elements,n=t=>{return n=e[t],1e-9*Math.round(n/1e-9)+0;var n};return{r:[[n(0),n(4),n(8)],[n(1),n(5),n(9)],[n(2),n(6),n(10)]],t:[n(12),n(13),n(14)]}}),l=new Float64Array(c.flatMap(t=>[...t.r.flat(),...t.t]));let h=this.carried.get(a.key);if(!(h&&h.ids.length===e.length&&e.every((t,e)=>t.id===h.ids[e]&&t.shape===h.made[e].shape&&t.segments===h.made[e].segments)&&l.every((t,e)=>t===h.relative[e]))){const n=DS(e.map((t,e)=>({shape:t.shape,segments:t.segments,pose:c[e]})));if(!n){i.push(...a.ids);continue}if(h)IS(h.mesh.geometry),h.mesh.geometry=n.geometry,h.ids=a.ids,h.starts=n.starts;else{const i=new t.Mesh(n.geometry,this.materialFor(e[0]));i.name=`figure-carried:${this.carried.size}`,i.matrixAutoUpdate=!1,i.castShadow=!0,h={mesh:i,ids:a.ids,starts:n.starts,made:[],relative:l},this.carried.set(a.key,h)}h.made=e.map(t=>({shape:t.shape,segments:t.segments})),h.relative=l}zS.pose(h.mesh,e[0].pose),s.add(a.key);const d=!1!==e[0].visible;d&&h.mesh.parent!==this.group?this.group.add(h.mesh):d||h.mesh.parent!==this.group||this.group.remove(h.mesh)}for(const[t,e]of this.carried)s.has(t)||(e.mesh.parent===this.group&&this.group.remove(e.mesh),IS(e.mesh.geometry),this.carried.delete(t));return this.carriedAt=this.designKey(),i}designKey(){const t=this.size;let e=t?`${t.x},${t.y},${t.z}`:"-";for(const t in this.design)e+=`|${t}=${this.design[t]}`;return e}placeNode(e){let n=this.places.get(e);if(n)return n;if(!this.asset.document.capabilities.bindings.some(t=>t.id===e))return null;n=new t.Object3D,n.name=`place:${e}`,n.matrixAutoUpdate=!1,this.places.set(e,n),this.group.add(n);const i=this.evaluation().bindings.find(t=>t.id===e);return i&&zS.pose(n,i.pose),n}static pose(t,e){t.matrix.copy(zS.matrixOf(e)),t.matrixWorldNeedsUpdate=!0}planOf(t){const e=this.planned,n=t.filter(t=>"pose"in t);if(e&&e.ids.length===n.length&&n.every((t,n)=>t.id===e.ids[n]&&t.shape===e.shapes[n]&&!1!==t.visible===e.shown[n]))return e.plan;const i=n.map(t=>t.id);!this.merge||e?.still&&e.ids.length===i.length&&i.every((t,n)=>t===e.ids[n])||(this.stillOf=zS.stillJudgeOf(this.compiled)(t),this.carriedOf=zS.carrierJudgeOf(this.compiled)(t));const s=this.merge?this.stillOf:void 0,r=function(t,e={}){const n=[],i=new Map;for(const e of t){if(!("pose"in e))continue;const t="key"in e&&"string"==typeof e.key?e.key:void 0;if(!t){n.push(e.id);continue}const s=i.get(t)??[];s.push(e),i.set(t,s)}const s=[],r=[];for(const[t,e]of i){const i=new Map;for(const t of e){const e=JM(t),n=i.get(e);n?n.push(t.id):i.set(e,[t.id])}for(const[o,a]of i)a.length>1?s.push({key:`${t}|${o}`,member:t,ids:a}):(n.push(...a),r.push({member:t,ids:a,reason:1===e.length?"one-copy":"copies-differ"}))}const o=[];if(e.still?.size){const i=new Map(t.map(t=>[t.id,t])),s=new Map;for(const t of n){const n=i.get(t);if(!n||!e.still.has(t)||n.material.transparent)continue;const r=eS(n),o=s.get(r);o?o.push(t):s.set(r,[t])}const r=new Set;for(const[t,e]of s)e.length<2||(o.push({key:t,ids:e}),e.forEach(t=>r.add(t)));r.size&&n.splice(0,n.length,...n.filter(t=>!r.has(t)))}const a=[];if(e.carried?.size){const i=new Map(t.map(t=>[t.id,t])),s=new Map;for(const t of n){const n=i.get(t),r=e.carried.get(t);if(!n||void 0===r||e.still?.has(t)||n.material.transparent)continue;const o=`${r}|${eS(n)}`,a=s.get(o);a?a.ids.push(t):s.set(o,{carrier:r,ids:[t]})}const r=new Set;for(const[t,{carrier:e,ids:n}]of s)n.length<2||(a.push({key:t,carrier:e,ids:n}),n.forEach(t=>r.add(t)));r.size&&n.splice(0,n.length,...n.filter(t=>!r.has(t)))}return{batches:s,merged:o,carried:a,alone:n,unbatched:r}}(t,s?{still:s,carried:this.carriedOf}:{});return this.planned={ids:i,shapes:n.map(t=>t.shape),shown:n.map(t=>!1!==t.visible),plan:r,still:s},r}static matrixOf(t){const e=t.r,n=t.t;return zS.matrix.set(e[0][0],e[0][1],e[0][2],n[0],e[1][0],e[1][1],e[1][2],n[1],e[2][0],e[2][1],e[2][2],n[2],0,0,0,1)}bodyAt(t,e,n){if(t.isMesh&&this.meshes.get(t.name)===t)return t.name;for(const n of this.batches.values())if(n.set.mesh===t&&void 0!==e){const t=n.set.indexOf(e);return t>=0?n.ids[t]:void 0}for(const e of[...this.merged.values(),...this.carried.values()]){if(e.mesh!==t||void 0===n)continue;const{starts:i}=e;if(n<0||n>=i[i.length-1])return;let s=0,r=e.ids.length-1;for(;s<r;){const t=s+r+1>>1;i[t]<=n?s=t:r=t-1}return e.ids[s]}}drawOf(t){const e=this.meshes.get(t);if(e)return e.parent===this.group?{kind:"alone",object:e}:void 0;for(const e of this.batches.values()){const n=e.ids.indexOf(t);if(n>=0)return e.set.object3d.parent===this.group?{kind:"copy",object:e.set.mesh,index:n}:void 0}for(const e of this.merged.values()){const n=e.ids.indexOf(t);if(n>=0)return e.mesh.parent===this.group?{kind:"merged",object:e.mesh,triangles:{start:e.starts[n],count:e.starts[n+1]-e.starts[n]}}:void 0}for(const e of this.carried.values()){const n=e.ids.indexOf(t);if(n>=0)return e.mesh.parent===this.group?{kind:"carried",object:e.mesh,triangles:{start:e.starts[n],count:e.starts[n+1]-e.starts[n]}}:void 0}}get draws(){let t=0;for(const e of this.batches.values())e.set.object3d.parent===this.group&&(t+=e.set.count);return{batches:[...this.batches.values()].filter(t=>t.set.object3d.parent===this.group).length,merged:[...this.merged.values()].filter(t=>t.mesh.parent===this.group).length,carried:[...this.carried.values()].filter(t=>t.mesh.parent===this.group).length,alone:[...this.meshes.values()].filter(t=>t.parent===this.group).length,instances:t}}evaluationInputs(){const t={...this.asset.designInputs,...this.design,...this.asset.stateDefaults,...this.stateOverrides()};return this.size&&(t[Jx.x]=this.size.x,t[Jx.y]=this.size.y,t[Jx.z]=this.size.z),t}evaluate(){const t=this.evaluationInputs();return this.evaluator??=this.compiled.document.evaluator(),this.dress(this.evaluator.evaluate(t),t)}dress(t,e){const n=this.dressed,i=new Map,s=t.geometry.map(e=>{const s="key"in e&&e.key?this.compiled.writers.get(e.key):e.id,r=this.compiled.looks.get(s);if(!r)throw new Error(`figure: no appearance for ${s}`);const o=void 0===r.visibility||!0===t.values[r.visibility],a=n.get(e.id);if(a&&a.body===e&&a.visible===o)return i.set(e.id,a),a.dressed;let c=this.materials.get(s);c||this.materials.set(s,c=structuredClone(r.material));const l={...e,material:c,visible:o};return void 0!==r.segments&&(l.segments=r.segments),i.set(e.id,{body:e,visible:o,dressed:l}),l});return this.dressed=i,{geometry:s,bindings:t.bindings,inputs:e,palette:{...this.asset.palette}}}colourOf(t){return this.theme[t]??this.asset.palette[t]??"#9a9a9a"}materialFor(t){const e=t.material,n=Td[e.preset??"default"]??Td.default,i=!!e.emissive?.on,s=i&&e.emissive?this.colourOf(e.emissive.token):this.colourOf(e.token),r=i&&e.emissive?e.emissive.intensity:0,o=`figure|${this.compiled.fingerprint}|${e.token}|${e.preset??"default"}|${e.transparent?"t":"o"}|${i?"on":"off"}|${s}|${r}`;return av.material(o,{color:s,metalness:n.metalness,roughness:n.roughness,envMapIntensity:n.envMapIntensity,flatShading:!0,transparent:e.transparent??!1,opacity:e.transparent?n.opacity??.3:1,emissive:s,emissiveIntensity:r})}meshOf(t){return this.meshes.get(t)}drawnIds(){return[...[...this.meshes.values()].filter(t=>t.parent===this.group).map(t=>t.name),...[...this.batches.values()].filter(t=>t.set.object3d.parent===this.group).flatMap(t=>t.ids),...[...this.merged.values(),...this.carried.values()].filter(t=>t.mesh.parent===this.group).flatMap(t=>t.ids)]}dispose(){for(const t of this.meshes.values())t.parent===this.group&&this.group.remove(t),CS(t.geometry);this.meshes.clear(),this.drawnWith.clear(),this.dressed.clear();for(const t of this.batches.values())t.set.object3d.parent===this.group&&this.group.remove(t.set.object3d),t.set.dispose(),CS(t.geometry);this.batches.clear();for(const t of this.merged.values())t.mesh.parent===this.group&&this.group.remove(t.mesh),IS(t.mesh.geometry);this.merged.clear();for(const t of this.carried.values())t.mesh.parent===this.group&&this.group.remove(t.mesh),IS(t.mesh.geometry);this.carried.clear();for(const t of this.places.values())this.group.remove(t);this.places.clear()}}zS.matrix=new t.Matrix4,zS.carrierJudges=new WeakMap,zS.stillJudges=new WeakMap;class RS extends xu{constructor(){super(...arguments),this.rig=null}get figure(){return gS(this.component.state.type)}getObject3dInstance(){return new t.Group}build(){super.build();const t=this.figure;t&&(this.rig=new zS(t.compiled.asset),this.object3d.add(this.rig.group),this.rig.setSize(this.instanceSize()),this.seat(),this.rig.setDesignInputs(this.designInputs),this.rig.setState(this.parameters),this.rig.update(),this.startTicking())}get designInputs(){const t=this.component.state.designInputs;return t&&"object"==typeof t?t:{}}get parameters(){const t=this.component.state.parameters;return t&&"object"==typeof t?t:{}}get clipSpeeds(){const t=this.component.state.clips;return t&&"object"==typeof t?t:{}}clipTime(t){return this.rig?.clipTime(t)??0}onchange(t,e){super.onchange(t,e),"designInputs"in t&&this.updateDesignInputs(),"parameters"in t&&this.updateParameters(),"clips"in t&&this.updateClips()}instanceSize(){const t=this.rig?.base;if(!t)return null;const{width:e,height:n}=this.component.bounds;return{x:e,y:this.effectiveDepth,z:n}}get effectiveDepth(){const t=this.component.state.depth;if("number"==typeof t&&Number.isFinite(t)&&t>0)return t;const e=this.rig?.base;if(!e)return super.effectiveDepth;const{width:n,height:i}=this.component.bounds,s=e.x>0?n/e.x:1,r=e.z>0?i/e.z:1;return e.y*Math.sqrt(Math.max(s,0)*Math.max(r,0))}get effectiveZPos(){const t=this.component.state.zPos;return"number"==typeof t&&Number.isFinite(t)?t:"ceiling"!==this.figure?.compiled.asset.placement?super.effectiveZPos:function(t,e,n){switch(t){case"inverted":return e;case"space":return e-n/2;default:return e-n}}(this.placementMode,this.sceneHeights.ceiling,this.effectiveDepth)}updateDimension(){this.rig&&(this.rig.setSize(this.instanceSize()),this.seat(),this.refresh())}seat(){if(!this.rig)return;const t=this.figure?.compiled.asset.placement;if("wall"===t)return this.rig.group.position.y=0,void(this.rig.group.position.z=-this.component.bounds.height/2);this.rig.group.position.z=0;const e=this.rig.drawnSize?.y??this.effectiveDepth,n=this.effectiveDepth-e,i="ceiling"===t?n:"center"===t?n/2:0;this.rig.group.position.y=-this.effectiveDepth/2+i}get sizeClamps(){return this.rig?.clamped??[]}updateDesignInputs(){this.rig&&(this.rig.setDesignInputs(this.designInputs),this.refresh())}updateParameters(){this.rig&&(this.rig.setState(this.parameters),this.refresh())}updateClips(){this.rig&&(this.startTicking(),this.refresh())}refresh(){this.rig&&(this.rig.update(),this.component.invalidate?.())}startTicking(){const t=this.rig?.asset.drivers??[];this.unsubscribe||0===t.length||(this.unsubscribe=Rr.subscribe(t=>this.advance(t),{description:`Figure[${this.component.state.type}].drivers`,component:this.component,getTargets:()=>this.rig?[this.rig.group]:[]}))}tick(t){const e=this.rig;if(!e)return;const n=this.clipSpeeds;let i=!1;for(const s of e.clips){const r=n[s]??0;Number.isFinite(r)&&0!==r&&(e.setClipTime(s,e.clipTime(s)+t/1e3*r),i=!0)}i&&(e.update(),this.component.invalidate?.())}advance(t){this.tick(t)}placeAttachment(t,e){const n=this.rig,i=n?.placeNode(t);if(!n||!i)return;const s=IM(n.asset).find(e=>e.id===t)?.face,r=s&&SM[s]||[0,0,0],o=t=>{const n=Number(e?.state?.[t]);return Number.isFinite(n)&&n>0?n/2:0};return{attach:i,localPosition:{x:r[0]*o("width"),y:r[1]*o("depth"),z:r[2]*o("height")}}}clear(){return this.unsubscribe?.(),this.unsubscribe=void 0,this.rig?.dispose(),this.rig=null,super.clear()}}function jS(t,e){const n=new zS(t.compiled.asset);n.setSize(e);const i=n.evaluate();return{shapes:oS(i.geometry,i.palette),size:n.drawnSize}}const LS=Kx,FS=Object.freeze({Capacity:t=>Jy(t),Holdable:t=>c_(t),Transferable:t=>l_(t),FlowNode:t=>h_(t)}),NS=Object.freeze({Capacity:"자리를 갖는다 — 물건이 앉을 곳과 몇 개까지인지를 정한다",Holdable:"물건을 보유한다 — 담긴 것을 함께 들고 그린다",Transferable:"주고받는다 — 자리를 잡아 두고 넘겨받는다. Capacity 가 있어야 자리를 찾는다",FlowNode:"흐름의 마디다 — 담는 것에 더해 문(port)으로 받고 보낸다. 위의 셋을 스스로 포함한다"});function HS(t){return t.map(t=>({id:t.id,maxCount:t.capacity,allowedTypes:[...t.accepts]}))}const BS=new Map;function YS(t,e=[],n){const i=new Set(e),s=[...i].filter(t=>!LS.includes(t));if(s.length>0)throw new Error(`모르는 능력이다: ${s.join(" · ")} — 쓸 수 있는 것은 ${LS.join(" · ")}`);for(const[t,e]of Object.entries(Qx))if(i.has(t)&&!e.some(t=>i.has(t)))throw new Error(`${t} 은 혼자 설 수 없다 — ${e.join(" 이나 ")} 가 함께 있어야 한다`);const r=`${[...i].sort().join("+")}|${n??""}`,o=BS.get(r);if(o)return o;const a=0===i.size?t:(c=function(t,e){const n=t.capabilities??[],i=[...new Set([...n,...e])];return Object.defineProperty(t,"capabilities",{value:Object.freeze(i),configurable:!0}),t}(function(t,e){if(e.has("FlowNode"))return FS.FlowNode(t);let n=t;for(const t of["Capacity","Transferable","Holdable"])e.has(t)&&(n=FS[t](n));return n}(t,i),i),class extends c{get _places(){return gS(this.state?.type)?.compiled.asset.document.capabilities.bindings??null}get slots(){const t=this._places;return t?.length?HS(t):super.slots??[]}attachPointFor(t,e){const n=()=>super.attachPointFor?super.attachPointFor(t,e):null,i=e?.slotId??t?.[Wy],s=this._places;return s&&i&&s.some(t=>t.id===i)?this._realObject?.placeAttachment?.(i,t)??n():n()}});var c;const l=void 0===n?a:function(t,e){const n=class extends t{};return Object.defineProperty(n,"placement",{value:e,enumerable:!0}),Object.defineProperty(n,"name",{value:`${t.name??"Figure"}·${e}`}),n}(a,n);return BS.set(r,l),l}function VS(){BS.clear()}const GS={mutable:!1,resizable:!0,rotatable:!0,properties:[],help:"scene/component/figure"};class $S extends(Oc(Tc)){static registerType(t,e=[],n){const i=Cc.register(t);if(i&&!(i===$S||i.prototype instanceof $S))throw new Error(`figure type '${t}' is already registered by a non-figure component — refusing to replace it`);const s=YS($S,e,n);Cc.register(t,s)}get hasTextProperty(){return!1}is3dish(){return!0}get nature(){const t=gS(this.state.type),e=t?.compiled.asset.publicInputs??[];if(!e.length)return GS;const n=t.compiled.asset,i=e.flatMap(t=>{const e=n.document.model.inputs.find(e=>e.id===t.input);return e?[{key:t.input,label:t.label,unit:e.unit,min:e.min,max:e.max,default:n.designInputs[t.input]}]:[]});return{...GS,properties:[{type:"number-map",label:"design-inputs",name:"designInputs",property:{entries:i}}]}}buildRealObject(){return yS(this.state.type)?new RS(this):void 0}render(t){const{left:e=0,top:n=0,width:i=0,height:s=0}=this.state,r=gS(this.state.type);if(!r)return void this.renderPlace(t,e,n,i,s);const o=this.topView(r,i,s),a=e+i/2,c="wall"===r.compiled.asset.placement?n:n+s/2;for(const e of o.shapes)if(!(e.outline.length<3)){t.save(),t.fillStyle=e.color,e.transparent&&(t.globalAlpha=.35),t.beginPath();for(const n of[e.outline,...e.holes])if(!(n.length<3)){t.moveTo(a+n[0][0],c+n[0][1]);for(let e=1;e<n.length;e++)t.lineTo(a+n[e][0],c+n[e][1]);t.closePath()}t.fill("evenodd"),t.restore()}}topView(t,e,n){const i=t.compiled.asset.designInputs,s=["x","y","z"].every(t=>"number"==typeof i[`size.${t}`])?{x:i["size.x"],y:i["size.y"],z:i["size.z"]}:null,r=this.state.depth,o="number"==typeof r&&Number.isFinite(r)&&r>0?r:s?s.y*Math.sqrt(Math.max(s.x>0?e/s.x:1,0)*Math.max(s.z>0?n/s.z:1,0)):0,a=s?{x:e,y:o,z:n}:null,c=`${t.compiled.fingerprint}|${a?`${a.x}|${a.y}|${a.z}`:"authored"}`;return this._top?.key!==c&&(this._top={key:c,view:jS(t,a)}),this._top.view}renderPlace(t,e,n,i,s){t.save(),t.strokeStyle="#e53935",t.lineWidth=1,t.setLineDash([4,4]),t.beginPath(),t.rect(e,n,i,s),t.stroke(),t.restore()}postrender(t){Cc.prototype.postrender.call(this,t)}}lS($S);const US={"palette.primary":"#154473","palette.accent":"#f79c40","palette.neutral":"#96989b","palette.dark":"#27292c","palette.light":"#d6d7d9","palette.surface":"#56585b","palette.status-danger":"#f61b30","palette.status-warning":"#e68d1a","palette.status-info":"#158bde","palette.status-success":"#1cb648"},WS=new Map([["default",US]]);let qS="default",XS=0;function KS(){return XS}function QS(t,e){WS.set(t,e),t===qS&&XS++}function ZS(t){if(!WS.has(t))throw new Error(`등록되지 않은 팔레트다: '${t}'. 등록된 것 — ${[...WS.keys()].join(", ")}`);t!==qS&&(qS=t,XS++)}function JS(){return qS}function tk(){return WS.get(qS)}function ek(t){const e=tk()[t];if(void 0===e)throw new Error(`팔레트에 없는 토큰이다: '${t}' (팔레트 '${qS}'). 쓸 수 있는 것 — ${Object.keys(tk()).join(", ")}`);return e}const nk=US["palette.neutral"];function ik(){WS.clear(),WS.set("default",US),qS="default",XS++}const sk={mutable:!1,resizable:!0,rotatable:!0,properties:[],help:"scene/component/figure-part"},rk=["shape","segments"],ok=["color","preset","transparent","glow"];function ak(e,n){let i;try{i=TS(e,n)}catch{return null}if(!i?.getAttribute("position"))return null;const s=i.clone();i.dispose(),s.computeBoundingBox();const r=s.boundingBox,o=r.getCenter(new t.Vector3),a=r.getSize(new t.Vector3);return s.translate(-o.x,-o.y,-o.z),s.scale(1/(a.x||1),1/(a.y||1),1/(a.z||1)),s.computeBoundingBox(),s.getAttribute("normal")||s.computeVertexNormals(),{geometry:s,extent:a,centre:o}}class ck extends xu{build(){super.build();const e=this.component.state,n=e.shape?ak(e.shape,e.segments):null;if(!n)return;const i=new t.Mesh(n.geometry,this.material());i.castShadow=!0,i.receiveShadow=!0,this.object3d.add(i),this.mesh=i,this.updateDimension()}clear(){return this.mesh?.geometry.dispose(),this.mesh=void 0,super.clear()}onchange(t,e){const n=e=>e.some(e=>e in t);n(rk)?this.update():(super.onchange(t,e),n(ok)&&this.mesh&&(this.mesh.material=this.material()))}updateDimension(){const{width:t=1,height:e=1}=this.component.bounds;this.setDimensionScale(t||1,this.effectiveDepth||1,e||1)}material(){const t=this.component.state,e=Td[t.preset??"default"]??Td.default,n=t.color??"#9a9a9a",i=t.transparent??!1,s=t.glow,r=s?s.color:n,o=s?s.intensity:0;return av.material(`figure-part|${n}|${t.preset??"default"}|${i}|${s?`${s.color}:${o}`:"-"}`,{color:r,metalness:e.metalness,roughness:e.roughness,envMapIntensity:e.envMapIntensity,flatShading:!0,transparent:i,opacity:i?e.opacity??.3:1,emissive:r,emissiveIntensity:o})}}class lk extends(Oc(Tc)){static registerType(){Cc.register("figure-part",lk)}get hasTextProperty(){return!1}is3dish(){return!0}get nature(){return sk}buildRealObject(){return new ck(this)}render(t){const{left:e=0,top:n=0,width:i=0,height:s=0}=this.state;t.beginPath(),t.rect(e,n,i,s),t.fillStyle=this.state.color??"#9a9a9a",t.fill()}}var hk;lk.registerType(),function(t){t.compile=jl,t.duplicate=Ll,t.select=ec,t.match=Za}(hk||(hk={})),ji.registerResidents(()=>({componentResidentsCount:Cc.residentsCount,sceneResidentsCount:Ku.residentsCount,referenceMapResidentsCount:V_.residentsCount,sceneResidents:Cc.residents}));var dk=Object.freeze({__proto__:null,AbsoluteLayout:Nc,Animation:ka,AudioPlayer:Zg,BULGE_EPSILON:qr,get Banner(){return ex},Banner3D:tx,BoxSelectionManager:Rf,CAPABILITY_MIXINS:FS,COMMON_PLACEHOLDER_PROPERTIES:vg,CORE_PLACEHOLDER_TYPES:Sg,get Camera(){return ox},Camera3D:rx,CameraBookmarkManager:zf,CameraManager:_f,Capacity:Jy,CapacityEventTracker:Ry,CardLayout:Bc,CenteringQueueStrategy:Ly,CenteringSlotStrategy:v_,Component:Cc,Connectable:nm,Container:ng,ContainerAbstract:Jl,ControlsManager:Mf,get Cube(){return Xv},Cube3D:qv,get Cylinder(){return Zv},Cylinder3D:Qv,DEFAULT:Ks,DEFAULT_CEILING:bu,DEFAULT_PALETTE:US,DEFAULT_PLACEMENT:uu,DPPX:Ws,DataLagTracker:sh,DataSource:Ey,DefaultLoadingOverlayRenderer:Vd,Donut:yy,DonutExtrude:Ev,Ellipse:bg,EllipseExtrude:Mv,EventManager3D:Sf,EventMap:fl,FIGURE_CAPABILITIES:LS,FIGURE_CAPABILITY_NOTES:NS,FPS:Fp,FigureInstance:$S,FigurePart:lk,FigurePartRealObject:ck,FixedSlotStrategy:Ky,get FloorPlate(){return yx},FlowEngine:a_,FlowNode:h_,GESTURES:qs,get GLTFObject(){return cx},GLTF_BASE_URL_ALIAS:Ty,GenericObject:Mg,GeometryBank:Dv,GifView:Kg,GizmoManager:Af,GizmoOperationManager:Tf,GlobalRef:oy,GltfComponent:Oy,GridStacking:Hy,Group:ey,HTMLAbsoluteLayout:Fc,HTMLOverlayContainer:sy,HTMLOverlayElement:Fg,Holdable:c_,ImageView:Lg,InfoWindow:Rc,InstancedSet:Fx,InteractionManager:Pf,ItemsDataBinding:Xy,KEYEVENTS:Xs,Layer:gp,Layout:Lc,LightManager:xf,LightObject:hx,Line:gg,Line3D:zx,LinearHorizontalLayout:Vc,LinearVerticalLayout:$c,LoadTracker:ah,LoadingOverlay:Rd,LocalRef:iy,MATERIAL_PRESETS:Td,MAX_SEGMENTS:jv,MAX_UNDO_SIZE:30,MIN_SEGMENTS:3,MODE_ADD:3,MODE_EDIT:1,MODE_PASTE_DATABIND:5,MODE_PASTE_STYLE:4,MODE_SHIFT:2,MODE_VIEW:0,MaterialBank:av,get Model(){return hk},MoveHandle:Ql,NOTHING:Fs,NavGraph:A_,Node:wy,OrthoLine:Rg,OrthoLine3D:jx,PIXEL_RATIO:Np,PLACEHOLDER_THEMES:_g,Path:uy,PatternStacking:Ny,PlacementManager:Of,get PointLight(){return dx},Polygon:Cg,PolygonContainer:Pg,PolygonExtrude:Av,PolygonPathPolyline:I_,Polyline:Ig,Polyline3D:Rx,Popup:ly,PopupContainer:dy,Pose6DOF:vl,RealObject:xu,RealObjectCamera:Yx,RealObjectDomElement:Wp,RealObjectDomTexture:iv,RealObjectDummy:Hx,RealObjectExternalModel:Su,RealObjectExtrude:wv,RealObjectGLTF:Cu,RealObjectGroup:wx,RealObjectLine:Ix,RealObjectMesh:cv,RealObjectPlane:Vx,RealObjectPlane2D:Ux,RealObjectScene:Gx,RealObjectService:My,RealObjectSprite:Vv,RealObjectSprite2D:Gv,RealObjectText:mv,Rect:rm,RectExtrude:Sv,RectPath:Oc,ReferenceMap:V_,RendererManager:vf,ReservationTable:S_,RootContainer:ih,Ruler:am,SCALE_MIN:Zd,SCENE_MODE:$s,SEGMENT_DEFAULTS:zv,SEGMENT_PRESETS:Iv,SHORTCUT_SECTIONS:qf,Scene:Ku,SceneManager:bf,ScenePopup:mp,SceneSearchEngine:Iu,ScriptLoader:K_,SearchOverlay:Ru,ServiceComponent:ky,Shape:Tc,get Sphere(){return Yv},Sphere3D:Bv,get Sprite(){return Uv},Star:vy,StarExtrude:Tv,TRANSFER_SLOT_KEY:Wy,TableLayout:Uc,Text:Jg,ThreeCapability:Bf,get ThreeContainer(){return qx},ThreeDOnly:Cy,Tracker:Lu,Transfer:Uu,TransitionEffect:Kl,Triangle:fy,TriangleExtrude:Cv,UNIT_DIMENSION:nu,UNIT_ROTATE:ru,UNIT_SCALE:iu,UNIT_TRANSLATE:su,UNTOKENED_COLOR:nk,ValueHolder:Ay,VertexGizmoManager:Hf,VolumeStacking:By,get Wall(){return fx},Wall3D:px,Z_PRIORITY:fu,acquireFigureGeometry:ES,activePalette:tk,activePaletteName:JS,allDestinations:qb,anchorsConnect:rb,animate:Sa,applyAlpha:tu,applyMaterial3dProps:Id,applyPolicy:Qb,applySeatingRotation:Uy,applyStackLayout:Yy,applyZPriorityToMaterials:gu,arcSegmentTopology:ib,autoWireBackPressure:jy,buildArrow3D:$p,buildContractInspector:N_,buildCoordinateGround:sf,buildFigureGeometry:TS,buildFlowGraph:hb,buildNavGraph:T_,buildShapeFromPolygonPath:kv,buildTether:op,bulgeFromDrag:Zr,bulgeHandlePosition:Qr,canReach:mb,capability:Bm,centerOnBBox:xv,chooseNearestPickupFrame:__,clearTether:cp,collectAdjacentSegments:vb,compile:Ea,componentForNode:Wb,computeArcParams:Kr,computeFlowMap:Rb,computeStackPositions:Fy,cornerHandlePosition:to,cornerRadiusFromDrag:eo,create:Zu,createCanvas:Hp,createCanvasTexture:J_,createFloor:mf,createRealObjectFor:Zp,createSelectionHandle3D:bx,dataLagTracker:rh,debug:Ji,deliversInto:cb,delta:wa,disposeCoordinateGround:cf,disposeObject3D:cu,disposeTether:lp,downstream:t_,drawTextTexture:dv,effectiveCornerRadius:Jr,ellipseOutline:vv,enumerateDataScenarios:Sb,error:Qi,figureClassFor:YS,figureSectionOutline:nS,fillStyleOpacity:Jd,filterByToolType:b_,filterShortcuts:Xf,findNearestWithCapability:Fb,flattenPolygonPath:z_,flowGraphFor:$b,flowGraphIssues:Gb,flowReverseFor:jb,fontStyle:lv,footprint2D:Vy,frameClock:Rr,ftId:Ob,ftrace:Pb,getAllCapabilityMeta:$m,getCapabilityMeta:Gm,getFigure:gS,getPose:kl,getWorldPose:Al,globalSimClock:Ir,gltfNatureProperties:Py,graphFor:s_,gridPlacements:Nx,hasArc:Xr,hasCapability:Hm,hasCapacity:Iy,hasFigure:yS,inferCapacity:zy,inferDownstreamId:xb,inferFlowDirections:Tb,initFontFamilyWatcher:Zs,inspector:zd,installContractInspector:H_,isFlowNode:d_,isGenericPlaceholder:kg,isGeometricHost:Lb,isParted:wu,isRoutingTarget:Nb,isSegmentPreset:Nv,isStateDriven:pu,isThreedEnabled:Pu,matchOutbounds:lb,metrics:ji,next:Jb,nextHop:fb,nextHops:pb,nextHopsToAny:yb,nextHopsToAnyDetailed:bb,niceGridStep:ef,nodeIdOf:Xb,opaqueColor:eu,paletteVersion:KS,partAtByIndex:Mu,pickWeightedDestination:o_,planPathAStar:P_,planToReservations:O_,pointInRotatedRect:ob,polygonOffsetForPriority:mu,polygonPathLength:R_,projectToScreen:np,quatFromYaw:p_,rayAbsDistanceToRect:ab,reachableByOutbound:db,reachableDestinations:e_,reachableDestinationsFrom:n_,reachableDestinationsWeightedFrom:i_,reachableSinks:gb,receiptToJSON:Gu,recommendsLogarithmicDepthForSky:yf,rectFaceAnchors:tb,rectOutline:_v,rectangularFootprintFrames:g_,registerCapabilityMeta:Vm,registerDefaultRealObjectFactory:Qp,registerFigure:mS,registerFigureType:hS,registerPalette:QS,registerRealObjectFactory:Kp,registerTypeResolver:Rh,releaseFigureGeometry:CS,renderCanvasTexture:tv,renderPlaceholder:xg,reservationTable:k_,resetFigureClasses:VS,resetFigures:_S,resetPalettes:ik,resolveAnchorWorldPosition:rp,resolveHeightSegments:Fv,resolveMaterial3d:Pd,resolveNextHop:Zb,resolveSegments:Lv,resolveToken:ek,resolveUnknownTypes:Lh,resolveVariant:Xd,sceneComponent:Dy,setActivePalette:ZS,setPose:El,setThreedEnabled:Ou,setWorldPose:Cl,sinksForDestination:Ub,slotsFromBindings:HS,standardYieldPolicy:M_,stopFPSMeasure:Lp,straightSegmentEndpoints:nb,straightSegmentMultiInbound:sb,straightSegmentTopology:eb,textBounds:fv,textTexture:uv,toThreeSide:Dd,topApproachFrame:y_,transferLog:Wu,transferTracer:Yu,uniformZ:no,unitFigurePartGeometry:ak,unknownTypesOf:jh,unregisterFigure:bS,updateDefaultFontFamily:Qs,updateTether:ap,useFigureComponent:lS,validate:r_,validateFlowGraph:_b,version:Q_,warn:Zi});const uk=globalThis;"undefined"==typeof globalThis||uk.scene||(uk.scene=dk);export{Nc as AbsoluteLayout,ka as Animation,Zg as AudioPlayer,qr as BULGE_EPSILON,ex as Banner,tx as Banner3D,Rf as BoxSelectionManager,FS as CAPABILITY_MIXINS,vg as COMMON_PLACEHOLDER_PROPERTIES,Sg as CORE_PLACEHOLDER_TYPES,ox as Camera,rx as Camera3D,zf as CameraBookmarkManager,_f as CameraManager,Jy as Capacity,Ry as CapacityEventTracker,Bc as CardLayout,Ly as CenteringQueueStrategy,v_ as CenteringSlotStrategy,Cc as Component,nm as Connectable,ng as Container,Jl as ContainerAbstract,Mf as ControlsManager,Xv as Cube,qv as Cube3D,Zv as Cylinder,Qv as Cylinder3D,Ks as DEFAULT,bu as DEFAULT_CEILING,US as DEFAULT_PALETTE,uu as DEFAULT_PLACEMENT,Ws as DPPX,sh as DataLagTracker,Ey as DataSource,Vd as DefaultLoadingOverlayRenderer,yy as Donut,Ev as DonutExtrude,bg as Ellipse,Mv as EllipseExtrude,Sf as EventManager3D,fl as EventMap,LS as FIGURE_CAPABILITIES,NS as FIGURE_CAPABILITY_NOTES,Fp as FPS,$S as FigureInstance,lk as FigurePart,ck as FigurePartRealObject,Ky as FixedSlotStrategy,yx as FloorPlate,a_ as FlowEngine,h_ as FlowNode,qs as GESTURES,cx as GLTFObject,Ty as GLTF_BASE_URL_ALIAS,Mg as GenericObject,Dv as GeometryBank,Kg as GifView,Af as GizmoManager,Tf as GizmoOperationManager,oy as GlobalRef,Oy as GltfComponent,Hy as GridStacking,ey as Group,Fc as HTMLAbsoluteLayout,sy as HTMLOverlayContainer,Fg as HTMLOverlayElement,c_ as Holdable,Lg as ImageView,Rc as InfoWindow,Fx as InstancedSet,Pf as InteractionManager,Xy as ItemsDataBinding,Xs as KEYEVENTS,gp as Layer,Lc as Layout,xf as LightManager,hx as LightObject,gg as Line,zx as Line3D,Vc as LinearHorizontalLayout,$c as LinearVerticalLayout,ah as LoadTracker,Rd as LoadingOverlay,iy as LocalRef,Td as MATERIAL_PRESETS,jv as MAX_SEGMENTS,Us as MAX_UNDO_SIZE,Rv as MIN_SEGMENTS,Ys as MODE_ADD,Hs as MODE_EDIT,Gs as MODE_PASTE_DATABIND,Vs as MODE_PASTE_STYLE,Bs as MODE_SHIFT,Ns as MODE_VIEW,av as MaterialBank,hk as Model,Ql as MoveHandle,Fs as NOTHING,A_ as NavGraph,wy as Node,Rg as OrthoLine,jx as OrthoLine3D,Np as PIXEL_RATIO,_g as PLACEHOLDER_THEMES,uy as Path,Ny as PatternStacking,Of as PlacementManager,dx as PointLight,Cg as Polygon,Pg as PolygonContainer,Av as PolygonExtrude,I_ as PolygonPathPolyline,Ig as Polyline,Rx as Polyline3D,ly as Popup,dy as PopupContainer,vl as Pose6DOF,xu as RealObject,Yx as RealObjectCamera,Wp as RealObjectDomElement,iv as RealObjectDomTexture,Hx as RealObjectDummy,Su as RealObjectExternalModel,wv as RealObjectExtrude,Cu as RealObjectGLTF,wx as RealObjectGroup,Ix as RealObjectLine,cv as RealObjectMesh,Vx as RealObjectPlane,Ux as RealObjectPlane2D,Gx as RealObjectScene,My as RealObjectService,Vv as RealObjectSprite,Gv as RealObjectSprite2D,mv as RealObjectText,rm as Rect,Sv as RectExtrude,Oc as RectPath,V_ as ReferenceMap,vf as RendererManager,S_ as ReservationTable,ih as RootContainer,am as Ruler,Zd as SCALE_MIN,$s as SCENE_MODE,zv as SEGMENT_DEFAULTS,Iv as SEGMENT_PRESETS,qf as SHORTCUT_SECTIONS,Ku as Scene,bf as SceneManager,mp as ScenePopup,Iu as SceneSearchEngine,K_ as ScriptLoader,Ru as SearchOverlay,ky as ServiceComponent,Tc as Shape,Yv as Sphere,Bv as Sphere3D,Uv as Sprite,vy as Star,Tv as StarExtrude,Wy as TRANSFER_SLOT_KEY,Uc as TableLayout,Jg as Text,Bf as ThreeCapability,qx as ThreeContainer,Cy as ThreeDOnly,Lu as Tracker,Uu as Transfer,Kl as TransitionEffect,fy as Triangle,Cv as TriangleExtrude,nu as UNIT_DIMENSION,ru as UNIT_ROTATE,iu as UNIT_SCALE,su as UNIT_TRANSLATE,nk as UNTOKENED_COLOR,Ay as ValueHolder,Hf as VertexGizmoManager,By as VolumeStacking,fx as Wall,px as Wall3D,fu as Z_PRIORITY,ES as acquireFigureGeometry,tk as activePalette,JS as activePaletteName,qb as allDestinations,rb as anchorsConnect,Sa as animate,tu as applyAlpha,Id as applyMaterial3dProps,Qb as applyPolicy,Uy as applySeatingRotation,Yy as applyStackLayout,gu as applyZPriorityToMaterials,ib as arcSegmentTopology,jy as autoWireBackPressure,$p as buildArrow3D,N_ as buildContractInspector,sf as buildCoordinateGround,TS as buildFigureGeometry,hb as buildFlowGraph,T_ as buildNavGraph,kv as buildShapeFromPolygonPath,op as buildTether,Zr as bulgeFromDrag,Qr as bulgeHandlePosition,mb as canReach,Bm as capability,xv as centerOnBBox,__ as chooseNearestPickupFrame,cp as clearTether,vb as collectAdjacentSegments,Ea as compile,Wb as componentForNode,Kr as computeArcParams,Rb as computeFlowMap,Fy as computeStackPositions,to as cornerHandlePosition,eo as cornerRadiusFromDrag,Zu as create,Hp as createCanvas,J_ as createCanvasTexture,mf as createFloor,Zp as createRealObjectFor,bx as createSelectionHandle3D,rh as dataLagTracker,Ji as debug,cb as deliversInto,wa as delta,cf as disposeCoordinateGround,cu as disposeObject3D,lp as disposeTether,t_ as downstream,dv as drawTextTexture,Jr as effectiveCornerRadius,vv as ellipseOutline,Sb as enumerateDataScenarios,Qi as error,YS as figureClassFor,nS as figureSectionOutline,Jd as fillStyleOpacity,b_ as filterByToolType,Xf as filterShortcuts,Fb as findNearestWithCapability,z_ as flattenPolygonPath,$b as flowGraphFor,Gb as flowGraphIssues,jb as flowReverseFor,lv as fontStyle,Vy as footprint2D,Rr as frameClock,Ob as ftId,Pb as ftrace,$m as getAllCapabilityMeta,Gm as getCapabilityMeta,gS as getFigure,kl as getPose,Al as getWorldPose,Ir as globalSimClock,Py as gltfNatureProperties,s_ as graphFor,Nx as gridPlacements,Xr as hasArc,Hm as hasCapability,Iy as hasCapacity,yS as hasFigure,zy as inferCapacity,xb as inferDownstreamId,Tb as inferFlowDirections,Zs as initFontFamilyWatcher,zd as inspector,H_ as installContractInspector,d_ as isFlowNode,kg as isGenericPlaceholder,Lb as isGeometricHost,wu as isParted,Nb as isRoutingTarget,Nv as isSegmentPreset,pu as isStateDriven,Pu as isThreedEnabled,lb as matchOutbounds,ji as metrics,Jb as next,fb as nextHop,pb as nextHops,yb as nextHopsToAny,bb as nextHopsToAnyDetailed,ef as niceGridStep,Xb as nodeIdOf,eu as opaqueColor,KS as paletteVersion,Mu as partAtByIndex,o_ as pickWeightedDestination,P_ as planPathAStar,O_ as planToReservations,ob as pointInRotatedRect,mu as polygonOffsetForPriority,R_ as polygonPathLength,np as projectToScreen,p_ as quatFromYaw,ab as rayAbsDistanceToRect,db as reachableByOutbound,e_ as reachableDestinations,n_ as reachableDestinationsFrom,i_ as reachableDestinationsWeightedFrom,gb as reachableSinks,Gu as receiptToJSON,yf as recommendsLogarithmicDepthForSky,tb as rectFaceAnchors,_v as rectOutline,g_ as rectangularFootprintFrames,Vm as registerCapabilityMeta,Qp as registerDefaultRealObjectFactory,mS as registerFigure,hS as registerFigureType,QS as registerPalette,Kp as registerRealObjectFactory,Rh as registerTypeResolver,CS as releaseFigureGeometry,tv as renderCanvasTexture,xg as renderPlaceholder,k_ as reservationTable,VS as resetFigureClasses,_S as resetFigures,ik as resetPalettes,rp as resolveAnchorWorldPosition,Fv as resolveHeightSegments,Pd as resolveMaterial3d,Zb as resolveNextHop,Lv as resolveSegments,ek as resolveToken,Lh as resolveUnknownTypes,Xd as resolveVariant,Dy as sceneComponent,ZS as setActivePalette,El as setPose,Ou as setThreedEnabled,Cl as setWorldPose,Ub as sinksForDestination,HS as slotsFromBindings,M_ as standardYieldPolicy,Lp as stopFPSMeasure,nb as straightSegmentEndpoints,sb as straightSegmentMultiInbound,eb as straightSegmentTopology,fv as textBounds,uv as textTexture,Dd as toThreeSide,y_ as topApproachFrame,Wu as transferLog,Yu as transferTracer,no as uniformZ,ak as unitFigurePartGeometry,jh as unknownTypesOf,bS as unregisterFigure,Qs as updateDefaultFontFamily,ap as updateTether,lS as useFigureComponent,r_ as validate,_b as validateFlowGraph,Q_ as version,Zi as warn};
51
51
  //# sourceMappingURL=things-scene.mjs.map