@tscircuit/runframe 0.0.249 → 0.0.251

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.
@@ -811,7 +811,7 @@ Layer: ${a.z}`,color:this.colorMap[a.connectionName]||"#000"});const t=new Map;f
811
811
  ${n.stack}`),t.complete=!0,"root"in this&&this.root&&this.root.emit("asyncEffect:end",{effectName:r,componentDisplayName:this.getString(),phase:t.phase,error:n.toString()})})}_emitRenderLifecycleEvent(r,e){Bet(`${r}:${e} ${this.getString()}`);const t=`renderable:renderLifecycle:${r}:${e}`,n={renderId:this._renderId,componentDisplayName:this.getString(),type:t};"root"in this&&this.root&&(this.root.emit(t,n),this.root.emit("renderable:renderLifecycle:anyEvent",{...n,type:t}))}getString(){return this.constructor.name}_hasIncompleteAsyncEffects(){return this._asyncEffects.some(r=>!r.complete)}getCurrentRenderPhase(){return this._currentRenderPhase}getRenderGraph(){return{id:this._renderId,currentPhase:this._currentRenderPhase,renderPhaseStates:this.renderPhaseStates,shouldBeRemoved:this.shouldBeRemoved,children:this.children.map(r=>r.getRenderGraph())}}runRenderCycle(){for(const r of h3)this.runRenderPhaseForChildren(r),this.runRenderPhase(r)}runRenderPhase(r){var a,o,s;this._currentRenderPhase=r;const e=this.renderPhaseStates[r],t=e.initialized,n=e.dirty;if(!t&&this.shouldBeRemoved)return;if(this.shouldBeRemoved&&t){this._emitRenderLifecycleEvent(r,"start"),(a=this==null?void 0:this[`remove${r}`])==null||a.call(this),e.initialized=!1,e.dirty=!1,this._emitRenderLifecycleEvent(r,"end");return}const i=h3.indexOf(r)-1;if(i>=0){const l=h3[i];if(this._asyncEffects.filter(u=>u.phase===l).some(u=>!u.complete))return}if(this._emitRenderLifecycleEvent(r,"start"),t){n&&((o=this==null?void 0:this[`update${r}`])==null||o.call(this),e.dirty=!1),this._emitRenderLifecycleEvent(r,"end");return}e.dirty=!1,(s=this==null?void 0:this[`doInitial${r}`])==null||s.call(this),e.initialized=!0,this._emitRenderLifecycleEvent(r,"end")}runRenderPhaseForChildren(r){for(const e of this.children)e.runRenderPhaseForChildren(r),e.runRenderPhase(r)}renderError(r){throw typeof r=="string"?new Error(r):new Error(JSON.stringify(r,null,2))}},IN={},hhe=r=>{const e=Object.fromEntries(Object.entries(r).map(([t,n])=>[t.toLowerCase(),n]));Object.assign(IN,r),Object.assign(IN,e)};function jet(r,e){const t=r;return t.__tsci={...e},r}var phe={supportsMutation:!0,createInstance(r,e){const t=IN[r];if(!t)throw Object.keys(IN).length===0?new Error("No components registered in catalogue, did you forget to import lib/register-catalogue in your test file?"):new Error(`Unsupported component type (not registered in @tscircuit/core catalogue): "${r}" See CREATING_NEW_COMPONENTS.md`);return jet(new t(e),{})},createTextInstance(){return{}},appendInitialChild(r,e){r.add(e)},appendChild(r,e){r.add(e)},appendChildToContainer(r,e){r.add(e)},finalizeInitialChildren(){return!1},prepareUpdate(){return null},shouldSetTextContent(){return!1},getRootHostContext(){return{}},getChildHostContext(){return{}},prepareForCommit(){return null},resetAfterCommit(){},commitMount(){},commitUpdate(){},removeChild(){},clearContainer(){},supportsPersistence:!1,getPublicInstance(r){return r},preparePortalMount(r){throw new Error("Function not implemented.")},scheduleTimeout(r,e){throw new Error("Function not implemented.")},cancelTimeout(r){throw new Error("Function not implemented.")},noTimeout:void 0,isPrimaryRenderer:!1,getInstanceFromNode(r){throw new Error("Function not implemented.")},beforeActiveInstanceBlur(){throw new Error("Function not implemented.")},afterActiveInstanceBlur(){throw new Error("Function not implemented.")},prepareScopeUpdate:(r,e)=>{throw new Error("Function not implemented.")},getInstanceFromScope:r=>{throw new Error("Function not implemented.")},detachDeletedInstance:r=>{throw new Error("Function not implemented.")},getCurrentEventPriority:()=>Pk.DefaultEventPriority,getCurrentUpdatePriority:()=>Pk.DefaultEventPriority,resolveUpdatePriority:()=>Pk.DefaultEventPriority,setCurrentUpdatePriority:()=>{},maySuspendCommit:()=>!1,supportsHydration:!1},_E;wh.version.startsWith("19.")?_E=QGe(phe):_E=nqe(phe);var mhe=r=>{const e={children:[],props:{name:"$root"},add(a){a.parent=this,this.children.push(a)},computePcbGlobalTransform(){return K_()}},t=[],n=_E.createContainer(e,0,null,!1,null,"tsci",a=>{console.log("Error in createContainer"),console.error(a),t.push(a)},null);if(wh.version.startsWith("19.")?(_E.updateContainerSync(r,n,null,()=>{}),_E.flushSyncWork()):_E.updateContainer(r,n,null,()=>{}),t.length>0)throw t[0];const i=_E.getPublicRootInstance(n);return i||e.children[0]},J6=(r,e)=>{if(typeof r=="number")return r;if(r.startsWith("pin"))return Number(r.slice(3));if(!e)throw new Error(`No pin labels provided and pin number or label is not a number: "${r}"`);for(const t in e)if((Array.isArray(e[t])?e[t]:[e[t]]).includes(r))return Number(t.replace("pin",""));throw new Error(`No pin labels provided and pin number or label is not a number: "${r}"`)},Vet=(r,e)=>{if(!r)return;const t={},n={};for(const[i,a]of Object.entries(r)){const o=J6(i,e);n[o]={...n[o],...a}}for(const[i,a]of Object.entries(n)){const o=`pin${i}`;t[o]={bottom_margin:a.bottomMargin,left_margin:a.leftMargin,right_margin:a.rightMargin,top_margin:a.topMargin}}return t},Get=r=>{if(r){if("leftSide"in r||"rightSide"in r||"topSide"in r||"bottomSide"in r)return{left_side:r.leftSide,right_side:r.rightSide,top_side:r.topSide,bottom_side:r.bottomSide};if("leftPinCount"in r||"rightPinCount"in r||"topPinCount"in r||"bottomPinCount"in r)return{left_size:r.leftPinCount,right_size:r.rightPinCount,top_size:r.topPinCount,bottom_size:r.bottomPinCount};if("leftSize"in r||"rightSize"in r||"topSize"in r||"bottomSize"in r)return{left_size:r.leftSize,right_size:r.rightSize,top_size:r.topSize,bottom_size:r.bottomSize}}},qet=class extends Error{constructor(r,e,t){let n;const a=Object.keys(t).filter(o=>o!=="_errors").map(o=>t[o]._errors[0]?`${o} (${t[o]._errors[0]})`:`${o} (${JSON.stringify(t[o])})`).join(", ");"name"in e?n=`Invalid props for ${r} "${e.name}": ${a}`:"footprint"in e&&typeof e.footprint=="string"?n=`Invalid props for ${r} (unnamed ${e.footprint} component): ${a}`:n=`Invalid props for ${r} (unnamed): ${a}`,super(n),this.componentName=r,this.originalProps=e,this.formattedError=t}};function pH(r,e){const t=e.match(/^#(\w+)/);if(t)return r.props.id===t[1];const n=e.match(/^\.(\w+)/);if(n)return r.isMatchingNameOrAlias(n[1]);let[i,...a]=e.split(/(?=[#.[])/);return i==="pin"&&(i="port"),i&&i!=="*"&&r.lowercaseComponentName!==i.toLowerCase()?!1:a.every(o=>{if(o.startsWith("#"))return r.props.id===o.slice(1);if(o.startsWith("."))return r.isMatchingNameOrAlias(o.slice(1));const s=o.match(/\[(\w+)=['"]?(.+?)['"]?\]/);if(!s)return!0;const[,l,c]=s;return r.props[l].toString()===c})}var eM=w9("tscircuit:primitive-component:selectAll"),T9=class extends dhe{constructor(e){super(e);rn(this,"parent",null);rn(this,"children");rn(this,"childrenPendingRemoval");rn(this,"props");rn(this,"_parsedProps");rn(this,"externallyAddedAliases");rn(this,"isPrimitiveContainer",!1);rn(this,"source_group_id",null);rn(this,"source_component_id",null);rn(this,"schematic_component_id",null);rn(this,"pcb_component_id",null);rn(this,"cad_component_id",null);this.children=[],this.childrenPendingRemoval=[],this.props=e??{},this.externallyAddedAliases=[];const t=this.config.zodProps.safeParse(e??{});if(t.success)this._parsedProps=t.data;else throw new qet(this.lowercaseComponentName,this.props,t.error.format())}get config(){return{componentName:"",zodProps:le.object({}).passthrough()}}get componentName(){return this.config.componentName}getInheritedProperty(e){let t=this;for(;t;){if(t._parsedProps&&e in t._parsedProps)return t._parsedProps[e];t=t.parent}}get lowercaseComponentName(){return this.componentName.toLowerCase()}get isSubcircuit(){var e;return!!this.props.subcircuit||this.lowercaseComponentName==="group"&&((e=this==null?void 0:this.parent)==null?void 0:e.isRoot)}get isGroup(){return this.lowercaseComponentName==="group"}setProps(e){var i,a;const t=this.config.zodProps.parse({...this.props,...e}),n=this.props;this.props=t,this._parsedProps=this.config.zodProps.parse(e),this.onPropsChange({oldProps:n,newProps:t,changedProps:Object.keys(e)}),(a=(i=this.parent)==null?void 0:i.onChildChanged)==null||a.call(i,this)}computePcbPropsTransform(){const{_parsedProps:e}=this;return Hd(f0(e.pcbX??0,e.pcbY??0),u3((e.pcbRotation??0)*Math.PI/180))}_computePcbGlobalTransformBeforeLayout(){var n,i,a;const{_parsedProps:e}=this,t=this.getSubcircuit()._getPcbManualPlacementForComponent(this);if(t&&this.props.pcbX===void 0&&this.props.pcbY===void 0)return Hd(((n=this.parent)==null?void 0:n._computePcbGlobalTransformBeforeLayout())??K_(),Hd(f0(t.x,t.y),u3((e.pcbRotation??0)*Math.PI/180)));if(this.isPcbPrimitive){const o=this.getPrimitiveContainer();if(o){const s=o._parsedProps.layer==="bottom",l=o._getGlobalPcbPositionBeforeLayout();if(s)return Hd(f0(l.x,l.y),Ik(),f0(-l.x,-l.y)),Hd(((i=this.parent)==null?void 0:i._computePcbGlobalTransformBeforeLayout())??K_(),Ik(),this.computePcbPropsTransform())}}return Hd(((a=this.parent)==null?void 0:a._computePcbGlobalTransformBeforeLayout())??K_(),this.computePcbPropsTransform())}getPrimitiveContainer(){var e,t;return this.isPrimitiveContainer?this:((t=(e=this.parent)==null?void 0:e.getPrimitiveContainer)==null?void 0:t.call(e))??null}_getPcbCircuitJsonBounds(){return{center:{x:0,y:0},bounds:{left:0,top:0,right:0,bottom:0},width:0,height:0}}_getPcbPrimitiveFlippedHelpers(){const e=this.getPrimitiveContainer(),t=e?e._parsedProps.layer==="bottom":!1;return{isFlipped:t,maybeFlipLayer:i=>t?i==="top"?"bottom":"top":i}}_setPositionFromLayout(e){throw new Error(`_setPositionFromLayout not implemented for ${this.componentName}`)}computeSchematicPropsTransform(){const{_parsedProps:e}=this;return Hd(f0(e.schX??0,e.schY??0))}computeSchematicGlobalTransform(){var t,n;const e=this._getSchematicGlobalManualPlacementTransform(this);return e||Hd(((n=(t=this.parent)==null?void 0:t.computeSchematicGlobalTransform)==null?void 0:n.call(t))??K_(),this.computeSchematicPropsTransform())}_getSchematicSymbolName(){const{_parsedProps:e}=this,t=this.config.schematicSymbolName;let n=e.schRotation;if(n===void 0&&(n=0),n=n%360,n<0&&(n+=360),e.schRotation!==void 0&&n%90!==0)throw new Error(`Schematic rotation ${e.schRotation} is not supported for ${this.componentName}`);const i=`${t}_horz`,a=`${t}_vert`,o=`${t}_up`,s=`${t}_down`,l=`${t}_left`,c=`${t}_right`;if(c in z3&&n===0)return c;if(o in z3&&n===90)return o;if(l in z3&&n===180)return l;if(s in z3&&n===270)return s;if(i in z3&&(n===0||n===180))return i;if(a in z3&&(n===90||n===270))return a;if(t in z3)return t}_getSchematicSymbolNameOrThrow(){const e=this._getSchematicSymbolName();if(!e)throw new Error(`No schematic symbol found (given: "${this.config.schematicSymbolName}")`);return e}getSchematicSymbol(){const e=this._getSchematicSymbolName();return e?z3[e]??null:null}_getPcbManualPlacementForComponent(e){var a;if(!this.isSubcircuit)return null;const t=this.props.layout,n=this.props.manualEdits;if(!t&&!n)return null;const i=((a=t==null?void 0:t.manual_pcb_placement_config)==null?void 0:a.positions)||(n==null?void 0:n.pcb_placements);if(!i)return null;for(const o of i)if(t&&pH(e,o.selector)||e.props.name===o.selector)return ai(this._computePcbGlobalTransformBeforeLayout(),o.center);return null}_getSchematicGlobalManualPlacementTransform(e){var n,i;const t=(n=this.getSubcircuit())==null?void 0:n._parsedProps.manualEdits;if(!t)return null;for(const a of t.schematic_placements??[])if((pH(e,a.selector)||e.props.name===a.selector)&&a.relative_to==="group_center")return Hd(((i=this.parent)==null?void 0:i._computePcbGlobalTransformBeforeLayout())??K_(),f0(a.center.x,a.center.y));return null}_getGlobalPcbPositionBeforeLayout(){return ai(this._computePcbGlobalTransformBeforeLayout(),{x:0,y:0})}_getGlobalSchematicPositionBeforeLayout(){return ai(this.computeSchematicGlobalTransform(),{x:0,y:0})}get root(){var e;return((e=this.parent)==null?void 0:e.root)??null}onAddToParent(e){this.parent=e}onPropsChange(e){}onChildChanged(e){var t,n;(n=(t=this.parent)==null?void 0:t.onChildChanged)==null||n.call(t,e)}add(e){if(!e.onAddToParent)throw new Error(`Invalid JSX Element: Expected a React component but received "${JSON.stringify(e)}"`);e.onAddToParent(this),e.parent=this,this.children.push(e)}addAll(e){for(const t of e)this.add(t)}remove(e){this.children=this.children.filter(t=>t!==e),this.childrenPendingRemoval.push(e),e.shouldBeRemoved=!0}getSubcircuitSelector(){const e=this._parsedProps.name,t=e?`${this.lowercaseComponentName}.${e}`:this.lowercaseComponentName;return!this.parent||this.parent.isSubcircuit?t:`${this.parent.getSubcircuitSelector()} > ${t}`}getFullPathSelector(){var i,a;const e=this._parsedProps.name,t=e?`${this.lowercaseComponentName}.${e}`:this.lowercaseComponentName,n=(a=(i=this.parent)==null?void 0:i.getFullPathSelector)==null?void 0:a.call(i);return n?`${n} > ${t}`:t}getNameAndAliases(){return[this._parsedProps.name,...this._parsedProps.portHints??[]].filter(Boolean)}isMatchingNameOrAlias(e){return this.getNameAndAliases().includes(e)}isMatchingAnyOf(e){return this.getNameAndAliases().some(t=>e.map(n=>n.toString()).includes(t))}getPcbSize(){throw new Error(`getPcbSize not implemented for ${this.componentName}`)}doesSelectorMatch(e){const t=[this.componentName,this.lowercaseComponentName],n=[this._parsedProps.name].filter(Boolean),i=e.trim().split(/\> /)[0],a=i[0];return i.length>1?!1:!!(e==="*"||e[0]==="#"&&e.slice(1)===this.props.id||e[0]==="."&&n.includes(e.slice(1))||/^[a-zA-Z0-9_]/.test(a)&&t.includes(a))}getSubcircuit(){var t,n;if(this.isSubcircuit)return this;const e=(n=(t=this.parent)==null?void 0:t.getSubcircuit)==null?void 0:n.call(t);if(!e)throw new Error("Component is not inside an opaque group (no board?)");return e}getGroup(){var e,t;return this.isGroup?this:((t=(e=this.parent)==null?void 0:e.getGroup)==null?void 0:t.call(e))??null}selectAll(e){eM(`selectAll: "${e}"`);const t=e.trim().split(/\s+/);let n=t[0]===">"?this.children:this.getSelectableDescendants(),i=[],a=!1,o=-1;for(const s of t)if(o++,eM(`
812
812
 
813
813
  iteration: ${o}`),eM(`part: "${t[o]}"`),eM(`currentSearch: [${n.map(l=>l.getString()).join(",")}]`),eM(`currentResults: [${i.map(l=>l.getString()).join(",")}]`),s===">")a=!0;else{const l=n.filter(u=>pH(u,s));n=l.flatMap(u=>a?u.children:u.getSelectableDescendants()),i=l,a=!1}return i}selectOne(e,t){var i;let n=(i=t==null?void 0:t.type)==null?void 0:i.toLowerCase();return t!=null&&t.port&&(n="port"),n?this.selectAll(e).find(a=>a.lowercaseComponentName===n)??null:t!=null&&t.pcbPrimitive?this.selectAll(e).find(a=>a.isPcbPrimitive)??null:t!=null&&t.schematicPrimitive?this.selectAll(e).find(a=>a.isSchematicPrimitive)??null:this.selectAll(e)[0]??null}getAvailablePcbLayers(){var e,t;if(this.isPcbPrimitive){const{maybeFlipLayer:n}=this._getPcbPrimitiveFlippedHelpers();return"layer"in this._parsedProps||this.componentName==="SmtPad"?[n(this._parsedProps.layer??"top")]:"layers"in this._parsedProps?this._parsedProps.layers:this.componentName==="PlatedHole"?((t=(e=this.root)==null?void 0:e._getBoard())==null?void 0:t.allLayers)??["top","bottom"]:[]}return[]}getDescendants(){const e=[];for(const t of this.children)e.push(t),e.push(...t.getDescendants());return e}getSelectableDescendants(){const e=[];for(const t of this.children)t.isSubcircuit?e.push(t):(e.push(t),e.push(...t.getSelectableDescendants()));return e}_getPinCount(){return 0}_getSchematicBoxDimensions(){return null}renderError(e){var t;if(typeof e=="string")return super.renderError(e);(t=this.root)==null||t.db.pcb_placement_error.insert(e)}getString(){var i,a;const{lowercaseComponentName:e,_parsedProps:t,parent:n}=this;return(t==null?void 0:t.pinNumber)!==void 0&&((i=n==null?void 0:n.props)!=null&&i.name)&&(t!=null&&t.name)?`<${e}#${this._renderId}(pin:${t.pinNumber} .${n==null?void 0:n.props.name}>.${t.name}) />`:(a=n==null?void 0:n.props)!=null&&a.name&&(t!=null&&t.name)?`<${e}#${this._renderId}(.${n==null?void 0:n.props.name}>.${t==null?void 0:t.name}) />`:t!=null&&t.from&&(t!=null&&t.to)?`<${e}#${this._renderId}(from:${t.from} to:${t==null?void 0:t.to}) />`:t!=null&&t.name?`<${e}#${this._renderId} name=".${t==null?void 0:t.name}" />`:t!=null&&t.portHints?`<${e}#${this._renderId}(${t.portHints.map(o=>`.${o}`).join(", ")}) />`:`<${e}#${this._renderId} />`}get[Symbol.toStringTag](){return this.getString()}[Symbol.for("nodejs.util.inspect.custom")](){return this.getString()}};function vhe(r){const e=[];for(let t=0;t<r.length-1;t++)e.push([r[t],r[t+1]]);return e}var Wet=le.object({name:le.string()}),yhe=class extends T9{constructor(){super(...arguments);rn(this,"source_net_id")}get config(){return{componentName:"Net",zodProps:Wet}}getPortSelector(){return`net.${this.props.name}`}doInitialSourceRender(){const{db:e}=this.root,{_parsedProps:t}=this,n=e.source_net.insert({name:t.name,member_source_group_ids:[]});this.source_net_id=n.source_net_id}doInitialSourceParentAttachment(){const e=this.getSubcircuit();if(!e)return;const{db:t}=this.root;t.source_net.update(this.source_net_id,{subcircuit_id:e.subcircuit_id})}getAllConnectedPorts(){const e=this.getSubcircuit().selectAll("port"),t=[];for(const n of e){const i=n._getDirectlyConnectedTraces();for(const a of i)if(a._isExplicitlyConnectedToNet(this)){t.push(n);break}}return t}_getAllDirectlyConnectedTraces(){const e=this.getSubcircuit().selectAll("trace"),t=[];for(const n of e)n._isExplicitlyConnectedToNet(this)&&t.push(n);return t}doInitialPcbRouteNetIslands(){var o;if((o=this.root)!=null&&o.pcbDisabled||this.getSubcircuit()._parsedProps.routingDisabled||this.getSubcircuit()._getAutorouterConfig().groupMode!=="sequential-trace")return;const{db:e}=this.root,{_parsedProps:t}=this,n=this._getAllDirectlyConnectedTraces().filter(s=>{var l;return(((l=s._portsRoutedOnPcb)==null?void 0:l.length)??0)>0}),i=[];for(const s of n){const l=s._portsRoutedOnPcb,c=i.find(u=>l.some(f=>u.ports.includes(f)));if(!c){i.push({ports:[...l],traces:[s]});continue}c.traces.push(s),c.ports.push(...l)}if(i.length===0)return;const a=vhe(i);for(const[s,l]of a){const c=s.ports.map(L=>L._getGlobalPcbPositionBeforeLayout()),u=l.ports.map(L=>L._getGlobalPcbPositionBeforeLayout());let f=1/0,v=[-1,-1];for(let L=0;L<c.length;L++){const O=c[L];for(let B=0;B<u.length;B++){const X=u[B],$=Math.sqrt((O.x-X.x)**2+(O.y-X.y)**2);$<f&&(f=$,v=[L,B])}}const _=s.ports[v[0]],x=l.ports[v[1]],M=e.toArray().filter(L=>L.type==="pcb_smtpad"||L.type==="pcb_trace"||L.type==="pcb_plated_hole"||L.type==="pcb_hole"||L.type==="source_port"||L.type==="pcb_port"),{solution:w}=RQe(M.concat([{type:"source_trace",source_trace_id:"__net_trace_tmp",connected_source_port_ids:[_.source_port_id,x.source_port_id]}])),T=w[0];if(!T){this.renderError({pcb_trace_error_id:"",pcb_trace_id:"__net_trace_tmp",pcb_component_ids:[_.pcb_component_id,x.pcb_component_id].filter(Boolean),pcb_port_ids:[_.pcb_port_id,x.pcb_port_id].filter(Boolean),type:"pcb_trace_error",error_type:"pcb_trace_error",message:`Failed to route net islands for "${this.getString()}"`,source_trace_id:"__net_trace_tmp"});return}e.pcb_trace.insert(T)}}renderError(e){var t;if(typeof e=="string")return super.renderError(e);(t=this.root)==null||t.db.pcb_trace_error.insert(e)}},ghe=(r,e)=>{for(const t of e)if(typeof t=="string"&&t.startsWith("net.")){const n=r.getSubcircuit();if(!n.selectOne(t)){const i=new yhe({name:t.split("net.")[1]});n.add(i)}}},mH=class extends T9{constructor(){super(...arguments);rn(this,"pcb_smtpad_id",null);rn(this,"matchedPort",null);rn(this,"isPcbPrimitive",!0)}get config(){return{componentName:"SmtPad",zodProps:dKe}}getPcbSize(){const{_parsedProps:e}=this;if(e.shape==="circle")return{width:e.radius*2,height:e.radius*2};if(e.shape==="rect")return{width:e.width,height:e.height};throw new Error(`getPcbSize for shape "${e.shape}" not implemented for ${this.componentName}`)}doInitialPortMatching(){var t;const e=(t=this.getPrimitiveContainer())==null?void 0:t.selectAll("port");if(this.props.portHints){for(const n of e)if(n.isMatchingAnyOf(this.props.portHints)){this.matchedPort=n,n.registerMatch(this);return}}}doInitialPcbPrimitiveRender(){var v,_,x,M,w,T,L,O,B;if((v=this.root)!=null&&v.pcbDisabled)return;const{db:e}=this.root,{_parsedProps:t}=this;if(!t.portHints)return;const n=this.getPrimitiveContainer(),i=this.getSubcircuit(),a=this._getGlobalPcbPositionBeforeLayout();n==null||n._getGlobalPcbPositionBeforeLayout();const o=zk(this._computePcbGlobalTransformBeforeLayout()),s=Math.abs(o.rotation.angle*(180/Math.PI)-90)%180<.01,{maybeFlipLayer:l}=this._getPcbPrimitiveFlippedHelpers(),c=(n==null?void 0:n._parsedProps.pcbRotation)??0;let u=null;const f=((_=this.parent)==null?void 0:_.pcb_component_id)??((x=this.getPrimitiveContainer())==null?void 0:x.pcb_component_id);t.shape==="circle"?(u=e.pcb_smtpad.insert({pcb_component_id:f,pcb_port_id:(M=this.matchedPort)==null?void 0:M.pcb_port_id,layer:l(t.layer??"top"),shape:"circle",radius:t.radius,port_hints:t.portHints.map(X=>X.toString()),x:a.x,y:a.y,subcircuit_id:(i==null?void 0:i.subcircuit_id)??void 0}),e.pcb_solder_paste.insert({layer:u.layer,shape:"circle",radius:u.radius*.7,x:u.x,y:u.y,pcb_component_id:u.pcb_component_id,pcb_smtpad_id:u.pcb_smtpad_id,subcircuit_id:(i==null?void 0:i.subcircuit_id)??void 0,pcb_group_id:((w=this.getGroup())==null?void 0:w.pcb_group_id)??void 0})):t.shape==="rect"&&(u=c===0||s?e.pcb_smtpad.insert({pcb_component_id:f,pcb_port_id:(T=this.matchedPort)==null?void 0:T.pcb_port_id,layer:l(t.layer??"top"),shape:"rect",width:s?t.height:t.width,height:s?t.width:t.height,port_hints:t.portHints.map(X=>X.toString()),x:a.x,y:a.y,subcircuit_id:(i==null?void 0:i.subcircuit_id)??void 0,pcb_group_id:((L=this.getGroup())==null?void 0:L.pcb_group_id)??void 0}):e.pcb_smtpad.insert({pcb_component_id:f,layer:t.layer??"top",shape:"rotated_rect",width:t.width,height:t.height,x:a.x,y:a.y,ccw_rotation:c,port_hints:t.portHints.map(X=>X.toString()),subcircuit_id:(i==null?void 0:i.subcircuit_id)??void 0,pcb_group_id:((O=this.getGroup())==null?void 0:O.pcb_group_id)??void 0}),u.shape==="rect"&&e.pcb_solder_paste.insert({layer:u.layer,shape:"rect",width:u.width*.7,height:u.height*.7,x:u.x,y:u.y,pcb_component_id:u.pcb_component_id,pcb_smtpad_id:u.pcb_smtpad_id,subcircuit_id:(i==null?void 0:i.subcircuit_id)??void 0,pcb_group_id:((B=this.getGroup())==null?void 0:B.pcb_group_id)??void 0})),u&&(this.pcb_smtpad_id=u.pcb_smtpad_id)}doInitialPcbPortAttachment(){var t,n;if((t=this.root)!=null&&t.pcbDisabled)return;const{db:e}=this.root;e.pcb_smtpad.update(this.pcb_smtpad_id,{pcb_port_id:(n=this.matchedPort)==null?void 0:n.pcb_port_id})}_getPcbCircuitJsonBounds(){const{db:e}=this.root,t=e.pcb_smtpad.get(this.pcb_smtpad_id);if(t.shape==="rect")return{center:{x:t.x,y:t.y},bounds:{left:t.x-t.width/2,top:t.y+t.height/2,right:t.x+t.width/2,bottom:t.y-t.height/2},width:t.width,height:t.height};if(t.shape==="rotated_rect"){const n=t.ccw_rotation*Math.PI/180,i=Math.cos(n),a=Math.sin(n),o=t.width/2,s=t.height/2,l=Math.abs(o*i)+Math.abs(s*a),c=Math.abs(o*a)+Math.abs(s*i);return{center:{x:t.x,y:t.y},bounds:{left:t.x-l,right:t.x+l,top:t.y-c,bottom:t.y+c},width:l*2,height:c*2}}if(t.shape==="circle")return{center:{x:t.x,y:t.y},bounds:{left:t.x-t.radius,top:t.y-t.radius,right:t.x+t.radius,bottom:t.y+t.radius},width:t.radius*2,height:t.radius*2};throw new Error(`circuitJson bounds calculation not implemented for shape "${t.shape}"`)}_setPositionFromLayout(e){var i;const{db:t}=this.root;t.pcb_smtpad.update(this.pcb_smtpad_id,{x:e.x,y:e.y});const n=t.pcb_solder_paste.list().find(a=>a.pcb_smtpad_id===this.pcb_smtpad_id);t.pcb_solder_paste.update(n==null?void 0:n.pcb_solder_paste_id,{x:e.x,y:e.y}),(i=this.matchedPort)==null||i._setPositionFromLayout(e)}},_he=class extends T9{constructor(){super(...arguments);rn(this,"pcb_silkscreen_path_id",null);rn(this,"isPcbPrimitive",!0)}get config(){return{componentName:"SilkscreenPath",zodProps:UKe}}doInitialPcbPrimitiveRender(){var l,c,u;if((l=this.root)!=null&&l.pcbDisabled)return;const{db:e}=this.root,{_parsedProps:t}=this,{maybeFlipLayer:n}=this._getPcbPrimitiveFlippedHelpers(),i=n(t.layer??"top");if(i!=="top"&&i!=="bottom")throw new Error(`Invalid layer "${i}" for SilkscreenPath. Must be "top" or "bottom".`);const a=this._computePcbGlobalTransformBeforeLayout(),o=this.getSubcircuit(),s=e.pcb_silkscreen_path.insert({pcb_component_id:(c=this.parent)==null?void 0:c.pcb_component_id,layer:i,route:t.route.map(f=>{const v=ai(a,{x:f.x,y:f.y});return{...f,x:v.x,y:v.y}}),stroke_width:t.strokeWidth??.1,subcircuit_id:(o==null?void 0:o.subcircuit_id)??void 0,pcb_group_id:((u=this.getGroup())==null?void 0:u.pcb_group_id)??void 0});this.pcb_silkscreen_path_id=s.pcb_silkscreen_path_id}getPcbSize(){const{_parsedProps:e}=this;if(!e.route||e.route.length===0)return{width:0,height:0};let t=1/0,n=-1/0,i=1/0,a=-1/0;for(const o of e.route)t=Math.min(t,o.x),n=Math.max(n,o.x),i=Math.min(i,o.y),a=Math.max(a,o.y);return{width:n-t,height:a-i}}},xhe=class extends T9{constructor(){super(...arguments);rn(this,"pcb_plated_hole_id",null);rn(this,"matchedPort",null);rn(this,"isPcbPrimitive",!0)}get config(){return{componentName:"PlatedHole",zodProps:QQe}}getAvailablePcbLayers(){return["top","inner1","inner2","bottom"]}getPcbSize(){const{_parsedProps:e}=this;if(e.shape==="circle")return{width:e.outerDiameter,height:e.outerDiameter};if(e.shape==="oval"||e.shape==="pill")return{width:e.outerWidth,height:e.outerHeight};throw new Error(`getPcbSize for shape "${e.shape}" not implemented for ${this.componentName}`)}_getPcbCircuitJsonBounds(){const{db:e}=this.root,t=e.pcb_plated_hole.get(this.pcb_plated_hole_id),n=this.getPcbSize();return{center:{x:t.x,y:t.y},bounds:{left:t.x-n.width/2,top:t.y+n.height/2,right:t.x+n.width/2,bottom:t.y-n.height/2},width:n.width,height:n.height}}_setPositionFromLayout(e){var n;const{db:t}=this.root;t.pcb_plated_hole.update(this.pcb_plated_hole_id,{x:e.x,y:e.y}),(n=this.matchedPort)==null||n._setPositionFromLayout(e)}doInitialPortMatching(){var t;const e=(t=this.getPrimitiveContainer())==null?void 0:t.selectAll("port");if(this.props.portHints){for(const n of e)if(n.isMatchingAnyOf(this.props.portHints)){this.matchedPort=n,n.registerMatch(this);return}}}doInitialPcbPrimitiveRender(){var o,s,l,c,u,f,v;if((o=this.root)!=null&&o.pcbDisabled)return;const{db:e}=this.root,{_parsedProps:t}=this,n=this._getGlobalPcbPositionBeforeLayout(),i=((s=this.parent)==null?void 0:s.pcb_component_id)??((l=this.getPrimitiveContainer())==null?void 0:l.pcb_component_id),a=this.getSubcircuit();if(t.shape==="circle"){const _=e.pcb_plated_hole.insert({pcb_component_id:i,pcb_port_id:(c=this.matchedPort)==null?void 0:c.pcb_port_id,outer_diameter:t.outerDiameter,hole_diameter:t.holeDiameter,shape:"circle",port_hints:this.getNameAndAliases(),x:n.x,y:n.y,layers:["top","bottom"],subcircuit_id:(a==null?void 0:a.subcircuit_id)??void 0,pcb_group_id:((u=this.getGroup())==null?void 0:u.pcb_group_id)??void 0});this.pcb_plated_hole_id=_.pcb_plated_hole_id}else if(t.shape==="pill"||t.shape==="oval"){const _=e.pcb_plated_hole.insert({pcb_component_id:i,pcb_port_id:(f=this.matchedPort)==null?void 0:f.pcb_port_id,outer_width:t.outerWidth,outer_height:t.outerHeight,hole_width:t.innerWidth,hole_height:t.innerHeight,shape:t.shape,port_hints:this.getNameAndAliases(),x:n.x,y:n.y,layers:["top","bottom"],subcircuit_id:(a==null?void 0:a.subcircuit_id)??void 0,pcb_group_id:((v=this.getGroup())==null?void 0:v.pcb_group_id)??void 0});this.pcb_plated_hole_id=_.pcb_plated_hole_id}}doInitialPcbPortAttachment(){var t,n;if((t=this.root)!=null&&t.pcbDisabled)return;const{db:e}=this.root;e.pcb_plated_hole.update(this.pcb_plated_hole_id,{pcb_port_id:(n=this.matchedPort)==null?void 0:n.pcb_port_id})}},vH=class extends T9{constructor(){super(...arguments);rn(this,"pcb_keepout_id",null);rn(this,"isPcbPrimitive",!0)}get config(){return{componentName:"Keepout",zodProps:DKe}}doInitialPcbPrimitiveRender(){var l,c,u;if((l=this.root)!=null&&l.pcbDisabled)return;const e=this.getSubcircuit(),{db:t}=this.root,{_parsedProps:n}=this,i=this._getGlobalPcbPositionBeforeLayout(),a=zk(this._computePcbGlobalTransformBeforeLayout()),o=Math.abs(a.rotation.angle*(180/Math.PI)-90)%180<.01;let s=null;n.shape==="circle"?s=t.pcb_keepout.insert({layers:["top"],shape:"circle",radius:n.radius,center:{x:i.x,y:i.y},subcircuit_id:(e==null?void 0:e.subcircuit_id)??void 0,pcb_group_id:((c=e==null?void 0:e.getGroup())==null?void 0:c.pcb_group_id)??void 0}):n.shape==="rect"&&(s=t.pcb_keepout.insert({layers:["top"],shape:"rect",...o?{width:n.height,height:n.width}:{width:n.width,height:n.height},center:{x:i.x,y:i.y},subcircuit_id:(e==null?void 0:e.subcircuit_id)??void 0,pcb_group_id:((u=e==null?void 0:e.getGroup())==null?void 0:u.pcb_group_id)??void 0})),s&&(this.pcb_keepout_id=s.pcb_keepout_id)}},bhe=class extends T9{constructor(){super(...arguments);rn(this,"pcb_hole_id",null);rn(this,"isPcbPrimitive",!0)}get config(){return{componentName:"Hole",zodProps:mKe}}getPcbSize(){const{_parsedProps:e}=this;return{width:e.diameter,height:e.diameter}}doInitialPcbPrimitiveRender(){var o,s;if((o=this.root)!=null&&o.pcbDisabled)return;const{db:e}=this.root,{_parsedProps:t}=this,n=this.getSubcircuit(),i=this._getGlobalPcbPositionBeforeLayout(),a=e.pcb_hole.insert({hole_shape:"circle",hole_diameter:t.diameter,x:i.x,y:i.y,subcircuit_id:(n==null?void 0:n.subcircuit_id)??void 0,pcb_group_id:((s=n==null?void 0:n.getGroup())==null?void 0:s.pcb_group_id)??void 0});this.pcb_hole_id=a.pcb_hole_id}_getPcbCircuitJsonBounds(){const{db:e}=this.root,t=e.pcb_hole.get(this.pcb_hole_id),n=this.getPcbSize();return{center:{x:t.x,y:t.y},bounds:{left:t.x-n.width/2,top:t.y-n.height/2,right:t.x+n.width/2,bottom:t.y+n.height/2},width:n.width,height:n.height}}_setPositionFromLayout(e){const{db:t}=this.root;t.pcb_hole.update(this.pcb_hole_id,{x:e.x,y:e.y})}},She=class extends T9{constructor(){super(...arguments);rn(this,"isPcbPrimitive",!0)}get config(){return{componentName:"SilkscreenText",zodProps:OKe}}doInitialPcbPrimitiveRender(){var s,l;if((s=this.root)!=null&&s.pcbDisabled)return;const{db:e}=this.root,{_parsedProps:t}=this,n=this.getPrimitiveContainer(),i=this._getGlobalPcbPositionBeforeLayout(),{maybeFlipLayer:a}=this._getPcbPrimitiveFlippedHelpers(),o=this.getSubcircuit();e.pcb_silkscreen_text.insert({anchor_alignment:t.anchorAlignment,anchor_position:{x:i.x,y:i.y},font:t.font??"tscircuit2024",font_size:t.fontSize??1,layer:a(t.layer??"top"),text:t.text??"",ccw_rotation:t.pcbRotation,pcb_component_id:n.pcb_component_id,subcircuit_id:(o==null?void 0:o.subcircuit_id)??void 0,pcb_group_id:((l=this.getGroup())==null?void 0:l.pcb_group_id)??void 0})}getPcbSize(){const{_parsedProps:e}=this,t=e.fontSize??1,i=(e.text??"").length*t,a=t;return{width:i*t,height:a*t}}},Yet=({componentName:r,componentRotation:e},t)=>{const n=[];for(const i of t)if(i.type==="pcb_smtpad"&&i.shape==="rect")n.push(new mH({pcbX:i.x,pcbY:i.y,layer:i.layer,shape:"rect",height:i.height,width:i.width,portHints:i.port_hints}));else if(i.type==="pcb_smtpad"&&i.shape==="circle")n.push(new mH({pcbX:i.x,pcbY:i.y,layer:i.layer,shape:"circle",radius:i.radius,portHints:i.port_hints}));else if(i.type==="pcb_silkscreen_path")n.push(new _he({layer:i.layer,route:i.route,strokeWidth:i.stroke_width}));else if(i.type==="pcb_plated_hole"&&i.shape==="circle")i.shape==="circle"&&n.push(new xhe({pcbX:i.x,pcbY:i.y,shape:"circle",holeDiameter:i.hole_diameter,outerDiameter:i.outer_diameter,portHints:i.port_hints}));else if(i.type==="pcb_keepout"&&i.shape==="circle")n.push(new vH({pcbX:i.center.x,pcbY:i.center.y,shape:"circle",radius:i.radius}));else if(i.type==="pcb_keepout"&&i.shape==="rect")n.push(new vH({pcbX:i.center.x,pcbY:i.center.y,shape:"rect",width:i.width,height:i.height}));else if(i.type==="pcb_hole"&&i.hole_shape==="circle")n.push(new bhe({pcbX:i.x,pcbY:i.y,diameter:i.hole_diameter}));else if(i.type==="pcb_silkscreen_text"){let a=e?parseInt(e):0;const o=(a%360+360)%360;a=o>90&&o<=270?(o+180)%360:o,n.push(new She({anchorAlignment:"center",text:r,fontSize:i.font_size+.2,pcbX:isNaN(i.anchor_position.x)?0:i.anchor_position.x,pcbY:i.anchor_position.y,pcbRotation:a??0}))}return n};function Ehe(r){let e=1/0,t=1/0,n=-1/0,i=-1/0;for(const s of r)if(s.isPcbPrimitive&&!s.componentName.startsWith("Silkscreen")){const{x:l,y:c}=s._getGlobalPcbPositionBeforeLayout(),{width:u,height:f}=s.getPcbSize();e=Math.min(e,l-u/2),t=Math.min(t,c-f/2),n=Math.max(n,l+u/2),i=Math.max(i,c+f/2)}else if(s.componentName==="Footprint"){const l=Ehe(s.children);e=Math.min(e,l.minX),t=Math.min(t,l.minY),n=Math.max(n,l.maxX),i=Math.max(i,l.maxY)}let a=n-e,o=i-t;return a<0&&(a=0),o<0&&(o=0),{minX:e,minY:t,maxX:n,maxY:i,width:a,height:o}}function Xet(r,e){const t=e.x-r.x,n=e.y-r.y;return Math.abs(t)>Math.abs(n)?t>=0?"right":"left":n>=0?"up":"down"}var $et=r=>{if(r.length<=1)return!0;const e=r.map(a=>{const o=a._getPcbCircuitJsonBounds();return{left:o.bounds.left,right:o.bounds.right,top:o.bounds.top,bottom:o.bounds.bottom}}),t=Array(e.length).fill(!1).map(()=>Array(e.length).fill(!1));for(let a=0;a<e.length;a++)for(let o=a+1;o<e.length;o++){const s=e[a],l=e[o];t[a][o]=t[o][a]=!(s.right<l.left||s.left>l.right||s.bottom>l.top||s.top<l.bottom)}const n=new Set,i=a=>{n.add(a);for(let o=0;o<e.length;o++)t[a][o]&&!n.has(o)&&i(o)};return i(0),n.size===e.length},Zet=r=>{if(r.length===0)throw new Error("Cannot get center of empty PCB primitives array");const e=r.map(i=>i._getPcbCircuitJsonBounds().center).filter(Boolean),t=e.reduce((i,a)=>i+a.x,0),n=e.reduce((i,a)=>i+a.y,0);return{x:t/e.length,y:n/e.length}},Qet=le.object({name:le.string().optional(),pinNumber:le.number().optional(),aliases:le.array(le.string()).optional()}),TS=class extends T9{constructor(e,t={}){if(!e.name&&e.pinNumber!==void 0&&(e.name=`pin${e.pinNumber}`),!e.name)throw new Error("Port must have a name or a pinNumber");super(e);rn(this,"source_port_id",null);rn(this,"pcb_port_id",null);rn(this,"schematic_port_id",null);rn(this,"schematicSymbolPortDef",null);rn(this,"matchedComponents");rn(this,"facingDirection",null);rn(this,"originDescription",null);t.originDescription&&(this.originDescription=t.originDescription),this.matchedComponents=[]}get config(){return{componentName:"Port",zodProps:Qet}}_getGlobalPcbPositionBeforeLayout(){const e=this.matchedComponents.find(n=>n.isPcbPrimitive),t=this.parent;if(t&&!t.props.footprint)throw new Error(`${t.componentName} "${t.props.name}" does not have a footprint. Add a footprint prop, e.g. <${t.componentName.toLowerCase()} footprint="..." />`);if(!e)throw new Error(`Port ${this} has no matching PCB primitives. This often means the footprint's pads lack matching port hints.`);return(e==null?void 0:e._getGlobalPcbPositionBeforeLayout())??{x:0,y:0}}_getPcbCircuitJsonBounds(){if(!this.pcb_port_id)return super._getPcbCircuitJsonBounds();const{db:e}=this.root,t=e.pcb_port.get(this.pcb_port_id);return{center:{x:t.x,y:t.y},bounds:{left:0,top:0,right:0,bottom:0},width:0,height:0}}_getGlobalPcbPositionAfterLayout(){return this._getPcbCircuitJsonBounds().center}_getPortsInternallyConnectedToThisPort(){const e=this.parent;if(!e||!e._getInternallyConnectedPins)return[];const t=e._getInternallyConnectedPins();for(const n of t)if(n.some(i=>i===this))return n;return[]}_hasSchematicPort(){var n,i;if((n=this.parent)==null?void 0:n.getSchematicSymbol())return!!(this.schematicSymbolPortDef||this._getPortsInternallyConnectedToThisPort().some(o=>o.schematicSymbolPortDef));const t=(i=this==null?void 0:this.parent)==null?void 0:i._getSchematicBoxDimensions();return!!(t&&this.props.pinNumber!==void 0&&t.getPortPositionByPinNumber(this.props.pinNumber))}_getGlobalSchematicPositionBeforeLayout(){var n,i,a;const e=(n=this.parent)==null?void 0:n.getSchematicSymbol();if(e){let o=this.schematicSymbolPortDef;if(!o&&(o=((i=this._getPortsInternallyConnectedToThisPort().find(l=>l.schematicSymbolPortDef))==null?void 0:i.schematicSymbolPortDef)??null,!o))throw new Error(`Couldn't find schematicSymbolPortDef for port ${this.getString()}, searched internally connected ports and none had a schematicSymbolPortDef. Why are we trying to get the schematic position of this port?`);const s=Hd(this.parent.computeSchematicGlobalTransform(),f0(-e.center.x,-e.center.y));return ai(s,o)}const t=(a=this==null?void 0:this.parent)==null?void 0:a._getSchematicBoxDimensions();if(t&&this.props.pinNumber!==void 0){const o=t.getPortPositionByPinNumber(this.props.pinNumber);if(!o)throw new Error(`Couldn't find position for schematic_port for port ${this.getString()} inside of the schematic box`);return ai(this.parent.computeSchematicGlobalTransform(),o)}throw new Error(`Couldn't find position for schematic_port for port ${this.getString()}`)}_getGlobalSchematicPositionAfterLayout(){const{db:e}=this.root;if(!this.schematic_port_id)throw new Error("Can't get schematic port position after layout, no schematic_port_id");const t=e.schematic_port.get(this.schematic_port_id);if(!t)throw new Error(`Schematic port not found when trying to get post-layout position: ${this.schematic_port_id}`);return t.center}registerMatch(e){this.matchedComponents.push(e)}getNameAndAliases(){const{_parsedProps:e}=this;return Array.from(new Set([...e.aliases??[],...e.name?[e.name]:[],...typeof e.pinNumber=="number"?[`pin${e.pinNumber}`,e.pinNumber.toString()]:[],...this.externallyAddedAliases??[]]))}isMatchingPort(e){return this.isMatchingAnyOf(e.getNameAndAliases())}getPortSelector(){var e;return`.${(e=this.parent)==null?void 0:e.props.name} > port.${this.props.name}`}getAvailablePcbLayers(){return Array.from(new Set(this.matchedComponents.flatMap(e=>e.getAvailablePcbLayers())))}_getDirectlyConnectedTraces(){return this.getSubcircuit().selectAll("trace").filter(n=>n._isExplicitlyConnectedToPort(this))}doInitialSourceRender(){var a,o;const{db:e}=this.root,{_parsedProps:t}=this,n=this.getNameAndAliases(),i=e.source_port.insert({name:t.name,pin_number:t.pinNumber,port_hints:n,source_component_id:(a=this.parent)==null?void 0:a.source_component_id,subcircuit_id:(o=this.getSubcircuit())==null?void 0:o.subcircuit_id});this.source_port_id=i.source_port_id}doInitialSourceParentAttachment(){var t,n,i,a,o;const{db:e}=this.root;if(!((t=this.parent)!=null&&t.source_component_id))throw new Error(`${this.getString()} has no parent source component (parent: ${(n=this.parent)==null?void 0:n.getString()})`);e.source_port.update(this.source_port_id,{source_component_id:(i=this.parent)==null?void 0:i.source_component_id,subcircuit_id:(a=this.getSubcircuit())==null?void 0:a.subcircuit_id}),this.source_component_id=(o=this.parent)==null?void 0:o.source_component_id}doInitialPcbPortRender(){var a,o,s,l,c;if((a=this.root)!=null&&a.pcbDisabled)return;const{db:e}=this.root,{matchedComponents:t}=this;if(!((o=this.parent)!=null&&o.pcb_component_id))throw new Error(`${this.getString()} has no parent pcb component, cannot render pcb_port (parent: ${(s=this.parent)==null?void 0:s.getString()})`);const n=t.filter(u=>u.isPcbPrimitive);if(n.length===0)return;let i=null;if(n.length===1&&(i=n[0]._getPcbCircuitJsonBounds().center),n.length>1){if(!$et(n))throw new Error(`${this.getString()} has multiple non-overlapping pcb matches, unclear how to place pcb_port: ${n.map(u=>u.getString()).join(", ")}. (Note: tscircuit core does not currently allow you to specify internally connected pcb primitives with the same port hints, try giving them different port hints and specifying they are connected externally- or file an issue)`);i=Zet(n)}if(i){const u=this.getSubcircuit(),f=e.pcb_port.insert({pcb_component_id:(l=this.parent)==null?void 0:l.pcb_component_id,layers:this.getAvailablePcbLayers(),subcircuit_id:(u==null?void 0:u.subcircuit_id)??void 0,pcb_group_id:((c=this.getGroup())==null?void 0:c.pcb_group_id)??void 0,...i,source_port_id:this.source_port_id});this.pcb_port_id=f.pcb_port_id}else{const u=n[0];throw new Error(`${u.getString()} does not have a center or _getGlobalPcbPositionBeforeLayout method (needed for pcb_port placement)`)}}doInitialSchematicPortRender(){var f;const{db:e}=this.root,{_parsedProps:t}=this,n=this.getPrimitiveContainer();if(!n||!this._hasSchematicPort())return;const i=n._getGlobalSchematicPositionBeforeLayout(),a=this._getGlobalSchematicPositionBeforeLayout();let o=null;const s=n._getSchematicBoxDimensions();s&&t.pinNumber!==void 0&&(o=s.getPortPositionByPinNumber(t.pinNumber)),this.getSubcircuit().props._schDebugObjectsEnabled&&e.schematic_debug_object.insert({shape:"rect",center:a,size:{width:.1,height:.1},label:"obstacle"}),o!=null&&o.side?this.facingDirection={left:"left",right:"right",top:"up",bottom:"down"}[o.side]:this.facingDirection=Xet(i,a);const l=e.source_port.get(this.source_port_id);let c;for(const v of(l==null?void 0:l.port_hints)??[])v.match(/^(pin)?\d+$/)||(c=v);const u=e.schematic_port.insert({schematic_component_id:(f=this.parent)==null?void 0:f.schematic_component_id,center:a,source_port_id:this.source_port_id,facing_direction:this.facingDirection,distance_from_component_edge:.4,side_of_component:o==null?void 0:o.side,pin_number:t.pinNumber,true_ccw_index:o==null?void 0:o.trueIndex,display_pin_label:c});this.schematic_port_id=u.schematic_port_id}_setPositionFromLayout(e){const{db:t}=this.root;this.pcb_port_id&&t.pcb_port.update(this.pcb_port_id,{x:e.x,y:e.y})}_hasMatchedPcbPrimitive(){return this.matchedComponents.some(e=>e.isPcbPrimitive)}},whe=r=>{const e=r.find(t=>/^(pin)?\d+$/.test(t));return e?Number.parseInt(e.replace(/^pin/,"")):null};function tM(r,e){var a;const t=whe(r);if(!t)return null;const i=[...r.filter(o=>o.toString()!==t.toString()&&o!==`pin${t}`),...((a=e==null?void 0:e.additionalAliases)==null?void 0:a[`pin${t}`])??[]];return new TS({pinNumber:t,aliases:i})}var Ket=r=>{for(const e of["leftSide","rightSide","topSide","bottomSide"])if(e in r&&typeof r[e]=="number")throw new Error(`A number was specified for "${e}", you probably meant to use "size" not "side"`);return"leftSide"in r||"rightSide"in r||"topSide"in r||"bottomSide"in r},Jet=r=>{var a,o,s,l;if(Ket(r))return{leftSize:((a=r.leftSide)==null?void 0:a.pins.length)??0,rightSize:((o=r.rightSide)==null?void 0:o.pins.length)??0,topSize:((s=r.topSide)==null?void 0:s.pins.length)??0,bottomSize:((l=r.bottomSide)==null?void 0:l.pins.length)??0};const{leftSize:e=0,rightSize:t=0,topSize:n=0,bottomSize:i=0}=r;return{leftSize:e,rightSize:t,topSize:n,bottomSize:i}};function The(r){return r.leftSide!==void 0}var ett=r=>{var w,T,L,O,B,X,$,Q;const e=r.portDistanceFromEdge??.4;let t=r.schPortArrangement?Jet(r.schPortArrangement):null;const n={left:0,right:0,top:0,bottom:0};let i=r.pinCount??null;if(i===null)if(t)i=t.leftSize+t.rightSize+t.topSize;else throw new Error("Could not determine pin count for the schematic box");if(i&&!t){const ee=Math.floor(i/2);t={leftSize:i-ee,rightSize:ee,topSize:0,bottomSize:0}}t||(t={leftSize:0,rightSize:0,topSize:0,bottomSize:0});const a=({side:ee,sideIndex:ae,truePinIndex:K})=>{var Oe,we,Le,Te;if(!r.schPortArrangement||!The(r.schPortArrangement))return K+1;const pe={left:"top-to-bottom",bottom:"left-to-right",right:"bottom-to-top",top:"right-to-left"}[ee],me=((we=(Oe=r.schPortArrangement)==null?void 0:Oe[`${ee}Side`])==null?void 0:we.direction)??pe,be=(Te=(Le=r.schPortArrangement)==null?void 0:Le[`${ee}Side`])==null?void 0:Te.pins;let Ae=ae;return me!==pe&&(Ae=be.length-ae-1),J6(be[Ae],r.pinLabels)},o=[];let s=0,l=0;for(let ee=0;ee<t.leftSize;ee++){const ae=a({side:"left",sideIndex:ee,truePinIndex:l}),K=((w=r.numericSchPinStyle)==null?void 0:w[`pin${ae}`])??((T=r.numericSchPinStyle)==null?void 0:T[ae]);K!=null&&K.topMargin&&(s+=K.topMargin),o.push({trueIndex:l,pinNumber:ae,side:"left",distanceFromOrthogonalEdge:s}),K!=null&&K.bottomMargin&&(s+=K.bottomMargin),ee===t.leftSize-1?n.left=s:s+=r.schPinSpacing,l++}s=0;for(let ee=0;ee<t.bottomSize;ee++){const ae=a({side:"bottom",sideIndex:ee,truePinIndex:l}),K=((L=r.numericSchPinStyle)==null?void 0:L[`pin${ae}`])??((O=r.numericSchPinStyle)==null?void 0:O[ae]);K!=null&&K.leftMargin&&(s+=K.leftMargin),o.push({trueIndex:l,pinNumber:ae,side:"bottom",distanceFromOrthogonalEdge:s}),K!=null&&K.rightMargin&&(s+=K.rightMargin),ee===t.bottomSize-1?n.bottom=s:s+=r.schPinSpacing,l++}s=0;for(let ee=0;ee<t.rightSize;ee++){const ae=a({side:"right",sideIndex:ee,truePinIndex:l}),K=((B=r.numericSchPinStyle)==null?void 0:B[`pin${ae}`])??((X=r.numericSchPinStyle)==null?void 0:X[ae]);K!=null&&K.bottomMargin&&(s+=K.bottomMargin),o.push({trueIndex:l,pinNumber:ae,side:"right",distanceFromOrthogonalEdge:s}),K!=null&&K.topMargin&&(s+=K.topMargin),ee===t.rightSize-1?n.right=s:s+=r.schPinSpacing,l++}s=0;for(let ee=0;ee<t.topSize;ee++){const ae=a({side:"top",sideIndex:ee,truePinIndex:l}),K=(($=r.numericSchPinStyle)==null?void 0:$[`pin${ae}`])??((Q=r.numericSchPinStyle)==null?void 0:Q[ae]);K!=null&&K.rightMargin&&(s+=K.rightMargin),o.push({trueIndex:l,pinNumber:ae,side:"top",distanceFromOrthogonalEdge:s}),K!=null&&K.leftMargin&&(s+=K.leftMargin),ee===t.topSize-1?n.top=s:s+=r.schPinSpacing,l++}let c=r.schWidth;c||(c=Math.max(n.top+r.schPinSpacing*2,n.bottom+r.schPinSpacing*2));const u=r.pinLabels?Math.max(...Object.values(r.pinLabels).map(ee=>ee.length*.1)):0,f=u>0?1.1:0;c=Math.max(c,u+f);let v=r.schHeight;v||(v=Math.max(n.left+r.schPinSpacing*2,n.right+r.schPinSpacing*2));const _={left:{x:-c/2-e,y:n.left/2},bottom:{x:-n.bottom/2,y:-v/2-e},right:{x:c/2+e,y:-n.right/2},top:{x:n.top/2,y:v/2+e}},x={left:{x:0,y:-1},right:{x:0,y:1},top:{x:-1,y:0},bottom:{x:1,y:0}},M=o.map(ee=>{const{distanceFromOrthogonalEdge:ae,side:K}=ee,pe=_[K],me=x[K];return{x:pe.x+ae*me.x,y:pe.y+ae*me.y,...ee}});return{getPortPositionByPinNumber(ee){const ae=M.find(K=>K.pinNumber.toString()===ee.toString());return ae||null},getSize(){return{width:c,height:v}},getSizeIncludingPins(){return{width:c+(t.leftSize||t.rightSize?.4:0),height:v+(t.topSize||t.bottomSize?.4:0)}},pinCount:i}},ttt=w9("tscircuit:core:footprint"),ntt=class extends T9{get config(){return{componentName:"Footprint",zodProps:yKe}}doInitialPcbFootprintLayout(){var f,v,_,x,M;if((f=this.root)!=null&&f.pcbDisabled)return;const r=this.children.filter(w=>w.componentName==="Constraint");if(r.length===0)return;const{isFlipped:e}=this._getPcbPrimitiveFlippedHelpers(),t=w=>e&&"left"in w&&"right"in w?{...w,left:w.right,right:w.left}:w,n=r.flatMap(w=>w._getAllReferencedComponents().componentsWithSelectors).map(({component:w,selector:T,componentSelector:L,edge:O})=>({component:w,selector:T,componentSelector:L,edge:O,bounds:w._getPcbCircuitJsonBounds()}));if(n.some(w=>w.edge))throw new Error("edge constraints not implemented yet for footprint layout, contributions welcome!");function i(w){return n.find(({selector:T})=>T===w)}const a=new VKe,o={};function s(w){return w in o||(o[w]=new iH(w),a.addEditVariable(o[w],t5.weak)),o[w]}for(const{selector:w,bounds:T}of n){const L=s(`${w}_x`),O=s(`${w}_y`);a.suggestValue(L,T.center.x),a.suggestValue(O,T.center.y)}for(const w of r){const T=w._parsedProps;if("xDist"in T){const{xDist:L,left:O,right:B,edgeToEdge:X,centerToCenter:$}=t(T),Q=s(`${O}_x`),ee=s(`${B}_x`),ae=(v=i(O))==null?void 0:v.bounds,K=(_=i(B))==null?void 0:_.bounds;if($){const pe=new vx(ee,[-1,Q]);a.addConstraint(new _4(pe,f3.Eq,T.xDist,t5.required))}else if(X){const pe=new vx(ee,-K.width/2,[-1,Q],-ae.width/2);a.addConstraint(new _4(pe,f3.Eq,T.xDist,t5.required))}}else if("yDist"in T){const{yDist:L,top:O,bottom:B,edgeToEdge:X,centerToCenter:$}=T,Q=s(`${O}_y`),ee=s(`${B}_y`),ae=(x=i(O))==null?void 0:x.bounds,K=(M=i(B))==null?void 0:M.bounds;if($){const pe=new vx(Q,[-1,ee]);a.addConstraint(new _4(pe,f3.Eq,T.yDist,t5.required))}else if(X){const pe=new vx(Q,ae.height/2,[-1,ee],-K.height/2);a.addConstraint(new _4(pe,f3.Eq,T.yDist,t5.required))}}else if("sameY"in T){const{for:L}=T;if(L.length<2)continue;const O=L.map(X=>s(`${X}_y`)),B=new vx(...O.slice(1));a.addConstraint(new _4(B,f3.Eq,O[0],t5.required))}else if("sameX"in T){const{for:L}=T;if(L.length<2)continue;const O=L.map(X=>s(`${X}_x`)),B=new vx(...O.slice(1));a.addConstraint(new _4(B,f3.Eq,O[0],t5.required))}}a.updateVariables(),ttt.enabled&&(console.log("Solution to layout constraints:"),console.table(Object.entries(o).map(([w,T])=>({var:w,val:T.value()}))));const l={left:1/0,right:-1/0,top:-1/0,bottom:1/0};for(const{selector:w,bounds:{width:T,height:L}}of n){const O=s(`${w}_x`),B=s(`${w}_y`),X=O.value()-T/2,$=O.value()+T/2,Q=B.value()+L/2,ee=B.value()-L/2;l.left=Math.min(l.left,X),l.right=Math.max(l.right,$),l.top=Math.max(l.top,Q),l.bottom=Math.min(l.bottom,ee)}const c={x:-(l.right+l.left)/2,y:-(l.top+l.bottom)/2},u=this.getPrimitiveContainer()._getGlobalPcbPositionBeforeLayout();c.x+=u.x,c.y+=u.y;for(const{component:w,selector:T}of n){const L=s(`${T}_x`),O=s(`${T}_y`);w._setPositionFromLayout({x:L.value()+c.x,y:O.value()+c.y})}}},rtt=(r,e)=>{if(!r)return;const t={};for(const[n,i]of Object.entries(r)){const a=J6(n,e),o={leftMargin:i.marginLeft??i.leftMargin,rightMargin:i.marginRight??i.rightMargin,topMargin:i.marginTop??i.topMargin,bottomMargin:i.marginBottom??i.bottomMargin};t[`pin${a}`]={...t[`pin${a}`],...o}}return t},Mhe=class{constructor({input:r}){rn(this,"input");this.input=r}solveAndMapToTraces(){const r=[];for(const e of this.input.connections){if(e.pointsToConnect.length!==2)continue;const[t,n]=e.pointsToConnect,i={type:"pcb_trace",pcb_trace_id:"",connection_name:e.name,route:[{route_type:"wire",x:t.x,y:t.y,layer:"top",width:.1},{route_type:"wire",x:n.x,y:n.y,layer:"top",width:.1}]};r.push(i)}return r}},itt=r=>{const e=Math.min(...r.map(a=>a.center.x)),t=Math.max(...r.map(a=>a.center.x)),n=Math.min(...r.map(a=>a.center.y)),i=Math.max(...r.map(a=>a.center.y));return{minX:e,maxX:t,minY:n,maxY:i}},Che=["top","bottom","inner1","inner2"],kN=(r,e=[])=>{var s;const t=[];if(e.length===0){const l=r[0].layers;for(const c of l)t.push(...kN(r.slice(1),[c]));return t}if(r.length===0)return[];const n=r[0],i=n.via||n.optional_via,a=e[e.length-1];if(r.length===1){const l=n;return l.layers&&i?l.layers.map(c=>({layer_path:[...e,c]})):(s=l.layers)!=null&&s.includes(a)?[{layer_path:[...e,a]}]:[]}if(!i)return n.layers&&!n.layers.includes(a)?[]:kN(r.slice(1),e.concat([a]));const o=(n.optional_via?Che:Che.filter(l=>l!==a)).filter(l=>{var c;return!n.layers||((c=n.layers)==null?void 0:c.includes(l))});for(const l of o)t.push(...kN(r.slice(1),e.concat(l)));return t};function Rhe(r){const e={x:r.to.x-r.from.x,y:r.to.y-r.from.y},t=Math.abs(e.x),n=Math.abs(e.y);return t>n?e.x>0?"right":"left":e.y>0?"down":"up"}function fT(r,e){return Math.hypot(r.x-e.x,r.y-e.y)}var att=r=>{if(r.length===1)return r[0];if(r.some(l=>l.length===0))throw new Error("Cannot merge routes with zero length");const e=[],t=r[0][0],n=r[0][r[0].length-1],i=r[1][0],a=r[1][r[1].length-1],o=Math.min(fT(t,i),fT(t,a)),s=Math.min(fT(n,i),fT(n,a));o<s?e.push(...r[0].reverse()):e.push(...r[0]);for(let l=1;l<r.length;l++){const c=e[e.length-1],u=r[l],f=u[0],v=u[u.length-1],_=fT(c,f),x=fT(c,v);_<x?e.push(...u):e.push(...u.reverse())}for(let l=1;l<e.length-1;l++){const c=e[l-1],u=e[l];c.route_type==="wire"&&u.route_type==="wire"&&c.layer!==u.layer&&e.splice(l,0,{x:c.x,y:c.y,from_layer:c.layer,to_layer:u.layer,route_type:"via"})}return e},ott=(r,e)=>{const t="_getGlobalPcbPositionBeforeLayout"in r?r._getGlobalPcbPositionBeforeLayout():r,n="_getGlobalPcbPositionBeforeLayout"in e?e._getGlobalPcbPositionBeforeLayout():e;return Math.sqrt((t.x-n.x)**2+(t.y-n.y)**2)};function stt(r,e){if(e.length===0)throw new Error("No candidates given to getClosest method");let t=e[0],n=1/0;for(const i of e){const a=ott(r,i);a<n&&(t=i,n=a)}return t}var ltt=(r,e)=>{let t=0;t+=r.length??0,t+=e.filter(n=>n.is_crossing).length;for(let n=1;n<e.length;n++){const i=e[n-1],a=e[n],o=Math.abs(i.from.x-i.to.x)<.01,s=Math.abs(a.from.x-a.to.x)<.01;o!==s&&t++}return t},yH=r=>({up:"bottom",down:"top",left:"right",right:"left"})[r]??null,gH=({firstEdge:r,firstEdgePort:e,firstDominantDirection:t,lastEdge:n,lastEdgePort:i,lastDominantDirection:a})=>{if(r&&e)return gH({lastEdge:{from:r.to,to:r.from},lastEdgePort:e,lastDominantDirection:t}).reverse().map(s=>({from:s.to,to:s.from}));let o=[];if(n&&i){const s={x:n.to.x,y:n.to.y};a==="left"||a==="right"?(s.x=i.position.x,o.push({from:n.to,to:{...s}}),o.push({from:s,to:{...i.position}})):(s.y=i.position.y,o.push({from:n.to,to:{...s}}),o.push({from:s,to:{...i.position}}))}return o=o.filter(s=>X6(s.from,s.to)>.01),o};function ctt(r){try{return[r(),null]}catch(e){return[null,e]}}function utt(r){let e=0;for(let t=0;t<r.length;t++){const n=r[t];if(n.route_type==="wire"){const i=r[t+1];if(i){const a=i.x-n.x,o=i.y-n.y;e+=Math.sqrt(a*a+o*o)}}else n.route_type==="via"&&(e+=1.6)}return e}var ftt=r=>{var s,l;const e={left:{x:-.5,y:0},up:{x:.5,y:.5},right:{x:.5,y:0},down:{x:0,y:-.5}}[r.facingDirection],t=(s=r.parent)!=null&&s.config.shouldRenderAsSchematicBox?3:1,n=(l=r.parent)!=null&&l.config.shouldRenderAsSchematicBox&&(r.facingDirection==="left"||r.facingDirection==="right")?3:1,i=e.x,a=e.y,o=r.facingDirection==="up"?.5:0;return{schBoxVertOffset:t,schBoxHorzOffset:n,horzPortDirection:i,vertPortDirectionOffset:a,handleUp:o}},FN=({port:r,anchorPos:e,schDisplayLabel:t,source_trace_id:n},{db:i})=>{const a=ftt(r);i.schematic_net_label.insert({anchor_side:"top",center:{x:e.x+a.horzPortDirection*a.schBoxHorzOffset,y:e.y+a.vertPortDirectionOffset*a.schBoxVertOffset},source_net_id:r.source_port_id,text:t,anchor_position:{x:e.x+a.horzPortDirection*a.schBoxHorzOffset,y:e.y+a.vertPortDirectionOffset*a.schBoxVertOffset},symbol_name:"ground_horz"}),i.schematic_trace.insert({edges:[{from:{x:e.x,y:e.y},to:{x:e.x,y:e.y+a.handleUp*a.schBoxVertOffset}},{from:{x:e.x,y:e.y},to:{x:e.x+a.horzPortDirection*a.schBoxHorzOffset,y:e.y+a.vertPortDirectionOffset*a.schBoxVertOffset}}],junctions:[{x:e.x+a.horzPortDirection*a.schBoxHorzOffset,y:e.y+a.vertPortDirectionOffset*a.schBoxVertOffset}],source_trace_id:n})},_H=({db:r,source_trace_id:e,sameNetOnly:t,differentNetOnly:n})=>{!t&&!n&&(n=!0);const i=r.source_trace.get(e),a=[];for(const o of r.schematic_trace.list()){if(o.source_trace_id===e)continue;const s=r.source_trace.get(o.source_trace_id),l=(s==null?void 0:s.subcircuit_connectivity_map_key)===i.subcircuit_connectivity_map_key;n&&l||t&&!l||a.push(o)}return a},dtt=({edges:r,otherEdges:e})=>{const t=[...r];for(let n=0;n<t.length;n++){if(n>2e3)throw new Error("Over 2000 iterations spent inside createSchematicTraceCrossingSegments, you have triggered an infinite loop, please report this!");const i=t[n],a=Math.abs(i.from.x-i.to.x)<.01?"vertical":i.from.y===i.to.y?"horizontal":"not-orthogonal";if(a==="not-orthogonal")continue;const o=[];for(const M of e){const w=M.from.x===M.to.x?"vertical":M.from.y===M.to.y?"horizontal":"not-orthogonal";if(w==="not-orthogonal"||a===w)continue;if(Bde([i.from,i.to],[M.from,M.to],{lineThickness:.01})){const L=a==="vertical"?i.from.x:M.from.x,O=a==="vertical"?M.from.y:i.from.y,B={x:L,y:O};o.push({otherEdge:M,crossingPoint:B,distanceFromEdgeFrom:X6(i.from,B)})}}if(o.length===0)continue;let s=o[0];for(const M of o)M.distanceFromEdgeFrom<s.distanceFromEdgeFrom&&(s=M);const l=s.crossingPoint,c=.075;if(l.x===i.from.x&&l.y===i.from.y)continue;const u=XKe(i.from,l),f={x:l.x-u.x*c/2,y:l.y-u.y*c/2},v={x:l.x+u.x*c/2,y:l.y+u.y*c/2},_=X6(v,i.to)<c,x=[{from:i.from,to:f},{from:f,to:v,is_crossing:!0},{from:v,to:i.to}];t.splice(n,1,...x),n+=x.length-2,_&&n++}return t},htt=(r,e)=>{if(r.from.x===r.to.x&&e.from.x===e.to.x)return null;if(r.from.x===r.to.x){const u=r.from.x,f=(e.to.y-e.from.y)/(e.to.x-e.from.x),v=e.from.y-f*e.from.x,_=f*u+v;return u>=Math.min(e.from.x,e.to.x)&&u<=Math.max(e.from.x,e.to.x)&&_>=Math.min(e.from.y,e.to.y)&&_<=Math.max(e.from.y,e.to.y)?{x:u,y:_}:null}if(e.from.x===e.to.x){const u=e.from.x,f=(r.to.y-r.from.y)/(r.to.x-r.from.x),v=r.from.y-f*r.from.x,_=f*u+v;return u>=Math.min(r.from.x,r.to.x)&&u<=Math.max(r.from.x,r.to.x)&&_>=Math.min(r.from.y,r.to.y)&&_<=Math.max(r.from.y,r.to.y)?{x:u,y:_}:null}const t=(r.to.y-r.from.y)/(r.to.x-r.from.x),n=r.from.y-t*r.from.x,i=(e.to.y-e.from.y)/(e.to.x-e.from.x),a=e.from.y-i*e.from.x;if(t===i)return null;const o=(a-n)/(t-i),s=t*o+n,l=o>=Math.min(r.from.x,r.to.x)&&o<=Math.max(r.from.x,r.to.x)&&s>=Math.min(r.from.y,r.to.y)&&s<=Math.max(r.from.y,r.to.y),c=o>=Math.min(e.from.x,e.to.x)&&o<=Math.max(e.from.x,e.to.x)&&s>=Math.min(e.from.y,e.to.y)&&s<=Math.max(e.from.y,e.to.y);return l&&c?{x:o,y:s}:null},ptt=({edges:r,db:e,source_trace_id:t})=>{const n=_H({db:e,source_trace_id:t,sameNetOnly:!0}).flatMap(i=>i.edges);for(const i of r)for(const a of n){const o=htt(i,a);if(o)return`${o.x}${o.y}`,[{x:o.x,y:o.y}]}return[]},mtt=(r,{db:e})=>{const t=r.map(n=>{const i=e.source_port.get(n.source_port_id);if(!(i!=null&&i.source_component_id))return null;const a=e.source_component.get(i.source_component_id);return(a==null?void 0:a.ftype)==="simple_capacitor"?a.max_decoupling_trace_length:null}).filter(n=>n!==null);if(t.length!==0)return Math.min(...t)},vtt=r=>{var a;const e=r.root.db,t=r._findConnectedPorts().ports??[],n=new Set(t.map(o=>o.schematic_port_id)),i=[];for(const o of e.toArray()){if(o.type==="schematic_component"){const s=!!o.symbol_name,l=o.size.width>o.size.height?"horz":"vert";i.push({type:"rect",layers:["top"],center:o.center,width:o.size.width+(s&&l==="horz"?-.5:0),height:o.size.height+(s&&l==="vert"?-.5:0),connectedTo:[]})}if(o.type==="schematic_port"){if(n.has(o.schematic_port_id))continue;const s=o.facing_direction?$Ke(o.facing_direction):{x:0,y:0};i.push({type:"rect",layers:["top"],center:{x:o.center.x-s.x*.1,y:o.center.y-s.y*.1},width:.1+Math.abs(s.x)*.3,height:.1+Math.abs(s.y)*.3,connectedTo:[]})}o.type==="schematic_text"&&i.push({type:"rect",layers:["top"],center:o.position,width:(((a=o.text)==null?void 0:a.length)??0)*.1,height:.2,connectedTo:[]}),o.type==="schematic_box"&&i.push({type:"rect",layers:["top"],center:{x:o.x,y:o.y},width:o.width,height:o.height,connectedTo:[]})}return i};function ytt({ports:r,nets:e}){var t,n,i;if(r.length>=2)return`${(t=r[0])==null?void 0:t.selector} to ${(n=r[1])==null?void 0:n.selector}`;if(r.length===1&&e.length===1)return`${(i=r[0])==null?void 0:i.selector} to net.${e[0]._parsedProps.name}`}var gtt=({edges:r,db:e,source_trace_id:t})=>{e.source_trace.get(t);const n=_H({db:e,source_trace_id:t,differentNetOnly:!0}).flatMap(a=>a.edges),i=a=>{const{from:o,to:s}=a;return o.x===s.x?"vertical":"horizontal"};for(const a of r){const o=i(a),s=()=>n.find(c=>i(c)===o&&Bde([a.from,a.to],[c.from,c.to],{lineThickness:.05}));let l=s();for(;l;)o==="horizontal"?(a.from.y+=.1,a.to.y+=.1):(a.from.x+=.1,a.to.x+=.1),l=s()}},_tt=(r,{db:e})=>{const t=e.pcb_board.list()[0];if(t.outline){const l=t.outline,c=(u,f)=>{let v=!1;for(let _=0,x=f.length-1;_<f.length;x=_++){const M=f[_].x,w=f[_].y,T=f[x].x,L=f[x].y;w>u.y!=L>u.y&&u.x<(T-M)*(u.y-w)/(L-w)+M&&(v=!v)}return v};return r.some(u=>!c(u,l))}const n=t.width,i=t.height,a=t.center.x,o=t.center.y;return r.some(l=>l.x<a-n/2||l.y<o-i/2||l.x>a+n/2||l.y>o+i/2)},BN=r=>({...r._getGlobalPcbPositionAfterLayout(),layers:r.getAvailablePcbLayers()}),xE=class extends T9{constructor(e){super(e);rn(this,"source_trace_id",null);rn(this,"pcb_trace_id",null);rn(this,"schematic_trace_id",null);rn(this,"_portsRoutedOnPcb");rn(this,"subcircuit_connectivity_map_key",null);this._portsRoutedOnPcb=[]}get config(){return{zodProps:vKe,componentName:"Trace"}}_getTracePortOrNetSelectorListFromProps(){return"from"in this.props&&"to"in this.props?[typeof this.props.from=="string"?this.props.from:this.props.from.getPortSelector(),typeof this.props.to=="string"?this.props.to:this.props.to.getPortSelector()]:"path"in this.props?this.props.path.map(e=>typeof e=="string"?e:e.getPortSelector()):[]}getTracePortPathSelectors(){return this._getTracePortOrNetSelectorListFromProps().filter(e=>!e.includes("net."))}getTracePathNetSelectors(){return this._getTracePortOrNetSelectorListFromProps().filter(e=>e.includes("net."))}_findConnectedPorts(){const{db:e}=this.root,{_parsedProps:t,parent:n}=this;if(!n)throw new Error("Trace has no parent");const a=this.getTracePortPathSelectors().map(o=>({selector:o,port:this.getSubcircuit().selectOne(o,{type:"port"})??null}));for(const{selector:o,port:s}of a)if(!s){const l=o.replace(/\>.*$/,""),c=this.getSubcircuit().selectOne(l);c?this.renderError(`Could not find port for selector "${o}" (did you forget to include the pin name?)
814
- searched component ${c.getString()}, which has ports: ${c.children.filter(u=>u.componentName==="Port").map(u=>`${u.getString()}(${u.getNameAndAliases().join(",")})`).join(" & ")}`):this.renderError(`Could not find port for selector "${o}"`)}return a.some(o=>!o.port)?{allPortsFound:!1}:{allPortsFound:!0,portsWithSelectors:a,ports:a.map(({port:o})=>o)}}_findConnectedNets(){const e=this.getTracePathNetSelectors().map(n=>({selector:n,net:this.getSubcircuit().selectOne(n,{type:"net"})})),t=e.filter(n=>!n.net);return t.length>0&&this.renderError(`Could not find net for selector "${t[0].selector}" inside ${this}`),{netsWithSelectors:e,nets:e.map(n=>n.net)}}_getAllTracesConnectedToSameNet(){const e=this.getSubcircuit().selectAll("trace"),t=this._findConnectedNets().nets,n=this._findConnectedPorts().ports??[];return e.filter(i=>{if(i===this)return!1;const a=i._findConnectedNets().nets,o=i._findConnectedPorts().ports??[];return a.some(s=>t.includes(s))||o.some(s=>n.includes(s))})}_isExplicitlyConnectedToPort(e){const{allPortsFound:t,portsWithSelectors:n}=this._findConnectedPorts();return t?n.map(a=>a.port).includes(e):!1}_isExplicitlyConnectedToNet(e){return this._findConnectedNets().nets.includes(e)}doInitialCreateNetsFromProps(){ghe(this,this.getTracePathNetSelectors())}doInitialSourceTraceRender(){var c;const{db:e}=this.root,{_parsedProps:t,parent:n}=this;if(!n){this.renderError("Trace has no parent");return}const{allPortsFound:i,portsWithSelectors:a}=this._findConnectedPorts();if(!i)return;const o=this._findConnectedNets().nets,s=ytt({ports:a,nets:o}),l=e.source_trace.insert({connected_source_port_ids:a.map(u=>u.port.source_port_id),connected_source_net_ids:o.map(u=>u.source_net_id),subcircuit_id:(c=this.getSubcircuit())==null?void 0:c.subcircuit_id,max_length:mtt(a.map(u=>u.port),{db:e})??t.maxLength,display_name:s,min_trace_thickness:t.thickness});this.source_trace_id=l.source_trace_id}_insertErrorIfTraceIsOutsideBoard(e,t){const{db:n}=this.root;_tt(e,{db:n})&&n.pcb_trace_error.insert({error_type:"pcb_trace_error",source_trace_id:this.source_trace_id,message:`Trace ${this.getString()} routed outside the board boundaries.`,pcb_trace_id:this.pcb_trace_id,pcb_component_ids:[],pcb_port_ids:t.map(a=>a.pcb_port_id)})}doInitialPcbTraceRender(){var ee,ae,K,pe;if((ee=this.root)!=null&&ee.pcbDisabled)return;const{db:e}=this.root,{_parsedProps:t,parent:n}=this,i=this.getSubcircuit();if(!n)throw new Error("Trace has no parent");if(i._parsedProps.routingDisabled)return;const a=(ae=i._parsedProps.pcbRouteCache)==null?void 0:ae.pcbTraces;if(a){const me=e.pcb_trace.insert({route:a.flatMap(be=>be.route),source_trace_id:this.source_trace_id,subcircuit_id:(i==null?void 0:i.subcircuit_id)??void 0,pcb_group_id:((K=this.getGroup())==null?void 0:K.pcb_group_id)??void 0});this.pcb_trace_id=me.pcb_trace_id;return}if(!i._shouldUseTraceByTraceRouting())return;const{allPortsFound:o,ports:s}=this._findConnectedPorts();if(!o)return;const l=[];for(const me of s)me._hasMatchedPcbPrimitive()||l.push(me);if(l.length>0){e.pcb_trace_error.insert({error_type:"pcb_trace_error",source_trace_id:this.source_trace_id,message:`Some ports did not have a matching PCB primitive (e.g. a pad or plated hole), this can happen if a footprint is missing. As a result, ${this} wasn't routed. Missing ports: ${l.map(me=>me.getString()).join(", ")}`,pcb_trace_id:this.pcb_trace_id,pcb_component_ids:[],pcb_port_ids:l.map(me=>me.pcb_port_id).filter(Boolean)});return}const c=this._findConnectedNets().netsWithSelectors;if(s.length===0&&c.length===2){this.renderError("Trace connects two nets, we haven't implemented a way to route this yet");return}else if(s.length===1&&c.length===1){const me=s[0],Ae=c[0].net.getAllConnectedPorts().filter(we=>we!==me);if(Ae.length===0){console.log("Nothing to connect this port to, the net is empty. TODO should emit a warning!");return}const Oe=stt(me,Ae);s.push(Oe)}else if(s.length>1&&c.length>=1){this.renderError("Trace has more than one port and one or more nets, we don't currently support this type of complex trace routing");return}const u=s.flatMap(me=>me.matchedComponents.filter(be=>be.componentName==="TraceHint")),f=(this._parsedProps.pcbRouteHints??[]).concat(u.flatMap(me=>me.getPcbRouteHints()));if(s.length>2){this.renderError(`Trace has more than two ports (${s.map(me=>me.getString()).join(", ")}), routing between more than two ports for a single trace is not implemented`);return}if(this.getSubcircuit().selectAll("trace").filter(me=>me.renderPhaseStates.PcbTraceRender.initialized).some(me=>me._portsRoutedOnPcb.length===s.length&&me._portsRoutedOnPcb.every(be=>s.includes(be))))return;let x=[];f.length===0?x=[BN(s[0]),BN(s[1])]:x=[BN(s[0]),...f,BN(s[1])];const M=kN(x),w=XB(this.root.db.toArray()),[T,L]=ctt(()=>Rde(this.root.db.toArray()));if(L){this.renderError({type:"pcb_trace_error",error_type:"pcb_trace_error",pcb_trace_error_id:this.pcb_trace_id,message:`Error getting obstacles for autorouting: ${L.message}`,source_trace_id:this.source_trace_id,center:{x:0,y:0},pcb_port_ids:s.map(me=>me.pcb_port_id),pcb_trace_id:this.pcb_trace_id,pcb_component_ids:[]});return}for(const me of T)if(me.connectedTo.length>0){const Ae=w.getNetConnectedToId(me.connectedTo[0]);Ae&&me.connectedTo.push(Ae)}let O=[];if(M.length===0)O=x;else{const me=M[0].layer_path;O=x.map((be,Ae)=>be.via?{...be,via_to_layer:me[Ae]}:{...be,layers:[me[Ae]]})}O[0].pcb_port_id=s[0].pcb_port_id,O[O.length-1].pcb_port_id=s[1].pcb_port_id;const B=[];for(const[me,be]of vhe(O)){const Ae="via_to_layer"in me?me.via_to_layer:null,Oe=2,we="layers"in me&&me.layers.length===1?me.layers[0]:Ae??"top",Le="layers"in be&&be.layers.length===1?be.layers[0]:Ae??"top",Te="pcb_port_id"in me?me.pcb_port_id:null,je="pcb_port_id"in be?be.pcb_port_id:null,Ue=this.getSubcircuit()._parsedProps.minTraceWidth??.16,Ve=new Cde({OBSTACLE_MARGIN:Ue*2,isRemovePathLoopsEnabled:!0,optimizeWithGoalBoxes:!!(Te&&je),connMap:w,input:{obstacles:T,minTraceWidth:Ue,connections:[{name:this.source_trace_id,pointsToConnect:[{...me,layer:we,pcb_port_id:Te},{...be,layer:Le,pcb_port_id:je}]}],layerCount:2,bounds:{minX:Math.min(me.x,be.x)-Oe,maxX:Math.max(me.x,be.x)+Oe,minY:Math.min(me.y,be.y)-Oe,maxY:Math.max(me.y,be.y)+Oe}}});let ze=null;try{ze=Ve.solveAndMapToTraces()}catch(vt){this.renderError({type:"pcb_trace_error",pcb_trace_error_id:this.source_trace_id,error_type:"pcb_trace_error",message:`error solving route: ${vt.message}`,source_trace_id:this.pcb_trace_id,center:{x:(me.x+be.x)/2,y:(me.y+be.y)/2},pcb_port_ids:s.map(At=>At.pcb_port_id),pcb_trace_id:this.pcb_trace_id,pcb_component_ids:s.map(At=>At.pcb_component_id)})}if(!ze)return;if(ze.length===0){this.renderError({type:"pcb_trace_error",error_type:"pcb_trace_error",pcb_trace_error_id:this.pcb_trace_id,message:`Could not find a route for ${this}`,source_trace_id:this.source_trace_id,center:{x:(me.x+be.x)/2,y:(me.y+be.y)/2},pcb_port_ids:s.map(vt=>vt.pcb_port_id),pcb_trace_id:this.pcb_trace_id,pcb_component_ids:s.map(vt=>vt.pcb_component_id)});return}const[lt]=ze;Ae&&(lt.route=lt.route.map(vt=>(vt.route_type==="wire"&&!vt.layer&&(vt.layer=Ae),vt))),Te&&lt.route[0].route_type==="wire"&&(lt.route[0].start_pcb_port_id=Te);const it=lt.route[lt.route.length-1];je&&it.route_type==="wire"&&(it.end_pcb_port_id=je),B.push(lt.route)}const X=att(B),$=utt(X),Q=e.pcb_trace.insert({route:X,source_trace_id:this.source_trace_id,subcircuit_id:(pe=this.getSubcircuit())==null?void 0:pe.subcircuit_id,trace_length:$});this._portsRoutedOnPcb=s,this.pcb_trace_id=Q.pcb_trace_id;for(const me of X)me.route_type==="via"&&e.pcb_via.insert({pcb_trace_id:Q.pcb_trace_id,x:me.x,y:me.y,hole_diameter:.3,outer_diameter:.6,layers:[me.from_layer,me.to_layer],from_layer:me.from_layer,to_layer:me.to_layer});this._insertErrorIfTraceIsOutsideBoard(X,s)}_doInitialSchematicTraceRenderWithDisplayLabel(){var B,X,$,Q;if((B=this.root)!=null&&B.schematicDisabled)return;const{db:e}=this.root,{_parsedProps:t,parent:n}=this;if(!n)throw new Error("Trace has no parent");const{allPortsFound:i,portsWithSelectors:a}=this._findConnectedPorts();if(!i)return;const o=a.map(({port:ee})=>({port:ee,position:ee._getGlobalSchematicPositionAfterLayout(),schematic_port_id:ee.schematic_port_id,facingDirection:ee.facingDirection}));if(o.length<2)throw new Error("Expected at least two ports in portsWithPosition.");let s,l;const c=o[0].position,u=o[0].port;if("path"in this.props){if(this.props.path.length!==2)throw new Error("Invalid 'path': Must contain exactly two elements.");[s,l]=this.props.path}else{if(!("from"in this.props&&"to"in this.props))throw new Error("Missing 'from' or 'to' properties in props.");s=this.props.from,l=this.props.to}if(!u.source_port_id)throw new Error(`Missing source_port_id for the 'from' port (${s}).`);const f=o[1].position,v=o[1].port;if(!v.source_port_id)throw new Error(`Missing source_port_id for the 'to' port (${l}).`);const _=e.schematic_net_label.list().find(ee=>ee.source_net_id===u.source_port_id),x=e.schematic_net_label.list().find(ee=>ee.source_net_id===v.source_port_id),[M,w]=a.map(({port:ee})=>ee),L=((X=M.parent)==null?void 0:X.config.shouldRenderAsSchematicBox)?`${($=M==null?void 0:M.parent)==null?void 0:$.props.name}_${M==null?void 0:M.props.name}`:`${(Q=w==null?void 0:w.parent)==null?void 0:Q.props.name}_${w==null?void 0:w.props.name}`,O=this.props.schDisplayLabel??L;if(_&&_.text!==O&&(_.text=`${O} / ${_.text}`),x&&(x==null?void 0:x.text)!==O&&(x.text=`${O} / ${x.text}`),O!=null&&O.toLocaleLowerCase().includes("gnd")||O!=null&&O.toLocaleLowerCase().includes("ground")){!_&&!x?(FN({port:u,anchorPos:c,schDisplayLabel:this.props.schDisplayLabel,source_trace_id:this.source_trace_id},{db:e}),FN({port:v,anchorPos:f,schDisplayLabel:this.props.schDisplayLabel,source_trace_id:this.source_trace_id},{db:e})):_?x||FN({port:v,anchorPos:f,schDisplayLabel:this.props.schDisplayLabel,source_trace_id:this.source_trace_id},{db:e}):FN({port:u,anchorPos:c,schDisplayLabel:this.props.schDisplayLabel,source_trace_id:this.source_trace_id},{db:e});return}x||e.schematic_net_label.insert({text:this.props.schDisplayLabel??L,source_net_id:v.source_port_id,anchor_position:f,center:f,anchor_side:yH(v.facingDirection)??"bottom"}),_||e.schematic_net_label.insert({text:this.props.schDisplayLabel??L,source_net_id:u.source_port_id,anchor_position:c,center:c,anchor_side:yH(u.facingDirection)??"bottom"})}_isSymbolToChipConnection(){const{allPortsFound:e,ports:t}=this._findConnectedPorts();if(!e||t.length!==2)return!1;const[n,i]=t;if(!(n!=null&&n.parent)||!(i!=null&&i.parent))return!1;const a=n.parent.config.shouldRenderAsSchematicBox,o=i.parent.config.shouldRenderAsSchematicBox;return a&&!o||!a&&o}_isSymbolToSymbolConnection(){const{allPortsFound:e,ports:t}=this._findConnectedPorts();if(!e||t.length!==2)return!1;const[n,i]=t;if(!(n!=null&&n.parent)||!(i!=null&&i.parent))return!1;const a=!n.parent.config.shouldRenderAsSchematicBox,o=!i.parent.config.shouldRenderAsSchematicBox;return a&&o}_isChipToChipConnection(){const{allPortsFound:e,ports:t}=this._findConnectedPorts();if(!e||t.length!==2)return!1;const[n,i]=t;if(!(n!=null&&n.parent)||!(i!=null&&i.parent))return!1;const a=n.parent.config.shouldRenderAsSchematicBox,o=i.parent.config.shouldRenderAsSchematicBox;return a&&o}doInitialSchematicTraceRender(){var be;if((be=this.root)!=null&&be.schematicDisabled)return;const{db:e}=this.root,{_parsedProps:t,parent:n}=this;if(!n)throw new Error("Trace has no parent");const{allPortsFound:i,portsWithSelectors:a}=this._findConnectedPorts(),{netsWithSelectors:o}=this._findConnectedNets();if(!i)return;if(this.props.schDisplayLabel&&("from"in this.props&&"to"in this.props||"path"in this.props)){this._doInitialSchematicTraceRenderWithDisplayLabel();return}const s={name:this.source_trace_id,pointsToConnect:[]},l=vtt(this),c=a.map(({port:Ae})=>({port:Ae,position:Ae._getGlobalSchematicPositionAfterLayout(),schematic_port_id:Ae.schematic_port_id??void 0,facingDirection:Ae.facingDirection}));if(c.length===1&&o.length===1){const Ae=o[0].net,{port:Oe,position:we}=c[0];e.schematic_net_label.insert({text:Ae._parsedProps.name,source_net_id:Ae.source_net_id,anchor_position:we,center:we,anchor_side:yH(Oe.facingDirection)??"bottom"});return}if(c.length<2)return;s.pointsToConnect=c.map(({position:Ae})=>({...Ae,layer:"top"}));const f=itt(l),v=2,_={minTraceWidth:.1,obstacles:l,connections:[s],bounds:{minX:f.minX-v,maxX:f.maxX+v,minY:f.minY-v,maxY:f.maxY+v},layerCount:1};let x=Cde,M=!1;this.getSubcircuit().props._schDirectLineRoutingEnabled&&(x=Mhe,M=!0);let T=new x({input:_,MAX_ITERATIONS:100,OBSTACLE_MARGIN:.1,isRemovePathLoopsEnabled:!0,isShortenPathWithShortcutsEnabled:!0,marginsWithCosts:[{margin:1,enterCost:0,travelCostFactor:1},{margin:.3,enterCost:0,travelCostFactor:1},{margin:.2,enterCost:0,travelCostFactor:2},{margin:.1,enterCost:0,travelCostFactor:3}]}).solveAndMapToTraces();if(T.length===0){if(this._isSymbolToChipConnection()||this._isSymbolToSymbolConnection()||this._isChipToChipConnection()){this._doInitialSchematicTraceRenderWithDisplayLabel();return}T=new Mhe({input:_}).solveAndMapToTraces(),M=!0}const[{route:L}]=T;let O=[];for(let Ae=0;Ae<L.length-1;Ae++)O.push({from:L[Ae],to:L[Ae+1]});const B=this.source_trace_id;let X=[];if(!M){gtt({edges:O,db:e,source_trace_id:B});const Ae=_H({db:e,source_trace_id:B,differentNetOnly:!0}).flatMap(Oe=>Oe.edges);O=dtt({edges:O,otherEdges:Ae}),X=ptt({edges:O,db:e,source_trace_id:this.source_trace_id})}const $=O[O.length-1],Q=c[c.length-1],ee=Rhe($);O.push(...gH({lastEdge:$,lastEdgePort:Q,lastDominantDirection:ee}));const ae=O[0],K=c[0],pe=Rhe(ae);if(O.unshift(...gH({firstEdge:ae,firstEdgePort:K,firstDominantDirection:pe})),!this.source_trace_id)throw new Error("Missing source_trace_id for schematic trace insertion.");if(this.getSubcircuit()._parsedProps.schTraceAutoLabelEnabled&&ltt(X,O)>=5&&(this._isSymbolToChipConnection()||this._isSymbolToSymbolConnection()||this._isChipToChipConnection())){this._doInitialSchematicTraceRenderWithDisplayLabel();return}const me=e.schematic_trace.insert({source_trace_id:this.source_trace_id,edges:O,junctions:X});this.schematic_trace_id=me.schematic_trace_id}},xtt=w9("tscircuit:core"),btt=le.object({x:SS,y:SS,z:SS}),yx=class extends T9{constructor(e){super(e);rn(this,"reactSubtrees",[]);rn(this,"_impliedFootprint");rn(this,"isPrimitiveContainer",!0);rn(this,"_asyncSupplierPartNumbers");rn(this,"pcb_missing_footprint_error_id");this._addChildrenFromStringFootprint(),this.initPorts()}get defaultInternallyConnectedPinNames(){return[]}get internallyConnectedPinNames(){return this._parsedProps.internallyConnectedPins??this.defaultInternallyConnectedPinNames}initPorts(e={}){var o,s,l,c,u,f,v,_,x,M;if((o=this.root)!=null&&o.schematicDisabled)return;const{config:t}=this,n=[],i=this._getSchematicPortArrangement();if(i&&!this._parsedProps.pinLabels){for(const L in i){const O=i[L].pins;if(Array.isArray(O))for(const B of O){const X=J6(B,this._parsedProps.pinLabels);n.push(new TS({pinNumber:X,aliases:((s=e.additionalAliases)==null?void 0:s[`pin${X}`])??[]},{originDescription:`schPortArrangement:${L}`}))}}const w=["left","right","top","bottom"];let T=1;for(const L of w){const O=i[`${L}Size`];for(let B=0;B<O;B++)n.push(new TS({pinNumber:T++,aliases:((l=e.additionalAliases)==null?void 0:l[`pin${T}`])??[]},{originDescription:`schPortArrangement:${L}`}))}}const a=this._parsedProps.pinLabels;if(a)for(let[w,T]of Object.entries(a)){w=w.replace("pin","");let L=n.find(X=>X._parsedProps.pinNumber===Number(w));const O=Array.isArray(T)?T[0]:T,B=Array.isArray(T)?T.slice(1):[];L?(L.externallyAddedAliases.push(O,...B),L.props.name=O):(L=new TS({pinNumber:parseInt(w),name:O,aliases:[...B,...((c=e.additionalAliases)==null?void 0:c[`pin${parseInt(w)}`])??[]]},{originDescription:`pinLabels:pin${w}`}),n.push(L))}if(t.schematicSymbolName){const w=z3[this._getSchematicSymbolNameOrThrow()];if(!w)return;for(const T of w.ports){const L=whe(T.labels);if(!L)continue;const O=tM(T.labels.concat(((u=e.additionalAliases)==null?void 0:u[`pin${L}`])??[]));O&&(O.originDescription=`schematicSymbol:labels[0]:${T.labels[0]}`,O.schematicSymbolPortDef=T,n.push(O))}this.addAll(n)}if(!this._getSchematicPortArrangement()){const w=this.getPortsFromFootprint(e);for(const T of w)n.some(L=>L.isMatchingAnyOf(T.getNameAndAliases()))||n.push(T)}for(let w=1;w<=(e.pinCount??this._getPinCount());w++){if(!i||n.find(L=>L._parsedProps.pinNumber===w))continue;let T=[...((f=i.leftSide)==null?void 0:f.pins)??[],...((v=i.rightSide)==null?void 0:v.pins)??[],...((_=i.topSide)==null?void 0:_.pins)??[],...((x=i.bottomSide)==null?void 0:x.pins)??[]].map(L=>J6(L,this._parsedProps.pinLabels));["leftSize","rightSize","topSize","bottomSize","leftPinCount","rightPinCount","topPinCount","bottomPinCount"].some(L=>L in i)&&(T=Array.from({length:this._getPinCount()},(L,O)=>O+1)),T.includes(w)&&n.push(new TS({pinNumber:w,aliases:((M=e.additionalAliases)==null?void 0:M[`pin${w}`])??[]},{originDescription:`notOtherwiseAddedButDeducedFromPinCount:${w}`}))}n.length>0&&this.addAll(n)}_getImpliedFootprintString(){return null}_addChildrenFromStringFootprint(){var i;const{name:e,pcbRotation:t}=this.props;let{footprint:n}=this.props;if(n??(n=(i=this._getImpliedFootprintString)==null?void 0:i.call(this)),!!n&&typeof n=="string"){const a=gk.string(n).soup(),o=Yet({componentName:e,componentRotation:t},a);this.addAll(o)}}get portMap(){return new Proxy({},{get:(e,t)=>{const n=this.children.find(i=>i.componentName==="Port"&&i.isMatchingNameOrAlias(t));if(!n)throw new Error(`There was an issue finding the port "${t.toString()}" inside of a ${this.componentName} component with name: "${this.props.name}". This is a bug in @tscircuit/core`);return n}})}getInstanceForReactElement(e){for(const t of this.reactSubtrees)if(t.element===e)return t.component;return null}doInitialSourceRender(){const e=this.config.sourceFtype;if(!e)return;const{db:t}=this.root,{_parsedProps:n}=this,i=t.source_component.insert({ftype:e,name:n.name,manufacturer_part_number:n.manufacturerPartNumber??n.mfn,supplier_part_numbers:n.supplierPartNumbers});this.source_component_id=i.source_component_id}doInitialSchematicComponentRender(){var n;if((n=this.root)!=null&&n.schematicDisabled)return;const{schematicSymbolName:e}=this.config;if(e)return this._doInitialSchematicComponentRenderWithSymbol();if(this._getSchematicBoxDimensions())return this._doInitialSchematicComponentRenderWithSchematicBoxDimensions()}_getSchematicSymbolDisplayValue(){}_getInternallyConnectedPins(){if(this.internallyConnectedPinNames.length===0)return[];const e=[];for(const t of this.internallyConnectedPinNames){const n=[];for(const i of t)n.push(this.portMap[i]);e.push(n)}return e}_doInitialSchematicComponentRenderWithSymbol(){var o;if((o=this.root)!=null&&o.schematicDisabled)return;const{db:e}=this.root,{_parsedProps:t}=this,n=this._getSchematicSymbolNameOrThrow(),i=z3[n],a=this._getGlobalSchematicPositionBeforeLayout();if(i){const s=e.schematic_component.insert({center:a,size:i.size,source_component_id:this.source_component_id,symbol_name:n,symbol_display_value:this._getSchematicSymbolDisplayValue()});this.schematic_component_id=s.schematic_component_id}}_doInitialSchematicComponentRenderWithSchematicBoxDimensions(){var f;if((f=this.root)!=null&&f.schematicDisabled)return;const{db:e}=this.root,{_parsedProps:t}=this,n=this._getSchematicBoxDimensions(),i={};if(Array.isArray(t.pinLabels))t.pinLabels.forEach((v,_)=>{i[String(_+1)]=v});else for(const[v,_]of Object.entries(t.pinLabels??{}))i[v]=Array.isArray(_)?_[0]:_;const a=this._getGlobalSchematicPositionBeforeLayout(),o=this._getSchematicPortArrangement(),s=e.schematic_component.insert({center:a,rotation:t.schRotation??0,size:n.getSize(),port_arrangement:Get(o),pin_spacing:t.schPinSpacing??.2,pin_styles:Vet(t.schPinStyle,t.pinLabels),port_labels:i,source_component_id:this.source_component_id}),l=(o==null?void 0:o.topSide)!==void 0||(o==null?void 0:o.bottomSide)!==void 0,c=n==null?void 0:n.getSize().width,u=n==null?void 0:n.getSize().height;e.schematic_text.insert({text:t.manufacturerPartNumber??"",schematic_component_id:s.schematic_component_id,anchor:"left",rotation:0,position:{x:l?a.x+(c??0)/2+.1:a.x-(c??0)/2,y:l?a.y+(u??0)/2+.35:a.y-(u??0)/2-.13},color:"#006464"}),e.schematic_text.insert({text:t.name??"",schematic_component_id:s.schematic_component_id,anchor:"left",rotation:0,position:{x:l?a.x+(c??0)/2+.1:a.x-(c??0)/2,y:l?a.y+(u??0)/2+.55:a.y+(u??0)/2+.13},color:"#006464"}),this.schematic_component_id=s.schematic_component_id}doInitialPcbComponentRender(){var o;if((o=this.root)!=null&&o.pcbDisabled)return;const{db:e}=this.root,{_parsedProps:t}=this,n=this.getSubcircuit(),i=e.pcb_component.insert({center:this._getGlobalPcbPositionBeforeLayout(),width:0,height:0,layer:t.layer??"top",rotation:t.pcbRotation??0,source_component_id:this.source_component_id,subcircuit_id:n.subcircuit_id??void 0});if(!t.footprint&&!this.isGroup){const s=e.pcb_missing_footprint_error.insert({message:`No footprint found for component: ${this.getString()}`,source_component_id:`${this.source_component_id}`,error_type:"pcb_missing_footprint_error"});this.pcb_missing_footprint_error_id=s.pcb_missing_footprint_error_id}this.pcb_component_id=i.pcb_component_id;const a=this.getSubcircuit()._getPcbManualPlacementForComponent(this);this.props.pcbX!==void 0&&this.props.pcbY!==void 0&&a&&this.renderError({type:"pcb_manual_edit_conflict_error",message:`${this.getString()} has both manual placement and explicit coordinates. pcbX and pcbY will be used. Remove pcbX/pcbY or clear the manual placement.`,pcb_component_id:this.pcb_component_id,source_component_id:this.source_component_id})}doInitialPcbComponentSizeCalculation(){var a;if((a=this.root)!=null&&a.pcbDisabled||!this.pcb_component_id)return;const{db:e}=this.root,{_parsedProps:t}=this,n=Ehe(this.children);if(n.width===0||n.height===0)return;const i={x:(n.minX+n.maxX)/2,y:(n.minY+n.maxY)/2};e.pcb_component.update(this.pcb_component_id,{center:i,width:n.width,height:n.height})}_renderReactSubtree(e){return{element:e,component:mhe(e)}}doInitialInitializePortsFromChildren(){this.initPorts()}doInitialReactSubtreesRender(){if(ut.isValidElement(this.props.footprint)){if(this.reactSubtrees.some(t=>t.element===this.props.footprint))return;const e=this._renderReactSubtree(this.props.footprint);this.reactSubtrees.push(e),this.add(e.component)}}_hasExistingPortExactly(e){return this.children.filter(n=>n.componentName==="Port").some(n=>{const i=e.getNameAndAliases(),a=n.getNameAndAliases();return i.length===a.length&&i.every(o=>a.includes(o))})}add(e){let t;if(ut.isValidElement(e)){const n=this._renderReactSubtree(e);this.reactSubtrees.push(n),t=n.component}else t=e;if(t.componentName==="Port"){if(this._hasExistingPortExactly(t))return;const i=this.children.filter(a=>a.componentName==="Port").find(a=>a.isMatchingAnyOf(t.getNameAndAliases()));i&&xtt(`Similar ports added. Port 1: ${i}, Port 2: ${t}`)}super.add(t)}getPortsFromFootprint(e){let{footprint:t}=this.props;if((!t||ut.isValidElement(t))&&(t=this.children.find(i=>i.componentName==="Footprint")),typeof t=="string"){const i=gk.string(t).soup(),a=[];for(const o of i)if("port_hints"in o&&o.port_hints){const s=tM(o.port_hints,e);if(!s)continue;s.originDescription=`footprint:string:${t}:port_hints[0]:${o.port_hints[0]}`,a.push(s)}return a}if(!ut.isValidElement(t)&&t&&t.componentName==="Footprint"){const i=t;let a=1;const o=[];for(const s of i.children){if(!s.props.portHints)continue;let l=s.props.portHints;l.some(f=>f.startsWith("pin"))||(l=[...l,`pin${a}`]),a++;const u=tM(l);u&&(u.originDescription=`footprint:${t}`,o.push(u))}return o}const n=[];if(!t){for(const i of this.children)if(i.props.portHints&&i.isPcbPrimitive){const a=tM(i.props.portHints);a&&n.push(a)}}return n}getPortsFromSchematicSymbol(){var i;if((i=this.root)!=null&&i.schematicDisabled)return[];const{config:e}=this;if(!e.schematicSymbolName)return[];const t=z3[e.schematicSymbolName];if(!t)return[];const n=[];for(const a of t.ports){const o=tM(a.labels);o&&(o.schematicSymbolPortDef=a,n.push(o))}return n}doInitialCreateNetsFromProps(){this._createNetsFromProps(this._getNetsFromConnectionsProp())}_getNetsFromConnectionsProp(){const{_parsedProps:e}=this,t=[];if(e.connections)for(const[n,i]of Object.entries(e.connections)){const a=Array.isArray(i)?i:[i];for(const o of a)t.push(o)}return t}_createNetsFromProps(e){ghe(this,e)}_getPcbCircuitJsonBounds(){const{db:e}=this.root;if(!this.pcb_component_id)return super._getPcbCircuitJsonBounds();const t=e.pcb_component.get(this.pcb_component_id);return{center:{x:t.center.x,y:t.center.y},bounds:{left:t.center.x-t.width/2,top:t.center.y-t.height/2,right:t.center.x+t.width/2,bottom:t.center.y+t.height/2},width:t.width,height:t.height}}_getPinCountFromSchematicPortArrangement(){const e=this._getSchematicPortArrangement();if(!e)return 0;if(!The(e))return(e.leftSize??e.leftPinCount??0)+(e.rightSize??e.rightPinCount??0)+(e.topSize??e.topPinCount??0)+(e.bottomSize??e.bottomPinCount??0);const{leftSide:n,rightSide:i,topSide:a,bottomSide:o}=e;return Math.max(...(n==null?void 0:n.pins)??[],...(i==null?void 0:i.pins)??[],...(a==null?void 0:a.pins)??[],...(o==null?void 0:o.pins)??[])}_getPinCount(){return this._getSchematicPortArrangement()?this._getPinCountFromSchematicPortArrangement():this.getPortsFromFootprint().length}_getSchematicPortArrangement(){return this._parsedProps.schPinArrangement??this._parsedProps.schPortArrangement}_getSchematicBoxDimensions(){if(this.getSchematicSymbol()||!this.config.shouldRenderAsSchematicBox)return null;const{_parsedProps:e}=this,t=this._getPinCount(),n=e.schPinSpacing??.2;return ett({schWidth:e.schWidth,schHeight:e.schHeight,schPinSpacing:n,numericSchPinStyle:rtt(e.schPinStyle,e.pinLabels),pinCount:t,schPortArrangement:this._getSchematicPortArrangement(),pinLabels:e.pinLabels})}doInitialCadModelRender(){var c;const{db:e}=this.root,{boardThickness:t=0}=((c=this.root)==null?void 0:c._getBoard())??{},n=this._parsedProps.cadModel;if(!this.pcb_component_id||!n&&!this.props.footprint)return;const i=this._getPcbCircuitJsonBounds(),a=e.pcb_component.get(this.pcb_component_id);if(typeof n=="string")throw new Error("String cadModel not yet implemented");const o=btt.parse({x:0,y:0,z:typeof(n==null?void 0:n.rotationOffset)=="number"?n.rotationOffset:0,...typeof(n==null?void 0:n.rotationOffset)=="object"?n.rotationOffset??{}:{}}),s=lA.parse({x:0,y:0,z:0,...typeof(n==null?void 0:n.positionOffset)=="object"?n.positionOffset:{}}),l=this.props.layer==="bottom"?"bottom":"top";e.cad_component.insert({position:{x:i.center.x+s.x,y:i.center.y+s.y,z:(l==="bottom"?-t/2:t/2)+s.z},rotation:{x:o.x,y:(l==="top"?0:180)+o.y,z:((a==null?void 0:a.rotation)??0)+(l==="bottom"?180:0)+o.z},pcb_component_id:this.pcb_component_id,source_component_id:this.source_component_id,model_stl_url:"stlUrl"in(n??{})?this._addCachebustToModelUrl(n.stlUrl):void 0,model_obj_url:"objUrl"in(n??{})?this._addCachebustToModelUrl(n.objUrl):void 0,model_jscad:"jscad"in(n??{})?n.jscad:void 0,footprinter_string:typeof this.props.footprint=="string"&&!n?this.props.footprint:void 0})}_addCachebustToModelUrl(e){var n;if(!e||!e.includes("modelcdn.tscircuit.com"))return e;const t=((n=this.root)==null?void 0:n.getClientOrigin())??"";return`${e}${e.includes("?")?"&":"?"}cachebust_origin=${encodeURIComponent(t)}`}doInitialPartsEngineRender(){const e=this.getInheritedProperty("partsEngine");if(!e)return;const{db:t}=this.root,n=t.source_component.get(this.source_component_id);if(!n||n.supplier_part_numbers)return;let i;this.props.footprint&&typeof this.props.footprint=="string"&&(i=this.props.footprint);const a=e.findPart({sourceComponent:n,footprinterString:i});if(!(a instanceof Promise)){t.source_component.update(this.source_component_id,{supplier_part_numbers:a});return}this._queueAsyncEffect("get-supplier-part-numbers",async()=>{this._asyncSupplierPartNumbers=await a,this._markDirty("PartsEngineRender")})}updatePartsEngineRender(){const{db:e}=this.root,t=e.source_component.get(this.source_component_id);if(t&&!t.supplier_part_numbers&&this._asyncSupplierPartNumbers){e.source_component.update(this.source_component_id,{supplier_part_numbers:this._asyncSupplierPartNumbers});return}}doInitialCreateTracesFromProps(){this._createTracesFromConnectionsProp()}_createTracesFromConnectionsProp(){const{_parsedProps:e}=this;if(e.connections)for(const[t,n]of Object.entries(e.connections)){const i=Array.isArray(n)?n:[n];for(const a of i)this.add(new xE({from:`${this.getSubcircuitSelector()} > port.${t}`,to:a}))}}},Stt=class{constructor(r,e={}){rn(this,"input");rn(this,"isRouting",!1);rn(this,"solver");rn(this,"eventHandlers",{complete:[],error:[],progress:[]});rn(this,"cycleCount",0);rn(this,"stepDelay");rn(this,"timeoutId");this.input=r;const{capacityDepth:t,targetMinCapacity:n,stepDelay:i=0}=e;this.solver=new Iet(r,{capacityDepth:t,targetMinCapacity:n}),this.stepDelay=i}start(){this.isRouting||(this.isRouting=!0,this.cycleCount=0,this.runCycleAndQueueNextCycle())}runCycleAndQueueNextCycle(){var r;if(this.isRouting)try{if(this.solver.solved||this.solver.failed){this.solver.failed?this.emitEvent({type:"error",error:new Error(this.solver.error||"Routing failed")}):this.emitEvent({type:"complete",traces:this.solver.getOutputSimpleRouteJson().traces||[]}),this.isRouting=!1;return}const e=Date.now(),t=this.solver.iterations;for(;Date.now()-e<250&&!this.solver.failed&&!this.solver.solved;)this.solver.step();const n=(this.solver.iterations-t)/(Date.now()-e)*1e3;this.cycleCount++;const i=((r=this.solver.activeSolver)==null?void 0:r.visualize())||void 0,a=this.solver.progress;this.emitEvent({type:"progress",steps:this.cycleCount,iterationsPerSecond:n,progress:a,phase:this.solver.getCurrentPhase(),debugGraphics:i}),this.stepDelay>0?this.timeoutId=setTimeout(()=>this.runCycleAndQueueNextCycle(),this.stepDelay):this.timeoutId=setTimeout(()=>this.runCycleAndQueueNextCycle(),0)}catch(e){this.emitEvent({type:"error",error:e instanceof Error?e:new Error(String(e))}),this.isRouting=!1}}stop(){this.isRouting&&(this.isRouting=!1,this.timeoutId!==void 0&&(clearTimeout(this.timeoutId),this.timeoutId=void 0))}on(r,e){r==="complete"?this.eventHandlers.complete.push(e):r==="error"?this.eventHandlers.error.push(e):r==="progress"&&this.eventHandlers.progress.push(e)}emitEvent(r){if(r.type==="complete")for(const e of this.eventHandlers.complete)e(r);else if(r.type==="error")for(const e of this.eventHandlers.error)e(r);else if(r.type==="progress")for(const e of this.eventHandlers.progress)e(r)}solveSync(){if(this.solver.solve(),this.solver.failed)throw new Error(this.solver.error||"Routing failed");return this.solver.getOutputSimpleRouteJson().traces||[]}},Ahe=class extends T9{constructor(){super(...arguments);rn(this,"matchedPort",null)}get config(){return{componentName:"TraceHint",zodProps:FKe}}doInitialPortMatching(){const{db:e}=this.root,{_parsedProps:t,parent:n}=this;if(!n)return;if(n.componentName==="Trace"){this.renderError(`Port inference inside trace is not yet supported (${this})`);return}if(!n)throw new Error("TraceHint has no parent");if(!t.for){this.renderError(`TraceHint has no for property (${this})`);return}const i=n.selectOne(t.for,{type:"port"});i||this.renderError(`${this} could not find port for selector "${t.for}"`),this.matchedPort=i,i.registerMatch(this)}getPcbRouteHints(){const{_parsedProps:e}=this,t=e.offset?[e.offset]:e.offsets;if(!t)return[];const n=this._computePcbGlobalTransformBeforeLayout();return t.map(i=>({...ai(n,i),via:i.via,to_layer:i.to_layer,trace_width:i.trace_width}))}doInitialPcbTraceHintRender(){var n,i,a;if((n=this.root)!=null&&n.pcbDisabled)return;const{db:e}=this.root,{_parsedProps:t}=this;e.pcb_trace_hint.insert({pcb_component_id:(i=this.matchedPort)==null?void 0:i.pcb_component_id,pcb_port_id:(a=this.matchedPort)==null?void 0:a.pcb_port_id,route:this.getPcbRouteHints()})}},Ett=({circuitJson:r,editEvents:e,manualEditsFile:t})=>{var i;const n={...t,schematic_placements:[...t.schematic_placements??[]]};for(const a of e)if(a.edit_event_type==="edit_schematic_component_location"){const{schematic_component_id:o,new_center:s}=a,l=m1(r).schematic_component.get(o);if(!l)continue;const c=m1(r).source_component.get(l.source_component_id);if(!c)continue;const u=(i=n.schematic_placements)==null?void 0:i.findIndex(v=>v.selector===c.name),f={selector:c.name,center:s,relative_to:"group_center"};u>=0?n.schematic_placements[u]=f:n.schematic_placements.push(f)}return n},wtt=(r,e)=>{const t=r.source_group.list(),n=[],i=a=>{const o=t.filter(s=>s.parent_subcircuit_id===a);for(const s of o)s.subcircuit_id&&(n.push(s.subcircuit_id),i(s.subcircuit_id))};return i(e),n},Nhe=({db:r,circuitJson:e,subcircuit_id:t,minTraceWidth:n=.1})=>{if(!r&&e&&(r=m1(e)),!r)throw new Error("db or circuitJson is required");const i=t?new Set([t]):null;if(t){const x=wtt(r,t);for(const M of x)i.add(M)}const a=(e??r.toArray()).filter(x=>!t||"subcircuit_id"in x&&i.has(x.subcircuit_id)),o=r.pcb_board.list()[0];r=m1(a);const s=XB(a),l=Rde([...r.pcb_component.list(),...r.pcb_smtpad.list(),...r.pcb_plated_hole.list(),...r.pcb_hole.list(),...r.pcb_via.list()].filter(x=>!t||(i==null?void 0:i.has(x.subcircuit_id))),s);for(const x of l){const M=x.connectedTo.flatMap(w=>s.getIdsConnectedToNet(w));x.connectedTo.push(...M)}const c=l.flatMap(x=>[{x:x.center.x-x.width/2,y:x.center.y-x.height/2},{x:x.center.x+x.width/2,y:x.center.y+x.height/2}]);let u;o?u={minX:o.center.x-o.width/2,maxX:o.center.x+o.width/2,minY:o.center.y-o.height/2,maxY:o.center.y+o.height/2}:u={minX:Math.min(...c.map(x=>x.x))-1,maxX:Math.max(...c.map(x=>x.x))+1,minY:Math.min(...c.map(x=>x.y))-1,maxY:Math.max(...c.map(x=>x.y))+1};const f=r.source_trace.list().map(x=>{const M=x.connected_source_port_ids.map(w=>{const T=r.source_port.get(w),L=r.pcb_port.getWhere({source_port_id:w});return{...T,...L}});return M.length<2?null:{name:x.source_trace_id??s.getNetConnectedToId(x.source_trace_id)??"",source_trace_id:x.source_trace_id,pointsToConnect:M.map(w=>{var T;return{x:w.x,y:w.y,layer:((T=w.layers)==null?void 0:T[0])??"top"}})}}).filter(x=>x!==null),v=r.source_net.list().filter(x=>!t||(i==null?void 0:i.has(x.subcircuit_id))),_=[];for(const x of v){const M=r.source_trace.list().filter(w=>{var T;return(T=w.connected_source_net_ids)==null?void 0:T.includes(x.source_net_id)});_.push({name:x.source_net_id??s.getNetConnectedToId(x.source_net_id),pointsToConnect:M.flatMap(w=>r.pcb_port.list().filter(L=>w.connected_source_port_ids.includes(L.source_port_id)).map(L=>{var O;return{x:L.x,y:L.y,layer:((O=L.layers)==null?void 0:O[0])??"top",pcb_port_id:L.pcb_port_id}}))})}return{simpleRouteJson:{bounds:u,obstacles:l,connections:[...f,..._],layerCount:2,minTraceWidth:n},connMap:s}},xH=class extends yx{constructor(){super(...arguments);rn(this,"pcb_group_id",null);rn(this,"subcircuit_id",null);rn(this,"_hasStartedAsyncAutorouting",!1);rn(this,"_asyncAutoroutingResult",null)}get config(){return{zodProps:WQe,componentName:"Group"}}doInitialSourceRender(){const{db:t}=this.root,n=t.source_group.insert({name:this._parsedProps.name,is_subcircuit:this.isSubcircuit});this.subcircuit_id=`subcircuit_${n.source_group_id}`,this.source_group_id=n.source_group_id,t.source_group.update(n.source_group_id,{subcircuit_id:this.subcircuit_id})}doInitialSourceParentAttachment(){var i,a,o;const{db:t}=this.root;if(!this.isSubcircuit)return;const n=(o=(a=(i=this.parent)==null?void 0:i.getSubcircuit)==null?void 0:a.call(i))==null?void 0:o.subcircuit_id;n&&t.source_group.update(this.source_group_id,{parent_subcircuit_id:n})}doInitialPcbComponentRender(){var a;if((a=this.root)!=null&&a.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,i=t.pcb_group.insert({is_subcircuit:this.isSubcircuit,subcircuit_id:this.subcircuit_id,name:this._parsedProps.name,center:this._getGlobalPcbPositionBeforeLayout(),width:0,height:0,pcb_component_ids:[],source_group_id:this.source_group_id});this.pcb_group_id=i.pcb_group_id}doInitialCreateTraceHintsFromProps(){var o;const{_parsedProps:t}=this,{db:n}=this.root,i=t;if(!this.isSubcircuit)return;const a=(o=i.layout)==null?void 0:o.manual_trace_hints;if(a)for(const s of a)this.add(new Ahe({for:s.pcb_port_selector,offsets:s.offsets}))}doInitialSourceAddConnectivityMapKey(){if(!this.isSubcircuit)return;const{db:t}=this.root,n=this.selectAll("trace"),i=new xN({});i.addConnections(n.map(a=>{const o=t.source_trace.get(a.source_trace_id);return o?[o.source_trace_id,...o.connected_source_port_ids,...o.connected_source_net_ids]:null}).filter(a=>a!==null));for(const a of n){if(!a.source_trace_id)continue;const o=i.getNetConnectedToId(a.source_trace_id);if(!o)continue;const{name:s}=this._parsedProps;a.subcircuit_connectivity_map_key=`${s??`unnamedsubcircuit${this._renderId}`}_${o}`,t.source_trace.update(a.source_trace_id,{subcircuit_connectivity_map_key:a.subcircuit_connectivity_map_key})}}_areChildSubcircuitsRouted(){const t=this.selectAll("group").filter(n=>n.isSubcircuit);for(const n of t)if(n._shouldRouteAsync()&&!n._asyncAutoroutingResult)return!1;return!0}_shouldRouteAsync(){const t=this._getAutorouterConfig();return t.groupMode==="sequential-trace"?!1:!!(t.local&&t.groupMode==="subcircuit"||!t.local)}_hasTracesToRoute(){const t=w9("tscircuit:core:_hasTracesToRoute"),n=this.selectAll("trace");return t(`[${this.getString()}] has ${n.length} traces to route`),n.length>0}async _runEffectMakeHttpAutoroutingRequest(){var u,f,v,_;const{db:t}=this.root,n=w9("tscircuit:core:_runEffectMakeHttpAutoroutingRequest");this._parsedProps;const i=this._getAutorouterConfig(),a=i.serverUrl,o=i.serverMode,s=(x,M)=>{var w;return n("fetching",x),M.headers&&(M.headers["Tscircuit-Core-Version"]=(w=this.root)==null?void 0:w.getCoreVersion()),fetch(x,M)},l=this.root.db.toArray().filter(x=>x.type.startsWith("source_")||x.type.startsWith("pcb_"));if(o==="solve-endpoint"){if(((u=this.props.autorouter)==null?void 0:u.inputFormat)==="simplified"){const{autorouting_result:M}=await s(`${a}/autorouting/solve`,{method:"POST",body:JSON.stringify({input_simple_route_json:Nhe({db:t,minTraceWidth:((f=this.props.autorouter)==null?void 0:f.minTraceWidth)??.15,subcircuit_id:this.subcircuit_id}).simpleRouteJson,subcircuit_id:this.subcircuit_id}),headers:{"Content-Type":"application/json"}}).then(w=>w.json());this._asyncAutoroutingResult=M,this._markDirty("PcbTraceRender");return}const{autorouting_result:x}=await s(`${a}/autorouting/solve`,{method:"POST",body:JSON.stringify({input_circuit_json:l,subcircuit_id:this.subcircuit_id}),headers:{"Content-Type":"application/json"}}).then(M=>M.json());this._asyncAutoroutingResult=x,this._markDirty("PcbTraceRender");return}const{autorouting_job:c}=await s(`${a}/autorouting/jobs/create`,{method:"POST",body:JSON.stringify({input_circuit_json:l,provider:"freerouting",autostart:!0,display_name:(v=this.root)==null?void 0:v.name,subcircuit_id:this.subcircuit_id,server_cache_enabled:i.serverCacheEnabled}),headers:{"Content-Type":"application/json"}}).then(x=>x.json());for(;;){const{autorouting_job:x}=await s(`${a}/autorouting/jobs/get`,{method:"POST",body:JSON.stringify({autorouting_job_id:c.autorouting_job_id}),headers:{"Content-Type":"application/json"}}).then(M=>M.json());if(x.is_finished){const{autorouting_job_output:M}=await s(`${a}/autorouting/jobs/get_output`,{method:"POST",body:JSON.stringify({autorouting_job_id:c.autorouting_job_id}),headers:{"Content-Type":"application/json"}}).then(w=>w.json());this._asyncAutoroutingResult={output_pcb_traces:M.output_pcb_traces},this._markDirty("PcbTraceRender");break}if(x.has_error)throw t.pcb_autorouting_error.insert({pcb_error_id:c.autorouting_job_id,message:((_=x.error)==null?void 0:_.message)??JSON.stringify(x.error)}),new Error(`Autorouting job failed: ${JSON.stringify(x.error)}`);await new Promise(M=>setTimeout(M,100))}}async _runLocalAutorouting(){var l,c,u,f,v;const{db:t}=this.root;this._parsedProps;const n=w9("tscircuit:core:_runLocalAutorouting");n(`[${this.getString()}] starting local autorouting`);const i=this._getAutorouterConfig(),{simpleRouteJson:a}=Nhe({db:t,minTraceWidth:((l=this.props.autorouter)==null?void 0:l.minTraceWidth)??.15,subcircuit_id:this.subcircuit_id});(c=this.root)==null||c.emit("autorouting:start",{subcircuit_id:this.subcircuit_id,componentDisplayName:this.getString(),simpleRouteJson:a});let o;i.algorithmFn?o=await i.algorithmFn(a):o=new Stt(a,{capacityDepth:(u=this.props.autorouter)==null?void 0:u.capacityDepth,targetMinCapacity:(f=this.props.autorouter)==null?void 0:f.targetMinCapacity});const s=new Promise((_,x)=>{o.on("complete",M=>{n(`[${this.getString()}] local autorouting complete`),_(M.traces)}),o.on("error",M=>{n(`[${this.getString()}] local autorouting error: ${M.error.message}`),x(M.error)})});o.on("progress",_=>{var x;(x=this.root)==null||x.emit("autorouting:progress",{subcircuit_id:this.subcircuit_id,componentDisplayName:this.getString(),..._})}),o.start();try{const _=await s;this._asyncAutoroutingResult={output_pcb_traces:_},this._markDirty("PcbTraceRender")}catch(_){const{db:x}=this.root;throw x.pcb_autorouting_error.insert({pcb_error_id:`pcb_autorouter_error_subcircuit_${this.subcircuit_id}`,message:_ instanceof Error?_.message:String(_)}),(v=this.root)==null||v.emit("autorouting:error",{subcircuit_id:this.subcircuit_id,componentDisplayName:this.getString(),error:{message:_ instanceof Error?_.message:String(_)},simpleRouteJson:a}),_}finally{o.stop()}}_startAsyncAutorouting(){this._hasStartedAsyncAutorouting||(this._hasStartedAsyncAutorouting=!0,this._getAutorouterConfig().local?this._queueAsyncEffect("capacity-mesh-autorouting",async()=>this._runLocalAutorouting()):this._queueAsyncEffect("make-http-autorouting-request",async()=>this._runEffectMakeHttpAutoroutingRequest()))}doInitialPcbTraceRender(){var n;const t=w9("tscircuit:core:doInitialPcbTraceRender");if(this.isSubcircuit&&!((n=this.root)!=null&&n.pcbDisabled)&&!this.getInheritedProperty("routingDisabled")&&!this._shouldUseTraceByTraceRouting()){if(!this._areChildSubcircuitsRouted()){t(`[${this.getString()}] child subcircuits are not routed, skipping async autorouting until subcircuits routed`);return}t(`[${this.getString()}] no child subcircuits to wait for, initiating async routing`),this._hasTracesToRoute()&&this._startAsyncAutorouting()}}updatePcbTraceRender(){var i;const t=w9("tscircuit:core:updatePcbTraceRender");if(t(`[${this.getString()}] updating...`),!this.isSubcircuit)return;if(this._shouldRouteAsync()&&this._hasTracesToRoute()&&!this._hasStartedAsyncAutorouting){this._areChildSubcircuitsRouted()&&(t(`[${this.getString()}] child subcircuits are now routed, starting async autorouting`),this._startAsyncAutorouting());return}if(!this._asyncAutoroutingResult||this._shouldUseTraceByTraceRouting())return;const{db:n}=this.root;if(this._asyncAutoroutingResult.output_simple_route_json){t(`[${this.getString()}] updating PCB traces from simple route json (${(i=this._asyncAutoroutingResult.output_simple_route_json.traces)==null?void 0:i.length} traces)`),this._updatePcbTraceRenderFromSimpleRouteJson();return}if(this._asyncAutoroutingResult.output_pcb_traces){t(`[${this.getString()}] updating PCB traces from ${this._asyncAutoroutingResult.output_pcb_traces.length} traces`),this._updatePcbTraceRenderFromPcbTraces();return}}_updatePcbTraceRenderFromSimpleRouteJson(){const{db:t}=this.root,{traces:n}=this._asyncAutoroutingResult.output_simple_route_json;if(n)for(const i of n)t.pcb_trace.insert({subcircuit_id:this.subcircuit_id,route:i.route})}_updatePcbTraceRenderFromPcbTraces(){const{output_pcb_traces:t}=this._asyncAutoroutingResult;if(!t)return;const{db:n}=this.root;for(const i of t){if(i.subcircuit_id=this.subcircuit_id,i.connection_name){const a=i.connection_name;i.source_trace_id=a}n.pcb_trace.insert(i)}for(const i of t)for(const a of i.route)a.route_type==="via"&&n.pcb_via.insert({pcb_trace_id:i.pcb_trace_id,x:a.x,y:a.y,hole_diameter:.3,outer_diameter:.6,layers:[a.from_layer,a.to_layer],from_layer:a.from_layer,to_layer:a.to_layer})}doInitialSchematicLayout(){if(!this.isSubcircuit||!this._parsedProps.schAutoLayoutEnabled)return;const{db:n}=this.root,i=this.getDescendants(),a=[];for(const l of i)if("schematic_component_id"in l){const c=n.schematic_component.get(l.schematic_component_id);if(c){const u=n.schematic_port.list().filter(f=>f.schematic_component_id===c.schematic_component_id);a.push(...u)}}const o=nJe(n.toArray()),s=fJe(o);tJe(n.toArray(),s)}_getAutorouterConfig(){const t={serverUrl:"https://registry-api.tscircuit.com",serverMode:"job",serverCacheEnabled:!0},n=this._parsedProps.autorouter??this.getInheritedProperty("autorouter");return typeof n=="object"?{local:!(n.serverUrl||n.serverMode||n.serverCacheEnabled),...t,...n}:n==="auto-local"?{local:!0,groupMode:"subcircuit"}:n==="sequential-trace"?{local:!0,groupMode:"sequential-trace"}:n==="subcircuit"?{local:!0,groupMode:"subcircuit"}:n==="auto-cloud"?{local:!1,groupMode:"subcircuit",serverUrl:t.serverUrl,serverMode:t.serverMode,serverCacheEnabled:!0}:{local:!0,groupMode:"subcircuit"}}_shouldUseTraceByTraceRouting(){return this._getAutorouterConfig().groupMode==="sequential-trace"}},Ttt=class extends xH{constructor(){super(...arguments);rn(this,"pcb_board_id",null)}get isSubcircuit(){return!0}get config(){return{componentName:"Board",zodProps:zde}}get boardThickness(){const{_parsedProps:e}=this;return 1.4}get allLayers(){return["top","bottom","inner1","inner2"]}doInitialPcbBoardAutoSize(){var f;if((f=this.root)!=null&&f.pcbDisabled||!this.pcb_board_id)return;const{db:e}=this.root,{_parsedProps:t}=this;if(t.width&&t.height)return;let n=1/0,i=1/0,a=-1/0,o=-1/0;for(const v of this.children){if(!v.pcb_component_id)continue;const _=e.pcb_component.get(v.pcb_component_id);if(!_)continue;const{width:x,height:M,center:w}=_;x===0||M===0||(n=Math.min(n,w.x-x/2),i=Math.min(i,w.y-M/2),a=Math.max(a,w.x+x/2),o=Math.max(o,w.y+M/2))}const s=2,l=a-n+s*2,c=o-i+s*2,u={x:(n+a)/2+(t.outlineOffsetX??0),y:(i+o)/2+(t.outlineOffsetY??0)};e.pcb_board.update(this.pcb_board_id,{width:l,height:c,center:u})}doInitialPcbComponentRender(){var o,s;if((o=this.root)!=null&&o.pcbDisabled)return;const{db:e}=this.root,{_parsedProps:t}=this;let n=t.width??0,i=t.height??0;if(t.outline){const l=t.outline.map(x=>x.x),c=t.outline.map(x=>x.y),u=Math.min(...l),f=Math.max(...l),v=Math.min(...c),_=Math.max(...c);n=f-u,i=_-v}const a=e.pcb_board.insert({center:{x:(t.pcbX??0)+(t.outlineOffsetX??0),y:(t.pcbY??0)+(t.outlineOffsetY??0)},thickness:this.boardThickness,num_layers:this.allLayers.length,width:n,height:i,outline:(s=t.outline)==null?void 0:s.map(l=>({x:l.x+(t.outlineOffsetX??0),y:l.y+(t.outlineOffsetY??0)}))});this.pcb_board_id=a.pcb_board_id}removePcbComponentRender(){const{db:e}=this.root;this.pcb_board_id&&(e.pcb_board.delete(this.pcb_board_id),this.pcb_board_id=null)}_computePcbGlobalTransformBeforeLayout(){return K_()}},Mtt=new Proxy({},{get:(r,e)=>e}),nM=Mtt,Ctt=class extends yx{get config(){return{componentName:"Capacitor",schematicSymbolName:this.props.polarized?"capacitor_polarized":this.props.symbolName??"capacitor",zodProps:nKe,sourceFtype:nM.simple_capacitor}}initPorts(){super.initPorts({additionalAliases:{pin1:["anode","pos","left"],pin2:["cathode","neg","right"]}})}_getSchematicSymbolDisplayValue(){const r=`${zN(this._parsedProps.capacitance)}F`;return this._parsedProps.schShowRatings&&this._parsedProps.maxVoltageRating?`${r}/${zN(this._parsedProps.maxVoltageRating)}V`:r}doInitialCreateNetsFromProps(){this._createNetsFromProps([this.props.decouplingFor,this.props.decouplingTo,...this._getNetsFromConnectionsProp()])}doInitialCreateTracesFromProps(){this.props.decouplingFor&&this.props.decouplingTo&&(this.add(new xE({from:`${this.getSubcircuitSelector()} > port.1`,to:this.props.decouplingFor})),this.add(new xE({from:`${this.getSubcircuitSelector()} > port.2`,to:this.props.decouplingTo})))}doInitialSourceRender(){const{db:r}=this.root,{_parsedProps:e}=this,t=r.source_component.insert({ftype:"simple_capacitor",name:e.name,manufacturer_part_number:e.manufacturerPartNumber??e.mfn,supplier_part_numbers:e.supplierPartNumbers,capacitance:e.capacitance,max_voltage_rating:e.maxVoltageRating,max_decoupling_trace_length:e.maxDecouplingTraceLength,display_capacitance:this._getSchematicSymbolDisplayValue()});this.source_component_id=t.source_component_id}},Phe=class extends yx{constructor(){super(...arguments);rn(this,"schematicBoxDimensions",null)}get config(){return{componentName:"Chip",zodProps:$Qe,shouldRenderAsSchematicBox:!0}}doInitialSchematicComponentRender(){const{_parsedProps:e}=this;(e==null?void 0:e.noSchematicRepresentation)!==!0&&super.doInitialSchematicComponentRender()}doInitialSourceRender(){const{db:e}=this.root,{_parsedProps:t}=this,n=e.source_component.insert({ftype:"simple_chip",name:t.name,manufacturer_part_number:t.manufacturerPartNumber,supplier_part_numbers:t.supplierPartNumbers});this.source_component_id=n.source_component_id}doInitialPcbComponentRender(){var i;if((i=this.root)!=null&&i.pcbDisabled)return;const{db:e}=this.root,{_parsedProps:t}=this,n=e.pcb_component.insert({center:{x:t.pcbX??0,y:t.pcbY??0},width:2,height:3,layer:t.layer??"top",rotation:t.pcbRotation??0,source_component_id:this.source_component_id,subcircuit_id:this.getSubcircuit().subcircuit_id??void 0});this.pcb_component_id=n.pcb_component_id}doInitialCreateTracesFromProps(){const{_parsedProps:e}=this;if(e.externallyConnectedPins)for(const[t,n]of e.externallyConnectedPins)this.add(new xE({from:`${this.getSubcircuitSelector()} > port.${t}`,to:`${this.getSubcircuitSelector()} > port.${n}`}));this._createTracesFromConnectionsProp()}},Rtt=class extends yx{constructor(){super(...arguments);rn(this,"pos",this.portMap.pin1);rn(this,"anode",this.portMap.pin1);rn(this,"neg",this.portMap.pin2);rn(this,"cathode",this.portMap.pin2)}get config(){return{schematicSymbolName:this.props.symbolName??"diode",componentName:"Diode",zodProps:MKe,sourceFtype:"simple_diode"}}initPorts(){super.initPorts({additionalAliases:{pin1:["anode","pos","left"],pin2:["cathode","neg","right"]}})}},Att=class extends yx{constructor(){super(...arguments);rn(this,"schematicDimensions",null)}get config(){return{componentName:"Jumper",zodProps:ZQe,shouldRenderAsSchematicBox:!0}}doInitialSourceRender(){const{db:e}=this.root,{_parsedProps:t}=this,n=e.source_component.insert({ftype:"simple_chip",name:t.name,manufacturer_part_number:t.manufacturerPartNumber,supplier_part_numbers:t.supplierPartNumbers});this.source_component_id=n.source_component_id}doInitialPcbComponentRender(){var i;if((i=this.root)!=null&&i.pcbDisabled)return;const{db:e}=this.root,{_parsedProps:t}=this,n=e.pcb_component.insert({center:{x:t.pcbX??0,y:t.pcbY??0},width:2,height:3,layer:t.layer??"top",rotation:t.pcbRotation??0,source_component_id:this.source_component_id,subcircuit_id:this.getSubcircuit().subcircuit_id??void 0});this.pcb_component_id=n.pcb_component_id}},Ntt=class extends yx{constructor(){super(...arguments);rn(this,"pos",this.portMap.pin1);rn(this,"anode",this.portMap.pin1);rn(this,"neg",this.portMap.pin2);rn(this,"cathode",this.portMap.pin2)}get config(){return{componentName:"Led",schematicSymbolName:this.props.symbolName??"led",zodProps:CKe,sourceFtype:"simple_diode"}}initPorts(){super.initPorts({additionalAliases:{pin1:["anode","pos","left"],pin2:["cathode","neg","right"]}})}},Ptt=class extends yx{constructor(){super(...arguments);rn(this,"pos",this.portMap.pin1);rn(this,"positive",this.portMap.pin1);rn(this,"neg",this.portMap.pin2);rn(this,"negative",this.portMap.pin2)}get config(){return{schematicSymbolName:this.props.symbolName??"power_factor_meter_horz",componentName:"PowerSource",zodProps:LKe,sourceFtype:"simple_power_source"}}initPorts(){this.add(new TS({name:"pin1",pinNumber:1,aliases:["positive","pos"]})),this.add(new TS({name:"pin2",pinNumber:2,aliases:["negative","neg"]}))}},Dtt=class extends yx{get config(){return{componentName:"Resistor",schematicSymbolName:this.props.symbolName??"boxresistor",zodProps:KQe,sourceFtype:"simple_resistor"}}initPorts(){super.initPorts({additionalAliases:{pin1:["anode","pos","left"],pin2:["cathode","neg","right"]}})}_getSchematicSymbolDisplayValue(){return`${zN(this._parsedProps.resistance)}Ω`}doInitialCreateNetsFromProps(){this._createNetsFromProps([this.props.pullupFor,this.props.pullupTo,...this._getNetsFromConnectionsProp()])}doInitialCreateTracesFromProps(){this.props.pullupFor&&this.props.pullupTo&&(this.add(new xE({from:`${this.getSubcircuitSelector()} > port.1`,to:this.props.pullupFor})),this.add(new xE({from:`${this.getSubcircuitSelector()} > port.2`,to:this.props.pullupTo})))}doInitialSourceRender(){const{db:r}=this.root,{_parsedProps:e}=this,t=r.source_component.insert({ftype:"simple_resistor",name:e.name,manufacturer_part_number:e.manufacturerPartNumber??e.mfn,supplier_part_numbers:e.supplierPartNumbers,resistance:e.resistance,display_resistance:this._getSchematicSymbolDisplayValue()});this.source_component_id=t.source_component_id}},Ltt=["leftedge","rightedge","topedge","bottomedge","center"],Ott=class extends T9{get config(){return{componentName:"Constraint",zodProps:sKe}}constructor(r){if(super(r),("xdist"in r||"ydist"in r)&&!("edgeToEdge"in r)&&!("centerToCenter"in r))throw new Error(`edgeToEdge, centerToCenter must be set for xDist or yDist for ${this}`);if("for"in r&&r.for.length<2)throw new Error(`"for" must have at least two selectors for ${this}`)}_getAllReferencedComponents(){const r=[],e=this.getPrimitiveContainer();function t(n){const i=n.split(" ").pop(),a=Ltt.includes(i)?i:void 0,o=a?n.replace(` ${a}`,""):n,s=e.selectOne(o,{pcbPrimitive:!0});s&&r.push({selector:n,component:s,componentSelector:o,edge:a})}for(const n of["left","right","top","bottom"])n in this._parsedProps&&t(this._parsedProps[n]);if("for"in this._parsedProps)for(const n of this._parsedProps.for)t(n);return{componentsWithSelectors:r}}},Utt=class extends T9{constructor(){super(...arguments);rn(this,"fabrication_note_path_id",null)}get config(){return{componentName:"FabricationNotePath",zodProps:NKe}}doInitialPcbPrimitiveRender(){var s,l;if((s=this.root)!=null&&s.pcbDisabled)return;const{db:e}=this.root,t=this.getSubcircuit(),{_parsedProps:n}=this,i=n.layer??"top";if(i!=="top"&&i!=="bottom")throw new Error(`Invalid layer "${i}" for SilkscreenPath. Must be "top" or "bottom".`);const a=this._computePcbGlobalTransformBeforeLayout(),o=e.pcb_fabrication_note_path.insert({pcb_component_id:(l=this.parent)==null?void 0:l.pcb_component_id,layer:i,color:n.color,route:n.route.map(c=>{const u=ai(a,{x:c.x,y:c.y});return{...c,x:u.x,y:u.y}}),stroke_width:n.strokeWidth??.1,subcircuit_id:(t==null?void 0:t.subcircuit_id)??void 0});this.fabrication_note_path_id=o.pcb_fabrication_note_path_id}},ztt=class extends T9{get config(){return{componentName:"FabricationNoteText",zodProps:AKe}}doInitialPcbPrimitiveRender(){var i,a;if((i=this.root)!=null&&i.pcbDisabled)return;const{db:r}=this.root,{_parsedProps:e}=this,t=this.getPrimitiveContainer(),n=this.getSubcircuit();r.pcb_fabrication_note_text.insert({anchor_alignment:e.anchorAlignment,anchor_position:{x:e.pcbX??0,y:e.pcbY??0},font:e.font??"tscircuit2024",font_size:e.fontSize??1,layer:"top",color:e.color,text:e.text??"",pcb_component_id:t.pcb_component_id,subcircuit_id:(n==null?void 0:n.subcircuit_id)??void 0,pcb_group_id:((a=this.getGroup())==null?void 0:a.pcb_group_id)??void 0})}},Itt=class extends xH{constructor(r){super({...r,subcircuit:!0})}},ktt=class extends T9{constructor(){super(...arguments);rn(this,"source_net_alias_id")}get config(){return{componentName:"NetAlias",zodProps:bKe}}doInitialSchematicComponentRender(){var a;if((a=this.root)!=null&&a.schematicDisabled)return;const{db:e}=this.root,{_parsedProps:t}=this,n={x:t.schX??0,y:t.schY??0},i=e.schematic_net_label.insert({text:t.net,source_net_id:t.net,anchor_position:n,center:n,anchor_side:"bottom"});this.source_net_alias_id=i.source_net_id}},Ftt=class extends T9{constructor(){super(...arguments);rn(this,"pcb_silkscreen_circle_id",null);rn(this,"isPcbPrimitive",!0)}get config(){return{componentName:"SilkscreenCircle",zodProps:kKe}}doInitialPcbPrimitiveRender(){var s,l,c;if((s=this.root)!=null&&s.pcbDisabled)return;const{db:e}=this.root,{_parsedProps:t}=this,{maybeFlipLayer:n}=this._getPcbPrimitiveFlippedHelpers(),i=n(t.layer??"top");if(i!=="top"&&i!=="bottom")throw new Error(`Invalid layer "${i}" for SilkscreenCircle. Must be "top" or "bottom".`);this._computePcbGlobalTransformBeforeLayout();const a=this.getSubcircuit(),o=e.pcb_silkscreen_circle.insert({pcb_component_id:(l=this.parent)==null?void 0:l.pcb_component_id,layer:i,center:{x:t.pcbX??0,y:t.pcbY??0},radius:t.radius,subcircuit_id:(a==null?void 0:a.subcircuit_id)??void 0,pcb_group_id:((c=this.getGroup())==null?void 0:c.pcb_group_id)??void 0,stroke_width:t.strokeWidth??.1});this.pcb_silkscreen_circle_id=o.pcb_silkscreen_circle_id}getPcbSize(){const{_parsedProps:e}=this,t=e.radius*2;return{width:t,height:t}}},Btt=class extends T9{constructor(){super(...arguments);rn(this,"pcb_silkscreen_rect_id",null);rn(this,"isPcbPrimitive",!0)}get config(){return{componentName:"SilkscreenRect",zodProps:IKe}}doInitialPcbPrimitiveRender(){var s,l,c;if((s=this.root)!=null&&s.pcbDisabled)return;const{db:e}=this.root,{_parsedProps:t}=this,{maybeFlipLayer:n}=this._getPcbPrimitiveFlippedHelpers(),i=n(t.layer??"top");if(i!=="top"&&i!=="bottom")throw new Error(`Invalid layer "${i}" for SilkscreenRect. Must be "top" or "bottom".`);const a=this.getSubcircuit(),o=e.pcb_silkscreen_rect.insert({pcb_component_id:(l=this.parent)==null?void 0:l.pcb_component_id,layer:i,center:{x:t.pcbX??0,y:t.pcbY??0},width:t.width,height:t.height,subcircuit_id:(a==null?void 0:a.subcircuit_id)??void 0,pcb_group_id:((c=this==null?void 0:this.getGroup())==null?void 0:c.pcb_group_id)??void 0,stroke_width:t.strokeWidth??.1});this.pcb_silkscreen_rect_id=o.pcb_silkscreen_rect_id}getPcbSize(){const{_parsedProps:e}=this;return{width:e.width,height:e.height}}},Htt=class extends T9{constructor(){super(...arguments);rn(this,"pcb_silkscreen_line_id",null);rn(this,"isPcbPrimitive",!0)}get config(){return{componentName:"SilkscreenLine",zodProps:zKe}}doInitialPcbPrimitiveRender(){var s,l,c;if((s=this.root)!=null&&s.pcbDisabled)return;const{db:e}=this.root,{_parsedProps:t}=this,{maybeFlipLayer:n}=this._getPcbPrimitiveFlippedHelpers(),i=n(t.layer??"top");if(i!=="top"&&i!=="bottom")throw new Error(`Invalid layer "${i}" for SilkscreenLine. Must be "top" or "bottom".`);const a=this.getSubcircuit(),o=e.pcb_silkscreen_line.insert({pcb_component_id:(l=this.parent)==null?void 0:l.pcb_component_id,layer:i,x1:t.x1,y1:t.y1,x2:t.x2,y2:t.y2,stroke_width:t.strokeWidth??.1,subcircuit_id:(a==null?void 0:a.subcircuit_id)??void 0,pcb_group_id:((c=a==null?void 0:a.getGroup())==null?void 0:c.pcb_group_id)??void 0});this.pcb_silkscreen_line_id=o.pcb_silkscreen_line_id}getPcbSize(){const{_parsedProps:e}=this,t=Math.abs(e.x2-e.x1),n=Math.abs(e.y2-e.y1);return{width:t,height:n}}},jtt=class extends T9{constructor(){super(...arguments);rn(this,"pcb_via_id",null);rn(this,"matchedPort",null);rn(this,"isPcbPrimitive",!0)}get config(){return{componentName:"Via",zodProps:PKe}}getAvailablePcbLayers(){return["top","inner1","inner2","bottom"]}getPcbSize(){const{_parsedProps:e}=this;return{width:e.outerDiameter,height:e.outerDiameter}}_getPcbCircuitJsonBounds(){const{db:e}=this.root,t=e.pcb_via.get(this.pcb_via_id),n=this.getPcbSize();return{center:{x:t.x,y:t.y},bounds:{left:t.x-n.width/2,top:t.y-n.height/2,right:t.x+n.width/2,bottom:t.y+n.height/2},width:n.width,height:n.height}}_setPositionFromLayout(e){const{db:t}=this.root;t.pcb_via.update(this.pcb_via_id,{x:e.x,y:e.y})}doInitialPcbPrimitiveRender(){var o,s;if((o=this.root)!=null&&o.pcbDisabled)return;const{db:e}=this.root,{_parsedProps:t}=this,n=this._getGlobalPcbPositionBeforeLayout(),i=this.getSubcircuit(),a=e.pcb_via.insert({x:n.x,y:n.y,hole_diameter:t.holeDiameter,outer_diameter:t.outerDiameter,layers:["bottom","top"],from_layer:t.fromLayer||"bottom",to_layer:t.toLayer||"top",subcircuit_id:(i==null?void 0:i.subcircuit_id)??void 0,pcb_group_id:((s=this.getGroup())==null?void 0:s.pcb_group_id)??void 0});this.pcb_via_id=a.pcb_via_id}},Vtt=class extends yx{get config(){return{componentName:"Battery",schematicSymbolName:this.props.symbolName??"battery",zodProps:_Ke,sourceFtype:"simple_power_source"}}initPorts(){super.initPorts({additionalAliases:{pin1:["anode","pos","left"],pin2:["cathode","neg","right"]}})}doInitialSourceRender(){const{db:r}=this.root,{_parsedProps:e}=this,t=r.source_component.insert({name:e.name,ftype:"simple_power_source",capacity:e.capacity,supplier_part_numbers:e.supplierPartNumbers});this.source_component_id=t.source_component_id}},Gtt=class extends yx{get config(){return{componentName:"PinHeader",zodProps:xKe,shouldRenderAsSchematicBox:!0}}_getImpliedFootprintString(){var i;const r=this._parsedProps.pinCount??((i=this._parsedProps.pinLabels)==null?void 0:i.length)??0,e=this._parsedProps.holeDiameter,t=this._parsedProps.platedDiameter,n=this._parsedProps.pitch;return r>0&&n?!e&&!t?`pinrow${r}_p${n}`:`pinrow${r}_p${n}_id${e}_od${t}`:null}initPorts(){var e,t;const r=this._parsedProps.pinCount??((e=this._parsedProps.pinLabels)==null?void 0:e.length)??1;for(let n=1;n<=r;n++)this.add(new TS({name:`pin${n}`,pinNumber:n,aliases:[(t=this._parsedProps.pinLabels)==null?void 0:t[n-1]].filter(Boolean)}))}_getSchematicPortArrangement(){const r=this._parsedProps.pinCount??1,e=this._parsedProps.facingDirection??"right";return{leftSize:e==="left"?r:0,rightSize:e==="right"?r:0}}doInitialSourceRender(){const{db:r}=this.root,{_parsedProps:e}=this,t=r.source_component.insert({ftype:"simple_pin_header",name:e.name,supplier_part_numbers:e.supplierPartNumbers,pin_count:e.pinCount,gender:e.gender});this.source_component_id=t.source_component_id}};function qtt(r){switch(r){case"two_ground_pins":return"crystal_4pin";case"ground_pin":return"resonator";case"no_ground":return"crystal";default:return"crystal"}}var Wtt=class extends yx{get config(){return{componentName:"Resonator",schematicSymbolName:this.props.symbolName??qtt(this.props.pinVariant),zodProps:tKe,shouldRenderAsSchematicBox:!1}}doInitialSourceRender(){const{db:r}=this.root,{_parsedProps:e}=this,t=r.source_component.insert({ftype:"simple_resonator",name:e.name,frequency:e.frequency,load_capacitance:e.loadCapacitance,supplier_part_numbers:e.supplierPartNumbers,pin_variant:e.pinVariant||"no_ground"});this.source_component_id=t.source_component_id}},Ytt=class extends yx{get config(){return{componentName:"Inductor",schematicSymbolName:this.props.symbolName??"inductor",zodProps:TKe,sourceFtype:nM.simple_inductor}}initPorts(){super.initPorts({additionalAliases:{pin1:["anode","pos","left"],pin2:["cathode","neg","right"]}})}doInitialSourceRender(){const{db:r}=this.root,{_parsedProps:e}=this,t=r.source_component.insert({name:e.name,ftype:nM.simple_inductor,inductance:e.inductance,supplier_part_numbers:e.supplierPartNumbers});this.source_component_id=t.source_component_id}};function Xtt(r){switch(r){case"three_pin":return"potentiometer3";case"two_pin":return"potentiometer2";default:return"potentiometer2"}}var $tt=class extends yx{get config(){return{componentName:"Potentiometer",schematicSymbolName:this.props.symbolName??Xtt(this.props.pinVariant),zodProps:JQe,shouldRenderAsSchematicBox:!1}}doInitialSourceRender(){const{db:r}=this.root,{_parsedProps:e}=this,t=r.source_component.insert({ftype:"simple_potentiometer",name:e.name,max_resistance:e.maxResistance,pin_variant:e.pinVariant||"two_pin"});this.source_component_id=t.source_component_id}},Ztt=class extends yx{get config(){return{componentName:"PushButton",schematicSymbolName:this.props.symbolName??"push_button_normally_open_momentary",zodProps:SKe,sourceFtype:nM.simple_push_button}}get defaultInternallyConnectedPinNames(){return[["pin1","pin4"],["pin2","pin3"]]}initPorts(){super.initPorts({pinCount:4,additionalAliases:{pin1:["side1"],pin3:["side2"]}})}doInitialSourceRender(){const{db:e}=this.root,{_parsedProps:t}=this,n=e.source_component.insert({name:t.name,ftype:nM.simple_push_button,supplier_part_numbers:t.supplierPartNumbers});this.source_component_id=n.source_component_id}},Qtt=class extends yx{get config(){return{schematicSymbolName:this.props.symbolName??(this.props.pinVariant==="four_pin"?"crystal_4pin":"crystal"),componentName:"Crystal",zodProps:eKe,sourceFtype:"simple_crystal"}}initPorts(){const r=this.props.pinVariant==="four_pin"?{pin1:["left1","1"],pin2:["top1","2","gnd1"],pin3:["right1","3"],pin4:["bottom1","4","gnd2"]}:{pin1:["pos","left"],pin2:["neg","right"]};super.initPorts({additionalAliases:r})}_getSchematicSymbolDisplayValue(){return`${zN(this._parsedProps.frequency)}Hz`}doInitialSourceRender(){const{db:r}=this.root,{_parsedProps:e}=this,t=r.source_component.insert({name:e.name,ftype:"simple_crystal",frequency:e.frequency,load_capacitance:e.loadCapacitance,pin_variant:e.pinVariant||"two_pin"});this.source_component_id=t.source_component_id}},Ktt=class extends yx{constructor(){super(...arguments);rn(this,"emitter",this.portMap.pin1);rn(this,"collector",this.portMap.pin2);rn(this,"base",this.portMap.pin3)}get config(){return{componentName:"Transistor",schematicSymbolName:this.props.type==="npn"?"npn_bipolar_transistor":"pnp_bipolar_transistor",zodProps:EKe,sourceFtype:"simple_transistor",shouldRenderAsSchematicBox:!1}}initPorts(){super.initPorts({pinCount:3,additionalAliases:{pin1:["emitter","e"],pin2:["collector","c"],pin3:["base","b"]}})}doInitialSourceRender(){const{db:e}=this.root,{_parsedProps:t}=this,n=e.source_component.insert({ftype:"simple_transistor",name:t.name,transistor_type:t.type});this.source_component_id=n.source_component_id}},Jtt=class extends yx{get config(){const r=this.props.mosfetMode==="depletion"?"d":"e";return{componentName:"Mosfet",schematicSymbolName:`${this.props.channelType}_channel_${r}_mosfet_transistor`,zodProps:wKe,shouldRenderAsSchematicBox:!1}}doInitialSourceRender(){const{db:r}=this.root,{_parsedProps:e}=this,t=r.source_component.insert({ftype:"simple_mosfet",name:e.name,mosfet_mode:e.mosfetMode,channel_type:e.channelType});this.source_component_id=t.source_component_id}},ent=class extends yx{_getSwitchType(){const{spst:r,spdt:e,dpst:t,dpdt:n,type:i}=this._parsedProps??{};return n?"dpdt":r?"spst":e?"spdt":t?"dpst":i??"spst"}get config(){const r=this._getSwitchType(),{isNormallyClosed:e}=this._parsedProps??{};return{componentName:"Switch",schematicSymbolName:{spst:e?"spst_normally_closed_switch":"SPST_switch",spdt:e?"spdt_normally_closed_switch":"SPDT_switch",dpst:e?"dpst_normally_closed_switch":"dpst_switch",dpdt:e?"dpdt_normally_closed_switch":"dpdt_switch"}[r]??"SPST_switch",zodProps:RKe,shouldRenderAsSchematicBox:!1}}doInitialSourceRender(){const{db:r}=this.root,{_parsedProps:e}=this,t=r.source_component.insert({ftype:"simple_switch",name:e.name,switch_type:e.type,is_normally_closed:e.isNormallyClosed??!1});this.source_component_id=t.source_component_id}},tnt={version:"0.0.349"},Dhe=class{constructor(){rn(this,"firstChild",null);rn(this,"children");rn(this,"db");rn(this,"root",null);rn(this,"isRoot",!0);rn(this,"schematicDisabled",!1);rn(this,"pcbDisabled",!1);rn(this,"pcbRoutingDisabled",!1);rn(this,"name");rn(this,"_hasRenderedAtleastOnce",!1);rn(this,"_eventListeners",{});this.children=[],this.db=m1([]),this.root=this}add(r){let e;ut.isValidElement(r)?e=mhe(r):e=r,this.children.push(e)}_getBoard(){return this.children.find(r=>r.componentName==="Board")}_guessRootComponent(){if(!this.firstChild){if(this.children.length===1){this.firstChild=this.children[0];return}if(this.children.length===0)throw new Error("Not able to guess root component: RootCircuit has no children (use circuit.add(...))");if(this.children.length>0){const r=this.children.find(e=>e.componentName==="Board")??null;if(r){this.firstChild=r;return}}throw new Error("Not able to guess root component: RootCircuit has multiple children and no board")}}render(){this.firstChild||this._guessRootComponent();const{firstChild:r,db:e}=this;if(!r)throw new Error("RootCircuit has no root component");r.parent=this,r.runRenderCycle(),this._hasRenderedAtleastOnce=!0}async renderUntilSettled(){var r;for((r=this.db.source_project_metadata.list())!=null&&r[0]||this.db.source_project_metadata.insert({software_used_string:`@tscircuit/core@${this.getCoreVersion()}`}),this.render();this._hasIncompleteAsyncEffects();)await new Promise(e=>setTimeout(e,100)),this.render();this.emit("renderComplete")}_hasIncompleteAsyncEffects(){return this.children.some(r=>r._hasIncompleteAsyncEffects()?!0:r.children.some(e=>e._hasIncompleteAsyncEffects()))}getCircuitJson(){return this._hasRenderedAtleastOnce||this.render(),this.db.toArray()}toJson(){return this.getCircuitJson()}async getSvg(r){return(await Promise.resolve().then(()=>fOt).catch(t=>{throw new Error(`To use circuit.getSvg, you must install the "circuit-to-svg" package.
814
+ searched component ${c.getString()}, which has ports: ${c.children.filter(u=>u.componentName==="Port").map(u=>`${u.getString()}(${u.getNameAndAliases().join(",")})`).join(" & ")}`):this.renderError(`Could not find port for selector "${o}"`)}return a.some(o=>!o.port)?{allPortsFound:!1}:{allPortsFound:!0,portsWithSelectors:a,ports:a.map(({port:o})=>o)}}_findConnectedNets(){const e=this.getTracePathNetSelectors().map(n=>({selector:n,net:this.getSubcircuit().selectOne(n,{type:"net"})})),t=e.filter(n=>!n.net);return t.length>0&&this.renderError(`Could not find net for selector "${t[0].selector}" inside ${this}`),{netsWithSelectors:e,nets:e.map(n=>n.net)}}_getAllTracesConnectedToSameNet(){const e=this.getSubcircuit().selectAll("trace"),t=this._findConnectedNets().nets,n=this._findConnectedPorts().ports??[];return e.filter(i=>{if(i===this)return!1;const a=i._findConnectedNets().nets,o=i._findConnectedPorts().ports??[];return a.some(s=>t.includes(s))||o.some(s=>n.includes(s))})}_isExplicitlyConnectedToPort(e){const{allPortsFound:t,portsWithSelectors:n}=this._findConnectedPorts();return t?n.map(a=>a.port).includes(e):!1}_isExplicitlyConnectedToNet(e){return this._findConnectedNets().nets.includes(e)}doInitialCreateNetsFromProps(){ghe(this,this.getTracePathNetSelectors())}doInitialSourceTraceRender(){var c;const{db:e}=this.root,{_parsedProps:t,parent:n}=this;if(!n){this.renderError("Trace has no parent");return}const{allPortsFound:i,portsWithSelectors:a}=this._findConnectedPorts();if(!i)return;const o=this._findConnectedNets().nets,s=ytt({ports:a,nets:o}),l=e.source_trace.insert({connected_source_port_ids:a.map(u=>u.port.source_port_id),connected_source_net_ids:o.map(u=>u.source_net_id),subcircuit_id:(c=this.getSubcircuit())==null?void 0:c.subcircuit_id,max_length:mtt(a.map(u=>u.port),{db:e})??t.maxLength,display_name:s,min_trace_thickness:t.thickness});this.source_trace_id=l.source_trace_id}_insertErrorIfTraceIsOutsideBoard(e,t){const{db:n}=this.root;_tt(e,{db:n})&&n.pcb_trace_error.insert({error_type:"pcb_trace_error",source_trace_id:this.source_trace_id,message:`Trace ${this.getString()} routed outside the board boundaries.`,pcb_trace_id:this.pcb_trace_id,pcb_component_ids:[],pcb_port_ids:t.map(a=>a.pcb_port_id)})}doInitialPcbTraceRender(){var ee,ae,K,pe;if((ee=this.root)!=null&&ee.pcbDisabled)return;const{db:e}=this.root,{_parsedProps:t,parent:n}=this,i=this.getSubcircuit();if(!n)throw new Error("Trace has no parent");if(i._parsedProps.routingDisabled)return;const a=(ae=i._parsedProps.pcbRouteCache)==null?void 0:ae.pcbTraces;if(a){const me=e.pcb_trace.insert({route:a.flatMap(be=>be.route),source_trace_id:this.source_trace_id,subcircuit_id:(i==null?void 0:i.subcircuit_id)??void 0,pcb_group_id:((K=this.getGroup())==null?void 0:K.pcb_group_id)??void 0});this.pcb_trace_id=me.pcb_trace_id;return}if(!i._shouldUseTraceByTraceRouting())return;const{allPortsFound:o,ports:s}=this._findConnectedPorts();if(!o)return;const l=[];for(const me of s)me._hasMatchedPcbPrimitive()||l.push(me);if(l.length>0){e.pcb_trace_error.insert({error_type:"pcb_trace_error",source_trace_id:this.source_trace_id,message:`Some ports did not have a matching PCB primitive (e.g. a pad or plated hole), this can happen if a footprint is missing. As a result, ${this} wasn't routed. Missing ports: ${l.map(me=>me.getString()).join(", ")}`,pcb_trace_id:this.pcb_trace_id,pcb_component_ids:[],pcb_port_ids:l.map(me=>me.pcb_port_id).filter(Boolean)});return}const c=this._findConnectedNets().netsWithSelectors;if(s.length===0&&c.length===2){this.renderError("Trace connects two nets, we haven't implemented a way to route this yet");return}else if(s.length===1&&c.length===1){const me=s[0],Ae=c[0].net.getAllConnectedPorts().filter(we=>we!==me);if(Ae.length===0){console.log("Nothing to connect this port to, the net is empty. TODO should emit a warning!");return}const Oe=stt(me,Ae);s.push(Oe)}else if(s.length>1&&c.length>=1){this.renderError("Trace has more than one port and one or more nets, we don't currently support this type of complex trace routing");return}const u=s.flatMap(me=>me.matchedComponents.filter(be=>be.componentName==="TraceHint")),f=(this._parsedProps.pcbRouteHints??[]).concat(u.flatMap(me=>me.getPcbRouteHints()));if(s.length>2){this.renderError(`Trace has more than two ports (${s.map(me=>me.getString()).join(", ")}), routing between more than two ports for a single trace is not implemented`);return}if(this.getSubcircuit().selectAll("trace").filter(me=>me.renderPhaseStates.PcbTraceRender.initialized).some(me=>me._portsRoutedOnPcb.length===s.length&&me._portsRoutedOnPcb.every(be=>s.includes(be))))return;let x=[];f.length===0?x=[BN(s[0]),BN(s[1])]:x=[BN(s[0]),...f,BN(s[1])];const M=kN(x),w=XB(this.root.db.toArray()),[T,L]=ctt(()=>Rde(this.root.db.toArray()));if(L){this.renderError({type:"pcb_trace_error",error_type:"pcb_trace_error",pcb_trace_error_id:this.pcb_trace_id,message:`Error getting obstacles for autorouting: ${L.message}`,source_trace_id:this.source_trace_id,center:{x:0,y:0},pcb_port_ids:s.map(me=>me.pcb_port_id),pcb_trace_id:this.pcb_trace_id,pcb_component_ids:[]});return}for(const me of T)if(me.connectedTo.length>0){const Ae=w.getNetConnectedToId(me.connectedTo[0]);Ae&&me.connectedTo.push(Ae)}let O=[];if(M.length===0)O=x;else{const me=M[0].layer_path;O=x.map((be,Ae)=>be.via?{...be,via_to_layer:me[Ae]}:{...be,layers:[me[Ae]]})}O[0].pcb_port_id=s[0].pcb_port_id,O[O.length-1].pcb_port_id=s[1].pcb_port_id;const B=[];for(const[me,be]of vhe(O)){const Ae="via_to_layer"in me?me.via_to_layer:null,Oe=2,we="layers"in me&&me.layers.length===1?me.layers[0]:Ae??"top",Le="layers"in be&&be.layers.length===1?be.layers[0]:Ae??"top",Te="pcb_port_id"in me?me.pcb_port_id:null,je="pcb_port_id"in be?be.pcb_port_id:null,Ue=this.getSubcircuit()._parsedProps.minTraceWidth??.16,Ve=new Cde({OBSTACLE_MARGIN:Ue*2,isRemovePathLoopsEnabled:!0,optimizeWithGoalBoxes:!!(Te&&je),connMap:w,input:{obstacles:T,minTraceWidth:Ue,connections:[{name:this.source_trace_id,pointsToConnect:[{...me,layer:we,pcb_port_id:Te},{...be,layer:Le,pcb_port_id:je}]}],layerCount:2,bounds:{minX:Math.min(me.x,be.x)-Oe,maxX:Math.max(me.x,be.x)+Oe,minY:Math.min(me.y,be.y)-Oe,maxY:Math.max(me.y,be.y)+Oe}}});let ze=null;try{ze=Ve.solveAndMapToTraces()}catch(vt){this.renderError({type:"pcb_trace_error",pcb_trace_error_id:this.source_trace_id,error_type:"pcb_trace_error",message:`error solving route: ${vt.message}`,source_trace_id:this.pcb_trace_id,center:{x:(me.x+be.x)/2,y:(me.y+be.y)/2},pcb_port_ids:s.map(At=>At.pcb_port_id),pcb_trace_id:this.pcb_trace_id,pcb_component_ids:s.map(At=>At.pcb_component_id)})}if(!ze)return;if(ze.length===0){this.renderError({type:"pcb_trace_error",error_type:"pcb_trace_error",pcb_trace_error_id:this.pcb_trace_id,message:`Could not find a route for ${this}`,source_trace_id:this.source_trace_id,center:{x:(me.x+be.x)/2,y:(me.y+be.y)/2},pcb_port_ids:s.map(vt=>vt.pcb_port_id),pcb_trace_id:this.pcb_trace_id,pcb_component_ids:s.map(vt=>vt.pcb_component_id)});return}const[lt]=ze;Ae&&(lt.route=lt.route.map(vt=>(vt.route_type==="wire"&&!vt.layer&&(vt.layer=Ae),vt))),Te&&lt.route[0].route_type==="wire"&&(lt.route[0].start_pcb_port_id=Te);const it=lt.route[lt.route.length-1];je&&it.route_type==="wire"&&(it.end_pcb_port_id=je),B.push(lt.route)}const X=att(B),$=utt(X),Q=e.pcb_trace.insert({route:X,source_trace_id:this.source_trace_id,subcircuit_id:(pe=this.getSubcircuit())==null?void 0:pe.subcircuit_id,trace_length:$});this._portsRoutedOnPcb=s,this.pcb_trace_id=Q.pcb_trace_id;for(const me of X)me.route_type==="via"&&e.pcb_via.insert({pcb_trace_id:Q.pcb_trace_id,x:me.x,y:me.y,hole_diameter:.3,outer_diameter:.6,layers:[me.from_layer,me.to_layer],from_layer:me.from_layer,to_layer:me.to_layer});this._insertErrorIfTraceIsOutsideBoard(X,s)}_doInitialSchematicTraceRenderWithDisplayLabel(){var B,X,$,Q;if((B=this.root)!=null&&B.schematicDisabled)return;const{db:e}=this.root,{_parsedProps:t,parent:n}=this;if(!n)throw new Error("Trace has no parent");const{allPortsFound:i,portsWithSelectors:a}=this._findConnectedPorts();if(!i)return;const o=a.map(({port:ee})=>({port:ee,position:ee._getGlobalSchematicPositionAfterLayout(),schematic_port_id:ee.schematic_port_id,facingDirection:ee.facingDirection}));if(o.length<2)throw new Error("Expected at least two ports in portsWithPosition.");let s,l;const c=o[0].position,u=o[0].port;if("path"in this.props){if(this.props.path.length!==2)throw new Error("Invalid 'path': Must contain exactly two elements.");[s,l]=this.props.path}else{if(!("from"in this.props&&"to"in this.props))throw new Error("Missing 'from' or 'to' properties in props.");s=this.props.from,l=this.props.to}if(!u.source_port_id)throw new Error(`Missing source_port_id for the 'from' port (${s}).`);const f=o[1].position,v=o[1].port;if(!v.source_port_id)throw new Error(`Missing source_port_id for the 'to' port (${l}).`);const _=e.schematic_net_label.list().find(ee=>ee.source_net_id===u.source_port_id),x=e.schematic_net_label.list().find(ee=>ee.source_net_id===v.source_port_id),[M,w]=a.map(({port:ee})=>ee),L=((X=M.parent)==null?void 0:X.config.shouldRenderAsSchematicBox)?`${($=M==null?void 0:M.parent)==null?void 0:$.props.name}_${M==null?void 0:M.props.name}`:`${(Q=w==null?void 0:w.parent)==null?void 0:Q.props.name}_${w==null?void 0:w.props.name}`,O=this.props.schDisplayLabel??L;if(_&&_.text!==O&&(_.text=`${O} / ${_.text}`),x&&(x==null?void 0:x.text)!==O&&(x.text=`${O} / ${x.text}`),O!=null&&O.toLocaleLowerCase().includes("gnd")||O!=null&&O.toLocaleLowerCase().includes("ground")){!_&&!x?(FN({port:u,anchorPos:c,schDisplayLabel:this.props.schDisplayLabel,source_trace_id:this.source_trace_id},{db:e}),FN({port:v,anchorPos:f,schDisplayLabel:this.props.schDisplayLabel,source_trace_id:this.source_trace_id},{db:e})):_?x||FN({port:v,anchorPos:f,schDisplayLabel:this.props.schDisplayLabel,source_trace_id:this.source_trace_id},{db:e}):FN({port:u,anchorPos:c,schDisplayLabel:this.props.schDisplayLabel,source_trace_id:this.source_trace_id},{db:e});return}x||e.schematic_net_label.insert({text:this.props.schDisplayLabel??L,source_net_id:v.source_port_id,anchor_position:f,center:f,anchor_side:yH(v.facingDirection)??"bottom"}),_||e.schematic_net_label.insert({text:this.props.schDisplayLabel??L,source_net_id:u.source_port_id,anchor_position:c,center:c,anchor_side:yH(u.facingDirection)??"bottom"})}_isSymbolToChipConnection(){const{allPortsFound:e,ports:t}=this._findConnectedPorts();if(!e||t.length!==2)return!1;const[n,i]=t;if(!(n!=null&&n.parent)||!(i!=null&&i.parent))return!1;const a=n.parent.config.shouldRenderAsSchematicBox,o=i.parent.config.shouldRenderAsSchematicBox;return a&&!o||!a&&o}_isSymbolToSymbolConnection(){const{allPortsFound:e,ports:t}=this._findConnectedPorts();if(!e||t.length!==2)return!1;const[n,i]=t;if(!(n!=null&&n.parent)||!(i!=null&&i.parent))return!1;const a=!n.parent.config.shouldRenderAsSchematicBox,o=!i.parent.config.shouldRenderAsSchematicBox;return a&&o}_isChipToChipConnection(){const{allPortsFound:e,ports:t}=this._findConnectedPorts();if(!e||t.length!==2)return!1;const[n,i]=t;if(!(n!=null&&n.parent)||!(i!=null&&i.parent))return!1;const a=n.parent.config.shouldRenderAsSchematicBox,o=i.parent.config.shouldRenderAsSchematicBox;return a&&o}doInitialSchematicTraceRender(){var be;if((be=this.root)!=null&&be.schematicDisabled)return;const{db:e}=this.root,{_parsedProps:t,parent:n}=this;if(!n)throw new Error("Trace has no parent");const{allPortsFound:i,portsWithSelectors:a}=this._findConnectedPorts(),{netsWithSelectors:o}=this._findConnectedNets();if(!i)return;if(this.props.schDisplayLabel&&("from"in this.props&&"to"in this.props||"path"in this.props)){this._doInitialSchematicTraceRenderWithDisplayLabel();return}const s={name:this.source_trace_id,pointsToConnect:[]},l=vtt(this),c=a.map(({port:Ae})=>({port:Ae,position:Ae._getGlobalSchematicPositionAfterLayout(),schematic_port_id:Ae.schematic_port_id??void 0,facingDirection:Ae.facingDirection}));if(c.length===1&&o.length===1){const Ae=o[0].net,{port:Oe,position:we}=c[0];e.schematic_net_label.insert({text:Ae._parsedProps.name,source_net_id:Ae.source_net_id,anchor_position:we,center:we,anchor_side:yH(Oe.facingDirection)??"bottom"});return}if(c.length<2)return;s.pointsToConnect=c.map(({position:Ae})=>({...Ae,layer:"top"}));const f=itt(l),v=2,_={minTraceWidth:.1,obstacles:l,connections:[s],bounds:{minX:f.minX-v,maxX:f.maxX+v,minY:f.minY-v,maxY:f.maxY+v},layerCount:1};let x=Cde,M=!1;this.getSubcircuit().props._schDirectLineRoutingEnabled&&(x=Mhe,M=!0);let T=new x({input:_,MAX_ITERATIONS:100,OBSTACLE_MARGIN:.1,isRemovePathLoopsEnabled:!0,isShortenPathWithShortcutsEnabled:!0,marginsWithCosts:[{margin:1,enterCost:0,travelCostFactor:1},{margin:.3,enterCost:0,travelCostFactor:1},{margin:.2,enterCost:0,travelCostFactor:2},{margin:.1,enterCost:0,travelCostFactor:3}]}).solveAndMapToTraces();if(T.length===0){if(this._isSymbolToChipConnection()||this._isSymbolToSymbolConnection()||this._isChipToChipConnection()){this._doInitialSchematicTraceRenderWithDisplayLabel();return}T=new Mhe({input:_}).solveAndMapToTraces(),M=!0}const[{route:L}]=T;let O=[];for(let Ae=0;Ae<L.length-1;Ae++)O.push({from:L[Ae],to:L[Ae+1]});const B=this.source_trace_id;let X=[];if(!M){gtt({edges:O,db:e,source_trace_id:B});const Ae=_H({db:e,source_trace_id:B,differentNetOnly:!0}).flatMap(Oe=>Oe.edges);O=dtt({edges:O,otherEdges:Ae}),X=ptt({edges:O,db:e,source_trace_id:this.source_trace_id})}const $=O[O.length-1],Q=c[c.length-1],ee=Rhe($);O.push(...gH({lastEdge:$,lastEdgePort:Q,lastDominantDirection:ee}));const ae=O[0],K=c[0],pe=Rhe(ae);if(O.unshift(...gH({firstEdge:ae,firstEdgePort:K,firstDominantDirection:pe})),!this.source_trace_id)throw new Error("Missing source_trace_id for schematic trace insertion.");if(this.getSubcircuit()._parsedProps.schTraceAutoLabelEnabled&&ltt(X,O)>=5&&(this._isSymbolToChipConnection()||this._isSymbolToSymbolConnection()||this._isChipToChipConnection())){this._doInitialSchematicTraceRenderWithDisplayLabel();return}const me=e.schematic_trace.insert({source_trace_id:this.source_trace_id,edges:O,junctions:X});this.schematic_trace_id=me.schematic_trace_id}},xtt=w9("tscircuit:core"),btt=le.object({x:SS,y:SS,z:SS}),yx=class extends T9{constructor(e){super(e);rn(this,"reactSubtrees",[]);rn(this,"_impliedFootprint");rn(this,"isPrimitiveContainer",!0);rn(this,"_asyncSupplierPartNumbers");rn(this,"pcb_missing_footprint_error_id");this._addChildrenFromStringFootprint(),this.initPorts()}get defaultInternallyConnectedPinNames(){return[]}get internallyConnectedPinNames(){return this._parsedProps.internallyConnectedPins??this.defaultInternallyConnectedPinNames}initPorts(e={}){var o,s,l,c,u,f,v,_,x,M;if((o=this.root)!=null&&o.schematicDisabled)return;const{config:t}=this,n=[],i=this._getSchematicPortArrangement();if(i&&!this._parsedProps.pinLabels){for(const L in i){const O=i[L].pins;if(Array.isArray(O))for(const B of O){const X=J6(B,this._parsedProps.pinLabels);n.push(new TS({pinNumber:X,aliases:((s=e.additionalAliases)==null?void 0:s[`pin${X}`])??[]},{originDescription:`schPortArrangement:${L}`}))}}const w=["left","right","top","bottom"];let T=1;for(const L of w){const O=i[`${L}Size`];for(let B=0;B<O;B++)n.push(new TS({pinNumber:T++,aliases:((l=e.additionalAliases)==null?void 0:l[`pin${T}`])??[]},{originDescription:`schPortArrangement:${L}`}))}}const a=this._parsedProps.pinLabels;if(a)for(let[w,T]of Object.entries(a)){w=w.replace("pin","");let L=n.find(X=>X._parsedProps.pinNumber===Number(w));const O=Array.isArray(T)?T[0]:T,B=Array.isArray(T)?T.slice(1):[];L?(L.externallyAddedAliases.push(O,...B),L.props.name=O):(L=new TS({pinNumber:parseInt(w),name:O,aliases:[...B,...((c=e.additionalAliases)==null?void 0:c[`pin${parseInt(w)}`])??[]]},{originDescription:`pinLabels:pin${w}`}),n.push(L))}if(t.schematicSymbolName){const w=z3[this._getSchematicSymbolNameOrThrow()];if(!w)return;for(const T of w.ports){const L=whe(T.labels);if(!L)continue;const O=tM(T.labels.concat(((u=e.additionalAliases)==null?void 0:u[`pin${L}`])??[]));O&&(O.originDescription=`schematicSymbol:labels[0]:${T.labels[0]}`,O.schematicSymbolPortDef=T,n.push(O))}this.addAll(n)}if(!this._getSchematicPortArrangement()){const w=this.getPortsFromFootprint(e);for(const T of w)n.some(L=>L.isMatchingAnyOf(T.getNameAndAliases()))||n.push(T)}for(let w=1;w<=(e.pinCount??this._getPinCount());w++){if(!i||n.find(L=>L._parsedProps.pinNumber===w))continue;let T=[...((f=i.leftSide)==null?void 0:f.pins)??[],...((v=i.rightSide)==null?void 0:v.pins)??[],...((_=i.topSide)==null?void 0:_.pins)??[],...((x=i.bottomSide)==null?void 0:x.pins)??[]].map(L=>J6(L,this._parsedProps.pinLabels));["leftSize","rightSize","topSize","bottomSize","leftPinCount","rightPinCount","topPinCount","bottomPinCount"].some(L=>L in i)&&(T=Array.from({length:this._getPinCount()},(L,O)=>O+1)),T.includes(w)&&n.push(new TS({pinNumber:w,aliases:((M=e.additionalAliases)==null?void 0:M[`pin${w}`])??[]},{originDescription:`notOtherwiseAddedButDeducedFromPinCount:${w}`}))}n.length>0&&this.addAll(n)}_getImpliedFootprintString(){return null}_addChildrenFromStringFootprint(){var i;const{name:e,pcbRotation:t}=this.props;let{footprint:n}=this.props;if(n??(n=(i=this._getImpliedFootprintString)==null?void 0:i.call(this)),!!n&&typeof n=="string"){const a=gk.string(n).soup(),o=Yet({componentName:e,componentRotation:t},a);this.addAll(o)}}get portMap(){return new Proxy({},{get:(e,t)=>{const n=this.children.find(i=>i.componentName==="Port"&&i.isMatchingNameOrAlias(t));if(!n)throw new Error(`There was an issue finding the port "${t.toString()}" inside of a ${this.componentName} component with name: "${this.props.name}". This is a bug in @tscircuit/core`);return n}})}getInstanceForReactElement(e){for(const t of this.reactSubtrees)if(t.element===e)return t.component;return null}doInitialSourceRender(){const e=this.config.sourceFtype;if(!e)return;const{db:t}=this.root,{_parsedProps:n}=this,i=t.source_component.insert({ftype:e,name:n.name,manufacturer_part_number:n.manufacturerPartNumber??n.mfn,supplier_part_numbers:n.supplierPartNumbers});this.source_component_id=i.source_component_id}doInitialSchematicComponentRender(){var n;if((n=this.root)!=null&&n.schematicDisabled)return;const{schematicSymbolName:e}=this.config;if(e)return this._doInitialSchematicComponentRenderWithSymbol();if(this._getSchematicBoxDimensions())return this._doInitialSchematicComponentRenderWithSchematicBoxDimensions()}_getSchematicSymbolDisplayValue(){}_getInternallyConnectedPins(){if(this.internallyConnectedPinNames.length===0)return[];const e=[];for(const t of this.internallyConnectedPinNames){const n=[];for(const i of t)n.push(this.portMap[i]);e.push(n)}return e}_doInitialSchematicComponentRenderWithSymbol(){var o;if((o=this.root)!=null&&o.schematicDisabled)return;const{db:e}=this.root,{_parsedProps:t}=this,n=this._getSchematicSymbolNameOrThrow(),i=z3[n],a=this._getGlobalSchematicPositionBeforeLayout();if(i){const s=e.schematic_component.insert({center:a,size:i.size,source_component_id:this.source_component_id,symbol_name:n,symbol_display_value:this._getSchematicSymbolDisplayValue()});this.schematic_component_id=s.schematic_component_id}}_doInitialSchematicComponentRenderWithSchematicBoxDimensions(){var f;if((f=this.root)!=null&&f.schematicDisabled)return;const{db:e}=this.root,{_parsedProps:t}=this,n=this._getSchematicBoxDimensions(),i={};if(Array.isArray(t.pinLabels))t.pinLabels.forEach((v,_)=>{i[String(_+1)]=v});else for(const[v,_]of Object.entries(t.pinLabels??{}))i[v]=Array.isArray(_)?_[0]:_;const a=this._getGlobalSchematicPositionBeforeLayout(),o=this._getSchematicPortArrangement(),s=e.schematic_component.insert({center:a,rotation:t.schRotation??0,size:n.getSize(),port_arrangement:Get(o),pin_spacing:t.schPinSpacing??.2,pin_styles:Vet(t.schPinStyle,t.pinLabels),port_labels:i,source_component_id:this.source_component_id}),l=(o==null?void 0:o.topSide)!==void 0||(o==null?void 0:o.bottomSide)!==void 0,c=n==null?void 0:n.getSize().width,u=n==null?void 0:n.getSize().height;e.schematic_text.insert({text:t.manufacturerPartNumber??"",schematic_component_id:s.schematic_component_id,anchor:"left",rotation:0,position:{x:l?a.x+(c??0)/2+.1:a.x-(c??0)/2,y:l?a.y+(u??0)/2+.35:a.y-(u??0)/2-.13},color:"#006464"}),e.schematic_text.insert({text:t.name??"",schematic_component_id:s.schematic_component_id,anchor:"left",rotation:0,position:{x:l?a.x+(c??0)/2+.1:a.x-(c??0)/2,y:l?a.y+(u??0)/2+.55:a.y+(u??0)/2+.13},color:"#006464"}),this.schematic_component_id=s.schematic_component_id}doInitialPcbComponentRender(){var o;if((o=this.root)!=null&&o.pcbDisabled)return;const{db:e}=this.root,{_parsedProps:t}=this,n=this.getSubcircuit(),i=e.pcb_component.insert({center:this._getGlobalPcbPositionBeforeLayout(),width:0,height:0,layer:t.layer??"top",rotation:t.pcbRotation??0,source_component_id:this.source_component_id,subcircuit_id:n.subcircuit_id??void 0});if(!t.footprint&&!this.isGroup){const s=e.pcb_missing_footprint_error.insert({message:`No footprint found for component: ${this.getString()}`,source_component_id:`${this.source_component_id}`,error_type:"pcb_missing_footprint_error"});this.pcb_missing_footprint_error_id=s.pcb_missing_footprint_error_id}this.pcb_component_id=i.pcb_component_id;const a=this.getSubcircuit()._getPcbManualPlacementForComponent(this);this.props.pcbX!==void 0&&this.props.pcbY!==void 0&&a&&this.renderError({type:"pcb_manual_edit_conflict_error",message:`${this.getString()} has both manual placement and explicit coordinates. pcbX and pcbY will be used. Remove pcbX/pcbY or clear the manual placement.`,pcb_component_id:this.pcb_component_id,source_component_id:this.source_component_id})}doInitialPcbComponentSizeCalculation(){var a;if((a=this.root)!=null&&a.pcbDisabled||!this.pcb_component_id)return;const{db:e}=this.root,{_parsedProps:t}=this,n=Ehe(this.children);if(n.width===0||n.height===0)return;const i={x:(n.minX+n.maxX)/2,y:(n.minY+n.maxY)/2};e.pcb_component.update(this.pcb_component_id,{center:i,width:n.width,height:n.height})}_renderReactSubtree(e){return{element:e,component:mhe(e)}}doInitialInitializePortsFromChildren(){this.initPorts()}doInitialReactSubtreesRender(){if(ut.isValidElement(this.props.footprint)){if(this.reactSubtrees.some(t=>t.element===this.props.footprint))return;const e=this._renderReactSubtree(this.props.footprint);this.reactSubtrees.push(e),this.add(e.component)}}_hasExistingPortExactly(e){return this.children.filter(n=>n.componentName==="Port").some(n=>{const i=e.getNameAndAliases(),a=n.getNameAndAliases();return i.length===a.length&&i.every(o=>a.includes(o))})}add(e){let t;if(ut.isValidElement(e)){const n=this._renderReactSubtree(e);this.reactSubtrees.push(n),t=n.component}else t=e;if(t.componentName==="Port"){if(this._hasExistingPortExactly(t))return;const i=this.children.filter(a=>a.componentName==="Port").find(a=>a.isMatchingAnyOf(t.getNameAndAliases()));i&&xtt(`Similar ports added. Port 1: ${i}, Port 2: ${t}`)}super.add(t)}getPortsFromFootprint(e){let{footprint:t}=this.props;if((!t||ut.isValidElement(t))&&(t=this.children.find(i=>i.componentName==="Footprint")),typeof t=="string"){const i=gk.string(t).soup(),a=[];for(const o of i)if("port_hints"in o&&o.port_hints){const s=tM(o.port_hints,e);if(!s)continue;s.originDescription=`footprint:string:${t}:port_hints[0]:${o.port_hints[0]}`,a.push(s)}return a}if(!ut.isValidElement(t)&&t&&t.componentName==="Footprint"){const i=t;let a=1;const o=[];for(const s of i.children){if(!s.props.portHints)continue;let l=s.props.portHints;l.some(f=>f.startsWith("pin"))||(l=[...l,`pin${a}`]),a++;const u=tM(l);u&&(u.originDescription=`footprint:${t}`,o.push(u))}return o}const n=[];if(!t){for(const i of this.children)if(i.props.portHints&&i.isPcbPrimitive){const a=tM(i.props.portHints);a&&n.push(a)}}return n}getPortsFromSchematicSymbol(){var i;if((i=this.root)!=null&&i.schematicDisabled)return[];const{config:e}=this;if(!e.schematicSymbolName)return[];const t=z3[e.schematicSymbolName];if(!t)return[];const n=[];for(const a of t.ports){const o=tM(a.labels);o&&(o.schematicSymbolPortDef=a,n.push(o))}return n}doInitialCreateNetsFromProps(){this._createNetsFromProps(this._getNetsFromConnectionsProp())}_getNetsFromConnectionsProp(){const{_parsedProps:e}=this,t=[];if(e.connections)for(const[n,i]of Object.entries(e.connections)){const a=Array.isArray(i)?i:[i];for(const o of a)t.push(o)}return t}_createNetsFromProps(e){ghe(this,e)}_getPcbCircuitJsonBounds(){const{db:e}=this.root;if(!this.pcb_component_id)return super._getPcbCircuitJsonBounds();const t=e.pcb_component.get(this.pcb_component_id);return{center:{x:t.center.x,y:t.center.y},bounds:{left:t.center.x-t.width/2,top:t.center.y-t.height/2,right:t.center.x+t.width/2,bottom:t.center.y+t.height/2},width:t.width,height:t.height}}_getPinCountFromSchematicPortArrangement(){const e=this._getSchematicPortArrangement();if(!e)return 0;if(!The(e))return(e.leftSize??e.leftPinCount??0)+(e.rightSize??e.rightPinCount??0)+(e.topSize??e.topPinCount??0)+(e.bottomSize??e.bottomPinCount??0);const{leftSide:n,rightSide:i,topSide:a,bottomSide:o}=e;return Math.max(...(n==null?void 0:n.pins)??[],...(i==null?void 0:i.pins)??[],...(a==null?void 0:a.pins)??[],...(o==null?void 0:o.pins)??[])}_getPinCount(){return this._getSchematicPortArrangement()?this._getPinCountFromSchematicPortArrangement():this.getPortsFromFootprint().length}_getSchematicPortArrangement(){return this._parsedProps.schPinArrangement??this._parsedProps.schPortArrangement}_getSchematicBoxDimensions(){if(this.getSchematicSymbol()||!this.config.shouldRenderAsSchematicBox)return null;const{_parsedProps:e}=this,t=this._getPinCount(),n=e.schPinSpacing??.2;return ett({schWidth:e.schWidth,schHeight:e.schHeight,schPinSpacing:n,numericSchPinStyle:rtt(e.schPinStyle,e.pinLabels),pinCount:t,schPortArrangement:this._getSchematicPortArrangement(),pinLabels:e.pinLabels})}doInitialCadModelRender(){var c;const{db:e}=this.root,{boardThickness:t=0}=((c=this.root)==null?void 0:c._getBoard())??{},n=this._parsedProps.cadModel;if(!this.pcb_component_id||!n&&!this.props.footprint)return;const i=this._getPcbCircuitJsonBounds(),a=e.pcb_component.get(this.pcb_component_id);if(typeof n=="string")throw new Error("String cadModel not yet implemented");const o=btt.parse({x:0,y:0,z:typeof(n==null?void 0:n.rotationOffset)=="number"?n.rotationOffset:0,...typeof(n==null?void 0:n.rotationOffset)=="object"?n.rotationOffset??{}:{}}),s=lA.parse({x:0,y:0,z:0,...typeof(n==null?void 0:n.positionOffset)=="object"?n.positionOffset:{}}),l=this.props.layer==="bottom"?"bottom":"top";e.cad_component.insert({position:{x:i.center.x+s.x,y:i.center.y+s.y,z:(l==="bottom"?-t/2:t/2)+s.z},rotation:{x:o.x,y:(l==="top"?0:180)+o.y,z:((a==null?void 0:a.rotation)??0)+(l==="bottom"?180:0)+o.z},pcb_component_id:this.pcb_component_id,source_component_id:this.source_component_id,model_stl_url:"stlUrl"in(n??{})?this._addCachebustToModelUrl(n.stlUrl):void 0,model_obj_url:"objUrl"in(n??{})?this._addCachebustToModelUrl(n.objUrl):void 0,model_jscad:"jscad"in(n??{})?n.jscad:void 0,footprinter_string:typeof this.props.footprint=="string"&&!n?this.props.footprint:void 0})}_addCachebustToModelUrl(e){var n;if(!e||!e.includes("modelcdn.tscircuit.com"))return e;const t=((n=this.root)==null?void 0:n.getClientOrigin())??"";return`${e}${e.includes("?")?"&":"?"}cachebust_origin=${encodeURIComponent(t)}`}doInitialPartsEngineRender(){const e=this.getInheritedProperty("partsEngine");if(!e)return;const{db:t}=this.root,n=t.source_component.get(this.source_component_id);if(!n||n.supplier_part_numbers)return;let i;this.props.footprint&&typeof this.props.footprint=="string"&&(i=this.props.footprint);const a=e.findPart({sourceComponent:n,footprinterString:i});if(!(a instanceof Promise)){t.source_component.update(this.source_component_id,{supplier_part_numbers:a});return}this._queueAsyncEffect("get-supplier-part-numbers",async()=>{this._asyncSupplierPartNumbers=await a,this._markDirty("PartsEngineRender")})}updatePartsEngineRender(){const{db:e}=this.root,t=e.source_component.get(this.source_component_id);if(t&&!t.supplier_part_numbers&&this._asyncSupplierPartNumbers){e.source_component.update(this.source_component_id,{supplier_part_numbers:this._asyncSupplierPartNumbers});return}}doInitialCreateTracesFromProps(){this._createTracesFromConnectionsProp()}_createTracesFromConnectionsProp(){const{_parsedProps:e}=this;if(e.connections)for(const[t,n]of Object.entries(e.connections)){const i=Array.isArray(n)?n:[n];for(const a of i)this.add(new xE({from:`${this.getSubcircuitSelector()} > port.${t}`,to:a}))}}},Stt=class{constructor(r,e={}){rn(this,"input");rn(this,"isRouting",!1);rn(this,"solver");rn(this,"eventHandlers",{complete:[],error:[],progress:[]});rn(this,"cycleCount",0);rn(this,"stepDelay");rn(this,"timeoutId");this.input=r;const{capacityDepth:t,targetMinCapacity:n,stepDelay:i=0}=e;this.solver=new Iet(r,{capacityDepth:t,targetMinCapacity:n}),this.stepDelay=i}start(){this.isRouting||(this.isRouting=!0,this.cycleCount=0,this.runCycleAndQueueNextCycle())}runCycleAndQueueNextCycle(){var r;if(this.isRouting)try{if(this.solver.solved||this.solver.failed){this.solver.failed?this.emitEvent({type:"error",error:new Error(this.solver.error||"Routing failed")}):this.emitEvent({type:"complete",traces:this.solver.getOutputSimpleRouteJson().traces||[]}),this.isRouting=!1;return}const e=Date.now(),t=this.solver.iterations;for(;Date.now()-e<250&&!this.solver.failed&&!this.solver.solved;)this.solver.step();const n=(this.solver.iterations-t)/(Date.now()-e)*1e3;this.cycleCount++;const i=((r=this.solver.activeSolver)==null?void 0:r.visualize())||void 0,a=this.solver.progress;this.emitEvent({type:"progress",steps:this.cycleCount,iterationsPerSecond:n,progress:a,phase:this.solver.getCurrentPhase(),debugGraphics:i}),this.stepDelay>0?this.timeoutId=setTimeout(()=>this.runCycleAndQueueNextCycle(),this.stepDelay):this.timeoutId=setTimeout(()=>this.runCycleAndQueueNextCycle(),0)}catch(e){this.emitEvent({type:"error",error:e instanceof Error?e:new Error(String(e))}),this.isRouting=!1}}stop(){this.isRouting&&(this.isRouting=!1,this.timeoutId!==void 0&&(clearTimeout(this.timeoutId),this.timeoutId=void 0))}on(r,e){r==="complete"?this.eventHandlers.complete.push(e):r==="error"?this.eventHandlers.error.push(e):r==="progress"&&this.eventHandlers.progress.push(e)}emitEvent(r){if(r.type==="complete")for(const e of this.eventHandlers.complete)e(r);else if(r.type==="error")for(const e of this.eventHandlers.error)e(r);else if(r.type==="progress")for(const e of this.eventHandlers.progress)e(r)}solveSync(){if(this.solver.solve(),this.solver.failed)throw new Error(this.solver.error||"Routing failed");return this.solver.getOutputSimpleRouteJson().traces||[]}},Ahe=class extends T9{constructor(){super(...arguments);rn(this,"matchedPort",null)}get config(){return{componentName:"TraceHint",zodProps:FKe}}doInitialPortMatching(){const{db:e}=this.root,{_parsedProps:t,parent:n}=this;if(!n)return;if(n.componentName==="Trace"){this.renderError(`Port inference inside trace is not yet supported (${this})`);return}if(!n)throw new Error("TraceHint has no parent");if(!t.for){this.renderError(`TraceHint has no for property (${this})`);return}const i=n.selectOne(t.for,{type:"port"});i||this.renderError(`${this} could not find port for selector "${t.for}"`),this.matchedPort=i,i.registerMatch(this)}getPcbRouteHints(){const{_parsedProps:e}=this,t=e.offset?[e.offset]:e.offsets;if(!t)return[];const n=this._computePcbGlobalTransformBeforeLayout();return t.map(i=>({...ai(n,i),via:i.via,to_layer:i.to_layer,trace_width:i.trace_width}))}doInitialPcbTraceHintRender(){var n,i,a;if((n=this.root)!=null&&n.pcbDisabled)return;const{db:e}=this.root,{_parsedProps:t}=this;e.pcb_trace_hint.insert({pcb_component_id:(i=this.matchedPort)==null?void 0:i.pcb_component_id,pcb_port_id:(a=this.matchedPort)==null?void 0:a.pcb_port_id,route:this.getPcbRouteHints()})}},Ett=({circuitJson:r,editEvents:e,manualEditsFile:t})=>{var i;const n={...t,schematic_placements:[...t.schematic_placements??[]]};for(const a of e)if(a.edit_event_type==="edit_schematic_component_location"){const{schematic_component_id:o,new_center:s}=a,l=m1(r).schematic_component.get(o);if(!l)continue;const c=m1(r).source_component.get(l.source_component_id);if(!c)continue;const u=(i=n.schematic_placements)==null?void 0:i.findIndex(v=>v.selector===c.name),f={selector:c.name,center:s,relative_to:"group_center"};u>=0?n.schematic_placements[u]=f:n.schematic_placements.push(f)}return n},wtt=(r,e)=>{const t=r.source_group.list(),n=[],i=a=>{const o=t.filter(s=>s.parent_subcircuit_id===a);for(const s of o)s.subcircuit_id&&(n.push(s.subcircuit_id),i(s.subcircuit_id))};return i(e),n},Nhe=({db:r,circuitJson:e,subcircuit_id:t,minTraceWidth:n=.1})=>{if(!r&&e&&(r=m1(e)),!r)throw new Error("db or circuitJson is required");const i=t?new Set([t]):null;if(t){const x=wtt(r,t);for(const M of x)i.add(M)}const a=(e??r.toArray()).filter(x=>!t||"subcircuit_id"in x&&i.has(x.subcircuit_id)),o=r.pcb_board.list()[0];r=m1(a);const s=XB(a),l=Rde([...r.pcb_component.list(),...r.pcb_smtpad.list(),...r.pcb_plated_hole.list(),...r.pcb_hole.list(),...r.pcb_via.list()].filter(x=>!t||(i==null?void 0:i.has(x.subcircuit_id))),s);for(const x of l){const M=x.connectedTo.flatMap(w=>s.getIdsConnectedToNet(w));x.connectedTo.push(...M)}const c=l.flatMap(x=>[{x:x.center.x-x.width/2,y:x.center.y-x.height/2},{x:x.center.x+x.width/2,y:x.center.y+x.height/2}]);let u;o?u={minX:o.center.x-o.width/2,maxX:o.center.x+o.width/2,minY:o.center.y-o.height/2,maxY:o.center.y+o.height/2}:u={minX:Math.min(...c.map(x=>x.x))-1,maxX:Math.max(...c.map(x=>x.x))+1,minY:Math.min(...c.map(x=>x.y))-1,maxY:Math.max(...c.map(x=>x.y))+1};const f=r.source_trace.list().map(x=>{const M=x.connected_source_port_ids.map(w=>{const T=r.source_port.get(w),L=r.pcb_port.getWhere({source_port_id:w});return{...T,...L}});return M.length<2?null:{name:x.source_trace_id??s.getNetConnectedToId(x.source_trace_id)??"",source_trace_id:x.source_trace_id,pointsToConnect:M.map(w=>{var T;return{x:w.x,y:w.y,layer:((T=w.layers)==null?void 0:T[0])??"top"}})}}).filter(x=>x!==null),v=r.source_net.list().filter(x=>!t||(i==null?void 0:i.has(x.subcircuit_id))),_=[];for(const x of v){const M=r.source_trace.list().filter(w=>{var T;return(T=w.connected_source_net_ids)==null?void 0:T.includes(x.source_net_id)});_.push({name:x.source_net_id??s.getNetConnectedToId(x.source_net_id),pointsToConnect:M.flatMap(w=>r.pcb_port.list().filter(L=>w.connected_source_port_ids.includes(L.source_port_id)).map(L=>{var O;return{x:L.x,y:L.y,layer:((O=L.layers)==null?void 0:O[0])??"top",pcb_port_id:L.pcb_port_id}}))})}return{simpleRouteJson:{bounds:u,obstacles:l,connections:[...f,..._],layerCount:2,minTraceWidth:n},connMap:s}},xH=class extends yx{constructor(){super(...arguments);rn(this,"pcb_group_id",null);rn(this,"subcircuit_id",null);rn(this,"_hasStartedAsyncAutorouting",!1);rn(this,"_asyncAutoroutingResult",null)}get config(){return{zodProps:WQe,componentName:"Group"}}doInitialSourceRender(){const{db:t}=this.root,n=t.source_group.insert({name:this._parsedProps.name,is_subcircuit:this.isSubcircuit});this.subcircuit_id=`subcircuit_${n.source_group_id}`,this.source_group_id=n.source_group_id,t.source_group.update(n.source_group_id,{subcircuit_id:this.subcircuit_id})}doInitialSourceParentAttachment(){var i,a,o;const{db:t}=this.root;if(!this.isSubcircuit)return;const n=(o=(a=(i=this.parent)==null?void 0:i.getSubcircuit)==null?void 0:a.call(i))==null?void 0:o.subcircuit_id;n&&t.source_group.update(this.source_group_id,{parent_subcircuit_id:n})}doInitialPcbComponentRender(){var a;if((a=this.root)!=null&&a.pcbDisabled)return;const{db:t}=this.root,{_parsedProps:n}=this,i=t.pcb_group.insert({is_subcircuit:this.isSubcircuit,subcircuit_id:this.subcircuit_id,name:this._parsedProps.name,center:this._getGlobalPcbPositionBeforeLayout(),width:0,height:0,pcb_component_ids:[],source_group_id:this.source_group_id});this.pcb_group_id=i.pcb_group_id}doInitialCreateTraceHintsFromProps(){var o;const{_parsedProps:t}=this,{db:n}=this.root,i=t;if(!this.isSubcircuit)return;const a=(o=i.layout)==null?void 0:o.manual_trace_hints;if(a)for(const s of a)this.add(new Ahe({for:s.pcb_port_selector,offsets:s.offsets}))}doInitialSourceAddConnectivityMapKey(){if(!this.isSubcircuit)return;const{db:t}=this.root,n=this.selectAll("trace"),i=new xN({});i.addConnections(n.map(a=>{const o=t.source_trace.get(a.source_trace_id);return o?[o.source_trace_id,...o.connected_source_port_ids,...o.connected_source_net_ids]:null}).filter(a=>a!==null));for(const a of n){if(!a.source_trace_id)continue;const o=i.getNetConnectedToId(a.source_trace_id);if(!o)continue;const{name:s}=this._parsedProps;a.subcircuit_connectivity_map_key=`${s??`unnamedsubcircuit${this._renderId}`}_${o}`,t.source_trace.update(a.source_trace_id,{subcircuit_connectivity_map_key:a.subcircuit_connectivity_map_key})}}_areChildSubcircuitsRouted(){const t=this.selectAll("group").filter(n=>n.isSubcircuit);for(const n of t)if(n._shouldRouteAsync()&&!n._asyncAutoroutingResult)return!1;return!0}_shouldRouteAsync(){const t=this._getAutorouterConfig();return t.groupMode==="sequential-trace"?!1:!!(t.local&&t.groupMode==="subcircuit"||!t.local)}_hasTracesToRoute(){const t=w9("tscircuit:core:_hasTracesToRoute"),n=this.selectAll("trace");return t(`[${this.getString()}] has ${n.length} traces to route`),n.length>0}async _runEffectMakeHttpAutoroutingRequest(){var u,f,v,_;const{db:t}=this.root,n=w9("tscircuit:core:_runEffectMakeHttpAutoroutingRequest");this._parsedProps;const i=this._getAutorouterConfig(),a=i.serverUrl,o=i.serverMode,s=(x,M)=>{var w;return n("fetching",x),M.headers&&(M.headers["Tscircuit-Core-Version"]=(w=this.root)==null?void 0:w.getCoreVersion()),fetch(x,M)},l=this.root.db.toArray().filter(x=>x.type.startsWith("source_")||x.type.startsWith("pcb_"));if(o==="solve-endpoint"){if(((u=this.props.autorouter)==null?void 0:u.inputFormat)==="simplified"){const{autorouting_result:M}=await s(`${a}/autorouting/solve`,{method:"POST",body:JSON.stringify({input_simple_route_json:Nhe({db:t,minTraceWidth:((f=this.props.autorouter)==null?void 0:f.minTraceWidth)??.15,subcircuit_id:this.subcircuit_id}).simpleRouteJson,subcircuit_id:this.subcircuit_id}),headers:{"Content-Type":"application/json"}}).then(w=>w.json());this._asyncAutoroutingResult=M,this._markDirty("PcbTraceRender");return}const{autorouting_result:x}=await s(`${a}/autorouting/solve`,{method:"POST",body:JSON.stringify({input_circuit_json:l,subcircuit_id:this.subcircuit_id}),headers:{"Content-Type":"application/json"}}).then(M=>M.json());this._asyncAutoroutingResult=x,this._markDirty("PcbTraceRender");return}const{autorouting_job:c}=await s(`${a}/autorouting/jobs/create`,{method:"POST",body:JSON.stringify({input_circuit_json:l,provider:"freerouting",autostart:!0,display_name:(v=this.root)==null?void 0:v.name,subcircuit_id:this.subcircuit_id,server_cache_enabled:i.serverCacheEnabled}),headers:{"Content-Type":"application/json"}}).then(x=>x.json());for(;;){const{autorouting_job:x}=await s(`${a}/autorouting/jobs/get`,{method:"POST",body:JSON.stringify({autorouting_job_id:c.autorouting_job_id}),headers:{"Content-Type":"application/json"}}).then(M=>M.json());if(x.is_finished){const{autorouting_job_output:M}=await s(`${a}/autorouting/jobs/get_output`,{method:"POST",body:JSON.stringify({autorouting_job_id:c.autorouting_job_id}),headers:{"Content-Type":"application/json"}}).then(w=>w.json());this._asyncAutoroutingResult={output_pcb_traces:M.output_pcb_traces},this._markDirty("PcbTraceRender");break}if(x.has_error)throw t.pcb_autorouting_error.insert({pcb_error_id:c.autorouting_job_id,message:((_=x.error)==null?void 0:_.message)??JSON.stringify(x.error)}),new Error(`Autorouting job failed: ${JSON.stringify(x.error)}`);await new Promise(M=>setTimeout(M,100))}}async _runLocalAutorouting(){var l,c,u,f,v;const{db:t}=this.root;this._parsedProps;const n=w9("tscircuit:core:_runLocalAutorouting");n(`[${this.getString()}] starting local autorouting`);const i=this._getAutorouterConfig(),{simpleRouteJson:a}=Nhe({db:t,minTraceWidth:((l=this.props.autorouter)==null?void 0:l.minTraceWidth)??.15,subcircuit_id:this.subcircuit_id});(c=this.root)==null||c.emit("autorouting:start",{subcircuit_id:this.subcircuit_id,componentDisplayName:this.getString(),simpleRouteJson:a});let o;i.algorithmFn?o=await i.algorithmFn(a):o=new Stt(a,{capacityDepth:(u=this.props.autorouter)==null?void 0:u.capacityDepth,targetMinCapacity:(f=this.props.autorouter)==null?void 0:f.targetMinCapacity});const s=new Promise((_,x)=>{o.on("complete",M=>{n(`[${this.getString()}] local autorouting complete`),_(M.traces)}),o.on("error",M=>{n(`[${this.getString()}] local autorouting error: ${M.error.message}`),x(M.error)})});o.on("progress",_=>{var x;(x=this.root)==null||x.emit("autorouting:progress",{subcircuit_id:this.subcircuit_id,componentDisplayName:this.getString(),..._})}),o.start();try{const _=await s;this._asyncAutoroutingResult={output_pcb_traces:_},this._markDirty("PcbTraceRender")}catch(_){const{db:x}=this.root;throw x.pcb_autorouting_error.insert({pcb_error_id:`pcb_autorouter_error_subcircuit_${this.subcircuit_id}`,message:_ instanceof Error?_.message:String(_)}),(v=this.root)==null||v.emit("autorouting:error",{subcircuit_id:this.subcircuit_id,componentDisplayName:this.getString(),error:{message:_ instanceof Error?_.message:String(_)},simpleRouteJson:a}),_}finally{o.stop()}}_startAsyncAutorouting(){this._hasStartedAsyncAutorouting||(this._hasStartedAsyncAutorouting=!0,this._getAutorouterConfig().local?this._queueAsyncEffect("capacity-mesh-autorouting",async()=>this._runLocalAutorouting()):this._queueAsyncEffect("make-http-autorouting-request",async()=>this._runEffectMakeHttpAutoroutingRequest()))}doInitialPcbTraceRender(){var n;const t=w9("tscircuit:core:doInitialPcbTraceRender");if(this.isSubcircuit&&!((n=this.root)!=null&&n.pcbDisabled)&&!this.getInheritedProperty("routingDisabled")&&!this._shouldUseTraceByTraceRouting()){if(!this._areChildSubcircuitsRouted()){t(`[${this.getString()}] child subcircuits are not routed, skipping async autorouting until subcircuits routed`);return}t(`[${this.getString()}] no child subcircuits to wait for, initiating async routing`),this._hasTracesToRoute()&&this._startAsyncAutorouting()}}updatePcbTraceRender(){var i;const t=w9("tscircuit:core:updatePcbTraceRender");if(t(`[${this.getString()}] updating...`),!this.isSubcircuit)return;if(this._shouldRouteAsync()&&this._hasTracesToRoute()&&!this._hasStartedAsyncAutorouting){this._areChildSubcircuitsRouted()&&(t(`[${this.getString()}] child subcircuits are now routed, starting async autorouting`),this._startAsyncAutorouting());return}if(!this._asyncAutoroutingResult||this._shouldUseTraceByTraceRouting())return;const{db:n}=this.root;if(this._asyncAutoroutingResult.output_simple_route_json){t(`[${this.getString()}] updating PCB traces from simple route json (${(i=this._asyncAutoroutingResult.output_simple_route_json.traces)==null?void 0:i.length} traces)`),this._updatePcbTraceRenderFromSimpleRouteJson();return}if(this._asyncAutoroutingResult.output_pcb_traces){t(`[${this.getString()}] updating PCB traces from ${this._asyncAutoroutingResult.output_pcb_traces.length} traces`),this._updatePcbTraceRenderFromPcbTraces();return}}_updatePcbTraceRenderFromSimpleRouteJson(){const{db:t}=this.root,{traces:n}=this._asyncAutoroutingResult.output_simple_route_json;if(n)for(const i of n)t.pcb_trace.insert({subcircuit_id:this.subcircuit_id,route:i.route})}_updatePcbTraceRenderFromPcbTraces(){const{output_pcb_traces:t}=this._asyncAutoroutingResult;if(!t)return;const{db:n}=this.root;for(const i of t){if(i.subcircuit_id=this.subcircuit_id,i.connection_name){const a=i.connection_name;i.source_trace_id=a}n.pcb_trace.insert(i)}for(const i of t)for(const a of i.route)a.route_type==="via"&&n.pcb_via.insert({pcb_trace_id:i.pcb_trace_id,x:a.x,y:a.y,hole_diameter:.3,outer_diameter:.6,layers:[a.from_layer,a.to_layer],from_layer:a.from_layer,to_layer:a.to_layer})}doInitialSchematicLayout(){if(!this.isSubcircuit||!this._parsedProps.schAutoLayoutEnabled)return;const{db:n}=this.root,i=this.getDescendants(),a=[];for(const l of i)if("schematic_component_id"in l){const c=n.schematic_component.get(l.schematic_component_id);if(c){const u=n.schematic_port.list().filter(f=>f.schematic_component_id===c.schematic_component_id);a.push(...u)}}const o=nJe(n.toArray()),s=fJe(o);tJe(n.toArray(),s)}_getAutorouterConfig(){const t={serverUrl:"https://registry-api.tscircuit.com",serverMode:"job",serverCacheEnabled:!0},n=this._parsedProps.autorouter??this.getInheritedProperty("autorouter");return typeof n=="object"?{local:!(n.serverUrl||n.serverMode||n.serverCacheEnabled),...t,...n}:n==="auto-local"?{local:!0,groupMode:"subcircuit"}:n==="sequential-trace"?{local:!0,groupMode:"sequential-trace"}:n==="subcircuit"?{local:!0,groupMode:"subcircuit"}:n==="auto-cloud"?{local:!1,groupMode:"subcircuit",serverUrl:t.serverUrl,serverMode:t.serverMode,serverCacheEnabled:!0}:{local:!0,groupMode:"subcircuit"}}_shouldUseTraceByTraceRouting(){return this._getAutorouterConfig().groupMode==="sequential-trace"}},Ttt=class extends xH{constructor(){super(...arguments);rn(this,"pcb_board_id",null)}get isSubcircuit(){return!0}get config(){return{componentName:"Board",zodProps:zde}}get boardThickness(){const{_parsedProps:e}=this;return 1.4}get allLayers(){return["top","bottom","inner1","inner2"]}doInitialPcbBoardAutoSize(){var _;if((_=this.root)!=null&&_.pcbDisabled||!this.pcb_board_id)return;const{db:e}=this.root,{_parsedProps:t}=this;if(t.width&&t.height)return;let n=1/0,i=1/0,a=-1/0,o=-1/0;const s=e.pcb_component.list();let l=!1;for(const x of s){const{width:M,height:w,center:T}=x;M===0||w===0||(l=!0,n=Math.min(n,T.x-M/2),i=Math.min(i,T.y-w/2),a=Math.max(a,T.x+M/2),o=Math.max(o,T.y+w/2))}const c=2,u=l?a-n+c*2:0,f=l?o-i+c*2:0,v={x:l?(n+a)/2+(t.outlineOffsetX??0):t.outlineOffsetX??0,y:l?(i+o)/2+(t.outlineOffsetY??0):t.outlineOffsetY??0};e.pcb_board.update(this.pcb_board_id,{width:u,height:f,center:v})}doInitialPcbComponentRender(){var o,s;if((o=this.root)!=null&&o.pcbDisabled)return;const{db:e}=this.root,{_parsedProps:t}=this;let n=t.width??0,i=t.height??0;if(t.outline){const l=t.outline.map(x=>x.x),c=t.outline.map(x=>x.y),u=Math.min(...l),f=Math.max(...l),v=Math.min(...c),_=Math.max(...c);n=f-u,i=_-v}const a=e.pcb_board.insert({center:{x:(t.pcbX??0)+(t.outlineOffsetX??0),y:(t.pcbY??0)+(t.outlineOffsetY??0)},thickness:this.boardThickness,num_layers:this.allLayers.length,width:n,height:i,outline:(s=t.outline)==null?void 0:s.map(l=>({x:l.x+(t.outlineOffsetX??0),y:l.y+(t.outlineOffsetY??0)}))});this.pcb_board_id=a.pcb_board_id}removePcbComponentRender(){const{db:e}=this.root;this.pcb_board_id&&(e.pcb_board.delete(this.pcb_board_id),this.pcb_board_id=null)}_computePcbGlobalTransformBeforeLayout(){return K_()}},Mtt=new Proxy({},{get:(r,e)=>e}),nM=Mtt,Ctt=class extends yx{get config(){return{componentName:"Capacitor",schematicSymbolName:this.props.polarized?"capacitor_polarized":this.props.symbolName??"capacitor",zodProps:nKe,sourceFtype:nM.simple_capacitor}}initPorts(){super.initPorts({additionalAliases:{pin1:["anode","pos","left"],pin2:["cathode","neg","right"]}})}_getSchematicSymbolDisplayValue(){const r=`${zN(this._parsedProps.capacitance)}F`;return this._parsedProps.schShowRatings&&this._parsedProps.maxVoltageRating?`${r}/${zN(this._parsedProps.maxVoltageRating)}V`:r}doInitialCreateNetsFromProps(){this._createNetsFromProps([this.props.decouplingFor,this.props.decouplingTo,...this._getNetsFromConnectionsProp()])}doInitialCreateTracesFromProps(){this.props.decouplingFor&&this.props.decouplingTo&&(this.add(new xE({from:`${this.getSubcircuitSelector()} > port.1`,to:this.props.decouplingFor})),this.add(new xE({from:`${this.getSubcircuitSelector()} > port.2`,to:this.props.decouplingTo})))}doInitialSourceRender(){const{db:r}=this.root,{_parsedProps:e}=this,t=r.source_component.insert({ftype:"simple_capacitor",name:e.name,manufacturer_part_number:e.manufacturerPartNumber??e.mfn,supplier_part_numbers:e.supplierPartNumbers,capacitance:e.capacitance,max_voltage_rating:e.maxVoltageRating,max_decoupling_trace_length:e.maxDecouplingTraceLength,display_capacitance:this._getSchematicSymbolDisplayValue()});this.source_component_id=t.source_component_id}},Phe=class extends yx{constructor(){super(...arguments);rn(this,"schematicBoxDimensions",null)}get config(){return{componentName:"Chip",zodProps:$Qe,shouldRenderAsSchematicBox:!0}}doInitialSchematicComponentRender(){const{_parsedProps:e}=this;(e==null?void 0:e.noSchematicRepresentation)!==!0&&super.doInitialSchematicComponentRender()}doInitialSourceRender(){const{db:e}=this.root,{_parsedProps:t}=this,n=e.source_component.insert({ftype:"simple_chip",name:t.name,manufacturer_part_number:t.manufacturerPartNumber,supplier_part_numbers:t.supplierPartNumbers});this.source_component_id=n.source_component_id}doInitialPcbComponentRender(){var i;if((i=this.root)!=null&&i.pcbDisabled)return;const{db:e}=this.root,{_parsedProps:t}=this,n=e.pcb_component.insert({center:{x:t.pcbX??0,y:t.pcbY??0},width:2,height:3,layer:t.layer??"top",rotation:t.pcbRotation??0,source_component_id:this.source_component_id,subcircuit_id:this.getSubcircuit().subcircuit_id??void 0});this.pcb_component_id=n.pcb_component_id}doInitialCreateTracesFromProps(){const{_parsedProps:e}=this;if(e.externallyConnectedPins)for(const[t,n]of e.externallyConnectedPins)this.add(new xE({from:`${this.getSubcircuitSelector()} > port.${t}`,to:`${this.getSubcircuitSelector()} > port.${n}`}));this._createTracesFromConnectionsProp()}},Rtt=class extends yx{constructor(){super(...arguments);rn(this,"pos",this.portMap.pin1);rn(this,"anode",this.portMap.pin1);rn(this,"neg",this.portMap.pin2);rn(this,"cathode",this.portMap.pin2)}get config(){return{schematicSymbolName:this.props.symbolName??"diode",componentName:"Diode",zodProps:MKe,sourceFtype:"simple_diode"}}initPorts(){super.initPorts({additionalAliases:{pin1:["anode","pos","left"],pin2:["cathode","neg","right"]}})}},Att=class extends yx{constructor(){super(...arguments);rn(this,"schematicDimensions",null)}get config(){return{componentName:"Jumper",zodProps:ZQe,shouldRenderAsSchematicBox:!0}}doInitialSourceRender(){const{db:e}=this.root,{_parsedProps:t}=this,n=e.source_component.insert({ftype:"simple_chip",name:t.name,manufacturer_part_number:t.manufacturerPartNumber,supplier_part_numbers:t.supplierPartNumbers});this.source_component_id=n.source_component_id}doInitialPcbComponentRender(){var i;if((i=this.root)!=null&&i.pcbDisabled)return;const{db:e}=this.root,{_parsedProps:t}=this,n=e.pcb_component.insert({center:{x:t.pcbX??0,y:t.pcbY??0},width:2,height:3,layer:t.layer??"top",rotation:t.pcbRotation??0,source_component_id:this.source_component_id,subcircuit_id:this.getSubcircuit().subcircuit_id??void 0});this.pcb_component_id=n.pcb_component_id}},Ntt=class extends yx{constructor(){super(...arguments);rn(this,"pos",this.portMap.pin1);rn(this,"anode",this.portMap.pin1);rn(this,"neg",this.portMap.pin2);rn(this,"cathode",this.portMap.pin2)}get config(){return{componentName:"Led",schematicSymbolName:this.props.symbolName??"led",zodProps:CKe,sourceFtype:"simple_diode"}}initPorts(){super.initPorts({additionalAliases:{pin1:["anode","pos","left"],pin2:["cathode","neg","right"]}})}},Ptt=class extends yx{constructor(){super(...arguments);rn(this,"pos",this.portMap.pin1);rn(this,"positive",this.portMap.pin1);rn(this,"neg",this.portMap.pin2);rn(this,"negative",this.portMap.pin2)}get config(){return{schematicSymbolName:this.props.symbolName??"power_factor_meter_horz",componentName:"PowerSource",zodProps:LKe,sourceFtype:"simple_power_source"}}initPorts(){this.add(new TS({name:"pin1",pinNumber:1,aliases:["positive","pos"]})),this.add(new TS({name:"pin2",pinNumber:2,aliases:["negative","neg"]}))}},Dtt=class extends yx{get config(){return{componentName:"Resistor",schematicSymbolName:this.props.symbolName??"boxresistor",zodProps:KQe,sourceFtype:"simple_resistor"}}initPorts(){super.initPorts({additionalAliases:{pin1:["anode","pos","left"],pin2:["cathode","neg","right"]}})}_getSchematicSymbolDisplayValue(){return`${zN(this._parsedProps.resistance)}Ω`}doInitialCreateNetsFromProps(){this._createNetsFromProps([this.props.pullupFor,this.props.pullupTo,...this._getNetsFromConnectionsProp()])}doInitialCreateTracesFromProps(){this.props.pullupFor&&this.props.pullupTo&&(this.add(new xE({from:`${this.getSubcircuitSelector()} > port.1`,to:this.props.pullupFor})),this.add(new xE({from:`${this.getSubcircuitSelector()} > port.2`,to:this.props.pullupTo})))}doInitialSourceRender(){const{db:r}=this.root,{_parsedProps:e}=this,t=r.source_component.insert({ftype:"simple_resistor",name:e.name,manufacturer_part_number:e.manufacturerPartNumber??e.mfn,supplier_part_numbers:e.supplierPartNumbers,resistance:e.resistance,display_resistance:this._getSchematicSymbolDisplayValue()});this.source_component_id=t.source_component_id}},Ltt=["leftedge","rightedge","topedge","bottomedge","center"],Ott=class extends T9{get config(){return{componentName:"Constraint",zodProps:sKe}}constructor(r){if(super(r),("xdist"in r||"ydist"in r)&&!("edgeToEdge"in r)&&!("centerToCenter"in r))throw new Error(`edgeToEdge, centerToCenter must be set for xDist or yDist for ${this}`);if("for"in r&&r.for.length<2)throw new Error(`"for" must have at least two selectors for ${this}`)}_getAllReferencedComponents(){const r=[],e=this.getPrimitiveContainer();function t(n){const i=n.split(" ").pop(),a=Ltt.includes(i)?i:void 0,o=a?n.replace(` ${a}`,""):n,s=e.selectOne(o,{pcbPrimitive:!0});s&&r.push({selector:n,component:s,componentSelector:o,edge:a})}for(const n of["left","right","top","bottom"])n in this._parsedProps&&t(this._parsedProps[n]);if("for"in this._parsedProps)for(const n of this._parsedProps.for)t(n);return{componentsWithSelectors:r}}},Utt=class extends T9{constructor(){super(...arguments);rn(this,"fabrication_note_path_id",null)}get config(){return{componentName:"FabricationNotePath",zodProps:NKe}}doInitialPcbPrimitiveRender(){var s,l;if((s=this.root)!=null&&s.pcbDisabled)return;const{db:e}=this.root,t=this.getSubcircuit(),{_parsedProps:n}=this,i=n.layer??"top";if(i!=="top"&&i!=="bottom")throw new Error(`Invalid layer "${i}" for SilkscreenPath. Must be "top" or "bottom".`);const a=this._computePcbGlobalTransformBeforeLayout(),o=e.pcb_fabrication_note_path.insert({pcb_component_id:(l=this.parent)==null?void 0:l.pcb_component_id,layer:i,color:n.color,route:n.route.map(c=>{const u=ai(a,{x:c.x,y:c.y});return{...c,x:u.x,y:u.y}}),stroke_width:n.strokeWidth??.1,subcircuit_id:(t==null?void 0:t.subcircuit_id)??void 0});this.fabrication_note_path_id=o.pcb_fabrication_note_path_id}},ztt=class extends T9{get config(){return{componentName:"FabricationNoteText",zodProps:AKe}}doInitialPcbPrimitiveRender(){var i,a;if((i=this.root)!=null&&i.pcbDisabled)return;const{db:r}=this.root,{_parsedProps:e}=this,t=this.getPrimitiveContainer(),n=this.getSubcircuit();r.pcb_fabrication_note_text.insert({anchor_alignment:e.anchorAlignment,anchor_position:{x:e.pcbX??0,y:e.pcbY??0},font:e.font??"tscircuit2024",font_size:e.fontSize??1,layer:"top",color:e.color,text:e.text??"",pcb_component_id:t.pcb_component_id,subcircuit_id:(n==null?void 0:n.subcircuit_id)??void 0,pcb_group_id:((a=this.getGroup())==null?void 0:a.pcb_group_id)??void 0})}},Itt=class extends xH{constructor(r){super({...r,subcircuit:!0})}},ktt=class extends T9{constructor(){super(...arguments);rn(this,"source_net_alias_id")}get config(){return{componentName:"NetAlias",zodProps:bKe}}doInitialSchematicComponentRender(){var a;if((a=this.root)!=null&&a.schematicDisabled)return;const{db:e}=this.root,{_parsedProps:t}=this,n={x:t.schX??0,y:t.schY??0},i=e.schematic_net_label.insert({text:t.net,source_net_id:t.net,anchor_position:n,center:n,anchor_side:"bottom"});this.source_net_alias_id=i.source_net_id}},Ftt=class extends T9{constructor(){super(...arguments);rn(this,"pcb_silkscreen_circle_id",null);rn(this,"isPcbPrimitive",!0)}get config(){return{componentName:"SilkscreenCircle",zodProps:kKe}}doInitialPcbPrimitiveRender(){var s,l,c;if((s=this.root)!=null&&s.pcbDisabled)return;const{db:e}=this.root,{_parsedProps:t}=this,{maybeFlipLayer:n}=this._getPcbPrimitiveFlippedHelpers(),i=n(t.layer??"top");if(i!=="top"&&i!=="bottom")throw new Error(`Invalid layer "${i}" for SilkscreenCircle. Must be "top" or "bottom".`);this._computePcbGlobalTransformBeforeLayout();const a=this.getSubcircuit(),o=e.pcb_silkscreen_circle.insert({pcb_component_id:(l=this.parent)==null?void 0:l.pcb_component_id,layer:i,center:{x:t.pcbX??0,y:t.pcbY??0},radius:t.radius,subcircuit_id:(a==null?void 0:a.subcircuit_id)??void 0,pcb_group_id:((c=this.getGroup())==null?void 0:c.pcb_group_id)??void 0,stroke_width:t.strokeWidth??.1});this.pcb_silkscreen_circle_id=o.pcb_silkscreen_circle_id}getPcbSize(){const{_parsedProps:e}=this,t=e.radius*2;return{width:t,height:t}}},Btt=class extends T9{constructor(){super(...arguments);rn(this,"pcb_silkscreen_rect_id",null);rn(this,"isPcbPrimitive",!0)}get config(){return{componentName:"SilkscreenRect",zodProps:IKe}}doInitialPcbPrimitiveRender(){var s,l,c;if((s=this.root)!=null&&s.pcbDisabled)return;const{db:e}=this.root,{_parsedProps:t}=this,{maybeFlipLayer:n}=this._getPcbPrimitiveFlippedHelpers(),i=n(t.layer??"top");if(i!=="top"&&i!=="bottom")throw new Error(`Invalid layer "${i}" for SilkscreenRect. Must be "top" or "bottom".`);const a=this.getSubcircuit(),o=e.pcb_silkscreen_rect.insert({pcb_component_id:(l=this.parent)==null?void 0:l.pcb_component_id,layer:i,center:{x:t.pcbX??0,y:t.pcbY??0},width:t.width,height:t.height,subcircuit_id:(a==null?void 0:a.subcircuit_id)??void 0,pcb_group_id:((c=this==null?void 0:this.getGroup())==null?void 0:c.pcb_group_id)??void 0,stroke_width:t.strokeWidth??.1});this.pcb_silkscreen_rect_id=o.pcb_silkscreen_rect_id}getPcbSize(){const{_parsedProps:e}=this;return{width:e.width,height:e.height}}},Htt=class extends T9{constructor(){super(...arguments);rn(this,"pcb_silkscreen_line_id",null);rn(this,"isPcbPrimitive",!0)}get config(){return{componentName:"SilkscreenLine",zodProps:zKe}}doInitialPcbPrimitiveRender(){var s,l,c;if((s=this.root)!=null&&s.pcbDisabled)return;const{db:e}=this.root,{_parsedProps:t}=this,{maybeFlipLayer:n}=this._getPcbPrimitiveFlippedHelpers(),i=n(t.layer??"top");if(i!=="top"&&i!=="bottom")throw new Error(`Invalid layer "${i}" for SilkscreenLine. Must be "top" or "bottom".`);const a=this.getSubcircuit(),o=e.pcb_silkscreen_line.insert({pcb_component_id:(l=this.parent)==null?void 0:l.pcb_component_id,layer:i,x1:t.x1,y1:t.y1,x2:t.x2,y2:t.y2,stroke_width:t.strokeWidth??.1,subcircuit_id:(a==null?void 0:a.subcircuit_id)??void 0,pcb_group_id:((c=a==null?void 0:a.getGroup())==null?void 0:c.pcb_group_id)??void 0});this.pcb_silkscreen_line_id=o.pcb_silkscreen_line_id}getPcbSize(){const{_parsedProps:e}=this,t=Math.abs(e.x2-e.x1),n=Math.abs(e.y2-e.y1);return{width:t,height:n}}},jtt=class extends T9{constructor(){super(...arguments);rn(this,"pcb_via_id",null);rn(this,"matchedPort",null);rn(this,"isPcbPrimitive",!0)}get config(){return{componentName:"Via",zodProps:PKe}}getAvailablePcbLayers(){return["top","inner1","inner2","bottom"]}getPcbSize(){const{_parsedProps:e}=this;return{width:e.outerDiameter,height:e.outerDiameter}}_getPcbCircuitJsonBounds(){const{db:e}=this.root,t=e.pcb_via.get(this.pcb_via_id),n=this.getPcbSize();return{center:{x:t.x,y:t.y},bounds:{left:t.x-n.width/2,top:t.y-n.height/2,right:t.x+n.width/2,bottom:t.y+n.height/2},width:n.width,height:n.height}}_setPositionFromLayout(e){const{db:t}=this.root;t.pcb_via.update(this.pcb_via_id,{x:e.x,y:e.y})}doInitialPcbPrimitiveRender(){var o,s;if((o=this.root)!=null&&o.pcbDisabled)return;const{db:e}=this.root,{_parsedProps:t}=this,n=this._getGlobalPcbPositionBeforeLayout(),i=this.getSubcircuit(),a=e.pcb_via.insert({x:n.x,y:n.y,hole_diameter:t.holeDiameter,outer_diameter:t.outerDiameter,layers:["bottom","top"],from_layer:t.fromLayer||"bottom",to_layer:t.toLayer||"top",subcircuit_id:(i==null?void 0:i.subcircuit_id)??void 0,pcb_group_id:((s=this.getGroup())==null?void 0:s.pcb_group_id)??void 0});this.pcb_via_id=a.pcb_via_id}},Vtt=class extends yx{get config(){return{componentName:"Battery",schematicSymbolName:this.props.symbolName??"battery",zodProps:_Ke,sourceFtype:"simple_power_source"}}initPorts(){super.initPorts({additionalAliases:{pin1:["anode","pos","left"],pin2:["cathode","neg","right"]}})}doInitialSourceRender(){const{db:r}=this.root,{_parsedProps:e}=this,t=r.source_component.insert({name:e.name,ftype:"simple_power_source",capacity:e.capacity,supplier_part_numbers:e.supplierPartNumbers});this.source_component_id=t.source_component_id}},Gtt=class extends yx{get config(){return{componentName:"PinHeader",zodProps:xKe,shouldRenderAsSchematicBox:!0}}_getImpliedFootprintString(){var i;const r=this._parsedProps.pinCount??((i=this._parsedProps.pinLabels)==null?void 0:i.length)??0,e=this._parsedProps.holeDiameter,t=this._parsedProps.platedDiameter,n=this._parsedProps.pitch;return r>0&&n?!e&&!t?`pinrow${r}_p${n}`:`pinrow${r}_p${n}_id${e}_od${t}`:null}initPorts(){var e,t;const r=this._parsedProps.pinCount??((e=this._parsedProps.pinLabels)==null?void 0:e.length)??1;for(let n=1;n<=r;n++)this.add(new TS({name:`pin${n}`,pinNumber:n,aliases:[(t=this._parsedProps.pinLabels)==null?void 0:t[n-1]].filter(Boolean)}))}_getSchematicPortArrangement(){const r=this._parsedProps.pinCount??1,e=this._parsedProps.facingDirection??"right";return{leftSize:e==="left"?r:0,rightSize:e==="right"?r:0}}doInitialSourceRender(){const{db:r}=this.root,{_parsedProps:e}=this,t=r.source_component.insert({ftype:"simple_pin_header",name:e.name,supplier_part_numbers:e.supplierPartNumbers,pin_count:e.pinCount,gender:e.gender});this.source_component_id=t.source_component_id}};function qtt(r){switch(r){case"two_ground_pins":return"crystal_4pin";case"ground_pin":return"resonator";case"no_ground":return"crystal";default:return"crystal"}}var Wtt=class extends yx{get config(){return{componentName:"Resonator",schematicSymbolName:this.props.symbolName??qtt(this.props.pinVariant),zodProps:tKe,shouldRenderAsSchematicBox:!1}}doInitialSourceRender(){const{db:r}=this.root,{_parsedProps:e}=this,t=r.source_component.insert({ftype:"simple_resonator",name:e.name,frequency:e.frequency,load_capacitance:e.loadCapacitance,supplier_part_numbers:e.supplierPartNumbers,pin_variant:e.pinVariant||"no_ground"});this.source_component_id=t.source_component_id}},Ytt=class extends yx{get config(){return{componentName:"Inductor",schematicSymbolName:this.props.symbolName??"inductor",zodProps:TKe,sourceFtype:nM.simple_inductor}}initPorts(){super.initPorts({additionalAliases:{pin1:["anode","pos","left"],pin2:["cathode","neg","right"]}})}doInitialSourceRender(){const{db:r}=this.root,{_parsedProps:e}=this,t=r.source_component.insert({name:e.name,ftype:nM.simple_inductor,inductance:e.inductance,supplier_part_numbers:e.supplierPartNumbers});this.source_component_id=t.source_component_id}};function Xtt(r){switch(r){case"three_pin":return"potentiometer3";case"two_pin":return"potentiometer2";default:return"potentiometer2"}}var $tt=class extends yx{get config(){return{componentName:"Potentiometer",schematicSymbolName:this.props.symbolName??Xtt(this.props.pinVariant),zodProps:JQe,shouldRenderAsSchematicBox:!1}}doInitialSourceRender(){const{db:r}=this.root,{_parsedProps:e}=this,t=r.source_component.insert({ftype:"simple_potentiometer",name:e.name,max_resistance:e.maxResistance,pin_variant:e.pinVariant||"two_pin"});this.source_component_id=t.source_component_id}},Ztt=class extends yx{get config(){return{componentName:"PushButton",schematicSymbolName:this.props.symbolName??"push_button_normally_open_momentary",zodProps:SKe,sourceFtype:nM.simple_push_button}}get defaultInternallyConnectedPinNames(){return[["pin1","pin4"],["pin2","pin3"]]}initPorts(){super.initPorts({pinCount:4,additionalAliases:{pin1:["side1"],pin3:["side2"]}})}doInitialSourceRender(){const{db:e}=this.root,{_parsedProps:t}=this,n=e.source_component.insert({name:t.name,ftype:nM.simple_push_button,supplier_part_numbers:t.supplierPartNumbers});this.source_component_id=n.source_component_id}},Qtt=class extends yx{get config(){return{schematicSymbolName:this.props.symbolName??(this.props.pinVariant==="four_pin"?"crystal_4pin":"crystal"),componentName:"Crystal",zodProps:eKe,sourceFtype:"simple_crystal"}}initPorts(){const r=this.props.pinVariant==="four_pin"?{pin1:["left1","1"],pin2:["top1","2","gnd1"],pin3:["right1","3"],pin4:["bottom1","4","gnd2"]}:{pin1:["pos","left"],pin2:["neg","right"]};super.initPorts({additionalAliases:r})}_getSchematicSymbolDisplayValue(){return`${zN(this._parsedProps.frequency)}Hz`}doInitialSourceRender(){const{db:r}=this.root,{_parsedProps:e}=this,t=r.source_component.insert({name:e.name,ftype:"simple_crystal",frequency:e.frequency,load_capacitance:e.loadCapacitance,pin_variant:e.pinVariant||"two_pin"});this.source_component_id=t.source_component_id}},Ktt=class extends yx{constructor(){super(...arguments);rn(this,"emitter",this.portMap.pin1);rn(this,"collector",this.portMap.pin2);rn(this,"base",this.portMap.pin3)}get config(){return{componentName:"Transistor",schematicSymbolName:this.props.type==="npn"?"npn_bipolar_transistor":"pnp_bipolar_transistor",zodProps:EKe,sourceFtype:"simple_transistor",shouldRenderAsSchematicBox:!1}}initPorts(){super.initPorts({pinCount:3,additionalAliases:{pin1:["emitter","e"],pin2:["collector","c"],pin3:["base","b"]}})}doInitialSourceRender(){const{db:e}=this.root,{_parsedProps:t}=this,n=e.source_component.insert({ftype:"simple_transistor",name:t.name,transistor_type:t.type});this.source_component_id=n.source_component_id}},Jtt=class extends yx{get config(){const r=this.props.mosfetMode==="depletion"?"d":"e";return{componentName:"Mosfet",schematicSymbolName:`${this.props.channelType}_channel_${r}_mosfet_transistor`,zodProps:wKe,shouldRenderAsSchematicBox:!1}}doInitialSourceRender(){const{db:r}=this.root,{_parsedProps:e}=this,t=r.source_component.insert({ftype:"simple_mosfet",name:e.name,mosfet_mode:e.mosfetMode,channel_type:e.channelType});this.source_component_id=t.source_component_id}},ent=class extends yx{_getSwitchType(){const{spst:r,spdt:e,dpst:t,dpdt:n,type:i}=this._parsedProps??{};return n?"dpdt":r?"spst":e?"spdt":t?"dpst":i??"spst"}get config(){const r=this._getSwitchType(),{isNormallyClosed:e}=this._parsedProps??{};return{componentName:"Switch",schematicSymbolName:{spst:e?"spst_normally_closed_switch":"SPST_switch",spdt:e?"spdt_normally_closed_switch":"SPDT_switch",dpst:e?"dpst_normally_closed_switch":"dpst_switch",dpdt:e?"dpdt_normally_closed_switch":"dpdt_switch"}[r]??"SPST_switch",zodProps:RKe,shouldRenderAsSchematicBox:!1}}doInitialSourceRender(){const{db:r}=this.root,{_parsedProps:e}=this,t=r.source_component.insert({ftype:"simple_switch",name:e.name,switch_type:e.type,is_normally_closed:e.isNormallyClosed??!1});this.source_component_id=t.source_component_id}},tnt={version:"0.0.350"},Dhe=class{constructor(){rn(this,"firstChild",null);rn(this,"children");rn(this,"db");rn(this,"root",null);rn(this,"isRoot",!0);rn(this,"schematicDisabled",!1);rn(this,"pcbDisabled",!1);rn(this,"pcbRoutingDisabled",!1);rn(this,"name");rn(this,"_hasRenderedAtleastOnce",!1);rn(this,"_eventListeners",{});this.children=[],this.db=m1([]),this.root=this}add(r){let e;ut.isValidElement(r)?e=mhe(r):e=r,this.children.push(e)}_getBoard(){return this.children.find(r=>r.componentName==="Board")}_guessRootComponent(){if(!this.firstChild){if(this.children.length===1){this.firstChild=this.children[0];return}if(this.children.length===0)throw new Error("Not able to guess root component: RootCircuit has no children (use circuit.add(...))");if(this.children.length>0){const r=this.children.find(e=>e.componentName==="Board")??null;if(r){this.firstChild=r;return}}throw new Error("Not able to guess root component: RootCircuit has multiple children and no board")}}render(){this.firstChild||this._guessRootComponent();const{firstChild:r,db:e}=this;if(!r)throw new Error("RootCircuit has no root component");r.parent=this,r.runRenderCycle(),this._hasRenderedAtleastOnce=!0}async renderUntilSettled(){var r;for((r=this.db.source_project_metadata.list())!=null&&r[0]||this.db.source_project_metadata.insert({software_used_string:`@tscircuit/core@${this.getCoreVersion()}`}),this.render();this._hasIncompleteAsyncEffects();)await new Promise(e=>setTimeout(e,100)),this.render();this.emit("renderComplete")}_hasIncompleteAsyncEffects(){return this.children.some(r=>r._hasIncompleteAsyncEffects()?!0:r.children.some(e=>e._hasIncompleteAsyncEffects()))}getCircuitJson(){return this._hasRenderedAtleastOnce||this.render(),this.db.toArray()}toJson(){return this.getCircuitJson()}async getSvg(r){return(await Promise.resolve().then(()=>fOt).catch(t=>{throw new Error(`To use circuit.getSvg, you must install the "circuit-to-svg" package.
815
815
 
816
816
  "${t.message}"`)})).convertCircuitJsonToPcbSvg(this.getCircuitJson())}getCoreVersion(){const[r,e,t]=tnt.version.split(".").map(Number);return`${r}.${e}.${t+1}`}async preview(r){throw new Error("project.preview is not yet implemented")}computeSchematicGlobalTransform(){return K_()}_computePcbGlobalTransformBeforeLayout(){return K_()}selectAll(r){var e;return this._guessRootComponent(),((e=this.firstChild)==null?void 0:e.selectAll(r))??[]}selectOne(r,e){var t;return this._guessRootComponent(),((t=this.firstChild)==null?void 0:t.selectOne(r,e))??null}emit(r,...e){if(this._eventListeners[r])for(const t of this._eventListeners[r])t(...e)}on(r,e){this._eventListeners[r]||(this._eventListeners[r]=[]),this._eventListeners[r].push(e)}removeListener(r,e){this._eventListeners[r]&&(this._eventListeners[r]=this._eventListeners[r].filter(t=>t!==e))}getClientOrigin(){return typeof window<"u"?window.location.origin:typeof self<"u"?self.origin:""}},nnt=Dhe,rnt=r=>{const[e,t]=wh.useState(!0),[n,i]=wh.useState(null),[a,o]=wh.useState(),[s,l]=wh.useState();return wh.useEffect(()=>{t(!0),i(null),r&&setTimeout(()=>{try{const c=new Dhe;c.add(r),o(c),l(c.toJson())}catch(c){i(c)}t(!1)},1)},[r]),{isLoading:e,error:n,circuit:a,circuitJson:s}};new Proxy({},{get:(r,e)=>new Proxy({},{get:(t,n)=>e==="net"?`net.${n}`:e==="subcircuit"?new Proxy({},{get:(i,a)=>new Proxy({},{get:(o,s)=>`subcircuit.${n} > .${a} > .${s}`})}):`.${e} > .${n}`})}),hhe(fhe),hhe({Bug:Phe});var bH,Lhe;function Mh(){if(Lhe)return bH;Lhe=1;const r=e=>e.reduce((t,n)=>Array.isArray(n)?t.concat(r(n)):t.concat(n),[]);return bH=r,bH}var SH,Ohe;function int(){return Ohe||(Ohe=1,SH=e=>Object.assign({},e)),SH}var EH,Uhe;function ant(){return Uhe||(Uhe=1,EH=(e,t,n)=>(e[0]=t[0]+n[0],e[1]=t[1]+n[1],e[2]=t[2]+n[2],e[3]=t[3]+n[3],e[4]=t[4]+n[4],e[5]=t[5]+n[5],e[6]=t[6]+n[6],e[7]=t[7]+n[7],e[8]=t[8]+n[8],e[9]=t[9]+n[9],e[10]=t[10]+n[10],e[11]=t[11]+n[11],e[12]=t[12]+n[12],e[13]=t[13]+n[13],e[14]=t[14]+n[14],e[15]=t[15]+n[15],e)),EH}var wH,zhe;function TH(){return zhe||(zhe=1,wH=()=>[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),wH}var MH,Ihe;function ont(){if(Ihe)return MH;Ihe=1;const r=TH();return MH=t=>{const n=r();return n[0]=t[0],n[1]=t[1],n[2]=t[2],n[3]=t[3],n[4]=t[4],n[5]=t[5],n[6]=t[6],n[7]=t[7],n[8]=t[8],n[9]=t[9],n[10]=t[10],n[11]=t[11],n[12]=t[12],n[13]=t[13],n[14]=t[14],n[15]=t[15],n},MH}var CH,khe;function Fhe(){return khe||(khe=1,CH=(e,t)=>(e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7],e[8]=t[8],e[9]=t[9],e[10]=t[10],e[11]=t[11],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15],e)),CH}var RH,Bhe;function snt(){return Bhe||(Bhe=1,RH=(e,t)=>{const n=t[0],i=t[1],a=t[2],o=t[3],s=t[4],l=t[5],c=t[6],u=t[7],f=t[8],v=t[9],_=t[10],x=t[11],M=t[12],w=t[13],T=t[14],L=t[15],O=n*l-i*s,B=n*c-a*s,X=n*u-o*s,$=i*c-a*l,Q=i*u-o*l,ee=a*u-o*c,ae=f*w-v*M,K=f*T-_*M,pe=f*L-x*M,me=v*T-_*w,be=v*L-x*w,Ae=_*L-x*T;let Oe=O*Ae-B*be+X*me+$*pe-Q*K+ee*ae;return Oe?(Oe=1/Oe,e[0]=(l*Ae-c*be+u*me)*Oe,e[1]=(a*be-i*Ae-o*me)*Oe,e[2]=(w*ee-T*Q+L*$)*Oe,e[3]=(_*Q-v*ee-x*$)*Oe,e[4]=(c*pe-s*Ae-u*K)*Oe,e[5]=(n*Ae-a*pe+o*K)*Oe,e[6]=(T*X-M*ee-L*B)*Oe,e[7]=(f*ee-_*X+x*B)*Oe,e[8]=(s*be-l*pe+u*ae)*Oe,e[9]=(i*pe-n*be-o*ae)*Oe,e[10]=(M*Q-w*X+L*O)*Oe,e[11]=(v*X-f*Q-x*O)*Oe,e[12]=(l*K-s*me-c*ae)*Oe,e[13]=(n*me-i*K+a*ae)*Oe,e[14]=(w*B-M*$-T*O)*Oe,e[15]=(f*$-v*B+_*O)*Oe,e):null}),RH}var AH,Hhe;function lnt(){return Hhe||(Hhe=1,AH=(e,t)=>e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]&&e[3]===t[3]&&e[4]===t[4]&&e[5]===t[5]&&e[6]===t[6]&&e[7]===t[7]&&e[8]===t[8]&&e[9]===t[9]&&e[10]===t[10]&&e[11]===t[11]&&e[12]===t[12]&&e[13]===t[13]&&e[14]===t[14]&&e[15]===t[15]),AH}var NH,jhe;function Nm(){if(jhe)return NH;jhe=1;const r=1e5,e=1e-5,t=1e-13,n=Math.PI*2;return NH={EPS:e,NEPS:t,TAU:n,spatialResolution:r},NH}var PH,Vhe;function R2(){if(Vhe)return PH;Vhe=1;const{NEPS:r}=Nm(),e=i=>Math.abs(i)<r?0:i;return PH={sin:i=>e(Math.sin(i)),cos:i=>e(Math.cos(i))},PH}var DH,Ghe;function qhe(){return Ghe||(Ghe=1,DH=e=>(e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=1,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=1,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e)),DH}var LH,Whe;function Yhe(){if(Whe)return LH;Whe=1;const{EPS:r}=Nm(),{sin:e,cos:t}=R2(),n=qhe();return LH=(a,o,s)=>{let[l,c,u]=s;const f=l*l+c*c+u*u;if(Math.abs(f)<r)return n(a);const v=1/Math.sqrt(f);l*=v,c*=v,u*=v;const _=e(o),x=t(o),M=1-x;return a[0]=l*l*M+x,a[1]=c*l*M+u*_,a[2]=u*l*M-c*_,a[3]=0,a[4]=l*c*M-u*_,a[5]=c*c*M+x,a[6]=u*c*M+l*_,a[7]=0,a[8]=l*u*M+c*_,a[9]=c*u*M-l*_,a[10]=u*u*M+x,a[11]=0,a[12]=0,a[13]=0,a[14]=0,a[15]=1,a},LH}var OH,Xhe;function cnt(){return Xhe||(Xhe=1,OH=(e,t)=>(e[0]=t[0],e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=t[1],e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=t[2],e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e)),OH}var UH,$he;function unt(){if($he)return UH;$he=1;const{sin:r,cos:e}=R2();return UH=(n,i,a,o)=>{const s=r(i),l=e(i),c=r(a),u=e(a),f=r(o),v=e(o);return n[0]=u*l,n[1]=u*s,n[2]=-c,n[3]=0,n[4]=f*c*l-v*s,n[5]=v*l+f*c*s,n[6]=f*u,n[7]=0,n[8]=f*s+v*c*l,n[9]=v*c*s-f*l,n[10]=v*u,n[11]=0,n[12]=0,n[13]=0,n[14]=0,n[15]=1,n},UH}var zH,Zhe;function fnt(){return Zhe||(Zhe=1,zH=(e,t)=>(e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=1,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=1,e[11]=0,e[12]=t[0],e[13]=t[1],e[14]=t[2],e[15]=1,e)),zH}var IH,Qhe;function dnt(){if(Qhe)return IH;Qhe=1;const r=TH();return IH=(t,n,i,a,o,s,l,c,u,f,v,_,x,M,w,T)=>{const L=r();return L[0]=t,L[1]=n,L[2]=i,L[3]=a,L[4]=o,L[5]=s,L[6]=l,L[7]=c,L[8]=u,L[9]=f,L[10]=v,L[11]=_,L[12]=x,L[13]=M,L[14]=w,L[15]=T,L},IH}var kH,Khe;function Jhe(){return Khe||(Khe=1,kH=(e,t)=>(e[0]=Math.abs(t[0]),e[1]=Math.abs(t[1]),e[2]=Math.abs(t[2]),e)),kH}var FH,epe;function tpe(){return epe||(epe=1,FH=(e,t,n)=>(e[0]=t[0]+n[0],e[1]=t[1]+n[1],e[2]=t[2]+n[2],e)),FH}var BH,npe;function HN(){return npe||(npe=1,BH=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2]),BH}var HH,rpe;function hnt(){if(rpe)return HH;rpe=1;const r=HN();return HH=(t,n)=>{const i=t[0],a=t[1],o=t[2],s=n[0],l=n[1],c=n[2],u=Math.sqrt(i*i+a*a+o*o),f=Math.sqrt(s*s+l*l+c*c),v=u*f,_=v&&r(t,n)/v;return Math.acos(Math.min(Math.max(_,-1),1))},HH}var jH,ipe;function jN(){return ipe||(ipe=1,jH=()=>[0,0,0]),jH}var VH,ape;function pnt(){if(ape)return VH;ape=1;const r=jN();return VH=t=>{const n=r();return n[0]=t[0],n[1]=t[1],n[2]=t[2],n},VH}var GH,ope;function spe(){return ope||(ope=1,GH=(e,t)=>(e[0]=t[0],e[1]=t[1],e[2]=t[2],e)),GH}var qH,lpe;function rM(){return lpe||(lpe=1,qH=(e,t,n)=>{const i=t[0],a=t[1],o=t[2],s=n[0],l=n[1],c=n[2];return e[0]=a*c-o*l,e[1]=o*s-i*c,e[2]=i*l-a*s,e}),qH}var WH,cpe;function upe(){return cpe||(cpe=1,WH=(e,t)=>{const n=t[0]-e[0],i=t[1]-e[1],a=t[2]-e[2];return Math.sqrt(n*n+i*i+a*a)}),WH}var YH,fpe;function mnt(){return fpe||(fpe=1,YH=(e,t,n)=>(e[0]=t[0]/n[0],e[1]=t[1]/n[1],e[2]=t[2]/n[2],e)),YH}var XH,dpe;function vnt(){return dpe||(dpe=1,XH=(e,t)=>e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]),XH}var $H,hpe;function ynt(){return hpe||(hpe=1,$H=(e,t)=>(e[0]=t,e[1]=t,e[2]=t,e)),$H}var ZH,ppe;function gnt(){if(ppe)return ZH;ppe=1;const r=jN();return ZH=(t,n,i)=>{const a=r();return a[0]=t,a[1]=n,a[2]=i,a},ZH}var QH,mpe;function _nt(){return mpe||(mpe=1,QH=(e,t,n=0)=>(e[0]=t[0],e[1]=t[1],e[2]=n,e)),QH}var KH,vpe;function ype(){return vpe||(vpe=1,KH=e=>{const t=e[0],n=e[1],i=e[2];return Math.sqrt(t*t+n*n+i*i)}),KH}var JH,gpe;function xnt(){return gpe||(gpe=1,JH=(e,t,n,i)=>(e[0]=t[0]+i*(n[0]-t[0]),e[1]=t[1]+i*(n[1]-t[1]),e[2]=t[2]+i*(n[2]-t[2]),e)),JH}var ej,_pe;function xpe(){return _pe||(_pe=1,ej=(e,t,n)=>(e[0]=Math.max(t[0],n[0]),e[1]=Math.max(t[1],n[1]),e[2]=Math.max(t[2],n[2]),e)),ej}var tj,bpe;function Spe(){return bpe||(bpe=1,tj=(e,t,n)=>(e[0]=Math.min(t[0],n[0]),e[1]=Math.min(t[1],n[1]),e[2]=Math.min(t[2],n[2]),e)),tj}var nj,Epe;function bnt(){return Epe||(Epe=1,nj=(e,t,n)=>(e[0]=t[0]*n[0],e[1]=t[1]*n[1],e[2]=t[2]*n[2],e)),nj}var rj,wpe;function Snt(){return wpe||(wpe=1,rj=(e,t)=>(e[0]=-t[0],e[1]=-t[1],e[2]=-t[2],e)),rj}var ij,Tpe;function aj(){return Tpe||(Tpe=1,ij=(e,t)=>{const n=t[0],i=t[1],a=t[2];let o=n*n+i*i+a*a;return o>0&&(o=1/Math.sqrt(o)),e[0]=n*o,e[1]=i*o,e[2]=a*o,e}),ij}var oj,Mpe;function Ent(){if(Mpe)return oj;Mpe=1;const r=Jhe(),e=jN(),t=rM();return oj=(i,a)=>{const o=r(e(),a),s=0+(o[0]<o[1]&&o[0]<o[2]),l=0+(o[1]<=o[0]&&o[1]<o[2]),c=0+(o[2]<=o[0]&&o[2]<=o[1]);return t(i,a,[s,l,c])},oj}var sj,Cpe;function wnt(){return Cpe||(Cpe=1,sj=(e,t,n,i)=>{const a=[],o=[];return a[0]=t[0]-n[0],a[1]=t[1]-n[1],a[2]=t[2]-n[2],o[0]=a[0],o[1]=a[1]*Math.cos(i)-a[2]*Math.sin(i),o[2]=a[1]*Math.sin(i)+a[2]*Math.cos(i),e[0]=o[0]+n[0],e[1]=o[1]+n[1],e[2]=o[2]+n[2],e}),sj}var lj,Rpe;function Tnt(){return Rpe||(Rpe=1,lj=(e,t,n,i)=>{const a=[],o=[];return a[0]=t[0]-n[0],a[1]=t[1]-n[1],a[2]=t[2]-n[2],o[0]=a[2]*Math.sin(i)+a[0]*Math.cos(i),o[1]=a[1],o[2]=a[2]*Math.cos(i)-a[0]*Math.sin(i),e[0]=o[0]+n[0],e[1]=o[1]+n[1],e[2]=o[2]+n[2],e}),lj}var cj,Ape;function Mnt(){return Ape||(Ape=1,cj=(e,t,n,i)=>{const a=[],o=[];return a[0]=t[0]-n[0],a[1]=t[1]-n[1],o[0]=a[0]*Math.cos(i)-a[1]*Math.sin(i),o[1]=a[0]*Math.sin(i)+a[1]*Math.cos(i),e[0]=o[0]+n[0],e[1]=o[1]+n[1],e[2]=t[2],e}),cj}var uj,Npe;function Ppe(){return Npe||(Npe=1,uj=(e,t,n)=>(e[0]=t[0]*n,e[1]=t[1]*n,e[2]=t[2]*n,e)),uj}var fj,Dpe;function Cnt(){return Dpe||(Dpe=1,fj=(e,t,n)=>(e[0]=Math.round(t[0]/n)*n+0,e[1]=Math.round(t[1]/n)*n+0,e[2]=Math.round(t[2]/n)*n+0,e)),fj}var dj,Lpe;function Ope(){return Lpe||(Lpe=1,dj=(e,t)=>{const n=t[0]-e[0],i=t[1]-e[1],a=t[2]-e[2];return n*n+i*i+a*a}),dj}var hj,Upe;function zpe(){return Upe||(Upe=1,hj=e=>{const t=e[0],n=e[1],i=e[2];return t*t+n*n+i*i}),hj}var pj,Ipe;function VN(){return Ipe||(Ipe=1,pj=(e,t,n)=>(e[0]=t[0]-n[0],e[1]=t[1]-n[1],e[2]=t[2]-n[2],e)),pj}var mj,kpe;function Rnt(){return kpe||(kpe=1,mj=e=>`[${e[0].toFixed(7)}, ${e[1].toFixed(7)}, ${e[2].toFixed(7)}]`),mj}var vj,Fpe;function Ant(){return Fpe||(Fpe=1,vj=(e,t,n)=>{const i=t[0],a=t[1],o=t[2];let s=n[3]*i+n[7]*a+n[11]*o+n[15];return s=s||1,e[0]=(n[0]*i+n[4]*a+n[8]*o+n[12])/s,e[1]=(n[1]*i+n[5]*a+n[9]*o+n[13])/s,e[2]=(n[2]*i+n[6]*a+n[10]*o+n[14])/s,e}),vj}var yj,Bpe;function Vu(){return Bpe||(Bpe=1,yj={abs:Jhe(),add:tpe(),angle:hnt(),clone:pnt(),copy:spe(),create:jN(),cross:rM(),distance:upe(),divide:mnt(),dot:HN(),equals:vnt(),fromScalar:ynt(),fromValues:gnt(),fromVec2:_nt(),length:ype(),lerp:xnt(),max:xpe(),min:Spe(),multiply:bnt(),negate:Snt(),normalize:aj(),orthogonal:Ent(),rotateX:wnt(),rotateY:Tnt(),rotateZ:Mnt(),scale:Ppe(),snap:Cnt(),squaredDistance:Ope(),squaredLength:zpe(),subtract:VN(),toString:Rnt(),transform:Ant()}),yj}var gj,Hpe;function Nnt(){if(Hpe)return gj;Hpe=1;const r=Vu(),e=Yhe();return gj=(n,i,a)=>{const o=r.normalize(r.create(),i),s=r.normalize(r.create(),a),l=r.cross(r.create(),s,o),c=r.dot(s,o);if(c===-1)return e(n,Math.PI,r.orthogonal(l,o));const u=1/(1+c);return n[0]=l[0]*l[0]*u+c,n[1]=l[1]*l[0]*u-l[2],n[2]=l[2]*l[0]*u+l[1],n[3]=0,n[4]=l[0]*l[1]*u+l[2],n[5]=l[1]*l[1]*u+c,n[6]=l[2]*l[1]*u-l[0],n[7]=0,n[8]=l[0]*l[2]*u-l[1],n[9]=l[1]*l[2]*u+l[0],n[10]=l[2]*l[2]*u+c,n[11]=0,n[12]=0,n[13]=0,n[14]=0,n[15]=1,n},gj}var _j,jpe;function Pnt(){if(jpe)return _j;jpe=1;const{sin:r,cos:e}=R2();return _j=(n,i)=>{const a=r(i),o=e(i);return n[0]=1,n[1]=0,n[2]=0,n[3]=0,n[4]=0,n[5]=o,n[6]=a,n[7]=0,n[8]=0,n[9]=-a,n[10]=o,n[11]=0,n[12]=0,n[13]=0,n[14]=0,n[15]=1,n},_j}var xj,Vpe;function Dnt(){if(Vpe)return xj;Vpe=1;const{sin:r,cos:e}=R2();return xj=(n,i)=>{const a=r(i),o=e(i);return n[0]=o,n[1]=0,n[2]=-a,n[3]=0,n[4]=0,n[5]=1,n[6]=0,n[7]=0,n[8]=a,n[9]=0,n[10]=o,n[11]=0,n[12]=0,n[13]=0,n[14]=0,n[15]=1,n},xj}var bj,Gpe;function Lnt(){if(Gpe)return bj;Gpe=1;const{sin:r,cos:e}=R2();return bj=(n,i)=>{const a=r(i),o=e(i);return n[0]=o,n[1]=a,n[2]=0,n[3]=0,n[4]=-a,n[5]=o,n[6]=0,n[7]=0,n[8]=0,n[9]=0,n[10]=1,n[11]=0,n[12]=0,n[13]=0,n[14]=0,n[15]=1,n},bj}var Sj,qpe;function Ont(){return qpe||(qpe=1,Sj=e=>e[0]===1&&e[1]===0&&e[2]===0&&e[3]===0&&e[4]===0&&e[5]===1&&e[6]===0&&e[7]===0&&e[8]===0&&e[9]===0&&e[10]===1&&e[11]===0&&e[12]===0&&e[13]===0&&e[14]===0&&e[15]===1),Sj}var Ej,Wpe;function Unt(){if(Wpe)return Ej;Wpe=1;const r=t=>e(t[1])&&e(t[2])&&e(t[3])&&e(t[4])&&e(t[6])&&e(t[7])&&e(t[8])&&e(t[9])&&e(t[11])&&t[15]===1,e=t=>Math.abs(t)<Number.EPSILON;return Ej=r,Ej}var wj,Ype;function znt(){return Ype||(Ype=1,wj=e=>{const t=e[4]*e[9]-e[8]*e[5],n=e[8]*e[1]-e[0]*e[9],i=e[0]*e[5]-e[4]*e[1];return t*e[2]+n*e[6]+i*e[10]<0}),wj}var Tj,Xpe;function Int(){return Xpe||(Xpe=1,Tj=(e,t)=>{const[n,i,a,o]=t;return e[0]=1-2*n*n,e[1]=-2*i*n,e[2]=-2*a*n,e[3]=0,e[4]=-2*n*i,e[5]=1-2*i*i,e[6]=-2*a*i,e[7]=0,e[8]=-2*n*a,e[9]=-2*i*a,e[10]=1-2*a*a,e[11]=0,e[12]=2*n*o,e[13]=2*i*o,e[14]=2*a*o,e[15]=1,e}),Tj}var Mj,$pe;function knt(){return $pe||($pe=1,Mj=(e,t,n)=>{const i=t[0],a=t[1],o=t[2],s=t[3],l=t[4],c=t[5],u=t[6],f=t[7],v=t[8],_=t[9],x=t[10],M=t[11],w=t[12],T=t[13],L=t[14],O=t[15];let B=n[0],X=n[1],$=n[2],Q=n[3];return e[0]=B*i+X*l+$*v+Q*w,e[1]=B*a+X*c+$*_+Q*T,e[2]=B*o+X*u+$*x+Q*L,e[3]=B*s+X*f+$*M+Q*O,B=n[4],X=n[5],$=n[6],Q=n[7],e[4]=B*i+X*l+$*v+Q*w,e[5]=B*a+X*c+$*_+Q*T,e[6]=B*o+X*u+$*x+Q*L,e[7]=B*s+X*f+$*M+Q*O,B=n[8],X=n[9],$=n[10],Q=n[11],e[8]=B*i+X*l+$*v+Q*w,e[9]=B*a+X*c+$*_+Q*T,e[10]=B*o+X*u+$*x+Q*L,e[11]=B*s+X*f+$*M+Q*O,B=n[12],X=n[13],$=n[14],Q=n[15],e[12]=B*i+X*l+$*v+Q*w,e[13]=B*a+X*c+$*_+Q*T,e[14]=B*o+X*u+$*x+Q*L,e[15]=B*s+X*f+$*M+Q*O,e}),Mj}var Cj,Zpe;function Fnt(){if(Zpe)return Cj;Zpe=1;const{EPS:r}=Nm(),{sin:e,cos:t}=R2(),n=Fhe();return Cj=(a,o,s,l)=>{let[c,u,f]=l;const v=c*c+u*u+f*f;if(Math.abs(v)<r)return n(a,o);const _=1/Math.sqrt(v);c*=_,u*=_,f*=_;const x=e(s),M=t(s),w=1-M,T=o[0],L=o[1],O=o[2],B=o[3],X=o[4],$=o[5],Q=o[6],ee=o[7],ae=o[8],K=o[9],pe=o[10],me=o[11],be=c*c*w+M,Ae=u*c*w+f*x,Oe=f*c*w-u*x,we=c*u*w-f*x,Le=u*u*w+M,Te=f*u*w+c*x,je=c*f*w+u*x,Ue=u*f*w-c*x,Ve=f*f*w+M;return a[0]=T*be+X*Ae+ae*Oe,a[1]=L*be+$*Ae+K*Oe,a[2]=O*be+Q*Ae+pe*Oe,a[3]=B*be+ee*Ae+me*Oe,a[4]=T*we+X*Le+ae*Te,a[5]=L*we+$*Le+K*Te,a[6]=O*we+Q*Le+pe*Te,a[7]=B*we+ee*Le+me*Te,a[8]=T*je+X*Ue+ae*Ve,a[9]=L*je+$*Ue+K*Ve,a[10]=O*je+Q*Ue+pe*Ve,a[11]=B*je+ee*Ue+me*Ve,o!==a&&(a[12]=o[12],a[13]=o[13],a[14]=o[14],a[15]=o[15]),a},Cj}var Rj,Qpe;function Bnt(){if(Qpe)return Rj;Qpe=1;const{sin:r,cos:e}=R2();return Rj=(n,i,a)=>{const o=r(a),s=e(a),l=i[4],c=i[5],u=i[6],f=i[7],v=i[8],_=i[9],x=i[10],M=i[11];return i!==n&&(n[0]=i[0],n[1]=i[1],n[2]=i[2],n[3]=i[3],n[12]=i[12],n[13]=i[13],n[14]=i[14],n[15]=i[15]),n[4]=l*s+v*o,n[5]=c*s+_*o,n[6]=u*s+x*o,n[7]=f*s+M*o,n[8]=v*s-l*o,n[9]=_*s-c*o,n[10]=x*s-u*o,n[11]=M*s-f*o,n},Rj}var Aj,Kpe;function Hnt(){if(Kpe)return Aj;Kpe=1;const{sin:r,cos:e}=R2();return Aj=(n,i,a)=>{const o=r(a),s=e(a),l=i[0],c=i[1],u=i[2],f=i[3],v=i[8],_=i[9],x=i[10],M=i[11];return i!==n&&(n[4]=i[4],n[5]=i[5],n[6]=i[6],n[7]=i[7],n[12]=i[12],n[13]=i[13],n[14]=i[14],n[15]=i[15]),n[0]=l*s-v*o,n[1]=c*s-_*o,n[2]=u*s-x*o,n[3]=f*s-M*o,n[8]=l*o+v*s,n[9]=c*o+_*s,n[10]=u*o+x*s,n[11]=f*o+M*s,n},Aj}var Nj,Jpe;function jnt(){if(Jpe)return Nj;Jpe=1;const{sin:r,cos:e}=R2();return Nj=(n,i,a)=>{const o=r(a),s=e(a),l=i[0],c=i[1],u=i[2],f=i[3],v=i[4],_=i[5],x=i[6],M=i[7];return i!==n&&(n[8]=i[8],n[9]=i[9],n[10]=i[10],n[11]=i[11],n[12]=i[12],n[13]=i[13],n[14]=i[14],n[15]=i[15]),n[0]=l*s+v*o,n[1]=c*s+_*o,n[2]=u*s+x*o,n[3]=f*s+M*o,n[4]=v*s-l*o,n[5]=_*s-c*o,n[6]=x*s-u*o,n[7]=M*s-f*o,n},Nj}var Pj,e0e;function Vnt(){return e0e||(e0e=1,Pj=(e,t,n)=>{const i=n[0],a=n[1],o=n[2];return e[0]=t[0]*i,e[1]=t[1]*i,e[2]=t[2]*i,e[3]=t[3]*i,e[4]=t[4]*a,e[5]=t[5]*a,e[6]=t[6]*a,e[7]=t[7]*a,e[8]=t[8]*o,e[9]=t[9]*o,e[10]=t[10]*o,e[11]=t[11]*o,e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15],e}),Pj}var Dj,t0e;function Gnt(){return t0e||(t0e=1,Dj=(e,t,n)=>(e[0]=t[0]-n[0],e[1]=t[1]-n[1],e[2]=t[2]-n[2],e[3]=t[3]-n[3],e[4]=t[4]-n[4],e[5]=t[5]-n[5],e[6]=t[6]-n[6],e[7]=t[7]-n[7],e[8]=t[8]-n[8],e[9]=t[9]-n[9],e[10]=t[10]-n[10],e[11]=t[11]-n[11],e[12]=t[12]-n[12],e[13]=t[13]-n[13],e[14]=t[14]-n[14],e[15]=t[15]-n[15],e)),Dj}var Lj,n0e;function qnt(){return n0e||(n0e=1,Lj=e=>e.map(t=>t.toFixed(7)).toString()),Lj}var Oj,r0e;function Wnt(){return r0e||(r0e=1,Oj=(e,t,n)=>{const i=n[0],a=n[1],o=n[2];let s,l,c,u,f,v,_,x,M,w,T,L;return t===e?(e[12]=t[0]*i+t[4]*a+t[8]*o+t[12],e[13]=t[1]*i+t[5]*a+t[9]*o+t[13],e[14]=t[2]*i+t[6]*a+t[10]*o+t[14],e[15]=t[3]*i+t[7]*a+t[11]*o+t[15]):(s=t[0],l=t[1],c=t[2],u=t[3],f=t[4],v=t[5],_=t[6],x=t[7],M=t[8],w=t[9],T=t[10],L=t[11],e[0]=s,e[1]=l,e[2]=c,e[3]=u,e[4]=f,e[5]=v,e[6]=_,e[7]=x,e[8]=M,e[9]=w,e[10]=T,e[11]=L,e[12]=s*i+f*a+M*o+t[12],e[13]=l*i+v*a+w*o+t[13],e[14]=c*i+_*a+T*o+t[14],e[15]=u*i+x*a+L*o+t[15]),e}),Oj}var Uj,i0e;function ky(){return i0e||(i0e=1,Uj={add:ant(),clone:ont(),copy:Fhe(),create:TH(),invert:snt(),equals:lnt(),fromRotation:Yhe(),fromScaling:cnt(),fromTaitBryanRotation:unt(),fromTranslation:fnt(),fromValues:dnt(),fromVectorRotation:Nnt(),fromXRotation:Pnt(),fromYRotation:Dnt(),fromZRotation:Lnt(),identity:qhe(),isIdentity:Ont(),isOnlyTransformScale:Unt(),isMirroring:znt(),mirrorByPlane:Int(),multiply:knt(),rotate:Fnt(),rotateX:Bnt(),rotateY:Hnt(),rotateZ:jnt(),scale:Vnt(),subtract:Gnt(),toString:qnt(),translate:Wnt()}),Uj}var zj,a0e;function GN(){if(a0e)return zj;a0e=1;const r=ky();return zj=t=>(t===void 0&&(t=[]),{sides:t,transforms:r.create()}),zj}var Ij,o0e;function Ynt(){return o0e||(o0e=1,Ij=(e,t)=>(e[0]=Math.abs(t[0]),e[1]=Math.abs(t[1]),e)),Ij}var kj,s0e;function Xnt(){return s0e||(s0e=1,kj=(e,t,n)=>(e[0]=t[0]+n[0],e[1]=t[1]+n[1],e)),kj}var Fj,l0e;function Bj(){return l0e||(l0e=1,Fj=e=>Math.atan2(e[1],e[0])),Fj}var Hj,c0e;function $nt(){return c0e||(c0e=1,Hj=Bj()),Hj}var jj,u0e;function Znt(){if(u0e)return jj;u0e=1;const r=Bj();return jj=t=>r(t)*57.29577951308232,jj}var Vj,f0e;function qN(){return f0e||(f0e=1,Vj=()=>[0,0]),Vj}var Gj,d0e;function Qnt(){if(d0e)return Gj;d0e=1;const r=qN();return Gj=t=>{const n=r();return n[0]=t[0],n[1]=t[1],n},Gj}var qj,h0e;function Knt(){return h0e||(h0e=1,qj=(e,t)=>(e[0]=t[0],e[1]=t[1],e)),qj}var Wj,p0e;function Jnt(){return p0e||(p0e=1,Wj=(e,t,n)=>(e[0]=0,e[1]=0,e[2]=t[0]*n[1]-t[1]*n[0],e)),Wj}var Yj,m0e;function ert(){return m0e||(m0e=1,Yj=(e,t)=>{const n=t[0]-e[0],i=t[1]-e[1];return Math.sqrt(n*n+i*i)}),Yj}var Xj,v0e;function trt(){return v0e||(v0e=1,Xj=(e,t,n)=>(e[0]=t[0]/n[0],e[1]=t[1]/n[1],e)),Xj}var $j,y0e;function nrt(){return y0e||(y0e=1,$j=(e,t)=>e[0]*t[0]+e[1]*t[1]),$j}var Zj,g0e;function rrt(){return g0e||(g0e=1,Zj=(e,t)=>e[0]===t[0]&&e[1]===t[1]),Zj}var Qj,_0e;function x0e(){if(_0e)return Qj;_0e=1;const{sin:r,cos:e}=R2();return Qj=(n,i)=>(n[0]=e(i),n[1]=r(i),n),Qj}var Kj,b0e;function irt(){if(b0e)return Kj;b0e=1;const r=x0e();return Kj=(t,n)=>r(t,n*.017453292519943295),Kj}var Jj,S0e;function art(){return S0e||(S0e=1,Jj=(e,t)=>(e[0]=t,e[1]=t,e)),Jj}var eV,E0e;function ort(){if(E0e)return eV;E0e=1;const r=qN();return eV=(t,n)=>{const i=r();return i[0]=t,i[1]=n,i},eV}var tV,w0e;function srt(){return w0e||(w0e=1,tV=e=>Math.sqrt(e[0]*e[0]+e[1]*e[1])),tV}var nV,T0e;function lrt(){return T0e||(T0e=1,nV=(e,t,n,i)=>{const a=t[0],o=t[1];return e[0]=a+i*(n[0]-a),e[1]=o+i*(n[1]-o),e}),nV}var rV,M0e;function crt(){return M0e||(M0e=1,rV=(e,t,n)=>(e[0]=Math.max(t[0],n[0]),e[1]=Math.max(t[1],n[1]),e)),rV}var iV,C0e;function urt(){return C0e||(C0e=1,iV=(e,t,n)=>(e[0]=Math.min(t[0],n[0]),e[1]=Math.min(t[1],n[1]),e)),iV}var aV,R0e;function frt(){return R0e||(R0e=1,aV=(e,t,n)=>(e[0]=t[0]*n[0],e[1]=t[1]*n[1],e)),aV}var oV,A0e;function drt(){return A0e||(A0e=1,oV=(e,t)=>(e[0]=-t[0],e[1]=-t[1],e)),oV}var sV,N0e;function P0e(){return N0e||(N0e=1,sV=(e,t,n,i)=>{const a=t[0]-n[0],o=t[1]-n[1],s=Math.cos(i),l=Math.sin(i);return e[0]=a*s-o*l+n[0],e[1]=a*l+o*s+n[1],e}),sV}var lV,D0e;function hrt(){if(D0e)return lV;D0e=1;const{TAU:r}=Nm(),e=qN(),t=P0e();return lV=(i,a)=>t(i,a,e(),r/4),lV}var cV,L0e;function prt(){return L0e||(L0e=1,cV=(e,t)=>{const n=t[0],i=t[1];let a=n*n+i*i;return a>0&&(a=1/Math.sqrt(a)),e[0]=n*a,e[1]=i*a,e}),cV}var uV,O0e;function mrt(){return O0e||(O0e=1,uV=(e,t,n)=>(e[0]=t[0]*n,e[1]=t[1]*n,e)),uV}var fV,U0e;function vrt(){return U0e||(U0e=1,fV=(e,t,n)=>(e[0]=Math.round(t[0]/n)*n+0,e[1]=Math.round(t[1]/n)*n+0,e)),fV}var dV,z0e;function yrt(){return z0e||(z0e=1,dV=(e,t)=>{const n=t[0]-e[0],i=t[1]-e[1];return n*n+i*i}),dV}var hV,I0e;function grt(){return I0e||(I0e=1,hV=e=>{const t=e[0],n=e[1];return t*t+n*n}),hV}var pV,k0e;function _rt(){return k0e||(k0e=1,pV=(e,t,n)=>(e[0]=t[0]-n[0],e[1]=t[1]-n[1],e)),pV}var mV,F0e;function xrt(){return F0e||(F0e=1,mV=e=>`[${e[0].toFixed(7)}, ${e[1].toFixed(7)}]`),mV}var vV,B0e;function brt(){return B0e||(B0e=1,vV=(e,t,n)=>{const i=t[0],a=t[1];return e[0]=n[0]*i+n[4]*a+n[12],e[1]=n[1]*i+n[5]*a+n[13],e}),vV}var yV,H0e;function Zp(){return H0e||(H0e=1,yV={abs:Ynt(),add:Xnt(),angle:$nt(),angleDegrees:Znt(),angleRadians:Bj(),clone:Qnt(),copy:Knt(),create:qN(),cross:Jnt(),distance:ert(),divide:trt(),dot:nrt(),equals:rrt(),fromAngleDegrees:irt(),fromAngleRadians:x0e(),fromScalar:art(),fromValues:ort(),length:srt(),lerp:lrt(),max:crt(),min:urt(),multiply:frt(),negate:drt(),normal:hrt(),normalize:prt(),rotate:P0e(),scale:mrt(),snap:vrt(),squaredDistance:yrt(),squaredLength:grt(),subtract:_rt(),toString:xrt(),transform:brt()}),yV}var gV,j0e;function Srt(){if(j0e)return gV;j0e=1;const r=Zp(),e=GN();return gV=n=>{if(!Array.isArray(n))throw new Error("the given points must be an array");let i=n.length;if(i<3)throw new Error("the given points must define a closed geometry with three or more points");r.equals(n[0],n[i-1])&&--i;const a=[];let o=n[i-1];for(let s=0;s<i;s++){const l=n[s];a.push([r.clone(o),r.clone(l)]),o=l}return e(a)},gV}var _V,V0e;function Ert(){if(V0e)return _V;V0e=1;const r=ky(),e=Zp(),t=GN();return _V=i=>{if(i[0]!==0)throw new Error("invalid compact binary data");const a=t();a.transforms=r.clone(i.slice(1,17));for(let o=21;o<i.length;o+=4){const s=e.fromValues(i[o+0],i[o+1]),l=e.fromValues(i[o+2],i[o+3]);a.sides.push([s,l])}return i[17]>=0&&(a.color=[i[17],i[18],i[19],i[20]]),a},_V}var xV,G0e;function q0e(){return G0e||(G0e=1,xV=e=>!!(e&&typeof e=="object"&&"sides"in e&&"transforms"in e&&Array.isArray(e.sides)&&"length"in e.transforms)),xV}var bV,W0e;function wrt(){if(W0e)return bV;W0e=1;const r=ky(),e=Zp();return bV=n=>(r.isIdentity(n.transforms)||(n.sides=n.sides.map(i=>{const a=e.transform(e.create(),i[0],n.transforms),o=e.transform(e.create(),i[1],n.transforms);return[a,o]}),n.transforms=r.create()),n),bV}var SV,Y0e;function iM(){if(Y0e)return SV;Y0e=1;const r=wrt();return SV=t=>r(t).sides,SV}var EV,X0e;function $0e(){if(X0e)return EV;X0e=1;const r=GN(),e=iM();return EV=n=>{const a=e(n).map(o=>[o[1],o[0]]);return a.reverse(),r(a)},EV}var wV,Z0e;function Q0e(){if(Z0e)return wV;Z0e=1;const r=Zp(),e=iM(),t=o=>{const s=new Map,l=c=>{const u=c.toString();return s.has(u)?s.get(u):(s.set(u,c),c)};return o.map(c=>c.map(l))},n=o=>{const s=new Map;return t(o).forEach(c=>{s.has(c[0])?s.get(c[0]).push(c):s.set(c[0],[c])}),s},i=o=>{const s=n(e(o)),l=[];for(;;){let c;for(const[v,_]of s){if(c=_.shift(),!c){s.delete(v);continue}break}if(c===void 0)break;const u=[],f=c[0];for(;;){u.push(c[0]);const v=c[1];if(v===f)break;const _=s.get(v);if(!_)throw new Error(`geometry is not closed at vertex ${v}`);const x=a(c,_);_.length===0&&s.delete(v),c=x}u.length>0&&u.push(u.shift()),l.push(u)}return s.clear(),l},a=(o,s)=>{if(s.length===1)return s.pop();const l=r.create(),c=r.angleDegrees(r.subtract(l,o[1],o[0]));let u,f;s.forEach((_,x)=>{let w=r.angleDegrees(r.subtract(l,_[1],_[0]))-c;w<-180&&(w+=360),w>=180&&(w-=360),(f===void 0||w>u)&&(f=x,u=w)});const v=s[f];return s.splice(f,1),v};return wV=i,wV}var TV,K0e;function Trt(){if(K0e)return TV;K0e=1;const r=iM();return TV=t=>{const i=r(t).map(a=>a[0]);return i.length>0&&i.push(i.shift()),i},TV}var MV,J0e;function Mrt(){if(J0e)return MV;J0e=1;const r=Zp(),e=iM();return MV=n=>{const i=e(n);let a="geom2 ("+i.length+` sides):
817
817
  [
@@ -13012,7 +13012,7 @@ ${l.join(`
13012
13012
  `)!==-1&&(r=r.replace(/\r\n/g,`
13013
13013
  `)),r.indexOf(`\\
13014
13014
  `)!==-1&&(r=r.replace(/\\\n/g,""));const t=r.split(`
13015
- `);let n="",i="",a=0,o=[];const s=typeof"".trimLeft=="function";for(let u=0,f=t.length;u<f;u++)if(n=t[u],n=s?n.trimLeft():n.trim(),a=n.length,a!==0&&(i=n.charAt(0),i!=="#"))if(i==="v"){const v=n.split(/\s+/);switch(v[0]){case"v":e.vertices.push(parseFloat(v[1]),parseFloat(v[2]),parseFloat(v[3])),v.length>=7?e.colors.push(parseFloat(v[4]),parseFloat(v[5]),parseFloat(v[6])):e.colors.push(void 0,void 0,void 0);break;case"vn":e.normals.push(parseFloat(v[1]),parseFloat(v[2]),parseFloat(v[3]));break;case"vt":e.uvs.push(parseFloat(v[1]),parseFloat(v[2]));break}}else if(i==="f"){const _=n.substr(1).trim().split(/\s+/),x=[];for(let w=0,T=_.length;w<T;w++){const L=_[w];if(L.length>0){const O=L.split("/");x.push(O)}}const M=x[0];for(let w=1,T=x.length-1;w<T;w++){const L=x[w],O=x[w+1];e.addFace(M[0],L[0],O[0],M[1],L[1],O[1],M[2],L[2],O[2])}}else if(i==="l"){const v=n.substring(1).trim().split(" ");let _=[];const x=[];if(n.indexOf("/")===-1)_=v;else for(let M=0,w=v.length;M<w;M++){const T=v[M].split("/");T[0]!==""&&_.push(T[0]),T[1]!==""&&x.push(T[1])}e.addLineGeometry(_,x)}else if(i==="p"){const _=n.substr(1).trim().split(" ");e.addPointGeometry(_)}else if((o=d4t.exec(n))!==null){const v=(" "+o[0].substr(1).trim()).substr(1);e.startObject(v)}else if(p4t.test(n))e.object.startMaterial(n.substring(7).trim(),e.materialLibraries);else if(h4t.test(n))e.materialLibraries.push(n.substring(7).trim());else if(m4t.test(n))console.warn('THREE.OBJLoader: Rendering identifier "usemap" not supported. Textures must be defined in MTL files.');else if(i==="s"){if(o=n.split(" "),o.length>1){const _=o[1].trim().toLowerCase();e.object.smooth=_!=="0"&&_!=="off"}else e.object.smooth=!0;const v=e.object.currentMaterial();v&&(v.smooth=e.object.smooth)}else{if(n==="\0")continue;console.warn('THREE.OBJLoader: Unexpected line: "'+n+'"')}e.finalize();const l=new WE;if(l.materialLibraries=[].concat(e.materialLibraries),!(e.objects.length===1&&e.objects[0].geometry.vertices.length===0)===!0)for(let u=0,f=e.objects.length;u<f;u++){const v=e.objects[u],_=v.geometry,x=v.materials,M=_.type==="Line",w=_.type==="Points";let T=!1;if(_.vertices.length===0)continue;const L=new Rh;L.setAttribute("position",new Rc(_.vertices,3)),_.normals.length>0&&L.setAttribute("normal",new Rc(_.normals,3)),_.colors.length>0&&(T=!0,L.setAttribute("color",new Rc(_.colors,3))),_.hasUVIndices===!0&&L.setAttribute("uv",new Rc(_.uvs,2));const O=[];for(let X=0,$=x.length;X<$;X++){const Q=x[X],ee=Q.name+"_"+Q.smooth+"_"+T;let ae=e.materials[ee];if(this.materials!==null){if(ae=this.materials.create(Q.name),M&&ae&&!(ae instanceof Sx)){const K=new Sx;o2.prototype.copy.call(K,ae),K.color.copy(ae.color),ae=K}else if(w&&ae&&!(ae instanceof KE)){const K=new KE({size:10,sizeAttenuation:!1});o2.prototype.copy.call(K,ae),K.color.copy(ae.color),K.map=ae.map,ae=K}}ae===void 0&&(M?ae=new Sx:w?ae=new KE({size:1,sizeAttenuation:!1}):ae=new lL,ae.name=Q.name,ae.flatShading=!Q.smooth,ae.vertexColors=T,e.materials[ee]=ae),O.push(ae)}let B;if(O.length>1){for(let X=0,$=x.length;X<$;X++){const Q=x[X];L.addGroup(Q.groupStart,Q.groupCount,X)}M?B=new B3(L,O):w?B=new $M(L,O):B=new Yg(L,O)}else M?B=new B3(L,O[0]):w?B=new $M(L,O[0]):B=new Yg(L,O[0]);B.name=v.name,l.add(B)}else if(e.vertices.length>0){const u=new KE({size:1,sizeAttenuation:!1}),f=new Rh;f.setAttribute("position",new Rc(e.vertices,3)),e.colors.length>0&&e.colors[0]!==void 0&&(f.setAttribute("color",new Rc(e.colors,3)),u.vertexColors=!0);const v=new $M(f,u);l.add(v)}return l}};function g4t({stlUrl:r,mtlUrl:e,color:t,opacity:n=1}){const i=IQ(c4t,r),a=ut.useRef();return tt.jsxs("mesh",{ref:a,children:[tt.jsx("primitive",{object:i,attach:"geometry"}),tt.jsx("meshStandardMaterial",{color:t,transparent:n!==1,opacity:n})]})}var _4t={version:"0.0.168"};typeof window<"u"&&(window.TSCI_MAIN_CAMERA_ROTATION=new W5(0,0,0));function x4t(r,e){const t=new N2().setFromEuler(new W5(r.x,r.y,r.z)),n=new Ln(0,0,1);return n.applyQuaternion(t),n.multiplyScalar(e)}var b4t=({})=>{const r=ut.useRef();return ut.useRef({lastRotation:new W5}),mC((e,t)=>{if(!r.current)return;const n=window.TSCI_MAIN_CAMERA_ROTATION,i=x4t(n,2);e.camera.position.copy(i),e.camera.lookAt(0,0,0)}),tt.jsxs("mesh",{ref:r,rotation:[Math.PI/2,0,0],children:[tt.jsx("boxGeometry",{args:[1,1,1]}),tt.jsx("meshStandardMaterial",{color:"white"}),tt.jsx(hw,{position:[0,0,.51],fontSize:.25,color:"black",children:"Front"}),tt.jsx(hw,{position:[0,0,-.51],fontSize:.25,color:"black",rotation:[0,Math.PI,0],children:"Back"}),tt.jsx(hw,{position:[.51,0,0],fontSize:.25,color:"black",rotation:[0,Math.PI/2,0],children:"Right"}),tt.jsx(hw,{position:[-.51,0,0],fontSize:.25,color:"black",rotation:[0,-Math.PI/2,0],children:"Left"}),tt.jsx(hw,{position:[0,.51,0],fontSize:.25,color:"black",rotation:[-Math.PI/2,0,0],children:"Top"}),tt.jsx(hw,{position:[0,-.51,0],fontSize:.25,color:"black",rotation:[Math.PI/2,0,0],children:"Bottom"}),tt.jsx("lineSegments",{args:[new JZ(new L4(1,1,1))],material:new Sx({color:0,linewidth:2})})]})},S4t=()=>(mC(({camera:r})=>{window.TSCI_MAIN_CAMERA_ROTATION=r.rotation}),tt.jsx(tt.Fragment,{})),E4t=ut.forwardRef(({children:r,hoveredComponent:e,initialCameraPosition:t=[5,5,5],autoRotateDisabled:n},i)=>tt.jsxs("div",{style:{position:"relative",width:"100%",height:"100%"},children:[tt.jsx("div",{style:{position:"absolute",top:0,left:0,width:120,height:120},children:tt.jsxs(obe,{camera:{up:[0,0,1],position:[1,1,1]},style:{zIndex:10},children:[tt.jsx("ambientLight",{intensity:Math.PI/2}),tt.jsx(b4t,{})]})}),tt.jsxs(obe,{scene:{up:[0,0,1]},camera:{up:[0,0,1],position:t},children:[tt.jsx(S4t,{}),tt.jsx(jmt,{autoRotate:!n,autoRotateSpeed:1}),tt.jsx("ambientLight",{intensity:Math.PI/2}),tt.jsx("pointLight",{position:[-10,-10,10],decay:0,intensity:Math.PI/4}),tt.jsx(Gmt,{rotation:[Math.PI/2,0,0],infiniteGrid:!0,cellSize:1,sectionSize:10}),tt.jsx("object3D",{ref:i,children:r}),e&&tt.jsx(I0t,{position:e.mousePosition,style:{fontFamily:"sans-serif",transform:"translate3d(50%, 50%, 0)",backgroundColor:"white",padding:"5px",borderRadius:"3px",pointerEvents:"none",userSelect:"none",WebkitUserSelect:"none",MozUserSelect:"none",msUserSelect:"none"},children:e.name})]}),tt.jsxs("div",{style:{position:"absolute",right:24,bottom:24,fontFamily:"sans-serif",color:"white",WebkitTextStroke:"0.5px rgba(0, 0, 0, 0.5)",fontSize:11},children:["@",_4t.version]})]})),w4t=r=>tt.jsx("group",{...r}),T4t=({children:r,isHovered:e,onHover:t,position:n})=>{const i=ut.useRef(null),a=ut.useCallback(s=>{s.stopPropagation();try{const l=s.point||(s.intersections&&s.intersections.length>0?s.intersections[0].point:null)||(n?new Ln(...n):null);l?(i.current=l,t({mousePosition:[l.x,l.y,l.z]})):t({})}catch(l){console.warn("Hover event error:",l),t({})}},[n]),o=ut.useCallback(s=>{s.stopPropagation(),i.current=null,t(null)},[t]);return tt.jsx(w4t,{onPointerEnter:a,onPointerMove:a,onPointerLeave:o,children:r})},FO=T4t;typeof window<"u"&&!window.TSCIRCUIT_OBJ_LOADER_CACHE&&(window.TSCIRCUIT_OBJ_LOADER_CACHE=new Map);function M4t(r){const[e,t]=ut.useState(null);return ut.useEffect(()=>{if(!r)return;const n=window.TSCIRCUIT_OBJ_LOADER_CACHE;let i=!1;async function a(){var s;try{const c=await(await fetch(r)).text(),u=(s=c.match(/newmtl[\s\S]*?endmtl/g))==null?void 0:s.join(`
13015
+ `);let n="",i="",a=0,o=[];const s=typeof"".trimLeft=="function";for(let u=0,f=t.length;u<f;u++)if(n=t[u],n=s?n.trimLeft():n.trim(),a=n.length,a!==0&&(i=n.charAt(0),i!=="#"))if(i==="v"){const v=n.split(/\s+/);switch(v[0]){case"v":e.vertices.push(parseFloat(v[1]),parseFloat(v[2]),parseFloat(v[3])),v.length>=7?e.colors.push(parseFloat(v[4]),parseFloat(v[5]),parseFloat(v[6])):e.colors.push(void 0,void 0,void 0);break;case"vn":e.normals.push(parseFloat(v[1]),parseFloat(v[2]),parseFloat(v[3]));break;case"vt":e.uvs.push(parseFloat(v[1]),parseFloat(v[2]));break}}else if(i==="f"){const _=n.substr(1).trim().split(/\s+/),x=[];for(let w=0,T=_.length;w<T;w++){const L=_[w];if(L.length>0){const O=L.split("/");x.push(O)}}const M=x[0];for(let w=1,T=x.length-1;w<T;w++){const L=x[w],O=x[w+1];e.addFace(M[0],L[0],O[0],M[1],L[1],O[1],M[2],L[2],O[2])}}else if(i==="l"){const v=n.substring(1).trim().split(" ");let _=[];const x=[];if(n.indexOf("/")===-1)_=v;else for(let M=0,w=v.length;M<w;M++){const T=v[M].split("/");T[0]!==""&&_.push(T[0]),T[1]!==""&&x.push(T[1])}e.addLineGeometry(_,x)}else if(i==="p"){const _=n.substr(1).trim().split(" ");e.addPointGeometry(_)}else if((o=d4t.exec(n))!==null){const v=(" "+o[0].substr(1).trim()).substr(1);e.startObject(v)}else if(p4t.test(n))e.object.startMaterial(n.substring(7).trim(),e.materialLibraries);else if(h4t.test(n))e.materialLibraries.push(n.substring(7).trim());else if(m4t.test(n))console.warn('THREE.OBJLoader: Rendering identifier "usemap" not supported. Textures must be defined in MTL files.');else if(i==="s"){if(o=n.split(" "),o.length>1){const _=o[1].trim().toLowerCase();e.object.smooth=_!=="0"&&_!=="off"}else e.object.smooth=!0;const v=e.object.currentMaterial();v&&(v.smooth=e.object.smooth)}else{if(n==="\0")continue;console.warn('THREE.OBJLoader: Unexpected line: "'+n+'"')}e.finalize();const l=new WE;if(l.materialLibraries=[].concat(e.materialLibraries),!(e.objects.length===1&&e.objects[0].geometry.vertices.length===0)===!0)for(let u=0,f=e.objects.length;u<f;u++){const v=e.objects[u],_=v.geometry,x=v.materials,M=_.type==="Line",w=_.type==="Points";let T=!1;if(_.vertices.length===0)continue;const L=new Rh;L.setAttribute("position",new Rc(_.vertices,3)),_.normals.length>0&&L.setAttribute("normal",new Rc(_.normals,3)),_.colors.length>0&&(T=!0,L.setAttribute("color",new Rc(_.colors,3))),_.hasUVIndices===!0&&L.setAttribute("uv",new Rc(_.uvs,2));const O=[];for(let X=0,$=x.length;X<$;X++){const Q=x[X],ee=Q.name+"_"+Q.smooth+"_"+T;let ae=e.materials[ee];if(this.materials!==null){if(ae=this.materials.create(Q.name),M&&ae&&!(ae instanceof Sx)){const K=new Sx;o2.prototype.copy.call(K,ae),K.color.copy(ae.color),ae=K}else if(w&&ae&&!(ae instanceof KE)){const K=new KE({size:10,sizeAttenuation:!1});o2.prototype.copy.call(K,ae),K.color.copy(ae.color),K.map=ae.map,ae=K}}ae===void 0&&(M?ae=new Sx:w?ae=new KE({size:1,sizeAttenuation:!1}):ae=new lL,ae.name=Q.name,ae.flatShading=!Q.smooth,ae.vertexColors=T,e.materials[ee]=ae),O.push(ae)}let B;if(O.length>1){for(let X=0,$=x.length;X<$;X++){const Q=x[X];L.addGroup(Q.groupStart,Q.groupCount,X)}M?B=new B3(L,O):w?B=new $M(L,O):B=new Yg(L,O)}else M?B=new B3(L,O[0]):w?B=new $M(L,O[0]):B=new Yg(L,O[0]);B.name=v.name,l.add(B)}else if(e.vertices.length>0){const u=new KE({size:1,sizeAttenuation:!1}),f=new Rh;f.setAttribute("position",new Rc(e.vertices,3)),e.colors.length>0&&e.colors[0]!==void 0&&(f.setAttribute("color",new Rc(e.colors,3)),u.vertexColors=!0);const v=new $M(f,u);l.add(v)}return l}};function g4t({stlUrl:r,mtlUrl:e,color:t,opacity:n=1}){const i=IQ(c4t,r),a=ut.useRef();return tt.jsxs("mesh",{ref:a,children:[tt.jsx("primitive",{object:i,attach:"geometry"}),tt.jsx("meshStandardMaterial",{color:t,transparent:n!==1,opacity:n})]})}var _4t={version:"0.0.169"};typeof window<"u"&&(window.TSCI_MAIN_CAMERA_ROTATION=new W5(0,0,0));function x4t(r,e){const t=new N2().setFromEuler(new W5(r.x,r.y,r.z)),n=new Ln(0,0,1);return n.applyQuaternion(t),n.multiplyScalar(e)}var b4t=({})=>{const r=ut.useRef();return ut.useRef({lastRotation:new W5}),mC((e,t)=>{if(!r.current)return;const n=window.TSCI_MAIN_CAMERA_ROTATION,i=x4t(n,2);e.camera.position.copy(i),e.camera.lookAt(0,0,0)}),tt.jsxs("mesh",{ref:r,rotation:[Math.PI/2,0,0],children:[tt.jsx("boxGeometry",{args:[1,1,1]}),tt.jsx("meshStandardMaterial",{color:"white"}),tt.jsx(hw,{position:[0,0,.51],fontSize:.25,color:"black",children:"Front"}),tt.jsx(hw,{position:[0,0,-.51],fontSize:.25,color:"black",rotation:[0,Math.PI,0],children:"Back"}),tt.jsx(hw,{position:[.51,0,0],fontSize:.25,color:"black",rotation:[0,Math.PI/2,0],children:"Right"}),tt.jsx(hw,{position:[-.51,0,0],fontSize:.25,color:"black",rotation:[0,-Math.PI/2,0],children:"Left"}),tt.jsx(hw,{position:[0,.51,0],fontSize:.25,color:"black",rotation:[-Math.PI/2,0,0],children:"Top"}),tt.jsx(hw,{position:[0,-.51,0],fontSize:.25,color:"black",rotation:[Math.PI/2,0,0],children:"Bottom"}),tt.jsx("lineSegments",{args:[new JZ(new L4(1,1,1))],material:new Sx({color:0,linewidth:2})})]})},S4t=()=>(mC(({camera:r})=>{window.TSCI_MAIN_CAMERA_ROTATION=r.rotation}),tt.jsx(tt.Fragment,{})),E4t=ut.forwardRef(({children:r,hoveredComponent:e,initialCameraPosition:t=[5,5,5],autoRotateDisabled:n},i)=>tt.jsxs("div",{style:{position:"relative",width:"100%",height:"100%"},children:[tt.jsx("div",{style:{position:"absolute",top:0,left:0,width:120,height:120},children:tt.jsxs(obe,{camera:{up:[0,0,1],position:[1,1,1]},style:{zIndex:10},children:[tt.jsx("ambientLight",{intensity:Math.PI/2}),tt.jsx(b4t,{})]})}),tt.jsxs(obe,{scene:{up:[0,0,1]},camera:{up:[0,0,1],position:t},children:[tt.jsx(S4t,{}),tt.jsx(jmt,{autoRotate:!n,autoRotateSpeed:1}),tt.jsx("ambientLight",{intensity:Math.PI/2}),tt.jsx("pointLight",{position:[-10,-10,10],decay:0,intensity:Math.PI/4}),tt.jsx(Gmt,{rotation:[Math.PI/2,0,0],infiniteGrid:!0,cellSize:1,sectionSize:10}),tt.jsx("object3D",{ref:i,children:r}),e&&tt.jsx(I0t,{position:e.mousePosition,style:{fontFamily:"sans-serif",transform:"translate3d(50%, 50%, 0)",backgroundColor:"white",padding:"5px",borderRadius:"3px",pointerEvents:"none",userSelect:"none",WebkitUserSelect:"none",MozUserSelect:"none",msUserSelect:"none"},children:e.name})]}),tt.jsxs("div",{style:{position:"absolute",right:24,bottom:24,fontFamily:"sans-serif",color:"white",WebkitTextStroke:"0.5px rgba(0, 0, 0, 0.5)",fontSize:11},children:["@",_4t.version]})]})),w4t=r=>tt.jsx("group",{...r}),T4t=({children:r,isHovered:e,onHover:t,position:n})=>{const i=ut.useRef(null),a=ut.useCallback(s=>{s.stopPropagation();try{const l=s.point||(s.intersections&&s.intersections.length>0?s.intersections[0].point:null)||(n?new Ln(...n):null);l?(i.current=l,t({mousePosition:[l.x,l.y,l.z]})):t({})}catch(l){console.warn("Hover event error:",l),t({})}},[n]),o=ut.useCallback(s=>{s.stopPropagation(),i.current=null,t(null)},[t]);return tt.jsx(w4t,{onPointerEnter:a,onPointerMove:a,onPointerLeave:o,children:r})},FO=T4t;typeof window<"u"&&!window.TSCIRCUIT_OBJ_LOADER_CACHE&&(window.TSCIRCUIT_OBJ_LOADER_CACHE=new Map);function M4t(r){const[e,t]=ut.useState(null);return ut.useEffect(()=>{if(!r)return;const n=window.TSCIRCUIT_OBJ_LOADER_CACHE;let i=!1;async function a(){var s;try{const c=await(await fetch(r)).text(),u=(s=c.match(/newmtl[\s\S]*?endmtl/g))==null?void 0:s.join(`
13016
13016
  `).replace(/d 0\./g,"d 1."),f=c.replace(/newmtl[\s\S]*?endmtl/g,""),v=new u4t;v.setMaterialOptions({invertTrProperty:!0});const _=v.parse(u.replace(/Kd\s+([\d.]+)\s+([\d.]+)\s+([\d.]+)/g,"Kd $2 $2 $2"),"test.mtl"),x=new y4t;return x.setMaterials(_),x.parse(f)}catch(l){return l}}function o(){if(n.has(r)){const l=n.get(r);return l.result?Promise.resolve(l.result.clone()):l.promise.then(c=>c.clone())}const s=a().then(l=>(l instanceof Error||n.set(r,{...n.get(r),result:l}),l));return n.set(r,{promise:s,result:null}),s}return o().then(s=>{i||t(s)}).catch(s=>{console.error(s)}),()=>{i=!0}},[r]),e}function C4t({url:r,position:e,rotation:t,onHover:n,isHovered:i}){const a=M4t(r);return a?a instanceof Error?tt.jsx(FO,{isHovered:i,onHover:n,children:tt.jsxs("mesh",{position:e,children:[tt.jsx("boxGeometry",{args:[.5,.5,.5]}),tt.jsx("meshStandardMaterial",{transparent:!0,color:"red",opacity:.5}),tt.jsx("meshBasicMaterial",{color:"red"})]})}):tt.jsx(FO,{isHovered:i,onHover:n,children:tt.jsx("primitive",{rotation:t,position:e,object:a})}):tt.jsx(FO,{isHovered:i,onHover:n,children:tt.jsxs("mesh",{position:e,children:[tt.jsx("boxGeometry",{args:[.5,.5,.5]}),tt.jsx("meshStandardMaterial",{transparent:!0,color:"red",opacity:.25})]})})}var R4t=u5(lMe()),yMe=({jscadPlan:r,positionOffset:e,rotationOffset:t,onHover:n,isHovered:i})=>{const{threeGeom:a,material:o}=ut.useMemo(()=>{const s=Zbe.executeJscadOperations(R4t.default,r),l=Hvt(s),c=new sL({vertexColors:!0,side:p3});return{threeGeom:l,material:c}},[r]);return ut.useMemo(()=>{if(i){const s=new Cl(o.color.getHex());o.emissive.copy(s),o.emissive.setRGB(0,0,1),o.emissiveIntensity=.2}else o.emissiveIntensity=0},[i,o]),a?tt.jsx(FO,{isHovered:i,onHover:n,position:e,children:tt.jsx("mesh",{geometry:a,material:o,position:e,rotation:t})}):null},{createJSCADRoot:A4t}=Fvt(Zbe.jscadPlanner),N4t=({positionOffset:r,footprint:e,rotationOffset:t,onHover:n,isHovered:i})=>{const a=ut.useMemo(()=>{if(!e)return null;const o=[];return A4t(o).render(tt.jsx(o2t,{footprint:e})),o},[e]);return a?tt.jsx(tt.Fragment,{children:a.map((o,s)=>tt.jsx(yMe,{positionOffset:r,rotationOffset:t,jscadPlan:o,onHover:n,isHovered:i},s))}):null},P4t=(...r)=>r,D4t=({cad_component:r,onHover:e=()=>{},isHovered:t=!1})=>{const n=r.model_obj_url??r.model_stl_url,i=r.rotation?P4t(r.rotation.x*Math.PI/180,r.rotation.y*Math.PI/180,r.rotation.z*Math.PI/180):void 0;if(n)return tt.jsx(C4t,{url:n,position:r.position?[r.position.x,r.position.y,r.position.z]:void 0,rotation:i,onHover:e,isHovered:t},r.cad_component_id);if(r.model_jscad)return tt.jsx(yMe,{jscadPlan:r.model_jscad,rotationOffset:i,onHover:e,isHovered:t},r.cad_component_id);if(r.footprinter_string)return tt.jsx(N4t,{positionOffset:r.position?[r.position.x,r.position.y,r.position.z]:void 0,rotationOffset:i,footprint:r.footprinter_string,onHover:e,isHovered:t})},L4t=class extends wh.Component{constructor(r){super(r),this.state={hasError:!1,error:null}}static getDerivedStateFromError(r){return{hasError:!0,error:r}}render(){return this.state.hasError&&this.state.error?this.props.fallback({error:this.state.error}):this.props.children}},O4t=({error:r,cad_component:e})=>{let t=[0,0,0];return e!=null&&e.position&&(t=[e.position.x,e.position.y,e.position.z],t=t.map(n=>Number.isNaN(n)?0:n)),tt.jsxs("group",{position:t,children:[tt.jsxs("mesh",{renderOrder:-99999,rotation:[Math.PI/4,Math.PI/4,0],ref:n=>{n&&(n.renderOrder=999999)},children:[tt.jsx("boxGeometry",{args:[.5,.5,.5]}),tt.jsx("meshStandardMaterial",{depthTest:!1,transparent:!0,color:"red",opacity:.5})]}),tt.jsxs(hw,{scale:[.1,.1,.1],color:"red",anchorX:"center",anchorY:"middle",depthOffset:-99999,children:[r.toString().slice(0,50),"..."]})]})},U4t=ut.forwardRef(({soup:r,circuitJson:e,children:t,autoRotateDisabled:n},i)=>{e??(e=r);const[a,o]=ut.useState(null);e??(e=QSt(t));const s=ut.useMemo(()=>{if(!e)return[5,5,5];try{const f=m1(e).pcb_board.list()[0];if(!f)return[5,5,5];const{width:v,height:_}=f,x=Math.max(v,_);return[x/2,x/2,x]}catch(f){return console.error(f),[5,5,5]}},[e]),l=ut.useMemo(()=>!e||!e.some(f=>f.type==="pcb_board")?null:a4t(e),[e]),{stls:c}=s4t(l);if(!e)return null;const u=m1(e).cad_component.list();return tt.jsxs(E4t,{ref:i,hoveredComponent:a,autoRotateDisabled:n,initialCameraPosition:s,children:[c.map(({stlUrl:f,color:v},_)=>tt.jsx(g4t,{stlUrl:f,color:v,opacity:_===0?.95:1},f)),u.map(f=>tt.jsx(L4t,{fallback:({error:v})=>tt.jsx(O4t,{cad_component:f,error:v}),children:tt.jsx(D4t,{onHover:v=>{var x;if(v||o(null),!v.mousePosition)return;const _=(x=m1(e).source_component.getUsing({source_component_id:f.source_component_id}))==null?void 0:x.name;o({cad_component_id:f.cad_component_id,name:_??"<unknown>",mousePosition:v.mousePosition})},cad_component:f,isHovered:(a==null?void 0:a.cad_component_id)===f.cad_component_id},f.cad_component_id)},f.cad_component_id))]})}),z4t=u5(ZSt());u5(lMe()),(0,z4t.default)("tscircuit:3d-viewer:convert-circuit-json-to-3d-svg");const g7=r=>typeof r=="number"&&!isNaN(r),Cw=r=>typeof r=="string",x3=r=>typeof r=="function",BO=r=>Cw(r)||x3(r)?r:null,gee=r=>ut.isValidElement(r)||Cw(r)||x3(r)||g7(r);function I4t(r,e,t){t===void 0&&(t=300);const{scrollHeight:n,style:i}=r;requestAnimationFrame(()=>{i.minHeight="initial",i.height=n+"px",i.transition=`all ${t}ms`,requestAnimationFrame(()=>{i.height="0",i.padding="0",i.margin="0",setTimeout(e,t)})})}function HO(r){let{enter:e,exit:t,appendPosition:n=!1,collapse:i=!0,collapseDuration:a=300}=r;return function(o){let{children:s,position:l,preventExitTransition:c,done:u,nodeRef:f,isIn:v,playToast:_}=o;const x=n?`${e}--${l}`:e,M=n?`${t}--${l}`:t,w=ut.useRef(0);return ut.useLayoutEffect(()=>{const T=f.current,L=x.split(" "),O=B=>{B.target===f.current&&(_(),T.removeEventListener("animationend",O),T.removeEventListener("animationcancel",O),w.current===0&&B.type!=="animationcancel"&&T.classList.remove(...L))};T.classList.add(...L),T.addEventListener("animationend",O),T.addEventListener("animationcancel",O)},[]),ut.useEffect(()=>{const T=f.current,L=()=>{T.removeEventListener("animationend",L),i?I4t(T,u,a):u()};v||(c?L():(w.current=1,T.className+=` ${M}`,T.addEventListener("animationend",L)))},[v]),wh.createElement(wh.Fragment,null,s)}}function gMe(r,e){return r!=null?{content:r.content,containerId:r.props.containerId,id:r.props.toastId,theme:r.props.theme,type:r.props.type,data:r.props.data||{},isLoading:r.props.isLoading,icon:r.props.icon,status:e}:{}}const M5=new Map;let _7=[];const _ee=new Set,k4t=r=>_ee.forEach(e=>e(r)),_Me=()=>M5.size>0;function xMe(r,e){var t;if(e)return!((t=M5.get(e))==null||!t.isToastActive(r));let n=!1;return M5.forEach(i=>{i.isToastActive(r)&&(n=!0)}),n}function bMe(r,e){gee(r)&&(_Me()||_7.push({content:r,options:e}),M5.forEach(t=>{t.buildToast(r,e)}))}function SMe(r,e){M5.forEach(t=>{e!=null&&e!=null&&e.containerId?(e==null?void 0:e.containerId)===t.id&&t.toggle(r,e==null?void 0:e.id):t.toggle(r,e==null?void 0:e.id)})}function F4t(r){const{subscribe:e,getSnapshot:t,setProps:n}=ut.useRef(function(a){const o=a.containerId||1;return{subscribe(s){const l=function(u,f,v){let _=1,x=0,M=[],w=[],T=[],L=f;const O=new Map,B=new Set,X=()=>{T=Array.from(O.values()),B.forEach(ee=>ee())},$=ee=>{w=ee==null?[]:w.filter(ae=>ae!==ee),X()},Q=ee=>{const{toastId:ae,onOpen:K,updateId:pe,children:me}=ee.props,be=pe==null;ee.staleId&&O.delete(ee.staleId),O.set(ae,ee),w=[...w,ee.props.toastId].filter(Ae=>Ae!==ee.staleId),X(),v(gMe(ee,be?"added":"updated")),be&&x3(K)&&K(ut.isValidElement(me)&&me.props)};return{id:u,props:L,observe:ee=>(B.add(ee),()=>B.delete(ee)),toggle:(ee,ae)=>{O.forEach(K=>{ae!=null&&ae!==K.props.toastId||x3(K.toggle)&&K.toggle(ee)})},removeToast:$,toasts:O,clearQueue:()=>{x-=M.length,M=[]},buildToast:(ee,ae)=>{if((ze=>{let{containerId:lt,toastId:it,updateId:vt}=ze;const At=lt?lt!==u:u!==1,Ot=O.has(it)&&vt==null;return At||Ot})(ae))return;const{toastId:K,updateId:pe,data:me,staleId:be,delay:Ae}=ae,Oe=()=>{$(K)},we=pe==null;we&&x++;const Le={...L,style:L.toastStyle,key:_++,...Object.fromEntries(Object.entries(ae).filter(ze=>{let[lt,it]=ze;return it!=null})),toastId:K,updateId:pe,data:me,closeToast:Oe,isIn:!1,className:BO(ae.className||L.toastClassName),bodyClassName:BO(ae.bodyClassName||L.bodyClassName),progressClassName:BO(ae.progressClassName||L.progressClassName),autoClose:!ae.isLoading&&(Te=ae.autoClose,je=L.autoClose,Te===!1||g7(Te)&&Te>0?Te:je),deleteToast(){const ze=O.get(K),{onClose:lt,children:it}=ze.props;x3(lt)&&lt(ut.isValidElement(it)&&it.props),v(gMe(ze,"removed")),O.delete(K),x--,x<0&&(x=0),M.length>0?Q(M.shift()):X()}};var Te,je;Le.closeButton=L.closeButton,ae.closeButton===!1||gee(ae.closeButton)?Le.closeButton=ae.closeButton:ae.closeButton===!0&&(Le.closeButton=!gee(L.closeButton)||L.closeButton);let Ue=ee;ut.isValidElement(ee)&&!Cw(ee.type)?Ue=ut.cloneElement(ee,{closeToast:Oe,toastProps:Le,data:me}):x3(ee)&&(Ue=ee({closeToast:Oe,toastProps:Le,data:me}));const Ve={content:Ue,props:Le,staleId:be};L.limit&&L.limit>0&&x>L.limit&&we?M.push(Ve):g7(Ae)?setTimeout(()=>{Q(Ve)},Ae):Q(Ve)},setProps(ee){L=ee},setToggle:(ee,ae)=>{O.get(ee).toggle=ae},isToastActive:ee=>w.some(ae=>ae===ee),getSnapshot:()=>T}}(o,a,k4t);M5.set(o,l);const c=l.observe(s);return _7.forEach(u=>bMe(u.content,u.options)),_7=[],()=>{c(),M5.delete(o)}},setProps(s){var l;(l=M5.get(o))==null||l.setProps(s)},getSnapshot(){var s;return(s=M5.get(o))==null?void 0:s.getSnapshot()}}}(r)).current;n(r);const i=ut.useSyncExternalStore(e,t,t);return{getToastToRender:function(a){if(!i)return[];const o=new Map;return r.newestOnTop&&i.reverse(),i.forEach(s=>{const{position:l}=s.props;o.has(l)||o.set(l,[]),o.get(l).push(s)}),Array.from(o,s=>a(s[0],s[1]))},isToastActive:xMe,count:i==null?void 0:i.length}}function B4t(r){const[e,t]=ut.useState(!1),[n,i]=ut.useState(!1),a=ut.useRef(null),o=ut.useRef({start:0,delta:0,removalDistance:0,canCloseOnClick:!0,canDrag:!1,didMove:!1}).current,{autoClose:s,pauseOnHover:l,closeToast:c,onClick:u,closeOnClick:f}=r;var v,_;function x(){t(!0)}function M(){t(!1)}function w(O){const B=a.current;o.canDrag&&B&&(o.didMove=!0,e&&M(),o.delta=r.draggableDirection==="x"?O.clientX-o.start:O.clientY-o.start,o.start!==O.clientX&&(o.canCloseOnClick=!1),B.style.transform=`translate3d(${r.draggableDirection==="x"?`${o.delta}px, var(--y)`:`0, calc(${o.delta}px + var(--y))`},0)`,B.style.opacity=""+(1-Math.abs(o.delta/o.removalDistance)))}function T(){document.removeEventListener("pointermove",w),document.removeEventListener("pointerup",T);const O=a.current;if(o.canDrag&&o.didMove&&O){if(o.canDrag=!1,Math.abs(o.delta)>o.removalDistance)return i(!0),r.closeToast(),void r.collapseAll();O.style.transition="transform 0.2s, opacity 0.2s",O.style.removeProperty("transform"),O.style.removeProperty("opacity")}}(_=M5.get((v={id:r.toastId,containerId:r.containerId,fn:t}).containerId||1))==null||_.setToggle(v.id,v.fn),ut.useEffect(()=>{if(r.pauseOnFocusLoss)return document.hasFocus()||M(),window.addEventListener("focus",x),window.addEventListener("blur",M),()=>{window.removeEventListener("focus",x),window.removeEventListener("blur",M)}},[r.pauseOnFocusLoss]);const L={onPointerDown:function(O){if(r.draggable===!0||r.draggable===O.pointerType){o.didMove=!1,document.addEventListener("pointermove",w),document.addEventListener("pointerup",T);const B=a.current;o.canCloseOnClick=!0,o.canDrag=!0,B.style.transition="none",r.draggableDirection==="x"?(o.start=O.clientX,o.removalDistance=B.offsetWidth*(r.draggablePercent/100)):(o.start=O.clientY,o.removalDistance=B.offsetHeight*(r.draggablePercent===80?1.5*r.draggablePercent:r.draggablePercent)/100)}},onPointerUp:function(O){const{top:B,bottom:X,left:$,right:Q}=a.current.getBoundingClientRect();O.nativeEvent.type!=="touchend"&&r.pauseOnHover&&O.clientX>=$&&O.clientX<=Q&&O.clientY>=B&&O.clientY<=X?M():x()}};return s&&l&&(L.onMouseEnter=M,r.stacked||(L.onMouseLeave=x)),f&&(L.onClick=O=>{u&&u(O),o.canCloseOnClick&&c()}),{playToast:x,pauseToast:M,isRunning:e,preventExitTransition:n,toastRef:a,eventHandlers:L}}function H4t(r){let{delay:e,isRunning:t,closeToast:n,type:i="default",hide:a,className:o,style:s,controlledProgress:l,progress:c,rtl:u,isIn:f,theme:v}=r;const _=a||l&&c===0,x={...s,animationDuration:`${e}ms`,animationPlayState:t?"running":"paused"};l&&(x.transform=`scaleX(${c})`);const M=Pb("Toastify__progress-bar",l?"Toastify__progress-bar--controlled":"Toastify__progress-bar--animated",`Toastify__progress-bar-theme--${v}`,`Toastify__progress-bar--${i}`,{"Toastify__progress-bar--rtl":u}),w=x3(o)?o({rtl:u,type:i,defaultClassName:M}):Pb(M,o),T={[l&&c>=1?"onTransitionEnd":"onAnimationEnd"]:l&&c<1?null:()=>{f&&n()}};return wh.createElement("div",{className:"Toastify__progress-bar--wrp","data-hidden":_},wh.createElement("div",{className:`Toastify__progress-bar--bg Toastify__progress-bar-theme--${v} Toastify__progress-bar--${i}`}),wh.createElement("div",{role:"progressbar","aria-hidden":_?"true":"false","aria-label":"notification timer",className:w,style:x,...T}))}let j4t=1;const EMe=()=>""+j4t++;function V4t(r){return r&&(Cw(r.toastId)||g7(r.toastId))?r.toastId:EMe()}function x7(r,e){return bMe(r,e),e.toastId}function jO(r,e){return{...e,type:e&&e.type||r,toastId:V4t(e)}}function VO(r){return(e,t)=>x7(e,jO(r,t))}function Hy(r,e){return x7(r,jO("default",e))}Hy.loading=(r,e)=>x7(r,jO("default",{isLoading:!0,autoClose:!1,closeOnClick:!1,closeButton:!1,draggable:!1,...e})),Hy.promise=function(r,e,t){let n,{pending:i,error:a,success:o}=e;i&&(n=Cw(i)?Hy.loading(i,t):Hy.loading(i.render,{...t,...i}));const s={isLoading:null,autoClose:null,closeOnClick:null,closeButton:null,draggable:null},l=(u,f,v)=>{if(f==null)return void Hy.dismiss(n);const _={type:u,...s,...t,data:v},x=Cw(f)?{render:f}:f;return n?Hy.update(n,{..._,...x}):Hy(x.render,{..._,...x}),v},c=x3(r)?r():r;return c.then(u=>l("success",o,u)).catch(u=>l("error",a,u)),c},Hy.success=VO("success"),Hy.info=VO("info"),Hy.error=VO("error"),Hy.warning=VO("warning"),Hy.warn=Hy.warning,Hy.dark=(r,e)=>x7(r,jO("default",{theme:"dark",...e})),Hy.dismiss=function(r){(function(e){var t;if(_Me()){if(e==null||Cw(t=e)||g7(t))M5.forEach(n=>{n.removeToast(e)});else if(e&&("containerId"in e||"id"in e)){const n=M5.get(e.containerId);n?n.removeToast(e.id):M5.forEach(i=>{i.removeToast(e.id)})}}else _7=_7.filter(n=>e!=null&&n.options.toastId!==e)})(r)},Hy.clearWaitingQueue=function(r){r===void 0&&(r={}),M5.forEach(e=>{!e.props.limit||r.containerId&&e.id!==r.containerId||e.clearQueue()})},Hy.isActive=xMe,Hy.update=function(r,e){e===void 0&&(e={});const t=((n,i)=>{var a;let{containerId:o}=i;return(a=M5.get(o||1))==null?void 0:a.toasts.get(n)})(r,e);if(t){const{props:n,content:i}=t,a={delay:100,...n,...e,toastId:e.toastId||r,updateId:EMe()};a.toastId!==r&&(a.staleId=r);const o=a.render||i;delete a.render,x7(o,a)}},Hy.done=r=>{Hy.update(r,{progress:1})},Hy.onChange=function(r){return _ee.add(r),()=>{_ee.delete(r)}},Hy.play=r=>SMe(!0,r),Hy.pause=r=>SMe(!1,r);const G4t=typeof window<"u"?ut.useLayoutEffect:ut.useEffect,GO=r=>{let{theme:e,type:t,isLoading:n,...i}=r;return wh.createElement("svg",{viewBox:"0 0 24 24",width:"100%",height:"100%",fill:e==="colored"?"currentColor":`var(--toastify-icon-color-${t})`,...i})},xee={info:function(r){return wh.createElement(GO,{...r},wh.createElement("path",{d:"M12 0a12 12 0 1012 12A12.013 12.013 0 0012 0zm.25 5a1.5 1.5 0 11-1.5 1.5 1.5 1.5 0 011.5-1.5zm2.25 13.5h-4a1 1 0 010-2h.75a.25.25 0 00.25-.25v-4.5a.25.25 0 00-.25-.25h-.75a1 1 0 010-2h1a2 2 0 012 2v4.75a.25.25 0 00.25.25h.75a1 1 0 110 2z"}))},warning:function(r){return wh.createElement(GO,{...r},wh.createElement("path",{d:"M23.32 17.191L15.438 2.184C14.728.833 13.416 0 11.996 0c-1.42 0-2.733.833-3.443 2.184L.533 17.448a4.744 4.744 0 000 4.368C1.243 23.167 2.555 24 3.975 24h16.05C22.22 24 24 22.044 24 19.632c0-.904-.251-1.746-.68-2.44zm-9.622 1.46c0 1.033-.724 1.823-1.698 1.823s-1.698-.79-1.698-1.822v-.043c0-1.028.724-1.822 1.698-1.822s1.698.79 1.698 1.822v.043zm.039-12.285l-.84 8.06c-.057.581-.408.943-.897.943-.49 0-.84-.367-.896-.942l-.84-8.065c-.057-.624.25-1.095.779-1.095h1.91c.528.005.84.476.784 1.1z"}))},success:function(r){return wh.createElement(GO,{...r},wh.createElement("path",{d:"M12 0a12 12 0 1012 12A12.014 12.014 0 0012 0zm6.927 8.2l-6.845 9.289a1.011 1.011 0 01-1.43.188l-4.888-3.908a1 1 0 111.25-1.562l4.076 3.261 6.227-8.451a1 1 0 111.61 1.183z"}))},error:function(r){return wh.createElement(GO,{...r},wh.createElement("path",{d:"M11.983 0a12.206 12.206 0 00-8.51 3.653A11.8 11.8 0 000 12.207 11.779 11.779 0 0011.8 24h.214A12.111 12.111 0 0024 11.791 11.766 11.766 0 0011.983 0zM10.5 16.542a1.476 1.476 0 011.449-1.53h.027a1.527 1.527 0 011.523 1.47 1.475 1.475 0 01-1.449 1.53h-.027a1.529 1.529 0 01-1.523-1.47zM11 12.5v-6a1 1 0 012 0v6a1 1 0 11-2 0z"}))},spinner:function(){return wh.createElement("div",{className:"Toastify__spinner"})}},q4t=r=>{const{isRunning:e,preventExitTransition:t,toastRef:n,eventHandlers:i,playToast:a}=B4t(r),{closeButton:o,children:s,autoClose:l,onClick:c,type:u,hideProgressBar:f,closeToast:v,transition:_,position:x,className:M,style:w,bodyClassName:T,bodyStyle:L,progressClassName:O,progressStyle:B,updateId:X,role:$,progress:Q,rtl:ee,toastId:ae,deleteToast:K,isIn:pe,isLoading:me,closeOnClick:be,theme:Ae}=r,Oe=Pb("Toastify__toast",`Toastify__toast-theme--${Ae}`,`Toastify__toast--${u}`,{"Toastify__toast--rtl":ee},{"Toastify__toast--close-on-click":be}),we=x3(M)?M({rtl:ee,position:x,type:u,defaultClassName:Oe}):Pb(Oe,M),Le=function(Ve){let{theme:ze,type:lt,isLoading:it,icon:vt}=Ve,At=null;const Ot={theme:ze,type:lt};return vt===!1||(x3(vt)?At=vt({...Ot,isLoading:it}):ut.isValidElement(vt)?At=ut.cloneElement(vt,Ot):it?At=xee.spinner():(Qt=>Qt in xee)(lt)&&(At=xee[lt](Ot))),At}(r),Te=!!Q||!l,je={closeToast:v,type:u,theme:Ae};let Ue=null;return o===!1||(Ue=x3(o)?o(je):ut.isValidElement(o)?ut.cloneElement(o,je):function(Ve){let{closeToast:ze,theme:lt,ariaLabel:it="close"}=Ve;return wh.createElement("button",{className:`Toastify__close-button Toastify__close-button--${lt}`,type:"button",onClick:vt=>{vt.stopPropagation(),ze(vt)},"aria-label":it},wh.createElement("svg",{"aria-hidden":"true",viewBox:"0 0 14 16"},wh.createElement("path",{fillRule:"evenodd",d:"M7.71 8.23l3.75 3.75-1.48 1.48-3.75-3.75-3.75 3.75L1 11.98l3.75-3.75L1 4.48 2.48 3l3.75 3.75L9.98 3l1.48 1.48-3.75 3.75z"})))}(je)),wh.createElement(_,{isIn:pe,done:K,position:x,preventExitTransition:t,nodeRef:n,playToast:a},wh.createElement("div",{id:ae,onClick:c,"data-in":pe,className:we,...i,style:w,ref:n},wh.createElement("div",{...pe&&{role:$},className:x3(T)?T({type:u}):Pb("Toastify__toast-body",T),style:L},Le!=null&&wh.createElement("div",{className:Pb("Toastify__toast-icon",{"Toastify--animate-icon Toastify__zoom-enter":!me})},Le),wh.createElement("div",null,s)),Ue,wh.createElement(H4t,{...X&&!Te?{key:`pb-${X}`}:{},rtl:ee,theme:Ae,delay:l,isRunning:e,isIn:pe,closeToast:v,hide:f,type:u,style:B,className:O,controlledProgress:Te,progress:Q||0})))},qO=function(r,e){return e===void 0&&(e=!1),{enter:`Toastify--animate Toastify__${r}-enter`,exit:`Toastify--animate Toastify__${r}-exit`,appendPosition:e}},W4t=HO(qO("bounce",!0));HO(qO("slide",!0)),HO(qO("zoom")),HO(qO("flip"));const Y4t={position:"top-right",transition:W4t,autoClose:5e3,closeButton:!0,pauseOnHover:!0,pauseOnFocusLoss:!0,draggable:"touch",draggablePercent:80,draggableDirection:"x",role:"alert",theme:"light"};function X4t(r){let e={...Y4t,...r};const t=r.stacked,[n,i]=ut.useState(!0),a=ut.useRef(null),{getToastToRender:o,isToastActive:s,count:l}=F4t(e),{className:c,style:u,rtl:f,containerId:v}=e;function _(M){const w=Pb("Toastify__toast-container",`Toastify__toast-container--${M}`,{"Toastify__toast-container--rtl":f});return x3(c)?c({position:M,rtl:f,defaultClassName:w}):Pb(w,BO(c))}function x(){t&&(i(!0),Hy.play())}return G4t(()=>{if(t){var M;const w=a.current.querySelectorAll('[data-in="true"]'),T=12,L=(M=e.position)==null?void 0:M.includes("top");let O=0,B=0;Array.from(w).reverse().forEach((X,$)=>{const Q=X;Q.classList.add("Toastify__toast--stacked"),$>0&&(Q.dataset.collapsed=`${n}`),Q.dataset.pos||(Q.dataset.pos=L?"top":"bot");const ee=O*(n?.2:1)+(n?0:T*$);Q.style.setProperty("--y",`${L?ee:-1*ee}px`),Q.style.setProperty("--g",`${T}`),Q.style.setProperty("--s",""+(1-(n?B:0))),O+=Q.offsetHeight,B+=.025})}},[n,l,t]),wh.createElement("div",{ref:a,className:"Toastify",id:v,onMouseEnter:()=>{t&&(i(!1),Hy.pause())},onMouseLeave:x},o((M,w)=>{const T=w.length?{...u}:{...u,pointerEvents:"none"};return wh.createElement("div",{className:_(M),style:T,key:`container-${M}`},w.map(L=>{let{content:O,props:B}=L;return wh.createElement(q4t,{...B,stacked:t,collapseAll:x,isIn:s(B.toastId,B.containerId),style:B.style,key:`toast-${B.key}`},O)}))}))}function $4t(){var r=':root{--toastify-color-light:#fff;--toastify-color-dark:#121212;--toastify-color-info:#3498db;--toastify-color-success:#07bc0c;--toastify-color-warning:#f1c40f;--toastify-color-error:#e74c3c;--toastify-color-transparent:hsla(0,0%,100%,.7);--toastify-icon-color-info:var(--toastify-color-info);--toastify-icon-color-success:var(--toastify-color-success);--toastify-icon-color-warning:var(--toastify-color-warning);--toastify-icon-color-error:var(--toastify-color-error);--toastify-toast-width:320px;--toastify-toast-offset:16px;--toastify-toast-top:max(var(--toastify-toast-offset),env(safe-area-inset-top));--toastify-toast-right:max(var(--toastify-toast-offset),env(safe-area-inset-right));--toastify-toast-left:max(var(--toastify-toast-offset),env(safe-area-inset-left));--toastify-toast-bottom:max(var(--toastify-toast-offset),env(safe-area-inset-bottom));--toastify-toast-background:#fff;--toastify-toast-min-height:64px;--toastify-toast-max-height:800px;--toastify-toast-bd-radius:6px;--toastify-font-family:sans-serif;--toastify-z-index:9999;--toastify-text-color-light:#757575;--toastify-text-color-dark:#fff;--toastify-text-color-info:#fff;--toastify-text-color-success:#fff;--toastify-text-color-warning:#fff;--toastify-text-color-error:#fff;--toastify-spinner-color:#616161;--toastify-spinner-color-empty-area:#e0e0e0;--toastify-color-progress-light:linear-gradient(90deg,#4cd964,#5ac8fa,#007aff,#34aadc,#5856d6,#ff2d55);--toastify-color-progress-dark:#bb86fc;--toastify-color-progress-info:var(--toastify-color-info);--toastify-color-progress-success:var(--toastify-color-success);--toastify-color-progress-warning:var(--toastify-color-warning);--toastify-color-progress-error:var(--toastify-color-error);--toastify-color-progress-bgo:0.2}.Toastify__toast-container{z-index:var(--toastify-z-index);-webkit-transform:translateZ(var(--toastify-z-index));position:fixed;padding:4px;width:var(--toastify-toast-width);box-sizing:border-box;color:#fff}.Toastify__toast-container--top-left{top:var(--toastify-toast-top);left:var(--toastify-toast-left)}.Toastify__toast-container--top-center{top:var(--toastify-toast-top);left:50%;transform:translateX(-50%)}.Toastify__toast-container--top-right{top:var(--toastify-toast-top);right:var(--toastify-toast-right)}.Toastify__toast-container--bottom-left{bottom:var(--toastify-toast-bottom);left:var(--toastify-toast-left)}.Toastify__toast-container--bottom-center{bottom:var(--toastify-toast-bottom);left:50%;transform:translateX(-50%)}.Toastify__toast-container--bottom-right{bottom:var(--toastify-toast-bottom);right:var(--toastify-toast-right)}@media only screen and (max-width:480px){.Toastify__toast-container{width:100vw;padding:0;left:env(safe-area-inset-left);margin:0}.Toastify__toast-container--top-center,.Toastify__toast-container--top-left,.Toastify__toast-container--top-right{top:env(safe-area-inset-top);transform:translateX(0)}.Toastify__toast-container--bottom-center,.Toastify__toast-container--bottom-left,.Toastify__toast-container--bottom-right{bottom:env(safe-area-inset-bottom);transform:translateX(0)}.Toastify__toast-container--rtl{right:env(safe-area-inset-right);left:auto}}.Toastify__toast{--y:0;position:relative;-ms-touch-action:none;touch-action:none;min-height:var(--toastify-toast-min-height);box-sizing:border-box;margin-bottom:1rem;padding:8px;border-radius:var(--toastify-toast-bd-radius);box-shadow:0 4px 12px rgba(0,0,0,.1);display:-ms-flexbox;display:flex;-ms-flex-pack:justify;justify-content:space-between;max-height:var(--toastify-toast-max-height);font-family:var(--toastify-font-family);cursor:default;direction:ltr;z-index:0;overflow:hidden}.Toastify__toast--stacked{position:absolute;width:100%;transform:translate3d(0,var(--y),0) scale(var(--s));transition:transform .3s}.Toastify__toast--stacked[data-collapsed] .Toastify__close-button,.Toastify__toast--stacked[data-collapsed] .Toastify__toast-body{transition:opacity .1s}.Toastify__toast--stacked[data-collapsed=false]{overflow:visible}.Toastify__toast--stacked[data-collapsed=true]:not(:last-child)>*{opacity:0}.Toastify__toast--stacked:after{content:"";position:absolute;left:0;right:0;height:calc(var(--g) * 1px);bottom:100%}.Toastify__toast--stacked[data-pos=top]{top:0}.Toastify__toast--stacked[data-pos=bot]{bottom:0}.Toastify__toast--stacked[data-pos=bot].Toastify__toast--stacked:before{transform-origin:top}.Toastify__toast--stacked[data-pos=top].Toastify__toast--stacked:before{transform-origin:bottom}.Toastify__toast--stacked:before{content:"";position:absolute;left:0;right:0;bottom:0;height:100%;transform:scaleY(3);z-index:-1}.Toastify__toast--rtl{direction:rtl}.Toastify__toast--close-on-click{cursor:pointer}.Toastify__toast-body{margin:auto 0;-ms-flex:1 1 auto;flex:1 1 auto;padding:6px;display:-ms-flexbox;display:flex;-ms-flex-align:center;align-items:center}.Toastify__toast-body>div:last-child{word-break:break-word;-ms-flex:1;flex:1}.Toastify__toast-icon{-webkit-margin-end:10px;margin-inline-end:10px;width:20px;-ms-flex-negative:0;flex-shrink:0;display:-ms-flexbox;display:flex}.Toastify--animate{animation-fill-mode:both;animation-duration:.5s}.Toastify--animate-icon{animation-fill-mode:both;animation-duration:.3s}@media only screen and (max-width:480px){.Toastify__toast{margin-bottom:0;border-radius:0}}.Toastify__toast-theme--dark{background:var(--toastify-color-dark);color:var(--toastify-text-color-dark)}.Toastify__toast-theme--colored.Toastify__toast--default,.Toastify__toast-theme--light{background:var(--toastify-color-light);color:var(--toastify-text-color-light)}.Toastify__toast-theme--colored.Toastify__toast--info{color:var(--toastify-text-color-info);background:var(--toastify-color-info)}.Toastify__toast-theme--colored.Toastify__toast--success{color:var(--toastify-text-color-success);background:var(--toastify-color-success)}.Toastify__toast-theme--colored.Toastify__toast--warning{color:var(--toastify-text-color-warning);background:var(--toastify-color-warning)}.Toastify__toast-theme--colored.Toastify__toast--error{color:var(--toastify-text-color-error);background:var(--toastify-color-error)}.Toastify__progress-bar-theme--light{background:var(--toastify-color-progress-light)}.Toastify__progress-bar-theme--dark{background:var(--toastify-color-progress-dark)}.Toastify__progress-bar--info{background:var(--toastify-color-progress-info)}.Toastify__progress-bar--success{background:var(--toastify-color-progress-success)}.Toastify__progress-bar--warning{background:var(--toastify-color-progress-warning)}.Toastify__progress-bar--error{background:var(--toastify-color-progress-error)}.Toastify__progress-bar-theme--colored.Toastify__progress-bar--error,.Toastify__progress-bar-theme--colored.Toastify__progress-bar--info,.Toastify__progress-bar-theme--colored.Toastify__progress-bar--success,.Toastify__progress-bar-theme--colored.Toastify__progress-bar--warning{background:var(--toastify-color-transparent)}.Toastify__close-button{color:#fff;background:transparent;outline:none;border:none;padding:0;cursor:pointer;opacity:.7;transition:.3s ease;-ms-flex-item-align:start;align-self:flex-start;z-index:1}.Toastify__close-button--light{color:#000;opacity:.3}.Toastify__close-button>svg{fill:currentColor;height:16px;width:14px}.Toastify__close-button:focus,.Toastify__close-button:hover{opacity:1}@keyframes Toastify__trackProgress{0%{transform:scaleX(1)}to{transform:scaleX(0)}}.Toastify__progress-bar{position:absolute;bottom:0;left:0;width:100%;height:100%;z-index:var(--toastify-z-index);opacity:.7;transform-origin:left;border-bottom-left-radius:var(--toastify-toast-bd-radius)}.Toastify__progress-bar--animated{animation:Toastify__trackProgress linear 1 forwards}.Toastify__progress-bar--controlled{transition:transform .2s}.Toastify__progress-bar--rtl{right:0;left:auto;transform-origin:right;border-bottom-left-radius:0;border-bottom-right-radius:var(--toastify-toast-bd-radius)}.Toastify__progress-bar--wrp{position:absolute;bottom:0;left:0;width:100%;height:5px;border-bottom-left-radius:var(--toastify-toast-bd-radius)}.Toastify__progress-bar--wrp[data-hidden=true]{opacity:0}.Toastify__progress-bar--bg{opacity:var(--toastify-color-progress-bgo);width:100%;height:100%}.Toastify__spinner{width:20px;height:20px;box-sizing:border-box;border:2px solid;border-radius:100%;border-color:var(--toastify-spinner-color-empty-area);border-right-color:var(--toastify-spinner-color);animation:Toastify__spin .65s linear infinite}@keyframes Toastify__bounceInRight{0%,60%,75%,90%,to{animation-timing-function:cubic-bezier(.215,.61,.355,1)}0%{opacity:0;transform:translate3d(3000px,0,0)}60%{opacity:1;transform:translate3d(-25px,0,0)}75%{transform:translate3d(10px,0,0)}90%{transform:translate3d(-5px,0,0)}to{transform:none}}@keyframes Toastify__bounceOutRight{20%{opacity:1;transform:translate3d(-20px,var(--y),0)}to{opacity:0;transform:translate3d(2000px,var(--y),0)}}@keyframes Toastify__bounceInLeft{0%,60%,75%,90%,to{animation-timing-function:cubic-bezier(.215,.61,.355,1)}0%{opacity:0;transform:translate3d(-3000px,0,0)}60%{opacity:1;transform:translate3d(25px,0,0)}75%{transform:translate3d(-10px,0,0)}90%{transform:translate3d(5px,0,0)}to{transform:none}}@keyframes Toastify__bounceOutLeft{20%{opacity:1;transform:translate3d(20px,var(--y),0)}to{opacity:0;transform:translate3d(-2000px,var(--y),0)}}@keyframes Toastify__bounceInUp{0%,60%,75%,90%,to{animation-timing-function:cubic-bezier(.215,.61,.355,1)}0%{opacity:0;transform:translate3d(0,3000px,0)}60%{opacity:1;transform:translate3d(0,-20px,0)}75%{transform:translate3d(0,10px,0)}90%{transform:translate3d(0,-5px,0)}to{transform:translateZ(0)}}@keyframes Toastify__bounceOutUp{20%{transform:translate3d(0,calc(var(--y) - 10px),0)}40%,45%{opacity:1;transform:translate3d(0,calc(var(--y) + 20px),0)}to{opacity:0;transform:translate3d(0,-2000px,0)}}@keyframes Toastify__bounceInDown{0%,60%,75%,90%,to{animation-timing-function:cubic-bezier(.215,.61,.355,1)}0%{opacity:0;transform:translate3d(0,-3000px,0)}60%{opacity:1;transform:translate3d(0,25px,0)}75%{transform:translate3d(0,-10px,0)}90%{transform:translate3d(0,5px,0)}to{transform:none}}@keyframes Toastify__bounceOutDown{20%{transform:translate3d(0,calc(var(--y) - 10px),0)}40%,45%{opacity:1;transform:translate3d(0,calc(var(--y) + 20px),0)}to{opacity:0;transform:translate3d(0,2000px,0)}}.Toastify__bounce-enter--bottom-left,.Toastify__bounce-enter--top-left{animation-name:Toastify__bounceInLeft}.Toastify__bounce-enter--bottom-right,.Toastify__bounce-enter--top-right{animation-name:Toastify__bounceInRight}.Toastify__bounce-enter--top-center{animation-name:Toastify__bounceInDown}.Toastify__bounce-enter--bottom-center{animation-name:Toastify__bounceInUp}.Toastify__bounce-exit--bottom-left,.Toastify__bounce-exit--top-left{animation-name:Toastify__bounceOutLeft}.Toastify__bounce-exit--bottom-right,.Toastify__bounce-exit--top-right{animation-name:Toastify__bounceOutRight}.Toastify__bounce-exit--top-center{animation-name:Toastify__bounceOutUp}.Toastify__bounce-exit--bottom-center{animation-name:Toastify__bounceOutDown}@keyframes Toastify__zoomIn{0%{opacity:0;transform:scale3d(.3,.3,.3)}50%{opacity:1}}@keyframes Toastify__zoomOut{0%{opacity:1}50%{opacity:0;transform:translate3d(0,var(--y),0) scale3d(.3,.3,.3)}to{opacity:0}}.Toastify__zoom-enter{animation-name:Toastify__zoomIn}.Toastify__zoom-exit{animation-name:Toastify__zoomOut}@keyframes Toastify__flipIn{0%{transform:perspective(400px) rotateX(90deg);animation-timing-function:ease-in;opacity:0}40%{transform:perspective(400px) rotateX(-20deg);animation-timing-function:ease-in}60%{transform:perspective(400px) rotateX(10deg);opacity:1}80%{transform:perspective(400px) rotateX(-5deg)}to{transform:perspective(400px)}}@keyframes Toastify__flipOut{0%{transform:translate3d(0,var(--y),0) perspective(400px)}30%{transform:translate3d(0,var(--y),0) perspective(400px) rotateX(-20deg);opacity:1}to{transform:translate3d(0,var(--y),0) perspective(400px) rotateX(90deg);opacity:0}}.Toastify__flip-enter{animation-name:Toastify__flipIn}.Toastify__flip-exit{animation-name:Toastify__flipOut}@keyframes Toastify__slideInRight{0%{transform:translate3d(110%,0,0);visibility:visible}to{transform:translate3d(0,var(--y),0)}}@keyframes Toastify__slideInLeft{0%{transform:translate3d(-110%,0,0);visibility:visible}to{transform:translate3d(0,var(--y),0)}}@keyframes Toastify__slideInUp{0%{transform:translate3d(0,110%,0);visibility:visible}to{transform:translate3d(0,var(--y),0)}}@keyframes Toastify__slideInDown{0%{transform:translate3d(0,-110%,0);visibility:visible}to{transform:translate3d(0,var(--y),0)}}@keyframes Toastify__slideOutRight{0%{transform:translate3d(0,var(--y),0)}to{visibility:hidden;transform:translate3d(110%,var(--y),0)}}@keyframes Toastify__slideOutLeft{0%{transform:translate3d(0,var(--y),0)}to{visibility:hidden;transform:translate3d(-110%,var(--y),0)}}@keyframes Toastify__slideOutDown{0%{transform:translate3d(0,var(--y),0)}to{visibility:hidden;transform:translate3d(0,500px,0)}}@keyframes Toastify__slideOutUp{0%{transform:translate3d(0,var(--y),0)}to{visibility:hidden;transform:translate3d(0,-500px,0)}}.Toastify__slide-enter--bottom-left,.Toastify__slide-enter--top-left{animation-name:Toastify__slideInLeft}.Toastify__slide-enter--bottom-right,.Toastify__slide-enter--top-right{animation-name:Toastify__slideInRight}.Toastify__slide-enter--top-center{animation-name:Toastify__slideInDown}.Toastify__slide-enter--bottom-center{animation-name:Toastify__slideInUp}.Toastify__slide-exit--bottom-left,.Toastify__slide-exit--top-left{animation-name:Toastify__slideOutLeft;animation-timing-function:ease-in;animation-duration:.3s}.Toastify__slide-exit--bottom-right,.Toastify__slide-exit--top-right{animation-name:Toastify__slideOutRight;animation-timing-function:ease-in;animation-duration:.3s}.Toastify__slide-exit--top-center{animation-name:Toastify__slideOutUp;animation-timing-function:ease-in;animation-duration:.3s}.Toastify__slide-exit--bottom-center{animation-name:Toastify__slideOutDown;animation-timing-function:ease-in;animation-duration:.3s}@keyframes Toastify__spin{0%{transform:rotate(0deg)}to{transform:rotate(1turn)}}',e=document.createElement("style");e.innerText=r,document.head.appendChild(e)}const Z4t=qw(bqe);var bee,wMe;function Q4t(){if(wMe)return bee;wMe=1;var r=Object.defineProperty,e=Object.getOwnPropertyDescriptor,t=Object.getOwnPropertyNames,n=Object.prototype.hasOwnProperty,i=(w,T)=>{for(var L in T)r(w,L,{get:T[L],enumerable:!0})},a=(w,T,L,O)=>{if(T&&typeof T=="object"||typeof T=="function")for(let B of t(T))!n.call(w,B)&&B!==L&&r(w,B,{get:()=>T[B],enumerable:!(O=e(T,B))||O.enumerable});return w},o=w=>a(r({},"__esModule",{value:!0}),w),s={};i(s,{SuperGrid:()=>M,toMMSI:()=>x,toMeterSI:()=>_}),bee=o(s);var l=n2(),c=Z4t,u=Mae(),f=(w,T,L)=>{const O=[];if(T<w)for(let B=w;B>=T;B-=Math.abs(L))O.push(B);else for(let B=w;B<=T;B+=Math.abs(L))O.push(B);return O};function v(w,T){return{x:Math.round(T.x/w)*w,y:Math.round(T.y/w)*w}}function _(w,T=1){return w<0?"-"+_(-w):w<1e-6?"0m":w>1e3?Math.floor(w/1e3)+"km":w>1&&T>1?Math.round(w)+"m":w>1&&T<=1?w.toFixed(Math.ceil(-Math.log10(T)))+"m":w<1&&T>=1/1e3?Math.round(w*1e3)+"mm":w<1&&T<1/1e3?(w*1e3).toFixed(Math.ceil(-Math.log10(T*1e3)))+"mm":""}function x(w,T=1){return _(w/1e3,T/1e3)}var M=w=>{var T;const L=(0,l.useRef)(null),[O,B]=(0,l.useState)({x:0,y:0}),{majorColor:X="rgba(0,0,0,0.2)",minorColor:$="rgba(0,0,0,0.1)",textColor:Q=(T=w.majorColor)!=null?T:"rgba(0,0,0,0.5)",width:ee,height:ae,screenSpaceCellSize:K=200,stringifyCoord:pe=(Oe,we,Le)=>`${_(Oe,Le)}, ${_(we,Le)}`}=w,me=Math.ceil(ee/K)+2,be=Math.ceil(ae/K)+2;(0,l.useEffect)(()=>{if(!L.current)return;const Oe=L.current.getContext("2d");if(!Oe)return;const we=K/10**Math.floor(Math.log10(w.transform.a)),Le=w.transform.d<0?-1:1,je=K/10**Math.log10(w.transform.a)/we;function Ue(kn,gn,dn){const Tn=kn;let Yt,gr,Jn;for(Yt=gn.x;Yt<=dn.x;Yt+=Tn)gr=(0,c.applyToPoint)(w.transform,{x:Yt,y:gn.y}),Jn=(0,c.applyToPoint)(w.transform,{x:Yt,y:dn.y}),Oe.beginPath(),Oe.moveTo(gr.x,gr.y),Oe.lineTo(Jn.x,Jn.y),Oe.stroke();const sn=f(gn.y,dn.y,Tn*Le);for(const lr of sn)gr=(0,c.applyToPoint)(w.transform,{x:gn.x,y:lr}),Jn=(0,c.applyToPoint)(w.transform,{x:dn.x,y:lr}),Oe.beginPath(),Oe.moveTo(gr.x,gr.y),Oe.lineTo(Jn.x,Jn.y),Oe.stroke()}function Ve(kn,gn,dn){const Tn=kn;let Yt;for(Yt=gn.x;Yt<=dn.x;Yt+=Tn)for(const gr of f(gn.y,dn.y,Tn*Le)){const Jn=(0,c.applyToPoint)(w.transform,{x:Yt,y:gr});Oe.fillStyle=Q,Oe.font="12px sans-serif",Oe.fillText(pe(Yt,gr,kn),Jn.x+2,Jn.y-2)}}Oe.clearRect(0,0,ee,ae);const ze=(0,c.applyToPoint)((0,c.inverse)(w.transform),{x:0,y:0}),lt={x:Math.floor((ze.x-we)/we)*we,y:Math.floor((ze.y-we)/we+(Le==-1?2:0))*we},it={x:lt.x+we*me,y:lt.y+we*be*Le},At=we*5,Ot={x:Math.floor((ze.x-At)/At)*At,y:Math.floor((ze.y-At)/At+(Le==-1?2:0))*At},Qt={x:Ot.x+At*me,y:Ot.y+At*be*Le};Oe.globalAlpha=1,Oe.strokeStyle=X,Ue(we,lt,it),Ve(At,Ot,Qt),Oe.globalAlpha=1-je,Ue(At/10,Ot,Qt),Oe.globalAlpha=1-je,Oe.strokeStyle=$,Ue(we/10,lt,it),Oe.globalAlpha=Math.max(((1-je)*10-5)/5,0),Ve(At/10,Ot,Qt),Oe.globalAlpha=1;const Kt=(0,c.applyToPoint)(w.transform,O);Oe.font="12px sans-serif",Oe.fillStyle=Q,Oe.fillText(pe(O.x,O.y,we),Kt.x+2,Kt.y-2),Oe.strokeStyle=X,Oe.strokeRect(Kt.x-5,Kt.y-5,10,10)},[L,w.transform,O,ee,ae]);const Ae=Oe=>{if(!L.current)return;const we=K/10/10**Math.floor(Math.log10(w.transform.a)),Le=L.current.getBoundingClientRect(),Te=(0,c.applyToPoint)((0,c.inverse)(w.transform),{x:Oe.clientX-Le.left,y:Oe.clientY-Le.top}),je=v(we,Te);B(je)};return(0,u.jsx)("canvas",{onMouseUp:Oe=>{Oe.button===1&&Ae(Oe)},onDoubleClick:Ae,ref:L,width:w.width,height:w.height})};return bee}var See=Q4t();function K4t(r,e,t){const n=(t.x-e.x)**2+(t.y-e.y)**2;if(n===0)return TMe(r,e);let i=((r.x-e.x)*(t.x-e.x)+(r.y-e.y)*(t.y-e.y))/n;i=Math.max(0,Math.min(1,i));const a={x:e.x+i*(t.x-e.x),y:e.y+i*(t.y-e.y)};return TMe(r,a)}function TMe(r,e){const t=r.x-e.x,n=r.y-e.y;return Math.sqrt(t*t+n*n)}function J4t(r){if(r.sheet)return r.sheet;for(var e=0;e<document.styleSheets.length;e++)if(document.styleSheets[e].ownerNode===r)return document.styleSheets[e]}function eEt(r){var e=document.createElement("style");return e.setAttribute("data-emotion",r.key),r.nonce!==void 0&&e.setAttribute("nonce",r.nonce),e.appendChild(document.createTextNode("")),e.setAttribute("data-s",""),e}var tEt=function(){function r(t){var n=this;this._insertTag=function(i){var a;n.tags.length===0?n.insertionPoint?a=n.insertionPoint.nextSibling:n.prepend?a=n.container.firstChild:a=n.before:a=n.tags[n.tags.length-1].nextSibling,n.container.insertBefore(i,a),n.tags.push(i)},this.isSpeedy=t.speedy===void 0?!0:t.speedy,this.tags=[],this.ctr=0,this.nonce=t.nonce,this.key=t.key,this.container=t.container,this.prepend=t.prepend,this.insertionPoint=t.insertionPoint,this.before=null}var e=r.prototype;return e.hydrate=function(n){n.forEach(this._insertTag)},e.insert=function(n){this.ctr%(this.isSpeedy?65e3:1)===0&&this._insertTag(eEt(this));var i=this.tags[this.tags.length-1];if(this.isSpeedy){var a=J4t(i);try{a.insertRule(n,a.cssRules.length)}catch{}}else i.appendChild(document.createTextNode(n));this.ctr++},e.flush=function(){this.tags.forEach(function(n){var i;return(i=n.parentNode)==null?void 0:i.removeChild(n)}),this.tags=[],this.ctr=0},r}(),d5="-ms-",WO="-moz-",v1="-webkit-",MMe="comm",Eee="rule",wee="decl",nEt="@import",CMe="@keyframes",rEt="@layer",iEt=Math.abs,YO=String.fromCharCode,aEt=Object.assign;function oEt(r,e){return F2(r,0)^45?(((e<<2^F2(r,0))<<2^F2(r,1))<<2^F2(r,2))<<2^F2(r,3):0}function RMe(r){return r.trim()}function sEt(r,e){return(r=e.exec(r))?r[0]:r}function y1(r,e,t){return r.replace(e,t)}function Tee(r,e){return r.indexOf(e)}function F2(r,e){return r.charCodeAt(e)|0}function b7(r,e,t){return r.slice(e,t)}function nS(r){return r.length}function Mee(r){return r.length}function XO(r,e){return e.push(r),r}function lEt(r,e){return r.map(e).join("")}var $O=1,T8=1,AMe=0,J5=0,ex=0,M8="";function ZO(r,e,t,n,i,a,o){return{value:r,root:e,parent:t,type:n,props:i,children:a,line:$O,column:T8,length:o,return:""}}function S7(r,e){return aEt(ZO("",null,null,"",null,null,0),r,{length:-r.length},e)}function cEt(){return ex}function uEt(){return ex=J5>0?F2(M8,--J5):0,T8--,ex===10&&(T8=1,$O--),ex}function b3(){return ex=J5<AMe?F2(M8,J5++):0,T8++,ex===10&&(T8=1,$O++),ex}function rS(){return F2(M8,J5)}function QO(){return J5}function E7(r,e){return b7(M8,r,e)}function w7(r){switch(r){case 0:case 9:case 10:case 13:case 32:return 5;case 33:case 43:case 44:case 47:case 62:case 64:case 126:case 59:case 123:case 125:return 4;case 58:return 3;case 34:case 39:case 40:case 91:return 2;case 41:case 93:return 1}return 0}function NMe(r){return $O=T8=1,AMe=nS(M8=r),J5=0,[]}function PMe(r){return M8="",r}function KO(r){return RMe(E7(J5-1,Cee(r===91?r+2:r===40?r+1:r)))}function fEt(r){for(;(ex=rS())&&ex<33;)b3();return w7(r)>2||w7(ex)>3?"":" "}function dEt(r,e){for(;--e&&b3()&&!(ex<48||ex>102||ex>57&&ex<65||ex>70&&ex<97););return E7(r,QO()+(e<6&&rS()==32&&b3()==32))}function Cee(r){for(;b3();)switch(ex){case r:return J5;case 34:case 39:r!==34&&r!==39&&Cee(ex);break;case 40:r===41&&Cee(r);break;case 92:b3();break}return J5}function hEt(r,e){for(;b3()&&r+ex!==57;)if(r+ex===84&&rS()===47)break;return"/*"+E7(e,J5-1)+"*"+YO(r===47?r:b3())}function pEt(r){for(;!w7(rS());)b3();return E7(r,J5)}function mEt(r){return PMe(JO("",null,null,null,[""],r=NMe(r),0,[0],r))}function JO(r,e,t,n,i,a,o,s,l){for(var c=0,u=0,f=o,v=0,_=0,x=0,M=1,w=1,T=1,L=0,O="",B=i,X=a,$=n,Q=O;w;)switch(x=L,L=b3()){case 40:if(x!=108&&F2(Q,f-1)==58){Tee(Q+=y1(KO(L),"&","&\f"),"&\f")!=-1&&(T=-1);break}case 34:case 39:case 91:Q+=KO(L);break;case 9:case 10:case 13:case 32:Q+=fEt(x);break;case 92:Q+=dEt(QO()-1,7);continue;case 47:switch(rS()){case 42:case 47:XO(vEt(hEt(b3(),QO()),e,t),l);break;default:Q+="/"}break;case 123*M:s[c++]=nS(Q)*T;case 125*M:case 59:case 0:switch(L){case 0:case 125:w=0;case 59+u:T==-1&&(Q=y1(Q,/\f/g,"")),_>0&&nS(Q)-f&&XO(_>32?LMe(Q+";",n,t,f-1):LMe(y1(Q," ","")+";",n,t,f-2),l);break;case 59:Q+=";";default:if(XO($=DMe(Q,e,t,c,u,i,s,O,B=[],X=[],f),a),L===123)if(u===0)JO(Q,e,$,$,B,a,f,s,X);else switch(v===99&&F2(Q,3)===110?100:v){case 100:case 108:case 109:case 115:JO(r,$,$,n&&XO(DMe(r,$,$,0,0,i,s,O,i,B=[],f),X),i,X,f,s,n?B:X);break;default:JO(Q,$,$,$,[""],X,0,s,X)}}c=u=_=0,M=T=1,O=Q="",f=o;break;case 58:f=1+nS(Q),_=x;default:if(M<1){if(L==123)--M;else if(L==125&&M++==0&&uEt()==125)continue}switch(Q+=YO(L),L*M){case 38:T=u>0?1:(Q+="\f",-1);break;case 44:s[c++]=(nS(Q)-1)*T,T=1;break;case 64:rS()===45&&(Q+=KO(b3())),v=rS(),u=f=nS(O=Q+=pEt(QO())),L++;break;case 45:x===45&&nS(Q)==2&&(M=0)}}return a}function DMe(r,e,t,n,i,a,o,s,l,c,u){for(var f=i-1,v=i===0?a:[""],_=Mee(v),x=0,M=0,w=0;x<n;++x)for(var T=0,L=b7(r,f+1,f=iEt(M=o[x])),O=r;T<_;++T)(O=RMe(M>0?v[T]+" "+L:y1(L,/&\f/g,v[T])))&&(l[w++]=O);return ZO(r,e,t,i===0?Eee:s,l,c,u)}function vEt(r,e,t){return ZO(r,e,t,MMe,YO(cEt()),b7(r,2,-2),0)}function LMe(r,e,t,n){return ZO(r,e,t,wee,b7(r,0,n),b7(r,n+1,-1),n)}function C8(r,e){for(var t="",n=Mee(r),i=0;i<n;i++)t+=e(r[i],i,r,e)||"";return t}function yEt(r,e,t,n){switch(r.type){case rEt:if(r.children.length)break;case nEt:case wee:return r.return=r.return||r.value;case MMe:return"";case CMe:return r.return=r.value+"{"+C8(r.children,n)+"}";case Eee:r.value=r.props.join(",")}return nS(t=C8(r.children,n))?r.return=r.value+"{"+t+"}":""}function gEt(r){var e=Mee(r);return function(t,n,i,a){for(var o="",s=0;s<e;s++)o+=r[s](t,n,i,a)||"";return o}}function _Et(r){return function(e){e.root||(e=e.return)&&r(e)}}function xEt(r){var e=Object.create(null);return function(t){return e[t]===void 0&&(e[t]=r(t)),e[t]}}var bEt=function(e,t,n){for(var i=0,a=0;i=a,a=rS(),i===38&&a===12&&(t[n]=1),!w7(a);)b3();return E7(e,J5)},SEt=function(e,t){var n=-1,i=44;do switch(w7(i)){case 0:i===38&&rS()===12&&(t[n]=1),e[n]+=bEt(J5-1,t,n);break;case 2:e[n]+=KO(i);break;case 4:if(i===44){e[++n]=rS()===58?"&\f":"",t[n]=e[n].length;break}default:e[n]+=YO(i)}while(i=b3());return e},EEt=function(e,t){return PMe(SEt(NMe(e),t))},OMe=new WeakMap,wEt=function(e){if(!(e.type!=="rule"||!e.parent||e.length<1)){for(var t=e.value,n=e.parent,i=e.column===n.column&&e.line===n.line;n.type!=="rule";)if(n=n.parent,!n)return;if(!(e.props.length===1&&t.charCodeAt(0)!==58&&!OMe.get(n))&&!i){OMe.set(e,!0);for(var a=[],o=EEt(t,a),s=n.props,l=0,c=0;l<o.length;l++)for(var u=0;u<s.length;u++,c++)e.props[c]=a[l]?o[l].replace(/&\f/g,s[u]):s[u]+" "+o[l]}}},TEt=function(e){if(e.type==="decl"){var t=e.value;t.charCodeAt(0)===108&&t.charCodeAt(2)===98&&(e.return="",e.value="")}};function UMe(r,e){switch(oEt(r,e)){case 5103:return v1+"print-"+r+r;case 5737:case 4201:case 3177:case 3433:case 1641:case 4457:case 2921:case 5572:case 6356:case 5844:case 3191:case 6645:case 3005:case 6391:case 5879:case 5623:case 6135:case 4599:case 4855:case 4215:case 6389:case 5109:case 5365:case 5621:case 3829:return v1+r+r;case 5349:case 4246:case 4810:case 6968:case 2756:return v1+r+WO+r+d5+r+r;case 6828:case 4268:return v1+r+d5+r+r;case 6165:return v1+r+d5+"flex-"+r+r;case 5187:return v1+r+y1(r,/(\w+).+(:[^]+)/,v1+"box-$1$2"+d5+"flex-$1$2")+r;case 5443:return v1+r+d5+"flex-item-"+y1(r,/flex-|-self/,"")+r;case 4675:return v1+r+d5+"flex-line-pack"+y1(r,/align-content|flex-|-self/,"")+r;case 5548:return v1+r+d5+y1(r,"shrink","negative")+r;case 5292:return v1+r+d5+y1(r,"basis","preferred-size")+r;case 6060:return v1+"box-"+y1(r,"-grow","")+v1+r+d5+y1(r,"grow","positive")+r;case 4554:return v1+y1(r,/([^-])(transform)/g,"$1"+v1+"$2")+r;case 6187:return y1(y1(y1(r,/(zoom-|grab)/,v1+"$1"),/(image-set)/,v1+"$1"),r,"")+r;case 5495:case 3959:return y1(r,/(image-set\([^]*)/,v1+"$1$`$1");case 4968:return y1(y1(r,/(.+:)(flex-)?(.*)/,v1+"box-pack:$3"+d5+"flex-pack:$3"),/s.+-b[^;]+/,"justify")+v1+r+r;case 4095:case 3583:case 4068:case 2532:return y1(r,/(.+)-inline(.+)/,v1+"$1$2")+r;case 8116:case 7059:case 5753:case 5535:case 5445:case 5701:case 4933:case 4677:case 5533:case 5789:case 5021:case 4765:if(nS(r)-1-e>6)switch(F2(r,e+1)){case 109:if(F2(r,e+4)!==45)break;case 102:return y1(r,/(.+:)(.+)-([^]+)/,"$1"+v1+"$2-$3$1"+WO+(F2(r,e+3)==108?"$3":"$2-$3"))+r;case 115:return~Tee(r,"stretch")?UMe(y1(r,"stretch","fill-available"),e)+r:r}break;case 4949:if(F2(r,e+1)!==115)break;case 6444:switch(F2(r,nS(r)-3-(~Tee(r,"!important")&&10))){case 107:return y1(r,":",":"+v1)+r;case 101:return y1(r,/(.+:)([^;!]+)(;|!.+)?/,"$1"+v1+(F2(r,14)===45?"inline-":"")+"box$3$1"+v1+"$2$3$1"+d5+"$2box$3")+r}break;case 5936:switch(F2(r,e+11)){case 114:return v1+r+d5+y1(r,/[svh]\w+-[tblr]{2}/,"tb")+r;case 108:return v1+r+d5+y1(r,/[svh]\w+-[tblr]{2}/,"tb-rl")+r;case 45:return v1+r+d5+y1(r,/[svh]\w+-[tblr]{2}/,"lr")+r}return v1+r+d5+r+r}return r}var MEt=function(e,t,n,i){if(e.length>-1&&!e.return)switch(e.type){case wee:e.return=UMe(e.value,e.length);break;case CMe:return C8([S7(e,{value:y1(e.value,"@","@"+v1)})],i);case Eee:if(e.length)return lEt(e.props,function(a){switch(sEt(a,/(::plac\w+|:read-\w+)/)){case":read-only":case":read-write":return C8([S7(e,{props:[y1(a,/:(read-\w+)/,":"+WO+"$1")]})],i);case"::placeholder":return C8([S7(e,{props:[y1(a,/:(plac\w+)/,":"+v1+"input-$1")]}),S7(e,{props:[y1(a,/:(plac\w+)/,":"+WO+"$1")]}),S7(e,{props:[y1(a,/:(plac\w+)/,d5+"input-$1")]})],i)}return""})}},CEt=[MEt],REt=function(e){var t=e.key;if(t==="css"){var n=document.querySelectorAll("style[data-emotion]:not([data-s])");Array.prototype.forEach.call(n,function(M){var w=M.getAttribute("data-emotion");w.indexOf(" ")!==-1&&(document.head.appendChild(M),M.setAttribute("data-s",""))})}var i=e.stylisPlugins||CEt,a={},o,s=[];o=e.container||document.head,Array.prototype.forEach.call(document.querySelectorAll('style[data-emotion^="'+t+' "]'),function(M){for(var w=M.getAttribute("data-emotion").split(" "),T=1;T<w.length;T++)a[w[T]]=!0;s.push(M)});var l,c=[wEt,TEt];{var u,f=[yEt,_Et(function(M){u.insert(M)})],v=gEt(c.concat(i,f)),_=function(w){return C8(mEt(w),v)};l=function(w,T,L,O){u=L,_(w?w+"{"+T.styles+"}":T.styles),O&&(x.inserted[T.name]=!0)}}var x={key:t,sheet:new tEt({key:t,container:o,nonce:e.nonce,speedy:e.speedy,prepend:e.prepend,insertionPoint:e.insertionPoint}),nonce:e.nonce,inserted:a,registered:{},insert:l};return x.sheet.hydrate(s),x};function AEt(r){for(var e=0,t,n=0,i=r.length;i>=4;++n,i-=4)t=r.charCodeAt(n)&255|(r.charCodeAt(++n)&255)<<8|(r.charCodeAt(++n)&255)<<16|(r.charCodeAt(++n)&255)<<24,t=(t&65535)*1540483477+((t>>>16)*59797<<16),t^=t>>>24,e=(t&65535)*1540483477+((t>>>16)*59797<<16)^(e&65535)*1540483477+((e>>>16)*59797<<16);switch(i){case 3:e^=(r.charCodeAt(n+2)&255)<<16;case 2:e^=(r.charCodeAt(n+1)&255)<<8;case 1:e^=r.charCodeAt(n)&255,e=(e&65535)*1540483477+((e>>>16)*59797<<16)}return e^=e>>>13,e=(e&65535)*1540483477+((e>>>16)*59797<<16),((e^e>>>15)>>>0).toString(36)}var NEt={animationIterationCount:1,aspectRatio:1,borderImageOutset:1,borderImageSlice:1,borderImageWidth:1,boxFlex:1,boxFlexGroup:1,boxOrdinalGroup:1,columnCount:1,columns:1,flex:1,flexGrow:1,flexPositive:1,flexShrink:1,flexNegative:1,flexOrder:1,gridRow:1,gridRowEnd:1,gridRowSpan:1,gridRowStart:1,gridColumn:1,gridColumnEnd:1,gridColumnSpan:1,gridColumnStart:1,msGridRow:1,msGridRowSpan:1,msGridColumn:1,msGridColumnSpan:1,fontWeight:1,lineHeight:1,opacity:1,order:1,orphans:1,scale:1,tabSize:1,widows:1,zIndex:1,zoom:1,WebkitLineClamp:1,fillOpacity:1,floodOpacity:1,stopOpacity:1,strokeDasharray:1,strokeDashoffset:1,strokeMiterlimit:1,strokeOpacity:1,strokeWidth:1},PEt=/[A-Z]|^ms/g,DEt=/_EMO_([^_]+?)_([^]*?)_EMO_/g,zMe=function(e){return e.charCodeAt(1)===45},IMe=function(e){return e!=null&&typeof e!="boolean"},Ree=xEt(function(r){return zMe(r)?r:r.replace(PEt,"-$&").toLowerCase()}),kMe=function(e,t){switch(e){case"animation":case"animationName":if(typeof t=="string")return t.replace(DEt,function(n,i,a){return q4={name:i,styles:a,next:q4},i})}return NEt[e]!==1&&!zMe(e)&&typeof t=="number"&&t!==0?t+"px":t};function eU(r,e,t){if(t==null)return"";var n=t;if(n.__emotion_styles!==void 0)return n;switch(typeof t){case"boolean":return"";case"object":{var i=t;if(i.anim===1)return q4={name:i.name,styles:i.styles,next:q4},i.name;var a=t;if(a.styles!==void 0){var o=a.next;if(o!==void 0)for(;o!==void 0;)q4={name:o.name,styles:o.styles,next:q4},o=o.next;var s=a.styles+";";return s}return LEt(r,e,t)}}var l=t;if(e==null)return l;var c=e[l];return c!==void 0?c:l}function LEt(r,e,t){var n="";if(Array.isArray(t))for(var i=0;i<t.length;i++)n+=eU(r,e,t[i])+";";else for(var a in t){var o=t[a];if(typeof o!="object"){var s=o;e!=null&&e[s]!==void 0?n+=a+"{"+e[s]+"}":IMe(s)&&(n+=Ree(a)+":"+kMe(a,s)+";")}else if(Array.isArray(o)&&typeof o[0]=="string"&&(e==null||e[o[0]]===void 0))for(var l=0;l<o.length;l++)IMe(o[l])&&(n+=Ree(a)+":"+kMe(a,o[l])+";");else{var c=eU(r,e,o);switch(a){case"animation":case"animationName":{n+=Ree(a)+":"+c+";";break}default:n+=a+"{"+c+"}"}}}return n}var FMe=/label:\s*([^\s;{]+)\s*(;|$)/g,q4;function Aee(r,e,t){if(r.length===1&&typeof r[0]=="object"&&r[0]!==null&&r[0].styles!==void 0)return r[0];var n=!0,i="";q4=void 0;var a=r[0];if(a==null||a.raw===void 0)n=!1,i+=eU(t,e,a);else{var o=a;i+=o[0]}for(var s=1;s<r.length;s++)if(i+=eU(t,e,r[s]),n){var l=a;i+=l[s]}FMe.lastIndex=0;for(var c="",u;(u=FMe.exec(i))!==null;)c+="-"+u[1];var f=AEt(i)+c;return{name:f,styles:i,next:q4}}function BMe(r,e,t){var n="";return t.split(" ").forEach(function(i){r[i]!==void 0?e.push(r[i]+";"):i&&(n+=i+" ")}),n}var OEt=function(e,t,n){var i=e.key+"-"+t.name;e.registered[i]===void 0&&(e.registered[i]=t.styles)},UEt=function(e,t,n){OEt(e,t);var i=e.key+"-"+t.name;if(e.inserted[t.name]===void 0){var a=t;do e.insert(t===a?"."+i:"",a,e.sheet,!0),a=a.next;while(a!==void 0)}};function HMe(r,e){if(r.inserted[e.name]===void 0)return r.insert("",e,r.sheet,!0)}function jMe(r,e,t){var n=[],i=BMe(r,n,t);return n.length<2?t:i+e(n)}var zEt=function(e){var t=REt(e);t.sheet.speedy=function(s){this.isSpeedy=s},t.compat=!0;var n=function(){for(var l=arguments.length,c=new Array(l),u=0;u<l;u++)c[u]=arguments[u];var f=Aee(c,t.registered,void 0);return UEt(t,f),t.key+"-"+f.name},i=function(){for(var l=arguments.length,c=new Array(l),u=0;u<l;u++)c[u]=arguments[u];var f=Aee(c,t.registered),v="animation-"+f.name;return HMe(t,{name:f.name,styles:"@keyframes "+v+"{"+f.styles+"}"}),v},a=function(){for(var l=arguments.length,c=new Array(l),u=0;u<l;u++)c[u]=arguments[u];var f=Aee(c,t.registered);HMe(t,f)},o=function(){for(var l=arguments.length,c=new Array(l),u=0;u<l;u++)c[u]=arguments[u];return jMe(t.registered,n,IEt(c))};return{css:n,cx:o,injectGlobal:a,keyframes:i,hydrate:function(l){l.forEach(function(c){t.inserted[c]=!0})},flush:function(){t.registered={},t.inserted={},t.sheet.flush()},sheet:t.sheet,cache:t,getRegisteredStyles:BMe.bind(null,t.registered),merge:jMe.bind(null,t.registered,n)}},IEt=function r(e){for(var t="",n=0;n<e.length;n++){var i=e[n];if(i!=null){var a=void 0;switch(typeof i){case"boolean":break;case"object":{if(Array.isArray(i))a=r(i);else{a="";for(var o in i)i[o]&&o&&(a&&(a+=" "),a+=o)}break}default:a=i}a&&(t&&(t+=" "),t+=a)}}return t},kEt=zEt({key:"css"}),R8=kEt.css;function FEt(r){const e=new Map;let t=0;function n(i){for(const[,o]of e)if(o.has(i))return o;const a=new Set;return e.set(`connectivity_net${t++}`,a),a}for(const i of r){let a=null;for(const o of i){if(!a)a=n(o);else if(!a.has(o)){const s=n(o);if(s!==a){for(const l of s)a.add(l);e.delete(Array.from(e.entries()).find(([,l])=>l===s)[0])}}a.add(o)}}return Object.fromEntries(Array.from(e.entries()).map(([i,a])=>[i,Array.from(a)]))}var BEt=class{constructor(r){rn(this,"netMap");rn(this,"idToNetMap");this.netMap=r,this.idToNetMap={};for(const[e,t]of Object.entries(r))for(const n of t)this.idToNetMap[n]=e}addConnections(r){for(const e of r){const t=new Set;for(const i of e){const a=this.idToNetMap[i];a&&t.add(a)}let n;if(t.size===0)n=`connectivity_net${Object.keys(this.netMap).length}`,this.netMap[n]=[];else if(t.size===1)n=t.values().next().value??`connectivity_net${Object.keys(this.netMap).length}`;else{n=t.values().next().value??`connectivity_net${Object.keys(this.netMap).length}`;for(const i of t)if(i!==n){this.netMap[n].push(...this.netMap[i]),this.netMap[i]=this.netMap[n];for(const a of this.netMap[n])this.idToNetMap[a]=n}}for(const i of e)this.netMap[n].includes(i)||this.netMap[n].push(i),this.idToNetMap[i]=n}}getIdsConnectedToNet(r){return this.netMap[r]||[]}getNetConnectedToId(r){return this.idToNetMap[r]}areIdsConnected(r,e){if(r===e)return!0;const t=this.getNetConnectedToId(r);if(!t)return!1;const n=this.getNetConnectedToId(e);return n?t===n||n===r||n===r:!1}areAllIdsConnected(r){const e=this.getNetConnectedToId(r[0]);for(const t of r){const n=this.getNetConnectedToId(t);if(n===void 0||n!==e)return!1}return!0}},VMe=r=>{const e=[];for(const n of r)if(n.type==="source_trace")e.push([n.source_trace_id,...n.connected_source_port_ids??[],...n.connected_source_net_ids??[]].filter(Boolean));else if(n.type==="pcb_port"){const{pcb_port_id:i,source_port_id:a}=n;a&&i&&e.push([a,i])}else if(n.type==="pcb_smtpad"){const{pcb_smtpad_id:i,pcb_port_id:a}=n;a&&i&&e.push([i,a])}else if(n.type==="pcb_plated_hole"){const{pcb_plated_hole_id:i,pcb_port_id:a}=n;a&&i&&e.push([i,a])}else if(n.type==="pcb_trace"){const{pcb_trace_id:i,source_trace_id:a}=n;a&&i&&e.push([i,a])}const t=FEt(e);return new BEt(t)};/*!
13017
13017
  * Determine if an object is a Buffer
13018
13018
  *
@@ -13355,7 +13355,7 @@ ${n.slice(0,2e3)}
13355
13355
  50% { opacity: 0.2; }
13356
13356
  100% { opacity: 0.6; }
13357
13357
  }
13358
- `,i.appendChild(O)}})}};a();const o=new MutationObserver(a);return o.observe(i,{childList:!0,subtree:!1,characterData:!1}),()=>{o.disconnect()}},[r,t,e,n])},bOt=({circuitJson:r,containerStyle:e,editEvents:t=[],onEditEvent:n,defaultEditMode:i=!1,debugGrid:a=!1,editingEnabled:o=!1,debug:s=!1})=>{s&&mOt();const[l,c]=ut.useState(i),u=ut.useRef(null),{ref:f,cancelDrag:v,transform:_}=jNe({onSetTransform($){u.current&&(u.current.style.transform=pE($))}}),{containerWidth:x,containerHeight:M}=hOt(f),w=ut.useMemo(()=>!x||!M?"":Kre(r,{width:x,height:M||720,grid:a?{cellSize:1,labelCells:!0}:void 0}),[r,x,M]),T=ut.useMemo(()=>{var Q;if(!w)return K_();const $=(Q=w.match(/data-real-to-screen-transform="([^"]+)"/))==null?void 0:Q[1];try{return Dk($)}catch(ee){return console.error(ee),K_()}},[w]),{handleMouseDown:L,isDragging:O,activeEditEvent:B}=gOt({onEditEvent:n,cancelDrag:v,realToSvgProjection:T,svgToScreenProjection:_,circuitJson:r,editEvents:t,enabled:l});_Ot({svgDivRef:u,editEvents:t,realToSvgProjection:T,svgToScreenProjection:_,activeEditEvent:B}),xOt({svgDivRef:u,circuitJson:r,activeEditEvent:B,editEvents:t});const X=ut.useMemo(()=>tt.jsx("div",{ref:u,style:{pointerEvents:"auto",transformOrigin:"0 0"},dangerouslySetInnerHTML:{__html:w}}),[w]);return tt.jsxs("div",{ref:f,style:{position:"relative",backgroundColor:"#F5F1ED",overflow:"hidden",cursor:O?"grabbing":"grab",minHeight:"300px",...e},onMouseDown:L,children:[o&&tt.jsx(dOt,{active:l,onClick:()=>c(!l)}),X]})},SOt=r=>{const[e,t]=ut.useState(0),[n,i]=ut.useState(0);return ut.useEffect(()=>{if(!r.current)return;const a=()=>{var l;const s=(l=r.current)==null?void 0:l.getBoundingClientRect();t((s==null?void 0:s.width)||0),i((s==null?void 0:s.height)||0)};a();const o=new ResizeObserver(a);return o.observe(r.current),window.addEventListener("resize",a),()=>{o.disconnect(),window.removeEventListener("resize",a)}},[]),{containerWidth:e,containerHeight:n}};w9("assembly-viewer");var EOt=()=>{w9.enable("assembly-viewer*")},wOt=({circuitJson:r,containerStyle:e,debugGrid:t=!1,debug:n=!1})=>{n&&EOt();const i=ut.useRef(null),{ref:a}=jNe({onSetTransform(u){i.current&&(i.current.style.transform=pE(u))}}),{containerWidth:o,containerHeight:s}=SOt(a),l=ut.useMemo(()=>!o||!s?"":KLe(r,{width:o,height:s||720}),[r,o,s]);ut.useMemo(()=>{var f;if(!l)return K_();const u=(f=l.match(/data-real-to-screen-transform="([^"]+)"/))==null?void 0:f[1];try{return Dk(u)}catch(v){return console.error(v),K_()}},[l]);const c=ut.useMemo(()=>tt.jsx("div",{ref:i,style:{pointerEvents:"auto",transformOrigin:"0 0"},dangerouslySetInnerHTML:{__html:l}}),[l]);return tt.jsx("div",{ref:a,style:{position:"relative",backgroundColor:"#F5F1ED",overflow:"hidden",minHeight:"300px",...e},children:c})};const zw=({onRunClicked:r})=>tt.jsxs("div",{className:"rf-flex rf-items-center rf-gap-3 rf-bg-gray-100 rf-text-center rf-justify-center rf-py-10",children:["No circuit json loaded",r&&tt.jsxs(KS,{className:"rf-bg-blue-600 rf-hover:bg-blue-500",onClick:r,children:["Run Code",tt.jsx(CRe,{className:"rf-w-3 rf-h-3 rf-ml-2"})]})]}),qz=({text:r,onClick:e})=>tt.jsx("span",{className:"rf-cursor-pointer rf-underline rf-text-blue-600 rf-mx-2",onClick:e,children:r}),Wz=r=>{var e;return tt.jsxs("div",{className:"rf-leading-5",children:[tt.jsx("div",{className:"rf-py-2 rf-font-bold",children:r.column.name}),tt.jsx("div",{children:((e=r.field)==null?void 0:e.call(r))??tt.jsx("input",{type:"text",className:"rf-border rf-rounded rf-p-1 rf-w-full",onChange:t=>{var n;(n=r.onTextChange)==null||n.call(r,t.target.value)}})})]})},TOt=({open:r,children:e,title:t,onClose:n})=>r?tt.jsx("div",{className:"rf-fixed rf-inset-0 rf-bg-black rf-bg-opacity-50 rf-flex rf-justify-center rf-items-center rf-z-50",onClick:n,children:tt.jsxs("div",{className:"rf-bg-white rf-p-5 rf-rounded-lg rf-relative rf-w-11/12 rf-max-w-2xl",onClick:i=>{i.preventDefault(),i.stopPropagation()},children:[tt.jsx("h2",{className:"rf-mt-0 rf-text-md rf-pb-4",children:t}),tt.jsx("button",{type:"button",className:"rf-absolute rf-top-2 rf-right-4 rf-text-2xl rf-font-bold",onClick:n,children:"×"}),e]})}):null,MOt=({elements:r})=>{const[e,t]=ut.useState({open:!1}),[n,i]=ut.useReducer((u,f)=>({...u,...f}),{}),a=[...new Set(r.map(u=>u.type))],o=r.map(u=>{const f=u[`${u.type}_id`],v=Object.fromEntries(Object.entries(u).filter(([x])=>!(x===`${u.type}_id`||!x.endsWith("_id")))),_=Object.fromEntries(Object.entries(u).filter(([x])=>!x.endsWith("_id")));return{primary_id:f,other_ids:v,..._,_og_elm:u}}),s=o.map(u=>{let f="";const v=_=>{const x=Object.keys(_.other_ids).find(T=>T.startsWith("source_"));if(!x)return`.${_.name}`;const M=x.slice(0,-3),w=o.find(T=>T.type===M&&T.primary_id===_.other_ids[x]);return w?"name"in w?`${v(w)} > .${_.name}`:`#${w.primary_id} > .${_.name}`:`??? > .${_.name}`};return"name"in u&&(f=v(u)),{...u,selector_path:f}}),l=[{key:"primary_id",name:"primary_id",renderCell:u=>tt.jsxs("div",{className:"rf-flex rf-items-center",children:[tt.jsx(qz,{text:u.primary_id,onClick:()=>i({focused_id:u.primary_id,id_search:void 0,selector_search:void 0})}),tt.jsx("span",{className:"rf-flex-grow"}),tt.jsx(qz,{text:"(JSON)",onClick:()=>t({open:!0,element:u._og_elm,title:u.primary_id})})]}),renderHeaderCell:u=>tt.jsx(Wz,{column:u,onTextChange:f=>i({id_search:f}),field:n.focused_id?()=>tt.jsxs("div",{children:["Focus:"," ",tt.jsx("span",{className:"rf-underline",children:n.focused_id}),tt.jsx(qz,{text:"(unfocus)",onClick:()=>i({focused_id:void 0})})]}):void 0})},{key:"type",name:"type",renderHeaderCell:u=>tt.jsx(Wz,{column:u,field:()=>tt.jsxs("select",{onChange:f=>i({component_type_filter:f.target.value}),className:"rf-border rf-rounded rf-p-1 rf-w-full",children:[tt.jsx("option",{value:"any",children:"any"},"any"),tt.jsx("option",{value:"source",children:"source"},"source"),tt.jsx("option",{value:"source/pcb",children:"source/pcb"},"source/pcb"),tt.jsx("option",{value:"source/schematic",children:"source/schematic"},"source/schematic"),a.map(f=>tt.jsx("option",{value:f,children:f},f))]})})},{key:"name",name:"name",renderHeaderCell:u=>tt.jsx(Wz,{column:u,onTextChange:f=>i({name_search:f})})},{key:"selector_path",name:"selector_path",renderHeaderCell:u=>tt.jsx(Wz,{column:u,onTextChange:f=>i({selector_search:f})})},{key:"other_ids",name:"other_ids",renderCell:u=>tt.jsx("div",{className:"rf-space-x-2",children:Object.entries(u.other_ids).map(([f,v])=>tt.jsx(qz,{text:v,onClick:()=>i({focused_id:v})},v))})}],c=s.filter(u=>{var f,v;return n.name_search?(v=(f=u.name)==null?void 0:f.toLowerCase())==null?void 0:v.includes(n.name_search.toLowerCase()):!0}).filter(u=>{var f;return!n.component_type_filter||n.component_type_filter==="any"?!0:n.component_type_filter==="source"?u.type.startsWith("source_"):n.component_type_filter==="source/pcb"?u.type.startsWith("source_")||u.type.startsWith("pcb_"):n.component_type_filter==="source/schematic"?u.type.startsWith("source_")||u.type.startsWith("schematic_"):(f=u.type)==null?void 0:f.includes(n.component_type_filter)}).filter(u=>n.selector_search?n.selector_search.split(" ").filter(v=>v.length>0).every(v=>{var _;return(_=u.selector_path)==null?void 0:_.includes(v)}):!0).filter(u=>{var f;return n.id_search?(f=u.primary_id)==null?void 0:f.includes(n.id_search):!0}).filter(u=>!!(!n.focused_id||u.primary_id===n.focused_id||Object.values(u.other_ids).includes(n.focused_id)));return tt.jsxs("div",{className:"rf-font-mono rf-text-xs rf-bg-white",children:[tt.jsx("div",{className:"rf-overflow-x-auto",children:tt.jsxs("table",{className:"rf-table-auto rf-w-full rf-text-left",children:[tt.jsx("thead",{children:tt.jsx("tr",{children:l.map(u=>tt.jsx("th",{className:"rf-px-4 rf-py-2 rf-border-b",children:u.renderHeaderCell?u.renderHeaderCell(u):u.name},u.key))})}),tt.jsx("tbody",{children:c.map((u,f)=>tt.jsx("tr",{className:"rf-hover:bg-gray-100",children:l.map(v=>tt.jsx("td",{className:"rf-px-4 rf-py-2 rf-border-b",children:v.renderCell?v.renderCell(u):u[v.key]},v.key))},f))})]})}),tt.jsx(TOt,{open:e.open,onClose:()=>t({open:!1}),title:e.open?e.title:"",children:tt.jsx("div",{className:"rf-bg-gray-800 rf-p-3 rf-text-white rf-rounded",children:tt.jsx("pre",{className:"rf-whitespace-pre-wrap",children:e.open?JSON.stringify(e.element,null,2):""})})})]})},COt=(r,e)=>r==="jlcpcb"?tt.jsx("a",{className:"rf-underline rf-text-blue-500",target:"_blank",rel:"noreferrer",href:`https://jlcpcb.com/partdetail/${e}`,children:e}):e,ROt=({circuitJson:r})=>{const e=r.filter(n=>n.type==="source_component"),t=new Set;for(const n of e)if(n.supplier_part_numbers)for(const i of Object.keys(n.supplier_part_numbers))t.add(i);return tt.jsx("div",{className:"rf-overflow-x-auto",children:tt.jsxs("table",{className:"rf-w-full rf-text-left rf-text-sm",children:[tt.jsx("thead",{children:tt.jsxs("tr",{className:"rf-border-b",children:[tt.jsx("th",{className:"rf-p-2",children:"Name"}),Array.from(t).map(n=>tt.jsx("th",{className:"rf-p-2 rf-capitalize",children:n},n))]})}),tt.jsx("tbody",{children:e.map(n=>tt.jsxs("tr",{className:"rf-border-b",children:[tt.jsx("td",{className:"rf-p-2",children:n.name}),Array.from(t).map(i=>{var a,o;return tt.jsx("td",{className:"rf-p-2",children:COt(i,((o=(a=n.supplier_part_numbers)==null?void 0:a[i])==null?void 0:o[0])||"")},i)})]},n.source_component_id))})]})})},AOt=({containerClassName:r,...e})=>{const t=ut.useRef(null),[n,i]=ut.useState(620);return ut.useLayoutEffect(()=>{const a=()=>{if(t.current){const s=t.current.clientHeight,l=window.innerHeight;i(Math.min(Math.max(s,620),l))}};a();const o=new ResizeObserver(a);return t.current&&o.observe(t.current),window.addEventListener("resize",a),()=>{o.disconnect(),window.removeEventListener("resize",a)}},[]),tt.jsx("div",{ref:t,className:r||"rf-w-full rf-h-full",children:tt.jsx($8t,{...e,height:n})})},NOt='*,:after,:before{--tw-border-spacing-x:0;--tw-border-spacing-y:0;--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness:proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:rgba(59,130,246,.5);--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: ;--tw-contain-size: ;--tw-contain-layout: ;--tw-contain-paint: ;--tw-contain-style: }::backdrop{--tw-border-spacing-x:0;--tw-border-spacing-y:0;--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness:proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:rgba(59,130,246,.5);--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: ;--tw-contain-size: ;--tw-contain-layout: ;--tw-contain-paint: ;--tw-contain-style: }/*! tailwindcss v3.4.17 | MIT License | https://tailwindcss.com*/*,:after,:before{border:0 solid #e5e7eb;box-sizing:border-box}:after,:before{--tw-content:""}:host,html{line-height:1.5;-webkit-text-size-adjust:100%;font-family:ui-sans-serif,system-ui,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji;font-feature-settings:normal;font-variation-settings:normal;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-tap-highlight-color:transparent}body{line-height:inherit;margin:0}hr{border-top-width:1px;color:inherit;height:0}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,pre,samp{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace;font-feature-settings:normal;font-size:1em;font-variation-settings:normal}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}table{border-collapse:collapse;border-color:inherit;text-indent:0}button,input,optgroup,select,textarea{color:inherit;font-family:inherit;font-feature-settings:inherit;font-size:100%;font-variation-settings:inherit;font-weight:inherit;letter-spacing:inherit;line-height:inherit;margin:0;padding:0}button,select{text-transform:none}button,input:where([type=button]),input:where([type=reset]),input:where([type=submit]){-webkit-appearance:button;background-color:transparent;background-image:none}:-moz-focusring{outline:auto}:-moz-ui-invalid{box-shadow:none}progress{vertical-align:baseline}::-webkit-inner-spin-button,::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item}blockquote,dd,dl,figure,h1,h2,h3,h4,h5,h6,hr,p,pre{margin:0}fieldset{margin:0}fieldset,legend{padding:0}menu,ol,ul{list-style:none;margin:0;padding:0}dialog{padding:0}textarea{resize:vertical}input::-moz-placeholder,textarea::-moz-placeholder{color:#9ca3af;opacity:1}input::placeholder,textarea::placeholder{color:#9ca3af;opacity:1}[role=button],button{cursor:pointer}:disabled{cursor:default}audio,canvas,embed,iframe,img,object,svg,video{display:block;vertical-align:middle}img,video{height:auto;max-width:100%}[hidden]:where(:not([hidden=until-found])){display:none}:root{--radius:0.5rem}.rf-pointer-events-none{pointer-events:none}.rf-invisible{visibility:hidden}.rf-fixed{position:fixed}.rf-absolute{position:absolute}.rf-relative{position:relative}.rf-inset-0{inset:0}.-rf-left-2{left:-.5rem}.-rf-right-10{right:-2.5rem}.-rf-right-2{right:-.5rem}.-rf-right-4{right:-1rem}.-rf-right-6{right:-1.5rem}.-rf-right-7{right:-1.75rem}.-rf-right-8{right:-2rem}.-rf-right-9{right:-2.25rem}.rf-bottom-full{bottom:100%}.rf-left-0{left:0}.rf-left-1{left:.25rem}.rf-left-1\\/2{left:50%}.rf-left-2{left:.5rem}.rf-left-\\[50\\%\\]{left:50%}.rf-right-0{right:0}.rf-right-4{right:1rem}.rf-right-\\[4px\\]{right:4px}.rf-top-0{top:0}.rf-top-1{top:.25rem}.rf-top-2{top:.5rem}.rf-top-\\[50\\%\\]{top:50%}.rf-top-\\[6px\\]{top:6px}.rf-z-50{z-index:50}.rf-z-\\[100\\]{z-index:100}.rf--mx-1{margin-left:-.25rem;margin-right:-.25rem}.rf-mx-1{margin-left:.25rem;margin-right:.25rem}.rf-mx-2{margin-left:.5rem;margin-right:.5rem}.rf-my-1{margin-bottom:.25rem;margin-top:.25rem}.rf-my-auto{margin-bottom:auto;margin-top:auto}.rf-mb-2{margin-bottom:.5rem}.rf-mb-3{margin-bottom:.75rem}.rf-mb-4{margin-bottom:1rem}.rf-ml-1{margin-left:.25rem}.rf-ml-2{margin-left:.5rem}.rf-ml-auto{margin-left:auto}.rf-mr-1{margin-right:.25rem}.rf-mr-2{margin-right:.5rem}.rf-mt-0{margin-top:0}.rf-mt-1{margin-top:.25rem}.rf-mt-2{margin-top:.5rem}.rf-mt-4{margin-top:1rem}.rf-inline{display:inline}.rf-flex{display:flex}.rf-inline-flex{display:inline-flex}.rf-grid{display:grid}.rf-size-4{height:1rem;width:1rem}.\\!rf-h-2{height:.5rem!important}.\\!rf-h-2\\.5{height:.625rem!important}.\\!rf-h-3{height:.75rem!important}.\\!rf-h-full{height:100%!important}.rf-h-1{height:.25rem}.rf-h-10{height:2.5rem}.rf-h-2{height:.5rem}.rf-h-3{height:.75rem}.rf-h-3\\.5{height:.875rem}.rf-h-4{height:1rem}.rf-h-60{height:15rem}.rf-h-8{height:2rem}.rf-h-9{height:2.25rem}.rf-h-\\[620px\\]{height:620px}.rf-h-\\[calc\\(100vh-96px\\)\\]{height:calc(100vh - 96px)}.rf-h-fit{height:-moz-fit-content;height:fit-content}.rf-h-full{height:100%}.rf-h-px{height:1px}.rf-max-h-\\[500px\\]{max-height:500px}.rf-min-h-\\[620px\\]{min-height:620px}.rf-min-h-\\[calc\\(100vh-240px\\)\\]{min-height:calc(100vh - 240px)}.\\!rf-w-2{width:.5rem!important}.\\!rf-w-2\\.5{width:.625rem!important}.rf-w-1{width:.25rem}.rf-w-11{width:2.75rem}.rf-w-11\\/12{width:91.666667%}.rf-w-16{width:4rem}.rf-w-2{width:.5rem}.rf-w-3{width:.75rem}.rf-w-3\\.5{width:.875rem}.rf-w-32{width:8rem}.rf-w-4{width:1rem}.rf-w-64{width:16rem}.rf-w-72{width:18rem}.rf-w-8{width:2rem}.rf-w-9{width:2.25rem}.rf-w-96{width:24rem}.rf-w-fit{width:-moz-fit-content;width:fit-content}.rf-w-full{width:100%}.rf-min-w-10{min-width:2.5rem}.rf-min-w-16{min-width:4rem}.rf-min-w-\\[8rem\\]{min-width:8rem}.rf-max-w-2xl{max-width:42rem}.rf-max-w-lg{max-width:32rem}.rf-max-w-xl{max-width:36rem}.rf-shrink-0{flex-shrink:0}.rf-flex-grow{flex-grow:1}.rf-table-auto{table-layout:auto}.-rf-translate-x-1{--tw-translate-x:-0.25rem}.-rf-translate-x-1,.-rf-translate-x-1\\/2{transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.-rf-translate-x-1\\/2{--tw-translate-x:-50%}.-rf-translate-y-1{--tw-translate-y:-0.25rem}.-rf-translate-y-1,.rf--translate-x-1{transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.rf--translate-x-1{--tw-translate-x:-0.25rem}.rf-translate-x-\\[-50\\%\\]{--tw-translate-x:-50%}.rf-translate-x-\\[-50\\%\\],.rf-translate-y-\\[-50\\%\\]{transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.rf-translate-y-\\[-50\\%\\]{--tw-translate-y:-50%}.rf-transform{transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}@keyframes rf-spin{to{transform:rotate(1turn)}}.rf-animate-spin{animation:rf-spin 1s linear infinite}.rf-cursor-default{cursor:default}.rf-cursor-pointer{cursor:pointer}.rf-select-none{-webkit-user-select:none;-moz-user-select:none;user-select:none}.rf-flex-col{flex-direction:column}.rf-flex-col-reverse{flex-direction:column-reverse}.rf-place-items-center{place-items:center}.rf-items-center{align-items:center}.rf-justify-end{justify-content:flex-end}.rf-justify-center{justify-content:center}.rf-justify-between{justify-content:space-between}.rf-gap-0{gap:0}.rf-gap-1{gap:.25rem}.rf-gap-2{gap:.5rem}.rf-gap-3{gap:.75rem}.rf-gap-4{gap:1rem}.rf-gap-5{gap:1.25rem}.rf-gap-6{gap:1.5rem}.rf-space-x-2>:not([hidden])~:not([hidden]){--tw-space-x-reverse:0;margin-left:calc(.5rem*(1 - var(--tw-space-x-reverse)));margin-right:calc(.5rem*var(--tw-space-x-reverse))}.rf-space-y-2>:not([hidden])~:not([hidden]){--tw-space-y-reverse:0;margin-bottom:calc(.5rem*var(--tw-space-y-reverse));margin-top:calc(.5rem*(1 - var(--tw-space-y-reverse)))}.rf-overflow-auto{overflow:auto}.rf-overflow-hidden{overflow:hidden}.rf-overflow-visible{overflow:visible}.rf-overflow-x-auto{overflow-x:auto}.rf-overflow-y-auto{overflow-y:auto}.rf-overflow-x-hidden{overflow-x:hidden}.rf-truncate{overflow:hidden;text-overflow:ellipsis}.rf-truncate,.rf-whitespace-nowrap{white-space:nowrap}.rf-whitespace-pre-wrap{white-space:pre-wrap}.rf-break-words{overflow-wrap:break-word}.rf-rounded{border-radius:.25rem}.rf-rounded-full{border-radius:9999px}.rf-rounded-lg{border-radius:var(--radius)}.rf-rounded-md{border-radius:calc(var(--radius) - 2px)}.rf-rounded-sm{border-radius:calc(var(--radius) - 4px)}.rf-border{border-width:1px}.rf-border-b{border-bottom-width:1px}.rf-border-green-200{--tw-border-opacity:1;border-color:rgb(187 247 208/var(--tw-border-opacity,1))}.rf-border-neutral-200{--tw-border-opacity:1;border-color:rgb(229 229 229/var(--tw-border-opacity,1))}.rf-border-red-200{--tw-border-opacity:1;border-color:rgb(254 202 202/var(--tw-border-opacity,1))}.rf-border-zinc-200{--tw-border-opacity:1;border-color:rgb(228 228 231/var(--tw-border-opacity,1))}.rf-bg-black{--tw-bg-opacity:1;background-color:rgb(0 0 0/var(--tw-bg-opacity,1))}.rf-bg-black\\/80{background-color:rgba(0,0,0,.8)}.rf-bg-blue-500{--tw-bg-opacity:1;background-color:rgb(59 130 246/var(--tw-bg-opacity,1))}.rf-bg-blue-600{--tw-bg-opacity:1;background-color:rgb(37 99 235/var(--tw-bg-opacity,1))}.rf-bg-blue-600\\/70{background-color:rgba(37,99,235,.7)}.rf-bg-gray-100{--tw-bg-opacity:1;background-color:rgb(243 244 246/var(--tw-bg-opacity,1))}.rf-bg-gray-500{--tw-bg-opacity:1;background-color:rgb(107 114 128/var(--tw-bg-opacity,1))}.rf-bg-gray-800{--tw-bg-opacity:1;background-color:rgb(31 41 55/var(--tw-bg-opacity,1))}.rf-bg-gray-900{--tw-bg-opacity:1;background-color:rgb(17 24 39/var(--tw-bg-opacity,1))}.rf-bg-green-50{--tw-bg-opacity:1;background-color:rgb(240 253 244/var(--tw-bg-opacity,1))}.rf-bg-neutral-100{--tw-bg-opacity:1;background-color:rgb(245 245 245/var(--tw-bg-opacity,1))}.rf-bg-neutral-50{--tw-bg-opacity:1;background-color:rgb(250 250 250/var(--tw-bg-opacity,1))}.rf-bg-neutral-800{--tw-bg-opacity:1;background-color:rgb(38 38 38/var(--tw-bg-opacity,1))}.rf-bg-neutral-900{--tw-bg-opacity:1;background-color:rgb(23 23 23/var(--tw-bg-opacity,1))}.rf-bg-orange-400{--tw-bg-opacity:1;background-color:rgb(251 146 60/var(--tw-bg-opacity,1))}.rf-bg-red-100{--tw-bg-opacity:1;background-color:rgb(254 226 226/var(--tw-bg-opacity,1))}.rf-bg-red-50{--tw-bg-opacity:1;background-color:rgb(254 242 242/var(--tw-bg-opacity,1))}.rf-bg-red-500{--tw-bg-opacity:1;background-color:rgb(239 68 68/var(--tw-bg-opacity,1))}.rf-bg-red-900{--tw-bg-opacity:1;background-color:rgb(127 29 29/var(--tw-bg-opacity,1))}.rf-bg-white{--tw-bg-opacity:1;background-color:rgb(255 255 255/var(--tw-bg-opacity,1))}.rf-bg-zinc-100{--tw-bg-opacity:1;background-color:rgb(244 244 245/var(--tw-bg-opacity,1))}.rf-bg-zinc-200{--tw-bg-opacity:1;background-color:rgb(228 228 231/var(--tw-bg-opacity,1))}.rf-bg-zinc-50{--tw-bg-opacity:1;background-color:rgb(250 250 250/var(--tw-bg-opacity,1))}.rf-bg-zinc-800{--tw-bg-opacity:1;background-color:rgb(39 39 42/var(--tw-bg-opacity,1))}.rf-bg-zinc-900{--tw-bg-opacity:1;background-color:rgb(24 24 27/var(--tw-bg-opacity,1))}.rf-bg-opacity-50{--tw-bg-opacity:0.5}.rf-fill-current{fill:currentColor}.rf-p-0{padding:0}.rf-p-0\\.5{padding:.125rem}.rf-p-1{padding:.25rem}.rf-p-2{padding:.5rem}.rf-p-3{padding:.75rem}.rf-p-4{padding:1rem}.rf-p-5{padding:1.25rem}.rf-p-6{padding:1.5rem}.rf-px-1{padding-left:.25rem;padding-right:.25rem}.rf-px-1\\.5{padding-left:.375rem;padding-right:.375rem}.rf-px-2{padding-left:.5rem;padding-right:.5rem}.rf-px-3{padding-left:.75rem;padding-right:.75rem}.rf-px-4{padding-left:1rem;padding-right:1rem}.rf-px-8{padding-left:2rem;padding-right:2rem}.rf-py-0{padding-bottom:0;padding-top:0}.rf-py-1{padding-bottom:.25rem;padding-top:.25rem}.rf-py-1\\.5{padding-bottom:.375rem;padding-top:.375rem}.rf-py-10{padding-bottom:2.5rem;padding-top:2.5rem}.rf-py-2{padding-bottom:.5rem;padding-top:.5rem}.rf-pb-0{padding-bottom:0}.rf-pb-4{padding-bottom:1rem}.rf-pl-2{padding-left:.5rem}.rf-pl-8{padding-left:2rem}.rf-pr-2{padding-right:.5rem}.rf-text-left{text-align:left}.rf-text-center{text-align:center}.rf-font-mono{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace}.rf-text-2xl{font-size:1.5rem;line-height:2rem}.rf-text-\\[8px\\]{font-size:8px}.rf-text-lg{font-size:1.125rem;line-height:1.75rem}.rf-text-sm{font-size:.875rem;line-height:1.25rem}.rf-text-xs{font-size:.75rem;line-height:1rem}.rf-font-bold{font-weight:700}.rf-font-medium{font-weight:500}.rf-font-semibold{font-weight:600}.rf-capitalize{text-transform:capitalize}.rf-tabular-nums{--tw-numeric-spacing:tabular-nums;font-variant-numeric:var(--tw-ordinal) var(--tw-slashed-zero) var(--tw-numeric-figure) var(--tw-numeric-spacing) var(--tw-numeric-fraction)}.rf-leading-5{line-height:1.25rem}.rf-tracking-widest{letter-spacing:.1em}.rf-text-blue-500{--tw-text-opacity:1;color:rgb(59 130 246/var(--tw-text-opacity,1))}.rf-text-blue-600{--tw-text-opacity:1;color:rgb(37 99 235/var(--tw-text-opacity,1))}.rf-text-gray-500{--tw-text-opacity:1;color:rgb(107 114 128/var(--tw-text-opacity,1))}.rf-text-gray-600{--tw-text-opacity:1;color:rgb(75 85 99/var(--tw-text-opacity,1))}.rf-text-gray-700{--tw-text-opacity:1;color:rgb(55 65 81/var(--tw-text-opacity,1))}.rf-text-green-500{--tw-text-opacity:1;color:rgb(34 197 94/var(--tw-text-opacity,1))}.rf-text-green-700{--tw-text-opacity:1;color:rgb(21 128 61/var(--tw-text-opacity,1))}.rf-text-green-800{--tw-text-opacity:1;color:rgb(22 101 52/var(--tw-text-opacity,1))}.rf-text-neutral-50{--tw-text-opacity:1;color:rgb(250 250 250/var(--tw-text-opacity,1))}.rf-text-neutral-500{--tw-text-opacity:1;color:rgb(115 115 115/var(--tw-text-opacity,1))}.rf-text-neutral-900{--tw-text-opacity:1;color:rgb(23 23 23/var(--tw-text-opacity,1))}.rf-text-neutral-950{--tw-text-opacity:1;color:rgb(10 10 10/var(--tw-text-opacity,1))}.rf-text-red-200{--tw-text-opacity:1;color:rgb(254 202 202/var(--tw-text-opacity,1))}.rf-text-red-300{--tw-text-opacity:1;color:rgb(252 165 165/var(--tw-text-opacity,1))}.rf-text-red-400{--tw-text-opacity:1;color:rgb(248 113 113/var(--tw-text-opacity,1))}.rf-text-red-500{--tw-text-opacity:1;color:rgb(239 68 68/var(--tw-text-opacity,1))}.rf-text-red-600{--tw-text-opacity:1;color:rgb(220 38 38/var(--tw-text-opacity,1))}.rf-text-red-700{--tw-text-opacity:1;color:rgb(185 28 28/var(--tw-text-opacity,1))}.rf-text-red-800{--tw-text-opacity:1;color:rgb(153 27 27/var(--tw-text-opacity,1))}.rf-text-red-900{--tw-text-opacity:1;color:rgb(127 29 29/var(--tw-text-opacity,1))}.rf-text-white{--tw-text-opacity:1;color:rgb(255 255 255/var(--tw-text-opacity,1))}.rf-text-zinc-200{--tw-text-opacity:1;color:rgb(228 228 231/var(--tw-text-opacity,1))}.rf-text-zinc-300{--tw-text-opacity:1;color:rgb(212 212 216/var(--tw-text-opacity,1))}.rf-text-zinc-400{--tw-text-opacity:1;color:rgb(161 161 170/var(--tw-text-opacity,1))}.rf-text-zinc-50{--tw-text-opacity:1;color:rgb(250 250 250/var(--tw-text-opacity,1))}.rf-text-zinc-500{--tw-text-opacity:1;color:rgb(113 113 122/var(--tw-text-opacity,1))}.rf-text-zinc-900{--tw-text-opacity:1;color:rgb(24 24 27/var(--tw-text-opacity,1))}.rf-text-zinc-950{--tw-text-opacity:1;color:rgb(9 9 11/var(--tw-text-opacity,1))}.rf-underline{text-decoration-line:underline}.rf-underline-offset-4{text-underline-offset:4px}.rf-opacity-0{opacity:0}.rf-opacity-25{opacity:.25}.rf-opacity-30{opacity:.3}.rf-opacity-50{opacity:.5}.rf-opacity-60{opacity:.6}.rf-shadow{--tw-shadow:0 1px 3px 0 rgba(0,0,0,.1),0 1px 2px -1px rgba(0,0,0,.1);--tw-shadow-colored:0 1px 3px 0 var(--tw-shadow-color),0 1px 2px -1px var(--tw-shadow-color)}.rf-shadow,.rf-shadow-lg{box-shadow:var(--tw-ring-offset-shadow,0 0 #0000),var(--tw-ring-shadow,0 0 #0000),var(--tw-shadow)}.rf-shadow-lg{--tw-shadow:0 10px 15px -3px rgba(0,0,0,.1),0 4px 6px -4px rgba(0,0,0,.1);--tw-shadow-colored:0 10px 15px -3px var(--tw-shadow-color),0 4px 6px -4px var(--tw-shadow-color)}.rf-shadow-md{--tw-shadow:0 4px 6px -1px rgba(0,0,0,.1),0 2px 4px -2px rgba(0,0,0,.1);--tw-shadow-colored:0 4px 6px -1px var(--tw-shadow-color),0 2px 4px -2px var(--tw-shadow-color)}.rf-shadow-md,.rf-shadow-sm{box-shadow:var(--tw-ring-offset-shadow,0 0 #0000),var(--tw-ring-shadow,0 0 #0000),var(--tw-shadow)}.rf-shadow-sm{--tw-shadow:0 1px 2px 0 rgba(0,0,0,.05);--tw-shadow-colored:0 1px 2px 0 var(--tw-shadow-color)}.rf-outline-none{outline:2px solid transparent;outline-offset:2px}.rf-ring-offset-white{--tw-ring-offset-color:#fff}.rf-transition-all{transition-duration:.15s;transition-property:all;transition-timing-function:cubic-bezier(.4,0,.2,1)}.rf-transition-colors{transition-duration:.15s;transition-property:color,background-color,border-color,text-decoration-color,fill,stroke;transition-timing-function:cubic-bezier(.4,0,.2,1)}.rf-transition-opacity{transition-duration:.15s;transition-property:opacity;transition-timing-function:cubic-bezier(.4,0,.2,1)}.rf-duration-200{transition-duration:.2s}@keyframes enter{0%{opacity:var(--tw-enter-opacity,1);transform:translate3d(var(--tw-enter-translate-x,0),var(--tw-enter-translate-y,0),0) scale3d(var(--tw-enter-scale,1),var(--tw-enter-scale,1),var(--tw-enter-scale,1)) rotate(var(--tw-enter-rotate,0))}}@keyframes exit{to{opacity:var(--tw-exit-opacity,1);transform:translate3d(var(--tw-exit-translate-x,0),var(--tw-exit-translate-y,0),0) scale3d(var(--tw-exit-scale,1),var(--tw-exit-scale,1),var(--tw-exit-scale,1)) rotate(var(--tw-exit-rotate,0))}}.rf-slide-in-from-left-1{--tw-enter-translate-x:-0.25rem}.rf-slide-out-to-left-1{--tw-exit-translate-x:-0.25rem}.rf-duration-200{animation-duration:.2s}.hover\\:\\!rf-bg-transparent:hover{background-color:transparent!important}.hover\\:rf-bg-blue-700:hover{--tw-bg-opacity:1;background-color:rgb(29 78 216/var(--tw-bg-opacity,1))}.hover\\:rf-bg-red-500\\/90:hover{background-color:rgba(239,68,68,.9)}.hover\\:rf-bg-zinc-100:hover{--tw-bg-opacity:1;background-color:rgb(244 244 245/var(--tw-bg-opacity,1))}.hover\\:rf-bg-zinc-100\\/80:hover{background-color:hsla(240,5%,96%,.8)}.hover\\:rf-bg-zinc-900\\/90:hover{background-color:rgba(24,24,27,.9)}.hover\\:rf-text-red-400:hover{--tw-text-opacity:1;color:rgb(248 113 113/var(--tw-text-opacity,1))}.hover\\:rf-text-zinc-900:hover{--tw-text-opacity:1;color:rgb(24 24 27/var(--tw-text-opacity,1))}.hover\\:rf-underline:hover{text-decoration-line:underline}.focus\\:rf-bg-zinc-100:focus{--tw-bg-opacity:1;background-color:rgb(244 244 245/var(--tw-bg-opacity,1))}.focus\\:rf-text-zinc-900:focus{--tw-text-opacity:1;color:rgb(24 24 27/var(--tw-text-opacity,1))}.focus-visible\\:rf-outline-none:focus-visible{outline:2px solid transparent;outline-offset:2px}.focus-visible\\:rf-ring-1:focus-visible{--tw-ring-offset-shadow:var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow:var(--tw-ring-inset) 0 0 0 calc(1px + var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow,0 0 #0000)}.focus-visible\\:rf-ring-2:focus-visible{--tw-ring-offset-shadow:var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow:var(--tw-ring-inset) 0 0 0 calc(2px + var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow,0 0 #0000)}.focus-visible\\:rf-ring-zinc-950:focus-visible{--tw-ring-opacity:1;--tw-ring-color:rgb(9 9 11/var(--tw-ring-opacity,1))}.focus-visible\\:rf-ring-offset-2:focus-visible{--tw-ring-offset-width:2px}.disabled\\:rf-pointer-events-none:disabled{pointer-events:none}.disabled\\:rf-bg-blue-600\\/60:disabled{background-color:rgba(37,99,235,.6)}.disabled\\:rf-opacity-50:disabled{opacity:.5}.rf-group\\/bar:hover .group-hover\\/bar\\:rf-opacity-100{opacity:1}.data-\\[disabled\\]\\:rf-pointer-events-none[data-disabled]{pointer-events:none}.data-\\[state\\=active\\]\\:rf-bg-white[data-state=active]{--tw-bg-opacity:1;background-color:rgb(255 255 255/var(--tw-bg-opacity,1))}.data-\\[state\\=open\\]\\:rf-bg-zinc-100[data-state=open]{--tw-bg-opacity:1;background-color:rgb(244 244 245/var(--tw-bg-opacity,1))}.data-\\[state\\=active\\]\\:rf-text-zinc-950[data-state=active]{--tw-text-opacity:1;color:rgb(9 9 11/var(--tw-text-opacity,1))}.data-\\[disabled\\]\\:rf-opacity-50[data-disabled]{opacity:.5}.data-\\[state\\=active\\]\\:rf-shadow[data-state=active]{--tw-shadow:0 1px 3px 0 rgba(0,0,0,.1),0 1px 2px -1px rgba(0,0,0,.1);--tw-shadow-colored:0 1px 3px 0 var(--tw-shadow-color),0 1px 2px -1px var(--tw-shadow-color);box-shadow:var(--tw-ring-offset-shadow,0 0 #0000),var(--tw-ring-shadow,0 0 #0000),var(--tw-shadow)}.data-\\[state\\=open\\]\\:rf-animate-in[data-state=open]{animation-duration:.15s;animation-name:enter;--tw-enter-opacity:initial;--tw-enter-scale:initial;--tw-enter-rotate:initial;--tw-enter-translate-x:initial;--tw-enter-translate-y:initial}.data-\\[state\\=closed\\]\\:rf-animate-out[data-state=closed]{animation-duration:.15s;animation-name:exit;--tw-exit-opacity:initial;--tw-exit-scale:initial;--tw-exit-rotate:initial;--tw-exit-translate-x:initial;--tw-exit-translate-y:initial}.data-\\[state\\=closed\\]\\:rf-fade-out-0[data-state=closed]{--tw-exit-opacity:0}.data-\\[state\\=open\\]\\:rf-fade-in-0[data-state=open]{--tw-enter-opacity:0}.data-\\[state\\=closed\\]\\:rf-zoom-out-95[data-state=closed]{--tw-exit-scale:.95}.data-\\[state\\=open\\]\\:rf-zoom-in-95[data-state=open]{--tw-enter-scale:.95}.data-\\[side\\=bottom\\]\\:rf-slide-in-from-top-2[data-side=bottom]{--tw-enter-translate-y:-0.5rem}.data-\\[side\\=left\\]\\:rf-slide-in-from-right-2[data-side=left]{--tw-enter-translate-x:0.5rem}.data-\\[side\\=right\\]\\:rf-slide-in-from-left-2[data-side=right]{--tw-enter-translate-x:-0.5rem}.data-\\[side\\=top\\]\\:rf-slide-in-from-bottom-2[data-side=top]{--tw-enter-translate-y:0.5rem}.data-\\[state\\=closed\\]\\:rf-slide-out-to-left-1\\/2[data-state=closed]{--tw-exit-translate-x:-50%}.data-\\[state\\=closed\\]\\:rf-slide-out-to-top-\\[48\\%\\][data-state=closed]{--tw-exit-translate-y:-48%}.data-\\[state\\=open\\]\\:rf-slide-in-from-left-1\\/2[data-state=open]{--tw-enter-translate-x:-50%}.data-\\[state\\=open\\]\\:rf-slide-in-from-top-\\[48\\%\\][data-state=open]{--tw-enter-translate-y:-48%}.dark\\:rf-border-zinc-800:is(.rf-dark *){--tw-border-opacity:1;border-color:rgb(39 39 42/var(--tw-border-opacity,1))}.dark\\:rf-bg-red-900:is(.rf-dark *){--tw-bg-opacity:1;background-color:rgb(127 29 29/var(--tw-bg-opacity,1))}.dark\\:rf-bg-zinc-50:is(.rf-dark *){--tw-bg-opacity:1;background-color:rgb(250 250 250/var(--tw-bg-opacity,1))}.dark\\:rf-bg-zinc-800:is(.rf-dark *){--tw-bg-opacity:1;background-color:rgb(39 39 42/var(--tw-bg-opacity,1))}.dark\\:rf-bg-zinc-950:is(.rf-dark *){--tw-bg-opacity:1;background-color:rgb(9 9 11/var(--tw-bg-opacity,1))}.dark\\:rf-text-zinc-400:is(.rf-dark *){--tw-text-opacity:1;color:rgb(161 161 170/var(--tw-text-opacity,1))}.dark\\:rf-text-zinc-50:is(.rf-dark *){--tw-text-opacity:1;color:rgb(250 250 250/var(--tw-text-opacity,1))}.dark\\:rf-text-zinc-900:is(.rf-dark *){--tw-text-opacity:1;color:rgb(24 24 27/var(--tw-text-opacity,1))}.dark\\:rf-ring-offset-zinc-950:is(.rf-dark *){--tw-ring-offset-color:#09090b}.dark\\:hover\\:rf-bg-red-900\\/90:hover:is(.rf-dark *){background-color:rgba(127,29,29,.9)}.dark\\:hover\\:rf-bg-zinc-50\\/90:hover:is(.rf-dark *){background-color:hsla(0,0%,98%,.9)}.dark\\:hover\\:rf-bg-zinc-800:hover:is(.rf-dark *){--tw-bg-opacity:1;background-color:rgb(39 39 42/var(--tw-bg-opacity,1))}.dark\\:hover\\:rf-bg-zinc-800\\/80:hover:is(.rf-dark *){background-color:rgba(39,39,42,.8)}.dark\\:hover\\:rf-text-zinc-50:hover:is(.rf-dark *){--tw-text-opacity:1;color:rgb(250 250 250/var(--tw-text-opacity,1))}.dark\\:focus\\:rf-bg-zinc-800:focus:is(.rf-dark *){--tw-bg-opacity:1;background-color:rgb(39 39 42/var(--tw-bg-opacity,1))}.dark\\:focus\\:rf-text-zinc-50:focus:is(.rf-dark *){--tw-text-opacity:1;color:rgb(250 250 250/var(--tw-text-opacity,1))}.dark\\:focus-visible\\:rf-ring-zinc-300:focus-visible:is(.rf-dark *){--tw-ring-opacity:1;--tw-ring-color:rgb(212 212 216/var(--tw-ring-opacity,1))}.dark\\:data-\\[state\\=active\\]\\:rf-bg-zinc-950[data-state=active]:is(.rf-dark *){--tw-bg-opacity:1;background-color:rgb(9 9 11/var(--tw-bg-opacity,1))}.dark\\:data-\\[state\\=open\\]\\:rf-bg-zinc-800[data-state=open]:is(.rf-dark *){--tw-bg-opacity:1;background-color:rgb(39 39 42/var(--tw-bg-opacity,1))}.dark\\:data-\\[state\\=active\\]\\:rf-text-zinc-50[data-state=active]:is(.rf-dark *){--tw-text-opacity:1;color:rgb(250 250 250/var(--tw-text-opacity,1))}@media (min-width:640px){.sm\\:rf-mt-0{margin-top:0}.sm\\:rf-flex-row{flex-direction:row}.sm\\:rf-justify-end{justify-content:flex-end}.sm\\:rf-space-x-2>:not([hidden])~:not([hidden]){--tw-space-x-reverse:0;margin-left:calc(.5rem*(1 - var(--tw-space-x-reverse)));margin-right:calc(.5rem*var(--tw-space-x-reverse))}.sm\\:rf-rounded-lg{border-radius:var(--radius)}.sm\\:rf-text-left{text-align:left}}.\\[\\&\\>svg\\]\\:rf-size-4>svg{height:1rem;width:1rem}.\\[\\&\\>svg\\]\\:rf-shrink-0>svg{flex-shrink:0}.\\[\\&\\>svg\\]\\:rf-text-red-300>svg{--tw-text-opacity:1;color:rgb(252 165 165/var(--tw-text-opacity,1))}.\\[\\&\\>svg\\]\\:hover\\:rf-text-red-400:hover>svg{--tw-text-opacity:1;color:rgb(248 113 113/var(--tw-text-opacity,1))}.\\[\\&_svg\\]\\:rf-pointer-events-none svg{pointer-events:none}.\\[\\&_svg\\]\\:rf-size-4 svg{height:1rem;width:1rem}.\\[\\&_svg\\]\\:rf-shrink-0 svg{flex-shrink:0}',POt=()=>{ut.useEffect(()=>{if(document.querySelector('style[data-styles="tscircuit-runframe"]'))return;const e=document.createElement("style");e.setAttribute("data-styles","tscircuit-runframe"),e.textContent=NOt,document.head.appendChild(e)},[])},iOe=r=>`hsl(${h3.indexOf(r)*137.5%360}, 70%, 50%)`,DOt=({phaseTimings:r})=>{if(!r)return null;const e=Object.values(r).reduce((t,n)=>t+n,0);return tt.jsxs("div",{className:"rf-space-y-2 rf-w-full rf-px-4",children:[tt.jsx("div",{className:"rf-relative rf-h-8 rf-flex rf-rounded-sm",children:h3.map(t=>{const n=r[t]||0,i=n/e*100;return tt.jsx("div",{className:"rf-group/bar rf-relative rf-overflow-visible",style:{width:`${i}%`,backgroundColor:iOe(t)},children:tt.jsxs("div",{className:"rf-opacity-0 group-hover/bar:rf-opacity-100 rf-transition-opacity rf-absolute rf-bottom-full rf-left-1/2 rf-transform -rf-translate-x-1/2 rf-mb-2 rf-px-2 rf-py-1 rf-text-xs rf-whitespace-nowrap rf-rounded rf-bg-gray-900 rf-text-white rf-pointer-events-none",children:[t,": ",n.toFixed(1),"ms"]})},t)})}),tt.jsxs("div",{className:"rf-text-xs rf-text-gray-500",children:["Total: ",e.toFixed(2),"ms"]})]})},LOt=({renderLog:r})=>{const[e,t]=ut.useState("chronological");if(!r)return tt.jsx("div",{className:"rf-p-4 rf-bg-gray-100 rf-rounded-md",children:"No render log, make sure this tab is open when you render (TODO add a rerender button here)"});const n=Object.entries((r==null?void 0:r.phaseTimings)??{});e==="chronological"?n.sort((a,o)=>h3.indexOf(a[0])-h3.indexOf(o[0])):n.sort((a,o)=>o[1]-a[1]);const i=n.reduce((a,[o,s])=>a+s,0);return tt.jsxs("div",{className:"rf-bg-white",children:[tt.jsxs("div",{className:"rf-flex rf-justify-between rf-items-center",children:[tt.jsx("div",{children:"Render Logs"}),tt.jsxs("div",{className:"rf-mb-4 rf-pr-2 rf-flex rf-text-xs rf-items-center",children:[tt.jsx("div",{className:"rf-mr-2",children:"Sort by:"}),tt.jsxs("select",{value:e,onChange:a=>t(a.target.value),className:"rf-px-2 rf-py-1 rf-border rf-rounded rf-text-xs",children:[tt.jsx("option",{value:"chronological",children:"Phase Order"}),tt.jsx("option",{value:"longest",children:"Duration"})]})]})]}),tt.jsx(DOt,{phaseTimings:r.phaseTimings}),tt.jsxs("table",{className:"rf-w-full rf-text-xs",children:[tt.jsx("thead",{children:tt.jsxs("tr",{children:[tt.jsx("th",{className:"rf-text-left rf-p-2",children:"Phase Order"}),tt.jsx("th",{className:"rf-text-left rf-p-2",children:"Phase"}),tt.jsx("th",{className:"rf-text-left rf-p-2",children:"Duration (ms)"})]})}),tt.jsx("tbody",{children:n.map(([a,o])=>tt.jsxs("tr",{children:[tt.jsx("td",{className:"rf-p-2",children:h3.indexOf(a)}),tt.jsx("td",{className:"rf-p-2",children:a}),tt.jsx("td",{className:"rf-p-2",children:tt.jsx("div",{className:"rf-w-8",children:tt.jsx("div",{className:"rf-h-2 rf-rounded-sm",style:{backgroundColor:iOe(a),width:`${o/i*100}%`}})})}),tt.jsx("td",{className:"rf-p-2",children:tt.jsxs("div",{className:"rf-flex w-full",children:[tt.jsxs("span",{className:"rf-flex-grow",children:[o,"ms"]}),tt.jsxs("span",{className:"rf-text-gray-500 rf-pr-2",children:[(o/i*100).toFixed(1),"%"]})]})})]},a))})]})]})},OOt="0.0.248",UOt=["assembly","bom","circuit_json","errors","render_log"],zOt=({code:r,onRunClicked:e=void 0,errorMessage:t,circuitJsonKey:n="",circuitJson:i,autoroutingGraphics:a,showRightHeaderContent:o=!0,showCodeTab:s=!1,codeTabContent:l,showJsonTab:c=!0,showRenderLogTab:u=!0,onActiveTabChange:f,renderLog:v,showImportAndFormatButtons:_=!0,className:x,headerClassName:M,leftHeaderContent:w,readOnly:T,isStreaming:L,autoroutingLog:O,onReportAutoroutingLog:B,isRunningCode:X,hasCodeChangedSinceLastRun:$,onEditEvent:Q,editEvents:ee,defaultActiveTab:ae,autoRotate3dViewerDisabled:K,showSchematicDebugGrid:pe=!1,showToggleFullScreen:me=!0})=>{var je;POt();const[be,Ae]=ut.useState(ae??"pcb"),[Oe,we]=ut.useState(!1),Le=ut.useCallback(Ue=>{Ae(Ue),f==null||f(Ue)},[f]),Te=()=>{we(!Oe)};return ut.useEffect(()=>{t&&Le("errors")},[t]),ut.useEffect(()=>{(be==="code"||be==="errors")&&i&&!t&&Le(ae??"pcb")},[i]),tt.jsx("div",{className:Gv("flex flex-col relative rf-overflow-x-hidden",x),children:tt.jsx("div",{className:Gv("rf-md:sticky rf-md:top-2",Oe&&"rf-fixed rf-top-0 rf-left-0 rf-w-full rf-bg-white"),children:tt.jsxs(fFe,{value:be,onValueChange:Le,className:"rf-flex-grow rf-flex rf-flex-col",children:[tt.jsxs("div",{className:Gv("rf-flex rf-items-center rf-gap-2 rf-p-2 rf-pb-0",M),children:[w,w&&tt.jsx("div",{className:"rf-flex-grow"}),!w&&X&&tt.jsx(Hte,{className:"rf-w-4 rf-h-4 rf-animate-spin"}),!w&&tt.jsx("div",{className:"rf-flex-grow"}),v&&v.progress!==1&&tt.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[v.lastRenderEvent&&tt.jsx("div",{className:"rf-text-xs rf-text-gray-500",children:(je=v.lastRenderEvent)==null?void 0:je.type.split("renderable:renderLifecycle:")[1].split(":")[0]}),tt.jsx("div",{className:"rf-w-4 rf-h-4 rf-bg-blue-500 rf-opacity-50 rf-rounded-full rf-text-white",children:tt.jsx(Hte,{className:"rf-w-4 rf-h-4 rf-animate-spin"})}),tt.jsxs("div",{className:"rf-text-xs rf-font-bold rf-text-gray-700 rf-tabular-nums",children:[((v.progress??0)*100).toFixed(1),"%"]})]}),o&&tt.jsxs(Moe,{children:[s&&tt.jsx(Qw,{value:"code",children:"Code"}),tt.jsxs(Qw,{value:"pcb",className:"rf-whitespace-nowrap",children:[i&&tt.jsx("span",{className:Gv("rf-inline-flex rf-items-center rf-justify-center rf-w-2 rf-h-2 rf-mr-1 rf-text-xs rf-font-bold rf-text-white rf-rounded-full",$?"rf-bg-gray-500":"rf-bg-blue-500")}),"PCB"]}),tt.jsxs(Qw,{value:"schematic",className:"rf-whitespace-nowrap",children:[i&&tt.jsx("span",{className:Gv("rf-inline-flex rf-items-center rf-justify-center rf-w-2 rf-h-2 rf-mr-1 rf-text-xs rf-font-bold rf-text-white rf-rounded-full",$?"rf-bg-gray-500":"rf-bg-blue-500")}),"Schematic"]}),tt.jsxs(Qw,{value:"cad",children:[i&&tt.jsx("span",{className:Gv("inline-flex items-center justify-center w-2 h-2 mr-1 text-xs font-bold text-white rounded-full",$?"rf-bg-gray-500":"rf-bg-blue-500")}),"3D"]}),!["pcb","cad","schematic"].includes(be)&&tt.jsx(Qw,{value:be,children:Toe(be)}),tt.jsxs(One,{children:[tt.jsx(Une,{asChild:!0,children:tt.jsxs("div",{className:"rf-whitespace-nowrap rf-p-2 rf-mr-1 rf-cursor-pointer rf-relative",children:[tt.jsx(u6t,{className:"rf-w-4 rf-h-4"}),t&&tt.jsx("span",{className:"rf-inline-flex rf-absolute rf-top-[6px] rf-right-[4px] rf-items-center rf-justify-center rf-w-1 rf-h-1 rf-ml-2 rf-text-[8px] rf-font-bold rf-text-white rf-bg-red-500 rf-rounded-full"})]})}),tt.jsxs(HU,{className:"rf-*:text-xs",children:[UOt.map(Ue=>tt.jsxs(X8,{onSelect:()=>Le(Ue),children:[be!==Ue&&tt.jsx(MRe,{className:"rf-w-3 rf-h-3 rf-opacity-30"}),be===Ue&&tt.jsx(TRe,{className:"rf-w-3 rf-h-3"}),tt.jsx("div",{className:"rf-pr-2",children:Toe(Ue)}),Ue==="errors"&&t&&tt.jsx("span",{className:"rf-inline-flex rf-items-center rf-justify-center rf-w-3 rf-h-3 rf-ml-2 rf-text-[8px] rf-font-bold rf-text-white rf-bg-red-500 rf-rounded-full",children:"1"})]},Ue)),tt.jsx(X8,{disabled:!0,className:"rf-opacity-60 rf-cursor-default rf-select-none",children:tt.jsxs("div",{className:"rf-pr-2 rf-text-xs rf-text-gray-500",children:["@tscircuit/runframe@",OOt.split(".").map((Ue,Ve)=>Ve===2?parseInt(Ue)+1:Ue).join(".")]})})]})]})]}),me&&tt.jsx(KS,{onClick:Te,variant:"ghost",children:Oe?tt.jsx(d6t,{size:16}):tt.jsx(f6t,{size:16})})]}),s&&tt.jsx(Db,{value:"code",className:"rf-flex-grow rf-overflow-hidden",children:tt.jsx("div",{className:"rf-h-full",children:l})}),tt.jsx(Db,{value:"pcb",children:tt.jsx("div",{className:Gv("rf-overflow-hidden",Oe?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:tt.jsx(F8,{fallbackRender:({error:Ue})=>tt.jsx("div",{className:"rf-mt-4 rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200",children:tt.jsxs("div",{className:"rf-p-4",children:[tt.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-3",children:"Error loading PCB viewer"}),tt.jsx("p",{className:"rf-text-xs rf-font-mono rf-whitespace-pre-wrap rf-text-red-600 rf-mt-2",children:(Ue==null?void 0:Ue.message)||"An unknown error occurred"})]})}),children:i?tt.jsx(AOt,{disableAutoFocus:!0,focusOnHover:!1,circuitJson:i,debugGraphics:a,containerClassName:Gv("rf-h-full rf-w-full",Oe?"rf-min-h-[calc(100vh-240px)]":"rf-min-h-[620px]"),onEditEventsChanged:Ue=>{Q&&Ue.forEach(Ve=>Q(Ve))}},n):tt.jsx(zw,{onRunClicked:e})})})}),tt.jsx(Db,{value:"assembly",children:tt.jsx("div",{className:Gv("rf-overflow-auto",Oe?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:tt.jsx(F8,{fallback:tt.jsx("div",{children:"Error loading Assembly"}),children:i?tt.jsx(wOt,{circuitJson:i,containerStyle:{height:"100%"},editingEnabled:!0,debugGrid:!0}):tt.jsx(zw,{onRunClicked:e})})})}),tt.jsx(Db,{value:"schematic",children:tt.jsx("div",{className:Gv("rf-overflow-auto",Oe?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:tt.jsx(F8,{fallbackRender:({error:Ue})=>tt.jsx("div",{className:"rf-mt-4 rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200",children:tt.jsxs("div",{className:"rf-p-4",children:[tt.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-3",children:"Error loading Schematic"}),tt.jsx("p",{className:"rf-text-xs rf-font-mono rf-whitespace-pre-wrap rf-text-red-600 rf-mt-2",children:(Ue==null?void 0:Ue.message)||"An unknown error occurred"})]})}),children:i?tt.jsx(bOt,{circuitJson:i,containerStyle:{height:"100%"},editingEnabled:!0,onEditEvent:Ue=>Q==null?void 0:Q(Ue),editEvents:ee,debugGrid:pe}):tt.jsx(zw,{onRunClicked:e})})})}),tt.jsx(Db,{value:"cad",children:tt.jsx("div",{className:Gv("rf-overflow-auto",Oe?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:tt.jsx(F8,{FallbackComponent:Z8t,children:i?tt.jsx(U4t,{soup:i,autoRotateDisabled:K}):tt.jsx(zw,{onRunClicked:e})})})}),tt.jsx(Db,{value:"bom",children:tt.jsx("div",{className:Gv("rf-overflow-auto",Oe?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:tt.jsx(F8,{fallbackRender:({error:Ue})=>tt.jsx("div",{className:"rf-mt-4 rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200",children:tt.jsxs("div",{className:"rf-p-4",children:[tt.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-3",children:"Error loading Bill of Materials"}),tt.jsx("p",{className:"rf-text-xs rf-font-mono rf-whitespace-pre-wrap rf-text-red-600 rf-mt-2",children:(Ue==null?void 0:Ue.message)||"An unknown error occurred"})]})}),children:i?tt.jsx(ROt,{circuitJson:i}):tt.jsx(zw,{onRunClicked:e})})})}),tt.jsx(Db,{value:"circuit_json",children:tt.jsx("div",{className:Gv("rf-overflow-auto",Oe?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:tt.jsx(F8,{fallback:tt.jsx("div",{children:"Error loading JSON viewer"}),children:i?tt.jsx(MOt,{elements:i}):tt.jsx(zw,{onRunClicked:e})})})}),tt.jsx(Db,{value:"errors",children:i||t?tt.jsx(aRt,{code:r,errorMessage:t,autoroutingLog:O,onReportAutoroutingLog:B}):tt.jsx(zw,{onRunClicked:e})}),u&&tt.jsx(Db,{value:"render_log",children:tt.jsx(LOt,{renderLog:v})})]})})})},Jre={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},eie=new Map,Yz=r=>{const e=eie.get(r);return e?Object.fromEntries(Object.entries(e.stores).map(([t,n])=>[t,n.getState()])):{}},IOt=(r,e,t)=>{if(r===void 0)return{type:"untracked",connection:e.connect(t)};const n=eie.get(t.name);if(n)return{type:"tracked",store:r,...n};const i={connection:e.connect(t),stores:{}};return eie.set(t.name,i),{type:"tracked",store:r,...i}},kOt=(r,e={})=>(t,n,i)=>{const{enabled:a,anonymousActionType:o,store:s,...l}=e;let c;try{c=(a??(Jre?"production":void 0)!=="production")&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!c)return(Jre?"production":void 0)!=="production"&&a&&console.warn("[zustand devtools middleware] Please install/enable Redux devtools extension"),r(t,n,i);const{connection:u,...f}=IOt(s,c,l);let v=!0;i.setState=(M,w,T)=>{const L=t(M,w);if(!v)return L;const O=T===void 0?{type:o||"anonymous"}:typeof T=="string"?{type:T}:T;return s===void 0?(u==null||u.send(O,n()),L):(u==null||u.send({...O,type:`${s}/${O.type}`},{...Yz(l.name),[s]:i.getState()}),L)};const _=(...M)=>{const w=v;v=!1,t(...M),v=w},x=r(i.setState,n,i);if(f.type==="untracked"?u==null||u.init(x):(f.stores[f.store]=i,u==null||u.init(Object.fromEntries(Object.entries(f.stores).map(([M,w])=>[M,M===f.store?x:w.getState()])))),i.dispatchFromDevtools&&typeof i.dispatch=="function"){let M=!1;const w=i.dispatch;i.dispatch=(...T)=>{(Jre?"production":void 0)!=="production"&&T[0].type==="__setState"&&!M&&(console.warn('[zustand devtools middleware] "__setState" action type is reserved to set state from the devtools. Avoid using it.'),M=!0),w(...T)}}return u.subscribe(M=>{var w;switch(M.type){case"ACTION":if(typeof M.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return tie(M.payload,T=>{if(T.type==="__setState"){if(s===void 0){_(T.state);return}Object.keys(T.state).length!==1&&console.error(`
13358
+ `,i.appendChild(O)}})}};a();const o=new MutationObserver(a);return o.observe(i,{childList:!0,subtree:!1,characterData:!1}),()=>{o.disconnect()}},[r,t,e,n])},bOt=({circuitJson:r,containerStyle:e,editEvents:t=[],onEditEvent:n,defaultEditMode:i=!1,debugGrid:a=!1,editingEnabled:o=!1,debug:s=!1})=>{s&&mOt();const[l,c]=ut.useState(i),u=ut.useRef(null),{ref:f,cancelDrag:v,transform:_}=jNe({onSetTransform($){u.current&&(u.current.style.transform=pE($))}}),{containerWidth:x,containerHeight:M}=hOt(f),w=ut.useMemo(()=>!x||!M?"":Kre(r,{width:x,height:M||720,grid:a?{cellSize:1,labelCells:!0}:void 0}),[r,x,M]),T=ut.useMemo(()=>{var Q;if(!w)return K_();const $=(Q=w.match(/data-real-to-screen-transform="([^"]+)"/))==null?void 0:Q[1];try{return Dk($)}catch(ee){return console.error(ee),K_()}},[w]),{handleMouseDown:L,isDragging:O,activeEditEvent:B}=gOt({onEditEvent:n,cancelDrag:v,realToSvgProjection:T,svgToScreenProjection:_,circuitJson:r,editEvents:t,enabled:l});_Ot({svgDivRef:u,editEvents:t,realToSvgProjection:T,svgToScreenProjection:_,activeEditEvent:B}),xOt({svgDivRef:u,circuitJson:r,activeEditEvent:B,editEvents:t});const X=ut.useMemo(()=>tt.jsx("div",{ref:u,style:{pointerEvents:"auto",transformOrigin:"0 0"},dangerouslySetInnerHTML:{__html:w}}),[w]);return tt.jsxs("div",{ref:f,style:{position:"relative",backgroundColor:"#F5F1ED",overflow:"hidden",cursor:O?"grabbing":"grab",minHeight:"300px",...e},onMouseDown:L,children:[o&&tt.jsx(dOt,{active:l,onClick:()=>c(!l)}),X]})},SOt=r=>{const[e,t]=ut.useState(0),[n,i]=ut.useState(0);return ut.useEffect(()=>{if(!r.current)return;const a=()=>{var l;const s=(l=r.current)==null?void 0:l.getBoundingClientRect();t((s==null?void 0:s.width)||0),i((s==null?void 0:s.height)||0)};a();const o=new ResizeObserver(a);return o.observe(r.current),window.addEventListener("resize",a),()=>{o.disconnect(),window.removeEventListener("resize",a)}},[]),{containerWidth:e,containerHeight:n}};w9("assembly-viewer");var EOt=()=>{w9.enable("assembly-viewer*")},wOt=({circuitJson:r,containerStyle:e,debugGrid:t=!1,debug:n=!1})=>{n&&EOt();const i=ut.useRef(null),{ref:a}=jNe({onSetTransform(u){i.current&&(i.current.style.transform=pE(u))}}),{containerWidth:o,containerHeight:s}=SOt(a),l=ut.useMemo(()=>!o||!s?"":KLe(r,{width:o,height:s||720}),[r,o,s]);ut.useMemo(()=>{var f;if(!l)return K_();const u=(f=l.match(/data-real-to-screen-transform="([^"]+)"/))==null?void 0:f[1];try{return Dk(u)}catch(v){return console.error(v),K_()}},[l]);const c=ut.useMemo(()=>tt.jsx("div",{ref:i,style:{pointerEvents:"auto",transformOrigin:"0 0"},dangerouslySetInnerHTML:{__html:l}}),[l]);return tt.jsx("div",{ref:a,style:{position:"relative",backgroundColor:"#F5F1ED",overflow:"hidden",minHeight:"300px",...e},children:c})};const zw=({onRunClicked:r})=>tt.jsxs("div",{className:"rf-flex rf-items-center rf-gap-3 rf-bg-gray-100 rf-text-center rf-justify-center rf-py-10",children:["No circuit json loaded",r&&tt.jsxs(KS,{className:"rf-bg-blue-600 rf-hover:bg-blue-500",onClick:r,children:["Run Code",tt.jsx(CRe,{className:"rf-w-3 rf-h-3 rf-ml-2"})]})]}),qz=({text:r,onClick:e})=>tt.jsx("span",{className:"rf-cursor-pointer rf-underline rf-text-blue-600 rf-mx-2",onClick:e,children:r}),Wz=r=>{var e;return tt.jsxs("div",{className:"rf-leading-5",children:[tt.jsx("div",{className:"rf-py-2 rf-font-bold",children:r.column.name}),tt.jsx("div",{children:((e=r.field)==null?void 0:e.call(r))??tt.jsx("input",{type:"text",className:"rf-border rf-rounded rf-p-1 rf-w-full",onChange:t=>{var n;(n=r.onTextChange)==null||n.call(r,t.target.value)}})})]})},TOt=({open:r,children:e,title:t,onClose:n})=>r?tt.jsx("div",{className:"rf-fixed rf-inset-0 rf-bg-black rf-bg-opacity-50 rf-flex rf-justify-center rf-items-center rf-z-50",onClick:n,children:tt.jsxs("div",{className:"rf-bg-white rf-p-5 rf-rounded-lg rf-relative rf-w-11/12 rf-max-w-2xl",onClick:i=>{i.preventDefault(),i.stopPropagation()},children:[tt.jsx("h2",{className:"rf-mt-0 rf-text-md rf-pb-4",children:t}),tt.jsx("button",{type:"button",className:"rf-absolute rf-top-2 rf-right-4 rf-text-2xl rf-font-bold",onClick:n,children:"×"}),e]})}):null,MOt=({elements:r})=>{const[e,t]=ut.useState({open:!1}),[n,i]=ut.useReducer((u,f)=>({...u,...f}),{}),a=[...new Set(r.map(u=>u.type))],o=r.map(u=>{const f=u[`${u.type}_id`],v=Object.fromEntries(Object.entries(u).filter(([x])=>!(x===`${u.type}_id`||!x.endsWith("_id")))),_=Object.fromEntries(Object.entries(u).filter(([x])=>!x.endsWith("_id")));return{primary_id:f,other_ids:v,..._,_og_elm:u}}),s=o.map(u=>{let f="";const v=_=>{const x=Object.keys(_.other_ids).find(T=>T.startsWith("source_"));if(!x)return`.${_.name}`;const M=x.slice(0,-3),w=o.find(T=>T.type===M&&T.primary_id===_.other_ids[x]);return w?"name"in w?`${v(w)} > .${_.name}`:`#${w.primary_id} > .${_.name}`:`??? > .${_.name}`};return"name"in u&&(f=v(u)),{...u,selector_path:f}}),l=[{key:"primary_id",name:"primary_id",renderCell:u=>tt.jsxs("div",{className:"rf-flex rf-items-center",children:[tt.jsx(qz,{text:u.primary_id,onClick:()=>i({focused_id:u.primary_id,id_search:void 0,selector_search:void 0})}),tt.jsx("span",{className:"rf-flex-grow"}),tt.jsx(qz,{text:"(JSON)",onClick:()=>t({open:!0,element:u._og_elm,title:u.primary_id})})]}),renderHeaderCell:u=>tt.jsx(Wz,{column:u,onTextChange:f=>i({id_search:f}),field:n.focused_id?()=>tt.jsxs("div",{children:["Focus:"," ",tt.jsx("span",{className:"rf-underline",children:n.focused_id}),tt.jsx(qz,{text:"(unfocus)",onClick:()=>i({focused_id:void 0})})]}):void 0})},{key:"type",name:"type",renderHeaderCell:u=>tt.jsx(Wz,{column:u,field:()=>tt.jsxs("select",{onChange:f=>i({component_type_filter:f.target.value}),className:"rf-border rf-rounded rf-p-1 rf-w-full",children:[tt.jsx("option",{value:"any",children:"any"},"any"),tt.jsx("option",{value:"source",children:"source"},"source"),tt.jsx("option",{value:"source/pcb",children:"source/pcb"},"source/pcb"),tt.jsx("option",{value:"source/schematic",children:"source/schematic"},"source/schematic"),a.map(f=>tt.jsx("option",{value:f,children:f},f))]})})},{key:"name",name:"name",renderHeaderCell:u=>tt.jsx(Wz,{column:u,onTextChange:f=>i({name_search:f})})},{key:"selector_path",name:"selector_path",renderHeaderCell:u=>tt.jsx(Wz,{column:u,onTextChange:f=>i({selector_search:f})})},{key:"other_ids",name:"other_ids",renderCell:u=>tt.jsx("div",{className:"rf-space-x-2",children:Object.entries(u.other_ids).map(([f,v])=>tt.jsx(qz,{text:v,onClick:()=>i({focused_id:v})},v))})}],c=s.filter(u=>{var f,v;return n.name_search?(v=(f=u.name)==null?void 0:f.toLowerCase())==null?void 0:v.includes(n.name_search.toLowerCase()):!0}).filter(u=>{var f;return!n.component_type_filter||n.component_type_filter==="any"?!0:n.component_type_filter==="source"?u.type.startsWith("source_"):n.component_type_filter==="source/pcb"?u.type.startsWith("source_")||u.type.startsWith("pcb_"):n.component_type_filter==="source/schematic"?u.type.startsWith("source_")||u.type.startsWith("schematic_"):(f=u.type)==null?void 0:f.includes(n.component_type_filter)}).filter(u=>n.selector_search?n.selector_search.split(" ").filter(v=>v.length>0).every(v=>{var _;return(_=u.selector_path)==null?void 0:_.includes(v)}):!0).filter(u=>{var f;return n.id_search?(f=u.primary_id)==null?void 0:f.includes(n.id_search):!0}).filter(u=>!!(!n.focused_id||u.primary_id===n.focused_id||Object.values(u.other_ids).includes(n.focused_id)));return tt.jsxs("div",{className:"rf-font-mono rf-text-xs rf-bg-white",children:[tt.jsx("div",{className:"rf-overflow-x-auto",children:tt.jsxs("table",{className:"rf-table-auto rf-w-full rf-text-left",children:[tt.jsx("thead",{children:tt.jsx("tr",{children:l.map(u=>tt.jsx("th",{className:"rf-px-4 rf-py-2 rf-border-b",children:u.renderHeaderCell?u.renderHeaderCell(u):u.name},u.key))})}),tt.jsx("tbody",{children:c.map((u,f)=>tt.jsx("tr",{className:"rf-hover:bg-gray-100",children:l.map(v=>tt.jsx("td",{className:"rf-px-4 rf-py-2 rf-border-b",children:v.renderCell?v.renderCell(u):u[v.key]},v.key))},f))})]})}),tt.jsx(TOt,{open:e.open,onClose:()=>t({open:!1}),title:e.open?e.title:"",children:tt.jsx("div",{className:"rf-bg-gray-800 rf-p-3 rf-text-white rf-rounded",children:tt.jsx("pre",{className:"rf-whitespace-pre-wrap",children:e.open?JSON.stringify(e.element,null,2):""})})})]})},COt=(r,e)=>r==="jlcpcb"?tt.jsx("a",{className:"rf-underline rf-text-blue-500",target:"_blank",rel:"noreferrer",href:`https://jlcpcb.com/partdetail/${e}`,children:e}):e,ROt=({circuitJson:r})=>{const e=r.filter(n=>n.type==="source_component"),t=new Set;for(const n of e)if(n.supplier_part_numbers)for(const i of Object.keys(n.supplier_part_numbers))t.add(i);return tt.jsx("div",{className:"rf-overflow-x-auto",children:tt.jsxs("table",{className:"rf-w-full rf-text-left rf-text-sm",children:[tt.jsx("thead",{children:tt.jsxs("tr",{className:"rf-border-b",children:[tt.jsx("th",{className:"rf-p-2",children:"Name"}),Array.from(t).map(n=>tt.jsx("th",{className:"rf-p-2 rf-capitalize",children:n},n))]})}),tt.jsx("tbody",{children:e.map(n=>tt.jsxs("tr",{className:"rf-border-b",children:[tt.jsx("td",{className:"rf-p-2",children:n.name}),Array.from(t).map(i=>{var a,o;return tt.jsx("td",{className:"rf-p-2",children:COt(i,((o=(a=n.supplier_part_numbers)==null?void 0:a[i])==null?void 0:o[0])||"")},i)})]},n.source_component_id))})]})})},AOt=({containerClassName:r,...e})=>{const t=ut.useRef(null),[n,i]=ut.useState(620);return ut.useLayoutEffect(()=>{const a=()=>{if(t.current){const s=t.current.clientHeight,l=window.innerHeight;i(Math.min(Math.max(s,620),l))}};a();const o=new ResizeObserver(a);return t.current&&o.observe(t.current),window.addEventListener("resize",a),()=>{o.disconnect(),window.removeEventListener("resize",a)}},[]),tt.jsx("div",{ref:t,className:r||"rf-w-full rf-h-full",children:tt.jsx($8t,{...e,height:n})})},NOt='*,:after,:before{--tw-border-spacing-x:0;--tw-border-spacing-y:0;--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness:proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:rgba(59,130,246,.5);--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: ;--tw-contain-size: ;--tw-contain-layout: ;--tw-contain-paint: ;--tw-contain-style: }::backdrop{--tw-border-spacing-x:0;--tw-border-spacing-y:0;--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness:proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:rgba(59,130,246,.5);--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: ;--tw-contain-size: ;--tw-contain-layout: ;--tw-contain-paint: ;--tw-contain-style: }/*! tailwindcss v3.4.17 | MIT License | https://tailwindcss.com*/*,:after,:before{border:0 solid #e5e7eb;box-sizing:border-box}:after,:before{--tw-content:""}:host,html{line-height:1.5;-webkit-text-size-adjust:100%;font-family:ui-sans-serif,system-ui,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji;font-feature-settings:normal;font-variation-settings:normal;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-tap-highlight-color:transparent}body{line-height:inherit;margin:0}hr{border-top-width:1px;color:inherit;height:0}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,pre,samp{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace;font-feature-settings:normal;font-size:1em;font-variation-settings:normal}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}table{border-collapse:collapse;border-color:inherit;text-indent:0}button,input,optgroup,select,textarea{color:inherit;font-family:inherit;font-feature-settings:inherit;font-size:100%;font-variation-settings:inherit;font-weight:inherit;letter-spacing:inherit;line-height:inherit;margin:0;padding:0}button,select{text-transform:none}button,input:where([type=button]),input:where([type=reset]),input:where([type=submit]){-webkit-appearance:button;background-color:transparent;background-image:none}:-moz-focusring{outline:auto}:-moz-ui-invalid{box-shadow:none}progress{vertical-align:baseline}::-webkit-inner-spin-button,::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item}blockquote,dd,dl,figure,h1,h2,h3,h4,h5,h6,hr,p,pre{margin:0}fieldset{margin:0}fieldset,legend{padding:0}menu,ol,ul{list-style:none;margin:0;padding:0}dialog{padding:0}textarea{resize:vertical}input::-moz-placeholder,textarea::-moz-placeholder{color:#9ca3af;opacity:1}input::placeholder,textarea::placeholder{color:#9ca3af;opacity:1}[role=button],button{cursor:pointer}:disabled{cursor:default}audio,canvas,embed,iframe,img,object,svg,video{display:block;vertical-align:middle}img,video{height:auto;max-width:100%}[hidden]:where(:not([hidden=until-found])){display:none}:root{--radius:0.5rem}.rf-pointer-events-none{pointer-events:none}.rf-invisible{visibility:hidden}.rf-fixed{position:fixed}.rf-absolute{position:absolute}.rf-relative{position:relative}.rf-inset-0{inset:0}.-rf-left-2{left:-.5rem}.-rf-right-10{right:-2.5rem}.-rf-right-2{right:-.5rem}.-rf-right-4{right:-1rem}.-rf-right-6{right:-1.5rem}.-rf-right-7{right:-1.75rem}.-rf-right-8{right:-2rem}.-rf-right-9{right:-2.25rem}.rf-bottom-full{bottom:100%}.rf-left-0{left:0}.rf-left-1{left:.25rem}.rf-left-1\\/2{left:50%}.rf-left-2{left:.5rem}.rf-left-\\[50\\%\\]{left:50%}.rf-right-0{right:0}.rf-right-4{right:1rem}.rf-right-\\[4px\\]{right:4px}.rf-top-0{top:0}.rf-top-1{top:.25rem}.rf-top-2{top:.5rem}.rf-top-\\[50\\%\\]{top:50%}.rf-top-\\[6px\\]{top:6px}.rf-z-50{z-index:50}.rf-z-\\[100\\]{z-index:100}.rf--mx-1{margin-left:-.25rem;margin-right:-.25rem}.rf-mx-1{margin-left:.25rem;margin-right:.25rem}.rf-mx-2{margin-left:.5rem;margin-right:.5rem}.rf-my-1{margin-bottom:.25rem;margin-top:.25rem}.rf-my-auto{margin-bottom:auto;margin-top:auto}.rf-mb-2{margin-bottom:.5rem}.rf-mb-3{margin-bottom:.75rem}.rf-mb-4{margin-bottom:1rem}.rf-ml-1{margin-left:.25rem}.rf-ml-2{margin-left:.5rem}.rf-ml-auto{margin-left:auto}.rf-mr-1{margin-right:.25rem}.rf-mr-2{margin-right:.5rem}.rf-mt-0{margin-top:0}.rf-mt-1{margin-top:.25rem}.rf-mt-2{margin-top:.5rem}.rf-mt-4{margin-top:1rem}.rf-inline{display:inline}.rf-flex{display:flex}.rf-inline-flex{display:inline-flex}.rf-grid{display:grid}.rf-size-4{height:1rem;width:1rem}.\\!rf-h-2{height:.5rem!important}.\\!rf-h-2\\.5{height:.625rem!important}.\\!rf-h-3{height:.75rem!important}.\\!rf-h-full{height:100%!important}.rf-h-1{height:.25rem}.rf-h-10{height:2.5rem}.rf-h-2{height:.5rem}.rf-h-3{height:.75rem}.rf-h-3\\.5{height:.875rem}.rf-h-4{height:1rem}.rf-h-60{height:15rem}.rf-h-8{height:2rem}.rf-h-9{height:2.25rem}.rf-h-\\[620px\\]{height:620px}.rf-h-\\[calc\\(100vh-96px\\)\\]{height:calc(100vh - 96px)}.rf-h-fit{height:-moz-fit-content;height:fit-content}.rf-h-full{height:100%}.rf-h-px{height:1px}.rf-max-h-\\[500px\\]{max-height:500px}.rf-min-h-\\[620px\\]{min-height:620px}.rf-min-h-\\[calc\\(100vh-240px\\)\\]{min-height:calc(100vh - 240px)}.\\!rf-w-2{width:.5rem!important}.\\!rf-w-2\\.5{width:.625rem!important}.rf-w-1{width:.25rem}.rf-w-11{width:2.75rem}.rf-w-11\\/12{width:91.666667%}.rf-w-16{width:4rem}.rf-w-2{width:.5rem}.rf-w-3{width:.75rem}.rf-w-3\\.5{width:.875rem}.rf-w-32{width:8rem}.rf-w-4{width:1rem}.rf-w-64{width:16rem}.rf-w-72{width:18rem}.rf-w-8{width:2rem}.rf-w-9{width:2.25rem}.rf-w-96{width:24rem}.rf-w-fit{width:-moz-fit-content;width:fit-content}.rf-w-full{width:100%}.rf-min-w-10{min-width:2.5rem}.rf-min-w-16{min-width:4rem}.rf-min-w-\\[8rem\\]{min-width:8rem}.rf-max-w-2xl{max-width:42rem}.rf-max-w-lg{max-width:32rem}.rf-max-w-xl{max-width:36rem}.rf-shrink-0{flex-shrink:0}.rf-flex-grow{flex-grow:1}.rf-table-auto{table-layout:auto}.-rf-translate-x-1{--tw-translate-x:-0.25rem}.-rf-translate-x-1,.-rf-translate-x-1\\/2{transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.-rf-translate-x-1\\/2{--tw-translate-x:-50%}.-rf-translate-y-1{--tw-translate-y:-0.25rem}.-rf-translate-y-1,.rf--translate-x-1{transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.rf--translate-x-1{--tw-translate-x:-0.25rem}.rf-translate-x-\\[-50\\%\\]{--tw-translate-x:-50%}.rf-translate-x-\\[-50\\%\\],.rf-translate-y-\\[-50\\%\\]{transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.rf-translate-y-\\[-50\\%\\]{--tw-translate-y:-50%}.rf-transform{transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}@keyframes rf-spin{to{transform:rotate(1turn)}}.rf-animate-spin{animation:rf-spin 1s linear infinite}.rf-cursor-default{cursor:default}.rf-cursor-pointer{cursor:pointer}.rf-select-none{-webkit-user-select:none;-moz-user-select:none;user-select:none}.rf-flex-col{flex-direction:column}.rf-flex-col-reverse{flex-direction:column-reverse}.rf-place-items-center{place-items:center}.rf-items-center{align-items:center}.rf-justify-end{justify-content:flex-end}.rf-justify-center{justify-content:center}.rf-justify-between{justify-content:space-between}.rf-gap-0{gap:0}.rf-gap-1{gap:.25rem}.rf-gap-2{gap:.5rem}.rf-gap-3{gap:.75rem}.rf-gap-4{gap:1rem}.rf-gap-5{gap:1.25rem}.rf-gap-6{gap:1.5rem}.rf-space-x-2>:not([hidden])~:not([hidden]){--tw-space-x-reverse:0;margin-left:calc(.5rem*(1 - var(--tw-space-x-reverse)));margin-right:calc(.5rem*var(--tw-space-x-reverse))}.rf-space-y-2>:not([hidden])~:not([hidden]){--tw-space-y-reverse:0;margin-bottom:calc(.5rem*var(--tw-space-y-reverse));margin-top:calc(.5rem*(1 - var(--tw-space-y-reverse)))}.rf-overflow-auto{overflow:auto}.rf-overflow-hidden{overflow:hidden}.rf-overflow-visible{overflow:visible}.rf-overflow-x-auto{overflow-x:auto}.rf-overflow-y-auto{overflow-y:auto}.rf-overflow-x-hidden{overflow-x:hidden}.rf-truncate{overflow:hidden;text-overflow:ellipsis}.rf-truncate,.rf-whitespace-nowrap{white-space:nowrap}.rf-whitespace-pre-wrap{white-space:pre-wrap}.rf-break-words{overflow-wrap:break-word}.rf-rounded{border-radius:.25rem}.rf-rounded-full{border-radius:9999px}.rf-rounded-lg{border-radius:var(--radius)}.rf-rounded-md{border-radius:calc(var(--radius) - 2px)}.rf-rounded-sm{border-radius:calc(var(--radius) - 4px)}.rf-border{border-width:1px}.rf-border-b{border-bottom-width:1px}.rf-border-green-200{--tw-border-opacity:1;border-color:rgb(187 247 208/var(--tw-border-opacity,1))}.rf-border-neutral-200{--tw-border-opacity:1;border-color:rgb(229 229 229/var(--tw-border-opacity,1))}.rf-border-red-200{--tw-border-opacity:1;border-color:rgb(254 202 202/var(--tw-border-opacity,1))}.rf-border-zinc-200{--tw-border-opacity:1;border-color:rgb(228 228 231/var(--tw-border-opacity,1))}.rf-bg-black{--tw-bg-opacity:1;background-color:rgb(0 0 0/var(--tw-bg-opacity,1))}.rf-bg-black\\/80{background-color:rgba(0,0,0,.8)}.rf-bg-blue-500{--tw-bg-opacity:1;background-color:rgb(59 130 246/var(--tw-bg-opacity,1))}.rf-bg-blue-600{--tw-bg-opacity:1;background-color:rgb(37 99 235/var(--tw-bg-opacity,1))}.rf-bg-blue-600\\/70{background-color:rgba(37,99,235,.7)}.rf-bg-gray-100{--tw-bg-opacity:1;background-color:rgb(243 244 246/var(--tw-bg-opacity,1))}.rf-bg-gray-500{--tw-bg-opacity:1;background-color:rgb(107 114 128/var(--tw-bg-opacity,1))}.rf-bg-gray-800{--tw-bg-opacity:1;background-color:rgb(31 41 55/var(--tw-bg-opacity,1))}.rf-bg-gray-900{--tw-bg-opacity:1;background-color:rgb(17 24 39/var(--tw-bg-opacity,1))}.rf-bg-green-50{--tw-bg-opacity:1;background-color:rgb(240 253 244/var(--tw-bg-opacity,1))}.rf-bg-neutral-100{--tw-bg-opacity:1;background-color:rgb(245 245 245/var(--tw-bg-opacity,1))}.rf-bg-neutral-50{--tw-bg-opacity:1;background-color:rgb(250 250 250/var(--tw-bg-opacity,1))}.rf-bg-neutral-800{--tw-bg-opacity:1;background-color:rgb(38 38 38/var(--tw-bg-opacity,1))}.rf-bg-neutral-900{--tw-bg-opacity:1;background-color:rgb(23 23 23/var(--tw-bg-opacity,1))}.rf-bg-orange-400{--tw-bg-opacity:1;background-color:rgb(251 146 60/var(--tw-bg-opacity,1))}.rf-bg-red-100{--tw-bg-opacity:1;background-color:rgb(254 226 226/var(--tw-bg-opacity,1))}.rf-bg-red-50{--tw-bg-opacity:1;background-color:rgb(254 242 242/var(--tw-bg-opacity,1))}.rf-bg-red-500{--tw-bg-opacity:1;background-color:rgb(239 68 68/var(--tw-bg-opacity,1))}.rf-bg-red-900{--tw-bg-opacity:1;background-color:rgb(127 29 29/var(--tw-bg-opacity,1))}.rf-bg-white{--tw-bg-opacity:1;background-color:rgb(255 255 255/var(--tw-bg-opacity,1))}.rf-bg-zinc-100{--tw-bg-opacity:1;background-color:rgb(244 244 245/var(--tw-bg-opacity,1))}.rf-bg-zinc-200{--tw-bg-opacity:1;background-color:rgb(228 228 231/var(--tw-bg-opacity,1))}.rf-bg-zinc-50{--tw-bg-opacity:1;background-color:rgb(250 250 250/var(--tw-bg-opacity,1))}.rf-bg-zinc-800{--tw-bg-opacity:1;background-color:rgb(39 39 42/var(--tw-bg-opacity,1))}.rf-bg-zinc-900{--tw-bg-opacity:1;background-color:rgb(24 24 27/var(--tw-bg-opacity,1))}.rf-bg-opacity-50{--tw-bg-opacity:0.5}.rf-fill-current{fill:currentColor}.rf-p-0{padding:0}.rf-p-0\\.5{padding:.125rem}.rf-p-1{padding:.25rem}.rf-p-2{padding:.5rem}.rf-p-3{padding:.75rem}.rf-p-4{padding:1rem}.rf-p-5{padding:1.25rem}.rf-p-6{padding:1.5rem}.rf-px-1{padding-left:.25rem;padding-right:.25rem}.rf-px-1\\.5{padding-left:.375rem;padding-right:.375rem}.rf-px-2{padding-left:.5rem;padding-right:.5rem}.rf-px-3{padding-left:.75rem;padding-right:.75rem}.rf-px-4{padding-left:1rem;padding-right:1rem}.rf-px-8{padding-left:2rem;padding-right:2rem}.rf-py-0{padding-bottom:0;padding-top:0}.rf-py-1{padding-bottom:.25rem;padding-top:.25rem}.rf-py-1\\.5{padding-bottom:.375rem;padding-top:.375rem}.rf-py-10{padding-bottom:2.5rem;padding-top:2.5rem}.rf-py-2{padding-bottom:.5rem;padding-top:.5rem}.rf-pb-0{padding-bottom:0}.rf-pb-4{padding-bottom:1rem}.rf-pl-2{padding-left:.5rem}.rf-pl-8{padding-left:2rem}.rf-pr-2{padding-right:.5rem}.rf-text-left{text-align:left}.rf-text-center{text-align:center}.rf-font-mono{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace}.rf-text-2xl{font-size:1.5rem;line-height:2rem}.rf-text-\\[8px\\]{font-size:8px}.rf-text-lg{font-size:1.125rem;line-height:1.75rem}.rf-text-sm{font-size:.875rem;line-height:1.25rem}.rf-text-xs{font-size:.75rem;line-height:1rem}.rf-font-bold{font-weight:700}.rf-font-medium{font-weight:500}.rf-font-semibold{font-weight:600}.rf-capitalize{text-transform:capitalize}.rf-tabular-nums{--tw-numeric-spacing:tabular-nums;font-variant-numeric:var(--tw-ordinal) var(--tw-slashed-zero) var(--tw-numeric-figure) var(--tw-numeric-spacing) var(--tw-numeric-fraction)}.rf-leading-5{line-height:1.25rem}.rf-tracking-widest{letter-spacing:.1em}.rf-text-blue-500{--tw-text-opacity:1;color:rgb(59 130 246/var(--tw-text-opacity,1))}.rf-text-blue-600{--tw-text-opacity:1;color:rgb(37 99 235/var(--tw-text-opacity,1))}.rf-text-gray-500{--tw-text-opacity:1;color:rgb(107 114 128/var(--tw-text-opacity,1))}.rf-text-gray-600{--tw-text-opacity:1;color:rgb(75 85 99/var(--tw-text-opacity,1))}.rf-text-gray-700{--tw-text-opacity:1;color:rgb(55 65 81/var(--tw-text-opacity,1))}.rf-text-green-500{--tw-text-opacity:1;color:rgb(34 197 94/var(--tw-text-opacity,1))}.rf-text-green-700{--tw-text-opacity:1;color:rgb(21 128 61/var(--tw-text-opacity,1))}.rf-text-green-800{--tw-text-opacity:1;color:rgb(22 101 52/var(--tw-text-opacity,1))}.rf-text-neutral-50{--tw-text-opacity:1;color:rgb(250 250 250/var(--tw-text-opacity,1))}.rf-text-neutral-500{--tw-text-opacity:1;color:rgb(115 115 115/var(--tw-text-opacity,1))}.rf-text-neutral-900{--tw-text-opacity:1;color:rgb(23 23 23/var(--tw-text-opacity,1))}.rf-text-neutral-950{--tw-text-opacity:1;color:rgb(10 10 10/var(--tw-text-opacity,1))}.rf-text-red-200{--tw-text-opacity:1;color:rgb(254 202 202/var(--tw-text-opacity,1))}.rf-text-red-300{--tw-text-opacity:1;color:rgb(252 165 165/var(--tw-text-opacity,1))}.rf-text-red-400{--tw-text-opacity:1;color:rgb(248 113 113/var(--tw-text-opacity,1))}.rf-text-red-500{--tw-text-opacity:1;color:rgb(239 68 68/var(--tw-text-opacity,1))}.rf-text-red-600{--tw-text-opacity:1;color:rgb(220 38 38/var(--tw-text-opacity,1))}.rf-text-red-700{--tw-text-opacity:1;color:rgb(185 28 28/var(--tw-text-opacity,1))}.rf-text-red-800{--tw-text-opacity:1;color:rgb(153 27 27/var(--tw-text-opacity,1))}.rf-text-red-900{--tw-text-opacity:1;color:rgb(127 29 29/var(--tw-text-opacity,1))}.rf-text-white{--tw-text-opacity:1;color:rgb(255 255 255/var(--tw-text-opacity,1))}.rf-text-zinc-200{--tw-text-opacity:1;color:rgb(228 228 231/var(--tw-text-opacity,1))}.rf-text-zinc-300{--tw-text-opacity:1;color:rgb(212 212 216/var(--tw-text-opacity,1))}.rf-text-zinc-400{--tw-text-opacity:1;color:rgb(161 161 170/var(--tw-text-opacity,1))}.rf-text-zinc-50{--tw-text-opacity:1;color:rgb(250 250 250/var(--tw-text-opacity,1))}.rf-text-zinc-500{--tw-text-opacity:1;color:rgb(113 113 122/var(--tw-text-opacity,1))}.rf-text-zinc-900{--tw-text-opacity:1;color:rgb(24 24 27/var(--tw-text-opacity,1))}.rf-text-zinc-950{--tw-text-opacity:1;color:rgb(9 9 11/var(--tw-text-opacity,1))}.rf-underline{text-decoration-line:underline}.rf-underline-offset-4{text-underline-offset:4px}.rf-opacity-0{opacity:0}.rf-opacity-25{opacity:.25}.rf-opacity-30{opacity:.3}.rf-opacity-50{opacity:.5}.rf-opacity-60{opacity:.6}.rf-shadow{--tw-shadow:0 1px 3px 0 rgba(0,0,0,.1),0 1px 2px -1px rgba(0,0,0,.1);--tw-shadow-colored:0 1px 3px 0 var(--tw-shadow-color),0 1px 2px -1px var(--tw-shadow-color)}.rf-shadow,.rf-shadow-lg{box-shadow:var(--tw-ring-offset-shadow,0 0 #0000),var(--tw-ring-shadow,0 0 #0000),var(--tw-shadow)}.rf-shadow-lg{--tw-shadow:0 10px 15px -3px rgba(0,0,0,.1),0 4px 6px -4px rgba(0,0,0,.1);--tw-shadow-colored:0 10px 15px -3px var(--tw-shadow-color),0 4px 6px -4px var(--tw-shadow-color)}.rf-shadow-md{--tw-shadow:0 4px 6px -1px rgba(0,0,0,.1),0 2px 4px -2px rgba(0,0,0,.1);--tw-shadow-colored:0 4px 6px -1px var(--tw-shadow-color),0 2px 4px -2px var(--tw-shadow-color)}.rf-shadow-md,.rf-shadow-sm{box-shadow:var(--tw-ring-offset-shadow,0 0 #0000),var(--tw-ring-shadow,0 0 #0000),var(--tw-shadow)}.rf-shadow-sm{--tw-shadow:0 1px 2px 0 rgba(0,0,0,.05);--tw-shadow-colored:0 1px 2px 0 var(--tw-shadow-color)}.rf-outline-none{outline:2px solid transparent;outline-offset:2px}.rf-ring-offset-white{--tw-ring-offset-color:#fff}.rf-transition-all{transition-duration:.15s;transition-property:all;transition-timing-function:cubic-bezier(.4,0,.2,1)}.rf-transition-colors{transition-duration:.15s;transition-property:color,background-color,border-color,text-decoration-color,fill,stroke;transition-timing-function:cubic-bezier(.4,0,.2,1)}.rf-transition-opacity{transition-duration:.15s;transition-property:opacity;transition-timing-function:cubic-bezier(.4,0,.2,1)}.rf-duration-200{transition-duration:.2s}@keyframes enter{0%{opacity:var(--tw-enter-opacity,1);transform:translate3d(var(--tw-enter-translate-x,0),var(--tw-enter-translate-y,0),0) scale3d(var(--tw-enter-scale,1),var(--tw-enter-scale,1),var(--tw-enter-scale,1)) rotate(var(--tw-enter-rotate,0))}}@keyframes exit{to{opacity:var(--tw-exit-opacity,1);transform:translate3d(var(--tw-exit-translate-x,0),var(--tw-exit-translate-y,0),0) scale3d(var(--tw-exit-scale,1),var(--tw-exit-scale,1),var(--tw-exit-scale,1)) rotate(var(--tw-exit-rotate,0))}}.rf-slide-in-from-left-1{--tw-enter-translate-x:-0.25rem}.rf-slide-out-to-left-1{--tw-exit-translate-x:-0.25rem}.rf-duration-200{animation-duration:.2s}.hover\\:\\!rf-bg-transparent:hover{background-color:transparent!important}.hover\\:rf-bg-blue-700:hover{--tw-bg-opacity:1;background-color:rgb(29 78 216/var(--tw-bg-opacity,1))}.hover\\:rf-bg-red-500\\/90:hover{background-color:rgba(239,68,68,.9)}.hover\\:rf-bg-zinc-100:hover{--tw-bg-opacity:1;background-color:rgb(244 244 245/var(--tw-bg-opacity,1))}.hover\\:rf-bg-zinc-100\\/80:hover{background-color:hsla(240,5%,96%,.8)}.hover\\:rf-bg-zinc-900\\/90:hover{background-color:rgba(24,24,27,.9)}.hover\\:rf-text-red-400:hover{--tw-text-opacity:1;color:rgb(248 113 113/var(--tw-text-opacity,1))}.hover\\:rf-text-zinc-900:hover{--tw-text-opacity:1;color:rgb(24 24 27/var(--tw-text-opacity,1))}.hover\\:rf-underline:hover{text-decoration-line:underline}.focus\\:rf-bg-zinc-100:focus{--tw-bg-opacity:1;background-color:rgb(244 244 245/var(--tw-bg-opacity,1))}.focus\\:rf-text-zinc-900:focus{--tw-text-opacity:1;color:rgb(24 24 27/var(--tw-text-opacity,1))}.focus-visible\\:rf-outline-none:focus-visible{outline:2px solid transparent;outline-offset:2px}.focus-visible\\:rf-ring-1:focus-visible{--tw-ring-offset-shadow:var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow:var(--tw-ring-inset) 0 0 0 calc(1px + var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow,0 0 #0000)}.focus-visible\\:rf-ring-2:focus-visible{--tw-ring-offset-shadow:var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow:var(--tw-ring-inset) 0 0 0 calc(2px + var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow,0 0 #0000)}.focus-visible\\:rf-ring-zinc-950:focus-visible{--tw-ring-opacity:1;--tw-ring-color:rgb(9 9 11/var(--tw-ring-opacity,1))}.focus-visible\\:rf-ring-offset-2:focus-visible{--tw-ring-offset-width:2px}.disabled\\:rf-pointer-events-none:disabled{pointer-events:none}.disabled\\:rf-bg-blue-600\\/60:disabled{background-color:rgba(37,99,235,.6)}.disabled\\:rf-opacity-50:disabled{opacity:.5}.rf-group\\/bar:hover .group-hover\\/bar\\:rf-opacity-100{opacity:1}.data-\\[disabled\\]\\:rf-pointer-events-none[data-disabled]{pointer-events:none}.data-\\[state\\=active\\]\\:rf-bg-white[data-state=active]{--tw-bg-opacity:1;background-color:rgb(255 255 255/var(--tw-bg-opacity,1))}.data-\\[state\\=open\\]\\:rf-bg-zinc-100[data-state=open]{--tw-bg-opacity:1;background-color:rgb(244 244 245/var(--tw-bg-opacity,1))}.data-\\[state\\=active\\]\\:rf-text-zinc-950[data-state=active]{--tw-text-opacity:1;color:rgb(9 9 11/var(--tw-text-opacity,1))}.data-\\[disabled\\]\\:rf-opacity-50[data-disabled]{opacity:.5}.data-\\[state\\=active\\]\\:rf-shadow[data-state=active]{--tw-shadow:0 1px 3px 0 rgba(0,0,0,.1),0 1px 2px -1px rgba(0,0,0,.1);--tw-shadow-colored:0 1px 3px 0 var(--tw-shadow-color),0 1px 2px -1px var(--tw-shadow-color);box-shadow:var(--tw-ring-offset-shadow,0 0 #0000),var(--tw-ring-shadow,0 0 #0000),var(--tw-shadow)}.data-\\[state\\=open\\]\\:rf-animate-in[data-state=open]{animation-duration:.15s;animation-name:enter;--tw-enter-opacity:initial;--tw-enter-scale:initial;--tw-enter-rotate:initial;--tw-enter-translate-x:initial;--tw-enter-translate-y:initial}.data-\\[state\\=closed\\]\\:rf-animate-out[data-state=closed]{animation-duration:.15s;animation-name:exit;--tw-exit-opacity:initial;--tw-exit-scale:initial;--tw-exit-rotate:initial;--tw-exit-translate-x:initial;--tw-exit-translate-y:initial}.data-\\[state\\=closed\\]\\:rf-fade-out-0[data-state=closed]{--tw-exit-opacity:0}.data-\\[state\\=open\\]\\:rf-fade-in-0[data-state=open]{--tw-enter-opacity:0}.data-\\[state\\=closed\\]\\:rf-zoom-out-95[data-state=closed]{--tw-exit-scale:.95}.data-\\[state\\=open\\]\\:rf-zoom-in-95[data-state=open]{--tw-enter-scale:.95}.data-\\[side\\=bottom\\]\\:rf-slide-in-from-top-2[data-side=bottom]{--tw-enter-translate-y:-0.5rem}.data-\\[side\\=left\\]\\:rf-slide-in-from-right-2[data-side=left]{--tw-enter-translate-x:0.5rem}.data-\\[side\\=right\\]\\:rf-slide-in-from-left-2[data-side=right]{--tw-enter-translate-x:-0.5rem}.data-\\[side\\=top\\]\\:rf-slide-in-from-bottom-2[data-side=top]{--tw-enter-translate-y:0.5rem}.data-\\[state\\=closed\\]\\:rf-slide-out-to-left-1\\/2[data-state=closed]{--tw-exit-translate-x:-50%}.data-\\[state\\=closed\\]\\:rf-slide-out-to-top-\\[48\\%\\][data-state=closed]{--tw-exit-translate-y:-48%}.data-\\[state\\=open\\]\\:rf-slide-in-from-left-1\\/2[data-state=open]{--tw-enter-translate-x:-50%}.data-\\[state\\=open\\]\\:rf-slide-in-from-top-\\[48\\%\\][data-state=open]{--tw-enter-translate-y:-48%}.dark\\:rf-border-zinc-800:is(.rf-dark *){--tw-border-opacity:1;border-color:rgb(39 39 42/var(--tw-border-opacity,1))}.dark\\:rf-bg-red-900:is(.rf-dark *){--tw-bg-opacity:1;background-color:rgb(127 29 29/var(--tw-bg-opacity,1))}.dark\\:rf-bg-zinc-50:is(.rf-dark *){--tw-bg-opacity:1;background-color:rgb(250 250 250/var(--tw-bg-opacity,1))}.dark\\:rf-bg-zinc-800:is(.rf-dark *){--tw-bg-opacity:1;background-color:rgb(39 39 42/var(--tw-bg-opacity,1))}.dark\\:rf-bg-zinc-950:is(.rf-dark *){--tw-bg-opacity:1;background-color:rgb(9 9 11/var(--tw-bg-opacity,1))}.dark\\:rf-text-zinc-400:is(.rf-dark *){--tw-text-opacity:1;color:rgb(161 161 170/var(--tw-text-opacity,1))}.dark\\:rf-text-zinc-50:is(.rf-dark *){--tw-text-opacity:1;color:rgb(250 250 250/var(--tw-text-opacity,1))}.dark\\:rf-text-zinc-900:is(.rf-dark *){--tw-text-opacity:1;color:rgb(24 24 27/var(--tw-text-opacity,1))}.dark\\:rf-ring-offset-zinc-950:is(.rf-dark *){--tw-ring-offset-color:#09090b}.dark\\:hover\\:rf-bg-red-900\\/90:hover:is(.rf-dark *){background-color:rgba(127,29,29,.9)}.dark\\:hover\\:rf-bg-zinc-50\\/90:hover:is(.rf-dark *){background-color:hsla(0,0%,98%,.9)}.dark\\:hover\\:rf-bg-zinc-800:hover:is(.rf-dark *){--tw-bg-opacity:1;background-color:rgb(39 39 42/var(--tw-bg-opacity,1))}.dark\\:hover\\:rf-bg-zinc-800\\/80:hover:is(.rf-dark *){background-color:rgba(39,39,42,.8)}.dark\\:hover\\:rf-text-zinc-50:hover:is(.rf-dark *){--tw-text-opacity:1;color:rgb(250 250 250/var(--tw-text-opacity,1))}.dark\\:focus\\:rf-bg-zinc-800:focus:is(.rf-dark *){--tw-bg-opacity:1;background-color:rgb(39 39 42/var(--tw-bg-opacity,1))}.dark\\:focus\\:rf-text-zinc-50:focus:is(.rf-dark *){--tw-text-opacity:1;color:rgb(250 250 250/var(--tw-text-opacity,1))}.dark\\:focus-visible\\:rf-ring-zinc-300:focus-visible:is(.rf-dark *){--tw-ring-opacity:1;--tw-ring-color:rgb(212 212 216/var(--tw-ring-opacity,1))}.dark\\:data-\\[state\\=active\\]\\:rf-bg-zinc-950[data-state=active]:is(.rf-dark *){--tw-bg-opacity:1;background-color:rgb(9 9 11/var(--tw-bg-opacity,1))}.dark\\:data-\\[state\\=open\\]\\:rf-bg-zinc-800[data-state=open]:is(.rf-dark *){--tw-bg-opacity:1;background-color:rgb(39 39 42/var(--tw-bg-opacity,1))}.dark\\:data-\\[state\\=active\\]\\:rf-text-zinc-50[data-state=active]:is(.rf-dark *){--tw-text-opacity:1;color:rgb(250 250 250/var(--tw-text-opacity,1))}@media (min-width:640px){.sm\\:rf-mt-0{margin-top:0}.sm\\:rf-flex-row{flex-direction:row}.sm\\:rf-justify-end{justify-content:flex-end}.sm\\:rf-space-x-2>:not([hidden])~:not([hidden]){--tw-space-x-reverse:0;margin-left:calc(.5rem*(1 - var(--tw-space-x-reverse)));margin-right:calc(.5rem*var(--tw-space-x-reverse))}.sm\\:rf-rounded-lg{border-radius:var(--radius)}.sm\\:rf-text-left{text-align:left}}.\\[\\&\\>svg\\]\\:rf-size-4>svg{height:1rem;width:1rem}.\\[\\&\\>svg\\]\\:rf-shrink-0>svg{flex-shrink:0}.\\[\\&\\>svg\\]\\:rf-text-red-300>svg{--tw-text-opacity:1;color:rgb(252 165 165/var(--tw-text-opacity,1))}.\\[\\&\\>svg\\]\\:hover\\:rf-text-red-400:hover>svg{--tw-text-opacity:1;color:rgb(248 113 113/var(--tw-text-opacity,1))}.\\[\\&_svg\\]\\:rf-pointer-events-none svg{pointer-events:none}.\\[\\&_svg\\]\\:rf-size-4 svg{height:1rem;width:1rem}.\\[\\&_svg\\]\\:rf-shrink-0 svg{flex-shrink:0}',POt=()=>{ut.useEffect(()=>{if(document.querySelector('style[data-styles="tscircuit-runframe"]'))return;const e=document.createElement("style");e.setAttribute("data-styles","tscircuit-runframe"),e.textContent=NOt,document.head.appendChild(e)},[])},iOe=r=>`hsl(${h3.indexOf(r)*137.5%360}, 70%, 50%)`,DOt=({phaseTimings:r})=>{if(!r)return null;const e=Object.values(r).reduce((t,n)=>t+n,0);return tt.jsxs("div",{className:"rf-space-y-2 rf-w-full rf-px-4",children:[tt.jsx("div",{className:"rf-relative rf-h-8 rf-flex rf-rounded-sm",children:h3.map(t=>{const n=r[t]||0,i=n/e*100;return tt.jsx("div",{className:"rf-group/bar rf-relative rf-overflow-visible",style:{width:`${i}%`,backgroundColor:iOe(t)},children:tt.jsxs("div",{className:"rf-opacity-0 group-hover/bar:rf-opacity-100 rf-transition-opacity rf-absolute rf-bottom-full rf-left-1/2 rf-transform -rf-translate-x-1/2 rf-mb-2 rf-px-2 rf-py-1 rf-text-xs rf-whitespace-nowrap rf-rounded rf-bg-gray-900 rf-text-white rf-pointer-events-none",children:[t,": ",n.toFixed(1),"ms"]})},t)})}),tt.jsxs("div",{className:"rf-text-xs rf-text-gray-500",children:["Total: ",e.toFixed(2),"ms"]})]})},LOt=({renderLog:r})=>{const[e,t]=ut.useState("chronological");if(!r)return tt.jsx("div",{className:"rf-p-4 rf-bg-gray-100 rf-rounded-md",children:"No render log, make sure this tab is open when you render (TODO add a rerender button here)"});const n=Object.entries((r==null?void 0:r.phaseTimings)??{});e==="chronological"?n.sort((a,o)=>h3.indexOf(a[0])-h3.indexOf(o[0])):n.sort((a,o)=>o[1]-a[1]);const i=n.reduce((a,[o,s])=>a+s,0);return tt.jsxs("div",{className:"rf-bg-white",children:[tt.jsxs("div",{className:"rf-flex rf-justify-between rf-items-center",children:[tt.jsx("div",{children:"Render Logs"}),tt.jsxs("div",{className:"rf-mb-4 rf-pr-2 rf-flex rf-text-xs rf-items-center",children:[tt.jsx("div",{className:"rf-mr-2",children:"Sort by:"}),tt.jsxs("select",{value:e,onChange:a=>t(a.target.value),className:"rf-px-2 rf-py-1 rf-border rf-rounded rf-text-xs",children:[tt.jsx("option",{value:"chronological",children:"Phase Order"}),tt.jsx("option",{value:"longest",children:"Duration"})]})]})]}),tt.jsx(DOt,{phaseTimings:r.phaseTimings}),tt.jsxs("table",{className:"rf-w-full rf-text-xs",children:[tt.jsx("thead",{children:tt.jsxs("tr",{children:[tt.jsx("th",{className:"rf-text-left rf-p-2",children:"Phase Order"}),tt.jsx("th",{className:"rf-text-left rf-p-2",children:"Phase"}),tt.jsx("th",{className:"rf-text-left rf-p-2",children:"Duration (ms)"})]})}),tt.jsx("tbody",{children:n.map(([a,o])=>tt.jsxs("tr",{children:[tt.jsx("td",{className:"rf-p-2",children:h3.indexOf(a)}),tt.jsx("td",{className:"rf-p-2",children:a}),tt.jsx("td",{className:"rf-p-2",children:tt.jsx("div",{className:"rf-w-8",children:tt.jsx("div",{className:"rf-h-2 rf-rounded-sm",style:{backgroundColor:iOe(a),width:`${o/i*100}%`}})})}),tt.jsx("td",{className:"rf-p-2",children:tt.jsxs("div",{className:"rf-flex w-full",children:[tt.jsxs("span",{className:"rf-flex-grow",children:[o,"ms"]}),tt.jsxs("span",{className:"rf-text-gray-500 rf-pr-2",children:[(o/i*100).toFixed(1),"%"]})]})})]},a))})]})]})},OOt="0.0.250",UOt=["assembly","bom","circuit_json","errors","render_log"],zOt=({code:r,onRunClicked:e=void 0,errorMessage:t,circuitJsonKey:n="",circuitJson:i,autoroutingGraphics:a,showRightHeaderContent:o=!0,showCodeTab:s=!1,codeTabContent:l,showJsonTab:c=!0,showRenderLogTab:u=!0,onActiveTabChange:f,renderLog:v,showImportAndFormatButtons:_=!0,className:x,headerClassName:M,leftHeaderContent:w,readOnly:T,isStreaming:L,autoroutingLog:O,onReportAutoroutingLog:B,isRunningCode:X,hasCodeChangedSinceLastRun:$,onEditEvent:Q,editEvents:ee,defaultActiveTab:ae,autoRotate3dViewerDisabled:K,showSchematicDebugGrid:pe=!1,showToggleFullScreen:me=!0})=>{var je;POt();const[be,Ae]=ut.useState(ae??"pcb"),[Oe,we]=ut.useState(!1),Le=ut.useCallback(Ue=>{Ae(Ue),f==null||f(Ue)},[f]),Te=()=>{we(!Oe)};return ut.useEffect(()=>{t&&Le("errors")},[t]),ut.useEffect(()=>{(be==="code"||be==="errors")&&i&&!t&&Le(ae??"pcb")},[i]),tt.jsx("div",{className:Gv("flex flex-col relative rf-overflow-x-hidden",x),children:tt.jsx("div",{className:Gv("rf-md:sticky rf-md:top-2",Oe&&"rf-fixed rf-top-0 rf-left-0 rf-w-full rf-bg-white"),children:tt.jsxs(fFe,{value:be,onValueChange:Le,className:"rf-flex-grow rf-flex rf-flex-col",children:[tt.jsxs("div",{className:Gv("rf-flex rf-items-center rf-gap-2 rf-p-2 rf-pb-0",M),children:[w,w&&tt.jsx("div",{className:"rf-flex-grow"}),!w&&X&&tt.jsx(Hte,{className:"rf-w-4 rf-h-4 rf-animate-spin"}),!w&&tt.jsx("div",{className:"rf-flex-grow"}),v&&v.progress!==1&&tt.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[v.lastRenderEvent&&tt.jsx("div",{className:"rf-text-xs rf-text-gray-500",children:(je=v.lastRenderEvent)==null?void 0:je.type.split("renderable:renderLifecycle:")[1].split(":")[0]}),tt.jsx("div",{className:"rf-w-4 rf-h-4 rf-bg-blue-500 rf-opacity-50 rf-rounded-full rf-text-white",children:tt.jsx(Hte,{className:"rf-w-4 rf-h-4 rf-animate-spin"})}),tt.jsxs("div",{className:"rf-text-xs rf-font-bold rf-text-gray-700 rf-tabular-nums",children:[((v.progress??0)*100).toFixed(1),"%"]})]}),o&&tt.jsxs(Moe,{children:[s&&tt.jsx(Qw,{value:"code",children:"Code"}),tt.jsxs(Qw,{value:"pcb",className:"rf-whitespace-nowrap",children:[i&&tt.jsx("span",{className:Gv("rf-inline-flex rf-items-center rf-justify-center rf-w-2 rf-h-2 rf-mr-1 rf-text-xs rf-font-bold rf-text-white rf-rounded-full",$?"rf-bg-gray-500":"rf-bg-blue-500")}),"PCB"]}),tt.jsxs(Qw,{value:"schematic",className:"rf-whitespace-nowrap",children:[i&&tt.jsx("span",{className:Gv("rf-inline-flex rf-items-center rf-justify-center rf-w-2 rf-h-2 rf-mr-1 rf-text-xs rf-font-bold rf-text-white rf-rounded-full",$?"rf-bg-gray-500":"rf-bg-blue-500")}),"Schematic"]}),tt.jsxs(Qw,{value:"cad",children:[i&&tt.jsx("span",{className:Gv("inline-flex items-center justify-center w-2 h-2 mr-1 text-xs font-bold text-white rounded-full",$?"rf-bg-gray-500":"rf-bg-blue-500")}),"3D"]}),!["pcb","cad","schematic"].includes(be)&&tt.jsx(Qw,{value:be,children:Toe(be)}),tt.jsxs(One,{children:[tt.jsx(Une,{asChild:!0,children:tt.jsxs("div",{className:"rf-whitespace-nowrap rf-p-2 rf-mr-1 rf-cursor-pointer rf-relative",children:[tt.jsx(u6t,{className:"rf-w-4 rf-h-4"}),t&&tt.jsx("span",{className:"rf-inline-flex rf-absolute rf-top-[6px] rf-right-[4px] rf-items-center rf-justify-center rf-w-1 rf-h-1 rf-ml-2 rf-text-[8px] rf-font-bold rf-text-white rf-bg-red-500 rf-rounded-full"})]})}),tt.jsxs(HU,{className:"rf-*:text-xs",children:[UOt.map(Ue=>tt.jsxs(X8,{onSelect:()=>Le(Ue),children:[be!==Ue&&tt.jsx(MRe,{className:"rf-w-3 rf-h-3 rf-opacity-30"}),be===Ue&&tt.jsx(TRe,{className:"rf-w-3 rf-h-3"}),tt.jsx("div",{className:"rf-pr-2",children:Toe(Ue)}),Ue==="errors"&&t&&tt.jsx("span",{className:"rf-inline-flex rf-items-center rf-justify-center rf-w-3 rf-h-3 rf-ml-2 rf-text-[8px] rf-font-bold rf-text-white rf-bg-red-500 rf-rounded-full",children:"1"})]},Ue)),tt.jsx(X8,{disabled:!0,className:"rf-opacity-60 rf-cursor-default rf-select-none",children:tt.jsxs("div",{className:"rf-pr-2 rf-text-xs rf-text-gray-500",children:["@tscircuit/runframe@",OOt.split(".").map((Ue,Ve)=>Ve===2?parseInt(Ue)+1:Ue).join(".")]})})]})]})]}),me&&tt.jsx(KS,{onClick:Te,variant:"ghost",children:Oe?tt.jsx(d6t,{size:16}):tt.jsx(f6t,{size:16})})]}),s&&tt.jsx(Db,{value:"code",className:"rf-flex-grow rf-overflow-hidden",children:tt.jsx("div",{className:"rf-h-full",children:l})}),tt.jsx(Db,{value:"pcb",children:tt.jsx("div",{className:Gv("rf-overflow-hidden",Oe?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:tt.jsx(F8,{fallbackRender:({error:Ue})=>tt.jsx("div",{className:"rf-mt-4 rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200",children:tt.jsxs("div",{className:"rf-p-4",children:[tt.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-3",children:"Error loading PCB viewer"}),tt.jsx("p",{className:"rf-text-xs rf-font-mono rf-whitespace-pre-wrap rf-text-red-600 rf-mt-2",children:(Ue==null?void 0:Ue.message)||"An unknown error occurred"})]})}),children:i?tt.jsx(AOt,{disableAutoFocus:!0,focusOnHover:!1,circuitJson:i,debugGraphics:a,containerClassName:Gv("rf-h-full rf-w-full",Oe?"rf-min-h-[calc(100vh-240px)]":"rf-min-h-[620px]"),onEditEventsChanged:Ue=>{Q&&Ue.forEach(Ve=>Q(Ve))}},n):tt.jsx(zw,{onRunClicked:e})})})}),tt.jsx(Db,{value:"assembly",children:tt.jsx("div",{className:Gv("rf-overflow-auto",Oe?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:tt.jsx(F8,{fallback:tt.jsx("div",{children:"Error loading Assembly"}),children:i?tt.jsx(wOt,{circuitJson:i,containerStyle:{height:"100%"},editingEnabled:!0,debugGrid:!0}):tt.jsx(zw,{onRunClicked:e})})})}),tt.jsx(Db,{value:"schematic",children:tt.jsx("div",{className:Gv("rf-overflow-auto",Oe?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:tt.jsx(F8,{fallbackRender:({error:Ue})=>tt.jsx("div",{className:"rf-mt-4 rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200",children:tt.jsxs("div",{className:"rf-p-4",children:[tt.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-3",children:"Error loading Schematic"}),tt.jsx("p",{className:"rf-text-xs rf-font-mono rf-whitespace-pre-wrap rf-text-red-600 rf-mt-2",children:(Ue==null?void 0:Ue.message)||"An unknown error occurred"})]})}),children:i?tt.jsx(bOt,{circuitJson:i,containerStyle:{height:"100%"},editingEnabled:!0,onEditEvent:Ue=>Q==null?void 0:Q(Ue),editEvents:ee,debugGrid:pe}):tt.jsx(zw,{onRunClicked:e})})})}),tt.jsx(Db,{value:"cad",children:tt.jsx("div",{className:Gv("rf-overflow-auto",Oe?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:tt.jsx(F8,{FallbackComponent:Z8t,children:i?tt.jsx(U4t,{soup:i,autoRotateDisabled:K}):tt.jsx(zw,{onRunClicked:e})})})}),tt.jsx(Db,{value:"bom",children:tt.jsx("div",{className:Gv("rf-overflow-auto",Oe?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:tt.jsx(F8,{fallbackRender:({error:Ue})=>tt.jsx("div",{className:"rf-mt-4 rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200",children:tt.jsxs("div",{className:"rf-p-4",children:[tt.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-3",children:"Error loading Bill of Materials"}),tt.jsx("p",{className:"rf-text-xs rf-font-mono rf-whitespace-pre-wrap rf-text-red-600 rf-mt-2",children:(Ue==null?void 0:Ue.message)||"An unknown error occurred"})]})}),children:i?tt.jsx(ROt,{circuitJson:i}):tt.jsx(zw,{onRunClicked:e})})})}),tt.jsx(Db,{value:"circuit_json",children:tt.jsx("div",{className:Gv("rf-overflow-auto",Oe?"rf-h-[calc(100vh-96px)]":"rf-h-[620px]"),children:tt.jsx(F8,{fallback:tt.jsx("div",{children:"Error loading JSON viewer"}),children:i?tt.jsx(MOt,{elements:i}):tt.jsx(zw,{onRunClicked:e})})})}),tt.jsx(Db,{value:"errors",children:i||t?tt.jsx(aRt,{code:r,errorMessage:t,autoroutingLog:O,onReportAutoroutingLog:B}):tt.jsx(zw,{onRunClicked:e})}),u&&tt.jsx(Db,{value:"render_log",children:tt.jsx(LOt,{renderLog:v})})]})})})},Jre={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},eie=new Map,Yz=r=>{const e=eie.get(r);return e?Object.fromEntries(Object.entries(e.stores).map(([t,n])=>[t,n.getState()])):{}},IOt=(r,e,t)=>{if(r===void 0)return{type:"untracked",connection:e.connect(t)};const n=eie.get(t.name);if(n)return{type:"tracked",store:r,...n};const i={connection:e.connect(t),stores:{}};return eie.set(t.name,i),{type:"tracked",store:r,...i}},kOt=(r,e={})=>(t,n,i)=>{const{enabled:a,anonymousActionType:o,store:s,...l}=e;let c;try{c=(a??(Jre?"production":void 0)!=="production")&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!c)return(Jre?"production":void 0)!=="production"&&a&&console.warn("[zustand devtools middleware] Please install/enable Redux devtools extension"),r(t,n,i);const{connection:u,...f}=IOt(s,c,l);let v=!0;i.setState=(M,w,T)=>{const L=t(M,w);if(!v)return L;const O=T===void 0?{type:o||"anonymous"}:typeof T=="string"?{type:T}:T;return s===void 0?(u==null||u.send(O,n()),L):(u==null||u.send({...O,type:`${s}/${O.type}`},{...Yz(l.name),[s]:i.getState()}),L)};const _=(...M)=>{const w=v;v=!1,t(...M),v=w},x=r(i.setState,n,i);if(f.type==="untracked"?u==null||u.init(x):(f.stores[f.store]=i,u==null||u.init(Object.fromEntries(Object.entries(f.stores).map(([M,w])=>[M,M===f.store?x:w.getState()])))),i.dispatchFromDevtools&&typeof i.dispatch=="function"){let M=!1;const w=i.dispatch;i.dispatch=(...T)=>{(Jre?"production":void 0)!=="production"&&T[0].type==="__setState"&&!M&&(console.warn('[zustand devtools middleware] "__setState" action type is reserved to set state from the devtools. Avoid using it.'),M=!0),w(...T)}}return u.subscribe(M=>{var w;switch(M.type){case"ACTION":if(typeof M.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return tie(M.payload,T=>{if(T.type==="__setState"){if(s===void 0){_(T.state);return}Object.keys(T.state).length!==1&&console.error(`
13359
13359
  [zustand devtools middleware] Unsupported __setState action format.
13360
13360
  When using 'store' option in devtools(), the 'state' should have only one key, which is a value of 'store' that was passed in devtools(),
13361
13361
  and value of this only key should be a state object. Example: { "type": "__setState", "state": { "abc123Store": { "foo": "bar" } } }