@tscircuit/runframe 0.0.2406 → 0.0.2408

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.
@@ -2183,7 +2183,7 @@ var usePostHogActivity = (properties) => {
2183
2183
  };
2184
2184
 
2185
2185
  // package.json
2186
- var version = "0.0.2405";
2186
+ var version = "0.0.2407";
2187
2187
  var package_default = {
2188
2188
  name: "@tscircuit/runframe",
2189
2189
  main: "dist/preview.js",
@@ -2294,13 +2294,13 @@ var package_default = {
2294
2294
  "tailwind-merge": "^2.6.0",
2295
2295
  tailwindcss: "^3.4.17",
2296
2296
  "tailwindcss-animate": "^1.0.7",
2297
- tscircuit: "^0.0.2269",
2297
+ tscircuit: "^0.0.2272",
2298
2298
  tsup: "^8.3.5",
2299
2299
  vite: "^7.1.2",
2300
2300
  yargs: "^17.7.2"
2301
2301
  },
2302
2302
  dependencies: {
2303
- "@tscircuit/eval": "^0.0.1161",
2303
+ "@tscircuit/eval": "^0.0.1162",
2304
2304
  "@tscircuit/solver-utils": "^0.0.7",
2305
2305
  debug: "^4.4.0"
2306
2306
  }
package/dist/preview.js CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  SchematicViewer,
8
8
  useOrderDialog,
9
9
  useOrderDialogCli
10
- } from "./chunk-STXN7U6E.js";
10
+ } from "./chunk-LCXG2GCS.js";
11
11
  export {
12
12
  BomTable,
13
13
  CadViewer,
package/dist/runner.js CHANGED
@@ -39,7 +39,7 @@ import {
39
39
  useRunFrameStore,
40
40
  useRunnerStore,
41
41
  useStyles
42
- } from "./chunk-STXN7U6E.js";
42
+ } from "./chunk-LCXG2GCS.js";
43
43
 
44
44
  // lib/components/RunFrame/RunFrame.tsx
45
45
  import { createCircuitWebWorker } from "@tscircuit/eval/worker";
@@ -5197,10 +5197,10 @@ orientation: ${n.orientation}
5197
5197
  moving: ${e}`}),t.points.push({x:n.anchor.x,y:n.anchor.y,color:o,label:`candidate anchor
5198
5198
  ${n.status}`})}return t}},yx=.2,une=1e-9,rro="GND",o6=(t,e)=>Math.abs(t.x-e.x)<=une&&Math.abs(t.y-e.y)<=une,oT=t=>{const e=[];for(const n of t){const o=e.at(-1);(!o||!o6(o,n))&&e.push(n)}return e},dne=t=>{let e=0;for(let n=0;n<t.length-1;n++){const o=t[n],i=t[n+1];e+=Math.abs(i.x-o.x)+Math.abs(i.y-o.y)}return e},Sxe=({pin:t,facingDirection:e})=>{const n={x:t.x,y:t.y};return e==="x+"&&(n.x+=yx),e==="x-"&&(n.x-=yx),e==="y+"&&(n.y+=yx),e==="y-"&&(n.y-=yx),n},TCt=t=>({minX:Math.min(...t.map(e=>e.minX)),minY:Math.min(...t.map(e=>e.minY)),maxX:Math.max(...t.map(e=>e.maxX)),maxY:Math.max(...t.map(e=>e.maxY))}),sro=({connectionPair:t,obstacles:e})=>{const[n,o]=t.pins,i=Sxe({pin:n,facingDirection:n._facingDirection}),r=Sxe({pin:o,facingDirection:o._facingDirection}),s=TCt(e),a=[s.minY-yx,s.maxY+yx],A=[s.minX-yx,s.maxX+yx],c=[];for(const l of a)c.push(oT([n,i,{x:i.x,y:l},{x:r.x,y:l},r,o]));for(const l of A)c.push(oT([n,i,{x:l,y:i.y},{x:l,y:r.y},r,o]));return c.sort((l,g)=>dne(l)-dne(g))},aro=(t,e)=>({x:(t.x+e.x)/2,y:(t.y+e.y)/2}),Aro=t=>{const e=[];for(const n of t){for(let i=0;i<n.tracePath.length-1;i++){const r=n.tracePath[i],s=n.tracePath[i+1];e.push(r),e.push(aro(r,s))}const o=n.tracePath.at(-1);o&&e.push(o)}return e},cro=({connectionPair:t,sameNetTraces:e})=>{const n=new Set(e.flatMap(o=>o.pinIds));return t.pins.filter(o=>!n.has(o.pinId))},lro=({connectionPair:t,sameNetTraces:e,obstacles:n,maxConnectionDistance:o})=>{const i=TCt(n),r=[i.minY-yx,i.maxY+yx],s=[i.minX-yx,i.maxX+yx],a=[],A=Aro(e),c=cro({connectionPair:t,sameNetTraces:e});for(const l of c){const g=Sxe({pin:l,facingDirection:l._facingDirection});for(const u of A)if(!(Jl(l,u)>o)){a.push(oT([l,g,{x:g.x,y:u.y},u])),a.push(oT([l,g,{x:u.x,y:g.y},u]));for(const h of r)a.push(oT([l,g,{x:g.x,y:h},{x:u.x,y:h},u]));for(const h of s)a.push(oT([l,g,{x:h,y:g.y},{x:h,y:u.y},u]))}}return a.sort((l,g)=>dne(l)-dne(g))},gro=({path:t,obstacles:e,connectionPair:n,rejectComponentBoundaryTravel:o})=>{const i=t[0],r=t.at(-1),s=n.pins.find(u=>o6(u,i)),a=n.pins.find(u=>o6(u,r)),A=s!==void 0&&a!==void 0,c=e.find(u=>u.kind==="chip"&&u.chipId===s?.chipId),l=e.find(u=>u.kind==="chip"&&u.chipId===a?.chipId);return o&&c&&nxe(t[0],t[1],c)||o&&l&&nxe(t[t.length-2],t[t.length-1],l)?!0:mK(t,e,{excludeRectsForSegment:u=>{const h=new Set;return u===0&&c&&h.add(c),A&&u===t.length-2&&l&&h.add(l),h}})!==null},uro=({connectionPair:t,failedConnectionPairs:e})=>{const n=new Set(t.pins.map(o=>o.chipId));return e.some(o=>o.mspPairId===t.mspPairId?!1:o.pins.every(i=>n.has(i.chipId)))},dro=({firstStart:t,firstEnd:e,secondStart:n,secondEnd:o})=>Rp(t,e)&&Rp(n,o)?Math.min(Math.max(t.x,e.x),Math.max(n.x,o.x))-Math.max(Math.min(t.x,e.x),Math.min(n.x,o.x))>une:Mm(t,e)&&Mm(n,o)?Math.min(Math.max(t.y,e.y),Math.max(n.y,o.y))-Math.max(Math.min(t.y,e.y),Math.min(n.y,o.y))>une:!1,hro=({connectionPair:t,existingTrace:e})=>{const n=new Set(e.pinIds);return t.pins.filter(o=>n.has(o.pinId))},_ro=({path:t,connectionPair:e,existingTraces:n})=>{for(const o of n){if(o.globalConnNetId===e.globalConnNetId)continue;const i=hro({connectionPair:e,existingTrace:o});for(let r=0;r<t.length-1;r++){const s=t[r],a=t[r+1];for(let A=0;A<o.tracePath.length-1;A++){const c=o.tracePath[A],l=o.tracePath[A+1];if(!(!VC(s,a,c,l)||i.some(u=>(o6(s,u)||o6(a,u))&&(o6(c,u)||o6(l,u)))&&!dro({firstStart:s,firstEnd:a,secondStart:c,secondEnd:l})))return!0}}}return!1},pro=class extends r0{constructor(t){super(),this.params=t,this.inputProblem=t.inputProblem,this.alreadySolvedTraces=t.alreadySolvedTraces,this.failedConnectionPairs=t.failedConnectionPairs,this.queuedConnectionPairs=[...t.failedConnectionPairs],this.maxConnectionDistance=this.inputProblem.maxMspPairDistance??_ft;const{netConnMap:e}=Kte(this.inputProblem);this.groundGlobalConnNetId=e.getNetConnectedToId(rro)??void 0}params;inputProblem;alreadySolvedTraces;failedConnectionPairs;queuedConnectionPairs;maxConnectionDistance;groundGlobalConnNetId;solvedUnroutedTraces=[];getConstructorParams(){return this.params}_step(){const t=this.queuedConnectionPairs.shift();if(!t){this.solved=!0;return}if(t.globalConnNetId===this.groundGlobalConnNetId||Jl(t.pins[0],t.pins[1])>this.maxConnectionDistance)return;const e=px(this.inputProblem),n=[...this.alreadySolvedTraces,...this.solvedUnroutedTraces],o=n.filter(A=>A.globalConnNetId===t.globalConnNetId),i=lro({connectionPair:t,sameNetTraces:o,obstacles:e,maxConnectionDistance:this.maxConnectionDistance}),r=sro({connectionPair:t,obstacles:e}),s=[...i,...r],a=uro({connectionPair:t,failedConnectionPairs:this.failedConnectionPairs});for(const A of s)if(!gro({path:A,obstacles:e,connectionPair:t,rejectComponentBoundaryTravel:a})&&!_ro({path:A,connectionPair:t,existingTraces:n})){this.solvedUnroutedTraces.push({...t,tracePath:A,mspConnectionPairIds:[t.mspPairId],pinIds:t.pins.map(c=>c.pinId)});return}}getOutput(){return{newTraces:this.solvedUnroutedTraces,allTracesMerged:[...this.alreadySolvedTraces,...this.solvedUnroutedTraces]}}visualize(){const t=Ed(this.inputProblem);for(const e of this.solvedUnroutedTraces)t.lines.push({points:e.tracePath,strokeColor:"blue"});return t}},hne=1e-6,kCt=({path:t,netLabelPlacements:e})=>{for(const n of e){const o=tl(n.center,n.width,n.height);for(let i=0;i<t.length-1;i++)if(U4(t[i],t[i+1],o))return!0}return!1},mro=({path:t,netLabelPlacements:e})=>{for(const n of e){const o=tl(n.center,n.width,n.height),i={minX:o.minX+hne,minY:o.minY+hne,maxX:o.maxX-hne,maxY:o.maxY-hne};for(let r=0;r<t.length-1;r++)if(U4(t[r],t[r+1],i))return!0}return!1},Iro=.2,fro=.2,Cro=({donorTrace:t,branchTrace:e})=>{const n=new Set(e.pins.map(o=>o.pinId));return t.pins.find(o=>n.has(o.pinId))??null},FCt=({trace:t,sharedPin:e})=>t.pins.find(n=>n.pinId!==e.pinId)??null,_ne=t=>{let e=null;for(let n=0;n<t.tracePath.length-1;n++){const o=t.tracePath[n],i=t.tracePath[n+1];cxe(o,i)&&(!e||Math.abs(i.x-o.x)>Math.abs(e.end.x-e.start.x))&&(e={start:o,end:i})}return e},yro=({segment:t,sharedPin:e})=>{const n=Math.abs(t.start.x-e.x),o=Math.abs(t.end.x-e.x);return n<=o?t.start:t.end},Ero=({railY:t,pin:e})=>e._facingDirection==="y+"?t>e.y:!1,xro=({donorTrace:t,branchTrace:e})=>{const n=Cro({donorTrace:t,branchTrace:e});if(!n)return null;const o=FCt({trace:t,sharedPin:n});if(!o)return null;const i=FCt({trace:e,sharedPin:n});if(!i||Math.abs(n.y-i.y)>Iro)return null;const r=_ne(t);if(!r)return null;const s=_ne(e);if(s&&Ix(s.start.y,r.start.y)||!Ero({railY:r.start.y,pin:i}))return null;const a=yro({segment:r,sharedPin:n});if(!(o.x<a.x&&i.x>a.x||o.x>a.x&&i.x<a.x))return null;const c=L_([{x:n.x,y:n.y},{x:a.x,y:n.y},{x:a.x,y:a.y},{x:i.x,y:a.y},{x:i.x,y:i.y}]);return e.pins[0].pinId===n.pinId?c:[...c].reverse()},Bro=({candidateTrace:t,originalTrace:e,traces:n,inputProblem:o,netLabelPlacements:i})=>{const r=px(o);if(IK(t.tracePath,r))return!1;const s=n.filter(g=>g.globalConnNetId!==t.globalConnNetId);if(Wte(t.tracePath,s))return!1;const a=i.filter(g=>g.globalConnNetId!==t.globalConnNetId);if(kCt({path:t.tracePath,netLabelPlacements:a}))return!1;const A=i.filter(g=>g.globalConnNetId===t.globalConnNetId);if(!kCt({path:t.tracePath,netLabelPlacements:A}))return!0;if(mro({path:t.tracePath,netLabelPlacements:A}))return!1;const c=_ne(e),l=_ne(t);return!c||!l?!1:Math.abs(c.start.y-l.start.y)<=fro},Qro=({inputProblem:t,traces:e,netLabelPlacements:n})=>{let o=[...e];const i=new Set;let r=0;for(const s of e.map(a=>a.mspPairId)){const a=o.find(A=>A.mspPairId===s);for(const A of o){if(i.has(A.mspPairId)||a.mspPairId===A.mspPairId||a.globalConnNetId!==A.globalConnNetId)continue;const c=xro({donorTrace:a,branchTrace:A});if(!c)continue;const l={...A,tracePath:c},g=[a,A],u=[a,l],h=lxe(u)<lxe(g),d=tT(u)<tT(g)&&!Ix(tT(u),tT(g));!h&&!d||Bro({candidateTrace:l,originalTrace:A,traces:o,inputProblem:t,netLabelPlacements:n})&&(o=o.map(_=>_.mspPairId===A.mspPairId?l:_),i.add(A.mspPairId),r++)}}return{traces:o,alignedJunctionCount:r}},Sro=class extends r0{input;outputTraces;constructor(t){super(),this.input=t,this.outputTraces=t.traces}_step(){const t=Qro(this.input);this.outputTraces=t.traces,this.stats.alignedJunctionCount=t.alignedJunctionCount,this.solved=!0}getOutput(){return{traces:this.outputTraces,netLabelPlacements:this.input.netLabelPlacements}}visualize(){const t=Ed(this.input.inputProblem);t.lines??=[],t.rects??=[],t.points??=[];for(const e of this.outputTraces)t.lines.push({points:e.tracePath,strokeColor:"purple"});for(const e of this.input.netLabelPlacements){const n={center:e.center,width:e.width,height:e.height,fill:vA(e.globalConnNetId,.35),strokeColor:vA(e.globalConnNetId,.9),label:`netId: ${e.netId}
5199
5199
  globalConnNetId: ${e.globalConnNetId}`};t.rects.push(n),t.points.push({x:e.anchorPoint.x,y:e.anchorPoint.y,color:vA(e.globalConnNetId,.9),label:`anchorPoint
5200
- orientation: ${e.orientation}`})}return t}},LCt=t=>{const e=L_(t);if(e.length!==6)return!1;const n=e.slice(0,-1).map((o,i)=>Rp(o,e[i+1]));return n.every((o,i)=>i===0||o!==n[i-1])},bro=({trace:t,label:e,paddingBuffer:n,detourCount:o})=>{if(t.globalConnNetId===e.globalConnNetId)return[];const i=L_(t.tracePath);if(!LCt(i))return[];const r=tl(e.center,e.width,e.height),s=n+o*n,a={minX:r.minX-s,maxX:r.maxX+s,minY:r.minY-s,maxY:r.maxY+s},A=[];for(let c=1;c<i.length-2;c++){const l=i[c],g=i[c+1];if(!bS(l,g,r))continue;const u=Rp(l,g),h=Mm(l,g);if(!u&&!h)continue;const d=u?"y":"x",_=u?[a.minY,a.maxY]:[a.minX,a.maxX];for(const p of _){const m=oxe(i,c,d,p);m&&A.push(m)}}return A},Dro=({trace:t,label:e,paddingBuffer:n,detourCount:o})=>{const i=L_(t.tracePath);if(!LCt(i))return[];const r=tl(e.center,e.width,e.height),s=n+o*n,a={minX:r.minX-s,maxX:r.maxX+s,minY:r.minY-s,maxY:r.maxY+s},A=i[0],c=i[i.length-1],l=2,g=[];for(let u=0;u<i.length-1;u++){const h=i[u],d=i[u+1];if(!bS(h,d,r)||Math.abs(u-l)!==1)continue;const _=Rp(h,d),p=Mm(h,d);if(!_&&!p)continue;const m=_?"x":"y",I=_?a.minX:a.minY,f=_?a.maxX:a.maxY,C=_?A.x:A.y,y=_?c.x:c.y,E=[];C<I?E.push((C+I)/2):C>f&&E.push((C+f)/2),y<I?E.push((y+I)/2):y>f&&E.push((y+f)/2);for(const B of new Set(E)){const Q=oxe(i,l,m,B);Q&&g.push(Q)}}return g},vro=({trace:t,label:e,netLabelPlacements:n,paddingBuffer:o,detourCount:i})=>Dro({trace:t,label:e,paddingBuffer:o,detourCount:i}).flatMap(s=>{const a={...t,tracePath:s};return eh({traces:[a],netLabels:n}).flatMap(({label:c})=>bro({trace:a,label:c,paddingBuffer:o,detourCount:i}))}),HCt=1e-9,iT=t=>t.slice(1).reduce((e,n,o)=>{const i=t[o];return e+Math.abs(n.x-i.x)+Math.abs(n.y-i.y)},0),bxe=class extends r0{input;outputTraces;traceIdQueue;obstacles;constructor(t){super(),this.input=t,this.outputTraces=[...t.traces];const e=new Set(t.completedReroutes.map(n=>n.initialTrace.mspPairId));this.traceIdQueue=t.traces.map(n=>n.mspPairId).filter(n=>e.has(n)),this.obstacles=px(t.inputProblem)}_step(){const t=this.traceIdQueue.shift();if(!t){this.solved=!0;return}const e=this.outputTraces.findIndex(h=>h.mspPairId===t),n=this.outputTraces[e],o=L_(n.tracePath),i=eh({traces:[{...n,tracePath:o}],netLabels:this.input.netLabelPlacements}),r=this.outputTraces.filter(h=>h.mspPairId!==n.mspPairId&&h.globalConnNetId!==n.globalConnNetId),s=new Map,a=this.input.completedReroutes.filter(h=>h.initialTrace.mspPairId===n.mspPairId);for(const h of a){const d=L_(h.initialTrace.tracePath),_=L_(h.reroutedTracePath),p=eh({traces:[{...h.initialTrace,tracePath:d}],netLabels:this.input.netLabelPlacements}).length,m=vro({trace:h.initialTrace,label:h.label,netLabelPlacements:this.input.netLabelPlacements,paddingBuffer:this.input.paddingBuffer,detourCount:h.detourCount});for(const I of m){const f=L_(I),C={...h.initialTrace,tracePath:f};eh({traces:[C],netLabels:this.input.netLabelPlacements}).length<p&&Math.abs(iT(f)-iT(_))<HCt&&f.length<_.length&&hxe(this.input.netLabelPlacements,[h.initialTrace],[C])&&s.set(f.map(B=>`${B.x},${B.y}`).join(";"),f)}}const A=new Set(i.map(({label:h})=>`${h.globalConnNetId}:${h.netId}`)),c=iT(o),l=[...s.values()].filter(h=>{const d={...n,tracePath:h},_=eh({traces:[d],netLabels:this.input.netLabelPlacements}),p=_.every(({label:f})=>A.has(`${f.globalConnNetId}:${f.netId}`)),m=_.length<i.length,I=_.length===i.length&&iT(h)<=c+HCt&&h.length<o.length;return p&&(m||I)&&hxe(this.input.netLabelPlacements,[n],[d])&&!IK(h,this.obstacles)&&!Wte(h,r)}),g=h=>eh({traces:[{...n,tracePath:h}],netLabels:this.input.netLabelPlacements}).length;l.sort((h,d)=>{const _=g(h)-g(d);return _!==0?_:iT(h)-iT(d)||h.length-d.length});const u=l[0];u&&(this.outputTraces[e]={...n,tracePath:u},this.stats.simplifiedTraceCount=(this.stats.simplifiedTraceCount??0)+1)}getOutput(){return{traces:this.outputTraces,netLabelPlacements:this.input.netLabelPlacements}}visualize(){const t=Ed(this.input.inputProblem);t.lines??=[];for(const e of this.outputTraces)t.lines.push({points:e.tracePath,strokeColor:"purple"});return t}},Pro=(t,e=1e-6)=>{const n=[];let o=null,i=null,r=0;const s=a=>{if(o&&i){const A=Math.abs(i==="x"?a.x-o.x:a.y-o.y);A>e&&n.push({start:o,end:a,axis:i,length:A})}o=null,i=null,r=0};for(let a=0;a<t.length-1;a++){const A=t[a],c=t[a+1],l=c.x-A.x,g=c.y-A.y;if(Math.abs(l)<=e&&Math.abs(g)<=e)continue;const u=Math.abs(g)<=e?"x":Math.abs(l)<=e?"y":null;if(!u){s(A);continue}const h=Math.sign(u==="x"?l:g);o&&i===u&&r===h||(s(A),o=A,i=u,r=h)}return t.length>=2&&s(t[t.length-1]),n.sort((a,A)=>A.length-a.length)},GCt=.18,Mro=.05,wro=.5,OCt=t=>[...t].sort().join("::"),Nro=class extends r0{inputProblem;traces;inputNetLabelPlacements;inlineNetLabelPlacements=[];queuedDirectConnections;tracesByPinPairKey;constructor(t){super(),this.inputProblem=t.inputProblem,this.traces=t.traces,this.inputNetLabelPlacements=t.netLabelPlacements,this.queuedDirectConnections=this.inputProblem.directConnections.filter(e=>e.allowInlineNetLabel&&e.netId),this.tracesByPinPairKey=new Map;for(const e of this.traces){const n=OCt(e.pins.map(i=>i.pinId)),o=this.tracesByPinPairKey.get(n);o?o.push(e):this.tracesByPinPairKey.set(n,[e])}}getConstructorParams(){return[{inputProblem:this.inputProblem,traces:this.traces,netLabelPlacements:this.inputNetLabelPlacements}]}_step(){const t=this.queuedDirectConnections.shift();if(!t){this.solved=!0,this.stats.inlineNetLabelCount=this.inlineNetLabelPlacements.length;return}const e=this.computeInlinePlacement(t);e&&this.inlineNetLabelPlacements.push(e)}computeInlinePlacement(t){const e=this.tracesByPinPairKey.get(OCt(t.pinIds))??[];if(e.length===0)return null;const n=e[0],o=Pro(n.tracePath);if(o.length===0)return null;const i=t.inlineNetLabelHeight??GCt,r=t.inlineNetLabelWidth??t.netLabelWidth??Rro(t.netId,i),s=i/2+Mro,a=o.filter(A=>A.length>=r*wro).sort((A,c)=>{const l=A.length>=r,g=c.length>=r;return l!==g?l?-1:1:c.length-A.length});for(const A of a){const c=A.axis==="x"?["y+","y-"]:["x-","x+"];for(const l of c)for(const g of Tro(A,r)){const u=l==="y+"?{x:g.x,y:g.y+s}:l==="y-"?{x:g.x,y:g.y-s}:l==="x-"?{x:g.x-s,y:g.y}:{x:g.x+s,y:g.y},h=r/2,d=i/2,_=A.axis==="x"?{minX:u.x-h,maxX:u.x+h,minY:u.y-d,maxY:u.y+d}:{minX:u.x-d,maxX:u.x+d,minY:u.y-h,maxY:u.y+h};if(!this.isObstructed(_,n))return{globalConnNetId:n.globalConnNetId,netId:t.netId,mspPairId:n.mspPairId,pinIds:[...t.pinIds],axis:A.axis,anchorPoint:g,center:u,width:r,height:i,side:l}}}return null}isObstructed(t,e){for(const n of this.inputProblem.chips){const o={minX:n.center.x-n.width/2,maxX:n.center.x+n.width/2,minY:n.center.y-n.height/2,maxY:n.center.y+n.height/2};if(Yte(t,o))return!0}for(const n of this.inputProblem.textBoxes??[])if(Yte(t,Ute(n)))return!0;for(const n of this.traces)if(n.mspPairId!==e.mspPairId&&n.globalConnNetId!==e.globalConnNetId&&kro(n.tracePath,t))return!0;return!1}getSupersededNetLabelKeys(){const t=new Set;for(const e of this.inlineNetLabelPlacements)t.add(e.globalConnNetId);return t}getOutput(){const t=this.getSupersededNetLabelKeys();return{traces:this.traces,netLabelPlacements:this.inputNetLabelPlacements.filter(e=>!t.has(e.globalConnNetId)),inlineNetLabelPlacements:this.inlineNetLabelPlacements}}visualize(){const t=Ed(this.inputProblem);t.lines??=[],t.rects??=[],t.points??=[],t.texts??=[];for(const n of this.traces)t.lines.push({points:n.tracePath,strokeColor:"purple"});const{netLabelPlacements:e}=this.getOutput();for(const n of e)t.rects.push({center:n.center,width:n.width,height:n.height,fill:vA(n.globalConnNetId,.35),strokeColor:vA(n.globalConnNetId,.9),label:`netId: ${n.netId}
5200
+ orientation: ${e.orientation}`})}return t}},LCt=t=>{const e=L_(t);if(e.length!==6)return!1;const n=e.slice(0,-1).map((o,i)=>Rp(o,e[i+1]));return n.every((o,i)=>i===0||o!==n[i-1])},bro=({trace:t,label:e,paddingBuffer:n,detourCount:o})=>{if(t.globalConnNetId===e.globalConnNetId)return[];const i=L_(t.tracePath);if(!LCt(i))return[];const r=tl(e.center,e.width,e.height),s=n+o*n,a={minX:r.minX-s,maxX:r.maxX+s,minY:r.minY-s,maxY:r.maxY+s},A=[];for(let c=1;c<i.length-2;c++){const l=i[c],g=i[c+1];if(!bS(l,g,r))continue;const u=Rp(l,g),h=Mm(l,g);if(!u&&!h)continue;const d=u?"y":"x",_=u?[a.minY,a.maxY]:[a.minX,a.maxX];for(const p of _){const m=oxe(i,c,d,p);m&&A.push(m)}}return A},Dro=({trace:t,label:e,paddingBuffer:n,detourCount:o})=>{const i=L_(t.tracePath);if(!LCt(i))return[];const r=tl(e.center,e.width,e.height),s=n+o*n,a={minX:r.minX-s,maxX:r.maxX+s,minY:r.minY-s,maxY:r.maxY+s},A=i[0],c=i[i.length-1],l=2,g=[];for(let u=0;u<i.length-1;u++){const h=i[u],d=i[u+1];if(!bS(h,d,r)||Math.abs(u-l)!==1)continue;const _=Rp(h,d),p=Mm(h,d);if(!_&&!p)continue;const m=_?"x":"y",I=_?a.minX:a.minY,f=_?a.maxX:a.maxY,C=_?A.x:A.y,y=_?c.x:c.y,E=[];C<I?E.push((C+I)/2):C>f&&E.push((C+f)/2),y<I?E.push((y+I)/2):y>f&&E.push((y+f)/2);for(const B of new Set(E)){const Q=oxe(i,l,m,B);Q&&g.push(Q)}}return g},vro=({trace:t,label:e,netLabelPlacements:n,paddingBuffer:o,detourCount:i})=>Dro({trace:t,label:e,paddingBuffer:o,detourCount:i}).flatMap(s=>{const a={...t,tracePath:s};return eh({traces:[a],netLabels:n}).flatMap(({label:c})=>bro({trace:a,label:c,paddingBuffer:o,detourCount:i}))}),HCt=1e-9,iT=t=>t.slice(1).reduce((e,n,o)=>{const i=t[o];return e+Math.abs(n.x-i.x)+Math.abs(n.y-i.y)},0),bxe=class extends r0{input;outputTraces;traceIdQueue;obstacles;constructor(t){super(),this.input=t,this.outputTraces=[...t.traces];const e=new Set(t.completedReroutes.map(n=>n.initialTrace.mspPairId));this.traceIdQueue=t.traces.map(n=>n.mspPairId).filter(n=>e.has(n)),this.obstacles=px(t.inputProblem)}_step(){const t=this.traceIdQueue.shift();if(!t){this.solved=!0;return}const e=this.outputTraces.findIndex(h=>h.mspPairId===t),n=this.outputTraces[e],o=L_(n.tracePath),i=eh({traces:[{...n,tracePath:o}],netLabels:this.input.netLabelPlacements}),r=this.outputTraces.filter(h=>h.mspPairId!==n.mspPairId&&h.globalConnNetId!==n.globalConnNetId),s=new Map,a=this.input.completedReroutes.filter(h=>h.initialTrace.mspPairId===n.mspPairId);for(const h of a){const d=L_(h.initialTrace.tracePath),_=L_(h.reroutedTracePath),p=eh({traces:[{...h.initialTrace,tracePath:d}],netLabels:this.input.netLabelPlacements}).length,m=vro({trace:h.initialTrace,label:h.label,netLabelPlacements:this.input.netLabelPlacements,paddingBuffer:this.input.paddingBuffer,detourCount:h.detourCount});for(const I of m){const f=L_(I),C={...h.initialTrace,tracePath:f};eh({traces:[C],netLabels:this.input.netLabelPlacements}).length<p&&Math.abs(iT(f)-iT(_))<HCt&&f.length<_.length&&hxe(this.input.netLabelPlacements,[h.initialTrace],[C])&&s.set(f.map(B=>`${B.x},${B.y}`).join(";"),f)}}const A=new Set(i.map(({label:h})=>`${h.globalConnNetId}:${h.netId}`)),c=iT(o),l=[...s.values()].filter(h=>{const d={...n,tracePath:h},_=eh({traces:[d],netLabels:this.input.netLabelPlacements}),p=_.every(({label:f})=>A.has(`${f.globalConnNetId}:${f.netId}`)),m=_.length<i.length,I=_.length===i.length&&iT(h)<=c+HCt&&h.length<o.length;return p&&(m||I)&&hxe(this.input.netLabelPlacements,[n],[d])&&!IK(h,this.obstacles)&&!Wte(h,r)}),g=h=>eh({traces:[{...n,tracePath:h}],netLabels:this.input.netLabelPlacements}).length;l.sort((h,d)=>{const _=g(h)-g(d);return _!==0?_:iT(h)-iT(d)||h.length-d.length});const u=l[0];u&&(this.outputTraces[e]={...n,tracePath:u},this.stats.simplifiedTraceCount=(this.stats.simplifiedTraceCount??0)+1)}getOutput(){return{traces:this.outputTraces,netLabelPlacements:this.input.netLabelPlacements}}visualize(){const t=Ed(this.input.inputProblem);t.lines??=[];for(const e of this.outputTraces)t.lines.push({points:e.tracePath,strokeColor:"purple"});return t}},Pro=(t,e=1e-6)=>{const n=[];let o=null,i=null,r=0;const s=a=>{if(o&&i){const A=Math.abs(i==="x"?a.x-o.x:a.y-o.y);A>e&&n.push({start:o,end:a,axis:i,length:A})}o=null,i=null,r=0};for(let a=0;a<t.length-1;a++){const A=t[a],c=t[a+1],l=c.x-A.x,g=c.y-A.y;if(Math.abs(l)<=e&&Math.abs(g)<=e)continue;const u=Math.abs(g)<=e?"x":Math.abs(l)<=e?"y":null;if(!u){s(A);continue}const h=Math.sign(u==="x"?l:g);o&&i===u&&r===h||(s(A),o=A,i=u,r=h)}return t.length>=2&&s(t[t.length-1]),n.sort((a,A)=>A.length-a.length)},GCt=.18,Mro=.05,wro=.4,OCt=t=>[...t].sort().join("::"),Nro=class extends r0{inputProblem;traces;inputNetLabelPlacements;inlineNetLabelPlacements=[];queuedDirectConnections;tracesByPinPairKey;constructor(t){super(),this.inputProblem=t.inputProblem,this.traces=t.traces,this.inputNetLabelPlacements=t.netLabelPlacements,this.queuedDirectConnections=this.inputProblem.directConnections.filter(e=>e.allowInlineNetLabel&&e.netId),this.tracesByPinPairKey=new Map;for(const e of this.traces){const n=OCt(e.pins.map(i=>i.pinId)),o=this.tracesByPinPairKey.get(n);o?o.push(e):this.tracesByPinPairKey.set(n,[e])}}getConstructorParams(){return[{inputProblem:this.inputProblem,traces:this.traces,netLabelPlacements:this.inputNetLabelPlacements}]}_step(){const t=this.queuedDirectConnections.shift();if(!t){this.solved=!0,this.stats.inlineNetLabelCount=this.inlineNetLabelPlacements.length;return}const e=this.computeInlinePlacement(t);e&&this.inlineNetLabelPlacements.push(e)}computeInlinePlacement(t){const e=this.tracesByPinPairKey.get(OCt(t.pinIds))??[];if(e.length===0)return null;const n=e[0],o=Pro(n.tracePath);if(o.length===0)return null;const i=t.inlineNetLabelHeight??GCt,r=t.inlineNetLabelWidth??t.netLabelWidth??Rro(t.netId,i),s=i/2+Mro,a=o.filter(c=>c.length>=r).sort((c,l)=>l.length-c.length);for(const c of a){const l=c.axis==="x"?["y+","y-"]:["x-","x+"];for(const g of l)for(const u of Tro(c,r)){const h=g==="y+"?{x:u.x,y:u.y+s}:g==="y-"?{x:u.x,y:u.y-s}:g==="x-"?{x:u.x-s,y:u.y}:{x:u.x+s,y:u.y},d=r/2,_=i/2,p=c.axis==="x"?{minX:h.x-d,maxX:h.x+d,minY:h.y-_,maxY:h.y+_}:{minX:h.x-_,maxX:h.x+_,minY:h.y-d,maxY:h.y+d};if(!this.isObstructed(p,n))return{globalConnNetId:n.globalConnNetId,netId:t.netId,mspPairId:n.mspPairId,pinIds:[...t.pinIds],axis:c.axis,anchorPoint:u,center:h,width:r,height:i,side:g}}}const A=this.computeSpanPlacement({trace:n,directConnection:t,width:r,height:i,offset:s});return A||null}computeSpanPlacement({trace:t,directConnection:e,width:n,height:o,offset:i}){const r=t.tracePath;if(r.length<2)return null;let s=1/0,a=-1/0,A=1/0,c=-1/0;for(const y of r)s=Math.min(s,y.x),a=Math.max(a,y.x),A=Math.min(A,y.y),c=Math.max(c,y.y);const l=a-s,g=c-A,u=l>=g?"x":"y",h=u==="x"?l:g;if((u==="x"?g:l)>wro||h<n)return null;const m=((u==="x"?s:A)+(u==="x"?a:c))/2,I=(h-n)/2,f=[0];for(let y=.1;y<=I+1e-9;y+=.1)f.push(y,-y);f.push(I,-I);const C=u==="x"?["y+","y-"]:["x-","x+"];for(const y of C)for(const E of f){const B=m+E,Q=y==="y+"?{x:B,y:c+i}:y==="y-"?{x:B,y:A-i}:y==="x-"?{x:s-i,y:B}:{x:a+i,y:B},b=n/2,D=o/2,T=u==="x"?{minX:Q.x-b,maxX:Q.x+b,minY:Q.y-D,maxY:Q.y+D}:{minX:Q.x-D,maxX:Q.x+D,minY:Q.y-b,maxY:Q.y+b};if(this.isObstructed(T,t))continue;const N=u==="x"?{x:B,y:y==="y+"?c:A}:{x:y==="x-"?s:a,y:B};return{globalConnNetId:t.globalConnNetId,netId:e.netId,mspPairId:t.mspPairId,pinIds:[...e.pinIds],axis:u,anchorPoint:N,center:Q,width:n,height:o,side:y}}return null}isObstructed(t,e){for(const n of this.inputProblem.chips){const o={minX:n.center.x-n.width/2,maxX:n.center.x+n.width/2,minY:n.center.y-n.height/2,maxY:n.center.y+n.height/2};if(Yte(t,o))return!0}for(const n of this.inputProblem.textBoxes??[])if(Yte(t,Ute(n)))return!0;for(const n of this.traces)if(n.mspPairId!==e.mspPairId&&n.globalConnNetId!==e.globalConnNetId&&kro(n.tracePath,t))return!0;return!1}getSupersededNetLabelKeys(){const t=new Set;for(const e of this.inlineNetLabelPlacements)t.add(e.globalConnNetId);return t}getOutput(){const t=this.getSupersededNetLabelKeys();return{traces:this.traces,netLabelPlacements:this.inputNetLabelPlacements.filter(e=>!t.has(e.globalConnNetId)),inlineNetLabelPlacements:this.inlineNetLabelPlacements}}visualize(){const t=Ed(this.inputProblem);t.lines??=[],t.rects??=[],t.points??=[],t.texts??=[];for(const n of this.traces)t.lines.push({points:n.tracePath,strokeColor:"purple"});const{netLabelPlacements:e}=this.getOutput();for(const n of e)t.rects.push({center:n.center,width:n.width,height:n.height,fill:vA(n.globalConnNetId,.35),strokeColor:vA(n.globalConnNetId,.9),label:`netId: ${n.netId}
5201
5201
  globalConnNetId: ${n.globalConnNetId}`}),t.points.push({x:n.anchorPoint.x,y:n.anchorPoint.y,color:vA(n.globalConnNetId,.9),label:`anchorPoint
5202
5202
  orientation: ${n.orientation}`});for(const n of this.inlineNetLabelPlacements){const o=n.axis==="x";t.rects.push({center:n.center,width:o?n.width:n.height,height:o?n.height:n.width,fill:vA(n.globalConnNetId,.35),strokeColor:"green",label:[`INLINE netId: ${n.netId}`,`axis: ${n.axis}`,`side: ${n.side}`].join(`
5203
- `)}),t.texts.push({x:n.center.x,y:n.center.y,text:n.netId??"",color:"green",fontSize:n.height,anchorSide:"center"}),t.points.push({x:n.anchorPoint.x,y:n.anchorPoint.y,color:"green",label:`inline anchor
5203
+ `)}),t.texts.push({x:n.center.x,y:n.center.y,text:n.netId??"",color:"green",fontSize:n.height,anchorSide:"center",rotation:n.axis==="y"?90:void 0}),t.points.push({x:n.anchorPoint.x,y:n.anchorPoint.y,color:"green",label:`inline anchor
5204
5204
  ${n.netId}`})}return t}},Rro=(t,e=GCt)=>{const n=e/.18;return t.length*.12*n+.12*n},Tro=(t,e,n=.1)=>{const o=t.axis==="x"?"x":"y",i=t.start[o],r=t.end[o],s=(i+r)/2,a=Math.sign(r-i)||1,A=g=>t.axis==="x"?{x:g,y:t.start.y}:{x:t.start.x,y:t.start.y+(g-i)},c=t.length-e;if(c<=0)return[A(s)];const l=[0];for(let g=n;g<=c/2+1e-9;g+=n)l.push(g,-g);return l.push(c/2,-c/2),l.map(g=>A(s+g*a))},kro=(t,e)=>{for(let n=0;n<t.length-1;n++){const o=t[n],i=t[n+1],r={minX:Math.min(o.x,i.x),maxX:Math.max(o.x,i.x),minY:Math.min(o.y,i.y),maxY:Math.max(o.y,i.y)};if(Yte(r,e))return!0}return!1};function xd(t,e,n,o={}){return{solverName:t,solverClass:e,getConstructorParams:n,onSolved:o.onSolved,shouldSkip:o.shouldSkip}}var KCt=class extends r0{mspConnectionPairSolver;schematicTraceLinesSolver;longDistancePairSolver;unroutedTraceRecoverySolver;traceOverlapShiftSolver;netLabelPlacementSolver;labelMergingSolver;traceLabelOverlapAvoidanceSolver;traceCleanupSolver;example28Solver;availableNetOrientationSolver;postLabelTraceOverlapShiftSolver;railNetLabelCornerPlacementSolver;traceAnchoredNetLabelOverlapSolver;preAlignmentNetLabelTraceCollisionSolver;netLabelTraceCollisionSolver;traceCleanupSolver2;netLabelNetLabelCollisionSolver;traceElbowTransitionSimplificationSolver;preAlignmentTraceElbowTransitionSimplificationSolver;finalTraceElbowTransitionSimplificationSolver;sameNetJunctionAlignmentSolver;inlineNetLabelSolver;startTimeOfPhase;endTimeOfPhase;timeSpentOnPhase;firstIterationOfPhase;inputProblem;hideRatsNet;pipelineDef=[xd("mspConnectionPairSolver",bto,()=>[{inputProblem:this.inputProblem}],{onSolved:t=>{}}),xd("schematicTraceLinesSolver",Oto,()=>[{mspConnectionPairs:this.mspConnectionPairSolver.mspConnectionPairs,dcConnMap:this.mspConnectionPairSolver.dcConnMap,globalConnMap:this.mspConnectionPairSolver.globalConnMap,inputProblem:this.inputProblem,chipMap:this.mspConnectionPairSolver.chipMap}]),xd("longDistancePairSolver",Ino,t=>[{inputProblem:t.inputProblem,primaryMspConnectionPairs:t.mspConnectionPairSolver.mspConnectionPairs,alreadySolvedTraces:t.schematicTraceLinesSolver.solvedTracePaths,failedConnectionPairs:t.schematicTraceLinesSolver.failedConnectionPairs}],{onSolved:t=>{}}),xd("unroutedTraceRecoverySolver",pro,t=>[{inputProblem:t.inputProblem,failedConnectionPairs:t.schematicTraceLinesSolver.failedConnectionPairs,alreadySolvedTraces:t.longDistancePairSolver.getOutput().allTracesMerged}]),xd("traceOverlapShiftSolver",bft,()=>[{inputProblem:this.inputProblem,inputTracePaths:this.unroutedTraceRecoverySolver?.getOutput().allTracesMerged,globalConnMap:this.mspConnectionPairSolver.globalConnMap}],{onSolved:t=>{}}),xd("netLabelPlacementSolver",Mft,()=>[{inputProblem:this.inputProblem,inputTraceMap:this.traceOverlapShiftSolver?.correctedTraceMap??Object.fromEntries(this.unroutedTraceRecoverySolver.getOutput().allTracesMerged.map(t=>[t.mspPairId,t]))}],{onSolved:t=>{}}),xd("traceLabelOverlapAvoidanceSolver",uno,t=>{const e=t.traceOverlapShiftSolver?.correctedTraceMap??Object.fromEntries(t.unroutedTraceRecoverySolver.getOutput().allTracesMerged.map(i=>[i.mspPairId,i])),n=Object.values(e),o=t.netLabelPlacementSolver.netLabelPlacements;return[{inputProblem:t.inputProblem,traces:n,netLabelPlacements:o}]}),xd("traceElbowTransitionSimplificationSolver",bxe,t=>{const e=t.traceLabelOverlapAvoidanceSolver.getOutput();return[{inputProblem:t.inputProblem,traces:e.traces,completedReroutes:e.completedReroutes,netLabelPlacements:t.traceLabelOverlapAvoidanceSolver.netLabelPlacements,paddingBuffer:.1}]}),xd("traceCleanupSolver",sCt,t=>{const n=t.traceElbowTransitionSimplificationSolver.getOutput().traces,o=t.traceLabelOverlapAvoidanceSolver.labelMergingSolver.getOutput();return[{inputProblem:t.inputProblem,allTraces:n,allLabelPlacements:o.netLabelPlacements,mergedLabelNetIdMap:o.mergedLabelNetIdMap,paddingBuffer:.1}]}),xd("netLabelPlacementSolver",Mft,t=>{const e=t.traceCleanupSolver?.getOutput().traces??t.traceLabelOverlapAvoidanceSolver.getOutput().traces;return[{inputProblem:t.inputProblem,inputTraceMap:Object.fromEntries(e.map(n=>[n.mspPairId,n]))}]}),xd("example28Solver",Goo,t=>{const e=t.traceCleanupSolver?.getOutput().traces??t.traceLabelOverlapAvoidanceSolver.getOutput().traces;return[{inputProblem:t.inputProblem,traces:e,netLabelPlacements:t.netLabelPlacementSolver.netLabelPlacements}]}),xd("availableNetOrientationSolver",eio,t=>[{inputProblem:t.inputProblem,traces:t.example28Solver.outputTraces,netLabelPlacements:t.example28Solver.outputNetLabelPlacements}]),xd("postLabelTraceOverlapShiftSolver",bft,t=>[{inputProblem:t.inputProblem,inputTracePaths:t.availableNetOrientationSolver.traces,globalConnMap:t.mspConnectionPairSolver.globalConnMap,traceIdsToShift:new Set(t.availableNetOrientationSolver.traces.filter(e=>e.mspPairId.startsWith("available-net-orientation-")).map(e=>e.mspPairId))}]),xd("railNetLabelCornerPlacementSolver",Aio,t=>[{inputProblem:t.inputProblem,traces:Object.values(t.postLabelTraceOverlapShiftSolver.correctedTraceMap),netLabelPlacements:t.availableNetOrientationSolver.outputNetLabelPlacements}]),xd("traceAnchoredNetLabelOverlapSolver",Vio,t=>[{inputProblem:t.inputProblem,traces:t.railNetLabelCornerPlacementSolver.getOutput().traces,netLabelPlacements:t.railNetLabelCornerPlacementSolver.outputNetLabelPlacements}]),xd("preAlignmentNetLabelTraceCollisionSolver",MCt,t=>[{inputProblem:t.inputProblem,traces:t.railNetLabelCornerPlacementSolver.getOutput().traces,netLabelPlacements:t.traceAnchoredNetLabelOverlapSolver.outputNetLabelPlacements}]),xd("preAlignmentTraceElbowTransitionSimplificationSolver",bxe,t=>{const e=t.preAlignmentNetLabelTraceCollisionSolver.getOutput();return[{inputProblem:t.inputProblem,traces:e.traces,completedReroutes:e.completedReroutes,netLabelPlacements:e.netLabelPlacements,paddingBuffer:.1}]}),xd("traceCleanupSolver2",sCt,t=>{const e=t.preAlignmentTraceElbowTransitionSimplificationSolver.getOutput(),n=t.traceLabelOverlapAvoidanceSolver.labelMergingSolver.getOutput();return[{inputProblem:t.inputProblem,allTraces:e.traces,allLabelPlacements:e.netLabelPlacements,mergedLabelNetIdMap:n.mergedLabelNetIdMap,paddingBuffer:.1,operations:["aligning_same_net_rails"],eligibleTraceIds:new Set(t.traceCleanupSolver.getOutput().traces.map(o=>o.mspPairId))}]}),xd("netLabelTraceCollisionSolver",MCt,t=>{const e=t.preAlignmentNetLabelTraceCollisionSolver.getOutput(),n=t.traceCleanupSolver2.getOutput(),o=new Map(e.traces.map(r=>[r.mspPairId,r]));let i=e.netLabelPlacements;for(const r of n.traces){const s=o.get(r.mspPairId);if(!s||s.tracePath===r.tracePath)continue;const a=i;i=Cxe({trace:s,originalTracePath:s.tracePath,reroutedTracePath:r.tracePath,netLabelPlacements:a}).map((c,l)=>{const g=a[l];return g.orientation==="y+"||g.orientation==="y-"?c:g})}return[{inputProblem:t.inputProblem,traces:n.traces,netLabelPlacements:i}]}),xd("finalTraceElbowTransitionSimplificationSolver",bxe,t=>{const e=t.netLabelTraceCollisionSolver.getOutput();return[{inputProblem:t.inputProblem,traces:e.traces,completedReroutes:e.completedReroutes,netLabelPlacements:e.netLabelPlacements,paddingBuffer:.1}]}),xd("netLabelNetLabelCollisionSolver",iro,t=>{const e=t.finalTraceElbowTransitionSimplificationSolver.getOutput();return[{inputProblem:t.inputProblem,traces:e.traces,netLabelPlacements:e.netLabelPlacements}]}),xd("sameNetJunctionAlignmentSolver",Sro,t=>{const e=t.netLabelNetLabelCollisionSolver.getOutput();return[{inputProblem:t.inputProblem,traces:t.netLabelNetLabelCollisionSolver.traces,netLabelPlacements:e.netLabelPlacements}]}),xd("inlineNetLabelSolver",Nro,t=>{const e=t.sameNetJunctionAlignmentSolver.getOutput();return[{inputProblem:t.inputProblem,traces:e.traces,netLabelPlacements:e.netLabelPlacements}]})];constructor(t,e){super(),this.hideRatsNet=e?.hideRatsNet??!1,this.inputProblem=this.cloneAndCorrectInputProblem(t),this.MAX_ITERATIONS=1e6,this.startTimeOfPhase={},this.endTimeOfPhase={},this.timeSpentOnPhase={},this.firstIterationOfPhase={}}getConstructorParams(){return[this.inputProblem,{hideRatsNet:this.hideRatsNet}]}currentPipelineStepIndex=0;cloneAndCorrectInputProblem(t){const e=structuredClone({...t,_chipObstacleSpatialIndex:void 0,_hideRatsNet:this.hideRatsNet});return hno(e),dno(e),e}_step(){const t=this.pipelineDef[this.currentPipelineStepIndex];if(!t){this.solved=!0;return}if(this.activeSubSolver){this.activeSubSolver.step(),this.activeSubSolver.solved?(this.endTimeOfPhase[t.solverName]=performance.now(),this.timeSpentOnPhase[t.solverName]=this.endTimeOfPhase[t.solverName]-this.startTimeOfPhase[t.solverName],t.onSolved?.(this),this.activeSubSolver=null,this.currentPipelineStepIndex++):this.activeSubSolver.failed&&(this.error=this.activeSubSolver?.error,this.failed=!0,this.activeSubSolver=null);return}const e=t.getConstructorParams(this);this.activeSubSolver=new t.solverClass(...e),this[t.solverName]=this.activeSubSolver,this.timeSpentOnPhase[t.solverName]=0,this.startTimeOfPhase[t.solverName]=performance.now(),this.firstIterationOfPhase[t.solverName]=this.iterations}solveUntilPhase(t){for(;this.getCurrentPhase().toLowerCase()!==t.toLowerCase();)this.step()}getCurrentPhase(){return this.pipelineDef[this.currentPipelineStepIndex]?.solverName??"none"}visualize(){if(!this.solved&&this.activeSubSolver)return this.activeSubSolver.visualize();const t=[Ed(this.inputProblem,{hideRatsNet:this.hideRatsNet}),...this.pipelineDef.map(n=>this[n.solverName]?.visualize()).filter(Boolean).map((n,o)=>{for(const i of n.rects??[])i.step=o;for(const i of n.points??[])i.step=o;for(const i of n.circles??[])i.step=o;for(const i of n.texts??[])i.step=o;for(const i of n.lines??[])i.step=o;return n})];if(t.length===1)return t[0];const e={points:t.flatMap(n=>n.points||[]),rects:t.flatMap(n=>n.rects||[]),lines:t.flatMap(n=>n.lines||[]),circles:t.flatMap(n=>n.circles||[]),texts:t.flatMap(n=>n.texts||[])};return jto(e,this.inputProblem),e}preview(){return this.activeSubSolver?this.activeSubSolver.preview():super.preview()}},UCt={flexGrow:0,flexShrink:1,flexBasis:0,alignSelf:"auto",width:void 0,height:void 0},YCt=class{id;metadata;size={width:0,height:0};position={x:0,y:0};style;constructor(t={}){this.style={...UCt,...t},this.id=t.id,this.metadata=t.metadata}},Fro=class extends YCt{build(){}},zCt=class mNe extends YCt{children=[];direction="row";columnGap=0;rowGap=0;justifyContent="flex-start";alignItems="stretch";constructor(e,n,o={}){super({}),this.size.width=e,this.size.height=n,this.id=o.id,Object.assign(this,o)}addChild(e,n){if(e instanceof mNe){const i=e;return n&&(i.style={...UCt,...n}),this.children.push(i),i}const o=new Fro(e);return this.children.push(o),o}build(){const e=this.direction.startsWith("row"),n=e?"width":"height",o=e?"height":"width",i=e?this.columnGap:this.rowGap;e?this.rowGap:this.columnGap;const r=i*Math.max(0,this.children.length-1),s=this.size[n],a=this.size[o];let A=0,c=0,l=0;for(const C of this.children)A+=C.style.flexBasis,c+=C.style.flexGrow,l+=C.style.flexShrink;const g=s-A-r;for(const C of this.children){let y=C.style.flexBasis;g>0&&c>0?y+=g*C.style.flexGrow/c:g<0&&l>0&&(y+=g*C.style.flexShrink/l,y<0&&(y=0)),C.size[n]=y;const E=C.style.alignSelf!=="auto"?C.style.alignSelf:this.alignItems,B=e?C.style.height:C.style.width;B!==void 0?C.size[o]=B:E==="stretch"&&(C.size[o]=a)}const u=this.children.reduce((C,y)=>C+y.size[n],0)+r,h=s-u;let d=0,_=i;const p=this.children.length;switch(this.justifyContent){case"flex-start":break;case"flex-end":d=h;break;case"center":d=h/2;break;case"space-between":_=p>1?i+h/(p-1):0;break;case"space-around":_=i+h/p,d=_/2;break;case"space-evenly":_=i+h/(p+1),d=_;break}const m=this.direction.endsWith("reverse")?[...this.children].reverse():this.children;let I=d;for(const C of m)e?(C.position.x=this.direction==="row"?I:s-I-C.size.width,C.position.y=f(C,o,a,this.alignItems)):(C.position.y=this.direction==="column"?I:s-I-C.size.height,C.position.x=f(C,o,a,this.alignItems)),I+=C.size[n]+_;for(const C of this.children)C instanceof mNe&&C.build();function f(C,y,E,B){switch(C.style.alignSelf!=="auto"?C.style.alignSelf:B){case"flex-start":return 0;case"flex-end":return E-C.size[y];case"center":return(E-C.size[y])/2;default:return 0}}}},VCt=class extends zCt{constructor(t,e,n={}){super(t,e,n)}getLayout(){this.build();const t={};return this._collectLayout(this,t),t}_collectLayout(t,e,n={counter:0}){for(const o of t.children){const i=o.id??`_$$${n.counter++}`;e[i]={position:o.position,size:o.size},o instanceof zCt&&this._collectLayout(o,e,n)}}},JCt=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20].map(t=>`hsl(${t*360/21}deg, 100%, 50%)`),Lro=t=>{let e=0;for(let n=0;n<t.length;n++)e=(e<<5)-e+t.charCodeAt(n);return e},qCt=t=>JCt[Math.abs(Lro(t))%JCt.length],Hro=t=>{const e=d=>d?typeof d=="string"?d:d.join(" "):void 0,n=["display:grid","background-color:gray"],{gridTemplateRows:o,gridTemplateColumns:i,gap:r,justifyItems:s,alignItems:a,containerWidth:A,containerHeight:c}=t.opts,l=e(o);l&&n.push(`grid-template-rows:${l}`);const g=e(i);if(g&&n.push(`grid-template-columns:${g}`),r!==void 0)if(typeof r=="number")n.push(`gap:${r}px`);else{const[d,_]=r;n.push(`row-gap:${d}px`,`column-gap:${_}px`)}s&&n.push(`justify-items:${s}`),a&&n.push(`align-items:${a}`),A!=null&&n.push(`width:${A}px`),c!=null&&n.push(`height:${c}px`);const u=n.join(";"),h=t.opts.children.map(d=>{const _=["display:flex",`background-color:${qCt(d.key)}`];if(d.area)_.push(`grid-area:${d.area}`);else{if(typeof d.row=="string"&&d.row.includes("/"))_.push(`grid-row:${d.row}`);else{const f=d.rowStart??d.row,C=d.rowEnd,y=d.rowSpan;f!==void 0||C!==void 0?f!==void 0&&C!==void 0?_.push(`grid-row:${f} / ${C}`):f!==void 0?y!==void 0?_.push(`grid-row:${f} / span ${y}`):_.push(`grid-row-start:${f}`):_.push(`grid-row-end:${C}`):y!==void 0&&_.push(`grid-row:auto / span ${y}`)}if(typeof d.column=="string"&&d.column.includes("/"))_.push(`grid-column:${d.column}`);else{const f=d.columnStart??d.column,C=d.columnEnd,y=d.columnSpan;f!==void 0||C!==void 0?f!==void 0&&C!==void 0?_.push(`grid-column:${f} / ${C}`):f!==void 0?y!==void 0?_.push(`grid-column:${f} / span ${y}`):_.push(`grid-column-start:${f}`):_.push(`grid-column-end:${C}`):y!==void 0&&_.push(`grid-column:auto / span ${y}`)}}const p=_.join(";"),m=["font-size: 7px"];if(d.contentWidth!==void 0){const f=typeof d.contentWidth=="string"?d.contentWidth:`${d.contentWidth}px`;m.push(`width:${f}`)}else m.push(`width:${d.key.length*5}px`);if(d.contentHeight!==void 0){const f=typeof d.contentHeight=="string"?d.contentHeight:`${d.contentHeight}px`;m.push(`height:${f}`)}const I=m.join(";");return` <div id="${d.key}" style="${p}"><div style="${I}">${d.key}</div></div>`});return`<div style="${u}">
5205
5205
  ${h.join(`
5206
5206
  `)}
@@ -5791,7 +5791,7 @@ test("${c} should solve problem correctly", () => {
5791
5791
  // Add more specific assertions based on expected output
5792
5792
  // expect(solver.netLabelPlacementSolver!.netLabelPlacements).toMatchInlineSnapshot()
5793
5793
  })
5794
- `,g=new Blob([l],{type:"text/plain"}),u=URL.createObjectURL(g),h=document.createElement("a");h.href=u,h.download=`${c}.test.ts`,h.click(),URL.revokeObjectURL(u)}catch(A){alert(`Error generating test.ts for ${t.constructor.name}: ${A instanceof Error?A.message:String(A)}`)}o(!1)};return j.jsxs("div",{className:`relative ${e}`,ref:i,children:[j.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>o(!n),title:`Download options for ${t.constructor.name}`,children:t.constructor.name}),n&&j.jsxs("div",{className:"absolute top-full left-0 mt-1 bg-white border border-gray-300 rounded shadow-lg z-10 min-w-[150px]",children:[j.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download JSON"}),j.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),j.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:a,children:"Download test.ts"})]})]})},NHt=t=>t.activeSubSolver?[t,...NHt(t.activeSubSolver)]:[t],qWo=({solver:t})=>{const e=NHt(t);return j.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:e.map((n,o)=>j.jsxs("div",{className:"flex items-center",children:[o>0&&j.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),j.jsx(JWo,{solver:n})]},n.constructor.name))})},WWo=({solver:t,triggerRender:e,animationSpeed:n=25,onSolverStarted:o,onSolverCompleted:i})=>{const[r,s]=ne.useReducer(_=>!_,!1),a=ne.useRef(void 0),A=()=>{!t.solved&&!t.failed&&(t.step(),e())},c=()=>{!t.solved&&!t.failed&&(o&&o(t),t.solve(),e(),i&&i(t))},l=()=>{r?(a.current&&(clearInterval(a.current),a.current=void 0),s()):(s(),a.current=setInterval(()=>{if(t.solved||t.failed){a.current&&(clearInterval(a.current),a.current=void 0),s(),e(),i&&t.solved&&i(t);return}t.step(),e()},n))},g=()=>{const _=t;if(_.getCurrentPhase&&!t.solved&&!t.failed){const p=_.getCurrentPhase();for(;_.getCurrentPhase()===p&&!t.solved&&!t.failed;)t.step();e()}},u=()=>{if(t.solved||t.failed||r)return;const _=window.prompt("Step until which iteration?",`${t.iterations}`);if(_===null)return;const p=Number(_);if(!Number.isFinite(p)){window.alert("Please enter a valid number for the iteration");return}for(;t.iterations<p&&!t.solved&&!t.failed;)t.step();e(),t.solved&&i&&i(t)};ne.useEffect(()=>()=>{a.current&&clearInterval(a.current)},[]),ne.useEffect(()=>{(t.solved||t.failed)&&r&&(a.current&&(clearInterval(a.current),a.current=void 0),s())},[t.solved,t.failed,r]);const h=t.getCurrentPhase!==void 0,d=h?t.getCurrentPhase():null;return j.jsxs("div",{className:"space-y-2 p-2 border-b",children:[j.jsx("div",{className:"flex items-center",children:j.jsx(qWo,{solver:t})}),j.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[j.jsx("button",{onClick:A,disabled:t.solved||t.failed||r,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),j.jsx("button",{onClick:c,disabled:t.solved||t.failed||r,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),j.jsx("button",{onClick:l,disabled:t.solved||t.failed,className:`px-3 py-1 rounded text-white text-sm ${r?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:r?"Stop":"Animate"}),j.jsx("button",{onClick:u,disabled:t.solved||t.failed||r,className:"bg-orange-500 hover:bg-orange-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step Until Iteration"}),h&&j.jsx("button",{onClick:g,disabled:t.solved||t.failed||r,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Next Stage"}),j.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&j.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),d&&j.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",j.jsx("span",{className:"font-medium",children:d})]}),t.solved&&j.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&j.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&j.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},jWo=(t,e,n)=>{const o=t.currentPipelineStepIndex;return e<o?"Completed":e===o&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},XWo=(t,e)=>{const o=t.pipelineDef[e].solverName,i=jWo(t,e),r=t[o],s=t.firstIterationOfPhase?.[o]??null,a=t.iterations;let A=0;if(i==="Completed"){const u=t.pipelineDef[e+1],h=u?t.firstIterationOfPhase?.[u.solverName]:void 0;h!==void 0&&s!==null?A=h-s:s!==null&&(A=a-s)}else i==="In Progress"&&s!==null&&(A=a-s);const c=t.timeSpentOnPhase?.[o]??0;let l=0;i==="Completed"?l=1:i==="In Progress"&&r&&(l=r.progress??0);const g=r?.stats??null;return{index:e,name:o,status:i,firstIteration:s,iterations:A,progress:l,timeSpent:c,stats:g&&Object.keys(g).length>0?g:null,solverInstance:r??null}},$Wo=({status:t})=>{const e={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return j.jsx("span",{className:`font-medium ${e[t]}`,children:t})},ZWo=({progress:t})=>{if(t===0)return null;const e=Math.round(t*100);return j.jsxs("div",{className:"flex items-center gap-2",children:[j.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:j.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${e}%`}})}),j.jsxs("span",{className:"text-xs text-gray-500",children:[e,"%"]})]})},ejo=t=>Object.entries(t).map(([e,n])=>`${e}: ${n}`).join(", "),tjo=({stats:t})=>{if(!t||Object.keys(t).length===0)return j.jsx("span",{children:"-"});const e=Object.entries(t),n=ejo(t);return j.jsxs("details",{className:"cursor-pointer",children:[j.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:n}),j.jsx("div",{className:"mt-1 text-xs",children:e.map(([o,i])=>j.jsxs("div",{children:[o,": ",String(i)]},o))})]})},_9e=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(_9e);const e={};for(const[n,o]of Object.entries(t))n.startsWith("_")||(e[n]=_9e(o));return e},njo=(t,e)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${e}`);return}const n=_9e(t.getConstructorParams()),o=new Blob([JSON.stringify(n,null,2)],{type:"application/json"}),i=URL.createObjectURL(o),r=document.createElement("a");r.href=i,r.download=`${e}_input.json`,r.click(),URL.revokeObjectURL(i)}catch(n){alert(`Error downloading input for ${e}: ${n instanceof Error?n.message:String(n)}`)}},ojo=({solver:t,onStepUntilPhase:e,onDownloadInput:n})=>{const o=t.pipelineDef.map((a,A)=>XWo(t,A)),i=a=>{e?.(a)},r=a=>{a.solverInstance&&(n?n(a.solverInstance,a.name):njo(a.solverInstance,a.name))},s=a=>`${(a/1e3).toFixed(2)}s`;return j.jsxs("div",{className:"border-t border-gray-200",children:[j.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:j.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),j.jsx("div",{className:"overflow-x-auto",children:j.jsxs("table",{className:"w-full text-sm",children:[j.jsx("thead",{children:j.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[j.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),j.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),j.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",j.jsx("sub",{children:"0"})]}),j.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),j.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),j.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),j.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),j.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),j.jsx("tbody",{children:o.map(a=>j.jsxs("tr",{className:`border-b border-gray-100 ${a.status==="In Progress"?"bg-yellow-50":""}`,children:[j.jsx("td",{className:"px-4 py-2",children:j.jsxs("div",{className:"flex items-center gap-2",children:[j.jsx("span",{className:"text-gray-400 w-6",children:String(a.index+1).padStart(2,"0")}),j.jsx("button",{onClick:()=>i(a.name),disabled:a.status==="Completed"||t.solved||t.failed,className:"text-blue-500 hover:text-blue-700 disabled:text-gray-300 disabled:cursor-not-allowed",title:`Step until ${a.name} completes`,children:j.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:j.jsx("path",{fillRule:"evenodd",d:"M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z",clipRule:"evenodd"})})}),j.jsx("span",{className:"font-medium text-gray-900",children:a.name})]})}),j.jsx("td",{className:"px-4 py-2",children:j.jsx($Wo,{status:a.status})}),j.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:a.firstIteration!==null?a.firstIteration:""}),j.jsx("td",{className:"px-4 py-2 text-gray-600",children:a.iterations}),j.jsx("td",{className:"px-4 py-2",children:j.jsx(ZWo,{progress:a.progress})}),j.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(a.timeSpent)}),j.jsx("td",{className:"px-4 py-2 text-gray-500",children:j.jsx(tjo,{stats:a.stats})}),j.jsx("td",{className:"px-4 py-2",children:a.solverInstance?j.jsxs("button",{onClick:()=>r(a),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${a.name}`,children:[j.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:j.jsx("path",{fillRule:"evenodd",d:"M12 2.25a.75.75 0 01.75.75v11.69l3.22-3.22a.75.75 0 111.06 1.06l-4.5 4.5a.75.75 0 01-1.06 0l-4.5-4.5a.75.75 0 111.06-1.06l3.22 3.22V3a.75.75 0 01.75-.75zm-9 13.5a.75.75 0 01.75.75v2.25a1.5 1.5 0 001.5 1.5h13.5a1.5 1.5 0 001.5-1.5V16.5a.75.75 0 011.5 0v2.25a3 3 0 01-3 3H5.25a3 3 0 01-3-3V16.5a.75.75 0 01.75-.75z",clipRule:"evenodd"})}),j.jsx("span",{children:"Input"})]}):null})]},a.name))})]})})]})},ijo=class extends es.Component{constructor(t){super(t),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(t){console.error("InteractiveGraphics render error:",t)}render(){return this.state.hasError?this.props.fallback:this.props.children}};function rjo({graphics:t}){const e=t.points??[],n=t.lines??[],o=t.rects??[],i=t.circles??[],r=t.texts??[];let s=Number.POSITIVE_INFINITY,a=Number.POSITIVE_INFINITY,A=Number.NEGATIVE_INFINITY,c=Number.NEGATIVE_INFINITY;const l=(p,m)=>{typeof p=="number"&&(p<s&&(s=p),p>A&&(A=p)),typeof m=="number"&&(m<a&&(a=m),m>c&&(c=m))};for(const p of e)l(p.x,p.y);for(const p of n){const m=p.points??[];for(const I of m)l(I.x,I.y)}for(const p of o){const m=p.x??0,I=p.y??0,f=p.width??0,C=p.height??0;l(m,I),l(m+f,I+C)}for(const p of i){const m=p.x??0,I=p.y??0,f=p.radius??1;l(m-f,I-f),l(m+f,I+f)}for(const p of r)l(p.x,p.y);(!isFinite(s)||!isFinite(a)||!isFinite(A)||!isFinite(c))&&(s=-20,a=-20,A=20,c=20);const g=10,u=s-g,h=a-g,d=Math.max(1,A-s+2*g),_=Math.max(1,c-a+2*g);return j.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${u} ${h} ${d} ${_}`,role:"img","aria-label":"Graphics fallback",children:[o.map((p,m)=>j.jsx("rect",{x:p.x??0,y:p.y??0,width:p.width??0,height:p.height??0,fill:"none",stroke:p.strokeColor??"black",strokeWidth:p.strokeWidth??1},`rect-${m}`)),n.map((p,m)=>j.jsx("polyline",{fill:"none",stroke:p.strokeColor??"black",strokeWidth:p.strokeWidth??1,points:(p.points??[]).map(I=>`${I.x??0},${I.y??0}`).join(" ")},`line-${m}`)),i.map((p,m)=>j.jsx("circle",{cx:p.x??0,cy:p.y??0,r:p.radius??1.5,fill:p.fillColor??"none",stroke:p.strokeColor??"black",strokeWidth:p.strokeWidth??1},`circle-${m}`)),e.map((p,m)=>j.jsx("circle",{cx:p.x??0,cy:p.y??0,r:p.radius??1.5,fill:p.color??"black"},`point-${m}`)),r.map((p,m)=>j.jsx("text",{x:p.x??0,y:p.y??0,fontSize:p.fontSize??10,fill:p.color??"black",children:p.text??""},`text-${m}`))]})}var sjo=({solver:t,animationSpeed:e=25,onSolverStarted:n,onSolverCompleted:o})=>{const[i,r]=ne.useReducer(l=>l+1,0),s=ne.useMemo(()=>{try{return t.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(l){return console.error("Visualization error:",l),{points:[],lines:[],rects:[],circles:[]}}},[t,i]),a=ne.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);ne.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const l=document.createElement("script");l.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(l)}},[]);const A=t.pipelineDef!==void 0,c=l=>{const g=t;if(!t.solved&&!t.failed){for(;!t.solved&&!t.failed&&g.currentPipelineStepIndex<=g.pipelineDef.findIndex(u=>u.solverName===l);)t.step();r()}};return j.jsxs("div",{children:[j.jsx(WWo,{solver:t,triggerRender:r,animationSpeed:e,onSolverStarted:n,onSolverCompleted:o}),a?j.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):j.jsx(ijo,{fallback:j.jsx(rjo,{graphics:s}),children:j.jsx(VWo,{graphics:s})}),A&&j.jsx(ojo,{solver:t,onStepUntilPhase:c})]})};const ajo=()=>{ne.useEffect(()=>{const t="tailwind-cdn-script";if(document.getElementById(t)||window.tailwind)return;const e=document.createElement("div");e.className="hidden",document.body.appendChild(e);const n=window.getComputedStyle(e).display==="none";if(document.body.removeChild(e),n)return;const o=document.createElement("script");o.id=t,o.src="https://cdn.tailwindcss.com",document.head.appendChild(o)},[])},Ajo=1e3,lb=(t,e)=>{const{fileName:n,mimeType:o="text/plain"}=e,i=t instanceof Blob?t:new Blob([t],{type:o}),r=URL.createObjectURL(i),s=document.createElement("a");s.href=r,s.download=n,s.target="_blank",s.rel="noopener noreferrer",s.style.display="none",document.body.appendChild(s),s.click(),document.body.removeChild(s),setTimeout(()=>{URL.revokeObjectURL(r)},Ajo)},RHt=t=>{let e=t.trim().replace(/[\\/:*?"<>|]/g,"_").replace(/[\x00-\x1f]/g,"").replace(/^\.+/,"").replace(/\.+$/,"").replace(/\s+/g," ").replace(/_+/g,"_");return/^(con|prn|aux|nul|com[0-9]|lpt[0-9])$/i.test(e)&&(e=`_${e}`),e=e.slice(0,200),e||"untitled"},gb="https://github.com/tscircuit/tscircuit-autorouter/issues/new",THt="https://github.com/tscircuit/copper-pour-solver/issues/new",kHt="https://github.com/tscircuit/calculate-packing/issues/new",cjo="https://github.com/tscircuit/matchpack/issues/new",FHt="https://github.com/tscircuit/schematic-trace-solver/issues/new?template=json-bug-report.yml",ljo={PackSolver2:kHt,LayoutPipelineSolver:cjo,AutoroutingPipelineSolver:gb,AssignableAutoroutingPipeline2:gb,AssignableAutoroutingPipeline3:gb,AutoroutingPipeline1_OriginalUnravel:gb,AutoroutingPipelineSolver3_HgPortPointPathing:gb,AutoroutingPipelineSolver4:gb,AutoroutingPipelineSolver5:gb,AutoroutingPipelineSolver7_MultiGraph:gb,AutoroutingPipelineSolver8:gb,CopperPourPipelineSolver:THt,SchematicTracePipelineSolver:FHt},gjo=t=>t.toLowerCase().includes("pack")?HLo:t.toLowerCase().includes("rout")?VLo:wLo,LHt=t=>{const e=ljo[t];if(e)return e;const n=t.toLowerCase();return n.includes("autorout")?gb:n.includes("schematic")&&n.includes("trace")?FHt:n.includes("copperpour")?THt:n.includes("pack")?kHt:null},ujo=t=>`${RHt(`${t.componentName}-${t.solverName}`)}-solver-input.json`,HHt=t=>{lb(JSON.stringify(t.solverParams,null,2),{fileName:ujo(t),mimeType:"application/json"})},djo=({solverEvent:t})=>{const e=LHt(t.solverName);return j.jsxs("div",{className:"rf-flex rf-items-center rf-justify-end rf-gap-2 rf-border-b rf-border-gray-200 rf-bg-gray-50 rf-px-4 rf-py-2",children:[j.jsxs(Mc,{type:"button",variant:"outline",size:"sm",onClick:()=>HHt(t),children:[j.jsx(o6e,{className:"rf-w-4 rf-h-4"}),"Download"]}),e?j.jsx(Mc,{asChild:!0,variant:"outline",size:"sm",children:j.jsxs("a",{href:e,target:"_blank",rel:"noopener noreferrer",children:[j.jsx(Qre,{className:"rf-w-4 rf-h-4"}),"Report"]})}):j.jsxs(Mc,{type:"button",variant:"outline",size:"sm",disabled:!0,title:"No report link configured for this solver",children:[j.jsx(Qre,{className:"rf-w-4 rf-h-4"}),"Report"]})]})},hjo=({solverEvent:t})=>{const e=LHt(t.solverName);return e?j.jsx(Mc,{asChild:!0,variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8",children:j.jsx("a",{href:e,target:"_blank",rel:"noopener noreferrer",title:"Report solver bug","aria-label":"Report solver bug",children:j.jsx(Qre,{className:"rf-w-4 rf-h-4"})})}):j.jsx(Mc,{type:"button",variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8",disabled:!0,title:"No report link configured for this solver","aria-label":"Report solver bug",children:j.jsx(Qre,{className:"rf-w-4 rf-h-4"})})},_jo=({solverEvents:t=[]})=>{const[e,n]=ne.useState(null);ajo();const o=ne.useMemo(()=>{const a=new Map;for(const A of t){const c=`${A.componentName}-${A.solverName}`;a.set(c,A)}return a},[t]),i=ne.useMemo(()=>Array.from(o.keys()),[o]),r=e?o.get(e):null,s=ne.useMemo(()=>{if(!r)return{instance:null,error:null,classFound:!1};const a=DBe[r.solverName];if(!a)return{instance:null,error:`Solver class "${r.solverName}" not found in SOLVERS registry. Available: ${Object.keys(DBe).join(", ")}`,classFound:!1};try{const A=r.solverParams,c=A?.input!==void 0?A.input:A;return{instance:new a(c),error:null,classFound:!0}}catch(A){const c=A instanceof Error?A.message:String(A);return console.error("Failed to reconstruct solver:",A),{instance:null,error:`Failed to instantiate solver: ${c}`,classFound:!0}}},[r]);return t.length===0?j.jsx("div",{className:"rf-p-4",children:j.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:j.jsxs("div",{className:"rf-p-4",children:[j.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),j.jsx("p",{className:"rf-text-sm rf-text-gray-600",children:"Solvers will appear here when the circuit runs. Solvers are used for tasks like component packing and autorouting."})]})})}):j.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[j.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[j.jsxs("div",{className:"rf-text-xs rf-font-semibold rf-text-gray-500 rf-px-3 rf-py-2 rf-bg-gray-50 rf-border-b rf-border-gray-200",children:[i.length," ",i.length===1?"Solver":"Solvers"]}),i.map(a=>{const A=o.get(a),c=e===a;return j.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${c?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>n(a),children:(()=>{const l=gjo(A.solverName);return j.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[j.jsx(l,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),j.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[j.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:A.componentName}),j.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:A.solverName})]})]})})()},a)})]}),j.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:r?s.instance?j.jsxs("div",{className:"rf-flex rf-h-full rf-flex-col rf-overflow-y-auto",children:[j.jsx(djo,{solverEvent:r}),j.jsx("div",{className:"rf-min-h-0 rf-flex-1",children:j.jsx(ZS,{fallback:j.jsx("div",{className:"rf-p-4",children:j.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[j.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),j.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",r.solverName]})]})}),children:j.jsx(sjo,{solver:s.instance})})})]}):j.jsxs("div",{className:"rf-p-4",children:[j.jsxs("div",{className:"rf-mb-4",children:[j.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:r.solverName}),j.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",r.componentName]})]}),s.error&&j.jsx("div",{className:`rf-rounded-md rf-border rf-p-4 rf-mb-4 ${s.classFound?"rf-bg-red-50 rf-border-red-200":"rf-bg-yellow-50 rf-border-yellow-200"}`,children:j.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),j.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[j.jsxs("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50 rf-flex rf-items-center rf-justify-between rf-gap-2",children:[j.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"}),j.jsxs("div",{className:"rf-flex rf-items-center rf-gap-1",children:[j.jsx(hjo,{solverEvent:r}),j.jsx(Mc,{type:"button",variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8","aria-label":"Download solver input JSON",title:"Download solver input JSON",onClick:()=>HHt(r),children:j.jsx(o6e,{className:"rf-w-4 rf-h-4"})})]})]}),j.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:j.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(r.solverParams,null,2)})})]})]}):j.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:j.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},GHt=({errorMessage:t,errorStack:e,circuitJsonErrors:n})=>{ne.useEffect(()=>{if(t){const o=new Error(t);e&&(o.stack=e);try{Y8.captureException(o)}catch{}}},[t,e]),ne.useEffect(()=>{if(n&&n.length>0)for(const o of n){const i=new Error(o.message||"Circuit JSON Error");o.stack&&(i.stack=o.stack);try{Y8.captureException(i,{error_type:o.type})}catch{}}},[n])},pjo=t=>{ne.useEffect(()=>{try{rWt(t)}catch{}},[t.source,t.component,t.isWebEmbedded,t.activeTab])},OHt="0.0.2405",mjo={version:OHt},p9e={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},m9e=new Map,Hse=t=>{const e=m9e.get(t);return e?Object.fromEntries(Object.entries(e.stores).map(([n,o])=>[n,o.getState()])):{}},Ijo=(t,e,n)=>{if(t===void 0)return{type:"untracked",connection:e.connect(n)};const o=m9e.get(n.name);if(o)return{type:"tracked",store:t,...o};const i={connection:e.connect(n),stores:{}};return m9e.set(n.name,i),{type:"tracked",store:t,...i}},KHt=(t,e={})=>(n,o,i)=>{const{enabled:r,anonymousActionType:s,store:a,...A}=e;let c;try{c=(r??(p9e?"production":void 0)!=="production")&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!c)return(p9e?"production":void 0)!=="production"&&r&&console.warn("[zustand devtools middleware] Please install/enable Redux devtools extension"),t(n,o,i);const{connection:l,...g}=Ijo(a,c,A);let u=!0;i.setState=(_,p,m)=>{const I=n(_,p);if(!u)return I;const f=m===void 0?{type:s||"anonymous"}:typeof m=="string"?{type:m}:m;return a===void 0?(l?.send(f,o()),I):(l?.send({...f,type:`${a}/${f.type}`},{...Hse(A.name),[a]:i.getState()}),I)};const h=(..._)=>{const p=u;u=!1,n(..._),u=p},d=t(i.setState,o,i);if(g.type==="untracked"?l?.init(d):(g.stores[g.store]=i,l?.init(Object.fromEntries(Object.entries(g.stores).map(([_,p])=>[_,_===g.store?d:p.getState()])))),i.dispatchFromDevtools&&typeof i.dispatch=="function"){let _=!1;const p=i.dispatch;i.dispatch=(...m)=>{(p9e?"production":void 0)!=="production"&&m[0].type==="__setState"&&!_&&(console.warn('[zustand devtools middleware] "__setState" action type is reserved to set state from the devtools. Avoid using it.'),_=!0),p(...m)}}return l.subscribe(_=>{var p;switch(_.type){case"ACTION":if(typeof _.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return I9e(_.payload,m=>{if(m.type==="__setState"){if(a===void 0){h(m.state);return}Object.keys(m.state).length!==1&&console.error(`
5794
+ `,g=new Blob([l],{type:"text/plain"}),u=URL.createObjectURL(g),h=document.createElement("a");h.href=u,h.download=`${c}.test.ts`,h.click(),URL.revokeObjectURL(u)}catch(A){alert(`Error generating test.ts for ${t.constructor.name}: ${A instanceof Error?A.message:String(A)}`)}o(!1)};return j.jsxs("div",{className:`relative ${e}`,ref:i,children:[j.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>o(!n),title:`Download options for ${t.constructor.name}`,children:t.constructor.name}),n&&j.jsxs("div",{className:"absolute top-full left-0 mt-1 bg-white border border-gray-300 rounded shadow-lg z-10 min-w-[150px]",children:[j.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download JSON"}),j.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),j.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:a,children:"Download test.ts"})]})]})},NHt=t=>t.activeSubSolver?[t,...NHt(t.activeSubSolver)]:[t],qWo=({solver:t})=>{const e=NHt(t);return j.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:e.map((n,o)=>j.jsxs("div",{className:"flex items-center",children:[o>0&&j.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),j.jsx(JWo,{solver:n})]},n.constructor.name))})},WWo=({solver:t,triggerRender:e,animationSpeed:n=25,onSolverStarted:o,onSolverCompleted:i})=>{const[r,s]=ne.useReducer(_=>!_,!1),a=ne.useRef(void 0),A=()=>{!t.solved&&!t.failed&&(t.step(),e())},c=()=>{!t.solved&&!t.failed&&(o&&o(t),t.solve(),e(),i&&i(t))},l=()=>{r?(a.current&&(clearInterval(a.current),a.current=void 0),s()):(s(),a.current=setInterval(()=>{if(t.solved||t.failed){a.current&&(clearInterval(a.current),a.current=void 0),s(),e(),i&&t.solved&&i(t);return}t.step(),e()},n))},g=()=>{const _=t;if(_.getCurrentPhase&&!t.solved&&!t.failed){const p=_.getCurrentPhase();for(;_.getCurrentPhase()===p&&!t.solved&&!t.failed;)t.step();e()}},u=()=>{if(t.solved||t.failed||r)return;const _=window.prompt("Step until which iteration?",`${t.iterations}`);if(_===null)return;const p=Number(_);if(!Number.isFinite(p)){window.alert("Please enter a valid number for the iteration");return}for(;t.iterations<p&&!t.solved&&!t.failed;)t.step();e(),t.solved&&i&&i(t)};ne.useEffect(()=>()=>{a.current&&clearInterval(a.current)},[]),ne.useEffect(()=>{(t.solved||t.failed)&&r&&(a.current&&(clearInterval(a.current),a.current=void 0),s())},[t.solved,t.failed,r]);const h=t.getCurrentPhase!==void 0,d=h?t.getCurrentPhase():null;return j.jsxs("div",{className:"space-y-2 p-2 border-b",children:[j.jsx("div",{className:"flex items-center",children:j.jsx(qWo,{solver:t})}),j.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[j.jsx("button",{onClick:A,disabled:t.solved||t.failed||r,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),j.jsx("button",{onClick:c,disabled:t.solved||t.failed||r,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),j.jsx("button",{onClick:l,disabled:t.solved||t.failed,className:`px-3 py-1 rounded text-white text-sm ${r?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:r?"Stop":"Animate"}),j.jsx("button",{onClick:u,disabled:t.solved||t.failed||r,className:"bg-orange-500 hover:bg-orange-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step Until Iteration"}),h&&j.jsx("button",{onClick:g,disabled:t.solved||t.failed||r,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Next Stage"}),j.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&j.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),d&&j.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",j.jsx("span",{className:"font-medium",children:d})]}),t.solved&&j.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&j.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&j.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},jWo=(t,e,n)=>{const o=t.currentPipelineStepIndex;return e<o?"Completed":e===o&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},XWo=(t,e)=>{const o=t.pipelineDef[e].solverName,i=jWo(t,e),r=t[o],s=t.firstIterationOfPhase?.[o]??null,a=t.iterations;let A=0;if(i==="Completed"){const u=t.pipelineDef[e+1],h=u?t.firstIterationOfPhase?.[u.solverName]:void 0;h!==void 0&&s!==null?A=h-s:s!==null&&(A=a-s)}else i==="In Progress"&&s!==null&&(A=a-s);const c=t.timeSpentOnPhase?.[o]??0;let l=0;i==="Completed"?l=1:i==="In Progress"&&r&&(l=r.progress??0);const g=r?.stats??null;return{index:e,name:o,status:i,firstIteration:s,iterations:A,progress:l,timeSpent:c,stats:g&&Object.keys(g).length>0?g:null,solverInstance:r??null}},$Wo=({status:t})=>{const e={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return j.jsx("span",{className:`font-medium ${e[t]}`,children:t})},ZWo=({progress:t})=>{if(t===0)return null;const e=Math.round(t*100);return j.jsxs("div",{className:"flex items-center gap-2",children:[j.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:j.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${e}%`}})}),j.jsxs("span",{className:"text-xs text-gray-500",children:[e,"%"]})]})},ejo=t=>Object.entries(t).map(([e,n])=>`${e}: ${n}`).join(", "),tjo=({stats:t})=>{if(!t||Object.keys(t).length===0)return j.jsx("span",{children:"-"});const e=Object.entries(t),n=ejo(t);return j.jsxs("details",{className:"cursor-pointer",children:[j.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:n}),j.jsx("div",{className:"mt-1 text-xs",children:e.map(([o,i])=>j.jsxs("div",{children:[o,": ",String(i)]},o))})]})},_9e=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(_9e);const e={};for(const[n,o]of Object.entries(t))n.startsWith("_")||(e[n]=_9e(o));return e},njo=(t,e)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${e}`);return}const n=_9e(t.getConstructorParams()),o=new Blob([JSON.stringify(n,null,2)],{type:"application/json"}),i=URL.createObjectURL(o),r=document.createElement("a");r.href=i,r.download=`${e}_input.json`,r.click(),URL.revokeObjectURL(i)}catch(n){alert(`Error downloading input for ${e}: ${n instanceof Error?n.message:String(n)}`)}},ojo=({solver:t,onStepUntilPhase:e,onDownloadInput:n})=>{const o=t.pipelineDef.map((a,A)=>XWo(t,A)),i=a=>{e?.(a)},r=a=>{a.solverInstance&&(n?n(a.solverInstance,a.name):njo(a.solverInstance,a.name))},s=a=>`${(a/1e3).toFixed(2)}s`;return j.jsxs("div",{className:"border-t border-gray-200",children:[j.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:j.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),j.jsx("div",{className:"overflow-x-auto",children:j.jsxs("table",{className:"w-full text-sm",children:[j.jsx("thead",{children:j.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[j.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),j.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),j.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",j.jsx("sub",{children:"0"})]}),j.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),j.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),j.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),j.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),j.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),j.jsx("tbody",{children:o.map(a=>j.jsxs("tr",{className:`border-b border-gray-100 ${a.status==="In Progress"?"bg-yellow-50":""}`,children:[j.jsx("td",{className:"px-4 py-2",children:j.jsxs("div",{className:"flex items-center gap-2",children:[j.jsx("span",{className:"text-gray-400 w-6",children:String(a.index+1).padStart(2,"0")}),j.jsx("button",{onClick:()=>i(a.name),disabled:a.status==="Completed"||t.solved||t.failed,className:"text-blue-500 hover:text-blue-700 disabled:text-gray-300 disabled:cursor-not-allowed",title:`Step until ${a.name} completes`,children:j.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:j.jsx("path",{fillRule:"evenodd",d:"M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z",clipRule:"evenodd"})})}),j.jsx("span",{className:"font-medium text-gray-900",children:a.name})]})}),j.jsx("td",{className:"px-4 py-2",children:j.jsx($Wo,{status:a.status})}),j.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:a.firstIteration!==null?a.firstIteration:""}),j.jsx("td",{className:"px-4 py-2 text-gray-600",children:a.iterations}),j.jsx("td",{className:"px-4 py-2",children:j.jsx(ZWo,{progress:a.progress})}),j.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(a.timeSpent)}),j.jsx("td",{className:"px-4 py-2 text-gray-500",children:j.jsx(tjo,{stats:a.stats})}),j.jsx("td",{className:"px-4 py-2",children:a.solverInstance?j.jsxs("button",{onClick:()=>r(a),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${a.name}`,children:[j.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:j.jsx("path",{fillRule:"evenodd",d:"M12 2.25a.75.75 0 01.75.75v11.69l3.22-3.22a.75.75 0 111.06 1.06l-4.5 4.5a.75.75 0 01-1.06 0l-4.5-4.5a.75.75 0 111.06-1.06l3.22 3.22V3a.75.75 0 01.75-.75zm-9 13.5a.75.75 0 01.75.75v2.25a1.5 1.5 0 001.5 1.5h13.5a1.5 1.5 0 001.5-1.5V16.5a.75.75 0 011.5 0v2.25a3 3 0 01-3 3H5.25a3 3 0 01-3-3V16.5a.75.75 0 01.75-.75z",clipRule:"evenodd"})}),j.jsx("span",{children:"Input"})]}):null})]},a.name))})]})})]})},ijo=class extends es.Component{constructor(t){super(t),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(t){console.error("InteractiveGraphics render error:",t)}render(){return this.state.hasError?this.props.fallback:this.props.children}};function rjo({graphics:t}){const e=t.points??[],n=t.lines??[],o=t.rects??[],i=t.circles??[],r=t.texts??[];let s=Number.POSITIVE_INFINITY,a=Number.POSITIVE_INFINITY,A=Number.NEGATIVE_INFINITY,c=Number.NEGATIVE_INFINITY;const l=(p,m)=>{typeof p=="number"&&(p<s&&(s=p),p>A&&(A=p)),typeof m=="number"&&(m<a&&(a=m),m>c&&(c=m))};for(const p of e)l(p.x,p.y);for(const p of n){const m=p.points??[];for(const I of m)l(I.x,I.y)}for(const p of o){const m=p.x??0,I=p.y??0,f=p.width??0,C=p.height??0;l(m,I),l(m+f,I+C)}for(const p of i){const m=p.x??0,I=p.y??0,f=p.radius??1;l(m-f,I-f),l(m+f,I+f)}for(const p of r)l(p.x,p.y);(!isFinite(s)||!isFinite(a)||!isFinite(A)||!isFinite(c))&&(s=-20,a=-20,A=20,c=20);const g=10,u=s-g,h=a-g,d=Math.max(1,A-s+2*g),_=Math.max(1,c-a+2*g);return j.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${u} ${h} ${d} ${_}`,role:"img","aria-label":"Graphics fallback",children:[o.map((p,m)=>j.jsx("rect",{x:p.x??0,y:p.y??0,width:p.width??0,height:p.height??0,fill:"none",stroke:p.strokeColor??"black",strokeWidth:p.strokeWidth??1},`rect-${m}`)),n.map((p,m)=>j.jsx("polyline",{fill:"none",stroke:p.strokeColor??"black",strokeWidth:p.strokeWidth??1,points:(p.points??[]).map(I=>`${I.x??0},${I.y??0}`).join(" ")},`line-${m}`)),i.map((p,m)=>j.jsx("circle",{cx:p.x??0,cy:p.y??0,r:p.radius??1.5,fill:p.fillColor??"none",stroke:p.strokeColor??"black",strokeWidth:p.strokeWidth??1},`circle-${m}`)),e.map((p,m)=>j.jsx("circle",{cx:p.x??0,cy:p.y??0,r:p.radius??1.5,fill:p.color??"black"},`point-${m}`)),r.map((p,m)=>j.jsx("text",{x:p.x??0,y:p.y??0,fontSize:p.fontSize??10,fill:p.color??"black",children:p.text??""},`text-${m}`))]})}var sjo=({solver:t,animationSpeed:e=25,onSolverStarted:n,onSolverCompleted:o})=>{const[i,r]=ne.useReducer(l=>l+1,0),s=ne.useMemo(()=>{try{return t.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(l){return console.error("Visualization error:",l),{points:[],lines:[],rects:[],circles:[]}}},[t,i]),a=ne.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);ne.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const l=document.createElement("script");l.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(l)}},[]);const A=t.pipelineDef!==void 0,c=l=>{const g=t;if(!t.solved&&!t.failed){for(;!t.solved&&!t.failed&&g.currentPipelineStepIndex<=g.pipelineDef.findIndex(u=>u.solverName===l);)t.step();r()}};return j.jsxs("div",{children:[j.jsx(WWo,{solver:t,triggerRender:r,animationSpeed:e,onSolverStarted:n,onSolverCompleted:o}),a?j.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):j.jsx(ijo,{fallback:j.jsx(rjo,{graphics:s}),children:j.jsx(VWo,{graphics:s})}),A&&j.jsx(ojo,{solver:t,onStepUntilPhase:c})]})};const ajo=()=>{ne.useEffect(()=>{const t="tailwind-cdn-script";if(document.getElementById(t)||window.tailwind)return;const e=document.createElement("div");e.className="hidden",document.body.appendChild(e);const n=window.getComputedStyle(e).display==="none";if(document.body.removeChild(e),n)return;const o=document.createElement("script");o.id=t,o.src="https://cdn.tailwindcss.com",document.head.appendChild(o)},[])},Ajo=1e3,lb=(t,e)=>{const{fileName:n,mimeType:o="text/plain"}=e,i=t instanceof Blob?t:new Blob([t],{type:o}),r=URL.createObjectURL(i),s=document.createElement("a");s.href=r,s.download=n,s.target="_blank",s.rel="noopener noreferrer",s.style.display="none",document.body.appendChild(s),s.click(),document.body.removeChild(s),setTimeout(()=>{URL.revokeObjectURL(r)},Ajo)},RHt=t=>{let e=t.trim().replace(/[\\/:*?"<>|]/g,"_").replace(/[\x00-\x1f]/g,"").replace(/^\.+/,"").replace(/\.+$/,"").replace(/\s+/g," ").replace(/_+/g,"_");return/^(con|prn|aux|nul|com[0-9]|lpt[0-9])$/i.test(e)&&(e=`_${e}`),e=e.slice(0,200),e||"untitled"},gb="https://github.com/tscircuit/tscircuit-autorouter/issues/new",THt="https://github.com/tscircuit/copper-pour-solver/issues/new",kHt="https://github.com/tscircuit/calculate-packing/issues/new",cjo="https://github.com/tscircuit/matchpack/issues/new",FHt="https://github.com/tscircuit/schematic-trace-solver/issues/new?template=json-bug-report.yml",ljo={PackSolver2:kHt,LayoutPipelineSolver:cjo,AutoroutingPipelineSolver:gb,AssignableAutoroutingPipeline2:gb,AssignableAutoroutingPipeline3:gb,AutoroutingPipeline1_OriginalUnravel:gb,AutoroutingPipelineSolver3_HgPortPointPathing:gb,AutoroutingPipelineSolver4:gb,AutoroutingPipelineSolver5:gb,AutoroutingPipelineSolver7_MultiGraph:gb,AutoroutingPipelineSolver8:gb,CopperPourPipelineSolver:THt,SchematicTracePipelineSolver:FHt},gjo=t=>t.toLowerCase().includes("pack")?HLo:t.toLowerCase().includes("rout")?VLo:wLo,LHt=t=>{const e=ljo[t];if(e)return e;const n=t.toLowerCase();return n.includes("autorout")?gb:n.includes("schematic")&&n.includes("trace")?FHt:n.includes("copperpour")?THt:n.includes("pack")?kHt:null},ujo=t=>`${RHt(`${t.componentName}-${t.solverName}`)}-solver-input.json`,HHt=t=>{lb(JSON.stringify(t.solverParams,null,2),{fileName:ujo(t),mimeType:"application/json"})},djo=({solverEvent:t})=>{const e=LHt(t.solverName);return j.jsxs("div",{className:"rf-flex rf-items-center rf-justify-end rf-gap-2 rf-border-b rf-border-gray-200 rf-bg-gray-50 rf-px-4 rf-py-2",children:[j.jsxs(Mc,{type:"button",variant:"outline",size:"sm",onClick:()=>HHt(t),children:[j.jsx(o6e,{className:"rf-w-4 rf-h-4"}),"Download"]}),e?j.jsx(Mc,{asChild:!0,variant:"outline",size:"sm",children:j.jsxs("a",{href:e,target:"_blank",rel:"noopener noreferrer",children:[j.jsx(Qre,{className:"rf-w-4 rf-h-4"}),"Report"]})}):j.jsxs(Mc,{type:"button",variant:"outline",size:"sm",disabled:!0,title:"No report link configured for this solver",children:[j.jsx(Qre,{className:"rf-w-4 rf-h-4"}),"Report"]})]})},hjo=({solverEvent:t})=>{const e=LHt(t.solverName);return e?j.jsx(Mc,{asChild:!0,variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8",children:j.jsx("a",{href:e,target:"_blank",rel:"noopener noreferrer",title:"Report solver bug","aria-label":"Report solver bug",children:j.jsx(Qre,{className:"rf-w-4 rf-h-4"})})}):j.jsx(Mc,{type:"button",variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8",disabled:!0,title:"No report link configured for this solver","aria-label":"Report solver bug",children:j.jsx(Qre,{className:"rf-w-4 rf-h-4"})})},_jo=({solverEvents:t=[]})=>{const[e,n]=ne.useState(null);ajo();const o=ne.useMemo(()=>{const a=new Map;for(const A of t){const c=`${A.componentName}-${A.solverName}`;a.set(c,A)}return a},[t]),i=ne.useMemo(()=>Array.from(o.keys()),[o]),r=e?o.get(e):null,s=ne.useMemo(()=>{if(!r)return{instance:null,error:null,classFound:!1};const a=DBe[r.solverName];if(!a)return{instance:null,error:`Solver class "${r.solverName}" not found in SOLVERS registry. Available: ${Object.keys(DBe).join(", ")}`,classFound:!1};try{const A=r.solverParams,c=A?.input!==void 0?A.input:A;return{instance:new a(c),error:null,classFound:!0}}catch(A){const c=A instanceof Error?A.message:String(A);return console.error("Failed to reconstruct solver:",A),{instance:null,error:`Failed to instantiate solver: ${c}`,classFound:!0}}},[r]);return t.length===0?j.jsx("div",{className:"rf-p-4",children:j.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:j.jsxs("div",{className:"rf-p-4",children:[j.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),j.jsx("p",{className:"rf-text-sm rf-text-gray-600",children:"Solvers will appear here when the circuit runs. Solvers are used for tasks like component packing and autorouting."})]})})}):j.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[j.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[j.jsxs("div",{className:"rf-text-xs rf-font-semibold rf-text-gray-500 rf-px-3 rf-py-2 rf-bg-gray-50 rf-border-b rf-border-gray-200",children:[i.length," ",i.length===1?"Solver":"Solvers"]}),i.map(a=>{const A=o.get(a),c=e===a;return j.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${c?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>n(a),children:(()=>{const l=gjo(A.solverName);return j.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[j.jsx(l,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),j.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[j.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:A.componentName}),j.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:A.solverName})]})]})})()},a)})]}),j.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:r?s.instance?j.jsxs("div",{className:"rf-flex rf-h-full rf-flex-col rf-overflow-y-auto",children:[j.jsx(djo,{solverEvent:r}),j.jsx("div",{className:"rf-min-h-0 rf-flex-1",children:j.jsx(ZS,{fallback:j.jsx("div",{className:"rf-p-4",children:j.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[j.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),j.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",r.solverName]})]})}),children:j.jsx(sjo,{solver:s.instance})})})]}):j.jsxs("div",{className:"rf-p-4",children:[j.jsxs("div",{className:"rf-mb-4",children:[j.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:r.solverName}),j.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",r.componentName]})]}),s.error&&j.jsx("div",{className:`rf-rounded-md rf-border rf-p-4 rf-mb-4 ${s.classFound?"rf-bg-red-50 rf-border-red-200":"rf-bg-yellow-50 rf-border-yellow-200"}`,children:j.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),j.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[j.jsxs("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50 rf-flex rf-items-center rf-justify-between rf-gap-2",children:[j.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"}),j.jsxs("div",{className:"rf-flex rf-items-center rf-gap-1",children:[j.jsx(hjo,{solverEvent:r}),j.jsx(Mc,{type:"button",variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8","aria-label":"Download solver input JSON",title:"Download solver input JSON",onClick:()=>HHt(r),children:j.jsx(o6e,{className:"rf-w-4 rf-h-4"})})]})]}),j.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:j.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(r.solverParams,null,2)})})]})]}):j.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:j.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},GHt=({errorMessage:t,errorStack:e,circuitJsonErrors:n})=>{ne.useEffect(()=>{if(t){const o=new Error(t);e&&(o.stack=e);try{Y8.captureException(o)}catch{}}},[t,e]),ne.useEffect(()=>{if(n&&n.length>0)for(const o of n){const i=new Error(o.message||"Circuit JSON Error");o.stack&&(i.stack=o.stack);try{Y8.captureException(i,{error_type:o.type})}catch{}}},[n])},pjo=t=>{ne.useEffect(()=>{try{rWt(t)}catch{}},[t.source,t.component,t.isWebEmbedded,t.activeTab])},OHt="0.0.2407",mjo={version:OHt},p9e={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},m9e=new Map,Hse=t=>{const e=m9e.get(t);return e?Object.fromEntries(Object.entries(e.stores).map(([n,o])=>[n,o.getState()])):{}},Ijo=(t,e,n)=>{if(t===void 0)return{type:"untracked",connection:e.connect(n)};const o=m9e.get(n.name);if(o)return{type:"tracked",store:t,...o};const i={connection:e.connect(n),stores:{}};return m9e.set(n.name,i),{type:"tracked",store:t,...i}},KHt=(t,e={})=>(n,o,i)=>{const{enabled:r,anonymousActionType:s,store:a,...A}=e;let c;try{c=(r??(p9e?"production":void 0)!=="production")&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!c)return(p9e?"production":void 0)!=="production"&&r&&console.warn("[zustand devtools middleware] Please install/enable Redux devtools extension"),t(n,o,i);const{connection:l,...g}=Ijo(a,c,A);let u=!0;i.setState=(_,p,m)=>{const I=n(_,p);if(!u)return I;const f=m===void 0?{type:s||"anonymous"}:typeof m=="string"?{type:m}:m;return a===void 0?(l?.send(f,o()),I):(l?.send({...f,type:`${a}/${f.type}`},{...Hse(A.name),[a]:i.getState()}),I)};const h=(..._)=>{const p=u;u=!1,n(..._),u=p},d=t(i.setState,o,i);if(g.type==="untracked"?l?.init(d):(g.stores[g.store]=i,l?.init(Object.fromEntries(Object.entries(g.stores).map(([_,p])=>[_,_===g.store?d:p.getState()])))),i.dispatchFromDevtools&&typeof i.dispatch=="function"){let _=!1;const p=i.dispatch;i.dispatch=(...m)=>{(p9e?"production":void 0)!=="production"&&m[0].type==="__setState"&&!_&&(console.warn('[zustand devtools middleware] "__setState" action type is reserved to set state from the devtools. Avoid using it.'),_=!0),p(...m)}}return l.subscribe(_=>{var p;switch(_.type){case"ACTION":if(typeof _.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return I9e(_.payload,m=>{if(m.type==="__setState"){if(a===void 0){h(m.state);return}Object.keys(m.state).length!==1&&console.error(`
5795
5795
  [zustand devtools middleware] Unsupported __setState action format.
5796
5796
  When using 'store' option in devtools(), the 'state' should have only one key, which is a value of 'store' that was passed in devtools(),
5797
5797
  and value of this only key should be a state object. Example: { "type": "__setState", "state": { "abc123Store": { "foo": "bar" } } }