tscircuit 0.0.2830-libonly → 0.0.2831-libonly

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.
@@ -228,7 +228,7 @@ Visit https://react.dev/link/error-boundaries to learn more about error boundari
228
228
  `+(matchedNames.join(" > ")+`
229
229
 
230
230
  No matching component was found for:
231
- `)+hostRoot.join(" > ")}return null},exports2.getPublicRootInstance=function(container){if(container=container.current,!container.child)return null;switch(container.child.tag){case 27:case 5:return getPublicInstance(container.child.stateNode);default:return container.child.stateNode}},exports2.injectIntoDevTools=function(){var internals={bundleType:1,version:rendererVersion,rendererPackageName,currentDispatcherRef:ReactSharedInternals,reconcilerVersion:"19.1.0"};return extraDevToolsConfig!==null&&(internals.rendererConfig=extraDevToolsConfig),internals.overrideHookState=overrideHookState,internals.overrideHookStateDeletePath=overrideHookStateDeletePath,internals.overrideHookStateRenamePath=overrideHookStateRenamePath,internals.overrideProps=overrideProps,internals.overridePropsDeletePath=overridePropsDeletePath,internals.overridePropsRenamePath=overridePropsRenamePath,internals.scheduleUpdate=scheduleUpdate,internals.setErrorHandler=setErrorHandler,internals.setSuspenseHandler=setSuspenseHandler,internals.scheduleRefresh=scheduleRefresh,internals.scheduleRoot=scheduleRoot,internals.setRefreshHandler=setRefreshHandler,internals.getCurrentFiber=getCurrentFiberForDevTools,internals.getLaneLabelMap=getLaneLabelMap,internals.injectProfilingHooks=injectProfilingHooks,injectInternals(internals)},exports2.isAlreadyRendering=function(){return(executionContext2&(RenderContext|CommitContext))!==NoContext},exports2.observeVisibleRects=function(hostRoot,selectors4,callback,options){function commitHook(){var nextInstanceRoots=findAllNodes(hostRoot,selectors4);instanceRoots.forEach(function(target){0>nextInstanceRoots.indexOf(target)&&unobserve(target)}),nextInstanceRoots.forEach(function(target){0>instanceRoots.indexOf(target)&&observe(target)})}if(!supportsTestSelectors)throw Error("Test selector API is not supported by this renderer.");var instanceRoots=findAllNodes(hostRoot,selectors4);callback=setupIntersectionObserver(instanceRoots,callback,options);var disconnect=callback.disconnect,observe=callback.observe,unobserve=callback.unobserve;return commitHooks.push(commitHook),{disconnect:function(){var index2=commitHooks.indexOf(commitHook);0<=index2&&commitHooks.splice(index2,1),disconnect()}}},exports2.shouldError=function(fiber){return shouldErrorImpl(fiber)},exports2.shouldSuspend=function(fiber){return shouldSuspendImpl(fiber)},exports2.startHostTransition=function(formFiber,pendingState,action,formData){if(formFiber.tag!==5)throw Error("Expected the form instance to be a HostComponent. This is a bug in React.");var queue=ensureFormComponentIsStateful(formFiber).queue;startTransition(formFiber,queue,pendingState,NotPendingTransition,action===null?noop:function(){ReactSharedInternals.T===null&&console.error("requestFormReset was called outside a transition or action. To fix, move to an action, or wrap with startTransition.");var resetStateQueue=ensureFormComponentIsStateful(formFiber).next.queue;return dispatchSetStateInternal(formFiber,resetStateQueue,{},requestUpdateLane(formFiber)),action(formData)})},exports2.updateContainer=function(element,container,parentComponent,callback){var current4=container.current,lane=requestUpdateLane(current4);return updateContainerImpl(current4,lane,element,container,parentComponent,callback),lane},exports2.updateContainerSync=updateContainerSync,exports2},module.exports.default=module.exports,Object.defineProperty(module.exports,"__esModule",{value:!0})}});var require_react_reconciler=__commonJS({"node_modules/react-reconciler/index.js"(exports,module){"use strict";module.exports=require_react_reconciler_development()}});var require_react_reconciler_constants_development=__commonJS({"node_modules/react-reconciler/cjs/react-reconciler-constants.development.js"(exports){"use strict";exports.ConcurrentRoot=1,exports.ContinuousEventPriority=8,exports.DefaultEventPriority=32,exports.DiscreteEventPriority=2,exports.IdleEventPriority=268435456,exports.LegacyRoot=0,exports.NoEventPriority=0}});var require_constants=__commonJS({"node_modules/react-reconciler/constants.js"(exports,module){"use strict";module.exports=require_react_reconciler_constants_development()}});var common_exports={};__export(common_exports,{ANGLE_ORDER:()=>ANGLE_ORDER,ARRAY_TYPE:()=>ARRAY_TYPE,EPSILON:()=>EPSILON,RANDOM:()=>RANDOM,equals:()=>equals,round:()=>round,setMatrixArrayType:()=>setMatrixArrayType,toDegree:()=>toDegree,toRadian:()=>toRadian});function round(a10){return a10>=0?Math.round(a10):a10%.5===0?Math.floor(a10):Math.round(a10)}function setMatrixArrayType(type){ARRAY_TYPE=type}function toRadian(a10){return a10*degree}function toDegree(a10){return a10*radian}function equals(a10,b10){var tolerance=arguments.length>2&&arguments[2]!==void 0?arguments[2]:EPSILON;return Math.abs(a10-b10)<=tolerance*Math.max(1,Math.abs(a10),Math.abs(b10))}var EPSILON,ARRAY_TYPE,RANDOM,ANGLE_ORDER,degree,radian,init_common=__esm({"node_modules/gl-matrix/esm/common.js"(){"use strict";EPSILON=1e-6,ARRAY_TYPE=typeof Float32Array<"u"?Float32Array:Array,RANDOM=Math.random,ANGLE_ORDER="zyx";degree=Math.PI/180,radian=180/Math.PI}});var mat2_exports={};__export(mat2_exports,{LDU:()=>LDU,add:()=>add,adjoint:()=>adjoint,clone:()=>clone,copy:()=>copy,create:()=>create,determinant:()=>determinant,equals:()=>equals2,exactEquals:()=>exactEquals,frob:()=>frob,fromRotation:()=>fromRotation,fromScaling:()=>fromScaling,fromValues:()=>fromValues2,identity:()=>identity2,invert:()=>invert,mul:()=>mul,multiply:()=>multiply,multiplyScalar:()=>multiplyScalar,multiplyScalarAndAdd:()=>multiplyScalarAndAdd,rotate:()=>rotate3,scale:()=>scale3,set:()=>set,str:()=>str,sub:()=>sub,subtract:()=>subtract2,transpose:()=>transpose});function create(){var out=new ARRAY_TYPE(4);return ARRAY_TYPE!=Float32Array&&(out[1]=0,out[2]=0),out[0]=1,out[3]=1,out}function clone(a10){var out=new ARRAY_TYPE(4);return out[0]=a10[0],out[1]=a10[1],out[2]=a10[2],out[3]=a10[3],out}function copy(out,a10){return out[0]=a10[0],out[1]=a10[1],out[2]=a10[2],out[3]=a10[3],out}function identity2(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out}function fromValues2(m00,m01,m10,m11){var out=new ARRAY_TYPE(4);return out[0]=m00,out[1]=m01,out[2]=m10,out[3]=m11,out}function set(out,m00,m01,m10,m11){return out[0]=m00,out[1]=m01,out[2]=m10,out[3]=m11,out}function transpose(out,a10){if(out===a10){var a12=a10[1];out[1]=a10[2],out[2]=a12}else out[0]=a10[0],out[1]=a10[2],out[2]=a10[1],out[3]=a10[3];return out}function invert(out,a10){var a03=a10[0],a12=a10[1],a22=a10[2],a32=a10[3],det=a03*a32-a22*a12;return det?(det=1/det,out[0]=a32*det,out[1]=-a12*det,out[2]=-a22*det,out[3]=a03*det,out):null}function adjoint(out,a10){var a03=a10[0];return out[0]=a10[3],out[1]=-a10[1],out[2]=-a10[2],out[3]=a03,out}function determinant(a10){return a10[0]*a10[3]-a10[2]*a10[1]}function multiply(out,a10,b10){var a03=a10[0],a12=a10[1],a22=a10[2],a32=a10[3],b03=b10[0],b12=b10[1],b22=b10[2],b32=b10[3];return out[0]=a03*b03+a22*b12,out[1]=a12*b03+a32*b12,out[2]=a03*b22+a22*b32,out[3]=a12*b22+a32*b32,out}function rotate3(out,a10,rad){var a03=a10[0],a12=a10[1],a22=a10[2],a32=a10[3],s11=Math.sin(rad),c10=Math.cos(rad);return out[0]=a03*c10+a22*s11,out[1]=a12*c10+a32*s11,out[2]=a03*-s11+a22*c10,out[3]=a12*-s11+a32*c10,out}function scale3(out,a10,v11){var a03=a10[0],a12=a10[1],a22=a10[2],a32=a10[3],v03=v11[0],v12=v11[1];return out[0]=a03*v03,out[1]=a12*v03,out[2]=a22*v12,out[3]=a32*v12,out}function fromRotation(out,rad){var s11=Math.sin(rad),c10=Math.cos(rad);return out[0]=c10,out[1]=s11,out[2]=-s11,out[3]=c10,out}function fromScaling(out,v11){return out[0]=v11[0],out[1]=0,out[2]=0,out[3]=v11[1],out}function str(a10){return"mat2("+a10[0]+", "+a10[1]+", "+a10[2]+", "+a10[3]+")"}function frob(a10){return Math.sqrt(a10[0]*a10[0]+a10[1]*a10[1]+a10[2]*a10[2]+a10[3]*a10[3])}function LDU(L11,D11,U11,a10){return L11[2]=a10[2]/a10[0],U11[0]=a10[0],U11[1]=a10[1],U11[3]=a10[3]-L11[2]*U11[1],[L11,D11,U11]}function add(out,a10,b10){return out[0]=a10[0]+b10[0],out[1]=a10[1]+b10[1],out[2]=a10[2]+b10[2],out[3]=a10[3]+b10[3],out}function subtract2(out,a10,b10){return out[0]=a10[0]-b10[0],out[1]=a10[1]-b10[1],out[2]=a10[2]-b10[2],out[3]=a10[3]-b10[3],out}function exactEquals(a10,b10){return a10[0]===b10[0]&&a10[1]===b10[1]&&a10[2]===b10[2]&&a10[3]===b10[3]}function equals2(a10,b10){var a03=a10[0],a12=a10[1],a22=a10[2],a32=a10[3],b03=b10[0],b12=b10[1],b22=b10[2],b32=b10[3];return Math.abs(a03-b03)<=EPSILON*Math.max(1,Math.abs(a03),Math.abs(b03))&&Math.abs(a12-b12)<=EPSILON*Math.max(1,Math.abs(a12),Math.abs(b12))&&Math.abs(a22-b22)<=EPSILON*Math.max(1,Math.abs(a22),Math.abs(b22))&&Math.abs(a32-b32)<=EPSILON*Math.max(1,Math.abs(a32),Math.abs(b32))}function multiplyScalar(out,a10,b10){return out[0]=a10[0]*b10,out[1]=a10[1]*b10,out[2]=a10[2]*b10,out[3]=a10[3]*b10,out}function multiplyScalarAndAdd(out,a10,b10,scale15){return out[0]=a10[0]+b10[0]*scale15,out[1]=a10[1]+b10[1]*scale15,out[2]=a10[2]+b10[2]*scale15,out[3]=a10[3]+b10[3]*scale15,out}var mul,sub,init_mat2=__esm({"node_modules/gl-matrix/esm/mat2.js"(){"use strict";init_common();mul=multiply,sub=subtract2}});var mat2d_exports={};__export(mat2d_exports,{add:()=>add2,clone:()=>clone2,copy:()=>copy2,create:()=>create2,determinant:()=>determinant2,equals:()=>equals3,exactEquals:()=>exactEquals2,frob:()=>frob2,fromRotation:()=>fromRotation2,fromScaling:()=>fromScaling2,fromTranslation:()=>fromTranslation,fromValues:()=>fromValues3,identity:()=>identity3,invert:()=>invert2,mul:()=>mul2,multiply:()=>multiply2,multiplyScalar:()=>multiplyScalar2,multiplyScalarAndAdd:()=>multiplyScalarAndAdd2,rotate:()=>rotate4,scale:()=>scale4,set:()=>set2,str:()=>str2,sub:()=>sub2,subtract:()=>subtract3,translate:()=>translate3});function create2(){var out=new ARRAY_TYPE(6);return ARRAY_TYPE!=Float32Array&&(out[1]=0,out[2]=0,out[4]=0,out[5]=0),out[0]=1,out[3]=1,out}function clone2(a10){var out=new ARRAY_TYPE(6);return out[0]=a10[0],out[1]=a10[1],out[2]=a10[2],out[3]=a10[3],out[4]=a10[4],out[5]=a10[5],out}function copy2(out,a10){return out[0]=a10[0],out[1]=a10[1],out[2]=a10[2],out[3]=a10[3],out[4]=a10[4],out[5]=a10[5],out}function identity3(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out[4]=0,out[5]=0,out}function fromValues3(a10,b10,c10,d11,tx4,ty4){var out=new ARRAY_TYPE(6);return out[0]=a10,out[1]=b10,out[2]=c10,out[3]=d11,out[4]=tx4,out[5]=ty4,out}function set2(out,a10,b10,c10,d11,tx4,ty4){return out[0]=a10,out[1]=b10,out[2]=c10,out[3]=d11,out[4]=tx4,out[5]=ty4,out}function invert2(out,a10){var aa3=a10[0],ab4=a10[1],ac4=a10[2],ad3=a10[3],atx=a10[4],aty=a10[5],det=aa3*ad3-ab4*ac4;return det?(det=1/det,out[0]=ad3*det,out[1]=-ab4*det,out[2]=-ac4*det,out[3]=aa3*det,out[4]=(ac4*aty-ad3*atx)*det,out[5]=(ab4*atx-aa3*aty)*det,out):null}function determinant2(a10){return a10[0]*a10[3]-a10[1]*a10[2]}function multiply2(out,a10,b10){var a03=a10[0],a12=a10[1],a22=a10[2],a32=a10[3],a42=a10[4],a52=a10[5],b03=b10[0],b12=b10[1],b22=b10[2],b32=b10[3],b43=b10[4],b52=b10[5];return out[0]=a03*b03+a22*b12,out[1]=a12*b03+a32*b12,out[2]=a03*b22+a22*b32,out[3]=a12*b22+a32*b32,out[4]=a03*b43+a22*b52+a42,out[5]=a12*b43+a32*b52+a52,out}function rotate4(out,a10,rad){var a03=a10[0],a12=a10[1],a22=a10[2],a32=a10[3],a42=a10[4],a52=a10[5],s11=Math.sin(rad),c10=Math.cos(rad);return out[0]=a03*c10+a22*s11,out[1]=a12*c10+a32*s11,out[2]=a03*-s11+a22*c10,out[3]=a12*-s11+a32*c10,out[4]=a42,out[5]=a52,out}function scale4(out,a10,v11){var a03=a10[0],a12=a10[1],a22=a10[2],a32=a10[3],a42=a10[4],a52=a10[5],v03=v11[0],v12=v11[1];return out[0]=a03*v03,out[1]=a12*v03,out[2]=a22*v12,out[3]=a32*v12,out[4]=a42,out[5]=a52,out}function translate3(out,a10,v11){var a03=a10[0],a12=a10[1],a22=a10[2],a32=a10[3],a42=a10[4],a52=a10[5],v03=v11[0],v12=v11[1];return out[0]=a03,out[1]=a12,out[2]=a22,out[3]=a32,out[4]=a03*v03+a22*v12+a42,out[5]=a12*v03+a32*v12+a52,out}function fromRotation2(out,rad){var s11=Math.sin(rad),c10=Math.cos(rad);return out[0]=c10,out[1]=s11,out[2]=-s11,out[3]=c10,out[4]=0,out[5]=0,out}function fromScaling2(out,v11){return out[0]=v11[0],out[1]=0,out[2]=0,out[3]=v11[1],out[4]=0,out[5]=0,out}function fromTranslation(out,v11){return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out[4]=v11[0],out[5]=v11[1],out}function str2(a10){return"mat2d("+a10[0]+", "+a10[1]+", "+a10[2]+", "+a10[3]+", "+a10[4]+", "+a10[5]+")"}function frob2(a10){return Math.sqrt(a10[0]*a10[0]+a10[1]*a10[1]+a10[2]*a10[2]+a10[3]*a10[3]+a10[4]*a10[4]+a10[5]*a10[5]+1)}function add2(out,a10,b10){return out[0]=a10[0]+b10[0],out[1]=a10[1]+b10[1],out[2]=a10[2]+b10[2],out[3]=a10[3]+b10[3],out[4]=a10[4]+b10[4],out[5]=a10[5]+b10[5],out}function subtract3(out,a10,b10){return out[0]=a10[0]-b10[0],out[1]=a10[1]-b10[1],out[2]=a10[2]-b10[2],out[3]=a10[3]-b10[3],out[4]=a10[4]-b10[4],out[5]=a10[5]-b10[5],out}function multiplyScalar2(out,a10,b10){return out[0]=a10[0]*b10,out[1]=a10[1]*b10,out[2]=a10[2]*b10,out[3]=a10[3]*b10,out[4]=a10[4]*b10,out[5]=a10[5]*b10,out}function multiplyScalarAndAdd2(out,a10,b10,scale15){return out[0]=a10[0]+b10[0]*scale15,out[1]=a10[1]+b10[1]*scale15,out[2]=a10[2]+b10[2]*scale15,out[3]=a10[3]+b10[3]*scale15,out[4]=a10[4]+b10[4]*scale15,out[5]=a10[5]+b10[5]*scale15,out}function exactEquals2(a10,b10){return a10[0]===b10[0]&&a10[1]===b10[1]&&a10[2]===b10[2]&&a10[3]===b10[3]&&a10[4]===b10[4]&&a10[5]===b10[5]}function equals3(a10,b10){var a03=a10[0],a12=a10[1],a22=a10[2],a32=a10[3],a42=a10[4],a52=a10[5],b03=b10[0],b12=b10[1],b22=b10[2],b32=b10[3],b43=b10[4],b52=b10[5];return Math.abs(a03-b03)<=EPSILON*Math.max(1,Math.abs(a03),Math.abs(b03))&&Math.abs(a12-b12)<=EPSILON*Math.max(1,Math.abs(a12),Math.abs(b12))&&Math.abs(a22-b22)<=EPSILON*Math.max(1,Math.abs(a22),Math.abs(b22))&&Math.abs(a32-b32)<=EPSILON*Math.max(1,Math.abs(a32),Math.abs(b32))&&Math.abs(a42-b43)<=EPSILON*Math.max(1,Math.abs(a42),Math.abs(b43))&&Math.abs(a52-b52)<=EPSILON*Math.max(1,Math.abs(a52),Math.abs(b52))}var mul2,sub2,init_mat2d=__esm({"node_modules/gl-matrix/esm/mat2d.js"(){"use strict";init_common();mul2=multiply2,sub2=subtract3}});var mat3_exports={};__export(mat3_exports,{add:()=>add3,adjoint:()=>adjoint2,clone:()=>clone3,copy:()=>copy3,create:()=>create3,determinant:()=>determinant3,equals:()=>equals4,exactEquals:()=>exactEquals3,frob:()=>frob3,fromMat2d:()=>fromMat2d,fromMat4:()=>fromMat4,fromQuat:()=>fromQuat,fromRotation:()=>fromRotation3,fromScaling:()=>fromScaling3,fromTranslation:()=>fromTranslation2,fromValues:()=>fromValues4,identity:()=>identity4,invert:()=>invert3,mul:()=>mul3,multiply:()=>multiply3,multiplyScalar:()=>multiplyScalar3,multiplyScalarAndAdd:()=>multiplyScalarAndAdd3,normalFromMat4:()=>normalFromMat4,projection:()=>projection,rotate:()=>rotate5,scale:()=>scale5,set:()=>set3,str:()=>str3,sub:()=>sub3,subtract:()=>subtract4,translate:()=>translate4,transpose:()=>transpose2});function create3(){var out=new ARRAY_TYPE(9);return ARRAY_TYPE!=Float32Array&&(out[1]=0,out[2]=0,out[3]=0,out[5]=0,out[6]=0,out[7]=0),out[0]=1,out[4]=1,out[8]=1,out}function fromMat4(out,a10){return out[0]=a10[0],out[1]=a10[1],out[2]=a10[2],out[3]=a10[4],out[4]=a10[5],out[5]=a10[6],out[6]=a10[8],out[7]=a10[9],out[8]=a10[10],out}function clone3(a10){var out=new ARRAY_TYPE(9);return out[0]=a10[0],out[1]=a10[1],out[2]=a10[2],out[3]=a10[3],out[4]=a10[4],out[5]=a10[5],out[6]=a10[6],out[7]=a10[7],out[8]=a10[8],out}function copy3(out,a10){return out[0]=a10[0],out[1]=a10[1],out[2]=a10[2],out[3]=a10[3],out[4]=a10[4],out[5]=a10[5],out[6]=a10[6],out[7]=a10[7],out[8]=a10[8],out}function fromValues4(m00,m01,m022,m10,m11,m12,m20,m21,m22){var out=new ARRAY_TYPE(9);return out[0]=m00,out[1]=m01,out[2]=m022,out[3]=m10,out[4]=m11,out[5]=m12,out[6]=m20,out[7]=m21,out[8]=m22,out}function set3(out,m00,m01,m022,m10,m11,m12,m20,m21,m22){return out[0]=m00,out[1]=m01,out[2]=m022,out[3]=m10,out[4]=m11,out[5]=m12,out[6]=m20,out[7]=m21,out[8]=m22,out}function identity4(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=1,out[5]=0,out[6]=0,out[7]=0,out[8]=1,out}function transpose2(out,a10){if(out===a10){var a01=a10[1],a022=a10[2],a12=a10[5];out[1]=a10[3],out[2]=a10[6],out[3]=a01,out[5]=a10[7],out[6]=a022,out[7]=a12}else out[0]=a10[0],out[1]=a10[3],out[2]=a10[6],out[3]=a10[1],out[4]=a10[4],out[5]=a10[7],out[6]=a10[2],out[7]=a10[5],out[8]=a10[8];return out}function invert3(out,a10){var a00=a10[0],a01=a10[1],a022=a10[2],a102=a10[3],a11=a10[4],a12=a10[5],a20=a10[6],a21=a10[7],a22=a10[8],b01=a22*a11-a12*a21,b11=-a22*a102+a12*a20,b21=a21*a102-a11*a20,det=a00*b01+a01*b11+a022*b21;return det?(det=1/det,out[0]=b01*det,out[1]=(-a22*a01+a022*a21)*det,out[2]=(a12*a01-a022*a11)*det,out[3]=b11*det,out[4]=(a22*a00-a022*a20)*det,out[5]=(-a12*a00+a022*a102)*det,out[6]=b21*det,out[7]=(-a21*a00+a01*a20)*det,out[8]=(a11*a00-a01*a102)*det,out):null}function adjoint2(out,a10){var a00=a10[0],a01=a10[1],a022=a10[2],a102=a10[3],a11=a10[4],a12=a10[5],a20=a10[6],a21=a10[7],a22=a10[8];return out[0]=a11*a22-a12*a21,out[1]=a022*a21-a01*a22,out[2]=a01*a12-a022*a11,out[3]=a12*a20-a102*a22,out[4]=a00*a22-a022*a20,out[5]=a022*a102-a00*a12,out[6]=a102*a21-a11*a20,out[7]=a01*a20-a00*a21,out[8]=a00*a11-a01*a102,out}function determinant3(a10){var a00=a10[0],a01=a10[1],a022=a10[2],a102=a10[3],a11=a10[4],a12=a10[5],a20=a10[6],a21=a10[7],a22=a10[8];return a00*(a22*a11-a12*a21)+a01*(-a22*a102+a12*a20)+a022*(a21*a102-a11*a20)}function multiply3(out,a10,b10){var a00=a10[0],a01=a10[1],a022=a10[2],a102=a10[3],a11=a10[4],a12=a10[5],a20=a10[6],a21=a10[7],a22=a10[8],b00=b10[0],b01=b10[1],b022=b10[2],b102=b10[3],b11=b10[4],b12=b10[5],b20=b10[6],b21=b10[7],b22=b10[8];return out[0]=b00*a00+b01*a102+b022*a20,out[1]=b00*a01+b01*a11+b022*a21,out[2]=b00*a022+b01*a12+b022*a22,out[3]=b102*a00+b11*a102+b12*a20,out[4]=b102*a01+b11*a11+b12*a21,out[5]=b102*a022+b11*a12+b12*a22,out[6]=b20*a00+b21*a102+b22*a20,out[7]=b20*a01+b21*a11+b22*a21,out[8]=b20*a022+b21*a12+b22*a22,out}function translate4(out,a10,v11){var a00=a10[0],a01=a10[1],a022=a10[2],a102=a10[3],a11=a10[4],a12=a10[5],a20=a10[6],a21=a10[7],a22=a10[8],x11=v11[0],y11=v11[1];return out[0]=a00,out[1]=a01,out[2]=a022,out[3]=a102,out[4]=a11,out[5]=a12,out[6]=x11*a00+y11*a102+a20,out[7]=x11*a01+y11*a11+a21,out[8]=x11*a022+y11*a12+a22,out}function rotate5(out,a10,rad){var a00=a10[0],a01=a10[1],a022=a10[2],a102=a10[3],a11=a10[4],a12=a10[5],a20=a10[6],a21=a10[7],a22=a10[8],s11=Math.sin(rad),c10=Math.cos(rad);return out[0]=c10*a00+s11*a102,out[1]=c10*a01+s11*a11,out[2]=c10*a022+s11*a12,out[3]=c10*a102-s11*a00,out[4]=c10*a11-s11*a01,out[5]=c10*a12-s11*a022,out[6]=a20,out[7]=a21,out[8]=a22,out}function scale5(out,a10,v11){var x11=v11[0],y11=v11[1];return out[0]=x11*a10[0],out[1]=x11*a10[1],out[2]=x11*a10[2],out[3]=y11*a10[3],out[4]=y11*a10[4],out[5]=y11*a10[5],out[6]=a10[6],out[7]=a10[7],out[8]=a10[8],out}function fromTranslation2(out,v11){return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=1,out[5]=0,out[6]=v11[0],out[7]=v11[1],out[8]=1,out}function fromRotation3(out,rad){var s11=Math.sin(rad),c10=Math.cos(rad);return out[0]=c10,out[1]=s11,out[2]=0,out[3]=-s11,out[4]=c10,out[5]=0,out[6]=0,out[7]=0,out[8]=1,out}function fromScaling3(out,v11){return out[0]=v11[0],out[1]=0,out[2]=0,out[3]=0,out[4]=v11[1],out[5]=0,out[6]=0,out[7]=0,out[8]=1,out}function fromMat2d(out,a10){return out[0]=a10[0],out[1]=a10[1],out[2]=0,out[3]=a10[2],out[4]=a10[3],out[5]=0,out[6]=a10[4],out[7]=a10[5],out[8]=1,out}function fromQuat(out,q11){var x11=q11[0],y11=q11[1],z10=q11[2],w10=q11[3],x22=x11+x11,y22=y11+y11,z22=z10+z10,xx4=x11*x22,yx4=y11*x22,yy4=y11*y22,zx4=z10*x22,zy4=z10*y22,zz2=z10*z22,wx4=w10*x22,wy4=w10*y22,wz2=w10*z22;return out[0]=1-yy4-zz2,out[3]=yx4-wz2,out[6]=zx4+wy4,out[1]=yx4+wz2,out[4]=1-xx4-zz2,out[7]=zy4-wx4,out[2]=zx4-wy4,out[5]=zy4+wx4,out[8]=1-xx4-yy4,out}function normalFromMat4(out,a10){var a00=a10[0],a01=a10[1],a022=a10[2],a03=a10[3],a102=a10[4],a11=a10[5],a12=a10[6],a13=a10[7],a20=a10[8],a21=a10[9],a22=a10[10],a23=a10[11],a30=a10[12],a31=a10[13],a32=a10[14],a33=a10[15],b00=a00*a11-a01*a102,b01=a00*a12-a022*a102,b022=a00*a13-a03*a102,b03=a01*a12-a022*a11,b04=a01*a13-a03*a11,b05=a022*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32,det=b00*b11-b01*b10+b022*b09+b03*b08-b04*b07+b05*b06;return det?(det=1/det,out[0]=(a11*b11-a12*b10+a13*b09)*det,out[1]=(a12*b08-a102*b11-a13*b07)*det,out[2]=(a102*b10-a11*b08+a13*b06)*det,out[3]=(a022*b10-a01*b11-a03*b09)*det,out[4]=(a00*b11-a022*b08+a03*b07)*det,out[5]=(a01*b08-a00*b10-a03*b06)*det,out[6]=(a31*b05-a32*b04+a33*b03)*det,out[7]=(a32*b022-a30*b05-a33*b01)*det,out[8]=(a30*b04-a31*b022+a33*b00)*det,out):null}function projection(out,width,height){return out[0]=2/width,out[1]=0,out[2]=0,out[3]=0,out[4]=-2/height,out[5]=0,out[6]=-1,out[7]=1,out[8]=1,out}function str3(a10){return"mat3("+a10[0]+", "+a10[1]+", "+a10[2]+", "+a10[3]+", "+a10[4]+", "+a10[5]+", "+a10[6]+", "+a10[7]+", "+a10[8]+")"}function frob3(a10){return Math.sqrt(a10[0]*a10[0]+a10[1]*a10[1]+a10[2]*a10[2]+a10[3]*a10[3]+a10[4]*a10[4]+a10[5]*a10[5]+a10[6]*a10[6]+a10[7]*a10[7]+a10[8]*a10[8])}function add3(out,a10,b10){return out[0]=a10[0]+b10[0],out[1]=a10[1]+b10[1],out[2]=a10[2]+b10[2],out[3]=a10[3]+b10[3],out[4]=a10[4]+b10[4],out[5]=a10[5]+b10[5],out[6]=a10[6]+b10[6],out[7]=a10[7]+b10[7],out[8]=a10[8]+b10[8],out}function subtract4(out,a10,b10){return out[0]=a10[0]-b10[0],out[1]=a10[1]-b10[1],out[2]=a10[2]-b10[2],out[3]=a10[3]-b10[3],out[4]=a10[4]-b10[4],out[5]=a10[5]-b10[5],out[6]=a10[6]-b10[6],out[7]=a10[7]-b10[7],out[8]=a10[8]-b10[8],out}function multiplyScalar3(out,a10,b10){return out[0]=a10[0]*b10,out[1]=a10[1]*b10,out[2]=a10[2]*b10,out[3]=a10[3]*b10,out[4]=a10[4]*b10,out[5]=a10[5]*b10,out[6]=a10[6]*b10,out[7]=a10[7]*b10,out[8]=a10[8]*b10,out}function multiplyScalarAndAdd3(out,a10,b10,scale15){return out[0]=a10[0]+b10[0]*scale15,out[1]=a10[1]+b10[1]*scale15,out[2]=a10[2]+b10[2]*scale15,out[3]=a10[3]+b10[3]*scale15,out[4]=a10[4]+b10[4]*scale15,out[5]=a10[5]+b10[5]*scale15,out[6]=a10[6]+b10[6]*scale15,out[7]=a10[7]+b10[7]*scale15,out[8]=a10[8]+b10[8]*scale15,out}function exactEquals3(a10,b10){return a10[0]===b10[0]&&a10[1]===b10[1]&&a10[2]===b10[2]&&a10[3]===b10[3]&&a10[4]===b10[4]&&a10[5]===b10[5]&&a10[6]===b10[6]&&a10[7]===b10[7]&&a10[8]===b10[8]}function equals4(a10,b10){var a03=a10[0],a12=a10[1],a22=a10[2],a32=a10[3],a42=a10[4],a52=a10[5],a62=a10[6],a72=a10[7],a82=a10[8],b03=b10[0],b12=b10[1],b22=b10[2],b32=b10[3],b43=b10[4],b52=b10[5],b62=b10[6],b72=b10[7],b82=b10[8];return Math.abs(a03-b03)<=EPSILON*Math.max(1,Math.abs(a03),Math.abs(b03))&&Math.abs(a12-b12)<=EPSILON*Math.max(1,Math.abs(a12),Math.abs(b12))&&Math.abs(a22-b22)<=EPSILON*Math.max(1,Math.abs(a22),Math.abs(b22))&&Math.abs(a32-b32)<=EPSILON*Math.max(1,Math.abs(a32),Math.abs(b32))&&Math.abs(a42-b43)<=EPSILON*Math.max(1,Math.abs(a42),Math.abs(b43))&&Math.abs(a52-b52)<=EPSILON*Math.max(1,Math.abs(a52),Math.abs(b52))&&Math.abs(a62-b62)<=EPSILON*Math.max(1,Math.abs(a62),Math.abs(b62))&&Math.abs(a72-b72)<=EPSILON*Math.max(1,Math.abs(a72),Math.abs(b72))&&Math.abs(a82-b82)<=EPSILON*Math.max(1,Math.abs(a82),Math.abs(b82))}var mul3,sub3,init_mat3=__esm({"node_modules/gl-matrix/esm/mat3.js"(){"use strict";init_common();mul3=multiply3,sub3=subtract4}});var mat4_exports={};__export(mat4_exports,{add:()=>add4,adjoint:()=>adjoint3,clone:()=>clone4,copy:()=>copy4,create:()=>create4,decompose:()=>decompose,determinant:()=>determinant4,equals:()=>equals5,exactEquals:()=>exactEquals4,frob:()=>frob4,fromQuat:()=>fromQuat3,fromQuat2:()=>fromQuat2,fromRotation:()=>fromRotation4,fromRotationTranslation:()=>fromRotationTranslation,fromRotationTranslationScale:()=>fromRotationTranslationScale,fromRotationTranslationScaleOrigin:()=>fromRotationTranslationScaleOrigin,fromScaling:()=>fromScaling4,fromTranslation:()=>fromTranslation3,fromValues:()=>fromValues5,fromXRotation:()=>fromXRotation,fromYRotation:()=>fromYRotation,fromZRotation:()=>fromZRotation,frustum:()=>frustum,getRotation:()=>getRotation,getScaling:()=>getScaling,getTranslation:()=>getTranslation,identity:()=>identity5,invert:()=>invert4,lookAt:()=>lookAt,mul:()=>mul4,multiply:()=>multiply4,multiplyScalar:()=>multiplyScalar4,multiplyScalarAndAdd:()=>multiplyScalarAndAdd4,ortho:()=>ortho,orthoNO:()=>orthoNO,orthoZO:()=>orthoZO,perspective:()=>perspective,perspectiveFromFieldOfView:()=>perspectiveFromFieldOfView,perspectiveNO:()=>perspectiveNO,perspectiveZO:()=>perspectiveZO,rotate:()=>rotate6,rotateX:()=>rotateX,rotateY:()=>rotateY,rotateZ:()=>rotateZ,scale:()=>scale6,set:()=>set4,str:()=>str4,sub:()=>sub4,subtract:()=>subtract5,targetTo:()=>targetTo,translate:()=>translate5,transpose:()=>transpose3});function create4(){var out=new ARRAY_TYPE(16);return ARRAY_TYPE!=Float32Array&&(out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[11]=0,out[12]=0,out[13]=0,out[14]=0),out[0]=1,out[5]=1,out[10]=1,out[15]=1,out}function clone4(a10){var out=new ARRAY_TYPE(16);return out[0]=a10[0],out[1]=a10[1],out[2]=a10[2],out[3]=a10[3],out[4]=a10[4],out[5]=a10[5],out[6]=a10[6],out[7]=a10[7],out[8]=a10[8],out[9]=a10[9],out[10]=a10[10],out[11]=a10[11],out[12]=a10[12],out[13]=a10[13],out[14]=a10[14],out[15]=a10[15],out}function copy4(out,a10){return out[0]=a10[0],out[1]=a10[1],out[2]=a10[2],out[3]=a10[3],out[4]=a10[4],out[5]=a10[5],out[6]=a10[6],out[7]=a10[7],out[8]=a10[8],out[9]=a10[9],out[10]=a10[10],out[11]=a10[11],out[12]=a10[12],out[13]=a10[13],out[14]=a10[14],out[15]=a10[15],out}function fromValues5(m00,m01,m022,m03,m10,m11,m12,m13,m20,m21,m22,m23,m30,m31,m32,m33){var out=new ARRAY_TYPE(16);return out[0]=m00,out[1]=m01,out[2]=m022,out[3]=m03,out[4]=m10,out[5]=m11,out[6]=m12,out[7]=m13,out[8]=m20,out[9]=m21,out[10]=m22,out[11]=m23,out[12]=m30,out[13]=m31,out[14]=m32,out[15]=m33,out}function set4(out,m00,m01,m022,m03,m10,m11,m12,m13,m20,m21,m22,m23,m30,m31,m32,m33){return out[0]=m00,out[1]=m01,out[2]=m022,out[3]=m03,out[4]=m10,out[5]=m11,out[6]=m12,out[7]=m13,out[8]=m20,out[9]=m21,out[10]=m22,out[11]=m23,out[12]=m30,out[13]=m31,out[14]=m32,out[15]=m33,out}function identity5(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=1,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[10]=1,out[11]=0,out[12]=0,out[13]=0,out[14]=0,out[15]=1,out}function transpose3(out,a10){if(out===a10){var a01=a10[1],a022=a10[2],a03=a10[3],a12=a10[6],a13=a10[7],a23=a10[11];out[1]=a10[4],out[2]=a10[8],out[3]=a10[12],out[4]=a01,out[6]=a10[9],out[7]=a10[13],out[8]=a022,out[9]=a12,out[11]=a10[14],out[12]=a03,out[13]=a13,out[14]=a23}else out[0]=a10[0],out[1]=a10[4],out[2]=a10[8],out[3]=a10[12],out[4]=a10[1],out[5]=a10[5],out[6]=a10[9],out[7]=a10[13],out[8]=a10[2],out[9]=a10[6],out[10]=a10[10],out[11]=a10[14],out[12]=a10[3],out[13]=a10[7],out[14]=a10[11],out[15]=a10[15];return out}function invert4(out,a10){var a00=a10[0],a01=a10[1],a022=a10[2],a03=a10[3],a102=a10[4],a11=a10[5],a12=a10[6],a13=a10[7],a20=a10[8],a21=a10[9],a22=a10[10],a23=a10[11],a30=a10[12],a31=a10[13],a32=a10[14],a33=a10[15],b00=a00*a11-a01*a102,b01=a00*a12-a022*a102,b022=a00*a13-a03*a102,b03=a01*a12-a022*a11,b04=a01*a13-a03*a11,b05=a022*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32,det=b00*b11-b01*b10+b022*b09+b03*b08-b04*b07+b05*b06;return det?(det=1/det,out[0]=(a11*b11-a12*b10+a13*b09)*det,out[1]=(a022*b10-a01*b11-a03*b09)*det,out[2]=(a31*b05-a32*b04+a33*b03)*det,out[3]=(a22*b04-a21*b05-a23*b03)*det,out[4]=(a12*b08-a102*b11-a13*b07)*det,out[5]=(a00*b11-a022*b08+a03*b07)*det,out[6]=(a32*b022-a30*b05-a33*b01)*det,out[7]=(a20*b05-a22*b022+a23*b01)*det,out[8]=(a102*b10-a11*b08+a13*b06)*det,out[9]=(a01*b08-a00*b10-a03*b06)*det,out[10]=(a30*b04-a31*b022+a33*b00)*det,out[11]=(a21*b022-a20*b04-a23*b00)*det,out[12]=(a11*b07-a102*b09-a12*b06)*det,out[13]=(a00*b09-a01*b07+a022*b06)*det,out[14]=(a31*b01-a30*b03-a32*b00)*det,out[15]=(a20*b03-a21*b01+a22*b00)*det,out):null}function adjoint3(out,a10){var a00=a10[0],a01=a10[1],a022=a10[2],a03=a10[3],a102=a10[4],a11=a10[5],a12=a10[6],a13=a10[7],a20=a10[8],a21=a10[9],a22=a10[10],a23=a10[11],a30=a10[12],a31=a10[13],a32=a10[14],a33=a10[15],b00=a00*a11-a01*a102,b01=a00*a12-a022*a102,b022=a00*a13-a03*a102,b03=a01*a12-a022*a11,b04=a01*a13-a03*a11,b05=a022*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32;return out[0]=a11*b11-a12*b10+a13*b09,out[1]=a022*b10-a01*b11-a03*b09,out[2]=a31*b05-a32*b04+a33*b03,out[3]=a22*b04-a21*b05-a23*b03,out[4]=a12*b08-a102*b11-a13*b07,out[5]=a00*b11-a022*b08+a03*b07,out[6]=a32*b022-a30*b05-a33*b01,out[7]=a20*b05-a22*b022+a23*b01,out[8]=a102*b10-a11*b08+a13*b06,out[9]=a01*b08-a00*b10-a03*b06,out[10]=a30*b04-a31*b022+a33*b00,out[11]=a21*b022-a20*b04-a23*b00,out[12]=a11*b07-a102*b09-a12*b06,out[13]=a00*b09-a01*b07+a022*b06,out[14]=a31*b01-a30*b03-a32*b00,out[15]=a20*b03-a21*b01+a22*b00,out}function determinant4(a10){var a00=a10[0],a01=a10[1],a022=a10[2],a03=a10[3],a102=a10[4],a11=a10[5],a12=a10[6],a13=a10[7],a20=a10[8],a21=a10[9],a22=a10[10],a23=a10[11],a30=a10[12],a31=a10[13],a32=a10[14],a33=a10[15],b03=a00*a11-a01*a102,b12=a00*a12-a022*a102,b22=a01*a12-a022*a11,b32=a20*a31-a21*a30,b43=a20*a32-a22*a30,b52=a21*a32-a22*a31,b62=a00*b52-a01*b43+a022*b32,b72=a102*b52-a11*b43+a12*b32,b82=a20*b22-a21*b12+a22*b03,b93=a30*b22-a31*b12+a32*b03;return a13*b62-a03*b72+a33*b82-a23*b93}function multiply4(out,a10,b10){var a00=a10[0],a01=a10[1],a022=a10[2],a03=a10[3],a102=a10[4],a11=a10[5],a12=a10[6],a13=a10[7],a20=a10[8],a21=a10[9],a22=a10[10],a23=a10[11],a30=a10[12],a31=a10[13],a32=a10[14],a33=a10[15],b03=b10[0],b12=b10[1],b22=b10[2],b32=b10[3];return out[0]=b03*a00+b12*a102+b22*a20+b32*a30,out[1]=b03*a01+b12*a11+b22*a21+b32*a31,out[2]=b03*a022+b12*a12+b22*a22+b32*a32,out[3]=b03*a03+b12*a13+b22*a23+b32*a33,b03=b10[4],b12=b10[5],b22=b10[6],b32=b10[7],out[4]=b03*a00+b12*a102+b22*a20+b32*a30,out[5]=b03*a01+b12*a11+b22*a21+b32*a31,out[6]=b03*a022+b12*a12+b22*a22+b32*a32,out[7]=b03*a03+b12*a13+b22*a23+b32*a33,b03=b10[8],b12=b10[9],b22=b10[10],b32=b10[11],out[8]=b03*a00+b12*a102+b22*a20+b32*a30,out[9]=b03*a01+b12*a11+b22*a21+b32*a31,out[10]=b03*a022+b12*a12+b22*a22+b32*a32,out[11]=b03*a03+b12*a13+b22*a23+b32*a33,b03=b10[12],b12=b10[13],b22=b10[14],b32=b10[15],out[12]=b03*a00+b12*a102+b22*a20+b32*a30,out[13]=b03*a01+b12*a11+b22*a21+b32*a31,out[14]=b03*a022+b12*a12+b22*a22+b32*a32,out[15]=b03*a03+b12*a13+b22*a23+b32*a33,out}function translate5(out,a10,v11){var x11=v11[0],y11=v11[1],z10=v11[2],a00,a01,a022,a03,a102,a11,a12,a13,a20,a21,a22,a23;return a10===out?(out[12]=a10[0]*x11+a10[4]*y11+a10[8]*z10+a10[12],out[13]=a10[1]*x11+a10[5]*y11+a10[9]*z10+a10[13],out[14]=a10[2]*x11+a10[6]*y11+a10[10]*z10+a10[14],out[15]=a10[3]*x11+a10[7]*y11+a10[11]*z10+a10[15]):(a00=a10[0],a01=a10[1],a022=a10[2],a03=a10[3],a102=a10[4],a11=a10[5],a12=a10[6],a13=a10[7],a20=a10[8],a21=a10[9],a22=a10[10],a23=a10[11],out[0]=a00,out[1]=a01,out[2]=a022,out[3]=a03,out[4]=a102,out[5]=a11,out[6]=a12,out[7]=a13,out[8]=a20,out[9]=a21,out[10]=a22,out[11]=a23,out[12]=a00*x11+a102*y11+a20*z10+a10[12],out[13]=a01*x11+a11*y11+a21*z10+a10[13],out[14]=a022*x11+a12*y11+a22*z10+a10[14],out[15]=a03*x11+a13*y11+a23*z10+a10[15]),out}function scale6(out,a10,v11){var x11=v11[0],y11=v11[1],z10=v11[2];return out[0]=a10[0]*x11,out[1]=a10[1]*x11,out[2]=a10[2]*x11,out[3]=a10[3]*x11,out[4]=a10[4]*y11,out[5]=a10[5]*y11,out[6]=a10[6]*y11,out[7]=a10[7]*y11,out[8]=a10[8]*z10,out[9]=a10[9]*z10,out[10]=a10[10]*z10,out[11]=a10[11]*z10,out[12]=a10[12],out[13]=a10[13],out[14]=a10[14],out[15]=a10[15],out}function rotate6(out,a10,rad,axis){var x11=axis[0],y11=axis[1],z10=axis[2],len6=Math.sqrt(x11*x11+y11*y11+z10*z10),s11,c10,t48,a00,a01,a022,a03,a102,a11,a12,a13,a20,a21,a22,a23,b00,b01,b022,b10,b11,b12,b20,b21,b22;return len6<EPSILON?null:(len6=1/len6,x11*=len6,y11*=len6,z10*=len6,s11=Math.sin(rad),c10=Math.cos(rad),t48=1-c10,a00=a10[0],a01=a10[1],a022=a10[2],a03=a10[3],a102=a10[4],a11=a10[5],a12=a10[6],a13=a10[7],a20=a10[8],a21=a10[9],a22=a10[10],a23=a10[11],b00=x11*x11*t48+c10,b01=y11*x11*t48+z10*s11,b022=z10*x11*t48-y11*s11,b10=x11*y11*t48-z10*s11,b11=y11*y11*t48+c10,b12=z10*y11*t48+x11*s11,b20=x11*z10*t48+y11*s11,b21=y11*z10*t48-x11*s11,b22=z10*z10*t48+c10,out[0]=a00*b00+a102*b01+a20*b022,out[1]=a01*b00+a11*b01+a21*b022,out[2]=a022*b00+a12*b01+a22*b022,out[3]=a03*b00+a13*b01+a23*b022,out[4]=a00*b10+a102*b11+a20*b12,out[5]=a01*b10+a11*b11+a21*b12,out[6]=a022*b10+a12*b11+a22*b12,out[7]=a03*b10+a13*b11+a23*b12,out[8]=a00*b20+a102*b21+a20*b22,out[9]=a01*b20+a11*b21+a21*b22,out[10]=a022*b20+a12*b21+a22*b22,out[11]=a03*b20+a13*b21+a23*b22,a10!==out&&(out[12]=a10[12],out[13]=a10[13],out[14]=a10[14],out[15]=a10[15]),out)}function rotateX(out,a10,rad){var s11=Math.sin(rad),c10=Math.cos(rad),a102=a10[4],a11=a10[5],a12=a10[6],a13=a10[7],a20=a10[8],a21=a10[9],a22=a10[10],a23=a10[11];return a10!==out&&(out[0]=a10[0],out[1]=a10[1],out[2]=a10[2],out[3]=a10[3],out[12]=a10[12],out[13]=a10[13],out[14]=a10[14],out[15]=a10[15]),out[4]=a102*c10+a20*s11,out[5]=a11*c10+a21*s11,out[6]=a12*c10+a22*s11,out[7]=a13*c10+a23*s11,out[8]=a20*c10-a102*s11,out[9]=a21*c10-a11*s11,out[10]=a22*c10-a12*s11,out[11]=a23*c10-a13*s11,out}function rotateY(out,a10,rad){var s11=Math.sin(rad),c10=Math.cos(rad),a00=a10[0],a01=a10[1],a022=a10[2],a03=a10[3],a20=a10[8],a21=a10[9],a22=a10[10],a23=a10[11];return a10!==out&&(out[4]=a10[4],out[5]=a10[5],out[6]=a10[6],out[7]=a10[7],out[12]=a10[12],out[13]=a10[13],out[14]=a10[14],out[15]=a10[15]),out[0]=a00*c10-a20*s11,out[1]=a01*c10-a21*s11,out[2]=a022*c10-a22*s11,out[3]=a03*c10-a23*s11,out[8]=a00*s11+a20*c10,out[9]=a01*s11+a21*c10,out[10]=a022*s11+a22*c10,out[11]=a03*s11+a23*c10,out}function rotateZ(out,a10,rad){var s11=Math.sin(rad),c10=Math.cos(rad),a00=a10[0],a01=a10[1],a022=a10[2],a03=a10[3],a102=a10[4],a11=a10[5],a12=a10[6],a13=a10[7];return a10!==out&&(out[8]=a10[8],out[9]=a10[9],out[10]=a10[10],out[11]=a10[11],out[12]=a10[12],out[13]=a10[13],out[14]=a10[14],out[15]=a10[15]),out[0]=a00*c10+a102*s11,out[1]=a01*c10+a11*s11,out[2]=a022*c10+a12*s11,out[3]=a03*c10+a13*s11,out[4]=a102*c10-a00*s11,out[5]=a11*c10-a01*s11,out[6]=a12*c10-a022*s11,out[7]=a13*c10-a03*s11,out}function fromTranslation3(out,v11){return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=1,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[10]=1,out[11]=0,out[12]=v11[0],out[13]=v11[1],out[14]=v11[2],out[15]=1,out}function fromScaling4(out,v11){return out[0]=v11[0],out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=v11[1],out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[10]=v11[2],out[11]=0,out[12]=0,out[13]=0,out[14]=0,out[15]=1,out}function fromRotation4(out,rad,axis){var x11=axis[0],y11=axis[1],z10=axis[2],len6=Math.sqrt(x11*x11+y11*y11+z10*z10),s11,c10,t48;return len6<EPSILON?null:(len6=1/len6,x11*=len6,y11*=len6,z10*=len6,s11=Math.sin(rad),c10=Math.cos(rad),t48=1-c10,out[0]=x11*x11*t48+c10,out[1]=y11*x11*t48+z10*s11,out[2]=z10*x11*t48-y11*s11,out[3]=0,out[4]=x11*y11*t48-z10*s11,out[5]=y11*y11*t48+c10,out[6]=z10*y11*t48+x11*s11,out[7]=0,out[8]=x11*z10*t48+y11*s11,out[9]=y11*z10*t48-x11*s11,out[10]=z10*z10*t48+c10,out[11]=0,out[12]=0,out[13]=0,out[14]=0,out[15]=1,out)}function fromXRotation(out,rad){var s11=Math.sin(rad),c10=Math.cos(rad);return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=c10,out[6]=s11,out[7]=0,out[8]=0,out[9]=-s11,out[10]=c10,out[11]=0,out[12]=0,out[13]=0,out[14]=0,out[15]=1,out}function fromYRotation(out,rad){var s11=Math.sin(rad),c10=Math.cos(rad);return out[0]=c10,out[1]=0,out[2]=-s11,out[3]=0,out[4]=0,out[5]=1,out[6]=0,out[7]=0,out[8]=s11,out[9]=0,out[10]=c10,out[11]=0,out[12]=0,out[13]=0,out[14]=0,out[15]=1,out}function fromZRotation(out,rad){var s11=Math.sin(rad),c10=Math.cos(rad);return out[0]=c10,out[1]=s11,out[2]=0,out[3]=0,out[4]=-s11,out[5]=c10,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[10]=1,out[11]=0,out[12]=0,out[13]=0,out[14]=0,out[15]=1,out}function fromRotationTranslation(out,q11,v11){var x11=q11[0],y11=q11[1],z10=q11[2],w10=q11[3],x22=x11+x11,y22=y11+y11,z22=z10+z10,xx4=x11*x22,xy4=x11*y22,xz2=x11*z22,yy4=y11*y22,yz2=y11*z22,zz2=z10*z22,wx4=w10*x22,wy4=w10*y22,wz2=w10*z22;return out[0]=1-(yy4+zz2),out[1]=xy4+wz2,out[2]=xz2-wy4,out[3]=0,out[4]=xy4-wz2,out[5]=1-(xx4+zz2),out[6]=yz2+wx4,out[7]=0,out[8]=xz2+wy4,out[9]=yz2-wx4,out[10]=1-(xx4+yy4),out[11]=0,out[12]=v11[0],out[13]=v11[1],out[14]=v11[2],out[15]=1,out}function fromQuat2(out,a10){var translation=new ARRAY_TYPE(3),bx4=-a10[0],by4=-a10[1],bz2=-a10[2],bw4=a10[3],ax4=a10[4],ay4=a10[5],az2=a10[6],aw3=a10[7],magnitude=bx4*bx4+by4*by4+bz2*bz2+bw4*bw4;return magnitude>0?(translation[0]=(ax4*bw4+aw3*bx4+ay4*bz2-az2*by4)*2/magnitude,translation[1]=(ay4*bw4+aw3*by4+az2*bx4-ax4*bz2)*2/magnitude,translation[2]=(az2*bw4+aw3*bz2+ax4*by4-ay4*bx4)*2/magnitude):(translation[0]=(ax4*bw4+aw3*bx4+ay4*bz2-az2*by4)*2,translation[1]=(ay4*bw4+aw3*by4+az2*bx4-ax4*bz2)*2,translation[2]=(az2*bw4+aw3*bz2+ax4*by4-ay4*bx4)*2),fromRotationTranslation(out,a10,translation),out}function getTranslation(out,mat){return out[0]=mat[12],out[1]=mat[13],out[2]=mat[14],out}function getScaling(out,mat){var m11=mat[0],m12=mat[1],m13=mat[2],m21=mat[4],m22=mat[5],m23=mat[6],m31=mat[8],m32=mat[9],m33=mat[10];return out[0]=Math.sqrt(m11*m11+m12*m12+m13*m13),out[1]=Math.sqrt(m21*m21+m22*m22+m23*m23),out[2]=Math.sqrt(m31*m31+m32*m32+m33*m33),out}function getRotation(out,mat){var scaling=new ARRAY_TYPE(3);getScaling(scaling,mat);var is1=1/scaling[0],is22=1/scaling[1],is32=1/scaling[2],sm11=mat[0]*is1,sm12=mat[1]*is22,sm13=mat[2]*is32,sm21=mat[4]*is1,sm22=mat[5]*is22,sm23=mat[6]*is32,sm31=mat[8]*is1,sm32=mat[9]*is22,sm33=mat[10]*is32,trace=sm11+sm22+sm33,S10=0;return trace>0?(S10=Math.sqrt(trace+1)*2,out[3]=.25*S10,out[0]=(sm23-sm32)/S10,out[1]=(sm31-sm13)/S10,out[2]=(sm12-sm21)/S10):sm11>sm22&&sm11>sm33?(S10=Math.sqrt(1+sm11-sm22-sm33)*2,out[3]=(sm23-sm32)/S10,out[0]=.25*S10,out[1]=(sm12+sm21)/S10,out[2]=(sm31+sm13)/S10):sm22>sm33?(S10=Math.sqrt(1+sm22-sm11-sm33)*2,out[3]=(sm31-sm13)/S10,out[0]=(sm12+sm21)/S10,out[1]=.25*S10,out[2]=(sm23+sm32)/S10):(S10=Math.sqrt(1+sm33-sm11-sm22)*2,out[3]=(sm12-sm21)/S10,out[0]=(sm31+sm13)/S10,out[1]=(sm23+sm32)/S10,out[2]=.25*S10),out}function decompose(out_r,out_t,out_s,mat){out_t[0]=mat[12],out_t[1]=mat[13],out_t[2]=mat[14];var m11=mat[0],m12=mat[1],m13=mat[2],m21=mat[4],m22=mat[5],m23=mat[6],m31=mat[8],m32=mat[9],m33=mat[10];out_s[0]=Math.sqrt(m11*m11+m12*m12+m13*m13),out_s[1]=Math.sqrt(m21*m21+m22*m22+m23*m23),out_s[2]=Math.sqrt(m31*m31+m32*m32+m33*m33);var is1=1/out_s[0],is22=1/out_s[1],is32=1/out_s[2],sm11=m11*is1,sm12=m12*is22,sm13=m13*is32,sm21=m21*is1,sm22=m22*is22,sm23=m23*is32,sm31=m31*is1,sm32=m32*is22,sm33=m33*is32,trace=sm11+sm22+sm33,S10=0;return trace>0?(S10=Math.sqrt(trace+1)*2,out_r[3]=.25*S10,out_r[0]=(sm23-sm32)/S10,out_r[1]=(sm31-sm13)/S10,out_r[2]=(sm12-sm21)/S10):sm11>sm22&&sm11>sm33?(S10=Math.sqrt(1+sm11-sm22-sm33)*2,out_r[3]=(sm23-sm32)/S10,out_r[0]=.25*S10,out_r[1]=(sm12+sm21)/S10,out_r[2]=(sm31+sm13)/S10):sm22>sm33?(S10=Math.sqrt(1+sm22-sm11-sm33)*2,out_r[3]=(sm31-sm13)/S10,out_r[0]=(sm12+sm21)/S10,out_r[1]=.25*S10,out_r[2]=(sm23+sm32)/S10):(S10=Math.sqrt(1+sm33-sm11-sm22)*2,out_r[3]=(sm12-sm21)/S10,out_r[0]=(sm31+sm13)/S10,out_r[1]=(sm23+sm32)/S10,out_r[2]=.25*S10),out_r}function fromRotationTranslationScale(out,q11,v11,s11){var x11=q11[0],y11=q11[1],z10=q11[2],w10=q11[3],x22=x11+x11,y22=y11+y11,z22=z10+z10,xx4=x11*x22,xy4=x11*y22,xz2=x11*z22,yy4=y11*y22,yz2=y11*z22,zz2=z10*z22,wx4=w10*x22,wy4=w10*y22,wz2=w10*z22,sx4=s11[0],sy4=s11[1],sz2=s11[2];return out[0]=(1-(yy4+zz2))*sx4,out[1]=(xy4+wz2)*sx4,out[2]=(xz2-wy4)*sx4,out[3]=0,out[4]=(xy4-wz2)*sy4,out[5]=(1-(xx4+zz2))*sy4,out[6]=(yz2+wx4)*sy4,out[7]=0,out[8]=(xz2+wy4)*sz2,out[9]=(yz2-wx4)*sz2,out[10]=(1-(xx4+yy4))*sz2,out[11]=0,out[12]=v11[0],out[13]=v11[1],out[14]=v11[2],out[15]=1,out}function fromRotationTranslationScaleOrigin(out,q11,v11,s11,o11){var x11=q11[0],y11=q11[1],z10=q11[2],w10=q11[3],x22=x11+x11,y22=y11+y11,z22=z10+z10,xx4=x11*x22,xy4=x11*y22,xz2=x11*z22,yy4=y11*y22,yz2=y11*z22,zz2=z10*z22,wx4=w10*x22,wy4=w10*y22,wz2=w10*z22,sx4=s11[0],sy4=s11[1],sz2=s11[2],ox4=o11[0],oy4=o11[1],oz2=o11[2],out0=(1-(yy4+zz2))*sx4,out1=(xy4+wz2)*sx4,out2=(xz2-wy4)*sx4,out4=(xy4-wz2)*sy4,out5=(1-(xx4+zz2))*sy4,out6=(yz2+wx4)*sy4,out8=(xz2+wy4)*sz2,out9=(yz2-wx4)*sz2,out10=(1-(xx4+yy4))*sz2;return out[0]=out0,out[1]=out1,out[2]=out2,out[3]=0,out[4]=out4,out[5]=out5,out[6]=out6,out[7]=0,out[8]=out8,out[9]=out9,out[10]=out10,out[11]=0,out[12]=v11[0]+ox4-(out0*ox4+out4*oy4+out8*oz2),out[13]=v11[1]+oy4-(out1*ox4+out5*oy4+out9*oz2),out[14]=v11[2]+oz2-(out2*ox4+out6*oy4+out10*oz2),out[15]=1,out}function fromQuat3(out,q11){var x11=q11[0],y11=q11[1],z10=q11[2],w10=q11[3],x22=x11+x11,y22=y11+y11,z22=z10+z10,xx4=x11*x22,yx4=y11*x22,yy4=y11*y22,zx4=z10*x22,zy4=z10*y22,zz2=z10*z22,wx4=w10*x22,wy4=w10*y22,wz2=w10*z22;return out[0]=1-yy4-zz2,out[1]=yx4+wz2,out[2]=zx4-wy4,out[3]=0,out[4]=yx4-wz2,out[5]=1-xx4-zz2,out[6]=zy4+wx4,out[7]=0,out[8]=zx4+wy4,out[9]=zy4-wx4,out[10]=1-xx4-yy4,out[11]=0,out[12]=0,out[13]=0,out[14]=0,out[15]=1,out}function frustum(out,left,right,bottom,top,near3,far){var rl3=1/(right-left),tb4=1/(top-bottom),nf3=1/(near3-far);return out[0]=near3*2*rl3,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=near3*2*tb4,out[6]=0,out[7]=0,out[8]=(right+left)*rl3,out[9]=(top+bottom)*tb4,out[10]=(far+near3)*nf3,out[11]=-1,out[12]=0,out[13]=0,out[14]=far*near3*2*nf3,out[15]=0,out}function perspectiveNO(out,fovy,aspect,near3,far){var f3=1/Math.tan(fovy/2);if(out[0]=f3/aspect,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=f3,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[11]=-1,out[12]=0,out[13]=0,out[15]=0,far!=null&&far!==1/0){var nf3=1/(near3-far);out[10]=(far+near3)*nf3,out[14]=2*far*near3*nf3}else out[10]=-1,out[14]=-2*near3;return out}function perspectiveZO(out,fovy,aspect,near3,far){var f3=1/Math.tan(fovy/2);if(out[0]=f3/aspect,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=f3,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[11]=-1,out[12]=0,out[13]=0,out[15]=0,far!=null&&far!==1/0){var nf3=1/(near3-far);out[10]=far*nf3,out[14]=far*near3*nf3}else out[10]=-1,out[14]=-near3;return out}function perspectiveFromFieldOfView(out,fov,near3,far){var upTan=Math.tan(fov.upDegrees*Math.PI/180),downTan=Math.tan(fov.downDegrees*Math.PI/180),leftTan=Math.tan(fov.leftDegrees*Math.PI/180),rightTan=Math.tan(fov.rightDegrees*Math.PI/180),xScale=2/(leftTan+rightTan),yScale=2/(upTan+downTan);return out[0]=xScale,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=yScale,out[6]=0,out[7]=0,out[8]=-((leftTan-rightTan)*xScale*.5),out[9]=(upTan-downTan)*yScale*.5,out[10]=far/(near3-far),out[11]=-1,out[12]=0,out[13]=0,out[14]=far*near3/(near3-far),out[15]=0,out}function orthoNO(out,left,right,bottom,top,near3,far){var lr3=1/(left-right),bt5=1/(bottom-top),nf3=1/(near3-far);return out[0]=-2*lr3,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=-2*bt5,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[10]=2*nf3,out[11]=0,out[12]=(left+right)*lr3,out[13]=(top+bottom)*bt5,out[14]=(far+near3)*nf3,out[15]=1,out}function orthoZO(out,left,right,bottom,top,near3,far){var lr3=1/(left-right),bt5=1/(bottom-top),nf3=1/(near3-far);return out[0]=-2*lr3,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=-2*bt5,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[10]=nf3,out[11]=0,out[12]=(left+right)*lr3,out[13]=(top+bottom)*bt5,out[14]=near3*nf3,out[15]=1,out}function lookAt(out,eye,center2,up4){var x03,x12,x22,y03,y12,y22,z03,z12,z22,len6,eyex=eye[0],eyey=eye[1],eyez=eye[2],upx=up4[0],upy=up4[1],upz=up4[2],centerx=center2[0],centery=center2[1],centerz=center2[2];return Math.abs(eyex-centerx)<EPSILON&&Math.abs(eyey-centery)<EPSILON&&Math.abs(eyez-centerz)<EPSILON?identity5(out):(z03=eyex-centerx,z12=eyey-centery,z22=eyez-centerz,len6=1/Math.sqrt(z03*z03+z12*z12+z22*z22),z03*=len6,z12*=len6,z22*=len6,x03=upy*z22-upz*z12,x12=upz*z03-upx*z22,x22=upx*z12-upy*z03,len6=Math.sqrt(x03*x03+x12*x12+x22*x22),len6?(len6=1/len6,x03*=len6,x12*=len6,x22*=len6):(x03=0,x12=0,x22=0),y03=z12*x22-z22*x12,y12=z22*x03-z03*x22,y22=z03*x12-z12*x03,len6=Math.sqrt(y03*y03+y12*y12+y22*y22),len6?(len6=1/len6,y03*=len6,y12*=len6,y22*=len6):(y03=0,y12=0,y22=0),out[0]=x03,out[1]=y03,out[2]=z03,out[3]=0,out[4]=x12,out[5]=y12,out[6]=z12,out[7]=0,out[8]=x22,out[9]=y22,out[10]=z22,out[11]=0,out[12]=-(x03*eyex+x12*eyey+x22*eyez),out[13]=-(y03*eyex+y12*eyey+y22*eyez),out[14]=-(z03*eyex+z12*eyey+z22*eyez),out[15]=1,out)}function targetTo(out,eye,target,up4){var eyex=eye[0],eyey=eye[1],eyez=eye[2],upx=up4[0],upy=up4[1],upz=up4[2],z03=eyex-target[0],z12=eyey-target[1],z22=eyez-target[2],len6=z03*z03+z12*z12+z22*z22;len6>0&&(len6=1/Math.sqrt(len6),z03*=len6,z12*=len6,z22*=len6);var x03=upy*z22-upz*z12,x12=upz*z03-upx*z22,x22=upx*z12-upy*z03;return len6=x03*x03+x12*x12+x22*x22,len6>0&&(len6=1/Math.sqrt(len6),x03*=len6,x12*=len6,x22*=len6),out[0]=x03,out[1]=x12,out[2]=x22,out[3]=0,out[4]=z12*x22-z22*x12,out[5]=z22*x03-z03*x22,out[6]=z03*x12-z12*x03,out[7]=0,out[8]=z03,out[9]=z12,out[10]=z22,out[11]=0,out[12]=eyex,out[13]=eyey,out[14]=eyez,out[15]=1,out}function str4(a10){return"mat4("+a10[0]+", "+a10[1]+", "+a10[2]+", "+a10[3]+", "+a10[4]+", "+a10[5]+", "+a10[6]+", "+a10[7]+", "+a10[8]+", "+a10[9]+", "+a10[10]+", "+a10[11]+", "+a10[12]+", "+a10[13]+", "+a10[14]+", "+a10[15]+")"}function frob4(a10){return Math.sqrt(a10[0]*a10[0]+a10[1]*a10[1]+a10[2]*a10[2]+a10[3]*a10[3]+a10[4]*a10[4]+a10[5]*a10[5]+a10[6]*a10[6]+a10[7]*a10[7]+a10[8]*a10[8]+a10[9]*a10[9]+a10[10]*a10[10]+a10[11]*a10[11]+a10[12]*a10[12]+a10[13]*a10[13]+a10[14]*a10[14]+a10[15]*a10[15])}function add4(out,a10,b10){return out[0]=a10[0]+b10[0],out[1]=a10[1]+b10[1],out[2]=a10[2]+b10[2],out[3]=a10[3]+b10[3],out[4]=a10[4]+b10[4],out[5]=a10[5]+b10[5],out[6]=a10[6]+b10[6],out[7]=a10[7]+b10[7],out[8]=a10[8]+b10[8],out[9]=a10[9]+b10[9],out[10]=a10[10]+b10[10],out[11]=a10[11]+b10[11],out[12]=a10[12]+b10[12],out[13]=a10[13]+b10[13],out[14]=a10[14]+b10[14],out[15]=a10[15]+b10[15],out}function subtract5(out,a10,b10){return out[0]=a10[0]-b10[0],out[1]=a10[1]-b10[1],out[2]=a10[2]-b10[2],out[3]=a10[3]-b10[3],out[4]=a10[4]-b10[4],out[5]=a10[5]-b10[5],out[6]=a10[6]-b10[6],out[7]=a10[7]-b10[7],out[8]=a10[8]-b10[8],out[9]=a10[9]-b10[9],out[10]=a10[10]-b10[10],out[11]=a10[11]-b10[11],out[12]=a10[12]-b10[12],out[13]=a10[13]-b10[13],out[14]=a10[14]-b10[14],out[15]=a10[15]-b10[15],out}function multiplyScalar4(out,a10,b10){return out[0]=a10[0]*b10,out[1]=a10[1]*b10,out[2]=a10[2]*b10,out[3]=a10[3]*b10,out[4]=a10[4]*b10,out[5]=a10[5]*b10,out[6]=a10[6]*b10,out[7]=a10[7]*b10,out[8]=a10[8]*b10,out[9]=a10[9]*b10,out[10]=a10[10]*b10,out[11]=a10[11]*b10,out[12]=a10[12]*b10,out[13]=a10[13]*b10,out[14]=a10[14]*b10,out[15]=a10[15]*b10,out}function multiplyScalarAndAdd4(out,a10,b10,scale15){return out[0]=a10[0]+b10[0]*scale15,out[1]=a10[1]+b10[1]*scale15,out[2]=a10[2]+b10[2]*scale15,out[3]=a10[3]+b10[3]*scale15,out[4]=a10[4]+b10[4]*scale15,out[5]=a10[5]+b10[5]*scale15,out[6]=a10[6]+b10[6]*scale15,out[7]=a10[7]+b10[7]*scale15,out[8]=a10[8]+b10[8]*scale15,out[9]=a10[9]+b10[9]*scale15,out[10]=a10[10]+b10[10]*scale15,out[11]=a10[11]+b10[11]*scale15,out[12]=a10[12]+b10[12]*scale15,out[13]=a10[13]+b10[13]*scale15,out[14]=a10[14]+b10[14]*scale15,out[15]=a10[15]+b10[15]*scale15,out}function exactEquals4(a10,b10){return a10[0]===b10[0]&&a10[1]===b10[1]&&a10[2]===b10[2]&&a10[3]===b10[3]&&a10[4]===b10[4]&&a10[5]===b10[5]&&a10[6]===b10[6]&&a10[7]===b10[7]&&a10[8]===b10[8]&&a10[9]===b10[9]&&a10[10]===b10[10]&&a10[11]===b10[11]&&a10[12]===b10[12]&&a10[13]===b10[13]&&a10[14]===b10[14]&&a10[15]===b10[15]}function equals5(a10,b10){var a03=a10[0],a12=a10[1],a22=a10[2],a32=a10[3],a42=a10[4],a52=a10[5],a62=a10[6],a72=a10[7],a82=a10[8],a93=a10[9],a102=a10[10],a11=a10[11],a122=a10[12],a13=a10[13],a14=a10[14],a15=a10[15],b03=b10[0],b12=b10[1],b22=b10[2],b32=b10[3],b43=b10[4],b52=b10[5],b62=b10[6],b72=b10[7],b82=b10[8],b93=b10[9],b102=b10[10],b11=b10[11],b122=b10[12],b13=b10[13],b14=b10[14],b15=b10[15];return Math.abs(a03-b03)<=EPSILON*Math.max(1,Math.abs(a03),Math.abs(b03))&&Math.abs(a12-b12)<=EPSILON*Math.max(1,Math.abs(a12),Math.abs(b12))&&Math.abs(a22-b22)<=EPSILON*Math.max(1,Math.abs(a22),Math.abs(b22))&&Math.abs(a32-b32)<=EPSILON*Math.max(1,Math.abs(a32),Math.abs(b32))&&Math.abs(a42-b43)<=EPSILON*Math.max(1,Math.abs(a42),Math.abs(b43))&&Math.abs(a52-b52)<=EPSILON*Math.max(1,Math.abs(a52),Math.abs(b52))&&Math.abs(a62-b62)<=EPSILON*Math.max(1,Math.abs(a62),Math.abs(b62))&&Math.abs(a72-b72)<=EPSILON*Math.max(1,Math.abs(a72),Math.abs(b72))&&Math.abs(a82-b82)<=EPSILON*Math.max(1,Math.abs(a82),Math.abs(b82))&&Math.abs(a93-b93)<=EPSILON*Math.max(1,Math.abs(a93),Math.abs(b93))&&Math.abs(a102-b102)<=EPSILON*Math.max(1,Math.abs(a102),Math.abs(b102))&&Math.abs(a11-b11)<=EPSILON*Math.max(1,Math.abs(a11),Math.abs(b11))&&Math.abs(a122-b122)<=EPSILON*Math.max(1,Math.abs(a122),Math.abs(b122))&&Math.abs(a13-b13)<=EPSILON*Math.max(1,Math.abs(a13),Math.abs(b13))&&Math.abs(a14-b14)<=EPSILON*Math.max(1,Math.abs(a14),Math.abs(b14))&&Math.abs(a15-b15)<=EPSILON*Math.max(1,Math.abs(a15),Math.abs(b15))}var perspective,ortho,mul4,sub4,init_mat4=__esm({"node_modules/gl-matrix/esm/mat4.js"(){"use strict";init_common();perspective=perspectiveNO;ortho=orthoNO;mul4=multiply4,sub4=subtract5}});var vec3_exports={};__export(vec3_exports,{add:()=>add5,angle:()=>angle,bezier:()=>bezier,ceil:()=>ceil,clone:()=>clone5,copy:()=>copy5,create:()=>create5,cross:()=>cross,dist:()=>dist,distance:()=>distance5,div:()=>div,divide:()=>divide,dot:()=>dot,equals:()=>equals6,exactEquals:()=>exactEquals5,floor:()=>floor,forEach:()=>forEach,fromValues:()=>fromValues6,hermite:()=>hermite,inverse:()=>inverse3,len:()=>len,length:()=>length3,lerp:()=>lerp,max:()=>max,min:()=>min,mul:()=>mul5,multiply:()=>multiply5,negate:()=>negate,normalize:()=>normalize,random:()=>random,rotateX:()=>rotateX2,rotateY:()=>rotateY2,rotateZ:()=>rotateZ2,round:()=>round2,scale:()=>scale7,scaleAndAdd:()=>scaleAndAdd,set:()=>set5,slerp:()=>slerp,sqrDist:()=>sqrDist,sqrLen:()=>sqrLen,squaredDistance:()=>squaredDistance,squaredLength:()=>squaredLength,str:()=>str5,sub:()=>sub5,subtract:()=>subtract6,transformMat3:()=>transformMat3,transformMat4:()=>transformMat4,transformQuat:()=>transformQuat,zero:()=>zero});function create5(){var out=new ARRAY_TYPE(3);return ARRAY_TYPE!=Float32Array&&(out[0]=0,out[1]=0,out[2]=0),out}function clone5(a10){var out=new ARRAY_TYPE(3);return out[0]=a10[0],out[1]=a10[1],out[2]=a10[2],out}function length3(a10){var x11=a10[0],y11=a10[1],z10=a10[2];return Math.sqrt(x11*x11+y11*y11+z10*z10)}function fromValues6(x11,y11,z10){var out=new ARRAY_TYPE(3);return out[0]=x11,out[1]=y11,out[2]=z10,out}function copy5(out,a10){return out[0]=a10[0],out[1]=a10[1],out[2]=a10[2],out}function set5(out,x11,y11,z10){return out[0]=x11,out[1]=y11,out[2]=z10,out}function add5(out,a10,b10){return out[0]=a10[0]+b10[0],out[1]=a10[1]+b10[1],out[2]=a10[2]+b10[2],out}function subtract6(out,a10,b10){return out[0]=a10[0]-b10[0],out[1]=a10[1]-b10[1],out[2]=a10[2]-b10[2],out}function multiply5(out,a10,b10){return out[0]=a10[0]*b10[0],out[1]=a10[1]*b10[1],out[2]=a10[2]*b10[2],out}function divide(out,a10,b10){return out[0]=a10[0]/b10[0],out[1]=a10[1]/b10[1],out[2]=a10[2]/b10[2],out}function ceil(out,a10){return out[0]=Math.ceil(a10[0]),out[1]=Math.ceil(a10[1]),out[2]=Math.ceil(a10[2]),out}function floor(out,a10){return out[0]=Math.floor(a10[0]),out[1]=Math.floor(a10[1]),out[2]=Math.floor(a10[2]),out}function min(out,a10,b10){return out[0]=Math.min(a10[0],b10[0]),out[1]=Math.min(a10[1],b10[1]),out[2]=Math.min(a10[2],b10[2]),out}function max(out,a10,b10){return out[0]=Math.max(a10[0],b10[0]),out[1]=Math.max(a10[1],b10[1]),out[2]=Math.max(a10[2],b10[2]),out}function round2(out,a10){return out[0]=round(a10[0]),out[1]=round(a10[1]),out[2]=round(a10[2]),out}function scale7(out,a10,b10){return out[0]=a10[0]*b10,out[1]=a10[1]*b10,out[2]=a10[2]*b10,out}function scaleAndAdd(out,a10,b10,scale15){return out[0]=a10[0]+b10[0]*scale15,out[1]=a10[1]+b10[1]*scale15,out[2]=a10[2]+b10[2]*scale15,out}function distance5(a10,b10){var x11=b10[0]-a10[0],y11=b10[1]-a10[1],z10=b10[2]-a10[2];return Math.sqrt(x11*x11+y11*y11+z10*z10)}function squaredDistance(a10,b10){var x11=b10[0]-a10[0],y11=b10[1]-a10[1],z10=b10[2]-a10[2];return x11*x11+y11*y11+z10*z10}function squaredLength(a10){var x11=a10[0],y11=a10[1],z10=a10[2];return x11*x11+y11*y11+z10*z10}function negate(out,a10){return out[0]=-a10[0],out[1]=-a10[1],out[2]=-a10[2],out}function inverse3(out,a10){return out[0]=1/a10[0],out[1]=1/a10[1],out[2]=1/a10[2],out}function normalize(out,a10){var x11=a10[0],y11=a10[1],z10=a10[2],len6=x11*x11+y11*y11+z10*z10;return len6>0&&(len6=1/Math.sqrt(len6)),out[0]=a10[0]*len6,out[1]=a10[1]*len6,out[2]=a10[2]*len6,out}function dot(a10,b10){return a10[0]*b10[0]+a10[1]*b10[1]+a10[2]*b10[2]}function cross(out,a10,b10){var ax4=a10[0],ay4=a10[1],az2=a10[2],bx4=b10[0],by4=b10[1],bz2=b10[2];return out[0]=ay4*bz2-az2*by4,out[1]=az2*bx4-ax4*bz2,out[2]=ax4*by4-ay4*bx4,out}function lerp(out,a10,b10,t48){var ax4=a10[0],ay4=a10[1],az2=a10[2];return out[0]=ax4+t48*(b10[0]-ax4),out[1]=ay4+t48*(b10[1]-ay4),out[2]=az2+t48*(b10[2]-az2),out}function slerp(out,a10,b10,t48){var angle3=Math.acos(Math.min(Math.max(dot(a10,b10),-1),1)),sinTotal=Math.sin(angle3),ratioA=Math.sin((1-t48)*angle3)/sinTotal,ratioB=Math.sin(t48*angle3)/sinTotal;return out[0]=ratioA*a10[0]+ratioB*b10[0],out[1]=ratioA*a10[1]+ratioB*b10[1],out[2]=ratioA*a10[2]+ratioB*b10[2],out}function hermite(out,a10,b10,c10,d11,t48){var factorTimes2=t48*t48,factor1=factorTimes2*(2*t48-3)+1,factor2=factorTimes2*(t48-2)+t48,factor3=factorTimes2*(t48-1),factor4=factorTimes2*(3-2*t48);return out[0]=a10[0]*factor1+b10[0]*factor2+c10[0]*factor3+d11[0]*factor4,out[1]=a10[1]*factor1+b10[1]*factor2+c10[1]*factor3+d11[1]*factor4,out[2]=a10[2]*factor1+b10[2]*factor2+c10[2]*factor3+d11[2]*factor4,out}function bezier(out,a10,b10,c10,d11,t48){var inverseFactor=1-t48,inverseFactorTimesTwo=inverseFactor*inverseFactor,factorTimes2=t48*t48,factor1=inverseFactorTimesTwo*inverseFactor,factor2=3*t48*inverseFactorTimesTwo,factor3=3*factorTimes2*inverseFactor,factor4=factorTimes2*t48;return out[0]=a10[0]*factor1+b10[0]*factor2+c10[0]*factor3+d11[0]*factor4,out[1]=a10[1]*factor1+b10[1]*factor2+c10[1]*factor3+d11[1]*factor4,out[2]=a10[2]*factor1+b10[2]*factor2+c10[2]*factor3+d11[2]*factor4,out}function random(out,scale15){scale15=scale15===void 0?1:scale15;var r11=RANDOM()*2*Math.PI,z10=RANDOM()*2-1,zScale=Math.sqrt(1-z10*z10)*scale15;return out[0]=Math.cos(r11)*zScale,out[1]=Math.sin(r11)*zScale,out[2]=z10*scale15,out}function transformMat4(out,a10,m5){var x11=a10[0],y11=a10[1],z10=a10[2],w10=m5[3]*x11+m5[7]*y11+m5[11]*z10+m5[15];return w10=w10||1,out[0]=(m5[0]*x11+m5[4]*y11+m5[8]*z10+m5[12])/w10,out[1]=(m5[1]*x11+m5[5]*y11+m5[9]*z10+m5[13])/w10,out[2]=(m5[2]*x11+m5[6]*y11+m5[10]*z10+m5[14])/w10,out}function transformMat3(out,a10,m5){var x11=a10[0],y11=a10[1],z10=a10[2];return out[0]=x11*m5[0]+y11*m5[3]+z10*m5[6],out[1]=x11*m5[1]+y11*m5[4]+z10*m5[7],out[2]=x11*m5[2]+y11*m5[5]+z10*m5[8],out}function transformQuat(out,a10,q11){var qx4=q11[0],qy4=q11[1],qz2=q11[2],qw3=q11[3],vx4=a10[0],vy4=a10[1],vz2=a10[2],tx4=qy4*vz2-qz2*vy4,ty4=qz2*vx4-qx4*vz2,tz2=qx4*vy4-qy4*vx4;return tx4=tx4+tx4,ty4=ty4+ty4,tz2=tz2+tz2,out[0]=vx4+qw3*tx4+qy4*tz2-qz2*ty4,out[1]=vy4+qw3*ty4+qz2*tx4-qx4*tz2,out[2]=vz2+qw3*tz2+qx4*ty4-qy4*tx4,out}function rotateX2(out,a10,b10,rad){var p11=[],r11=[];return p11[0]=a10[0]-b10[0],p11[1]=a10[1]-b10[1],p11[2]=a10[2]-b10[2],r11[0]=p11[0],r11[1]=p11[1]*Math.cos(rad)-p11[2]*Math.sin(rad),r11[2]=p11[1]*Math.sin(rad)+p11[2]*Math.cos(rad),out[0]=r11[0]+b10[0],out[1]=r11[1]+b10[1],out[2]=r11[2]+b10[2],out}function rotateY2(out,a10,b10,rad){var p11=[],r11=[];return p11[0]=a10[0]-b10[0],p11[1]=a10[1]-b10[1],p11[2]=a10[2]-b10[2],r11[0]=p11[2]*Math.sin(rad)+p11[0]*Math.cos(rad),r11[1]=p11[1],r11[2]=p11[2]*Math.cos(rad)-p11[0]*Math.sin(rad),out[0]=r11[0]+b10[0],out[1]=r11[1]+b10[1],out[2]=r11[2]+b10[2],out}function rotateZ2(out,a10,b10,rad){var p11=[],r11=[];return p11[0]=a10[0]-b10[0],p11[1]=a10[1]-b10[1],p11[2]=a10[2]-b10[2],r11[0]=p11[0]*Math.cos(rad)-p11[1]*Math.sin(rad),r11[1]=p11[0]*Math.sin(rad)+p11[1]*Math.cos(rad),r11[2]=p11[2],out[0]=r11[0]+b10[0],out[1]=r11[1]+b10[1],out[2]=r11[2]+b10[2],out}function angle(a10,b10){var ax4=a10[0],ay4=a10[1],az2=a10[2],bx4=b10[0],by4=b10[1],bz2=b10[2],mag=Math.sqrt((ax4*ax4+ay4*ay4+az2*az2)*(bx4*bx4+by4*by4+bz2*bz2)),cosine=mag&&dot(a10,b10)/mag;return Math.acos(Math.min(Math.max(cosine,-1),1))}function zero(out){return out[0]=0,out[1]=0,out[2]=0,out}function str5(a10){return"vec3("+a10[0]+", "+a10[1]+", "+a10[2]+")"}function exactEquals5(a10,b10){return a10[0]===b10[0]&&a10[1]===b10[1]&&a10[2]===b10[2]}function equals6(a10,b10){var a03=a10[0],a12=a10[1],a22=a10[2],b03=b10[0],b12=b10[1],b22=b10[2];return Math.abs(a03-b03)<=EPSILON*Math.max(1,Math.abs(a03),Math.abs(b03))&&Math.abs(a12-b12)<=EPSILON*Math.max(1,Math.abs(a12),Math.abs(b12))&&Math.abs(a22-b22)<=EPSILON*Math.max(1,Math.abs(a22),Math.abs(b22))}var sub5,mul5,div,dist,sqrDist,len,sqrLen,forEach,init_vec3=__esm({"node_modules/gl-matrix/esm/vec3.js"(){"use strict";init_common();sub5=subtract6,mul5=multiply5,div=divide,dist=distance5,sqrDist=squaredDistance,len=length3,sqrLen=squaredLength,forEach=(function(){var vec=create5();return function(a10,stride,offset2,count,fn3,arg){var i11,l10;for(stride||(stride=3),offset2||(offset2=0),count?l10=Math.min(count*stride+offset2,a10.length):l10=a10.length,i11=offset2;i11<l10;i11+=stride)vec[0]=a10[i11],vec[1]=a10[i11+1],vec[2]=a10[i11+2],fn3(vec,vec,arg),a10[i11]=vec[0],a10[i11+1]=vec[1],a10[i11+2]=vec[2];return a10}})()}});var vec4_exports={};__export(vec4_exports,{add:()=>add6,ceil:()=>ceil2,clone:()=>clone6,copy:()=>copy6,create:()=>create6,cross:()=>cross2,dist:()=>dist2,distance:()=>distance6,div:()=>div2,divide:()=>divide2,dot:()=>dot2,equals:()=>equals7,exactEquals:()=>exactEquals6,floor:()=>floor2,forEach:()=>forEach2,fromValues:()=>fromValues7,inverse:()=>inverse4,len:()=>len2,length:()=>length4,lerp:()=>lerp2,max:()=>max2,min:()=>min2,mul:()=>mul6,multiply:()=>multiply6,negate:()=>negate2,normalize:()=>normalize2,random:()=>random2,round:()=>round3,scale:()=>scale8,scaleAndAdd:()=>scaleAndAdd2,set:()=>set6,sqrDist:()=>sqrDist2,sqrLen:()=>sqrLen2,squaredDistance:()=>squaredDistance2,squaredLength:()=>squaredLength2,str:()=>str6,sub:()=>sub6,subtract:()=>subtract7,transformMat4:()=>transformMat42,transformQuat:()=>transformQuat2,zero:()=>zero2});function create6(){var out=new ARRAY_TYPE(4);return ARRAY_TYPE!=Float32Array&&(out[0]=0,out[1]=0,out[2]=0,out[3]=0),out}function clone6(a10){var out=new ARRAY_TYPE(4);return out[0]=a10[0],out[1]=a10[1],out[2]=a10[2],out[3]=a10[3],out}function fromValues7(x11,y11,z10,w10){var out=new ARRAY_TYPE(4);return out[0]=x11,out[1]=y11,out[2]=z10,out[3]=w10,out}function copy6(out,a10){return out[0]=a10[0],out[1]=a10[1],out[2]=a10[2],out[3]=a10[3],out}function set6(out,x11,y11,z10,w10){return out[0]=x11,out[1]=y11,out[2]=z10,out[3]=w10,out}function add6(out,a10,b10){return out[0]=a10[0]+b10[0],out[1]=a10[1]+b10[1],out[2]=a10[2]+b10[2],out[3]=a10[3]+b10[3],out}function subtract7(out,a10,b10){return out[0]=a10[0]-b10[0],out[1]=a10[1]-b10[1],out[2]=a10[2]-b10[2],out[3]=a10[3]-b10[3],out}function multiply6(out,a10,b10){return out[0]=a10[0]*b10[0],out[1]=a10[1]*b10[1],out[2]=a10[2]*b10[2],out[3]=a10[3]*b10[3],out}function divide2(out,a10,b10){return out[0]=a10[0]/b10[0],out[1]=a10[1]/b10[1],out[2]=a10[2]/b10[2],out[3]=a10[3]/b10[3],out}function ceil2(out,a10){return out[0]=Math.ceil(a10[0]),out[1]=Math.ceil(a10[1]),out[2]=Math.ceil(a10[2]),out[3]=Math.ceil(a10[3]),out}function floor2(out,a10){return out[0]=Math.floor(a10[0]),out[1]=Math.floor(a10[1]),out[2]=Math.floor(a10[2]),out[3]=Math.floor(a10[3]),out}function min2(out,a10,b10){return out[0]=Math.min(a10[0],b10[0]),out[1]=Math.min(a10[1],b10[1]),out[2]=Math.min(a10[2],b10[2]),out[3]=Math.min(a10[3],b10[3]),out}function max2(out,a10,b10){return out[0]=Math.max(a10[0],b10[0]),out[1]=Math.max(a10[1],b10[1]),out[2]=Math.max(a10[2],b10[2]),out[3]=Math.max(a10[3],b10[3]),out}function round3(out,a10){return out[0]=round(a10[0]),out[1]=round(a10[1]),out[2]=round(a10[2]),out[3]=round(a10[3]),out}function scale8(out,a10,b10){return out[0]=a10[0]*b10,out[1]=a10[1]*b10,out[2]=a10[2]*b10,out[3]=a10[3]*b10,out}function scaleAndAdd2(out,a10,b10,scale15){return out[0]=a10[0]+b10[0]*scale15,out[1]=a10[1]+b10[1]*scale15,out[2]=a10[2]+b10[2]*scale15,out[3]=a10[3]+b10[3]*scale15,out}function distance6(a10,b10){var x11=b10[0]-a10[0],y11=b10[1]-a10[1],z10=b10[2]-a10[2],w10=b10[3]-a10[3];return Math.sqrt(x11*x11+y11*y11+z10*z10+w10*w10)}function squaredDistance2(a10,b10){var x11=b10[0]-a10[0],y11=b10[1]-a10[1],z10=b10[2]-a10[2],w10=b10[3]-a10[3];return x11*x11+y11*y11+z10*z10+w10*w10}function length4(a10){var x11=a10[0],y11=a10[1],z10=a10[2],w10=a10[3];return Math.sqrt(x11*x11+y11*y11+z10*z10+w10*w10)}function squaredLength2(a10){var x11=a10[0],y11=a10[1],z10=a10[2],w10=a10[3];return x11*x11+y11*y11+z10*z10+w10*w10}function negate2(out,a10){return out[0]=-a10[0],out[1]=-a10[1],out[2]=-a10[2],out[3]=-a10[3],out}function inverse4(out,a10){return out[0]=1/a10[0],out[1]=1/a10[1],out[2]=1/a10[2],out[3]=1/a10[3],out}function normalize2(out,a10){var x11=a10[0],y11=a10[1],z10=a10[2],w10=a10[3],len6=x11*x11+y11*y11+z10*z10+w10*w10;return len6>0&&(len6=1/Math.sqrt(len6)),out[0]=x11*len6,out[1]=y11*len6,out[2]=z10*len6,out[3]=w10*len6,out}function dot2(a10,b10){return a10[0]*b10[0]+a10[1]*b10[1]+a10[2]*b10[2]+a10[3]*b10[3]}function cross2(out,u5,v11,w10){var A10=v11[0]*w10[1]-v11[1]*w10[0],B11=v11[0]*w10[2]-v11[2]*w10[0],C11=v11[0]*w10[3]-v11[3]*w10[0],D11=v11[1]*w10[2]-v11[2]*w10[1],E11=v11[1]*w10[3]-v11[3]*w10[1],F11=v11[2]*w10[3]-v11[3]*w10[2],G11=u5[0],H11=u5[1],I11=u5[2],J11=u5[3];return out[0]=H11*F11-I11*E11+J11*D11,out[1]=-(G11*F11)+I11*C11-J11*B11,out[2]=G11*E11-H11*C11+J11*A10,out[3]=-(G11*D11)+H11*B11-I11*A10,out}function lerp2(out,a10,b10,t48){var ax4=a10[0],ay4=a10[1],az2=a10[2],aw3=a10[3];return out[0]=ax4+t48*(b10[0]-ax4),out[1]=ay4+t48*(b10[1]-ay4),out[2]=az2+t48*(b10[2]-az2),out[3]=aw3+t48*(b10[3]-aw3),out}function random2(out,scale15){scale15=scale15===void 0?1:scale15;var v12,v22,v32,v43,s12,s22,rand;rand=RANDOM(),v12=rand*2-1,v22=(4*RANDOM()-2)*Math.sqrt(rand*-rand+rand),s12=v12*v12+v22*v22,rand=RANDOM(),v32=rand*2-1,v43=(4*RANDOM()-2)*Math.sqrt(rand*-rand+rand),s22=v32*v32+v43*v43;var d11=Math.sqrt((1-s12)/s22);return out[0]=scale15*v12,out[1]=scale15*v22,out[2]=scale15*v32*d11,out[3]=scale15*v43*d11,out}function transformMat42(out,a10,m5){var x11=a10[0],y11=a10[1],z10=a10[2],w10=a10[3];return out[0]=m5[0]*x11+m5[4]*y11+m5[8]*z10+m5[12]*w10,out[1]=m5[1]*x11+m5[5]*y11+m5[9]*z10+m5[13]*w10,out[2]=m5[2]*x11+m5[6]*y11+m5[10]*z10+m5[14]*w10,out[3]=m5[3]*x11+m5[7]*y11+m5[11]*z10+m5[15]*w10,out}function transformQuat2(out,a10,q11){var qx4=q11[0],qy4=q11[1],qz2=q11[2],qw3=q11[3],vx4=a10[0],vy4=a10[1],vz2=a10[2],tx4=qy4*vz2-qz2*vy4,ty4=qz2*vx4-qx4*vz2,tz2=qx4*vy4-qy4*vx4;return tx4=tx4+tx4,ty4=ty4+ty4,tz2=tz2+tz2,out[0]=vx4+qw3*tx4+qy4*tz2-qz2*ty4,out[1]=vy4+qw3*ty4+qz2*tx4-qx4*tz2,out[2]=vz2+qw3*tz2+qx4*ty4-qy4*tx4,out[3]=a10[3],out}function zero2(out){return out[0]=0,out[1]=0,out[2]=0,out[3]=0,out}function str6(a10){return"vec4("+a10[0]+", "+a10[1]+", "+a10[2]+", "+a10[3]+")"}function exactEquals6(a10,b10){return a10[0]===b10[0]&&a10[1]===b10[1]&&a10[2]===b10[2]&&a10[3]===b10[3]}function equals7(a10,b10){var a03=a10[0],a12=a10[1],a22=a10[2],a32=a10[3],b03=b10[0],b12=b10[1],b22=b10[2],b32=b10[3];return Math.abs(a03-b03)<=EPSILON*Math.max(1,Math.abs(a03),Math.abs(b03))&&Math.abs(a12-b12)<=EPSILON*Math.max(1,Math.abs(a12),Math.abs(b12))&&Math.abs(a22-b22)<=EPSILON*Math.max(1,Math.abs(a22),Math.abs(b22))&&Math.abs(a32-b32)<=EPSILON*Math.max(1,Math.abs(a32),Math.abs(b32))}var sub6,mul6,div2,dist2,sqrDist2,len2,sqrLen2,forEach2,init_vec4=__esm({"node_modules/gl-matrix/esm/vec4.js"(){"use strict";init_common();sub6=subtract7,mul6=multiply6,div2=divide2,dist2=distance6,sqrDist2=squaredDistance2,len2=length4,sqrLen2=squaredLength2,forEach2=(function(){var vec=create6();return function(a10,stride,offset2,count,fn3,arg){var i11,l10;for(stride||(stride=4),offset2||(offset2=0),count?l10=Math.min(count*stride+offset2,a10.length):l10=a10.length,i11=offset2;i11<l10;i11+=stride)vec[0]=a10[i11],vec[1]=a10[i11+1],vec[2]=a10[i11+2],vec[3]=a10[i11+3],fn3(vec,vec,arg),a10[i11]=vec[0],a10[i11+1]=vec[1],a10[i11+2]=vec[2],a10[i11+3]=vec[3];return a10}})()}});var quat_exports={};__export(quat_exports,{add:()=>add7,calculateW:()=>calculateW,clone:()=>clone7,conjugate:()=>conjugate,copy:()=>copy7,create:()=>create7,dot:()=>dot3,equals:()=>equals8,exactEquals:()=>exactEquals7,exp:()=>exp,fromEuler:()=>fromEuler,fromMat3:()=>fromMat3,fromValues:()=>fromValues8,getAngle:()=>getAngle,getAxisAngle:()=>getAxisAngle,identity:()=>identity6,invert:()=>invert5,len:()=>len3,length:()=>length5,lerp:()=>lerp3,ln:()=>ln2,mul:()=>mul7,multiply:()=>multiply7,normalize:()=>normalize3,pow:()=>pow,random:()=>random3,rotateX:()=>rotateX3,rotateY:()=>rotateY3,rotateZ:()=>rotateZ3,rotationTo:()=>rotationTo,scale:()=>scale9,set:()=>set7,setAxes:()=>setAxes,setAxisAngle:()=>setAxisAngle,slerp:()=>slerp2,sqlerp:()=>sqlerp,sqrLen:()=>sqrLen3,squaredLength:()=>squaredLength3,str:()=>str7});function create7(){var out=new ARRAY_TYPE(4);return ARRAY_TYPE!=Float32Array&&(out[0]=0,out[1]=0,out[2]=0),out[3]=1,out}function identity6(out){return out[0]=0,out[1]=0,out[2]=0,out[3]=1,out}function setAxisAngle(out,axis,rad){rad=rad*.5;var s11=Math.sin(rad);return out[0]=s11*axis[0],out[1]=s11*axis[1],out[2]=s11*axis[2],out[3]=Math.cos(rad),out}function getAxisAngle(out_axis,q11){var rad=Math.acos(q11[3])*2,s11=Math.sin(rad/2);return s11>EPSILON?(out_axis[0]=q11[0]/s11,out_axis[1]=q11[1]/s11,out_axis[2]=q11[2]/s11):(out_axis[0]=1,out_axis[1]=0,out_axis[2]=0),rad}function getAngle(a10,b10){var dotproduct=dot3(a10,b10);return Math.acos(2*dotproduct*dotproduct-1)}function multiply7(out,a10,b10){var ax4=a10[0],ay4=a10[1],az2=a10[2],aw3=a10[3],bx4=b10[0],by4=b10[1],bz2=b10[2],bw4=b10[3];return out[0]=ax4*bw4+aw3*bx4+ay4*bz2-az2*by4,out[1]=ay4*bw4+aw3*by4+az2*bx4-ax4*bz2,out[2]=az2*bw4+aw3*bz2+ax4*by4-ay4*bx4,out[3]=aw3*bw4-ax4*bx4-ay4*by4-az2*bz2,out}function rotateX3(out,a10,rad){rad*=.5;var ax4=a10[0],ay4=a10[1],az2=a10[2],aw3=a10[3],bx4=Math.sin(rad),bw4=Math.cos(rad);return out[0]=ax4*bw4+aw3*bx4,out[1]=ay4*bw4+az2*bx4,out[2]=az2*bw4-ay4*bx4,out[3]=aw3*bw4-ax4*bx4,out}function rotateY3(out,a10,rad){rad*=.5;var ax4=a10[0],ay4=a10[1],az2=a10[2],aw3=a10[3],by4=Math.sin(rad),bw4=Math.cos(rad);return out[0]=ax4*bw4-az2*by4,out[1]=ay4*bw4+aw3*by4,out[2]=az2*bw4+ax4*by4,out[3]=aw3*bw4-ay4*by4,out}function rotateZ3(out,a10,rad){rad*=.5;var ax4=a10[0],ay4=a10[1],az2=a10[2],aw3=a10[3],bz2=Math.sin(rad),bw4=Math.cos(rad);return out[0]=ax4*bw4+ay4*bz2,out[1]=ay4*bw4-ax4*bz2,out[2]=az2*bw4+aw3*bz2,out[3]=aw3*bw4-az2*bz2,out}function calculateW(out,a10){var x11=a10[0],y11=a10[1],z10=a10[2];return out[0]=x11,out[1]=y11,out[2]=z10,out[3]=Math.sqrt(Math.abs(1-x11*x11-y11*y11-z10*z10)),out}function exp(out,a10){var x11=a10[0],y11=a10[1],z10=a10[2],w10=a10[3],r11=Math.sqrt(x11*x11+y11*y11+z10*z10),et5=Math.exp(w10),s11=r11>0?et5*Math.sin(r11)/r11:0;return out[0]=x11*s11,out[1]=y11*s11,out[2]=z10*s11,out[3]=et5*Math.cos(r11),out}function ln2(out,a10){var x11=a10[0],y11=a10[1],z10=a10[2],w10=a10[3],r11=Math.sqrt(x11*x11+y11*y11+z10*z10),t48=r11>0?Math.atan2(r11,w10)/r11:0;return out[0]=x11*t48,out[1]=y11*t48,out[2]=z10*t48,out[3]=.5*Math.log(x11*x11+y11*y11+z10*z10+w10*w10),out}function pow(out,a10,b10){return ln2(out,a10),scale9(out,out,b10),exp(out,out),out}function slerp2(out,a10,b10,t48){var ax4=a10[0],ay4=a10[1],az2=a10[2],aw3=a10[3],bx4=b10[0],by4=b10[1],bz2=b10[2],bw4=b10[3],omega,cosom,sinom,scale0,scale1;return cosom=ax4*bx4+ay4*by4+az2*bz2+aw3*bw4,cosom<0&&(cosom=-cosom,bx4=-bx4,by4=-by4,bz2=-bz2,bw4=-bw4),1-cosom>EPSILON?(omega=Math.acos(cosom),sinom=Math.sin(omega),scale0=Math.sin((1-t48)*omega)/sinom,scale1=Math.sin(t48*omega)/sinom):(scale0=1-t48,scale1=t48),out[0]=scale0*ax4+scale1*bx4,out[1]=scale0*ay4+scale1*by4,out[2]=scale0*az2+scale1*bz2,out[3]=scale0*aw3+scale1*bw4,out}function random3(out){var u12=RANDOM(),u22=RANDOM(),u32=RANDOM(),sqrt1MinusU1=Math.sqrt(1-u12),sqrtU1=Math.sqrt(u12);return out[0]=sqrt1MinusU1*Math.sin(2*Math.PI*u22),out[1]=sqrt1MinusU1*Math.cos(2*Math.PI*u22),out[2]=sqrtU1*Math.sin(2*Math.PI*u32),out[3]=sqrtU1*Math.cos(2*Math.PI*u32),out}function invert5(out,a10){var a03=a10[0],a12=a10[1],a22=a10[2],a32=a10[3],dot10=a03*a03+a12*a12+a22*a22+a32*a32,invDot=dot10?1/dot10:0;return out[0]=-a03*invDot,out[1]=-a12*invDot,out[2]=-a22*invDot,out[3]=a32*invDot,out}function conjugate(out,a10){return out[0]=-a10[0],out[1]=-a10[1],out[2]=-a10[2],out[3]=a10[3],out}function fromMat3(out,m5){var fTrace=m5[0]+m5[4]+m5[8],fRoot;if(fTrace>0)fRoot=Math.sqrt(fTrace+1),out[3]=.5*fRoot,fRoot=.5/fRoot,out[0]=(m5[5]-m5[7])*fRoot,out[1]=(m5[6]-m5[2])*fRoot,out[2]=(m5[1]-m5[3])*fRoot;else{var i11=0;m5[4]>m5[0]&&(i11=1),m5[8]>m5[i11*3+i11]&&(i11=2);var j11=(i11+1)%3,k11=(i11+2)%3;fRoot=Math.sqrt(m5[i11*3+i11]-m5[j11*3+j11]-m5[k11*3+k11]+1),out[i11]=.5*fRoot,fRoot=.5/fRoot,out[3]=(m5[j11*3+k11]-m5[k11*3+j11])*fRoot,out[j11]=(m5[j11*3+i11]+m5[i11*3+j11])*fRoot,out[k11]=(m5[k11*3+i11]+m5[i11*3+k11])*fRoot}return out}function fromEuler(out,x11,y11,z10){var order=arguments.length>4&&arguments[4]!==void 0?arguments[4]:ANGLE_ORDER,halfToRad=Math.PI/360;x11*=halfToRad,z10*=halfToRad,y11*=halfToRad;var sx4=Math.sin(x11),cx4=Math.cos(x11),sy4=Math.sin(y11),cy4=Math.cos(y11),sz2=Math.sin(z10),cz2=Math.cos(z10);switch(order){case"xyz":out[0]=sx4*cy4*cz2+cx4*sy4*sz2,out[1]=cx4*sy4*cz2-sx4*cy4*sz2,out[2]=cx4*cy4*sz2+sx4*sy4*cz2,out[3]=cx4*cy4*cz2-sx4*sy4*sz2;break;case"xzy":out[0]=sx4*cy4*cz2-cx4*sy4*sz2,out[1]=cx4*sy4*cz2-sx4*cy4*sz2,out[2]=cx4*cy4*sz2+sx4*sy4*cz2,out[3]=cx4*cy4*cz2+sx4*sy4*sz2;break;case"yxz":out[0]=sx4*cy4*cz2+cx4*sy4*sz2,out[1]=cx4*sy4*cz2-sx4*cy4*sz2,out[2]=cx4*cy4*sz2-sx4*sy4*cz2,out[3]=cx4*cy4*cz2+sx4*sy4*sz2;break;case"yzx":out[0]=sx4*cy4*cz2+cx4*sy4*sz2,out[1]=cx4*sy4*cz2+sx4*cy4*sz2,out[2]=cx4*cy4*sz2-sx4*sy4*cz2,out[3]=cx4*cy4*cz2-sx4*sy4*sz2;break;case"zxy":out[0]=sx4*cy4*cz2-cx4*sy4*sz2,out[1]=cx4*sy4*cz2+sx4*cy4*sz2,out[2]=cx4*cy4*sz2+sx4*sy4*cz2,out[3]=cx4*cy4*cz2-sx4*sy4*sz2;break;case"zyx":out[0]=sx4*cy4*cz2-cx4*sy4*sz2,out[1]=cx4*sy4*cz2+sx4*cy4*sz2,out[2]=cx4*cy4*sz2-sx4*sy4*cz2,out[3]=cx4*cy4*cz2+sx4*sy4*sz2;break;default:throw new Error("Unknown angle order "+order)}return out}function str7(a10){return"quat("+a10[0]+", "+a10[1]+", "+a10[2]+", "+a10[3]+")"}function equals8(a10,b10){return Math.abs(dot2(a10,b10))>=1-EPSILON}var clone7,fromValues8,copy7,set7,add7,mul7,scale9,dot3,lerp3,length5,len3,squaredLength3,sqrLen3,normalize3,exactEquals7,rotationTo,sqlerp,setAxes,init_quat=__esm({"node_modules/gl-matrix/esm/quat.js"(){"use strict";init_common();init_mat3();init_vec3();init_vec4();clone7=clone6,fromValues8=fromValues7,copy7=copy6,set7=set6,add7=add6,mul7=multiply7,scale9=scale8,dot3=dot2,lerp3=lerp2,length5=length4,len3=length5,squaredLength3=squaredLength2,sqrLen3=squaredLength3,normalize3=normalize2,exactEquals7=exactEquals6;rotationTo=(function(){var tmpvec3=create5(),xUnitVec3=fromValues6(1,0,0),yUnitVec3=fromValues6(0,1,0);return function(out,a10,b10){var dot10=dot(a10,b10);return dot10<-.999999?(cross(tmpvec3,xUnitVec3,a10),len(tmpvec3)<1e-6&&cross(tmpvec3,yUnitVec3,a10),normalize(tmpvec3,tmpvec3),setAxisAngle(out,tmpvec3,Math.PI),out):dot10>.999999?(out[0]=0,out[1]=0,out[2]=0,out[3]=1,out):(cross(tmpvec3,a10,b10),out[0]=tmpvec3[0],out[1]=tmpvec3[1],out[2]=tmpvec3[2],out[3]=1+dot10,normalize3(out,out))}})(),sqlerp=(function(){var temp1=create7(),temp2=create7();return function(out,a10,b10,c10,d11,t48){return slerp2(temp1,a10,d11,t48),slerp2(temp2,b10,c10,t48),slerp2(out,temp1,temp2,2*t48*(1-t48)),out}})(),setAxes=(function(){var matr=create3();return function(out,view,right,up4){return matr[0]=right[0],matr[3]=right[1],matr[6]=right[2],matr[1]=up4[0],matr[4]=up4[1],matr[7]=up4[2],matr[2]=-view[0],matr[5]=-view[1],matr[8]=-view[2],normalize3(out,fromMat3(out,matr))}})()}});var quat2_exports={};__export(quat2_exports,{add:()=>add8,clone:()=>clone8,conjugate:()=>conjugate2,copy:()=>copy8,create:()=>create8,dot:()=>dot4,equals:()=>equals9,exactEquals:()=>exactEquals8,fromMat4:()=>fromMat42,fromRotation:()=>fromRotation5,fromRotationTranslation:()=>fromRotationTranslation2,fromRotationTranslationValues:()=>fromRotationTranslationValues,fromTranslation:()=>fromTranslation4,fromValues:()=>fromValues9,getDual:()=>getDual,getReal:()=>getReal,getTranslation:()=>getTranslation2,identity:()=>identity7,invert:()=>invert6,len:()=>len4,length:()=>length6,lerp:()=>lerp4,mul:()=>mul8,multiply:()=>multiply8,normalize:()=>normalize4,rotateAroundAxis:()=>rotateAroundAxis,rotateByQuatAppend:()=>rotateByQuatAppend,rotateByQuatPrepend:()=>rotateByQuatPrepend,rotateX:()=>rotateX4,rotateY:()=>rotateY4,rotateZ:()=>rotateZ4,scale:()=>scale10,set:()=>set8,setDual:()=>setDual,setReal:()=>setReal,sqrLen:()=>sqrLen4,squaredLength:()=>squaredLength4,str:()=>str8,translate:()=>translate6});function create8(){var dq2=new ARRAY_TYPE(8);return ARRAY_TYPE!=Float32Array&&(dq2[0]=0,dq2[1]=0,dq2[2]=0,dq2[4]=0,dq2[5]=0,dq2[6]=0,dq2[7]=0),dq2[3]=1,dq2}function clone8(a10){var dq2=new ARRAY_TYPE(8);return dq2[0]=a10[0],dq2[1]=a10[1],dq2[2]=a10[2],dq2[3]=a10[3],dq2[4]=a10[4],dq2[5]=a10[5],dq2[6]=a10[6],dq2[7]=a10[7],dq2}function fromValues9(x12,y12,z12,w12,x22,y22,z22,w22){var dq2=new ARRAY_TYPE(8);return dq2[0]=x12,dq2[1]=y12,dq2[2]=z12,dq2[3]=w12,dq2[4]=x22,dq2[5]=y22,dq2[6]=z22,dq2[7]=w22,dq2}function fromRotationTranslationValues(x12,y12,z12,w12,x22,y22,z22){var dq2=new ARRAY_TYPE(8);dq2[0]=x12,dq2[1]=y12,dq2[2]=z12,dq2[3]=w12;var ax4=x22*.5,ay4=y22*.5,az2=z22*.5;return dq2[4]=ax4*w12+ay4*z12-az2*y12,dq2[5]=ay4*w12+az2*x12-ax4*z12,dq2[6]=az2*w12+ax4*y12-ay4*x12,dq2[7]=-ax4*x12-ay4*y12-az2*z12,dq2}function fromRotationTranslation2(out,q11,t48){var ax4=t48[0]*.5,ay4=t48[1]*.5,az2=t48[2]*.5,bx4=q11[0],by4=q11[1],bz2=q11[2],bw4=q11[3];return out[0]=bx4,out[1]=by4,out[2]=bz2,out[3]=bw4,out[4]=ax4*bw4+ay4*bz2-az2*by4,out[5]=ay4*bw4+az2*bx4-ax4*bz2,out[6]=az2*bw4+ax4*by4-ay4*bx4,out[7]=-ax4*bx4-ay4*by4-az2*bz2,out}function fromTranslation4(out,t48){return out[0]=0,out[1]=0,out[2]=0,out[3]=1,out[4]=t48[0]*.5,out[5]=t48[1]*.5,out[6]=t48[2]*.5,out[7]=0,out}function fromRotation5(out,q11){return out[0]=q11[0],out[1]=q11[1],out[2]=q11[2],out[3]=q11[3],out[4]=0,out[5]=0,out[6]=0,out[7]=0,out}function fromMat42(out,a10){var outer=create7();getRotation(outer,a10);var t48=new ARRAY_TYPE(3);return getTranslation(t48,a10),fromRotationTranslation2(out,outer,t48),out}function copy8(out,a10){return out[0]=a10[0],out[1]=a10[1],out[2]=a10[2],out[3]=a10[3],out[4]=a10[4],out[5]=a10[5],out[6]=a10[6],out[7]=a10[7],out}function identity7(out){return out[0]=0,out[1]=0,out[2]=0,out[3]=1,out[4]=0,out[5]=0,out[6]=0,out[7]=0,out}function set8(out,x12,y12,z12,w12,x22,y22,z22,w22){return out[0]=x12,out[1]=y12,out[2]=z12,out[3]=w12,out[4]=x22,out[5]=y22,out[6]=z22,out[7]=w22,out}function getDual(out,a10){return out[0]=a10[4],out[1]=a10[5],out[2]=a10[6],out[3]=a10[7],out}function setDual(out,q11){return out[4]=q11[0],out[5]=q11[1],out[6]=q11[2],out[7]=q11[3],out}function getTranslation2(out,a10){var ax4=a10[4],ay4=a10[5],az2=a10[6],aw3=a10[7],bx4=-a10[0],by4=-a10[1],bz2=-a10[2],bw4=a10[3];return out[0]=(ax4*bw4+aw3*bx4+ay4*bz2-az2*by4)*2,out[1]=(ay4*bw4+aw3*by4+az2*bx4-ax4*bz2)*2,out[2]=(az2*bw4+aw3*bz2+ax4*by4-ay4*bx4)*2,out}function translate6(out,a10,v11){var ax1=a10[0],ay1=a10[1],az1=a10[2],aw1=a10[3],bx1=v11[0]*.5,by1=v11[1]*.5,bz1=v11[2]*.5,ax22=a10[4],ay22=a10[5],az2=a10[6],aw22=a10[7];return out[0]=ax1,out[1]=ay1,out[2]=az1,out[3]=aw1,out[4]=aw1*bx1+ay1*bz1-az1*by1+ax22,out[5]=aw1*by1+az1*bx1-ax1*bz1+ay22,out[6]=aw1*bz1+ax1*by1-ay1*bx1+az2,out[7]=-ax1*bx1-ay1*by1-az1*bz1+aw22,out}function rotateX4(out,a10,rad){var bx4=-a10[0],by4=-a10[1],bz2=-a10[2],bw4=a10[3],ax4=a10[4],ay4=a10[5],az2=a10[6],aw3=a10[7],ax1=ax4*bw4+aw3*bx4+ay4*bz2-az2*by4,ay1=ay4*bw4+aw3*by4+az2*bx4-ax4*bz2,az1=az2*bw4+aw3*bz2+ax4*by4-ay4*bx4,aw1=aw3*bw4-ax4*bx4-ay4*by4-az2*bz2;return rotateX3(out,a10,rad),bx4=out[0],by4=out[1],bz2=out[2],bw4=out[3],out[4]=ax1*bw4+aw1*bx4+ay1*bz2-az1*by4,out[5]=ay1*bw4+aw1*by4+az1*bx4-ax1*bz2,out[6]=az1*bw4+aw1*bz2+ax1*by4-ay1*bx4,out[7]=aw1*bw4-ax1*bx4-ay1*by4-az1*bz2,out}function rotateY4(out,a10,rad){var bx4=-a10[0],by4=-a10[1],bz2=-a10[2],bw4=a10[3],ax4=a10[4],ay4=a10[5],az2=a10[6],aw3=a10[7],ax1=ax4*bw4+aw3*bx4+ay4*bz2-az2*by4,ay1=ay4*bw4+aw3*by4+az2*bx4-ax4*bz2,az1=az2*bw4+aw3*bz2+ax4*by4-ay4*bx4,aw1=aw3*bw4-ax4*bx4-ay4*by4-az2*bz2;return rotateY3(out,a10,rad),bx4=out[0],by4=out[1],bz2=out[2],bw4=out[3],out[4]=ax1*bw4+aw1*bx4+ay1*bz2-az1*by4,out[5]=ay1*bw4+aw1*by4+az1*bx4-ax1*bz2,out[6]=az1*bw4+aw1*bz2+ax1*by4-ay1*bx4,out[7]=aw1*bw4-ax1*bx4-ay1*by4-az1*bz2,out}function rotateZ4(out,a10,rad){var bx4=-a10[0],by4=-a10[1],bz2=-a10[2],bw4=a10[3],ax4=a10[4],ay4=a10[5],az2=a10[6],aw3=a10[7],ax1=ax4*bw4+aw3*bx4+ay4*bz2-az2*by4,ay1=ay4*bw4+aw3*by4+az2*bx4-ax4*bz2,az1=az2*bw4+aw3*bz2+ax4*by4-ay4*bx4,aw1=aw3*bw4-ax4*bx4-ay4*by4-az2*bz2;return rotateZ3(out,a10,rad),bx4=out[0],by4=out[1],bz2=out[2],bw4=out[3],out[4]=ax1*bw4+aw1*bx4+ay1*bz2-az1*by4,out[5]=ay1*bw4+aw1*by4+az1*bx4-ax1*bz2,out[6]=az1*bw4+aw1*bz2+ax1*by4-ay1*bx4,out[7]=aw1*bw4-ax1*bx4-ay1*by4-az1*bz2,out}function rotateByQuatAppend(out,a10,q11){var qx4=q11[0],qy4=q11[1],qz2=q11[2],qw3=q11[3],ax4=a10[0],ay4=a10[1],az2=a10[2],aw3=a10[3];return out[0]=ax4*qw3+aw3*qx4+ay4*qz2-az2*qy4,out[1]=ay4*qw3+aw3*qy4+az2*qx4-ax4*qz2,out[2]=az2*qw3+aw3*qz2+ax4*qy4-ay4*qx4,out[3]=aw3*qw3-ax4*qx4-ay4*qy4-az2*qz2,ax4=a10[4],ay4=a10[5],az2=a10[6],aw3=a10[7],out[4]=ax4*qw3+aw3*qx4+ay4*qz2-az2*qy4,out[5]=ay4*qw3+aw3*qy4+az2*qx4-ax4*qz2,out[6]=az2*qw3+aw3*qz2+ax4*qy4-ay4*qx4,out[7]=aw3*qw3-ax4*qx4-ay4*qy4-az2*qz2,out}function rotateByQuatPrepend(out,q11,a10){var qx4=q11[0],qy4=q11[1],qz2=q11[2],qw3=q11[3],bx4=a10[0],by4=a10[1],bz2=a10[2],bw4=a10[3];return out[0]=qx4*bw4+qw3*bx4+qy4*bz2-qz2*by4,out[1]=qy4*bw4+qw3*by4+qz2*bx4-qx4*bz2,out[2]=qz2*bw4+qw3*bz2+qx4*by4-qy4*bx4,out[3]=qw3*bw4-qx4*bx4-qy4*by4-qz2*bz2,bx4=a10[4],by4=a10[5],bz2=a10[6],bw4=a10[7],out[4]=qx4*bw4+qw3*bx4+qy4*bz2-qz2*by4,out[5]=qy4*bw4+qw3*by4+qz2*bx4-qx4*bz2,out[6]=qz2*bw4+qw3*bz2+qx4*by4-qy4*bx4,out[7]=qw3*bw4-qx4*bx4-qy4*by4-qz2*bz2,out}function rotateAroundAxis(out,a10,axis,rad){if(Math.abs(rad)<EPSILON)return copy8(out,a10);var axisLength=Math.sqrt(axis[0]*axis[0]+axis[1]*axis[1]+axis[2]*axis[2]);rad=rad*.5;var s11=Math.sin(rad),bx4=s11*axis[0]/axisLength,by4=s11*axis[1]/axisLength,bz2=s11*axis[2]/axisLength,bw4=Math.cos(rad),ax1=a10[0],ay1=a10[1],az1=a10[2],aw1=a10[3];out[0]=ax1*bw4+aw1*bx4+ay1*bz2-az1*by4,out[1]=ay1*bw4+aw1*by4+az1*bx4-ax1*bz2,out[2]=az1*bw4+aw1*bz2+ax1*by4-ay1*bx4,out[3]=aw1*bw4-ax1*bx4-ay1*by4-az1*bz2;var ax4=a10[4],ay4=a10[5],az2=a10[6],aw3=a10[7];return out[4]=ax4*bw4+aw3*bx4+ay4*bz2-az2*by4,out[5]=ay4*bw4+aw3*by4+az2*bx4-ax4*bz2,out[6]=az2*bw4+aw3*bz2+ax4*by4-ay4*bx4,out[7]=aw3*bw4-ax4*bx4-ay4*by4-az2*bz2,out}function add8(out,a10,b10){return out[0]=a10[0]+b10[0],out[1]=a10[1]+b10[1],out[2]=a10[2]+b10[2],out[3]=a10[3]+b10[3],out[4]=a10[4]+b10[4],out[5]=a10[5]+b10[5],out[6]=a10[6]+b10[6],out[7]=a10[7]+b10[7],out}function multiply8(out,a10,b10){var ax0=a10[0],ay0=a10[1],az0=a10[2],aw0=a10[3],bx1=b10[4],by1=b10[5],bz1=b10[6],bw1=b10[7],ax1=a10[4],ay1=a10[5],az1=a10[6],aw1=a10[7],bx0=b10[0],by0=b10[1],bz0=b10[2],bw0=b10[3];return out[0]=ax0*bw0+aw0*bx0+ay0*bz0-az0*by0,out[1]=ay0*bw0+aw0*by0+az0*bx0-ax0*bz0,out[2]=az0*bw0+aw0*bz0+ax0*by0-ay0*bx0,out[3]=aw0*bw0-ax0*bx0-ay0*by0-az0*bz0,out[4]=ax0*bw1+aw0*bx1+ay0*bz1-az0*by1+ax1*bw0+aw1*bx0+ay1*bz0-az1*by0,out[5]=ay0*bw1+aw0*by1+az0*bx1-ax0*bz1+ay1*bw0+aw1*by0+az1*bx0-ax1*bz0,out[6]=az0*bw1+aw0*bz1+ax0*by1-ay0*bx1+az1*bw0+aw1*bz0+ax1*by0-ay1*bx0,out[7]=aw0*bw1-ax0*bx1-ay0*by1-az0*bz1+aw1*bw0-ax1*bx0-ay1*by0-az1*bz0,out}function scale10(out,a10,b10){return out[0]=a10[0]*b10,out[1]=a10[1]*b10,out[2]=a10[2]*b10,out[3]=a10[3]*b10,out[4]=a10[4]*b10,out[5]=a10[5]*b10,out[6]=a10[6]*b10,out[7]=a10[7]*b10,out}function lerp4(out,a10,b10,t48){var mt5=1-t48;return dot4(a10,b10)<0&&(t48=-t48),out[0]=a10[0]*mt5+b10[0]*t48,out[1]=a10[1]*mt5+b10[1]*t48,out[2]=a10[2]*mt5+b10[2]*t48,out[3]=a10[3]*mt5+b10[3]*t48,out[4]=a10[4]*mt5+b10[4]*t48,out[5]=a10[5]*mt5+b10[5]*t48,out[6]=a10[6]*mt5+b10[6]*t48,out[7]=a10[7]*mt5+b10[7]*t48,out}function invert6(out,a10){var sqlen=squaredLength4(a10);return out[0]=-a10[0]/sqlen,out[1]=-a10[1]/sqlen,out[2]=-a10[2]/sqlen,out[3]=a10[3]/sqlen,out[4]=-a10[4]/sqlen,out[5]=-a10[5]/sqlen,out[6]=-a10[6]/sqlen,out[7]=a10[7]/sqlen,out}function conjugate2(out,a10){return out[0]=-a10[0],out[1]=-a10[1],out[2]=-a10[2],out[3]=a10[3],out[4]=-a10[4],out[5]=-a10[5],out[6]=-a10[6],out[7]=a10[7],out}function normalize4(out,a10){var magnitude=squaredLength4(a10);if(magnitude>0){magnitude=Math.sqrt(magnitude);var a03=a10[0]/magnitude,a12=a10[1]/magnitude,a22=a10[2]/magnitude,a32=a10[3]/magnitude,b03=a10[4],b12=a10[5],b22=a10[6],b32=a10[7],a_dot_b=a03*b03+a12*b12+a22*b22+a32*b32;out[0]=a03,out[1]=a12,out[2]=a22,out[3]=a32,out[4]=(b03-a03*a_dot_b)/magnitude,out[5]=(b12-a12*a_dot_b)/magnitude,out[6]=(b22-a22*a_dot_b)/magnitude,out[7]=(b32-a32*a_dot_b)/magnitude}return out}function str8(a10){return"quat2("+a10[0]+", "+a10[1]+", "+a10[2]+", "+a10[3]+", "+a10[4]+", "+a10[5]+", "+a10[6]+", "+a10[7]+")"}function exactEquals8(a10,b10){return a10[0]===b10[0]&&a10[1]===b10[1]&&a10[2]===b10[2]&&a10[3]===b10[3]&&a10[4]===b10[4]&&a10[5]===b10[5]&&a10[6]===b10[6]&&a10[7]===b10[7]}function equals9(a10,b10){var a03=a10[0],a12=a10[1],a22=a10[2],a32=a10[3],a42=a10[4],a52=a10[5],a62=a10[6],a72=a10[7],b03=b10[0],b12=b10[1],b22=b10[2],b32=b10[3],b43=b10[4],b52=b10[5],b62=b10[6],b72=b10[7];return Math.abs(a03-b03)<=EPSILON*Math.max(1,Math.abs(a03),Math.abs(b03))&&Math.abs(a12-b12)<=EPSILON*Math.max(1,Math.abs(a12),Math.abs(b12))&&Math.abs(a22-b22)<=EPSILON*Math.max(1,Math.abs(a22),Math.abs(b22))&&Math.abs(a32-b32)<=EPSILON*Math.max(1,Math.abs(a32),Math.abs(b32))&&Math.abs(a42-b43)<=EPSILON*Math.max(1,Math.abs(a42),Math.abs(b43))&&Math.abs(a52-b52)<=EPSILON*Math.max(1,Math.abs(a52),Math.abs(b52))&&Math.abs(a62-b62)<=EPSILON*Math.max(1,Math.abs(a62),Math.abs(b62))&&Math.abs(a72-b72)<=EPSILON*Math.max(1,Math.abs(a72),Math.abs(b72))}var getReal,setReal,mul8,dot4,length6,len4,squaredLength4,sqrLen4,init_quat2=__esm({"node_modules/gl-matrix/esm/quat2.js"(){"use strict";init_common();init_quat();init_mat4();getReal=copy7;setReal=copy7;mul8=multiply8;dot4=dot3;length6=length5,len4=length6,squaredLength4=squaredLength3,sqrLen4=squaredLength4}});var vec2_exports={};__export(vec2_exports,{add:()=>add9,angle:()=>angle2,ceil:()=>ceil3,clone:()=>clone9,copy:()=>copy9,create:()=>create9,cross:()=>cross3,dist:()=>dist3,distance:()=>distance7,div:()=>div3,divide:()=>divide3,dot:()=>dot5,equals:()=>equals10,exactEquals:()=>exactEquals9,floor:()=>floor3,forEach:()=>forEach3,fromValues:()=>fromValues10,inverse:()=>inverse5,len:()=>len5,length:()=>length7,lerp:()=>lerp5,max:()=>max3,min:()=>min3,mul:()=>mul9,multiply:()=>multiply9,negate:()=>negate3,normalize:()=>normalize5,random:()=>random4,rotate:()=>rotate7,round:()=>round4,scale:()=>scale11,scaleAndAdd:()=>scaleAndAdd3,set:()=>set9,signedAngle:()=>signedAngle,sqrDist:()=>sqrDist3,sqrLen:()=>sqrLen5,squaredDistance:()=>squaredDistance3,squaredLength:()=>squaredLength5,str:()=>str9,sub:()=>sub7,subtract:()=>subtract8,transformMat2:()=>transformMat2,transformMat2d:()=>transformMat2d,transformMat3:()=>transformMat32,transformMat4:()=>transformMat43,zero:()=>zero3});function create9(){var out=new ARRAY_TYPE(2);return ARRAY_TYPE!=Float32Array&&(out[0]=0,out[1]=0),out}function clone9(a10){var out=new ARRAY_TYPE(2);return out[0]=a10[0],out[1]=a10[1],out}function fromValues10(x11,y11){var out=new ARRAY_TYPE(2);return out[0]=x11,out[1]=y11,out}function copy9(out,a10){return out[0]=a10[0],out[1]=a10[1],out}function set9(out,x11,y11){return out[0]=x11,out[1]=y11,out}function add9(out,a10,b10){return out[0]=a10[0]+b10[0],out[1]=a10[1]+b10[1],out}function subtract8(out,a10,b10){return out[0]=a10[0]-b10[0],out[1]=a10[1]-b10[1],out}function multiply9(out,a10,b10){return out[0]=a10[0]*b10[0],out[1]=a10[1]*b10[1],out}function divide3(out,a10,b10){return out[0]=a10[0]/b10[0],out[1]=a10[1]/b10[1],out}function ceil3(out,a10){return out[0]=Math.ceil(a10[0]),out[1]=Math.ceil(a10[1]),out}function floor3(out,a10){return out[0]=Math.floor(a10[0]),out[1]=Math.floor(a10[1]),out}function min3(out,a10,b10){return out[0]=Math.min(a10[0],b10[0]),out[1]=Math.min(a10[1],b10[1]),out}function max3(out,a10,b10){return out[0]=Math.max(a10[0],b10[0]),out[1]=Math.max(a10[1],b10[1]),out}function round4(out,a10){return out[0]=round(a10[0]),out[1]=round(a10[1]),out}function scale11(out,a10,b10){return out[0]=a10[0]*b10,out[1]=a10[1]*b10,out}function scaleAndAdd3(out,a10,b10,scale15){return out[0]=a10[0]+b10[0]*scale15,out[1]=a10[1]+b10[1]*scale15,out}function distance7(a10,b10){var x11=b10[0]-a10[0],y11=b10[1]-a10[1];return Math.sqrt(x11*x11+y11*y11)}function squaredDistance3(a10,b10){var x11=b10[0]-a10[0],y11=b10[1]-a10[1];return x11*x11+y11*y11}function length7(a10){var x11=a10[0],y11=a10[1];return Math.sqrt(x11*x11+y11*y11)}function squaredLength5(a10){var x11=a10[0],y11=a10[1];return x11*x11+y11*y11}function negate3(out,a10){return out[0]=-a10[0],out[1]=-a10[1],out}function inverse5(out,a10){return out[0]=1/a10[0],out[1]=1/a10[1],out}function normalize5(out,a10){var x11=a10[0],y11=a10[1],len6=x11*x11+y11*y11;return len6>0&&(len6=1/Math.sqrt(len6)),out[0]=a10[0]*len6,out[1]=a10[1]*len6,out}function dot5(a10,b10){return a10[0]*b10[0]+a10[1]*b10[1]}function cross3(out,a10,b10){var z10=a10[0]*b10[1]-a10[1]*b10[0];return out[0]=out[1]=0,out[2]=z10,out}function lerp5(out,a10,b10,t48){var ax4=a10[0],ay4=a10[1];return out[0]=ax4+t48*(b10[0]-ax4),out[1]=ay4+t48*(b10[1]-ay4),out}function random4(out,scale15){scale15=scale15===void 0?1:scale15;var r11=RANDOM()*2*Math.PI;return out[0]=Math.cos(r11)*scale15,out[1]=Math.sin(r11)*scale15,out}function transformMat2(out,a10,m5){var x11=a10[0],y11=a10[1];return out[0]=m5[0]*x11+m5[2]*y11,out[1]=m5[1]*x11+m5[3]*y11,out}function transformMat2d(out,a10,m5){var x11=a10[0],y11=a10[1];return out[0]=m5[0]*x11+m5[2]*y11+m5[4],out[1]=m5[1]*x11+m5[3]*y11+m5[5],out}function transformMat32(out,a10,m5){var x11=a10[0],y11=a10[1];return out[0]=m5[0]*x11+m5[3]*y11+m5[6],out[1]=m5[1]*x11+m5[4]*y11+m5[7],out}function transformMat43(out,a10,m5){var x11=a10[0],y11=a10[1];return out[0]=m5[0]*x11+m5[4]*y11+m5[12],out[1]=m5[1]*x11+m5[5]*y11+m5[13],out}function rotate7(out,a10,b10,rad){var p03=a10[0]-b10[0],p12=a10[1]-b10[1],sinC=Math.sin(rad),cosC=Math.cos(rad);return out[0]=p03*cosC-p12*sinC+b10[0],out[1]=p03*sinC+p12*cosC+b10[1],out}function angle2(a10,b10){var ax4=a10[0],ay4=a10[1],bx4=b10[0],by4=b10[1];return Math.abs(Math.atan2(ay4*bx4-ax4*by4,ax4*bx4+ay4*by4))}function signedAngle(a10,b10){var ax4=a10[0],ay4=a10[1],bx4=b10[0],by4=b10[1];return Math.atan2(ax4*by4-ay4*bx4,ax4*bx4+ay4*by4)}function zero3(out){return out[0]=0,out[1]=0,out}function str9(a10){return"vec2("+a10[0]+", "+a10[1]+")"}function exactEquals9(a10,b10){return a10[0]===b10[0]&&a10[1]===b10[1]}function equals10(a10,b10){var a03=a10[0],a12=a10[1],b03=b10[0],b12=b10[1];return Math.abs(a03-b03)<=EPSILON*Math.max(1,Math.abs(a03),Math.abs(b03))&&Math.abs(a12-b12)<=EPSILON*Math.max(1,Math.abs(a12),Math.abs(b12))}var len5,sub7,mul9,div3,dist3,sqrDist3,sqrLen5,forEach3,init_vec2=__esm({"node_modules/gl-matrix/esm/vec2.js"(){"use strict";init_common();len5=length7,sub7=subtract8,mul9=multiply9,div3=divide3,dist3=distance7,sqrDist3=squaredDistance3,sqrLen5=squaredLength5,forEach3=(function(){var vec=create9();return function(a10,stride,offset2,count,fn3,arg){var i11,l10;for(stride||(stride=2),offset2||(offset2=0),count?l10=Math.min(count*stride+offset2,a10.length):l10=a10.length,i11=offset2;i11<l10;i11+=stride)vec[0]=a10[i11],vec[1]=a10[i11+1],fn3(vec,vec,arg),a10[i11]=vec[0],a10[i11+1]=vec[1];return a10}})()}});var esm_exports3={};__export(esm_exports3,{glMatrix:()=>common_exports,mat2:()=>mat2_exports,mat2d:()=>mat2d_exports,mat3:()=>mat3_exports,mat4:()=>mat4_exports,quat:()=>quat_exports,quat2:()=>quat2_exports,vec2:()=>vec2_exports,vec3:()=>vec3_exports,vec4:()=>vec4_exports});var init_esm=__esm({"node_modules/gl-matrix/esm/index.js"(){"use strict";init_common();init_mat2();init_mat2d();init_mat3();init_mat4();init_quat();init_quat2();init_vec2();init_vec3();init_vec4()}});var require_dist=__commonJS({"node_modules/jscad-planner/dist/index.cjs"(exports,module){"use strict";var __defProp6=Object.defineProperty,__getOwnPropDesc4=Object.getOwnPropertyDescriptor,__getOwnPropNames4=Object.getOwnPropertyNames,__hasOwnProp5=Object.prototype.hasOwnProperty,__export5=(target,all)=>{for(var name in all)__defProp6(target,name,{get:all[name],enumerable:!0})},__copyProps4=(to3,from,except,desc)=>{if(from&&typeof from=="object"||typeof from=="function")for(let key of __getOwnPropNames4(from))!__hasOwnProp5.call(to3,key)&&key!==except&&__defProp6(to3,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc4(from,key))||desc.enumerable});return to3},__toCommonJS2=mod=>__copyProps4(__defProp6({},"__esModule",{value:!0}),mod),index_exports={};__export5(index_exports,{assertTransformMatrix:()=>assertTransformMatrix,executeJscadOperations:()=>executeJscadOperations,jscadPlanner:()=>jscadPlanner2,resolveReferencePlanes:()=>resolveReferencePlanes3,toTransformMatrix:()=>toTransformMatrix});module.exports=__toCommonJS2(index_exports);var invalidTransformMatrixMessage="Transform matrix must be a column-major array of exactly 16 finite numbers";function assertTransformMatrix(matrix2){if(!Array.isArray(matrix2)||matrix2.length!==16||!Array.from(matrix2).every(Number.isFinite))throw new Error(invalidTransformMatrixMessage)}function toTransformMatrix(matrix2){if(matrix2==null||matrix2.length!==16)throw new Error(invalidTransformMatrixMessage);let copy10=Array.from(matrix2);return assertTransformMatrix(copy10),copy10}var jscadPlanner2={booleans:{intersect:(...shapes)=>({type:"intersect",shapes}),subtract:(...shapes)=>({type:"subtract",shapes}),union:(...shapes)=>({type:"union",shapes})},hulls:{hull:(...shapes)=>({type:"hull",shapes:shapes.flat()}),hullChain:(...shapes)=>({type:"hullChain",shapes:shapes.flat()})},colors:{colorize:(color3,shape21)=>({type:"colorize",color:color3,shape:shape21})},primitives:{rectangle:options=>({...options,type:"rectangle"}),cube:options=>({type:"cube",...options}),sphere:options=>({type:"sphere",...options}),cylinder:options=>({type:"cylinder",...options}),polygon:options=>({type:"polygon",...options}),cuboid:options=>({type:"cuboid",...options}),roundedCuboid:options=>({type:"roundedCuboid",...options})},transforms:{transform:(matrix2,shape21)=>(assertTransformMatrix(matrix2),{type:"transform",matrix:matrix2,shape:shape21}),rotate:(angles,shape21)=>({type:"rotate",angles,shape:shape21}),rotateX:(angle3,shape21)=>({type:"rotateX",angle:angle3,shape:shape21}),rotateY:(angle3,shape21)=>({type:"rotateY",angle:angle3,shape:shape21}),rotateZ:(angle3,shape21)=>({type:"rotateZ",angle:angle3,shape:shape21}),scale:(factors,shape21)=>({type:"scale",factors,shape:shape21}),translate:(vector3,shape21)=>({type:"translate",vector:vector3,shape:shape21})},extrusions:{extrudeLinear:(options,shape21)=>({type:"extrudeLinear",options,shape:shape21}),extrudeRotate:(options,shape21)=>({type:"extrudeRotate",options,shape:shape21})},maths:{vec2:{create:(x11,y11)=>[x11,y11],fromValues:(x11,y11)=>[x11,y11]},vec3:{create:(x11,y11,z10)=>[x11,y11,z10],fromValues:(x11,y11,z10)=>[x11,y11,z10]}},geometries:{geom2:{create:points=>({type:"createGeom2",points}),fromPoints:points=>({type:"fromPointsGeom2",points})},geom3:{create:polygons=>({type:"createGeom3",polygons})},path2:{create:points=>({type:"createPath2",points})}},measurements:{measureBoundingBox:shape21=>({type:"measureBoundingBox",shape:shape21}),measureArea:shape21=>({type:"measureArea",shape:shape21}),measureVolume:shape21=>({type:"measureVolume",shape:shape21})},utils:{degToRad:degrees3=>degrees3*Math.PI/180,radToDeg:radians3=>radians3*180/Math.PI}},import_gl_matrix9=(init_esm(),__toCommonJS(esm_exports3)),identity8=()=>toTransformMatrix(import_gl_matrix9.mat4.create());function transformMatrix(operation){let result=identity8();switch(operation.type){case"transform":return assertTransformMatrix(operation.matrix),[...operation.matrix];case"translate":return toTransformMatrix(import_gl_matrix9.mat4.fromTranslation(result,operation.vector));case"scale":return toTransformMatrix(import_gl_matrix9.mat4.fromScaling(result,operation.factors));case"rotate":return import_gl_matrix9.mat4.rotateZ(result,result,operation.angles[2]),import_gl_matrix9.mat4.rotateY(result,result,operation.angles[1]),import_gl_matrix9.mat4.rotateX(result,result,operation.angles[0]),result;case"rotateX":return toTransformMatrix(import_gl_matrix9.mat4.fromXRotation(result,operation.angle));case"rotateY":return toTransformMatrix(import_gl_matrix9.mat4.fromYRotation(result,operation.angle));case"rotateZ":return toTransformMatrix(import_gl_matrix9.mat4.fromZRotation(result,operation.angle));default:throw new Error(`Cannot use ${operation.type} as a reference transform`)}}function getReferencePlane(rectangle2,transforms){let name=rectangle2.name;if(!name?.trim())throw new Error("Reference rectangles require a nonblank name");let center2;if(rectangle2.type==="rectangle"){if(rectangle2.size.length!==2||!rectangle2.size.every(n10=>Number.isFinite(n10)&&n10>0))throw new Error(`Reference rectangle "${name}" requires two positive finite dimensions`);center2=rectangle2.center??[0,0]}else{let points=rectangle2.points;if(rectangle2.paths||points.length!==4||!points.every(p11=>p11.length===2&&p11.every(n10=>typeof n10=="number"&&Number.isFinite(n10))))throw new Error(`Reference polygon "${name}" must be an axis-aligned rectangle`);let corners=points,xs3=[...new Set(corners.map(p11=>p11[0]))],ys3=[...new Set(corners.map(p11=>p11[1]))];if(xs3.length!==2||ys3.length!==2||new Set(corners.map(p11=>JSON.stringify(p11))).size!==4)throw new Error(`Reference polygon "${name}" must be an axis-aligned rectangle`);center2=[(xs3[0]+xs3[1])/2,(ys3[0]+ys3[1])/2]}if(center2.length!==2||!center2.every(Number.isFinite))throw new Error(`Reference rectangle "${name}" has an invalid center`);let matrix2=identity8();for(let transform7 of transforms)import_gl_matrix9.mat4.multiply(matrix2,matrix2,transformMatrix(transform7));if(assertTransformMatrix(matrix2),matrix2[3]!==0||matrix2[7]!==0||matrix2[11]!==0||matrix2[15]!==1)throw new Error(`Reference rectangle "${name}" requires affine transforms`);let inverse8=import_gl_matrix9.mat4.invert(identity8(),matrix2);if(!inverse8)throw new Error(`Reference rectangle "${name}" has a singular transform`);let origin=[0,0,0];import_gl_matrix9.vec3.transformMat4(origin,[center2[0],center2[1],0],matrix2);let normal=[inverse8[2],inverse8[6],inverse8[10]],xAxis=[matrix2[0],matrix2[1],matrix2[2]];if(![...origin,...normal,...xAxis].every(Number.isFinite)||!import_gl_matrix9.vec3.length(normal)||!import_gl_matrix9.vec3.length(xAxis))throw new Error(`Reference rectangle "${name}" has an invalid frame`);return import_gl_matrix9.vec3.normalize(normal,normal),import_gl_matrix9.vec3.normalize(xAxis,xAxis),{name,origin,normal,xAxis}}function resolveReferencePlanes3(plan){let referencePlanes=[],names=new Set;function visit(operation,transforms,inProfile=!1){if(operation.reference){if(operation.type!=="rectangle"&&operation.type!=="polygon")throw new Error("Only rectangles can be reference geometry");if(inProfile)throw new Error("Reference rectangles must be outside extrusion and measurement inputs");let plane=getReferencePlane(operation,transforms);if(names.has(plane.name))throw new Error(`Duplicate reference plane "${plane.name}"`);names.add(plane.name),referencePlanes.push(plane);return}switch(operation.type){case"translate":case"rotate":case"rotateX":case"rotateY":case"rotateZ":case"scale":case"transform":{let shape21=visit(operation.shape,[...transforms,operation],inProfile);return shape21?{...operation,shape:shape21}:void 0}case"colorize":{let shape21=visit(operation.shape,transforms,inProfile);return shape21?{...operation,shape:shape21}:void 0}case"extrudeLinear":case"extrudeRotate":case"measureArea":case"measureVolume":case"measureBoundingBox":{let shape21=visit(operation.shape,transforms,!0);return shape21?{...operation,shape:shape21}:void 0}case"union":case"subtract":case"intersect":case"hull":case"hullChain":{let children=operation.shapes.map(shape21=>visit(shape21,transforms,inProfile));if(operation.type==="subtract"&&operation.shapes.length&&!children[0])throw new Error("A subtraction base cannot be reference geometry");let shapes=children.filter(shape21=>shape21!==void 0);return shapes.length?shapes.length===1?shapes[0]:{...operation,shapes}:void 0}default:return{...operation}}}let roots=(Array.isArray(plan)?plan:[plan]).map(operation=>visit(operation,[])).filter(operation=>operation!==void 0);return{geometry:roots.length>1?{type:"union",shapes:roots}:roots[0],referencePlanes}}var executeJscadOperations=(jscad2,operation)=>{if(Array.isArray(operation)&&operation.length===1)return executeJscadOperations(jscad2,operation[0]);if(Array.isArray(operation))throw new Error("executeJscadOperations currently doesn't support Array<JscadOperation>, try adding a root union or or executing each element individually");let{geometry}=resolveReferencePlanes3(operation);if(!geometry)throw new Error("JSCAD plan contains only reference geometry");return executeGeometry(jscad2,geometry)},executeGeometry=(jscad2,operation)=>{let recurse=op4=>executeGeometry(jscad2,op4),{type,...params}=operation;switch(type){case"rectangle":if(!jscad2.primitives.rectangle)throw new Error("JSCAD adapter does not support primitives.rectangle");return jscad2.primitives.rectangle({size:operation.size,center:operation.center??[0,0]});case"intersect":return jscad2.booleans.intersect(...operation.shapes.map(recurse));case"subtract":return jscad2.booleans.subtract(...operation.shapes.map(recurse));case"union":return jscad2.booleans.union(...operation.shapes.map(recurse));case"hull":return jscad2.hulls.hull(...operation.shapes.map(recurse));case"hullChain":return jscad2.hulls.hullChain(...operation.shapes.map(recurse));case"colorize":return jscad2.colors.colorize(operation.color,recurse(operation.shape));case"cube":return jscad2.primitives.cube(params);case"sphere":return jscad2.primitives.sphere(params);case"cylinder":return jscad2.primitives.cylinder(params);case"polygon":return jscad2.primitives.polygon(params);case"cuboid":return jscad2.primitives.cuboid(params);case"roundedCuboid":return jscad2.primitives.roundedCuboid(params);case"transform":if(assertTransformMatrix(operation.matrix),!jscad2.transforms.transform)throw new Error('Cannot execute "transform" operation: this JSCAD adapter does not support transforms.transform');return jscad2.transforms.transform(operation.matrix,recurse(operation.shape));case"rotate":return jscad2.transforms.rotate(operation.angles,recurse(operation.shape));case"rotateX":return jscad2.transforms.rotateX(operation.angle,recurse(operation.shape));case"rotateY":return jscad2.transforms.rotateY(operation.angle,recurse(operation.shape));case"rotateZ":return jscad2.transforms.rotateZ(operation.angle,recurse(operation.shape));case"scale":return jscad2.transforms.scale(operation.factors,recurse(operation.shape));case"translate":return jscad2.transforms.translate(operation.vector,recurse(operation.shape));case"extrudeLinear":return jscad2.extrusions.extrudeLinear(operation.options,recurse(operation.shape));case"extrudeRotate":return jscad2.extrusions.extrudeRotate(operation.options,recurse(operation.shape));case"createGeom2":return jscad2.geometries.geom2.create(operation.points);case"fromPointsGeom2":return jscad2.geometries.geom2.fromPoints(operation.points);case"createGeom3":return jscad2.geometries.geom3.create(operation.polygons);case"createPath2":return jscad2.geometries.path2.create(operation.points);case"measureBoundingBox":return jscad2.measurements.measureBoundingBox(recurse(operation.shape));case"measureArea":return jscad2.measurements.measureArea(recurse(operation.shape));case"measureVolume":return jscad2.measurements.measureVolume(recurse(operation.shape));case"degToRad":return jscad2.utils.degToRad(operation.degrees);case"radToDeg":return jscad2.utils.radToDeg(operation.radians);default:throw operation.type===void 0?new Error(`Operation type is undefined. This usually means the operation object is malformed or not properly initialized. Operation: ${JSON.stringify(operation,null,2).slice(0,200)}...`):new Error(`Unsupported operation type: ${operation.type}. Operation: ${JSON.stringify(operation,null,2)}`)}}}});function connect(map,a10,b10){if(!a10||!b10)return;let setA=map.get(a10);setA||(setA=new Set,map.set(a10,setA)),setA.add(b10);let setB=map.get(b10);setB||(setB=new Set,map.set(b10,setB)),setB.add(a10)}function buildSubtree(soup,opts){if(!opts.subcircuit_id&&!opts.source_group_id)return[...soup];let effectiveOpts=opts;if(opts.subcircuit_id){let subcircuitIds=new Set([opts.subcircuit_id]),groupChildren=new Map,groupSubcircuit=new Map;for(let elm of soup)if(elm.type==="source_group"){let groupId=elm.source_group_id,subcircuitId=elm.subcircuit_id;subcircuitId&&groupSubcircuit.set(groupId,subcircuitId);let parentId=elm.parent_source_group_id;parentId&&(groupChildren.has(parentId)||groupChildren.set(parentId,[]),groupChildren.get(parentId).push(groupId))}let rootGroupId;for(let[groupId,subcircuitId]of groupSubcircuit)if(subcircuitId===opts.subcircuit_id){rootGroupId=groupId;break}if(rootGroupId){let collectChildSubcircuits=groupId=>{let children=groupChildren.get(groupId)||[];for(let childId of children){let childSubcircuit=groupSubcircuit.get(childId);childSubcircuit&&subcircuitIds.add(childSubcircuit),collectChildSubcircuits(childId)}};collectChildSubcircuits(rootGroupId),effectiveOpts={...opts,subcircuit_ids:Array.from(subcircuitIds)}}}let idMap=new Map;for(let elm of soup){let idKey=`${elm.type}_id`,idVal=elm[idKey];typeof idVal=="string"&&idMap.set(idVal,elm)}let adj=new Map;for(let elm of soup){let entries=Object.entries(elm);for(let[key,val]of entries)if(key!=="parent_source_group_id"){if(key.endsWith("_id")&&typeof val=="string"){let other=idMap.get(val);connect(adj,elm,other)}else if(key.endsWith("_ids")&&Array.isArray(val)){for(let v11 of val)if(typeof v11=="string"){let other=idMap.get(v11);connect(adj,elm,other)}}}}let queue=[],included=new Set;for(let elm of soup){let shouldInclude=!1;(effectiveOpts.subcircuit_id&&"subcircuit_id"in elm&&elm.subcircuit_id===effectiveOpts.subcircuit_id||effectiveOpts.subcircuit_ids&&"subcircuit_id"in elm&&elm.subcircuit_id&&effectiveOpts.subcircuit_ids.includes(elm.subcircuit_id)||effectiveOpts.source_group_id&&"source_group_id"in elm&&elm.source_group_id===effectiveOpts.source_group_id||effectiveOpts.source_group_id&&"member_source_group_ids"in elm&&Array.isArray(elm.member_source_group_ids)&&elm.member_source_group_ids.includes(effectiveOpts.source_group_id))&&(shouldInclude=!0),shouldInclude&&(queue.push(elm),included.add(elm))}for(;queue.length>0;){let elm=queue.shift(),neighbors=adj.get(elm);if(neighbors)for(let n10 of neighbors)included.has(n10)||(included.add(n10),queue.push(n10))}return soup.filter(e55=>included.has(e55))}function createIdKey(element){let type=element.type;return`${type}:${element[`${type}_id`]}`}function getReadableNameForPcbSmtpad(soup,pcb_smtpad_id){let pcbSmtpad=cju(soup).pcb_smtpad.get(pcb_smtpad_id);return!pcbSmtpad||!pcbSmtpad.pcb_port_id?`smtpad[${pcb_smtpad_id}]`:getReadableNameForPcbPort(soup,pcbSmtpad.pcb_port_id)}function getReadableNameForPcbTrace(soup,pcb_trace_id){let pcbTrace=cju(soup).pcb_trace.get(pcb_trace_id);if(!pcbTrace)return`trace[${pcb_trace_id}]`;let connectedPcbPortIds=pcbTrace.route.flatMap(point7=>[point7.start_pcb_port_id,point7.end_pcb_port_id]).filter(Boolean);if(connectedPcbPortIds.length===0)return`trace[${pcb_trace_id}]`;function getComponentAndPortInfo(pcb_port_id){let pcbPort=cju(soup).pcb_port.get(pcb_port_id);if(!pcbPort)return null;let pcbComponent=pcbPort.pcb_component_id?cju(soup).pcb_component.get(pcbPort.pcb_component_id):void 0;if(!pcbComponent)return null;let sourceComponent=cju(soup).source_component.get(pcbComponent.source_component_id);if(!sourceComponent)return null;let sourcePort=cju(soup).source_port.get(pcbPort.source_port_id),portHint=sourcePort?.port_hints?sourcePort.port_hints[1]:"";return{componentName:sourceComponent.name,portHint}}return`trace[${connectedPcbPortIds.map(portId=>{let info=getComponentAndPortInfo(portId);return info?`.${info.componentName} > port.${info.portHint}`:`port[${portId}]`}).join(", ")}]`}function stringHash(str10){let hash=0;if(str10.length==0)return hash;for(var i11=0;i11<str10.length;i11++){var char=str10.charCodeAt(i11);hash=(hash<<5)-hash+char,hash=hash&hash}return Math.abs(hash)}function getMinimumFlexContainer(children,options={}){if(children.length===0)return{width:0,height:0};let direction3=options.direction??"row",columnGap=options.columnGap??0,rowGap=options.rowGap??0;if(direction3==="row"||direction3==="row-reverse"){let width=children.reduce((sum,c10)=>sum+c10.width,0)+columnGap*Math.max(0,children.length-1),height=children.reduce((max5,c10)=>Math.max(max5,c10.height),0);return{width,height}}else{let height=children.reduce((sum,c10)=>sum+c10.height,0)+rowGap*Math.max(0,children.length-1);return{width:children.reduce((max5,c10)=>Math.max(max5,c10.width),0),height}}}var cju,su3,cju_default,cjuIndexed,cju_indexed_default,rotateClockwise,rotateCounterClockwise,rotateDirection,oppositeSide,getQuarterTurns,insertionDirectionToVec,vecToInsertionDirection,transformInsertionDirection,transformSchematicElement,transformSchematicElements,transformPcbSoldermaskOpening,transformPCBElement,transformPCBElements,getElementId,getElementById2,getReadableNameForPcbPort,getReadableNameForElement,mergeBounds,getCircleBounds,getRotatedRectBounds,getRotatedOvalBounds,getRotatedPillBounds,getBoundsFromPoints3,getRoutePoints,getPcbElementBounds,getBoundsOfPcbElements,getBoardBounds,SCHEMATIC_TRACE_WIDTH,SCHEMATIC_NET_LABEL_FONT_SIZE,SCHEMATIC_NET_LABEL_HEIGHT,createBounds,getSchematicNetLabelTextWidth,getSchematicNetLabelBounds,getSchematicElementBounds,nice_color_palettes,getDebugLayoutObject,isTruthy,findBoundsAndCenter,getPrimaryId,repositionPcbComponentTo,findAllDescendantGroupIds,repositionPcbGroupTo,repositionSchematicComponentTo,findAllDescendantGroupIds2,repositionSchematicGroupTo,getCircuitJsonTree,EPSILON2,clamp3,distanceBetweenPoints,distanceBetweenPointAndSegment,cross4,isPointOnSegment2,segmentsIntersect,getPolygonEdges2,isPointInPolygon,distanceBetweenCircleAndCircle,distanceBetweenPolygonAndPolygon,distanceBetweenCircleAndPolygon,PIN1_LOCATION_PARTS,PIN1_LOCATIONS,getPadCenter2,getPinNumber,getCanonicalRowLocation,pinMatchesLocation2,analyzePcbPin1Location,placePolygon,ccw,circlePolygon,roundedRectangle,ringPolygon,subtractHole,getPourPolygon,getSmtPadPolygon,getViaPolygon,getPlatedHolePolygon,getTraceSegmentPolygon,copperPolygonsTouch,init_dist7=__esm({"node_modules/@tscircuit/circuit-json-util/dist/index.js"(){"use strict";init_dist2();init_dist2();init_src();init_parsel();init_src();init_src();init_src();init_src();init_main();init_src();cju=((circuitJsonInput,options={})=>{let circuitJson=circuitJsonInput,internalStore=circuitJson._internal_store;if(!internalStore){internalStore={counts:{},editCount:0},circuitJson._internal_store=internalStore;for(let elm of circuitJson){let type=elm.type,idVal=elm[`${type}_id`];if(!idVal)continue;let idNum=Number.parseInt(idVal.split("_").pop());Number.isNaN(idNum)||(internalStore.counts[type]=Math.max(internalStore.counts[type]??0,idNum))}}let su22=new Proxy({},{get:(proxy_target,prop)=>{if(prop==="toArray")return()=>(circuitJson.editCount=internalStore.editCount,circuitJson);if(prop==="editCount")return internalStore.editCount;if(prop==="subtree")return opts=>cju(buildSubtree(circuitJson,opts),options);if(prop==="insert")return elm=>{var _a543;let component_type2=elm.type;if(!component_type2)throw new Error("insert requires an element with a type");(_a543=internalStore.counts)[component_type2]??(_a543[component_type2]=-1),internalStore.counts[component_type2]++;let index2=internalStore.counts[component_type2],newElm={...elm,type:component_type2,[`${component_type2}_id`]:`${component_type2}_${index2}`};return options.validateInserts&&(dist_exports[component_type2]??any_soup_element).parse(newElm),circuitJson.push(newElm),internalStore.editCount++,newElm};if(prop==="insertAll")return elms=>elms.map(elm=>su22.insert(elm));let component_type=prop;return{get:id3=>circuitJson.find(e55=>e55.type===component_type&&e55[`${component_type}_id`]===id3),getUsing:using=>{let keys=Object.keys(using);if(keys.length!==1)throw new Error("getUsing requires exactly one key, e.g. { pcb_component_id }");let join_key=keys[0],join_type=join_key.replace("_id",""),joiner=circuitJson.find(e55=>e55.type===join_type&&e55[join_key]===using[join_key]);return joiner?circuitJson.find(e55=>e55.type===component_type&&e55[`${component_type}_id`]===joiner[`${component_type}_id`]):null},getWhere:where=>{let keys=Object.keys(where);return circuitJson.find(e55=>e55.type===component_type&&keys.every(key=>e55[key]===where[key]))},list:where=>{let keys=where?Object.keys(where):[];return circuitJson.filter(e55=>e55.type===component_type&&keys.every(key=>e55[key]===where[key]))},insert:elm=>{var _a543;(_a543=internalStore.counts)[component_type]??(_a543[component_type]=-1),internalStore.counts[component_type]++;let index2=internalStore.counts[component_type],newElm={type:component_type,[`${component_type}_id`]:`${component_type}_${index2}`,...elm};return options.validateInserts&&(dist_exports[component_type]??any_soup_element).parse(newElm),circuitJson.push(newElm),internalStore.editCount++,newElm},delete:id3=>{let elm=circuitJson.find(e55=>e55[`${component_type}_id`]===id3);elm&&(circuitJson.splice(circuitJson.indexOf(elm),1),internalStore.editCount++)},update:(id3,newProps)=>{let elm=circuitJson.find(e55=>e55.type===component_type&&e55[`${component_type}_id`]===id3);return elm?(Object.assign(elm,newProps),internalStore.editCount++,elm):null},select:selector2=>{if(component_type==="source_component")return circuitJson.find(e55=>e55.type==="source_component"&&e55.name===selector2.replace(/\./g,""));if(component_type==="pcb_port"||component_type==="source_port"||component_type==="schematic_port"){let[component_name,port_selector]=selector2.replace(/\./g,"").split(/[\s\>]+/),source_component=circuitJson.find(e55=>e55.type==="source_component"&&e55.name===component_name);if(!source_component)return null;let source_port3=circuitJson.find(e55=>e55.type==="source_port"&&e55.source_component_id===source_component.source_component_id&&(e55.name===port_selector||(e55.port_hints??[]).includes(port_selector)));if(!source_port3)return null;if(component_type==="source_port")return source_port3;if(component_type==="pcb_port")return circuitJson.find(e55=>e55.type==="pcb_port"&&e55.source_port_id===source_port3.source_port_id);if(component_type==="schematic_port")return circuitJson.find(e55=>e55.type==="schematic_port"&&e55.source_port_id===source_port3.source_port_id)}}}}});return su22});cju.unparsed=cju;su3=cju,cju_default=cju;cjuIndexed=((soup,options={})=>{let internalStore=soup._internal_store_indexed;if(!internalStore){internalStore={counts:{},editCount:0,indexes:{}};for(let elm of soup){let type=elm.type,idVal=elm[`${type}_id`];if(!idVal)continue;let idNum=Number.parseInt(idVal.split("_").pop()||"");Number.isNaN(idNum)||(internalStore.counts[type]=Math.max(internalStore.counts[type]??0,idNum))}let indexConfig=options.indexConfig||{},indexes=internalStore.indexes;if(indexConfig.byId&&(indexes.byId=new Map),indexConfig.byType&&(indexes.byType=new Map),indexConfig.byRelation&&(indexes.byRelation=new Map),indexConfig.bySubcircuit&&(indexes.bySubcircuit=new Map),indexConfig.byCustomField&&indexConfig.byCustomField.length>0){indexes.byCustomField=new Map;for(let field of indexConfig.byCustomField)indexes.byCustomField.set(field,new Map)}for(let element of soup){if(indexConfig.byId){let idKey=createIdKey(element);indexes.byId.set(idKey,element)}if(indexConfig.byType){let elementsOfType=indexes.byType.get(element.type)||[];elementsOfType.push(element),indexes.byType.set(element.type,elementsOfType)}if(indexConfig.byRelation){let elementEntries=Object.entries(element);for(let[key,value]of elementEntries)if(key.endsWith("_id")&&key!==`${element.type}_id`&&typeof value=="string"){let relationTypeMap=indexes.byRelation.get(key)||new Map,relatedElements=relationTypeMap.get(value)||[];relatedElements.push(element),relationTypeMap.set(value,relatedElements),indexes.byRelation.set(key,relationTypeMap)}}if(indexConfig.bySubcircuit&&"subcircuit_id"in element){let subcircuitId=element.subcircuit_id;if(subcircuitId&&typeof subcircuitId=="string"){let subcircuitElements=indexes.bySubcircuit.get(subcircuitId)||[];subcircuitElements.push(element),indexes.bySubcircuit.set(subcircuitId,subcircuitElements)}}if(indexConfig.byCustomField&&indexes.byCustomField){for(let field of indexConfig.byCustomField)if(field in element){let fieldValue=element[field];if(fieldValue!==void 0&&(typeof fieldValue=="string"||typeof fieldValue=="number")){let fieldValueStr=String(fieldValue),fieldMap=indexes.byCustomField.get(field),elementsWithFieldValue=fieldMap.get(fieldValueStr)||[];elementsWithFieldValue.push(element),fieldMap.set(fieldValueStr,elementsWithFieldValue)}}}}soup._internal_store_indexed=internalStore}let suIndexed=new Proxy({},{get:(proxy_target,prop)=>{if(prop==="toArray")return()=>(soup.editCount=internalStore.editCount,soup);if(prop==="editCount")return internalStore.editCount;if(prop==="insert")return elm=>{let{type,...props}=elm;if(!type)throw new Error("insert requires an element with a type");return delete props[`${type}_id`],suIndexed[type].insert(props)};if(prop==="insertAll")return elms=>elms.map(elm=>suIndexed.insert(elm));if(prop==="subtree")return opts=>cjuIndexed(buildSubtree(soup,opts),options);let component_type=prop;return{get:id3=>{let indexConfig=options.indexConfig||{};return indexConfig.byId&&internalStore.indexes.byId?internalStore.indexes.byId.get(`${component_type}:${id3}`)||null:indexConfig.byType&&internalStore.indexes.byType?(internalStore.indexes.byType.get(component_type)||[]).find(e55=>e55[`${component_type}_id`]===id3)||null:soup.find(e55=>e55.type===component_type&&e55[`${component_type}_id`]===id3)||null},getUsing:using=>{let indexConfig=options.indexConfig||{},keys=Object.keys(using);if(keys.length!==1)throw new Error("getUsing requires exactly one key, e.g. { pcb_component_id }");let join_key=keys[0],join_type=join_key.replace("_id","");if(indexConfig.byRelation&&internalStore.indexes.byRelation){let relationMap=internalStore.indexes.byRelation.get(join_key);if(relationMap){let joiner2=(relationMap.get(using[join_key])||[]).find(e55=>e55.type===join_type);if(!joiner2)return null;let joinerId=joiner2[`${component_type}_id`];return indexConfig.byId&&internalStore.indexes.byId?internalStore.indexes.byId.get(`${component_type}:${joinerId}`)||null:indexConfig.byType&&internalStore.indexes.byType?(internalStore.indexes.byType.get(component_type)||[]).find(e55=>e55[`${component_type}_id`]===joinerId)||null:soup.find(e55=>e55.type===component_type&&e55[`${component_type}_id`]===joinerId)||null}}let joiner=soup.find(e55=>e55.type===join_type&&e55[join_key]===using[join_key]);return joiner&&soup.find(e55=>e55.type===component_type&&e55[`${component_type}_id`]===joiner[`${component_type}_id`])||null},getWhere:where=>{let indexConfig=options.indexConfig||{},keys=Object.keys(where);if(keys.length===1&&indexConfig.byCustomField&&internalStore.indexes.byCustomField){let field=keys[0],fieldMap=internalStore.indexes.byCustomField.get(field);if(fieldMap){let fieldValue=String(where[field]);return(fieldMap.get(fieldValue)||[]).find(e55=>e55.type===component_type)||null}}if("subcircuit_id"in where&&indexConfig.bySubcircuit&&internalStore.indexes.bySubcircuit){let subcircuitId=where.subcircuit_id;return(internalStore.indexes.bySubcircuit.get(subcircuitId)||[]).find(e55=>e55.type===component_type&&keys.every(key=>e55[key]===where[key]))||null}return indexConfig.byType&&internalStore.indexes.byType?(internalStore.indexes.byType.get(component_type)||[]).find(e55=>keys.every(key=>e55[key]===where[key]))||null:soup.find(e55=>e55.type===component_type&&keys.every(key=>e55[key]===where[key]))||null},list:where=>{let indexConfig=options.indexConfig||{},keys=where?Object.keys(where):[];if(keys.length===0&&indexConfig.byType&&internalStore.indexes.byType)return(internalStore.indexes.byType.get(component_type)||[]).slice();if(keys.length===1&&keys[0]==="subcircuit_id"&&indexConfig.bySubcircuit&&internalStore.indexes.bySubcircuit){let subcircuitId=where.subcircuit_id;return(internalStore.indexes.bySubcircuit.get(subcircuitId)||[]).filter(e55=>e55.type===component_type)}let elementsToFilter;return indexConfig.byType&&internalStore.indexes.byType?elementsToFilter=internalStore.indexes.byType.get(component_type)||[]:elementsToFilter=soup.filter(e55=>e55.type===component_type),keys.length>0?elementsToFilter.filter(e55=>keys.every(key=>e55[key]===where[key])):elementsToFilter.slice()},insert:elm=>{var _a543;(_a543=internalStore.counts)[component_type]??(_a543[component_type]=-1),internalStore.counts[component_type]++;let index2=internalStore.counts[component_type],newElm={type:component_type,[`${component_type}_id`]:`${component_type}_${index2}`,...elm};options.validateInserts&&(dist_exports[component_type]??any_soup_element).parse(newElm),soup.push(newElm),internalStore.editCount++;let indexConfig=options.indexConfig||{};if(indexConfig.byId&&internalStore.indexes.byId){let idKey=createIdKey(newElm);internalStore.indexes.byId.set(idKey,newElm)}if(indexConfig.byType&&internalStore.indexes.byType){let elementsOfType=internalStore.indexes.byType.get(component_type)||[];elementsOfType.push(newElm),internalStore.indexes.byType.set(component_type,elementsOfType)}if(indexConfig.byRelation&&internalStore.indexes.byRelation){let elementEntries=Object.entries(newElm);for(let[key,value]of elementEntries)if(key.endsWith("_id")&&key!==`${newElm.type}_id`&&typeof value=="string"){let relationTypeMap=internalStore.indexes.byRelation.get(key)||new Map,relatedElements=relationTypeMap.get(value)||[];relatedElements.push(newElm),relationTypeMap.set(value,relatedElements),internalStore.indexes.byRelation.set(key,relationTypeMap)}}if(indexConfig.bySubcircuit&&internalStore.indexes.bySubcircuit&&"subcircuit_id"in newElm){let subcircuitId=newElm.subcircuit_id;if(subcircuitId&&typeof subcircuitId=="string"){let subcircuitElements=internalStore.indexes.bySubcircuit.get(subcircuitId)||[];subcircuitElements.push(newElm),internalStore.indexes.bySubcircuit.set(subcircuitId,subcircuitElements)}}if(indexConfig.byCustomField&&internalStore.indexes.byCustomField){for(let field of indexConfig.byCustomField)if(field in newElm){let fieldValue=newElm[field];if(fieldValue!==void 0&&(typeof fieldValue=="string"||typeof fieldValue=="number")){let fieldValueStr=String(fieldValue),fieldMap=internalStore.indexes.byCustomField.get(field),elementsWithFieldValue=fieldMap.get(fieldValueStr)||[];elementsWithFieldValue.push(newElm),fieldMap.set(fieldValueStr,elementsWithFieldValue)}}}return newElm},delete:id3=>{let indexConfig=options.indexConfig||{},elm;if(indexConfig.byId&&internalStore.indexes.byId?elm=internalStore.indexes.byId.get(`${component_type}:${id3}`):indexConfig.byType&&internalStore.indexes.byType?elm=(internalStore.indexes.byType.get(component_type)||[]).find(e55=>e55[`${component_type}_id`]===id3):elm=soup.find(e55=>e55[`${component_type}_id`]===id3),!elm)return;let elmIndex=soup.indexOf(elm);if(elmIndex>=0&&(soup.splice(elmIndex,1),internalStore.editCount++),indexConfig.byId&&internalStore.indexes.byId){let idKey=createIdKey(elm);internalStore.indexes.byId.delete(idKey)}if(indexConfig.byType&&internalStore.indexes.byType){let filteredElements=(internalStore.indexes.byType.get(component_type)||[]).filter(e55=>e55[`${component_type}_id`]!==id3);internalStore.indexes.byType.set(component_type,filteredElements)}if(indexConfig.byRelation&&internalStore.indexes.byRelation)for(let[relationKey,relationMap]of internalStore.indexes.byRelation.entries())for(let[relationValue,elements]of relationMap.entries()){let updatedElements=elements.filter(e55=>e55!==elm);updatedElements.length===0?relationMap.delete(relationValue):relationMap.set(relationValue,updatedElements)}if(indexConfig.bySubcircuit&&internalStore.indexes.bySubcircuit&&"subcircuit_id"in elm){let subcircuitId=elm.subcircuit_id;if(subcircuitId){let updatedElements=(internalStore.indexes.bySubcircuit.get(subcircuitId)||[]).filter(e55=>e55!==elm);updatedElements.length===0?internalStore.indexes.bySubcircuit.delete(subcircuitId):internalStore.indexes.bySubcircuit.set(subcircuitId,updatedElements)}}if(indexConfig.byCustomField&&internalStore.indexes.byCustomField)for(let fieldMap of internalStore.indexes.byCustomField.values())for(let[fieldValue,elements]of fieldMap.entries()){let updatedElements=elements.filter(e55=>e55!==elm);updatedElements.length===0?fieldMap.delete(fieldValue):fieldMap.set(fieldValue,updatedElements)}},update:(id3,newProps)=>{let indexConfig=options.indexConfig||{},elm;if(indexConfig.byId&&internalStore.indexes.byId?elm=internalStore.indexes.byId.get(`${component_type}:${id3}`):indexConfig.byType&&internalStore.indexes.byType?elm=(internalStore.indexes.byType.get(component_type)||[]).find(e55=>e55[`${component_type}_id`]===id3):elm=soup.find(e55=>e55.type===component_type&&e55[`${component_type}_id`]===id3),!elm)return null;if(indexConfig.byRelation&&internalStore.indexes.byRelation){let elementEntries=Object.entries(elm);for(let[key,value]of elementEntries)if(key.endsWith("_id")&&key!==`${elm.type}_id`&&typeof value=="string"&&key in newProps&&newProps[key]!==value){let relationTypeMap=internalStore.indexes.byRelation.get(key);if(relationTypeMap){let updatedElements=(relationTypeMap.get(value)||[]).filter(e55=>e55!==elm);updatedElements.length===0?relationTypeMap.delete(value):relationTypeMap.set(value,updatedElements)}}}if(indexConfig.bySubcircuit&&internalStore.indexes.bySubcircuit&&"subcircuit_id"in elm&&"subcircuit_id"in newProps){let oldSubcircuitId=elm.subcircuit_id,newSubcircuitId=newProps.subcircuit_id;if(oldSubcircuitId!==newSubcircuitId){let updatedElements=(internalStore.indexes.bySubcircuit.get(oldSubcircuitId)||[]).filter(e55=>e55!==elm);updatedElements.length===0?internalStore.indexes.bySubcircuit.delete(oldSubcircuitId):internalStore.indexes.bySubcircuit.set(oldSubcircuitId,updatedElements)}}if(indexConfig.byCustomField&&internalStore.indexes.byCustomField){for(let field of indexConfig.byCustomField)if(field in elm&&field in newProps&&elm[field]!==newProps[field]){let fieldMap=internalStore.indexes.byCustomField.get(field);if(fieldMap){let oldValue=String(elm[field]),updatedElements=(fieldMap.get(oldValue)||[]).filter(e55=>e55!==elm);updatedElements.length===0?fieldMap.delete(oldValue):fieldMap.set(oldValue,updatedElements)}}}if(Object.assign(elm,newProps),internalStore.editCount++,indexConfig.byRelation&&internalStore.indexes.byRelation){let elementEntries=Object.entries(elm);for(let[key,value]of elementEntries)if(key.endsWith("_id")&&key!==`${elm.type}_id`&&typeof value=="string"&&key in newProps){let relationTypeMap=internalStore.indexes.byRelation.get(key)||new Map,relatedElements=relationTypeMap.get(value)||[];relatedElements.includes(elm)||(relatedElements.push(elm),relationTypeMap.set(value,relatedElements),internalStore.indexes.byRelation.set(key,relationTypeMap))}}if(indexConfig.bySubcircuit&&internalStore.indexes.bySubcircuit&&"subcircuit_id"in elm&&"subcircuit_id"in newProps){let subcircuitId=elm.subcircuit_id;if(subcircuitId&&typeof subcircuitId=="string"){let subcircuitElements=internalStore.indexes.bySubcircuit.get(subcircuitId)||[];subcircuitElements.includes(elm)||(subcircuitElements.push(elm),internalStore.indexes.bySubcircuit.set(subcircuitId,subcircuitElements))}}if(indexConfig.byCustomField&&internalStore.indexes.byCustomField){for(let field of indexConfig.byCustomField)if(field in elm&&field in newProps){let fieldValue=elm[field];if(fieldValue!==void 0&&(typeof fieldValue=="string"||typeof fieldValue=="number")){let fieldValueStr=String(fieldValue),fieldMap=internalStore.indexes.byCustomField.get(field),elementsWithFieldValue=fieldMap.get(fieldValueStr)||[];elementsWithFieldValue.includes(elm)||(elementsWithFieldValue.push(elm),fieldMap.set(fieldValueStr,elementsWithFieldValue))}}}return elm},select:selector2=>{if(component_type==="source_component")return soup.find(e55=>e55.type==="source_component"&&e55.name===selector2.replace(/\./g,""))||null;if(component_type==="pcb_port"||component_type==="source_port"||component_type==="schematic_port"){let[component_name,port_selector]=selector2.replace(/\./g,"").split(/[\s\>]+/),source_component=soup.find(e55=>e55.type==="source_component"&&e55.name===component_name);if(!source_component)return null;let source_port3=soup.find(e55=>e55.type==="source_port"&&e55.source_component_id===source_component.source_component_id&&(e55.name===port_selector||(e55.port_hints??[]).includes(port_selector)));if(!source_port3)return null;if(component_type==="source_port")return source_port3;if(component_type==="pcb_port")return soup.find(e55=>e55.type==="pcb_port"&&e55.source_port_id===source_port3.source_port_id)||null;if(component_type==="schematic_port")return soup.find(e55=>e55.type==="schematic_port"&&e55.source_port_id===source_port3.source_port_id)||null}return null}}}});return suIndexed});cjuIndexed.unparsed=cjuIndexed;cju_indexed_default=cjuIndexed,rotateClockwise=direction3=>{if(direction3==="up")return"right";if(direction3==="right")return"down";if(direction3==="down")return"left";if(direction3==="left")return"up";throw new Error(`Invalid direction: ${direction3}`)},rotateCounterClockwise=direction3=>{if(direction3==="up")return"left";if(direction3==="left")return"down";if(direction3==="down")return"right";if(direction3==="right")return"up";throw new Error(`Invalid direction: ${direction3}`)},rotateDirection=(direction3,num90DegreeClockwiseTurns)=>{for(;num90DegreeClockwiseTurns>0;)direction3=rotateClockwise(direction3),num90DegreeClockwiseTurns--;for(;num90DegreeClockwiseTurns<0;)direction3=rotateCounterClockwise(direction3),num90DegreeClockwiseTurns++;return direction3},oppositeSide=sideOrDir=>{if(sideOrDir==="top"||sideOrDir==="up")return"bottom";if(sideOrDir==="bottom"||sideOrDir==="down")return"top";if(sideOrDir==="left")return"right";if(sideOrDir==="right")return"left";throw new Error(`Invalid sideOrDir: ${sideOrDir}`)},getQuarterTurns=angleRadians=>Math.round(angleRadians/(Math.PI/2)),insertionDirectionToVec=direction3=>{switch(direction3){case"from_left":return{x:-1,y:0};case"from_right":return{x:1,y:0};case"from_top":return{x:0,y:1};case"from_bottom":return{x:0,y:-1}}},vecToInsertionDirection=({x:x11,y:y11})=>x11>0?"from_right":x11<0?"from_left":y11>0?"from_top":"from_bottom",transformInsertionDirection=(direction3,opts)=>{if(!direction3)return direction3;if(direction3==="from_above"||direction3==="from_below")return opts.isFlipped?direction3==="from_above"?"from_below":"from_above":direction3;let{x:x11,y:y11}=insertionDirectionToVec(direction3),quarterTurns=Math.round(opts.rotationDegrees/90);for(;quarterTurns>0;)[x11,y11]=[-y11,x11],quarterTurns--;for(;quarterTurns<0;)[x11,y11]=[y11,-x11],quarterTurns++;return opts.isFlipped&&(y11=-y11),vecToInsertionDirection({x:x11,y:y11})},transformSchematicElement=(elm,matrix2)=>{if(elm.type==="schematic_component")elm.center=applyToPoint(matrix2,elm.center);else if(elm.type==="schematic_port")elm.center=applyToPoint(matrix2,elm.center),elm.facing_direction&&(elm.facing_direction=rotateDirection(elm.facing_direction,-(Math.atan2(matrix2.b,matrix2.a)/Math.PI)*2));else if(elm.type==="schematic_text")elm.position=applyToPoint(matrix2,elm.position);else if(elm.type==="schematic_trace"){let anyElm=elm;anyElm.route=(anyElm.route??[]).map(rp4=>{let tp3=applyToPoint(matrix2,rp4);return rp4.x=tp3.x,rp4.y=tp3.y,rp4}),Array.isArray(anyElm.junctions)&&(anyElm.junctions=anyElm.junctions.map(j11=>{let tp3=applyToPoint(matrix2,j11);return j11.x=tp3.x,j11.y=tp3.y,j11})),Array.isArray(anyElm.edges)&&(anyElm.edges=anyElm.edges.map(e55=>(e55.from=applyToPoint(matrix2,e55.from),e55.to=applyToPoint(matrix2,e55.to),e55)))}else if(elm.type==="schematic_box"){let{x:x11,y:y11}=applyToPoint(matrix2,{x:elm.x,y:elm.y});elm.x=x11,elm.y=y11}else if(elm.type==="schematic_line"){let{x:x12,y:y12}=applyToPoint(matrix2,{x:elm.x1,y:elm.y1}),{x:x22,y:y22}=applyToPoint(matrix2,{x:elm.x2,y:elm.y2});elm.x1=x12,elm.y1=y12,elm.x2=x22,elm.y2=y22}return elm},transformSchematicElements=(elms,matrix2)=>elms.map(elm=>transformSchematicElement(elm,matrix2)),transformPcbSoldermaskOpening=(opening,matrix2)=>{if(opening.shape==="polygon")return opening.points=opening.points.map(point7=>applyToPoint(matrix2,point7)),opening;let center2=applyToPoint(matrix2,{x:opening.x,y:opening.y});if(opening.x=center2.x,opening.y=center2.y,opening.shape==="circle")return opening;let rectRotation=opening.shape==="rotated_rect"?opening.ccw_rotation:0,isReflected=matrix2.a*matrix2.d-matrix2.b*matrix2.c<0,transformedRotation=decomposeTSR(compose(matrix2,rotateDEG(rectRotation)),!1,isReflected).rotation.angle*180/Math.PI;return Math.abs(transformedRotation)<1e-8?(Object.assign(opening,{shape:"rect"}),Reflect.deleteProperty(opening,"ccw_rotation")):Object.assign(opening,{shape:"rotated_rect",ccw_rotation:transformedRotation}),opening},transformPCBElement=(elm,matrix2)=>{if(elm.type==="pcb_soldermask_opening")return transformPcbSoldermaskOpening(elm,matrix2);if((elm.type==="pcb_smtpad"||elm.type==="pcb_solder_paste")&&elm.shape==="polygon")return elm.points=elm.points.map(point7=>applyToPoint(matrix2,point7)),elm.type==="pcb_solder_paste"&&elm.holes&&(elm.holes=elm.holes.map(hole=>hole.map(point7=>applyToPoint(matrix2,point7)))),elm;let tsr=decomposeTSR(matrix2),flipPadWidthHeight=Math.abs(getQuarterTurns(tsr.rotation.angle))%2===1,rotationDegrees=tsr.rotation.angle/Math.PI*180,isFlipped=tsr.scale.sy<0;if(elm.type==="pcb_plated_hole"||elm.type==="pcb_hole"||elm.type==="pcb_via"||elm.type==="pcb_smtpad"||elm.type==="pcb_solder_paste"||elm.type==="pcb_port"){let{x:x11,y:y11}=applyToPoint(matrix2,{x:elm.x,y:elm.y});elm.x=x11,elm.y=y11}else if(elm.type==="pcb_keepout"&&elm.shape==="outline")elm.outline=elm.outline.map(point7=>applyToPoint(matrix2,point7));else if(elm.type==="pcb_keepout"||elm.type==="pcb_board")elm.center=applyToPoint(matrix2,elm.center);else if(elm.type==="pcb_silkscreen_text"||elm.type==="pcb_fabrication_note_text"||elm.type==="pcb_note_text")elm.anchor_position=applyToPoint(matrix2,elm.anchor_position);else if(elm.type==="pcb_copper_text")elm.anchor_position&&(elm.anchor_position=applyToPoint(matrix2,elm.anchor_position));else if(elm.type==="pcb_courtyard_rect")elm.center=applyToPoint(matrix2,elm.center),elm.ccw_rotation=((elm.ccw_rotation??0)+rotationDegrees)%360;else if(elm.type==="pcb_silkscreen_circle"||elm.type==="pcb_silkscreen_rect"||elm.type==="pcb_silkscreen_pill"||elm.type==="pcb_silkscreen_oval"||elm.type==="pcb_note_rect"||elm.type==="pcb_courtyard_circle")elm.center=applyToPoint(matrix2,elm.center);else if(elm.type==="pcb_component")elm.center=applyToPoint(matrix2,elm.center),elm.rotation=elm.rotation+rotationDegrees,elm.rotation=elm.rotation%360,elm.cable_insertion_center&&(elm.cable_insertion_center=applyToPoint(matrix2,elm.cable_insertion_center)),elm.insertion_direction=transformInsertionDirection(elm.insertion_direction,{rotationDegrees,isFlipped}),flipPadWidthHeight&&([elm.width,elm.height]=[elm.height,elm.width]);else if(elm.type==="pcb_courtyard_outline")elm.outline=elm.outline.map(p11=>{let tp3=applyToPoint(matrix2,p11);return p11.x=tp3.x,p11.y=tp3.y,p11});else if(elm.type==="pcb_courtyard_polygon")elm.points=elm.points.map(p11=>{let tp3=applyToPoint(matrix2,p11);return p11.x=tp3.x,p11.y=tp3.y,p11});else if(elm.type==="pcb_trace")elm.route=elm.route.map(rp4=>{if(!("x"in rp4))return rp4.start=applyToPoint(matrix2,rp4.start),rp4.end=applyToPoint(matrix2,rp4.end),rp4;let tp3=applyToPoint(matrix2,rp4);return rp4.x=tp3.x,rp4.y=tp3.y,rp4});else if(elm.type==="pcb_silkscreen_path"||elm.type==="pcb_trace_hint"||elm.type==="pcb_fabrication_note_path"||elm.type==="pcb_note_path")elm.route=elm.route.map(rp4=>{let tp3=applyToPoint(matrix2,rp4);return rp4.x=tp3.x,rp4.y=tp3.y,rp4});else if(elm.type==="pcb_silkscreen_line"||elm.type==="pcb_note_line"){let p12={x:elm.x1,y:elm.y1},p22={x:elm.x2,y:elm.y2},p1t=applyToPoint(matrix2,p12),p2t=applyToPoint(matrix2,p22);elm.x1=p1t.x,elm.y1=p1t.y,elm.x2=p2t.x,elm.y2=p2t.y}else if(elm.type==="cad_component"){let newPos=applyToPoint(matrix2,{x:elm.position.x,y:elm.position.y});elm.position.x=newPos.x,elm.position.y=newPos.y}return elm},transformPCBElements=(elms,matrix2)=>{let tsr=decomposeTSR(matrix2),quarterTurns=getQuarterTurns(tsr.rotation.angle),flipPadWidthHeight=Math.abs(quarterTurns)%2===1,transformedElms=elms.map(elm=>transformPCBElement(elm,matrix2));return flipPadWidthHeight&&(transformedElms=transformedElms.map(elm=>((elm.type==="pcb_smtpad"||elm.type==="pcb_solder_paste")&&(elm.shape==="rect"||elm.shape==="pill")&&([elm.width,elm.height]=[elm.height,elm.width]),elm))),transformedElms},getElementId=elm=>{let type=elm.type;return elm[`${type}_id`]},getElementById2=(soup,id3)=>soup.find(elm=>getElementId(elm)===id3)??null,getReadableNameForPcbPort=(soup,pcb_port_id)=>{let pcbPort=cju(soup).pcb_port.get(pcb_port_id);if(!pcbPort)return`pcb_port[#${pcb_port_id}]`;let pcbComponent=pcbPort.pcb_component_id?cju(soup).pcb_component.get(pcbPort.pcb_component_id):void 0;if(!pcbComponent)return`pcb_port[#${pcb_port_id}]`;let sourceComponent=cju(soup).source_component.get(pcbComponent.source_component_id);if(!sourceComponent)return`pcb_port[#${pcb_port_id}]`;let sourcePort=cju(soup).source_port.get(pcbPort.source_port_id);if(!sourcePort)return`pcb_port[#${pcb_port_id}]`;let padIdentifier;return sourcePort?.port_hints&&sourcePort.port_hints.length>0||sourcePort.port_hints&&sourcePort.port_hints.length>0?padIdentifier=sourcePort.port_hints[0]:padIdentifier=pcb_port_id,`pcb_port[.${sourceComponent.name} > .${padIdentifier}]`};getReadableNameForElement=(soup,elm)=>{if(typeof elm=="string"){let elmObj=getElementById2(soup,elm);return elmObj||`${elm}`,getReadableNameForElement(soup,elmObj)}switch(elm.type){case"pcb_port":return getReadableNameForPcbPort(soup,elm.pcb_port_id);case"pcb_smtpad":return getReadableNameForPcbSmtpad(soup,elm.pcb_smtpad_id);case"pcb_trace":return getReadableNameForPcbTrace(soup,elm.pcb_trace_id);case"source_component":return`source_component[${elm.name}]`;default:return`${elm.type}[#${getElementId(elm)}]`}},mergeBounds=(currentBounds,nextBounds)=>({minX:Math.min(currentBounds.minX,nextBounds.minX),minY:Math.min(currentBounds.minY,nextBounds.minY),maxX:Math.max(currentBounds.maxX,nextBounds.maxX),maxY:Math.max(currentBounds.maxY,nextBounds.maxY)}),getCircleBounds=(x11,y11,diameter)=>{let radius=diameter/2;return{minX:x11-radius,minY:y11-radius,maxX:x11+radius,maxY:y11+radius}},getRotatedRectBounds=(x11,y11,width,height,rotationDegrees)=>{let halfWidth=width/2,halfHeight=height/2,theta=rotationDegrees*Math.PI/180,cosTheta=Math.cos(theta),sinTheta=Math.sin(theta),corners=[{x:-halfWidth,y:-halfHeight},{x:halfWidth,y:-halfHeight},{x:halfWidth,y:halfHeight},{x:-halfWidth,y:halfHeight}].map(corner=>({x:x11+corner.x*cosTheta-corner.y*sinTheta,y:y11+corner.x*sinTheta+corner.y*cosTheta}));return{minX:Math.min(...corners.map(corner=>corner.x)),minY:Math.min(...corners.map(corner=>corner.y)),maxX:Math.max(...corners.map(corner=>corner.x)),maxY:Math.max(...corners.map(corner=>corner.y))}},getRotatedOvalBounds=(x11,y11,width,height,rotationDegrees)=>{let radiusX=width/2,radiusY=height/2,theta=rotationDegrees*Math.PI/180,cosTheta=Math.cos(theta),sinTheta=Math.sin(theta),halfWidth=Math.hypot(radiusX*cosTheta,radiusY*sinTheta),halfHeight=Math.hypot(radiusX*sinTheta,radiusY*cosTheta);return{minX:x11-halfWidth,minY:y11-halfHeight,maxX:x11+halfWidth,maxY:y11+halfHeight}},getRotatedPillBounds=(x11,y11,width,height,rotationDegrees)=>{let radius=Math.min(width,height)/2,halfLineLength=Math.max(width,height)/2-radius,theta=rotationDegrees*Math.PI/180,axis=width>=height?{x:halfLineLength,y:0}:{x:0,y:halfLineLength},rotatedAxis={x:axis.x*Math.cos(theta)-axis.y*Math.sin(theta),y:axis.x*Math.sin(theta)+axis.y*Math.cos(theta)},halfWidth=Math.abs(rotatedAxis.x)+radius,halfHeight=Math.abs(rotatedAxis.y)+radius;return{minX:x11-halfWidth,minY:y11-halfHeight,maxX:x11+halfWidth,maxY:y11+halfHeight}},getBoundsFromPoints3=points=>points.length===0?null:{minX:Math.min(...points.map(point7=>point7.x)),minY:Math.min(...points.map(point7=>point7.y)),maxX:Math.max(...points.map(point7=>point7.x)),maxY:Math.max(...points.map(point7=>point7.y))},getRoutePoints=route2=>Array.isArray(route2)?route2.flatMap(point7=>!point7||typeof point7!="object"?[]:"x"in point7&&"y"in point7&&typeof point7.x=="number"&&typeof point7.y=="number"?[{x:point7.x,y:point7.y}]:"start"in point7&&"end"in point7?[point7.start,point7.end].filter(position4=>!!(position4&&typeof position4=="object"&&"x"in position4&&"y"in position4&&typeof position4.x=="number"&&typeof position4.y=="number")):[]):[],getPcbElementBounds=elm=>{if(!elm.type.startsWith("pcb_"))return null;if(elm.type==="pcb_smtpad"&&elm.shape==="polygon"&&Array.isArray(elm.points))return getBoundsFromPoints3(elm.points);if(elm.type==="pcb_hole"&&elm.hole_shape==="circle")return getCircleBounds(elm.x,elm.y,elm.hole_diameter);if(elm.type==="pcb_plated_hole"){let platedHoleBounds;if("outer_diameter"in elm&&typeof elm.outer_diameter=="number"?platedHoleBounds=getCircleBounds(elm.x,elm.y,elm.outer_diameter):"hole_diameter"in elm&&typeof elm.hole_diameter=="number"&&(platedHoleBounds=getCircleBounds(elm.x,elm.y,elm.hole_diameter)),(elm.shape==="oval"||elm.shape==="pill")&&typeof elm.outer_width=="number"&&typeof elm.outer_height=="number"&&(platedHoleBounds=(elm.shape==="pill"?getRotatedPillBounds:getRotatedOvalBounds)(elm.x,elm.y,elm.outer_width,elm.outer_height,elm.ccw_rotation??0)),"rect_pad_width"in elm&&typeof elm.rect_pad_width=="number"&&"rect_pad_height"in elm&&typeof elm.rect_pad_height=="number"){let rectBounds2=getRotatedRectBounds(elm.x,elm.y,elm.rect_pad_width,elm.rect_pad_height,"rect_ccw_rotation"in elm?elm.rect_ccw_rotation??0:0);platedHoleBounds=platedHoleBounds?mergeBounds(platedHoleBounds,rectBounds2):rectBounds2}if("hole_diameter"in elm&&typeof elm.hole_diameter=="number"){let drillBounds=getCircleBounds(elm.x+("hole_offset_x"in elm?elm.hole_offset_x??0:0),elm.y+("hole_offset_y"in elm?elm.hole_offset_y??0:0),elm.hole_diameter);platedHoleBounds=platedHoleBounds?mergeBounds(platedHoleBounds,drillBounds):drillBounds}if(platedHoleBounds)return platedHoleBounds}let elementRecord=elm,routeBounds=getBoundsFromPoints3(getRoutePoints(elementRecord.route));if(routeBounds)return routeBounds;let outlineBounds=getBoundsFromPoints3(getRoutePoints(elementRecord.outline));if(outlineBounds)return outlineBounds;let pointsBounds=getBoundsFromPoints3(getRoutePoints(elementRecord.points));if(pointsBounds)return pointsBounds;let centerX,centerY,width,height;"x"in elm&&"y"in elm&&(centerX=Number(elm.x),centerY=Number(elm.y)),"outer_diameter"in elm&&(width=Number(elm.outer_diameter),height=Number(elm.outer_diameter)),"width"in elm&&(width=Number(elm.width)),"height"in elm&&(height=Number(elm.height)),"center"in elm&&elm.center&&typeof elm.center=="object"&&"x"in elm.center&&"y"in elm.center&&(centerX=Number(elm.center.x),centerY=Number(elm.center.y));let rotation5=0;if("rotation"in elm&&typeof elm.rotation=="number"&&(rotation5=elm.rotation),"ccw_rotation"in elm&&typeof elm.ccw_rotation=="number"&&(rotation5=elm.ccw_rotation),centerX!==void 0&&centerY!==void 0)return width!==void 0&&height!==void 0?rotation5?getRotatedRectBounds(centerX,centerY,width,height,rotation5):{minX:centerX-width/2,minY:centerY-height/2,maxX:centerX+width/2,maxY:centerY+height/2}:"radius"in elm&&typeof elm.radius=="number"?getCircleBounds(centerX,centerY,elm.radius*2):{minX:centerX,minY:centerY,maxX:centerX,maxY:centerY};let anchoredPoint=[elementRecord.anchor_position,elementRecord.position].filter(position4=>!!(position4&&typeof position4=="object"&&"x"in position4&&"y"in position4&&typeof position4.x=="number"&&typeof position4.y=="number")).at(0);return anchoredPoint?{minX:anchoredPoint.x,minY:anchoredPoint.y,maxX:anchoredPoint.x,maxY:anchoredPoint.y}:null},getBoundsOfPcbElements=elements=>{let bounds={minX:Number.POSITIVE_INFINITY,minY:Number.POSITIVE_INFINITY,maxX:Number.NEGATIVE_INFINITY,maxY:Number.NEGATIVE_INFINITY};for(let element of elements){let elementBounds=getPcbElementBounds(element);elementBounds&&(bounds=mergeBounds(bounds,elementBounds))}return bounds},getBoardBounds=board=>{if(board.width&&board.height&&board.center){let halfWidth=board.width/2,halfHeight=board.height/2;return{minX:board.center.x-halfWidth,minY:board.center.y-halfHeight,maxX:board.center.x+halfWidth,maxY:board.center.y+halfHeight,width:board.width,height:board.height,center:{x:board.center.x,y:board.center.y}}}if(!board.outline||board.outline.length===0)throw new Error("Unable to compute board bounds. pcb_board must include width/height/center or a non-empty outline.");let minX=Number.POSITIVE_INFINITY,minY=Number.POSITIVE_INFINITY,maxX=Number.NEGATIVE_INFINITY,maxY=Number.NEGATIVE_INFINITY;for(let point7 of board.outline)minX=Math.min(minX,point7.x),minY=Math.min(minY,point7.y),maxX=Math.max(maxX,point7.x),maxY=Math.max(maxY,point7.y);let width=maxX-minX,height=maxY-minY;return{minX,minY,maxX,maxY,width,height,center:{x:minX+width/2,y:minY+height/2}}},SCHEMATIC_TRACE_WIDTH=.1,SCHEMATIC_NET_LABEL_FONT_SIZE=.18,SCHEMATIC_NET_LABEL_HEIGHT=.2,createBounds=({minX,minY,maxX,maxY})=>{let width=maxX-minX,height=maxY-minY;return{minX,minY,maxX,maxY,width,height,center:{x:minX+width/2,y:minY+height/2}}},getSchematicNetLabelTextWidth=text=>{let characterWidth=.12*(SCHEMATIC_NET_LABEL_FONT_SIZE/.18),horizontalPadding=.12*(SCHEMATIC_NET_LABEL_FONT_SIZE/.18);return text.length*characterWidth+horizontalPadding},getSchematicNetLabelBounds=netLabel=>{let labelLength=getSchematicNetLabelTextWidth(netLabel.text),anchor3=netLabel.anchor_position;if(!anchor3){let isVertical6=netLabel.anchor_side==="top"||netLabel.anchor_side==="bottom",width=isVertical6?SCHEMATIC_NET_LABEL_HEIGHT:labelLength,height=isVertical6?labelLength:SCHEMATIC_NET_LABEL_HEIGHT;return createBounds({minX:netLabel.center.x-width/2,minY:netLabel.center.y-height/2,maxX:netLabel.center.x+width/2,maxY:netLabel.center.y+height/2})}switch(netLabel.anchor_side){case"left":return createBounds({minX:anchor3.x,minY:anchor3.y-SCHEMATIC_NET_LABEL_HEIGHT/2,maxX:anchor3.x+labelLength,maxY:anchor3.y+SCHEMATIC_NET_LABEL_HEIGHT/2});case"right":return createBounds({minX:anchor3.x-labelLength,minY:anchor3.y-SCHEMATIC_NET_LABEL_HEIGHT/2,maxX:anchor3.x,maxY:anchor3.y+SCHEMATIC_NET_LABEL_HEIGHT/2});case"top":return createBounds({minX:anchor3.x-SCHEMATIC_NET_LABEL_HEIGHT/2,minY:anchor3.y-labelLength,maxX:anchor3.x+SCHEMATIC_NET_LABEL_HEIGHT/2,maxY:anchor3.y});case"bottom":return createBounds({minX:anchor3.x-SCHEMATIC_NET_LABEL_HEIGHT/2,minY:anchor3.y,maxX:anchor3.x+SCHEMATIC_NET_LABEL_HEIGHT/2,maxY:anchor3.y+labelLength})}},getSchematicElementBounds=element=>{if(element.type==="schematic_component")return createBounds({minX:element.center.x-element.size.width/2,minY:element.center.y-element.size.height/2,maxX:element.center.x+element.size.width/2,maxY:element.center.y+element.size.height/2});if(element.type==="schematic_net_label")return getSchematicNetLabelBounds(element);let points=[...element.edges.flatMap(edge=>[edge.from,edge.to]),...element.junctions];if(points.length===0)return null;let halfTraceWidth=SCHEMATIC_TRACE_WIDTH/2;return createBounds({minX:Math.min(...points.map(point7=>point7.x))-halfTraceWidth,minY:Math.min(...points.map(point7=>point7.y))-halfTraceWidth,maxX:Math.max(...points.map(point7=>point7.x))+halfTraceWidth,maxY:Math.max(...points.map(point7=>point7.y))+halfTraceWidth})};nice_color_palettes=[["#69d2e7","#a7dbd8","#e0e4cc","#f38630","#fa6900"],["#fe4365","#fc9d9a","#f9cdad","#c8c8a9","#83af9b"],["#ecd078","#d95b43","#c02942","#542437","#53777a"],["#556270","#4ecdc4","#c7f464","#ff6b6b","#c44d58"],["#774f38","#e08e79","#f1d4af","#ece5ce","#c5e0dc"],["#e8ddcb","#cdb380","#036564","#033649","#031634"],["#490a3d","#bd1550","#e97f02","#f8ca00","#8a9b0f"],["#594f4f","#547980","#45ada8","#9de0ad","#e5fcc2"],["#00a0b0","#6a4a3c","#cc333f","#eb6841","#edc951"],["#e94e77","#d68189","#c6a49a","#c6e5d9","#f4ead5"],["#3fb8af","#7fc7af","#dad8a7","#ff9e9d","#ff3d7f"],["#d9ceb2","#948c75","#d5ded9","#7a6a53","#99b2b7"],["#ffffff","#cbe86b","#f2e9e1","#1c140d","#cbe86b"],["#efffcd","#dce9be","#555152","#2e2633","#99173c"],["#343838","#005f6b","#008c9e","#00b4cc","#00dffc"],["#413e4a","#73626e","#b38184","#f0b49e","#f7e4be"],["#ff4e50","#fc913a","#f9d423","#ede574","#e1f5c4"],["#99b898","#fecea8","#ff847c","#e84a5f","#2a363b"],["#655643","#80bca3","#f6f7bd","#e6ac27","#bf4d28"],["#00a8c6","#40c0cb","#f9f2e7","#aee239","#8fbe00"],["#351330","#424254","#64908a","#e8caa4","#cc2a41"],["#554236","#f77825","#d3ce3d","#f1efa5","#60b99a"],["#5d4157","#838689","#a8caba","#cad7b2","#ebe3aa"],["#8c2318","#5e8c6a","#88a65e","#bfb35a","#f2c45a"],["#fad089","#ff9c5b","#f5634a","#ed303c","#3b8183"],["#ff4242","#f4fad2","#d4ee5e","#e1edb9","#f0f2eb"],["#f8b195","#f67280","#c06c84","#6c5b7b","#355c7d"],["#d1e751","#ffffff","#000000","#4dbce9","#26ade4"],["#1b676b","#519548","#88c425","#bef202","#eafde6"],["#5e412f","#fcebb6","#78c0a8","#f07818","#f0a830"],["#bcbdac","#cfbe27","#f27435","#f02475","#3b2d38"],["#452632","#91204d","#e4844a","#e8bf56","#e2f7ce"],["#eee6ab","#c5bc8e","#696758","#45484b","#36393b"],["#f0d8a8","#3d1c00","#86b8b1","#f2d694","#fa2a00"],["#2a044a","#0b2e59","#0d6759","#7ab317","#a0c55f"],["#f04155","#ff823a","#f2f26f","#fff7bd","#95cfb7"],["#b9d7d9","#668284","#2a2829","#493736","#7b3b3b"],["#bbbb88","#ccc68d","#eedd99","#eec290","#eeaa88"],["#b3cc57","#ecf081","#ffbe40","#ef746f","#ab3e5b"],["#a3a948","#edb92e","#f85931","#ce1836","#009989"],["#300030","#480048","#601848","#c04848","#f07241"],["#67917a","#170409","#b8af03","#ccbf82","#e33258"],["#aab3ab","#c4cbb7","#ebefc9","#eee0b7","#e8caaf"],["#e8d5b7","#0e2430","#fc3a51","#f5b349","#e8d5b9"],["#ab526b","#bca297","#c5ceae","#f0e2a4","#f4ebc3"],["#607848","#789048","#c0d860","#f0f0d8","#604848"],["#b6d8c0","#c8d9bf","#dadabd","#ecdbbc","#fedcba"],["#a8e6ce","#dcedc2","#ffd3b5","#ffaaa6","#ff8c94"],["#3e4147","#fffedf","#dfba69","#5a2e2e","#2a2c31"],["#fc354c","#29221f","#13747d","#0abfbc","#fcf7c5"],["#cc0c39","#e6781e","#c8cf02","#f8fcc1","#1693a7"],["#1c2130","#028f76","#b3e099","#ffeaad","#d14334"],["#a7c5bd","#e5ddcb","#eb7b59","#cf4647","#524656"],["#dad6ca","#1bb0ce","#4f8699","#6a5e72","#563444"],["#5c323e","#a82743","#e15e32","#c0d23e","#e5f04c"],["#edebe6","#d6e1c7","#94c7b6","#403b33","#d3643b"],["#fdf1cc","#c6d6b8","#987f69","#e3ad40","#fcd036"],["#230f2b","#f21d41","#ebebbc","#bce3c5","#82b3ae"],["#b9d3b0","#81bda4","#b28774","#f88f79","#f6aa93"],["#3a111c","#574951","#83988e","#bcdea5","#e6f9bc"],["#5e3929","#cd8c52","#b7d1a3","#dee8be","#fcf7d3"],["#1c0113","#6b0103","#a30006","#c21a01","#f03c02"],["#000000","#9f111b","#b11623","#292c37","#cccccc"],["#382f32","#ffeaf2","#fcd9e5","#fbc5d8","#f1396d"],["#e3dfba","#c8d6bf","#93ccc6","#6cbdb5","#1a1f1e"],["#f6f6f6","#e8e8e8","#333333","#990100","#b90504"],["#1b325f","#9cc4e4","#e9f2f9","#3a89c9","#f26c4f"],["#a1dbb2","#fee5ad","#faca66","#f7a541","#f45d4c"],["#c1b398","#605951","#fbeec2","#61a6ab","#accec0"],["#5e9fa3","#dcd1b4","#fab87f","#f87e7b","#b05574"],["#951f2b","#f5f4d7","#e0dfb1","#a5a36c","#535233"],["#8dccad","#988864","#fea6a2","#f9d6ac","#ffe9af"],["#2d2d29","#215a6d","#3ca2a2","#92c7a3","#dfece6"],["#413d3d","#040004","#c8ff00","#fa023c","#4b000f"],["#eff3cd","#b2d5ba","#61ada0","#248f8d","#605063"],["#ffefd3","#fffee4","#d0ecea","#9fd6d2","#8b7a5e"],["#cfffdd","#b4dec1","#5c5863","#a85163","#ff1f4c"],["#9dc9ac","#fffec7","#f56218","#ff9d2e","#919167"],["#4e395d","#827085","#8ebe94","#ccfc8e","#dc5b3e"],["#a8a7a7","#cc527a","#e8175d","#474747","#363636"],["#f8edd1","#d88a8a","#474843","#9d9d93","#c5cfc6"],["#046d8b","#309292","#2fb8ac","#93a42a","#ecbe13"],["#f38a8a","#55443d","#a0cab5","#cde9ca","#f1edd0"],["#a70267","#f10c49","#fb6b41","#f6d86b","#339194"],["#ff003c","#ff8a00","#fabe28","#88c100","#00c176"],["#ffedbf","#f7803c","#f54828","#2e0d23","#f8e4c1"],["#4e4d4a","#353432","#94ba65","#2790b0","#2b4e72"],["#0ca5b0","#4e3f30","#fefeeb","#f8f4e4","#a5b3aa"],["#4d3b3b","#de6262","#ffb88c","#ffd0b3","#f5e0d3"],["#fffbb7","#a6f6af","#66b6ab","#5b7c8d","#4f2958"],["#edf6ee","#d1c089","#b3204d","#412e28","#151101"],["#9d7e79","#ccac95","#9a947c","#748b83","#5b756c"],["#fcfef5","#e9ffe1","#cdcfb7","#d6e6c3","#fafbe3"],["#9cddc8","#bfd8ad","#ddd9ab","#f7af63","#633d2e"],["#30261c","#403831","#36544f","#1f5f61","#0b8185"],["#aaff00","#ffaa00","#ff00aa","#aa00ff","#00aaff"],["#d1313d","#e5625c","#f9bf76","#8eb2c5","#615375"],["#ffe181","#eee9e5","#fad3b2","#ffba7f","#ff9c97"],["#73c8a9","#dee1b6","#e1b866","#bd5532","#373b44"],["#805841","#dcf7f3","#fffcdd","#ffd8d8","#f5a2a2"]],getDebugLayoutObject=lo3=>{let{x:x11,y:y11,width,height}={...lo3,...lo3.size,...lo3.center,...lo3.position};if(lo3.x1!==void 0&&lo3.x2!==void 0&&lo3.y1!==void 0&&lo3.y2!==void 0&&(x11=(lo3.x1+lo3.x2)/2,y11=(lo3.y1+lo3.y2)/2,width=Math.abs(lo3.x1-lo3.x2),height=Math.abs(lo3.y1-lo3.y2)),lo3.points&&Array.isArray(lo3.points)&&lo3.points.length>0){let xCoords=lo3.points.map(point7=>point7.x),yCoords=lo3.points.map(point7=>point7.y),minX=Math.min(...xCoords),maxX=Math.max(...xCoords),minY=Math.min(...yCoords),maxY=Math.max(...yCoords);x11=(minX+maxX)/2,y11=(minY+maxY)/2,width=maxX-minX,height=maxY-minY}let title=lo3.text||lo3.name||lo3.source?.text||lo3.source?.name||"?",content=lo3;return x11===void 0||y11===void 0?null:(width===void 0&&("radius"in lo3?(width=lo3.radius*2,height=lo3.radius*2):"outer_diameter"in lo3?(width=lo3.outer_diameter,height=lo3.outer_diameter):"rect_pad_width"in lo3&&"rect_pad_height"in lo3?(width=lo3.rect_pad_width,height=lo3.rect_pad_height,"hole_diameter"in lo3&&(width=Math.max(width,lo3.hole_diameter),height=Math.max(height,lo3.hole_diameter))):"hole_diameter"in lo3&&(width=lo3.hole_diameter,height=lo3.hole_diameter)),(width===void 0||height===void 0)&&(width=.1,height=.1),{x:x11,y:y11,width,height,title,content,bg_color:nice_color_palettes[stringHash(lo3.type||title)%nice_color_palettes.length]?.[4]??"#f00"})},isTruthy=value=>!!value,findBoundsAndCenter=elements=>{let debugObjects=elements.filter(elm=>elm.type.startsWith("pcb_")||elm.type.startsWith("schematic_")).concat(elements.filter(elm=>elm.type==="pcb_trace"||elm.type==="schematic_trace").flatMap(elm=>elm.route)).map(elm=>getDebugLayoutObject(elm)).filter(isTruthy);if(debugObjects.length===0)return{center:{x:0,y:0},width:0,height:0};let minX=debugObjects[0].x-debugObjects[0].width/2,maxX=debugObjects[0].x+debugObjects[0].width/2,minY=debugObjects[0].y-debugObjects[0].height/2,maxY=debugObjects[0].y+debugObjects[0].height/2;for(let obj of debugObjects.slice(1))minX=Math.min(minX,obj.x-obj.width/2),maxX=Math.max(maxX,obj.x+obj.width/2),minY=Math.min(minY,obj.y-obj.height/2),maxY=Math.max(maxY,obj.y+obj.height/2);let width=maxX-minX,height=maxY-minY;return{center:{x:minX+width/2,y:minY+height/2},width,height}},getPrimaryId=element=>element[`${element.type}_id`],repositionPcbComponentTo=(circuitJson,pcb_component_id,newCenter)=>{let pcbComponent=circuitJson.find(e55=>e55.type==="pcb_component"&&e55.pcb_component_id===pcb_component_id);if(!pcbComponent)return;let currentCenter="center"in pcbComponent?pcbComponent.center:{x:pcbComponent.x,y:pcbComponent.y},dx4=newCenter.x-currentCenter.x,dy4=newCenter.y-currentCenter.y,portIds=circuitJson.filter(e55=>e55.type==="pcb_port"&&e55.pcb_component_id===pcb_component_id).map(e55=>e55.pcb_port_id),elementsToMove=circuitJson.filter(elm=>{if(elm===pcbComponent)return!0;let anyElm=elm;return!!(anyElm.pcb_component_id===pcb_component_id||Array.isArray(anyElm.pcb_component_ids)&&anyElm.pcb_component_ids.includes(pcb_component_id)||anyElm.pcb_port_id&&portIds.includes(anyElm.pcb_port_id)||Array.isArray(anyElm.pcb_port_ids)&&anyElm.pcb_port_ids.some(id3=>portIds.includes(id3))||anyElm.start_pcb_port_id&&portIds.includes(anyElm.start_pcb_port_id)||anyElm.end_pcb_port_id&&portIds.includes(anyElm.end_pcb_port_id)||Array.isArray(anyElm.route)&&anyElm.route.some(pt5=>pt5.start_pcb_port_id&&portIds.includes(pt5.start_pcb_port_id)||pt5.end_pcb_port_id&&portIds.includes(pt5.end_pcb_port_id)))}),matrix2=translate(dx4,dy4);transformPCBElements(elementsToMove,matrix2)},findAllDescendantGroupIds=(circuitJson,parentGroupId)=>{let childGroupIds=[],directChildren=circuitJson.filter(elm=>elm.type==="source_group"&&elm.parent_source_group_id===parentGroupId).map(elm=>elm.source_group_id);childGroupIds.push(...directChildren);for(let childId of directChildren)childGroupIds.push(...findAllDescendantGroupIds(circuitJson,childId));return childGroupIds},repositionPcbGroupTo=(circuitJson,source_group_id,newCenter)=>{let allGroupIds=[source_group_id,...findAllDescendantGroupIds(circuitJson,source_group_id)],allGroupElements=new Set;for(let groupId of allGroupIds)buildSubtree(circuitJson,{source_group_id:groupId}).forEach(elm=>allGroupElements.add(elm));let portIds=Array.from(allGroupElements).filter(e55=>e55.type==="pcb_port").map(e55=>e55.pcb_port_id);circuitJson.filter(elm=>{if(elm.type!=="pcb_trace"||allGroupElements.has(elm))return!1;let anyElm=elm;return!!(anyElm.start_pcb_port_id&&portIds.includes(anyElm.start_pcb_port_id)||anyElm.end_pcb_port_id&&portIds.includes(anyElm.end_pcb_port_id)||Array.isArray(anyElm.route)&&anyElm.route.some(pt5=>pt5.start_pcb_port_id&&portIds.includes(pt5.start_pcb_port_id)||pt5.end_pcb_port_id&&portIds.includes(pt5.end_pcb_port_id)))}).forEach(trace=>allGroupElements.add(trace));let pcbElements=Array.from(allGroupElements).filter(elm=>elm.type.startsWith("pcb_"));if(pcbElements.length===0)return;let{center:currentCenter}=findBoundsAndCenter(pcbElements),dx4=newCenter.x-currentCenter.x,dy4=newCenter.y-currentCenter.y,matrix2=translate(dx4,dy4);transformPCBElements(pcbElements,matrix2)},repositionSchematicComponentTo=(circuitJson,schematic_component_id,newCenter)=>{let schematicComponent=circuitJson.find(e55=>e55.type==="schematic_component"&&e55.schematic_component_id===schematic_component_id);if(!schematicComponent)return;let currentCenter="center"in schematicComponent?schematicComponent.center:{x:schematicComponent.x,y:schematicComponent.y},dx4=newCenter.x-currentCenter.x,dy4=newCenter.y-currentCenter.y,portIds=circuitJson.filter(e55=>e55.type==="schematic_port"&&e55.schematic_component_id===schematic_component_id).map(e55=>e55.schematic_port_id),elementsToMove=circuitJson.filter(elm=>{if(elm===schematicComponent)return!0;let anyElm=elm;return!!(anyElm.schematic_component_id===schematic_component_id||Array.isArray(anyElm.schematic_component_ids)&&anyElm.schematic_component_ids.includes(schematic_component_id)||anyElm.schematic_port_id&&portIds.includes(anyElm.schematic_port_id)||Array.isArray(anyElm.schematic_port_ids)&&anyElm.schematic_port_ids.some(id3=>portIds.includes(id3))||anyElm.start_schematic_port_id&&portIds.includes(anyElm.start_schematic_port_id)||anyElm.end_schematic_port_id&&portIds.includes(anyElm.end_schematic_port_id)||Array.isArray(anyElm.route)&&anyElm.route.some(pt5=>pt5.start_schematic_port_id&&portIds.includes(pt5.start_schematic_port_id)||pt5.end_schematic_port_id&&portIds.includes(pt5.end_schematic_port_id)))}),matrix2=translate(dx4,dy4);transformSchematicElements(elementsToMove,matrix2)},findAllDescendantGroupIds2=(circuitJson,parentGroupId)=>{let childGroupIds=[],directChildren=circuitJson.filter(elm=>elm.type==="source_group"&&elm.parent_source_group_id===parentGroupId).map(elm=>elm.source_group_id);childGroupIds.push(...directChildren);for(let childId of directChildren)childGroupIds.push(...findAllDescendantGroupIds2(circuitJson,childId));return childGroupIds},repositionSchematicGroupTo=(circuitJson,source_group_id,newCenter)=>{let allGroupIds=[source_group_id,...findAllDescendantGroupIds2(circuitJson,source_group_id)],allGroupElements=new Set;for(let groupId of allGroupIds)buildSubtree(circuitJson,{source_group_id:groupId}).forEach(elm=>allGroupElements.add(elm));let portIds=Array.from(allGroupElements).filter(e55=>e55.type==="schematic_port").map(e55=>e55.schematic_port_id);circuitJson.filter(elm=>{if(elm.type!=="schematic_trace"||allGroupElements.has(elm))return!1;let anyElm=elm;return!!(anyElm.start_schematic_port_id&&portIds.includes(anyElm.start_schematic_port_id)||anyElm.end_schematic_port_id&&portIds.includes(anyElm.end_schematic_port_id)||Array.isArray(anyElm.route)&&anyElm.route.some(pt5=>pt5.start_schematic_port_id&&portIds.includes(pt5.start_schematic_port_id)||pt5.end_schematic_port_id&&portIds.includes(pt5.end_schematic_port_id)))}).forEach(trace=>allGroupElements.add(trace));let schematicElements=Array.from(allGroupElements).filter(elm=>elm.type.startsWith("schematic_"));if(schematicElements.length===0)return;let{center:currentCenter}=findBoundsAndCenter(schematicElements),dx4=newCenter.x-currentCenter.x,dy4=newCenter.y-currentCenter.y,matrix2=translate(dx4,dy4);transformSchematicElements(schematicElements,matrix2)},getCircuitJsonTree=(circuitJson,opts)=>{let groupChildMap=new Map,existingGroupIds=new Set;for(let elm of circuitJson)elm.type==="source_group"&&existingGroupIds.add(elm.source_group_id);let orphanedGroups=[];for(let elm of circuitJson)if(elm.type==="source_group"&&elm.parent_source_group_id){let parentId=elm.parent_source_group_id,childId=elm.source_group_id;if(!existingGroupIds.has(parentId))orphanedGroups.push(childId),groupChildMap.has(childId)||groupChildMap.set(childId,[]);else{let children=groupChildMap.get(parentId)??[];children.push(childId),groupChildMap.set(parentId,children),groupChildMap.has(childId)||groupChildMap.set(childId,[])}}for(let elm of circuitJson)elm.type==="source_group"&&!groupChildMap.has(elm.source_group_id)&&groupChildMap.set(elm.source_group_id,[]);let groupNodes=new Map,getNextGroupId=()=>{for(let[parentId,children]of groupChildMap)if(!groupNodes.has(parentId)&&children.every(childId=>groupNodes.has(childId)))return parentId;return null},lastGroupId=null;for(;;){let nextGroupId=getNextGroupId();if(!nextGroupId)break;let node={nodeType:"group",sourceGroup:circuitJson.find(elm=>elm.type==="source_group"&&elm.source_group_id===nextGroupId),otherChildElements:[],childNodes:[...groupChildMap.get(nextGroupId)?.map(childId=>groupNodes.get(childId))??[],...circuitJson.filter(elm=>elm.type==="source_component"&&elm.source_group_id===nextGroupId).map(elm=>({nodeType:"component",sourceComponent:elm,childNodes:[],otherChildElements:[...circuitJson.filter(e55=>e55.type==="pcb_component"&&e55.source_component_id===elm.source_component_id)]}))]};groupNodes.set(nextGroupId,node),lastGroupId=nextGroupId}if(!lastGroupId)return console.warn("No groups were processed, returning tree without sourceGroup"),{nodeType:"group",childNodes:[],otherChildElements:circuitJson};let rootGroupId=null;return opts&&opts.source_group_id!==void 0?rootGroupId=opts.source_group_id:orphanedGroups.length>0?rootGroupId=orphanedGroups[0]:rootGroupId=lastGroupId,rootGroupId?groupNodes.get(rootGroupId):(console.warn("No valid root group found, returning tree without sourceGroup"),{nodeType:"group",childNodes:[],otherChildElements:circuitJson})};EPSILON2=1e-9,clamp3=(value,min4,max5)=>Math.max(min4,Math.min(max5,value)),distanceBetweenPoints=(a10,b10)=>Math.hypot(a10.x-b10.x,a10.y-b10.y),distanceBetweenPointAndSegment=(point7,a10,b10)=>{let abX=b10.x-a10.x,abY=b10.y-a10.y,lengthSquared=abX*abX+abY*abY;if(lengthSquared<=EPSILON2)return distanceBetweenPoints(point7,a10);let t48=clamp3(((point7.x-a10.x)*abX+(point7.y-a10.y)*abY)/lengthSquared,0,1);return Math.hypot(point7.x-(a10.x+t48*abX),point7.y-(a10.y+t48*abY))},cross4=(a10,b10,c10)=>(b10.x-a10.x)*(c10.y-a10.y)-(b10.y-a10.y)*(c10.x-a10.x),isPointOnSegment2=(point7,a10,b10)=>Math.abs(cross4(a10,b10,point7))>EPSILON2?!1:point7.x>=Math.min(a10.x,b10.x)-EPSILON2&&point7.x<=Math.max(a10.x,b10.x)+EPSILON2&&point7.y>=Math.min(a10.y,b10.y)-EPSILON2&&point7.y<=Math.max(a10.y,b10.y)+EPSILON2,segmentsIntersect=(a12,a22,b12,b22)=>{let c12=cross4(a12,a22,b12),c22=cross4(a12,a22,b22),c32=cross4(b12,b22,a12),c42=cross4(b12,b22,a22);return(c12>EPSILON2&&c22<-EPSILON2||c12<-EPSILON2&&c22>EPSILON2)&&(c32>EPSILON2&&c42<-EPSILON2||c32<-EPSILON2&&c42>EPSILON2)?!0:isPointOnSegment2(b12,a12,a22)||isPointOnSegment2(b22,a12,a22)||isPointOnSegment2(a12,b12,b22)||isPointOnSegment2(a22,b12,b22)},getPolygonEdges2=polygon2=>{let edges=[];if(polygon2.points.length<2)return edges;for(let i11=0;i11<polygon2.points.length;i11+=1){let a10=polygon2.points[i11],b10=polygon2.points[(i11+1)%polygon2.points.length];!a10||!b10||edges.push([a10,b10])}return edges},isPointInPolygon=(point7,polygon2)=>{for(let[a10,b10]of getPolygonEdges2(polygon2))if(isPointOnSegment2(point7,a10,b10))return!0;let inside3=!1;for(let i11=0,j11=polygon2.points.length-1;i11<polygon2.points.length;j11=i11++){let pi3=polygon2.points[i11],pj2=polygon2.points[j11];if(!pi3||!pj2)continue;pi3.y>point7.y!=pj2.y>point7.y&&point7.x<(pj2.x-pi3.x)*(point7.y-pi3.y)/(pj2.y-pi3.y)+pi3.x&&(inside3=!inside3)}return inside3},distanceBetweenCircleAndCircle=(a10,b10)=>Math.max(0,Math.hypot(a10.x-b10.x,a10.y-b10.y)-a10.radius-b10.radius),distanceBetweenPolygonAndPolygon=(a10,b10)=>{if(a10.points.length<3||b10.points.length<3)return Number.POSITIVE_INFINITY;for(let[a12,a22]of getPolygonEdges2(a10))for(let[b12,b22]of getPolygonEdges2(b10))if(segmentsIntersect(a12,a22,b12,b22))return 0;let aPoint=a10.points[0],bPoint=b10.points[0];if(aPoint&&isPointInPolygon(aPoint,b10)||bPoint&&isPointInPolygon(bPoint,a10))return 0;let minDistance=Number.POSITIVE_INFINITY;for(let[a12,a22]of getPolygonEdges2(a10))for(let[b12,b22]of getPolygonEdges2(b10))minDistance=Math.min(minDistance,distanceBetweenPointAndSegment(a12,b12,b22),distanceBetweenPointAndSegment(a22,b12,b22),distanceBetweenPointAndSegment(b12,a12,a22),distanceBetweenPointAndSegment(b22,a12,a22));return minDistance},distanceBetweenCircleAndPolygon=(circle3,polygon2)=>{if(polygon2.points.length<3)return Number.POSITIVE_INFINITY;if(isPointInPolygon({x:circle3.x,y:circle3.y},polygon2))return 0;let minDistanceToEdge=Number.POSITIVE_INFINITY;for(let[start,end]of getPolygonEdges2(polygon2))minDistanceToEdge=Math.min(minDistanceToEdge,distanceBetweenPointAndSegment({x:circle3.x,y:circle3.y},start,end));return Math.max(0,minDistanceToEdge-circle3.radius)},PIN1_LOCATION_PARTS={leftside_top:{side:"leftside",alignment:"top"},leftside_bottom:{side:"leftside",alignment:"bottom"},rightside_top:{side:"rightside",alignment:"top"},rightside_bottom:{side:"rightside",alignment:"bottom"},topside_left:{side:"topside",alignment:"left"},topside_right:{side:"topside",alignment:"right"},bottomside_left:{side:"bottomside",alignment:"left"},bottomside_right:{side:"bottomside",alignment:"right"}},PIN1_LOCATIONS=Object.keys(PIN1_LOCATION_PARTS),getPadCenter2=pad2=>{if(typeof pad2.x=="number"&&typeof pad2.y=="number")return{x:pad2.x,y:pad2.y};if(pad2.points&&pad2.points.length>0){let xs3=pad2.points.map(point7=>point7.x),ys3=pad2.points.map(point7=>point7.y);return{x:(Math.min(...xs3)+Math.max(...xs3))/2,y:(Math.min(...ys3)+Math.max(...ys3))/2}}return null},getPinNumber=pad2=>{for(let hint of pad2.port_hints??[]){let match2=String(hint).trim().match(/^(?:pin)?(\d+)$/i);if(match2)return Number.parseInt(match2[1],10)}return null},getCanonicalRowLocation=(pin1,pin2,tolerance)=>{let dx4=pin2.x-pin1.x,dy4=pin2.y-pin1.y;return Math.abs(dy4)<=tolerance&&Math.abs(dx4)>tolerance?dx4>0?"topside_left":"bottomside_right":Math.abs(dx4)<=tolerance&&Math.abs(dy4)>tolerance?dy4>0?"leftside_bottom":"rightside_top":null},pinMatchesLocation2=(padCenters,pin1Center,pin1Location)=>{let xs3=padCenters.map(point7=>point7.x),ys3=padCenters.map(point7=>point7.y),minX=Math.min(...xs3),maxX=Math.max(...xs3),minY=Math.min(...ys3),maxY=Math.max(...ys3),centerX=(minX+maxX)/2,centerY=(minY+maxY)/2,spanX=maxX-minX,spanY=maxY-minY,tolerance=Math.max(spanX,spanY,1)*1e-6,{side,alignment}=PIN1_LOCATION_PARTS[pin1Location],onRequestedSide=side==="leftside"&&Math.abs(pin1Center.x-minX)<=tolerance||side==="rightside"&&Math.abs(pin1Center.x-maxX)<=tolerance||side==="topside"&&Math.abs(pin1Center.y-maxY)<=tolerance||side==="bottomside"&&Math.abs(pin1Center.y-minY)<=tolerance,atRequestedAlignment=alignment==="left"&&(spanX<=tolerance||pin1Center.x<centerX-tolerance)||alignment==="right"&&(spanX<=tolerance||pin1Center.x>centerX+tolerance)||alignment==="top"&&(spanY<=tolerance||pin1Center.y>centerY+tolerance)||alignment==="bottom"&&(spanY<=tolerance||pin1Center.y<centerY-tolerance);return onRequestedSide&&atRequestedAlignment},analyzePcbPin1Location=elements=>{let numberedPads=elements.filter(element=>element.type==="pcb_smtpad"||element.type==="pcb_plated_hole").map(pad2=>({center:getPadCenter2(pad2),pinNumber:getPinNumber(pad2)})),pin1Center=numberedPads.find(pad2=>pad2.pinNumber===1)?.center,padCenters=numberedPads.map(pad2=>pad2.center).filter(point7=>point7!==null);if(!pin1Center||padCenters.length===0)return null;let candidates=PIN1_LOCATIONS.filter(pin1Location=>pinMatchesLocation2(padCenters,pin1Center,pin1Location));if(candidates.length===1)return candidates[0];if(candidates.length===0)return null;let nextNumberedPad;for(let pad2 of numberedPads)!pad2.center||pad2.pinNumber===null||pad2.pinNumber<=1||(!nextNumberedPad||pad2.pinNumber<nextNumberedPad.pinNumber)&&(nextNumberedPad={center:pad2.center,pinNumber:pad2.pinNumber});if(!nextNumberedPad)return null;let xs3=padCenters.map(point7=>point7.x),ys3=padCenters.map(point7=>point7.y),tolerance=Math.max(Math.max(...xs3)-Math.min(...xs3),Math.max(...ys3)-Math.min(...ys3),1)*1e-6;if(numberedPads.length===2&&nextNumberedPad.pinNumber===2)return getCanonicalRowLocation(pin1Center,nextNumberedPad.center,tolerance);if(numberedPads.length>2){let row=[...numberedPads].sort((a10,b10)=>(a10.pinNumber??Number.POSITIVE_INFINITY)-(b10.pinNumber??Number.POSITIVE_INFINITY));if(row.every(({center:center2,pinNumber},index2)=>pinNumber===index2+1&&center2!==null&&Number.isFinite(center2.x)&&Number.isFinite(center2.y))){let first=row[0].center,last=row[row.length-1].center,dx4=last.x-first.x,dy4=last.y-first.y,horizontal=Math.abs(dy4)<=tolerance&&Math.abs(dx4)>tolerance,vertical=Math.abs(dx4)<=tolerance&&Math.abs(dy4)>tolerance;if((horizontal||vertical)&&row.slice(1).every(({center:center2},index2)=>{let previous=row[index2].center;return horizontal?Math.abs(center2.y-first.y)<=tolerance&&(center2.x-previous.x)*Math.sign(dx4)>tolerance:Math.abs(center2.x-first.x)<=tolerance&&(center2.y-previous.y)*Math.sign(dy4)>tolerance}))return getCanonicalRowLocation(first,row[1].center,tolerance)}}let topologyCandidates=candidates.filter(pin1Location=>{let{side}=PIN1_LOCATION_PARTS[pin1Location];return side==="leftside"||side==="rightside"?Math.abs(nextNumberedPad.center.x-pin1Center.x)<=tolerance:Math.abs(nextNumberedPad.center.y-pin1Center.y)<=tolerance});return topologyCandidates.length===1?topologyCandidates[0]:null},placePolygon=(polygon2,center2,degrees3=0)=>{let{a:a10,b:b10,c:c10,d:d11,e:e55,f:f3}=compose(translate(center2.x,center2.y),rotate(degrees3*Math.PI/180));return polygon2.transform(new Matrix(a10,b10,c10,d11,e55,f3))},ccw=polygon2=>polygon2.orientation()===ORIENTATION.CCW?polygon2:polygon2.reverse(),circlePolygon=(center2,radius)=>ccw(new Polygon$1(new Circle$1(new Point$2(center2.x,center2.y),radius))),roundedRectangle=(center2,width,height,radius=0,degrees3=0)=>{let x11=width/2,y11=height/2,r11=Math.max(0,Math.min(radius,x11,y11));if(r11===0)return placePolygon(ccw(new Polygon$1(new Box(-x11,-y11,x11,y11))),center2,degrees3);let arcs=[new Arc(new Point$2(x11-r11,-y11+r11),r11,-Math.PI/2,0,!0),new Arc(new Point$2(x11-r11,y11-r11),r11,0,Math.PI/2,!0),new Arc(new Point$2(-x11+r11,y11-r11),r11,Math.PI/2,Math.PI,!0),new Arc(new Point$2(-x11+r11,-y11+r11),r11,Math.PI,Math.PI*1.5,!0)],edges=[];for(let i11=0;i11<arcs.length;i11++){let arc2=arcs[i11],next2=arcs[(i11+1)%arcs.length];edges.push(arc2),arc2.end.distanceTo(next2.start)[0]>1e-12&&edges.push(new Segment$1(arc2.end,next2.start))}return placePolygon(ccw(new Polygon$1(edges)),center2,degrees3)},ringPolygon=ring4=>{let edges=[];for(let i11=0;i11<ring4.vertices.length;i11++){let start=ring4.vertices[i11],end=ring4.vertices[(i11+1)%ring4.vertices.length],dx4=end.x-start.x,dy4=end.y-start.y;if(dx4===0&&dy4===0)continue;let bulge=start.bulge??0;if(bulge===0)edges.push(new Segment$1(new Point$2(start.x,start.y),new Point$2(end.x,end.y)));else{let offset2=(1-bulge*bulge)/(4*bulge),center2=new Point$2((start.x+end.x)/2-dy4*offset2,(start.y+end.y)/2+dx4*offset2);edges.push(new Arc(center2,Math.hypot(dx4,dy4)*(1+bulge*bulge)/(4*Math.abs(bulge)),Math.atan2(start.y-center2.y,start.x-center2.x),Math.atan2(end.y-center2.y,end.x-center2.x),bulge>0))}}return ccw(new Polygon$1(edges))},subtractHole=(outer,hole)=>{for(let face of hole.reverse().faces)outer.addFace(face.shapes);return outer},getPourPolygon=pour=>{if(pour.shape==="rect")return roundedRectangle(pour.center,pour.width,pour.height,0,pour.rotation);if(pour.shape==="polygon")return ccw(new Polygon$1(pour.points.map(p11=>new Point$2(p11.x,p11.y))));let polygon2=ringPolygon(pour.brep_shape.outer_ring);for(let ring4 of pour.brep_shape.inner_rings)subtractHole(polygon2,ringPolygon(ring4));return polygon2},getSmtPadPolygon=pad2=>{if(pad2.shape==="polygon")return ccw(new Polygon$1(pad2.points.map(p11=>new Point$2(p11.x,p11.y))));if(pad2.shape==="circle")return circlePolygon(pad2,pad2.radius);let radius=pad2.shape==="pill"||pad2.shape==="rotated_pill"?pad2.radius:pad2.corner_radius??pad2.rect_border_radius??0;return roundedRectangle(pad2,pad2.width,pad2.height,radius,"ccw_rotation"in pad2?pad2.ccw_rotation:0)},getViaPolygon=(center2,outerDiameter,holeDiameter)=>subtractHole(circlePolygon(center2,outerDiameter/2),circlePolygon(center2,holeDiameter/2)),getPlatedHolePolygon=(pad2,componentRotation=0)=>{if(pad2.shape==="circle")return getViaPolygon(pad2,pad2.outer_diameter,pad2.hole_diameter);if("outer_width"in pad2)return subtractHole(roundedRectangle(pad2,pad2.outer_width,pad2.outer_height,Math.min(pad2.outer_width,pad2.outer_height)/2,pad2.ccw_rotation),roundedRectangle(pad2,pad2.hole_width,pad2.hole_height,Math.min(pad2.hole_width,pad2.hole_height)/2,pad2.ccw_rotation));let center2={x:pad2.x+pad2.hole_offset_x,y:pad2.y+pad2.hole_offset_y},outer=pad2.shape==="hole_with_polygon_pad"?placePolygon(ccw(new Polygon$1(pad2.pad_outline.map(p11=>new Point$2(p11.x,p11.y)))),pad2,pad2.ccw_rotation??componentRotation):roundedRectangle(pad2,pad2.rect_pad_width,pad2.rect_pad_height,pad2.rect_border_radius,"rect_ccw_rotation"in pad2?pad2.rect_ccw_rotation:0);if(pad2.shape==="circular_hole_with_rect_pad"||pad2.shape==="hole_with_polygon_pad"&&pad2.hole_shape==="circle"){if(pad2.hole_diameter===void 0)throw new Error("Circular plated hole requires hole_diameter");return subtractHole(outer,circlePolygon(center2,pad2.hole_diameter/2))}if(!("hole_width"in pad2)||pad2.hole_width===void 0||pad2.hole_height===void 0)throw new Error("Slotted plated hole requires hole_width and hole_height");return subtractHole(outer,roundedRectangle(center2,pad2.hole_width,pad2.hole_height,Math.min(pad2.hole_width,pad2.hole_height)/2,"hole_ccw_rotation"in pad2?pad2.hole_ccw_rotation:pad2.shape==="hole_with_polygon_pad"?pad2.ccw_rotation??componentRotation:0))},getTraceSegmentPolygon=(start,end,startWidth,endWidth=startWidth)=>{let length14=Math.hypot(end.x-start.x,end.y-start.y),r12=startWidth/2,r22=endWidth/2;if(length14<=Math.abs(r22-r12))return circlePolygon(r12>=r22?start:end,Math.max(r12,r22));let angle3=Math.atan2(end.y-start.y,end.x-start.x),tangent=Math.acos((r12-r22)/length14),first=new Arc(new Point$2(start.x,start.y),r12,angle3+tangent,angle3-tangent,!0),second=new Arc(new Point$2(end.x,end.y),r22,angle3-tangent,angle3+tangent,!0);return ccw(new Polygon$1([first,new Segment$1(first.end,second.start),second,new Segment$1(second.end,first.start)]))},copperPolygonsTouch=(a10,b10,tolerance=1e-7)=>a10.vertices.some(p11=>b10.contains(p11))||b10.vertices.some(p11=>a10.contains(p11))||a10.distanceTo(b10)[0]<=tolerance}});var svgAlphabet,lineAlphabet,strokeWidthRatio,glyphWidthRatio,spaceWidthRatio,lineHeightRatio,letterSpacingRatio,glyphAdvanceRatio,textMetrics,init_dist8=__esm({"node_modules/@tscircuit/alphabet/dist/index.js"(){"use strict";svgAlphabet={0:"M0.301025 0.257813 L0.206593 0.283385 L0.122042 0.361307 L0.075923 0.474441 L0.064942 0.642221 L0.091296 0.78289 L0.159376 0.899463 L0.257104 0.961214 L0.344948 0.961214 L0.442678 0.899463 L0.510757 0.78289 L0.537111 0.642221 L0.526131 0.474441 L0.480012 0.361307 L0.39546 0.283385 L0.301025 0.257813",1:"M0.220426 0.40845 L0.381626 0.270996 L0.381626 0.948966",2:"M0.110409 0.39212 L0.125621 0.342293 L0.170571 0.295823 L0.244237 0.26431 L0.291518 0.257813 L0.373319 0.263799 L0.434683 0.290705 L0.468239 0.331966 L0.480292 0.379913 L0.479492 0.411806 L0.465088 0.465192 L0.402571 0.568988 L0.245134 0.766438 L0.07959 0.948045 L0.522462 0.948045",3:"M0.081606 0.345073 L0.119154 0.315633 L0.178996 0.284091 L0.255265 0.257813 L0.349133 0.263062 L0.43127 0.289348 L0.48994 0.336662 L0.525141 0.394491 L0.513407 0.457577 L0.466472 0.504892 L0.384334 0.541692 L0.290464 0.56272 L0.20833 0.573235 L0.290464 0.583749 L0.384334 0.610035 L0.466472 0.652092 L0.519274 0.709922 L0.531007 0.773007 L0.50754 0.841351 L0.454738 0.899179 L0.3726 0.946494 L0.310412 0.961214 L0.209503 0.959111 L0.127367 0.946494 L0.071046 0.929671",4:"M0.418494 0.270996 L0.048828 0.724199 L0.553224 0.724199 M0.414181 0.578167 L0.414181 0.94897",5:"M0.074951 0.270996 L0.074951 0.614701 L0.267655 0.5695 L0.405247 0.586502 L0.460002 0.617189 L0.498028 0.660731 L0.527101 0.779401 L0.513352 0.841049 L0.477274 0.889568 L0.406378 0.93463 L0.324445 0.958337 L0.247399 0.962139 L0.182516 0.949767 L0.130068 0.925508 L0.074951 0.875607 M0.074951 0.270996 L0.527101 0.270996",6:"M0.428549 0.257813 L0.341433 0.285053 L0.26073 0.312099 L0.192188 0.360182 L0.138902 0.410969 L0.098219 0.500422 L0.070249 0.584267 L0.067264 0.670716 L0.065164 0.756863 L0.087163 0.820973 L0.108168 0.861042 L0.157916 0.913131 L0.210981 0.948192 L0.29279 0.961214 L0.384548 0.956206 L0.456409 0.924151 L0.507262 0.881077 L0.5349 0.821975 L0.537111 0.771889 L0.521634 0.718798 L0.498418 0.67372 L0.463042 0.636657 L0.414398 0.613617 L0.34696 0.598591 L0.28284 0.595587 L0.215403 0.605604 L0.145756 0.641665 L0.109274 0.678729 L0.064942 0.724006",7:"M0.071534 0.270996 L0.530519 0.270996 L0.495935 0.291702 L0.477752 0.305407 L0.435186 0.346112 L0.412067 0.374136 L0.388565 0.40796 L0.365315 0.448098 L0.342943 0.495062 L0.322081 0.549366 L0.303364 0.611524 L0.287416 0.68205 L0.270077 0.80465 L0.26253 0.94897",8:"M0.286761 0.257813 L0.210684 0.27162 L0.1414 0.305622 L0.092494 0.382125 L0.111513 0.450128 L0.16857 0.502193 L0.228345 0.539382 L0.377781 0.594635 L0.470161 0.645637 L0.52586 0.706203 L0.538087 0.792269 L0.506841 0.87621 L0.438915 0.927212 L0.339743 0.961214 L0.263666 0.959089 L0.174004 0.929337 L0.102003 0.881523 L0.063965 0.811395 L0.066682 0.741266 L0.102003 0.671139 L0.180797 0.608448 L0.259591 0.580822 L0.358762 0.548945 L0.456576 0.49688 L0.486463 0.446941 L0.487822 0.362999 L0.453859 0.302434 L0.384574 0.265245 L0.286761 0.257813",9:"M0.511026 0.437812 L0.491026 0.347812 L0.451026 0.297812 L0.391026 0.267812 L0.311026 0.257813 L0.231026 0.267812 L0.161026 0.297812 L0.111026 0.347812 L0.091026 0.417812 L0.111026 0.487812 L0.161026 0.537812 L0.231026 0.567812 L0.311026 0.577812 L0.391026 0.557812 L0.451026 0.517812 L0.491026 0.477812 L0.511026 0.437812 M0.510026 0.438812 L0.434026 0.636812 L0.381026 0.777812 L0.337026 0.879812 L0.301026 0.957812","!":"M0.301026 0.270996 L0.301026 0.749566 M0.251466 0.94897 L0.350587 0.94897",'"':"M0.16504 0.270996 L0.16504 0.523022 M0.437013 0.270996 L0.437013 0.523022","#":"M0.20958 0.282227 L0.146515 0.949754 M0.461844 0.282227 L0.398779 0.949754 M0.032999 0.526969 L0.600587 0.452796 M0.001465 0.82366 L0.569055 0.749486",$:"M0.307121 0.240234 L0.307121 1.083502 M0.490031 0.415915 L0.404676 0.328075 L0.23396 0.310507 L0.136407 0.398347 L0.099828 0.521324 L0.124213 0.591596 L0.197379 0.644299 L0.429061 0.697003 L0.502224 0.749708 L0.526613 0.837547 L0.477836 0.960526 L0.355897 1.013228 L0.197379 0.99566 L0.112021 0.942957 L0.07544 0.837547","'":"M0.301026 0.270996 L0.301026 0.523022","(":"M0.413087 0.241211 L0.372337 0.28347 L0.331589 0.334184 L0.290838 0.393349 L0.25009 0.460965 L0.219528 0.528584 L0.199153 0.5962 L0.188966 0.655364 L0.199153 0.714529 L0.219528 0.782146 L0.25009 0.849764 L0.290838 0.91738 L0.331589 0.976544 L0.372337 1.027258 L0.413087 1.069491",")":"M0.188966 0.241211 L0.229716 0.28347 L0.270466 0.334184 L0.311213 0.393349 L0.351964 0.460965 L0.382526 0.528584 L0.4029 0.5962 L0.413087 0.655364 L0.4029 0.714529 L0.382526 0.782146 L0.351964 0.849764 L0.311213 0.91738 L0.270466 0.976544 L0.229716 1.027258 L0.188966 1.069491","*":"M0.301026 0.458702 L0.301026 0.681942 M0.301026 0.458702 L0.520997 0.536834 M0.301026 0.458702 L0.439954 0.257813 M0.301026 0.458702 L0.162098 0.257813 M0.301026 0.458702 L0.081055 0.536834","+":"M0.042969 0.66845 L0.559083 0.66845 M0.301023 0.428223 L0.301023 0.908661",",":"M0.38672 0.852051 L0.215333 1.030661 L0.301025 1.119971","-":"M0.173829 0.686035 L0.428224 0.686035",".":"M0.362549 0.851074 L0.239503 0.851074","/":"M0.062501 1.035249 L0.539551 0.270996","<":"M0.559083 0.441895 L0.042969 0.66939 L0.042969 0.66939 L0.559083 0.896902","=":"M0.042969 0.545898 L0.559083 0.545898 M0.042969 0.80837 L0.559083 0.80837",">":"M0.042969 0.441895 L0.559083 0.66939 L0.559083 0.66939 L0.042969 0.896902",A:"M0.018067 0.94897 L0.290179 0.270996 L0.583986 0.94897 M0.155303 0.684521 L0.433548 0.684521",B:"M0.063965 0.94897 L0.063965 0.278953 L0.209356 0.270996 L0.342486 0.294394 L0.432179 0.37292 L0.418224 0.48773 L0.312686 0.549166 L0.084728 0.575531 L0.306377 0.589434 L0.468877 0.647456 L0.538087 0.736658 L0.5324 0.85202 L0.501247 0.902983 L0.42355 0.944398 L0.063965 0.94897",C:"M0.529054 0.419847 L0.498425 0.345196 L0.442238 0.292341 L0.33583 0.257813 L0.257199 0.268357 L0.187906 0.303748 L0.120243 0.385432 L0.072998 0.599844 L0.110073 0.815385 L0.165381 0.902183 L0.222883 0.942801 L0.334904 0.961214 L0.43253 0.937679 L0.504816 0.868999 L0.529054 0.772065",D:"M0.064454 0.94897 L0.071838 0.285078 L0.171217 0.270996 L0.247348 0.272633 L0.37101 0.306078 L0.462461 0.378304 L0.514748 0.475555 L0.535591 0.576392 L0.537599 0.652313 L0.528065 0.717381 L0.508562 0.772419 L0.445948 0.855695 L0.362356 0.90871 L0.225203 0.945862 L0.064454 0.94897",E:"M0.080078 0.270996 L0.080078 0.94897 M0.080078 0.270996 L0.521974 0.270996 M0.080078 0.609981 L0.389405 0.609981 M0.080078 0.94897 L0.521974 0.94897",F:"M0.086426 0.270996 L0.086426 0.94897 M0.091304 0.275607 L0.515626 0.275607 M0.091304 0.607677 L0.447344 0.607677",G:"M0.498034 0.284943 L0.374621 0.257813 L0.244219 0.268648 L0.160577 0.311997 L0.094556 0.398116 L0.056397 0.58404 L0.076752 0.785532 L0.120865 0.858197 L0.188947 0.916734 L0.271008 0.953591 L0.357069 0.961214 L0.43715 0.932047 L0.501262 0.858539 L0.545656 0.648611 L0.329595 0.648131",H:"M0.066895 0.270996 L0.066895 0.94897 M0.066895 0.595658 L0.530009 0.595658 M0.535157 0.270996 L0.535157 0.94897",I:"M0.301026 0.270996 L0.301026 0.94897",J:"M0.506839 0.270996 L0.507814 0.782193 L0.498468 0.846168 L0.480733 0.880789 L0.455864 0.90832 L0.426095 0.929408 L0.360746 0.954812 L0.302508 0.962139 L0.223573 0.953638 L0.16538 0.930312 L0.137072 0.907715 L0.116428 0.880312 L0.102822 0.848819 L0.095633 0.813947 L0.094239 0.776413",K:"M0.035401 0.270996 L0.035401 0.94897 M0.502258 0.316194 L0.035401 0.687823 M0.212484 0.582361 L0.566652 0.933903",L:"M0.07544 0.270996 L0.07544 0.94897 L0.526613 0.94897",M:"M0.042481 0.94897 L0.042481 0.270996 L0.301027 0.712492 L0.559571 0.270996 L0.559571 0.94897",N:"M0.067871 0.94897 L0.067871 0.270996 L0.534181 0.94897 L0.525031 0.270996",O:"M0.287293 0.961214 L0.19843 0.933567 L0.1172 0.849451 L0.057129 0.563945 L0.114348 0.350255 L0.18455 0.289392 L0.306101 0.257813 L0.42054 0.29572 L0.487543 0.365003 L0.544923 0.625294 L0.516366 0.789624 L0.465476 0.884596 L0.375084 0.949287 L0.287293 0.961214",P:"M0.070557 0.94897 L0.070557 0.28379 L0.20704 0.270996 L0.329134 0.278993 L0.408525 0.300514 L0.444022 0.317908 L0.500637 0.368929 L0.525796 0.423728 L0.531496 0.50384 L0.508934 0.554205 L0.473724 0.582043 L0.417577 0.604365 L0.336375 0.620372 L0.226014 0.629268 L0.082368 0.630258",Q:"M0.282435 1.050813 L0.195447 1.019646 L0.115933 0.924817 L0.057129 0.602943 L0.113139 0.362034 L0.18186 0.293418 L0.300844 0.257813 L0.412868 0.300553 L0.478457 0.37866 L0.534625 0.672103 L0.506671 0.857367 L0.456855 0.964437 L0.368371 1.037368 L0.282435 1.050813 M0.341225 0.815559 L0.544923 1.070653",R:"M0.034912 0.944112 L0.034912 0.288556 L0.227127 0.270996 L0.362038 0.276867 L0.443423 0.294907 L0.477644 0.309614 L0.505809 0.328757 L0.526616 0.352817 L0.544963 0.418061 L0.543241 0.475921 L0.524463 0.517817 L0.49076 0.546518 L0.444265 0.564799 L0.355195 0.578739 L0.047653 0.589627 M0.303054 0.617306 L0.56714 0.94897",S:"M0.483037 0.364333 L0.407613 0.267477 L0.22883 0.257813 L0.128623 0.327565 L0.087712 0.455539 L0.104656 0.518727 L0.168054 0.573307 L0.41928 0.617318 L0.503796 0.669342 L0.535157 0.759324 L0.493846 0.900055 L0.367668 0.961214 L0.205436 0.956661 L0.116711 0.907038 L0.066895 0.790334",T:"M0.022949 0.270996 L0.579103 0.270996 M0.309284 0.270996 L0.309284 0.94897",U:"M0.072022 0.270996 L0.07308 0.648875 L0.080372 0.75167 L0.099024 0.827813 L0.134786 0.885729 L0.181571 0.924023 L0.251464 0.95168 L0.339655 0.962139 L0.401553 0.951668 L0.45232 0.924086 L0.482701 0.891771 L0.495745 0.870529 L0.515699 0.81637 L0.525014 0.744626 L0.530031 0.272017",V:"M0.027832 0.270996 L0.320083 0.94897 L0.57422 0.270996",W:"M0 0.270996 L0.079799 0.940377 L0.285198 0.472884 L0.505255 0.94897 L0.602052 0.270996",X:"M0.009034 0.270996 L0.586805 0.94897 M0.593019 0.270996 L0.015246 0.94897",Y:"M0.018067 0.270996 L0.293132 0.574135 M0.583986 0.271959 L0.294954 0.57606 L0.305277 0.94897",Z:"M0.053711 0.270996 L0.548341 0.270996 L0.053711 0.94897 L0.548341 0.94897","[":"M0.404542 0.240234 L0.197511 0.240234 L0.197511 1.069424 L0.404542 1.069424","\\":"M0.062501 0.270996 L0.539551 1.035249","]":"M0.19751 0.240234 L0.404542 0.240234 L0.404542 1.069424 L0.19751 1.069424","^":"M0.035156 0.523931 L0.301024 0.270996 L0.566896 0.523931",_:"M0 1.160601 L0.602052 1.160601",a:"M0.527101 0.439941 L0.527101 0.973965 M0.527101 0.553824 L0.451366 0.477535 L0.376759 0.439941 L0.263722 0.439941 L0.187989 0.477535 L0.112255 0.553824 L0.074951 0.66881 L0.074951 0.745099 L0.112255 0.85898 L0.187989 0.93527 L0.263722 0.973965 L0.376759 0.973965 L0.451366 0.93527 L0.527101 0.85898",b:"M0.07666 0.240234 L0.07666 0.959985 M0.07666 0.582737 L0.151822 0.514237 L0.225865 0.480483 L0.338045 0.480483 L0.413211 0.514237 L0.488374 0.582737 L0.525392 0.685983 L0.525392 0.754485 L0.488374 0.856739 L0.413211 0.92524 L0.338045 0.959985 L0.225865 0.959985 L0.151822 0.92524 L0.07666 0.856739",c:"M0.512452 0.553823 L0.441624 0.477535 L0.371854 0.439941 L0.26614 0.439941 L0.195312 0.477535 L0.124486 0.553823 L0.0896 0.668808 L0.0896 0.745099 L0.124486 0.858979 L0.195312 0.93527 L0.26614 0.973965 L0.371854 0.973965 L0.441624 0.93527 L0.512452 0.858979",d:"M0.525392 0.240234 L0.525392 0.959985 M0.525392 0.582737 L0.450232 0.514237 L0.376189 0.480483 L0.264006 0.480483 L0.188844 0.514237 L0.11368 0.582737 L0.076661 0.685983 L0.076661 0.754485 L0.11368 0.856739 L0.188844 0.92524 L0.264006 0.959985 L0.376189 0.959985 L0.450232 0.92524 L0.525392 0.856739",e:"M0.059571 0.668808 L0.542482 0.668808 M0.542482 0.592521 L0.502641 0.516231 L0.461594 0.477535 L0.381914 0.439941 L0.261186 0.439941 L0.180299 0.477535 L0.099412 0.553823 L0.059571 0.668808 L0.059571 0.745099 L0.099412 0.858979 L0.180299 0.93527 L0.261186 0.973965 L0.381914 0.973965 L0.461594 0.93527 L0.542482 0.858979",f:"M0.512941 0.240234 L0.406984 0.240234 L0.301026 0.274346 L0.248047 0.374731 L0.248047 0.946817 M0.089112 0.476088 L0.459965 0.476088",g:"M0.525392 0.439941 L0.525392 0.989395 L0.488373 1.091918 L0.45023 1.126757 L0.376189 1.160601 L0.264004 1.160601 L0.188844 1.126757 L0.113681 1.058075 L0.076661 0.954555 M0.525392 0.542467 L0.45023 0.473786 L0.376189 0.439941 L0.264004 0.439941 L0.188844 0.473786 L0.113681 0.542467 L0.076661 0.645988 L0.076661 0.714669 L0.113681 0.817193 L0.188844 0.885875 L0.264004 0.920713 L0.376189 0.920713 L0.45023 0.885875 L0.525392 0.817193",h:"M0.092041 0.240234 L0.092041 0.946817 M0.092041 0.61058 L0.205937 0.509225 L0.282214 0.476086 L0.396109 0.476086 L0.47187 0.509225 L0.510011 0.61058 L0.510011 0.946817",i:"M0.261026 0.240234 L0.341026 0.240234 M0.300978 0.476089 L0.300978 0.946817",j:"M0.3853 0.240234 L0.447023 0.240234 M0.416159 0.465708 L0.416159 1.011689 L0.383887 1.108586 L0.252832 1.140264 L0.15503 1.108586",k:"M0.065186 0.240234 L0.065186 0.946817 M0.493824 0.476086 L0.065186 0.812323 M0.236758 0.677829 L0.536867 0.946817",l:"M0.301026 0.234863 L0.301026 0.946441",m:"M0.050538 0.439941 L0.050538 0.960796 M0.050538 0.588758 L0.114405 0.476607 L0.157178 0.439941 L0.236864 0.439941 L0.279637 0.476607 L0.32241 0.588758 L0.32241 0.960796 M0.32241 0.588758 L0.386281 0.476607 L0.428467 0.439941 L0.50874 0.439941 L0.551515 0.476607 L0.551515 0.960796",n:"M0.092041 0.439941 L0.092041 0.960796 M0.092041 0.588758 L0.205936 0.476607 L0.282216 0.439941 L0.396113 0.439941 L0.471871 0.476607 L0.510011 0.588758 L0.510011 0.960796",o:"M0.247175 0.439941 L0.175178 0.477535 L0.103186 0.553823 L0.066895 0.668808 L0.066895 0.745099 L0.103186 0.858979 L0.175178 0.93527 L0.247175 0.973965 L0.354874 0.973965 L0.426872 0.93527 L0.498866 0.858979 L0.535157 0.745099 L0.535157 0.668808 L0.498866 0.553823 L0.426872 0.477535 L0.354874 0.439941 L0.247175 0.439941",p:"M0.076904 0.439941 L0.076904 1.154244 M0.076904 0.541563 L0.151986 0.473487 L0.225944 0.439941 L0.338005 0.439941 L0.413087 0.473487 L0.488166 0.541563 L0.525148 0.644169 L0.525148 0.712246 L0.488166 0.813866 L0.413087 0.881942 L0.338005 0.916471 L0.225944 0.916471 L0.151986 0.881942 L0.076904 0.813866",q:"M0.525148 0.441895 L0.525148 1.156195 M0.525148 0.5435 L0.450067 0.47544 L0.376106 0.441895 L0.264042 0.441895 L0.188966 0.47544 L0.113885 0.5435 L0.076905 0.646108 L0.076905 0.714187 L0.113885 0.815809 L0.188966 0.883886 L0.264042 0.918418 L0.376106 0.918418 L0.450067 0.883886 L0.525148 0.815809",r:"M0.107422 0.439941 L0.107422 0.960796 M0.107422 0.663164 L0.155824 0.551014 L0.252626 0.476607 L0.349428 0.439941 L0.49463 0.439941",s:"M0.475556 0.477535 L0.400757 0.439941 L0.276092 0.439941 L0.176361 0.477535 L0.101563 0.553823 L0.101563 0.630112 L0.176361 0.668808 L0.301024 0.668808 L0.425688 0.745099 L0.50049 0.821387 L0.50049 0.897677 L0.425688 0.93527 L0.325956 0.973965 L0.201295 0.973965 L0.126496 0.93527 L0.101563 0.858979",t:"M0.246032 0.297852 L0.246032 0.826549 L0.301023 0.919323 L0.411011 0.950848 L0.520997 0.950848 M0.081055 0.515799 L0.466004 0.515799",u:"M0.092041 0.454102 L0.092041 0.826134 L0.13018 0.937211 L0.205936 0.974954 L0.319832 0.974954 L0.396113 0.937211 L0.510011 0.826134 M0.510011 0.454102 L0.510011 0.974954",v:"M0.048828 0.453125 L0.301026 0.961719 M0.553224 0.453125 L0.301026 0.961719",w:"M0 0.453125 L0.150512 0.961719 M0.301024 0.453125 L0.150512 0.961719 M0.301024 0.453125 L0.451539 0.961719 M0.602052 0.453125 L0.451539 0.961719",x:"M0.03711 0.453125 L0.564943 0.961719 M0.564943 0.453125 L0.03711 0.961719",y:"M0.084618 0.453125 L0.320232 0.921476 M0.55713 0.453125 L0.320232 0.921476 L0.242119 1.055289 L0.163369 1.122196 L0.084618 1.155166 L0.044922 1.155166",z:"M0.505373 0.452148 L0.09668 0.961651 M0.09668 0.452148 L0.505373 0.452148 M0.09668 0.961651 L0.505373 0.961651"},lineAlphabet={};for(let letter in svgAlphabet){lineAlphabet[letter]=[];let segs=svgAlphabet[letter].split("M").slice(1).map(seg=>seg.split("L").map(pr3=>pr3.trim().split(" ").map(parseFloat)));for(let seg of segs)for(let i11=0;i11<seg.length-1;i11++)lineAlphabet[letter].push({x1:seg[i11][0],y1:1-seg[i11][1],x2:seg[i11+1][0],y2:1-seg[i11+1][1]})}strokeWidthRatio=.09,glyphWidthRatio=.692052,spaceWidthRatio=.692052,lineHeightRatio=1.152,letterSpacingRatio=0,glyphAdvanceRatio={0:.692052,1:.692052,2:.692052,3:.692052,4:.692052,5:.692052,6:.692052,7:.692052,8:.692052,9:.692052,"!":.692052,'"':.692052,"#":.692052,$:.692052,"'":.692052,"(":.692052,")":.692052,"*":.692052,"+":.692052,",":.692052,"-":.692052,".":.692052,"/":.692052,"<":.692052,"=":.692052,">":.692052,A:.692052,B:.692052,C:.692052,D:.692052,E:.692052,F:.692052,G:.692052,H:.692052,I:.692052,J:.692052,K:.692052,L:.692052,M:.692052,N:.692052,O:.692052,P:.692052,Q:.692052,R:.692052,S:.692052,T:.692052,U:.692052,V:.692052,W:.692052,X:.692052,Y:.692052,Z:.692052,"[":.692052,"\\":.692052,"]":.692052,"^":.692052,_:.692052,a:.692052,b:.692052,c:.692052,d:.692052,e:.692052,f:.692052,g:.692052,h:.692052,i:.692052,j:.692052,k:.692052,l:.692052,m:.692052,n:.692052,o:.692052,p:.692052,q:.692052,r:.692052,s:.692052,t:.692052,u:.692052,v:.692052,w:.692052,x:.692052,y:.692052,z:.692052," ":.692052},textMetrics={glyphWidthRatio,spaceWidthRatio,lineHeightRatio,strokeWidthRatio,letterSpacingRatio}}});var require_svgson_umd=__commonJS({"node_modules/svgson/dist/svgson.umd.js"(exports,module){"use strict";(function(global2,factory){typeof exports=="object"&&typeof module<"u"?module.exports=factory():typeof define=="function"&&define.amd?define(factory):(global2=typeof globalThis<"u"?globalThis:global2||self,global2.svgson=factory())})(exports,(function(){"use strict";var isBuffer_1=function(obj){return obj!=null&&(isBuffer(obj)||isSlowBuffer(obj)||!!obj._isBuffer)};function isBuffer(obj){return!!obj.constructor&&typeof obj.constructor.isBuffer=="function"&&obj.constructor.isBuffer(obj)}function isSlowBuffer(obj){return typeof obj.readFloatLE=="function"&&typeof obj.slice=="function"&&isBuffer(obj.slice(0,0))}var toString3=Object.prototype.toString,kindOf=function(val){if(typeof val>"u")return"undefined";if(val===null)return"null";if(val===!0||val===!1||val instanceof Boolean)return"boolean";if(typeof val=="string"||val instanceof String)return"string";if(typeof val=="number"||val instanceof Number)return"number";if(typeof val=="function"||val instanceof Function)return"function";if(typeof Array.isArray<"u"&&Array.isArray(val))return"array";if(val instanceof RegExp)return"regexp";if(val instanceof Date)return"date";var type=toString3.call(val);return type==="[object RegExp]"?"regexp":type==="[object Date]"?"date":type==="[object Arguments]"?"arguments":type==="[object Error]"?"error":isBuffer_1(val)?"buffer":type==="[object Set]"?"set":type==="[object WeakSet]"?"weakset":type==="[object Map]"?"map":type==="[object WeakMap]"?"weakmap":type==="[object Symbol]"?"symbol":type==="[object Int8Array]"?"int8array":type==="[object Uint8Array]"?"uint8array":type==="[object Uint8ClampedArray]"?"uint8clampedarray":type==="[object Int16Array]"?"int16array":type==="[object Uint16Array]"?"uint16array":type==="[object Int32Array]"?"int32array":type==="[object Uint32Array]"?"uint32array":type==="[object Float32Array]"?"float32array":type==="[object Float64Array]"?"float64array":"object"};function createCommonjsModule(fn3,module2){return module2={exports:{}},fn3(module2,module2.exports),module2.exports}var renameKeys=createCommonjsModule(function(module2){(function(){function rename(obj,fn3){if(typeof fn3!="function")return obj;var res2={};for(var key in obj)Object.prototype.hasOwnProperty.call(obj,key)&&(res2[fn3(key,obj[key])||key]=obj[key]);return res2}module2.exports?module2.exports=rename:window.rename=rename})()}),deepRenameKeys=function renameDeep(obj,cb4){var type=kindOf(obj);if(type!=="object"&&type!=="array")throw new Error("expected an object");var res2=[];type==="object"&&(obj=renameKeys(obj,cb4),res2={});for(var key in obj)if(obj.hasOwnProperty(key)){var val=obj[key];kindOf(val)==="object"||kindOf(val)==="array"?res2[key]=renameDeep(val,cb4):res2[key]=val}return res2},eventemitter3=createCommonjsModule(function(module2){var has=Object.prototype.hasOwnProperty,prefix="~";function Events(){}Object.create&&(Events.prototype=Object.create(null),new Events().__proto__||(prefix=!1));function EE3(fn3,context,once){this.fn=fn3,this.context=context,this.once=once||!1}function EventEmitter(){this._events=new Events,this._eventsCount=0}EventEmitter.prototype.eventNames=function(){var names=[],events,name;if(this._eventsCount===0)return names;for(name in events=this._events)has.call(events,name)&&names.push(prefix?name.slice(1):name);return Object.getOwnPropertySymbols?names.concat(Object.getOwnPropertySymbols(events)):names},EventEmitter.prototype.listeners=function(event,exists){var evt=prefix?prefix+event:event,available=this._events[evt];if(exists)return!!available;if(!available)return[];if(available.fn)return[available.fn];for(var i11=0,l10=available.length,ee4=new Array(l10);i11<l10;i11++)ee4[i11]=available[i11].fn;return ee4},EventEmitter.prototype.emit=function(event,a12,a22,a32,a42,a52){var evt=prefix?prefix+event:event;if(!this._events[evt])return!1;var listeners=this._events[evt],len6=arguments.length,args,i11;if(listeners.fn){switch(listeners.once&&this.removeListener(event,listeners.fn,void 0,!0),len6){case 1:return listeners.fn.call(listeners.context),!0;case 2:return listeners.fn.call(listeners.context,a12),!0;case 3:return listeners.fn.call(listeners.context,a12,a22),!0;case 4:return listeners.fn.call(listeners.context,a12,a22,a32),!0;case 5:return listeners.fn.call(listeners.context,a12,a22,a32,a42),!0;case 6:return listeners.fn.call(listeners.context,a12,a22,a32,a42,a52),!0}for(i11=1,args=new Array(len6-1);i11<len6;i11++)args[i11-1]=arguments[i11];listeners.fn.apply(listeners.context,args)}else{var length14=listeners.length,j11;for(i11=0;i11<length14;i11++)switch(listeners[i11].once&&this.removeListener(event,listeners[i11].fn,void 0,!0),len6){case 1:listeners[i11].fn.call(listeners[i11].context);break;case 2:listeners[i11].fn.call(listeners[i11].context,a12);break;case 3:listeners[i11].fn.call(listeners[i11].context,a12,a22);break;case 4:listeners[i11].fn.call(listeners[i11].context,a12,a22,a32);break;default:if(!args)for(j11=1,args=new Array(len6-1);j11<len6;j11++)args[j11-1]=arguments[j11];listeners[i11].fn.apply(listeners[i11].context,args)}}return!0},EventEmitter.prototype.on=function(event,fn3,context){var listener=new EE3(fn3,context||this),evt=prefix?prefix+event:event;return this._events[evt]?this._events[evt].fn?this._events[evt]=[this._events[evt],listener]:this._events[evt].push(listener):(this._events[evt]=listener,this._eventsCount++),this},EventEmitter.prototype.once=function(event,fn3,context){var listener=new EE3(fn3,context||this,!0),evt=prefix?prefix+event:event;return this._events[evt]?this._events[evt].fn?this._events[evt]=[this._events[evt],listener]:this._events[evt].push(listener):(this._events[evt]=listener,this._eventsCount++),this},EventEmitter.prototype.removeListener=function(event,fn3,context,once){var evt=prefix?prefix+event:event;if(!this._events[evt])return this;if(!fn3)return--this._eventsCount===0?this._events=new Events:delete this._events[evt],this;var listeners=this._events[evt];if(listeners.fn)listeners.fn===fn3&&(!once||listeners.once)&&(!context||listeners.context===context)&&(--this._eventsCount===0?this._events=new Events:delete this._events[evt]);else{for(var i11=0,events=[],length14=listeners.length;i11<length14;i11++)(listeners[i11].fn!==fn3||once&&!listeners[i11].once||context&&listeners[i11].context!==context)&&events.push(listeners[i11]);events.length?this._events[evt]=events.length===1?events[0]:events:--this._eventsCount===0?this._events=new Events:delete this._events[evt]}return this},EventEmitter.prototype.removeAllListeners=function(event){var evt;return event?(evt=prefix?prefix+event:event,this._events[evt]&&(--this._eventsCount===0?this._events=new Events:delete this._events[evt])):(this._events=new Events,this._eventsCount=0),this},EventEmitter.prototype.off=EventEmitter.prototype.removeListener,EventEmitter.prototype.addListener=EventEmitter.prototype.on,EventEmitter.prototype.setMaxListeners=function(){return this},EventEmitter.prefixed=prefix,EventEmitter.EventEmitter=EventEmitter,module2.exports=EventEmitter});function _defineProperty(obj,key,value){return key in obj?Object.defineProperty(obj,key,{value,enumerable:!0,configurable:!0,writable:!0}):obj[key]=value,obj}var noop=function(){},State2={data:"state-data",cdata:"state-cdata",tagBegin:"state-tag-begin",tagName:"state-tag-name",tagEnd:"state-tag-end",attributeNameStart:"state-attribute-name-start",attributeName:"state-attribute-name",attributeNameEnd:"state-attribute-name-end",attributeValueBegin:"state-attribute-value-begin",attributeValue:"state-attribute-value"},Action={lt:"action-lt",gt:"action-gt",space:"action-space",equal:"action-equal",quote:"action-quote",slash:"action-slash",char:"action-char",error:"action-error"},Type$1={text:"text",openTag:"open-tag",closeTag:"close-tag",attributeName:"attribute-name",attributeValue:"attribute-value"},charToAction={" ":Action.space," ":Action.space,"\n":Action.space,"\r":Action.space,"<":Action.lt,">":Action.gt,'"':Action.quote,"'":Action.quote,"=":Action.equal,"/":Action.slash},getAction=function(char){return charToAction[char]||Action.char},create$1=function(options){var _State$data,_State$tagBegin,_State$tagName,_State$tagEnd,_State$attributeNameS,_State$attributeName,_State$attributeNameE,_State$attributeValue,_State$attributeValue2,_lexer$stateMachine;options=Object.assign({debug:!1},options);var lexer2=new eventemitter3,state2=State2.data,data="",tagName="",attrName="",attrValue="",isClosing="",openingQuote="",emit=function(type,value){if(!(tagName[0]==="?"||tagName[0]==="!")){var event={type,value};options.debug&&console.log("emit:",event),lexer2.emit("data",event)}};lexer2.stateMachine=(_lexer$stateMachine={},_defineProperty(_lexer$stateMachine,State2.data,(_State$data={},_defineProperty(_State$data,Action.lt,function(){data.trim()&&emit(Type$1.text,data),tagName="",isClosing=!1,state2=State2.tagBegin}),_defineProperty(_State$data,Action.char,function(char){data+=char}),_State$data)),_defineProperty(_lexer$stateMachine,State2.cdata,_defineProperty({},Action.char,function(char){data+=char,data.substr(-3)==="]]>"&&(emit(Type$1.text,data.slice(0,-3)),data="",state2=State2.data)})),_defineProperty(_lexer$stateMachine,State2.tagBegin,(_State$tagBegin={},_defineProperty(_State$tagBegin,Action.space,noop),_defineProperty(_State$tagBegin,Action.char,function(char){tagName=char,state2=State2.tagName}),_defineProperty(_State$tagBegin,Action.slash,function(){tagName="",isClosing=!0}),_State$tagBegin)),_defineProperty(_lexer$stateMachine,State2.tagName,(_State$tagName={},_defineProperty(_State$tagName,Action.space,function(){isClosing?state2=State2.tagEnd:(state2=State2.attributeNameStart,emit(Type$1.openTag,tagName))}),_defineProperty(_State$tagName,Action.gt,function(){emit(isClosing?Type$1.closeTag:Type$1.openTag,tagName),data="",state2=State2.data}),_defineProperty(_State$tagName,Action.slash,function(){state2=State2.tagEnd,emit(Type$1.openTag,tagName)}),_defineProperty(_State$tagName,Action.char,function(char){tagName+=char,tagName==="![CDATA["&&(state2=State2.cdata,data="",tagName="")}),_State$tagName)),_defineProperty(_lexer$stateMachine,State2.tagEnd,(_State$tagEnd={},_defineProperty(_State$tagEnd,Action.gt,function(){emit(Type$1.closeTag,tagName),data="",state2=State2.data}),_defineProperty(_State$tagEnd,Action.char,noop),_State$tagEnd)),_defineProperty(_lexer$stateMachine,State2.attributeNameStart,(_State$attributeNameS={},_defineProperty(_State$attributeNameS,Action.char,function(char){attrName=char,state2=State2.attributeName}),_defineProperty(_State$attributeNameS,Action.gt,function(){data="",state2=State2.data}),_defineProperty(_State$attributeNameS,Action.space,noop),_defineProperty(_State$attributeNameS,Action.slash,function(){isClosing=!0,state2=State2.tagEnd}),_State$attributeNameS)),_defineProperty(_lexer$stateMachine,State2.attributeName,(_State$attributeName={},_defineProperty(_State$attributeName,Action.space,function(){state2=State2.attributeNameEnd}),_defineProperty(_State$attributeName,Action.equal,function(){emit(Type$1.attributeName,attrName),state2=State2.attributeValueBegin}),_defineProperty(_State$attributeName,Action.gt,function(){attrValue="",emit(Type$1.attributeName,attrName),emit(Type$1.attributeValue,attrValue),data="",state2=State2.data}),_defineProperty(_State$attributeName,Action.slash,function(){isClosing=!0,attrValue="",emit(Type$1.attributeName,attrName),emit(Type$1.attributeValue,attrValue),state2=State2.tagEnd}),_defineProperty(_State$attributeName,Action.char,function(char){attrName+=char}),_State$attributeName)),_defineProperty(_lexer$stateMachine,State2.attributeNameEnd,(_State$attributeNameE={},_defineProperty(_State$attributeNameE,Action.space,noop),_defineProperty(_State$attributeNameE,Action.equal,function(){emit(Type$1.attributeName,attrName),state2=State2.attributeValueBegin}),_defineProperty(_State$attributeNameE,Action.gt,function(){attrValue="",emit(Type$1.attributeName,attrName),emit(Type$1.attributeValue,attrValue),data="",state2=State2.data}),_defineProperty(_State$attributeNameE,Action.char,function(char){attrValue="",emit(Type$1.attributeName,attrName),emit(Type$1.attributeValue,attrValue),attrName=char,state2=State2.attributeName}),_State$attributeNameE)),_defineProperty(_lexer$stateMachine,State2.attributeValueBegin,(_State$attributeValue={},_defineProperty(_State$attributeValue,Action.space,noop),_defineProperty(_State$attributeValue,Action.quote,function(char){openingQuote=char,attrValue="",state2=State2.attributeValue}),_defineProperty(_State$attributeValue,Action.gt,function(){attrValue="",emit(Type$1.attributeValue,attrValue),data="",state2=State2.data}),_defineProperty(_State$attributeValue,Action.char,function(char){openingQuote="",attrValue=char,state2=State2.attributeValue}),_State$attributeValue)),_defineProperty(_lexer$stateMachine,State2.attributeValue,(_State$attributeValue2={},_defineProperty(_State$attributeValue2,Action.space,function(char){openingQuote?attrValue+=char:(emit(Type$1.attributeValue,attrValue),state2=State2.attributeNameStart)}),_defineProperty(_State$attributeValue2,Action.quote,function(char){openingQuote===char?(emit(Type$1.attributeValue,attrValue),state2=State2.attributeNameStart):attrValue+=char}),_defineProperty(_State$attributeValue2,Action.gt,function(char){openingQuote?attrValue+=char:(emit(Type$1.attributeValue,attrValue),data="",state2=State2.data)}),_defineProperty(_State$attributeValue2,Action.slash,function(char){openingQuote?attrValue+=char:(emit(Type$1.attributeValue,attrValue),isClosing=!0,state2=State2.tagEnd)}),_defineProperty(_State$attributeValue2,Action.char,function(char){attrValue+=char}),_State$attributeValue2)),_lexer$stateMachine);var step=function(char){options.debug&&console.log(state2,char);var actions=lexer2.stateMachine[state2],action=actions[getAction(char)]||actions[Action.error]||actions[Action.char];action(char)};return lexer2.write=function(str10){for(var len6=str10.length,i11=0;i11<len6;i11++)step(str10[i11])},lexer2},lexer={State:State2,Action,Type:Type$1,create:create$1},Type=lexer.Type,NodeType={element:"element",text:"text"},createNode=function(params){return Object.assign({name:"",type:NodeType.element,value:"",parent:null,attributes:{},children:[]},params)},create10=function(options){options=Object.assign({stream:!1,parentNodes:!0,doneEvent:"done",tagPrefix:"tag:",emitTopLevelOnly:!1,debug:!1},options);var lexer$1=void 0,rootNode=void 0,current3=void 0,attrName=void 0,reader2=new eventemitter3,handleLexerData=function(data){switch(data.type){case Type.openTag:if(current3===null)current3=rootNode,current3.name=data.value;else{var node=createNode({name:data.value,parent:current3});current3.children.push(node),current3=node}break;case Type.closeTag:var parent=current3.parent;if(options.parentNodes||(current3.parent=null),current3.name!==data.value)break;options.stream&&parent===rootNode&&(rootNode.children=[],current3.parent=null),(!options.emitTopLevelOnly||parent===rootNode)&&(reader2.emit(options.tagPrefix+current3.name,current3),reader2.emit("tag",current3.name,current3)),current3===rootNode&&(lexer$1.removeAllListeners("data"),reader2.emit(options.doneEvent,current3),rootNode=null),current3=parent;break;case Type.text:current3&&current3.children.push(createNode({type:NodeType.text,value:data.value,parent:options.parentNodes?current3:null}));break;case Type.attributeName:attrName=data.value,current3.attributes[attrName]="";break;case Type.attributeValue:current3.attributes[attrName]=data.value;break}};return reader2.reset=function(){lexer$1=lexer.create({debug:options.debug}),lexer$1.on("data",handleLexerData),rootNode=createNode(),current3=null,attrName="",reader2.parse=lexer$1.write},reader2.reset(),reader2},parseSync=function(xml,options){options=Object.assign({},options,{stream:!1,tagPrefix:":"});var reader2=create10(options),res2=void 0;return reader2.on("done",function(ast){res2=ast}),reader2.parse(xml),res2},reader={parseSync,create:create10,NodeType},reader_1=reader.parseSync,parseInput=function(input2){var parsed=reader_1("<root>".concat(input2,"</root>"),{parentNodes:!1}),isValid3=parsed.children&&parsed.children.length>0&&parsed.children.every(function(node){return node.name==="svg"});if(isValid3)return parsed.children.length===1?parsed.children[0]:parsed.children;throw Error("nothing to parse")},camelize=function(node){return deepRenameKeys(node,function(key){return notCamelcase(key)?key:toCamelCase(key)})},toCamelCase=function(prop){return prop.replace(/[-|:]([a-z])/gi,function(all,letter){return letter.toUpperCase()})},notCamelcase=function(prop){return/^(data|aria)(-\w+)/.test(prop)},escapeText2=function(text){if(text){var str10=String(text);return/[&<>]/.test(str10)?"<![CDATA[".concat(str10.replace(/]]>/,"]]]]><![CDATA[>"),"]]>"):str10}return""},escapeAttr2=function(attr){return String(attr).replace(/&/g,"&amp;").replace(/'/g,"&apos;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;")},svgsonSync=function(input2){var _ref=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},_ref$transformNode=_ref.transformNode,transformNode=_ref$transformNode===void 0?function(node){return node}:_ref$transformNode,_ref$camelcase=_ref.camelcase,camelcase=_ref$camelcase===void 0?!1:_ref$camelcase,applyFilters=function(input3){var n10;return n10=transformNode(input3),camelcase&&(n10=camelize(n10)),n10};return applyFilters(parseInput(input2))};function svgson(){for(var _len=arguments.length,args=new Array(_len),_key=0;_key<_len;_key++)args[_key]=arguments[_key];return new Promise(function(resolve7,reject){try{var res2=svgsonSync.apply(void 0,args);resolve7(res2)}catch(e55){reject(e55)}})}var stringify4=function stringify5(_ast){var _ref=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},_ref$transformAttr=_ref.transformAttr,transformAttr=_ref$transformAttr===void 0?function(key,value,escape2){return"".concat(key,'="').concat(escape2(value),'"')}:_ref$transformAttr,_ref$transformNode=_ref.transformNode,transformNode=_ref$transformNode===void 0?function(node){return node}:_ref$transformNode,_ref$selfClose=_ref.selfClose,selfClose=_ref$selfClose===void 0?!0:_ref$selfClose;if(Array.isArray(_ast))return _ast.map(function(ast2){return stringify5(ast2,{transformAttr,selfClose,transformNode})}).join("");var ast=transformNode(_ast);if(ast.type==="text")return escapeText2(ast.value);var attributes2="";for(var attr in ast.attributes){var attrStr=transformAttr(attr,ast.attributes[attr],escapeAttr2,ast.name);attributes2+=attrStr?" ".concat(attrStr):""}return ast.children&&ast.children.length>0||!selfClose?"<".concat(ast.name).concat(attributes2,">").concat(stringify5(ast.children,{transformAttr,transformNode,selfClose}),"</").concat(ast.name,">"):"<".concat(ast.name).concat(attributes2,"/>")},indexUmd=Object.assign({},{parse:svgson,parseSync:svgsonSync,stringify:stringify4});return indexUmd}))}});var require_object_hash=__commonJS({"node_modules/object-hash/dist/object_hash.js"(exports,module){"use strict";(function(e55){var t48;typeof exports=="object"?module.exports=e55():typeof define=="function"&&define.amd?define(e55):(typeof window<"u"?t48=window:typeof global<"u"?t48=global:typeof self<"u"&&(t48=self),t48.objectHash=e55())})(function(){return(function r11(o11,i11,u5){function s11(n10,e56){if(!i11[n10]){if(!o11[n10]){var t48=typeof __require=="function"&&__require;if(!e56&&t48)return t48(n10,!0);if(a10)return a10(n10,!0);throw new Error("Cannot find module '"+n10+"'")}e56=i11[n10]={exports:{}},o11[n10][0].call(e56.exports,function(e57){var t49=o11[n10][1][e57];return s11(t49||e57)},e56,e56.exports,r11,o11,i11,u5)}return i11[n10].exports}for(var a10=typeof __require=="function"&&__require,e55=0;e55<u5.length;e55++)s11(u5[e55]);return s11})({1:[function(w10,b10,m5){(function(e55,n10,s11,c10,d11,h11,p11,g11,y11){"use strict";var r11=w10("crypto");function t48(e56,t49){t49=u5(e56,t49);var n11;return(n11=t49.algorithm!=="passthrough"?r11.createHash(t49.algorithm):new l10).write===void 0&&(n11.write=n11.update,n11.end=n11.update),f3(t49,n11).dispatch(e56),n11.update||n11.end(""),n11.digest?n11.digest(t49.encoding==="buffer"?void 0:t49.encoding):(e56=n11.read(),t49.encoding!=="buffer"?e56.toString(t49.encoding):e56)}(m5=b10.exports=t48).sha1=function(e56){return t48(e56)},m5.keys=function(e56){return t48(e56,{excludeValues:!0,algorithm:"sha1",encoding:"hex"})},m5.MD5=function(e56){return t48(e56,{algorithm:"md5",encoding:"hex"})},m5.keysMD5=function(e56){return t48(e56,{algorithm:"md5",encoding:"hex",excludeValues:!0})};var o11=r11.getHashes?r11.getHashes().slice():["sha1","md5"],i11=(o11.push("passthrough"),["buffer","hex","binary","base64"]);function u5(e56,t49){var n11={};if(n11.algorithm=(t49=t49||{}).algorithm||"sha1",n11.encoding=t49.encoding||"hex",n11.excludeValues=!!t49.excludeValues,n11.algorithm=n11.algorithm.toLowerCase(),n11.encoding=n11.encoding.toLowerCase(),n11.ignoreUnknown=t49.ignoreUnknown===!0,n11.respectType=t49.respectType!==!1,n11.respectFunctionNames=t49.respectFunctionNames!==!1,n11.respectFunctionProperties=t49.respectFunctionProperties!==!1,n11.unorderedArrays=t49.unorderedArrays===!0,n11.unorderedSets=t49.unorderedSets!==!1,n11.unorderedObjects=t49.unorderedObjects!==!1,n11.replacer=t49.replacer||void 0,n11.excludeKeys=t49.excludeKeys||void 0,e56===void 0)throw new Error("Object argument required.");for(var r12=0;r12<o11.length;++r12)o11[r12].toLowerCase()===n11.algorithm.toLowerCase()&&(n11.algorithm=o11[r12]);if(o11.indexOf(n11.algorithm)===-1)throw new Error('Algorithm "'+n11.algorithm+'" not supported. supported values: '+o11.join(", "));if(i11.indexOf(n11.encoding)===-1&&n11.algorithm!=="passthrough")throw new Error('Encoding "'+n11.encoding+'" not supported. supported values: '+i11.join(", "));return n11}function a10(e56){if(typeof e56=="function")return/^function\s+\w*\s*\(\s*\)\s*{\s+\[native code\]\s+}$/i.exec(Function.prototype.toString.call(e56))!=null}function f3(o12,t49,i12){i12=i12||[];function u10(e56){return t49.update?t49.update(e56,"utf8"):t49.write(e56,"utf8")}return{dispatch:function(e56){return this["_"+((e56=o12.replacer?o12.replacer(e56):e56)===null?"null":typeof e56)](e56)},_object:function(t50){var n11,e56=Object.prototype.toString.call(t50),r12=/\[object (.*)\]/i.exec(e56);if(r12=(r12=r12?r12[1]:"unknown:["+e56+"]").toLowerCase(),0<=(e56=i12.indexOf(t50)))return this.dispatch("[CIRCULAR:"+e56+"]");if(i12.push(t50),s11!==void 0&&s11.isBuffer&&s11.isBuffer(t50))return u10("buffer:"),u10(t50);if(r12==="object"||r12==="function"||r12==="asyncfunction")return e56=Object.keys(t50),o12.unorderedObjects&&(e56=e56.sort()),o12.respectType===!1||a10(t50)||e56.splice(0,0,"prototype","__proto__","constructor"),o12.excludeKeys&&(e56=e56.filter(function(e57){return!o12.excludeKeys(e57)})),u10("object:"+e56.length+":"),n11=this,e56.forEach(function(e57){n11.dispatch(e57),u10(":"),o12.excludeValues||n11.dispatch(t50[e57]),u10(",")});if(!this["_"+r12]){if(o12.ignoreUnknown)return u10("["+r12+"]");throw new Error('Unknown object type "'+r12+'"')}this["_"+r12](t50)},_array:function(e56,t50){t50=t50!==void 0?t50:o12.unorderedArrays!==!1;var n11=this;if(u10("array:"+e56.length+":"),!t50||e56.length<=1)return e56.forEach(function(e57){return n11.dispatch(e57)});var r12=[],t50=e56.map(function(e57){var t51=new l10,n12=i12.slice();return f3(o12,t51,n12).dispatch(e57),r12=r12.concat(n12.slice(i12.length)),t51.read().toString()});return i12=i12.concat(r12),t50.sort(),this._array(t50,!1)},_date:function(e56){return u10("date:"+e56.toJSON())},_symbol:function(e56){return u10("symbol:"+e56.toString())},_error:function(e56){return u10("error:"+e56.toString())},_boolean:function(e56){return u10("bool:"+e56.toString())},_string:function(e56){u10("string:"+e56.length+":"),u10(e56.toString())},_function:function(e56){u10("fn:"),a10(e56)?this.dispatch("[native]"):this.dispatch(e56.toString()),o12.respectFunctionNames!==!1&&this.dispatch("function-name:"+String(e56.name)),o12.respectFunctionProperties&&this._object(e56)},_number:function(e56){return u10("number:"+e56.toString())},_xml:function(e56){return u10("xml:"+e56.toString())},_null:function(){return u10("Null")},_undefined:function(){return u10("Undefined")},_regexp:function(e56){return u10("regex:"+e56.toString())},_uint8array:function(e56){return u10("uint8array:"),this.dispatch(Array.prototype.slice.call(e56))},_uint8clampedarray:function(e56){return u10("uint8clampedarray:"),this.dispatch(Array.prototype.slice.call(e56))},_int8array:function(e56){return u10("int8array:"),this.dispatch(Array.prototype.slice.call(e56))},_uint16array:function(e56){return u10("uint16array:"),this.dispatch(Array.prototype.slice.call(e56))},_int16array:function(e56){return u10("int16array:"),this.dispatch(Array.prototype.slice.call(e56))},_uint32array:function(e56){return u10("uint32array:"),this.dispatch(Array.prototype.slice.call(e56))},_int32array:function(e56){return u10("int32array:"),this.dispatch(Array.prototype.slice.call(e56))},_float32array:function(e56){return u10("float32array:"),this.dispatch(Array.prototype.slice.call(e56))},_float64array:function(e56){return u10("float64array:"),this.dispatch(Array.prototype.slice.call(e56))},_arraybuffer:function(e56){return u10("arraybuffer:"),this.dispatch(new Uint8Array(e56))},_url:function(e56){return u10("url:"+e56.toString())},_map:function(e56){return u10("map:"),e56=Array.from(e56),this._array(e56,o12.unorderedSets!==!1)},_set:function(e56){return u10("set:"),e56=Array.from(e56),this._array(e56,o12.unorderedSets!==!1)},_file:function(e56){return u10("file:"),this.dispatch([e56.name,e56.size,e56.type,e56.lastModfied])},_blob:function(){if(o12.ignoreUnknown)return u10("[blob]");throw Error(`Hashing Blob objects is currently not supported
231
+ `)+hostRoot.join(" > ")}return null},exports2.getPublicRootInstance=function(container){if(container=container.current,!container.child)return null;switch(container.child.tag){case 27:case 5:return getPublicInstance(container.child.stateNode);default:return container.child.stateNode}},exports2.injectIntoDevTools=function(){var internals={bundleType:1,version:rendererVersion,rendererPackageName,currentDispatcherRef:ReactSharedInternals,reconcilerVersion:"19.1.0"};return extraDevToolsConfig!==null&&(internals.rendererConfig=extraDevToolsConfig),internals.overrideHookState=overrideHookState,internals.overrideHookStateDeletePath=overrideHookStateDeletePath,internals.overrideHookStateRenamePath=overrideHookStateRenamePath,internals.overrideProps=overrideProps,internals.overridePropsDeletePath=overridePropsDeletePath,internals.overridePropsRenamePath=overridePropsRenamePath,internals.scheduleUpdate=scheduleUpdate,internals.setErrorHandler=setErrorHandler,internals.setSuspenseHandler=setSuspenseHandler,internals.scheduleRefresh=scheduleRefresh,internals.scheduleRoot=scheduleRoot,internals.setRefreshHandler=setRefreshHandler,internals.getCurrentFiber=getCurrentFiberForDevTools,internals.getLaneLabelMap=getLaneLabelMap,internals.injectProfilingHooks=injectProfilingHooks,injectInternals(internals)},exports2.isAlreadyRendering=function(){return(executionContext2&(RenderContext|CommitContext))!==NoContext},exports2.observeVisibleRects=function(hostRoot,selectors4,callback,options){function commitHook(){var nextInstanceRoots=findAllNodes(hostRoot,selectors4);instanceRoots.forEach(function(target){0>nextInstanceRoots.indexOf(target)&&unobserve(target)}),nextInstanceRoots.forEach(function(target){0>instanceRoots.indexOf(target)&&observe(target)})}if(!supportsTestSelectors)throw Error("Test selector API is not supported by this renderer.");var instanceRoots=findAllNodes(hostRoot,selectors4);callback=setupIntersectionObserver(instanceRoots,callback,options);var disconnect=callback.disconnect,observe=callback.observe,unobserve=callback.unobserve;return commitHooks.push(commitHook),{disconnect:function(){var index2=commitHooks.indexOf(commitHook);0<=index2&&commitHooks.splice(index2,1),disconnect()}}},exports2.shouldError=function(fiber){return shouldErrorImpl(fiber)},exports2.shouldSuspend=function(fiber){return shouldSuspendImpl(fiber)},exports2.startHostTransition=function(formFiber,pendingState,action,formData){if(formFiber.tag!==5)throw Error("Expected the form instance to be a HostComponent. This is a bug in React.");var queue=ensureFormComponentIsStateful(formFiber).queue;startTransition(formFiber,queue,pendingState,NotPendingTransition,action===null?noop:function(){ReactSharedInternals.T===null&&console.error("requestFormReset was called outside a transition or action. To fix, move to an action, or wrap with startTransition.");var resetStateQueue=ensureFormComponentIsStateful(formFiber).next.queue;return dispatchSetStateInternal(formFiber,resetStateQueue,{},requestUpdateLane(formFiber)),action(formData)})},exports2.updateContainer=function(element,container,parentComponent,callback){var current4=container.current,lane=requestUpdateLane(current4);return updateContainerImpl(current4,lane,element,container,parentComponent,callback),lane},exports2.updateContainerSync=updateContainerSync,exports2},module.exports.default=module.exports,Object.defineProperty(module.exports,"__esModule",{value:!0})}});var require_react_reconciler=__commonJS({"node_modules/react-reconciler/index.js"(exports,module){"use strict";module.exports=require_react_reconciler_development()}});var require_react_reconciler_constants_development=__commonJS({"node_modules/react-reconciler/cjs/react-reconciler-constants.development.js"(exports){"use strict";exports.ConcurrentRoot=1,exports.ContinuousEventPriority=8,exports.DefaultEventPriority=32,exports.DiscreteEventPriority=2,exports.IdleEventPriority=268435456,exports.LegacyRoot=0,exports.NoEventPriority=0}});var require_constants=__commonJS({"node_modules/react-reconciler/constants.js"(exports,module){"use strict";module.exports=require_react_reconciler_constants_development()}});var common_exports={};__export(common_exports,{ANGLE_ORDER:()=>ANGLE_ORDER,ARRAY_TYPE:()=>ARRAY_TYPE,EPSILON:()=>EPSILON,RANDOM:()=>RANDOM,equals:()=>equals,round:()=>round,setMatrixArrayType:()=>setMatrixArrayType,toDegree:()=>toDegree,toRadian:()=>toRadian});function round(a10){return a10>=0?Math.round(a10):a10%.5===0?Math.floor(a10):Math.round(a10)}function setMatrixArrayType(type){ARRAY_TYPE=type}function toRadian(a10){return a10*degree}function toDegree(a10){return a10*radian}function equals(a10,b10){var tolerance=arguments.length>2&&arguments[2]!==void 0?arguments[2]:EPSILON;return Math.abs(a10-b10)<=tolerance*Math.max(1,Math.abs(a10),Math.abs(b10))}var EPSILON,ARRAY_TYPE,RANDOM,ANGLE_ORDER,degree,radian,init_common=__esm({"node_modules/gl-matrix/esm/common.js"(){"use strict";EPSILON=1e-6,ARRAY_TYPE=typeof Float32Array<"u"?Float32Array:Array,RANDOM=Math.random,ANGLE_ORDER="zyx";degree=Math.PI/180,radian=180/Math.PI}});var mat2_exports={};__export(mat2_exports,{LDU:()=>LDU,add:()=>add,adjoint:()=>adjoint,clone:()=>clone,copy:()=>copy,create:()=>create,determinant:()=>determinant,equals:()=>equals2,exactEquals:()=>exactEquals,frob:()=>frob,fromRotation:()=>fromRotation,fromScaling:()=>fromScaling,fromValues:()=>fromValues2,identity:()=>identity2,invert:()=>invert,mul:()=>mul,multiply:()=>multiply,multiplyScalar:()=>multiplyScalar,multiplyScalarAndAdd:()=>multiplyScalarAndAdd,rotate:()=>rotate3,scale:()=>scale3,set:()=>set,str:()=>str,sub:()=>sub,subtract:()=>subtract2,transpose:()=>transpose});function create(){var out=new ARRAY_TYPE(4);return ARRAY_TYPE!=Float32Array&&(out[1]=0,out[2]=0),out[0]=1,out[3]=1,out}function clone(a10){var out=new ARRAY_TYPE(4);return out[0]=a10[0],out[1]=a10[1],out[2]=a10[2],out[3]=a10[3],out}function copy(out,a10){return out[0]=a10[0],out[1]=a10[1],out[2]=a10[2],out[3]=a10[3],out}function identity2(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out}function fromValues2(m00,m01,m10,m11){var out=new ARRAY_TYPE(4);return out[0]=m00,out[1]=m01,out[2]=m10,out[3]=m11,out}function set(out,m00,m01,m10,m11){return out[0]=m00,out[1]=m01,out[2]=m10,out[3]=m11,out}function transpose(out,a10){if(out===a10){var a12=a10[1];out[1]=a10[2],out[2]=a12}else out[0]=a10[0],out[1]=a10[2],out[2]=a10[1],out[3]=a10[3];return out}function invert(out,a10){var a03=a10[0],a12=a10[1],a22=a10[2],a32=a10[3],det=a03*a32-a22*a12;return det?(det=1/det,out[0]=a32*det,out[1]=-a12*det,out[2]=-a22*det,out[3]=a03*det,out):null}function adjoint(out,a10){var a03=a10[0];return out[0]=a10[3],out[1]=-a10[1],out[2]=-a10[2],out[3]=a03,out}function determinant(a10){return a10[0]*a10[3]-a10[2]*a10[1]}function multiply(out,a10,b10){var a03=a10[0],a12=a10[1],a22=a10[2],a32=a10[3],b03=b10[0],b12=b10[1],b22=b10[2],b32=b10[3];return out[0]=a03*b03+a22*b12,out[1]=a12*b03+a32*b12,out[2]=a03*b22+a22*b32,out[3]=a12*b22+a32*b32,out}function rotate3(out,a10,rad){var a03=a10[0],a12=a10[1],a22=a10[2],a32=a10[3],s11=Math.sin(rad),c10=Math.cos(rad);return out[0]=a03*c10+a22*s11,out[1]=a12*c10+a32*s11,out[2]=a03*-s11+a22*c10,out[3]=a12*-s11+a32*c10,out}function scale3(out,a10,v11){var a03=a10[0],a12=a10[1],a22=a10[2],a32=a10[3],v03=v11[0],v12=v11[1];return out[0]=a03*v03,out[1]=a12*v03,out[2]=a22*v12,out[3]=a32*v12,out}function fromRotation(out,rad){var s11=Math.sin(rad),c10=Math.cos(rad);return out[0]=c10,out[1]=s11,out[2]=-s11,out[3]=c10,out}function fromScaling(out,v11){return out[0]=v11[0],out[1]=0,out[2]=0,out[3]=v11[1],out}function str(a10){return"mat2("+a10[0]+", "+a10[1]+", "+a10[2]+", "+a10[3]+")"}function frob(a10){return Math.sqrt(a10[0]*a10[0]+a10[1]*a10[1]+a10[2]*a10[2]+a10[3]*a10[3])}function LDU(L11,D11,U11,a10){return L11[2]=a10[2]/a10[0],U11[0]=a10[0],U11[1]=a10[1],U11[3]=a10[3]-L11[2]*U11[1],[L11,D11,U11]}function add(out,a10,b10){return out[0]=a10[0]+b10[0],out[1]=a10[1]+b10[1],out[2]=a10[2]+b10[2],out[3]=a10[3]+b10[3],out}function subtract2(out,a10,b10){return out[0]=a10[0]-b10[0],out[1]=a10[1]-b10[1],out[2]=a10[2]-b10[2],out[3]=a10[3]-b10[3],out}function exactEquals(a10,b10){return a10[0]===b10[0]&&a10[1]===b10[1]&&a10[2]===b10[2]&&a10[3]===b10[3]}function equals2(a10,b10){var a03=a10[0],a12=a10[1],a22=a10[2],a32=a10[3],b03=b10[0],b12=b10[1],b22=b10[2],b32=b10[3];return Math.abs(a03-b03)<=EPSILON*Math.max(1,Math.abs(a03),Math.abs(b03))&&Math.abs(a12-b12)<=EPSILON*Math.max(1,Math.abs(a12),Math.abs(b12))&&Math.abs(a22-b22)<=EPSILON*Math.max(1,Math.abs(a22),Math.abs(b22))&&Math.abs(a32-b32)<=EPSILON*Math.max(1,Math.abs(a32),Math.abs(b32))}function multiplyScalar(out,a10,b10){return out[0]=a10[0]*b10,out[1]=a10[1]*b10,out[2]=a10[2]*b10,out[3]=a10[3]*b10,out}function multiplyScalarAndAdd(out,a10,b10,scale15){return out[0]=a10[0]+b10[0]*scale15,out[1]=a10[1]+b10[1]*scale15,out[2]=a10[2]+b10[2]*scale15,out[3]=a10[3]+b10[3]*scale15,out}var mul,sub,init_mat2=__esm({"node_modules/gl-matrix/esm/mat2.js"(){"use strict";init_common();mul=multiply,sub=subtract2}});var mat2d_exports={};__export(mat2d_exports,{add:()=>add2,clone:()=>clone2,copy:()=>copy2,create:()=>create2,determinant:()=>determinant2,equals:()=>equals3,exactEquals:()=>exactEquals2,frob:()=>frob2,fromRotation:()=>fromRotation2,fromScaling:()=>fromScaling2,fromTranslation:()=>fromTranslation,fromValues:()=>fromValues3,identity:()=>identity3,invert:()=>invert2,mul:()=>mul2,multiply:()=>multiply2,multiplyScalar:()=>multiplyScalar2,multiplyScalarAndAdd:()=>multiplyScalarAndAdd2,rotate:()=>rotate4,scale:()=>scale4,set:()=>set2,str:()=>str2,sub:()=>sub2,subtract:()=>subtract3,translate:()=>translate3});function create2(){var out=new ARRAY_TYPE(6);return ARRAY_TYPE!=Float32Array&&(out[1]=0,out[2]=0,out[4]=0,out[5]=0),out[0]=1,out[3]=1,out}function clone2(a10){var out=new ARRAY_TYPE(6);return out[0]=a10[0],out[1]=a10[1],out[2]=a10[2],out[3]=a10[3],out[4]=a10[4],out[5]=a10[5],out}function copy2(out,a10){return out[0]=a10[0],out[1]=a10[1],out[2]=a10[2],out[3]=a10[3],out[4]=a10[4],out[5]=a10[5],out}function identity3(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out[4]=0,out[5]=0,out}function fromValues3(a10,b10,c10,d11,tx4,ty4){var out=new ARRAY_TYPE(6);return out[0]=a10,out[1]=b10,out[2]=c10,out[3]=d11,out[4]=tx4,out[5]=ty4,out}function set2(out,a10,b10,c10,d11,tx4,ty4){return out[0]=a10,out[1]=b10,out[2]=c10,out[3]=d11,out[4]=tx4,out[5]=ty4,out}function invert2(out,a10){var aa3=a10[0],ab4=a10[1],ac4=a10[2],ad3=a10[3],atx=a10[4],aty=a10[5],det=aa3*ad3-ab4*ac4;return det?(det=1/det,out[0]=ad3*det,out[1]=-ab4*det,out[2]=-ac4*det,out[3]=aa3*det,out[4]=(ac4*aty-ad3*atx)*det,out[5]=(ab4*atx-aa3*aty)*det,out):null}function determinant2(a10){return a10[0]*a10[3]-a10[1]*a10[2]}function multiply2(out,a10,b10){var a03=a10[0],a12=a10[1],a22=a10[2],a32=a10[3],a42=a10[4],a52=a10[5],b03=b10[0],b12=b10[1],b22=b10[2],b32=b10[3],b43=b10[4],b52=b10[5];return out[0]=a03*b03+a22*b12,out[1]=a12*b03+a32*b12,out[2]=a03*b22+a22*b32,out[3]=a12*b22+a32*b32,out[4]=a03*b43+a22*b52+a42,out[5]=a12*b43+a32*b52+a52,out}function rotate4(out,a10,rad){var a03=a10[0],a12=a10[1],a22=a10[2],a32=a10[3],a42=a10[4],a52=a10[5],s11=Math.sin(rad),c10=Math.cos(rad);return out[0]=a03*c10+a22*s11,out[1]=a12*c10+a32*s11,out[2]=a03*-s11+a22*c10,out[3]=a12*-s11+a32*c10,out[4]=a42,out[5]=a52,out}function scale4(out,a10,v11){var a03=a10[0],a12=a10[1],a22=a10[2],a32=a10[3],a42=a10[4],a52=a10[5],v03=v11[0],v12=v11[1];return out[0]=a03*v03,out[1]=a12*v03,out[2]=a22*v12,out[3]=a32*v12,out[4]=a42,out[5]=a52,out}function translate3(out,a10,v11){var a03=a10[0],a12=a10[1],a22=a10[2],a32=a10[3],a42=a10[4],a52=a10[5],v03=v11[0],v12=v11[1];return out[0]=a03,out[1]=a12,out[2]=a22,out[3]=a32,out[4]=a03*v03+a22*v12+a42,out[5]=a12*v03+a32*v12+a52,out}function fromRotation2(out,rad){var s11=Math.sin(rad),c10=Math.cos(rad);return out[0]=c10,out[1]=s11,out[2]=-s11,out[3]=c10,out[4]=0,out[5]=0,out}function fromScaling2(out,v11){return out[0]=v11[0],out[1]=0,out[2]=0,out[3]=v11[1],out[4]=0,out[5]=0,out}function fromTranslation(out,v11){return out[0]=1,out[1]=0,out[2]=0,out[3]=1,out[4]=v11[0],out[5]=v11[1],out}function str2(a10){return"mat2d("+a10[0]+", "+a10[1]+", "+a10[2]+", "+a10[3]+", "+a10[4]+", "+a10[5]+")"}function frob2(a10){return Math.sqrt(a10[0]*a10[0]+a10[1]*a10[1]+a10[2]*a10[2]+a10[3]*a10[3]+a10[4]*a10[4]+a10[5]*a10[5]+1)}function add2(out,a10,b10){return out[0]=a10[0]+b10[0],out[1]=a10[1]+b10[1],out[2]=a10[2]+b10[2],out[3]=a10[3]+b10[3],out[4]=a10[4]+b10[4],out[5]=a10[5]+b10[5],out}function subtract3(out,a10,b10){return out[0]=a10[0]-b10[0],out[1]=a10[1]-b10[1],out[2]=a10[2]-b10[2],out[3]=a10[3]-b10[3],out[4]=a10[4]-b10[4],out[5]=a10[5]-b10[5],out}function multiplyScalar2(out,a10,b10){return out[0]=a10[0]*b10,out[1]=a10[1]*b10,out[2]=a10[2]*b10,out[3]=a10[3]*b10,out[4]=a10[4]*b10,out[5]=a10[5]*b10,out}function multiplyScalarAndAdd2(out,a10,b10,scale15){return out[0]=a10[0]+b10[0]*scale15,out[1]=a10[1]+b10[1]*scale15,out[2]=a10[2]+b10[2]*scale15,out[3]=a10[3]+b10[3]*scale15,out[4]=a10[4]+b10[4]*scale15,out[5]=a10[5]+b10[5]*scale15,out}function exactEquals2(a10,b10){return a10[0]===b10[0]&&a10[1]===b10[1]&&a10[2]===b10[2]&&a10[3]===b10[3]&&a10[4]===b10[4]&&a10[5]===b10[5]}function equals3(a10,b10){var a03=a10[0],a12=a10[1],a22=a10[2],a32=a10[3],a42=a10[4],a52=a10[5],b03=b10[0],b12=b10[1],b22=b10[2],b32=b10[3],b43=b10[4],b52=b10[5];return Math.abs(a03-b03)<=EPSILON*Math.max(1,Math.abs(a03),Math.abs(b03))&&Math.abs(a12-b12)<=EPSILON*Math.max(1,Math.abs(a12),Math.abs(b12))&&Math.abs(a22-b22)<=EPSILON*Math.max(1,Math.abs(a22),Math.abs(b22))&&Math.abs(a32-b32)<=EPSILON*Math.max(1,Math.abs(a32),Math.abs(b32))&&Math.abs(a42-b43)<=EPSILON*Math.max(1,Math.abs(a42),Math.abs(b43))&&Math.abs(a52-b52)<=EPSILON*Math.max(1,Math.abs(a52),Math.abs(b52))}var mul2,sub2,init_mat2d=__esm({"node_modules/gl-matrix/esm/mat2d.js"(){"use strict";init_common();mul2=multiply2,sub2=subtract3}});var mat3_exports={};__export(mat3_exports,{add:()=>add3,adjoint:()=>adjoint2,clone:()=>clone3,copy:()=>copy3,create:()=>create3,determinant:()=>determinant3,equals:()=>equals4,exactEquals:()=>exactEquals3,frob:()=>frob3,fromMat2d:()=>fromMat2d,fromMat4:()=>fromMat4,fromQuat:()=>fromQuat,fromRotation:()=>fromRotation3,fromScaling:()=>fromScaling3,fromTranslation:()=>fromTranslation2,fromValues:()=>fromValues4,identity:()=>identity4,invert:()=>invert3,mul:()=>mul3,multiply:()=>multiply3,multiplyScalar:()=>multiplyScalar3,multiplyScalarAndAdd:()=>multiplyScalarAndAdd3,normalFromMat4:()=>normalFromMat4,projection:()=>projection,rotate:()=>rotate5,scale:()=>scale5,set:()=>set3,str:()=>str3,sub:()=>sub3,subtract:()=>subtract4,translate:()=>translate4,transpose:()=>transpose2});function create3(){var out=new ARRAY_TYPE(9);return ARRAY_TYPE!=Float32Array&&(out[1]=0,out[2]=0,out[3]=0,out[5]=0,out[6]=0,out[7]=0),out[0]=1,out[4]=1,out[8]=1,out}function fromMat4(out,a10){return out[0]=a10[0],out[1]=a10[1],out[2]=a10[2],out[3]=a10[4],out[4]=a10[5],out[5]=a10[6],out[6]=a10[8],out[7]=a10[9],out[8]=a10[10],out}function clone3(a10){var out=new ARRAY_TYPE(9);return out[0]=a10[0],out[1]=a10[1],out[2]=a10[2],out[3]=a10[3],out[4]=a10[4],out[5]=a10[5],out[6]=a10[6],out[7]=a10[7],out[8]=a10[8],out}function copy3(out,a10){return out[0]=a10[0],out[1]=a10[1],out[2]=a10[2],out[3]=a10[3],out[4]=a10[4],out[5]=a10[5],out[6]=a10[6],out[7]=a10[7],out[8]=a10[8],out}function fromValues4(m00,m01,m022,m10,m11,m12,m20,m21,m22){var out=new ARRAY_TYPE(9);return out[0]=m00,out[1]=m01,out[2]=m022,out[3]=m10,out[4]=m11,out[5]=m12,out[6]=m20,out[7]=m21,out[8]=m22,out}function set3(out,m00,m01,m022,m10,m11,m12,m20,m21,m22){return out[0]=m00,out[1]=m01,out[2]=m022,out[3]=m10,out[4]=m11,out[5]=m12,out[6]=m20,out[7]=m21,out[8]=m22,out}function identity4(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=1,out[5]=0,out[6]=0,out[7]=0,out[8]=1,out}function transpose2(out,a10){if(out===a10){var a01=a10[1],a022=a10[2],a12=a10[5];out[1]=a10[3],out[2]=a10[6],out[3]=a01,out[5]=a10[7],out[6]=a022,out[7]=a12}else out[0]=a10[0],out[1]=a10[3],out[2]=a10[6],out[3]=a10[1],out[4]=a10[4],out[5]=a10[7],out[6]=a10[2],out[7]=a10[5],out[8]=a10[8];return out}function invert3(out,a10){var a00=a10[0],a01=a10[1],a022=a10[2],a102=a10[3],a11=a10[4],a12=a10[5],a20=a10[6],a21=a10[7],a22=a10[8],b01=a22*a11-a12*a21,b11=-a22*a102+a12*a20,b21=a21*a102-a11*a20,det=a00*b01+a01*b11+a022*b21;return det?(det=1/det,out[0]=b01*det,out[1]=(-a22*a01+a022*a21)*det,out[2]=(a12*a01-a022*a11)*det,out[3]=b11*det,out[4]=(a22*a00-a022*a20)*det,out[5]=(-a12*a00+a022*a102)*det,out[6]=b21*det,out[7]=(-a21*a00+a01*a20)*det,out[8]=(a11*a00-a01*a102)*det,out):null}function adjoint2(out,a10){var a00=a10[0],a01=a10[1],a022=a10[2],a102=a10[3],a11=a10[4],a12=a10[5],a20=a10[6],a21=a10[7],a22=a10[8];return out[0]=a11*a22-a12*a21,out[1]=a022*a21-a01*a22,out[2]=a01*a12-a022*a11,out[3]=a12*a20-a102*a22,out[4]=a00*a22-a022*a20,out[5]=a022*a102-a00*a12,out[6]=a102*a21-a11*a20,out[7]=a01*a20-a00*a21,out[8]=a00*a11-a01*a102,out}function determinant3(a10){var a00=a10[0],a01=a10[1],a022=a10[2],a102=a10[3],a11=a10[4],a12=a10[5],a20=a10[6],a21=a10[7],a22=a10[8];return a00*(a22*a11-a12*a21)+a01*(-a22*a102+a12*a20)+a022*(a21*a102-a11*a20)}function multiply3(out,a10,b10){var a00=a10[0],a01=a10[1],a022=a10[2],a102=a10[3],a11=a10[4],a12=a10[5],a20=a10[6],a21=a10[7],a22=a10[8],b00=b10[0],b01=b10[1],b022=b10[2],b102=b10[3],b11=b10[4],b12=b10[5],b20=b10[6],b21=b10[7],b22=b10[8];return out[0]=b00*a00+b01*a102+b022*a20,out[1]=b00*a01+b01*a11+b022*a21,out[2]=b00*a022+b01*a12+b022*a22,out[3]=b102*a00+b11*a102+b12*a20,out[4]=b102*a01+b11*a11+b12*a21,out[5]=b102*a022+b11*a12+b12*a22,out[6]=b20*a00+b21*a102+b22*a20,out[7]=b20*a01+b21*a11+b22*a21,out[8]=b20*a022+b21*a12+b22*a22,out}function translate4(out,a10,v11){var a00=a10[0],a01=a10[1],a022=a10[2],a102=a10[3],a11=a10[4],a12=a10[5],a20=a10[6],a21=a10[7],a22=a10[8],x11=v11[0],y11=v11[1];return out[0]=a00,out[1]=a01,out[2]=a022,out[3]=a102,out[4]=a11,out[5]=a12,out[6]=x11*a00+y11*a102+a20,out[7]=x11*a01+y11*a11+a21,out[8]=x11*a022+y11*a12+a22,out}function rotate5(out,a10,rad){var a00=a10[0],a01=a10[1],a022=a10[2],a102=a10[3],a11=a10[4],a12=a10[5],a20=a10[6],a21=a10[7],a22=a10[8],s11=Math.sin(rad),c10=Math.cos(rad);return out[0]=c10*a00+s11*a102,out[1]=c10*a01+s11*a11,out[2]=c10*a022+s11*a12,out[3]=c10*a102-s11*a00,out[4]=c10*a11-s11*a01,out[5]=c10*a12-s11*a022,out[6]=a20,out[7]=a21,out[8]=a22,out}function scale5(out,a10,v11){var x11=v11[0],y11=v11[1];return out[0]=x11*a10[0],out[1]=x11*a10[1],out[2]=x11*a10[2],out[3]=y11*a10[3],out[4]=y11*a10[4],out[5]=y11*a10[5],out[6]=a10[6],out[7]=a10[7],out[8]=a10[8],out}function fromTranslation2(out,v11){return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=1,out[5]=0,out[6]=v11[0],out[7]=v11[1],out[8]=1,out}function fromRotation3(out,rad){var s11=Math.sin(rad),c10=Math.cos(rad);return out[0]=c10,out[1]=s11,out[2]=0,out[3]=-s11,out[4]=c10,out[5]=0,out[6]=0,out[7]=0,out[8]=1,out}function fromScaling3(out,v11){return out[0]=v11[0],out[1]=0,out[2]=0,out[3]=0,out[4]=v11[1],out[5]=0,out[6]=0,out[7]=0,out[8]=1,out}function fromMat2d(out,a10){return out[0]=a10[0],out[1]=a10[1],out[2]=0,out[3]=a10[2],out[4]=a10[3],out[5]=0,out[6]=a10[4],out[7]=a10[5],out[8]=1,out}function fromQuat(out,q11){var x11=q11[0],y11=q11[1],z10=q11[2],w10=q11[3],x22=x11+x11,y22=y11+y11,z22=z10+z10,xx4=x11*x22,yx4=y11*x22,yy4=y11*y22,zx4=z10*x22,zy4=z10*y22,zz2=z10*z22,wx4=w10*x22,wy4=w10*y22,wz2=w10*z22;return out[0]=1-yy4-zz2,out[3]=yx4-wz2,out[6]=zx4+wy4,out[1]=yx4+wz2,out[4]=1-xx4-zz2,out[7]=zy4-wx4,out[2]=zx4-wy4,out[5]=zy4+wx4,out[8]=1-xx4-yy4,out}function normalFromMat4(out,a10){var a00=a10[0],a01=a10[1],a022=a10[2],a03=a10[3],a102=a10[4],a11=a10[5],a12=a10[6],a13=a10[7],a20=a10[8],a21=a10[9],a22=a10[10],a23=a10[11],a30=a10[12],a31=a10[13],a32=a10[14],a33=a10[15],b00=a00*a11-a01*a102,b01=a00*a12-a022*a102,b022=a00*a13-a03*a102,b03=a01*a12-a022*a11,b04=a01*a13-a03*a11,b05=a022*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32,det=b00*b11-b01*b10+b022*b09+b03*b08-b04*b07+b05*b06;return det?(det=1/det,out[0]=(a11*b11-a12*b10+a13*b09)*det,out[1]=(a12*b08-a102*b11-a13*b07)*det,out[2]=(a102*b10-a11*b08+a13*b06)*det,out[3]=(a022*b10-a01*b11-a03*b09)*det,out[4]=(a00*b11-a022*b08+a03*b07)*det,out[5]=(a01*b08-a00*b10-a03*b06)*det,out[6]=(a31*b05-a32*b04+a33*b03)*det,out[7]=(a32*b022-a30*b05-a33*b01)*det,out[8]=(a30*b04-a31*b022+a33*b00)*det,out):null}function projection(out,width,height){return out[0]=2/width,out[1]=0,out[2]=0,out[3]=0,out[4]=-2/height,out[5]=0,out[6]=-1,out[7]=1,out[8]=1,out}function str3(a10){return"mat3("+a10[0]+", "+a10[1]+", "+a10[2]+", "+a10[3]+", "+a10[4]+", "+a10[5]+", "+a10[6]+", "+a10[7]+", "+a10[8]+")"}function frob3(a10){return Math.sqrt(a10[0]*a10[0]+a10[1]*a10[1]+a10[2]*a10[2]+a10[3]*a10[3]+a10[4]*a10[4]+a10[5]*a10[5]+a10[6]*a10[6]+a10[7]*a10[7]+a10[8]*a10[8])}function add3(out,a10,b10){return out[0]=a10[0]+b10[0],out[1]=a10[1]+b10[1],out[2]=a10[2]+b10[2],out[3]=a10[3]+b10[3],out[4]=a10[4]+b10[4],out[5]=a10[5]+b10[5],out[6]=a10[6]+b10[6],out[7]=a10[7]+b10[7],out[8]=a10[8]+b10[8],out}function subtract4(out,a10,b10){return out[0]=a10[0]-b10[0],out[1]=a10[1]-b10[1],out[2]=a10[2]-b10[2],out[3]=a10[3]-b10[3],out[4]=a10[4]-b10[4],out[5]=a10[5]-b10[5],out[6]=a10[6]-b10[6],out[7]=a10[7]-b10[7],out[8]=a10[8]-b10[8],out}function multiplyScalar3(out,a10,b10){return out[0]=a10[0]*b10,out[1]=a10[1]*b10,out[2]=a10[2]*b10,out[3]=a10[3]*b10,out[4]=a10[4]*b10,out[5]=a10[5]*b10,out[6]=a10[6]*b10,out[7]=a10[7]*b10,out[8]=a10[8]*b10,out}function multiplyScalarAndAdd3(out,a10,b10,scale15){return out[0]=a10[0]+b10[0]*scale15,out[1]=a10[1]+b10[1]*scale15,out[2]=a10[2]+b10[2]*scale15,out[3]=a10[3]+b10[3]*scale15,out[4]=a10[4]+b10[4]*scale15,out[5]=a10[5]+b10[5]*scale15,out[6]=a10[6]+b10[6]*scale15,out[7]=a10[7]+b10[7]*scale15,out[8]=a10[8]+b10[8]*scale15,out}function exactEquals3(a10,b10){return a10[0]===b10[0]&&a10[1]===b10[1]&&a10[2]===b10[2]&&a10[3]===b10[3]&&a10[4]===b10[4]&&a10[5]===b10[5]&&a10[6]===b10[6]&&a10[7]===b10[7]&&a10[8]===b10[8]}function equals4(a10,b10){var a03=a10[0],a12=a10[1],a22=a10[2],a32=a10[3],a42=a10[4],a52=a10[5],a62=a10[6],a72=a10[7],a82=a10[8],b03=b10[0],b12=b10[1],b22=b10[2],b32=b10[3],b43=b10[4],b52=b10[5],b62=b10[6],b72=b10[7],b82=b10[8];return Math.abs(a03-b03)<=EPSILON*Math.max(1,Math.abs(a03),Math.abs(b03))&&Math.abs(a12-b12)<=EPSILON*Math.max(1,Math.abs(a12),Math.abs(b12))&&Math.abs(a22-b22)<=EPSILON*Math.max(1,Math.abs(a22),Math.abs(b22))&&Math.abs(a32-b32)<=EPSILON*Math.max(1,Math.abs(a32),Math.abs(b32))&&Math.abs(a42-b43)<=EPSILON*Math.max(1,Math.abs(a42),Math.abs(b43))&&Math.abs(a52-b52)<=EPSILON*Math.max(1,Math.abs(a52),Math.abs(b52))&&Math.abs(a62-b62)<=EPSILON*Math.max(1,Math.abs(a62),Math.abs(b62))&&Math.abs(a72-b72)<=EPSILON*Math.max(1,Math.abs(a72),Math.abs(b72))&&Math.abs(a82-b82)<=EPSILON*Math.max(1,Math.abs(a82),Math.abs(b82))}var mul3,sub3,init_mat3=__esm({"node_modules/gl-matrix/esm/mat3.js"(){"use strict";init_common();mul3=multiply3,sub3=subtract4}});var mat4_exports={};__export(mat4_exports,{add:()=>add4,adjoint:()=>adjoint3,clone:()=>clone4,copy:()=>copy4,create:()=>create4,decompose:()=>decompose,determinant:()=>determinant4,equals:()=>equals5,exactEquals:()=>exactEquals4,frob:()=>frob4,fromQuat:()=>fromQuat3,fromQuat2:()=>fromQuat2,fromRotation:()=>fromRotation4,fromRotationTranslation:()=>fromRotationTranslation,fromRotationTranslationScale:()=>fromRotationTranslationScale,fromRotationTranslationScaleOrigin:()=>fromRotationTranslationScaleOrigin,fromScaling:()=>fromScaling4,fromTranslation:()=>fromTranslation3,fromValues:()=>fromValues5,fromXRotation:()=>fromXRotation,fromYRotation:()=>fromYRotation,fromZRotation:()=>fromZRotation,frustum:()=>frustum,getRotation:()=>getRotation,getScaling:()=>getScaling,getTranslation:()=>getTranslation,identity:()=>identity5,invert:()=>invert4,lookAt:()=>lookAt,mul:()=>mul4,multiply:()=>multiply4,multiplyScalar:()=>multiplyScalar4,multiplyScalarAndAdd:()=>multiplyScalarAndAdd4,ortho:()=>ortho,orthoNO:()=>orthoNO,orthoZO:()=>orthoZO,perspective:()=>perspective,perspectiveFromFieldOfView:()=>perspectiveFromFieldOfView,perspectiveNO:()=>perspectiveNO,perspectiveZO:()=>perspectiveZO,rotate:()=>rotate6,rotateX:()=>rotateX,rotateY:()=>rotateY,rotateZ:()=>rotateZ,scale:()=>scale6,set:()=>set4,str:()=>str4,sub:()=>sub4,subtract:()=>subtract5,targetTo:()=>targetTo,translate:()=>translate5,transpose:()=>transpose3});function create4(){var out=new ARRAY_TYPE(16);return ARRAY_TYPE!=Float32Array&&(out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[11]=0,out[12]=0,out[13]=0,out[14]=0),out[0]=1,out[5]=1,out[10]=1,out[15]=1,out}function clone4(a10){var out=new ARRAY_TYPE(16);return out[0]=a10[0],out[1]=a10[1],out[2]=a10[2],out[3]=a10[3],out[4]=a10[4],out[5]=a10[5],out[6]=a10[6],out[7]=a10[7],out[8]=a10[8],out[9]=a10[9],out[10]=a10[10],out[11]=a10[11],out[12]=a10[12],out[13]=a10[13],out[14]=a10[14],out[15]=a10[15],out}function copy4(out,a10){return out[0]=a10[0],out[1]=a10[1],out[2]=a10[2],out[3]=a10[3],out[4]=a10[4],out[5]=a10[5],out[6]=a10[6],out[7]=a10[7],out[8]=a10[8],out[9]=a10[9],out[10]=a10[10],out[11]=a10[11],out[12]=a10[12],out[13]=a10[13],out[14]=a10[14],out[15]=a10[15],out}function fromValues5(m00,m01,m022,m03,m10,m11,m12,m13,m20,m21,m22,m23,m30,m31,m32,m33){var out=new ARRAY_TYPE(16);return out[0]=m00,out[1]=m01,out[2]=m022,out[3]=m03,out[4]=m10,out[5]=m11,out[6]=m12,out[7]=m13,out[8]=m20,out[9]=m21,out[10]=m22,out[11]=m23,out[12]=m30,out[13]=m31,out[14]=m32,out[15]=m33,out}function set4(out,m00,m01,m022,m03,m10,m11,m12,m13,m20,m21,m22,m23,m30,m31,m32,m33){return out[0]=m00,out[1]=m01,out[2]=m022,out[3]=m03,out[4]=m10,out[5]=m11,out[6]=m12,out[7]=m13,out[8]=m20,out[9]=m21,out[10]=m22,out[11]=m23,out[12]=m30,out[13]=m31,out[14]=m32,out[15]=m33,out}function identity5(out){return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=1,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[10]=1,out[11]=0,out[12]=0,out[13]=0,out[14]=0,out[15]=1,out}function transpose3(out,a10){if(out===a10){var a01=a10[1],a022=a10[2],a03=a10[3],a12=a10[6],a13=a10[7],a23=a10[11];out[1]=a10[4],out[2]=a10[8],out[3]=a10[12],out[4]=a01,out[6]=a10[9],out[7]=a10[13],out[8]=a022,out[9]=a12,out[11]=a10[14],out[12]=a03,out[13]=a13,out[14]=a23}else out[0]=a10[0],out[1]=a10[4],out[2]=a10[8],out[3]=a10[12],out[4]=a10[1],out[5]=a10[5],out[6]=a10[9],out[7]=a10[13],out[8]=a10[2],out[9]=a10[6],out[10]=a10[10],out[11]=a10[14],out[12]=a10[3],out[13]=a10[7],out[14]=a10[11],out[15]=a10[15];return out}function invert4(out,a10){var a00=a10[0],a01=a10[1],a022=a10[2],a03=a10[3],a102=a10[4],a11=a10[5],a12=a10[6],a13=a10[7],a20=a10[8],a21=a10[9],a22=a10[10],a23=a10[11],a30=a10[12],a31=a10[13],a32=a10[14],a33=a10[15],b00=a00*a11-a01*a102,b01=a00*a12-a022*a102,b022=a00*a13-a03*a102,b03=a01*a12-a022*a11,b04=a01*a13-a03*a11,b05=a022*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32,det=b00*b11-b01*b10+b022*b09+b03*b08-b04*b07+b05*b06;return det?(det=1/det,out[0]=(a11*b11-a12*b10+a13*b09)*det,out[1]=(a022*b10-a01*b11-a03*b09)*det,out[2]=(a31*b05-a32*b04+a33*b03)*det,out[3]=(a22*b04-a21*b05-a23*b03)*det,out[4]=(a12*b08-a102*b11-a13*b07)*det,out[5]=(a00*b11-a022*b08+a03*b07)*det,out[6]=(a32*b022-a30*b05-a33*b01)*det,out[7]=(a20*b05-a22*b022+a23*b01)*det,out[8]=(a102*b10-a11*b08+a13*b06)*det,out[9]=(a01*b08-a00*b10-a03*b06)*det,out[10]=(a30*b04-a31*b022+a33*b00)*det,out[11]=(a21*b022-a20*b04-a23*b00)*det,out[12]=(a11*b07-a102*b09-a12*b06)*det,out[13]=(a00*b09-a01*b07+a022*b06)*det,out[14]=(a31*b01-a30*b03-a32*b00)*det,out[15]=(a20*b03-a21*b01+a22*b00)*det,out):null}function adjoint3(out,a10){var a00=a10[0],a01=a10[1],a022=a10[2],a03=a10[3],a102=a10[4],a11=a10[5],a12=a10[6],a13=a10[7],a20=a10[8],a21=a10[9],a22=a10[10],a23=a10[11],a30=a10[12],a31=a10[13],a32=a10[14],a33=a10[15],b00=a00*a11-a01*a102,b01=a00*a12-a022*a102,b022=a00*a13-a03*a102,b03=a01*a12-a022*a11,b04=a01*a13-a03*a11,b05=a022*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32;return out[0]=a11*b11-a12*b10+a13*b09,out[1]=a022*b10-a01*b11-a03*b09,out[2]=a31*b05-a32*b04+a33*b03,out[3]=a22*b04-a21*b05-a23*b03,out[4]=a12*b08-a102*b11-a13*b07,out[5]=a00*b11-a022*b08+a03*b07,out[6]=a32*b022-a30*b05-a33*b01,out[7]=a20*b05-a22*b022+a23*b01,out[8]=a102*b10-a11*b08+a13*b06,out[9]=a01*b08-a00*b10-a03*b06,out[10]=a30*b04-a31*b022+a33*b00,out[11]=a21*b022-a20*b04-a23*b00,out[12]=a11*b07-a102*b09-a12*b06,out[13]=a00*b09-a01*b07+a022*b06,out[14]=a31*b01-a30*b03-a32*b00,out[15]=a20*b03-a21*b01+a22*b00,out}function determinant4(a10){var a00=a10[0],a01=a10[1],a022=a10[2],a03=a10[3],a102=a10[4],a11=a10[5],a12=a10[6],a13=a10[7],a20=a10[8],a21=a10[9],a22=a10[10],a23=a10[11],a30=a10[12],a31=a10[13],a32=a10[14],a33=a10[15],b03=a00*a11-a01*a102,b12=a00*a12-a022*a102,b22=a01*a12-a022*a11,b32=a20*a31-a21*a30,b43=a20*a32-a22*a30,b52=a21*a32-a22*a31,b62=a00*b52-a01*b43+a022*b32,b72=a102*b52-a11*b43+a12*b32,b82=a20*b22-a21*b12+a22*b03,b93=a30*b22-a31*b12+a32*b03;return a13*b62-a03*b72+a33*b82-a23*b93}function multiply4(out,a10,b10){var a00=a10[0],a01=a10[1],a022=a10[2],a03=a10[3],a102=a10[4],a11=a10[5],a12=a10[6],a13=a10[7],a20=a10[8],a21=a10[9],a22=a10[10],a23=a10[11],a30=a10[12],a31=a10[13],a32=a10[14],a33=a10[15],b03=b10[0],b12=b10[1],b22=b10[2],b32=b10[3];return out[0]=b03*a00+b12*a102+b22*a20+b32*a30,out[1]=b03*a01+b12*a11+b22*a21+b32*a31,out[2]=b03*a022+b12*a12+b22*a22+b32*a32,out[3]=b03*a03+b12*a13+b22*a23+b32*a33,b03=b10[4],b12=b10[5],b22=b10[6],b32=b10[7],out[4]=b03*a00+b12*a102+b22*a20+b32*a30,out[5]=b03*a01+b12*a11+b22*a21+b32*a31,out[6]=b03*a022+b12*a12+b22*a22+b32*a32,out[7]=b03*a03+b12*a13+b22*a23+b32*a33,b03=b10[8],b12=b10[9],b22=b10[10],b32=b10[11],out[8]=b03*a00+b12*a102+b22*a20+b32*a30,out[9]=b03*a01+b12*a11+b22*a21+b32*a31,out[10]=b03*a022+b12*a12+b22*a22+b32*a32,out[11]=b03*a03+b12*a13+b22*a23+b32*a33,b03=b10[12],b12=b10[13],b22=b10[14],b32=b10[15],out[12]=b03*a00+b12*a102+b22*a20+b32*a30,out[13]=b03*a01+b12*a11+b22*a21+b32*a31,out[14]=b03*a022+b12*a12+b22*a22+b32*a32,out[15]=b03*a03+b12*a13+b22*a23+b32*a33,out}function translate5(out,a10,v11){var x11=v11[0],y11=v11[1],z10=v11[2],a00,a01,a022,a03,a102,a11,a12,a13,a20,a21,a22,a23;return a10===out?(out[12]=a10[0]*x11+a10[4]*y11+a10[8]*z10+a10[12],out[13]=a10[1]*x11+a10[5]*y11+a10[9]*z10+a10[13],out[14]=a10[2]*x11+a10[6]*y11+a10[10]*z10+a10[14],out[15]=a10[3]*x11+a10[7]*y11+a10[11]*z10+a10[15]):(a00=a10[0],a01=a10[1],a022=a10[2],a03=a10[3],a102=a10[4],a11=a10[5],a12=a10[6],a13=a10[7],a20=a10[8],a21=a10[9],a22=a10[10],a23=a10[11],out[0]=a00,out[1]=a01,out[2]=a022,out[3]=a03,out[4]=a102,out[5]=a11,out[6]=a12,out[7]=a13,out[8]=a20,out[9]=a21,out[10]=a22,out[11]=a23,out[12]=a00*x11+a102*y11+a20*z10+a10[12],out[13]=a01*x11+a11*y11+a21*z10+a10[13],out[14]=a022*x11+a12*y11+a22*z10+a10[14],out[15]=a03*x11+a13*y11+a23*z10+a10[15]),out}function scale6(out,a10,v11){var x11=v11[0],y11=v11[1],z10=v11[2];return out[0]=a10[0]*x11,out[1]=a10[1]*x11,out[2]=a10[2]*x11,out[3]=a10[3]*x11,out[4]=a10[4]*y11,out[5]=a10[5]*y11,out[6]=a10[6]*y11,out[7]=a10[7]*y11,out[8]=a10[8]*z10,out[9]=a10[9]*z10,out[10]=a10[10]*z10,out[11]=a10[11]*z10,out[12]=a10[12],out[13]=a10[13],out[14]=a10[14],out[15]=a10[15],out}function rotate6(out,a10,rad,axis){var x11=axis[0],y11=axis[1],z10=axis[2],len6=Math.sqrt(x11*x11+y11*y11+z10*z10),s11,c10,t48,a00,a01,a022,a03,a102,a11,a12,a13,a20,a21,a22,a23,b00,b01,b022,b10,b11,b12,b20,b21,b22;return len6<EPSILON?null:(len6=1/len6,x11*=len6,y11*=len6,z10*=len6,s11=Math.sin(rad),c10=Math.cos(rad),t48=1-c10,a00=a10[0],a01=a10[1],a022=a10[2],a03=a10[3],a102=a10[4],a11=a10[5],a12=a10[6],a13=a10[7],a20=a10[8],a21=a10[9],a22=a10[10],a23=a10[11],b00=x11*x11*t48+c10,b01=y11*x11*t48+z10*s11,b022=z10*x11*t48-y11*s11,b10=x11*y11*t48-z10*s11,b11=y11*y11*t48+c10,b12=z10*y11*t48+x11*s11,b20=x11*z10*t48+y11*s11,b21=y11*z10*t48-x11*s11,b22=z10*z10*t48+c10,out[0]=a00*b00+a102*b01+a20*b022,out[1]=a01*b00+a11*b01+a21*b022,out[2]=a022*b00+a12*b01+a22*b022,out[3]=a03*b00+a13*b01+a23*b022,out[4]=a00*b10+a102*b11+a20*b12,out[5]=a01*b10+a11*b11+a21*b12,out[6]=a022*b10+a12*b11+a22*b12,out[7]=a03*b10+a13*b11+a23*b12,out[8]=a00*b20+a102*b21+a20*b22,out[9]=a01*b20+a11*b21+a21*b22,out[10]=a022*b20+a12*b21+a22*b22,out[11]=a03*b20+a13*b21+a23*b22,a10!==out&&(out[12]=a10[12],out[13]=a10[13],out[14]=a10[14],out[15]=a10[15]),out)}function rotateX(out,a10,rad){var s11=Math.sin(rad),c10=Math.cos(rad),a102=a10[4],a11=a10[5],a12=a10[6],a13=a10[7],a20=a10[8],a21=a10[9],a22=a10[10],a23=a10[11];return a10!==out&&(out[0]=a10[0],out[1]=a10[1],out[2]=a10[2],out[3]=a10[3],out[12]=a10[12],out[13]=a10[13],out[14]=a10[14],out[15]=a10[15]),out[4]=a102*c10+a20*s11,out[5]=a11*c10+a21*s11,out[6]=a12*c10+a22*s11,out[7]=a13*c10+a23*s11,out[8]=a20*c10-a102*s11,out[9]=a21*c10-a11*s11,out[10]=a22*c10-a12*s11,out[11]=a23*c10-a13*s11,out}function rotateY(out,a10,rad){var s11=Math.sin(rad),c10=Math.cos(rad),a00=a10[0],a01=a10[1],a022=a10[2],a03=a10[3],a20=a10[8],a21=a10[9],a22=a10[10],a23=a10[11];return a10!==out&&(out[4]=a10[4],out[5]=a10[5],out[6]=a10[6],out[7]=a10[7],out[12]=a10[12],out[13]=a10[13],out[14]=a10[14],out[15]=a10[15]),out[0]=a00*c10-a20*s11,out[1]=a01*c10-a21*s11,out[2]=a022*c10-a22*s11,out[3]=a03*c10-a23*s11,out[8]=a00*s11+a20*c10,out[9]=a01*s11+a21*c10,out[10]=a022*s11+a22*c10,out[11]=a03*s11+a23*c10,out}function rotateZ(out,a10,rad){var s11=Math.sin(rad),c10=Math.cos(rad),a00=a10[0],a01=a10[1],a022=a10[2],a03=a10[3],a102=a10[4],a11=a10[5],a12=a10[6],a13=a10[7];return a10!==out&&(out[8]=a10[8],out[9]=a10[9],out[10]=a10[10],out[11]=a10[11],out[12]=a10[12],out[13]=a10[13],out[14]=a10[14],out[15]=a10[15]),out[0]=a00*c10+a102*s11,out[1]=a01*c10+a11*s11,out[2]=a022*c10+a12*s11,out[3]=a03*c10+a13*s11,out[4]=a102*c10-a00*s11,out[5]=a11*c10-a01*s11,out[6]=a12*c10-a022*s11,out[7]=a13*c10-a03*s11,out}function fromTranslation3(out,v11){return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=1,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[10]=1,out[11]=0,out[12]=v11[0],out[13]=v11[1],out[14]=v11[2],out[15]=1,out}function fromScaling4(out,v11){return out[0]=v11[0],out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=v11[1],out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[10]=v11[2],out[11]=0,out[12]=0,out[13]=0,out[14]=0,out[15]=1,out}function fromRotation4(out,rad,axis){var x11=axis[0],y11=axis[1],z10=axis[2],len6=Math.sqrt(x11*x11+y11*y11+z10*z10),s11,c10,t48;return len6<EPSILON?null:(len6=1/len6,x11*=len6,y11*=len6,z10*=len6,s11=Math.sin(rad),c10=Math.cos(rad),t48=1-c10,out[0]=x11*x11*t48+c10,out[1]=y11*x11*t48+z10*s11,out[2]=z10*x11*t48-y11*s11,out[3]=0,out[4]=x11*y11*t48-z10*s11,out[5]=y11*y11*t48+c10,out[6]=z10*y11*t48+x11*s11,out[7]=0,out[8]=x11*z10*t48+y11*s11,out[9]=y11*z10*t48-x11*s11,out[10]=z10*z10*t48+c10,out[11]=0,out[12]=0,out[13]=0,out[14]=0,out[15]=1,out)}function fromXRotation(out,rad){var s11=Math.sin(rad),c10=Math.cos(rad);return out[0]=1,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=c10,out[6]=s11,out[7]=0,out[8]=0,out[9]=-s11,out[10]=c10,out[11]=0,out[12]=0,out[13]=0,out[14]=0,out[15]=1,out}function fromYRotation(out,rad){var s11=Math.sin(rad),c10=Math.cos(rad);return out[0]=c10,out[1]=0,out[2]=-s11,out[3]=0,out[4]=0,out[5]=1,out[6]=0,out[7]=0,out[8]=s11,out[9]=0,out[10]=c10,out[11]=0,out[12]=0,out[13]=0,out[14]=0,out[15]=1,out}function fromZRotation(out,rad){var s11=Math.sin(rad),c10=Math.cos(rad);return out[0]=c10,out[1]=s11,out[2]=0,out[3]=0,out[4]=-s11,out[5]=c10,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[10]=1,out[11]=0,out[12]=0,out[13]=0,out[14]=0,out[15]=1,out}function fromRotationTranslation(out,q11,v11){var x11=q11[0],y11=q11[1],z10=q11[2],w10=q11[3],x22=x11+x11,y22=y11+y11,z22=z10+z10,xx4=x11*x22,xy4=x11*y22,xz2=x11*z22,yy4=y11*y22,yz2=y11*z22,zz2=z10*z22,wx4=w10*x22,wy4=w10*y22,wz2=w10*z22;return out[0]=1-(yy4+zz2),out[1]=xy4+wz2,out[2]=xz2-wy4,out[3]=0,out[4]=xy4-wz2,out[5]=1-(xx4+zz2),out[6]=yz2+wx4,out[7]=0,out[8]=xz2+wy4,out[9]=yz2-wx4,out[10]=1-(xx4+yy4),out[11]=0,out[12]=v11[0],out[13]=v11[1],out[14]=v11[2],out[15]=1,out}function fromQuat2(out,a10){var translation=new ARRAY_TYPE(3),bx4=-a10[0],by4=-a10[1],bz2=-a10[2],bw4=a10[3],ax4=a10[4],ay4=a10[5],az2=a10[6],aw3=a10[7],magnitude=bx4*bx4+by4*by4+bz2*bz2+bw4*bw4;return magnitude>0?(translation[0]=(ax4*bw4+aw3*bx4+ay4*bz2-az2*by4)*2/magnitude,translation[1]=(ay4*bw4+aw3*by4+az2*bx4-ax4*bz2)*2/magnitude,translation[2]=(az2*bw4+aw3*bz2+ax4*by4-ay4*bx4)*2/magnitude):(translation[0]=(ax4*bw4+aw3*bx4+ay4*bz2-az2*by4)*2,translation[1]=(ay4*bw4+aw3*by4+az2*bx4-ax4*bz2)*2,translation[2]=(az2*bw4+aw3*bz2+ax4*by4-ay4*bx4)*2),fromRotationTranslation(out,a10,translation),out}function getTranslation(out,mat){return out[0]=mat[12],out[1]=mat[13],out[2]=mat[14],out}function getScaling(out,mat){var m11=mat[0],m12=mat[1],m13=mat[2],m21=mat[4],m22=mat[5],m23=mat[6],m31=mat[8],m32=mat[9],m33=mat[10];return out[0]=Math.sqrt(m11*m11+m12*m12+m13*m13),out[1]=Math.sqrt(m21*m21+m22*m22+m23*m23),out[2]=Math.sqrt(m31*m31+m32*m32+m33*m33),out}function getRotation(out,mat){var scaling=new ARRAY_TYPE(3);getScaling(scaling,mat);var is1=1/scaling[0],is22=1/scaling[1],is32=1/scaling[2],sm11=mat[0]*is1,sm12=mat[1]*is22,sm13=mat[2]*is32,sm21=mat[4]*is1,sm22=mat[5]*is22,sm23=mat[6]*is32,sm31=mat[8]*is1,sm32=mat[9]*is22,sm33=mat[10]*is32,trace=sm11+sm22+sm33,S10=0;return trace>0?(S10=Math.sqrt(trace+1)*2,out[3]=.25*S10,out[0]=(sm23-sm32)/S10,out[1]=(sm31-sm13)/S10,out[2]=(sm12-sm21)/S10):sm11>sm22&&sm11>sm33?(S10=Math.sqrt(1+sm11-sm22-sm33)*2,out[3]=(sm23-sm32)/S10,out[0]=.25*S10,out[1]=(sm12+sm21)/S10,out[2]=(sm31+sm13)/S10):sm22>sm33?(S10=Math.sqrt(1+sm22-sm11-sm33)*2,out[3]=(sm31-sm13)/S10,out[0]=(sm12+sm21)/S10,out[1]=.25*S10,out[2]=(sm23+sm32)/S10):(S10=Math.sqrt(1+sm33-sm11-sm22)*2,out[3]=(sm12-sm21)/S10,out[0]=(sm31+sm13)/S10,out[1]=(sm23+sm32)/S10,out[2]=.25*S10),out}function decompose(out_r,out_t,out_s,mat){out_t[0]=mat[12],out_t[1]=mat[13],out_t[2]=mat[14];var m11=mat[0],m12=mat[1],m13=mat[2],m21=mat[4],m22=mat[5],m23=mat[6],m31=mat[8],m32=mat[9],m33=mat[10];out_s[0]=Math.sqrt(m11*m11+m12*m12+m13*m13),out_s[1]=Math.sqrt(m21*m21+m22*m22+m23*m23),out_s[2]=Math.sqrt(m31*m31+m32*m32+m33*m33);var is1=1/out_s[0],is22=1/out_s[1],is32=1/out_s[2],sm11=m11*is1,sm12=m12*is22,sm13=m13*is32,sm21=m21*is1,sm22=m22*is22,sm23=m23*is32,sm31=m31*is1,sm32=m32*is22,sm33=m33*is32,trace=sm11+sm22+sm33,S10=0;return trace>0?(S10=Math.sqrt(trace+1)*2,out_r[3]=.25*S10,out_r[0]=(sm23-sm32)/S10,out_r[1]=(sm31-sm13)/S10,out_r[2]=(sm12-sm21)/S10):sm11>sm22&&sm11>sm33?(S10=Math.sqrt(1+sm11-sm22-sm33)*2,out_r[3]=(sm23-sm32)/S10,out_r[0]=.25*S10,out_r[1]=(sm12+sm21)/S10,out_r[2]=(sm31+sm13)/S10):sm22>sm33?(S10=Math.sqrt(1+sm22-sm11-sm33)*2,out_r[3]=(sm31-sm13)/S10,out_r[0]=(sm12+sm21)/S10,out_r[1]=.25*S10,out_r[2]=(sm23+sm32)/S10):(S10=Math.sqrt(1+sm33-sm11-sm22)*2,out_r[3]=(sm12-sm21)/S10,out_r[0]=(sm31+sm13)/S10,out_r[1]=(sm23+sm32)/S10,out_r[2]=.25*S10),out_r}function fromRotationTranslationScale(out,q11,v11,s11){var x11=q11[0],y11=q11[1],z10=q11[2],w10=q11[3],x22=x11+x11,y22=y11+y11,z22=z10+z10,xx4=x11*x22,xy4=x11*y22,xz2=x11*z22,yy4=y11*y22,yz2=y11*z22,zz2=z10*z22,wx4=w10*x22,wy4=w10*y22,wz2=w10*z22,sx4=s11[0],sy4=s11[1],sz2=s11[2];return out[0]=(1-(yy4+zz2))*sx4,out[1]=(xy4+wz2)*sx4,out[2]=(xz2-wy4)*sx4,out[3]=0,out[4]=(xy4-wz2)*sy4,out[5]=(1-(xx4+zz2))*sy4,out[6]=(yz2+wx4)*sy4,out[7]=0,out[8]=(xz2+wy4)*sz2,out[9]=(yz2-wx4)*sz2,out[10]=(1-(xx4+yy4))*sz2,out[11]=0,out[12]=v11[0],out[13]=v11[1],out[14]=v11[2],out[15]=1,out}function fromRotationTranslationScaleOrigin(out,q11,v11,s11,o11){var x11=q11[0],y11=q11[1],z10=q11[2],w10=q11[3],x22=x11+x11,y22=y11+y11,z22=z10+z10,xx4=x11*x22,xy4=x11*y22,xz2=x11*z22,yy4=y11*y22,yz2=y11*z22,zz2=z10*z22,wx4=w10*x22,wy4=w10*y22,wz2=w10*z22,sx4=s11[0],sy4=s11[1],sz2=s11[2],ox4=o11[0],oy4=o11[1],oz2=o11[2],out0=(1-(yy4+zz2))*sx4,out1=(xy4+wz2)*sx4,out2=(xz2-wy4)*sx4,out4=(xy4-wz2)*sy4,out5=(1-(xx4+zz2))*sy4,out6=(yz2+wx4)*sy4,out8=(xz2+wy4)*sz2,out9=(yz2-wx4)*sz2,out10=(1-(xx4+yy4))*sz2;return out[0]=out0,out[1]=out1,out[2]=out2,out[3]=0,out[4]=out4,out[5]=out5,out[6]=out6,out[7]=0,out[8]=out8,out[9]=out9,out[10]=out10,out[11]=0,out[12]=v11[0]+ox4-(out0*ox4+out4*oy4+out8*oz2),out[13]=v11[1]+oy4-(out1*ox4+out5*oy4+out9*oz2),out[14]=v11[2]+oz2-(out2*ox4+out6*oy4+out10*oz2),out[15]=1,out}function fromQuat3(out,q11){var x11=q11[0],y11=q11[1],z10=q11[2],w10=q11[3],x22=x11+x11,y22=y11+y11,z22=z10+z10,xx4=x11*x22,yx4=y11*x22,yy4=y11*y22,zx4=z10*x22,zy4=z10*y22,zz2=z10*z22,wx4=w10*x22,wy4=w10*y22,wz2=w10*z22;return out[0]=1-yy4-zz2,out[1]=yx4+wz2,out[2]=zx4-wy4,out[3]=0,out[4]=yx4-wz2,out[5]=1-xx4-zz2,out[6]=zy4+wx4,out[7]=0,out[8]=zx4+wy4,out[9]=zy4-wx4,out[10]=1-xx4-yy4,out[11]=0,out[12]=0,out[13]=0,out[14]=0,out[15]=1,out}function frustum(out,left,right,bottom,top,near3,far){var rl3=1/(right-left),tb4=1/(top-bottom),nf3=1/(near3-far);return out[0]=near3*2*rl3,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=near3*2*tb4,out[6]=0,out[7]=0,out[8]=(right+left)*rl3,out[9]=(top+bottom)*tb4,out[10]=(far+near3)*nf3,out[11]=-1,out[12]=0,out[13]=0,out[14]=far*near3*2*nf3,out[15]=0,out}function perspectiveNO(out,fovy,aspect,near3,far){var f3=1/Math.tan(fovy/2);if(out[0]=f3/aspect,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=f3,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[11]=-1,out[12]=0,out[13]=0,out[15]=0,far!=null&&far!==1/0){var nf3=1/(near3-far);out[10]=(far+near3)*nf3,out[14]=2*far*near3*nf3}else out[10]=-1,out[14]=-2*near3;return out}function perspectiveZO(out,fovy,aspect,near3,far){var f3=1/Math.tan(fovy/2);if(out[0]=f3/aspect,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=f3,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[11]=-1,out[12]=0,out[13]=0,out[15]=0,far!=null&&far!==1/0){var nf3=1/(near3-far);out[10]=far*nf3,out[14]=far*near3*nf3}else out[10]=-1,out[14]=-near3;return out}function perspectiveFromFieldOfView(out,fov,near3,far){var upTan=Math.tan(fov.upDegrees*Math.PI/180),downTan=Math.tan(fov.downDegrees*Math.PI/180),leftTan=Math.tan(fov.leftDegrees*Math.PI/180),rightTan=Math.tan(fov.rightDegrees*Math.PI/180),xScale=2/(leftTan+rightTan),yScale=2/(upTan+downTan);return out[0]=xScale,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=yScale,out[6]=0,out[7]=0,out[8]=-((leftTan-rightTan)*xScale*.5),out[9]=(upTan-downTan)*yScale*.5,out[10]=far/(near3-far),out[11]=-1,out[12]=0,out[13]=0,out[14]=far*near3/(near3-far),out[15]=0,out}function orthoNO(out,left,right,bottom,top,near3,far){var lr3=1/(left-right),bt5=1/(bottom-top),nf3=1/(near3-far);return out[0]=-2*lr3,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=-2*bt5,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[10]=2*nf3,out[11]=0,out[12]=(left+right)*lr3,out[13]=(top+bottom)*bt5,out[14]=(far+near3)*nf3,out[15]=1,out}function orthoZO(out,left,right,bottom,top,near3,far){var lr3=1/(left-right),bt5=1/(bottom-top),nf3=1/(near3-far);return out[0]=-2*lr3,out[1]=0,out[2]=0,out[3]=0,out[4]=0,out[5]=-2*bt5,out[6]=0,out[7]=0,out[8]=0,out[9]=0,out[10]=nf3,out[11]=0,out[12]=(left+right)*lr3,out[13]=(top+bottom)*bt5,out[14]=near3*nf3,out[15]=1,out}function lookAt(out,eye,center2,up4){var x03,x12,x22,y03,y12,y22,z03,z12,z22,len6,eyex=eye[0],eyey=eye[1],eyez=eye[2],upx=up4[0],upy=up4[1],upz=up4[2],centerx=center2[0],centery=center2[1],centerz=center2[2];return Math.abs(eyex-centerx)<EPSILON&&Math.abs(eyey-centery)<EPSILON&&Math.abs(eyez-centerz)<EPSILON?identity5(out):(z03=eyex-centerx,z12=eyey-centery,z22=eyez-centerz,len6=1/Math.sqrt(z03*z03+z12*z12+z22*z22),z03*=len6,z12*=len6,z22*=len6,x03=upy*z22-upz*z12,x12=upz*z03-upx*z22,x22=upx*z12-upy*z03,len6=Math.sqrt(x03*x03+x12*x12+x22*x22),len6?(len6=1/len6,x03*=len6,x12*=len6,x22*=len6):(x03=0,x12=0,x22=0),y03=z12*x22-z22*x12,y12=z22*x03-z03*x22,y22=z03*x12-z12*x03,len6=Math.sqrt(y03*y03+y12*y12+y22*y22),len6?(len6=1/len6,y03*=len6,y12*=len6,y22*=len6):(y03=0,y12=0,y22=0),out[0]=x03,out[1]=y03,out[2]=z03,out[3]=0,out[4]=x12,out[5]=y12,out[6]=z12,out[7]=0,out[8]=x22,out[9]=y22,out[10]=z22,out[11]=0,out[12]=-(x03*eyex+x12*eyey+x22*eyez),out[13]=-(y03*eyex+y12*eyey+y22*eyez),out[14]=-(z03*eyex+z12*eyey+z22*eyez),out[15]=1,out)}function targetTo(out,eye,target,up4){var eyex=eye[0],eyey=eye[1],eyez=eye[2],upx=up4[0],upy=up4[1],upz=up4[2],z03=eyex-target[0],z12=eyey-target[1],z22=eyez-target[2],len6=z03*z03+z12*z12+z22*z22;len6>0&&(len6=1/Math.sqrt(len6),z03*=len6,z12*=len6,z22*=len6);var x03=upy*z22-upz*z12,x12=upz*z03-upx*z22,x22=upx*z12-upy*z03;return len6=x03*x03+x12*x12+x22*x22,len6>0&&(len6=1/Math.sqrt(len6),x03*=len6,x12*=len6,x22*=len6),out[0]=x03,out[1]=x12,out[2]=x22,out[3]=0,out[4]=z12*x22-z22*x12,out[5]=z22*x03-z03*x22,out[6]=z03*x12-z12*x03,out[7]=0,out[8]=z03,out[9]=z12,out[10]=z22,out[11]=0,out[12]=eyex,out[13]=eyey,out[14]=eyez,out[15]=1,out}function str4(a10){return"mat4("+a10[0]+", "+a10[1]+", "+a10[2]+", "+a10[3]+", "+a10[4]+", "+a10[5]+", "+a10[6]+", "+a10[7]+", "+a10[8]+", "+a10[9]+", "+a10[10]+", "+a10[11]+", "+a10[12]+", "+a10[13]+", "+a10[14]+", "+a10[15]+")"}function frob4(a10){return Math.sqrt(a10[0]*a10[0]+a10[1]*a10[1]+a10[2]*a10[2]+a10[3]*a10[3]+a10[4]*a10[4]+a10[5]*a10[5]+a10[6]*a10[6]+a10[7]*a10[7]+a10[8]*a10[8]+a10[9]*a10[9]+a10[10]*a10[10]+a10[11]*a10[11]+a10[12]*a10[12]+a10[13]*a10[13]+a10[14]*a10[14]+a10[15]*a10[15])}function add4(out,a10,b10){return out[0]=a10[0]+b10[0],out[1]=a10[1]+b10[1],out[2]=a10[2]+b10[2],out[3]=a10[3]+b10[3],out[4]=a10[4]+b10[4],out[5]=a10[5]+b10[5],out[6]=a10[6]+b10[6],out[7]=a10[7]+b10[7],out[8]=a10[8]+b10[8],out[9]=a10[9]+b10[9],out[10]=a10[10]+b10[10],out[11]=a10[11]+b10[11],out[12]=a10[12]+b10[12],out[13]=a10[13]+b10[13],out[14]=a10[14]+b10[14],out[15]=a10[15]+b10[15],out}function subtract5(out,a10,b10){return out[0]=a10[0]-b10[0],out[1]=a10[1]-b10[1],out[2]=a10[2]-b10[2],out[3]=a10[3]-b10[3],out[4]=a10[4]-b10[4],out[5]=a10[5]-b10[5],out[6]=a10[6]-b10[6],out[7]=a10[7]-b10[7],out[8]=a10[8]-b10[8],out[9]=a10[9]-b10[9],out[10]=a10[10]-b10[10],out[11]=a10[11]-b10[11],out[12]=a10[12]-b10[12],out[13]=a10[13]-b10[13],out[14]=a10[14]-b10[14],out[15]=a10[15]-b10[15],out}function multiplyScalar4(out,a10,b10){return out[0]=a10[0]*b10,out[1]=a10[1]*b10,out[2]=a10[2]*b10,out[3]=a10[3]*b10,out[4]=a10[4]*b10,out[5]=a10[5]*b10,out[6]=a10[6]*b10,out[7]=a10[7]*b10,out[8]=a10[8]*b10,out[9]=a10[9]*b10,out[10]=a10[10]*b10,out[11]=a10[11]*b10,out[12]=a10[12]*b10,out[13]=a10[13]*b10,out[14]=a10[14]*b10,out[15]=a10[15]*b10,out}function multiplyScalarAndAdd4(out,a10,b10,scale15){return out[0]=a10[0]+b10[0]*scale15,out[1]=a10[1]+b10[1]*scale15,out[2]=a10[2]+b10[2]*scale15,out[3]=a10[3]+b10[3]*scale15,out[4]=a10[4]+b10[4]*scale15,out[5]=a10[5]+b10[5]*scale15,out[6]=a10[6]+b10[6]*scale15,out[7]=a10[7]+b10[7]*scale15,out[8]=a10[8]+b10[8]*scale15,out[9]=a10[9]+b10[9]*scale15,out[10]=a10[10]+b10[10]*scale15,out[11]=a10[11]+b10[11]*scale15,out[12]=a10[12]+b10[12]*scale15,out[13]=a10[13]+b10[13]*scale15,out[14]=a10[14]+b10[14]*scale15,out[15]=a10[15]+b10[15]*scale15,out}function exactEquals4(a10,b10){return a10[0]===b10[0]&&a10[1]===b10[1]&&a10[2]===b10[2]&&a10[3]===b10[3]&&a10[4]===b10[4]&&a10[5]===b10[5]&&a10[6]===b10[6]&&a10[7]===b10[7]&&a10[8]===b10[8]&&a10[9]===b10[9]&&a10[10]===b10[10]&&a10[11]===b10[11]&&a10[12]===b10[12]&&a10[13]===b10[13]&&a10[14]===b10[14]&&a10[15]===b10[15]}function equals5(a10,b10){var a03=a10[0],a12=a10[1],a22=a10[2],a32=a10[3],a42=a10[4],a52=a10[5],a62=a10[6],a72=a10[7],a82=a10[8],a93=a10[9],a102=a10[10],a11=a10[11],a122=a10[12],a13=a10[13],a14=a10[14],a15=a10[15],b03=b10[0],b12=b10[1],b22=b10[2],b32=b10[3],b43=b10[4],b52=b10[5],b62=b10[6],b72=b10[7],b82=b10[8],b93=b10[9],b102=b10[10],b11=b10[11],b122=b10[12],b13=b10[13],b14=b10[14],b15=b10[15];return Math.abs(a03-b03)<=EPSILON*Math.max(1,Math.abs(a03),Math.abs(b03))&&Math.abs(a12-b12)<=EPSILON*Math.max(1,Math.abs(a12),Math.abs(b12))&&Math.abs(a22-b22)<=EPSILON*Math.max(1,Math.abs(a22),Math.abs(b22))&&Math.abs(a32-b32)<=EPSILON*Math.max(1,Math.abs(a32),Math.abs(b32))&&Math.abs(a42-b43)<=EPSILON*Math.max(1,Math.abs(a42),Math.abs(b43))&&Math.abs(a52-b52)<=EPSILON*Math.max(1,Math.abs(a52),Math.abs(b52))&&Math.abs(a62-b62)<=EPSILON*Math.max(1,Math.abs(a62),Math.abs(b62))&&Math.abs(a72-b72)<=EPSILON*Math.max(1,Math.abs(a72),Math.abs(b72))&&Math.abs(a82-b82)<=EPSILON*Math.max(1,Math.abs(a82),Math.abs(b82))&&Math.abs(a93-b93)<=EPSILON*Math.max(1,Math.abs(a93),Math.abs(b93))&&Math.abs(a102-b102)<=EPSILON*Math.max(1,Math.abs(a102),Math.abs(b102))&&Math.abs(a11-b11)<=EPSILON*Math.max(1,Math.abs(a11),Math.abs(b11))&&Math.abs(a122-b122)<=EPSILON*Math.max(1,Math.abs(a122),Math.abs(b122))&&Math.abs(a13-b13)<=EPSILON*Math.max(1,Math.abs(a13),Math.abs(b13))&&Math.abs(a14-b14)<=EPSILON*Math.max(1,Math.abs(a14),Math.abs(b14))&&Math.abs(a15-b15)<=EPSILON*Math.max(1,Math.abs(a15),Math.abs(b15))}var perspective,ortho,mul4,sub4,init_mat4=__esm({"node_modules/gl-matrix/esm/mat4.js"(){"use strict";init_common();perspective=perspectiveNO;ortho=orthoNO;mul4=multiply4,sub4=subtract5}});var vec3_exports={};__export(vec3_exports,{add:()=>add5,angle:()=>angle,bezier:()=>bezier,ceil:()=>ceil,clone:()=>clone5,copy:()=>copy5,create:()=>create5,cross:()=>cross,dist:()=>dist,distance:()=>distance5,div:()=>div,divide:()=>divide,dot:()=>dot,equals:()=>equals6,exactEquals:()=>exactEquals5,floor:()=>floor,forEach:()=>forEach,fromValues:()=>fromValues6,hermite:()=>hermite,inverse:()=>inverse3,len:()=>len,length:()=>length3,lerp:()=>lerp,max:()=>max,min:()=>min,mul:()=>mul5,multiply:()=>multiply5,negate:()=>negate,normalize:()=>normalize,random:()=>random,rotateX:()=>rotateX2,rotateY:()=>rotateY2,rotateZ:()=>rotateZ2,round:()=>round2,scale:()=>scale7,scaleAndAdd:()=>scaleAndAdd,set:()=>set5,slerp:()=>slerp,sqrDist:()=>sqrDist,sqrLen:()=>sqrLen,squaredDistance:()=>squaredDistance,squaredLength:()=>squaredLength,str:()=>str5,sub:()=>sub5,subtract:()=>subtract6,transformMat3:()=>transformMat3,transformMat4:()=>transformMat4,transformQuat:()=>transformQuat,zero:()=>zero});function create5(){var out=new ARRAY_TYPE(3);return ARRAY_TYPE!=Float32Array&&(out[0]=0,out[1]=0,out[2]=0),out}function clone5(a10){var out=new ARRAY_TYPE(3);return out[0]=a10[0],out[1]=a10[1],out[2]=a10[2],out}function length3(a10){var x11=a10[0],y11=a10[1],z10=a10[2];return Math.sqrt(x11*x11+y11*y11+z10*z10)}function fromValues6(x11,y11,z10){var out=new ARRAY_TYPE(3);return out[0]=x11,out[1]=y11,out[2]=z10,out}function copy5(out,a10){return out[0]=a10[0],out[1]=a10[1],out[2]=a10[2],out}function set5(out,x11,y11,z10){return out[0]=x11,out[1]=y11,out[2]=z10,out}function add5(out,a10,b10){return out[0]=a10[0]+b10[0],out[1]=a10[1]+b10[1],out[2]=a10[2]+b10[2],out}function subtract6(out,a10,b10){return out[0]=a10[0]-b10[0],out[1]=a10[1]-b10[1],out[2]=a10[2]-b10[2],out}function multiply5(out,a10,b10){return out[0]=a10[0]*b10[0],out[1]=a10[1]*b10[1],out[2]=a10[2]*b10[2],out}function divide(out,a10,b10){return out[0]=a10[0]/b10[0],out[1]=a10[1]/b10[1],out[2]=a10[2]/b10[2],out}function ceil(out,a10){return out[0]=Math.ceil(a10[0]),out[1]=Math.ceil(a10[1]),out[2]=Math.ceil(a10[2]),out}function floor(out,a10){return out[0]=Math.floor(a10[0]),out[1]=Math.floor(a10[1]),out[2]=Math.floor(a10[2]),out}function min(out,a10,b10){return out[0]=Math.min(a10[0],b10[0]),out[1]=Math.min(a10[1],b10[1]),out[2]=Math.min(a10[2],b10[2]),out}function max(out,a10,b10){return out[0]=Math.max(a10[0],b10[0]),out[1]=Math.max(a10[1],b10[1]),out[2]=Math.max(a10[2],b10[2]),out}function round2(out,a10){return out[0]=round(a10[0]),out[1]=round(a10[1]),out[2]=round(a10[2]),out}function scale7(out,a10,b10){return out[0]=a10[0]*b10,out[1]=a10[1]*b10,out[2]=a10[2]*b10,out}function scaleAndAdd(out,a10,b10,scale15){return out[0]=a10[0]+b10[0]*scale15,out[1]=a10[1]+b10[1]*scale15,out[2]=a10[2]+b10[2]*scale15,out}function distance5(a10,b10){var x11=b10[0]-a10[0],y11=b10[1]-a10[1],z10=b10[2]-a10[2];return Math.sqrt(x11*x11+y11*y11+z10*z10)}function squaredDistance(a10,b10){var x11=b10[0]-a10[0],y11=b10[1]-a10[1],z10=b10[2]-a10[2];return x11*x11+y11*y11+z10*z10}function squaredLength(a10){var x11=a10[0],y11=a10[1],z10=a10[2];return x11*x11+y11*y11+z10*z10}function negate(out,a10){return out[0]=-a10[0],out[1]=-a10[1],out[2]=-a10[2],out}function inverse3(out,a10){return out[0]=1/a10[0],out[1]=1/a10[1],out[2]=1/a10[2],out}function normalize(out,a10){var x11=a10[0],y11=a10[1],z10=a10[2],len6=x11*x11+y11*y11+z10*z10;return len6>0&&(len6=1/Math.sqrt(len6)),out[0]=a10[0]*len6,out[1]=a10[1]*len6,out[2]=a10[2]*len6,out}function dot(a10,b10){return a10[0]*b10[0]+a10[1]*b10[1]+a10[2]*b10[2]}function cross(out,a10,b10){var ax4=a10[0],ay4=a10[1],az2=a10[2],bx4=b10[0],by4=b10[1],bz2=b10[2];return out[0]=ay4*bz2-az2*by4,out[1]=az2*bx4-ax4*bz2,out[2]=ax4*by4-ay4*bx4,out}function lerp(out,a10,b10,t48){var ax4=a10[0],ay4=a10[1],az2=a10[2];return out[0]=ax4+t48*(b10[0]-ax4),out[1]=ay4+t48*(b10[1]-ay4),out[2]=az2+t48*(b10[2]-az2),out}function slerp(out,a10,b10,t48){var angle3=Math.acos(Math.min(Math.max(dot(a10,b10),-1),1)),sinTotal=Math.sin(angle3),ratioA=Math.sin((1-t48)*angle3)/sinTotal,ratioB=Math.sin(t48*angle3)/sinTotal;return out[0]=ratioA*a10[0]+ratioB*b10[0],out[1]=ratioA*a10[1]+ratioB*b10[1],out[2]=ratioA*a10[2]+ratioB*b10[2],out}function hermite(out,a10,b10,c10,d11,t48){var factorTimes2=t48*t48,factor1=factorTimes2*(2*t48-3)+1,factor2=factorTimes2*(t48-2)+t48,factor3=factorTimes2*(t48-1),factor4=factorTimes2*(3-2*t48);return out[0]=a10[0]*factor1+b10[0]*factor2+c10[0]*factor3+d11[0]*factor4,out[1]=a10[1]*factor1+b10[1]*factor2+c10[1]*factor3+d11[1]*factor4,out[2]=a10[2]*factor1+b10[2]*factor2+c10[2]*factor3+d11[2]*factor4,out}function bezier(out,a10,b10,c10,d11,t48){var inverseFactor=1-t48,inverseFactorTimesTwo=inverseFactor*inverseFactor,factorTimes2=t48*t48,factor1=inverseFactorTimesTwo*inverseFactor,factor2=3*t48*inverseFactorTimesTwo,factor3=3*factorTimes2*inverseFactor,factor4=factorTimes2*t48;return out[0]=a10[0]*factor1+b10[0]*factor2+c10[0]*factor3+d11[0]*factor4,out[1]=a10[1]*factor1+b10[1]*factor2+c10[1]*factor3+d11[1]*factor4,out[2]=a10[2]*factor1+b10[2]*factor2+c10[2]*factor3+d11[2]*factor4,out}function random(out,scale15){scale15=scale15===void 0?1:scale15;var r11=RANDOM()*2*Math.PI,z10=RANDOM()*2-1,zScale=Math.sqrt(1-z10*z10)*scale15;return out[0]=Math.cos(r11)*zScale,out[1]=Math.sin(r11)*zScale,out[2]=z10*scale15,out}function transformMat4(out,a10,m5){var x11=a10[0],y11=a10[1],z10=a10[2],w10=m5[3]*x11+m5[7]*y11+m5[11]*z10+m5[15];return w10=w10||1,out[0]=(m5[0]*x11+m5[4]*y11+m5[8]*z10+m5[12])/w10,out[1]=(m5[1]*x11+m5[5]*y11+m5[9]*z10+m5[13])/w10,out[2]=(m5[2]*x11+m5[6]*y11+m5[10]*z10+m5[14])/w10,out}function transformMat3(out,a10,m5){var x11=a10[0],y11=a10[1],z10=a10[2];return out[0]=x11*m5[0]+y11*m5[3]+z10*m5[6],out[1]=x11*m5[1]+y11*m5[4]+z10*m5[7],out[2]=x11*m5[2]+y11*m5[5]+z10*m5[8],out}function transformQuat(out,a10,q11){var qx4=q11[0],qy4=q11[1],qz2=q11[2],qw3=q11[3],vx4=a10[0],vy4=a10[1],vz2=a10[2],tx4=qy4*vz2-qz2*vy4,ty4=qz2*vx4-qx4*vz2,tz2=qx4*vy4-qy4*vx4;return tx4=tx4+tx4,ty4=ty4+ty4,tz2=tz2+tz2,out[0]=vx4+qw3*tx4+qy4*tz2-qz2*ty4,out[1]=vy4+qw3*ty4+qz2*tx4-qx4*tz2,out[2]=vz2+qw3*tz2+qx4*ty4-qy4*tx4,out}function rotateX2(out,a10,b10,rad){var p11=[],r11=[];return p11[0]=a10[0]-b10[0],p11[1]=a10[1]-b10[1],p11[2]=a10[2]-b10[2],r11[0]=p11[0],r11[1]=p11[1]*Math.cos(rad)-p11[2]*Math.sin(rad),r11[2]=p11[1]*Math.sin(rad)+p11[2]*Math.cos(rad),out[0]=r11[0]+b10[0],out[1]=r11[1]+b10[1],out[2]=r11[2]+b10[2],out}function rotateY2(out,a10,b10,rad){var p11=[],r11=[];return p11[0]=a10[0]-b10[0],p11[1]=a10[1]-b10[1],p11[2]=a10[2]-b10[2],r11[0]=p11[2]*Math.sin(rad)+p11[0]*Math.cos(rad),r11[1]=p11[1],r11[2]=p11[2]*Math.cos(rad)-p11[0]*Math.sin(rad),out[0]=r11[0]+b10[0],out[1]=r11[1]+b10[1],out[2]=r11[2]+b10[2],out}function rotateZ2(out,a10,b10,rad){var p11=[],r11=[];return p11[0]=a10[0]-b10[0],p11[1]=a10[1]-b10[1],p11[2]=a10[2]-b10[2],r11[0]=p11[0]*Math.cos(rad)-p11[1]*Math.sin(rad),r11[1]=p11[0]*Math.sin(rad)+p11[1]*Math.cos(rad),r11[2]=p11[2],out[0]=r11[0]+b10[0],out[1]=r11[1]+b10[1],out[2]=r11[2]+b10[2],out}function angle(a10,b10){var ax4=a10[0],ay4=a10[1],az2=a10[2],bx4=b10[0],by4=b10[1],bz2=b10[2],mag=Math.sqrt((ax4*ax4+ay4*ay4+az2*az2)*(bx4*bx4+by4*by4+bz2*bz2)),cosine=mag&&dot(a10,b10)/mag;return Math.acos(Math.min(Math.max(cosine,-1),1))}function zero(out){return out[0]=0,out[1]=0,out[2]=0,out}function str5(a10){return"vec3("+a10[0]+", "+a10[1]+", "+a10[2]+")"}function exactEquals5(a10,b10){return a10[0]===b10[0]&&a10[1]===b10[1]&&a10[2]===b10[2]}function equals6(a10,b10){var a03=a10[0],a12=a10[1],a22=a10[2],b03=b10[0],b12=b10[1],b22=b10[2];return Math.abs(a03-b03)<=EPSILON*Math.max(1,Math.abs(a03),Math.abs(b03))&&Math.abs(a12-b12)<=EPSILON*Math.max(1,Math.abs(a12),Math.abs(b12))&&Math.abs(a22-b22)<=EPSILON*Math.max(1,Math.abs(a22),Math.abs(b22))}var sub5,mul5,div,dist,sqrDist,len,sqrLen,forEach,init_vec3=__esm({"node_modules/gl-matrix/esm/vec3.js"(){"use strict";init_common();sub5=subtract6,mul5=multiply5,div=divide,dist=distance5,sqrDist=squaredDistance,len=length3,sqrLen=squaredLength,forEach=(function(){var vec=create5();return function(a10,stride,offset2,count,fn3,arg){var i11,l10;for(stride||(stride=3),offset2||(offset2=0),count?l10=Math.min(count*stride+offset2,a10.length):l10=a10.length,i11=offset2;i11<l10;i11+=stride)vec[0]=a10[i11],vec[1]=a10[i11+1],vec[2]=a10[i11+2],fn3(vec,vec,arg),a10[i11]=vec[0],a10[i11+1]=vec[1],a10[i11+2]=vec[2];return a10}})()}});var vec4_exports={};__export(vec4_exports,{add:()=>add6,ceil:()=>ceil2,clone:()=>clone6,copy:()=>copy6,create:()=>create6,cross:()=>cross2,dist:()=>dist2,distance:()=>distance6,div:()=>div2,divide:()=>divide2,dot:()=>dot2,equals:()=>equals7,exactEquals:()=>exactEquals6,floor:()=>floor2,forEach:()=>forEach2,fromValues:()=>fromValues7,inverse:()=>inverse4,len:()=>len2,length:()=>length4,lerp:()=>lerp2,max:()=>max2,min:()=>min2,mul:()=>mul6,multiply:()=>multiply6,negate:()=>negate2,normalize:()=>normalize2,random:()=>random2,round:()=>round3,scale:()=>scale8,scaleAndAdd:()=>scaleAndAdd2,set:()=>set6,sqrDist:()=>sqrDist2,sqrLen:()=>sqrLen2,squaredDistance:()=>squaredDistance2,squaredLength:()=>squaredLength2,str:()=>str6,sub:()=>sub6,subtract:()=>subtract7,transformMat4:()=>transformMat42,transformQuat:()=>transformQuat2,zero:()=>zero2});function create6(){var out=new ARRAY_TYPE(4);return ARRAY_TYPE!=Float32Array&&(out[0]=0,out[1]=0,out[2]=0,out[3]=0),out}function clone6(a10){var out=new ARRAY_TYPE(4);return out[0]=a10[0],out[1]=a10[1],out[2]=a10[2],out[3]=a10[3],out}function fromValues7(x11,y11,z10,w10){var out=new ARRAY_TYPE(4);return out[0]=x11,out[1]=y11,out[2]=z10,out[3]=w10,out}function copy6(out,a10){return out[0]=a10[0],out[1]=a10[1],out[2]=a10[2],out[3]=a10[3],out}function set6(out,x11,y11,z10,w10){return out[0]=x11,out[1]=y11,out[2]=z10,out[3]=w10,out}function add6(out,a10,b10){return out[0]=a10[0]+b10[0],out[1]=a10[1]+b10[1],out[2]=a10[2]+b10[2],out[3]=a10[3]+b10[3],out}function subtract7(out,a10,b10){return out[0]=a10[0]-b10[0],out[1]=a10[1]-b10[1],out[2]=a10[2]-b10[2],out[3]=a10[3]-b10[3],out}function multiply6(out,a10,b10){return out[0]=a10[0]*b10[0],out[1]=a10[1]*b10[1],out[2]=a10[2]*b10[2],out[3]=a10[3]*b10[3],out}function divide2(out,a10,b10){return out[0]=a10[0]/b10[0],out[1]=a10[1]/b10[1],out[2]=a10[2]/b10[2],out[3]=a10[3]/b10[3],out}function ceil2(out,a10){return out[0]=Math.ceil(a10[0]),out[1]=Math.ceil(a10[1]),out[2]=Math.ceil(a10[2]),out[3]=Math.ceil(a10[3]),out}function floor2(out,a10){return out[0]=Math.floor(a10[0]),out[1]=Math.floor(a10[1]),out[2]=Math.floor(a10[2]),out[3]=Math.floor(a10[3]),out}function min2(out,a10,b10){return out[0]=Math.min(a10[0],b10[0]),out[1]=Math.min(a10[1],b10[1]),out[2]=Math.min(a10[2],b10[2]),out[3]=Math.min(a10[3],b10[3]),out}function max2(out,a10,b10){return out[0]=Math.max(a10[0],b10[0]),out[1]=Math.max(a10[1],b10[1]),out[2]=Math.max(a10[2],b10[2]),out[3]=Math.max(a10[3],b10[3]),out}function round3(out,a10){return out[0]=round(a10[0]),out[1]=round(a10[1]),out[2]=round(a10[2]),out[3]=round(a10[3]),out}function scale8(out,a10,b10){return out[0]=a10[0]*b10,out[1]=a10[1]*b10,out[2]=a10[2]*b10,out[3]=a10[3]*b10,out}function scaleAndAdd2(out,a10,b10,scale15){return out[0]=a10[0]+b10[0]*scale15,out[1]=a10[1]+b10[1]*scale15,out[2]=a10[2]+b10[2]*scale15,out[3]=a10[3]+b10[3]*scale15,out}function distance6(a10,b10){var x11=b10[0]-a10[0],y11=b10[1]-a10[1],z10=b10[2]-a10[2],w10=b10[3]-a10[3];return Math.sqrt(x11*x11+y11*y11+z10*z10+w10*w10)}function squaredDistance2(a10,b10){var x11=b10[0]-a10[0],y11=b10[1]-a10[1],z10=b10[2]-a10[2],w10=b10[3]-a10[3];return x11*x11+y11*y11+z10*z10+w10*w10}function length4(a10){var x11=a10[0],y11=a10[1],z10=a10[2],w10=a10[3];return Math.sqrt(x11*x11+y11*y11+z10*z10+w10*w10)}function squaredLength2(a10){var x11=a10[0],y11=a10[1],z10=a10[2],w10=a10[3];return x11*x11+y11*y11+z10*z10+w10*w10}function negate2(out,a10){return out[0]=-a10[0],out[1]=-a10[1],out[2]=-a10[2],out[3]=-a10[3],out}function inverse4(out,a10){return out[0]=1/a10[0],out[1]=1/a10[1],out[2]=1/a10[2],out[3]=1/a10[3],out}function normalize2(out,a10){var x11=a10[0],y11=a10[1],z10=a10[2],w10=a10[3],len6=x11*x11+y11*y11+z10*z10+w10*w10;return len6>0&&(len6=1/Math.sqrt(len6)),out[0]=x11*len6,out[1]=y11*len6,out[2]=z10*len6,out[3]=w10*len6,out}function dot2(a10,b10){return a10[0]*b10[0]+a10[1]*b10[1]+a10[2]*b10[2]+a10[3]*b10[3]}function cross2(out,u5,v11,w10){var A10=v11[0]*w10[1]-v11[1]*w10[0],B11=v11[0]*w10[2]-v11[2]*w10[0],C11=v11[0]*w10[3]-v11[3]*w10[0],D11=v11[1]*w10[2]-v11[2]*w10[1],E11=v11[1]*w10[3]-v11[3]*w10[1],F11=v11[2]*w10[3]-v11[3]*w10[2],G11=u5[0],H11=u5[1],I11=u5[2],J11=u5[3];return out[0]=H11*F11-I11*E11+J11*D11,out[1]=-(G11*F11)+I11*C11-J11*B11,out[2]=G11*E11-H11*C11+J11*A10,out[3]=-(G11*D11)+H11*B11-I11*A10,out}function lerp2(out,a10,b10,t48){var ax4=a10[0],ay4=a10[1],az2=a10[2],aw3=a10[3];return out[0]=ax4+t48*(b10[0]-ax4),out[1]=ay4+t48*(b10[1]-ay4),out[2]=az2+t48*(b10[2]-az2),out[3]=aw3+t48*(b10[3]-aw3),out}function random2(out,scale15){scale15=scale15===void 0?1:scale15;var v12,v22,v32,v43,s12,s22,rand;rand=RANDOM(),v12=rand*2-1,v22=(4*RANDOM()-2)*Math.sqrt(rand*-rand+rand),s12=v12*v12+v22*v22,rand=RANDOM(),v32=rand*2-1,v43=(4*RANDOM()-2)*Math.sqrt(rand*-rand+rand),s22=v32*v32+v43*v43;var d11=Math.sqrt((1-s12)/s22);return out[0]=scale15*v12,out[1]=scale15*v22,out[2]=scale15*v32*d11,out[3]=scale15*v43*d11,out}function transformMat42(out,a10,m5){var x11=a10[0],y11=a10[1],z10=a10[2],w10=a10[3];return out[0]=m5[0]*x11+m5[4]*y11+m5[8]*z10+m5[12]*w10,out[1]=m5[1]*x11+m5[5]*y11+m5[9]*z10+m5[13]*w10,out[2]=m5[2]*x11+m5[6]*y11+m5[10]*z10+m5[14]*w10,out[3]=m5[3]*x11+m5[7]*y11+m5[11]*z10+m5[15]*w10,out}function transformQuat2(out,a10,q11){var qx4=q11[0],qy4=q11[1],qz2=q11[2],qw3=q11[3],vx4=a10[0],vy4=a10[1],vz2=a10[2],tx4=qy4*vz2-qz2*vy4,ty4=qz2*vx4-qx4*vz2,tz2=qx4*vy4-qy4*vx4;return tx4=tx4+tx4,ty4=ty4+ty4,tz2=tz2+tz2,out[0]=vx4+qw3*tx4+qy4*tz2-qz2*ty4,out[1]=vy4+qw3*ty4+qz2*tx4-qx4*tz2,out[2]=vz2+qw3*tz2+qx4*ty4-qy4*tx4,out[3]=a10[3],out}function zero2(out){return out[0]=0,out[1]=0,out[2]=0,out[3]=0,out}function str6(a10){return"vec4("+a10[0]+", "+a10[1]+", "+a10[2]+", "+a10[3]+")"}function exactEquals6(a10,b10){return a10[0]===b10[0]&&a10[1]===b10[1]&&a10[2]===b10[2]&&a10[3]===b10[3]}function equals7(a10,b10){var a03=a10[0],a12=a10[1],a22=a10[2],a32=a10[3],b03=b10[0],b12=b10[1],b22=b10[2],b32=b10[3];return Math.abs(a03-b03)<=EPSILON*Math.max(1,Math.abs(a03),Math.abs(b03))&&Math.abs(a12-b12)<=EPSILON*Math.max(1,Math.abs(a12),Math.abs(b12))&&Math.abs(a22-b22)<=EPSILON*Math.max(1,Math.abs(a22),Math.abs(b22))&&Math.abs(a32-b32)<=EPSILON*Math.max(1,Math.abs(a32),Math.abs(b32))}var sub6,mul6,div2,dist2,sqrDist2,len2,sqrLen2,forEach2,init_vec4=__esm({"node_modules/gl-matrix/esm/vec4.js"(){"use strict";init_common();sub6=subtract7,mul6=multiply6,div2=divide2,dist2=distance6,sqrDist2=squaredDistance2,len2=length4,sqrLen2=squaredLength2,forEach2=(function(){var vec=create6();return function(a10,stride,offset2,count,fn3,arg){var i11,l10;for(stride||(stride=4),offset2||(offset2=0),count?l10=Math.min(count*stride+offset2,a10.length):l10=a10.length,i11=offset2;i11<l10;i11+=stride)vec[0]=a10[i11],vec[1]=a10[i11+1],vec[2]=a10[i11+2],vec[3]=a10[i11+3],fn3(vec,vec,arg),a10[i11]=vec[0],a10[i11+1]=vec[1],a10[i11+2]=vec[2],a10[i11+3]=vec[3];return a10}})()}});var quat_exports={};__export(quat_exports,{add:()=>add7,calculateW:()=>calculateW,clone:()=>clone7,conjugate:()=>conjugate,copy:()=>copy7,create:()=>create7,dot:()=>dot3,equals:()=>equals8,exactEquals:()=>exactEquals7,exp:()=>exp,fromEuler:()=>fromEuler,fromMat3:()=>fromMat3,fromValues:()=>fromValues8,getAngle:()=>getAngle,getAxisAngle:()=>getAxisAngle,identity:()=>identity6,invert:()=>invert5,len:()=>len3,length:()=>length5,lerp:()=>lerp3,ln:()=>ln2,mul:()=>mul7,multiply:()=>multiply7,normalize:()=>normalize3,pow:()=>pow,random:()=>random3,rotateX:()=>rotateX3,rotateY:()=>rotateY3,rotateZ:()=>rotateZ3,rotationTo:()=>rotationTo,scale:()=>scale9,set:()=>set7,setAxes:()=>setAxes,setAxisAngle:()=>setAxisAngle,slerp:()=>slerp2,sqlerp:()=>sqlerp,sqrLen:()=>sqrLen3,squaredLength:()=>squaredLength3,str:()=>str7});function create7(){var out=new ARRAY_TYPE(4);return ARRAY_TYPE!=Float32Array&&(out[0]=0,out[1]=0,out[2]=0),out[3]=1,out}function identity6(out){return out[0]=0,out[1]=0,out[2]=0,out[3]=1,out}function setAxisAngle(out,axis,rad){rad=rad*.5;var s11=Math.sin(rad);return out[0]=s11*axis[0],out[1]=s11*axis[1],out[2]=s11*axis[2],out[3]=Math.cos(rad),out}function getAxisAngle(out_axis,q11){var rad=Math.acos(q11[3])*2,s11=Math.sin(rad/2);return s11>EPSILON?(out_axis[0]=q11[0]/s11,out_axis[1]=q11[1]/s11,out_axis[2]=q11[2]/s11):(out_axis[0]=1,out_axis[1]=0,out_axis[2]=0),rad}function getAngle(a10,b10){var dotproduct=dot3(a10,b10);return Math.acos(2*dotproduct*dotproduct-1)}function multiply7(out,a10,b10){var ax4=a10[0],ay4=a10[1],az2=a10[2],aw3=a10[3],bx4=b10[0],by4=b10[1],bz2=b10[2],bw4=b10[3];return out[0]=ax4*bw4+aw3*bx4+ay4*bz2-az2*by4,out[1]=ay4*bw4+aw3*by4+az2*bx4-ax4*bz2,out[2]=az2*bw4+aw3*bz2+ax4*by4-ay4*bx4,out[3]=aw3*bw4-ax4*bx4-ay4*by4-az2*bz2,out}function rotateX3(out,a10,rad){rad*=.5;var ax4=a10[0],ay4=a10[1],az2=a10[2],aw3=a10[3],bx4=Math.sin(rad),bw4=Math.cos(rad);return out[0]=ax4*bw4+aw3*bx4,out[1]=ay4*bw4+az2*bx4,out[2]=az2*bw4-ay4*bx4,out[3]=aw3*bw4-ax4*bx4,out}function rotateY3(out,a10,rad){rad*=.5;var ax4=a10[0],ay4=a10[1],az2=a10[2],aw3=a10[3],by4=Math.sin(rad),bw4=Math.cos(rad);return out[0]=ax4*bw4-az2*by4,out[1]=ay4*bw4+aw3*by4,out[2]=az2*bw4+ax4*by4,out[3]=aw3*bw4-ay4*by4,out}function rotateZ3(out,a10,rad){rad*=.5;var ax4=a10[0],ay4=a10[1],az2=a10[2],aw3=a10[3],bz2=Math.sin(rad),bw4=Math.cos(rad);return out[0]=ax4*bw4+ay4*bz2,out[1]=ay4*bw4-ax4*bz2,out[2]=az2*bw4+aw3*bz2,out[3]=aw3*bw4-az2*bz2,out}function calculateW(out,a10){var x11=a10[0],y11=a10[1],z10=a10[2];return out[0]=x11,out[1]=y11,out[2]=z10,out[3]=Math.sqrt(Math.abs(1-x11*x11-y11*y11-z10*z10)),out}function exp(out,a10){var x11=a10[0],y11=a10[1],z10=a10[2],w10=a10[3],r11=Math.sqrt(x11*x11+y11*y11+z10*z10),et5=Math.exp(w10),s11=r11>0?et5*Math.sin(r11)/r11:0;return out[0]=x11*s11,out[1]=y11*s11,out[2]=z10*s11,out[3]=et5*Math.cos(r11),out}function ln2(out,a10){var x11=a10[0],y11=a10[1],z10=a10[2],w10=a10[3],r11=Math.sqrt(x11*x11+y11*y11+z10*z10),t48=r11>0?Math.atan2(r11,w10)/r11:0;return out[0]=x11*t48,out[1]=y11*t48,out[2]=z10*t48,out[3]=.5*Math.log(x11*x11+y11*y11+z10*z10+w10*w10),out}function pow(out,a10,b10){return ln2(out,a10),scale9(out,out,b10),exp(out,out),out}function slerp2(out,a10,b10,t48){var ax4=a10[0],ay4=a10[1],az2=a10[2],aw3=a10[3],bx4=b10[0],by4=b10[1],bz2=b10[2],bw4=b10[3],omega,cosom,sinom,scale0,scale1;return cosom=ax4*bx4+ay4*by4+az2*bz2+aw3*bw4,cosom<0&&(cosom=-cosom,bx4=-bx4,by4=-by4,bz2=-bz2,bw4=-bw4),1-cosom>EPSILON?(omega=Math.acos(cosom),sinom=Math.sin(omega),scale0=Math.sin((1-t48)*omega)/sinom,scale1=Math.sin(t48*omega)/sinom):(scale0=1-t48,scale1=t48),out[0]=scale0*ax4+scale1*bx4,out[1]=scale0*ay4+scale1*by4,out[2]=scale0*az2+scale1*bz2,out[3]=scale0*aw3+scale1*bw4,out}function random3(out){var u12=RANDOM(),u22=RANDOM(),u32=RANDOM(),sqrt1MinusU1=Math.sqrt(1-u12),sqrtU1=Math.sqrt(u12);return out[0]=sqrt1MinusU1*Math.sin(2*Math.PI*u22),out[1]=sqrt1MinusU1*Math.cos(2*Math.PI*u22),out[2]=sqrtU1*Math.sin(2*Math.PI*u32),out[3]=sqrtU1*Math.cos(2*Math.PI*u32),out}function invert5(out,a10){var a03=a10[0],a12=a10[1],a22=a10[2],a32=a10[3],dot10=a03*a03+a12*a12+a22*a22+a32*a32,invDot=dot10?1/dot10:0;return out[0]=-a03*invDot,out[1]=-a12*invDot,out[2]=-a22*invDot,out[3]=a32*invDot,out}function conjugate(out,a10){return out[0]=-a10[0],out[1]=-a10[1],out[2]=-a10[2],out[3]=a10[3],out}function fromMat3(out,m5){var fTrace=m5[0]+m5[4]+m5[8],fRoot;if(fTrace>0)fRoot=Math.sqrt(fTrace+1),out[3]=.5*fRoot,fRoot=.5/fRoot,out[0]=(m5[5]-m5[7])*fRoot,out[1]=(m5[6]-m5[2])*fRoot,out[2]=(m5[1]-m5[3])*fRoot;else{var i11=0;m5[4]>m5[0]&&(i11=1),m5[8]>m5[i11*3+i11]&&(i11=2);var j11=(i11+1)%3,k11=(i11+2)%3;fRoot=Math.sqrt(m5[i11*3+i11]-m5[j11*3+j11]-m5[k11*3+k11]+1),out[i11]=.5*fRoot,fRoot=.5/fRoot,out[3]=(m5[j11*3+k11]-m5[k11*3+j11])*fRoot,out[j11]=(m5[j11*3+i11]+m5[i11*3+j11])*fRoot,out[k11]=(m5[k11*3+i11]+m5[i11*3+k11])*fRoot}return out}function fromEuler(out,x11,y11,z10){var order=arguments.length>4&&arguments[4]!==void 0?arguments[4]:ANGLE_ORDER,halfToRad=Math.PI/360;x11*=halfToRad,z10*=halfToRad,y11*=halfToRad;var sx4=Math.sin(x11),cx4=Math.cos(x11),sy4=Math.sin(y11),cy4=Math.cos(y11),sz2=Math.sin(z10),cz2=Math.cos(z10);switch(order){case"xyz":out[0]=sx4*cy4*cz2+cx4*sy4*sz2,out[1]=cx4*sy4*cz2-sx4*cy4*sz2,out[2]=cx4*cy4*sz2+sx4*sy4*cz2,out[3]=cx4*cy4*cz2-sx4*sy4*sz2;break;case"xzy":out[0]=sx4*cy4*cz2-cx4*sy4*sz2,out[1]=cx4*sy4*cz2-sx4*cy4*sz2,out[2]=cx4*cy4*sz2+sx4*sy4*cz2,out[3]=cx4*cy4*cz2+sx4*sy4*sz2;break;case"yxz":out[0]=sx4*cy4*cz2+cx4*sy4*sz2,out[1]=cx4*sy4*cz2-sx4*cy4*sz2,out[2]=cx4*cy4*sz2-sx4*sy4*cz2,out[3]=cx4*cy4*cz2+sx4*sy4*sz2;break;case"yzx":out[0]=sx4*cy4*cz2+cx4*sy4*sz2,out[1]=cx4*sy4*cz2+sx4*cy4*sz2,out[2]=cx4*cy4*sz2-sx4*sy4*cz2,out[3]=cx4*cy4*cz2-sx4*sy4*sz2;break;case"zxy":out[0]=sx4*cy4*cz2-cx4*sy4*sz2,out[1]=cx4*sy4*cz2+sx4*cy4*sz2,out[2]=cx4*cy4*sz2+sx4*sy4*cz2,out[3]=cx4*cy4*cz2-sx4*sy4*sz2;break;case"zyx":out[0]=sx4*cy4*cz2-cx4*sy4*sz2,out[1]=cx4*sy4*cz2+sx4*cy4*sz2,out[2]=cx4*cy4*sz2-sx4*sy4*cz2,out[3]=cx4*cy4*cz2+sx4*sy4*sz2;break;default:throw new Error("Unknown angle order "+order)}return out}function str7(a10){return"quat("+a10[0]+", "+a10[1]+", "+a10[2]+", "+a10[3]+")"}function equals8(a10,b10){return Math.abs(dot2(a10,b10))>=1-EPSILON}var clone7,fromValues8,copy7,set7,add7,mul7,scale9,dot3,lerp3,length5,len3,squaredLength3,sqrLen3,normalize3,exactEquals7,rotationTo,sqlerp,setAxes,init_quat=__esm({"node_modules/gl-matrix/esm/quat.js"(){"use strict";init_common();init_mat3();init_vec3();init_vec4();clone7=clone6,fromValues8=fromValues7,copy7=copy6,set7=set6,add7=add6,mul7=multiply7,scale9=scale8,dot3=dot2,lerp3=lerp2,length5=length4,len3=length5,squaredLength3=squaredLength2,sqrLen3=squaredLength3,normalize3=normalize2,exactEquals7=exactEquals6;rotationTo=(function(){var tmpvec3=create5(),xUnitVec3=fromValues6(1,0,0),yUnitVec3=fromValues6(0,1,0);return function(out,a10,b10){var dot10=dot(a10,b10);return dot10<-.999999?(cross(tmpvec3,xUnitVec3,a10),len(tmpvec3)<1e-6&&cross(tmpvec3,yUnitVec3,a10),normalize(tmpvec3,tmpvec3),setAxisAngle(out,tmpvec3,Math.PI),out):dot10>.999999?(out[0]=0,out[1]=0,out[2]=0,out[3]=1,out):(cross(tmpvec3,a10,b10),out[0]=tmpvec3[0],out[1]=tmpvec3[1],out[2]=tmpvec3[2],out[3]=1+dot10,normalize3(out,out))}})(),sqlerp=(function(){var temp1=create7(),temp2=create7();return function(out,a10,b10,c10,d11,t48){return slerp2(temp1,a10,d11,t48),slerp2(temp2,b10,c10,t48),slerp2(out,temp1,temp2,2*t48*(1-t48)),out}})(),setAxes=(function(){var matr=create3();return function(out,view,right,up4){return matr[0]=right[0],matr[3]=right[1],matr[6]=right[2],matr[1]=up4[0],matr[4]=up4[1],matr[7]=up4[2],matr[2]=-view[0],matr[5]=-view[1],matr[8]=-view[2],normalize3(out,fromMat3(out,matr))}})()}});var quat2_exports={};__export(quat2_exports,{add:()=>add8,clone:()=>clone8,conjugate:()=>conjugate2,copy:()=>copy8,create:()=>create8,dot:()=>dot4,equals:()=>equals9,exactEquals:()=>exactEquals8,fromMat4:()=>fromMat42,fromRotation:()=>fromRotation5,fromRotationTranslation:()=>fromRotationTranslation2,fromRotationTranslationValues:()=>fromRotationTranslationValues,fromTranslation:()=>fromTranslation4,fromValues:()=>fromValues9,getDual:()=>getDual,getReal:()=>getReal,getTranslation:()=>getTranslation2,identity:()=>identity7,invert:()=>invert6,len:()=>len4,length:()=>length6,lerp:()=>lerp4,mul:()=>mul8,multiply:()=>multiply8,normalize:()=>normalize4,rotateAroundAxis:()=>rotateAroundAxis,rotateByQuatAppend:()=>rotateByQuatAppend,rotateByQuatPrepend:()=>rotateByQuatPrepend,rotateX:()=>rotateX4,rotateY:()=>rotateY4,rotateZ:()=>rotateZ4,scale:()=>scale10,set:()=>set8,setDual:()=>setDual,setReal:()=>setReal,sqrLen:()=>sqrLen4,squaredLength:()=>squaredLength4,str:()=>str8,translate:()=>translate6});function create8(){var dq2=new ARRAY_TYPE(8);return ARRAY_TYPE!=Float32Array&&(dq2[0]=0,dq2[1]=0,dq2[2]=0,dq2[4]=0,dq2[5]=0,dq2[6]=0,dq2[7]=0),dq2[3]=1,dq2}function clone8(a10){var dq2=new ARRAY_TYPE(8);return dq2[0]=a10[0],dq2[1]=a10[1],dq2[2]=a10[2],dq2[3]=a10[3],dq2[4]=a10[4],dq2[5]=a10[5],dq2[6]=a10[6],dq2[7]=a10[7],dq2}function fromValues9(x12,y12,z12,w12,x22,y22,z22,w22){var dq2=new ARRAY_TYPE(8);return dq2[0]=x12,dq2[1]=y12,dq2[2]=z12,dq2[3]=w12,dq2[4]=x22,dq2[5]=y22,dq2[6]=z22,dq2[7]=w22,dq2}function fromRotationTranslationValues(x12,y12,z12,w12,x22,y22,z22){var dq2=new ARRAY_TYPE(8);dq2[0]=x12,dq2[1]=y12,dq2[2]=z12,dq2[3]=w12;var ax4=x22*.5,ay4=y22*.5,az2=z22*.5;return dq2[4]=ax4*w12+ay4*z12-az2*y12,dq2[5]=ay4*w12+az2*x12-ax4*z12,dq2[6]=az2*w12+ax4*y12-ay4*x12,dq2[7]=-ax4*x12-ay4*y12-az2*z12,dq2}function fromRotationTranslation2(out,q11,t48){var ax4=t48[0]*.5,ay4=t48[1]*.5,az2=t48[2]*.5,bx4=q11[0],by4=q11[1],bz2=q11[2],bw4=q11[3];return out[0]=bx4,out[1]=by4,out[2]=bz2,out[3]=bw4,out[4]=ax4*bw4+ay4*bz2-az2*by4,out[5]=ay4*bw4+az2*bx4-ax4*bz2,out[6]=az2*bw4+ax4*by4-ay4*bx4,out[7]=-ax4*bx4-ay4*by4-az2*bz2,out}function fromTranslation4(out,t48){return out[0]=0,out[1]=0,out[2]=0,out[3]=1,out[4]=t48[0]*.5,out[5]=t48[1]*.5,out[6]=t48[2]*.5,out[7]=0,out}function fromRotation5(out,q11){return out[0]=q11[0],out[1]=q11[1],out[2]=q11[2],out[3]=q11[3],out[4]=0,out[5]=0,out[6]=0,out[7]=0,out}function fromMat42(out,a10){var outer=create7();getRotation(outer,a10);var t48=new ARRAY_TYPE(3);return getTranslation(t48,a10),fromRotationTranslation2(out,outer,t48),out}function copy8(out,a10){return out[0]=a10[0],out[1]=a10[1],out[2]=a10[2],out[3]=a10[3],out[4]=a10[4],out[5]=a10[5],out[6]=a10[6],out[7]=a10[7],out}function identity7(out){return out[0]=0,out[1]=0,out[2]=0,out[3]=1,out[4]=0,out[5]=0,out[6]=0,out[7]=0,out}function set8(out,x12,y12,z12,w12,x22,y22,z22,w22){return out[0]=x12,out[1]=y12,out[2]=z12,out[3]=w12,out[4]=x22,out[5]=y22,out[6]=z22,out[7]=w22,out}function getDual(out,a10){return out[0]=a10[4],out[1]=a10[5],out[2]=a10[6],out[3]=a10[7],out}function setDual(out,q11){return out[4]=q11[0],out[5]=q11[1],out[6]=q11[2],out[7]=q11[3],out}function getTranslation2(out,a10){var ax4=a10[4],ay4=a10[5],az2=a10[6],aw3=a10[7],bx4=-a10[0],by4=-a10[1],bz2=-a10[2],bw4=a10[3];return out[0]=(ax4*bw4+aw3*bx4+ay4*bz2-az2*by4)*2,out[1]=(ay4*bw4+aw3*by4+az2*bx4-ax4*bz2)*2,out[2]=(az2*bw4+aw3*bz2+ax4*by4-ay4*bx4)*2,out}function translate6(out,a10,v11){var ax1=a10[0],ay1=a10[1],az1=a10[2],aw1=a10[3],bx1=v11[0]*.5,by1=v11[1]*.5,bz1=v11[2]*.5,ax22=a10[4],ay22=a10[5],az2=a10[6],aw22=a10[7];return out[0]=ax1,out[1]=ay1,out[2]=az1,out[3]=aw1,out[4]=aw1*bx1+ay1*bz1-az1*by1+ax22,out[5]=aw1*by1+az1*bx1-ax1*bz1+ay22,out[6]=aw1*bz1+ax1*by1-ay1*bx1+az2,out[7]=-ax1*bx1-ay1*by1-az1*bz1+aw22,out}function rotateX4(out,a10,rad){var bx4=-a10[0],by4=-a10[1],bz2=-a10[2],bw4=a10[3],ax4=a10[4],ay4=a10[5],az2=a10[6],aw3=a10[7],ax1=ax4*bw4+aw3*bx4+ay4*bz2-az2*by4,ay1=ay4*bw4+aw3*by4+az2*bx4-ax4*bz2,az1=az2*bw4+aw3*bz2+ax4*by4-ay4*bx4,aw1=aw3*bw4-ax4*bx4-ay4*by4-az2*bz2;return rotateX3(out,a10,rad),bx4=out[0],by4=out[1],bz2=out[2],bw4=out[3],out[4]=ax1*bw4+aw1*bx4+ay1*bz2-az1*by4,out[5]=ay1*bw4+aw1*by4+az1*bx4-ax1*bz2,out[6]=az1*bw4+aw1*bz2+ax1*by4-ay1*bx4,out[7]=aw1*bw4-ax1*bx4-ay1*by4-az1*bz2,out}function rotateY4(out,a10,rad){var bx4=-a10[0],by4=-a10[1],bz2=-a10[2],bw4=a10[3],ax4=a10[4],ay4=a10[5],az2=a10[6],aw3=a10[7],ax1=ax4*bw4+aw3*bx4+ay4*bz2-az2*by4,ay1=ay4*bw4+aw3*by4+az2*bx4-ax4*bz2,az1=az2*bw4+aw3*bz2+ax4*by4-ay4*bx4,aw1=aw3*bw4-ax4*bx4-ay4*by4-az2*bz2;return rotateY3(out,a10,rad),bx4=out[0],by4=out[1],bz2=out[2],bw4=out[3],out[4]=ax1*bw4+aw1*bx4+ay1*bz2-az1*by4,out[5]=ay1*bw4+aw1*by4+az1*bx4-ax1*bz2,out[6]=az1*bw4+aw1*bz2+ax1*by4-ay1*bx4,out[7]=aw1*bw4-ax1*bx4-ay1*by4-az1*bz2,out}function rotateZ4(out,a10,rad){var bx4=-a10[0],by4=-a10[1],bz2=-a10[2],bw4=a10[3],ax4=a10[4],ay4=a10[5],az2=a10[6],aw3=a10[7],ax1=ax4*bw4+aw3*bx4+ay4*bz2-az2*by4,ay1=ay4*bw4+aw3*by4+az2*bx4-ax4*bz2,az1=az2*bw4+aw3*bz2+ax4*by4-ay4*bx4,aw1=aw3*bw4-ax4*bx4-ay4*by4-az2*bz2;return rotateZ3(out,a10,rad),bx4=out[0],by4=out[1],bz2=out[2],bw4=out[3],out[4]=ax1*bw4+aw1*bx4+ay1*bz2-az1*by4,out[5]=ay1*bw4+aw1*by4+az1*bx4-ax1*bz2,out[6]=az1*bw4+aw1*bz2+ax1*by4-ay1*bx4,out[7]=aw1*bw4-ax1*bx4-ay1*by4-az1*bz2,out}function rotateByQuatAppend(out,a10,q11){var qx4=q11[0],qy4=q11[1],qz2=q11[2],qw3=q11[3],ax4=a10[0],ay4=a10[1],az2=a10[2],aw3=a10[3];return out[0]=ax4*qw3+aw3*qx4+ay4*qz2-az2*qy4,out[1]=ay4*qw3+aw3*qy4+az2*qx4-ax4*qz2,out[2]=az2*qw3+aw3*qz2+ax4*qy4-ay4*qx4,out[3]=aw3*qw3-ax4*qx4-ay4*qy4-az2*qz2,ax4=a10[4],ay4=a10[5],az2=a10[6],aw3=a10[7],out[4]=ax4*qw3+aw3*qx4+ay4*qz2-az2*qy4,out[5]=ay4*qw3+aw3*qy4+az2*qx4-ax4*qz2,out[6]=az2*qw3+aw3*qz2+ax4*qy4-ay4*qx4,out[7]=aw3*qw3-ax4*qx4-ay4*qy4-az2*qz2,out}function rotateByQuatPrepend(out,q11,a10){var qx4=q11[0],qy4=q11[1],qz2=q11[2],qw3=q11[3],bx4=a10[0],by4=a10[1],bz2=a10[2],bw4=a10[3];return out[0]=qx4*bw4+qw3*bx4+qy4*bz2-qz2*by4,out[1]=qy4*bw4+qw3*by4+qz2*bx4-qx4*bz2,out[2]=qz2*bw4+qw3*bz2+qx4*by4-qy4*bx4,out[3]=qw3*bw4-qx4*bx4-qy4*by4-qz2*bz2,bx4=a10[4],by4=a10[5],bz2=a10[6],bw4=a10[7],out[4]=qx4*bw4+qw3*bx4+qy4*bz2-qz2*by4,out[5]=qy4*bw4+qw3*by4+qz2*bx4-qx4*bz2,out[6]=qz2*bw4+qw3*bz2+qx4*by4-qy4*bx4,out[7]=qw3*bw4-qx4*bx4-qy4*by4-qz2*bz2,out}function rotateAroundAxis(out,a10,axis,rad){if(Math.abs(rad)<EPSILON)return copy8(out,a10);var axisLength=Math.sqrt(axis[0]*axis[0]+axis[1]*axis[1]+axis[2]*axis[2]);rad=rad*.5;var s11=Math.sin(rad),bx4=s11*axis[0]/axisLength,by4=s11*axis[1]/axisLength,bz2=s11*axis[2]/axisLength,bw4=Math.cos(rad),ax1=a10[0],ay1=a10[1],az1=a10[2],aw1=a10[3];out[0]=ax1*bw4+aw1*bx4+ay1*bz2-az1*by4,out[1]=ay1*bw4+aw1*by4+az1*bx4-ax1*bz2,out[2]=az1*bw4+aw1*bz2+ax1*by4-ay1*bx4,out[3]=aw1*bw4-ax1*bx4-ay1*by4-az1*bz2;var ax4=a10[4],ay4=a10[5],az2=a10[6],aw3=a10[7];return out[4]=ax4*bw4+aw3*bx4+ay4*bz2-az2*by4,out[5]=ay4*bw4+aw3*by4+az2*bx4-ax4*bz2,out[6]=az2*bw4+aw3*bz2+ax4*by4-ay4*bx4,out[7]=aw3*bw4-ax4*bx4-ay4*by4-az2*bz2,out}function add8(out,a10,b10){return out[0]=a10[0]+b10[0],out[1]=a10[1]+b10[1],out[2]=a10[2]+b10[2],out[3]=a10[3]+b10[3],out[4]=a10[4]+b10[4],out[5]=a10[5]+b10[5],out[6]=a10[6]+b10[6],out[7]=a10[7]+b10[7],out}function multiply8(out,a10,b10){var ax0=a10[0],ay0=a10[1],az0=a10[2],aw0=a10[3],bx1=b10[4],by1=b10[5],bz1=b10[6],bw1=b10[7],ax1=a10[4],ay1=a10[5],az1=a10[6],aw1=a10[7],bx0=b10[0],by0=b10[1],bz0=b10[2],bw0=b10[3];return out[0]=ax0*bw0+aw0*bx0+ay0*bz0-az0*by0,out[1]=ay0*bw0+aw0*by0+az0*bx0-ax0*bz0,out[2]=az0*bw0+aw0*bz0+ax0*by0-ay0*bx0,out[3]=aw0*bw0-ax0*bx0-ay0*by0-az0*bz0,out[4]=ax0*bw1+aw0*bx1+ay0*bz1-az0*by1+ax1*bw0+aw1*bx0+ay1*bz0-az1*by0,out[5]=ay0*bw1+aw0*by1+az0*bx1-ax0*bz1+ay1*bw0+aw1*by0+az1*bx0-ax1*bz0,out[6]=az0*bw1+aw0*bz1+ax0*by1-ay0*bx1+az1*bw0+aw1*bz0+ax1*by0-ay1*bx0,out[7]=aw0*bw1-ax0*bx1-ay0*by1-az0*bz1+aw1*bw0-ax1*bx0-ay1*by0-az1*bz0,out}function scale10(out,a10,b10){return out[0]=a10[0]*b10,out[1]=a10[1]*b10,out[2]=a10[2]*b10,out[3]=a10[3]*b10,out[4]=a10[4]*b10,out[5]=a10[5]*b10,out[6]=a10[6]*b10,out[7]=a10[7]*b10,out}function lerp4(out,a10,b10,t48){var mt5=1-t48;return dot4(a10,b10)<0&&(t48=-t48),out[0]=a10[0]*mt5+b10[0]*t48,out[1]=a10[1]*mt5+b10[1]*t48,out[2]=a10[2]*mt5+b10[2]*t48,out[3]=a10[3]*mt5+b10[3]*t48,out[4]=a10[4]*mt5+b10[4]*t48,out[5]=a10[5]*mt5+b10[5]*t48,out[6]=a10[6]*mt5+b10[6]*t48,out[7]=a10[7]*mt5+b10[7]*t48,out}function invert6(out,a10){var sqlen=squaredLength4(a10);return out[0]=-a10[0]/sqlen,out[1]=-a10[1]/sqlen,out[2]=-a10[2]/sqlen,out[3]=a10[3]/sqlen,out[4]=-a10[4]/sqlen,out[5]=-a10[5]/sqlen,out[6]=-a10[6]/sqlen,out[7]=a10[7]/sqlen,out}function conjugate2(out,a10){return out[0]=-a10[0],out[1]=-a10[1],out[2]=-a10[2],out[3]=a10[3],out[4]=-a10[4],out[5]=-a10[5],out[6]=-a10[6],out[7]=a10[7],out}function normalize4(out,a10){var magnitude=squaredLength4(a10);if(magnitude>0){magnitude=Math.sqrt(magnitude);var a03=a10[0]/magnitude,a12=a10[1]/magnitude,a22=a10[2]/magnitude,a32=a10[3]/magnitude,b03=a10[4],b12=a10[5],b22=a10[6],b32=a10[7],a_dot_b=a03*b03+a12*b12+a22*b22+a32*b32;out[0]=a03,out[1]=a12,out[2]=a22,out[3]=a32,out[4]=(b03-a03*a_dot_b)/magnitude,out[5]=(b12-a12*a_dot_b)/magnitude,out[6]=(b22-a22*a_dot_b)/magnitude,out[7]=(b32-a32*a_dot_b)/magnitude}return out}function str8(a10){return"quat2("+a10[0]+", "+a10[1]+", "+a10[2]+", "+a10[3]+", "+a10[4]+", "+a10[5]+", "+a10[6]+", "+a10[7]+")"}function exactEquals8(a10,b10){return a10[0]===b10[0]&&a10[1]===b10[1]&&a10[2]===b10[2]&&a10[3]===b10[3]&&a10[4]===b10[4]&&a10[5]===b10[5]&&a10[6]===b10[6]&&a10[7]===b10[7]}function equals9(a10,b10){var a03=a10[0],a12=a10[1],a22=a10[2],a32=a10[3],a42=a10[4],a52=a10[5],a62=a10[6],a72=a10[7],b03=b10[0],b12=b10[1],b22=b10[2],b32=b10[3],b43=b10[4],b52=b10[5],b62=b10[6],b72=b10[7];return Math.abs(a03-b03)<=EPSILON*Math.max(1,Math.abs(a03),Math.abs(b03))&&Math.abs(a12-b12)<=EPSILON*Math.max(1,Math.abs(a12),Math.abs(b12))&&Math.abs(a22-b22)<=EPSILON*Math.max(1,Math.abs(a22),Math.abs(b22))&&Math.abs(a32-b32)<=EPSILON*Math.max(1,Math.abs(a32),Math.abs(b32))&&Math.abs(a42-b43)<=EPSILON*Math.max(1,Math.abs(a42),Math.abs(b43))&&Math.abs(a52-b52)<=EPSILON*Math.max(1,Math.abs(a52),Math.abs(b52))&&Math.abs(a62-b62)<=EPSILON*Math.max(1,Math.abs(a62),Math.abs(b62))&&Math.abs(a72-b72)<=EPSILON*Math.max(1,Math.abs(a72),Math.abs(b72))}var getReal,setReal,mul8,dot4,length6,len4,squaredLength4,sqrLen4,init_quat2=__esm({"node_modules/gl-matrix/esm/quat2.js"(){"use strict";init_common();init_quat();init_mat4();getReal=copy7;setReal=copy7;mul8=multiply8;dot4=dot3;length6=length5,len4=length6,squaredLength4=squaredLength3,sqrLen4=squaredLength4}});var vec2_exports={};__export(vec2_exports,{add:()=>add9,angle:()=>angle2,ceil:()=>ceil3,clone:()=>clone9,copy:()=>copy9,create:()=>create9,cross:()=>cross3,dist:()=>dist3,distance:()=>distance7,div:()=>div3,divide:()=>divide3,dot:()=>dot5,equals:()=>equals10,exactEquals:()=>exactEquals9,floor:()=>floor3,forEach:()=>forEach3,fromValues:()=>fromValues10,inverse:()=>inverse5,len:()=>len5,length:()=>length7,lerp:()=>lerp5,max:()=>max3,min:()=>min3,mul:()=>mul9,multiply:()=>multiply9,negate:()=>negate3,normalize:()=>normalize5,random:()=>random4,rotate:()=>rotate7,round:()=>round4,scale:()=>scale11,scaleAndAdd:()=>scaleAndAdd3,set:()=>set9,signedAngle:()=>signedAngle,sqrDist:()=>sqrDist3,sqrLen:()=>sqrLen5,squaredDistance:()=>squaredDistance3,squaredLength:()=>squaredLength5,str:()=>str9,sub:()=>sub7,subtract:()=>subtract8,transformMat2:()=>transformMat2,transformMat2d:()=>transformMat2d,transformMat3:()=>transformMat32,transformMat4:()=>transformMat43,zero:()=>zero3});function create9(){var out=new ARRAY_TYPE(2);return ARRAY_TYPE!=Float32Array&&(out[0]=0,out[1]=0),out}function clone9(a10){var out=new ARRAY_TYPE(2);return out[0]=a10[0],out[1]=a10[1],out}function fromValues10(x11,y11){var out=new ARRAY_TYPE(2);return out[0]=x11,out[1]=y11,out}function copy9(out,a10){return out[0]=a10[0],out[1]=a10[1],out}function set9(out,x11,y11){return out[0]=x11,out[1]=y11,out}function add9(out,a10,b10){return out[0]=a10[0]+b10[0],out[1]=a10[1]+b10[1],out}function subtract8(out,a10,b10){return out[0]=a10[0]-b10[0],out[1]=a10[1]-b10[1],out}function multiply9(out,a10,b10){return out[0]=a10[0]*b10[0],out[1]=a10[1]*b10[1],out}function divide3(out,a10,b10){return out[0]=a10[0]/b10[0],out[1]=a10[1]/b10[1],out}function ceil3(out,a10){return out[0]=Math.ceil(a10[0]),out[1]=Math.ceil(a10[1]),out}function floor3(out,a10){return out[0]=Math.floor(a10[0]),out[1]=Math.floor(a10[1]),out}function min3(out,a10,b10){return out[0]=Math.min(a10[0],b10[0]),out[1]=Math.min(a10[1],b10[1]),out}function max3(out,a10,b10){return out[0]=Math.max(a10[0],b10[0]),out[1]=Math.max(a10[1],b10[1]),out}function round4(out,a10){return out[0]=round(a10[0]),out[1]=round(a10[1]),out}function scale11(out,a10,b10){return out[0]=a10[0]*b10,out[1]=a10[1]*b10,out}function scaleAndAdd3(out,a10,b10,scale15){return out[0]=a10[0]+b10[0]*scale15,out[1]=a10[1]+b10[1]*scale15,out}function distance7(a10,b10){var x11=b10[0]-a10[0],y11=b10[1]-a10[1];return Math.sqrt(x11*x11+y11*y11)}function squaredDistance3(a10,b10){var x11=b10[0]-a10[0],y11=b10[1]-a10[1];return x11*x11+y11*y11}function length7(a10){var x11=a10[0],y11=a10[1];return Math.sqrt(x11*x11+y11*y11)}function squaredLength5(a10){var x11=a10[0],y11=a10[1];return x11*x11+y11*y11}function negate3(out,a10){return out[0]=-a10[0],out[1]=-a10[1],out}function inverse5(out,a10){return out[0]=1/a10[0],out[1]=1/a10[1],out}function normalize5(out,a10){var x11=a10[0],y11=a10[1],len6=x11*x11+y11*y11;return len6>0&&(len6=1/Math.sqrt(len6)),out[0]=a10[0]*len6,out[1]=a10[1]*len6,out}function dot5(a10,b10){return a10[0]*b10[0]+a10[1]*b10[1]}function cross3(out,a10,b10){var z10=a10[0]*b10[1]-a10[1]*b10[0];return out[0]=out[1]=0,out[2]=z10,out}function lerp5(out,a10,b10,t48){var ax4=a10[0],ay4=a10[1];return out[0]=ax4+t48*(b10[0]-ax4),out[1]=ay4+t48*(b10[1]-ay4),out}function random4(out,scale15){scale15=scale15===void 0?1:scale15;var r11=RANDOM()*2*Math.PI;return out[0]=Math.cos(r11)*scale15,out[1]=Math.sin(r11)*scale15,out}function transformMat2(out,a10,m5){var x11=a10[0],y11=a10[1];return out[0]=m5[0]*x11+m5[2]*y11,out[1]=m5[1]*x11+m5[3]*y11,out}function transformMat2d(out,a10,m5){var x11=a10[0],y11=a10[1];return out[0]=m5[0]*x11+m5[2]*y11+m5[4],out[1]=m5[1]*x11+m5[3]*y11+m5[5],out}function transformMat32(out,a10,m5){var x11=a10[0],y11=a10[1];return out[0]=m5[0]*x11+m5[3]*y11+m5[6],out[1]=m5[1]*x11+m5[4]*y11+m5[7],out}function transformMat43(out,a10,m5){var x11=a10[0],y11=a10[1];return out[0]=m5[0]*x11+m5[4]*y11+m5[12],out[1]=m5[1]*x11+m5[5]*y11+m5[13],out}function rotate7(out,a10,b10,rad){var p03=a10[0]-b10[0],p12=a10[1]-b10[1],sinC=Math.sin(rad),cosC=Math.cos(rad);return out[0]=p03*cosC-p12*sinC+b10[0],out[1]=p03*sinC+p12*cosC+b10[1],out}function angle2(a10,b10){var ax4=a10[0],ay4=a10[1],bx4=b10[0],by4=b10[1];return Math.abs(Math.atan2(ay4*bx4-ax4*by4,ax4*bx4+ay4*by4))}function signedAngle(a10,b10){var ax4=a10[0],ay4=a10[1],bx4=b10[0],by4=b10[1];return Math.atan2(ax4*by4-ay4*bx4,ax4*bx4+ay4*by4)}function zero3(out){return out[0]=0,out[1]=0,out}function str9(a10){return"vec2("+a10[0]+", "+a10[1]+")"}function exactEquals9(a10,b10){return a10[0]===b10[0]&&a10[1]===b10[1]}function equals10(a10,b10){var a03=a10[0],a12=a10[1],b03=b10[0],b12=b10[1];return Math.abs(a03-b03)<=EPSILON*Math.max(1,Math.abs(a03),Math.abs(b03))&&Math.abs(a12-b12)<=EPSILON*Math.max(1,Math.abs(a12),Math.abs(b12))}var len5,sub7,mul9,div3,dist3,sqrDist3,sqrLen5,forEach3,init_vec2=__esm({"node_modules/gl-matrix/esm/vec2.js"(){"use strict";init_common();len5=length7,sub7=subtract8,mul9=multiply9,div3=divide3,dist3=distance7,sqrDist3=squaredDistance3,sqrLen5=squaredLength5,forEach3=(function(){var vec=create9();return function(a10,stride,offset2,count,fn3,arg){var i11,l10;for(stride||(stride=2),offset2||(offset2=0),count?l10=Math.min(count*stride+offset2,a10.length):l10=a10.length,i11=offset2;i11<l10;i11+=stride)vec[0]=a10[i11],vec[1]=a10[i11+1],fn3(vec,vec,arg),a10[i11]=vec[0],a10[i11+1]=vec[1];return a10}})()}});var esm_exports3={};__export(esm_exports3,{glMatrix:()=>common_exports,mat2:()=>mat2_exports,mat2d:()=>mat2d_exports,mat3:()=>mat3_exports,mat4:()=>mat4_exports,quat:()=>quat_exports,quat2:()=>quat2_exports,vec2:()=>vec2_exports,vec3:()=>vec3_exports,vec4:()=>vec4_exports});var init_esm=__esm({"node_modules/gl-matrix/esm/index.js"(){"use strict";init_common();init_mat2();init_mat2d();init_mat3();init_mat4();init_quat();init_quat2();init_vec2();init_vec3();init_vec4()}});var require_dist=__commonJS({"node_modules/jscad-planner/dist/index.cjs"(exports,module){"use strict";var __defProp6=Object.defineProperty,__getOwnPropDesc4=Object.getOwnPropertyDescriptor,__getOwnPropNames4=Object.getOwnPropertyNames,__hasOwnProp5=Object.prototype.hasOwnProperty,__export5=(target,all)=>{for(var name in all)__defProp6(target,name,{get:all[name],enumerable:!0})},__copyProps4=(to3,from,except,desc)=>{if(from&&typeof from=="object"||typeof from=="function")for(let key of __getOwnPropNames4(from))!__hasOwnProp5.call(to3,key)&&key!==except&&__defProp6(to3,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc4(from,key))||desc.enumerable});return to3},__toCommonJS2=mod=>__copyProps4(__defProp6({},"__esModule",{value:!0}),mod),index_exports={};__export5(index_exports,{assertTransformMatrix:()=>assertTransformMatrix,executeJscadOperations:()=>executeJscadOperations,jscadPlanner:()=>jscadPlanner2,resolveReferencePlanes:()=>resolveReferencePlanes3,toTransformMatrix:()=>toTransformMatrix});module.exports=__toCommonJS2(index_exports);var invalidTransformMatrixMessage="Transform matrix must be a column-major array of exactly 16 finite numbers";function assertTransformMatrix(matrix2){if(!Array.isArray(matrix2)||matrix2.length!==16||!Array.from(matrix2).every(Number.isFinite))throw new Error(invalidTransformMatrixMessage)}function toTransformMatrix(matrix2){if(matrix2==null||matrix2.length!==16)throw new Error(invalidTransformMatrixMessage);let copy10=Array.from(matrix2);return assertTransformMatrix(copy10),copy10}var jscadPlanner2={booleans:{intersect:(...shapes)=>({type:"intersect",shapes}),subtract:(...shapes)=>({type:"subtract",shapes}),union:(...shapes)=>({type:"union",shapes})},hulls:{hull:(...shapes)=>({type:"hull",shapes:shapes.flat()}),hullChain:(...shapes)=>({type:"hullChain",shapes:shapes.flat()})},colors:{colorize:(color3,shape21)=>({type:"colorize",color:color3,shape:shape21})},primitives:{rectangle:options=>({...options,type:"rectangle"}),cube:options=>({type:"cube",...options}),sphere:options=>({type:"sphere",...options}),cylinder:options=>({type:"cylinder",...options}),polygon:options=>({type:"polygon",...options}),cuboid:options=>({type:"cuboid",...options}),roundedCuboid:options=>({type:"roundedCuboid",...options})},transforms:{transform:(matrix2,shape21)=>(assertTransformMatrix(matrix2),{type:"transform",matrix:matrix2,shape:shape21}),rotate:(angles,shape21)=>({type:"rotate",angles,shape:shape21}),rotateX:(angle3,shape21)=>({type:"rotateX",angle:angle3,shape:shape21}),rotateY:(angle3,shape21)=>({type:"rotateY",angle:angle3,shape:shape21}),rotateZ:(angle3,shape21)=>({type:"rotateZ",angle:angle3,shape:shape21}),scale:(factors,shape21)=>({type:"scale",factors,shape:shape21}),translate:(vector3,shape21)=>({type:"translate",vector:vector3,shape:shape21})},extrusions:{extrudeLinear:(options,shape21)=>({type:"extrudeLinear",options,shape:shape21}),extrudeRotate:(options,shape21)=>({type:"extrudeRotate",options,shape:shape21})},maths:{vec2:{create:(x11,y11)=>[x11,y11],fromValues:(x11,y11)=>[x11,y11]},vec3:{create:(x11,y11,z10)=>[x11,y11,z10],fromValues:(x11,y11,z10)=>[x11,y11,z10]}},geometries:{geom2:{create:points=>({type:"createGeom2",points}),fromPoints:points=>({type:"fromPointsGeom2",points})},geom3:{create:polygons=>({type:"createGeom3",polygons})},path2:{create:points=>({type:"createPath2",points})}},measurements:{measureBoundingBox:shape21=>({type:"measureBoundingBox",shape:shape21}),measureArea:shape21=>({type:"measureArea",shape:shape21}),measureVolume:shape21=>({type:"measureVolume",shape:shape21})},utils:{degToRad:degrees3=>degrees3*Math.PI/180,radToDeg:radians3=>radians3*180/Math.PI}},import_gl_matrix9=(init_esm(),__toCommonJS(esm_exports3)),identity8=()=>toTransformMatrix(import_gl_matrix9.mat4.create());function transformMatrix(operation){let result=identity8();switch(operation.type){case"transform":return assertTransformMatrix(operation.matrix),[...operation.matrix];case"translate":return toTransformMatrix(import_gl_matrix9.mat4.fromTranslation(result,operation.vector));case"scale":return toTransformMatrix(import_gl_matrix9.mat4.fromScaling(result,operation.factors));case"rotate":return import_gl_matrix9.mat4.rotateZ(result,result,operation.angles[2]),import_gl_matrix9.mat4.rotateY(result,result,operation.angles[1]),import_gl_matrix9.mat4.rotateX(result,result,operation.angles[0]),result;case"rotateX":return toTransformMatrix(import_gl_matrix9.mat4.fromXRotation(result,operation.angle));case"rotateY":return toTransformMatrix(import_gl_matrix9.mat4.fromYRotation(result,operation.angle));case"rotateZ":return toTransformMatrix(import_gl_matrix9.mat4.fromZRotation(result,operation.angle));default:throw new Error(`Cannot use ${operation.type} as a reference transform`)}}function getReferencePlane(rectangle2,transforms){let name=rectangle2.name;if(!name?.trim())throw new Error("Reference rectangles require a nonblank name");let center2;if(rectangle2.type==="rectangle"){if(rectangle2.size.length!==2||!rectangle2.size.every(n10=>Number.isFinite(n10)&&n10>0))throw new Error(`Reference rectangle "${name}" requires two positive finite dimensions`);center2=rectangle2.center??[0,0]}else{let points=rectangle2.points;if(rectangle2.paths||points.length!==4||!points.every(p11=>p11.length===2&&p11.every(n10=>typeof n10=="number"&&Number.isFinite(n10))))throw new Error(`Reference polygon "${name}" must be an axis-aligned rectangle`);let corners=points,xs3=[...new Set(corners.map(p11=>p11[0]))],ys3=[...new Set(corners.map(p11=>p11[1]))];if(xs3.length!==2||ys3.length!==2||new Set(corners.map(p11=>JSON.stringify(p11))).size!==4)throw new Error(`Reference polygon "${name}" must be an axis-aligned rectangle`);center2=[(xs3[0]+xs3[1])/2,(ys3[0]+ys3[1])/2]}if(center2.length!==2||!center2.every(Number.isFinite))throw new Error(`Reference rectangle "${name}" has an invalid center`);let matrix2=identity8();for(let transform7 of transforms)import_gl_matrix9.mat4.multiply(matrix2,matrix2,transformMatrix(transform7));if(assertTransformMatrix(matrix2),matrix2[3]!==0||matrix2[7]!==0||matrix2[11]!==0||matrix2[15]!==1)throw new Error(`Reference rectangle "${name}" requires affine transforms`);let inverse8=import_gl_matrix9.mat4.invert(identity8(),matrix2);if(!inverse8)throw new Error(`Reference rectangle "${name}" has a singular transform`);let origin=[0,0,0];import_gl_matrix9.vec3.transformMat4(origin,[center2[0],center2[1],0],matrix2);let normal=[inverse8[2],inverse8[6],inverse8[10]],xAxis=[matrix2[0],matrix2[1],matrix2[2]];if(![...origin,...normal,...xAxis].every(Number.isFinite)||!import_gl_matrix9.vec3.length(normal)||!import_gl_matrix9.vec3.length(xAxis))throw new Error(`Reference rectangle "${name}" has an invalid frame`);return import_gl_matrix9.vec3.normalize(normal,normal),import_gl_matrix9.vec3.normalize(xAxis,xAxis),{name,origin,normal,xAxis}}function resolveReferencePlanes3(plan){let referencePlanes=[],names=new Set;function visit(operation,transforms,inProfile=!1){if(operation.reference){if(operation.type!=="rectangle"&&operation.type!=="polygon")throw new Error("Only rectangles can be reference geometry");if(inProfile)throw new Error("Reference rectangles must be outside extrusion and measurement inputs");let plane=getReferencePlane(operation,transforms);if(names.has(plane.name))throw new Error(`Duplicate reference plane "${plane.name}"`);names.add(plane.name),referencePlanes.push(plane);return}switch(operation.type){case"translate":case"rotate":case"rotateX":case"rotateY":case"rotateZ":case"scale":case"transform":{let shape21=visit(operation.shape,[...transforms,operation],inProfile);return shape21?{...operation,shape:shape21}:void 0}case"colorize":{let shape21=visit(operation.shape,transforms,inProfile);return shape21?{...operation,shape:shape21}:void 0}case"extrudeLinear":case"extrudeRotate":case"measureArea":case"measureVolume":case"measureBoundingBox":{let shape21=visit(operation.shape,transforms,!0);return shape21?{...operation,shape:shape21}:void 0}case"union":case"subtract":case"intersect":case"hull":case"hullChain":{let children=operation.shapes.map(shape21=>visit(shape21,transforms,inProfile));if(operation.type==="subtract"&&operation.shapes.length&&!children[0])throw new Error("A subtraction base cannot be reference geometry");let shapes=children.filter(shape21=>shape21!==void 0);return shapes.length?shapes.length===1?shapes[0]:{...operation,shapes}:void 0}default:return{...operation}}}let roots=(Array.isArray(plan)?plan:[plan]).map(operation=>visit(operation,[])).filter(operation=>operation!==void 0);return{geometry:roots.length>1?{type:"union",shapes:roots}:roots[0],referencePlanes}}var executeJscadOperations=(jscad2,operation)=>{if(Array.isArray(operation)&&operation.length===1)return executeJscadOperations(jscad2,operation[0]);if(Array.isArray(operation))throw new Error("executeJscadOperations currently doesn't support Array<JscadOperation>, try adding a root union or or executing each element individually");let{geometry}=resolveReferencePlanes3(operation);if(!geometry)throw new Error("JSCAD plan contains only reference geometry");return executeGeometry(jscad2,geometry)},executeGeometry=(jscad2,operation)=>{let recurse=op4=>executeGeometry(jscad2,op4),{type,...params}=operation;switch(type){case"rectangle":if(!jscad2.primitives.rectangle)throw new Error("JSCAD adapter does not support primitives.rectangle");return jscad2.primitives.rectangle({size:operation.size,center:operation.center??[0,0]});case"intersect":return jscad2.booleans.intersect(...operation.shapes.map(recurse));case"subtract":return jscad2.booleans.subtract(...operation.shapes.map(recurse));case"union":return jscad2.booleans.union(...operation.shapes.map(recurse));case"hull":return jscad2.hulls.hull(...operation.shapes.map(recurse));case"hullChain":return jscad2.hulls.hullChain(...operation.shapes.map(recurse));case"colorize":return jscad2.colors.colorize(operation.color,recurse(operation.shape));case"cube":return jscad2.primitives.cube(params);case"sphere":return jscad2.primitives.sphere(params);case"cylinder":return jscad2.primitives.cylinder(params);case"polygon":return jscad2.primitives.polygon(params);case"cuboid":return jscad2.primitives.cuboid(params);case"roundedCuboid":return jscad2.primitives.roundedCuboid(params);case"transform":if(assertTransformMatrix(operation.matrix),!jscad2.transforms.transform)throw new Error('Cannot execute "transform" operation: this JSCAD adapter does not support transforms.transform');return jscad2.transforms.transform(operation.matrix,recurse(operation.shape));case"rotate":return jscad2.transforms.rotate(operation.angles,recurse(operation.shape));case"rotateX":return jscad2.transforms.rotateX(operation.angle,recurse(operation.shape));case"rotateY":return jscad2.transforms.rotateY(operation.angle,recurse(operation.shape));case"rotateZ":return jscad2.transforms.rotateZ(operation.angle,recurse(operation.shape));case"scale":return jscad2.transforms.scale(operation.factors,recurse(operation.shape));case"translate":return jscad2.transforms.translate(operation.vector,recurse(operation.shape));case"extrudeLinear":return jscad2.extrusions.extrudeLinear(operation.options,recurse(operation.shape));case"extrudeRotate":return jscad2.extrusions.extrudeRotate(operation.options,recurse(operation.shape));case"createGeom2":return jscad2.geometries.geom2.create(operation.points);case"fromPointsGeom2":return jscad2.geometries.geom2.fromPoints(operation.points);case"createGeom3":return jscad2.geometries.geom3.create(operation.polygons);case"createPath2":return jscad2.geometries.path2.create(operation.points);case"measureBoundingBox":return jscad2.measurements.measureBoundingBox(recurse(operation.shape));case"measureArea":return jscad2.measurements.measureArea(recurse(operation.shape));case"measureVolume":return jscad2.measurements.measureVolume(recurse(operation.shape));case"degToRad":return jscad2.utils.degToRad(operation.degrees);case"radToDeg":return jscad2.utils.radToDeg(operation.radians);default:throw operation.type===void 0?new Error(`Operation type is undefined. This usually means the operation object is malformed or not properly initialized. Operation: ${JSON.stringify(operation,null,2).slice(0,200)}...`):new Error(`Unsupported operation type: ${operation.type}. Operation: ${JSON.stringify(operation,null,2)}`)}}}});function connect(map,a10,b10){if(!a10||!b10)return;let setA=map.get(a10);setA||(setA=new Set,map.set(a10,setA)),setA.add(b10);let setB=map.get(b10);setB||(setB=new Set,map.set(b10,setB)),setB.add(a10)}function buildSubtree(soup,opts){if(!opts.subcircuit_id&&!opts.source_group_id)return[...soup];let effectiveOpts=opts;if(opts.subcircuit_id){let subcircuitIds=new Set([opts.subcircuit_id]),groupChildren=new Map,groupSubcircuit=new Map;for(let elm of soup)if(elm.type==="source_group"){let groupId=elm.source_group_id,subcircuitId=elm.subcircuit_id;subcircuitId&&groupSubcircuit.set(groupId,subcircuitId);let parentId=elm.parent_source_group_id;parentId&&(groupChildren.has(parentId)||groupChildren.set(parentId,[]),groupChildren.get(parentId).push(groupId))}let rootGroupId;for(let[groupId,subcircuitId]of groupSubcircuit)if(subcircuitId===opts.subcircuit_id){rootGroupId=groupId;break}if(rootGroupId){let collectChildSubcircuits=groupId=>{let children=groupChildren.get(groupId)||[];for(let childId of children){let childSubcircuit=groupSubcircuit.get(childId);childSubcircuit&&subcircuitIds.add(childSubcircuit),collectChildSubcircuits(childId)}};collectChildSubcircuits(rootGroupId),effectiveOpts={...opts,subcircuit_ids:Array.from(subcircuitIds)}}}let idMap=new Map;for(let elm of soup){let idKey=`${elm.type}_id`,idVal=elm[idKey];typeof idVal=="string"&&idMap.set(idVal,elm)}let adj=new Map;for(let elm of soup){let entries=Object.entries(elm);for(let[key,val]of entries)if(key!=="parent_source_group_id"){if(key.endsWith("_id")&&typeof val=="string"){let other=idMap.get(val);connect(adj,elm,other)}else if(key.endsWith("_ids")&&Array.isArray(val)){for(let v11 of val)if(typeof v11=="string"){let other=idMap.get(v11);connect(adj,elm,other)}}}}let queue=[],included=new Set;for(let elm of soup){let shouldInclude=!1;(effectiveOpts.subcircuit_id&&"subcircuit_id"in elm&&elm.subcircuit_id===effectiveOpts.subcircuit_id||effectiveOpts.subcircuit_ids&&"subcircuit_id"in elm&&elm.subcircuit_id&&effectiveOpts.subcircuit_ids.includes(elm.subcircuit_id)||effectiveOpts.source_group_id&&"source_group_id"in elm&&elm.source_group_id===effectiveOpts.source_group_id||effectiveOpts.source_group_id&&"member_source_group_ids"in elm&&Array.isArray(elm.member_source_group_ids)&&elm.member_source_group_ids.includes(effectiveOpts.source_group_id))&&(shouldInclude=!0),shouldInclude&&(queue.push(elm),included.add(elm))}for(;queue.length>0;){let elm=queue.shift(),neighbors=adj.get(elm);if(neighbors)for(let n10 of neighbors)included.has(n10)||(included.add(n10),queue.push(n10))}return soup.filter(e55=>included.has(e55))}function createIdKey(element){let type=element.type;return`${type}:${element[`${type}_id`]}`}function getReadableNameForPcbSmtpad(soup,pcb_smtpad_id){let pcbSmtpad=cju(soup).pcb_smtpad.get(pcb_smtpad_id);return!pcbSmtpad||!pcbSmtpad.pcb_port_id?`smtpad[${pcb_smtpad_id}]`:getReadableNameForPcbPort(soup,pcbSmtpad.pcb_port_id)}function getReadableNameForPcbTrace(soup,pcb_trace_id){let pcbTrace=cju(soup).pcb_trace.get(pcb_trace_id);if(!pcbTrace)return`trace[${pcb_trace_id}]`;let connectedPcbPortIds=pcbTrace.route.flatMap(point7=>[point7.start_pcb_port_id,point7.end_pcb_port_id]).filter(Boolean);if(connectedPcbPortIds.length===0)return`trace[${pcb_trace_id}]`;function getComponentAndPortInfo(pcb_port_id){let pcbPort=cju(soup).pcb_port.get(pcb_port_id);if(!pcbPort)return null;let pcbComponent=pcbPort.pcb_component_id?cju(soup).pcb_component.get(pcbPort.pcb_component_id):void 0;if(!pcbComponent)return null;let sourceComponent=cju(soup).source_component.get(pcbComponent.source_component_id);if(!sourceComponent)return null;let sourcePort=cju(soup).source_port.get(pcbPort.source_port_id),portHint=sourcePort?.port_hints?sourcePort.port_hints[1]:"";return{componentName:sourceComponent.name,portHint}}return`trace[${connectedPcbPortIds.map(portId=>{let info=getComponentAndPortInfo(portId);return info?`.${info.componentName} > port.${info.portHint}`:`port[${portId}]`}).join(", ")}]`}function stringHash(str10){let hash=0;if(str10.length==0)return hash;for(var i11=0;i11<str10.length;i11++){var char=str10.charCodeAt(i11);hash=(hash<<5)-hash+char,hash=hash&hash}return Math.abs(hash)}function getMinimumFlexContainer(children,options={}){if(children.length===0)return{width:0,height:0};let direction3=options.direction??"row",columnGap=options.columnGap??0,rowGap=options.rowGap??0;if(direction3==="row"||direction3==="row-reverse"){let width=children.reduce((sum,c10)=>sum+c10.width,0)+columnGap*Math.max(0,children.length-1),height=children.reduce((max5,c10)=>Math.max(max5,c10.height),0);return{width,height}}else{let height=children.reduce((sum,c10)=>sum+c10.height,0)+rowGap*Math.max(0,children.length-1);return{width:children.reduce((max5,c10)=>Math.max(max5,c10.width),0),height}}}var cju,su3,cju_default,cjuIndexed,cju_indexed_default,rotateClockwise,rotateCounterClockwise,rotateDirection,oppositeSide,getQuarterTurns,insertionDirectionToVec,vecToInsertionDirection,transformInsertionDirection,transformSchematicElement,transformSchematicElements,transformPcbSoldermaskOpening,transformPCBElement,transformPCBElements,getElementId,getElementById2,getReadableNameForPcbPort,getReadableNameForElement,mergeBounds,getCircleBounds,getRotatedRectBounds,getRotatedOvalBounds,getRotatedPillBounds,getBoundsFromPoints3,getRoutePoints,getPcbElementBounds,getBoundsOfPcbElements,getBoardBounds,SCHEMATIC_TRACE_WIDTH,SCHEMATIC_NET_LABEL_FONT_SIZE,SCHEMATIC_NET_LABEL_HEIGHT,createBounds,getSchematicNetLabelTextWidth,getSchematicNetLabelBounds,getSchematicElementBounds,nice_color_palettes,getDebugLayoutObject,isTruthy,findBoundsAndCenter,getPrimaryId,repositionPcbComponentTo,findAllDescendantGroupIds,repositionPcbGroupTo,repositionSchematicComponentTo,findAllDescendantGroupIds2,repositionSchematicGroupTo,getCircuitJsonTree,EPSILON2,clamp3,distanceBetweenPoints,distanceBetweenPointAndSegment,cross4,isPointOnSegment2,segmentsIntersect,getPolygonEdges2,isPointInPolygon,distanceBetweenCircleAndCircle,distanceBetweenPolygonAndPolygon,distanceBetweenCircleAndPolygon,PIN1_LOCATION_PARTS,PIN1_LOCATIONS,getPadCenter2,getPinNumber,getCanonicalRowLocation,pinMatchesLocation2,analyzePcbPin1Location,placePolygon,ccw,circlePolygon,roundedRectangle,ringPolygon,subtractHole,getPourPolygon,getSmtPadPolygon,getViaPolygon,getPlatedHolePolygon,getTraceSegmentPolygon,copperPolygonsTouch,init_dist7=__esm({"node_modules/@tscircuit/circuit-json-util/dist/index.js"(){"use strict";init_dist2();init_dist2();init_src();init_parsel();init_src();init_src();init_src();init_src();init_main();init_src();cju=((circuitJsonInput,options={})=>{let circuitJson=circuitJsonInput,internalStore=circuitJson._internal_store;if(!internalStore){internalStore={counts:{},editCount:0},circuitJson._internal_store=internalStore;for(let elm of circuitJson){let type=elm.type,idVal=elm[`${type}_id`];if(!idVal)continue;let idNum=Number.parseInt(idVal.split("_").pop());Number.isNaN(idNum)||(internalStore.counts[type]=Math.max(internalStore.counts[type]??0,idNum))}}let su22=new Proxy({},{get:(proxy_target,prop)=>{if(prop==="toArray")return()=>(circuitJson.editCount=internalStore.editCount,circuitJson);if(prop==="editCount")return internalStore.editCount;if(prop==="subtree")return opts=>cju(buildSubtree(circuitJson,opts),options);if(prop==="insert")return elm=>{var _a543;let component_type2=elm.type;if(!component_type2)throw new Error("insert requires an element with a type");(_a543=internalStore.counts)[component_type2]??(_a543[component_type2]=-1),internalStore.counts[component_type2]++;let index2=internalStore.counts[component_type2],newElm={...elm,type:component_type2,[`${component_type2}_id`]:`${component_type2}_${index2}`};return options.validateInserts&&(dist_exports[component_type2]??any_soup_element).parse(newElm),circuitJson.push(newElm),internalStore.editCount++,newElm};if(prop==="insertAll")return elms=>elms.map(elm=>su22.insert(elm));let component_type=prop;return{get:id3=>circuitJson.find(e55=>e55.type===component_type&&e55[`${component_type}_id`]===id3),getUsing:using=>{let keys=Object.keys(using);if(keys.length!==1)throw new Error("getUsing requires exactly one key, e.g. { pcb_component_id }");let join_key=keys[0],join_type=join_key.replace("_id",""),joiner=circuitJson.find(e55=>e55.type===join_type&&e55[join_key]===using[join_key]);return joiner?circuitJson.find(e55=>e55.type===component_type&&e55[`${component_type}_id`]===joiner[`${component_type}_id`]):null},getWhere:where=>{let keys=Object.keys(where);return circuitJson.find(e55=>e55.type===component_type&&keys.every(key=>e55[key]===where[key]))},list:where=>{let keys=where?Object.keys(where):[];return circuitJson.filter(e55=>e55.type===component_type&&keys.every(key=>e55[key]===where[key]))},insert:elm=>{var _a543;(_a543=internalStore.counts)[component_type]??(_a543[component_type]=-1),internalStore.counts[component_type]++;let index2=internalStore.counts[component_type],newElm={type:component_type,[`${component_type}_id`]:`${component_type}_${index2}`,...elm};return options.validateInserts&&(dist_exports[component_type]??any_soup_element).parse(newElm),circuitJson.push(newElm),internalStore.editCount++,newElm},delete:id3=>{let elm=circuitJson.find(e55=>e55[`${component_type}_id`]===id3);elm&&(circuitJson.splice(circuitJson.indexOf(elm),1),internalStore.editCount++)},update:(id3,newProps)=>{let elm=circuitJson.find(e55=>e55.type===component_type&&e55[`${component_type}_id`]===id3);return elm?(Object.assign(elm,newProps),internalStore.editCount++,elm):null},select:selector2=>{if(component_type==="source_component")return circuitJson.find(e55=>e55.type==="source_component"&&e55.name===selector2.replace(/\./g,""));if(component_type==="pcb_port"||component_type==="source_port"||component_type==="schematic_port"){let[component_name,port_selector]=selector2.replace(/\./g,"").split(/[\s\>]+/),source_component=circuitJson.find(e55=>e55.type==="source_component"&&e55.name===component_name);if(!source_component)return null;let source_port3=circuitJson.find(e55=>e55.type==="source_port"&&e55.source_component_id===source_component.source_component_id&&(e55.name===port_selector||(e55.port_hints??[]).includes(port_selector)));if(!source_port3)return null;if(component_type==="source_port")return source_port3;if(component_type==="pcb_port")return circuitJson.find(e55=>e55.type==="pcb_port"&&e55.source_port_id===source_port3.source_port_id);if(component_type==="schematic_port")return circuitJson.find(e55=>e55.type==="schematic_port"&&e55.source_port_id===source_port3.source_port_id)}}}}});return su22});cju.unparsed=cju;su3=cju,cju_default=cju;cjuIndexed=((soup,options={})=>{let internalStore=soup._internal_store_indexed;if(!internalStore){internalStore={counts:{},editCount:0,indexes:{}};for(let elm of soup){let type=elm.type,idVal=elm[`${type}_id`];if(!idVal)continue;let idNum=Number.parseInt(idVal.split("_").pop()||"");Number.isNaN(idNum)||(internalStore.counts[type]=Math.max(internalStore.counts[type]??0,idNum))}let indexConfig=options.indexConfig||{},indexes=internalStore.indexes;if(indexConfig.byId&&(indexes.byId=new Map),indexConfig.byType&&(indexes.byType=new Map),indexConfig.byRelation&&(indexes.byRelation=new Map),indexConfig.bySubcircuit&&(indexes.bySubcircuit=new Map),indexConfig.byCustomField&&indexConfig.byCustomField.length>0){indexes.byCustomField=new Map;for(let field of indexConfig.byCustomField)indexes.byCustomField.set(field,new Map)}for(let element of soup){if(indexConfig.byId){let idKey=createIdKey(element);indexes.byId.set(idKey,element)}if(indexConfig.byType){let elementsOfType=indexes.byType.get(element.type)||[];elementsOfType.push(element),indexes.byType.set(element.type,elementsOfType)}if(indexConfig.byRelation){let elementEntries=Object.entries(element);for(let[key,value]of elementEntries)if(key.endsWith("_id")&&key!==`${element.type}_id`&&typeof value=="string"){let relationTypeMap=indexes.byRelation.get(key)||new Map,relatedElements=relationTypeMap.get(value)||[];relatedElements.push(element),relationTypeMap.set(value,relatedElements),indexes.byRelation.set(key,relationTypeMap)}}if(indexConfig.bySubcircuit&&"subcircuit_id"in element){let subcircuitId=element.subcircuit_id;if(subcircuitId&&typeof subcircuitId=="string"){let subcircuitElements=indexes.bySubcircuit.get(subcircuitId)||[];subcircuitElements.push(element),indexes.bySubcircuit.set(subcircuitId,subcircuitElements)}}if(indexConfig.byCustomField&&indexes.byCustomField){for(let field of indexConfig.byCustomField)if(field in element){let fieldValue=element[field];if(fieldValue!==void 0&&(typeof fieldValue=="string"||typeof fieldValue=="number")){let fieldValueStr=String(fieldValue),fieldMap=indexes.byCustomField.get(field),elementsWithFieldValue=fieldMap.get(fieldValueStr)||[];elementsWithFieldValue.push(element),fieldMap.set(fieldValueStr,elementsWithFieldValue)}}}}soup._internal_store_indexed=internalStore}let suIndexed=new Proxy({},{get:(proxy_target,prop)=>{if(prop==="toArray")return()=>(soup.editCount=internalStore.editCount,soup);if(prop==="editCount")return internalStore.editCount;if(prop==="insert")return elm=>{let{type,...props}=elm;if(!type)throw new Error("insert requires an element with a type");return delete props[`${type}_id`],suIndexed[type].insert(props)};if(prop==="insertAll")return elms=>elms.map(elm=>suIndexed.insert(elm));if(prop==="subtree")return opts=>cjuIndexed(buildSubtree(soup,opts),options);let component_type=prop;return{get:id3=>{let indexConfig=options.indexConfig||{};return indexConfig.byId&&internalStore.indexes.byId?internalStore.indexes.byId.get(`${component_type}:${id3}`)||null:indexConfig.byType&&internalStore.indexes.byType?(internalStore.indexes.byType.get(component_type)||[]).find(e55=>e55[`${component_type}_id`]===id3)||null:soup.find(e55=>e55.type===component_type&&e55[`${component_type}_id`]===id3)||null},getUsing:using=>{let indexConfig=options.indexConfig||{},keys=Object.keys(using);if(keys.length!==1)throw new Error("getUsing requires exactly one key, e.g. { pcb_component_id }");let join_key=keys[0],join_type=join_key.replace("_id","");if(indexConfig.byRelation&&internalStore.indexes.byRelation){let relationMap=internalStore.indexes.byRelation.get(join_key);if(relationMap){let joiner2=(relationMap.get(using[join_key])||[]).find(e55=>e55.type===join_type);if(!joiner2)return null;let joinerId=joiner2[`${component_type}_id`];return indexConfig.byId&&internalStore.indexes.byId?internalStore.indexes.byId.get(`${component_type}:${joinerId}`)||null:indexConfig.byType&&internalStore.indexes.byType?(internalStore.indexes.byType.get(component_type)||[]).find(e55=>e55[`${component_type}_id`]===joinerId)||null:soup.find(e55=>e55.type===component_type&&e55[`${component_type}_id`]===joinerId)||null}}let joiner=soup.find(e55=>e55.type===join_type&&e55[join_key]===using[join_key]);return joiner&&soup.find(e55=>e55.type===component_type&&e55[`${component_type}_id`]===joiner[`${component_type}_id`])||null},getWhere:where=>{let indexConfig=options.indexConfig||{},keys=Object.keys(where);if(keys.length===1&&indexConfig.byCustomField&&internalStore.indexes.byCustomField){let field=keys[0],fieldMap=internalStore.indexes.byCustomField.get(field);if(fieldMap){let fieldValue=String(where[field]);return(fieldMap.get(fieldValue)||[]).find(e55=>e55.type===component_type)||null}}if("subcircuit_id"in where&&indexConfig.bySubcircuit&&internalStore.indexes.bySubcircuit){let subcircuitId=where.subcircuit_id;return(internalStore.indexes.bySubcircuit.get(subcircuitId)||[]).find(e55=>e55.type===component_type&&keys.every(key=>e55[key]===where[key]))||null}return indexConfig.byType&&internalStore.indexes.byType?(internalStore.indexes.byType.get(component_type)||[]).find(e55=>keys.every(key=>e55[key]===where[key]))||null:soup.find(e55=>e55.type===component_type&&keys.every(key=>e55[key]===where[key]))||null},list:where=>{let indexConfig=options.indexConfig||{},keys=where?Object.keys(where):[];if(keys.length===0&&indexConfig.byType&&internalStore.indexes.byType)return(internalStore.indexes.byType.get(component_type)||[]).slice();if(keys.length===1&&keys[0]==="subcircuit_id"&&indexConfig.bySubcircuit&&internalStore.indexes.bySubcircuit){let subcircuitId=where.subcircuit_id;return(internalStore.indexes.bySubcircuit.get(subcircuitId)||[]).filter(e55=>e55.type===component_type)}let elementsToFilter;return indexConfig.byType&&internalStore.indexes.byType?elementsToFilter=internalStore.indexes.byType.get(component_type)||[]:elementsToFilter=soup.filter(e55=>e55.type===component_type),keys.length>0?elementsToFilter.filter(e55=>keys.every(key=>e55[key]===where[key])):elementsToFilter.slice()},insert:elm=>{var _a543;(_a543=internalStore.counts)[component_type]??(_a543[component_type]=-1),internalStore.counts[component_type]++;let index2=internalStore.counts[component_type],newElm={type:component_type,[`${component_type}_id`]:`${component_type}_${index2}`,...elm};options.validateInserts&&(dist_exports[component_type]??any_soup_element).parse(newElm),soup.push(newElm),internalStore.editCount++;let indexConfig=options.indexConfig||{};if(indexConfig.byId&&internalStore.indexes.byId){let idKey=createIdKey(newElm);internalStore.indexes.byId.set(idKey,newElm)}if(indexConfig.byType&&internalStore.indexes.byType){let elementsOfType=internalStore.indexes.byType.get(component_type)||[];elementsOfType.push(newElm),internalStore.indexes.byType.set(component_type,elementsOfType)}if(indexConfig.byRelation&&internalStore.indexes.byRelation){let elementEntries=Object.entries(newElm);for(let[key,value]of elementEntries)if(key.endsWith("_id")&&key!==`${newElm.type}_id`&&typeof value=="string"){let relationTypeMap=internalStore.indexes.byRelation.get(key)||new Map,relatedElements=relationTypeMap.get(value)||[];relatedElements.push(newElm),relationTypeMap.set(value,relatedElements),internalStore.indexes.byRelation.set(key,relationTypeMap)}}if(indexConfig.bySubcircuit&&internalStore.indexes.bySubcircuit&&"subcircuit_id"in newElm){let subcircuitId=newElm.subcircuit_id;if(subcircuitId&&typeof subcircuitId=="string"){let subcircuitElements=internalStore.indexes.bySubcircuit.get(subcircuitId)||[];subcircuitElements.push(newElm),internalStore.indexes.bySubcircuit.set(subcircuitId,subcircuitElements)}}if(indexConfig.byCustomField&&internalStore.indexes.byCustomField){for(let field of indexConfig.byCustomField)if(field in newElm){let fieldValue=newElm[field];if(fieldValue!==void 0&&(typeof fieldValue=="string"||typeof fieldValue=="number")){let fieldValueStr=String(fieldValue),fieldMap=internalStore.indexes.byCustomField.get(field),elementsWithFieldValue=fieldMap.get(fieldValueStr)||[];elementsWithFieldValue.push(newElm),fieldMap.set(fieldValueStr,elementsWithFieldValue)}}}return newElm},delete:id3=>{let indexConfig=options.indexConfig||{},elm;if(indexConfig.byId&&internalStore.indexes.byId?elm=internalStore.indexes.byId.get(`${component_type}:${id3}`):indexConfig.byType&&internalStore.indexes.byType?elm=(internalStore.indexes.byType.get(component_type)||[]).find(e55=>e55[`${component_type}_id`]===id3):elm=soup.find(e55=>e55[`${component_type}_id`]===id3),!elm)return;let elmIndex=soup.indexOf(elm);if(elmIndex>=0&&(soup.splice(elmIndex,1),internalStore.editCount++),indexConfig.byId&&internalStore.indexes.byId){let idKey=createIdKey(elm);internalStore.indexes.byId.delete(idKey)}if(indexConfig.byType&&internalStore.indexes.byType){let filteredElements=(internalStore.indexes.byType.get(component_type)||[]).filter(e55=>e55[`${component_type}_id`]!==id3);internalStore.indexes.byType.set(component_type,filteredElements)}if(indexConfig.byRelation&&internalStore.indexes.byRelation)for(let[relationKey,relationMap]of internalStore.indexes.byRelation.entries())for(let[relationValue,elements]of relationMap.entries()){let updatedElements=elements.filter(e55=>e55!==elm);updatedElements.length===0?relationMap.delete(relationValue):relationMap.set(relationValue,updatedElements)}if(indexConfig.bySubcircuit&&internalStore.indexes.bySubcircuit&&"subcircuit_id"in elm){let subcircuitId=elm.subcircuit_id;if(subcircuitId){let updatedElements=(internalStore.indexes.bySubcircuit.get(subcircuitId)||[]).filter(e55=>e55!==elm);updatedElements.length===0?internalStore.indexes.bySubcircuit.delete(subcircuitId):internalStore.indexes.bySubcircuit.set(subcircuitId,updatedElements)}}if(indexConfig.byCustomField&&internalStore.indexes.byCustomField)for(let fieldMap of internalStore.indexes.byCustomField.values())for(let[fieldValue,elements]of fieldMap.entries()){let updatedElements=elements.filter(e55=>e55!==elm);updatedElements.length===0?fieldMap.delete(fieldValue):fieldMap.set(fieldValue,updatedElements)}},update:(id3,newProps)=>{let indexConfig=options.indexConfig||{},elm;if(indexConfig.byId&&internalStore.indexes.byId?elm=internalStore.indexes.byId.get(`${component_type}:${id3}`):indexConfig.byType&&internalStore.indexes.byType?elm=(internalStore.indexes.byType.get(component_type)||[]).find(e55=>e55[`${component_type}_id`]===id3):elm=soup.find(e55=>e55.type===component_type&&e55[`${component_type}_id`]===id3),!elm)return null;if(indexConfig.byRelation&&internalStore.indexes.byRelation){let elementEntries=Object.entries(elm);for(let[key,value]of elementEntries)if(key.endsWith("_id")&&key!==`${elm.type}_id`&&typeof value=="string"&&key in newProps&&newProps[key]!==value){let relationTypeMap=internalStore.indexes.byRelation.get(key);if(relationTypeMap){let updatedElements=(relationTypeMap.get(value)||[]).filter(e55=>e55!==elm);updatedElements.length===0?relationTypeMap.delete(value):relationTypeMap.set(value,updatedElements)}}}if(indexConfig.bySubcircuit&&internalStore.indexes.bySubcircuit&&"subcircuit_id"in elm&&"subcircuit_id"in newProps){let oldSubcircuitId=elm.subcircuit_id,newSubcircuitId=newProps.subcircuit_id;if(oldSubcircuitId!==newSubcircuitId){let updatedElements=(internalStore.indexes.bySubcircuit.get(oldSubcircuitId)||[]).filter(e55=>e55!==elm);updatedElements.length===0?internalStore.indexes.bySubcircuit.delete(oldSubcircuitId):internalStore.indexes.bySubcircuit.set(oldSubcircuitId,updatedElements)}}if(indexConfig.byCustomField&&internalStore.indexes.byCustomField){for(let field of indexConfig.byCustomField)if(field in elm&&field in newProps&&elm[field]!==newProps[field]){let fieldMap=internalStore.indexes.byCustomField.get(field);if(fieldMap){let oldValue=String(elm[field]),updatedElements=(fieldMap.get(oldValue)||[]).filter(e55=>e55!==elm);updatedElements.length===0?fieldMap.delete(oldValue):fieldMap.set(oldValue,updatedElements)}}}if(Object.assign(elm,newProps),internalStore.editCount++,indexConfig.byRelation&&internalStore.indexes.byRelation){let elementEntries=Object.entries(elm);for(let[key,value]of elementEntries)if(key.endsWith("_id")&&key!==`${elm.type}_id`&&typeof value=="string"&&key in newProps){let relationTypeMap=internalStore.indexes.byRelation.get(key)||new Map,relatedElements=relationTypeMap.get(value)||[];relatedElements.includes(elm)||(relatedElements.push(elm),relationTypeMap.set(value,relatedElements),internalStore.indexes.byRelation.set(key,relationTypeMap))}}if(indexConfig.bySubcircuit&&internalStore.indexes.bySubcircuit&&"subcircuit_id"in elm&&"subcircuit_id"in newProps){let subcircuitId=elm.subcircuit_id;if(subcircuitId&&typeof subcircuitId=="string"){let subcircuitElements=internalStore.indexes.bySubcircuit.get(subcircuitId)||[];subcircuitElements.includes(elm)||(subcircuitElements.push(elm),internalStore.indexes.bySubcircuit.set(subcircuitId,subcircuitElements))}}if(indexConfig.byCustomField&&internalStore.indexes.byCustomField){for(let field of indexConfig.byCustomField)if(field in elm&&field in newProps){let fieldValue=elm[field];if(fieldValue!==void 0&&(typeof fieldValue=="string"||typeof fieldValue=="number")){let fieldValueStr=String(fieldValue),fieldMap=internalStore.indexes.byCustomField.get(field),elementsWithFieldValue=fieldMap.get(fieldValueStr)||[];elementsWithFieldValue.includes(elm)||(elementsWithFieldValue.push(elm),fieldMap.set(fieldValueStr,elementsWithFieldValue))}}}return elm},select:selector2=>{if(component_type==="source_component")return soup.find(e55=>e55.type==="source_component"&&e55.name===selector2.replace(/\./g,""))||null;if(component_type==="pcb_port"||component_type==="source_port"||component_type==="schematic_port"){let[component_name,port_selector]=selector2.replace(/\./g,"").split(/[\s\>]+/),source_component=soup.find(e55=>e55.type==="source_component"&&e55.name===component_name);if(!source_component)return null;let source_port3=soup.find(e55=>e55.type==="source_port"&&e55.source_component_id===source_component.source_component_id&&(e55.name===port_selector||(e55.port_hints??[]).includes(port_selector)));if(!source_port3)return null;if(component_type==="source_port")return source_port3;if(component_type==="pcb_port")return soup.find(e55=>e55.type==="pcb_port"&&e55.source_port_id===source_port3.source_port_id)||null;if(component_type==="schematic_port")return soup.find(e55=>e55.type==="schematic_port"&&e55.source_port_id===source_port3.source_port_id)||null}return null}}}});return suIndexed});cjuIndexed.unparsed=cjuIndexed;cju_indexed_default=cjuIndexed,rotateClockwise=direction3=>{if(direction3==="up")return"right";if(direction3==="right")return"down";if(direction3==="down")return"left";if(direction3==="left")return"up";throw new Error(`Invalid direction: ${direction3}`)},rotateCounterClockwise=direction3=>{if(direction3==="up")return"left";if(direction3==="left")return"down";if(direction3==="down")return"right";if(direction3==="right")return"up";throw new Error(`Invalid direction: ${direction3}`)},rotateDirection=(direction3,num90DegreeClockwiseTurns)=>{for(;num90DegreeClockwiseTurns>0;)direction3=rotateClockwise(direction3),num90DegreeClockwiseTurns--;for(;num90DegreeClockwiseTurns<0;)direction3=rotateCounterClockwise(direction3),num90DegreeClockwiseTurns++;return direction3},oppositeSide=sideOrDir=>{if(sideOrDir==="top"||sideOrDir==="up")return"bottom";if(sideOrDir==="bottom"||sideOrDir==="down")return"top";if(sideOrDir==="left")return"right";if(sideOrDir==="right")return"left";throw new Error(`Invalid sideOrDir: ${sideOrDir}`)},getQuarterTurns=angleRadians=>Math.round(angleRadians/(Math.PI/2)),insertionDirectionToVec=direction3=>{switch(direction3){case"from_left":return{x:-1,y:0};case"from_right":return{x:1,y:0};case"from_top":return{x:0,y:1};case"from_bottom":return{x:0,y:-1}}},vecToInsertionDirection=({x:x11,y:y11})=>x11>0?"from_right":x11<0?"from_left":y11>0?"from_top":"from_bottom",transformInsertionDirection=(direction3,opts)=>{if(!direction3)return direction3;if(direction3==="from_above"||direction3==="from_below")return opts.isFlipped?direction3==="from_above"?"from_below":"from_above":direction3;let{x:x11,y:y11}=insertionDirectionToVec(direction3),quarterTurns=Math.round(opts.rotationDegrees/90);for(;quarterTurns>0;)[x11,y11]=[-y11,x11],quarterTurns--;for(;quarterTurns<0;)[x11,y11]=[y11,-x11],quarterTurns++;return opts.isFlipped&&(y11=-y11),vecToInsertionDirection({x:x11,y:y11})},transformSchematicElement=(elm,matrix2)=>{if(elm.type==="schematic_component")elm.center=applyToPoint(matrix2,elm.center);else if(elm.type==="schematic_port")elm.center=applyToPoint(matrix2,elm.center),elm.facing_direction&&(elm.facing_direction=rotateDirection(elm.facing_direction,-(Math.atan2(matrix2.b,matrix2.a)/Math.PI)*2));else if(elm.type==="schematic_text")elm.position=applyToPoint(matrix2,elm.position);else if(elm.type==="schematic_trace"){let anyElm=elm;anyElm.route=(anyElm.route??[]).map(rp4=>{let tp3=applyToPoint(matrix2,rp4);return rp4.x=tp3.x,rp4.y=tp3.y,rp4}),Array.isArray(anyElm.junctions)&&(anyElm.junctions=anyElm.junctions.map(j11=>{let tp3=applyToPoint(matrix2,j11);return j11.x=tp3.x,j11.y=tp3.y,j11})),Array.isArray(anyElm.edges)&&(anyElm.edges=anyElm.edges.map(e55=>(e55.from=applyToPoint(matrix2,e55.from),e55.to=applyToPoint(matrix2,e55.to),e55)))}else if(elm.type==="schematic_box"){let{x:x11,y:y11}=applyToPoint(matrix2,{x:elm.x,y:elm.y});elm.x=x11,elm.y=y11}else if(elm.type==="schematic_line"){let{x:x12,y:y12}=applyToPoint(matrix2,{x:elm.x1,y:elm.y1}),{x:x22,y:y22}=applyToPoint(matrix2,{x:elm.x2,y:elm.y2});elm.x1=x12,elm.y1=y12,elm.x2=x22,elm.y2=y22}return elm},transformSchematicElements=(elms,matrix2)=>elms.map(elm=>transformSchematicElement(elm,matrix2)),transformPcbSoldermaskOpening=(opening,matrix2)=>{if(opening.shape==="polygon")return opening.points=opening.points.map(point7=>applyToPoint(matrix2,point7)),opening;let center2=applyToPoint(matrix2,{x:opening.x,y:opening.y});if(opening.x=center2.x,opening.y=center2.y,opening.shape==="circle")return opening;let rectRotation=opening.shape==="rotated_rect"?opening.ccw_rotation:0,isReflected=matrix2.a*matrix2.d-matrix2.b*matrix2.c<0,transformedRotation=decomposeTSR(compose(matrix2,rotateDEG(rectRotation)),!1,isReflected).rotation.angle*180/Math.PI;return Math.abs(transformedRotation)<1e-8?(Object.assign(opening,{shape:"rect"}),Reflect.deleteProperty(opening,"ccw_rotation")):Object.assign(opening,{shape:"rotated_rect",ccw_rotation:transformedRotation}),opening},transformPCBElement=(elm,matrix2)=>{if(elm.type==="pcb_soldermask_opening")return transformPcbSoldermaskOpening(elm,matrix2);if((elm.type==="pcb_smtpad"||elm.type==="pcb_solder_paste")&&elm.shape==="polygon")return elm.points=elm.points.map(point7=>applyToPoint(matrix2,point7)),elm.type==="pcb_solder_paste"&&elm.holes&&(elm.holes=elm.holes.map(hole=>hole.map(point7=>applyToPoint(matrix2,point7)))),elm;let tsr=decomposeTSR(matrix2),flipPadWidthHeight=Math.abs(getQuarterTurns(tsr.rotation.angle))%2===1,rotationDegrees=tsr.rotation.angle/Math.PI*180,isFlipped=tsr.scale.sy<0;if(elm.type==="pcb_plated_hole"||elm.type==="pcb_hole"||elm.type==="pcb_via"||elm.type==="pcb_smtpad"||elm.type==="pcb_solder_paste"||elm.type==="pcb_port"){let{x:x11,y:y11}=applyToPoint(matrix2,{x:elm.x,y:elm.y});elm.x=x11,elm.y=y11}else if(elm.type==="pcb_keepout"&&elm.shape==="outline")elm.outline=elm.outline.map(point7=>applyToPoint(matrix2,point7));else if(elm.type==="pcb_keepout"||elm.type==="pcb_board")elm.center=applyToPoint(matrix2,elm.center);else if(elm.type==="pcb_silkscreen_text"||elm.type==="pcb_fabrication_note_text"||elm.type==="pcb_note_text")elm.anchor_position=applyToPoint(matrix2,elm.anchor_position);else if(elm.type==="pcb_copper_text")elm.anchor_position&&(elm.anchor_position=applyToPoint(matrix2,elm.anchor_position));else if(elm.type==="pcb_courtyard_rect")elm.center=applyToPoint(matrix2,elm.center),elm.ccw_rotation=((elm.ccw_rotation??0)+rotationDegrees)%360;else if(elm.type==="pcb_silkscreen_circle"||elm.type==="pcb_silkscreen_rect"||elm.type==="pcb_silkscreen_pill"||elm.type==="pcb_silkscreen_oval"||elm.type==="pcb_note_rect"||elm.type==="pcb_courtyard_circle")elm.center=applyToPoint(matrix2,elm.center);else if(elm.type==="pcb_component")elm.center=applyToPoint(matrix2,elm.center),elm.rotation=elm.rotation+rotationDegrees,elm.rotation=elm.rotation%360,elm.cable_insertion_center&&(elm.cable_insertion_center=applyToPoint(matrix2,elm.cable_insertion_center)),elm.insertion_direction=transformInsertionDirection(elm.insertion_direction,{rotationDegrees,isFlipped}),flipPadWidthHeight&&([elm.width,elm.height]=[elm.height,elm.width]);else if(elm.type==="pcb_courtyard_outline")elm.outline=elm.outline.map(p11=>{let tp3=applyToPoint(matrix2,p11);return p11.x=tp3.x,p11.y=tp3.y,p11});else if(elm.type==="pcb_courtyard_polygon")elm.points=elm.points.map(p11=>{let tp3=applyToPoint(matrix2,p11);return p11.x=tp3.x,p11.y=tp3.y,p11});else if(elm.type==="pcb_trace")elm.route=elm.route.map(rp4=>{if(!("x"in rp4))return rp4.start=applyToPoint(matrix2,rp4.start),rp4.end=applyToPoint(matrix2,rp4.end),rp4;let tp3=applyToPoint(matrix2,rp4);return rp4.x=tp3.x,rp4.y=tp3.y,rp4});else if(elm.type==="pcb_silkscreen_path"||elm.type==="pcb_trace_hint"||elm.type==="pcb_fabrication_note_path"||elm.type==="pcb_note_path")elm.route=elm.route.map(rp4=>{let tp3=applyToPoint(matrix2,rp4);return rp4.x=tp3.x,rp4.y=tp3.y,rp4});else if(elm.type==="pcb_silkscreen_line"||elm.type==="pcb_note_line"){let p12={x:elm.x1,y:elm.y1},p22={x:elm.x2,y:elm.y2},p1t=applyToPoint(matrix2,p12),p2t=applyToPoint(matrix2,p22);elm.x1=p1t.x,elm.y1=p1t.y,elm.x2=p2t.x,elm.y2=p2t.y}else if(elm.type==="cad_component"){let newPos=applyToPoint(matrix2,{x:elm.position.x,y:elm.position.y});elm.position.x=newPos.x,elm.position.y=newPos.y}return elm},transformPCBElements=(elms,matrix2)=>{let tsr=decomposeTSR(matrix2),quarterTurns=getQuarterTurns(tsr.rotation.angle),flipPadWidthHeight=Math.abs(quarterTurns)%2===1,transformedElms=elms.map(elm=>transformPCBElement(elm,matrix2));return flipPadWidthHeight&&(transformedElms=transformedElms.map(elm=>((elm.type==="pcb_smtpad"||elm.type==="pcb_solder_paste")&&(elm.shape==="rect"||elm.shape==="pill")&&([elm.width,elm.height]=[elm.height,elm.width]),elm))),transformedElms},getElementId=elm=>{let type=elm.type;return elm[`${type}_id`]},getElementById2=(soup,id3)=>soup.find(elm=>getElementId(elm)===id3)??null,getReadableNameForPcbPort=(soup,pcb_port_id)=>{let pcbPort=cju(soup).pcb_port.get(pcb_port_id);if(!pcbPort)return`pcb_port[#${pcb_port_id}]`;let pcbComponent=pcbPort.pcb_component_id?cju(soup).pcb_component.get(pcbPort.pcb_component_id):void 0;if(!pcbComponent)return`pcb_port[#${pcb_port_id}]`;let sourceComponent=cju(soup).source_component.get(pcbComponent.source_component_id);if(!sourceComponent)return`pcb_port[#${pcb_port_id}]`;let sourcePort=cju(soup).source_port.get(pcbPort.source_port_id);if(!sourcePort)return`pcb_port[#${pcb_port_id}]`;let padIdentifier;return sourcePort?.port_hints&&sourcePort.port_hints.length>0||sourcePort.port_hints&&sourcePort.port_hints.length>0?padIdentifier=sourcePort.port_hints[0]:padIdentifier=pcb_port_id,`pcb_port[.${sourceComponent.name} > .${padIdentifier}]`};getReadableNameForElement=(soup,elm)=>{if(typeof elm=="string"){let elmObj=getElementById2(soup,elm);return elmObj||`${elm}`,getReadableNameForElement(soup,elmObj)}switch(elm.type){case"pcb_port":return getReadableNameForPcbPort(soup,elm.pcb_port_id);case"pcb_smtpad":return getReadableNameForPcbSmtpad(soup,elm.pcb_smtpad_id);case"pcb_trace":return getReadableNameForPcbTrace(soup,elm.pcb_trace_id);case"source_component":return`source_component[${elm.name}]`;default:return`${elm.type}[#${getElementId(elm)}]`}},mergeBounds=(currentBounds,nextBounds)=>({minX:Math.min(currentBounds.minX,nextBounds.minX),minY:Math.min(currentBounds.minY,nextBounds.minY),maxX:Math.max(currentBounds.maxX,nextBounds.maxX),maxY:Math.max(currentBounds.maxY,nextBounds.maxY)}),getCircleBounds=(x11,y11,diameter)=>{let radius=diameter/2;return{minX:x11-radius,minY:y11-radius,maxX:x11+radius,maxY:y11+radius}},getRotatedRectBounds=(x11,y11,width,height,rotationDegrees)=>{let halfWidth=width/2,halfHeight=height/2,theta=rotationDegrees*Math.PI/180,cosTheta=Math.cos(theta),sinTheta=Math.sin(theta),corners=[{x:-halfWidth,y:-halfHeight},{x:halfWidth,y:-halfHeight},{x:halfWidth,y:halfHeight},{x:-halfWidth,y:halfHeight}].map(corner=>({x:x11+corner.x*cosTheta-corner.y*sinTheta,y:y11+corner.x*sinTheta+corner.y*cosTheta}));return{minX:Math.min(...corners.map(corner=>corner.x)),minY:Math.min(...corners.map(corner=>corner.y)),maxX:Math.max(...corners.map(corner=>corner.x)),maxY:Math.max(...corners.map(corner=>corner.y))}},getRotatedOvalBounds=(x11,y11,width,height,rotationDegrees)=>{let radiusX=width/2,radiusY=height/2,theta=rotationDegrees*Math.PI/180,cosTheta=Math.cos(theta),sinTheta=Math.sin(theta),halfWidth=Math.hypot(radiusX*cosTheta,radiusY*sinTheta),halfHeight=Math.hypot(radiusX*sinTheta,radiusY*cosTheta);return{minX:x11-halfWidth,minY:y11-halfHeight,maxX:x11+halfWidth,maxY:y11+halfHeight}},getRotatedPillBounds=(x11,y11,width,height,rotationDegrees)=>{let radius=Math.min(width,height)/2,halfLineLength=Math.max(width,height)/2-radius,theta=rotationDegrees*Math.PI/180,axis=width>=height?{x:halfLineLength,y:0}:{x:0,y:halfLineLength},rotatedAxis={x:axis.x*Math.cos(theta)-axis.y*Math.sin(theta),y:axis.x*Math.sin(theta)+axis.y*Math.cos(theta)},halfWidth=Math.abs(rotatedAxis.x)+radius,halfHeight=Math.abs(rotatedAxis.y)+radius;return{minX:x11-halfWidth,minY:y11-halfHeight,maxX:x11+halfWidth,maxY:y11+halfHeight}},getBoundsFromPoints3=points=>points.length===0?null:{minX:Math.min(...points.map(point7=>point7.x)),minY:Math.min(...points.map(point7=>point7.y)),maxX:Math.max(...points.map(point7=>point7.x)),maxY:Math.max(...points.map(point7=>point7.y))},getRoutePoints=route2=>Array.isArray(route2)?route2.flatMap(point7=>!point7||typeof point7!="object"?[]:"x"in point7&&"y"in point7&&typeof point7.x=="number"&&typeof point7.y=="number"?[{x:point7.x,y:point7.y}]:"start"in point7&&"end"in point7?[point7.start,point7.end].filter(position4=>!!(position4&&typeof position4=="object"&&"x"in position4&&"y"in position4&&typeof position4.x=="number"&&typeof position4.y=="number")):[]):[],getPcbElementBounds=elm=>{if(!elm.type.startsWith("pcb_"))return null;if(elm.type==="pcb_smtpad"&&elm.shape==="polygon"&&Array.isArray(elm.points))return getBoundsFromPoints3(elm.points);if(elm.type==="pcb_hole"&&elm.hole_shape==="circle")return getCircleBounds(elm.x,elm.y,elm.hole_diameter);if(elm.type==="pcb_plated_hole"){let platedHoleBounds;if("outer_diameter"in elm&&typeof elm.outer_diameter=="number"?platedHoleBounds=getCircleBounds(elm.x,elm.y,elm.outer_diameter):"hole_diameter"in elm&&typeof elm.hole_diameter=="number"&&(platedHoleBounds=getCircleBounds(elm.x,elm.y,elm.hole_diameter)),(elm.shape==="oval"||elm.shape==="pill")&&typeof elm.outer_width=="number"&&typeof elm.outer_height=="number"&&(platedHoleBounds=(elm.shape==="pill"?getRotatedPillBounds:getRotatedOvalBounds)(elm.x,elm.y,elm.outer_width,elm.outer_height,elm.ccw_rotation??0)),"rect_pad_width"in elm&&typeof elm.rect_pad_width=="number"&&"rect_pad_height"in elm&&typeof elm.rect_pad_height=="number"){let rectBounds2=getRotatedRectBounds(elm.x,elm.y,elm.rect_pad_width,elm.rect_pad_height,"rect_ccw_rotation"in elm?elm.rect_ccw_rotation??0:0);platedHoleBounds=platedHoleBounds?mergeBounds(platedHoleBounds,rectBounds2):rectBounds2}if("hole_diameter"in elm&&typeof elm.hole_diameter=="number"){let drillBounds=getCircleBounds(elm.x+("hole_offset_x"in elm?elm.hole_offset_x??0:0),elm.y+("hole_offset_y"in elm?elm.hole_offset_y??0:0),elm.hole_diameter);platedHoleBounds=platedHoleBounds?mergeBounds(platedHoleBounds,drillBounds):drillBounds}if(platedHoleBounds)return platedHoleBounds}let elementRecord=elm,routeBounds=getBoundsFromPoints3(getRoutePoints(elementRecord.route));if(routeBounds)return routeBounds;let outlineBounds=getBoundsFromPoints3(getRoutePoints(elementRecord.outline));if(outlineBounds)return outlineBounds;let pointsBounds=getBoundsFromPoints3(getRoutePoints(elementRecord.points));if(pointsBounds)return pointsBounds;let centerX,centerY,width,height;"x"in elm&&"y"in elm&&(centerX=Number(elm.x),centerY=Number(elm.y)),"outer_diameter"in elm&&(width=Number(elm.outer_diameter),height=Number(elm.outer_diameter)),"width"in elm&&(width=Number(elm.width)),"height"in elm&&(height=Number(elm.height)),"center"in elm&&elm.center&&typeof elm.center=="object"&&"x"in elm.center&&"y"in elm.center&&(centerX=Number(elm.center.x),centerY=Number(elm.center.y));let rotation5=0;if("rotation"in elm&&typeof elm.rotation=="number"&&(rotation5=elm.rotation),"ccw_rotation"in elm&&typeof elm.ccw_rotation=="number"&&(rotation5=elm.ccw_rotation),centerX!==void 0&&centerY!==void 0)return width!==void 0&&height!==void 0?rotation5?getRotatedRectBounds(centerX,centerY,width,height,rotation5):{minX:centerX-width/2,minY:centerY-height/2,maxX:centerX+width/2,maxY:centerY+height/2}:"radius"in elm&&typeof elm.radius=="number"?getCircleBounds(centerX,centerY,elm.radius*2):{minX:centerX,minY:centerY,maxX:centerX,maxY:centerY};let anchoredPoint=[elementRecord.anchor_position,elementRecord.position].filter(position4=>!!(position4&&typeof position4=="object"&&"x"in position4&&"y"in position4&&typeof position4.x=="number"&&typeof position4.y=="number")).at(0);return anchoredPoint?{minX:anchoredPoint.x,minY:anchoredPoint.y,maxX:anchoredPoint.x,maxY:anchoredPoint.y}:null},getBoundsOfPcbElements=elements=>{let bounds={minX:Number.POSITIVE_INFINITY,minY:Number.POSITIVE_INFINITY,maxX:Number.NEGATIVE_INFINITY,maxY:Number.NEGATIVE_INFINITY};for(let element of elements){let elementBounds=getPcbElementBounds(element);elementBounds&&(bounds=mergeBounds(bounds,elementBounds))}return bounds},getBoardBounds=board=>{if(board.width&&board.height&&board.center){let halfWidth=board.width/2,halfHeight=board.height/2;return{minX:board.center.x-halfWidth,minY:board.center.y-halfHeight,maxX:board.center.x+halfWidth,maxY:board.center.y+halfHeight,width:board.width,height:board.height,center:{x:board.center.x,y:board.center.y}}}if(!board.outline||board.outline.length===0)throw new Error("Unable to compute board bounds. pcb_board must include width/height/center or a non-empty outline.");let minX=Number.POSITIVE_INFINITY,minY=Number.POSITIVE_INFINITY,maxX=Number.NEGATIVE_INFINITY,maxY=Number.NEGATIVE_INFINITY;for(let point7 of board.outline)minX=Math.min(minX,point7.x),minY=Math.min(minY,point7.y),maxX=Math.max(maxX,point7.x),maxY=Math.max(maxY,point7.y);let width=maxX-minX,height=maxY-minY;return{minX,minY,maxX,maxY,width,height,center:{x:minX+width/2,y:minY+height/2}}},SCHEMATIC_TRACE_WIDTH=.1,SCHEMATIC_NET_LABEL_FONT_SIZE=.18,SCHEMATIC_NET_LABEL_HEIGHT=.2,createBounds=({minX,minY,maxX,maxY})=>{let width=maxX-minX,height=maxY-minY;return{minX,minY,maxX,maxY,width,height,center:{x:minX+width/2,y:minY+height/2}}},getSchematicNetLabelTextWidth=text=>{let characterWidth=.12*(SCHEMATIC_NET_LABEL_FONT_SIZE/.18),horizontalPadding=.12*(SCHEMATIC_NET_LABEL_FONT_SIZE/.18);return text.length*characterWidth+horizontalPadding},getSchematicNetLabelBounds=netLabel=>{let labelLength=getSchematicNetLabelTextWidth(netLabel.text),anchor3=netLabel.anchor_position;if(!anchor3){let isVertical6=netLabel.anchor_side==="top"||netLabel.anchor_side==="bottom",width=isVertical6?SCHEMATIC_NET_LABEL_HEIGHT:labelLength,height=isVertical6?labelLength:SCHEMATIC_NET_LABEL_HEIGHT;return createBounds({minX:netLabel.center.x-width/2,minY:netLabel.center.y-height/2,maxX:netLabel.center.x+width/2,maxY:netLabel.center.y+height/2})}switch(netLabel.anchor_side){case"left":return createBounds({minX:anchor3.x,minY:anchor3.y-SCHEMATIC_NET_LABEL_HEIGHT/2,maxX:anchor3.x+labelLength,maxY:anchor3.y+SCHEMATIC_NET_LABEL_HEIGHT/2});case"right":return createBounds({minX:anchor3.x-labelLength,minY:anchor3.y-SCHEMATIC_NET_LABEL_HEIGHT/2,maxX:anchor3.x,maxY:anchor3.y+SCHEMATIC_NET_LABEL_HEIGHT/2});case"top":return createBounds({minX:anchor3.x-SCHEMATIC_NET_LABEL_HEIGHT/2,minY:anchor3.y-labelLength,maxX:anchor3.x+SCHEMATIC_NET_LABEL_HEIGHT/2,maxY:anchor3.y});case"bottom":return createBounds({minX:anchor3.x-SCHEMATIC_NET_LABEL_HEIGHT/2,minY:anchor3.y,maxX:anchor3.x+SCHEMATIC_NET_LABEL_HEIGHT/2,maxY:anchor3.y+labelLength})}},getSchematicElementBounds=element=>{if(element.type==="schematic_component")return createBounds({minX:element.center.x-element.size.width/2,minY:element.center.y-element.size.height/2,maxX:element.center.x+element.size.width/2,maxY:element.center.y+element.size.height/2});if(element.type==="schematic_net_label")return getSchematicNetLabelBounds(element);let points=[...element.edges.flatMap(edge=>[edge.from,edge.to]),...element.junctions];if(points.length===0)return null;let halfTraceWidth=SCHEMATIC_TRACE_WIDTH/2;return createBounds({minX:Math.min(...points.map(point7=>point7.x))-halfTraceWidth,minY:Math.min(...points.map(point7=>point7.y))-halfTraceWidth,maxX:Math.max(...points.map(point7=>point7.x))+halfTraceWidth,maxY:Math.max(...points.map(point7=>point7.y))+halfTraceWidth})};nice_color_palettes=[["#69d2e7","#a7dbd8","#e0e4cc","#f38630","#fa6900"],["#fe4365","#fc9d9a","#f9cdad","#c8c8a9","#83af9b"],["#ecd078","#d95b43","#c02942","#542437","#53777a"],["#556270","#4ecdc4","#c7f464","#ff6b6b","#c44d58"],["#774f38","#e08e79","#f1d4af","#ece5ce","#c5e0dc"],["#e8ddcb","#cdb380","#036564","#033649","#031634"],["#490a3d","#bd1550","#e97f02","#f8ca00","#8a9b0f"],["#594f4f","#547980","#45ada8","#9de0ad","#e5fcc2"],["#00a0b0","#6a4a3c","#cc333f","#eb6841","#edc951"],["#e94e77","#d68189","#c6a49a","#c6e5d9","#f4ead5"],["#3fb8af","#7fc7af","#dad8a7","#ff9e9d","#ff3d7f"],["#d9ceb2","#948c75","#d5ded9","#7a6a53","#99b2b7"],["#ffffff","#cbe86b","#f2e9e1","#1c140d","#cbe86b"],["#efffcd","#dce9be","#555152","#2e2633","#99173c"],["#343838","#005f6b","#008c9e","#00b4cc","#00dffc"],["#413e4a","#73626e","#b38184","#f0b49e","#f7e4be"],["#ff4e50","#fc913a","#f9d423","#ede574","#e1f5c4"],["#99b898","#fecea8","#ff847c","#e84a5f","#2a363b"],["#655643","#80bca3","#f6f7bd","#e6ac27","#bf4d28"],["#00a8c6","#40c0cb","#f9f2e7","#aee239","#8fbe00"],["#351330","#424254","#64908a","#e8caa4","#cc2a41"],["#554236","#f77825","#d3ce3d","#f1efa5","#60b99a"],["#5d4157","#838689","#a8caba","#cad7b2","#ebe3aa"],["#8c2318","#5e8c6a","#88a65e","#bfb35a","#f2c45a"],["#fad089","#ff9c5b","#f5634a","#ed303c","#3b8183"],["#ff4242","#f4fad2","#d4ee5e","#e1edb9","#f0f2eb"],["#f8b195","#f67280","#c06c84","#6c5b7b","#355c7d"],["#d1e751","#ffffff","#000000","#4dbce9","#26ade4"],["#1b676b","#519548","#88c425","#bef202","#eafde6"],["#5e412f","#fcebb6","#78c0a8","#f07818","#f0a830"],["#bcbdac","#cfbe27","#f27435","#f02475","#3b2d38"],["#452632","#91204d","#e4844a","#e8bf56","#e2f7ce"],["#eee6ab","#c5bc8e","#696758","#45484b","#36393b"],["#f0d8a8","#3d1c00","#86b8b1","#f2d694","#fa2a00"],["#2a044a","#0b2e59","#0d6759","#7ab317","#a0c55f"],["#f04155","#ff823a","#f2f26f","#fff7bd","#95cfb7"],["#b9d7d9","#668284","#2a2829","#493736","#7b3b3b"],["#bbbb88","#ccc68d","#eedd99","#eec290","#eeaa88"],["#b3cc57","#ecf081","#ffbe40","#ef746f","#ab3e5b"],["#a3a948","#edb92e","#f85931","#ce1836","#009989"],["#300030","#480048","#601848","#c04848","#f07241"],["#67917a","#170409","#b8af03","#ccbf82","#e33258"],["#aab3ab","#c4cbb7","#ebefc9","#eee0b7","#e8caaf"],["#e8d5b7","#0e2430","#fc3a51","#f5b349","#e8d5b9"],["#ab526b","#bca297","#c5ceae","#f0e2a4","#f4ebc3"],["#607848","#789048","#c0d860","#f0f0d8","#604848"],["#b6d8c0","#c8d9bf","#dadabd","#ecdbbc","#fedcba"],["#a8e6ce","#dcedc2","#ffd3b5","#ffaaa6","#ff8c94"],["#3e4147","#fffedf","#dfba69","#5a2e2e","#2a2c31"],["#fc354c","#29221f","#13747d","#0abfbc","#fcf7c5"],["#cc0c39","#e6781e","#c8cf02","#f8fcc1","#1693a7"],["#1c2130","#028f76","#b3e099","#ffeaad","#d14334"],["#a7c5bd","#e5ddcb","#eb7b59","#cf4647","#524656"],["#dad6ca","#1bb0ce","#4f8699","#6a5e72","#563444"],["#5c323e","#a82743","#e15e32","#c0d23e","#e5f04c"],["#edebe6","#d6e1c7","#94c7b6","#403b33","#d3643b"],["#fdf1cc","#c6d6b8","#987f69","#e3ad40","#fcd036"],["#230f2b","#f21d41","#ebebbc","#bce3c5","#82b3ae"],["#b9d3b0","#81bda4","#b28774","#f88f79","#f6aa93"],["#3a111c","#574951","#83988e","#bcdea5","#e6f9bc"],["#5e3929","#cd8c52","#b7d1a3","#dee8be","#fcf7d3"],["#1c0113","#6b0103","#a30006","#c21a01","#f03c02"],["#000000","#9f111b","#b11623","#292c37","#cccccc"],["#382f32","#ffeaf2","#fcd9e5","#fbc5d8","#f1396d"],["#e3dfba","#c8d6bf","#93ccc6","#6cbdb5","#1a1f1e"],["#f6f6f6","#e8e8e8","#333333","#990100","#b90504"],["#1b325f","#9cc4e4","#e9f2f9","#3a89c9","#f26c4f"],["#a1dbb2","#fee5ad","#faca66","#f7a541","#f45d4c"],["#c1b398","#605951","#fbeec2","#61a6ab","#accec0"],["#5e9fa3","#dcd1b4","#fab87f","#f87e7b","#b05574"],["#951f2b","#f5f4d7","#e0dfb1","#a5a36c","#535233"],["#8dccad","#988864","#fea6a2","#f9d6ac","#ffe9af"],["#2d2d29","#215a6d","#3ca2a2","#92c7a3","#dfece6"],["#413d3d","#040004","#c8ff00","#fa023c","#4b000f"],["#eff3cd","#b2d5ba","#61ada0","#248f8d","#605063"],["#ffefd3","#fffee4","#d0ecea","#9fd6d2","#8b7a5e"],["#cfffdd","#b4dec1","#5c5863","#a85163","#ff1f4c"],["#9dc9ac","#fffec7","#f56218","#ff9d2e","#919167"],["#4e395d","#827085","#8ebe94","#ccfc8e","#dc5b3e"],["#a8a7a7","#cc527a","#e8175d","#474747","#363636"],["#f8edd1","#d88a8a","#474843","#9d9d93","#c5cfc6"],["#046d8b","#309292","#2fb8ac","#93a42a","#ecbe13"],["#f38a8a","#55443d","#a0cab5","#cde9ca","#f1edd0"],["#a70267","#f10c49","#fb6b41","#f6d86b","#339194"],["#ff003c","#ff8a00","#fabe28","#88c100","#00c176"],["#ffedbf","#f7803c","#f54828","#2e0d23","#f8e4c1"],["#4e4d4a","#353432","#94ba65","#2790b0","#2b4e72"],["#0ca5b0","#4e3f30","#fefeeb","#f8f4e4","#a5b3aa"],["#4d3b3b","#de6262","#ffb88c","#ffd0b3","#f5e0d3"],["#fffbb7","#a6f6af","#66b6ab","#5b7c8d","#4f2958"],["#edf6ee","#d1c089","#b3204d","#412e28","#151101"],["#9d7e79","#ccac95","#9a947c","#748b83","#5b756c"],["#fcfef5","#e9ffe1","#cdcfb7","#d6e6c3","#fafbe3"],["#9cddc8","#bfd8ad","#ddd9ab","#f7af63","#633d2e"],["#30261c","#403831","#36544f","#1f5f61","#0b8185"],["#aaff00","#ffaa00","#ff00aa","#aa00ff","#00aaff"],["#d1313d","#e5625c","#f9bf76","#8eb2c5","#615375"],["#ffe181","#eee9e5","#fad3b2","#ffba7f","#ff9c97"],["#73c8a9","#dee1b6","#e1b866","#bd5532","#373b44"],["#805841","#dcf7f3","#fffcdd","#ffd8d8","#f5a2a2"]],getDebugLayoutObject=lo3=>{let{x:x11,y:y11,width,height}={...lo3,...lo3.size,...lo3.center,...lo3.position};if(lo3.x1!==void 0&&lo3.x2!==void 0&&lo3.y1!==void 0&&lo3.y2!==void 0&&(x11=(lo3.x1+lo3.x2)/2,y11=(lo3.y1+lo3.y2)/2,width=Math.abs(lo3.x1-lo3.x2),height=Math.abs(lo3.y1-lo3.y2)),lo3.points&&Array.isArray(lo3.points)&&lo3.points.length>0){let xCoords=lo3.points.map(point7=>point7.x),yCoords=lo3.points.map(point7=>point7.y),minX=Math.min(...xCoords),maxX=Math.max(...xCoords),minY=Math.min(...yCoords),maxY=Math.max(...yCoords);x11=(minX+maxX)/2,y11=(minY+maxY)/2,width=maxX-minX,height=maxY-minY}let title=lo3.text||lo3.name||lo3.source?.text||lo3.source?.name||"?",content=lo3;return x11===void 0||y11===void 0?null:(width===void 0&&("radius"in lo3?(width=lo3.radius*2,height=lo3.radius*2):"outer_diameter"in lo3?(width=lo3.outer_diameter,height=lo3.outer_diameter):"rect_pad_width"in lo3&&"rect_pad_height"in lo3?(width=lo3.rect_pad_width,height=lo3.rect_pad_height,"hole_diameter"in lo3&&(width=Math.max(width,lo3.hole_diameter),height=Math.max(height,lo3.hole_diameter))):"hole_diameter"in lo3&&(width=lo3.hole_diameter,height=lo3.hole_diameter)),(width===void 0||height===void 0)&&(width=.1,height=.1),{x:x11,y:y11,width,height,title,content,bg_color:nice_color_palettes[stringHash(lo3.type||title)%nice_color_palettes.length]?.[4]??"#f00"})},isTruthy=value=>!!value,findBoundsAndCenter=elements=>{let debugObjects=elements.filter(elm=>elm.type.startsWith("pcb_")||elm.type.startsWith("schematic_")).concat(elements.filter(elm=>elm.type==="pcb_trace"||elm.type==="schematic_trace").flatMap(elm=>elm.route)).map(elm=>getDebugLayoutObject(elm)).filter(isTruthy);if(debugObjects.length===0)return{center:{x:0,y:0},width:0,height:0};let minX=debugObjects[0].x-debugObjects[0].width/2,maxX=debugObjects[0].x+debugObjects[0].width/2,minY=debugObjects[0].y-debugObjects[0].height/2,maxY=debugObjects[0].y+debugObjects[0].height/2;for(let obj of debugObjects.slice(1))minX=Math.min(minX,obj.x-obj.width/2),maxX=Math.max(maxX,obj.x+obj.width/2),minY=Math.min(minY,obj.y-obj.height/2),maxY=Math.max(maxY,obj.y+obj.height/2);let width=maxX-minX,height=maxY-minY;return{center:{x:minX+width/2,y:minY+height/2},width,height}},getPrimaryId=element=>element[`${element.type}_id`],repositionPcbComponentTo=(circuitJson,pcb_component_id,newCenter)=>{let pcbComponent=circuitJson.find(e55=>e55.type==="pcb_component"&&e55.pcb_component_id===pcb_component_id);if(!pcbComponent)return;let currentCenter="center"in pcbComponent?pcbComponent.center:{x:pcbComponent.x,y:pcbComponent.y},dx4=newCenter.x-currentCenter.x,dy4=newCenter.y-currentCenter.y,portIds=circuitJson.filter(e55=>e55.type==="pcb_port"&&e55.pcb_component_id===pcb_component_id).map(e55=>e55.pcb_port_id),elementsToMove=circuitJson.filter(elm=>{if(elm===pcbComponent)return!0;let anyElm=elm;return!!(anyElm.pcb_component_id===pcb_component_id||Array.isArray(anyElm.pcb_component_ids)&&anyElm.pcb_component_ids.includes(pcb_component_id)||anyElm.pcb_port_id&&portIds.includes(anyElm.pcb_port_id)||Array.isArray(anyElm.pcb_port_ids)&&anyElm.pcb_port_ids.some(id3=>portIds.includes(id3))||anyElm.start_pcb_port_id&&portIds.includes(anyElm.start_pcb_port_id)||anyElm.end_pcb_port_id&&portIds.includes(anyElm.end_pcb_port_id)||Array.isArray(anyElm.route)&&anyElm.route.some(pt5=>pt5.start_pcb_port_id&&portIds.includes(pt5.start_pcb_port_id)||pt5.end_pcb_port_id&&portIds.includes(pt5.end_pcb_port_id)))}),matrix2=translate(dx4,dy4);transformPCBElements(elementsToMove,matrix2)},findAllDescendantGroupIds=(circuitJson,parentGroupId)=>{let childGroupIds=[],directChildren=circuitJson.filter(elm=>elm.type==="source_group"&&elm.parent_source_group_id===parentGroupId).map(elm=>elm.source_group_id);childGroupIds.push(...directChildren);for(let childId of directChildren)childGroupIds.push(...findAllDescendantGroupIds(circuitJson,childId));return childGroupIds},repositionPcbGroupTo=(circuitJson,source_group_id,newCenter)=>{let allGroupIds=[source_group_id,...findAllDescendantGroupIds(circuitJson,source_group_id)],allGroupElements=new Set;for(let groupId of allGroupIds)buildSubtree(circuitJson,{source_group_id:groupId}).forEach(elm=>allGroupElements.add(elm));let portIds=Array.from(allGroupElements).filter(e55=>e55.type==="pcb_port").map(e55=>e55.pcb_port_id);circuitJson.filter(elm=>{if(elm.type!=="pcb_trace"||allGroupElements.has(elm))return!1;let anyElm=elm;return!!(anyElm.start_pcb_port_id&&portIds.includes(anyElm.start_pcb_port_id)||anyElm.end_pcb_port_id&&portIds.includes(anyElm.end_pcb_port_id)||Array.isArray(anyElm.route)&&anyElm.route.some(pt5=>pt5.start_pcb_port_id&&portIds.includes(pt5.start_pcb_port_id)||pt5.end_pcb_port_id&&portIds.includes(pt5.end_pcb_port_id)))}).forEach(trace=>allGroupElements.add(trace));let pcbElements=Array.from(allGroupElements).filter(elm=>elm.type.startsWith("pcb_"));if(pcbElements.length===0)return;let{center:currentCenter}=findBoundsAndCenter(pcbElements),dx4=newCenter.x-currentCenter.x,dy4=newCenter.y-currentCenter.y,matrix2=translate(dx4,dy4);transformPCBElements(pcbElements,matrix2)},repositionSchematicComponentTo=(circuitJson,schematic_component_id,newCenter)=>{let schematicComponent=circuitJson.find(e55=>e55.type==="schematic_component"&&e55.schematic_component_id===schematic_component_id);if(!schematicComponent)return;let currentCenter="center"in schematicComponent?schematicComponent.center:{x:schematicComponent.x,y:schematicComponent.y},dx4=newCenter.x-currentCenter.x,dy4=newCenter.y-currentCenter.y,portIds=circuitJson.filter(e55=>e55.type==="schematic_port"&&e55.schematic_component_id===schematic_component_id).map(e55=>e55.schematic_port_id),elementsToMove=circuitJson.filter(elm=>{if(elm===schematicComponent)return!0;let anyElm=elm;return!!(anyElm.schematic_component_id===schematic_component_id||Array.isArray(anyElm.schematic_component_ids)&&anyElm.schematic_component_ids.includes(schematic_component_id)||anyElm.schematic_port_id&&portIds.includes(anyElm.schematic_port_id)||Array.isArray(anyElm.schematic_port_ids)&&anyElm.schematic_port_ids.some(id3=>portIds.includes(id3))||anyElm.start_schematic_port_id&&portIds.includes(anyElm.start_schematic_port_id)||anyElm.end_schematic_port_id&&portIds.includes(anyElm.end_schematic_port_id)||Array.isArray(anyElm.route)&&anyElm.route.some(pt5=>pt5.start_schematic_port_id&&portIds.includes(pt5.start_schematic_port_id)||pt5.end_schematic_port_id&&portIds.includes(pt5.end_schematic_port_id)))}),matrix2=translate(dx4,dy4);transformSchematicElements(elementsToMove,matrix2)},findAllDescendantGroupIds2=(circuitJson,parentGroupId)=>{let childGroupIds=[],directChildren=circuitJson.filter(elm=>elm.type==="source_group"&&elm.parent_source_group_id===parentGroupId).map(elm=>elm.source_group_id);childGroupIds.push(...directChildren);for(let childId of directChildren)childGroupIds.push(...findAllDescendantGroupIds2(circuitJson,childId));return childGroupIds},repositionSchematicGroupTo=(circuitJson,source_group_id,newCenter)=>{let allGroupIds=[source_group_id,...findAllDescendantGroupIds2(circuitJson,source_group_id)],allGroupElements=new Set;for(let groupId of allGroupIds)buildSubtree(circuitJson,{source_group_id:groupId}).forEach(elm=>allGroupElements.add(elm));let portIds=Array.from(allGroupElements).filter(e55=>e55.type==="schematic_port").map(e55=>e55.schematic_port_id);circuitJson.filter(elm=>{if(elm.type!=="schematic_trace"||allGroupElements.has(elm))return!1;let anyElm=elm;return!!(anyElm.start_schematic_port_id&&portIds.includes(anyElm.start_schematic_port_id)||anyElm.end_schematic_port_id&&portIds.includes(anyElm.end_schematic_port_id)||Array.isArray(anyElm.route)&&anyElm.route.some(pt5=>pt5.start_schematic_port_id&&portIds.includes(pt5.start_schematic_port_id)||pt5.end_schematic_port_id&&portIds.includes(pt5.end_schematic_port_id)))}).forEach(trace=>allGroupElements.add(trace));let schematicElements=Array.from(allGroupElements).filter(elm=>elm.type.startsWith("schematic_"));if(schematicElements.length===0)return;let{center:currentCenter}=findBoundsAndCenter(schematicElements),dx4=newCenter.x-currentCenter.x,dy4=newCenter.y-currentCenter.y,matrix2=translate(dx4,dy4);transformSchematicElements(schematicElements,matrix2)},getCircuitJsonTree=(circuitJson,opts)=>{let groupChildMap=new Map,existingGroupIds=new Set;for(let elm of circuitJson)elm.type==="source_group"&&existingGroupIds.add(elm.source_group_id);let orphanedGroups=[];for(let elm of circuitJson)if(elm.type==="source_group"&&elm.parent_source_group_id){let parentId=elm.parent_source_group_id,childId=elm.source_group_id;if(!existingGroupIds.has(parentId))orphanedGroups.push(childId),groupChildMap.has(childId)||groupChildMap.set(childId,[]);else{let children=groupChildMap.get(parentId)??[];children.push(childId),groupChildMap.set(parentId,children),groupChildMap.has(childId)||groupChildMap.set(childId,[])}}for(let elm of circuitJson)elm.type==="source_group"&&!groupChildMap.has(elm.source_group_id)&&groupChildMap.set(elm.source_group_id,[]);let groupNodes=new Map,getNextGroupId=()=>{for(let[parentId,children]of groupChildMap)if(!groupNodes.has(parentId)&&children.every(childId=>groupNodes.has(childId)))return parentId;return null},lastGroupId=null;for(;;){let nextGroupId=getNextGroupId();if(!nextGroupId)break;let node={nodeType:"group",sourceGroup:circuitJson.find(elm=>elm.type==="source_group"&&elm.source_group_id===nextGroupId),otherChildElements:[],childNodes:[...groupChildMap.get(nextGroupId)?.map(childId=>groupNodes.get(childId))??[],...circuitJson.filter(elm=>elm.type==="source_component"&&elm.source_group_id===nextGroupId).map(elm=>({nodeType:"component",sourceComponent:elm,childNodes:[],otherChildElements:[...circuitJson.filter(e55=>e55.type==="pcb_component"&&e55.source_component_id===elm.source_component_id)]}))]};groupNodes.set(nextGroupId,node),lastGroupId=nextGroupId}if(!lastGroupId)return console.warn("No groups were processed, returning tree without sourceGroup"),{nodeType:"group",childNodes:[],otherChildElements:circuitJson};let rootGroupId=null;return opts&&opts.source_group_id!==void 0?rootGroupId=opts.source_group_id:orphanedGroups.length>0?rootGroupId=orphanedGroups[0]:rootGroupId=lastGroupId,rootGroupId?groupNodes.get(rootGroupId):(console.warn("No valid root group found, returning tree without sourceGroup"),{nodeType:"group",childNodes:[],otherChildElements:circuitJson})};EPSILON2=1e-9,clamp3=(value,min4,max5)=>Math.max(min4,Math.min(max5,value)),distanceBetweenPoints=(a10,b10)=>Math.hypot(a10.x-b10.x,a10.y-b10.y),distanceBetweenPointAndSegment=(point7,a10,b10)=>{let abX=b10.x-a10.x,abY=b10.y-a10.y,lengthSquared=abX*abX+abY*abY;if(lengthSquared<=EPSILON2)return distanceBetweenPoints(point7,a10);let t48=clamp3(((point7.x-a10.x)*abX+(point7.y-a10.y)*abY)/lengthSquared,0,1);return Math.hypot(point7.x-(a10.x+t48*abX),point7.y-(a10.y+t48*abY))},cross4=(a10,b10,c10)=>(b10.x-a10.x)*(c10.y-a10.y)-(b10.y-a10.y)*(c10.x-a10.x),isPointOnSegment2=(point7,a10,b10)=>Math.abs(cross4(a10,b10,point7))>EPSILON2?!1:point7.x>=Math.min(a10.x,b10.x)-EPSILON2&&point7.x<=Math.max(a10.x,b10.x)+EPSILON2&&point7.y>=Math.min(a10.y,b10.y)-EPSILON2&&point7.y<=Math.max(a10.y,b10.y)+EPSILON2,segmentsIntersect=(a12,a22,b12,b22)=>{let c12=cross4(a12,a22,b12),c22=cross4(a12,a22,b22),c32=cross4(b12,b22,a12),c42=cross4(b12,b22,a22);return(c12>EPSILON2&&c22<-EPSILON2||c12<-EPSILON2&&c22>EPSILON2)&&(c32>EPSILON2&&c42<-EPSILON2||c32<-EPSILON2&&c42>EPSILON2)?!0:isPointOnSegment2(b12,a12,a22)||isPointOnSegment2(b22,a12,a22)||isPointOnSegment2(a12,b12,b22)||isPointOnSegment2(a22,b12,b22)},getPolygonEdges2=polygon2=>{let edges=[];if(polygon2.points.length<2)return edges;for(let i11=0;i11<polygon2.points.length;i11+=1){let a10=polygon2.points[i11],b10=polygon2.points[(i11+1)%polygon2.points.length];!a10||!b10||edges.push([a10,b10])}return edges},isPointInPolygon=(point7,polygon2)=>{for(let[a10,b10]of getPolygonEdges2(polygon2))if(isPointOnSegment2(point7,a10,b10))return!0;let inside3=!1;for(let i11=0,j11=polygon2.points.length-1;i11<polygon2.points.length;j11=i11++){let pi3=polygon2.points[i11],pj2=polygon2.points[j11];if(!pi3||!pj2)continue;pi3.y>point7.y!=pj2.y>point7.y&&point7.x<(pj2.x-pi3.x)*(point7.y-pi3.y)/(pj2.y-pi3.y)+pi3.x&&(inside3=!inside3)}return inside3},distanceBetweenCircleAndCircle=(a10,b10)=>Math.max(0,Math.hypot(a10.x-b10.x,a10.y-b10.y)-a10.radius-b10.radius),distanceBetweenPolygonAndPolygon=(a10,b10)=>{if(a10.points.length<3||b10.points.length<3)return Number.POSITIVE_INFINITY;for(let[a12,a22]of getPolygonEdges2(a10))for(let[b12,b22]of getPolygonEdges2(b10))if(segmentsIntersect(a12,a22,b12,b22))return 0;let aPoint=a10.points[0],bPoint=b10.points[0];if(aPoint&&isPointInPolygon(aPoint,b10)||bPoint&&isPointInPolygon(bPoint,a10))return 0;let minDistance=Number.POSITIVE_INFINITY;for(let[a12,a22]of getPolygonEdges2(a10))for(let[b12,b22]of getPolygonEdges2(b10))minDistance=Math.min(minDistance,distanceBetweenPointAndSegment(a12,b12,b22),distanceBetweenPointAndSegment(a22,b12,b22),distanceBetweenPointAndSegment(b12,a12,a22),distanceBetweenPointAndSegment(b22,a12,a22));return minDistance},distanceBetweenCircleAndPolygon=(circle3,polygon2)=>{if(polygon2.points.length<3)return Number.POSITIVE_INFINITY;if(isPointInPolygon({x:circle3.x,y:circle3.y},polygon2))return 0;let minDistanceToEdge=Number.POSITIVE_INFINITY;for(let[start,end]of getPolygonEdges2(polygon2))minDistanceToEdge=Math.min(minDistanceToEdge,distanceBetweenPointAndSegment({x:circle3.x,y:circle3.y},start,end));return Math.max(0,minDistanceToEdge-circle3.radius)},PIN1_LOCATION_PARTS={leftside_top:{side:"leftside",alignment:"top"},leftside_bottom:{side:"leftside",alignment:"bottom"},rightside_top:{side:"rightside",alignment:"top"},rightside_bottom:{side:"rightside",alignment:"bottom"},topside_left:{side:"topside",alignment:"left"},topside_right:{side:"topside",alignment:"right"},bottomside_left:{side:"bottomside",alignment:"left"},bottomside_right:{side:"bottomside",alignment:"right"}},PIN1_LOCATIONS=Object.keys(PIN1_LOCATION_PARTS),getPadCenter2=pad2=>{if(typeof pad2.x=="number"&&typeof pad2.y=="number")return{x:pad2.x,y:pad2.y};if(pad2.points&&pad2.points.length>0){let xs3=pad2.points.map(point7=>point7.x),ys3=pad2.points.map(point7=>point7.y);return{x:(Math.min(...xs3)+Math.max(...xs3))/2,y:(Math.min(...ys3)+Math.max(...ys3))/2}}return null},getPinNumber=pad2=>{for(let hint of pad2.port_hints??[]){let match2=String(hint).trim().match(/^(?:pin)?(\d+)$/i);if(match2)return Number.parseInt(match2[1],10)}return null},getCanonicalRowLocation=(pin1,pin2,tolerance)=>{let dx4=pin2.x-pin1.x,dy4=pin2.y-pin1.y;return Math.abs(dy4)<=tolerance&&Math.abs(dx4)>tolerance?dx4>0?"topside_left":"bottomside_right":Math.abs(dx4)<=tolerance&&Math.abs(dy4)>tolerance?dy4>0?"leftside_bottom":"rightside_top":null},pinMatchesLocation2=(padCenters,pin1Center,pin1Location)=>{let xs3=padCenters.map(point7=>point7.x),ys3=padCenters.map(point7=>point7.y),minX=Math.min(...xs3),maxX=Math.max(...xs3),minY=Math.min(...ys3),maxY=Math.max(...ys3),centerX=(minX+maxX)/2,centerY=(minY+maxY)/2,spanX=maxX-minX,spanY=maxY-minY,tolerance=Math.max(spanX,spanY,1)*1e-6,{side,alignment}=PIN1_LOCATION_PARTS[pin1Location],onRequestedSide=side==="leftside"&&Math.abs(pin1Center.x-minX)<=tolerance||side==="rightside"&&Math.abs(pin1Center.x-maxX)<=tolerance||side==="topside"&&Math.abs(pin1Center.y-maxY)<=tolerance||side==="bottomside"&&Math.abs(pin1Center.y-minY)<=tolerance,atRequestedAlignment=alignment==="left"&&(spanX<=tolerance||pin1Center.x<centerX-tolerance)||alignment==="right"&&(spanX<=tolerance||pin1Center.x>centerX+tolerance)||alignment==="top"&&(spanY<=tolerance||pin1Center.y>centerY+tolerance)||alignment==="bottom"&&(spanY<=tolerance||pin1Center.y<centerY-tolerance);return onRequestedSide&&atRequestedAlignment},analyzePcbPin1Location=elements=>{let numberedPads=elements.filter(element=>element.type==="pcb_smtpad"||element.type==="pcb_plated_hole").map(pad2=>({center:getPadCenter2(pad2),pinNumber:getPinNumber(pad2)})),pin1Center=numberedPads.find(pad2=>pad2.pinNumber===1)?.center,padCenters=numberedPads.map(pad2=>pad2.center).filter(point7=>point7!==null);if(!pin1Center||padCenters.length===0)return null;let candidates=PIN1_LOCATIONS.filter(pin1Location=>pinMatchesLocation2(padCenters,pin1Center,pin1Location));if(candidates.length===1)return candidates[0];if(candidates.length===0)return null;let nextNumberedPad;for(let pad2 of numberedPads)!pad2.center||pad2.pinNumber===null||pad2.pinNumber<=1||(!nextNumberedPad||pad2.pinNumber<nextNumberedPad.pinNumber)&&(nextNumberedPad={center:pad2.center,pinNumber:pad2.pinNumber});if(!nextNumberedPad)return null;let xs3=padCenters.map(point7=>point7.x),ys3=padCenters.map(point7=>point7.y),tolerance=Math.max(Math.max(...xs3)-Math.min(...xs3),Math.max(...ys3)-Math.min(...ys3),1)*1e-6;if(numberedPads.length===2&&nextNumberedPad.pinNumber===2)return getCanonicalRowLocation(pin1Center,nextNumberedPad.center,tolerance);if(numberedPads.length>2){let row=[...numberedPads].sort((a10,b10)=>(a10.pinNumber??Number.POSITIVE_INFINITY)-(b10.pinNumber??Number.POSITIVE_INFINITY));if(row.every(({center:center2,pinNumber},index2)=>pinNumber===index2+1&&center2!==null&&Number.isFinite(center2.x)&&Number.isFinite(center2.y))){let first=row[0].center,last=row[row.length-1].center,dx4=last.x-first.x,dy4=last.y-first.y,horizontal=Math.abs(dy4)<=tolerance&&Math.abs(dx4)>tolerance,vertical=Math.abs(dx4)<=tolerance&&Math.abs(dy4)>tolerance;if((horizontal||vertical)&&row.slice(1).every(({center:center2},index2)=>{let previous=row[index2].center;return horizontal?Math.abs(center2.y-first.y)<=tolerance&&(center2.x-previous.x)*Math.sign(dx4)>tolerance:Math.abs(center2.x-first.x)<=tolerance&&(center2.y-previous.y)*Math.sign(dy4)>tolerance}))return getCanonicalRowLocation(first,row[1].center,tolerance)}}let topologyCandidates=candidates.filter(pin1Location=>{let{side}=PIN1_LOCATION_PARTS[pin1Location];return side==="leftside"||side==="rightside"?Math.abs(nextNumberedPad.center.x-pin1Center.x)<=tolerance:Math.abs(nextNumberedPad.center.y-pin1Center.y)<=tolerance});return topologyCandidates.length===1?topologyCandidates[0]:null},placePolygon=(polygon2,center2,degrees3=0)=>{let{a:a10,b:b10,c:c10,d:d11,e:e55,f:f3}=compose(translate(center2.x,center2.y),rotate(degrees3*Math.PI/180));return polygon2.transform(new Matrix(a10,b10,c10,d11,e55,f3))},ccw=polygon2=>polygon2.orientation()===ORIENTATION.CCW?polygon2:polygon2.reverse(),circlePolygon=(center2,radius)=>ccw(new Polygon$1(new Circle$1(new Point$2(center2.x,center2.y),radius))),roundedRectangle=(center2,width,height,radius=0,degrees3=0)=>{let x11=width/2,y11=height/2,r11=Math.max(0,Math.min(radius,x11,y11));if(r11===0)return placePolygon(ccw(new Polygon$1(new Box(-x11,-y11,x11,y11))),center2,degrees3);let arcs=[new Arc(new Point$2(x11-r11,-y11+r11),r11,-Math.PI/2,0,!0),new Arc(new Point$2(x11-r11,y11-r11),r11,0,Math.PI/2,!0),new Arc(new Point$2(-x11+r11,y11-r11),r11,Math.PI/2,Math.PI,!0),new Arc(new Point$2(-x11+r11,-y11+r11),r11,Math.PI,Math.PI*1.5,!0)],edges=[];for(let i11=0;i11<arcs.length;i11++){let arc2=arcs[i11],next2=arcs[(i11+1)%arcs.length];edges.push(arc2),arc2.end.distanceTo(next2.start)[0]>1e-12&&edges.push(new Segment$1(arc2.end,next2.start))}return placePolygon(ccw(new Polygon$1(edges)),center2,degrees3)},ringPolygon=ring4=>{let edges=[];for(let i11=0;i11<ring4.vertices.length;i11++){let start=ring4.vertices[i11],end=ring4.vertices[(i11+1)%ring4.vertices.length],dx4=end.x-start.x,dy4=end.y-start.y;if(dx4===0&&dy4===0)continue;let bulge=start.bulge??0;if(bulge===0)edges.push(new Segment$1(new Point$2(start.x,start.y),new Point$2(end.x,end.y)));else{let offset2=(1-bulge*bulge)/(4*bulge),center2=new Point$2((start.x+end.x)/2-dy4*offset2,(start.y+end.y)/2+dx4*offset2);edges.push(new Arc(center2,Math.hypot(dx4,dy4)*(1+bulge*bulge)/(4*Math.abs(bulge)),Math.atan2(start.y-center2.y,start.x-center2.x),Math.atan2(end.y-center2.y,end.x-center2.x),bulge>0))}}return ccw(new Polygon$1(edges))},subtractHole=(outer,hole)=>{for(let face of hole.reverse().faces)outer.addFace(face.shapes);return outer},getPourPolygon=pour=>{if(pour.shape==="rect")return roundedRectangle(pour.center,pour.width,pour.height,0,pour.rotation);if(pour.shape==="polygon")return ccw(new Polygon$1(pour.points.map(p11=>new Point$2(p11.x,p11.y))));let polygon2=ringPolygon(pour.brep_shape.outer_ring);for(let ring4 of pour.brep_shape.inner_rings)subtractHole(polygon2,ringPolygon(ring4));return polygon2},getSmtPadPolygon=pad2=>{if(pad2.shape==="polygon")return ccw(new Polygon$1(pad2.points.map(p11=>new Point$2(p11.x,p11.y))));if(pad2.shape==="circle")return circlePolygon(pad2,pad2.radius);let radius=pad2.shape==="pill"||pad2.shape==="rotated_pill"?pad2.radius:pad2.corner_radius??pad2.rect_border_radius??0;return roundedRectangle(pad2,pad2.width,pad2.height,radius,"ccw_rotation"in pad2?pad2.ccw_rotation:0)},getViaPolygon=(center2,outerDiameter,holeDiameter)=>subtractHole(circlePolygon(center2,outerDiameter/2),circlePolygon(center2,holeDiameter/2)),getPlatedHolePolygon=(pad2,componentRotation=0)=>{if(pad2.shape==="circle")return getViaPolygon(pad2,pad2.outer_diameter,pad2.hole_diameter);if("outer_width"in pad2)return subtractHole(roundedRectangle(pad2,pad2.outer_width,pad2.outer_height,Math.min(pad2.outer_width,pad2.outer_height)/2,pad2.ccw_rotation),roundedRectangle(pad2,pad2.hole_width,pad2.hole_height,Math.min(pad2.hole_width,pad2.hole_height)/2,pad2.ccw_rotation));let center2={x:pad2.x+pad2.hole_offset_x,y:pad2.y+pad2.hole_offset_y},outer=pad2.shape==="hole_with_polygon_pad"?placePolygon(ccw(new Polygon$1(pad2.pad_outline.map(p11=>new Point$2(p11.x,p11.y)))),pad2,pad2.ccw_rotation??componentRotation):roundedRectangle(pad2,pad2.rect_pad_width,pad2.rect_pad_height,pad2.rect_border_radius,"rect_ccw_rotation"in pad2?pad2.rect_ccw_rotation:0);if(pad2.shape==="circular_hole_with_rect_pad"||pad2.shape==="hole_with_polygon_pad"&&pad2.hole_shape==="circle"){if(pad2.hole_diameter===void 0)throw new Error("Circular plated hole requires hole_diameter");return subtractHole(outer,circlePolygon(center2,pad2.hole_diameter/2))}if(!("hole_width"in pad2)||pad2.hole_width===void 0||pad2.hole_height===void 0)throw new Error("Slotted plated hole requires hole_width and hole_height");return subtractHole(outer,roundedRectangle(center2,pad2.hole_width,pad2.hole_height,Math.min(pad2.hole_width,pad2.hole_height)/2,"hole_ccw_rotation"in pad2?pad2.hole_ccw_rotation:pad2.shape==="hole_with_polygon_pad"?pad2.ccw_rotation??componentRotation:0))},getTraceSegmentPolygon=(start,end,startWidth,endWidth=startWidth)=>{let length14=Math.hypot(end.x-start.x,end.y-start.y),r12=startWidth/2,r22=endWidth/2;if(Utils$1.EQ_0(length14)||length14<=Math.abs(r22-r12))return circlePolygon(r12>=r22?start:end,Math.max(r12,r22));let angle3=Math.atan2(end.y-start.y,end.x-start.x),tangent=Math.acos((r12-r22)/length14),first=new Arc(new Point$2(start.x,start.y),r12,angle3+tangent,angle3-tangent,!0),second=new Arc(new Point$2(end.x,end.y),r22,angle3-tangent,angle3+tangent,!0);return ccw(new Polygon$1([first,new Segment$1(first.end,second.start),second,new Segment$1(second.end,first.start)]))},copperPolygonsTouch=(a10,b10,tolerance=1e-7)=>a10.vertices.some(p11=>b10.contains(p11))||b10.vertices.some(p11=>a10.contains(p11))||a10.distanceTo(b10)[0]<=tolerance}});var svgAlphabet,lineAlphabet,strokeWidthRatio,glyphWidthRatio,spaceWidthRatio,lineHeightRatio,letterSpacingRatio,glyphAdvanceRatio,textMetrics,init_dist8=__esm({"node_modules/@tscircuit/alphabet/dist/index.js"(){"use strict";svgAlphabet={0:"M0.301025 0.257813 L0.206593 0.283385 L0.122042 0.361307 L0.075923 0.474441 L0.064942 0.642221 L0.091296 0.78289 L0.159376 0.899463 L0.257104 0.961214 L0.344948 0.961214 L0.442678 0.899463 L0.510757 0.78289 L0.537111 0.642221 L0.526131 0.474441 L0.480012 0.361307 L0.39546 0.283385 L0.301025 0.257813",1:"M0.220426 0.40845 L0.381626 0.270996 L0.381626 0.948966",2:"M0.110409 0.39212 L0.125621 0.342293 L0.170571 0.295823 L0.244237 0.26431 L0.291518 0.257813 L0.373319 0.263799 L0.434683 0.290705 L0.468239 0.331966 L0.480292 0.379913 L0.479492 0.411806 L0.465088 0.465192 L0.402571 0.568988 L0.245134 0.766438 L0.07959 0.948045 L0.522462 0.948045",3:"M0.081606 0.345073 L0.119154 0.315633 L0.178996 0.284091 L0.255265 0.257813 L0.349133 0.263062 L0.43127 0.289348 L0.48994 0.336662 L0.525141 0.394491 L0.513407 0.457577 L0.466472 0.504892 L0.384334 0.541692 L0.290464 0.56272 L0.20833 0.573235 L0.290464 0.583749 L0.384334 0.610035 L0.466472 0.652092 L0.519274 0.709922 L0.531007 0.773007 L0.50754 0.841351 L0.454738 0.899179 L0.3726 0.946494 L0.310412 0.961214 L0.209503 0.959111 L0.127367 0.946494 L0.071046 0.929671",4:"M0.418494 0.270996 L0.048828 0.724199 L0.553224 0.724199 M0.414181 0.578167 L0.414181 0.94897",5:"M0.074951 0.270996 L0.074951 0.614701 L0.267655 0.5695 L0.405247 0.586502 L0.460002 0.617189 L0.498028 0.660731 L0.527101 0.779401 L0.513352 0.841049 L0.477274 0.889568 L0.406378 0.93463 L0.324445 0.958337 L0.247399 0.962139 L0.182516 0.949767 L0.130068 0.925508 L0.074951 0.875607 M0.074951 0.270996 L0.527101 0.270996",6:"M0.428549 0.257813 L0.341433 0.285053 L0.26073 0.312099 L0.192188 0.360182 L0.138902 0.410969 L0.098219 0.500422 L0.070249 0.584267 L0.067264 0.670716 L0.065164 0.756863 L0.087163 0.820973 L0.108168 0.861042 L0.157916 0.913131 L0.210981 0.948192 L0.29279 0.961214 L0.384548 0.956206 L0.456409 0.924151 L0.507262 0.881077 L0.5349 0.821975 L0.537111 0.771889 L0.521634 0.718798 L0.498418 0.67372 L0.463042 0.636657 L0.414398 0.613617 L0.34696 0.598591 L0.28284 0.595587 L0.215403 0.605604 L0.145756 0.641665 L0.109274 0.678729 L0.064942 0.724006",7:"M0.071534 0.270996 L0.530519 0.270996 L0.495935 0.291702 L0.477752 0.305407 L0.435186 0.346112 L0.412067 0.374136 L0.388565 0.40796 L0.365315 0.448098 L0.342943 0.495062 L0.322081 0.549366 L0.303364 0.611524 L0.287416 0.68205 L0.270077 0.80465 L0.26253 0.94897",8:"M0.286761 0.257813 L0.210684 0.27162 L0.1414 0.305622 L0.092494 0.382125 L0.111513 0.450128 L0.16857 0.502193 L0.228345 0.539382 L0.377781 0.594635 L0.470161 0.645637 L0.52586 0.706203 L0.538087 0.792269 L0.506841 0.87621 L0.438915 0.927212 L0.339743 0.961214 L0.263666 0.959089 L0.174004 0.929337 L0.102003 0.881523 L0.063965 0.811395 L0.066682 0.741266 L0.102003 0.671139 L0.180797 0.608448 L0.259591 0.580822 L0.358762 0.548945 L0.456576 0.49688 L0.486463 0.446941 L0.487822 0.362999 L0.453859 0.302434 L0.384574 0.265245 L0.286761 0.257813",9:"M0.511026 0.437812 L0.491026 0.347812 L0.451026 0.297812 L0.391026 0.267812 L0.311026 0.257813 L0.231026 0.267812 L0.161026 0.297812 L0.111026 0.347812 L0.091026 0.417812 L0.111026 0.487812 L0.161026 0.537812 L0.231026 0.567812 L0.311026 0.577812 L0.391026 0.557812 L0.451026 0.517812 L0.491026 0.477812 L0.511026 0.437812 M0.510026 0.438812 L0.434026 0.636812 L0.381026 0.777812 L0.337026 0.879812 L0.301026 0.957812","!":"M0.301026 0.270996 L0.301026 0.749566 M0.251466 0.94897 L0.350587 0.94897",'"':"M0.16504 0.270996 L0.16504 0.523022 M0.437013 0.270996 L0.437013 0.523022","#":"M0.20958 0.282227 L0.146515 0.949754 M0.461844 0.282227 L0.398779 0.949754 M0.032999 0.526969 L0.600587 0.452796 M0.001465 0.82366 L0.569055 0.749486",$:"M0.307121 0.240234 L0.307121 1.083502 M0.490031 0.415915 L0.404676 0.328075 L0.23396 0.310507 L0.136407 0.398347 L0.099828 0.521324 L0.124213 0.591596 L0.197379 0.644299 L0.429061 0.697003 L0.502224 0.749708 L0.526613 0.837547 L0.477836 0.960526 L0.355897 1.013228 L0.197379 0.99566 L0.112021 0.942957 L0.07544 0.837547","'":"M0.301026 0.270996 L0.301026 0.523022","(":"M0.413087 0.241211 L0.372337 0.28347 L0.331589 0.334184 L0.290838 0.393349 L0.25009 0.460965 L0.219528 0.528584 L0.199153 0.5962 L0.188966 0.655364 L0.199153 0.714529 L0.219528 0.782146 L0.25009 0.849764 L0.290838 0.91738 L0.331589 0.976544 L0.372337 1.027258 L0.413087 1.069491",")":"M0.188966 0.241211 L0.229716 0.28347 L0.270466 0.334184 L0.311213 0.393349 L0.351964 0.460965 L0.382526 0.528584 L0.4029 0.5962 L0.413087 0.655364 L0.4029 0.714529 L0.382526 0.782146 L0.351964 0.849764 L0.311213 0.91738 L0.270466 0.976544 L0.229716 1.027258 L0.188966 1.069491","*":"M0.301026 0.458702 L0.301026 0.681942 M0.301026 0.458702 L0.520997 0.536834 M0.301026 0.458702 L0.439954 0.257813 M0.301026 0.458702 L0.162098 0.257813 M0.301026 0.458702 L0.081055 0.536834","+":"M0.042969 0.66845 L0.559083 0.66845 M0.301023 0.428223 L0.301023 0.908661",",":"M0.38672 0.852051 L0.215333 1.030661 L0.301025 1.119971","-":"M0.173829 0.686035 L0.428224 0.686035",".":"M0.362549 0.851074 L0.239503 0.851074","/":"M0.062501 1.035249 L0.539551 0.270996","<":"M0.559083 0.441895 L0.042969 0.66939 L0.042969 0.66939 L0.559083 0.896902","=":"M0.042969 0.545898 L0.559083 0.545898 M0.042969 0.80837 L0.559083 0.80837",">":"M0.042969 0.441895 L0.559083 0.66939 L0.559083 0.66939 L0.042969 0.896902",A:"M0.018067 0.94897 L0.290179 0.270996 L0.583986 0.94897 M0.155303 0.684521 L0.433548 0.684521",B:"M0.063965 0.94897 L0.063965 0.278953 L0.209356 0.270996 L0.342486 0.294394 L0.432179 0.37292 L0.418224 0.48773 L0.312686 0.549166 L0.084728 0.575531 L0.306377 0.589434 L0.468877 0.647456 L0.538087 0.736658 L0.5324 0.85202 L0.501247 0.902983 L0.42355 0.944398 L0.063965 0.94897",C:"M0.529054 0.419847 L0.498425 0.345196 L0.442238 0.292341 L0.33583 0.257813 L0.257199 0.268357 L0.187906 0.303748 L0.120243 0.385432 L0.072998 0.599844 L0.110073 0.815385 L0.165381 0.902183 L0.222883 0.942801 L0.334904 0.961214 L0.43253 0.937679 L0.504816 0.868999 L0.529054 0.772065",D:"M0.064454 0.94897 L0.071838 0.285078 L0.171217 0.270996 L0.247348 0.272633 L0.37101 0.306078 L0.462461 0.378304 L0.514748 0.475555 L0.535591 0.576392 L0.537599 0.652313 L0.528065 0.717381 L0.508562 0.772419 L0.445948 0.855695 L0.362356 0.90871 L0.225203 0.945862 L0.064454 0.94897",E:"M0.080078 0.270996 L0.080078 0.94897 M0.080078 0.270996 L0.521974 0.270996 M0.080078 0.609981 L0.389405 0.609981 M0.080078 0.94897 L0.521974 0.94897",F:"M0.086426 0.270996 L0.086426 0.94897 M0.091304 0.275607 L0.515626 0.275607 M0.091304 0.607677 L0.447344 0.607677",G:"M0.498034 0.284943 L0.374621 0.257813 L0.244219 0.268648 L0.160577 0.311997 L0.094556 0.398116 L0.056397 0.58404 L0.076752 0.785532 L0.120865 0.858197 L0.188947 0.916734 L0.271008 0.953591 L0.357069 0.961214 L0.43715 0.932047 L0.501262 0.858539 L0.545656 0.648611 L0.329595 0.648131",H:"M0.066895 0.270996 L0.066895 0.94897 M0.066895 0.595658 L0.530009 0.595658 M0.535157 0.270996 L0.535157 0.94897",I:"M0.301026 0.270996 L0.301026 0.94897",J:"M0.506839 0.270996 L0.507814 0.782193 L0.498468 0.846168 L0.480733 0.880789 L0.455864 0.90832 L0.426095 0.929408 L0.360746 0.954812 L0.302508 0.962139 L0.223573 0.953638 L0.16538 0.930312 L0.137072 0.907715 L0.116428 0.880312 L0.102822 0.848819 L0.095633 0.813947 L0.094239 0.776413",K:"M0.035401 0.270996 L0.035401 0.94897 M0.502258 0.316194 L0.035401 0.687823 M0.212484 0.582361 L0.566652 0.933903",L:"M0.07544 0.270996 L0.07544 0.94897 L0.526613 0.94897",M:"M0.042481 0.94897 L0.042481 0.270996 L0.301027 0.712492 L0.559571 0.270996 L0.559571 0.94897",N:"M0.067871 0.94897 L0.067871 0.270996 L0.534181 0.94897 L0.525031 0.270996",O:"M0.287293 0.961214 L0.19843 0.933567 L0.1172 0.849451 L0.057129 0.563945 L0.114348 0.350255 L0.18455 0.289392 L0.306101 0.257813 L0.42054 0.29572 L0.487543 0.365003 L0.544923 0.625294 L0.516366 0.789624 L0.465476 0.884596 L0.375084 0.949287 L0.287293 0.961214",P:"M0.070557 0.94897 L0.070557 0.28379 L0.20704 0.270996 L0.329134 0.278993 L0.408525 0.300514 L0.444022 0.317908 L0.500637 0.368929 L0.525796 0.423728 L0.531496 0.50384 L0.508934 0.554205 L0.473724 0.582043 L0.417577 0.604365 L0.336375 0.620372 L0.226014 0.629268 L0.082368 0.630258",Q:"M0.282435 1.050813 L0.195447 1.019646 L0.115933 0.924817 L0.057129 0.602943 L0.113139 0.362034 L0.18186 0.293418 L0.300844 0.257813 L0.412868 0.300553 L0.478457 0.37866 L0.534625 0.672103 L0.506671 0.857367 L0.456855 0.964437 L0.368371 1.037368 L0.282435 1.050813 M0.341225 0.815559 L0.544923 1.070653",R:"M0.034912 0.944112 L0.034912 0.288556 L0.227127 0.270996 L0.362038 0.276867 L0.443423 0.294907 L0.477644 0.309614 L0.505809 0.328757 L0.526616 0.352817 L0.544963 0.418061 L0.543241 0.475921 L0.524463 0.517817 L0.49076 0.546518 L0.444265 0.564799 L0.355195 0.578739 L0.047653 0.589627 M0.303054 0.617306 L0.56714 0.94897",S:"M0.483037 0.364333 L0.407613 0.267477 L0.22883 0.257813 L0.128623 0.327565 L0.087712 0.455539 L0.104656 0.518727 L0.168054 0.573307 L0.41928 0.617318 L0.503796 0.669342 L0.535157 0.759324 L0.493846 0.900055 L0.367668 0.961214 L0.205436 0.956661 L0.116711 0.907038 L0.066895 0.790334",T:"M0.022949 0.270996 L0.579103 0.270996 M0.309284 0.270996 L0.309284 0.94897",U:"M0.072022 0.270996 L0.07308 0.648875 L0.080372 0.75167 L0.099024 0.827813 L0.134786 0.885729 L0.181571 0.924023 L0.251464 0.95168 L0.339655 0.962139 L0.401553 0.951668 L0.45232 0.924086 L0.482701 0.891771 L0.495745 0.870529 L0.515699 0.81637 L0.525014 0.744626 L0.530031 0.272017",V:"M0.027832 0.270996 L0.320083 0.94897 L0.57422 0.270996",W:"M0 0.270996 L0.079799 0.940377 L0.285198 0.472884 L0.505255 0.94897 L0.602052 0.270996",X:"M0.009034 0.270996 L0.586805 0.94897 M0.593019 0.270996 L0.015246 0.94897",Y:"M0.018067 0.270996 L0.293132 0.574135 M0.583986 0.271959 L0.294954 0.57606 L0.305277 0.94897",Z:"M0.053711 0.270996 L0.548341 0.270996 L0.053711 0.94897 L0.548341 0.94897","[":"M0.404542 0.240234 L0.197511 0.240234 L0.197511 1.069424 L0.404542 1.069424","\\":"M0.062501 0.270996 L0.539551 1.035249","]":"M0.19751 0.240234 L0.404542 0.240234 L0.404542 1.069424 L0.19751 1.069424","^":"M0.035156 0.523931 L0.301024 0.270996 L0.566896 0.523931",_:"M0 1.160601 L0.602052 1.160601",a:"M0.527101 0.439941 L0.527101 0.973965 M0.527101 0.553824 L0.451366 0.477535 L0.376759 0.439941 L0.263722 0.439941 L0.187989 0.477535 L0.112255 0.553824 L0.074951 0.66881 L0.074951 0.745099 L0.112255 0.85898 L0.187989 0.93527 L0.263722 0.973965 L0.376759 0.973965 L0.451366 0.93527 L0.527101 0.85898",b:"M0.07666 0.240234 L0.07666 0.959985 M0.07666 0.582737 L0.151822 0.514237 L0.225865 0.480483 L0.338045 0.480483 L0.413211 0.514237 L0.488374 0.582737 L0.525392 0.685983 L0.525392 0.754485 L0.488374 0.856739 L0.413211 0.92524 L0.338045 0.959985 L0.225865 0.959985 L0.151822 0.92524 L0.07666 0.856739",c:"M0.512452 0.553823 L0.441624 0.477535 L0.371854 0.439941 L0.26614 0.439941 L0.195312 0.477535 L0.124486 0.553823 L0.0896 0.668808 L0.0896 0.745099 L0.124486 0.858979 L0.195312 0.93527 L0.26614 0.973965 L0.371854 0.973965 L0.441624 0.93527 L0.512452 0.858979",d:"M0.525392 0.240234 L0.525392 0.959985 M0.525392 0.582737 L0.450232 0.514237 L0.376189 0.480483 L0.264006 0.480483 L0.188844 0.514237 L0.11368 0.582737 L0.076661 0.685983 L0.076661 0.754485 L0.11368 0.856739 L0.188844 0.92524 L0.264006 0.959985 L0.376189 0.959985 L0.450232 0.92524 L0.525392 0.856739",e:"M0.059571 0.668808 L0.542482 0.668808 M0.542482 0.592521 L0.502641 0.516231 L0.461594 0.477535 L0.381914 0.439941 L0.261186 0.439941 L0.180299 0.477535 L0.099412 0.553823 L0.059571 0.668808 L0.059571 0.745099 L0.099412 0.858979 L0.180299 0.93527 L0.261186 0.973965 L0.381914 0.973965 L0.461594 0.93527 L0.542482 0.858979",f:"M0.512941 0.240234 L0.406984 0.240234 L0.301026 0.274346 L0.248047 0.374731 L0.248047 0.946817 M0.089112 0.476088 L0.459965 0.476088",g:"M0.525392 0.439941 L0.525392 0.989395 L0.488373 1.091918 L0.45023 1.126757 L0.376189 1.160601 L0.264004 1.160601 L0.188844 1.126757 L0.113681 1.058075 L0.076661 0.954555 M0.525392 0.542467 L0.45023 0.473786 L0.376189 0.439941 L0.264004 0.439941 L0.188844 0.473786 L0.113681 0.542467 L0.076661 0.645988 L0.076661 0.714669 L0.113681 0.817193 L0.188844 0.885875 L0.264004 0.920713 L0.376189 0.920713 L0.45023 0.885875 L0.525392 0.817193",h:"M0.092041 0.240234 L0.092041 0.946817 M0.092041 0.61058 L0.205937 0.509225 L0.282214 0.476086 L0.396109 0.476086 L0.47187 0.509225 L0.510011 0.61058 L0.510011 0.946817",i:"M0.261026 0.240234 L0.341026 0.240234 M0.300978 0.476089 L0.300978 0.946817",j:"M0.3853 0.240234 L0.447023 0.240234 M0.416159 0.465708 L0.416159 1.011689 L0.383887 1.108586 L0.252832 1.140264 L0.15503 1.108586",k:"M0.065186 0.240234 L0.065186 0.946817 M0.493824 0.476086 L0.065186 0.812323 M0.236758 0.677829 L0.536867 0.946817",l:"M0.301026 0.234863 L0.301026 0.946441",m:"M0.050538 0.439941 L0.050538 0.960796 M0.050538 0.588758 L0.114405 0.476607 L0.157178 0.439941 L0.236864 0.439941 L0.279637 0.476607 L0.32241 0.588758 L0.32241 0.960796 M0.32241 0.588758 L0.386281 0.476607 L0.428467 0.439941 L0.50874 0.439941 L0.551515 0.476607 L0.551515 0.960796",n:"M0.092041 0.439941 L0.092041 0.960796 M0.092041 0.588758 L0.205936 0.476607 L0.282216 0.439941 L0.396113 0.439941 L0.471871 0.476607 L0.510011 0.588758 L0.510011 0.960796",o:"M0.247175 0.439941 L0.175178 0.477535 L0.103186 0.553823 L0.066895 0.668808 L0.066895 0.745099 L0.103186 0.858979 L0.175178 0.93527 L0.247175 0.973965 L0.354874 0.973965 L0.426872 0.93527 L0.498866 0.858979 L0.535157 0.745099 L0.535157 0.668808 L0.498866 0.553823 L0.426872 0.477535 L0.354874 0.439941 L0.247175 0.439941",p:"M0.076904 0.439941 L0.076904 1.154244 M0.076904 0.541563 L0.151986 0.473487 L0.225944 0.439941 L0.338005 0.439941 L0.413087 0.473487 L0.488166 0.541563 L0.525148 0.644169 L0.525148 0.712246 L0.488166 0.813866 L0.413087 0.881942 L0.338005 0.916471 L0.225944 0.916471 L0.151986 0.881942 L0.076904 0.813866",q:"M0.525148 0.441895 L0.525148 1.156195 M0.525148 0.5435 L0.450067 0.47544 L0.376106 0.441895 L0.264042 0.441895 L0.188966 0.47544 L0.113885 0.5435 L0.076905 0.646108 L0.076905 0.714187 L0.113885 0.815809 L0.188966 0.883886 L0.264042 0.918418 L0.376106 0.918418 L0.450067 0.883886 L0.525148 0.815809",r:"M0.107422 0.439941 L0.107422 0.960796 M0.107422 0.663164 L0.155824 0.551014 L0.252626 0.476607 L0.349428 0.439941 L0.49463 0.439941",s:"M0.475556 0.477535 L0.400757 0.439941 L0.276092 0.439941 L0.176361 0.477535 L0.101563 0.553823 L0.101563 0.630112 L0.176361 0.668808 L0.301024 0.668808 L0.425688 0.745099 L0.50049 0.821387 L0.50049 0.897677 L0.425688 0.93527 L0.325956 0.973965 L0.201295 0.973965 L0.126496 0.93527 L0.101563 0.858979",t:"M0.246032 0.297852 L0.246032 0.826549 L0.301023 0.919323 L0.411011 0.950848 L0.520997 0.950848 M0.081055 0.515799 L0.466004 0.515799",u:"M0.092041 0.454102 L0.092041 0.826134 L0.13018 0.937211 L0.205936 0.974954 L0.319832 0.974954 L0.396113 0.937211 L0.510011 0.826134 M0.510011 0.454102 L0.510011 0.974954",v:"M0.048828 0.453125 L0.301026 0.961719 M0.553224 0.453125 L0.301026 0.961719",w:"M0 0.453125 L0.150512 0.961719 M0.301024 0.453125 L0.150512 0.961719 M0.301024 0.453125 L0.451539 0.961719 M0.602052 0.453125 L0.451539 0.961719",x:"M0.03711 0.453125 L0.564943 0.961719 M0.564943 0.453125 L0.03711 0.961719",y:"M0.084618 0.453125 L0.320232 0.921476 M0.55713 0.453125 L0.320232 0.921476 L0.242119 1.055289 L0.163369 1.122196 L0.084618 1.155166 L0.044922 1.155166",z:"M0.505373 0.452148 L0.09668 0.961651 M0.09668 0.452148 L0.505373 0.452148 M0.09668 0.961651 L0.505373 0.961651"},lineAlphabet={};for(let letter in svgAlphabet){lineAlphabet[letter]=[];let segs=svgAlphabet[letter].split("M").slice(1).map(seg=>seg.split("L").map(pr3=>pr3.trim().split(" ").map(parseFloat)));for(let seg of segs)for(let i11=0;i11<seg.length-1;i11++)lineAlphabet[letter].push({x1:seg[i11][0],y1:1-seg[i11][1],x2:seg[i11+1][0],y2:1-seg[i11+1][1]})}strokeWidthRatio=.09,glyphWidthRatio=.692052,spaceWidthRatio=.692052,lineHeightRatio=1.152,letterSpacingRatio=0,glyphAdvanceRatio={0:.692052,1:.692052,2:.692052,3:.692052,4:.692052,5:.692052,6:.692052,7:.692052,8:.692052,9:.692052,"!":.692052,'"':.692052,"#":.692052,$:.692052,"'":.692052,"(":.692052,")":.692052,"*":.692052,"+":.692052,",":.692052,"-":.692052,".":.692052,"/":.692052,"<":.692052,"=":.692052,">":.692052,A:.692052,B:.692052,C:.692052,D:.692052,E:.692052,F:.692052,G:.692052,H:.692052,I:.692052,J:.692052,K:.692052,L:.692052,M:.692052,N:.692052,O:.692052,P:.692052,Q:.692052,R:.692052,S:.692052,T:.692052,U:.692052,V:.692052,W:.692052,X:.692052,Y:.692052,Z:.692052,"[":.692052,"\\":.692052,"]":.692052,"^":.692052,_:.692052,a:.692052,b:.692052,c:.692052,d:.692052,e:.692052,f:.692052,g:.692052,h:.692052,i:.692052,j:.692052,k:.692052,l:.692052,m:.692052,n:.692052,o:.692052,p:.692052,q:.692052,r:.692052,s:.692052,t:.692052,u:.692052,v:.692052,w:.692052,x:.692052,y:.692052,z:.692052," ":.692052},textMetrics={glyphWidthRatio,spaceWidthRatio,lineHeightRatio,strokeWidthRatio,letterSpacingRatio}}});var require_svgson_umd=__commonJS({"node_modules/svgson/dist/svgson.umd.js"(exports,module){"use strict";(function(global2,factory){typeof exports=="object"&&typeof module<"u"?module.exports=factory():typeof define=="function"&&define.amd?define(factory):(global2=typeof globalThis<"u"?globalThis:global2||self,global2.svgson=factory())})(exports,(function(){"use strict";var isBuffer_1=function(obj){return obj!=null&&(isBuffer(obj)||isSlowBuffer(obj)||!!obj._isBuffer)};function isBuffer(obj){return!!obj.constructor&&typeof obj.constructor.isBuffer=="function"&&obj.constructor.isBuffer(obj)}function isSlowBuffer(obj){return typeof obj.readFloatLE=="function"&&typeof obj.slice=="function"&&isBuffer(obj.slice(0,0))}var toString3=Object.prototype.toString,kindOf=function(val){if(typeof val>"u")return"undefined";if(val===null)return"null";if(val===!0||val===!1||val instanceof Boolean)return"boolean";if(typeof val=="string"||val instanceof String)return"string";if(typeof val=="number"||val instanceof Number)return"number";if(typeof val=="function"||val instanceof Function)return"function";if(typeof Array.isArray<"u"&&Array.isArray(val))return"array";if(val instanceof RegExp)return"regexp";if(val instanceof Date)return"date";var type=toString3.call(val);return type==="[object RegExp]"?"regexp":type==="[object Date]"?"date":type==="[object Arguments]"?"arguments":type==="[object Error]"?"error":isBuffer_1(val)?"buffer":type==="[object Set]"?"set":type==="[object WeakSet]"?"weakset":type==="[object Map]"?"map":type==="[object WeakMap]"?"weakmap":type==="[object Symbol]"?"symbol":type==="[object Int8Array]"?"int8array":type==="[object Uint8Array]"?"uint8array":type==="[object Uint8ClampedArray]"?"uint8clampedarray":type==="[object Int16Array]"?"int16array":type==="[object Uint16Array]"?"uint16array":type==="[object Int32Array]"?"int32array":type==="[object Uint32Array]"?"uint32array":type==="[object Float32Array]"?"float32array":type==="[object Float64Array]"?"float64array":"object"};function createCommonjsModule(fn3,module2){return module2={exports:{}},fn3(module2,module2.exports),module2.exports}var renameKeys=createCommonjsModule(function(module2){(function(){function rename(obj,fn3){if(typeof fn3!="function")return obj;var res2={};for(var key in obj)Object.prototype.hasOwnProperty.call(obj,key)&&(res2[fn3(key,obj[key])||key]=obj[key]);return res2}module2.exports?module2.exports=rename:window.rename=rename})()}),deepRenameKeys=function renameDeep(obj,cb4){var type=kindOf(obj);if(type!=="object"&&type!=="array")throw new Error("expected an object");var res2=[];type==="object"&&(obj=renameKeys(obj,cb4),res2={});for(var key in obj)if(obj.hasOwnProperty(key)){var val=obj[key];kindOf(val)==="object"||kindOf(val)==="array"?res2[key]=renameDeep(val,cb4):res2[key]=val}return res2},eventemitter3=createCommonjsModule(function(module2){var has=Object.prototype.hasOwnProperty,prefix="~";function Events(){}Object.create&&(Events.prototype=Object.create(null),new Events().__proto__||(prefix=!1));function EE3(fn3,context,once){this.fn=fn3,this.context=context,this.once=once||!1}function EventEmitter(){this._events=new Events,this._eventsCount=0}EventEmitter.prototype.eventNames=function(){var names=[],events,name;if(this._eventsCount===0)return names;for(name in events=this._events)has.call(events,name)&&names.push(prefix?name.slice(1):name);return Object.getOwnPropertySymbols?names.concat(Object.getOwnPropertySymbols(events)):names},EventEmitter.prototype.listeners=function(event,exists){var evt=prefix?prefix+event:event,available=this._events[evt];if(exists)return!!available;if(!available)return[];if(available.fn)return[available.fn];for(var i11=0,l10=available.length,ee4=new Array(l10);i11<l10;i11++)ee4[i11]=available[i11].fn;return ee4},EventEmitter.prototype.emit=function(event,a12,a22,a32,a42,a52){var evt=prefix?prefix+event:event;if(!this._events[evt])return!1;var listeners=this._events[evt],len6=arguments.length,args,i11;if(listeners.fn){switch(listeners.once&&this.removeListener(event,listeners.fn,void 0,!0),len6){case 1:return listeners.fn.call(listeners.context),!0;case 2:return listeners.fn.call(listeners.context,a12),!0;case 3:return listeners.fn.call(listeners.context,a12,a22),!0;case 4:return listeners.fn.call(listeners.context,a12,a22,a32),!0;case 5:return listeners.fn.call(listeners.context,a12,a22,a32,a42),!0;case 6:return listeners.fn.call(listeners.context,a12,a22,a32,a42,a52),!0}for(i11=1,args=new Array(len6-1);i11<len6;i11++)args[i11-1]=arguments[i11];listeners.fn.apply(listeners.context,args)}else{var length14=listeners.length,j11;for(i11=0;i11<length14;i11++)switch(listeners[i11].once&&this.removeListener(event,listeners[i11].fn,void 0,!0),len6){case 1:listeners[i11].fn.call(listeners[i11].context);break;case 2:listeners[i11].fn.call(listeners[i11].context,a12);break;case 3:listeners[i11].fn.call(listeners[i11].context,a12,a22);break;case 4:listeners[i11].fn.call(listeners[i11].context,a12,a22,a32);break;default:if(!args)for(j11=1,args=new Array(len6-1);j11<len6;j11++)args[j11-1]=arguments[j11];listeners[i11].fn.apply(listeners[i11].context,args)}}return!0},EventEmitter.prototype.on=function(event,fn3,context){var listener=new EE3(fn3,context||this),evt=prefix?prefix+event:event;return this._events[evt]?this._events[evt].fn?this._events[evt]=[this._events[evt],listener]:this._events[evt].push(listener):(this._events[evt]=listener,this._eventsCount++),this},EventEmitter.prototype.once=function(event,fn3,context){var listener=new EE3(fn3,context||this,!0),evt=prefix?prefix+event:event;return this._events[evt]?this._events[evt].fn?this._events[evt]=[this._events[evt],listener]:this._events[evt].push(listener):(this._events[evt]=listener,this._eventsCount++),this},EventEmitter.prototype.removeListener=function(event,fn3,context,once){var evt=prefix?prefix+event:event;if(!this._events[evt])return this;if(!fn3)return--this._eventsCount===0?this._events=new Events:delete this._events[evt],this;var listeners=this._events[evt];if(listeners.fn)listeners.fn===fn3&&(!once||listeners.once)&&(!context||listeners.context===context)&&(--this._eventsCount===0?this._events=new Events:delete this._events[evt]);else{for(var i11=0,events=[],length14=listeners.length;i11<length14;i11++)(listeners[i11].fn!==fn3||once&&!listeners[i11].once||context&&listeners[i11].context!==context)&&events.push(listeners[i11]);events.length?this._events[evt]=events.length===1?events[0]:events:--this._eventsCount===0?this._events=new Events:delete this._events[evt]}return this},EventEmitter.prototype.removeAllListeners=function(event){var evt;return event?(evt=prefix?prefix+event:event,this._events[evt]&&(--this._eventsCount===0?this._events=new Events:delete this._events[evt])):(this._events=new Events,this._eventsCount=0),this},EventEmitter.prototype.off=EventEmitter.prototype.removeListener,EventEmitter.prototype.addListener=EventEmitter.prototype.on,EventEmitter.prototype.setMaxListeners=function(){return this},EventEmitter.prefixed=prefix,EventEmitter.EventEmitter=EventEmitter,module2.exports=EventEmitter});function _defineProperty(obj,key,value){return key in obj?Object.defineProperty(obj,key,{value,enumerable:!0,configurable:!0,writable:!0}):obj[key]=value,obj}var noop=function(){},State2={data:"state-data",cdata:"state-cdata",tagBegin:"state-tag-begin",tagName:"state-tag-name",tagEnd:"state-tag-end",attributeNameStart:"state-attribute-name-start",attributeName:"state-attribute-name",attributeNameEnd:"state-attribute-name-end",attributeValueBegin:"state-attribute-value-begin",attributeValue:"state-attribute-value"},Action={lt:"action-lt",gt:"action-gt",space:"action-space",equal:"action-equal",quote:"action-quote",slash:"action-slash",char:"action-char",error:"action-error"},Type$1={text:"text",openTag:"open-tag",closeTag:"close-tag",attributeName:"attribute-name",attributeValue:"attribute-value"},charToAction={" ":Action.space," ":Action.space,"\n":Action.space,"\r":Action.space,"<":Action.lt,">":Action.gt,'"':Action.quote,"'":Action.quote,"=":Action.equal,"/":Action.slash},getAction=function(char){return charToAction[char]||Action.char},create$1=function(options){var _State$data,_State$tagBegin,_State$tagName,_State$tagEnd,_State$attributeNameS,_State$attributeName,_State$attributeNameE,_State$attributeValue,_State$attributeValue2,_lexer$stateMachine;options=Object.assign({debug:!1},options);var lexer2=new eventemitter3,state2=State2.data,data="",tagName="",attrName="",attrValue="",isClosing="",openingQuote="",emit=function(type,value){if(!(tagName[0]==="?"||tagName[0]==="!")){var event={type,value};options.debug&&console.log("emit:",event),lexer2.emit("data",event)}};lexer2.stateMachine=(_lexer$stateMachine={},_defineProperty(_lexer$stateMachine,State2.data,(_State$data={},_defineProperty(_State$data,Action.lt,function(){data.trim()&&emit(Type$1.text,data),tagName="",isClosing=!1,state2=State2.tagBegin}),_defineProperty(_State$data,Action.char,function(char){data+=char}),_State$data)),_defineProperty(_lexer$stateMachine,State2.cdata,_defineProperty({},Action.char,function(char){data+=char,data.substr(-3)==="]]>"&&(emit(Type$1.text,data.slice(0,-3)),data="",state2=State2.data)})),_defineProperty(_lexer$stateMachine,State2.tagBegin,(_State$tagBegin={},_defineProperty(_State$tagBegin,Action.space,noop),_defineProperty(_State$tagBegin,Action.char,function(char){tagName=char,state2=State2.tagName}),_defineProperty(_State$tagBegin,Action.slash,function(){tagName="",isClosing=!0}),_State$tagBegin)),_defineProperty(_lexer$stateMachine,State2.tagName,(_State$tagName={},_defineProperty(_State$tagName,Action.space,function(){isClosing?state2=State2.tagEnd:(state2=State2.attributeNameStart,emit(Type$1.openTag,tagName))}),_defineProperty(_State$tagName,Action.gt,function(){emit(isClosing?Type$1.closeTag:Type$1.openTag,tagName),data="",state2=State2.data}),_defineProperty(_State$tagName,Action.slash,function(){state2=State2.tagEnd,emit(Type$1.openTag,tagName)}),_defineProperty(_State$tagName,Action.char,function(char){tagName+=char,tagName==="![CDATA["&&(state2=State2.cdata,data="",tagName="")}),_State$tagName)),_defineProperty(_lexer$stateMachine,State2.tagEnd,(_State$tagEnd={},_defineProperty(_State$tagEnd,Action.gt,function(){emit(Type$1.closeTag,tagName),data="",state2=State2.data}),_defineProperty(_State$tagEnd,Action.char,noop),_State$tagEnd)),_defineProperty(_lexer$stateMachine,State2.attributeNameStart,(_State$attributeNameS={},_defineProperty(_State$attributeNameS,Action.char,function(char){attrName=char,state2=State2.attributeName}),_defineProperty(_State$attributeNameS,Action.gt,function(){data="",state2=State2.data}),_defineProperty(_State$attributeNameS,Action.space,noop),_defineProperty(_State$attributeNameS,Action.slash,function(){isClosing=!0,state2=State2.tagEnd}),_State$attributeNameS)),_defineProperty(_lexer$stateMachine,State2.attributeName,(_State$attributeName={},_defineProperty(_State$attributeName,Action.space,function(){state2=State2.attributeNameEnd}),_defineProperty(_State$attributeName,Action.equal,function(){emit(Type$1.attributeName,attrName),state2=State2.attributeValueBegin}),_defineProperty(_State$attributeName,Action.gt,function(){attrValue="",emit(Type$1.attributeName,attrName),emit(Type$1.attributeValue,attrValue),data="",state2=State2.data}),_defineProperty(_State$attributeName,Action.slash,function(){isClosing=!0,attrValue="",emit(Type$1.attributeName,attrName),emit(Type$1.attributeValue,attrValue),state2=State2.tagEnd}),_defineProperty(_State$attributeName,Action.char,function(char){attrName+=char}),_State$attributeName)),_defineProperty(_lexer$stateMachine,State2.attributeNameEnd,(_State$attributeNameE={},_defineProperty(_State$attributeNameE,Action.space,noop),_defineProperty(_State$attributeNameE,Action.equal,function(){emit(Type$1.attributeName,attrName),state2=State2.attributeValueBegin}),_defineProperty(_State$attributeNameE,Action.gt,function(){attrValue="",emit(Type$1.attributeName,attrName),emit(Type$1.attributeValue,attrValue),data="",state2=State2.data}),_defineProperty(_State$attributeNameE,Action.char,function(char){attrValue="",emit(Type$1.attributeName,attrName),emit(Type$1.attributeValue,attrValue),attrName=char,state2=State2.attributeName}),_State$attributeNameE)),_defineProperty(_lexer$stateMachine,State2.attributeValueBegin,(_State$attributeValue={},_defineProperty(_State$attributeValue,Action.space,noop),_defineProperty(_State$attributeValue,Action.quote,function(char){openingQuote=char,attrValue="",state2=State2.attributeValue}),_defineProperty(_State$attributeValue,Action.gt,function(){attrValue="",emit(Type$1.attributeValue,attrValue),data="",state2=State2.data}),_defineProperty(_State$attributeValue,Action.char,function(char){openingQuote="",attrValue=char,state2=State2.attributeValue}),_State$attributeValue)),_defineProperty(_lexer$stateMachine,State2.attributeValue,(_State$attributeValue2={},_defineProperty(_State$attributeValue2,Action.space,function(char){openingQuote?attrValue+=char:(emit(Type$1.attributeValue,attrValue),state2=State2.attributeNameStart)}),_defineProperty(_State$attributeValue2,Action.quote,function(char){openingQuote===char?(emit(Type$1.attributeValue,attrValue),state2=State2.attributeNameStart):attrValue+=char}),_defineProperty(_State$attributeValue2,Action.gt,function(char){openingQuote?attrValue+=char:(emit(Type$1.attributeValue,attrValue),data="",state2=State2.data)}),_defineProperty(_State$attributeValue2,Action.slash,function(char){openingQuote?attrValue+=char:(emit(Type$1.attributeValue,attrValue),isClosing=!0,state2=State2.tagEnd)}),_defineProperty(_State$attributeValue2,Action.char,function(char){attrValue+=char}),_State$attributeValue2)),_lexer$stateMachine);var step=function(char){options.debug&&console.log(state2,char);var actions=lexer2.stateMachine[state2],action=actions[getAction(char)]||actions[Action.error]||actions[Action.char];action(char)};return lexer2.write=function(str10){for(var len6=str10.length,i11=0;i11<len6;i11++)step(str10[i11])},lexer2},lexer={State:State2,Action,Type:Type$1,create:create$1},Type=lexer.Type,NodeType={element:"element",text:"text"},createNode=function(params){return Object.assign({name:"",type:NodeType.element,value:"",parent:null,attributes:{},children:[]},params)},create10=function(options){options=Object.assign({stream:!1,parentNodes:!0,doneEvent:"done",tagPrefix:"tag:",emitTopLevelOnly:!1,debug:!1},options);var lexer$1=void 0,rootNode=void 0,current3=void 0,attrName=void 0,reader2=new eventemitter3,handleLexerData=function(data){switch(data.type){case Type.openTag:if(current3===null)current3=rootNode,current3.name=data.value;else{var node=createNode({name:data.value,parent:current3});current3.children.push(node),current3=node}break;case Type.closeTag:var parent=current3.parent;if(options.parentNodes||(current3.parent=null),current3.name!==data.value)break;options.stream&&parent===rootNode&&(rootNode.children=[],current3.parent=null),(!options.emitTopLevelOnly||parent===rootNode)&&(reader2.emit(options.tagPrefix+current3.name,current3),reader2.emit("tag",current3.name,current3)),current3===rootNode&&(lexer$1.removeAllListeners("data"),reader2.emit(options.doneEvent,current3),rootNode=null),current3=parent;break;case Type.text:current3&&current3.children.push(createNode({type:NodeType.text,value:data.value,parent:options.parentNodes?current3:null}));break;case Type.attributeName:attrName=data.value,current3.attributes[attrName]="";break;case Type.attributeValue:current3.attributes[attrName]=data.value;break}};return reader2.reset=function(){lexer$1=lexer.create({debug:options.debug}),lexer$1.on("data",handleLexerData),rootNode=createNode(),current3=null,attrName="",reader2.parse=lexer$1.write},reader2.reset(),reader2},parseSync=function(xml,options){options=Object.assign({},options,{stream:!1,tagPrefix:":"});var reader2=create10(options),res2=void 0;return reader2.on("done",function(ast){res2=ast}),reader2.parse(xml),res2},reader={parseSync,create:create10,NodeType},reader_1=reader.parseSync,parseInput=function(input2){var parsed=reader_1("<root>".concat(input2,"</root>"),{parentNodes:!1}),isValid3=parsed.children&&parsed.children.length>0&&parsed.children.every(function(node){return node.name==="svg"});if(isValid3)return parsed.children.length===1?parsed.children[0]:parsed.children;throw Error("nothing to parse")},camelize=function(node){return deepRenameKeys(node,function(key){return notCamelcase(key)?key:toCamelCase(key)})},toCamelCase=function(prop){return prop.replace(/[-|:]([a-z])/gi,function(all,letter){return letter.toUpperCase()})},notCamelcase=function(prop){return/^(data|aria)(-\w+)/.test(prop)},escapeText2=function(text){if(text){var str10=String(text);return/[&<>]/.test(str10)?"<![CDATA[".concat(str10.replace(/]]>/,"]]]]><![CDATA[>"),"]]>"):str10}return""},escapeAttr2=function(attr){return String(attr).replace(/&/g,"&amp;").replace(/'/g,"&apos;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;")},svgsonSync=function(input2){var _ref=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},_ref$transformNode=_ref.transformNode,transformNode=_ref$transformNode===void 0?function(node){return node}:_ref$transformNode,_ref$camelcase=_ref.camelcase,camelcase=_ref$camelcase===void 0?!1:_ref$camelcase,applyFilters=function(input3){var n10;return n10=transformNode(input3),camelcase&&(n10=camelize(n10)),n10};return applyFilters(parseInput(input2))};function svgson(){for(var _len=arguments.length,args=new Array(_len),_key=0;_key<_len;_key++)args[_key]=arguments[_key];return new Promise(function(resolve7,reject){try{var res2=svgsonSync.apply(void 0,args);resolve7(res2)}catch(e55){reject(e55)}})}var stringify4=function stringify5(_ast){var _ref=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},_ref$transformAttr=_ref.transformAttr,transformAttr=_ref$transformAttr===void 0?function(key,value,escape2){return"".concat(key,'="').concat(escape2(value),'"')}:_ref$transformAttr,_ref$transformNode=_ref.transformNode,transformNode=_ref$transformNode===void 0?function(node){return node}:_ref$transformNode,_ref$selfClose=_ref.selfClose,selfClose=_ref$selfClose===void 0?!0:_ref$selfClose;if(Array.isArray(_ast))return _ast.map(function(ast2){return stringify5(ast2,{transformAttr,selfClose,transformNode})}).join("");var ast=transformNode(_ast);if(ast.type==="text")return escapeText2(ast.value);var attributes2="";for(var attr in ast.attributes){var attrStr=transformAttr(attr,ast.attributes[attr],escapeAttr2,ast.name);attributes2+=attrStr?" ".concat(attrStr):""}return ast.children&&ast.children.length>0||!selfClose?"<".concat(ast.name).concat(attributes2,">").concat(stringify5(ast.children,{transformAttr,transformNode,selfClose}),"</").concat(ast.name,">"):"<".concat(ast.name).concat(attributes2,"/>")},indexUmd=Object.assign({},{parse:svgson,parseSync:svgsonSync,stringify:stringify4});return indexUmd}))}});var require_object_hash=__commonJS({"node_modules/object-hash/dist/object_hash.js"(exports,module){"use strict";(function(e55){var t48;typeof exports=="object"?module.exports=e55():typeof define=="function"&&define.amd?define(e55):(typeof window<"u"?t48=window:typeof global<"u"?t48=global:typeof self<"u"&&(t48=self),t48.objectHash=e55())})(function(){return(function r11(o11,i11,u5){function s11(n10,e56){if(!i11[n10]){if(!o11[n10]){var t48=typeof __require=="function"&&__require;if(!e56&&t48)return t48(n10,!0);if(a10)return a10(n10,!0);throw new Error("Cannot find module '"+n10+"'")}e56=i11[n10]={exports:{}},o11[n10][0].call(e56.exports,function(e57){var t49=o11[n10][1][e57];return s11(t49||e57)},e56,e56.exports,r11,o11,i11,u5)}return i11[n10].exports}for(var a10=typeof __require=="function"&&__require,e55=0;e55<u5.length;e55++)s11(u5[e55]);return s11})({1:[function(w10,b10,m5){(function(e55,n10,s11,c10,d11,h11,p11,g11,y11){"use strict";var r11=w10("crypto");function t48(e56,t49){t49=u5(e56,t49);var n11;return(n11=t49.algorithm!=="passthrough"?r11.createHash(t49.algorithm):new l10).write===void 0&&(n11.write=n11.update,n11.end=n11.update),f3(t49,n11).dispatch(e56),n11.update||n11.end(""),n11.digest?n11.digest(t49.encoding==="buffer"?void 0:t49.encoding):(e56=n11.read(),t49.encoding!=="buffer"?e56.toString(t49.encoding):e56)}(m5=b10.exports=t48).sha1=function(e56){return t48(e56)},m5.keys=function(e56){return t48(e56,{excludeValues:!0,algorithm:"sha1",encoding:"hex"})},m5.MD5=function(e56){return t48(e56,{algorithm:"md5",encoding:"hex"})},m5.keysMD5=function(e56){return t48(e56,{algorithm:"md5",encoding:"hex",excludeValues:!0})};var o11=r11.getHashes?r11.getHashes().slice():["sha1","md5"],i11=(o11.push("passthrough"),["buffer","hex","binary","base64"]);function u5(e56,t49){var n11={};if(n11.algorithm=(t49=t49||{}).algorithm||"sha1",n11.encoding=t49.encoding||"hex",n11.excludeValues=!!t49.excludeValues,n11.algorithm=n11.algorithm.toLowerCase(),n11.encoding=n11.encoding.toLowerCase(),n11.ignoreUnknown=t49.ignoreUnknown===!0,n11.respectType=t49.respectType!==!1,n11.respectFunctionNames=t49.respectFunctionNames!==!1,n11.respectFunctionProperties=t49.respectFunctionProperties!==!1,n11.unorderedArrays=t49.unorderedArrays===!0,n11.unorderedSets=t49.unorderedSets!==!1,n11.unorderedObjects=t49.unorderedObjects!==!1,n11.replacer=t49.replacer||void 0,n11.excludeKeys=t49.excludeKeys||void 0,e56===void 0)throw new Error("Object argument required.");for(var r12=0;r12<o11.length;++r12)o11[r12].toLowerCase()===n11.algorithm.toLowerCase()&&(n11.algorithm=o11[r12]);if(o11.indexOf(n11.algorithm)===-1)throw new Error('Algorithm "'+n11.algorithm+'" not supported. supported values: '+o11.join(", "));if(i11.indexOf(n11.encoding)===-1&&n11.algorithm!=="passthrough")throw new Error('Encoding "'+n11.encoding+'" not supported. supported values: '+i11.join(", "));return n11}function a10(e56){if(typeof e56=="function")return/^function\s+\w*\s*\(\s*\)\s*{\s+\[native code\]\s+}$/i.exec(Function.prototype.toString.call(e56))!=null}function f3(o12,t49,i12){i12=i12||[];function u10(e56){return t49.update?t49.update(e56,"utf8"):t49.write(e56,"utf8")}return{dispatch:function(e56){return this["_"+((e56=o12.replacer?o12.replacer(e56):e56)===null?"null":typeof e56)](e56)},_object:function(t50){var n11,e56=Object.prototype.toString.call(t50),r12=/\[object (.*)\]/i.exec(e56);if(r12=(r12=r12?r12[1]:"unknown:["+e56+"]").toLowerCase(),0<=(e56=i12.indexOf(t50)))return this.dispatch("[CIRCULAR:"+e56+"]");if(i12.push(t50),s11!==void 0&&s11.isBuffer&&s11.isBuffer(t50))return u10("buffer:"),u10(t50);if(r12==="object"||r12==="function"||r12==="asyncfunction")return e56=Object.keys(t50),o12.unorderedObjects&&(e56=e56.sort()),o12.respectType===!1||a10(t50)||e56.splice(0,0,"prototype","__proto__","constructor"),o12.excludeKeys&&(e56=e56.filter(function(e57){return!o12.excludeKeys(e57)})),u10("object:"+e56.length+":"),n11=this,e56.forEach(function(e57){n11.dispatch(e57),u10(":"),o12.excludeValues||n11.dispatch(t50[e57]),u10(",")});if(!this["_"+r12]){if(o12.ignoreUnknown)return u10("["+r12+"]");throw new Error('Unknown object type "'+r12+'"')}this["_"+r12](t50)},_array:function(e56,t50){t50=t50!==void 0?t50:o12.unorderedArrays!==!1;var n11=this;if(u10("array:"+e56.length+":"),!t50||e56.length<=1)return e56.forEach(function(e57){return n11.dispatch(e57)});var r12=[],t50=e56.map(function(e57){var t51=new l10,n12=i12.slice();return f3(o12,t51,n12).dispatch(e57),r12=r12.concat(n12.slice(i12.length)),t51.read().toString()});return i12=i12.concat(r12),t50.sort(),this._array(t50,!1)},_date:function(e56){return u10("date:"+e56.toJSON())},_symbol:function(e56){return u10("symbol:"+e56.toString())},_error:function(e56){return u10("error:"+e56.toString())},_boolean:function(e56){return u10("bool:"+e56.toString())},_string:function(e56){u10("string:"+e56.length+":"),u10(e56.toString())},_function:function(e56){u10("fn:"),a10(e56)?this.dispatch("[native]"):this.dispatch(e56.toString()),o12.respectFunctionNames!==!1&&this.dispatch("function-name:"+String(e56.name)),o12.respectFunctionProperties&&this._object(e56)},_number:function(e56){return u10("number:"+e56.toString())},_xml:function(e56){return u10("xml:"+e56.toString())},_null:function(){return u10("Null")},_undefined:function(){return u10("Undefined")},_regexp:function(e56){return u10("regex:"+e56.toString())},_uint8array:function(e56){return u10("uint8array:"),this.dispatch(Array.prototype.slice.call(e56))},_uint8clampedarray:function(e56){return u10("uint8clampedarray:"),this.dispatch(Array.prototype.slice.call(e56))},_int8array:function(e56){return u10("int8array:"),this.dispatch(Array.prototype.slice.call(e56))},_uint16array:function(e56){return u10("uint16array:"),this.dispatch(Array.prototype.slice.call(e56))},_int16array:function(e56){return u10("int16array:"),this.dispatch(Array.prototype.slice.call(e56))},_uint32array:function(e56){return u10("uint32array:"),this.dispatch(Array.prototype.slice.call(e56))},_int32array:function(e56){return u10("int32array:"),this.dispatch(Array.prototype.slice.call(e56))},_float32array:function(e56){return u10("float32array:"),this.dispatch(Array.prototype.slice.call(e56))},_float64array:function(e56){return u10("float64array:"),this.dispatch(Array.prototype.slice.call(e56))},_arraybuffer:function(e56){return u10("arraybuffer:"),this.dispatch(new Uint8Array(e56))},_url:function(e56){return u10("url:"+e56.toString())},_map:function(e56){return u10("map:"),e56=Array.from(e56),this._array(e56,o12.unorderedSets!==!1)},_set:function(e56){return u10("set:"),e56=Array.from(e56),this._array(e56,o12.unorderedSets!==!1)},_file:function(e56){return u10("file:"),this.dispatch([e56.name,e56.size,e56.type,e56.lastModfied])},_blob:function(){if(o12.ignoreUnknown)return u10("[blob]");throw Error(`Hashing Blob objects is currently not supported
232
232
  (see https://github.com/puleos/object-hash/issues/26)
233
233
  Use "options.replacer" or "options.ignoreUnknown"
234
234
  `)},_domwindow:function(){return u10("domwindow")},_bigint:function(e56){return u10("bigint:"+e56.toString())},_process:function(){return u10("process")},_timer:function(){return u10("timer")},_pipe:function(){return u10("pipe")},_tcp:function(){return u10("tcp")},_udp:function(){return u10("udp")},_tty:function(){return u10("tty")},_statwatcher:function(){return u10("statwatcher")},_securecontext:function(){return u10("securecontext")},_connection:function(){return u10("connection")},_zlib:function(){return u10("zlib")},_context:function(){return u10("context")},_nodescript:function(){return u10("nodescript")},_httpparser:function(){return u10("httpparser")},_dataview:function(){return u10("dataview")},_signal:function(){return u10("signal")},_fsevent:function(){return u10("fsevent")},_tlswrap:function(){return u10("tlswrap")}}}function l10(){return{buf:"",write:function(e56){this.buf+=e56},end:function(e56){this.buf+=e56},read:function(){return this.buf}}}m5.writeToStream=function(e56,t49,n11){return n11===void 0&&(n11=t49,t49={}),f3(t49=u5(e56,t49),n11).dispatch(e56)}}).call(this,w10("lYpoI2"),typeof self<"u"?self:typeof window<"u"?window:{},w10("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/fake_9a5aa49d.js","/")},{buffer:3,crypto:5,lYpoI2:11}],2:[function(e55,t48,f3){(function(e56,t49,n10,r11,o11,i11,u5,s11,a10){(function(e57){"use strict";var a11=typeof Uint8Array<"u"?Uint8Array:Array,t50=43,n11=47,r12=48,o12=97,i12=65,u10=45,s12=95;function f10(e58){return e58=e58.charCodeAt(0),e58===t50||e58===u10?62:e58===n11||e58===s12?63:e58<r12?-1:e58<r12+10?e58-r12+26+26:e58<i12+26?e58-i12:e58<o12+26?e58-o12+26:void 0}e57.toByteArray=function(e58){var t51,n12;if(0<e58.length%4)throw new Error("Invalid string. Length must be a multiple of 4");var r13=e58.length,r13=e58.charAt(r13-2)==="="?2:e58.charAt(r13-1)==="="?1:0,o13=new a11(3*e58.length/4-r13),i13=0<r13?e58.length-4:e58.length,u11=0;function s13(e59){o13[u11++]=e59}for(t51=0;t51<i13;t51+=4,0)s13((16711680&(n12=f10(e58.charAt(t51))<<18|f10(e58.charAt(t51+1))<<12|f10(e58.charAt(t51+2))<<6|f10(e58.charAt(t51+3))))>>16),s13((65280&n12)>>8),s13(255&n12);return r13==2?s13(255&(n12=f10(e58.charAt(t51))<<2|f10(e58.charAt(t51+1))>>4)):r13==1&&(s13((n12=f10(e58.charAt(t51))<<10|f10(e58.charAt(t51+1))<<4|f10(e58.charAt(t51+2))>>2)>>8&255),s13(255&n12)),o13},e57.fromByteArray=function(e58){var t51,n12,r13,o13,i13=e58.length%3,u11="";function s13(e59){return"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(e59)}for(t51=0,r13=e58.length-i13;t51<r13;t51+=3)n12=(e58[t51]<<16)+(e58[t51+1]<<8)+e58[t51+2],u11+=s13((o13=n12)>>18&63)+s13(o13>>12&63)+s13(o13>>6&63)+s13(63&o13);switch(i13){case 1:u11=(u11+=s13((n12=e58[e58.length-1])>>2))+s13(n12<<4&63)+"==";break;case 2:u11=(u11=(u11+=s13((n12=(e58[e58.length-2]<<8)+e58[e58.length-1])>>10))+s13(n12>>4&63))+s13(n12<<2&63)+"="}return u11}})(f3===void 0?this.base64js={}:f3)}).call(this,e55("lYpoI2"),typeof self<"u"?self:typeof window<"u"?window:{},e55("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/node_modules/gulp-browserify/node_modules/base64-js/lib/b64.js","/node_modules/gulp-browserify/node_modules/base64-js/lib")},{buffer:3,lYpoI2:11}],3:[function(O11,e55,H11){(function(e56,n10,f3,r11,h11,p11,g11,y11,w10){var a10=O11("base64-js"),i11=O11("ieee754");function f3(e57,t49,n11){if(!(this instanceof f3))return new f3(e57,t49,n11);var r12,o12,i12,u10,s12=typeof e57;if(t49==="base64"&&s12=="string")for(e57=(u10=e57).trim?u10.trim():u10.replace(/^\s+|\s+$/g,"");e57.length%4!=0;)e57+="=";if(s12=="number")r12=j11(e57);else if(s12=="string")r12=f3.byteLength(e57,t49);else{if(s12!="object")throw new Error("First argument needs to be a number, array or string.");r12=j11(e57.length)}if(f3._useTypedArrays?o12=f3._augment(new Uint8Array(r12)):((o12=this).length=r12,o12._isBuffer=!0),f3._useTypedArrays&&typeof e57.byteLength=="number")o12._set(e57);else if(C11(u10=e57)||f3.isBuffer(u10)||u10&&typeof u10=="object"&&typeof u10.length=="number")for(i12=0;i12<r12;i12++)f3.isBuffer(e57)?o12[i12]=e57.readUInt8(i12):o12[i12]=e57[i12];else if(s12=="string")o12.write(e57,0,t49);else if(s12=="number"&&!f3._useTypedArrays&&!n11)for(i12=0;i12<r12;i12++)o12[i12]=0;return o12}function b10(e57,t49,n11,r12){return f3._charsWritten=c10((function(e58){for(var t50=[],n12=0;n12<e58.length;n12++)t50.push(255&e58.charCodeAt(n12));return t50})(t49),e57,n11,r12)}function m5(e57,t49,n11,r12){return f3._charsWritten=c10((function(e58){for(var t50,n12,r13=[],o12=0;o12<e58.length;o12++)n12=e58.charCodeAt(o12),t50=n12>>8,n12=n12%256,r13.push(n12),r13.push(t50);return r13})(t49),e57,n11,r12)}function v11(e57,t49,n11){var r12="";n11=Math.min(e57.length,n11);for(var o12=t49;o12<n11;o12++)r12+=String.fromCharCode(e57[o12]);return r12}function o11(e57,t49,n11,r12){r12||(d11(typeof n11=="boolean","missing or invalid endian"),d11(t49!=null,"missing offset"),d11(t49+1<e57.length,"Trying to read beyond buffer length"));var o12,r12=e57.length;if(!(r12<=t49))return n11?(o12=e57[t49],t49+1<r12&&(o12|=e57[t49+1]<<8)):(o12=e57[t49]<<8,t49+1<r12&&(o12|=e57[t49+1])),o12}function u5(e57,t49,n11,r12){r12||(d11(typeof n11=="boolean","missing or invalid endian"),d11(t49!=null,"missing offset"),d11(t49+3<e57.length,"Trying to read beyond buffer length"));var o12,r12=e57.length;if(!(r12<=t49))return n11?(t49+2<r12&&(o12=e57[t49+2]<<16),t49+1<r12&&(o12|=e57[t49+1]<<8),o12|=e57[t49],t49+3<r12&&(o12+=e57[t49+3]<<24>>>0)):(t49+1<r12&&(o12=e57[t49+1]<<16),t49+2<r12&&(o12|=e57[t49+2]<<8),t49+3<r12&&(o12|=e57[t49+3]),o12+=e57[t49]<<24>>>0),o12}function _11(e57,t49,n11,r12){if(r12||(d11(typeof n11=="boolean","missing or invalid endian"),d11(t49!=null,"missing offset"),d11(t49+1<e57.length,"Trying to read beyond buffer length")),!(e57.length<=t49))return r12=o11(e57,t49,n11,!0),32768&r12?-1*(65535-r12+1):r12}function E11(e57,t49,n11,r12){if(r12||(d11(typeof n11=="boolean","missing or invalid endian"),d11(t49!=null,"missing offset"),d11(t49+3<e57.length,"Trying to read beyond buffer length")),!(e57.length<=t49))return r12=u5(e57,t49,n11,!0),2147483648&r12?-1*(4294967295-r12+1):r12}function I11(e57,t49,n11,r12){return r12||(d11(typeof n11=="boolean","missing or invalid endian"),d11(t49+3<e57.length,"Trying to read beyond buffer length")),i11.read(e57,t49,n11,23,4)}function A10(e57,t49,n11,r12){return r12||(d11(typeof n11=="boolean","missing or invalid endian"),d11(t49+7<e57.length,"Trying to read beyond buffer length")),i11.read(e57,t49,n11,52,8)}function s11(e57,t49,n11,r12,o12){if(o12||(d11(t49!=null,"missing value"),d11(typeof r12=="boolean","missing or invalid endian"),d11(n11!=null,"missing offset"),d11(n11+1<e57.length,"trying to write beyond buffer length"),Y11(t49,65535)),o12=e57.length,!(o12<=n11))for(var i12=0,u10=Math.min(o12-n11,2);i12<u10;i12++)e57[n11+i12]=(t49&255<<8*(r12?i12:1-i12))>>>8*(r12?i12:1-i12)}function l10(e57,t49,n11,r12,o12){if(o12||(d11(t49!=null,"missing value"),d11(typeof r12=="boolean","missing or invalid endian"),d11(n11!=null,"missing offset"),d11(n11+3<e57.length,"trying to write beyond buffer length"),Y11(t49,4294967295)),o12=e57.length,!(o12<=n11))for(var i12=0,u10=Math.min(o12-n11,4);i12<u10;i12++)e57[n11+i12]=t49>>>8*(r12?i12:3-i12)&255}function B11(e57,t49,n11,r12,o12){o12||(d11(t49!=null,"missing value"),d11(typeof r12=="boolean","missing or invalid endian"),d11(n11!=null,"missing offset"),d11(n11+1<e57.length,"Trying to write beyond buffer length"),F11(t49,32767,-32768)),e57.length<=n11||s11(e57,0<=t49?t49:65535+t49+1,n11,r12,o12)}function L11(e57,t49,n11,r12,o12){o12||(d11(t49!=null,"missing value"),d11(typeof r12=="boolean","missing or invalid endian"),d11(n11!=null,"missing offset"),d11(n11+3<e57.length,"Trying to write beyond buffer length"),F11(t49,2147483647,-2147483648)),e57.length<=n11||l10(e57,0<=t49?t49:4294967295+t49+1,n11,r12,o12)}function U11(e57,t49,n11,r12,o12){o12||(d11(t49!=null,"missing value"),d11(typeof r12=="boolean","missing or invalid endian"),d11(n11!=null,"missing offset"),d11(n11+3<e57.length,"Trying to write beyond buffer length"),D11(t49,34028234663852886e22,-34028234663852886e22)),e57.length<=n11||i11.write(e57,t49,n11,r12,23,4)}function x11(e57,t49,n11,r12,o12){o12||(d11(t49!=null,"missing value"),d11(typeof r12=="boolean","missing or invalid endian"),d11(n11!=null,"missing offset"),d11(n11+7<e57.length,"Trying to write beyond buffer length"),D11(t49,17976931348623157e292,-17976931348623157e292)),e57.length<=n11||i11.write(e57,t49,n11,r12,52,8)}H11.Buffer=f3,H11.SlowBuffer=f3,H11.INSPECT_MAX_BYTES=50,f3.poolSize=8192,f3._useTypedArrays=(function(){try{var e57=new ArrayBuffer(0),t49=new Uint8Array(e57);return t49.foo=function(){return 42},t49.foo()===42&&typeof t49.subarray=="function"}catch{return!1}})(),f3.isEncoding=function(e57){switch(String(e57).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"raw":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},f3.isBuffer=function(e57){return!(e57==null||!e57._isBuffer)},f3.byteLength=function(e57,t49){var n11;switch(e57+="",t49||"utf8"){case"hex":n11=e57.length/2;break;case"utf8":case"utf-8":n11=T11(e57).length;break;case"ascii":case"binary":case"raw":n11=e57.length;break;case"base64":n11=M11(e57).length;break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":n11=2*e57.length;break;default:throw new Error("Unknown encoding")}return n11},f3.concat=function(e57,t49){if(d11(C11(e57),`Usage: Buffer.concat(list, [totalLength])
@@ -949,7 +949,7 @@ orientation: ${label.orientation}`});for(let inlineLabel of inlineNetLabelPlacem
949
949
  `)});let textX=inlineLabel.center.x,textY=inlineLabel.center.y,anchorSide="center",rotation5;if(inlineLabel.stubTracePath){let stubStart=inlineLabel.stubTracePath[0],stubEnd=inlineLabel.stubTracePath[1],labelOffset=inlineLabel.width/2;stubEnd[inlineLabel.axis]>stubStart[inlineLabel.axis]?(labelOffset=-inlineLabel.width/2,anchorSide="center_left"):anchorSide="center_right",inlineLabel.axis==="x"?textX+=labelOffset:textY+=labelOffset}inlineLabel.axis==="y"&&(rotation5=90),graphics.texts.push({x:textX,y:textY,text:inlineLabel.netLabelText??inlineLabel.netId??"",color:"green",fontSize:inlineLabel.height,anchorSide,rotation:rotation5}),graphics.points.push({x:inlineLabel.anchorPoint.x,y:inlineLabel.anchorPoint.y,color:"green",label:`inline anchor
950
950
  ${inlineLabel.netLabelText??inlineLabel.netId}`})}return graphics},estimateInlineNetLabelWidth=(text,fontSize=DEFAULT_INLINE_NET_LABEL_HEIGHT)=>{let fontScale=fontSize/.18;return text.length*.12*fontScale+.12*fontScale},getAnchorCandidates=(segment2,labelWidth,step=.1)=>{let along2=segment2.axis==="x"?"x":"y",start=segment2.start[along2],end=segment2.end[along2],mid=(start+end)/2,direction3=Math.sign(end-start)||1,pointAt2=value=>segment2.axis==="x"?{x:value,y:segment2.start.y}:{x:segment2.start.x,y:segment2.start.y+(value-start)},slack=segment2.length-labelWidth;if(slack<=0)return[pointAt2(mid)];let offsets=[0];for(let offset2=step;offset2<=slack/2+1e-9;offset2+=step)offsets.push(offset2,-offset2);return offsets.push(slack/2,-slack/2),offsets.map(offset2=>pointAt2(mid+offset2*direction3))},doesPathIntersectBounds3=(path,bounds)=>{for(let i22=0;i22<path.length-1;i22++){let a22=path[i22],b22=path[i22+1],segmentBounds={minX:Math.min(a22.x,b22.x),maxX:Math.max(a22.x,b22.x),minY:Math.min(a22.y,b22.y),maxY:Math.max(a22.y,b22.y)};if(boundsOverlap2(segmentBounds,bounds))return!0}return!1},GEOMETRY_EPSILON3=1e-6,getCollisionLimitedTerminalStubEnd=({start,intendedEnd,minimumLength,traces,ownGlobalConnNetId,ignoredTraceIds})=>{let isHorizontal5=Math.abs(intendedEnd.x-start.x)>=Math.abs(intendedEnd.y-start.y),alongAxis=isHorizontal5?"x":"y",acrossAxis=isHorizontal5?"y":"x",direction3=Math.sign(intendedEnd[alongAxis]-start[alongAxis])||1,intendedLength=Math.abs(intendedEnd[alongAxis]-start[alongAxis]),availableLength=intendedLength;for(let trace of traces)if(!ignoredTraceIds.has(trace.mspPairId)&&trace.globalConnNetId!==ownGlobalConnNetId)for(let segmentIndex=0;segmentIndex<trace.tracePath.length-1;segmentIndex++){let segmentStart=trace.tracePath[segmentIndex],segmentEnd=trace.tracePath[segmentIndex+1],startAlong=(segmentStart[alongAxis]-start[alongAxis])*direction3,endAlong=(segmentEnd[alongAxis]-start[alongAxis])*direction3,startAcross=segmentStart[acrossAxis]-start[acrossAxis],endAcross=segmentEnd[acrossAxis]-start[acrossAxis],minAlong=Math.min(startAlong,endAlong),maxAlong=Math.max(startAlong,endAlong),minAcross=Math.min(startAcross,endAcross),maxAcross=Math.max(startAcross,endAcross),collisionDistance;if(Math.abs(startAcross)<=GEOMETRY_EPSILON3&&Math.abs(endAcross)<=GEOMETRY_EPSILON3&&maxAlong>=-GEOMETRY_EPSILON3&&minAlong<=intendedLength+INLINE_NET_LABEL_STUB_TRACE_CLEARANCE+GEOMETRY_EPSILON3)collisionDistance=Math.max(0,minAlong);else{let crossesStubAxis=minAcross<=GEOMETRY_EPSILON3&&maxAcross>=-GEOMETRY_EPSILON3,perpendicularAlong=(startAlong+endAlong)/2;crossesStubAxis&&Math.abs(startAlong-endAlong)<=GEOMETRY_EPSILON3&&perpendicularAlong>=-GEOMETRY_EPSILON3&&perpendicularAlong<=intendedLength+INLINE_NET_LABEL_STUB_TRACE_CLEARANCE+GEOMETRY_EPSILON3&&(collisionDistance=Math.max(0,perpendicularAlong))}collisionDistance!==void 0&&(availableLength=Math.min(availableLength,collisionDistance-INLINE_NET_LABEL_STUB_TRACE_CLEARANCE))}return availableLength+GEOMETRY_EPSILON3<minimumLength?null:isHorizontal5?{x:start.x+direction3*availableLength,y:start.y}:{x:start.x,y:start.y+direction3*availableLength}},EPSILON29=1e-6,isStrictlyBetween2=({coordinate:coordinate3,segmentStartCoordinate,segmentEndCoordinate})=>coordinate3>Math.min(segmentStartCoordinate,segmentEndCoordinate)+EPSILON29&&coordinate3<Math.max(segmentStartCoordinate,segmentEndCoordinate)-EPSILON29,isStrictInteriorPerpendicularCrossing=({firstSegmentStart,firstSegmentEnd,secondSegmentStart,secondSegmentEnd})=>{let firstIsHorizontal=Math.abs(firstSegmentStart.y-firstSegmentEnd.y)<=EPSILON29,firstIsVertical=Math.abs(firstSegmentStart.x-firstSegmentEnd.x)<=EPSILON29,secondIsHorizontal=Math.abs(secondSegmentStart.y-secondSegmentEnd.y)<=EPSILON29,secondIsVertical=Math.abs(secondSegmentStart.x-secondSegmentEnd.x)<=EPSILON29,horizontalStart,horizontalEnd;if(firstIsHorizontal)horizontalStart=firstSegmentStart,horizontalEnd=firstSegmentEnd;else if(secondIsHorizontal)horizontalStart=secondSegmentStart,horizontalEnd=secondSegmentEnd;else return!1;let verticalStart,verticalEnd;if(firstIsVertical)verticalStart=firstSegmentStart,verticalEnd=firstSegmentEnd;else if(secondIsVertical)verticalStart=secondSegmentStart,verticalEnd=secondSegmentEnd;else return!1;return isStrictlyBetween2({coordinate:verticalStart.x,segmentStartCoordinate:horizontalStart.x,segmentEndCoordinate:horizontalEnd.x})&&isStrictlyBetween2({coordinate:horizontalStart.y,segmentStartCoordinate:verticalStart.y,segmentEndCoordinate:verticalEnd.y})},doesTraceRecoveryPathConflict=(tracePath,collisionTraces)=>{for(let pathIndex=0;pathIndex<tracePath.length-1;pathIndex++){let pathStart=tracePath[pathIndex],pathEnd=tracePath[pathIndex+1];for(let trace of collisionTraces)for(let traceIndex=0;traceIndex<trace.tracePath.length-1;traceIndex++){let traceStart=trace.tracePath[traceIndex],traceEnd=trace.tracePath[traceIndex+1];if(doSegmentsIntersect22(pathStart,pathEnd,traceStart,traceEnd)&&!isStrictInteriorPerpendicularCrossing({firstSegmentStart:pathStart,firstSegmentEnd:pathEnd,secondSegmentStart:traceStart,secondSegmentEnd:traceEnd}))return!0}}return!1},getTraceRecoveryConnectivityMaps=inputProblem=>{let chipMap={},pinMap=new Map;for(let chip of inputProblem.chips){chipMap[chip.chipId]=chip;for(let pin of chip.pins)pinMap.set(pin.pinId,{...pin,chipId:chip.chipId,_facingDirection:pin._facingDirection??getPinDirection2(pin,chip)})}return{chipMap,pinMap}},getSimpleConnectionPath=(first,second)=>{let firstDirection=dir(first._facingDirection),secondDirection=dir(second._facingDirection),dx22=second.x-first.x,dy22=second.y-first.y;if((firstDirection.x?Math.abs(dy22)<=1e-6:Math.abs(dx22)<=1e-6)&&firstDirection.x===-secondDirection.x&&firstDirection.y===-secondDirection.y&&dx22*firstDirection.x+dy22*firstDirection.y>1e-6)return[{x:first.x,y:first.y},{x:second.x,y:second.y}];if(firstDirection.x*secondDirection.x||firstDirection.y*secondDirection.y)return;let elbow=firstDirection.x?{x:second.x,y:first.y}:{x:first.x,y:second.y};for(let[pin,direction3]of[[first,firstDirection],[second,secondDirection]])if((elbow.x-pin.x)*direction3.x+(elbow.y-pin.y)*direction3.y<=1e-6)return;return[{x:first.x,y:first.y},elbow,{x:second.x,y:second.y}]},EPS18=1e-9,isHorizontal4=(start,end)=>Math.abs(start.y-end.y)<EPS18,isVertical5=(start,end)=>Math.abs(start.x-end.x)<EPS18,compactConsecutivePoints=path=>path.filter((point62,index2)=>{let previousPoint=path[index2-1];return!previousPoint||Math.abs(point62.x-previousPoint.x)>=EPS18||Math.abs(point62.y-previousPoint.y)>=EPS18}),isValidOrthogonalPath=path=>{if(path.length<2||!path.every((point62,index2)=>{let nextPoint=path[index2+1];return nextPoint?isHorizontal4(point62,nextPoint)||isVertical5(point62,nextPoint):!0}))return!1;for(let firstSegmentIndex=0;firstSegmentIndex<path.length-1;firstSegmentIndex++)for(let secondSegmentIndex=firstSegmentIndex+2;secondSegmentIndex<path.length-1;secondSegmentIndex++)if(segmentsIntersect22(path[firstSegmentIndex],path[firstSegmentIndex+1],path[secondSegmentIndex],path[secondSegmentIndex+1]))return!1;return!0},getEndpointAlignedSegmentCandidates=tracePath=>{let candidates=[];for(let segmentIndex=2;segmentIndex<=tracePath.length-4;segmentIndex++){let previousPoint=tracePath[segmentIndex-1],start=tracePath[segmentIndex],end=tracePath[segmentIndex+1],nextPoint=tracePath[segmentIndex+2],segmentIsVertical=isVertical5(start,end),segmentIsHorizontal=isHorizontal4(start,end);if(!segmentIsVertical&&!segmentIsHorizontal||segmentIsVertical&&(!isHorizontal4(previousPoint,start)||!isHorizontal4(end,nextPoint))||segmentIsHorizontal&&(!isVertical5(previousPoint,start)||!isVertical5(end,nextPoint)))continue;let alignedCoordinates=segmentIsVertical?[previousPoint.x,nextPoint.x]:[previousPoint.y,nextPoint.y];for(let alignedCoordinate of alignedCoordinates){if(Math.abs(alignedCoordinate-(segmentIsVertical?start.x:start.y))<EPS18)continue;let candidate=tracePath.map(point62=>({...point62}));segmentIsVertical?(candidate[segmentIndex].x=alignedCoordinate,candidate[segmentIndex+1].x=alignedCoordinate):(candidate[segmentIndex].y=alignedCoordinate,candidate[segmentIndex+1].y=alignedCoordinate);let compactedCandidate=compactConsecutivePoints(candidate);isValidOrthogonalPath(compactedCandidate)&&candidates.push(compactedCandidate)}}return candidates},countOtherNetCrossings2=({tracePath,globalConnNetId,otherTraces})=>otherTraces.reduce((crossingCount,otherTrace)=>crossingCount+(otherTrace.globalConnNetId===globalConnNetId?0:countPathIntersections(tracePath,otherTrace.tracePath)),0),reduceTraceCrossings=({tracePath,globalConnNetId,otherTraces,isCandidateValid})=>{let bestPath=tracePath,bestCrossingCount=countOtherNetCrossings2({tracePath,globalConnNetId,otherTraces}),bestPathLength=getPathLength4(tracePath);for(let candidate of getEndpointAlignedSegmentCandidates(tracePath)){if(!isCandidateValid(candidate))continue;let crossingCount=countOtherNetCrossings2({tracePath:candidate,globalConnNetId,otherTraces}),pathLength4=getPathLength4(candidate);(crossingCount<bestCrossingCount||crossingCount===bestCrossingCount&&pathLength4<bestPathLength)&&(bestPath=candidate,bestCrossingCount=crossingCount,bestPathLength=pathLength4)}return bestPath},RECOVERED_TRACE_PREFIX="net-label-to-trace-",MAX_NAMED_NET_RECOVERY_PERPENDICULAR_OFFSET=.05,MAX_ROUTED_COMPONENT_RECOVERY_PERPENDICULAR_OFFSET=.25,getCanonicalPairKey=(firstPinId,secondPinId)=>[firstPinId,secondPinId].sort().join("--"),getPerpendicularOffset=(firstPoint,secondPoint)=>{let xDistance=Math.abs(firstPoint.x-secondPoint.x),yDistance=Math.abs(firstPoint.y-secondPoint.y);return xDistance>=yDistance?yDistance:xDistance},arePinsCoFacingAlongSeparationAxis=(firstPin,secondPin)=>{if(firstPin._facingDirection!==secondPin._facingDirection)return!1;let xDistance=Math.abs(firstPin.x-secondPin.x),yDistance=Math.abs(firstPin.y-secondPin.y);return xDistance>=yDistance?firstPin._facingDirection==="x+"||firstPin._facingDirection==="x-":firstPin._facingDirection==="y+"||firstPin._facingDirection==="y-"},NetLabelToTraceSolver=class extends BaseSolver10{constructor(input2,options={}){super();__publicField(this,"input");__publicField(this,"options");__publicField(this,"inputProblem");__publicField(this,"outputTraces");__publicField(this,"outputNetLabelPlacements");__publicField(this,"recoveredTraceIds",new Set);__publicField(this,"chipMap");__publicField(this,"pinMap");__publicField(this,"canRecoverParallelPair");__publicField(this,"queuedCandidates");__publicField(this,"currentCandidate",null);this.input=input2,this.options=options,this.inputProblem=input2.inputProblem,this.outputTraces=[...input2.traces],this.outputNetLabelPlacements=[...input2.netLabelPlacements];let{chipMap,pinMap}=getTraceRecoveryConnectivityMaps(this.inputProblem);this.chipMap=chipMap,this.pinMap=pinMap,this.canRecoverParallelPair=getParallelNetLabelPolicy(this.inputProblem,getConnectivityMapsFromInputProblem(this.inputProblem).netConnMap,new Set(input2.traces.filter(trace=>trace.pinIds.length>1).flatMap(trace=>trace.pinIds))),this.queuedCandidates=this.buildCandidatePairs(),this.stats.candidateCount=this.queuedCandidates.length,this.stats.recoveredTraceCount=0}getConstructorParams(){return[this.input,this.options]}isPortOnlyFallbackLabel(label,groundGlobalConnNetIds){return!(label.pinIds.length!==1||label.mspConnectionPairIds.length!==0||!label.netId||groundGlobalConnNetIds.has(label.globalConnNetId))}isDirectConnectionLabel(label){if(!label.netId||label.pinIds.length!==1)return!1;let pinId=label.pinIds[0];return this.inputProblem.directConnections.some(connection=>connection.netId===label.netId&&connection.pinIds.includes(pinId))}getMultiPinNetConnection(label){if(!label.netId||label.pinIds.length!==1)return;let pinId=label.pinIds[0];return this.inputProblem.netConnections.find(connection=>connection.isGround===!1&&connection.pinIds.length>2&&connection.netId===label.netId&&connection.pinIds.includes(pinId))}getTwoPinNetConnection(label){return this.inputProblem.netConnections.find(connection=>!connection.isGround&&connection.pinIds.length===2&&connection.netId===label.netId&&connection.pinIds.includes(label.pinIds[0]))}buildCandidatePairs(){let{netConnMap}=getConnectivityMapsFromInputProblem(this.inputProblem),groundGlobalConnNetIds=new Set;for(let connection of this.inputProblem.netConnections){if(!connection.isGround)continue;let globalConnNetId=netConnMap.getNetConnectedToId(connection.netId);globalConnNetId&&groundGlobalConnNetIds.add(globalConnNetId)}let labelsByGlobalNet=new Map;for(let label of this.input.netLabelPlacements){if(!this.isPortOnlyFallbackLabel(label,groundGlobalConnNetIds)||!this.isDirectConnectionLabel(label)&&!this.getMultiPinNetConnection(label)&&!this.getTwoPinNetConnection(label))continue;let labels=labelsByGlobalNet.get(label.globalConnNetId)??[];labels.push(label),labelsByGlobalNet.set(label.globalConnNetId,labels)}let candidates=[];for(let labels of labelsByGlobalNet.values())for(let firstIndex=0;firstIndex<labels.length;firstIndex++)for(let secondIndex=firstIndex+1;secondIndex<labels.length;secondIndex++){let firstLabel=labels[firstIndex],secondLabel=labels[secondIndex],firstPin=this.pinMap.get(firstLabel.pinIds[0]),secondPin=this.pinMap.get(secondLabel.pinIds[0]);if(!firstPin||!secondPin||!this.canRecoverParallelPair(firstPin,secondPin))continue;let perpendicularOffset=getPerpendicularOffset(firstPin,secondPin),bothLabelsBelongToDirectConnections=this.isDirectConnectionLabel(firstLabel)&&this.isDirectConnectionLabel(secondLabel),firstMultiPinNetConnection=this.getMultiPinNetConnection(firstLabel),secondMultiPinNetConnection=this.getMultiPinNetConnection(secondLabel),twoPinNetConnection=this.getTwoPinNetConnection(firstLabel),simpleConnectionPath=!bothLabelsBelongToDirectConnections&&twoPinNetConnection&&firstPin.chipId!==secondPin.chipId&&twoPinNetConnection===this.getTwoPinNetConnection(secondLabel)?getSimpleConnectionPath(firstPin,secondPin):void 0;!simpleConnectionPath&&!bothLabelsBelongToDirectConnections&&(!firstMultiPinNetConnection||firstMultiPinNetConnection!==secondMultiPinNetConnection||perpendicularOffset>MAX_NAMED_NET_RECOVERY_PERPENDICULAR_OFFSET)||arePinsInDifferentSchematicSections(this.inputProblem,firstPin,secondPin)||doesPairCrossRestrictedCenterLines({inputProblem:this.inputProblem,chipMap:this.chipMap,pinIdMap:this.pinMap,p1:firstPin,p2:secondPin})||candidates.push({firstLabel,secondLabel,pins:[firstPin,secondPin],perpendicularOffset,routeDistance:Math.abs(firstPin.x-secondPin.x)+Math.abs(firstPin.y-secondPin.y),key:getCanonicalPairKey(firstPin.pinId,secondPin.pinId),recoveryMode:"fallback_labels",simpleConnectionPath})}candidates.push(...this.buildRoutedComponentCandidates(groundGlobalConnNetIds));let selectedCandidates=this.options.onlyInlineDirectConnections||this.options.onlyInlineConnections?candidates.filter(candidate=>this.options.onlyInlineConnections&&candidate.simpleConnectionPath?.length===2&&this.inputProblem.netConnections.some(net=>net.allowInlineNetLabel&&!net.isGround&&net.pinIds.length===2&&candidate.pins.every(pin=>net.pinIds.includes(pin.pinId)))||this.inputProblem.directConnections.some(connection=>candidate.pins.every(pin=>connection.pinIds.includes(pin.pinId))&&(connection.allowInlineNetLabel||this.inputProblem.netConnections.some(net=>net.allowInlineNetLabel&&candidate.pins.every(pin=>net.pinIds.includes(pin.pinId)))))):candidates;return selectedCandidates.sort((first,second)=>first.perpendicularOffset-second.perpendicularOffset||first.routeDistance-second.routeDistance||first.key.localeCompare(second.key)),selectedCandidates}buildRoutedComponentCandidates(groundGlobalConnNetIds){let{netConnMap}=getConnectivityMapsFromInputProblem(this.inputProblem),candidates=[],directConnections=new Set(this.inputProblem.directConnections);for(let connection of[...this.inputProblem.netConnections.filter(connection2=>connection2.pinIds.length>2&&connection2.isGround===!1),...this.inputProblem.directConnections]){let isDirectConnection=directConnections.has(connection),canRecoverElbow=isDirectConnection&&(this.options.onlyInlineDirectConnections||this.options.onlyInlineConnections),globalConnNetId=netConnMap.getNetConnectedToId(connection.pinIds[0]);if(!globalConnNetId||isDirectConnection&&groundGlobalConnNetIds.has(globalConnNetId))continue;let connectionPinIds=connection.pinIds;isDirectConnection&&(connectionPinIds=[...this.pinMap.keys()].filter(pinId=>netConnMap.getNetConnectedToId(pinId)===globalConnNetId));let traceConnectedPinComponents=getTraceConnectedPinComponents({pinIds:connectionPinIds,traces:this.outputTraces.filter(trace=>trace.globalConnNetId===globalConnNetId)}).filter(component=>component.traces.length>0);for(let firstIndex=0;firstIndex<traceConnectedPinComponents.length;firstIndex++)for(let secondIndex=firstIndex+1;secondIndex<traceConnectedPinComponents.length;secondIndex++){let firstComponent=traceConnectedPinComponents[firstIndex],secondComponent=traceConnectedPinComponents[secondIndex];if(isDirectConnection&&!(firstComponent.pinIds.includes(connection.pinIds[0])&&secondComponent.pinIds.includes(connection.pinIds[1])||firstComponent.pinIds.includes(connection.pinIds[1])&&secondComponent.pinIds.includes(connection.pinIds[0])))continue;let firstLabel=this.input.netLabelPlacements.find(label=>label.globalConnNetId===globalConnNetId&&label.mspConnectionPairIds.length>0&&label.pinIds.some(pinId=>firstComponent.pinIds.includes(pinId))),secondLabel=this.input.netLabelPlacements.find(label=>label.globalConnNetId===globalConnNetId&&label.mspConnectionPairIds.length>0&&label.pinIds.some(pinId=>secondComponent.pinIds.includes(pinId)));if(!firstLabel||!secondLabel||firstLabel===secondLabel)continue;let labelsAreAligned=getPerpendicularOffset(firstLabel.anchorPoint,secondLabel.anchorPoint)<=MAX_ROUTED_COMPONENT_RECOVERY_PERPENDICULAR_OFFSET;if(!labelsAreAligned&&!canRecoverElbow)continue;let bestCandidate,firstPinIds=firstComponent.pinIds,secondPinIds=secondComponent.pinIds;isDirectConnection&&(firstPinIds=connection.pinIds.filter(pinId=>firstComponent.pinIds.includes(pinId)),secondPinIds=connection.pinIds.filter(pinId=>secondComponent.pinIds.includes(pinId)));for(let firstPinId of firstPinIds)for(let secondPinId of secondPinIds){let firstPin=this.pinMap.get(firstPinId),secondPin=this.pinMap.get(secondPinId);if(!firstPin||!secondPin||!this.canRecoverParallelPair(firstPin,secondPin)||isDirectConnection&&firstPin.chipId===secondPin.chipId)continue;let perpendicularOffset=getPerpendicularOffset(firstPin,secondPin),simpleConnectionPath=canRecoverElbow&&(!labelsAreAligned||perpendicularOffset>MAX_ROUTED_COMPONENT_RECOVERY_PERPENDICULAR_OFFSET)?getSimpleConnectionPath(firstPin,secondPin):void 0;if((!labelsAreAligned||perpendicularOffset>MAX_ROUTED_COMPONENT_RECOVERY_PERPENDICULAR_OFFSET)&&!simpleConnectionPath||arePinsCoFacingAlongSeparationAxis(firstPin,secondPin)||arePinsInDifferentSchematicSections(this.inputProblem,firstPin,secondPin)||doesPairCrossRestrictedCenterLines({inputProblem:this.inputProblem,chipMap:this.chipMap,pinIdMap:this.pinMap,p1:firstPin,p2:secondPin}))continue;let routeDistance=Math.abs(firstPin.x-secondPin.x)+Math.abs(firstPin.y-secondPin.y),recoveryMode="routed_components";isDirectConnection&&(recoveryMode="routed_direct_connection");let candidate={firstLabel,secondLabel,pins:[firstPin,secondPin],perpendicularOffset,routeDistance,key:getCanonicalPairKey(firstPin.pinId,secondPin.pinId),recoveryMode,netConnectionPinIds:connectionPinIds,simpleConnectionPath};(!bestCandidate||candidate.routeDistance<bestCandidate.routeDistance||candidate.routeDistance===bestCandidate.routeDistance&&(candidate.perpendicularOffset<bestCandidate.perpendicularOffset||candidate.perpendicularOffset===bestCandidate.perpendicularOffset&&candidate.key.localeCompare(bestCandidate.key)<0))&&(bestCandidate=candidate)}bestCandidate&&candidates.push(bestCandidate)}}return candidates}isSupersededConnectorTrace(trace,candidate){return!this.input.netLabelConnectorTraceIds?.has(trace.mspPairId)||trace.pinIds.length!==1?!1:candidate.pins.some(pin=>pin.pinId===trace.pinIds[0])}routeIntersectsRemainingLabels(tracePath,candidate){for(let label of this.outputNetLabelPlacements)if(!(label===candidate.firstLabel||label===candidate.secondLabel)&&pathIntersectsRenderedLabel(tracePath,label))return!0;return this.input.inlineNetLabelPlacements.some(label=>pathIntersectsRenderedLabel(tracePath,label))}tryAcceptCurrentRoute(){let candidate=this.currentCandidate,tracePath=this.activeSubSolver?.solvedTracePath;if(!candidate||!tracePath)return;let retainedTraces=this.outputTraces.filter(trace=>!this.isSupersededConnectorTrace(trace,candidate)),collisionTraces=retainedTraces;if(candidate.recoveryMode!=="fallback_labels"&&(collisionTraces=retainedTraces.filter(trace=>trace.globalConnNetId!==candidate.firstLabel.globalConnNetId)),candidate.simpleConnectionPath&&(tracePath=candidate.simpleConnectionPath,findFirstCollision(tracePath,this.activeSubSolver.obstacles)||collisionTraces.reduce((count,trace)=>count+findPerpendicularPathCrossings(tracePath,trace.tracePath,{includeTerminalSegments:!0}).length,0)>1)||doesTraceRecoveryPathConflict(tracePath,collisionTraces)||this.routeIntersectsRemainingLabels(tracePath,candidate))return;tracePath=reduceTraceCrossings({tracePath,globalConnNetId:candidate.firstLabel.globalConnNetId,otherTraces:collisionTraces,isCandidateValid:candidatePath=>findFirstCollision(candidatePath,this.activeSubSolver.obstacles)===null&&!doesTraceRecoveryPathConflict(candidatePath,collisionTraces)&&!this.routeIntersectsRemainingLabels(candidatePath,candidate)});let[firstPin,secondPin]=candidate.pins,mspPairId=`${RECOVERED_TRACE_PREFIX}${candidate.key}`,recoveredTrace={mspPairId,dcConnNetId:candidate.firstLabel.globalConnNetId,globalConnNetId:candidate.firstLabel.globalConnNetId,pins:[firstPin,secondPin],tracePath,mspConnectionPairIds:[mspPairId],pinIds:[firstPin.pinId,secondPin.pinId]};this.recoveredTraceIds.add(mspPairId),this.outputTraces=[...retainedTraces,recoveredTrace],candidate.recoveryMode!=="routed_components"&&(this.outputNetLabelPlacements=this.outputNetLabelPlacements.filter(label=>label!==candidate.firstLabel&&label!==candidate.secondLabel)),this.stats.recoveredTraceCount++}areCandidatePinsAlreadyConnected(candidate){return candidate.netConnectionPinIds?getTraceConnectedPinComponents({pinIds:candidate.netConnectionPinIds,traces:this.outputTraces}).some(component=>component.pinIds.includes(candidate.pins[0].pinId)&&component.pinIds.includes(candidate.pins[1].pinId)):!1}_step(){if(this.activeSubSolver){this.activeSubSolver.step(),this.activeSubSolver.solved?(this.tryAcceptCurrentRoute(),this.activeSubSolver=null,this.currentCandidate=null):this.activeSubSolver.failed&&(this.activeSubSolver=null,this.currentCandidate=null);return}let candidate=this.queuedCandidates.shift();for(;candidate&&(!this.outputNetLabelPlacements.includes(candidate.firstLabel)||!this.outputNetLabelPlacements.includes(candidate.secondLabel)||this.areCandidatePinsAlreadyConnected(candidate));)candidate=this.queuedCandidates.shift();if(!candidate){this.solved=!0;return}this.currentCandidate=candidate,this.activeSubSolver=new SchematicTraceSingleLineSolver2({inputProblem:this.inputProblem,pins:candidate.pins,chipMap:this.chipMap})}getOutput(){return{traces:this.outputTraces,netLabelPlacements:this.outputNetLabelPlacements,inlineNetLabelPlacements:this.input.inlineNetLabelPlacements}}visualize(){if(this.activeSubSolver)return this.activeSubSolver.visualize();let graphics=visualizeInlineNetLabelOutput({inputProblem:this.inputProblem,...this.getOutput()});for(let trace of this.outputTraces)this.recoveredTraceIds.has(trace.mspPairId)&&graphics.lines.push({points:trace.tracePath,strokeColor:"green",label:`recovered from net labels: ${trace.pinIds.join(" -> ")}`});return graphics}};function definePipelineStep22(solverName,solverClass,getConstructorParams,opts={}){return{solverName,solverClass,getConstructorParams,onSolved:opts.onSolved,shouldSkip:opts.shouldSkip}}var SchematicTracePipelineSolver=class extends BaseSolver10{constructor(inputProblem,opts){super();__publicField(this,"mspConnectionPairSolver");__publicField(this,"schematicTraceLinesSolver");__publicField(this,"longDistancePairSolver");__publicField(this,"unroutedTraceRecoverySolver");__publicField(this,"traceOverlapShiftSolver");__publicField(this,"netLabelPlacementSolver");__publicField(this,"labelMergingSolver");__publicField(this,"traceLabelOverlapAvoidanceSolver");__publicField(this,"traceCleanupSolver");__publicField(this,"example28Solver");__publicField(this,"availableNetOrientationSolver");__publicField(this,"postLabelTraceOverlapShiftSolver");__publicField(this,"railNetLabelCornerPlacementSolver");__publicField(this,"traceAnchoredNetLabelOverlapSolver");__publicField(this,"finalTraceAnchoredNetLabelOverlapSolver");__publicField(this,"preAlignmentNetLabelTraceCollisionSolver");__publicField(this,"netLabelTraceCollisionSolver");__publicField(this,"traceCleanupSolver2");__publicField(this,"netLabelNetLabelCollisionSolver");__publicField(this,"finalRailNetLabelCornerPlacementSolver");__publicField(this,"traceElbowTransitionSimplificationSolver");__publicField(this,"preAlignmentTraceElbowTransitionSimplificationSolver");__publicField(this,"finalTraceElbowTransitionSimplificationSolver");__publicField(this,"sameNetJunctionAlignmentSolver");__publicField(this,"inlineDirectTraceRecoverySolver");__publicField(this,"inlineNetLabelSolver");__publicField(this,"netLabelToTraceSolver");__publicField(this,"startTimeOfPhase");__publicField(this,"endTimeOfPhase");__publicField(this,"timeSpentOnPhase");__publicField(this,"firstIterationOfPhase");__publicField(this,"inputProblem");__publicField(this,"hideRatsNet");__publicField(this,"pipelineDef",[definePipelineStep22("mspConnectionPairSolver",MspConnectionPairSolver,()=>[{inputProblem:this.inputProblem}],{onSolved:mspSolver=>{}}),definePipelineStep22("schematicTraceLinesSolver",SchematicTraceLinesSolver,()=>[{mspConnectionPairs:this.mspConnectionPairSolver.mspConnectionPairs,dcConnMap:this.mspConnectionPairSolver.dcConnMap,globalConnMap:this.mspConnectionPairSolver.globalConnMap,inputProblem:this.inputProblem,chipMap:this.mspConnectionPairSolver.chipMap}]),definePipelineStep22("longDistancePairSolver",LongDistancePairSolver,instance=>[{inputProblem:instance.inputProblem,primaryMspConnectionPairs:instance.mspConnectionPairSolver.mspConnectionPairs,alreadySolvedTraces:instance.schematicTraceLinesSolver.solvedTracePaths,failedConnectionPairs:instance.schematicTraceLinesSolver.failedConnectionPairs}],{onSolved:schematicTraceLinesSolver=>{}}),definePipelineStep22("unroutedTraceRecoverySolver",UnroutedTraceRecoverySolver,instance=>[{inputProblem:instance.inputProblem,failedConnectionPairs:instance.schematicTraceLinesSolver.failedConnectionPairs,alreadySolvedTraces:instance.longDistancePairSolver.getOutput().allTracesMerged}]),definePipelineStep22("traceOverlapShiftSolver",TraceOverlapShiftSolver,()=>[{inputProblem:this.inputProblem,inputTracePaths:this.unroutedTraceRecoverySolver?.getOutput().allTracesMerged,globalConnMap:this.mspConnectionPairSolver.globalConnMap}],{onSolved:_solver=>{}}),definePipelineStep22("netLabelPlacementSolver",NetLabelPlacementSolver,()=>[{inputProblem:this.inputProblem,inputTraceMap:this.traceOverlapShiftSolver?.correctedTraceMap??Object.fromEntries(this.unroutedTraceRecoverySolver.getOutput().allTracesMerged.map(p22=>[p22.mspPairId,p22]))}],{onSolved:_solver=>{}}),definePipelineStep22("traceLabelOverlapAvoidanceSolver",TraceLabelOverlapAvoidanceSolver,instance=>{let traceMap=instance.traceOverlapShiftSolver?.correctedTraceMap??Object.fromEntries(instance.unroutedTraceRecoverySolver.getOutput().allTracesMerged.map(p22=>[p22.mspPairId,p22])),traces=Object.values(traceMap),netLabelPlacements=instance.netLabelPlacementSolver.netLabelPlacements;return[{inputProblem:instance.inputProblem,traces,netLabelPlacements}]}),definePipelineStep22("traceElbowTransitionSimplificationSolver",TraceElbowTransitionSimplificationSolver,instance=>{let overlapAvoidanceOutput=instance.traceLabelOverlapAvoidanceSolver.getOutput();return[{inputProblem:instance.inputProblem,traces:overlapAvoidanceOutput.traces,completedReroutes:overlapAvoidanceOutput.completedReroutes,netLabelPlacements:instance.traceLabelOverlapAvoidanceSolver.netLabelPlacements,paddingBuffer:.1}]}),definePipelineStep22("traceCleanupSolver",TraceCleanupSolver,instance=>{let traces=instance.traceElbowTransitionSimplificationSolver.getOutput().traces,overlapShiftSolver=instance.traceOverlapShiftSolver,inlineLabelNetIds=new Set([...instance.inputProblem.directConnections,...instance.inputProblem.netConnections].filter(connection=>connection.allowInlineNetLabel).map(connection=>connection.netId)),traceIdsInNewCrossingsAfterOverlapShift=new Set;for(let traceIndex=0;traceIndex<overlapShiftSolver.inputTracePaths.length;traceIndex++){let inputTrace=overlapShiftSolver.inputTracePaths[traceIndex],shiftedTrace=overlapShiftSolver.correctedTraceMap[inputTrace.mspPairId];for(let otherTraceIndex=traceIndex+1;otherTraceIndex<overlapShiftSolver.inputTracePaths.length;otherTraceIndex++){let otherInputTrace=overlapShiftSolver.inputTracePaths[otherTraceIndex];if(inputTrace.globalConnNetId===otherInputTrace.globalConnNetId||!inlineLabelNetIds.has(inputTrace.userNetId??"")&&!inlineLabelNetIds.has(otherInputTrace.userNetId??""))continue;let otherShiftedTrace=overlapShiftSolver.correctedTraceMap[otherInputTrace.mspPairId],crossingCountBeforeShift=findPerpendicularPathCrossings(inputTrace.tracePath,otherInputTrace.tracePath).length;findPerpendicularPathCrossings(shiftedTrace.tracePath,otherShiftedTrace.tracePath).length>crossingCountBeforeShift&&(traceIdsInNewCrossingsAfterOverlapShift.add(inputTrace.mspPairId),traceIdsInNewCrossingsAfterOverlapShift.add(otherInputTrace.mspPairId))}}let labelMergingOutput=instance.traceLabelOverlapAvoidanceSolver.labelMergingSolver.getOutput();return[{inputProblem:instance.inputProblem,allTraces:traces,allLabelPlacements:labelMergingOutput.netLabelPlacements,mergedLabelNetIdMap:labelMergingOutput.mergedLabelNetIdMap,paddingBuffer:.1,eligibleTraceIds:traceIdsInNewCrossingsAfterOverlapShift}]}),definePipelineStep22("netLabelPlacementSolver",NetLabelPlacementSolver,instance=>{let traces=instance.traceCleanupSolver?.getOutput().traces??instance.traceLabelOverlapAvoidanceSolver.getOutput().traces;return[{inputProblem:instance.inputProblem,inputTraceMap:Object.fromEntries(traces.map(trace=>[trace.mspPairId,trace]))}]}),definePipelineStep22("example28Solver",Example28Solver,instance=>{let traces=instance.traceCleanupSolver?.getOutput().traces??instance.traceLabelOverlapAvoidanceSolver.getOutput().traces;return[{inputProblem:instance.inputProblem,traces,netLabelPlacements:instance.netLabelPlacementSolver.netLabelPlacements}]}),definePipelineStep22("availableNetOrientationSolver",AvailableNetOrientationSolver,instance=>[{inputProblem:instance.inputProblem,traces:instance.example28Solver.outputTraces,netLabelPlacements:instance.example28Solver.outputNetLabelPlacements}]),definePipelineStep22("postLabelTraceOverlapShiftSolver",TraceOverlapShiftSolver,instance=>[{inputProblem:instance.inputProblem,inputTracePaths:instance.availableNetOrientationSolver.traces,globalConnMap:instance.mspConnectionPairSolver.globalConnMap,traceIdsToShift:new Set(instance.availableNetOrientationSolver.netLabelConnectorTraceIds)}]),definePipelineStep22("railNetLabelCornerPlacementSolver",RailNetLabelCornerPlacementSolver,instance=>[{inputProblem:instance.inputProblem,traces:Object.values(instance.postLabelTraceOverlapShiftSolver.correctedTraceMap),netLabelPlacements:instance.availableNetOrientationSolver.outputNetLabelPlacements,netLabelConnectorTraceIds:instance.availableNetOrientationSolver.netLabelConnectorTraceIds}]),definePipelineStep22("traceAnchoredNetLabelOverlapSolver",TraceAnchoredNetLabelOverlapSolver,instance=>[{inputProblem:instance.inputProblem,netLabelConnectorTraceIds:instance.availableNetOrientationSolver.netLabelConnectorTraceIds,traces:instance.railNetLabelCornerPlacementSolver.getOutput().traces,netLabelPlacements:instance.railNetLabelCornerPlacementSolver.outputNetLabelPlacements}]),definePipelineStep22("preAlignmentNetLabelTraceCollisionSolver",NetLabelTraceCollisionSolver,instance=>[{inputProblem:instance.inputProblem,traces:instance.railNetLabelCornerPlacementSolver.getOutput().traces,netLabelPlacements:instance.traceAnchoredNetLabelOverlapSolver.outputNetLabelPlacements}]),definePipelineStep22("preAlignmentTraceElbowTransitionSimplificationSolver",TraceElbowTransitionSimplificationSolver,instance=>{let collisionOutput=instance.preAlignmentNetLabelTraceCollisionSolver.getOutput();return[{inputProblem:instance.inputProblem,traces:collisionOutput.traces,completedReroutes:collisionOutput.completedReroutes,netLabelPlacements:collisionOutput.netLabelPlacements,paddingBuffer:.1,allowShorterPaths:!0}]}),definePipelineStep22("traceCleanupSolver2",TraceCleanupSolver,instance=>{let collisionOutput=instance.preAlignmentTraceElbowTransitionSimplificationSolver.getOutput(),labelMergingOutput=instance.traceLabelOverlapAvoidanceSolver.labelMergingSolver.getOutput();return[{inputProblem:instance.inputProblem,allTraces:collisionOutput.traces,allLabelPlacements:collisionOutput.netLabelPlacements,mergedLabelNetIdMap:labelMergingOutput.mergedLabelNetIdMap,paddingBuffer:.1,operations:["rerouting_generated_net_label_connector_crossings","aligning_same_net_rails"],eligibleTraceIds:new Set(instance.traceCleanupSolver.getOutput().traces.map(trace=>trace.mspPairId)),netLabelConnectorTraceIds:instance.availableNetOrientationSolver.netLabelConnectorTraceIds}]}),definePipelineStep22("netLabelTraceCollisionSolver",NetLabelTraceCollisionSolver,instance=>{let previousOutput=instance.preAlignmentNetLabelTraceCollisionSolver.getOutput(),alignmentOutput=instance.traceCleanupSolver2.getOutput(),connectorMovement=moveNetLabelConnectorsToReroutedTraces({originalTraces:previousOutput.traces,reroutedTraces:alignmentOutput.traces,netLabelPlacements:previousOutput.netLabelPlacements}),previousTraceMap=new Map(previousOutput.traces.map(trace=>[trace.mspPairId,trace])),netLabelPlacements=connectorMovement.netLabelPlacements;for(let trace of connectorMovement.traces){let previousTrace=previousTraceMap.get(trace.mspPairId);if(!previousTrace||previousTrace.tracePath===trace.tracePath)continue;let currentLabels=netLabelPlacements;netLabelPlacements=moveAttachedLabelsToReroutedTrace({trace:previousTrace,originalTracePath:previousTrace.tracePath,reroutedTracePath:trace.tracePath,netLabelPlacements:currentLabels}).map((movedLabel,labelIndex)=>{let label=currentLabels[labelIndex];return label.orientation==="y+"||label.orientation==="y-"?movedLabel:label})}return[{inputProblem:instance.inputProblem,traces:connectorMovement.traces,netLabelPlacements}]}),definePipelineStep22("finalTraceElbowTransitionSimplificationSolver",TraceElbowTransitionSimplificationSolver,instance=>{let collisionOutput=instance.netLabelTraceCollisionSolver.getOutput(),completedReroutes=[...instance.traceLabelOverlapAvoidanceSolver.getOutput().completedReroutes,...instance.preAlignmentNetLabelTraceCollisionSolver.getOutput().completedReroutes,...collisionOutput.completedReroutes];return[{inputProblem:instance.inputProblem,traces:collisionOutput.traces,completedReroutes,netLabelPlacements:collisionOutput.netLabelPlacements,paddingBuffer:.1,allowShorterPaths:!0}]}),definePipelineStep22("finalRailNetLabelCornerPlacementSolver",RailNetLabelCornerPlacementSolver,instance=>[{inputProblem:instance.inputProblem,...instance.finalTraceElbowTransitionSimplificationSolver.getOutput(),originalTraces:instance.railNetLabelCornerPlacementSolver.getOutput().traces,netLabelConnectorTraceIds:instance.availableNetOrientationSolver.netLabelConnectorTraceIds,onlyOverlappingLabels:!0}]),definePipelineStep22("netLabelNetLabelCollisionSolver",NetLabelNetLabelCollisionSolver,instance=>{let placementOutput=instance.finalRailNetLabelCornerPlacementSolver.getOutput();return[{inputProblem:instance.inputProblem,traces:placementOutput.traces,netLabelPlacements:placementOutput.netLabelPlacements,preserveNonInlineLabelsAgainstInlineEligibleCollisions:!0}]}),definePipelineStep22("finalTraceAnchoredNetLabelOverlapSolver",TraceAnchoredNetLabelOverlapSolver,instance=>[{inputProblem:instance.inputProblem,netLabelConnectorTraceIds:instance.availableNetOrientationSolver.netLabelConnectorTraceIds,traces:instance.netLabelNetLabelCollisionSolver.traces,netLabelPlacements:instance.netLabelNetLabelCollisionSolver.getOutput().netLabelPlacements,overlapMode:"traces"}]),definePipelineStep22("sameNetJunctionAlignmentSolver",SameNetJunctionAlignmentSolver,instance=>{let collisionOutput=instance.finalTraceAnchoredNetLabelOverlapSolver.getOutput();return[{inputProblem:instance.inputProblem,traces:instance.netLabelNetLabelCollisionSolver.traces,netLabelPlacements:collisionOutput.netLabelPlacements,netLabelConnectorTraceIds:instance.availableNetOrientationSolver.netLabelConnectorTraceIds}]}),definePipelineStep22("inlineDirectTraceRecoverySolver",NetLabelToTraceSolver,instance=>[{inputProblem:instance.inputProblem,...instance.sameNetJunctionAlignmentSolver.getOutput(),inlineNetLabelPlacements:[],netLabelConnectorTraceIds:instance.availableNetOrientationSolver.netLabelConnectorTraceIds},{onlyInlineConnections:!0}]),definePipelineStep22("inlineNetLabelSolver",InlineNetLabelSolver,instance=>{let recoveredOutput=instance.inlineDirectTraceRecoverySolver.getOutput(),completedReroutes=[...instance.traceLabelOverlapAvoidanceSolver.getOutput().completedReroutes,...instance.preAlignmentNetLabelTraceCollisionSolver.getOutput().completedReroutes,...instance.netLabelTraceCollisionSolver.getOutput().completedReroutes];return[{inputProblem:instance.inputProblem,traces:recoveredOutput.traces,netLabelPlacements:recoveredOutput.netLabelPlacements,completedReroutes,resolveTraceCollisions:!0,netLabelConnectorTraceIds:instance.availableNetOrientationSolver.netLabelConnectorTraceIds}]}),definePipelineStep22("netLabelToTraceSolver",NetLabelToTraceSolver,instance=>{let inlineOutput=instance.inlineNetLabelSolver.getOutput();return[{inputProblem:instance.inputProblem,...inlineOutput}]})]);__publicField(this,"currentPipelineStepIndex",0);this.hideRatsNet=opts?.hideRatsNet??!1,this.inputProblem=this.cloneAndCorrectInputProblem(inputProblem),this.MAX_ITERATIONS=1e6,this.startTimeOfPhase={},this.endTimeOfPhase={},this.timeSpentOnPhase={},this.firstIterationOfPhase={}}getSolverName(){return"SchematicTracePipelineSolver"}getConstructorParams(){return[this.inputProblem,{hideRatsNet:this.hideRatsNet}]}cloneAndCorrectInputProblem(original){let cloned=structuredClone({...original,_chipObstacleSpatialIndex:void 0,_hideRatsNet:this.hideRatsNet});return correctPinsInsideChips(cloned),cloned}_step(){let pipelineStepDef=this.pipelineDef[this.currentPipelineStepIndex];if(!pipelineStepDef){this.solved=!0;return}if(this.activeSubSolver){this.activeSubSolver.step(),this.activeSubSolver.solved?(this.endTimeOfPhase[pipelineStepDef.solverName]=performance.now(),this.timeSpentOnPhase[pipelineStepDef.solverName]=this.endTimeOfPhase[pipelineStepDef.solverName]-this.startTimeOfPhase[pipelineStepDef.solverName],pipelineStepDef.onSolved?.(this),this.activeSubSolver=null,this.currentPipelineStepIndex++):this.activeSubSolver.failed&&(this.error=this.activeSubSolver?.error,this.failed=!0,this.activeSubSolver=null);return}let constructorParams=pipelineStepDef.getConstructorParams(this);this.activeSubSolver=new pipelineStepDef.solverClass(...constructorParams),this[pipelineStepDef.solverName]=this.activeSubSolver,this.timeSpentOnPhase[pipelineStepDef.solverName]=0,this.startTimeOfPhase[pipelineStepDef.solverName]=performance.now(),this.firstIterationOfPhase[pipelineStepDef.solverName]=this.iterations}solveUntilPhase(phase){for(;this.getCurrentPhase().toLowerCase()!==phase.toLowerCase();)this.step()}getCurrentPhase(){return this.pipelineDef[this.currentPipelineStepIndex]?.solverName??"none"}visualize(){if(!this.solved&&this.activeSubSolver)return this.activeSubSolver.visualize();let visualizations=[visualizeInputProblem2(this.inputProblem,{hideRatsNet:this.hideRatsNet}),...this.pipelineDef.map(p22=>this[p22.solverName]?.visualize()).filter(Boolean).map((viz,stepIndex)=>{for(let rect of viz.rects??[])rect.step=stepIndex;for(let point62 of viz.points??[])point62.step=stepIndex;for(let circle3 of viz.circles??[])circle3.step=stepIndex;for(let text of viz.texts??[])text.step=stepIndex;for(let line2 of viz.lines??[])line2.step=stepIndex;return viz})];if(visualizations.length===1)return visualizations[0];let finalGraphics={points:visualizations.flatMap(v22=>v22.points||[]),rects:visualizations.flatMap(v22=>v22.rects||[]),lines:visualizations.flatMap(v22=>v22.lines||[]),circles:visualizations.flatMap(v22=>v22.circles||[]),texts:visualizations.flatMap(v22=>v22.texts||[])};return colorAvailableNetOrientationLabels(finalGraphics,this.inputProblem),finalGraphics}preview(){return this.activeSubSolver?this.activeSubSolver.preview():super.preview()}},POINT_EPSILON2=1e-8,isPointOnSegment32=(point62,start,end)=>{let cross52=(point62.y-start.y)*(end.x-start.x)-(point62.x-start.x)*(end.y-start.y);if(Math.abs(cross52)>POINT_EPSILON2)return!1;let dot23=(point62.x-start.x)*(end.x-start.x)+(point62.y-start.y)*(end.y-start.y);if(dot23<-POINT_EPSILON2)return!1;let squaredLength6=(end.x-start.x)**2+(end.y-start.y)**2;return dot23<=squaredLength6+POINT_EPSILON2},isPointInRing=(point62,ring4)=>{let isInside=!1;for(let currentIndex=0,previousIndex=ring4.vertices.length-1;currentIndex<ring4.vertices.length;previousIndex=currentIndex++){let current3=ring4.vertices[currentIndex],previous=ring4.vertices[previousIndex];if(isPointOnSegment32(point62,previous,current3))return!0;current3.y>point62.y!=previous.y>point62.y&&point62.x<(previous.x-current3.x)*(point62.y-current3.y)/(previous.y-current3.y)+current3.x&&(isInside=!isInside)}return isInside},isPointInShape=(point62,shape21)=>isPointInRing(point62,shape21.outer_ring)&&!shape21.inner_rings.some(innerRing=>isPointInRing(point62,innerRing)),isPointInShapeUnion=(point62,shapes)=>shapes.some(shape21=>isPointInShape(point62,shape21)),getShapeUnionBounds=shapes=>{let vertices=shapes.flatMap(shape21=>shape21.outer_ring.vertices);if(vertices.length!==0)return{minX:Math.min(...vertices.map(vertex=>vertex.x)),maxX:Math.max(...vertices.map(vertex=>vertex.x)),minY:Math.min(...vertices.map(vertex=>vertex.y)),maxY:Math.max(...vertices.map(vertex=>vertex.y))}},isViaAnnulusInsideShapeUnion=({center:center2,radius,shapes})=>{let samplePoints=[center2];for(let sampleIndex=0;sampleIndex<32;sampleIndex++){let angle3=sampleIndex/32*Math.PI*2;samplePoints.push({x:center2.x+Math.cos(angle3)*radius,y:center2.y+Math.sin(angle3)*radius})}return samplePoints.every(samplePoint=>isPointInShapeUnion(samplePoint,shapes))},layerMatches=(layer,layers)=>layers.some(candidateLayer=>String(candidateLayer)===String(layer)),componentToObstacle=component=>{if(!(component.do_not_place||!component.obstructs_within_bounds))return{kind:"rect",center:component.center,width:component.width,height:component.height,ccwRotation:component.rotation}},smtPadToObstacle=smtPad2=>smtPad2.shape==="circle"?{kind:"circle",center:{x:smtPad2.x,y:smtPad2.y},radius:smtPad2.radius}:smtPad2.shape==="polygon"?{kind:"polygon",points:smtPad2.points}:{kind:"rect",center:{x:smtPad2.x,y:smtPad2.y},width:smtPad2.width,height:smtPad2.height,ccwRotation:smtPad2.shape==="rotated_rect"||smtPad2.shape==="rotated_pill"?smtPad2.ccw_rotation:0},platedHoleToObstacle=platedHole2=>{if(platedHole2.shape==="circle")return{kind:"circle",center:{x:platedHole2.x,y:platedHole2.y},radius:platedHole2.outer_diameter/2};if("outer_width"in platedHole2)return{kind:"rect",center:{x:platedHole2.x,y:platedHole2.y},width:platedHole2.outer_width,height:platedHole2.outer_height,ccwRotation:platedHole2.ccw_rotation};if(platedHole2.shape==="hole_with_polygon_pad"){let rotationRadians=(platedHole2.ccw_rotation??0)*Math.PI/180,cosine=Math.cos(rotationRadians),sine=Math.sin(rotationRadians);return{kind:"polygon",points:platedHole2.pad_outline.map(point62=>({x:platedHole2.x+point62.x*cosine-point62.y*sine,y:platedHole2.y+point62.x*sine+point62.y*cosine}))}}return{kind:"rect",center:{x:platedHole2.x,y:platedHole2.y},width:platedHole2.rect_pad_width,height:platedHole2.rect_pad_height,ccwRotation:"rect_ccw_rotation"in platedHole2?platedHole2.rect_ccw_rotation??0:0}},holeToObstacle=hole=>"hole_diameter"in hole?hole.hole_shape==="circle"?{kind:"circle",center:{x:hole.x,y:hole.y},radius:hole.hole_diameter/2}:{kind:"rect",center:{x:hole.x,y:hole.y},width:hole.hole_diameter,height:hole.hole_diameter,ccwRotation:0}:{kind:"rect",center:{x:hole.x,y:hole.y},width:hole.hole_width,height:hole.hole_height,ccwRotation:hole.hole_shape==="rotated_pill"?hole.ccw_rotation:0},getDistanceToSegment=(point62,start,end)=>{let segmentX=end.x-start.x,segmentY=end.y-start.y,squaredLength6=segmentX**2+segmentY**2;if(squaredLength6===0)return Math.hypot(point62.x-start.x,point62.y-start.y);let projection2=Math.max(0,Math.min(1,((point62.x-start.x)*segmentX+(point62.y-start.y)*segmentY)/squaredLength6));return Math.hypot(point62.x-(start.x+projection2*segmentX),point62.y-(start.y+projection2*segmentY))},isPointInPolygon4=(point62,polygon2)=>{let isInside=!1;for(let currentIndex=0,previousIndex=polygon2.length-1;currentIndex<polygon2.length;previousIndex=currentIndex++){let current3=polygon2[currentIndex],previous=polygon2[previousIndex];current3.y>point62.y!=previous.y>point62.y&&point62.x<(previous.x-current3.x)*(point62.y-current3.y)/(previous.y-current3.y)+current3.x&&(isInside=!isInside)}return isInside},doesCircleIntersectObstacle=(center2,radius,obstacle)=>{if(obstacle.kind==="circle")return Math.hypot(center2.x-obstacle.center.x,center2.y-obstacle.center.y)<radius+obstacle.radius;if(obstacle.kind==="polygon")return isPointInPolygon4(center2,obstacle.points)?!0:obstacle.points.some((point62,pointIndex)=>getDistanceToSegment(center2,point62,obstacle.points[(pointIndex+1)%obstacle.points.length])<radius);let rotationRadians=-obstacle.ccwRotation*Math.PI/180,deltaX=center2.x-obstacle.center.x,deltaY=center2.y-obstacle.center.y,localX=deltaX*Math.cos(rotationRadians)-deltaY*Math.sin(rotationRadians),localY=deltaX*Math.sin(rotationRadians)+deltaY*Math.cos(rotationRadians),outsideX=Math.max(Math.abs(localX)-obstacle.width/2,0),outsideY=Math.max(Math.abs(localY)-obstacle.height/2,0);return Math.hypot(outsideX,outsideY)<radius},getStitchingObstacles=(circuitJson,layers)=>circuitJson.flatMap(element=>{if(element.type==="pcb_component"&&layerMatches(element.layer,layers)){let obstacle=componentToObstacle(element);return obstacle?[obstacle]:[]}return element.type==="pcb_smtpad"&&layerMatches(element.layer,layers)?[smtPadToObstacle(element)]:element.type==="pcb_plated_hole"&&element.layers.some(layer=>layerMatches(layer,layers))?[platedHoleToObstacle(element)]:element.type==="pcb_hole"?[holeToObstacle(element)]:[]}),doesViaIntersectStitchingObstacle=({center:center2,radius,obstacles})=>obstacles.some(obstacle=>doesCircleIntersectObstacle(center2,radius,obstacle)),resolveOptions=(options={})=>{let resolvedOptions={sourceNetIds:options.sourceNetIds?new Set(options.sourceNetIds):void 0,layers:options.layers??["top","bottom"],viaStitchPitch:options.viaStitchPitch??1,viaHoleDiameter:options.viaHoleDiameter??.3,viaOuterDiameter:options.viaOuterDiameter??.6,pourEdgeClearance:options.pourEdgeClearance??.2,obstacleClearance:options.obstacleClearance??.2,minimumViaSeparation:options.minimumViaSeparation??Math.max(options.viaOuterDiameter??.6,.8),gridOrigin:options.gridOrigin??{x:0,y:0},isTented:options.isTented??!0};for(let[optionName,optionValue]of[["viaStitchPitch",resolvedOptions.viaStitchPitch],["viaHoleDiameter",resolvedOptions.viaHoleDiameter],["viaOuterDiameter",resolvedOptions.viaOuterDiameter],["minimumViaSeparation",resolvedOptions.minimumViaSeparation]])if(!Number.isFinite(optionValue)||optionValue<=0)throw new Error(`${optionName} must be a finite number greater than zero`);if(!Number.isFinite(resolvedOptions.pourEdgeClearance)||resolvedOptions.pourEdgeClearance<0)throw new Error("pourEdgeClearance must be a finite non-negative number");if(!Number.isFinite(resolvedOptions.obstacleClearance)||resolvedOptions.obstacleClearance<0)throw new Error("obstacleClearance must be a finite non-negative number");if(!Number.isFinite(resolvedOptions.gridOrigin.x)||!Number.isFinite(resolvedOptions.gridOrigin.y))throw new Error("gridOrigin coordinates must be finite numbers");if(resolvedOptions.viaHoleDiameter>=resolvedOptions.viaOuterDiameter)throw new Error("viaHoleDiameter must be smaller than viaOuterDiameter");if(String(resolvedOptions.layers[0])===String(resolvedOptions.layers[1]))throw new Error("layers must contain two distinct PCB layers");return resolvedOptions},isBrepCopperPour=element=>element.type==="pcb_copper_pour"&&element.shape==="brep",getCopperPourPairContexts=(input2,options)=>{let sourceNetsById=new Map(input2.circuitJson.filter(element=>element.type==="source_net").map(sourceNet=>[sourceNet.source_net_id,sourceNet])),poursBySourceNetId=new Map;for(let element of input2.circuitJson){if(!isBrepCopperPour(element)||!element.source_net_id||options.sourceNetIds&&!options.sourceNetIds.has(element.source_net_id))continue;let sourceNetPours=poursBySourceNetId.get(element.source_net_id)??[];sourceNetPours.push(element),poursBySourceNetId.set(element.source_net_id,sourceNetPours)}let[fromLayer,toLayer]=options.layers,contexts=[];for(let[sourceNetId,sourceNetPours]of poursBySourceNetId){let fromLayerPours=sourceNetPours.filter(copperPour=>String(copperPour.layer)===String(fromLayer)),toLayerPours=sourceNetPours.filter(copperPour=>String(copperPour.layer)===String(toLayer));fromLayerPours.length===0||toLayerPours.length===0||contexts.push({sourceNetId,sourceNet:sourceNetsById.get(sourceNetId),fromLayerPours,toLayerPours})}return contexts},getPcbTraceViaRadius=(routePoint3,fallbackRadius)=>(routePoint3.outer_diameter??fallbackRadius*2)/2,isTooCloseToOccupiedVia=({center:center2,radius,occupiedVias,minimumViaSeparation})=>occupiedVias.some(occupiedVia=>Math.hypot(center2.x-occupiedVia.center.x,center2.y-occupiedVia.center.y)<Math.max(minimumViaSeparation,radius+occupiedVia.radius)),getGridCoordinates=({minimum,maximum,origin,pitch})=>{let coordinates=[],firstGridIndex=Math.ceil((minimum-origin)/pitch),lastGridIndex=Math.floor((maximum-origin)/pitch);for(let gridIndex=firstGridIndex;gridIndex<=lastGridIndex;gridIndex++)coordinates.push(origin+gridIndex*pitch);return coordinates},ViaStitchSolver=class extends BaseSolver{constructor(input2){super();__publicField(this,"input");__publicField(this,"options");__publicField(this,"copperPourPairContexts");__publicField(this,"pcbVias",[]);__publicField(this,"occupiedVias",[]);__publicField(this,"existingPcbViaIds",new Set);__publicField(this,"stitchingObstacles");__publicField(this,"nextCopperPourPairIndex",0);__publicField(this,"nextViaId",0);this.input=input2,this.options=resolveOptions(input2.options),this.copperPourPairContexts=getCopperPourPairContexts(input2,this.options),this.stitchingObstacles=getStitchingObstacles(input2.circuitJson,this.options.layers);let fallbackViaRadius=this.options.viaOuterDiameter/2;for(let element of input2.circuitJson)if(element.type==="pcb_via"){let pcbVia=element;this.existingPcbViaIds.add(pcbVia.pcb_via_id),this.occupiedVias.push({center:{x:pcbVia.x,y:pcbVia.y},radius:pcbVia.outer_diameter/2})}else if(element.type==="pcb_trace")for(let routePoint3 of element.route)routePoint3.route_type==="via"&&this.occupiedVias.push({center:{x:routePoint3.x,y:routePoint3.y},radius:getPcbTraceViaRadius(routePoint3,fallbackViaRadius)})}_step(){let copperPourPairContext=this.copperPourPairContexts[this.nextCopperPourPairIndex];if(!copperPourPairContext){this.solved=!0,this.progress=1;return}this.processCopperPourPair(copperPourPairContext),this.nextCopperPourPairIndex+=1,this.progress=this.copperPourPairContexts.length===0?1:this.nextCopperPourPairIndex/this.copperPourPairContexts.length,this.solved=this.nextCopperPourPairIndex===this.copperPourPairContexts.length}processCopperPourPair(context){let[fromLayer,toLayer]=this.options.layers,fromLayerShapes=context.fromLayerPours.map(copperPour=>copperPour.brep_shape),toLayerShapes=context.toLayerPours.map(copperPour=>copperPour.brep_shape),fromBounds=getShapeUnionBounds(fromLayerShapes),toBounds=getShapeUnionBounds(toLayerShapes);if(!fromBounds||!toBounds)return;let overlapBounds={minX:Math.max(fromBounds.minX,toBounds.minX),maxX:Math.min(fromBounds.maxX,toBounds.maxX),minY:Math.max(fromBounds.minY,toBounds.minY),maxY:Math.min(fromBounds.maxY,toBounds.maxY)};if(overlapBounds.minX>overlapBounds.maxX||overlapBounds.minY>overlapBounds.maxY)return;let viaRadius=this.options.viaOuterDiameter/2,requiredCopperRadius=viaRadius+this.options.pourEdgeClearance,requiredObstacleRadius=viaRadius+this.options.obstacleClearance,xCoordinates=getGridCoordinates({minimum:overlapBounds.minX+requiredCopperRadius,maximum:overlapBounds.maxX-requiredCopperRadius,origin:this.options.gridOrigin.x,pitch:this.options.viaStitchPitch}),yCoordinates=getGridCoordinates({minimum:overlapBounds.minY+requiredCopperRadius,maximum:overlapBounds.maxY-requiredCopperRadius,origin:this.options.gridOrigin.y,pitch:this.options.viaStitchPitch});for(let y22 of yCoordinates)for(let x22 of xCoordinates){let center2={x:x22,y:y22};if(isTooCloseToOccupiedVia({center:center2,radius:viaRadius,occupiedVias:this.occupiedVias,minimumViaSeparation:this.options.minimumViaSeparation})||doesViaIntersectStitchingObstacle({center:center2,radius:requiredObstacleRadius,obstacles:this.stitchingObstacles})||!isViaAnnulusInsideShapeUnion({center:center2,radius:requiredCopperRadius,shapes:fromLayerShapes})||!isViaAnnulusInsideShapeUnion({center:center2,radius:requiredCopperRadius,shapes:toLayerShapes}))continue;let pcbViaId=`via_stitch_via_${this.nextViaId++}`;for(;this.existingPcbViaIds.has(pcbViaId);)pcbViaId=`via_stitch_via_${this.nextViaId++}`;let referencePour=context.fromLayerPours[0],pcbVia={type:"pcb_via",pcb_via_id:pcbViaId,x:x22,y:y22,hole_diameter:this.options.viaHoleDiameter,outer_diameter:this.options.viaOuterDiameter,layers:[fromLayer,toLayer],from_layer:fromLayer,to_layer:toLayer,source_net_id:context.sourceNetId,subcircuit_id:referencePour.subcircuit_id,pcb_group_id:referencePour.pcb_group_id,subcircuit_connectivity_map_key:context.sourceNet?.subcircuit_connectivity_map_key,is_tented:this.options.isTented};this.pcbVias.push(pcbVia),this.existingPcbViaIds.add(pcbViaId),this.occupiedVias.push({center:center2,radius:viaRadius})}}getOutput(){return{processedCopperPourPairCount:this.copperPourPairContexts.length,pcbVias:this.pcbVias}}},SOLVERS={DogboneFanoutSolver,BusLanesSolver,BusLanesPipelineSolver,PackSolver2,LayoutPipelineSolver,AutoroutingPipelineSolver:kne,AssignableAutoroutingPipeline2:Mj,AssignableAutoroutingPipeline3:LH,AutoroutingPipeline1_OriginalUnravel:QF,AutoroutingPipelineSolver3_HgPortPointPathing:cG,AutoroutingPipelineSolver4:Y02,AutoroutingPipelineSolver5:K02,AutoroutingPipelineSolver7_MultiGraph:T7,AutoroutingPipelineSolver8:O7,AutoroutingPipelineSolver9_PreloadedTraceGraph:kne,AutoroutingPipelineSolver9_Networked:roe,AutoroutingPipelineSolver11_Simplification:zse,CopperPourPipelineSolver,CreateFdmEnclosureSolver,FanoutSolver,ImplicitCopperPourPipelineSolver,SchematicTracePipelineSolver,ViaStitchSolver},AUTOROUTER_CACHE_KEY_PREFIX="capacity-autorouter:",cacheProvidersByLocalCacheEngine=new WeakMap;function isPromiseLike(value){return typeof value=="object"&&value!==null&&"then"in value&&typeof value.then=="function"}function isAsyncFunction(fn3){return fn3.constructor.name==="AsyncFunction"}var LocalCacheEngineCacheProvider=class{constructor(localCacheEngine3){__publicField(this,"localCacheEngine");__publicField(this,"isSyncCache");__publicField(this,"cacheHits",0);__publicField(this,"cacheMisses",0);__publicField(this,"cacheHitsByPrefix",{});__publicField(this,"cacheMissesByPrefix",{});__publicField(this,"knownCacheKeys",new Set);this.localCacheEngine=localCacheEngine3,this.isSyncCache=!isAsyncFunction(localCacheEngine3.getItem)&&!isAsyncFunction(localCacheEngine3.setItem)}getCachedSolutionSync(cacheKey){if(this.isSyncCache){this.knownCacheKeys.add(cacheKey);try{let cachedItem=this.localCacheEngine.getItem(this.getLocalCacheEngineKey(cacheKey));if(isPromiseLike(cachedItem)){this.isSyncCache=!1,Promise.resolve(cachedItem).catch(()=>{}),this.recordCacheMiss(cacheKey);return}return this.parseCachedItem(cacheKey,cachedItem)}catch{this.recordCacheMiss(cacheKey);return}}}async getCachedSolution(cacheKey){this.knownCacheKeys.add(cacheKey);try{let cachedItem=await this.localCacheEngine.getItem(this.getLocalCacheEngineKey(cacheKey));return this.parseCachedItem(cacheKey,cachedItem)}catch{this.recordCacheMiss(cacheKey);return}}setCachedSolutionSync(cacheKey,cachedSolution){if(this.isSyncCache){this.knownCacheKeys.add(cacheKey);try{let serializedSolution=JSON.stringify(cachedSolution);if(serializedSolution===void 0)return;let writeResult=this.localCacheEngine.setItem(this.getLocalCacheEngineKey(cacheKey),serializedSolution);isPromiseLike(writeResult)&&(this.isSyncCache=!1,Promise.resolve(writeResult).catch(()=>{}))}catch{}}}async setCachedSolution(cacheKey,cachedSolution){this.knownCacheKeys.add(cacheKey);try{let serializedSolution=JSON.stringify(cachedSolution);if(serializedSolution===void 0)return;await this.localCacheEngine.setItem(this.getLocalCacheEngineKey(cacheKey),serializedSolution)}catch{}}getAllCacheKeys(){return[...this.knownCacheKeys]}clearCache(){for(let cacheKey of this.knownCacheKeys){let localCacheEngineKey=this.getLocalCacheEngineKey(cacheKey);try{let clearResult=this.localCacheEngine.removeItem?this.localCacheEngine.removeItem(localCacheEngineKey):this.localCacheEngine.setItem(localCacheEngineKey,"null");isPromiseLike(clearResult)&&Promise.resolve(clearResult).catch(()=>{})}catch{}}this.knownCacheKeys.clear(),this.cacheHits=0,this.cacheMisses=0,this.cacheHitsByPrefix={},this.cacheMissesByPrefix={}}getLocalCacheEngineKey(cacheKey){return`${AUTOROUTER_CACHE_KEY_PREFIX}${cacheKey}`}parseCachedItem(cacheKey,cachedItem){if(cachedItem===null){this.recordCacheMiss(cacheKey);return}try{let cachedSolution=JSON.parse(cachedItem);if(cachedSolution===null){this.recordCacheMiss(cacheKey);return}return this.recordCacheHit(cacheKey),cachedSolution}catch{this.recordCacheMiss(cacheKey);return}}recordCacheHit(cacheKey){this.cacheHits++;let prefix=cacheKey.split(":")[0];this.cacheHitsByPrefix[prefix]=(this.cacheHitsByPrefix[prefix]??0)+1}recordCacheMiss(cacheKey){this.cacheMisses++;let prefix=cacheKey.split(":")[0];this.cacheMissesByPrefix[prefix]=(this.cacheMissesByPrefix[prefix]??0)+1}};function getCacheProviderForLocalCacheEngine(localCacheEngine3){let cacheProvider=cacheProvidersByLocalCacheEngine.get(localCacheEngine3);return cacheProvider||(cacheProvider=new LocalCacheEngineCacheProvider(localCacheEngine3),cacheProvidersByLocalCacheEngine.set(localCacheEngine3,cacheProvider)),cacheProvider}var getAutorouterSolverName=({useAssignableSolver=!1,useAutoJumperSolver=!1,autorouterVersion:autorouterVersion22,useLaserPrefabSolver=!1,useTraceSimplificationSolver=!1,platformConfig:platformConfig3,effort})=>{let pipeline9SolverName=platformConfig3?.useCloudAutorouter&&(effort===void 0||effort===1)?"AutoroutingPipelineSolver9_Networked":"AutoroutingPipelineSolver9_PreloadedTraceGraph";return useTraceSimplificationSolver?"AutoroutingPipelineSolver11_Simplification":autorouterVersion22==="beta_pipeline1"?"AutoroutingPipeline1_OriginalUnravel":autorouterVersion22==="beta_pipeline3"?"AutoroutingPipelineSolver3_HgPortPointPathing":autorouterVersion22==="beta_pipeline4"?"AutoroutingPipelineSolver4":autorouterVersion22==="beta_pipeline5"?"AutoroutingPipelineSolver5":autorouterVersion22==="beta_pipeline7"?"AutoroutingPipelineSolver7_MultiGraph":autorouterVersion22==="beta_pipeline9"||autorouterVersion22==="latest"?pipeline9SolverName:useLaserPrefabSolver?"AutoroutingPipelineSolver8":useAutoJumperSolver?"AssignableAutoroutingPipeline3":useAssignableSolver?"AssignableAutoroutingPipeline2":pipeline9SolverName};function getCapacityAutorouterCacheProvider(platformConfig3){return platformConfig3?.localCacheEngine?getCacheProviderForLocalCacheEngine(platformConfig3.localCacheEngine):null}var TscircuitAutorouter=class{constructor(input2,options={}){__publicField(this,"input");__publicField(this,"isRouting",!1);__publicField(this,"solver");__publicField(this,"eventHandlers",{complete:[],error:[],progress:[]});__publicField(this,"cycleCount",0);__publicField(this,"stepDelay");__publicField(this,"timeoutId");this.input=input2;let{capacityDepth,targetMinCapacity,stepDelay=0,useAssignableSolver=!1,useAutoJumperSolver=!1,autorouterVersion:autorouterVersion22,useLaserPrefabSolver=!1,useTraceSimplificationSolver=!1,effort,platformConfig:platformConfig3,onSolverStarted}=options,solverName=getAutorouterSolverName({useAssignableSolver,useAutoJumperSolver,autorouterVersion:autorouterVersion22,useLaserPrefabSolver,useTraceSimplificationSolver,platformConfig:platformConfig3,effort}),solverCacheProvider=getCapacityAutorouterCacheProvider(platformConfig3),solverOptions={capacityDepth,targetMinCapacity,cacheProvider:solverCacheProvider,effort};this.solver=solverName==="AutoroutingPipelineSolver9_Networked"?new roe(input2,{...solverOptions,effort:1}):new SOLVERS[solverName](input2,solverOptions),onSolverStarted?.({solverName,solverParams:{input:input2,options:{capacityDepth,targetMinCapacity,cacheProvider:solverCacheProvider,effort}}}),this.stepDelay=stepDelay}start(){this.isRouting||(this.isRouting=!0,this.cycleCount=0,this.runCycleAndQueueNextCycle())}async stepSolver(){if("stepAsync"in this.solver&&typeof this.solver.stepAsync=="function"){await this.solver.stepAsync();return}this.solver.step()}async runCycleAndQueueNextCycle(){if(this.isRouting)try{if(this.solver.solved||this.solver.failed){this.solver.failed?this.emitEvent({type:"error",error:new AutorouterError(this.solver.error||"Routing failed")}):this.emitEvent({type:"complete",traces:this.solver.getOutputSimplifiedPcbTraces()}),this.isRouting=!1;return}let startTime=Date.now(),startIterations=this.solver.iterations;for(;Date.now()-startTime<250&&!this.solver.failed&&!this.solver.solved;)await this.stepSolver();let iterationsPerSecond=(this.solver.iterations-startIterations)/(Date.now()-startTime)*1e3;this.cycleCount++;let debugGraphics=this.solver?.preview()||void 0,progress=this.solver.progress;this.emitEvent({type:"progress",steps:this.cycleCount,iterationsPerSecond,progress,phase:"getCurrentPhase"in this.solver?this.solver.getCurrentPhase():this.solver.activeSubSolver?.getSolverName()??this.solver.getSolverName(),debugGraphics}),this.stepDelay>0?this.timeoutId=setTimeout(()=>{this.runCycleAndQueueNextCycle()},this.stepDelay):this.timeoutId=setTimeout(()=>{this.runCycleAndQueueNextCycle()},0)}catch(error2){this.emitEvent({type:"error",error:error2 instanceof Error?new AutorouterError(error2.message):new AutorouterError(String(error2))}),this.isRouting=!1}}stop(){this.isRouting&&(this.isRouting=!1,this.timeoutId!==void 0&&(clearTimeout(this.timeoutId),this.timeoutId=void 0))}on(event,callback){event==="complete"?this.eventHandlers.complete.push(callback):event==="error"?this.eventHandlers.error.push(callback):event==="progress"&&this.eventHandlers.progress.push(callback)}emitEvent(event){if(event.type==="complete")for(let handler of this.eventHandlers.complete)handler(event);else if(event.type==="error")for(let handler of this.eventHandlers.error)handler(event);else if(event.type==="progress")for(let handler of this.eventHandlers.progress)handler(event)}solveSync(){if(this.solver.solve(),this.solver.failed)throw new AutorouterError(this.solver.error||"Routing failed");return this.solver.getOutputSimplifiedPcbTraces()}getConnectedOffboardObstacles(){return"getConnectedOffboardObstacles"in this.solver?this.solver.getConnectedOffboardObstacles():{}}},createTscircuitAutorouterStrategy=(name,strategyOptions)=>({name,cacheable:!0,getSolverName:options=>getAutorouterSolverName({...options,...strategyOptions}),create:({simpleRouteJson,commonAutorouterOptions,onSolverStarted})=>new TscircuitAutorouter(simpleRouteJson,{...commonAutorouterOptions,...strategyOptions,onSolverStarted:details=>onSolverStarted?.({...details,solverConstructorArgs:[details.solverParams]})})}),defaultLocalAutorouterStrategy=createTscircuitAutorouterStrategy("tscircuit",{}),simplificationLocalAutorouterStrategy=createTscircuitAutorouterStrategy("tscircuit_simplify",{useTraceSimplificationSolver:!0}),createFanoutAutorouterStrategy=mode=>({name:mode,cacheable:!1,followUpAutorouter:"default",getSolverName:()=>"FanoutSolver",create:({simpleRouteJson,busFanoutDirections,fanoutBounds,fanoutRoutingLayers,allowBlindAndBuriedVias,componentNamesById,onSolverStarted})=>new FanoutAutorouter(simpleRouteJson,{mode,busFanoutDirections,fanoutBounds,fanoutRoutingLayers,allowBlindAndBuriedVias,componentNamesById,onSolverStarted})}),localAutorouterStrategies=new Map([["single_layer_fanout",createFanoutAutorouterStrategy("single_layer_fanout")],["fanout",createFanoutAutorouterStrategy("fanout")],["dogbone",{name:"dogbone",preserveOutputTraces:!0,followUpAutorouter:"default",cacheable:!1,getSolverName:()=>"DogboneFanoutSolver",create:({simpleRouteJson,fanoutRoutingLayers,onSolverStarted,onSolverEnded})=>new DogboneAutorouter({input:simpleRouteJson,fanoutRoutingLayers},{onSolverStarted,onSolverEnded})}],["bus_lanes",{name:"bus_lanes",preserveOutputTraces:!0,cacheable:!1,getSolverName:()=>"BusLanesPipelineSolver",create:({simpleRouteJson,onSolverStarted})=>(onSolverStarted?.({solverName:"BusLanesPipelineSolver",solverParams:simpleRouteJson,solverConstructorArgs:[simpleRouteJson]}),new BusLanesAutorouter(simpleRouteJson))}],["simplify",simplificationLocalAutorouterStrategy]]),getLocalAutorouterStrategy=preset=>localAutorouterStrategies.get(preset??"")??defaultLocalAutorouterStrategy,getLocalAutoroutingStages=(autorouterConfig3,platformConfig3)=>{let strategy=getLocalAutorouterStrategy(autorouterConfig3.preset),stages=[{autorouterConfig:autorouterConfig3,strategy,usesPreviousStageOutput:!1}];if(strategy.followUpAutorouter&&!autorouterConfig3.algorithmFn){let followUpAutorouterConfig=getPresetAutoroutingConfig(strategy.followUpAutorouter,platformConfig3);stages.push({autorouterConfig:followUpAutorouterConfig,strategy:getLocalAutorouterStrategy(followUpAutorouterConfig.preset),usesPreviousStageOutput:!0})}return stages},applyPcbEditEventsToManualEditsFile=({circuitJson,editEvents,manualEditsFile})=>{let updatedManualEditsFile={...manualEditsFile,pcb_placements:[...manualEditsFile.pcb_placements??[]]};for(let editEvent of editEvents)if(editEvent.edit_event_type==="edit_pcb_component_location"){let{pcb_component_id,new_center}=editEvent,pcb_component3=su3(circuitJson).pcb_component.get(pcb_component_id);if(!pcb_component3)continue;let source_component=su3(circuitJson).source_component.get(pcb_component3.source_component_id);if(!source_component)continue;let existingPlacementIndex=updatedManualEditsFile.pcb_placements?.findIndex(p22=>p22.selector===source_component.name),newPlacement={selector:source_component.name,center:new_center,relative_to:"group_center"};existingPlacementIndex>=0?updatedManualEditsFile.pcb_placements[existingPlacementIndex]=newPlacement:updatedManualEditsFile.pcb_placements.push(newPlacement)}return updatedManualEditsFile},applySchematicEditEventsToManualEditsFile=({circuitJson,editEvents,manualEditsFile})=>{let updatedManualEditsFile={...manualEditsFile,schematic_placements:[...manualEditsFile.schematic_placements??[]]};for(let editEvent of editEvents)if(editEvent.edit_event_type==="edit_schematic_component_location"){let{schematic_component_id,new_center}=editEvent,schematic_component23=su3(circuitJson).schematic_component.get(schematic_component_id);if(!schematic_component23||!schematic_component23.source_component_id)continue;let source_component=su3(circuitJson).source_component.get(schematic_component23.source_component_id);if(!source_component)continue;let existingPlacementIndex=updatedManualEditsFile.schematic_placements?.findIndex(p22=>p22.selector===source_component.name),newPlacement={selector:source_component.name,center:new_center,relative_to:"group_center"};existingPlacementIndex>=0?updatedManualEditsFile.schematic_placements[existingPlacementIndex]=newPlacement:updatedManualEditsFile.schematic_placements.push(newPlacement)}return updatedManualEditsFile},applyEditEventsToManualEditsFile=({circuitJson,editEvents,manualEditsFile})=>{let schematicEditEvents=editEvents.filter(event=>event.edit_event_type==="edit_schematic_component_location"),pcbEditEvents=editEvents.filter(event=>event.edit_event_type==="edit_pcb_component_location"),updatedManualEditsFile=manualEditsFile;return schematicEditEvents.length>0&&(updatedManualEditsFile=applySchematicEditEventsToManualEditsFile({circuitJson,editEvents:schematicEditEvents,manualEditsFile:updatedManualEditsFile})),pcbEditEvents.length>0&&(updatedManualEditsFile=applyPcbEditEventsToManualEditsFile({circuitJson,editEvents:pcbEditEvents,manualEditsFile:updatedManualEditsFile})),updatedManualEditsFile},applyTraceHintEditEvent=(circuitJson,edit_event)=>{if(su3(circuitJson).pcb_trace_hint.get(edit_event.pcb_trace_hint_id))circuitJson=circuitJson.map(e210=>e210.pcb_trace_hint_id===edit_event.pcb_trace_hint_id?{...e210,route:edit_event.route}:e210);else{let pcbPort=su3(circuitJson).pcb_port.get(edit_event.pcb_port_id);circuitJson=circuitJson.filter(e210=>!(e210.type==="pcb_trace_hint"&&e210.pcb_port_id===edit_event.pcb_port_id)).concat([{type:"pcb_trace_hint",pcb_trace_hint_id:edit_event.pcb_trace_hint_id,route:edit_event.route,pcb_port_id:edit_event.pcb_port_id,pcb_component_id:pcbPort?.pcb_component_id}])}return circuitJson},applyEditEvents=({circuitJson,editEvents})=>{circuitJson=JSON.parse(JSON.stringify(circuitJson));for(let editEvent of editEvents)if(editEvent.edit_event_type==="edit_pcb_component_location"){let component=circuitJson.find(e210=>e210.type==="pcb_component"&&e210.pcb_component_id===editEvent.pcb_component_id);if((!component||component.center.x!==editEvent.new_center.x||component.center.y!==editEvent.new_center.y)&&editEvent.original_center){let mat=translate2(editEvent.new_center.x-editEvent.original_center.x,editEvent.new_center.y-editEvent.original_center.y);circuitJson=circuitJson.map(e210=>e210.pcb_component_id!==editEvent.pcb_component_id?e210:transformPCBElement(e210,mat))}}else editEvent.edit_event_type==="edit_schematic_component_location"?circuitJson=circuitJson.map(e210=>e210.type==="schematic_component"&&e210.schematic_component_id===editEvent.schematic_component_id?{...e210,center:editEvent.new_center}:e210):editEvent.edit_event_type==="edit_pcb_trace_hint"&&(circuitJson=applyTraceHintEditEvent(circuitJson,editEvent));return circuitJson},getBusSourceTraceIdOrThrow=({bus,busSourceTraces,traceNameOrPortSelector})=>{let sourceTracesWithMatchingName=busSourceTraces.filter(sourceTrace2=>sourceTrace2.name===traceNameOrPortSelector),selectedSourcePortId=(sourceTracesWithMatchingName.length===0?bus.getSubcircuit().selectOne(traceNameOrPortSelector,{type:"port"}):null)?.source_port_id??void 0,matchingSourceTraces=selectedSourcePortId?busSourceTraces.filter(sourceTrace2=>sourceTrace2.connected_source_port_ids.includes(selectedSourcePortId)):sourceTracesWithMatchingName;if(matchingSourceTraces.length===0)throw new Error(`Could not find source trace for trace name or port selector "${traceNameOrPortSelector}" in bus "${bus.name}"`);if(matchingSourceTraces.length>1)throw new Error(`Trace name or port selector "${traceNameOrPortSelector}" matches multiple source traces in bus "${bus.name}"`);return matchingSourceTraces[0].source_trace_id},getSourceBusTargetLength=({bus,busSourceTraces})=>{let targetLength=bus._parsedProps.targetLength;return targetLength===void 0||typeof targetLength=="number"?targetLength:{reference:targetLength.reference,offset:targetLength.offset,source_trace_ids:targetLength.of?.map(traceNameOrPortSelector=>getBusSourceTraceIdOrThrow({bus,busSourceTraces,traceNameOrPortSelector}))}},Bus=class extends PrimitiveComponent2{constructor(){super(...arguments);__publicField(this,"source_bus_id")}get config(){return{componentName:"Bus",zodProps:busProps}}doInitialSourceAddConnectivityMapKey(){let{db:db22}=this.root,subcircuit_id=this.getSubcircuit().subcircuit_id,busSourceTraces=db22.source_trace.list().filter(sourceTrace=>sourceTrace.subcircuit_id===subcircuit_id),source_trace_ids=this._parsedProps.connections.map(traceNameOrPortSelector=>getBusSourceTraceIdOrThrow({bus:this,busSourceTraces,traceNameOrPortSelector}));if(new Set(source_trace_ids).size!==source_trace_ids.length)throw new Error(`Bus "${this.name}" resolves multiple entries to one trace`);let sourceBus=db22.source_bus.insert({name:this._parsedProps.name,source_trace_ids,max_length_skew:this._parsedProps.maxLengthSkew,target_length:getSourceBusTargetLength({bus:this,busSourceTraces}),length_tolerance:this._parsedProps.lengthTolerance,subcircuit_id});this.source_bus_id=sourceBus.source_bus_id}},resolvePointToPointConnection=(differentialPair,connectionSelector)=>{let{db:db22}=differentialPair.root,subcircuit=differentialPair.getSubcircuit(),subcircuitSourceTraces=db22.source_trace.list().filter(sourceTrace=>sourceTrace.subcircuit_id===subcircuit.subcircuit_id),matchingSourceTraces=subcircuitSourceTraces.filter(sourceTrace=>sourceTrace.name===connectionSelector),connectivityMapKeys=new Set;if(matchingSourceTraces.length>0)for(let sourceTrace of matchingSourceTraces)sourceTrace.subcircuit_connectivity_map_key&&connectivityMapKeys.add(sourceTrace.subcircuit_connectivity_map_key);else{let selectedPort=subcircuit.selectOne(connectionSelector,{type:"port"});if(selectedPort?.source_port_id){let sourcePort=db22.source_port.get(selectedPort.source_port_id);sourcePort?.subcircuit_connectivity_map_key&&connectivityMapKeys.add(sourcePort.subcircuit_connectivity_map_key)}}if(connectivityMapKeys.size!==1)return;let connectivityMapKey=connectivityMapKeys.values().next().value;if(!connectivityMapKey)return;let sourcePorts=db22.source_port.list().filter(sourcePort=>sourcePort.subcircuit_connectivity_map_key===connectivityMapKey);return{sourceTraceIds:subcircuitSourceTraces.filter(trace=>trace.subcircuit_connectivity_map_key===connectivityMapKey).map(trace=>trace.source_trace_id),sourcePorts,sourceTraceName:matchingSourceTraces.length>0?connectionSelector:void 0}},formatTerminalPinList=terminalPinSelectors=>terminalPinSelectors.length<=1?terminalPinSelectors.join(""):terminalPinSelectors.length===2?`${terminalPinSelectors[0]} and ${terminalPinSelectors[1]}`:`${terminalPinSelectors.slice(0,-1).join(", ")}, and ${terminalPinSelectors.at(-1)}`,getTerminalPinSelector=(sourcePort,sourceComponentsById)=>{let sourceComponent;if(sourcePort.source_component_id&&(sourceComponent=sourceComponentsById.get(sourcePort.source_component_id)),!sourceComponent?.name)return sourcePort.source_port_id;let portName=sourcePort.most_frequently_referenced_by_name??sourcePort.name;return`.${sourceComponent.name} > .${portName}`},getPointToPointWarningMessage=({differentialPairName,connectionPolarity,connectionSelector,sourceTraceName,terminalPinSelectors})=>{let terminalList=formatTerminalPinList(terminalPinSelectors),terminalListDescription=terminalList?`: ${terminalList}`:"";return sourceTraceName&&terminalPinSelectors.length>2?`Differential pair "${differentialPairName}" ${connectionPolarity}Connection uses the ambiguous trace name "${sourceTraceName}": its connection has more than 2 terminal pins${terminalListDescription}.`:`Differential pair "${differentialPairName}" ${connectionPolarity}Connection="${connectionSelector}" is not point-to-point: expected exactly 2 terminal pins, found ${terminalPinSelectors.length}${terminalListDescription}.`},DifferentialPair_doInitialSourceDesignRuleChecks=differentialPair=>{let{db:db22}=differentialPair.root,sourceComponentsById=new Map;for(let sourceComponent of db22.source_component.list())sourceComponentsById.set(sourceComponent.source_component_id,{name:sourceComponent.name});let memberTraceIds=[],resolvedPolarityCount=0;for(let connectionPolarity of["positive","negative"]){let connectionSelector=differentialPair._parsedProps.negativeConnection;connectionPolarity==="positive"&&(connectionSelector=differentialPair._parsedProps.positiveConnection);let resolvedConnection=resolvePointToPointConnection(differentialPair,connectionSelector);if(!resolvedConnection)continue;resolvedPolarityCount++,memberTraceIds.push(...resolvedConnection.sourceTraceIds);let terminalSourcePorts=resolvedConnection.sourcePorts;if(terminalSourcePorts.length===2)continue;let warningSourceComponentId="",firstTerminalSourcePort=terminalSourcePorts[0];if(firstTerminalSourcePort){if(!firstTerminalSourcePort.source_component_id)throw new Error(`Differential pair "${differentialPair.name}" resolved terminal port "${firstTerminalSourcePort.source_port_id}" without a source_component_id`);warningSourceComponentId=firstTerminalSourcePort.source_component_id}let terminalPinSelectors=terminalSourcePorts.map(sourcePort=>getTerminalPinSelector(sourcePort,sourceComponentsById)).sort((selectorA,selectorB)=>selectorA.localeCompare(selectorB));db22.source_property_ignored_warning.insert({source_component_id:warningSourceComponentId,property_name:`${connectionPolarity}Connection`,error_type:"source_property_ignored_warning",message:getPointToPointWarningMessage({differentialPairName:differentialPair.name,connectionPolarity,connectionSelector,sourceTraceName:resolvedConnection.sourceTraceName,terminalPinSelectors}),subcircuit_id:differentialPair.getSubcircuit().subcircuit_id??void 0})}resolvedPolarityCount===2&&memberTraceIds.length>0&&db22.source_bus.insert({name:differentialPair.name,source_trace_ids:[...new Set(memberTraceIds)],max_length_skew:differentialPair._parsedProps.maxLengthSkew,subcircuit_id:differentialPair.getSubcircuit().subcircuit_id??void 0})},DifferentialPair=class extends PrimitiveComponent2{get config(){return{componentName:"DifferentialPair",zodProps:differentialPairProps}}doInitialSourceDesignRuleChecks(){DifferentialPair_doInitialSourceDesignRuleChecks(this)}},expandSrjBoundsToIncludeConnectionPoints=input2=>{let expandedBounds={...input2.bounds};for(let connection of input2.connections)if(!connection.isOffBoard)for(let point62 of connection.pointsToConnect)expandedBounds.minX=Math.min(expandedBounds.minX,point62.x),expandedBounds.maxX=Math.max(expandedBounds.maxX,point62.x),expandedBounds.minY=Math.min(expandedBounds.minY,point62.y),expandedBounds.maxY=Math.max(expandedBounds.maxY,point62.y);return expandedBounds},getSrjOutlineForRoutingBounds=({bounds,outline},routingBounds2)=>{if(outline)return outline;if(!(bounds.minX===routingBounds2.minX&&bounds.maxX===routingBounds2.maxX&&bounds.minY===routingBounds2.minY&&bounds.maxY===routingBounds2.maxY))return new Box(bounds.minX,bounds.minY,bounds.maxX,bounds.maxY).toPoints().map(({x:x22,y:y22})=>({x:x22,y:y22}))},getBusTargetLengthBounds=bus=>{if(!bus.source_bus_id)return{};let{db:db22}=bus.root,sourceBus=db22.source_bus.get(bus.source_bus_id);if(sourceBus.target_length===void 0)return{};let tolerance=sourceBus.length_tolerance;if(tolerance===void 0)throw new Error(`Bus "${bus.name}" requires lengthTolerance with targetLength`);let targetLength;if(typeof sourceBus.target_length=="number")targetLength=sourceBus.target_length;else{let reference3=sourceBus.target_length,manhattanLengths=(reference3.source_trace_ids??sourceBus.source_trace_ids).map(sourceTraceId=>{let sourceTrace=db22.source_trace.get(sourceTraceId),pcbPorts=db22.pcb_port.list().filter(port=>sourceTrace.connected_source_port_ids.includes(port.source_port_id));if(pcbPorts.length!==2)throw new Error(`Bus "${bus.name}" targetLength requires two placed endpoint pads per reference trace`);return Math.abs(pcbPorts[0].x-pcbPorts[1].x)+Math.abs(pcbPorts[0].y-pcbPorts[1].y)});targetLength=Math.max(...manhattanLengths)+(reference3.offset??0)}return{minLength:Math.max(0,targetLength-tolerance),maxLength:targetLength+tolerance}},getBusSrjConnectionNamesOrThrow=({srjConnections,bus,sourceTraceId,traceNameOrPortSelector,busSourceTraces})=>{let directSrjConnections=srjConnections.filter(srjConnection=>srjConnection.source_trace_id===sourceTraceId);if(directSrjConnections.length>0)return directSrjConnections.map(srjConnection=>srjConnection.name);let sourceTrace=busSourceTraces.find(trace=>trace.source_trace_id===sourceTraceId),connectedSourceTraces=busSourceTraces.filter(trace=>trace.source_trace_id===sourceTraceId||sourceTrace.subcircuit_connectivity_map_key!==void 0&&trace.subcircuit_connectivity_map_key===sourceTrace.subcircuit_connectivity_map_key),connectedSourceNetIds=new Set(connectedSourceTraces.flatMap(trace=>trace.connected_source_net_ids??[])),matchingSrjConnections=srjConnections.filter(srjConnection=>connectedSourceNetIds.has(srjConnection.name));if(matchingSrjConnections.length===0)throw new Error(`Could not find an SRJ connection for "${traceNameOrPortSelector}" in bus "${bus.name}"`);return matchingSrjConnections.map(srjConnection=>srjConnection.name)},normalizeNetName=netNameOrSelector=>netNameOrSelector.trim().replace(/^net\./,"").replace(/^\./,""),getPlaneTerminatedSourceTraceLayers=({fanoutPourNetMap,sourceNets,sourceTraces,subcircuitId})=>{let traceLayers=new Map;if(!fanoutPourNetMap)return traceLayers;let planeLayerBySourceNetId=new Map;for(let[layer,netOrNets]of Object.entries(fanoutPourNetMap)){let netNames=Array.isArray(netOrNets)?netOrNets:[netOrNets];for(let netNameOrSelector of netNames){let netName=normalizeNetName(netNameOrSelector);for(let sourceNet of sourceNets){if(sourceNet.name!==netName)continue;let previousLayer=planeLayerBySourceNetId.get(sourceNet.source_net_id);if(previousLayer&&previousLayer!==layer)throw new Error(`Fanout plane net "${netName}" maps to multiple layers ("${previousLayer}" and "${layer}"); use fanoutPourNetMap to select one`);planeLayerBySourceNetId.set(sourceNet.source_net_id,layer)}}}for(let sourceTrace of sourceTraces){if(subcircuitId&&sourceTrace.subcircuit_id!==subcircuitId||sourceTrace.connected_source_port_ids.length!==1)continue;let mappedLayers=new Set((sourceTrace.connected_source_net_ids??[]).map(sourceNetId=>planeLayerBySourceNetId.get(sourceNetId)).filter(layer2=>layer2!==void 0));if(mappedLayers.size>1)throw new Error(`Source trace "${sourceTrace.name??sourceTrace.source_trace_id}" connects to fanout planes on multiple layers`);let layer=mappedLayers.values().next().value;layer&&traceLayers.set(sourceTrace.source_trace_id,layer)}return traceLayers},getBusesForSimpleRouteJson=({srjConnections,buses,sourceTraces,subcircuitId,planeTerminatedSourceTraceLayers,preservedSourceTraceIds})=>{let declaredSrjBuses=[];for(let bus of buses){let busSubcircuitId=bus.getSubcircuit().subcircuit_id;if(subcircuitId&&busSubcircuitId!==subcircuitId)continue;let busSourceTraces=sourceTraces.filter(sourceTrace=>sourceTrace.subcircuit_id===busSubcircuitId),connectionNames=bus._parsedProps.connections.flatMap(traceNameOrPortSelector=>{let sourceTraceId=getBusSourceTraceIdOrThrow({bus,busSourceTraces,traceNameOrPortSelector});return preservedSourceTraceIds?.has(sourceTraceId)?[]:getBusSrjConnectionNamesOrThrow({srjConnections,bus,sourceTraceId,traceNameOrPortSelector,busSourceTraces})});if(new Set(connectionNames).size!==connectionNames.length)throw new Error(`Bus "${bus.name}" resolves multiple entries to one trace`);connectionNames.length!==0&&declaredSrjBuses.push({busId:bus.name,name:bus.name,connectionNames,...getBusTargetLengthBounds(bus),...bus._parsedProps.maxLengthSkew!==void 0?{maxLengthSkew:bus._parsedProps.maxLengthSkew}:{},...bus._parsedProps.pcbTraceWidth!==void 0?{traceWidth:bus._parsedProps.pcbTraceWidth}:{},...bus._parsedProps.pcbAllowedLayers!==void 0?{allowedLayers:bus._parsedProps.pcbAllowedLayers}:{},...bus._parsedProps.preferredLayer!==void 0?{preferredLayer:bus._parsedProps.preferredLayer}:{},...bus._parsedProps.preferredLayers!==void 0?{preferredLayers:bus._parsedProps.preferredLayers}:{}})}let planeSrjBuses=[];for(let[sourceTraceId,layer]of planeTerminatedSourceTraceLayers??[]){let sourceTrace=sourceTraces.find(candidate=>candidate.source_trace_id===sourceTraceId),srjConnection=srjConnections.find(connection=>connection.source_trace_id===sourceTraceId);if(!sourceTrace||!srjConnection)continue;let busId=sourceTrace.name??sourceTrace.source_trace_id;if([...declaredSrjBuses,...planeSrjBuses].some(bus=>bus.busId===busId))throw new Error(`Fanout plane trace "${busId}" conflicts with an existing bus name`);planeSrjBuses.push({busId,name:busId,connectionNames:[srjConnection.name],termination:{type:"plane",layer}})}let srjBuses=[...planeSrjBuses,...declaredSrjBuses];return srjBuses.length>0?srjBuses:void 0},getDifferentialPairSourceTracesByTraceName=(differentialPairSourceTraces,traceName)=>differentialPairSourceTraces.filter(sourceTrace=>sourceTrace.name===traceName),getDifferentialPairSourceTracesByPortId=(differentialPairSourceTraces,sourcePortId)=>differentialPairSourceTraces.filter(sourceTrace=>sourceTrace.connected_source_port_ids.includes(sourcePortId)),getDifferentialPairTraceSubcircuitConnectivityMapKeyOrThrow=({differentialPair,differentialPairSourceTraces,traceNameOrPortSelector})=>{let differentialPairSubcircuit=differentialPair.getSubcircuit(),sourceTracesWithMatchingName=getDifferentialPairSourceTracesByTraceName(differentialPairSourceTraces,traceNameOrPortSelector),selectedSourcePortId=(sourceTracesWithMatchingName.length===0?differentialPairSubcircuit.selectOne(traceNameOrPortSelector,{type:"port"}):null)?.source_port_id??void 0,matchingSourceTraces=selectedSourcePortId?getDifferentialPairSourceTracesByPortId(differentialPairSourceTraces,selectedSourcePortId):sourceTracesWithMatchingName;if(matchingSourceTraces.length===0)throw new Error(`Could not find source trace for trace name or port selector "${traceNameOrPortSelector}" in differential pair "${differentialPair.name}"`);if(matchingSourceTraces.length>1)throw new Error(`Trace name or port selector "${traceNameOrPortSelector}" matches multiple source traces for differential pair "${differentialPair.name}"`);let sourceTrace=matchingSourceTraces[0];if(!sourceTrace)throw new Error(`Expected one source trace for trace name or port selector "${traceNameOrPortSelector}" in differential pair "${differentialPair.name}"`);let subcircuitConnectivityMapKey=sourceTrace.subcircuit_connectivity_map_key;if(!subcircuitConnectivityMapKey)throw new Error(`Source trace "${sourceTrace.source_trace_id}" does not have a subcircuit connectivity map key for differential pair "${differentialPair.name}"`);return subcircuitConnectivityMapKey},getDifferentialPairSrjConnectionNamesByCohortOrThrow=({srjConnections,differentialPairName,differentialPairSourceTraces,traceSubcircuitConnectivityMapKey,traceNameOrPortSelector})=>{let differentialPairSourceTraceIds=[],differentialPairSourceNetIds=new Set;for(let sourceTrace of differentialPairSourceTraces)if(sourceTrace.subcircuit_connectivity_map_key===traceSubcircuitConnectivityMapKey){differentialPairSourceTraceIds.push(sourceTrace.source_trace_id);for(let sourceNetId of sourceTrace.connected_source_net_ids??[])differentialPairSourceNetIds.add(sourceNetId)}let matchingSrjConnections=[];for(let srjConnection of srjConnections)(differentialPairSourceNetIds.has(srjConnection.name)||srjConnection.source_trace_id&&differentialPairSourceTraceIds.includes(srjConnection.source_trace_id))&&matchingSrjConnections.push(srjConnection);if(matchingSrjConnections.length===0)throw new Error(`Could not find an SRJ connection for trace name or port selector "${traceNameOrPortSelector}" in differential pair "${differentialPairName}"`);let connectionNamesByCohort=new Map;for(let srjConnection of matchingSrjConnections){let cohort=srjConnection.routingPcbGroupId;if(connectionNamesByCohort.has(cohort)){let cohortLabel=cohort===void 0?"the global routing cohort":`routing PCB group "${cohort}"`;throw new Error(`Subcircuit connectivity map key "${traceSubcircuitConnectivityMapKey}" matches multiple SRJ connections in ${cohortLabel} for differential pair "${differentialPairName}"`)}connectionNamesByCohort.set(cohort,srjConnection.name)}return connectionNamesByCohort},getDifferentialPairCohortLabel=cohort=>cohort===void 0?"the global routing cohort":`routing PCB group "${cohort}"`,getDifferentialPairsForSimpleRouteJson=({srjConnections,differentialPairs,sourceTraces,subcircuitId})=>{let srjDifferentialPairs=[];for(let differentialPair of differentialPairs){let differentialPairSubcircuitId=differentialPair.getSubcircuit().subcircuit_id;if(subcircuitId&&differentialPairSubcircuitId!==subcircuitId)continue;let differentialPairSourceTraces=sourceTraces.filter(sourceTrace=>sourceTrace.subcircuit_id===differentialPairSubcircuitId),positiveTraceNameOrPortSelector=differentialPair._parsedProps.positiveConnection,negativeTraceNameOrPortSelector=differentialPair._parsedProps.negativeConnection,positiveSubcircuitConnectivityMapKey=getDifferentialPairTraceSubcircuitConnectivityMapKeyOrThrow({differentialPair,differentialPairSourceTraces,traceNameOrPortSelector:positiveTraceNameOrPortSelector}),negativeSubcircuitConnectivityMapKey=getDifferentialPairTraceSubcircuitConnectivityMapKeyOrThrow({differentialPair,differentialPairSourceTraces,traceNameOrPortSelector:negativeTraceNameOrPortSelector}),positiveSrjConnectionNamesByCohort=getDifferentialPairSrjConnectionNamesByCohortOrThrow({srjConnections,differentialPairName:differentialPair.name,differentialPairSourceTraces,traceSubcircuitConnectivityMapKey:positiveSubcircuitConnectivityMapKey,traceNameOrPortSelector:positiveTraceNameOrPortSelector}),negativeSrjConnectionNamesByCohort=getDifferentialPairSrjConnectionNamesByCohortOrThrow({srjConnections,differentialPairName:differentialPair.name,differentialPairSourceTraces,traceSubcircuitConnectivityMapKey:negativeSubcircuitConnectivityMapKey,traceNameOrPortSelector:negativeTraceNameOrPortSelector}),lengthTolerance=differentialPair._parsedProps.maxLengthSkew??.1;for(let cohort of positiveSrjConnectionNamesByCohort.keys())if(!negativeSrjConnectionNamesByCohort.has(cohort))throw new Error(`Differential pair "${differentialPair.name}" has a positive SRJ connection in ${getDifferentialPairCohortLabel(cohort)} without a matching negative SRJ connection`);for(let cohort of negativeSrjConnectionNamesByCohort.keys())if(!positiveSrjConnectionNamesByCohort.has(cohort))throw new Error(`Differential pair "${differentialPair.name}" has a negative SRJ connection in ${getDifferentialPairCohortLabel(cohort)} without a matching positive SRJ connection`);for(let[cohort,positiveSrjConnectionName]of positiveSrjConnectionNamesByCohort){let negativeSrjConnectionName=negativeSrjConnectionNamesByCohort.get(cohort);srjDifferentialPairs.push({connectionNames:[positiveSrjConnectionName,negativeSrjConnectionName],lengthTolerance,...differentialPair._parsedProps.pcbTraceGap!==void 0?{traceGap:differentialPair._parsedProps.pcbTraceGap}:{},...differentialPair._parsedProps.maxUncoupledLength!==void 0?{maxUncoupledLength:differentialPair._parsedProps.maxUncoupledLength}:{}})}}return srjDifferentialPairs.length>0?srjDifferentialPairs:void 0},getLayerName=layer=>typeof layer=="string"?layer:layer.name,getPreservedTraceConnectionName=trace=>trace.source_trace_id??trace.connection_name??trace.pcb_trace_id,getPhysicalConnectionIdsForPreservedTrace=trace=>{let physicallyConnectedIds=new Set(trace.connectsTo??[]);for(let routePoint3 of trace.route)if(routePoint3.route_type==="wire")for(let pcbPortId of[routePoint3.start_pcb_port_id,routePoint3.end_pcb_port_id])pcbPortId&&physicallyConnectedIds.add(pcbPortId);return Array.from(physicallyConnectedIds)},getSimpleRouteForPreservedTrace=trace=>trace.route.map(routePoint3=>{if(routePoint3.route_type==="wire")return{route_type:"wire",x:routePoint3.x,y:routePoint3.y,width:routePoint3.width,layer:getLayerName(routePoint3.layer)};if(routePoint3.route_type==="via"){let preservedViaRoutePoint=routePoint3,viaDiameter=preservedViaRoutePoint.outer_diameter??preservedViaRoutePoint.via_diameter,viaHoleDiameter=preservedViaRoutePoint.hole_diameter??preservedViaRoutePoint.via_hole_diameter;return{route_type:"via",x:routePoint3.x,y:routePoint3.y,from_layer:getLayerName(routePoint3.from_layer),to_layer:getLayerName(routePoint3.to_layer),...viaDiameter!==void 0?{via_diameter:viaDiameter}:{},...viaHoleDiameter!==void 0?{via_hole_diameter:viaHoleDiameter}:{}}}return{route_type:"through_obstacle",start:routePoint3.start,end:routePoint3.end,from_layer:getLayerName(routePoint3.start_layer),to_layer:getLayerName(routePoint3.end_layer),width:routePoint3.width}}),getPreservedRoutedSubcircuitTraces=({scopedDb,relevantSubcircuitIds})=>scopedDb.pcb_trace.list().filter(trace=>!trace.subcircuit_id||trace.pcb_component_id&&!trace.source_trace_id?!1:relevantSubcircuitIds===null||relevantSubcircuitIds.has(trace.subcircuit_id)).map(trace=>{let preservedTrace=trace,connectionName=getPreservedTraceConnectionName(preservedTrace);return{type:"pcb_trace",pcb_trace_id:trace.pcb_trace_id,source_trace_id:trace.source_trace_id,connection_name:connectionName,connectsTo:getPhysicalConnectionIdsForPreservedTrace(preservedTrace),route:getSimpleRouteForPreservedTrace(preservedTrace)}}).filter(trace=>trace.route.length>=2),COPPER_POUR_RECT_HEIGHT=.5,dedupeStrings2=values=>Array.from(new Set(values.filter(value=>!!value))),getLayerName2=layer=>typeof layer=="string"?layer:layer.name,createCopperPourObstacle=({layer,connectedTo,center:center2,width,height})=>({type:"rect",layers:[layer],center:center2,width,height,connectedTo,isCopperPour:!0}),getCopperPourBoundary=({outline,group:group2,board})=>outline&&outline.length>=3?outline:group2?.outline&&group2.outline.length>=3?group2.outline:board?.outline&&board.outline.length>=3?board.outline:null,getCopperPourBoundsRect=({group:group2,board})=>group2?.width&&group2.height?{center:group2.center,width:group2.width,height:group2.height}:board?.width&&board.height?{center:board.center,width:board.width,height:board.height}:null,getCopperPourConnectedTo=(net,connMap)=>dedupeStrings2([net.source_net_id,net.subcircuit_connectivity_map_key,net.source_net_id?connMap.getNetConnectedToId(net.source_net_id):null]),getUnbrokenCopperPourObstacles=({connMap,subcircuitComponent,board,group:group2})=>{if(!subcircuitComponent)return[];let obstacles=[],copperPours=subcircuitComponent.selectAll("copperpour");for(let copperPour of copperPours){let props=copperPour._parsedProps;if(!props.unbroken)continue;let net=copperPour.getSubcircuit().selectOne(props.connectsTo);if(!net?.source_net_id)continue;let layer=getLayerName2(props.layer),connectedTo=getCopperPourConnectedTo(net,connMap);if(connectedTo.length===0)continue;let boundary=getCopperPourBoundary({outline:props.outline,group:group2,board});if(boundary){let rects=fillPolygonWithRects(boundary,{rectHeight:COPPER_POUR_RECT_HEIGHT});if(rects.length>0){obstacles.push(...rects.map(rect=>createCopperPourObstacle({layer,connectedTo,center:rect.center,width:rect.width,height:rect.height})));continue}}let boundsRect=getCopperPourBoundsRect({group:group2,board});boundsRect&&obstacles.push(createCopperPourObstacle({layer,connectedTo,center:boundsRect.center,width:boundsRect.width,height:boundsRect.height}))}return obstacles},getSrjConnectionPointsFromPcbTraceHints=(connectedPcbPorts,pcbTraceHints)=>{let connectedPcbPortById=new Map(connectedPcbPorts.map(pcbPort=>[pcbPort.pcb_port_id,pcbPort]));return pcbTraceHints.flatMap(pcbTraceHint=>{let pcbPort=connectedPcbPortById.get(pcbTraceHint.pcb_port_id);if(!pcbPort)return[];let layer=pcbPort.layers?.[0]??"top";return pcbTraceHint.route.map(routePoint3=>({x:routePoint3.x,y:routePoint3.y,layer}))})},getOwningPcbBoardForSubcircuit=(db22,subcircuitId)=>{let visitedSubcircuitIds=new Set,currentSubcircuitId=subcircuitId,isRequestedSubcircuit=!0;for(;currentSubcircuitId&&!visitedSubcircuitIds.has(currentSubcircuitId);){visitedSubcircuitIds.add(currentSubcircuitId);let sourceGroup=db22.source_group.getWhere({subcircuit_id:currentSubcircuitId}),sourceBoard=sourceGroup?db22.source_board.getWhere({source_group_id:sourceGroup.source_group_id}):void 0;if(sourceBoard)return{board:db22.pcb_board.getWhere({source_board_id:sourceBoard.source_board_id})??null,subcircuitIsBoard:isRequestedSubcircuit};currentSubcircuitId=sourceGroup?.parent_subcircuit_id??null,isRequestedSubcircuit=!1}return{board:null,subcircuitIsBoard:!1}},getSimpleRouteJsonFromCircuitJson=({db:db22,circuitJson,subcircuit_id,minTraceWidth,minTraceToPadEdgeClearance,minTraceToHoleEdgeClearance,minViaEdgeToPadEdgeClearance,minViaHoleEdgeToViaHoleEdgeClearance,minPlatedHoleDrillEdgeToDrillEdgeClearance,minPadEdgeToPadEdgeClearance,minBoardEdgeClearance,minViaHoleDiameter,minViaPadDiameter,nominalTraceWidth,subcircuitComponent,routingPcbGroupId,fanoutPourNetMap,ignoreExistingTopLevelPcbRouteState=!1})=>{if(!db22&&circuitJson&&(db22=su3(circuitJson)),!db22)throw new Error("db or circuitJson is required");let traceHints=db22.pcb_trace_hint.list(),relevantSubcircuitIds=subcircuit_id?new Set([subcircuit_id]):null;if(subcircuit_id){let descendantSubcircuitIds=getDescendantSubcircuitIds2(db22,subcircuit_id);for(let id3 of descendantSubcircuitIds)relevantSubcircuitIds.add(id3)}let allElements=circuitJson??db22.toArray(),sourceTraceById=new Map(allElements.flatMap(element=>element.type==="source_trace"?[[element.source_trace_id,element]]:[])),subcircuitElements=allElements.map(element=>{if(ignoreExistingTopLevelPcbRouteState||element.type!=="pcb_trace"||element.subcircuit_id||!element.source_trace_id)return element;let inheritedSubcircuitId=sourceTraceById.get(element.source_trace_id)?.subcircuit_id;return inheritedSubcircuitId?{...element,subcircuit_id:inheritedSubcircuitId}:element}).filter(e210=>!subcircuit_id||"subcircuit_id"in e210&&relevantSubcircuitIds.has(e210.subcircuit_id)),board=null,subcircuitIsBoard=!1;if(subcircuit_id){let owningBoard=getOwningPcbBoardForSubcircuit(db22,subcircuit_id);board=owningBoard.board,subcircuitIsBoard=owningBoard.subcircuitIsBoard&&board!==null}board||(board=db22.pcb_board.list()[0]),db22=su3(subcircuitElements);let getPortSelector=sourcePort=>{if(!sourcePort?.source_component_id)return;let sourceComponent=db22.source_component.get(sourcePort.source_component_id);if(sourceComponent?.name)return`${sourceComponent.name}.${sourcePort.name}`},pcbGroup=routingPcbGroupId?db22.pcb_group.get(routingPcbGroupId):subcircuit_id?db22.pcb_group.getWhere({subcircuit_id}):void 0,activeRoutingPcbGroupId=subcircuitComponent?.pcb_group_id;activeRoutingPcbGroupId==null&&!subcircuitIsBoard&&(activeRoutingPcbGroupId=pcbGroup?.pcb_group_id);let sharedConnMap=getFullConnectivityMapFromCircuitJson(subcircuitElements),breakoutPoints=db22.pcb_breakout_point.list().filter(bp22=>!subcircuit_id||relevantSubcircuitIds?.has(bp22.subcircuit_id)),breakoutPointIsInActiveRoutingGroup=breakoutPoint=>breakoutPoint.subcircuit_id===subcircuit_id&&(activeRoutingPcbGroupId?breakoutPoint.pcb_group_id===activeRoutingPcbGroupId:!subcircuitIsBoard),preservedRoutedSubcircuitTraces=getPreservedRoutedSubcircuitTraces({scopedDb:db22,relevantSubcircuitIds}),preservedSrjTraceByPcbTraceId=new Map(preservedRoutedSubcircuitTraces.map(trace=>[trace.pcb_trace_id,trace])),isPcbViaRepresentedByPreservedSrjTrace=via=>{if(!via.pcb_trace_id)return!1;let preservedTrace=preservedSrjTraceByPcbTraceId.get(via.pcb_trace_id);if(!preservedTrace)return!1;let pcbViaLayerNames=new Set(via.layers);return preservedTrace.route.some(routePoint3=>{if(routePoint3.route_type!=="via"||routePoint3.x!==via.x||routePoint3.y!==via.y)return!1;let routeViaLayerNames=new Set(getViaSpanLayers({fromLayer:routePoint3.from_layer,toLayer:routePoint3.to_layer,layerCount:board?.num_layers??2}));return routeViaLayerNames.size===pcbViaLayerNames.size&&[...routeViaLayerNames].every(layer=>pcbViaLayerNames.has(layer))})},obstacles=getObstaclesFromCircuitJson2([...board?[board]:[],...db22.source_component.list(),...db22.source_port.list(),...db22.pcb_port.list(),...db22.pcb_component.list(),...db22.pcb_smtpad.list(),...db22.pcb_plated_hole.list(),...db22.pcb_hole.list(),...db22.pcb_trace.list().filter(trace=>!trace.source_trace_id),...db22.pcb_via.list().filter(via=>(!ignoreExistingTopLevelPcbRouteState||!!via.subcircuit_id)&&!isPcbViaRepresentedByPreservedSrjTrace(via)),...db22.pcb_keepout.list(),...db22.pcb_cutout.list()].filter(e210=>e210.type==="pcb_board"||!subcircuit_id||relevantSubcircuitIds?.has(e210.subcircuit_id)),sharedConnMap);obstacles.push(...getUnbrokenCopperPourObstacles({connMap:sharedConnMap,subcircuitComponent,board,group:pcbGroup}));for(let obstacle of obstacles){let additionalIds=obstacle.connectedTo.flatMap(id3=>sharedConnMap.getIdsConnectedToNet(id3));obstacle.connectedTo=[...new Set([...obstacle.connectedTo,...additionalIds])]}let internalConnections=db22.source_component_internal_connection.list(),sourcePortIdToInternalConnectionId=new Map;for(let ic3 of internalConnections)for(let sourcePortId of ic3.source_port_ids)sourcePortIdToInternalConnectionId.set(sourcePortId,ic3.source_component_internal_connection_id);let pcbElementIdToSourcePortId=new Map;for(let pcbPort of db22.pcb_port.list())if(pcbPort.source_port_id){let smtpad2=db22.pcb_smtpad.getWhere({pcb_port_id:pcbPort.pcb_port_id});smtpad2&&pcbElementIdToSourcePortId.set(smtpad2.pcb_smtpad_id,pcbPort.source_port_id);let platedHole2=db22.pcb_plated_hole.getWhere({pcb_port_id:pcbPort.pcb_port_id});platedHole2&&pcbElementIdToSourcePortId.set(platedHole2.pcb_plated_hole_id,pcbPort.source_port_id)}for(let obstacle of obstacles)for(let connectedId of obstacle.connectedTo){let sourcePortId=pcbElementIdToSourcePortId.get(connectedId);if(sourcePortId){let internalConnectionId=sourcePortIdToInternalConnectionId.get(sourcePortId);if(internalConnectionId){obstacle.offBoardConnectsTo=[internalConnectionId],obstacle.netIsAssignable=!0;break}}}let allPoints=obstacles.flatMap(o22=>[{x:o22.center.x-o22.width/2,y:o22.center.y-o22.height/2},{x:o22.center.x+o22.width/2,y:o22.center.y+o22.height/2}]).concat(board?.outline??[]),boardBounds=board&&!board.outline?{minX:board.center.x-board.width/2,maxX:board.center.x+board.width/2,minY:board.center.y-board.height/2,maxY:board.center.y+board.height/2}:void 0,bounds,useGroupBoundsAsSrjBounds=!!(pcbGroup?.width&&pcbGroup.height&&subcircuit_id&&!subcircuitIsBoard);if(useGroupBoundsAsSrjBounds?bounds={minX:pcbGroup.center.x-pcbGroup.width/2,maxX:pcbGroup.center.x+pcbGroup.width/2,minY:pcbGroup.center.y-pcbGroup.height/2,maxY:pcbGroup.center.y+pcbGroup.height/2}:boardBounds?bounds=boardBounds:bounds={minX:Math.min(...allPoints.map(p22=>p22.x))-1,maxX:Math.max(...allPoints.map(p22=>p22.x))+1,minY:Math.min(...allPoints.map(p22=>p22.y))-1,maxY:Math.max(...allPoints.map(p22=>p22.y))+1},pcbGroup?.width&&pcbGroup.height&&!useGroupBoundsAsSrjBounds){let groupBounds={minX:pcbGroup.center.x-pcbGroup.width/2,maxX:pcbGroup.center.x+pcbGroup.width/2,minY:pcbGroup.center.y-pcbGroup.height/2,maxY:pcbGroup.center.y+pcbGroup.height/2};bounds={minX:Math.min(bounds.minX,groupBounds.minX),maxX:Math.max(bounds.maxX,groupBounds.maxX),minY:Math.min(bounds.minY,groupBounds.minY),maxY:Math.max(bounds.maxY,groupBounds.maxY)}}let sourceTraceIdsAlreadyPreservedAsSrjTraces=new Set(db22.pcb_trace.list().filter(t48=>t48.source_trace_id?subcircuit_id?t48.subcircuit_id===subcircuit_id:t48.subcircuit_id?db22.source_trace.get(t48.source_trace_id)?.subcircuit_id===t48.subcircuit_id:!1:!1).map(t48=>t48.source_trace_id).filter(id3=>!!id3)),sourcePortIdToBreakoutPoint=new Map;for(let bp22 of breakoutPoints){let spId=bp22.source_port_id;spId&&sourcePortIdToBreakoutPoint.set(spId,bp22)}let getPcbPortRoutePoint=pcbPort=>{let layer=pcbPort.layers?.[0]??"top",breakoutPoint=sourcePortIdToBreakoutPoint.get(pcbPort.source_port_id),portSelector=getPortSelector(db22.source_port.get(pcbPort.source_port_id));return breakoutPoint&&!breakoutPointIsInActiveRoutingGroup(breakoutPoint)?{x:breakoutPoint.x,y:breakoutPoint.y,layer:breakoutPoint.layer??layer,pointId:breakoutPoint.pcb_breakout_point_id,port_selector:portSelector}:{x:pcbPort.x,y:pcbPort.y,layer,pointId:pcbPort.pcb_port_id,pcb_port_id:pcbPort.pcb_port_id,port_selector:portSelector}},sourceTraces=db22.source_trace.list(),planeTerminatedSourceTraceLayers=getPlaneTerminatedSourceTraceLayers({fanoutPourNetMap,sourceNets:db22.source_net.list(),sourceTraces,subcircuitId:subcircuit_id}),directTraceConnections=sourceTraces.filter(trace=>!sourceTraceIdsAlreadyPreservedAsSrjTraces.has(trace.source_trace_id)).filter(trace=>!subcircuit_id||trace.subcircuit_id===subcircuit_id).filter(sourceTrace=>sourceTrace.connected_source_net_ids.length===0||planeTerminatedSourceTraceLayers.has(sourceTrace.source_trace_id)).map(trace=>{let connectedPcbPorts=trace.connected_source_port_ids.map(sourcePortId=>db22.pcb_port.getWhere({source_port_id:sourcePortId})).filter(pcbPort=>pcbPort!==null),isPlaneTerminatedSourceTrace=planeTerminatedSourceTraceLayers.has(trace.source_trace_id);if(connectedPcbPorts.length<2&&!(isPlaneTerminatedSourceTrace&&connectedPcbPorts.length===1))return null;for(let connectedPort of connectedPcbPorts)if(connectedPort.x===void 0||connectedPort.y===void 0)return console.error(`(source_port_id: ${connectedPort.source_port_id}) for trace ${trace.source_trace_id} does not have x/y coordinates. Skipping this trace.`),null;let srjTraceHintConnectionPoints=getSrjConnectionPointsFromPcbTraceHints(connectedPcbPorts,traceHints),connectedPortRoutePoints=connectedPcbPorts.map(port=>getPcbPortRoutePoint(port)),[firstConnectedPortRoutePoint,...remainingPortRoutePoints]=connectedPortRoutePoints;return{name:trace.source_trace_id??sharedConnMap.getNetConnectedToId(trace.source_trace_id)??"",source_trace_id:trace.source_trace_id,nominalTraceWidth:trace.min_trace_thickness,width:trace.min_trace_thickness,pointsToConnect:[firstConnectedPortRoutePoint,...srjTraceHintConnectionPoints,...remainingPortRoutePoints]}}).filter(c22=>c22!==null),source_nets=db22.source_net.list().filter(e210=>!subcircuit_id||e210.subcircuit_id===subcircuit_id),connectionsFromNets=[],connectionFromNetId=new Map,handledNetConnectivityKeys=new Set,sourceNetIds=new Set(source_nets.map(net=>net.source_net_id)),currentSubcircuitSourceTraces=db22.source_trace.list().filter(trace=>!subcircuit_id||trace.subcircuit_id===subcircuit_id),exposedBridgeSourceTraceIds=new Set((subcircuitComponent?.selectAll("trace")??[]).flatMap(trace=>{let candidate=trace;return candidate._exposesSubcircuitConnection&&candidate.source_trace_id?[candidate.source_trace_id]:[]})),exposedDescendantSourceNetIds=new Set;for(let trace of currentSubcircuitSourceTraces)if(exposedBridgeSourceTraceIds.has(trace.source_trace_id))for(let sourceNetId of trace.connected_source_net_ids??[])sourceNetIds.has(sourceNetId)||exposedDescendantSourceNetIds.add(sourceNetId);let routedDescendantSourceTraceIds=new Set(subcircuit_id?db22.pcb_trace.list().filter(trace=>trace.subcircuit_id&&trace.subcircuit_id!==subcircuit_id&&relevantSubcircuitIds?.has(trace.subcircuit_id)).map(trace=>trace.source_trace_id).filter(id3=>!!id3):[]),sourceTracesEligibleForNetConnections=db22.source_trace.list().filter(trace=>!planeTerminatedSourceTraceLayers.has(trace.source_trace_id)).filter(trace=>!sourceTraceIdsAlreadyPreservedAsSrjTraces.has(trace.source_trace_id)||subcircuit_id!=null&&trace.subcircuit_id===subcircuit_id).filter(trace=>!subcircuit_id||trace.subcircuit_id===subcircuit_id||(trace.connected_source_net_ids?.some(id3=>sourceNetIds.has(id3))??!1)||(trace.connected_source_net_ids?.some(id3=>exposedDescendantSourceNetIds.has(id3))??!1)&&!routedDescendantSourceTraceIds.has(trace.source_trace_id)),getSourceConnectivityKey=id3=>id3?sharedConnMap.getNetConnectedToId(id3)??id3:null;for(let net of source_nets){let netConnectivityKey=getSourceConnectivityKey(net.source_net_id);if(!netConnectivityKey||handledNetConnectivityKeys.has(netConnectivityKey))continue;handledNetConnectivityKeys.add(netConnectivityKey);let connectedSourceNets=source_nets.filter(sourceNet=>getSourceConnectivityKey(sourceNet.source_net_id)===netConnectivityKey),connectedSourceNetIds=connectedSourceNets.map(sourceNet=>sourceNet.source_net_id),connectedSourceTraces=sourceTracesEligibleForNetConnections.filter(st22=>[st22.source_trace_id,...st22.connected_source_net_ids??[]].some(id3=>getSourceConnectivityKey(id3)===netConnectivityKey)),nominalTraceWidthForConnection;for(let sourceNet of connectedSourceNets)sourceNet.trace_width!==void 0&&(nominalTraceWidthForConnection=Math.max(nominalTraceWidthForConnection??0,sourceNet.trace_width));for(let sourceTrace of connectedSourceTraces)sourceTrace.min_trace_thickness!==void 0&&(nominalTraceWidthForConnection=Math.max(nominalTraceWidthForConnection??0,sourceTrace.min_trace_thickness));let pointsToConnect=[],addedPointIds=new Set,connectedPcbPorts=[];for(let st22 of connectedSourceTraces){let pcb_ports=db22.pcb_port.list().filter(p22=>st22.connected_source_port_ids.includes(p22.source_port_id));for(let p22 of pcb_ports){let routePoint3=getPcbPortRoutePoint(p22);addedPointIds.has(routePoint3.pointId)||(addedPointIds.add(routePoint3.pointId),connectedPcbPorts.push(p22),pointsToConnect.push(routePoint3))}}pointsToConnect.push(...getSrjConnectionPointsFromPcbTraceHints(connectedPcbPorts,traceHints));let connection={name:net.source_net_id??sharedConnMap.getNetConnectedToId(net.source_net_id),nominalTraceWidth:nominalTraceWidthForConnection,width:nominalTraceWidthForConnection,pointsToConnect};if(pointsToConnect.length!==0){connectionsFromNets.push(connection);for(let sourceNetId of connectedSourceNetIds)connectionFromNetId.set(sourceNetId,connection)}}let connectionsFromBreakoutPoints=[];for(let bp22 of breakoutPoints){let bpSourcePortId=bp22.source_port_id,pt22={x:bp22.x,y:bp22.y,layer:bp22.layer??"top",pointId:bp22.pcb_breakout_point_id};if(bpSourcePortId){let pcb_port3=db22.pcb_port.getWhere({source_port_id:bpSourcePortId});if(!pcb_port3)continue;let portPt={x:pcb_port3.x,y:pcb_port3.y,layer:pcb_port3.layers?.[0]??"top",pointId:pcb_port3.pcb_port_id,pcb_port_id:pcb_port3.pcb_port_id,port_selector:getPortSelector(db22.source_port.get(pcb_port3.source_port_id))},isInActiveRoutingGroup=breakoutPointIsInActiveRoutingGroup(bp22),isInTransparentChildRoutingGroup=!isInActiveRoutingGroup&&bp22.subcircuit_id===subcircuit_id;if(isInActiveRoutingGroup||isInTransparentChildRoutingGroup){connectionsFromBreakoutPoints.push({name:isInTransparentChildRoutingGroup?`breakout:${bp22.pcb_breakout_point_id}`:bpSourcePortId,source_trace_id:bp22.source_trace_id,routingPcbGroupId:isInTransparentChildRoutingGroup?bp22.pcb_group_id:void 0,pointsToConnect:[portPt,pt22]});continue}bp22.source_trace_id||connectionsFromBreakoutPoints.push({name:bpSourcePortId,pointsToConnect:[portPt,pt22]});continue}if(bp22.source_net_id){let conn=connectionFromNetId.get(bp22.source_net_id);conn?conn.pointsToConnect.push(pt22):connectionsFromBreakoutPoints.push({name:bp22.source_net_id,pointsToConnect:[pt22]})}}let routableConnectionsFromNets=connectionsFromNets.filter(connection=>connection.pointsToConnect.length>=2),allConns=[...directTraceConnections,...routableConnectionsFromNets,...connectionsFromBreakoutPoints],defaultTraceWidth=minTraceWidth??board?.min_trace_width??.1;for(let conn of allConns)conn.nominalTraceWidth??(conn.nominalTraceWidth=nominalTraceWidth??defaultTraceWidth),conn.width??(conn.width=nominalTraceWidth??defaultTraceWidth);bounds=expandSrjBoundsToIncludeConnectionPoints({bounds,connections:allConns});let differentialPairs=subcircuitComponent?.selectAll("differentialpair")??[],buses=subcircuitComponent?.selectAll("bus")??[],srjDifferentialPairs=getDifferentialPairsForSimpleRouteJson({srjConnections:allConns,differentialPairs,sourceTraces:db22.source_trace.list(),subcircuitId:subcircuit_id}),srjBuses=getBusesForSimpleRouteJson({srjConnections:allConns,buses,sourceTraces:db22.source_trace.list(),subcircuitId:subcircuit_id,planeTerminatedSourceTraceLayers,preservedSourceTraceIds:sourceTraceIdsAlreadyPreservedAsSrjTraces});if(subcircuit_id){let pointIdToConn=new Map;for(let conn of allConns)for(let pt22 of conn.pointsToConnect)pt22.pointId&&pointIdToConn.set(pt22.pointId,conn);let existingTraces=db22.pcb_trace.list().filter(t48=>relevantSubcircuitIds?.has(t48.subcircuit_id));for(let tr3 of existingTraces){let tracePortIds=new Set;for(let seg of tr3.route)seg.start_pcb_port_id&&tracePortIds.add(seg.start_pcb_port_id),seg.end_pcb_port_id&&tracePortIds.add(seg.end_pcb_port_id);if(tracePortIds.size<2)continue;let firstId=tracePortIds.values().next().value;if(!firstId)continue;let conn=pointIdToConn.get(firstId);conn&&[...tracePortIds].every(pid=>pointIdToConn.get(pid)===conn)&&(conn.externallyConnectedPointIds??(conn.externallyConnectedPointIds=[]),conn.externallyConnectedPointIds.push([...tracePortIds]))}}let resolvedMinViaHoleDiameter=minViaHoleDiameter??board?.min_via_hole_diameter,resolvedMinViaPadDiameter=minViaPadDiameter??board?.min_via_pad_diameter,resolvedMinTraceToHoleEdgeClearance=minTraceToHoleEdgeClearance??board?.min_trace_to_hole_edge_clearance,resolvedMinTraceToPadEdgeClearance=minTraceToPadEdgeClearance??board?.min_trace_to_pad_edge_clearance,resolvedMinViaEdgeToPadEdgeClearance=minViaEdgeToPadEdgeClearance??board?.min_via_edge_to_pad_edge_clearance,resolvedMinViaHoleEdgeToViaHoleEdgeClearance=minViaHoleEdgeToViaHoleEdgeClearance??board?.min_via_hole_edge_to_via_hole_edge_clearance,resolvedMinPlatedHoleDrillEdgeToDrillEdgeClearance=minPlatedHoleDrillEdgeToDrillEdgeClearance??board?.min_plated_hole_drill_edge_to_drill_edge_clearance,resolvedMinPadEdgeToPadEdgeClearance=minPadEdgeToPadEdgeClearance??board?.min_pad_edge_to_pad_edge_clearance,resolvedMinBoardEdgeClearance=minBoardEdgeClearance??board?.min_board_edge_clearance;return{simpleRouteJson:{bounds,obstacles,connections:allConns,differentialPairs:srjDifferentialPairs,...srjBuses?{buses:srjBuses}:{},traces:preservedRoutedSubcircuitTraces.length>0?preservedRoutedSubcircuitTraces:void 0,layerCount:board?.num_layers??2,allowBlindAndBuriedVias:board?.allow_blind_and_buried_vias??!1,minTraceWidth:Math.min(defaultTraceWidth,...allConns.map(c22=>c22.width)),minViaDiameter:resolvedMinViaPadDiameter,minViaHoleDiameter:resolvedMinViaHoleDiameter,minViaPadDiameter:resolvedMinViaPadDiameter,min_via_hole_diameter:resolvedMinViaHoleDiameter,min_via_pad_diameter:resolvedMinViaPadDiameter,minTraceToPadEdgeClearance:resolvedMinTraceToPadEdgeClearance,minTraceToHoleEdgeClearance:resolvedMinTraceToHoleEdgeClearance,minViaEdgeToPadEdgeClearance:resolvedMinViaEdgeToPadEdgeClearance,minViaHoleEdgeToViaHoleEdgeClearance:resolvedMinViaHoleEdgeToViaHoleEdgeClearance,minPlatedHoleDrillEdgeToDrillEdgeClearance:resolvedMinPlatedHoleDrillEdgeToDrillEdgeClearance,minPadEdgeToPadEdgeClearance:resolvedMinPadEdgeToPadEdgeClearance,minBoardEdgeClearance:resolvedMinBoardEdgeClearance,nominalTraceWidth,outline:getSrjOutlineForRoutingBounds({bounds:boardBounds??bounds,outline:board?.outline?.map(point62=>({...point62}))},bounds)},connMap:sharedConnMap}},unroutedElementTypes=new Set(["pcb_trace","pcb_trace_error"]),unrouteCircuitJson=circuitJson=>circuitJson.filter(element=>!unroutedElementTypes.has(element.type)),getPhaseTimingsFromRenderEvents=renderEvents=>{let phaseTimings={};if(!renderEvents)return phaseTimings;for(let renderPhase of orderedRenderPhases)phaseTimings[renderPhase]=0;let startEvents=new Map;for(let event of renderEvents){let[,,phase,eventType]=event.type.split(":");if(eventType==="start"){startEvents.set(`${phase}:${event.renderId}`,event);continue}if(eventType==="end"){let startEvent=startEvents.get(`${phase}:${event.renderId}`);if(startEvent){let duration=event.createdAt-startEvent.createdAt;phaseTimings[phase]=(phaseTimings[phase]||0)+duration}}}return phaseTimings},normalizePinLabels=inputPinLabels=>{let unqInputPinLabels=inputPinLabels.map(labels=>[...new Set(labels)]),result=unqInputPinLabels.map(()=>[]),desiredNumbers=unqInputPinLabels.map(()=>null);for(let i22=0;i22<unqInputPinLabels.length;i22++)for(let label of unqInputPinLabels[i22])if(/^\d+$/.test(label)){desiredNumbers[i22]=Number.parseInt(label);break}let highestPinNumber=0,alreadyAcceptedDesiredNumbers=new Set;for(let i22=0;i22<desiredNumbers.length;i22++){let desiredNumber=desiredNumbers[i22];if(desiredNumber===null||desiredNumber<1)continue;if(!alreadyAcceptedDesiredNumbers.has(desiredNumber)){alreadyAcceptedDesiredNumbers.add(desiredNumber),result[i22].push(`pin${desiredNumber}`),highestPinNumber=Math.max(highestPinNumber,desiredNumber);continue}let existingAltsForPin=0;for(let label of result[i22])label.startsWith(`pin${desiredNumber}_alt`)&&existingAltsForPin++;result[i22].push(`pin${desiredNumber}_alt${existingAltsForPin+1}`)}for(let i22=0;i22<result.length;i22++)result[i22][0]?.includes("_alt")&&(highestPinNumber++,result[i22].unshift(`pin${highestPinNumber}`));for(let i22=0;i22<result.length;i22++)result[i22].length===0&&(highestPinNumber++,result[i22].push(`pin${highestPinNumber}`));let totalLabelCounts={};for(let inputLabels of unqInputPinLabels)for(let label of inputLabels)/^\d+$/.test(label)||(totalLabelCounts[label]=(totalLabelCounts[label]??0)+1);let incrementalLabelCounts={};for(let i22=0;i22<unqInputPinLabels.length;i22++){let inputLabels=unqInputPinLabels[i22];for(let label of inputLabels)/^\d+$/.test(label)||(totalLabelCounts[label]===1?result[i22].push(label):(incrementalLabelCounts[label]=(incrementalLabelCounts[label]??0)+1,result[i22].push(`${label}${incrementalLabelCounts[label]}`)))}return result},TraceHint=class extends PrimitiveComponent2{constructor(){super(...arguments);__publicField(this,"matchedPort",null)}get config(){return{componentName:"TraceHint",zodProps:traceHintProps}}doInitialPortMatching(){let{db:db22}=this.root,{_parsedProps:props,parent}=this;if(!parent)return;if(parent.componentName==="Trace"){this.renderError(`Port inference inside trace is not yet supported (${this})`);return}if(!parent)throw new Error("TraceHint has no parent");if(!props.for){this.renderError(`TraceHint has no for property (${this})`);return}let port=parent.selectOne(props.for,{type:"port"});port||this.renderError(`${this} could not find port for selector "${props.for}"`),this.matchedPort=port,port.registerMatch(this)}getPcbRouteHints(){let{_parsedProps:props}=this,offsets=props.offset?[props.offset]:props.offsets;if(!offsets)return[];let globalTransform=this._computePcbGlobalTransformBeforeLayout();return offsets.map(offset2=>({...applyToPoint2(globalTransform,offset2),via:offset2.via,to_layer:offset2.to_layer,trace_width:offset2.trace_width}))}doInitialPcbTraceHintRender(){if(this.root?.pcbDisabled)return;let{db:db22}=this.root,{_parsedProps:props}=this;db22.pcb_trace_hint.insert({pcb_component_id:this.matchedPort?.pcb_component_id,pcb_port_id:this.matchedPort?.pcb_port_id,route:this.getPcbRouteHints()})}};function getTitleAnchorAndPosition({anchor:anchor3,x:x22,y:y22,width,height,isInside}){switch(anchor3){case"top_left":return{x:x22,y:y22+height,textAnchor:isInside?"top_left":"bottom_left"};case"top_center":return{x:x22+width/2,y:y22+height,textAnchor:isInside?"top_center":"bottom_center"};case"top_right":return{x:x22+width,y:y22+height,textAnchor:isInside?"top_right":"bottom_right"};case"center_left":return{x:x22,y:y22+height/2,textAnchor:isInside?"center_left":"center_right"};case"center":return{x:x22+width/2,y:y22+height/2,textAnchor:"center"};case"center_right":return{x:x22+width,y:y22+height/2,textAnchor:isInside?"center_right":"center_left"};case"bottom_left":return{x:x22,y:y22,textAnchor:isInside?"bottom_left":"top_left"};case"bottom_center":return{x:x22+width/2,y:y22,textAnchor:isInside?"bottom_center":"top_center"};case"bottom_right":return{x:x22+width,y:y22,textAnchor:isInside?"bottom_right":"top_right"};default:return{x:x22+width/2,y:y22+height,textAnchor:"center"}}}var getSchematicBoxPinLabels=pinLabels=>pinLabels?Object.entries(pinLabels).map(([pinKey,pinLabel])=>{let pinNumber=getPinNumberFromPinLabelsKey(pinKey);if(pinNumber===null)throw new Error(`Invalid schematicbox pinLabels key "${pinKey}". Expected pin<number>.`);let pinAliases=typeof pinLabel=="string"?[pinLabel]:[...pinLabel];return{pinNumber,displayPinLabel:pinAliases[0]??pinKey,pinAliases}}):[],getSchematicBoxPinStyleFromReferencedChip=({referencedChip,schematicBoxPins})=>{let referencedChipPinStyle=getNumericSchPinStyle(referencedChip._parsedProps.schPinStyle,referencedChip._parsedProps.pinLabels);if(!referencedChipPinStyle)return;let schematicBoxPinStyle={};for(let{pinNumber,referencedSourcePort}of schematicBoxPins){if(referencedSourcePort.pin_number===void 0)continue;let pinStyle=referencedChipPinStyle[`pin${referencedSourcePort.pin_number}`];pinStyle&&(schematicBoxPinStyle[`pin${pinNumber}`]=pinStyle)}return Object.keys(schematicBoxPinStyle).length>0?schematicBoxPinStyle:void 0},mergeSchematicBoxPinStyles=({inheritedPinStyle,overridePinStyle})=>{if(!inheritedPinStyle&&!overridePinStyle)return;let mergedPinStyle={...inheritedPinStyle};for(let[pinKey,pinStyle]of Object.entries(overridePinStyle??{}))mergedPinStyle[pinKey]={...mergedPinStyle[pinKey],...pinStyle};return Object.keys(mergedPinStyle).length>0?mergedPinStyle:void 0},SchematicBox_doInitialSchematicComponentRender=schematicBox=>{if(schematicBox.root?.schematicDisabled)return;let{db:db22}=schematicBox.root,props=schematicBox._parsedProps;if(!props.chipRef)return;let referencedChip=schematicBox.getSubcircuit().selectOne(props.chipRef);if(!referencedChip?.source_component_id)throw new Error(`Could not resolve chipRef "${props.chipRef}" for ${schematicBox.getString()}`);let schematicBoxPinLabels=getSchematicBoxPinLabels(props.pinLabels),pinLabelsByPinKey=Object.fromEntries(schematicBoxPinLabels.map(({pinNumber,displayPinLabel})=>[`pin${pinNumber}`,displayPinLabel])),sourcePorts=db22.source_port.list({source_component_id:referencedChip.source_component_id}),schematicBoxPins=schematicBoxPinLabels.map(schematicBoxPin=>{let referencedSourcePort=sourcePorts.find(sourcePort=>schematicBoxPin.pinAliases.some(pinAlias=>sourcePort.name===pinAlias||sourcePort.port_hints?.includes(pinAlias)));if(!referencedSourcePort)throw new Error(`Could not find pin "${schematicBoxPin.displayPinLabel}" on chipRef "${props.chipRef}"`);return{...schematicBoxPin,referencedSourcePort}}),inheritedPinStyle=getSchematicBoxPinStyleFromReferencedChip({referencedChip,schematicBoxPins}),schematicBoxPinStyle=mergeSchematicBoxPinStyles({inheritedPinStyle,overridePinStyle:getNumericSchPinStyle(props.schPinStyle,props.pinLabels)}),dimensions4=getAllDimensionsForSchematicBox({schWidth:props.width,schHeight:props.height,schPinSpacing:.2,pinCount:schematicBoxPinLabels.length,schPortArrangement:props.schPinArrangement,numericSchPinStyle:getNumericSchPinStyle(schematicBoxPinStyle),pinLabels:pinLabelsByPinKey}),center2=schematicBox._getGlobalSchematicPositionBeforeLayout(),size3=dimensions4.getSize(),schematicSheetId=schematicBox._resolveSchematicSheetId(),portLabels=Object.fromEntries(schematicBoxPinLabels.map(({pinNumber,displayPinLabel})=>[String(pinNumber),displayPinLabel])),schematicComponent=db22.schematic_component.insert({center:center2,size:size3,source_component_id:referencedChip.source_component_id,is_box_with_pins:!0,port_arrangement:underscorifyPortArrangement(props.schPinArrangement),port_labels:portLabels,pin_spacing:.2,pin_styles:underscorifyPinStyles(schematicBoxPinStyle),schematic_sheet_id:schematicSheetId});schematicBox.schematic_component_id=schematicComponent.schematic_component_id;for(let{pinNumber,displayPinLabel,referencedSourcePort}of schematicBoxPins){let portPosition=dimensions4.getPortPositionByPinNumber(pinNumber);if(!portPosition)throw new Error(`Could not determine schematic position for ${schematicBox.getString()} pin${pinNumber}`);let facingDirection={left:"left",right:"right",top:"up",bottom:"down"}[portPosition.side];db22.schematic_port.insert({schematic_component_id:schematicComponent.schematic_component_id,center:{x:center2.x+portPosition.x,y:center2.y+portPosition.y},source_port_id:referencedSourcePort.source_port_id,facing_direction:facingDirection,distance_from_component_edge:.4,side_of_component:portPosition.side,pin_number:pinNumber,true_ccw_index:portPosition.trueIndex,display_pin_label:displayPinLabel,is_connected:!1,schematic_sheet_id:schematicSheetId})}let sectionName=props.name??props.chipRef;db22.schematic_text.insert({text:sectionName,schematic_component_id:schematicComponent.schematic_component_id,anchor:"left",rotation:0,position:{x:center2.x-size3.width/2,y:center2.y+size3.height/2+.13},color:"#006464",font_size:.18,schematic_sheet_id:schematicSheetId});let referencedSourceComponent=db22.source_component.get(referencedChip.source_component_id);db22.schematic_text.insert({text:referencedSourceComponent?.manufacturer_part_number??"",schematic_component_id:schematicComponent.schematic_component_id,anchor:"left",rotation:0,position:{x:center2.x-size3.width/2,y:center2.y-size3.height/2-.13},color:"#006464",font_size:.18,schematic_sheet_id:schematicSheetId})},SchematicBox=class extends PrimitiveComponent2{constructor(){super(...arguments);__publicField(this,"isSchematicPrimitive",!0)}get config(){return{componentName:"SchematicBox",zodProps:schematicBoxProps,shouldRenderAsSchematicBox:!0}}doInitialSchematicComponentRender(){SchematicBox_doInitialSchematicComponentRender(this)}doInitialSchematicPrimitiveRender(){if(this.root?.schematicDisabled||this.getCollapsedSchematicBoxAncestor())return;let{db:db22}=this.root,{_parsedProps:props}=this;if(props.chipRef)return;let basePadding=.6,generalPadding=typeof props.padding=="number"?props.padding:0,paddingTop=typeof props.paddingTop=="number"?props.paddingTop:generalPadding,paddingBottom=typeof props.paddingBottom=="number"?props.paddingBottom:generalPadding,paddingLeft=typeof props.paddingLeft=="number"?props.paddingLeft:generalPadding,paddingRight=typeof props.paddingRight=="number"?props.paddingRight:generalPadding,hasOverlay=props.overlay&&props.overlay.length>0,hasFixedSize=typeof props.width=="number"&&typeof props.height=="number",width,height,x22,y22,centerX,centerY;if(hasOverlay){let portsWithPosition=props.overlay.map(selector2=>({selector:selector2,port:this.getSubcircuit().selectOne(selector2,{type:"port"})})).filter(({port})=>port!=null).map(({port})=>({position:port._getGlobalSchematicPositionAfterLayout()}));if(portsWithPosition.length===0)return;let xs3=portsWithPosition.map(p22=>p22.position.x),ys3=portsWithPosition.map(p22=>p22.position.y),minX=Math.min(...xs3),maxX=Math.max(...xs3),minY=Math.min(...ys3),maxY=Math.max(...ys3),rawWidth=maxX-minX,rawHeight=maxY-minY,defaultHorizontalPadding=rawWidth===0?basePadding:0,defaultVerticalPadding=rawHeight===0?basePadding:0,finalPaddingLeft=paddingLeft+defaultHorizontalPadding/2,finalPaddingRight=paddingRight+defaultHorizontalPadding/2,finalPaddingTop=paddingTop+defaultVerticalPadding/2,finalPaddingBottom=paddingBottom+defaultVerticalPadding/2,left=minX-finalPaddingLeft,right=maxX+finalPaddingRight,top=minY-finalPaddingBottom,bottom=maxY+finalPaddingTop;width=right-left,height=bottom-top,x22=left+(props.schX??0),y22=top+(props.schY??0),centerX=x22+width/2,centerY=y22+height/2}else if(hasFixedSize){width=props.width,height=props.height;let center2=this._getGlobalSchematicPositionBeforeLayout();centerX=center2.x,centerY=center2.y,x22=centerX-width/2,y22=centerY-height/2}else return;if(db22.schematic_box.insert({height,width,x:x22,y:y22,is_dashed:props.strokeStyle==="dashed",schematic_sheet_id:this._resolveSchematicSheetId()}),props.title){let isInside=props.titleInside,TITLE_PADDING=.1,anchor3=props.titleAlignment,anchorPos=getTitleAnchorAndPosition({anchor:anchor3,x:x22,y:y22,width,height,isInside}),titleOffsetY,titleOffsetX,textAnchor=anchorPos.textAnchor;isInside?(titleOffsetY=anchor3.includes("top")?-TITLE_PADDING:anchor3.includes("bottom")?TITLE_PADDING:0,titleOffsetX=anchor3.includes("left")?TITLE_PADDING:anchor3.includes("right")?-TITLE_PADDING:0):(titleOffsetY=anchor3.includes("top")?TITLE_PADDING:anchor3.includes("bottom")?-TITLE_PADDING:0,titleOffsetX=anchor3.includes("center_left")?-TITLE_PADDING:anchor3.includes("center_right")?TITLE_PADDING:0);let titleX=anchorPos.x+titleOffsetX,titleY=anchorPos.y+titleOffsetY;db22.schematic_text.insert({anchor:textAnchor,text:props.title,font_size:props.titleFontSize??.18,color:props.titleColor??"#000000",position:{x:titleX,y:titleY},rotation:0,schematic_sheet_id:this._resolveSchematicSheetId()})}}},Group_doInitialAssignSchematicSheetToConnectedComponents=group2=>{if(!group2.isSubcircuit||group2.root?.schematicDisabled)return;let{db:db22}=group2.root,schematicSheetIdsBySubcircuitConnectivityMapKey=new Map,schematicBoxReferencedSourceComponentIds=new Set,schematicBoxes=group2.getDescendants().filter(component=>component instanceof SchematicBox&&component.getSubcircuit()===group2);for(let schematicBox of schematicBoxes){let{chipRef,pinLabels}=schematicBox._parsedProps,schematicSheetId=schematicBox._resolveSchematicSheetId();if(!chipRef||!schematicSheetId)continue;let referencedComponent=schematicBox.getSubcircuit().selectOne(chipRef);if(!(referencedComponent instanceof NormalComponent)||!referencedComponent.source_component_id)continue;schematicBoxReferencedSourceComponentIds.add(referencedComponent.source_component_id);let referencedSourcePorts=db22.source_port.list({source_component_id:referencedComponent.source_component_id});for(let{pinAliases}of getSchematicBoxPinLabels(pinLabels)){let subcircuitConnectivityMapKey=referencedSourcePorts.find(sourcePort=>pinAliases.some(pinAlias=>sourcePort.name===pinAlias||sourcePort.port_hints?.includes(pinAlias)))?.subcircuit_connectivity_map_key;if(!subcircuitConnectivityMapKey)continue;let schematicSheetIds=schematicSheetIdsBySubcircuitConnectivityMapKey.get(subcircuitConnectivityMapKey)??new Set;schematicSheetIds.add(schematicSheetId),schematicSheetIdsBySubcircuitConnectivityMapKey.set(subcircuitConnectivityMapKey,schematicSheetIds)}}let normalComponents=group2.getDescendants().filter(component=>component instanceof NormalComponent&&component.getSubcircuit()===group2);for(let normalComponent of normalComponents){if(!normalComponent.source_component_id||schematicBoxReferencedSourceComponentIds.has(normalComponent.source_component_id)||normalComponent._resolveSchematicSheetId())continue;let connectedSchematicSheetIds=new Set,sourcePorts=db22.source_port.list({source_component_id:normalComponent.source_component_id});for(let sourcePort of sourcePorts){let subcircuitConnectivityMapKey=sourcePort.subcircuit_connectivity_map_key;if(!subcircuitConnectivityMapKey)continue;let schematicSheetIds=schematicSheetIdsBySubcircuitConnectivityMapKey.get(subcircuitConnectivityMapKey);if(schematicSheetIds)for(let schematicSheetId of schematicSheetIds)connectedSchematicSheetIds.add(schematicSheetId)}if(connectedSchematicSheetIds.size!==1)continue;let[inferredSchematicSheetId]=connectedSchematicSheetIds;inferredSchematicSheetId&&(normalComponent.schematic_sheet_id=inferredSchematicSheetId)}},SUPPORTED_COMPONENT_FIELDS=new Set(["x","y","minx","maxx","miny","maxy","width","height"]);function Group_doInitialPcbCalcPlacementResolution(group2){if(group2.root?.pcbDisabled||!group2.isSubcircuit)return;let{db:db22}=group2.root,normalComponentNameMap=group2.getNormalComponentNameMap?.()??new Map,allNormalComponents=collectNormalComponentsInSubcircuit(group2);if(!allNormalComponents.some(shouldResolvePlacementInCalcPhase))return;let namedComponentVars={};for(let component of allNormalComponents)updateVarsForNamedComponent(component,namedComponentVars);let candidatesByName=new Map,inDegree=new Map,dependents=new Map;for(let component of allNormalComponents){if(!shouldResolvePlacementInCalcPhase(component))continue;let refs=getComponentRefsForCalcPlacement(component);if(!component.name)throw new Error(`Invalid pcb position expression for ${component.getString()}: component-relative calc requires the component to have a name`);candidatesByName.set(component.name,{component,refs}),inDegree.set(component.name,0)}for(let[candidateName,candidate]of candidatesByName.entries()){let referencedCandidateNames=new Set;for(let token of candidate.refs){let{referencePath,field}=parseComponentReferenceToken(token);if(!SUPPORTED_COMPONENT_FIELDS.has(field))throw new Error(`Invalid pcb position expression for ${candidate.component.getString()}: unsupported component field "${field}" in "${token}"`);let referencedComponentName=resolveReferencedComponentName({token,referencePath,candidate,normalComponentNameMap});candidatesByName.has(referencedComponentName)&&referencedComponentName!==candidateName&&referencedCandidateNames.add(referencedComponentName)}for(let referencedComponentName of referencedCandidateNames)inDegree.set(candidateName,(inDegree.get(candidateName)??0)+1),dependents.has(referencedComponentName)||dependents.set(referencedComponentName,new Set),dependents.get(referencedComponentName).add(candidateName)}let queue=[...inDegree.entries()].filter(([,degree2])=>degree2===0).map(([name])=>name),resolvedCount=0;for(;queue.length>0;){let name=queue.shift(),candidate=candidatesByName.get(name);if(candidate){resolveCandidatePlacement(candidate.component,namedComponentVars),resolvedCount++;for(let dependentName of dependents.get(name)??[]){let nextDegree=(inDegree.get(dependentName)??0)-1;inDegree.set(dependentName,nextDegree),nextDegree===0&&queue.push(dependentName)}}}if(resolvedCount<candidatesByName.size){let unresolvedNames=[...candidatesByName.keys()].filter(name=>(inDegree.get(name)??0)>0);throw new Error(`Circular pcb position calc references detected among: ${unresolvedNames.join(", ")}`)}function resolveCandidatePlacement(component,componentVars){if(!component.pcb_component_id)return;let pcbComponent=db22.pcb_component.get(component.pcb_component_id);if(!pcbComponent)return;let rawPcbX=component._parsedProps.pcbX,rawPcbY=component._parsedProps.pcbY,rawComponentProps=component.props,rawPcbLeftEdgeX=component._parsedProps.pcbLeftEdgeX??rawComponentProps.pcbLeftEdgeX,rawPcbRightEdgeX=component._parsedProps.pcbRightEdgeX??rawComponentProps.pcbRightEdgeX,rawPcbTopEdgeY=component._parsedProps.pcbTopEdgeY??rawComponentProps.pcbTopEdgeY,rawPcbBottomEdgeY=component._parsedProps.pcbBottomEdgeY??rawComponentProps.pcbBottomEdgeY;if(rawPcbLeftEdgeX!==void 0&&rawPcbRightEdgeX!==void 0)throw new Error(`${component.componentName} cannot set both pcbLeftEdgeX and pcbRightEdgeX`);if(rawPcbTopEdgeY!==void 0&&rawPcbBottomEdgeY!==void 0)throw new Error(`${component.componentName} cannot set both pcbTopEdgeY and pcbBottomEdgeY`);let componentWidth=pcbComponent.width??0,componentHeight=pcbComponent.height??0,nextCenter={x:pcbComponent.center.x,y:pcbComponent.center.y};if(rawPcbX!==void 0){let resolvedPcbX=component.resolvePcbCoordinate({rawValue:rawPcbX,axis:"pcbX",allowComponentVariables:!0,componentVariables:componentVars});component._resolvedPcbCalcOffsetX=resolvedPcbX,nextCenter.x=resolvedPcbX}else if(rawPcbLeftEdgeX!==void 0){let resolvedPcbX=component.resolvePcbCoordinate({rawValue:rawPcbLeftEdgeX,axis:"pcbX",allowComponentVariables:!0,componentVariables:componentVars,propertyName:"pcbLeftEdgeX"})+componentWidth/2;component._resolvedPcbCalcOffsetX=resolvedPcbX,nextCenter.x=resolvedPcbX}else if(rawPcbRightEdgeX!==void 0){let resolvedPcbX=component.resolvePcbCoordinate({rawValue:rawPcbRightEdgeX,axis:"pcbX",allowComponentVariables:!0,componentVariables:componentVars,propertyName:"pcbRightEdgeX"})-componentWidth/2;component._resolvedPcbCalcOffsetX=resolvedPcbX,nextCenter.x=resolvedPcbX}if(rawPcbY!==void 0){let resolvedPcbY=component.resolvePcbCoordinate({rawValue:rawPcbY,axis:"pcbY",allowComponentVariables:!0,componentVariables:componentVars});component._resolvedPcbCalcOffsetY=resolvedPcbY,nextCenter.y=resolvedPcbY}else if(rawPcbTopEdgeY!==void 0){let resolvedPcbY=component.resolvePcbCoordinate({rawValue:rawPcbTopEdgeY,axis:"pcbY",allowComponentVariables:!0,componentVariables:componentVars,propertyName:"pcbTopEdgeY"})-componentHeight/2;component._resolvedPcbCalcOffsetY=resolvedPcbY,nextCenter.y=resolvedPcbY}else if(rawPcbBottomEdgeY!==void 0){let resolvedPcbY=component.resolvePcbCoordinate({rawValue:rawPcbBottomEdgeY,axis:"pcbY",allowComponentVariables:!0,componentVariables:componentVars,propertyName:"pcbBottomEdgeY"})+componentHeight/2;component._resolvedPcbCalcOffsetY=resolvedPcbY,nextCenter.y=resolvedPcbY}component._repositionOnPcb(nextCenter),updateVarsForNamedComponent(component,componentVars)}}function shouldResolvePlacementInCalcPhase(component){let parsedProps=component._parsedProps,rawProps=component.props,pcbX=parsedProps.pcbX,pcbY=parsedProps.pcbY,pcbLeftEdgeX=parsedProps.pcbLeftEdgeX??rawProps.pcbLeftEdgeX,pcbRightEdgeX=parsedProps.pcbRightEdgeX??rawProps.pcbRightEdgeX,pcbTopEdgeY=parsedProps.pcbTopEdgeY??rawProps.pcbTopEdgeY,pcbBottomEdgeY=parsedProps.pcbBottomEdgeY??rawProps.pcbBottomEdgeY;return pcbLeftEdgeX!==void 0||pcbRightEdgeX!==void 0||pcbTopEdgeY!==void 0||pcbBottomEdgeY!==void 0?!0:typeof pcbX=="string"||typeof pcbY=="string"}function collectNormalComponentsInSubcircuit(group2){let components=[],walk=node=>{node._isNormalComponent&&components.push(node);for(let child of node.children)child.isSubcircuit||walk(child)};for(let child of group2.children)child.isSubcircuit||walk(child);return components}function getComponentRefsForCalcPlacement(component){let refs=new Set,rawPcbX=component._parsedProps.pcbX,rawPcbY=component._parsedProps.pcbY,rawComponentProps=component.props,rawPcbLeftEdgeX=component._parsedProps.pcbLeftEdgeX??rawComponentProps.pcbLeftEdgeX,rawPcbRightEdgeX=component._parsedProps.pcbRightEdgeX??rawComponentProps.pcbRightEdgeX,rawPcbTopEdgeY=component._parsedProps.pcbTopEdgeY??rawComponentProps.pcbTopEdgeY,rawPcbBottomEdgeY=component._parsedProps.pcbBottomEdgeY??rawComponentProps.pcbBottomEdgeY,addRefs=rawValue=>{if(typeof rawValue!="string")return;let identifiers=extractCalcIdentifiers(rawValue);for(let identifier of identifiers)identifier.startsWith("board.")||refs.add(identifier)};return addRefs(rawPcbX),addRefs(rawPcbY),addRefs(rawPcbLeftEdgeX),addRefs(rawPcbRightEdgeX),addRefs(rawPcbTopEdgeY),addRefs(rawPcbBottomEdgeY),refs}function parseComponentReferenceToken(token){let dotIndex=token.lastIndexOf(".");if(dotIndex<=0||dotIndex===token.length-1)throw new Error(`Invalid component reference token: "${token}"`);return{referencePath:token.slice(0,dotIndex),field:token.slice(dotIndex+1).toLowerCase()}}function resolveReferencedComponentName(params){let{token,referencePath,candidate,normalComponentNameMap}=params,directComponents=normalComponentNameMap.get(referencePath);if(directComponents&&directComponents.length>0){if(directComponents.length>1)throw new Error(`Invalid pcb position expression for ${candidate.component.getString()}: ambiguous component reference "${referencePath}" in "${token}"`);return referencePath}let bestMatch=null;for(let componentName of normalComponentNameMap.keys())referencePath.startsWith(`${componentName}.`)&&(!bestMatch||componentName.length>bestMatch.length)&&(bestMatch=componentName);if(!bestMatch)throw new Error(`Invalid pcb position expression for ${candidate.component.getString()}: unknown component reference "${referencePath}" in "${token}"`);return bestMatch}function updateVarsForNamedComponent(component,vars){if(!component.name||!component.pcb_component_id||!component.root)return;let pcbComponent=component.root.db.pcb_component.get(component.pcb_component_id);if(!pcbComponent)return;let width=pcbComponent.width??0,height=pcbComponent.height??0,x22=pcbComponent.center.x,y22=pcbComponent.center.y;setSubcircuitPcbComponentCalcVariables({vars,componentName:component.name,position:{x:x22,y:y22},size:{width,height}});let padElementsByReference=collectPadElementsByReference(component);for(let[referencePath,elements]of padElementsByReference.entries()){let bounds=getBoundsOfPcbElements(elements),minX=bounds.minX,maxX=bounds.maxX,minY=bounds.minY,maxY=bounds.maxY;vars[`${referencePath}.x`]=(minX+maxX)/2,vars[`${referencePath}.y`]=(minY+maxY)/2,vars[`${referencePath}.width`]=maxX-minX,vars[`${referencePath}.height`]=maxY-minY,vars[`${referencePath}.minX`]=minX,vars[`${referencePath}.maxX`]=maxX,vars[`${referencePath}.minY`]=minY,vars[`${referencePath}.maxY`]=maxY}}function collectPadElementsByReference(component){let refsToElements=new Map;if(!component.name||!component.pcb_component_id||!component.root)return refsToElements;let{db:db22}=component.root,padElements=[...db22.pcb_smtpad.list({pcb_component_id:component.pcb_component_id}),...db22.pcb_plated_hole.list({pcb_component_id:component.pcb_component_id})];for(let pad2 of padElements){let aliases4=new Set;for(let hint of pad2.port_hints??[])typeof hint=="string"&&hint.length>0&&aliases4.add(hint);let pcbPortId=pad2.pcb_port_id;if(pcbPortId){let pcbPort=db22.pcb_port.get(pcbPortId),sourcePort=pcbPort?.source_port_id?db22.source_port.get(pcbPort.source_port_id):null;sourcePort?.name&&aliases4.add(sourcePort.name),sourcePort?.pin_number!=null&&aliases4.add(`pin${sourcePort.pin_number}`)}for(let alias of aliases4){let referencePath=`${component.name}.${alias}`;refsToElements.has(referencePath)||refsToElements.set(referencePath,[]),refsToElements.get(referencePath).push(pad2)}}return refsToElements}function Group_doInitialPcbComponentAnchorAlignment(group2){if(group2.root?.pcbDisabled||!group2.pcb_group_id)return;let pcbPositionAnchor=group2._parsedProps?.pcbPositionAnchor;if(!pcbPositionAnchor)return;let targetPosition=group2._getGlobalPcbPositionBeforeLayout(),{pcbX,pcbY}=group2._parsedProps;if(pcbX===void 0&&pcbY===void 0)return;let{db:db22}=group2.root,pcbGroup=db22.pcb_group.get(group2.pcb_group_id);if(!pcbGroup)return;let width=pcbGroup.width,height=pcbGroup.height,{center:center2}=pcbGroup;if(pcbGroup.outline&&pcbGroup.outline.length>0){let bounds2=getBoundsFromPoints(pcbGroup.outline);bounds2&&(width=bounds2.maxX-bounds2.minX,height=bounds2.maxY-bounds2.minY)}if(!width||!height)return;let bounds={left:center2.x-width/2,right:center2.x+width/2,top:center2.y+height/2,bottom:center2.y-height/2},currentCenter={...center2},anchorPos=null;if(new Set(["center","top_left","top_center","top_right","center_left","center_right","bottom_left","bottom_center","bottom_right"]).has(pcbPositionAnchor))switch(pcbPositionAnchor){case"center":anchorPos=currentCenter;break;case"top_left":anchorPos={x:bounds.left,y:bounds.top};break;case"top_center":anchorPos={x:currentCenter.x,y:bounds.top};break;case"top_right":anchorPos={x:bounds.right,y:bounds.top};break;case"center_left":anchorPos={x:bounds.left,y:currentCenter.y};break;case"center_right":anchorPos={x:bounds.right,y:currentCenter.y};break;case"bottom_left":anchorPos={x:bounds.left,y:bounds.bottom};break;case"bottom_center":anchorPos={x:currentCenter.x,y:bounds.bottom};break;case"bottom_right":anchorPos={x:bounds.right,y:bounds.bottom};break}if(!anchorPos)return;let newCenter={...currentCenter};targetPosition.x!==void 0&&(newCenter.x+=targetPosition.x-anchorPos.x),targetPosition.y!==void 0&&(newCenter.y+=targetPosition.y-anchorPos.y),(Math.abs(newCenter.x-currentCenter.x)>1e-6||Math.abs(newCenter.y-currentCenter.y)>1e-6)&&(group2._repositionOnPcb(newCenter),db22.pcb_group.update(group2.pcb_group_id,{center:newCenter})),db22.pcb_group.update(group2.pcb_group_id,{anchor_position:targetPosition,anchor_alignment:pcbPositionAnchor,display_offset_x:pcbX,display_offset_y:pcbY})}var Group_doInitialPcbLayoutFlex=group2=>{let{db:db22}=group2.root,{_parsedProps:props}=group2,pcbChildren=group2.children.filter(c22=>c22.pcb_component_id||c22.pcb_group_id);if(pcbChildren.some(child=>{let childProps=child._parsedProps;return childProps?.pcbX!==void 0||childProps?.pcbY!==void 0}))return;let rawJustify=props.pcbJustifyContent??props.justifyContent,rawAlign=props.pcbAlignItems??props.alignItems,rawGap=props.pcbFlexGap??props.pcbGap??props.gap,direction3=props.pcbFlexDirection??"row",justifyContent={start:"flex-start",end:"flex-end","flex-start":"flex-start","flex-end":"flex-end",stretch:"space-between","space-between":"space-between","space-around":"space-around","space-evenly":"space-evenly",center:"center"}[rawJustify??"space-between"],alignItems={start:"flex-start",end:"flex-end","flex-start":"flex-start","flex-end":"flex-end",stretch:"stretch",center:"center"}[rawAlign??"center"];if(!justifyContent)throw new Error(`Invalid justifyContent value: "${rawJustify}"`);if(!alignItems)throw new Error(`Invalid alignItems value: "${rawAlign}"`);let rowGap=0,columnGap=0;typeof rawGap=="object"?(rowGap=rawGap.y??0,columnGap=rawGap.x??0):typeof rawGap=="number"?(rowGap=rawGap,columnGap=rawGap):typeof rawGap=="string"&&(rowGap=length.parse(rawGap),columnGap=length.parse(rawGap));let minFlexContainer,width=props.width??props.pcbWidth??void 0,height=props.height??props.pcbHeight??void 0;(width===void 0||height===void 0)&&(minFlexContainer=getMinimumFlexContainer(pcbChildren.map(child=>child._getMinimumFlexContainerSize()).filter(size3=>size3!==null),{alignItems,justifyContent,direction:direction3,rowGap,columnGap}),width=minFlexContainer.width,height=minFlexContainer.height);let flexBox=new RootFlexBox(width,height,{alignItems,justifyContent,direction:direction3,rowGap,columnGap});for(let child of pcbChildren){let size3=child._getMinimumFlexContainerSize();flexBox.addChild({metadata:child,width:size3?.width??0,height:size3?.height??0,flexBasis:size3?direction3==="row"?size3.width:size3.height:void 0})}flexBox.build();let bounds={minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0,width:0,height:0};for(let child of flexBox.children)bounds.minX=Math.min(bounds.minX,child.position.x),bounds.minY=Math.min(bounds.minY,child.position.y),bounds.maxX=Math.max(bounds.maxX,child.position.x+child.size.width),bounds.maxY=Math.max(bounds.maxY,child.position.y+child.size.height);bounds.width=bounds.maxX-bounds.minX,bounds.height=bounds.maxY-bounds.minY;let groupCenter=group2._getGlobalPcbPositionBeforeLayout(),offset2={x:groupCenter.x-(bounds.maxX+bounds.minX)/2,y:groupCenter.y-(bounds.maxY+bounds.minY)/2};for(let child of flexBox.children)child.metadata._repositionOnPcb({x:child.position.x+child.size.width/2+offset2.x,y:child.position.y+child.size.height/2+offset2.y});db22.pcb_group.update(group2.pcb_group_id,{width:bounds.width,height:bounds.height,center:groupCenter})},MIN_GAP=1;function Group_doInitialPcbLayoutGrid(group2){let{db:db22}=group2.root,props=group2._parsedProps,pcbChildren=getPcbChildren(group2);if(pcbChildren.length===0)return;let childDimensions=calculateChildDimensions({db:db22,pcbChildren}),gridConfig=parseGridConfiguration(props),gridLayout=createGridLayout({props,pcbChildren,childDimensions,gridConfig}),cssGrid=createCssGrid({pcbChildren,childDimensions,gridLayout,gridConfig}),{itemCoordinates}=cssGrid.layout();positionChildren({db:db22,group:group2,pcbChildren,itemCoordinates,gridLayout}),updateGroupDimensions({db:db22,group:group2,props,gridLayout})}function getPcbChildren(group2){return group2.children.filter(child=>child.pcb_component_id||child.pcb_group_id)}function calculateChildDimensions(params){let{db:db22,pcbChildren}=params,maxWidth=0,maxHeight=0;for(let child of pcbChildren){let width=0,height=0;if(child.pcb_group_id){let pcbGroup=db22.pcb_group.get(child.pcb_group_id);width=pcbGroup?.width??0,height=pcbGroup?.height??0}else if(child.pcb_component_id){let pcbComp=db22.pcb_component.get(child.pcb_component_id);width=pcbComp?.width??0,height=pcbComp?.height??0}maxWidth=Math.max(maxWidth,width),maxHeight=Math.max(maxHeight,height)}return{width:maxWidth,height:maxHeight}}function parseGridConfiguration(props){let cols=props.pcbGridCols??props.gridCols??props.pcbLayout?.grid?.cols,rows=props.pcbGridRows??props.pcbLayout?.grid?.rows,templateColumns=props.pcbGridTemplateColumns,templateRows=props.pcbGridTemplateRows,parseGap=gapValue=>gapValue===void 0?MIN_GAP:typeof gapValue=="number"?gapValue:length.parse(gapValue),gridGapOption=props.pcbGridGap??props.gridGap??props.pcbLayout?.gridGap,rowGapOption=props.pcbGridRowGap??props.gridRowGap??props.pcbLayout?.gridRowGap,colGapOption=props.pcbGridColumnGap??props.gridColumnGap??props.pcbLayout?.gridColumnGap,gapX=MIN_GAP,gapY=MIN_GAP;if(rowGapOption!==void 0||colGapOption!==void 0){let fallbackX=typeof gridGapOption=="object"?gridGapOption?.x:gridGapOption,fallbackY=typeof gridGapOption=="object"?gridGapOption?.y:gridGapOption;gapX=parseGap(colGapOption??fallbackX),gapY=parseGap(rowGapOption??fallbackY)}else if(typeof gridGapOption=="object"&&gridGapOption!==null)gapX=parseGap(gridGapOption.x),gapY=parseGap(gridGapOption.y);else{let gap=parseGap(gridGapOption);gapX=gap,gapY=gap}return{cols,rows,gapX,gapY,templateColumns,templateRows}}function createGridLayout(params){let{props,pcbChildren,childDimensions,gridConfig}=params;return props.pcbGridTemplateColumns||props.pcbGridTemplateRows?createTemplateBasedLayout({props,gridConfig,pcbChildren,childDimensions}):createDefaultLayout({gridConfig,pcbChildren,childDimensions})}function createTemplateBasedLayout(params){let{props,gridConfig,pcbChildren,childDimensions}=params,gridTemplateColumns=props.pcbGridTemplateColumns??"",gridTemplateRows=props.pcbGridTemplateRows??"",extractRepeatCount=template=>{let match2=template.match(/repeat\((\d+),/);return match2?parseInt(match2[1]):Math.ceil(Math.sqrt(pcbChildren.length))},numCols=props.pcbGridTemplateColumns?extractRepeatCount(gridTemplateColumns):Math.ceil(Math.sqrt(pcbChildren.length)),numRows=props.pcbGridTemplateRows?extractRepeatCount(gridTemplateRows):Math.ceil(pcbChildren.length/numCols),containerWidth=numCols*childDimensions.width+Math.max(0,numCols-1)*gridConfig.gapX,containerHeight=numRows*childDimensions.height+Math.max(0,numRows-1)*gridConfig.gapY;return{gridTemplateColumns,gridTemplateRows,containerWidth,containerHeight}}function createDefaultLayout(params){let{gridConfig,pcbChildren,childDimensions}=params,numCols,numRows;gridConfig.cols!==void 0&&gridConfig.rows!==void 0?(numCols=gridConfig.cols,numRows=gridConfig.rows):gridConfig.cols!==void 0?(numCols=gridConfig.cols,numRows=Math.ceil(pcbChildren.length/numCols)):gridConfig.rows!==void 0?(numRows=gridConfig.rows,numCols=Math.ceil(pcbChildren.length/numRows)):(numCols=Math.ceil(Math.sqrt(pcbChildren.length)),numRows=Math.ceil(pcbChildren.length/numCols)),numCols=Math.max(1,numCols),numRows=Math.max(1,numRows);let containerWidth=numCols*childDimensions.width+Math.max(0,numCols-1)*gridConfig.gapX,containerHeight=numRows*childDimensions.height+Math.max(0,numRows-1)*gridConfig.gapY,gridTemplateColumns=`repeat(${numCols}, ${childDimensions.width}px)`,gridTemplateRows=`repeat(${numRows}, ${childDimensions.height}px)`;return{gridTemplateColumns,gridTemplateRows,containerWidth,containerHeight}}function createCssGrid(params){let{pcbChildren,childDimensions,gridLayout,gridConfig}=params,gridChildren=pcbChildren.map((child,index2)=>({key:child.getString()||`child-${index2}`,contentWidth:childDimensions.width,contentHeight:childDimensions.height}));return new CssGrid({containerWidth:gridLayout.containerWidth,containerHeight:gridLayout.containerHeight,gridTemplateColumns:gridLayout.gridTemplateColumns,gridTemplateRows:gridLayout.gridTemplateRows,gap:[gridConfig.gapY,gridConfig.gapX],children:gridChildren})}function positionChildren(params){let{db:db22,group:group2,pcbChildren,itemCoordinates,gridLayout}=params,groupCenter=group2._getGlobalPcbPositionBeforeLayout(),allCircuitJson=db22.toArray();for(let i22=0;i22<pcbChildren.length;i22++){let child=pcbChildren[i22],childKey=child.getString()||`child-${i22}`,coordinates=itemCoordinates[childKey];if(!coordinates){console.warn(`PCB grid layout: No coordinates found for child ${childKey}`);continue}let targetX=groupCenter.x-gridLayout.containerWidth/2+coordinates.x+coordinates.width/2,targetY=groupCenter.y+gridLayout.containerHeight/2-coordinates.y-coordinates.height/2;if(child.pcb_component_id)repositionPcbComponentTo(allCircuitJson,child.pcb_component_id,{x:targetX,y:targetY});else{let groupChild=child;groupChild.pcb_group_id&&groupChild.source_group_id&&repositionPcbGroupTo(allCircuitJson,groupChild.source_group_id,{x:targetX,y:targetY})}}}function updateGroupDimensions(params){let{db:db22,group:group2,props,gridLayout}=params;if(group2.pcb_group_id){let groupCenter=group2._getGlobalPcbPositionBeforeLayout();db22.pcb_group.update(group2.pcb_group_id,{width:props.width??gridLayout.containerWidth,height:props.height??gridLayout.containerHeight,center:groupCenter})}}var solvePackSolverWithTimeout=(solver,timeoutMs,getCurrentTime=()=>performance.now())=>{if(timeoutMs===void 0||!Number.isFinite(timeoutMs)||timeoutMs<=0)return solver.solve(),{elapsedMs:0,timedOut:!1};let startedAt=getCurrentTime(),elapsedMs=0;for(;!solver.solved&&!solver.failed&&(solver.step(),!(solver.solved||solver.failed));)if(elapsedMs=getCurrentTime()-startedAt,elapsedMs>=timeoutMs)return{elapsedMs,timedOut:!0};return{elapsedMs,timedOut:!1}},applyComponentConstraintClusters=(group2,packInput)=>{let constraints=group2.children.filter(c22=>c22.componentName==="Constraint"&&c22._parsedProps.pcb),clusterByRoot=new Map,parent={},find2=x22=>(parent[x22]!==x22&&(parent[x22]=find2(parent[x22])),parent[x22]),union2=(a22,b22)=>{let ra3=find2(a22),rb22=find2(b22);ra3!==rb22&&(parent[rb22]=ra3)},makeSet=x22=>{x22 in parent||(parent[x22]=x22)},getIdFromSelector=sel2=>{let name=sel2.startsWith(".")?sel2.slice(1):sel2;return group2.children.find(c22=>c22.name===name)?.pcb_component_id??void 0};for(let constraint of constraints){let props=constraint._parsedProps;if("left"in props&&"right"in props){let a22=getIdFromSelector(props.left),b22=getIdFromSelector(props.right);a22&&b22&&(makeSet(a22),makeSet(b22),union2(a22,b22))}else if("top"in props&&"bottom"in props){let a22=getIdFromSelector(props.top),b22=getIdFromSelector(props.bottom);a22&&b22&&(makeSet(a22),makeSet(b22),union2(a22,b22))}else if("for"in props&&Array.isArray(props.for)){let ids=props.for.map(s22=>getIdFromSelector(s22)).filter(s22=>!!s22);for(let id3 of ids)makeSet(id3);for(let i22=1;i22<ids.length;i22++)union2(ids[0],ids[i22])}}for(let id3 of Object.keys(parent)){let rootId=find2(id3);clusterByRoot.has(rootId)||clusterByRoot.set(rootId,{componentIds:[],constraints:[]}),clusterByRoot.get(rootId).componentIds.push(id3)}for(let constraint of constraints){let props=constraint._parsedProps,compId;if("left"in props?compId=getIdFromSelector(props.left):"top"in props?compId=getIdFromSelector(props.top):"for"in props&&(compId=getIdFromSelector(props.for[0])),!compId)continue;let root=find2(compId);clusterByRoot.get(root)?.constraints.push(constraint)}let clusterMap={},packCompById=Object.fromEntries(packInput.components.map(c22=>[c22.componentId,c22]));for(let[rootId,info]of clusterByRoot.entries()){if(info.componentIds.length<=1)continue;let solver=new Solver,kVars={},getVar=(id3,axis)=>{let key=`${id3}_${axis}`;return kVars[key]||(kVars[key]=new Variable(key)),kVars[key]},anchor3=info.componentIds[0];solver.addConstraint(new Constraint(getVar(anchor3,"x"),Operator.Eq,0,Strength.required)),solver.addConstraint(new Constraint(getVar(anchor3,"y"),Operator.Eq,0,Strength.required));for(let constraint of info.constraints){let props=constraint._parsedProps;if("xDist"in props){let left=getIdFromSelector(props.left),right=getIdFromSelector(props.right);left&&right&&solver.addConstraint(new Constraint(new Expression(getVar(right,"x"),[-1,getVar(left,"x")]),Operator.Eq,props.xDist,Strength.required))}else if("yDist"in props){let top=getIdFromSelector(props.top),bottom=getIdFromSelector(props.bottom);top&&bottom&&solver.addConstraint(new Constraint(new Expression(getVar(top,"y"),[-1,getVar(bottom,"y")]),Operator.Eq,props.yDist,Strength.required))}else if("sameX"in props&&Array.isArray(props.for)){let ids=props.for.map(s22=>getIdFromSelector(s22)).filter(s22=>!!s22);if(ids.length>1){let base=getVar(ids[0],"x");for(let i22=1;i22<ids.length;i22++)solver.addConstraint(new Constraint(new Expression(getVar(ids[i22],"x"),[-1,base]),Operator.Eq,0,Strength.required))}}else if("sameY"in props&&Array.isArray(props.for)){let ids=props.for.map(s22=>getIdFromSelector(s22)).filter(s22=>!!s22);if(ids.length>1){let base=getVar(ids[0],"y");for(let i22=1;i22<ids.length;i22++)solver.addConstraint(new Constraint(new Expression(getVar(ids[i22],"y"),[-1,base]),Operator.Eq,0,Strength.required))}}}solver.updateVariables();let positions={};for(let id3 of info.componentIds)positions[id3]={x:getVar(id3,"x").value(),y:getVar(id3,"y").value()};let minX=1/0,minY=1/0,maxX=-1/0,maxY=-1/0;for(let id3 of info.componentIds){let comp=packCompById[id3],pos=positions[id3];if(comp)for(let pad2 of comp.pads){let ax22=pos.x+pad2.offset.x,ay22=pos.y+pad2.offset.y;minX=Math.min(minX,ax22-pad2.size.x/2),maxX=Math.max(maxX,ax22+pad2.size.x/2),minY=Math.min(minY,ay22-pad2.size.y/2),maxY=Math.max(maxY,ay22+pad2.size.y/2)}}let clusterCenter={x:(minX+maxX)/2,y:(minY+maxY)/2},mergedPads=[],relCenters={};for(let id3 of info.componentIds){let comp=packCompById[id3],pos=positions[id3];if(comp){relCenters[id3]={x:pos.x-clusterCenter.x,y:pos.y-clusterCenter.y};for(let pad2 of comp.pads)mergedPads.push({padId:pad2.padId,networkId:pad2.networkId,type:pad2.type,size:pad2.size,offset:{x:pos.x+pad2.offset.x-clusterCenter.x,y:pos.y+pad2.offset.y-clusterCenter.y}})}}packInput.components=packInput.components.filter(c22=>!info.componentIds.includes(c22.componentId)),packInput.components.push({componentId:info.componentIds[0],pads:mergedPads,availableRotationDegrees:[0]}),info.relativeCenters=relCenters,clusterMap[info.componentIds[0]]=info}return clusterMap},updateCadRotation=({db:db22,pcbComponentId,rotationDegrees,layer})=>{if(rotationDegrees==null||!db22?.cad_component?.list)return;let cadComponent=db22.cad_component.getWhere({pcb_component_id:pcbComponentId});if(!cadComponent)return;let delta=layer?.toLowerCase?.()==="bottom"?-rotationDegrees:rotationDegrees,currentRotationZ=cadComponent.rotation?.z??0,nextRotation={...cadComponent.rotation??{x:0,y:0,z:0},z:normalizeDegrees(currentRotationZ+delta)};db22.cad_component.update(cadComponent.cad_component_id,{rotation:nextRotation}),cadComponent.rotation=nextRotation},isDescendantGroup=(db22,groupId,ancestorId)=>{if(groupId===ancestorId)return!0;let group2=db22.source_group.get(groupId);return!group2||!group2.parent_source_group_id?!1:isDescendantGroup(db22,group2.parent_source_group_id,ancestorId)},applyPackOutput=(group2,packOutput,clusterMap,initialPackOutput)=>{let{db:db22}=group2.root;for(let packedComponent of packOutput.components){if(packedComponent.isStatic)continue;let{center:center2,componentId,ccwRotationOffset,ccwRotationDegrees}=packedComponent,cluster=clusterMap[componentId];if(cluster){let rotationDegrees2=ccwRotationDegrees??ccwRotationOffset??0,angleRad=rotationDegrees2*Math.PI/180;for(let memberId of cluster.componentIds){let rel=cluster.relativeCenters[memberId];if(!rel)continue;db22.pcb_component.update(memberId,{position_mode:"packed"});let rotatedRel={x:rel.x*Math.cos(angleRad)-rel.y*Math.sin(angleRad),y:rel.x*Math.sin(angleRad)+rel.y*Math.cos(angleRad)},member=db22.pcb_component.get(memberId);if(!member)continue;let originalCenter2=member.center,transformMatrix2=compose2(group2._computePcbGlobalTransformBeforeLayout(),translate2(center2.x+rotatedRel.x,center2.y+rotatedRel.y),rotate2(angleRad),translate2(-originalCenter2.x,-originalCenter2.y)),related=db22.toArray().filter(elm=>"pcb_component_id"in elm&&elm.pcb_component_id===memberId);transformPCBElements(related,transformMatrix2),updateCadRotation({db:db22,pcbComponentId:memberId,rotationDegrees:rotationDegrees2,layer:member.layer})}continue}let pcbComponent=db22.pcb_component.get(componentId);if(pcbComponent){db22.pcb_component.update(componentId,{position_mode:"packed"});let currentGroupId=group2.source_group_id,componentGroupId=db22.source_component.get(pcbComponent.source_component_id)?.source_group_id;if(componentGroupId!==void 0&&!isDescendantGroup(db22,componentGroupId,currentGroupId))continue;let originalCenter2=pcbComponent.center,rotationDegrees2=ccwRotationDegrees??ccwRotationOffset??0,transformMatrix2=compose2(group2._computePcbGlobalTransformBeforeLayout(),translate2(center2.x,center2.y),rotate2(rotationDegrees2*Math.PI/180),translate2(-originalCenter2.x,-originalCenter2.y)),related=db22.toArray().filter(elm=>"pcb_component_id"in elm&&elm.pcb_component_id===componentId);transformPCBElements(related,transformMatrix2),updateCadRotation({db:db22,pcbComponentId:componentId,rotationDegrees:rotationDegrees2,layer:pcbComponent.layer});continue}let pcbGroup=db22.pcb_group.list().find(g22=>g22.source_group_id===componentId);if(!pcbGroup)continue;let originalCenter=initialPackOutput.components.find(component=>component.componentId===componentId)?.center??pcbGroup.center,rotationDegrees=ccwRotationDegrees??ccwRotationOffset??0,transformMatrix=compose2(group2._computePcbGlobalTransformBeforeLayout(),translate2(center2.x,center2.y),rotate2(rotationDegrees*Math.PI/180),translate2(-originalCenter.x,-originalCenter.y)),relatedElements=db22.toArray().filter(elm=>{if("source_group_id"in elm&&elm.source_group_id&&(elm.source_group_id===componentId||isDescendantGroup(db22,elm.source_group_id,componentId)))return!0;if("source_component_id"in elm&&elm.source_component_id){let sourceComponent=db22.source_component.get(elm.source_component_id);if(sourceComponent?.source_group_id&&(sourceComponent.source_group_id===componentId||isDescendantGroup(db22,sourceComponent.source_group_id,componentId)))return!0}if("pcb_component_id"in elm&&elm.pcb_component_id){let pcbComp=db22.pcb_component.get(elm.pcb_component_id);if(pcbComp?.source_component_id){let sourceComp=db22.source_component.get(pcbComp.source_component_id);if(sourceComp?.source_group_id&&(sourceComp.source_group_id===componentId||isDescendantGroup(db22,sourceComp.source_group_id,componentId)))return!0}}return!1});for(let elm of relatedElements)elm.type==="pcb_component"&&db22.pcb_component.update(elm.pcb_component_id,{position_mode:"packed"});transformPCBElements(relatedElements,transformMatrix),db22.pcb_group.update(pcbGroup.pcb_group_id,{center:center2})}if(group2.pcb_group_id){let groupPcbComponents=db22.pcb_component.list({pcb_group_id:group2.pcb_group_id});group2.calculatePcbGroupBounds(findBoundsAndCenter(groupPcbComponents))}},normalizeLayer=layer=>(layer??"top").toLowerCase(),getPackComponentPcbLayer=(component,db22)=>{let layers=new Set,directPcbComponent=db22.pcb_component.get(component.componentId);directPcbComponent&&layers.add(normalizeLayer(directPcbComponent.layer));for(let pad2 of component.pads){let via=db22.pcb_via.get(pad2.padId),pcbComponentId=db22.pcb_smtpad.get(pad2.padId)?.pcb_component_id??db22.pcb_plated_hole.get(pad2.padId)?.pcb_component_id??via?.pcb_component_id;if(!pcbComponentId)continue;let pcbComponent=db22.pcb_component.get(pcbComponentId);pcbComponent&&layers.add(normalizeLayer(pcbComponent.layer))}return layers.size===1?layers.values().next().value:void 0},getPackInputsByPcbLayer=(packInput,db22)=>{let componentsByLayer=new Map;for(let component of packInput.components){let layer=getPackComponentPcbLayer(component,db22);if(!layer)return[packInput];let components=componentsByLayer.get(layer)??[];components.push(component),componentsByLayer.set(layer,components)}if(componentsByLayer.size<=1)return[packInput];let layerPriority=layer=>layer==="top"?0:layer==="bottom"?1:2;return Array.from(componentsByLayer.entries()).sort(([layerA],[layerB])=>layerPriority(layerA)-layerPriority(layerB)||layerA.localeCompare(layerB)).map(([,components])=>({...packInput,components}))},DEFAULT_MIN_GAP="1mm",debug42=(0,import_debug12.default)("Group_doInitialPcbLayoutPack"),getCollisionObstacleForStaticComponent=component=>{if(component.courtyard&&component.center)return{obstacleId:component.componentId,absoluteCenter:{x:component.center.x+component.courtyard.offsetFromCenter.x,y:component.center.y+component.courtyard.offsetFromCenter.y},width:component.courtyard.width,height:component.courtyard.height};if(component.pads.length===0)return;let minX=1/0,minY=1/0,maxX=-1/0,maxY=-1/0;for(let pad2 of component.pads){let absoluteCenter=pad2.absoluteCenter??(component.center?{x:component.center.x+pad2.offset.x,y:component.center.y+pad2.offset.y}:pad2.offset);minX=Math.min(minX,absoluteCenter.x-pad2.size.x/2),minY=Math.min(minY,absoluteCenter.y-pad2.size.y/2),maxX=Math.max(maxX,absoluteCenter.x+pad2.size.x/2),maxY=Math.max(maxY,absoluteCenter.y+pad2.size.y/2)}return{obstacleId:component.componentId,absoluteCenter:{x:(minX+maxX)/2,y:(minY+maxY)/2},width:maxX-minX,height:maxY-minY}},getCrossLayerPadObstacles=({components,targetLayer:targetLayer2,db:db22})=>components.flatMap(component=>component.pads.flatMap(pad2=>{let platedHole2=db22.pcb_plated_hole.get(pad2.padId),via=db22.pcb_via.get(pad2.padId);if(!(platedHole2?.layers??via?.layers)?.includes(targetLayer2))return[];let absoluteCenter=pad2.absoluteCenter??(component.center?{x:component.center.x+pad2.offset.x,y:component.center.y+pad2.offset.y}:pad2.offset);return[{obstacleId:`cross_layer_${targetLayer2}_${pad2.padId}`,absoluteCenter,width:pad2.size.x,height:pad2.size.y}]})),Group_doInitialPcbLayoutPack=group2=>{let{db:db22}=group2.root,{_parsedProps:props}=group2;group2.root?.emit("packing:start",{subcircuit_id:group2.subcircuit_id,componentDisplayName:group2.getString()});let{packOrderStrategy,packPlacementStrategy,gap:gapProp,pcbGap,pcbPackGap}=props,gap=pcbPackGap??pcbGap??gapProp,gapMm=length.parse(gap??DEFAULT_MIN_GAP),chipMarginsMap={},staticPcbComponentIds=new Set,collectMargins=comp=>{if(comp?.pcb_component_id&&comp?._parsedProps){let props2=comp._parsedProps,left=length.parse(props2.pcbMarginLeft??props2.pcbMarginX??0),right=length.parse(props2.pcbMarginRight??props2.pcbMarginX??0),top=length.parse(props2.pcbMarginTop??props2.pcbMarginY??0),bottom=length.parse(props2.pcbMarginBottom??props2.pcbMarginY??0);(left||right||top||bottom)&&(chipMarginsMap[comp.pcb_component_id]={left,right,top,bottom})}comp?.children&&comp.children.forEach(collectMargins)};collectMargins(group2);let excludedPcbGroupIds=new Set;for(let child of group2.children){let childIsGroupOrNormalComponent=child;childIsGroupOrNormalComponent._isNormalComponent&&childIsGroupOrNormalComponent.isRelativelyPositioned?.()&&(childIsGroupOrNormalComponent.pcb_component_id&&staticPcbComponentIds.add(childIsGroupOrNormalComponent.pcb_component_id),childIsGroupOrNormalComponent.pcb_group_id&&excludedPcbGroupIds.add(childIsGroupOrNormalComponent.pcb_group_id))}let isDescendantGroup2=(db32,groupId,ancestorId)=>{if(groupId===ancestorId)return!0;let group22=db32.source_group.get(groupId);return!group22||!group22.parent_source_group_id?!1:isDescendantGroup2(db32,group22.parent_source_group_id,ancestorId)};if(excludedPcbGroupIds.size>0)for(let element of db22.toArray()){if(element.type!=="pcb_component")continue;let sourceComponent=db22.source_component.get(element.source_component_id);if(sourceComponent?.source_group_id)for(let groupId of excludedPcbGroupIds)isDescendantGroup2(db22,sourceComponent.source_group_id,groupId)&&staticPcbComponentIds.add(element.pcb_component_id)}let filteredCircuitJson=db22.toArray(),bounds;if(props.width!==void 0&&props.height!==void 0){let widthMm=length.parse(props.width),heightMm=length.parse(props.height);bounds={minX:-widthMm/2,maxX:widthMm/2,minY:-heightMm/2,maxY:heightMm/2}}let initialPackOutput=convertCircuitJsonToPackOutput(filteredCircuitJson,{source_group_id:group2.source_group_id,chipMarginsMap,staticPcbComponentIds:Array.from(staticPcbComponentIds)}),packInput={...convertPackOutputToPackInput(initialPackOutput),packOrderStrategy:packOrderStrategy??"largest_to_smallest",packPlacementStrategy:packPlacementStrategy??"minimum_sum_squared_distance_to_network",minGap:gapMm,bounds},clusterMap=applyComponentConstraintClusters(group2,packInput);debug42.enabled&&(group2.root?.emit("debug:logOutput",{type:"debug:logOutput",name:`packInput-circuitjson-${group2.name}`,content:JSON.stringify(db22.toArray())}),group2.root?.emit("debug:logOutput",{type:"debug:logOutput",name:`packInput-${group2.name}`,content:packInput}));let packInputs=getPackInputsByPcbLayer(packInput,db22),packOutput={...packInput,components:[]},packingFailed=!1,reportPackingError=solverErrorMessage=>{let message=`Unable to pack all PCB components within the layout bounds: ${solverErrorMessage}`;db22.pcb_packing_error.insert({error_type:"pcb_packing_error",message,pcb_group_id:group2.pcb_group_id??void 0,subcircuit_id:group2.subcircuit_id??void 0}),group2.root?.emit("packing:error",{subcircuit_id:group2.subcircuit_id,componentDisplayName:group2.getString(),error:{message}})};try{for(let layerPackInput of packInputs){let targetLayer2=getPackComponentPcbLayer(layerPackInput.components[0],db22),componentIdsForLayer=new Set(layerPackInput.components.map(component=>component.componentId)),staticLayerObstacles=layerPackInput.components.flatMap(component=>{if(!component.isStatic)return[];let obstacle=getCollisionObstacleForStaticComponent(component);return obstacle?[obstacle]:[]}),canUseCrossLayerNetworkReferences=layerPackInput.components.every(component=>!!db22.pcb_component.get(component.componentId)&&!clusterMap[component.componentId]),crossLayerStaticComponents=packInput.components.filter(component=>component.isStatic&&!componentIdsForLayer.has(component.componentId)),fallbackCrossLayerObstacles=canUseCrossLayerNetworkReferences?[]:crossLayerStaticComponents.flatMap(component=>{let obstacle=getCollisionObstacleForStaticComponent(component);return obstacle?[obstacle]:[]}),collisionOnlyPadIds=new Set([...layerPackInput.components.filter(component=>component.isStatic),...canUseCrossLayerNetworkReferences?[]:crossLayerStaticComponents].flatMap(component=>component.pads.map(pad2=>pad2.padId))),networkReferenceSources=new Map([...packOutput.components.map(component=>[component.componentId,{component,courtyardSize:Number.EPSILON}]),...canUseCrossLayerNetworkReferences?crossLayerStaticComponents.map(component=>[component.componentId,{component,courtyardSize:1e-6}]):[]]),networkReferenceComponents=Array.from(networkReferenceSources.values(),({component,courtyardSize})=>({...component,componentId:`network_reference_${component.componentId}`,isStatic:!0,courtyard:{offsetFromCenter:{x:0,y:0},width:courtyardSize,height:courtyardSize}})),crossLayerPadObstacles=targetLayer2?getCrossLayerPadObstacles({components:Array.from(networkReferenceSources.values(),({component})=>component),targetLayer:targetLayer2,db:db22}):[],solverInput={...layerPackInput,weightedConnections:layerPackInput.weightedConnections?.filter(connection=>connection.padIds.every(padId=>!collisionOnlyPadIds.has(padId))),obstacles:[...layerPackInput.obstacles??[],...staticLayerObstacles,...fallbackCrossLayerObstacles,...crossLayerPadObstacles],components:[...networkReferenceComponents,...layerPackInput.components.filter(component=>!component.isStatic)]},solver=new PackSolver2(solverInput),solverParams=solver.getConstructorParams();group2.root?.emit("solver:started",{type:"solver:started",solverName:"PackSolver2",solverParams,solverConstructorArgs:[solverParams],componentName:group2.getString()});let pcbPackSolverTimeoutMs=group2.root?.platform?.pcbPackSolverTimeoutMs,{timedOut}=solvePackSolverWithTimeout(solver,pcbPackSolverTimeoutMs);if(timedOut&&(packingFailed=!0,reportPackingError(`PackSolver2 timed out after ${pcbPackSolverTimeoutMs}ms`)),solver.failed){packingFailed=!0;let solverErrorMessage=solver.error??solver.activeSubSolver?.error??"No valid packing solution found";reportPackingError(solverErrorMessage)}if(packOutput.components.push(...solver.packedComponents.filter(component=>componentIdsForLayer.has(component.componentId))),timedOut)break}}catch(error2){throw reportPackingError(error2 instanceof Error?error2.message:String(error2)),error2}if(debug42.enabled&&global?.debugGraphics){let graphics=getGraphicsFromPackOutput(packOutput);graphics.title=`packOutput-${group2.name}`,global.debugGraphics?.push(graphics)}applyPackOutput(group2,packOutput,clusterMap,initialPackOutput),!packingFailed&&group2.root?.emit("packing:end",{subcircuit_id:group2.subcircuit_id,componentDisplayName:group2.getString()})},parsePinNumberFromPortName=name=>{if(!name)return null;let match2=name.match(/^pin(\d+)$/i)??name.match(/^(\d+)$/);if(!match2)return null;let pinNumber=Number(match2[1]);return Number.isFinite(pinNumber)&&pinNumber>0?pinNumber:null},getDirectGroupPorts=group2=>group2.children.filter(child=>child.componentName==="Port"),normalizeGroupSchematicBoxPorts=group2=>{let{db:db22}=group2.root,ports=getDirectGroupPorts(group2);for(let port of ports){if(port._parsedProps.pinNumber!==void 0)continue;let pinNumber=parsePinNumberFromPortName(port._parsedProps.name);pinNumber!==null&&(port._parsedProps.pinNumber=pinNumber)}let usedPinNumbers=new Set(ports.map(port=>port._parsedProps.pinNumber).filter(pinNumber=>pinNumber!==void 0)),nextPinNumber=1;for(let port of ports){if(port._parsedProps.pinNumber===void 0){for(;usedPinNumbers.has(nextPinNumber);)nextPinNumber++;port._parsedProps.pinNumber=nextPinNumber,usedPinNumbers.add(nextPinNumber)}port.source_port_id&&db22.source_port.update(port.source_port_id,{pin_number:port._parsedProps.pinNumber,port_hints:port.getNameAndAliases()})}},getGroupSchematicBoxPinLabels=group2=>{let pinLabels={};for(let port of getDirectGroupPorts(group2)){let pinNumber=port._parsedProps.pinNumber,name=port._parsedProps.name;pinNumber===void 0||!name||name===`pin${pinNumber}`||name===String(pinNumber)||(pinLabels[`pin${pinNumber}`]=name)}return pinLabels},Group_doInitialSchematicBoxComponentRender=group2=>{if(group2.root?.schematicDisabled)return;let{db:db22}=group2.root,props=group2._parsedProps;props.schPinSpacing!==void 0&&db22.source_property_ignored_warning.insert({source_component_id:group2.source_group_id??"",property_name:"schPinSpacing",error_type:"source_property_ignored_warning",message:"schPinSpacing is deprecated and will be ignored. Pin spacing is always 0.2."}),normalizeGroupSchematicBoxPorts(group2);let dimensions4=group2._getSchematicBoxDimensions();if(!dimensions4)return;let center2=group2._getGlobalSchematicPositionBeforeLayout(),size3=dimensions4.getSize(),portLabels=group2._getPinLabelsFromPorts(),schPortArrangement=group2._getSchematicPortArrangement(),schematicComponent=db22.schematic_component.insert({center:center2,size:size3,source_group_id:group2.source_group_id,schematic_group_id:group2.schematic_group_id??void 0,subcircuit_id:group2.subcircuit_id??group2.getSubcircuit()?.subcircuit_id??void 0,is_schematic_group:!0,is_box_with_pins:!0,port_arrangement:underscorifyPortArrangement(schPortArrangement),pin_spacing:.2,pin_styles:underscorifyPinStyles(props.schPinStyle,portLabels),port_labels:portLabels,schematic_sheet_id:group2._resolveSchematicSheetId()});group2.schematic_component_id=schematicComponent.schematic_component_id,group2.schematic_group_id&&db22.schematic_group.update(group2.schematic_group_id,{center:center2,width:size3.width,height:size3.height,schematic_component_ids:[schematicComponent.schematic_component_id]});let title=props.schTitle??props.name;title&&db22.schematic_text.insert({text:title,schematic_component_id:schematicComponent.schematic_component_id,anchor:"left",rotation:0,position:{x:center2.x-size3.width/2,y:center2.y+size3.height/2+.13},color:"#006464",font_size:.18,schematic_sheet_id:group2._resolveSchematicSheetId()})},getSizeOfTreeNodeChild=(db22,child)=>{let{sourceComponent,sourceGroup}=child;if(child.nodeType==="component"){let schComponent=db22.schematic_component.getWhere({source_component_id:sourceComponent?.source_component_id});return schComponent?.size?{width:schComponent.size.width,height:schComponent.size.height}:null}if(child.nodeType==="group"){let schGroup=db22.schematic_group.getWhere({source_group_id:sourceGroup?.source_group_id});if(schGroup?.width&&schGroup?.height)return{width:schGroup.width,height:schGroup.height};let groupComponents=db22.schematic_component.list({schematic_group_id:schGroup?.schematic_group_id}),minX=1/0,maxX=-1/0,minY=1/0,maxY=-1/0;for(let comp of groupComponents)if(comp.center&&comp.size){let halfWidth=comp.size.width/2,halfHeight=comp.size.height/2;minX=Math.min(minX,comp.center.x-halfWidth),maxX=Math.max(maxX,comp.center.x+halfWidth),minY=Math.min(minY,comp.center.y-halfHeight),maxY=Math.max(maxY,comp.center.y+halfHeight)}let groupWidth=maxX-minX,groupHeight=maxY-minY;return{width:groupWidth,height:groupHeight}}return null},Group_doInitialSchematicLayoutFlex=group2=>{let{db:db22}=group2.root,props=group2._parsedProps,tree=getCircuitJsonTree(db22.toArray(),{source_group_id:group2.source_group_id}),rawJustify=props.schJustifyContent??props.justifyContent,rawAlign=props.schAlignItems??props.alignItems,rawGap=props.schFlexGap??props.schGap??props.gap,direction3=props.schFlexDirection??"row",justifyContent={start:"flex-start",end:"flex-end","flex-start":"flex-start","flex-end":"flex-end",stretch:"space-between","space-between":"space-between","space-around":"space-around","space-evenly":"space-evenly",center:"center"}[rawJustify??"space-between"],alignItems={start:"flex-start",end:"flex-end","flex-start":"flex-start","flex-end":"flex-end",stretch:"stretch",center:"center"}[rawAlign??"center"];if(!justifyContent)throw new Error(`Invalid justifyContent value: "${rawJustify}"`);if(!alignItems)throw new Error(`Invalid alignItems value: "${rawAlign}"`);let rowGap=0,columnGap=0;typeof rawGap=="object"?(rowGap=rawGap.y??0,columnGap=rawGap.x??0):typeof rawGap=="number"?(rowGap=rawGap,columnGap=rawGap):typeof rawGap=="string"&&(rowGap=length.parse(rawGap),columnGap=length.parse(rawGap));let minFlexContainer,width=props.width??props.schWidth??void 0,height=props.height??props.schHeight??void 0;(width===void 0||height===void 0)&&(minFlexContainer=getMinimumFlexContainer(tree.childNodes.map(child=>getSizeOfTreeNodeChild(db22,child)).filter(size3=>size3!==null),{alignItems,justifyContent,direction:direction3,rowGap,columnGap}),width=minFlexContainer.width,height=minFlexContainer.height);let flexBox=new RootFlexBox(width,height,{alignItems,justifyContent,direction:direction3,rowGap,columnGap});for(let child of tree.childNodes){let size3=getSizeOfTreeNodeChild(db22,child);flexBox.addChild({metadata:child,width:size3?.width??0,height:size3?.height??0,flexBasis:size3?direction3==="row"?size3.width:size3.height:void 0})}flexBox.build();let bounds={minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0,width:0,height:0};for(let child of flexBox.children)bounds.minX=Math.min(bounds.minX,child.position.x),bounds.minY=Math.min(bounds.minY,child.position.y),bounds.maxX=Math.max(bounds.maxX,child.position.x+child.size.width),bounds.maxY=Math.max(bounds.maxY,child.position.y+child.size.height);bounds.width=bounds.maxX-bounds.minX,bounds.height=bounds.maxY-bounds.minY;let offset2={x:-(bounds.maxX+bounds.minX)/2,y:-(bounds.maxY+bounds.minY)/2},allCircuitJson=db22.toArray();for(let child of flexBox.children){let{sourceComponent,sourceGroup}=child.metadata;if(sourceComponent){let schComponent=db22.schematic_component.getWhere({source_component_id:sourceComponent.source_component_id});if(!schComponent)continue;repositionSchematicComponentTo(allCircuitJson,schComponent.schematic_component_id,{x:child.position.x+child.size.width/2+offset2.x,y:child.position.y+child.size.height/2+offset2.y})}if(sourceGroup){if(!db22.schematic_group.getWhere({source_group_id:sourceGroup.source_group_id}))continue;repositionSchematicGroupTo(allCircuitJson,sourceGroup.source_group_id,{x:child.position.x+child.size.width/2+offset2.x,y:child.position.y+child.size.height/2+offset2.y})}}group2.schematic_group_id&&db22.schematic_group.update(group2.schematic_group_id,{width:bounds.width,height:bounds.height})};function updateSchematicPrimitivesForLayoutShift({db:db22,schematicComponentId,deltaX,deltaY}){let rects=db22.schematic_rect.list({schematic_component_id:schematicComponentId});for(let rect of rects)rect.center.x+=deltaX,rect.center.y+=deltaY;let lines=db22.schematic_line.list({schematic_component_id:schematicComponentId});for(let line2 of lines)line2.x1+=deltaX,line2.y1+=deltaY,line2.x2+=deltaX,line2.y2+=deltaY;let circles=db22.schematic_circle.list({schematic_component_id:schematicComponentId});for(let circle3 of circles)circle3.center.x+=deltaX,circle3.center.y+=deltaY;let arcs=db22.schematic_arc.list({schematic_component_id:schematicComponentId});for(let arc2 of arcs)arc2.center.x+=deltaX,arc2.center.y+=deltaY;let paths=db22.schematic_path.list({schematic_component_id:schematicComponentId});for(let path of paths)for(let point62 of path.points)point62.x+=deltaX,point62.y+=deltaY}function Group_doInitialSchematicLayoutGrid(group2){let{db:db22}=group2.root,props=group2._parsedProps,schematicChildren=group2.children.filter(child=>{let isExplicitlyPositioned=child._parsedProps?.schX!==void 0||child._parsedProps?.schY!==void 0;return child.schematic_component_id&&!isExplicitlyPositioned});if(schematicChildren.length===0)return;let maxCellWidth=0,maxCellHeight=0;for(let child of schematicChildren){let schComp=db22.schematic_component.get(child.schematic_component_id);schComp?.size&&(maxCellWidth=Math.max(maxCellWidth,schComp.size.width),maxCellHeight=Math.max(maxCellHeight,schComp.size.height))}maxCellWidth===0&&schematicChildren.length>0&&(maxCellWidth=1),maxCellHeight===0&&schematicChildren.length>0&&(maxCellHeight=1);let gridColsOption=props.gridCols,gridRowsOption,gridGapOption=props.gridGap,gridRowGapOption=props.gridRowGap,gridColumnGapOption=props.gridColumnGap;props.schLayout?.grid&&(gridColsOption=props.schLayout.grid.cols??gridColsOption,gridRowsOption=props.schLayout.grid.rows,gridGapOption=props.schLayout.gridGap??gridGapOption,gridRowGapOption=props.schLayout.gridRowGap??gridRowGapOption,gridColumnGapOption=props.schLayout.gridColumnGap??gridColumnGapOption);let numCols,numRows;gridColsOption!==void 0&&gridRowsOption!==void 0?(numCols=gridColsOption,numRows=gridRowsOption):gridColsOption!==void 0?(numCols=gridColsOption,numRows=Math.ceil(schematicChildren.length/numCols)):gridRowsOption!==void 0?(numRows=gridRowsOption,numCols=Math.ceil(schematicChildren.length/numRows)):(numCols=Math.ceil(Math.sqrt(schematicChildren.length)),numRows=Math.ceil(schematicChildren.length/numCols)),numCols===0&&schematicChildren.length>0&&(numCols=1),numRows===0&&schematicChildren.length>0&&(numRows=schematicChildren.length);let gridGapX,gridGapY,parseGap=val=>{if(val!==void 0)return typeof val=="number"?val:length.parse(val)};if(gridRowGapOption!==void 0||gridColumnGapOption!==void 0){let fallbackX=typeof gridGapOption=="object"&&gridGapOption!==null?gridGapOption.x:gridGapOption,fallbackY=typeof gridGapOption=="object"&&gridGapOption!==null?gridGapOption.y:gridGapOption;gridGapX=parseGap(gridColumnGapOption??fallbackX)??1,gridGapY=parseGap(gridRowGapOption??fallbackY)??1}else if(typeof gridGapOption=="number")gridGapX=gridGapOption,gridGapY=gridGapOption;else if(typeof gridGapOption=="string"){let parsed=length.parse(gridGapOption);gridGapX=parsed,gridGapY=parsed}else if(typeof gridGapOption=="object"&&gridGapOption!==null){let xRaw=gridGapOption.x,yRaw=gridGapOption.y;gridGapX=typeof xRaw=="number"?xRaw:length.parse(xRaw??"0mm"),gridGapY=typeof yRaw=="number"?yRaw:length.parse(yRaw??"0mm")}else gridGapX=1,gridGapY=1;let totalGridWidth=numCols*maxCellWidth+Math.max(0,numCols-1)*gridGapX,totalGridHeight=numRows*maxCellHeight+Math.max(0,numRows-1)*gridGapY,groupCenter=group2._getGlobalSchematicPositionBeforeLayout(),firstCellCenterX=groupCenter.x-totalGridWidth/2+maxCellWidth/2,firstCellCenterY=groupCenter.y+totalGridHeight/2-maxCellHeight/2;for(let i22=0;i22<schematicChildren.length;i22++){let child=schematicChildren[i22];if(!child.schematic_component_id)continue;let row=Math.floor(i22/numCols),col=i22%numCols;if(row>=numRows||col>=numCols){console.warn(`Schematic grid layout: Child ${child.getString()} at index ${i22} (row ${row}, col ${col}) exceeds specified grid dimensions (${numRows}x${numCols}). Skipping placement.`);continue}let targetCellCenterX=firstCellCenterX+col*(maxCellWidth+gridGapX),targetCellCenterY=firstCellCenterY-row*(maxCellHeight+gridGapY),schComp=db22.schematic_component.get(child.schematic_component_id);if(schComp){let oldChildCenter=schComp.center,newChildCenter={x:targetCellCenterX,y:targetCellCenterY};db22.schematic_component.update(child.schematic_component_id,{center:newChildCenter});let deltaX=newChildCenter.x-oldChildCenter.x,deltaY=newChildCenter.y-oldChildCenter.y,schPorts=db22.schematic_port.list({schematic_component_id:child.schematic_component_id});for(let port of schPorts)db22.schematic_port.update(port.schematic_port_id,{center:{x:port.center.x+deltaX,y:port.center.y+deltaY}});let schTexts=db22.schematic_text.list({schematic_component_id:child.schematic_component_id});for(let text of schTexts)db22.schematic_text.update(text.schematic_text_id,{position:{x:text.position.x+deltaX,y:text.position.y+deltaY}});updateSchematicPrimitivesForLayoutShift({db:db22,schematicComponentId:child.schematic_component_id,deltaX,deltaY})}}group2.schematic_group_id&&db22.schematic_group.update(group2.schematic_group_id,{width:totalGridWidth,height:totalGridHeight,center:groupCenter})}var debug52=(0,import_debug13.default)("Group_doInitialSchematicLayoutMatchAdapt");function Group_doInitialSchematicLayoutMatchAdapt(group2){let{db:db22}=group2.root,subtreeCircuitJson=buildSubtree(db22.toArray(),{source_group_id:group2.source_group_id});if(subtreeCircuitJson.filter(item=>item.type==="source_component").length<=1)return;let floatingGraph=convertCircuitJsonToBpc(subtreeCircuitJson);debug52.enabled&&global?.debugGraphics&&global.debugGraphics?.push(getGraphicsForBpcGraph(floatingGraph,{title:`floatingBpcGraph-${group2.name}`}));let floatingGraphNoNotConnected={boxes:floatingGraph.boxes,pins:floatingGraph.pins.map(p22=>({...p22,color:p22.color.replace("not_connected","normal")}))},{result:laidOutBpcGraph}=layoutSchematicGraphVariants([{variantName:"default",floatingGraph},{variantName:"noNotConnected",floatingGraph:floatingGraphNoNotConnected}],{singletonKeys:["vcc/2","gnd/2"],centerPinColors:["netlabel_center","component_center"],floatingBoxIdsWithMutablePinOffsets:new Set(floatingGraph.boxes.filter(box2=>floatingGraph.pins.filter(p22=>p22.boxId===box2.boxId).filter(bp22=>!bp22.color.includes("center")).length<=2).map(b22=>b22.boxId)),corpus:{}});debug52.enabled&&global?.debugGraphics&&global.debugGraphics?.push(getGraphicsForBpcGraph(laidOutBpcGraph,{title:`laidOutBpcGraph-${group2.name}`}));let groupOffset=group2._getGlobalSchematicPositionBeforeLayout();for(let box2 of laidOutBpcGraph.boxes){if(!box2.center)continue;let schematic_component23=db22.schematic_component.get(box2.boxId);if(schematic_component23){let newCenter={x:box2.center.x+groupOffset.x,y:box2.center.y+groupOffset.y},ports=db22.schematic_port.list({schematic_component_id:schematic_component23.schematic_component_id}),texts=db22.schematic_text.list({schematic_component_id:schematic_component23.schematic_component_id}),positionDelta={x:newCenter.x-schematic_component23.center.x,y:newCenter.y-schematic_component23.center.y};for(let port of ports)port.center.x+=positionDelta.x,port.center.y+=positionDelta.y;for(let text of texts)text.position.x+=positionDelta.x,text.position.y+=positionDelta.y;updateSchematicPrimitivesForLayoutShift({db:db22,schematicComponentId:schematic_component23.schematic_component_id,deltaX:positionDelta.x,deltaY:positionDelta.y}),schematic_component23.center=newCenter;continue}let schematic_net_label3=db22.schematic_net_label.get(box2.boxId);if(schematic_net_label3){let pin=laidOutBpcGraph.pins.find(p22=>p22.boxId===box2.boxId&&p22.color==="netlabel_center");if(!pin)throw new Error(`No pin found for net label: ${box2.boxId}`);let finalCenter={x:box2.center.x+groupOffset.x,y:box2.center.y+groupOffset.y};schematic_net_label3.center=finalCenter,schematic_net_label3.anchor_position={x:finalCenter.x+pin.offset.x,y:finalCenter.y+pin.offset.y};continue}console.error(`No schematic element found for box: ${box2.boxId}. This is a bug in the matchAdapt binding with @tscircuit/core`)}}function getSchematicTextWidth2({text,fontSize}){let charWidth=.12*(fontSize/.18);return text.length*charWidth}var SYMBOL_TEXT_FONT_SIZE=.18,TEXT_BOX_ENABLED_FTYPES=new Set(["simple_resistor","simple_capacitor","simple_inductor","simple_crystal","simple_resonator","simple_potentiometer","simple_fuse","simple_diode","simple_led","simple_transistor","simple_mosfet","simple_op_amp","simple_voltage_source","simple_test_point"]);function getSchematicTextBounds({text,position:position4,anchor:anchor3,fontSize}){let width=getSchematicTextWidth2({text,fontSize}),height=fontSize,relMinX,relMaxX;anchor3.includes("left")?(relMinX=0,relMaxX=width):anchor3.includes("right")?(relMinX=-width,relMaxX=0):(relMinX=-width/2,relMaxX=width/2);let relMinY,relMaxY;return anchor3.includes("top")?(relMinY=-height,relMaxY=0):anchor3.includes("bottom")?(relMinY=0,relMaxY=height):(relMinY=-height/2,relMaxY=height/2),{minX:position4.x+relMinX,maxX:position4.x+relMaxX,minY:position4.y+relMinY,maxY:position4.y+relMaxY}}function getSymbolTextBounds({schematicComponent,sourceComponent}){if(!schematicComponent.symbol_name)return[];let symbol=zh[schematicComponent.symbol_name];if(!symbol?.primitives||!symbol.center)return[];let textBounds=[];for(let primitive of symbol.primitives){if(primitive.type!=="text")continue;let value;primitive.text==="{REF}"?value=sourceComponent?.display_name??sourceComponent?.name??"":primitive.text==="{VAL}"?value=schematicComponent.symbol_display_value??"":value=primitive.text??"",value&&textBounds.push(getSchematicTextBounds({text:value,position:{x:primitive.x-symbol.center.x+schematicComponent.center.x,y:primitive.y-symbol.center.y+schematicComponent.center.y},anchor:primitive.anchor??"center",fontSize:SYMBOL_TEXT_FONT_SIZE}))}return textBounds}function getSymbolBoxBounds(schematicComponent){return getBoundFromCenteredRect({center:schematicComponent.center,width:schematicComponent.size.width,height:schematicComponent.size.height})}function getSchematicComponentTextInclusiveBounds(db22,schematicComponent){if(!schematicComponent.center||!schematicComponent.size)return null;let sourceComponent=schematicComponent.source_component_id?db22.source_component.get(schematicComponent.source_component_id):void 0;if(!sourceComponent||!TEXT_BOX_ENABLED_FTYPES.has(sourceComponent.ftype))return null;let textBounds=getSymbolTextBounds({schematicComponent,sourceComponent});if(textBounds.length===0)return null;let boxBounds=getSymbolBoxBounds(schematicComponent),bounds={...boxBounds};for(let textBound of textBounds)bounds.minX=Math.min(bounds.minX,textBound.minX),bounds.maxX=Math.max(bounds.maxX,textBound.maxX),bounds.minY=Math.min(bounds.minY,textBound.minY),bounds.maxY=Math.max(bounds.maxY,textBound.maxY);return bounds.minX===boxBounds.minX&&bounds.maxX===boxBounds.maxX&&bounds.minY===boxBounds.minY&&bounds.maxY===boxBounds.maxY?null:bounds}function getOrientedSchematicComponent(schematicComponent,ccwRotationDegrees){let size3=schematicComponent.size;return size3&&(size3=getRotatedSize2(size3,ccwRotationDegrees)),{...schematicComponent,symbol_name:getRotatedSymbolName(schematicComponent.symbol_name,ccwRotationDegrees),size:size3}}function getSchematicComponentWithTextBounds({db:db22,schematicComponent,ccwRotationDegrees=0}){let orientedComponent=getOrientedSchematicComponent(schematicComponent,ccwRotationDegrees),textBounds=getSchematicComponentTextInclusiveBounds(db22,orientedComponent);if(!textBounds)return null;let boxBounds=getSymbolBoxBounds(orientedComponent);if(orientedComponent.size.height>orientedComponent.size.width)return textBounds;let padLeft=Math.max(0,boxBounds.minX-textBounds.minX),padRight=Math.max(0,textBounds.maxX-boxBounds.maxX),padTop=Math.max(0,textBounds.maxY-boxBounds.maxY),padBottom=Math.max(0,boxBounds.minY-textBounds.minY),left=padLeft,right=padRight;padLeft>0&&padRight>0&&(left=Math.max(padLeft,padRight),right=left);let top=padTop,bottom=padBottom;return padTop>0&&padBottom>0&&(top=Math.max(padTop,padBottom),bottom=top),{minX:boxBounds.minX-left,maxX:boxBounds.maxX+right,minY:boxBounds.minY-bottom,maxY:boxBounds.maxY+top}}var debug62=(0,import_debug14.default)("Group_doInitialSchematicLayoutMatchpack"),DEFAULT_AVAILABLE_ROTATIONS=[0,90,180,270],ROTATION_TO_PLACE_SIDE_ON_TOP={"y+":0,"x+":90,"y-":180,"x-":270};function facingDirectionToSide(facingDirection){switch(facingDirection){case"up":return"y+";case"down":return"y-";case"left":return"x-";case"right":return"x+";default:return"y+"}}function getPowerGroundForcedRotation(db22,ports){if(ports.length!==2)return null;let powerGroundRotations=new Set;for(let port of ports){let connectivityKey=db22.source_port.get(port.source_port_id)?.subcircuit_connectivity_map_key;if(!connectivityKey)continue;let net=db22.source_net.getWhere({subcircuit_connectivity_map_key:connectivityKey});if(!net)continue;let isGround=net.is_ground??!1,isPositiveVoltageSource=net.is_power===!0||net.is_positive_voltage_source===!0;if(isPositiveVoltageSource===isGround)continue;let rotationToPlacePinOnTop=ROTATION_TO_PLACE_SIDE_ON_TOP[facingDirectionToSide(port.facing_direction)],rotation5=isPositiveVoltageSource?rotationToPlacePinOnTop:(rotationToPlacePinOnTop+180)%360;powerGroundRotations.add(rotation5)}return powerGroundRotations.size===1?powerGroundRotations.values().next().value:null}function getChipSize({db:db22,schematicComponent,component,ccwRotationDegrees}){let orientedSymbolSize=schematicComponent.size;orientedSymbolSize&&(orientedSymbolSize=getRotatedSize2(orientedSymbolSize,ccwRotationDegrees));let componentWithTextBounds=getSchematicComponentWithTextBounds({db:db22,schematicComponent,ccwRotationDegrees}),textPadLeft=0,textPadRight=0,textPadTop=0,textPadBottom=0;if(componentWithTextBounds&&schematicComponent.center){let halfWidth=(orientedSymbolSize?.width??0)/2,halfHeight=(orientedSymbolSize?.height??0)/2;textPadLeft=schematicComponent.center.x-halfWidth-componentWithTextBounds.minX,textPadRight=componentWithTextBounds.maxX-(schematicComponent.center.x+halfWidth),textPadTop=componentWithTextBounds.maxY-(schematicComponent.center.y+halfHeight),textPadBottom=schematicComponent.center.y-halfHeight-componentWithTextBounds.minY}let marginLeft=(component?._parsedProps?.schMarginLeft??component?._parsedProps?.schMarginX??0)+textPadLeft,marginRight=(component?._parsedProps?.schMarginRight??component?._parsedProps?.schMarginX??0)+textPadRight,marginTop=(component?._parsedProps?.schMarginTop??component?._parsedProps?.schMarginY??0)+textPadTop,marginBottom=(component?._parsedProps?.schMarginBottom??component?._parsedProps?.schMarginY??0)+textPadBottom;component?.config.shouldRenderAsSchematicBox&&(marginTop+=.4,marginBottom+=.4);let orientedFootprint={width:(orientedSymbolSize?.width||1)+marginLeft+marginRight,height:(orientedSymbolSize?.height||1)+marginTop+marginBottom},chipSize=getRotatedSize2(orientedFootprint,ccwRotationDegrees);return{x:chipSize.width,y:chipSize.height}}function getReservedChipSize({db:db22,schematicComponent,component,ccwRotationDegrees,chipGap}){let unrotatedSize=getChipSize({db:db22,schematicComponent,component,ccwRotationDegrees:0});if(!shouldSwapOrientation(ccwRotationDegrees))return unrotatedSize;let rotatedSize=getChipSize({db:db22,schematicComponent,component,ccwRotationDegrees});return rotatedSize.x-unrotatedSize.x>=chipGap||rotatedSize.y-unrotatedSize.y>=chipGap?rotatedSize:unrotatedSize}function getNestedGroupMatchpackProxy({db:db22,schematicGroup,groupComponents,groupInstance}){let minX=1/0,maxX=-1/0,minY=1/0,maxY=-1/0,hasValidBounds=!1;for(let component of groupComponents){if(!component.center||!component.size)continue;hasValidBounds=!0;let componentBounds=getSchematicComponentWithTextBounds({db:db22,schematicComponent:component})??getBoundFromCenteredRect({center:component.center,width:component.size.width,height:component.size.height});minX=Math.min(minX,componentBounds.minX),maxX=Math.max(maxX,componentBounds.maxX),minY=Math.min(minY,componentBounds.minY),maxY=Math.max(maxY,componentBounds.maxY)}let marginLeft=groupInstance?._parsedProps?.schMarginLeft??groupInstance?._parsedProps?.schMarginX??0,marginRight=groupInstance?._parsedProps?.schMarginRight??groupInstance?._parsedProps?.schMarginX??0,marginTop=groupInstance?._parsedProps?.schMarginTop??groupInstance?._parsedProps?.schMarginY??0,marginBottom=groupInstance?._parsedProps?.schMarginBottom??groupInstance?._parsedProps?.schMarginY??0,contentCenter=hasValidBounds?{x:(minX+maxX)/2,y:(minY+maxY)/2}:schematicGroup.center??{x:0,y:0};return{center:{x:contentCenter.x+(marginRight-marginLeft)/2,y:contentCenter.y+(marginTop-marginBottom)/2},size:{x:(hasValidBounds?maxX-minX:2)+marginLeft+marginRight,y:(hasValidBounds?maxY-minY:2)+marginTop+marginBottom}}}function isTreeChildExplicitlyPositioned(treeChild,group2){if(treeChild.nodeType==="component"&&treeChild.sourceComponent){let component=group2.children.find(groupChild=>groupChild.source_component_id===treeChild.sourceComponent?.source_component_id);return component?._parsedProps?.schX!==void 0||component?._parsedProps?.schY!==void 0}if(treeChild.nodeType==="group"&&treeChild.sourceGroup){let nestedGroup=group2.children.find(groupChild=>groupChild.source_group_id===treeChild.sourceGroup?.source_group_id);return nestedGroup?._parsedProps?.schX!==void 0||nestedGroup?._parsedProps?.schY!==void 0}return!1}function getTreeChildChipId(child,index2){return child.nodeType==="component"&&child.sourceComponent?child.sourceComponent.name||`chip_${index2}`:child.nodeType==="group"&&child.sourceGroup?child.sourceGroup.name||`group_${index2}`:null}var getSchematicComponentForSourceComponent=({db:db22,sourceComponentId,schematicSheetId})=>db22.schematic_component.getWhere({source_component_id:sourceComponentId,...schematicSheetId?{schematic_sheet_id:schematicSheetId}:{}});function convertTreeToMatchPackInputProblem(tree,db22,group2,opts={}){let problem={chipMap:{},chipPinMap:{},netMap:{},pinStrongConnMap:{},netConnMap:{},chipGap:.6,decouplingCapsGap:.4,partitionGap:1.2},nestedGroupMatchpackProxyMap={},groupOffset=group2._getGlobalSchematicPositionBeforeLayout();debug62(`[${group2.name}] Processing ${tree.childNodes.length} child nodes for input problem`),tree.childNodes.forEach((child,index2)=>{let explicitlyPositioned=isTreeChildExplicitlyPositioned(child,group2);if(debug62(explicitlyPositioned?`[${group2.name}] Child ${index2} explicitly positioned, including as fixed chip`:`[${group2.name}] Processing child ${index2}: nodeType=${child.nodeType}`),child.nodeType==="component"?debug62(`[${group2.name}] - Component: ${child.sourceComponent?.name}`):child.nodeType==="group"&&debug62(`[${group2.name}] - Group: ${child.sourceGroup?.name}`),child.nodeType==="component"&&child.sourceComponent){let chipId=getTreeChildChipId(child,index2),schematicComponent=getSchematicComponentForSourceComponent({db:db22,sourceComponentId:child.sourceComponent.source_component_id,schematicSheetId:opts.schematicSheetId});if(!schematicComponent)return;let component=group2.children.find(groupChild=>groupChild.source_component_id===child.sourceComponent?.source_component_id),ports=db22.schematic_port.list({schematic_component_id:schematicComponent.schematic_component_id}),availableRotations=[...DEFAULT_AVAILABLE_ROTATIONS];if(component?._parsedProps?.schOrientation&&(availableRotations=[0]),component?._parsedProps?.schRotation!==void 0&&(availableRotations=[0]),component?._parsedProps?.facingDirection&&(availableRotations=[0]),component?._parsedProps?.schFacingDirection&&(availableRotations=[0]),component?.componentName==="Chip"&&(availableRotations=[0]),availableRotations.length===DEFAULT_AVAILABLE_ROTATIONS.length){let forcedRotation=getPowerGroundForcedRotation(db22,ports);forcedRotation!==null&&(availableRotations=[forcedRotation])}let ccwRotationDegrees=availableRotations.length===1?availableRotations[0]:0;problem.chipMap[chipId]={chipId,pins:[],size:getReservedChipSize({db:db22,schematicComponent,component,ccwRotationDegrees,chipGap:problem.chipGap}),isCapacitor:child.sourceComponent.ftype==="simple_capacitor",isCrystal:child.sourceComponent.ftype==="simple_crystal",isResistor:child.sourceComponent.ftype==="simple_resistor",isTestPoint:child.sourceComponent.ftype==="simple_test_point",availableRotations,...explicitlyPositioned&&{fixedPosition:{x:schematicComponent.center.x-groupOffset.x,y:schematicComponent.center.y-groupOffset.y}}};for(let port of ports){let sourcePort=db22.source_port.get(port.source_port_id);if(!sourcePort)continue;let pinId=`${chipId}.${sourcePort.pin_number||sourcePort.name||port.schematic_port_id}`;problem.chipMap[chipId].pins.push(pinId);let side=facingDirectionToSide(port.facing_direction);problem.chipPinMap[pinId]={pinId,offset:{x:(port.center?.x||0)-(schematicComponent.center.x||0),y:(port.center?.y||0)-(schematicComponent.center.y||0)},side}}}else if(child.nodeType==="group"&&child.sourceGroup){let groupId=getTreeChildChipId(child,index2);debug62(`[${group2.name}] Processing nested group: ${groupId}`);let schematicGroup=db22.schematic_group?.getWhere?.({source_group_id:child.sourceGroup.source_group_id}),groupInstance=group2.children.find(groupChild=>groupChild.source_group_id===child.sourceGroup?.source_group_id);if(debug62(`[${group2.name}] Found schematic_group for ${groupId}:`,schematicGroup),schematicGroup){debug62(`[${group2.name}] Treating group ${groupId} as composite chip`);let groupComponents=db22.schematic_component.list({schematic_group_id:schematicGroup.schematic_group_id});debug62(`[${group2.name}] Group ${groupId} has ${groupComponents.length} components:`,groupComponents.map(c22=>c22.source_component_id));let matchpackProxy=getNestedGroupMatchpackProxy({db:db22,schematicGroup,groupComponents,groupInstance});nestedGroupMatchpackProxyMap[groupId]=matchpackProxy,debug62(`[${group2.name}] Group ${groupId} computed proxy: ${matchpackProxy.size.x} x ${matchpackProxy.size.y} centered at (${matchpackProxy.center.x}, ${matchpackProxy.center.y})`);let groupPins=[];for(let comp of groupComponents){let ports=db22.schematic_port.list({schematic_component_id:comp.schematic_component_id});for(let port of ports){let sourcePort=db22.source_port.get(port.source_port_id);if(!sourcePort)continue;let pinId=`${groupId}.${sourcePort.pin_number||sourcePort.name||port.schematic_port_id}`;groupPins.push(pinId);let side=facingDirectionToSide(port.facing_direction);problem.chipPinMap[pinId]={pinId,offset:{x:(port.center?.x||0)-matchpackProxy.center.x,y:(port.center?.y||0)-matchpackProxy.center.y},side}}}debug62(`[${group2.name}] Group ${groupId} has ${groupPins.length} pins:`,groupPins),problem.chipMap[groupId]={chipId:groupId,pins:groupPins,size:matchpackProxy.size},debug62(`[${group2.name}] Added group ${groupId} to chipMap`)}else debug62(`[${group2.name}] Warning: No schematic_group found for group ${groupId}`)}}),debug62(`[${group2.name}] Creating connections using connectivity keys`);let connectivityGroups=new Map;for(let[chipId,chip]of Object.entries(problem.chipMap))for(let pinId of chip.pins){let pinNumber=pinId.split(".").pop(),treeNode=tree.childNodes.find(child=>getTreeChildChipId(child,tree.childNodes.indexOf(child))===chipId);if(treeNode?.nodeType==="group"&&treeNode.sourceGroup){let schematicGroup=db22.schematic_group?.getWhere?.({source_group_id:treeNode.sourceGroup.source_group_id});if(schematicGroup){let groupComponents=db22.schematic_component.list({schematic_group_id:schematicGroup.schematic_group_id});for(let comp of groupComponents){let sourcePorts=db22.source_port.list({source_component_id:comp.source_component_id});for(let sourcePort of sourcePorts){let portNumber=sourcePort.pin_number||sourcePort.name;if(String(portNumber)===String(pinNumber))if(sourcePort.subcircuit_connectivity_map_key){let connectivityKey=sourcePort.subcircuit_connectivity_map_key;connectivityGroups.has(connectivityKey)||connectivityGroups.set(connectivityKey,[]),connectivityGroups.get(connectivityKey).push(pinId),debug62(`[${group2.name}] \u2713 Pin ${pinId} has connectivity key: ${connectivityKey}`)}else debug62(`[${group2.name}] Pin ${pinId} has no connectivity key`)}}}}else if(treeNode?.nodeType==="component"&&treeNode.sourceComponent){let sourcePorts=db22.source_port.list({source_component_id:treeNode.sourceComponent.source_component_id});for(let sourcePort of sourcePorts){let portNumber=sourcePort.pin_number||sourcePort.name;if(String(portNumber)===String(pinNumber)&&sourcePort.subcircuit_connectivity_map_key){let connectivityKey=sourcePort.subcircuit_connectivity_map_key;connectivityGroups.has(connectivityKey)||connectivityGroups.set(connectivityKey,[]),connectivityGroups.get(connectivityKey).push(pinId),debug62(`[${group2.name}] Pin ${pinId} has connectivity key: ${connectivityKey}`)}}}}debug62(`[${group2.name}] Found ${connectivityGroups.size} connectivity groups:`,Array.from(connectivityGroups.entries()).map(([key,pins])=>({key,pins})));for(let[connectivityKey,pins]of connectivityGroups){let tracesWithThisKey=db22.source_trace.list().filter(trace=>trace.subcircuit_connectivity_map_key===connectivityKey),hasNetConnections=tracesWithThisKey.some(trace=>trace.connected_source_net_ids&&trace.connected_source_net_ids.length>0),hasDirectConnections=tracesWithThisKey.some(trace=>trace.connected_source_port_ids&&trace.connected_source_port_ids.length>=2);if(debug62(`[${group2.name}] Connectivity ${connectivityKey}: hasNetConnections=${hasNetConnections}, hasDirectConnections=${hasDirectConnections}`),pins.length>=2&&hasDirectConnections){for(let trace of tracesWithThisKey)if(trace.connected_source_port_ids&&trace.connected_source_port_ids.length>=2){let directlyConnectedPins=[];for(let portId of trace.connected_source_port_ids)for(let pinId of pins){let pinNumber=pinId.split(".").pop(),sourcePort=db22.source_port.get(portId);if(sourcePort&&String(sourcePort.pin_number||sourcePort.name)===String(pinNumber)){let chipId=pinId.split(".")[0],treeNode=tree.childNodes.find(child=>getTreeChildChipId(child,tree.childNodes.indexOf(child))===chipId);treeNode?.nodeType==="component"&&treeNode.sourceComponent&&db22.source_port.list({source_component_id:treeNode.sourceComponent.source_component_id}).some(p22=>p22.source_port_id===portId)&&directlyConnectedPins.push(pinId)}}for(let i22=0;i22<directlyConnectedPins.length;i22++)for(let j22=i22+1;j22<directlyConnectedPins.length;j22++){let pin1=directlyConnectedPins[i22],pin2=directlyConnectedPins[j22];problem.pinStrongConnMap[`${pin1}-${pin2}`]=!0,problem.pinStrongConnMap[`${pin2}-${pin1}`]=!0,debug62(`[${group2.name}] Created strong connection: ${pin1} <-> ${pin2}`)}}}if(hasNetConnections){let source_net3=db22.source_net.getWhere({subcircuit_connectivity_map_key:connectivityKey}),isGround=source_net3?.is_ground??!1,isPositiveVoltageSource=source_net3?.is_power===!0||source_net3?.is_positive_voltage_source===!0;problem.netMap[connectivityKey]={netId:connectivityKey,isGround,isPositiveVoltageSource};for(let pinId of pins)problem.netConnMap[`${pinId}-${connectivityKey}`]=!0;debug62(`[${group2.name}] Created net ${connectivityKey} with ${pins.length} pins:`,pins)}}return{inputProblem:problem,nestedGroupMatchpackProxyMap}}function applySchematicMatchPackLayoutToTree(group2,tree,opts={}){let{db:db22}=group2.root;if(debug62(`[${group2.name}] Starting matchpack layout with ${tree.childNodes.length} children`),debug62(`[${group2.name}] Tree structure:`,JSON.stringify(tree,null,2)),tree.childNodes.length<=1){debug62(`[${group2.name}] Only ${tree.childNodes.length} children, skipping layout`);return}debug62("Converting circuit tree to InputProblem...");let{inputProblem,nestedGroupMatchpackProxyMap}=convertTreeToMatchPackInputProblem(tree,db22,group2,opts);debug62.enabled&&group2.root?.emit("debug:logOutput",{type:"debug:logOutput",name:`matchpack-input-problem-${group2.name}`,content:JSON.stringify(inputProblem,null,2)});let solver=new LayoutPipelineSolver(inputProblem);if(group2.root?.emit("solver:started",{type:"solver:started",solverName:"LayoutPipelineSolver",solverParams:inputProblem,solverConstructorArgs:[inputProblem],componentName:group2.getString()}),debug62("Starting LayoutPipelineSolver..."),debug62.enabled&&global?.debugGraphics){let initialViz=solver.visualize();global.debugGraphics.push({...initialViz,title:`matchpack-initial-${group2.name}`})}if(solver.solve(),group2.root?.emit("solver:ended",{type:"solver:ended",solverName:"LayoutPipelineSolver",componentName:group2.getString(),solved:solver.solved,failed:solver.failed,iterations:solver.iterations,error:solver.error}),debug62(`Solver completed in ${solver.iterations} iterations`),debug62(`Solved: ${solver.solved}, Failed: ${solver.failed}`),solver.failed){let solverError=solver.error??"Unknown Matchpack failure";debug62(`Solver failed with error: ${solverError}`),db22.schematic_layout_error.insert({error_type:"schematic_layout_error",message:`Matchpack layout solver failed: ${solverError}`,is_fatal:!1,source_group_id:group2.source_group_id,schematic_group_id:group2.schematic_group_id,subcircuit_id:group2.subcircuit_id??void 0});return}let outputLayout=solver.getOutputLayout();if(debug62("OutputLayout:",JSON.stringify(outputLayout,null,2)),debug62("Solver completed successfully:",!solver.failed),debug62.enabled&&global?.debugGraphics){let finalViz=solver.visualize();global.debugGraphics.push({...finalViz,title:`matchpack-final-${group2.name}`})}let overlaps=solver.checkForOverlaps(outputLayout);if(overlaps.length>0){debug62(`Warning: Found ${overlaps.length} overlapping components:`);for(let overlap of overlaps)debug62(` ${overlap.chip1} overlaps ${overlap.chip2} (area: ${overlap.overlapArea})`)}let groupOffset=group2._getGlobalSchematicPositionBeforeLayout();debug62(`Group offset: x=${groupOffset.x}, y=${groupOffset.y}`),debug62(`Applying layout results for ${Object.keys(outputLayout.chipPlacements).length} chip placements`);for(let[chipId,placement]of Object.entries(outputLayout.chipPlacements)){debug62(`Processing placement for chip: ${chipId} at (${placement.x}, ${placement.y})`);let treeNode=tree.childNodes.find(child=>{let expectedChipId=getTreeChildChipId(child,tree.childNodes.indexOf(child)),matches=expectedChipId===chipId;return debug62(` Checking child ${expectedChipId}: matches=${matches}`),matches});if(!treeNode){debug62(`Warning: No tree node found for chip: ${chipId}`),debug62("Available tree nodes:",tree.childNodes.map((child,idx)=>({type:child.nodeType,name:child.nodeType==="component"?child.sourceComponent?.name:child.sourceGroup?.name,expectedChipId:getTreeChildChipId(child,idx)})));continue}let newCenter={x:placement.x+groupOffset.x,y:placement.y+groupOffset.y};if(treeNode.nodeType==="component"&&treeNode.sourceComponent){let groupChild=group2.children.find(c22=>c22.source_component_id===treeNode.sourceComponent?.source_component_id);if(groupChild?._parsedProps?.schX!==void 0||groupChild?._parsedProps?.schY!==void 0){debug62(`Skipping position update for fixed chip ${chipId}`);continue}let schematicComponent=getSchematicComponentForSourceComponent({db:db22,sourceComponentId:treeNode.sourceComponent.source_component_id,schematicSheetId:opts.schematicSheetId});if(schematicComponent){debug62(`Moving component ${chipId} to (${newCenter.x}, ${newCenter.y})`);let ports=db22.schematic_port.list({schematic_component_id:schematicComponent.schematic_component_id}),texts=db22.schematic_text.list({schematic_component_id:schematicComponent.schematic_component_id}),positionDelta={x:newCenter.x-schematicComponent.center.x,y:newCenter.y-schematicComponent.center.y};for(let port of ports)port.center.x+=positionDelta.x,port.center.y+=positionDelta.y;for(let text of texts)text.position.x+=positionDelta.x,text.position.y+=positionDelta.y;if(updateSchematicPrimitivesForLayoutShift({db:db22,schematicComponentId:schematicComponent.schematic_component_id,deltaX:positionDelta.x,deltaY:positionDelta.y}),schematicComponent.center=newCenter,placement.ccwRotationDegrees!==0){debug62(`Component ${chipId} has rotation: ${placement.ccwRotationDegrees}\xB0`);let normalizedRotation=(Math.round(placement.ccwRotationDegrees)%360+360)%360;if((normalizedRotation===90||normalizedRotation===270)&&schematicComponent.size){let prevWidth=schematicComponent.size.width;schematicComponent.size.width=schematicComponent.size.height,schematicComponent.size.height=prevWidth}let angleRad=placement.ccwRotationDegrees*Math.PI/180,cos32=Math.cos(angleRad),sin32=Math.sin(angleRad);for(let port of ports){let dx22=port.center.x-newCenter.x,dy22=port.center.y-newCenter.y,rotatedDx=dx22*cos32-dy22*sin32,rotatedDy=dx22*sin32+dy22*cos32;port.center.x=newCenter.x+rotatedDx,port.center.y=newCenter.y+rotatedDy;let originalDirection=port.facing_direction||"right";port.facing_direction=rotateDirection2(originalDirection,placement.ccwRotationDegrees),port.side_of_component=(port.facing_direction==="up"?"top":port.facing_direction==="down"?"bottom":port.facing_direction)||port.side_of_component}for(let text of texts){let dx22=text.position.x-newCenter.x,dy22=text.position.y-newCenter.y,rotatedDx=dx22*cos32-dy22*sin32,rotatedDy=dx22*sin32+dy22*cos32;text.position.x=newCenter.x+rotatedDx,text.position.y=newCenter.y+rotatedDy}schematicComponent.symbol_name&&(schematicComponent.symbol_name=getRotatedSymbolName(schematicComponent.symbol_name,placement.ccwRotationDegrees))}}}else if(treeNode.nodeType==="group"&&treeNode.sourceGroup){let schematicGroup=db22.schematic_group?.getWhere?.({source_group_id:treeNode.sourceGroup.source_group_id});if(schematicGroup){debug62(`Moving group ${chipId} to (${newCenter.x}, ${newCenter.y}) from (${schematicGroup.center?.x}, ${schematicGroup.center?.y})`);let groupComponents=db22.schematic_component.list({schematic_group_id:schematicGroup.schematic_group_id});debug62(`Group ${chipId} has ${groupComponents.length} components to move`);let matchpackProxy=nestedGroupMatchpackProxyMap[chipId],oldCenter=matchpackProxy?.center??schematicGroup.center??{x:0,y:0},positionDelta={x:newCenter.x-oldCenter.x,y:newCenter.y-oldCenter.y};debug62(`Position delta for group ${chipId}: (${positionDelta.x}, ${positionDelta.y})`);for(let component of groupComponents)if(component.center){let oldComponentCenter={...component.center};component.center.x+=positionDelta.x,component.center.y+=positionDelta.y,debug62(`Moved component ${component.source_component_id} from (${oldComponentCenter.x}, ${oldComponentCenter.y}) to (${component.center.x}, ${component.center.y})`);let ports=db22.schematic_port.list({schematic_component_id:component.schematic_component_id}),texts=db22.schematic_text.list({schematic_component_id:component.schematic_component_id});for(let port of ports)port.center&&(port.center.x+=positionDelta.x,port.center.y+=positionDelta.y);for(let text of texts)text.position&&(text.position.x+=positionDelta.x,text.position.y+=positionDelta.y);updateSchematicPrimitivesForLayoutShift({db:db22,schematicComponentId:component.schematic_component_id,deltaX:positionDelta.x,deltaY:positionDelta.y})}schematicGroup.center=newCenter,matchpackProxy&&(schematicGroup.width=matchpackProxy.size.x,schematicGroup.height=matchpackProxy.size.y),debug62(`Updated group ${chipId} center to (${newCenter.x}, ${newCenter.y})`)}}}debug62("Matchpack layout completed successfully")}function getSchematicSheetIdsBySourceGroupId({circuitJson,schematicSheetIdsBySourceComponentId}){let parentBySourceGroupId=new Map;for(let element of circuitJson)element.type==="source_group"&&parentBySourceGroupId.set(element.source_group_id,element.parent_source_group_id);let schematicSheetIdsBySourceGroupId=new Map;for(let element of circuitJson){if(element.type!=="source_component"||!element.source_group_id)continue;let schematicSheetIds=schematicSheetIdsBySourceComponentId.get(element.source_component_id);if(schematicSheetIds!==void 0)for(let schematicSheetId of schematicSheetIds){let sourceGroupId=element.source_group_id,visitedSourceGroupIds=new Set;for(;sourceGroupId&&!visitedSourceGroupIds.has(sourceGroupId);){visitedSourceGroupIds.add(sourceGroupId);let groupSchematicSheetIds=schematicSheetIdsBySourceGroupId.get(sourceGroupId)??new Set;groupSchematicSheetIds.add(schematicSheetId),schematicSheetIdsBySourceGroupId.set(sourceGroupId,groupSchematicSheetIds),sourceGroupId=parentBySourceGroupId.get(sourceGroupId)}}}return schematicSheetIdsBySourceGroupId}function getCircuitJsonScopedToSchematicSheet({circuitJson,schematicSheetId,rootSourceGroupId,schematicSheetIdsBySourceComponentId,schematicSheetIdsBySourceGroupId}){let isGroupOnSheet=sourceGroupId=>sourceGroupId===rootSourceGroupId||schematicSheetIdsBySourceGroupId.get(sourceGroupId)?.has(schematicSheetId)===!0;return circuitJson.filter(element=>element.type==="source_group"?isGroupOnSheet(element.source_group_id):element.type==="source_component"?schematicSheetIdsBySourceComponentId.get(element.source_component_id)?.has(schematicSheetId)!==!0?!1:element.source_group_id?isGroupOnSheet(element.source_group_id):!0:!0)}function getSchematicCircuitJsonTrees(circuitJson,opts){let{source_group_id}=opts,schematicSheetIdsBySourceComponentId=new Map;for(let element of circuitJson){if(element.type!=="schematic_component"||!element.source_component_id||!element.schematic_sheet_id)continue;let schematicSheetIds2=schematicSheetIdsBySourceComponentId.get(element.source_component_id)??new Set;schematicSheetIds2.add(element.schematic_sheet_id),schematicSheetIdsBySourceComponentId.set(element.source_component_id,schematicSheetIds2)}let schematicSheetIds=new Set;for(let componentSchematicSheetIds of schematicSheetIdsBySourceComponentId.values())for(let schematicSheetId of componentSchematicSheetIds)schematicSheetIds.add(schematicSheetId);if(schematicSheetIds.size<=1)return[{tree:getCircuitJsonTree(circuitJson,{source_group_id}),schematicSheetId:schematicSheetIds.values().next().value}];let schematicSheetIdsBySourceGroupId=getSchematicSheetIdsBySourceGroupId({circuitJson,schematicSheetIdsBySourceComponentId});return Array.from(schematicSheetIds).map(schematicSheetId=>({tree:getCircuitJsonTree(getCircuitJsonScopedToSchematicSheet({circuitJson,schematicSheetId,rootSourceGroupId:source_group_id,schematicSheetIdsBySourceComponentId,schematicSheetIdsBySourceGroupId}),{source_group_id}),schematicSheetId}))}function Group_doInitialSchematicLayoutMatchPack(group2){let{db:db22}=group2.root,trees=getSchematicCircuitJsonTrees(db22.toArray(),{source_group_id:group2.source_group_id});for(let{tree,schematicSheetId}of trees)applySchematicMatchPackLayoutToTree(group2,tree,{schematicSheetId})}var SECTION_GAP=1,MARGIN2=1.5;function computeSchematicSectionLayoutUsingRows({sectionBlocks,groupSchPositionBeforeLayout:groupOffset}){let totalArea=sectionBlocks.reduce((sum,block)=>{let paddedWidth=Math.max(block.size.x,.5)+MARGIN2*2,paddedHeight=Math.max(block.size.y,.5)+MARGIN2*2;return sum+paddedWidth*paddedHeight},0),targetRowWidth=Math.sqrt(totalArea)*2,computedSectionsMatrix=[],currentSectionRow=[],currentRowSectionWidth=0;for(let section of sectionBlocks){let paddedWidth=Math.max(section.size.x,.5)+MARGIN2*2,paddedHeight=Math.max(section.size.y,.5)+MARGIN2*2,neededWidth=currentRowSectionWidth>0?currentRowSectionWidth+SECTION_GAP+paddedWidth:paddedWidth;currentSectionRow.length>0&&neededWidth>targetRowWidth&&(computedSectionsMatrix.push(currentSectionRow),currentSectionRow=[],currentRowSectionWidth=0);let xOffsetInRow=currentRowSectionWidth>0?currentRowSectionWidth+SECTION_GAP:0;currentSectionRow.push({sectionName:section.sectionName,rowOffset:xOffsetInRow,width:paddedWidth,height:paddedHeight}),currentRowSectionWidth=xOffsetInRow+paddedWidth}currentSectionRow.length>0&&computedSectionsMatrix.push(currentSectionRow);let sectionPlacements=new Map,rowY=0;for(let sectionRow of computedSectionsMatrix){let rowHeight=Math.max(...sectionRow.map(rowEntry=>rowEntry.height)),rowCenteringOffsetX=-(sectionRow[sectionRow.length-1].rowOffset+sectionRow[sectionRow.length-1].width)/2;for(let section of sectionRow)sectionPlacements.set(section.sectionName,{x:rowCenteringOffsetX+section.rowOffset+section.width/2+groupOffset.x,y:rowY-rowHeight/2+groupOffset.y});rowY-=rowHeight+SECTION_GAP}return sectionPlacements}var debug7=(0,import_debug15.default)("Group_doInitialSchematicLayoutSections");function Group_doInitialSchematicLayoutSections(group2){let{db:db22}=group2.root,sectionNamesUsedByChildren=new Set,hasChildrenWithoutSection=!1;for(let child of group2.children){if(!child.source_component_id)continue;let sectionName=child.getSchematicSectionName();sectionName!==null?sectionNamesUsedByChildren.add(sectionName):hasChildrenWithoutSection=!0}let sectionNamesToLayout=Array.from(sectionNamesUsedByChildren);if(hasChildrenWithoutSection&&sectionNamesToLayout.push(null),sectionNamesToLayout.length===0)return;for(let sectionName of sectionNamesToLayout){let sectionTree=getCircuitJsonTree(db22.toArray(),{source_group_id:group2.source_group_id});sectionTree.childNodes=sectionTree.childNodes.filter(child=>child.nodeType!=="component"||!child.sourceComponent?!1:(group2.children.find(c22=>c22.source_component_id===child.sourceComponent?.source_component_id)?.getSchematicSectionName()??null)===sectionName),applySchematicMatchPackLayoutToTree(group2,sectionTree)}if(sectionNamesToLayout.length<=1)return;let sectionNameToBoundsWithChildren=new Map;for(let sectionName of sectionNamesToLayout){let minX=1/0,maxX=-1/0,minY=1/0,maxY=-1/0,sourceCompIds=new Set;for(let child of group2.children){let sourceComponentId=child.source_component_id;if(!sourceComponentId||child.getSchematicSectionName()!==sectionName)continue;let schComp=db22.schematic_component.getWhere({source_component_id:sourceComponentId});if(!schComp)continue;sourceCompIds.add(sourceComponentId);let hw22=schComp.size.width/2,hh22=schComp.size.height/2;minX=Math.min(minX,schComp.center.x-hw22),maxX=Math.max(maxX,schComp.center.x+hw22),minY=Math.min(minY,schComp.center.y-hh22),maxY=Math.max(maxY,schComp.center.y+hh22)}!Number.isFinite(minX)||sourceCompIds.size===0||sectionNameToBoundsWithChildren.set(sectionName,{sectionName,center:{x:(minX+maxX)/2,y:(minY+maxY)/2},size:{x:maxX-minX,y:maxY-minY},sourceCompIds})}if(sectionNameToBoundsWithChildren.size<=1)return;let anchoredSections=new Set;for(let child of group2.children){if(!child.source_component_id)continue;let props=child._parsedProps;(props?.schX!==void 0||props?.schY!==void 0)&&anchoredSections.add(child.getSchematicSectionName())}let groupSchPositionBeforeLayout=group2._getGlobalSchematicPositionBeforeLayout(),sectionPlacements=computeSchematicSectionLayoutUsingRows({sectionBlocks:Array.from(sectionNameToBoundsWithChildren.values()).map(bounds=>({sectionName:bounds.sectionName,size:bounds.size})),groupSchPositionBeforeLayout});for(let[sectionName,placement]of sectionPlacements){let boundsWithChildren=sectionNameToBoundsWithChildren.get(sectionName);if(!boundsWithChildren)continue;if(anchoredSections.has(sectionName)){debug7(`[${group2.name}] Section "${sectionName}" anchored by manual position, skipping shift`);continue}let delta={x:placement.x-boundsWithChildren.center.x,y:placement.y-boundsWithChildren.center.y};for(let sourceComponentId of boundsWithChildren.sourceCompIds){let schComp=db22.schematic_component.getWhere({source_component_id:sourceComponentId});if(!schComp)continue;let ports=db22.schematic_port.list({schematic_component_id:schComp.schematic_component_id}),texts=db22.schematic_text.list({schematic_component_id:schComp.schematic_component_id});for(let port of ports)port.center.x+=delta.x,port.center.y+=delta.y;for(let text of texts)text.position.x+=delta.x,text.position.y+=delta.y;updateSchematicPrimitivesForLayoutShift({db:db22,schematicComponentId:schComp.schematic_component_id,deltaX:delta.x,deltaY:delta.y}),schComp.center={x:schComp.center.x+delta.x,y:schComp.center.y+delta.y}}}}var updateMissingSchematicSheetWarning=({db:db22,schematicDisabled})=>{let existingWarning=db22.schematic_missing_sheet_warning.list()[0],hasSchematicComponents=db22.schematic_component.list().length>0;if(!(!schematicDisabled&&hasSchematicComponents&&db22.schematic_sheet.list().length===0)){existingWarning&&db22.schematic_missing_sheet_warning.delete(existingWarning.schematic_missing_sheet_warning_id);return}existingWarning||db22.schematic_missing_sheet_warning.insert({warning_type:"schematic_missing_sheet_warning",message:"No <schematicsheet> was found. Add a <schematicsheet> to define the schematic drawing area."})},Group_doInitialSchematicSheetRender=group2=>{let root=group2.root;if(!root?.isRootCircuit)return;let isRootGroup=root.firstChild===group2,isRootAssemblyChild=isAssemblyDeviceContainer(root.firstChild)&&group2.parent===root.firstChild;!isRootGroup&&!isRootAssemblyChild||updateMissingSchematicSheetWarning({db:root.db,schematicDisabled:root.schematicDisabled})},Group_updateSchematicSheetRender=group2=>{Group_doInitialSchematicSheetRender(group2)},NetLabel=class extends PrimitiveComponent2{constructor(){super(...arguments);__publicField(this,"source_net_label_id");__publicField(this,"schematic_net_label_id")}get config(){return{componentName:"NetLabel",zodProps:netLabelProps}}_getAnchorSide(){let{_parsedProps:props}=this;if(props.anchorSide)return props.anchorSide;if(!this._resolveConnectsTo())return"right";let net=this.getSubcircuit().selectOne(`net.${this._getNetName()}`),sourceNet;if(net?.source_net_id&&(sourceNet=this.root?.db.source_net.get(net.source_net_id)),sourceNet?.is_ground)return"top";if(sourceNet?.is_power)return"bottom";let anchorPos=this._getGlobalSchematicPositionBeforeLayout(),connectedPorts=this._getConnectedPorts();if(connectedPorts.length===0)return"right";let port=connectedPorts[0];if(port.facingDirection)return getEnteringEdgeFromDirection(port.facingDirection);let connectedPortPosition=port._getGlobalSchematicPositionBeforeLayout(),dx22=connectedPortPosition.x-anchorPos.x,dy22=connectedPortPosition.y-anchorPos.y;if(Math.abs(dx22)>Math.abs(dy22)){if(dx22>0)return"right";if(dx22<0)return"left"}else{if(dy22>0)return"top";if(dy22<0)return"bottom"}return"right"}_getConnectedPorts(){let connectsTo=this._resolveConnectsTo();if(!connectsTo)return[];let connectedPorts=[];for(let connection of connectsTo){let port=this.getSubcircuit().selectOne(connection);port&&connectedPorts.push(port)}return connectedPorts}computeSchematicPropsTransform(){let{_parsedProps:props}=this;if(props.schX===void 0&&props.schY===void 0){let connectedPorts=this._getConnectedPorts();if(connectedPorts.length>0){let portPos=connectedPorts[0]._getGlobalSchematicPositionBeforeLayout(),parentCenter=applyToPoint2(this.parent?.computeSchematicGlobalTransform?.()??identity(),{x:0,y:0});return translate2(portPos.x-parentCenter.x,portPos.y-parentCenter.y)}}return super.computeSchematicPropsTransform()}doInitialSchematicPrimitiveRender(){if(this.root?.schematicDisabled||this.getCollapsedSchematicBoxAncestor())return;let{db:db22}=this.root,{_parsedProps:props}=this;if(props.inline&&this.root?._featureMspSchematicTraceRouting&&this._getConnectedPorts().length>0)return;let anchorPos=this._getGlobalSchematicPositionBeforeLayout(),net=this.getSubcircuit().selectOne(`net.${this._getNetName()}`),anchorSide=this._getAnchorSide(),center2=computeSchematicNetLabelCenter({anchor_position:anchorPos,anchor_side:anchorSide,text:props.net}),netLabel=db22.schematic_net_label.insert({text:props.net,source_net_id:net.source_net_id,anchor_position:anchorPos,center:center2,anchor_side:anchorSide,schematic_sheet_id:this._resolveSchematicSheetId()});this.source_net_label_id=netLabel.source_net_id,this.schematic_net_label_id=netLabel.schematic_net_label_id}_resolveConnectsTo(){let{_parsedProps:props}=this,connectsTo=props.connectsTo??props.connection;if(Array.isArray(connectsTo))return connectsTo;if(typeof connectsTo=="string")return[connectsTo]}_getNetName(){let{_parsedProps:props}=this;return props.net}doInitialCreateNetsFromProps(){let{_parsedProps:props}=this;props.net&&createNetsFromProps(this,[`net.${props.net}`])}doInitialCreateTracesFromNetLabels(){let connectsTo=this._resolveConnectsTo();if(connectsTo)for(let connection of connectsTo)this.add(new Trace({from:connection,to:`net.${this._getNetName()}`}))}doInitialSchematicTraceRender(){if(!this.root?._featureMspSchematicTraceRouting||this.root?.schematicDisabled||this.getCollapsedSchematicBoxAncestor()||this._parsedProps.inline)return;let{schX,schY}=this._parsedProps;if(schX===void 0&&schY===void 0)return;let{db:db22}=this.root,connectsTo=this._resolveConnectsTo();if(!connectsTo||connectsTo.length===0)return;let anchorPos=this._getGlobalSchematicPositionBeforeLayout(),anchorSide=this._getAnchorSide(),anchorFacing={left:"x-",right:"x+",top:"y+",bottom:"y-"}[anchorSide],net=this.getSubcircuit().selectOne(`net.${this._getNetName()}`);for(let connection of connectsTo){let port=this.getSubcircuit().selectOne(connection,{type:"port"});if(!port||!port.schematic_port_id)continue;let existingTraceForThisConnection=!1;if(net?.source_net_id){let candidateSourceTrace=db22.source_trace.list().find(st22=>st22.connected_source_net_ids?.includes(net.source_net_id)&&st22.connected_source_port_ids?.includes(port.source_port_id??""));if(candidateSourceTrace&&(existingTraceForThisConnection=db22.schematic_trace.list().some(t48=>t48.source_trace_id===candidateSourceTrace.source_trace_id)),existingTraceForThisConnection)continue}let portPos=port._getGlobalSchematicPositionAfterLayout(),portFacing=convertFacingDirectionToElbowDirection(port.facingDirection??"right")??"x+",path=calculateElbow({x:portPos.x,y:portPos.y,facingDirection:portFacing},{x:anchorPos.x,y:anchorPos.y,facingDirection:anchorFacing});if(!Array.isArray(path)||path.length<2)continue;let edges=[];for(let i22=0;i22<path.length-1;i22++)edges.push({from:{x:path[i22].x,y:path[i22].y},to:{x:path[i22+1].x,y:path[i22+1].y}});let source_trace_id,subcircuit_connectivity_map_key;if(net?.source_net_id&&port.source_port_id){let st22=db22.source_trace.list().find(s22=>s22.connected_source_net_ids?.includes(net.source_net_id)&&s22.connected_source_port_ids?.includes(port.source_port_id));source_trace_id=st22?.source_trace_id,subcircuit_connectivity_map_key=st22?.subcircuit_connectivity_map_key||db22.source_net.get(net.source_net_id)?.subcircuit_connectivity_map_key}db22.schematic_trace.insert({source_trace_id,edges,junctions:[],subcircuit_connectivity_map_key,schematic_sheet_id:this._resolveSchematicSheetId()}),db22.schematic_port.update(port.schematic_port_id,{is_connected:!0})}}},getNetNameFromPorts=ports=>{let directlyConnectedTraces=[...new Set(ports.flatMap(port=>port._getDirectlyConnectedTraces()))],displayLabel=directlyConnectedTraces.find(trace=>trace._parsedProps.schDisplayLabel)?._parsedProps.schDisplayLabel??directlyConnectedTraces.find(trace=>trace._parsedProps.displayName)?._parsedProps.displayName??directlyConnectedTraces.find(trace=>trace._parsedProps.name)?._parsedProps.name;if(displayLabel)return{name:displayLabel,wasAssignedDisplayLabel:!0};let db22=ports.find(port=>port.root)?.root?.db,sourcePortIds=ports.map(port=>port.source_port_id).filter(sourcePortId=>!!sourcePortId);return{name:(db22?getNetNameFromSourcePorts(db22,sourcePortIds):ports.map(port=>port._getNetLabelText()).filter(name=>!!name).sort((a22,b22)=>a22.localeCompare(b22,void 0,{numeric:!0,sensitivity:"base"}))[0])??"",wasAssignedDisplayLabel:!1}},appendToMap=(map,key,value)=>{let values=map.get(key);values?values.push(value):map.set(key,[value])},createCanonicalSchematicNetLabelTextResolver=group2=>{let{db:db22}=group2.root,sourceNetByConnectionKey=new Map,portsByConnectionKey=new Map,sourcePortIdsByConnectionKey=new Map,resolvedTextByConnectionKey=new Map;for(let sourceNet of db22.source_net.list())sourceNet.subcircuit_connectivity_map_key&&sourceNetByConnectionKey.set(sourceNet.subcircuit_connectivity_map_key,sourceNet);for(let port of group2.selectAll("port")){let connectionKey=port._getSubcircuitConnectivityKey();connectionKey&&appendToMap(portsByConnectionKey,connectionKey,port)}for(let sourcePort of db22.source_port.list())sourcePort.subcircuit_connectivity_map_key&&appendToMap(sourcePortIdsByConnectionKey,sourcePort.subcircuit_connectivity_map_key,sourcePort.source_port_id);return({subcircuitConnectivityMapKey})=>{let cached=resolvedTextByConnectionKey.get(subcircuitConnectivityMapKey);if(cached)return cached;let resolvedSourceNet=sourceNetByConnectionKey.get(subcircuitConnectivityMapKey);if(resolvedSourceNet?.name){let result2={name:resolvedSourceNet.name,wasAssignedDisplayLabel:!0};return resolvedTextByConnectionKey.set(subcircuitConnectivityMapKey,result2),result2}let portLabel=getNetNameFromPorts(portsByConnectionKey.get(subcircuitConnectivityMapKey)??[]);if(portLabel.name)return resolvedTextByConnectionKey.set(subcircuitConnectivityMapKey,portLabel),portLabel;let result={name:getNetNameFromSourcePorts(db22,sourcePortIdsByConnectionKey.get(subcircuitConnectivityMapKey)??[])??"",wasAssignedDisplayLabel:!1};return resolvedTextByConnectionKey.set(subcircuitConnectivityMapKey,result),result}},asSchematicPortId=id3=>id3,asSourcePortId=id3=>id3,debug8=(0,import_debug17.default)("Group_doInitialSchematicTraceRender"),INLINE_NET_LABEL_COLOR="rgb(132, 0, 0)",VERTICAL_INLINE_NET_LABEL_ROTATION=-90;function applyInlineNetLabelPlacements(args){let{group:group2,solver,userNetIdToConnKey,sourceTraceIdByPinPairKey,crossScopeSourceTraceIdBySchematicPortIdAndNetId}=args,{db:db22}=group2.root,inlineNetLabelPlacements=solver.inlineNetLabelSolver?.getOutput().inlineNetLabelPlacements??[];if(inlineNetLabelPlacements.length===0)return;let resolveCanonicalNetLabelText=createCanonicalSchematicNetLabelTextResolver(group2),globalConnMap=solver.mspConnectionPairSolver.globalConnMap;for(let placement of inlineNetLabelPlacements){let schematicPortIds=placement.pinIds.map(asSchematicPortId),placementUserNetId=globalConnMap.getIdsConnectedToNet(placement.globalConnNetId).find(id3=>userNetIdToConnKey.has(id3)),crossScopeSourceTraceId=schematicPortIds.length===1?crossScopeSourceTraceIdBySchematicPortIdAndNetId.get(schematicPortIds[0])?.get(placement.netId??placement.globalConnNetId):void 0,connKey=(crossScopeSourceTraceId?db22.source_trace.get(crossScopeSourceTraceId)?.subcircuit_connectivity_map_key:void 0)??(placementUserNetId?userNetIdToConnKey.get(placementUserNetId):void 0),text=placement.netLabelText??(connKey?resolveCanonicalNetLabelText({subcircuitConnectivityMapKey:connKey}).name:placement.netId??placement.globalConnNetId);if(!text){debug8(`skipping inline net label for "${placement.netId}" REASON:no resolvable text`);continue}let sourceTraceId=crossScopeSourceTraceId??sourceTraceIdByPinPairKey.get([...schematicPortIds].sort().join("::"));if(!sourceTraceId&&connKey){let sourcePortIds=schematicPortIds.flatMap(schematicPortId=>{let sourcePortId=db22.schematic_port.get(schematicPortId)?.source_port_id;return sourcePortId?[sourcePortId]:[]});sourceTraceId=db22.source_trace.list().find(sourceTrace=>sourceTrace.subcircuit_connectivity_map_key===connKey&&sourcePortIds.some(sourcePortId=>sourceTrace.connected_source_port_ids.includes(sourcePortId)))?.source_trace_id}let schematicSheetId=group2._resolveSchematicSheetId(),schematicPort=db22.schematic_port.get(schematicPortIds[0]);schematicPort?.schematic_sheet_id&&(schematicSheetId=schematicPort.schematic_sheet_id);let placementOffset={x:0,y:0},stubTracePath=placement.stubTracePath?.map(point62=>({...point62}));if(stubTracePath&&schematicPortIds.length===1){let portCenter=db22.schematic_port.get(schematicPortIds[0])?.center;portCenter&&(placementOffset={x:portCenter.x-stubTracePath[0].x,y:portCenter.y-stubTracePath[0].y},stubTracePath=stubTracePath.map(point62=>({x:point62.x+placementOffset.x,y:point62.y+placementOffset.y})))}let shiftedAnchorPoint={x:placement.anchorPoint.x+placementOffset.x,y:placement.anchorPoint.y+placementOffset.y},position4={x:placement.center.x+placementOffset.x,y:placement.center.y+placementOffset.y},textAnchor="center",halfHeight=placement.height/2;switch(placement.side){case"y+":position4.y=shiftedAnchorPoint.y+halfHeight;break;case"y-":position4.y=shiftedAnchorPoint.y-halfHeight;break;case"x+":position4.x=shiftedAnchorPoint.x+halfHeight;break;case"x-":position4.x=shiftedAnchorPoint.x-halfHeight;break}if(stubTracePath&&stubTracePath.length===2){let[start,end]=stubTracePath;if(placement.axis==="x"){let extendsRight=end.x>start.x;textAnchor=extendsRight?"left":"right",position4.x+=extendsRight?-placement.width/2:placement.width/2}else{let extendsUp=end.y>start.y;textAnchor=extendsUp?"left":"right",position4.y+=extendsUp?-placement.width/2:placement.width/2}}stubTracePath&&stubTracePath.length===2&&(db22.schematic_trace.insert({source_trace_id:sourceTraceId,edges:[{from:stubTracePath[0],to:stubTracePath[1]}],junctions:[],subcircuit_connectivity_map_key:connKey,schematic_sheet_id:schematicSheetId}),db22.schematic_port.update(schematicPortIds[0],{is_connected:!0})),db22.schematic_text.insert({text,source_trace_id:sourceTraceId,anchor:textAnchor,position:position4,rotation:placement.axis==="y"?VERTICAL_INLINE_NET_LABEL_ROTATION:0,font_size:placement.height,color:INLINE_NET_LABEL_COLOR,schematic_sheet_id:schematicSheetId})}}var NET_LABEL_TEXT_HEIGHT=.18,getNetLabelTextBounds=({center:center2,text})=>{let halfWidth=getSchematicNetLabelTextWidth2({text})/2,halfHeight=NET_LABEL_TEXT_HEIGHT/2;return{minX:center2.x-halfWidth,maxX:center2.x+halfWidth,minY:center2.y-halfHeight,maxY:center2.y+halfHeight}},oppositeSide2=input2=>{switch(input2){case"x+":return"left";case"x-":return"right";case"y+":return"bottom";case"y-":return"top";case"left":return"right";case"top":return"bottom";case"right":return"left";case"bottom":return"top"}},debug9=(0,import_debug18.default)("Group_doInitialSchematicTraceRender"),isSameNet=(label,sourceNet)=>label.schematicNetLabel.source_net_id!=null&&label.schematicNetLabel.source_net_id===sourceNet.source_net_id,isUserDefinedNetLabelRedundantWithPlacement=(label,solverPlacement)=>isSameNet(label,solverPlacement.sourceNet)?label.schematicPortIds.some(id3=>solverPlacement.schematicPortIds.has(id3))?!0:label.schematicNetLabel.center?doBoundsOverlap(getNetLabelTextBounds({center:label.schematicNetLabel.center,text:label.schematicNetLabel.text}),solverPlacement.bounds):!1:!1;function applyNetLabelPlacements(args){let{group:group2,routedSchematicPortIdBySchematicPortId,solver,connKeyToSourceNet,userNetIdToConnKey,crossScopeSourceTraceIdBySchematicPortIdAndNetId,sourceTraceIdByPortOnlyLabelSchematicPortId,connKeysWithExplicitPortNetTraces,schematicPortIdsWithPreExistingNetLabels,schematicPortIdsWithRoutedTraces,netLabels}=args,{db:db22}=group2.root,resolveCanonicalNetLabelText=createCanonicalSchematicNetLabelTextResolver(group2),netLabelPlacements=solver.inlineNetLabelSolver?.getOutput().netLabelPlacements??solver.netLabelNetLabelCollisionSolver?.getOutput().netLabelPlacements??solver.netLabelTraceCollisionSolver?.getOutput().netLabelPlacements??solver.netLabelPlacementSolver?.netLabelPlacements??solver.traceLabelOverlapAvoidanceSolver?.getOutput().netLabelPlacements??[],dedupedNetLabelPlacements=[],netLabelPlacementKeys=new Set;for(let placement of netLabelPlacements){let pinIds=[...placement.pinIds??[]].sort(),key=`${placement.globalConnNetId}|${pinIds.join("::")}|${placement.netId??""}`;if(netLabelPlacementKeys.has(key)){debug9(`skipping duplicate placement for "${placement.netId}" REASON:identical net label placement`);continue}netLabelPlacementKeys.add(key),dedupedNetLabelPlacements.push(placement)}let netLabelPlacementCountByGlobalNetId=new Map,routedPairKeysByGlobalNetId=new Map,globalNetIdsWithPortOnlyPlacements=new Set;for(let placement of dedupedNetLabelPlacements)netLabelPlacementCountByGlobalNetId.set(placement.globalConnNetId,(netLabelPlacementCountByGlobalNetId.get(placement.globalConnNetId)??0)+1),(placement.pinIds?.length??0)>1&&(routedPairKeysByGlobalNetId.has(placement.globalConnNetId)||routedPairKeysByGlobalNetId.set(placement.globalConnNetId,new Set),routedPairKeysByGlobalNetId.get(placement.globalConnNetId).add(placement.pinIds.slice().sort().join("::"))),(placement.pinIds?.length??0)<=1&&globalNetIdsWithPortOnlyPlacements.add(placement.globalConnNetId);let globalConnMap=solver.mspConnectionPairSolver.globalConnMap,userDefinedNetLabels=netLabels.map(label=>{if(!label.schematic_net_label_id)return null;let dbLabel=db22.schematic_net_label.get(label.schematic_net_label_id);return dbLabel?{schematicNetLabel:dbLabel,schematicPortIds:label._getConnectedPorts().map(port=>port.schematic_port_id).filter(id3=>!!id3).map(id3=>routedSchematicPortIdBySchematicPortId.get(id3)??id3),shouldUseSchematicTraceSolver:label._parsedProps.schX===void 0&&label._parsedProps.schY===void 0}:null}).filter(label=>label!==null);for(let placement of dedupedNetLabelPlacements){debug9(`processing placement: ${placement.netId}`);let schPortIds=placement.pinIds.map(asSchematicPortId),placementSourceTraceId=(schPortIds.length===1?crossScopeSourceTraceIdBySchematicPortIdAndNetId.get(schPortIds[0])?.get(placement.netId??placement.globalConnNetId):void 0)??(schPortIds.length===1?sourceTraceIdByPortOnlyLabelSchematicPortId.get(schPortIds[0]):void 0),placementSourceTrace=placementSourceTraceId?db22.source_trace.get(placementSourceTraceId):void 0,placementUserNetId=globalConnMap.getIdsConnectedToNet(placement.globalConnNetId).find(id3=>userNetIdToConnKey.get(id3)),placementConnKey=placementSourceTrace?.subcircuit_connectivity_map_key??userNetIdToConnKey.get(placementUserNetId),orientation22=placement.orientation,anchor_side=oppositeSide2(orientation22),sourceNet;placementConnKey&&(sourceNet=connKeyToSourceNet.get(placementConnKey));let resolvedCanonicalNetLabel=placementConnKey?resolveCanonicalNetLabelText({subcircuitConnectivityMapKey:placementConnKey}):{name:placement.netId??placement.globalConnNetId,wasAssignedDisplayLabel:!1},canonicalNetLabel=placement.netLabelText?{name:placement.netLabelText,wasAssignedDisplayLabel:!0}:resolvedCanonicalNetLabel,schematicSheetId=group2._resolveSchematicSheetId(),schematicPort=db22.schematic_port.get(schPortIds[0]);schematicPort?.schematic_sheet_id&&(schematicSheetId=schematicPort.schematic_sheet_id);let anchor_position=placement.anchorPoint;if(schPortIds.length===1&&schPortIds[0]){let anchorSchPort=db22.schematic_port.get(schPortIds[0]);anchorSchPort?.center&&!anchorSchPort.is_connected&&(anchor_position=anchorSchPort.center)}if(schPortIds.some(schPortId=>schematicPortIdsWithPreExistingNetLabels.has(schPortId))){debug9(`skipping net label placement for "${placement.netId}" REASON:schematic port has pre-existing net label`);continue}if(sourceNet){let isPowerOrGroundNet=sourceNet.is_ground||sourceNet.is_power,hasExplicitPortNetTrace=connKeysWithExplicitPortNetTraces.has(placementConnKey),hasRoutedTraceForPlacementPort=schPortIds.some(id3=>schematicPortIdsWithRoutedTraces.has(id3)),hasSingleLabelPlacement=(netLabelPlacementCountByGlobalNetId.get(placement.globalConnNetId)??0)<=1;if(!hasExplicitPortNetTrace&&!isPowerOrGroundNet&&hasRoutedTraceForPlacementPort&&hasSingleLabelPlacement){debug9(`skipping net label placement for "${placement.netId}" REASON:schematic port has routed trace`);continue}let text2=canonicalNetLabel.name,center22=computeSchematicNetLabelCenter({anchor_position,anchor_side,text:text2}),solverManagedUserNetLabel=userDefinedNetLabels.find(label=>label.shouldUseSchematicTraceSolver&&isSameNet(label,sourceNet)&&label.schematicPortIds.some(id3=>schPortIds.includes(id3)));if(solverManagedUserNetLabel){db22.schematic_net_label.update(solverManagedUserNetLabel.schematicNetLabel.schematic_net_label_id,{anchor_position,center:center22,anchor_side,schematic_sheet_id:schematicSheetId,source_trace_id:placementSourceTraceId});continue}if(!isPowerOrGroundNet){let solverPlacement={sourceNet,text:text2,schematicPortIds:new Set(schPortIds),bounds:getNetLabelTextBounds({center:center22,text:text2})};if(userDefinedNetLabels.some(label=>isUserDefinedNetLabelRedundantWithPlacement(label,solverPlacement)))continue}let netLabel2={text:text2,source_net_id:sourceNet.source_net_id,anchor_position,center:center22,anchor_side,schematic_sheet_id:schematicSheetId,source_trace_id:placementSourceTraceId};db22.schematic_net_label.insert(netLabel2);continue}let{name:text,wasAssignedDisplayLabel}=canonicalNetLabel,shouldKeepRoutedPairLabel=(placement.pinIds?.length??0)>1&&(globalNetIdsWithPortOnlyPlacements.has(placement.globalConnNetId)||(routedPairKeysByGlobalNetId.get(placement.globalConnNetId)?.size??0)>1);if(!wasAssignedDisplayLabel&&!shouldKeepRoutedPairLabel&&schPortIds.some(schPortId=>schematicPortIdsWithRoutedTraces.has(schPortId))){debug9(`skipping net label placement for "${placement.netId}" REASON:schematic port has routed traces and no display label`);continue}let center2=computeSchematicNetLabelCenter({anchor_position,anchor_side,text}),netLabel={text,source_net_id:placementConnKey??placement.netId??placement.globalConnNetId,anchor_position,center:center2,anchor_side,schematic_sheet_id:schematicSheetId,source_trace_id:placementSourceTraceId};db22.schematic_net_label.insert(netLabel)}}var cross42=(ax22,ay22,bx22,by22)=>ax22*by22-ay22*bx22;function segmentIntersection(p12,p22,q12,q22,tol){let r22={x:p22.x-p12.x,y:p22.y-p12.y},s22={x:q22.x-q12.x,y:q22.y-q12.y},rxs=cross42(r22.x,r22.y,s22.x,s22.y),q_p={x:q12.x-p12.x,y:q12.y-p12.y},q_pxr=cross42(q_p.x,q_p.y,r22.x,r22.y);if(Math.abs(rxs)<tol&&Math.abs(q_pxr)<tol||Math.abs(rxs)<tol&&Math.abs(q_pxr)>=tol)return null;let t48=cross42(q_p.x,q_p.y,s22.x,s22.y)/rxs,u22=cross42(q_p.x,q_p.y,r22.x,r22.y)/rxs;return t48<-tol||t48>1+tol||u22<-tol||u22>1+tol?null:{x:p12.x+t48*r22.x,y:p12.y+t48*r22.y}}var TOL4=1e-6;function isHorizontalEdge(edge){let dx22=Math.abs(edge.to.x-edge.from.x),dy22=Math.abs(edge.to.y-edge.from.y);return dx22>=dy22}function length73(a22,b22){return Math.hypot(b22.x-a22.x,b22.y-a22.y)}function pointAt(a22,b22,t48){return{x:a22.x+(b22.x-a22.x)*t48,y:a22.y+(b22.y-a22.y)*t48}}function paramAlong(a22,b22,p22){let L22=length73(a22,b22);if(L22<TOL4)return 0;let t48=((p22.x-a22.x)*(b22.x-a22.x)+(p22.y-a22.y)*(b22.y-a22.y))/((b22.x-a22.x)*(b22.x-a22.x)+(b22.y-a22.y)*(b22.y-a22.y));return Math.max(0,Math.min(1,t48))*L22}function mergeIntervals(intervals,tol=TOL4){if(intervals.length===0)return intervals;intervals.sort((a22,b22)=>a22.start-b22.start);let merged=[],cur={...intervals[0]};for(let i22=1;i22<intervals.length;i22++){let nxt=intervals[i22];nxt.start<=cur.end+tol?cur.end=Math.max(cur.end,nxt.end):(merged.push(cur),cur={...nxt})}return merged.push(cur),merged}function splitEdgeByCrossings(edge,crossingDistances,crossLen){let L22=length73(edge.from,edge.to);if(L22<TOL4||crossingDistances.length===0)return[edge];let half=crossLen/2,rawIntervals=crossingDistances.map(d23=>({start:Math.max(0,d23-half),end:Math.min(L22,d23+half)})).filter(iv22=>iv22.end-iv22.start>TOL4),intervals=mergeIntervals(rawIntervals),result=[],cursor=0,dir2={x:edge.to.x-edge.from.x,y:edge.to.y-edge.from.y},addSeg=(d03,d12,isCrossing)=>{if(d12-d03<=TOL4)return;let t03=d03/L22,t110=d12/L22;result.push({from:pointAt(edge.from,edge.to,t03),to:pointAt(edge.from,edge.to,t110),...isCrossing?{is_crossing:!0}:{}})};for(let iv22 of intervals)iv22.start-cursor>TOL4&&addSeg(cursor,iv22.start,!1),addSeg(iv22.start,iv22.end,!0),cursor=iv22.end;return L22-cursor>TOL4&&addSeg(cursor,L22,!1),result.length>0?result:[edge]}function computeCrossings(traces,opts={}){let crossLen=opts.crossSegmentLength??.075,tol=opts.tolerance??TOL4,crossingsByEdge=new Map,keyOf=ref=>`${ref.traceIdx}:${ref.edgeIdx}`,getEdge=ref=>traces[ref.traceIdx].edges[ref.edgeIdx];for(let ti3=0;ti3<traces.length;ti3++){let A22=traces[ti3];for(let ei3=0;ei3<A22.edges.length;ei3++){let eA22=A22.edges[ei3];for(let tj2=ti3;tj2<traces.length;tj2++){let B22=traces[tj2];for(let ej2=tj2===ti3?ei3+1:0;ej2<B22.edges.length;ej2++){let eB2=B22.edges[ej2];if(A22.connectivity_key!==void 0&&A22.connectivity_key===B22.connectivity_key)continue;let P22=segmentIntersection(eA22.from,eA22.to,eB2.from,eB2.to,tol);if(!P22)continue;let LA22=length73(eA22.from,eA22.to),LB2=length73(eB2.from,eB2.to);if(LA22<tol||LB2<tol)continue;let dA22=paramAlong(eA22.from,eA22.to,P22),dB3=paramAlong(eB2.from,eB2.to,P22),nearEndpointA=dA22<=tol||Math.abs(LA22-dA22)<=tol||Number.isNaN(dA22),nearEndpointB=dB3<=tol||Math.abs(LB2-dB3)<=tol||Number.isNaN(dB3);if(!nearEndpointA&&!nearEndpointB){let aIsHorizontal=isHorizontalEdge(eA22),bIsHorizontal=isHorizontalEdge(eB2),assignToA;if(aIsHorizontal!==bIsHorizontal)assignToA=aIsHorizontal;else{let ax22=Math.abs(eA22.to.x-eA22.from.x),ay22=Math.abs(eA22.to.y-eA22.from.y),bx22=Math.abs(eB2.to.x-eB2.from.x),by22=Math.abs(eB2.to.y-eB2.from.y),aScore=ax22-ay22,bScore=bx22-by22;assignToA=aScore===bScore?!0:aScore>bScore}let chosenKey=keyOf({traceIdx:assignToA?ti3:tj2,edgeIdx:assignToA?ei3:ej2}),chosenList=crossingsByEdge.get(chosenKey)??[];chosenList.push(assignToA?dA22:dB3),crossingsByEdge.set(chosenKey,chosenList)}}}}}let out=traces.map(t48=>({source_trace_id:t48.source_trace_id,connectivity_key:t48.connectivity_key,edges:[]}));for(let ti3=0;ti3<traces.length;ti3++){let trace=traces[ti3];for(let ei3=0;ei3<trace.edges.length;ei3++){let eRefKey=keyOf({traceIdx:ti3,edgeIdx:ei3}),splittingDistances=crossingsByEdge.get(eRefKey)??[];if(splittingDistances.length===0){out[ti3].edges.push(trace.edges[ei3]);continue}let uniqueSorted3=Array.from(new Set(splittingDistances.map(d23=>Number(d23.toFixed(6))))).sort((a22,b22)=>a22-b22),split=splitEdgeByCrossings(trace.edges[ei3],uniqueSorted3,crossLen);out[ti3].edges.push(...split)}}return out}var TOL22=1e-6;function nearlyEqual2(a22,b22,tol=TOL22){return Math.abs(a22-b22)<=tol}function pointEq(a22,b22,tol=TOL22){return nearlyEqual2(a22.x,b22.x,tol)&&nearlyEqual2(a22.y,b22.y,tol)}function onSegment32(p22,a22,b22,tol=TOL22){let minX=Math.min(a22.x,b22.x)-tol,maxX=Math.max(a22.x,b22.x)+tol,minY=Math.min(a22.y,b22.y)-tol,maxY=Math.max(a22.y,b22.y)+tol;return p22.x<minX||p22.x>maxX||p22.y<minY||p22.y>maxY?!1:Math.abs((b22.x-a22.x)*(p22.y-a22.y)-(b22.y-a22.y)*(p22.x-a22.x))<=tol}function dedupePoints(points,tol=TOL22){let map=new Map;for(let p22 of points){let key=`${p22.x.toFixed(6)},${p22.y.toFixed(6)}`;map.has(key)||map.set(key,p22)}return Array.from(map.values())}function edgeVec(e210){return{x:e210.to.x-e210.from.x,y:e210.to.y-e210.from.y}}function isEndpointOfEdge(p22,e210,tol=TOL22){return pointEq(p22,e210.from,tol)||pointEq(p22,e210.to,tol)}function isParallel(e110,e210,tol=TOL22){let v12=edgeVec(e110),v22=edgeVec(e210),L12=Math.hypot(v12.x,v12.y),L22=Math.hypot(v22.x,v22.y);if(L12<tol||L22<tol)return!0;let cross52=v12.x*v22.y-v12.y*v22.x;return Math.abs(cross52)<=tol*L12*L22}function incidentEdgesAtPoint(trace,p22,tol=TOL22){return trace.edges.filter(e210=>pointEq(e210.from,p22,tol)||pointEq(e210.to,p22,tol))}function nearestEndpointOnTrace(trace,p22,tol=TOL22){for(let e210 of trace.edges){if(pointEq(e210.from,p22,tol))return e210.from;if(pointEq(e210.to,p22,tol))return e210.to}return null}function edgeDirectionFromPoint(e210,p22,tol=TOL22){let other=pointEq(e210.from,p22,tol)||nearlyEqual2(e210.from.x,p22.x,tol)&&nearlyEqual2(e210.from.y,p22.y,tol)?e210.to:e210.from,dx22=other.x-p22.x,dy22=other.y-p22.y;return Math.abs(dx22)<tol&&Math.abs(dy22)<tol?null:Math.abs(dx22)>=Math.abs(dy22)?dx22>=0?"right":"left":dy22>=0?"up":"down"}function getCornerOrientationAtPoint(trace,p22,tol=TOL22){let incident=incidentEdgesAtPoint(trace,p22,tol);if(incident.length<2)return null;let dirs=incident.map(e210=>edgeDirectionFromPoint(e210,p22,tol)),hasUp=dirs.includes("up"),hasDown=dirs.includes("down"),hasLeft=dirs.includes("left"),hasRight=dirs.includes("right"),vertical=hasUp?"up":hasDown?"down":null,horizontal=hasRight?"right":hasLeft?"left":null;return vertical&&horizontal?`${vertical}-${horizontal}`:null}function computeJunctions(traces,opts={}){let tol=opts.tolerance??TOL22,result={};for(let t48 of traces)result[t48.source_trace_id]=[];let endpointsByTrace=traces.map(t48=>{let pts=[];for(let e210 of t48.edges)pts.push(e210.from,e210.to);return dedupePoints(pts,tol)});for(let i22=0;i22<traces.length;i22++){let A22=traces[i22],AEnds=endpointsByTrace[i22];for(let j22=i22+1;j22<traces.length;j22++){let B22=traces[j22],BEnds=endpointsByTrace[j22];if(A22.connectivity_key!==void 0&&A22.connectivity_key===B22.connectivity_key){for(let eA22 of A22.edges)for(let eB2 of B22.edges){let p22=segmentIntersection(eA22.from,eA22.to,eB2.from,eB2.to,tol);p22&&(isEndpointOfEdge(p22,eA22,tol)||isEndpointOfEdge(p22,eB2,tol)||(result[A22.source_trace_id].push(p22),A22.source_trace_id!==B22.source_trace_id&&result[B22.source_trace_id].push(p22)))}for(let pa3 of AEnds)for(let pb22 of BEnds)if(pointEq(pa3,pb22,tol)){let aEdgesAtP=incidentEdgesAtPoint(A22,pa3,tol),bEdgesAtP=incidentEdgesAtPoint(B22,pb22,tol),hasCorner=aEdgesAtP.some(eA22=>bEdgesAtP.some(eB2=>!isParallel(eA22,eB2,tol))),aCorner=getCornerOrientationAtPoint(A22,pa3,tol),bCorner=getCornerOrientationAtPoint(B22,pb22,tol);hasCorner&&!(aCorner!==null&&bCorner!==null&&aCorner===bCorner)&&(result[A22.source_trace_id].push(pa3),A22.source_trace_id!==B22.source_trace_id&&result[B22.source_trace_id].push(pb22))}for(let pa3 of AEnds)for(let eB2 of B22.edges)if(onSegment32(pa3,eB2.from,eB2.to,tol)){let hasCorner=incidentEdgesAtPoint(A22,pa3,tol).some(eA22=>!isParallel(eA22,eB2,tol)),aCorner=getCornerOrientationAtPoint(A22,pa3,tol),bEndpointNearPa=nearestEndpointOnTrace(B22,pa3,tol*1e3),bCorner=bEndpointNearPa?getCornerOrientationAtPoint(B22,bEndpointNearPa,tol):null;hasCorner&&!(aCorner!==null&&bCorner!==null&&aCorner===bCorner)&&(result[A22.source_trace_id].push(pa3),A22.source_trace_id!==B22.source_trace_id&&result[B22.source_trace_id].push(pa3))}for(let pb22 of BEnds)for(let eA22 of A22.edges)if(onSegment32(pb22,eA22.from,eA22.to,tol)){let hasCorner=incidentEdgesAtPoint(B22,pb22,tol).some(eB2=>!isParallel(eA22,eB2,tol)),bCorner=getCornerOrientationAtPoint(B22,pb22,tol),aEndpointNearPb=nearestEndpointOnTrace(A22,pb22,tol*1e3),aCorner=aEndpointNearPb?getCornerOrientationAtPoint(A22,aEndpointNearPb,tol):null;hasCorner&&!(aCorner!==null&&bCorner!==null&&aCorner===bCorner)&&(result[B22.source_trace_id].push(pb22),A22.source_trace_id!==B22.source_trace_id&&result[A22.source_trace_id].push(pb22))}}}}for(let id3 of Object.keys(result))result[id3]=dedupePoints(result[id3],tol);return result}var TOL32=1e-6;function isCollinear(a22,b22,tol=TOL32){let adx=a22.to.x-a22.from.x,ady=a22.to.y-a22.from.y,bdx=b22.to.x-b22.from.x,bdy=b22.to.y-b22.from.y,aLen=Math.hypot(adx,ady),bLen=Math.hypot(bdx,bdy);if(aLen<=tol||bLen<=tol)return!1;let directionCross=adx*bdy-ady*bdx;if(Math.abs(directionCross)>tol*aLen*bLen)return!1;let offsetCross=adx*(b22.from.y-a22.from.y)-ady*(b22.from.x-a22.from.x);return Math.abs(offsetCross)<=tol*aLen}function splitEdgeAroundIntervals(edge,intervals){let merged=mergeIntervals(intervals);if(merged.length===0)return[edge];let edgeLength=length73(edge.from,edge.to);if(edgeLength<=TOL32)return[edge];let result=[],cursor=0;for(let interval of merged)interval.start-cursor>TOL32&&result.push({from:pointAt(edge.from,edge.to,cursor/edgeLength),to:pointAt(edge.from,edge.to,interval.start/edgeLength)}),interval.end-interval.start>TOL32&&result.push({from:pointAt(edge.from,edge.to,interval.start/edgeLength),to:pointAt(edge.from,edge.to,interval.end/edgeLength),is_crossing:!0}),cursor=Math.max(cursor,interval.end);return edgeLength-cursor>TOL32&&result.push({from:pointAt(edge.from,edge.to,cursor/edgeLength),to:edge.to}),result}function removeOverlappingSameNetCrossingSegments(traces){let intervalsToRemove=new Map;for(let crossingTraceIndex=0;crossingTraceIndex<traces.length;crossingTraceIndex++){let crossingTrace=traces[crossingTraceIndex];if(crossingTrace.connectivity_key){for(let crossingEdge of crossingTrace.edges)if(!(!crossingEdge.is_crossing||length73(crossingEdge.from,crossingEdge.to)<=TOL32))for(let traceIndex=0;traceIndex<traces.length;traceIndex++){let candidateTrace=traces[traceIndex];if(!(traceIndex===crossingTraceIndex||candidateTrace.connectivity_key!==crossingTrace.connectivity_key))for(let edgeIndex=0;edgeIndex<candidateTrace.edges.length;edgeIndex++){let candidateEdge=candidateTrace.edges[edgeIndex],candidateLength=length73(candidateEdge.from,candidateEdge.to);if(candidateEdge.is_crossing||candidateLength<=TOL32||!isCollinear(candidateEdge,crossingEdge))continue;let start=Math.max(0,Math.min(paramAlong(candidateEdge.from,candidateEdge.to,crossingEdge.from),paramAlong(candidateEdge.from,candidateEdge.to,crossingEdge.to))),end=Math.min(candidateLength,Math.max(paramAlong(candidateEdge.from,candidateEdge.to,crossingEdge.from),paramAlong(candidateEdge.from,candidateEdge.to,crossingEdge.to)));if(end-start<=TOL32)continue;let key=`${traceIndex}:${edgeIndex}`,intervals=intervalsToRemove.get(key)??[];intervals.push({start,end}),intervalsToRemove.set(key,intervals)}}}}return intervalsToRemove.size===0?traces:traces.map((trace,traceIndex)=>({...trace,edges:trace.edges.flatMap((edge,edgeIndex)=>{let intervals=intervalsToRemove.get(`${traceIndex}:${edgeIndex}`);return intervals?splitEdgeAroundIntervals(edge,intervals):[edge]})}))}var debug10=(0,import_debug19.default)("Group_doInitialSchematicTraceRender"),MAX_PIN_SNAP_GAP=1.5;function extendTraceEndpointsToReachPinsInsideExpandedBoundingBox(params,db22){let{points,schematicPortIds,componentBoundsByPortId}=params,centers=schematicPortIds.map(id3=>{let center2=db22.schematic_port.get(id3)?.center,bounds=componentBoundsByPortId.get(id3);return!center2||!bounds?null:{center:center2,bounds}}).filter(port=>!!port);if(centers.length===0)return points;let result=points.map(p22=>({x:p22.x,y:p22.y})),d23=(a22,b22)=>(a22.x-b22.x)**2+(a22.y-b22.y)**2,usedCenters=new Set;for(let i22=0;i22<centers.length;i22++)result.some(p22=>d23(centers[i22].center,p22)<=1e-12)&&usedCenters.add(i22);let ALIGN_EPS=.001,endpoints=["start","end"],candidates=[];for(let endpoint of endpoints){let endpointPoint=endpoint==="start"?result[0]:result[result.length-1];for(let i22=0;i22<centers.length;i22++){if(usedCenters.has(i22))continue;let{center:center2,bounds}=centers[i22],dist4=d23(center2,endpointPoint);Math.abs(center2.x-endpointPoint.x)>ALIGN_EPS&&Math.abs(center2.y-endpointPoint.y)>ALIGN_EPS||dist4>MAX_PIN_SNAP_GAP**2&&pointToBoundsDistance(endpointPoint,bounds)>ALIGN_EPS||candidates.push({endpoint,centerIndex:i22,dist:dist4})}}candidates.sort((a22,b22)=>a22.dist-b22.dist);let usedEndpoints=new Set;for(let{endpoint,centerIndex,dist:dist4}of candidates){if(usedEndpoints.has(endpoint)||usedCenters.has(centerIndex)||(usedCenters.add(centerIndex),usedEndpoints.add(endpoint),dist4<=1e-12))continue;let center2=centers[centerIndex].center;endpoint==="start"?result.unshift({x:center2.x,y:center2.y}):result.push({x:center2.x,y:center2.y})}return result}function applyTracesFromSolverOutput(args){let{group:group2,solver,userNetIdToConnKey,schematicPortIdsWithPreExistingNetLabels}=args,{db:db22}=group2.root,customSymbolPortIds=new Set(group2.selectAll("port").filter(port=>{if(!port._getSymbolAncestor())return!1;let symbol=port.getParentNormalComponent()?._parsedProps.symbol;return(0,import_react9.isValidElement)(symbol)||isCircuitJsonSymbol(symbol)}).map(port=>port.schematic_port_id).filter(schematicPortId=>schematicPortId!=null).map(asSchematicPortId)),componentBoundsByPortId=new Map;for(let schematicComponent of db22.schematic_component.list()){let textInclusiveBounds=getSchematicComponentWithTextBounds({db:db22,schematicComponent}),componentBounds=getBoundFromCenteredRect({center:schematicComponent.center,width:schematicComponent.size.width,height:schematicComponent.size.height});for(let port of db22.schematic_port.list({schematic_component_id:schematicComponent.schematic_component_id})){let isInsideComponentBounds=port.center.x>componentBounds.minX&&port.center.x<componentBounds.maxX&&port.center.y>componentBounds.minY&&port.center.y<componentBounds.maxY,schematicPortId=asSchematicPortId(port.schematic_port_id);!textInclusiveBounds&&!customSymbolPortIds.has(schematicPortId)||!textInclusiveBounds&&isInsideComponentBounds||componentBoundsByPortId.set(schematicPortId,textInclusiveBounds??componentBounds)}}let traces=solver.inlineNetLabelSolver?.getOutput().traces??solver.sameNetJunctionAlignmentSolver?.getOutput().traces??solver.netLabelTraceCollisionSolver?.getOutput().traces??solver.traceCleanupSolver?.getOutput().traces??solver.traceLabelOverlapAvoidanceSolver?.getOutput().traces??solver.schematicTraceLinesSolver?.solvedTracePaths,pendingTraces=[];debug10(`Traces inside SchematicTraceSolver output: ${(traces??[]).length}`);for(let solvedTracePath of traces??[]){let solvedTraceSchematicPortIds=Array.from(new Set(solvedTracePath.pinIds??[])).map(asSchematicPortId);if(solvedTraceSchematicPortIds.length>0&&solvedTraceSchematicPortIds.every(id3=>schematicPortIdsWithPreExistingNetLabels.has(id3))){debug10(`Skipping solver netlabel-covered trace ${solvedTracePath?.mspPairId} because all schematic ports already have netlabels`);continue}let points=solvedTracePath?.tracePath;if(!Array.isArray(points)||points.length<2){debug10(`Skipping trace ${solvedTracePath?.pinIds.join(",")} because it has less than 2 points`);continue}let snappedPoints=extendTraceEndpointsToReachPinsInsideExpandedBoundingBox({points,schematicPortIds:solvedTraceSchematicPortIds,componentBoundsByPortId},db22),edges=[];for(let i22=0;i22<snappedPoints.length-1;i22++)edges.push({from:{x:snappedPoints[i22].x,y:snappedPoints[i22].y},to:{x:snappedPoints[i22+1].x,y:snappedPoints[i22+1].y}});let source_trace_id=String(solvedTracePath?.mspPairId),subcircuit_connectivity_map_key;if(Array.isArray(solvedTracePath?.pins)&&solvedTracePath.pins.length===2){let firstPinId=solvedTracePath.pins[0]?.pinId,secondPinId=solvedTracePath.pins[1]?.pinId,pA22=firstPinId?asSchematicPortId(firstPinId):void 0,pB2=secondPinId?asSchematicPortId(secondPinId):void 0;if(pA22&&pB2){let routedSchematicPortIds=new Set([pA22,pB2]);for(let routedSchematicPortId of routedSchematicPortIds)db22.schematic_port.update(routedSchematicPortId,{is_connected:!0});subcircuit_connectivity_map_key=userNetIdToConnKey.get(String(solvedTracePath.userNetId))}}if(subcircuit_connectivity_map_key||(subcircuit_connectivity_map_key=userNetIdToConnKey.get(String(solvedTracePath.userNetId))),!subcircuit_connectivity_map_key){let sourcePortConnKeys=solvedTraceSchematicPortIds.map(schematicPortId=>{let sourcePortId=db22.schematic_port.get(schematicPortId)?.source_port_id;if(sourcePortId)return db22.source_port.get(sourcePortId)?.subcircuit_connectivity_map_key}).filter(key=>!!key);new Set(sourcePortConnKeys).size===1&&(subcircuit_connectivity_map_key=sourcePortConnKeys[0])}let endpointSchematicSheetIds=new Set(solvedTraceSchematicPortIds.map(schematicPortId=>db22.schematic_port.get(schematicPortId)?.schematic_sheet_id).filter(sheetId=>!!sheetId)),schematicSheetId2;endpointSchematicSheetIds.size===1?schematicSheetId2=endpointSchematicSheetIds.values().next().value:endpointSchematicSheetIds.size===0&&(schematicSheetId2=group2._resolveSchematicSheetId()),pendingTraces.push({source_trace_id,edges,subcircuit_connectivity_map_key,schematic_sheet_id:schematicSheetId2})}debug10(`Applying ${pendingTraces.length} traces from SchematicTraceSolver output`);let withCrossings=computeCrossings(pendingTraces.map(t48=>({source_trace_id:t48.source_trace_id,edges:t48.edges,connectivity_key:t48.subcircuit_connectivity_map_key}))),existingTracesForJunctions=[],schematicSheetId=group2._resolveSchematicSheetId();for(let t48 of db22.schematic_trace.list()){if(t48.edges.length===0||t48.schematic_sheet_id!==schematicSheetId)continue;let sourceTrace=t48.source_trace_id?db22.source_trace.get(t48.source_trace_id):void 0;existingTracesForJunctions.push({schematic_trace_id:t48.schematic_trace_id,source_trace_id:t48.source_trace_id??t48.schematic_trace_id,edges:t48.edges,connectivity_key:t48.subcircuit_connectivity_map_key??sourceTrace?.subcircuit_connectivity_map_key})}let tracesWithTrimmedCrossingOverlaps=removeOverlappingSameNetCrossingSegments([...withCrossings,...existingTracesForJunctions]),visibleTraces=tracesWithTrimmedCrossingOverlaps.slice(0,withCrossings.length),visibleExistingTraces=tracesWithTrimmedCrossingOverlaps.slice(withCrossings.length);for(let trace of visibleExistingTraces)trace.schematic_trace_id&&db22.schematic_trace.update(trace.schematic_trace_id,{edges:trace.edges});let junctionsById=computeJunctions([...visibleTraces,...visibleExistingTraces]);for(let t48 of visibleTraces){let pendingTrace=pendingTraces.find(pendingTrace2=>pendingTrace2.source_trace_id===t48.source_trace_id),traceSchematicSheetId=schematicSheetId;pendingTrace?.schematic_sheet_id&&(traceSchematicSheetId=pendingTrace.schematic_sheet_id),db22.schematic_trace.insert({source_trace_id:t48.source_trace_id,edges:t48.edges,junctions:junctionsById[t48.source_trace_id]??[],subcircuit_connectivity_map_key:pendingTrace?.subcircuit_connectivity_map_key,schematic_sheet_id:traceSchematicSheetId})}}var INLINE_NET_LABEL_FONT_SIZE=.12,markConnectionEligibleForInlineNetLabel=(connection,name)=>{connection.anchoredNetLabelWidth??(connection.anchoredNetLabelWidth=Number(getSchematicNetLabelTextWidth2({text:name}).toFixed(2))),connection.allowInlineNetLabel=!0,connection.inlineNetLabelHeight=INLINE_NET_LABEL_FONT_SIZE,connection.inlineNetLabelWidth=Number(getSchematicNetLabelTextWidth2({text:name,font_size:INLINE_NET_LABEL_FONT_SIZE}).toFixed(2))},applyInlineNetLabelEligibility=({directConnections,netConnections,connKeyToSchematicPortIds,connKeyToSourceNet,connKeysWithExplicitPortNetTraces,schematicPortIdsWithExplicitNetLabels,schematicPortIdsWithInlineNetLabels,areSchematicPortsOnDifferentComponents,resolveCanonicalNetLabelText})=>{for(let directConnection of directConnections){let{connKey}=directConnection;if(!connKey||connKeyToSchematicPortIds.get(connKey)?.length!==2)continue;let sourceNet=connKeyToSourceNet.get(connKey);if(sourceNet?.is_power||sourceNet?.is_ground)continue;let{name,wasAssignedDisplayLabel}=resolveCanonicalNetLabelText({subcircuitConnectivityMapKey:connKey});!name||!wasAssignedDisplayLabel||markConnectionEligibleForInlineNetLabel(directConnection,name)}for(let netConnection of netConnections){let{schematicPortIds}=netConnection,{isSameSheetCrossSectionConnection}=netConnection,hasInlineNetLabel=schematicPortIds.some(schematicPortId=>schematicPortIdsWithInlineNetLabels.has(schematicPortId)),isSinglePort=schematicPortIds.length===1,firstSchematicPortId=schematicPortIds[0],hasPortsOnDifferentComponents=firstSchematicPortId!==void 0&&schematicPortIds.slice(1).some(otherSchematicPortId=>areSchematicPortsOnDifferentComponents([firstSchematicPortId,otherSchematicPortId]));if(!hasInlineNetLabel&&!isSameSheetCrossSectionConnection&&!isSinglePort&&!hasPortsOnDifferentComponents||!hasInlineNetLabel&&schematicPortIds.some(schematicPortId=>schematicPortIdsWithExplicitNetLabels.has(schematicPortId)))continue;let{connKey}=netConnection;if(!connKey&&!isSameSheetCrossSectionConnection||connKey&&!isSameSheetCrossSectionConnection&&!connKeysWithExplicitPortNetTraces.has(connKey))continue;let sourceNet=connKey?connKeyToSourceNet.get(connKey):void 0;if(!hasInlineNetLabel&&(netConnection.isPowerOrGroundConnection||sourceNet?.is_power||sourceNet?.is_ground))continue;let name=netConnection.netLabelText??"",wasAssignedDisplayLabel=!!name;if(!isSameSheetCrossSectionConnection){if(!connKey)continue;let resolvedLabel=resolveCanonicalNetLabelText({subcircuitConnectivityMapKey:connKey});name=resolvedLabel.name,wasAssignedDisplayLabel=resolvedLabel.wasAssignedDisplayLabel}!name||!hasInlineNetLabel&&!wasAssignedDisplayLabel||markConnectionEligibleForInlineNetLabel(netConnection,name)}},getPortForSchematicSymbolPort=port=>{let{schX,schY}=port._parsedProps;if(schX!==void 0&&schY!==void 0||!port.getParentNormalComponent()?.getSchematicSymbol())return port;let internallyConnectedPorts=port._getPortsInternallyConnectedToThisPort(),schematicSymbolPortDef=port.schematicSymbolPortDef??internallyConnectedPorts.find(connectedPort=>connectedPort.schematicSymbolPortDef)?.schematicSymbolPortDef;return schematicSymbolPortDef?internallyConnectedPorts.find(connectedPort=>connectedPort.schematicSymbolPortDef===schematicSymbolPortDef)??port:port};function createRoutedSchematicPortIdMap(group2){let{db:db22}=group2.root,routedSchematicPortIdBySchematicPortId=new Map;for(let port of group2.selectAll("port")){if(!port.schematic_port_id)continue;let schematicPort=db22.schematic_port.get(port.schematic_port_id),terminalPort=getPortForSchematicSymbolPort(port),terminalSchematicPort=terminalPort.schematic_port_id?db22.schematic_port.get(terminalPort.schematic_port_id):void 0;!schematicPort||!terminalSchematicPort||schematicPort.schematic_component_id!==terminalSchematicPort.schematic_component_id||schematicPort.schematic_sheet_id!==terminalSchematicPort.schematic_sheet_id||routedSchematicPortIdBySchematicPortId.set(asSchematicPortId(schematicPort.schematic_port_id),asSchematicPortId(terminalSchematicPort.schematic_port_id))}return routedSchematicPortIdBySchematicPortId}var isDirectConnectionEndpointOutsideSchematicScope=({db:db22,sourcePortId,otherSourcePortId,sourcePortIdsInSchematicScope,schematicSheetId})=>{if(sourcePortIdsInSchematicScope.has(otherSourcePortId))return!1;let sourcePort=db22.source_port.get(sourcePortId),otherSourcePort=db22.source_port.get(otherSourcePortId);if(!sourcePort||!otherSourcePort)return!1;if(sourcePort.subcircuit_id!==otherSourcePort.subcircuit_id)return!0;if(!schematicSheetId)return!1;let otherEndpointSchematicPorts=db22.schematic_port.list({source_port_id:otherSourcePortId});return otherEndpointSchematicPorts.some(schematicPort=>schematicPort.schematic_sheet_id===schematicSheetId)?!1:otherEndpointSchematicPorts.some(schematicPort=>schematicPort.schematic_sheet_id!==void 0)},getDirectConnectionOutsideSchematicScopeSourcePortId=({db:db22,sourcePortId,sourcePortIdsInSchematicScope,schematicSheetId})=>{if(db22.source_port.get(sourcePortId))for(let sourceTrace of db22.source_trace.list()){let connectedSourcePortIds=(sourceTrace.connected_source_port_ids??[]).map(asSourcePortId);if(connectedSourcePortIds.length!==2||(sourceTrace.connected_source_net_ids??[]).length>0||!connectedSourcePortIds.includes(sourcePortId))continue;let otherSourcePortId=connectedSourcePortIds.find(portId=>portId!==sourcePortId);if(otherSourcePortId&&isDirectConnectionEndpointOutsideSchematicScope({db:db22,sourcePortId,otherSourcePortId,sourcePortIdsInSchematicScope,schematicSheetId}))return otherSourcePortId}},resolveNetLabelForPortMissingTrace=({group:group2,sourcePortId,connectedSourcePortIdsForKey,sourcePortIdsInSchematicScope,schematicSheetId,connKey,sourceNet})=>{let{db:db22}=group2.root,connectedPortsForKey=group2.selectAll("port").filter(port=>port._getSubcircuitConnectivityKey()===connKey),{name:resolvedPortNetLabelText,wasAssignedDisplayLabel}=getNetNameFromPorts(connectedPortsForKey),assignedPortNetLabelText=wasAssignedDisplayLabel?resolvedPortNetLabelText:void 0,fallbackPortNetLabelText=wasAssignedDisplayLabel?void 0:resolvedPortNetLabelText||void 0,implicitPortLabelText=getNetNameFromSourcePorts(db22,connectedSourcePortIdsForKey),directConnectionOutsideSchematicScopeSourcePortId=getDirectConnectionOutsideSchematicScopeSourcePortId({db:db22,sourcePortId,sourcePortIdsInSchematicScope,schematicSheetId}),directConnectionOutsideSchematicScopeLabelText=directConnectionOutsideSchematicScopeSourcePortId?getSourcePortNetLabelText(db22,directConnectionOutsideSchematicScopeSourcePortId):void 0;return{text:sourceNet?.name||sourceNet?.source_net_id||assignedPortNetLabelText||directConnectionOutsideSchematicScopeLabelText||fallbackPortNetLabelText||implicitPortLabelText||connKey,wasAssignedDisplayLabel,directConnectionOutsideSchematicScopeSourcePortId}},DEFAULT_SCHEMATIC_TEXT_FONT_SIZE=.18;function getSchematicTextBounds2(text){let fontSize=text.font_size??DEFAULT_SCHEMATIC_TEXT_FONT_SIZE,width=getSchematicTextWidth2({text:text.text??"",fontSize}),height=fontSize,anchor3=text.anchor??"center",minX,maxX;anchor3.includes("left")?(minX=0,maxX=width):anchor3.includes("right")?(minX=-width,maxX=0):(minX=-width/2,maxX=width/2);let minY,maxY;anchor3.includes("top")?(minY=-height,maxY=0):anchor3.includes("bottom")?(minY=0,maxY=height):(minY=-height/2,maxY=height/2);let rotation5=(text.rotation??0)*Math.PI/180,cos32=Math.cos(rotation5),sin32=Math.sin(rotation5),corners=[{x:minX,y:minY},{x:minX,y:maxY},{x:maxX,y:minY},{x:maxX,y:maxY}].map(corner=>({x:text.position.x+corner.x*cos32-corner.y*sin32,y:text.position.y+corner.x*sin32+corner.y*cos32}));return getBoundsFromPoints(corners)}var REFDES_TEXT_BOX_CHIP_OVERLAP=.01,REFDES_TEXT_BOX_CLEARANCE=.06;function isReferenceDesignatorText(text,sourceComponent){return sourceComponent?text.text===sourceComponent.display_name||text.text===sourceComponent.name:!1}function schematicTextToTextBox(text,options={}){if(!text.text)return null;let bounds=getSchematicTextBounds2(text);if(isReferenceDesignatorText(text,options.sourceComponent)&&options.schematicComponent?.center&&options.schematicComponent?.size){let componentBounds=getBoundFromCenteredRect({center:options.schematicComponent.center,width:options.schematicComponent.size.width,height:options.schematicComponent.size.height}),textHeight=bounds.maxY-bounds.minY;bounds.minY>componentBounds.maxY&&(bounds.minX-=REFDES_TEXT_BOX_CLEARANCE,bounds.maxX+=REFDES_TEXT_BOX_CLEARANCE,bounds.minY=componentBounds.maxY-REFDES_TEXT_BOX_CHIP_OVERLAP,bounds.maxY=componentBounds.maxY+textHeight+REFDES_TEXT_BOX_CLEARANCE)}return{chipId:text.schematic_component_id,center:getBoundsCenter(bounds),width:bounds.maxX-bounds.minX,height:bounds.maxY-bounds.minY,text:text.text}}var DEFAULT_MAX_MSP_PAIR_DISTANCE2=2.4,SCHEMATIC_RAIL_NET_LABEL_HEIGHT=.42;function createSchematicTraceSolverInputProblem(group2,opts={}){let{db:db22}=group2.root,routedSchematicPortIdBySchematicPortId=createRoutedSchematicPortIdMap(group2),resolveRoutedSchematicPortId=schematicPortId=>routedSchematicPortIdBySchematicPortId.get(schematicPortId)??schematicPortId,sourcePortConnectivityMap=getSourcePortConnectivityMapFromCircuitJson(db22.toArray()),getStableSourceConnectivityNetId=connectivityNetId=>{let canonicalSourceId=[...sourcePortConnectivityMap.getIdsConnectedToNet(connectivityNetId)].sort()[0];return canonicalSourceId?`source_connectivity_${canonicalSourceId}`:`source_${connectivityNetId}`},getSourceConnectivityNetId=sourceTrace=>{let connectivityNetId=[...sourceTrace.connected_source_port_ids,...sourceTrace.connected_source_net_ids].map(sourceId=>sourcePortConnectivityMap.getNetConnectedToId(sourceId)).find(netId=>!!netId);return connectivityNetId?getStableSourceConnectivityNetId(connectivityNetId):sourceTrace.subcircuit_connectivity_map_key??sourceTrace.source_trace_id},powerOrGroundSourceConnectivityNetIds=new Set;for(let sourceNet of db22.source_net.list()){if(!sourceNet.is_power&&!sourceNet.is_ground)continue;let connectivityNetId=sourcePortConnectivityMap.getNetConnectedToId(sourceNet.source_net_id);connectivityNetId&&powerOrGroundSourceConnectivityNetIds.add(getStableSourceConnectivityNetId(connectivityNetId))}let connKeyToSourceNet=new Map,childGroups=[],componentsToVisit=[...group2.children].reverse();for(;componentsToVisit.length>0;){let child=componentsToVisit.pop();if(child instanceof Group5){if(child.isSubcircuit){child._parsedProps.showAsSchematicBox&&childGroups.push(child);continue}childGroups.push(child)}componentsToVisit.push(...[...child.children].reverse())}let allSchematicGroupIds=[group2.schematic_group_id,...childGroups.map(a22=>a22.schematic_group_id)],schematicComponents=db22.schematic_component.list().filter(component=>allSchematicGroupIds.includes(component.schematic_group_id)).filter(component=>opts.schematicSheetId===void 0||component.schematic_sheet_id===opts.schematicSheetId),schematicComponentIds=new Set(schematicComponents.map(component=>component.schematic_component_id)),schematicComponentsById=new Map(schematicComponents.map(component=>[component.schematic_component_id,component])),textBoxes=db22.schematic_text.list().filter(text=>text.schematic_component_id&&schematicComponentIds.has(text.schematic_component_id)).map(text=>{let schematicComponent=schematicComponentsById.get(text.schematic_component_id);if(!schematicComponent)return;let sourceComponent=db22.source_component.get(schematicComponent.source_component_id);return schematicTextToTextBox(text,{schematicComponent,sourceComponent})}).filter(textBox=>!!textBox),sectionIdBySchematicComponentId=new Map,boardDescendants=group2._getBoard()?.getDescendants()??[];for(let component of boardDescendants){let schematicComponentId=component.schematic_component_id,sectionId=component.getSchematicSectionName();schematicComponentId&&sectionId&&sectionIdBySchematicComponentId.set(schematicComponentId,sectionId)}let chips=[];for(let schematicComponent of schematicComponents){let chipId=schematicComponent.schematic_component_id,schematicPorts=db22.schematic_port.list({schematic_component_id:schematicComponent.schematic_component_id}),pins=schematicPorts.filter(schematicPort=>{let id3=asSchematicPortId(schematicPort.schematic_port_id);return resolveRoutedSchematicPortId(id3)===id3}).map(schematicPort=>{let schematicPortId=asSchematicPortId(schematicPort.schematic_port_id),sourcePort=schematicPort.source_port_id?db22.source_port.get(schematicPort.source_port_id):void 0;return{pinId:schematicPortId,displayName:schematicPort.display_pin_label??schematicPort.pin_number?.toString()??sourcePort?.name,x:schematicPort.center.x,y:schematicPort.center.y,_facingDirection:convertFacingDirectionToElbowDirection(schematicPort.facing_direction??null)}}),sectionId=sectionIdBySchematicComponentId.get(schematicComponent.schematic_component_id),obstacleBounds=(schematicComponent.is_box_with_pins===!1?void 0:getSchematicComponentWithTextBounds({db:db22,schematicComponent}))??getBoundFromCenteredRect({center:schematicComponent.center,width:schematicComponent.size.width,height:schematicComponent.size.height});if(schematicComponent.is_box_with_pins!==!1)for(let port of schematicPorts)obstacleBounds.minX=Math.min(obstacleBounds.minX,port.center.x),obstacleBounds.maxX=Math.max(obstacleBounds.maxX,port.center.x),obstacleBounds.minY=Math.min(obstacleBounds.minY,port.center.y),obstacleBounds.maxY=Math.max(obstacleBounds.maxY,port.center.y);chips.push({chipId,center:getBoundsCenter(obstacleBounds),width:obstacleBounds.maxX-obstacleBounds.minX,height:obstacleBounds.maxY-obstacleBounds.minY,pins,sectionId})}let schematicPortIdsInScope=new Set,schPortIdToSourcePortId=new Map,sourcePortIdToSchPortId=new Map,userNetIdToConnKey=new Map,componentPortBySchematicPortId=new Map(group2.selectAll("port").filter(port=>port.schematic_port_id).map(port=>[asSchematicPortId(port.schematic_port_id),port])),resolveCanonicalNetLabelText=createCanonicalSchematicNetLabelTextResolver(group2);for(let sc3 of schematicComponents){let ports=db22.schematic_port.list({schematic_component_id:sc3.schematic_component_id});for(let sp22 of ports){let schematicPortId=asSchematicPortId(sp22.schematic_port_id);if(schematicPortIdsInScope.add(schematicPortId),sp22.source_port_id){let sourcePortId=asSourcePortId(sp22.source_port_id);schPortIdToSourcePortId.set(schematicPortId,sourcePortId),sourcePortIdToSchPortId.set(sourcePortId,schematicPortId)}}}let sourcePortIdsInSchematicScope=new Set(sourcePortIdToSchPortId.keys()),netLabelsInScope=(opts.netLabels??[]).filter(netLabel=>netLabel._getConnectedPorts().some(port=>port.schematic_port_id?schematicPortIdsInScope.has(asSchematicPortId(port.schematic_port_id)):!1)),schematicPortIdsWithExplicitNetLabels=new Set(netLabelsInScope.filter(netLabel=>!netLabel._parsedProps.inline).flatMap(netLabel=>netLabel._getConnectedPorts()).map(port=>port.schematic_port_id).filter(schematicPortId=>schematicPortId!=null).map(asSchematicPortId).map(resolveRoutedSchematicPortId)),solverManagedNetLabelSchematicPortIds=new Set(netLabelsInScope.filter(netLabel=>netLabel._parsedProps.inline||netLabel._parsedProps.schX===void 0&&netLabel._parsedProps.schY===void 0).flatMap(netLabel=>netLabel._getConnectedPorts()).map(port=>port.schematic_port_id).filter(schematicPortId=>schematicPortId!=null).map(asSchematicPortId).map(resolveRoutedSchematicPortId)),schematicPortIdsWithInlineNetLabels=new Set(netLabelsInScope.filter(netLabel=>netLabel._parsedProps.inline).flatMap(netLabel=>netLabel._getConnectedPorts()).map(port=>port.schematic_port_id).filter(schematicPortId=>schematicPortId!=null).map(asSchematicPortId).map(resolveRoutedSchematicPortId)),allowedSubcircuitIds=new Set;group2.subcircuit_id&&allowedSubcircuitIds.add(group2.subcircuit_id);for(let cg2 of childGroups)cg2.subcircuit_id&&allowedSubcircuitIds.add(cg2.subcircuit_id);let tracesInScope=db22.source_trace.list().filter(st22=>{if(st22.subcircuit_id===group2.subcircuit_id)return!0;for(let source_port_id of st22.connected_source_port_ids)if(sourcePortIdToSchPortId.has(asSourcePortId(source_port_id)))return!0;return!1}),schematicPortIdsWithExternallyRoutedRepresentations=new Set;for(let sourceTrace of tracesInScope)if(sourceTrace.subcircuit_id!==group2.subcircuit_id&&sourceTrace.connected_source_net_ids.length!==0)for(let sourcePortId of sourceTrace.connected_source_port_ids){let typedSourcePortId=asSourcePortId(sourcePortId),schematicPortId=sourcePortIdToSchPortId.get(typedSourcePortId);!schematicPortId||solverManagedNetLabelSchematicPortIds.has(schematicPortId)||!db22.schematic_port.list({source_port_id:sourcePortId}).some(port=>port.schematic_port_id===schematicPortId?!1:(port.schematic_component_id?db22.schematic_component.get(port.schematic_component_id):void 0)?.schematic_sheet_id===opts.schematicSheetId)||schematicPortIdsWithExternallyRoutedRepresentations.add(schematicPortId)}let externalNetIds=tracesInScope.flatMap(st22=>st22.connected_source_net_ids);for(let netId of externalNetIds){let net=db22.source_net.get(netId);net?.subcircuit_id&&allowedSubcircuitIds.add(net.subcircuit_id)}for(let net of db22.source_net.list().filter(sourceNet=>!sourceNet.subcircuit_id||allowedSubcircuitIds.has(sourceNet.subcircuit_id)))net.subcircuit_connectivity_map_key&&connKeyToSourceNet.set(net.subcircuit_connectivity_map_key,net);let directConnections=[],boundaryTraceNetConnections=[],connectedPairKeys=new Set,crossScopeSourceTraceIdBySchematicPortIdAndNetId=new Map,crossSectionNetConnectionByKey=new Map,setCrossScopeSourceTraceId=({schematicPortId,netId,sourceTraceId,replaceExisting=!1})=>{let sourceTraceIdByNetId=crossScopeSourceTraceIdBySchematicPortIdAndNetId.get(schematicPortId)??new Map;return sourceTraceIdByNetId.has(netId)&&!replaceExisting?!1:(sourceTraceIdByNetId.set(netId,sourceTraceId),crossScopeSourceTraceIdBySchematicPortIdAndNetId.set(schematicPortId,sourceTraceIdByNetId),!0)},addPortToCrossSectionInlineNetConnection=({sourceConnectivityNetId,schematicPortId,text,sourceTraceId,connKey,preferInScopeTraceMetadata=!1})=>{let netId=sourceConnectivityNetId;if(setCrossScopeSourceTraceId({schematicPortId,netId,sourceTraceId,replaceExisting:preferInScopeTraceMetadata}),schematicPortIdsWithExplicitNetLabels.has(schematicPortId))return;let connection=crossSectionNetConnectionByKey.get(sourceConnectivityNetId);connection?preferInScopeTraceMetadata&&(connection.netLabelText=text,connection.netLabelWidth=Number(getSchematicNetLabelTextWidth2({text}).toFixed(2)),connection.connKey=connKey??connection.connKey):(connection={netId,netLabelText:text,schematicPortIds:[],netLabelWidth:Number(getSchematicNetLabelTextWidth2({text}).toFixed(2)),connKey,isSameSheetCrossSectionConnection:!0,isPowerOrGroundConnection:powerOrGroundSourceConnectivityNetIds.has(netId)},crossSectionNetConnectionByKey.set(sourceConnectivityNetId,connection),boundaryTraceNetConnections.push(connection)),connection.schematicPortIds.includes(schematicPortId)||connection.schematicPortIds.push(schematicPortId)},sourceTraceIdsByPortOnlyLabelSchematicPortId=new Map,sourceTraceIdByPinPairKey=new Map,connKeysWithExplicitPortNetTraces=new Set;for(let sourceTrace of tracesInScope)sourceTrace?.subcircuit_connectivity_map_key&&(sourceTrace.connected_source_port_ids?.length??0)>0&&(sourceTrace.connected_source_net_ids?.length??0)>0&&connKeysWithExplicitPortNetTraces.add(sourceTrace.subcircuit_connectivity_map_key);let areSchematicPortsInDifferentSectionsOnSameSheet=(firstSchematicPortId,secondSchematicPortId)=>{let firstSchematicPort=db22.schematic_port.get(firstSchematicPortId),secondSchematicPort=db22.schematic_port.get(secondSchematicPortId);if(!firstSchematicPort||!secondSchematicPort||!(firstSchematicPort.schematic_sheet_id===secondSchematicPort.schematic_sheet_id))return!1;let firstSectionId=firstSchematicPort.schematic_component_id?sectionIdBySchematicComponentId.get(firstSchematicPort.schematic_component_id):void 0,secondSectionId=secondSchematicPort.schematic_component_id?sectionIdBySchematicComponentId.get(secondSchematicPort.schematic_component_id):void 0;return firstSectionId!==secondSectionId&&(firstSectionId!==void 0||secondSectionId!==void 0)},doesSourcePortCrossSectionOnSameSheet=({schematicPortId,otherSourcePortId})=>db22.schematic_port.list({source_port_id:otherSourcePortId}).some(otherSchematicPort=>areSchematicPortsInDifferentSectionsOnSameSheet(schematicPortId,asSchematicPortId(otherSchematicPort.schematic_port_id)));for(let st22 of tracesInScope){let connected=Array.from(new Set((st22.connected_source_port_ids??[]).map(sourcePortId=>sourcePortIdToSchPortId.get(asSourcePortId(sourcePortId))).filter(schematicPortId=>!!schematicPortId&&schematicPortIdsInScope.has(schematicPortId)).map(resolveRoutedSchematicPortId))),sourcePortIdForSingleConnectedEndpoint=connected.length===1?schPortIdToSourcePortId.get(connected[0]):void 0,otherSourcePortId=sourcePortIdForSingleConnectedEndpoint?st22.connected_source_port_ids.map(asSourcePortId).find(sourcePortId=>sourcePortId!==sourcePortIdForSingleConnectedEndpoint):void 0,crossesSchematicScopeBoundary=!!(sourcePortIdForSingleConnectedEndpoint&&otherSourcePortId&&isDirectConnectionEndpointOutsideSchematicScope({db:db22,sourcePortId:sourcePortIdForSingleConnectedEndpoint,otherSourcePortId,sourcePortIdsInSchematicScope,schematicSheetId:opts.schematicSheetId})),crossesSchematicSectionOnSameSheet=!!(connected.length===1&&otherSourcePortId&&doesSourcePortCrossSectionOnSameSheet({schematicPortId:connected[0],otherSourcePortId}));if(connected.length===1&&st22.connected_source_port_ids.length===2&&crossesSchematicScopeBoundary&&st22.connected_source_net_ids.length===0&&st22.subcircuit_connectivity_map_key){let schematicPortId=connected[0],sourcePortId=schPortIdToSourcePortId.get(schematicPortId);if(sourcePortId){let connKey=st22.subcircuit_connectivity_map_key,sourcePortConnKey=db22.source_port.get(sourcePortId)?.subcircuit_connectivity_map_key,sourceNetInCurrentSubcircuit=db22.source_net.list().find(sourceNet=>sourceNet.subcircuit_id===group2.subcircuit_id&&sourcePortConnectivityMap.areIdsConnected(sourceNet.source_net_id,sourcePortId)),sourceNetForLabel=connKeyToSourceNet.get(connKey)??(sourcePortConnKey?connKeyToSourceNet.get(sourcePortConnKey):void 0)??sourceNetInCurrentSubcircuit,connectedSourcePortIdsForKey=Array.from(schematicPortIdsInScope).map(portId=>schPortIdToSourcePortId.get(portId)).filter(sourcePortId2=>sourcePortId2?db22.source_port.get(sourcePortId2)?.subcircuit_connectivity_map_key===connKey:!1),{text}=resolveNetLabelForPortMissingTrace({group:group2,sourcePortId,connectedSourcePortIdsForKey,sourcePortIdsInSchematicScope,schematicSheetId:opts.schematicSheetId,connKey,sourceNet:sourceNetForLabel});if(text){let sourceConnectivityNetId=getSourceConnectivityNetId(st22);userNetIdToConnKey.has(sourceConnectivityNetId)||userNetIdToConnKey.set(sourceConnectivityNetId,connKey),crossesSchematicSectionOnSameSheet?addPortToCrossSectionInlineNetConnection({sourceConnectivityNetId,schematicPortId,text,sourceTraceId:st22.source_trace_id,connKey}):setCrossScopeSourceTraceId({schematicPortId,netId:sourceConnectivityNetId,sourceTraceId:st22.source_trace_id})&&boundaryTraceNetConnections.push({netId:sourceConnectivityNetId,netLabelText:text,schematicPortIds:[schematicPortId],netLabelWidth:Number(getSchematicNetLabelTextWidth2({text}).toFixed(2)),connKey})}}}else if(connected.length>=2){for(let schematicPortId of connected){let sourceTraceIds=sourceTraceIdsByPortOnlyLabelSchematicPortId.get(schematicPortId)??new Set;sourceTraceIds.add(st22.source_trace_id),sourceTraceIdsByPortOnlyLabelSchematicPortId.set(schematicPortId,sourceTraceIds)}let traceLabel=st22.name??st22.display_name,userNetId=traceLabel??st22.source_trace_id;st22.subcircuit_connectivity_map_key&&userNetIdToConnKey.set(userNetId,st22.subcircuit_connectivity_map_key);let maxMspDist=group2._parsedProps.schMaxTraceDistance??DEFAULT_MAX_MSP_PAIR_DISTANCE2,portsForConnection=connected.map(schematicPortId=>componentPortBySchematicPortId.get(schematicPortId)).filter(port=>!!port),renderedNetLabelText=st22.subcircuit_connectivity_map_key?resolveCanonicalNetLabelText({subcircuitConnectivityMapKey:st22.subcircuit_connectivity_map_key}).name:getNetNameFromPorts(portsForConnection).name||traceLabel,shouldRenderNetLabels=connected.slice(1).some((b22,index2)=>{let a22=connected[index2],portA=db22.schematic_port.get(a22),portB=db22.schematic_port.get(b22);return!portA||!portB?!1:Math.sqrt((portA.center.x-portB.center.x)**2+(portA.center.y-portB.center.y)**2)>maxMspDist}),netLabelWidth=renderedNetLabelText&&shouldRenderNetLabels?Number(getSchematicNetLabelTextWidth2({text:renderedNetLabelText}).toFixed(2)):void 0,crossSectionNetLabelText=renderedNetLabelText;for(let i22=0;i22<connected.length-1;i22++){let a22=connected[i22],b22=connected[i22+1],pairKey=[a22,b22].sort().join("::");if(!connectedPairKeys.has(pairKey)){if(connectedPairKeys.add(pairKey),crossSectionNetLabelText&&areSchematicPortsInDifferentSectionsOnSameSheet(a22,b22)){let sourceConnectivityNetId=getSourceConnectivityNetId(st22);st22.subcircuit_connectivity_map_key&&userNetIdToConnKey.set(sourceConnectivityNetId,st22.subcircuit_connectivity_map_key),addPortToCrossSectionInlineNetConnection({sourceConnectivityNetId,schematicPortId:a22,text:crossSectionNetLabelText,sourceTraceId:st22.source_trace_id,connKey:st22.subcircuit_connectivity_map_key,preferInScopeTraceMetadata:!0}),addPortToCrossSectionInlineNetConnection({sourceConnectivityNetId,schematicPortId:b22,text:crossSectionNetLabelText,sourceTraceId:st22.source_trace_id,connKey:st22.subcircuit_connectivity_map_key,preferInScopeTraceMetadata:!0});continue}sourceTraceIdByPinPairKey.set(pairKey,st22.source_trace_id),directConnections.push({schematicPortIds:[a22,b22],netId:userNetId,netLabelWidth,connKey:st22.subcircuit_connectivity_map_key})}}}}let netConnections=[...boundaryTraceNetConnections],connKeyToSchematicPortIds=new Map;for(let[schId,srcPortId]of schPortIdToSourcePortId){if(schematicPortIdsWithExternallyRoutedRepresentations.has(schId))continue;let sp22=db22.source_port.get(srcPortId);if(!sp22?.subcircuit_connectivity_map_key)continue;let connKey=sp22.subcircuit_connectivity_map_key;connKeyToSchematicPortIds.has(connKey)||connKeyToSchematicPortIds.set(connKey,[]);let routedSchematicPortId=resolveRoutedSchematicPortId(schId),netSchematicPortIds=connKeyToSchematicPortIds.get(connKey);netSchematicPortIds.includes(routedSchematicPortId)||netSchematicPortIds.push(routedSchematicPortId)}for(let[connKey,schematicPortIds]of connKeyToSchematicPortIds){let sourceNet=connKeyToSourceNet.get(connKey);if(sourceNet&&schematicPortIds.length>=1){let userNetId=String(sourceNet.name||sourceNet.source_net_id||connKey);userNetIdToConnKey.set(userNetId,connKey);let netLabelTextWidth=Number(getSchematicNetLabelTextWidth2({text:String(userNetId)}).toFixed(2)),netLabelWidth=netLabelTextWidth,netLabelHeight;(sourceNet.is_ground||sourceNet.is_power)&&(netLabelWidth=SCHEMATIC_RAIL_NET_LABEL_HEIGHT,netLabelHeight=netLabelTextWidth),netConnections.push({netId:userNetId,schematicPortIds,isGround:sourceNet.is_ground,netLabelWidth,netLabelHeight,connKey})}}applyInlineNetLabelEligibility({directConnections,netConnections,connKeyToSchematicPortIds,connKeyToSourceNet,connKeysWithExplicitPortNetTraces,schematicPortIdsWithExplicitNetLabels,schematicPortIdsWithInlineNetLabels,areSchematicPortsOnDifferentComponents:schematicPortIds=>{let componentIds=schematicPortIds.map(schematicPortId=>db22.schematic_port.get(schematicPortId)?.schematic_component_id);return componentIds.every(componentId=>!!componentId)&&componentIds[0]!==componentIds[1]},resolveCanonicalNetLabelText});let availableNetLabelOrientations=(()=>{let netToAllowedOrientations={},presentNetIds=new Set(netConnections.map(nc3=>nc3.netId));for(let net of db22.source_net.list().filter(n22=>!n22.subcircuit_id||allowedSubcircuitIds.has(n22.subcircuit_id)))net.name&&presentNetIds.has(net.name)&&(net.is_ground?netToAllowedOrientations[net.name]=["y-"]:net.is_power?netToAllowedOrientations[net.name]=["y+"]:netToAllowedOrientations[net.name]=["x-","x+"]);for(let{netId}of boundaryTraceNetConnections)netToAllowedOrientations[netId]??(netToAllowedOrientations[netId]=["x-","x+"]);return netToAllowedOrientations})(),inputProblem={chips,directConnections:directConnections.map(({schematicPortIds,connKey,...connection})=>({...connection,pinIds:schematicPortIds})),netConnections:netConnections.map(({schematicPortIds,connKey,isSameSheetCrossSectionConnection,isPowerOrGroundConnection,...connection})=>({...connection,pinIds:schematicPortIds})),textBoxes,availableNetLabelOrientations,maxMspPairDistance:group2._parsedProps.schMaxTraceDistance??DEFAULT_MAX_MSP_PAIR_DISTANCE2},sourceTraceIdByPortOnlyLabelSchematicPortId=new Map(Array.from(sourceTraceIdsByPortOnlyLabelSchematicPortId).flatMap(([schematicPortId,sourceTraceIds])=>sourceTraceIds.size!==1?[]:[[schematicPortId,sourceTraceIds.values().next().value]]));return{inputProblem,routedSchematicPortIdBySchematicPortId,connKeyToSourceNet,userNetIdToConnKey,crossScopeSourceTraceIdBySchematicPortIdAndNetId,sourceTraceIdByPortOnlyLabelSchematicPortId,connKeysWithExplicitPortNetTraces,schematicPortIdsInScope,schematicPortIdsWithExternallyRoutedRepresentations,schPortIdToSourcePortId,netLabelsInScope,sourceTraceIdByPinPairKey}}var getSchematicPortIdsWithAssignedNetLabels=(netLabels,routedSchematicPortIdBySchematicPortId)=>{let schematicPortIdsWithNetLabels=new Set;for(let netLabel of netLabels){let{inline,schX,schY}=netLabel._parsedProps;if(inline||schX===void 0&&schY===void 0)continue;let netLabelPorts=netLabel._getConnectedPorts();for(let port of netLabelPorts)port.schematic_port_id&&schematicPortIdsWithNetLabels.add(routedSchematicPortIdBySchematicPortId.get(asSchematicPortId(port.schematic_port_id))??asSchematicPortId(port.schematic_port_id))}return schematicPortIdsWithNetLabels},getSchematicPortIdsWithRoutedTraces=({solver})=>{let solvedTraces=solver.traceCleanupSolver?.getOutput().traces??solver.traceLabelOverlapAvoidanceSolver?.getOutput().traces??solver.schematicTraceLinesSolver?.solvedTracePaths??[],schematicPortIdsWithRoutedTraces=new Set;for(let solvedTrace of solvedTraces){let points=solvedTrace?.tracePath;if(!Array.isArray(points)||points.length<2)continue;let pinIds=Array.isArray(solvedTrace.pins)?solvedTrace.pins.map(pin=>pin.pinId):solvedTrace.pinIds;for(let pinId of pinIds){let schPortId=asSchematicPortId(pinId);schPortId&&schematicPortIdsWithRoutedTraces.add(schPortId)}}return schematicPortIdsWithRoutedTraces},NEAR_EXISTING_NET_LABEL_DISTANCE=.5,SAME_ANCHOR_POSITION_DISTANCE=.1,doesSchematicNetLabelRepresentCurrentSourceConnection=args=>{let{nl:nl3,connKey,sourceNet,text}=args;return sourceNet?.source_net_id&&nl3.source_net_id?nl3.source_net_id===sourceNet.source_net_id:nl3.source_net_id?nl3.source_net_id===connKey:nl3.text===text},insertNetLabelsForPortsMissingTrace=({schematicPortIdsInScope,schematicPortIdsWithExternallyRoutedRepresentations,group:group2,schPortIdToSourcePortId,connKeyToSourceNet})=>{let{db:db22}=group2.root,sourcePortIdsInSchematicScope=new Set(Array.from(schematicPortIdsInScope).map(schematicPortId=>schPortIdToSourcePortId.get(schematicPortId)).filter(sourcePortId=>sourcePortId!==void 0));for(let schematicPortId of schematicPortIdsInScope){if(schematicPortIdsWithExternallyRoutedRepresentations.has(schematicPortId))continue;let schPort=db22.schematic_port.get(schematicPortId);if(!schPort||schPort.is_connected)continue;let srcPortId=schPortIdToSourcePortId.get(schematicPortId);if(!srcPortId)continue;let sourcePort=db22.source_port.get(srcPortId);if(group2._parsedProps.showAsSchematicBox&&sourcePort?.subcircuit_id===group2.subcircuit_id&&!sourcePort.source_component_id&&getDirectConnectionOutsideSchematicScopeSourcePortId({db:db22,sourcePortId:srcPortId,sourcePortIdsInSchematicScope,schematicSheetId:schPort.schematic_sheet_id}))continue;let connKey=sourcePort?.subcircuit_connectivity_map_key;if(!connKey)continue;let sourceNet=connKeyToSourceNet.get(connKey),schComponent=schPort.schematic_component_id?db22.schematic_component.get(schPort.schematic_component_id):void 0,portSchematicSheetId=schComponent?.schematic_sheet_id??group2._resolveSchematicSheetId(),connectedSourcePortIdsForKey=Array.from(schematicPortIdsInScope).map(portId=>schPortIdToSourcePortId.get(portId)).filter(sourcePortId=>sourcePortId?db22.source_port.get(sourcePortId)?.subcircuit_connectivity_map_key===connKey:!1),{text,wasAssignedDisplayLabel,directConnectionOutsideSchematicScopeSourcePortId}=resolveNetLabelForPortMissingTrace({group:group2,sourcePortId:srcPortId,connectedSourcePortIdsForKey,sourcePortIdsInSchematicScope,schematicSheetId:schPort.schematic_sheet_id,connKey,sourceNet}),shouldPreserveDirectConnectionEndpointLabels=directConnectionOutsideSchematicScopeSourcePortId?db22.schematic_port.list({source_port_id:directConnectionOutsideSchematicScopeSourcePortId}).some(port=>!port.is_connected):!1,isCollapsedBoxPort=schComponent?.is_box_with_pins&&sourcePort&&!sourcePort.source_component_id,hasExternalTrace=db22.source_trace.list().some(trace=>trace.connected_source_port_ids.includes(srcPortId)&&trace.subcircuit_id!==sourcePort?.subcircuit_id);if(isCollapsedBoxPort&&!hasExternalTrace&&!!!(sourceNet||wasAssignedDisplayLabel))continue;let connectedPortCountForKey=Array.from(schematicPortIdsInScope).filter(portId=>{let sourcePortId=schPortIdToSourcePortId.get(portId);return sourcePortId?db22.source_port.get(sourcePortId)?.subcircuit_connectivity_map_key===connKey:!1}).length,isGndNet=sourceNet?.is_ground??!1,isPowerNet=!isGndNet&&(sourceNet?.is_power??!1),side;isGndNet?side="top":isPowerNet?side="bottom":side=getEnteringEdgeFromDirection(schPort.facing_direction||"right")||"right";let center2=computeSchematicNetLabelCenter({anchor_position:schPort.center,anchor_side:side,text}),existingNetLabelForCurrentSourceConnection=db22.schematic_net_label.list().find(nl3=>nl3.schematic_sheet_id!==portSchematicSheetId?!1:doesSchematicNetLabelRepresentCurrentSourceConnection({nl:nl3,connKey,sourceNet,text}));if(existingNetLabelForCurrentSourceConnection&&connectedPortCountForKey<=1&&!shouldPreserveDirectConnectionEndpointLabels){db22.schematic_net_label.update(existingNetLabelForCurrentSourceConnection.schematic_net_label_id,{text,anchor_position:schPort.center,center:center2,anchor_side:side});continue}if(existingNetLabelForCurrentSourceConnection){let dx22=existingNetLabelForCurrentSourceConnection.anchor_position.x-schPort.center.x,dy22=existingNetLabelForCurrentSourceConnection.anchor_position.y-schPort.center.y;if(dx22*dx22+dy22*dy22<NEAR_EXISTING_NET_LABEL_DISTANCE*NEAR_EXISTING_NET_LABEL_DISTANCE){if(isGndNet){let anchor_side=existingNetLabelForCurrentSourceConnection.anchor_side??side;db22.schematic_net_label.update(existingNetLabelForCurrentSourceConnection.schematic_net_label_id,{text,anchor_position:schPort.center,center:computeSchematicNetLabelCenter({anchor_position:schPort.center,anchor_side,text}),anchor_side})}else if(!isPowerNet&&existingNetLabelForCurrentSourceConnection.text===text){let anchor_side=existingNetLabelForCurrentSourceConnection.anchor_side??side;db22.schematic_net_label.update(existingNetLabelForCurrentSourceConnection.schematic_net_label_id,{text,anchor_position:schPort.center,center:computeSchematicNetLabelCenter({anchor_position:schPort.center,anchor_side,text}),anchor_side})}continue}if(db22.schematic_net_label.list().some(nl3=>{if(nl3.schematic_sheet_id!==portSchematicSheetId)return!1;let dx32=nl3.anchor_position.x-schPort.center.x,dy32=nl3.anchor_position.y-schPort.center.y;return dx32*dx32+dy32*dy32>=SAME_ANCHOR_POSITION_DISTANCE*SAME_ANCHOR_POSITION_DISTANCE?!1:doesSchematicNetLabelRepresentCurrentSourceConnection({nl:nl3,connKey,sourceNet,text})}))continue}if(!sourceNet&&!shouldPreserveDirectConnectionEndpointLabels)for(let nl3 of db22.schematic_net_label.list()){if(nl3.source_net_id!==connKey||nl3.schematic_sheet_id!==portSchematicSheetId)continue;connectedSourcePortIdsForKey.some(sourcePortId=>{let schPortId=Array.from(schPortIdToSourcePortId.entries()).find(([,id3])=>id3===sourcePortId)?.[0],connectedSchPort;if(schPortId&&(connectedSchPort=db22.schematic_port.get(schPortId)),!connectedSchPort?.center||!nl3.anchor_position)return!1;let dx22=nl3.anchor_position.x-connectedSchPort.center.x,dy22=nl3.anchor_position.y-connectedSchPort.center.y;return dx22*dx22+dy22*dy22<SAME_ANCHOR_POSITION_DISTANCE*SAME_ANCHOR_POSITION_DISTANCE})||db22.schematic_net_label.delete(nl3.schematic_net_label_id)}let netLabel={text,source_net_id:sourceNet?.source_net_id??connKey,anchor_position:schPort.center,center:center2,anchor_side:side,schematic_sheet_id:portSchematicSheetId};db22.schematic_net_label.insert(netLabel)}},debug11=(0,import_debug16.default)("Group_doInitialSchematicTraceRender"),renderSchematicTracesForSheet=({group:group2,schematicSheetId,netLabels})=>{let{inputProblem,routedSchematicPortIdBySchematicPortId,connKeyToSourceNet,schematicPortIdsInScope,schematicPortIdsWithExternallyRoutedRepresentations,schPortIdToSourcePortId,userNetIdToConnKey,crossScopeSourceTraceIdBySchematicPortIdAndNetId,sourceTraceIdByPortOnlyLabelSchematicPortId,connKeysWithExplicitPortNetTraces,netLabelsInScope,sourceTraceIdByPinPairKey}=createSchematicTraceSolverInputProblem(group2,{schematicSheetId,netLabels});if(inputProblem.chips.length===0)return;let schematicPortIdsWithPreExistingNetLabels=getSchematicPortIdsWithAssignedNetLabels(netLabelsInScope,routedSchematicPortIdBySchematicPortId);if(!(inputProblem.directConnections.length>0||inputProblem.netConnections.length>0)){insertNetLabelsForPortsMissingTrace({group:group2,schematicPortIdsInScope,schematicPortIdsWithExternallyRoutedRepresentations,schPortIdToSourcePortId,connKeyToSourceNet});return}debug11.enabled&&group2.root?.emit("debug:logOutput",{type:"debug:logOutput",name:"group-trace-render-input-problem",content:JSON.stringify(inputProblem,null,2)});let solver=new SchematicTracePipelineSolver(inputProblem),solverConstructorArgs=solver.getConstructorParams();group2.root?.emit("solver:started",{type:"solver:started",solverName:"SchematicTracePipelineSolver",solverParams:solverConstructorArgs[0],solverConstructorArgs,componentName:group2.getString()}),solver.solve();let schematicPortIdsWithRoutedTraces=getSchematicPortIdsWithRoutedTraces({solver});applyTracesFromSolverOutput({group:group2,solver,userNetIdToConnKey,schematicPortIdsWithPreExistingNetLabels}),applyNetLabelPlacements({group:group2,routedSchematicPortIdBySchematicPortId,solver,connKeyToSourceNet,userNetIdToConnKey,crossScopeSourceTraceIdBySchematicPortIdAndNetId,sourceTraceIdByPortOnlyLabelSchematicPortId,connKeysWithExplicitPortNetTraces,schematicPortIdsWithPreExistingNetLabels,schematicPortIdsWithRoutedTraces,netLabels:netLabelsInScope}),applyInlineNetLabelPlacements({group:group2,solver,userNetIdToConnKey,sourceTraceIdByPinPairKey,crossScopeSourceTraceIdBySchematicPortIdAndNetId});let{db:db22}=group2.root;for(let[schematicPortId,routedSchematicPortId]of routedSchematicPortIdBySchematicPortId)db22.schematic_port.get(routedSchematicPortId)?.is_connected&&db22.schematic_port.update(schematicPortId,{is_connected:!0});insertNetLabelsForPortsMissingTrace({group:group2,schematicPortIdsInScope,schematicPortIdsWithExternallyRoutedRepresentations,schPortIdToSourcePortId,connKeyToSourceNet})},Group_doInitialSchematicTraceRender=group2=>{if(!group2.root?._featureMspSchematicTraceRouting||!group2.isSubcircuit||group2.root?.schematicDisabled)return;let netLabels=new Set,board=group2._getBoard(),schematicScope=group2;for(;schematicScope;){if(schematicScope instanceof Group5)for(let netLabel of schematicScope.selectAll("netlabel"))netLabels.add(netLabel);if(schematicScope===board)break;schematicScope=schematicScope.parent}let netLabelComponents=[...netLabels],schematicGroupIds=new Set([group2,...group2.getDescendants().filter(component=>component instanceof Group5)].map(schematicGroup=>schematicGroup.schematic_group_id).filter(schematicGroupId=>!!schematicGroupId)),schematicSheetIds=new Set(group2.root.db.schematic_component.list().filter(schematicComponent=>schematicGroupIds.has(schematicComponent.schematic_group_id)).map(schematicComponent=>schematicComponent.schematic_sheet_id).filter(schematicSheetId=>!!schematicSheetId));if(schematicSheetIds.size===0){renderSchematicTracesForSheet({group:group2,netLabels:netLabelComponents});return}for(let schematicSheetId of schematicSheetIds)renderSchematicTracesForSheet({group:group2,schematicSheetId,netLabels:netLabelComponents})};function getTransientVoltageGraphNamesFromSpiceNetlist(spiceNetlist){let graphNames=[];for(let printStatement of spiceNetlist.printStatements){let match2=printStatement.match(/^\.PRINT\s+TRAN\s+(.+)$/i);if(match2)for(let voltageExpression of match2[1].match(/V\(([^)]+)\)/g)??[]){let nodeList=voltageExpression.slice(2,-1);graphNames.push(nodeList.replace(",","-"))}}return graphNames}var SIMULATION_COLOR_PALETTE=["rgb(0, 150, 0)","rgb(0, 0, 220)","rgb(220, 0, 0)","rgb(0, 160, 160)","rgb(180, 0, 180)","rgb(170, 140, 0)","rgb(220, 120, 0)","rgb(128, 128, 128)","rgb(100, 0, 180)","rgb(140, 70, 0)","rgb(220, 80, 120)","rgb(0, 120, 220)","rgb(0, 120, 120)","rgb(120, 0, 0)","rgb(0, 0, 132)","rgb(80, 80, 80)"],idToColorMap=new Map,colorIndex=0;function getSimulationColorForId(id3){if(idToColorMap.has(id3))return idToColorMap.get(id3);let color3=SIMULATION_COLOR_PALETTE[colorIndex];return colorIndex=(colorIndex+1)%SIMULATION_COLOR_PALETTE.length,idToColorMap.set(id3,color3),color3}function resetSimulationColorState(){idToColorMap.clear(),colorIndex=0}var getSpiceyEngine=()=>({async simulate(spiceString){let simulation_experiment_id="spice-experiment-1",{circuit:parsedCircuit,tran}=simulate(spiceString);return{simulationResultCircuitJson:spiceyTranToVGraphs(tran,parsedCircuit,simulation_experiment_id)}}}),isCurrentGraph2=element=>element.type==="simulation_transient_current_graph",isSimulationCurrentResult=circuitElement=>circuitElement.type==="simulation_dc_operating_point_current"||circuitElement.type==="simulation_dc_sweep_current_graph"||circuitElement.type==="simulation_ac_sweep_current_graph",isSimulationVoltageResult=circuitElement=>circuitElement.type==="simulation_dc_operating_point_voltage"||circuitElement.type==="simulation_dc_sweep_voltage_graph"||circuitElement.type==="simulation_ac_sweep_voltage_graph",isVoltageGraph=element=>element.type==="simulation_transient_voltage_graph",isSimulationAnalysisResult2=circuitElement=>isVoltageGraph(circuitElement)||isCurrentGraph2(circuitElement)||isSimulationVoltageResult(circuitElement)||isSimulationCurrentResult(circuitElement),attachSweepCoordinateToSimulationResult=({simulationResult,simulationParameterSweepCoordinate})=>{if(!simulationParameterSweepCoordinate||!isSimulationAnalysisResult2(simulationResult))return simulationResult;let simulationResultWithSweepCoordinate={...simulationResult},simulationResultIdKey=`${simulationResultWithSweepCoordinate.type}_id`;return Reflect.deleteProperty(simulationResultWithSweepCoordinate,simulationResultIdKey),simulationResultWithSweepCoordinate.simulation_parameter_sweep_coordinate=simulationParameterSweepCoordinate,simulationResultWithSweepCoordinate},getSourceComponentOrThrow=({circuitJson,sourceComponentId,isMatchingSourceComponent})=>{let sourceComponent=circuitJson.find(circuitElement=>isMatchingSourceComponent(circuitElement)&&circuitElement.source_component_id===sourceComponentId);if(!sourceComponent)throw new Error(`Parameter sweep target ${sourceComponentId} was not found`);return sourceComponent},applyParameterSweepCoordinate=({circuitJson,parameterSweep,simulationParameterSweepCoordinate})=>{let sweptCircuitJson=structuredClone(circuitJson),parameterValue=simulationParameterSweepCoordinate.parameter_value;if(parameterSweep.parameter_type==="resistance"){let resistor=getSourceComponentOrThrow({circuitJson:sweptCircuitJson,sourceComponentId:parameterSweep.resistor_source_component_id,isMatchingSourceComponent:circuitElement=>circuitElement.type==="source_component"&&circuitElement.ftype==="simple_resistor"});return resistor.resistance=parameterValue,sweptCircuitJson}if(parameterSweep.parameter_type==="capacitance"){let capacitor=getSourceComponentOrThrow({circuitJson:sweptCircuitJson,sourceComponentId:parameterSweep.capacitor_source_component_id,isMatchingSourceComponent:circuitElement=>circuitElement.type==="source_component"&&circuitElement.ftype==="simple_capacitor"});return capacitor.capacitance=parameterValue,sweptCircuitJson}if(parameterSweep.parameter_type==="inductance"){let inductor=getSourceComponentOrThrow({circuitJson:sweptCircuitJson,sourceComponentId:parameterSweep.inductor_source_component_id,isMatchingSourceComponent:circuitElement=>circuitElement.type==="source_component"&&circuitElement.ftype==="simple_inductor"});return inductor.inductance=parameterValue,sweptCircuitJson}if(parameterSweep.parameter_type==="voltage"){let groundNet=sweptCircuitJson.find(circuitElement=>circuitElement.type==="source_net"&&circuitElement.name.toUpperCase()==="GND");if(!groundNet||groundNet.type!=="source_net")throw new Error("A voltage parameter sweep requires a GND net");let sweepVoltageSource={type:"simulation_voltage_source",simulation_voltage_source_id:`simulation_voltage_source_${simulationParameterSweepCoordinate.simulation_parameter_sweep_id}_${simulationParameterSweepCoordinate.sweep_index}`,is_dc_source:!0,positive_source_net_id:parameterSweep.source_net_id,negative_source_net_id:groundNet.source_net_id,voltage:parameterValue};return sweptCircuitJson.push(sweepVoltageSource),sweptCircuitJson}if(parameterSweep.parameter_type==="current"){let currentSourcePortIds=new Set(sweptCircuitJson.filter(circuitElement=>circuitElement.type==="source_port"&&circuitElement.source_component_id===parameterSweep.current_source_component_id).map(sourcePort=>sourcePort.source_port_id)),currentSource=sweptCircuitJson.find(circuitElement=>circuitElement.type==="simulation_current_source"&&(circuitElement.is_dc_source?!!(circuitElement.positive_source_port_id&&currentSourcePortIds.has(circuitElement.positive_source_port_id)):!!(circuitElement.terminal1_source_port_id&&currentSourcePortIds.has(circuitElement.terminal1_source_port_id))));if(!currentSource)throw new Error(`Current sweep target ${parameterSweep.current_source_component_id} has no simulation source`);return currentSource.current=parameterValue,sweptCircuitJson}throw new Error("Parameter sweep target is incomplete")},createSimulationRun=({circuitJson,simulationParameterSweepCoordinate})=>{let spiceNetlist=circuitJsonToSpice(circuitJson);return{spiceNetlist,spiceString:spiceNetlist.toSpiceString(),simulationParameterSweepCoordinate}},createSimulationRuns=({circuitJson,simulationExperimentId})=>{let parameterSweep=circuitJson.find(circuitElement=>circuitElement.type==="simulation_parameter_sweep"&&circuitElement.simulation_experiment_id===simulationExperimentId);return parameterSweep?parameterSweep.parameter_values.map((parameterValue,sweepIndex)=>{let simulationParameterSweepCoordinate={simulation_parameter_sweep_id:parameterSweep.simulation_parameter_sweep_id,sweep_index:sweepIndex,parameter_value:parameterValue,parameter_unit:parameterSweep.parameter_unit};return createSimulationRun({circuitJson:applyParameterSweepCoordinate({circuitJson,parameterSweep,simulationParameterSweepCoordinate}),simulationParameterSweepCoordinate})}):[createSimulationRun({circuitJson})]},SI_PREFIX_MULTIPLIERS={p:1e-12,n:1e-9,u:1e-6,\u00B5:1e-6,m:.001,"":1,k:1e3,K:1e3,M:1e6,G:1e9},parseSimulationGraphValue=value=>{if(value===void 0)return;if(typeof value=="number")return value;let match2=value.trim().match(/^([+-]?(?:\d+(?:\.\d*)?|\.\d+))\s*([pnumµkKMG]?)/);if(!match2)return;let numericValue=Number(match2[1]);if(Number.isFinite(numericValue))return numericValue*(SI_PREFIX_MULTIPLIERS[match2[2]??""]??1)},getVoltageProbeGraphDisplayOverrides=probe=>{let{graphDisplayName,graphCenter,graphVerticalOffset,graphVoltagePerDiv}=probe._parsedProps;return{displayName:graphDisplayName,color:probe.color??void 0,center:graphCenter,verticalOffset:parseSimulationGraphValue(graphVerticalOffset),valuePerDiv:parseSimulationGraphValue(graphVoltagePerDiv)}},getAmmeterGraphDisplayOverrides=ammeter=>{let{color:color3,graphDisplayName,graphCenter,graphVerticalOffset,graphCurrentPerDiv}=ammeter._parsedProps;return{displayName:graphDisplayName,color:color3,center:graphCenter,verticalOffset:parseSimulationGraphValue(graphVerticalOffset),valuePerDiv:parseSimulationGraphValue(graphCurrentPerDiv)}},getFiniteBounds=values=>{let min4=Number.POSITIVE_INFINITY,max5=Number.NEGATIVE_INFINITY;for(let value of values)Number.isFinite(value)&&(min4=Math.min(min4,value),max5=Math.max(max5,value));return min4===Number.POSITIVE_INFINITY||max5===Number.NEGATIVE_INFINITY?null:{min:min4,max:max5}},getGraphLevels2=graph=>graph.type==="simulation_transient_current_graph"?graph.current_levels:graph.voltage_levels,DISPLAY_SECTION_HEIGHT_DIVS=2,DISPLAY_SECTION_DATA_FILL=.8,getAutoDisplayScale=({graph,index:index2,graphCount})=>{let bounds=getFiniteBounds(getGraphLevels2(graph));if(!bounds)return null;let center2=(bounds.min+bounds.max)/2,span=bounds.max-bounds.min,valuePerDiv=span>0?span/(DISPLAY_SECTION_HEIGHT_DIVS*DISPLAY_SECTION_DATA_FILL):Math.max(Math.abs(center2)/10,Number.EPSILON);return{display_center_value:center2,display_center_offset_divs:((graphCount-1)/2-index2)*DISPLAY_SECTION_HEIGHT_DIVS,value_per_div:valuePerDiv}},isDefinedString=value=>value!==void 0,getTraceByVoltageProbeId=traces=>{let traceByVoltageProbeId=new Map;for(let trace of traces)trace.simulation_voltage_probe_id&&traceByVoltageProbeId.set(trace.simulation_voltage_probe_id,trace);return traceByVoltageProbeId},getTraceByCurrentProbeId=traces=>{let traceByCurrentProbeId=new Map;for(let trace of traces)trace.simulation_current_probe_id&&traceByCurrentProbeId.set(trace.simulation_current_probe_id,trace);return traceByCurrentProbeId},insertIndependentAxisScopeTraces=({db:db22,graphs,graphDisplayOverridesByProbeId})=>{if(graphs.length===0)return;let existingScopeTraces=db22.simulation_oscilloscope_trace.list(),traceByVoltageProbeId=getTraceByVoltageProbeId(existingScopeTraces),traceByCurrentProbeId=getTraceByCurrentProbeId(existingScopeTraces),graphIdsWithTrace=new Set(existingScopeTraces.flatMap(trace=>[trace.simulation_transient_voltage_graph_id,trace.simulation_transient_current_graph_id]).filter(isDefinedString));for(let[index2,{type,graph}]of graphs.entries()){let scale42=getAutoDisplayScale({graph,index:index2,graphCount:graphs.length});if(!scale42)continue;let graphId=type==="voltage"?graph.simulation_transient_voltage_graph_id:graph.simulation_transient_current_graph_id;if(graphIdsWithTrace.has(graphId))continue;let sourceProbeId=graph.source_probe_id??void 0,probeTrace=sourceProbeId===void 0?void 0:type==="voltage"?traceByVoltageProbeId.get(sourceProbeId):traceByCurrentProbeId.get(sourceProbeId),overrides=sourceProbeId===void 0?void 0:graphDisplayOverridesByProbeId?.get(sourceProbeId),valuePerDiv=overrides?.valuePerDiv??scale42.value_per_div,displayCenter=overrides?.center??scale42.display_center_value,displayCenterOffsetDivs=overrides?.verticalOffset!==void 0&&valuePerDiv!==0?overrides.verticalOffset/valuePerDiv:probeTrace?.display_center_offset_divs??scale42.display_center_offset_divs;db22.simulation_oscilloscope_trace.insert({...type==="voltage"?{simulation_transient_voltage_graph_id:graph.simulation_transient_voltage_graph_id,volts_per_div:valuePerDiv}:{simulation_transient_current_graph_id:graph.simulation_transient_current_graph_id,amps_per_div:valuePerDiv},display_name:overrides?.displayName??probeTrace?.display_name,color:overrides?.color??probeTrace?.color??graph.color,display_center_value:displayCenter,display_center_offset_divs:displayCenterOffsetDivs})}},isCircuitElementInput=element=>!!(element&&typeof element=="object"&&"type"in element),debug12=(0,import_debug20.default)("tscircuit:core:Group_doInitialSimulationSpiceEngineRender"),getCircuitJsonForAnalogSimulation=({circuitJson,simulationExperimentId,voltageProbes,ammeters})=>{let voltageProbeIds=new Set(voltageProbes.map(voltageProbe=>voltageProbe.simulation_voltage_probe_id).filter(simulationVoltageProbeId=>!!simulationVoltageProbeId)),currentProbeIds=new Set(ammeters.map(ammeter=>ammeter.simulation_current_probe_id).filter(simulationCurrentProbeId=>!!simulationCurrentProbeId));return circuitJson.filter(element=>{if(element.type==="simulation_experiment")return element.simulation_experiment_id===simulationExperimentId;if(element.type==="simulation_voltage_probe")return voltageProbeIds.has(element.simulation_voltage_probe_id);if(element.type==="simulation_current_probe")return currentProbeIds.has(element.simulation_current_probe_id);if(element.type==="simulation_parameter_sweep")return element.simulation_experiment_id===simulationExperimentId;if(element.type==="simulation_oscilloscope_trace"){if(element.simulation_voltage_probe_id)return voltageProbeIds.has(element.simulation_voltage_probe_id);if(element.simulation_current_probe_id)return currentProbeIds.has(element.simulation_current_probe_id)}return!(element.type==="simulation_transient_voltage_graph"||element.type==="simulation_transient_current_graph"||element.type==="simulation_dc_operating_point_voltage"||element.type==="simulation_dc_operating_point_current"||element.type==="simulation_dc_sweep_voltage_graph"||element.type==="simulation_dc_sweep_current_graph"||element.type==="simulation_ac_sweep_voltage_graph"||element.type==="simulation_ac_sweep_current_graph"||element.type==="simulation_unknown_experiment_error")})};function Group_doInitialSimulationSpiceEngineRender(group2){if(group2.getInheritedProperty("analogSimulationDisabled")||!group2.isSubcircuit)return;let{root}=group2;if(!root)return;let analogSimulations=[...group2.selectAll("analogsimulation"),...group2.selectAll("analogtransientsimulation"),...group2.selectAll("analogdcoperatingpointsimulation"),...group2.selectAll("analogdcsweepsimulation"),...group2.selectAll("analogacsweepsimulation")];if(analogSimulations.length===0)return;resetSimulationColorState();let spiceEngineMap={...root.platform?.spiceEngineMap};spiceEngineMap.spicey||(spiceEngineMap.spicey=getSpiceyEngine());for(let analogSimulation of analogSimulations){let simulationExperimentId=analogSimulation.simulation_experiment_id;if(!simulationExperimentId){debug12("No simulation experiment id found, skipping simulation");continue}let simulationExperiment=root.db.simulation_experiment.get(simulationExperimentId);if(!simulationExperiment){debug12("No simulation experiment found, skipping simulation");continue}let simulationScope=analogSimulation.getGroup()??group2,voltageProbes=simulationScope.selectAll("voltageprobe"),ammeters=simulationScope.selectAll("ammeter"),circuitJson=getCircuitJsonForAnalogSimulation({circuitJson:root.db.toArray(),simulationExperimentId,voltageProbes,ammeters}),simulationRuns;try{simulationRuns=createSimulationRuns({circuitJson,simulationExperimentId}),debug12(`Generated ${simulationRuns.length} SPICE run(s):
951
951
  ${simulationRuns.map(simulationRun=>simulationRun.spiceString).join(`
952
- `)}`)}catch(error2){debug12(`Failed to convert circuit JSON to SPICE: ${error2}`),root.db.simulation_unknown_experiment_error.insert({simulation_experiment_id:simulationExperimentId,error_type:"simulation_unknown_experiment_error",message:error2 instanceof Error?error2.message:String(error2)});continue}let voltageProbeByGraphName=new Map,voltageProbeById=new Map,graphDisplayOverridesByProbeId=new Map;for(let probe of voltageProbes)probe.finalProbeName&&voltageProbeByGraphName.set(probe.finalProbeName,probe),probe.simulation_voltage_probe_id&&(voltageProbeById.set(probe.simulation_voltage_probe_id,probe),graphDisplayOverridesByProbeId.set(probe.simulation_voltage_probe_id,getVoltageProbeGraphDisplayOverrides(probe)));for(let ammeter of ammeters)ammeter.simulation_current_probe_id&&graphDisplayOverridesByProbeId.set(ammeter.simulation_current_probe_id,getAmmeterGraphDisplayOverrides(ammeter));let scopedCurrentProbeIds=new Set(ammeters.map(ammeter=>ammeter.simulation_current_probe_id).filter(simulationCurrentProbeId=>!!simulationCurrentProbeId)),currentProbeById=new Map,currentProbeByName=new Map;for(let probe of root.db.simulation_current_probe.list().filter(probe2=>scopedCurrentProbeIds.has(probe2.simulation_current_probe_id)))currentProbeById.set(probe.simulation_current_probe_id,probe),probe.name!==void 0&&currentProbeByName.set(probe.name,probe);let orderedSimulationProbes=root.db.simulation_voltage_probe.list().filter(probe=>voltageProbeById.has(probe.simulation_voltage_probe_id)),firstSpiceNetlist=simulationRuns[0]?.spiceNetlist,graphNamesFromNetlist=firstSpiceNetlist?getTransientVoltageGraphNamesFromSpiceNetlist(firstSpiceNetlist):[];if(graphNamesFromNetlist.length===orderedSimulationProbes.length)for(let[simulationProbeIndex,simulationProbe]of orderedSimulationProbes.entries()){let probe=voltageProbeById.get(simulationProbe.simulation_voltage_probe_id),graphName=graphNamesFromNetlist[simulationProbeIndex];probe&&graphName&&voltageProbeByGraphName.set(graphName,probe)}else debug12(`Skipping probe-to-graph order mapping because counts differ: probes=${orderedSimulationProbes.length} graphNames=${graphNamesFromNetlist.length}`);let engineName=analogSimulation.getSpiceEngineName()??"spicey",spiceEngine3=spiceEngineMap[engineName];if(!spiceEngine3)throw new Error(`SPICE engine "${engineName}" not found in platform config. Available engines: ${JSON.stringify(Object.keys(spiceEngineMap).filter(spiceEngineName=>spiceEngineName!=="spicey"))}`);let effectId=`spice-simulation-${engineName}-${simulationExperimentId}`;debug12(`Queueing simulation for spice engine: ${engineName} (id: ${effectId})`),group2._queueAsyncEffect(effectId,async()=>{try{let insertedVoltageGraphs=[],insertedCurrentGraphs=[];for(let simulationRun of simulationRuns){debug12(`Running simulation with engine: ${engineName}`);let simulationResult=await spiceEngine3.simulate(simulationRun.spiceString);debug12(`Simulation completed, received ${simulationResult.simulationResultCircuitJson.length} elements`);for(let simulationResultCircuitElement of simulationResult.simulationResultCircuitJson){if(!isCircuitElementInput(simulationResultCircuitElement)){debug12("Skipping invalid simulation result element");continue}let simulationResultWithSweepCoordinate=attachSweepCoordinateToSimulationResult({simulationResult:simulationResultCircuitElement,simulationParameterSweepCoordinate:simulationRun.simulationParameterSweepCoordinate});if(isVoltageGraph(simulationResultWithSweepCoordinate)){simulationResultWithSweepCoordinate.simulation_experiment_id=simulationExperiment.simulation_experiment_id;let probeMatch=simulationResultWithSweepCoordinate.name?voltageProbeByGraphName.get(simulationResultWithSweepCoordinate.name):void 0;probeMatch&&(simulationResultWithSweepCoordinate.color=probeMatch.color??void 0,simulationResultWithSweepCoordinate.source_probe_id=probeMatch.simulation_voltage_probe_id??void 0)}else if(isSimulationVoltageResult(simulationResultWithSweepCoordinate)){simulationResultWithSweepCoordinate.simulation_experiment_id=simulationExperiment.simulation_experiment_id;let probeMatch=voltageProbeById.get(simulationResultWithSweepCoordinate.simulation_voltage_probe_id)??(simulationResultWithSweepCoordinate.name?voltageProbeByGraphName.get(simulationResultWithSweepCoordinate.name):void 0);probeMatch?.simulation_voltage_probe_id&&(simulationResultWithSweepCoordinate.color=probeMatch.color??void 0,simulationResultWithSweepCoordinate.simulation_voltage_probe_id=probeMatch.simulation_voltage_probe_id)}if(isCurrentGraph2(simulationResultWithSweepCoordinate)){simulationResultWithSweepCoordinate.simulation_experiment_id=simulationExperiment.simulation_experiment_id;let probeMatch=(simulationResultWithSweepCoordinate.source_probe_id?currentProbeById.get(simulationResultWithSweepCoordinate.source_probe_id):void 0)??(simulationResultWithSweepCoordinate.name?currentProbeByName.get(simulationResultWithSweepCoordinate.name):void 0);probeMatch&&(simulationResultWithSweepCoordinate.color=probeMatch.color,simulationResultWithSweepCoordinate.source_probe_id=probeMatch.simulation_current_probe_id)}else if(isSimulationCurrentResult(simulationResultWithSweepCoordinate)){simulationResultWithSweepCoordinate.simulation_experiment_id=simulationExperiment.simulation_experiment_id;let probeMatch=currentProbeById.get(simulationResultWithSweepCoordinate.simulation_current_probe_id)??(simulationResultWithSweepCoordinate.name?currentProbeByName.get(simulationResultWithSweepCoordinate.name):void 0);probeMatch&&(simulationResultWithSweepCoordinate.color=probeMatch.color,simulationResultWithSweepCoordinate.simulation_current_probe_id=probeMatch.simulation_current_probe_id)}let insertedSimulationResult=root.db.insert(simulationResultWithSweepCoordinate);isVoltageGraph(insertedSimulationResult)&&insertedVoltageGraphs.push({type:"voltage",graph:insertedSimulationResult}),isCurrentGraph2(insertedSimulationResult)&&insertedCurrentGraphs.push({type:"current",graph:insertedSimulationResult}),debug12(`Inserted ${simulationResultWithSweepCoordinate.type} into database`)}}analogSimulation.usesIndependentGraphAxes()&&insertIndependentAxisScopeTraces({db:root.db,graphs:[...insertedVoltageGraphs,...insertedCurrentGraphs],graphDisplayOverridesByProbeId}),group2._markDirty("SimulationSpiceEngineRender")}catch(error2){debug12(`Simulation failed for engine ${engineName}: ${error2}`),root.db.simulation_unknown_experiment_error.insert({simulation_experiment_id:simulationExperimentId,error_type:"simulation_unknown_experiment_error",message:error2 instanceof Error?error2.message:String(error2)})}})}}function Group_doInitialSourceAddConnectivityMapKey(group2){if(!group2.isSubcircuit)return;let{db:db22}=group2.root,traces=group2.selectAll("trace"),vias=group2.selectAll("via"),nets=group2.selectAll("net"),connMap=new ConnectivityMap({});connMap.addConnections(traces.map(t48=>{let source_trace3=db22.source_trace.get(t48.source_trace_id);return source_trace3?[source_trace3.source_trace_id,...source_trace3.connected_source_port_ids,...source_trace3.connected_source_net_ids]:null}).filter(c22=>c22!==null));let sourceNets=db22.source_net.list().filter(net=>net.subcircuit_id===group2.subcircuit_id);for(let sourceNet of sourceNets)connMap.addConnections([[sourceNet.source_net_id]]);let{name:subcircuitName}=group2._parsedProps;for(let trace of traces){if(!trace.source_trace_id)continue;let connNetId=connMap.getNetConnectedToId(trace.source_trace_id);connNetId&&(trace.subcircuit_connectivity_map_key=`${subcircuitName??`unnamedsubcircuit${group2.subcircuit_id??group2.source_group_id??group2._renderId}`}_${connNetId}`,db22.source_trace.update(trace.source_trace_id,{subcircuit_connectivity_map_key:trace.subcircuit_connectivity_map_key}))}let allSourcePortIds=new Set;for(let trace of traces){if(!trace.source_trace_id)continue;let source_trace3=db22.source_trace.get(trace.source_trace_id);if(source_trace3)for(let id3 of source_trace3.connected_source_port_ids)allSourcePortIds.add(id3)}for(let portId of allSourcePortIds){let connNetId=connMap.getNetConnectedToId(portId);if(!connNetId)continue;let connectivityMapKey=`${subcircuitName??`unnamedsubcircuit${group2.subcircuit_id??group2.source_group_id??group2._renderId}`}_${connNetId}`;db22.source_port.update(portId,{subcircuit_connectivity_map_key:connectivityMapKey})}let allSourceNetIds=new Set;for(let trace of traces){if(!trace.source_trace_id)continue;let source_trace3=db22.source_trace.get(trace.source_trace_id);if(source_trace3)for(let source_net_id of source_trace3.connected_source_net_ids)allSourceNetIds.add(source_net_id)}for(let sourceNet of sourceNets)allSourceNetIds.add(sourceNet.source_net_id);for(let netId of allSourceNetIds){let connNetId=connMap.getNetConnectedToId(netId);if(!connNetId)continue;let connectivityMapKey=`${subcircuitName??`unnamedsubcircuit${group2.subcircuit_id??group2.source_group_id??group2._renderId}`}_${connNetId}`;db22.source_net.update(netId,{subcircuit_connectivity_map_key:connectivityMapKey});let netInstance=nets.find(n22=>n22.source_net_id===netId);netInstance&&(netInstance.subcircuit_connectivity_map_key=connectivityMapKey)}for(let via of vias){let connectedNetOrTrace=via._getConnectedNetOrTrace();connectedNetOrTrace&&connectedNetOrTrace.subcircuit_connectivity_map_key&&(via.subcircuit_connectivity_map_key=connectedNetOrTrace.subcircuit_connectivity_map_key)}}var Group_doInitialStandaloneSubcircuitPcbDesignRuleChecks=group2=>{let isRootSubcircuit=group2.root?.firstChild===group2;if(!group2.isSubcircuit||!isRootSubcircuit||group2._getBoard())return;let routingDisabled=group2.root?.pcbRoutingDisabled||group2.getInheritedProperty("routingDisabled"),drcChecksDisabled=group2.root?.platform?.drcChecksDisabled??group2.getInheritedProperty("drcChecksDisabled"),routingDrcChecksDisabled=group2.root?.platform?.routingDrcChecksDisabled??group2.getInheritedProperty("routingDrcChecksDisabled");if(group2.root?.pcbDisabled||routingDisabled||drcChecksDisabled||routingDrcChecksDisabled||group2._hasIncompleteAsyncEffectsInSubtreeForPhase("PcbTraceRender")||group2._hasTracesToRoute()&&!group2._areChildSubcircuitsRouted()||group2._standaloneSubcircuitDrcChecksComplete||group2._standaloneSubcircuitDrcChecksInProgress)return;let{db:db22}=group2.root,subcircuitCircuitJson=db22.subtree({subcircuit_id:group2.subcircuit_id}).toArray();group2._standaloneSubcircuitDrcChecksInProgress=!0,group2._queueAsyncEffect("standalone-subcircuit:routing-drc-checks",async()=>{try{let results=await runAllRoutingChecks(subcircuitCircuitJson);db22.insertAll(dedupePcbDrcErrors(results)),group2._standaloneSubcircuitDrcChecksComplete=!0}finally{group2._standaloneSubcircuitDrcChecksInProgress=!1}})},addPourNetMap=(target,pourNetMap)=>{for(let[layer,netOrNets]of Object.entries(pourNetMap)){if(!netOrNets)continue;let nets=Array.isArray(netOrNets)?netOrNets:[netOrNets],layerNets=target.get(layer)??new Set;for(let net of nets)layerNets.add(net);target.set(layer,layerNets)}},toFanoutPourNetMap=netsByLayer=>Object.fromEntries(Array.from(netsByLayer,([layer,nets])=>[layer,nets.size===1?Array.from(nets)[0]:Array.from(nets)])),Group_getFanoutPourNetMap=(group2,routingPhasePlans)=>{let explicitMaps=routingPhasePlans.map(plan=>plan.fanoutPourNetMap).filter(map=>map!==void 0),netsByLayer=new Map;if(explicitMaps.length>0){for(let explicitMap of explicitMaps)addPourNetMap(netsByLayer,explicitMap);return toFanoutPourNetMap(netsByLayer)}let scope=group2;for(;scope;){if(scope.isSubcircuit){let subcircuit=scope,copperPours=subcircuit.selectAll("copperpour");for(let copperPour of copperPours){if(copperPour.getSubcircuit()!==subcircuit)continue;let{layer,connectsTo}=copperPour._parsedProps;addPourNetMap(netsByLayer,{[layer]:connectsTo})}}scope=scope.parent}return netsByLayer.size>0?toFanoutPourNetMap(netsByLayer):void 0},baseBreakoutPointProps=pcbLayoutProps.omit({pcbRotation:!0,layer:!0}),BaseBreakoutPoint=class extends PrimitiveComponent2{constructor(){super(...arguments);__publicField(this,"pcb_breakout_point_id",null);__publicField(this,"matchedPort",null);__publicField(this,"matchedNet",null);__publicField(this,"matchedSourceTraceId",null);__publicField(this,"isPcbPrimitive",!0)}_getSourceTraceIdForPort(port){let{db:db22}=this.root;return db22.source_trace.list().find(st22=>st22.connected_source_port_ids.includes(port.source_port_id))?.source_trace_id}_getSourceNetIdForPort(port){let{db:db22}=this.root;return db22.source_trace.list().find(st22=>st22.connected_source_port_ids.includes(port.source_port_id))?.connected_source_net_ids[0]}_renderPcbBreakoutPoint({layer}={}){if(this.pcb_breakout_point_id||this.root?.pcbDisabled)return;let{db:db22}=this.root,position4=this._getGlobalPcbPositionBeforeLayout(),group2=this.parent?.getGroup(),subcircuit=this.getSubcircuit();if(!group2||!group2.pcb_group_id)return;let pcb_breakout_point3=db22.pcb_breakout_point.insert({pcb_group_id:group2.pcb_group_id,subcircuit_id:subcircuit?.subcircuit_id??void 0,source_port_id:this.matchedPort?.source_port_id??void 0,source_trace_id:this.matchedPort?this.matchedSourceTraceId??this._getSourceTraceIdForPort(this.matchedPort):void 0,source_net_id:this.matchedNet?this.matchedNet.source_net_id:this.matchedPort?this._getSourceNetIdForPort(this.matchedPort):void 0,layer,x:position4.x,y:position4.y});this.pcb_breakout_point_id=pcb_breakout_point3.pcb_breakout_point_id}_getPcbCircuitJsonBounds(){let position4=this._getGlobalPcbPositionBeforeLayout();return{center:{x:position4.x,y:position4.y},bounds:{left:position4.x,top:position4.y,right:position4.x,bottom:position4.y},width:0,height:0}}_setPositionFromLayout(newCenter){let{db:db22}=this.root;if(!this.pcb_breakout_point_id)return;let updatedProperties={x:newCenter.x,y:newCenter.y};this.matchedSourceTraceId&&(updatedProperties.source_trace_id=this.matchedSourceTraceId),db22.pcb_breakout_point.update(this.pcb_breakout_point_id,updatedProperties)}_moveCircuitJsonElements({deltaX,deltaY}){if(this.root?.pcbDisabled)return;let{db:db22}=this.root;if(!this.pcb_breakout_point_id)return;let point62=db22.pcb_breakout_point.get(this.pcb_breakout_point_id);point62&&db22.pcb_breakout_point.update(this.pcb_breakout_point_id,{x:point62.x+deltaX,y:point62.y+deltaY})}getPcbSize(){return{width:0,height:0}}},BreakoutPoint=class extends BaseBreakoutPoint{get config(){return{componentName:"BreakoutPoint",zodProps:breakoutPointProps}}_matchConnection(){if(this.matchedPort)return;let{connection}=this._parsedProps,subcircuit=this.getSubcircuit();subcircuit&&(this.matchedPort=subcircuit.selectOne(connection,{type:"port"}),this.matchedPort||(this.matchedNet=subcircuit.selectOne(connection,{type:"net"})),!this.matchedPort&&!this.matchedNet&&this.renderError(`Could not find connection target "${connection}"`))}doInitialPcbPrimitiveRender(){this._matchConnection(),this._renderPcbBreakoutPoint()}},SavedFanoutPoint=class extends BreakoutPoint{constructor(){super(...arguments);__publicField(this,"exitLayer","top")}doInitialPcbPrimitiveRender(){this._matchConnection(),this._renderPcbBreakoutPoint({layer:this.exitLayer})}};function getSavedFanoutTraces(breakout,input2){let{db:db22}=breakout.root,boardLayers=getViaBoardLayers(input2.layerCount),coveredConnections=new Set,exits=breakout.children.filter(child=>child instanceof SavedFanoutPoint),traces=(breakout._parsedProps.pcbTracePaths??[]).map((path,pathIndex)=>{for(let point62 of path.route)if((point62.route_type==="wire"?[point62.layer]:[point62.from_layer,point62.to_layer]).some(layer=>!boardLayers.includes(layer)))throw new Error(`Saved fanout path "${path.connection}" uses a layer unavailable on this board`);let exit=exits[pathIndex],port=exit.matchedPort,connection=input2.connections.find(connection2=>connection2.pointsToConnect.some(point62=>point62.pcb_port_id===port.pcb_port_id));if(!connection)throw new Error(`No fanout connection for saved path "${path.connection}"`);let pcbExit=db22.pcb_breakout_point.get(exit.pcb_breakout_point_id),localExit=path.route.at(-1),transform7=compose2(exit._computePcbGlobalTransformBeforeLayout(),translate2(-localExit.x,-localExit.y)),originalExit=applyToPoint2(transform7,localExit),route2=resolveSavedTraceRouteWidths(path.route).map(point62=>{let position4=applyToPoint2(transform7,point62);return{...point62,x:position4.x+pcbExit.x-originalExit.x,y:position4.y+pcbExit.y-originalExit.y}}),first=route2[0],firstLayer=first.route_type==="wire"?first.layer:first.from_layer,portPosition=port._getGlobalPcbPositionAfterLayout();if(Math.hypot(first.x-portPosition.x,first.y-portPosition.y)>1e-4||!port.getAvailablePcbLayers().includes(firstLayer))throw new Error(`Saved fanout path "${path.connection}" must start at its PCB port on an available layer`);if(first.route_type==="via"&&!input2.allowViaInPad)throw new Error(`Saved fanout path "${path.connection}" starts with a via at a pad; enable allowViaInPad`);let last=route2.at(-1),lastLayer=last.route_type==="wire"?last.layer:last.to_layer,endpoints=[{...first,layer:firstLayer},{...last,layer:lastLayer}];if(connection.pointsToConnect.some(point62=>!endpoints.some(endpoint=>Math.hypot(point62.x-endpoint.x,point62.y-endpoint.y)<1e-4&&point62.layer===endpoint.layer)))throw new Error(`Saved fanout path "${path.connection}" does not cover its connection endpoints`);let startContactWidths=getSavedTraceViaContactWidths(route2,0,input2.minTraceWidth),endContactWidths=getSavedTraceViaContactWidths(route2,route2.length-1,input2.minTraceWidth);return first.route_type==="via"&&(route2.splice(1,0,{route_type:"wire",x:first.x,y:first.y,layer:first.to_layer,width:startContactWidths.toWidth}),route2.unshift({route_type:"wire",x:first.x,y:first.y,layer:first.from_layer,width:startContactWidths.fromWidth})),last.route_type==="via"&&(route2.splice(route2.length-1,0,{route_type:"wire",x:last.x,y:last.y,layer:last.from_layer,width:endContactWidths.fromWidth}),route2.push({route_type:"wire",x:last.x,y:last.y,layer:last.to_layer,width:endContactWidths.toWidth})),last.route_type==="via"&&route2.push({route_type:"wire",x:last.x,y:last.y,layer:last.to_layer,width:endContactWidths.toWidth}),coveredConnections.add(connection),{type:"pcb_trace",pcb_trace_id:`saved_fanout_${breakout.pcb_group_id}_${pathIndex}`,connection_name:connection.name,source_trace_id:connection.source_trace_id,connectsTo:[connection.source_trace_id,...connection.pointsToConnect.map(point62=>point62.pointId)].filter(id3=>!!id3),route:route2}}),missing=input2.connections.filter(connection=>!coveredConnections.has(connection));if(missing.length)throw new Error(`pcbTracePaths must cover every fanout connection; missing: ${missing.map(connection=>connection.name).join(", ")}`);return traces}function getPhaseSortValue(routingPhaseIndex){return routingPhaseIndex===null?Number.POSITIVE_INFINITY:routingPhaseIndex}function compareRoutingPhasePlans(a22,b22){return getPhaseSortValue(a22.routingPhaseIndex)-getPhaseSortValue(b22.routingPhaseIndex)}function getOrCreateRoutingPhasePlan(plansByPhaseIndex,routingPhaseIndex){let plan=plansByPhaseIndex.get(routingPhaseIndex);return plan||(plan={routingPhaseIndex,nets:[],traces:[]},plansByPhaseIndex.set(routingPhaseIndex,plan)),plan}function getNetRoutingPhaseIndex(net){return net.props.routingPhaseIndex??null}function getTraceRoutingPhaseIndex(trace,buses=[]){let busRoutingPhaseIndexes=new Set;for(let bus of buses){if(bus._parsedProps.routingPhaseIndex===void 0)continue;bus._parsedProps.connections.some(connection=>connection===trace.name||traceHasEndpointMatchingConnectionSelector(trace,convertPortSelectorToEndpointKey(connection)))&&busRoutingPhaseIndexes.add(bus._parsedProps.routingPhaseIndex)}if(busRoutingPhaseIndexes.size>1)throw new Error(`Trace "${trace.name}" belongs to buses with different routing phases`);let busRoutingPhaseIndex=busRoutingPhaseIndexes.values().next().value;if(busRoutingPhaseIndex!==void 0)return busRoutingPhaseIndex;let traceRoutingPhaseIndex=trace.props.routingPhaseIndex;if(traceRoutingPhaseIndex!==void 0)return traceRoutingPhaseIndex;let routingPhaseIndex=null,connectedNets=trace._findConnectedNets().nets;for(let net of connectedNets){let netRoutingPhaseIndex=getNetRoutingPhaseIndex(net);typeof netRoutingPhaseIndex=="number"&&(routingPhaseIndex===null||netRoutingPhaseIndex<routingPhaseIndex)&&(routingPhaseIndex=netRoutingPhaseIndex)}return routingPhaseIndex}function convertPortSelectorToEndpointKey(selector2){return selector2.trim().replace(/\s*>\s*/g,".").replace(/\s+/g,".").replace(/^\./,"").replace(/\.\./g,".")}function getConnectionSelectorsFromAutoroutingPhaseProps(phaseProps){return phaseProps.connection===void 0&&phaseProps.connections===void 0?phaseProps.pcbTracePaths?.map(path=>path.connection)??[]:[...phaseProps.connection?[phaseProps.connection]:[],...phaseProps.connections??[]]}function traceHasEndpointMatchingConnectionSelector(trace,connectionSelectorEndpointKey){if(trace.getTracePortPathSelectors().some(selector2=>convertPortSelectorToEndpointKey(selector2)===connectionSelectorEndpointKey))return!0;let port=trace.getSubcircuit().selectOne(connectionSelectorEndpointKey,{type:"port"});return port!==null&&(trace._findConnectedPorts().ports?.includes(port)??!1)}function getAutoroutersByPhaseIndex(group2){let autoroutingPhases=group2.selectAll("autoroutingphase"),autoroutersByPhaseIndex=new Map;for(let autoroutingPhase of autoroutingPhases){let{phaseIndex,autorouter}=autoroutingPhase._parsedProps;autorouter!==void 0&&autoroutersByPhaseIndex.set(phaseIndex??null,autorouter)}return autoroutersByPhaseIndex}function getAutoroutingPhasePropsByPhaseIndex(group2){let autoroutingPhases=group2.selectAll("autoroutingphase"),propsByPhaseIndex=new Map;for(let autoroutingPhase of autoroutingPhases){let props=autoroutingPhase._parsedProps;propsByPhaseIndex.set(props.phaseIndex??null,props)}return propsByPhaseIndex}function toParsedDistance(value){if(value!==void 0)return Number(value)}function getDrcTolerancesFromAutoroutingPhaseProps(phaseProps){let{minTraceWidth,minViaHoleEdgeToViaHoleEdgeClearance,minPlatedHoleDrillEdgeToDrillEdgeClearance,minTraceToPadEdgeClearance,minTraceToHoleEdgeClearance,minPadEdgeToPadEdgeClearance,minBoardEdgeClearance,minViaEdgeToPadEdgeClearance,minViaHoleDiameter,minViaPadDiameter}=phaseProps;if(!(minTraceWidth===void 0&&minViaHoleEdgeToViaHoleEdgeClearance===void 0&&minPlatedHoleDrillEdgeToDrillEdgeClearance===void 0&&minTraceToPadEdgeClearance===void 0&&minTraceToHoleEdgeClearance===void 0&&minPadEdgeToPadEdgeClearance===void 0&&minBoardEdgeClearance===void 0&&minViaEdgeToPadEdgeClearance===void 0&&minViaHoleDiameter===void 0&&minViaPadDiameter===void 0))return{minTraceWidth:toParsedDistance(minTraceWidth),minViaHoleEdgeToViaHoleEdgeClearance:toParsedDistance(minViaHoleEdgeToViaHoleEdgeClearance),minPlatedHoleDrillEdgeToDrillEdgeClearance:toParsedDistance(minPlatedHoleDrillEdgeToDrillEdgeClearance),minTraceToPadEdgeClearance:toParsedDistance(minTraceToPadEdgeClearance),minTraceToHoleEdgeClearance:toParsedDistance(minTraceToHoleEdgeClearance),minPadEdgeToPadEdgeClearance:toParsedDistance(minPadEdgeToPadEdgeClearance),minBoardEdgeClearance:toParsedDistance(minBoardEdgeClearance),minViaEdgeToPadEdgeClearance:toParsedDistance(minViaEdgeToPadEdgeClearance),minViaHoleDiameter:toParsedDistance(minViaHoleDiameter),minViaPadDiameter:toParsedDistance(minViaPadDiameter)}}function Group_getRoutingPhasePlans(group2){let traces=group2.selectAll("trace"),nets=group2.selectAll("net"),buses=group2.selectAll("bus"),breakouts=group2.selectAll("group").filter(candidate=>candidate.isRoutingDirective),breakoutByTrace=new Map,breakoutByNet=new Map;for(let trace of traces){let ancestor=trace.parent;for(;ancestor&&ancestor!==group2;){if(ancestor.isRoutingDirective){breakoutByTrace.set(trace,ancestor);break}ancestor=ancestor.parent}}for(let net of nets)net.parent?.isRoutingDirective&&breakouts.includes(net.parent)&&breakoutByNet.set(net,net.parent);let plansByPhaseIndex=new Map,autoroutersByPhaseIndex=getAutoroutersByPhaseIndex(group2),phasePropsByPhaseIndex=getAutoroutingPhasePropsByPhaseIndex(group2),groupFanoutProps=group2._parsedProps,routeRemaining=group2.getInheritedProperty("routeRemaining")!==!1,defaultPhaseProps=phasePropsByPhaseIndex.get(null),includeUnassignedConnections=routeRemaining||defaultPhaseProps!==void 0&&!defaultPhaseProps.reroute&&getConnectionSelectorsFromAutoroutingPhaseProps(defaultPhaseProps).length===0,hasDirectRoutingTargets=traces.length>0||nets.length>0,hasReroutePhase=Array.from(phasePropsByPhaseIndex.values()).some(phaseProps=>phaseProps.reroute),hasConnectionTargetedPhase=Array.from(phasePropsByPhaseIndex.values()).some(phaseProps=>getConnectionSelectorsFromAutoroutingPhaseProps(phaseProps).length>0);if(!hasDirectRoutingTargets&&!hasReroutePhase&&!hasConnectionTargetedPhase&&breakouts.length===0)return[];for(let net of nets){if(breakoutByNet.has(net))continue;let routingPhaseIndex=getNetRoutingPhaseIndex(net);routingPhaseIndex===null&&!includeUnassignedConnections||getOrCreateRoutingPhasePlan(plansByPhaseIndex,routingPhaseIndex).nets.push(net)}for(let trace of traces){if(breakoutByTrace.has(trace))continue;let routingPhaseIndex=getTraceRoutingPhaseIndex(trace,buses);routingPhaseIndex===null&&!includeUnassignedConnections||getOrCreateRoutingPhasePlan(plansByPhaseIndex,routingPhaseIndex).traces.push(trace)}for(let[phaseIndex,phaseProps]of phasePropsByPhaseIndex){let connectionSelectors=getConnectionSelectorsFromAutoroutingPhaseProps(phaseProps);if(connectionSelectors.length>0){let plan=getOrCreateRoutingPhasePlan(plansByPhaseIndex,phaseIndex),connectionSelectorEndpointKeys=connectionSelectors.map(convertPortSelectorToEndpointKey);plan.connectionSelectors=connectionSelectors;for(let trace of traces)if(!breakoutByTrace.has(trace)&&connectionSelectorEndpointKeys.some(endpointKey=>traceHasEndpointMatchingConnectionSelector(trace,endpointKey))){if(!phaseProps.reroute)for(let existingPlan of plansByPhaseIndex.values())existingPlan!==plan&&(existingPlan.traces=existingPlan.traces.filter(existingTrace=>existingTrace!==trace));if(plan.traces.includes(trace))continue;plan.traces.push(trace)}}(phaseProps.reroute||phaseProps.pcbTracePaths!==void 0)&&getOrCreateRoutingPhasePlan(plansByPhaseIndex,phaseIndex)}let plans=Array.from(plansByPhaseIndex.values()).sort(compareRoutingPhasePlans);for(let plan of plans){plan.autorouter=autoroutersByPhaseIndex.get(plan.routingPhaseIndex);let phaseProps=phasePropsByPhaseIndex.get(plan.routingPhaseIndex);plan.algorithmFn=phaseProps?.algorithmFn,plan.isImplicitRemainingPhase=plan.routingPhaseIndex===null&&phaseProps===void 0,plan.phaseName=phaseProps?.name,plan.reroute=phaseProps?.reroute,plan.region=phaseProps?.region,plan.connectionSelectors=phaseProps?getConnectionSelectorsFromAutoroutingPhaseProps(phaseProps):void 0,plan.busFanoutDirections=phaseProps?.busFanoutDirections??groupFanoutProps.busFanoutDirections,plan.fanoutBoundaryPadding=phaseProps?.fanoutBoundaryPadding??groupFanoutProps.fanoutBoundaryPadding;let fanoutRoutingLayers=phaseProps?.fanoutRoutingLayers??groupFanoutProps.fanoutRoutingLayers;plan.fanoutRoutingLayers=fanoutRoutingLayers?.map(layer=>typeof layer=="string"?layer:layer.name),plan.fanoutPourNetMap=phaseProps?.fanoutPourNetMap??groupFanoutProps.fanoutPourNetMap,plan.drcTolerances=phaseProps?getDrcTolerancesFromAutoroutingPhaseProps(phaseProps):void 0}for(let phase of group2.selectAll("autoroutingphase")){let plan=plansByPhaseIndex.get(phase._parsedProps.phaseIndex??null);if(!plan||(plan.autoroutingPhase=phase,phase._parsedProps.pcbTracePaths===void 0))continue;let config=plan.autorouter!==void 0?getPresetAutoroutingConfig(plan.autorouter,group2.root?.platform):group2._getAutorouterConfig(),isFanout=["fanout","single_layer_fanout"].includes(config.preset??"");plan.getPrecomputedRoutingResult=input2=>getSavedAutoroutingPhaseTraces(phase,input2,isFanout)}let breakoutPlans=[];for(let breakout of breakouts){let breakoutProps22=breakout._parsedProps,shouldUseDefaultAutorouterForBreakoutPoints=breakout.children.some(child=>child instanceof BreakoutPoint)&&breakout.props.autorouter===void 0,breakoutTraces=traces.filter(trace=>breakoutByTrace.get(trace)===breakout),unroutedBreakoutTraces=breakoutTraces.filter(trace=>!trace.pcb_trace_id),pcbGroup=breakout.pcb_group_id?breakout.root?.db.pcb_group.get(breakout.pcb_group_id):null,outlineBounds=pcbGroup?.outline?getBoundsFromPoints(pcbGroup.outline):null,routingWidth=pcbGroup?.width??(outlineBounds?outlineBounds.maxX-outlineBounds.minX:void 0),routingHeight=pcbGroup?.height??(outlineBounds?outlineBounds.maxY-outlineBounds.minY:void 0),routingBounds2=pcbGroup&&routingWidth&&routingHeight?{minX:pcbGroup.center.x-routingWidth/2,maxX:pcbGroup.center.x+routingWidth/2,minY:pcbGroup.center.y-routingHeight/2,maxY:pcbGroup.center.y+routingHeight/2}:void 0,rawBreakoutProps=breakout.props,hasExplicitGeometry=rawBreakoutProps.width!==void 0||rawBreakoutProps.height!==void 0||!!rawBreakoutProps.outline?.length,hasExplicitFanoutBoundaryPadding=rawBreakoutProps.fanoutBoundaryPadding!==void 0,breakoutPlan={routingPhaseIndex:null,routingPcbGroupId:breakout.pcb_group_id??void 0,fanoutRegionPcbGroupId:breakout.pcb_group_id??void 0,routingBounds:routingBounds2,fanoutBounds:hasExplicitGeometry?routingBounds2:hasExplicitFanoutBoundaryPadding?void 0:routingBounds2,autorouter:breakoutProps22.autorouter??"fanout",busFanoutDirections:breakoutProps22.busFanoutDirections,fanoutBoundaryPadding:breakoutProps22.fanoutBoundaryPadding,fanoutRoutingLayers:breakoutProps22.fanoutRoutingLayers?.map(layer=>typeof layer=="string"?layer:layer.name),fanoutPourNetMap:breakoutProps22.fanoutPourNetMap,nets:nets.filter(net=>breakoutByNet.get(net)===breakout),traces:breakoutTraces};if(breakout.isDogboneFanout&&breakoutProps22.pcbTracePaths===void 0){breakoutPlans.push({...breakoutPlan,routingBounds:void 0,fanoutBounds:routingBounds2});continue}if(breakout._parsedProps.pcbTracePaths!==void 0){breakoutPlans.push({...breakoutPlan,autorouter:{local:!0,groupMode:"subcircuit",allowViaInPad:(typeof breakoutProps22.autorouter=="object"?breakoutProps22.autorouter.allowViaInPad:void 0)??group2._getAutorouterConfig().allowViaInPad},getPrecomputedRoutingResult:input2=>({traces:getSavedFanoutTraces(breakout,input2)})});continue}if(!shouldUseDefaultAutorouterForBreakoutPoints){breakoutPlans.push(breakoutPlan);continue}if(breakoutPlans.push({...breakoutPlan,autorouter:"default",traces:[]}),unroutedBreakoutTraces.length>0){let automaticFanoutBusIds=new Set(buses.filter(bus=>unroutedBreakoutTraces.some(trace=>bus._parsedProps.connections.some(connection=>connection===trace.name||traceHasEndpointMatchingConnectionSelector(trace,convertPortSelectorToEndpointKey(connection))))).map(bus=>bus.name));for(let trace of unroutedBreakoutTraces)trace.name&&automaticFanoutBusIds.add(trace.name);let automaticBusFanoutDirections=breakoutProps22.busFanoutDirections?Object.fromEntries(Object.entries(breakoutProps22.busFanoutDirections).filter(([busId])=>automaticFanoutBusIds.has(busId))):void 0;breakoutPlans.push({...breakoutPlan,routingPcbGroupId:void 0,busFanoutDirections:automaticBusFanoutDirections,traces:unroutedBreakoutTraces})}}if(routeRemaining&&hasDirectRoutingTargets&&phasePropsByPhaseIndex.size===1&&defaultPhaseProps?.reroute&&plans.length===1&&plans[0]?.routingPhaseIndex===null){let reroutePlan=plans[0];return[...breakoutPlans,{routingPhaseIndex:null,isImplicitRemainingPhase:!0,nets:[...reroutePlan.nets],traces:[...reroutePlan.traces]},reroutePlan]}return[...breakoutPlans,...plans]}var RoutingPhasePreparationError=class extends Error{},package_default3={name:"@tscircuit/core",type:"module",version:"0.0.2128",types:"dist/index.d.ts",main:"dist/index.js",module:"dist/index.js",exports:{".":{import:"./dist/index.js",types:"./dist/index.d.ts"}},files:["dist"],repository:{type:"git",url:"https://github.com/tscircuit/core"},scripts:{build:"tsup-node",format:"biome format . --write","measure-bundle":"howfat -r table .","pkg-pr-new-release":"bunx pkg-pr-new publish --comment=off --peerDeps","smoke-test:dist":"bun run scripts/smoke-tests/test-dist-simple-circuit.tsx && bun run scripts/smoke-tests/check-dist-bundled-schematic-solver.ts","build:benchmarking":"bun build --experimental-html ./benchmarking/website/index.html --outdir ./benchmarking-dist","build:benchmarking:watch":`chokidar "./{benchmarking,lib}/**/*.{ts,tsx}" -c 'bun build --experimental-html ./benchmarking/website/index.html --outdir ./benchmarking-dist'`,"start:benchmarking":'concurrently "bun run build:benchmarking:watch" "live-server ./benchmarking-dist"',"generate-test-plan":"bun run scripts/generate-test-plan.ts"},devDependencies:{"@biomejs/biome":"^1.8.3","@jscad/modeling":"^2.13.0","@resvg/resvg-js":"^2.6.2","@tsci/tscircuit.ti":"github:tscircuit/ti#57e314be4b2b06bc546d4def7453e619604d1157","@tscircuit/alphabet":"0.0.25","@tscircuit/bga-fanout-solver":"github:tscircuit/bga-fanout-solver#247c835cb8d69b65e53891dcf869731079415b39","@tscircuit/bus-lanes-solver":"https://jscdn.tscircuit.com/@tscircuit/bus-lanes-solver/0.0.21.tgz","@tscircuit/cableprinter":"^0.0.6","@tscircuit/capacity-autorouter":"^0.0.965","@tscircuit/checks":"^0.0.247","@tscircuit/circuit-json-util":"^0.0.119","@tscircuit/common":"^0.0.20","@tscircuit/copper-pour-solver":"^0.0.67","@tscircuit/create-fdm-enclosure":"0.0.4","@tscircuit/dogbone-solver":"https://jscdn.tscircuit.com/@tscircuit/dogbone-solver/0.0.1.tgz","@tscircuit/fanout-solver":"0.0.78","@tscircuit/flex-utils":"https://jscdn.tscircuit.com/@tscircuit/flex-utils/0.0.8.tgz","@tscircuit/footprinter":"^0.0.431","@tscircuit/image-utils":"^0.0.8","@tscircuit/implicit-copper-pour-solver":"github:tscircuit/implicit-copper-pour-solver#a5cbbda0cd65fd4707c5c1af25779837c25aba92","@tscircuit/infer-cable-insertion-point":"^0.0.4","@tscircuit/infgrid-ijump-astar":"^0.0.35","@tscircuit/jlcpcb-manufacturing-specs":"git+https://github.com/tscircuit/jlcpcb-manufacturing-specs#23260504fceffff2d64bf11720f74e974d1d9321","@tscircuit/krt-wasm":"^0.1.1","@tscircuit/log-soup":"^1.0.2","@tscircuit/matchpack":"^0.0.97","@tscircuit/math-utils":"^0.0.36","@tscircuit/miniflex":"^0.0.4","@tscircuit/modelprinter":"^0.0.18","@tscircuit/ngspice-spice-engine":"^0.0.20","@tscircuit/props":"^0.0.698","@tscircuit/schematic-match-adapt":"^0.0.18","@tscircuit/schematic-trace-solver":"https://jscdn.tscircuit.com/@tscircuit/schematic-trace-solver/0.0.230.tgz","@tscircuit/solver-utils":"^0.0.16","@tscircuit/soup-util":"^0.0.41","@tscircuit/via-stitch-solver":"github:tscircuit/via-stitch-solver#64f2ac7781b795bdc0d74ba411988e60767fa653","@tscircuit/winding-breakout-point-solver":"github:tscircuit/winding-breakout-point-solver#202dbe9eb0088633b6fa094120dba6f2f41f8803","@types/bun":"^1.2.16","@types/debug":"^4.1.12","@types/react":"^19.1.8","@types/react-dom":"^19.1.6","@types/react-reconciler":"^0.28.9","bpc-graph":"^0.0.57","bun-match-svg":"0.0.12","calculate-elbow":"^0.0.12","chokidar-cli":"^3.0.0","circuit-json":"^0.0.525","circuit-json-to-bpc":"^0.0.13","circuit-json-to-connectivity-map":"^0.0.33","circuit-json-to-gltf":"^0.0.151","circuit-json-to-spice":"^0.0.45","circuit-to-svg":"^0.0.445",concurrently:"^9.1.2","connectivity-map":"^1.0.1",debug:"^4.3.6",flatbush:"^4.5.0","graphics-debug":"^0.0.95",howfat:"^0.3.8","kicad-to-circuit-json":"^0.0.142",kicadts:"^0.0.53","live-server":"^1.2.2",minicssgrid:"^0.0.9","pkg-pr-new":"^0.0.37",poppygl:"0.0.34",react:"^19.1.0","react-dom":"^19.1.0","schematic-symbols":"^0.0.248",spicets:"^0.0.4",spicey:"^0.0.14","stack-svgs":"^0.0.1","ts-expect":"^1.3.0",tsup:"^8.2.4"},peerDependencies:{"@tscircuit/capacity-autorouter":"*","@tscircuit/checks":"*","@tscircuit/circuit-json-util":"*","@tscircuit/create-fdm-enclosure":"*","@tscircuit/footprinter":"*","@tscircuit/infgrid-ijump-astar":"*","@tscircuit/math-utils":"*","@tscircuit/modelprinter":"*","@tscircuit/props":"*","@tscircuit/schematic-match-adapt":"*","circuit-json-to-bpc":"*","bpc-graph":"*","@tscircuit/matchpack":"*","circuit-json":"*","circuit-json-to-connectivity-map":"*","circuit-json-to-spice":"*","schematic-symbols":"*",spicets:"*",typescript:"^5.0.0","@tscircuit/cableprinter":"*"},dependencies:{"@flatten-js/core":"^1.6.2","@lume/kiwi":"^0.4.3","calculate-cell-boundaries":"^0.0.25","calculate-packing":"^0.0.90","css-select":"5.1.0","format-si-unit":"^0.0.12","gl-matrix":"^3.4.4",nanoid:"^5.0.7","performance-now":"^2.1.0","react-reconciler":"^0.32.0","svg-path-commander":"^2.1.11","transformation-matrix":"^2.16.1",zod:"^3.25.67","jscad-planner":"^0.0.18","jscad-fiber":"^0.0.88"},overrides:{"@tscircuit/circuit-json-util":"^0.0.119","@tscircuit/props":"^0.0.698","circuit-json":"^0.0.525","@tscircuit/cableprinter":"^0.0.6"}},getFnv1aHash=value=>{let hash=2166136261;for(let i22=0;i22<value.length;i22++)hash^=value.charCodeAt(i22),hash=Math.imul(hash,16777619);return hash>>>0},getJsonHash=value=>{let serializedValue=JSON.stringify(value),hash1=getFnv1aHash(serializedValue),hash2=getFnv1aHash(`${serializedValue}${hash1}`);return`${hash1.toString(16).padStart(8,"0")}${hash2.toString(16).padStart(8,"0")}`},getLocalAutoroutingCacheKey=(simpleRouteJson,solverOptions)=>`routes:core@${package_default3.version}:solver:${getJsonHash(solverOptions)}:srj:${getJsonHash(simpleRouteJson)}`,getCachedLocalAutoroutingPhaseResult=async({cacheEngine,cacheKey})=>{if(!cacheEngine)return null;try{let cachedResult=await cacheEngine.getItem(cacheKey);if(!cachedResult)return null;let parsedResult=JSON.parse(cachedResult);return!parsedResult||!Array.isArray(parsedResult.traces)?null:parsedResult}catch{return null}},cacheLocalAutoroutingPhaseResult=async({cacheEngine,cacheKey,result})=>{if(cacheEngine)try{await cacheEngine.setItem(cacheKey,JSON.stringify(result))}catch{}},SRJ_POINT_POSITION_TOLERANCE_MM=1e-6,srjPointsHaveSamePointId=(first,second)=>first.pointId!==void 0&&second.pointId!==void 0&&first.pointId===second.pointId,srjPointsHaveSameBoardPositionAndLayer=(first,second)=>Math.abs(first.x-second.x)<=SRJ_POINT_POSITION_TOLERANCE_MM&&Math.abs(first.y-second.y)<=SRJ_POINT_POSITION_TOLERANCE_MM&&first.layer===second.layer,srjPointsReferToSameEndpoint=(first,second)=>first.pointId!==void 0&&second.pointId!==void 0?srjPointsHaveSamePointId(first,second):srjPointsHaveSameBoardPositionAndLayer(first,second),getPairedGlobalPoint=(simpleRouteJson,connection)=>{let globalConnection=simpleRouteJson.connections.find(candidate=>candidate.routingPcbGroupId!==connection.routingPcbGroupId&&candidate.source_trace_id===connection.source_trace_id&&candidate.pointsToConnect.some(globalPoint=>connection.pointsToConnect.some(localPoint=>srjPointsReferToSameEndpoint(globalPoint,localPoint))));if(!globalConnection)return;let pairedPoints=globalConnection.pointsToConnect.filter(globalPoint=>!connection.pointsToConnect.some(localPoint=>srjPointsReferToSameEndpoint(globalPoint,localPoint)));return pairedPoints.length===1?pairedPoints[0]:void 0},getPairedBreakoutExitTarget=(simpleRouteJson,connection)=>{if(!connection.routingPcbGroupId||!connection.source_trace_id)return;let pairedGlobalPoint=getPairedGlobalPoint(simpleRouteJson,connection);if(!(!pairedGlobalPoint||!simpleRouteJson.connections.some(candidate=>candidate.routingPcbGroupId!==void 0&&candidate.routingPcbGroupId!==connection.routingPcbGroupId&&candidate.source_trace_id===connection.source_trace_id&&candidate.pointsToConnect.some(candidatePoint=>srjPointsReferToSameEndpoint(candidatePoint,pairedGlobalPoint)))))return{x:pairedGlobalPoint.x,y:pairedGlobalPoint.y,layer:pairedGlobalPoint.layer}};function connectionIsInRoutingPhase(connection,phasePlan){if(connection.routingPcbGroupId)return connection.routingPcbGroupId===phasePlan.routingPcbGroupId;for(let trace of phasePlan.traces)if(trace.source_trace_id&&(connection.source_trace_id===trace.source_trace_id||connection.name===trace.source_trace_id||connection.rootConnectionName===trace.source_trace_id||connection.mergedConnectionNames?.includes(trace.source_trace_id)))return!0;for(let net of phasePlan.nets)if(net.source_net_id&&connection.name===net.source_net_id)return!0;return!1}function Group_hasPhasedAutorouting(routingPhasePlans){for(let plan of routingPhasePlans)if(plan.routingPcbGroupId||plan.routingPhaseIndex!==null)return!0;return!1}function Group_filterSimpleRouteJsonForPhase(simpleRouteJson,phasePlan){let connections=[];for(let connection of simpleRouteJson.connections)connectionIsInRoutingPhase(connection,phasePlan)&&connections.push(connection);let includedConnectionNames=new Set;for(let connection of connections)includedConnectionNames.add(connection.name);let differentialPairs=[];for(let differentialPair of simpleRouteJson.differentialPairs??[]){let positiveConnectionIncluded=includedConnectionNames.has(differentialPair.connectionNames[0]),negativeConnectionIncluded=includedConnectionNames.has(differentialPair.connectionNames[1]);if(positiveConnectionIncluded!==negativeConnectionIncluded)throw new Error(`Differential pair "${differentialPair.connectionNames.join("/")}" cannot be split across autorouting phases`);positiveConnectionIncluded&&differentialPairs.push(differentialPair)}let srjConnectionByName=new Map(simpleRouteJson.connections.map(connection=>[connection.name,connection])),buses=(simpleRouteJson.buses??[]).map(bus=>{let connectionNames=bus.connectionNames.filter(connectionName=>includedConnectionNames.has(connectionName)),cohortConnectionNames=bus.connectionNames.filter(connectionName=>srjConnectionByName.get(connectionName)?.routingPcbGroupId===phasePlan.routingPcbGroupId);if(bus.maxLengthSkew!==void 0&&connectionNames.length>0&&connectionNames.length!==cohortConnectionNames.length)throw new RoutingPhasePreparationError(`Length-matched bus "${bus.name||"unnamed bus"}" cannot be split across autorouting phases. Assign the complete bus to one routingPhaseIndex.`);let connectionExitTargets=Object.fromEntries(connectionNames.flatMap(connectionName=>{let connection=srjConnectionByName.get(connectionName);if(!connection)return[];let pairedTarget=getPairedBreakoutExitTarget(simpleRouteJson,connection);return pairedTarget?[[connectionName,pairedTarget]]:[]}));return{...bus,connectionNames,...Object.keys(connectionExitTargets).length>0?{connectionExitTargets}:{}}}).filter(bus=>bus.connectionNames.length>0),bounds=expandSrjBoundsToIncludeConnectionPoints({bounds:phasePlan.routingBounds??simpleRouteJson.bounds,connections});return{...simpleRouteJson,bounds,outline:getSrjOutlineForRoutingBounds(simpleRouteJson,bounds),connections,differentialPairs:differentialPairs.length>0?differentialPairs:void 0,buses:buses.length>0?buses:void 0}}function hasDrcTolerances(drcTolerances){return drcTolerances?Object.values(drcTolerances).some(value=>value!==void 0):!1}function applyMinTraceWidthToConnections(connections,minTraceWidth){return minTraceWidth===void 0?connections:connections.map(connection=>({...connection,nominalTraceWidth:Math.max(connection.nominalTraceWidth??minTraceWidth,minTraceWidth),width:Math.max(connection.width??minTraceWidth,minTraceWidth)}))}function Group_applyDrcTolerancesToSimpleRouteJson(simpleRouteJson,drcTolerances){if(!hasDrcTolerances(drcTolerances))return simpleRouteJson;let minTraceWidth=drcTolerances.minTraceWidth??simpleRouteJson.minTraceWidth,minViaHoleDiameter=drcTolerances.minViaHoleDiameter??simpleRouteJson.minViaHoleDiameter,minViaPadDiameter=drcTolerances.minViaPadDiameter??simpleRouteJson.minViaPadDiameter,minTraceToHoleEdgeClearance=drcTolerances.minTraceToHoleEdgeClearance??simpleRouteJson.minTraceToHoleEdgeClearance,minTraceToPadEdgeClearance=drcTolerances.minTraceToPadEdgeClearance??simpleRouteJson.minTraceToPadEdgeClearance,minViaEdgeToPadEdgeClearance=drcTolerances.minViaEdgeToPadEdgeClearance??simpleRouteJson.minViaEdgeToPadEdgeClearance,minViaHoleEdgeToViaHoleEdgeClearance=drcTolerances.minViaHoleEdgeToViaHoleEdgeClearance??simpleRouteJson.minViaHoleEdgeToViaHoleEdgeClearance,minPlatedHoleDrillEdgeToDrillEdgeClearance=drcTolerances.minPlatedHoleDrillEdgeToDrillEdgeClearance??simpleRouteJson.minPlatedHoleDrillEdgeToDrillEdgeClearance,minPadEdgeToPadEdgeClearance=drcTolerances.minPadEdgeToPadEdgeClearance??simpleRouteJson.minPadEdgeToPadEdgeClearance,minBoardEdgeClearance=drcTolerances.minBoardEdgeClearance??simpleRouteJson.minBoardEdgeClearance;return{...simpleRouteJson,connections:applyMinTraceWidthToConnections(simpleRouteJson.connections,drcTolerances.minTraceWidth),minTraceWidth,minViaDiameter:minViaPadDiameter,minViaHoleDiameter,minViaPadDiameter,min_via_hole_diameter:minViaHoleDiameter,min_via_pad_diameter:minViaPadDiameter,minTraceToPadEdgeClearance,minTraceToHoleEdgeClearance,minViaEdgeToPadEdgeClearance,minViaHoleEdgeToViaHoleEdgeClearance,minPlatedHoleDrillEdgeToDrillEdgeClearance,minPadEdgeToPadEdgeClearance,minBoardEdgeClearance}}var removeCompletedFanoutConnections=(simpleRouteJson,routingPcbGroupId)=>{let connections=simpleRouteJson.connections.filter(connection=>connection.routingPcbGroupId!==routingPcbGroupId),includedConnectionNames=new Set(connections.map(connection=>connection.name)),differentialPairs=[];for(let differentialPair of simpleRouteJson.differentialPairs??[]){let positiveConnectionIncluded=includedConnectionNames.has(differentialPair.connectionNames[0]),negativeConnectionIncluded=includedConnectionNames.has(differentialPair.connectionNames[1]);if(positiveConnectionIncluded!==negativeConnectionIncluded)throw new Error(`Differential pair "${differentialPair.connectionNames.join("/")}" cannot be split at a breakout boundary`);positiveConnectionIncluded&&differentialPairs.push(differentialPair)}let buses=(simpleRouteJson.buses??[]).map(bus=>({...bus,connectionNames:bus.connectionNames.filter(connectionName=>includedConnectionNames.has(connectionName))})).filter(bus=>bus.connectionNames.length>0);return{...simpleRouteJson,connections,differentialPairs:differentialPairs.length>0?differentialPairs:void 0,buses:buses.length>0?buses:void 0}},connectFanoutTracesToBreakoutPoints=(simpleRouteJson,breakoutPointIdByConnectionName)=>({...simpleRouteJson,traces:simpleRouteJson.traces?.map(trace=>{let breakoutPointId=breakoutPointIdByConnectionName.get(trace.connection_name??"");return breakoutPointId?{...trace,connectsTo:[...new Set([...trace.connectsTo??[],breakoutPointId])]}:trace})});function Group_syncFanoutExitsWithGlobalConnections({fanoutInputSimpleRouteJson,fanoutOutputSimpleRouteJson,baseSimpleRouteJson,routingPhasePlan}){let routingPcbGroupId=routingPhasePlan.routingPcbGroupId;if(!routingPcbGroupId)return{downstreamSimpleRouteJson:fanoutOutputSimpleRouteJson,baseSimpleRouteJson,synchronizedBreakoutPoints:[]};let outputConnectionByName=new Map(fanoutOutputSimpleRouteJson.connections.map(connection=>[connection.name,connection])),baseConnections=baseSimpleRouteJson.connections.map(connection=>({...connection,pointsToConnect:connection.pointsToConnect.map(point62=>({...point62}))})),synchronizedBreakoutPoints=[],breakoutPointIdByConnectionName=new Map;for(let inputConnection of fanoutInputSimpleRouteJson.connections){if(inputConnection.routingPcbGroupId!==routingPcbGroupId||!inputConnection.source_trace_id)continue;let outputConnection=outputConnectionByName.get(inputConnection.name);if(!outputConnection)continue;let globalPointMatches=baseConnections.filter(connection=>{if(connection.routingPcbGroupId===routingPcbGroupId)return!1;let sharesSourceTrace=connection.source_trace_id===inputConnection.source_trace_id,sharesPointId=connection.pointsToConnect.some(globalPoint=>inputConnection.pointsToConnect.some(inputPoint=>srjPointsHaveSamePointId(globalPoint,inputPoint)));return!sharesSourceTrace&&!sharesPointId?!1:connection.pointsToConnect.some(globalPoint=>inputConnection.pointsToConnect.some(inputPoint=>srjPointsReferToSameEndpoint(globalPoint,inputPoint)))}).flatMap(globalConnection=>globalConnection.pointsToConnect.flatMap((previousPoint,pointIndex)=>inputConnection.pointsToConnect.some(inputPoint=>srjPointsReferToSameEndpoint(previousPoint,inputPoint))?[{globalConnection,pointIndex,previousPoint}]:[])),changedPointIndex=outputConnection.pointsToConnect.findIndex((outputPoint,pointIndex)=>{let inputPoint=inputConnection.pointsToConnect[pointIndex];return inputPoint!==void 0&&!srjPointsHaveSameBoardPositionAndLayer(outputPoint,inputPoint)});if(changedPointIndex<0)continue;let fanoutExitPoint=outputConnection.pointsToConnect[changedPointIndex];globalPointMatches.length===0&&synchronizedBreakoutPoints.push({sourceTraceId:inputConnection.source_trace_id,routingPcbGroupId,previousPoint:inputConnection.pointsToConnect[changedPointIndex],fanoutExitPoint});for(let{globalConnection,pointIndex,previousPoint}of globalPointMatches){let{terminalVia:_previousTerminalVia,...previousPointWithoutLayerOverrides}=previousPoint,synchronizedGlobalPoint={...previousPointWithoutLayerOverrides,x:fanoutExitPoint.x,y:fanoutExitPoint.y,layer:fanoutExitPoint.layer,...fanoutExitPoint.terminalVia?{terminalVia:{...fanoutExitPoint.terminalVia}}:{}};globalConnection.pointsToConnect[pointIndex]=synchronizedGlobalPoint,previousPoint.pointId&&breakoutPointIdByConnectionName.set(inputConnection.name,previousPoint.pointId),synchronizedBreakoutPoints.push({sourceTraceId:inputConnection.source_trace_id,routingPcbGroupId,previousPoint,fanoutExitPoint})}}let newFanoutSourceKeepouts=fanoutOutputSimpleRouteJson.obstacles.filter(obstacle=>obstacle.isFanoutSourceKeepout===!0&&obstacle.componentId!==void 0),completedSourceComponentIds=new Set(newFanoutSourceKeepouts.flatMap(obstacle=>obstacle.componentId===void 0?[]:[obstacle.componentId])),retainedBaseObstacles=baseSimpleRouteJson.obstacles.filter(obstacle=>!obstacle.componentId||!completedSourceComponentIds.has(obstacle.componentId));return{downstreamSimpleRouteJson:removeCompletedFanoutConnections(connectFanoutTracesToBreakoutPoints(fanoutOutputSimpleRouteJson,breakoutPointIdByConnectionName),routingPcbGroupId),baseSimpleRouteJson:{...baseSimpleRouteJson,connections:baseConnections,obstacles:[...retainedBaseObstacles,...newFanoutSourceKeepouts]},synchronizedBreakoutPoints}}function getJumperPadInfos(db22){let padInfos=[],jumperSourceComponentIds=new Set(db22.source_component.list().filter(component=>component.name?.startsWith("__autoplaced_jumper")).map(component=>component.source_component_id));if(jumperSourceComponentIds.size===0)return padInfos;let jumperPcbComponentIds=new Set(db22.pcb_component.list().filter(component=>jumperSourceComponentIds.has(component.source_component_id)).map(component=>component.pcb_component_id)),jumperSmtpads=db22.pcb_smtpad.list().filter(pad2=>jumperPcbComponentIds.has(pad2.pcb_component_id));for(let smtpad2 of jumperSmtpads)if(smtpad2.shape!=="polygon"&&smtpad2.pcb_port_id){if(smtpad2.shape==="rect"||smtpad2.shape==="rotated_rect"){let halfWidth=smtpad2.width/2,halfHeight=smtpad2.height/2;padInfos.push({pcb_port_id:smtpad2.pcb_port_id,x:smtpad2.x,y:smtpad2.y,minX:smtpad2.x-halfWidth,maxX:smtpad2.x+halfWidth,minY:smtpad2.y-halfHeight,maxY:smtpad2.y+halfHeight})}else if(smtpad2.shape==="circle"){let radius=smtpad2.radius;padInfos.push({pcb_port_id:smtpad2.pcb_port_id,x:smtpad2.x,y:smtpad2.y,minX:smtpad2.x-radius,maxX:smtpad2.x+radius,minY:smtpad2.y-radius,maxY:smtpad2.y+radius})}}return padInfos}function findJumperPortAtPosition(padInfos,x22,y22,tolerance=.01){for(let pad2 of padInfos)if(Math.abs(pad2.x-x22)<tolerance&&Math.abs(pad2.y-y22)<tolerance)return pad2.pcb_port_id}function findJumperPortContainingPoint(padInfos,x22,y22){for(let pad2 of padInfos)if(x22>=pad2.minX&&x22<=pad2.maxX&&y22>=pad2.minY&&y22<=pad2.maxY)return pad2}function splitRouteAtJumperPads(route2,padInfos){if(route2.length===0||padInfos.length===0)return[route2];let segments=[],currentSegment=[];for(let i22=0;i22<route2.length;i22++){let point62=route2[i22];if(currentSegment.push(point62),point62.route_type==="wire"&&i22>0&&i22<route2.length-1){let padInfo=findJumperPortContainingPoint(padInfos,point62.x,point62.y);if(padInfo){point62.end_pcb_port_id||(point62.end_pcb_port_id=padInfo.pcb_port_id),segments.push(currentSegment);let newStartPoint={...point62};delete newStartPoint.end_pcb_port_id,newStartPoint.start_pcb_port_id||(newStartPoint.start_pcb_port_id=padInfo.pcb_port_id),currentSegment=[newStartPoint]}}}return currentSegment.length>0&&segments.push(currentSegment),segments}function addPortIdsToTracesAtJumperPads(segments,padInfos){if(padInfos.length===0)return segments;let result=[];for(let segment2 of segments){let subSegments=splitRouteAtJumperPads(segment2,padInfos);for(let subSegment of subSegments)if(subSegment.length>0){let firstPoint=subSegment[0],lastPoint=subSegment[subSegment.length-1];if(firstPoint.route_type==="wire"&&!firstPoint.start_pcb_port_id){let portId=findJumperPortAtPosition(padInfos,firstPoint.x,firstPoint.y);portId&&(firstPoint.start_pcb_port_id=portId)}if(lastPoint.route_type==="wire"&&!lastPoint.end_pcb_port_id){let portId=findJumperPortAtPosition(padInfos,lastPoint.x,lastPoint.y);portId&&(lastPoint.end_pcb_port_id=portId)}result.push(subSegment)}}return result}var claimSrjAssignablePcbViasTraversedByRoute=({db:db22,pcbTrace,routeWithSrjMetadata})=>{for(let routePoint3 of routeWithSrjMetadata){if(routePoint3.route_type!=="through_pad")continue;let pcbViaId=routePoint3.circuitJsonMetadata?.pcb_via_id;if(!pcbViaId)continue;let assignablePcbVia=db22.pcb_via.get(pcbViaId);!assignablePcbVia?.net_is_assignable||assignablePcbVia.net_assigned&&assignablePcbVia.pcb_trace_id!==pcbTrace.pcb_trace_id||db22.pcb_via.update(assignablePcbVia.pcb_via_id,{pcb_trace_id:pcbTrace.pcb_trace_id,net_assigned:!0})}},getAxisGap=(firstMinimum,firstMaximum,secondMinimum,secondMaximum)=>Math.max(secondMinimum-firstMaximum,firstMinimum-secondMaximum),findFanoutPhaseSeparationConflict=regions=>{for(let firstIndex=0;firstIndex<regions.length;firstIndex++){let firstRegion=regions[firstIndex];for(let secondIndex=firstIndex+1;secondIndex<regions.length;secondIndex++){let secondRegion=regions[secondIndex];if(firstRegion.regionId&&firstRegion.regionId===secondRegion.regionId)continue;let horizontalGap=getAxisGap(firstRegion.bounds.minX,firstRegion.bounds.maxX,secondRegion.bounds.minX,secondRegion.bounds.maxX),verticalGap=getAxisGap(firstRegion.bounds.minY,firstRegion.bounds.maxY,secondRegion.bounds.minY,secondRegion.bounds.maxY),availableGap=Math.max(horizontalGap,verticalGap),requiredGap=firstRegion.boundaryKeepaway+secondRegion.boundaryKeepaway;if(availableGap+1e-6<requiredGap)return{firstRegion,secondRegion,availableGap,requiredGap}}}};function getAccumulatedPcbTracesWithStageOutputReplacements({accumulatedPcbTraces,stageOutputPcbTraces}){let replacedPcbTraceIds=new Set(stageOutputPcbTraces.flatMap(trace=>[trace.pcb_trace_id,...trace.__replaces_pcb_trace_id?[trace.__replaces_pcb_trace_id]:[]]));return[...accumulatedPcbTraces.filter(trace=>!replacedPcbTraceIds.has(trace.pcb_trace_id)),...stageOutputPcbTraces]}var POINT_EPSILON3=1e-6;function isPointOnWireSegment({point:point62,segmentStart,segmentEnd}){return point62.layer&&(segmentStart.layer!==point62.layer||segmentEnd.layer!==point62.layer)?!1:pointToSegmentDistance(point62,segmentStart,segmentEnd)<=POINT_EPSILON3}function isPointInSmtPad({point:point62,pad:pad2,traceWidth=0}){return pad2.shape==="rect"||pad2.shape==="rotated_rect"?Math.abs(point62.x-pad2.x)<=pad2.width/2+traceWidth/2&&Math.abs(point62.y-pad2.y)<=pad2.height/2+traceWidth/2:pad2.shape==="circle"?distance3(point62,pad2)<=pad2.radius+traceWidth/2:!1}function isPointInPlatedHole({point:point62,hole,traceWidth=0}){return distance3(point62,hole)<=(hole.outer_diameter??hole.hole_diameter??0)/2+traceWidth/2}function getEndpointSourcePortIdsFromGeometry(db22,trace){let sourcePortIds=new Set,route2=trace.route,endpoints=[route2[0],route2[route2.length-1]].filter(point62=>!!point62&&point62.route_type==="wire"&&point62.x!==void 0&&point62.y!==void 0);for(let endpoint of endpoints){for(let pcbPort of db22.pcb_port.list())pcbPort.source_port_id&&(endpoint.layer&&pcbPort.layers&&!pcbPort.layers.includes(endpoint.layer)||distance3(endpoint,pcbPort)<=.01&&sourcePortIds.add(pcbPort.source_port_id));for(let smtpad2 of db22.pcb_smtpad.list()){if(!smtpad2.pcb_port_id||endpoint.layer&&smtpad2.layer!==endpoint.layer||!isPointInSmtPad({point:endpoint,pad:smtpad2,traceWidth:endpoint.width}))continue;let sourcePortId=db22.pcb_port.get(smtpad2.pcb_port_id)?.source_port_id;sourcePortId&&sourcePortIds.add(sourcePortId)}for(let hole of db22.pcb_plated_hole.list()){if(!hole.pcb_port_id||!isPointInPlatedHole({point:endpoint,hole,traceWidth:endpoint.width}))continue;let sourcePortId=db22.pcb_port.get(hole.pcb_port_id)?.source_port_id;sourcePortId&&sourcePortIds.add(sourcePortId)}}return[...sourcePortIds]}function getWireRouteEndpoints(trace){let route2=trace.route.filter(point62=>point62.route_type==="wire"&&point62.x!==void 0&&point62.y!==void 0);return[route2[0],route2[route2.length-1]].filter(point62=>!!point62)}function getSourceIdsFromConnectedPcbTraces(db22,trace){let sourceIds=new Set,endpoints=getWireRouteEndpoints(trace);if(endpoints.length===0)return[];for(let existingTrace of db22.pcb_trace.list()){if(!existingTrace.source_trace_id||existingTrace.pcb_trace_id===trace.pcb_trace_id||!db22.source_trace.get(existingTrace.source_trace_id)&&!db22.source_net.get(existingTrace.source_trace_id))continue;let existingRoute=existingTrace.route.filter(point62=>point62.route_type==="wire");for(let i22=0;i22<existingRoute.length-1;i22++){let segmentStart=existingRoute[i22],segmentEnd=existingRoute[i22+1];if(!(!segmentStart||!segmentEnd))for(let endpoint of endpoints)isPointOnWireSegment({point:endpoint,segmentStart,segmentEnd})&&sourceIds.add(existingTrace.source_trace_id)}}return[...sourceIds]}function getSourcePortIdsFromRoutedTrace(db22,trace){let sourcePortIds=new Set;for(let point62 of trace.route)for(let pcbPortId of[point62.start_pcb_port_id,point62.end_pcb_port_id]){if(!pcbPortId)continue;let sourcePortId=db22.pcb_port.get(pcbPortId)?.source_port_id;sourcePortId&&sourcePortIds.add(sourcePortId)}return sourcePortIds.size>0?[...sourcePortIds]:getEndpointSourcePortIdsFromGeometry(db22,trace)}function buildSourceConnectivityMap(sourceTraces){let connMap=new ConnectivityMap({});return connMap.addConnections(sourceTraces.map(trace=>[trace.source_trace_id,...trace.connected_source_port_ids,...trace.connected_source_net_ids])),connMap}function getSourceTraceIdForRoutedTrace({db:db22,trace,subcircuit_id}){if(trace.source_trace_id&&(db22.source_trace.get(trace.source_trace_id)??db22.source_net.get(trace.source_trace_id)))return trace.source_trace_id;let sourcePortIds=getSourcePortIdsFromRoutedTrace(db22,trace);if(sourcePortIds.length===0)return getSourceIdsFromConnectedPcbTraces(db22,trace)[0];let sourceTraces=db22.source_trace.list(),connMap=buildSourceConnectivityMap(sourceTraces),endpointNetIds=sourcePortIds.map(sourcePortId=>connMap.getNetConnectedToId(sourcePortId)).filter(netId=>!!netId),exactSourceTrace=sourcePortIds.length>=2?sourceTraces.find(sourceTrace=>sourcePortIds.every(sourcePortId=>sourceTrace.connected_source_port_ids.includes(sourcePortId))):void 0;if(exactSourceTrace)return exactSourceTrace.source_trace_id;let sourceTracesInEndpointNets=sourceTraces.filter(sourceTrace=>{let sourceTraceNetId=connMap.getNetConnectedToId(sourceTrace.source_trace_id);return endpointNetIds.some(netId=>netId===sourceTraceNetId)}),connectedToEndpoint=sourceTracesInEndpointNets.filter(sourceTrace=>sourceTrace.connected_source_port_ids.some(sourcePortId=>sourcePortIds.includes(sourcePortId))),candidates=connectedToEndpoint.length>0?connectedToEndpoint:sourceTracesInEndpointNets;if(candidates.length!==0)return(candidates.find(sourceTrace=>sourceTrace.subcircuit_id===subcircuit_id)??candidates[0])?.source_trace_id}function groupPadsByInternalConnection(pads,orientation22){let groups=[];for(let pad2 of pads){let key=orientation22==="vertical"?pad2.center.y:pad2.center.x,foundGroup=!1;for(let group2 of groups){let groupKey=orientation22==="vertical"?group2[0].center.y:group2[0].center.x;if(Math.abs(key-groupKey)<.01){group2.push(pad2),foundGroup=!0;break}}foundGroup||groups.push([pad2])}return groups.filter(g22=>g22.length>=2)}function insertAutoplacedJumpers(params){let{db:db22,output_jumpers,subcircuit_id}=params;for(let jumperIndex=0;jumperIndex<output_jumpers.length;jumperIndex++){let jumper=output_jumpers[jumperIndex],sourceComponent=db22.source_component.insert({ftype:"simple_chip",name:`__autoplaced_jumper_${jumperIndex}`,supplier_part_numbers:{}}),rotation5=jumper.orientation==="horizontal"?0:90,firstPadLayer=jumper.pads[0]?.layer||jumper.pads[0]?.layers?.[0]||"top",pcbComponent=db22.pcb_component.insert({source_component_id:sourceComponent.source_component_id,center:jumper.center,rotation:rotation5,layer:firstPadLayer,width:jumper.width||0,height:jumper.height||0,obstructs_within_bounds:!1}),padData=[];for(let padIndex=0;padIndex<jumper.pads.length;padIndex++){let pad2=jumper.pads[padIndex],pinNumber=padIndex+1,sourcePort=db22.source_port.insert({source_component_id:sourceComponent.source_component_id,name:`pin${pinNumber}`,pin_number:pinNumber}),padLayer=pad2.layer||pad2.layers?.[0]||"top",pcbPort=db22.pcb_port.insert({pcb_component_id:pcbComponent.pcb_component_id,source_port_id:sourcePort.source_port_id,x:pad2.center.x,y:pad2.center.y,layers:[padLayer]}),pcbSmtpad=db22.pcb_smtpad.insert({pcb_component_id:pcbComponent.pcb_component_id,pcb_port_id:pcbPort.pcb_port_id,shape:"rect",x:pad2.center.x,y:pad2.center.y,width:pad2.width,height:pad2.height,layer:padLayer});padData.push({pad:pad2,sourcePortId:sourcePort.source_port_id,pcbSmtpadId:pcbSmtpad.pcb_smtpad_id})}let internalGroups=groupPadsByInternalConnection(jumper.pads,jumper.orientation);for(let group2 of internalGroups){let sourcePortIds=[];for(let groupPad of group2){let padInfo=padData.find(p22=>Math.abs(p22.pad.center.x-groupPad.center.x)<.01&&Math.abs(p22.pad.center.y-groupPad.center.y)<.01);padInfo&&sourcePortIds.push(padInfo.sourcePortId)}sourcePortIds.length>=2&&db22.source_component_internal_connection.insert({source_component_id:sourceComponent.source_component_id,subcircuit_id:subcircuit_id??void 0,source_port_ids:sourcePortIds})}}}function convertPcbTraceToSimplifiedPcbTrace(trace){return{...trace,type:"pcb_trace",pcb_trace_id:trace.pcb_trace_id,connection_name:trace.connection_name??trace.source_trace_id??trace.pcb_trace_id,route:trace.route.map(point62=>({...point62}))}}function getRelevantSubcircuitIdsForReroute(group2){let relevantSubcircuitIds=new Set;if(!group2.subcircuit_id)return relevantSubcircuitIds;relevantSubcircuitIds.add(group2.subcircuit_id);let db22=group2.root?.db;if(!db22)return relevantSubcircuitIds;for(let subcircuitId of getDescendantSubcircuitIds2(db22,group2.subcircuit_id))relevantSubcircuitIds.add(subcircuitId);return relevantSubcircuitIds}function getExistingPcbTracesForReroute(group2){let db22=group2.root?.db;if(!db22)return[];let relevantSubcircuitIds=getRelevantSubcircuitIdsForReroute(group2);return db22.pcb_trace.list().filter(trace=>!trace.route||trace.route.length<2?!1:group2.subcircuit_id?!!(trace.subcircuit_id&&relevantSubcircuitIds.has(trace.subcircuit_id)):!0)}function getSourceTraceIdsFromRerouteName(value){return typeof value!="string"||value.length===0?[]:value.split("__").flatMap(connectionNamePart=>{if(connectionNamePart.length===0)return[];let sourceTraceIds=[connectionNamePart],rerouteSuffixIndex=connectionNamePart.indexOf("_reroute_");return rerouteSuffixIndex>0&&sourceTraceIds.push(connectionNamePart.slice(0,rerouteSuffixIndex)),sourceTraceIds})}function addPossibleReplacementSourceTraceId(sourceTraceIds,value){if(!(typeof value!="string"||value.length===0)){sourceTraceIds.add(value);for(let sourceTraceId of getSourceTraceIdsFromRerouteName(value))sourceTraceIds.add(sourceTraceId)}}function deleteExistingPcbTracesReplacedBy({group:group2,outputPcbTraces,pcbTraceIdsToReplace=[]}){let db22=group2.root?.db;if(!db22)return;let replacementPcbTraceIds=new Set(pcbTraceIdsToReplace),replacementSourceTraceIds=new Set;for(let trace of outputPcbTraces){if(trace.type!=="pcb_trace")continue;let replacementTrace=trace;replacementPcbTraceIds.add(replacementTrace.pcb_trace_id),addPossibleReplacementSourceTraceId(replacementSourceTraceIds,replacementTrace.source_trace_id),addPossibleReplacementSourceTraceId(replacementSourceTraceIds,replacementTrace.connection_name),addPossibleReplacementSourceTraceId(replacementSourceTraceIds,replacementTrace.rootConnectionName)}if(replacementPcbTraceIds.size===0&&replacementSourceTraceIds.size===0)return;let tracesToDelete=getExistingPcbTracesForReroute(group2).filter(trace=>replacementPcbTraceIds.has(trace.pcb_trace_id)||!!(trace.source_trace_id&&trace.subcircuit_id===group2.subcircuit_id&&replacementSourceTraceIds.has(trace.source_trace_id)));if(tracesToDelete.length===0)return;let deletedPcbTraceIds=new Set(tracesToDelete.map(trace=>trace.pcb_trace_id));for(let via of db22.pcb_via.list())via.pcb_trace_id&&deletedPcbTraceIds.has(via.pcb_trace_id)&&db22.pcb_via.delete(via.pcb_via_id);for(let trace of tracesToDelete)db22.pcb_trace.delete(trace.pcb_trace_id)}function getExistingSimplifiedPcbTracesForReroute(group2){return getExistingPcbTracesForReroute(group2).map(convertPcbTraceToSimplifiedPcbTrace)}function splitPcbTracesOnJumperSegments(route2){let jumperRoutes=route2.filter(p22=>p22.route_type==="jumper"),wireAndViaRoutes=route2.filter(p22=>p22.route_type!=="jumper");if(jumperRoutes.length===0)return null;let splitRanges=[];for(let jumperRoute of jumperRoutes){let jumperStart=jumperRoute.start,jumperEnd=jumperRoute.end,startIdx=-1,endIdx=-1,minStartDist=1/0,minEndDist=1/0;for(let i22=0;i22<wireAndViaRoutes.length;i22++){let p22=wireAndViaRoutes[i22];if(p22.route_type!=="wire")continue;let distToStart=Math.hypot(p22.x-jumperStart.x,p22.y-jumperStart.y),distToEnd=Math.hypot(p22.x-jumperEnd.x,p22.y-jumperEnd.y);distToStart<minStartDist&&(minStartDist=distToStart,startIdx=i22),distToEnd<minEndDist&&(minEndDist=distToEnd,endIdx=i22)}startIdx>endIdx&&([startIdx,endIdx]=[endIdx,startIdx]),startIdx>=0&&endIdx>=0&&startIdx!==endIdx&&splitRanges.push({startIdx,endIdx})}splitRanges.sort((a22,b22)=>a22.startIdx-b22.startIdx);let segments=[],currentStart=0;for(let range2 of splitRanges)currentStart<range2.startIdx&&segments.push(wireAndViaRoutes.slice(currentStart,range2.startIdx+1)),currentStart=range2.endIdx;return currentStart<wireAndViaRoutes.length&&segments.push(wireAndViaRoutes.slice(currentStart)),segments}function computeCenterFromAnchorPosition(anchorPosition,ctx){let{width,height,pcbAnchorAlignment}=ctx;if(!pcbAnchorAlignment)return anchorPosition;let alignment=pcbAnchorAlignment;if(typeof width!="number"||typeof height!="number")return anchorPosition;let ax22=anchorPosition.x,ay22=anchorPosition.y;switch(alignment){case"top_left":return{x:ax22+width/2,y:ay22-height/2};case"top_center":return{x:ax22,y:ay22-height/2};case"top_right":return{x:ax22-width/2,y:ay22-height/2};case"center_left":return{x:ax22+width/2,y:ay22};case"center_right":return{x:ax22-width/2,y:ay22};case"bottom_left":return{x:ax22+width/2,y:ay22+height/2};case"bottom_center":return{x:ax22,y:ay22+height/2};case"bottom_right":return{x:ax22-width/2,y:ay22+height/2};default:return anchorPosition}}var getDistanceToPoint=(routePoint3,targetPoint)=>{let position4=getRoutePointPosition(routePoint3);return Math.hypot(position4.x-targetPoint.x,position4.y-targetPoint.y)},platformAllowsLegacyAutorouters=group2=>{let platform=group2.root?.platform;return platform!==void 0&&"allowLegacyAutorouters"in platform&&platform.allowLegacyAutorouters===!0},getDisabledLegacyGroupAutorouterPreset=group2=>{if(platformAllowsLegacyAutorouters(group2))return null;let resolvedGroupAutorouter=group2._parsedProps.autorouter??group2.getInheritedProperty("autorouter");return getLegacyAutorouterPreset(resolvedGroupAutorouter)},getDisabledLegacyAutorouterPreset=group2=>{if(platformAllowsLegacyAutorouters(group2))return null;let legacyGroupAutorouterPreset=getDisabledLegacyGroupAutorouterPreset(group2);if(legacyGroupAutorouterPreset)return legacyGroupAutorouterPreset;let routingPhaseAutorouters=group2.selectAll("autoroutingphase").map(autoroutingPhase=>autoroutingPhase._parsedProps.autorouter);for(let autorouter of routingPhaseAutorouters){let legacyAutorouterPreset=getLegacyAutorouterPreset(autorouter);if(legacyAutorouterPreset)return legacyAutorouterPreset}return null},ensureRouteStartsAtSourceTraceStart=({db:db22,route:route2,routeThicknessMode,sourceTraceId})=>{if(!sourceTraceId||route2.length<2)return route2;let firstSourcePortId=db22.source_trace.get(sourceTraceId)?.connected_source_port_ids[0];if(!firstSourcePortId)return route2;let firstPcbPort=db22.pcb_port.list().find(port=>port.source_port_id===firstSourcePortId);if(!firstPcbPort)return route2;let firstPoint=route2[0],lastPoint=route2[route2.length-1];return getDistanceToPoint(lastPoint,firstPcbPort)<getDistanceToPoint(firstPoint,firstPcbPort)?reversePcbTraceRoute(route2,routeThicknessMode):route2},Group5=class extends NormalComponent{constructor(){super(...arguments);__publicField(this,"pcb_group_id",null);__publicField(this,"schematic_group_id",null);__publicField(this,"subcircuit_id",null);__publicField(this,"_hasStartedAsyncAutorouting",!1);__publicField(this,"_pcbPlacementDrcErrorCount",null);__publicField(this,"_pcbPlacementDrcCheckError",null);__publicField(this,"_pcbPlacementDrcChecksPending",!1);__publicField(this,"_standaloneSubcircuitDrcChecksComplete",!1);__publicField(this,"_standaloneSubcircuitDrcChecksInProgress",!1);__publicField(this,"_isInflatedFromCircuitJson",!1);__publicField(this,"_isolatedCircuitJson",null);__publicField(this,"_normalComponentNameMap",null);__publicField(this,"_asyncAutoroutingResult",null);__publicField(this,"unnamedElementCounter",{})}get _isIsolatedSubcircuit(){return!!this.getInheritedProperty("_subcircuitCachingEnabled")}getNormalComponentNameMap(){if(this._normalComponentNameMap)return this._normalComponentNameMap;let nameMap=new Map,collectNamedComponents=component=>{if(component._isNormalComponent&&component.name){let componentsWithSameName=nameMap.get(component.name);componentsWithSameName?componentsWithSameName.push(component):nameMap.set(component.name,[component])}for(let child of component.children)child.isSubcircuit||collectNamedComponents(child)};for(let child of this.children)child.isSubcircuit||collectNamedComponents(child);return this._normalComponentNameMap=nameMap,nameMap}get config(){return{zodProps:groupProps,componentName:"Group"}}initPorts(opts={}){let schPinArrangement=this._getSchematicPortArrangement();this._parsedProps?.showAsSchematicBox&&!this._parsedProps.pinLabels&&schPinArrangement&&getPinsFromPortArrangement(schPinArrangement).some(pin=>typeof pin=="string")||super.initPorts(opts)}_getSchematicPortArrangementFromPortDirections(){if(!this._parsedProps?.showAsSchematicBox)return null;let sidePins={leftSide:[],rightSide:[],topSide:[],bottomSide:[]};for(let port of this.children){if(port.componentName!=="Port")continue;let direction3=port._parsedProps.direction;if(!direction3)continue;let pin=port._parsedProps.pinNumber??port._parsedProps.name??void 0;if(pin===void 0)continue;sidePins[direction3==="left"?"leftSide":direction3==="right"?"rightSide":direction3==="up"?"topSide":"bottomSide"].push(pin)}if(sidePins.leftSide.length===0&&sidePins.rightSide.length===0&&sidePins.topSide.length===0&&sidePins.bottomSide.length===0)return null;let arrangement={};return sidePins.leftSide.length>0&&(arrangement.leftSide={pins:sidePins.leftSide,direction:"top-to-bottom"}),sidePins.rightSide.length>0&&(arrangement.rightSide={pins:sidePins.rightSide,direction:"top-to-bottom"}),sidePins.topSide.length>0&&(arrangement.topSide={pins:sidePins.topSide,direction:"left-to-right"}),sidePins.bottomSide.length>0&&(arrangement.bottomSide={pins:sidePins.bottomSide,direction:"left-to-right"}),arrangement}_getSchematicPortArrangement(){return super._getSchematicPortArrangement()??this._getSchematicPortArrangementFromPortDirections()}_ensureSchematicBoxPortsFromConnections(){if(this._parsedProps?.showAsSchematicBox&&this._parsedProps?.connections)for(let[pinName,target]of Object.entries(this._parsedProps.connections)){if(this.children.find(child=>child.componentName==="Port"&&child.isMatchingAnyOf([pinName])))continue;let pinNumberMatch=pinName.match(/^pin(\d+)$/i)??pinName.match(/^(\d+)$/),pinNumber=pinNumberMatch?Number(pinNumberMatch[1]):void 0;this.add(new Port({name:pinName,pinNumber,connectsTo:target}))}}doInitialInitializePortsFromChildren(){super.doInitialInitializePortsFromChildren(),this._ensureSchematicBoxPortsFromConnections()}updateInitializePortsFromChildren(){super.updateInitializePortsFromChildren(),this._ensureSchematicBoxPortsFromConnections()}_getPrimaryPinCount(){let superPinCount=super._getPrimaryPinCount();if(!this._parsedProps?.showAsSchematicBox)return superPinCount;let directPortPinNumbers=this.children.filter(child=>child.componentName==="Port").map(port=>port._parsedProps.pinNumber).filter(pinNumber=>pinNumber!==void 0);return directPortPinNumbers.length===0?superPinCount:Math.max(superPinCount,...directPortPinNumbers)}_getPinLabelsFromPorts(){return this._parsedProps?.showAsSchematicBox?getGroupSchematicBoxPinLabels(this):super._getPinLabelsFromPorts()}doInitialSourceGroupRender(){let{db:db22}=this.root,hasExplicitName=typeof this._parsedProps.name=="string"&&this._parsedProps.name.length>0,source_group3=db22.source_group.insert({name:this.name,is_subcircuit:this.isSubcircuit,was_automatically_named:!hasExplicitName});this.source_group_id=source_group3.source_group_id,this.isSubcircuit&&(this.subcircuit_id=`subcircuit_${source_group3.source_group_id}`,db22.source_group.update(source_group3.source_group_id,{subcircuit_id:this.subcircuit_id}))}doInitialSourceRender(){let{db:db22}=this.root;for(let child of this.getDescendants())child.getGroup()?.source_group_id===this.source_group_id&&db22.source_component.update(child.source_component_id,{source_group_id:this.source_group_id});if(!this.isSubcircuit)return;let disabledLegacyAutorouterPreset=getDisabledLegacyAutorouterPreset(this);disabledLegacyAutorouterPreset&&db22.source_invalid_component_property_error.insert({source_component_id:this.source_component_id??"",property_name:"autorouter",error_type:"source_invalid_component_property_error",message:`The "${disabledLegacyAutorouterPreset}" autorouter is deprecated and is not enabled by this platform. Use the default autorouter and introduce <autoroutingphase /> or <fanout /> elements as needed.`})}doInitialSourceParentAttachment(){let{db:db22}=this.root,parentGroup=this.parent?.getGroup?.();if(parentGroup?.source_group_id&&db22.source_group.update(this.source_group_id,{parent_source_group_id:parentGroup.source_group_id}),!this.isSubcircuit||isAssemblyDeviceContainer(this.parent))return;let parent_subcircuit_id=this.parent?.getSubcircuit?.()?.subcircuit_id;parent_subcircuit_id&&db22.source_group.update(this.source_group_id,{parent_subcircuit_id})}doInitialPcbComponentRender(){if(this.root?.pcbDisabled)return;let{db:db22}=this.root,{_parsedProps:props}=this,groupProps22=props,hasOutline=groupProps22.outline&&groupProps22.outline.length>0,numericOutline=hasOutline?groupProps22.outline.map(point62=>({x:distance.parse(point62.x),y:distance.parse(point62.y)})):void 0,ctx=this.props,anchorPosition=this._getGlobalPcbPositionBeforeLayout(),center2=computeCenterFromAnchorPosition(anchorPosition,ctx),pcb_group3=db22.pcb_group.insert({is_subcircuit:this.isSubcircuit,subcircuit_id:this.subcircuit_id??this.getSubcircuit()?.subcircuit_id,name:this.name,anchor_position:anchorPosition,center:center2,...hasOutline?{outline:numericOutline}:{width:0,height:0},pcb_component_ids:[],source_group_id:this.source_group_id,autorouter_configuration:props.autorouter?{trace_clearance:props.autorouter.traceClearance}:void 0,anchor_alignment:props.pcbAnchorAlignment??null});this.pcb_group_id=pcb_group3.pcb_group_id;for(let child of this.children)db22.pcb_component.update(child.pcb_component_id,{pcb_group_id:pcb_group3.pcb_group_id})}doInitialPcbPrimitiveRender(){this.calculatePcbGroupBounds()}calculatePcbGroupBounds(pcbContentBounds){if(!this.pcb_group_id||this.root?.pcbDisabled)return;let{db:db22}=this.root,props=this._parsedProps,hasOutline=props.outline&&props.outline.length>0,hasExplicitPositioning=this._parsedProps.pcbX!==void 0||this._parsedProps.pcbY!==void 0;if(hasOutline){let numericOutline=props.outline.map(point62=>({x:distance.parse(point62.x),y:distance.parse(point62.y)})),outlineBounds=getBoundsFromPoints(numericOutline);if(!outlineBounds)return;let centerX2=(outlineBounds.minX+outlineBounds.maxX)/2,centerY2=(outlineBounds.minY+outlineBounds.maxY)/2,center22=hasExplicitPositioning?db22.pcb_group.get(this.pcb_group_id)?.center??{x:centerX2,y:centerY2}:{x:centerX2,y:centerY2};db22.pcb_group.update(this.pcb_group_id,{center:center22});return}let contentBounds=pcbContentBounds;if(!contentBounds){let bounds=getBoundsOfPcbComponents(this.children);contentBounds={center:{x:(bounds.minX+bounds.maxX)/2,y:(bounds.minY+bounds.maxY)/2},width:bounds.width,height:bounds.height}}let{width,height}=contentBounds,{x:centerX,y:centerY}=contentBounds.center;if(this.isSubcircuit||this.isRoutingDirective){let{padLeft,padRight,padTop,padBottom}=this._resolvePcbPadding();width+=padLeft+padRight,height+=padTop+padBottom,centerX+=(padRight-padLeft)/2,centerY+=(padTop-padBottom)/2}let resolvedWidth=Number(props.width??width),resolvedHeight=Number(props.height??height),existingCenter=db22.pcb_group.get(this.pcb_group_id)?.center??{x:centerX,y:centerY},shouldUsePcbContentCenter=this.isSubcircuit||this.isRoutingDirective||pcbContentBounds!==void 0,center2=hasExplicitPositioning?shouldUsePcbContentCenter?{x:props.width===void 0?centerX:existingCenter.x,y:props.height===void 0?centerY:existingCenter.y}:existingCenter:{x:centerX,y:centerY};if(hasExplicitPositioning&&props.pcbAnchorAlignment){let anchorPosition=this._getGlobalPcbPositionBeforeLayout(),anchorAlignedCenter=computeCenterFromAnchorPosition(anchorPosition,{...this.props,width:resolvedWidth,height:resolvedHeight});(Math.abs(anchorAlignedCenter.x-center2.x)>1e-6||Math.abs(anchorAlignedCenter.y-center2.y)>1e-6)&&this._repositionOnPcb(anchorAlignedCenter),center2=anchorAlignedCenter}db22.pcb_group.update(this.pcb_group_id,{width:resolvedWidth,height:resolvedHeight,center:center2})}updatePcbPrimitiveRender(){this.calculatePcbGroupBounds()}getNextAvailableName(elm){var _a543,_b6;return(_a543=this.unnamedElementCounter)[_b6=elm.lowercaseComponentName]??(_a543[_b6]=1),`unnamed_${elm.lowercaseComponentName}${this.unnamedElementCounter[elm.lowercaseComponentName]++}`}_resolvePcbPadding(){let props=this._parsedProps,layout=props.pcbLayout,getPaddingValue=key=>{let layoutValue=layout?.[key],propsValue=props[key];if(typeof layoutValue=="number")return layoutValue;if(typeof propsValue=="number")return propsValue},generalPadding=getPaddingValue("padding")??0,paddingX=getPaddingValue("paddingX"),paddingY=getPaddingValue("paddingY"),padLeft=getPaddingValue("paddingLeft")??paddingX??generalPadding,padRight=getPaddingValue("paddingRight")??paddingX??generalPadding,padTop=getPaddingValue("paddingTop")??paddingY??generalPadding,padBottom=getPaddingValue("paddingBottom")??paddingY??generalPadding;return{padLeft,padRight,padTop,padBottom}}doInitialCreateTraceHintsFromProps(){let{_parsedProps:props}=this,{db:db22}=this.root,groupProps22=props;if(!this.isSubcircuit)return;let manualTraceHints=groupProps22.manualEdits?.manual_trace_hints;if(manualTraceHints)for(let manualTraceHint of manualTraceHints)this.add(new TraceHint({for:manualTraceHint.pcb_port_selector,offsets:manualTraceHint.offsets}))}doInitialSourceAddConnectivityMapKey(){Group_doInitialSourceAddConnectivityMapKey(this),Group_doInitialAssignSchematicSheetToConnectedComponents(this)}_areChildSubcircuitsRouted(){let subcircuitChildren=this._findDirectChildSubcircuits();for(let subcircuitChild of subcircuitChildren)if(!subcircuitChild._isInflatedFromCircuitJson&&subcircuitChild._hasTracesToRoute()&&subcircuitChild._shouldRouteAsync()&&!subcircuitChild._asyncAutoroutingResult)return!1;return!0}_findDirectChildSubcircuits(){let result=[],visit=children=>{for(let child of children)child.isSubcircuit&&child!==this?result.push(child):visit(child.children)};return visit(this.children),result}_shouldRouteAsync(){if(this._isLegacyAutorouterDisabled())return!1;let autorouter=this._getAutorouterConfig();return autorouter.groupMode==="sequential-trace"?!1:!!(autorouter.local&&autorouter.groupMode==="subcircuit"||!autorouter.local)}_getRoutingPhasePlans(){return Group_getRoutingPhasePlans(this)}_hasTracesToRoute(){let debug132=(0,import_debug11.default)("tscircuit:core:_hasTracesToRoute"),routingPhasePlans=this._getRoutingPhasePlans(),traceCount=0,hasReroutePhaseWithExistingTraceInput=!1;for(let routingPhasePlan of routingPhasePlans){traceCount+=routingPhasePlan.traces.length;let phaseAutorouterConfig=routingPhasePlan.autorouter?getPresetAutoroutingConfig(routingPhasePlan.autorouter,this.root?.platform):void 0;hasReroutePhaseWithExistingTraceInput||(hasReroutePhaseWithExistingTraceInput=!!(routingPhasePlan.reroute&&(routingPhasePlan.region||phaseAutorouterConfig?.preset==="simplify")))}if(debug132(`[${this.getString()}] has ${traceCount} traces to route`),traceCount>0)return!0;if(hasReroutePhaseWithExistingTraceInput){let existingTraceCount=getExistingPcbTracesForReroute(this).length;return debug132(`[${this.getString()}] has ${existingTraceCount} existing pcb traces available for reroute`),existingTraceCount>0}return!1}async _runEffectMakeHttpAutoroutingRequest(){let{db:db22}=this.root,debug132=(0,import_debug11.default)("tscircuit:core:_runEffectMakeHttpAutoroutingRequest"),props=this._parsedProps,autorouterConfig3=this._getAutorouterConfig(),serverUrl=autorouterConfig3.serverUrl,serverMode=autorouterConfig3.serverMode,fetchWithDebug=(url3,options)=>(debug132("fetching",url3),options.headers&&(options.headers["Tscircuit-Core-Version"]=this.root?.getCoreVersion()),fetch(url3,options)),pcbAndSourceCircuitJson=this.root.db.toArray().filter(element=>element.type.startsWith("source_")||element.type.startsWith("pcb_"));if(serverMode==="solve-endpoint"){if(this.props.autorouter?.inputFormat==="simplified"){let preferredTraceWidth=props.defaultTraceWidth??props.nominalTraceWidth,{simpleRouteJson}=getSimpleRouteJsonFromCircuitJson({db:db22,minTraceWidth:Number(props.minTraceWidth??.15),nominalTraceWidth:preferredTraceWidth!=null?Number(preferredTraceWidth):void 0,subcircuit_id:this.subcircuit_id,subcircuitComponent:this});simpleRouteJson.allowViaInPad=autorouterConfig3.allowViaInPad;let{autorouting_result:autorouting_result2}=await fetchWithDebug(`${serverUrl}/autorouting/solve`,{method:"POST",body:JSON.stringify({input_simple_route_json:simpleRouteJson,subcircuit_id:this.subcircuit_id}),headers:{"Content-Type":"application/json"}}).then(r22=>r22.json());this._asyncAutoroutingResult=autorouting_result2,this._markDirty("PcbTraceRender");return}let{autorouting_result}=await fetchWithDebug(`${serverUrl}/autorouting/solve`,{method:"POST",body:JSON.stringify({input_circuit_json:pcbAndSourceCircuitJson,subcircuit_id:this.subcircuit_id}),headers:{"Content-Type":"application/json"}}).then(r22=>r22.json());this._asyncAutoroutingResult=autorouting_result,this._markDirty("PcbTraceRender");return}let{autorouting_job}=await fetchWithDebug(`${serverUrl}/autorouting/jobs/create`,{method:"POST",body:JSON.stringify({input_circuit_json:pcbAndSourceCircuitJson,provider:"freerouting",autostart:!0,display_name:this.root?.name,subcircuit_id:this.subcircuit_id,server_cache_enabled:autorouterConfig3.serverCacheEnabled}),headers:{"Content-Type":"application/json"}}).then(r22=>r22.json());for(;;){let{autorouting_job:job}=await fetchWithDebug(`${serverUrl}/autorouting/jobs/get`,{method:"POST",body:JSON.stringify({autorouting_job_id:autorouting_job.autorouting_job_id}),headers:{"Content-Type":"application/json"}}).then(r22=>r22.json());if(job.is_finished){let{autorouting_job_output}=await fetchWithDebug(`${serverUrl}/autorouting/jobs/get_output`,{method:"POST",body:JSON.stringify({autorouting_job_id:autorouting_job.autorouting_job_id}),headers:{"Content-Type":"application/json"}}).then(r22=>r22.json());this._asyncAutoroutingResult={output_pcb_traces:autorouting_job_output.output_pcb_traces},this._markDirty("PcbTraceRender");break}if(job.has_error){let err2=new AutorouterError(`Autorouting job failed: ${JSON.stringify(job.error)}`);throw db22.pcb_autorouting_error.insert({pcb_error_id:autorouting_job.autorouting_job_id,error_type:"pcb_autorouting_error",message:err2.message}),err2}await new Promise(resolve7=>setTimeout(resolve7,100))}}async _runLocalAutorouting(){let{db:db22}=this.root,props=this._parsedProps,debug132=(0,import_debug11.default)("tscircuit:core:_runLocalAutorouting");debug132(`[${this.getString()}] starting local autorouting`);let autorouterConfig3=this._getAutorouterConfig(),isLaserPrefabPreset=this._isLaserPrefabAutorouter(autorouterConfig3),isAutoJumperPreset=this._isAutoJumperAutorouter(autorouterConfig3),isSingleLayerBoard=this._getSubcircuitLayerCount()===1,minTraceWidth=Number(props.minTraceWidth??.15),nominalTraceWidth=Number(props.defaultTraceWidth??props.nominalTraceWidth??minTraceWidth),routingPhasePlans=this._getRoutingPhasePlans(),hasPhasedAutorouting=this.getInheritedProperty("routeRemaining")===!1||Group_hasPhasedAutorouting(routingPhasePlans),shouldEmitRoutingPhaseDebugObjects=routingPhasePlans.length>1,routingPhaseDebugLabels=new Map;if(shouldEmitRoutingPhaseDebugObjects)for(let debugObject of db22.pcb_debug_object.list())debugObject.subcircuit_id===this.subcircuit_id&&(debugObject.label?.startsWith("Autorouting phase: ")||debugObject.label?.startsWith("autorouting phase "))&&db22.pcb_debug_object.delete(debugObject.pcb_debug_object_id);let emitRoutingPhaseDebugObject=(routingPhasePlan,bounds)=>{if(!shouldEmitRoutingPhaseDebugObjects)return;let phaseLabel=routingPhaseDebugLabels.get(routingPhasePlan),phaseName=routingPhasePlan.phaseName?.trim();db22.pcb_debug_object.insert({shape:"rect",center:{x:(bounds.minX+bounds.maxX)/2,y:(bounds.minY+bounds.maxY)/2},size:{width:bounds.maxX-bounds.minX,height:bounds.maxY-bounds.minY},label:`autorouting phase ${phaseLabel}${phaseName?` ${phaseName}`:""}`,subcircuit_id:this.subcircuit_id??void 0})},routingStages=routingPhasePlans.flatMap(routingPhasePlan=>{let resolvedPhaseAutorouterConfig=routingPhasePlan.autorouter?getPresetAutoroutingConfig(routingPhasePlan.autorouter,this.root?.platform):autorouterConfig3,preset=resolvedPhaseAutorouterConfig.preset,implicitPhaseLabel=routingPhasePlan.reroute?preset==="simplify"?"simplify":"reroute":routingPhasePlan.fanoutRegionPcbGroupId?routingPhasePlan.autorouter==="default"&&!routingPhasePlan.getPrecomputedRoutingResult?"breakout":"fanout":preset&&preset!=="default"?preset.replaceAll("_"," "):"default";routingPhaseDebugLabels.set(routingPhasePlan,routingPhasePlan.routingPhaseIndex?.toString()??implicitPhaseLabel);let phaseAutorouterConfig=routingPhasePlan.getPrecomputedRoutingResult?{...resolvedPhaseAutorouterConfig,allowViaInPad:(typeof routingPhasePlan.autorouter=="object"?routingPhasePlan.autorouter.allowViaInPad:void 0)??autorouterConfig3.allowViaInPad}:resolvedPhaseAutorouterConfig,stages=getLocalAutoroutingStages(routingPhasePlan.algorithmFn?{...phaseAutorouterConfig,algorithmFn:routingPhasePlan.algorithmFn}:phaseAutorouterConfig,this.root?.platform);return stages.map((stage,phaseStageIndex)=>({...stage,routingPhasePlan,phaseStageIndex,phaseStageCount:stages.length}))}),implicitPhaseLabelCounts=new Map;for(let plan of routingPhasePlans){if(plan.routingPhaseIndex!==null)continue;let label=routingPhaseDebugLabels.get(plan);implicitPhaseLabelCounts.set(label,(implicitPhaseLabelCounts.get(label)??0)+1)}let implicitPhaseLabelOrdinals=new Map;for(let plan of routingPhasePlans){if(plan.routingPhaseIndex!==null)continue;let label=routingPhaseDebugLabels.get(plan);if(implicitPhaseLabelCounts.get(label)<=1)continue;let ordinal=(implicitPhaseLabelOrdinals.get(label)??0)+1;implicitPhaseLabelOrdinals.set(label,ordinal),routingPhaseDebugLabels.set(plan,`${label} ${ordinal}`)}let fanoutPourNetMap=routingStages.some(({autorouterConfig:autorouterConfig22})=>["fanout","single_layer_fanout","dogbone"].includes(autorouterConfig22.preset??""))?Group_getFanoutPourNetMap(this,routingPhasePlans):void 0,{simpleRouteJson:baseSimpleRouteJson}=getSimpleRouteJsonFromCircuitJson({db:db22,minTraceWidth,nominalTraceWidth,subcircuit_id:this.subcircuit_id,subcircuitComponent:this,fanoutPourNetMap}),emitFanoutBoundsConflictWarning=routingPhasePlan=>{let fanoutRegionPcbGroupId=routingPhasePlan.fanoutRegionPcbGroupId;if(!fanoutRegionPcbGroupId)return;let pcbGroup=db22.pcb_group.get(fanoutRegionPcbGroupId),sourceComponentId=db22.pcb_component.list().find(component=>component.pcb_group_id===fanoutRegionPcbGroupId)?.source_component_id;if(!sourceComponentId)return;let message=`${pcbGroup?.name??"Breakout"} defines conflicting fanout bounds with explicit breakout geometry and fanoutBoundaryPadding. Explicit breakout geometry takes precedence, so fanoutBoundaryPadding is ignored.`;db22.source_property_ignored_warning.list().some(warning=>warning.source_component_id===sourceComponentId&&warning.property_name==="fanoutBoundaryPadding"&&warning.message===message)||db22.source_property_ignored_warning.insert({source_component_id:sourceComponentId,property_name:"fanoutBoundaryPadding",message,error_type:"source_property_ignored_warning",subcircuit_id:pcbGroup?.subcircuit_id})},fanoutConfigByPhasePlan=new Map;for(let routingStage of routingStages){let fanoutMode=routingStage.autorouterConfig.preset;(fanoutMode==="fanout"||fanoutMode==="single_layer_fanout")&&!fanoutConfigByPhasePlan.has(routingStage.routingPhasePlan)&&fanoutConfigByPhasePlan.set(routingStage.routingPhasePlan,routingStage.autorouterConfig)}let fanoutPhaseRegions=[];for(let[routingPhasePlan,phaseAutorouterConfig]of fanoutConfigByPhasePlan){let fanoutRegionPcbGroupId=routingPhasePlan.fanoutRegionPcbGroupId;if(!fanoutRegionPcbGroupId)continue;let phaseSimpleRouteJson=Group_filterSimpleRouteJsonForPhase(baseSimpleRouteJson,routingPhasePlan);if(phaseSimpleRouteJson.connections.length===0)continue;phaseSimpleRouteJson=Group_applyDrcTolerancesToSimpleRouteJson(phaseSimpleRouteJson,routingPhasePlan.drcTolerances);let breakoutPoints=db22.pcb_breakout_point.list().filter(point62=>point62.pcb_group_id===fanoutRegionPcbGroupId).map(point62=>({x:point62.x,y:point62.y})),fanoutMode=phaseAutorouterConfig.preset,fanoutBounds=FanoutAutorouter.resolveFanoutBounds(phaseSimpleRouteJson,{mode:fanoutMode,busFanoutDirections:routingPhasePlan.busFanoutDirections,fanoutBounds:routingPhasePlan.fanoutBounds,fanoutBoundaryPadding:routingPhasePlan.fanoutBoundaryPadding,fanoutRoutingLayers:routingPhasePlan.fanoutRoutingLayers,allowBlindAndBuriedVias:phaseSimpleRouteJson.allowBlindAndBuriedVias,breakoutPoints,onFanoutBoundsConflict:()=>emitFanoutBoundsConflictWarning(routingPhasePlan)});if(routingPhasePlan.fanoutBounds=fanoutBounds,!fanoutBounds)continue;let pcbGroup=db22.pcb_group.get(fanoutRegionPcbGroupId),maximumTraceWidth=Math.max(phaseSimpleRouteJson.minTraceWidth,...phaseSimpleRouteJson.connections.map(connection=>connection.nominalTraceWidth??connection.width??phaseSimpleRouteJson.minTraceWidth)),viaPadDiameter=phaseSimpleRouteJson.minViaPadDiameter??phaseSimpleRouteJson.min_via_pad_diameter??phaseSimpleRouteJson.minViaDiameter,traceToPadClearance=phaseSimpleRouteJson.minTraceToPadEdgeClearance??phaseSimpleRouteJson.defaultObstacleMargin??maximumTraceWidth;fanoutPhaseRegions.push({regionId:fanoutRegionPcbGroupId,name:pcbGroup?.name??routingPhasePlan.phaseName??fanoutRegionPcbGroupId,bounds:fanoutBounds,boundaryKeepaway:getFanoutBoundaryPointSpacing({traceWidth:maximumTraceWidth,traceToPadClearance,viaPadDiameter})/2})}let fanoutSeparationConflict=findFanoutPhaseSeparationConflict(fanoutPhaseRegions);if(fanoutSeparationConflict){let{firstRegion,secondRegion,availableGap,requiredGap}=fanoutSeparationConflict,separationDescription=availableGap<0?`overlap by ${Math.abs(availableGap).toFixed(3)}mm`:`are only ${availableGap.toFixed(3)}mm apart`,message=`Fanout regions "${firstRegion.name}" and "${secondRegion.name}" ${separationDescription}, but at least ${requiredGap.toFixed(3)}mm of separation is required for a via-safe routing channel. Move the components farther apart or reduce their facing fanout padding.`;throw db22.pcb_autorouting_error.insert({pcb_error_id:`pcb_autorouter_error_subcircuit_${this.subcircuit_id}`,error_type:"pcb_autorouting_error",message}),this.root?.emit("autorouting:error",{subcircuit_id:this.subcircuit_id,componentDisplayName:this.getString(),error:{message},simpleRouteJson:baseSimpleRouteJson}),new Error(message)}for(let{regionId,bounds}of fanoutPhaseRegions)db22.pcb_group.update(regionId,{center:{x:(bounds.minX+bounds.maxX)/2,y:(bounds.minY+bounds.maxY)/2},width:bounds.maxX-bounds.minX,height:bounds.maxY-bounds.minY});let outputTraces=[],outputJumpers=[],pcbTraceIdsToDelete=new Set,existingRerouteSeedTraces=getExistingSimplifiedPcbTracesForReroute(this),traceMatchesRoutingPhase=(trace,routingPhasePlan)=>{let connectionName=trace.connection_name??trace.pcb_trace_id,sourceTraceIds=new Set([connectionName,trace.pcb_trace_id,...getSourceTraceIdsFromRerouteName(connectionName),...getSourceTraceIdsFromRerouteName(trace.pcb_trace_id)]);return baseSimpleRouteJson.connections.some(connection=>connectionIsInRoutingPhase(connection,routingPhasePlan)?sourceTraceIds.has(connection.name)||(connection.source_trace_id?sourceTraceIds.has(connection.source_trace_id):!1)||(connection.rootConnectionName?sourceTraceIds.has(connection.rootConnectionName):!1)||connection.mergedConnectionNames?.some(name=>sourceTraceIds.has(name)):!1)},manualSourceTraceIds=new Set(this.getDescendants().filter(child=>child instanceof Trace&&!child.getSubcircuit()._isInflatedFromCircuitJson&&!!child._parsedProps.pcbPath?.length).map(trace=>trace.source_trace_id)),manualPcbTraceIds=new Set(db22.pcb_trace.list().filter(trace=>trace.source_trace_id&&manualSourceTraceIds.has(trace.source_trace_id)).map(trace=>trace.pcb_trace_id)),fixedTraceIds=new Set(manualPcbTraceIds),previousStageOutputSimpleRouteJson,skippedRemainingPhases=new Set;for(let[routingStageIndex,{routingPhasePlan,autorouterConfig:phaseAutorouterConfig,strategy:localAutorouterStrategy,usesPreviousStageOutput,phaseStageIndex,phaseStageCount}]of routingStages.entries()){if(skippedRemainingPhases.has(routingPhasePlan))continue;if(usesPreviousStageOutput||(previousStageOutputSimpleRouteJson=void 0),usesPreviousStageOutput&&previousStageOutputSimpleRouteJson===void 0)throw new Error("Autorouting follow-up stage is missing the preceding stage output");let simpleRouteJson=previousStageOutputSimpleRouteJson??baseSimpleRouteJson,isTraceSimplificationPhase=!!(routingPhasePlan.reroute&&phaseAutorouterConfig.preset==="simplify"),isRegionReroutePhase=!!(routingPhasePlan.reroute&&routingPhasePlan.region&&!isTraceSimplificationPhase),isConnectionReroutePhase=!!(routingPhasePlan.reroute&&!isTraceSimplificationPhase&&!routingPhasePlan.region&&routingPhasePlan.traces.length>0),isReroutePhase=isRegionReroutePhase||isConnectionReroutePhase||isTraceSimplificationPhase,rerouteOriginalSrj=isRegionReroutePhase?{...baseSimpleRouteJson,traces:[...existingRerouteSeedTraces,...outputTraces]}:null;if(!usesPreviousStageOutput&&isTraceSimplificationPhase)simpleRouteJson={...Group_filterSimpleRouteJsonForPhase(baseSimpleRouteJson,routingPhasePlan),traces:getAccumulatedPcbTracesWithStageOutputReplacements({accumulatedPcbTraces:existingRerouteSeedTraces,stageOutputPcbTraces:outputTraces})};else if(!usesPreviousStageOutput&&isRegionReroutePhase&&rerouteOriginalSrj)simpleRouteJson=dae(rerouteOriginalSrj,{shape:"rect",...routingPhasePlan.region});else if(!usesPreviousStageOutput&&isConnectionReroutePhase){let phaseInput=Group_filterSimpleRouteJsonForPhase(baseSimpleRouteJson,routingPhasePlan);simpleRouteJson={...phaseInput,traces:[...phaseInput.traces??[],...outputTraces.filter(trace=>!traceMatchesRoutingPhase(trace,routingPhasePlan))]}}else if(!usesPreviousStageOutput&&hasPhasedAutorouting){let phaseInput=Group_filterSimpleRouteJsonForPhase(baseSimpleRouteJson,routingPhasePlan),activeCustomBreakoutRoutingGroupId=routingPhasePlan.routingPcbGroupId;if(activeCustomBreakoutRoutingGroupId){let activeGroupCopperPourObstacles=getSimpleRouteJsonFromCircuitJson({db:db22,minTraceWidth,nominalTraceWidth,subcircuit_id:this.subcircuit_id,subcircuitComponent:this,routingPcbGroupId:activeCustomBreakoutRoutingGroupId,fanoutPourNetMap}).simpleRouteJson.obstacles.filter(obstacle=>obstacle.isCopperPour),nonCopperPourObstacles=phaseInput.obstacles.filter(obstacle=>!obstacle.isCopperPour);phaseInput.obstacles=nonCopperPourObstacles.concat(activeGroupCopperPourObstacles)}simpleRouteJson={...phaseInput,traces:getAccumulatedPcbTracesWithStageOutputReplacements({accumulatedPcbTraces:phaseInput.traces??[],stageOutputPcbTraces:outputTraces})}}if(phaseAutorouterConfig.preset!=="bus_lanes"){let preservesManualTraceGeometry=!phaseAutorouterConfig.algorithmFn&&(phaseAutorouterConfig.preset==="fanout"||phaseAutorouterConfig.preset==="single_layer_fanout");simpleRouteJson=withFixedTraces(simpleRouteJson,preservesManualTraceGeometry?new Set([...fixedTraceIds].filter(pcbTraceId=>!manualPcbTraceIds.has(pcbTraceId))):fixedTraceIds)}simpleRouteJson=Group_applyDrcTolerancesToSimpleRouteJson(simpleRouteJson,routingPhasePlan.drcTolerances),simpleRouteJson.allowViaInPad=phaseAutorouterConfig.allowViaInPad;let getPrecomputedRoutingResult=usesPreviousStageOutput?void 0:routingPhasePlan.getPrecomputedRoutingResult,preflightRoutingCheckPolicy3=this.getInheritedProperty("preflightRoutingCheckPolicy");if(routingPhasePlan.isImplicitRemainingPhase&&phaseStageIndex===0&&this.getInheritedProperty("routeRemaining")===void 0&&(preflightRoutingCheckPolicy3==="basic"||preflightRoutingCheckPolicy3==="conservative")&&simpleRouteJson.connections.length>50){skippedRemainingPhases.add(routingPhasePlan),db22.pcb_autorouting_error.insert({pcb_error_id:`pcb_autorouting_error_remaining_routes_${this.subcircuit_id}`,subcircuit_id:this.subcircuit_id??void 0,error_type:"pcb_autorouting_error",message:`Remaining routes left unrouted (over 50 traces remaining and preflightRoutingCheckPolicy="${preflightRoutingCheckPolicy3}"). Set <board routeRemaining={true} /> or create <autoroutingphase /> elements for specific connections in the order you'd like to route them. The autorouter may hang unless you create autorouting phases incrementally.`});continue}let simplificationHasNoTraceInput=!!(isTraceSimplificationPhase&&simpleRouteJson.traces?.length===0);if((hasPhasedAutorouting||isReroutePhase||usesPreviousStageOutput)&&(simpleRouteJson.connections.length===0&&!isTraceSimplificationPhase&&!getPrecomputedRoutingResult||simplificationHasNoTraceInput)){phaseStageIndex===0&&emitRoutingPhaseDebugObject(routingPhasePlan,simpleRouteJson.bounds),previousStageOutputSimpleRouteJson=simpleRouteJson;continue}let phaseIsAutoJumperPreset=routingPhasePlan.autorouter!==void 0?this._isAutoJumperAutorouter(phaseAutorouterConfig):isAutoJumperPreset,phaseIsLaserPrefabPreset=routingPhasePlan.autorouter!==void 0?this._isLaserPrefabAutorouter(phaseAutorouterConfig):isLaserPrefabPreset;phaseIsAutoJumperPreset&&(simpleRouteJson.allowJumpers=!0,phaseAutorouterConfig.availableJumperTypes&&(simpleRouteJson.availableJumperTypes=phaseAutorouterConfig.availableJumperTypes));let fanoutMode=phaseAutorouterConfig.preset;if((fanoutMode==="fanout"||fanoutMode==="single_layer_fanout")&&!routingPhasePlan.fanoutRegionPcbGroupId&&!getPrecomputedRoutingResult&&(routingPhasePlan.fanoutBounds=FanoutAutorouter.resolveFanoutBounds(simpleRouteJson,{mode:fanoutMode,busFanoutDirections:routingPhasePlan.busFanoutDirections,fanoutBounds:routingPhasePlan.fanoutBounds,fanoutBoundaryPadding:routingPhasePlan.fanoutBoundaryPadding,fanoutRoutingLayers:routingPhasePlan.fanoutRoutingLayers,allowBlindAndBuriedVias:simpleRouteJson.allowBlindAndBuriedVias})),phaseStageIndex===0&&emitRoutingPhaseDebugObject(routingPhasePlan,routingPhasePlan.fanoutBounds??simpleRouteJson.bounds),debug132.enabled&&global.debugOutputArray?.push({name:`simpleroutejson-${this.props.name}.json`,obj:simpleRouteJson}),debug132.enabled){let graphicsObject=Go2(simpleRouteJson);graphicsObject.title=`autorouting-${this.props.name}`,global.debugGraphics?.push(graphicsObject)}let autorouterVersion22=phaseAutorouterConfig.autorouterVersion??this.props.autorouterVersion,effortLevel=this.props.autorouterEffortLevel,effort=effortLevel?Number.parseInt(effortLevel.replace("x",""),10):void 0,commonAutorouterOptions={capacityDepth:phaseAutorouterConfig.capacityDepth,targetMinCapacity:phaseAutorouterConfig.targetMinCapacity,platformConfig:this.root?.platform,useAssignableSolver:phaseIsLaserPrefabPreset||isSingleLayerBoard,useAutoJumperSolver:phaseIsAutoJumperPreset,useLaserPrefabSolver:phaseIsLaserPrefabPreset,autorouterVersion:autorouterVersion22,effort},autorouterName=getPrecomputedRoutingResult?"precomputed":phaseAutorouterConfig.algorithmFn?"custom":localAutorouterStrategy.name,solverName=getPrecomputedRoutingResult||phaseAutorouterConfig.algorithmFn?void 0:localAutorouterStrategy.getSolverName(commonAutorouterOptions),localAutoroutingCacheSolverOptions={autorouterName,solverName,capacityDepth:commonAutorouterOptions.capacityDepth,targetMinCapacity:commonAutorouterOptions.targetMinCapacity,useAssignableSolver:commonAutorouterOptions.useAssignableSolver,useAutoJumperSolver:commonAutorouterOptions.useAutoJumperSolver,useLaserPrefabSolver:commonAutorouterOptions.useLaserPrefabSolver,useTraceSimplificationSolver:phaseAutorouterConfig.preset==="simplify",autorouterVersion:commonAutorouterOptions.autorouterVersion,effort:commonAutorouterOptions.effort},cacheEngine=getPrecomputedRoutingResult||phaseAutorouterConfig.algorithmFn||!localAutorouterStrategy.cacheable?void 0:this.root?.platform?.localCacheEngine,cacheKey=cacheEngine?getLocalAutoroutingCacheKey(simpleRouteJson,localAutoroutingCacheSolverOptions):void 0,cachedResult=cacheKey?await getCachedLocalAutoroutingPhaseResult({cacheEngine,cacheKey}):null,cacheDisabledReason=getPrecomputedRoutingResult?"precomputed":phaseAutorouterConfig.algorithmFn?"custom_algorithm":localAutorouterStrategy.cacheable?cacheEngine?void 0:"no_cache_engine":"strategy_not_cacheable",autoroutingMetadata={routingPhaseIndex:routingPhasePlan.routingPhaseIndex,_actualRoutingPhaseOrderIndex:routingStageIndex,phaseOrdinal:routingStageIndex+1,phaseCount:routingStages.length,connectionCount:simpleRouteJson.connections.length,obstacleCount:simpleRouteJson.obstacles.length,previousTraceCount:simpleRouteJson.traces?.length??0,isReroutePhase,autorouterName,autorouterVersion:autorouterVersion22,solverName,effort,cacheStatus:cacheEngine?cachedResult?"hit":"miss":"disabled",cacheKey,cacheDisabledReason};this.root?.emit("autorouting:start",{type:"autorouting:start",subcircuit_id:this.subcircuit_id,componentDisplayName:this.getString(),...routingPhasePlan.phaseName!==void 0?{phaseName:routingPhasePlan.phaseName,phaseStageIndex,phaseStageCount}:{},...autoroutingMetadata,simpleRouteJson});let autorouter;try{let traces,precomputedOutputSimpleRouteJson;if(getPrecomputedRoutingResult){let result=getPrecomputedRoutingResult(simpleRouteJson);traces=result.traces,precomputedOutputSimpleRouteJson=result.outputSimpleRouteJson;for(let trace of traces)fixedTraceIds.add(trace.pcb_trace_id)}else if(cachedResult)debug132(`[${this.getString()}] using cached local autorouting result`),traces=cachedResult.traces;else{if(phaseAutorouterConfig.algorithmFn?autorouter=await phaseAutorouterConfig.algorithmFn(simpleRouteJson):autorouter=localAutorouterStrategy.create({simpleRouteJson,onSolverEnded:event=>this.root?.emit("solver:ended",{...event,type:"solver:ended",componentName:this.getString()}),commonAutorouterOptions,busFanoutDirections:routingPhasePlan.busFanoutDirections,fanoutBounds:routingPhasePlan.fanoutBounds,fanoutRoutingLayers:routingPhasePlan.fanoutRoutingLayers,allowBlindAndBuriedVias:simpleRouteJson.allowBlindAndBuriedVias,componentNamesById:getPcbComponentNamesById(db22),onSolverStarted:({solverName:solverName2,solverParams,solverConstructorArgs})=>this.root?.emit("solver:started",{type:"solver:started",solverName:solverName2,solverParams,solverConstructorArgs,componentName:this.getString()})}),!autorouter)throw new Error("Failed to create local autorouter");let activeAutorouter=autorouter,routingPromise=new Promise((resolve7,reject)=>{activeAutorouter.on("complete",event=>{debug132(`[${this.getString()}] local autorouting complete`),resolve7(event.traces)}),activeAutorouter.on("error",event=>{debug132(`[${this.getString()}] local autorouting error: ${event.error.message}`),reject(event.error)})});activeAutorouter.on("progress",event=>{this.root?.emit("autorouting:progress",{subcircuit_id:this.subcircuit_id,componentDisplayName:this.getString(),...routingPhasePlan.phaseName!==void 0?{phaseName:routingPhasePlan.phaseName,phaseStageIndex,phaseStageCount}:{},...autoroutingMetadata,...event,type:"autorouting:progress"})}),activeAutorouter.start(),traces=await routingPromise}let transformedSimpleRouteJson=precomputedOutputSimpleRouteJson??autorouter?.getOutputSimpleRouteJson?.();if(transformedSimpleRouteJson&&!usesPreviousStageOutput&&["fanout","single_layer_fanout","dogbone"].includes(phaseAutorouterConfig.preset??"")&&routingPhasePlan.routingPcbGroupId){let synchronizedFanout=Group_syncFanoutExitsWithGlobalConnections({fanoutInputSimpleRouteJson:simpleRouteJson,fanoutOutputSimpleRouteJson:transformedSimpleRouteJson,baseSimpleRouteJson,routingPhasePlan});baseSimpleRouteJson=synchronizedFanout.baseSimpleRouteJson,transformedSimpleRouteJson=synchronizedFanout.downstreamSimpleRouteJson;for(let synchronizedPoint of synchronizedFanout.synchronizedBreakoutPoints){let breakoutPoint=db22.pcb_breakout_point.list().find(point62=>point62.pcb_group_id===synchronizedPoint.routingPcbGroupId&&point62.source_trace_id===synchronizedPoint.sourceTraceId&&Math.abs(point62.x-synchronizedPoint.previousPoint.x)<=1e-6&&Math.abs(point62.y-synchronizedPoint.previousPoint.y)<=1e-6);breakoutPoint&&db22.pcb_breakout_point.update(breakoutPoint.pcb_breakout_point_id,{x:synchronizedPoint.fanoutExitPoint.x,y:synchronizedPoint.fanoutExitPoint.y,layer:synchronizedPoint.fanoutExitPoint.layer})}}if(localAutorouterStrategy.preserveOutputTraces)for(let trace of traces)fixedTraceIds.add(trace.pcb_trace_id);let stageOutputTraces=traces;transformedSimpleRouteJson?.traces?stageOutputTraces=transformedSimpleRouteJson.traces:usesPreviousStageOutput&&(stageOutputTraces=getAccumulatedPcbTracesWithStageOutputReplacements({accumulatedPcbTraces:simpleRouteJson.traces??[],stageOutputPcbTraces:traces}));let eventOutputPcbTraces=stageOutputTraces;!transformedSimpleRouteJson&&!usesPreviousStageOutput&&routingPhasePlan.routingPhaseIndex!==null&&(eventOutputPcbTraces=getAccumulatedPcbTracesWithStageOutputReplacements({accumulatedPcbTraces:simpleRouteJson.traces??[],stageOutputPcbTraces:traces}));let outputSimpleRouteJson={...transformedSimpleRouteJson??simpleRouteJson,traces:eventOutputPcbTraces};previousStageOutputSimpleRouteJson=transformedSimpleRouteJson?outputSimpleRouteJson:void 0,!cachedResult&&cacheKey&&await cacheLocalAutoroutingPhaseResult({cacheEngine,cacheKey,result:{...simpleRouteJson,traces}});let savedPhasePaths=getAutoroutingPhasePcbTracePaths({group:this.selectAll("group").find(group2=>group2.pcb_group_id===routingPhasePlan.fanoutRegionPcbGroupId)??routingPhasePlan.autoroutingPhase?.getGroup()??this,subcircuit:this,input:simpleRouteJson,traces,isFanout:["fanout","single_layer_fanout","dogbone"].includes(phaseAutorouterConfig.preset??"")});if(this.root?.emit("autorouting:end",{...savedPhasePaths,type:"autorouting:end",subcircuit_id:this.subcircuit_id,componentDisplayName:this.getString(),...routingPhasePlan.phaseName!==void 0?{phaseName:routingPhasePlan.phaseName,phaseStageIndex,phaseStageCount}:{},...autoroutingMetadata,simpleRouteJson:outputSimpleRouteJson}),autorouter?.getConnectedOffboardObstacles){let connectedOffboardObstacles=autorouter.getConnectedOffboardObstacles();createSourceTracesFromOffboardConnections({db:db22,connectedOffboardObstacles,simpleRouteJson,subcircuit_id:this.subcircuit_id})}let solver=autorouter?.solver;if(solver?.getOutputJumpers&&outputJumpers.push(...solver.getOutputJumpers()||[]),isRegionReroutePhase&&rerouteOriginalSrj){for(let trace of rerouteOriginalSrj.traces??[])trace.type==="pcb_trace"&&pcbTraceIdsToDelete.add(trace.pcb_trace_id);let reconnectedSrj=uae(rerouteOriginalSrj,{...simpleRouteJson,traces:[...simpleRouteJson.traces??[],...traces]});outputTraces.splice(0,outputTraces.length,...reconnectedSrj.traces??[])}else if(isConnectionReroutePhase){let retainedPcbTraces=outputTraces.filter(trace=>!traceMatchesRoutingPhase(trace,routingPhasePlan));outputTraces.splice(0,outputTraces.length,...getAccumulatedPcbTracesWithStageOutputReplacements({accumulatedPcbTraces:retainedPcbTraces,stageOutputPcbTraces:stageOutputTraces}))}else{if(isTraceSimplificationPhase)for(let existingTrace of existingRerouteSeedTraces)fixedTraceIds.has(existingTrace.pcb_trace_id)||pcbTraceIdsToDelete.add(existingTrace.pcb_trace_id);outputTraces.splice(0,outputTraces.length,...getAccumulatedPcbTracesWithStageOutputReplacements({accumulatedPcbTraces:outputTraces,stageOutputPcbTraces:stageOutputTraces}))}}catch(error2){let{db:db32}=this.root;throw db32.pcb_autorouting_error.insert({pcb_error_id:`pcb_autorouter_error_subcircuit_${this.subcircuit_id}`,error_type:"pcb_autorouting_error",message:error2 instanceof Error?error2.message:String(error2)}),this.root?.emit("autorouting:error",{type:"autorouting:error",subcircuit_id:this.subcircuit_id,componentDisplayName:this.getString(),...routingPhasePlan.phaseName!==void 0?{phaseName:routingPhasePlan.phaseName,phaseStageIndex,phaseStageCount}:{},...autoroutingMetadata,error:{message:error2 instanceof Error?error2.message:String(error2)},simpleRouteJson}),error2}finally{autorouter?.stop()}}this._asyncAutoroutingResult={output_pcb_traces:outputTraces,output_jumpers:outputJumpers,pcb_trace_ids_to_be_replaced:[...pcbTraceIdsToDelete]},this._markDirty("PcbTraceRender")}_startAsyncAutorouting(){this._hasStartedAsyncAutorouting||(this._hasStartedAsyncAutorouting=!0,this._getAutorouterConfig().local?this._queueAsyncEffect("autorouting",async()=>{try{await this._runLocalAutorouting()}catch(error2){if(!(error2 instanceof RoutingPhasePreparationError))throw error2;let{db:db22}=this.root,pcbErrorId=`pcb_autorouter_error_subcircuit_${this.subcircuit_id}`;throw db22.pcb_autorouting_error.list().some(recordedError=>recordedError.pcb_error_id===pcbErrorId&&recordedError.message===error2.message)||(db22.pcb_autorouting_error.insert({pcb_error_id:pcbErrorId,error_type:"pcb_autorouting_error",message:error2.message,subcircuit_id:this.subcircuit_id??void 0}),this.root?.emit("autorouting:error",{type:"autorouting:error",subcircuit_id:this.subcircuit_id,componentDisplayName:this.getString(),error:{message:error2.message}})),error2}}):this._queueAsyncEffect("make-http-autorouting-request",async()=>this._runEffectMakeHttpAutoroutingRequest()))}doInitialPcbTraceRender(){let debug132=(0,import_debug11.default)("tscircuit:core:doInitialPcbTraceRender");if(!this.isSubcircuit||this.root?.pcbDisabled||this.root?.pcbRoutingDisabled||this.getInheritedProperty("routingDisabled")||this._isInflatedFromCircuitJson||this._isLegacyAutorouterDisabled()||this._shouldUseTraceByTraceRouting())return;if(!this._areChildSubcircuitsRouted()){debug132(`[${this.getString()}] child subcircuits are not routed, skipping async autorouting until subcircuits routed`);return}if(debug132(`[${this.getString()}] no child subcircuits to wait for, initiating async routing`),!this._hasTracesToRoute())return;let shouldSkipBecauseOfPlacementErrors=shouldSkipAutoroutingBecauseOfPlacementErrors({component:this,subcircuit:this}),shouldSkipBecauseOfTraceLengthViolations=shouldSkipAutoroutingBecauseOfTraceLengthViolations({component:this,subcircuit:this});shouldSkipBecauseOfPlacementErrors||shouldSkipBecauseOfTraceLengthViolations||this._startAsyncAutorouting()}doInitialSchematicTraceRender(){this._parsedProps.showAsSchematicBox||Group_doInitialSchematicTraceRender(this)}doInitialSchematicSheetRender(){Group_doInitialSchematicSheetRender(this)}updateSchematicSheetRender(){Group_updateSchematicSheetRender(this)}updatePcbTraceRender(){let debug132=(0,import_debug11.default)("tscircuit:core:updatePcbTraceRender");if(debug132(`[${this.getString()}] updating...`),!this.isSubcircuit||this._isInflatedFromCircuitJson||this._isLegacyAutorouterDisabled())return;if(this._shouldRouteAsync()&&this._hasTracesToRoute()&&!this._hasStartedAsyncAutorouting){if(this._areChildSubcircuitsRouted()){let shouldSkipBecauseOfPlacementErrors=shouldSkipAutoroutingBecauseOfPlacementErrors({component:this,subcircuit:this}),shouldSkipBecauseOfTraceLengthViolations=shouldSkipAutoroutingBecauseOfTraceLengthViolations({component:this,subcircuit:this});if(shouldSkipBecauseOfPlacementErrors||shouldSkipBecauseOfTraceLengthViolations)return;debug132(`[${this.getString()}] child subcircuits are now routed, starting async autorouting`),this._startAsyncAutorouting()}return}if(!this._asyncAutoroutingResult||this._shouldUseTraceByTraceRouting())return;let{db:db22}=this.root;if(this._asyncAutoroutingResult.output_simple_route_json){debug132(`[${this.getString()}] updating PCB traces from simple route json (${this._asyncAutoroutingResult.output_simple_route_json.traces?.length} traces)`),this._updatePcbTraceRenderFromSimpleRouteJson();return}if(this._asyncAutoroutingResult.output_pcb_traces){debug132(`[${this.getString()}] updating PCB traces from ${this._asyncAutoroutingResult.output_pcb_traces.length} traces`),this._updatePcbTraceRenderFromPcbTraces();return}}_updatePcbTraceRenderFromSimpleRouteJson(){let{db:db22}=this.root,{traces:routedTraces}=this._asyncAutoroutingResult.output_simple_route_json;if(routedTraces)for(let routedTrace of routedTraces){let cjRoute=routedTrace.route.map(point62=>point62.route_type!=="through_obstacle"?point62:{route_type:"through_pad",start:point62.start,end:point62.end,start_layer:point62.from_layer,end_layer:point62.to_layer,width:point62.width,circuitJsonMetadata:point62.circuitJsonMetadata}),pcb_trace3=db22.pcb_trace.insert({subcircuit_id:this.subcircuit_id,route:getCircuitJsonPcbTraceRoute(cjRoute)});claimSrjAssignablePcbViasTraversedByRoute({db:db22,pcbTrace:pcb_trace3,routeWithSrjMetadata:cjRoute})}}_updatePcbTraceRenderFromPcbTraces(){let{output_pcb_traces,output_jumpers,pcb_trace_ids_to_be_replaced}=this._asyncAutoroutingResult;if(!output_pcb_traces)return;let{db:db22}=this.root,pcbStyle3=this.getInheritedMergedProperty("pcbStyle"),{holeDiameter,padDiameter}=getViaDiameterDefaults(pcbStyle3),boardComponent=this._getBoard(),board=boardComponent?.pcb_board_id?db22.pcb_board.get(boardComponent.pcb_board_id):db22.pcb_board.list()[0],routedViaHoleDiameter=board?.min_via_hole_diameter??holeDiameter,routedViaPadDiameter=board?.min_via_pad_diameter??padDiameter;output_jumpers&&output_jumpers.length>0&&insertAutoplacedJumpers({db:db22,output_jumpers,subcircuit_id:this.subcircuit_id}),deleteExistingPcbTracesReplacedBy({group:this,outputPcbTraces:output_pcb_traces,pcbTraceIdsToReplace:pcb_trace_ids_to_be_replaced});let materializedPcbVias=db22.pcb_via.list(),jumperPadInfos=getJumperPadInfos(db22);for(let pcb_trace3 of output_pcb_traces){if(pcb_trace3.type!=="pcb_trace")continue;pcb_trace3.subcircuit_id??(pcb_trace3.subcircuit_id=this.subcircuit_id);let cjRoute=pcb_trace3.route.map(point62=>point62.route_type!=="through_obstacle"?point62:{route_type:"through_pad",start:point62.start,end:point62.end,start_layer:point62.from_layer,end_layer:point62.to_layer,width:point62.width,circuitJsonMetadata:point62.circuitJsonMetadata}),routeSourceTraceId=getSourceTraceIdForRoutedTrace({db:db22,trace:{...pcb_trace3,route:cjRoute},subcircuit_id:this.subcircuit_id});cjRoute=ensureRouteStartsAtSourceTraceStart({db:db22,route:cjRoute,routeThicknessMode:pcb_trace3.route_thickness_mode,sourceTraceId:routeSourceTraceId}),pcb_trace3.route=cjRoute;let segments=splitPcbTracesOnJumperSegments(cjRoute);segments===null&&(segments=[cjRoute]);let processedSegments=addPortIdsToTracesAtJumperPads(segments,jumperPadInfos);for(let segment2 of processedSegments)if(segment2.length>0){let circuitJsonSegment=getCircuitJsonPcbTraceRoute(segment2),sourceTraceId=getSourceTraceIdForRoutedTrace({db:db22,trace:{...pcb_trace3,route:circuitJsonSegment},subcircuit_id:this.subcircuit_id}),insertedPcbTrace=db22.pcb_trace.insert({...pcb_trace3,source_trace_id:sourceTraceId,route:circuitJsonSegment});claimSrjAssignablePcbViasTraversedByRoute({db:db22,pcbTrace:insertedPcbTrace,routeWithSrjMetadata:segment2})}}for(let pcb_trace3 of output_pcb_traces)if(pcb_trace3.type!=="pcb_via"&&pcb_trace3.type==="pcb_trace"){let sourceTraceId=getSourceTraceIdForRoutedTrace({db:db22,trace:pcb_trace3,subcircuit_id:this.subcircuit_id}),{connection_name:inputConnectionName}=pcb_trace3,subcircuitConnectivityMapKey;if(sourceTraceId&&(subcircuitConnectivityMapKey=db22.source_trace.get(sourceTraceId)?.subcircuit_connectivity_map_key),!subcircuitConnectivityMapKey&&inputConnectionName){let sourceNet=db22.source_net.get(inputConnectionName);sourceNet&&(subcircuitConnectivityMapKey=sourceNet.subcircuit_connectivity_map_key)}for(let point62 of pcb_trace3.route)if(point62.route_type==="via"){let routedViaPoint=point62,fromLayer=point62.from_layer,toLayer=point62.to_layer,pcbVia={pcb_trace_id:pcb_trace3.pcb_trace_id,x:point62.x,y:point62.y,hole_diameter:routedViaPoint.via_hole_diameter??routedViaPoint.hole_diameter??routedViaHoleDiameter,outer_diameter:routedViaPoint.via_diameter??routedViaPoint.outer_diameter??routedViaPadDiameter,layers:getAutoroutedViaLayers({fromLayer,toLayer,layerCount:this._getSubcircuitLayerCount(),allowBlindAndBuriedVias:board?.allow_blind_and_buried_vias??!1,physicalLayers:routedViaPoint.layers}),from_layer:fromLayer,to_layer:toLayer,subcircuit_id:this.subcircuit_id,pcb_group_id:this.pcb_group_id??void 0,subcircuit_connectivity_map_key:subcircuitConnectivityMapKey};if(materializedPcbVias.some(materializedPcbVia=>pcbViasSharePhysicalHole(materializedPcbVia,pcbVia)))continue;materializedPcbVias.push(db22.pcb_via.insert(pcbVia))}}}doInitialSchematicComponentRender(){if(this.root?.schematicDisabled)return;let{db:db22}=this.root,{_parsedProps:props}=this,schematic_group3=db22.schematic_group.insert({is_subcircuit:this.isSubcircuit,subcircuit_id:this.subcircuit_id,name:this.name,center:this._getGlobalSchematicPositionBeforeLayout(),width:0,height:0,schematic_component_ids:[],source_group_id:this.source_group_id,show_as_schematic_box:props.showAsSchematicBox??!1});this.schematic_group_id=schematic_group3.schematic_group_id,props.showAsSchematicBox&&Group_doInitialSchematicBoxComponentRender(this);for(let child of this.getDescendants())child.getGroup()?.source_group_id===this.source_group_id&&(child._parsedProps?.showAsSchematicBox||child.schematic_component_id&&db22.schematic_component.update(child.schematic_component_id,{schematic_group_id:schematic_group3.schematic_group_id}))}_getSchematicLayoutMode(){let props=this._parsedProps,schAutoLayoutEnabled=props.schAutoLayoutEnabled??!1;if(props.schLayout?.layoutMode==="none"||props.schLayout?.layoutMode==="relative")return"relative";if(props.schLayout?.matchAdapt)return"match-adapt";if(props.schLayout?.flex)return"flex";if(props.schLayout?.grid)return"grid";if(props.schMatchAdapt)return"match-adapt";if(props.schFlex)return"flex";if(props.schGrid)return"grid";if(props.matchAdapt)return"match-adapt";if(props.flex)return"flex";if(props.grid)return"grid";if(props.relative||props.schRelative)return"relative";let anyLayoutChildHasSchCoords=this.children.some(child=>{let cProps=child._parsedProps;return(child.source_component_id!==null||child.source_group_id!==null)&&(cProps?.schX!==void 0||cProps?.schY!==void 0)}),hasManualEdits=(props.manualEdits?.schematic_placements?.length??0)>0;return schAutoLayoutEnabled&&!hasManualEdits||!anyLayoutChildHasSchCoords&&!hasManualEdits?"match-adapt":"relative"}doInitialSchematicLayout(){if(this._parsedProps.showAsSchematicBox){this._insertSchematicBorder();return}if(this.children.some(c22=>c22.source_component_id!==null&&c22._parsedProps?.schSectionName!==void 0)){this._doInitialSchematicLayoutSections(),this._insertSchematicBorder();return}let schematicLayoutMode=this._getSchematicLayoutMode();schematicLayoutMode==="match-adapt"&&this._doInitialSchematicLayoutMatchpack(),schematicLayoutMode==="grid"&&this._doInitialSchematicLayoutGrid(),schematicLayoutMode==="flex"&&this._doInitialSchematicLayoutFlex(),this._insertSchematicBorder()}_doInitialSchematicLayoutSections(){Group_doInitialSchematicLayoutSections(this)}_doInitialSchematicLayoutMatchAdapt(){Group_doInitialSchematicLayoutMatchAdapt(this)}_doInitialSchematicLayoutMatchpack(){Group_doInitialSchematicLayoutMatchPack(this)}_doInitialSchematicLayoutGrid(){Group_doInitialSchematicLayoutGrid(this)}_doInitialSchematicLayoutFlex(){Group_doInitialSchematicLayoutFlex(this)}_getPcbLayoutMode(){let props=this._parsedProps,rawProps=this.props;if(this._isInflatedFromCircuitJson||props.pcbRelative)return"none";if(props.pcbLayout?.matchAdapt)return"match-adapt";if(props.pcbLayout?.flex)return"flex";if(props.pcbLayout?.grid)return"grid";if(props.pcbLayout?.pack)return"pack";if(props.pcbFlex)return"flex";if(props.pcbGrid)return"grid";if(props.pcbPack||props.pack)return"pack";if(props.matchAdapt)return"match-adapt";if(props.flex)return"flex";if(props.grid)return"grid";let groupHasCoords=props.pcbX!==void 0||props.pcbY!==void 0||props.pcbLeftEdgeX!==void 0||props.pcbRightEdgeX!==void 0||props.pcbTopEdgeY!==void 0||props.pcbBottomEdgeY!==void 0||rawProps.pcbLeftEdgeX!==void 0||rawProps.pcbRightEdgeX!==void 0||rawProps.pcbTopEdgeY!==void 0||rawProps.pcbBottomEdgeY!==void 0,hasManualEdits=(props.manualEdits?.pcb_placements?.length??0)>0,unpositionedDirectChildrenCount=this.children.reduce((count,child)=>{if(!child.pcb_component_id&&!child.pcb_group_id)return count;let childProps=child._parsedProps,rawChildProps=child.props,hasCoords=childProps?.pcbX!==void 0||childProps?.pcbY!==void 0||childProps?.pcbLeftEdgeX!==void 0||childProps?.pcbRightEdgeX!==void 0||childProps?.pcbTopEdgeY!==void 0||childProps?.pcbBottomEdgeY!==void 0||rawChildProps?.pcbLeftEdgeX!==void 0||rawChildProps?.pcbRightEdgeX!==void 0||rawChildProps?.pcbTopEdgeY!==void 0||rawChildProps?.pcbBottomEdgeY!==void 0;return count+(hasCoords?0:1)},0);return!hasManualEdits&&unpositionedDirectChildrenCount>1?"pack":"none"}doInitialPcbLayout(){if(this.root?.pcbDisabled)return;if(this.pcb_group_id){let{db:db22}=this.root,props=this._parsedProps;if(props.pcbX!==void 0||props.pcbY!==void 0){let parentGroup=this.parent?.getGroup?.(),pcbParentGroupId=parentGroup?.pcb_group_id?db22.pcb_group.get(parentGroup.pcb_group_id)?.pcb_group_id:void 0,positionedRelativeToBoardId=pcbParentGroupId?void 0:this._getBoard()?.pcb_board_id??void 0;db22.pcb_group.update(this.pcb_group_id,{position_mode:"relative_to_group_anchor",positioned_relative_to_pcb_group_id:pcbParentGroupId,positioned_relative_to_pcb_board_id:positionedRelativeToBoardId,display_offset_x:props.pcbX,display_offset_y:props.pcbY})}}let pcbLayoutMode=this._getPcbLayoutMode();pcbLayoutMode==="grid"?this._doInitialPcbLayoutGrid():pcbLayoutMode==="pack"?this._doInitialPcbLayoutPack():pcbLayoutMode==="flex"&&this._doInitialPcbLayoutFlex()}_doInitialPcbLayoutGrid(){Group_doInitialPcbLayoutGrid(this)}_doInitialPcbLayoutPack(){Group_doInitialPcbLayoutPack(this)}_doInitialPcbLayoutFlex(){Group_doInitialPcbLayoutFlex(this)}_insertSchematicBorder(){if(this.root?.schematicDisabled)return;let{db:db22}=this.root,props=this._parsedProps;if(!props.border)return;let width=typeof props.schWidth=="number"?props.schWidth:void 0,height=typeof props.schHeight=="number"?props.schHeight:void 0,paddingGeneral=typeof props.schPadding=="number"?props.schPadding:0,paddingLeft=typeof props.schPaddingLeft=="number"?props.schPaddingLeft:paddingGeneral,paddingRight=typeof props.schPaddingRight=="number"?props.schPaddingRight:paddingGeneral,paddingTop=typeof props.schPaddingTop=="number"?props.schPaddingTop:paddingGeneral,paddingBottom=typeof props.schPaddingBottom=="number"?props.schPaddingBottom:paddingGeneral,schematicGroup=this.schematic_group_id?db22.schematic_group.get(this.schematic_group_id):null;if(schematicGroup&&(width===void 0&&typeof schematicGroup.width=="number"&&(width=schematicGroup.width),height===void 0&&typeof schematicGroup.height=="number"&&(height=schematicGroup.height)),width===void 0||height===void 0)return;let center2=schematicGroup?.center??this._getGlobalSchematicPositionBeforeLayout(),left=center2.x-width/2-paddingLeft,bottom=center2.y-height/2-paddingBottom,finalWidth=width+paddingLeft+paddingRight,finalHeight=height+paddingTop+paddingBottom;db22.schematic_box.insert({width:finalWidth,height:finalHeight,x:left,y:bottom,is_dashed:props.border?.dashed??!1})}_determineSideFromPosition(port,component){if(!port.center||!component.center)return"left";let dx22=port.center.x-component.center.x,dy22=port.center.y-component.center.y;return Math.abs(dx22)>Math.abs(dy22)?dx22>0?"right":"left":dy22>0?"bottom":"top"}_calculateSchematicBounds(boxes){if(boxes.length===0)return{minX:0,maxX:0,minY:0,maxY:0};let minX=1/0,maxX=-1/0,minY=1/0,maxY=-1/0;for(let box2 of boxes)minX=Math.min(minX,box2.centerX),maxX=Math.max(maxX,box2.centerX),minY=Math.min(minY,box2.centerY),maxY=Math.max(maxY,box2.centerY);let padding=2;return{minX:minX-padding,maxX:maxX+padding,minY:minY-padding,maxY:maxY+padding}}_getAutorouterConfig(){let autorouter=this._parsedProps.autorouter||this.getInheritedProperty("autorouter");return getPresetAutoroutingConfig(autorouter,this.root?.platform)}_isLegacyAutorouterDisabled(){return getDisabledLegacyAutorouterPreset(this)!==null}_isLaserPrefabAutorouter(autorouterConfig3=this._getAutorouterConfig()){let autorouterProp3=this.props.autorouter,normalize9=value=>value?.replace(/-/g,"_")??value;return autorouterConfig3.preset==="laser_prefab"?!0:typeof autorouterProp3=="string"?normalize9(autorouterProp3)==="laser_prefab":typeof autorouterProp3=="object"&&autorouterProp3?normalize9(autorouterProp3.preset)==="laser_prefab":!1}_isAutoJumperAutorouter(autorouterConfig3=this._getAutorouterConfig()){let autorouterProp3=this.props.autorouter,normalize9=value=>value?.replace(/-/g,"_")??value;return autorouterConfig3.preset==="auto_jumper"?!0:typeof autorouterProp3=="string"?normalize9(autorouterProp3)==="auto_jumper":typeof autorouterProp3=="object"&&autorouterProp3?normalize9(autorouterProp3.preset)==="auto_jumper":!1}_getSubcircuitLayerCount(){let layers=this.getInheritedProperty("layers");return typeof layers=="number"?layers:2}_shouldUseTraceByTraceRouting(){return getDisabledLegacyGroupAutorouterPreset(this)?!1:this._getAutorouterConfig().groupMode==="sequential-trace"}doInitialPcbDesignRuleChecks(){if(this.root?.pcbDisabled||this._isLegacyAutorouterDisabled()||this.root?.pcbRoutingDisabled||this.getInheritedProperty("routingDisabled"))return;let{db:db22}=this.root;if(this.isSubcircuit){let immediateChildrenByName=new Map;for(let child of this.children)if(!child.isSubcircuit&&child._parsedProps.name){let components=immediateChildrenByName.get(child._parsedProps.name)||[];components.push(child),immediateChildrenByName.set(child._parsedProps.name,components)}for(let[name,components]of immediateChildrenByName.entries()){if(components.length<=1)continue;let sameNamedTraces=components.filter(child=>child instanceof Trace),duplicateNameIsOnlyTraces=sameNamedTraces.length===components.length,mutuallyConnectedTraceKeys=sameNamedTraces.map(trace=>trace.subcircuit_connectivity_map_key),sameNamedTracesAreMutuallyConnected=duplicateNameIsOnlyTraces&&mutuallyConnectedTraceKeys.every(Boolean)&&new Set(mutuallyConnectedTraceKeys).size===1;if(!duplicateNameIsOnlyTraces||!sameNamedTracesAreMutuallyConnected){let displaySubcircuitName=this.name||"unnamed",message=duplicateNameIsOnlyTraces?`Trace "${name}" in subcircuit "${displaySubcircuitName}" shares a name with another trace, but the traces are not mutually connected. Same-named traces must have the same subcircuit connectivity map key.`:`Multiple immediate children found with name "${name}" in subcircuit "${displaySubcircuitName}". Names must be unique.`;db22.pcb_trace_error.insert({error_type:"pcb_trace_error",message,source_trace_id:"",pcb_trace_id:"",pcb_component_ids:components.map(c22=>c22.pcb_component_id).filter(Boolean),pcb_port_ids:[]})}}}Group_doInitialStandaloneSubcircuitPcbDesignRuleChecks(this)}doInitialSchematicLabelNetsWithConflictingNames(){this.root?.schematicDisabled||this.getTopLevelRenderable()===this&&assignSchematicNetLabelSuperscripts(this.root.db)}updateSchematicLabelNetsWithConflictingNames(){this.doInitialSchematicLabelNetsWithConflictingNames()}doInitialSchematicReplaceNetLabelsWithSymbols(){if(this.root?.schematicDisabled||!this.isSubcircuit)return;let{db:db22}=this.root,subtree=db22;for(let nl3 of subtree.schematic_net_label.list()){let net=subtree.source_net.get(nl3.source_net_id),text=nl3.text||net?.name||"",isGroundNet=net?.is_ground||GROUND_NET_REGEX.test(text),isPowerNet=net?.is_power||POWER_NET_REGEX.test(text);if(nl3.anchor_side==="top"&&isGroundNet){subtree.schematic_net_label.update(nl3.schematic_net_label_id,{symbol_name:"rail_down"});continue}nl3.anchor_side==="bottom"&&isPowerNet&&subtree.schematic_net_label.update(nl3.schematic_net_label_id,{symbol_name:"rail_up"})}}doInitialSimulationSpiceEngineRender(){Group_doInitialSimulationSpiceEngineRender(this)}doInitialPcbComponentAnchorAlignment(){Group_doInitialPcbComponentAnchorAlignment(this)}updatePcbComponentAnchorAlignment(){this.doInitialPcbComponentAnchorAlignment()}doInitialPcbCalcPlacementResolution(){Group_doInitialPcbCalcPlacementResolution(this)}updatePcbCalcPlacementResolution(){this.doInitialPcbCalcPlacementResolution()}_getMinimumFlexContainerSize(){return super._getMinimumFlexContainerSize()}_repositionOnPcb(position4){return super._repositionOnPcb(position4)}};function inflateSourceGroup(sourceGroup,inflatorContext){let{injectionDb,subcircuit,groupsMap}=inflatorContext,pcbGroup=injectionDb.pcb_group.getWhere({source_group_id:sourceGroup.source_group_id}),groupProps22={name:sourceGroup.name??`inflated_group_${sourceGroup.source_group_id}`};if(pcbGroup?.position_mode==="relative_to_group_anchor"&&pcbGroup.anchor_position){let baseAnchor={x:0,y:0};if(sourceGroup.parent_source_group_id){let parentPcbGroup=injectionDb.pcb_group.getWhere({source_group_id:sourceGroup.parent_source_group_id});parentPcbGroup?.anchor_position&&(baseAnchor=parentPcbGroup.anchor_position)}groupProps22.pcbX=pcbGroup.anchor_position.x-baseAnchor.x,groupProps22.pcbY=pcbGroup.anchor_position.y-baseAnchor.y}pcbGroup?.anchor_alignment&&(groupProps22.pcbAnchorAlignment=pcbGroup.anchor_alignment);let group2=new Group5(groupProps22);return group2._isInflatedFromCircuitJson=!0,group2.source_group_id=sourceGroup.source_group_id,groupsMap&&groupsMap.set(sourceGroup.source_group_id,group2),sourceGroup.parent_source_group_id&&groupsMap?.has(sourceGroup.parent_source_group_id)?groupsMap.get(sourceGroup.parent_source_group_id).add(group2):subcircuit.add(group2),group2}var Inductor2=class extends NormalComponent{constructor(){super(...arguments);__publicField(this,"_adjustSilkscreenTextAutomatically",!0)}get config(){return{componentName:"Inductor",schematicSymbolName:this.props.symbolName??"inductor",zodProps:inductorProps,sourceFtype:FTYPE.simple_inductor}}_getSchematicSymbolDisplayValue(){return`${formatSiUnit(this._parsedProps.inductance)}H`}initPorts(){super.initPorts({additionalAliases:{pin1:["anode","pos","left"],pin2:["cathode","neg","right"]}})}doInitialSourceRender(){let{db:db22}=this.root,{_parsedProps:props}=this,source_component=db22.source_component.insert({name:this.name,ftype:FTYPE.simple_inductor,inductance:this.props.inductance,max_current_rating:props.maxCurrentRating===void 0?void 0:parseAndConvertSiUnit(props.maxCurrentRating,"A").value,display_inductance:this._getSchematicSymbolDisplayValue(),supplier_part_numbers:props.supplierPartNumbers,manufacturer_part_number:resolveManufacturerPartNumber(props),are_pins_interchangeable:!0,display_name:props.displayName});this.source_component_id=source_component.source_component_id}};function inflateSourceInductor(sourceElm,inflatorContext){let{injectionDb,subcircuit,groupsMap}=inflatorContext,pcbElm=injectionDb.pcb_component.getWhere({source_component_id:sourceElm.source_component_id}),cadElm=injectionDb.cad_component.getWhere({source_component_id:sourceElm.source_component_id}),{pcbX,pcbY}=getInflatedPcbPlacement({pcbComponent:pcbElm,sourceGroupId:sourceElm.source_group_id,inflatorContext}),inductor=new Inductor2({name:sourceElm.name,inductance:sourceElm.inductance,layer:pcbElm?.layer,pcbX,pcbY,pcbRotation:pcbElm?.rotation,doNotPlace:pcbElm?.do_not_place,obstructsWithinBounds:pcbElm?.obstructs_within_bounds});if(pcbElm){let footprint=inflateFootprintComponent(pcbElm,{...inflatorContext,normalComponent:inductor});footprint&&inductor.add(footprint)}sourceElm.source_group_id&&groupsMap?.has(sourceElm.source_group_id)?groupsMap.get(sourceElm.source_group_id).add(inductor):subcircuit.add(inductor)}var generatedNotes=new WeakMap,getPolarity2=port=>{let hints=[port.name,...port.port_hints??[]].map(hint=>hint.toLowerCase().replace(/[^a-z0-9+-]/g,"")),anode=hints.some(hint=>["a","anode","pos","positive","+"].includes(hint)),cathode=hints.some(hint=>["k","c","cathode","neg","negative","-"].includes(hint));return anode===cathode?null:anode?"anode":"cathode"},Led_addPolarityFabricationSymbol=led2=>{let root=led2.root;if(!root)return;let{db:db22}=root,previous=generatedNotes.get(led2);for(let path of previous??[])db22.pcb_fabrication_note_path.delete(path.pcb_fabrication_note_path_id);if(generatedNotes.delete(led2),root.pcbDisabled||!led2.pcb_component_id)return;let pcb=db22.pcb_component.get(led2.pcb_component_id);if(!pcb||pcb.layer!=="top"&&pcb.layer!=="bottom")return;let ports=db22.source_port.list({source_component_id:led2.source_component_id}),anodes=ports.filter(port=>getPolarity2(port)==="anode"),cathodes=ports.filter(port=>getPolarity2(port)==="cathode");if(anodes.length!==1||cathodes.length!==1)return;let anode=anodes[0],cathode=cathodes[0],a22=db22.pcb_port.getWhere({source_port_id:anode.source_port_id}),k22=db22.pcb_port.getWhere({source_port_id:cathode.source_port_id});if(!a22||!k22)return;let distance27=Math.hypot(k22.x-a22.x,k22.y-a22.y);if(distance27<1e-6)return;let angle3=Math.atan2(k22.y-a22.y,k22.x-a22.x),frame=compose2(translate2((a22.x+k22.x)/2,(a22.y+k22.y)/2),rotate2(angle3)),point62=(x22,y22)=>applyToPoint2(frame,{x:x22,y:y22}),common={pcb_component_id:pcb.pcb_component_id,subcircuit_id:led2.getSubcircuit()?.subcircuit_id??void 0,layer:pcb.layer},notes=[];generatedNotes.set(led2,notes);let halfLength=Math.min(distance27*.2,.4),halfHeight=halfLength*.75,routes=[[point62(-distance27/2,0),point62(-halfLength,0)],[point62(-halfLength,-halfHeight),point62(halfLength,0),point62(-halfLength,halfHeight),point62(-halfLength,-halfHeight)],[point62(halfLength,-halfHeight),point62(halfLength,halfHeight)],[point62(halfLength,0),point62(distance27/2,0)]];for(let route2 of routes)notes.push(db22.pcb_fabrication_note_path.insert({...common,route:route2,stroke_width:.08}))},Led=class extends NormalComponent{get config(){let symbolMap={laser:"laser_diode"},variantSymbol=this.props.laser?"laser":null,baseSymbolName=variantSymbol?symbolMap[variantSymbol]:this.props.symbolName??"led",compactSize=this.props.schSize==="sm"||this.props.schSize==="xs"?this.props.schSize:void 0,compactSymbolName=compactSize&&baseSymbolName==="led"?`led_${compactSize}`:void 0;return{schematicSymbolName:compactSymbolName&&`${compactSymbolName}_right`in zh?compactSymbolName:baseSymbolName,componentName:"Led",zodProps:ledProps,sourceFtype:"simple_led"}}initPorts(){let hasFootprintChild=this.children.some(child=>child.componentName==="Footprint"),footprint=this.resolveFootprint(),hasPinLabels=!!this._resolvePinLabels(),shouldAddDefaultAliases=!hasPinLabels&&!hasFootprintChild&&(!footprint||isFootprinterString(footprint));super.initPorts({pinCount:2,ignoreSymbolPorts:!hasPinLabels&&!shouldAddDefaultAliases,additionalAliases:{pin1:shouldAddDefaultAliases?["anode","pos","left"]:[],pin2:shouldAddDefaultAliases?["cathode","neg","right"]:[]}})}_getSchematicSymbolDisplayValue(){return this._parsedProps.schDisplayValue||this._parsedProps.color||void 0}getFootprinterString(){let baseFootprint=super.getFootprinterString();return baseFootprint&&this.props.color?`${baseFootprint}_color(${this.props.color})`:baseFootprint}doInitialSourceRender(){let{db:db22}=this.root,{_parsedProps:props}=this,source_component=db22.source_component.insert({ftype:"simple_led",name:this.name,wave_length:props.wavelength,color:props.color,symbol_display_value:this._getSchematicSymbolDisplayValue(),manufacturer_part_number:resolveManufacturerPartNumber(props),supplier_part_numbers:props.supplierPartNumbers,are_pins_interchangeable:!1,display_name:props.displayName});this.source_component_id=source_component.source_component_id}get pos(){return this.portMap.pos}doInitialPcbComponentSizeCalculation(){super.doInitialPcbComponentSizeCalculation(),Led_addPolarityFabricationSymbol(this)}get anode(){return this.portMap.anode}get neg(){return this.portMap.neg}get cathode(){return this.portMap.cathode}};function inflateSourceLed(sourceElm,inflatorContext){let{injectionDb,subcircuit,groupsMap}=inflatorContext,pcbElm=injectionDb.pcb_component.getWhere({source_component_id:sourceElm.source_component_id}),cadElm=injectionDb.cad_component.getWhere({source_component_id:sourceElm.source_component_id}),{pcbX,pcbY}=getInflatedPcbPlacement({pcbComponent:pcbElm,sourceGroupId:sourceElm.source_group_id,inflatorContext}),led2=new Led({name:sourceElm.name,color:sourceElm.color,wavelength:sourceElm.wavelength??sourceElm.wave_length,layer:pcbElm?.layer,pcbX,pcbY,pcbRotation:pcbElm?.rotation,doNotPlace:pcbElm?.do_not_place,obstructsWithinBounds:pcbElm?.obstructs_within_bounds});if(pcbElm){let footprint=inflateFootprintComponent(pcbElm,{...inflatorContext,normalComponent:led2});footprint&&led2.add(footprint)}sourceElm.source_group_id&&groupsMap?.has(sourceElm.source_group_id)?groupsMap.get(sourceElm.source_group_id).add(led2):subcircuit.add(led2)}var possibleOrientations=[{gate:"left",drain:"top",source:"bottom"},{gate:"left",drain:"bottom",source:"top"},{gate:"right",drain:"top",source:"bottom"},{gate:"right",drain:"bottom",source:"top"},{gate:"top",drain:"left",source:"right"},{gate:"top",drain:"right",source:"left"},{gate:"bottom",drain:"left",source:"right"},{gate:"bottom",drain:"right",source:"left"}],getBaselineOrientation=rotation5=>{let normalizedRotation=(rotation5%360+360)%360;if(normalizedRotation%90!==0)throw new Error(`Schematic rotation ${rotation5} is not supported for Mosfet`);return[{gate:"left",drain:"top",source:"bottom"},{gate:"top",drain:"right",source:"left"},{gate:"right",drain:"bottom",source:"top"},{gate:"bottom",drain:"left",source:"right"}][normalizedRotation/90]},getRequestedOrientation=props=>{let requestedSides={drain:props.symbolDrainSide,source:props.symbolSourceSide,gate:props.symbolGateSide},baseline=getBaselineOrientation(Number(props.schRotation??0)),matchingOrientations=possibleOrientations.filter(orientation22=>Object.keys(requestedSides).every(portName=>requestedSides[portName]===void 0||requestedSides[portName]===orientation22[portName]));if(matchingOrientations.length===0){let requestedDescription=Object.entries(requestedSides).filter(([,side])=>side!==void 0).map(([portName,side])=>`${portName}=${side}`).join(", ");throw new Error(`Invalid MOSFET symbol port side combination (${requestedDescription}). The gate must be perpendicular to the drain and source, and the drain and source must be opposite.`)}return matchingOrientations.sort((a22,b22)=>{let score=orientation22=>Object.keys(baseline).filter(portName=>orientation22[portName]!==baseline[portName]).length;return score(a22)-score(b22)})[0]},getMosfetSchematicSymbolName=props=>{let mosfetMode=props.mosfetMode==="depletion"?"d":"e",baseSymbolName=`${props.channelType}_channel_${mosfetMode}_mosfet_transistor`;if(!(props.symbolDrainSide!==void 0||props.symbolSourceSide!==void 0||props.symbolGateSide!==void 0))return baseSymbolName;let{gate,drain}=getRequestedOrientation(props);return`${baseSymbolName}_gate_${gate}_drain_${drain}`},Mosfet2=class extends NormalComponent{get config(){return{componentName:"Mosfet",schematicSymbolName:this.props.symbolName??getMosfetSchematicSymbolName(this.props),zodProps:mosfetProps,shouldRenderAsSchematicBox:!1}}doInitialSourceRender(){let{db:db22}=this.root,{_parsedProps:props}=this,source_component=db22.source_component.insert({ftype:"simple_mosfet",name:this.name,manufacturer_part_number:resolveManufacturerPartNumber(props),supplier_part_numbers:props.supplierPartNumbers,mosfet_mode:props.mosfetMode,channel_type:props.channelType,display_name:props.displayName});this.source_component_id=source_component.source_component_id}};function inflateSourceMosfet(sourceElm,inflatorContext){let{injectionDb,subcircuit,groupsMap}=inflatorContext,pcbElm=injectionDb.pcb_component.getWhere({source_component_id:sourceElm.source_component_id}),{pcbX,pcbY}=getInflatedPcbPlacement({pcbComponent:pcbElm,sourceGroupId:sourceElm.source_group_id,inflatorContext}),mosfet=new Mosfet2({name:sourceElm.name,channelType:sourceElm.channel_type,mosfetMode:sourceElm.mosfet_mode,manufacturerPartNumber:sourceElm.manufacturer_part_number,supplierPartNumbers:sourceElm.supplier_part_numbers??void 0,displayName:sourceElm.display_name,layer:pcbElm?.layer,pcbX,pcbY,pcbRotation:pcbElm?.rotation,doNotPlace:pcbElm?.do_not_place,obstructsWithinBounds:pcbElm?.obstructs_within_bounds});if(pcbElm){let footprint=inflateFootprintComponent(pcbElm,{...inflatorContext,normalComponent:mosfet});footprint&&mosfet.add(footprint)}sourceElm.source_group_id&&groupsMap?.has(sourceElm.source_group_id)?groupsMap.get(sourceElm.source_group_id).add(mosfet):subcircuit.add(mosfet)}function inflateSourcePort(sourcePort,inflatorContext){let{injectionDb,subcircuit}=inflatorContext;if(sourcePort.source_component_id!==null)return;let pcbPortFromInjection=injectionDb.pcb_port.getWhere({source_port_id:sourcePort.source_port_id}),port=new Port({name:sourcePort.name,pinNumber:sourcePort.pin_number});subcircuit.add(port),port.source_port_id=sourcePort.source_port_id;let root=subcircuit.root;if(root&&pcbPortFromInjection){let{db:db22}=root,pcb_port3=db22.pcb_port.insert({pcb_component_id:void 0,layers:pcbPortFromInjection.layers,subcircuit_id:subcircuit.subcircuit_id??void 0,pcb_group_id:subcircuit.getGroup()?.pcb_group_id??void 0,x:pcbPortFromInjection.x,y:pcbPortFromInjection.y,source_port_id:sourcePort.source_port_id,is_board_pinout:!1});port.pcb_port_id=pcb_port3.pcb_port_id}}var PushButton=class extends NormalComponent{get config(){return{componentName:"PushButton",schematicSymbolName:this.props.symbolName??"push_button_normally_open_momentary",zodProps:pushButtonProps,sourceFtype:FTYPE.simple_push_button}}get defaultInternallyConnectedPinNames(){return[]}initPorts(){super.initPorts({pinCount:2,ignoreSymbolPorts:!0});let symbol=zh[this._getSchematicSymbolNameOrThrow()],symPort1=symbol.ports.find(p22=>p22.labels.includes("1")),symPort2=symbol.ports.find(p22=>p22.labels.includes("2")),ports=this.selectAll("port"),pin1Port=ports.find(port=>port.props.pinNumber===1);pin1Port.schematicSymbolPortDef=symPort1;let firstTerminalPorts=new Set(pin1Port._getPortsInternallyConnectedToThisPort()),secondTerminalPort=ports.filter(port=>port!==pin1Port&&!firstTerminalPorts.has(port)).sort((a22,b22)=>(a22.props.pinNumber??0)-(b22.props.pinNumber??0))[0];secondTerminalPort&&(secondTerminalPort.schematicSymbolPortDef=symPort2)}doInitialSourceRender(){let{db:db22}=this.root,{_parsedProps:props}=this,source_component=db22.source_component.insert({name:this.name,ftype:FTYPE.simple_push_button,supplier_part_numbers:props.supplierPartNumbers,manufacturer_part_number:resolveManufacturerPartNumber(props),are_pins_interchangeable:!0,display_name:props.displayName});this.source_component_id=source_component.source_component_id}};function inflateSourcePushButton(sourceElm,inflatorContext){let{injectionDb,subcircuit,groupsMap}=inflatorContext,pcbElm=injectionDb.pcb_component.getWhere({source_component_id:sourceElm.source_component_id}),cadElm=injectionDb.cad_component.getWhere({source_component_id:sourceElm.source_component_id}),{pcbX,pcbY}=getInflatedPcbPlacement({pcbComponent:pcbElm,sourceGroupId:sourceElm.source_group_id,inflatorContext}),pushButton=new PushButton({name:sourceElm.name,layer:pcbElm?.layer,pcbX,pcbY,pcbRotation:pcbElm?.rotation,doNotPlace:pcbElm?.do_not_place,obstructsWithinBounds:pcbElm?.obstructs_within_bounds});if(pcbElm){let footprint=inflateFootprintComponent(pcbElm,{...inflatorContext,normalComponent:pushButton});footprint&&pushButton.add(footprint)}sourceElm.source_group_id&&groupsMap?.has(sourceElm.source_group_id)?groupsMap.get(sourceElm.source_group_id).add(pushButton):subcircuit.add(pushButton)}var Resistor2=class extends NormalComponent{constructor(){super(...arguments);__publicField(this,"_adjustSilkscreenTextAutomatically",!0)}get config(){let baseSymbolName=this.props.symbolName??"boxresistor",compactSize=this.props.schSize==="sm"||this.props.schSize==="xs"?this.props.schSize:void 0,compactSymbolName=compactSize&&(baseSymbolName==="boxresistor"||baseSymbolName==="resistor")?`${baseSymbolName}_${compactSize}`:void 0;return{componentName:"Resistor",schematicSymbolName:compactSymbolName&&`${compactSymbolName}_right`in zh?compactSymbolName:baseSymbolName,zodProps:resistorProps,sourceFtype:"simple_resistor"}}initPorts(){super.initPorts({additionalAliases:{pin1:["anode","pos","left"],pin2:["cathode","neg","right"]}})}_getSchematicSymbolDisplayValue(){return`${formatSiUnit(this._parsedProps.resistance)}\u03A9`}doInitialCreateNetsFromProps(){this._createNetsFromProps([this.props.pullupFor,this.props.pullupTo,this.props.pulldownFor,this.props.pulldownTo,...this._getNetsFromConnectionsProp()])}doInitialCreateTracesFromProps(){this.props.pullupFor&&this.props.pullupTo&&(this.add(new Trace({from:`${this.getSubcircuitSelector()} > port.1`,to:this.props.pullupFor})),this.add(new Trace({from:`${this.getSubcircuitSelector()} > port.2`,to:this.props.pullupTo}))),this.props.pulldownFor&&this.props.pulldownTo&&(this.add(new Trace({from:`${this.getSubcircuitSelector()} > port.1`,to:this.props.pulldownFor})),this.add(new Trace({from:`${this.getSubcircuitSelector()} > port.2`,to:this.props.pulldownTo}))),this._createTracesFromConnectionsProp()}doInitialSourceRender(){let{db:db22}=this.root,{_parsedProps:props}=this,source_component=db22.source_component.insert({ftype:"simple_resistor",name:this.name,manufacturer_part_number:resolveManufacturerPartNumber(props),supplier_part_numbers:props.supplierPartNumbers,resistance:props.resistance,display_resistance:this._getSchematicSymbolDisplayValue(),are_pins_interchangeable:!0,display_name:props.displayName});this.source_component_id=source_component.source_component_id}};function inflateSourceResistor(sourceElm,inflatorContext){let{injectionDb,subcircuit,groupsMap}=inflatorContext,pcbElm=injectionDb.pcb_component.getWhere({source_component_id:sourceElm.source_component_id}),cadElm=injectionDb.cad_component.getWhere({source_component_id:sourceElm.source_component_id}),{pcbX,pcbY}=getInflatedPcbPlacement({pcbComponent:pcbElm,sourceGroupId:sourceElm.source_group_id,inflatorContext}),resistor=new Resistor2({name:sourceElm.name,resistance:sourceElm.resistance,layer:pcbElm?.layer,pcbX,pcbY,pcbRotation:pcbElm?.rotation,doNotPlace:pcbElm?.do_not_place,obstructsWithinBounds:pcbElm?.obstructs_within_bounds});if(pcbElm){let footprint=inflateFootprintComponent(pcbElm,{...inflatorContext,normalComponent:resistor});footprint&&resistor.add(footprint)}sourceElm.source_group_id&&groupsMap?.has(sourceElm.source_group_id)?groupsMap.get(sourceElm.source_group_id).add(resistor):subcircuit.add(resistor)}function hasSimProps(props){return props.simSwitchFrequency!==void 0||props.simCloseAt!==void 0||props.simOpenAt!==void 0||props.simStartClosed!==void 0||props.simStartOpen!==void 0}var Switch=class extends NormalComponent{_getSwitchType(){let props=this._parsedProps;return props?props.dpdt?"dpdt":props.spst?"spst":props.spdt?"spdt":props.dpst?"dpst":props.type??"spst":"spst"}get config(){let switchType=this._getSwitchType(),isNormallyClosed=this._parsedProps?.isNormallyClosed??!1,symbolMap={spst:isNormallyClosed?"spst_normally_closed_switch":"spst_switch",spdt:isNormallyClosed?"spdt_normally_closed_switch":"spdt_switch",dpst:isNormallyClosed?"dpst_normally_closed_switch":"dpst_switch",dpdt:isNormallyClosed?"dpdt_normally_closed_switch":"dpdt_switch"};return{componentName:"Switch",schematicSymbolName:this.props.symbolName??symbolMap[switchType],zodProps:switchProps,shouldRenderAsSchematicBox:!1}}doInitialSourceRender(){let{db:db22}=this.root,props=this._parsedProps??{},source_component=db22.source_component.insert({ftype:"simple_switch",name:this.name,manufacturer_part_number:resolveManufacturerPartNumber(props),supplier_part_numbers:props.supplierPartNumbers,are_pins_interchangeable:this._getSwitchType()==="spst",display_name:props?.displayName});this.source_component_id=source_component.source_component_id}doInitialSimulationRender(){let{_parsedProps:props}=this;if(!hasSimProps(props))return;let{db:db22}=this.root,simulationSwitch={type:"simulation_switch",source_component_id:this.source_component_id||""};props.simSwitchFrequency!==void 0&&(simulationSwitch.switching_frequency=frequency.parse(props.simSwitchFrequency)),props.simCloseAt!==void 0&&(simulationSwitch.closes_at=ms.parse(props.simCloseAt)),props.simOpenAt!==void 0&&(simulationSwitch.opens_at=ms.parse(props.simOpenAt)),props.simStartOpen!==void 0&&(simulationSwitch.starts_closed=!props.simStartOpen),props.simStartClosed!==void 0&&(simulationSwitch.starts_closed=props.simStartClosed),db22.simulation_switch.insert(simulationSwitch)}},getImportedSwitchProps=(sourceElm,inflatorContext)=>{let sourcePorts=inflatorContext.injectionDb.source_port.list().filter(port=>port.source_component_id===sourceElm.source_component_id),pinLabels={},highestPinNumber=0;for(let sourcePort of sourcePorts){let pinNumber=sourcePort.pin_number;if(pinNumber==null)continue;highestPinNumber=Math.max(highestPinNumber,pinNumber);let labels=Array.from(new Set([sourcePort.name,...sourcePort.port_hints??[]].filter(label=>typeof label=="string"&&label.length>0)));labels.length>0&&(pinLabels[`pin${pinNumber}`]=labels)}let type="spst";return highestPinNumber>=5?type="dpdt":highestPinNumber===4?type="dpst":highestPinNumber===3&&(type="spdt"),{type,pinLabels:Object.keys(pinLabels).length>0?pinLabels:void 0}};function inflateSourceSwitch(sourceElm,inflatorContext){let{injectionDb,subcircuit,groupsMap}=inflatorContext,pcbElm=injectionDb.pcb_component.getWhere({source_component_id:sourceElm.source_component_id}),{pcbX,pcbY}=getInflatedPcbPlacement({pcbComponent:pcbElm,sourceGroupId:sourceElm.source_group_id,inflatorContext}),importedSwitchProps=getImportedSwitchProps(sourceElm,inflatorContext),switchComponent=new Switch({name:sourceElm.name,displayName:sourceElm.display_name,...importedSwitchProps,layer:pcbElm?.layer,pcbX,pcbY,pcbRotation:pcbElm?.rotation,doNotPlace:pcbElm?.do_not_place,obstructsWithinBounds:pcbElm?.obstructs_within_bounds});if(pcbElm){let footprint=inflateFootprintComponent(pcbElm,{...inflatorContext,normalComponent:switchComponent});footprint&&switchComponent.add(footprint)}sourceElm.source_group_id&&groupsMap?.has(sourceElm.source_group_id)?groupsMap.get(sourceElm.source_group_id).add(switchComponent):subcircuit.add(switchComponent)}function pcbTraceRouteToPcbPath(route2){if(route2.length<=2)return[];let firstPoint=route2[0],lastPoint=route2[route2.length-1];return route2.slice(1,-1).filter(point62=>{let position4=getRoutePointPosition(point62),firstPosition=getRoutePointPosition(firstPoint),lastPosition=getRoutePointPosition(lastPoint),isSameAsFirst=position4.x===firstPosition.x&&position4.y===firstPosition.y,isSameAsLast=position4.x===lastPosition.x&&position4.y===lastPosition.y;return!isSameAsFirst&&!isSameAsLast}).map(point62=>{if(point62.route_type==="via")return{x:point62.x,y:point62.y,via:!0,fromLayer:point62.from_layer,toLayer:point62.to_layer};let position4=getRoutePointPosition(point62);return{x:position4.x,y:position4.y}})}var getSelectorPath=(component,inflatorContext)=>{let{injectionDb,subcircuit,groupsMap}=inflatorContext,path_parts=[],currentGroupId=component.source_group_id;for(;currentGroupId&&currentGroupId!==subcircuit.source_group_id;){let sourceGroup=injectionDb.source_group.get(currentGroupId),groupInstance=groupsMap?.get(currentGroupId);if(!sourceGroup||!groupInstance)break;let groupName=groupInstance.props.name??groupInstance.fallbackUnassignedName;path_parts.unshift(`.${groupName}`),currentGroupId=sourceGroup.parent_source_group_id}return path_parts.push(`.${component.name}`),path_parts.join(" > ")};function inflateSourceTrace(sourceTrace,inflatorContext){let{injectionDb,subcircuit}=inflatorContext,connectedSelectors=[];for(let sourcePortId of sourceTrace.connected_source_port_ids){let sourcePort=injectionDb.source_port.get(sourcePortId);if(!sourcePort)continue;let selector2;if(sourcePort.source_component_id){let sourceComponent=injectionDb.source_component.get(sourcePort.source_component_id);sourceComponent&&(selector2=`${getSelectorPath({name:sourceComponent.name,source_group_id:sourceComponent.source_group_id},inflatorContext)} > .${sourcePort.name}`)}else selector2=`.${sourcePort.name}`;selector2&&connectedSelectors.push(selector2)}for(let sourceNetId of sourceTrace.connected_source_net_ids){let sourceNet=injectionDb.source_net.get(sourceNetId);sourceNet&&connectedSelectors.push(`net.${sourceNet.name}`)}if(connectedSelectors.length<2)return;let pcbTraces=injectionDb.pcb_trace.list().filter(trace2=>trace2.source_trace_id===sourceTrace.source_trace_id),pcbTrace=pcbTraces[0],pcbPath3;pcbTrace&&(pcbPath3=pcbTraceRouteToPcbPath(pcbTrace.route));let traceWidth=sourceTrace.min_trace_thickness;if(!traceWidth&&pcbTrace?.route){let wirePoint=pcbTrace.route.find(pt22=>pt22.route_type==="wire");wirePoint&&wirePoint.route_type==="wire"&&(traceWidth=wirePoint.width)}let traceProps22={path:connectedSelectors};traceWidth!==void 0&&(traceProps22.thickness=traceWidth),pcbPath3&&pcbPath3.length>0?traceProps22.pcbPath=pcbPath3:!pcbTrace&&sourceTrace.connected_source_port_ids.length===2&&sourceTrace.connected_source_net_ids.length===0&&(traceProps22.pcbStraightLine=!0);let trace=new Trace(traceProps22);trace._inflatedPcbTraces=pcbTraces.length>0?pcbTraces:void 0,trace._inflatedPcbVias=pcbTrace?injectionDb.pcb_via.list().filter(via=>pcbTraces.some(trace2=>via.pcb_trace_id===trace2.pcb_trace_id)):void 0,subcircuit.add(trace)}var SHORT_ALIASES={collector:["c"],base:["b"],emitter:["e"]},Transistor=class extends NormalComponent{get config(){let baseSymbolName=this.props.type==="npn"?"npn_bipolar_transistor":"pnp_bipolar_transistor";return{componentName:"Transistor",schematicSymbolName:this.props.symbolName??baseSymbolName,zodProps:transistorProps,sourceFtype:"simple_transistor",shouldRenderAsSchematicBox:!1}}initPorts(){let additionalAliases={},symbol=this.getSchematicSymbol();for(let symPort of symbol?.ports??[]){let pinNumber=getPinNumberFromLabels(symPort.labels);if(pinNumber)for(let label of symPort.labels){let shortAliases=SHORT_ALIASES[label];shortAliases&&(additionalAliases[`pin${pinNumber}`]=shortAliases)}}super.initPorts({pinCount:3,additionalAliases})}get collector(){return this.portMap.collector}get base(){return this.portMap.base}get emitter(){return this.portMap.emitter}doInitialCreateNetsFromProps(){this._createNetsFromProps([...this._getNetsFromConnectionsProp()])}doInitialCreateTracesFromProps(){this._createTracesFromConnectionsProp()}doInitialSourceRender(){let{db:db22}=this.root,{_parsedProps:props}=this,source_component=db22.source_component.insert({ftype:"simple_transistor",name:this.name,manufacturer_part_number:resolveManufacturerPartNumber(props),supplier_part_numbers:props.supplierPartNumbers,transistor_type:props.type,display_name:props.displayName});this.source_component_id=source_component.source_component_id}};function inflateSourceTransistor(sourceElm,inflatorContext){let{injectionDb,subcircuit,groupsMap}=inflatorContext,pcbElm=injectionDb.pcb_component.getWhere({source_component_id:sourceElm.source_component_id}),cadElm=injectionDb.cad_component.getWhere({source_component_id:sourceElm.source_component_id}),{pcbX,pcbY}=getInflatedPcbPlacement({pcbComponent:pcbElm,sourceGroupId:sourceElm.source_group_id,inflatorContext}),transistor=new Transistor({name:sourceElm.name,type:sourceElm.transistor_type,layer:pcbElm?.layer,pcbX,pcbY,pcbRotation:pcbElm?.rotation,doNotPlace:pcbElm?.do_not_place,obstructsWithinBounds:pcbElm?.obstructs_within_bounds});if(pcbElm){let footprint=inflateFootprintComponent(pcbElm,{...inflatorContext,normalComponent:transistor});footprint&&transistor.add(footprint)}sourceElm.source_group_id&&groupsMap?.has(sourceElm.source_group_id)?groupsMap.get(sourceElm.source_group_id).add(transistor):subcircuit.add(transistor)}function inflateStandalonePcbPrimitives(inflatorContext){let{injectionDb,subcircuit,groupsMap}=inflatorContext,standalonePrimitiveTypes=["pcb_silkscreen_rect","pcb_silkscreen_circle","pcb_silkscreen_line","pcb_silkscreen_path","pcb_silkscreen_text","pcb_fabrication_note_text","pcb_fabrication_note_path","pcb_fabrication_note_rect","pcb_note_text","pcb_note_rect","pcb_note_path","pcb_note_line","pcb_via","pcb_hole","pcb_plated_hole","pcb_cutout","pcb_soldermask_opening"],standalonePrimitives=injectionDb.toArray().filter(elm=>{if(!standalonePrimitiveTypes.includes(elm.type))return!1;if(elm.type==="pcb_via"){if(!elm.pcb_trace_id)return!0;let pcbTrace=injectionDb.pcb_trace.get(elm.pcb_trace_id),sourceTraceId=pcbTrace?.source_trace_id;return!(sourceTraceId&&injectionDb.source_trace.get(sourceTraceId)&&pcbTrace?.route.some(point62=>point62.route_type==="via"&&Math.abs(point62.x-elm.x)<1e-4&&Math.abs(point62.y-elm.y)<1e-4))}return elm.type==="pcb_cutout"?!0:elm.type==="pcb_soldermask_opening"?elm.pcb_component_id===void 0:"pcb_component_id"in elm&&(elm.pcb_component_id===null||elm.pcb_component_id===void 0)});if(standalonePrimitives.length===0)return;let components=createComponentsFromCircuitJson({componentName:"",componentRotation:"0deg"},standalonePrimitives);for(let component of components)subcircuit.add(component)}var inflateCircuitJson=(target,circuitJson,children)=>{if(!circuitJson)return;let injectionDb=cju_default(circuitJson);if(circuitJson&&children?.length>0)throw new Error("Component cannot have both circuitJson and children");let inflationCtx={injectionDb,subcircuit:target,groupsMap:new Map},sourceGroups=injectionDb.source_group.list(),renderedGroupIds=new Set,groupsToRender=[...sourceGroups];for(;groupsToRender.length>0;){let groupIndex=groupsToRender.findIndex(g22=>!g22.parent_source_group_id||renderedGroupIds.has(g22.parent_source_group_id));if(groupIndex===-1){let remainingIds=groupsToRender.map(g22=>g22.source_group_id).join(", ");throw new Error(`Cannot inflate source_groups: cyclic dependency or missing parent detected. Remaining groups: ${remainingIds}`)}let groupToRender=groupsToRender[groupIndex];inflateSourceGroup(groupToRender,inflationCtx),renderedGroupIds.add(groupToRender.source_group_id),groupsToRender.splice(groupIndex,1)}let pcbBoards=injectionDb.pcb_board.list();for(let pcbBoard of pcbBoards)inflatePcbBoard(pcbBoard,inflationCtx);let sourceComponents=injectionDb.source_component.list();for(let sourceComponent of sourceComponents)switch(sourceComponent.ftype){case"simple_resistor":inflateSourceResistor(sourceComponent,inflationCtx);break;case"simple_capacitor":inflateSourceCapacitor(sourceComponent,inflationCtx);break;case"simple_inductor":inflateSourceInductor(sourceComponent,inflationCtx);break;case"simple_diode":inflateSourceDiode(sourceComponent,inflationCtx);break;case"simple_fiducial":inflateSourceFiducial(sourceComponent,inflationCtx);break;case"simple_led":inflateSourceLed(sourceComponent,inflationCtx);break;case"simple_chip":inflateSourceChip(sourceComponent,inflationCtx);break;case"simple_connector":inflateSourceConnector(sourceComponent,inflationCtx);break;case"simple_transistor":inflateSourceTransistor(sourceComponent,inflationCtx);break;case"simple_mosfet":inflateSourceMosfet(sourceComponent,inflationCtx);break;case"simple_push_button":inflateSourcePushButton(sourceComponent,inflationCtx);break;case"simple_switch":inflateSourceSwitch(sourceComponent,inflationCtx);break;default:throw new Error(`No inflator implemented for source component ftype: "${sourceComponent.ftype}"`)}let sourcePorts=injectionDb.source_port.list();for(let sourcePort of sourcePorts)inflateSourcePort(sourcePort,inflationCtx);let sourceTraces=injectionDb.source_trace.list();for(let sourceTrace of sourceTraces)inflateSourceTrace(sourceTrace,inflationCtx);inflateStandalonePcbPrimitives(inflationCtx)},resolveBoardMotorMount=board=>{if(boardMountsToPrintedPart(board)){resolvePrintedPartMounts(board);return}let{mountedTo,mountRotation,mountRotationAnchor,mountOrientation}=board._parsedProps;if(!mountedTo){if(mountRotation||mountRotationAnchor||mountOrientation)throw new Error(`board "${board.name}" mounting alignment requires mountedTo`);return}let separator=mountedTo.lastIndexOf("."),motorName=mountedTo.slice(0,separator),face=mountedTo.slice(separator+1);if(separator<1||face!=="backface")throw new Error(`board "${board.name}" mountedTo "${mountedTo}" must name a motor backface, e.g. "NEMA17.backface"`);let motors=getComponentsInAssemblyScope(board).filter(motor2=>motor2.componentName==="AssemblyMotor"&&matchesAssemblyIdentity(motor2,motorName));if(motors.length!==1)throw new Error(`board "${board.name}" mountedTo "${mountedTo}" matched ${motors.length} motors; expected exactly one in the assembly device`);let motor=motors[0];if(motor._parsedProps.mountedTo){resolvePrintedPartMounts(board);return}let direction3=motor._parsedProps.shaftFacingDirection;if(direction3!=="z+"&&direction3!=="z-")throw new Error(`board "${board.name}" cannot mount to motor "${motorName}" facing ${direction3}: rotated PCB boards are not yet supported; use shaftFacingDirection="z+" or "z-"`);if(mountRotationAnchor&&!mountRotation)throw new Error(`board "${board.name}" mountRotationAnchor requires mountRotation`);if(motor.props.shaftFacingDirection&&mountOrientation&&mountOrientation!==(direction3==="z+"?"top_layer_toward_mount_face":"bottom_layer_toward_mount_face"))throw new Error(`board "${board.name}" mountOrientation "${mountOrientation}" conflicts with motor "${motorName}" shaftFacingDirection "${direction3}"`);return motor},resolveMotorMountedBoard=motor=>{let boards=getComponentsInAssemblyScope(motor).filter(board=>board.componentName==="Board").filter(board=>resolveBoardMotorMount(board)===motor);if(boards.length>1)throw new Error(`assembly.motor "${motor.name}" has multiple mounted boards; only one board may determine its placement`);return boards[0]};function createCircuitJsonDatabase(){if(typeof cju_indexed_default!="function")return cju_default([]);let indexed=cju_indexed_default([],{indexConfig:{byId:!0,byType:!0}});return typeof indexed.insert!="function"||typeof indexed.insertAll!="function"||typeof indexed.subtree!="function"?cju_default([]):indexed}var IsolatedCircuit=class{constructor({platform,projectUrl,cachedSubcircuits,pendingSubcircuitRenders}={}){__publicField(this,"firstChild",null);__publicField(this,"children");__publicField(this,"db");__publicField(this,"root",null);__publicField(this,"isRootCircuit",!1);__publicField(this,"cachedSubcircuits");__publicField(this,"pendingSubcircuitRenders");__publicField(this,"_schematicDisabledOverride");__publicField(this,"pcbDisabled",!1);__publicField(this,"pcbRoutingDisabled",!1);__publicField(this,"_featureMspSchematicTraceRouting",!0);__publicField(this,"_featurePcbViaStitching",!0);__publicField(this,"name");__publicField(this,"platform");__publicField(this,"projectUrl");__publicField(this,"_hasRenderedAtleastOnce",!1);__publicField(this,"_asyncEffectIdsByPhase",new Map);__publicField(this,"_asyncEffectPhaseById",new Map);__publicField(this,"_hasUnrenderedUpdatesFromAsyncEffects",!1);__publicField(this,"_runningAsyncEffectsById",new Map);__publicField(this,"_hasRenderLifecycleListeners",!1);__publicField(this,"_eventListeners",{});this.children=[],this.db=createCircuitJsonDatabase(),this.platform=platform,this.projectUrl=projectUrl,this.pcbDisabled=platform?.pcbDisabled??!1,this.pcbRoutingDisabled=platform?.routingDisabled??!1,this.cachedSubcircuits=cachedSubcircuits,this.pendingSubcircuitRenders=pendingSubcircuitRenders,this.root=this}get schematicDisabled(){return this._schematicDisabledOverride!==void 0?this._schematicDisabledOverride:this.platform?.schematicDisabled!==void 0?this.platform.schematicDisabled:this._getBoard()?._parsedProps?.schematicDisabled??!1}set schematicDisabled(value){this._schematicDisabledOverride=value}add(componentOrElm){let component;(0,import_react10.isValidElement)(componentOrElm)?component=createInstanceFromReactElement(componentOrElm):component=componentOrElm,this.children.push(component)}setPlatform(platform){this.platform={...this.platform,...platform},platform.pcbDisabled!==void 0&&(this.pcbDisabled=platform.pcbDisabled),platform.routingDisabled!==void 0&&(this.pcbRoutingDisabled=platform.routingDisabled)}_getBoard(){let findBoard=components=>{for(let child of components){if(child.componentName==="Board")return child;if(isAssemblyDeviceContainer(child)){let nested=findBoard(child.children);if(nested)return nested}}};return findBoard(this.children)}_guessRootComponent(){if(this.firstChild)return;if(this.children.length===0)throw new Error("Not able to guess root component: IsolatedCircuit has no children (use circuit.add(...))");let panels=this.children.filter(child=>child.lowercaseComponentName==="panel");if(panels.length>1)throw new Error("Only one <panel> is allowed per circuit");if(panels.length===1){if(this.children.length!==1)throw new Error("<panel> must be the root element of the circuit");this.firstChild=panels[0];return}if(this.children.length===1&&(this.children[0].isGroup||isAssemblyDeviceContainer(this.children[0]))){this.firstChild=this.children[0];return}let group2=new Group5({subcircuit:!0});group2.parent=this,group2.addAll(this.children),this.children=[group2],this.firstChild=group2}render(){this.firstChild||this._guessRootComponent();let{firstChild,db:db22}=this;if(!firstChild)throw new Error("IsolatedCircuit has no root component");firstChild.parent=this,firstChild.runRenderCycle(),this._hasUnrenderedUpdatesFromAsyncEffects=!1,this._hasRenderedAtleastOnce=!0}async renderUntilSettled(){for(this.db.source_project_metadata.list()?.[0]||this.db.source_project_metadata.insert({software_used_string:`@tscircuit/core@${this.getCoreVersion()}`,...this.projectUrl?{project_url:this.projectUrl}:{}}),this.render();!this.isDoneRendering();)await new Promise(resolve7=>{let resume=()=>{clearTimeout(timer),this.removeListener("asyncEffect:end",resume),resolve7()},timer=setTimeout(resume,100);this.on("asyncEffect:end",resume),this._hasUnrenderedUpdatesFromAsyncEffects&&resume()}),(this._hasUnrenderedUpdatesFromAsyncEffects||this._asyncEffectPhaseById.size===0)&&this.render();this.emit("renderComplete")}isDoneRendering(){return this._hasRenderedAtleastOnce&&!this._hasIncompleteAsyncEffects()}_hasIncompleteAsyncEffects(){return this._asyncEffectPhaseById.size>0||this._hasUnrenderedUpdatesFromAsyncEffects?!0:this.children.some(child=>child._hasIncompleteAsyncEffects())}_hasIncompleteAsyncEffectsForPhase(phase){return(this._asyncEffectIdsByPhase.get(phase)?.size??0)>0}getRunningAsyncEffects(){return Array.from(this._runningAsyncEffectsById.values())}getCircuitJson(){return this._hasRenderedAtleastOnce||this.render(),this.db.toArray()}toJson(){return this.getCircuitJson()}async getSvg(options){let circuitToSvg=await Promise.resolve().then(()=>(init_dist9(),dist_exports4)).catch(e210=>{throw new Error(`To use circuit.getSvg, you must install the "circuit-to-svg" package.
952
+ `)}`)}catch(error2){debug12(`Failed to convert circuit JSON to SPICE: ${error2}`),root.db.simulation_unknown_experiment_error.insert({simulation_experiment_id:simulationExperimentId,error_type:"simulation_unknown_experiment_error",message:error2 instanceof Error?error2.message:String(error2)});continue}let voltageProbeByGraphName=new Map,voltageProbeById=new Map,graphDisplayOverridesByProbeId=new Map;for(let probe of voltageProbes)probe.finalProbeName&&voltageProbeByGraphName.set(probe.finalProbeName,probe),probe.simulation_voltage_probe_id&&(voltageProbeById.set(probe.simulation_voltage_probe_id,probe),graphDisplayOverridesByProbeId.set(probe.simulation_voltage_probe_id,getVoltageProbeGraphDisplayOverrides(probe)));for(let ammeter of ammeters)ammeter.simulation_current_probe_id&&graphDisplayOverridesByProbeId.set(ammeter.simulation_current_probe_id,getAmmeterGraphDisplayOverrides(ammeter));let scopedCurrentProbeIds=new Set(ammeters.map(ammeter=>ammeter.simulation_current_probe_id).filter(simulationCurrentProbeId=>!!simulationCurrentProbeId)),currentProbeById=new Map,currentProbeByName=new Map;for(let probe of root.db.simulation_current_probe.list().filter(probe2=>scopedCurrentProbeIds.has(probe2.simulation_current_probe_id)))currentProbeById.set(probe.simulation_current_probe_id,probe),probe.name!==void 0&&currentProbeByName.set(probe.name,probe);let orderedSimulationProbes=root.db.simulation_voltage_probe.list().filter(probe=>voltageProbeById.has(probe.simulation_voltage_probe_id)),firstSpiceNetlist=simulationRuns[0]?.spiceNetlist,graphNamesFromNetlist=firstSpiceNetlist?getTransientVoltageGraphNamesFromSpiceNetlist(firstSpiceNetlist):[];if(graphNamesFromNetlist.length===orderedSimulationProbes.length)for(let[simulationProbeIndex,simulationProbe]of orderedSimulationProbes.entries()){let probe=voltageProbeById.get(simulationProbe.simulation_voltage_probe_id),graphName=graphNamesFromNetlist[simulationProbeIndex];probe&&graphName&&voltageProbeByGraphName.set(graphName,probe)}else debug12(`Skipping probe-to-graph order mapping because counts differ: probes=${orderedSimulationProbes.length} graphNames=${graphNamesFromNetlist.length}`);let engineName=analogSimulation.getSpiceEngineName()??"spicey",spiceEngine3=spiceEngineMap[engineName];if(!spiceEngine3)throw new Error(`SPICE engine "${engineName}" not found in platform config. Available engines: ${JSON.stringify(Object.keys(spiceEngineMap).filter(spiceEngineName=>spiceEngineName!=="spicey"))}`);let effectId=`spice-simulation-${engineName}-${simulationExperimentId}`;debug12(`Queueing simulation for spice engine: ${engineName} (id: ${effectId})`),group2._queueAsyncEffect(effectId,async()=>{try{let insertedVoltageGraphs=[],insertedCurrentGraphs=[];for(let simulationRun of simulationRuns){debug12(`Running simulation with engine: ${engineName}`);let simulationResult=await spiceEngine3.simulate(simulationRun.spiceString);debug12(`Simulation completed, received ${simulationResult.simulationResultCircuitJson.length} elements`);for(let simulationResultCircuitElement of simulationResult.simulationResultCircuitJson){if(!isCircuitElementInput(simulationResultCircuitElement)){debug12("Skipping invalid simulation result element");continue}let simulationResultWithSweepCoordinate=attachSweepCoordinateToSimulationResult({simulationResult:simulationResultCircuitElement,simulationParameterSweepCoordinate:simulationRun.simulationParameterSweepCoordinate});if(isVoltageGraph(simulationResultWithSweepCoordinate)){simulationResultWithSweepCoordinate.simulation_experiment_id=simulationExperiment.simulation_experiment_id;let probeMatch=simulationResultWithSweepCoordinate.name?voltageProbeByGraphName.get(simulationResultWithSweepCoordinate.name):void 0;probeMatch&&(simulationResultWithSweepCoordinate.color=probeMatch.color??void 0,simulationResultWithSweepCoordinate.source_probe_id=probeMatch.simulation_voltage_probe_id??void 0)}else if(isSimulationVoltageResult(simulationResultWithSweepCoordinate)){simulationResultWithSweepCoordinate.simulation_experiment_id=simulationExperiment.simulation_experiment_id;let probeMatch=voltageProbeById.get(simulationResultWithSweepCoordinate.simulation_voltage_probe_id)??(simulationResultWithSweepCoordinate.name?voltageProbeByGraphName.get(simulationResultWithSweepCoordinate.name):void 0);probeMatch?.simulation_voltage_probe_id&&(simulationResultWithSweepCoordinate.color=probeMatch.color??void 0,simulationResultWithSweepCoordinate.simulation_voltage_probe_id=probeMatch.simulation_voltage_probe_id)}if(isCurrentGraph2(simulationResultWithSweepCoordinate)){simulationResultWithSweepCoordinate.simulation_experiment_id=simulationExperiment.simulation_experiment_id;let probeMatch=(simulationResultWithSweepCoordinate.source_probe_id?currentProbeById.get(simulationResultWithSweepCoordinate.source_probe_id):void 0)??(simulationResultWithSweepCoordinate.name?currentProbeByName.get(simulationResultWithSweepCoordinate.name):void 0);probeMatch&&(simulationResultWithSweepCoordinate.color=probeMatch.color,simulationResultWithSweepCoordinate.source_probe_id=probeMatch.simulation_current_probe_id)}else if(isSimulationCurrentResult(simulationResultWithSweepCoordinate)){simulationResultWithSweepCoordinate.simulation_experiment_id=simulationExperiment.simulation_experiment_id;let probeMatch=currentProbeById.get(simulationResultWithSweepCoordinate.simulation_current_probe_id)??(simulationResultWithSweepCoordinate.name?currentProbeByName.get(simulationResultWithSweepCoordinate.name):void 0);probeMatch&&(simulationResultWithSweepCoordinate.color=probeMatch.color,simulationResultWithSweepCoordinate.simulation_current_probe_id=probeMatch.simulation_current_probe_id)}let insertedSimulationResult=root.db.insert(simulationResultWithSweepCoordinate);isVoltageGraph(insertedSimulationResult)&&insertedVoltageGraphs.push({type:"voltage",graph:insertedSimulationResult}),isCurrentGraph2(insertedSimulationResult)&&insertedCurrentGraphs.push({type:"current",graph:insertedSimulationResult}),debug12(`Inserted ${simulationResultWithSweepCoordinate.type} into database`)}}analogSimulation.usesIndependentGraphAxes()&&insertIndependentAxisScopeTraces({db:root.db,graphs:[...insertedVoltageGraphs,...insertedCurrentGraphs],graphDisplayOverridesByProbeId}),group2._markDirty("SimulationSpiceEngineRender")}catch(error2){debug12(`Simulation failed for engine ${engineName}: ${error2}`),root.db.simulation_unknown_experiment_error.insert({simulation_experiment_id:simulationExperimentId,error_type:"simulation_unknown_experiment_error",message:error2 instanceof Error?error2.message:String(error2)})}})}}function Group_doInitialSourceAddConnectivityMapKey(group2){if(!group2.isSubcircuit)return;let{db:db22}=group2.root,traces=group2.selectAll("trace"),vias=group2.selectAll("via"),nets=group2.selectAll("net"),connMap=new ConnectivityMap({});connMap.addConnections(traces.map(t48=>{let source_trace3=db22.source_trace.get(t48.source_trace_id);return source_trace3?[source_trace3.source_trace_id,...source_trace3.connected_source_port_ids,...source_trace3.connected_source_net_ids]:null}).filter(c22=>c22!==null));let sourceNets=db22.source_net.list().filter(net=>net.subcircuit_id===group2.subcircuit_id);for(let sourceNet of sourceNets)connMap.addConnections([[sourceNet.source_net_id]]);let{name:subcircuitName}=group2._parsedProps;for(let trace of traces){if(!trace.source_trace_id)continue;let connNetId=connMap.getNetConnectedToId(trace.source_trace_id);connNetId&&(trace.subcircuit_connectivity_map_key=`${subcircuitName??`unnamedsubcircuit${group2.subcircuit_id??group2.source_group_id??group2._renderId}`}_${connNetId}`,db22.source_trace.update(trace.source_trace_id,{subcircuit_connectivity_map_key:trace.subcircuit_connectivity_map_key}))}let allSourcePortIds=new Set;for(let trace of traces){if(!trace.source_trace_id)continue;let source_trace3=db22.source_trace.get(trace.source_trace_id);if(source_trace3)for(let id3 of source_trace3.connected_source_port_ids)allSourcePortIds.add(id3)}for(let portId of allSourcePortIds){let connNetId=connMap.getNetConnectedToId(portId);if(!connNetId)continue;let connectivityMapKey=`${subcircuitName??`unnamedsubcircuit${group2.subcircuit_id??group2.source_group_id??group2._renderId}`}_${connNetId}`;db22.source_port.update(portId,{subcircuit_connectivity_map_key:connectivityMapKey})}let allSourceNetIds=new Set;for(let trace of traces){if(!trace.source_trace_id)continue;let source_trace3=db22.source_trace.get(trace.source_trace_id);if(source_trace3)for(let source_net_id of source_trace3.connected_source_net_ids)allSourceNetIds.add(source_net_id)}for(let sourceNet of sourceNets)allSourceNetIds.add(sourceNet.source_net_id);for(let netId of allSourceNetIds){let connNetId=connMap.getNetConnectedToId(netId);if(!connNetId)continue;let connectivityMapKey=`${subcircuitName??`unnamedsubcircuit${group2.subcircuit_id??group2.source_group_id??group2._renderId}`}_${connNetId}`;db22.source_net.update(netId,{subcircuit_connectivity_map_key:connectivityMapKey});let netInstance=nets.find(n22=>n22.source_net_id===netId);netInstance&&(netInstance.subcircuit_connectivity_map_key=connectivityMapKey)}for(let via of vias){let connectedNetOrTrace=via._getConnectedNetOrTrace();connectedNetOrTrace&&connectedNetOrTrace.subcircuit_connectivity_map_key&&(via.subcircuit_connectivity_map_key=connectedNetOrTrace.subcircuit_connectivity_map_key)}}var Group_doInitialStandaloneSubcircuitPcbDesignRuleChecks=group2=>{let isRootSubcircuit=group2.root?.firstChild===group2;if(!group2.isSubcircuit||!isRootSubcircuit||group2._getBoard())return;let routingDisabled=group2.root?.pcbRoutingDisabled||group2.getInheritedProperty("routingDisabled"),drcChecksDisabled=group2.root?.platform?.drcChecksDisabled??group2.getInheritedProperty("drcChecksDisabled"),routingDrcChecksDisabled=group2.root?.platform?.routingDrcChecksDisabled??group2.getInheritedProperty("routingDrcChecksDisabled");if(group2.root?.pcbDisabled||routingDisabled||drcChecksDisabled||routingDrcChecksDisabled||group2._hasIncompleteAsyncEffectsInSubtreeForPhase("PcbTraceRender")||group2._hasTracesToRoute()&&!group2._areChildSubcircuitsRouted()||group2._standaloneSubcircuitDrcChecksComplete||group2._standaloneSubcircuitDrcChecksInProgress)return;let{db:db22}=group2.root,subcircuitCircuitJson=db22.subtree({subcircuit_id:group2.subcircuit_id}).toArray();group2._standaloneSubcircuitDrcChecksInProgress=!0,group2._queueAsyncEffect("standalone-subcircuit:routing-drc-checks",async()=>{try{let results=await runAllRoutingChecks(subcircuitCircuitJson);db22.insertAll(dedupePcbDrcErrors(results)),group2._standaloneSubcircuitDrcChecksComplete=!0}finally{group2._standaloneSubcircuitDrcChecksInProgress=!1}})},addPourNetMap=(target,pourNetMap)=>{for(let[layer,netOrNets]of Object.entries(pourNetMap)){if(!netOrNets)continue;let nets=Array.isArray(netOrNets)?netOrNets:[netOrNets],layerNets=target.get(layer)??new Set;for(let net of nets)layerNets.add(net);target.set(layer,layerNets)}},toFanoutPourNetMap=netsByLayer=>Object.fromEntries(Array.from(netsByLayer,([layer,nets])=>[layer,nets.size===1?Array.from(nets)[0]:Array.from(nets)])),Group_getFanoutPourNetMap=(group2,routingPhasePlans)=>{let explicitMaps=routingPhasePlans.map(plan=>plan.fanoutPourNetMap).filter(map=>map!==void 0),netsByLayer=new Map;if(explicitMaps.length>0){for(let explicitMap of explicitMaps)addPourNetMap(netsByLayer,explicitMap);return toFanoutPourNetMap(netsByLayer)}let scope=group2;for(;scope;){if(scope.isSubcircuit){let subcircuit=scope,copperPours=subcircuit.selectAll("copperpour");for(let copperPour of copperPours){if(copperPour.getSubcircuit()!==subcircuit)continue;let{layer,connectsTo}=copperPour._parsedProps;addPourNetMap(netsByLayer,{[layer]:connectsTo})}}scope=scope.parent}return netsByLayer.size>0?toFanoutPourNetMap(netsByLayer):void 0},baseBreakoutPointProps=pcbLayoutProps.omit({pcbRotation:!0,layer:!0}),BaseBreakoutPoint=class extends PrimitiveComponent2{constructor(){super(...arguments);__publicField(this,"pcb_breakout_point_id",null);__publicField(this,"matchedPort",null);__publicField(this,"matchedNet",null);__publicField(this,"matchedSourceTraceId",null);__publicField(this,"isPcbPrimitive",!0)}_getSourceTraceIdForPort(port){let{db:db22}=this.root;return db22.source_trace.list().find(st22=>st22.connected_source_port_ids.includes(port.source_port_id))?.source_trace_id}_getSourceNetIdForPort(port){let{db:db22}=this.root;return db22.source_trace.list().find(st22=>st22.connected_source_port_ids.includes(port.source_port_id))?.connected_source_net_ids[0]}_renderPcbBreakoutPoint({layer}={}){if(this.pcb_breakout_point_id||this.root?.pcbDisabled)return;let{db:db22}=this.root,position4=this._getGlobalPcbPositionBeforeLayout(),group2=this.parent?.getGroup(),subcircuit=this.getSubcircuit();if(!group2||!group2.pcb_group_id)return;let pcb_breakout_point3=db22.pcb_breakout_point.insert({pcb_group_id:group2.pcb_group_id,subcircuit_id:subcircuit?.subcircuit_id??void 0,source_port_id:this.matchedPort?.source_port_id??void 0,source_trace_id:this.matchedPort?this.matchedSourceTraceId??this._getSourceTraceIdForPort(this.matchedPort):void 0,source_net_id:this.matchedNet?this.matchedNet.source_net_id:this.matchedPort?this._getSourceNetIdForPort(this.matchedPort):void 0,layer,x:position4.x,y:position4.y});this.pcb_breakout_point_id=pcb_breakout_point3.pcb_breakout_point_id}_getPcbCircuitJsonBounds(){let position4=this._getGlobalPcbPositionBeforeLayout();return{center:{x:position4.x,y:position4.y},bounds:{left:position4.x,top:position4.y,right:position4.x,bottom:position4.y},width:0,height:0}}_setPositionFromLayout(newCenter){let{db:db22}=this.root;if(!this.pcb_breakout_point_id)return;let updatedProperties={x:newCenter.x,y:newCenter.y};this.matchedSourceTraceId&&(updatedProperties.source_trace_id=this.matchedSourceTraceId),db22.pcb_breakout_point.update(this.pcb_breakout_point_id,updatedProperties)}_moveCircuitJsonElements({deltaX,deltaY}){if(this.root?.pcbDisabled)return;let{db:db22}=this.root;if(!this.pcb_breakout_point_id)return;let point62=db22.pcb_breakout_point.get(this.pcb_breakout_point_id);point62&&db22.pcb_breakout_point.update(this.pcb_breakout_point_id,{x:point62.x+deltaX,y:point62.y+deltaY})}getPcbSize(){return{width:0,height:0}}},BreakoutPoint=class extends BaseBreakoutPoint{get config(){return{componentName:"BreakoutPoint",zodProps:breakoutPointProps}}_matchConnection(){if(this.matchedPort)return;let{connection}=this._parsedProps,subcircuit=this.getSubcircuit();subcircuit&&(this.matchedPort=subcircuit.selectOne(connection,{type:"port"}),this.matchedPort||(this.matchedNet=subcircuit.selectOne(connection,{type:"net"})),!this.matchedPort&&!this.matchedNet&&this.renderError(`Could not find connection target "${connection}"`))}doInitialPcbPrimitiveRender(){this._matchConnection(),this._renderPcbBreakoutPoint()}},SavedFanoutPoint=class extends BreakoutPoint{constructor(){super(...arguments);__publicField(this,"exitLayer","top")}doInitialPcbPrimitiveRender(){this._matchConnection(),this._renderPcbBreakoutPoint({layer:this.exitLayer})}};function getSavedFanoutTraces(breakout,input2){let{db:db22}=breakout.root,boardLayers=getViaBoardLayers(input2.layerCount),coveredConnections=new Set,exits=breakout.children.filter(child=>child instanceof SavedFanoutPoint),traces=(breakout._parsedProps.pcbTracePaths??[]).map((path,pathIndex)=>{for(let point62 of path.route)if((point62.route_type==="wire"?[point62.layer]:[point62.from_layer,point62.to_layer]).some(layer=>!boardLayers.includes(layer)))throw new Error(`Saved fanout path "${path.connection}" uses a layer unavailable on this board`);let exit=exits[pathIndex],port=exit.matchedPort,connection=input2.connections.find(connection2=>connection2.pointsToConnect.some(point62=>point62.pcb_port_id===port.pcb_port_id));if(!connection)throw new Error(`No fanout connection for saved path "${path.connection}"`);let pcbExit=db22.pcb_breakout_point.get(exit.pcb_breakout_point_id),localExit=path.route.at(-1),transform7=compose2(exit._computePcbGlobalTransformBeforeLayout(),translate2(-localExit.x,-localExit.y)),originalExit=applyToPoint2(transform7,localExit),route2=resolveSavedTraceRouteWidths(path.route).map(point62=>{let position4=applyToPoint2(transform7,point62);return{...point62,x:position4.x+pcbExit.x-originalExit.x,y:position4.y+pcbExit.y-originalExit.y}}),first=route2[0],firstLayer=first.route_type==="wire"?first.layer:first.from_layer,portPosition=port._getGlobalPcbPositionAfterLayout();if(Math.hypot(first.x-portPosition.x,first.y-portPosition.y)>1e-4||!port.getAvailablePcbLayers().includes(firstLayer))throw new Error(`Saved fanout path "${path.connection}" must start at its PCB port on an available layer`);if(first.route_type==="via"&&!input2.allowViaInPad)throw new Error(`Saved fanout path "${path.connection}" starts with a via at a pad; enable allowViaInPad`);let last=route2.at(-1),lastLayer=last.route_type==="wire"?last.layer:last.to_layer,endpoints=[{...first,layer:firstLayer},{...last,layer:lastLayer}];if(connection.pointsToConnect.some(point62=>!endpoints.some(endpoint=>Math.hypot(point62.x-endpoint.x,point62.y-endpoint.y)<1e-4&&point62.layer===endpoint.layer)))throw new Error(`Saved fanout path "${path.connection}" does not cover its connection endpoints`);let startContactWidths=getSavedTraceViaContactWidths(route2,0,input2.minTraceWidth),endContactWidths=getSavedTraceViaContactWidths(route2,route2.length-1,input2.minTraceWidth);return first.route_type==="via"&&(route2.splice(1,0,{route_type:"wire",x:first.x,y:first.y,layer:first.to_layer,width:startContactWidths.toWidth}),route2.unshift({route_type:"wire",x:first.x,y:first.y,layer:first.from_layer,width:startContactWidths.fromWidth})),last.route_type==="via"&&(route2.splice(route2.length-1,0,{route_type:"wire",x:last.x,y:last.y,layer:last.from_layer,width:endContactWidths.fromWidth}),route2.push({route_type:"wire",x:last.x,y:last.y,layer:last.to_layer,width:endContactWidths.toWidth})),last.route_type==="via"&&route2.push({route_type:"wire",x:last.x,y:last.y,layer:last.to_layer,width:endContactWidths.toWidth}),coveredConnections.add(connection),{type:"pcb_trace",pcb_trace_id:`saved_fanout_${breakout.pcb_group_id}_${pathIndex}`,connection_name:connection.name,source_trace_id:connection.source_trace_id,connectsTo:[connection.source_trace_id,...connection.pointsToConnect.map(point62=>point62.pointId)].filter(id3=>!!id3),route:route2}}),missing=input2.connections.filter(connection=>!coveredConnections.has(connection));if(missing.length)throw new Error(`pcbTracePaths must cover every fanout connection; missing: ${missing.map(connection=>connection.name).join(", ")}`);return traces}function getPhaseSortValue(routingPhaseIndex){return routingPhaseIndex===null?Number.POSITIVE_INFINITY:routingPhaseIndex}function compareRoutingPhasePlans(a22,b22){return getPhaseSortValue(a22.routingPhaseIndex)-getPhaseSortValue(b22.routingPhaseIndex)}function getOrCreateRoutingPhasePlan(plansByPhaseIndex,routingPhaseIndex){let plan=plansByPhaseIndex.get(routingPhaseIndex);return plan||(plan={routingPhaseIndex,nets:[],traces:[]},plansByPhaseIndex.set(routingPhaseIndex,plan)),plan}function getNetRoutingPhaseIndex(net){return net.props.routingPhaseIndex??null}function getTraceRoutingPhaseIndex(trace,buses=[]){let busRoutingPhaseIndexes=new Set;for(let bus of buses){if(bus._parsedProps.routingPhaseIndex===void 0)continue;bus._parsedProps.connections.some(connection=>connection===trace.name||traceHasEndpointMatchingConnectionSelector(trace,convertPortSelectorToEndpointKey(connection)))&&busRoutingPhaseIndexes.add(bus._parsedProps.routingPhaseIndex)}if(busRoutingPhaseIndexes.size>1)throw new Error(`Trace "${trace.name}" belongs to buses with different routing phases`);let busRoutingPhaseIndex=busRoutingPhaseIndexes.values().next().value;if(busRoutingPhaseIndex!==void 0)return busRoutingPhaseIndex;let traceRoutingPhaseIndex=trace.props.routingPhaseIndex;if(traceRoutingPhaseIndex!==void 0)return traceRoutingPhaseIndex;let routingPhaseIndex=null,connectedNets=trace._findConnectedNets().nets;for(let net of connectedNets){let netRoutingPhaseIndex=getNetRoutingPhaseIndex(net);typeof netRoutingPhaseIndex=="number"&&(routingPhaseIndex===null||netRoutingPhaseIndex<routingPhaseIndex)&&(routingPhaseIndex=netRoutingPhaseIndex)}return routingPhaseIndex}function convertPortSelectorToEndpointKey(selector2){return selector2.trim().replace(/\s*>\s*/g,".").replace(/\s+/g,".").replace(/^\./,"").replace(/\.\./g,".")}function getConnectionSelectorsFromAutoroutingPhaseProps(phaseProps){return phaseProps.connection===void 0&&phaseProps.connections===void 0?phaseProps.pcbTracePaths?.map(path=>path.connection)??[]:[...phaseProps.connection?[phaseProps.connection]:[],...phaseProps.connections??[]]}function traceHasEndpointMatchingConnectionSelector(trace,connectionSelectorEndpointKey){if(trace.getTracePortPathSelectors().some(selector2=>convertPortSelectorToEndpointKey(selector2)===connectionSelectorEndpointKey))return!0;let port=trace.getSubcircuit().selectOne(connectionSelectorEndpointKey,{type:"port"});return port!==null&&(trace._findConnectedPorts().ports?.includes(port)??!1)}function getAutoroutersByPhaseIndex(group2){let autoroutingPhases=group2.selectAll("autoroutingphase"),autoroutersByPhaseIndex=new Map;for(let autoroutingPhase of autoroutingPhases){let{phaseIndex,autorouter}=autoroutingPhase._parsedProps;autorouter!==void 0&&autoroutersByPhaseIndex.set(phaseIndex??null,autorouter)}return autoroutersByPhaseIndex}function getAutoroutingPhasePropsByPhaseIndex(group2){let autoroutingPhases=group2.selectAll("autoroutingphase"),propsByPhaseIndex=new Map;for(let autoroutingPhase of autoroutingPhases){let props=autoroutingPhase._parsedProps;propsByPhaseIndex.set(props.phaseIndex??null,props)}return propsByPhaseIndex}function toParsedDistance(value){if(value!==void 0)return Number(value)}function getDrcTolerancesFromAutoroutingPhaseProps(phaseProps){let{minTraceWidth,minViaHoleEdgeToViaHoleEdgeClearance,minPlatedHoleDrillEdgeToDrillEdgeClearance,minTraceToPadEdgeClearance,minTraceToHoleEdgeClearance,minPadEdgeToPadEdgeClearance,minBoardEdgeClearance,minViaEdgeToPadEdgeClearance,minViaHoleDiameter,minViaPadDiameter}=phaseProps;if(!(minTraceWidth===void 0&&minViaHoleEdgeToViaHoleEdgeClearance===void 0&&minPlatedHoleDrillEdgeToDrillEdgeClearance===void 0&&minTraceToPadEdgeClearance===void 0&&minTraceToHoleEdgeClearance===void 0&&minPadEdgeToPadEdgeClearance===void 0&&minBoardEdgeClearance===void 0&&minViaEdgeToPadEdgeClearance===void 0&&minViaHoleDiameter===void 0&&minViaPadDiameter===void 0))return{minTraceWidth:toParsedDistance(minTraceWidth),minViaHoleEdgeToViaHoleEdgeClearance:toParsedDistance(minViaHoleEdgeToViaHoleEdgeClearance),minPlatedHoleDrillEdgeToDrillEdgeClearance:toParsedDistance(minPlatedHoleDrillEdgeToDrillEdgeClearance),minTraceToPadEdgeClearance:toParsedDistance(minTraceToPadEdgeClearance),minTraceToHoleEdgeClearance:toParsedDistance(minTraceToHoleEdgeClearance),minPadEdgeToPadEdgeClearance:toParsedDistance(minPadEdgeToPadEdgeClearance),minBoardEdgeClearance:toParsedDistance(minBoardEdgeClearance),minViaEdgeToPadEdgeClearance:toParsedDistance(minViaEdgeToPadEdgeClearance),minViaHoleDiameter:toParsedDistance(minViaHoleDiameter),minViaPadDiameter:toParsedDistance(minViaPadDiameter)}}function Group_getRoutingPhasePlans(group2){let traces=group2.selectAll("trace"),nets=group2.selectAll("net"),buses=group2.selectAll("bus"),breakouts=group2.selectAll("group").filter(candidate=>candidate.isRoutingDirective),breakoutByTrace=new Map,breakoutByNet=new Map;for(let trace of traces){let ancestor=trace.parent;for(;ancestor&&ancestor!==group2;){if(ancestor.isRoutingDirective){breakoutByTrace.set(trace,ancestor);break}ancestor=ancestor.parent}}for(let net of nets)net.parent?.isRoutingDirective&&breakouts.includes(net.parent)&&breakoutByNet.set(net,net.parent);let plansByPhaseIndex=new Map,autoroutersByPhaseIndex=getAutoroutersByPhaseIndex(group2),phasePropsByPhaseIndex=getAutoroutingPhasePropsByPhaseIndex(group2),groupFanoutProps=group2._parsedProps,routeRemaining=group2.getInheritedProperty("routeRemaining")!==!1,defaultPhaseProps=phasePropsByPhaseIndex.get(null),includeUnassignedConnections=routeRemaining||defaultPhaseProps!==void 0&&!defaultPhaseProps.reroute&&getConnectionSelectorsFromAutoroutingPhaseProps(defaultPhaseProps).length===0,hasDirectRoutingTargets=traces.length>0||nets.length>0,hasReroutePhase=Array.from(phasePropsByPhaseIndex.values()).some(phaseProps=>phaseProps.reroute),hasConnectionTargetedPhase=Array.from(phasePropsByPhaseIndex.values()).some(phaseProps=>getConnectionSelectorsFromAutoroutingPhaseProps(phaseProps).length>0);if(!hasDirectRoutingTargets&&!hasReroutePhase&&!hasConnectionTargetedPhase&&breakouts.length===0)return[];for(let net of nets){if(breakoutByNet.has(net))continue;let routingPhaseIndex=getNetRoutingPhaseIndex(net);routingPhaseIndex===null&&!includeUnassignedConnections||getOrCreateRoutingPhasePlan(plansByPhaseIndex,routingPhaseIndex).nets.push(net)}for(let trace of traces){if(breakoutByTrace.has(trace))continue;let routingPhaseIndex=getTraceRoutingPhaseIndex(trace,buses);routingPhaseIndex===null&&!includeUnassignedConnections||getOrCreateRoutingPhasePlan(plansByPhaseIndex,routingPhaseIndex).traces.push(trace)}for(let[phaseIndex,phaseProps]of phasePropsByPhaseIndex){let connectionSelectors=getConnectionSelectorsFromAutoroutingPhaseProps(phaseProps);if(connectionSelectors.length>0){let plan=getOrCreateRoutingPhasePlan(plansByPhaseIndex,phaseIndex),connectionSelectorEndpointKeys=connectionSelectors.map(convertPortSelectorToEndpointKey);plan.connectionSelectors=connectionSelectors;for(let trace of traces)if(!breakoutByTrace.has(trace)&&connectionSelectorEndpointKeys.some(endpointKey=>traceHasEndpointMatchingConnectionSelector(trace,endpointKey))){if(!phaseProps.reroute)for(let existingPlan of plansByPhaseIndex.values())existingPlan!==plan&&(existingPlan.traces=existingPlan.traces.filter(existingTrace=>existingTrace!==trace));if(plan.traces.includes(trace))continue;plan.traces.push(trace)}}(phaseProps.reroute||phaseProps.pcbTracePaths!==void 0)&&getOrCreateRoutingPhasePlan(plansByPhaseIndex,phaseIndex)}let plans=Array.from(plansByPhaseIndex.values()).sort(compareRoutingPhasePlans);for(let plan of plans){plan.autorouter=autoroutersByPhaseIndex.get(plan.routingPhaseIndex);let phaseProps=phasePropsByPhaseIndex.get(plan.routingPhaseIndex);plan.algorithmFn=phaseProps?.algorithmFn,plan.isImplicitRemainingPhase=plan.routingPhaseIndex===null&&phaseProps===void 0,plan.phaseName=phaseProps?.name,plan.reroute=phaseProps?.reroute,plan.region=phaseProps?.region,plan.connectionSelectors=phaseProps?getConnectionSelectorsFromAutoroutingPhaseProps(phaseProps):void 0,plan.busFanoutDirections=phaseProps?.busFanoutDirections??groupFanoutProps.busFanoutDirections,plan.fanoutBoundaryPadding=phaseProps?.fanoutBoundaryPadding??groupFanoutProps.fanoutBoundaryPadding;let fanoutRoutingLayers=phaseProps?.fanoutRoutingLayers??groupFanoutProps.fanoutRoutingLayers;plan.fanoutRoutingLayers=fanoutRoutingLayers?.map(layer=>typeof layer=="string"?layer:layer.name),plan.fanoutPourNetMap=phaseProps?.fanoutPourNetMap??groupFanoutProps.fanoutPourNetMap,plan.drcTolerances=phaseProps?getDrcTolerancesFromAutoroutingPhaseProps(phaseProps):void 0}for(let phase of group2.selectAll("autoroutingphase")){let plan=plansByPhaseIndex.get(phase._parsedProps.phaseIndex??null);if(!plan||(plan.autoroutingPhase=phase,phase._parsedProps.pcbTracePaths===void 0))continue;let config=plan.autorouter!==void 0?getPresetAutoroutingConfig(plan.autorouter,group2.root?.platform):group2._getAutorouterConfig(),isFanout=["fanout","single_layer_fanout"].includes(config.preset??"");plan.getPrecomputedRoutingResult=input2=>getSavedAutoroutingPhaseTraces(phase,input2,isFanout)}let breakoutPlans=[];for(let breakout of breakouts){let breakoutProps22=breakout._parsedProps,shouldUseDefaultAutorouterForBreakoutPoints=breakout.children.some(child=>child instanceof BreakoutPoint)&&breakout.props.autorouter===void 0,breakoutTraces=traces.filter(trace=>breakoutByTrace.get(trace)===breakout),unroutedBreakoutTraces=breakoutTraces.filter(trace=>!trace.pcb_trace_id),pcbGroup=breakout.pcb_group_id?breakout.root?.db.pcb_group.get(breakout.pcb_group_id):null,outlineBounds=pcbGroup?.outline?getBoundsFromPoints(pcbGroup.outline):null,routingWidth=pcbGroup?.width??(outlineBounds?outlineBounds.maxX-outlineBounds.minX:void 0),routingHeight=pcbGroup?.height??(outlineBounds?outlineBounds.maxY-outlineBounds.minY:void 0),routingBounds2=pcbGroup&&routingWidth&&routingHeight?{minX:pcbGroup.center.x-routingWidth/2,maxX:pcbGroup.center.x+routingWidth/2,minY:pcbGroup.center.y-routingHeight/2,maxY:pcbGroup.center.y+routingHeight/2}:void 0,rawBreakoutProps=breakout.props,hasExplicitGeometry=rawBreakoutProps.width!==void 0||rawBreakoutProps.height!==void 0||!!rawBreakoutProps.outline?.length,hasExplicitFanoutBoundaryPadding=rawBreakoutProps.fanoutBoundaryPadding!==void 0,breakoutPlan={routingPhaseIndex:null,routingPcbGroupId:breakout.pcb_group_id??void 0,fanoutRegionPcbGroupId:breakout.pcb_group_id??void 0,routingBounds:routingBounds2,fanoutBounds:hasExplicitGeometry?routingBounds2:hasExplicitFanoutBoundaryPadding?void 0:routingBounds2,autorouter:breakoutProps22.autorouter??"fanout",busFanoutDirections:breakoutProps22.busFanoutDirections,fanoutBoundaryPadding:breakoutProps22.fanoutBoundaryPadding,fanoutRoutingLayers:breakoutProps22.fanoutRoutingLayers?.map(layer=>typeof layer=="string"?layer:layer.name),fanoutPourNetMap:breakoutProps22.fanoutPourNetMap,nets:nets.filter(net=>breakoutByNet.get(net)===breakout),traces:breakoutTraces};if(breakout.isDogboneFanout&&breakoutProps22.pcbTracePaths===void 0){breakoutPlans.push({...breakoutPlan,routingBounds:void 0,fanoutBounds:routingBounds2});continue}if(breakout._parsedProps.pcbTracePaths!==void 0){breakoutPlans.push({...breakoutPlan,autorouter:{local:!0,groupMode:"subcircuit",allowViaInPad:(typeof breakoutProps22.autorouter=="object"?breakoutProps22.autorouter.allowViaInPad:void 0)??group2._getAutorouterConfig().allowViaInPad},getPrecomputedRoutingResult:input2=>({traces:getSavedFanoutTraces(breakout,input2)})});continue}if(!shouldUseDefaultAutorouterForBreakoutPoints){breakoutPlans.push(breakoutPlan);continue}if(breakoutPlans.push({...breakoutPlan,autorouter:"default",traces:[]}),unroutedBreakoutTraces.length>0){let automaticFanoutBusIds=new Set(buses.filter(bus=>unroutedBreakoutTraces.some(trace=>bus._parsedProps.connections.some(connection=>connection===trace.name||traceHasEndpointMatchingConnectionSelector(trace,convertPortSelectorToEndpointKey(connection))))).map(bus=>bus.name));for(let trace of unroutedBreakoutTraces)trace.name&&automaticFanoutBusIds.add(trace.name);let automaticBusFanoutDirections=breakoutProps22.busFanoutDirections?Object.fromEntries(Object.entries(breakoutProps22.busFanoutDirections).filter(([busId])=>automaticFanoutBusIds.has(busId))):void 0;breakoutPlans.push({...breakoutPlan,routingPcbGroupId:void 0,busFanoutDirections:automaticBusFanoutDirections,traces:unroutedBreakoutTraces})}}if(routeRemaining&&hasDirectRoutingTargets&&phasePropsByPhaseIndex.size===1&&defaultPhaseProps?.reroute&&plans.length===1&&plans[0]?.routingPhaseIndex===null){let reroutePlan=plans[0];return[...breakoutPlans,{routingPhaseIndex:null,isImplicitRemainingPhase:!0,nets:[...reroutePlan.nets],traces:[...reroutePlan.traces]},reroutePlan]}return[...breakoutPlans,...plans]}var RoutingPhasePreparationError=class extends Error{},package_default3={name:"@tscircuit/core",type:"module",version:"0.0.2129",types:"dist/index.d.ts",main:"dist/index.js",module:"dist/index.js",exports:{".":{import:"./dist/index.js",types:"./dist/index.d.ts"}},files:["dist"],repository:{type:"git",url:"https://github.com/tscircuit/core"},scripts:{build:"tsup-node",format:"biome format . --write","measure-bundle":"howfat -r table .","pkg-pr-new-release":"bunx pkg-pr-new publish --comment=off --peerDeps","smoke-test:dist":"bun run scripts/smoke-tests/test-dist-simple-circuit.tsx && bun run scripts/smoke-tests/check-dist-bundled-schematic-solver.ts","build:benchmarking":"bun build --experimental-html ./benchmarking/website/index.html --outdir ./benchmarking-dist","build:benchmarking:watch":`chokidar "./{benchmarking,lib}/**/*.{ts,tsx}" -c 'bun build --experimental-html ./benchmarking/website/index.html --outdir ./benchmarking-dist'`,"start:benchmarking":'concurrently "bun run build:benchmarking:watch" "live-server ./benchmarking-dist"',"generate-test-plan":"bun run scripts/generate-test-plan.ts"},devDependencies:{"@biomejs/biome":"^1.8.3","@jscad/modeling":"^2.13.0","@resvg/resvg-js":"^2.6.2","@tsci/tscircuit.ti":"github:tscircuit/ti#57e314be4b2b06bc546d4def7453e619604d1157","@tscircuit/alphabet":"0.0.25","@tscircuit/bga-fanout-solver":"github:tscircuit/bga-fanout-solver#247c835cb8d69b65e53891dcf869731079415b39","@tscircuit/bus-lanes-solver":"https://jscdn.tscircuit.com/@tscircuit/bus-lanes-solver/0.0.21.tgz","@tscircuit/cableprinter":"^0.0.6","@tscircuit/capacity-autorouter":"^0.0.965","@tscircuit/checks":"^0.0.247","@tscircuit/circuit-json-util":"^0.0.121","@tscircuit/common":"^0.0.20","@tscircuit/copper-pour-solver":"^0.0.67","@tscircuit/create-fdm-enclosure":"0.0.4","@tscircuit/dogbone-solver":"https://jscdn.tscircuit.com/@tscircuit/dogbone-solver/0.0.1.tgz","@tscircuit/fanout-solver":"0.0.78","@tscircuit/flex-utils":"https://jscdn.tscircuit.com/@tscircuit/flex-utils/0.0.8.tgz","@tscircuit/footprinter":"^0.0.431","@tscircuit/image-utils":"^0.0.8","@tscircuit/implicit-copper-pour-solver":"github:tscircuit/implicit-copper-pour-solver#a5cbbda0cd65fd4707c5c1af25779837c25aba92","@tscircuit/infer-cable-insertion-point":"^0.0.4","@tscircuit/infgrid-ijump-astar":"^0.0.35","@tscircuit/jlcpcb-manufacturing-specs":"git+https://github.com/tscircuit/jlcpcb-manufacturing-specs#23260504fceffff2d64bf11720f74e974d1d9321","@tscircuit/krt-wasm":"^0.1.1","@tscircuit/log-soup":"^1.0.2","@tscircuit/matchpack":"^0.0.97","@tscircuit/math-utils":"^0.0.36","@tscircuit/miniflex":"^0.0.4","@tscircuit/modelprinter":"^0.0.18","@tscircuit/ngspice-spice-engine":"^0.0.20","@tscircuit/props":"^0.0.698","@tscircuit/schematic-match-adapt":"^0.0.18","@tscircuit/schematic-trace-solver":"https://jscdn.tscircuit.com/@tscircuit/schematic-trace-solver/0.0.230.tgz","@tscircuit/solver-utils":"^0.0.16","@tscircuit/soup-util":"^0.0.41","@tscircuit/via-stitch-solver":"github:tscircuit/via-stitch-solver#64f2ac7781b795bdc0d74ba411988e60767fa653","@tscircuit/winding-breakout-point-solver":"github:tscircuit/winding-breakout-point-solver#202dbe9eb0088633b6fa094120dba6f2f41f8803","@types/bun":"^1.2.16","@types/debug":"^4.1.12","@types/react":"^19.1.8","@types/react-dom":"^19.1.6","@types/react-reconciler":"^0.28.9","bpc-graph":"^0.0.57","bun-match-svg":"0.0.12","calculate-elbow":"^0.0.12","chokidar-cli":"^3.0.0","circuit-json":"^0.0.525","circuit-json-to-bpc":"^0.0.13","circuit-json-to-connectivity-map":"^0.0.33","circuit-json-to-gltf":"^0.0.151","circuit-json-to-spice":"^0.0.45","circuit-to-svg":"^0.0.445",concurrently:"^9.1.2","connectivity-map":"^1.0.1",debug:"^4.3.6",flatbush:"^4.5.0","graphics-debug":"^0.0.95",howfat:"^0.3.8","kicad-to-circuit-json":"^0.0.142",kicadts:"^0.0.53","live-server":"^1.2.2",minicssgrid:"^0.0.9","pkg-pr-new":"^0.0.37",poppygl:"0.0.34",react:"^19.1.0","react-dom":"^19.1.0","schematic-symbols":"^0.0.248",spicets:"^0.0.4",spicey:"^0.0.14","stack-svgs":"^0.0.1","ts-expect":"^1.3.0",tsup:"^8.2.4"},peerDependencies:{"@tscircuit/capacity-autorouter":"*","@tscircuit/checks":"*","@tscircuit/circuit-json-util":"*","@tscircuit/create-fdm-enclosure":"*","@tscircuit/footprinter":"*","@tscircuit/infgrid-ijump-astar":"*","@tscircuit/math-utils":"*","@tscircuit/modelprinter":"*","@tscircuit/props":"*","@tscircuit/schematic-match-adapt":"*","circuit-json-to-bpc":"*","bpc-graph":"*","@tscircuit/matchpack":"*","circuit-json":"*","circuit-json-to-connectivity-map":"*","circuit-json-to-spice":"*","schematic-symbols":"*",spicets:"*",typescript:"^5.0.0","@tscircuit/cableprinter":"*"},dependencies:{"@flatten-js/core":"^1.6.2","@lume/kiwi":"^0.4.3","calculate-cell-boundaries":"^0.0.25","calculate-packing":"^0.0.90","css-select":"5.1.0","format-si-unit":"^0.0.12","gl-matrix":"^3.4.4",nanoid:"^5.0.7","performance-now":"^2.1.0","react-reconciler":"^0.32.0","svg-path-commander":"^2.1.11","transformation-matrix":"^2.16.1",zod:"^3.25.67","jscad-planner":"^0.0.18","jscad-fiber":"^0.0.88"},overrides:{"@tscircuit/circuit-json-util":"^0.0.121","@tscircuit/props":"^0.0.698","circuit-json":"^0.0.525","@tscircuit/cableprinter":"^0.0.6"}},getFnv1aHash=value=>{let hash=2166136261;for(let i22=0;i22<value.length;i22++)hash^=value.charCodeAt(i22),hash=Math.imul(hash,16777619);return hash>>>0},getJsonHash=value=>{let serializedValue=JSON.stringify(value),hash1=getFnv1aHash(serializedValue),hash2=getFnv1aHash(`${serializedValue}${hash1}`);return`${hash1.toString(16).padStart(8,"0")}${hash2.toString(16).padStart(8,"0")}`},getLocalAutoroutingCacheKey=(simpleRouteJson,solverOptions)=>`routes:core@${package_default3.version}:solver:${getJsonHash(solverOptions)}:srj:${getJsonHash(simpleRouteJson)}`,getCachedLocalAutoroutingPhaseResult=async({cacheEngine,cacheKey})=>{if(!cacheEngine)return null;try{let cachedResult=await cacheEngine.getItem(cacheKey);if(!cachedResult)return null;let parsedResult=JSON.parse(cachedResult);return!parsedResult||!Array.isArray(parsedResult.traces)?null:parsedResult}catch{return null}},cacheLocalAutoroutingPhaseResult=async({cacheEngine,cacheKey,result})=>{if(cacheEngine)try{await cacheEngine.setItem(cacheKey,JSON.stringify(result))}catch{}},SRJ_POINT_POSITION_TOLERANCE_MM=1e-6,srjPointsHaveSamePointId=(first,second)=>first.pointId!==void 0&&second.pointId!==void 0&&first.pointId===second.pointId,srjPointsHaveSameBoardPositionAndLayer=(first,second)=>Math.abs(first.x-second.x)<=SRJ_POINT_POSITION_TOLERANCE_MM&&Math.abs(first.y-second.y)<=SRJ_POINT_POSITION_TOLERANCE_MM&&first.layer===second.layer,srjPointsReferToSameEndpoint=(first,second)=>first.pointId!==void 0&&second.pointId!==void 0?srjPointsHaveSamePointId(first,second):srjPointsHaveSameBoardPositionAndLayer(first,second),getPairedGlobalPoint=(simpleRouteJson,connection)=>{let globalConnection=simpleRouteJson.connections.find(candidate=>candidate.routingPcbGroupId!==connection.routingPcbGroupId&&candidate.source_trace_id===connection.source_trace_id&&candidate.pointsToConnect.some(globalPoint=>connection.pointsToConnect.some(localPoint=>srjPointsReferToSameEndpoint(globalPoint,localPoint))));if(!globalConnection)return;let pairedPoints=globalConnection.pointsToConnect.filter(globalPoint=>!connection.pointsToConnect.some(localPoint=>srjPointsReferToSameEndpoint(globalPoint,localPoint)));return pairedPoints.length===1?pairedPoints[0]:void 0},getPairedBreakoutExitTarget=(simpleRouteJson,connection)=>{if(!connection.routingPcbGroupId||!connection.source_trace_id)return;let pairedGlobalPoint=getPairedGlobalPoint(simpleRouteJson,connection);if(!(!pairedGlobalPoint||!simpleRouteJson.connections.some(candidate=>candidate.routingPcbGroupId!==void 0&&candidate.routingPcbGroupId!==connection.routingPcbGroupId&&candidate.source_trace_id===connection.source_trace_id&&candidate.pointsToConnect.some(candidatePoint=>srjPointsReferToSameEndpoint(candidatePoint,pairedGlobalPoint)))))return{x:pairedGlobalPoint.x,y:pairedGlobalPoint.y,layer:pairedGlobalPoint.layer}};function connectionIsInRoutingPhase(connection,phasePlan){if(connection.routingPcbGroupId)return connection.routingPcbGroupId===phasePlan.routingPcbGroupId;for(let trace of phasePlan.traces)if(trace.source_trace_id&&(connection.source_trace_id===trace.source_trace_id||connection.name===trace.source_trace_id||connection.rootConnectionName===trace.source_trace_id||connection.mergedConnectionNames?.includes(trace.source_trace_id)))return!0;for(let net of phasePlan.nets)if(net.source_net_id&&connection.name===net.source_net_id)return!0;return!1}function Group_hasPhasedAutorouting(routingPhasePlans){for(let plan of routingPhasePlans)if(plan.routingPcbGroupId||plan.routingPhaseIndex!==null)return!0;return!1}function Group_filterSimpleRouteJsonForPhase(simpleRouteJson,phasePlan){let connections=[];for(let connection of simpleRouteJson.connections)connectionIsInRoutingPhase(connection,phasePlan)&&connections.push(connection);let includedConnectionNames=new Set;for(let connection of connections)includedConnectionNames.add(connection.name);let differentialPairs=[];for(let differentialPair of simpleRouteJson.differentialPairs??[]){let positiveConnectionIncluded=includedConnectionNames.has(differentialPair.connectionNames[0]),negativeConnectionIncluded=includedConnectionNames.has(differentialPair.connectionNames[1]);if(positiveConnectionIncluded!==negativeConnectionIncluded)throw new Error(`Differential pair "${differentialPair.connectionNames.join("/")}" cannot be split across autorouting phases`);positiveConnectionIncluded&&differentialPairs.push(differentialPair)}let srjConnectionByName=new Map(simpleRouteJson.connections.map(connection=>[connection.name,connection])),buses=(simpleRouteJson.buses??[]).map(bus=>{let connectionNames=bus.connectionNames.filter(connectionName=>includedConnectionNames.has(connectionName)),cohortConnectionNames=bus.connectionNames.filter(connectionName=>srjConnectionByName.get(connectionName)?.routingPcbGroupId===phasePlan.routingPcbGroupId);if(bus.maxLengthSkew!==void 0&&connectionNames.length>0&&connectionNames.length!==cohortConnectionNames.length)throw new RoutingPhasePreparationError(`Length-matched bus "${bus.name||"unnamed bus"}" cannot be split across autorouting phases. Assign the complete bus to one routingPhaseIndex.`);let connectionExitTargets=Object.fromEntries(connectionNames.flatMap(connectionName=>{let connection=srjConnectionByName.get(connectionName);if(!connection)return[];let pairedTarget=getPairedBreakoutExitTarget(simpleRouteJson,connection);return pairedTarget?[[connectionName,pairedTarget]]:[]}));return{...bus,connectionNames,...Object.keys(connectionExitTargets).length>0?{connectionExitTargets}:{}}}).filter(bus=>bus.connectionNames.length>0),bounds=expandSrjBoundsToIncludeConnectionPoints({bounds:phasePlan.routingBounds??simpleRouteJson.bounds,connections});return{...simpleRouteJson,bounds,outline:getSrjOutlineForRoutingBounds(simpleRouteJson,bounds),connections,differentialPairs:differentialPairs.length>0?differentialPairs:void 0,buses:buses.length>0?buses:void 0}}function hasDrcTolerances(drcTolerances){return drcTolerances?Object.values(drcTolerances).some(value=>value!==void 0):!1}function applyMinTraceWidthToConnections(connections,minTraceWidth){return minTraceWidth===void 0?connections:connections.map(connection=>({...connection,nominalTraceWidth:Math.max(connection.nominalTraceWidth??minTraceWidth,minTraceWidth),width:Math.max(connection.width??minTraceWidth,minTraceWidth)}))}function Group_applyDrcTolerancesToSimpleRouteJson(simpleRouteJson,drcTolerances){if(!hasDrcTolerances(drcTolerances))return simpleRouteJson;let minTraceWidth=drcTolerances.minTraceWidth??simpleRouteJson.minTraceWidth,minViaHoleDiameter=drcTolerances.minViaHoleDiameter??simpleRouteJson.minViaHoleDiameter,minViaPadDiameter=drcTolerances.minViaPadDiameter??simpleRouteJson.minViaPadDiameter,minTraceToHoleEdgeClearance=drcTolerances.minTraceToHoleEdgeClearance??simpleRouteJson.minTraceToHoleEdgeClearance,minTraceToPadEdgeClearance=drcTolerances.minTraceToPadEdgeClearance??simpleRouteJson.minTraceToPadEdgeClearance,minViaEdgeToPadEdgeClearance=drcTolerances.minViaEdgeToPadEdgeClearance??simpleRouteJson.minViaEdgeToPadEdgeClearance,minViaHoleEdgeToViaHoleEdgeClearance=drcTolerances.minViaHoleEdgeToViaHoleEdgeClearance??simpleRouteJson.minViaHoleEdgeToViaHoleEdgeClearance,minPlatedHoleDrillEdgeToDrillEdgeClearance=drcTolerances.minPlatedHoleDrillEdgeToDrillEdgeClearance??simpleRouteJson.minPlatedHoleDrillEdgeToDrillEdgeClearance,minPadEdgeToPadEdgeClearance=drcTolerances.minPadEdgeToPadEdgeClearance??simpleRouteJson.minPadEdgeToPadEdgeClearance,minBoardEdgeClearance=drcTolerances.minBoardEdgeClearance??simpleRouteJson.minBoardEdgeClearance;return{...simpleRouteJson,connections:applyMinTraceWidthToConnections(simpleRouteJson.connections,drcTolerances.minTraceWidth),minTraceWidth,minViaDiameter:minViaPadDiameter,minViaHoleDiameter,minViaPadDiameter,min_via_hole_diameter:minViaHoleDiameter,min_via_pad_diameter:minViaPadDiameter,minTraceToPadEdgeClearance,minTraceToHoleEdgeClearance,minViaEdgeToPadEdgeClearance,minViaHoleEdgeToViaHoleEdgeClearance,minPlatedHoleDrillEdgeToDrillEdgeClearance,minPadEdgeToPadEdgeClearance,minBoardEdgeClearance}}var removeCompletedFanoutConnections=(simpleRouteJson,routingPcbGroupId)=>{let connections=simpleRouteJson.connections.filter(connection=>connection.routingPcbGroupId!==routingPcbGroupId),includedConnectionNames=new Set(connections.map(connection=>connection.name)),differentialPairs=[];for(let differentialPair of simpleRouteJson.differentialPairs??[]){let positiveConnectionIncluded=includedConnectionNames.has(differentialPair.connectionNames[0]),negativeConnectionIncluded=includedConnectionNames.has(differentialPair.connectionNames[1]);if(positiveConnectionIncluded!==negativeConnectionIncluded)throw new Error(`Differential pair "${differentialPair.connectionNames.join("/")}" cannot be split at a breakout boundary`);positiveConnectionIncluded&&differentialPairs.push(differentialPair)}let buses=(simpleRouteJson.buses??[]).map(bus=>({...bus,connectionNames:bus.connectionNames.filter(connectionName=>includedConnectionNames.has(connectionName))})).filter(bus=>bus.connectionNames.length>0);return{...simpleRouteJson,connections,differentialPairs:differentialPairs.length>0?differentialPairs:void 0,buses:buses.length>0?buses:void 0}},connectFanoutTracesToBreakoutPoints=(simpleRouteJson,breakoutPointIdByConnectionName)=>({...simpleRouteJson,traces:simpleRouteJson.traces?.map(trace=>{let breakoutPointId=breakoutPointIdByConnectionName.get(trace.connection_name??"");return breakoutPointId?{...trace,connectsTo:[...new Set([...trace.connectsTo??[],breakoutPointId])]}:trace})});function Group_syncFanoutExitsWithGlobalConnections({fanoutInputSimpleRouteJson,fanoutOutputSimpleRouteJson,baseSimpleRouteJson,routingPhasePlan}){let routingPcbGroupId=routingPhasePlan.routingPcbGroupId;if(!routingPcbGroupId)return{downstreamSimpleRouteJson:fanoutOutputSimpleRouteJson,baseSimpleRouteJson,synchronizedBreakoutPoints:[]};let outputConnectionByName=new Map(fanoutOutputSimpleRouteJson.connections.map(connection=>[connection.name,connection])),baseConnections=baseSimpleRouteJson.connections.map(connection=>({...connection,pointsToConnect:connection.pointsToConnect.map(point62=>({...point62}))})),synchronizedBreakoutPoints=[],breakoutPointIdByConnectionName=new Map;for(let inputConnection of fanoutInputSimpleRouteJson.connections){if(inputConnection.routingPcbGroupId!==routingPcbGroupId||!inputConnection.source_trace_id)continue;let outputConnection=outputConnectionByName.get(inputConnection.name);if(!outputConnection)continue;let globalPointMatches=baseConnections.filter(connection=>{if(connection.routingPcbGroupId===routingPcbGroupId)return!1;let sharesSourceTrace=connection.source_trace_id===inputConnection.source_trace_id,sharesPointId=connection.pointsToConnect.some(globalPoint=>inputConnection.pointsToConnect.some(inputPoint=>srjPointsHaveSamePointId(globalPoint,inputPoint)));return!sharesSourceTrace&&!sharesPointId?!1:connection.pointsToConnect.some(globalPoint=>inputConnection.pointsToConnect.some(inputPoint=>srjPointsReferToSameEndpoint(globalPoint,inputPoint)))}).flatMap(globalConnection=>globalConnection.pointsToConnect.flatMap((previousPoint,pointIndex)=>inputConnection.pointsToConnect.some(inputPoint=>srjPointsReferToSameEndpoint(previousPoint,inputPoint))?[{globalConnection,pointIndex,previousPoint}]:[])),changedPointIndex=outputConnection.pointsToConnect.findIndex((outputPoint,pointIndex)=>{let inputPoint=inputConnection.pointsToConnect[pointIndex];return inputPoint!==void 0&&!srjPointsHaveSameBoardPositionAndLayer(outputPoint,inputPoint)});if(changedPointIndex<0)continue;let fanoutExitPoint=outputConnection.pointsToConnect[changedPointIndex];globalPointMatches.length===0&&synchronizedBreakoutPoints.push({sourceTraceId:inputConnection.source_trace_id,routingPcbGroupId,previousPoint:inputConnection.pointsToConnect[changedPointIndex],fanoutExitPoint});for(let{globalConnection,pointIndex,previousPoint}of globalPointMatches){let{terminalVia:_previousTerminalVia,...previousPointWithoutLayerOverrides}=previousPoint,synchronizedGlobalPoint={...previousPointWithoutLayerOverrides,x:fanoutExitPoint.x,y:fanoutExitPoint.y,layer:fanoutExitPoint.layer,...fanoutExitPoint.terminalVia?{terminalVia:{...fanoutExitPoint.terminalVia}}:{}};globalConnection.pointsToConnect[pointIndex]=synchronizedGlobalPoint,previousPoint.pointId&&breakoutPointIdByConnectionName.set(inputConnection.name,previousPoint.pointId),synchronizedBreakoutPoints.push({sourceTraceId:inputConnection.source_trace_id,routingPcbGroupId,previousPoint,fanoutExitPoint})}}let newFanoutSourceKeepouts=fanoutOutputSimpleRouteJson.obstacles.filter(obstacle=>obstacle.isFanoutSourceKeepout===!0&&obstacle.componentId!==void 0),completedSourceComponentIds=new Set(newFanoutSourceKeepouts.flatMap(obstacle=>obstacle.componentId===void 0?[]:[obstacle.componentId])),retainedBaseObstacles=baseSimpleRouteJson.obstacles.filter(obstacle=>!obstacle.componentId||!completedSourceComponentIds.has(obstacle.componentId));return{downstreamSimpleRouteJson:removeCompletedFanoutConnections(connectFanoutTracesToBreakoutPoints(fanoutOutputSimpleRouteJson,breakoutPointIdByConnectionName),routingPcbGroupId),baseSimpleRouteJson:{...baseSimpleRouteJson,connections:baseConnections,obstacles:[...retainedBaseObstacles,...newFanoutSourceKeepouts]},synchronizedBreakoutPoints}}function getJumperPadInfos(db22){let padInfos=[],jumperSourceComponentIds=new Set(db22.source_component.list().filter(component=>component.name?.startsWith("__autoplaced_jumper")).map(component=>component.source_component_id));if(jumperSourceComponentIds.size===0)return padInfos;let jumperPcbComponentIds=new Set(db22.pcb_component.list().filter(component=>jumperSourceComponentIds.has(component.source_component_id)).map(component=>component.pcb_component_id)),jumperSmtpads=db22.pcb_smtpad.list().filter(pad2=>jumperPcbComponentIds.has(pad2.pcb_component_id));for(let smtpad2 of jumperSmtpads)if(smtpad2.shape!=="polygon"&&smtpad2.pcb_port_id){if(smtpad2.shape==="rect"||smtpad2.shape==="rotated_rect"){let halfWidth=smtpad2.width/2,halfHeight=smtpad2.height/2;padInfos.push({pcb_port_id:smtpad2.pcb_port_id,x:smtpad2.x,y:smtpad2.y,minX:smtpad2.x-halfWidth,maxX:smtpad2.x+halfWidth,minY:smtpad2.y-halfHeight,maxY:smtpad2.y+halfHeight})}else if(smtpad2.shape==="circle"){let radius=smtpad2.radius;padInfos.push({pcb_port_id:smtpad2.pcb_port_id,x:smtpad2.x,y:smtpad2.y,minX:smtpad2.x-radius,maxX:smtpad2.x+radius,minY:smtpad2.y-radius,maxY:smtpad2.y+radius})}}return padInfos}function findJumperPortAtPosition(padInfos,x22,y22,tolerance=.01){for(let pad2 of padInfos)if(Math.abs(pad2.x-x22)<tolerance&&Math.abs(pad2.y-y22)<tolerance)return pad2.pcb_port_id}function findJumperPortContainingPoint(padInfos,x22,y22){for(let pad2 of padInfos)if(x22>=pad2.minX&&x22<=pad2.maxX&&y22>=pad2.minY&&y22<=pad2.maxY)return pad2}function splitRouteAtJumperPads(route2,padInfos){if(route2.length===0||padInfos.length===0)return[route2];let segments=[],currentSegment=[];for(let i22=0;i22<route2.length;i22++){let point62=route2[i22];if(currentSegment.push(point62),point62.route_type==="wire"&&i22>0&&i22<route2.length-1){let padInfo=findJumperPortContainingPoint(padInfos,point62.x,point62.y);if(padInfo){point62.end_pcb_port_id||(point62.end_pcb_port_id=padInfo.pcb_port_id),segments.push(currentSegment);let newStartPoint={...point62};delete newStartPoint.end_pcb_port_id,newStartPoint.start_pcb_port_id||(newStartPoint.start_pcb_port_id=padInfo.pcb_port_id),currentSegment=[newStartPoint]}}}return currentSegment.length>0&&segments.push(currentSegment),segments}function addPortIdsToTracesAtJumperPads(segments,padInfos){if(padInfos.length===0)return segments;let result=[];for(let segment2 of segments){let subSegments=splitRouteAtJumperPads(segment2,padInfos);for(let subSegment of subSegments)if(subSegment.length>0){let firstPoint=subSegment[0],lastPoint=subSegment[subSegment.length-1];if(firstPoint.route_type==="wire"&&!firstPoint.start_pcb_port_id){let portId=findJumperPortAtPosition(padInfos,firstPoint.x,firstPoint.y);portId&&(firstPoint.start_pcb_port_id=portId)}if(lastPoint.route_type==="wire"&&!lastPoint.end_pcb_port_id){let portId=findJumperPortAtPosition(padInfos,lastPoint.x,lastPoint.y);portId&&(lastPoint.end_pcb_port_id=portId)}result.push(subSegment)}}return result}var claimSrjAssignablePcbViasTraversedByRoute=({db:db22,pcbTrace,routeWithSrjMetadata})=>{for(let routePoint3 of routeWithSrjMetadata){if(routePoint3.route_type!=="through_pad")continue;let pcbViaId=routePoint3.circuitJsonMetadata?.pcb_via_id;if(!pcbViaId)continue;let assignablePcbVia=db22.pcb_via.get(pcbViaId);!assignablePcbVia?.net_is_assignable||assignablePcbVia.net_assigned&&assignablePcbVia.pcb_trace_id!==pcbTrace.pcb_trace_id||db22.pcb_via.update(assignablePcbVia.pcb_via_id,{pcb_trace_id:pcbTrace.pcb_trace_id,net_assigned:!0})}},getAxisGap=(firstMinimum,firstMaximum,secondMinimum,secondMaximum)=>Math.max(secondMinimum-firstMaximum,firstMinimum-secondMaximum),findFanoutPhaseSeparationConflict=regions=>{for(let firstIndex=0;firstIndex<regions.length;firstIndex++){let firstRegion=regions[firstIndex];for(let secondIndex=firstIndex+1;secondIndex<regions.length;secondIndex++){let secondRegion=regions[secondIndex];if(firstRegion.regionId&&firstRegion.regionId===secondRegion.regionId)continue;let horizontalGap=getAxisGap(firstRegion.bounds.minX,firstRegion.bounds.maxX,secondRegion.bounds.minX,secondRegion.bounds.maxX),verticalGap=getAxisGap(firstRegion.bounds.minY,firstRegion.bounds.maxY,secondRegion.bounds.minY,secondRegion.bounds.maxY),availableGap=Math.max(horizontalGap,verticalGap),requiredGap=firstRegion.boundaryKeepaway+secondRegion.boundaryKeepaway;if(availableGap+1e-6<requiredGap)return{firstRegion,secondRegion,availableGap,requiredGap}}}};function getAccumulatedPcbTracesWithStageOutputReplacements({accumulatedPcbTraces,stageOutputPcbTraces}){let replacedPcbTraceIds=new Set(stageOutputPcbTraces.flatMap(trace=>[trace.pcb_trace_id,...trace.__replaces_pcb_trace_id?[trace.__replaces_pcb_trace_id]:[]]));return[...accumulatedPcbTraces.filter(trace=>!replacedPcbTraceIds.has(trace.pcb_trace_id)),...stageOutputPcbTraces]}var POINT_EPSILON3=1e-6;function isPointOnWireSegment({point:point62,segmentStart,segmentEnd}){return point62.layer&&(segmentStart.layer!==point62.layer||segmentEnd.layer!==point62.layer)?!1:pointToSegmentDistance(point62,segmentStart,segmentEnd)<=POINT_EPSILON3}function isPointInSmtPad({point:point62,pad:pad2,traceWidth=0}){return pad2.shape==="rect"||pad2.shape==="rotated_rect"?Math.abs(point62.x-pad2.x)<=pad2.width/2+traceWidth/2&&Math.abs(point62.y-pad2.y)<=pad2.height/2+traceWidth/2:pad2.shape==="circle"?distance3(point62,pad2)<=pad2.radius+traceWidth/2:!1}function isPointInPlatedHole({point:point62,hole,traceWidth=0}){return distance3(point62,hole)<=(hole.outer_diameter??hole.hole_diameter??0)/2+traceWidth/2}function getEndpointSourcePortIdsFromGeometry(db22,trace){let sourcePortIds=new Set,route2=trace.route,endpoints=[route2[0],route2[route2.length-1]].filter(point62=>!!point62&&point62.route_type==="wire"&&point62.x!==void 0&&point62.y!==void 0);for(let endpoint of endpoints){for(let pcbPort of db22.pcb_port.list())pcbPort.source_port_id&&(endpoint.layer&&pcbPort.layers&&!pcbPort.layers.includes(endpoint.layer)||distance3(endpoint,pcbPort)<=.01&&sourcePortIds.add(pcbPort.source_port_id));for(let smtpad2 of db22.pcb_smtpad.list()){if(!smtpad2.pcb_port_id||endpoint.layer&&smtpad2.layer!==endpoint.layer||!isPointInSmtPad({point:endpoint,pad:smtpad2,traceWidth:endpoint.width}))continue;let sourcePortId=db22.pcb_port.get(smtpad2.pcb_port_id)?.source_port_id;sourcePortId&&sourcePortIds.add(sourcePortId)}for(let hole of db22.pcb_plated_hole.list()){if(!hole.pcb_port_id||!isPointInPlatedHole({point:endpoint,hole,traceWidth:endpoint.width}))continue;let sourcePortId=db22.pcb_port.get(hole.pcb_port_id)?.source_port_id;sourcePortId&&sourcePortIds.add(sourcePortId)}}return[...sourcePortIds]}function getWireRouteEndpoints(trace){let route2=trace.route.filter(point62=>point62.route_type==="wire"&&point62.x!==void 0&&point62.y!==void 0);return[route2[0],route2[route2.length-1]].filter(point62=>!!point62)}function getSourceIdsFromConnectedPcbTraces(db22,trace){let sourceIds=new Set,endpoints=getWireRouteEndpoints(trace);if(endpoints.length===0)return[];for(let existingTrace of db22.pcb_trace.list()){if(!existingTrace.source_trace_id||existingTrace.pcb_trace_id===trace.pcb_trace_id||!db22.source_trace.get(existingTrace.source_trace_id)&&!db22.source_net.get(existingTrace.source_trace_id))continue;let existingRoute=existingTrace.route.filter(point62=>point62.route_type==="wire");for(let i22=0;i22<existingRoute.length-1;i22++){let segmentStart=existingRoute[i22],segmentEnd=existingRoute[i22+1];if(!(!segmentStart||!segmentEnd))for(let endpoint of endpoints)isPointOnWireSegment({point:endpoint,segmentStart,segmentEnd})&&sourceIds.add(existingTrace.source_trace_id)}}return[...sourceIds]}function getSourcePortIdsFromRoutedTrace(db22,trace){let sourcePortIds=new Set;for(let point62 of trace.route)for(let pcbPortId of[point62.start_pcb_port_id,point62.end_pcb_port_id]){if(!pcbPortId)continue;let sourcePortId=db22.pcb_port.get(pcbPortId)?.source_port_id;sourcePortId&&sourcePortIds.add(sourcePortId)}return sourcePortIds.size>0?[...sourcePortIds]:getEndpointSourcePortIdsFromGeometry(db22,trace)}function buildSourceConnectivityMap(sourceTraces){let connMap=new ConnectivityMap({});return connMap.addConnections(sourceTraces.map(trace=>[trace.source_trace_id,...trace.connected_source_port_ids,...trace.connected_source_net_ids])),connMap}function getSourceTraceIdForRoutedTrace({db:db22,trace,subcircuit_id}){if(trace.source_trace_id&&(db22.source_trace.get(trace.source_trace_id)??db22.source_net.get(trace.source_trace_id)))return trace.source_trace_id;let sourcePortIds=getSourcePortIdsFromRoutedTrace(db22,trace);if(sourcePortIds.length===0)return getSourceIdsFromConnectedPcbTraces(db22,trace)[0];let sourceTraces=db22.source_trace.list(),connMap=buildSourceConnectivityMap(sourceTraces),endpointNetIds=sourcePortIds.map(sourcePortId=>connMap.getNetConnectedToId(sourcePortId)).filter(netId=>!!netId),exactSourceTrace=sourcePortIds.length>=2?sourceTraces.find(sourceTrace=>sourcePortIds.every(sourcePortId=>sourceTrace.connected_source_port_ids.includes(sourcePortId))):void 0;if(exactSourceTrace)return exactSourceTrace.source_trace_id;let sourceTracesInEndpointNets=sourceTraces.filter(sourceTrace=>{let sourceTraceNetId=connMap.getNetConnectedToId(sourceTrace.source_trace_id);return endpointNetIds.some(netId=>netId===sourceTraceNetId)}),connectedToEndpoint=sourceTracesInEndpointNets.filter(sourceTrace=>sourceTrace.connected_source_port_ids.some(sourcePortId=>sourcePortIds.includes(sourcePortId))),candidates=connectedToEndpoint.length>0?connectedToEndpoint:sourceTracesInEndpointNets;if(candidates.length!==0)return(candidates.find(sourceTrace=>sourceTrace.subcircuit_id===subcircuit_id)??candidates[0])?.source_trace_id}function groupPadsByInternalConnection(pads,orientation22){let groups=[];for(let pad2 of pads){let key=orientation22==="vertical"?pad2.center.y:pad2.center.x,foundGroup=!1;for(let group2 of groups){let groupKey=orientation22==="vertical"?group2[0].center.y:group2[0].center.x;if(Math.abs(key-groupKey)<.01){group2.push(pad2),foundGroup=!0;break}}foundGroup||groups.push([pad2])}return groups.filter(g22=>g22.length>=2)}function insertAutoplacedJumpers(params){let{db:db22,output_jumpers,subcircuit_id}=params;for(let jumperIndex=0;jumperIndex<output_jumpers.length;jumperIndex++){let jumper=output_jumpers[jumperIndex],sourceComponent=db22.source_component.insert({ftype:"simple_chip",name:`__autoplaced_jumper_${jumperIndex}`,supplier_part_numbers:{}}),rotation5=jumper.orientation==="horizontal"?0:90,firstPadLayer=jumper.pads[0]?.layer||jumper.pads[0]?.layers?.[0]||"top",pcbComponent=db22.pcb_component.insert({source_component_id:sourceComponent.source_component_id,center:jumper.center,rotation:rotation5,layer:firstPadLayer,width:jumper.width||0,height:jumper.height||0,obstructs_within_bounds:!1}),padData=[];for(let padIndex=0;padIndex<jumper.pads.length;padIndex++){let pad2=jumper.pads[padIndex],pinNumber=padIndex+1,sourcePort=db22.source_port.insert({source_component_id:sourceComponent.source_component_id,name:`pin${pinNumber}`,pin_number:pinNumber}),padLayer=pad2.layer||pad2.layers?.[0]||"top",pcbPort=db22.pcb_port.insert({pcb_component_id:pcbComponent.pcb_component_id,source_port_id:sourcePort.source_port_id,x:pad2.center.x,y:pad2.center.y,layers:[padLayer]}),pcbSmtpad=db22.pcb_smtpad.insert({pcb_component_id:pcbComponent.pcb_component_id,pcb_port_id:pcbPort.pcb_port_id,shape:"rect",x:pad2.center.x,y:pad2.center.y,width:pad2.width,height:pad2.height,layer:padLayer});padData.push({pad:pad2,sourcePortId:sourcePort.source_port_id,pcbSmtpadId:pcbSmtpad.pcb_smtpad_id})}let internalGroups=groupPadsByInternalConnection(jumper.pads,jumper.orientation);for(let group2 of internalGroups){let sourcePortIds=[];for(let groupPad of group2){let padInfo=padData.find(p22=>Math.abs(p22.pad.center.x-groupPad.center.x)<.01&&Math.abs(p22.pad.center.y-groupPad.center.y)<.01);padInfo&&sourcePortIds.push(padInfo.sourcePortId)}sourcePortIds.length>=2&&db22.source_component_internal_connection.insert({source_component_id:sourceComponent.source_component_id,subcircuit_id:subcircuit_id??void 0,source_port_ids:sourcePortIds})}}}function convertPcbTraceToSimplifiedPcbTrace(trace){return{...trace,type:"pcb_trace",pcb_trace_id:trace.pcb_trace_id,connection_name:trace.connection_name??trace.source_trace_id??trace.pcb_trace_id,route:trace.route.map(point62=>({...point62}))}}function getRelevantSubcircuitIdsForReroute(group2){let relevantSubcircuitIds=new Set;if(!group2.subcircuit_id)return relevantSubcircuitIds;relevantSubcircuitIds.add(group2.subcircuit_id);let db22=group2.root?.db;if(!db22)return relevantSubcircuitIds;for(let subcircuitId of getDescendantSubcircuitIds2(db22,group2.subcircuit_id))relevantSubcircuitIds.add(subcircuitId);return relevantSubcircuitIds}function getExistingPcbTracesForReroute(group2){let db22=group2.root?.db;if(!db22)return[];let relevantSubcircuitIds=getRelevantSubcircuitIdsForReroute(group2);return db22.pcb_trace.list().filter(trace=>!trace.route||trace.route.length<2?!1:group2.subcircuit_id?!!(trace.subcircuit_id&&relevantSubcircuitIds.has(trace.subcircuit_id)):!0)}function getSourceTraceIdsFromRerouteName(value){return typeof value!="string"||value.length===0?[]:value.split("__").flatMap(connectionNamePart=>{if(connectionNamePart.length===0)return[];let sourceTraceIds=[connectionNamePart],rerouteSuffixIndex=connectionNamePart.indexOf("_reroute_");return rerouteSuffixIndex>0&&sourceTraceIds.push(connectionNamePart.slice(0,rerouteSuffixIndex)),sourceTraceIds})}function addPossibleReplacementSourceTraceId(sourceTraceIds,value){if(!(typeof value!="string"||value.length===0)){sourceTraceIds.add(value);for(let sourceTraceId of getSourceTraceIdsFromRerouteName(value))sourceTraceIds.add(sourceTraceId)}}function deleteExistingPcbTracesReplacedBy({group:group2,outputPcbTraces,pcbTraceIdsToReplace=[]}){let db22=group2.root?.db;if(!db22)return;let replacementPcbTraceIds=new Set(pcbTraceIdsToReplace),replacementSourceTraceIds=new Set;for(let trace of outputPcbTraces){if(trace.type!=="pcb_trace")continue;let replacementTrace=trace;replacementPcbTraceIds.add(replacementTrace.pcb_trace_id),addPossibleReplacementSourceTraceId(replacementSourceTraceIds,replacementTrace.source_trace_id),addPossibleReplacementSourceTraceId(replacementSourceTraceIds,replacementTrace.connection_name),addPossibleReplacementSourceTraceId(replacementSourceTraceIds,replacementTrace.rootConnectionName)}if(replacementPcbTraceIds.size===0&&replacementSourceTraceIds.size===0)return;let tracesToDelete=getExistingPcbTracesForReroute(group2).filter(trace=>replacementPcbTraceIds.has(trace.pcb_trace_id)||!!(trace.source_trace_id&&trace.subcircuit_id===group2.subcircuit_id&&replacementSourceTraceIds.has(trace.source_trace_id)));if(tracesToDelete.length===0)return;let deletedPcbTraceIds=new Set(tracesToDelete.map(trace=>trace.pcb_trace_id));for(let via of db22.pcb_via.list())via.pcb_trace_id&&deletedPcbTraceIds.has(via.pcb_trace_id)&&db22.pcb_via.delete(via.pcb_via_id);for(let trace of tracesToDelete)db22.pcb_trace.delete(trace.pcb_trace_id)}function getExistingSimplifiedPcbTracesForReroute(group2){return getExistingPcbTracesForReroute(group2).map(convertPcbTraceToSimplifiedPcbTrace)}function splitPcbTracesOnJumperSegments(route2){let jumperRoutes=route2.filter(p22=>p22.route_type==="jumper"),wireAndViaRoutes=route2.filter(p22=>p22.route_type!=="jumper");if(jumperRoutes.length===0)return null;let splitRanges=[];for(let jumperRoute of jumperRoutes){let jumperStart=jumperRoute.start,jumperEnd=jumperRoute.end,startIdx=-1,endIdx=-1,minStartDist=1/0,minEndDist=1/0;for(let i22=0;i22<wireAndViaRoutes.length;i22++){let p22=wireAndViaRoutes[i22];if(p22.route_type!=="wire")continue;let distToStart=Math.hypot(p22.x-jumperStart.x,p22.y-jumperStart.y),distToEnd=Math.hypot(p22.x-jumperEnd.x,p22.y-jumperEnd.y);distToStart<minStartDist&&(minStartDist=distToStart,startIdx=i22),distToEnd<minEndDist&&(minEndDist=distToEnd,endIdx=i22)}startIdx>endIdx&&([startIdx,endIdx]=[endIdx,startIdx]),startIdx>=0&&endIdx>=0&&startIdx!==endIdx&&splitRanges.push({startIdx,endIdx})}splitRanges.sort((a22,b22)=>a22.startIdx-b22.startIdx);let segments=[],currentStart=0;for(let range2 of splitRanges)currentStart<range2.startIdx&&segments.push(wireAndViaRoutes.slice(currentStart,range2.startIdx+1)),currentStart=range2.endIdx;return currentStart<wireAndViaRoutes.length&&segments.push(wireAndViaRoutes.slice(currentStart)),segments}function computeCenterFromAnchorPosition(anchorPosition,ctx){let{width,height,pcbAnchorAlignment}=ctx;if(!pcbAnchorAlignment)return anchorPosition;let alignment=pcbAnchorAlignment;if(typeof width!="number"||typeof height!="number")return anchorPosition;let ax22=anchorPosition.x,ay22=anchorPosition.y;switch(alignment){case"top_left":return{x:ax22+width/2,y:ay22-height/2};case"top_center":return{x:ax22,y:ay22-height/2};case"top_right":return{x:ax22-width/2,y:ay22-height/2};case"center_left":return{x:ax22+width/2,y:ay22};case"center_right":return{x:ax22-width/2,y:ay22};case"bottom_left":return{x:ax22+width/2,y:ay22+height/2};case"bottom_center":return{x:ax22,y:ay22+height/2};case"bottom_right":return{x:ax22-width/2,y:ay22+height/2};default:return anchorPosition}}var getDistanceToPoint=(routePoint3,targetPoint)=>{let position4=getRoutePointPosition(routePoint3);return Math.hypot(position4.x-targetPoint.x,position4.y-targetPoint.y)},platformAllowsLegacyAutorouters=group2=>{let platform=group2.root?.platform;return platform!==void 0&&"allowLegacyAutorouters"in platform&&platform.allowLegacyAutorouters===!0},getDisabledLegacyGroupAutorouterPreset=group2=>{if(platformAllowsLegacyAutorouters(group2))return null;let resolvedGroupAutorouter=group2._parsedProps.autorouter??group2.getInheritedProperty("autorouter");return getLegacyAutorouterPreset(resolvedGroupAutorouter)},getDisabledLegacyAutorouterPreset=group2=>{if(platformAllowsLegacyAutorouters(group2))return null;let legacyGroupAutorouterPreset=getDisabledLegacyGroupAutorouterPreset(group2);if(legacyGroupAutorouterPreset)return legacyGroupAutorouterPreset;let routingPhaseAutorouters=group2.selectAll("autoroutingphase").map(autoroutingPhase=>autoroutingPhase._parsedProps.autorouter);for(let autorouter of routingPhaseAutorouters){let legacyAutorouterPreset=getLegacyAutorouterPreset(autorouter);if(legacyAutorouterPreset)return legacyAutorouterPreset}return null},ensureRouteStartsAtSourceTraceStart=({db:db22,route:route2,routeThicknessMode,sourceTraceId})=>{if(!sourceTraceId||route2.length<2)return route2;let firstSourcePortId=db22.source_trace.get(sourceTraceId)?.connected_source_port_ids[0];if(!firstSourcePortId)return route2;let firstPcbPort=db22.pcb_port.list().find(port=>port.source_port_id===firstSourcePortId);if(!firstPcbPort)return route2;let firstPoint=route2[0],lastPoint=route2[route2.length-1];return getDistanceToPoint(lastPoint,firstPcbPort)<getDistanceToPoint(firstPoint,firstPcbPort)?reversePcbTraceRoute(route2,routeThicknessMode):route2},Group5=class extends NormalComponent{constructor(){super(...arguments);__publicField(this,"pcb_group_id",null);__publicField(this,"schematic_group_id",null);__publicField(this,"subcircuit_id",null);__publicField(this,"_hasStartedAsyncAutorouting",!1);__publicField(this,"_pcbPlacementDrcErrorCount",null);__publicField(this,"_pcbPlacementDrcCheckError",null);__publicField(this,"_pcbPlacementDrcChecksPending",!1);__publicField(this,"_standaloneSubcircuitDrcChecksComplete",!1);__publicField(this,"_standaloneSubcircuitDrcChecksInProgress",!1);__publicField(this,"_isInflatedFromCircuitJson",!1);__publicField(this,"_isolatedCircuitJson",null);__publicField(this,"_normalComponentNameMap",null);__publicField(this,"_asyncAutoroutingResult",null);__publicField(this,"unnamedElementCounter",{})}get _isIsolatedSubcircuit(){return!!this.getInheritedProperty("_subcircuitCachingEnabled")}getNormalComponentNameMap(){if(this._normalComponentNameMap)return this._normalComponentNameMap;let nameMap=new Map,collectNamedComponents=component=>{if(component._isNormalComponent&&component.name){let componentsWithSameName=nameMap.get(component.name);componentsWithSameName?componentsWithSameName.push(component):nameMap.set(component.name,[component])}for(let child of component.children)child.isSubcircuit||collectNamedComponents(child)};for(let child of this.children)child.isSubcircuit||collectNamedComponents(child);return this._normalComponentNameMap=nameMap,nameMap}get config(){return{zodProps:groupProps,componentName:"Group"}}initPorts(opts={}){let schPinArrangement=this._getSchematicPortArrangement();this._parsedProps?.showAsSchematicBox&&!this._parsedProps.pinLabels&&schPinArrangement&&getPinsFromPortArrangement(schPinArrangement).some(pin=>typeof pin=="string")||super.initPorts(opts)}_getSchematicPortArrangementFromPortDirections(){if(!this._parsedProps?.showAsSchematicBox)return null;let sidePins={leftSide:[],rightSide:[],topSide:[],bottomSide:[]};for(let port of this.children){if(port.componentName!=="Port")continue;let direction3=port._parsedProps.direction;if(!direction3)continue;let pin=port._parsedProps.pinNumber??port._parsedProps.name??void 0;if(pin===void 0)continue;sidePins[direction3==="left"?"leftSide":direction3==="right"?"rightSide":direction3==="up"?"topSide":"bottomSide"].push(pin)}if(sidePins.leftSide.length===0&&sidePins.rightSide.length===0&&sidePins.topSide.length===0&&sidePins.bottomSide.length===0)return null;let arrangement={};return sidePins.leftSide.length>0&&(arrangement.leftSide={pins:sidePins.leftSide,direction:"top-to-bottom"}),sidePins.rightSide.length>0&&(arrangement.rightSide={pins:sidePins.rightSide,direction:"top-to-bottom"}),sidePins.topSide.length>0&&(arrangement.topSide={pins:sidePins.topSide,direction:"left-to-right"}),sidePins.bottomSide.length>0&&(arrangement.bottomSide={pins:sidePins.bottomSide,direction:"left-to-right"}),arrangement}_getSchematicPortArrangement(){return super._getSchematicPortArrangement()??this._getSchematicPortArrangementFromPortDirections()}_ensureSchematicBoxPortsFromConnections(){if(this._parsedProps?.showAsSchematicBox&&this._parsedProps?.connections)for(let[pinName,target]of Object.entries(this._parsedProps.connections)){if(this.children.find(child=>child.componentName==="Port"&&child.isMatchingAnyOf([pinName])))continue;let pinNumberMatch=pinName.match(/^pin(\d+)$/i)??pinName.match(/^(\d+)$/),pinNumber=pinNumberMatch?Number(pinNumberMatch[1]):void 0;this.add(new Port({name:pinName,pinNumber,connectsTo:target}))}}doInitialInitializePortsFromChildren(){super.doInitialInitializePortsFromChildren(),this._ensureSchematicBoxPortsFromConnections()}updateInitializePortsFromChildren(){super.updateInitializePortsFromChildren(),this._ensureSchematicBoxPortsFromConnections()}_getPrimaryPinCount(){let superPinCount=super._getPrimaryPinCount();if(!this._parsedProps?.showAsSchematicBox)return superPinCount;let directPortPinNumbers=this.children.filter(child=>child.componentName==="Port").map(port=>port._parsedProps.pinNumber).filter(pinNumber=>pinNumber!==void 0);return directPortPinNumbers.length===0?superPinCount:Math.max(superPinCount,...directPortPinNumbers)}_getPinLabelsFromPorts(){return this._parsedProps?.showAsSchematicBox?getGroupSchematicBoxPinLabels(this):super._getPinLabelsFromPorts()}doInitialSourceGroupRender(){let{db:db22}=this.root,hasExplicitName=typeof this._parsedProps.name=="string"&&this._parsedProps.name.length>0,source_group3=db22.source_group.insert({name:this.name,is_subcircuit:this.isSubcircuit,was_automatically_named:!hasExplicitName});this.source_group_id=source_group3.source_group_id,this.isSubcircuit&&(this.subcircuit_id=`subcircuit_${source_group3.source_group_id}`,db22.source_group.update(source_group3.source_group_id,{subcircuit_id:this.subcircuit_id}))}doInitialSourceRender(){let{db:db22}=this.root;for(let child of this.getDescendants())child.getGroup()?.source_group_id===this.source_group_id&&db22.source_component.update(child.source_component_id,{source_group_id:this.source_group_id});if(!this.isSubcircuit)return;let disabledLegacyAutorouterPreset=getDisabledLegacyAutorouterPreset(this);disabledLegacyAutorouterPreset&&db22.source_invalid_component_property_error.insert({source_component_id:this.source_component_id??"",property_name:"autorouter",error_type:"source_invalid_component_property_error",message:`The "${disabledLegacyAutorouterPreset}" autorouter is deprecated and is not enabled by this platform. Use the default autorouter and introduce <autoroutingphase /> or <fanout /> elements as needed.`})}doInitialSourceParentAttachment(){let{db:db22}=this.root,parentGroup=this.parent?.getGroup?.();if(parentGroup?.source_group_id&&db22.source_group.update(this.source_group_id,{parent_source_group_id:parentGroup.source_group_id}),!this.isSubcircuit||isAssemblyDeviceContainer(this.parent))return;let parent_subcircuit_id=this.parent?.getSubcircuit?.()?.subcircuit_id;parent_subcircuit_id&&db22.source_group.update(this.source_group_id,{parent_subcircuit_id})}doInitialPcbComponentRender(){if(this.root?.pcbDisabled)return;let{db:db22}=this.root,{_parsedProps:props}=this,groupProps22=props,hasOutline=groupProps22.outline&&groupProps22.outline.length>0,numericOutline=hasOutline?groupProps22.outline.map(point62=>({x:distance.parse(point62.x),y:distance.parse(point62.y)})):void 0,ctx=this.props,anchorPosition=this._getGlobalPcbPositionBeforeLayout(),center2=computeCenterFromAnchorPosition(anchorPosition,ctx),pcb_group3=db22.pcb_group.insert({is_subcircuit:this.isSubcircuit,subcircuit_id:this.subcircuit_id??this.getSubcircuit()?.subcircuit_id,name:this.name,anchor_position:anchorPosition,center:center2,...hasOutline?{outline:numericOutline}:{width:0,height:0},pcb_component_ids:[],source_group_id:this.source_group_id,autorouter_configuration:props.autorouter?{trace_clearance:props.autorouter.traceClearance}:void 0,anchor_alignment:props.pcbAnchorAlignment??null});this.pcb_group_id=pcb_group3.pcb_group_id;for(let child of this.children)db22.pcb_component.update(child.pcb_component_id,{pcb_group_id:pcb_group3.pcb_group_id})}doInitialPcbPrimitiveRender(){this.calculatePcbGroupBounds()}calculatePcbGroupBounds(pcbContentBounds){if(!this.pcb_group_id||this.root?.pcbDisabled)return;let{db:db22}=this.root,props=this._parsedProps,hasOutline=props.outline&&props.outline.length>0,hasExplicitPositioning=this._parsedProps.pcbX!==void 0||this._parsedProps.pcbY!==void 0;if(hasOutline){let numericOutline=props.outline.map(point62=>({x:distance.parse(point62.x),y:distance.parse(point62.y)})),outlineBounds=getBoundsFromPoints(numericOutline);if(!outlineBounds)return;let centerX2=(outlineBounds.minX+outlineBounds.maxX)/2,centerY2=(outlineBounds.minY+outlineBounds.maxY)/2,center22=hasExplicitPositioning?db22.pcb_group.get(this.pcb_group_id)?.center??{x:centerX2,y:centerY2}:{x:centerX2,y:centerY2};db22.pcb_group.update(this.pcb_group_id,{center:center22});return}let contentBounds=pcbContentBounds;if(!contentBounds){let bounds=getBoundsOfPcbComponents(this.children);contentBounds={center:{x:(bounds.minX+bounds.maxX)/2,y:(bounds.minY+bounds.maxY)/2},width:bounds.width,height:bounds.height}}let{width,height}=contentBounds,{x:centerX,y:centerY}=contentBounds.center;if(this.isSubcircuit||this.isRoutingDirective){let{padLeft,padRight,padTop,padBottom}=this._resolvePcbPadding();width+=padLeft+padRight,height+=padTop+padBottom,centerX+=(padRight-padLeft)/2,centerY+=(padTop-padBottom)/2}let resolvedWidth=Number(props.width??width),resolvedHeight=Number(props.height??height),existingCenter=db22.pcb_group.get(this.pcb_group_id)?.center??{x:centerX,y:centerY},shouldUsePcbContentCenter=this.isSubcircuit||this.isRoutingDirective||pcbContentBounds!==void 0,center2=hasExplicitPositioning?shouldUsePcbContentCenter?{x:props.width===void 0?centerX:existingCenter.x,y:props.height===void 0?centerY:existingCenter.y}:existingCenter:{x:centerX,y:centerY};if(hasExplicitPositioning&&props.pcbAnchorAlignment){let anchorPosition=this._getGlobalPcbPositionBeforeLayout(),anchorAlignedCenter=computeCenterFromAnchorPosition(anchorPosition,{...this.props,width:resolvedWidth,height:resolvedHeight});(Math.abs(anchorAlignedCenter.x-center2.x)>1e-6||Math.abs(anchorAlignedCenter.y-center2.y)>1e-6)&&this._repositionOnPcb(anchorAlignedCenter),center2=anchorAlignedCenter}db22.pcb_group.update(this.pcb_group_id,{width:resolvedWidth,height:resolvedHeight,center:center2})}updatePcbPrimitiveRender(){this.calculatePcbGroupBounds()}getNextAvailableName(elm){var _a543,_b6;return(_a543=this.unnamedElementCounter)[_b6=elm.lowercaseComponentName]??(_a543[_b6]=1),`unnamed_${elm.lowercaseComponentName}${this.unnamedElementCounter[elm.lowercaseComponentName]++}`}_resolvePcbPadding(){let props=this._parsedProps,layout=props.pcbLayout,getPaddingValue=key=>{let layoutValue=layout?.[key],propsValue=props[key];if(typeof layoutValue=="number")return layoutValue;if(typeof propsValue=="number")return propsValue},generalPadding=getPaddingValue("padding")??0,paddingX=getPaddingValue("paddingX"),paddingY=getPaddingValue("paddingY"),padLeft=getPaddingValue("paddingLeft")??paddingX??generalPadding,padRight=getPaddingValue("paddingRight")??paddingX??generalPadding,padTop=getPaddingValue("paddingTop")??paddingY??generalPadding,padBottom=getPaddingValue("paddingBottom")??paddingY??generalPadding;return{padLeft,padRight,padTop,padBottom}}doInitialCreateTraceHintsFromProps(){let{_parsedProps:props}=this,{db:db22}=this.root,groupProps22=props;if(!this.isSubcircuit)return;let manualTraceHints=groupProps22.manualEdits?.manual_trace_hints;if(manualTraceHints)for(let manualTraceHint of manualTraceHints)this.add(new TraceHint({for:manualTraceHint.pcb_port_selector,offsets:manualTraceHint.offsets}))}doInitialSourceAddConnectivityMapKey(){Group_doInitialSourceAddConnectivityMapKey(this),Group_doInitialAssignSchematicSheetToConnectedComponents(this)}_areChildSubcircuitsRouted(){let subcircuitChildren=this._findDirectChildSubcircuits();for(let subcircuitChild of subcircuitChildren)if(!subcircuitChild._isInflatedFromCircuitJson&&subcircuitChild._hasTracesToRoute()&&subcircuitChild._shouldRouteAsync()&&!subcircuitChild._asyncAutoroutingResult)return!1;return!0}_findDirectChildSubcircuits(){let result=[],visit=children=>{for(let child of children)child.isSubcircuit&&child!==this?result.push(child):visit(child.children)};return visit(this.children),result}_shouldRouteAsync(){if(this._isLegacyAutorouterDisabled())return!1;let autorouter=this._getAutorouterConfig();return autorouter.groupMode==="sequential-trace"?!1:!!(autorouter.local&&autorouter.groupMode==="subcircuit"||!autorouter.local)}_getRoutingPhasePlans(){return Group_getRoutingPhasePlans(this)}_hasTracesToRoute(){let debug132=(0,import_debug11.default)("tscircuit:core:_hasTracesToRoute"),routingPhasePlans=this._getRoutingPhasePlans(),traceCount=0,hasReroutePhaseWithExistingTraceInput=!1;for(let routingPhasePlan of routingPhasePlans){traceCount+=routingPhasePlan.traces.length;let phaseAutorouterConfig=routingPhasePlan.autorouter?getPresetAutoroutingConfig(routingPhasePlan.autorouter,this.root?.platform):void 0;hasReroutePhaseWithExistingTraceInput||(hasReroutePhaseWithExistingTraceInput=!!(routingPhasePlan.reroute&&(routingPhasePlan.region||phaseAutorouterConfig?.preset==="simplify")))}if(debug132(`[${this.getString()}] has ${traceCount} traces to route`),traceCount>0)return!0;if(hasReroutePhaseWithExistingTraceInput){let existingTraceCount=getExistingPcbTracesForReroute(this).length;return debug132(`[${this.getString()}] has ${existingTraceCount} existing pcb traces available for reroute`),existingTraceCount>0}return!1}async _runEffectMakeHttpAutoroutingRequest(){let{db:db22}=this.root,debug132=(0,import_debug11.default)("tscircuit:core:_runEffectMakeHttpAutoroutingRequest"),props=this._parsedProps,autorouterConfig3=this._getAutorouterConfig(),serverUrl=autorouterConfig3.serverUrl,serverMode=autorouterConfig3.serverMode,fetchWithDebug=(url3,options)=>(debug132("fetching",url3),options.headers&&(options.headers["Tscircuit-Core-Version"]=this.root?.getCoreVersion()),fetch(url3,options)),pcbAndSourceCircuitJson=this.root.db.toArray().filter(element=>element.type.startsWith("source_")||element.type.startsWith("pcb_"));if(serverMode==="solve-endpoint"){if(this.props.autorouter?.inputFormat==="simplified"){let preferredTraceWidth=props.defaultTraceWidth??props.nominalTraceWidth,{simpleRouteJson}=getSimpleRouteJsonFromCircuitJson({db:db22,minTraceWidth:Number(props.minTraceWidth??.15),nominalTraceWidth:preferredTraceWidth!=null?Number(preferredTraceWidth):void 0,subcircuit_id:this.subcircuit_id,subcircuitComponent:this});simpleRouteJson.allowViaInPad=autorouterConfig3.allowViaInPad;let{autorouting_result:autorouting_result2}=await fetchWithDebug(`${serverUrl}/autorouting/solve`,{method:"POST",body:JSON.stringify({input_simple_route_json:simpleRouteJson,subcircuit_id:this.subcircuit_id}),headers:{"Content-Type":"application/json"}}).then(r22=>r22.json());this._asyncAutoroutingResult=autorouting_result2,this._markDirty("PcbTraceRender");return}let{autorouting_result}=await fetchWithDebug(`${serverUrl}/autorouting/solve`,{method:"POST",body:JSON.stringify({input_circuit_json:pcbAndSourceCircuitJson,subcircuit_id:this.subcircuit_id}),headers:{"Content-Type":"application/json"}}).then(r22=>r22.json());this._asyncAutoroutingResult=autorouting_result,this._markDirty("PcbTraceRender");return}let{autorouting_job}=await fetchWithDebug(`${serverUrl}/autorouting/jobs/create`,{method:"POST",body:JSON.stringify({input_circuit_json:pcbAndSourceCircuitJson,provider:"freerouting",autostart:!0,display_name:this.root?.name,subcircuit_id:this.subcircuit_id,server_cache_enabled:autorouterConfig3.serverCacheEnabled}),headers:{"Content-Type":"application/json"}}).then(r22=>r22.json());for(;;){let{autorouting_job:job}=await fetchWithDebug(`${serverUrl}/autorouting/jobs/get`,{method:"POST",body:JSON.stringify({autorouting_job_id:autorouting_job.autorouting_job_id}),headers:{"Content-Type":"application/json"}}).then(r22=>r22.json());if(job.is_finished){let{autorouting_job_output}=await fetchWithDebug(`${serverUrl}/autorouting/jobs/get_output`,{method:"POST",body:JSON.stringify({autorouting_job_id:autorouting_job.autorouting_job_id}),headers:{"Content-Type":"application/json"}}).then(r22=>r22.json());this._asyncAutoroutingResult={output_pcb_traces:autorouting_job_output.output_pcb_traces},this._markDirty("PcbTraceRender");break}if(job.has_error){let err2=new AutorouterError(`Autorouting job failed: ${JSON.stringify(job.error)}`);throw db22.pcb_autorouting_error.insert({pcb_error_id:autorouting_job.autorouting_job_id,error_type:"pcb_autorouting_error",message:err2.message}),err2}await new Promise(resolve7=>setTimeout(resolve7,100))}}async _runLocalAutorouting(){let{db:db22}=this.root,props=this._parsedProps,debug132=(0,import_debug11.default)("tscircuit:core:_runLocalAutorouting");debug132(`[${this.getString()}] starting local autorouting`);let autorouterConfig3=this._getAutorouterConfig(),isLaserPrefabPreset=this._isLaserPrefabAutorouter(autorouterConfig3),isAutoJumperPreset=this._isAutoJumperAutorouter(autorouterConfig3),isSingleLayerBoard=this._getSubcircuitLayerCount()===1,minTraceWidth=Number(props.minTraceWidth??.15),nominalTraceWidth=Number(props.defaultTraceWidth??props.nominalTraceWidth??minTraceWidth),routingPhasePlans=this._getRoutingPhasePlans(),hasPhasedAutorouting=this.getInheritedProperty("routeRemaining")===!1||Group_hasPhasedAutorouting(routingPhasePlans),shouldEmitRoutingPhaseDebugObjects=routingPhasePlans.length>1,routingPhaseDebugLabels=new Map;if(shouldEmitRoutingPhaseDebugObjects)for(let debugObject of db22.pcb_debug_object.list())debugObject.subcircuit_id===this.subcircuit_id&&(debugObject.label?.startsWith("Autorouting phase: ")||debugObject.label?.startsWith("autorouting phase "))&&db22.pcb_debug_object.delete(debugObject.pcb_debug_object_id);let emitRoutingPhaseDebugObject=(routingPhasePlan,bounds)=>{if(!shouldEmitRoutingPhaseDebugObjects)return;let phaseLabel=routingPhaseDebugLabels.get(routingPhasePlan),phaseName=routingPhasePlan.phaseName?.trim();db22.pcb_debug_object.insert({shape:"rect",center:{x:(bounds.minX+bounds.maxX)/2,y:(bounds.minY+bounds.maxY)/2},size:{width:bounds.maxX-bounds.minX,height:bounds.maxY-bounds.minY},label:`autorouting phase ${phaseLabel}${phaseName?` ${phaseName}`:""}`,subcircuit_id:this.subcircuit_id??void 0})},routingStages=routingPhasePlans.flatMap(routingPhasePlan=>{let resolvedPhaseAutorouterConfig=routingPhasePlan.autorouter?getPresetAutoroutingConfig(routingPhasePlan.autorouter,this.root?.platform):autorouterConfig3,preset=resolvedPhaseAutorouterConfig.preset,implicitPhaseLabel=routingPhasePlan.reroute?preset==="simplify"?"simplify":"reroute":routingPhasePlan.fanoutRegionPcbGroupId?routingPhasePlan.autorouter==="default"&&!routingPhasePlan.getPrecomputedRoutingResult?"breakout":"fanout":preset&&preset!=="default"?preset.replaceAll("_"," "):"default";routingPhaseDebugLabels.set(routingPhasePlan,routingPhasePlan.routingPhaseIndex?.toString()??implicitPhaseLabel);let phaseAutorouterConfig=routingPhasePlan.getPrecomputedRoutingResult?{...resolvedPhaseAutorouterConfig,allowViaInPad:(typeof routingPhasePlan.autorouter=="object"?routingPhasePlan.autorouter.allowViaInPad:void 0)??autorouterConfig3.allowViaInPad}:resolvedPhaseAutorouterConfig,stages=getLocalAutoroutingStages(routingPhasePlan.algorithmFn?{...phaseAutorouterConfig,algorithmFn:routingPhasePlan.algorithmFn}:phaseAutorouterConfig,this.root?.platform);return stages.map((stage,phaseStageIndex)=>({...stage,routingPhasePlan,phaseStageIndex,phaseStageCount:stages.length}))}),implicitPhaseLabelCounts=new Map;for(let plan of routingPhasePlans){if(plan.routingPhaseIndex!==null)continue;let label=routingPhaseDebugLabels.get(plan);implicitPhaseLabelCounts.set(label,(implicitPhaseLabelCounts.get(label)??0)+1)}let implicitPhaseLabelOrdinals=new Map;for(let plan of routingPhasePlans){if(plan.routingPhaseIndex!==null)continue;let label=routingPhaseDebugLabels.get(plan);if(implicitPhaseLabelCounts.get(label)<=1)continue;let ordinal=(implicitPhaseLabelOrdinals.get(label)??0)+1;implicitPhaseLabelOrdinals.set(label,ordinal),routingPhaseDebugLabels.set(plan,`${label} ${ordinal}`)}let fanoutPourNetMap=routingStages.some(({autorouterConfig:autorouterConfig22})=>["fanout","single_layer_fanout","dogbone"].includes(autorouterConfig22.preset??""))?Group_getFanoutPourNetMap(this,routingPhasePlans):void 0,{simpleRouteJson:baseSimpleRouteJson}=getSimpleRouteJsonFromCircuitJson({db:db22,minTraceWidth,nominalTraceWidth,subcircuit_id:this.subcircuit_id,subcircuitComponent:this,fanoutPourNetMap}),emitFanoutBoundsConflictWarning=routingPhasePlan=>{let fanoutRegionPcbGroupId=routingPhasePlan.fanoutRegionPcbGroupId;if(!fanoutRegionPcbGroupId)return;let pcbGroup=db22.pcb_group.get(fanoutRegionPcbGroupId),sourceComponentId=db22.pcb_component.list().find(component=>component.pcb_group_id===fanoutRegionPcbGroupId)?.source_component_id;if(!sourceComponentId)return;let message=`${pcbGroup?.name??"Breakout"} defines conflicting fanout bounds with explicit breakout geometry and fanoutBoundaryPadding. Explicit breakout geometry takes precedence, so fanoutBoundaryPadding is ignored.`;db22.source_property_ignored_warning.list().some(warning=>warning.source_component_id===sourceComponentId&&warning.property_name==="fanoutBoundaryPadding"&&warning.message===message)||db22.source_property_ignored_warning.insert({source_component_id:sourceComponentId,property_name:"fanoutBoundaryPadding",message,error_type:"source_property_ignored_warning",subcircuit_id:pcbGroup?.subcircuit_id})},fanoutConfigByPhasePlan=new Map;for(let routingStage of routingStages){let fanoutMode=routingStage.autorouterConfig.preset;(fanoutMode==="fanout"||fanoutMode==="single_layer_fanout")&&!fanoutConfigByPhasePlan.has(routingStage.routingPhasePlan)&&fanoutConfigByPhasePlan.set(routingStage.routingPhasePlan,routingStage.autorouterConfig)}let fanoutPhaseRegions=[];for(let[routingPhasePlan,phaseAutorouterConfig]of fanoutConfigByPhasePlan){let fanoutRegionPcbGroupId=routingPhasePlan.fanoutRegionPcbGroupId;if(!fanoutRegionPcbGroupId)continue;let phaseSimpleRouteJson=Group_filterSimpleRouteJsonForPhase(baseSimpleRouteJson,routingPhasePlan);if(phaseSimpleRouteJson.connections.length===0)continue;phaseSimpleRouteJson=Group_applyDrcTolerancesToSimpleRouteJson(phaseSimpleRouteJson,routingPhasePlan.drcTolerances);let breakoutPoints=db22.pcb_breakout_point.list().filter(point62=>point62.pcb_group_id===fanoutRegionPcbGroupId).map(point62=>({x:point62.x,y:point62.y})),fanoutMode=phaseAutorouterConfig.preset,fanoutBounds=FanoutAutorouter.resolveFanoutBounds(phaseSimpleRouteJson,{mode:fanoutMode,busFanoutDirections:routingPhasePlan.busFanoutDirections,fanoutBounds:routingPhasePlan.fanoutBounds,fanoutBoundaryPadding:routingPhasePlan.fanoutBoundaryPadding,fanoutRoutingLayers:routingPhasePlan.fanoutRoutingLayers,allowBlindAndBuriedVias:phaseSimpleRouteJson.allowBlindAndBuriedVias,breakoutPoints,onFanoutBoundsConflict:()=>emitFanoutBoundsConflictWarning(routingPhasePlan)});if(routingPhasePlan.fanoutBounds=fanoutBounds,!fanoutBounds)continue;let pcbGroup=db22.pcb_group.get(fanoutRegionPcbGroupId),maximumTraceWidth=Math.max(phaseSimpleRouteJson.minTraceWidth,...phaseSimpleRouteJson.connections.map(connection=>connection.nominalTraceWidth??connection.width??phaseSimpleRouteJson.minTraceWidth)),viaPadDiameter=phaseSimpleRouteJson.minViaPadDiameter??phaseSimpleRouteJson.min_via_pad_diameter??phaseSimpleRouteJson.minViaDiameter,traceToPadClearance=phaseSimpleRouteJson.minTraceToPadEdgeClearance??phaseSimpleRouteJson.defaultObstacleMargin??maximumTraceWidth;fanoutPhaseRegions.push({regionId:fanoutRegionPcbGroupId,name:pcbGroup?.name??routingPhasePlan.phaseName??fanoutRegionPcbGroupId,bounds:fanoutBounds,boundaryKeepaway:getFanoutBoundaryPointSpacing({traceWidth:maximumTraceWidth,traceToPadClearance,viaPadDiameter})/2})}let fanoutSeparationConflict=findFanoutPhaseSeparationConflict(fanoutPhaseRegions);if(fanoutSeparationConflict){let{firstRegion,secondRegion,availableGap,requiredGap}=fanoutSeparationConflict,separationDescription=availableGap<0?`overlap by ${Math.abs(availableGap).toFixed(3)}mm`:`are only ${availableGap.toFixed(3)}mm apart`,message=`Fanout regions "${firstRegion.name}" and "${secondRegion.name}" ${separationDescription}, but at least ${requiredGap.toFixed(3)}mm of separation is required for a via-safe routing channel. Move the components farther apart or reduce their facing fanout padding.`;throw db22.pcb_autorouting_error.insert({pcb_error_id:`pcb_autorouter_error_subcircuit_${this.subcircuit_id}`,error_type:"pcb_autorouting_error",message}),this.root?.emit("autorouting:error",{subcircuit_id:this.subcircuit_id,componentDisplayName:this.getString(),error:{message},simpleRouteJson:baseSimpleRouteJson}),new Error(message)}for(let{regionId,bounds}of fanoutPhaseRegions)db22.pcb_group.update(regionId,{center:{x:(bounds.minX+bounds.maxX)/2,y:(bounds.minY+bounds.maxY)/2},width:bounds.maxX-bounds.minX,height:bounds.maxY-bounds.minY});let outputTraces=[],outputJumpers=[],pcbTraceIdsToDelete=new Set,existingRerouteSeedTraces=getExistingSimplifiedPcbTracesForReroute(this),traceMatchesRoutingPhase=(trace,routingPhasePlan)=>{let connectionName=trace.connection_name??trace.pcb_trace_id,sourceTraceIds=new Set([connectionName,trace.pcb_trace_id,...getSourceTraceIdsFromRerouteName(connectionName),...getSourceTraceIdsFromRerouteName(trace.pcb_trace_id)]);return baseSimpleRouteJson.connections.some(connection=>connectionIsInRoutingPhase(connection,routingPhasePlan)?sourceTraceIds.has(connection.name)||(connection.source_trace_id?sourceTraceIds.has(connection.source_trace_id):!1)||(connection.rootConnectionName?sourceTraceIds.has(connection.rootConnectionName):!1)||connection.mergedConnectionNames?.some(name=>sourceTraceIds.has(name)):!1)},manualSourceTraceIds=new Set(this.getDescendants().filter(child=>child instanceof Trace&&!child.getSubcircuit()._isInflatedFromCircuitJson&&!!child._parsedProps.pcbPath?.length).map(trace=>trace.source_trace_id)),manualPcbTraceIds=new Set(db22.pcb_trace.list().filter(trace=>trace.source_trace_id&&manualSourceTraceIds.has(trace.source_trace_id)).map(trace=>trace.pcb_trace_id)),fixedTraceIds=new Set(manualPcbTraceIds),previousStageOutputSimpleRouteJson,skippedRemainingPhases=new Set;for(let[routingStageIndex,{routingPhasePlan,autorouterConfig:phaseAutorouterConfig,strategy:localAutorouterStrategy,usesPreviousStageOutput,phaseStageIndex,phaseStageCount}]of routingStages.entries()){if(skippedRemainingPhases.has(routingPhasePlan))continue;if(usesPreviousStageOutput||(previousStageOutputSimpleRouteJson=void 0),usesPreviousStageOutput&&previousStageOutputSimpleRouteJson===void 0)throw new Error("Autorouting follow-up stage is missing the preceding stage output");let simpleRouteJson=previousStageOutputSimpleRouteJson??baseSimpleRouteJson,isTraceSimplificationPhase=!!(routingPhasePlan.reroute&&phaseAutorouterConfig.preset==="simplify"),isRegionReroutePhase=!!(routingPhasePlan.reroute&&routingPhasePlan.region&&!isTraceSimplificationPhase),isConnectionReroutePhase=!!(routingPhasePlan.reroute&&!isTraceSimplificationPhase&&!routingPhasePlan.region&&routingPhasePlan.traces.length>0),isReroutePhase=isRegionReroutePhase||isConnectionReroutePhase||isTraceSimplificationPhase,rerouteOriginalSrj=isRegionReroutePhase?{...baseSimpleRouteJson,traces:[...existingRerouteSeedTraces,...outputTraces]}:null;if(!usesPreviousStageOutput&&isTraceSimplificationPhase)simpleRouteJson={...Group_filterSimpleRouteJsonForPhase(baseSimpleRouteJson,routingPhasePlan),traces:getAccumulatedPcbTracesWithStageOutputReplacements({accumulatedPcbTraces:existingRerouteSeedTraces,stageOutputPcbTraces:outputTraces})};else if(!usesPreviousStageOutput&&isRegionReroutePhase&&rerouteOriginalSrj)simpleRouteJson=dae(rerouteOriginalSrj,{shape:"rect",...routingPhasePlan.region});else if(!usesPreviousStageOutput&&isConnectionReroutePhase){let phaseInput=Group_filterSimpleRouteJsonForPhase(baseSimpleRouteJson,routingPhasePlan);simpleRouteJson={...phaseInput,traces:[...phaseInput.traces??[],...outputTraces.filter(trace=>!traceMatchesRoutingPhase(trace,routingPhasePlan))]}}else if(!usesPreviousStageOutput&&hasPhasedAutorouting){let phaseInput=Group_filterSimpleRouteJsonForPhase(baseSimpleRouteJson,routingPhasePlan),activeCustomBreakoutRoutingGroupId=routingPhasePlan.routingPcbGroupId;if(activeCustomBreakoutRoutingGroupId){let activeGroupCopperPourObstacles=getSimpleRouteJsonFromCircuitJson({db:db22,minTraceWidth,nominalTraceWidth,subcircuit_id:this.subcircuit_id,subcircuitComponent:this,routingPcbGroupId:activeCustomBreakoutRoutingGroupId,fanoutPourNetMap}).simpleRouteJson.obstacles.filter(obstacle=>obstacle.isCopperPour),nonCopperPourObstacles=phaseInput.obstacles.filter(obstacle=>!obstacle.isCopperPour);phaseInput.obstacles=nonCopperPourObstacles.concat(activeGroupCopperPourObstacles)}simpleRouteJson={...phaseInput,traces:getAccumulatedPcbTracesWithStageOutputReplacements({accumulatedPcbTraces:phaseInput.traces??[],stageOutputPcbTraces:outputTraces})}}if(phaseAutorouterConfig.preset!=="bus_lanes"){let preservesManualTraceGeometry=!phaseAutorouterConfig.algorithmFn&&(phaseAutorouterConfig.preset==="fanout"||phaseAutorouterConfig.preset==="single_layer_fanout");simpleRouteJson=withFixedTraces(simpleRouteJson,preservesManualTraceGeometry?new Set([...fixedTraceIds].filter(pcbTraceId=>!manualPcbTraceIds.has(pcbTraceId))):fixedTraceIds)}simpleRouteJson=Group_applyDrcTolerancesToSimpleRouteJson(simpleRouteJson,routingPhasePlan.drcTolerances),simpleRouteJson.allowViaInPad=phaseAutorouterConfig.allowViaInPad;let getPrecomputedRoutingResult=usesPreviousStageOutput?void 0:routingPhasePlan.getPrecomputedRoutingResult,preflightRoutingCheckPolicy3=this.getInheritedProperty("preflightRoutingCheckPolicy");if(routingPhasePlan.isImplicitRemainingPhase&&phaseStageIndex===0&&this.getInheritedProperty("routeRemaining")===void 0&&(preflightRoutingCheckPolicy3==="basic"||preflightRoutingCheckPolicy3==="conservative")&&simpleRouteJson.connections.length>50){skippedRemainingPhases.add(routingPhasePlan),db22.pcb_autorouting_error.insert({pcb_error_id:`pcb_autorouting_error_remaining_routes_${this.subcircuit_id}`,subcircuit_id:this.subcircuit_id??void 0,error_type:"pcb_autorouting_error",message:`Remaining routes left unrouted (over 50 traces remaining and preflightRoutingCheckPolicy="${preflightRoutingCheckPolicy3}"). Set <board routeRemaining={true} /> or create <autoroutingphase /> elements for specific connections in the order you'd like to route them. The autorouter may hang unless you create autorouting phases incrementally.`});continue}let simplificationHasNoTraceInput=!!(isTraceSimplificationPhase&&simpleRouteJson.traces?.length===0);if((hasPhasedAutorouting||isReroutePhase||usesPreviousStageOutput)&&(simpleRouteJson.connections.length===0&&!isTraceSimplificationPhase&&!getPrecomputedRoutingResult||simplificationHasNoTraceInput)){phaseStageIndex===0&&emitRoutingPhaseDebugObject(routingPhasePlan,simpleRouteJson.bounds),previousStageOutputSimpleRouteJson=simpleRouteJson;continue}let phaseIsAutoJumperPreset=routingPhasePlan.autorouter!==void 0?this._isAutoJumperAutorouter(phaseAutorouterConfig):isAutoJumperPreset,phaseIsLaserPrefabPreset=routingPhasePlan.autorouter!==void 0?this._isLaserPrefabAutorouter(phaseAutorouterConfig):isLaserPrefabPreset;phaseIsAutoJumperPreset&&(simpleRouteJson.allowJumpers=!0,phaseAutorouterConfig.availableJumperTypes&&(simpleRouteJson.availableJumperTypes=phaseAutorouterConfig.availableJumperTypes));let fanoutMode=phaseAutorouterConfig.preset;if((fanoutMode==="fanout"||fanoutMode==="single_layer_fanout")&&!routingPhasePlan.fanoutRegionPcbGroupId&&!getPrecomputedRoutingResult&&(routingPhasePlan.fanoutBounds=FanoutAutorouter.resolveFanoutBounds(simpleRouteJson,{mode:fanoutMode,busFanoutDirections:routingPhasePlan.busFanoutDirections,fanoutBounds:routingPhasePlan.fanoutBounds,fanoutBoundaryPadding:routingPhasePlan.fanoutBoundaryPadding,fanoutRoutingLayers:routingPhasePlan.fanoutRoutingLayers,allowBlindAndBuriedVias:simpleRouteJson.allowBlindAndBuriedVias})),phaseStageIndex===0&&emitRoutingPhaseDebugObject(routingPhasePlan,routingPhasePlan.fanoutBounds??simpleRouteJson.bounds),debug132.enabled&&global.debugOutputArray?.push({name:`simpleroutejson-${this.props.name}.json`,obj:simpleRouteJson}),debug132.enabled){let graphicsObject=Go2(simpleRouteJson);graphicsObject.title=`autorouting-${this.props.name}`,global.debugGraphics?.push(graphicsObject)}let autorouterVersion22=phaseAutorouterConfig.autorouterVersion??this.props.autorouterVersion,effortLevel=this.props.autorouterEffortLevel,effort=effortLevel?Number.parseInt(effortLevel.replace("x",""),10):void 0,commonAutorouterOptions={capacityDepth:phaseAutorouterConfig.capacityDepth,targetMinCapacity:phaseAutorouterConfig.targetMinCapacity,platformConfig:this.root?.platform,useAssignableSolver:phaseIsLaserPrefabPreset||isSingleLayerBoard,useAutoJumperSolver:phaseIsAutoJumperPreset,useLaserPrefabSolver:phaseIsLaserPrefabPreset,autorouterVersion:autorouterVersion22,effort},autorouterName=getPrecomputedRoutingResult?"precomputed":phaseAutorouterConfig.algorithmFn?"custom":localAutorouterStrategy.name,solverName=getPrecomputedRoutingResult||phaseAutorouterConfig.algorithmFn?void 0:localAutorouterStrategy.getSolverName(commonAutorouterOptions),localAutoroutingCacheSolverOptions={autorouterName,solverName,capacityDepth:commonAutorouterOptions.capacityDepth,targetMinCapacity:commonAutorouterOptions.targetMinCapacity,useAssignableSolver:commonAutorouterOptions.useAssignableSolver,useAutoJumperSolver:commonAutorouterOptions.useAutoJumperSolver,useLaserPrefabSolver:commonAutorouterOptions.useLaserPrefabSolver,useTraceSimplificationSolver:phaseAutorouterConfig.preset==="simplify",autorouterVersion:commonAutorouterOptions.autorouterVersion,effort:commonAutorouterOptions.effort},cacheEngine=getPrecomputedRoutingResult||phaseAutorouterConfig.algorithmFn||!localAutorouterStrategy.cacheable?void 0:this.root?.platform?.localCacheEngine,cacheKey=cacheEngine?getLocalAutoroutingCacheKey(simpleRouteJson,localAutoroutingCacheSolverOptions):void 0,cachedResult=cacheKey?await getCachedLocalAutoroutingPhaseResult({cacheEngine,cacheKey}):null,cacheDisabledReason=getPrecomputedRoutingResult?"precomputed":phaseAutorouterConfig.algorithmFn?"custom_algorithm":localAutorouterStrategy.cacheable?cacheEngine?void 0:"no_cache_engine":"strategy_not_cacheable",autoroutingMetadata={routingPhaseIndex:routingPhasePlan.routingPhaseIndex,_actualRoutingPhaseOrderIndex:routingStageIndex,phaseOrdinal:routingStageIndex+1,phaseCount:routingStages.length,connectionCount:simpleRouteJson.connections.length,obstacleCount:simpleRouteJson.obstacles.length,previousTraceCount:simpleRouteJson.traces?.length??0,isReroutePhase,autorouterName,autorouterVersion:autorouterVersion22,solverName,effort,cacheStatus:cacheEngine?cachedResult?"hit":"miss":"disabled",cacheKey,cacheDisabledReason};this.root?.emit("autorouting:start",{type:"autorouting:start",subcircuit_id:this.subcircuit_id,componentDisplayName:this.getString(),...routingPhasePlan.phaseName!==void 0?{phaseName:routingPhasePlan.phaseName,phaseStageIndex,phaseStageCount}:{},...autoroutingMetadata,simpleRouteJson});let autorouter;try{let traces,precomputedOutputSimpleRouteJson;if(getPrecomputedRoutingResult){let result=getPrecomputedRoutingResult(simpleRouteJson);traces=result.traces,precomputedOutputSimpleRouteJson=result.outputSimpleRouteJson;for(let trace of traces)fixedTraceIds.add(trace.pcb_trace_id)}else if(cachedResult)debug132(`[${this.getString()}] using cached local autorouting result`),traces=cachedResult.traces;else{if(phaseAutorouterConfig.algorithmFn?autorouter=await phaseAutorouterConfig.algorithmFn(simpleRouteJson):autorouter=localAutorouterStrategy.create({simpleRouteJson,onSolverEnded:event=>this.root?.emit("solver:ended",{...event,type:"solver:ended",componentName:this.getString()}),commonAutorouterOptions,busFanoutDirections:routingPhasePlan.busFanoutDirections,fanoutBounds:routingPhasePlan.fanoutBounds,fanoutRoutingLayers:routingPhasePlan.fanoutRoutingLayers,allowBlindAndBuriedVias:simpleRouteJson.allowBlindAndBuriedVias,componentNamesById:getPcbComponentNamesById(db22),onSolverStarted:({solverName:solverName2,solverParams,solverConstructorArgs})=>this.root?.emit("solver:started",{type:"solver:started",solverName:solverName2,solverParams,solverConstructorArgs,componentName:this.getString()})}),!autorouter)throw new Error("Failed to create local autorouter");let activeAutorouter=autorouter,routingPromise=new Promise((resolve7,reject)=>{activeAutorouter.on("complete",event=>{debug132(`[${this.getString()}] local autorouting complete`),resolve7(event.traces)}),activeAutorouter.on("error",event=>{debug132(`[${this.getString()}] local autorouting error: ${event.error.message}`),reject(event.error)})});activeAutorouter.on("progress",event=>{this.root?.emit("autorouting:progress",{subcircuit_id:this.subcircuit_id,componentDisplayName:this.getString(),...routingPhasePlan.phaseName!==void 0?{phaseName:routingPhasePlan.phaseName,phaseStageIndex,phaseStageCount}:{},...autoroutingMetadata,...event,type:"autorouting:progress"})}),activeAutorouter.start(),traces=await routingPromise}let transformedSimpleRouteJson=precomputedOutputSimpleRouteJson??autorouter?.getOutputSimpleRouteJson?.();if(transformedSimpleRouteJson&&!usesPreviousStageOutput&&["fanout","single_layer_fanout","dogbone"].includes(phaseAutorouterConfig.preset??"")&&routingPhasePlan.routingPcbGroupId){let synchronizedFanout=Group_syncFanoutExitsWithGlobalConnections({fanoutInputSimpleRouteJson:simpleRouteJson,fanoutOutputSimpleRouteJson:transformedSimpleRouteJson,baseSimpleRouteJson,routingPhasePlan});baseSimpleRouteJson=synchronizedFanout.baseSimpleRouteJson,transformedSimpleRouteJson=synchronizedFanout.downstreamSimpleRouteJson;for(let synchronizedPoint of synchronizedFanout.synchronizedBreakoutPoints){let breakoutPoint=db22.pcb_breakout_point.list().find(point62=>point62.pcb_group_id===synchronizedPoint.routingPcbGroupId&&point62.source_trace_id===synchronizedPoint.sourceTraceId&&Math.abs(point62.x-synchronizedPoint.previousPoint.x)<=1e-6&&Math.abs(point62.y-synchronizedPoint.previousPoint.y)<=1e-6);breakoutPoint&&db22.pcb_breakout_point.update(breakoutPoint.pcb_breakout_point_id,{x:synchronizedPoint.fanoutExitPoint.x,y:synchronizedPoint.fanoutExitPoint.y,layer:synchronizedPoint.fanoutExitPoint.layer})}}if(localAutorouterStrategy.preserveOutputTraces)for(let trace of traces)fixedTraceIds.add(trace.pcb_trace_id);let stageOutputTraces=traces;transformedSimpleRouteJson?.traces?stageOutputTraces=transformedSimpleRouteJson.traces:usesPreviousStageOutput&&(stageOutputTraces=getAccumulatedPcbTracesWithStageOutputReplacements({accumulatedPcbTraces:simpleRouteJson.traces??[],stageOutputPcbTraces:traces}));let eventOutputPcbTraces=stageOutputTraces;!transformedSimpleRouteJson&&!usesPreviousStageOutput&&routingPhasePlan.routingPhaseIndex!==null&&(eventOutputPcbTraces=getAccumulatedPcbTracesWithStageOutputReplacements({accumulatedPcbTraces:simpleRouteJson.traces??[],stageOutputPcbTraces:traces}));let outputSimpleRouteJson={...transformedSimpleRouteJson??simpleRouteJson,traces:eventOutputPcbTraces};previousStageOutputSimpleRouteJson=transformedSimpleRouteJson?outputSimpleRouteJson:void 0,!cachedResult&&cacheKey&&await cacheLocalAutoroutingPhaseResult({cacheEngine,cacheKey,result:{...simpleRouteJson,traces}});let savedPhasePaths=getAutoroutingPhasePcbTracePaths({group:this.selectAll("group").find(group2=>group2.pcb_group_id===routingPhasePlan.fanoutRegionPcbGroupId)??routingPhasePlan.autoroutingPhase?.getGroup()??this,subcircuit:this,input:simpleRouteJson,traces,isFanout:["fanout","single_layer_fanout","dogbone"].includes(phaseAutorouterConfig.preset??"")});if(this.root?.emit("autorouting:end",{...savedPhasePaths,type:"autorouting:end",subcircuit_id:this.subcircuit_id,componentDisplayName:this.getString(),...routingPhasePlan.phaseName!==void 0?{phaseName:routingPhasePlan.phaseName,phaseStageIndex,phaseStageCount}:{},...autoroutingMetadata,simpleRouteJson:outputSimpleRouteJson}),autorouter?.getConnectedOffboardObstacles){let connectedOffboardObstacles=autorouter.getConnectedOffboardObstacles();createSourceTracesFromOffboardConnections({db:db22,connectedOffboardObstacles,simpleRouteJson,subcircuit_id:this.subcircuit_id})}let solver=autorouter?.solver;if(solver?.getOutputJumpers&&outputJumpers.push(...solver.getOutputJumpers()||[]),isRegionReroutePhase&&rerouteOriginalSrj){for(let trace of rerouteOriginalSrj.traces??[])trace.type==="pcb_trace"&&pcbTraceIdsToDelete.add(trace.pcb_trace_id);let reconnectedSrj=uae(rerouteOriginalSrj,{...simpleRouteJson,traces:[...simpleRouteJson.traces??[],...traces]});outputTraces.splice(0,outputTraces.length,...reconnectedSrj.traces??[])}else if(isConnectionReroutePhase){let retainedPcbTraces=outputTraces.filter(trace=>!traceMatchesRoutingPhase(trace,routingPhasePlan));outputTraces.splice(0,outputTraces.length,...getAccumulatedPcbTracesWithStageOutputReplacements({accumulatedPcbTraces:retainedPcbTraces,stageOutputPcbTraces:stageOutputTraces}))}else{if(isTraceSimplificationPhase)for(let existingTrace of existingRerouteSeedTraces)fixedTraceIds.has(existingTrace.pcb_trace_id)||pcbTraceIdsToDelete.add(existingTrace.pcb_trace_id);outputTraces.splice(0,outputTraces.length,...getAccumulatedPcbTracesWithStageOutputReplacements({accumulatedPcbTraces:outputTraces,stageOutputPcbTraces:stageOutputTraces}))}}catch(error2){let{db:db32}=this.root;throw db32.pcb_autorouting_error.insert({pcb_error_id:`pcb_autorouter_error_subcircuit_${this.subcircuit_id}`,error_type:"pcb_autorouting_error",message:error2 instanceof Error?error2.message:String(error2)}),this.root?.emit("autorouting:error",{type:"autorouting:error",subcircuit_id:this.subcircuit_id,componentDisplayName:this.getString(),...routingPhasePlan.phaseName!==void 0?{phaseName:routingPhasePlan.phaseName,phaseStageIndex,phaseStageCount}:{},...autoroutingMetadata,error:{message:error2 instanceof Error?error2.message:String(error2)},simpleRouteJson}),error2}finally{autorouter?.stop()}}this._asyncAutoroutingResult={output_pcb_traces:outputTraces,output_jumpers:outputJumpers,pcb_trace_ids_to_be_replaced:[...pcbTraceIdsToDelete]},this._markDirty("PcbTraceRender")}_startAsyncAutorouting(){this._hasStartedAsyncAutorouting||(this._hasStartedAsyncAutorouting=!0,this._getAutorouterConfig().local?this._queueAsyncEffect("autorouting",async()=>{try{await this._runLocalAutorouting()}catch(error2){if(!(error2 instanceof RoutingPhasePreparationError))throw error2;let{db:db22}=this.root,pcbErrorId=`pcb_autorouter_error_subcircuit_${this.subcircuit_id}`;throw db22.pcb_autorouting_error.list().some(recordedError=>recordedError.pcb_error_id===pcbErrorId&&recordedError.message===error2.message)||(db22.pcb_autorouting_error.insert({pcb_error_id:pcbErrorId,error_type:"pcb_autorouting_error",message:error2.message,subcircuit_id:this.subcircuit_id??void 0}),this.root?.emit("autorouting:error",{type:"autorouting:error",subcircuit_id:this.subcircuit_id,componentDisplayName:this.getString(),error:{message:error2.message}})),error2}}):this._queueAsyncEffect("make-http-autorouting-request",async()=>this._runEffectMakeHttpAutoroutingRequest()))}doInitialPcbTraceRender(){let debug132=(0,import_debug11.default)("tscircuit:core:doInitialPcbTraceRender");if(!this.isSubcircuit||this.root?.pcbDisabled||this.root?.pcbRoutingDisabled||this.getInheritedProperty("routingDisabled")||this._isInflatedFromCircuitJson||this._isLegacyAutorouterDisabled()||this._shouldUseTraceByTraceRouting())return;if(!this._areChildSubcircuitsRouted()){debug132(`[${this.getString()}] child subcircuits are not routed, skipping async autorouting until subcircuits routed`);return}if(debug132(`[${this.getString()}] no child subcircuits to wait for, initiating async routing`),!this._hasTracesToRoute())return;let shouldSkipBecauseOfPlacementErrors=shouldSkipAutoroutingBecauseOfPlacementErrors({component:this,subcircuit:this}),shouldSkipBecauseOfTraceLengthViolations=shouldSkipAutoroutingBecauseOfTraceLengthViolations({component:this,subcircuit:this});shouldSkipBecauseOfPlacementErrors||shouldSkipBecauseOfTraceLengthViolations||this._startAsyncAutorouting()}doInitialSchematicTraceRender(){this._parsedProps.showAsSchematicBox||Group_doInitialSchematicTraceRender(this)}doInitialSchematicSheetRender(){Group_doInitialSchematicSheetRender(this)}updateSchematicSheetRender(){Group_updateSchematicSheetRender(this)}updatePcbTraceRender(){let debug132=(0,import_debug11.default)("tscircuit:core:updatePcbTraceRender");if(debug132(`[${this.getString()}] updating...`),!this.isSubcircuit||this._isInflatedFromCircuitJson||this._isLegacyAutorouterDisabled())return;if(this._shouldRouteAsync()&&this._hasTracesToRoute()&&!this._hasStartedAsyncAutorouting){if(this._areChildSubcircuitsRouted()){let shouldSkipBecauseOfPlacementErrors=shouldSkipAutoroutingBecauseOfPlacementErrors({component:this,subcircuit:this}),shouldSkipBecauseOfTraceLengthViolations=shouldSkipAutoroutingBecauseOfTraceLengthViolations({component:this,subcircuit:this});if(shouldSkipBecauseOfPlacementErrors||shouldSkipBecauseOfTraceLengthViolations)return;debug132(`[${this.getString()}] child subcircuits are now routed, starting async autorouting`),this._startAsyncAutorouting()}return}if(!this._asyncAutoroutingResult||this._shouldUseTraceByTraceRouting())return;let{db:db22}=this.root;if(this._asyncAutoroutingResult.output_simple_route_json){debug132(`[${this.getString()}] updating PCB traces from simple route json (${this._asyncAutoroutingResult.output_simple_route_json.traces?.length} traces)`),this._updatePcbTraceRenderFromSimpleRouteJson();return}if(this._asyncAutoroutingResult.output_pcb_traces){debug132(`[${this.getString()}] updating PCB traces from ${this._asyncAutoroutingResult.output_pcb_traces.length} traces`),this._updatePcbTraceRenderFromPcbTraces();return}}_updatePcbTraceRenderFromSimpleRouteJson(){let{db:db22}=this.root,{traces:routedTraces}=this._asyncAutoroutingResult.output_simple_route_json;if(routedTraces)for(let routedTrace of routedTraces){let cjRoute=routedTrace.route.map(point62=>point62.route_type!=="through_obstacle"?point62:{route_type:"through_pad",start:point62.start,end:point62.end,start_layer:point62.from_layer,end_layer:point62.to_layer,width:point62.width,circuitJsonMetadata:point62.circuitJsonMetadata}),pcb_trace3=db22.pcb_trace.insert({subcircuit_id:this.subcircuit_id,route:getCircuitJsonPcbTraceRoute(cjRoute)});claimSrjAssignablePcbViasTraversedByRoute({db:db22,pcbTrace:pcb_trace3,routeWithSrjMetadata:cjRoute})}}_updatePcbTraceRenderFromPcbTraces(){let{output_pcb_traces,output_jumpers,pcb_trace_ids_to_be_replaced}=this._asyncAutoroutingResult;if(!output_pcb_traces)return;let{db:db22}=this.root,pcbStyle3=this.getInheritedMergedProperty("pcbStyle"),{holeDiameter,padDiameter}=getViaDiameterDefaults(pcbStyle3),boardComponent=this._getBoard(),board=boardComponent?.pcb_board_id?db22.pcb_board.get(boardComponent.pcb_board_id):db22.pcb_board.list()[0],routedViaHoleDiameter=board?.min_via_hole_diameter??holeDiameter,routedViaPadDiameter=board?.min_via_pad_diameter??padDiameter;output_jumpers&&output_jumpers.length>0&&insertAutoplacedJumpers({db:db22,output_jumpers,subcircuit_id:this.subcircuit_id}),deleteExistingPcbTracesReplacedBy({group:this,outputPcbTraces:output_pcb_traces,pcbTraceIdsToReplace:pcb_trace_ids_to_be_replaced});let materializedPcbVias=db22.pcb_via.list(),jumperPadInfos=getJumperPadInfos(db22);for(let pcb_trace3 of output_pcb_traces){if(pcb_trace3.type!=="pcb_trace")continue;pcb_trace3.subcircuit_id??(pcb_trace3.subcircuit_id=this.subcircuit_id);let cjRoute=pcb_trace3.route.map(point62=>point62.route_type!=="through_obstacle"?point62:{route_type:"through_pad",start:point62.start,end:point62.end,start_layer:point62.from_layer,end_layer:point62.to_layer,width:point62.width,circuitJsonMetadata:point62.circuitJsonMetadata}),routeSourceTraceId=getSourceTraceIdForRoutedTrace({db:db22,trace:{...pcb_trace3,route:cjRoute},subcircuit_id:this.subcircuit_id});cjRoute=ensureRouteStartsAtSourceTraceStart({db:db22,route:cjRoute,routeThicknessMode:pcb_trace3.route_thickness_mode,sourceTraceId:routeSourceTraceId}),pcb_trace3.route=cjRoute;let segments=splitPcbTracesOnJumperSegments(cjRoute);segments===null&&(segments=[cjRoute]);let processedSegments=addPortIdsToTracesAtJumperPads(segments,jumperPadInfos);for(let segment2 of processedSegments)if(segment2.length>0){let circuitJsonSegment=getCircuitJsonPcbTraceRoute(segment2),sourceTraceId=getSourceTraceIdForRoutedTrace({db:db22,trace:{...pcb_trace3,route:circuitJsonSegment},subcircuit_id:this.subcircuit_id}),insertedPcbTrace=db22.pcb_trace.insert({...pcb_trace3,source_trace_id:sourceTraceId,route:circuitJsonSegment});claimSrjAssignablePcbViasTraversedByRoute({db:db22,pcbTrace:insertedPcbTrace,routeWithSrjMetadata:segment2})}}for(let pcb_trace3 of output_pcb_traces)if(pcb_trace3.type!=="pcb_via"&&pcb_trace3.type==="pcb_trace"){let sourceTraceId=getSourceTraceIdForRoutedTrace({db:db22,trace:pcb_trace3,subcircuit_id:this.subcircuit_id}),{connection_name:inputConnectionName}=pcb_trace3,subcircuitConnectivityMapKey;if(sourceTraceId&&(subcircuitConnectivityMapKey=db22.source_trace.get(sourceTraceId)?.subcircuit_connectivity_map_key),!subcircuitConnectivityMapKey&&inputConnectionName){let sourceNet=db22.source_net.get(inputConnectionName);sourceNet&&(subcircuitConnectivityMapKey=sourceNet.subcircuit_connectivity_map_key)}for(let point62 of pcb_trace3.route)if(point62.route_type==="via"){let routedViaPoint=point62,fromLayer=point62.from_layer,toLayer=point62.to_layer,pcbVia={pcb_trace_id:pcb_trace3.pcb_trace_id,x:point62.x,y:point62.y,hole_diameter:routedViaPoint.via_hole_diameter??routedViaPoint.hole_diameter??routedViaHoleDiameter,outer_diameter:routedViaPoint.via_diameter??routedViaPoint.outer_diameter??routedViaPadDiameter,layers:getAutoroutedViaLayers({fromLayer,toLayer,layerCount:this._getSubcircuitLayerCount(),allowBlindAndBuriedVias:board?.allow_blind_and_buried_vias??!1,physicalLayers:routedViaPoint.layers}),from_layer:fromLayer,to_layer:toLayer,subcircuit_id:this.subcircuit_id,pcb_group_id:this.pcb_group_id??void 0,subcircuit_connectivity_map_key:subcircuitConnectivityMapKey};if(materializedPcbVias.some(materializedPcbVia=>pcbViasSharePhysicalHole(materializedPcbVia,pcbVia)))continue;materializedPcbVias.push(db22.pcb_via.insert(pcbVia))}}}doInitialSchematicComponentRender(){if(this.root?.schematicDisabled)return;let{db:db22}=this.root,{_parsedProps:props}=this,schematic_group3=db22.schematic_group.insert({is_subcircuit:this.isSubcircuit,subcircuit_id:this.subcircuit_id,name:this.name,center:this._getGlobalSchematicPositionBeforeLayout(),width:0,height:0,schematic_component_ids:[],source_group_id:this.source_group_id,show_as_schematic_box:props.showAsSchematicBox??!1});this.schematic_group_id=schematic_group3.schematic_group_id,props.showAsSchematicBox&&Group_doInitialSchematicBoxComponentRender(this);for(let child of this.getDescendants())child.getGroup()?.source_group_id===this.source_group_id&&(child._parsedProps?.showAsSchematicBox||child.schematic_component_id&&db22.schematic_component.update(child.schematic_component_id,{schematic_group_id:schematic_group3.schematic_group_id}))}_getSchematicLayoutMode(){let props=this._parsedProps,schAutoLayoutEnabled=props.schAutoLayoutEnabled??!1;if(props.schLayout?.layoutMode==="none"||props.schLayout?.layoutMode==="relative")return"relative";if(props.schLayout?.matchAdapt)return"match-adapt";if(props.schLayout?.flex)return"flex";if(props.schLayout?.grid)return"grid";if(props.schMatchAdapt)return"match-adapt";if(props.schFlex)return"flex";if(props.schGrid)return"grid";if(props.matchAdapt)return"match-adapt";if(props.flex)return"flex";if(props.grid)return"grid";if(props.relative||props.schRelative)return"relative";let anyLayoutChildHasSchCoords=this.children.some(child=>{let cProps=child._parsedProps;return(child.source_component_id!==null||child.source_group_id!==null)&&(cProps?.schX!==void 0||cProps?.schY!==void 0)}),hasManualEdits=(props.manualEdits?.schematic_placements?.length??0)>0;return schAutoLayoutEnabled&&!hasManualEdits||!anyLayoutChildHasSchCoords&&!hasManualEdits?"match-adapt":"relative"}doInitialSchematicLayout(){if(this._parsedProps.showAsSchematicBox){this._insertSchematicBorder();return}if(this.children.some(c22=>c22.source_component_id!==null&&c22._parsedProps?.schSectionName!==void 0)){this._doInitialSchematicLayoutSections(),this._insertSchematicBorder();return}let schematicLayoutMode=this._getSchematicLayoutMode();schematicLayoutMode==="match-adapt"&&this._doInitialSchematicLayoutMatchpack(),schematicLayoutMode==="grid"&&this._doInitialSchematicLayoutGrid(),schematicLayoutMode==="flex"&&this._doInitialSchematicLayoutFlex(),this._insertSchematicBorder()}_doInitialSchematicLayoutSections(){Group_doInitialSchematicLayoutSections(this)}_doInitialSchematicLayoutMatchAdapt(){Group_doInitialSchematicLayoutMatchAdapt(this)}_doInitialSchematicLayoutMatchpack(){Group_doInitialSchematicLayoutMatchPack(this)}_doInitialSchematicLayoutGrid(){Group_doInitialSchematicLayoutGrid(this)}_doInitialSchematicLayoutFlex(){Group_doInitialSchematicLayoutFlex(this)}_getPcbLayoutMode(){let props=this._parsedProps,rawProps=this.props;if(this._isInflatedFromCircuitJson||props.pcbRelative)return"none";if(props.pcbLayout?.matchAdapt)return"match-adapt";if(props.pcbLayout?.flex)return"flex";if(props.pcbLayout?.grid)return"grid";if(props.pcbLayout?.pack)return"pack";if(props.pcbFlex)return"flex";if(props.pcbGrid)return"grid";if(props.pcbPack||props.pack)return"pack";if(props.matchAdapt)return"match-adapt";if(props.flex)return"flex";if(props.grid)return"grid";let groupHasCoords=props.pcbX!==void 0||props.pcbY!==void 0||props.pcbLeftEdgeX!==void 0||props.pcbRightEdgeX!==void 0||props.pcbTopEdgeY!==void 0||props.pcbBottomEdgeY!==void 0||rawProps.pcbLeftEdgeX!==void 0||rawProps.pcbRightEdgeX!==void 0||rawProps.pcbTopEdgeY!==void 0||rawProps.pcbBottomEdgeY!==void 0,hasManualEdits=(props.manualEdits?.pcb_placements?.length??0)>0,unpositionedDirectChildrenCount=this.children.reduce((count,child)=>{if(!child.pcb_component_id&&!child.pcb_group_id)return count;let childProps=child._parsedProps,rawChildProps=child.props,hasCoords=childProps?.pcbX!==void 0||childProps?.pcbY!==void 0||childProps?.pcbLeftEdgeX!==void 0||childProps?.pcbRightEdgeX!==void 0||childProps?.pcbTopEdgeY!==void 0||childProps?.pcbBottomEdgeY!==void 0||rawChildProps?.pcbLeftEdgeX!==void 0||rawChildProps?.pcbRightEdgeX!==void 0||rawChildProps?.pcbTopEdgeY!==void 0||rawChildProps?.pcbBottomEdgeY!==void 0;return count+(hasCoords?0:1)},0);return!hasManualEdits&&unpositionedDirectChildrenCount>1?"pack":"none"}doInitialPcbLayout(){if(this.root?.pcbDisabled)return;if(this.pcb_group_id){let{db:db22}=this.root,props=this._parsedProps;if(props.pcbX!==void 0||props.pcbY!==void 0){let parentGroup=this.parent?.getGroup?.(),pcbParentGroupId=parentGroup?.pcb_group_id?db22.pcb_group.get(parentGroup.pcb_group_id)?.pcb_group_id:void 0,positionedRelativeToBoardId=pcbParentGroupId?void 0:this._getBoard()?.pcb_board_id??void 0;db22.pcb_group.update(this.pcb_group_id,{position_mode:"relative_to_group_anchor",positioned_relative_to_pcb_group_id:pcbParentGroupId,positioned_relative_to_pcb_board_id:positionedRelativeToBoardId,display_offset_x:props.pcbX,display_offset_y:props.pcbY})}}let pcbLayoutMode=this._getPcbLayoutMode();pcbLayoutMode==="grid"?this._doInitialPcbLayoutGrid():pcbLayoutMode==="pack"?this._doInitialPcbLayoutPack():pcbLayoutMode==="flex"&&this._doInitialPcbLayoutFlex()}_doInitialPcbLayoutGrid(){Group_doInitialPcbLayoutGrid(this)}_doInitialPcbLayoutPack(){Group_doInitialPcbLayoutPack(this)}_doInitialPcbLayoutFlex(){Group_doInitialPcbLayoutFlex(this)}_insertSchematicBorder(){if(this.root?.schematicDisabled)return;let{db:db22}=this.root,props=this._parsedProps;if(!props.border)return;let width=typeof props.schWidth=="number"?props.schWidth:void 0,height=typeof props.schHeight=="number"?props.schHeight:void 0,paddingGeneral=typeof props.schPadding=="number"?props.schPadding:0,paddingLeft=typeof props.schPaddingLeft=="number"?props.schPaddingLeft:paddingGeneral,paddingRight=typeof props.schPaddingRight=="number"?props.schPaddingRight:paddingGeneral,paddingTop=typeof props.schPaddingTop=="number"?props.schPaddingTop:paddingGeneral,paddingBottom=typeof props.schPaddingBottom=="number"?props.schPaddingBottom:paddingGeneral,schematicGroup=this.schematic_group_id?db22.schematic_group.get(this.schematic_group_id):null;if(schematicGroup&&(width===void 0&&typeof schematicGroup.width=="number"&&(width=schematicGroup.width),height===void 0&&typeof schematicGroup.height=="number"&&(height=schematicGroup.height)),width===void 0||height===void 0)return;let center2=schematicGroup?.center??this._getGlobalSchematicPositionBeforeLayout(),left=center2.x-width/2-paddingLeft,bottom=center2.y-height/2-paddingBottom,finalWidth=width+paddingLeft+paddingRight,finalHeight=height+paddingTop+paddingBottom;db22.schematic_box.insert({width:finalWidth,height:finalHeight,x:left,y:bottom,is_dashed:props.border?.dashed??!1})}_determineSideFromPosition(port,component){if(!port.center||!component.center)return"left";let dx22=port.center.x-component.center.x,dy22=port.center.y-component.center.y;return Math.abs(dx22)>Math.abs(dy22)?dx22>0?"right":"left":dy22>0?"bottom":"top"}_calculateSchematicBounds(boxes){if(boxes.length===0)return{minX:0,maxX:0,minY:0,maxY:0};let minX=1/0,maxX=-1/0,minY=1/0,maxY=-1/0;for(let box2 of boxes)minX=Math.min(minX,box2.centerX),maxX=Math.max(maxX,box2.centerX),minY=Math.min(minY,box2.centerY),maxY=Math.max(maxY,box2.centerY);let padding=2;return{minX:minX-padding,maxX:maxX+padding,minY:minY-padding,maxY:maxY+padding}}_getAutorouterConfig(){let autorouter=this._parsedProps.autorouter||this.getInheritedProperty("autorouter");return getPresetAutoroutingConfig(autorouter,this.root?.platform)}_isLegacyAutorouterDisabled(){return getDisabledLegacyAutorouterPreset(this)!==null}_isLaserPrefabAutorouter(autorouterConfig3=this._getAutorouterConfig()){let autorouterProp3=this.props.autorouter,normalize9=value=>value?.replace(/-/g,"_")??value;return autorouterConfig3.preset==="laser_prefab"?!0:typeof autorouterProp3=="string"?normalize9(autorouterProp3)==="laser_prefab":typeof autorouterProp3=="object"&&autorouterProp3?normalize9(autorouterProp3.preset)==="laser_prefab":!1}_isAutoJumperAutorouter(autorouterConfig3=this._getAutorouterConfig()){let autorouterProp3=this.props.autorouter,normalize9=value=>value?.replace(/-/g,"_")??value;return autorouterConfig3.preset==="auto_jumper"?!0:typeof autorouterProp3=="string"?normalize9(autorouterProp3)==="auto_jumper":typeof autorouterProp3=="object"&&autorouterProp3?normalize9(autorouterProp3.preset)==="auto_jumper":!1}_getSubcircuitLayerCount(){let layers=this.getInheritedProperty("layers");return typeof layers=="number"?layers:2}_shouldUseTraceByTraceRouting(){return getDisabledLegacyGroupAutorouterPreset(this)?!1:this._getAutorouterConfig().groupMode==="sequential-trace"}doInitialPcbDesignRuleChecks(){if(this.root?.pcbDisabled||this._isLegacyAutorouterDisabled()||this.root?.pcbRoutingDisabled||this.getInheritedProperty("routingDisabled"))return;let{db:db22}=this.root;if(this.isSubcircuit){let immediateChildrenByName=new Map;for(let child of this.children)if(!child.isSubcircuit&&child._parsedProps.name){let components=immediateChildrenByName.get(child._parsedProps.name)||[];components.push(child),immediateChildrenByName.set(child._parsedProps.name,components)}for(let[name,components]of immediateChildrenByName.entries()){if(components.length<=1)continue;let sameNamedTraces=components.filter(child=>child instanceof Trace),duplicateNameIsOnlyTraces=sameNamedTraces.length===components.length,mutuallyConnectedTraceKeys=sameNamedTraces.map(trace=>trace.subcircuit_connectivity_map_key),sameNamedTracesAreMutuallyConnected=duplicateNameIsOnlyTraces&&mutuallyConnectedTraceKeys.every(Boolean)&&new Set(mutuallyConnectedTraceKeys).size===1;if(!duplicateNameIsOnlyTraces||!sameNamedTracesAreMutuallyConnected){let displaySubcircuitName=this.name||"unnamed",message=duplicateNameIsOnlyTraces?`Trace "${name}" in subcircuit "${displaySubcircuitName}" shares a name with another trace, but the traces are not mutually connected. Same-named traces must have the same subcircuit connectivity map key.`:`Multiple immediate children found with name "${name}" in subcircuit "${displaySubcircuitName}". Names must be unique.`;db22.pcb_trace_error.insert({error_type:"pcb_trace_error",message,source_trace_id:"",pcb_trace_id:"",pcb_component_ids:components.map(c22=>c22.pcb_component_id).filter(Boolean),pcb_port_ids:[]})}}}Group_doInitialStandaloneSubcircuitPcbDesignRuleChecks(this)}doInitialSchematicLabelNetsWithConflictingNames(){this.root?.schematicDisabled||this.getTopLevelRenderable()===this&&assignSchematicNetLabelSuperscripts(this.root.db)}updateSchematicLabelNetsWithConflictingNames(){this.doInitialSchematicLabelNetsWithConflictingNames()}doInitialSchematicReplaceNetLabelsWithSymbols(){if(this.root?.schematicDisabled||!this.isSubcircuit)return;let{db:db22}=this.root,subtree=db22;for(let nl3 of subtree.schematic_net_label.list()){let net=subtree.source_net.get(nl3.source_net_id),text=nl3.text||net?.name||"",isGroundNet=net?.is_ground||GROUND_NET_REGEX.test(text),isPowerNet=net?.is_power||POWER_NET_REGEX.test(text);if(nl3.anchor_side==="top"&&isGroundNet){subtree.schematic_net_label.update(nl3.schematic_net_label_id,{symbol_name:"rail_down"});continue}nl3.anchor_side==="bottom"&&isPowerNet&&subtree.schematic_net_label.update(nl3.schematic_net_label_id,{symbol_name:"rail_up"})}}doInitialSimulationSpiceEngineRender(){Group_doInitialSimulationSpiceEngineRender(this)}doInitialPcbComponentAnchorAlignment(){Group_doInitialPcbComponentAnchorAlignment(this)}updatePcbComponentAnchorAlignment(){this.doInitialPcbComponentAnchorAlignment()}doInitialPcbCalcPlacementResolution(){Group_doInitialPcbCalcPlacementResolution(this)}updatePcbCalcPlacementResolution(){this.doInitialPcbCalcPlacementResolution()}_getMinimumFlexContainerSize(){return super._getMinimumFlexContainerSize()}_repositionOnPcb(position4){return super._repositionOnPcb(position4)}};function inflateSourceGroup(sourceGroup,inflatorContext){let{injectionDb,subcircuit,groupsMap}=inflatorContext,pcbGroup=injectionDb.pcb_group.getWhere({source_group_id:sourceGroup.source_group_id}),groupProps22={name:sourceGroup.name??`inflated_group_${sourceGroup.source_group_id}`};if(pcbGroup?.position_mode==="relative_to_group_anchor"&&pcbGroup.anchor_position){let baseAnchor={x:0,y:0};if(sourceGroup.parent_source_group_id){let parentPcbGroup=injectionDb.pcb_group.getWhere({source_group_id:sourceGroup.parent_source_group_id});parentPcbGroup?.anchor_position&&(baseAnchor=parentPcbGroup.anchor_position)}groupProps22.pcbX=pcbGroup.anchor_position.x-baseAnchor.x,groupProps22.pcbY=pcbGroup.anchor_position.y-baseAnchor.y}pcbGroup?.anchor_alignment&&(groupProps22.pcbAnchorAlignment=pcbGroup.anchor_alignment);let group2=new Group5(groupProps22);return group2._isInflatedFromCircuitJson=!0,group2.source_group_id=sourceGroup.source_group_id,groupsMap&&groupsMap.set(sourceGroup.source_group_id,group2),sourceGroup.parent_source_group_id&&groupsMap?.has(sourceGroup.parent_source_group_id)?groupsMap.get(sourceGroup.parent_source_group_id).add(group2):subcircuit.add(group2),group2}var Inductor2=class extends NormalComponent{constructor(){super(...arguments);__publicField(this,"_adjustSilkscreenTextAutomatically",!0)}get config(){return{componentName:"Inductor",schematicSymbolName:this.props.symbolName??"inductor",zodProps:inductorProps,sourceFtype:FTYPE.simple_inductor}}_getSchematicSymbolDisplayValue(){return`${formatSiUnit(this._parsedProps.inductance)}H`}initPorts(){super.initPorts({additionalAliases:{pin1:["anode","pos","left"],pin2:["cathode","neg","right"]}})}doInitialSourceRender(){let{db:db22}=this.root,{_parsedProps:props}=this,source_component=db22.source_component.insert({name:this.name,ftype:FTYPE.simple_inductor,inductance:this.props.inductance,max_current_rating:props.maxCurrentRating===void 0?void 0:parseAndConvertSiUnit(props.maxCurrentRating,"A").value,display_inductance:this._getSchematicSymbolDisplayValue(),supplier_part_numbers:props.supplierPartNumbers,manufacturer_part_number:resolveManufacturerPartNumber(props),are_pins_interchangeable:!0,display_name:props.displayName});this.source_component_id=source_component.source_component_id}};function inflateSourceInductor(sourceElm,inflatorContext){let{injectionDb,subcircuit,groupsMap}=inflatorContext,pcbElm=injectionDb.pcb_component.getWhere({source_component_id:sourceElm.source_component_id}),cadElm=injectionDb.cad_component.getWhere({source_component_id:sourceElm.source_component_id}),{pcbX,pcbY}=getInflatedPcbPlacement({pcbComponent:pcbElm,sourceGroupId:sourceElm.source_group_id,inflatorContext}),inductor=new Inductor2({name:sourceElm.name,inductance:sourceElm.inductance,layer:pcbElm?.layer,pcbX,pcbY,pcbRotation:pcbElm?.rotation,doNotPlace:pcbElm?.do_not_place,obstructsWithinBounds:pcbElm?.obstructs_within_bounds});if(pcbElm){let footprint=inflateFootprintComponent(pcbElm,{...inflatorContext,normalComponent:inductor});footprint&&inductor.add(footprint)}sourceElm.source_group_id&&groupsMap?.has(sourceElm.source_group_id)?groupsMap.get(sourceElm.source_group_id).add(inductor):subcircuit.add(inductor)}var generatedNotes=new WeakMap,getPolarity2=port=>{let hints=[port.name,...port.port_hints??[]].map(hint=>hint.toLowerCase().replace(/[^a-z0-9+-]/g,"")),anode=hints.some(hint=>["a","anode","pos","positive","+"].includes(hint)),cathode=hints.some(hint=>["k","c","cathode","neg","negative","-"].includes(hint));return anode===cathode?null:anode?"anode":"cathode"},Led_addPolarityFabricationSymbol=led2=>{let root=led2.root;if(!root)return;let{db:db22}=root,previous=generatedNotes.get(led2);for(let path of previous??[])db22.pcb_fabrication_note_path.delete(path.pcb_fabrication_note_path_id);if(generatedNotes.delete(led2),root.pcbDisabled||!led2.pcb_component_id)return;let pcb=db22.pcb_component.get(led2.pcb_component_id);if(!pcb||pcb.layer!=="top"&&pcb.layer!=="bottom")return;let ports=db22.source_port.list({source_component_id:led2.source_component_id}),anodes=ports.filter(port=>getPolarity2(port)==="anode"),cathodes=ports.filter(port=>getPolarity2(port)==="cathode");if(anodes.length!==1||cathodes.length!==1)return;let anode=anodes[0],cathode=cathodes[0],a22=db22.pcb_port.getWhere({source_port_id:anode.source_port_id}),k22=db22.pcb_port.getWhere({source_port_id:cathode.source_port_id});if(!a22||!k22)return;let distance27=Math.hypot(k22.x-a22.x,k22.y-a22.y);if(distance27<1e-6)return;let angle3=Math.atan2(k22.y-a22.y,k22.x-a22.x),frame=compose2(translate2((a22.x+k22.x)/2,(a22.y+k22.y)/2),rotate2(angle3)),point62=(x22,y22)=>applyToPoint2(frame,{x:x22,y:y22}),common={pcb_component_id:pcb.pcb_component_id,subcircuit_id:led2.getSubcircuit()?.subcircuit_id??void 0,layer:pcb.layer},notes=[];generatedNotes.set(led2,notes);let halfLength=Math.min(distance27*.2,.4),halfHeight=halfLength*.75,routes=[[point62(-distance27/2,0),point62(-halfLength,0)],[point62(-halfLength,-halfHeight),point62(halfLength,0),point62(-halfLength,halfHeight),point62(-halfLength,-halfHeight)],[point62(halfLength,-halfHeight),point62(halfLength,halfHeight)],[point62(halfLength,0),point62(distance27/2,0)]];for(let route2 of routes)notes.push(db22.pcb_fabrication_note_path.insert({...common,route:route2,stroke_width:.08}))},Led=class extends NormalComponent{get config(){let symbolMap={laser:"laser_diode"},variantSymbol=this.props.laser?"laser":null,baseSymbolName=variantSymbol?symbolMap[variantSymbol]:this.props.symbolName??"led",compactSize=this.props.schSize==="sm"||this.props.schSize==="xs"?this.props.schSize:void 0,compactSymbolName=compactSize&&baseSymbolName==="led"?`led_${compactSize}`:void 0;return{schematicSymbolName:compactSymbolName&&`${compactSymbolName}_right`in zh?compactSymbolName:baseSymbolName,componentName:"Led",zodProps:ledProps,sourceFtype:"simple_led"}}initPorts(){let hasFootprintChild=this.children.some(child=>child.componentName==="Footprint"),footprint=this.resolveFootprint(),hasPinLabels=!!this._resolvePinLabels(),shouldAddDefaultAliases=!hasPinLabels&&!hasFootprintChild&&(!footprint||isFootprinterString(footprint));super.initPorts({pinCount:2,ignoreSymbolPorts:!hasPinLabels&&!shouldAddDefaultAliases,additionalAliases:{pin1:shouldAddDefaultAliases?["anode","pos","left"]:[],pin2:shouldAddDefaultAliases?["cathode","neg","right"]:[]}})}_getSchematicSymbolDisplayValue(){return this._parsedProps.schDisplayValue||this._parsedProps.color||void 0}getFootprinterString(){let baseFootprint=super.getFootprinterString();return baseFootprint&&this.props.color?`${baseFootprint}_color(${this.props.color})`:baseFootprint}doInitialSourceRender(){let{db:db22}=this.root,{_parsedProps:props}=this,source_component=db22.source_component.insert({ftype:"simple_led",name:this.name,wave_length:props.wavelength,color:props.color,symbol_display_value:this._getSchematicSymbolDisplayValue(),manufacturer_part_number:resolveManufacturerPartNumber(props),supplier_part_numbers:props.supplierPartNumbers,are_pins_interchangeable:!1,display_name:props.displayName});this.source_component_id=source_component.source_component_id}get pos(){return this.portMap.pos}doInitialPcbComponentSizeCalculation(){super.doInitialPcbComponentSizeCalculation(),Led_addPolarityFabricationSymbol(this)}get anode(){return this.portMap.anode}get neg(){return this.portMap.neg}get cathode(){return this.portMap.cathode}};function inflateSourceLed(sourceElm,inflatorContext){let{injectionDb,subcircuit,groupsMap}=inflatorContext,pcbElm=injectionDb.pcb_component.getWhere({source_component_id:sourceElm.source_component_id}),cadElm=injectionDb.cad_component.getWhere({source_component_id:sourceElm.source_component_id}),{pcbX,pcbY}=getInflatedPcbPlacement({pcbComponent:pcbElm,sourceGroupId:sourceElm.source_group_id,inflatorContext}),led2=new Led({name:sourceElm.name,color:sourceElm.color,wavelength:sourceElm.wavelength??sourceElm.wave_length,layer:pcbElm?.layer,pcbX,pcbY,pcbRotation:pcbElm?.rotation,doNotPlace:pcbElm?.do_not_place,obstructsWithinBounds:pcbElm?.obstructs_within_bounds});if(pcbElm){let footprint=inflateFootprintComponent(pcbElm,{...inflatorContext,normalComponent:led2});footprint&&led2.add(footprint)}sourceElm.source_group_id&&groupsMap?.has(sourceElm.source_group_id)?groupsMap.get(sourceElm.source_group_id).add(led2):subcircuit.add(led2)}var possibleOrientations=[{gate:"left",drain:"top",source:"bottom"},{gate:"left",drain:"bottom",source:"top"},{gate:"right",drain:"top",source:"bottom"},{gate:"right",drain:"bottom",source:"top"},{gate:"top",drain:"left",source:"right"},{gate:"top",drain:"right",source:"left"},{gate:"bottom",drain:"left",source:"right"},{gate:"bottom",drain:"right",source:"left"}],getBaselineOrientation=rotation5=>{let normalizedRotation=(rotation5%360+360)%360;if(normalizedRotation%90!==0)throw new Error(`Schematic rotation ${rotation5} is not supported for Mosfet`);return[{gate:"left",drain:"top",source:"bottom"},{gate:"top",drain:"right",source:"left"},{gate:"right",drain:"bottom",source:"top"},{gate:"bottom",drain:"left",source:"right"}][normalizedRotation/90]},getRequestedOrientation=props=>{let requestedSides={drain:props.symbolDrainSide,source:props.symbolSourceSide,gate:props.symbolGateSide},baseline=getBaselineOrientation(Number(props.schRotation??0)),matchingOrientations=possibleOrientations.filter(orientation22=>Object.keys(requestedSides).every(portName=>requestedSides[portName]===void 0||requestedSides[portName]===orientation22[portName]));if(matchingOrientations.length===0){let requestedDescription=Object.entries(requestedSides).filter(([,side])=>side!==void 0).map(([portName,side])=>`${portName}=${side}`).join(", ");throw new Error(`Invalid MOSFET symbol port side combination (${requestedDescription}). The gate must be perpendicular to the drain and source, and the drain and source must be opposite.`)}return matchingOrientations.sort((a22,b22)=>{let score=orientation22=>Object.keys(baseline).filter(portName=>orientation22[portName]!==baseline[portName]).length;return score(a22)-score(b22)})[0]},getMosfetSchematicSymbolName=props=>{let mosfetMode=props.mosfetMode==="depletion"?"d":"e",baseSymbolName=`${props.channelType}_channel_${mosfetMode}_mosfet_transistor`;if(!(props.symbolDrainSide!==void 0||props.symbolSourceSide!==void 0||props.symbolGateSide!==void 0))return baseSymbolName;let{gate,drain}=getRequestedOrientation(props);return`${baseSymbolName}_gate_${gate}_drain_${drain}`},Mosfet2=class extends NormalComponent{get config(){return{componentName:"Mosfet",schematicSymbolName:this.props.symbolName??getMosfetSchematicSymbolName(this.props),zodProps:mosfetProps,shouldRenderAsSchematicBox:!1}}doInitialSourceRender(){let{db:db22}=this.root,{_parsedProps:props}=this,source_component=db22.source_component.insert({ftype:"simple_mosfet",name:this.name,manufacturer_part_number:resolveManufacturerPartNumber(props),supplier_part_numbers:props.supplierPartNumbers,mosfet_mode:props.mosfetMode,channel_type:props.channelType,display_name:props.displayName});this.source_component_id=source_component.source_component_id}};function inflateSourceMosfet(sourceElm,inflatorContext){let{injectionDb,subcircuit,groupsMap}=inflatorContext,pcbElm=injectionDb.pcb_component.getWhere({source_component_id:sourceElm.source_component_id}),{pcbX,pcbY}=getInflatedPcbPlacement({pcbComponent:pcbElm,sourceGroupId:sourceElm.source_group_id,inflatorContext}),mosfet=new Mosfet2({name:sourceElm.name,channelType:sourceElm.channel_type,mosfetMode:sourceElm.mosfet_mode,manufacturerPartNumber:sourceElm.manufacturer_part_number,supplierPartNumbers:sourceElm.supplier_part_numbers??void 0,displayName:sourceElm.display_name,layer:pcbElm?.layer,pcbX,pcbY,pcbRotation:pcbElm?.rotation,doNotPlace:pcbElm?.do_not_place,obstructsWithinBounds:pcbElm?.obstructs_within_bounds});if(pcbElm){let footprint=inflateFootprintComponent(pcbElm,{...inflatorContext,normalComponent:mosfet});footprint&&mosfet.add(footprint)}sourceElm.source_group_id&&groupsMap?.has(sourceElm.source_group_id)?groupsMap.get(sourceElm.source_group_id).add(mosfet):subcircuit.add(mosfet)}function inflateSourcePort(sourcePort,inflatorContext){let{injectionDb,subcircuit}=inflatorContext;if(sourcePort.source_component_id!==null)return;let pcbPortFromInjection=injectionDb.pcb_port.getWhere({source_port_id:sourcePort.source_port_id}),port=new Port({name:sourcePort.name,pinNumber:sourcePort.pin_number});subcircuit.add(port),port.source_port_id=sourcePort.source_port_id;let root=subcircuit.root;if(root&&pcbPortFromInjection){let{db:db22}=root,pcb_port3=db22.pcb_port.insert({pcb_component_id:void 0,layers:pcbPortFromInjection.layers,subcircuit_id:subcircuit.subcircuit_id??void 0,pcb_group_id:subcircuit.getGroup()?.pcb_group_id??void 0,x:pcbPortFromInjection.x,y:pcbPortFromInjection.y,source_port_id:sourcePort.source_port_id,is_board_pinout:!1});port.pcb_port_id=pcb_port3.pcb_port_id}}var PushButton=class extends NormalComponent{get config(){return{componentName:"PushButton",schematicSymbolName:this.props.symbolName??"push_button_normally_open_momentary",zodProps:pushButtonProps,sourceFtype:FTYPE.simple_push_button}}get defaultInternallyConnectedPinNames(){return[]}initPorts(){super.initPorts({pinCount:2,ignoreSymbolPorts:!0});let symbol=zh[this._getSchematicSymbolNameOrThrow()],symPort1=symbol.ports.find(p22=>p22.labels.includes("1")),symPort2=symbol.ports.find(p22=>p22.labels.includes("2")),ports=this.selectAll("port"),pin1Port=ports.find(port=>port.props.pinNumber===1);pin1Port.schematicSymbolPortDef=symPort1;let firstTerminalPorts=new Set(pin1Port._getPortsInternallyConnectedToThisPort()),secondTerminalPort=ports.filter(port=>port!==pin1Port&&!firstTerminalPorts.has(port)).sort((a22,b22)=>(a22.props.pinNumber??0)-(b22.props.pinNumber??0))[0];secondTerminalPort&&(secondTerminalPort.schematicSymbolPortDef=symPort2)}doInitialSourceRender(){let{db:db22}=this.root,{_parsedProps:props}=this,source_component=db22.source_component.insert({name:this.name,ftype:FTYPE.simple_push_button,supplier_part_numbers:props.supplierPartNumbers,manufacturer_part_number:resolveManufacturerPartNumber(props),are_pins_interchangeable:!0,display_name:props.displayName});this.source_component_id=source_component.source_component_id}};function inflateSourcePushButton(sourceElm,inflatorContext){let{injectionDb,subcircuit,groupsMap}=inflatorContext,pcbElm=injectionDb.pcb_component.getWhere({source_component_id:sourceElm.source_component_id}),cadElm=injectionDb.cad_component.getWhere({source_component_id:sourceElm.source_component_id}),{pcbX,pcbY}=getInflatedPcbPlacement({pcbComponent:pcbElm,sourceGroupId:sourceElm.source_group_id,inflatorContext}),pushButton=new PushButton({name:sourceElm.name,layer:pcbElm?.layer,pcbX,pcbY,pcbRotation:pcbElm?.rotation,doNotPlace:pcbElm?.do_not_place,obstructsWithinBounds:pcbElm?.obstructs_within_bounds});if(pcbElm){let footprint=inflateFootprintComponent(pcbElm,{...inflatorContext,normalComponent:pushButton});footprint&&pushButton.add(footprint)}sourceElm.source_group_id&&groupsMap?.has(sourceElm.source_group_id)?groupsMap.get(sourceElm.source_group_id).add(pushButton):subcircuit.add(pushButton)}var Resistor2=class extends NormalComponent{constructor(){super(...arguments);__publicField(this,"_adjustSilkscreenTextAutomatically",!0)}get config(){let baseSymbolName=this.props.symbolName??"boxresistor",compactSize=this.props.schSize==="sm"||this.props.schSize==="xs"?this.props.schSize:void 0,compactSymbolName=compactSize&&(baseSymbolName==="boxresistor"||baseSymbolName==="resistor")?`${baseSymbolName}_${compactSize}`:void 0;return{componentName:"Resistor",schematicSymbolName:compactSymbolName&&`${compactSymbolName}_right`in zh?compactSymbolName:baseSymbolName,zodProps:resistorProps,sourceFtype:"simple_resistor"}}initPorts(){super.initPorts({additionalAliases:{pin1:["anode","pos","left"],pin2:["cathode","neg","right"]}})}_getSchematicSymbolDisplayValue(){return`${formatSiUnit(this._parsedProps.resistance)}\u03A9`}doInitialCreateNetsFromProps(){this._createNetsFromProps([this.props.pullupFor,this.props.pullupTo,this.props.pulldownFor,this.props.pulldownTo,...this._getNetsFromConnectionsProp()])}doInitialCreateTracesFromProps(){this.props.pullupFor&&this.props.pullupTo&&(this.add(new Trace({from:`${this.getSubcircuitSelector()} > port.1`,to:this.props.pullupFor})),this.add(new Trace({from:`${this.getSubcircuitSelector()} > port.2`,to:this.props.pullupTo}))),this.props.pulldownFor&&this.props.pulldownTo&&(this.add(new Trace({from:`${this.getSubcircuitSelector()} > port.1`,to:this.props.pulldownFor})),this.add(new Trace({from:`${this.getSubcircuitSelector()} > port.2`,to:this.props.pulldownTo}))),this._createTracesFromConnectionsProp()}doInitialSourceRender(){let{db:db22}=this.root,{_parsedProps:props}=this,source_component=db22.source_component.insert({ftype:"simple_resistor",name:this.name,manufacturer_part_number:resolveManufacturerPartNumber(props),supplier_part_numbers:props.supplierPartNumbers,resistance:props.resistance,display_resistance:this._getSchematicSymbolDisplayValue(),are_pins_interchangeable:!0,display_name:props.displayName});this.source_component_id=source_component.source_component_id}};function inflateSourceResistor(sourceElm,inflatorContext){let{injectionDb,subcircuit,groupsMap}=inflatorContext,pcbElm=injectionDb.pcb_component.getWhere({source_component_id:sourceElm.source_component_id}),cadElm=injectionDb.cad_component.getWhere({source_component_id:sourceElm.source_component_id}),{pcbX,pcbY}=getInflatedPcbPlacement({pcbComponent:pcbElm,sourceGroupId:sourceElm.source_group_id,inflatorContext}),resistor=new Resistor2({name:sourceElm.name,resistance:sourceElm.resistance,layer:pcbElm?.layer,pcbX,pcbY,pcbRotation:pcbElm?.rotation,doNotPlace:pcbElm?.do_not_place,obstructsWithinBounds:pcbElm?.obstructs_within_bounds});if(pcbElm){let footprint=inflateFootprintComponent(pcbElm,{...inflatorContext,normalComponent:resistor});footprint&&resistor.add(footprint)}sourceElm.source_group_id&&groupsMap?.has(sourceElm.source_group_id)?groupsMap.get(sourceElm.source_group_id).add(resistor):subcircuit.add(resistor)}function hasSimProps(props){return props.simSwitchFrequency!==void 0||props.simCloseAt!==void 0||props.simOpenAt!==void 0||props.simStartClosed!==void 0||props.simStartOpen!==void 0}var Switch=class extends NormalComponent{_getSwitchType(){let props=this._parsedProps;return props?props.dpdt?"dpdt":props.spst?"spst":props.spdt?"spdt":props.dpst?"dpst":props.type??"spst":"spst"}get config(){let switchType=this._getSwitchType(),isNormallyClosed=this._parsedProps?.isNormallyClosed??!1,symbolMap={spst:isNormallyClosed?"spst_normally_closed_switch":"spst_switch",spdt:isNormallyClosed?"spdt_normally_closed_switch":"spdt_switch",dpst:isNormallyClosed?"dpst_normally_closed_switch":"dpst_switch",dpdt:isNormallyClosed?"dpdt_normally_closed_switch":"dpdt_switch"};return{componentName:"Switch",schematicSymbolName:this.props.symbolName??symbolMap[switchType],zodProps:switchProps,shouldRenderAsSchematicBox:!1}}doInitialSourceRender(){let{db:db22}=this.root,props=this._parsedProps??{},source_component=db22.source_component.insert({ftype:"simple_switch",name:this.name,manufacturer_part_number:resolveManufacturerPartNumber(props),supplier_part_numbers:props.supplierPartNumbers,are_pins_interchangeable:this._getSwitchType()==="spst",display_name:props?.displayName});this.source_component_id=source_component.source_component_id}doInitialSimulationRender(){let{_parsedProps:props}=this;if(!hasSimProps(props))return;let{db:db22}=this.root,simulationSwitch={type:"simulation_switch",source_component_id:this.source_component_id||""};props.simSwitchFrequency!==void 0&&(simulationSwitch.switching_frequency=frequency.parse(props.simSwitchFrequency)),props.simCloseAt!==void 0&&(simulationSwitch.closes_at=ms.parse(props.simCloseAt)),props.simOpenAt!==void 0&&(simulationSwitch.opens_at=ms.parse(props.simOpenAt)),props.simStartOpen!==void 0&&(simulationSwitch.starts_closed=!props.simStartOpen),props.simStartClosed!==void 0&&(simulationSwitch.starts_closed=props.simStartClosed),db22.simulation_switch.insert(simulationSwitch)}},getImportedSwitchProps=(sourceElm,inflatorContext)=>{let sourcePorts=inflatorContext.injectionDb.source_port.list().filter(port=>port.source_component_id===sourceElm.source_component_id),pinLabels={},highestPinNumber=0;for(let sourcePort of sourcePorts){let pinNumber=sourcePort.pin_number;if(pinNumber==null)continue;highestPinNumber=Math.max(highestPinNumber,pinNumber);let labels=Array.from(new Set([sourcePort.name,...sourcePort.port_hints??[]].filter(label=>typeof label=="string"&&label.length>0)));labels.length>0&&(pinLabels[`pin${pinNumber}`]=labels)}let type="spst";return highestPinNumber>=5?type="dpdt":highestPinNumber===4?type="dpst":highestPinNumber===3&&(type="spdt"),{type,pinLabels:Object.keys(pinLabels).length>0?pinLabels:void 0}};function inflateSourceSwitch(sourceElm,inflatorContext){let{injectionDb,subcircuit,groupsMap}=inflatorContext,pcbElm=injectionDb.pcb_component.getWhere({source_component_id:sourceElm.source_component_id}),{pcbX,pcbY}=getInflatedPcbPlacement({pcbComponent:pcbElm,sourceGroupId:sourceElm.source_group_id,inflatorContext}),importedSwitchProps=getImportedSwitchProps(sourceElm,inflatorContext),switchComponent=new Switch({name:sourceElm.name,displayName:sourceElm.display_name,...importedSwitchProps,layer:pcbElm?.layer,pcbX,pcbY,pcbRotation:pcbElm?.rotation,doNotPlace:pcbElm?.do_not_place,obstructsWithinBounds:pcbElm?.obstructs_within_bounds});if(pcbElm){let footprint=inflateFootprintComponent(pcbElm,{...inflatorContext,normalComponent:switchComponent});footprint&&switchComponent.add(footprint)}sourceElm.source_group_id&&groupsMap?.has(sourceElm.source_group_id)?groupsMap.get(sourceElm.source_group_id).add(switchComponent):subcircuit.add(switchComponent)}function pcbTraceRouteToPcbPath(route2){if(route2.length<=2)return[];let firstPoint=route2[0],lastPoint=route2[route2.length-1];return route2.slice(1,-1).filter(point62=>{let position4=getRoutePointPosition(point62),firstPosition=getRoutePointPosition(firstPoint),lastPosition=getRoutePointPosition(lastPoint),isSameAsFirst=position4.x===firstPosition.x&&position4.y===firstPosition.y,isSameAsLast=position4.x===lastPosition.x&&position4.y===lastPosition.y;return!isSameAsFirst&&!isSameAsLast}).map(point62=>{if(point62.route_type==="via")return{x:point62.x,y:point62.y,via:!0,fromLayer:point62.from_layer,toLayer:point62.to_layer};let position4=getRoutePointPosition(point62);return{x:position4.x,y:position4.y}})}var getSelectorPath=(component,inflatorContext)=>{let{injectionDb,subcircuit,groupsMap}=inflatorContext,path_parts=[],currentGroupId=component.source_group_id;for(;currentGroupId&&currentGroupId!==subcircuit.source_group_id;){let sourceGroup=injectionDb.source_group.get(currentGroupId),groupInstance=groupsMap?.get(currentGroupId);if(!sourceGroup||!groupInstance)break;let groupName=groupInstance.props.name??groupInstance.fallbackUnassignedName;path_parts.unshift(`.${groupName}`),currentGroupId=sourceGroup.parent_source_group_id}return path_parts.push(`.${component.name}`),path_parts.join(" > ")};function inflateSourceTrace(sourceTrace,inflatorContext){let{injectionDb,subcircuit}=inflatorContext,connectedSelectors=[];for(let sourcePortId of sourceTrace.connected_source_port_ids){let sourcePort=injectionDb.source_port.get(sourcePortId);if(!sourcePort)continue;let selector2;if(sourcePort.source_component_id){let sourceComponent=injectionDb.source_component.get(sourcePort.source_component_id);sourceComponent&&(selector2=`${getSelectorPath({name:sourceComponent.name,source_group_id:sourceComponent.source_group_id},inflatorContext)} > .${sourcePort.name}`)}else selector2=`.${sourcePort.name}`;selector2&&connectedSelectors.push(selector2)}for(let sourceNetId of sourceTrace.connected_source_net_ids){let sourceNet=injectionDb.source_net.get(sourceNetId);sourceNet&&connectedSelectors.push(`net.${sourceNet.name}`)}if(connectedSelectors.length<2)return;let pcbTraces=injectionDb.pcb_trace.list().filter(trace2=>trace2.source_trace_id===sourceTrace.source_trace_id),pcbTrace=pcbTraces[0],pcbPath3;pcbTrace&&(pcbPath3=pcbTraceRouteToPcbPath(pcbTrace.route));let traceWidth=sourceTrace.min_trace_thickness;if(!traceWidth&&pcbTrace?.route){let wirePoint=pcbTrace.route.find(pt22=>pt22.route_type==="wire");wirePoint&&wirePoint.route_type==="wire"&&(traceWidth=wirePoint.width)}let traceProps22={path:connectedSelectors};traceWidth!==void 0&&(traceProps22.thickness=traceWidth),pcbPath3&&pcbPath3.length>0?traceProps22.pcbPath=pcbPath3:!pcbTrace&&sourceTrace.connected_source_port_ids.length===2&&sourceTrace.connected_source_net_ids.length===0&&(traceProps22.pcbStraightLine=!0);let trace=new Trace(traceProps22);trace._inflatedPcbTraces=pcbTraces.length>0?pcbTraces:void 0,trace._inflatedPcbVias=pcbTrace?injectionDb.pcb_via.list().filter(via=>pcbTraces.some(trace2=>via.pcb_trace_id===trace2.pcb_trace_id)):void 0,subcircuit.add(trace)}var SHORT_ALIASES={collector:["c"],base:["b"],emitter:["e"]},Transistor=class extends NormalComponent{get config(){let baseSymbolName=this.props.type==="npn"?"npn_bipolar_transistor":"pnp_bipolar_transistor";return{componentName:"Transistor",schematicSymbolName:this.props.symbolName??baseSymbolName,zodProps:transistorProps,sourceFtype:"simple_transistor",shouldRenderAsSchematicBox:!1}}initPorts(){let additionalAliases={},symbol=this.getSchematicSymbol();for(let symPort of symbol?.ports??[]){let pinNumber=getPinNumberFromLabels(symPort.labels);if(pinNumber)for(let label of symPort.labels){let shortAliases=SHORT_ALIASES[label];shortAliases&&(additionalAliases[`pin${pinNumber}`]=shortAliases)}}super.initPorts({pinCount:3,additionalAliases})}get collector(){return this.portMap.collector}get base(){return this.portMap.base}get emitter(){return this.portMap.emitter}doInitialCreateNetsFromProps(){this._createNetsFromProps([...this._getNetsFromConnectionsProp()])}doInitialCreateTracesFromProps(){this._createTracesFromConnectionsProp()}doInitialSourceRender(){let{db:db22}=this.root,{_parsedProps:props}=this,source_component=db22.source_component.insert({ftype:"simple_transistor",name:this.name,manufacturer_part_number:resolveManufacturerPartNumber(props),supplier_part_numbers:props.supplierPartNumbers,transistor_type:props.type,display_name:props.displayName});this.source_component_id=source_component.source_component_id}};function inflateSourceTransistor(sourceElm,inflatorContext){let{injectionDb,subcircuit,groupsMap}=inflatorContext,pcbElm=injectionDb.pcb_component.getWhere({source_component_id:sourceElm.source_component_id}),cadElm=injectionDb.cad_component.getWhere({source_component_id:sourceElm.source_component_id}),{pcbX,pcbY}=getInflatedPcbPlacement({pcbComponent:pcbElm,sourceGroupId:sourceElm.source_group_id,inflatorContext}),transistor=new Transistor({name:sourceElm.name,type:sourceElm.transistor_type,layer:pcbElm?.layer,pcbX,pcbY,pcbRotation:pcbElm?.rotation,doNotPlace:pcbElm?.do_not_place,obstructsWithinBounds:pcbElm?.obstructs_within_bounds});if(pcbElm){let footprint=inflateFootprintComponent(pcbElm,{...inflatorContext,normalComponent:transistor});footprint&&transistor.add(footprint)}sourceElm.source_group_id&&groupsMap?.has(sourceElm.source_group_id)?groupsMap.get(sourceElm.source_group_id).add(transistor):subcircuit.add(transistor)}function inflateStandalonePcbPrimitives(inflatorContext){let{injectionDb,subcircuit,groupsMap}=inflatorContext,standalonePrimitiveTypes=["pcb_silkscreen_rect","pcb_silkscreen_circle","pcb_silkscreen_line","pcb_silkscreen_path","pcb_silkscreen_text","pcb_fabrication_note_text","pcb_fabrication_note_path","pcb_fabrication_note_rect","pcb_note_text","pcb_note_rect","pcb_note_path","pcb_note_line","pcb_via","pcb_hole","pcb_plated_hole","pcb_cutout","pcb_soldermask_opening"],standalonePrimitives=injectionDb.toArray().filter(elm=>{if(!standalonePrimitiveTypes.includes(elm.type))return!1;if(elm.type==="pcb_via"){if(!elm.pcb_trace_id)return!0;let pcbTrace=injectionDb.pcb_trace.get(elm.pcb_trace_id),sourceTraceId=pcbTrace?.source_trace_id;return!(sourceTraceId&&injectionDb.source_trace.get(sourceTraceId)&&pcbTrace?.route.some(point62=>point62.route_type==="via"&&Math.abs(point62.x-elm.x)<1e-4&&Math.abs(point62.y-elm.y)<1e-4))}return elm.type==="pcb_cutout"?!0:elm.type==="pcb_soldermask_opening"?elm.pcb_component_id===void 0:"pcb_component_id"in elm&&(elm.pcb_component_id===null||elm.pcb_component_id===void 0)});if(standalonePrimitives.length===0)return;let components=createComponentsFromCircuitJson({componentName:"",componentRotation:"0deg"},standalonePrimitives);for(let component of components)subcircuit.add(component)}var inflateCircuitJson=(target,circuitJson,children)=>{if(!circuitJson)return;let injectionDb=cju_default(circuitJson);if(circuitJson&&children?.length>0)throw new Error("Component cannot have both circuitJson and children");let inflationCtx={injectionDb,subcircuit:target,groupsMap:new Map},sourceGroups=injectionDb.source_group.list(),renderedGroupIds=new Set,groupsToRender=[...sourceGroups];for(;groupsToRender.length>0;){let groupIndex=groupsToRender.findIndex(g22=>!g22.parent_source_group_id||renderedGroupIds.has(g22.parent_source_group_id));if(groupIndex===-1){let remainingIds=groupsToRender.map(g22=>g22.source_group_id).join(", ");throw new Error(`Cannot inflate source_groups: cyclic dependency or missing parent detected. Remaining groups: ${remainingIds}`)}let groupToRender=groupsToRender[groupIndex];inflateSourceGroup(groupToRender,inflationCtx),renderedGroupIds.add(groupToRender.source_group_id),groupsToRender.splice(groupIndex,1)}let pcbBoards=injectionDb.pcb_board.list();for(let pcbBoard of pcbBoards)inflatePcbBoard(pcbBoard,inflationCtx);let sourceComponents=injectionDb.source_component.list();for(let sourceComponent of sourceComponents)switch(sourceComponent.ftype){case"simple_resistor":inflateSourceResistor(sourceComponent,inflationCtx);break;case"simple_capacitor":inflateSourceCapacitor(sourceComponent,inflationCtx);break;case"simple_inductor":inflateSourceInductor(sourceComponent,inflationCtx);break;case"simple_diode":inflateSourceDiode(sourceComponent,inflationCtx);break;case"simple_fiducial":inflateSourceFiducial(sourceComponent,inflationCtx);break;case"simple_led":inflateSourceLed(sourceComponent,inflationCtx);break;case"simple_chip":inflateSourceChip(sourceComponent,inflationCtx);break;case"simple_connector":inflateSourceConnector(sourceComponent,inflationCtx);break;case"simple_transistor":inflateSourceTransistor(sourceComponent,inflationCtx);break;case"simple_mosfet":inflateSourceMosfet(sourceComponent,inflationCtx);break;case"simple_push_button":inflateSourcePushButton(sourceComponent,inflationCtx);break;case"simple_switch":inflateSourceSwitch(sourceComponent,inflationCtx);break;default:throw new Error(`No inflator implemented for source component ftype: "${sourceComponent.ftype}"`)}let sourcePorts=injectionDb.source_port.list();for(let sourcePort of sourcePorts)inflateSourcePort(sourcePort,inflationCtx);let sourceTraces=injectionDb.source_trace.list();for(let sourceTrace of sourceTraces)inflateSourceTrace(sourceTrace,inflationCtx);inflateStandalonePcbPrimitives(inflationCtx)},resolveBoardMotorMount=board=>{if(boardMountsToPrintedPart(board)){resolvePrintedPartMounts(board);return}let{mountedTo,mountRotation,mountRotationAnchor,mountOrientation}=board._parsedProps;if(!mountedTo){if(mountRotation||mountRotationAnchor||mountOrientation)throw new Error(`board "${board.name}" mounting alignment requires mountedTo`);return}let separator=mountedTo.lastIndexOf("."),motorName=mountedTo.slice(0,separator),face=mountedTo.slice(separator+1);if(separator<1||face!=="backface")throw new Error(`board "${board.name}" mountedTo "${mountedTo}" must name a motor backface, e.g. "NEMA17.backface"`);let motors=getComponentsInAssemblyScope(board).filter(motor2=>motor2.componentName==="AssemblyMotor"&&matchesAssemblyIdentity(motor2,motorName));if(motors.length!==1)throw new Error(`board "${board.name}" mountedTo "${mountedTo}" matched ${motors.length} motors; expected exactly one in the assembly device`);let motor=motors[0];if(motor._parsedProps.mountedTo){resolvePrintedPartMounts(board);return}let direction3=motor._parsedProps.shaftFacingDirection;if(direction3!=="z+"&&direction3!=="z-")throw new Error(`board "${board.name}" cannot mount to motor "${motorName}" facing ${direction3}: rotated PCB boards are not yet supported; use shaftFacingDirection="z+" or "z-"`);if(mountRotationAnchor&&!mountRotation)throw new Error(`board "${board.name}" mountRotationAnchor requires mountRotation`);if(motor.props.shaftFacingDirection&&mountOrientation&&mountOrientation!==(direction3==="z+"?"top_layer_toward_mount_face":"bottom_layer_toward_mount_face"))throw new Error(`board "${board.name}" mountOrientation "${mountOrientation}" conflicts with motor "${motorName}" shaftFacingDirection "${direction3}"`);return motor},resolveMotorMountedBoard=motor=>{let boards=getComponentsInAssemblyScope(motor).filter(board=>board.componentName==="Board").filter(board=>resolveBoardMotorMount(board)===motor);if(boards.length>1)throw new Error(`assembly.motor "${motor.name}" has multiple mounted boards; only one board may determine its placement`);return boards[0]};function createCircuitJsonDatabase(){if(typeof cju_indexed_default!="function")return cju_default([]);let indexed=cju_indexed_default([],{indexConfig:{byId:!0,byType:!0}});return typeof indexed.insert!="function"||typeof indexed.insertAll!="function"||typeof indexed.subtree!="function"?cju_default([]):indexed}var IsolatedCircuit=class{constructor({platform,projectUrl,cachedSubcircuits,pendingSubcircuitRenders}={}){__publicField(this,"firstChild",null);__publicField(this,"children");__publicField(this,"db");__publicField(this,"root",null);__publicField(this,"isRootCircuit",!1);__publicField(this,"cachedSubcircuits");__publicField(this,"pendingSubcircuitRenders");__publicField(this,"_schematicDisabledOverride");__publicField(this,"pcbDisabled",!1);__publicField(this,"pcbRoutingDisabled",!1);__publicField(this,"_featureMspSchematicTraceRouting",!0);__publicField(this,"_featurePcbViaStitching",!0);__publicField(this,"name");__publicField(this,"platform");__publicField(this,"projectUrl");__publicField(this,"_hasRenderedAtleastOnce",!1);__publicField(this,"_asyncEffectIdsByPhase",new Map);__publicField(this,"_asyncEffectPhaseById",new Map);__publicField(this,"_hasUnrenderedUpdatesFromAsyncEffects",!1);__publicField(this,"_runningAsyncEffectsById",new Map);__publicField(this,"_hasRenderLifecycleListeners",!1);__publicField(this,"_eventListeners",{});this.children=[],this.db=createCircuitJsonDatabase(),this.platform=platform,this.projectUrl=projectUrl,this.pcbDisabled=platform?.pcbDisabled??!1,this.pcbRoutingDisabled=platform?.routingDisabled??!1,this.cachedSubcircuits=cachedSubcircuits,this.pendingSubcircuitRenders=pendingSubcircuitRenders,this.root=this}get schematicDisabled(){return this._schematicDisabledOverride!==void 0?this._schematicDisabledOverride:this.platform?.schematicDisabled!==void 0?this.platform.schematicDisabled:this._getBoard()?._parsedProps?.schematicDisabled??!1}set schematicDisabled(value){this._schematicDisabledOverride=value}add(componentOrElm){let component;(0,import_react10.isValidElement)(componentOrElm)?component=createInstanceFromReactElement(componentOrElm):component=componentOrElm,this.children.push(component)}setPlatform(platform){this.platform={...this.platform,...platform},platform.pcbDisabled!==void 0&&(this.pcbDisabled=platform.pcbDisabled),platform.routingDisabled!==void 0&&(this.pcbRoutingDisabled=platform.routingDisabled)}_getBoard(){let findBoard=components=>{for(let child of components){if(child.componentName==="Board")return child;if(isAssemblyDeviceContainer(child)){let nested=findBoard(child.children);if(nested)return nested}}};return findBoard(this.children)}_guessRootComponent(){if(this.firstChild)return;if(this.children.length===0)throw new Error("Not able to guess root component: IsolatedCircuit has no children (use circuit.add(...))");let panels=this.children.filter(child=>child.lowercaseComponentName==="panel");if(panels.length>1)throw new Error("Only one <panel> is allowed per circuit");if(panels.length===1){if(this.children.length!==1)throw new Error("<panel> must be the root element of the circuit");this.firstChild=panels[0];return}if(this.children.length===1&&(this.children[0].isGroup||isAssemblyDeviceContainer(this.children[0]))){this.firstChild=this.children[0];return}let group2=new Group5({subcircuit:!0});group2.parent=this,group2.addAll(this.children),this.children=[group2],this.firstChild=group2}render(){this.firstChild||this._guessRootComponent();let{firstChild,db:db22}=this;if(!firstChild)throw new Error("IsolatedCircuit has no root component");firstChild.parent=this,firstChild.runRenderCycle(),this._hasUnrenderedUpdatesFromAsyncEffects=!1,this._hasRenderedAtleastOnce=!0}async renderUntilSettled(){for(this.db.source_project_metadata.list()?.[0]||this.db.source_project_metadata.insert({software_used_string:`@tscircuit/core@${this.getCoreVersion()}`,...this.projectUrl?{project_url:this.projectUrl}:{}}),this.render();!this.isDoneRendering();)await new Promise(resolve7=>{let resume=()=>{clearTimeout(timer),this.removeListener("asyncEffect:end",resume),resolve7()},timer=setTimeout(resume,100);this.on("asyncEffect:end",resume),this._hasUnrenderedUpdatesFromAsyncEffects&&resume()}),(this._hasUnrenderedUpdatesFromAsyncEffects||this._asyncEffectPhaseById.size===0)&&this.render();this.emit("renderComplete")}isDoneRendering(){return this._hasRenderedAtleastOnce&&!this._hasIncompleteAsyncEffects()}_hasIncompleteAsyncEffects(){return this._asyncEffectPhaseById.size>0||this._hasUnrenderedUpdatesFromAsyncEffects?!0:this.children.some(child=>child._hasIncompleteAsyncEffects())}_hasIncompleteAsyncEffectsForPhase(phase){return(this._asyncEffectIdsByPhase.get(phase)?.size??0)>0}getRunningAsyncEffects(){return Array.from(this._runningAsyncEffectsById.values())}getCircuitJson(){return this._hasRenderedAtleastOnce||this.render(),this.db.toArray()}toJson(){return this.getCircuitJson()}async getSvg(options){let circuitToSvg=await Promise.resolve().then(()=>(init_dist9(),dist_exports4)).catch(e210=>{throw new Error(`To use circuit.getSvg, you must install the "circuit-to-svg" package.
953
953
 
954
954
  "${e210.message}"`)});if(options.view==="pcb")return circuitToSvg.convertCircuitJsonToPcbSvg(this.getCircuitJson());if(options.view==="schematic")return circuitToSvg.convertCircuitJsonToSchematicSvg(this.getCircuitJson());throw new Error(`Invalid view: ${options.view}`)}getCoreVersion(){let[major,minor,patch]=package_default3.version.split(".").map(Number);return`${major}.${minor}.${patch+1}`}async preview(previewNameOrOpts){let previewOpts=typeof previewNameOrOpts=="object"?previewNameOrOpts:{previewName:previewNameOrOpts};throw new Error("project.preview is not yet implemented")}computeSchematicGlobalTransform(){return identity()}_computePcbGlobalTransformBeforeLayout(){return identity()}selectAll(selector2){return this._guessRootComponent(),this.firstChild?.selectAll(selector2)??[]}selectOne(selector2,opts){return this._guessRootComponent(),this.firstChild?.selectOne(selector2,opts)??null}emit(event,...args){if(event==="asyncEffect:start"?this._registerAsyncEffectStart(args[0]):event==="asyncEffect:end"&&this._registerAsyncEffectEnd(args[0]),!!this._eventListeners[event])for(let listener of this._eventListeners[event])listener(...args)}hasEventListener(event){return(this._eventListeners[event]?.length??0)>0}on(event,listener){this._eventListeners[event]||(this._eventListeners[event]=[]),this._eventListeners[event].push(listener),event.startsWith("renderable:renderLifecycle:")&&(this._hasRenderLifecycleListeners=!0)}removeListener(event,listener){this._eventListeners[event]&&(this._eventListeners[event]=this._eventListeners[event].filter(l22=>l22!==listener),event.startsWith("renderable:renderLifecycle:")&&(this._hasRenderLifecycleListeners=Object.entries(this._eventListeners).some(([eventName,listeners])=>eventName.startsWith("renderable:renderLifecycle:")&&listeners.length>0)))}enableDebug(debug132){typeof debug132=="string"?import_debug21.default.enable(debug132):(debug132===null||debug132===!1)&&import_debug21.default.disable()}getClientOrigin(){return typeof window<"u"&&window.location?window.location.origin:typeof self<"u"&&self.location?self.location.origin:""}_registerAsyncEffectStart(payload){if(!payload?.asyncEffectId||!payload.phase)return;let{asyncEffectId,phase}=payload,existingPhase=this._asyncEffectPhaseById.get(asyncEffectId);existingPhase&&existingPhase!==phase&&this._asyncEffectIdsByPhase.get(existingPhase)?.delete(asyncEffectId),this._asyncEffectIdsByPhase.has(phase)||this._asyncEffectIdsByPhase.set(phase,new Set),this._asyncEffectIdsByPhase.get(phase).add(asyncEffectId),this._asyncEffectPhaseById.set(asyncEffectId,phase),this._runningAsyncEffectsById.set(asyncEffectId,{asyncEffectId,effectName:payload.effectName,componentDisplayName:payload.componentDisplayName,phase,error:payload.error})}_registerAsyncEffectEnd(payload){if(!payload?.asyncEffectId)return;let{asyncEffectId}=payload,phase=this._asyncEffectPhaseById.get(asyncEffectId)??payload.phase;if(phase){let phaseSet=this._asyncEffectIdsByPhase.get(phase);phaseSet?.delete(asyncEffectId),phaseSet&&phaseSet.size===0&&this._asyncEffectIdsByPhase.delete(phase)}this._asyncEffectPhaseById.delete(asyncEffectId),this._runningAsyncEffectsById.delete(asyncEffectId),this._hasUnrenderedUpdatesFromAsyncEffects=!0}};function Subcircuit_doInitialRenderIsolatedSubcircuits(subcircuit){if(!subcircuit._isIsolatedSubcircuit||subcircuit._isolatedCircuitJson||!subcircuit.getSubcircuitPropHash)return;let propHash=subcircuit.getSubcircuitPropHash(),cachedSubcircuits=subcircuit.root?.cachedSubcircuits,pendingSubcircuitRenders=subcircuit.root?.pendingSubcircuitRenders,cached=cachedSubcircuits?.get(propHash);if(cached){subcircuit._isolatedCircuitJson=cached,subcircuit.children=[],subcircuit._normalComponentNameMap=null;return}let childrenToRender=[...subcircuit.children];subcircuit.children=[],subcircuit._normalComponentNameMap=null;let parentRoot=subcircuit.root;subcircuit._queueAsyncEffect("render-isolated-subcircuit",async()=>{let cachedResult=cachedSubcircuits?.get(propHash);if(cachedResult){subcircuit._isolatedCircuitJson=cachedResult;return}let pendingRenderPromise=pendingSubcircuitRenders?.get(propHash);if(pendingRenderPromise){subcircuit._isolatedCircuitJson=await pendingRenderPromise;return}let resolveRender,rejectRender,renderPromise=new Promise((resolve7,reject)=>{resolveRender=resolve7,rejectRender=reject});pendingSubcircuitRenders?.set(propHash,renderPromise);try{let isolatedCircuit=new IsolatedCircuit({platform:{...parentRoot.platform,pcbDisabled:parentRoot.pcbDisabled,schematicDisabled:parentRoot.schematicDisabled},cachedSubcircuits,pendingSubcircuitRenders});for(let child of childrenToRender)isolatedCircuit.add(child);await isolatedCircuit.renderUntilSettled();let circuitJson=isolatedCircuit.getCircuitJson();cachedSubcircuits?.set(propHash,circuitJson),subcircuit._isolatedCircuitJson=circuitJson,resolveRender(circuitJson)}catch(error2){throw rejectRender(error2 instanceof Error?error2:new Error(String(error2))),error2}finally{pendingSubcircuitRenders?.delete(propHash)}})}var EXCLUDED_PROPS=new Set(["name","key","pcbX","pcbY","schX","schY","pcbLeftEdgeX","pcbRightEdgeX","pcbTopEdgeY","pcbBottomEdgeY","pcbRotation","schRotation"]);function safeSerialize(value,seen=new WeakSet){if(value===null)return"null";if(value===void 0)return"undefined";let type=typeof value;if(type==="string")return`"${value}"`;if(type==="number"||type==="boolean")return String(value);if(type==="function")return"[function]";if(type==="symbol")return"[symbol]";if(type==="object"){if(seen.has(value))return"[circular]";if(seen.add(value),value.$$typeof!==void 0){let elementType=typeof value.type=="string"?value.type:value.type?.name||"[component]",propsStr=value.props?safeSerialize(value.props,seen):"{}";return`ReactElement(${elementType},${propsStr})`}return Array.isArray(value)?`[${value.map(v22=>safeSerialize(v22,seen)).join(",")}]`:`{${Object.keys(value).sort().map(k22=>`${k22}:${safeSerialize(value[k22],seen)}`).join(",")}}`}return String(value)}function getHashableProps(props){let result={},keys=Object.keys(props).sort();for(let key of keys)!EXCLUDED_PROPS.has(key)&&props[key]!==void 0&&(result[key]=props[key]);return result}function getChildrenHashData(children){return children.map(child=>({componentName:child.componentName,props:getHashableProps(child.props??{}),children:getChildrenHashData(child.children)}))}function fnv1aHash(str10){let hash=2166136261;for(let i22=0;i22<str10.length;i22++)hash^=str10.charCodeAt(i22),hash=Math.imul(hash,16777619);return hash>>>0}function computeHash(data){let serialized=safeSerialize(data),hash1=fnv1aHash(serialized),hash2=fnv1aHash(serialized+hash1.toString());return hash1.toString(16).padStart(8,"0")+hash2.toString(16).padStart(8,"0")}function Subcircuit_getSubcircuitPropHash(subcircuit){let hashableData={props:getHashableProps(subcircuit.props??{}),children:getChildrenHashData(subcircuit.children)};return computeHash(hashableData)}var Board_updatePcbDesignRuleChecks=board=>{let{db:db22}=board.root,routingDisabled=board.root?.pcbRoutingDisabled||board.getInheritedProperty("routingDisabled"),pcbDisabled=board.root?.pcbDisabled,schematicDisabled=board.root?.schematicDisabled,drcChecksDisabled=board.root?.platform?.drcChecksDisabled??board.getInheritedProperty("drcChecksDisabled");if(drcChecksDisabled){board._drcChecksComplete=!0;return}let netlistDrcChecksDisabled=board.root?.platform?.netlistDrcChecksDisabled??board.getInheritedProperty("netlistDrcChecksDisabled"),placementDrcChecksDisabled=board.root?.platform?.placementDrcChecksDisabled??board.getInheritedProperty("placementDrcChecksDisabled"),routingDrcChecksDisabled=board.root?.platform?.routingDrcChecksDisabled??board.getInheritedProperty("routingDrcChecksDisabled"),shouldRunNetlistChecks=!drcChecksDisabled&&!netlistDrcChecksDisabled,shouldRunSchematicChecks=!drcChecksDisabled&&!schematicDisabled,shouldRunPlacementChecks=!drcChecksDisabled&&!pcbDisabled&&!placementDrcChecksDisabled,shouldRunRoutingChecks=!drcChecksDisabled&&!pcbDisabled&&!routingDisabled&&!routingDrcChecksDisabled,fabricatorEngine4=board.root?.platform?.fabricatorEngine,fabricatorPreset=board._parsedProps.fabricatorPreset,shouldRunFabricatorChecks=!drcChecksDisabled&&!pcbDisabled&&!!fabricatorEngine4&&!!fabricatorPreset;if((shouldRunRoutingChecks||shouldRunFabricatorChecks)&&board._hasIncompleteAsyncEffectsInSubtreeForPhase("PcbTraceRender"))return;let hasTracesToRoute=board._hasTracesToRoute();if((shouldRunRoutingChecks||shouldRunFabricatorChecks)&&hasTracesToRoute&&!board._areChildSubcircuitsRouted()||board._drcChecksComplete||board._drcChecksInProgress)return;let runDrcChecks2=async circuitJson=>{let checksToRun=[],queueCheck=(checkName,check)=>{checksToRun.push(Promise.resolve().then(check).catch(error2=>{let cause=error2 instanceof Error?error2.message:String(error2);return db22.source_runtime_error.insert({error_type:"source_runtime_error",phase_name:"PcbDesignRuleChecks",message:`DRC could not complete (${checkName}): ${cause}`}),[]}))},pcbBoardId=board.pcb_board_id;if(shouldRunFabricatorChecks&&fabricatorEngine4&&fabricatorPreset&&pcbBoardId&&queueCheck("fabricator",()=>fabricatorEngine4.runDrcChecks({circuitJson,fabricatorPreset,pcbBoardId})),shouldRunRoutingChecks&&queueCheck("routing",()=>runAllRoutingChecks(circuitJson).then(results=>results.filter(result=>!board._isExpectedCastellatedHoleDrcError(result)))),shouldRunPlacementChecks){let existingPlacementDiagnostics=db22.toArray();queueCheck("placement",()=>runAllPlacementChecks(circuitJson,{consolidateOverlaps:!1}).then(results=>consolidatePcbOverlapErrors(circuitJson,results.filter(result=>!board._isExpectedCastellatedHoleDrcError(result))).filter(result=>!existingPlacementDiagnostics.some(existing=>existing.type===result.type&&"message"in existing&&existing.message===result.message))))}if(shouldRunNetlistChecks&&queueCheck("netlist",()=>runAllNetlistChecks(circuitJson)),shouldRunSchematicChecks&&queueCheck("schematic",()=>runAllSchematicChecks(circuitJson)),!drcChecksDisabled)for(let drcCheck of board.selectAll("drccheck"))queueCheck(drcCheck.getString(),()=>drcCheck.runCustomDrcCheck(circuitJson));let checkResults=await Promise.all(checksToRun);db22.insertAll(consolidatePcbOverlapErrors(circuitJson,dedupePcbDrcErrors(checkResults.flat())))},subcircuitCircuitJson=db22.subtree({subcircuit_id:board.subcircuit_id}).toArray();board._drcChecksInProgress=!0,board._queueAsyncEffect("board:drc-checks",async()=>{try{await runDrcChecks2(subcircuitCircuitJson),board._drcChecksComplete=!0}finally{board._drcChecksInProgress=!1}})},GEOMETRY_SCALE=1e6,CONTACT_TOLERANCE=1e-7*GEOMETRY_SCALE,getRouteEndpoint=(routePoint3,side)=>routePoint3.route_type==="wire"?{point:routePoint3,layer:routePoint3.layer}:routePoint3.route_type==="via"?{point:routePoint3,layer:side==="start"?routePoint3.from_layer:routePoint3.to_layer}:{point:routePoint3[side],layer:side==="start"?routePoint3.start_layer:routePoint3.end_layer},findFloatingCopper=(circuitJson,generatedStitchingViaIds=new Set)=>{let connectivity=getFullConnectivityMapFromCircuitJson(circuitJson),pours=circuitJson.filter(e210=>e210.type==="pcb_copper_pour"),pouredNets=new Set(pours.flatMap(pour=>pour.source_net_id?[connectivity.getNetConnectedToId(pour.source_net_id)??pour.source_net_id]:[])),conductors=[],add10=conductor=>{pouredNets.has(conductor.netId)&&!conductor.polygon.isEmpty()&&conductors.push({...conductor,polygon:conductor.polygon.scale(GEOMETRY_SCALE,GEOMETRY_SCALE)})},components=new Map(circuitJson.filter(e210=>e210.type==="pcb_component").map(e210=>[e210.pcb_component_id,e210])),vias=circuitJson.filter(e210=>e210.type==="pcb_via"),board=circuitJson.find(e210=>e210.type==="pcb_board");for(let pour of pours)pour.source_net_id&&add10({polygon:getPourPolygon(pour),layers:[pour.layer],netId:connectivity.getNetConnectedToId(pour.source_net_id)??pour.source_net_id,isTerminal:!1,pourId:pour.pcb_copper_pour_id});for(let element of circuitJson)if(element.type==="pcb_smtpad"){let netId=connectivity.getNetConnectedToId(element.pcb_smtpad_id);netId&&pouredNets.has(netId)&&add10({polygon:getSmtPadPolygon(element),layers:[element.layer],netId,isTerminal:!!element.pcb_port_id})}else if(element.type==="pcb_plated_hole"){let netId=connectivity.getNetConnectedToId(element.pcb_plated_hole_id);netId&&pouredNets.has(netId)&&add10({polygon:getPlatedHolePolygon(element,element.pcb_component_id?components.get(element.pcb_component_id)?.rotation:0),layers:element.layers,netId,isTerminal:!!element.pcb_port_id})}else if(element.type==="pcb_via"){let netId=connectivity.getNetConnectedToId(element.pcb_via_id);netId&&pouredNets.has(netId)&&add10({polygon:getViaPolygon(element,element.outer_diameter,element.hole_diameter),layers:element.layers,netId,isTerminal:!generatedStitchingViaIds.has(element.pcb_via_id),viaId:element.pcb_via_id})}else if(element.type==="pcb_trace"){let netId=connectivity.getNetConnectedToId(element.pcb_trace_id);if(!netId||!pouredNets.has(netId))continue;for(let i22=0;i22<element.route.length;i22++){let routePoint3=element.route[i22];if(routePoint3.route_type==="via"){let actualVia=vias.find(via=>via.x===routePoint3.x&&via.y===routePoint3.y&&via.layers.includes(routePoint3.from_layer)&&via.layers.includes(routePoint3.to_layer));add10({polygon:getViaPolygon(routePoint3,actualVia?.outer_diameter??routePoint3.outer_diameter??board?.min_via_pad_diameter??.3,actualVia?.hole_diameter??routePoint3.hole_diameter??board?.min_via_hole_diameter??.2),layers:actualVia?.layers??getViaSpanLayers({fromLayer:routePoint3.from_layer,toLayer:routePoint3.to_layer,layerCount:board?.num_layers??2}),netId,isTerminal:!1})}let next2=element.route[i22+1];if(!next2)continue;let start=getRouteEndpoint(routePoint3,"end"),end=getRouteEndpoint(next2,"start");if(start.layer!==end.layer)continue;let startWidth=routePoint3.route_type==="via"?next2.route_type==="via"?void 0:next2.width:routePoint3.width;if(startWidth===void 0)continue;let endWidth=element.route_thickness_mode==="interpolated"&&next2.route_type!=="via"?next2.width:startWidth;add10({polygon:getTraceSegmentPolygon(start.point,end.point,startWidth,endWidth),layers:[start.layer],netId,isTerminal:!1})}}let floatingPourIds=new Set,floatingViaIds=new Set;if(conductors.length===0)return{floatingPourIds,floatingViaIds};let parent=conductors.map((_22,i22)=>i22),find2=i22=>{for(;parent[i22]!==i22;)parent[i22]=parent[parent[i22]],i22=parent[i22];return i22},bounds=conductors.map(conductor=>conductor.polygon.box),spatialIndex=new Flatbush(conductors.length);for(let box2 of bounds)spatialIndex.add(box2.xmin,box2.ymin,box2.xmax,box2.ymax);spatialIndex.finish();for(let[i22,conductor]of conductors.entries()){let box2=bounds[i22];for(let j22 of spatialIndex.search(box2.xmin-CONTACT_TOLERANCE,box2.ymin-CONTACT_TOLERANCE,box2.xmax+CONTACT_TOLERANCE,box2.ymax+CONTACT_TOLERANCE)){if(j22<=i22||find2(i22)===find2(j22))continue;let neighbor=conductors[j22];conductor.netId!==neighbor.netId||!conductor.layers.some(layer=>neighbor.layers.includes(layer))||copperPolygonsTouch(conductor.polygon,neighbor.polygon,CONTACT_TOLERANCE)&&(parent[find2(j22)]=find2(i22))}}let netsWithTerminals=new Set(conductors.flatMap(conductor=>conductor.isTerminal?[conductor.netId]:[])),terminalRoots=new Set(conductors.flatMap((conductor,i22)=>conductor.isTerminal?[find2(i22)]:[]));for(let[i22,conductor]of conductors.entries())!netsWithTerminals.has(conductor.netId)||terminalRoots.has(find2(i22))||(conductor.pourId&&floatingPourIds.add(conductor.pourId),conductor.viaId&&floatingViaIds.add(conductor.viaId));return{floatingPourIds,floatingViaIds}},Board_doInitialPcbCopperPourCleanup=board=>{if(!board.root||board.root.pcbDisabled)return;let{db:db22}=board.root;if(db22.pcb_copper_pour.list().length===0)return;let circuitJson=db22.subtree({subcircuit_id:board.subcircuit_id}).toArray();if(db22.pcb_autorouting_error.list().length>0||!circuitJson.some(element=>element.type==="pcb_copper_pour"))return;let{floatingPourIds,floatingViaIds}=findFloatingCopper(circuitJson,board._generatedStitchingViaIds);for(let pourId of floatingPourIds)db22.pcb_copper_pour.delete(pourId);for(let viaId of floatingViaIds)board._generatedStitchingViaIds.has(viaId)&&db22.pcb_via.delete(viaId);for(let trace of db22.pcb_trace.list())trace.route.some(point62=>"copper_pour_id"in point62&&point62.copper_pour_id&&floatingPourIds.has(point62.copper_pour_id))&&db22.pcb_trace.update(trace.pcb_trace_id,{route:trace.route.map(point62=>{if(!("copper_pour_id"in point62)||!point62.copper_pour_id||!floatingPourIds.has(point62.copper_pour_id))return point62;let{copper_pour_id,is_inside_copper_pour,...wireOrVia}=point62;return wireOrVia})})},resetPcbTraceRenderInSubtree=renderable=>{renderable._pcbTraceRenderWaitingForPlacementChecks&&(renderable.renderPhaseStates.PcbTraceRender.initialized=!1,renderable.renderPhaseStates.PcbTraceRender.dirty=!1,renderable._pcbTraceRenderWaitingForPlacementChecks=!1);for(let child of renderable.children)resetPcbTraceRenderInSubtree(child)},Board_doInitialPcbPlacementDesignRuleChecks=board=>{if(board.root?.pcbDisabled)return;let placementDrcChecksDisabled=board.root?.platform?.placementDrcChecksDisabled??board.getInheritedProperty("placementDrcChecksDisabled"),drcChecksDisabled=board.root?.platform?.drcChecksDisabled??board.getInheritedProperty("drcChecksDisabled");if(board._pcbPlacementDrcErrorCount=null,board._pcbPlacementDrcCheckError=null,board._pcbPlacementDrcChecksPending=!1,placementDrcChecksDisabled||drcChecksDisabled){board._pcbPlacementDrcErrorCount=0;return}let{db:db22}=board.root,subcircuitCircuitJson=db22.subtree({subcircuit_id:board.subcircuit_id}).toArray(),existingPlacementDiagnostics=db22.toArray();board._pcbPlacementDrcChecksPending=!0,board._queueAsyncEffect("board:pre-route-placement-checks",async()=>{try{let placementCheckResults=await runAllPlacementChecks(subcircuitCircuitJson,{consolidateOverlaps:!1}),relevantPlacementCheckResults=consolidatePcbOverlapErrors(subcircuitCircuitJson,placementCheckResults.filter(result=>!board._isExpectedCastellatedHoleDrcError(result))),newPlacementDiagnostics=relevantPlacementCheckResults.filter(result=>!existingPlacementDiagnostics.some(existing=>existing.type===result.type&&"message"in existing&&existing.message===result.message));db22.insertAll(newPlacementDiagnostics),board._pcbPlacementDrcErrorCount=relevantPlacementCheckResults.filter(result=>result.type.endsWith("_error")).length}catch(error2){board._pcbPlacementDrcCheckError=error2 instanceof Error?error2.message:String(error2)}finally{board._pcbPlacementDrcChecksPending=!1,resetPcbTraceRenderInSubtree(board)}})},CASTELLATED_HOLE_ENDPOINT_TOLERANCE_MM=1e-6,getConnectionTargets2=connectsTo=>connectsTo?Array.isArray(connectsTo)?connectsTo:[connectsTo]:[],BoardCastellatedHole=class _BoardCastellatedHole extends PlatedHole{constructor(outlinePoint,outlinePointIndex){let name=`castellated_hole_${outlinePointIndex+1}`,connectionTargets=getConnectionTargets2(outlinePoint.connectsTo),holeDiameter=distance.parse(outlinePoint.holeDiameter),padDiameter=distance.parse(outlinePoint.padDiameter);super({shape:"circle",holeDiameter,outerDiameter:padDiameter,portHints:[name]});__publicField(this,"outlinePointIndex");__publicField(this,"holeDiameter");__publicField(this,"padDiameter");__publicField(this,"port");__publicField(this,"trace");this.outlinePointIndex=outlinePointIndex,this.holeDiameter=holeDiameter,this.padDiameter=padDiameter,this.port=connectionTargets.length>0?new Port({name}):null,this.trace=this.port?new Trace({path:[`port.${name}`,...connectionTargets],displayName:`Castellated hole ${outlinePointIndex+1} connectivity`}):null}static fromBoardOutline(outline){return(outline??[]).flatMap((outlinePoint,outlinePointIndex)=>outlinePoint.isCastellatedHole?[new _BoardCastellatedHole(outlinePoint,outlinePointIndex)]:[])}_getParentBoard(){if(this.parent?.componentName!=="Board")throw new Error("A board castellated hole must be a direct board child");return this.parent}_getPositionFromBoardOutline(){let board=this._getParentBoard(),outlinePoint=(board.pcb_board_id?board.root?.db.pcb_board.get(board.pcb_board_id):null)?.outline?.[this.outlinePointIndex];if(!outlinePoint)throw new Error(`Missing emitted board outline point ${this.outlinePointIndex}`);return outlinePoint}_getGlobalPcbPositionBeforeLayout(){return this._getPositionFromBoardOutline()}doInitialPcbPrimitiveRender(){if(this.root?.pcbDisabled)return;let{db:db22}=this.root,position4=this._getPositionFromBoardOutline(),pcbPlatedHole=db22.pcb_plated_hole.insert({shape:"circle",outer_diameter:this.padDiameter,hole_diameter:this.holeDiameter,...position4,layers:this.getAvailablePcbLayers(),port_hints:this.getNameAndAliases(),subcircuit_id:this.getSubcircuit()?.subcircuit_id??void 0});this.pcb_plated_hole_id=pcbPlatedHole.pcb_plated_hole_id}syncPositionToBoardOutline(){this.pcb_plated_hole_id&&this._setPositionFromLayout(this._getPositionFromBoardOutline())}removePcbPrimitiveRender(){let{db:db22}=this.root;this.pcb_plated_hole_id&&(db22.pcb_plated_hole.delete(this.pcb_plated_hole_id),this.pcb_plated_hole_id=null),this.matchedPort?.pcb_port_id&&(db22.pcb_port.delete(this.matchedPort.pcb_port_id),this.matchedPort.pcb_port_id=null)}isExpectedBoardEdgeDrcError(result){if(!this.pcb_plated_hole_id)return!1;if(result.type==="pcb_placement_error")return result.pcb_placement_error_id===`copper_too_close_to_board_edge_${this.pcb_plated_hole_id}`;if(result.type!=="pcb_trace_error"||!result.pcb_trace_error_id.startsWith("trace_too_close_to_board_"))return!1;let segmentIndexMatch=result.pcb_trace_error_id.match(/_segment_(\d+)$/);if(!segmentIndexMatch)return!1;let pcbTrace=this.root?.db.pcb_trace.get(result.pcb_trace_id),segmentIndex=Number(segmentIndexMatch[1]),segmentEndpoints=[pcbTrace?.route[segmentIndex],pcbTrace?.route[segmentIndex+1]].flatMap(routePoint3=>routePoint3&&"x"in routePoint3&&"y"in routePoint3?[{x:routePoint3.x,y:routePoint3.y}]:[]),platedHole2=this.root?.db.pcb_plated_hole.get(this.pcb_plated_hole_id);return platedHole2?segmentEndpoints.some(endpoint=>Math.hypot(endpoint.x-platedHole2.x,endpoint.y-platedHole2.y)<=CASTELLATED_HOLE_ENDPOINT_TOLERANCE_MM):!1}},MIN_EFFECTIVE_BORDER_RADIUS_MM=.01,DEFAULT_VIA_PAD_DIAMETER_OVER_HOLE_DIAMETER_MM=.15,getRoundedRectOutline=(width,height,radius)=>{let w22=width/2,h22=height/2,r22=Math.min(radius,w22,h22);if(r22<MIN_EFFECTIVE_BORDER_RADIUS_MM)return[{x:-w22,y:-h22},{x:w22,y:-h22},{x:w22,y:h22},{x:-w22,y:h22}];let segments=Math.max(1,Math.ceil(Math.PI/2*r22/.1)),step=Math.PI/2/segments,outline=[];outline.push({x:-w22+r22,y:-h22}),outline.push({x:w22-r22,y:-h22});for(let i22=1;i22<=segments;i22++){let theta=-Math.PI/2+i22*step;outline.push({x:w22-r22+r22*Math.cos(theta),y:-h22+r22+r22*Math.sin(theta)})}outline.push({x:w22,y:h22-r22});for(let i22=1;i22<=segments;i22++){let theta=0+i22*step;outline.push({x:w22-r22+r22*Math.cos(theta),y:h22-r22+r22*Math.sin(theta)})}outline.push({x:-w22+r22,y:h22});for(let i22=1;i22<=segments;i22++){let theta=Math.PI/2+i22*step;outline.push({x:-w22+r22+r22*Math.cos(theta),y:h22-r22+r22*Math.sin(theta)})}outline.push({x:-w22,y:-h22+r22});for(let i22=1;i22<=segments;i22++){let theta=Math.PI+i22*step;outline.push({x:-w22+r22+r22*Math.cos(theta),y:-h22+r22+r22*Math.sin(theta)})}return outline},Board=class extends Group5{constructor(props){super(props);__publicField(this,"pcbFold");__publicField(this,"pcb_board_id",null);__publicField(this,"source_board_id",null);__publicField(this,"_drcChecksComplete",!1);__publicField(this,"_drcChecksInProgress",!1);__publicField(this,"_connectedSchematicPortPairs",new Set);__publicField(this,"_panelPositionOffset",null);__publicField(this,"_castellatedHoles");__publicField(this,"_generatedStitchingViaIds",new Set);this._castellatedHoles=BoardCastellatedHole.fromBoardOutline(this._parsedProps.outline);for(let castellatedHole of this._castellatedHoles)castellatedHole.port&&this.add(castellatedHole.port),this.add(castellatedHole),castellatedHole.trace&&this.add(castellatedHole.trace)}doInitialCadModelRender(){this.root?.pcbDisabled||(resolveBoardMotorMount(this),super.doInitialCadModelRender())}doInitialPcbFlexRender(){if(!this.pcb_board_id)return;let bends=this.root.db.pcb_bend.list().filter(bend=>bend.pcb_board_id===this.pcb_board_id);if(this.pcbFold=void 0,!bends.length)return;let pcbBoard=this.root.db.pcb_board.get(this.pcb_board_id),foldResult=tryCreatePcbFold(bends,this.boardThickness,{outline:pcbBoard.outline?.map(point62=>({x:point62.x-pcbBoard.center.x,y:point62.y-pcbBoard.center.y}))});foldResult.ok?this.pcbFold=foldResult.value:this.root.db.pcb_placement_error.insert({error_type:"pcb_placement_error",subcircuit_id:this.subcircuit_id??void 0,message:`Unable to fold PCB board ${this._parsedProps.name??"unnamed board"}; CAD remains flat: ${getReadablePcbFoldIssueMessage(foldResult.issue,bends)}`})}get isSubcircuit(){return!0}get isGroup(){return!0}get config(){return{componentName:"Board",zodProps:boardProps}}get boardThickness(){return this._parsedProps.thickness??1.4}get allLayers(){return getBoardAvailableLayers(this._parsedProps.layers??2)}_getSubcircuitLayerCount(){return this._parsedProps.layers??2}_computePcbGlobalTransformBeforeLayout(){if(this._panelPositionOffset){let parentTransform=this.parent?._computePcbGlobalTransformBeforeLayout?.()??{a:1,b:0,c:0,d:1,e:0,f:0};return compose2(parentTransform,translate2(this._panelPositionOffset.x,this._panelPositionOffset.y))}return super._computePcbGlobalTransformBeforeLayout()}_getBoardCalcVariables(){let{_parsedProps:props}=this;if((props.width==null||props.height==null)&&!props.outline)return{};let dbBoard=this.pcb_board_id?this.root?.db.pcb_board.get(this.pcb_board_id):null,width=dbBoard?.width??props.width,height=dbBoard?.height??props.height;if((width==null||height==null)&&props.outline?.length){let outlineBounds=getBoundsFromPoints(props.outline);outlineBounds&&(width??(width=outlineBounds.maxX-outlineBounds.minX),height??(height=outlineBounds.maxY-outlineBounds.minY))}let{pcbX,pcbY}=this.getResolvedPcbPositionProp(),center2=dbBoard?.center??{x:pcbX+(props.outlineOffsetX??0),y:pcbY+(props.outlineOffsetY??0)},resolvedWidth=width??0,resolvedHeight=height??0;return{"board.minX":center2.x-resolvedWidth/2,"board.maxX":center2.x+resolvedWidth/2,"board.minY":center2.y-resolvedHeight/2,"board.maxY":center2.y+resolvedHeight/2}}doInitialPcbBoardAutoSize(){if(this.root?.pcbDisabled||!this.pcb_board_id)return;let{db:db22}=this.root,{_parsedProps:props}=this,globalPos=this._getGlobalPcbPositionBeforeLayout(),pcbBoard=db22.pcb_board.get(this.pcb_board_id);if(pcbBoard?.width&&pcbBoard?.height||pcbBoard?.outline&&pcbBoard.outline.length>0)return;let minX=1/0,minY=1/0,maxX=-1/0,maxY=-1/0,descendantIds=getDescendantSubcircuitIds2(db22,this.subcircuit_id),allowedSubcircuitIds=new Set([this.subcircuit_id,...descendantIds]),allPcbComponents=db22.pcb_component.list().filter(c22=>c22.subcircuit_id&&allowedSubcircuitIds.has(c22.subcircuit_id)),allPcbGroups=db22.pcb_group.list().filter(g22=>g22.subcircuit_id&&allowedSubcircuitIds.has(g22.subcircuit_id)),hasComponents=!1,updateBounds=(center22,width,height)=>{width===0||height===0||(hasComponents=!0,minX=Math.min(minX,center22.x-width/2),minY=Math.min(minY,center22.y-height/2),maxX=Math.max(maxX,center22.x+width/2),maxY=Math.max(maxY,center22.y+height/2))};for(let pcbComponent of allPcbComponents)updateBounds(pcbComponent.center,pcbComponent.width,pcbComponent.height);for(let pcbGroup of allPcbGroups){let width=pcbGroup.width??0,height=pcbGroup.height??0;if(pcbGroup.outline&&pcbGroup.outline.length>0){let bounds=getBoundsFromPoints(pcbGroup.outline);bounds&&(width=bounds.maxX-bounds.minX,height=bounds.maxY-bounds.minY)}updateBounds(pcbGroup.center,width,height)}if(props.boardAnchorPosition){let{x:x22,y:y22}=props.boardAnchorPosition;minX=Math.min(minX,x22),minY=Math.min(minY,y22),maxX=Math.max(maxX,x22),maxY=Math.max(maxY,y22)}let padding=2,computedWidth=hasComponents?maxX-minX+padding*2:0,computedHeight=hasComponents?maxY-minY+padding*2:0,center2={x:hasComponents?(minX+maxX)/2+(props.outlineOffsetX??0):(props.outlineOffsetX??0)+globalPos.x,y:hasComponents?(minY+maxY)/2+(props.outlineOffsetY??0):(props.outlineOffsetY??0)+globalPos.y},finalWidth=props.width??computedWidth,finalHeight=props.height??computedHeight,outline=props.outline;!outline&&props.borderRadius!=null&&finalWidth>0&&finalHeight>0&&(outline=getRoundedRectOutline(finalWidth,finalHeight,props.borderRadius));let update2={width:finalWidth,height:finalHeight,center:center2};outline&&(update2.outline=outline.map(point62=>({x:point62.x+(props.outlineOffsetX??0),y:point62.y+(props.outlineOffsetY??0)}))),db22.pcb_board.update(this.pcb_board_id,update2)}updatePcbBoardAutoSize(){this.doInitialPcbBoardAutoSize()}_addBoardInformationToSilkscreen(){let platform=this.root?.platform;if(!platform?.printBoardInformationToSilkscreen)return;let pcbBoard=this.root.db.pcb_board.get(this.pcb_board_id);if(!pcbBoard)return;let boardInformation=[];if(platform.projectName&&boardInformation.push(platform.projectName),platform.version&&boardInformation.push(`v${platform.version}`),platform.url&&boardInformation.push(platform.url),boardInformation.length===0)return;let text=boardInformation.join(`
955
955
  `),position4={x:pcbBoard.center.x+pcbBoard.width/2-.25,y:pcbBoard.center.y-pcbBoard.height/2+1};this.root.db.pcb_silkscreen_text.insert({pcb_component_id:this.pcb_board_id,layer:"top",font:"tscircuit2024",font_size:.45,text,ccw_rotation:0,anchor_alignment:"bottom_right",anchor_position:position4})}doInitialSourceRender(){let nestedBoard=this.getDescendants().find(d23=>d23.lowercaseComponentName==="board");if(nestedBoard)throw new Error(`Nested boards are not supported: found board "${nestedBoard.name}" inside board "${this.name}"`);super.doInitialSourceRender();let{db:db22}=this.root,source_board3=db22.source_board.insert({source_group_id:this.source_group_id,title:this.props.title||this.props.name});this.source_board_id=source_board3.source_board_id}getSubcircuitPropHash(){return Subcircuit_getSubcircuitPropHash(this)}doInitialRenderIsolatedSubcircuits(){Subcircuit_doInitialRenderIsolatedSubcircuits(this)}doInitialInflateSubcircuitCircuitJson(){let isolatedJson=this._isolatedCircuitJson;if(isolatedJson){this._isInflatedFromCircuitJson=!0,this._isolatedCircuitJson=null,inflateCircuitJson(this,isolatedJson,[]);return}let{circuitJson,children}=this._parsedProps;circuitJson&&(this._isInflatedFromCircuitJson=!0),inflateCircuitJson(this,circuitJson,children)}doInitialPcbComponentRender(){if(this.root?.pcbDisabled)return;let{db:db22}=this.root,{_parsedProps:props}=this,pcbBoardFromCircuitJson=props.circuitJson?.find(elm=>elm.type==="pcb_board"),viaTenting=getViaTenting(props.defaultViaTenting),rawProps=this.props,resolvedIsViaInPadAllowed=rawProps.isViaInPadAllowed??pcbBoardFromCircuitJson?.is_via_in_pad_allowed,resolvedAllowBlindAndBuriedVias=rawProps.allowBlindAndBuriedVias??pcbBoardFromCircuitJson?.allow_blind_and_buried_vias,computedWidth=props.width??pcbBoardFromCircuitJson?.width??0,computedHeight=props.height??pcbBoardFromCircuitJson?.height??0,globalPos=this._getGlobalPcbPositionBeforeLayout(),center2={x:globalPos.x+(props.outlineOffsetX??0),y:globalPos.y+(props.outlineOffsetY??0)},{boardAnchorPosition,boardAnchorAlignment}=props;if(boardAnchorPosition&&(center2=getBoardCenterFromAnchor({boardAnchorPosition,boardAnchorAlignment:boardAnchorAlignment??"center",width:computedWidth,height:computedHeight})),props.outline){let xValues=props.outline.map(point62=>point62.x),yValues=props.outline.map(point62=>point62.y),minX=Math.min(...xValues),maxX=Math.max(...xValues),minY=Math.min(...yValues),maxY=Math.max(...yValues);computedWidth=maxX-minX,computedHeight=maxY-minY}let outline=props.outline;!outline&&props.borderRadius!=null&&computedWidth>0&&computedHeight>0&&(outline=getRoundedRectOutline(computedWidth,computedHeight,props.borderRadius));let outlineTranslation={x:0,y:0};if(outline&&outline.length>0&&(this.parent?.lowercaseComponentName==="panel"||this.parent?.lowercaseComponentName==="subpanel")){let outlineBounds=getBoundsFromPoints(outline);if(outlineBounds){let outlineCenterX=(outlineBounds.minX+outlineBounds.maxX)/2,outlineCenterY=(outlineBounds.minY+outlineBounds.maxY)/2;outlineTranslation={x:center2.x-outlineCenterX,y:center2.y-outlineCenterY}}}let subcircuitProps2=this.getSubcircuit()._parsedProps,pcbStyle3=this.getInheritedMergedProperty("pcbStyle"),styledViaDimensions=getViaDiameterDefaults(pcbStyle3),configuredViaHoleDiameter=subcircuitProps2.minViaHoleDiameter??(pcbStyle3?.viaHoleDiameter!==void 0?styledViaDimensions.holeDiameter:void 0),resolvedMinViaHoleDiameter=configuredViaHoleDiameter??jlcMinTolerances2.min_via_hole_diameter,resolvedMinViaPadDiameter=subcircuitProps2.minViaPadDiameter??(pcbStyle3?.viaPadDiameter!==void 0?styledViaDimensions.padDiameter:configuredViaHoleDiameter!==void 0?configuredViaHoleDiameter+DEFAULT_VIA_PAD_DIAMETER_OVER_HOLE_DIAMETER_MM:jlcMinTolerances2.min_via_pad_diameter),pcb_board3=db22.pcb_board.insert({source_board_id:this.source_board_id,subcircuit_id:this.subcircuit_id??void 0,center:center2,default_via_tented_on_top:viaTenting.tented_on_top??pcbBoardFromCircuitJson?.default_via_tented_on_top,default_via_tented_on_bottom:viaTenting.tented_on_bottom??pcbBoardFromCircuitJson?.default_via_tented_on_bottom,thickness:this.boardThickness,num_layers:this.allLayers.length,width:computedWidth,height:computedHeight,outline:outline?.map(point62=>({x:point62.x+(props.outlineOffsetX??0)+outlineTranslation.x,y:point62.y+(props.outlineOffsetY??0)+outlineTranslation.y})),material:props.material,...resolvedIsViaInPadAllowed!==void 0&&{is_via_in_pad_allowed:resolvedIsViaInPadAllowed},...resolvedAllowBlindAndBuriedVias!==void 0&&{allow_blind_and_buried_vias:resolvedAllowBlindAndBuriedVias},...props.solderMaskColor!==void 0&&{solder_mask_color:props.solderMaskColor},...props.silkscreenColor!==void 0&&{silkscreen_color:props.silkscreenColor},min_trace_width:subcircuitProps2.minTraceWidth??jlcMinTolerances2.min_trace_width,min_via_hole_diameter:resolvedMinViaHoleDiameter,min_via_pad_diameter:resolvedMinViaPadDiameter,min_via_hole_edge_to_via_hole_edge_clearance:subcircuitProps2.minViaHoleEdgeToViaHoleEdgeClearance??jlcMinTolerances2.min_via_hole_edge_to_via_hole_edge_clearance,min_via_edge_to_pad_edge_clearance:subcircuitProps2.minViaEdgeToPadEdgeClearance??jlcMinTolerances2.min_via_edge_to_pad_edge_clearance,min_trace_to_hole_edge_clearance:subcircuitProps2.minTraceToHoleEdgeClearance??jlcMinTolerances2.min_trace_to_hole_edge_clearance,min_trace_to_pad_edge_clearance:subcircuitProps2.minTraceToPadEdgeClearance??jlcMinTolerances2.min_trace_to_pad_edge_clearance,min_pad_edge_to_pad_edge_clearance:subcircuitProps2.minPadEdgeToPadEdgeClearance??jlcMinTolerances2.min_pad_edge_to_pad_edge_clearance,min_plated_hole_drill_edge_to_drill_edge_clearance:subcircuitProps2.minPlatedHoleDrillEdgeToDrillEdgeClearance??jlcMinTolerances2.min_plated_hole_drill_edge_to_drill_edge_clearance,min_board_edge_clearance:subcircuitProps2.minBoardEdgeClearance??jlcMinTolerances2.min_board_edge_clearance});this.pcb_board_id=pcb_board3.pcb_board_id,this._addBoardInformationToSilkscreen()}removePcbComponentRender(){let{db:db22}=this.root;this.pcb_board_id&&(db22.pcb_board.delete(this.pcb_board_id),this.pcb_board_id=null)}doInitialPcbDesignRuleChecks(){super.doInitialPcbDesignRuleChecks(),this.updatePcbDesignRuleChecks()}doInitialPcbPlacementDesignRuleChecks(){Board_doInitialPcbPlacementDesignRuleChecks(this)}doInitialPcbCopperPourCleanup(){Board_doInitialPcbCopperPourCleanup(this)}updatePcbDesignRuleChecks(){Board_updatePcbDesignRuleChecks(this)}runRenderPhaseForChildren(phase){this.root?.emit("board:renderPhaseStarted",{renderId:this._renderId,phase}),super.runRenderPhaseForChildren(phase)}_repositionOnPcb(position4){let{db:db22}=this.root,pcbBoard=this.pcb_board_id?db22.pcb_board.get(this.pcb_board_id):null,oldPos=pcbBoard?.center;if(!oldPos){this.pcb_board_id&&db22.pcb_board.update(this.pcb_board_id,{center:position4});return}let deltaX=position4.x-oldPos.x,deltaY=position4.y-oldPos.y;if(!(Math.abs(deltaX)<1e-6&&Math.abs(deltaY)<1e-6)&&this.pcb_board_id&&(db22.pcb_board.update(this.pcb_board_id,{center:position4}),pcbBoard?.outline)){let outlineBounds=getBoundsFromPoints(pcbBoard.outline);if(outlineBounds){let oldOutlineCenter={x:(outlineBounds.minX+outlineBounds.maxX)/2,y:(outlineBounds.minY+outlineBounds.maxY)/2},outlineDeltaX=position4.x-oldOutlineCenter.x,outlineDeltaY=position4.y-oldOutlineCenter.y,newOutline=pcbBoard.outline.map(p22=>({x:p22.x+outlineDeltaX,y:p22.y+outlineDeltaY}));db22.pcb_board.update(this.pcb_board_id,{outline:newOutline});for(let castellatedHole of this._castellatedHoles)castellatedHole.syncPositionToBoardOutline()}}}_isExpectedCastellatedHoleDrcError(result){return this._castellatedHoles.some(castellatedHole=>castellatedHole.isExpectedBoardEdgeDrcError(result))}},Subcircuit=class extends Group5{constructor(props){super({...props,subcircuit:!0})}getSubcircuitPropHash(){return Subcircuit_getSubcircuitPropHash(this)}doInitialRenderIsolatedSubcircuits(){Subcircuit_doInitialRenderIsolatedSubcircuits(this)}doInitialCreateNetsFromProps(){super.doInitialCreateNetsFromProps(),this._createTracesForExposedConnections()}_createTracesForExposedConnections(){let exposedNets=this._getNetNamesToExpose();if(!exposedNets?.length)return;let parentSubcircuit=this.parent?.getSubcircuit?.();if(parentSubcircuit&&this.name)for(let exposedNetName of exposedNets){let netName=normalizeExposedNetName(exposedNetName),parentNetSelector=`> net.${netName}`,childNetSelector=`.${this.name} > net.${netName}`;if(parentSubcircuit.children.find(child=>child instanceof Net&&child._parsedProps.name===netName)||parentSubcircuit.add(new Net({name:netName})),parentSubcircuit.children.find(child=>{if(!(child instanceof Trace)||!child._exposesSubcircuitConnection)return!1;let childProps=child._parsedProps;return childProps.from===childNetSelector&&childProps.to===parentNetSelector}))continue;let trace=new Trace({from:childNetSelector,to:parentNetSelector,displayName:netName});trace._exposesSubcircuitConnection=!0,parentSubcircuit.add(trace)}}_getNetNamesToExpose(){let explicitExposedNets=this._parsedProps.exposedNets??[];if(!this._parsedProps.exposeNets)return explicitExposedNets;let childNetNames=this.selectAll("net").filter(net=>net instanceof Net&&net.getSubcircuit()===this).map(net=>net._parsedProps.name);return Array.from(new Set([...explicitExposedNets,...childNetNames]))}doInitialInflateSubcircuitCircuitJson(){let isolatedJson=this._isolatedCircuitJson;if(isolatedJson){this._isInflatedFromCircuitJson=!0,this._isolatedCircuitJson=null,inflateCircuitJson(this,isolatedJson,[]);return}let{circuitJson,children}=this._parsedProps;circuitJson&&(this._isInflatedFromCircuitJson=!0),inflateCircuitJson(this,circuitJson,children)}},normalizeExposedNetName=netName=>netName.startsWith("net.")?netName.slice(4):netName,MountedBoard=class extends Subcircuit{constructor(){super(...arguments);__publicField(this,"pcb_board_id",null);__publicField(this,"_connectedSchematicPortPairs",new Set)}get config(){return{componentName:"MountedBoard",zodProps:mountedboardProps}}get boardThickness(){return 1.4}get allLayers(){return["top","bottom"]}_getBoardCalcVariables(){return this._findCarrierBoard()?._getBoardCalcVariables()??{}}_findCarrierBoard(){let current3=this.parent;for(;current3;){if(current3 instanceof Board)return current3;current3=current3.parent}return null}doInitialPcbComponentRender(){if(this.root?.pcbDisabled)return;let{db:db22}=this.root,{_parsedProps:props}=this,globalPos=this._getGlobalPcbPositionBeforeLayout(),pcb_board3=db22.pcb_board.insert({center:{x:globalPos.x,y:globalPos.y},width:props.width??0,height:props.height??0,is_mounted_to_carrier_board:!0});this.pcb_board_id=pcb_board3.pcb_board_id}doInitialPcbBoardAutoSize(){if(!this.pcb_board_id||!this.root)return;let carrierBoard=this._findCarrierBoard();carrierBoard?.pcb_board_id&&this.root.db.pcb_board.update(this.pcb_board_id,{carrier_pcb_board_id:carrierBoard.pcb_board_id})}},DEFAULT_TAB_LENGTH=5,DEFAULT_TAB_WIDTH=2,generateCutoutsAndMousebitesForOutline=(outline,options)=>{let{gapLength,cutoutWidth,mouseBites,mouseBiteHoleDiameter,mouseBiteHoleSpacing}=options,tabCutouts=[],mouseBiteHoles=[];if(outline.length<2)return{tabCutouts,mouseBiteHoles};let outlinePolygon=new Polygon$1(outline.map(p22=>point4(p22.x,p22.y))),is_ccw;if(outline.length>2){let p03=point4(outline[0].x,outline[0].y),p12=point4(outline[1].x,outline[1].y),segmentDir=vector$1(p03,p12).normalize(),normalToLeft=segmentDir.rotate(Math.PI/2),testPoint=p03.translate(segmentDir.multiply(segment(p03,p12).length/2)).translate(normalToLeft.multiply(.01));is_ccw=outlinePolygon.contains(testPoint)}else is_ccw=outlinePolygon.area()>0;for(let i22=0;i22<outline.length;i22++){let p1_=outline[i22],p2_=outline[(i22+1)%outline.length];if(!p1_||!p2_)continue;let p12=point4(p1_.x,p1_.y),p22=point4(p2_.x,p2_.y),segment2=segment(p12,p22),segmentLength=segment2.length;if(segmentLength<1e-6)continue;let segmentVec=vector$1(p12,p22),segmentDir=segmentVec.normalize(),normalVec=segmentDir.rotate(Math.PI/2),testPoint=segment2.middle().translate(normalVec.multiply(.01));outlinePolygon.contains(testPoint)&&(normalVec=normalVec.multiply(-1));let numBitesInGap=2,totalBitesLength=numBitesInGap*mouseBiteHoleDiameter+(numBitesInGap-1)*mouseBiteHoleSpacing,effectiveGapLength;mouseBites?effectiveGapLength=totalBitesLength:effectiveGapLength=gapLength,effectiveGapLength=Math.min(effectiveGapLength,segmentLength*.9);let gapStartDist=(segmentLength-effectiveGapLength)/2,gapEndDist=gapStartDist+effectiveGapLength;if(mouseBites){let holeAndSpacing=mouseBiteHoleDiameter+mouseBiteHoleSpacing;if(effectiveGapLength>=totalBitesLength&&holeAndSpacing>0){let firstBiteCenterOffsetInGap=(effectiveGapLength-totalBitesLength)/2+mouseBiteHoleDiameter/2,firstBiteDistFromP1=gapStartDist+firstBiteCenterOffsetInGap;for(let k22=0;k22<numBitesInGap;k22++){let biteDist=firstBiteDistFromP1+k22*holeAndSpacing,pos=p12.translate(segmentDir.multiply(biteDist));mouseBiteHoles.push({x:pos.x,y:pos.y})}}}let p_prev_=outline[(i22-1+outline.length)%outline.length],p_next_=outline[(i22+2)%outline.length],start_ext=0,end_ext=0;if(p_prev_&&p_next_){let vec_in_p1=vector$1(point4(p_prev_.x,p_prev_.y),p12),p1_cross=vec_in_p1.cross(segmentVec),is_p1_convex=is_ccw?p1_cross>1e-9:p1_cross<-1e-9,vec_out_p2=vector$1(p22,point4(p_next_.x,p_next_.y)),p2_cross=segmentVec.cross(vec_out_p2),is_p2_convex=is_ccw?p2_cross>1e-9:p2_cross<-1e-9;if(is_p1_convex){let angle3=vec_in_p1.angleTo(segmentVec);angle3>Math.PI&&(angle3=2*Math.PI-angle3),start_ext=cutoutWidth*Math.tan(angle3/2)}else start_ext=0;if(is_p2_convex){let angle3=segmentVec.angleTo(vec_out_p2);angle3>Math.PI&&(angle3=2*Math.PI-angle3),end_ext=cutoutWidth*Math.tan(angle3/2)}else end_ext=0}let cutoutParts=effectiveGapLength<1e-6?[{start:0-start_ext,end:segmentLength+end_ext}]:[{start:0-start_ext,end:gapStartDist},{start:gapEndDist,end:segmentLength+end_ext}],extrusion=normalVec.multiply(cutoutWidth);for(let part of cutoutParts){let partLength=part.end-part.start;if(partLength<1e-6)continue;let center2=p12.translate(segmentDir.multiply(part.start+partLength/2)).translate(extrusion.multiply(.5)),width=partLength,height=cutoutWidth,rotationDeg=segmentDir.slope*180/Math.PI;tabCutouts.push({type:"pcb_cutout",shape:"rect",center:{x:center2.x,y:center2.y},width,height,rotation:rotationDeg,corner_radius:cutoutWidth/2})}}return{tabCutouts,mouseBiteHoles}};function generatePanelTabsAndMouseBites(boards,options){let finalTabCutouts=[],allMouseBites=[],{tabWidth,tabLength,mouseBites:useMouseBites}=options,boardDimensions=[];for(let board of boards)if(board.width&&board.height)boardDimensions.push(Math.min(board.width,board.height));else if(board.outline&&board.outline.length>0){let outlinePolygon=new Polygon$1(board.outline.map(p22=>point4(p22.x,p22.y))),area=Math.abs(outlinePolygon.area());area>0&&boardDimensions.push(Math.sqrt(area))}if(boardDimensions.length>0){let scaleFactor=Math.min(...boardDimensions)/20;tabWidth=Math.min(tabWidth,DEFAULT_TAB_WIDTH*Math.max(scaleFactor,.3)),tabLength=Math.min(tabLength,DEFAULT_TAB_LENGTH*Math.max(scaleFactor,.3))}let processedBoards=boards.map(board=>{if((!board.outline||board.outline.length===0)&&board.width&&board.height){let w22=board.width/2,h22=board.height/2;return{...board,outline:[{x:board.center.x-w22,y:board.center.y-h22},{x:board.center.x+w22,y:board.center.y-h22},{x:board.center.x+w22,y:board.center.y+h22},{x:board.center.x-w22,y:board.center.y+h22}]}}return board});for(let board of processedBoards)if(board.outline&&board.outline.length>0){let mouseBiteDiameter2=tabWidth*.45,mouseBiteSpacing=mouseBiteDiameter2*.1,generated=generateCutoutsAndMousebitesForOutline(board.outline,{gapLength:tabLength,cutoutWidth:tabWidth,mouseBites:useMouseBites,mouseBiteHoleDiameter:mouseBiteDiameter2,mouseBiteHoleSpacing:mouseBiteSpacing});finalTabCutouts.push(...generated.tabCutouts),allMouseBites.push(...generated.mouseBiteHoles)}let tabCutouts=finalTabCutouts.map((tab,index2)=>({...tab,pcb_cutout_id:`panel_tab_${index2}`})),mouseBiteDiameter=tabWidth*.45,mouseBiteHoles=allMouseBites.map((bite,index2)=>({type:"pcb_hole",pcb_hole_id:`panel_mouse_bite_${index2}`,hole_shape:"circle",hole_diameter:mouseBiteDiameter,x:bite.x,y:bite.y}));return{tabCutouts,mouseBiteHoles}}function generatePanelOutlineRoutingCutouts(boards,options){return boards.map(board=>{if((!board.outline||board.outline.length===0)&&board.width&&board.height){let halfWidth=board.width/2,halfHeight=board.height/2;return{...board,outline:[{x:board.center.x-halfWidth,y:board.center.y-halfHeight},{x:board.center.x+halfWidth,y:board.center.y-halfHeight},{x:board.center.x+halfWidth,y:board.center.y+halfHeight},{x:board.center.x-halfWidth,y:board.center.y+halfHeight}]}}return board}).flatMap(board=>{if(!board.outline||board.outline.length===0)return[];let{tabCutouts}=generateCutoutsAndMousebitesForOutline(board.outline,{gapLength:0,cutoutWidth:options.cutoutWidth,mouseBites:!1,mouseBiteHoleDiameter:0,mouseBiteHoleSpacing:0});return tabCutouts.map(cutout=>({...cutout,pcb_board_id:board.pcb_board_id}))}).map((cutout,outlineRoutingCutoutIndex)=>({...cutout,pcb_cutout_id:`panel_outline_routing_cutout_${outlineRoutingCutoutIndex}`}))}var getBoardDimensionsFromProps=board=>{let props=board._parsedProps,width=props.width!=null?distance.parse(props.width):void 0,height=props.height!=null?distance.parse(props.height):void 0;if((width===void 0||height===void 0)&&props.outline?.length){let outlineBounds=getBoundsFromPoints(props.outline);outlineBounds&&(width??(width=outlineBounds.maxX-outlineBounds.minX),height??(height=outlineBounds.maxY-outlineBounds.minY))}if((width===void 0||height===void 0)&&props.circuitJson?.length){let pcbBoardFromJson=props.circuitJson.find(elm=>elm.type==="pcb_board");pcbBoardFromJson&&(width??(width=pcbBoardFromJson.width),height??(height=pcbBoardFromJson.height))}return{width:width??0,height:height??0}};function packIntoGrid({items,db:db22,row,col,cellWidth,cellHeight,boardGap,availablePanelWidth,availablePanelHeight}){let itemsWithDims=items.map(item=>{let dims=getItemDimensions(item,db22);return{item,width:dims.width,height:dims.height}}).filter(item=>!(item.width===0&&item.height===0));if(itemsWithDims.length===0)return{positions:[],gridWidth:0,gridHeight:0};let cols,rows,minCellWidth=cellWidth?distance.parse(cellWidth):0,minCellHeight=cellHeight?distance.parse(cellHeight):0;if(col!==void 0)cols=col,rows=row??Math.ceil(itemsWithDims.length/cols);else if(row!==void 0)rows=row,cols=Math.ceil(itemsWithDims.length/rows);else if(availablePanelWidth!==void 0&&availablePanelHeight!==void 0){let maxItemWidth=Math.max(...itemsWithDims.map(b22=>b22.width),minCellWidth),maxItemHeight=Math.max(...itemsWithDims.map(b22=>b22.height),minCellHeight),maxCols=Math.max(1,Math.floor((availablePanelWidth+boardGap)/(maxItemWidth+boardGap))),maxRows=Math.max(1,Math.floor((availablePanelHeight+boardGap)/(maxItemHeight+boardGap)));cols=maxCols,rows=Math.ceil(itemsWithDims.length/cols),rows>maxRows&&(rows=maxRows,cols=Math.ceil(itemsWithDims.length/rows),cols>maxCols&&(cols=maxCols,rows=Math.ceil(itemsWithDims.length/cols))),cols=Math.max(1,cols),rows=Math.max(1,rows)}else cols=Math.ceil(Math.sqrt(itemsWithDims.length)),rows=Math.ceil(itemsWithDims.length/cols);let colWidths=Array(cols).fill(0),rowHeights=Array(rows).fill(0);itemsWithDims.forEach((item,i22)=>{let colIdx=i22%cols,rowIdx=Math.floor(i22/cols);rowIdx<rowHeights.length&&item.height>rowHeights[rowIdx]&&(rowHeights[rowIdx]=item.height),colIdx<colWidths.length&&item.width>colWidths[colIdx]&&(colWidths[colIdx]=item.width)});for(let i22=0;i22<colWidths.length;i22++)colWidths[i22]=Math.max(colWidths[i22],minCellWidth);for(let i22=0;i22<rowHeights.length;i22++)rowHeights[i22]=Math.max(rowHeights[i22],minCellHeight);let gridWidth=colWidths.reduce((a22,b22)=>a22+b22,0)+(cols>1?(cols-1)*boardGap:0),gridHeight=rowHeights.reduce((a22,b22)=>a22+b22,0)+(rows>1?(rows-1)*boardGap:0),startX=-gridWidth/2,startY=-gridHeight/2,colXOffsets=[startX];for(let i22=1;i22<cols;i22++)colXOffsets.push(colXOffsets[i22-1]+colWidths[i22-1]+boardGap);let rowYOffsets=[startY];for(let i22=1;i22<rows;i22++)rowYOffsets.push(rowYOffsets[i22-1]+rowHeights[i22-1]+boardGap);let positions=[];return itemsWithDims.forEach((itemWithDims,i22)=>{let colIdx=i22%cols,rowIdx=Math.floor(i22/cols);if(rowIdx>=rowYOffsets.length||colIdx>=colXOffsets.length)return;let x22=colXOffsets[colIdx]+colWidths[colIdx]/2,y22=rowYOffsets[rowIdx]+rowHeights[rowIdx]/2;positions.push({item:itemWithDims.item,pos:{x:x22,y:y22}})}),{positions,gridWidth,gridHeight}}function getItemDimensions(item,db22){if(item.componentName==="Board"){let board=item;if(db22&&board.pcb_board_id){let pcbBoard=db22.pcb_board.get(board.pcb_board_id);if(pcbBoard?.width!==void 0&&pcbBoard?.height!==void 0)return{width:pcbBoard.width,height:pcbBoard.height}}return getBoardDimensionsFromProps(board)}if(item.componentName==="Subpanel"){let subpanel=item,props=subpanel._parsedProps;if(props.width!==void 0&&props.height!==void 0)return{width:distance.parse(props.width),height:distance.parse(props.height)};let directBoards=subpanel._getDirectBoardChildren();if(directBoards.length===0){let allBoards=subpanel._getAllBoardInstances();if(allBoards.length===0)return{width:0,height:0};let minX=1/0,minY=1/0,maxX=-1/0,maxY=-1/0;for(let board of allBoards){let dims=getBoardDimensionsFromProps(board);if(dims.width===0||dims.height===0)continue;let offset2=board._panelPositionOffset??{x:0,y:0};minX=Math.min(minX,offset2.x-dims.width/2),maxX=Math.max(maxX,offset2.x+dims.width/2),minY=Math.min(minY,offset2.y-dims.height/2),maxY=Math.max(maxY,offset2.y+dims.height/2)}return minX===1/0?{width:0,height:0}:{width:maxX-minX,height:maxY-minY}}if(directBoards.length===1)return getBoardDimensionsFromProps(directBoards[0]);if(subpanel._cachedGridWidth>0&&subpanel._cachedGridHeight>0){let edgePadding=distance.parse(props.edgePadding??5);return{width:subpanel._cachedGridWidth+edgePadding*2,height:subpanel._cachedGridHeight+edgePadding*2}}let totalWidth=0,totalHeight=0;for(let board of directBoards){let dims=getBoardDimensionsFromProps(board);totalWidth=Math.max(totalWidth,dims.width),totalHeight=Math.max(totalHeight,dims.height)}return{width:totalWidth,height:totalHeight}}return{width:0,height:0}}var Subpanel=class _Subpanel extends Group5{constructor(){super(...arguments);__publicField(this,"pcb_panel_id",null);__publicField(this,"_panelizationFeaturesGenerated",!1);__publicField(this,"_cachedGridWidth",0);__publicField(this,"_cachedGridHeight",0);__publicField(this,"_panelPositionOffset",null)}get config(){return{componentName:"Subpanel",zodProps:subpanelProps}}get _errorComponentName(){return this.componentName.toLowerCase()}get isGroup(){return!0}get isSubcircuit(){return!0}_getPcbLayoutMode(){return"none"}doInitialSchematicComponentRender(){}doInitialSchematicLayout(){}doInitialSchematicTraceRender(){}add(component){if(component.lowercaseComponentName!=="board"&&component.lowercaseComponentName!=="subpanel")throw new Error(`<${this._errorComponentName}> can only contain <board> or <subpanel> elements`);super.add(component)}_computePcbGlobalTransformBeforeLayout(){if(this._panelPositionOffset){let parentTransform=this.parent?._computePcbGlobalTransformBeforeLayout?.()??identity();return compose2(parentTransform,translate2(this._panelPositionOffset.x,this._panelPositionOffset.y))}return super._computePcbGlobalTransformBeforeLayout()}_getAllBoardInstances(){let boards=[];for(let child of this.children)child instanceof Board?boards.push(child):child instanceof _Subpanel&&boards.push(...child._getAllBoardInstances());return boards}_containsBoards(){for(let child of this.children)if(child.componentName==="Board"||child.componentName==="Subpanel"&&"_containsBoards"in child&&child._containsBoards())return!0;return!1}_getDirectBoardChildren(){return this.children.filter(c22=>c22 instanceof Board)}doInitialPanelBoardLayout(){if(this.root?.pcbDisabled)return;let layoutMode=this._parsedProps.layoutMode??"none",gridItems=this.children.filter(c22=>c22 instanceof Board||c22 instanceof _Subpanel);if(layoutMode!=="none")for(let child of gridItems)child instanceof Board&&child._hasUserDefinedPcbPosition()&&this.root.db.source_property_ignored_warning.insert({source_component_id:child.source_component_id,property_name:"pcbX/pcbY",message:`Board has manual positioning but ${this._errorComponentName} layout mode is "${layoutMode}". Manual positioning will be ignored.`,error_type:"source_property_ignored_warning"});if(layoutMode==="none"&&gridItems.length>1&&gridItems.filter(c22=>!c22._hasUserDefinedPcbPosition()).length>1&&this.root.db.pcb_placement_error.insert({error_type:"pcb_placement_error",message:`Multiple boards/subpanels in ${this._errorComponentName} without positions. When layoutMode="none", each item must have explicit positioning. Use layoutMode="grid" for automatic positioning.`}),layoutMode!=="grid")return;let tabWidth=this._parsedProps.tabWidth??DEFAULT_TAB_WIDTH,boardGap=this._parsedProps.boardGap??tabWidth,availablePanelWidth,availablePanelHeight,hasExplicitRowOrCol=this._parsedProps.row!==void 0||this._parsedProps.col!==void 0,hasExplicitWidth=this._parsedProps.width!==void 0,hasExplicitHeight=this._parsedProps.height!==void 0;if(!hasExplicitRowOrCol&&hasExplicitWidth&&hasExplicitHeight){let{edgePadding:edgePaddingProp,edgePaddingLeft:edgePaddingLeftProp,edgePaddingRight:edgePaddingRightProp,edgePaddingTop:edgePaddingTopProp,edgePaddingBottom:edgePaddingBottomProp}=this._parsedProps,edgePadding=distance.parse(edgePaddingProp??5),edgePaddingLeft=distance.parse(edgePaddingLeftProp??edgePadding),edgePaddingRight=distance.parse(edgePaddingRightProp??edgePadding),edgePaddingTop=distance.parse(edgePaddingTopProp??edgePadding),edgePaddingBottom=distance.parse(edgePaddingBottomProp??edgePadding),panelWidth=distance.parse(this._parsedProps.width),panelHeight=distance.parse(this._parsedProps.height);availablePanelWidth=panelWidth-edgePaddingLeft-edgePaddingRight,availablePanelHeight=panelHeight-edgePaddingTop-edgePaddingBottom}let{positions,gridWidth,gridHeight}=packIntoGrid({items:gridItems,row:this._parsedProps.row,col:this._parsedProps.col,cellWidth:this._parsedProps.cellWidth,cellHeight:this._parsedProps.cellHeight,boardGap,availablePanelHeight,availablePanelWidth});this._cachedGridWidth=gridWidth,this._cachedGridHeight=gridHeight;for(let{item,pos}of positions)item._panelPositionOffset=pos}doInitialPanelLayout(){if(this.root?.pcbDisabled)return;let{db:db22}=this.root;if((this._parsedProps.layoutMode??"none")==="grid"){for(let child of this.children)if(child instanceof Board){if(!child.pcb_board_id||!child._panelPositionOffset)continue;db22.pcb_board.update(child.pcb_board_id,{position_mode:"relative_to_panel_anchor",display_offset_x:`${child._panelPositionOffset.x}mm`,display_offset_y:`${child._panelPositionOffset.y}mm`})}else if(child instanceof _Subpanel&&child._panelPositionOffset)for(let board of child._getAllBoardInstances()){if(!board.pcb_board_id)continue;let boardOffset=board._panelPositionOffset??{x:0,y:0};db22.pcb_board.update(board.pcb_board_id,{position_mode:"relative_to_panel_anchor",display_offset_x:`${child._panelPositionOffset.x+boardOffset.x}mm`,display_offset_y:`${child._panelPositionOffset.y+boardOffset.y}mm`})}this._updatePanelDimensions()}else{let panelGlobalPos=this._getGlobalPcbPositionBeforeLayout();for(let board of this._getDirectBoardChildren()){if(!board.pcb_board_id)continue;let boardDb=db22.pcb_board.get(board.pcb_board_id);if(!boardDb)continue;let relativeX=boardDb.center.x-panelGlobalPos.x,relativeY=boardDb.center.y-panelGlobalPos.y;db22.pcb_board.update(board.pcb_board_id,{position_mode:"relative_to_panel_anchor",display_offset_x:`${relativeX}mm`,display_offset_y:`${relativeY}mm`})}}this._generatePanelizationFeatures()}_updatePanelDimensions(){let{db:db22}=this.root,hasExplicitWidth=this._parsedProps.width!==void 0,hasExplicitHeight=this._parsedProps.height!==void 0,gridWidth=this._cachedGridWidth,gridHeight=this._cachedGridHeight;if(this.pcb_group_id){if(hasExplicitWidth&&hasExplicitHeight)db22.pcb_group.update(this.pcb_group_id,{width:distance.parse(this._parsedProps.width),height:distance.parse(this._parsedProps.height)});else if(gridWidth>0||gridHeight>0){let{edgePadding:edgePaddingProp,edgePaddingLeft:edgePaddingLeftProp,edgePaddingRight:edgePaddingRightProp,edgePaddingTop:edgePaddingTopProp,edgePaddingBottom:edgePaddingBottomProp}=this._parsedProps,edgePadding=distance.parse(edgePaddingProp??5),edgePaddingLeft=distance.parse(edgePaddingLeftProp??edgePadding),edgePaddingRight=distance.parse(edgePaddingRightProp??edgePadding),edgePaddingTop=distance.parse(edgePaddingTopProp??edgePadding),edgePaddingBottom=distance.parse(edgePaddingBottomProp??edgePadding);db22.pcb_group.update(this.pcb_group_id,{width:hasExplicitWidth?distance.parse(this._parsedProps.width):gridWidth+edgePaddingLeft+edgePaddingRight,height:hasExplicitHeight?distance.parse(this._parsedProps.height):gridHeight+edgePaddingTop+edgePaddingBottom})}}}_generatePanelizationFeatures(){if(this._panelizationFeaturesGenerated)return;let{db:db22}=this.root,props=this._parsedProps,panelizationMethod=props.panelizationMethod??"none",childBoardInstances=this._getAllBoardInstances();if(panelizationMethod!=="none"){let childBoardIds=childBoardInstances.map(c22=>c22.pcb_board_id).filter(id3=>!!id3),boardsInPanel=db22.pcb_board.list().filter(b22=>childBoardIds.includes(b22.pcb_board_id));if(boardsInPanel.length===0)return;let tabWidth=props.tabWidth??DEFAULT_TAB_WIDTH;if(panelizationMethod==="outline_routing"){let outlineRoutingCutouts=generatePanelOutlineRoutingCutouts(boardsInPanel,{cutoutWidth:tabWidth});for(let outlineRoutingCutout of outlineRoutingCutouts)db22.pcb_cutout.insert({...outlineRoutingCutout,pcb_group_id:this.pcb_group_id??void 0,pcb_panel_id:this.pcb_panel_id??void 0})}else{let boardGap=props.boardGap??tabWidth,{tabCutouts,mouseBiteHoles}=generatePanelTabsAndMouseBites(boardsInPanel,{boardGap,tabWidth,tabLength:props.tabLength??DEFAULT_TAB_LENGTH,mouseBites:props.mouseBites??!0});for(let tabCutout of tabCutouts)db22.pcb_cutout.insert(tabCutout);for(let mouseBiteHole of mouseBiteHoles)db22.pcb_hole.insert(mouseBiteHole)}}this._panelizationFeaturesGenerated=!0}doInitialPcbComponentRender(){if(!this.root?.pcbDisabled){if(!this._containsBoards())throw new Error(`<${this._errorComponentName}> must contain at least one <board>`);super.doInitialPcbComponentRender()}}},Panel=class extends Subpanel{get config(){return{componentName:"Panel",zodProps:panelProps}}doInitialPcbComponentRender(){if(this.root?.pcbDisabled)return;if(!this._containsBoards())throw new Error(`<${this._errorComponentName}> must contain at least one <board>`);let{db:db22}=this.root,props=this._parsedProps,inserted=db22.pcb_panel.insert({width:props.width!==void 0?distance.parse(props.width):0,height:props.height!==void 0?distance.parse(props.height):0,thickness:1.6,center:this._getGlobalPcbPositionBeforeLayout(),covered_with_solder_mask:!(props.noSolderMask??!1)});this.pcb_panel_id=inserted.pcb_panel_id}_updatePanelDimensions(){let{db:db22}=this.root,hasExplicitWidth=this._parsedProps.width!==void 0,hasExplicitHeight=this._parsedProps.height!==void 0,gridWidth=this._cachedGridWidth,gridHeight=this._cachedGridHeight;if(this.pcb_panel_id){if(hasExplicitWidth&&hasExplicitHeight)db22.pcb_panel.update(this.pcb_panel_id,{width:distance.parse(this._parsedProps.width),height:distance.parse(this._parsedProps.height)});else if(gridWidth>0||gridHeight>0){let{edgePadding:edgePaddingProp,edgePaddingLeft:edgePaddingLeftProp,edgePaddingRight:edgePaddingRightProp,edgePaddingTop:edgePaddingTopProp,edgePaddingBottom:edgePaddingBottomProp}=this._parsedProps,edgePadding=distance.parse(edgePaddingProp??5),edgePaddingLeft=distance.parse(edgePaddingLeftProp??edgePadding),edgePaddingRight=distance.parse(edgePaddingRightProp??edgePadding),edgePaddingTop=distance.parse(edgePaddingTopProp??edgePadding),edgePaddingBottom=distance.parse(edgePaddingBottomProp??edgePadding);db22.pcb_panel.update(this.pcb_panel_id,{width:hasExplicitWidth?distance.parse(this._parsedProps.width):gridWidth+edgePaddingLeft+edgePaddingRight,height:hasExplicitHeight?distance.parse(this._parsedProps.height):gridHeight+edgePaddingTop+edgePaddingBottom})}}}updatePcbComponentRender(){if(this.root?.pcbDisabled||!this.pcb_panel_id)return;let{db:db22}=this.root,props=this._parsedProps,currentPanel=db22.pcb_panel.get(this.pcb_panel_id);db22.pcb_panel.update(this.pcb_panel_id,{width:props.width!==void 0?distance.parse(props.width):currentPanel?.width,height:props.height!==void 0?distance.parse(props.height):currentPanel?.height,center:this._getGlobalPcbPositionBeforeLayout(),covered_with_solder_mask:!(props.noSolderMask??!1)})}removePcbComponentRender(){this.pcb_panel_id&&(this.root?.db.pcb_panel.delete(this.pcb_panel_id),this.pcb_panel_id=null)}},GENERATED_ANTENNA_KEEPOUT_CLEARANCE_MM=1,GENERATED_ANTENNA_FEED_OPENING_CLEARANCE_MM=1,getGeneratedAntennaKeepouts=geometry=>{let xCoordinates=geometry.route.map(point62=>point62.x),yCoordinates=geometry.route.map(point62=>point62.y),edgeClearance=geometry.traceWidth/2+GENERATED_ANTENNA_KEEPOUT_CLEARANCE_MM,left=Math.min(...xCoordinates)-edgeClearance,right=Math.max(...xCoordinates)+edgeClearance,bottom=Math.min(...yCoordinates)-edgeClearance,top=Math.max(...yCoordinates)+edgeClearance,feedOpeningPoints=[geometry.feedPoint,...geometry.secondaryPort?[geometry.secondaryPort.point]:[]],openingLeft=Math.min(...feedOpeningPoints.map(point62=>point62.x))-GENERATED_ANTENNA_FEED_OPENING_CLEARANCE_MM,openingRight=Math.max(...feedOpeningPoints.map(point62=>point62.x))+GENERATED_ANTENNA_FEED_OPENING_CLEARANCE_MM,openingBottom=Math.min(...feedOpeningPoints.map(point62=>point62.y))-GENERATED_ANTENNA_FEED_OPENING_CLEARANCE_MM,openingTop=Math.max(...feedOpeningPoints.map(point62=>point62.y))+GENERATED_ANTENNA_FEED_OPENING_CLEARANCE_MM,rects=[],addRect=(rectLeft,rectRight,rectBottom,rectTop)=>{rectRight<=rectLeft||rectTop<=rectBottom||rects.push({center:{x:(rectLeft+rectRight)/2,y:(rectBottom+rectTop)/2},width:rectRight-rectLeft,height:rectTop-rectBottom})};return geometry.feedKeepoutOpeningDirection==="left"?(addRect(left,right,openingTop,top),addRect(left,right,bottom,openingBottom),addRect(openingRight,right,openingBottom,openingTop)):(addRect(left,openingLeft,bottom,openingTop),addRect(openingRight,right,bottom,openingTop),addRect(left,right,openingTop,top)),rects},getGeneratedAntennaGeometry=antennaShape3=>{switch(antennaShape3){case"2.4ghz_quarter_wave_monopole":return{traceWidth:.6,feedPoint:{x:0,y:0},feedKeepoutOpeningDirection:"left",route:[{x:0,y:0},{x:31,y:0}]};case"2.4ghz_meandered_monopole":return{traceWidth:.5,feedPoint:{x:0,y:0},feedKeepoutOpeningDirection:"bottom",route:[{x:0,y:0},{x:0,y:6},{x:3,y:6},{x:3,y:1.5},{x:6,y:1.5},{x:6,y:6},{x:9,y:6},{x:9,y:1.5},{x:12,y:1.5},{x:12,y:6},{x:15,y:6}]};case"2.4ghz_inverted_f":return{traceWidth:.8,feedPoint:{x:0,y:0},feedKeepoutOpeningDirection:"bottom",secondaryPort:{point:{x:-4,y:0},role:"ground"},groundViaPoint:{x:-4,y:0},route:[{x:-4,y:0},{x:-4,y:3},{x:0,y:3},{x:0,y:0},{x:0,y:3},{x:-4,y:3},{x:-4,y:8},{x:22,y:8}]};case"2.4ghz_meandered_inverted_f":return{traceWidth:.5,feedPoint:{x:0,y:0},feedKeepoutOpeningDirection:"bottom",secondaryPort:{point:{x:-1.7,y:0},role:"ground"},groundViaPoint:{x:-1.7,y:0},route:[{x:-1.7,y:0},{x:-1.7,y:4.9},{x:0,y:4.9},{x:0,y:0},{x:0,y:4.9},{x:-1.7,y:4.9},{x:2.3,y:4.9},{x:2.3,y:1.4},{x:5.3,y:1.4},{x:5.3,y:4.9},{x:8.3,y:4.9},{x:8.3,y:1.4},{x:11.3,y:1.4},{x:11.3,y:4.9},{x:13.3,y:4.9}]};case"2.4ghz_folded_dipole":return{traceWidth:.9,feedPoint:{x:0,y:0},feedKeepoutOpeningDirection:"bottom",secondaryPort:{point:{x:1.2,y:0},role:"feed2"},route:[{x:0,y:0},{x:-22.4,y:0},{x:-22.4,y:9},{x:23.6,y:9},{x:23.6,y:0},{x:1.2,y:0}]}}},Antenna=class extends NormalComponent{get config(){return{componentName:"Antenna",zodProps:antennaProps,sourceFtype:FTYPE.simple_chip,shouldRenderAsSchematicBox:!0}}getRefDesPrefixes(){return["ANT"]}initPorts(){let{antennaShape:antennaShape3,pcbPath:pcbPath3}=this._parsedProps,secondaryPortRole=pcbPath3?void 0:antennaShape3==="2.4ghz_inverted_f"||antennaShape3==="2.4ghz_meandered_inverted_f"?"ground":antennaShape3==="2.4ghz_folded_dipole"?"feed2":void 0;super.initPorts({pinCount:secondaryPortRole?2:1,additionalAliases:{pin1:secondaryPortRole==="feed2"?["feed","feed1"]:["feed"],...secondaryPortRole==="ground"?{pin2:["ground","gnd"]}:secondaryPortRole==="feed2"?{pin2:["feed2"]}:{}}})}doInitialReactSubtreesRender(){super.doInitialReactSubtreesRender();let{antennaShape:antennaShape3,pcbPath:pcbPath3}=this._parsedProps;if(!antennaShape3)return;let hasFootprint=this.children.some(child=>child.componentName==="Footprint");if(pcbPath3&&hasFootprint)return;let geometry=pcbPath3?void 0:getGeneratedAntennaGeometry(antennaShape3),generatedFootprint=new Footprint({name:`${this.name}_generated_antenna`});if(hasFootprint||generatedFootprint.add(new SmtPad({shape:"rect",width:.8,height:.8,pcbX:geometry?.feedPoint.x??0,pcbY:geometry?.feedPoint.y??0,layer:"top",portHints:["pin1"],coveredWithSolderMask:!0})),geometry){let keepouts=getGeneratedAntennaKeepouts(geometry);for(let keepout of keepouts)generatedFootprint.add(new Keepout({shape:"rect",pcbX:keepout.center.x,pcbY:keepout.center.y,width:keepout.width,height:keepout.height,layers:[...this.root?._getBoard()?.allLayers??["top","bottom"]],excludeRefs:[this.getSubcircuitSelector()]}));let antennaTrace=new PcbTrace({route:geometry.route.map(point62=>({route_type:"wire",...point62,width:geometry.traceWidth,layer:"top"}))});antennaTrace.isAntennaTrace=!0,generatedFootprint.add(antennaTrace),geometry.secondaryPort&&!geometry.groundViaPoint&&!hasFootprint&&generatedFootprint.add(new SmtPad({shape:"rect",width:.8,height:.8,pcbX:geometry.secondaryPort.point.x,pcbY:geometry.secondaryPort.point.y,layer:"top",portHints:["pin2"],coveredWithSolderMask:!0})),geometry.groundViaPoint&&generatedFootprint.add(new PlatedHole({shape:"circle",pcbX:geometry.groundViaPoint.x,pcbY:geometry.groundViaPoint.y,holeDiameter:.3,outerDiameter:.7,portHints:["pin2"],coveredWithSolderMask:!0}))}this.add(generatedFootprint)}doInitialCreateTracesFromProps(){super.doInitialCreateTracesFromProps();let{pcbPath:pcbPath3}=this._parsedProps;if(!pcbPath3)return;let antennaTrace=new Trace({name:`${this.name}_pcb_path`,path:[`${this.getSubcircuitSelector()} > port.pin1`],pcbPath:pcbPath3});antennaTrace.isAntennaTrace=!0,this.add(antennaTrace)}},Pinout=class extends Chip{constructor(props){super(props)}get config(){return{...super.config,componentName:"Pinout",zodProps:pinoutProps}}doInitialSourceRender(){let{db:db22}=this.root,{_parsedProps:props}=this,source_component=db22.source_component.insert({ftype:"simple_pinout",name:this.name,manufacturer_part_number:resolveManufacturerPartNumber(props),supplier_part_numbers:props.supplierPartNumbers,display_name:props.displayName});this.source_component_id=source_component.source_component_id}},Fuse=class extends NormalComponent{get config(){return{componentName:"fuse",schematicSymbolName:this.props.symbolName??"fuse",zodProps:fuseProps,sourceFtype:FTYPE.simple_fuse}}_getSchematicSymbolDisplayValue(){if(this._parsedProps.schShowRatings===!1)return"";let rawCurrent=this._parsedProps.currentRating,rawVoltage=this._parsedProps.voltageRating,current3=parseAndConvertSiUnit(rawCurrent,"A").value,voltage23=parseAndConvertSiUnit(rawVoltage,"V").value;return`${formatSiUnit(current3)}A / ${formatSiUnit(voltage23)}V`}doInitialSourceRender(){let{db:db22}=this.root,{_parsedProps:props}=this,currentRating=parseAndConvertSiUnit(props.currentRating,"A").value,voltageRating=parseAndConvertSiUnit(props.voltageRating,"V").value,display_current_rating,display_voltage_rating;props.schShowRatings!==!1&&(display_current_rating=`${formatSiUnit(currentRating)}A`,display_voltage_rating=`${formatSiUnit(voltageRating)}V`);let source_component=db22.source_component.insert({name:this.name,ftype:FTYPE.simple_fuse,manufacturer_part_number:resolveManufacturerPartNumber(props),supplier_part_numbers:props.supplierPartNumbers,...currentRating!=null?{current_rating_amps:currentRating}:{},...voltageRating!=null?{voltage_rating_volts:voltageRating}:{},display_current_rating,display_voltage_rating,display_name:props.displayName});this.source_component_id=source_component.source_component_id}},Jumper=class extends NormalComponent{constructor(){super(...arguments);__publicField(this,"schematicDimensions",null)}get config(){return{schematicSymbolName:void 0,componentName:"Jumper",zodProps:jumperProps,shouldRenderAsSchematicBox:!0}}_getSchematicPortArrangement(){let arrangement=super._getSchematicPortArrangement();if(arrangement&&Object.keys(arrangement).length>0)return arrangement;let pinCount=this._parsedProps.pinCount??(Array.isArray(this._parsedProps.pinLabels)?this._parsedProps.pinLabels.length:this._parsedProps.pinLabels?Object.keys(this._parsedProps.pinLabels).length:this.getPortsFromFootprint().length),direction3=this._parsedProps.schDirection??"right";return{leftSize:direction3==="left"?pinCount:0,rightSize:direction3==="right"?pinCount:0}}doInitialSourceRender(){let{db:db22}=this.root,{_parsedProps:props}=this,{pcbX,pcbY}=this.getResolvedPcbPositionProp(),source_component=db22.source_component.insert({ftype:"simple_chip",name:this.name,manufacturer_part_number:resolveManufacturerPartNumber(props),supplier_part_numbers:props.supplierPartNumbers,are_pins_interchangeable:!0,display_name:props.displayName});this.source_component_id=source_component.source_component_id}doInitialPcbComponentRender(){if(this.root?.pcbDisabled)return;let{db:db22}=this.root,{_parsedProps:props}=this,{pcbX,pcbY}=this.getResolvedPcbPositionProp(),globalTransformRotation=this.getGlobalTransformRotation(),pcb_component3=db22.pcb_component.insert({center:{x:pcbX,y:pcbY},width:2,height:3,layer:props.layer??"top",rotation:normalizeDegrees(globalTransformRotation),insertion_direction:this._getPcbComponentInsertionDirection(props.layer??"top",globalTransformRotation),source_component_id:this.source_component_id,subcircuit_id:this.getSubcircuit().subcircuit_id??void 0,do_not_place:props.doNotPlace??!1,obstructs_within_bounds:props.obstructsWithinBounds??!0,is_allowed_to_be_off_board:props.allowOffBoard??!1,metadata:props.kicadFootprintMetadata?{kicad_footprint:props.kicadFootprintMetadata}:void 0});this.pcb_component_id=pcb_component3.pcb_component_id}doInitialPcbPortAttachment(){let{db:db22}=this.root,pcb_ports=db22.pcb_port.list({pcb_component_id:this.pcb_component_id}),pinLabelToPortId={};for(let i22=0;i22<pcb_ports.length;i22++){let port=pcb_ports[i22],sourcePort=db22.source_port.get(port.source_port_id),pinLabel="";if(typeof sourcePort?.pin_number=="number")pinLabel=sourcePort.pin_number.toString();else if(Array.isArray(sourcePort?.port_hints)){let matchedHint=sourcePort.port_hints.find(h22=>/^(pin)?\d+$/.test(h22));matchedHint&&(/^pin\d+$/.test(matchedHint)?pinLabel=matchedHint.replace(/^pin/,""):pinLabel=matchedHint)}pinLabelToPortId[pinLabel]=port.pcb_port_id}let traces=db22.pcb_trace.list({pcb_component_id:this.pcb_component_id}),updatePortId=portId=>{if(portId&&typeof portId=="string"&&portId.startsWith("{PIN")){let pin=portId.replace("{PIN","").replace("}","");return pinLabelToPortId[pin]||portId}return portId};for(let trace of traces)if(trace.route)for(let segment2 of trace.route)segment2.route_type==="wire"&&(segment2.start_pcb_port_id=updatePortId(segment2.start_pcb_port_id),segment2.end_pcb_port_id=updatePortId(segment2.end_pcb_port_id))}},INTERCONNECT_STANDARD_FOOTPRINTS={"0402":"0402","0603":"0603","0805":"0805",1206:"1206"},Interconnect=class extends NormalComponent{get config(){return{componentName:"Interconnect",zodProps:interconnectProps,shouldRenderAsSchematicBox:!0,sourceFtype:"interconnect"}}get defaultInternallyConnectedPinNames(){let{standard}=this._parsedProps;return standard&&INTERCONNECT_STANDARD_FOOTPRINTS[standard]?[["pin1","pin2"]]:[]}_getImpliedFootprintString(){let{standard}=this._parsedProps;return standard?INTERCONNECT_STANDARD_FOOTPRINTS[standard]??null:null}doInitialSourceRender(){let{db:db22}=this.root,{_parsedProps:props}=this,source_component=db22.source_component.insert({ftype:"interconnect",name:this.name,manufacturer_part_number:resolveManufacturerPartNumber(props),supplier_part_numbers:props.supplierPartNumbers,are_pins_interchangeable:!0,display_name:props.displayName});this.source_component_id=source_component.source_component_id}doInitialSourceParentAttachment(){let{db:db22}=this.root,internallyConnectedPorts=this._getInternallyConnectedPins();for(let ports of internallyConnectedPorts){let sourcePortIds=ports.map(port=>port.source_port_id).filter(id3=>id3!==null);sourcePortIds.length>=2&&db22.source_component_internal_connection.insert({source_component_id:this.source_component_id,subcircuit_id:this.getSubcircuit()?.subcircuit_id,source_port_ids:sourcePortIds})}}},SolderJumper=class extends NormalComponent{constructor(){super(...arguments);__publicField(this,"schematicDimensions",null)}_getPinCountFromFootprintString(footprint){let match2=footprint.match(/^solderjumper([23])(?:_|$)/);return match2?Number(match2[1]):null}_getPinNumberFromBridgedPinsProp(pinName){let numericPinMatch=pinName.match(/^(?:pin)?(\d+)$/i);if(numericPinMatch)return Number(numericPinMatch[1]);let pinLabels=this._parsedProps.pinLabels??this.props.pinLabels;if(Array.isArray(pinLabels)){let labelIndex=pinLabels.findIndex(label=>label===pinName);return labelIndex>=0?labelIndex+1:null}if(pinLabels&&typeof pinLabels=="object")for(let[pinKey,labelOrLabels]of Object.entries(pinLabels)){if(!(Array.isArray(labelOrLabels)?labelOrLabels:[labelOrLabels]).includes(pinName))continue;let pinNumberMatch=pinKey.match(/^(?:pin)?(\d+)$/i);return pinNumberMatch?Number(pinNumberMatch[1]):null}return null}_getBridgedPinNumbersForFootprint(pinCount){let props=this._parsedProps??this.props;return Array.isArray(props.bridgedPins)&&props.bridgedPins.length>0?Array.from(new Set(props.bridgedPins.flat().map(pinName=>this._getPinNumberFromBridgedPinsProp(pinName)).filter(pinNumber=>pinNumber!==null&&pinNumber>=1&&pinNumber<=pinCount))).sort((a22,b22)=>a22-b22):props.bridged?Array.from({length:pinCount},(_22,index2)=>index2+1):[]}resolveFootprint(){let footprint=super.resolveFootprint();if(typeof footprint!="string")return footprint;let pinCount=this._getPinCountFromFootprintString(footprint);if(!pinCount||/_bridged\d+/.test(footprint))return footprint;let bridgedPinNumbers=this._getBridgedPinNumbersForFootprint(pinCount);return bridgedPinNumbers.length===0?footprint:footprint.replace(/^solderjumper[23]/,`solderjumper${pinCount}_bridged${bridgedPinNumbers.join("")}`)}_getPinNumberFromBridgedPinName(pinName){return this.selectOne(`port.${pinName}`,{type:"port"})?._parsedProps.pinNumber??null}get defaultInternallyConnectedPinNames(){if(this._parsedProps.bridged){let pins=this.children.filter(c22=>c22.componentName==="Port").map(p22=>p22.name);return pins.length>0?[pins]:[]}return this._parsedProps.bridgedPins??[]}get config(){let props=this._parsedProps??this.props,resolvedPinCount=props.pinCount;if(props.pinCount==null&&!props.footprint&&(resolvedPinCount=2),props.pinCount==null){let nums=(props.bridgedPins??[]).flat().map(p_str=>this._getPinNumberFromBridgedPinName(p_str)).filter(n22=>n22!==null),maxPinFromBridged=nums.length>0?Math.max(...nums):0,pinCountFromLabels=props.pinLabels?Object.keys(props.pinLabels).length:0,finalPinCount=Math.max(maxPinFromBridged,pinCountFromLabels);(finalPinCount===2||finalPinCount===3)&&(resolvedPinCount=finalPinCount),resolvedPinCount==null&&props.footprint&&[2,3].includes(this.getPortsFromFootprint().length)&&(resolvedPinCount=this.getPortsFromFootprint().length)}let symbolName="";resolvedPinCount?symbolName+=`solderjumper${resolvedPinCount}`:symbolName="solderjumper";let bridgedPinNumbers=[];return Array.isArray(props.bridgedPins)&&props.bridgedPins.length>0?bridgedPinNumbers=Array.from(new Set(props.bridgedPins.flat().map(pinName=>this._getPinNumberFromBridgedPinName(pinName)).filter(n22=>n22!==null))).sort((a22,b22)=>a22-b22):props.bridged&&resolvedPinCount&&(bridgedPinNumbers=Array.from({length:resolvedPinCount},(_22,i22)=>i22+1)),bridgedPinNumbers.length>0&&(symbolName+=`_bridged${bridgedPinNumbers.join("")}`),{schematicSymbolName:props.symbolName??symbolName,componentName:"SolderJumper",zodProps:solderjumperProps,shouldRenderAsSchematicBox:!0}}_getSchematicPortArrangement(){let arrangement=super._getSchematicPortArrangement();if(arrangement&&Object.keys(arrangement).length>0)return arrangement;let pinCount=this._parsedProps.pinCount??(Array.isArray(this._parsedProps.pinLabels)?this._parsedProps.pinLabels.length:this._parsedProps.pinLabels?Object.keys(this._parsedProps.pinLabels).length:this.getPortsFromFootprint().length);pinCount==null&&!this._parsedProps.footprint&&(pinCount=2);let direction3=this._parsedProps.schDirection??"right";return{leftSize:direction3==="left"?pinCount:0,rightSize:direction3==="right"?pinCount:0}}doInitialSourceRender(){let{db:db22}=this.root,{_parsedProps:props}=this,{pcbX,pcbY}=this.getResolvedPcbPositionProp(),source_component=db22.source_component.insert({ftype:"simple_chip",name:this.name,manufacturer_part_number:resolveManufacturerPartNumber(props),supplier_part_numbers:props.supplierPartNumbers,are_pins_interchangeable:!0,display_name:props.displayName});this.source_component_id=source_component.source_component_id}doInitialPcbComponentRender(){if(this.root?.pcbDisabled)return;let{db:db22}=this.root,{_parsedProps:props}=this,{pcbX,pcbY}=this.getResolvedPcbPositionProp(),globalTransformRotation=this.getGlobalTransformRotation(),pcb_component3=db22.pcb_component.insert({center:{x:pcbX,y:pcbY},width:2,height:3,layer:props.layer??"top",rotation:normalizeDegrees(globalTransformRotation),insertion_direction:this._getPcbComponentInsertionDirection(props.layer??"top",globalTransformRotation),source_component_id:this.source_component_id,subcircuit_id:this.getSubcircuit().subcircuit_id??void 0,do_not_place:props.doNotPlace??!1,obstructs_within_bounds:props.obstructsWithinBounds??!0,is_allowed_to_be_off_board:props.allowOffBoard??!1,metadata:props.kicadFootprintMetadata?{kicad_footprint:props.kicadFootprintMetadata}:void 0});this.pcb_component_id=pcb_component3.pcb_component_id}doInitialPcbPortAttachment(){let{db:db22}=this.root,pcb_ports=db22.pcb_port.list({pcb_component_id:this.pcb_component_id}),pinLabelToPortId={};for(let i22=0;i22<pcb_ports.length;i22++){let port=pcb_ports[i22],sourcePort=db22.source_port.get(port.source_port_id),pinLabel="";if(typeof sourcePort?.pin_number=="number")pinLabel=sourcePort.pin_number.toString();else if(Array.isArray(sourcePort?.port_hints)){let matchedHint=sourcePort.port_hints.find(h22=>/^(pin)?\d+$/.test(h22));matchedHint&&(/^pin\d+$/.test(matchedHint)?pinLabel=matchedHint.replace(/^pin/,""):pinLabel=matchedHint)}pinLabelToPortId[pinLabel]=port.pcb_port_id}let traces=db22.pcb_trace.list({pcb_component_id:this.pcb_component_id}),updatePortId=portId=>{if(portId&&typeof portId=="string"&&portId.startsWith("{PIN")){let pin=portId.replace("{PIN","").replace("}","");return pinLabelToPortId[pin]||portId}return portId};for(let trace of traces)if(trace.route)for(let segment2 of trace.route)segment2.route_type==="wire"&&(segment2.start_pcb_port_id=updatePortId(segment2.start_pcb_port_id),segment2.end_pcb_port_id=updatePortId(segment2.end_pcb_port_id))}},PowerSource=class extends NormalComponent{constructor(){super(...arguments);__publicField(this,"pos",this.portMap.pin1);__publicField(this,"positive",this.portMap.pin1);__publicField(this,"neg",this.portMap.pin2);__publicField(this,"negative",this.portMap.pin2)}get config(){return{schematicSymbolName:this.props.symbolName??"power_factor_meter_horz",componentName:"PowerSource",zodProps:powerSourceProps,sourceFtype:"simple_power_source"}}initPorts(){this.add(new Port({name:"pin1",pinNumber:1,aliases:["positive","pos"]})),this.add(new Port({name:"pin2",pinNumber:2,aliases:["negative","neg"]}))}doInitialSourceRender(){let{db:db22}=this.root,{_parsedProps:props}=this,source_component=db22.source_component.insert({ftype:"simple_power_source",name:this.name,voltage:props.voltage,supplier_part_numbers:props.supplierPartNumbers,manufacturer_part_number:resolveManufacturerPartNumber(props),are_pins_interchangeable:!1,display_name:props.displayName});this.source_component_id=source_component.source_component_id}},VoltageSource2=class extends NormalComponent{constructor(){super(...arguments);__publicField(this,"simulation_voltage_source_id",null);__publicField(this,"terminal1",this.portMap.terminal1);__publicField(this,"terminal2",this.portMap.terminal2)}get config(){return{componentName:"VoltageSource",schematicSymbolName:this.props.waveShape==="square"?"square_wave":"ac_voltmeter",zodProps:voltageSourceProps,sourceFtype:"simple_voltage_source"}}runRenderPhaseForChildren(phase){if(!phase.startsWith("Pcb"))for(let child of this.children)child.runRenderPhaseForChildren(phase),child.runRenderPhase(phase)}doInitialPcbComponentRender(){let hasExplicitPcbPosition=this._hasUserDefinedPcbPosition();if(!this._parsedProps.footprint){if(!hasExplicitPcbPosition)return;throw new Error("VoltageSource requires a footprint when pcbX/pcbY or pcb edge position props are used")}super.doInitialPcbComponentRender()}initPorts(){super.initPorts({additionalAliases:{pin1:["terminal1"],pin2:["terminal2"]}})}_getSchematicSymbolDisplayValue(){let{voltage:voltage23,frequency:frequency23}=this._parsedProps,parts=[];return voltage23!==void 0&&parts.push(`${formatSiUnit(voltage23)}V`),frequency23!==void 0&&parts.push(`${formatSiUnit(frequency23)}Hz`),parts.length>0?parts.join(" "):void 0}doInitialSourceRender(){let{db:db22}=this.root,{_parsedProps:props}=this,source_component=db22.source_component.insert({ftype:"simple_voltage_source",name:this.name,voltage:props.voltage,frequency:props.frequency,peak_to_peak_voltage:props.peakToPeakVoltage,wave_shape:props.waveShape,phase:props.phase,duty_cycle:props.dutyCycle,pulse_delay:props.pulseDelay,rise_time:props.riseTime,fall_time:props.fallTime,pulse_width:props.pulseWidth,period:props.period,supplier_part_numbers:props.supplierPartNumbers,manufacturer_part_number:resolveManufacturerPartNumber(props),are_pins_interchangeable:!0,display_name:props.displayName});this.source_component_id=source_component.source_component_id}doInitialSimulationRender(){let{db:db22}=this.root,{_parsedProps:props}=this,terminal1Port=this.portMap.terminal1,terminal2Port=this.portMap.terminal2,simulationVoltageSource=db22.simulation_voltage_source.insert({is_dc_source:!1,terminal1_source_port_id:terminal1Port.source_port_id??void 0,terminal2_source_port_id:terminal2Port.source_port_id??void 0,voltage:props.voltage,frequency:props.frequency,peak_to_peak_voltage:props.peakToPeakVoltage,wave_shape:props.waveShape,phase:props.phase,duty_cycle:props.dutyCycle,pulse_delay:props.pulseDelay,rise_time:props.riseTime,fall_time:props.fallTime,pulse_width:props.pulseWidth,period:props.period,ac_magnitude:props.acMagnitude,ac_phase:props.acPhase});this.simulation_voltage_source_id=simulationVoltageSource.simulation_voltage_source_id}},CurrentSource2=class extends NormalComponent{constructor(){super(...arguments);__publicField(this,"simulation_current_source_id",null);__publicField(this,"pos",this.portMap.pos);__publicField(this,"neg",this.portMap.neg)}get config(){return{componentName:"CurrentSource",schematicSymbolName:"current_source",zodProps:currentSourceProps,sourceFtype:"simple_current_source"}}runRenderPhaseForChildren(phase){if(!phase.startsWith("Pcb"))for(let child of this.children)child.runRenderPhaseForChildren(phase),child.runRenderPhase(phase)}doInitialPcbComponentRender(){let hasExplicitPcbPosition=this._hasUserDefinedPcbPosition();if(!this._parsedProps.footprint){if(!hasExplicitPcbPosition)return;throw new Error("CurrentSource requires a footprint when pcbX/pcbY or pcb edge position props are used")}super.doInitialPcbComponentRender()}initPorts(){super.initPorts({additionalAliases:{pin1:["pos"],pin2:["neg"]}})}_getSchematicSymbolDisplayValue(){let{current:current3,frequency:frequency23,peakToPeakCurrent}=this._parsedProps,parts=[];return current3!==void 0&&parts.push(`${formatSiUnit(current3)}A`),peakToPeakCurrent!==void 0&&parts.push(`${formatSiUnit(peakToPeakCurrent)}A p-p`),frequency23!==void 0&&parts.push(`${formatSiUnit(frequency23)}Hz`),parts.length>0?parts.join(" "):void 0}doInitialSourceRender(){let{db:db22}=this.root,{_parsedProps:props}=this,source_component=db22.source_component.insert({ftype:"simple_current_source",name:this.name,current:props.current,frequency:props.frequency,peak_to_peak_current:props.peakToPeakCurrent,wave_shape:props.waveShape,phase:props.phase,duty_cycle:props.dutyCycle,supplier_part_numbers:props.supplierPartNumbers,manufacturer_part_number:resolveManufacturerPartNumber(props),are_pins_interchangeable:!0,display_name:props.displayName});this.source_component_id=source_component.source_component_id}doInitialSimulationRender(){let{db:db22}=this.root,{_parsedProps:props}=this,isAc=props.frequency!==void 0||props.peakToPeakCurrent!==void 0||props.waveShape!==void 0||props.acMagnitude!==void 0||props.acPhase!==void 0,posPort=this.portMap.pos,negPort=this.portMap.neg;if(isAc){let simulationCurrentSource=db22.simulation_current_source.insert({is_dc_source:!1,terminal1_source_port_id:posPort.source_port_id??void 0,terminal2_source_port_id:negPort.source_port_id??void 0,current:props.current,frequency:props.frequency,peak_to_peak_current:props.peakToPeakCurrent,wave_shape:props.waveShape,phase:props.phase,duty_cycle:props.dutyCycle,ac_magnitude:props.acMagnitude,ac_phase:props.acPhase});this.simulation_current_source_id=simulationCurrentSource.simulation_current_source_id}else{if(props.current===void 0)return;let simulationCurrentSource=db22.simulation_current_source.insert({is_dc_source:!0,positive_source_port_id:posPort.source_port_id??void 0,negative_source_port_id:negPort.source_port_id??void 0,current:props.current,ac_magnitude:props.acMagnitude,ac_phase:props.acPhase});this.simulation_current_source_id=simulationCurrentSource.simulation_current_source_id}}},PLACEMENT_MARGIN=.25,rectForComponent=(component,margin)=>({left:component.center.x-component.size.width/2-margin,right:component.center.x+component.size.width/2+margin,bottom:component.center.y-component.size.height/2-margin,top:component.center.y+component.size.height/2+margin}),rectsOverlap4=(a22,b22)=>a22.left<b22.right&&a22.right>b22.left&&a22.bottom<b22.top&&a22.top>b22.bottom,getCandidateCenters=({baseCenter,size:size3})=>{let xStep=size3.width+PLACEMENT_MARGIN*2,yStep=size3.height+PLACEMENT_MARGIN*2;return[baseCenter,{x:baseCenter.x,y:baseCenter.y+yStep},{x:baseCenter.x,y:baseCenter.y-yStep},{x:baseCenter.x+xStep,y:baseCenter.y},{x:baseCenter.x-xStep,y:baseCenter.y},{x:baseCenter.x+xStep,y:baseCenter.y+yStep},{x:baseCenter.x-xStep,y:baseCenter.y+yStep},{x:baseCenter.x+xStep,y:baseCenter.y-yStep},{x:baseCenter.x-xStep,y:baseCenter.y-yStep},{x:baseCenter.x,y:baseCenter.y+yStep*2},{x:baseCenter.x,y:baseCenter.y-yStep*2}]},getConnectedSchematicPort=({ammeterSourcePortId,schematicPorts,sourceTraces})=>{for(let sourceTrace of sourceTraces){if(!sourceTrace.connected_source_port_ids.includes(ammeterSourcePortId))continue;let connectedSourcePortId=sourceTrace.connected_source_port_ids.find(sourcePortId=>sourcePortId!==ammeterSourcePortId);if(connectedSourcePortId===void 0)continue;let schematicPort=schematicPorts.find(port=>port.source_port_id===connectedSourcePortId);if(schematicPort)return schematicPort}return null},midpoint22=ports=>({x:ports.reduce((sum,port)=>sum+port.center.x,0)/ports.length,y:ports.reduce((sum,port)=>sum+port.center.y,0)/ports.length}),shiftAmmeterSchematicElements=({ammeter,db:db22,oldCenter,newCenter})=>{let schematicComponentId=ammeter.schematic_component_id;if(!schematicComponentId)return;let deltaX=newCenter.x-oldCenter.x,deltaY=newCenter.y-oldCenter.y;if(!(deltaX===0&&deltaY===0)){db22.schematic_component.update(schematicComponentId,{center:newCenter});for(let port of db22.schematic_port.list({schematic_component_id:schematicComponentId}))db22.schematic_port.update(port.schematic_port_id,{center:{x:port.center.x+deltaX,y:port.center.y+deltaY}});for(let text of db22.schematic_text.list({schematic_component_id:schematicComponentId}))db22.schematic_text.update(text.schematic_text_id,{position:{x:text.position.x+deltaX,y:text.position.y+deltaY}});updateSchematicPrimitivesForLayoutShift({db:db22,schematicComponentId,deltaX,deltaY})}},Ammeter_doInitialSchematicLayout=ammeter=>{let{root}=ammeter;if(!root||root.schematicDisabled||!ammeter.schematic_component_id||ammeter._parsedProps.schX!==void 0||ammeter._parsedProps.schY!==void 0||ammeter.getGroup()?._getSchematicLayoutMode()!=="relative")return;let{db:db22}=root,schematicComponent=db22.schematic_component.get(ammeter.schematic_component_id);if(!schematicComponent)return;let ammeterSourcePortIds=[ammeter.portMap.pos.source_port_id,ammeter.portMap.neg.source_port_id].filter(sourcePortId=>typeof sourcePortId=="string");if(ammeterSourcePortIds.length===0)return;let schematicPorts=db22.schematic_port.list(),sourceTraces=db22.source_trace.list(),connectedSchematicPorts=ammeterSourcePortIds.map(ammeterSourcePortId=>getConnectedSchematicPort({ammeterSourcePortId,schematicPorts,sourceTraces})).filter(port=>port!==null);if(connectedSchematicPorts.length===0)return;let baseCenter=midpoint22(connectedSchematicPorts),obstacles=db22.schematic_component.list().filter(component=>component.schematic_component_id!==schematicComponent.schematic_component_id&&!component.is_schematic_group&&component.schematic_sheet_id===schematicComponent.schematic_sheet_id).map(component=>rectForComponent(component,PLACEMENT_MARGIN)),bestCenter=getCandidateCenters({baseCenter,size:schematicComponent.size}).find(candidateCenter=>{let candidateRect=rectForComponent({...schematicComponent,center:candidateCenter},PLACEMENT_MARGIN);return!obstacles.some(obstacle=>rectsOverlap4(candidateRect,obstacle))})??baseCenter;shiftAmmeterSchematicElements({ammeter,db:db22,oldCenter:schematicComponent.center,newCenter:bestCenter})},Ammeter=class extends NormalComponent{constructor(){super(...arguments);__publicField(this,"simulation_current_probe_id",null);__publicField(this,"pos",this.portMap.pos);__publicField(this,"neg",this.portMap.neg)}get config(){return{componentName:"Ammeter",schematicSymbolName:"dc_ammeter",zodProps:ammeterProps,sourceFtype:"simple_ammeter"}}runRenderPhaseForChildren(phase){if(!phase.startsWith("Pcb"))for(let child of this.children)child.runRenderPhaseForChildren(phase),child.runRenderPhase(phase)}doInitialPcbComponentRender(){let hasExplicitPcbPosition=this._hasUserDefinedPcbPosition();if(!this._parsedProps.footprint){if(!hasExplicitPcbPosition)return;throw new Error("Ammeter requires a footprint when pcbX/pcbY or pcb edge position props are used")}super.doInitialPcbComponentRender()}initPorts(){super.initPorts({ignoreSymbolPorts:!0,pinCount:2,additionalAliases:{pin1:["pos"],pin2:["neg"]}});let symbol=zh[this._getSchematicSymbolNameOrThrow()];this.portMap.pos.schematicSymbolPortDef=symbol.ports.find(port=>port.labels.includes("1"))??null,this.portMap.neg.schematicSymbolPortDef=symbol.ports.find(port=>port.labels.includes("2"))??null}doInitialSourceRender(){let{db:db22}=this.root,{supplierPartNumbers,displayName}=this._parsedProps,source_component=db22.source_component.insert({ftype:"simple_ammeter",name:this.name,supplier_part_numbers:supplierPartNumbers,manufacturer_part_number:resolveManufacturerPartNumber(this._parsedProps),display_name:displayName});this.source_component_id=source_component.source_component_id}doInitialSimulationRender(){let{db:db22}=this.root,{color:color3,graphDisplayName,graphCenter,graphVerticalOffset,graphCurrentPerDiv}=this._parsedProps,posPort=this.portMap.pos,negPort=this.portMap.neg,{simulation_current_probe_id}=db22.simulation_current_probe.insert({type:"simulation_current_probe",name:this.name,source_component_id:this.source_component_id,positive_source_port_id:posPort.source_port_id,negative_source_port_id:negPort.source_port_id,subcircuit_id:this.getSubcircuit()?.subcircuit_id??void 0,color:color3});if(this.simulation_current_probe_id=simulation_current_probe_id,graphDisplayName!==void 0||graphCenter!==void 0||graphVerticalOffset!==void 0||graphCurrentPerDiv!==void 0){let graphCurrentPerDivValue=parseSimulationGraphValue(graphCurrentPerDiv),graphVerticalOffsetValue=parseSimulationGraphValue(graphVerticalOffset);db22.simulation_oscilloscope_trace.insert({simulation_current_probe_id,display_name:graphDisplayName,color:color3,display_center_value:graphCenter,amps_per_div:graphCurrentPerDivValue,display_center_offset_divs:graphVerticalOffsetValue!==void 0&&graphCurrentPerDivValue!==void 0&&graphCurrentPerDivValue!==0?graphVerticalOffsetValue/graphCurrentPerDivValue:void 0})}}doInitialSchematicLayout(){Ammeter_doInitialSchematicLayout(this)}},edgeSpecifiers=["leftedge","rightedge","topedge","bottomedge","center"],Constraint3=class extends PrimitiveComponent2{get config(){return{componentName:"Constraint",zodProps:constraintProps}}constructor(props){if(super(props),("xdist"in props||"ydist"in props)&&!("edgeToEdge"in props)&&!("centerToCenter"in props))throw new Error(`edgeToEdge, centerToCenter must be set for xDist or yDist for ${this}`);if("for"in props&&props.for.length<2)throw new Error(`"for" must have at least two selectors for ${this}`)}_getAllReferencedComponents(){let componentsWithSelectors=[],container=this.getPrimitiveContainer();function addComponentFromSelector(selector2){let maybeEdge=selector2.split(" ").pop(),edge=edgeSpecifiers.includes(maybeEdge)?maybeEdge:void 0,componentSelector=edge?selector2.replace(` ${edge}`,""):selector2,component=container.selectOne(componentSelector,{pcbPrimitive:!0});component&&componentsWithSelectors.push({selector:selector2,component,componentSelector,edge})}for(let key of["left","right","top","bottom"])key in this._parsedProps&&addComponentFromSelector(this._parsedProps[key]);if("for"in this._parsedProps)for(let selector2 of this._parsedProps.for)addComponentFromSelector(selector2);return{componentsWithSelectors}}},isSelectionResultPort=connectable=>!connectable||typeof connectable!="object"?!1:typeof connectable.getSourcePort=="function",isSelectionResultNet=connectable=>!connectable||typeof connectable!="object"?!1:typeof connectable.getSourceNet=="function",isSelectionResultComponent=connectable=>!connectable||typeof connectable!="object"?!1:typeof connectable.getPorts=="function",isCircuitJsonElement=connectable=>!connectable||typeof connectable!="object"?!1:typeof connectable.type=="string",isNonEmptyString=value=>typeof value=="string"&&value.length>0,SelectionResultPortImpl=class{constructor(port){__publicField(this,"port");this.port=port}getPcbPort(){let pcbPortId=this.port.pcb_port_id;return pcbPortId?this.port.root?.db.pcb_port.get(pcbPortId)??null:null}getSourcePort(){let sourcePortId=this.port.source_port_id;return sourcePortId?this.port.root?.db.source_port.get(sourcePortId)??null:null}},SelectionResultNetImpl=class{constructor(net){__publicField(this,"net");this.net=net}getSourceNet(){let sourceNetId=this.net.source_net_id;return sourceNetId?this.net.root?.db.source_net.get(sourceNetId)??null:null}},SelectionResultComponentImpl=class{constructor(component){__publicField(this,"component");this.component=component}getPort(name){let port=this.component.selectOne(`port.${name}`,{type:"port"})??this.component.selectOne(`.${name}`,{type:"port"});return port?new SelectionResultPortImpl(port):null}getPorts(){return this.component.selectAll("port").map(port=>new SelectionResultPortImpl(port))}getPcbComponent(){let pcbComponentId=this.component.pcb_component_id;return pcbComponentId?this.component.root?.db.pcb_component.get(pcbComponentId)??null:null}getSourceComponent(){let sourceComponentId=this.component.source_component_id;return sourceComponentId?this.component.root?.db.source_component.get(sourceComponentId)??null:null}},DrcCheck=class extends PrimitiveComponent2{get config(){return{componentName:"DrcCheck",zodProps:drcCheckProps}}constructor(props){super(props)}async runCustomDrcCheck(circuitJson){let result=await this._parsedProps.checkFn(this.createCustomDrcCheckContext(circuitJson)),diagnostics=[];return Array.isArray(result)?diagnostics=result:result&&(diagnostics=[result]),diagnostics.map((diagnostic,index2)=>this.createCircuitJsonDiagnostic(diagnostic,index2)).filter(diagnostic=>!!diagnostic)}createCustomDrcCheckContext(circuitJson){return{select:this.selectCustomDrcElement.bind(this),selectAll:this.selectAllCustomDrcElements.bind(this),isConnected:(a22,b22)=>this.isConnected(a22,b22,circuitJson),isPulledUp:a22=>this.isConnected(a22,"net.VCC",circuitJson)||this.isConnected(a22,"net.VDD",circuitJson)||this.getResistanceBetween(a22,"net.VCC",circuitJson)!==null||this.getResistanceBetween(a22,"net.VDD",circuitJson)!==null,isPulledDown:a22=>this.isConnected(a22,"net.GND",circuitJson)||this.getResistanceBetween(a22,"net.GND",circuitJson)!==null,getResistanceBetween:(a22,b22)=>this.getResistanceBetween(a22,b22,circuitJson)}}selectCustomDrcElement(selector2){return this.wrapSelectionResult(this.getSubcircuit().selectOne(selector2))}selectAllCustomDrcElements(selector2){let selectionResults=[];for(let component of this.getSubcircuit().selectAll(selector2)){let selectionResult=this.wrapSelectionResult(component);selectionResult&&selectionResults.push(selectionResult)}return selectionResults}wrapSelectionResult(component){return component?component instanceof Port?new SelectionResultPortImpl(component):component instanceof Net?new SelectionResultNetImpl(component):new SelectionResultComponentImpl(component):null}createCircuitJsonDiagnostic(diagnostic,index2){let diagnosticRecord=diagnostic,diagnosticType="source_component_misconfigured_error";typeof diagnosticRecord.error_type=="string"?diagnosticType=diagnosticRecord.error_type:typeof diagnosticRecord.warning_type=="string"&&(diagnosticType=diagnosticRecord.warning_type);let diagnosticWithCircuitJsonDefaults={...diagnostic};typeof diagnosticRecord.type=="string"?diagnosticWithCircuitJsonDefaults.type=diagnosticRecord.type:diagnosticWithCircuitJsonDefaults.type=diagnosticType,typeof diagnosticRecord.warning_type!="string"&&(typeof diagnosticRecord.error_type=="string"?diagnosticWithCircuitJsonDefaults.error_type=diagnosticRecord.error_type:diagnosticWithCircuitJsonDefaults.error_type=diagnosticType);let diagnosticIdField=`${diagnosticType}_id`;return diagnosticRecord[diagnosticIdField]?diagnosticWithCircuitJsonDefaults[diagnosticIdField]=diagnosticRecord[diagnosticIdField]:diagnosticWithCircuitJsonDefaults[diagnosticIdField]=`${diagnosticType}_${this._renderId}_${index2}`,any_circuit_element.parse(diagnosticWithCircuitJsonDefaults)}isConnected(a22,b22,circuitJson){let aKeys=this.getConnectivityKeys(a22,circuitJson),bKeys=this.getConnectivityKeys(b22,circuitJson);return aKeys.some(key=>bKeys.includes(key))}getResistanceBetween(a22,b22,circuitJson){if(this.isConnected(a22,b22,circuitJson))return 0;let aKeys=this.getConnectivityKeys(a22,circuitJson),bKeys=this.getConnectivityKeys(b22,circuitJson);if(aKeys.length===0||bKeys.length===0)return null;let sourceResistors=circuitJson.filter(elm=>elm.type==="source_component"&&elm.ftype==="simple_resistor"),root=this.root;if(!root)return null;for(let resistor of sourceResistors){let resistorPorts=root.db.source_port.list({source_component_id:resistor.source_component_id});if(resistorPorts.length!==2)continue;let resistorKeys=resistorPorts.map(port=>port.subcircuit_connectivity_map_key),connectsA=resistorKeys.some(key=>key&&aKeys.includes(key)),connectsB=resistorKeys.some(key=>key&&bKeys.includes(key));if(connectsA&&connectsB)return resistor.resistance}return null}getConnectivityKeys(connectable,circuitJson){if(!connectable)return[];if(typeof connectable=="string"){let selected=this.selectCustomDrcElement(connectable);return selected?this.getConnectivityKeys(selected,circuitJson):[]}return isSelectionResultPort(connectable)?[connectable.getSourcePort()?.subcircuit_connectivity_map_key].filter(isNonEmptyString):isSelectionResultNet(connectable)?[connectable.getSourceNet()?.subcircuit_connectivity_map_key].filter(isNonEmptyString):isSelectionResultComponent(connectable)?connectable.getPorts().flatMap(port=>this.getConnectivityKeys(port,circuitJson)):isCircuitJsonElement(connectable)?this.getCircuitJsonElementConnectivityKeys(connectable,circuitJson):[]}getCircuitJsonElementConnectivityKeys(element,circuitJson){if(!element)return[];if(element.type==="source_port")return[element.subcircuit_connectivity_map_key].filter(isNonEmptyString);if(element.type==="source_net")return[element.subcircuit_connectivity_map_key].filter(isNonEmptyString);if(element.type==="pcb_port")return this.getConnectivityKeys(element.source_port_id,circuitJson);if(element.type==="source_component"){let root=this.root;return root?root.db.source_port.list({source_component_id:element.source_component_id}).map(port=>port.subcircuit_connectivity_map_key).filter(isNonEmptyString):[]}return[]}},AutoroutingPhase=class extends PrimitiveComponent2{get config(){return{componentName:"AutoroutingPhase",zodProps:autoroutingPhaseProps}}add(_component){throw new Error("<autoroutingphase> cannot contain children")}},resolvePcbDimensionOffsetDirection=({from,offset:offset2,offsetDirection,to:to3,transform:transform7})=>{if(offsetDirection)return applyToPoint2({...transform7,e:0,f:0},offsetDirection);let dx22=to3.x-from.x,dy22=to3.y-from.y,distance27=Math.hypot(dx22,dy22);if(!(offset2===void 0||distance27===0))return{x:-dy22/distance27,y:dx22/distance27}},FabricationNoteDimension=class extends PrimitiveComponent2{constructor(){super(...arguments);__publicField(this,"fabrication_note_dimension_id",null);__publicField(this,"isPcbPrimitive",!0)}get config(){return{componentName:"FabricationNoteDimension",zodProps:fabricationNoteDimensionProps}}_resolvePoint(input2,transform7){if(typeof input2=="string"){let target=this.getSubcircuit().selectOne(input2);return target?target._getGlobalPcbPositionBeforeLayout():(this.renderError(`FabricationNoteDimension could not find selector "${input2}"`),applyToPoint2(transform7,{x:0,y:0}))}let numericX=typeof input2.x=="string"?parseFloat(input2.x):input2.x,numericY=typeof input2.y=="string"?parseFloat(input2.y):input2.y;return applyToPoint2(transform7,{x:numericX,y:numericY})}doInitialPcbPrimitiveRender(){if(this.root?.pcbDisabled)return;let{db:db22}=this.root,{_parsedProps:props}=this,transform7=this._computePcbGlobalTransformBeforeLayout(),from=this._resolvePoint(props.from,transform7),to3=this._resolvePoint(props.to,transform7),subcircuit=this.getSubcircuit(),group2=this.getGroup(),{maybeFlipLayer}=this._getPcbPrimitiveFlippedHelpers(),layer=maybeFlipLayer(props.layer??"top");if(layer!=="top"&&layer!=="bottom")throw new Error(`Invalid layer "${layer}" for FabricationNoteDimension. Must be "top" or "bottom".`);let pcb_component_id=this.parent?.pcb_component_id??this.getPrimitiveContainer()?.pcb_component_id,text=props.text??this._formatDistanceText({from,to:to3,units:props.units??"mm"}),offsetDirection=resolvePcbDimensionOffsetDirection({from,offset:props.offset,offsetDirection:props.offsetDirection,to:to3,transform:transform7}),fabrication_note_dimension=db22.pcb_fabrication_note_dimension.insert({pcb_component_id,subcircuit_id:subcircuit?.subcircuit_id??void 0,pcb_group_id:group2?.pcb_group_id??void 0,layer,from,to:to3,text,offset:props.offset,offset_distance:props.offset,offset_direction:offsetDirection,font:props.font??"tscircuit2024",font_size:props.fontSize??1,color:props.color,arrow_size:props.arrowSize??1});this.fabrication_note_dimension_id=fabrication_note_dimension.pcb_fabrication_note_dimension_id}_moveCircuitJsonElements({deltaX,deltaY}){if(this.root?.pcbDisabled)return;let{db:db22}=this.root;if(!this.fabrication_note_dimension_id)return;let dimension2=db22.pcb_fabrication_note_dimension.get(this.fabrication_note_dimension_id);dimension2&&db22.pcb_fabrication_note_dimension.update(this.fabrication_note_dimension_id,{from:{x:dimension2.from.x+deltaX,y:dimension2.from.y+deltaY},to:{x:dimension2.to.x+deltaX,y:dimension2.to.y+deltaY}})}getPcbSize(){let transform7=this._computePcbGlobalTransformBeforeLayout(),from=this._resolvePoint(this._parsedProps.from,transform7),to3=this._resolvePoint(this._parsedProps.to,transform7);return{width:Math.abs(to3.x-from.x),height:Math.abs(to3.y-from.y)}}_formatDistanceText({from,to:to3,units}){let dx22=to3.x-from.x,dy22=to3.y-from.y,distanceInMillimeters=Math.sqrt(dx22*dx22+dy22*dy22),distanceInUnits=units==="in"?distanceInMillimeters/25.4:distanceInMillimeters,roundedDistance=Math.round(distanceInUnits);if(Math.abs(distanceInUnits-roundedDistance)<1e-9)return`${roundedDistance}${units}`;let decimalPlaces=units==="in"?3:2;return`${units==="in"?Number(distanceInUnits.toFixed(decimalPlaces)).toString():distanceInUnits.toFixed(decimalPlaces)}${units}`}},PcbNoteDimension=class extends PrimitiveComponent2{constructor(){super(...arguments);__publicField(this,"pcb_note_dimension_id",null);__publicField(this,"isPcbPrimitive",!0)}get config(){return{componentName:"PcbNoteDimension",zodProps:pcbNoteDimensionProps}}_resolvePoint(input2,transform7){if(typeof input2=="string"){let target=this.getSubcircuit().selectOne(`.${input2}`);if(!target)return this.renderError(`PcbNoteDimension could not find selector "${input2}"`),applyToPoint2(transform7,{x:0,y:0});let targetPcbComponentId=target.pcb_component_id,root=this.root;if(targetPcbComponentId&&root){let pcbComponent=root.db.pcb_component.get(targetPcbComponentId);if(pcbComponent?.center)return{x:pcbComponent.center.x,y:pcbComponent.center.y}}return target._getGlobalPcbPositionBeforeLayout()}let numericX=typeof input2.x=="string"?parseFloat(input2.x):input2.x,numericY=typeof input2.y=="string"?parseFloat(input2.y):input2.y;return applyToPoint2(transform7,{x:numericX,y:numericY})}doInitialPcbPrimitiveRender(){if(this.root?.pcbDisabled)return;let{db:db22}=this.root,{_parsedProps:props}=this,transform7=this._computePcbGlobalTransformBeforeLayout(),from=this._resolvePoint(props.from,transform7),to3=this._resolvePoint(props.to,transform7),subcircuit=this.getSubcircuit(),group2=this.getGroup(),pcb_component_id=this.parent?.pcb_component_id??this.getPrimitiveContainer()?.pcb_component_id??void 0,text=props.text??this._formatDistanceText({from,to:to3,units:props.units??"mm"}),offsetDirection=resolvePcbDimensionOffsetDirection({from,offset:props.offset,offsetDirection:props.offsetDirection,to:to3,transform:transform7}),pcb_note_dimension3=db22.pcb_note_dimension.insert({pcb_component_id,subcircuit_id:subcircuit?.subcircuit_id??void 0,pcb_group_id:group2?.pcb_group_id??void 0,from,to:to3,text,offset_distance:props.offset,offset_direction:offsetDirection,font:props.font??"tscircuit2024",font_size:props.fontSize??1,layer:props.layer==="bottom"?"bottom":"top",color:props.color,arrow_size:props.arrowSize??1});this.pcb_note_dimension_id=pcb_note_dimension3.pcb_note_dimension_id}doInitialPcbLayout(){let root=this.root;if(!root||root.pcbDisabled||!this.pcb_note_dimension_id)return;let{db:db22}=root,transform7=this._computePcbGlobalTransformBeforeLayout(),from=this._resolvePoint(this._parsedProps.from,transform7),to3=this._resolvePoint(this._parsedProps.to,transform7);db22.pcb_note_dimension.update(this.pcb_note_dimension_id,{from,to:to3})}getPcbSize(){let transform7=this._computePcbGlobalTransformBeforeLayout(),from=this._resolvePoint(this._parsedProps.from,transform7),to3=this._resolvePoint(this._parsedProps.to,transform7);return{width:Math.abs(to3.x-from.x),height:Math.abs(to3.y-from.y)}}_formatDistanceText({from,to:to3,units}){let dx22=to3.x-from.x,dy22=to3.y-from.y,distanceInMillimeters=Math.sqrt(dx22*dx22+dy22*dy22),distanceInUnits=units==="in"?distanceInMillimeters/25.4:distanceInMillimeters,roundedDistance=Math.round(distanceInUnits);if(Math.abs(distanceInUnits-roundedDistance)<1e-9)return`${roundedDistance}${units}`;let decimalPlaces=units==="in"?3:2;return`${units==="in"?Number(distanceInUnits.toFixed(decimalPlaces)).toString():distanceInUnits.toFixed(decimalPlaces)}${units}`}_moveCircuitJsonElements({deltaX,deltaY}){if(this.root?.pcbDisabled)return;let{db:db22}=this.root;if(!this.pcb_note_dimension_id)return;let dimension2=db22.pcb_note_dimension.get(this.pcb_note_dimension_id);dimension2&&db22.pcb_note_dimension.update(this.pcb_note_dimension_id,{from:{x:dimension2.from.x+deltaX,y:dimension2.from.y+deltaY},to:{x:dimension2.to.x+deltaX,y:dimension2.to.y+deltaY}})}},AutoplacedBreakoutPoint=class extends BaseBreakoutPoint{get config(){return{componentName:"AutoplacedBreakoutPoint",zodProps:baseBreakoutPointProps}}_applySolvedBreakoutPoint({sourceTraceId,layer,position:position4}){this.matchedSourceTraceId=sourceTraceId,this._renderPcbBreakoutPoint({layer:layer_ref.parse(layer)}),this._setPositionFromLayout(position4)}},DDR_BYTE0_PORTS=[{id:"DQ0",layer:"inner3",soc:{x:-6,y:-3},ram:{x:3.941917,y:-3.650917}},{id:"DQ1",layer:"inner6",fullLayer:"inner2",soc:{x:-5.5,y:-3},ram:{x:4.591917,y:-3.650917}},{id:"DQ2",layer:"inner5",fullLayer:"inner4",soc:{x:-4.5,y:-3},ram:{x:5.891917,y:-3.650917}},{id:"DQ3",layer:"inner2",fullLayer:"inner6",soc:{x:-4.5,y:-3.5},ram:{x:6.541917,y:-3.650917}},{id:"DQ4",layer:"inner3",fullLayer:"inner2",soc:{x:-6,y:-2.5},ram:{x:6.541917,y:-2.050917}},{id:"DQ5",layer:"inner2",fullLayer:"inner5",soc:{x:-6,y:-2},ram:{x:5.891917,y:-2.050917}},{id:"DQ6",layer:"inner5",fullLayer:"inner4",soc:{x:-5,y:-2},ram:{x:4.591917,y:-2.050917}},{id:"DQ7",layer:"inner4",fullLayer:"inner6",soc:{x:-5.5,y:-2},ram:{x:3.941917,y:-2.050917}},{id:"DM0",layer:"inner4",fullLayer:"inner5",soc:{x:-5,y:-3},ram:{x:4.591917,y:-2.850917}},{id:"DQS0",layer:"inner1",differentialPairId:"DQS0",soc:{x:-4.5,y:-2.5},ram:{x:5.241917,y:-2.850917}},{id:"DQS0_n",layer:"inner1",differentialPairId:"DQS0",soc:{x:-5,y:-2.5},ram:{x:5.891917,y:-2.850917}}],DDR_BYTE1_PORTS=[{id:"DQ8",layer:"inner6",fullLayer:"inner4",soc:{x:-6,y:3},ram:{x:3.941917,y:3.549083}},{id:"DQ9",layer:"inner3",fullLayer:"inner4",soc:{x:-5.5,y:2},ram:{x:4.591917,y:3.549083}},{id:"DQ10",layer:"inner3",fullLayer:"inner2",soc:{x:-4.5,y:2},ram:{x:5.891917,y:3.549083}},{id:"DQ11",layer:"inner6",fullLayer:"inner5",soc:{x:-4.5,y:2.5},ram:{x:6.541917,y:3.549083}},{id:"DQ12",layer:"inner5",fullLayer:"inner1",soc:{x:-6,y:2.5},ram:{x:6.541917,y:1.949083}},{id:"DQ13",layer:"inner2",fullLayer:"inner3",soc:{x:-6.5,y:3},ram:{x:5.891917,y:1.949083}},{id:"DQ14",layer:"inner5",fullLayer:"inner6",soc:{x:-5,y:2.5},ram:{x:4.591917,y:1.949083}},{id:"DQ15",layer:"inner4",fullLayer:"inner1",soc:{x:-4.5,y:3.5},ram:{x:3.941917,y:1.949083}},{id:"DM1",layer:"inner4",fullLayer:"inner5",soc:{x:-5,y:3.5},ram:{x:4.591917,y:2.749083}},{id:"DQS1",layer:"inner1",fullLayer:"bottom",differentialPairId:"DQS1",soc:{x:-4.5,y:3},ram:{x:5.241917,y:2.749083}},{id:"DQS1_n",layer:"inner1",fullLayer:"bottom",differentialPairId:"DQS1",soc:{x:-5,y:3},ram:{x:5.891917,y:2.749083}}],DDR_ADDR_CTRL_PORTS=[{id:"A0",layer:"bottom",soc:{x:-6.5,y:-.5},ram:{x:7.841917,y:-3.650917}},{id:"A1",layer:"inner3",soc:{x:-7,y:-2},ram:{x:8.491917,y:-3.650917}},{id:"A2",layer:"inner3",soc:{x:-7,y:-.5},ram:{x:7.841917,y:1.949083}},{id:"A3",layer:"inner6",soc:{x:-5,y:-1},ram:{x:7.841917,y:2.749083}},{id:"A4",layer:"inner4",soc:{x:-4.5,y:-1.5},ram:{x:7.841917,y:3.549083}},{id:"A5",layer:"inner2",soc:{x:-6.5,y:-2},ram:{x:8.491917,y:3.549083}},{id:"CS0_n",layer:"inner5",soc:{x:-5.5,y:-.5},ram:{x:7.841917,y:-2.050917}},{id:"CKE0",layer:"inner1",soc:{x:-4.5,y:-1},ram:{x:8.491917,y:-2.050917}},{id:"CK0",layer:"bottom",differentialPairId:"CK0",soc:{x:-4.5,y:1},ram:{x:8.491917,y:1.149083}},{id:"CK0_n",layer:"bottom",differentialPairId:"CK0",soc:{x:-5,y:1},ram:{x:8.491917,y:1.949083}},{id:"DDR_LINK_RESET0_n",layer:"inner6",soc:{x:-5,y:-1.5},ram:{x:13.041917,y:3.549083}}],createAm62lExample=options=>{let ports=options.buses.flatMap(bus=>bus.ports),addedPairIds=new Set,makeEndpoints=port=>[{regionId:"soc",position:port.soc},{regionId:"ram",position:port.ram}],connections=[];for(let port of ports){if(!port.differentialPairId){connections.push({id:port.id,endpoints:makeEndpoints(port)});continue}if(addedPairIds.has(port.differentialPairId))continue;addedPairIds.add(port.differentialPairId);let pair=ports.filter(candidate=>candidate.differentialPairId===port.differentialPairId);if(pair.length!==2)throw new Error(`Differential pair ${port.differentialPairId} must have two members`);let[first,second]=pair;connections.push({type:"differential",connections:[{id:first.id,endpoints:makeEndpoints(first)},{id:second.id,endpoints:makeEndpoints(second)}]})}let buses=options.buses.map(bus=>{let solverBus={id:bus.id,connectionIds:bus.ports.map(port=>port.id)};return bus.preferredLayer!==void 0&&(solverBus={...solverBus,preferredLayer:bus.preferredLayer}),bus.preferredLayers!==void 0&&(solverBus={...solverBus,preferredLayers:bus.preferredLayers}),solverBus});return{regions:[{id:"soc",bounds:{minX:-16.62808,maxX:-2.37192,minY:-10.62808,maxY:10.62808},edge:"right"},{id:"ram",bounds:{minX:1.091917,maxX:18.141917,minY:-9.650917,maxY:9.549083},edge:"left"}],connections,buses,boundaryPointSpacing:.48}},ddrByte0Example=createAm62lExample({buses:[{id:"DDR_BYTE0",ports:DDR_BYTE0_PORTS,preferredLayers:["inner1","inner4"]}]}),ddrByte1Example=createAm62lExample({buses:[{id:"DDR_BYTE1",ports:DDR_BYTE1_PORTS,preferredLayers:["inner2","inner5"]}]}),fullDdrExample=createAm62lExample({buses:[{id:"DDR_BYTE0",ports:DDR_BYTE0_PORTS,preferredLayers:["inner1","inner4"]},{id:"DDR_BYTE1",ports:DDR_BYTE1_PORTS,preferredLayers:["inner2","inner5"]},{id:"DDR_ADDR_CTRL",ports:DDR_ADDR_CTRL_PORTS,preferredLayers:["inner3","inner6"]}]}),controlBusExample=createAm62lExample({buses:[{id:"DDR_ADDR_CTRL",ports:DDR_ADDR_CTRL_PORTS,preferredLayers:["inner3","inner6"]}]}),WindingBreakoutInputError=class extends Error{constructor(){super(...arguments);__publicField(this,"name","WindingBreakoutInputError")}},WindingBreakoutInfeasibleError=class extends Error{constructor(){super(...arguments);__publicField(this,"name","WindingBreakoutInfeasibleError")}},WindingBreakoutInvariantError=class extends Error{constructor(){super(...arguments);__publicField(this,"name","WindingBreakoutInvariantError")}},WindingBreakoutOutputUnavailableError=class extends Error{constructor(){super(...arguments);__publicField(this,"name","WindingBreakoutOutputUnavailableError")}},getCanonicalConnections=input2=>{let connections=[];for(let entry of input2.connections)"type"in entry?connections.push(...entry.connections):connections.push(entry);return connections},getBusLayerCandidates=bus=>bus.preferredLayer!==void 0?[bus.preferredLayer]:bus.preferredLayers!==void 0?[...new Set(bus.preferredLayers)]:["top"],getLayerCandidatesByConnection=input2=>{let candidatesByConnection=new Map;for(let bus of input2.buses){let candidates=getBusLayerCandidates(bus);for(let connectionId of bus.connectionIds)candidatesByConnection.set(connectionId,candidates)}return Object.fromEntries(getCanonicalConnections(input2).map(connection=>[connection.id,candidatesByConnection.get(connection.id)??["top"]]))},fail=message=>{throw new WindingBreakoutInputError(`WindingBreakoutSolver: ${message}`)},isRecord=value=>typeof value=="object"&&value!==null&&!Array.isArray(value),requireRecord=(value,label)=>{isRecord(value)||fail(`${label} must be an object`)},requireId=(value,label)=>{(typeof value!="string"||value.trim().length===0)&&fail(`${label} must be a non-empty string`)},requireFinite=(value,label)=>{(typeof value!="number"||!Number.isFinite(value))&&fail(`${label} must be finite`)},requirePositive=(value,label)=>{requireFinite(value,label),value<=0&&fail(`${label} must be positive`)},requireArray=(value,message)=>Array.isArray(value)?value:fail(message),validatePoint=(value,label)=>(requireRecord(value,label),requireFinite(value.x,`${label}.x`),requireFinite(value.y,`${label}.y`),value),validateBounds=(value,label)=>(requireRecord(value,label),requireFinite(value.minX,`${label}.minX`),requireFinite(value.maxX,`${label}.maxX`),requireFinite(value.minY,`${label}.minY`),requireFinite(value.maxY,`${label}.maxY`),(value.minX>=value.maxX||value.minY>=value.maxY)&&fail(`${label} must have positive width and height`),{minX:value.minX,maxX:value.maxX,minY:value.minY,maxY:value.maxY}),pointIsInsideBounds4=(point62,bounds)=>point62.x>=bounds.minX&&point62.x<=bounds.maxX&&point62.y>=bounds.minY&&point62.y<=bounds.maxY,validateWindingBreakoutInput=input2=>{(!Array.isArray(input2.regions)||input2.regions.length===0)&&fail("at least one region is required"),requirePositive(input2.boundaryPointSpacing,"boundaryPointSpacing");let regionIds=new Set,regions=input2.regions.map((value,index2)=>{requireRecord(value,`regions[${index2}]`),requireId(value.id,`regions[${index2}].id`),regionIds.has(value.id)&&fail(`duplicate region id "${value.id}"`),regionIds.add(value.id);let bounds=validateBounds(value.bounds,`region "${value.id}" bounds`);return(typeof value.edge!="string"||!new Set(["left","right","bottom","top"]).has(value.edge))&&fail(`region "${value.id}" has invalid edge`),{id:value.id,bounds,edge:value.edge,center:{x:(bounds.minX+bounds.maxX)/2,y:(bounds.minY+bounds.maxY)/2}}}),vertical=regions.every(region=>region.edge==="left"||region.edge==="right"),horizontal=regions.every(region=>region.edge==="bottom"||region.edge==="top");!vertical&&!horizontal&&fail("all coordinated region edges must be parallel"),(!Array.isArray(input2.connections)||input2.connections.length===0)&&fail("at least one connection is required");let connections=[],connectionIds=new Set,atomicConnectionGroups=[],validateConnection=(value,label)=>{requireRecord(value,label),requireId(value.id,`${label}.id`),connectionIds.has(value.id)&&fail(`duplicate connection id "${value.id}"`),"layer"in value&&fail(`${label}.layer is not accepted; declare layer preferences on a bus`);let endpointValues=requireArray(value.endpoints,`${label}.endpoints must be an array`),endpointRegionIds=new Set,endpoints=endpointValues.map((endpointValue,endpointIndex)=>{let endpointLabel=`${label}.endpoints[${endpointIndex}]`;requireRecord(endpointValue,endpointLabel),requireId(endpointValue.regionId,`${endpointLabel}.regionId`),regionIds.has(endpointValue.regionId)||fail(`${endpointLabel} references unknown region "${endpointValue.regionId}"`),endpointRegionIds.has(endpointValue.regionId)&&fail(`${label} has duplicate endpoint for region "${endpointValue.regionId}"`),endpointRegionIds.add(endpointValue.regionId);let position4=validatePoint(endpointValue.position,`${endpointLabel}.position`),region=regions.find(candidate=>candidate.id===endpointValue.regionId);return pointIsInsideBounds4(position4,region.bounds)||fail(`${label} endpoint for region "${region.id}" is outside its bounds`),{regionId:endpointValue.regionId,position:position4}});for(let region of regions)endpointRegionIds.has(region.id)||fail(`${label} is missing endpoint for region "${region.id}"`);return endpoints.length!==regions.length&&fail(`${label} must contain exactly one endpoint for every region`),connectionIds.add(value.id),{id:value.id,endpoints}};for(let[index2,value]of input2.connections.entries()){let label=`connections[${index2}]`;if(requireRecord(value,label),"type"in value||"connections"in value){value.type!=="differential"&&fail(`${label} has invalid differential-pair type`),"layer"in value&&fail(`${label}.layer is not accepted; declare layer preferences on a bus`);let pairConnections=requireArray(value.connections,`${label}.connections must contain exactly two members`);pairConnections.length!==2&&fail(`${label}.connections must contain exactly two members`);let first=validateConnection(pairConnections[0],`${label}.connections[0]`),second=validateConnection(pairConnections[1],`${label}.connections[1]`);first.id===second.id&&fail(`${label} members must have distinct connection ids`),connections.push(first,second),atomicConnectionGroups.push([first.id,second.id])}else connections.push(validateConnection(value,label))}let busValues=requireArray(input2.buses,"buses must be an array"),busIds=new Set,busByConnection=new Map,buses=busValues.map((value,busIndex)=>{let label=`buses[${busIndex}]`;requireRecord(value,label),requireId(value.id,`${label}.id`);let busId=value.id;busIds.has(busId)&&fail(`duplicate bus id "${busId}"`),busIds.add(busId);let connectionIdValues=requireArray(value.connectionIds,`${label}.connectionIds must be a non-empty array`);connectionIdValues.length===0&&fail(`${label}.connectionIds must be a non-empty array`);let localConnectionIds=new Set,busConnectionIds=connectionIdValues.map((connectionId,connectionIndex)=>{requireId(connectionId,`${label}.connectionIds[${connectionIndex}]`),connectionIds.has(connectionId)||fail(`${label} references unknown connection "${connectionId}"`),localConnectionIds.has(connectionId)&&fail(`${label} contains duplicate connection "${connectionId}"`),localConnectionIds.add(connectionId);let previousBusId=busByConnection.get(connectionId);return previousBusId!==void 0&&fail(`connection "${connectionId}" belongs to multiple buses "${previousBusId}" and "${value.id}"`),busByConnection.set(connectionId,busId),connectionId}),preferredLayer;value.preferredLayer!==void 0&&(requireId(value.preferredLayer,`${label}.preferredLayer`),preferredLayer=value.preferredLayer);let preferredLayers;if(value.preferredLayers!==void 0){let preferredLayerValues=requireArray(value.preferredLayers,`${label}.preferredLayers must be a non-empty array`);preferredLayerValues.length===0&&fail(`${label}.preferredLayers must be a non-empty array`);let uniquePreferredLayers=new Set;preferredLayers=preferredLayerValues.map((layer,layerIndex)=>(requireId(layer,`${label}.preferredLayers[${layerIndex}]`),uniquePreferredLayers.has(layer)&&fail(`${label}.preferredLayers contains duplicate layer "${layer}"`),uniquePreferredLayers.add(layer),layer))}let validatedBus={id:busId,connectionIds:busConnectionIds};return preferredLayer!==void 0&&(validatedBus={...validatedBus,preferredLayer}),preferredLayers!==void 0&&(validatedBus={...validatedBus,preferredLayers}),validatedBus});for(let[firstConnectionId,secondConnectionId]of atomicConnectionGroups){let firstBusId=busByConnection.get(firstConnectionId),secondBusId=busByConnection.get(secondConnectionId);firstBusId!==secondBusId&&fail(`differential pair "${firstConnectionId}/${secondConnectionId}" must belong to the same bus`)}let layerNames=[...new Set([...buses.flatMap(bus=>getBusLayerCandidates(bus)),...connections.filter(connection=>!busByConnection.has(connection.id)).map(()=>"top")])].sort((first,second)=>first.localeCompare(second));return{regions,connections,buses,layerNames,atomicConnectionGroups}},GEOMETRY_EPSILON22=1e-9,isVerticalEdge=edge=>edge==="left"||edge==="right",getAxisMinimum=(region,vertical)=>vertical?region.bounds.minY:region.bounds.minX,getAxisMaximum=(region,vertical)=>vertical?region.bounds.maxY:region.bounds.maxX,getAxisPosition=(position4,vertical)=>vertical?position4.y:position4.x,deriveLayerOffsets=(layerNames,boundaryPointSpacing)=>{let staggerOffset=boundaryPointSpacing/2;return Object.fromEntries(layerNames.map((layer,index2)=>[layer,(index2-(layerNames.length-1)/2)*staggerOffset]))},makeAtomicLayerOrder=({referenceOrder,layer,layerByConnection,atomicGroups})=>{let candidates=referenceOrder.filter(connectionId=>layerByConnection[connectionId]===layer),groupByConnection=new Map(atomicGroups.flatMap(group2=>group2.map(connectionId=>[connectionId,group2]))),addedGroups=new Set,result=[];for(let connectionId of candidates){let group2=groupByConnection.get(connectionId);if(!group2){result.push(connectionId);continue}addedGroups.has(group2)||(addedGroups.add(group2),result.push(...candidates.filter(candidate=>group2.includes(candidate))))}return result},makeGateAxes=({regions,connections,spacing,count,layerOffsets})=>{let vertical=regions.every(region=>isVerticalEdge(region.edge)),minAxis=Math.max(...regions.map(region=>getAxisMinimum(region,vertical))),maxAxis=Math.min(...regions.map(region=>getAxisMaximum(region,vertical))),minimumOffset=Math.min(...Object.values(layerOffsets)),maximumOffset=Math.max(...Object.values(layerOffsets)),span=spacing*Math.max(0,count-1)+maximumOffset-minimumOffset;if(maxAxis-minAxis+GEOMETRY_EPSILON22<span)throw new WindingBreakoutInfeasibleError(`WindingBreakoutSolver: declared breakout edges need ${span.toFixed(2)}mm but expose only ${(maxAxis-minAxis).toFixed(2)}mm`);let meanAxis=regions.reduce((regionSum,region)=>{let positions=connections.map(connection=>connection.endpoints.find(endpoint=>endpoint.regionId===region.id).position);return regionSum+positions.reduce((sum,position4)=>sum+getAxisPosition(position4,vertical),0)/positions.length},0)/regions.length,start=Math.max(minAxis-minimumOffset,Math.min(maxAxis-spacing*Math.max(0,count-1)-maximumOffset,meanAxis-spacing*Math.max(0,count-1)/2));return{vertical,axes:Array.from({length:count},(_22,index2)=>start+index2*spacing)}},pointOnEdge=(region,axis,vertical)=>{if(vertical){let x22=region.bounds.maxX;return region.edge==="left"&&(x22=region.bounds.minX),{x:x22,y:axis}}let y22=region.bounds.maxY;return region.edge==="bottom"&&(y22=region.bounds.minY),{x:axis,y:y22}},placeBreakoutGates=({regions,connections,referenceOrder,layerNames,layerByConnection,boundaryPointSpacing,atomicGroups})=>{let layerOffsets=deriveLayerOffsets(layerNames,boundaryPointSpacing),gateOrderByLayer=Object.fromEntries(layerNames.map(layer=>[layer,makeAtomicLayerOrder({referenceOrder,layer,layerByConnection,atomicGroups})])),maxLayerNetCount=Math.max(...layerNames.map(layer=>connections.filter(connection=>layerByConnection[connection.id]===layer).length)),{vertical,axes:axes2}=makeGateAxes({regions,connections,spacing:boundaryPointSpacing,count:maxLayerNetCount,layerOffsets});return{breakoutPoints:regions.flatMap(region=>layerNames.flatMap(layer=>gateOrderByLayer[layer].map((connectionId,slotIndex)=>({regionId:region.id,connectionId,layer,...pointOnEdge(region,axes2[slotIndex]+layerOffsets[layer],vertical)}))))}},getAtomicUnits=(connectionIds,atomicGroups)=>{let connectionSet=new Set(connectionIds),groupByConnection=new Map(atomicGroups.flatMap(group2=>group2.map(connectionId=>[connectionId,group2]))),addedGroups=new Set,units=[];for(let connectionId of connectionIds){let group2=groupByConnection.get(connectionId);if(!group2){units.push([connectionId]);continue}addedGroups.has(group2)||(addedGroups.add(group2),units.push(group2.filter(memberId=>connectionSet.has(memberId))))}return units},assignConnectionLayers=({validated,referenceOrder})=>{let assignments=new Map;for(let bus of validated.buses){let busConnectionSet=new Set(bus.connectionIds),orderedBusConnections=referenceOrder.filter(connectionId=>busConnectionSet.has(connectionId)),candidates=getBusLayerCandidates(bus),units=getAtomicUnits(orderedBusConnections,validated.atomicConnectionGroups);for(let[unitIndex,unit2]of units.entries()){let layer=candidates[unitIndex%candidates.length];for(let connectionId of unit2)assignments.set(connectionId,layer)}}for(let connectionId of referenceOrder)assignments.has(connectionId)||assignments.set(connectionId,"top");let layerByConnection=Object.fromEntries(referenceOrder.map(connectionId=>[connectionId,assignments.get(connectionId)])),layerNames=[...new Set(Object.values(layerByConnection))].sort((first,second)=>first.localeCompare(second));return{layerByConnection,layerNames}},getLayerNames=input2=>[...new Set(Object.values(getLayerCandidatesByConnection(input2)).flat())].sort((first,second)=>first.localeCompare(second)),CONNECTION_COLORS=["#2563eb","#dc2626","#059669","#7c3aed","#d97706","#0891b2","#db2777","#4f46e5","#65a30d","#c2410c","#0f766e","#9333ea"],getConnectionColor=connectionId=>{let hash=2166136261;for(let character of connectionId)hash^=character.charCodeAt(0),hash=Math.imul(hash,16777619);return CONNECTION_COLORS[(hash>>>0)%CONNECTION_COLORS.length]},getGraphicsLayer3=(input2,layerIds)=>{let signalLayerIds=getLayerNames(input2),indexes=[...new Set(layerIds)].map(layerId=>{let index2=signalLayerIds.indexOf(layerId);if(index2<0)throw new Error(`Cannot visualize unknown signal layer "${layerId}"`);return index2});if(indexes.length===0)throw new Error("Cannot create graphics metadata without a signal layer");return indexes.sort((first,second)=>first-second),`z${indexes.join(",")}`},createInputGraphics=(input2,activeLayer)=>{let graphics={circles:[],rects:[],texts:[]},displayedLayers=getLayerNames(input2);activeLayer&&(displayedLayers=[activeLayer]);let visibleLayers=getGraphicsLayer3(input2,displayedLayers),connections=getCanonicalConnections(input2),layerCandidatesByConnection=getLayerCandidatesByConnection(input2),endpointRadius=Math.min(.12,input2.boundaryPointSpacing/4);for(let region of input2.regions){let center2={x:(region.bounds.minX+region.bounds.maxX)/2,y:(region.bounds.minY+region.bounds.maxY)/2};graphics.rects.push({center:center2,width:region.bounds.maxX-region.bounds.minX,height:region.bounds.maxY-region.bounds.minY,fill:"rgba(226, 232, 240, 0.035)",stroke:"rgba(71, 85, 105, 0.55)",layer:visibleLayers});for(let connection of connections){let layerCandidates=layerCandidatesByConnection[connection.id];if(activeLayer&&!layerCandidates.includes(activeLayer))continue;let endpoint=connection.endpoints.find(candidate=>candidate.regionId===region.id);if(!endpoint)continue;let color3=getConnectionColor(connection.id);graphics.circles.push({center:endpoint.position,radius:endpointRadius,fill:`${color3}70`,stroke:color3,layer:getGraphicsLayer3(input2,layerCandidates)})}graphics.texts.push({x:center2.x,y:region.bounds.maxY+.35,text:region.id,anchorSide:"bottom_center",color:"#334155",fontSize:.34,layer:visibleLayers})}return graphics},createStateGraphics=(input2,state2,activeLayer)=>{let connections=getCanonicalConnections(input2),breakoutPoints=state2.breakoutPoints.filter(point62=>!activeLayer||point62.layer===activeLayer),sharedGateSlots=new Map;for(let point62 of state2.breakoutPoints){let key=`${point62.regionId}:${point62.x.toFixed(9)}:${point62.y.toFixed(9)}`,slot=sharedGateSlots.get(key)??{x:point62.x,y:point62.y,layers:new Set};slot.layers.add(point62.layer),sharedGateSlots.set(key,slot)}return{lines:state2.referenceOrder.flatMap(connectionId=>{let connection=connections.find(candidate=>candidate.id===connectionId);if(!connection)return[];let connectionBreakouts=breakoutPoints.filter(point62=>point62.connectionId===connectionId),layer=connectionBreakouts[0]?.layer;if(!layer||activeLayer&&layer!==activeLayer)return[];if(connectionBreakouts.length!==input2.regions.length)return[];let points=input2.regions.flatMap((region,regionIndex)=>{let endpoint=connection.endpoints.find(candidate=>candidate.regionId===region.id),breakout=connectionBreakouts.find(candidate=>candidate.regionId===region.id);return!endpoint||!breakout?[]:regionIndex===0?[endpoint.position,breakout]:[breakout,endpoint.position]});return points.length<2?[]:[{points,strokeColor:`${getConnectionColor(connectionId)}55`,strokeWidth:.012,strokeDash:[.025,.07],layer:getGraphicsLayer3(input2,[layer])}]}),circles:[...sharedGateSlots.values()].flatMap(slot=>{let layers=[...slot.layers].filter(layer=>!activeLayer||layer===activeLayer);return layers.length===0?[]:[{center:slot,radius:.11,fill:"rgba(15, 23, 42, 0.06)",stroke:"#475569",layer:getGraphicsLayer3(input2,layers)}]}),points:breakoutPoints.map(point62=>({x:point62.x,y:point62.y,color:getConnectionColor(point62.connectionId),label:`${point62.connectionId} \xB7 ${point62.layer}`,layer:getGraphicsLayer3(input2,[point62.layer])}))}},createSolverPhaseVisualization=({input:input2,phase,detail,activeLayer,referenceOrder,referenceRegionId,showReferenceNumbers=!1,state:state2})=>{let inputGraphics=createInputGraphics(input2,activeLayer),stateGraphics;state2&&(stateGraphics=createStateGraphics(input2,state2,activeLayer));let displayedLayers=getLayerNames(input2);activeLayer&&(displayedLayers=[activeLayer]);let textLayer=getGraphicsLayer3(input2,displayedLayers),maxY=Math.max(...input2.regions.map(region=>region.bounds.maxY)),minX=Math.min(...input2.regions.map(region=>region.bounds.minX)),texts=[...inputGraphics.texts??[],...stateGraphics?.texts??[],{x:minX,y:maxY+1.05,text:phase,anchorSide:"bottom_left",color:"#0f172a",fontSize:.42,layer:textLayer},{x:minX,y:maxY+.68,text:detail,anchorSide:"bottom_left",color:"#475569",fontSize:.25,layer:textLayer}],referenceLines=[],referenceCircles=[];if(showReferenceNumbers&&referenceOrder){let referenceRegion=input2.regions.find(region=>region.id===referenceRegionId)??input2.regions[0],connections=getCanonicalConnections(input2),layerCandidatesByConnection=getLayerCandidatesByConnection(input2),orderedPositions=[];for(let[index2,connectionId]of referenceOrder.entries()){let connection=connections.find(candidate=>candidate.id===connectionId),layerCandidates=layerCandidatesByConnection[connectionId];if(!connection||!layerCandidates||activeLayer&&!layerCandidates.includes(activeLayer))continue;let endpoint=connection.endpoints.find(candidate=>candidate.regionId===referenceRegion.id);endpoint&&(orderedPositions.push(endpoint.position),texts.push({x:endpoint.position.x+.18,y:endpoint.position.y+.18,text:`${index2+1} \xB7 ${connectionId}`,anchorSide:"bottom_left",color:getConnectionColor(connectionId),fontSize:.21,layer:getGraphicsLayer3(input2,layerCandidates)}))}let center2={x:(referenceRegion.bounds.minX+referenceRegion.bounds.maxX)/2,y:(referenceRegion.bounds.minY+referenceRegion.bounds.maxY)/2};referenceLines.push(...orderedPositions.map(position4=>({points:[center2,position4],strokeColor:"rgba(100, 116, 139, 0.35)",strokeWidth:.01,strokeDash:[.03,.05],layer:textLayer}))),orderedPositions.length>1&&referenceLines.push({points:orderedPositions,strokeColor:"rgba(15, 23, 42, 0.65)",strokeWidth:.018,strokeDash:[.04,.04],label:`${referenceRegion.id} angular winding order`,layer:textLayer}),referenceCircles.push({center:center2,radius:.07,fill:"#0f172a",stroke:"#ffffff",label:`${referenceRegion.id} angular reference center`,layer:textLayer})}return{title:phase,coordinateSystem:"cartesian",rects:inputGraphics.rects,polygons:inputGraphics.polygons,lines:[...stateGraphics?.lines??[],...referenceLines],circles:[...inputGraphics.circles??[],...stateGraphics?.circles??[],...referenceCircles],points:stateGraphics?.points,texts}},getSharedGateSlotCount=points=>new Set(points.map(point62=>`${point62.regionId}:${point62.x.toFixed(9)}:${point62.y.toFixed(9)}`)).size,GatePlacementSolver=class extends BaseSolver{constructor(params){super();__publicField(this,"params");__publicField(this,"batchIndex",0);__publicField(this,"output");__publicField(this,"plannedPlacement");__publicField(this,"placementBatches");__publicField(this,"visibleBreakoutPoints",[]);__publicField(this,"layerByConnection");__publicField(this,"visualizationLayer");this.params=params,this.visualizationLayer=params.visualizationLayer;let assignment=assignConnectionLayers({validated:params.validated,referenceOrder:params.ordering.referenceOrder});this.layerByConnection=assignment.layerByConnection,this.placementBatches=params.validated.regions.flatMap(region=>assignment.layerNames.map(layer=>({regionId:region.id,layer}))),this.MAX_ITERATIONS=this.placementBatches.length+2}setVisualizationLayer(layer){this.visualizationLayer=layer}_step(){if(!this.plannedPlacement){this.plannedPlacement=placeBreakoutGates({regions:this.params.validated.regions,connections:this.params.validated.connections,referenceOrder:this.params.ordering.referenceOrder,layerNames:[...new Set(Object.values(this.layerByConnection))].sort((first,second)=>first.localeCompare(second)),layerByConnection:this.layerByConnection,boundaryPointSpacing:this.params.input.boundaryPointSpacing,atomicGroups:this.params.validated.atomicConnectionGroups}),this.stats={phase:"plan-gate-grid",regionLayerBatches:this.placementBatches.length,placedBreakpoints:0};return}let batch=this.placementBatches[this.batchIndex];if(batch){this.visibleBreakoutPoints.push(...this.plannedPlacement.breakoutPoints.filter(point62=>point62.regionId===batch.regionId&&point62.layer===batch.layer)),this.batchIndex+=1,this.stats={phase:"place-region-layer-batch",regionId:batch.regionId,layer:batch.layer,completedBatches:this.batchIndex,totalBatches:this.placementBatches.length,placedBreakpoints:this.visibleBreakoutPoints.length};return}this.output=this.plannedPlacement,this.stats={phase:"finalize-shared-gate-slots",placedBreakpoints:this.output.breakoutPoints.length,sharedGateSlots:getSharedGateSlotCount(this.output.breakoutPoints)},this.solved=!0}computeProgress(){let completedMicrosteps=this.batchIndex;return this.plannedPlacement&&(completedMicrosteps+=1),this.output&&(completedMicrosteps+=1),completedMicrosteps/this.MAX_ITERATIONS}getConstructorParams(){return[this.params]}getOutput(){if(!this.solved||!this.output)throw new WindingBreakoutInvariantError("WindingBreakoutSolver: gate placement requested before placement completed");return this.output}visualize(){let detail="Next microstep: derive layer offsets, atomic gate orders, and the common boundary slot grid";if(this.plannedPlacement&&this.batchIndex===0)detail=`Gate grid planned \xB7 ${this.placementBatches.length} region/layer batches remain`;else if(this.plannedPlacement&&!this.output){let latestBatch=this.placementBatches[this.batchIndex-1];detail=`Placed region \u201C${latestBatch.regionId}\u201D on layer \u201C${latestBatch.layer}\u201D \xB7 ${this.batchIndex}/${this.placementBatches.length} batches`}else if(this.output){let sharedGateSlotCount=getSharedGateSlotCount(this.output.breakoutPoints);detail=`${this.output.breakoutPoints.length} gates placed; coincident layer positions form ${sharedGateSlotCount} shared slots`}let visualizationState;if(this.plannedPlacement){let breakoutPoints=this.visibleBreakoutPoints;this.output&&(breakoutPoints=this.output.breakoutPoints),visualizationState={referenceOrder:this.params.ordering.referenceOrder,breakoutPoints}}let graphics=createSolverPhaseVisualization({input:this.params.input,activeLayer:this.visualizationLayer,phase:"Step 2 \xB7 Place boundary gates",detail,state:visualizationState}),plannedSlotGuides=(this.plannedPlacement?.breakoutPoints??[]).filter(point62=>!this.visualizationLayer||point62.layer===this.visualizationLayer).map(point62=>({center:point62,radius:.065,fill:"rgba(255, 255, 255, 0.75)",stroke:"rgba(100, 116, 139, 0.5)",label:`planned slot ${point62.regionId} \xB7 ${point62.layer}`,layer:getGraphicsLayer3(this.params.input,[point62.layer])}));return{...graphics,circles:[...graphics.circles??[],...plannedSlotGuides]}}},getNaturalWindingOrder=(region,connections)=>connections.map(connection=>{let position4=connection.endpoints.find(endpoint=>endpoint.regionId===region.id).position;return{id:connection.id,angle:Math.atan2(position4.y-region.center.y,position4.x-region.center.x),radius:Math.hypot(position4.x-region.center.x,position4.y-region.center.y)}}).sort((first,second)=>first.angle-second.angle||second.radius-first.radius||first.id.localeCompare(second.id)).map(connection=>connection.id),getReferenceWindingOrder=(naturalOrder,atomicGroups,buses)=>{let groupByConnection=new Map(atomicGroups.flatMap(group2=>group2.map(connectionId=>[connectionId,group2]))),addedGroups=new Set,result=[];for(let connectionId of naturalOrder){let group2=groupByConnection.get(connectionId);if(!group2){result.push(connectionId);continue}addedGroups.has(group2)||(addedGroups.add(group2),result.push(...naturalOrder.filter(candidate=>group2.includes(candidate))))}let busByConnection=new Map(buses.flatMap(bus=>bus.connectionIds.map(connectionId=>[connectionId,bus]))),addedBuses=new Set,busContiguousResult=[];for(let connectionId of result){let bus=busByConnection.get(connectionId);if(!bus){busContiguousResult.push(connectionId);continue}if(addedBuses.has(bus))continue;addedBuses.add(bus);let busConnectionIds=new Set(bus.connectionIds);busContiguousResult.push(...result.filter(candidate=>busConnectionIds.has(candidate)))}return busContiguousResult},ReferenceOrderingSolver=class extends BaseSolver{constructor(params){super();__publicField(this,"params");__publicField(this,"naturalOrderByRegion",{});__publicField(this,"currentRegionIndex",0);__publicField(this,"output");__publicField(this,"visualizedOrder");__publicField(this,"visualizedRegionId");__publicField(this,"visualizationLayer");this.params=params,this.visualizationLayer=params.visualizationLayer,this.MAX_ITERATIONS=params.validated.regions.length+1}setVisualizationLayer(layer){this.visualizationLayer=layer}_step(){let region=this.params.validated.regions[this.currentRegionIndex];if(region){let naturalOrder=getNaturalWindingOrder(region,this.params.validated.connections);this.naturalOrderByRegion[region.id]=naturalOrder,this.visualizedRegionId=region.id,this.visualizedOrder=naturalOrder,this.currentRegionIndex+=1,this.stats={phase:"derive-natural-order",regionId:region.id,completedRegions:this.currentRegionIndex,totalRegions:this.params.validated.regions.length,naturalOrder};return}let firstRegion=this.params.validated.regions[0],referenceOrder=getReferenceWindingOrder(this.naturalOrderByRegion[firstRegion.id],this.params.validated.atomicConnectionGroups,this.params.validated.buses);this.output={naturalOrderByRegion:this.naturalOrderByRegion,referenceOrder},this.visualizedRegionId=firstRegion.id,this.visualizedOrder=referenceOrder,this.stats={phase:"atomicize-reference-order",referenceRegion:firstRegion.id,referenceOrder},this.solved=!0}computeProgress(){let completedMicrosteps=this.currentRegionIndex;return this.output&&(completedMicrosteps+=1),completedMicrosteps/this.MAX_ITERATIONS}getConstructorParams(){return[this.params]}getOutput(){if(!this.solved||!this.output)throw new WindingBreakoutInvariantError("WindingBreakoutSolver: reference order requested before ordering completed");return this.output}visualize(){let firstRegionId=this.params.validated.regions[0].id,detail=`Next microstep: derive natural order for region \u201C${firstRegionId}\u201D`;return this.visualizedRegionId&&!this.output&&(detail=`Natural order for region \u201C${this.visualizedRegionId}\u201D \xB7 ${this.currentRegionIndex}/${this.params.validated.regions.length} regions processed`),this.output&&(detail=`Reference region \u201C${firstRegionId}\u201D finalized; buses are contiguous and differential pairs are atomic`),createSolverPhaseVisualization({input:this.params.input,activeLayer:this.visualizationLayer,phase:"Step 1 \xB7 Derive reference order",detail,referenceOrder:this.visualizedOrder,referenceRegionId:this.visualizedRegionId,showReferenceNumbers:!0})}},validateBreakoutPoints=({points,connectionIds,regions,atomicGroups})=>{let regionIds=regions.map(region=>region.id),endpointCounts=new Map,layerByConnection=new Map,connectionLayersAreValid=!0;for(let point62 of points){let key=`${point62.regionId}:${point62.connectionId}`;endpointCounts.set(key,(endpointCounts.get(key)??0)+1);let previousLayer=layerByConnection.get(point62.connectionId);previousLayer!==void 0&&previousLayer!==point62.layer&&(connectionLayersAreValid=!1),layerByConnection.set(point62.connectionId,point62.layer)}let expected=regionIds.flatMap(regionId=>connectionIds.map(connectionId=>`${regionId}:${connectionId}`)),endpointsAreValid=endpointCounts.size===expected.length&&expected.every(endpoint=>endpointCounts.get(endpoint)===1),atomicGroupsAreValid=atomicGroups.every(group2=>{let layer=layerByConnection.get(group2[0]);return!layer||group2.some(connectionId=>layerByConnection.get(connectionId)!==layer)?!1:regions.every(region=>{let layerPoints=points.filter(point62=>point62.regionId===region.id&&point62.layer===layer),vertical=region.edge==="left"||region.edge==="right",orderedConnectionIds=[...layerPoints].sort((first,second)=>vertical?first.y-second.y:first.x-second.x).map(point62=>point62.connectionId),firstIndex=orderedConnectionIds.indexOf(group2[0]),secondIndex=orderedConnectionIds.indexOf(group2[1]);return firstIndex!==-1&&secondIndex!==-1&&Math.abs(firstIndex-secondIndex)===1})});return endpointsAreValid&&connectionLayersAreValid&&atomicGroupsAreValid},finalizeWindingBreakoutOutput=({validated,placement})=>{if(!validateBreakoutPoints({points:placement.breakoutPoints,connectionIds:validated.connections.map(connection=>connection.id),regions:validated.regions,atomicGroups:validated.atomicConnectionGroups}))throw new WindingBreakoutInvariantError("WindingBreakoutSolver: generated invalid breakout points");return{breakoutPoints:placement.breakoutPoints}},PIPELINE_STAGE_NAMES=["referenceOrdering","gatePlacement"],WindingBreakoutSolver=class extends BasePipelineSolver{constructor(input2){super(input2);__publicField(this,"validatedInput");__publicField(this,"output");__publicField(this,"visualizationLayer");__publicField(this,"pipelineDef",[definePipelineStep("referenceOrdering",ReferenceOrderingSolver,pipeline=>[{input:pipeline.inputProblem,validated:pipeline.getValidatedInput(),visualizationLayer:pipeline.visualizationLayer}]),definePipelineStep("gatePlacement",GatePlacementSolver,pipeline=>[{input:pipeline.inputProblem,validated:pipeline.getValidatedInput(),ordering:pipeline.getRequiredStageOutput("referenceOrdering"),visualizationLayer:pipeline.visualizationLayer}])])}_setup(){this.validatedInput=validateWindingBreakoutInput(this.inputProblem),this.stats={phase:"setup-input-validation",regionCount:this.validatedInput.regions.length,connectionCount:this.validatedInput.connections.length,layerCount:this.validatedInput.layerNames.length}}getValidatedInput(){if(!this.validatedInput)throw new Error("WindingBreakoutSolver: input has not been validated");return this.validatedInput}_step(){super._step(),!this.output&&!this.activeSubSolver&&this.currentPipelineStageIndex>=this.pipelineDef.length&&(this.output=finalizeWindingBreakoutOutput({validated:this.getValidatedInput(),placement:this.getRequiredStageOutput("gatePlacement")}),this.solved=!0),this.stats={phase:this.getCurrentStageName(),completedStages:this.currentPipelineStageIndex,totalStages:this.pipelineDef.length},this.solved&&(this.stats.phase="finalize-output-validation"),this.output&&(this.stats.valid=!0,this.stats.breakoutPointCount=this.output.breakoutPoints.length)}getRequiredStageOutput(stageName){let output=this.getStageOutput(stageName);if(output===void 0)throw new Error(`WindingBreakoutSolver: pipeline stage \u201C${stageName}\u201D has no output`);return output}setVisualizationLayer(layer){this.visualizationLayer=layer;for(let stageName of PIPELINE_STAGE_NAMES){let solver=this.getSolver(stageName);solver&&"setVisualizationLayer"in solver&&solver.setVisualizationLayer(layer)}}getConstructorParams(){return[this.inputProblem]}getOutput(){if(!this.solved||!this.output)throw new WindingBreakoutOutputUnavailableError("WindingBreakoutSolver: getOutput() called before successful completion");return this.output}initialVisualize(){return createSolverPhaseVisualization({input:this.inputProblem,activeLayer:this.visualizationLayer,phase:"Input \xB7 Validated during setup",detail:"Region bounds, breakout edges, bus layer preferences, and canonical endpoints"})}finalVisualize(){if(!this.output)return null;let ordering=this.getRequiredStageOutput("referenceOrdering");return createSolverPhaseVisualization({input:this.inputProblem,activeLayer:this.visualizationLayer,phase:"Output \xB7 Validated after gate placement",detail:"Valid: one bus-constrained breakout point per connection and region; pairs are adjacent",state:{referenceOrder:ordering.referenceOrder,breakoutPoints:this.output.breakoutPoints}})}visualize(){return{...super.visualize(),title:"Winding breakout solver \xB7 step-by-step pipeline",coordinateSystem:"cartesian"}}},toWindingConnection=connection=>({id:connection.connectionId,endpoints:connection.endpoints}),defaultImplicitBreakoutPointSolverFn=input2=>{let windingInput={regions:input2.regions.map(region=>({id:region.regionId,bounds:region.bounds,edge:region.edge})),connections:input2.connections.map(connection=>"type"in connection?{type:"differential",connections:connection.connections.map(toWindingConnection)}:toWindingConnection(connection)),buses:input2.buses.map(bus=>({id:bus.busId,connectionIds:bus.connectionIds,preferredLayers:bus.targetLayers})),boundaryPointSpacing:input2.boundaryPointSpacing},solver=new WindingBreakoutSolver(windingInput);return solver.solve(),solver.getOutput()},getFanoutBounds=pcbGroup=>{let outlineBounds=pcbGroup.outline?getBoundsFromPoints(pcbGroup.outline):null,width=pcbGroup.width??(outlineBounds?outlineBounds.maxX-outlineBounds.minX:void 0),height=pcbGroup.height??(outlineBounds?outlineBounds.maxY-outlineBounds.minY:void 0);return width===void 0||height===void 0?null:{minX:pcbGroup.center.x-width/2,maxX:pcbGroup.center.x+width/2,minY:pcbGroup.center.y-height/2,maxY:pcbGroup.center.y+height/2}},getAxisGap2=(firstMin,firstMax,secondMin,secondMax)=>Math.max(firstMin-secondMax,secondMin-firstMax,0),Breakout_doInitialPcbPlacementDesignRuleChecks=breakout=>{if(breakout.root?.pcbDisabled||!breakout.pcb_group_id)return;let root=breakout.root;if(!root)return;let siblingFanouts=breakout.parent?.children.filter(sibling=>sibling instanceof breakout.constructor);if(!siblingFanouts)return;let breakoutIndex=siblingFanouts.indexOf(breakout);if(breakoutIndex<0)return;let{db:db22}=root,pcbGroup=db22.pcb_group.get(breakout.pcb_group_id);if(!pcbGroup)return;let bounds=getFanoutBounds(pcbGroup);if(bounds)for(let otherFanout of siblingFanouts.slice(breakoutIndex+1)){if(!otherFanout.pcb_group_id)continue;let otherPcbGroup=db22.pcb_group.get(otherFanout.pcb_group_id);if(!otherPcbGroup)continue;let otherBounds=getFanoutBounds(otherPcbGroup);if(!otherBounds)continue;let breakoutMargin=breakout._parsedProps.fanoutMargin,otherFanoutMargin=otherFanout._parsedProps.fanoutMargin,requiredMargin=Math.max(typeof breakoutMargin=="number"?breakoutMargin:0,typeof otherFanoutMargin=="number"?otherFanoutMargin:0),horizontalGap=getAxisGap2(bounds.minX,bounds.maxX,otherBounds.minX,otherBounds.maxX),verticalGap=getAxisGap2(bounds.minY,bounds.maxY,otherBounds.minY,otherBounds.maxY),horizontalOverlap=Math.min(bounds.maxX,otherBounds.maxX)-Math.max(bounds.minX,otherBounds.minX),verticalOverlap=Math.min(bounds.maxY,otherBounds.maxY)-Math.max(bounds.minY,otherBounds.minY),boundariesOverlap=horizontalOverlap>0&&verticalOverlap>0,violatesMargin=requiredMargin>0&&horizontalGap<requiredMargin&&verticalGap<requiredMargin;if(!boundariesOverlap&&!violatesMargin)continue;let message=boundariesOverlap?`Fanout boundaries "${breakout.name}" and "${otherFanout.name}" overlap. Fanout boundaries may not overlap.`:`Fanout boundaries "${breakout.name}" and "${otherFanout.name}" do not maintain the required ${requiredMargin}mm fanoutMargin.`;db22.pcb_placement_error.list().some(error2=>error2.message===message)||db22.pcb_placement_error.insert({error_type:"pcb_placement_error",message,subcircuit_id:breakout.subcircuit_id??void 0})}},reportWindingBreakoutInfeasibleError=(breakout,error2)=>{if(!(error2 instanceof WindingBreakoutInfeasibleError)||!breakout.root||!breakout.pcb_group_id)return!1;let componentNames=breakout.root.db.pcb_component.list().filter(pcbComponent=>pcbComponent.pcb_group_id===breakout.pcb_group_id).map(pcbComponent=>pcbComponent.source_component_id?breakout.root.db.source_component.get(pcbComponent.source_component_id)?.name:void 0).filter(name=>!!name);return breakout.root.db.pcb_autorouting_error.insert({pcb_error_id:`pcb_autorouting_error_winding_breakout_${breakout.pcb_group_id}`,error_type:"pcb_autorouting_error",message:`Winding fanout failed for ${componentNames.join(", ")||breakout.name}: ${error2.message}. The connections could not escape to the breakout boundary. Give the fanout more room by increasing the breakout's padding, or by extending the breakout to include the parts crowding it (decoupling capacitors, series resistors).`}),!0},getRoutingScopeOrThrow=breakout=>{let routingScope=breakout.parent;if(!routingScope?.selectAll)throw new Error(`Automatic breakout "${breakout.name}" has no coordinated routing scope`);return routingScope},getAutomaticBreakouts=(routingScope,breakoutToSolve)=>{let automaticBreakouts=[];for(let group2 of routingScope.selectAll("group")){if(!group2.isRoutingDirective||group2.parent!==routingScope)continue;let breakout=group2;breakout.children.some(child=>child instanceof AutoplacedBreakoutPoint)&&automaticBreakouts.push(breakout)}let getSourceTraceIds=breakout=>new Set(collectBreakoutRegionGeometry(breakout).endpointBySourceTraceId.keys()),sourceTraceIdsToSolve=getSourceTraceIds(breakoutToSolve);return automaticBreakouts.filter(automaticBreakout=>{let automaticBreakoutSourceTraceIds=getSourceTraceIds(automaticBreakout);return automaticBreakoutSourceTraceIds.size===sourceTraceIdsToSolve.size&&[...sourceTraceIdsToSolve].every(sourceTraceId=>automaticBreakoutSourceTraceIds.has(sourceTraceId))})},collectBreakoutRegionGeometry=breakout=>{if(!breakout.root||!breakout.pcb_group_id)throw new Error(`Automatic breakout "${breakout.name}" has no PCB region`);let pcbGroup=breakout.root.db.pcb_group.get(breakout.pcb_group_id);if(!pcbGroup||!pcbGroup.width||!pcbGroup.height)throw new Error(`Automatic breakout "${breakout.name}" has invalid PCB region bounds`);let bounds={minX:pcbGroup.center.x-pcbGroup.width/2,maxX:pcbGroup.center.x+pcbGroup.width/2,minY:pcbGroup.center.y-pcbGroup.height/2,maxY:pcbGroup.center.y+pcbGroup.height/2},center2={x:(bounds.minX+bounds.maxX)/2,y:(bounds.minY+bounds.maxY)/2},endpointBySourceTraceId=new Map,sourcePortIdBySourceTraceId=new Map;for(let breakoutPoint of breakout.children.filter(child=>child instanceof AutoplacedBreakoutPoint)){let matchedPort=breakoutPoint.matchedPort;if(!matchedPort?.pcb_port_id||!matchedPort.source_port_id)throw new Error(`Automatic breakout "${breakout.name}" is missing a PCB endpoint`);let sourceTraceId=breakoutPoint.matchedSourceTraceId;if(!sourceTraceId){let matchingSourceTraces=breakout.root.db.source_trace.list().filter(sourceTrace=>sourceTrace.connected_source_port_ids.includes(matchedPort.source_port_id));if(matchingSourceTraces.length===0)throw new Error(`Automatic breakout "${breakout.name}" has a point without a source trace identity`);let boundaryCrossingSourceTraces=matchingSourceTraces.filter(sourceTrace=>sourceTrace.connected_source_port_ids.some(sourcePortId=>{if(sourcePortId===matchedPort.source_port_id)return!1;let pcbPort2=breakout.root.db.pcb_port.getWhere({source_port_id:sourcePortId});return!pcbPort2||pcbPort2.pcb_group_id===breakout.pcb_group_id?!1:!(pcbPort2.x>=bounds.minX&&pcbPort2.x<=bounds.maxX&&pcbPort2.y>=bounds.minY&&pcbPort2.y<=bounds.maxY)}));sourceTraceId=(boundaryCrossingSourceTraces.length>0?boundaryCrossingSourceTraces:matchingSourceTraces).slice().sort((first,second)=>first.source_trace_id.localeCompare(second.source_trace_id))[0].source_trace_id,breakoutPoint.matchedSourceTraceId=sourceTraceId}if(endpointBySourceTraceId.has(sourceTraceId))throw new Error(`Connection "${sourceTraceId}" has duplicate endpoint for region "${breakout.pcb_group_id}"`);let pcbPort=breakout.root.db.pcb_port.get(matchedPort.pcb_port_id);if(!pcbPort)throw new Error(`Connection "${sourceTraceId}" references unknown PCB endpoint "${matchedPort.pcb_port_id}"`);if(pcbPort.pcb_group_id!==breakout.pcb_group_id)throw new Error(`Connection "${sourceTraceId}" endpoint references unknown region "${pcbPort.pcb_group_id??"unassigned"}" instead of "${breakout.pcb_group_id}"`);if(pcbPort.x===void 0||pcbPort.y===void 0)throw new Error(`Connection "${sourceTraceId}" is missing endpoint coordinates for region "${breakout.pcb_group_id}"`);endpointBySourceTraceId.set(sourceTraceId,{regionId:breakout.pcb_group_id,position:{x:pcbPort.x,y:pcbPort.y}}),sourcePortIdBySourceTraceId.set(sourceTraceId,matchedPort.source_port_id)}return{breakout,pcbGroupId:breakout.pcb_group_id,bounds,center:center2,endpointBySourceTraceId,sourcePortIdBySourceTraceId}},sortRegionsByPlacement=regions=>{let xCoordinates=regions.map(region=>region.center.x),yCoordinates=regions.map(region=>region.center.y),xSpan=Math.max(...xCoordinates)-Math.min(...xCoordinates),ySpan=Math.max(...yCoordinates)-Math.min(...yCoordinates),horizontalPlacement=xSpan>=ySpan;return regions.sort((firstRegion,secondRegion)=>{if(horizontalPlacement){let xDifference=firstRegion.center.x-secondRegion.center.x;if(xDifference!==0)return xDifference;let yDifference=firstRegion.center.y-secondRegion.center.y;if(yDifference!==0)return yDifference}else{let yDifference=firstRegion.center.y-secondRegion.center.y;if(yDifference!==0)return yDifference;let xDifference=firstRegion.center.x-secondRegion.center.x;if(xDifference!==0)return xDifference}return firstRegion.breakout.name.localeCompare(secondRegion.breakout.name)}),{regions,horizontalPlacement}},getFacingEdge=({region,regionIndex,regions,horizontalPlacement,singleRegionPreferredEdge})=>{if(regions.length===1&&singleRegionPreferredEdge)return singleRegionPreferredEdge;let otherRegions=regions.filter(candidate=>candidate!==region),otherCenter=otherRegions.reduce((sum,candidate)=>({x:sum.x+candidate.center.x/otherRegions.length,y:sum.y+candidate.center.y/otherRegions.length}),{x:0,y:0});return horizontalPlacement?otherCenter.x>region.center.x?"right":otherCenter.x<region.center.x?"left":regionIndex<regions.length/2?"right":"left":otherCenter.y>region.center.y?"top":otherCenter.y<region.center.y?"bottom":regionIndex<regions.length/2?"top":"bottom"},getSingleRegionPreferredEdge=({region,sourceTraces})=>{let root=region.breakout.root;if(!root)return;let internalSourcePortIds=new Set(region.sourcePortIdBySourceTraceId.values()),externalPcbPorts=new Map;for(let sourceTrace of sourceTraces)if(sourceTrace.connected_source_port_ids.some(sourcePortId=>internalSourcePortIds.has(sourcePortId)))for(let sourcePortId of sourceTrace.connected_source_port_ids){if(internalSourcePortIds.has(sourcePortId))continue;let pcbPort=root.db.pcb_port.getWhere({source_port_id:sourcePortId});!pcbPort?.pcb_port_id||pcbPort.x===void 0||pcbPort.y===void 0||pcbPort.x>=region.bounds.minX&&pcbPort.x<=region.bounds.maxX&&pcbPort.y>=region.bounds.minY&&pcbPort.y<=region.bounds.maxY||externalPcbPorts.set(pcbPort.pcb_port_id,{x:pcbPort.x,y:pcbPort.y})}if(externalPcbPorts.size===0)return;let distanceToEdge=(target,edge)=>{let edgePoint=edge==="left"||edge==="right"?{x:edge==="left"?region.bounds.minX:region.bounds.maxX,y:Math.max(region.bounds.minY,Math.min(region.bounds.maxY,target.y))}:{x:Math.max(region.bounds.minX,Math.min(region.bounds.maxX,target.x)),y:edge==="bottom"?region.bounds.minY:region.bounds.maxY};return Math.hypot(target.x-edgePoint.x,target.y-edgePoint.y)},edges=["right","left","top","bottom"];return edges.reduce((bestEdge,edge)=>{let bestCost=[...externalPcbPorts.values()].reduce((sum,target)=>sum+distanceToEdge(target,bestEdge),0);return[...externalPcbPorts.values()].reduce((sum,target)=>sum+distanceToEdge(target,edge),0)<bestCost?edge:bestEdge},edges[0])},getSourceTraceForConnectionOrThrow=({connectionOwner,connectionOwnerLabel,connectionSelector,sourceTraces})=>{let matchingSourceTraces=sourceTraces.filter(sourceTrace=>sourceTrace.name===connectionSelector);if(matchingSourceTraces.length===0){let selectedPort=connectionOwner.getSubcircuit().selectOne(connectionSelector,{type:"port"});selectedPort?.source_port_id&&(matchingSourceTraces=sourceTraces.filter(sourceTrace=>sourceTrace.connected_source_port_ids.includes(selectedPort.source_port_id)))}if(matchingSourceTraces.length===0)throw new Error(`Could not resolve "${connectionSelector}" in ${connectionOwnerLabel}`);if(matchingSourceTraces.length>1)throw new Error(`Connection "${connectionSelector}" resolves to multiple source traces in ${connectionOwnerLabel}`);return matchingSourceTraces[0]},getImplicitBreakoutSolverBuses=({routingScope,sourceTraces,coordinatedSourceTraceIds,availableLayers})=>{let solverBuses=[],subcircuitId=routingScope.getSubcircuit().subcircuit_id;for(let bus of routingScope.selectAll("bus")){if(bus.getSubcircuit().subcircuit_id!==subcircuitId)continue;let connectionIds=[];for(let connectionSelector of bus._parsedProps.connections){let sourceTrace=getSourceTraceForConnectionOrThrow({connectionOwner:bus,connectionOwnerLabel:`bus "${bus.name}"`,connectionSelector,sourceTraces});coordinatedSourceTraceIds.has(sourceTrace.source_trace_id)&&connectionIds.push(sourceTrace.source_trace_id)}if(connectionIds.length===0)continue;let solverBus={busId:bus.name,connectionIds};if(bus._parsedProps.preferredLayer!==void 0)solverBus={...solverBus,targetLayers:[bus._parsedProps.preferredLayer]};else if(bus._parsedProps.preferredLayers!==void 0)solverBus={...solverBus,targetLayers:bus._parsedProps.preferredLayers};else{let targetLayers=bus._parsedProps.pcbAllowedLayers??availableLayers;solverBus={...solverBus,targetLayers:[...new Set(targetLayers)]}}solverBuses.push(solverBus)}return solverBuses},getDifferentialPairSourceTraces=({routingScope,sourceTraces})=>{let subcircuitId=routingScope.getSubcircuit().subcircuit_id,pairs32=[];for(let differentialPair of routingScope.selectAll("differentialpair")){if(differentialPair.getSubcircuit().subcircuit_id!==subcircuitId)continue;let positiveSourceTrace=getSourceTraceForConnectionOrThrow({connectionOwner:differentialPair,connectionOwnerLabel:`differential pair "${differentialPair.name}"`,connectionSelector:differentialPair._parsedProps.positiveConnection,sourceTraces}),negativeSourceTrace=getSourceTraceForConnectionOrThrow({connectionOwner:differentialPair,connectionOwnerLabel:`differential pair "${differentialPair.name}"`,connectionSelector:differentialPair._parsedProps.negativeConnection,sourceTraces});pairs32.push({differentialPair,positiveSourceTraceId:positiveSourceTrace.source_trace_id,negativeSourceTraceId:negativeSourceTrace.source_trace_id})}return pairs32},getBoundaryPointSpacing=breakout=>{let board=breakout.root?.db.pcb_board.list()[0],traceWidth=board?.min_trace_width??.15,traceToPadClearance=board?.min_trace_to_pad_edge_clearance??.2,viaPadDiameter=board?.min_via_pad_diameter??.3;return getFanoutBoundaryPointSpacing({traceWidth,traceToPadClearance,viaPadDiameter})},getCoordinatedFanoutLayers=({routingScope,automaticBreakouts})=>{let coordinatedLayers=getBoardAvailableLayers(routingScope._getSubcircuitLayerCount());for(let automaticBreakout of automaticBreakouts){let fanoutRoutingLayers=automaticBreakout._parsedProps.fanoutRoutingLayers?.map(String);if(!fanoutRoutingLayers)continue;let fanoutLayerSet=new Set(fanoutRoutingLayers);coordinatedLayers=coordinatedLayers.filter(layer=>fanoutLayerSet.has(layer))}if(coordinatedLayers.length===0)throw new Error(`Automatic breakouts in routing scope "${routingScope.name}" have no shared fanout routing layer`);return coordinatedLayers},createImplicitBreakoutPointSolverContext=breakout=>{if(!breakout.root)throw new Error(`Automatic breakout "${breakout.name}" has no circuit root`);let routingScope=getRoutingScopeOrThrow(breakout),automaticBreakouts=getAutomaticBreakouts(routingScope,breakout),regionIds=new Set,collectedRegions=automaticBreakouts.map(automaticBreakout=>{let region=collectBreakoutRegionGeometry(automaticBreakout);if(regionIds.has(region.pcbGroupId))throw new Error(`Duplicate automatic breakout region "${region.pcbGroupId}"`);return regionIds.add(region.pcbGroupId),region}),{regions,horizontalPlacement}=sortRegionsByPlacement(collectedRegions),sourceTraceIds=new Set;for(let region of regions)for(let sourceTraceId of region.endpointBySourceTraceId.keys())sourceTraceIds.add(sourceTraceId);let sourceTraces=breakout.root.db.source_trace.list().filter(sourceTrace=>sourceTrace.subcircuit_id===routingScope.getSubcircuit().subcircuit_id),sourceTraceById=new Map;for(let sourceTrace of sourceTraces){if(sourceTraceById.has(sourceTrace.source_trace_id))throw new Error(`Duplicate connection identity "${sourceTrace.source_trace_id}"`);sourceTraceById.set(sourceTrace.source_trace_id,sourceTrace)}let sortedSourceTraceIds=[...sourceTraceIds].sort((firstSourceTraceId,secondSourceTraceId)=>{let firstName=sourceTraceById.get(firstSourceTraceId)?.name??firstSourceTraceId,secondName=sourceTraceById.get(secondSourceTraceId)?.name??secondSourceTraceId,nameDifference=firstName.localeCompare(secondName);return nameDifference!==0?nameDifference:firstSourceTraceId.localeCompare(secondSourceTraceId)});for(let sourceTraceId of sortedSourceTraceIds){if(!sourceTraceById.has(sourceTraceId))throw new Error(`Unknown connection identity "${sourceTraceId}"`);for(let region of regions)if(!region.endpointBySourceTraceId.has(sourceTraceId))throw new Error(`Connection "${sourceTraceId}" is missing endpoint for region "${region.pcbGroupId}"`)}let buses=getImplicitBreakoutSolverBuses({routingScope,sourceTraces,coordinatedSourceTraceIds:sourceTraceIds,availableLayers:getCoordinatedFanoutLayers({routingScope,automaticBreakouts})}),endpointsBySourceTraceId=new Map;for(let sourceTraceId of sortedSourceTraceIds)endpointsBySourceTraceId.set(sourceTraceId,regions.map(region=>region.endpointBySourceTraceId.get(sourceTraceId)));let differentialPairBySourceTraceId=new Map;for(let pair of getDifferentialPairSourceTraces({routingScope,sourceTraces})){let positiveIsCoordinated=sourceTraceIds.has(pair.positiveSourceTraceId),negativeIsCoordinated=sourceTraceIds.has(pair.negativeSourceTraceId);if(positiveIsCoordinated!==negativeIsCoordinated)throw new Error(`Differential pair "${pair.differentialPair.name}" is missing one coordinated member`);if(positiveIsCoordinated){if(differentialPairBySourceTraceId.has(pair.positiveSourceTraceId)||differentialPairBySourceTraceId.has(pair.negativeSourceTraceId))throw new Error("A connection belongs to multiple differential pairs");differentialPairBySourceTraceId.set(pair.positiveSourceTraceId,pair),differentialPairBySourceTraceId.set(pair.negativeSourceTraceId,pair)}}let connections=[],addedDifferentialPairs=new Set;for(let sourceTraceId of sortedSourceTraceIds){let differentialPair=differentialPairBySourceTraceId.get(sourceTraceId);if(!differentialPair){connections.push({connectionId:sourceTraceId,endpoints:endpointsBySourceTraceId.get(sourceTraceId)});continue}addedDifferentialPairs.has(differentialPair.differentialPair)||(addedDifferentialPairs.add(differentialPair.differentialPair),connections.push({type:"differential",connections:[{connectionId:differentialPair.positiveSourceTraceId,endpoints:endpointsBySourceTraceId.get(differentialPair.positiveSourceTraceId)},{connectionId:differentialPair.negativeSourceTraceId,endpoints:endpointsBySourceTraceId.get(differentialPair.negativeSourceTraceId)}]}))}let sourcePortIdByConnectionIdByRegionId=new Map,singleRegionPreferredEdge=regions.length===1?getSingleRegionPreferredEdge({region:regions[0],sourceTraces}):void 0;return{input:{regions:regions.map((region,regionIndex)=>(sourcePortIdByConnectionIdByRegionId.set(region.pcbGroupId,region.sourcePortIdBySourceTraceId),{regionId:region.pcbGroupId,bounds:region.bounds,edge:getFacingEdge({region,regionIndex,regions,horizontalPlacement,singleRegionPreferredEdge})})),connections,buses,boundaryPointSpacing:getBoundaryPointSpacing(breakout)},sourcePortIdByConnectionIdByRegionId}},cachedSolutionsByRoutingScope=new WeakMap,solveScope=(breakout,solverFn)=>{let context=createImplicitBreakoutPointSolverContext(breakout),output=solverFn(context.input);if(output instanceof Promise)throw new Error("Implicit breakout point solvers must return synchronously during PCB layout");let expectedConnectionCount=0;for(let connection of context.input.connections){if("type"in connection){expectedConnectionCount+=connection.connections.length;continue}expectedConnectionCount+=1}let breakoutPointsByRegionId=new Map,outputPointKeys=new Set;for(let region of context.input.regions)breakoutPointsByRegionId.set(region.regionId,[]);for(let breakoutPoint of output.breakoutPoints){let regionBreakoutPoints=breakoutPointsByRegionId.get(breakoutPoint.regionId);if(!regionBreakoutPoints)throw new Error(`Implicit breakout point solver returned unknown region "${breakoutPoint.regionId}"`);let outputPointKey=`${breakoutPoint.regionId}:${breakoutPoint.connectionId}`;if(outputPointKeys.has(outputPointKey))throw new Error(`Implicit breakout point solver returned duplicate endpoint for connection "${breakoutPoint.connectionId}" in region "${breakoutPoint.regionId}"`);outputPointKeys.add(outputPointKey);let sourcePortId=context.sourcePortIdByConnectionIdByRegionId.get(breakoutPoint.regionId)?.get(breakoutPoint.connectionId);if(!sourcePortId)throw new Error(`Implicit breakout point solver returned unknown connection "${breakoutPoint.connectionId}" for region "${breakoutPoint.regionId}"`);regionBreakoutPoints.push({sourcePortId,sourceTraceId:breakoutPoint.connectionId,layer:breakoutPoint.layer,x:breakoutPoint.x,y:breakoutPoint.y})}for(let[regionId,regionBreakoutPoints]of breakoutPointsByRegionId)if(regionBreakoutPoints.length!==expectedConnectionCount)throw new Error(`Implicit breakout point solver output is missing endpoints for region "${regionId}"`);return{breakoutPointsByRegionId}},solveImplicitBreakoutPoints=(breakout,solverFn)=>{let routingScope=breakout.parent;if(!routingScope||!breakout.pcb_group_id)throw new Error(`Automatic breakout "${breakout.name}" has no coordinated PCB region`);let cachedSolutions=cachedSolutionsByRoutingScope.get(routingScope);(!cachedSolutions||cachedSolutions.solverFn!==solverFn)&&(cachedSolutions={solverFn,solutions:[]},cachedSolutionsByRoutingScope.set(routingScope,cachedSolutions));let solution2=cachedSolutions.solutions.find(candidateSolution=>candidateSolution.breakoutPointsByRegionId.has(breakout.pcb_group_id));solution2||(solution2=solveScope(breakout,solverFn),cachedSolutions.solutions.push(solution2));let breakoutPoints=solution2.breakoutPointsByRegionId.get(breakout.pcb_group_id);if(!breakoutPoints)throw new Error(`Automatic breakout "${breakout.name}" references unknown implicit-breakout region "${breakout.pcb_group_id}"`);return breakoutPoints},Breakout=class extends Group5{get isDogboneFanout(){let autorouter=this._parsedProps.autorouter;return(typeof autorouter=="string"?autorouter:autorouter?.preset)==="dogbone"}get isRoutingDirective(){return!0}get config(){return{...super.config,zodProps:breakoutProps}}doInitialCreateAutoplacedBreakoutPoints(){for(let path of this._parsedProps.pcbTracePaths??[]){let exit=path.route.at(-1),point62=new SavedFanoutPoint({connection:path.connection,pcbX:exit.x,pcbY:exit.y});if(point62.exitLayer=exit.route_type==="wire"?exit.layer:exit.to_layer,this.add(point62),point62._matchConnection(),!point62.matchedPort||!this.selectAll("port").includes(point62.matchedPort))throw new Error(`Fanout trace path "${path.connection}" must select a port inside the fanout`);if(this.children.some(child=>!(child instanceof BreakoutPoint)||child===point62?!1:(child._matchConnection(),child.matchedPort===point62.matchedPort)))throw new Error(`Duplicate fanout exit for "${path.connection}"`)}let portsInBreakout=this.selectAll("port"),breakoutPortSet=new Set(portsInBreakout),manualBreakoutPoints=this.children.filter(c22=>c22 instanceof BreakoutPoint),manuallyMappedPorts=new Set(manualBreakoutPoints.map(bp22=>(bp22._matchConnection(),bp22.matchedPort)).filter(Boolean)),allTraces=this.getSubcircuit().selectAll("trace"),autoPlacedPorts=new Set;for(let trace of allTraces){let result=trace._findConnectedPorts();if(!(!result.allPortsFound||!result.ports))for(let port of result.ports){let isInside=breakoutPortSet.has(port),hasOutsidePort=result.ports.some(p22=>!breakoutPortSet.has(p22));if(!isInside||!hasOutsidePort&&!this.isDogboneFanout||manuallyMappedPorts.has(port)||autoPlacedPorts.has(port))continue;autoPlacedPorts.add(port);let breakoutPoint=new AutoplacedBreakoutPoint({});breakoutPoint.matchedPort=port,breakoutPoint.matchedSourceTraceId=trace.source_trace_id,this.add(breakoutPoint)}}}doInitialPcbAutoplaceBreakoutPoints(){if(this.root?.pcbDisabled)return;if(this.isDogboneFanout&&this._parsedProps.pcbTracePaths===void 0){for(let point62 of this.children){if(!(point62 instanceof AutoplacedBreakoutPoint))continue;let port=this.root.db.pcb_port.get(point62.matchedPort.pcb_port_id);point62._applySolvedBreakoutPoint({sourceTraceId:point62.matchedSourceTraceId,layer:port.layers[0],position:port})}return}let ownAutorouter=this.props.autorouter,inheritedAutorouter=ownAutorouter===void 0?this.parent?.getInheritedProperty("autorouter"):void 0,implicitBreakoutPointSolverFn=typeof ownAutorouter=="object"?ownAutorouter.implicitBreakoutPointSolverFn:typeof inheritedAutorouter=="object"?inheritedAutorouter.implicitBreakoutPointSolverFn:void 0,autoBreakoutPoints=this.children.filter(child=>child instanceof AutoplacedBreakoutPoint);if(autoBreakoutPoints.length===0||!this.root||!this.pcb_group_id)return;let pcbGroup=this.root.db.pcb_group.get(this.pcb_group_id);if(!pcbGroup?.width||!pcbGroup.height)return;let bounds={minX:pcbGroup.center.x-pcbGroup.width/2,maxX:pcbGroup.center.x+pcbGroup.width/2,minY:pcbGroup.center.y-pcbGroup.height/2,maxY:pcbGroup.center.y+pcbGroup.height/2},solvedBreakoutPoints;try{solvedBreakoutPoints=solveImplicitBreakoutPoints(this,implicitBreakoutPointSolverFn??defaultImplicitBreakoutPointSolverFn)}catch(error2){if(implicitBreakoutPointSolverFn||!reportWindingBreakoutInfeasibleError(this,error2))throw error2;return}let BOUNDARY_INSET_MM=1e-4,insetWithinBounds=(x22,y22)=>({x:Math.max(bounds.minX+BOUNDARY_INSET_MM,Math.min(bounds.maxX-BOUNDARY_INSET_MM,x22)),y:Math.max(bounds.minY+BOUNDARY_INSET_MM,Math.min(bounds.maxY-BOUNDARY_INSET_MM,y22))});for(let solvedPoint of solvedBreakoutPoints){let matchingBreakoutPoint=autoBreakoutPoints.find(child=>child.matchedPort?.source_port_id===solvedPoint.sourcePortId);if(matchingBreakoutPoint){let insetPoint=insetWithinBounds(solvedPoint.x,solvedPoint.y);matchingBreakoutPoint._applySolvedBreakoutPoint({sourceTraceId:solvedPoint.sourceTraceId,layer:solvedPoint.layer,position:insetPoint})}}}doInitialPcbPrimitiveRender(){super.doInitialPcbPrimitiveRender()}doInitialPcbPlacementDesignRuleChecks(){Breakout_doInitialPcbPlacementDesignRuleChecks(this)}},SilkscreenGraphic=class extends PrimitiveComponent2{constructor(){super(...arguments);__publicField(this,"pcb_silkscreen_graphic_id",null);__publicField(this,"pcb_silkscreen_graphic_ids",[]);__publicField(this,"pcb_silkscreen_path_ids",[]);__publicField(this,"isPcbPrimitive",!0)}get config(){return{componentName:"SilkscreenGraphic",zodProps:silkscreenGraphicProps}}doInitialPcbPrimitiveRender(){this.root?.pcbDisabled||this._queueAsyncEffect("SilkscreenGraphicRender",async()=>{if(this.root?.pcbDisabled)return;let{db:db22}=this.root,{_parsedProps:props}=this,{maybeFlipLayer}=this._getPcbPrimitiveFlippedHelpers(),layer=maybeFlipLayer(props.layer??"top");if(layer!=="top"&&layer!=="bottom")throw new Error(`Invalid layer "${layer}" for SilkscreenGraphic. Must be "top" or "bottom".`);let sourceImage=await loadImageSource(props.imageUrl);if(sourceImage.mimetype!==SVG_MIMETYPE&&sourceImage.mimetype!==PNG_MIMETYPE)throw new Error(`Unsupported imageUrl for SilkscreenGraphic: "${props.imageUrl}". Expected an SVG or PNG image.`);let imageAsset={project_relative_path:sourceImage.projectRelativePath,url:sourceImage.dataUrl,mimetype:sourceImage.mimetype},brepShapes=sourceImage.mimetype===SVG_MIMETYPE?getSvgBRepShapes({svg:sourceImage.text,width:props.width,height:props.height,transform:this._computePcbGlobalTransformBeforeLayout()}):[this.getPlacementBoxBRepShape()],pcbComponentId=this.parent?.pcb_component_id??this.getPrimitiveContainer()?.pcb_component_id??"";for(let brepShape of brepShapes){let graphic=db22.insert({type:"pcb_silkscreen_graphic",pcb_component_id:pcbComponentId,pcb_group_id:this.getGroup()?.pcb_group_id??void 0,subcircuit_id:this.getSubcircuit()?.subcircuit_id??void 0,layer,shape:"brep",brep_shape:brepShape,image_asset:imageAsset});this.pcb_silkscreen_graphic_ids.push(graphic.pcb_silkscreen_graphic_id)}this.pcb_silkscreen_graphic_id=this.pcb_silkscreen_graphic_ids[0]??null,sourceImage.mimetype===SVG_MIMETYPE&&this.insertRenderableSilkscreenPaths(sourceImage.text,layer)})}insertRenderableSilkscreenPaths(svg,layer){let{db:db22}=this.root,{_parsedProps:props}=this,transform7=this._computePcbGlobalTransformBeforeLayout(),pcb_component_id=this.parent?.pcb_component_id??this.getPrimitiveContainer()?.pcb_component_id??"";for(let route2 of getTransformedSvgPathRoutes({svg,width:props.width,height:props.height,transform:transform7})){if(route2.length<2)continue;let path=db22.pcb_silkscreen_path.insert({pcb_component_id,layer,route:route2,stroke_width:Math.max(Math.min(props.width,props.height)/60,.05),subcircuit_id:this.getSubcircuit()?.subcircuit_id??void 0,pcb_group_id:this.getGroup()?.pcb_group_id??void 0});this.pcb_silkscreen_path_ids.push(path.pcb_silkscreen_path_id)}}getPcbSize(){let{_parsedProps:props}=this;return{width:props.width,height:props.height}}getPlacementBoxBRepShape(){let{_parsedProps:props}=this,halfWidth=props.width/2,halfHeight=props.height/2,transform7=this._computePcbGlobalTransformBeforeLayout();return{outer_ring:{vertices:ensureClockwise([{x:-halfWidth,y:halfHeight},{x:halfWidth,y:halfHeight},{x:halfWidth,y:-halfHeight},{x:-halfWidth,y:-halfHeight}]).map(point62=>applyToPoint2(transform7,point62))},inner_rings:[]}}_moveCircuitJsonElements({deltaX,deltaY}){if(this.root?.pcbDisabled)return;let{db:db22}=this.root,moveVertex=vertex=>({...vertex,x:vertex.x+deltaX,y:vertex.y+deltaY});for(let graphicId of this.pcb_silkscreen_graphic_ids){let graphic=db22.pcb_silkscreen_graphic.get(graphicId);graphic&&db22.pcb_silkscreen_graphic.update(graphicId,{brep_shape:{outer_ring:{vertices:graphic.brep_shape.outer_ring.vertices.map(moveVertex)},inner_rings:graphic.brep_shape.inner_rings.map(ring4=>({vertices:ring4.vertices.map(moveVertex)}))}})}for(let pathId of this.pcb_silkscreen_path_ids){let path=db22.pcb_silkscreen_path.get(pathId);path&&db22.pcb_silkscreen_path.update(pathId,{route:path.route.map(point62=>({...point62,x:point62.x+deltaX,y:point62.y+deltaY}))})}}},Fiducial=class extends PrimitiveComponent2{constructor(){super(...arguments);__publicField(this,"pcb_smtpad_id",null);__publicField(this,"isPcbPrimitive",!0)}get config(){return{componentName:"Fiducial",zodProps:fiducialProps,sourceFtype:"simple_fiducial"}}doInitialPcbPrimitiveRender(){if(this.root?.pcbDisabled)return;let{db:db22}=this.root,{_parsedProps:props}=this,position4=this._getGlobalPcbPositionBeforeLayout(),{maybeFlipLayer}=this._getPcbPrimitiveFlippedHelpers(),pcb_component_id=this.parent?.pcb_component_id??this.getPrimitiveContainer()?.pcb_component_id,pcb_smtpad3=db22.pcb_smtpad.insert({pcb_component_id,layer:maybeFlipLayer(props.layer||"top"),shape:"circle",x:position4.x,y:position4.y,radius:distance.parse(props.padDiameter)/2,soldermask_margin:props.soldermaskPullback?distance.parse(props.soldermaskPullback):distance.parse(props.padDiameter)/2,is_covered_with_solder_mask:!0});this.pcb_smtpad_id=pcb_smtpad3.pcb_smtpad_id}getPcbSize(){let{_parsedProps:props}=this,d23=distance.parse(props.padDiameter);return{width:d23,height:d23}}_setPositionFromLayout(newCenter){if(!this.pcb_smtpad_id)return;let{db:db22}=this.root;db22.pcb_smtpad.update(this.pcb_smtpad_id,{x:newCenter.x,y:newCenter.y})}_moveCircuitJsonElements({deltaX,deltaY}){if(this.root?.pcbDisabled)return;let{db:db22}=this.root;if(!this.pcb_smtpad_id)return;let pad2=db22.pcb_smtpad.get(this.pcb_smtpad_id);pad2&&(pad2.shape==="rect"||pad2.shape==="circle"||pad2.shape==="rotated_rect"||pad2.shape==="pill"?this._setPositionFromLayout({x:pad2.x+deltaX,y:pad2.y+deltaY}):pad2.shape==="polygon"&&db22.pcb_smtpad.update(this.pcb_smtpad_id,{points:pad2.points.map(p22=>({x:p22.x+deltaX,y:p22.y+deltaY}))}))}},EPSILON30=1e-9,isWireRoutePoint=routePoint3=>routePoint3.route_type==="wire",isPointOnSegment42=(p22,a22,b22)=>{let cross52=(p22.y-a22.y)*(b22.x-a22.x)-(p22.x-a22.x)*(b22.y-a22.y);if(Math.abs(cross52)>EPSILON30)return!1;let dot23=(p22.x-a22.x)*(b22.x-a22.x)+(p22.y-a22.y)*(b22.y-a22.y);if(dot23<-EPSILON30)return!1;let squaredLength6=(b22.x-a22.x)**2+(b22.y-a22.y)**2;return!(dot23-squaredLength6>EPSILON30)},isPointInRing2=(point62,ring4)=>{if(ring4.length<3)return!1;let inside22=!1,previous=ring4[ring4.length-1];for(let current3 of ring4){if(isPointOnSegment42(point62,previous,current3))return!0;current3.y>point62.y!=previous.y>point62.y&&point62.x<(previous.x-current3.x)*(point62.y-current3.y)/(previous.y-current3.y)+current3.x&&(inside22=!inside22),previous=current3}return inside22},isPointInRectPour=(p22,pour)=>{let{center:center2,width,height}=pour,rotationRad=(pour.rotation??0)*Math.PI/180,cosR=Math.cos(-rotationRad),sinR=Math.sin(-rotationRad),dx22=p22.x-center2.x,dy22=p22.y-center2.y,localX=dx22*cosR-dy22*sinR,localY=dx22*sinR+dy22*cosR;return Math.abs(localX)<=width/2+EPSILON30&&Math.abs(localY)<=height/2+EPSILON30},isPointInBrepPour=(p22,pour)=>{let outerRing=pour.brep_shape.outer_ring.vertices.map(v22=>({x:v22.x,y:v22.y}));if(!isPointInRing2(p22,outerRing))return!1;for(let innerRing of pour.brep_shape.inner_rings){let points=innerRing.vertices.map(v22=>({x:v22.x,y:v22.y}));if(isPointInRing2(p22,points))return!1}return!0},isPointInCopperPour=(point62,pour)=>pour.shape==="rect"?isPointInRectPour(point62,pour):pour.shape==="brep"?isPointInBrepPour(point62,pour):!1,isTraceConnectedToSourceNet=(trace,sourceNetId,sourceTraceById)=>{if(trace.source_trace_id===sourceNetId)return!0;if(!trace.source_trace_id)return!1;let sourceTrace=sourceTraceById.get(trace.source_trace_id);return sourceTrace?sourceTrace.connected_source_net_ids.includes(sourceNetId):!1},isSegmentFullyInsideCopperPour=(start,end,pour)=>{let dx22=end.x-start.x,dy22=end.y-start.y;return Math.hypot(dx22,dy22)<=EPSILON30?!1:[0,.25,.5,.75,1].every(t48=>isPointInCopperPour({x:start.x+dx22*t48,y:start.y+dy22*t48},pour))},markTraceSegmentsInsideCopperPour=({db:db22,copperPour})=>{if(!copperPour.source_net_id)return;let sourceTraceById=new Map(db22.source_trace.list().map(sourceTrace=>[sourceTrace.source_trace_id,sourceTrace]));for(let trace of db22.pcb_trace.list()){if(!isTraceConnectedToSourceNet(trace,copperPour.source_net_id,sourceTraceById))continue;let routeChanged=!1,nextRoute=trace.route.map(routePoint3=>({...routePoint3}));for(let i22=0;i22<nextRoute.length-1;i22++){let fromRoutePoint=nextRoute[i22],toRoutePoint=nextRoute[i22+1];!fromRoutePoint||!toRoutePoint||!isWireRoutePoint(fromRoutePoint)||!isWireRoutePoint(toRoutePoint)||fromRoutePoint.layer!==copperPour.layer||toRoutePoint.layer!==copperPour.layer||isSegmentFullyInsideCopperPour({x:fromRoutePoint.x,y:fromRoutePoint.y},{x:toRoutePoint.x,y:toRoutePoint.y},copperPour)&&(fromRoutePoint.is_inside_copper_pour=!0,fromRoutePoint.copper_pour_id=copperPour.pcb_copper_pour_id,toRoutePoint.is_inside_copper_pour=!0,toRoutePoint.copper_pour_id=copperPour.pcb_copper_pour_id,routeChanged=!0)}routeChanged&&db22.pcb_trace.update(trace.pcb_trace_id,{route:nextRoute})}},pendingCopperPourRenders=new WeakMap,DEFAULT_THERMAL_RELIEF_SPOKE_WIDTH_MM=.3,renderAllCopperPoursForSubcircuit=async subcircuit=>{if(!subcircuit.root)return;let{db:db22}=subcircuit.root,copperPours=subcircuit.selectAll("copperpour").filter(copperPour=>copperPour.getSubcircuit()===subcircuit),resolvedCopperPours=[];for(let copperPour of copperPours){let{_parsedProps:props}=copperPour,sourceNetId=subcircuit.selectOne(props.connectsTo)?.source_net_id;if(!sourceNetId){copperPour.renderError(`Net "${props.connectsTo}" not found for copper pour`);continue}resolvedCopperPours.push({copperPour,sourceNetId})}if(resolvedCopperPours.length===0)return;let circuitJson=db22.toArray(),boardComponent=subcircuit._getBoard(),pcbBoard=boardComponent?.pcb_board_id?db22.pcb_board.get(boardComponent.pcb_board_id):void 0,resolvedPcbBoardOutline=pcbBoard?.outline?.length?pcbBoard.outline:void 0;if(!resolvedPcbBoardOutline&&pcbBoard?.width!==void 0&&pcbBoard.height!==void 0){let{center:center2,width,height}=pcbBoard;resolvedPcbBoardOutline=[{x:center2.x-width/2,y:center2.y-height/2},{x:center2.x+width/2,y:center2.y-height/2},{x:center2.x+width/2,y:center2.y+height/2},{x:center2.x-width/2,y:center2.y+height/2}]}let inputProblem=convertCircuitJsonToInputProblem(circuitJson,resolvedCopperPours.map(({copperPour,sourceNetId})=>{let{_parsedProps:props}=copperPour,clearance=props.clearance??.2;return{layer:props.layer,crosshatch:props.crosshatch,crosshatchPitch:props.crosshatchPitch,crosshatchWidth:props.crosshatchWidth,subcircuit_id:subcircuit.subcircuit_id??void 0,source_net_id:sourceNetId,pad_margin:props.padMargin??clearance,trace_margin:props.traceMargin??clearance,pour_margin:clearance,board_edge_margin:props.boardEdgeMargin??clearance,board_edge_outline:copperPour._isImplicitCopperPour?resolvedPcbBoardOutline:void 0,cutout_margin:props.cutoutMargin??clearance,...props.useThermalReliefs?{use_thermal_reliefs:!0,thermal_relief_spoke_width:DEFAULT_THERMAL_RELIEF_SPOKE_WIDTH_MM}:{},outline:props.outline??resolvedPcbBoardOutline}}));await initializeManifoldGeometry();let solver=new CopperPourPipelineSolver(inputProblem);subcircuit.root.emit("solver:started",{type:"solver:started",solverName:"CopperPourPipelineSolver",solverParams:inputProblem,solverConstructorArgs:[inputProblem],componentName:subcircuit.getString()});let{brep_shapes_by_region}=solver.getOutput();for(let[regionIndex,{copperPour,sourceNetId}]of resolvedCopperPours.entries()){let{_parsedProps:props}=copperPour,coveredWithSolderMask=props.coveredWithSolderMask??!1;for(let brepShape of brep_shapes_by_region[regionIndex]??[]){let insertedPour=db22.pcb_copper_pour.insert({shape:"brep",layer:props.layer,brep_shape:brepShape,source_net_id:sourceNetId,subcircuit_id:subcircuit.subcircuit_id??void 0,covered_with_solder_mask:coveredWithSolderMask});markTraceSegmentsInsideCopperPour({db:db22,copperPour:insertedPour})}}};function CopperPour_doInitialPcbCopperPourRender(copperPour){copperPour.root?.pcbDisabled||copperPour._queueAsyncEffect("PcbCopperPourRender",async()=>{let subcircuit=copperPour.getSubcircuit(),pendingRender=pendingCopperPourRenders.get(subcircuit);if(pendingRender){await pendingRender;return}let renderPromise=renderAllCopperPoursForSubcircuit(subcircuit);pendingCopperPourRenders.set(subcircuit,renderPromise);try{await renderPromise}finally{pendingCopperPourRenders.delete(subcircuit)}})}var renderViaStitchingForCopperPours=copperPour=>{let subcircuit=copperPour.getSubcircuit();if(!subcircuit.root)return;let copperPours=subcircuit.selectAll("copperpour").filter(candidateCopperPour=>candidateCopperPour.getSubcircuit()===subcircuit);if(copperPours[0]!==copperPour)return;let sourceNetIds=copperPours.flatMap(candidateCopperPour=>{let net=subcircuit.selectOne(candidateCopperPour._parsedProps.connectsTo);return net?.source_net_id?[net.source_net_id]:[]});if(sourceNetIds.length===0)return;let{db:db22}=subcircuit.root,pcbStyle3=copperPour.getInheritedMergedProperty("pcbStyle"),{holeDiameter,padDiameter}=getViaDiameterDefaults(pcbStyle3),boardComponent=copperPour._getBoard(),pcbBoard=boardComponent?.pcb_board_id?db22.pcb_board.get(boardComponent.pcb_board_id):void 0,solverInput={circuitJson:db22.toArray(),options:{sourceNetIds:[...new Set(sourceNetIds)],viaHoleDiameter:pcbBoard?.min_via_hole_diameter??holeDiameter,viaOuterDiameter:pcbBoard?.min_via_pad_diameter??padDiameter,viaStitchPitch:boardComponent?._parsedProps.viaStitchPitch}},solver=new ViaStitchSolver(solverInput);if(subcircuit.root.emit("solver:started",{type:"solver:started",solverName:"ViaStitchSolver",solverParams:solverInput,solverConstructorArgs:[solverInput],componentName:subcircuit.getString()}),solver.solve(),solver.failed)throw new Error(solver.error??"Via stitching solver failed");for(let pcbVia of solver.getOutput().pcbVias){let{pcb_via_id:_solverViaId,...pcbViaInput}=pcb_via.parse(pcbVia),insertedVia=db22.pcb_via.insert({...pcbViaInput,tented_on_top:void 0,tented_on_bottom:void 0});boardComponent?._generatedStitchingViaIds?.add(insertedVia.pcb_via_id)}};function CopperPour_doInitialPcbViaStitchRender(copperPour){copperPour.root?.pcbDisabled||!copperPour.root?._featurePcbViaStitching||copperPour._getBoard()?._parsedProps.enableViaStitching&&copperPour._queueAsyncEffect("PcbViaStitchRender",async()=>{renderViaStitchingForCopperPours(copperPour)})}var CopperPour=class extends PrimitiveComponent2{constructor(){super(...arguments);__publicField(this,"isPcbPrimitive",!0);__publicField(this,"_isImplicitCopperPour",!1)}get config(){return{componentName:"CopperPour",zodProps:copperPourProps}}getPcbSize(){return{width:0,height:0}}doInitialCreateNetsFromProps(){let{_parsedProps:props}=this;createNetsFromProps(this,[props.connectsTo])}doInitialPcbCopperPourRender(){CopperPour_doInitialPcbCopperPourRender(this)}doInitialPcbViaStitchRender(){CopperPour_doInitialPcbViaStitchRender(this)}},resolveAssemblyModel=props=>{if(props.model!==void 0)return/^https?:\/\//i.test(props.model)?resolveAssemblyModelUrl(props.model):{glbUrl:`https://modelcdn.tscircuit.com/jscad_models/${encodeURIComponent(props.model)}.glb`};if(props.modelUrl!==void 0)return resolveAssemblyModelUrl(props.modelUrl)},AssemblyDevice=class extends PrimitiveComponent2{constructor(){super(...arguments);__publicField(this,"isAssemblyDeviceContainer",!0)}get config(){return{componentName:"AssemblyDevice",zodProps:assemblyDeviceProps}}doInitialAssignNameToUnnamedComponents(){}computeSchematicGlobalTransform(){return identity()}_computePcbGlobalTransformBeforeLayout(){return identity()}doInitialSourceRender(){this._parsedProps.modelUrl===void 0&&this._parsedProps.model===void 0||!this.root||(this.source_component_id=this.root.db.source_component.insert({ftype:"subassembly",name:this.name}).source_component_id)}doInitialCadModelRender(){let model27=resolveAssemblyModel(this._parsedProps);!this.root||this.root.pcbDisabled||!this.source_component_id||!model27||(this.cad_component_id=renderAssemblyCadModel(this,model27,{position:{x:0,y:0,z:0},pcbRotation:0,layer:"top"}))}},resolveBoardMountRotationAnchor=board=>{let anchor3=board._parsedProps.mountRotationAnchor??"rightedge",transform7=board._computePcbGlobalTransformBeforeLayout();switch(anchor3){case"rightedge":return[transform7.a,transform7.b,0];case"leftedge":return[-transform7.a,-transform7.b,0];case"topedge":return[transform7.c,transform7.d,0];case"bottomedge":return[-transform7.c,-transform7.d,0]}let components=board.getDescendants().filter(component2=>matchesAssemblyIdentity(component2,anchor3));if(components.length!==1)throw new Error(`board "${board.name}" mountRotationAnchor "${anchor3}" matched ${components.length} components; expected exactly one on this board`);let component=components[0],pcbComponent=component.pcb_component_id&&board.root.db.pcb_component.get(component.pcb_component_id);if(!pcbComponent)throw new Error(`board "${board.name}" mountRotationAnchor "${anchor3}" has no PCB component geometry`);let pcbBoard=board.root.db.pcb_board.get(board.pcb_board_id),x22=pcbComponent.center.x-pcbBoard.center.x,y22=pcbComponent.center.y-pcbBoard.center.y;if(Math.hypot(x22,y22)<1e-6)throw new Error(`board "${board.name}" mountRotationAnchor "${anchor3}" is on the mounting axis and has no direction`);return[x22,y22,0]},radians2=degrees22=>degrees22*Math.PI/180,degrees2=angle3=>normalizeDegrees(angle3*180/Math.PI),shaftRotation=direction3=>{switch(direction3){case"x+":return{x:0,y:90,z:0};case"x-":return{x:0,y:270,z:0};case"y+":return{x:270,y:0,z:0};case"y-":return{x:90,y:0,z:0};default:return{x:0,y:0,z:0}}},resolveAssemblyMotorRotation=(motor,placement)=>{let alignment=shaftRotation(motor._parsedProps.shaftFacingDirection),board=resolveMotorMountedBoard(motor),input2=board?._parsedProps.mountRotation;if(!board||!input2)return alignment;let bottom=placement.layer==="bottom",sign=bottom?-1:1,orientation22=mat4_exports.create();mat4_exports.rotateX(orientation22,orientation22,radians2(alignment.x)),mat4_exports.rotateY(orientation22,orientation22,radians2(alignment.y+(bottom?180:0))),mat4_exports.rotateZ(orientation22,orientation22,radians2(sign*placement.pcbRotation));let expression3=input2.startsWith("calc(")?input2.match(/^calc\(\s*(.*?)\s*(?:([+-])\s*((?:\d+(?:\.\d*)?|\.\d+))\s*(degcw|degccw))?\s*\)$/):[input2,input2],path=expression3[1],separator=path.lastIndexOf("."),motorIdentity=path.slice(0,separator),directionName=path.slice(separator+1);if(!matchesAssemblyIdentity(motor,motorIdentity))throw new Error(`board "${board.name}" mountRotation "${input2}" must reference its mounted motor "${motor.name}"`);let direction3=Object.entries(motor.motorReferencePoints).find(([name])=>name===directionName)?.[1];if(!direction3)throw new Error(`assembly.motor "${motor.name}" has no ${directionName} reference`);if(Math.abs(direction3.direction.z)>1e-6)throw new Error(`board "${board.name}" mountRotation "${input2}" must reference a direction in the mounting face, e.g. "${motorIdentity}.wireside"`);let clockwiseAngle=radians2((expression3[2]==="-"?-1:1)*Number(expression3[3]??0)*(expression3[4]==="degccw"?-1:1)),anchor3=vec3_exports.normalize(vec3_exports.create(),resolveBoardMountRotationAnchor(board)),shaft=vec3_exports.transformMat4(vec3_exports.create(),[0,0,1],orientation22),turn=mat4_exports.fromRotation(mat4_exports.create(),-clockwiseAngle,shaft),target=vec3_exports.transformMat4(vec3_exports.create(),anchor3,turn),motorDirection=vec3_exports.transformMat4(vec3_exports.create(),[direction3.direction.x,direction3.direction.y,direction3.direction.z],orientation22),spin=Math.atan2(vec3_exports.dot(shaft,vec3_exports.cross(vec3_exports.create(),motorDirection,target)),vec3_exports.dot(motorDirection,target));mat4_exports.rotateZ(orientation22,orientation22,spin);let pitch=Math.asin(Math.max(-1,Math.min(1,orientation22[8]))),nonsingular=Math.abs(orientation22[8])<.999999,roll=nonsingular?Math.atan2(-orientation22[9],orientation22[10]):Math.atan2(orientation22[6],orientation22[5]),yaw=nonsingular?Math.atan2(-orientation22[4],orientation22[0]):0;return{x:degrees2(roll),y:degrees2(pitch)-(bottom?180:0),z:sign*degrees2(yaw)-placement.pcbRotation}},resolveAssemblyMotorPlacement=motor=>{let printedPartPlacement=resolveMotorPrintedPartPlacement(motor);if(printedPartPlacement)return printedPartPlacement;let board=resolveMotorMountedBoard(motor),orientation22=board?._parsedProps.mountOrientation,layer=orientation22?orientation22==="bottom_layer_toward_mount_face"?"bottom":"top":motor._parsedProps.shaftFacingDirection==="z-"?"bottom":"top";if(!board)return{position:{x:0,y:0,z:0},pcbRotation:0,layer};let pcbBoard=board.root.db.pcb_board.get(board.pcb_board_id);if(!pcbBoard)throw new Error(`Mounted board "${board.name}" has no PCB geometry`);let sign=layer==="bottom"?-1:1,boardTransform=board._computePcbGlobalTransformBeforeLayout();return{position:{...pcbBoard.center,z:sign*(-motor.motorReferencePoints.backface.position.z+(board._parsedProps.mountGap??0)+pcbBoard.thickness/2)},pcbRotation:normalizeDegrees(Math.atan2(boardTransform.b,boardTransform.a)*180/Math.PI),layer,subcircuit_id:pcbBoard.subcircuit_id}},resolveMotorFaceMount=motor=>{if(!getComponentsInAssemblyScope(motor).some(part=>part.componentName==="AssemblyMotor"&&part._parsedProps.mountedTo))return;let{transforms,roots,motorMountRoots,subcircuitId}=resolvePrintedPartMounts(motor);if(!motorMountRoots.has(roots.get(motor)))return;let world=transforms.get(motor),pitch=Math.asin(Math.max(-1,Math.min(1,world[8]))),nonsingular=Math.abs(world[8])<.999999,roll=nonsingular?Math.atan2(-world[9],world[10]):Math.atan2(world[6],world[5]),yaw=nonsingular?Math.atan2(-world[4],world[0]):0,degrees22=angle3=>normalizeDegrees(angle3*180/Math.PI);return{position:{x:world[12],y:world[13],z:world[14]},rotation:{x:degrees22(roll),y:degrees22(pitch),z:degrees22(yaw)},subcircuit_id:subcircuitId}},AssemblyMotor=class extends PrimitiveComponent2{get config(){return{componentName:"AssemblyMotor",zodProps:assemblyMotorProps}}get motorModelString(){let base=this._parsedProps.model??this._parsedProps.standard,wireConnection=this._parsedProps.wireConnection;return wireConnection===void 0?base:`${base}_${wireConnection}`}get motorModel(){let model27=(()=>{try{return parseModelString(this.motorModelString)}catch(cause){throw new Error(`assembly.motor "${this.name}" requires a NEMA modelprinter model: ${cause instanceof Error?cause.message:cause}`,{cause})}})();if(model27.fn!=="nema")throw new Error(`assembly.motor "${this.name}" requires a NEMA modelprinter model`);return model27}get motorReferencePoints(){let{fn:fn3,...parameters}=this.motorModel;return getNemaMotorReferencePoints(parameters)}doInitialSourceRender(){this.motorModel,this.source_component_id=this.root.db.source_component.insert({ftype:"motor",name:this.name}).source_component_id}doInitialCadModelRender(){if(!this.root||this.root.pcbDisabled||!this.source_component_id)return;let model27=resolveAssemblyModel({model:this.motorModelString}),faceMount=resolveMotorFaceMount(this);if(faceMount){this.cad_component_id=renderAssemblyCadModel(this,{...model27,rotationOffset:faceMount.rotation},{...faceMount,pcbRotation:0,layer:"top"});return}let placement=resolveAssemblyMotorPlacement(this);this.cad_component_id=renderAssemblyCadModel(this,{...model27,rotationOffset:resolveAssemblyMotorRotation(this,placement)},placement)}},formatMillimetersForModelprinter=millimeters=>Number(millimeters.toFixed(6)).toString(),getDefaultFlexScreenModel=component=>{let{width,height}=component._parsedProps;if(width===void 0||height===void 0)throw new Error(`assembly.screen "${component.name}" requires both width and height when cadModel is omitted`);return`flexscreen_w${formatMillimetersForModelprinter(width)}mm_h${formatMillimetersForModelprinter(height)}mm`},AssemblyScreen_doInitialCadModelRender=component=>{if(!component.root||component.root.pcbDisabled||!component.source_component_id)return;let placement=resolveAssemblyPlacement(component);component.cad_component_id=renderAssemblyCadModel(component,resolveAssemblyModel(component._parsedProps)??component._parsedProps.cadModel??getDefaultFlexScreenModel(component),placement)},AssemblyScreen=class extends PrimitiveComponent2{constructor(){super(...arguments);__publicField(this,"isAssemblyDeviceContainer",!0)}get config(){return{componentName:"AssemblyScreen",zodProps:assemblyScreenProps}}doInitialAssignNameToUnnamedComponents(){if(!this._parsedProps.name)throw new Error("assembly.screen requires a non-empty name")}doInitialSourceRender(){let sourceComponent=this.root.db.source_component.insert({ftype:"subassembly",name:this.name});this.source_component_id=sourceComponent.source_component_id}doInitialCadModelRender(){AssemblyScreen_doInitialCadModelRender(this)}},AssemblySubassembly=class extends PrimitiveComponent2{constructor(){super(...arguments);__publicField(this,"isAssemblyDeviceContainer",!0)}get config(){return{componentName:"AssemblySubassembly",zodProps:assemblySubassemblyProps}}doInitialAssignNameToUnnamedComponents(){if(!this._parsedProps.name)throw new Error("assembly.subassembly requires a non-empty name")}doInitialReactSubtreesRender(){(0,import_react11.isValidElement)(this.props.cadModel)&&this.add(createInstanceFromReactElement(this.props.cadModel))}doInitialSourceRender(){let sourceComponent=this.root.db.source_component.insert({ftype:"subassembly",name:this.name});this.source_component_id=sourceComponent.source_component_id}doInitialCadModelRender(){if(!this.root||this.root.pcbDisabled||!this.source_component_id)return;let placement=resolveAssemblyPlacement(this),model27=resolveAssemblyModel(this._parsedProps)??this._parsedProps.cadModel;model27&&!(typeof model27=="object"&&"type"in model27)&&(this.cad_component_id=renderAssemblyCadModel(this,model27,placement))}},renderPartReferenceSurfaces=part=>{let surfaces=getPartReferenceSurfaces(part);if(!surfaces.length)return;let{transforms,subcircuitId}=resolvePrintedPartMounts(part),world=transforms.get(part),rotation5=mat3_exports.fromMat4(mat3_exports.create(),world),toPoint=vector3=>({x:vector3[0],y:vector3[1],z:vector3[2]});for(let surface of surfaces){let child=part.children.find(child2=>child2.componentName==="AssemblyReferenceSurface"&&child2.name===surface.name);part.root.db.cad_reference_surface.insert({source_component_id:part.source_component_id,name:surface.name,shape:"rect",center:toPoint(vec3_exports.transformMat4(vec3_exports.create(),surface.origin,world)),normal:toPoint(vec3_exports.normalize(vec3_exports.create(),vec3_exports.transformMat3(vec3_exports.create(),surface.normal,rotation5))),x_axis:toPoint(vec3_exports.normalize(vec3_exports.create(),vec3_exports.transformMat3(vec3_exports.create(),surface.xAxis,rotation5))),width:child?._parsedProps.width,height:child?._parsedProps.height,subcircuit_id:subcircuitId})}},AssemblyPart=class extends PrimitiveComponent2{constructor(){super(...arguments);__publicField(this,"isAssemblyDeviceContainer",!0)}get config(){return{componentName:"AssemblyPart",zodProps:assemblyPartProps}}doInitialReactSubtreesRender(){(0,import_react12.isValidElement)(this.props.cadModel)&&this.add(createInstanceFromReactElement(this.props.cadModel))}doInitialSourceRender(){getPartReferenceSurfaces(this),this.source_component_id=this.root.db.source_component.insert({ftype:"subassembly",name:this.name,display_name:this._parsedProps.displayName}).source_component_id}doInitialCadModelRender(){if(!this.root||this.root.pcbDisabled||!this.source_component_id)return;renderPartReferenceSurfaces(this);let model27=resolveAssemblyModel(this._parsedProps)??this._parsedProps.cadModel;model27&&!(typeof model27=="object"&&"type"in model27)&&(this.cad_component_id=renderAssemblyCadModel(this,model27,resolveAssemblyPlacement(this)))}},AssemblyReferenceSurface=class extends PrimitiveComponent2{get config(){return{componentName:"AssemblyReferenceSurface",zodProps:assemblyReferenceSurfaceProps}}doInitialSourceRender(){if(this.parent?.componentName!=="AssemblyPart"&&this.parent?.componentName!=="AssemblyPrintedPart")throw new Error(`Reference surface "${this.name}" must be a child of assembly.part or assembly.printedpart`)}get referenceFrame(){let{name,plane,normalDirection,centerXOffset,centerYOffset,centerZOffset}=this._parsedProps,sign=normalDirection.endsWith("-")?-1:1;return{name,origin:[centerXOffset,centerYOffset,centerZOffset],normal:plane==="xy"?[0,0,sign]:plane==="xz"?[0,sign,0]:[sign,0,0],xAxis:plane==="yz"?[0,1,0]:[1,0,0]}}},getModelReachAboveOrigin=({cad,authoredModel})=>{let bounds=cad.model_bounds??authoredModel?.modelBounds,origin=cad.model_origin_position??authoredModel?.modelOriginPosition;if(!bounds?.min||!bounds?.max||!origin)return;let normal=cad.model_board_normal_direction??authoredModel?.modelBoardNormalDirection??"z+",axis=normal[0];if(axis!=="x"&&axis!=="y"&&axis!=="z")return;let min4=bounds.min[axis],max5=bounds.max[axis],at22=origin[axis];if(min4===void 0||max5===void 0||at22===void 0)return;let reach=normal.endsWith("-")?at22-min4:max5-at22;return Number.isFinite(reach)&&reach>=0?reach:void 0},getComponentBody=({owner,pcbComponent,cadComponent,boardSurfaceZ})=>{let cadModelProp22=owner?._parsedProps?.cadModel,authoredModel=cadModelProp22&&typeof cadModelProp22=="object"?cadModelProp22:void 0,size3=cadComponent?.size??authoredModel?.size,x22=size3?.x,y22=size3?.y,z20=size3?.z,reach=cadComponent?getModelReachAboveOrigin({cad:cadComponent,authoredModel}):void 0,originZ=cadComponent?.position?.z,aboveBoardHeight=reach!==void 0&&originZ!==void 0?reach+Math.abs(originZ-boardSurfaceZ):void 0;return{size:x22!==void 0&&y22!==void 0?{x:x22,y:y22,z:z20}:void 0,aboveBoardHeight,rotation:cadComponent?.rotation?.z??pcbComponent.rotation??0,footprint:{width:pcbComponent.width,height:pcbComponent.height}}},getNearestBoardWall=({point:point62,board})=>{let halfWidth=(board.width??0)/2,halfHeight=(board.height??0)/2,distances=[["x_neg",Math.abs(point62.x-(board.center.x-halfWidth))],["x_pos",Math.abs(point62.x-(board.center.x+halfWidth))],["y_neg",Math.abs(point62.y-(board.center.y-halfHeight))],["y_pos",Math.abs(point62.y-(board.center.y+halfHeight))]];return distances.sort((a22,b22)=>a22[1]-b22[1]),distances[0][0]},getSolverWall=boardWall=>boardWall,INSERTION_DIRECTION_TO_BOARD_WALL={from_top:"y_pos",from_bottom:"y_neg",from_left:"x_neg",from_right:"x_pos"},getFdmEnclosureSolverInput=(apertureComponent,{board,pcbBoard})=>{let owner=apertureComponent.parent;for(;owner&&owner!==board&&!owner.pcb_component_id;)owner=owner.parent;let pcbComponent=owner?.pcb_component_id?apertureComponent.root?.db.pcb_component.get(owner.pcb_component_id):null;if(!pcbComponent)throw new Error("<enclosure.cutoutaperture /> must be nested inside a component with a PCB footprint");let aperture=apertureComponent._parsedProps,apertureAxisDirection=owner?._getEnclosureApertureAxisDirection?.(pcbComponent.layer,pcbComponent.rotation??0),apertureDirection=apertureAxisDirection?apertureAxisDirection.z!==0?apertureAxisDirection.z>0?"from_above":"from_below":Math.abs(apertureAxisDirection.x)>=Math.abs(apertureAxisDirection.y)?apertureAxisDirection.x>=0?"from_right":"from_left":apertureAxisDirection.y>=0?"from_top":"from_bottom":pcbComponent.insertion_direction,verticalFace=apertureDirection==="from_above"?"z_pos":apertureDirection==="from_below"?"z_neg":void 0,boardSide=pcbComponent.layer==="bottom"?"bottom":"top",face,center2;if(verticalFace)face=verticalFace,center2={x:pcbComponent.center.x-pcbBoard.center.x,y:pcbComponent.center.y-pcbBoard.center.y};else{let point62=pcbComponent.cable_insertion_center??pcbComponent.center,boardWall=INSERTION_DIRECTION_TO_BOARD_WALL[apertureDirection]??getNearestBoardWall({point:point62,board:pcbBoard}),cableDelta=pcbComponent.cable_insertion_center?{x:pcbComponent.cable_insertion_center.x-pcbComponent.center.x,y:pcbComponent.cable_insertion_center.y-pcbComponent.center.y}:null,cableProjectionMatchesWall=cableDelta!=null&&(boardWall==="x_neg"||boardWall==="x_pos"?Math.abs(cableDelta.x)>=Math.abs(cableDelta.y):Math.abs(cableDelta.y)>=Math.abs(cableDelta.x)),tangentPoint=apertureAxisDirection?pcbComponent.center:cableProjectionMatchesWall?point62:pcbComponent.center;face=getSolverWall(boardWall),center2={x:tangentPoint.x-pcbBoard.center.x,y:tangentPoint.y-pcbBoard.center.y}}let cadComponent=apertureComponent.root?.db.cad_component.getWhere({pcb_component_id:pcbComponent.pcb_component_id})??null,boardSurfaceZ=(boardSide==="bottom"?-1:1)*((pcbBoard.thickness??board.boardThickness)/2),componentBody=getComponentBody({owner,pcbComponent,cadComponent,boardSurfaceZ}),commonInput={face,center:center2,boardSide,apertureAxisDirection,rotation:pcbComponent.rotation??void 0,depth:aperture.depth,componentBody,widthDimensionOffset:aperture.widthDimensionOffset,heightDimensionOffset:aperture.heightDimensionOffset,margin:aperture.margin};switch(aperture.shape){case"pill":case"rect":return{...commonInput,shape:aperture.shape,width:aperture.width,height:aperture.height};case"circle":return{...commonInput,shape:"circle",radius:aperture.radius}}},EnclosureCutoutAperture=class extends PrimitiveComponent2{get config(){return{componentName:"EnclosureCutoutAperture",zodProps:enclosureCutoutApertureProps}}getFdmEnclosureSolverInput(params){return getFdmEnclosureSolverInput(this,params)}},getReferencedEnclosureBoard=(component,boardRef)=>{let rootComponent=component.root?.firstChild,selectedComponent=rootComponent?selectOne(boardRef,rootComponent,{adapter:cssSelectPrimitiveComponentAdapter}):null,board=selectedComponent instanceof Board?selectedComponent:[rootComponent,...rootComponent?.getDescendants()??[]].find(descendant=>descendant instanceof Board&&descendant.isMatchingNameOrAlias(boardRef));if(!(board instanceof Board))throw new Error(`Could not find a <board /> matching enclosure boardRef "${boardRef}"`);return board},EnclosureFdmBox_doInitialCadModelRender=component=>{let root=component.root;if(!root||root.pcbDisabled||!component.source_component_id||!component.pcb_component_id)return;let{db:db22}=root,props=component._parsedProps,board=getReferencedEnclosureBoard(component,props.boardRef),pcbBoard=board.pcb_board_id?db22.pcb_board.get(board.pcb_board_id):null;if(!pcbBoard?.width||!pcbBoard.height)throw new Error(`Could not resolve dimensions for boardRef "${props.boardRef}"`);let boardThickness=pcbBoard.thickness??board.boardThickness,inputProblem={board:{width:pcbBoard.width,height:pcbBoard.height,thickness:boardThickness},width:props.width,height:props.height,depth:props.depth,wallThickness:props.wallThickness,floorThickness:props.floorThickness,lidThickness:props.lidThickness,boardClearance:props.boardClearance,standoffHeight:props.standoffHeight,topHeadroom:props.topHeadroom,lidLipDepth:props.lidLipDepth,apertures:props.disableCutouts?[]:board.getDescendants().filter(descendant=>descendant instanceof EnclosureCutoutAperture).map(aperture=>aperture.getFdmEnclosureSolverInput({board,pcbBoard}))},solver=new CreateFdmEnclosureSolver(inputProblem),solverConstructorArgs=solver.getConstructorParams();if(root.emit("solver:started",{type:"solver:started",solverName:"CreateFdmEnclosureSolver",solverParams:solverConstructorArgs[0],solverConstructorArgs,componentName:component.getString()}),solver.solve(),solver.failed)throw new Error(solver.error??"Failed to create FDM enclosure");let output=solver.getOutput();db22.pcb_component.update(component.pcb_component_id,{center:pcbBoard.center,width:output.dimensions.width,height:output.dimensions.height});let position4={x:pcbBoard.center.x,y:pcbBoard.center.y,z:-boardThickness/2-output.dimensions.floorThickness-output.dimensions.standoffHeight},cadComponents=output.parts.map(part=>db22.cad_component.insert({position:position4,rotation:{x:0,y:0,z:0},pcb_component_id:component.pcb_component_id,source_component_id:component.source_component_id,model_jscad:part.jscadPlan,model_unit_to_mm_scale_factor:1,model_object_fit:"contain_within_bounds",model_origin_alignment:"bottom_center_of_component",anchor_alignment:"center",show_as_translucent_model:!1,show_hidden_edges:props.showHiddenEdges}));component.cad_component_id=cadComponents[0]?.cad_component_id??null},EnclosureFdmBox=class _EnclosureFdmBox extends PrimitiveComponent2{get config(){return{componentName:"EnclosureFdmBox",zodProps:enclosureFdmBoxProps}}doInitialAssignNameToUnnamedComponents(){if(this._parsedProps.name)return;let top=this;for(;top.parent instanceof PrimitiveComponent2;)top=top.parent;let index2=[top,...top.getDescendants()].filter(component=>component instanceof _EnclosureFdmBox).indexOf(this);this.fallbackUnassignedName=`unnamed_enclosure_fdm_box_${index2===-1?0:index2+1}`}doInitialSourceRender(){let sourceComponent=this.root.db.source_component.insert({ftype:"simple_chip",name:this.name});this.source_component_id=sourceComponent.source_component_id}doInitialPcbComponentRender(){let root=this.root;if(!root||root.pcbDisabled||!this.source_component_id)return;let board=getReferencedEnclosureBoard(this,this._parsedProps.boardRef),center2=(board.pcb_board_id?root.db.pcb_board.get(board.pcb_board_id):null)?.center??board._getGlobalPcbPositionBeforeLayout(),pcbComponent=root.db.pcb_component.insert({center:center2,width:0,height:0,layer:"top",rotation:0,source_component_id:this.source_component_id,obstructs_within_bounds:!1,do_not_place:!0,is_allowed_to_be_off_board:!0});this.pcb_component_id=pcbComponent.pcb_component_id}doInitialCadModelRender(){EnclosureFdmBox_doInitialCadModelRender(this)}},Battery=class extends NormalComponent{get config(){return{componentName:"Battery",schematicSymbolName:this.props.symbolName??"battery",zodProps:batteryProps,sourceFtype:"simple_power_source"}}initPorts(){super.initPorts({additionalAliases:{pin1:["anode","pos","left"],pin2:["cathode","neg","right"]}})}doInitialSourceRender(){let{db:db22}=this.root,{_parsedProps:props}=this,source_component=db22.source_component.insert({name:this.name,ftype:"simple_power_source",capacity:props.capacity,supplier_part_numbers:props.supplierPartNumbers,manufacturer_part_number:resolveManufacturerPartNumber(props),are_pins_interchangeable:!1,display_name:props.displayName});this.source_component_id=source_component.source_component_id}},PinHeader=class extends NormalComponent{_getPcbRotationBeforeLayout(){let orientationRotation=this.props.pcbOrientation==="vertical"?-90:0;return(super._getPcbRotationBeforeLayout()??0)+orientationRotation}get config(){return{componentName:"PinHeader",zodProps:pinHeaderProps,shouldRenderAsSchematicBox:!0}}_getImpliedFootprintString(){let pinCount=this._parsedProps.pinCount??(Array.isArray(this._parsedProps.pinLabels)?this._parsedProps.pinLabels.length:this._parsedProps.pinLabels?Object.keys(this._parsedProps.pinLabels).length:0),holeDiameter=this._parsedProps.holeDiameter,platedDiameter=this._parsedProps.platedDiameter,pitch=this._parsedProps.pitch,showSilkscreenPinLabels=this._parsedProps.showSilkscreenPinLabels,rows=this._parsedProps.doubleRow?2:1,gender=this._parsedProps.gender;if(pinCount>0){let footprintString;if(pitch)!holeDiameter&&!platedDiameter?footprintString=`pinrow${pinCount}_p${pitch}`:footprintString=`pinrow${pinCount}_p${pitch}_id${holeDiameter}_od${platedDiameter}`;else if(!holeDiameter&&!platedDiameter)footprintString=`pinrow${pinCount}`;else return null;return showSilkscreenPinLabels!==!0&&(footprintString+="_nopinlabels"),gender==="female"&&(footprintString+="_female"),rows>1&&(footprintString+=`_rows${rows}`),footprintString}return null}initPorts(){let pinCount=this._parsedProps.pinCount??(Array.isArray(this._parsedProps.pinLabels)?this._parsedProps.pinLabels.length:this._parsedProps.pinLabels?Object.keys(this._parsedProps.pinLabels).length:1);for(let i22=1;i22<=pinCount;i22++){let rawLabel=Array.isArray(this._parsedProps.pinLabels)?this._parsedProps.pinLabels[i22-1]:this._parsedProps.pinLabels?.[`pin${i22}`];if(rawLabel){let primaryLabel=Array.isArray(rawLabel)?rawLabel[0]:rawLabel,otherLabels=Array.isArray(rawLabel)?rawLabel.slice(1):[];this.add(new Port({pinNumber:i22,name:primaryLabel,aliases:[`pin${i22}`,...otherLabels]}))}else this.add(new Port({pinNumber:i22,name:`pin${i22}`}))}}_getSchematicPortArrangement(){let pinCount=this._parsedProps.pinCount??1,facingDirection=this._parsedProps.schFacingDirection??this._parsedProps.facingDirection??"right",schPinArrangement=this._parsedProps.schPinArrangement,pins=Array.from({length:pinCount},(_22,i22)=>`pin${i22+1}`);return facingDirection==="left"?{leftSide:{direction:schPinArrangement?.leftSide?.direction??"top-to-bottom",pins:schPinArrangement?.leftSide?.pins??pins}}:facingDirection==="up"?{topSide:{direction:schPinArrangement?.topSide?.direction??"left-to-right",pins:schPinArrangement?.topSide?.pins??pins}}:facingDirection==="down"?{bottomSide:{direction:schPinArrangement?.bottomSide?.direction??"left-to-right",pins:schPinArrangement?.bottomSide?.pins??pins}}:{rightSide:{direction:schPinArrangement?.rightSide?.direction??"top-to-bottom",pins:schPinArrangement?.rightSide?.pins??pins}}}doInitialSourceRender(){let{db:db22}=this.root,{_parsedProps:props}=this,source_component=db22.source_component.insert({ftype:"simple_pin_header",name:this.name,supplier_part_numbers:props.supplierPartNumbers,manufacturer_part_number:resolveManufacturerPartNumber(props),pin_count:props.pinCount,gender:props.gender,are_pins_interchangeable:!0,display_name:props.displayName});this.source_component_id=source_component.source_component_id}};function getResonatorSymbolName(variant){switch(variant){case"two_ground_pins":return"crystal_4pin";case"ground_pin":return"resonator";case"no_ground":return"crystal";default:return"crystal"}}var Resonator=class extends NormalComponent{get config(){return{componentName:"Resonator",schematicSymbolName:this.props.symbolName??getResonatorSymbolName(this.props.pinVariant),zodProps:resonatorProps,shouldRenderAsSchematicBox:!1}}doInitialSourceRender(){let{db:db22}=this.root,{_parsedProps:props}=this,pinVariant=props.pinVariant||"no_ground",source_component=db22.source_component.insert({ftype:"simple_resonator",name:this.name,manufacturer_part_number:resolveManufacturerPartNumber(props),frequency:props.frequency,load_capacitance:props.loadCapacitance,supplier_part_numbers:props.supplierPartNumbers,pin_variant:pinVariant,are_pins_interchangeable:pinVariant==="no_ground"||pinVariant==="ground_pin",display_name:props.displayName});this.source_component_id=source_component.source_component_id}_getSchematicSymbolDisplayValue(){let freqDisplay=`${formatSiUnit(this._parsedProps.frequency)}Hz`;return this._parsedProps.loadCapacitance?`${freqDisplay} / ${formatSiUnit(this._parsedProps.loadCapacitance)}F`:freqDisplay}};function getPotentiometerSymbolName(variant){switch(variant){case"three_pin":return"potentiometer3";case"two_pin":return"potentiometer2";default:return"potentiometer2"}}var Potentiometer=class extends NormalComponent{get config(){return{componentName:"Potentiometer",schematicSymbolName:this.props.symbolName??getPotentiometerSymbolName(this.props.pinVariant),zodProps:potentiometerProps,shouldRenderAsSchematicBox:!1}}_getSchematicSymbolDisplayValue(){return`${formatSiUnit(this._parsedProps.maxResistance)}\u03A9`}doInitialSourceRender(){let{db:db22}=this.root,{_parsedProps:props}=this,pinVariant=props.pinVariant||"two_pin",source_component=db22.source_component.insert({ftype:"simple_potentiometer",name:this.name,manufacturer_part_number:resolveManufacturerPartNumber(props),supplier_part_numbers:props.supplierPartNumbers,max_resistance:props.maxResistance,pin_variant:pinVariant,are_pins_interchangeable:pinVariant==="two_pin",display_name:props.displayName,display_max_resistance:this._getSchematicSymbolDisplayValue()});this.source_component_id=source_component.source_component_id}},DEFAULT_CRYSTAL_MAX_TRACE_LENGTH_MM=10,DEFAULT_CRYSTAL_MAX_VIA_COUNT=0,Crystal=class extends NormalComponent{get config(){return{schematicSymbolName:this.props.symbolName??(this.props.pinVariant==="four_pin"?"crystal_4pin":"crystal"),componentName:"Crystal",zodProps:crystalProps,sourceFtype:"simple_crystal"}}initPorts(){let additionalAliases=this.props.pinVariant==="four_pin"?{pin1:["left1","1","X1"],pin2:["top1","2","gnd1"],pin3:["right1","3","X2"],pin4:["bottom1","4","gnd2"]}:{pin1:["pos","left","X1"],pin2:["neg","right","X2"]};super.initPorts({additionalAliases})}_getSchematicSymbolDisplayValue(){let freqDisplay=`${formatSiUnit(this._parsedProps.frequency)}Hz`;return this._parsedProps.loadCapacitance?`${freqDisplay} / ${formatSiUnit(this._parsedProps.loadCapacitance)}F`:freqDisplay}doInitialSourceRender(){let{db:db22}=this.root,{_parsedProps:props}=this,source_component=db22.source_component.insert({name:this.name,ftype:"simple_crystal",manufacturer_part_number:resolveManufacturerPartNumber(props),supplier_part_numbers:props.supplierPartNumbers,frequency:props.frequency,load_capacitance:props.loadCapacitance,pin_variant:props.pinVariant||"two_pin",are_pins_interchangeable:(props.pinVariant||"two_pin")==="two_pin",display_name:props.displayName});this.source_component_id=source_component.source_component_id}doInitialSourceDesignRuleChecks(){if(super.doInitialSourceDesignRuleChecks(),!this.source_component_id)return;let{db:db22}=this.root,maximumTraceLength=this._parsedProps.maxTraceLength??DEFAULT_CRYSTAL_MAX_TRACE_LENGTH_MM,crystalSignalSourcePortIds=new Set,crystalSignalConnectivityMapKeys=new Set;for(let signalPort of[this.portMap.X1,this.portMap.X2]){if(!signalPort.source_port_id)continue;let sourcePort=db22.source_port.get(signalPort.source_port_id);sourcePort&&(crystalSignalSourcePortIds.add(signalPort.source_port_id),sourcePort.subcircuit_connectivity_map_key&&crystalSignalConnectivityMapKeys.add(sourcePort.subcircuit_connectivity_map_key))}for(let sourceTrace of db22.source_trace.list()){let isDirectlyConnectedToCrystal=sourceTrace.connected_source_port_ids.some(sourcePortId=>crystalSignalSourcePortIds.has(sourcePortId)),isOnCrystalNet=sourceTrace.subcircuit_connectivity_map_key!==void 0&&crystalSignalConnectivityMapKeys.has(sourceTrace.subcircuit_connectivity_map_key);if(!isDirectlyConnectedToCrystal&&!isOnCrystalNet)continue;let needsMaximumTraceLength=typeof sourceTrace.max_length!="number"||sourceTrace.max_length>maximumTraceLength,needsMaximumViaCount=sourceTrace.max_via_count!==DEFAULT_CRYSTAL_MAX_VIA_COUNT;!needsMaximumTraceLength&&!needsMaximumViaCount||db22.source_trace.update(sourceTrace.source_trace_id,{...needsMaximumTraceLength?{max_length:maximumTraceLength}:{},...needsMaximumViaCount?{max_via_count:DEFAULT_CRYSTAL_MAX_VIA_COUNT}:{}})}}},OpAmp=class extends NormalComponent{constructor(){super(...arguments);__publicField(this,"inverting_input",this.portMap.inverting_input);__publicField(this,"non_inverting_input",this.portMap.non_inverting_input);__publicField(this,"output",this.portMap.output);__publicField(this,"positive_supply",this.portMap.positive_supply);__publicField(this,"negative_supply",this.portMap.negative_supply)}getSchematicSymbolName(){return this.props.symbolName?this.props.symbolName:this.props.connections?.positive_supply||this.props.connections?.negative_supply?"opamp_with_power":"opamp_no_power"}get config(){return{componentName:"OpAmp",schematicSymbolName:this.getSchematicSymbolName(),zodProps:opampProps,sourceFtype:"simple_op_amp"}}initPorts(){let additionalAliases={pin1:["non_inverting_input"],pin2:["inverting_input"]};this.getSchematicSymbolName()==="opamp_with_power"?Object.assign(additionalAliases,{pin4:["output"],pin5:["positive_supply","vcc","vdd"],pin3:["negative_supply","vee","vss","gnd"]}):Object.assign(additionalAliases,{pin3:["output"],pin4:["positive_supply","vcc","vdd"],pin5:["negative_supply","vee","vss","gnd"]}),super.initPorts({pinCount:5,additionalAliases})}doInitialSourceRender(){let{db:db22}=this.root,{_parsedProps:props}=this,source_component=db22.source_component.insert({ftype:"simple_op_amp",name:this.name,supplier_part_numbers:props.supplierPartNumbers,manufacturer_part_number:resolveManufacturerPartNumber(props),display_name:props.displayName});this.source_component_id=source_component.source_component_id}doInitialSimulationRender(){let{db:db22}=this.root,invertingInputPort=this.portMap.inverting_input,nonInvertingInputPort=this.portMap.non_inverting_input,outputPort=this.portMap.output,positiveSupplyPort=this.portMap.positive_supply,negativeSupplyPort=this.portMap.negative_supply;!invertingInputPort?.source_port_id||!nonInvertingInputPort?.source_port_id||!outputPort?.source_port_id||!positiveSupplyPort?.source_port_id||!negativeSupplyPort?.source_port_id||db22.simulation_op_amp.insert({type:"simulation_op_amp",source_component_id:this.source_component_id,inverting_input_source_port_id:invertingInputPort.source_port_id,non_inverting_input_source_port_id:nonInvertingInputPort.source_port_id,output_source_port_id:outputPort.source_port_id,positive_supply_source_port_id:positiveSupplyPort.source_port_id,negative_supply_source_port_id:negativeSupplyPort.source_port_id})}},TESTPOINT_DEFAULTS={HOLE_DIAMETER:.5,SMT_CIRCLE_DIAMETER:1.2,SMT_RECT_SIZE:2},TestPoint=class extends NormalComponent{get config(){return{componentName:"TestPoint",schematicSymbolName:this.props.symbolName??"testpoint",zodProps:testpointProps,sourceFtype:FTYPE.simple_test_point}}_getPropsWithDefaults(){let{padShape,holeDiameter,footprintVariant,padDiameter,width,height}=this._parsedProps;return!footprintVariant&&holeDiameter&&(footprintVariant="through_hole"),footprintVariant??(footprintVariant="through_hole"),padShape??(padShape="circle"),footprintVariant==="pad"?padShape==="circle"?padDiameter??(padDiameter=TESTPOINT_DEFAULTS.SMT_CIRCLE_DIAMETER):padShape==="rect"&&(width??(width=TESTPOINT_DEFAULTS.SMT_RECT_SIZE),height??(height=width)):footprintVariant==="through_hole"&&(holeDiameter??(holeDiameter=TESTPOINT_DEFAULTS.HOLE_DIAMETER)),{padShape,holeDiameter,footprintVariant,padDiameter,width,height}}_getImpliedFootprintString(){let{padShape,holeDiameter,footprintVariant,padDiameter,width,height}=this._getPropsWithDefaults();if(footprintVariant==="through_hole")return`platedhole_d${holeDiameter}`;if(footprintVariant==="pad"){if(padShape==="circle")return`smtpad_circle_d${padDiameter}`;if(padShape==="rect")return`smtpad_rect_w${width}_h${height}`}throw new Error(`Footprint variant "${footprintVariant}" with pad shape "${padShape}" not implemented`)}doInitialSourceRender(){let{db:db22}=this.root,{_parsedProps:props}=this,{padShape,holeDiameter,footprintVariant,padDiameter,width,height}=this._getPropsWithDefaults(),source_component=db22.source_component.insert({ftype:FTYPE.simple_test_point,name:this.name,supplier_part_numbers:props.supplierPartNumbers,manufacturer_part_number:resolveManufacturerPartNumber(props),footprint_variant:footprintVariant,pad_shape:padShape,pad_diameter:padDiameter,hole_diameter:holeDiameter,width,height,are_pins_interchangeable:!0,display_name:props.displayName});this.source_component_id=source_component.source_component_id}},SchematicSymbol_doInitialSchematicComponentRender=schematicSymbol=>{if(schematicSymbol.root?.schematicDisabled||schematicSymbol.getCollapsedSchematicBoxAncestor())return;let{db:db22}=schematicSymbol.root,symbolName=schematicSymbol._getSchematicSymbolNameOrThrow(),symbol=zh[symbolName];if(!symbol)throw new Error(`No schematic symbol found for "${symbolName}"`);let center2=schematicSymbol._getGlobalSchematicPositionBeforeLayout(),schematicSheetId=schematicSymbol._resolveSchematicSheetId(),subcircuitId=schematicSymbol.getSubcircuit().subcircuit_id??void 0,schematicComponent=db22.schematic_component.insert({center:center2,size:{...symbol.size},is_box_with_pins:!0,symbol_name:symbolName,source_component_id:schematicSymbol.source_component_id??void 0,schematic_sheet_id:schematicSheetId});schematicSymbol.schematic_component_id=schematicComponent.schematic_component_id;for(let symbolPort of symbol.ports){let port=schematicSymbol.getPortForSymbolPort(symbolPort);if(!port?.source_port_id)throw new Error(`Missing source port for schematic symbol port "${symbolPort.labels.join("/")}" on ${schematicSymbol.getString()}`);let portCenter={x:center2.x+symbolPort.x-symbol.center.x,y:center2.y+symbolPort.y-symbol.center.y},schematicPort=db22.schematic_port.insert({schematic_component_id:schematicComponent.schematic_component_id,center:portCenter,source_port_id:port.source_port_id,facing_direction:getRelativeDirection(center2,portCenter),distance_from_component_edge:.4,pin_number:port._parsedProps.pinNumber,display_pin_label:port._parsedProps.aliases?.[0],is_connected:!1,schematic_sheet_id:schematicSheetId,subcircuit_id:subcircuitId});port.schematic_port_id=schematicPort.schematic_port_id}},getSingleConnectionTarget=(connectionName,target)=>{let targets=Array.isArray(target)?target:[target];if(targets.length!==1)throw new Error(`SchematicSymbol connection "${connectionName}" must select exactly one physical port`);return targets[0]},SchematicSymbol_doInitialPortMatching=schematicSymbol=>{let{db:db22}=schematicSymbol.root,{chipRef,connections}=schematicSymbol._parsedProps;if(chipRef&&!connections){db22.source_property_ignored_warning.insert({source_component_id:schematicSymbol.source_component_id,property_name:"chipRef",message:`${schematicSymbol.getString()} has chipRef "${chipRef}" without connections. chipRef will be ignored.`,error_type:"source_property_ignored_warning",subcircuit_id:schematicSymbol.getSubcircuit().subcircuit_id??void 0});return}if(connections&&!chipRef){db22.source_property_ignored_warning.insert({source_component_id:schematicSymbol.source_component_id,property_name:"connections",message:`${schematicSymbol.getString()} has connections without chipRef. connections will be ignored.`,error_type:"source_property_ignored_warning",subcircuit_id:schematicSymbol.getSubcircuit().subcircuit_id??void 0});return}if(!chipRef||!connections)return;let referencedChip=schematicSymbol.getSubcircuit().selectOne(chipRef);if(!referencedChip?.source_component_id)throw new Error(`Could not resolve chipRef "${chipRef}" for ${schematicSymbol.getString()}`);let usedConnectionNames=new Set;for(let schematicPort of schematicSymbol.ports){let symbolPort=schematicPort.schematicSymbolPortDef,matchingConnections=Object.entries(connections).filter(([connectionName2])=>schematicPort.isMatchingAnyOf([connectionName2]));if(matchingConnections.length===0)throw new Error(`${schematicSymbol.getString()} is missing an explicit connection for symbol port "${symbolPort.labels.join("/")}"`);if(matchingConnections.length>1)throw new Error(`${schematicSymbol.getString()} has multiple connections for symbol port "${symbolPort.labels.join("/")}"`);let[connectionName,connectionTarget5]=matchingConnections[0];usedConnectionNames.add(connectionName);let targetSelector=getSingleConnectionTarget(connectionName,connectionTarget5),physicalPort=schematicSymbol.getSubcircuit().selectOne(targetSelector,{type:"port"});if(!physicalPort?.source_port_id)throw new Error(`Could not resolve connection "${connectionName}" target "${targetSelector}" for ${schematicSymbol.getString()}`);if(db22.source_port.get(physicalPort.source_port_id)?.source_component_id!==referencedChip.source_component_id)throw new Error(`Connection "${connectionName}" target "${targetSelector}" does not belong to chipRef "${chipRef}"`);schematicPort.source_port_id=physicalPort.source_port_id,schematicPort.source_component_id=physicalPort.source_component_id}let unusedConnectionNames=Object.keys(connections).filter(connectionName=>!usedConnectionNames.has(connectionName));if(unusedConnectionNames.length>0)throw new Error(`${schematicSymbol.getString()} has connections that do not match symbol ports: ${unusedConnectionNames.join(", ")}`)},SchematicSymbol=class extends PrimitiveComponent2{constructor(){super(...arguments);__publicField(this,"isSchematicPrimitive",!0);__publicField(this,"isPrimitiveContainer",!0)}get config(){return{componentName:"SchematicSymbol",schematicSymbolName:this.props.symbolName,zodProps:schematicSymbolProps}}initPorts(){let symbol=zh[this._getSchematicSymbolNameOrThrow()],shouldCreateSourcePort=!(this._parsedProps.chipRef&&this._parsedProps.connections);for(let symbolPort of symbol.ports){let pinNumber=getPinNumberFromLabels(symbolPort.labels);if(!pinNumber)throw new Error(`Schematic symbol port must have a numeric pin label: ${symbolPort.labels.join("/")}`);let existingPort=this.ports.find(port2=>port2._parsedProps.pinNumber===pinNumber);if(existingPort){existingPort.schematicSymbolPortDef=symbolPort;continue}let aliases4=symbolPort.labels.filter(label=>label!==pinNumber.toString()&&label!==`pin${pinNumber}`),port=new Port({pinNumber,aliases:aliases4},{shouldCreateSourcePort});port.schematicSymbolPortDef=symbolPort,this.add(port)}}doInitialInitializePortsFromChildren(){this.initPorts()}updateInitializePortsFromChildren(){this.initPorts()}get ports(){return this.children.filter(child=>child instanceof Port)}getPortForSymbolPort(symbolPort){return this.ports.find(port=>port.schematicSymbolPortDef===symbolPort)??null}doInitialSourceRender(){let sourceComponent=this.root.db.source_component.insert({ftype:"simple_chip",name:this.name,display_name:this._parsedProps.displayName,are_pins_interchangeable:!1});this.source_component_id=sourceComponent.source_component_id}doInitialPortMatching(){SchematicSymbol_doInitialPortMatching(this)}doInitialSchematicComponentRender(){SchematicSymbol_doInitialSchematicComponentRender(this)}},SchematicSection=class _SchematicSection extends PrimitiveComponent2{constructor(){super(...arguments);__publicField(this,"isSchematicPrimitive",!0)}get config(){return{componentName:"SchematicSection",zodProps:schematicSectionProps}}_computeSectionBounds(board,sectionName,schematicSheetId){let{db:db22}=this.root,members=board.getDescendants().filter(c22=>c22.getSchematicSectionName()===sectionName);if(members.length===0)return null;let positions=[];for(let member of members){let schematicComponentId=member.schematic_component_id;if(!schematicComponentId)continue;let schComp=db22.schematic_component.get(schematicComponentId);if(!schComp||schComp.schematic_sheet_id!==schematicSheetId)continue;let hw22=schComp.size.width/2,hh22=schComp.size.height/2;positions.push({minX:schComp.center.x-hw22,maxX:schComp.center.x+hw22,minY:schComp.center.y-hh22,maxY:schComp.center.y+hh22});for(let text of db22.schematic_text.list({schematic_component_id:schematicComponentId}))positions.push(getSchematicTextBounds({text:text.text,position:text.position,anchor:text.anchor,fontSize:text.font_size}))}return positions.length===0?null:computeBoundsFromCellContents(positions)}doInitialSchematicSectionRender(){if(this.root?.schematicDisabled)return;let board=this.root?._getBoard();if(!board)return;let schematicSheetId=this._resolveSchematicSheetId(),allSections=board.getDescendants().filter(component=>component instanceof _SchematicSection&&component._resolveSchematicSheetId()===schematicSheetId);if(allSections[0]!==this)return;let{db:db22}=this.root,PADDING=.5,LABEL_PADDING=.2,STROKE_WIDTH=.02,TOL42=.001,namedSectionsWithBounds=allSections.map(section=>{let bounds=section._computeSectionBounds(board,section._parsedProps.name,schematicSheetId);return bounds?{displayName:section._parsedProps.displayName,sectionTitleFontSize:section._parsedProps.sectionTitleFontSize,rawBounds:bounds,cell:{minX:bounds.minX-PADDING,maxX:bounds.maxX+PADDING,minY:bounds.minY-PADDING,maxY:bounds.maxY+PADDING}}:null}).filter(s22=>s22!==null),unsectionedBounds=this._computeSectionBounds(board,null,schematicSheetId),allSectionsWithBounds=[...namedSectionsWithBounds];if(unsectionedBounds&&allSectionsWithBounds.push({displayName:void 0,sectionTitleFontSize:void 0,rawBounds:unsectionedBounds,cell:{minX:unsectionedBounds.minX-PADDING,maxX:unsectionedBounds.maxX+PADDING,minY:unsectionedBounds.minY-PADDING,maxY:unsectionedBounds.maxY+PADDING}}),allSectionsWithBounds.length===0)return;let allCells=allSectionsWithBounds.map(s22=>s22.cell),outer=computeBoundsFromCellContents(allCells),dividers=calculateCellBoundaries2(allSectionsWithBounds.map(s22=>s22.rawBounds),{cellMargin:1});for(let line2 of dividers)db22.schematic_line.insert({x1:line2.start.x,y1:line2.start.y,x2:line2.end.x,y2:line2.end.y,stroke_width:STROKE_WIDTH,color:"#000000",is_dashed:!0,schematic_sheet_id:schematicSheetId});let hDividers=dividers.filter(l22=>Math.abs(l22.start.y-l22.end.y)<TOL42),vDividers=dividers.filter(l22=>Math.abs(l22.start.x-l22.end.x)<TOL42);for(let sectionWithBounds of allSectionsWithBounds){let{displayName,sectionTitleFontSize,rawBounds,cell}=sectionWithBounds;if(!displayName)continue;let overlapsAnotherSection=allSectionsWithBounds.some(section=>section!==sectionWithBounds&&doBoundsOverlap(section.rawBounds,rawBounds)),dividersAbove=hDividers.map(l22=>l22.start.y).filter(y22=>y22>rawBounds.maxY),topBoundary=dividersAbove.length>0?Math.min(...dividersAbove):outer.maxY,dividersToLeft=vDividers.map(l22=>l22.start.x).filter(x22=>x22<rawBounds.minX),leftBoundary=outer.minX;overlapsAnotherSection&&(leftBoundary=cell.minX),dividersToLeft.length>0&&(leftBoundary=Math.max(...dividersToLeft));let fontSize=sectionTitleFontSize??.18;db22.schematic_text.insert({anchor:"top_left",text:displayName,font_size:fontSize,color:"#000000",position:{x:leftBoundary+LABEL_PADDING,y:Math.max(topBoundary-LABEL_PADDING,rawBounds.maxY+LABEL_PADDING+fontSize)},rotation:0,schematic_sheet_id:schematicSheetId})}}},getCircuitJsonSchematicSheetSize=sheetSize=>schematic_sheet_size.parse(sheetSize.toLowerCase()),SCHEMATIC_SHEET_DIMENSIONS_MM={a4:{width:297,height:210},ansi_b:{width:431.8,height:279.4}},resolveCircuitJsonSchematicSheetProperties=({sheetSize,sheetWidth,sheetHeight})=>{let circuitJsonSheetSize=getCircuitJsonSchematicSheetSize(sheetSize),defaultDimensions=SCHEMATIC_SHEET_DIMENSIONS_MM[circuitJsonSheetSize];return{sheetSize:circuitJsonSheetSize,sheetWidth:sheetWidth??defaultDimensions.width,sheetHeight:sheetHeight??defaultDimensions.height}},SCHEMATIC_UNIT_TO_MM2=10.16/1.1,SCHEMATIC_SHEET_INNER_MARGIN2=5/SCHEMATIC_UNIT_TO_MM2,BOUNDS_EPSILON=1e-6,getSchematicElementId=schematicElement=>{switch(schematicElement.type){case"schematic_component":return schematicElement.schematic_component_id;case"schematic_net_label":return schematicElement.schematic_net_label_id;case"schematic_trace":return schematicElement.schematic_trace_id}},warnIfSchematicElementsOutsideSheet=({db:db22,schematicSheetId,schematicSheetName,schematicSheetCenter,sheetWidth,sheetHeight})=>{let sheetWidthInSchematicUnits=sheetWidth/SCHEMATIC_UNIT_TO_MM2,sheetHeightInSchematicUnits=sheetHeight/SCHEMATIC_UNIT_TO_MM2,sheetContentBounds={minX:schematicSheetCenter.x-sheetWidthInSchematicUnits/2+SCHEMATIC_SHEET_INNER_MARGIN2,maxX:schematicSheetCenter.x+sheetWidthInSchematicUnits/2-SCHEMATIC_SHEET_INNER_MARGIN2,minY:schematicSheetCenter.y-sheetHeightInSchematicUnits/2+SCHEMATIC_SHEET_INNER_MARGIN2,maxY:schematicSheetCenter.y+sheetHeightInSchematicUnits/2-SCHEMATIC_SHEET_INNER_MARGIN2},checkedElements=[...db22.schematic_component.list(),...db22.schematic_net_label.list(),...db22.schematic_trace.list()].filter(schematicElement=>schematicElement.schematic_sheet_id===schematicSheetId);for(let schematicElement of checkedElements){let elementBounds=getSchematicElementBounds(schematicElement);if(!elementBounds||!(elementBounds.minX<sheetContentBounds.minX-BOUNDS_EPSILON||elementBounds.maxX>sheetContentBounds.maxX+BOUNDS_EPSILON||elementBounds.minY<sheetContentBounds.minY-BOUNDS_EPSILON||elementBounds.maxY>sheetContentBounds.maxY+BOUNDS_EPSILON))continue;let schematicElementId=getSchematicElementId(schematicElement);db22.schematic_element_outside_sheet_warning.insert({warning_type:"schematic_element_outside_sheet_warning",message:`${schematicElement.type} ${schematicElementId} extends outside the drawing area of schematic sheet "${schematicSheetName}"`,schematic_sheet_id:schematicSheetId,schematic_element_type:schematicElement.type,schematic_element_id:schematicElementId})}},SchematicSheet=class extends PrimitiveComponent2{constructor(){super(...arguments);__publicField(this,"isSchematicPrimitive",!0);__publicField(this,"resolvedSchematicSheetDisplayName","Schematic Sheet")}get config(){return{componentName:"SchematicSheet",zodProps:schematicSheetProps}}doInitialSourceGroupRender(){if(this.root?.schematicDisabled)return;let{db:db22}=this.root,{_parsedProps:props}=this,explicitlyReservedSheetIndices=new Set(this.root.children.flatMap(component=>[component,...component.getDescendants()]).filter(component=>component.componentName==="SchematicSheet").map(component=>component._parsedProps.sheetIndex).filter(sheetIndex2=>sheetIndex2!==void 0)),occupiedSheetIndices=new Set([...explicitlyReservedSheetIndices,...db22.schematic_sheet.list().map(schematicSheet2=>schematicSheet2.sheet_index).filter(sheetIndex2=>sheetIndex2!==void 0)]),nextAvailableSheetIndex=0;for(;occupiedSheetIndices.has(nextAvailableSheetIndex);)nextAvailableSheetIndex+=1;let sheetIndex=props.sheetIndex??nextAvailableSheetIndex,name=props.name??props.displayName??`Sheet ${sheetIndex+1}`,displayName=props.displayName??name;this.resolvedSchematicSheetDisplayName=displayName;let resolvedSheetProperties=resolveCircuitJsonSchematicSheetProperties(props),schematicSheet=db22.schematic_sheet.insert({name,display_name:displayName,sheet_index:sheetIndex,sheet_size:resolvedSheetProperties.sheetSize,sheet_width:resolvedSheetProperties.sheetWidth,sheet_height:resolvedSheetProperties.sheetHeight,subcircuit_id:this.getSubcircuit().subcircuit_id??void 0});this.schematic_sheet_id=schematicSheet.schematic_sheet_id;let defaultSheetProperties=resolveCircuitJsonSchematicSheetProperties({sheetSize:"A4"});(resolvedSheetProperties.sheetSize!==defaultSheetProperties.sheetSize||resolvedSheetProperties.sheetWidth!==defaultSheetProperties.sheetWidth||resolvedSheetProperties.sheetHeight!==defaultSheetProperties.sheetHeight)&&db22.schematic_sheet_styling_warning.insert({warning_type:"schematic_sheet_styling_warning",styling_issue_type:"non_default_sheet_size",schematic_sheet_id:this.schematic_sheet_id,subcircuit_id:schematicSheet.subcircuit_id,message:`Schematic sheet "${displayName}" uses a non-default size (${resolvedSheetProperties.sheetWidth} \xD7 ${resolvedSheetProperties.sheetHeight} mm). Prefer the default A4 sheet size (297 \xD7 210 mm) for consistent schematic styling.`})}doInitialSchematicSheetRender(){if(this.root?.schematicDisabled||!this.schematic_sheet_id)return;let{db:db22}=this.root,resolvedSheetProperties=resolveCircuitJsonSchematicSheetProperties(this._parsedProps);if(this._parsedProps.sheetWidth!==void 0||this._parsedProps.sheetHeight!==void 0){warnIfSchematicElementsOutsideSheet({db:db22,schematicSheetId:this.schematic_sheet_id,schematicSheetName:this.resolvedSchematicSheetDisplayName,schematicSheetCenter:{x:0,y:0},sheetWidth:resolvedSheetProperties.sheetWidth,sheetHeight:resolvedSheetProperties.sheetHeight});return}let schematicElements=[...db22.schematic_component.list(),...db22.schematic_port.list(),...db22.schematic_text.list(),...db22.schematic_line.list(),...db22.schematic_rect.list(),...db22.schematic_circle.list(),...db22.schematic_arc.list(),...db22.schematic_path.list()].filter(element=>element.schematic_sheet_id===this.schematic_sheet_id),schematicSheetCenter={x:0,y:0};if(schematicElements.length>0){let bounds=getBoundsForSchematic(schematicElements);Number.isFinite(bounds.minX)&&Number.isFinite(bounds.maxX)&&Number.isFinite(bounds.minY)&&Number.isFinite(bounds.maxY)&&(schematicSheetCenter={x:(bounds.minX+bounds.maxX)/2,y:(bounds.minY+bounds.maxY)/2},db22.schematic_sheet.update(this.schematic_sheet_id,{center:schematicSheetCenter}))}warnIfSchematicElementsOutsideSheet({db:db22,schematicSheetId:this.schematic_sheet_id,schematicSheetName:this.resolvedSchematicSheetDisplayName,schematicSheetCenter,sheetWidth:resolvedSheetProperties.sheetWidth,sheetHeight:resolvedSheetProperties.sheetHeight})}},SchematicGraphic=class extends PrimitiveComponent2{constructor(){super(...arguments);__publicField(this,"isSchematicPrimitive",!0);__publicField(this,"schematic_graphic_id")}get config(){return{componentName:"SchematicGraphic",zodProps:schematicGraphicProps}}doInitialSchematicPrimitiveRender(){if(this.root?.schematicDisabled||this.getCollapsedSchematicBoxAncestor())return;let{db:db22}=this.root,{imageUrl,svgContent,width,height}=this._parsedProps;if(imageUrl!==void 0){this._queueAsyncEffect("SchematicGraphicRender",async()=>{if(this.root?.schematicDisabled)return;let resolvedImageUrl=await resolveStaticFileImport(imageUrl,this.root?.platform),sourceImage=await loadImageSource(resolvedImageUrl).catch(error2=>{if(svgContent===void 0||resolvedImageUrl.startsWith("data:"))throw error2;return null});if(sourceImage===null){let asset23={project_relative_path:imageUrl.startsWith("data:")?"inline":imageUrl,url:resolvedImageUrl,mimetype:SVG_MIMETYPE},schematicGraphic2=this.root.db.schematic_graphic.insert({asset:asset23,schematic_sheet_id:this._resolveSchematicSheetId(),svg_content:svgContent,...width===void 0?{}:{width},...height===void 0?{}:{height}});this.schematic_graphic_id=schematicGraphic2.schematic_graphic_id;return}if(sourceImage.mimetype!==SVG_MIMETYPE)throw new Error(`Unsupported imageUrl for SchematicGraphic: "${imageUrl}". Expected an SVG image.`);let asset3={project_relative_path:imageUrl.startsWith("data:")?sourceImage.projectRelativePath:imageUrl,url:sourceImage.dataUrl,mimetype:sourceImage.mimetype},fallbackSvgContent=sourceImage.dataUrl.startsWith("data:")?svgContent:sourceImage.text,schematicGraphic=this.root.db.schematic_graphic.insert({asset:asset3,schematic_sheet_id:this._resolveSchematicSheetId(),...fallbackSvgContent===void 0?{}:{svg_content:fallbackSvgContent},...width===void 0?{}:{width},...height===void 0?{}:{height}});this.schematic_graphic_id=schematicGraphic.schematic_graphic_id});return}if(svgContent!==void 0){let asset3={project_relative_path:"inline",url:`data:image/svg+xml,${encodeURIComponent(svgContent)}`,mimetype:SVG_MIMETYPE},schematicGraphic=db22.schematic_graphic.insert({asset:asset3,schematic_sheet_id:this._resolveSchematicSheetId(),...width===void 0?{}:{width},...height===void 0?{}:{height}});this.schematic_graphic_id=schematicGraphic.schematic_graphic_id}}},SchematicTable=class extends PrimitiveComponent2{constructor(){super(...arguments);__publicField(this,"isSchematicPrimitive",!0);__publicField(this,"schematic_table_id",null)}get config(){return{componentName:"SchematicTable",zodProps:schematicTableProps}}doInitialSchematicPrimitiveRender(){if(this.root?.schematicDisabled||this.getCollapsedSchematicBoxAncestor())return;let{db:db22}=this.root,{_parsedProps:props}=this,rows=this.children.filter(c22=>c22.componentName==="SchematicRow");if(rows.length===0)return;let grid22=[],maxCols=0;for(let row of rows){let cells=row.children.filter(c22=>c22.componentName==="SchematicCell");maxCols=Math.max(maxCols,cells.length)}for(let i22=0;i22<rows.length;i22++)grid22[i22]=[];for(let i22=0;i22<rows.length;i22++){let cells=rows[i22].children.filter(c22=>c22.componentName==="SchematicCell"),k22=0;for(let j22=0;j22<cells.length;j22++){for(;grid22[i22][k22];)k22++;let cell=cells[j22],colSpan=cell._parsedProps.colSpan??1,rowSpan=cell._parsedProps.rowSpan??1;for(let r22=0;r22<rowSpan;r22++)for(let c22=0;c22<colSpan;c22++)grid22[i22+r22]||(grid22[i22+r22]=[]),grid22[i22+r22][k22+c22]=cell;k22+=colSpan}}maxCols=Math.max(0,...grid22.map(r22=>r22.length));let rowHeights=rows.map((row,i22)=>row._parsedProps.height??1),colWidths=Array.from({length:maxCols},(_22,j22)=>{let maxWidth=0;for(let i22=0;i22<rows.length;i22++){let cell=grid22[i22]?.[j22];if(cell){let text=cell._parsedProps.text??cell._parsedProps.children,cellWidth=cell._parsedProps.width??(text?.length??2)*.5;cellWidth>maxWidth&&(maxWidth=cellWidth)}}return maxWidth||10}),anchorPos=this._getGlobalSchematicPositionBeforeLayout(),table=db22.schematic_table.insert({anchor_position:anchorPos,column_widths:colWidths,row_heights:rowHeights,cell_padding:props.cellPadding,border_width:props.borderWidth,anchor:props.anchor,subcircuit_id:this.getSubcircuit()?.subcircuit_id||"",schematic_component_id:this.parent?.schematic_component_id||"",schematic_sheet_id:this._resolveSchematicSheetId()});this.schematic_table_id=table.schematic_table_id;let processedCells=new Set,yOffset=0;for(let i22=0;i22<rows.length;i22++){let xOffset=0;for(let j22=0;j22<maxCols;j22++){let cell=grid22[i22]?.[j22];if(cell&&!processedCells.has(cell)){processedCells.add(cell);let cellProps=cell._parsedProps,rowSpan=cellProps.rowSpan??1,colSpan=cellProps.colSpan??1,cellWidth=0;for(let c22=0;c22<colSpan;c22++)cellWidth+=colWidths[j22+c22];let cellHeight=0;for(let r22=0;r22<rowSpan;r22++)cellHeight+=rowHeights[i22+r22];db22.schematic_table_cell.insert({schematic_table_id:this.schematic_table_id,start_row_index:i22,end_row_index:i22+rowSpan-1,start_column_index:j22,end_column_index:j22+colSpan-1,text:cellProps.text??cellProps.children,center:{x:anchorPos.x+xOffset+cellWidth/2,y:anchorPos.y-yOffset-cellHeight/2},width:cellWidth,height:cellHeight,horizontal_align:cellProps.horizontalAlign,vertical_align:cellProps.verticalAlign,font_size:cellProps.fontSize??props.fontSize,subcircuit_id:this.getSubcircuit()?.subcircuit_id||""})}colWidths[j22]&&(xOffset+=colWidths[j22])}yOffset+=rowHeights[i22]}}},SchematicRow=class extends PrimitiveComponent2{constructor(){super(...arguments);__publicField(this,"isSchematicPrimitive",!0)}get config(){return{componentName:"SchematicRow",zodProps:schematicRowProps}}},SchematicCell=class extends PrimitiveComponent2{constructor(){super(...arguments);__publicField(this,"isSchematicPrimitive",!0);__publicField(this,"canHaveTextChildren",!0)}get config(){return{componentName:"SchematicCell",zodProps:schematicCellProps}}},AnalogSimulation=class extends PrimitiveComponent2{constructor(){super(...arguments);__publicField(this,"simulation_experiment_id",null)}get config(){return{componentName:"AnalogSimulation",zodProps:analogSimulationProps}}getSpiceEngineName(){return this._parsedProps.spiceEngine}usesIndependentGraphAxes(){return this._parsedProps.graphIndependentAxes===!0}doInitialSimulationRender(){let{db:db22}=this.root,{duration,name,startTime,timePerStep,spiceOptions:spiceOptions3}=this._parsedProps,durationMs=duration||10,timePerStepMs=timePerStep||.01,simulationExperiment=db22.simulation_experiment.insert({name:name??"spice_transient_analysis",experiment_type:"spice_transient_analysis",end_time_ms:durationMs,start_time_ms:startTime,time_per_step:timePerStepMs,spice_options:spiceOptions3});this.simulation_experiment_id=simulationExperiment.simulation_experiment_id}},AnalogAnalysisSimulation=class extends PrimitiveComponent2{constructor(){super(...arguments);__publicField(this,"simulation_experiment_id",null)}getSpiceEngineName(){return typeof this.props.spiceEngine=="string"?this.props.spiceEngine:void 0}usesIndependentGraphAxes(){return this.props.graphIndependentAxes===!0}getOrCreateSimulationExperiment(){if(this.simulation_experiment_id)return this.root?.db.simulation_experiment.get(this.simulation_experiment_id)??null;if(this.children.filter(child=>child.componentName==="AnalogSweepParameter").length>1)return this.renderError("An analog simulation can contain at most one sweep parameter."),null;let simulationExperiment=this.insertSimulationExperiment();return this.simulation_experiment_id=simulationExperiment?.simulation_experiment_id??null,simulationExperiment}doInitialSimulationRender(){this.getOrCreateSimulationExperiment()}},AnalogTransientSimulation=class extends AnalogAnalysisSimulation{get config(){return{componentName:"AnalogTransientSimulation",zodProps:analogTransientSimulationProps}}insertSimulationExperiment(){let{db:db22}=this.root,{duration,name,startTime,timePerStep,spiceOptions:spiceOptions3}=this._parsedProps;return db22.simulation_experiment.insert({name:name??"spice_transient_analysis",experiment_type:"spice_transient_analysis",end_time_ms:duration,start_time_ms:startTime,time_per_step:timePerStep,spice_options:spiceOptions3})}},AnalogDcOperatingPointSimulation=class extends AnalogAnalysisSimulation{get config(){return{componentName:"AnalogDcOperatingPointSimulation",zodProps:analogDcOperatingPointSimulationProps}}insertSimulationExperiment(){let{name,spiceOptions:spiceOptions3}=this._parsedProps;return this.root.db.simulation_experiment.insert({name:name??"spice_dc_operating_point",experiment_type:"spice_dc_operating_point",spice_options:spiceOptions3})}},AnalogDcSweepSimulation=class extends AnalogAnalysisSimulation{get config(){return{componentName:"AnalogDcSweepSimulation",zodProps:analogDcSweepSimulationProps}}insertSimulationExperiment(){let{name,spiceOptions:spiceOptions3,sweepSource,sweepStart,sweepStop,sweepStep}=this._parsedProps,sweepSourceComponent=(this.getGroup()??this.getSubcircuit())?.selectOne(sweepSource),dcSweepSourceFields;if(sweepSourceComponent instanceof VoltageSource2){sweepSourceComponent.runRenderPhase("SimulationRender");let simulationVoltageSourceId=sweepSourceComponent.simulation_voltage_source_id;if(!simulationVoltageSourceId)return this.renderError(`DC sweep source "${sweepSource}" must resolve to one voltage or current source.`),null;dcSweepSourceFields={dc_sweep_voltage_source_id:simulationVoltageSourceId,dc_sweep_unit:"V"}}else if(sweepSourceComponent instanceof CurrentSource2){sweepSourceComponent.runRenderPhase("SimulationRender");let simulationCurrentSourceId=sweepSourceComponent.simulation_current_source_id;if(!simulationCurrentSourceId)return this.renderError(`DC sweep source "${sweepSource}" must resolve to one voltage or current source.`),null;dcSweepSourceFields={dc_sweep_current_source_id:simulationCurrentSourceId,dc_sweep_unit:"A"}}else return this.renderError(`DC sweep source "${sweepSource}" must resolve to one voltage or current source.`),null;return this.root.db.simulation_experiment.insert({name:name??"spice_dc_sweep",experiment_type:"spice_dc_sweep",spice_options:spiceOptions3,...dcSweepSourceFields,dc_sweep_start:sweepStart,dc_sweep_stop:sweepStop,dc_sweep_step:sweepStep})}},AnalogAcSweepSimulation=class extends AnalogAnalysisSimulation{get config(){return{componentName:"AnalogAcSweepSimulation",zodProps:analogAcSweepSimulationProps}}insertSimulationExperiment(){let{name,spiceOptions:spiceOptions3,sweepType,samplesPerInterval,sampleCount,startFrequency,stopFrequency}=this._parsedProps;return this.root.db.simulation_experiment.insert({name:name??"spice_ac_analysis",experiment_type:"spice_ac_analysis",spice_options:spiceOptions3,ac_sweep_type:sweepType,ac_samples_per_interval:samplesPerInterval,ac_sample_count:sampleCount,ac_start_frequency_hz:startFrequency,ac_stop_frequency_hz:stopFrequency})}},parameterUnits={resistance:"\u03A9",capacitance:"F",inductance:"H",voltage:"V",current:"A"},isParameterSweepCoordinateInRange=({parameterSweepCoordinate,stop,step})=>{let tolerance=Math.abs(step)*1e-9;return step>0?parameterSweepCoordinate<=stop+tolerance:parameterSweepCoordinate>=stop-tolerance},getGeneratedParameterSweepCoordinates=({start,stop,step})=>{let parameterSweepCoordinates=[];for(let parameterSweepCoordinate=start;isParameterSweepCoordinateInRange({parameterSweepCoordinate,stop,step});parameterSweepCoordinate=start+parameterSweepCoordinates.length*step)if(parameterSweepCoordinates.push(parameterSweepCoordinate),parameterSweepCoordinates.length>1e6)throw new Error("Parameter sweep exceeds 1,000,000 points");return parameterSweepCoordinates},getParameterSweepTargetSelector=props=>props.parameterType==="resistance"?props.resistorRef:props.parameterType==="capacitance"?props.capacitorRef:props.parameterType==="inductance"?props.inductorRef:props.parameterType==="voltage"?props.net:props.currentSourceRef,AnalogSweepParameter_doInitialSimulationRender=analogSweepParameter=>{if(!(analogSweepParameter.parent instanceof AnalogAnalysisSimulation)){analogSweepParameter.renderError("analog.sweepparameter must be nested directly in an analog simulation.");return}let simulationExperiment=analogSweepParameter.parent.getOrCreateSimulationExperiment();if(!simulationExperiment)return;let props=analogSweepParameter._parsedProps,parameterSweepCoordinates=props.values??getGeneratedParameterSweepCoordinates({start:props.start,stop:props.stop,step:props.step}),simulationScope=analogSweepParameter.parent.getGroup()??analogSweepParameter.parent.getSubcircuit(),targetSelector=getParameterSweepTargetSelector(props),parameterUnit=parameterUnits[props.parameterType],simulationParameterSweepTable=analogSweepParameter.root.db.simulation_parameter_sweep,simulationParameterSweepFields={simulation_experiment_id:simulationExperiment.simulation_experiment_id,name:props.name,parameter_type:props.parameterType,parameter_values:parameterSweepCoordinates,parameter_unit:parameterUnit},simulationParameterSweepId;if(props.parameterType==="voltage"){let sweepNet=simulationScope?.selectOne(targetSelector,{type:"net"});if(!sweepNet?.source_net_id){analogSweepParameter.renderError(`Voltage sweep net "${targetSelector}" could not be resolved.`);return}simulationParameterSweepId=simulationParameterSweepTable.insert({...simulationParameterSweepFields,parameter_type:"voltage",source_net_id:sweepNet.source_net_id}).simulation_parameter_sweep_id}else{let sourceComponentId=simulationScope?.selectOne(targetSelector)?.source_component_id;if(!sourceComponentId){analogSweepParameter.renderError(`Parameter sweep target "${targetSelector}" could not be resolved.`);return}props.parameterType==="resistance"?simulationParameterSweepId=simulationParameterSweepTable.insert({...simulationParameterSweepFields,parameter_type:"resistance",resistor_source_component_id:sourceComponentId}).simulation_parameter_sweep_id:props.parameterType==="capacitance"?simulationParameterSweepId=simulationParameterSweepTable.insert({...simulationParameterSweepFields,parameter_type:"capacitance",capacitor_source_component_id:sourceComponentId}).simulation_parameter_sweep_id:props.parameterType==="inductance"?simulationParameterSweepId=simulationParameterSweepTable.insert({...simulationParameterSweepFields,parameter_type:"inductance",inductor_source_component_id:sourceComponentId}).simulation_parameter_sweep_id:simulationParameterSweepId=simulationParameterSweepTable.insert({...simulationParameterSweepFields,parameter_type:"current",current_source_component_id:sourceComponentId}).simulation_parameter_sweep_id}analogSweepParameter.simulation_parameter_sweep_id=simulationParameterSweepId},AnalogSweepParameter=class extends PrimitiveComponent2{constructor(){super(...arguments);__publicField(this,"simulation_parameter_sweep_id",null)}get config(){return{componentName:"AnalogSweepParameter",zodProps:analogSweepParameterProps}}doInitialSimulationRender(){AnalogSweepParameter_doInitialSimulationRender(this)}},PcbReturnCurrentSimulation=class extends PrimitiveComponent2{constructor(){super(...arguments);__publicField(this,"simulation_experiment_id",null)}get config(){return{componentName:"PcbReturnCurrentSimulation",zodProps:pcbReturnCurrentSimulationProps}}doInitialSimulationRender(){if(this.root?.pcbDisabled)return;this.parent?.componentName==="PcbReturnCurrentSimulation"&&this.renderError("A PCB return-current simulation cannot contain another simulation."),this.children.some(child=>child.componentName!=="PcbReturnCurrentExcitation")&&this.renderError("A PCB return-current simulation can contain only return-current excitations.");let experiment=this.root.db.simulation_experiment.insert({name:this._parsedProps.name??"PCB return current",experiment_type:"pcb_return_current"});this.simulation_experiment_id=experiment.simulation_experiment_id}updateSimulationRender(){this.simulation_experiment_id&&this.root.db.simulation_experiment.update(this.simulation_experiment_id,{name:this._parsedProps.name??"PCB return current"})}removeSimulationRender(){this.simulation_experiment_id&&(this.root.db.simulation_experiment.delete(this.simulation_experiment_id),this.simulation_experiment_id=null)}},positionToleranceMm=1e-6;function PcbReturnCurrentExcitation_doInitialPcbSimulationRender(excitation){if(excitation.root?.pcbDisabled)return;let{db:db22}=excitation.root,props=excitation._parsedProps,simulation2=excitation.parent;if(simulation2?.componentName!=="PcbReturnCurrentSimulation"){excitation.renderError("A PCB return-current excitation must be directly inside a PCB return-current simulation.");return}if(!simulation2.simulation_experiment_id){excitation.renderError("The PCB return-current simulation has not been declared.");return}let subcircuit=excitation.getSubcircuit(),resolvePcbPort=(selector2,role)=>{let ports=subcircuit.selectAll(selector2).filter(component=>component.componentName==="Port");ports.length!==1&&excitation.renderError(`${role} selector "${selector2}" must identify exactly one physical PCB port.`);let port=ports[0],pcbPort=port?.pcb_port_id?db22.pcb_port.get(port.pcb_port_id):null,hasPhysicalPad=pcbPort&&(db22.pcb_smtpad.list({pcb_port_id:pcbPort.pcb_port_id}).length>0||db22.pcb_plated_hole.list({pcb_port_id:pcbPort.pcb_port_id}).length>0);return(!pcbPort||!hasPhysicalPad)&&excitation.renderError(`${role} selector "${selector2}" needs a physical PCB pad or plated-hole port.`),pcbPort},signalSource=resolvePcbPort(props.source,"Signal source"),signalLoad=resolvePcbPort(props.load,"Signal load"),returnSource=resolvePcbPort(props.returnSource,"Return source (load-side ground)"),returnSink=resolvePcbPort(props.returnSink,"Return sink (driver-side ground)");new Set([signalSource.pcb_port_id,signalLoad.pcb_port_id,returnSource.pcb_port_id,returnSink.pcb_port_id]).size!==4&&excitation.renderError("Signal source, signal load, return source and return sink must be four distinct physical PCB ports.");let groundNets=subcircuit.selectAll(props.ground.startsWith("net.")?"net":props.ground).filter(component=>component.componentName==="Net"&&(!props.ground.startsWith("net.")||component.getPortSelector()===props.ground));(groundNets.length!==1||!groundNets[0].source_net_id)&&excitation.renderError(`Ground selector "${props.ground}" must identify exactly one source net.`);let groundNet=db22.source_net.get(groundNets[0].source_net_id),groundConnectivityKey=groundNet.subcircuit_connectivity_map_key;for(let[pcbPort,selector2]of[[signalSource,props.source],[signalLoad,props.load]])groundConnectivityKey&&db22.source_port.get(pcbPort.source_port_id)?.subcircuit_connectivity_map_key===groundConnectivityKey&&excitation.renderError(`Signal terminal "${selector2}" is electrically connected to ground net "${groundNet.name}".`);for(let[pcbPort,selector2]of[[returnSource,props.returnSource],[returnSink,props.returnSink]]){let sourcePort=db22.source_port.get(pcbPort.source_port_id);(!groundConnectivityKey||sourcePort?.subcircuit_connectivity_map_key!==groundConnectivityKey)&&excitation.renderError(`Return contact "${selector2}" is not electrically connected to ground net "${groundNet.name}".`)}let contact=(pcbPort,selector2,requestedLayer,role)=>{let layers=[...new Set(pcbPort.layers)];!requestedLayer&&layers.length!==1&&excitation.renderError(`${role} "${selector2}" spans multiple layers; specify ${role==="Return source"?"returnSourceLayer":"returnSinkLayer"}.`);let layer=requestedLayer??layers[0];return layers.includes(layer)||excitation.renderError(`${role} "${selector2}" has no physical port on layer "${layer}".`),{contact_type:"pcb_port",pcb_port_id:pcbPort.pcb_port_id,x:pcbPort.x,y:pcbPort.y,layer}},returnSourceContact=contact(returnSource,props.returnSource,props.returnSourceLayer,"Return source"),returnSinkContact=contact(returnSink,props.returnSink,props.returnSinkLayer,"Return sink");for(let[signalPort,referenceContact]of[[signalSource,returnSinkContact],[signalLoad,returnSourceContact]])Math.hypot(signalPort.x-referenceContact.x,signalPort.y-referenceContact.y)<=positionToleranceMm&&signalPort.layers.includes(referenceContact.layer)&&excitation.renderError("A signal terminal and its ground reference must occupy different physical PCB locations on the same layer.");let selectedSourceTraceId;if(props.trace){let traces2=subcircuit.selectAll(props.trace).filter(component=>component.componentName==="Trace");(traces2.length!==1||!traces2[0].source_trace_id)&&excitation.renderError(`Trace selector "${props.trace}" must identify exactly one routed source trace.`),selectedSourceTraceId=traces2[0].source_trace_id}let endpointMatches=(endpoint,pcbPort,end)=>endpoint?.route_type==="wire"&&Math.hypot(endpoint.x-pcbPort.x,endpoint.y-pcbPort.y)<=positionToleranceMm&&pcbPort.layers.includes(endpoint.layer)&&(!endpoint[`${end}_pcb_port_id`]||endpoint[`${end}_pcb_port_id`]===pcbPort.pcb_port_id),traces=db22.pcb_trace.list().filter(pcbTrace=>{if(pcbTrace.subcircuit_id!==subcircuit.subcircuit_id||selectedSourceTraceId&&pcbTrace.source_trace_id!==selectedSourceTraceId)return!1;let sourceTrace=pcbTrace.source_trace_id?db22.source_trace.get(pcbTrace.source_trace_id):null;if(!sourceTrace||sourceTrace.connected_source_port_ids.length!==2||!sourceTrace.connected_source_port_ids.includes(signalSource.source_port_id)||!sourceTrace.connected_source_port_ids.includes(signalLoad.source_port_id))return!1;let first=pcbTrace.route[0],last=pcbTrace.route.at(-1);return endpointMatches(first,signalSource,"start")&&endpointMatches(last,signalLoad,"end")||endpointMatches(first,signalLoad,"start")&&endpointMatches(last,signalSource,"end")});traces.length!==1&&excitation.renderError(`The connection from "${props.source}" to "${props.load}" must have exactly one complete routed PCB trace${props.trace?` selected by "${props.trace}"`:"; use trace to disambiguate multiple routes"}. Split or branched routes are not supported.`);let previousExcitations=db22.simulation_return_current_excitation.list({simulation_experiment_id:simulation2.simulation_experiment_id});previousExcitations.some(previous=>previous.pcb_trace_id===traces[0].pcb_trace_id)&&excitation.renderError("A PCB return-current simulation can excite each signal trace only once. Use separate experiments to compare different currents or directions."),previousExcitations.some(previous=>previous.ground_source_net_id!==groundNet.source_net_id)&&excitation.renderError("All excitations in a PCB return-current simulation must use the same ground net. Use separate experiments for different ground nets.");let inserted=db22.simulation_return_current_excitation.insert({simulation_experiment_id:simulation2.simulation_experiment_id,pcb_trace_id:traces[0].pcb_trace_id,ground_source_net_id:groundNet.source_net_id,current:props.current,return_source:returnSourceContact,return_sink:returnSinkContact,source_port:{signal_pcb_port_id:signalSource.pcb_port_id,reference_pcb_port_id:returnSink.pcb_port_id,reference_layer:returnSinkContact.layer,resistance:props.sourceImpedance},load_port:{signal_pcb_port_id:signalLoad.pcb_port_id,reference_pcb_port_id:returnSource.pcb_port_id,reference_layer:returnSourceContact.layer,resistance:props.loadImpedance}});excitation.simulation_return_current_excitation_id=inserted.simulation_return_current_excitation_id}var PcbReturnCurrentExcitation=class extends PrimitiveComponent2{constructor(){super(...arguments);__publicField(this,"simulation_return_current_excitation_id",null)}get config(){return{componentName:"PcbReturnCurrentExcitation",zodProps:pcbReturnCurrentExcitationProps}}doInitialPcbSimulationRender(){PcbReturnCurrentExcitation_doInitialPcbSimulationRender(this)}updatePcbSimulationRender(){this.removePcbSimulationRender(),this.doInitialPcbSimulationRender()}removePcbSimulationRender(){this.simulation_return_current_excitation_id&&(this.root.db.simulation_return_current_excitation.delete(this.simulation_return_current_excitation_id),this.simulation_return_current_excitation_id=null)}};function getLabelBounds3(probePosition,labelText,alignment,labelOffset=.3){let labelWidth=Math.max(labelText.length*.1,.3),labelHeightWithPadding=.25+.2,anchorX=probePosition.x,anchorY=probePosition.y,offsetMultiplier=labelOffset+labelWidth/2;alignment.includes("top")?anchorY+=offsetMultiplier:alignment.includes("bottom")&&(anchorY-=offsetMultiplier),alignment.includes("right")?anchorX+=offsetMultiplier:alignment.includes("left")&&(anchorX-=offsetMultiplier);let minX,maxX,minY,maxY;return alignment.includes("left")?(minX=anchorX,maxX=anchorX+labelWidth):alignment.includes("right")?(minX=anchorX-labelWidth,maxX=anchorX):(minX=anchorX-labelWidth/2,maxX=anchorX+labelWidth/2),alignment.includes("top")?(minY=anchorY-labelHeightWithPadding,maxY=anchorY):alignment.includes("bottom")?(minY=anchorY,maxY=anchorY+labelHeightWithPadding):(minY=anchorY-labelHeightWithPadding/2,maxY=anchorY+labelHeightWithPadding/2),{minX,maxX,minY,maxY}}function getElementBounds(elm){let cx22,cy22,w22,h22;if(elm.type==="schematic_component")cx22=elm.center?.x,cy22=elm.center?.y,w22=elm.size?.width,h22=elm.size?.height;else if(elm.type==="schematic_text")cx22=elm.position?.x,cy22=elm.position?.y,w22=(elm.text?.length??0)*.1,h22=.2;else return null;return typeof cx22=="number"&&typeof cy22=="number"&&typeof w22=="number"&&typeof h22=="number"?{minX:cx22-w22/2,maxX:cx22+w22/2,minY:cy22-h22/2,maxY:cy22+h22/2}:null}function getOverlapArea(a22,b22){if(!doBoundsOverlap(a22,b22))return 0;let overlapWidth=Math.min(a22.maxX,b22.maxX)-Math.max(a22.minX,b22.minX),overlapHeight=Math.min(a22.maxY,b22.maxY)-Math.max(a22.minY,b22.minY);return overlapWidth*overlapHeight}function selectBestLabelAlignment({probePosition,labelText,schematicElements,defaultAlignment="top_right"}){let orderedAlignments=[defaultAlignment,...["top_right","top_left","bottom_right","bottom_left","top_center","bottom_center","center_right","center_left"].filter(a22=>a22!==defaultAlignment)],bestAlignment=defaultAlignment,minOverlapArea=1/0;for(let alignment of orderedAlignments){let labelBounds=getLabelBounds3(probePosition,labelText,alignment),totalOverlapArea=0;for(let element of schematicElements){let elementBounds=getElementBounds(element);elementBounds&&(totalOverlapArea+=getOverlapArea(labelBounds,elementBounds))}if(totalOverlapArea===0)return alignment;totalOverlapArea<minOverlapArea&&(minOverlapArea=totalOverlapArea,bestAlignment=alignment)}return bestAlignment}var VoltageProbe=class extends PrimitiveComponent2{constructor(){super(...arguments);__publicField(this,"simulation_voltage_probe_id",null);__publicField(this,"schematic_voltage_probe_id",null);__publicField(this,"finalProbeName",null);__publicField(this,"color",null)}get config(){return{componentName:"VoltageProbe",zodProps:voltageProbeProps}}doInitialSimulationRender(){let{db:db22}=this.root,{connectsTo,name,referenceTo,color:color3,graphDisplayName,graphCenter,graphVerticalOffset,graphVoltagePerDiv}=this._parsedProps,subcircuit=this.getSubcircuit();if(!subcircuit){this.renderError("VoltageProbe must be inside a subcircuit");return}let targets=Array.isArray(connectsTo)?connectsTo:[connectsTo];if(targets.length!==1){this.renderError("VoltageProbe must connect to exactly one port or net");return}let targetSelector=targets[0],port=subcircuit.selectOne(targetSelector,{type:"port"}),net=port?null:subcircuit.selectOne(targetSelector,{type:"net"});if(net&&net.componentName!=="Net"){this.renderError(`VoltageProbe connection target "${targetSelector}" resolved to a non-net component "${net.componentName}".`);return}if(!port&&!net){this.renderError(`VoltageProbe could not find connection target "${targetSelector}"`);return}let connectedId=port?.source_port_id??net?.source_net_id;if(!connectedId){this.renderError("Could not identify connected source for VoltageProbe");return}let referencePort=null,referenceNet=null;if(referenceTo){let referenceTargets=Array.isArray(referenceTo)?referenceTo:[referenceTo];if(referenceTargets.length!==1){this.renderError("VoltageProbe must reference exactly one port or net");return}let referenceSelector=referenceTargets[0];if(referencePort=subcircuit.selectOne(referenceSelector,{type:"port"}),referenceNet=referencePort?null:subcircuit.selectOne(referenceSelector,{type:"net"}),referenceNet&&referenceNet.componentName!=="Net"){this.renderError(`VoltageProbe reference target "${referenceSelector}" resolved to a non-net component "${referenceNet.componentName}".`);return}if(!referencePort&&!referenceNet){this.renderError(`VoltageProbe could not find reference target "${referenceSelector}"`);return}}this.color=color3??getSimulationColorForId(connectedId);let finalName=name;finalName||(finalName=targets[0].split(" > ").map(s22=>s22.replace(/^\./,"")).join(".")),this.finalProbeName=finalName??null;let{simulation_voltage_probe_id}=db22.simulation_voltage_probe.insert({name:finalName,signal_input_source_port_id:port?.source_port_id??void 0,signal_input_source_net_id:net?.source_net_id??void 0,reference_input_source_port_id:referencePort?.source_port_id??void 0,reference_input_source_net_id:referenceNet?.source_net_id??void 0,subcircuit_id:subcircuit.subcircuit_id||void 0,color:this.color});if(this.simulation_voltage_probe_id=simulation_voltage_probe_id,graphDisplayName!==void 0||graphCenter!==void 0||graphVerticalOffset!==void 0||graphVoltagePerDiv!==void 0){let graphVoltagePerDivValue=parseSimulationGraphValue(graphVoltagePerDiv),graphVerticalOffsetValue=parseSimulationGraphValue(graphVerticalOffset);db22.simulation_oscilloscope_trace.insert({simulation_voltage_probe_id,display_name:graphDisplayName,color:color3??void 0,display_center_value:graphCenter,volts_per_div:graphVoltagePerDivValue,display_center_offset_divs:graphVerticalOffsetValue!==void 0&&graphVoltagePerDivValue!==void 0&&graphVoltagePerDivValue!==0?graphVerticalOffsetValue/graphVoltagePerDivValue:void 0})}}doInitialSchematicReplaceNetLabelsWithSymbols(){if(this.root?.schematicDisabled)return;let{db:db22}=this.root,{connectsTo,name}=this._parsedProps,subcircuit=this.getSubcircuit();if(!subcircuit)return;let targets=Array.isArray(connectsTo)?connectsTo:[connectsTo];if(targets.length!==1)return;let targetSelector=targets[0],port=subcircuit.selectOne(targetSelector,{type:"port"});if(!port||!port.schematic_port_id)return;let position4=port._getGlobalSchematicPositionAfterLayout(),targetTraceId=null;for(let trace of db22.schematic_trace.list()){for(let edge of trace.edges)if(Math.abs(edge.from.x-position4.x)<1e-6&&Math.abs(edge.from.y-position4.y)<1e-6||Math.abs(edge.to.x-position4.x)<1e-6&&Math.abs(edge.to.y-position4.y)<1e-6){targetTraceId=trace.schematic_trace_id;break}if(targetTraceId)break}if(!targetTraceId)return;let probeName=this.finalProbeName,labelAlignment=selectBestLabelAlignment({probePosition:position4,labelText:probeName,schematicElements:[...db22.schematic_component.list(),...db22.schematic_text.list()],defaultAlignment:"top_right"}),schematic_voltage_probe3=db22.schematic_voltage_probe.insert({name:probeName,position:position4,schematic_trace_id:targetTraceId,subcircuit_id:subcircuit.subcircuit_id||void 0,color:this.color??void 0,label_alignment:labelAlignment});this.schematic_voltage_probe_id=schematic_voltage_probe3.schematic_voltage_probe_id}},SpiceModel=class extends PrimitiveComponent2{get config(){return{componentName:"SpiceModel",zodProps:spicemodelProps}}doInitialSimulationRender(){if(this.getInheritedProperty("analogSimulationDisabled"))return;let parent=this.parent;if(!parent)return;let parentSourceComponentId=parent.source_component_id;if(!parentSourceComponentId){this._insertSpiceModelError("spicemodel must be attached to a source component.",this._parsedProps);return}let{source,spicePinMapping}=this._parsedProps,subckt=parseSpiceNetlist(source).subckts[0]??null,spicePinNames=subckt?.pins.map(pin=>pin.name);if(!subckt||!spicePinNames||spicePinNames.length===0){this._insertSpiceModelError("spicemodel source must contain a .subckt declaration with a model name and pins.",source);return}let mapping=spicePinMapping??{};for(let spicePinName of Object.keys(mapping))if(!spicePinNames.includes(spicePinName)){this._insertSpiceModelError(`spicePinMapping references SPICE pin "${spicePinName}", but it is not present in .subckt ${subckt.name}.`,mapping);return}let spicePinToSourcePortMap={},seenSourcePortIds=new Set;for(let spicePinName of spicePinNames){let componentPinName=mapping[spicePinName]??spicePinName,matchingPorts=parent.selectAll("port").filter(port=>port instanceof Port&&port.isMatchingAnyOf([componentPinName]));if(matchingPorts.length!==1||!matchingPorts[0].source_port_id){this._insertSpiceModelError(`Could not resolve SPICE pin "${spicePinName}" to exactly one component port using "${componentPinName}".`,mapping);return}let sourcePortId=matchingPorts[0].source_port_id;if(seenSourcePortIds.has(sourcePortId)){this._insertSpiceModelError(`spicePinMapping maps more than one SPICE pin to component port "${componentPinName}".`,mapping);return}seenSourcePortIds.add(sourcePortId),spicePinToSourcePortMap[spicePinName]=sourcePortId}this.root.db.simulation_spice_subcircuit.insert({source_component_id:parentSourceComponentId,spice_pin_to_source_port_map:spicePinToSourcePortMap,subcircuit_source:source})}_insertSpiceModelError(message,propertyValue){this.root.db.source_invalid_component_property_error.insert({source_component_id:this.parent?.source_component_id||"",property_name:"spiceModel",property_value:propertyValue,message,error_type:"source_invalid_component_property_error"})}};function getPcbFlexBoardTransform(primitive){let boardId=primitive._getBoard()?.pcb_board_id,board=boardId?primitive.root.db.pcb_board.get(boardId):null;if(!board)throw new Error(`${primitive.componentName} must be inside a board`);let transform7=compose2(translate2(-board.center.x,-board.center.y),primitive._computePcbGlobalTransformBeforeLayout());return{board,transform:transform7}}var PcbBend=class extends PrimitiveComponent2{constructor(){super(...arguments);__publicField(this,"pcb_bend_id",null);__publicField(this,"tearReliefCutoutIds",[])}get config(){return{componentName:"PcbBend",zodProps:pcbBendProps}}doInitialPcbFlexRender(){if(this.root?.pcbDisabled)return;let{db:db22}=this.root,props=this._parsedProps,{board,transform:transform7}=getPcbFlexBoardTransform(this),bend=db22.pcb_bend.insert({pcb_board_id:board.pcb_board_id,pcb_group_id:this.getGroup()?.pcb_group_id??void 0,subcircuit_id:this.getSubcircuit().subcircuit_id??void 0,name:props.name,start:applyToPoint2(transform7,{x:props.x1,y:props.y1}),end:applyToPoint2(transform7,{x:props.x2,y:props.y2}),bend_angle:props.bendAngle,bend_radius:props.bendRadius,bend_side:props.bendSide});if(this.pcb_bend_id=bend.pcb_bend_id,props.tearReliefRadius!==void 0)for(let endpoint of[bend.start,bend.end]){let cutout=db22.pcb_cutout.insert({shape:"circle",center:{x:endpoint.x+board.center.x,y:endpoint.y+board.center.y},radius:props.tearReliefRadius,pcb_board_id:board.pcb_board_id,pcb_group_id:bend.pcb_group_id,subcircuit_id:bend.subcircuit_id});this.tearReliefCutoutIds.push(cutout.pcb_cutout_id)}}removePcbFlexRender(){for(let cutoutId of this.tearReliefCutoutIds)this.root.db.pcb_cutout.delete(cutoutId);this.tearReliefCutoutIds=[],this.pcb_bend_id&&(this.root.db.pcb_bend.delete(this.pcb_bend_id),this.pcb_bend_id=null)}},PcbStiffener=class extends PrimitiveComponent2{constructor(){super(...arguments);__publicField(this,"pcb_stiffener_id",null)}get config(){return{componentName:"PcbStiffener",zodProps:pcbStiffenerProps}}doInitialPcbFlexRender(){if(this.root?.pcbDisabled)return;let{db:db22}=this.root,props=this._parsedProps,{board,transform:transform7}=getPcbFlexBoardTransform(this),base={pcb_board_id:board.pcb_board_id,pcb_group_id:this.getGroup()?.pcb_group_id??void 0,subcircuit_id:this.getSubcircuit().subcircuit_id??void 0,name:props.name,layer:props.layer,material:props.material,thickness:props.thickness,adhesive_thickness:props.adhesiveThickness},geometry=props.shape==="rect"?{shape:"rect",center:applyToPoint2(transform7,{x:0,y:0}),rotation:decomposeTSR2(transform7).rotation.angle*180/Math.PI,width:props.width,height:props.height}:{shape:"polygon",outline:props.outline.map(point62=>applyToPoint2(transform7,point62))};this.pcb_stiffener_id=db22.pcb_stiffener.insert({...base,...geometry}).pcb_stiffener_id}doRemovePcbFlexRender(){this.pcb_stiffener_id&&(this.root.db.pcb_stiffener.delete(this.pcb_stiffener_id),this.pcb_stiffener_id=null)}},AssemblyPrintedPart=class extends PrimitiveComponent2{constructor(){super(...arguments);__publicField(this,"isAssemblyDeviceContainer",!0);__publicField(this,"compiledJscadInput");__publicField(this,"compiledJscad")}get config(){return{componentName:"AssemblyPrintedPart",zodProps:assemblyPrintedPartProps}}get printedPartPlan(){if(this._parsedProps.jscad){if(!this.compiledJscad||this.compiledJscadInput!==this._parsedProps.jscad){let{geometry,referencePlanes}=(0,import_jscad_planner3.resolveReferencePlanes)(renderToJscadPlan(this._parsedProps.jscad));if(!geometry)throw new Error(`assembly.printedpart "${this.name}" needs solid geometry in addition to references`);this.compiledJscad={geometry,referencePlanes},this.compiledJscadInput=this._parsedProps.jscad}return this.compiledJscad}}doInitialReactSubtreesRender(){(0,import_react13.isValidElement)(this.props.cadModel)&&this.add(createInstanceFromReactElement(this.props.cadModel))}doInitialSourceRender(){this.printedPartPlan,getPartReferenceSurfaces(this),this.source_component_id=this.root.db.source_component.insert({ftype:"printedpart",name:this.name,color:this._parsedProps.color,material:this._parsedProps.material}).source_component_id}doInitialCadModelRender(){if(!this.root||this.root.pcbDisabled||!this.source_component_id)return;renderPartReferenceSurfaces(this);let plan=this.printedPartPlan;if(!plan){let model27=resolveAssemblyModel(this._parsedProps)??this._parsedProps.cadModel,placement=resolveAssemblyPlacement(this);if(!model27||typeof model27=="object"&&"type"in model27)return;if(typeof model27=="object"&&"jscad"in model27){let{geometry}=(0,import_jscad_planner3.resolveReferencePlanes)(model27.jscad);if(!geometry)throw new Error(`assembly.printedpart "${this.name}" needs solid geometry in addition to references`);model27={...model27,jscad:geometry}}this.cad_component_id=renderAssemblyCadModel(this,model27,placement);return}let{transforms,subcircuitId}=resolvePrintedPartMounts(this),transform7=transforms.get(this),angles=getAssemblyEulerAngles(transform7);this.cad_component_id=renderAssemblyCadModel(this,{jscad:{type:"rotate",angles,shape:plan.geometry}},{position:{x:transform7[12],y:transform7[13],z:transform7[14]},pcbRotation:0,layer:"top",subcircuit_id:subcircuitId})}},bulletDiameterSchema=external_exports.union([external_exports.literal(2),external_exports.literal(3),external_exports.literal(3.5),external_exports.literal(4),external_exports.literal(5),external_exports.literal(5.5),external_exports.literal(6),external_exports.literal(8)]),bulletGenderSchema=external_exports.enum(["male","female"]);function getBulletConnector({diameter,gender,pinCount=1,pitch=diameter+2}){let contactDepth=diameter*2,bodyDiameter=diameter+(gender==="female"?1:.6);return{kind:gender==="male"?"bullet_male":"bullet_female",diameter,contactDepth,pinCount,pitch,bodyWidth:bodyDiameter+(pinCount-1)*pitch,bodyHeight:bodyDiameter,bodyDepth:contactDepth+diameter*1.5}}var cableStandardSchema=external_exports.enum(["usb_c","jst_sh","jst_ph","us_mains","bullet","adaptercable"]),dimension=external_exports.number().finite().positive(),color=external_exports.string().regex(/^#[0-9a-fA-F]{6}$/),body={bodyWidth:dimension,bodyHeight:dimension,bodyDepth:dimension},cableConnectorSchema=external_exports.discriminatedUnion("kind",[external_exports.object({kind:external_exports.literal("bullet_male"),...body,diameter:bulletDiameterSchema,pinCount:external_exports.number().int().min(1).max(16).default(1),pitch:dimension,contactDepth:dimension}).strict(),external_exports.object({kind:external_exports.literal("bullet_female"),...body,diameter:bulletDiameterSchema,pinCount:external_exports.number().int().min(1).max(16).default(1),pitch:dimension,contactDepth:dimension}).strict(),external_exports.object({kind:external_exports.literal("usb_c_plug"),...body,shellWidth:dimension,shellHeight:dimension,shellDepth:dimension}).strict(),external_exports.object({kind:external_exports.literal("jst_sh_housing"),...body,pinCount:external_exports.number().int().min(2).max(15),pitch:external_exports.literal(1)}).strict(),external_exports.object({kind:external_exports.literal("jst_ph_housing"),...body,pinCount:external_exports.number().int().min(2).max(16),pitch:external_exports.literal(2)}).strict(),external_exports.object({kind:external_exports.literal("nema_5_15p"),...body}).strict(),external_exports.object({kind:external_exports.literal("iec_c13"),...body}).strict()]),cableCrossSectionSchema=external_exports.discriminatedUnion("kind",[external_exports.object({kind:external_exports.literal("round_jacket"),diameter:dimension,color}).strict(),external_exports.object({kind:external_exports.literal("wire_bundle"),wires:external_exports.array(external_exports.object({diameter:dimension,color}).strict()).min(2),wirePitch:dimension}).strict()]),cableDefinitionSchema=external_exports.object({standard:cableStandardSchema,connectorA:cableConnectorSchema,connectorB:cableConnectorSchema,crossSection:cableCrossSectionSchema}).strict().superRefine((cable,ctx)=>{let{connectorA,connectorB,crossSection}=cable,expected={usb_c:["usb_c_plug","usb_c_plug"],jst_sh:["jst_sh_housing","jst_sh_housing"],jst_ph:["jst_ph_housing","jst_ph_housing"],us_mains:["nema_5_15p","iec_c13"],bullet:[connectorA.kind,connectorB.kind],adaptercable:[connectorA.kind,connectorB.kind]}[cable.standard];if((connectorA.kind!==expected[0]||connectorB.kind!==expected[1])&&ctx.addIssue({code:external_exports.ZodIssueCode.custom,message:"Connector kinds must match the cable standard"}),cable.standard==="bullet"){(!("diameter"in connectorA)||!("diameter"in connectorB)||connectorA.diameter!==connectorB.diameter||"pinCount"in connectorA&&"pinCount"in connectorB&&connectorA.pinCount!==connectorB.pinCount)&&ctx.addIssue({code:external_exports.ZodIssueCode.custom,message:"Bullet connectors require supported nominal diameters and matching contact counts"}),"pinCount"in connectorA&&(connectorA.pinCount===1&&crossSection.kind!=="round_jacket"||connectorA.pinCount>1&&crossSection.kind!=="wire_bundle")&&ctx.addIssue({code:external_exports.ZodIssueCode.custom,message:"Bullet cables require one insulated wire per contact"});for(let connector of[connectorA,connectorB])"diameter"in connector&&(connector.bodyHeight<=connector.diameter||connector.pitch<connector.bodyHeight||Math.abs(connector.bodyWidth-(connector.bodyHeight+(connector.pinCount-1)*connector.pitch))>1e-6||crossSection.kind==="wire_bundle"&&(crossSection.wirePitch!==connector.pitch||crossSection.wires.some(wire=>wire.diameter>connector.bodyHeight))||connector.contactDepth>=connector.bodyDepth||crossSection.kind==="round_jacket"&&crossSection.diameter>connector.bodyHeight)&&ctx.addIssue({code:external_exports.ZodIssueCode.custom,message:"Bullet contact, body, and wire dimensions must fit"})}else cable.standard!=="adaptercable"&&("diameter"in connectorA||"diameter"in connectorB)&&ctx.addIssue({code:external_exports.ZodIssueCode.custom,message:"Bullet connectors require the bullet cable standard"});if(cable.standard==="adaptercable"){"pinCount"in connectorA&&"pinCount"in connectorB&&connectorA.pinCount!==connectorB.pinCount&&ctx.addIssue({code:external_exports.ZodIssueCode.custom,message:"Adapter connector pin counts must match"}),"pinCount"in connectorA&&"pinCount"in connectorB&&connectorA.pinCount>1&&crossSection.kind!=="wire_bundle"&&ctx.addIssue({code:external_exports.ZodIssueCode.custom,message:"Adapter cables require one wire per explicit contact"});for(let connector of[connectorA,connectorB])"diameter"in connector&&(connector.bodyHeight<=connector.diameter||connector.pitch<connector.bodyHeight||Math.abs(connector.bodyWidth-(connector.bodyHeight+(connector.pinCount-1)*connector.pitch))>1e-6||connector.contactDepth>=connector.bodyDepth||connector.pinCount===1&&(crossSection.kind!=="round_jacket"||crossSection.diameter>connector.bodyHeight)||connector.pinCount>1&&(crossSection.kind!=="wire_bundle"||crossSection.wires.some(wire=>wire.diameter>connector.bodyHeight)))&&ctx.addIssue({code:external_exports.ZodIssueCode.custom,message:"Bullet contact, body, and wire dimensions must fit"})}if(crossSection.kind==="wire_bundle"){for(let connector of[connectorA,connectorB])(!("pinCount"in connector)||connector.pinCount!==crossSection.wires.length)&&ctx.addIssue({code:external_exports.ZodIssueCode.custom,message:"Bundle wire count must match each connector pin count"}),"pitch"in connector&&crossSection.wires.some(wire=>wire.diameter>connector.pitch)&&ctx.addIssue({code:external_exports.ZodIssueCode.custom,message:"Insulated wires must fit each connector pitch"});crossSection.wires.some(wire=>wire.diameter>crossSection.wirePitch)&&ctx.addIssue({code:external_exports.ZodIssueCode.custom,message:"Bundle wires must not overlap in the cross section"})}else(cable.standard==="jst_sh"||cable.standard==="jst_ph")&&ctx.addIssue({code:external_exports.ZodIssueCode.custom,message:"JST cables require a wire bundle"})}),adapterCableInputSchema=external_exports.object({standard:external_exports.literal("adaptercable"),connectorA:cableConnectorSchema,connectorB:cableConnectorSchema,crossSection:cableCrossSectionSchema.optional()}).strict(),color2=external_exports.string().regex(/^#[0-9a-fA-F]{6}$/),jacket={jacketDiameter:external_exports.number().finite().positive().default(4),color:color2.default("#263449")},cableInputSchema=external_exports.discriminatedUnion("standard",[external_exports.object({standard:external_exports.literal("bullet"),diameter:bulletDiameterSchema,pinCount:external_exports.number().int().min(1).max(16).default(1),genderA:bulletGenderSchema.default("male"),genderB:bulletGenderSchema.default("female"),wireDiameter:external_exports.number().finite().positive().default(2),color:color2.default("#263449")}).strict(),external_exports.object({standard:external_exports.literal("usb_c"),...jacket}).strict(),external_exports.object({standard:external_exports.literal("jst_sh"),pinCount:external_exports.number().int().min(2).max(15).default(4),wireDiameter:external_exports.number().finite().min(.4).max(.8).default(.6)}).strict(),external_exports.object({standard:external_exports.literal("jst_ph"),pinCount:external_exports.number().int().min(2).max(16).default(2),wireDiameter:external_exports.number().finite().min(.8).max(1.5).default(1.2)}).strict(),external_exports.object({standard:external_exports.literal("us_mains"),...jacket,jacketDiameter:jacket.jacketDiameter.default(6.2)}).strict(),adapterCableInputSchema]),wireColors=["#df4049","#263449","#e1b13c","#347dc9","#27a782","#af62bd"];function getAdapterCableDefinition(input2){let cable=adapterCableInputSchema.parse({standard:"adaptercable",...input2}),{connectorA,connectorB}=cable,bundled="pinCount"in connectorA&&"pinCount"in connectorB&&connectorA.pinCount>1,pitches=[connectorA,connectorB].flatMap(connector=>"pitch"in connector?[connector.pitch]:[]),wireDiameter=Math.min(2,...pitches.map(pitch=>pitch*.6));return cableDefinitionSchema.parse({...cable,crossSection:cable.crossSection??(bundled?{kind:"wire_bundle",wirePitch:Math.max(...pitches),wires:Array.from({length:connectorA.pinCount},(_22,index2)=>({diameter:wireDiameter,color:wireColors[index2%wireColors.length]}))}:{kind:"round_jacket",diameter:Math.min(4,connectorA.bodyHeight,connectorB.bodyHeight,...pitches.map(pitch=>Math.min(2,pitch*.6))),color:"#263449"})})}var wireColors2=["#df4049","#263449","#e1b13c","#347dc9","#27a782","#af62bd"];function getCableDefinition(cableInput){let cable=cableInputSchema.parse(cableInput);if(cable.standard==="adaptercable")return getAdapterCableDefinition(cable);if(cable.standard==="bullet"){let pitch=cable.diameter+2;return cableDefinitionSchema.parse({standard:"bullet",connectorA:getBulletConnector({diameter:cable.diameter,gender:cable.genderA,pinCount:cable.pinCount,pitch}),connectorB:getBulletConnector({diameter:cable.diameter,gender:cable.genderB,pinCount:cable.pinCount,pitch}),crossSection:cable.pinCount===1?{kind:"round_jacket",diameter:cable.wireDiameter,color:cable.color}:{kind:"wire_bundle",wirePitch:pitch,wires:Array.from({length:cable.pinCount},(_22,index2)=>({diameter:cable.wireDiameter,color:wireColors2[index2%wireColors2.length]}))}})}if(cable.standard==="usb_c"){let connector2={kind:"usb_c_plug",bodyWidth:12,bodyHeight:6,bodyDepth:18,shellWidth:8.25,shellHeight:2.4,shellDepth:6.5};return cableDefinitionSchema.parse({standard:cable.standard,connectorA:connector2,connectorB:{...connector2},crossSection:{kind:"round_jacket",diameter:cable.jacketDiameter,color:cable.color}})}if(cable.standard==="us_mains")return cableDefinitionSchema.parse({standard:cable.standard,connectorA:{kind:"nema_5_15p",bodyWidth:32,bodyHeight:28,bodyDepth:35},connectorB:{kind:"iec_c13",bodyWidth:24,bodyHeight:18,bodyDepth:30},crossSection:{kind:"round_jacket",diameter:cable.jacketDiameter,color:cable.color}});let isSh=cable.standard==="jst_sh",connector={kind:isSh?"jst_sh_housing":"jst_ph_housing",pinCount:cable.pinCount,pitch:isSh?1:2,bodyWidth:isSh?cable.pinCount+1:(cable.pinCount-1)*2+3.8,bodyHeight:isSh?2.8:4.5,bodyDepth:isSh?5:6.85};return cableDefinitionSchema.parse({standard:cable.standard,connectorA:connector,connectorB:{...connector},crossSection:{kind:"wire_bundle",wirePitch:connector.pitch,wires:Array.from({length:cable.pinCount},(_22,index2)=>({diameter:cable.wireDiameter,color:wireColors2[index2%wireColors2.length]}))}})}function parseConnectorString(connectorString){let name=connectorString.trim().toLowerCase(),bullet=/^bullet([1-9][0-9]*)?_(.+)$/.exec(name);if(bullet){let diameter,gender,seen=new Set;for(let parameter of bullet[2].split("_")){let match2=/^d([0-9]+(?:\.[0-9]+)?)mm$/.exec(parameter)??/^g(male|female)$/.exec(parameter),key=parameter[0];if(!match2||seen.has(key))throw new Error(`Invalid or duplicate connector parameter: "${parameter}"`);seen.add(key),key==="d"?diameter=Number(match2[1]):gender=match2[1]}if(diameter===void 0||gender===void 0)throw new Error("Bullet connector strings require dNmm and gmale or gfemale");return getCableDefinition({standard:"bullet",diameter:bulletDiameterSchema.parse(diameter),pinCount:bullet[1]?Number(bullet[1]):1,genderA:gender}).connectorA}let jst2=/^(jst_sh|jst_ph)(?:_pins([0-9]+))?$/.exec(name);if(jst2)return getCableDefinition({standard:jst2[1],...jst2[2]?{pinCount:Number(jst2[2])}:{}}).connectorA;if(name==="usb_c")return getCableDefinition({standard:"usb_c"}).connectorA;if(name==="nema_5_15p")return getCableDefinition({standard:"us_mains"}).connectorA;if(name==="iec_c13")return getCableDefinition({standard:"us_mains"}).connectorB;throw new Error(`Unsupported connector string: "${connectorString}"`)}function parseCableString(cableString){let cableName=cableString.trim().toLowerCase();if(cableName.startsWith("adaptercable")){let adapter=/^adaptercable_(a|b)\(([^()]+)\)_(a|b)\(([^()]+)\)$/.exec(cableName);if(!adapter||adapter[1]===adapter[3])throw new Error("Adapter cables require exactly one named a(CONNECTOR) and b(CONNECTOR)");let first=parseConnectorString(adapter[2]),second=parseConnectorString(adapter[4]);return getAdapterCableDefinition({connectorA:adapter[1]==="a"?first:second,connectorB:adapter[1]==="b"?first:second})}if(cableName==="usb_c"||cableName==="us_mains")return getCableDefinition({standard:cableName});let bulletMatch=/^bullet([1-9][0-9]*)?_(.+)$/.exec(cableName);if(bulletMatch){let diameter,genderA,genderB,seen=new Set;for(let parameter of bulletMatch[2].split("_")){let match2=/^d([0-9]+(?:\.[0-9]+)?)mm$/.exec(parameter)??/^(a|b)(male|female)$/.exec(parameter),key=parameter[0];if(!match2||seen.has(key))throw new Error(`Invalid or duplicate bullet parameter: "${parameter}"`);seen.add(key),key==="d"?diameter=Number(match2[1]):key==="a"?genderA=match2[2]:genderB=match2[2]}if(diameter===void 0)throw new Error("Bullet cables require dNmm");return getCableDefinition({standard:"bullet",diameter:bulletDiameterSchema.parse(diameter),pinCount:bulletMatch[1]?Number(bulletMatch[1]):1,genderA:genderA??"male",genderB:genderB??"female"})}let jstMatch=/^(jst_sh|jst_ph)(?:_pins([0-9]+))?$/.exec(cableName);if(jstMatch)return getCableDefinition({standard:jstMatch[1],...jstMatch[2]?{pinCount:Number(jstMatch[2])}:{}});throw new Error(`Unsupported cable string: "${cableString}". Expected usb_c, jst_sh[_pinsN], jst_ph[_pinsN], us_mains, bullet[CONTACTS]_dNmm[_amale][_bfemale], or adaptercable_a(CONNECTOR)_b(CONNECTOR).`)}function resolveAssemblyCablePin1Position(cable,connector,matingCenter,outward){let db22=cable.root.db,pins=db22.source_port.list().flatMap(sourcePort=>{if(sourcePort.source_component_id!==connector.source_component_id)return[];let pcbPort=db22.pcb_port.list().find(port=>port.source_port_id===sourcePort.source_port_id&&port.pcb_component_id===connector.pcb_component_id);if(!pcbPort)return[];let hint=[sourcePort.name,...sourcePort.port_hints??[]].find(name=>/^(?:pin)?\d+$/.test(name)),pin=sourcePort.pin_number??(hint?Number(hint.replace(/^pin/,"")):void 0);return[{position:pcbPort,pin}]}),pin1=pins.find(({pin})=>pin===1)?.position;if(!pin1||pins.length<2)return;let center2=pins.reduce((sum,{position:position4})=>({x:sum.x+position4.x/pins.length,y:sum.y+position4.y/pins.length}),{x:0,y:0}),offset2=vec3_exports.fromValues(pin1.x-center2.x,pin1.y-center2.y,0),axis=vec3_exports.normalize(vec3_exports.create(),[outward.x,outward.y,outward.z]);if(vec3_exports.scaleAndAdd(offset2,offset2,axis,-vec3_exports.dot(offset2,axis)),!(vec3_exports.length(offset2)<1e-6))return{x:matingCenter.x+offset2[0],y:matingCenter.y+offset2[1],z:matingCenter.z+offset2[2]}}function resolveAssemblyCableEndpoint(cable,selector2,cableConnector){let scoped=getComponentsInAssemblyScope(cable),motorReference=selector2.match(/^(.+)\.wireside$/);if(motorReference){let motors=scoped.filter(part=>part.componentName==="AssemblyMotor"&&part.name===motorReference[1]);if(motors.length!==1)throw new Error(`assembly.cable "${cable.name}" endpoint "${selector2}" must match exactly one motor in its assembly device`);let motor=motors[0],motorConnector=getJstMotorConnector(motor.motorModel.wireConnection);if(!motorConnector)throw new Error(`assembly.cable "${cable.name}" requires motor "${motor.name}" to have a JST PH or SH wireConnection, e.g. "jst4_ph" or "jst4_sh", for its connector endpoint`);let faceMount=resolveMotorFaceMount(motor),placement=faceMount?{position:faceMount.position,pcbRotation:0,layer:"top"}:resolveAssemblyMotorPlacement(motor),offset2=faceMount?.rotation??resolveAssemblyMotorRotation(motor,placement),orientation22=mat4_exports.create(),bottom=placement.layer==="bottom";mat4_exports.rotateX(orientation22,orientation22,offset2.x*Math.PI/180),mat4_exports.rotateY(orientation22,orientation22,(offset2.y+(bottom?180:0))*Math.PI/180),mat4_exports.rotateZ(orientation22,orientation22,(bottom?-1:1)*(placement.pcbRotation+offset2.z)*Math.PI/180);let reference3=motor.motorReferencePoints.wireside,direction22=vec3_exports.transformMat4(vec3_exports.create(),[reference3.direction.x,reference3.direction.y,reference3.direction.z],orientation22),point62=vec3_exports.transformMat4(vec3_exports.create(),[reference3.position.x,reference3.position.y,reference3.position.z],orientation22),halfPinSpan=(motorConnector.pinCount-1)*motorConnector.pitch/2,pin1Offset=vec3_exports.transformMat4(vec3_exports.create(),[reference3.direction.y*halfPinSpan,-reference3.direction.x*halfPinSpan,0],orientation22);return{sourceComponentId:motor.source_component_id,position:{x:point62[0]+placement.position.x+direction22[0]*motorConnector.matingDepth,y:point62[1]+placement.position.y+direction22[1]*motorConnector.matingDepth,z:point62[2]+placement.position.z+direction22[2]*motorConnector.matingDepth},pin1Position:{x:point62[0]+placement.position.x+direction22[0]*motorConnector.matingDepth+pin1Offset[0],y:point62[1]+placement.position.y+direction22[1]*motorConnector.matingDepth+pin1Offset[1],z:point62[2]+placement.position.z+direction22[2]*motorConnector.matingDepth+pin1Offset[2]},direction:{x:direction22[0],y:direction22[1],z:direction22[2]},cableInput:{standard:motorConnector.standard,pinCount:motorConnector.pinCount}}}let scope=getAssemblyScope(cable),matches=selectAll(preprocessSelector(selector2,cable),scope,{adapter:cssSelectPrimitiveComponentAdapter}).filter(part=>scoped.includes(part));if(matches.length!==1)throw new Error(`assembly.cable "${cable.name}" endpoint "${selector2}" matched ${matches.length} components; expected exactly one in its assembly device`);let connector=matches[0];if(!(connector instanceof NormalComponent)||connector.componentName!=="Connector"||!connector.pcb_component_id||!connector.source_component_id)throw new Error(`assembly.cable "${cable.name}" endpoint "${selector2}" must name a PCB connector or MOTOR.wireside`);let props=connector._parsedProps;if(!cableConnector&&props.standard!=="usb_c"&&props.standard!=="jst_sh"&&props.standard!=="jst_ph")throw new Error(`assembly.cable "${cable.name}" cannot infer endpoint "${selector2}"; use a connector with standard="usb_c", "jst_sh", or "jst_ph"`);let pcb=cable.root.db.pcb_component.get(connector.pcb_component_id),board=connector._getBoard(),layer=pcb.layer==="bottom"?"bottom":"top",inferredCenter=pcb.cable_insertion_center??pcb.center,inferredDirection=vec3_exports.normalize(vec3_exports.create(),[inferredCenter.x-pcb.center.x,inferredCenter.y-pcb.center.y,0]),direction3=connector._getPcbComponentInsertionAxisDirection(layer,pcb.rotation)??(props.standard==="usb_c"&&vec3_exports.length(inferredDirection)>0?{x:inferredDirection[0],y:inferredDirection[1],z:0}:{x:0,y:0,z:layer==="bottom"?-1:1}),center2=Math.abs(direction3.z)>.5?pcb.center:inferredCenter,sign=layer==="bottom"?-1:1,height=!props.standard&&cableConnector?Math.abs(direction3.z)>.5?cableConnector.bodyDepth:cableConnector.bodyHeight/2:Math.abs(direction3.z)>.5?props.standard==="jst_ph"?6:props.standard==="jst_sh"?4.25:1.5:props.standard==="usb_c"?1.5:props.standard==="jst_sh"?1.4:2.25,position4={x:center2.x,y:center2.y,z:sign*(board.boardThickness/2+height)};return{sourceComponentId:connector.source_component_id,position:position4,pin1Position:resolveAssemblyCablePin1Position(cable,connector,position4,direction3),direction:direction3,cableInput:props.standard==="usb_c"?{standard:"usb_c"}:props.standard==="jst_sh"||props.standard==="jst_ph"?{standard:props.standard,pinCount:props.pinCount}:void 0}}function inferAssemblyCablePath({from,to:to3,fromDirection,toDirection}){let distance27=Math.hypot(to3.x-from.x,to3.y-from.y,to3.z-from.z);if(distance27<1e-6)throw new Error("Cable wire exits must be at different positions");let chord=vec3_exports.fromValues(to3.x-from.x,to3.y-from.y,to3.z-from.z),routeNormal=vec3_exports.cross(vec3_exports.create(),chord,[fromDirection.x,fromDirection.y,fromDirection.z]);vec3_exports.length(routeNormal)<1e-6&&vec3_exports.cross(routeNormal,chord,Math.abs(chord[2])/distance27>.95?[0,1,0]:[0,0,1]);let archDirection=vec3_exports.normalize(vec3_exports.create(),vec3_exports.cross(vec3_exports.create(),routeNormal,chord)),archSide=from.z<0&&to3.z<0?-1:1;archDirection[2]*archSide<0&&vec3_exports.scale(archDirection,archDirection,-1);let clearance=Math.min(25,Math.max(8,distance27/3)),controlA={x:from.x+fromDirection.x*clearance,y:from.y+fromDirection.y*clearance,z:from.z+fromDirection.z*clearance},controlB={x:to3.x+toDirection.x*clearance,y:to3.y+toDirection.y*clearance,z:to3.z+toDirection.z*clearance},path=[from,{x:from.x+fromDirection.x*.1,y:from.y+fromDirection.y*.1,z:from.z+fromDirection.z*.1}];for(let i22=1;i22<48;i22++){let t48=i22/48,u22=1-t48,arch=Math.sin(Math.PI*t48)**2*Math.min(12,distance27*.15);path.push({x:u22**3*from.x+3*u22**2*t48*controlA.x+3*u22*t48**2*controlB.x+t48**3*to3.x+archDirection[0]*arch,y:u22**3*from.y+3*u22**2*t48*controlA.y+3*u22*t48**2*controlB.y+t48**3*to3.y+archDirection[1]*arch,z:u22**3*from.z+3*u22**2*t48*controlA.z+3*u22*t48**2*controlB.z+t48**3*to3.z+archDirection[2]*arch})}return path.push({x:to3.x+toDirection.x*.1,y:to3.y+toDirection.y*.1,z:to3.z+toDirection.z*.1},to3),path}var wireExitDepth=connector=>connector.bodyDepth+(connector.kind==="usb_c_plug"?connector.shellDepth:0);function resolveAssemblyCable(cable){let model27=cable._parsedProps.model,explicitDefinition=model27?parseCableString(model27):void 0,from=resolveAssemblyCableEndpoint(cable,cable._parsedProps.from,explicitDefinition?.connectorA),to3=resolveAssemblyCableEndpoint(cable,cable._parsedProps.to,explicitDefinition?.connectorB),fromDefinition=explicitDefinition??getCableDefinition(from.cableInput),toDefinition=explicitDefinition??getCableDefinition(to3.cableInput);if(from.sourceComponentId===to3.sourceComponentId)throw new Error(`assembly.cable "${cable.name}" must connect two different endpoints`);if(!explicitDefinition&&(fromDefinition.standard!==toDefinition.standard||fromDefinition.connectorA.kind!==toDefinition.connectorA.kind||"pinCount"in fromDefinition.connectorA&&"pinCount"in toDefinition.connectorA&&fromDefinition.connectorA.pinCount!==toDefinition.connectorA.pinCount))throw new Error(`assembly.cable "${cable.name}" endpoints "${cable._parsedProps.from}" and "${cable._parsedProps.to}" have incompatible connector standards or pin counts`);if(cable._parsedProps.standard&&cable._parsedProps.standard!==fromDefinition.standard)throw new Error(`assembly.cable "${cable.name}" standard="${cable._parsedProps.standard}" conflicts with its endpoints`);let definition=fromDefinition,endpointExit=(position4,direction3,depth)=>{let exit=vec3_exports.scaleAndAdd(vec3_exports.create(),[position4.x,position4.y,position4.z],[direction3.x,direction3.y,direction3.z],depth);return{x:exit[0],y:exit[1],z:exit[2]}},fromExit=endpointExit(from.position,from.direction,wireExitDepth(definition.connectorA)),toExit=endpointExit(to3.position,to3.direction,wireExitDepth(definition.connectorB));return{name:cable.name,from_source_component_id:from.sourceComponentId,to_source_component_id:to3.sourceComponentId,from_connector_pin1_position:from.pin1Position,to_connector_pin1_position:to3.pin1Position,cableprinter_string:model27??("pinCount"in definition.connectorA?`${definition.standard}_pins${definition.connectorA.pinCount}`:definition.standard),path:inferAssemblyCablePath({from:fromExit,to:toExit,fromDirection:from.direction,toDirection:to3.direction})}}var AssemblyCable=class extends PrimitiveComponent2{constructor(){super(...arguments);__publicField(this,"cadCableId")}get config(){return{componentName:"AssemblyCable",zodProps:assemblyCableProps}}doInitialCadModelRender(){if(!this.root||this.root.pcbDisabled)return;let cable=resolveAssemblyCable(this);this.cadCableId=this.root.db.cad_cable.insert(cable).cad_cable_id}updateCadModelRender(){!this.root||this.root.pcbDisabled||!this.cadCableId||this.root.db.cad_cable.update(this.cadCableId,resolveAssemblyCable(this))}},createNamespacedElement=hostType=>{let Component2=props=>(0,import_react14.createElement)(hostType,props);return Component2.displayName=hostType,Component2},analog={transientsimulation:createNamespacedElement("analogtransientsimulation"),dcoperatingpointsimulation:createNamespacedElement("analogdcoperatingpointsimulation"),dcsweepsimulation:createNamespacedElement("analogdcsweepsimulation"),acsweepsimulation:createNamespacedElement("analogacsweepsimulation"),sweepparameter:createNamespacedElement("analogsweepparameter")},assembly={referencesurface:createNamespacedElement("assembly.referencesurface"),part:createNamespacedElement("assembly.part"),cable:createNamespacedElement("assembly.cable"),printedpart:createNamespacedElement("assembly.printedpart"),motor:createNamespacedElement("assembly.motor"),subassembly:createNamespacedElement("assembly.subassembly"),cadassembly:createNamespacedElement("assembly.cadassembly"),device:createNamespacedElement("assembly.device"),screen:createNamespacedElement("assembly.screen")},EnclosureFdmBoxElement=createNamespacedElement("enclosure.fdm.box"),enclosure={cutoutaperture:createNamespacedElement("enclosure.cutoutaperture"),fdm:{box:EnclosureFdmBoxElement,Box:EnclosureFdmBoxElement}},simulation={pcbreturncurrentsimulation:createNamespacedElement("pcbreturncurrentsimulation"),pcbreturncurrentexcitation:createNamespacedElement("pcbreturncurrentexcitation")},RootCircuit=class extends IsolatedCircuit{constructor({platform,projectUrl}={}){super({platform,projectUrl,cachedSubcircuits:new Map,pendingSubcircuitRenders:new Map});__publicField(this,"isRootCircuit",!0);this.root=this}},Project2=RootCircuit,Circuit=RootCircuit,useRenderedCircuit=reactElements=>{let[isLoading,setIsLoading]=import_react15.default.useState(!0),[error2,setError]=import_react15.default.useState(null),[circuit,setCircuit]=import_react15.default.useState(),[circuitJson,setCircuitJson]=import_react15.default.useState();return import_react15.default.useEffect(()=>{setIsLoading(!0),setError(null),reactElements&&setTimeout(()=>{try{let circuit2=new RootCircuit;circuit2.add(reactElements),setCircuit(circuit2),setCircuitJson(circuit2.toJson())}catch(error22){setError(error22)}setIsLoading(!1)},1)},[reactElements]),{isLoading,error:error2,circuit,circuitJson}},createUseComponent=(Component2,pins)=>(name,props)=>{let pinLabelsFlatArray=[];Array.isArray(pins)?pinLabelsFlatArray.push(...pins.flat()):typeof pins=="object"&&pinLabelsFlatArray.push(...Object.values(pins).flat(),...Object.keys(pins));let R22=props2=>{if(props2?.name&&props2.name!==name)throw new Error(`Component name mismatch. Hook name: ${name}, Component prop name: ${props2.name}`);let combinedProps={...props,...props2,name},tracesToCreate=[];for(let portLabel of pinLabelsFlatArray)if(combinedProps[portLabel]){let from=`.${name} > .${portLabel}`,to3=combinedProps[portLabel];tracesToCreate.push({from,to:to3}),delete combinedProps[portLabel]}return(0,import_jsx_runtime31.jsxs)(import_jsx_runtime31.Fragment,{children:[(0,import_jsx_runtime31.jsx)(Component2,{...combinedProps}),tracesToCreate.map((trace,i22)=>(0,import_jsx_runtime31.jsx)("trace",{...trace},i22))]})};for(let port of pinLabelsFlatArray)R22[port]=`.${name} > .${port}`;return R22},useCapacitor=createUseComponent(props=>(0,import_jsx_runtime32.jsx)("capacitor",{...props}),capacitorPins),useChip=pinLabels=>createUseComponent(props=>(0,import_jsx_runtime33.jsx)("chip",{pinLabels,...props}),pinLabels),useDiode=createUseComponent(props=>(0,import_jsx_runtime34.jsx)("diode",{...props}),diodePins),useLed=createUseComponent(props=>(0,import_jsx_runtime35.jsx)("led",{...props}),ledPins),useResistor=createUseComponent(props=>(0,import_jsx_runtime36.jsx)("resistor",{...props}),resistorPins),sel=new Proxy(refdes=>new Proxy({},{get:(_22,pin)=>`.${refdes} > .${pin}`}),{get:(_22,prop1)=>{let fn3=(...args)=>{let chipFnOrPinType=args[0];return new Proxy({},{get:(_32,pinName)=>`.${prop1} > .${pinName}`})};return new Proxy(fn3,{get:(_32,prop2)=>prop1==="net"?`net.${prop2}`:prop1==="subcircuit"?new Proxy({},{get:(_43,prop3)=>new Proxy({},{get:(_52,prop4)=>`subcircuit.${prop2} > .${prop3} > .${prop4}`})}):`.${prop1} > .${prop2}`,apply:(target,_32,args)=>prop1==="net"?new Proxy({},{get:(_43,netName)=>`net.${netName}`}):new Proxy({},{get:(_43,pinOrSubComponentName)=>{let pinResult=`.${prop1} > .${pinOrSubComponentName}`;return["U","J","CN"].some(p22=>prop1.startsWith(p22))?pinResult:new Proxy(new String(pinResult),{get:(_52,nestedProp)=>typeof nestedProp=="symbol"||nestedProp==="toString"?()=>pinResult:`.${prop1} > .${pinOrSubComponentName} > .${nestedProp}`})}})})}});extendCatalogue(components_exports);extendCatalogue({"assembly.cable":AssemblyCable,"assembly.device":AssemblyDevice,"assembly.motor":AssemblyMotor,"assembly.part":AssemblyPart,"assembly.referencesurface":AssemblyReferenceSurface,"assembly.printedpart":AssemblyPrintedPart,"assembly.screen":AssemblyScreen,"assembly.subassembly":AssemblySubassembly,"assembly.cadassembly":AssemblySubassembly,Bug:Chip,"enclosure.cutoutaperture":EnclosureCutoutAperture,"enclosure.fdm.box":EnclosureFdmBox,Fanout:Breakout,FanoutPoint:BreakoutPoint});var React4=__toESM(require_react(),1),ReactJsxRuntime=__toESM(require_jsx_runtime(),1);init_dist2();var fabricatorPresets={jlcpcb_economy_20260912:{minimumViaHoleDiameterWithoutExtraCharge:.3},jlcpcb_standard_20260912:{minimumViaHoleDiameterWithoutExtraCharge:.3}},presetAliases={jlcpcb_economy:"jlcpcb_economy_20260912",jlcpcb_standard:"jlcpcb_standard_20260912"};function resolvePreset(name){let resolved=Object.hasOwn(presetAliases,name)?presetAliases[name]:name;return Object.hasOwn(fabricatorPresets,resolved)?fabricatorPresets[resolved]:void 0}function runDrcChecks({circuitJson,fabricatorPreset,pcbBoardId}){let preset=resolvePreset(fabricatorPreset);if(!preset)return[];let threshold=preset.minimumViaHoleDiameterWithoutExtraCharge,smallVias=circuitJson.filter(element=>element.type==="pcb_via").filter(via=>via.hole_diameter<threshold);return smallVias.length===0?[]:[pcb_fabricator_extra_charge_warning.parse({type:"pcb_fabricator_extra_charge_warning",fabricator_preset:fabricatorPreset,pcb_board_id:pcbBoardId,pcb_via_ids:smallVias.map(via=>via.pcb_via_id),message:`${fabricatorPreset}: ${smallVias.length} via(s) have a hole diameter below ${threshold} mm and incur an extra fabrication charge. Use a hole diameter of at least ${threshold} mm to avoid this charge.`})]}var fabricatorEngine2={runDrcChecks};var __create3=Object.create,__defProp5=Object.defineProperty,__getOwnPropDesc3=Object.getOwnPropertyDescriptor,__getOwnPropNames3=Object.getOwnPropertyNames,__getProtoOf3=Object.getPrototypeOf,__hasOwnProp4=Object.prototype.hasOwnProperty,__commonJS3=(cb4,mod)=>function(){return mod||(0,cb4[__getOwnPropNames3(cb4)[0]])((mod={exports:{}}).exports,mod),mod.exports},__export4=(target,all)=>{for(var name in all)__defProp5(target,name,{get:all[name],enumerable:!0})},__copyProps3=(to3,from,except,desc)=>{if(from&&typeof from=="object"||typeof from=="function")for(let key of __getOwnPropNames3(from))!__hasOwnProp4.call(to3,key)&&key!==except&&__defProp5(to3,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc3(from,key))||desc.enumerable});return to3},__toESM3=(mod,isNodeMode,target)=>(target=mod!=null?__create3(__getProtoOf3(mod)):{},__copyProps3(isNodeMode||!mod||!mod.__esModule?__defProp5(target,"default",{value:mod,enumerable:!0}):target,mod)),require_react_production=__commonJS3({"node_modules/react/cjs/react.production.js"(exports){"use strict";var REACT_ELEMENT_TYPE=Symbol.for("react.transitional.element"),REACT_PORTAL_TYPE=Symbol.for("react.portal"),REACT_FRAGMENT_TYPE=Symbol.for("react.fragment"),REACT_STRICT_MODE_TYPE=Symbol.for("react.strict_mode"),REACT_PROFILER_TYPE=Symbol.for("react.profiler"),REACT_CONSUMER_TYPE=Symbol.for("react.consumer"),REACT_CONTEXT_TYPE=Symbol.for("react.context"),REACT_FORWARD_REF_TYPE=Symbol.for("react.forward_ref"),REACT_SUSPENSE_TYPE=Symbol.for("react.suspense"),REACT_MEMO_TYPE=Symbol.for("react.memo"),REACT_LAZY_TYPE=Symbol.for("react.lazy"),MAYBE_ITERATOR_SYMBOL=Symbol.iterator;function getIteratorFn(maybeIterable){return maybeIterable===null||typeof maybeIterable!="object"?null:(maybeIterable=MAYBE_ITERATOR_SYMBOL&&maybeIterable[MAYBE_ITERATOR_SYMBOL]||maybeIterable["@@iterator"],typeof maybeIterable=="function"?maybeIterable:null)}var ReactNoopUpdateQueue={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},assign=Object.assign,emptyObject={};function Component(props,context,updater){this.props=props,this.context=context,this.refs=emptyObject,this.updater=updater||ReactNoopUpdateQueue}Component.prototype.isReactComponent={},Component.prototype.setState=function(partialState,callback){if(typeof partialState!="object"&&typeof partialState!="function"&&partialState!=null)throw Error("takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,partialState,callback,"setState")},Component.prototype.forceUpdate=function(callback){this.updater.enqueueForceUpdate(this,callback,"forceUpdate")};function ComponentDummy(){}ComponentDummy.prototype=Component.prototype;function PureComponent(props,context,updater){this.props=props,this.context=context,this.refs=emptyObject,this.updater=updater||ReactNoopUpdateQueue}var pureComponentPrototype=PureComponent.prototype=new ComponentDummy;pureComponentPrototype.constructor=PureComponent,assign(pureComponentPrototype,Component.prototype),pureComponentPrototype.isPureReactComponent=!0;var isArrayImpl=Array.isArray,ReactSharedInternals={H:null,A:null,T:null,S:null,V:null},hasOwnProperty=Object.prototype.hasOwnProperty;function ReactElement(type,key,self2,source,owner,props){return self2=props.ref,{$$typeof:REACT_ELEMENT_TYPE,type,key,ref:self2!==void 0?self2:null,props}}function cloneAndReplaceKey(oldElement,newKey){return ReactElement(oldElement.type,newKey,void 0,void 0,void 0,oldElement.props)}function isValidElement33(object){return typeof object=="object"&&object!==null&&object.$$typeof===REACT_ELEMENT_TYPE}function escape2(key){var escaperLookup={"=":"=0",":":"=2"};return"$"+key.replace(/[=:]/g,function(match2){return escaperLookup[match2]})}var userProvidedKeyEscapeRegex=/\/+/g;function getElementKey(element,index2){return typeof element=="object"&&element!==null&&element.key!=null?escape2(""+element.key):index2.toString(36)}function noop$1(){}function resolveThenable(thenable){switch(thenable.status){case"fulfilled":return thenable.value;case"rejected":throw thenable.reason;default:switch(typeof thenable.status=="string"?thenable.then(noop$1,noop$1):(thenable.status="pending",thenable.then(function(fulfilledValue){thenable.status==="pending"&&(thenable.status="fulfilled",thenable.value=fulfilledValue)},function(error2){thenable.status==="pending"&&(thenable.status="rejected",thenable.reason=error2)})),thenable.status){case"fulfilled":return thenable.value;case"rejected":throw thenable.reason}}throw thenable}function mapIntoArray(children,array2,escapedPrefix,nameSoFar,callback){var type=typeof children;(type==="undefined"||type==="boolean")&&(children=null);var invokeCallback=!1;if(children===null)invokeCallback=!0;else switch(type){case"bigint":case"string":case"number":invokeCallback=!0;break;case"object":switch(children.$$typeof){case REACT_ELEMENT_TYPE:case REACT_PORTAL_TYPE:invokeCallback=!0;break;case REACT_LAZY_TYPE:return invokeCallback=children._init,mapIntoArray(invokeCallback(children._payload),array2,escapedPrefix,nameSoFar,callback)}}if(invokeCallback)return callback=callback(children),invokeCallback=nameSoFar===""?"."+getElementKey(children,0):nameSoFar,isArrayImpl(callback)?(escapedPrefix="",invokeCallback!=null&&(escapedPrefix=invokeCallback.replace(userProvidedKeyEscapeRegex,"$&/")+"/"),mapIntoArray(callback,array2,escapedPrefix,"",function(c10){return c10})):callback!=null&&(isValidElement33(callback)&&(callback=cloneAndReplaceKey(callback,escapedPrefix+(callback.key==null||children&&children.key===callback.key?"":(""+callback.key).replace(userProvidedKeyEscapeRegex,"$&/")+"/")+invokeCallback)),array2.push(callback)),1;invokeCallback=0;var nextNamePrefix=nameSoFar===""?".":nameSoFar+":";if(isArrayImpl(children))for(var i11=0;i11<children.length;i11++)nameSoFar=children[i11],type=nextNamePrefix+getElementKey(nameSoFar,i11),invokeCallback+=mapIntoArray(nameSoFar,array2,escapedPrefix,type,callback);else if(i11=getIteratorFn(children),typeof i11=="function")for(children=i11.call(children),i11=0;!(nameSoFar=children.next()).done;)nameSoFar=nameSoFar.value,type=nextNamePrefix+getElementKey(nameSoFar,i11++),invokeCallback+=mapIntoArray(nameSoFar,array2,escapedPrefix,type,callback);else if(type==="object"){if(typeof children.then=="function")return mapIntoArray(resolveThenable(children),array2,escapedPrefix,nameSoFar,callback);throw array2=String(children),Error("Objects are not valid as a React child (found: "+(array2==="[object Object]"?"object with keys {"+Object.keys(children).join(", ")+"}":array2)+"). If you meant to render a collection of children, use an array instead.")}return invokeCallback}function mapChildren(children,func,context){if(children==null)return children;var result=[],count=0;return mapIntoArray(children,result,"","",function(child){return func.call(context,child,count++)}),result}function lazyInitializer(payload){if(payload._status===-1){var ctor=payload._result;ctor=ctor(),ctor.then(function(moduleObject){(payload._status===0||payload._status===-1)&&(payload._status=1,payload._result=moduleObject)},function(error2){(payload._status===0||payload._status===-1)&&(payload._status=2,payload._result=error2)}),payload._status===-1&&(payload._status=0,payload._result=ctor)}if(payload._status===1)return payload._result.default;throw payload._result}var reportGlobalError=typeof reportError=="function"?reportError:function(error2){if(typeof window=="object"&&typeof window.ErrorEvent=="function"){var event=new window.ErrorEvent("error",{bubbles:!0,cancelable:!0,message:typeof error2=="object"&&error2!==null&&typeof error2.message=="string"?String(error2.message):String(error2),error:error2});if(!window.dispatchEvent(event))return}else if(typeof process=="object"&&typeof process.emit=="function"){process.emit("uncaughtException",error2);return}console.error(error2)};function noop(){}exports.Children={map:mapChildren,forEach:function(children,forEachFunc,forEachContext){mapChildren(children,function(){forEachFunc.apply(this,arguments)},forEachContext)},count:function(children){var n10=0;return mapChildren(children,function(){n10++}),n10},toArray:function(children){return mapChildren(children,function(child){return child})||[]},only:function(children){if(!isValidElement33(children))throw Error("React.Children.only expected to receive a single React element child.");return children}},exports.Component=Component,exports.Fragment=REACT_FRAGMENT_TYPE,exports.Profiler=REACT_PROFILER_TYPE,exports.PureComponent=PureComponent,exports.StrictMode=REACT_STRICT_MODE_TYPE,exports.Suspense=REACT_SUSPENSE_TYPE,exports.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=ReactSharedInternals,exports.__COMPILER_RUNTIME={__proto__:null,c:function(size3){return ReactSharedInternals.H.useMemoCache(size3)}},exports.cache=function(fn3){return function(){return fn3.apply(null,arguments)}},exports.cloneElement=function(element,config,children){if(element==null)throw Error("The argument must be a React element, but you passed "+element+".");var props=assign({},element.props),key=element.key,owner=void 0;if(config!=null)for(propName in config.ref!==void 0&&(owner=void 0),config.key!==void 0&&(key=""+config.key),config)!hasOwnProperty.call(config,propName)||propName==="key"||propName==="__self"||propName==="__source"||propName==="ref"&&config.ref===void 0||(props[propName]=config[propName]);var propName=arguments.length-2;if(propName===1)props.children=children;else if(1<propName){for(var childArray=Array(propName),i11=0;i11<propName;i11++)childArray[i11]=arguments[i11+2];props.children=childArray}return ReactElement(element.type,key,void 0,void 0,owner,props)},exports.createContext=function(defaultValue){return defaultValue={$$typeof:REACT_CONTEXT_TYPE,_currentValue:defaultValue,_currentValue2:defaultValue,_threadCount:0,Provider:null,Consumer:null},defaultValue.Provider=defaultValue,defaultValue.Consumer={$$typeof:REACT_CONSUMER_TYPE,_context:defaultValue},defaultValue},exports.createElement=function(type,config,children){var propName,props={},key=null;if(config!=null)for(propName in config.key!==void 0&&(key=""+config.key),config)hasOwnProperty.call(config,propName)&&propName!=="key"&&propName!=="__self"&&propName!=="__source"&&(props[propName]=config[propName]);var childrenLength=arguments.length-2;if(childrenLength===1)props.children=children;else if(1<childrenLength){for(var childArray=Array(childrenLength),i11=0;i11<childrenLength;i11++)childArray[i11]=arguments[i11+2];props.children=childArray}if(type&&type.defaultProps)for(propName in childrenLength=type.defaultProps,childrenLength)props[propName]===void 0&&(props[propName]=childrenLength[propName]);return ReactElement(type,key,void 0,void 0,null,props)},exports.createRef=function(){return{current:null}},exports.forwardRef=function(render2){return{$$typeof:REACT_FORWARD_REF_TYPE,render:render2}},exports.isValidElement=isValidElement33,exports.lazy=function(ctor){return{$$typeof:REACT_LAZY_TYPE,_payload:{_status:-1,_result:ctor},_init:lazyInitializer}},exports.memo=function(type,compare2){return{$$typeof:REACT_MEMO_TYPE,type,compare:compare2===void 0?null:compare2}},exports.startTransition=function(scope){var prevTransition=ReactSharedInternals.T,currentTransition={};ReactSharedInternals.T=currentTransition;try{var returnValue=scope(),onStartTransitionFinish=ReactSharedInternals.S;onStartTransitionFinish!==null&&onStartTransitionFinish(currentTransition,returnValue),typeof returnValue=="object"&&returnValue!==null&&typeof returnValue.then=="function"&&returnValue.then(noop,reportGlobalError)}catch(error2){reportGlobalError(error2)}finally{ReactSharedInternals.T=prevTransition}},exports.unstable_useCacheRefresh=function(){return ReactSharedInternals.H.useCacheRefresh()},exports.use=function(usable){return ReactSharedInternals.H.use(usable)},exports.useActionState=function(action,initialState,permalink){return ReactSharedInternals.H.useActionState(action,initialState,permalink)},exports.useCallback=function(callback,deps){return ReactSharedInternals.H.useCallback(callback,deps)},exports.useContext=function(Context){return ReactSharedInternals.H.useContext(Context)},exports.useDebugValue=function(){},exports.useDeferredValue=function(value,initialValue){return ReactSharedInternals.H.useDeferredValue(value,initialValue)},exports.useEffect=function(create10,createDeps,update2){var dispatcher=ReactSharedInternals.H;if(typeof update2=="function")throw Error("useEffect CRUD overload is not enabled in this build of React.");return dispatcher.useEffect(create10,createDeps)},exports.useId=function(){return ReactSharedInternals.H.useId()},exports.useImperativeHandle=function(ref,create10,deps){return ReactSharedInternals.H.useImperativeHandle(ref,create10,deps)},exports.useInsertionEffect=function(create10,deps){return ReactSharedInternals.H.useInsertionEffect(create10,deps)},exports.useLayoutEffect=function(create10,deps){return ReactSharedInternals.H.useLayoutEffect(create10,deps)},exports.useMemo=function(create10,deps){return ReactSharedInternals.H.useMemo(create10,deps)},exports.useOptimistic=function(passthrough,reducer){return ReactSharedInternals.H.useOptimistic(passthrough,reducer)},exports.useReducer=function(reducer,initialArg,init){return ReactSharedInternals.H.useReducer(reducer,initialArg,init)},exports.useRef=function(initialValue){return ReactSharedInternals.H.useRef(initialValue)},exports.useState=function(initialState){return ReactSharedInternals.H.useState(initialState)},exports.useSyncExternalStore=function(subscribe,getSnapshot,getServerSnapshot){return ReactSharedInternals.H.useSyncExternalStore(subscribe,getSnapshot,getServerSnapshot)},exports.useTransition=function(){return ReactSharedInternals.H.useTransition()},exports.version="19.1.0"}}),require_react_development2=__commonJS3({"node_modules/react/cjs/react.development.js"(exports,module){"use strict";(function(){function defineDeprecationWarning(methodName,info){Object.defineProperty(Component.prototype,methodName,{get:function(){console.warn("%s(...) is deprecated in plain JavaScript React classes. %s",info[0],info[1])}})}function getIteratorFn(maybeIterable){return maybeIterable===null||typeof maybeIterable!="object"?null:(maybeIterable=MAYBE_ITERATOR_SYMBOL&&maybeIterable[MAYBE_ITERATOR_SYMBOL]||maybeIterable["@@iterator"],typeof maybeIterable=="function"?maybeIterable:null)}function warnNoop(publicInstance,callerName){publicInstance=(publicInstance=publicInstance.constructor)&&(publicInstance.displayName||publicInstance.name)||"ReactClass";var warningKey=publicInstance+"."+callerName;didWarnStateUpdateForUnmountedComponent[warningKey]||(console.error("Can't call %s on a component that is not yet mounted. This is a no-op, but it might indicate a bug in your application. Instead, assign to `this.state` directly or define a `state = {};` class property with the desired state in the %s component.",callerName,publicInstance),didWarnStateUpdateForUnmountedComponent[warningKey]=!0)}function Component(props,context,updater){this.props=props,this.context=context,this.refs=emptyObject,this.updater=updater||ReactNoopUpdateQueue}function ComponentDummy(){}function PureComponent(props,context,updater){this.props=props,this.context=context,this.refs=emptyObject,this.updater=updater||ReactNoopUpdateQueue}function testStringCoercion(value){return""+value}function checkKeyStringCoercion(value){try{testStringCoercion(value);var JSCompiler_inline_result=!1}catch{JSCompiler_inline_result=!0}if(JSCompiler_inline_result){JSCompiler_inline_result=console;var JSCompiler_temp_const=JSCompiler_inline_result.error,JSCompiler_inline_result$jscomp$0=typeof Symbol=="function"&&Symbol.toStringTag&&value[Symbol.toStringTag]||value.constructor.name||"Object";return JSCompiler_temp_const.call(JSCompiler_inline_result,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",JSCompiler_inline_result$jscomp$0),testStringCoercion(value)}}function getComponentNameFromType(type){if(type==null)return null;if(typeof type=="function")return type.$$typeof===REACT_CLIENT_REFERENCE?null:type.displayName||type.name||null;if(typeof type=="string")return type;switch(type){case REACT_FRAGMENT_TYPE:return"Fragment";case REACT_PROFILER_TYPE:return"Profiler";case REACT_STRICT_MODE_TYPE:return"StrictMode";case REACT_SUSPENSE_TYPE:return"Suspense";case REACT_SUSPENSE_LIST_TYPE:return"SuspenseList";case REACT_ACTIVITY_TYPE:return"Activity"}if(typeof type=="object")switch(typeof type.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),type.$$typeof){case REACT_PORTAL_TYPE:return"Portal";case REACT_CONTEXT_TYPE:return(type.displayName||"Context")+".Provider";case REACT_CONSUMER_TYPE:return(type._context.displayName||"Context")+".Consumer";case REACT_FORWARD_REF_TYPE:var innerType=type.render;return type=type.displayName,type||(type=innerType.displayName||innerType.name||"",type=type!==""?"ForwardRef("+type+")":"ForwardRef"),type;case REACT_MEMO_TYPE:return innerType=type.displayName||null,innerType!==null?innerType:getComponentNameFromType(type.type)||"Memo";case REACT_LAZY_TYPE:innerType=type._payload,type=type._init;try{return getComponentNameFromType(type(innerType))}catch{}}return null}function getTaskName(type){if(type===REACT_FRAGMENT_TYPE)return"<>";if(typeof type=="object"&&type!==null&&type.$$typeof===REACT_LAZY_TYPE)return"<...>";try{var name=getComponentNameFromType(type);return name?"<"+name+">":"<...>"}catch{return"<...>"}}function getOwner(){var dispatcher=ReactSharedInternals.A;return dispatcher===null?null:dispatcher.getOwner()}function UnknownOwner(){return Error("react-stack-top-frame")}function hasValidKey(config){if(hasOwnProperty.call(config,"key")){var getter=Object.getOwnPropertyDescriptor(config,"key").get;if(getter&&getter.isReactWarning)return!1}return config.key!==void 0}function defineKeyPropWarningGetter(props,displayName){function warnAboutAccessingKey(){specialPropKeyWarningShown||(specialPropKeyWarningShown=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",displayName))}warnAboutAccessingKey.isReactWarning=!0,Object.defineProperty(props,"key",{get:warnAboutAccessingKey,configurable:!0})}function elementRefGetterWithDeprecationWarning(){var componentName=getComponentNameFromType(this.type);return didWarnAboutElementRef[componentName]||(didWarnAboutElementRef[componentName]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),componentName=this.props.ref,componentName!==void 0?componentName:null}function ReactElement(type,key,self2,source,owner,props,debugStack,debugTask){return self2=props.ref,type={$$typeof:REACT_ELEMENT_TYPE,type,key,props,_owner:owner},(self2!==void 0?self2:null)!==null?Object.defineProperty(type,"ref",{enumerable:!1,get:elementRefGetterWithDeprecationWarning}):Object.defineProperty(type,"ref",{enumerable:!1,value:null}),type._store={},Object.defineProperty(type._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(type,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(type,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:debugStack}),Object.defineProperty(type,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:debugTask}),Object.freeze&&(Object.freeze(type.props),Object.freeze(type)),type}function cloneAndReplaceKey(oldElement,newKey){return newKey=ReactElement(oldElement.type,newKey,void 0,void 0,oldElement._owner,oldElement.props,oldElement._debugStack,oldElement._debugTask),oldElement._store&&(newKey._store.validated=oldElement._store.validated),newKey}function isValidElement33(object){return typeof object=="object"&&object!==null&&object.$$typeof===REACT_ELEMENT_TYPE}function escape2(key){var escaperLookup={"=":"=0",":":"=2"};return"$"+key.replace(/[=:]/g,function(match2){return escaperLookup[match2]})}function getElementKey(element,index2){return typeof element=="object"&&element!==null&&element.key!=null?(checkKeyStringCoercion(element.key),escape2(""+element.key)):index2.toString(36)}function noop$1(){}function resolveThenable(thenable){switch(thenable.status){case"fulfilled":return thenable.value;case"rejected":throw thenable.reason;default:switch(typeof thenable.status=="string"?thenable.then(noop$1,noop$1):(thenable.status="pending",thenable.then(function(fulfilledValue){thenable.status==="pending"&&(thenable.status="fulfilled",thenable.value=fulfilledValue)},function(error2){thenable.status==="pending"&&(thenable.status="rejected",thenable.reason=error2)})),thenable.status){case"fulfilled":return thenable.value;case"rejected":throw thenable.reason}}throw thenable}function mapIntoArray(children,array2,escapedPrefix,nameSoFar,callback){var type=typeof children;(type==="undefined"||type==="boolean")&&(children=null);var invokeCallback=!1;if(children===null)invokeCallback=!0;else switch(type){case"bigint":case"string":case"number":invokeCallback=!0;break;case"object":switch(children.$$typeof){case REACT_ELEMENT_TYPE:case REACT_PORTAL_TYPE:invokeCallback=!0;break;case REACT_LAZY_TYPE:return invokeCallback=children._init,mapIntoArray(invokeCallback(children._payload),array2,escapedPrefix,nameSoFar,callback)}}if(invokeCallback){invokeCallback=children,callback=callback(invokeCallback);var childKey=nameSoFar===""?"."+getElementKey(invokeCallback,0):nameSoFar;return isArrayImpl(callback)?(escapedPrefix="",childKey!=null&&(escapedPrefix=childKey.replace(userProvidedKeyEscapeRegex,"$&/")+"/"),mapIntoArray(callback,array2,escapedPrefix,"",function(c10){return c10})):callback!=null&&(isValidElement33(callback)&&(callback.key!=null&&(invokeCallback&&invokeCallback.key===callback.key||checkKeyStringCoercion(callback.key)),escapedPrefix=cloneAndReplaceKey(callback,escapedPrefix+(callback.key==null||invokeCallback&&invokeCallback.key===callback.key?"":(""+callback.key).replace(userProvidedKeyEscapeRegex,"$&/")+"/")+childKey),nameSoFar!==""&&invokeCallback!=null&&isValidElement33(invokeCallback)&&invokeCallback.key==null&&invokeCallback._store&&!invokeCallback._store.validated&&(escapedPrefix._store.validated=2),callback=escapedPrefix),array2.push(callback)),1}if(invokeCallback=0,childKey=nameSoFar===""?".":nameSoFar+":",isArrayImpl(children))for(var i11=0;i11<children.length;i11++)nameSoFar=children[i11],type=childKey+getElementKey(nameSoFar,i11),invokeCallback+=mapIntoArray(nameSoFar,array2,escapedPrefix,type,callback);else if(i11=getIteratorFn(children),typeof i11=="function")for(i11===children.entries&&(didWarnAboutMaps||console.warn("Using Maps as children is not supported. Use an array of keyed ReactElements instead."),didWarnAboutMaps=!0),children=i11.call(children),i11=0;!(nameSoFar=children.next()).done;)nameSoFar=nameSoFar.value,type=childKey+getElementKey(nameSoFar,i11++),invokeCallback+=mapIntoArray(nameSoFar,array2,escapedPrefix,type,callback);else if(type==="object"){if(typeof children.then=="function")return mapIntoArray(resolveThenable(children),array2,escapedPrefix,nameSoFar,callback);throw array2=String(children),Error("Objects are not valid as a React child (found: "+(array2==="[object Object]"?"object with keys {"+Object.keys(children).join(", ")+"}":array2)+"). If you meant to render a collection of children, use an array instead.")}return invokeCallback}function mapChildren(children,func,context){if(children==null)return children;var result=[],count=0;return mapIntoArray(children,result,"","",function(child){return func.call(context,child,count++)}),result}function lazyInitializer(payload){if(payload._status===-1){var ctor=payload._result;ctor=ctor(),ctor.then(function(moduleObject){(payload._status===0||payload._status===-1)&&(payload._status=1,payload._result=moduleObject)},function(error2){(payload._status===0||payload._status===-1)&&(payload._status=2,payload._result=error2)}),payload._status===-1&&(payload._status=0,payload._result=ctor)}if(payload._status===1)return ctor=payload._result,ctor===void 0&&console.error(`lazy: Expected the result of a dynamic import() call. Instead received: %s