copperflow 0.4.0 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -4
- package/dist/app/assets/NewPartDialog-PSXlbLR2.js +1 -0
- package/dist/app/assets/PackagesDialog-C8ZyWl-g.css +1 -0
- package/dist/app/assets/PackagesDialog-DmIT8b2D.js +2 -0
- package/dist/app/assets/{VerifyPartDialog-Ey6xpQ_U.js → VerifyPartDialog-KiW1nDnZ.js} +2 -2
- package/dist/app/assets/footprint-preview-oJ27yBAB.js +160 -0
- package/dist/app/assets/index-CArKmuM_.css +1 -0
- package/dist/app/assets/index-Yj6ATP2T.js +20 -0
- package/dist/app/assets/texture-worker-e8zKC6dv.js +1 -0
- package/dist/app/index.html +2 -2
- package/dist/cli-commands.d.ts +2 -0
- package/dist/cli-commands.js +45 -0
- package/dist/cli-commands.js.map +1 -1
- package/dist/cli-graphic.d.ts +9 -0
- package/dist/cli-graphic.js +62 -0
- package/dist/cli-graphic.js.map +1 -0
- package/dist/core/annotations.js +2 -2
- package/dist/core/annotations.js.map +1 -1
- package/dist/core/board-edits.d.ts +2 -0
- package/dist/core/board-edits.js +14 -0
- package/dist/core/board-edits.js.map +1 -1
- package/dist/core/board-graphic-edits.d.ts +8 -0
- package/dist/core/board-graphic-edits.js +88 -0
- package/dist/core/board-graphic-edits.js.map +1 -0
- package/dist/core/board-items.d.ts +6 -0
- package/dist/core/board-items.js +8 -3
- package/dist/core/board-items.js.map +1 -1
- package/dist/core/board-shape-edit.js +4 -2
- package/dist/core/board-shape-edit.js.map +1 -1
- package/dist/core/edit.js +17 -1
- package/dist/core/edit.js.map +1 -1
- package/dist/core/graphic-import.d.ts +43 -0
- package/dist/core/graphic-import.js +142 -0
- package/dist/core/graphic-import.js.map +1 -0
- package/dist/core/html-export.d.ts +37 -0
- package/dist/core/html-export.js +139 -0
- package/dist/core/html-export.js.map +1 -0
- package/dist/core/html-page.d.ts +39 -0
- package/dist/core/html-page.js +114 -0
- package/dist/core/html-page.js.map +1 -0
- package/dist/core/html-style.d.ts +3 -0
- package/dist/core/html-style.js +117 -0
- package/dist/core/html-style.js.map +1 -0
- package/dist/core/model-export.d.ts +33 -0
- package/dist/core/model-export.js +36 -0
- package/dist/core/model-export.js.map +1 -0
- package/dist/core/out-name.d.ts +5 -0
- package/dist/core/out-name.js +10 -0
- package/dist/core/out-name.js.map +1 -0
- package/dist/core/packages.d.ts +22 -0
- package/dist/core/packages.js +64 -0
- package/dist/core/packages.js.map +1 -0
- package/dist/core/pad-lines.d.ts +7 -0
- package/dist/core/pad-lines.js +15 -0
- package/dist/core/pad-lines.js.map +1 -0
- package/dist/core/pour-edits.d.ts +12 -1
- package/dist/core/pour-edits.js +6 -6
- package/dist/core/pour-edits.js.map +1 -1
- package/dist/core/render.d.ts +2 -1
- package/dist/core/render.js.map +1 -1
- package/dist/core/rules-patch.d.ts +17 -0
- package/dist/core/rules-patch.js +102 -0
- package/dist/core/rules-patch.js.map +1 -0
- package/dist/core/silk-text-edits.d.ts +8 -0
- package/dist/core/silk-text-edits.js +72 -0
- package/dist/core/silk-text-edits.js.map +1 -0
- package/dist/core/step-export.js +3 -0
- package/dist/core/step-export.js.map +1 -1
- package/dist/core/types.d.ts +55 -3
- package/dist/engine/board-graphic.d.ts +49 -0
- package/dist/engine/board-graphic.js +175 -0
- package/dist/engine/board-graphic.js.map +1 -0
- package/dist/engine/checks/copper-clearance.d.ts +1 -1
- package/dist/engine/checks/copper-clearance.js +19 -1
- package/dist/engine/checks/copper-clearance.js.map +1 -1
- package/dist/engine/checks/copper-pieces.d.ts +8 -2
- package/dist/engine/checks/copper-pieces.js +23 -2
- package/dist/engine/checks/copper-pieces.js.map +1 -1
- package/dist/engine/checks/drc-board-graphic.d.ts +10 -0
- package/dist/engine/checks/drc-board-graphic.js +95 -0
- package/dist/engine/checks/drc-board-graphic.js.map +1 -0
- package/dist/engine/checks/drc-parts.js +3 -1
- package/dist/engine/checks/drc-parts.js.map +1 -1
- package/dist/engine/checks/drc-pours.js +3 -3
- package/dist/engine/checks/drc-pours.js.map +1 -1
- package/dist/engine/checks/drc-silk-text.d.ts +15 -0
- package/dist/engine/checks/drc-silk-text.js +65 -0
- package/dist/engine/checks/drc-silk-text.js.map +1 -0
- package/dist/engine/checks/fill-point.d.ts +7 -0
- package/dist/engine/checks/fill-point.js +58 -0
- package/dist/engine/checks/fill-point.js.map +1 -0
- package/dist/engine/checks/stranded-copper.d.ts +14 -0
- package/dist/engine/checks/stranded-copper.js +43 -0
- package/dist/engine/checks/stranded-copper.js.map +1 -0
- package/dist/engine/design.js +1 -1
- package/dist/engine/design.js.map +1 -1
- package/dist/engine/elaborate.d.ts +2 -0
- package/dist/engine/elaborate.js +30 -1
- package/dist/engine/elaborate.js.map +1 -1
- package/dist/engine/engine.d.ts +4 -1
- package/dist/engine/engine.js +5 -2
- package/dist/engine/engine.js.map +1 -1
- package/dist/engine/fab/graphic-objects.d.ts +7 -0
- package/dist/engine/fab/graphic-objects.js +24 -0
- package/dist/engine/fab/graphic-objects.js.map +1 -0
- package/dist/engine/fab/layers.d.ts +9 -0
- package/dist/engine/fab/layers.js +60 -8
- package/dist/engine/fab/layers.js.map +1 -1
- package/dist/engine/fab/silk-text-strokes.d.ts +16 -0
- package/dist/engine/fab/silk-text-strokes.js +28 -0
- package/dist/engine/fab/silk-text-strokes.js.map +1 -0
- package/dist/engine/fab/stroke-font.d.ts +4 -0
- package/dist/engine/fab/stroke-font.js +38 -1
- package/dist/engine/fab/stroke-font.js.map +1 -1
- package/dist/engine/footprints/array.d.ts +4 -0
- package/dist/engine/footprints/array.js +51 -0
- package/dist/engine/footprints/array.js.map +1 -0
- package/dist/engine/footprints/axial.d.ts +6 -0
- package/dist/engine/footprints/axial.js +115 -0
- package/dist/engine/footprints/axial.js.map +1 -0
- package/dist/engine/footprints/catalogue.d.ts +39 -0
- package/dist/engine/footprints/catalogue.js +284 -0
- package/dist/engine/footprints/catalogue.js.map +1 -0
- package/dist/engine/footprints/chip.js +10 -1
- package/dist/engine/footprints/chip.js.map +1 -1
- package/dist/engine/footprints/connector.d.ts +16 -0
- package/dist/engine/footprints/connector.js +31 -0
- package/dist/engine/footprints/connector.js.map +1 -0
- package/dist/engine/footprints/dcjack.d.ts +3 -0
- package/dist/engine/footprints/dcjack.js +46 -0
- package/dist/engine/footprints/dcjack.js.map +1 -0
- package/dist/engine/footprints/dpak.d.ts +7 -0
- package/dist/engine/footprints/dpak.js +172 -0
- package/dist/engine/footprints/dpak.js.map +1 -0
- package/dist/engine/footprints/dual.d.ts +11 -2
- package/dist/engine/footprints/dual.js +113 -12
- package/dist/engine/footprints/dual.js.map +1 -1
- package/dist/engine/footprints/index.js +46 -3
- package/dist/engine/footprints/index.js.map +1 -1
- package/dist/engine/footprints/inductor.d.ts +3 -0
- package/dist/engine/footprints/inductor.js +32 -0
- package/dist/engine/footprints/inductor.js.map +1 -0
- package/dist/engine/footprints/known.js +114 -14
- package/dist/engine/footprints/known.js.map +1 -1
- package/dist/engine/footprints/ledsmd.d.ts +3 -0
- package/dist/engine/footprints/ledsmd.js +52 -0
- package/dist/engine/footprints/ledsmd.js.map +1 -0
- package/dist/engine/footprints/ledth.d.ts +4 -0
- package/dist/engine/footprints/ledth.js +45 -0
- package/dist/engine/footprints/ledth.js.map +1 -0
- package/dist/engine/footprints/melf.d.ts +8 -0
- package/dist/engine/footprints/melf.js +56 -0
- package/dist/engine/footprints/melf.js.map +1 -0
- package/dist/engine/footprints/pad-roles.d.ts +4 -0
- package/dist/engine/footprints/pad-roles.js +32 -0
- package/dist/engine/footprints/pad-roles.js.map +1 -0
- package/dist/engine/footprints/plcc.d.ts +4 -0
- package/dist/engine/footprints/plcc.js +117 -0
- package/dist/engine/footprints/plcc.js.map +1 -0
- package/dist/engine/footprints/resonator.d.ts +3 -0
- package/dist/engine/footprints/resonator.js +33 -0
- package/dist/engine/footprints/resonator.js.map +1 -0
- package/dist/engine/footprints/screw.d.ts +3 -0
- package/dist/engine/footprints/screw.js +51 -0
- package/dist/engine/footprints/screw.js.map +1 -0
- package/dist/engine/footprints/smallsot.d.ts +8 -0
- package/dist/engine/footprints/smallsot.js +143 -0
- package/dist/engine/footprints/smallsot.js.map +1 -0
- package/dist/engine/footprints/smdbox.d.ts +33 -0
- package/dist/engine/footprints/smdbox.js +76 -0
- package/dist/engine/footprints/smdbox.js.map +1 -0
- package/dist/engine/footprints/smdcan.d.ts +3 -0
- package/dist/engine/footprints/smdcan.js +61 -0
- package/dist/engine/footprints/smdcan.js.map +1 -0
- package/dist/engine/footprints/smdip.d.ts +4 -0
- package/dist/engine/footprints/smdip.js +58 -0
- package/dist/engine/footprints/smdip.js.map +1 -0
- package/dist/engine/footprints/socket.d.ts +8 -0
- package/dist/engine/footprints/socket.js +21 -0
- package/dist/engine/footprints/socket.js.map +1 -0
- package/dist/engine/footprints/sod.d.ts +6 -0
- package/dist/engine/footprints/sod.js +63 -6
- package/dist/engine/footprints/sod.js.map +1 -1
- package/dist/engine/footprints/sot.d.ts +1 -1
- package/dist/engine/footprints/sot.js +17 -2
- package/dist/engine/footprints/sot.js.map +1 -1
- package/dist/engine/footprints/tact.d.ts +3 -0
- package/dist/engine/footprints/tact.js +65 -0
- package/dist/engine/footprints/tact.js.map +1 -0
- package/dist/engine/footprints/tantalum.d.ts +7 -0
- package/dist/engine/footprints/tantalum.js +91 -0
- package/dist/engine/footprints/tantalum.js.map +1 -0
- package/dist/engine/footprints/to92inline.d.ts +14 -0
- package/dist/engine/footprints/to92inline.js +21 -0
- package/dist/engine/footprints/to92inline.js.map +1 -0
- package/dist/engine/footprints/topower.d.ts +7 -0
- package/dist/engine/footprints/topower.js +119 -0
- package/dist/engine/footprints/topower.js.map +1 -0
- package/dist/engine/footprints/usb.d.ts +32 -0
- package/dist/engine/footprints/usb.js +109 -0
- package/dist/engine/footprints/usb.js.map +1 -0
- package/dist/engine/footprints/xtal.d.ts +4 -0
- package/dist/engine/footprints/xtal.js +61 -0
- package/dist/engine/footprints/xtal.js.map +1 -0
- package/dist/engine/graphic-place.d.ts +34 -0
- package/dist/engine/graphic-place.js +132 -0
- package/dist/engine/graphic-place.js.map +1 -0
- package/dist/engine/graphics/curves.d.ts +18 -0
- package/dist/engine/graphics/curves.js +75 -0
- package/dist/engine/graphics/curves.js.map +1 -0
- package/dist/engine/graphics/dxf-entities.d.ts +20 -0
- package/dist/engine/graphics/dxf-entities.js +184 -0
- package/dist/engine/graphics/dxf-entities.js.map +1 -0
- package/dist/engine/graphics/dxf-pairs.d.ts +22 -0
- package/dist/engine/graphics/dxf-pairs.js +77 -0
- package/dist/engine/graphics/dxf-pairs.js.map +1 -0
- package/dist/engine/graphics/dxf.d.ts +5 -0
- package/dist/engine/graphics/dxf.js +110 -0
- package/dist/engine/graphics/dxf.js.map +1 -0
- package/dist/engine/graphics/index.d.ts +9 -0
- package/dist/engine/graphics/index.js +30 -0
- package/dist/engine/graphics/index.js.map +1 -0
- package/dist/engine/graphics/path-data.d.ts +12 -0
- package/dist/engine/graphics/path-data.js +162 -0
- package/dist/engine/graphics/path-data.js.map +1 -0
- package/dist/engine/graphics/rings.d.ts +7 -0
- package/dist/engine/graphics/rings.js +93 -0
- package/dist/engine/graphics/rings.js.map +1 -0
- package/dist/engine/graphics/shapes.d.ts +47 -0
- package/dist/engine/graphics/shapes.js +85 -0
- package/dist/engine/graphics/shapes.js.map +1 -0
- package/dist/engine/graphics/svg-attributes.d.ts +26 -0
- package/dist/engine/graphics/svg-attributes.js +116 -0
- package/dist/engine/graphics/svg-attributes.js.map +1 -0
- package/dist/engine/graphics/svg.d.ts +5 -0
- package/dist/engine/graphics/svg.js +118 -0
- package/dist/engine/graphics/svg.js.map +1 -0
- package/dist/engine/graphics/transform.d.ts +21 -0
- package/dist/engine/graphics/transform.js +88 -0
- package/dist/engine/graphics/transform.js.map +1 -0
- package/dist/engine/graphics/xml.d.ts +10 -0
- package/dist/engine/graphics/xml.js +130 -0
- package/dist/engine/graphics/xml.js.map +1 -0
- package/dist/engine/model.d.ts +55 -0
- package/dist/engine/model.js.map +1 -1
- package/dist/engine/pcb-place/grow.d.ts +12 -0
- package/dist/engine/pcb-place/grow.js +100 -0
- package/dist/engine/pcb-place/grow.js.map +1 -0
- package/dist/engine/pcb.d.ts +5 -1
- package/dist/engine/pcb.js +2 -0
- package/dist/engine/pcb.js.map +1 -1
- package/dist/engine/pour/cache.js +1 -0
- package/dist/engine/pour/cache.js.map +1 -1
- package/dist/engine/pour/obstacles.js +18 -1
- package/dist/engine/pour/obstacles.js.map +1 -1
- package/dist/engine/router/route-board.d.ts +2 -0
- package/dist/engine/router/route-board.js +7 -2
- package/dist/engine/router/route-board.js.map +1 -1
- package/dist/engine/router/unplaced.d.ts +18 -0
- package/dist/engine/router/unplaced.js +27 -0
- package/dist/engine/router/unplaced.js.map +1 -0
- package/dist/engine/rules/rotations.d.ts +12 -3
- package/dist/engine/rules/rotations.js +77 -2
- package/dist/engine/rules/rotations.js.map +1 -1
- package/dist/engine/silk-text.d.ts +40 -0
- package/dist/engine/silk-text.js +85 -0
- package/dist/engine/silk-text.js.map +1 -0
- package/dist/engine/solid/heights-smd.d.ts +3 -0
- package/dist/engine/solid/heights-smd.js +81 -0
- package/dist/engine/solid/heights-smd.js.map +1 -0
- package/dist/engine/solid/heights-through.d.ts +7 -0
- package/dist/engine/solid/heights-through.js +93 -0
- package/dist/engine/solid/heights-through.js.map +1 -0
- package/dist/engine/solid/heights-uno.d.ts +2 -0
- package/dist/engine/solid/heights-uno.js +15 -0
- package/dist/engine/solid/heights-uno.js.map +1 -0
- package/dist/engine/solid/heights.d.ts +2 -0
- package/dist/engine/solid/heights.js +43 -18
- package/dist/engine/solid/heights.js.map +1 -1
- package/dist/library/attach-datasheet.d.ts +2 -0
- package/dist/library/attach-datasheet.js +1 -1
- package/dist/library/attach-datasheet.js.map +1 -1
- package/dist/library/part-fields.d.ts +23 -0
- package/dist/library/part-fields.js +55 -0
- package/dist/library/part-fields.js.map +1 -0
- package/dist/mcp/batch-steps.d.ts +33 -0
- package/dist/mcp/batch-steps.js +211 -0
- package/dist/mcp/batch-steps.js.map +1 -0
- package/dist/mcp/batch.d.ts +16 -0
- package/dist/mcp/batch.js +18 -5
- package/dist/mcp/batch.js.map +1 -1
- package/dist/mcp/board-import-tool.d.ts +1 -1
- package/dist/mcp/board-import-tool.js +1 -1
- package/dist/mcp/board-import-tool.js.map +1 -1
- package/dist/mcp/board-summary.d.ts +1 -1
- package/dist/mcp/board-summary.js +32 -1
- package/dist/mcp/board-summary.js.map +1 -1
- package/dist/mcp/board-tool.d.ts +36 -0
- package/dist/mcp/board-tool.js +109 -0
- package/dist/mcp/board-tool.js.map +1 -0
- package/dist/mcp/copper-summary.d.ts +2 -0
- package/dist/mcp/copper-summary.js +10 -2
- package/dist/mcp/copper-summary.js.map +1 -1
- package/dist/mcp/copper-tools.d.ts +1 -1
- package/dist/mcp/copper-tools.js +1 -1
- package/dist/mcp/copper-tools.js.map +1 -1
- package/dist/mcp/create-part.js +2 -2
- package/dist/mcp/create-part.js.map +1 -1
- package/dist/mcp/graphic-tool.d.ts +34 -0
- package/dist/mcp/graphic-tool.js +29 -0
- package/dist/mcp/graphic-tool.js.map +1 -0
- package/dist/mcp/guide.d.ts +3 -1
- package/dist/mcp/guide.js +15 -4
- package/dist/mcp/guide.js.map +1 -1
- package/dist/mcp/html-tool.d.ts +28 -0
- package/dist/mcp/html-tool.js +21 -0
- package/dist/mcp/html-tool.js.map +1 -0
- package/dist/mcp/model-tool.d.ts +31 -0
- package/dist/mcp/model-tool.js +27 -0
- package/dist/mcp/model-tool.js.map +1 -0
- package/dist/mcp/new-circuit.d.ts +1 -1
- package/dist/mcp/new-circuit.js +10 -11
- package/dist/mcp/new-circuit.js.map +1 -1
- package/dist/mcp/part-tools.d.ts +20 -0
- package/dist/mcp/part-tools.js +40 -0
- package/dist/mcp/part-tools.js.map +1 -0
- package/dist/mcp/place-tools.d.ts +1 -1
- package/dist/mcp/place-tools.js +11 -5
- package/dist/mcp/place-tools.js.map +1 -1
- package/dist/mcp/project-tools.js +2 -0
- package/dist/mcp/project-tools.js.map +1 -1
- package/dist/mcp/render-tool.d.ts +2 -0
- package/dist/mcp/render-tool.js +32 -1
- package/dist/mcp/render-tool.js.map +1 -1
- package/dist/mcp/route-tools.d.ts +1 -1
- package/dist/mcp/route-tools.js +3 -1
- package/dist/mcp/route-tools.js.map +1 -1
- package/dist/mcp/rules-tool.d.ts +19 -0
- package/dist/mcp/rules-tool.js +73 -0
- package/dist/mcp/rules-tool.js.map +1 -0
- package/dist/mcp/server.js +53 -17
- package/dist/mcp/server.js.map +1 -1
- package/dist/mcp/text-tool.d.ts +34 -0
- package/dist/mcp/text-tool.js +37 -0
- package/dist/mcp/text-tool.js.map +1 -0
- package/dist/render/render.js +2335 -389
- package/dist/studio/server.js +32 -0
- package/dist/studio/server.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -1
- package/skills/copperflow/SKILL.md +8 -8
- package/skills/copperflow/references/copper.md +9 -1
- package/skills/copperflow/references/design-rules.md +36 -7
- package/skills/copperflow/references/editable-subset.md +18 -8
- package/skills/copperflow/references/parts-library.md +19 -1
- package/skills/copperflow/references/writing-circuits.md +71 -0
- package/dist/app/assets/NewPartDialog-BBJaZFCo.js +0 -160
- package/dist/app/assets/index-BKoIKo22.css +0 -1
- package/dist/app/assets/index-DPmr2dR1.js +0 -20
- package/dist/app/assets/texture-worker-CyI_g_XZ.js +0 -1
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./VerifyPartDialog-Ey6xpQ_U.js","./VerifyPartDialog-BHLqD_WJ.css"])))=>i.map(i=>d[i]);
|
|
2
|
-
var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t,t.exports),e=null),t.exports),s=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},c=(n,r,o)=>(o=n==null?{}:e(i(n)),s(r||!n||!n.__esModule||!a.call(n,`default`)?t(o,`default`,{value:n,enumerable:!0}):o,n));(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),t.credentials=e.crossOrigin===`use-credentials`?`include`:e.crossOrigin===`anonymous`?`omit`:`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var l=o((e=>{var t=Symbol.for(`react.transitional.element`),n=Symbol.for(`react.portal`),r=Symbol.for(`react.fragment`),i=Symbol.for(`react.strict_mode`),a=Symbol.for(`react.profiler`),o=Symbol.for(`react.consumer`),s=Symbol.for(`react.context`),c=Symbol.for(`react.forward_ref`),l=Symbol.for(`react.suspense`),u=Symbol.for(`react.memo`),d=Symbol.for(`react.lazy`),f=Symbol.iterator;function p(e){return typeof e!=`object`||!e?null:(e=f&&e[f]||e[`@@iterator`],typeof e==`function`?e:null)}var m={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},h=Object.assign,g={};function _(e,t,n){this.props=e,this.context=t,this.refs=g,this.updater=n||m}_.prototype.isReactComponent={},_.prototype.setState=function(e,t){if(typeof e!=`object`&&typeof e!=`function`&&e!=null)throw Error(`takes an object of state variables to update or a function which returns an object of state variables.`);this.updater.enqueueSetState(this,e,t,`setState`)},_.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,`forceUpdate`)};function v(){}v.prototype=_.prototype;function y(e,t,n){this.props=e,this.context=t,this.refs=g,this.updater=n||m}var b=y.prototype=new v;b.constructor=y,h(b,_.prototype),b.isPureReactComponent=!0;var x=Array.isArray,S={H:null,A:null,T:null,S:null,V:null},C=Object.prototype.hasOwnProperty;function w(e,n,r,i,a,o){return r=o.ref,{$$typeof:t,type:e,key:n,ref:r===void 0?null:r,props:o}}function T(e,t){return w(e.type,t,void 0,void 0,void 0,e.props)}function E(e){return typeof e==`object`&&!!e&&e.$$typeof===t}function D(e){var t={"=":`=0`,":":`=2`};return`$`+e.replace(/[=:]/g,function(e){return t[e]})}var O=/\/+/g;function k(e,t){return typeof e==`object`&&e&&e.key!=null?D(``+e.key):t.toString(36)}function A(){}function j(e){switch(e.status){case`fulfilled`:return e.value;case`rejected`:throw e.reason;default:switch(typeof e.status==`string`?e.then(A,A):(e.status=`pending`,e.then(function(t){e.status===`pending`&&(e.status=`fulfilled`,e.value=t)},function(t){e.status===`pending`&&(e.status=`rejected`,e.reason=t)})),e.status){case`fulfilled`:return e.value;case`rejected`:throw e.reason}}throw e}function M(e,r,i,a,o){var s=typeof e;(s===`undefined`||s===`boolean`)&&(e=null);var c=!1;if(e===null)c=!0;else switch(s){case`bigint`:case`string`:case`number`:c=!0;break;case`object`:switch(e.$$typeof){case t:case n:c=!0;break;case d:return c=e._init,M(c(e._payload),r,i,a,o)}}if(c)return o=o(e),c=a===``?`.`+k(e,0):a,x(o)?(i=``,c!=null&&(i=c.replace(O,`$&/`)+`/`),M(o,r,i,``,function(e){return e})):o!=null&&(E(o)&&(o=T(o,i+(o.key==null||e&&e.key===o.key?``:(``+o.key).replace(O,`$&/`)+`/`)+c)),r.push(o)),1;c=0;var l=a===``?`.`:a+`:`;if(x(e))for(var u=0;u<e.length;u++)a=e[u],s=l+k(a,u),c+=M(a,r,i,s,o);else if(u=p(e),typeof u==`function`)for(e=u.call(e),u=0;!(a=e.next()).done;)a=a.value,s=l+k(a,u++),c+=M(a,r,i,s,o);else if(s===`object`){if(typeof e.then==`function`)return M(j(e),r,i,a,o);throw r=String(e),Error(`Objects are not valid as a React child (found: `+(r===`[object Object]`?`object with keys {`+Object.keys(e).join(`, `)+`}`:r)+`). If you meant to render a collection of children, use an array instead.`)}return c}function ee(e,t,n){if(e==null)return e;var r=[],i=0;return M(e,r,``,``,function(e){return t.call(n,e,i++)}),r}function te(e){if(e._status===-1){var t=e._result;t=t(),t.then(function(t){(e._status===0||e._status===-1)&&(e._status=1,e._result=t)},function(t){(e._status===0||e._status===-1)&&(e._status=2,e._result=t)}),e._status===-1&&(e._status=0,e._result=t)}if(e._status===1)return e._result.default;throw e._result}var ne=typeof reportError==`function`?reportError:function(e){if(typeof window==`object`&&typeof window.ErrorEvent==`function`){var t=new window.ErrorEvent(`error`,{bubbles:!0,cancelable:!0,message:typeof e==`object`&&e&&typeof e.message==`string`?String(e.message):String(e),error:e});if(!window.dispatchEvent(t))return}else if(typeof process==`object`&&typeof process.emit==`function`){process.emit(`uncaughtException`,e);return}console.error(e)};function N(){}e.Children={map:ee,forEach:function(e,t,n){ee(e,function(){t.apply(this,arguments)},n)},count:function(e){var t=0;return ee(e,function(){t++}),t},toArray:function(e){return ee(e,function(e){return e})||[]},only:function(e){if(!E(e))throw Error(`React.Children.only expected to receive a single React element child.`);return e}},e.Component=_,e.Fragment=r,e.Profiler=a,e.PureComponent=y,e.StrictMode=i,e.Suspense=l,e.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=S,e.__COMPILER_RUNTIME={__proto__:null,c:function(e){return S.H.useMemoCache(e)}},e.cache=function(e){return function(){return e.apply(null,arguments)}},e.cloneElement=function(e,t,n){if(e==null)throw Error(`The argument must be a React element, but you passed `+e+`.`);var r=h({},e.props),i=e.key,a=void 0;if(t!=null)for(o in t.ref!==void 0&&(a=void 0),t.key!==void 0&&(i=``+t.key),t)!C.call(t,o)||o===`key`||o===`__self`||o===`__source`||o===`ref`&&t.ref===void 0||(r[o]=t[o]);var o=arguments.length-2;if(o===1)r.children=n;else if(1<o){for(var s=Array(o),c=0;c<o;c++)s[c]=arguments[c+2];r.children=s}return w(e.type,i,void 0,void 0,a,r)},e.createContext=function(e){return e={$$typeof:s,_currentValue:e,_currentValue2:e,_threadCount:0,Provider:null,Consumer:null},e.Provider=e,e.Consumer={$$typeof:o,_context:e},e},e.createElement=function(e,t,n){var r,i={},a=null;if(t!=null)for(r in t.key!==void 0&&(a=``+t.key),t)C.call(t,r)&&r!==`key`&&r!==`__self`&&r!==`__source`&&(i[r]=t[r]);var o=arguments.length-2;if(o===1)i.children=n;else if(1<o){for(var s=Array(o),c=0;c<o;c++)s[c]=arguments[c+2];i.children=s}if(e&&e.defaultProps)for(r in o=e.defaultProps,o)i[r]===void 0&&(i[r]=o[r]);return w(e,a,void 0,void 0,null,i)},e.createRef=function(){return{current:null}},e.forwardRef=function(e){return{$$typeof:c,render:e}},e.isValidElement=E,e.lazy=function(e){return{$$typeof:d,_payload:{_status:-1,_result:e},_init:te}},e.memo=function(e,t){return{$$typeof:u,type:e,compare:t===void 0?null:t}},e.startTransition=function(e){var t=S.T,n={};S.T=n;try{var r=e(),i=S.S;i!==null&&i(n,r),typeof r==`object`&&r&&typeof r.then==`function`&&r.then(N,ne)}catch(e){ne(e)}finally{S.T=t}},e.unstable_useCacheRefresh=function(){return S.H.useCacheRefresh()},e.use=function(e){return S.H.use(e)},e.useActionState=function(e,t,n){return S.H.useActionState(e,t,n)},e.useCallback=function(e,t){return S.H.useCallback(e,t)},e.useContext=function(e){return S.H.useContext(e)},e.useDebugValue=function(){},e.useDeferredValue=function(e,t){return S.H.useDeferredValue(e,t)},e.useEffect=function(e,t,n){var r=S.H;if(typeof n==`function`)throw Error(`useEffect CRUD overload is not enabled in this build of React.`);return r.useEffect(e,t)},e.useId=function(){return S.H.useId()},e.useImperativeHandle=function(e,t,n){return S.H.useImperativeHandle(e,t,n)},e.useInsertionEffect=function(e,t){return S.H.useInsertionEffect(e,t)},e.useLayoutEffect=function(e,t){return S.H.useLayoutEffect(e,t)},e.useMemo=function(e,t){return S.H.useMemo(e,t)},e.useOptimistic=function(e,t){return S.H.useOptimistic(e,t)},e.useReducer=function(e,t,n){return S.H.useReducer(e,t,n)},e.useRef=function(e){return S.H.useRef(e)},e.useState=function(e){return S.H.useState(e)},e.useSyncExternalStore=function(e,t,n){return S.H.useSyncExternalStore(e,t,n)},e.useTransition=function(){return S.H.useTransition()},e.version=`19.1.0`})),u=o(((e,t)=>{t.exports=l()})),d=o((e=>{function t(e,t){var n=e.length;e.push(t);a:for(;0<n;){var r=n-1>>>1,a=e[r];if(0<i(a,t))e[r]=t,e[n]=a,n=r;else break a}}function n(e){return e.length===0?null:e[0]}function r(e){if(e.length===0)return null;var t=e[0],n=e.pop();if(n!==t){e[0]=n;a:for(var r=0,a=e.length,o=a>>>1;r<o;){var s=2*(r+1)-1,c=e[s],l=s+1,u=e[l];if(0>i(c,n))l<a&&0>i(u,c)?(e[r]=u,e[l]=n,r=l):(e[r]=c,e[s]=n,r=s);else if(l<a&&0>i(u,n))e[r]=u,e[l]=n,r=l;else break a}}return t}function i(e,t){var n=e.sortIndex-t.sortIndex;return n===0?e.id-t.id:n}if(e.unstable_now=void 0,typeof performance==`object`&&typeof performance.now==`function`){var a=performance;e.unstable_now=function(){return a.now()}}else{var o=Date,s=o.now();e.unstable_now=function(){return o.now()-s}}var c=[],l=[],u=1,d=null,f=3,p=!1,m=!1,h=!1,g=!1,_=typeof setTimeout==`function`?setTimeout:null,v=typeof clearTimeout==`function`?clearTimeout:null,y=typeof setImmediate<`u`?setImmediate:null;function b(e){for(var i=n(l);i!==null;){if(i.callback===null)r(l);else if(i.startTime<=e)r(l),i.sortIndex=i.expirationTime,t(c,i);else break;i=n(l)}}function x(e){if(h=!1,b(e),!m){if(n(c)!==null)m=!0,S||(S=!0,O());else{var t=n(l);t!==null&&j(x,t.startTime-e)}}}var S=!1,C=-1,w=5,T=-1;function E(){return g?!0:!(e.unstable_now()-T<w)}function D(){if(g=!1,S){var t=e.unstable_now();T=t;var i=!0;try{a:{m=!1,h&&(h=!1,v(C),C=-1),p=!0;var a=f;try{b:{for(b(t),d=n(c);d!==null&&!(d.expirationTime>t&&E());){var o=d.callback;if(typeof o==`function`){d.callback=null,f=d.priorityLevel;var s=o(d.expirationTime<=t);if(t=e.unstable_now(),typeof s==`function`){d.callback=s,b(t),i=!0;break b}d===n(c)&&r(c),b(t)}else r(c);d=n(c)}if(d!==null)i=!0;else{var u=n(l);u!==null&&j(x,u.startTime-t),i=!1}}break a}finally{d=null,f=a,p=!1}i=void 0}}finally{i?O():S=!1}}}var O;if(typeof y==`function`)O=function(){y(D)};else if(typeof MessageChannel<`u`){var k=new MessageChannel,A=k.port2;k.port1.onmessage=D,O=function(){A.postMessage(null)}}else O=function(){_(D,0)};function j(t,n){C=_(function(){t(e.unstable_now())},n)}e.unstable_IdlePriority=5,e.unstable_ImmediatePriority=1,e.unstable_LowPriority=4,e.unstable_NormalPriority=3,e.unstable_Profiling=null,e.unstable_UserBlockingPriority=2,e.unstable_cancelCallback=function(e){e.callback=null},e.unstable_forceFrameRate=function(e){0>e||125<e?console.error(`forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported`):w=0<e?Math.floor(1e3/e):5},e.unstable_getCurrentPriorityLevel=function(){return f},e.unstable_next=function(e){switch(f){case 1:case 2:case 3:var t=3;break;default:t=f}var n=f;f=t;try{return e()}finally{f=n}},e.unstable_requestPaint=function(){g=!0},e.unstable_runWithPriority=function(e,t){switch(e){case 1:case 2:case 3:case 4:case 5:break;default:e=3}var n=f;f=e;try{return t()}finally{f=n}},e.unstable_scheduleCallback=function(r,i,a){var o=e.unstable_now();switch(typeof a==`object`&&a?(a=a.delay,a=typeof a==`number`&&0<a?o+a:o):a=o,r){case 1:var s=-1;break;case 2:s=250;break;case 5:s=1073741823;break;case 4:s=1e4;break;default:s=5e3}return s=a+s,r={id:u++,callback:i,priorityLevel:r,startTime:a,expirationTime:s,sortIndex:-1},a>o?(r.sortIndex=a,t(l,r),n(c)===null&&r===n(l)&&(h?(v(C),C=-1):h=!0,j(x,a-o))):(r.sortIndex=s,t(c,r),m||p||(m=!0,S||(S=!0,O()))),r},e.unstable_shouldYield=E,e.unstable_wrapCallback=function(e){var t=f;return function(){var n=f;f=t;try{return e.apply(this,arguments)}finally{f=n}}}})),f=o(((e,t)=>{t.exports=d()})),p=o((e=>{var t=u();function n(e){var t=`https://react.dev/errors/`+e;if(1<arguments.length){t+=`?args[]=`+encodeURIComponent(arguments[1]);for(var n=2;n<arguments.length;n++)t+=`&args[]=`+encodeURIComponent(arguments[n])}return`Minified React error #`+e+`; visit `+t+` for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`}function r(){}var i={d:{f:r,r:function(){throw Error(n(522))},D:r,C:r,L:r,m:r,X:r,S:r,M:r},p:0,findDOMNode:null},a=Symbol.for(`react.portal`);function o(e,t,n){var r=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:a,key:r==null?null:``+r,children:e,containerInfo:t,implementation:n}}var s=t.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;function c(e,t){if(e===`font`)return``;if(typeof t==`string`)return t===`use-credentials`?t:``}e.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=i,e.createPortal=function(e,t){var r=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!t||t.nodeType!==1&&t.nodeType!==9&&t.nodeType!==11)throw Error(n(299));return o(e,t,null,r)},e.flushSync=function(e){var t=s.T,n=i.p;try{if(s.T=null,i.p=2,e)return e()}finally{s.T=t,i.p=n,i.d.f()}},e.preconnect=function(e,t){typeof e==`string`&&(t?(t=t.crossOrigin,t=typeof t==`string`?t===`use-credentials`?t:``:void 0):t=null,i.d.C(e,t))},e.prefetchDNS=function(e){typeof e==`string`&&i.d.D(e)},e.preinit=function(e,t){if(typeof e==`string`&&t&&typeof t.as==`string`){var n=t.as,r=c(n,t.crossOrigin),a=typeof t.integrity==`string`?t.integrity:void 0,o=typeof t.fetchPriority==`string`?t.fetchPriority:void 0;n===`style`?i.d.S(e,typeof t.precedence==`string`?t.precedence:void 0,{crossOrigin:r,integrity:a,fetchPriority:o}):n===`script`&&i.d.X(e,{crossOrigin:r,integrity:a,fetchPriority:o,nonce:typeof t.nonce==`string`?t.nonce:void 0})}},e.preinitModule=function(e,t){if(typeof e==`string`){if(typeof t==`object`&&t){if(t.as==null||t.as===`script`){var n=c(t.as,t.crossOrigin);i.d.M(e,{crossOrigin:n,integrity:typeof t.integrity==`string`?t.integrity:void 0,nonce:typeof t.nonce==`string`?t.nonce:void 0})}}else t??i.d.M(e)}},e.preload=function(e,t){if(typeof e==`string`&&typeof t==`object`&&t&&typeof t.as==`string`){var n=t.as,r=c(n,t.crossOrigin);i.d.L(e,n,{crossOrigin:r,integrity:typeof t.integrity==`string`?t.integrity:void 0,nonce:typeof t.nonce==`string`?t.nonce:void 0,type:typeof t.type==`string`?t.type:void 0,fetchPriority:typeof t.fetchPriority==`string`?t.fetchPriority:void 0,referrerPolicy:typeof t.referrerPolicy==`string`?t.referrerPolicy:void 0,imageSrcSet:typeof t.imageSrcSet==`string`?t.imageSrcSet:void 0,imageSizes:typeof t.imageSizes==`string`?t.imageSizes:void 0,media:typeof t.media==`string`?t.media:void 0})}},e.preloadModule=function(e,t){if(typeof e==`string`){if(t){var n=c(t.as,t.crossOrigin);i.d.m(e,{as:typeof t.as==`string`&&t.as!==`script`?t.as:void 0,crossOrigin:n,integrity:typeof t.integrity==`string`?t.integrity:void 0})}else i.d.m(e)}},e.requestFormReset=function(e){i.d.r(e)},e.unstable_batchedUpdates=function(e,t){return e(t)},e.useFormState=function(e,t,n){return s.H.useFormState(e,t,n)},e.useFormStatus=function(){return s.H.useHostTransitionStatus()},e.version=`19.1.0`})),m=o(((e,t)=>{function n(){if(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<`u`&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE==`function`)try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(n)}catch(e){console.error(e)}}n(),t.exports=p()})),h=o((e=>{var t=f(),n=u(),r=m();function i(e){var t=`https://react.dev/errors/`+e;if(1<arguments.length){t+=`?args[]=`+encodeURIComponent(arguments[1]);for(var n=2;n<arguments.length;n++)t+=`&args[]=`+encodeURIComponent(arguments[n])}return`Minified React error #`+e+`; visit `+t+` for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`}function a(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11)}function o(e){var t=e,n=e;if(e.alternate)for(;t.return;)t=t.return;else{e=t;do t=e,t.flags&4098&&(n=t.return),e=t.return;while(e)}return t.tag===3?n:null}function s(e){if(e.tag===13){var t=e.memoizedState;if(t===null&&(e=e.alternate,e!==null&&(t=e.memoizedState)),t!==null)return t.dehydrated}return null}function c(e){if(o(e)!==e)throw Error(i(188))}function l(e){var t=e.alternate;if(!t){if(t=o(e),t===null)throw Error(i(188));return t===e?e:null}for(var n=e,r=t;;){var a=n.return;if(a===null)break;var s=a.alternate;if(s===null){if(r=a.return,r!==null){n=r;continue}break}if(a.child===s.child){for(s=a.child;s;){if(s===n)return c(a),e;if(s===r)return c(a),t;s=s.sibling}throw Error(i(188))}if(n.return!==r.return)n=a,r=s;else{for(var l=!1,u=a.child;u;){if(u===n){l=!0,n=a,r=s;break}if(u===r){l=!0,r=a,n=s;break}u=u.sibling}if(!l){for(u=s.child;u;){if(u===n){l=!0,n=s,r=a;break}if(u===r){l=!0,r=s,n=a;break}u=u.sibling}if(!l)throw Error(i(189))}}if(n.alternate!==r)throw Error(i(190))}if(n.tag!==3)throw Error(i(188));return n.stateNode.current===n?e:t}function d(e){var t=e.tag;if(t===5||t===26||t===27||t===6)return e;for(e=e.child;e!==null;){if(t=d(e),t!==null)return t;e=e.sibling}return null}var p=Object.assign,h=Symbol.for(`react.element`),g=Symbol.for(`react.transitional.element`),_=Symbol.for(`react.portal`),v=Symbol.for(`react.fragment`),y=Symbol.for(`react.strict_mode`),b=Symbol.for(`react.profiler`),x=Symbol.for(`react.provider`),S=Symbol.for(`react.consumer`),C=Symbol.for(`react.context`),w=Symbol.for(`react.forward_ref`),T=Symbol.for(`react.suspense`),E=Symbol.for(`react.suspense_list`),D=Symbol.for(`react.memo`),O=Symbol.for(`react.lazy`),k=Symbol.for(`react.activity`),A=Symbol.for(`react.memo_cache_sentinel`),j=Symbol.iterator;function M(e){return typeof e!=`object`||!e?null:(e=j&&e[j]||e[`@@iterator`],typeof e==`function`?e:null)}var ee=Symbol.for(`react.client.reference`);function te(e){if(e==null)return null;if(typeof e==`function`)return e.$$typeof===ee?null:e.displayName||e.name||null;if(typeof e==`string`)return e;switch(e){case v:return`Fragment`;case b:return`Profiler`;case y:return`StrictMode`;case T:return`Suspense`;case E:return`SuspenseList`;case k:return`Activity`}if(typeof e==`object`)switch(e.$$typeof){case _:return`Portal`;case C:return(e.displayName||`Context`)+`.Provider`;case S:return(e._context.displayName||`Context`)+`.Consumer`;case w:var t=e.render;return e=e.displayName,e||=(e=t.displayName||t.name||``,e===``?`ForwardRef`:`ForwardRef(`+e+`)`),e;case D:return t=e.displayName||null,t===null?te(e.type)||`Memo`:t;case O:t=e._payload,e=e._init;try{return te(e(t))}catch{}}return null}var ne=Array.isArray,N=n.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,P=r.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,F={pending:!1,data:null,method:null,action:null},re=[],I=-1;function L(e){return{current:e}}function R(e){0>I||(e.current=re[I],re[I]=null,I--)}function z(e,t){I++,re[I]=e.current,e.current=t}var ie=L(null),ae=L(null),oe=L(null),se=L(null);function ce(e,t){switch(z(oe,t),z(ae,e),z(ie,null),t.nodeType){case 9:case 11:e=(e=t.documentElement)&&(e=e.namespaceURI)?jd(e):0;break;default:if(e=t.tagName,t=t.namespaceURI)t=jd(t),e=Md(t,e);else switch(e){case`svg`:e=1;break;case`math`:e=2;break;default:e=0}}R(ie),z(ie,e)}function le(){R(ie),R(ae),R(oe)}function ue(e){e.memoizedState!==null&&z(se,e);var t=ie.current,n=Md(t,e.type);t!==n&&(z(ae,e),z(ie,n))}function de(e){ae.current===e&&(R(ie),R(ae)),se.current===e&&(R(se),zf._currentValue=F)}var fe=Object.prototype.hasOwnProperty,pe=t.unstable_scheduleCallback,B=t.unstable_cancelCallback,me=t.unstable_shouldYield,he=t.unstable_requestPaint,ge=t.unstable_now,_e=t.unstable_getCurrentPriorityLevel,ve=t.unstable_ImmediatePriority,V=t.unstable_UserBlockingPriority,ye=t.unstable_NormalPriority,be=t.unstable_LowPriority,xe=t.unstable_IdlePriority,Se=t.log,Ce=t.unstable_setDisableYieldValue,H=null,we=null;function Te(e){if(typeof Se==`function`&&Ce(e),we&&typeof we.setStrictMode==`function`)try{we.setStrictMode(H,e)}catch{}}var Ee=Math.clz32?Math.clz32:ke,De=Math.log,Oe=Math.LN2;function ke(e){return e>>>=0,e===0?32:31-(De(e)/Oe|0)|0}var Ae=256,je=4194304;function Me(e){var t=e&42;if(t!==0)return t;switch(e&-e){case 1:return 1;case 2:return 2;case 4:return 4;case 8:return 8;case 16:return 16;case 32:return 32;case 64:return 64;case 128:return 128;case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:return e&4194048;case 4194304:case 8388608:case 16777216:case 33554432:return e&62914560;case 67108864:return 67108864;case 134217728:return 134217728;case 268435456:return 268435456;case 536870912:return 536870912;case 1073741824:return 0;default:return e}}function Ne(e,t,n){var r=e.pendingLanes;if(r===0)return 0;var i=0,a=e.suspendedLanes,o=e.pingedLanes;e=e.warmLanes;var s=r&134217727;return s===0?(s=r&~a,s===0?o===0?n||(n=r&~e,n!==0&&(i=Me(n))):i=Me(o):i=Me(s)):(r=s&~a,r===0?(o&=s,o===0?n||(n=s&~e,n!==0&&(i=Me(n))):i=Me(o)):i=Me(r)),i===0?0:t!==0&&t!==i&&(t&a)===0&&(a=i&-i,n=t&-t,a>=n||a===32&&n&4194048)?t:i}function Pe(e,t){return(e.pendingLanes&~(e.suspendedLanes&~e.pingedLanes)&t)===0}function Fe(e,t){switch(e){case 1:case 2:case 4:case 8:case 64:return t+250;case 16:case 32:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:return t+5e3;case 4194304:case 8388608:case 16777216:case 33554432:return-1;case 67108864:case 134217728:case 268435456:case 536870912:case 1073741824:return-1;default:return-1}}function Ie(){var e=Ae;return Ae<<=1,!(Ae&4194048)&&(Ae=256),e}function Le(){var e=je;return je<<=1,!(je&62914560)&&(je=4194304),e}function Re(e){for(var t=[],n=0;31>n;n++)t.push(e);return t}function ze(e,t){e.pendingLanes|=t,t!==268435456&&(e.suspendedLanes=0,e.pingedLanes=0,e.warmLanes=0)}function Be(e,t,n,r,i,a){var o=e.pendingLanes;e.pendingLanes=n,e.suspendedLanes=0,e.pingedLanes=0,e.warmLanes=0,e.expiredLanes&=n,e.entangledLanes&=n,e.errorRecoveryDisabledLanes&=n,e.shellSuspendCounter=0;var s=e.entanglements,c=e.expirationTimes,l=e.hiddenUpdates;for(n=o&~n;0<n;){var u=31-Ee(n),d=1<<u;s[u]=0,c[u]=-1;var f=l[u];if(f!==null)for(l[u]=null,u=0;u<f.length;u++){var p=f[u];p!==null&&(p.lane&=-536870913)}n&=~d}r!==0&&Ve(e,r,0),a!==0&&i===0&&e.tag!==0&&(e.suspendedLanes|=a&~(o&~t))}function Ve(e,t,n){e.pendingLanes|=t,e.suspendedLanes&=~t;var r=31-Ee(t);e.entangledLanes|=t,e.entanglements[r]=e.entanglements[r]|1073741824|n&4194090}function He(e,t){var n=e.entangledLanes|=t;for(e=e.entanglements;n;){var r=31-Ee(n),i=1<<r;i&t|e[r]&t&&(e[r]|=t),n&=~i}}function Ue(e){switch(e){case 2:e=1;break;case 8:e=4;break;case 32:e=16;break;case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:case 4194304:case 8388608:case 16777216:case 33554432:e=128;break;case 268435456:e=134217728;break;default:e=0}return e}function We(e){return e&=-e,2<e?8<e?e&134217727?32:268435456:8:2}function Ge(){var e=P.p;return e===0?(e=window.event,e===void 0?32:ep(e.type)):e}function Ke(e,t){var n=P.p;try{return P.p=e,t()}finally{P.p=n}}var qe=Math.random().toString(36).slice(2),Je=`__reactFiber$`+qe,Ye=`__reactProps$`+qe,Xe=`__reactContainer$`+qe,Ze=`__reactEvents$`+qe,Qe=`__reactListeners$`+qe,$e=`__reactHandles$`+qe,et=`__reactResources$`+qe,tt=`__reactMarker$`+qe;function nt(e){delete e[Je],delete e[Ye],delete e[Ze],delete e[Qe],delete e[$e]}function rt(e){var t=e[Je];if(t)return t;for(var n=e.parentNode;n;){if(t=n[Xe]||n[Je]){if(n=t.alternate,t.child!==null||n!==null&&n.child!==null)for(e=Xd(e);e!==null;){if(n=e[Je])return n;e=Xd(e)}return t}e=n,n=e.parentNode}return null}function it(e){if(e=e[Je]||e[Xe]){var t=e.tag;if(t===5||t===6||t===13||t===26||t===27||t===3)return e}return null}function at(e){var t=e.tag;if(t===5||t===26||t===27||t===6)return e.stateNode;throw Error(i(33))}function ot(e){var t=e[et];return t||=e[et]={hoistableStyles:new Map,hoistableScripts:new Map},t}function st(e){e[tt]=!0}var ct=new Set,lt={};function ut(e,t){dt(e,t),dt(e+`Capture`,t)}function dt(e,t){for(lt[e]=t,e=0;e<t.length;e++)ct.add(t[e])}var ft=RegExp(`^[:A-Z_a-z\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD][:A-Z_a-z\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD\\-.0-9\\u00B7\\u0300-\\u036F\\u203F-\\u2040]*$`),pt={},mt={};function ht(e){return fe.call(mt,e)?!0:fe.call(pt,e)?!1:ft.test(e)?mt[e]=!0:(pt[e]=!0,!1)}function gt(e,t,n){if(ht(t)){if(n===null)e.removeAttribute(t);else{switch(typeof n){case`undefined`:case`function`:case`symbol`:e.removeAttribute(t);return;case`boolean`:var r=t.toLowerCase().slice(0,5);if(r!==`data-`&&r!==`aria-`){e.removeAttribute(t);return}}e.setAttribute(t,``+n)}}}function _t(e,t,n){if(n===null)e.removeAttribute(t);else{switch(typeof n){case`undefined`:case`function`:case`symbol`:case`boolean`:e.removeAttribute(t);return}e.setAttribute(t,``+n)}}function vt(e,t,n,r){if(r===null)e.removeAttribute(n);else{switch(typeof r){case`undefined`:case`function`:case`symbol`:case`boolean`:e.removeAttribute(n);return}e.setAttributeNS(t,n,``+r)}}var yt,bt;function xt(e){if(yt===void 0)try{throw Error()}catch(e){var t=e.stack.trim().match(/\n( *(at )?)/);yt=t&&t[1]||``,bt=-1<e.stack.indexOf(`
|
|
3
|
-
at`)?` (<anonymous>)`:-1<e.stack.indexOf(`@`)?`@unknown:0:0`:``}return`
|
|
4
|
-
`+yt+e+bt}var St=!1;function Ct(e,t){if(!e||St)return``;St=!0;var n=Error.prepareStackTrace;Error.prepareStackTrace=void 0;try{var r={DetermineComponentFrameRoot:function(){try{if(t){var n=function(){throw Error()};if(Object.defineProperty(n.prototype,"props",{set:function(){throw Error()}}),typeof Reflect==`object`&&Reflect.construct){try{Reflect.construct(n,[])}catch(e){var r=e}Reflect.construct(e,[],n)}else{try{n.call()}catch(e){r=e}e.call(n.prototype)}}else{try{throw Error()}catch(e){r=e}(n=e())&&typeof n.catch==`function`&&n.catch(function(){})}}catch(e){if(e&&r&&typeof e.stack==`string`)return[e.stack,r.stack]}return[null,null]}};r.DetermineComponentFrameRoot.displayName=`DetermineComponentFrameRoot`;var i=Object.getOwnPropertyDescriptor(r.DetermineComponentFrameRoot,`name`);i&&i.configurable&&Object.defineProperty(r.DetermineComponentFrameRoot,"name",{value:`DetermineComponentFrameRoot`});var a=r.DetermineComponentFrameRoot(),o=a[0],s=a[1];if(o&&s){var c=o.split(`
|
|
5
|
-
`),l=s.split(`
|
|
6
|
-
`);for(i=r=0;r<c.length&&!c[r].includes(`DetermineComponentFrameRoot`);)r++;for(;i<l.length&&!l[i].includes(`DetermineComponentFrameRoot`);)i++;if(r===c.length||i===l.length)for(r=c.length-1,i=l.length-1;1<=r&&0<=i&&c[r]!==l[i];)i--;for(;1<=r&&0<=i;r--,i--)if(c[r]!==l[i]){if(r!==1||i!==1)do if(r--,i--,0>i||c[r]!==l[i]){var u=`
|
|
7
|
-
`+c[r].replace(` at new `,` at `);return e.displayName&&u.includes(`<anonymous>`)&&(u=u.replace(`<anonymous>`,e.displayName)),u}while(1<=r&&0<=i);break}}}finally{St=!1,Error.prepareStackTrace=n}return(n=e?e.displayName||e.name:``)?xt(n):``}function U(e){switch(e.tag){case 26:case 27:case 5:return xt(e.type);case 16:return xt(`Lazy`);case 13:return xt(`Suspense`);case 19:return xt(`SuspenseList`);case 0:case 15:return Ct(e.type,!1);case 11:return Ct(e.type.render,!1);case 1:return Ct(e.type,!0);case 31:return xt(`Activity`);default:return``}}function wt(e){try{var t=``;do t+=U(e),e=e.return;while(e);return t}catch(e){return`
|
|
8
|
-
Error generating stack: `+e.message+`
|
|
9
|
-
`+e.stack}}function Tt(e){switch(typeof e){case`bigint`:case`boolean`:case`number`:case`string`:case`undefined`:return e;case`object`:return e;default:return``}}function Et(e){var t=e.type;return(e=e.nodeName)&&e.toLowerCase()===`input`&&(t===`checkbox`||t===`radio`)}function Dt(e){var t=Et(e)?`checked`:`value`,n=Object.getOwnPropertyDescriptor(e.constructor.prototype,t),r=``+e[t];if(!e.hasOwnProperty(t)&&n!==void 0&&typeof n.get==`function`&&typeof n.set==`function`){var i=n.get,a=n.set;return Object.defineProperty(e,t,{configurable:!0,get:function(){return i.call(this)},set:function(e){r=``+e,a.call(this,e)}}),Object.defineProperty(e,t,{enumerable:n.enumerable}),{getValue:function(){return r},setValue:function(e){r=``+e},stopTracking:function(){e._valueTracker=null,delete e[t]}}}}function Ot(e){e._valueTracker||=Dt(e)}function kt(e){if(!e)return!1;var t=e._valueTracker;if(!t)return!0;var n=t.getValue(),r=``;return e&&(r=Et(e)?e.checked?`true`:`false`:e.value),e=r,e!==n&&(t.setValue(e),!0)}function At(e){if(e||=typeof document<`u`?document:void 0,e===void 0)return null;try{return e.activeElement||e.body}catch{return e.body}}var jt=/[\n"\\]/g;function Mt(e){return e.replace(jt,function(e){return`\\`+e.charCodeAt(0).toString(16)+` `})}function Nt(e,t,n,r,i,a,o,s){e.name=``,o!=null&&typeof o!=`function`&&typeof o!=`symbol`&&typeof o!=`boolean`?e.type=o:e.removeAttribute(`type`),t==null?o!==`submit`&&o!==`reset`||e.removeAttribute(`value`):o===`number`?(t===0&&e.value===``||e.value!=t)&&(e.value=``+Tt(t)):e.value!==``+Tt(t)&&(e.value=``+Tt(t)),t==null?n==null?r!=null&&e.removeAttribute(`value`):Ft(e,o,Tt(n)):Ft(e,o,Tt(t)),i==null&&a!=null&&(e.defaultChecked=!!a),i!=null&&(e.checked=i&&typeof i!=`function`&&typeof i!=`symbol`),s!=null&&typeof s!=`function`&&typeof s!=`symbol`&&typeof s!=`boolean`?e.name=``+Tt(s):e.removeAttribute(`name`)}function Pt(e,t,n,r,i,a,o,s){if(a!=null&&typeof a!=`function`&&typeof a!=`symbol`&&typeof a!=`boolean`&&(e.type=a),t!=null||n!=null){if(!(a!==`submit`&&a!==`reset`||t!=null))return;n=n==null?``:``+Tt(n),t=t==null?n:``+Tt(t),s||t===e.value||(e.value=t),e.defaultValue=t}r??=i,r=typeof r!=`function`&&typeof r!=`symbol`&&!!r,e.checked=s?e.checked:!!r,e.defaultChecked=!!r,o!=null&&typeof o!=`function`&&typeof o!=`symbol`&&typeof o!=`boolean`&&(e.name=o)}function Ft(e,t,n){t===`number`&&At(e.ownerDocument)===e||e.defaultValue===``+n||(e.defaultValue=``+n)}function It(e,t,n,r){if(e=e.options,t){t={};for(var i=0;i<n.length;i++)t[`$`+n[i]]=!0;for(n=0;n<e.length;n++)i=t.hasOwnProperty(`$`+e[n].value),e[n].selected!==i&&(e[n].selected=i),i&&r&&(e[n].defaultSelected=!0)}else{for(n=``+Tt(n),t=null,i=0;i<e.length;i++){if(e[i].value===n){e[i].selected=!0,r&&(e[i].defaultSelected=!0);return}t!==null||e[i].disabled||(t=e[i])}t!==null&&(t.selected=!0)}}function Lt(e,t,n){t!=null&&(t=``+Tt(t),t!==e.value&&(e.value=t),n==null)?e.defaultValue!==t&&(e.defaultValue=t):e.defaultValue=n==null?``:``+Tt(n)}function Rt(e,t,n,r){if(t==null){if(r!=null){if(n!=null)throw Error(i(92));if(ne(r)){if(1<r.length)throw Error(i(93));r=r[0]}n=r}n??=``,t=n}n=Tt(t),e.defaultValue=n,r=e.textContent,r===n&&r!==``&&r!==null&&(e.value=r)}function zt(e,t){if(t){var n=e.firstChild;if(n&&n===e.lastChild&&n.nodeType===3){n.nodeValue=t;return}}e.textContent=t}var Bt=new Set(`animationIterationCount aspectRatio borderImageOutset borderImageSlice borderImageWidth boxFlex boxFlexGroup boxOrdinalGroup columnCount columns flex flexGrow flexPositive flexShrink flexNegative flexOrder gridArea gridRow gridRowEnd gridRowSpan gridRowStart gridColumn gridColumnEnd gridColumnSpan gridColumnStart fontWeight lineClamp lineHeight opacity order orphans scale tabSize widows zIndex zoom fillOpacity floodOpacity stopOpacity strokeDasharray strokeDashoffset strokeMiterlimit strokeOpacity strokeWidth MozAnimationIterationCount MozBoxFlex MozBoxFlexGroup MozLineClamp msAnimationIterationCount msFlex msZoom msFlexGrow msFlexNegative msFlexOrder msFlexPositive msFlexShrink msGridColumn msGridColumnSpan msGridRow msGridRowSpan WebkitAnimationIterationCount WebkitBoxFlex WebKitBoxFlexGroup WebkitBoxOrdinalGroup WebkitColumnCount WebkitColumns WebkitFlex WebkitFlexGrow WebkitFlexPositive WebkitFlexShrink WebkitLineClamp`.split(` `));function Vt(e,t,n){var r=t.indexOf(`--`)===0;n==null||typeof n==`boolean`||n===``?r?e.setProperty(t,``):t===`float`?e.cssFloat=``:e[t]=``:r?e.setProperty(t,n):typeof n!=`number`||n===0||Bt.has(t)?t===`float`?e.cssFloat=n:e[t]=(``+n).trim():e[t]=n+`px`}function Ht(e,t,n){if(t!=null&&typeof t!=`object`)throw Error(i(62));if(e=e.style,n!=null){for(var r in n)!n.hasOwnProperty(r)||t!=null&&t.hasOwnProperty(r)||(r.indexOf(`--`)===0?e.setProperty(r,``):r===`float`?e.cssFloat=``:e[r]=``);for(var a in t)r=t[a],t.hasOwnProperty(a)&&n[a]!==r&&Vt(e,a,r)}else for(var o in t)t.hasOwnProperty(o)&&Vt(e,o,t[o])}function Ut(e){if(e.indexOf(`-`)===-1)return!1;switch(e){case`annotation-xml`:case`color-profile`:case`font-face`:case`font-face-src`:case`font-face-uri`:case`font-face-format`:case`font-face-name`:case`missing-glyph`:return!1;default:return!0}}var Wt=new Map([[`acceptCharset`,`accept-charset`],[`htmlFor`,`for`],[`httpEquiv`,`http-equiv`],[`crossOrigin`,`crossorigin`],[`accentHeight`,`accent-height`],[`alignmentBaseline`,`alignment-baseline`],[`arabicForm`,`arabic-form`],[`baselineShift`,`baseline-shift`],[`capHeight`,`cap-height`],[`clipPath`,`clip-path`],[`clipRule`,`clip-rule`],[`colorInterpolation`,`color-interpolation`],[`colorInterpolationFilters`,`color-interpolation-filters`],[`colorProfile`,`color-profile`],[`colorRendering`,`color-rendering`],[`dominantBaseline`,`dominant-baseline`],[`enableBackground`,`enable-background`],[`fillOpacity`,`fill-opacity`],[`fillRule`,`fill-rule`],[`floodColor`,`flood-color`],[`floodOpacity`,`flood-opacity`],[`fontFamily`,`font-family`],[`fontSize`,`font-size`],[`fontSizeAdjust`,`font-size-adjust`],[`fontStretch`,`font-stretch`],[`fontStyle`,`font-style`],[`fontVariant`,`font-variant`],[`fontWeight`,`font-weight`],[`glyphName`,`glyph-name`],[`glyphOrientationHorizontal`,`glyph-orientation-horizontal`],[`glyphOrientationVertical`,`glyph-orientation-vertical`],[`horizAdvX`,`horiz-adv-x`],[`horizOriginX`,`horiz-origin-x`],[`imageRendering`,`image-rendering`],[`letterSpacing`,`letter-spacing`],[`lightingColor`,`lighting-color`],[`markerEnd`,`marker-end`],[`markerMid`,`marker-mid`],[`markerStart`,`marker-start`],[`overlinePosition`,`overline-position`],[`overlineThickness`,`overline-thickness`],[`paintOrder`,`paint-order`],[`panose-1`,`panose-1`],[`pointerEvents`,`pointer-events`],[`renderingIntent`,`rendering-intent`],[`shapeRendering`,`shape-rendering`],[`stopColor`,`stop-color`],[`stopOpacity`,`stop-opacity`],[`strikethroughPosition`,`strikethrough-position`],[`strikethroughThickness`,`strikethrough-thickness`],[`strokeDasharray`,`stroke-dasharray`],[`strokeDashoffset`,`stroke-dashoffset`],[`strokeLinecap`,`stroke-linecap`],[`strokeLinejoin`,`stroke-linejoin`],[`strokeMiterlimit`,`stroke-miterlimit`],[`strokeOpacity`,`stroke-opacity`],[`strokeWidth`,`stroke-width`],[`textAnchor`,`text-anchor`],[`textDecoration`,`text-decoration`],[`textRendering`,`text-rendering`],[`transformOrigin`,`transform-origin`],[`underlinePosition`,`underline-position`],[`underlineThickness`,`underline-thickness`],[`unicodeBidi`,`unicode-bidi`],[`unicodeRange`,`unicode-range`],[`unitsPerEm`,`units-per-em`],[`vAlphabetic`,`v-alphabetic`],[`vHanging`,`v-hanging`],[`vIdeographic`,`v-ideographic`],[`vMathematical`,`v-mathematical`],[`vectorEffect`,`vector-effect`],[`vertAdvY`,`vert-adv-y`],[`vertOriginX`,`vert-origin-x`],[`vertOriginY`,`vert-origin-y`],[`wordSpacing`,`word-spacing`],[`writingMode`,`writing-mode`],[`xmlnsXlink`,`xmlns:xlink`],[`xHeight`,`x-height`]]),Gt=/^[\u0000-\u001F ]*j[\r\n\t]*a[\r\n\t]*v[\r\n\t]*a[\r\n\t]*s[\r\n\t]*c[\r\n\t]*r[\r\n\t]*i[\r\n\t]*p[\r\n\t]*t[\r\n\t]*:/i;function Kt(e){return Gt.test(``+e)?`javascript:throw new Error('React has blocked a javascript: URL as a security precaution.')`:e}var qt=null;function Jt(e){return e=e.target||e.srcElement||window,e.correspondingUseElement&&(e=e.correspondingUseElement),e.nodeType===3?e.parentNode:e}var Yt=null,Xt=null;function Zt(e){var t=it(e);if(t&&(e=t.stateNode)){var n=e[Ye]||null;a:switch(e=t.stateNode,t.type){case`input`:if(Nt(e,n.value,n.defaultValue,n.defaultValue,n.checked,n.defaultChecked,n.type,n.name),t=n.name,n.type===`radio`&&t!=null){for(n=e;n.parentNode;)n=n.parentNode;for(n=n.querySelectorAll(`input[name="`+Mt(``+t)+`"][type="radio"]`),t=0;t<n.length;t++){var r=n[t];if(r!==e&&r.form===e.form){var a=r[Ye]||null;if(!a)throw Error(i(90));Nt(r,a.value,a.defaultValue,a.defaultValue,a.checked,a.defaultChecked,a.type,a.name)}}for(t=0;t<n.length;t++)r=n[t],r.form===e.form&&kt(r)}break a;case`textarea`:Lt(e,n.value,n.defaultValue);break a;case`select`:t=n.value,t!=null&&It(e,!!n.multiple,t,!1)}}}var Qt=!1;function $t(e,t,n){if(Qt)return e(t,n);Qt=!0;try{return e(t)}finally{if(Qt=!1,(Yt!==null||Xt!==null)&&(du(),Yt&&(t=Yt,e=Xt,Xt=Yt=null,Zt(t),e)))for(t=0;t<e.length;t++)Zt(e[t])}}function en(e,t){var n=e.stateNode;if(n===null)return null;var r=n[Ye]||null;if(r===null)return null;n=r[t];a:switch(t){case`onClick`:case`onClickCapture`:case`onDoubleClick`:case`onDoubleClickCapture`:case`onMouseDown`:case`onMouseDownCapture`:case`onMouseMove`:case`onMouseMoveCapture`:case`onMouseUp`:case`onMouseUpCapture`:case`onMouseEnter`:(r=!r.disabled)||(e=e.type,r=e!==`button`&&e!==`input`&&e!==`select`&&e!==`textarea`),e=!r;break a;default:e=!1}if(e)return null;if(n&&typeof n!=`function`)throw Error(i(231,t,typeof n));return n}var tn=typeof window<`u`&&window.document!==void 0&&window.document.createElement!==void 0,nn=!1;if(tn)try{var rn={};Object.defineProperty(rn,"passive",{get:function(){nn=!0}}),window.addEventListener(`test`,rn,rn),window.removeEventListener(`test`,rn,rn)}catch{nn=!1}var an=null,on=null,sn=null;function cn(){if(sn)return sn;var e,t=on,n=t.length,r,i=`value`in an?an.value:an.textContent,a=i.length;for(e=0;e<n&&t[e]===i[e];e++);var o=n-e;for(r=1;r<=o&&t[n-r]===i[a-r];r++);return sn=i.slice(e,1<r?1-r:void 0)}function ln(e){var t=e.keyCode;return`charCode`in e?(e=e.charCode,e===0&&t===13&&(e=13)):e=t,e===10&&(e=13),32<=e||e===13?e:0}function un(){return!0}function dn(){return!1}function fn(e){function t(t,n,r,i,a){for(var o in this._reactName=t,this._targetInst=r,this.type=n,this.nativeEvent=i,this.target=a,this.currentTarget=null,e)e.hasOwnProperty(o)&&(t=e[o],this[o]=t?t(i):i[o]);return this.isDefaultPrevented=(i.defaultPrevented==null?!1===i.returnValue:i.defaultPrevented)?un:dn,this.isPropagationStopped=dn,this}return p(t.prototype,{preventDefault:function(){this.defaultPrevented=!0;var e=this.nativeEvent;e&&(e.preventDefault?e.preventDefault():typeof e.returnValue!=`unknown`&&(e.returnValue=!1),this.isDefaultPrevented=un)},stopPropagation:function(){var e=this.nativeEvent;e&&(e.stopPropagation?e.stopPropagation():typeof e.cancelBubble!=`unknown`&&(e.cancelBubble=!0),this.isPropagationStopped=un)},persist:function(){},isPersistent:un}),t}var pn={eventPhase:0,bubbles:0,cancelable:0,timeStamp:function(e){return e.timeStamp||Date.now()},defaultPrevented:0,isTrusted:0},mn=fn(pn),hn=p({},pn,{view:0,detail:0}),gn=fn(hn),_n,vn,yn,bn=p({},hn,{screenX:0,screenY:0,clientX:0,clientY:0,pageX:0,pageY:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,getModifierState:jn,button:0,buttons:0,relatedTarget:function(e){return e.relatedTarget===void 0?e.fromElement===e.srcElement?e.toElement:e.fromElement:e.relatedTarget},movementX:function(e){return`movementX`in e?e.movementX:(e!==yn&&(yn&&e.type===`mousemove`?(_n=e.screenX-yn.screenX,vn=e.screenY-yn.screenY):vn=_n=0,yn=e),_n)},movementY:function(e){return`movementY`in e?e.movementY:vn}}),xn=fn(bn),Sn=fn(p({},bn,{dataTransfer:0})),Cn=fn(p({},hn,{relatedTarget:0})),wn=fn(p({},pn,{animationName:0,elapsedTime:0,pseudoElement:0})),Tn=fn(p({},pn,{clipboardData:function(e){return`clipboardData`in e?e.clipboardData:window.clipboardData}})),En=fn(p({},pn,{data:0})),Dn={Esc:`Escape`,Spacebar:` `,Left:`ArrowLeft`,Up:`ArrowUp`,Right:`ArrowRight`,Down:`ArrowDown`,Del:`Delete`,Win:`OS`,Menu:`ContextMenu`,Apps:`ContextMenu`,Scroll:`ScrollLock`,MozPrintableKey:`Unidentified`},On={8:`Backspace`,9:`Tab`,12:`Clear`,13:`Enter`,16:`Shift`,17:`Control`,18:`Alt`,19:`Pause`,20:`CapsLock`,27:`Escape`,32:` `,33:`PageUp`,34:`PageDown`,35:`End`,36:`Home`,37:`ArrowLeft`,38:`ArrowUp`,39:`ArrowRight`,40:`ArrowDown`,45:`Insert`,46:`Delete`,112:`F1`,113:`F2`,114:`F3`,115:`F4`,116:`F5`,117:`F6`,118:`F7`,119:`F8`,120:`F9`,121:`F10`,122:`F11`,123:`F12`,144:`NumLock`,145:`ScrollLock`,224:`Meta`},kn={Alt:`altKey`,Control:`ctrlKey`,Meta:`metaKey`,Shift:`shiftKey`};function An(e){var t=this.nativeEvent;return t.getModifierState?t.getModifierState(e):(e=kn[e])?!!t[e]:!1}function jn(){return An}var Mn=fn(p({},hn,{key:function(e){if(e.key){var t=Dn[e.key]||e.key;if(t!==`Unidentified`)return t}return e.type===`keypress`?(e=ln(e),e===13?`Enter`:String.fromCharCode(e)):e.type===`keydown`||e.type===`keyup`?On[e.keyCode]||`Unidentified`:``},code:0,location:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,repeat:0,locale:0,getModifierState:jn,charCode:function(e){return e.type===`keypress`?ln(e):0},keyCode:function(e){return e.type===`keydown`||e.type===`keyup`?e.keyCode:0},which:function(e){return e.type===`keypress`?ln(e):e.type===`keydown`||e.type===`keyup`?e.keyCode:0}})),Nn=fn(p({},bn,{pointerId:0,width:0,height:0,pressure:0,tangentialPressure:0,tiltX:0,tiltY:0,twist:0,pointerType:0,isPrimary:0})),Pn=fn(p({},hn,{touches:0,targetTouches:0,changedTouches:0,altKey:0,metaKey:0,ctrlKey:0,shiftKey:0,getModifierState:jn})),Fn=fn(p({},pn,{propertyName:0,elapsedTime:0,pseudoElement:0})),In=fn(p({},bn,{deltaX:function(e){return`deltaX`in e?e.deltaX:`wheelDeltaX`in e?-e.wheelDeltaX:0},deltaY:function(e){return`deltaY`in e?e.deltaY:`wheelDeltaY`in e?-e.wheelDeltaY:`wheelDelta`in e?-e.wheelDelta:0},deltaZ:0,deltaMode:0})),Ln=fn(p({},pn,{newState:0,oldState:0})),Rn=[9,13,27,32],zn=tn&&`CompositionEvent`in window,Bn=null;tn&&`documentMode`in document&&(Bn=document.documentMode);var Vn=tn&&`TextEvent`in window&&!Bn,Hn=tn&&(!zn||Bn&&8<Bn&&11>=Bn),Un=` `,Wn=!1;function Gn(e,t){switch(e){case`keyup`:return Rn.indexOf(t.keyCode)!==-1;case`keydown`:return t.keyCode!==229;case`keypress`:case`mousedown`:case`focusout`:return!0;default:return!1}}function Kn(e){return e=e.detail,typeof e==`object`&&`data`in e?e.data:null}var qn=!1;function Jn(e,t){switch(e){case`compositionend`:return Kn(t);case`keypress`:return t.which===32?(Wn=!0,Un):null;case`textInput`:return e=t.data,e===Un&&Wn?null:e;default:return null}}function Yn(e,t){if(qn)return e===`compositionend`||!zn&&Gn(e,t)?(e=cn(),sn=on=an=null,qn=!1,e):null;switch(e){case`paste`:return null;case`keypress`:if(!(t.ctrlKey||t.altKey||t.metaKey)||t.ctrlKey&&t.altKey){if(t.char&&1<t.char.length)return t.char;if(t.which)return String.fromCharCode(t.which)}return null;case`compositionend`:return Hn&&t.locale!==`ko`?null:t.data;default:return null}}var Xn={color:!0,date:!0,datetime:!0,"datetime-local":!0,email:!0,month:!0,number:!0,password:!0,range:!0,search:!0,tel:!0,text:!0,time:!0,url:!0,week:!0};function Zn(e){var t=e&&e.nodeName&&e.nodeName.toLowerCase();return t===`input`?!!Xn[e.type]:t===`textarea`}function Qn(e,t,n,r){Yt?Xt?Xt.push(r):Xt=[r]:Yt=r,t=_d(t,`onChange`),0<t.length&&(n=new mn(`onChange`,`change`,null,n,r),e.push({event:n,listeners:t}))}var $n=null,er=null;function tr(e){ud(e,0)}function nr(e){if(kt(at(e)))return e}function rr(e,t){if(e===`change`)return t}var ir=!1;if(tn){var ar;if(tn){var or=`oninput`in document;if(!or){var sr=document.createElement(`div`);sr.setAttribute(`oninput`,`return;`),or=typeof sr.oninput==`function`}ar=or}else ar=!1;ir=ar&&(!document.documentMode||9<document.documentMode)}function cr(){$n&&($n.detachEvent(`onpropertychange`,lr),er=$n=null)}function lr(e){if(e.propertyName===`value`&&nr(er)){var t=[];Qn(t,er,e,Jt(e)),$t(tr,t)}}function ur(e,t,n){e===`focusin`?(cr(),$n=t,er=n,$n.attachEvent(`onpropertychange`,lr)):e===`focusout`&&cr()}function dr(e){if(e===`selectionchange`||e===`keyup`||e===`keydown`)return nr(er)}function fr(e,t){if(e===`click`)return nr(t)}function pr(e,t){if(e===`input`||e===`change`)return nr(t)}function mr(e,t){return e===t&&(e!==0||1/e==1/t)||e!==e&&t!==t}var hr=typeof Object.is==`function`?Object.is:mr;function gr(e,t){if(hr(e,t))return!0;if(typeof e!=`object`||!e||typeof t!=`object`||!t)return!1;var n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(r=0;r<n.length;r++){var i=n[r];if(!fe.call(t,i)||!hr(e[i],t[i]))return!1}return!0}function _r(e){for(;e&&e.firstChild;)e=e.firstChild;return e}function vr(e,t){var n=_r(e);e=0;for(var r;n;){if(n.nodeType===3){if(r=e+n.textContent.length,e<=t&&r>=t)return{node:n,offset:t-e};e=r}a:{for(;n;){if(n.nextSibling){n=n.nextSibling;break a}n=n.parentNode}n=void 0}n=_r(n)}}function yr(e,t){return e&&t?e===t?!0:e&&e.nodeType===3?!1:t&&t.nodeType===3?yr(e,t.parentNode):`contains`in e?e.contains(t):e.compareDocumentPosition?!!(e.compareDocumentPosition(t)&16):!1:!1}function br(e){e=e!=null&&e.ownerDocument!=null&&e.ownerDocument.defaultView!=null?e.ownerDocument.defaultView:window;for(var t=At(e.document);t instanceof e.HTMLIFrameElement;){try{var n=typeof t.contentWindow.location.href==`string`}catch{n=!1}if(n)e=t.contentWindow;else break;t=At(e.document)}return t}function xr(e){var t=e&&e.nodeName&&e.nodeName.toLowerCase();return t&&(t===`input`&&(e.type===`text`||e.type===`search`||e.type===`tel`||e.type===`url`||e.type===`password`)||t===`textarea`||e.contentEditable===`true`)}var Sr=tn&&`documentMode`in document&&11>=document.documentMode,Cr=null,wr=null,Tr=null,Er=!1;function Dr(e,t,n){var r=n.window===n?n.document:n.nodeType===9?n:n.ownerDocument;Er||Cr==null||Cr!==At(r)||(r=Cr,`selectionStart`in r&&xr(r)?r={start:r.selectionStart,end:r.selectionEnd}:(r=(r.ownerDocument&&r.ownerDocument.defaultView||window).getSelection(),r={anchorNode:r.anchorNode,anchorOffset:r.anchorOffset,focusNode:r.focusNode,focusOffset:r.focusOffset}),Tr&&gr(Tr,r)||(Tr=r,r=_d(wr,`onSelect`),0<r.length&&(t=new mn(`onSelect`,`select`,null,t,n),e.push({event:t,listeners:r}),t.target=Cr)))}function Or(e,t){var n={};return n[e.toLowerCase()]=t.toLowerCase(),n[`Webkit`+e]=`webkit`+t,n[`Moz`+e]=`moz`+t,n}var kr={animationend:Or(`Animation`,`AnimationEnd`),animationiteration:Or(`Animation`,`AnimationIteration`),animationstart:Or(`Animation`,`AnimationStart`),transitionrun:Or(`Transition`,`TransitionRun`),transitionstart:Or(`Transition`,`TransitionStart`),transitioncancel:Or(`Transition`,`TransitionCancel`),transitionend:Or(`Transition`,`TransitionEnd`)},Ar={},jr={};tn&&(jr=document.createElement(`div`).style,`AnimationEvent`in window||(delete kr.animationend.animation,delete kr.animationiteration.animation,delete kr.animationstart.animation),`TransitionEvent`in window||delete kr.transitionend.transition);function Mr(e){if(Ar[e])return Ar[e];if(!kr[e])return e;var t=kr[e],n;for(n in t)if(t.hasOwnProperty(n)&&n in jr)return Ar[e]=t[n];return e}var Nr=Mr(`animationend`),Pr=Mr(`animationiteration`),Fr=Mr(`animationstart`),Ir=Mr(`transitionrun`),Lr=Mr(`transitionstart`),Rr=Mr(`transitioncancel`),zr=Mr(`transitionend`),Br=new Map,Vr=`abort auxClick beforeToggle cancel canPlay canPlayThrough click close contextMenu copy cut drag dragEnd dragEnter dragExit dragLeave dragOver dragStart drop durationChange emptied encrypted ended error gotPointerCapture input invalid keyDown keyPress keyUp load loadedData loadedMetadata loadStart lostPointerCapture mouseDown mouseMove mouseOut mouseOver mouseUp paste pause play playing pointerCancel pointerDown pointerMove pointerOut pointerOver pointerUp progress rateChange reset resize seeked seeking stalled submit suspend timeUpdate touchCancel touchEnd touchStart volumeChange scroll toggle touchMove waiting wheel`.split(` `);Vr.push(`scrollEnd`);function Hr(e,t){Br.set(e,t),ut(t,[e])}var Ur=new WeakMap;function Wr(e,t){if(typeof e==`object`&&e){var n=Ur.get(e);return n===void 0?(t={value:e,source:t,stack:wt(t)},Ur.set(e,t),t):n}return{value:e,source:t,stack:wt(t)}}var Gr=[],Kr=0,qr=0;function Jr(){for(var e=Kr,t=qr=Kr=0;t<e;){var n=Gr[t];Gr[t++]=null;var r=Gr[t];Gr[t++]=null;var i=Gr[t];Gr[t++]=null;var a=Gr[t];if(Gr[t++]=null,r!==null&&i!==null){var o=r.pending;o===null?i.next=i:(i.next=o.next,o.next=i),r.pending=i}a!==0&&Qr(n,i,a)}}function Yr(e,t,n,r){Gr[Kr++]=e,Gr[Kr++]=t,Gr[Kr++]=n,Gr[Kr++]=r,qr|=r,e.lanes|=r,e=e.alternate,e!==null&&(e.lanes|=r)}function Xr(e,t,n,r){return Yr(e,t,n,r),$r(e)}function Zr(e,t){return Yr(e,null,null,t),$r(e)}function Qr(e,t,n){e.lanes|=n;var r=e.alternate;r!==null&&(r.lanes|=n);for(var i=!1,a=e.return;a!==null;)a.childLanes|=n,r=a.alternate,r!==null&&(r.childLanes|=n),a.tag===22&&(e=a.stateNode,e===null||e._visibility&1||(i=!0)),e=a,a=a.return;return e.tag===3?(a=e.stateNode,i&&t!==null&&(i=31-Ee(n),e=a.hiddenUpdates,r=e[i],r===null?e[i]=[t]:r.push(t),t.lane=n|536870912),a):null}function $r(e){if(50<nu)throw nu=0,ru=null,Error(i(185));for(var t=e.return;t!==null;)e=t,t=e.return;return e.tag===3?e.stateNode:null}var ei={};function ti(e,t,n,r){this.tag=e,this.key=n,this.sibling=this.child=this.return=this.stateNode=this.type=this.elementType=null,this.index=0,this.refCleanup=this.ref=null,this.pendingProps=t,this.dependencies=this.memoizedState=this.updateQueue=this.memoizedProps=null,this.mode=r,this.subtreeFlags=this.flags=0,this.deletions=null,this.childLanes=this.lanes=0,this.alternate=null}function ni(e,t,n,r){return new ti(e,t,n,r)}function ri(e){return e=e.prototype,!(!e||!e.isReactComponent)}function ii(e,t){var n=e.alternate;return n===null?(n=ni(e.tag,t,e.key,e.mode),n.elementType=e.elementType,n.type=e.type,n.stateNode=e.stateNode,n.alternate=e,e.alternate=n):(n.pendingProps=t,n.type=e.type,n.flags=0,n.subtreeFlags=0,n.deletions=null),n.flags=e.flags&65011712,n.childLanes=e.childLanes,n.lanes=e.lanes,n.child=e.child,n.memoizedProps=e.memoizedProps,n.memoizedState=e.memoizedState,n.updateQueue=e.updateQueue,t=e.dependencies,n.dependencies=t===null?null:{lanes:t.lanes,firstContext:t.firstContext},n.sibling=e.sibling,n.index=e.index,n.ref=e.ref,n.refCleanup=e.refCleanup,n}function ai(e,t){e.flags&=65011714;var n=e.alternate;return n===null?(e.childLanes=0,e.lanes=t,e.child=null,e.subtreeFlags=0,e.memoizedProps=null,e.memoizedState=null,e.updateQueue=null,e.dependencies=null,e.stateNode=null):(e.childLanes=n.childLanes,e.lanes=n.lanes,e.child=n.child,e.subtreeFlags=0,e.deletions=null,e.memoizedProps=n.memoizedProps,e.memoizedState=n.memoizedState,e.updateQueue=n.updateQueue,e.type=n.type,t=n.dependencies,e.dependencies=t===null?null:{lanes:t.lanes,firstContext:t.firstContext}),e}function oi(e,t,n,r,a,o){var s=0;if(r=e,typeof e==`function`)ri(e)&&(s=1);else if(typeof e==`string`)s=kf(e,n,ie.current)?26:e===`html`||e===`head`||e===`body`?27:5;else a:switch(e){case k:return e=ni(31,n,t,a),e.elementType=k,e.lanes=o,e;case v:return si(n.children,a,o,t);case y:s=8,a|=24;break;case b:return e=ni(12,n,t,a|2),e.elementType=b,e.lanes=o,e;case T:return e=ni(13,n,t,a),e.elementType=T,e.lanes=o,e;case E:return e=ni(19,n,t,a),e.elementType=E,e.lanes=o,e;default:if(typeof e==`object`&&e)switch(e.$$typeof){case x:case C:s=10;break a;case S:s=9;break a;case w:s=11;break a;case D:s=14;break a;case O:s=16,r=null;break a}s=29,n=Error(i(130,e===null?`null`:typeof e,``)),r=null}return t=ni(s,n,t,a),t.elementType=e,t.type=r,t.lanes=o,t}function si(e,t,n,r){return e=ni(7,e,r,t),e.lanes=n,e}function ci(e,t,n){return e=ni(6,e,null,t),e.lanes=n,e}function li(e,t,n){return t=ni(4,e.children===null?[]:e.children,e.key,t),t.lanes=n,t.stateNode={containerInfo:e.containerInfo,pendingChildren:null,implementation:e.implementation},t}var ui=[],di=0,fi=null,pi=0,mi=[],hi=0,gi=null,_i=1,vi=``;function yi(e,t){ui[di++]=pi,ui[di++]=fi,fi=e,pi=t}function bi(e,t,n){mi[hi++]=_i,mi[hi++]=vi,mi[hi++]=gi,gi=e;var r=_i;e=vi;var i=32-Ee(r)-1;r&=~(1<<i),n+=1;var a=32-Ee(t)+i;if(30<a){var o=i-i%5;a=(r&(1<<o)-1).toString(32),r>>=o,i-=o,_i=1<<32-Ee(t)+i|n<<i|r,vi=a+e}else _i=1<<a|n<<i|r,vi=e}function xi(e){e.return!==null&&(yi(e,1),bi(e,1,0))}function Si(e){for(;e===fi;)fi=ui[--di],ui[di]=null,pi=ui[--di],ui[di]=null;for(;e===gi;)gi=mi[--hi],mi[hi]=null,vi=mi[--hi],mi[hi]=null,_i=mi[--hi],mi[hi]=null}var Ci=null,wi=null,Ti=!1,Ei=null,Di=!1,Oi=Error(i(519));function ki(e){throw Fi(Wr(Error(i(418,``)),e)),Oi}function Ai(e){var t=e.stateNode,n=e.type,r=e.memoizedProps;switch(t[Je]=e,t[Ye]=r,n){case`dialog`:J(`cancel`,t),J(`close`,t);break;case`iframe`:case`object`:case`embed`:J(`load`,t);break;case`video`:case`audio`:for(n=0;n<cd.length;n++)J(cd[n],t);break;case`source`:J(`error`,t);break;case`img`:case`image`:case`link`:J(`error`,t),J(`load`,t);break;case`details`:J(`toggle`,t);break;case`input`:J(`invalid`,t),Pt(t,r.value,r.defaultValue,r.checked,r.defaultChecked,r.type,r.name,!0),Ot(t);break;case`select`:J(`invalid`,t);break;case`textarea`:J(`invalid`,t),Rt(t,r.value,r.defaultValue,r.children),Ot(t)}n=r.children,typeof n!=`string`&&typeof n!=`number`&&typeof n!=`bigint`||t.textContent===``+n||!0===r.suppressHydrationWarning||Cd(t.textContent,n)?(r.popover!=null&&(J(`beforetoggle`,t),J(`toggle`,t)),r.onScroll!=null&&J(`scroll`,t),r.onScrollEnd!=null&&J(`scrollend`,t),r.onClick!=null&&(t.onclick=wd),t=!0):t=!1,t||ki(e)}function ji(e){for(Ci=e.return;Ci;)switch(Ci.tag){case 5:case 13:Di=!1;return;case 27:case 3:Di=!0;return;default:Ci=Ci.return}}function Mi(e){if(e!==Ci)return!1;if(!Ti)return ji(e),Ti=!0,!1;var t=e.tag,n;if((n=t!==3&&t!==27)&&((n=t===5)&&(n=e.type,n=n===`form`||n===`button`||Nd(e.type,e.memoizedProps)),n=!n),n&&wi&&ki(e),ji(e),t===13){if(e=e.memoizedState,e=e===null?null:e.dehydrated,!e)throw Error(i(317));a:{for(e=e.nextSibling,t=0;e;){if(e.nodeType===8){if(n=e.data,n===`/$`){if(t===0){wi=Jd(e.nextSibling);break a}t--}else n!==`$`&&n!==`$!`&&n!==`$?`||t++}e=e.nextSibling}wi=null}}else t===27?(t=wi,Vd(e.type)?(e=Yd,Yd=null,wi=e):wi=t):wi=Ci?Jd(e.stateNode.nextSibling):null;return!0}function Ni(){wi=Ci=null,Ti=!1}function Pi(){var e=Ei;return e!==null&&(Ul===null?Ul=e:Ul.push.apply(Ul,e),Ei=null),e}function Fi(e){Ei===null?Ei=[e]:Ei.push(e)}var Ii=L(null),Li=null,Ri=null;function zi(e,t,n){z(Ii,t._currentValue),t._currentValue=n}function Bi(e){e._currentValue=Ii.current,R(Ii)}function Vi(e,t,n){for(;e!==null;){var r=e.alternate;if((e.childLanes&t)===t?r!==null&&(r.childLanes&t)!==t&&(r.childLanes|=t):(e.childLanes|=t,r!==null&&(r.childLanes|=t)),e===n)break;e=e.return}}function Hi(e,t,n,r){var a=e.child;for(a!==null&&(a.return=e);a!==null;){var o=a.dependencies;if(o!==null){var s=a.child;o=o.firstContext;a:for(;o!==null;){var c=o;o=a;for(var l=0;l<t.length;l++)if(c.context===t[l]){o.lanes|=n,c=o.alternate,c!==null&&(c.lanes|=n),Vi(o.return,n,e),r||(s=null);break a}o=c.next}}else if(a.tag===18){if(s=a.return,s===null)throw Error(i(341));s.lanes|=n,o=s.alternate,o!==null&&(o.lanes|=n),Vi(s,n,e),s=null}else s=a.child;if(s!==null)s.return=a;else for(s=a;s!==null;){if(s===e){s=null;break}if(a=s.sibling,a!==null){a.return=s.return,s=a;break}s=s.return}a=s}}function Ui(e,t,n,r){e=null;for(var a=t,o=!1;a!==null;){if(!o){if(a.flags&524288)o=!0;else if(a.flags&262144)break}if(a.tag===10){var s=a.alternate;if(s===null)throw Error(i(387));if(s=s.memoizedProps,s!==null){var c=a.type;hr(a.pendingProps.value,s.value)||(e===null?e=[c]:e.push(c))}}else if(a===se.current){if(s=a.alternate,s===null)throw Error(i(387));s.memoizedState.memoizedState!==a.memoizedState.memoizedState&&(e===null?e=[zf]:e.push(zf))}a=a.return}e!==null&&Hi(t,e,n,r),t.flags|=262144}function Wi(e){for(e=e.firstContext;e!==null;){if(!hr(e.context._currentValue,e.memoizedValue))return!0;e=e.next}return!1}function Gi(e){Li=e,Ri=null,e=e.dependencies,e!==null&&(e.firstContext=null)}function Ki(e){return Ji(Li,e)}function qi(e,t){return Li===null&&Gi(e),Ji(e,t)}function Ji(e,t){var n=t._currentValue;if(t={context:t,memoizedValue:n,next:null},Ri===null){if(e===null)throw Error(i(308));Ri=t,e.dependencies={lanes:0,firstContext:t},e.flags|=524288}else Ri=Ri.next=t;return n}var Yi=typeof AbortController<`u`?AbortController:function(){var e=[],t=this.signal={aborted:!1,addEventListener:function(t,n){e.push(n)}};this.abort=function(){t.aborted=!0,e.forEach(function(e){return e()})}},Xi=t.unstable_scheduleCallback,Zi=t.unstable_NormalPriority,Qi={$$typeof:C,Consumer:null,Provider:null,_currentValue:null,_currentValue2:null,_threadCount:0};function $i(){return{controller:new Yi,data:new Map,refCount:0}}function ea(e){e.refCount--,e.refCount===0&&Xi(Zi,function(){e.controller.abort()})}var ta=null,na=0,ra=0,ia=null;function aa(e,t){if(ta===null){var n=ta=[];na=0,ra=nd(),ia={status:`pending`,value:void 0,then:function(e){n.push(e)}}}return na++,t.then(oa,oa),t}function oa(){if(--na===0&&ta!==null){ia!==null&&(ia.status=`fulfilled`);var e=ta;ta=null,ra=0,ia=null;for(var t=0;t<e.length;t++)(0,e[t])()}}function sa(e,t){var n=[],r={status:`pending`,value:null,reason:null,then:function(e){n.push(e)}};return e.then(function(){r.status=`fulfilled`,r.value=t;for(var e=0;e<n.length;e++)(0,n[e])(t)},function(e){for(r.status=`rejected`,r.reason=e,e=0;e<n.length;e++)(0,n[e])(void 0)}),r}var ca=N.S;N.S=function(e,t){typeof t==`object`&&t&&typeof t.then==`function`&&aa(e,t),ca!==null&&ca(e,t)};var la=L(null);function ua(){var e=la.current;return e===null?kl.pooledCache:e}function da(e,t){t===null?z(la,la.current):z(la,t.pool)}function fa(){var e=ua();return e===null?null:{parent:Qi._currentValue,pool:e}}var pa=Error(i(460)),ma=Error(i(474)),ha=Error(i(542)),ga={then:function(){}};function _a(e){return e=e.status,e===`fulfilled`||e===`rejected`}function va(){}function ya(e,t,n){switch(n=e[n],n===void 0?e.push(t):n!==t&&(t.then(va,va),t=n),t.status){case`fulfilled`:return t.value;case`rejected`:throw e=t.reason,Sa(e),e;default:if(typeof t.status==`string`)t.then(va,va);else{if(e=kl,e!==null&&100<e.shellSuspendCounter)throw Error(i(482));e=t,e.status=`pending`,e.then(function(e){if(t.status===`pending`){var n=t;n.status=`fulfilled`,n.value=e}},function(e){if(t.status===`pending`){var n=t;n.status=`rejected`,n.reason=e}})}switch(t.status){case`fulfilled`:return t.value;case`rejected`:throw e=t.reason,Sa(e),e}throw ba=t,pa}}var ba=null;function xa(){if(ba===null)throw Error(i(459));var e=ba;return ba=null,e}function Sa(e){if(e===pa||e===ha)throw Error(i(483))}var W=!1;function Ca(e){e.updateQueue={baseState:e.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,lanes:0,hiddenCallbacks:null},callbacks:null}}function wa(e,t){e=e.updateQueue,t.updateQueue===e&&(t.updateQueue={baseState:e.baseState,firstBaseUpdate:e.firstBaseUpdate,lastBaseUpdate:e.lastBaseUpdate,shared:e.shared,callbacks:null})}function Ta(e){return{lane:e,tag:0,payload:null,callback:null,next:null}}function Ea(e,t,n){var r=e.updateQueue;if(r===null)return null;if(r=r.shared,Ol&2){var i=r.pending;return i===null?t.next=t:(t.next=i.next,i.next=t),r.pending=t,t=$r(e),Qr(e,null,n),t}return Yr(e,r,t,n),$r(e)}function Da(e,t,n){if(t=t.updateQueue,t!==null&&(t=t.shared,n&4194048)){var r=t.lanes;r&=e.pendingLanes,n|=r,t.lanes=n,He(e,n)}}function Oa(e,t){var n=e.updateQueue,r=e.alternate;if(r!==null&&(r=r.updateQueue,n===r)){var i=null,a=null;if(n=n.firstBaseUpdate,n!==null){do{var o={lane:n.lane,tag:n.tag,payload:n.payload,callback:null,next:null};a===null?i=a=o:a=a.next=o,n=n.next}while(n!==null);a===null?i=a=t:a=a.next=t}else i=a=t;n={baseState:r.baseState,firstBaseUpdate:i,lastBaseUpdate:a,shared:r.shared,callbacks:r.callbacks},e.updateQueue=n}else e=n.lastBaseUpdate,e===null?n.firstBaseUpdate=t:e.next=t,n.lastBaseUpdate=t}var ka=!1;function Aa(){if(ka){var e=ia;if(e!==null)throw e}}function ja(e,t,n,r){ka=!1;var i=e.updateQueue;W=!1;var a=i.firstBaseUpdate,o=i.lastBaseUpdate,s=i.shared.pending;if(s!==null){i.shared.pending=null;var c=s,l=c.next;c.next=null,o===null?a=l:o.next=l,o=c;var u=e.alternate;u!==null&&(u=u.updateQueue,s=u.lastBaseUpdate,s!==o&&(s===null?u.firstBaseUpdate=l:s.next=l,u.lastBaseUpdate=c))}if(a!==null){var d=i.baseState;o=0,u=l=c=null,s=a;do{var f=s.lane&-536870913,m=f!==s.lane;if(m?(q&f)===f:(r&f)===f){f!==0&&f===ra&&(ka=!0),u!==null&&(u=u.next={lane:0,tag:s.tag,payload:s.payload,callback:null,next:null});a:{var h=e,g=s;f=t;var _=n;switch(g.tag){case 1:if(h=g.payload,typeof h==`function`){d=h.call(_,d,f);break a}d=h;break a;case 3:h.flags=h.flags&-65537|128;case 0:if(h=g.payload,f=typeof h==`function`?h.call(_,d,f):h,f==null)break a;d=p({},d,f);break a;case 2:W=!0}}f=s.callback,f!==null&&(e.flags|=64,m&&(e.flags|=8192),m=i.callbacks,m===null?i.callbacks=[f]:m.push(f))}else m={lane:f,tag:s.tag,payload:s.payload,callback:s.callback,next:null},u===null?(l=u=m,c=d):u=u.next=m,o|=f;if(s=s.next,s===null){if(s=i.shared.pending,s===null)break;m=s,s=m.next,m.next=null,i.lastBaseUpdate=m,i.shared.pending=null}}while(1);u===null&&(c=d),i.baseState=c,i.firstBaseUpdate=l,i.lastBaseUpdate=u,a===null&&(i.shared.lanes=0),Ll|=o,e.lanes=o,e.memoizedState=d}}function Ma(e,t){if(typeof e!=`function`)throw Error(i(191,e));e.call(t)}function Na(e,t){var n=e.callbacks;if(n!==null)for(e.callbacks=null,e=0;e<n.length;e++)Ma(n[e],t)}var Pa=L(null),Fa=L(0);function Ia(e,t){e=Fl,z(Fa,e),z(Pa,t),Fl=e|t.baseLanes}function La(){z(Fa,Fl),z(Pa,Pa.current)}function Ra(){Fl=Fa.current,R(Pa),R(Fa)}var za=0,G=null,Ba=null,Va=null,Ha=!1,Ua=!1,Wa=!1,Ga=0,Ka=0,qa=null,Ja=0;function Ya(){throw Error(i(321))}function Xa(e,t){if(t===null)return!1;for(var n=0;n<t.length&&n<e.length;n++)if(!hr(e[n],t[n]))return!1;return!0}function Za(e,t,n,r,i,a){return za=a,G=t,t.memoizedState=null,t.updateQueue=null,t.lanes=0,N.H=e===null||e.memoizedState===null?ms:hs,Wa=!1,a=n(r,i),Wa=!1,Ua&&(a=$a(t,n,r,i)),Qa(e),a}function Qa(e){N.H=ps;var t=Ba!==null&&Ba.next!==null;if(za=0,Va=Ba=G=null,Ha=!1,Ka=0,qa=null,t)throw Error(i(300));e===null||Xs||(e=e.dependencies,e!==null&&Wi(e)&&(Xs=!0))}function $a(e,t,n,r){G=e;var a=0;do{if(Ua&&(qa=null),Ka=0,Ua=!1,25<=a)throw Error(i(301));if(a+=1,Va=Ba=null,e.updateQueue!=null){var o=e.updateQueue;o.lastEffect=null,o.events=null,o.stores=null,o.memoCache!=null&&(o.memoCache.index=0)}N.H=gs,o=t(n,r)}while(Ua);return o}function eo(){var e=N.H,t=e.useState()[0];return t=typeof t.then==`function`?so(t):t,e=e.useState()[0],(Ba===null?null:Ba.memoizedState)!==e&&(G.flags|=1024),t}function to(){var e=Ga!==0;return Ga=0,e}function no(e,t,n){t.updateQueue=e.updateQueue,t.flags&=-2053,e.lanes&=~n}function ro(e){if(Ha){for(e=e.memoizedState;e!==null;){var t=e.queue;t!==null&&(t.pending=null),e=e.next}Ha=!1}za=0,Va=Ba=G=null,Ua=!1,Ka=Ga=0,qa=null}function io(){var e={memoizedState:null,baseState:null,baseQueue:null,queue:null,next:null};return Va===null?G.memoizedState=Va=e:Va=Va.next=e,Va}function ao(){if(Ba===null){var e=G.alternate;e=e===null?null:e.memoizedState}else e=Ba.next;var t=Va===null?G.memoizedState:Va.next;if(t!==null)Va=t,Ba=e;else{if(e===null)throw G.alternate===null?Error(i(467)):Error(i(310));Ba=e,e={memoizedState:Ba.memoizedState,baseState:Ba.baseState,baseQueue:Ba.baseQueue,queue:Ba.queue,next:null},Va===null?G.memoizedState=Va=e:Va=Va.next=e}return Va}function oo(){return{lastEffect:null,events:null,stores:null,memoCache:null}}function so(e){var t=Ka;return Ka+=1,qa===null&&(qa=[]),e=ya(qa,e,t),t=G,(Va===null?t.memoizedState:Va.next)===null&&(t=t.alternate,N.H=t===null||t.memoizedState===null?ms:hs),e}function co(e){if(typeof e==`object`&&e){if(typeof e.then==`function`)return so(e);if(e.$$typeof===C)return Ki(e)}throw Error(i(438,String(e)))}function lo(e){var t=null,n=G.updateQueue;if(n!==null&&(t=n.memoCache),t==null){var r=G.alternate;r!==null&&(r=r.updateQueue,r!==null&&(r=r.memoCache,r!=null&&(t={data:r.data.map(function(e){return e.slice()}),index:0})))}if(t??={data:[],index:0},n===null&&(n=oo(),G.updateQueue=n),n.memoCache=t,n=t.data[t.index],n===void 0)for(n=t.data[t.index]=Array(e),r=0;r<e;r++)n[r]=A;return t.index++,n}function uo(e,t){return typeof t==`function`?t(e):t}function fo(e){return po(ao(),Ba,e)}function po(e,t,n){var r=e.queue;if(r===null)throw Error(i(311));r.lastRenderedReducer=n;var a=e.baseQueue,o=r.pending;if(o!==null){if(a!==null){var s=a.next;a.next=o.next,o.next=s}t.baseQueue=a=o,r.pending=null}if(o=e.baseState,a===null)e.memoizedState=o;else{t=a.next;var c=s=null,l=null,u=t,d=!1;do{var f=u.lane&-536870913;if(f===u.lane?(za&f)===f:(q&f)===f){var p=u.revertLane;if(p===0)l!==null&&(l=l.next={lane:0,revertLane:0,action:u.action,hasEagerState:u.hasEagerState,eagerState:u.eagerState,next:null}),f===ra&&(d=!0);else if((za&p)===p){u=u.next,p===ra&&(d=!0);continue}else f={lane:0,revertLane:u.revertLane,action:u.action,hasEagerState:u.hasEagerState,eagerState:u.eagerState,next:null},l===null?(c=l=f,s=o):l=l.next=f,G.lanes|=p,Ll|=p;f=u.action,Wa&&n(o,f),o=u.hasEagerState?u.eagerState:n(o,f)}else p={lane:f,revertLane:u.revertLane,action:u.action,hasEagerState:u.hasEagerState,eagerState:u.eagerState,next:null},l===null?(c=l=p,s=o):l=l.next=p,G.lanes|=f,Ll|=f;u=u.next}while(u!==null&&u!==t);if(l===null?s=o:l.next=c,!hr(o,e.memoizedState)&&(Xs=!0,d&&(n=ia,n!==null)))throw n;e.memoizedState=o,e.baseState=s,e.baseQueue=l,r.lastRenderedState=o}return a===null&&(r.lanes=0),[e.memoizedState,r.dispatch]}function mo(e){var t=ao(),n=t.queue;if(n===null)throw Error(i(311));n.lastRenderedReducer=e;var r=n.dispatch,a=n.pending,o=t.memoizedState;if(a!==null){n.pending=null;var s=a=a.next;do o=e(o,s.action),s=s.next;while(s!==a);hr(o,t.memoizedState)||(Xs=!0),t.memoizedState=o,t.baseQueue===null&&(t.baseState=o),n.lastRenderedState=o}return[o,r]}function ho(e,t,n){var r=G,a=ao(),o=Ti;if(o){if(n===void 0)throw Error(i(407));n=n()}else n=t();var s=!hr((Ba||a).memoizedState,n);if(s&&(a.memoizedState=n,Xs=!0),a=a.queue,zo(2048,8,vo.bind(null,r,a,e),[e]),a.getSnapshot!==t||s||Va!==null&&Va.memoizedState.tag&1){if(r.flags|=2048,Fo(9,Io(),_o.bind(null,r,a,n,t),null),kl===null)throw Error(i(349));o||za&124||go(r,t,n)}return n}function go(e,t,n){e.flags|=16384,e={getSnapshot:t,value:n},t=G.updateQueue,t===null?(t=oo(),G.updateQueue=t,t.stores=[e]):(n=t.stores,n===null?t.stores=[e]:n.push(e))}function _o(e,t,n,r){t.value=n,t.getSnapshot=r,yo(t)&&bo(e)}function vo(e,t,n){return n(function(){yo(t)&&bo(e)})}function yo(e){var t=e.getSnapshot;e=e.value;try{var n=t();return!hr(e,n)}catch{return!0}}function bo(e){var t=Zr(e,2);t!==null&&ou(t,e,2)}function xo(e){var t=io();if(typeof e==`function`){var n=e;if(e=n(),Wa){Te(!0);try{n()}finally{Te(!1)}}}return t.memoizedState=t.baseState=e,t.queue={pending:null,lanes:0,dispatch:null,lastRenderedReducer:uo,lastRenderedState:e},t}function So(e,t,n,r){return e.baseState=n,po(e,Ba,typeof r==`function`?r:uo)}function Co(e,t,n,r,a){if(us(e))throw Error(i(485));if(e=t.action,e!==null){var o={payload:a,action:e,next:null,isTransition:!0,status:`pending`,value:null,reason:null,listeners:[],then:function(e){o.listeners.push(e)}};N.T===null?o.isTransition=!1:n(!0),r(o),n=t.pending,n===null?(o.next=t.pending=o,wo(t,o)):(o.next=n.next,t.pending=n.next=o)}}function wo(e,t){var n=t.action,r=t.payload,i=e.state;if(t.isTransition){var a=N.T,o={};N.T=o;try{var s=n(i,r),c=N.S;c!==null&&c(o,s),To(e,t,s)}catch(n){Do(e,t,n)}finally{N.T=a}}else try{a=n(i,r),To(e,t,a)}catch(n){Do(e,t,n)}}function To(e,t,n){typeof n==`object`&&n&&typeof n.then==`function`?n.then(function(n){Eo(e,t,n)},function(n){return Do(e,t,n)}):Eo(e,t,n)}function Eo(e,t,n){t.status=`fulfilled`,t.value=n,Oo(t),e.state=n,t=e.pending,t!==null&&(n=t.next,n===t?e.pending=null:(n=n.next,t.next=n,wo(e,n)))}function Do(e,t,n){var r=e.pending;if(e.pending=null,r!==null){r=r.next;do t.status=`rejected`,t.reason=n,Oo(t),t=t.next;while(t!==r)}e.action=null}function Oo(e){e=e.listeners;for(var t=0;t<e.length;t++)(0,e[t])()}function ko(e,t){return t}function Ao(e,t){if(Ti){var n=kl.formState;if(n!==null){a:{var r=G;if(Ti){if(wi){b:{for(var i=wi,a=Di;i.nodeType!==8;)if(!a||(i=Jd(i.nextSibling),i===null)){i=null;break b}a=i.data,i=a===`F!`||a===`F`?i:null}if(i){wi=Jd(i.nextSibling),r=i.data===`F!`;break a}}ki(r)}r=!1}r&&(t=n[0])}}return n=io(),n.memoizedState=n.baseState=t,r={pending:null,lanes:0,dispatch:null,lastRenderedReducer:ko,lastRenderedState:t},n.queue=r,n=ss.bind(null,G,r),r.dispatch=n,r=xo(!1),a=ls.bind(null,G,!1,r.queue),r=io(),i={state:t,dispatch:null,action:e,pending:null},r.queue=i,n=Co.bind(null,G,i,a,n),i.dispatch=n,r.memoizedState=e,[t,n,!1]}function jo(e){return Mo(ao(),Ba,e)}function Mo(e,t,n){if(t=po(e,t,ko)[0],e=fo(uo)[0],typeof t==`object`&&t&&typeof t.then==`function`)try{var r=so(t)}catch(e){throw e===pa?ha:e}else r=t;t=ao();var i=t.queue,a=i.dispatch;return n!==t.memoizedState&&(G.flags|=2048,Fo(9,Io(),No.bind(null,i,n),null)),[r,a,e]}function No(e,t){e.action=t}function Po(e){var t=ao(),n=Ba;if(n!==null)return Mo(t,n,e);ao(),t=t.memoizedState,n=ao();var r=n.queue.dispatch;return n.memoizedState=e,[t,r,!1]}function Fo(e,t,n,r){return e={tag:e,create:n,deps:r,inst:t,next:null},t=G.updateQueue,t===null&&(t=oo(),G.updateQueue=t),n=t.lastEffect,n===null?t.lastEffect=e.next=e:(r=n.next,n.next=e,e.next=r,t.lastEffect=e),e}function Io(){return{destroy:void 0,resource:void 0}}function Lo(){return ao().memoizedState}function Ro(e,t,n,r){var i=io();r=r===void 0?null:r,G.flags|=e,i.memoizedState=Fo(1|t,Io(),n,r)}function zo(e,t,n,r){var i=ao();r=r===void 0?null:r;var a=i.memoizedState.inst;Ba!==null&&r!==null&&Xa(r,Ba.memoizedState.deps)?i.memoizedState=Fo(t,a,n,r):(G.flags|=e,i.memoizedState=Fo(1|t,a,n,r))}function Bo(e,t){Ro(8390656,8,e,t)}function Vo(e,t){zo(2048,8,e,t)}function Ho(e,t){return zo(4,2,e,t)}function Uo(e,t){return zo(4,4,e,t)}function Wo(e,t){if(typeof t==`function`){e=e();var n=t(e);return function(){typeof n==`function`?n():t(null)}}if(t!=null)return e=e(),t.current=e,function(){t.current=null}}function Go(e,t,n){n=n==null?null:n.concat([e]),zo(4,4,Wo.bind(null,t,e),n)}function Ko(){}function qo(e,t){var n=ao();t=t===void 0?null:t;var r=n.memoizedState;return t!==null&&Xa(t,r[1])?r[0]:(n.memoizedState=[e,t],e)}function Jo(e,t){var n=ao();t=t===void 0?null:t;var r=n.memoizedState;if(t!==null&&Xa(t,r[1]))return r[0];if(r=e(),Wa){Te(!0);try{e()}finally{Te(!1)}}return n.memoizedState=[r,t],r}function Yo(e,t,n){return n===void 0||za&1073741824?e.memoizedState=t:(e.memoizedState=n,e=au(),G.lanes|=e,Ll|=e,n)}function Xo(e,t,n,r){return hr(n,t)?n:Pa.current===null?za&42?(e=au(),G.lanes|=e,Ll|=e,t):(Xs=!0,e.memoizedState=n):(e=Yo(e,n,r),hr(e,t)||(Xs=!0),e)}function Zo(e,t,n,r,i){var a=P.p;P.p=a!==0&&8>a?a:8;var o=N.T,s={};N.T=s,ls(e,!1,t,n);try{var c=i(),l=N.S;l!==null&&l(s,c),typeof c==`object`&&c&&typeof c.then==`function`?cs(e,t,sa(c,r),iu(e)):cs(e,t,r,iu(e))}catch(n){cs(e,t,{then:function(){},status:`rejected`,reason:n},iu())}finally{P.p=a,N.T=o}}function Qo(){}function $o(e,t,n,r){if(e.tag!==5)throw Error(i(476));var a=es(e).queue;Zo(e,a,t,F,n===null?Qo:function(){return ts(e),n(r)})}function es(e){var t=e.memoizedState;if(t!==null)return t;t={memoizedState:F,baseState:F,baseQueue:null,queue:{pending:null,lanes:0,dispatch:null,lastRenderedReducer:uo,lastRenderedState:F},next:null};var n={};return t.next={memoizedState:n,baseState:n,baseQueue:null,queue:{pending:null,lanes:0,dispatch:null,lastRenderedReducer:uo,lastRenderedState:n},next:null},e.memoizedState=t,e=e.alternate,e!==null&&(e.memoizedState=t),t}function ts(e){var t=es(e).next.queue;cs(e,t,{},iu())}function ns(){return Ki(zf)}function rs(){return ao().memoizedState}function is(){return ao().memoizedState}function as(e){for(var t=e.return;t!==null;){switch(t.tag){case 24:case 3:var n=iu();e=Ta(n);var r=Ea(t,e,n);r!==null&&(ou(r,t,n),Da(r,t,n)),t={cache:$i()},e.payload=t;return}t=t.return}}function os(e,t,n){var r=iu();n={lane:r,revertLane:0,action:n,hasEagerState:!1,eagerState:null,next:null},us(e)?ds(t,n):(n=Xr(e,t,n,r),n!==null&&(ou(n,e,r),fs(n,t,r)))}function ss(e,t,n){cs(e,t,n,iu())}function cs(e,t,n,r){var i={lane:r,revertLane:0,action:n,hasEagerState:!1,eagerState:null,next:null};if(us(e))ds(t,i);else{var a=e.alternate;if(e.lanes===0&&(a===null||a.lanes===0)&&(a=t.lastRenderedReducer,a!==null))try{var o=t.lastRenderedState,s=a(o,n);if(i.hasEagerState=!0,i.eagerState=s,hr(s,o))return Yr(e,t,i,0),kl===null&&Jr(),!1}catch{}if(n=Xr(e,t,i,r),n!==null)return ou(n,e,r),fs(n,t,r),!0}return!1}function ls(e,t,n,r){if(r={lane:2,revertLane:nd(),action:r,hasEagerState:!1,eagerState:null,next:null},us(e)){if(t)throw Error(i(479))}else t=Xr(e,n,r,2),t!==null&&ou(t,e,2)}function us(e){var t=e.alternate;return e===G||t!==null&&t===G}function ds(e,t){Ua=Ha=!0;var n=e.pending;n===null?t.next=t:(t.next=n.next,n.next=t),e.pending=t}function fs(e,t,n){if(n&4194048){var r=t.lanes;r&=e.pendingLanes,n|=r,t.lanes=n,He(e,n)}}var ps={readContext:Ki,use:co,useCallback:Ya,useContext:Ya,useEffect:Ya,useImperativeHandle:Ya,useLayoutEffect:Ya,useInsertionEffect:Ya,useMemo:Ya,useReducer:Ya,useRef:Ya,useState:Ya,useDebugValue:Ya,useDeferredValue:Ya,useTransition:Ya,useSyncExternalStore:Ya,useId:Ya,useHostTransitionStatus:Ya,useFormState:Ya,useActionState:Ya,useOptimistic:Ya,useMemoCache:Ya,useCacheRefresh:Ya},ms={readContext:Ki,use:co,useCallback:function(e,t){return io().memoizedState=[e,t===void 0?null:t],e},useContext:Ki,useEffect:Bo,useImperativeHandle:function(e,t,n){n=n==null?null:n.concat([e]),Ro(4194308,4,Wo.bind(null,t,e),n)},useLayoutEffect:function(e,t){return Ro(4194308,4,e,t)},useInsertionEffect:function(e,t){Ro(4,2,e,t)},useMemo:function(e,t){var n=io();t=t===void 0?null:t;var r=e();if(Wa){Te(!0);try{e()}finally{Te(!1)}}return n.memoizedState=[r,t],r},useReducer:function(e,t,n){var r=io();if(n!==void 0){var i=n(t);if(Wa){Te(!0);try{n(t)}finally{Te(!1)}}}else i=t;return r.memoizedState=r.baseState=i,e={pending:null,lanes:0,dispatch:null,lastRenderedReducer:e,lastRenderedState:i},r.queue=e,e=e.dispatch=os.bind(null,G,e),[r.memoizedState,e]},useRef:function(e){var t=io();return e={current:e},t.memoizedState=e},useState:function(e){e=xo(e);var t=e.queue,n=ss.bind(null,G,t);return t.dispatch=n,[e.memoizedState,n]},useDebugValue:Ko,useDeferredValue:function(e,t){return Yo(io(),e,t)},useTransition:function(){var e=xo(!1);return e=Zo.bind(null,G,e.queue,!0,!1),io().memoizedState=e,[!1,e]},useSyncExternalStore:function(e,t,n){var r=G,a=io();if(Ti){if(n===void 0)throw Error(i(407));n=n()}else{if(n=t(),kl===null)throw Error(i(349));q&124||go(r,t,n)}a.memoizedState=n;var o={value:n,getSnapshot:t};return a.queue=o,Bo(vo.bind(null,r,o,e),[e]),r.flags|=2048,Fo(9,Io(),_o.bind(null,r,o,n,t),null),n},useId:function(){var e=io(),t=kl.identifierPrefix;if(Ti){var n=vi,r=_i;n=(r&~(1<<32-Ee(r)-1)).toString(32)+n,t=`«`+t+`R`+n,n=Ga++,0<n&&(t+=`H`+n.toString(32)),t+=`»`}else n=Ja++,t=`«`+t+`r`+n.toString(32)+`»`;return e.memoizedState=t},useHostTransitionStatus:ns,useFormState:Ao,useActionState:Ao,useOptimistic:function(e){var t=io();t.memoizedState=t.baseState=e;var n={pending:null,lanes:0,dispatch:null,lastRenderedReducer:null,lastRenderedState:null};return t.queue=n,t=ls.bind(null,G,!0,n),n.dispatch=t,[e,t]},useMemoCache:lo,useCacheRefresh:function(){return io().memoizedState=as.bind(null,G)}},hs={readContext:Ki,use:co,useCallback:qo,useContext:Ki,useEffect:Vo,useImperativeHandle:Go,useInsertionEffect:Ho,useLayoutEffect:Uo,useMemo:Jo,useReducer:fo,useRef:Lo,useState:function(){return fo(uo)},useDebugValue:Ko,useDeferredValue:function(e,t){return Xo(ao(),Ba.memoizedState,e,t)},useTransition:function(){var e=fo(uo)[0],t=ao().memoizedState;return[typeof e==`boolean`?e:so(e),t]},useSyncExternalStore:ho,useId:rs,useHostTransitionStatus:ns,useFormState:jo,useActionState:jo,useOptimistic:function(e,t){return So(ao(),Ba,e,t)},useMemoCache:lo,useCacheRefresh:is},gs={readContext:Ki,use:co,useCallback:qo,useContext:Ki,useEffect:Vo,useImperativeHandle:Go,useInsertionEffect:Ho,useLayoutEffect:Uo,useMemo:Jo,useReducer:mo,useRef:Lo,useState:function(){return mo(uo)},useDebugValue:Ko,useDeferredValue:function(e,t){var n=ao();return Ba===null?Yo(n,e,t):Xo(n,Ba.memoizedState,e,t)},useTransition:function(){var e=mo(uo)[0],t=ao().memoizedState;return[typeof e==`boolean`?e:so(e),t]},useSyncExternalStore:ho,useId:rs,useHostTransitionStatus:ns,useFormState:Po,useActionState:Po,useOptimistic:function(e,t){var n=ao();return Ba===null?(n.baseState=e,[e,n.queue.dispatch]):So(n,Ba,e,t)},useMemoCache:lo,useCacheRefresh:is},_s=null,vs=0;function ys(e){var t=vs;return vs+=1,_s===null&&(_s=[]),ya(_s,e,t)}function bs(e,t){t=t.props.ref,e.ref=t===void 0?null:t}function xs(e,t){throw t.$$typeof===h?Error(i(525)):(e=Object.prototype.toString.call(t),Error(i(31,e===`[object Object]`?`object with keys {`+Object.keys(t).join(`, `)+`}`:e)))}function Ss(e){var t=e._init;return t(e._payload)}function Cs(e){function t(t,n){if(e){var r=t.deletions;r===null?(t.deletions=[n],t.flags|=16):r.push(n)}}function n(n,r){if(!e)return null;for(;r!==null;)t(n,r),r=r.sibling;return null}function r(e){for(var t=new Map;e!==null;)e.key===null?t.set(e.index,e):t.set(e.key,e),e=e.sibling;return t}function a(e,t){return e=ii(e,t),e.index=0,e.sibling=null,e}function o(t,n,r){return t.index=r,e?(r=t.alternate,r===null?(t.flags|=67108866,n):(r=r.index,r<n?(t.flags|=67108866,n):r)):(t.flags|=1048576,n)}function s(t){return e&&t.alternate===null&&(t.flags|=67108866),t}function c(e,t,n,r){return t===null||t.tag!==6?(t=ci(n,e.mode,r),t.return=e,t):(t=a(t,n),t.return=e,t)}function l(e,t,n,r){var i=n.type;return i===v?d(e,t,n.props.children,r,n.key):t!==null&&(t.elementType===i||typeof i==`object`&&i&&i.$$typeof===O&&Ss(i)===t.type)?(t=a(t,n.props),bs(t,n),t.return=e,t):(t=oi(n.type,n.key,n.props,null,e.mode,r),bs(t,n),t.return=e,t)}function u(e,t,n,r){return t===null||t.tag!==4||t.stateNode.containerInfo!==n.containerInfo||t.stateNode.implementation!==n.implementation?(t=li(n,e.mode,r),t.return=e,t):(t=a(t,n.children||[]),t.return=e,t)}function d(e,t,n,r,i){return t===null||t.tag!==7?(t=si(n,e.mode,r,i),t.return=e,t):(t=a(t,n),t.return=e,t)}function f(e,t,n){if(typeof t==`string`&&t!==``||typeof t==`number`||typeof t==`bigint`)return t=ci(``+t,e.mode,n),t.return=e,t;if(typeof t==`object`&&t){switch(t.$$typeof){case g:return n=oi(t.type,t.key,t.props,null,e.mode,n),bs(n,t),n.return=e,n;case _:return t=li(t,e.mode,n),t.return=e,t;case O:var r=t._init;return t=r(t._payload),f(e,t,n)}if(ne(t)||M(t))return t=si(t,e.mode,n,null),t.return=e,t;if(typeof t.then==`function`)return f(e,ys(t),n);if(t.$$typeof===C)return f(e,qi(e,t),n);xs(e,t)}return null}function p(e,t,n,r){var i=t===null?null:t.key;if(typeof n==`string`&&n!==``||typeof n==`number`||typeof n==`bigint`)return i===null?c(e,t,``+n,r):null;if(typeof n==`object`&&n){switch(n.$$typeof){case g:return n.key===i?l(e,t,n,r):null;case _:return n.key===i?u(e,t,n,r):null;case O:return i=n._init,n=i(n._payload),p(e,t,n,r)}if(ne(n)||M(n))return i===null?d(e,t,n,r,null):null;if(typeof n.then==`function`)return p(e,t,ys(n),r);if(n.$$typeof===C)return p(e,t,qi(e,n),r);xs(e,n)}return null}function m(e,t,n,r,i){if(typeof r==`string`&&r!==``||typeof r==`number`||typeof r==`bigint`)return e=e.get(n)||null,c(t,e,``+r,i);if(typeof r==`object`&&r){switch(r.$$typeof){case g:return e=e.get(r.key===null?n:r.key)||null,l(t,e,r,i);case _:return e=e.get(r.key===null?n:r.key)||null,u(t,e,r,i);case O:var a=r._init;return r=a(r._payload),m(e,t,n,r,i)}if(ne(r)||M(r))return e=e.get(n)||null,d(t,e,r,i,null);if(typeof r.then==`function`)return m(e,t,n,ys(r),i);if(r.$$typeof===C)return m(e,t,n,qi(t,r),i);xs(t,r)}return null}function h(i,a,s,c){for(var l=null,u=null,d=a,h=a=0,g=null;d!==null&&h<s.length;h++){d.index>h?(g=d,d=null):g=d.sibling;var _=p(i,d,s[h],c);if(_===null){d===null&&(d=g);break}e&&d&&_.alternate===null&&t(i,d),a=o(_,a,h),u===null?l=_:u.sibling=_,u=_,d=g}if(h===s.length)return n(i,d),Ti&&yi(i,h),l;if(d===null){for(;h<s.length;h++)d=f(i,s[h],c),d!==null&&(a=o(d,a,h),u===null?l=d:u.sibling=d,u=d);return Ti&&yi(i,h),l}for(d=r(d);h<s.length;h++)g=m(d,i,h,s[h],c),g!==null&&(e&&g.alternate!==null&&d.delete(g.key===null?h:g.key),a=o(g,a,h),u===null?l=g:u.sibling=g,u=g);return e&&d.forEach(function(e){return t(i,e)}),Ti&&yi(i,h),l}function y(a,s,c,l){if(c==null)throw Error(i(151));for(var u=null,d=null,h=s,g=s=0,_=null,v=c.next();h!==null&&!v.done;g++,v=c.next()){h.index>g?(_=h,h=null):_=h.sibling;var y=p(a,h,v.value,l);if(y===null){h===null&&(h=_);break}e&&h&&y.alternate===null&&t(a,h),s=o(y,s,g),d===null?u=y:d.sibling=y,d=y,h=_}if(v.done)return n(a,h),Ti&&yi(a,g),u;if(h===null){for(;!v.done;g++,v=c.next())v=f(a,v.value,l),v!==null&&(s=o(v,s,g),d===null?u=v:d.sibling=v,d=v);return Ti&&yi(a,g),u}for(h=r(h);!v.done;g++,v=c.next())v=m(h,a,g,v.value,l),v!==null&&(e&&v.alternate!==null&&h.delete(v.key===null?g:v.key),s=o(v,s,g),d===null?u=v:d.sibling=v,d=v);return e&&h.forEach(function(e){return t(a,e)}),Ti&&yi(a,g),u}function b(e,r,o,c){if(typeof o==`object`&&o&&o.type===v&&o.key===null&&(o=o.props.children),typeof o==`object`&&o){switch(o.$$typeof){case g:a:{for(var l=o.key;r!==null;){if(r.key===l){if(l=o.type,l===v){if(r.tag===7){n(e,r.sibling),c=a(r,o.props.children),c.return=e,e=c;break a}}else if(r.elementType===l||typeof l==`object`&&l&&l.$$typeof===O&&Ss(l)===r.type){n(e,r.sibling),c=a(r,o.props),bs(c,o),c.return=e,e=c;break a}n(e,r);break}t(e,r),r=r.sibling}o.type===v?(c=si(o.props.children,e.mode,c,o.key),c.return=e,e=c):(c=oi(o.type,o.key,o.props,null,e.mode,c),bs(c,o),c.return=e,e=c)}return s(e);case _:a:{for(l=o.key;r!==null;){if(r.key===l){if(r.tag===4&&r.stateNode.containerInfo===o.containerInfo&&r.stateNode.implementation===o.implementation){n(e,r.sibling),c=a(r,o.children||[]),c.return=e,e=c;break a}n(e,r);break}t(e,r),r=r.sibling}c=li(o,e.mode,c),c.return=e,e=c}return s(e);case O:return l=o._init,o=l(o._payload),b(e,r,o,c)}if(ne(o))return h(e,r,o,c);if(M(o)){if(l=M(o),typeof l!=`function`)throw Error(i(150));return o=l.call(o),y(e,r,o,c)}if(typeof o.then==`function`)return b(e,r,ys(o),c);if(o.$$typeof===C)return b(e,r,qi(e,o),c);xs(e,o)}return typeof o==`string`&&o!==``||typeof o==`number`||typeof o==`bigint`?(o=``+o,r!==null&&r.tag===6?(n(e,r.sibling),c=a(r,o),c.return=e,e=c):(n(e,r),c=ci(o,e.mode,c),c.return=e,e=c),s(e)):n(e,r)}return function(e,t,n,r){try{vs=0;var i=b(e,t,n,r);return _s=null,i}catch(t){if(t===pa||t===ha)throw t;var a=ni(29,t,null,e.mode);return a.lanes=r,a.return=e,a}}}var ws=Cs(!0),Ts=Cs(!1),Es=L(null),Ds=null;function Os(e){var t=e.alternate;z(Ms,Ms.current&1),z(Es,e),Ds===null&&(t===null||Pa.current!==null||t.memoizedState!==null)&&(Ds=e)}function ks(e){if(e.tag===22){if(z(Ms,Ms.current),z(Es,e),Ds===null){var t=e.alternate;t!==null&&t.memoizedState!==null&&(Ds=e)}}else As(e)}function As(){z(Ms,Ms.current),z(Es,Es.current)}function js(e){R(Es),Ds===e&&(Ds=null),R(Ms)}var Ms=L(0);function Ns(e){for(var t=e;t!==null;){if(t.tag===13){var n=t.memoizedState;if(n!==null&&(n=n.dehydrated,n===null||n.data===`$?`||Kd(n)))return t}else if(t.tag===19&&t.memoizedProps.revealOrder!==void 0){if(t.flags&128)return t}else if(t.child!==null){t.child.return=t,t=t.child;continue}if(t===e)break;for(;t.sibling===null;){if(t.return===null||t.return===e)return null;t=t.return}t.sibling.return=t.return,t=t.sibling}return null}function Ps(e,t,n,r){t=e.memoizedState,n=n(r,t),n=n==null?t:p({},t,n),e.memoizedState=n,e.lanes===0&&(e.updateQueue.baseState=n)}var Fs={enqueueSetState:function(e,t,n){e=e._reactInternals;var r=iu(),i=Ta(r);i.payload=t,n!=null&&(i.callback=n),t=Ea(e,i,r),t!==null&&(ou(t,e,r),Da(t,e,r))},enqueueReplaceState:function(e,t,n){e=e._reactInternals;var r=iu(),i=Ta(r);i.tag=1,i.payload=t,n!=null&&(i.callback=n),t=Ea(e,i,r),t!==null&&(ou(t,e,r),Da(t,e,r))},enqueueForceUpdate:function(e,t){e=e._reactInternals;var n=iu(),r=Ta(n);r.tag=2,t!=null&&(r.callback=t),t=Ea(e,r,n),t!==null&&(ou(t,e,n),Da(t,e,n))}};function Is(e,t,n,r,i,a,o){return e=e.stateNode,typeof e.shouldComponentUpdate==`function`?e.shouldComponentUpdate(r,a,o):t.prototype&&t.prototype.isPureReactComponent?!gr(n,r)||!gr(i,a):!0}function Ls(e,t,n,r){e=t.state,typeof t.componentWillReceiveProps==`function`&&t.componentWillReceiveProps(n,r),typeof t.UNSAFE_componentWillReceiveProps==`function`&&t.UNSAFE_componentWillReceiveProps(n,r),t.state!==e&&Fs.enqueueReplaceState(t,t.state,null)}function Rs(e,t){var n=t;if(`ref`in t)for(var r in n={},t)r!==`ref`&&(n[r]=t[r]);if(e=e.defaultProps)for(var i in n===t&&(n=p({},n)),e)n[i]===void 0&&(n[i]=e[i]);return n}var zs=typeof reportError==`function`?reportError:function(e){if(typeof window==`object`&&typeof window.ErrorEvent==`function`){var t=new window.ErrorEvent(`error`,{bubbles:!0,cancelable:!0,message:typeof e==`object`&&e&&typeof e.message==`string`?String(e.message):String(e),error:e});if(!window.dispatchEvent(t))return}else if(typeof process==`object`&&typeof process.emit==`function`){process.emit(`uncaughtException`,e);return}console.error(e)};function Bs(e){zs(e)}function Vs(e){console.error(e)}function Hs(e){zs(e)}function Us(e,t){try{var n=e.onUncaughtError;n(t.value,{componentStack:t.stack})}catch(e){setTimeout(function(){throw e})}}function Ws(e,t,n){try{var r=e.onCaughtError;r(n.value,{componentStack:n.stack,errorBoundary:t.tag===1?t.stateNode:null})}catch(e){setTimeout(function(){throw e})}}function Gs(e,t,n){return n=Ta(n),n.tag=3,n.payload={element:null},n.callback=function(){Us(e,t)},n}function Ks(e){return e=Ta(e),e.tag=3,e}function qs(e,t,n,r){var i=n.type.getDerivedStateFromError;if(typeof i==`function`){var a=r.value;e.payload=function(){return i(a)},e.callback=function(){Ws(t,n,r)}}var o=n.stateNode;o!==null&&typeof o.componentDidCatch==`function`&&(e.callback=function(){Ws(t,n,r),typeof i!=`function`&&(Jl===null?Jl=new Set([this]):Jl.add(this));var e=r.stack;this.componentDidCatch(r.value,{componentStack:e===null?``:e})})}function Js(e,t,n,r,a){if(n.flags|=32768,typeof r==`object`&&r&&typeof r.then==`function`){if(t=n.alternate,t!==null&&Ui(t,n,a,!0),n=Es.current,n!==null){switch(n.tag){case 13:return Ds===null?_u():n.alternate===null&&Il===0&&(Il=3),n.flags&=-257,n.flags|=65536,n.lanes=a,r===ga?n.flags|=16384:(t=n.updateQueue,t===null?n.updateQueue=new Set([r]):t.add(r),Iu(e,r,a)),!1;case 22:return n.flags|=65536,r===ga?n.flags|=16384:(t=n.updateQueue,t===null?(t={transitions:null,markerInstances:null,retryQueue:new Set([r])},n.updateQueue=t):(n=t.retryQueue,n===null?t.retryQueue=new Set([r]):n.add(r)),Iu(e,r,a)),!1}throw Error(i(435,n.tag))}return Iu(e,r,a),_u(),!1}if(Ti)return t=Es.current,t===null?(r!==Oi&&(t=Error(i(423),{cause:r}),Fi(Wr(t,n))),e=e.current.alternate,e.flags|=65536,a&=-a,e.lanes|=a,r=Wr(r,n),a=Gs(e.stateNode,r,a),Oa(e,a),Il!==4&&(Il=2)):(!(t.flags&65536)&&(t.flags|=256),t.flags|=65536,t.lanes=a,r!==Oi&&(e=Error(i(422),{cause:r}),Fi(Wr(e,n)))),!1;var o=Error(i(520),{cause:r});if(o=Wr(o,n),Hl===null?Hl=[o]:Hl.push(o),Il!==4&&(Il=2),t===null)return!0;r=Wr(r,n),n=t;do{switch(n.tag){case 3:return n.flags|=65536,e=a&-a,n.lanes|=e,e=Gs(n.stateNode,r,e),Oa(n,e),!1;case 1:if(t=n.type,o=n.stateNode,!(n.flags&128)&&(typeof t.getDerivedStateFromError==`function`||o!==null&&typeof o.componentDidCatch==`function`&&(Jl===null||!Jl.has(o))))return n.flags|=65536,a&=-a,n.lanes|=a,a=Ks(a),qs(a,e,n,r),Oa(n,a),!1}n=n.return}while(n!==null);return!1}var Ys=Error(i(461)),Xs=!1;function Zs(e,t,n,r){t.child=e===null?Ts(t,null,n,r):ws(t,e.child,n,r)}function Qs(e,t,n,r,i){n=n.render;var a=t.ref;if(`ref`in r){var o={};for(var s in r)s!==`ref`&&(o[s]=r[s])}else o=r;return Gi(t),r=Za(e,t,n,o,a,i),s=to(),e!==null&&!Xs?(no(e,t,i),vc(e,t,i)):(Ti&&s&&xi(t),t.flags|=1,Zs(e,t,r,i),t.child)}function $s(e,t,n,r,i){if(e===null){var a=n.type;return typeof a==`function`&&!ri(a)&&a.defaultProps===void 0&&n.compare===null?(t.tag=15,t.type=a,ec(e,t,a,r,i)):(e=oi(n.type,null,r,t,t.mode,i),e.ref=t.ref,e.return=t,t.child=e)}if(a=e.child,!yc(e,i)){var o=a.memoizedProps;if(n=n.compare,n=n===null?gr:n,n(o,r)&&e.ref===t.ref)return vc(e,t,i)}return t.flags|=1,e=ii(a,r),e.ref=t.ref,e.return=t,t.child=e}function ec(e,t,n,r,i){if(e!==null){var a=e.memoizedProps;if(gr(a,r)&&e.ref===t.ref){if(Xs=!1,t.pendingProps=r=a,yc(e,i))e.flags&131072&&(Xs=!0);else return t.lanes=e.lanes,vc(e,t,i)}}return ic(e,t,n,r,i)}function tc(e,t,n){var r=t.pendingProps,i=r.children,a=e===null?null:e.memoizedState;if(r.mode===`hidden`){if(t.flags&128){if(r=a===null?n:a.baseLanes|n,e!==null){for(i=t.child=e.child,a=0;i!==null;)a=a|i.lanes|i.childLanes,i=i.sibling;t.childLanes=a&~r}else t.childLanes=0,t.child=null;return nc(e,t,r,n)}if(n&536870912)t.memoizedState={baseLanes:0,cachePool:null},e!==null&&da(t,a===null?null:a.cachePool),a===null?La():Ia(t,a),ks(t);else return t.lanes=t.childLanes=536870912,nc(e,t,a===null?n:a.baseLanes|n,n)}else a===null?(e!==null&&da(t,null),La(),As(t)):(da(t,a.cachePool),Ia(t,a),As(t),t.memoizedState=null);return Zs(e,t,i,n),t.child}function nc(e,t,n,r){var i=ua();return i=i===null?null:{parent:Qi._currentValue,pool:i},t.memoizedState={baseLanes:n,cachePool:i},e!==null&&da(t,null),La(),ks(t),e!==null&&Ui(e,t,r,!0),null}function rc(e,t){var n=t.ref;if(n===null)e!==null&&e.ref!==null&&(t.flags|=4194816);else{if(typeof n!=`function`&&typeof n!=`object`)throw Error(i(284));(e===null||e.ref!==n)&&(t.flags|=4194816)}}function ic(e,t,n,r,i){return Gi(t),n=Za(e,t,n,r,void 0,i),r=to(),e!==null&&!Xs?(no(e,t,i),vc(e,t,i)):(Ti&&r&&xi(t),t.flags|=1,Zs(e,t,n,i),t.child)}function ac(e,t,n,r,i,a){return Gi(t),t.updateQueue=null,n=$a(t,r,n,i),Qa(e),r=to(),e!==null&&!Xs?(no(e,t,a),vc(e,t,a)):(Ti&&r&&xi(t),t.flags|=1,Zs(e,t,n,a),t.child)}function oc(e,t,n,r,i){if(Gi(t),t.stateNode===null){var a=ei,o=n.contextType;typeof o==`object`&&o&&(a=Ki(o)),a=new n(r,a),t.memoizedState=a.state!==null&&a.state!==void 0?a.state:null,a.updater=Fs,t.stateNode=a,a._reactInternals=t,a=t.stateNode,a.props=r,a.state=t.memoizedState,a.refs={},Ca(t),o=n.contextType,a.context=typeof o==`object`&&o?Ki(o):ei,a.state=t.memoizedState,o=n.getDerivedStateFromProps,typeof o==`function`&&(Ps(t,n,o,r),a.state=t.memoizedState),typeof n.getDerivedStateFromProps==`function`||typeof a.getSnapshotBeforeUpdate==`function`||typeof a.UNSAFE_componentWillMount!=`function`&&typeof a.componentWillMount!=`function`||(o=a.state,typeof a.componentWillMount==`function`&&a.componentWillMount(),typeof a.UNSAFE_componentWillMount==`function`&&a.UNSAFE_componentWillMount(),o!==a.state&&Fs.enqueueReplaceState(a,a.state,null),ja(t,r,a,i),Aa(),a.state=t.memoizedState),typeof a.componentDidMount==`function`&&(t.flags|=4194308),r=!0}else if(e===null){a=t.stateNode;var s=t.memoizedProps,c=Rs(n,s);a.props=c;var l=a.context,u=n.contextType;o=ei,typeof u==`object`&&u&&(o=Ki(u));var d=n.getDerivedStateFromProps;u=typeof d==`function`||typeof a.getSnapshotBeforeUpdate==`function`,s=t.pendingProps!==s,u||typeof a.UNSAFE_componentWillReceiveProps!=`function`&&typeof a.componentWillReceiveProps!=`function`||(s||l!==o)&&Ls(t,a,r,o),W=!1;var f=t.memoizedState;a.state=f,ja(t,r,a,i),Aa(),l=t.memoizedState,s||f!==l||W?(typeof d==`function`&&(Ps(t,n,d,r),l=t.memoizedState),(c=W||Is(t,n,c,r,f,l,o))?(u||typeof a.UNSAFE_componentWillMount!=`function`&&typeof a.componentWillMount!=`function`||(typeof a.componentWillMount==`function`&&a.componentWillMount(),typeof a.UNSAFE_componentWillMount==`function`&&a.UNSAFE_componentWillMount()),typeof a.componentDidMount==`function`&&(t.flags|=4194308)):(typeof a.componentDidMount==`function`&&(t.flags|=4194308),t.memoizedProps=r,t.memoizedState=l),a.props=r,a.state=l,a.context=o,r=c):(typeof a.componentDidMount==`function`&&(t.flags|=4194308),r=!1)}else{a=t.stateNode,wa(e,t),o=t.memoizedProps,u=Rs(n,o),a.props=u,d=t.pendingProps,f=a.context,l=n.contextType,c=ei,typeof l==`object`&&l&&(c=Ki(l)),s=n.getDerivedStateFromProps,(l=typeof s==`function`||typeof a.getSnapshotBeforeUpdate==`function`)||typeof a.UNSAFE_componentWillReceiveProps!=`function`&&typeof a.componentWillReceiveProps!=`function`||(o!==d||f!==c)&&Ls(t,a,r,c),W=!1,f=t.memoizedState,a.state=f,ja(t,r,a,i),Aa();var p=t.memoizedState;o!==d||f!==p||W||e!==null&&e.dependencies!==null&&Wi(e.dependencies)?(typeof s==`function`&&(Ps(t,n,s,r),p=t.memoizedState),(u=W||Is(t,n,u,r,f,p,c)||e!==null&&e.dependencies!==null&&Wi(e.dependencies))?(l||typeof a.UNSAFE_componentWillUpdate!=`function`&&typeof a.componentWillUpdate!=`function`||(typeof a.componentWillUpdate==`function`&&a.componentWillUpdate(r,p,c),typeof a.UNSAFE_componentWillUpdate==`function`&&a.UNSAFE_componentWillUpdate(r,p,c)),typeof a.componentDidUpdate==`function`&&(t.flags|=4),typeof a.getSnapshotBeforeUpdate==`function`&&(t.flags|=1024)):(typeof a.componentDidUpdate!=`function`||o===e.memoizedProps&&f===e.memoizedState||(t.flags|=4),typeof a.getSnapshotBeforeUpdate!=`function`||o===e.memoizedProps&&f===e.memoizedState||(t.flags|=1024),t.memoizedProps=r,t.memoizedState=p),a.props=r,a.state=p,a.context=c,r=u):(typeof a.componentDidUpdate!=`function`||o===e.memoizedProps&&f===e.memoizedState||(t.flags|=4),typeof a.getSnapshotBeforeUpdate!=`function`||o===e.memoizedProps&&f===e.memoizedState||(t.flags|=1024),r=!1)}return a=r,rc(e,t),r=!!(t.flags&128),a||r?(a=t.stateNode,n=r&&typeof n.getDerivedStateFromError!=`function`?null:a.render(),t.flags|=1,e!==null&&r?(t.child=ws(t,e.child,null,i),t.child=ws(t,null,n,i)):Zs(e,t,n,i),t.memoizedState=a.state,e=t.child):e=vc(e,t,i),e}function sc(e,t,n,r){return Ni(),t.flags|=256,Zs(e,t,n,r),t.child}var cc={dehydrated:null,treeContext:null,retryLane:0,hydrationErrors:null};function lc(e){return{baseLanes:e,cachePool:fa()}}function uc(e,t,n){return e=e===null?0:e.childLanes&~n,t&&(e|=Bl),e}function dc(e,t,n){var r=t.pendingProps,a=!1,o=!!(t.flags&128),s;if((s=o)||(s=e!==null&&e.memoizedState===null?!1:!!(Ms.current&2)),s&&(a=!0,t.flags&=-129),s=!!(t.flags&32),t.flags&=-33,e===null){if(Ti){if(a?Os(t):As(t),Ti){var c=wi,l;if(l=c){c:{for(l=c,c=Di;l.nodeType!==8;)if(!c||(l=Jd(l.nextSibling),l===null)){c=null;break c}c=l}c===null?l=!1:(t.memoizedState={dehydrated:c,treeContext:gi===null?null:{id:_i,overflow:vi},retryLane:536870912,hydrationErrors:null},l=ni(18,null,null,0),l.stateNode=c,l.return=t,t.child=l,Ci=t,wi=null,l=!0)}l||ki(t)}if(c=t.memoizedState,c!==null&&(c=c.dehydrated,c!==null))return Kd(c)?t.lanes=32:t.lanes=536870912,null;js(t)}return c=r.children,r=r.fallback,a?(As(t),a=t.mode,c=pc({mode:`hidden`,children:c},a),r=si(r,a,n,null),c.return=t,r.return=t,c.sibling=r,t.child=c,a=t.child,a.memoizedState=lc(n),a.childLanes=uc(e,s,n),t.memoizedState=cc,r):(Os(t),fc(t,c))}if(l=e.memoizedState,l!==null&&(c=l.dehydrated,c!==null)){if(o)t.flags&256?(Os(t),t.flags&=-257,t=mc(e,t,n)):t.memoizedState===null?(As(t),a=r.fallback,c=t.mode,r=pc({mode:`visible`,children:r.children},c),a=si(a,c,n,null),a.flags|=2,r.return=t,a.return=t,r.sibling=a,t.child=r,ws(t,e.child,null,n),r=t.child,r.memoizedState=lc(n),r.childLanes=uc(e,s,n),t.memoizedState=cc,t=a):(As(t),t.child=e.child,t.flags|=128,t=null);else if(Os(t),Kd(c)){if(s=c.nextSibling&&c.nextSibling.dataset,s)var u=s.dgst;s=u,r=Error(i(419)),r.stack=``,r.digest=s,Fi({value:r,source:null,stack:null}),t=mc(e,t,n)}else if(Xs||Ui(e,t,n,!1),s=(n&e.childLanes)!==0,Xs||s){if(s=kl,s!==null&&(r=n&-n,r=r&42?1:Ue(r),r=(r&(s.suspendedLanes|n))===0?r:0,r!==0&&r!==l.retryLane))throw l.retryLane=r,Zr(e,r),ou(s,e,r),Ys;c.data===`$?`||_u(),t=mc(e,t,n)}else c.data===`$?`?(t.flags|=192,t.child=e.child,t=null):(e=l.treeContext,wi=Jd(c.nextSibling),Ci=t,Ti=!0,Ei=null,Di=!1,e!==null&&(mi[hi++]=_i,mi[hi++]=vi,mi[hi++]=gi,_i=e.id,vi=e.overflow,gi=t),t=fc(t,r.children),t.flags|=4096);return t}return a?(As(t),a=r.fallback,c=t.mode,l=e.child,u=l.sibling,r=ii(l,{mode:`hidden`,children:r.children}),r.subtreeFlags=l.subtreeFlags&65011712,u===null?(a=si(a,c,n,null),a.flags|=2):a=ii(u,a),a.return=t,r.return=t,r.sibling=a,t.child=r,r=a,a=t.child,c=e.child.memoizedState,c===null?c=lc(n):(l=c.cachePool,l===null?l=fa():(u=Qi._currentValue,l=l.parent===u?l:{parent:u,pool:u}),c={baseLanes:c.baseLanes|n,cachePool:l}),a.memoizedState=c,a.childLanes=uc(e,s,n),t.memoizedState=cc,r):(Os(t),n=e.child,e=n.sibling,n=ii(n,{mode:`visible`,children:r.children}),n.return=t,n.sibling=null,e!==null&&(s=t.deletions,s===null?(t.deletions=[e],t.flags|=16):s.push(e)),t.child=n,t.memoizedState=null,n)}function fc(e,t){return t=pc({mode:`visible`,children:t},e.mode),t.return=e,e.child=t}function pc(e,t){return e=ni(22,e,null,t),e.lanes=0,e.stateNode={_visibility:1,_pendingMarkers:null,_retryCache:null,_transitions:null},e}function mc(e,t,n){return ws(t,e.child,null,n),e=fc(t,t.pendingProps.children),e.flags|=2,t.memoizedState=null,e}function hc(e,t,n){e.lanes|=t;var r=e.alternate;r!==null&&(r.lanes|=t),Vi(e.return,t,n)}function gc(e,t,n,r,i){var a=e.memoizedState;a===null?e.memoizedState={isBackwards:t,rendering:null,renderingStartTime:0,last:r,tail:n,tailMode:i}:(a.isBackwards=t,a.rendering=null,a.renderingStartTime=0,a.last=r,a.tail=n,a.tailMode=i)}function _c(e,t,n){var r=t.pendingProps,i=r.revealOrder,a=r.tail;if(Zs(e,t,r.children,n),r=Ms.current,r&2)r=r&1|2,t.flags|=128;else{if(e!==null&&e.flags&128)a:for(e=t.child;e!==null;){if(e.tag===13)e.memoizedState!==null&&hc(e,n,t);else if(e.tag===19)hc(e,n,t);else if(e.child!==null){e.child.return=e,e=e.child;continue}if(e===t)break a;for(;e.sibling===null;){if(e.return===null||e.return===t)break a;e=e.return}e.sibling.return=e.return,e=e.sibling}r&=1}switch(z(Ms,r),i){case`forwards`:for(n=t.child,i=null;n!==null;)e=n.alternate,e!==null&&Ns(e)===null&&(i=n),n=n.sibling;n=i,n===null?(i=t.child,t.child=null):(i=n.sibling,n.sibling=null),gc(t,!1,i,n,a);break;case`backwards`:for(n=null,i=t.child,t.child=null;i!==null;){if(e=i.alternate,e!==null&&Ns(e)===null){t.child=i;break}e=i.sibling,i.sibling=n,n=i,i=e}gc(t,!0,n,null,a);break;case`together`:gc(t,!1,null,null,void 0);break;default:t.memoizedState=null}return t.child}function vc(e,t,n){if(e!==null&&(t.dependencies=e.dependencies),Ll|=t.lanes,(n&t.childLanes)===0){if(e!==null){if(Ui(e,t,n,!1),(n&t.childLanes)===0)return null}else return null}if(e!==null&&t.child!==e.child)throw Error(i(153));if(t.child!==null){for(e=t.child,n=ii(e,e.pendingProps),t.child=n,n.return=t;e.sibling!==null;)e=e.sibling,n=n.sibling=ii(e,e.pendingProps),n.return=t;n.sibling=null}return t.child}function yc(e,t){return(e.lanes&t)!==0||(e=e.dependencies,!!(e!==null&&Wi(e)))}function bc(e,t,n){switch(t.tag){case 3:ce(t,t.stateNode.containerInfo),zi(t,Qi,e.memoizedState.cache),Ni();break;case 27:case 5:ue(t);break;case 4:ce(t,t.stateNode.containerInfo);break;case 10:zi(t,t.type,t.memoizedProps.value);break;case 13:var r=t.memoizedState;if(r!==null)return r.dehydrated===null?(n&t.child.childLanes)===0?(Os(t),e=vc(e,t,n),e===null?null:e.sibling):dc(e,t,n):(Os(t),t.flags|=128,null);Os(t);break;case 19:var i=!!(e.flags&128);if(r=(n&t.childLanes)!==0,r||=(Ui(e,t,n,!1),(n&t.childLanes)!==0),i){if(r)return _c(e,t,n);t.flags|=128}if(i=t.memoizedState,i!==null&&(i.rendering=null,i.tail=null,i.lastEffect=null),z(Ms,Ms.current),r)break;return null;case 22:case 23:return t.lanes=0,tc(e,t,n);case 24:zi(t,Qi,e.memoizedState.cache)}return vc(e,t,n)}function xc(e,t,n){if(e!==null){if(e.memoizedProps!==t.pendingProps)Xs=!0;else{if(!yc(e,n)&&!(t.flags&128))return Xs=!1,bc(e,t,n);Xs=!!(e.flags&131072)}}else Xs=!1,Ti&&t.flags&1048576&&bi(t,pi,t.index);switch(t.lanes=0,t.tag){case 16:a:{e=t.pendingProps;var r=t.elementType,a=r._init;if(r=a(r._payload),t.type=r,typeof r==`function`)ri(r)?(e=Rs(r,e),t.tag=1,t=oc(null,t,r,e,n)):(t.tag=0,t=ic(null,t,r,e,n));else{if(r!=null){if(a=r.$$typeof,a===w){t.tag=11,t=Qs(null,t,r,e,n);break a}if(a===D){t.tag=14,t=$s(null,t,r,e,n);break a}}throw t=te(r)||r,Error(i(306,t,``))}}return t;case 0:return ic(e,t,t.type,t.pendingProps,n);case 1:return r=t.type,a=Rs(r,t.pendingProps),oc(e,t,r,a,n);case 3:a:{if(ce(t,t.stateNode.containerInfo),e===null)throw Error(i(387));r=t.pendingProps;var o=t.memoizedState;a=o.element,wa(e,t),ja(t,r,null,n);var s=t.memoizedState;if(r=s.cache,zi(t,Qi,r),r!==o.cache&&Hi(t,[Qi],n,!0),Aa(),r=s.element,o.isDehydrated){if(o={element:r,isDehydrated:!1,cache:s.cache},t.updateQueue.baseState=o,t.memoizedState=o,t.flags&256){t=sc(e,t,r,n);break a}if(r!==a){a=Wr(Error(i(424)),t),Fi(a),t=sc(e,t,r,n);break a}switch(e=t.stateNode.containerInfo,e.nodeType){case 9:e=e.body;break;default:e=e.nodeName===`HTML`?e.ownerDocument.body:e}for(wi=Jd(e.firstChild),Ci=t,Ti=!0,Ei=null,Di=!0,n=Ts(t,null,r,n),t.child=n;n;)n.flags=n.flags&-3|4096,n=n.sibling}else{if(Ni(),r===a){t=vc(e,t,n);break a}Zs(e,t,r,n)}t=t.child}return t;case 26:return rc(e,t),e===null?(n=hf(t.type,null,t.pendingProps,null))?t.memoizedState=n:Ti||(n=t.type,e=t.pendingProps,r=Ad(oe.current).createElement(n),r[Je]=t,r[Ye]=e,Y(r,n,e),st(r),t.stateNode=r):t.memoizedState=hf(t.type,e.memoizedProps,t.pendingProps,e.memoizedState),null;case 27:return ue(t),e===null&&Ti&&(r=t.stateNode=Zd(t.type,t.pendingProps,oe.current),Ci=t,Di=!0,a=wi,Vd(t.type)?(Yd=a,wi=Jd(r.firstChild)):wi=a),Zs(e,t,t.pendingProps.children,n),rc(e,t),e===null&&(t.flags|=4194304),t.child;case 5:return e===null&&Ti&&((a=r=wi)&&(r=Wd(r,t.type,t.pendingProps,Di),r===null?a=!1:(t.stateNode=r,Ci=t,wi=Jd(r.firstChild),Di=!1,a=!0)),a||ki(t)),ue(t),a=t.type,o=t.pendingProps,s=e===null?null:e.memoizedProps,r=o.children,Nd(a,o)?r=null:s!==null&&Nd(a,s)&&(t.flags|=32),t.memoizedState!==null&&(a=Za(e,t,eo,null,null,n),zf._currentValue=a),rc(e,t),Zs(e,t,r,n),t.child;case 6:return e===null&&Ti&&((e=n=wi)&&(n=Gd(n,t.pendingProps,Di),n===null?e=!1:(t.stateNode=n,Ci=t,wi=null,e=!0)),e||ki(t)),null;case 13:return dc(e,t,n);case 4:return ce(t,t.stateNode.containerInfo),r=t.pendingProps,e===null?t.child=ws(t,null,r,n):Zs(e,t,r,n),t.child;case 11:return Qs(e,t,t.type,t.pendingProps,n);case 7:return Zs(e,t,t.pendingProps,n),t.child;case 8:return Zs(e,t,t.pendingProps.children,n),t.child;case 12:return Zs(e,t,t.pendingProps.children,n),t.child;case 10:return r=t.pendingProps,zi(t,t.type,r.value),Zs(e,t,r.children,n),t.child;case 9:return a=t.type._context,r=t.pendingProps.children,Gi(t),a=Ki(a),r=r(a),t.flags|=1,Zs(e,t,r,n),t.child;case 14:return $s(e,t,t.type,t.pendingProps,n);case 15:return ec(e,t,t.type,t.pendingProps,n);case 19:return _c(e,t,n);case 31:return r=t.pendingProps,n=t.mode,r={mode:r.mode,children:r.children},e===null?(n=pc(r,n),n.ref=t.ref,t.child=n,n.return=t,t=n):(n=ii(e.child,r),n.ref=t.ref,t.child=n,n.return=t,t=n),t;case 22:return tc(e,t,n);case 24:return Gi(t),r=Ki(Qi),e===null?(a=ua(),a===null&&(a=kl,o=$i(),a.pooledCache=o,o.refCount++,o!==null&&(a.pooledCacheLanes|=n),a=o),t.memoizedState={parent:r,cache:a},Ca(t),zi(t,Qi,a)):((e.lanes&n)!==0&&(wa(e,t),ja(t,null,null,n),Aa()),a=e.memoizedState,o=t.memoizedState,a.parent===r?(r=o.cache,zi(t,Qi,r),r!==a.cache&&Hi(t,[Qi],n,!0)):(a={parent:r,cache:r},t.memoizedState=a,t.lanes===0&&(t.memoizedState=t.updateQueue.baseState=a),zi(t,Qi,r))),Zs(e,t,t.pendingProps.children,n),t.child;case 29:throw t.pendingProps}throw Error(i(156,t.tag))}function Sc(e){e.flags|=4}function Cc(e,t){if(t.type!==`stylesheet`||t.state.loading&4)e.flags&=-16777217;else if(e.flags|=16777216,!Af(t)){if(t=Es.current,t!==null&&((q&4194048)===q?Ds!==null:(q&62914560)!==q&&!(q&536870912)||t!==Ds))throw ba=ga,ma;e.flags|=8192}}function wc(e,t){t!==null&&(e.flags|=4),e.flags&16384&&(t=e.tag===22?536870912:Le(),e.lanes|=t,Vl|=t)}function Tc(e,t){if(!Ti)switch(e.tailMode){case`hidden`:t=e.tail;for(var n=null;t!==null;)t.alternate!==null&&(n=t),t=t.sibling;n===null?e.tail=null:n.sibling=null;break;case`collapsed`:n=e.tail;for(var r=null;n!==null;)n.alternate!==null&&(r=n),n=n.sibling;r===null?t||e.tail===null?e.tail=null:e.tail.sibling=null:r.sibling=null}}function Ec(e){var t=e.alternate!==null&&e.alternate.child===e.child,n=0,r=0;if(t)for(var i=e.child;i!==null;)n|=i.lanes|i.childLanes,r|=i.subtreeFlags&65011712,r|=i.flags&65011712,i.return=e,i=i.sibling;else for(i=e.child;i!==null;)n|=i.lanes|i.childLanes,r|=i.subtreeFlags,r|=i.flags,i.return=e,i=i.sibling;return e.subtreeFlags|=r,e.childLanes=n,t}function Dc(e,t,n){var r=t.pendingProps;switch(Si(t),t.tag){case 31:case 16:case 15:case 0:case 11:case 7:case 8:case 12:case 9:case 14:return Ec(t),null;case 1:return Ec(t),null;case 3:return n=t.stateNode,r=null,e!==null&&(r=e.memoizedState.cache),t.memoizedState.cache!==r&&(t.flags|=2048),Bi(Qi),le(),n.pendingContext&&(n.context=n.pendingContext,n.pendingContext=null),(e===null||e.child===null)&&(Mi(t)?Sc(t):e===null||e.memoizedState.isDehydrated&&!(t.flags&256)||(t.flags|=1024,Pi())),Ec(t),null;case 26:return n=t.memoizedState,e===null?(Sc(t),n===null?(Ec(t),t.flags&=-16777217):(Ec(t),Cc(t,n))):n?n===e.memoizedState?(Ec(t),t.flags&=-16777217):(Sc(t),Ec(t),Cc(t,n)):(e.memoizedProps!==r&&Sc(t),Ec(t),t.flags&=-16777217),null;case 27:de(t),n=oe.current;var a=t.type;if(e!==null&&t.stateNode!=null)e.memoizedProps!==r&&Sc(t);else{if(!r){if(t.stateNode===null)throw Error(i(166));return Ec(t),null}e=ie.current,Mi(t)?Ai(t,e):(e=Zd(a,r,n),t.stateNode=e,Sc(t))}return Ec(t),null;case 5:if(de(t),n=t.type,e!==null&&t.stateNode!=null)e.memoizedProps!==r&&Sc(t);else{if(!r){if(t.stateNode===null)throw Error(i(166));return Ec(t),null}if(e=ie.current,Mi(t))Ai(t,e);else{switch(a=Ad(oe.current),e){case 1:e=a.createElementNS(`http://www.w3.org/2000/svg`,n);break;case 2:e=a.createElementNS(`http://www.w3.org/1998/Math/MathML`,n);break;default:switch(n){case`svg`:e=a.createElementNS(`http://www.w3.org/2000/svg`,n);break;case`math`:e=a.createElementNS(`http://www.w3.org/1998/Math/MathML`,n);break;case`script`:e=a.createElement(`div`),e.innerHTML=`<script><\/script>`,e=e.removeChild(e.firstChild);break;case`select`:e=typeof r.is==`string`?a.createElement(`select`,{is:r.is}):a.createElement(`select`),r.multiple?e.multiple=!0:r.size&&(e.size=r.size);break;default:e=typeof r.is==`string`?a.createElement(n,{is:r.is}):a.createElement(n)}}e[Je]=t,e[Ye]=r;a:for(a=t.child;a!==null;){if(a.tag===5||a.tag===6)e.appendChild(a.stateNode);else if(a.tag!==4&&a.tag!==27&&a.child!==null){a.child.return=a,a=a.child;continue}if(a===t)break a;for(;a.sibling===null;){if(a.return===null||a.return===t)break a;a=a.return}a.sibling.return=a.return,a=a.sibling}t.stateNode=e;a:switch(Y(e,n,r),n){case`button`:case`input`:case`select`:case`textarea`:e=!!r.autoFocus;break a;case`img`:e=!0;break a;default:e=!1}e&&Sc(t)}}return Ec(t),t.flags&=-16777217,null;case 6:if(e&&t.stateNode!=null)e.memoizedProps!==r&&Sc(t);else{if(typeof r!=`string`&&t.stateNode===null)throw Error(i(166));if(e=oe.current,Mi(t)){if(e=t.stateNode,n=t.memoizedProps,r=null,a=Ci,a!==null)switch(a.tag){case 27:case 5:r=a.memoizedProps}e[Je]=t,e=!!(e.nodeValue===n||r!==null&&!0===r.suppressHydrationWarning||Cd(e.nodeValue,n)),e||ki(t)}else e=Ad(e).createTextNode(r),e[Je]=t,t.stateNode=e}return Ec(t),null;case 13:if(r=t.memoizedState,e===null||e.memoizedState!==null&&e.memoizedState.dehydrated!==null){if(a=Mi(t),r!==null&&r.dehydrated!==null){if(e===null){if(!a)throw Error(i(318));if(a=t.memoizedState,a=a===null?null:a.dehydrated,!a)throw Error(i(317));a[Je]=t}else Ni(),!(t.flags&128)&&(t.memoizedState=null),t.flags|=4;Ec(t),a=!1}else a=Pi(),e!==null&&e.memoizedState!==null&&(e.memoizedState.hydrationErrors=a),a=!0;if(!a)return t.flags&256?(js(t),t):(js(t),null)}if(js(t),t.flags&128)return t.lanes=n,t;if(n=r!==null,e=e!==null&&e.memoizedState!==null,n){r=t.child,a=null,r.alternate!==null&&r.alternate.memoizedState!==null&&r.alternate.memoizedState.cachePool!==null&&(a=r.alternate.memoizedState.cachePool.pool);var o=null;r.memoizedState!==null&&r.memoizedState.cachePool!==null&&(o=r.memoizedState.cachePool.pool),o!==a&&(r.flags|=2048)}return n!==e&&n&&(t.child.flags|=8192),wc(t,t.updateQueue),Ec(t),null;case 4:return le(),e===null&&pd(t.stateNode.containerInfo),Ec(t),null;case 10:return Bi(t.type),Ec(t),null;case 19:if(R(Ms),a=t.memoizedState,a===null)return Ec(t),null;if(r=!!(t.flags&128),o=a.rendering,o===null){if(r)Tc(a,!1);else{if(Il!==0||e!==null&&e.flags&128)for(e=t.child;e!==null;){if(o=Ns(e),o!==null){for(t.flags|=128,Tc(a,!1),e=o.updateQueue,t.updateQueue=e,wc(t,e),t.subtreeFlags=0,e=n,n=t.child;n!==null;)ai(n,e),n=n.sibling;return z(Ms,Ms.current&1|2),t.child}e=e.sibling}a.tail!==null&&ge()>Kl&&(t.flags|=128,r=!0,Tc(a,!1),t.lanes=4194304)}}else{if(!r){if(e=Ns(o),e!==null){if(t.flags|=128,r=!0,e=e.updateQueue,t.updateQueue=e,wc(t,e),Tc(a,!0),a.tail===null&&a.tailMode===`hidden`&&!o.alternate&&!Ti)return Ec(t),null}else 2*ge()-a.renderingStartTime>Kl&&n!==536870912&&(t.flags|=128,r=!0,Tc(a,!1),t.lanes=4194304)}a.isBackwards?(o.sibling=t.child,t.child=o):(e=a.last,e===null?t.child=o:e.sibling=o,a.last=o)}return a.tail===null?(Ec(t),null):(t=a.tail,a.rendering=t,a.tail=t.sibling,a.renderingStartTime=ge(),t.sibling=null,e=Ms.current,z(Ms,r?e&1|2:e&1),t);case 22:case 23:return js(t),Ra(),r=t.memoizedState!==null,e===null?r&&(t.flags|=8192):e.memoizedState!==null!==r&&(t.flags|=8192),r?n&536870912&&!(t.flags&128)&&(Ec(t),t.subtreeFlags&6&&(t.flags|=8192)):Ec(t),n=t.updateQueue,n!==null&&wc(t,n.retryQueue),n=null,e!==null&&e.memoizedState!==null&&e.memoizedState.cachePool!==null&&(n=e.memoizedState.cachePool.pool),r=null,t.memoizedState!==null&&t.memoizedState.cachePool!==null&&(r=t.memoizedState.cachePool.pool),r!==n&&(t.flags|=2048),e!==null&&R(la),null;case 24:return n=null,e!==null&&(n=e.memoizedState.cache),t.memoizedState.cache!==n&&(t.flags|=2048),Bi(Qi),Ec(t),null;case 25:return null;case 30:return null}throw Error(i(156,t.tag))}function Oc(e,t){switch(Si(t),t.tag){case 1:return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 3:return Bi(Qi),le(),e=t.flags,e&65536&&!(e&128)?(t.flags=e&-65537|128,t):null;case 26:case 27:case 5:return de(t),null;case 13:if(js(t),e=t.memoizedState,e!==null&&e.dehydrated!==null){if(t.alternate===null)throw Error(i(340));Ni()}return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 19:return R(Ms),null;case 4:return le(),null;case 10:return Bi(t.type),null;case 22:case 23:return js(t),Ra(),e!==null&&R(la),e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 24:return Bi(Qi),null;case 25:return null;default:return null}}function kc(e,t){switch(Si(t),t.tag){case 3:Bi(Qi),le();break;case 26:case 27:case 5:de(t);break;case 4:le();break;case 13:js(t);break;case 19:R(Ms);break;case 10:Bi(t.type);break;case 22:case 23:js(t),Ra(),e!==null&&R(la);break;case 24:Bi(Qi)}}function Ac(e,t){try{var n=t.updateQueue,r=n===null?null:n.lastEffect;if(r!==null){var i=r.next;n=i;do{if((n.tag&e)===e){r=void 0;var a=n.create,o=n.inst;r=a(),o.destroy=r}n=n.next}while(n!==i)}}catch(e){Fu(t,t.return,e)}}function jc(e,t,n){try{var r=t.updateQueue,i=r===null?null:r.lastEffect;if(i!==null){var a=i.next;r=a;do{if((r.tag&e)===e){var o=r.inst,s=o.destroy;if(s!==void 0){o.destroy=void 0,i=t;var c=n,l=s;try{l()}catch(e){Fu(i,c,e)}}}r=r.next}while(r!==a)}}catch(e){Fu(t,t.return,e)}}function Mc(e){var t=e.updateQueue;if(t!==null){var n=e.stateNode;try{Na(t,n)}catch(t){Fu(e,e.return,t)}}}function Nc(e,t,n){n.props=Rs(e.type,e.memoizedProps),n.state=e.memoizedState;try{n.componentWillUnmount()}catch(n){Fu(e,t,n)}}function Pc(e,t){try{var n=e.ref;if(n!==null){switch(e.tag){case 26:case 27:case 5:var r=e.stateNode;break;case 30:r=e.stateNode;break;default:r=e.stateNode}typeof n==`function`?e.refCleanup=n(r):n.current=r}}catch(n){Fu(e,t,n)}}function Fc(e,t){var n=e.ref,r=e.refCleanup;if(n!==null){if(typeof r==`function`)try{r()}catch(n){Fu(e,t,n)}finally{e.refCleanup=null,e=e.alternate,e!=null&&(e.refCleanup=null)}else if(typeof n==`function`)try{n(null)}catch(n){Fu(e,t,n)}else n.current=null}}function Ic(e){var t=e.type,n=e.memoizedProps,r=e.stateNode;try{a:switch(t){case`button`:case`input`:case`select`:case`textarea`:n.autoFocus&&r.focus();break a;case`img`:n.src?r.src=n.src:n.srcSet&&(r.srcset=n.srcSet)}}catch(t){Fu(e,e.return,t)}}function Lc(e,t,n){try{var r=e.stateNode;Dd(r,e.type,n,t),r[Ye]=t}catch(t){Fu(e,e.return,t)}}function Rc(e){return e.tag===5||e.tag===3||e.tag===26||e.tag===27&&Vd(e.type)||e.tag===4}function zc(e){a:for(;;){for(;e.sibling===null;){if(e.return===null||Rc(e.return))return null;e=e.return}for(e.sibling.return=e.return,e=e.sibling;e.tag!==5&&e.tag!==6&&e.tag!==18;){if(e.tag===27&&Vd(e.type)||e.flags&2||e.child===null||e.tag===4)continue a;e.child.return=e,e=e.child}if(!(e.flags&2))return e.stateNode}}function Bc(e,t,n){var r=e.tag;if(r===5||r===6)e=e.stateNode,t?(n.nodeType===9?n.body:n.nodeName===`HTML`?n.ownerDocument.body:n).insertBefore(e,t):(t=n.nodeType===9?n.body:n.nodeName===`HTML`?n.ownerDocument.body:n,t.appendChild(e),n=n._reactRootContainer,n!=null||t.onclick!==null||(t.onclick=wd));else if(r!==4&&(r===27&&Vd(e.type)&&(n=e.stateNode,t=null),e=e.child,e!==null))for(Bc(e,t,n),e=e.sibling;e!==null;)Bc(e,t,n),e=e.sibling}function Vc(e,t,n){var r=e.tag;if(r===5||r===6)e=e.stateNode,t?n.insertBefore(e,t):n.appendChild(e);else if(r!==4&&(r===27&&Vd(e.type)&&(n=e.stateNode),e=e.child,e!==null))for(Vc(e,t,n),e=e.sibling;e!==null;)Vc(e,t,n),e=e.sibling}function Hc(e){var t=e.stateNode,n=e.memoizedProps;try{for(var r=e.type,i=t.attributes;i.length;)t.removeAttributeNode(i[0]);Y(t,r,n),t[Je]=e,t[Ye]=n}catch(t){Fu(e,e.return,t)}}var Uc=!1,Wc=!1,Gc=!1,Kc=typeof WeakSet==`function`?WeakSet:Set,qc=null;function Jc(e,t){if(e=e.containerInfo,Od=qf,e=br(e),xr(e)){if(`selectionStart`in e)var n={start:e.selectionStart,end:e.selectionEnd};else a:{n=(n=e.ownerDocument)&&n.defaultView||window;var r=n.getSelection&&n.getSelection();if(r&&r.rangeCount!==0){n=r.anchorNode;var a=r.anchorOffset,o=r.focusNode;r=r.focusOffset;try{n.nodeType,o.nodeType}catch{n=null;break a}var s=0,c=-1,l=-1,u=0,d=0,f=e,p=null;b:for(;;){for(var m;f!==n||a!==0&&f.nodeType!==3||(c=s+a),f!==o||r!==0&&f.nodeType!==3||(l=s+r),f.nodeType===3&&(s+=f.nodeValue.length),(m=f.firstChild)!==null;)p=f,f=m;for(;;){if(f===e)break b;if(p===n&&++u===a&&(c=s),p===o&&++d===r&&(l=s),(m=f.nextSibling)!==null)break;f=p,p=f.parentNode}f=m}n=c===-1||l===-1?null:{start:c,end:l}}else n=null}n||={start:0,end:0}}else n=null;for(kd={focusedElem:e,selectionRange:n},qf=!1,qc=t;qc!==null;)if(t=qc,e=t.child,t.subtreeFlags&1024&&e!==null)e.return=t,qc=e;else for(;qc!==null;){switch(t=qc,o=t.alternate,e=t.flags,t.tag){case 0:break;case 11:case 15:break;case 1:if(e&1024&&o!==null){e=void 0,n=t,a=o.memoizedProps,o=o.memoizedState,r=n.stateNode;try{var h=Rs(n.type,a,n.elementType===n.type);e=r.getSnapshotBeforeUpdate(h,o),r.__reactInternalSnapshotBeforeUpdate=e}catch(e){Fu(n,n.return,e)}}break;case 3:if(e&1024){if(e=t.stateNode.containerInfo,n=e.nodeType,n===9)Ud(e);else if(n===1)switch(e.nodeName){case`HEAD`:case`HTML`:case`BODY`:Ud(e);break;default:e.textContent=``}}break;case 5:case 26:case 27:case 6:case 4:case 17:break;default:if(e&1024)throw Error(i(163))}if(e=t.sibling,e!==null){e.return=t.return,qc=e;break}qc=t.return}}function Yc(e,t,n){var r=n.flags;switch(n.tag){case 0:case 11:case 15:ll(e,n),r&4&&Ac(5,n);break;case 1:if(ll(e,n),r&4){if(e=n.stateNode,t===null)try{e.componentDidMount()}catch(e){Fu(n,n.return,e)}else{var i=Rs(n.type,t.memoizedProps);t=t.memoizedState;try{e.componentDidUpdate(i,t,e.__reactInternalSnapshotBeforeUpdate)}catch(e){Fu(n,n.return,e)}}}r&64&&Mc(n),r&512&&Pc(n,n.return);break;case 3:if(ll(e,n),r&64&&(e=n.updateQueue,e!==null)){if(t=null,n.child!==null)switch(n.child.tag){case 27:case 5:t=n.child.stateNode;break;case 1:t=n.child.stateNode}try{Na(e,t)}catch(e){Fu(n,n.return,e)}}break;case 27:t===null&&r&4&&Hc(n);case 26:case 5:ll(e,n),t===null&&r&4&&Ic(n),r&512&&Pc(n,n.return);break;case 12:ll(e,n);break;case 13:ll(e,n),r&4&&tl(e,n),r&64&&(e=n.memoizedState,e!==null&&(e=e.dehydrated,e!==null&&(n=zu.bind(null,n),qd(e,n))));break;case 22:if(r=n.memoizedState!==null||Uc,!r){t=t!==null&&t.memoizedState!==null||Wc,i=Uc;var a=Wc;Uc=r,(Wc=t)&&!a?dl(e,n,!!(n.subtreeFlags&8772)):ll(e,n),Uc=i,Wc=a}break;case 30:break;default:ll(e,n)}}function Xc(e){var t=e.alternate;t!==null&&(e.alternate=null,Xc(t)),e.child=null,e.deletions=null,e.sibling=null,e.tag===5&&(t=e.stateNode,t!==null&&nt(t)),e.stateNode=null,e.return=null,e.dependencies=null,e.memoizedProps=null,e.memoizedState=null,e.pendingProps=null,e.stateNode=null,e.updateQueue=null}var Zc=null,Qc=!1;function $c(e,t,n){for(n=n.child;n!==null;)el(e,t,n),n=n.sibling}function el(e,t,n){if(we&&typeof we.onCommitFiberUnmount==`function`)try{we.onCommitFiberUnmount(H,n)}catch{}switch(n.tag){case 26:Wc||Fc(n,t),$c(e,t,n),n.memoizedState?n.memoizedState.count--:n.stateNode&&(n=n.stateNode,n.parentNode.removeChild(n));break;case 27:Wc||Fc(n,t);var r=Zc,i=Qc;Vd(n.type)&&(Zc=n.stateNode,Qc=!1),$c(e,t,n),Qd(n.stateNode),Zc=r,Qc=i;break;case 5:Wc||Fc(n,t);case 6:if(r=Zc,i=Qc,Zc=null,$c(e,t,n),Zc=r,Qc=i,Zc!==null){if(Qc)try{(Zc.nodeType===9?Zc.body:Zc.nodeName===`HTML`?Zc.ownerDocument.body:Zc).removeChild(n.stateNode)}catch(e){Fu(n,t,e)}else try{Zc.removeChild(n.stateNode)}catch(e){Fu(n,t,e)}}break;case 18:Zc!==null&&(Qc?(e=Zc,Hd(e.nodeType===9?e.body:e.nodeName===`HTML`?e.ownerDocument.body:e,n.stateNode),yp(e)):Hd(Zc,n.stateNode));break;case 4:r=Zc,i=Qc,Zc=n.stateNode.containerInfo,Qc=!0,$c(e,t,n),Zc=r,Qc=i;break;case 0:case 11:case 14:case 15:Wc||jc(2,n,t),Wc||jc(4,n,t),$c(e,t,n);break;case 1:Wc||(Fc(n,t),r=n.stateNode,typeof r.componentWillUnmount==`function`&&Nc(n,t,r)),$c(e,t,n);break;case 21:$c(e,t,n);break;case 22:Wc=(r=Wc)||n.memoizedState!==null,$c(e,t,n),Wc=r;break;default:$c(e,t,n)}}function tl(e,t){if(t.memoizedState===null&&(e=t.alternate,e!==null&&(e=e.memoizedState,e!==null&&(e=e.dehydrated,e!==null))))try{yp(e)}catch(e){Fu(t,t.return,e)}}function nl(e){switch(e.tag){case 13:case 19:var t=e.stateNode;return t===null&&(t=e.stateNode=new Kc),t;case 22:return e=e.stateNode,t=e._retryCache,t===null&&(t=e._retryCache=new Kc),t;default:throw Error(i(435,e.tag))}}function rl(e,t){var n=nl(e);t.forEach(function(t){var r=Bu.bind(null,e,t);n.has(t)||(n.add(t),t.then(r,r))})}function il(e,t){var n=t.deletions;if(n!==null)for(var r=0;r<n.length;r++){var a=n[r],o=e,s=t,c=s;a:for(;c!==null;){switch(c.tag){case 27:if(Vd(c.type)){Zc=c.stateNode,Qc=!1;break a}break;case 5:Zc=c.stateNode,Qc=!1;break a;case 3:case 4:Zc=c.stateNode.containerInfo,Qc=!0;break a}c=c.return}if(Zc===null)throw Error(i(160));el(o,s,a),Zc=null,Qc=!1,o=a.alternate,o!==null&&(o.return=null),a.return=null}if(t.subtreeFlags&13878)for(t=t.child;t!==null;)ol(t,e),t=t.sibling}var al=null;function ol(e,t){var n=e.alternate,r=e.flags;switch(e.tag){case 0:case 11:case 14:case 15:il(t,e),sl(e),r&4&&(jc(3,e,e.return),Ac(3,e),jc(5,e,e.return));break;case 1:il(t,e),sl(e),r&512&&(Wc||n===null||Fc(n,n.return)),r&64&&Uc&&(e=e.updateQueue,e!==null&&(r=e.callbacks,r!==null&&(n=e.shared.hiddenCallbacks,e.shared.hiddenCallbacks=n===null?r:n.concat(r))));break;case 26:var a=al;if(il(t,e),sl(e),r&512&&(Wc||n===null||Fc(n,n.return)),r&4){var o=n===null?null:n.memoizedState;if(r=e.memoizedState,n===null){if(r===null){if(e.stateNode===null){a:{r=e.type,n=e.memoizedProps,a=a.ownerDocument||a;b:switch(r){case`title`:o=a.getElementsByTagName(`title`)[0],(!o||o[tt]||o[Je]||o.namespaceURI===`http://www.w3.org/2000/svg`||o.hasAttribute(`itemprop`))&&(o=a.createElement(r),a.head.insertBefore(o,a.querySelector(`head > title`))),Y(o,r,n),o[Je]=e,st(o),r=o;break a;case`link`:var s=Df(`link`,`href`,a).get(r+(n.href||``));if(s){for(var c=0;c<s.length;c++)if(o=s[c],o.getAttribute(`href`)===(n.href==null||n.href===``?null:n.href)&&o.getAttribute(`rel`)===(n.rel==null?null:n.rel)&&o.getAttribute(`title`)===(n.title==null?null:n.title)&&o.getAttribute(`crossorigin`)===(n.crossOrigin==null?null:n.crossOrigin)){s.splice(c,1);break b}}o=a.createElement(r),Y(o,r,n),a.head.appendChild(o);break;case`meta`:if(s=Df(`meta`,`content`,a).get(r+(n.content||``))){for(c=0;c<s.length;c++)if(o=s[c],o.getAttribute(`content`)===(n.content==null?null:``+n.content)&&o.getAttribute(`name`)===(n.name==null?null:n.name)&&o.getAttribute(`property`)===(n.property==null?null:n.property)&&o.getAttribute(`http-equiv`)===(n.httpEquiv==null?null:n.httpEquiv)&&o.getAttribute(`charset`)===(n.charSet==null?null:n.charSet)){s.splice(c,1);break b}}o=a.createElement(r),Y(o,r,n),a.head.appendChild(o);break;default:throw Error(i(468,r))}o[Je]=e,st(o),r=o}e.stateNode=r}else Of(a,e.type,e.stateNode)}else e.stateNode=Sf(a,r,e.memoizedProps)}else o===r?r===null&&e.stateNode!==null&&Lc(e,e.memoizedProps,n.memoizedProps):(o===null?n.stateNode!==null&&(n=n.stateNode,n.parentNode.removeChild(n)):o.count--,r===null?Of(a,e.type,e.stateNode):Sf(a,r,e.memoizedProps))}break;case 27:il(t,e),sl(e),r&512&&(Wc||n===null||Fc(n,n.return)),n!==null&&r&4&&Lc(e,e.memoizedProps,n.memoizedProps);break;case 5:if(il(t,e),sl(e),r&512&&(Wc||n===null||Fc(n,n.return)),e.flags&32){a=e.stateNode;try{zt(a,``)}catch(t){Fu(e,e.return,t)}}r&4&&e.stateNode!=null&&(a=e.memoizedProps,Lc(e,a,n===null?a:n.memoizedProps)),r&1024&&(Gc=!0);break;case 6:if(il(t,e),sl(e),r&4){if(e.stateNode===null)throw Error(i(162));r=e.memoizedProps,n=e.stateNode;try{n.nodeValue=r}catch(t){Fu(e,e.return,t)}}break;case 3:if(Ef=null,a=al,al=tf(t.containerInfo),il(t,e),al=a,sl(e),r&4&&n!==null&&n.memoizedState.isDehydrated)try{yp(t.containerInfo)}catch(t){Fu(e,e.return,t)}Gc&&(Gc=!1,cl(e));break;case 4:r=al,al=tf(e.stateNode.containerInfo),il(t,e),sl(e),al=r;break;case 12:il(t,e),sl(e);break;case 13:il(t,e),sl(e),e.child.flags&8192&&e.memoizedState!==null!=(n!==null&&n.memoizedState!==null)&&(Gl=ge()),r&4&&(r=e.updateQueue,r!==null&&(e.updateQueue=null,rl(e,r)));break;case 22:a=e.memoizedState!==null;var l=n!==null&&n.memoizedState!==null,u=Uc,d=Wc;if(Uc=u||a,Wc=d||l,il(t,e),Wc=d,Uc=u,sl(e),r&8192)a:for(t=e.stateNode,t._visibility=a?t._visibility&-2:t._visibility|1,a&&(n===null||l||Uc||Wc||ul(e)),n=null,t=e;;){if(t.tag===5||t.tag===26){if(n===null){l=n=t;try{if(o=l.stateNode,a)s=o.style,typeof s.setProperty==`function`?s.setProperty(`display`,`none`,`important`):s.display=`none`;else{c=l.stateNode;var f=l.memoizedProps.style,p=f!=null&&f.hasOwnProperty(`display`)?f.display:null;c.style.display=p==null||typeof p==`boolean`?``:(``+p).trim()}}catch(e){Fu(l,l.return,e)}}}else if(t.tag===6){if(n===null){l=t;try{l.stateNode.nodeValue=a?``:l.memoizedProps}catch(e){Fu(l,l.return,e)}}}else if((t.tag!==22&&t.tag!==23||t.memoizedState===null||t===e)&&t.child!==null){t.child.return=t,t=t.child;continue}if(t===e)break a;for(;t.sibling===null;){if(t.return===null||t.return===e)break a;n===t&&(n=null),t=t.return}n===t&&(n=null),t.sibling.return=t.return,t=t.sibling}r&4&&(r=e.updateQueue,r!==null&&(n=r.retryQueue,n!==null&&(r.retryQueue=null,rl(e,n))));break;case 19:il(t,e),sl(e),r&4&&(r=e.updateQueue,r!==null&&(e.updateQueue=null,rl(e,r)));break;case 30:break;case 21:break;default:il(t,e),sl(e)}}function sl(e){var t=e.flags;if(t&2){try{for(var n,r=e.return;r!==null;){if(Rc(r)){n=r;break}r=r.return}if(n==null)throw Error(i(160));switch(n.tag){case 27:var a=n.stateNode;Vc(e,zc(e),a);break;case 5:var o=n.stateNode;n.flags&32&&(zt(o,``),n.flags&=-33),Vc(e,zc(e),o);break;case 3:case 4:var s=n.stateNode.containerInfo;Bc(e,zc(e),s);break;default:throw Error(i(161))}}catch(t){Fu(e,e.return,t)}e.flags&=-3}t&4096&&(e.flags&=-4097)}function cl(e){if(e.subtreeFlags&1024)for(e=e.child;e!==null;){var t=e;cl(t),t.tag===5&&t.flags&1024&&t.stateNode.reset(),e=e.sibling}}function ll(e,t){if(t.subtreeFlags&8772)for(t=t.child;t!==null;)Yc(e,t.alternate,t),t=t.sibling}function ul(e){for(e=e.child;e!==null;){var t=e;switch(t.tag){case 0:case 11:case 14:case 15:jc(4,t,t.return),ul(t);break;case 1:Fc(t,t.return);var n=t.stateNode;typeof n.componentWillUnmount==`function`&&Nc(t,t.return,n),ul(t);break;case 27:Qd(t.stateNode);case 26:case 5:Fc(t,t.return),ul(t);break;case 22:t.memoizedState===null&&ul(t);break;case 30:ul(t);break;default:ul(t)}e=e.sibling}}function dl(e,t,n){for(n&&=!!(t.subtreeFlags&8772),t=t.child;t!==null;){var r=t.alternate,i=e,a=t,o=a.flags;switch(a.tag){case 0:case 11:case 15:dl(i,a,n),Ac(4,a);break;case 1:if(dl(i,a,n),r=a,i=r.stateNode,typeof i.componentDidMount==`function`)try{i.componentDidMount()}catch(e){Fu(r,r.return,e)}if(r=a,i=r.updateQueue,i!==null){var s=r.stateNode;try{var c=i.shared.hiddenCallbacks;if(c!==null)for(i.shared.hiddenCallbacks=null,i=0;i<c.length;i++)Ma(c[i],s)}catch(e){Fu(r,r.return,e)}}n&&o&64&&Mc(a),Pc(a,a.return);break;case 27:Hc(a);case 26:case 5:dl(i,a,n),n&&r===null&&o&4&&Ic(a),Pc(a,a.return);break;case 12:dl(i,a,n);break;case 13:dl(i,a,n),n&&o&4&&tl(i,a);break;case 22:a.memoizedState===null&&dl(i,a,n),Pc(a,a.return);break;case 30:break;default:dl(i,a,n)}t=t.sibling}}function fl(e,t){var n=null;e!==null&&e.memoizedState!==null&&e.memoizedState.cachePool!==null&&(n=e.memoizedState.cachePool.pool),e=null,t.memoizedState!==null&&t.memoizedState.cachePool!==null&&(e=t.memoizedState.cachePool.pool),e!==n&&(e!=null&&e.refCount++,n!=null&&ea(n))}function pl(e,t){e=null,t.alternate!==null&&(e=t.alternate.memoizedState.cache),t=t.memoizedState.cache,t!==e&&(t.refCount++,e!=null&&ea(e))}function ml(e,t,n,r){if(t.subtreeFlags&10256)for(t=t.child;t!==null;)hl(e,t,n,r),t=t.sibling}function hl(e,t,n,r){var i=t.flags;switch(t.tag){case 0:case 11:case 15:ml(e,t,n,r),i&2048&&Ac(9,t);break;case 1:ml(e,t,n,r);break;case 3:ml(e,t,n,r),i&2048&&(e=null,t.alternate!==null&&(e=t.alternate.memoizedState.cache),t=t.memoizedState.cache,t!==e&&(t.refCount++,e!=null&&ea(e)));break;case 12:if(i&2048){ml(e,t,n,r),e=t.stateNode;try{var a=t.memoizedProps,o=a.id,s=a.onPostCommit;typeof s==`function`&&s(o,t.alternate===null?`mount`:`update`,e.passiveEffectDuration,-0)}catch(e){Fu(t,t.return,e)}}else ml(e,t,n,r);break;case 13:ml(e,t,n,r);break;case 23:break;case 22:a=t.stateNode,o=t.alternate,t.memoizedState===null?a._visibility&2?ml(e,t,n,r):(a._visibility|=2,gl(e,t,n,r,!!(t.subtreeFlags&10256))):a._visibility&2?ml(e,t,n,r):_l(e,t),i&2048&&fl(o,t);break;case 24:ml(e,t,n,r),i&2048&&pl(t.alternate,t);break;default:ml(e,t,n,r)}}function gl(e,t,n,r,i){for(i&&=!!(t.subtreeFlags&10256),t=t.child;t!==null;){var a=e,o=t,s=n,c=r,l=o.flags;switch(o.tag){case 0:case 11:case 15:gl(a,o,s,c,i),Ac(8,o);break;case 23:break;case 22:var u=o.stateNode;o.memoizedState===null?(u._visibility|=2,gl(a,o,s,c,i)):u._visibility&2?gl(a,o,s,c,i):_l(a,o),i&&l&2048&&fl(o.alternate,o);break;case 24:gl(a,o,s,c,i),i&&l&2048&&pl(o.alternate,o);break;default:gl(a,o,s,c,i)}t=t.sibling}}function _l(e,t){if(t.subtreeFlags&10256)for(t=t.child;t!==null;){var n=e,r=t,i=r.flags;switch(r.tag){case 22:_l(n,r),i&2048&&fl(r.alternate,r);break;case 24:_l(n,r),i&2048&&pl(r.alternate,r);break;default:_l(n,r)}t=t.sibling}}var vl=8192;function yl(e){if(e.subtreeFlags&vl)for(e=e.child;e!==null;)bl(e),e=e.sibling}function bl(e){switch(e.tag){case 26:yl(e),e.flags&vl&&e.memoizedState!==null&&Nf(al,e.memoizedState,e.memoizedProps);break;case 5:yl(e);break;case 3:case 4:var t=al;al=tf(e.stateNode.containerInfo),yl(e),al=t;break;case 22:e.memoizedState===null&&(t=e.alternate,t!==null&&t.memoizedState!==null?(t=vl,vl=16777216,yl(e),vl=t):yl(e));break;default:yl(e)}}function xl(e){var t=e.alternate;if(t!==null&&(e=t.child,e!==null)){t.child=null;do t=e.sibling,e.sibling=null,e=t;while(e!==null)}}function Sl(e){var t=e.deletions;if(e.flags&16){if(t!==null)for(var n=0;n<t.length;n++){var r=t[n];qc=r,Tl(r,e)}xl(e)}if(e.subtreeFlags&10256)for(e=e.child;e!==null;)Cl(e),e=e.sibling}function Cl(e){switch(e.tag){case 0:case 11:case 15:Sl(e),e.flags&2048&&jc(9,e,e.return);break;case 3:Sl(e);break;case 12:Sl(e);break;case 22:var t=e.stateNode;e.memoizedState!==null&&t._visibility&2&&(e.return===null||e.return.tag!==13)?(t._visibility&=-3,wl(e)):Sl(e);break;default:Sl(e)}}function wl(e){var t=e.deletions;if(e.flags&16){if(t!==null)for(var n=0;n<t.length;n++){var r=t[n];qc=r,Tl(r,e)}xl(e)}for(e=e.child;e!==null;){switch(t=e,t.tag){case 0:case 11:case 15:jc(8,t,t.return),wl(t);break;case 22:n=t.stateNode,n._visibility&2&&(n._visibility&=-3,wl(t));break;default:wl(t)}e=e.sibling}}function Tl(e,t){for(;qc!==null;){var n=qc;switch(n.tag){case 0:case 11:case 15:jc(8,n,t);break;case 23:case 22:if(n.memoizedState!==null&&n.memoizedState.cachePool!==null){var r=n.memoizedState.cachePool.pool;r!=null&&r.refCount++}break;case 24:ea(n.memoizedState.cache)}if(r=n.child,r!==null)r.return=n,qc=r;else a:for(n=e;qc!==null;){r=qc;var i=r.sibling,a=r.return;if(Xc(r),r===n){qc=null;break a}if(i!==null){i.return=a,qc=i;break a}qc=a}}}var El={getCacheForType:function(e){var t=Ki(Qi),n=t.data.get(e);return n===void 0&&(n=e(),t.data.set(e,n)),n}},Dl=typeof WeakMap==`function`?WeakMap:Map,Ol=0,kl=null,K=null,q=0,Al=0,jl=null,Ml=!1,Nl=!1,Pl=!1,Fl=0,Il=0,Ll=0,Rl=0,zl=0,Bl=0,Vl=0,Hl=null,Ul=null,Wl=!1,Gl=0,Kl=1/0,ql=null,Jl=null,Yl=0,Xl=null,Zl=null,Ql=0,$l=0,eu=null,tu=null,nu=0,ru=null;function iu(){if(Ol&2&&q!==0)return q&-q;if(N.T!==null){var e=ra;return e===0?nd():e}return Ge()}function au(){Bl===0&&(Bl=!(q&536870912)||Ti?Ie():536870912);var e=Es.current;return e!==null&&(e.flags|=32),Bl}function ou(e,t,n){(e===kl&&(Al===2||Al===9)||e.cancelPendingCommit!==null)&&(pu(e,0),uu(e,q,Bl,!1)),ze(e,n),Ol&2&&e===kl||(e===kl&&(!(Ol&2)&&(Rl|=n),Il===4&&uu(e,q,Bl,!1)),Ju(e))}function su(e,t,n){if(Ol&6)throw Error(i(327));var r=!n&&!(t&124)&&(t&e.expiredLanes)===0||Pe(e,t),a=r?bu(e,t):vu(e,t,!0),o=r;do{if(a===0){Nl&&!r&&uu(e,t,0,!1);break}if(n=e.current.alternate,o&&!lu(n))a=vu(e,t,!1),o=!1;else{if(a===2){if(o=t,e.errorRecoveryDisabledLanes&o)var s=0;else s=e.pendingLanes&-536870913,s=s===0?s&536870912?536870912:0:s;if(s!==0){t=s;a:{var c=e;a=Hl;var l=c.current.memoizedState.isDehydrated;if(l&&(pu(c,s).flags|=256),s=vu(c,s,!1),s!==2){if(Pl&&!l){c.errorRecoveryDisabledLanes|=o,Rl|=o,a=4;break a}o=Ul,Ul=a,o!==null&&(Ul===null?Ul=o:Ul.push.apply(Ul,o))}a=s}if(o=!1,a!==2)continue}}if(a===1){pu(e,0),uu(e,t,0,!0);break}a:{switch(r=e,o=a,o){case 0:case 1:throw Error(i(345));case 4:if((t&4194048)!==t)break;case 6:uu(r,t,Bl,!Ml);break a;case 2:Ul=null;break;case 3:case 5:break;default:throw Error(i(329))}if((t&62914560)===t&&(a=Gl+300-ge(),10<a)){if(uu(r,t,Bl,!Ml),Ne(r,0,!0)!==0)break a;r.timeoutHandle=Id(cu.bind(null,r,n,Ul,ql,Wl,t,Bl,Rl,Vl,Ml,o,2,-0,0),a);break a}cu(r,n,Ul,ql,Wl,t,Bl,Rl,Vl,Ml,o,0,-0,0)}break}}while(1);Ju(e)}function cu(e,t,n,r,i,a,o,s,c,l,u,d,f,p){e.timeoutHandle=-1,d=t.subtreeFlags,(d&8192||(d&16785408)==16785408)&&(jf={stylesheets:null,count:0,unsuspend:Mf},bl(t),d=Pf(),d!==null)?(e.cancelPendingCommit=d(Du.bind(null,e,t,a,n,r,i,o,s,c,u,1,f,p)),uu(e,a,o,!l)):Du(e,t,a,n,r,i,o,s,c)}function lu(e){for(var t=e;;){var n=t.tag;if((n===0||n===11||n===15)&&t.flags&16384&&(n=t.updateQueue,n!==null&&(n=n.stores,n!==null)))for(var r=0;r<n.length;r++){var i=n[r],a=i.getSnapshot;i=i.value;try{if(!hr(a(),i))return!1}catch{return!1}}if(n=t.child,t.subtreeFlags&16384&&n!==null)n.return=t,t=n;else{if(t===e)break;for(;t.sibling===null;){if(t.return===null||t.return===e)return!0;t=t.return}t.sibling.return=t.return,t=t.sibling}}return!0}function uu(e,t,n,r){t&=~zl,t&=~Rl,e.suspendedLanes|=t,e.pingedLanes&=~t,r&&(e.warmLanes|=t),r=e.expirationTimes;for(var i=t;0<i;){var a=31-Ee(i),o=1<<a;r[a]=-1,i&=~o}n!==0&&Ve(e,n,t)}function du(){return Ol&6?!0:(Yu(0,!1),!1)}function fu(){if(K!==null){if(Al===0)var e=K.return;else e=K,Ri=Li=null,ro(e),_s=null,vs=0,e=K;for(;e!==null;)kc(e.alternate,e),e=e.return;K=null}}function pu(e,t){var n=e.timeoutHandle;n!==-1&&(e.timeoutHandle=-1,Ld(n)),n=e.cancelPendingCommit,n!==null&&(e.cancelPendingCommit=null,n()),fu(),kl=e,K=n=ii(e.current,null),q=t,Al=0,jl=null,Ml=!1,Nl=Pe(e,t),Pl=!1,Vl=Bl=zl=Rl=Ll=Il=0,Ul=Hl=null,Wl=!1,t&8&&(t|=t&32);var r=e.entangledLanes;if(r!==0)for(e=e.entanglements,r&=t;0<r;){var i=31-Ee(r),a=1<<i;t|=e[i],r&=~a}return Fl=t,Jr(),n}function mu(e,t){G=null,N.H=ps,t===pa||t===ha?(t=xa(),Al=3):t===ma?(t=xa(),Al=4):Al=t===Ys?8:typeof t==`object`&&t&&typeof t.then==`function`?6:1,jl=t,K===null&&(Il=1,Us(e,Wr(t,e.current)))}function hu(){var e=N.H;return N.H=ps,e===null?ps:e}function gu(){var e=N.A;return N.A=El,e}function _u(){Il=4,Ml||(q&4194048)!==q&&Es.current!==null||(Nl=!0),!(Ll&134217727)&&!(Rl&134217727)||kl===null||uu(kl,q,Bl,!1)}function vu(e,t,n){var r=Ol;Ol|=2;var i=hu(),a=gu();(kl!==e||q!==t)&&(ql=null,pu(e,t)),t=!1;var o=Il;a:do try{if(Al!==0&&K!==null){var s=K,c=jl;switch(Al){case 8:fu(),o=6;break a;case 3:case 2:case 9:case 6:Es.current===null&&(t=!0);var l=Al;if(Al=0,jl=null,wu(e,s,c,l),n&&Nl){o=0;break a}break;default:l=Al,Al=0,jl=null,wu(e,s,c,l)}}yu(),o=Il;break}catch(t){mu(e,t)}while(1);return t&&e.shellSuspendCounter++,Ri=Li=null,Ol=r,N.H=i,N.A=a,K===null&&(kl=null,q=0,Jr()),o}function yu(){for(;K!==null;)Su(K)}function bu(e,t){var n=Ol;Ol|=2;var r=hu(),a=gu();kl!==e||q!==t?(ql=null,Kl=ge()+500,pu(e,t)):Nl=Pe(e,t);a:do try{if(Al!==0&&K!==null){t=K;var o=jl;b:switch(Al){case 1:Al=0,jl=null,wu(e,t,o,1);break;case 2:case 9:if(_a(o)){Al=0,jl=null,Cu(t);break}t=function(){Al!==2&&Al!==9||kl!==e||(Al=7),Ju(e)},o.then(t,t);break a;case 3:Al=7;break a;case 4:Al=5;break a;case 7:_a(o)?(Al=0,jl=null,Cu(t)):(Al=0,jl=null,wu(e,t,o,7));break;case 5:var s=null;switch(K.tag){case 26:s=K.memoizedState;case 5:case 27:var c=K;if(!s||Af(s)){Al=0,jl=null;var l=c.sibling;if(l!==null)K=l;else{var u=c.return;u===null?K=null:(K=u,Tu(u))}break b}}Al=0,jl=null,wu(e,t,o,5);break;case 6:Al=0,jl=null,wu(e,t,o,6);break;case 8:fu(),Il=6;break a;default:throw Error(i(462))}}xu();break}catch(t){mu(e,t)}while(1);return Ri=Li=null,N.H=r,N.A=a,Ol=n,K===null?(kl=null,q=0,Jr(),Il):0}function xu(){for(;K!==null&&!me();)Su(K)}function Su(e){var t=xc(e.alternate,e,Fl);e.memoizedProps=e.pendingProps,t===null?Tu(e):K=t}function Cu(e){var t=e,n=t.alternate;switch(t.tag){case 15:case 0:t=ac(n,t,t.pendingProps,t.type,void 0,q);break;case 11:t=ac(n,t,t.pendingProps,t.type.render,t.ref,q);break;case 5:ro(t);default:kc(n,t),t=K=ai(t,Fl),t=xc(n,t,Fl)}e.memoizedProps=e.pendingProps,t===null?Tu(e):K=t}function wu(e,t,n,r){Ri=Li=null,ro(t),_s=null,vs=0;var i=t.return;try{if(Js(e,i,t,n,q)){Il=1,Us(e,Wr(n,e.current)),K=null;return}}catch(t){if(i!==null)throw K=i,t;Il=1,Us(e,Wr(n,e.current)),K=null;return}t.flags&32768?(Ti||r===1?e=!0:Nl||q&536870912?e=!1:(Ml=e=!0,(r===2||r===9||r===3||r===6)&&(r=Es.current,r!==null&&r.tag===13&&(r.flags|=16384))),Eu(t,e)):Tu(t)}function Tu(e){var t=e;do{if(t.flags&32768){Eu(t,Ml);return}e=t.return;var n=Dc(t.alternate,t,Fl);if(n!==null){K=n;return}if(t=t.sibling,t!==null){K=t;return}K=t=e}while(t!==null);Il===0&&(Il=5)}function Eu(e,t){do{var n=Oc(e.alternate,e);if(n!==null){n.flags&=32767,K=n;return}if(n=e.return,n!==null&&(n.flags|=32768,n.subtreeFlags=0,n.deletions=null),!t&&(e=e.sibling,e!==null)){K=e;return}K=e=n}while(e!==null);Il=6,K=null}function Du(e,t,n,r,a,o,s,c,l){e.cancelPendingCommit=null;do Mu();while(Yl!==0);if(Ol&6)throw Error(i(327));if(t!==null){if(t===e.current)throw Error(i(177));if(o=t.lanes|t.childLanes,o|=qr,Be(e,n,o,s,c,l),e===kl&&(K=kl=null,q=0),Zl=t,Xl=e,Ql=n,$l=o,eu=a,tu=r,t.subtreeFlags&10256||t.flags&10256?(e.callbackNode=null,e.callbackPriority=0,Vu(ye,function(){return Nu(!0),null})):(e.callbackNode=null,e.callbackPriority=0),r=!!(t.flags&13878),t.subtreeFlags&13878||r){r=N.T,N.T=null,a=P.p,P.p=2,s=Ol,Ol|=4;try{Jc(e,t,n)}finally{Ol=s,P.p=a,N.T=r}}Yl=1,Ou(),ku(),Au()}}function Ou(){if(Yl===1){Yl=0;var e=Xl,t=Zl,n=!!(t.flags&13878);if(t.subtreeFlags&13878||n){n=N.T,N.T=null;var r=P.p;P.p=2;var i=Ol;Ol|=4;try{ol(t,e);var a=kd,o=br(e.containerInfo),s=a.focusedElem,c=a.selectionRange;if(o!==s&&s&&s.ownerDocument&&yr(s.ownerDocument.documentElement,s)){if(c!==null&&xr(s)){var l=c.start,u=c.end;if(u===void 0&&(u=l),`selectionStart`in s)s.selectionStart=l,s.selectionEnd=Math.min(u,s.value.length);else{var d=s.ownerDocument||document,f=d&&d.defaultView||window;if(f.getSelection){var p=f.getSelection(),m=s.textContent.length,h=Math.min(c.start,m),g=c.end===void 0?h:Math.min(c.end,m);!p.extend&&h>g&&(o=g,g=h,h=o);var _=vr(s,h),v=vr(s,g);if(_&&v&&(p.rangeCount!==1||p.anchorNode!==_.node||p.anchorOffset!==_.offset||p.focusNode!==v.node||p.focusOffset!==v.offset)){var y=d.createRange();y.setStart(_.node,_.offset),p.removeAllRanges(),h>g?(p.addRange(y),p.extend(v.node,v.offset)):(y.setEnd(v.node,v.offset),p.addRange(y))}}}}for(d=[],p=s;p=p.parentNode;)p.nodeType===1&&d.push({element:p,left:p.scrollLeft,top:p.scrollTop});for(typeof s.focus==`function`&&s.focus(),s=0;s<d.length;s++){var b=d[s];b.element.scrollLeft=b.left,b.element.scrollTop=b.top}}qf=!!Od,kd=Od=null}finally{Ol=i,P.p=r,N.T=n}}e.current=t,Yl=2}}function ku(){if(Yl===2){Yl=0;var e=Xl,t=Zl,n=!!(t.flags&8772);if(t.subtreeFlags&8772||n){n=N.T,N.T=null;var r=P.p;P.p=2;var i=Ol;Ol|=4;try{Yc(e,t.alternate,t)}finally{Ol=i,P.p=r,N.T=n}}Yl=3}}function Au(){if(Yl===4||Yl===3){Yl=0,he();var e=Xl,t=Zl,n=Ql,r=tu;t.subtreeFlags&10256||t.flags&10256?Yl=5:(Yl=0,Zl=Xl=null,ju(e,e.pendingLanes));var i=e.pendingLanes;if(i===0&&(Jl=null),We(n),t=t.stateNode,we&&typeof we.onCommitFiberRoot==`function`)try{we.onCommitFiberRoot(H,t,void 0,(t.current.flags&128)==128)}catch{}if(r!==null){t=N.T,i=P.p,P.p=2,N.T=null;try{for(var a=e.onRecoverableError,o=0;o<r.length;o++){var s=r[o];a(s.value,{componentStack:s.stack})}}finally{N.T=t,P.p=i}}Ql&3&&Mu(),Ju(e),i=e.pendingLanes,n&4194090&&i&42?e===ru?nu++:(nu=0,ru=e):nu=0,Yu(0,!1)}}function ju(e,t){(e.pooledCacheLanes&=t)===0&&(t=e.pooledCache,t!=null&&(e.pooledCache=null,ea(t)))}function Mu(e){return Ou(),ku(),Au(),Nu(e)}function Nu(){if(Yl!==5)return!1;var e=Xl,t=$l;$l=0;var n=We(Ql),r=N.T,a=P.p;try{P.p=32>n?32:n,N.T=null,n=eu,eu=null;var o=Xl,s=Ql;if(Yl=0,Zl=Xl=null,Ql=0,Ol&6)throw Error(i(331));var c=Ol;if(Ol|=4,Cl(o.current),hl(o,o.current,s,n),Ol=c,Yu(0,!1),we&&typeof we.onPostCommitFiberRoot==`function`)try{we.onPostCommitFiberRoot(H,o)}catch{}return!0}finally{P.p=a,N.T=r,ju(e,t)}}function Pu(e,t,n){t=Wr(n,t),t=Gs(e.stateNode,t,2),e=Ea(e,t,2),e!==null&&(ze(e,2),Ju(e))}function Fu(e,t,n){if(e.tag===3)Pu(e,e,n);else for(;t!==null;){if(t.tag===3){Pu(t,e,n);break}if(t.tag===1){var r=t.stateNode;if(typeof t.type.getDerivedStateFromError==`function`||typeof r.componentDidCatch==`function`&&(Jl===null||!Jl.has(r))){e=Wr(n,e),n=Ks(2),r=Ea(t,n,2),r!==null&&(qs(n,r,t,e),ze(r,2),Ju(r));break}}t=t.return}}function Iu(e,t,n){var r=e.pingCache;if(r===null){r=e.pingCache=new Dl;var i=new Set;r.set(t,i)}else i=r.get(t),i===void 0&&(i=new Set,r.set(t,i));i.has(n)||(Pl=!0,i.add(n),e=Lu.bind(null,e,t,n),t.then(e,e))}function Lu(e,t,n){var r=e.pingCache;r!==null&&r.delete(t),e.pingedLanes|=e.suspendedLanes&n,e.warmLanes&=~n,kl===e&&(q&n)===n&&(Il===4||Il===3&&(q&62914560)===q&&300>ge()-Gl?!(Ol&2)&&pu(e,0):zl|=n,Vl===q&&(Vl=0)),Ju(e)}function Ru(e,t){t===0&&(t=Le()),e=Zr(e,t),e!==null&&(ze(e,t),Ju(e))}function zu(e){var t=e.memoizedState,n=0;t!==null&&(n=t.retryLane),Ru(e,n)}function Bu(e,t){var n=0;switch(e.tag){case 13:var r=e.stateNode,a=e.memoizedState;a!==null&&(n=a.retryLane);break;case 19:r=e.stateNode;break;case 22:r=e.stateNode._retryCache;break;default:throw Error(i(314))}r!==null&&r.delete(t),Ru(e,n)}function Vu(e,t){return pe(e,t)}var Hu=null,Uu=null,Wu=!1,Gu=!1,Ku=!1,qu=0;function Ju(e){e!==Uu&&e.next===null&&(Uu===null?Hu=Uu=e:Uu=Uu.next=e),Gu=!0,Wu||(Wu=!0,td())}function Yu(e,t){if(!Ku&&Gu){Ku=!0;do for(var n=!1,r=Hu;r!==null;){if(!t){if(e!==0){var i=r.pendingLanes;if(i===0)var a=0;else{var o=r.suspendedLanes,s=r.pingedLanes;a=(1<<31-Ee(42|e)+1)-1,a&=i&~(o&~s),a=a&201326741?a&201326741|1:a?a|2:0}a!==0&&(n=!0,ed(r,a))}else a=q,a=Ne(r,r===kl?a:0,r.cancelPendingCommit!==null||r.timeoutHandle!==-1),!(a&3)||Pe(r,a)||(n=!0,ed(r,a))}r=r.next}while(n);Ku=!1}}function Xu(){Zu()}function Zu(){Gu=Wu=!1;var e=0;qu!==0&&(Fd()&&(e=qu),qu=0);for(var t=ge(),n=null,r=Hu;r!==null;){var i=r.next,a=Qu(r,t);a===0?(r.next=null,n===null?Hu=i:n.next=i,i===null&&(Uu=n)):(n=r,(e!==0||a&3)&&(Gu=!0)),r=i}Yu(e,!1)}function Qu(e,t){for(var n=e.suspendedLanes,r=e.pingedLanes,i=e.expirationTimes,a=e.pendingLanes&-62914561;0<a;){var o=31-Ee(a),s=1<<o,c=i[o];c===-1?((s&n)===0||(s&r)!==0)&&(i[o]=Fe(s,t)):c<=t&&(e.expiredLanes|=s),a&=~s}if(t=kl,n=q,n=Ne(e,e===t?n:0,e.cancelPendingCommit!==null||e.timeoutHandle!==-1),r=e.callbackNode,n===0||e===t&&(Al===2||Al===9)||e.cancelPendingCommit!==null)return r!==null&&r!==null&&B(r),e.callbackNode=null,e.callbackPriority=0;if(!(n&3)||Pe(e,n)){if(t=n&-n,t===e.callbackPriority)return t;switch(r!==null&&B(r),We(n)){case 2:case 8:n=V;break;case 32:n=ye;break;case 268435456:n=xe;break;default:n=ye}return r=$u.bind(null,e),n=pe(n,r),e.callbackPriority=t,e.callbackNode=n,t}return r!==null&&r!==null&&B(r),e.callbackPriority=2,e.callbackNode=null,2}function $u(e,t){if(Yl!==0&&Yl!==5)return e.callbackNode=null,e.callbackPriority=0,null;var n=e.callbackNode;if(Mu(!0)&&e.callbackNode!==n)return null;var r=q;return r=Ne(e,e===kl?r:0,e.cancelPendingCommit!==null||e.timeoutHandle!==-1),r===0?null:(su(e,r,t),Qu(e,ge()),e.callbackNode!=null&&e.callbackNode===n?$u.bind(null,e):null)}function ed(e,t){if(Mu())return null;su(e,t,!0)}function td(){zd(function(){Ol&6?pe(ve,Xu):Zu()})}function nd(){return qu===0&&(qu=Ie()),qu}function rd(e){return e==null||typeof e==`symbol`||typeof e==`boolean`?null:typeof e==`function`?e:Kt(``+e)}function id(e,t){var n=t.ownerDocument.createElement(`input`);return n.name=t.name,n.value=t.value,e.id&&n.setAttribute(`form`,e.id),t.parentNode.insertBefore(n,t),e=new FormData(e),n.parentNode.removeChild(n),e}function ad(e,t,n,r,i){if(t===`submit`&&n&&n.stateNode===i){var a=rd((i[Ye]||null).action),o=r.submitter;o&&(t=(t=o[Ye]||null)?rd(t.formAction):o.getAttribute(`formAction`),t!==null&&(a=t,o=null));var s=new mn(`action`,`action`,null,r,i);e.push({event:s,listeners:[{instance:null,listener:function(){if(r.defaultPrevented){if(qu!==0){var e=o?id(i,o):new FormData(i);$o(n,{pending:!0,data:e,method:i.method,action:a},null,e)}}else typeof a==`function`&&(s.preventDefault(),e=o?id(i,o):new FormData(i),$o(n,{pending:!0,data:e,method:i.method,action:a},a,e))},currentTarget:i}]})}}for(var od=0;od<Vr.length;od++){var sd=Vr[od];Hr(sd.toLowerCase(),`on`+(sd[0].toUpperCase()+sd.slice(1)))}Hr(Nr,`onAnimationEnd`),Hr(Pr,`onAnimationIteration`),Hr(Fr,`onAnimationStart`),Hr(`dblclick`,`onDoubleClick`),Hr(`focusin`,`onFocus`),Hr(`focusout`,`onBlur`),Hr(Ir,`onTransitionRun`),Hr(Lr,`onTransitionStart`),Hr(Rr,`onTransitionCancel`),Hr(zr,`onTransitionEnd`),dt(`onMouseEnter`,[`mouseout`,`mouseover`]),dt(`onMouseLeave`,[`mouseout`,`mouseover`]),dt(`onPointerEnter`,[`pointerout`,`pointerover`]),dt(`onPointerLeave`,[`pointerout`,`pointerover`]),ut(`onChange`,`change click focusin focusout input keydown keyup selectionchange`.split(` `)),ut(`onSelect`,`focusout contextmenu dragend focusin keydown keyup mousedown mouseup selectionchange`.split(` `)),ut(`onBeforeInput`,[`compositionend`,`keypress`,`textInput`,`paste`]),ut(`onCompositionEnd`,`compositionend focusout keydown keypress keyup mousedown`.split(` `)),ut(`onCompositionStart`,`compositionstart focusout keydown keypress keyup mousedown`.split(` `)),ut(`onCompositionUpdate`,`compositionupdate focusout keydown keypress keyup mousedown`.split(` `));var cd=`abort canplay canplaythrough durationchange emptied encrypted ended error loadeddata loadedmetadata loadstart pause play playing progress ratechange resize seeked seeking stalled suspend timeupdate volumechange waiting`.split(` `),ld=new Set(`beforetoggle cancel close invalid load scroll scrollend toggle`.split(` `).concat(cd));function ud(e,t){t=!!(t&4);for(var n=0;n<e.length;n++){var r=e[n],i=r.event;r=r.listeners;a:{var a=void 0;if(t)for(var o=r.length-1;0<=o;o--){var s=r[o],c=s.instance,l=s.currentTarget;if(s=s.listener,c!==a&&i.isPropagationStopped())break a;a=s,i.currentTarget=l;try{a(i)}catch(e){zs(e)}i.currentTarget=null,a=c}else for(o=0;o<r.length;o++){if(s=r[o],c=s.instance,l=s.currentTarget,s=s.listener,c!==a&&i.isPropagationStopped())break a;a=s,i.currentTarget=l;try{a(i)}catch(e){zs(e)}i.currentTarget=null,a=c}}}}function J(e,t){var n=t[Ze];n===void 0&&(n=t[Ze]=new Set);var r=e+`__bubble`;n.has(r)||(md(t,e,2,!1),n.add(r))}function dd(e,t,n){var r=0;t&&(r|=4),md(n,e,r,t)}var fd=`_reactListening`+Math.random().toString(36).slice(2);function pd(e){if(!e[fd]){e[fd]=!0,ct.forEach(function(t){t!==`selectionchange`&&(ld.has(t)||dd(t,!1,e),dd(t,!0,e))});var t=e.nodeType===9?e:e.ownerDocument;t===null||t[fd]||(t[fd]=!0,dd(`selectionchange`,!1,t))}}function md(e,t,n,r){switch(ep(t)){case 2:var i=Jf;break;case 8:i=Yf;break;default:i=Xf}n=i.bind(null,t,n,e),i=void 0,!nn||t!==`touchstart`&&t!==`touchmove`&&t!==`wheel`||(i=!0),r?i===void 0?e.addEventListener(t,n,!0):e.addEventListener(t,n,{capture:!0,passive:i}):i===void 0?e.addEventListener(t,n,!1):e.addEventListener(t,n,{passive:i})}function hd(e,t,n,r,i){var a=r;if(!(t&1)&&!(t&2)&&r!==null)a:for(;;){if(r===null)return;var s=r.tag;if(s===3||s===4){var c=r.stateNode.containerInfo;if(c===i)break;if(s===4)for(s=r.return;s!==null;){var l=s.tag;if((l===3||l===4)&&s.stateNode.containerInfo===i)return;s=s.return}for(;c!==null;){if(s=rt(c),s===null)return;if(l=s.tag,l===5||l===6||l===26||l===27){r=a=s;continue a}c=c.parentNode}}r=r.return}$t(function(){var r=a,i=Jt(n),s=[];a:{var c=Br.get(e);if(c!==void 0){var l=mn,u=e;switch(e){case`keypress`:if(ln(n)===0)break a;case`keydown`:case`keyup`:l=Mn;break;case`focusin`:u=`focus`,l=Cn;break;case`focusout`:u=`blur`,l=Cn;break;case`beforeblur`:case`afterblur`:l=Cn;break;case`click`:if(n.button===2)break a;case`auxclick`:case`dblclick`:case`mousedown`:case`mousemove`:case`mouseup`:case`mouseout`:case`mouseover`:case`contextmenu`:l=xn;break;case`drag`:case`dragend`:case`dragenter`:case`dragexit`:case`dragleave`:case`dragover`:case`dragstart`:case`drop`:l=Sn;break;case`touchcancel`:case`touchend`:case`touchmove`:case`touchstart`:l=Pn;break;case Nr:case Pr:case Fr:l=wn;break;case zr:l=Fn;break;case`scroll`:case`scrollend`:l=gn;break;case`wheel`:l=In;break;case`copy`:case`cut`:case`paste`:l=Tn;break;case`gotpointercapture`:case`lostpointercapture`:case`pointercancel`:case`pointerdown`:case`pointermove`:case`pointerout`:case`pointerover`:case`pointerup`:l=Nn;break;case`toggle`:case`beforetoggle`:l=Ln}var d=!!(t&4),f=!d&&(e===`scroll`||e===`scrollend`),p=d?c===null?null:c+`Capture`:c;d=[];for(var m=r,h;m!==null;){var g=m;if(h=g.stateNode,g=g.tag,g!==5&&g!==26&&g!==27||h===null||p===null||(g=en(m,p),g!=null&&d.push(gd(m,g,h))),f)break;m=m.return}0<d.length&&(c=new l(c,u,null,n,i),s.push({event:c,listeners:d}))}}if(!(t&7)){a:{if(c=e===`mouseover`||e===`pointerover`,l=e===`mouseout`||e===`pointerout`,c&&n!==qt&&(u=n.relatedTarget||n.fromElement)&&(rt(u)||u[Xe]))break a;if((l||c)&&(c=i.window===i?i:(c=i.ownerDocument)?c.defaultView||c.parentWindow:window,l?(u=n.relatedTarget||n.toElement,l=r,u=u?rt(u):null,u!==null&&(f=o(u),d=u.tag,u!==f||d!==5&&d!==27&&d!==6)&&(u=null)):(l=null,u=r),l!==u)){if(d=xn,g=`onMouseLeave`,p=`onMouseEnter`,m=`mouse`,(e===`pointerout`||e===`pointerover`)&&(d=Nn,g=`onPointerLeave`,p=`onPointerEnter`,m=`pointer`),f=l==null?c:at(l),h=u==null?c:at(u),c=new d(g,m+`leave`,l,n,i),c.target=f,c.relatedTarget=h,g=null,rt(i)===r&&(d=new d(p,m+`enter`,u,n,i),d.target=h,d.relatedTarget=f,g=d),f=g,l&&u)b:{for(d=l,p=u,m=0,h=d;h;h=vd(h))m++;for(h=0,g=p;g;g=vd(g))h++;for(;0<m-h;)d=vd(d),m--;for(;0<h-m;)p=vd(p),h--;for(;m--;){if(d===p||p!==null&&d===p.alternate)break b;d=vd(d),p=vd(p)}d=null}else d=null;l!==null&&yd(s,c,l,d,!1),u!==null&&f!==null&&yd(s,f,u,d,!0)}}a:{if(c=r?at(r):window,l=c.nodeName&&c.nodeName.toLowerCase(),l===`select`||l===`input`&&c.type===`file`)var _=rr;else if(Zn(c)){if(ir)_=pr;else{_=dr;var v=ur}}else l=c.nodeName,!l||l.toLowerCase()!==`input`||c.type!==`checkbox`&&c.type!==`radio`?r&&Ut(r.elementType)&&(_=rr):_=fr;if(_&&=_(e,r)){Qn(s,_,n,i);break a}v&&v(e,c,r),e===`focusout`&&r&&c.type===`number`&&r.memoizedProps.value!=null&&Ft(c,`number`,c.value)}switch(v=r?at(r):window,e){case`focusin`:(Zn(v)||v.contentEditable===`true`)&&(Cr=v,wr=r,Tr=null);break;case`focusout`:Tr=wr=Cr=null;break;case`mousedown`:Er=!0;break;case`contextmenu`:case`mouseup`:case`dragend`:Er=!1,Dr(s,n,i);break;case`selectionchange`:if(Sr)break;case`keydown`:case`keyup`:Dr(s,n,i)}var y;if(zn)b:{switch(e){case`compositionstart`:var b=`onCompositionStart`;break b;case`compositionend`:b=`onCompositionEnd`;break b;case`compositionupdate`:b=`onCompositionUpdate`;break b}b=void 0}else qn?Gn(e,n)&&(b=`onCompositionEnd`):e===`keydown`&&n.keyCode===229&&(b=`onCompositionStart`);b&&(Hn&&n.locale!==`ko`&&(qn||b!==`onCompositionStart`?b===`onCompositionEnd`&&qn&&(y=cn()):(an=i,on=`value`in an?an.value:an.textContent,qn=!0)),v=_d(r,b),0<v.length&&(b=new En(b,e,null,n,i),s.push({event:b,listeners:v}),y?b.data=y:(y=Kn(n),y!==null&&(b.data=y)))),(y=Vn?Jn(e,n):Yn(e,n))&&(b=_d(r,`onBeforeInput`),0<b.length&&(v=new En(`onBeforeInput`,`beforeinput`,null,n,i),s.push({event:v,listeners:b}),v.data=y)),ad(s,e,r,n,i)}ud(s,t)})}function gd(e,t,n){return{instance:e,listener:t,currentTarget:n}}function _d(e,t){for(var n=t+`Capture`,r=[];e!==null;){var i=e,a=i.stateNode;if(i=i.tag,i!==5&&i!==26&&i!==27||a===null||(i=en(e,n),i!=null&&r.unshift(gd(e,i,a)),i=en(e,t),i!=null&&r.push(gd(e,i,a))),e.tag===3)return r;e=e.return}return[]}function vd(e){if(e===null)return null;do e=e.return;while(e&&e.tag!==5&&e.tag!==27);return e||null}function yd(e,t,n,r,i){for(var a=t._reactName,o=[];n!==null&&n!==r;){var s=n,c=s.alternate,l=s.stateNode;if(s=s.tag,c!==null&&c===r)break;s!==5&&s!==26&&s!==27||l===null||(c=l,i?(l=en(n,a),l!=null&&o.unshift(gd(n,l,c))):i||(l=en(n,a),l!=null&&o.push(gd(n,l,c)))),n=n.return}o.length!==0&&e.push({event:t,listeners:o})}var bd=/\r\n?/g,xd=/\u0000|\uFFFD/g;function Sd(e){return(typeof e==`string`?e:``+e).replace(bd,`
|
|
10
|
-
`).replace(xd,``)}function Cd(e,t){return t=Sd(t),Sd(e)===t}function wd(){}function Td(e,t,n,r,a,o){switch(n){case`children`:typeof r==`string`?t===`body`||t===`textarea`&&r===``||zt(e,r):(typeof r==`number`||typeof r==`bigint`)&&t!==`body`&&zt(e,``+r);break;case`className`:_t(e,`class`,r);break;case`tabIndex`:_t(e,`tabindex`,r);break;case`dir`:case`role`:case`viewBox`:case`width`:case`height`:_t(e,n,r);break;case`style`:Ht(e,r,o);break;case`data`:if(t!==`object`){_t(e,`data`,r);break}case`src`:case`href`:if(r===``&&(t!==`a`||n!==`href`)||r==null||typeof r==`function`||typeof r==`symbol`||typeof r==`boolean`){e.removeAttribute(n);break}r=Kt(``+r),e.setAttribute(n,r);break;case`action`:case`formAction`:if(typeof r==`function`){e.setAttribute(n,`javascript:throw new Error('A React form was unexpectedly submitted. If you called form.submit() manually, consider using form.requestSubmit() instead. If you\\'re trying to use event.stopPropagation() in a submit event handler, consider also calling event.preventDefault().')`);break}if(typeof o==`function`&&(n===`formAction`?(t!==`input`&&Td(e,t,`name`,a.name,a,null),Td(e,t,`formEncType`,a.formEncType,a,null),Td(e,t,`formMethod`,a.formMethod,a,null),Td(e,t,`formTarget`,a.formTarget,a,null)):(Td(e,t,`encType`,a.encType,a,null),Td(e,t,`method`,a.method,a,null),Td(e,t,`target`,a.target,a,null))),r==null||typeof r==`symbol`||typeof r==`boolean`){e.removeAttribute(n);break}r=Kt(``+r),e.setAttribute(n,r);break;case`onClick`:r!=null&&(e.onclick=wd);break;case`onScroll`:r!=null&&J(`scroll`,e);break;case`onScrollEnd`:r!=null&&J(`scrollend`,e);break;case`dangerouslySetInnerHTML`:if(r!=null){if(typeof r!=`object`||!(`__html`in r))throw Error(i(61));if(n=r.__html,n!=null){if(a.children!=null)throw Error(i(60));e.innerHTML=n}}break;case`multiple`:e.multiple=r&&typeof r!=`function`&&typeof r!=`symbol`;break;case`muted`:e.muted=r&&typeof r!=`function`&&typeof r!=`symbol`;break;case`suppressContentEditableWarning`:case`suppressHydrationWarning`:case`defaultValue`:case`defaultChecked`:case`innerHTML`:case`ref`:break;case`autoFocus`:break;case`xlinkHref`:if(r==null||typeof r==`function`||typeof r==`boolean`||typeof r==`symbol`){e.removeAttribute(`xlink:href`);break}n=Kt(``+r),e.setAttributeNS(`http://www.w3.org/1999/xlink`,`xlink:href`,n);break;case`contentEditable`:case`spellCheck`:case`draggable`:case`value`:case`autoReverse`:case`externalResourcesRequired`:case`focusable`:case`preserveAlpha`:r!=null&&typeof r!=`function`&&typeof r!=`symbol`?e.setAttribute(n,``+r):e.removeAttribute(n);break;case`inert`:case`allowFullScreen`:case`async`:case`autoPlay`:case`controls`:case`default`:case`defer`:case`disabled`:case`disablePictureInPicture`:case`disableRemotePlayback`:case`formNoValidate`:case`hidden`:case`loop`:case`noModule`:case`noValidate`:case`open`:case`playsInline`:case`readOnly`:case`required`:case`reversed`:case`scoped`:case`seamless`:case`itemScope`:r&&typeof r!=`function`&&typeof r!=`symbol`?e.setAttribute(n,``):e.removeAttribute(n);break;case`capture`:case`download`:!0===r?e.setAttribute(n,``):!1!==r&&r!=null&&typeof r!=`function`&&typeof r!=`symbol`?e.setAttribute(n,r):e.removeAttribute(n);break;case`cols`:case`rows`:case`size`:case`span`:r!=null&&typeof r!=`function`&&typeof r!=`symbol`&&!isNaN(r)&&1<=r?e.setAttribute(n,r):e.removeAttribute(n);break;case`rowSpan`:case`start`:r==null||typeof r==`function`||typeof r==`symbol`||isNaN(r)?e.removeAttribute(n):e.setAttribute(n,r);break;case`popover`:J(`beforetoggle`,e),J(`toggle`,e),gt(e,`popover`,r);break;case`xlinkActuate`:vt(e,`http://www.w3.org/1999/xlink`,`xlink:actuate`,r);break;case`xlinkArcrole`:vt(e,`http://www.w3.org/1999/xlink`,`xlink:arcrole`,r);break;case`xlinkRole`:vt(e,`http://www.w3.org/1999/xlink`,`xlink:role`,r);break;case`xlinkShow`:vt(e,`http://www.w3.org/1999/xlink`,`xlink:show`,r);break;case`xlinkTitle`:vt(e,`http://www.w3.org/1999/xlink`,`xlink:title`,r);break;case`xlinkType`:vt(e,`http://www.w3.org/1999/xlink`,`xlink:type`,r);break;case`xmlBase`:vt(e,`http://www.w3.org/XML/1998/namespace`,`xml:base`,r);break;case`xmlLang`:vt(e,`http://www.w3.org/XML/1998/namespace`,`xml:lang`,r);break;case`xmlSpace`:vt(e,`http://www.w3.org/XML/1998/namespace`,`xml:space`,r);break;case`is`:gt(e,`is`,r);break;case`innerText`:case`textContent`:break;default:(!(2<n.length)||n[0]!==`o`&&n[0]!==`O`||n[1]!==`n`&&n[1]!==`N`)&&(n=Wt.get(n)||n,gt(e,n,r))}}function Ed(e,t,n,r,a,o){switch(n){case`style`:Ht(e,r,o);break;case`dangerouslySetInnerHTML`:if(r!=null){if(typeof r!=`object`||!(`__html`in r))throw Error(i(61));if(n=r.__html,n!=null){if(a.children!=null)throw Error(i(60));e.innerHTML=n}}break;case`children`:typeof r==`string`?zt(e,r):(typeof r==`number`||typeof r==`bigint`)&&zt(e,``+r);break;case`onScroll`:r!=null&&J(`scroll`,e);break;case`onScrollEnd`:r!=null&&J(`scrollend`,e);break;case`onClick`:r!=null&&(e.onclick=wd);break;case`suppressContentEditableWarning`:case`suppressHydrationWarning`:case`innerHTML`:case`ref`:break;case`innerText`:case`textContent`:break;default:if(!lt.hasOwnProperty(n))a:{if(n[0]===`o`&&n[1]===`n`&&(a=n.endsWith(`Capture`),t=n.slice(2,a?n.length-7:void 0),o=e[Ye]||null,o=o==null?null:o[n],typeof o==`function`&&e.removeEventListener(t,o,a),typeof r==`function`)){typeof o!=`function`&&o!==null&&(n in e?e[n]=null:e.hasAttribute(n)&&e.removeAttribute(n)),e.addEventListener(t,r,a);break a}n in e?e[n]=r:!0===r?e.setAttribute(n,``):gt(e,n,r)}}}function Y(e,t,n){switch(t){case`div`:case`span`:case`svg`:case`path`:case`a`:case`g`:case`p`:case`li`:break;case`img`:J(`error`,e),J(`load`,e);var r=!1,a=!1,o;for(o in n)if(n.hasOwnProperty(o)){var s=n[o];if(s!=null)switch(o){case`src`:r=!0;break;case`srcSet`:a=!0;break;case`children`:case`dangerouslySetInnerHTML`:throw Error(i(137,t));default:Td(e,t,o,s,n,null)}}a&&Td(e,t,`srcSet`,n.srcSet,n,null),r&&Td(e,t,`src`,n.src,n,null);return;case`input`:J(`invalid`,e);var c=o=s=a=null,l=null,u=null;for(r in n)if(n.hasOwnProperty(r)){var d=n[r];if(d!=null)switch(r){case`name`:a=d;break;case`type`:s=d;break;case`checked`:l=d;break;case`defaultChecked`:u=d;break;case`value`:o=d;break;case`defaultValue`:c=d;break;case`children`:case`dangerouslySetInnerHTML`:if(d!=null)throw Error(i(137,t));break;default:Td(e,t,r,d,n,null)}}Pt(e,o,c,l,u,s,a,!1),Ot(e);return;case`select`:for(a in J(`invalid`,e),r=s=o=null,n)if(n.hasOwnProperty(a)&&(c=n[a],c!=null))switch(a){case`value`:o=c;break;case`defaultValue`:s=c;break;case`multiple`:r=c;default:Td(e,t,a,c,n,null)}t=o,n=s,e.multiple=!!r,t==null?n!=null&&It(e,!!r,n,!0):It(e,!!r,t,!1);return;case`textarea`:for(s in J(`invalid`,e),o=a=r=null,n)if(n.hasOwnProperty(s)&&(c=n[s],c!=null))switch(s){case`value`:r=c;break;case`defaultValue`:a=c;break;case`children`:o=c;break;case`dangerouslySetInnerHTML`:if(c!=null)throw Error(i(91));break;default:Td(e,t,s,c,n,null)}Rt(e,r,a,o),Ot(e);return;case`option`:for(l in n)if(n.hasOwnProperty(l)&&(r=n[l],r!=null))switch(l){case`selected`:e.selected=r&&typeof r!=`function`&&typeof r!=`symbol`;break;default:Td(e,t,l,r,n,null)}return;case`dialog`:J(`beforetoggle`,e),J(`toggle`,e),J(`cancel`,e),J(`close`,e);break;case`iframe`:case`object`:J(`load`,e);break;case`video`:case`audio`:for(r=0;r<cd.length;r++)J(cd[r],e);break;case`image`:J(`error`,e),J(`load`,e);break;case`details`:J(`toggle`,e);break;case`embed`:case`source`:case`link`:J(`error`,e),J(`load`,e);case`area`:case`base`:case`br`:case`col`:case`hr`:case`keygen`:case`meta`:case`param`:case`track`:case`wbr`:case`menuitem`:for(u in n)if(n.hasOwnProperty(u)&&(r=n[u],r!=null))switch(u){case`children`:case`dangerouslySetInnerHTML`:throw Error(i(137,t));default:Td(e,t,u,r,n,null)}return;default:if(Ut(t)){for(d in n)n.hasOwnProperty(d)&&(r=n[d],r!==void 0&&Ed(e,t,d,r,n,void 0));return}}for(c in n)n.hasOwnProperty(c)&&(r=n[c],r!=null&&Td(e,t,c,r,n,null))}function Dd(e,t,n,r){switch(t){case`div`:case`span`:case`svg`:case`path`:case`a`:case`g`:case`p`:case`li`:break;case`input`:var a=null,o=null,s=null,c=null,l=null,u=null,d=null;for(m in n){var f=n[m];if(n.hasOwnProperty(m)&&f!=null)switch(m){case`checked`:break;case`value`:break;case`defaultValue`:l=f;default:r.hasOwnProperty(m)||Td(e,t,m,null,r,f)}}for(var p in r){var m=r[p];if(f=n[p],r.hasOwnProperty(p)&&(m!=null||f!=null))switch(p){case`type`:o=m;break;case`name`:a=m;break;case`checked`:u=m;break;case`defaultChecked`:d=m;break;case`value`:s=m;break;case`defaultValue`:c=m;break;case`children`:case`dangerouslySetInnerHTML`:if(m!=null)throw Error(i(137,t));break;default:m!==f&&Td(e,t,p,m,r,f)}}Nt(e,s,c,l,u,d,o,a);return;case`select`:for(o in m=s=c=p=null,n)if(l=n[o],n.hasOwnProperty(o)&&l!=null)switch(o){case`value`:break;case`multiple`:m=l;default:r.hasOwnProperty(o)||Td(e,t,o,null,r,l)}for(a in r)if(o=r[a],l=n[a],r.hasOwnProperty(a)&&(o!=null||l!=null))switch(a){case`value`:p=o;break;case`defaultValue`:c=o;break;case`multiple`:s=o;default:o!==l&&Td(e,t,a,o,r,l)}t=c,n=s,r=m,p==null?!!r!=!!n&&(t==null?It(e,!!n,n?[]:``,!1):It(e,!!n,t,!0)):It(e,!!n,p,!1);return;case`textarea`:for(c in m=p=null,n)if(a=n[c],n.hasOwnProperty(c)&&a!=null&&!r.hasOwnProperty(c))switch(c){case`value`:break;case`children`:break;default:Td(e,t,c,null,r,a)}for(s in r)if(a=r[s],o=n[s],r.hasOwnProperty(s)&&(a!=null||o!=null))switch(s){case`value`:p=a;break;case`defaultValue`:m=a;break;case`children`:break;case`dangerouslySetInnerHTML`:if(a!=null)throw Error(i(91));break;default:a!==o&&Td(e,t,s,a,r,o)}Lt(e,p,m);return;case`option`:for(var h in n)if(p=n[h],n.hasOwnProperty(h)&&p!=null&&!r.hasOwnProperty(h))switch(h){case`selected`:e.selected=!1;break;default:Td(e,t,h,null,r,p)}for(l in r)if(p=r[l],m=n[l],r.hasOwnProperty(l)&&p!==m&&(p!=null||m!=null))switch(l){case`selected`:e.selected=p&&typeof p!=`function`&&typeof p!=`symbol`;break;default:Td(e,t,l,p,r,m)}return;case`img`:case`link`:case`area`:case`base`:case`br`:case`col`:case`embed`:case`hr`:case`keygen`:case`meta`:case`param`:case`source`:case`track`:case`wbr`:case`menuitem`:for(var g in n)p=n[g],n.hasOwnProperty(g)&&p!=null&&!r.hasOwnProperty(g)&&Td(e,t,g,null,r,p);for(u in r)if(p=r[u],m=n[u],r.hasOwnProperty(u)&&p!==m&&(p!=null||m!=null))switch(u){case`children`:case`dangerouslySetInnerHTML`:if(p!=null)throw Error(i(137,t));break;default:Td(e,t,u,p,r,m)}return;default:if(Ut(t)){for(var _ in n)p=n[_],n.hasOwnProperty(_)&&p!==void 0&&!r.hasOwnProperty(_)&&Ed(e,t,_,void 0,r,p);for(d in r)p=r[d],m=n[d],!r.hasOwnProperty(d)||p===m||p===void 0&&m===void 0||Ed(e,t,d,p,r,m);return}}for(var v in n)p=n[v],n.hasOwnProperty(v)&&p!=null&&!r.hasOwnProperty(v)&&Td(e,t,v,null,r,p);for(f in r)p=r[f],m=n[f],!r.hasOwnProperty(f)||p===m||p==null&&m==null||Td(e,t,f,p,r,m)}var Od=null,kd=null;function Ad(e){return e.nodeType===9?e:e.ownerDocument}function jd(e){switch(e){case`http://www.w3.org/2000/svg`:return 1;case`http://www.w3.org/1998/Math/MathML`:return 2;default:return 0}}function Md(e,t){if(e===0)switch(t){case`svg`:return 1;case`math`:return 2;default:return 0}return e===1&&t===`foreignObject`?0:e}function Nd(e,t){return e===`textarea`||e===`noscript`||typeof t.children==`string`||typeof t.children==`number`||typeof t.children==`bigint`||typeof t.dangerouslySetInnerHTML==`object`&&t.dangerouslySetInnerHTML!==null&&t.dangerouslySetInnerHTML.__html!=null}var Pd=null;function Fd(){var e=window.event;return e&&e.type===`popstate`?e!==Pd&&(Pd=e,!0):(Pd=null,!1)}var Id=typeof setTimeout==`function`?setTimeout:void 0,Ld=typeof clearTimeout==`function`?clearTimeout:void 0,Rd=typeof Promise==`function`?Promise:void 0,zd=typeof queueMicrotask==`function`?queueMicrotask:Rd===void 0?Id:function(e){return Rd.resolve(null).then(e).catch(Bd)};function Bd(e){setTimeout(function(){throw e})}function Vd(e){return e===`head`}function Hd(e,t){var n=t,r=0,i=0;do{var a=n.nextSibling;if(e.removeChild(n),a&&a.nodeType===8){if(n=a.data,n===`/$`){if(0<r&&8>r){n=r;var o=e.ownerDocument;if(n&1&&Qd(o.documentElement),n&2&&Qd(o.body),n&4)for(n=o.head,Qd(n),o=n.firstChild;o;){var s=o.nextSibling,c=o.nodeName;o[tt]||c===`SCRIPT`||c===`STYLE`||c===`LINK`&&o.rel.toLowerCase()===`stylesheet`||n.removeChild(o),o=s}}if(i===0){e.removeChild(a),yp(t);return}i--}else n===`$`||n===`$?`||n===`$!`?i++:r=n.charCodeAt(0)-48}else r=0;n=a}while(n);yp(t)}function Ud(e){var t=e.firstChild;for(t&&t.nodeType===10&&(t=t.nextSibling);t;){var n=t;switch(t=t.nextSibling,n.nodeName){case`HTML`:case`HEAD`:case`BODY`:Ud(n),nt(n);continue;case`SCRIPT`:case`STYLE`:continue;case`LINK`:if(n.rel.toLowerCase()===`stylesheet`)continue}e.removeChild(n)}}function Wd(e,t,n,r){for(;e.nodeType===1;){var i=n;if(e.nodeName.toLowerCase()!==t.toLowerCase()){if(!r&&(e.nodeName!==`INPUT`||e.type!==`hidden`))break}else if(!r){if(t===`input`&&e.type===`hidden`){var a=i.name==null?null:``+i.name;if(i.type===`hidden`&&e.getAttribute(`name`)===a)return e}else return e}else if(!e[tt])switch(t){case`meta`:if(!e.hasAttribute(`itemprop`))break;return e;case`link`:if(a=e.getAttribute(`rel`),a===`stylesheet`&&e.hasAttribute(`data-precedence`)||a!==i.rel||e.getAttribute(`href`)!==(i.href==null||i.href===``?null:i.href)||e.getAttribute(`crossorigin`)!==(i.crossOrigin==null?null:i.crossOrigin)||e.getAttribute(`title`)!==(i.title==null?null:i.title))break;return e;case`style`:if(e.hasAttribute(`data-precedence`))break;return e;case`script`:if(a=e.getAttribute(`src`),(a!==(i.src==null?null:i.src)||e.getAttribute(`type`)!==(i.type==null?null:i.type)||e.getAttribute(`crossorigin`)!==(i.crossOrigin==null?null:i.crossOrigin))&&a&&e.hasAttribute(`async`)&&!e.hasAttribute(`itemprop`))break;return e;default:return e}if(e=Jd(e.nextSibling),e===null)break}return null}function Gd(e,t,n){if(t===``)return null;for(;e.nodeType!==3;)if((e.nodeType!==1||e.nodeName!==`INPUT`||e.type!==`hidden`)&&!n||(e=Jd(e.nextSibling),e===null))return null;return e}function Kd(e){return e.data===`$!`||e.data===`$?`&&e.ownerDocument.readyState===`complete`}function qd(e,t){var n=e.ownerDocument;if(e.data!==`$?`||n.readyState===`complete`)t();else{var r=function(){t(),n.removeEventListener(`DOMContentLoaded`,r)};n.addEventListener(`DOMContentLoaded`,r),e._reactRetry=r}}function Jd(e){for(;e!=null;e=e.nextSibling){var t=e.nodeType;if(t===1||t===3)break;if(t===8){if(t=e.data,t===`$`||t===`$!`||t===`$?`||t===`F!`||t===`F`)break;if(t===`/$`)return null}}return e}var Yd=null;function Xd(e){e=e.previousSibling;for(var t=0;e;){if(e.nodeType===8){var n=e.data;if(n===`$`||n===`$!`||n===`$?`){if(t===0)return e;t--}else n===`/$`&&t++}e=e.previousSibling}return null}function Zd(e,t,n){switch(t=Ad(n),e){case`html`:if(e=t.documentElement,!e)throw Error(i(452));return e;case`head`:if(e=t.head,!e)throw Error(i(453));return e;case`body`:if(e=t.body,!e)throw Error(i(454));return e;default:throw Error(i(451))}}function Qd(e){for(var t=e.attributes;t.length;)e.removeAttributeNode(t[0]);nt(e)}var $d=new Map,ef=new Set;function tf(e){return typeof e.getRootNode==`function`?e.getRootNode():e.nodeType===9?e:e.ownerDocument}var nf=P.d;P.d={f:rf,r:af,D:cf,C:lf,L:uf,m:df,X:pf,S:ff,M:mf};function rf(){var e=nf.f(),t=du();return e||t}function af(e){var t=it(e);t!==null&&t.tag===5&&t.type===`form`?ts(t):nf.r(e)}var of=typeof document>`u`?null:document;function sf(e,t,n){var r=of;if(r&&typeof t==`string`&&t){var i=Mt(t);i=`link[rel="`+e+`"][href="`+i+`"]`,typeof n==`string`&&(i+=`[crossorigin="`+n+`"]`),ef.has(i)||(ef.add(i),e={rel:e,crossOrigin:n,href:t},r.querySelector(i)===null&&(t=r.createElement(`link`),Y(t,`link`,e),st(t),r.head.appendChild(t)))}}function cf(e){nf.D(e),sf(`dns-prefetch`,e,null)}function lf(e,t){nf.C(e,t),sf(`preconnect`,e,t)}function uf(e,t,n){nf.L(e,t,n);var r=of;if(r&&e&&t){var i=`link[rel="preload"][as="`+Mt(t)+`"]`;t===`image`&&n&&n.imageSrcSet?(i+=`[imagesrcset="`+Mt(n.imageSrcSet)+`"]`,typeof n.imageSizes==`string`&&(i+=`[imagesizes="`+Mt(n.imageSizes)+`"]`)):i+=`[href="`+Mt(e)+`"]`;var a=i;switch(t){case`style`:a=gf(e);break;case`script`:a=bf(e)}$d.has(a)||(e=p({rel:`preload`,href:t===`image`&&n&&n.imageSrcSet?void 0:e,as:t},n),$d.set(a,e),r.querySelector(i)!==null||t===`style`&&r.querySelector(_f(a))||t===`script`&&r.querySelector(xf(a))||(t=r.createElement(`link`),Y(t,`link`,e),st(t),r.head.appendChild(t)))}}function df(e,t){nf.m(e,t);var n=of;if(n&&e){var r=t&&typeof t.as==`string`?t.as:`script`,i=`link[rel="modulepreload"][as="`+Mt(r)+`"][href="`+Mt(e)+`"]`,a=i;switch(r){case`audioworklet`:case`paintworklet`:case`serviceworker`:case`sharedworker`:case`worker`:case`script`:a=bf(e)}if(!$d.has(a)&&(e=p({rel:`modulepreload`,href:e},t),$d.set(a,e),n.querySelector(i)===null)){switch(r){case`audioworklet`:case`paintworklet`:case`serviceworker`:case`sharedworker`:case`worker`:case`script`:if(n.querySelector(xf(a)))return}r=n.createElement(`link`),Y(r,`link`,e),st(r),n.head.appendChild(r)}}}function ff(e,t,n){nf.S(e,t,n);var r=of;if(r&&e){var i=ot(r).hoistableStyles,a=gf(e);t||=`default`;var o=i.get(a);if(!o){var s={loading:0,preload:null};if(o=r.querySelector(_f(a)))s.loading=5;else{e=p({rel:`stylesheet`,href:e,"data-precedence":t},n),(n=$d.get(a))&&wf(e,n);var c=o=r.createElement(`link`);st(c),Y(c,`link`,e),c._p=new Promise(function(e,t){c.onload=e,c.onerror=t}),c.addEventListener(`load`,function(){s.loading|=1}),c.addEventListener(`error`,function(){s.loading|=2}),s.loading|=4,Cf(o,t,r)}o={type:`stylesheet`,instance:o,count:1,state:s},i.set(a,o)}}}function pf(e,t){nf.X(e,t);var n=of;if(n&&e){var r=ot(n).hoistableScripts,i=bf(e),a=r.get(i);a||(a=n.querySelector(xf(i)),a||(e=p({src:e,async:!0},t),(t=$d.get(i))&&Tf(e,t),a=n.createElement(`script`),st(a),Y(a,`link`,e),n.head.appendChild(a)),a={type:`script`,instance:a,count:1,state:null},r.set(i,a))}}function mf(e,t){nf.M(e,t);var n=of;if(n&&e){var r=ot(n).hoistableScripts,i=bf(e),a=r.get(i);a||(a=n.querySelector(xf(i)),a||(e=p({src:e,async:!0,type:`module`},t),(t=$d.get(i))&&Tf(e,t),a=n.createElement(`script`),st(a),Y(a,`link`,e),n.head.appendChild(a)),a={type:`script`,instance:a,count:1,state:null},r.set(i,a))}}function hf(e,t,n,r){var a=(a=oe.current)?tf(a):null;if(!a)throw Error(i(446));switch(e){case`meta`:case`title`:return null;case`style`:return typeof n.precedence==`string`&&typeof n.href==`string`?(t=gf(n.href),n=ot(a).hoistableStyles,r=n.get(t),r||(r={type:`style`,instance:null,count:0,state:null},n.set(t,r)),r):{type:`void`,instance:null,count:0,state:null};case`link`:if(n.rel===`stylesheet`&&typeof n.href==`string`&&typeof n.precedence==`string`){e=gf(n.href);var o=ot(a).hoistableStyles,s=o.get(e);if(s||(a=a.ownerDocument||a,s={type:`stylesheet`,instance:null,count:0,state:{loading:0,preload:null}},o.set(e,s),(o=a.querySelector(_f(e)))&&!o._p&&(s.instance=o,s.state.loading=5),$d.has(e)||(n={rel:`preload`,as:`style`,href:n.href,crossOrigin:n.crossOrigin,integrity:n.integrity,media:n.media,hrefLang:n.hrefLang,referrerPolicy:n.referrerPolicy},$d.set(e,n),o||yf(a,e,n,s.state))),t&&r===null)throw Error(i(528,``));return s}if(t&&r!==null)throw Error(i(529,``));return null;case`script`:return t=n.async,n=n.src,typeof n==`string`&&t&&typeof t!=`function`&&typeof t!=`symbol`?(t=bf(n),n=ot(a).hoistableScripts,r=n.get(t),r||(r={type:`script`,instance:null,count:0,state:null},n.set(t,r)),r):{type:`void`,instance:null,count:0,state:null};default:throw Error(i(444,e))}}function gf(e){return`href="`+Mt(e)+`"`}function _f(e){return`link[rel="stylesheet"][`+e+`]`}function vf(e){return p({},e,{"data-precedence":e.precedence,precedence:null})}function yf(e,t,n,r){e.querySelector(`link[rel="preload"][as="style"][`+t+`]`)?r.loading=1:(t=e.createElement(`link`),r.preload=t,t.addEventListener(`load`,function(){return r.loading|=1}),t.addEventListener(`error`,function(){return r.loading|=2}),Y(t,`link`,n),st(t),e.head.appendChild(t))}function bf(e){return`[src="`+Mt(e)+`"]`}function xf(e){return`script[async]`+e}function Sf(e,t,n){if(t.count++,t.instance===null)switch(t.type){case`style`:var r=e.querySelector(`style[data-href~="`+Mt(n.href)+`"]`);if(r)return t.instance=r,st(r),r;var a=p({},n,{"data-href":n.href,"data-precedence":n.precedence,href:null,precedence:null});return r=(e.ownerDocument||e).createElement(`style`),st(r),Y(r,`style`,a),Cf(r,n.precedence,e),t.instance=r;case`stylesheet`:a=gf(n.href);var o=e.querySelector(_f(a));if(o)return t.state.loading|=4,t.instance=o,st(o),o;r=vf(n),(a=$d.get(a))&&wf(r,a),o=(e.ownerDocument||e).createElement(`link`),st(o);var s=o;return s._p=new Promise(function(e,t){s.onload=e,s.onerror=t}),Y(o,`link`,r),t.state.loading|=4,Cf(o,n.precedence,e),t.instance=o;case`script`:return o=bf(n.src),(a=e.querySelector(xf(o)))?(t.instance=a,st(a),a):(r=n,(a=$d.get(o))&&(r=p({},n),Tf(r,a)),e=e.ownerDocument||e,a=e.createElement(`script`),st(a),Y(a,`link`,r),e.head.appendChild(a),t.instance=a);case`void`:return null;default:throw Error(i(443,t.type))}else t.type===`stylesheet`&&!(t.state.loading&4)&&(r=t.instance,t.state.loading|=4,Cf(r,n.precedence,e));return t.instance}function Cf(e,t,n){for(var r=n.querySelectorAll(`link[rel="stylesheet"][data-precedence],style[data-precedence]`),i=r.length?r[r.length-1]:null,a=i,o=0;o<r.length;o++){var s=r[o];if(s.dataset.precedence===t)a=s;else if(a!==i)break}a?a.parentNode.insertBefore(e,a.nextSibling):(t=n.nodeType===9?n.head:n,t.insertBefore(e,t.firstChild))}function wf(e,t){e.crossOrigin??=t.crossOrigin,e.referrerPolicy??=t.referrerPolicy,e.title??=t.title}function Tf(e,t){e.crossOrigin??=t.crossOrigin,e.referrerPolicy??=t.referrerPolicy,e.integrity??=t.integrity}var Ef=null;function Df(e,t,n){if(Ef===null){var r=new Map,i=Ef=new Map;i.set(n,r)}else i=Ef,r=i.get(n),r||(r=new Map,i.set(n,r));if(r.has(e))return r;for(r.set(e,null),n=n.getElementsByTagName(e),i=0;i<n.length;i++){var a=n[i];if(!(a[tt]||a[Je]||e===`link`&&a.getAttribute(`rel`)===`stylesheet`)&&a.namespaceURI!==`http://www.w3.org/2000/svg`){var o=a.getAttribute(t)||``;o=e+o;var s=r.get(o);s?s.push(a):r.set(o,[a])}}return r}function Of(e,t,n){e=e.ownerDocument||e,e.head.insertBefore(n,t===`title`?e.querySelector(`head > title`):null)}function kf(e,t,n){if(n===1||t.itemProp!=null)return!1;switch(e){case`meta`:case`title`:return!0;case`style`:if(typeof t.precedence!=`string`||typeof t.href!=`string`||t.href===``)break;return!0;case`link`:if(typeof t.rel!=`string`||typeof t.href!=`string`||t.href===``||t.onLoad||t.onError)break;switch(t.rel){case`stylesheet`:return e=t.disabled,typeof t.precedence==`string`&&e==null;default:return!0}case`script`:if(t.async&&typeof t.async!=`function`&&typeof t.async!=`symbol`&&!t.onLoad&&!t.onError&&t.src&&typeof t.src==`string`)return!0}return!1}function Af(e){return!(e.type===`stylesheet`&&!(e.state.loading&3))}var jf=null;function Mf(){}function Nf(e,t,n){if(jf===null)throw Error(i(475));var r=jf;if(t.type===`stylesheet`&&(typeof n.media!=`string`||!1!==matchMedia(n.media).matches)&&!(t.state.loading&4)){if(t.instance===null){var a=gf(n.href),o=e.querySelector(_f(a));if(o){e=o._p,typeof e==`object`&&e&&typeof e.then==`function`&&(r.count++,r=Ff.bind(r),e.then(r,r)),t.state.loading|=4,t.instance=o,st(o);return}o=e.ownerDocument||e,n=vf(n),(a=$d.get(a))&&wf(n,a),o=o.createElement(`link`),st(o);var s=o;s._p=new Promise(function(e,t){s.onload=e,s.onerror=t}),Y(o,`link`,n),t.instance=o}r.stylesheets===null&&(r.stylesheets=new Map),r.stylesheets.set(t,e),(e=t.state.preload)&&!(t.state.loading&3)&&(r.count++,t=Ff.bind(r),e.addEventListener(`load`,t),e.addEventListener(`error`,t))}}function Pf(){if(jf===null)throw Error(i(475));var e=jf;return e.stylesheets&&e.count===0&&Lf(e,e.stylesheets),0<e.count?function(t){var n=setTimeout(function(){if(e.stylesheets&&Lf(e,e.stylesheets),e.unsuspend){var t=e.unsuspend;e.unsuspend=null,t()}},6e4);return e.unsuspend=t,function(){e.unsuspend=null,clearTimeout(n)}}:null}function Ff(){if(this.count--,this.count===0){if(this.stylesheets)Lf(this,this.stylesheets);else if(this.unsuspend){var e=this.unsuspend;this.unsuspend=null,e()}}}var If=null;function Lf(e,t){e.stylesheets=null,e.unsuspend!==null&&(e.count++,If=new Map,t.forEach(Rf,e),If=null,Ff.call(e))}function Rf(e,t){if(!(t.state.loading&4)){var n=If.get(e);if(n)var r=n.get(null);else{n=new Map,If.set(e,n);for(var i=e.querySelectorAll(`link[data-precedence],style[data-precedence]`),a=0;a<i.length;a++){var o=i[a];(o.nodeName===`LINK`||o.getAttribute(`media`)!==`not all`)&&(n.set(o.dataset.precedence,o),r=o)}r&&n.set(null,r)}i=t.instance,o=i.getAttribute(`data-precedence`),a=n.get(o)||r,a===r&&n.set(null,i),n.set(o,i),this.count++,r=Ff.bind(this),i.addEventListener(`load`,r),i.addEventListener(`error`,r),a?a.parentNode.insertBefore(i,a.nextSibling):(e=e.nodeType===9?e.head:e,e.insertBefore(i,e.firstChild)),t.state.loading|=4}}var zf={$$typeof:C,Provider:null,Consumer:null,_currentValue:F,_currentValue2:F,_threadCount:0};function Bf(e,t,n,r,i,a,o,s){this.tag=1,this.containerInfo=e,this.pingCache=this.current=this.pendingChildren=null,this.timeoutHandle=-1,this.callbackNode=this.next=this.pendingContext=this.context=this.cancelPendingCommit=null,this.callbackPriority=0,this.expirationTimes=Re(-1),this.entangledLanes=this.shellSuspendCounter=this.errorRecoveryDisabledLanes=this.expiredLanes=this.warmLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=Re(0),this.hiddenUpdates=Re(null),this.identifierPrefix=r,this.onUncaughtError=i,this.onCaughtError=a,this.onRecoverableError=o,this.pooledCache=null,this.pooledCacheLanes=0,this.formState=s,this.incompleteTransitions=new Map}function Vf(e,t,n,r,i,a,o,s,c,l,u,d){return e=new Bf(e,t,n,o,s,c,l,d),t=1,!0===a&&(t|=24),a=ni(3,null,null,t),e.current=a,a.stateNode=e,t=$i(),t.refCount++,e.pooledCache=t,t.refCount++,a.memoizedState={element:r,isDehydrated:n,cache:t},Ca(a),e}function Hf(e){return e?(e=ei,e):ei}function Uf(e,t,n,r,i,a){i=Hf(i),r.context===null?r.context=i:r.pendingContext=i,r=Ta(t),r.payload={element:n},a=a===void 0?null:a,a!==null&&(r.callback=a),n=Ea(e,r,t),n!==null&&(ou(n,e,t),Da(n,e,t))}function Wf(e,t){if(e=e.memoizedState,e!==null&&e.dehydrated!==null){var n=e.retryLane;e.retryLane=n!==0&&n<t?n:t}}function Gf(e,t){Wf(e,t),(e=e.alternate)&&Wf(e,t)}function Kf(e){if(e.tag===13){var t=Zr(e,67108864);t!==null&&ou(t,e,67108864),Gf(e,67108864)}}var qf=!0;function Jf(e,t,n,r){var i=N.T;N.T=null;var a=P.p;try{P.p=2,Xf(e,t,n,r)}finally{P.p=a,N.T=i}}function Yf(e,t,n,r){var i=N.T;N.T=null;var a=P.p;try{P.p=8,Xf(e,t,n,r)}finally{P.p=a,N.T=i}}function Xf(e,t,n,r){if(qf){var i=Zf(r);if(i===null)hd(e,t,r,Qf,n),lp(e,r);else if(dp(i,e,t,n,r))r.stopPropagation();else if(lp(e,r),t&4&&-1<cp.indexOf(e)){for(;i!==null;){var a=it(i);if(a!==null)switch(a.tag){case 3:if(a=a.stateNode,a.current.memoizedState.isDehydrated){var o=Me(a.pendingLanes);if(o!==0){var s=a;for(s.pendingLanes|=2,s.entangledLanes|=2;o;){var c=1<<31-Ee(o);s.entanglements[1]|=c,o&=~c}Ju(a),!(Ol&6)&&(Kl=ge()+500,Yu(0,!1))}}break;case 13:s=Zr(a,2),s!==null&&ou(s,a,2),du(),Gf(a,2)}if(a=Zf(r),a===null&&hd(e,t,r,Qf,n),a===i)break;i=a}i!==null&&r.stopPropagation()}else hd(e,t,r,null,n)}}function Zf(e){return e=Jt(e),$f(e)}var Qf=null;function $f(e){if(Qf=null,e=rt(e),e!==null){var t=o(e);if(t===null)e=null;else{var n=t.tag;if(n===13){if(e=s(t),e!==null)return e;e=null}else if(n===3){if(t.stateNode.current.memoizedState.isDehydrated)return t.tag===3?t.stateNode.containerInfo:null;e=null}else t!==e&&(e=null)}}return Qf=e,null}function ep(e){switch(e){case`beforetoggle`:case`cancel`:case`click`:case`close`:case`contextmenu`:case`copy`:case`cut`:case`auxclick`:case`dblclick`:case`dragend`:case`dragstart`:case`drop`:case`focusin`:case`focusout`:case`input`:case`invalid`:case`keydown`:case`keypress`:case`keyup`:case`mousedown`:case`mouseup`:case`paste`:case`pause`:case`play`:case`pointercancel`:case`pointerdown`:case`pointerup`:case`ratechange`:case`reset`:case`resize`:case`seeked`:case`submit`:case`toggle`:case`touchcancel`:case`touchend`:case`touchstart`:case`volumechange`:case`change`:case`selectionchange`:case`textInput`:case`compositionstart`:case`compositionend`:case`compositionupdate`:case`beforeblur`:case`afterblur`:case`beforeinput`:case`blur`:case`fullscreenchange`:case`focus`:case`hashchange`:case`popstate`:case`select`:case`selectstart`:return 2;case`drag`:case`dragenter`:case`dragexit`:case`dragleave`:case`dragover`:case`mousemove`:case`mouseout`:case`mouseover`:case`pointermove`:case`pointerout`:case`pointerover`:case`scroll`:case`touchmove`:case`wheel`:case`mouseenter`:case`mouseleave`:case`pointerenter`:case`pointerleave`:return 8;case`message`:switch(_e()){case ve:return 2;case V:return 8;case ye:case be:return 32;case xe:return 268435456;default:return 32}default:return 32}}var tp=!1,np=null,rp=null,ip=null,ap=new Map,op=new Map,sp=[],cp=`mousedown mouseup touchcancel touchend touchstart auxclick dblclick pointercancel pointerdown pointerup dragend dragstart drop compositionend compositionstart keydown keypress keyup input textInput copy cut paste click change contextmenu reset`.split(` `);function lp(e,t){switch(e){case`focusin`:case`focusout`:np=null;break;case`dragenter`:case`dragleave`:rp=null;break;case`mouseover`:case`mouseout`:ip=null;break;case`pointerover`:case`pointerout`:ap.delete(t.pointerId);break;case`gotpointercapture`:case`lostpointercapture`:op.delete(t.pointerId)}}function up(e,t,n,r,i,a){return e===null||e.nativeEvent!==a?(e={blockedOn:t,domEventName:n,eventSystemFlags:r,nativeEvent:a,targetContainers:[i]},t!==null&&(t=it(t),t!==null&&Kf(t)),e):(e.eventSystemFlags|=r,t=e.targetContainers,i!==null&&t.indexOf(i)===-1&&t.push(i),e)}function dp(e,t,n,r,i){switch(t){case`focusin`:return np=up(np,e,t,n,r,i),!0;case`dragenter`:return rp=up(rp,e,t,n,r,i),!0;case`mouseover`:return ip=up(ip,e,t,n,r,i),!0;case`pointerover`:var a=i.pointerId;return ap.set(a,up(ap.get(a)||null,e,t,n,r,i)),!0;case`gotpointercapture`:return a=i.pointerId,op.set(a,up(op.get(a)||null,e,t,n,r,i)),!0}return!1}function fp(e){var t=rt(e.target);if(t!==null){var n=o(t);if(n!==null){if(t=n.tag,t===13){if(t=s(n),t!==null){e.blockedOn=t,Ke(e.priority,function(){if(n.tag===13){var e=iu();e=Ue(e);var t=Zr(n,e);t!==null&&ou(t,n,e),Gf(n,e)}});return}}else if(t===3&&n.stateNode.current.memoizedState.isDehydrated){e.blockedOn=n.tag===3?n.stateNode.containerInfo:null;return}}}e.blockedOn=null}function pp(e){if(e.blockedOn!==null)return!1;for(var t=e.targetContainers;0<t.length;){var n=Zf(e.nativeEvent);if(n===null){n=e.nativeEvent;var r=new n.constructor(n.type,n);qt=r,n.target.dispatchEvent(r),qt=null}else return t=it(n),t!==null&&Kf(t),e.blockedOn=n,!1;t.shift()}return!0}function mp(e,t,n){pp(e)&&n.delete(t)}function hp(){tp=!1,np!==null&&pp(np)&&(np=null),rp!==null&&pp(rp)&&(rp=null),ip!==null&&pp(ip)&&(ip=null),ap.forEach(mp),op.forEach(mp)}function gp(e,n){e.blockedOn===n&&(e.blockedOn=null,tp||(tp=!0,t.unstable_scheduleCallback(t.unstable_NormalPriority,hp)))}var _p=null;function vp(e){_p!==e&&(_p=e,t.unstable_scheduleCallback(t.unstable_NormalPriority,function(){_p===e&&(_p=null);for(var t=0;t<e.length;t+=3){var n=e[t],r=e[t+1],i=e[t+2];if(typeof r!=`function`){if($f(r||n)===null)continue;break}var a=it(n);a!==null&&(e.splice(t,3),t-=3,$o(a,{pending:!0,data:i,method:n.method,action:r},r,i))}}))}function yp(e){function t(t){return gp(t,e)}np!==null&&gp(np,e),rp!==null&&gp(rp,e),ip!==null&&gp(ip,e),ap.forEach(t),op.forEach(t);for(var n=0;n<sp.length;n++){var r=sp[n];r.blockedOn===e&&(r.blockedOn=null)}for(;0<sp.length&&(n=sp[0],n.blockedOn===null);)fp(n),n.blockedOn===null&&sp.shift();if(n=(e.ownerDocument||e).$$reactFormReplay,n!=null)for(r=0;r<n.length;r+=3){var i=n[r],a=n[r+1],o=i[Ye]||null;if(typeof a==`function`)o||vp(n);else if(o){var s=null;if(a&&a.hasAttribute(`formAction`)){if(i=a,o=a[Ye]||null)s=o.formAction;else if($f(i)!==null)continue}else s=o.action;typeof s==`function`?n[r+1]=s:(n.splice(r,3),r-=3),vp(n)}}}function bp(e){this._internalRoot=e}xp.prototype.render=bp.prototype.render=function(e){var t=this._internalRoot;if(t===null)throw Error(i(409));var n=t.current;Uf(n,iu(),e,t,null,null)},xp.prototype.unmount=bp.prototype.unmount=function(){var e=this._internalRoot;if(e!==null){this._internalRoot=null;var t=e.containerInfo;Uf(e.current,2,null,e,null,null),du(),t[Xe]=null}};function xp(e){this._internalRoot=e}xp.prototype.unstable_scheduleHydration=function(e){if(e){var t=Ge();e={blockedOn:null,target:e,priority:t};for(var n=0;n<sp.length&&t!==0&&t<sp[n].priority;n++);sp.splice(n,0,e),n===0&&fp(e)}};var Sp=n.version;if(Sp!==`19.1.0`)throw Error(i(527,Sp,`19.1.0`));P.findDOMNode=function(e){var t=e._reactInternals;if(t===void 0)throw typeof e.render==`function`?Error(i(188)):(e=Object.keys(e).join(`,`),Error(i(268,e)));return e=l(t),e=e===null?null:d(e),e=e===null?null:e.stateNode,e};var Cp={bundleType:0,version:`19.1.0`,rendererPackageName:`react-dom`,currentDispatcherRef:N,reconcilerVersion:`19.1.0`};if(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<`u`){var wp=__REACT_DEVTOOLS_GLOBAL_HOOK__;if(!wp.isDisabled&&wp.supportsFiber)try{H=wp.inject(Cp),we=wp}catch{}}e.createRoot=function(e,t){if(!a(e))throw Error(i(299));var n=!1,r=``,o=Bs,s=Vs,c=Hs,l=null;return t!=null&&(!0===t.unstable_strictMode&&(n=!0),t.identifierPrefix!==void 0&&(r=t.identifierPrefix),t.onUncaughtError!==void 0&&(o=t.onUncaughtError),t.onCaughtError!==void 0&&(s=t.onCaughtError),t.onRecoverableError!==void 0&&(c=t.onRecoverableError),t.unstable_transitionCallbacks!==void 0&&(l=t.unstable_transitionCallbacks)),t=Vf(e,1,!1,null,null,n,r,o,s,c,l,null),e[Xe]=t.current,pd(e),new bp(t)}})),g=o(((e,t)=>{function n(){if(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<`u`&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE==`function`)try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(n)}catch(e){console.error(e)}}n(),t.exports=h()})),_=u(),v=g(),y="This tab's key is out of date. Open the address printed by `copperflow studio` again.";function b(e,t){return e===403&&/session token/i.test(t??``)?y:t??`Request failed (${e})`}function x(e){return e===y}var S=`The copperflow Studio server is not answering. Start "copperflow studio" again in the project folder, then reload this page.`;function C(e){return e instanceof TypeError?S:e instanceof Error?e.message:String(e)}var w=[`alignLeft`,`alignRight`,`alignTop`,`alignBottom`,`alignHCentres`,`alignVCentres`,`distributeH`,`distributeV`],T=new Set([`distributeH`,`distributeV`]),E=e=>w.includes(e),D=e=>T.has(e)?3:2;function O(e,t){return t>=D(e)?null:D(e)===2?`Select two or more parts`:`Select three or more parts`}var k=[`drawBus`,`drawPolyline`,`drawArc`,`drawCircle`,`drawRectangle`,`drawText`],A={bus:`drawBus`,polyline:`drawPolyline`,arc:`drawArc`,circle:`drawCircle`,rectangle:`drawRectangle`,text:`drawText`},j={drawBus:`bus`,drawPolyline:`polyline`,drawArc:`arc`,drawCircle:`circle`,drawRectangle:`rectangle`,drawText:`text`},M=e=>k.includes(e),ee=`The AI lock is on. Open it to edit.`;function te(e){return{closed:e===`ai`,editedSinceOpen:!1}}function ne(e){return{closed:!e.closed,editedSinceOpen:!1}}function N(e,t){return e.closed?e:t===`human`?e.editedSinceOpen?e:{...e,editedSinceOpen:!0}:e.editedSinceOpen?e:{...e,closed:!0}}var P=[`undo`,`redo`,`delete`,`replicateLayout`,`makeSheet`,`placeComponent`,`wire`,`netLabel`,`groundFlag`,`powerFlag`,...k,`singleRouting`,`placeVia`,`placePour`,`placePourBoard`,`placeHole`,`autoplace`,`autoplaceSelection`,`autoplaceInstance`,`fitBoard`,`importBoardDxf`,`autoroute`,`autorouteSelection`,`autorouteNet`,`unroute`,`rotate`,`rotateRight`,`removeCorners`,`filletTracks`,`straightenTracks`,`designRules`,`tidySheet`,`addPage`,`renamePage`,`deletePage`,...w,`newCircuit`,`paste`,`noConnect`,`junction`,`annotate`,`placementTransfer`,`routingCorner`,`flip`,`footprintManager`];function F(e){return e?Object.fromEntries(P.map(e=>[e,ee])):{}}var re=new Set([`wire`,`route`,`placeVia`,`armNetLabel`,...k,`rotate`,`openLibrary`,`undo`,`redo`,`nudgeLeft`,`nudgeRight`,`nudgeUp`,`nudgeDown`,`delete`,`removeCorner`,`flipBend`,`alignLeft`,`distributeH`,`filletTracks`,`straightenTracks`,`routingCorner`,`flip`,`paste`,`junction`,`placementTransfer`]);function I(e){return re.has(e)}var L=new Set([`move`,`moveGroup`,`label`,`text`,`wireSegment`,`wireCorner`]);function R(e){return L.has(e)}var z=new Set([`/api/edit`,`/api/layout`,`/api/undo`,`/api/redo`,`/api/rename-parts`,`/api/make-sheet`,`/api/route`,`/api/autoplace`,`/api/fit-board`,`/api/import-board`,`/api/unroute`,`/api/rules`,`/api/place`,`/api/new-circuit`]);function ie(e,t){return t===void 0||typeof t==`object`&&t&&t.preview===!0?!1:z.has(e.split(`?`)[0]??e)}function ae(e){return e?{title:`AI is driving`,hint:`Unlock to edit`}:{title:`You are editing`,hint:`Lock for the agent`}}function oe(e){return P.includes(e)}function se(e){let t=!1,n=!1,r=e;return{set(e){e&&!t&&(n=!1),t=e},closed:()=>t,listen(e){r=e},refuses(){return t?(n||(n=!0,r(ee)),!0):!1}}}var ce=se(()=>void 0),le=`copperflow-token`,ue=2e3;function de(){let e=/[#&]token=([^&]+)/.exec(window.location.hash);if(e?.[1]){let t=decodeURIComponent(e[1]);try{sessionStorage.setItem(le,t)}catch{}return window.history.replaceState(null,``,window.location.pathname+window.location.search),t}try{return sessionStorage.getItem(le)??``}catch{return``}}var fe=de(),pe=fe!==``;window.addEventListener(`hashchange`,()=>{/[#&]token=/.test(window.location.hash)&&window.location.reload()});async function B(e,t){if(ce.closed()&&ie(e,t))throw Error(ee);let n;try{n=await fetch(e,{method:t===void 0?`GET`:`POST`,headers:{"x-copperflow-token":fe,"content-type":`application/json`},...t===void 0?{}:{body:JSON.stringify(t)}})}catch(e){throw Error(C(e))}let r=await n.json();if(!r.ok)throw Object.assign(Error(b(n.status,r.error)),{status:n.status,data:r.data});return r.data}async function me(e){let t;try{t=await fetch(e,{headers:{"x-copperflow-token":fe}})}catch(e){throw Error(C(e))}if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(b(t.status,e.error))}return t.blob()}var he=[`change`,`build`,`library`,`route`,`place`];function ge(e,t){let n=new AbortController,r=t=>{let n=/^event: (.+)$/m.exec(t)?.[1],r=/^data: (.+)$/m.exec(t)?.[1];if(n!==void 0&&he.includes(n)&&r){let t=JSON.parse(r);e(n,typeof t.file==`string`?t.file:``,t)}};return(async()=>{for(;!n.signal.aborted;){try{let e=await fetch(`/api/events`,{headers:{"x-copperflow-token":fe},signal:n.signal});if(!e.ok||!e.body)throw Error(`Event stream failed (${e.status})`);t?.(!0);let i=e.body.pipeThrough(new TextDecoderStream).getReader(),a=``;for(;;){let{value:e,done:t}=await i.read();if(t)break;a+=e;for(let e=a.indexOf(`
|
|
11
|
-
|
|
12
|
-
`);e>=0;e=a.indexOf(`
|
|
13
|
-
|
|
14
|
-
`))r(a.slice(0,e)),a=a.slice(e+2)}}catch(e){if(n.signal.aborted)return;e instanceof TypeError&&t?.(!1)}await new Promise(e=>setTimeout(e,ue))}})(),()=>n.abort()}var _e=.5,ve=2e3;function V(e,t,n){return{x:(n.x-e.cx)*e.scale+t.width/2,y:-(n.y-e.cy)*e.scale+t.height/2}}function ye(e,t,n){return{x:(n.x-t.width/2)/e.scale+e.cx,y:-(n.y-t.height/2)/e.scale+e.cy}}function be(e,t,n=.12){let r=Math.max(e.maxX-e.minX,1),i=Math.max(e.maxY-e.minY,1),a=Math.min(t.width/r,t.height/i)*(1-2*n);return{cx:(e.minX+e.maxX)/2,cy:(e.minY+e.maxY)/2,scale:je(a)}}function xe(e,t,n){return{...e,cx:e.cx-(n.x-t.x)/e.scale,cy:e.cy+(n.y-t.y)/e.scale}}function Se(e,t){return{...e,cx:t.x,cy:t.y}}function Ce(e,t,n,r){let i=ye(e,t,n),a=je(e.scale*r);return{scale:a,cx:i.x-(n.x-t.width/2)/a,cy:i.y+(n.y-t.height/2)/a}}var H=e=>Math.round(e*1e4)/1e4;function we(e,t){let n=Math.max(0,-Math.floor(Math.log10(t))+2);return Number((Math.round(e/t)*t).toFixed(n))}var Te=(e,t,n=!0)=>H(n?we(e,t):e),Ee=(e,t,n=!0)=>({x:Te(e.x,t,n),y:Te(e.y,t,n)});function De(e,t){let n=e=>(e.maxX-e.minX)*(e.maxY-e.minY);return e.filter(({box:e})=>t.x>=e.minX&&t.x<=e.maxX&&t.y>=e.minY&&t.y<=e.maxY).sort((e,t)=>n(e.box)-n(t.box))}function Oe(e){if(e.length===0)return;let t=e.map(e=>e.x),n=e.map(e=>e.y);return{minX:Math.min(...t),minY:Math.min(...n),maxX:Math.max(...t),maxY:Math.max(...n)}}function ke(e){return Oe(e.flatMap(e=>[{x:e.minX,y:e.minY},{x:e.maxX,y:e.maxY}]))}function Ae(e){let t=[];for(let n of e){let e=t[t.length-1];e&&e.x!==n.x&&e.y!==n.y&&t.push({x:n.x,y:e.y}),e&&e.x===n.x&&e.y===n.y||t.push(n)}return t}function je(e){return Math.min(ve,Math.max(_e,e))}var Me={pcb:{position:[`pcbX`,`pcbY`],rotation:`pcbRotation`,where:``,notePrompt:`Note for the agent, e.g. route ground here`},schematic:{position:[`schX`,`schY`],rotation:`schRotation`,where:` in the schematic`,notePrompt:`Note for the agent, e.g. add a pull-up here`}},Ne={x:0,y:0};function Pe(e,t){let n=new Map(e.circuit.components.map(e=>[e.id,t===`pcb`?e.groupOffset.pcb:e.groupOffset.sch])),r=t===`pcb`?e.pcb.parts:e.schematic.symbols;return new Map(r.map(e=>[e.component,{origin:{x:e.x,y:e.y},group:n.get(e.component)??Ne,autoPlaced:e.autoPlaced}]))}function Fe(e,t,n,r){let i=e.model.parts.find(e=>e.name===n);if(!i)return`This part has no editable source element`;if(t.has(n))return`${n} is locked`;if(!i.editable)return`${n} is read-only (${i.readonlyReason})`;let a=Me[r].position.find(e=>i.props[e]&&!i.props[e]?.editable);return a?`${n}.${a} is an expression; change it in the code`:null}function Ie(e,t,n,r=90){let i=Me[n].rotation,a=e.model.parts.find(e=>e.name===t)?.props[i]?.literal;return a!==void 0&&typeof a!=`number`?`${t}.${i} is not a number`:(((a??0)+r)%360+360)%360}function Le(e,t,n,r){let i=e.model.parts.find(e=>e.name===t)?.props,[a,o]=Me[n].position,s=(e,t,n)=>{let r=i?.[e]?.literal;return typeof r==`number`?r:t-n};return{x:s(a,r.origin.x,r.group.x),y:s(o,r.origin.y,r.group.y)}}function Re(e,t,n,r,i){let a=Le(e,t,n,r);return[H(a.x+i.x),H(a.y+i.y)]}var ze=`Keep auto-placed positions`,Be=`a repeated name cannot be addressed from the Studio`,Ve=e=>Math.round(e*100)/100;function He(e,t){let n=t===`pcb`?e.pcb.parts:e.schematic.symbols;return new Map(n.map(e=>[e.component,e.rotation]))}var Ue=(e,t,n)=>e?.model.parts.find(e=>e.name===t)?.props[Me[n].rotation]!==void 0;function We(e,t,n=()=>null,r){let[i,a]=Me[t].position,o=He(e,t),s=[],c=[];for(let[l,{origin:u,group:d,autoPlaced:f}]of Pe(e,t)){if(!f)continue;let e=l.includes(`~`)?Be:n(l);if(e!==null){c.push({part:l,reason:e});continue}let p=o.get(l)??0,m={[i]:Ve(u.x-d.x),[a]:Ve(u.y-d.y),...p!==0||Ue(r,l,t)?{[Me[t].rotation]:p}:{}};s.push({kind:`setProps`,part:l,props:m})}return{edits:s,skipped:c}}function Ge(e,t){return t.skipped.length===0?e:`${e} Skipped ${t.skipped.map(e=>`${e.part} (${e.reason})`).join(`, `)}.`}function Ke(e){let t=e.edits.length;return Ge(t===0?`No auto-placed part could be kept.`:`Kept the positions of ${t} auto-placed ${t===1?`part`:`parts`}.`,e)}function qe(e,t,n,r){if(e.edits.length===0)return r.notify(n(e));r.edit(e.edits,t).then(t=>{t&&r.notify(n(e))})}function Je(e,t,n,r,i){qe(We(e,t,n,i),ze,Ke,r)}var Ye=`Tidy sheet`,Xe=`Every part on the sheet has a position of its own`,Ze=`The schematic is not built yet`;function Qe(e,t){if(!e)return new Set;let n=t===`pcb`?e.pcb.parts:e.schematic.symbols;return new Set(n.flatMap(e=>e.autoPlaced?[e.component]:[]))}function $e(e){return e?Qe(e,`schematic`).size>0?null:Xe:Ze}var et=(e,t=()=>null,n)=>We(e,`schematic`,t,n);function tt(e){let t=e.edits.length;return Ge(t===0?`Tidied the sheet: no part Studio placed could be written.`:`Tidied the sheet: wrote the positions of ${t} ${t===1?`part`:`parts`} Studio placed.`,e)}function nt(e,t,n,r){let i=$e(e);if(i!==null)return n.notify(i);qe(et(e,t,r),Ye,tt,n)}var rt=/\.sheet\.tsx$/,it=e=>e!==void 0&&rt.test(e),at=e=>(e.split(`/`).pop()??e).replace(rt,``),ot=3;function st(e){return e.length<=1?e[0]??``:e.length>ot?`${e.slice(0,ot).join(`, `)} and ${e.length-ot} more`:`${e.slice(0,-1).join(`, `)} and ${e.at(-1)}`}var ct=e=>e.length>1?[`${e.length} wires`]:[...e],lt=e=>`by ${e}°`;function ut(e,t,n,r,i=90){let{rotation:a,where:o}=Me[n],s=[],c=[];for(let a of t){let t=r(a)??Ie(e,a,n,i);typeof t==`string`?c.push(t):s.push({name:a,to:t})}let l=s.map(e=>e.name),[u]=s,d=s.length===1&&u?`rotate ${u.name}${o} to ${u.to}°`:`rotate ${st(l)}${o} ${lt(i)}`;return{edits:s.map(e=>({kind:`setProps`,part:e.name,props:{[a]:e.to}})),summary:d,parts:l,skipped:c,done:`rotated`}}function dt(e,t,n,r,i,a){let[o,s]=Me[n].position,{where:c}=Me[n],l=t.flatMap(e=>a(e)??[]),u=t.filter(e=>a(e)===null),d=u.map(t=>({name:t,to:Re(e,t,n,r(t),i)})),[f]=d,p=d.length===1&&f?`move ${f.name}${c} to (${f.to[0]}, ${f.to[1]})`:`move ${st(u)}${c} by (${H(i.x)}, ${H(i.y)})`;return{edits:d.map(({name:e,to:t})=>({kind:`setProps`,part:e,props:{[o]:t[0],[s]:t[1]}})),summary:p,parts:u,skipped:l,done:`moved`}}function ft(e,t){return n=>e.get(n)??{origin:t.find(e=>e.name===n)?.center??Ne,group:Ne}}function pt(e,t,n,r=!0){let i=r?t:t/10;return{x:H(e.dx*i*n),y:H(e.dy*i*n)}}function mt(e,t){let n=ke(e);return n?{x:we((n.minX+n.maxX)/2,t),y:we((n.minY+n.maxY)/2,t)}:void 0}function ht(e,t,n=90){let r=n>0?1:-1;return{x:t.x-r*(e.y-t.y),y:t.y+r*(e.x-t.x)}}function gt(e,t,n,r,i,a,o=()=>!0,s=90){if(t.length===1)return ut(e,t,n,a,s);let{rotation:c,position:l,where:u}=Me[n],d=[],f=[],p=[];for(let u of t){if(!o(u)){p.push(`${u} is not in this view`);continue}let t=a(u)??Ie(e,u,n,s);if(typeof t==`string`){p.push(t);continue}let m=r(u),h=m.origin,g=ht(h,i,s),[_,v]=Re(e,u,n,m,{x:g.x-h.x,y:g.y-h.y});d.push({kind:`setProps`,part:u,props:{[l[0]]:_,[l[1]]:v,[c]:t}}),f.push(u)}return{edits:d,summary:`rotate ${st(f)}${u} ${lt(s)}`,parts:f,skipped:p,done:`rotated`}}function _t(e){let t=new Set(e.boxes.map(e=>e.name));return n=>t.has(n)||e.anchors.has(n)}function vt(e,t,n,r,i,a=90){if(t.length===1)return ut(e,t,n,i,a);let o=mt(r.boxes.filter(e=>t.includes(e.name)).map(e=>e.box),r.step);return o?gt(e,t,n,ft(r.anchors,r.boxes),o,i,_t(r),a):{message:`None of the selected parts is in this view.`}}function yt(e,t,n,r,i,a){let o=_t(r),s=t.filter(e=>!o(e)).map(e=>`${e} is not in this view`),c=dt(e,t.filter(o),n,ft(r.anchors,r.boxes),i,a);return{...c,skipped:[...s,...c.skipped]}}function bt(e,t){let n=e.flatMap(e=>t(e)??[]),r=e.filter(e=>t(e)===null);return{edits:r.map(e=>({kind:`removePart`,part:e})),summary:`remove ${st(r)}`,parts:r,skipped:n,done:`removed`}}function xt(e,t=0){let n=e.length===1?`${e[0]} and its connections`:`${e.length} parts (${st(e)}) and their connections`;return t===0?`Remove ${n}?`:`Remove ${n}, and ${t} ${t===1?`wire`:`wires`}?`}function St(e){if(e.skipped.length===0)return;let t=e.skipped.join(`; `);return e.edits.length===0?t:`Not ${e.done}: ${t}`}function Ct(e,t,n,r=new Set){if(e.length===0)return{message:`Select a part first.`};let i=e.filter(e=>n?!t.has(e)||r.has(e):t.has(e));if(i.length>0)return{parts:i};let a=e.length===1?`is`:`are`;return{message:`${st(e)} ${a} ${n?`already locked`:`not locked`}.`}}async function U(e,t){return(await wt(e,t)).ok}async function wt(e,t){let n=St(e);if(e.edits.length===0)return n&&t.notify(n),{ok:!1};let r=t.editMarked?await t.editMarked(e.edits,e.summary):{ok:await t.edit(e.edits,e.summary)};return r.ok&&n&&t.notify(n),r}var Tt={reference:.16,value:.16,"pin-name":.12,"pin-number":.1},Et=.6,Dt=e=>Math.round(e*1e6)/1e6,Ot=(e,t)=>({x:Dt(e),y:Dt(t)}),kt=(...e)=>({type:`polyline`,points:e.map(([e,t])=>Ot(e,t))});function At(e,t,n,r){return{type:`text`,text:e,at:t,anchor:n,size:Tt[r],role:r}}function jt(e){let t=Et*e.size*e.text.length,n=e.anchor===`left`?e.at.x:e.anchor===`right`?e.at.x-t:e.at.x-t/2;return{minX:n,maxX:n+t,minY:e.at.y-e.size/2,maxY:e.at.y+e.size/2}}function Mt(e){if(e.type===`text`)return jt(e);if(e.type===`polyline`){let t=e.points.map(e=>e.x),n=e.points.map(e=>e.y);return{minX:Math.min(...t),maxX:Math.max(...t),minY:Math.min(...n),maxY:Math.max(...n)}}let{center:t,radius:n}=e;return{minX:t.x-n,maxX:t.x+n,minY:t.y-n,maxY:t.y+n}}function Nt(e,t){let n=[...e.map(Mt),...t.map(e=>({minX:e.end.x,maxX:e.end.x,minY:e.end.y,maxY:e.end.y}))];return n.length===0?{minX:0,minY:0,maxX:0,maxY:0}:{minX:Dt(Math.min(...n.map(e=>e.minX))),minY:Dt(Math.min(...n.map(e=>e.minY))),maxX:Dt(Math.max(...n.map(e=>e.maxX))),maxY:Dt(Math.max(...n.map(e=>e.maxY)))}}var Pt=(e,t,n)=>({end:Ot(e,t),side:n});Pt(-.5,0,`left`),Pt(.5,0,`right`),Pt(-.5,0,`left`),Pt(.5,0,`right`),Pt(-.5,0,`left`),Pt(.3,-.5,`bottom`),Pt(.3,.5,`top`);function Ft(){return[kt([0,0],[0,-.1]),kt([-.15,-.1],[.15,-.1]),kt([-.1,-.15],[.1,-.15]),kt([-.05,-.2],[.05,-.2])]}function It(e){return[kt([0,0],[0,.1]),kt([-.1,.1],[.1,.1]),At(e,Ot(0,.2),`center`,`value`)]}var Lt=.16,Rt=Lt*1.5,zt=.66,Bt={right:{x:1,y:0},left:{x:-1,y:0},top:{x:0,y:1},bottom:{x:0,y:-1}};function Vt(e){let t=Bt[e.side],n=e.text.length*Lt*zt+Rt,r=t.x===0,i={x:e.at.x+t.x*n/2,y:e.at.y+t.y*n/2},[a,o]=r?[Rt,n]:[n,Rt];return{middle:i,upright:r,box:{minX:i.x-a/2,minY:i.y-o/2,maxX:i.x+a/2,maxY:i.y+o/2}}}var Ht=/[\w-]+/,Ut=new RegExp(String.raw`^net\.(${Ht.source})$`),Wt=/^([A-Za-z_][\w-]*)\.([\w-]+)$/,Gt=/^\.([A-Za-z_][\w-]*)\s*>\s*\.([\w-]+)$/;function Kt(e){let t=e.trim(),n=Ut.exec(t);if(n?.[1])return{kind:`net`,name:n[1]};let r=Gt.exec(t)??Wt.exec(t);return r?.[1]&&r[2]?{kind:`pin`,part:r[1],pin:r[2]}:void 0}var qt=/^net\.((?:[\w-]+(?:~\d+)?\/)+)([\w-]+)$/;function Jt(e){let t=qt.exec(e.trim());return t?.[1]&&t[2]?{instance:t[1].slice(0,-1),net:t[2]}:void 0}function Yt(e,t){return`${e.instance}/${e.net} is local to instance ${e.instance}; edit ${t??`its sheet file`} and use ${e.net} there`}var Xt={schematicpath:`path`,schematicrect:`rect`,schematiccircle:`circle`,schematicarc:`arc`,schematictext:`text`,bus:`bus`,junction:`junction`},Zt=.04,Qt=[`solid`,`dashed`,`dotted`],$t=[`left`,`center`,`right`];function en(e){return Object.hasOwn(Xt,e)?Xt[e]:void 0}var tn=new RegExp(String.raw`^${Ht.source}$`),nn=new RegExp(String.raw`^(${Ht.source})\[(\d+):(\d+)\]$`);function rn(e){if(tn.test(e))return[e];let t=nn.exec(e);if(!t)return;let[n,r,i]=[t[1],Number(t[2]),Number(t[3])],a=Math.abs(i-r)+1;if(a>1024)return;let o=i>=r?1:-1;return Array.from({length:a},(e,t)=>`${n}${r+t*o}`)}function an(e){let t=e.map(e=>e.x),n=e.map(e=>e.y);return{minX:Math.min(...t),minY:Math.min(...n),maxX:Math.max(...t),maxY:Math.max(...n)}}function on(e,t){let n=t-e;return Math.abs(n)>=360?360:(n%360+360)%360}function sn(e,t,n,r,i){let a=on(r,i),o=[r,r+a];for(let e=Math.ceil(r/90)*90;e<r+a;e+=90)o.push(e);return an(o.map(r=>({x:e+n*Math.cos(r*Math.PI/180),y:t+n*Math.sin(r*Math.PI/180)})))}function cn(e,t,n,r,i){let a=Et*r*n.length,o=i===`left`?e:i===`right`?e-a:e-a/2;return{minX:o,minY:t-r/2,maxX:o+a,maxY:t+r/2}}function ln(e){switch(e.kind){case`path`:case`bus`:return an(e.points);case`rect`:return{minX:e.x,minY:e.y,maxX:e.x+e.width,maxY:e.y+e.height};case`circle`:return{minX:e.x-e.radius,minY:e.y-e.radius,maxX:e.x+e.radius,maxY:e.y+e.radius};case`arc`:return sn(e.x,e.y,e.radius,e.startAngle,e.endAngle);case`text`:return cn(e.x,e.y,e.text,e.fontSize,e.anchor);case`junction`:return{minX:e.x-Zt,minY:e.y-Zt,maxX:e.x+Zt,maxY:e.y+Zt}}}var un=e=>Dt(e)+0;function dn(e){let t=ln(e);return{minX:un(t.minX),minY:un(t.minY),maxX:un(t.maxX),maxY:un(t.maxY)}}var fn=/^[A-Za-z_][\w-]*$/;function pn(e,t,n,r){let i=Jt(n);if(i)return Yt(i,void 0);let a=n.replace(/^net\./,``);return r?rn(a)===void 0?`${e} port ${t} is a bus port and takes a bus name such as "D[0:7]", not "${n}"`:void 0:fn.test(a)?void 0:`${e} port ${t} is a net port and takes a net name such as "VBUS", not "${n}"`}function mn(e,t){let n=new Set(e);for(let r of t??[]){let t=r.path.split(`/`)[0]??r.path;if(e.has(r.path)||e.has(t))for(let e of r.parts)n.add(e)}return n}var hn=e=>e?.circuit.instances??[];function gn(e,t){return hn(e).find(e=>e.path===t&&!e.path.includes(`/`))}function _n(e,t){let n=e?.circuit.components.find(e=>e.id===t);if(n?.instance===void 0)return;let r=hn(e).find(e=>e.path===n.instance);if(!r)return;let i=n.instance.split(`/`)[0]??n.instance;return{part:t,localId:n.localId??t,instance:r.path,outer:i,sheet:r.sheet,file:r.file}}function vn(e,t){return[...hn(e).find(e=>e.path===t)?.parts??[]]}function yn(e,t){return hn(e).filter(e=>e.file===t).length}function bn(e,t){return t===void 0?`In ${e}; every instance of it changes with it`:`In ${e}, used ${t===1?`once`:`${t} times`}`}function xn(e,t){let n=t.flatMap(t=>{let n=gn(e,t);if(n)return[n.path];let r=_n(e,t);return r?[r.outer]:[]});if(n.length!==0)return[...new Set(n)].flatMap(t=>vn(e,t))}function Sn(e,t,n){let r=Object.fromEntries(Object.entries(e.connections).filter(([e])=>e!==t));return n===``?r:{...e.connections,[t]:n}}function Cn(e,t){return mn(e,t?.circuit.instances)}function wn(e,t,n){let r=_n(e,n);if(r)return t.has(r.outer)?`${n} is in ${r.outer}, which is locked`:`${n} is ${r.localId} of ${r.instance}; it is placed in ${r.file}, where every instance of ${at(r.file)} shares it`}var Tn=e=>Math.round(e*1e4)/1e4||0,En=(e,t)=>e.x===t.x&&e.y===t.y;function Dn(e,t,n){return e.x===t.x||e.y===t.y?[t]:[n?{x:e.x,y:t.y}:{x:t.x,y:e.y},t]}function On(e,t=[]){let n=e[0];if(!n)return[];let r=[n];for(let n=1;n<e.length;n++)r.push(...Dn(e[n-1],e[n],t[n-1]===!0));return r}function kn(e){let t=e.map(e=>({x:Tn(e.x),y:Tn(e.y)})),n=[];for(let e of t){let t=n[n.length-1];t&&En(t,e)||n.push(e)}return n.filter((e,t)=>{let[r,i]=[n[t-1],n[t+1]];return!r||!i||!(r.x===e.x&&e.x===i.x||r.y===e.y&&e.y===i.y)})}function An(e,t=[]){return kn(On(e,t))}var jn=.2,Mn=/^[\w-]+$/,Nn=/^[A-Za-z_][\w-]*$/,Pn=/^([A-Za-z_][\w-]*)\.([\w-]+)$/,Fn=/^\.([A-Za-z_][\w-]*)\s*>\s*\.([\w-]+)$/;function In(e,t){let n=e.pinLabels;if(typeof n==`object`&&n)for(let[e,r]of Object.entries(n)){if(!RegExp(`^(?:pin)?${t}$`).test(e))continue;let n=(Array.isArray(r)?r:[r]).find(e=>typeof e==`string`&&e!==``);if(n!==void 0)return n}}function Ln(e,t){let n=e.circuit.components.find(e=>e.id===t.component),r=In(n?.props??{},t.number),i=(n?.pins??[]).filter(e=>e.id!==t.id),a=r!==void 0&&Mn.test(r)&&!i.some(e=>e.names.includes(r));return`${t.component}.${a?r:`pin${t.number}`}`}function Rn(e,t){let n=t.trim(),r=Pn.exec(n)??Fn.exec(n);return(r&&e.circuit.components.find(e=>e.id===r[1]))?.pins.find(e=>e.names.includes(r?.[2]??``))}var zn=e=>e.circuit.components.flatMap(e=>e.pins),Bn=(e,t)=>e.circuit.nets.find(e=>e.pins.includes(t)),Vn=(e,t)=>Math.hypot(e.x-t.x,e.y-t.y);function Hn(e,t,n){let r=Bn(e,t.id)?.names[0],i=Ln(e,t);return{selector:i,at:n,label:i,pin:t.id,...r===void 0?{}:{net:r}}}function Un(e,t){let n=Bn(e,t);return n===void 0||n.pins.length<2&&n.names.length===0}function Wn(e,t,n){for(let r of e.circuit.instances??[]){if(r.path.includes(`/`))continue;let e=r.ports.find(e=>`${r.path}.${e.name}`===t);if(!e)continue;let i=`${r.path}.${e.name}`,a=e.members?{members:e.members}:{};return{selector:`port:${i}`,at:n,label:i,port:{instance:r.path,name:e.name,bus:e.bus===!0,...a}}}}function Gn(e,t,n){let[r,i]=t.port?[t,n]:n.port?[n,t]:[];if(!r?.port||!i)return;let{port:a}=r;if(i.port)return{notice:`Connect ${r.label} and ${i.label} through a named net: wire each to a net label`};let o=(e.circuit.instances??[]).find(e=>e.path===a.instance);if(!o)return{notice:`${a.instance} is gone; wait for the build`};let s=a.bus?qn(a,i):Kn(i);if(s===void 0){let e=a.bus?`a bus with the members ${(a.members??[]).join(`, `)}`:`the net a name first (a net label)`;return{notice:a.bus?`${r.label} is a bus pin; wire it to ${e}`:`Give ${e}, then wire ${r.label} to it`}}let c=pn(o.sheet,a.name,s,a.bus);return c===void 0?{edits:[{kind:`setConnections`,part:o.path,connections:Sn(o,a.name,s)}],summary:`connect ${r.label} to ${s}`}:{notice:c}}var Kn=e=>e.members?void 0:e.selector.startsWith(`net.`)?e.selector.slice(4):e.net;function qn(e,t){let n=e.members??[],r=t.members??[];return r.length===n.length&&n.every(e=>r.includes(e))?t.label:void 0}function Jn(e,t,n){let r;for(let i of e.schematic.symbols)for(let[e,a]of Object.entries(i.pinEnds)){let i=Vn(a,t);i<=n&&(!r||i<r.d)&&(r={pin:e,at:a,d:i})}return r&&{pin:r.pin,at:r.at}}function Yn(e,t,n,r={}){let i=Jn(e,t,n),a=i&&zn(e).find(e=>e.id===i.pin);return i&&a?Hn(e,a,i.at):i&&Wn(e,i.pin,i.at)||(nr(e,t,n)??er(e,t,n,r)??ir(e,t,n,r))}function Xn(e,t){let n;for(let r=1;r<e.length;r++){let[i,a]=[e[r-1],e[r]];if(!i||!a)continue;let o=or(t,i,a),s=Vn(o,t);(!n||s<n.d)&&(n={at:o,d:s,a:i,b:a})}return n}var Zn=e=>Math.round(e*1e4)/1e4||0;function Qn(e,t,n,r,i,a){let o=e=>e>=n[0]&&e<=n[1];if(i!==void 0&&Math.abs(t-i)<=r&&o(i))return i;if(!a.snap||!a.step)return e;let s=Zn(Math.round(e/a.step)*a.step);return o(s)?s:e}function $n(e,t,n,r){let{a:i,b:a,at:o}=e,s=i.y===a.y&&i.x!==a.x?`x`:i.x===a.x&&i.y!==a.y?`y`:void 0;if(!s)return o;let c=Qn(o[s],t[s],[Math.min(i[s],a[s]),Math.max(i[s],a[s])],n,r.from?.[s],r);return s===`x`?{x:c,y:i.y}:{x:i.x,y:c}}function er(e,t,n,r){let i;for(let r of e.schematic.drawings){if(r.kind!==`bus`)continue;let e=Xn(r.points,t);e&&e.d<=n&&(!i||e.d<i.near.d)&&(i={id:r.id,name:r.name,members:r.members,near:e})}let a=i&&$n(i.near,t,n,r);return i&&a&&{selector:`bus:${i.id}`,at:{x:Zn(a.x),y:Zn(a.y)},label:i.name,members:i.members}}function tr(e,t){return{selector:`net.${t}`,at:e.at,label:t,net:t}}function nr(e,t,n){let r;for(let i of e.schematic.labels){let a=e.circuit.nets.find(e=>e.id===i.net),o=a?.names.includes(i.text)?i.text:a?.names[0],s=rr(i,t);o!==void 0&&s<=n&&(!r||s<r.d)&&(r={name:o,at:i.at,d:s})}return r&&{selector:`net.${r.name}`,at:r.at,label:r.name,net:r.name}}function rr(e,t){if(e.style!==`label`)return Math.max(Vn(e.at,t)-jn,0);let{box:n}=Vt(e);return Math.hypot(Math.max(n.minX-t.x,0,t.x-n.maxX),Math.max(n.minY-t.y,0,t.y-n.maxY))}function ir(e,t,n,r){let i;for(let r of e.schematic.wires){let e=Xn(r.points,t);e&&e.d<=n&&(!i||e.d<i.near.d)&&(i={net:r.net,near:e})}return i&&ar(e,i.net,$n(i.near,t,n,r))}function ar(e,t,n){let r=e.circuit.nets.find(e=>e.id===t),i=r?.names[0];if(i!==void 0)return{selector:`net.${i}`,at:n,label:i,net:i};let a=r?.pins[0]??(t.startsWith(`net:`)?t.slice(4):void 0),o=zn(e).find(e=>e.id===a);return o?{selector:Ln(e,o),at:n,label:Ln(e,o),pin:o.id}:void 0}function or(e,t,n){let r=n.x-t.x,i=n.y-t.y,a=r*r+i*i,o=a===0?0:Math.max(0,Math.min(1,((e.x-t.x)*r+(e.y-t.y)*i)/a));return{x:t.x+o*r,y:t.y+o*i}}function sr(e,t){if(t.pin!==void 0)return Bn(e,t.pin);let{selector:n}=t;if(n.startsWith(`net.`))return e.circuit.nets.find(e=>e.names.includes(n.slice(4)));let r=zn(e).find(t=>Ln(e,t)===n);return r&&Bn(e,r.id)}function cr(e,t){return e.selector===t.selector||e.pin!==void 0&&e.pin===t.pin}function lr(e,t,n){let[r,i]=[sr(e,t),sr(e,n)],[a,o]=[ur(t,r),ur(n,i)];if(r&&i&&r.id!==i.id&&a!==void 0&&o!==void 0)return[a,o]}var ur=(e,t)=>e.selector.startsWith(`net.`)?e.selector.slice(4):t?.names[0];function dr(e){let t=e.startsWith(`net.`)?void 0:e.split(`.`)[0];return t===void 0||Nn.test(t)&&!t.includes(`~`)}var fr=e=>e.selector.startsWith(`net.`);function pr(e,t,n,r=[]){let i=An([e.at,...n,t.at],r);return i.slice(+!fr(e),fr(t)?i.length:i.length-1)}function mr(e,t,n,r,i=[]){if(t.members||n.members||!dr(t.selector)||!dr(n.selector))return[];let[a,o]=[sr(e,t),sr(e,n)];if(cr(t,n)||a!==void 0&&a.id===o?.id)return[];let s=pr(t,n,r,i);return[{kind:`addTrace`,from:t.selector,to:n.selector,...s.length>0?{schematicRouteHints:s}:{}}]}var hr=/^net\.([\w-]+)$/,gr=new Set;function _r(e,t,n){return`pin`in n?t!==void 0&&Rn(e,t)?.id===n.pin:n.net.includes(hr.exec(t?.trim()??``)?.[1]??``)}function vr(e,t,n,r){return t.model.traces.filter(t=>_r(e,t.from,n)&&_r(e,t.to,r)||_r(e,t.from,r)&&_r(e,t.to,n))}function yr(e,t){return e[Number(/#(\d+)$/.exec(t??``)?.[1]??1)-1]??e[0]}function br(e){if(!e.editable)return`This wire is read-only (${e.readonlyReason}); change it in the code`;if(e.props.schematicRouteHints&&!e.schematicRouteHints)return`The corners of this wire are an expression; change them in the code`}function xr(e,t,n,r){let i=[n?.from,n?.to].flatMap(t=>t===void 0?[]:[Rn(e,t)?.component??``]);return[...t,...i].find(e=>r.has(e))}function Sr(e,t){return e.circuit.nets.find(e=>e.id===t)?.names??[t.replace(/^net\./,``)]}function Cr(e,t){let n=e.model.traces.find(e=>e.from===t.from&&e.to===t.to||e.from===t.to&&e.to===t.from);return n!==void 0&&n.start!==t.start?`This wire repeats another between the same ends; change its corners in the code`:void 0}var wr=.1,Tr=e=>Math.round(e*1e3)/1e3||0;function Er(e){if(e.style===`label`)return Vt(e).box;let t=Nt(e.style===`ground`?Ft():It(e.text),[]);return{minX:e.at.x+t.minX,minY:e.at.y+t.minY,maxX:e.at.x+t.maxX,maxY:e.at.y+t.maxY}}function Dr(e){let t=Er(e);return e.style===`label`?t:{minX:t.minX-wr,minY:t.minY-wr,maxX:t.maxX+wr,maxY:t.maxY+wr}}var Or=(e,t)=>t.x>=e.minX&&t.x<=e.maxX&&t.y>=e.minY&&t.y<=e.maxY,kr=e=>(e.maxX-e.minX)*(e.maxY-e.minY);function Ar(e,t){return e.schematic.labels.map(e=>({label:e,box:Dr(e)})).filter(({box:e})=>Or(e,t)).sort((e,t)=>kr(e.box)-kr(t.box))[0]?.label}function jr(e,t){return e.schematic.symbols.find(e=>e.pinEnds[t])?.pinEnds[t]}function Mr(e,t){let n=e.schematic.labels.find(e=>e.id===t);if(!n)return;let r=e.circuit.connections.find(e=>`label:${e.id}`===n.id),i=`label:${n.net}:`,a=r?[r.from,r.to].find(e=>!e.startsWith(`net.`)):n.id.startsWith(i)?n.id.slice(i.length):void 0,o=e.circuit.components.flatMap(e=>e.pins).find(e=>e.id===a),s=o&&jr(e,o.id);return o&&s?{label:n,pin:o,end:s,...r?{connection:r}:{}}:void 0}function Nr(e,t){let n=Mr(e,t);return n&&{part:n.pin.component,...n.connection?{wire:`wire:${n.connection.id}`}:{}}}function Pr(e,t){let n=Mr(e,t);return n&&`${n.label.net}|${n.pin.id}`}function Fr(e){return`the ${e.text} ${e.style===`label`?`label`:`flag`}`}function Ir(e){let t=e.connection?.corners??[];return e.connection?.from===e.pin.id?t:[...t].reverse()}function Lr(e,t){if(e.connection&&t.x===e.end.x&&t.y===e.end.y)return[];let n=e.connection?Ir(e).slice(0,-1):[],r=n[n.length-1]??e.end;return[...n,...Ae([r,t]).slice(1)]}var Rr=(e,t)=>e.length===t.length&&e.every((e,n)=>e.x===t[n]?.x&&e.y===t[n]?.y),zr=e=>({x:Tr(e.x),y:Tr(e.y)});function Br(e,t){return e?t.x===e.x?t.y<e.y?`bottom`:`top`:t.x>e.x?`right`:`left`:`right`}function Vr(e,t,n){let r=Mr(e,t);if(!r)return;let i=zr(n),a=[r.end,...Lr(r,i)];return{at:i,side:Br(a[a.length-2],i),wire:a,...r.connection?{hideWire:`wire:${r.connection.id}`}:{}}}function Hr(e,t,n){return yr(vr(e,t,{pin:n.pin.id},{net:Sr(e,n.label.net)}),n.connection?.id)}function Ur(e,t,n,r){let i=Mr(e,n);if(!i)return{blocked:`This label is not attached to a pin the Studio can find`};let a=Hr(e,t,i),o=xr(e,[i.pin.component],a,r);if(o!==void 0)return{blocked:`${o} is locked`};let s=a?Cr(t,a)??br(a):void 0;return s?{blocked:s}:!a&&i.connection?{blocked:`The wire of this label is not written in a trace the Studio can find`}:!a&&!dr(Ln(e,i.pin))?{blocked:`${i.pin.id} has a repeated name and cannot be wired from the Studio`}:a?{anchor:i,trace:a}:{anchor:i}}function Wr(e,t,n,r=gr){let i=Ur(e,t,n,r);return`blocked`in i?i.blocked:null}function Gr(e,t){let n=Sr(e,t.net);return`net.${n.includes(t.text)?t.text:n[0]??t.text}`}function Kr(e,t,n,r,i=gr){let a=Ur(e,t,n,i);if(`blocked`in a)return a;let{anchor:o,trace:s}=a,c=Lr(o,zr(r)).map(zr);if(Rr(c,o.connection?Ir(o):[]))return[];if(!s)return[{kind:`addTrace`,from:Ln(e,o.pin),to:Gr(e,o.label),schematicRouteHints:c}];let l=s.from!==void 0&&Rn(e,s.from)?.id===o.pin.id;return[{kind:`setTraceHints`,from:s.from??``,to:s.to??``,schematicRouteHints:l?c:[...c].reverse()}]}var qr=new Intl.Collator(`en`,{numeric:!0});function Jr(e,t){let n=Array.from(e,e=>e.codePointAt(0)),r=Array.from(t,e=>e.codePointAt(0));for(let e=0;e<Math.min(n.length,r.length);e++){let t=n[e]-r[e];if(t!==0)return t}return n.length-r.length}function Yr(e,t){return qr.compare(e,t)||Jr(e,t)}function Xr(e){return[...e].sort(Yr)}function Zr(e,t,n,r,i){let a={code:e,severity:t,message:n,items:Xr(r)};return i?{...a,source:i}:a}var Qr=/^([+-]?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?)\s*(mm|in|mil)?$/i,$r={mm:1,in:25.4,mil:.0254};function ei(e){if(typeof e==`number`)return Number.isFinite(e)?e:void 0;if(typeof e!=`string`)return;let t=Qr.exec(e.trim());if(!t)return;let n=Number(t[1])*($r[(t[2]??`mm`).toLowerCase()]??1);return Number.isFinite(n)?n:void 0}function ti(e){return e!==void 0&&e.outline.length>=3}var ni=Math.PI/180,ri=1e-12;function ii(e,t){let n=Math.cos(t.rotation*ni),r=Math.sin(t.rotation*ni);return{x:t.x+e.x*n-e.y*r,y:t.y+e.x*r+e.y*n}}function ai(e,t,n){return t<=ri&&n<=ri?[ii({x:0,y:0},e)]:n<=ri?[ii({x:-t,y:0},e),ii({x:t,y:0},e)]:t<=ri?[ii({x:0,y:-n},e),ii({x:0,y:n},e)]:[{x:-t,y:-n},{x:t,y:-n},{x:t,y:n},{x:-t,y:n}].map(t=>ii(t,e))}function oi(e,t,n){let r=Math.min(t,n),i=(Math.max(t,n)-r)/2;return{core:t>=n?ai(e,i,0):ai(e,0,i),radius:r/2}}function si(e){switch(e.shape){case`rect`:return{core:ai(e,e.width/2,e.height/2),radius:0};case`roundrect`:{let t=Math.min(Math.max(e.cornerRadius??0,0),e.width/2,e.height/2);return{core:ai(e,e.width/2-t,e.height/2-t),radius:t}}case`circle`:return{core:[ii({x:0,y:0},e)],radius:e.width/2};case`oval`:return oi(e,e.width,e.height);default:return}}function ci(e,t){return{x:e.x-t.x,y:e.y-t.y}}function li(e,t){return e.x*t.y-e.y*t.x}function ui(e,t,n){let r=ci(n,t),i=r.x*r.x+r.y*r.y,a=i===0?0:Math.max(0,Math.min(1,((e.x-t.x)*r.x+(e.y-t.y)*r.y)/i)),o={x:t.x+r.x*a,y:t.y+r.y*a};return{distance:Math.hypot(e.x-o.x,e.y-o.y),at:o}}function di(e,t,n,r){let i=ci(t,e),a=ci(r,n),o=li(i,a);if(o===0)return;let s=li(ci(n,e),a)/o,c=li(ci(n,e),i)/o;if(!(s<0||s>1||c<0||c>1))return{x:e.x+i.x*s,y:e.y+i.y*s}}function fi(e,t,n,r){let i=di(e,t,n,r);if(i!==void 0)return{distance:0,from:i,to:i};let a=[];for(let i of[e,t]){let e=ui(i,n,r);a.push({distance:e.distance,from:i,to:e.at})}for(let i of[n,r]){let n=ui(i,e,t);a.push({distance:n.distance,from:n.at,to:i})}return a.reduce((e,t)=>t.distance<e.distance?t:e)}function pi(e){return e.length===1?[[e[0],e[0]]]:e.length===2?[[e[0],e[1]]]:e.map((t,n)=>[t,e[(n+1)%e.length]])}function mi(e,t){let n=!1;for(let r=0,i=t.length-1;r<t.length;i=r++){let a=t[r],o=t[i];a.y>e.y!=o.y>e.y&&e.x<(o.x-a.x)*(e.y-a.y)/(o.y-a.y)+a.x&&(n=!n)}return n}function hi(e,t){if(!(e.length<3))return t.find(t=>mi(t,e))}function gi(e,t){let n=hi(e,t)??hi(t,e);if(n!==void 0)return{distance:0,from:n,to:n};let r;for(let[n,i]of pi(e))for(let[e,a]of pi(t)){let t=fi(n,i,e,a);(r===void 0||t.distance<r.distance)&&(r=t)}return r}function _i(e,t){return gi(e.core,t.core).distance-e.radius-t.radius}function vi(e,t,n){let r=Math.hypot(t.x-e.x,t.y-e.y);return r===0?e:{x:e.x+(t.x-e.x)/r*n,y:e.y+(t.y-e.y)/r*n}}function yi(e,t){let{from:n,to:r}=gi(e.core,t.core);return[vi(n,r,e.radius),vi(r,n,t.radius)]}function bi(e){let t=e.core.map(e=>e.x),n=e.core.map(e=>e.y);return{minX:Math.min(...t)-e.radius,minY:Math.min(...n)-e.radius,maxX:Math.max(...t)+e.radius,maxY:Math.max(...n)+e.radius}}var xi={A:`0,0 0,4 2,6 4,4 4,0;0,3 4,3`,B:`0,0 0,6 3,6 4,5 4,4 3,3 0,3;3,3 4,2 4,1 3,0 0,0`,C:`4,1 3,0 1,0 0,1 0,5 1,6 3,6 4,5`,D:`0,0 0,6 3,6 4,5 4,1 3,0 0,0`,E:`4,0 0,0 0,6 4,6;0,3 3,3`,F:`0,0 0,6 4,6;0,3 3,3`,G:`4,5 3,6 1,6 0,5 0,1 1,0 3,0 4,1 4,3 2,3`,H:`0,0 0,6;4,0 4,6;0,3 4,3`,I:`1,0 3,0;2,0 2,6;1,6 3,6`,J:`0,1 1,0 2,0 3,1 3,6;2,6 4,6`,K:`0,0 0,6;4,6 0,2;1,3 4,0`,L:`0,6 0,0 4,0`,M:`0,0 0,6 2,3 4,6 4,0`,N:`0,0 0,6 4,0 4,6`,O:`1,0 0,1 0,5 1,6 3,6 4,5 4,1 3,0 1,0`,P:`0,0 0,6 3,6 4,5 4,4 3,3 0,3`,Q:`1,0 0,1 0,5 1,6 3,6 4,5 4,1 3,0 1,0;2,2 4,0`,R:`0,0 0,6 3,6 4,5 4,4 3,3 0,3;2,3 4,0`,S:`4,5 3,6 1,6 0,5 0,4 1,3 3,3 4,2 4,1 3,0 1,0 0,1`,T:`0,6 4,6;2,6 2,0`,U:`0,6 0,1 1,0 3,0 4,1 4,6`,V:`0,6 2,0 4,6`,W:`0,6 1,0 2,3 3,0 4,6`,X:`0,0 4,6;0,6 4,0`,Y:`0,6 2,3 4,6;2,3 2,0`,Z:`0,6 4,6 0,0 4,0`,0:`1,0 0,1 0,5 1,6 3,6 4,5 4,1 3,0 1,0;0,1 4,5`,1:`1,5 2,6 2,0;1,0 3,0`,2:`0,5 1,6 3,6 4,5 4,4 0,0 4,0`,3:`0,5 1,6 3,6 4,5 4,4 3,3 4,2 4,1 3,0 1,0 0,1;1,3 3,3`,4:`3,0 3,6 0,2 4,2`,5:`4,6 0,6 0,3 3,3 4,2 4,1 3,0 1,0 0,1`,6:`4,5 3,6 1,6 0,5 0,1 1,0 3,0 4,1 4,2 3,3 0,3`,7:`0,6 4,6 1,0`,8:`1,3 0,4 0,5 1,6 3,6 4,5 4,4 3,3 1,3 0,2 0,1 1,0 3,0 4,1 4,2 3,3`,9:`0,1 1,0 3,0 4,1 4,5 3,6 1,6 0,5 0,4 1,3 4,3`,"-":`1,3 3,3`,_:`0,0 4,0`,"+":`2,1 2,5;0,3 4,3`,".":`2,0 2,0`,"/":`0,0 4,6`,"~":`0,3 1,4 3,2 4,3`,"(":`3,6 2,5 2,1 3,0`,")":`1,6 2,5 2,1 1,0`,"#":`1,0 1,6;3,0 3,6;0,2 4,2;0,4 4,4`," ":``},Si=`0,0 4,0 4,6 0,6 0,0`,Ci=4,wi=6,Ti=6;function Ei(e){let t=xi[e.toUpperCase()]??Si;return t===``?[]:t.split(`;`).map(e=>e.split(` `).map(e=>{let[t,n]=e.split(`,`).map(Number);return{x:t??0,y:n??0}}))}function Di(e,t){let n=[...e].length;return n===0?0:((n-1)*Ti+Ci)*t/wi}function Oi(e,t,n,r=!1,i=!1){let a=n/wi,o=[...e],s=Di(e,wi),c=r?-1:1;return o.flatMap((e,n)=>Ei(e).map(e=>e.map(e=>{let r=c*(n*Ti+e.x-s/2)*a,o=(e.y-wi/2)*a;return i?{x:t.x-o,y:t.y+r}:{x:t.x+r,y:t.y+o}})))}var ki=.15,Ai=[0,.4,.8,1.2,1.6],ji=.5,Mi=4,Ni=2,Pi={pad:100,hole:100,via:50,designator:100,courtyard:2,edge:1e3},Fi=(e,t)=>e.minX<t.maxX&&t.minX<e.maxX&&e.minY<t.maxY&&t.minY<e.maxY,Ii=(e,t)=>Math.max(0,Math.min(e.maxX,t.maxX)-Math.max(e.minX,t.minX))*Math.max(0,Math.min(e.maxY,t.maxY)-Math.max(e.minY,t.minY)),Li=(e,t)=>({minX:Math.min(e.minX,t.minX),minY:Math.min(e.minY,t.minY),maxX:Math.max(e.maxX,t.maxX),maxY:Math.max(e.maxY,t.maxY)}),Ri=(e,t)=>({minX:e.minX-t,minY:e.minY-t,maxX:e.maxX+t,maxY:e.maxY+t});function zi(e,t,n=0){let r=Di(e,1)/2+ki/2,i=.575,[a,o]=n===90?[i,r]:[r,i];return{minX:t.x-a,minY:t.y-o,maxX:t.x+a,maxY:t.y+o}}function Bi(e,t){let n=e.rotation*Math.PI/180,[r,i]=[Math.abs(Math.cos(n)),Math.abs(Math.sin(n))],[a,o]=[e.width/2+t,e.height/2+t],[s,c]=e.shape===`circle`?[a,a]:[a*r+o*i,a*i+o*r];return{minX:e.x-s,minY:e.y-c,maxX:e.x+s,maxY:e.y+c}}function Vi(e){let t=e.map(e=>e.x),n=e.map(e=>e.y);return{minX:Math.min(...t),minY:Math.min(...n),maxX:Math.max(...t),maxY:Math.max(...n)}}function Hi(e,t){let n=Math.abs(e-t),r=Math.max(e,n),i=Math.max(ji,r/Mi),a=[0,n,e,...Array.from({length:Math.floor(r/i)},(e,t)=>(t+1)*i)].flatMap(e=>[-e,e]).map(e=>Math.round(e*1e6)/1e6+0);return[...new Set(a)]}function Ui(e,t,n){return n===void 0?[...Wi(e,t,e=>e?0:90),...Wi(e,t,e=>e?90:0)]:Wi(e,t,()=>n)}function Wi(e,t,n){if(e.courtyard.length===0)return[{at:{x:e.x,y:e.y},rotation:n(!0)}];let r=Vi(e.courtyard),[i,a]=[(r.minX+r.maxX)/2,(r.minY+r.maxY)/2],[o,s]=[(r.maxX-r.minX)/2,(r.maxY-r.minY)/2],c=Di(e.component,1)/2+ki/2,l=.575,u=[],d={flat:Hi(o,n(!0)===0?c:l),upright:Hi(s,n(!1)===0?l:c)};for(let e of Ai){let o=t+e;for(let e of[`top`,`bottom`,`left`,`right`]){let t=e===`top`||e===`bottom`,s=n(t),[f,p]=s===0===t?[c,l]:[l,c];if(t){let t=e===`top`,n=t?r.maxY+o+p:r.minY-o-p,[a,c]=t?[r.maxY,n+p]:[n-p,r.minY];for(let e of d.flat)u.push({at:{x:i+e,y:n},rotation:s,reach:{minX:i+e-f,maxX:i+e+f,minY:a,maxY:c}})}else{let t=e===`right`,n=t?r.maxX+o+p:r.minX-o-p,[i,c]=t?[r.maxX,n+p]:[n-p,r.minX];for(let e of d.upright)u.push({at:{x:n,y:a+e},rotation:s,reach:{minX:i,maxX:c,minY:a+e-f,maxY:a+e+f}})}}}let f=e=>Math.round(Math.hypot(e.at.x-i,e.at.y-a)*1e3);return u.map((e,t)=>({place:e,i:t,d:f(e)})).sort((e,t)=>e.d-t.d||e.i-t.i).map(e=>e.place)}var Gi=class{outline;clearance;fixedIndex=new Ki;textIndex=new Ki;designators=new Map;keptOf=new WeakMap;constructor(e,t){this.outline=e,this.clearance=t}add(e,t,n,r){let i={kind:e,component:t,side:n,box:r};e===`designator`?(this.remove(t),this.designators.set(t,i),this.textIndex.insert(i,r)):this.fixedIndex.insert(i,r)}remove(e){let t=this.designators.get(e);t&&(t.gone=!0),this.designators.delete(e)}covered(e,t,n=!0){let{near:r,fixed:i}=n?this.kept(e,t):this.measured(e,t,!1);if(this.designators.size===0)return i;let a;for(let t of this.textIndex.query(r))!t.gone&&t.side===e.side&&t.component!==e.component&&Fi(r,t.box)&&(a??={...i,designators:[]},a.score+=Pi.designator*(1+Ii(r,t.box)),a.designators.push(t.component));return a??i}kept(e,t){let n=this.keptOf.get(t);if(n)return n;let r=this.measured(e,t,!0);return this.keptOf.set(t,r),r}measured(e,t,n){let r=zi(e.component,t.at,t.rotation);return{near:n?Ri(r,this.clearance):r,fixed:this.fixedCovered(e,t,r,n)}}fixedCovered(e,t,n,r){let i=t.reach??n,a={pads:[],designators:[],courtyards:[],vias:!1,holes:!1,edge:!1,score:0,fixed:0,between:0};for(let t of this.fixedIndex.query(r?Li(n,i):n)){if(t.side!==`both`&&t.side!==e.side||t.component===e.component&&t.kind!==`pad`)continue;let o=t.kind===`courtyard`&&r&&!Fi(n,t.box)&&Fi(i,t.box);if(!o&&!Fi(n,t.box))continue;let s=Ii(n,t.box),c=o?1:Pi[t.kind]*(t.kind===`courtyard`?Math.max(s,.001):1+s);a.score+=c,o?a.between+=1:a.fixed+=c,o||(t.kind===`pad`?a.pads.push(t.component):t.kind===`courtyard`?a.courtyards.push(t.component):t.kind===`via`?a.vias=!0:a.holes=!0)}return this.outline&&!qi(n,this.outline)&&(a.edge=!0,a.score+=Pi.edge,a.fixed+=Pi.edge),a}},Ki=class e{cells=new Map;stamp=0;static key(e,t){return(e+32768)*65536+(t+32768)}insert(t,n){for(let r=Math.floor(n.minX/Ni);r<=Math.floor(n.maxX/Ni);r++)for(let i=Math.floor(n.minY/Ni);i<=Math.floor(n.maxY/Ni);i++){let n=e.key(r,i),a=this.cells.get(n);a?a.push(t):this.cells.set(n,[t])}}query(t){let n=++this.stamp,r=[];for(let i=Math.floor(t.minX/Ni);i<=Math.floor(t.maxX/Ni);i++)for(let a=Math.floor(t.minY/Ni);a<=Math.floor(t.maxY/Ni);a++)for(let t of this.cells.get(e.key(i,a))??[])t.seen!==n&&(t.seen=n,r.push(t));return r}};function qi(e,t){return[{x:e.minX,y:e.minY},{x:e.maxX,y:e.minY},{x:e.maxX,y:e.maxY},{x:e.minX,y:e.maxY}].every(e=>mi(e,t))?!t.some(t=>t.x>e.minX&&t.x<e.maxX&&t.y>e.minY&&t.y<e.maxY):!1}var Ji=.15,Yi=e=>[...new Set(e)].sort(Yr),Xi=e=>(Math.round(e)%360+360)%360;function Zi(e,t,n){let r=new Gi(ti(e.board)?e.board?.outline:void 0,n);for(let n of e.parts){for(let e of n.pads)r.add(`pad`,n.component,e.layers===`through`?`both`:e.layers,Bi(e,t));n.courtyard.length>0&&r.add(`courtyard`,n.component,n.side,Vi(n.courtyard))}for(let t of e.vias??[]){let e=t.diameter/2;r.add(`via`,``,`both`,{minX:t.at.x-e,minY:t.at.y-e,maxX:t.at.x+e,maxY:t.at.y+e})}for(let t of e.holes??[]){let e=t.diameter/2;r.add(`hole`,``,`both`,{minX:t.x-e,minY:t.y-e,maxX:t.x+e,maxY:t.y+e})}return r}function Qi(e){let t=new Map;for(let n of e){if(n.copyOf===void 0)continue;let e=`${n.copyOf}@${Xi(n.rotation)}${n.side}`;t.set(e,[...t.get(e)??[],n])}return t}function $i(e,t,n=Ji){let r=`${t}/${n}`,i=ta(e,r);if(i)return i;let a=aa(e,t,n);return na(e,r,a),a}var ea=new WeakMap;function ta(e,t){let n=e.parts[0],r=n&&ea.get(n);if(r&&r.key===t&&r.vias===e.vias&&r.holes===e.holes&&r.board===e.board&&r.parts.length===e.parts.length){for(let t=0;t<r.parts.length;t++)if(r.parts[t]!==e.parts[t])return;return r.placements}}function na(e,t,n){let r=e.parts[0];r&&ea.set(r,{key:t,parts:e.parts,vias:e.vias,holes:e.holes,board:e.board,placements:n})}function ra(e,t){let n;for(let r of e){let e=t(r);if(e.score===0)return r;n===void 0&&e.score===e.between*1&&(n=r)}return n}function ia(e,t,n){let[r,i]=[0,0];for(let e of t){let t=n(e);if(t.score===0&&r++,t.score===t.between*1&&i++,r>=ca)break}return{clear:r,fair:i}}function aa(e,t,n){let r=e.parts.filter(e=>e.component!==``),i=Zi(e,t,n),a=new Map,o=(e,t)=>{a.set(e.component,t),i.add(`designator`,e.component,e.side,zi(e.component,t.at,t.rotation))},s=new Map,c=e=>{let t=s.get(e.component);if(t)return t;let r=Ui(e,n,e.nameRotation);return s.set(e.component,r),r},l=(e,t)=>i.covered(e,t).score===0,u=(e,t)=>{let n=i.covered(e,t);return n.score===n.between*1},d=e=>{let t=c(e),n=ra(t,t=>i.covered(e,t));if(n)return n;let r={place:t[0],score:1/0};for(let n of t){let t=i.covered(e,n).score;t<r.score&&(r={place:n,score:t})}return r.place};for(let e of r)e.nameAt&&o(e,{at:e.nameAt,rotation:e.nameRotation??0});let f=new Map(r.filter(e=>!e.nameAt).map(e=>[e.component,ia(e,c(e),t=>i.covered(e,t))])),p=oa(r.filter(e=>!e.nameAt),e=>f.get(e.component)??{clear:0,fair:0});for(let e of p)e.length>1?fa(e,c,l,d,o):o(e[0],d(e[0]));return ua(r,a,{tries:c,clear:l,fair:u,settle:o,covered:(e,t)=>i.covered(e,t),remove:e=>i.remove(e.component)}),r.map(e=>{let t=a.get(e.component),n=i.covered(e,t,!1);return{component:e.component,side:e.side,at:t.at,rotation:t.rotation,coversPads:Yi(n.pads),coversDesignators:Yi(n.designators),coversParts:Yi(n.courtyards),offBoard:n.edge}})}function oa(e,t){let n=e=>t(e).clear>0?0:t(e).fair>0?1:2,r=e=>[t(e).clear,t(e).fair,0][n(e)],i=new Map([...Qi(e).values()].flatMap(e=>e.map(t=>[t.component,e]))),a=[],o=new Set;for(let t of e){if(o.has(t.component))continue;let e=i.get(t.component)??[t];e.forEach(e=>o.add(e.component));let r=e.filter(e=>n(e)===0);r.length>0&&a.push(r),a.push(...e.filter(e=>n(e)>0).map(e=>[e]))}let s=e=>({tier:Math.max(...e.map(n)),size:Math.min(...e.map(r))});return a.map((e,t)=>({members:e,i:t,...s(e)})).sort((e,t)=>e.tier-t.tier||e.size-t.size||e.i-t.i).map(e=>e.members)}var sa=4,ca=12,la=2;function ua(e,t,n){let r=new Map(e.map(e=>[e.component,e])),i=new Set(e.filter(e=>e.nameAt).map(e=>e.component));for(let a=0;a<la;a++){let a=!1;for(let o of e){let e=t.get(o.component);if(i.has(o.component)||n.clear(o,e))continue;let s=n.fair(o,e);n.remove(o);let c=ra(n.tries(o),e=>n.covered(o,e)),l=c&&(n.clear(o,c)||!s)?c:void 0,u=[];for(let e of l?[]:n.tries(o)){let t=n.covered(o,e);if(t.fixed!==0||t.between!==0&&s||t.designators.some(e=>i.has(e))||u.push(e),u.length>=sa)break}l&&n.settle(o,l);let d=l!==void 0||u.some(e=>da(o,e,r,t,n));d||n.settle(o,e),a||=d}if(!a)return}}function da(e,t,n,r,i){let a=Yi(i.covered(e,t).designators).map(e=>n.get(e)),o=a.map(e=>[e,r.get(e.component)]);a.forEach(i.remove),i.settle(e,t);let s=[];for(let e of a){let t=ra(i.tries(e),t=>i.covered(e,t));if(!t)break;i.settle(e,t),s.push(e)}return s.length===a.length||(s.forEach(i.remove),i.remove(e),o.forEach(([e,t])=>i.settle(e,t)),!1)}function fa(e,t,n,r,i){let a=e.map(t),o=Math.min(...a.map(e=>e.length)),s=t=>e.every((e,r)=>n(e,a[r]?.[t]))&&pa(e,a,t);for(let t=0;t<o;t++)if(s(t)){e.forEach((e,n)=>i(e,a[n]?.[t]));return}let c={index:-1,clear:0};for(let t=0;t<o;t++){let r=e.filter((e,r)=>n(e,a[r]?.[t])).length;r>c.clear&&(c={index:t,clear:r})}let l=[];e.forEach((e,t)=>{let r=c.index>=0?a[t]?.[c.index]:void 0;r&&n(e,r)?i(e,r):l.push(e)}),l.forEach(e=>i(e,r(e)))}function pa(e,t,n){let r=e.map((e,r)=>{let i=t[r]?.[n];return zi(e.component,i.at,i.rotation)});return r.every((e,t)=>r.every((n,r)=>r<=t||!(e.minX<n.maxX&&n.minX<e.maxX&&e.minY<n.maxY&&n.minY<e.maxY)))}var ma=e=>e.minSilkToPad??.15,ha=e=>e.nameAt??e.designatorAt??Ui(e,.15,0).find(t=>t.at.y>e.y)?.at??{x:e.x,y:e.y},ga=e=>(e.nameAt?e.nameRotation:void 0)??e.designatorRotation??e.nameRotation??0,_a=.3,va=.5,ya=`"Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", sans-serif`,ba=`"Cascadia Mono", "JetBrains Mono", ui-monospace, Consolas, monospace`,xa={strong:600,regular:400},Sa=(e,t,n=ya)=>`${e} ${t}px ${n}`,W={background:`#000000`,boardEdge:`#ff00ff`,topCopper:`#ff0000`,bottomCopper:`#0000ff`,inner1Copper:`#cc9933`,inner2Copper:`#9966cc`,multiLayer:`#c0c0c0`,viaRing:`#c0c0c0`,highlight:`#ffffff`,drill:`#222222`,topSilk:`#ffcc00`,bottomSilk:`#66cc33`,topAssembly:`#33cc99`,bottomAssembly:`#5555ff`,ratsnest:`#6464ff`,keepout:`#f022f0`,document:`#ffffff`,grid:`rgb(255 255 255 / 30%)`,gridFifth:`rgb(255 255 255 / 50%)`,selection:`#ffffff`,selectionFill:`rgb(255 255 255 / 50%)`,hover:`rgb(255 255 255 / 60%)`,selectionBox:`#00ffff`,selectionBoxFill:`rgb(0 255 255 / 10%)`,notePanel:`rgb(0 0 0 / 80%)`,error:`#e5534b`,warning:`#e0a63a`,ringHaloOuter:`#ffffff`,ringHaloInner:`#000000`};function Ca(e){let t=e.split(`_`);return[t.includes(`top`)?`top`:t.includes(`bottom`)?`bottom`:`middle`,t.includes(`left`)?`left`:t.includes(`right`)?`right`:`center`]}var wa=[`top`,`bottom`,`topSilk`,`bottomSilk`,`topAssembly`,`bottomAssembly`,`courtyard`,`boardOutline`,`multiLayer`,`hole`,`ratline`,`keepout`],Ta=[{id:`top`,name:`Top Layer`},{id:`bottom`,name:`Bottom Layer`}],Ea=[{id:`top`,name:`Top Layer`,group:`copper`,color:W.topCopper},{id:`bottom`,name:`Bottom Layer`,group:`copper`,color:W.bottomCopper},{id:`topSilk`,name:`Top Silkscreen`,group:`non-copper`,color:W.topSilk},{id:`bottomSilk`,name:`Bottom Silkscreen`,group:`non-copper`,color:W.bottomSilk},{id:`topAssembly`,name:`Top Assembly`,group:`non-copper`,color:W.topAssembly},{id:`bottomAssembly`,name:`Bottom Assembly`,group:`non-copper`,color:W.bottomAssembly},{id:`courtyard`,name:`Courtyard`,group:`non-copper`,color:W.topAssembly,bottomColor:W.bottomAssembly},{id:`boardOutline`,name:`Board Outline`,group:`non-copper`,color:W.boardEdge},{id:`multiLayer`,name:`Multi-Layer`,group:`copper`,color:W.multiLayer},{id:`hole`,name:`Hole`,group:`non-copper`,color:W.drill},{id:`ratline`,name:`Ratline`,group:`non-copper`,color:W.ratsnest},{id:`keepout`,name:`Keepout`,group:`non-copper`,color:W.keepout}];function Da(e,t){return Ea.filter(n=>(e||n.id!==`keepout`)&&(t===`all`||n.group===t))}function Oa(e){return e.bottomColor?`linear-gradient(135deg, ${e.color} 50%, ${e.bottomColor} 50%)`:e.color}var ka={...Object.fromEntries(wa.map(e=>[e,!0])),topAssembly:!1,bottomAssembly:!1};function Aa(e,t){let n=new Set(e);return n.delete(t)||n.add(t),n}function ja(e,t,n){let r={top:`Top Layer`,bottom:`Bottom Layer`,inner1:`Inner Layer 1`,inner2:`Inner Layer 2`};return Object.keys(r).flatMap(i=>{let a=e.filter(e=>e.layer===i).map(e=>({id:e.id,net:t(e.net),layer:i,shown:!n.has(e.id)}));return a.length>0?[{layer:i,name:r[i],pours:a}]:[]})}function Ma(e,t){return{...e,[t]:!e[t]}}function Na(e){return e.layers===`through`?`multiLayer`:e.layers===`bottom`?`bottom`:`top`}function Pa(e){let t=e.side===`top`,n=new Set([`courtyard`]);e.fabrication.length>0&&n.add(t?`topAssembly`:`bottomAssembly`),e.silkscreen.length>0&&n.add(t?`topSilk`:`bottomSilk`);for(let t of e.pads)n.add(Na(t)),t.drill&&n.add(`hole`);return[...n]}function Fa(e,t){return e.some(e=>t[e])}function Ia(e,t){let n=new Map(e.map(e=>[e.component,Pa(e)]));return{visible:t,of:e=>n.get(e)}}var La={parts:!0,labels:!0,wires:!0,drawings:!0,tracks:!0,vias:!0,texts:!0,pours:!0};function Ra(e,t){return{...e,[t]:!e[t]}}function za(e,t){return e===void 0||e[t]}function G(e){let t={kind:`parts`,label:`Parts`};return e===`schematic`?[t,{kind:`wires`,label:`Wires`},{kind:`labels`,label:`Net labels and flags`},{kind:`drawings`,label:`Drawings`},{kind:`texts`,label:`Names and values`}]:[t,{kind:`tracks`,label:`Tracks`},{kind:`vias`,label:`Vias`},{kind:`pours`,label:`Copper pours and holes`},{kind:`texts`,label:`Designators`}]}var Ba={part:`parts`,label:`labels`,wire:`wires`,drawing:`drawings`,track:`tracks`,via:`vias`,text:`texts`,pour:`pours`,hole:`pours`};function Va(e,t){if(!Ha(Ba[e.kind],t))return!1;let{layers:n}=t,r=e.kind===`part`?n?.of(e.name):void 0;return!n||!r||Fa(r,n.visible)}function Ha(e,t){return t.armed===`note`||t.armed===`zoom`?!1:za(t.filter,e)}function Ua(e,t){return e.filter(e=>Va(e,t))}function Wa(e,t){return Ua(e.map(e=>({kind:`part`,name:e})),t).map(e=>e.name)}function Ga(e,t){return Ua(e.map(e=>({kind:`wire`,id:e})),t).map(e=>e.id)}function Ka(e,t){return Ha(`labels`,t)?[...e]:[]}function qa(e,t){return Ha(`drawings`,t)?[...e]:[]}function Ja(e,t){return Ua(e.map(({kind:e,id:t})=>({kind:e,id:t})),t).map(e=>e.id)}function Ya(e,t,n,r=[],i=[],a=[],o=[]){return s=>{let c={selection:s,armed:null,layers:t,filter:n};return s.all(Wa(e,c),Ga(r,c),Ka(i,c),qa(a,c),Ja(o,c))}}function Xa(e,t){return t.x>=e.x?`inside`:`touching`}var Za=(e,t)=>t.minX>=e.minX&&t.maxX<=e.maxX&&t.minY>=e.minY&&t.maxY<=e.maxY,Qa=(e,t)=>e.minX<=t.maxX&&t.minX<=e.maxX&&e.minY<=t.maxY&&t.minY<=e.maxY;function $a(e,t,n,r){let i=Oe([t,n]);if(!i)return[];let a=r===`inside`?e=>Za(i,e):e=>Qa(i,e);return e.filter(e=>a(e.box)).map(e=>e.id)}function eo(e,t,n,r){return $a(e.map(e=>({id:e.name,box:e.box})),t,n,r)}function to(e,t,n,r){return $a(e,t,n,r)}var no=(e,t)=>t.x>=e.minX&&t.x<=e.maxX&&t.y>=e.minY&&t.y<=e.maxY;function ro(e,t,n){if(no(e,t)||no(e,n))return!0;let r=Oe([t,n]);if(!r||!Qa(e,r))return!1;let i=[{x:e.minX,y:e.minY},{x:e.maxX,y:e.minY},{x:e.minX,y:e.maxY},{x:e.maxX,y:e.maxY}].map(e=>(n.x-t.x)*(e.y-t.y)-(n.y-t.y)*(e.x-t.x));return i.some(e=>e>=0)&&i.some(e=>e<=0)}function io(e,t,n,r){let i=Oe([t,n]);if(!i)return[];let a=r===`inside`?e=>e.every(e=>no(i,e)):e=>e.some((t,n)=>ro(i,e[n-1]??t,t));return e.filter(e=>a(e.points)).map(e=>e.id)}function ao(e,t,n=null,r,i){return a=>{let o={selection:a,armed:n,layers:r,filter:i},[s,c,l]=[Wa(e.parts,o),Ga(e.wires??[],o),Ka(e.labels??[],o)],u=qa(e.drawings??[],o),d=Ja(e.copper??[],o);return t?a.add(s).addWires(c).addLabels(l).addDrawings(u).addCopper(d):a.all(s,c,l,u,d)}}var oo=e=>[...new Set(e)],so=(e,t)=>e.length===t.length&&e.every((e,n)=>e===t[n]),co=(e,t)=>e.filter(e=>!t.includes(e)),lo=(e,t)=>{let n=new Set(t);return e.filter(e=>n.has(e))},uo=(e,t)=>e!==void 0&&e.x===t.x&&e.y===t.y,fo=(e,t)=>e!==void 0&&e.id===t.id&&e.index===t.index&&uo(e.from,t.from)&&uo(e.to,t.to);function po(e,t){let[n,r]=[e.points[t],e.points[t+1]];return Number.isInteger(t)&&t>=0&&n&&r?{id:e.id,index:t,from:{x:n.x,y:n.y},to:{x:r.x,y:r.y}}:void 0}function mo(e,t){return uo(t[e.index],e.from)&&uo(t[e.index+1],e.to)}var ho={names:[],wires:[],labels:[],drawings:[],copper:[],texts:[],board:[]},go=[`names`,`wires`,`labels`,`drawings`,`copper`,`texts`,`board`],_o=class e{static none=new e(ho);names;wires;labels;drawings;copper;texts;board;segment;constructor(e,t){this.names=Object.freeze([...e.names]),this.wires=Object.freeze([...e.wires]),this.labels=Object.freeze([...e.labels]),this.drawings=Object.freeze([...e.drawings]),this.copper=Object.freeze([...e.copper]),this.texts=Object.freeze([...e.texts]),this.board=Object.freeze([...e.board]),this.segment=t&&Object.freeze({id:t.id,index:t.index,from:Object.freeze({...t.from}),to:Object.freeze({...t.to})}),Object.freeze(this)}static from(t){return go.every(e=>t[e].length===0)?e.none:new e(t)}get lists(){return{names:this.names,wires:this.wires,labels:this.labels,drawings:this.drawings,copper:this.copper,texts:this.texts,board:this.board}}with(t){let n={...this.lists,...t};return go.every(e=>n[e].length===this[e].length)?this:e.from(n)}grown(t){return new e({...this.lists,...t})}get primary(){return this.names.at(-1)}get size(){return this.names.length}get wireCount(){return this.wires.length}get labelCount(){return this.labels.length}get drawingCount(){return this.drawings.length}get copperCount(){return this.copper.length}get textCount(){return this.texts.length}get boardCount(){return this.board.length}get total(){return this.names.length+this.wires.length+this.labels.length+this.drawings.length+this.copper.length+this.texts.length+this.board.length}get soleBoard(){return this.total===1?this.board[0]:void 0}get soleText(){return this.total===1?this.texts[0]:void 0}get soleCopper(){return this.total===1?this.copper[0]:void 0}get soleWire(){return this.total===1?this.wires[0]:void 0}get soleLabel(){return this.total===1?this.labels[0]:void 0}get soleDrawing(){return this.total===1?this.drawings[0]:void 0}has(e){return this.names.includes(e)}hasWire(e){return this.wires.includes(e)}hasLabel(e){return this.labels.includes(e)}hasDrawing(e){return this.drawings.includes(e)}hasCopper(e){return this.copper.includes(e)}hasText(e){return this.texts.includes(e)}hasBoard(e){return this.board.includes(e)}onlyBoard(t){return this.soleBoard===t?this:new e({...ho,board:[t]})}toggleBoard(e){return this.hasBoard(e)?this.withoutBoard([e]):this.grown({board:[...this.board,e]})}addBoard(e){let t=oo(e).filter(e=>!this.hasBoard(e));return t.length===0?this:this.grown({board:[...this.board,...t]})}withoutBoard(e){return this.with({board:co(this.board,e)})}keepBoard(e){return this.with({board:lo(this.board,e)})}only(t){return this.total===1&&this.names[0]===t?this:new e({...ho,names:[t]})}onlyWire(t){return this.soleWire===t?this:new e({...ho,wires:[t]})}onlyLabel(t){return this.soleLabel===t?this:new e({...ho,labels:[t]})}onlyDrawing(t){return this.soleDrawing===t?this:new e({...ho,drawings:[t]})}onlyText(t){return this.soleText===t?this:new e({...ho,texts:[t]})}onlyCopper(t){return this.soleCopper===t&&!this.segment?this:new e({...ho,copper:[t]})}onlySegment(t){return fo(this.segment,t)?this:new e({...ho,copper:[t.id]},t)}toggle(e){return this.has(e)?this.without([e]):this.grown({names:[...this.names,e]})}toggleWire(e){return this.hasWire(e)?this.withoutWires([e]):this.grown({wires:[...this.wires,e]})}toggleLabel(e){return this.hasLabel(e)?this.withoutLabels([e]):this.grown({labels:[...this.labels,e]})}toggleDrawing(e){return this.hasDrawing(e)?this.withoutDrawings([e]):this.grown({drawings:[...this.drawings,e]})}toggleCopper(e){return this.hasCopper(e)?this.withoutCopper([e]):this.grown({copper:[...this.copper,e]})}toggleText(e){return this.hasText(e)?this.with({texts:co(this.texts,[e])}):this.grown({texts:[...this.texts,e]})}add(e){let t=oo(e).filter(e=>!this.has(e));return t.length===0?this:this.grown({names:[...this.names,...t]})}addWires(e){let t=oo(e).filter(e=>!this.hasWire(e));return t.length===0?this:this.grown({wires:[...this.wires,...t]})}addLabels(e){let t=oo(e).filter(e=>!this.hasLabel(e));return t.length===0?this:this.grown({labels:[...this.labels,...t]})}addDrawings(e){let t=oo(e).filter(e=>!this.hasDrawing(e));return t.length===0?this:this.grown({drawings:[...this.drawings,...t]})}addCopper(e){let t=oo(e).filter(e=>!this.hasCopper(e));return t.length===0?this:this.grown({copper:[...this.copper,...t]})}clear(){return e.none}all(t,n=[],r=[],i=[],a=[]){let o={names:oo(t),wires:oo(n),labels:oo(r),drawings:oo(i),copper:oo(a),texts:[],board:[]};return go.every(e=>so(o[e],this[e]))?this:e.from(o)}without(e){return this.with({names:co(this.names,e)})}withoutWires(e){return this.with({wires:co(this.wires,e)})}withoutLabels(e){return this.with({labels:co(this.labels,e)})}withoutDrawings(e){return this.with({drawings:co(this.drawings,e)})}withoutCopper(e){return this.with({copper:co(this.copper,e)})}keep(e){return this.with({names:lo(this.names,e)})}keepWires(e){return this.with({wires:lo(this.wires,e)})}keepLabels(e){return this.with({labels:lo(this.labels,e)})}keepDrawings(e){return this.with({drawings:lo(this.drawings,e)})}withoutTexts(e){return this.with({texts:co(this.texts,e)})}keepTexts(e){return this.with({texts:lo(this.texts,e)})}keepCopper(e){return this.with({copper:lo(this.copper,e)})}};function vo(e,t){let{segment:n}=e,r=n&&t.find(e=>e.id===n.id);return n&&r&&!mo(n,r.points)?e.onlyCopper(n.id):e}function yo(e){return e.shiftKey||e.ctrlKey||e.metaKey}function bo(e,t){let n=yo(t);return t=>n?t.toggle(e):t.only(e)}function xo(e,t){let n=new Set(t);return e.filter(e=>!n.has(e))}var So={error:W.error,warning:W.warning},Co=6,wo=1.5,To=3,Eo=1;function Do(e,t,n,r,i,a=So){if(n.length!==0){e.globalAlpha=1,e.setLineDash([]);for(let o of n){let n=V(t.camera,t.size,o.at),s=o.id===r?To:wo;i&&ko(e,n,s),e.strokeStyle=o.severity===`error`?a.error:a.warning,Oo(e,n,Co,s)}}}function Oo(e,t,n,r){e.lineWidth=r,e.beginPath(),e.arc(t.x,t.y,n,0,Math.PI*2),e.stroke()}function ko(e,t,n){let r=(n+Eo)/2;e.strokeStyle=W.ringHaloOuter,Oo(e,t,Co+r,Eo),e.strokeStyle=W.ringHaloInner,Oo(e,t,Co-r,Eo)}var Ao={background:`#FFFCF8`,grid:`#F0F0EB`,wire:`#008800`,bus:`#008800`,drawing:`#000080`,junction:`#CC0000`,symbolOutline:`#A00000`,pin:`#880000`,pinName:`#000000`,pinNumber:`#000000`,designator:`#0000FF`,netName:`#0000FF`,value:`#000080`,noConnect:`#33CC33`,selection:`#FF0000`,highlight:`#FF9933`,border:`#A00000`,titleText:`#000080`,gridDot:`#D9D9D2`,flag:`#A00000`,markerError:W.error,markerWarning:W.warning,selectionGlow:0,hover:`rgb(255 0 0 / 45%)`,handleFill:`#FFFFFF`,selectionFill:`rgb(255 0 0 / 8%)`,selectionBox:`#0000FF`,selectionBoxFill:`rgb(0 0 255 / 8%)`,lockBadge:`#4f9a6c`,lockGlyph:`#ffffff`,notePin:`#e0a46a`,notePanel:`rgb(34 38 44 / 92%)`,noteText:`#e9e6df`},jo={background:`#141619`,grid:`#2B3038`,gridDot:`#2B3038`,gridFifth:`#3A4049`,wire:`#5BD3C7`,bus:`#8AB4FF`,drawing:`#9AA1A9`,junction:`#5BD3C7`,symbolOutline:`#D9DEE5`,pin:`#D9DEE5`,pinName:`#AEB6C0`,pinNumber:`#7E8792`,designator:`#E6E8EB`,netName:`#F2C66D`,value:`#AEB6C0`,noConnect:`#5BD3C7`,selection:`#4CC9F0`,highlight:`#E89A4F`,border:`#9AA1A9`,titleText:`#9AA1A9`,flag:`#FF9E80`,markerError:`#FF6B6B`,markerWarning:`#FFC857`,selectionGlow:8,hover:`#8BE0F5`,handleFill:`#141619`,selectionFill:`rgb(76 201 240 / 10%)`,selectionBox:`#4CC9F0`,selectionBoxFill:`rgb(76 201 240 / 8%)`,lockBadge:`#4f9a6c`,lockGlyph:`#ffffff`,notePin:`#e0a46a`,notePanel:`rgb(34 38 44 / 92%)`,noteText:`#e9e6df`},Mo=e=>e===`dark`?jo:Ao,No=Ao,Po=()=>No;function Fo(e){No=e}function Io(e,t,n=No){let r=t?n.selectionGlow:0;e.shadowBlur=r,e.shadowColor=r>0?n.selection:`transparent`}var Lo=.02,Ro=3*Lo;function zo(e){return e.kind===`bus`?Ro:e.kind===`text`||e.kind===`junction`?0:e.strokeWidth}var Bo=(e,t)=>Math.max(e,t);function Vo(e,t){return e===`dashed`?[4*t,3*t]:e===`dotted`?[0,2*t]:[]}function Ho(e){return e.kind===`bus`||e.kind===`text`||e.kind===`junction`?`solid`:e.lineStyle}function Uo(e){return e.kind===`bus`?Po().bus:e.kind===`junction`?e.color??Po().junction:e.color??Po().drawing}var Wo=e=>(e.kind===`rect`||e.kind===`circle`)&&e.filled,Go=e=>`${e}33`,Ko=e=>1/e,qo=(e,t)=>(Math.floor(e*t)+.5)/t,Jo=(e,t)=>Math.round(e*t)/t,Yo=(e,t)=>Math.max(1,Math.round(e*t))/t,Xo=(e,t)=>Math.round(e*t)/t,Zo=(e,t)=>e/t,Qo=(e,t)=>Math.max(1,Math.round(e*t)),$o=(e,t,n)=>n%2==1?qo(e,t):Jo(e,t);function es(e,t,n,r=1){let i=e=>$o(e,n,r),a=i(Math.min(e.x,t.x)),o=i(Math.min(e.y,t.y));return{x:a,y:o,width:i(Math.max(e.x,t.x))-a,height:i(Math.max(e.y,t.y))-o}}var ts=.16;function ns(e){return e<7?`none`:e<9?`names`:`all`}function rs(e,t,n){if(n<5)return!1;let r=ns(t);return e===`name`?r!==`none`:e===`pin-number`?t>=11:r===`all`}var is=(e,t,n)=>Math.max(1,Math.round(e*t*n)),as=(e,t)=>is(ts,e,t),os=(e,t,n)=>is(e,t,n)/n,ss=(e,t)=>({x:Jo(e.x,t),y:Xo(e.y,t)});function cs(e){`textRendering`in e&&(e.textRendering=`geometricPrecision`)}var ls=(e,t,n)=>t<=n||t<=0?e:Math.max(1,Math.floor(e*n/t)),us=e=>e*Math.PI/180;function ds(e,t){if(!t||t.length===0)return e;let n=new Map(t.map(e=>[e.id,e]));return e.map(e=>n.get(e.id)??e)}function fs(e,t){let n=t-e;return Math.abs(n)>=360?360:(n%360+360)%360}function ps(e,t){if(e.beginPath(),t.kind===`path`||t.kind===`bus`){t.points.forEach((t,n)=>n===0?e.moveTo(t.x,t.y):e.lineTo(t.x,t.y));return}if(t.kind===`rect`){let{x:n,y:r,width:i,height:a}=t;e.moveTo(n,r),e.lineTo(n+i,r),e.lineTo(n+i,r+a),e.lineTo(n,r+a),e.closePath();return}if(t.kind===`circle`)return e.arc(t.x,t.y,t.radius,0,2*Math.PI);let n=us(t.startAngle);e.arc(t.x,t.y,t.radius,n,n+us(fs(t.startAngle,t.endAngle)))}function ms(e,t){return t.selected?.includes(e.id)?{color:Po().selection,alpha:1}:{color:Uo(e),alpha:t.dim?_a:1}}function hs(e,t,n,r,i){e.globalAlpha=r,e.fillStyle=n,e.beginPath(),e.arc(t.x,t.y,Zt,0,2*Math.PI),Io(e,i),e.fill(),Io(e,!1)}function gs(e,t,n,r){for(let i of t){if(i.kind===`text`)continue;let{color:t,alpha:a}=ms(i,r);if(i.kind===`junction`){hs(e,i,t,a,r.selected?.includes(i.id)??!1);continue}let o=Bo(zo(i),n);e.globalAlpha=a,e.lineWidth=o,e.strokeStyle=t,e.setLineDash(Vo(r.pending?`dashed`:Ho(i),o)),ps(e,i),Wo(i)&&(e.fillStyle=Go(t),e.fill()),Io(e,r.selected?.includes(i.id)??!1),e.stroke(),Io(e,!1),e.setLineDash([])}e.globalAlpha=1}function _s(e,t,n,r,i,a){for(let o of t){if(o.kind!==`text`||o.text===``)continue;let t=is(o.fontSize,n.scale,a);if(!rs(`detail`,as(n.scale,a),t))continue;let s=t/a,{color:c,alpha:l}=ms(o,i),u=ss(V(n,r,o),a),[,d]=Ca(o.anchor);e.globalAlpha=l,e.fillStyle=c,e.font=`${s}px ${ya}`,e.textAlign=d,e.textBaseline=`middle`,e.fillText(o.text,u.x,u.y)}e.globalAlpha=1}var vs=.7,ys=`…`,bs=2;function xs(e,t,n){if(n(e)<=t)return e;for(let r=e.length-1;r>=bs;r--){let i=e.slice(0,r)+ys;if(n(i)<=t)return i}return null}function Ss(e,t,n){let r=t(e);if(r>=1)return{text:e,scale:1};if(r>=n)return{text:e,scale:r};for(let r=e.length-1;r>=bs;r--){let i=e.slice(0,r)+ys;if(t(i)>=n)return{text:i,scale:n}}return null}function Cs(e,t,n){if(t+n<=e)return t;let r=e/2;return t<=r?t:n<=r?e-n:r}var ws=(e,t,n,r)=>t===`x`===e.quarter?e.size:r(n),Ts=e=>e.side===`left`||e.side===`right`,Es=e=>Ts(e)?`x`:`y`,Ds=e=>Ts(e)?`y`:`x`,Os=e=>Ts(e)?1:.5,ks={left:`right`,right:`left`,top:`bottom`,bottom:`top`};function As(e,t,n,r){let[i,a]=[Es(e),Ds(e)],o=e.side===`left`||e.side===`bottom`?1:-1,s=e=>ws(e,i,e.text,n)*Os(e),c=t=>Math.abs(t.local[a]-e.local[a])<(ws(e,a,e.text,n)+ws(t,a,t.text,n))/2,l=t.filter(t=>t.side===ks[e.side]&&c(t)&&(t.local[i]-e.local[i])*o>0).sort((t,n)=>Math.abs(t.local[i]-e.local[i])-Math.abs(n.local[i]-e.local[i]))[0];return Cs(Math.abs((l?l.local[i]:-e.local[i])-e.local[i])-r,s(e),l?s(l):0)/Os(e)}function js(e,t,n){let r=Ds(e),i=t.filter(t=>t!==e&&t.side===e.side).map(t=>Math.abs(t.local[r]-e.local[r]));return i.length===0?1/0:Math.min(...i)-n}function Ms(e,t,n,r,i){let a=As(e,t,n,r),o=js(e,t,r);return Ss(e.text,t=>Math.min(a/ws(e,Es(e),t,n),o/ws(e,Ds(e),t,n)),i)}function Ns(e,t,n){let r=n(t.text)*t.scale,i=e.align===`left`?e.x:e.align===`right`?e.x-r:e.x-r/2;return{x0:i,x1:i+r,y0:e.y-e.ascent*t.scale,y1:e.y+e.descent*t.scale}}var Ps=(e,t)=>e.x0<t.x1&&t.x0<e.x1&&e.y0<t.y1&&t.y0<e.y1;function Fs(e,t){let n=new Set;return e.forEach((r,i)=>{e.forEach((e,a)=>{a>i&&r&&e&&t(i,a)&&Ps(r,e)&&n.add(i).add(a)})}),n}function Is(e,t,n,r=vs){let i=e.map(i=>Ms(i,e,t,n,r)),a=i.map((n,r)=>n===null?null:Ns(e[r],n,t)),o=Fs(a,(t,n)=>e[t]?.side===e[n]?.side),s=Fs(a.map((e,t)=>o.has(t)?null:e),()=>!0);return i.map((e,t)=>o.has(t)||s.has(t)?null:e)}var Ls=.25,Rs=.8,zs=.2,Bs={top:Rs,middle:.6000000000000001/2,bottom:-.2},Vs=(e,t,n)=>Sa(e.strong?xa.strong:xa.regular,t/n,e.mono?ba:void 0);function Hs(e,t,{camera:n,ratio:r}){let i=is(t.size,n.scale,r);return t.maxWidth===void 0?i:(e.font=Vs(t,i,r),ls(i,e.measureText(t.text).width,t.maxWidth*n.scale))}function Us(e,t,n,r){e.textBaseline=n;let i=e.measureText(t),a=(Bs[n]??0)*r;return{ascent:i.actualBoundingBoxAscent??Rs*r-a,descent:i.actualBoundingBoxDescent??zs*r+a}}function Ws(e,{label:t,devicePx:n},r){let i=t.pinOf;if(!i)return null;let a=n/r.ratio,o=V(r.camera,r.size,t.at),[s,c]=Ca(t.anchor),l={x:i.local.x*r.camera.scale,y:i.local.y*r.camera.scale},u=Us(e,t.text,s,a);return{text:t.text,x:o.x,y:o.y,align:c,size:a,...u,local:l,side:i.side,quarter:i.quarter}}function Gs(e,t,n){let r=t[0];if(!r)return t;e.font=Vs(r.label,r.devicePx,n.ratio);let i=t.map(t=>Ws(e,t,n)).filter(e=>e!==null);if(i.length!==t.length)return t;let a=Math.ceil(r.devicePx*vs)/r.devicePx,o=Is(i,t=>e.measureText(t).width,r.devicePx/n.ratio*Ls,a);return t.flatMap((e,t)=>{let n=o[t];if(!n)return[];let r=n.scale<1?Math.floor(e.devicePx*n.scale+1e-9):e.devicePx;return[{label:{...e.label,text:n.text},devicePx:r}]})}function Ks(e,t,n){let r=as(n.camera.scale,n.ratio),i=({label:e,devicePx:t})=>rs(e.kind,r,t),a=t.filter(e=>e.text!==``).map(t=>({label:t,devicePx:Hs(e,t,n)})).filter(i),o=new Map;for(let e of a){let t=e.label.pinOf?.symbol;t!==void 0&&o.set(t,[...o.get(t)??[],e])}let s=[...o.values()].flatMap(t=>Gs(e,t,n));return[...a.filter(({label:e})=>!e.pinOf),...s.filter(i)]}function qs(e,{label:t,devicePx:n},r){let i=ss(V(r.camera,r.size,t.at),r.ratio),[a,o]=Ca(t.anchor);e.save(),e.translate(i.x,i.y),t.rotation&&e.rotate(-t.rotation*Math.PI/180),e.globalAlpha=t.alpha??1,e.fillStyle=t.color,e.font=Vs(t,n,r.ratio),e.textAlign=o,e.textBaseline=a,e.fillText(t.text,0,0),e.restore()}function Js(e,t,n,r,i){let a={camera:n,size:r,ratio:i};cs(e);for(let n of Ks(e,t,a))qs(e,n,a)}var Ys=.05,Xs=.015;function Zs(e){let t=Ys;return[[{x:e.x-t,y:e.y-t},{x:e.x+t,y:e.y+t}],[{x:e.x-t,y:e.y+t},{x:e.x+t,y:e.y-t}]]}function Qs(e,t,n,r){if(t.length!==0){e.strokeStyle=Po().noConnect,e.lineWidth=n(Xs),e.globalAlpha=r?_a:1;for(let n of t)for(let[t,r]of Zs(n.at))e.beginPath(),e.moveTo(t.x,t.y),e.lineTo(r.x,r.y),e.stroke();e.globalAlpha=1}}var $s={x:0,y:0},ec=.02,tc=1.2,nc=3.5,rc=.06,ic=1.5,ac=1.6,oc=.04,sc=3,cc=[.1,.06],lc=.1,uc=.07,dc=2.5,fc={reference:`name`,value:`detail`,"pin-name":`detail`,"pin-number":`pin-number`},pc={reference:`designator`,value:`value`,"pin-name":`pinName`,"pin-number":`pinNumber`},mc={right:{x:1,y:0},left:{x:-1,y:0},top:{x:0,y:1},bottom:{x:0,y:-1}},hc=e=>e*Math.PI/180,gc=e=>Math.max(Lo*e,tc);function _c(e,t,n,r){let{camera:i,size:a}=n,o=1/i.scale,s=e=>Math.max(e,o/r.ratio),c=[],l=e=>r.moving?.components.includes(e.component)?r.moving.by:$s;e.save();let u=i.scale*r.ratio;e.setTransform(u,0,0,-u,(a.width/2-i.cx*i.scale)*r.ratio,(a.height/2+i.cy*i.scale)*r.ratio),e.lineCap=`round`,e.lineJoin=`round`,kc(e,t,r,o,s);let d=ds(t.drawings,r.movingDrawings),f=r.pendingDrawings??[],p=[...d,...f],m={...r.selectedDrawings?{selected:r.selectedDrawings}:{},dim:r.highlight!==void 0};gs(e,d,o/r.ratio,m),gs(e,f,o/r.ratio,{pending:!0,dim:m.dim});for(let n of t.symbols)Ac(e,n,l(n),{line:s,px:o,fade:Tc(n,r.highlight)},c);for(let n of t.labels){let t=r.movingLabels?.some(e=>e.id===n.id)??!1,i=r.selectedLabels?.includes(n.id)??!1,a=i?{color:Po().selection,alpha:1}:wc(n.net,r.highlight);Io(e,i),zc(e,Rc(n,r),s,c,t,a),Io(e,!1)}for(let t of r.ghostLabels??[])zc(e,t,s,c,!0,wc(t.net,void 0));Hc(e,t,r,o,l),Qs(e,t.noConnects??[],s,r.highlight!==void 0),e.setTransform(r.ratio,0,0,r.ratio,0,0),Js(e,c,i,a,r.ratio),_s(e,p,i,a,m,r.ratio),Do(e,n,r.violations??[],r.activeViolation,!1,{error:Po().markerError,warning:Po().markerWarning}),e.restore()}function vc(e){return e.symbols.map(e=>{let t=bc(e);return{name:e.component,pcbComponentId:e.component,center:{x:(t.minX+t.maxX)/2,y:(t.minY+t.maxY)/2},box:t}})}var yc=e=>e.type===`text`&&(e.role===`reference`||e.role===`value`);function bc(e){let{minX:t,minY:n,maxX:r,maxY:i}=Nt(e.symbol.shapes.filter(e=>!yc(e)),e.symbol.pins),a=[{x:t,y:n},{x:r,y:n},{x:r,y:i},{x:t,y:i}].map(t=>xc(t,e)),o=a.map(e=>e.x),s=a.map(e=>e.y);return{minX:Math.min(...o),minY:Math.min(...s),maxX:Math.max(...o),maxY:Math.max(...s)}}function xc(e,t){let n=hc(t.rotation),r=Math.cos(n),i=Math.sin(n);return{x:t.x+e.x*r-e.y*i,y:t.y+e.x*i+e.y*r}}function Sc(e,t){e.beginPath(),t.forEach((t,n)=>n===0?e.moveTo(t.x,t.y):e.lineTo(t.x,t.y))}function Cc(e,t,n){e.beginPath(),e.arc(t.x,t.y,Math.max(n,0),0,Math.PI*2)}function wc(e,t){return t?e===t.net||t.aliases?.includes(e)?{color:Po().highlight,alpha:1}:{color:void 0,alpha:_a}:{color:void 0,alpha:1}}function Tc(e,t){return t?t.pins?.some(t=>t in e.pinEnds)?1:_a:1}var Ec=1e-9;function Dc(e,t,n){let r=Math.abs((n.x-t.x)*(e.y-t.y)-(n.y-t.y)*(e.x-t.x))<Ec,i=(e,t,n)=>e>=Math.min(t,n)-Ec&&e<=Math.max(t,n)+Ec;return r&&i(e.x,t.x,n.x)&&i(e.y,t.y,n.y)}function Oc(e,t,n){return e.wires.some(e=>wc(e.net,n).color!==void 0&&e.points.some((n,r)=>r>0&&Dc(t,e.points[r-1]??n,n)))}function kc(e,t,n,r,i){e.lineWidth=i(Lo);for(let r of t.wires){if(n.movingLabels?.some(e=>e.hideWire===r.id))continue;let t=n.selectedWires?.includes(r.id)??!1,i=t?{color:Po().selection,alpha:1}:wc(r.net,n.highlight);e.strokeStyle=i.color??Po().wire,e.globalAlpha=i.alpha,Io(e,t),Sc(e,r.points),e.stroke()}Io(e,!1);for(let i of t.junctions){let a=n.highlight!==void 0&&Oc(t,i,n.highlight);e.fillStyle=a?Po().highlight:Po().junction,e.globalAlpha=n.highlight&&!a?_a:1,Cc(e,i,Math.max(oc,sc*r)),e.fill()}e.globalAlpha=1,e.strokeStyle=Po().wire;let a=(n.pending??[]).filter(e=>e.length>=2);if(a.length!==0){e.setLineDash(cc);for(let t of a)Sc(e,t),e.stroke();e.setLineDash([])}}function Ac(e,t,n,r,i){let a={x:t.x+n.x,y:t.y+n.y,rotation:t.rotation},o=r.fade,s=[];e.globalAlpha=o,e.lineWidth=r.line(ec),Nc(e,t.symbol.shapes,a,Po().symbolOutline,s),e.globalAlpha=1;let c=t.symbol.shapes.some(e=>e.type===`text`&&e.role===`pin-number`);t.symbol.kind!==`sheet`&&!c&&s.push(...Mc(t.symbol,a)),i.push(...s.map(e=>({...e,alpha:o,...jc(e,t)})))}function jc(e,t){if(e.pinOf)return{pinOf:{...e.pinOf,symbol:t.component}};if(e.role!==`reference`&&e.role!==`value`||t.symbol.pins.length!==2)return{};let[n,r]=t.symbol.pins;return n&&r?{maxWidth:dc*Math.hypot(n.end.x-r.end.x,n.end.y-r.end.y)}:{}}function Mc(e,t){return e.pins.map(e=>{let n=mc[e.side],r={x:e.end.x-n.x*lc,y:e.end.y-n.y*lc},i=n.x===0?{x:r.x+uc,y:r.y}:{x:r.x,y:r.y+uc};return{text:String(e.number),at:xc(i,t),size:.1,anchor:`center`,color:Po().pinNumber,mono:!0,kind:`pin-number`}})}function Nc(e,t,n,r,i){e.save(),e.translate(n.x,n.y),n.rotation&&e.rotate(hc(n.rotation)),e.strokeStyle=r,e.fillStyle=r;for(let a of t)a.type===`text`?i.push(Ic(a,n,r)):a.type===`polyline`&&a.bus?Pc(e,a):Fc(e,a);e.restore()}function Pc(e,t){let[n,r]=[e.strokeStyle,e.fillStyle];e.strokeStyle=Po().bus,e.fillStyle=Po().bus,Sc(e,t.points),e.closePath(),e.fill(),e.stroke(),e.strokeStyle=n,e.fillStyle=r}function Fc(e,t){if(t.type===`polyline`)Sc(e,t.points),(t.closed||t.fill)&&e.closePath(),t.fill&&e.fill(),e.stroke();else if(t.type===`circle`)Cc(e,t.center,t.radius),t.fill&&e.fill(),e.stroke();else{let n=t.end<t.start?t.end+360:t.end;e.beginPath(),e.arc(t.center.x,t.center.y,t.radius,hc(t.start),hc(n)),e.stroke()}}function Ic(e,t,n){let r=e.anchor===`left`?1:e.anchor===`right`?-1:0,i=hc(t.rotation),a=r*Math.cos(i),o=r*Math.sin(i),s=Math.abs(a)>.5?a>0?`left`:`right`:Math.abs(o)>.5?o>0?`bottom`:`top`:`center`,c={role:e.role,kind:fc[e.role],...e.role===`pin-name`?{pinOf:Lc(e,t)}:{},...e.role===`reference`?{strong:!0}:{},...e.role===`pin-number`?{mono:!0}:{}};return{text:e.text,at:xc(e.at,t),size:e.size,anchor:s,color:Po()[pc[e.role]]??n,...c}}function Lc(e,t){let n=e.anchor===`left`?`left`:e.anchor===`right`?`right`:e.at.y>0?`top`:`bottom`;return{symbol:``,local:e.at,side:n,quarter:Math.abs(Math.sin(hc(t.rotation)))>.5}}function Rc(e,t){let n=t.movingLabels?.find(t=>t.id===e.id);return n?{...e,at:n.at,side:n.side}:e}function zc(e,t,n,r,i,a){e.setLineDash(i?cc:[]),e.globalAlpha=a.alpha,Bc(e,t,n,r,a),e.globalAlpha=1,e.setLineDash([])}function Bc(e,t,n,r,i){if(t.style!==`label`){let a=t.style===`ground`?Ft():It(t.text);e.lineWidth=n(ec);let o=r.length;Nc(e,a,{x:t.at.x,y:t.at.y,rotation:0},i.color??Po().flag,r);for(let e=o;e<r.length;e++)r[e]={...r[e],strong:!0,kind:`name`,color:i.color??Po().netName,alpha:i.alpha};return}let{middle:a,upright:o,box:s}=Vt(t);r.push({text:t.text,at:a,size:Lt,anchor:`center`,strong:!0,kind:`name`,color:i.color??Po().netName,rotation:o?90:0,alpha:i.alpha}),t.port&&Vc(e,t,s,n,i)}function Vc(e,t,n,r,i){e.strokeStyle=i.color??Po().netName,e.lineWidth=r(t.bus?ec*3:ec),e.beginPath(),e.moveTo(n.minX,n.minY),e.lineTo(n.maxX,n.minY),e.lineTo(n.maxX,n.maxY),e.lineTo(n.minX,n.maxY),e.closePath(),e.stroke()}function Hc(e,t,n,r,i){for(let a of t.symbols){let t=i(a);for(let[i,o]of Object.entries(a.pinEnds)){let a=n.highlight?.pins?.includes(i)??!1,s=(n.activePins?.includes(i)??!1)||a;if(!s&&!n.showPins)continue;e.fillStyle=s?Po().highlight:Po().pin;let c=a?Math.min(nc*r,Math.max(rc,ic*r)):(s?ac:1)*nc*r;Cc(e,{x:o.x+t.x,y:o.y+t.y},c),e.fill()}}}var Uc=2;function Wc(e,t){return Math.max(e,gc(t)/2+Uc)}var Gc=e=>Wc(6,e);function Kc(e,t,n){let r=n.x-t.x,i=n.y-t.y,a=r*r+i*i,o=a===0?0:Math.max(0,Math.min(1,((e.x-t.x)*r+(e.y-t.y)*i)/a));return Math.hypot(e.x-(t.x+o*r),e.y-(t.y+o*i))}function qc(e,t){let n;for(let r=1;r<e.length;r++){let i=Kc(t,e[r-1],e[r]);(!n||i<n.distance)&&(n={index:r-1,distance:i})}return n}function Jc(e,t,n){let r=qc(e,t);return r&&r.distance<=n?r.index:void 0}function Yc(e,t,n){let r;for(let i of e){let e=qc(i.points,t);e&&e.distance<=n&&(!r||e.distance<r.distance)&&(r={id:i.id,distance:e.distance})}return r?.id}function Xc(e){return e.length<2?{corners:[],ends:[...e]}:{corners:e.slice(1,-1),ends:[e[0],e[e.length-1]]}}function Zc(e,t,n){let r=e.findIndex((r,i)=>i>0&&i<e.length-1&&Math.abs(r.x-t.x)<=n&&Math.abs(r.y-t.y)<=n);return r<0?void 0:r}var Qc=1e-9,$c={x:0,y:0},el=(e,t)=>Math.abs(e-t)<Qc;function tl(e,t){return el(e.y,t.y)?`horizontal`:el(e.x,t.x)?`vertical`:`slanted`}function nl(e,t){return e===`horizontal`?{x:0,y:t.y}:e===`vertical`?{x:t.x,y:0}:t}function rl(e,t){return e===`horizontal`?el(t.y,0):e!==`vertical`||el(t.x,0)}function il(e,t){return e.map((e,n)=>{let r=[t.get(n-1),t.get(n)].filter(e=>e!==void 0);return{x:r.find(e=>!el(e.x,0))?.x??0,y:r.find(e=>!el(e.y,0))?.y??0}})}function al(e,t,n,r){if(t===0||t===e.length-1)return!0;let i=r.has(t)?t-1:t,[a,o]=[e[i],e[i+1]];return a!==void 0&&o!==void 0&&!rl(tl(a,o),n)}function ol(e,t){let n=il(e,t);return kn(e.flatMap((r,i)=>{let a=n[i]??$c,o={x:r.x+a.x,y:r.y+a.y},s=t.has(i-1);return s===t.has(i)||!al(e,i,a,t)?[o]:s?[o,r]:[r,o]}))}function sl(e,t,n){let[r,i]=[e[t],e[t+1]];return!r||!i?kn(e):ol(e,new Map([[t,nl(tl(r,i),n)]]))}function cl(e,t,n){let[r,i,a]=[e[t-1],e[t],e[t+1]];if(!r||!i||!a)return kn(e);let o={x:n.x-i.x,y:n.y-i.y};return ol(e,new Map([[t-1,nl(tl(r,i),o)],[t,nl(tl(i,a),o)]]))}var ll=(e,t)=>({x:e.x+t.x,y:e.y+t.y});function ul(e,t,n){let[r,i,a,o]=[e[0],e[1],e[e.length-2],e[e.length-1]];if(!r||!i||!a||!o)return kn(e);let s=n.start?[ll(r,t)]:[r,ll(r,nl(tl(r,i),t))],c=n.end?[ll(o,t)]:[ll(o,nl(tl(a,o),t)),o];return kn([...s,...e.slice(1,-1).map(e=>ll(e,t)),...c])}function dl(e,t){let[n,r]=[e[t-1],e[t]];if(!n||!r||t>=e.length-1)return kn(e);let i=e.slice(0,-2).map(()=>!1);return i[t-1]=tl(n,r)===`horizontal`,kn(On(e.filter((e,n)=>n!==t),i))}var fl=kn,pl=`The pin of this wire has several traces to its net; change its corners in the code`,ml=1e-6;function hl(e,t){return e.slice(1).some((n,r)=>{let i=e[r],a=(n.x-i.x)*(t.y-i.y)-(n.y-i.y)*(t.x-i.x),o=Math.min(i.x,n.x)-ml<=t.x&&t.x<=Math.max(i.x,n.x)+ml&&Math.min(i.y,n.y)-ml<=t.y&&t.y<=Math.max(i.y,n.y)+ml;return Math.abs(a)<=ml&&o})}function gl(e,t,n,r){return e.schematic.wires.some(e=>e.id!==t&&e.net===n&&hl(e.points,r))}function _l(e,t,n,r){let i=vr(e,t,{pin:n.id},{net:Sr(e,r)}),[a]=i;if(!a)return{};if(i.length>1||a.props.schematicRouteHints)return{blocked:pl};let o=br(a)??Cr(t,a);return o===void 0?{trace:a}:{blocked:o}}function vl(e,t,n,r){let i=(e.pinLast?[...r].reverse():[...r]).slice(1),{trace:a}=e;if(!a)return[{kind:`addTrace`,from:t,to:n,schematicRouteHints:i}];let o=(a.from??``).startsWith(`net.`);return[{kind:`setTraceHints`,from:a.from??``,to:a.to??``,schematicRouteHints:o?[...i].reverse():i}]}var yl=/^wire:.+:\d+$/,bl=e=>e.startsWith(`net.`),xl=(e,t)=>e.x===t.x&&e.y===t.y,Sl=(e,t)=>e.circuit.components.flatMap(e=>e.pins).find(e=>e.id===t);function Cl(e,t,n){return{id:e,points:t,fixed:{start:!0,end:!0},writer:n}}function wl(e,t,n){let r=t=>bl(t)?{net:Sr(e,t)}:{pin:t};return yr(vr(e,t,r(n.from),r(n.to)).filter(t=>_r(e,t.from,r(n.from))),n.id)}function Tl(e,t,n,r,i){let a=wl(e,t,i);if(!a)return Cl(n,r,{kind:`none`,reason:`The wire is not written in a trace the Studio can find`});let o=[i.from,i.to].filter(e=>!bl(e)),s=o.map(t=>Sl(e,t)?.component??``),c=o.length===1,l=Cr(t,a);return Cl(n,r,{kind:`trace`,trace:a,toNet:c,reversed:c&&bl(i.from),components:s,...l?{repeat:l}:{}})}function El(e,t,n){let r=t.find(t=>e.schematic.symbols.some(e=>e.pinEnds[t]!==void 0&&xl(e.pinEnds[t],n)));return r===void 0?void 0:Sl(e,r)}var Dl=(e,t)=>{let n=t.find(t=>!dr(Ln(e,t)));return n?{unaddressable:`${n.id} has a repeated name and cannot be wired from the Studio`}:{}};function Ol(e,t,n,r,i,a,o){let s=e.circuit.nets.find(e=>e.id===o)?.names[0],c=a?r[0]:r[r.length-1];if(s===void 0||!c||!gl(e,n,o,c))return;let l={pinLast:a,..._l(e,t,i,o)};return Cl(n,r,{kind:`engine`,from:Ln(e,i),to:`net.${s}`,components:[i.component],...Dl(e,[i]),onWire:l})}function kl(e,t,n,r,i){let a=e.circuit.nets.find(e=>e.id===i),[o,s]=[r[0],r[r.length-1]],[c,l]=o&&s&&a?[El(e,a.pins,o),El(e,a.pins,s)]:[];return(c&&!l?Ol(e,t,n,r,c,!1,i):!c&&l?Ol(e,t,n,r,l,!0,i):void 0)||(!c||!l?Cl(n,r,{kind:`none`,reason:`The pins of this wire are not on the sheet`}):Cl(n,r,{kind:`engine`,from:Ln(e,c),to:Ln(e,l),components:[c.component,l.component],...Dl(e,[c,l])}))}function K(e,t,n){let r=e.schematic.wires.find(e=>e.id===n);if(!r)return;let i=r.points.map(e=>({x:e.x,y:e.y})),a=e.circuit.connections.find(e=>e.id===r.connection);return a?Tl(e,t,r.id,i,a):yl.test(r.id)?kl(e,t,r.id,i,r.net):Cl(r.id,i,{kind:`none`,reason:`This wire is not drawn from the code`})}function q(e,t,n=gr){let{writer:r}=t;if(r.kind===`none`)return r.reason;let i=xr(e,r.components,r.kind===`trace`?r.trace:void 0,n);return i===void 0?r.kind===`engine`?r.unaddressable??r.onWire?.blocked??null:r.repeat??br(r.trace)??null:`${i} is locked`}function Al(e,t){let n=e.slice(1,t.toNet?void 0:-1);return t.reversed?[...n].reverse():n}function jl(e,t){let[n,r]=[e[0],e[e.length-1]],[i,a]=[t.points[0],t.points[t.points.length-1]];return n!==void 0&&r!==void 0&&i!==void 0&&a!==void 0&&xl(n,i)&&xl(r,a)}var Ml=(e,t)=>e.length===t.length&&e.every((e,n)=>xl(e,t[n]));function Nl(e,t,n,r=gr,i=t.points){let a=q(e,t,r);if(a!==null)return{blocked:a};let o=fl(n);if(!jl(o,t))return{blocked:`The ends of a wire stay on their pins`};if(Ml(o,fl(i)))return[];let{writer:s}=t;if(s.kind===`trace`)return[{kind:`setTraceHints`,from:s.trace.from??``,to:s.trace.to??``,schematicRouteHints:Al(o,s)}];if(s.kind!==`engine`)return[];if(s.onWire)return vl(s.onWire,s.from,s.to,o);let c=o.slice(1,-1);return[{kind:`addTrace`,from:s.from,to:s.to,...c.length>0?{schematicRouteHints:c}:{}}]}var Pl=e=>({hover:e.hover,selected:e.selection,handleFill:e.handleFill});Pl(Ao);var Fl=3,Il=e=>Wc(Fl,e),Ll=[4,3],Rl=(e,t)=>{let n=Math.hypot(t.x-e.x,t.y-e.y);return{x:(t.x-e.x)/n,y:(t.y-e.y)/n}},zl=e=>({x:-e.y,y:e.x}),Bl=(e,t,n)=>({x:e.x+t.x*n,y:e.y+t.y*n});function Vl(e,t,n,r,i){let a=e[n];if(n===0)return Bl(Bl(a,t[0],-r),zl(t[0]),r*i);if(n===e.length-1)return Bl(Bl(a,t[n-1],r),zl(t[n-1]),r*i);let[o,s]=[zl(t[n-1]),zl(t[n])],c=o.x*s.x+o.y*s.y;return Bl(a,1+c<.1?o:{x:(o.x+s.x)/(1+c),y:(o.y+s.y)/(1+c)},r*i)}function Hl(e,t){let n=e.filter((t,n)=>n===0||t.x!==e[n-1]?.x||t.y!==e[n-1]?.y);if(n.length<2)return[];let r=n.slice(1).map((e,t)=>Rl(n[t],e)),i=e=>n.map((i,a)=>Vl(n,r,a,t,e));return[...i(1),...i(-1).reverse()]}function Ul(e,t,n,r,i,a){let o=Hl(r.map(e=>V(t,n,e)),Il(t.scale));o.length!==0&&(e.save(),e.strokeStyle=i.hover,e.lineWidth=Ko(a),e.setLineDash(Ll),e.beginPath(),o.forEach((t,n)=>n===0?e.moveTo(t.x,t.y):e.lineTo(t.x,t.y)),e.closePath(),e.stroke(),e.restore())}function Wl(e,t,n,r,i,a){let{corners:o,ends:s}=Xc(r),c=Yo(6,a),l=Ko(a),u=(r,i)=>{let o=V(t,n,r),[s,u]=[Jo(o.x-c/2,a),Jo(o.y-c/2,a)];i&&e.fillRect(s,u,c,c),e.strokeRect(s+l/2,u+l/2,c-l,c-l)};e.save(),e.fillStyle=i.handleFill,e.strokeStyle=i.selected,e.lineWidth=l,e.setLineDash([]);for(let e of o)u(e,!0);for(let e of s)u(e,!1);e.restore()}var Gl=e=>3/e,Kl=e=>Gc(e)/e;function ql(e,t,n,r){let i=t===void 0?void 0:e?.points(t),a=i?Zc(i,n,Gl(r)):void 0;return t===void 0||a===void 0?void 0:{id:t,index:a}}function Jl(e,t,n,r){let i=t.selection.soleWire;if(i!==void 0&&Va({kind:`wire`,id:i},t))return ql(e,i,n,r)}function Yl(e,t,n,r){if(r!==void 0)return{kind:`corner`,index:r};let i=Jc(e,t,Kl(n));return i===void 0?void 0:{kind:`segment`,index:i}}function Xl(e,t,n,r){let i=e[t.index];if(!i)return fl(e);let a={x:Te(i.x+n.x,r.step,r.snap),y:Te(i.y+n.y,r.step,r.snap)};return t.kind===`corner`?cl(e,t.index,a):sl(e,t.index,{x:a.x-i.x,y:a.y-i.y})}function Zl(e,t,n,r){let i=e?.points(t);if(e&&i)return{kind:`reshape`,wire:t,grip:n,points:i,path:i,start:r,moved:!1,blocker:e.blocker(t)}}function Ql(e,t,n,r){return e.blocker?(e.moved||r(e.blocker),{...e,moved:!0}):{...e,moved:!0,path:Xl(e.points,e.grip,t,n)}}var $l=`The wire changed while you dragged it; try again`;function eu(e,t,n){if(!e||!t.moved||t.blocker||Ml(t.path,fl(t.points)))return;let r=e.points(t.wire);if(!r||!Ml(r,t.points))return n($l);e.commit(t.wire,t.path)}function tu(e,t){return!e?.moved||e.blocker?t:[{id:e.wire,points:e.path},...t.filter(t=>t.id!==e.wire)]}function nu(e,t){return t.length===0?e:e.map(e=>{let n=t.find(t=>t.id===e.id);return n?{...e,points:[...n.points]}:e})}var ru=e=>e.missingLayer===void 0?{}:{missingLayer:e.missingLayer};function iu(e,t){return e.missingLayer===void 0?e.kind===`via`?t.multiLayer:(e.layer===`top`||e.layer===`bottom`)&&t[e.layer]:t.keepout}var au=2,ou=(e,t)=>Math.max(6,e*t/2+au)/t;function su(e,t,n,r,i){let a=e.find(e=>iu({kind:`via`,...ru(e)},r)&&Va({kind:`via`,id:e.id},i)&&Math.hypot(t.x-e.at.x,t.y-e.at.y)<=ou(e.diameter,n));return a&&{kind:`via`,id:a.id}}function cu(e,t){let n=1/0;for(let r=1;r<e.length;r++)n=Math.min(n,Kc(t,e[r-1],e[r]));return n}function lu(e,t,n,r,i){let a;for(let o of e){if(!iu({kind:`track`,layer:o.layer,...ru(o)},r)||!Va({kind:`track`,id:o.id},i))continue;let e=cu(o.points,t);e<=ou(o.width,n)&&(!a||e<a.distance)&&(a={id:o.id,distance:e})}return a&&{kind:`track`,id:a.id}}function uu(e,t,n,r,i){return su(e.vias,t,n,r,i)??lu(e.tracks,t,n,r,i)}function du(e,t,n,r,i){let a=uu(e,t,n,r,i),o=a?.kind===`track`?e.tracks.find(e=>e.id===a.id):void 0,s=o&&Jc(o.points,t,ou(o.width,n));return o&&s!==void 0?po(o,s):void 0}function fu(e,t,n,r,i=0){let a=r?Zc(e,t,Gl(n)):void 0;if(a!==void 0)return{kind:`corner`,index:a};let o=Jc(e,t,ou(i,n));return o===void 0?void 0:{kind:`segment`,index:o}}var pu=(e,t)=>{let n=e.map(e=>e.x),r=e.map(e=>e.y),i=e=>H(e);return{minX:i(Math.min(...n)-t),minY:i(Math.min(...r)-t),maxX:i(Math.max(...n)+t),maxY:i(Math.max(...r)+t)}};function mu(e,t){let n=e.tracks.filter(e=>iu({kind:`track`,layer:e.layer,...ru(e)},t)),r=e.vias.filter(e=>iu({kind:`via`,...ru(e)},t));return[...n.map(e=>({kind:`track`,id:e.id,box:pu(e.points,e.width/2)})),...r.map(e=>({kind:`via`,id:e.id,box:pu([e.at],e.diameter/2)}))]}function hu(e,t,n,r){let i=new Set($a(e,t,n,r));return e.filter(e=>i.has(e.id)).map(({kind:e,id:t})=>({kind:e,id:t}))}var gu=.4,_u=.7,vu=1.5,yu={top:W.topCopper,bottom:W.bottomCopper,inner1:W.topCopper,inner2:W.topCopper},bu=e=>e.missingLayer===void 0?yu[e.layer]:W.keepout,xu=e=>e.missingLayer===void 0?W.viaRing:W.keepout,Su=(e,t)=>iu({kind:`track`,layer:e.layer,...ru(e)},t),Cu=(e,t)=>iu({kind:`via`,...ru(e)},t),wu=(e,t)=>e&&(t===void 0||!e.nets.includes(t))?va:1;function Tu(e,t,n,r){e.strokeStyle=n,e.lineWidth=r,e.beginPath(),t.forEach((t,n)=>n===0?e.moveTo(t.x,t.y):e.lineTo(t.x,t.y)),e.stroke()}function Eu(e,t,n,r){e.fillStyle=r,e.beginPath(),e.arc(t.x,t.y,Math.max(n,0),0,Math.PI*2),e.fill()}function Du(e,t,n,r){let i=t.activeLayer??`top`,a=t.tracks.filter(e=>Su(e,n)),o=e=>e.layer===i||e.missingLayer!==void 0,s=[...a.filter(e=>!o(e)),...a.filter(o)];for(let t of s)e.globalAlpha=(o(t)?1:gu)*wu(r,t.net),Tu(e,t.points,bu(t),t.width);e.globalAlpha=1}function Ou(e,t,n,r){for(let i of t.vias.filter(e=>Cu(e,n)))e.globalAlpha=wu(r,i.net),Eu(e,i.at,i.diameter/2,xu(i)),n.hole&&Eu(e,i.at,i.drill/2,W.drill);e.globalAlpha=1}function ku(e,t,n){for(let{drawing:r,alpha:i}of t.routes??[]){e.globalAlpha=i;for(let t of r.tracks)iu({kind:`track`,layer:t.layer},n)&&Tu(e,t.points,yu[t.layer],t.width);if(iu({kind:`via`},n))for(let t of r.vias)Eu(e,t.at,t.diameter/2,W.viaRing),n.hole&&Eu(e,t.at,t.drill/2,W.drill)}e.globalAlpha=1}function Au(e,t,n){let{segment:r}=e;return n&&r?.id===t.id&&mo(r,t.points)?[r.from,r.to]:t.points}function ju(e,t,n,r,i,a,o){let s=t.tracks.find(e=>e.id===r);if(s&&Su(s,n)){let n=Au(t,s,a);Tu(e,n,i,s.width+2*vu*o),Tu(e,n,bu(s),s.width),a&&Tu(e,n,W.selectionFill,s.width);return}let c=t.vias.find(e=>e.id===r);c&&Cu(c,n)&&(Eu(e,c.at,c.diameter/2+vu*o,i),Eu(e,c.at,c.diameter/2,xu(c)),a&&Eu(e,c.at,c.diameter/2,W.selectionFill),n.hole&&Eu(e,c.at,c.drill/2,W.drill))}function Mu(e,t,n,r,i){Du(e,t,n,r),Ou(e,t,n,r),ku(e,t,n),t.hover!==void 0&&!t.selected.has(t.hover)&&ju(e,t,n,t.hover,W.hover,!1,i);for(let r of t.selected)ju(e,t,n,r,W.selection,!0,i)}var Nu=e=>e.pcb.board?.pours??[];function Pu(e,t){return e.outline??t?.outline??[]}function Fu(e,t){return e.circuit.nets.find(e=>e.id===t)?.names[0]??t}var Iu=(e,t)=>`pour ${Fu(e,t.net)} · ${t.layer}`,Lu=e=>`${Number(e.toFixed(4))} mm`,Ru=e=>`hole ${Lu(e.diameter)}`;function zu(e,t,n){return n.has(e.id)?!1:e.layer===`top`||e.layer===`bottom`?t[e.layer]:e.layer===`inner1`||e.layer===`inner2`}function Bu(e){return e.map((t,n)=>[t,e[(n+1)%e.length]])}function Vu(e,t,n,r,i){let a=6/n,o;for(let n of Nu(e))if(zu(n,r,i))for(let[r,i]of Bu(Pu(n,e.pcb.board))){let e=Kc(t,r,i);e<=a&&(!o||e<o.distance)&&(o={id:n.id,distance:e})}return o?.id}function Hu(e,t,n){let r=7/n,i=e.findIndex(e=>Math.hypot(e.x-t.x,e.y-t.y)<=r);return i===-1?void 0:i}function Uu(e,t,n,r){if(!r.hole)return;let i=3/n;return e.find(e=>Math.hypot(e.x-t.x,e.y-t.y)<=e.diameter/2+i)?.id}function Wu(e,t){let n=!1;for(let[r,i]of Bu(t))r.y>e.y!=i.y>e.y&&e.x<(i.x-r.x)*(e.y-r.y)/(i.y-r.y)+r.x&&(n=!n);return n}function Gu(e,t){return e.polygons.some(e=>Wu(t,e.outer)&&!e.holes.some(e=>Wu(t,e)))}function Ku(e,t,n,r,i){let a=e.pcb.pours.filter(e=>zu(e,n,r));return[...a.filter(e=>e.layer===i),...a.filter(e=>e.layer!==i)].find(e=>Gu(e,t))?.id}function qu(e,t){let n=e.pcb.holes.find(e=>e.id===t);if(n)return{x:n.x,y:n.y};let r=Nu(e).find(e=>e.id===t),i=r?Pu(r,e.pcb.board):[];if(i.length===0)return;let a=i.map(e=>e.x),o=i.map(e=>e.y);return{x:(Math.min(...a)+Math.max(...a))/2,y:(Math.min(...o)+Math.max(...o))/2}}var Ju=[`solid`,`hatched`,`outline`],Yu=`solid`,Xu=`copperflow.pourFill`,Zu=.35,Qu=e=>Ju.includes(e);function $u(e){try{let t=e()?.getItem(Xu);return Qu(t)?t:Yu}catch{return Yu}}function ed(e,t){try{let n=e();return n?(n.setItem(Xu,t),!0):!1}catch{return!1}}function td(e){return{pourSolid:e===`solid`,pourHatched:e===`hatched`,pourOutline:e===`outline`}}var nd={pourSolid:`solid`,pourHatched:`hatched`,pourOutline:`outline`},rd={top:W.topCopper,bottom:W.bottomCopper,inner1:W.inner1Copper,inner2:W.inner2Copper},id=rd,ad=.5,od=6,sd=1,cd=1.5;function ld(e,t){t.forEach((t,n)=>n===0?e.moveTo(t.x,t.y):e.lineTo(t.x,t.y)),e.closePath()}function ud(e,t){fd()&&e instanceof Path2D||e.beginPath();for(let n of t.polygons){ld(e,n.outer);for(let t of n.holes)ld(e,t)}}function J(e,t=0){let n=e.polygons.flatMap(e=>e.outer);if(n.length===0)return[];let r=n.map(e=>e.x),i=n.map(e=>e.y),[a,o,s,c]=[Math.min(...r),Math.max(...r),Math.min(...i),Math.max(...i)],l=c-s,u=a-l,d=o-u,f=Math.max(ad,6*t,d/399),p=Math.floor(d/f+1e-9)+1;return Array.from({length:p},(e,t)=>[{x:u+t*f,y:s},{x:u+t*f+l,y:c}])}var dd=new WeakMap,fd=()=>typeof Path2D==`function`;function pd(e){let t=dd.get(e);if(t)return t;let n={};return dd.set(e,n),n}function md(e){if(!fd())return;let t=pd(e);return t.rings||(t.rings=new Path2D,ud(t.rings,e)),t.rings}function hd(e,t){if(!fd())return;let n=pd(e);if(n.hatch?.px!==t){let r=new Path2D;for(let[n,i]of J(e,t))r.moveTo(n.x,n.y),r.lineTo(i.x,i.y);n.hatch={px:t,path:r}}return n.hatch.path}function gd(e,t,n){e.lineWidth=n;let r=md(t);if(r)return e.stroke(r);ud(e,t),e.stroke()}function _d(e,t,n){let r=md(t);if(r)return n===`fill`?e.fill(r,`evenodd`):e.clip(r,`evenodd`);ud(e,t),n===`fill`?e.fill(`evenodd`):e.clip(`evenodd`)}function vd(e,t,n){let r=hd(t,n);if(r)return e.stroke(r);e.beginPath();for(let[r,i]of J(t,n))e.moveTo(r.x,r.y),e.lineTo(i.x,i.y);e.stroke()}function yd(e,t,n,r){let i=id[t.layer]??W.topCopper;if(e.fillStyle=i,e.strokeStyle=i,n===`outline`)e.globalAlpha=1,gd(e,t,sd*r);else{if(e.globalAlpha=Zu,n===`solid`)return _d(e,t,`fill`);e.save(),_d(e,t,`clip`),e.lineWidth=sd*r,e.globalAlpha=1,vd(e,t,r),e.restore(),e.globalAlpha=1,gd(e,t,sd*r)}}function bd(e,t,n,r,i){let a=(t.pours??[]).filter(e=>zu(e,r,n.hidden)),o=[...a.filter(e=>e.layer!==n.activeLayer),...a.filter(e=>e.layer===n.activeLayer)];for(let t of o)yd(e,t,n.mode,i);e.globalAlpha=1}function xd(e,t,n){let r=n/2;e.beginPath(),e.moveTo(t.x-r,t.y-r),e.lineTo(t.x+r,t.y-r),e.lineTo(t.x+r,t.y+r),e.lineTo(t.x-r,t.y+r),e.closePath()}function Sd(e,t,n,r){if(e.strokeStyle=W.selection,e.lineWidth=cd*r,e.beginPath(),ld(e,t),e.stroke(),n){e.fillStyle=W.selection;for(let n of t)xd(e,n,od*r),e.fill()}}function Cd(e,t,n,r,i,a){if(r.selected.has(t.id))return Sd(e,n,t.outline!==void 0,i);let o=r.hover===t.id;(o||t.outline!==void 0)&&(e.strokeStyle=o?W.hover:id[t.layer]??W.topCopper,e.lineWidth=Math.max(a,sd*i),e.setLineDash([4*i,3*i]),e.beginPath(),ld(e,n),e.stroke(),e.setLineDash([]))}function wd(e,t,n){t.length<2||(e.strokeStyle=W.selection,e.lineWidth=sd*n,e.setLineDash([4*n,3*n]),e.beginPath(),ld(e,t),e.stroke(),e.setLineDash([]))}function Td(e,t,n,r,i,a){for(let o of t.board?.pours??[])zu(o,r,n.hidden)&&Cd(e,o,n.outlines?.get(o.id)??Pu(o,t.board),n,i,a);n.preview&&wd(e,n.preview,i)}function Ed(e,t,n,r,i,a){if(r.hole)for(let r of t){let t=r.diameter/2;e.fillStyle=W.drill,e.beginPath(),e.arc(r.x,r.y,t,0,Math.PI*2),e.fill();let o=n.selected.has(r.id);e.strokeStyle=o?W.selection:n.hover===r.id?W.hover:W.multiLayer,e.lineWidth=o?cd*i:a,e.stroke()}}var Y=(e,t=!1)=>({action:e,preventDefault:t}),Dd=new Map([[`ArrowLeft`,{action:`nudgeLeft`,dx:-1,dy:0}],[`ArrowRight`,{action:`nudgeRight`,dx:1,dy:0}],[`ArrowUp`,{action:`nudgeUp`,dx:0,dy:1}],[`ArrowDown`,{action:`nudgeDown`,dx:0,dy:-1}]]);function Od(e){for(let t of Dd.values())if(t.action===e)return{dx:t.dx,dy:t.dy}}function kd(e){let t=Dd.get(e.key);return!t||e.onButton||e.ctrlKey||e.metaKey||e.altKey?null:{action:t.action,preventDefault:!0,steps:e.shiftKey?10:1}}var Ad=`tr, [role='row'], [role='gridcell'], [role='grid'], [role='listbox'], [role='option'], [role='tree'], [role='treeitem'], [role='tablist'], [role='tab'], [role='radiogroup'], [role='menu'], [role='menubar'], [role='menuitem'], [role='menuitemcheckbox'], [data-keys='own']`,jd=`input:not([type='checkbox']):not([type='radio']), textarea, select, [contenteditable='true']`,Md=`button, a[href], summary, input[type='checkbox'], input[type='radio']`,Nd=`[data-keys='parts']`;function Pd(e){let t=e.target instanceof HTMLElement?e.target:null;return{key:e.key,code:e.code,shiftKey:e.shiftKey,altKey:e.altKey,ctrlKey:e.ctrlKey,metaKey:e.metaKey,altGraph:e.getModifierState?.(`AltGraph`)??!1,typing:t?.closest(jd)!=null,onButton:t?.closest(Md)!=null,ownsKeys:t?.closest(Ad)!=null,partRows:t?.closest(Nd)!=null,handled:e.defaultPrevented}}var Fd=e=>e.code?.startsWith(`Key`)?e.code.slice(3).toLowerCase():e.key.toLowerCase(),Id=new Map([[`w`,`wire`],[`n`,`armNetLabel`],[`b`,`drawBus`],[`l`,`drawPolyline`],[`r`,`drawRectangle`],[`c`,`drawCircle`],[`a`,`drawArc`],[`t`,`drawText`],[`j`,`junction`]]),Ld=new Map([[`w`,`route`],[`v`,`placeVia`]]);function Rd(e,t){if(e.shiftKey)return null;let n=Fd(e);if(n===`s`)return Y(`toggleSnap`,!0);let r=(t.view===`schematic`?Id:Ld).get(n);return r?Y(r,!0):null}function zd(e,t,n){switch(e){case`w`:return Y(n.view===`schematic`?`wire`:`route`);case`v`:return n.view===`pcb`?Y(`switchLayer`,!0):null;case`r`:return Y(`rotate`);case`k`:return Y(`fit`);case`f`:return t.shiftKey?Y(`openLibrary`,!0):Y(`fit`);case`h`:return t.shiftKey?Y(`clearHighlight`):Y(`highlight`);case`q`:return n.view===`pcb`?Y(`toggleUnit`):null;case`u`:return n.view===`pcb`?Y(t.shiftKey?`straightenTracks`:`filletTracks`,!0):null;case`l`:return n.view===`pcb`&&!t.shiftKey?Y(`routingCorner`,!0):null;case`x`:return n.view===`pcb`&&!t.shiftKey?Y(`flip`,!0):null;default:return null}}var Bd=new Map([[`[`,`toggleLeftPanel`],[`]`,`toggleRightPanel`],[`\\`,`toggleBottomPanel`]]),Vd=e=>!e.metaKey&&(e.altGraph===!0||e.ctrlKey&&e.altKey||!e.ctrlKey&&!e.altKey),Hd=new Map([[`z`,`undo`],[`y`,`redo`],[`o`,`openFile`],[`a`,`selectAll`],[`f`,`find`],[`c`,`copy`],[`v`,`paste`]]),Ud=new Map([[`z`,`redo`],[`l`,`alignLeft`],[`h`,`distributeH`],[`f`,`findSimilar`],[`x`,`placementTransfer`]]);function Wd(e){if(e.altKey||e.altGraph)return null;let t=(e.shiftKey?Ud:Hd).get(e.key.toLowerCase());return t?Y(t,t!==`copy`):null}function Gd(e,t){return t.drawing?e.key===`Backspace`&&!e.ownsKeys?Y(`removeCorner`,!0):null:Y(`delete`)}var Kd=e=>e.key===`Delete`||e.key===`Backspace`,qd=e=>e.ownsKeys===!0&&!(e.partRows===!0&&Kd(e)),Jd=e=>e.key===`ContextMenu`||e.key===`F10`&&e.shiftKey&&!e.ctrlKey&&!e.altKey&&!e.metaKey;function Yd(e,t){if(e.typing)return null;if(Jd(e))return Y(`contextMenu`,!0);let n=Bd.get(e.key);return n&&Vd(e)?Y(n):e.ctrlKey||e.metaKey?Wd(e):e.altKey?Rd(e,t):e.handled||qd(e)?null:kd(e)||(e.key===`Enter`?t.drawing&&!e.onButton&&!e.shiftKey?Y(`finishShape`,!0):null:Kd(e)?Gd(e,t):e.key===` `?e.onButton?null:Y(t.drawing?`flipBend`:`rotate`,!0):zd(e.key.toLowerCase(),e,t))}function Xd(e){return e.key===`Escape`&&!e.typing}var Zd=e=>Dt(e)+0,Qd=e=>Math.round((e%360+360)%360/90)%4;function $d(e,t){switch(Qd(t)){case 1:return{x:Zd(-e.y),y:Zd(e.x)};case 2:return{x:Zd(-e.x),y:Zd(-e.y)};case 3:return{x:Zd(e.y),y:Zd(-e.x)};default:return{x:Zd(e.x),y:Zd(e.y)}}}function ef(e,t){let n=$d(e,t.rotation);return{x:Zd(t.x+n.x),y:Zd(t.y+n.y)}}var tf={reference:`schNameAt`,value:`schValueAt`},nf=(e,t)=>`${e}:${t}`;function rf(e){let t=e.lastIndexOf(`:`);return t>0?{part:e.slice(0,t),prop:e.slice(t+1)}:void 0}function af(e,t,n){let r=Et*t*n/2;return{minX:e.x-r,maxX:e.x+r,minY:e.y-t/2,maxY:e.y+t/2}}function of(e){return e.symbol.shapes.flatMap(t=>{if(t.type!==`text`||t.role!==`reference`&&t.role!==`value`)return[];let n=ef(t.at,e),r=tf[t.role],i={x:Zd(n.x-e.x),y:Zd(n.y-e.y)};return[{id:nf(e.component,r),part:e.component,prop:r,text:t.text,at:n,offset:i,box:af(n,t.size,t.text.length)}]})}var sf=.8,cf={schematic:[`schNameAt`,`schValueAt`],pcb:[`pcbNameAt`]},lf={schNameAt:`Name`,schValueAt:`Value`,pcbNameAt:`Designator`};function uf(e){let t=rf(e)?.prop;if(t!==void 0)return cf.schematic.includes(t)?`schematic`:cf.pcb.includes(t)?`pcb`:void 0}function df(e){return e.symbols.flatMap(e=>of(e))}function ff(e){let t=ha(e),n={x:t.x-e.x,y:t.y-e.y},r=ga(e),i=af(t,sf,e.component.length),[a,o]=[(i.maxX-i.minX)/2,(i.maxY-i.minY)/2],s=r===90?{minX:t.x-o,maxX:t.x+o,minY:t.y-a,maxY:t.y+a}:i;return{id:nf(e.component,`pcbNameAt`),part:e.component,prop:`pcbNameAt`,text:e.component,at:t,offset:n,box:s,rotation:r}}function pf(e){return e.parts.map(ff)}function mf(e,t){return e===`pcb`?pf(t.pcb):df(t.schematic)}var hf=(e,t)=>t.x>=e.minX&&t.x<=e.maxX&&t.y>=e.minY&&t.y<=e.maxY,gf=e=>(e.maxX-e.minX)*(e.maxY-e.minY);function _f(e,t){return e.filter(e=>hf(e.box,t)).sort((e,t)=>gf(e.box)-gf(t.box))[0]}function vf(e,t){let n=t.x-e.at.x,r=t.y-e.at.y,{box:i}=e;return{...e,at:t,offset:{x:e.offset.x+n,y:e.offset.y+r},box:{minX:i.minX+n,maxX:i.maxX+n,minY:i.minY+r,maxY:i.maxY+r}}}function yf(e,t){return t.length===0?[...e]:e.map(e=>{let n=t.find(t=>t.id===e.id);return n?vf(e,n.at):e})}function bf(e,t){let n={x:e.at.x-e.offset.x,y:e.at.y-e.offset.y},r={x:H(t.x-n.x),y:H(t.y-n.y)};return H(e.offset.x)===r.x&&H(e.offset.y)===r.y?[]:[{kind:`setProps`,part:e.part,props:{[e.prop]:r}}]}function xf(e){let t=rf(e);return t?[{kind:`setProps`,part:t.part,props:{[t.prop]:null}}]:[]}function Sf(e,t){let n=rf(t);return n!==void 0&&e.model.parts.find(e=>e.name===n.part)?.props[n.prop]!==void 0}var Cf=(e,t)=>e.model.parts.find(e=>e.name===t)?.props.pcbNameRotation!==void 0;function wf(e,t,n){let r=rf(n),i=r&&e.model.parts.find(e=>e.name===r.part);if(!r||!i)return`This part has no editable source element`;if(t.has(i.name))return`${i.name} is locked`;if(!i.editable)return`${i.name} is read-only (${i.readonlyReason})`;let a=i.props[r.prop];return a&&!a.editable?`${i.name}.${r.prop} is an expression; change it in the code`:null}function Tf(e,t,n,r){let i=Af(e,t,n,r);return i?i.blocker??(i.moved?null:`It is where the layout puts it`):`It is not on this sheet`}function Ef(e,t,n){let r=t===`schNameAt`?`reference`:t===`schValueAt`?`value`:void 0,i=$d({x:n.x-e.x,y:n.y-e.y},-e.rotation),a=e.symbol.shapes.map(e=>e.type===`text`&&e.role===r?{...e,at:i,anchor:`center`}:e);return{...e,symbol:{...e.symbol,shapes:a}}}function Df(e,t){if(t.length===0)return e;let n=e.symbols.map(e=>t.reduce((t,n)=>{let r=rf(n.id);return r?.part===e.component?Ef(t,r.prop,n.at):t},e));return{...e,symbols:n}}function Of(e,t){if(t.length===0)return e;let n=e.parts.map(e=>{let n=t.find(t=>t.id===nf(e.component,`pcbNameAt`));return n?{...e,nameAt:n.at}:e});return{...e,parts:n}}var kf=e=>String(H(e));function Af(e,t,n,r){let i=uf(n),a=i&&mf(i,e).find(e=>e.id===n);if(!i||!a)return;let o=Sf(t,n),s=i===`pcb`?` mm`:``,c=[{label:`Part`,value:a.part},{label:`Text`,value:a.text},{label:`Offset X`,value:`${kf(a.offset.x)}${s}`},{label:`Offset Y`,value:`${kf(a.offset.y)}${s}`},{label:`Position`,value:o?`Moved (${a.prop})`:`Where the layout puts it`},...a.rotation===void 0?[]:[{label:`Turn`,value:`${a.rotation}°${Cf(t,a.part)?` (pcbNameRotation)`:``}`}]];return{title:lf[a.prop]??a.prop,rows:c,moved:o,blocker:wf(t,r,n)}}function jf(e,t,n){let r=e.soleText,i=Od(t.action);if(r!==void 0&&i)return{id:r,by:pt(i,n.step,t.steps??1,n.snap!==!1)}}var Mf={mode:`solid`,hidden:new Set,selected:new Set,activeLayer:`top`},Nf={x:0,y:0},Pf=1.5,Ff=.35,If=1.5,Lf=.6,Rf=.12,zf=1.5,Bf=.7,Vf=.5,Hf=1e-9,Uf=.25,Wf=.6,Gf=e=>e*Math.PI/180,Kf=(e,t,n)=>e[`${t.side===`top`?`top`:`bottom`}${n}`],qf=e=>e.autoPlaced?Wf:1,Jf=e=>e.side===`top`?W.topAssembly:W.bottomAssembly;function Yf(e,t,n,r){let i={...ka,...r.layers},{camera:a,size:o}=n,s=1/a.scale,c=Zo(s,r.ratio),l=e=>r.moving?.components.includes(e.component)?r.moving.by:Nf,u=n=>{for(let r of t.parts)ep(e,l(r).x,l(r).y,0,()=>{e.globalAlpha=qf(r),n(r)});e.globalAlpha=1};e.save(),e.setTransform(...Qf(n,r.ratio)),e.lineCap=`round`,e.lineJoin=`round`,i.keepout&&op(e,t,s,c);let d=r.pours??Mf;bd(e,t,d,i,s),up(e,i,r.highlight,u,s),r.copper&&Mu(e,r.copper,i,r.highlight,s),i.hole&&fp(e,u),Ed(e,t.holes??[],d,i,s,c),Td(e,t,d,i,s,c),u(t=>{Kf(i,t,`Silk`)&&pp(e,t.silkscreen,t.side===`top`?W.topSilk:W.bottomSilk,Math.max(Rf,c),!1)}),i.courtyard&&mp(e,u,s,c),u(t=>{Kf(i,t,`Assembly`)&&pp(e,t.fabrication,Jf(t),c,!1)}),i.boardOutline&&ap(e,t,()=>{e.strokeStyle=W.boardEdge,e.lineWidth=zf*s,e.stroke()}),r.ratsnest!==!1&&i.ratline&&hp(e,t,r,c),e.setTransform(r.ratio,0,0,r.ratio,0,0),cs(e);for(let n of t.parts)Kf(i,n,`Silk`)&&_p(e,n,a,o,l(n),r.ratio);Do(e,n,r.violations??[],r.activeViolation,!0),e.restore()}function Xf(e,t,n,r){for(let i of e.parts){if(r&&!r(i.component))continue;let e=i.pads.find(e=>(!n||n[Na(e)])&&yp(e,t));if(e)return e}}function Zf(e){return e.parts.map(e=>{let t=$f(e);return{name:e.component,pcbComponentId:e.component,center:{x:(t.minX+t.maxX)/2,y:(t.minY+t.maxY)/2},box:t}})}function Qf({camera:e,size:t},n){let r=e.scale*n;return[r,0,0,-r,(t.width/2-e.cx*e.scale)*n,(t.height/2+e.cy*e.scale)*n]}function $f(e){let t=e.courtyard.map(e=>e.x),n=e.courtyard.map(e=>e.y);return{minX:Math.min(...t),minY:Math.min(...n),maxX:Math.max(...t),maxY:Math.max(...n)}}function ep(e,t,n,r,i){e.save(),e.translate(t,n),r&&e.rotate(Gf(r)),i(),e.restore()}function tp(e,t){e.beginPath(),t.forEach((t,n)=>n===0?e.moveTo(t.x,t.y):e.lineTo(t.x,t.y)),e.closePath()}function np(e,t,n,r){e.beginPath(),e.arc(t,n,Math.max(r,0),0,Math.PI*2)}function rp(e,t,n,r){let i=Math.max(0,Math.min(r,t/2,n/2)),a=-t/2,o=-n/2;e.beginPath(),e.moveTo(a+i,o),e.arcTo(a+t,o,a+t,o+n,i),e.arcTo(a+t,o+n,a,o+n,i),e.arcTo(a,o+n,a,o,i),e.arcTo(a,o,a+t,o,i),e.closePath()}var ip=(e,t,n)=>rp(e,t,n,Math.min(t,n)/2);function ap(e,t,n){let r=t.board?.outline;!r||r.length<3||(tp(e,r),n())}function op(e,t,n,r){let i=t.board?.keepouts??[];if(i.length!==0){e.strokeStyle=W.keepout,e.globalAlpha=Bf;for(let t of i){e.lineWidth=r,e.setLineDash([4*n,3*n]),tp(e,t.outline),e.stroke(),e.setLineDash([]),e.save(),tp(e,t.outline),e.clip();for(let[n,r]of sp(t.outline))gp(e,n,r);e.restore()}e.globalAlpha=1}}function sp(e){let t=e.map(e=>e.x),n=e.map(e=>e.y),[r,i,a,o]=[Math.min(...t),Math.max(...t),Math.min(...n),Math.max(...n)];if(![r,i,a,o].every(Number.isFinite))return[];let s=o-a,c=r-s,l=i-c,u=Math.max(Vf,l/399),d=Math.floor(l/u+Hf)+1;return Array.from({length:d},(e,t)=>{let n=c+t*u;return[{x:n,y:a},{x:n+s,y:o}]})}function cp(e,t){ep(e,t.x,t.y,t.rotation,()=>{t.shape===`circle`?np(e,0,0,t.width/2):t.shape===`oval`?ip(e,t.width,t.height):rp(e,t.width,t.height,t.shape===`roundrect`?t.cornerRadius??Uf*Math.min(t.width,t.height):0)})}function lp(e){return e.layers===`through`?W.multiLayer:e.layers===`bottom`?W.bottomCopper:W.topCopper}function up(e,t,n,r,i){let a=[[t.bottom,e=>e.layers===`bottom`],[t.top,e=>e.layers===`top`],[t.multiLayer,e=>e.layers===`through`]];for(let[t,o]of a)t&&r(t=>{for(let r of t.pads.filter(o)){let a=n!==void 0&&r.net!==void 0&&n.nets.includes(r.net);e.globalAlpha=(n&&!a?va:1)*qf(t),e.fillStyle=lp(r),cp(e,r),e.fill(),a&&dp(e,r,i,qf(t))}});e.globalAlpha=1}function dp(e,t,n,r){e.globalAlpha=Ff*r,e.fillStyle=W.highlight,cp(e,t),e.fill(),e.globalAlpha=r,e.strokeStyle=W.highlight,e.lineWidth=If*n,e.stroke()}function fp(e,t){e.fillStyle=W.drill,t(t=>{for(let n of t.pads){let{drill:t}=n;t&&(t.width===t.height?np(e,n.x,n.y,t.width/2):ep(e,n.x,n.y,n.rotation,()=>ip(e,t.width,t.height)),e.fill())}})}function pp(e,t,n,r,i){e.strokeStyle=n,e.lineWidth=r;for(let n of t)n.length<2||(e.beginPath(),n.forEach((t,n)=>n===0?e.moveTo(t.x,t.y):e.lineTo(t.x,t.y)),i&&e.closePath(),e.stroke())}function mp(e,t,n,r){e.setLineDash([4*n,3*n]),t(t=>{e.globalAlpha=1,pp(e,[t.courtyard],Jf(t),t.autoPlaced?Pf*n:r,!0)}),e.setLineDash([])}function hp(e,t,n,r){let i=n.moving,a=new Set(t.parts.filter(e=>i?.components.includes(e.component)).flatMap(e=>e.pads.map(e=>e.id))),o=(e,t)=>i&&a.has(t)?{x:e.x+i.by.x,y:e.y+i.by.y}:e;e.lineWidth=r;for(let r of t.ratsnest){let t=n.highlight?.nets.includes(r.net)??!1;e.strokeStyle=t?W.highlight:W.ratsnest,e.globalAlpha=t?1:n.highlight?Lf*va:Lf,gp(e,o(r.a,r.from),o(r.b,r.to))}e.globalAlpha=1}function gp(e,t,n){e.beginPath(),e.moveTo(t.x,t.y),e.lineTo(n.x,n.y),e.stroke()}function _p(e,t,n,r,i,a){let o=is(sf,n.scale,a);if(!rs(`name`,o,o))return;let s=ha(t),c=ss(V(n,r,{x:s.x+i.x,y:s.y+i.y}),a);e.fillStyle=t.side===`top`?W.topSilk:W.bottomSilk,e.globalAlpha=qf(t),e.font=Sa(xa.strong,o/a),e.textAlign=`center`,e.textBaseline=`middle`,ga(t)===90?(e.save(),e.translate(c.x,c.y),e.rotate(-Math.PI/2),e.fillText(t.component,0,0),e.restore()):e.fillText(t.component,c.x,c.y),e.globalAlpha=1}function vp(e,t,n,r){let i;for(let a of e.parts)for(let e of a.pads){if(r&&!r[Na(e)])continue;let a=xp(e,t);a<=n&&(!i||a<i.distance)&&(i={pad:e,distance:a})}return i?.pad}var yp=(e,t)=>xp(e,t)<=0;function bp(e,t){let n=Gf(-e.rotation),r=t.x-e.x,i=t.y-e.y;return{x:r*Math.cos(n)-i*Math.sin(n),y:r*Math.sin(n)+i*Math.cos(n)}}function xp(e,t){let{x:n,y:r}=bp(e,t);return e.shape===`circle`?Math.max(0,Math.hypot(n,r)-e.width/2):e.shape===`oval`?Sp(n,r,e.width,e.height):Math.hypot(Math.max(0,Math.abs(n)-e.width/2),Math.max(0,Math.abs(r)-e.height/2))}function Sp(e,t,n,r){let i=Math.min(n,r)/2,a=Math.max(n,r)/2-i,[o,s]=n>=r?[Math.max(-a,Math.min(a,e)),0]:[0,Math.max(-a,Math.min(a,t))];return Math.max(0,Math.hypot(e-o,t-s)-i)}function Cp(e,t,n){let r=Yc(e.schematic.wires,t,n);return e.schematic.wires.find(e=>e.id===r)?.net}function wp(e,t,n){let r=Jn(e,t,n);if(r)return e.circuit.nets.find(e=>e.pins.includes(r.pin))?.id;let i=Ar(e,t)?.net??Cp(e,t,n);return i===void 0?void 0:Tp(e.circuit.nets,i)}function Tp(e,t){if(e.some(e=>e.id===t))return t;let n=t.startsWith(`net.`)?t.slice(4):void 0;return e.find(e=>n!==void 0&&e.names.includes(n))?.id??t}var Ep=[];function Dp(e,t){let n=t.flatMap(t=>e.circuit.nets.filter(e=>e.id===t)),r=n[0];if(!r)return;let i=[...new Set(n.flatMap(e=>e.pins))],a=[...new Set(n.flatMap(e=>[e.id,...e.names.map(e=>`net.${e}`)]))];return{net:r.id,pins:i,aliases:a}}function Op(e,t){let n=(e.circuit.components.find(e=>e.id===t)?.pins??[]).flatMap(t=>e.circuit.nets.filter(e=>e.pins.includes(t.id)).map(e=>e.id));return[...new Set(n)]}function kp(e,t){if(e.length===0)return{message:`Point at a net and press H.`};let n=[...new Set(e.flatMap(t))];return n.length>0?{nets:n}:{message:`${st(e)} ${e.length===1?`is`:`are`} on no net.`}}function Ap(e,t,n,r=()=>void 0){let i=[...new Set([...e.wires.flatMap(e=>t(e)??[]),...e.labels.flatMap(e=>r(e)??[])])],a=kp(e.names,n);return`nets`in a?{nets:[...new Set([...i,...a.nets])]}:i.length>0?{nets:i}:a}function jp(e,t,n){if(n.circuit.nets.some(t=>t.id===e))return e;let r=t?.circuit.nets.find(t=>t.id===e)?.pins[0];return r!==void 0&&n.circuit.nets.find(e=>e.pins.includes(r))?.id||void 0}function Mp(e,t,n){let r=[...new Set(e.flatMap(e=>jp(e,t,n)??[]))];return r.length===e.length&&r.every((t,n)=>t===e[n])?e:r.length===0?Ep:r}function Np(e,t,n){return Xf(e,t,n)?.net??void 0}var Pp=e=>e.startsWith(`drawing:`)||e.includes(`~`),Fp=e=>JSON.stringify({...e,source:void 0}),Ip=(e,t)=>e.filter(e=>e.kind===t).length,Lp=(e,t)=>t.some(t=>t.id.startsWith(`${e}~`));function Rp(e,t,n,r){return!Pp(t.id)&&!Lp(t.id,n)&&!Lp(t.id,r)?!0:e.kind===t.kind?Ip(n,t.kind)===Ip(r,t.kind)||Fp(e)===Fp(t):!1}function zp(e,t){let n=new Map((e??[]).map(e=>[e.id,e]));return t.flatMap(r=>{let i=n.get(r.id);return!e||!i||Rp(i,r,e,t)?[r.id]:[]})}function Bp(e,t,n){let r=e=>n.some(t=>t.id===e.to);return{selection:t.filter(r).reduce((e,{from:t,to:n})=>e.hasDrawing(t)?e.withoutDrawings([t]).addDrawings([n]):e,e),waiting:t.filter(e=>!r(e))}}function Vp(e,t,n){return e.drawingCount===0?e:e.keepDrawings(zp(t,n))}var Hp=/^[ADPF]?GND\w*$|^VSS\w*$/i,Up=/^(VCC|VDD|VBUS|VIN|V\d|\+)/i,Wp=new Intl.Collator(`en`,{numeric:!0});function Gp(e){return Hp.test(e)?`ground`:Up.test(e)?`power`:void 0}function Kp(e){for(let t of e){let e=Gp(t);if(e)return e}}var qp=e=>e.find(e=>Gp(e))??e[0];function Jp(e){return qp(e.names)??`(unnamed) ${e.pins[0]??e.id}`}function Yp(e){if(e.length===void 0)return``;let t=e.partner===void 0?``:`, pair ${e.partner}${e.skew===void 0?``:`, skew ${e.skew.toFixed(1)} mm`}`;return`${e.length.toFixed(1)} mm${t}`}function Xp(e){let t=new Map((e.lines??[]).map(e=>[e.net,e])),n=new Map(e.circuit.nets.map(e=>[e.id,e]));return e.circuit.nets.map(e=>{let r=qp(e.names),i=Kp(e.names),a=t.get(e.id),o=a?.partner===void 0?void 0:n.get(a.partner);return{id:e.id,label:Jp(e),pins:e.pins.length,named:r!==void 0,...i?{badge:i}:{},...a?{length:a.length}:{},...o?{partner:Jp(o)}:{},...a?.skew===void 0?{}:{skew:a.skew}}}).sort((e,t)=>Number(t.named)-Number(e.named)||Wp.compare(e.label,t.label))}function Zp(e,t,n,r){let i=new Map,a=[],o=[];for(let s of t){let t=Nr(e,s);t?.wire!==void 0&&(r.includes(t.wire)||n(t.part))?i.set(t.wire,s):t&&t.wire===void 0&&n(t.part)?a.push(s):o.push(s)}return{riding:i,onPins:a,alone:o}}var Qp=(e,t)=>e.schematic.labels.find(e=>e.id===t);function $p(e,t){let n=e?Fr(e):`the label`;return`${n.charAt(0).toUpperCase()}${n.slice(1)}: ${t}`}function em(e,t,n,r,i,a){let o=Qp(e,n),s={edits:[],shown:[],names:[],notes:[]};if(!o)return s;let c={x:H(o.at.x+r.x),y:H(o.at.y+r.y)},l=Kr(e,t,n,c,i);if(!Array.isArray(l))return a.includes(l.blocked)?s:{...s,notes:[$p(o,l.blocked)]};let u=l.length>0?Vr(e,n,c):void 0;return u?{edits:l,shown:[{id:n,...u}],names:[Fr(o)],notes:[]}:s}function tm(e,t,n,r,i,a){let o=n.map(n=>em(e,t,n,r,i,a));return{edits:o.flatMap(e=>e.edits),shown:o.flatMap(e=>e.shown),names:o.flatMap(e=>e.names),notes:o.flatMap(e=>e.notes)}}function nm(e,t){return t.flatMap(t=>{let n=Qp(e,t);return n?[Fr(n)]:[]})}var rm=e=>e.length>1?[`${e.length} labels`]:[...e];function im(e,t,n,r){if(r.has(e))return e;let i=t&&Pr(t,e);return i===void 0?void 0:n.schematic.labels.find(e=>Pr(n,e.id)===i)?.id}function am(e,t,n){if(e.labelCount===0)return e;let r=new Set(n.schematic.labels.map(e=>e.id)),i=e.labels.flatMap(e=>im(e,t,n,r)??[]);return e.all(e.names,e.wires,i,e.drawings)}var om=(e,t)=>e.slice(`label:${t}:`.length);function sm(e,t,n){let r=e.schematic.labels.find(e=>e.id===t),i=Nr(e,t);return i?.wire===void 0?i&&n.has(i.part)?{kind:`part`,label:t}:r?{kind:`skipped`,reason:$p(r,`Studio places it on ${om(t,r.net)} for its net; delete that pin's part or wire instead`)}:{kind:`gone`}:{kind:`wire`,label:t,wire:i.wire}}function cm(e,t,n){let r=t.map(t=>sm(e,t,n));return{withWires:r.flatMap(e=>e.kind===`wire`?[{label:e.label,wire:e.wire}]:[]),withParts:r.flatMap(e=>e.kind===`part`?[e.label]:[]),skipped:r.flatMap(e=>e.kind===`skipped`?[e.reason]:[])}}function lm(e,t){let n=e.schematic.labels.find(e=>e.id===t);if(!n)return;let r=Tp(e.circuit.nets,n.net),i=e.circuit.nets.find(e=>e.id===r),a=Nr(e,t)?.wire===void 0?`At a pin`:`Hand-drawn`;return{net:r,rows:[{label:`Net`,value:i?Jp(i):r.replace(/^net\./,``)},{label:`Text`,value:n.text},{label:`Kind`,value:a}]}}var um=e=>`${e.x},${e.y}`;function dm(e){let t=new Map(e.symbols.flatMap(e=>Object.entries(e.pinEnds).map(([e,t])=>[um(t),e])));return e.wires.map(e=>{let[n,r]=[e.points[0],e.points[e.points.length-1]],i=n&&r?[t.get(um(n)),t.get(um(r))]:[],a=i.length===2&&i.every(e=>e!==void 0);return e.connection===void 0&&a?{...e,ends:i}:e})}var fm=(e,t)=>e.x===t.x&&e.y===t.y;function pm(e,t){if(e.ends&&t.ends)return e.ends.length===t.ends.length&&e.ends.every(e=>t.ends?.includes(e));let[n,r,i,a]=[e.points[0],e.points[e.points.length-1],t.points[0],t.points[t.points.length-1]];return!n||!r||!i||!a?!1:fm(n,i)&&fm(r,a)||fm(n,a)&&fm(r,i)}function mm(e,t,n){let r=n.find(t=>t.id===e),i=t?.find(t=>t.id===e);return!r||r.connection===void 0&&i!==void 0&&!pm(i,r)}function hm(e,t,n){return e.withoutWires(e.wires.filter(e=>mm(e,t,n)))}function gm(e,t){let n=t.parts?e.keep(t.parts):e,r=t.view===`schematic`,i=e=>r?e??[]:[],a=r?[]:t.copper??[],o=r?[]:t.board??[];return n.keepWires(i(t.wires)).keepLabels(i(t.labels)).keepDrawings(i(t.drawings)).keepCopper(a).keepTexts(t.texts??[]).keepBoard(o)}var _m=[{id:`library`,label:`Library`},{id:`log`,label:`Log`},{id:`drc`,label:`DRC`},{id:`find`,label:`Find Results`}],vm=`bottom-panel`,ym=e=>`bottom-tab-${e}`,bm={open:!1,tab:`drc`};function xm(e,t){return e.open&&e.tab===t?{...e,open:!1}:{open:!0,tab:t}}function Sm(e){return{...e,open:!e.open}}function Cm(e,t){return{open:!0,tab:t}}function wm(e){return e.detail>0}var Tm=`button, input[type='checkbox']`;function Em(e){e.target instanceof HTMLElement&&e.target.closest(Tm)?.blur()}function Dm(e,t,n){return t>0||e===`checkbox`&&!n}function Om(e,t,n){return e===null||e===t||(n?.contains(e)??!1)}function km(e){let t=e.target instanceof HTMLElement?e.target.closest(Tm):null;t&&Dm(t instanceof HTMLInputElement?`checkbox`:`button`,e.detail,t.matches(`:focus-visible`))&&t.blur()}var Am=new Set([`ArrowLeft`,`ArrowUp`]),jm=new Set([`ArrowRight`,`ArrowDown`]);function Mm(e,t,n){if(e.length===0)return null;if(n===`Home`)return e[0]??null;if(n===`End`)return e[e.length-1]??null;let r=Am.has(n)?-1:+!!jm.has(n);return r===0?null:e[(Math.max(0,e.indexOf(t))+r+e.length)%e.length]??null}function Nm({ids:e,current:t,onSelect:n,onPointerClick:r}){return{onKeyDown:r=>{let i=Mm(e,t,r.key);i!==null&&(r.preventDefault(),r.stopPropagation(),n(i),r.currentTarget.querySelector(`[data-tab="${i}"]`)?.focus())},tab:e=>({"data-tab":e,tabIndex:e===t?0:-1,onClick:t=>{if(!wm(t))return n(e);Em(t),(r??n)(e)}})}}var Pm=o((e=>{var t=Symbol.for(`react.transitional.element`),n=Symbol.for(`react.fragment`);function r(e,n,r){var i=null;if(r!==void 0&&(i=``+r),n.key!==void 0&&(i=``+n.key),`key`in n)for(var a in r={},n)a!==`key`&&(r[a]=n[a]);else r=n;return n=r.ref,{$$typeof:t,type:e,key:i,ref:n===void 0?null:n,props:r}}e.Fragment=n,e.jsx=r,e.jsxs=r})),Fm=o(((e,t)=>{t.exports=Pm()})),X=Fm(),Im=_m.map(e=>e.id);function Lm({state:e,onClick:t,onOpen:n}){let r=Nm({ids:Im,current:e.tab,onSelect:n,onPointerClick:t});return(0,X.jsx)(`nav`,{className:`bottom-strip hairline-t`,role:`tablist`,"aria-label":`Bottom panel`,onKeyDown:r.onKeyDown,children:_m.map(t=>{let n=e.open&&e.tab===t.id;return(0,X.jsx)(`button`,{role:`tab`,id:ym(t.id),"aria-controls":vm,className:`bottom-tab${n?` on`:``}`,"aria-selected":n,...r.tab(t.id),children:(0,X.jsx)(`span`,{className:`bottom-tab-label`,children:t.label})},t.id)})})}function Rm(e){return{"--dpr":String(Number.isFinite(e)&&e>0?e:1)}}function zm(e){let t=e.document.documentElement,n,r=()=>{for(let[n,r]of Object.entries(Rm(e.devicePixelRatio)))t.style.setProperty(n,r);n?.removeEventListener(`change`,r),n=e.matchMedia(`(resolution: ${e.devicePixelRatio}dppx)`),n.addEventListener(`change`,r)};return r(),e.addEventListener(`resize`,r),()=>{e.removeEventListener(`resize`,r),n?.removeEventListener(`change`,r)}}var Z=(e,t)=>t?{tag:`path`,d:e,dash:t}:{tag:`path`,d:e},Bm=(e,t,n,r)=>r?{tag:`circle`,cx:e,cy:t,r:n,fill:r}:{tag:`circle`,cx:e,cy:t,r:n},Vm=(e,t,n,r,i=1,a)=>a?{tag:`rect`,x:e,y:t,width:n,height:r,rx:i,fill:a}:{tag:`rect`,x:e,y:t,width:n,height:r,rx:i},Hm=Z(`M2.5 5.5v-3h3M10.5 2.5h3v3M13.5 10.5v3h-3M5.5 13.5h-3v-3`),Um=[Vm(3,7,10,7,1.5),Z(`M8 10v1.5`)],Wm=[4,8,12].flatMap(e=>[4,8,12].map(t=>Bm(t,e,1,!0))),Gm={lock:[...Um,Z(`M5.5 7V5a2.5 2.5 0 0 1 5 0v2`)],unlock:[...Um,Z(`M5.5 7V5a2.5 2.5 0 0 1 5 0`)],padlock:[Vm(2.5,7,11,7.5,1.5),Z(`M5 7V5a3 3 0 0 1 6 0v2`),Z(`M8 10v2`)],padlockOpen:[Vm(2.5,7,11,7.5,1.5),Z(`M11 7V4a3 3 0 0 0-6 0v.5`),Z(`M8 10v2`)],trash:[Z(`M2.5 4.5h11M6 4.5V2.5h4v2`),Z(`M4 4.5l.5 9h7l.5-9`),Z(`M6.5 7v4M9.5 7v4`)],close:[Z(`M4 4l8 8M12 4l-8 8`)],chevron:[Z(`M6 4l4 4-4 4`)],eye:[Z(`M1.5 8S4 3.5 8 3.5 14.5 8 14.5 8 12 12.5 8 12.5 1.5 8 1.5 8z`),Bm(8,8,2)],eyeOff:[Z(`M1.5 8S4 3.5 8 3.5 14.5 8 14.5 8 12 12.5 8 12.5 1.5 8 1.5 8z`),Bm(8,8,2),Z(`M2.5 2.5l11 11`)],undo:[Z(`M5.5 3 3 5.5 5.5 8`),Z(`M3 5.5h6.5a3.5 3.5 0 0 1 0 7h-3`)],redo:[Z(`M10.5 3 13 5.5 10.5 8`),Z(`M13 5.5H6.5a3.5 3.5 0 0 0 0 7h3`)],zoomIn:[Bm(7,7,4.5),Z(`M10.5 10.5 14 14M7 5v4M5 7h4`)],zoomOut:[Bm(7,7,4.5),Z(`M10.5 10.5 14 14M5 7h4`)],fit:[Hm,Vm(6,6,4,4,.5)],fitSelection:[Hm,Vm(5.5,5.5,5,5,1,!0)],fitArea:[Vm(2.5,2.5,8,8,1),Z(`M7 7l6.5 6.5M13.5 9.5v4h-4`)].map(e=>e.tag===`rect`?{...e,dash:`2 2`}:e),grid:Wm,snap:[Z(`M3.5 2.5V8a4.5 4.5 0 0 0 9 0V2.5h-3V8a1.5 1.5 0 0 1-3 0V2.5z`),Z(`M3.5 5h3M9.5 5h3`)],component:[Vm(4.5,3,7,10,1),Z(`M2 6h2.5M2 10h2.5M11.5 6H14M11.5 10H14`)],wire:[Bm(3.5,12.5,1.5),Bm(12.5,3.5,1.5),Z(`M5 12.5h3.5v-9H11`)],netLabel:[Z(`M1.5 8h2`),Z(`M5.5 4.5h8v7h-8L3.5 8z`),Z(`M8 8h3`)],bus:[Z(`M2 10.5h12`,void 0),Z(`M5.5 10.5l2-4.5M9.5 10.5l2-4.5`)],polyline:[Z(`M2 13l3.5-7 4 4 4.5-7`)],arc:[Z(`M3 12a5 5 0 0 1 10 0`)],circle:[Bm(8,8,5.5)],rectangle:[Vm(2.5,4.5,11,7,0)],text:[Z(`M3.5 4.5V3h9v1.5M8 3v10M6 13h4`)],ground:[Z(`M8 2.5v6M3 8.5h10M5 11h6M7 13.5h2`)],power:[Z(`M8 14V5.5M3.5 5.5h9`),Z(`M3.5 5.5 8 2l4.5 3.5`)],noConnect:[Z(`M2 8h5`),Z(`M9 5.5l5 5M14 5.5l-5 5`)],via:[Bm(8,8,5.5),Bm(8,8,2)],boardOutline:[Z(`M2.5 3.5h8l3 3v6h-11z`)],copperArea:[Vm(2.5,2.5,11,11,1),Z(`M5.5 10.5l5-5M5.5 7.5l2-2M8.5 10.5l2-2`)],singleRouting:[Bm(3.5,12.5,1.5),Z(`M5 12.5h3.5L12 9V3.5`)],gerber:[Z(`M8 2.5 2.5 5 8 7.5 13.5 5z`),Z(`M2.5 8 8 10.5 13.5 8`),Z(`M2.5 11 8 13.5 13.5 11`)],rotate:[Z(`M3 8a5 5 0 1 0 5-5`),Z(`M9.5 1.5 8 3l1.5 1.5`)],rotateRight:[Z(`M13 8a5 5 0 1 1-5-5`),Z(`M6.5 1.5 8 3 6.5 4.5`)],alignLeft:[Z(`M2.5 2v12`),Vm(5,3.5,8.5,3.5,1),Vm(5,9,5,3.5,1)],distributeH:[Z(`M2.5 2v12M13.5 2v12`),Vm(6,4,4,8,1)],check:[Z(`M8 1.5 3 3.5v4c0 3 2 5.5 5 6.5 3-1 5-3.5 5-6.5v-4z`),Z(`M5.5 8l2 2 3-3.5`)]},Km={width:16,height:16,viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:1.5,strokeLinecap:`round`,strokeLinejoin:`round`,shapeRendering:`geometricPrecision`,"aria-hidden":!0};function qm(e,t){let{tag:n,fill:r,dash:i,...a}=e;return{key:t,...a,...r?{fill:`currentColor`,stroke:`none`}:{},...i?{strokeDasharray:i}:{}}}function Jm(e,t={}){let n=Gm[e];return(0,_.createElement)(`svg`,{...Km,...t},...n.map((e,t)=>(0,_.createElement)(e.tag,qm(e,t))))}var Ym=e=>Jm(`lock`,e),Xm=e=>Jm(`unlock`,e),Zm=e=>Jm(`padlock`,e),Qm=e=>Jm(`padlockOpen`,e),$m=e=>Jm(`rotate`,e),eh=e=>Jm(`trash`,e),th=e=>Jm(`undo`,e),nh=e=>Jm(`close`,e),rh=e=>Jm(`chevron`,e),ih=({off:e,...t})=>Jm(e?`eyeOff`:`eye`,t),ah=e=>t=>Jm(e,t),oh={undo:ah(`undo`),redo:ah(`redo`),zoomIn:ah(`zoomIn`),zoomOut:ah(`zoomOut`),fit:ah(`fit`),fitSelection:ah(`fitSelection`),fitArea:ah(`fitArea`),component:ah(`component`),wire:ah(`wire`),netLabel:ah(`netLabel`),ground:ah(`ground`),power:ah(`power`),rotate:ah(`rotate`),rotateRight:ah(`rotateRight`),snap:ah(`snap`),check:ah(`check`),grid:ah(`grid`),alignLeft:ah(`alignLeft`),distributeH:ah(`distributeH`),polyline:ah(`polyline`),arc:ah(`arc`),circle:ah(`circle`),rectangle:ah(`rectangle`),text:ah(`text`),bus:ah(`bus`),noConnect:ah(`noConnect`),via:ah(`via`),boardOutline:ah(`boardOutline`),copperArea:ah(`copperArea`),singleRouting:ah(`singleRouting`),gerber:ah(`gerber`)};function sh(e){return e===`Escape`?`close`:e===`Tab`?`trap`:`hold`}function ch(e,t,n){return t<=0?-1:e<0||e>=t?n?t-1:0:(e+(n?-1:1)+t)%t}function lh(){let e=[];return{hold(t){return e=[...e,t],()=>{e=e.filter(e=>e!==t)}},held(){return e.length>0},dispatch(t){let n=e.at(-1);return n?(n(t),t.stopImmediatePropagation(),!0):!1}}}var uh=lh();function dh(e){let t=e=>void uh.dispatch(e);return e.addEventListener(`keydown`,t,!0),()=>e.removeEventListener(`keydown`,t,!0)}function fh(e,t){let n=(0,_.useRef)(t);(0,_.useLayoutEffect)(()=>{n.current=t}),(0,_.useEffect)(()=>e?uh.hold(e=>n.current(e)):void 0,[e])}var ph=[`fitSelection`,`rotateRight`,`selectInstance`,`replicateLayout`,`makeSheet`,`autorouteSelection`,`autoplaceSelection`,`autoplaceInstance`],mh=`Select a part first`,hh=e=>ph.includes(e);function gh(e,t){return E(e)?O(e,t):hh(e)&&t<1?mh:null}var _h=`Comes with hand routing (engine stage 4)`,Q=(e,t,n)=>n?{label:e,command:t,shortcut:n}:{label:e,command:t},vh=[{title:`File`,entries:[Q(`Open circuit file`,`openFile`,`Ctrl+O`),Q(`New circuit…`,`newCircuit`),Q(`Import board (DXF or KiCad)…`,`importBoardDxf`),`separator`,Q(`Export BOM`,`exportBom`),Q(`Export package`,`exportPackage`),Q(`Export Gerber`,`exportFabrication`),Q(`Print…`,`print`)]},{title:`Edit`,entries:[Q(`Undo`,`undo`,`Ctrl+Z`),Q(`Redo`,`redo`,`Ctrl+Y`),`separator`,Q(`Copy`,`copy`,`Ctrl+C`),Q(`Paste`,`paste`,`Ctrl+V`),Q(`Delete`,`delete`,`Delete`),`separator`,Q(`Select all`,`selectAll`,`Ctrl+A`),Q(`Select the instance`,`selectInstance`),{label:`Make sub-sheet…`,command:`makeSheet`,only:`schematic`},Q(`Find`,`find`,`Ctrl+F`),Q(`Find similar objects`,`findSimilar`,`Ctrl+Shift+F`),`separator`,Q(`Fillet tracks`,`filletTracks`,`U`),Q(`Straighten tracks`,`straightenTracks`,`Shift+U`)]},{title:`View`,entries:[Q(`Fit all`,`fit`,`K`),Q(`Fit selection`,`fitSelection`),Q(`Fit area`,`fitArea`),Q(`Zoom in`,`zoomIn`),Q(`Zoom out`,`zoomOut`),`separator`,{...Q(`Unit`,`toggleUnit`,`Q`),only:`pcb`},Q(`Grid style`,`gridStyle`),{...Q(`Snap`,`snap`,`Alt+S`),toggle:`snap`},{...Q(`Hover labels`,`hoverLabels`),toggle:`hoverLabels`},{...Q(`Pour fill: Solid`,`pourSolid`),toggle:`pourSolid`},{...Q(`Pour fill: Hatched`,`pourHatched`),toggle:`pourHatched`},{...Q(`Pour fill: Outline only`,`pourOutline`),toggle:`pourOutline`},`separator`,Q(`Left panel`,`toggleLeftPanel`,`[`),Q(`Right panel`,`toggleRightPanel`,`]`),Q(`Bottom panel`,`toggleBottomPanel`,`\\`),`separator`,{...Q(`Theme: Light`,`themeLight`),toggle:`themeLight`},{...Q(`Theme: Dark`,`themeDark`),toggle:`themeDark`}]},{title:`Place`,entries:[Q(`Component`,`placeComponent`,`Shift+F`),Q(`Wire`,`wire`,`Alt+W`),Q(`Net label`,`netLabel`,`Alt+N`),Q(`Ground flag`,`groundFlag`),Q(`Power flag`,`powerFlag`),`separator`,Q(`Note box`,`noteBox`),`separator`,Q(`Bus`,`drawBus`,`Alt+B`),{label:`No connect flag`,command:`noConnect`,only:`schematic`},{label:`Junction`,command:`junction`,shortcut:`Alt+J`,only:`schematic`},`separator`,Q(`Copper pour`,`placePour`),Q(`Copper pour: Whole board`,`placePourBoard`),Q(`Hole`,`placeHole`),`separator`,{label:`Autoplace`,command:`autoplace`,only:`pcb`},{label:`Autoplace selection`,command:`autoplaceSelection`,only:`pcb`},{label:`Autoplace instance`,command:`autoplaceInstance`,only:`pcb`},`separator`,Q(`Polyline`,`drawPolyline`,`Alt+L`),Q(`Arc`,`drawArc`,`Alt+A`),Q(`Circle`,`drawCircle`,`Alt+C`),Q(`Rectangle`,`drawRectangle`,`Alt+R`),Q(`Text`,`drawText`,`Alt+T`)]},{title:`Design`,entries:[Q(`Check DRC`,`checkDrc`),Q(`Design rules`,`designRules`),`separator`,Q(`Highlight net`,`highlight`,`H`),Q(`Clear highlight`,`clearHighlight`,`Shift+H`),`separator`,{label:`Add page`,command:`addPage`,only:`schematic`},{label:`Rename page`,command:`renamePage`,only:`schematic`},{label:`Delete page`,command:`deletePage`,only:`schematic`},`separator`,{label:`Replicate layout`,command:`replicateLayout`,only:`pcb`},Q(`Annotate designators`,`annotate`),{label:`Placement transfer`,command:`placementTransfer`,shortcut:`Ctrl+Shift+X`,only:`pcb`}]},{title:`Route`,entries:[Q(`Single routing`,`singleRouting`,`Alt+W`),Q(`Via`,`placeVia`,`Alt+V`),{label:`Routing corner`,command:`routingCorner`,shortcut:`L`,only:`pcb`},`separator`,Q(`Autoroute`,`autoroute`),Q(`Autoroute selection`,`autorouteSelection`),Q(`Autoroute net`,`autorouteNet`),Q(`Unroute`,`unroute`)]},{title:`Layout`,entries:[Q(`Rotate`,`rotate`,`Space`),Q(`Rotate right`,`rotateRight`),{label:`Flip`,command:`flip`,shortcut:`X`,only:`pcb`},`separator`,Q(`Lock`,`lock`),Q(`Unlock`,`unlock`),`separator`,Q(`Align left`,`alignLeft`,`Ctrl+Shift+L`),Q(`Align right`,`alignRight`),Q(`Align top`,`alignTop`),Q(`Align bottom`,`alignBottom`),Q(`Align horizontal centres`,`alignHCentres`),Q(`Align vertical centres`,`alignVCentres`),`separator`,Q(`Distribute horizontally`,`distributeH`,`Ctrl+Shift+H`),Q(`Distribute vertically`,`distributeV`),`separator`,{label:`Fit board`,command:`fitBoard`,only:`pcb`},`separator`,{label:`Tidy sheet`,command:`tidySheet`,only:`schematic`}]},{title:`Tools`,entries:[Q(`History`,`history`),Q(`Footprint manager…`,`footprintManager`)]},{title:`Export`,entries:[Q(`BOM`,`exportBom`),Q(`Package`,`exportPackage`),Q(`Fabrication files (JLCPCB)`,`exportFabrication`),Q(`Gerber`,`exportFabrication`),Q(`Pick and place (CPL)`,`exportFabrication`),Q(`PDF…`,`exportPdf`)]},{title:`Settings`,entries:[Q(`System…`,`systemSettings`),Q(`Hotkeys`,`keys`)]},{title:`Help`,entries:[Q(`Keys`,`keys`),Q(`About`,`about`)]}];vh.map(e=>e.title);var yh={pcb:`PCB only`,schematic:`Schematic only`};function bh(e,t,n,r={}){if(!e.command)return e.pending?{enabled:!1,reason:e.pending}:{enabled:!1};if(e.only&&e.only!==t)return{enabled:!1,reason:yh[e.only]};let i=r[e.command];if(i!==void 0)return{enabled:!1,reason:i};let a=n===void 0?null:gh(e.command,n);return a?{enabled:!1,reason:a}:{enabled:!0}}function xh(e){return e.entries.filter(e=>e!==`separator`)}var Sh=[{keys:`Ctrl+Shift+Z`,label:`Redo`},{keys:`W`,label:`Wire (schematic), Single routing (PCB)`},{keys:`V (PCB)`,label:`Change the active layer; while routing, a via at the last corner`},{keys:`Space (while routing)`,label:`Step the corner mode: 45°, 45° reversed, 90°, arc`},{keys:`Enter (while routing)`,label:`End the track open at its last corner (or click that corner again)`},{keys:`R`,label:`Rotate`},{keys:`Space (while drawing a wire)`,label:`Flip the bend of the leg to the pointer`},{keys:`Shift (while drawing a polyline)`,label:`Keep the leg horizontal or vertical; Space flips its bend`},{keys:`Enter (while drawing a polyline)`,label:`Finish the polyline (or double click)`},{keys:`Backspace (while drawing)`,label:`Remove the last corner`},{keys:`F`,label:`Fit all`},{keys:`Esc`,label:`Clear the selection, put tools away`},{keys:`Arrow keys`,label:`Move the selection one grid step (a tenth with Snap off)`},{keys:`Shift+Arrow keys`,label:`Move the selection ten grid steps (ten tenths with Snap off)`},{keys:`Shift+F10`,label:`Open the context menu (also the menu key)`}];function Ch(){let e=new Set,t=[];for(let n of vh.flatMap(xh))n.command&&n.shortcut&&!e.has(n.shortcut)&&(e.add(n.shortcut),t.push({keys:n.shortcut,label:n.label}));return[...t,...Sh.filter(t=>!e.has(t.keys))]}function wh(e,t){switch(t.type){case`click`:return{open:e.open===t.title?null:t.title};case`hover`:return e.open===null||e.open===t.title?e:{open:t.title};case`set`:return e.open===t.title?e:{open:t.title};default:return e.open===null?e:{open:null}}}function Th(e,t,n={}){return vh.map(r=>r.entries.map(r=>r===`separator`?`separator`:bh(r,e,t,n).enabled?`item`:`disabled`))}var Eh=`Type the LCSC part number, e.g. C7950. The part is fetched from EasyEDA, so this needs the internet.`;function Dh(e,t,n){let r=e.trim().toUpperCase();if(r===``)return{message:Eh};if(!/^C[1-9][0-9]{0,9}$/.test(r))return{message:`"${e.trim()}" is not an LCSC part number: it looks like C7950 (C and digits).`};let i=t.trim();return{lcsc:r,replace:n,...i?{id:i}:{}}}function Oh(e){let t=(e,t)=>`${e} ${t}${e===1?``:`s`}`;return`Imported ${e.lcsc} as ${e.id}: ${e.title}, ${t(e.pins,`pin`)}, ${t(e.pads,`pad`)}.`}function kh(e){return`Not verified: check every pin and pad in parts/${e.id}/verification.md against the datasheet before verifying it.`}function Ah(e){if(!e)return;let t=/^lcsc (C\d+), imported (\S+)$/.exec(e);if(t)return`Imported from LCSC ${t[1]} on ${t[2]}`;let n=/^written (\S+)$/.exec(e);return n?`Written on ${n[1]}`:e}function jh({result:e}){return(0,X.jsxs)(`div`,{className:`import-result`,role:`status`,children:[(0,X.jsx)(`p`,{children:(0,X.jsx)(`strong`,{children:Oh(e)})}),(0,X.jsx)(`p`,{children:kh(e)}),e.notes.length>0&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`h3`,{children:`Check these too`}),(0,X.jsx)(`ul`,{children:e.notes.map(e=>(0,X.jsx)(`li`,{children:e},e))})]}),(0,X.jsx)(`h3`,{children:`Written`}),(0,X.jsx)(`ul`,{children:e.files.map(e=>(0,X.jsx)(`li`,{children:(0,X.jsx)(`code`,{children:e})},e))}),(0,X.jsx)(`p`,{children:e.terms})]})}function Mh({panel:e,onClose:t}){let[n,r]=(0,_.useState)(``),[i,a]=(0,_.useState)(``),[o,s]=(0,_.useState)(!1),[c,l]=(0,_.useState)(!1),[u,d]=(0,_.useState)(),[f,p]=(0,_.useState)(),m=(0,_.useId)(),h=async r=>{if(r.preventDefault(),c)return;if(f)return t();let a=Dh(n,i,o);if(`message`in a)return d(a.message);l(!0),d(void 0);try{p(await e.import(a))}catch(e){d(e.message)}finally{l(!1)}};return(0,X.jsxs)(`form`,{className:`rules-form import-part-form`,onSubmit:e=>void h(e),children:[(0,X.jsx)(`label`,{htmlFor:m,children:`LCSC part number`}),(0,X.jsx)(`input`,{id:m,value:n,placeholder:`C7950`,disabled:c||f!==void 0,onChange:e=>r(e.target.value),"aria-describedby":`${m}-note`,"aria-invalid":u!==void 0}),(0,X.jsx)(`label`,{htmlFor:`${m}-id`,children:`Part id`}),(0,X.jsx)(`input`,{id:`${m}-id`,value:i,placeholder:`the MPN`,disabled:c||f!==void 0,onChange:e=>a(e.target.value)}),(0,X.jsxs)(`label`,{className:`make-sheet-rename`,children:[(0,X.jsx)(`input`,{type:`checkbox`,checked:o,disabled:c||f!==void 0,onChange:e=>s(e.target.checked)}),`Replace a part with this id that is not verified`]}),(0,X.jsx)(`p`,{id:`${m}-note`,role:u?`alert`:void 0,children:c?`Fetching from EasyEDA…`:u??(f?``:`Type the LCSC part number, e.g. C7950. The part is fetched from EasyEDA, so this needs the internet.`)}),f&&(0,X.jsx)(jh,{result:f}),(0,X.jsx)(`button`,{type:`submit`,disabled:c,children:f?`Close`:`Import`})]})}var Nh=/(?:^|[\s>])\.([A-Za-z_][\w-]*)/,Ph=/^([A-Za-z_][\w-]*)\.[\w-]+$/;function Fh(e){let t=new Set;for(let n of e.split(`,`)){let e=n.trim();if(e.startsWith(`net.`))continue;let r=Ph.exec(e)??Nh.exec(e);r?.[1]&&t.add(r[1])}return[...t]}function Ih(e,t){if(t.includes(`/`))return;let n=e.parts.find(e=>e.name===t)?.tag,r=e.imports.find(e=>e.local===n)?.source;if(r===void 0||!/\.sheet(\.tsx)?$/.test(r))return;let i=r.replace(/^\.\//,``);return i.endsWith(`.tsx`)?i:`${i}.tsx`}var Lh=class extends Error{code;constructor(e,t){super(t),this.code=e,this.name=`EditError`}};function Rh(e,t){if(t.length===0)return`Select the parts to move into the sub-sheet first.`;let n=[];for(let r of new Set(t)){let t=e.parts.find(e=>e.name===r);if(!t)return`There is no part ${r} in the circuit.`;if(Ih(e,r)!==void 0)return`${r} is a sub-sheet instance; a sub-sheet is made of parts only, so leave instances out of the selection.`;if(!t.editable)return`${r} cannot be moved (${t.readonlyReason??`read-only`}).`;if(t.parent===`group`)return`${r} is inside a <group>, whose offset its position adds to; ungroup it first.`;n.push(t)}if(new Set(n.map(e=>e.page??``)).size>1)return`The selected parts are on different pages; select parts of one page.`}function zh(e,t){if(!e)return{message:`Wait for the circuit to load, then try again.`};let n=Rh(e,t);return n===void 0?{parts:[...new Set(t)]}:{message:n}}function Bh(e){return e.ports.map(t=>({port:t.name,joins:`${t.bus?`bus`:`net`} ${e.connections[t.name]??t.name}`}))}function Vh(e){return e.mapping.map(e=>({now:e.from,sheet:e.to,board:e.flat}))}var Hh=e=>`${e.trim()||`PowerStage`}1`,Uh=`Type the sheet's name, e.g. PowerStage: a capital letter, then letters, digits and _.`;function Wh(e,t){return`Made ${e.file}: ${e.instance} (base ${e.base}) replaces ${t} part${t===1?``:`s`}`}var Gh=200;function Kh(e,t){let{name:n,instance:r,rename:i}=t,[a,o]=(0,_.useState)({problem:Uh});return(0,_.useEffect)(()=>{if(n.trim()===``){o({problem:Uh});return}let t=!0,a=window.setTimeout(()=>{e.preview({name:n.trim(),rename:i,...r?{instance:r}:{}}).then(e=>t&&o({preview:e}),e=>t&&o({problem:e.message}))},Gh);return()=>{t=!1,window.clearTimeout(a)}},[e,n,r,i]),a}function qh({preview:e}){let t=Bh(e);return t.length===0?(0,X.jsx)(`p`,{children:`No net crosses the selection, so the sheet has no ports.`}):(0,X.jsx)(`table`,{"aria-label":`Ports`,children:(0,X.jsx)(`tbody`,{children:t.map(e=>(0,X.jsxs)(`tr`,{children:[(0,X.jsx)(`td`,{children:e.port}),(0,X.jsx)(`td`,{children:e.joins})]},e.port))})})}function Jh({preview:e}){return(0,X.jsxs)(`table`,{"aria-label":`Designators`,children:[(0,X.jsx)(`thead`,{children:(0,X.jsxs)(`tr`,{children:[(0,X.jsx)(`td`,{children:`Now`}),(0,X.jsx)(`td`,{children:`In the sheet`}),(0,X.jsx)(`td`,{children:`On the board`})]})}),(0,X.jsx)(`tbody`,{children:Vh(e).map(e=>(0,X.jsxs)(`tr`,{children:[(0,X.jsx)(`td`,{children:e.now}),(0,X.jsx)(`td`,{children:e.sheet}),(0,X.jsx)(`td`,{children:e.board})]},e.now))})]})}function Yh({panel:e,onClose:t}){let[n,r]=(0,_.useState)(``),[i,a]=(0,_.useState)(``),[o,s]=(0,_.useState)(!1),c=i.trim(),l={name:n.trim(),rename:o,...c?{instance:c}:{}},{preview:u,problem:d}=Kh(e,l),f=(0,_.useId)(),p=async n=>{n.preventDefault(),u&&await e.make(l)&&t()};return(0,X.jsxs)(`form`,{className:`rules-form make-sheet-form`,onSubmit:e=>void p(e),children:[(0,X.jsx)(`label`,{htmlFor:f,children:`Sheet name`}),(0,X.jsx)(`input`,{id:f,value:n,placeholder:`PowerStage`,onChange:e=>r(e.target.value),"aria-describedby":`${f}-note`,"aria-invalid":d!==void 0&&n!==``}),(0,X.jsx)(`label`,{htmlFor:`${f}-instance`,children:`Instance name`}),(0,X.jsx)(`input`,{id:`${f}-instance`,value:i,placeholder:Hh(n),onChange:e=>a(e.target.value)}),(0,X.jsx)(`p`,{id:`${f}-note`,children:u?`Writes ${u.file}; ${u.instance} (base ${u.base}) takes the place of ${e.parts.length} part${e.parts.length===1?``:`s`}.`:d}),u&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`h3`,{children:`Ports`}),(0,X.jsx)(qh,{preview:u}),(0,X.jsx)(`h3`,{children:`Designators`}),(0,X.jsx)(Jh,{preview:u})]}),(0,X.jsxs)(`label`,{className:`make-sheet-rename`,children:[(0,X.jsx)(`input`,{type:`checkbox`,checked:o,onChange:e=>s(e.target.checked)}),`Rename the parts to local designators (R1, C1, …)`]}),(0,X.jsx)(`button`,{type:`submit`,disabled:!u,children:`Make sub-sheet`})]})}function Xh(e){let t;return()=>(t??=e().catch(e=>{throw t=void 0,e}),t)}function Zh(e){let t=Xh(e),n=()=>(0,_.lazy)(()=>t().then(e=>({default:e}))),r=n();return{component:()=>r,retry:()=>{r=n()}}}function Qh({what:e,message:t,onRetry:n}){return(0,_.createElement)(`div`,{role:`alert`},(0,_.createElement)(`p`,null,`The ${e} dialog could not open (${t}). Check that the Studio is still running, then try again; if it fails again, reload the Studio.`),(0,_.createElement)(`button`,{type:`button`,onClick:n},`Retry`))}var $h=class extends _.Component{state={};static getDerivedStateFromError(e){return{error:e instanceof Error?e:Error(String(e))}}render(){let{error:e}=this.state;return e?(0,_.createElement)(Qh,{what:this.props.what,message:e.message,onRetry:()=>{this.props.onRetry(),this.setState({error:void 0})}}):(0,_.createElement)(_.Suspense,{fallback:(0,_.createElement)(`p`,null,`Loading…`)},this.props.render())}},eg=.0254,tg=e=>e===`mm`?`mil`:`mm`,ng=(e,t)=>t===`mil`?e/eg:e;function rg(e,t){let n=ng(e,t).toFixed(t===`mil`?1:2);return/^-0(\.0+)?$/.test(n)?n.slice(1):n}function ig(e,t){return`${Number(ng(e,t).toFixed(t===`mm`?4:2))} ${t}`}var ag=(e,t)=>Math.round(e/t*100),og=.0254,sg=[2*og,.1,5*og,10*og,.5,20*og,25*og,1,50*og,100*og].map(e=>Number(e.toFixed(4))),cg=.5,lg=[.05,.1,.2],ug=.1,dg=(e,t,n)=>({...e,[t]:n});function fg(e,t){if(e===`schematic`)return lg.map(e=>({value:e,label:`${e} in`}));if(!t)throw Error(`The PCB's Grid steps need its display unit`);return sg.map(e=>({value:e,label:ig(e,t)}))}var pg={schematic:`lines`,pcb:`lines`},mg=e=>e===`lines`?`dots`:`lines`,hg=(e,t)=>({...e,[t]:mg(e[t])}),gg=5,_g=2;function vg(e,t,n=1){let r=e;for(let e=0;e<=_g;e++,r*=gg)if(r*t*n>=3)return r;return null}function yg(e,t,n,r=1){let i=vg(n,e.scale,r);if(i===null)return null;let a=ye(e,t,{x:0,y:0}),o=ye(e,t,{x:t.width,y:t.height}),s=(e,t)=>{let n=[];for(let r=Math.floor(Math.min(e,t)/i);r<=Math.ceil(Math.max(e,t)/i);r++)n.push(r);return n};return{spacing:i,columns:s(a.x,o.x),rows:s(a.y,o.y),minor:i*e.scale*r>=6}}var bg=e=>e%5==0,xg=e=>({...e,columns:e.columns.filter(bg),rows:e.rows.filter(bg)});function Sg(e,t,n,r,i,a){let{spacing:o}=r,s=(t,n)=>{for(let[r,a]of[[i.minor,!1],[i.fifth??i.minor,!0]]){e.strokeStyle=r,e.beginPath();for(let r of t.filter(e=>!i.fifth||bg(e)===a)){let[t,i,a,o]=n(r);e.moveTo(t,i),e.lineTo(a,o)}if(e.stroke(),!i.fifth)return}};e.lineWidth=Ko(a),s(r.columns,e=>{let r=qo(V(t,n,{x:e*o,y:0}).x,a);return[r,0,r,n.height]}),s(r.rows,e=>{let r=qo(V(t,n,{x:0,y:e*o}).y,a);return[0,r,n.width,r]})}function Cg(e,t,n,r){let i=Math.floor((Math.round(n*r)-1)/2)/r;return e.map(e=>({at:Jo(t(e),r)-i,fifth:bg(e)}))}function wg(e,t,n,r){e.fillStyle=n,e.beginPath();for(let n=0;n+1<t.length;n+=2)e.rect(t[n],t[n+1],r,r);e.fill()}function Tg(e,t,n,r,i,a){let{spacing:o}=r,s=Yo(i.px,a),c=Cg(r.columns,e=>V(t,n,{x:e*o,y:0}).x,s,a),l=Cg(r.rows,e=>V(t,n,{x:0,y:e*o}).y,s,a),u=[];e.fillStyle=i.minor,e.beginPath();for(let t of c)for(let n of l)i.fifth&&t.fifth&&n.fifth?u.push(t.at,n.at):e.rect(t.at,n.at,s,s);e.fill(),i.fifth&&wg(e,u,i.fifth,s)}function Eg(e,t,n,r,i,a){let o=yg(t,n,r.step,a);if(!o)return;let s=o.minor?o:xg(o);e.save(),r.style===`dots`?Tg(e,t,n,s,i.dots,a):Sg(e,t,n,s,i.lines,a),e.restore()}function Dg({panel:e,onClose:t}){let[n,r]=(0,_.useState)(e.settings),i=(0,_.useId)(),a=(e,t)=>r(n=>({...n,[e]:t}));return(0,X.jsxs)(`form`,{className:`rules-form system-form`,onSubmit:r=>{r.preventDefault(),e.apply(n),t()},children:[(0,X.jsx)(`label`,{htmlFor:`${i}-theme`,children:`Theme`}),(0,X.jsxs)(`select`,{id:`${i}-theme`,value:n.theme,onChange:e=>a(`theme`,e.target.value),children:[(0,X.jsx)(`option`,{value:`light`,children:`Light`}),(0,X.jsx)(`option`,{value:`dark`,children:`Dark`})]}),(0,X.jsx)(`label`,{htmlFor:`${i}-unit`,children:`PCB unit`}),(0,X.jsxs)(`select`,{id:`${i}-unit`,value:n.unit,onChange:e=>a(`unit`,e.target.value),children:[(0,X.jsx)(`option`,{value:`mm`,children:`mm`}),(0,X.jsx)(`option`,{value:`mil`,children:`mil`})]}),(0,X.jsx)(`label`,{htmlFor:`${i}-sheet`,children:`Schematic grid`}),(0,X.jsx)(`select`,{id:`${i}-sheet`,value:n.grid.schematic,onChange:e=>a(`grid`,{...n.grid,schematic:Number(e.target.value)}),children:fg(`schematic`).map(e=>(0,X.jsx)(`option`,{value:e.value,children:e.label},e.value))}),(0,X.jsx)(`label`,{htmlFor:`${i}-pcb`,children:`PCB grid`}),(0,X.jsx)(`select`,{id:`${i}-pcb`,value:n.grid.pcb,onChange:e=>a(`grid`,{...n.grid,pcb:Number(e.target.value)}),children:fg(`pcb`,n.unit).map(e=>(0,X.jsx)(`option`,{value:e.value,children:e.label},e.value))}),(0,X.jsxs)(`label`,{children:[(0,X.jsx)(`input`,{type:`checkbox`,checked:n.hoverLabels,onChange:e=>a(`hoverLabels`,e.target.checked)}),` Hover labels`]}),(0,X.jsx)(`p`,{children:`Kept in this browser. The grid steps are where each document starts; the Grid select still changes them.`}),(0,X.jsx)(`button`,{type:`submit`,children:`Save`})]})}var Og={width:30,height:20},kg=1e3,Ag=/^[\w\- ]+(\/[\w\- ]+)*$/;function jg(e,t,n){let r=e.trim().replace(/\.circuit\.tsx$/,``);if(r===``)return{message:`Give the circuit a name`};if(!Ag.test(r))return{message:`Use letters, digits, spaces, - and _ in the name, and / between folders`};let i=[Number(t),Number(n)];return i.some(e=>!Number.isFinite(e)||e<=0||e>kg)?{message:`The board's width and height are mm above 0 and at most ${kg}`}:{file:`${r}.circuit.tsx`,width:i[0],height:i[1]}}function Mg({panel:e,onClose:t}){let[n,r]=(0,_.useState)(``),[i,a]=(0,_.useState)(String(Og.width)),[o,s]=(0,_.useState)(String(Og.height)),[c,l]=(0,_.useState)(),[u,d]=(0,_.useState)(!1),f=(0,_.useId)(),p=async r=>{r.preventDefault();let a=jg(n,i,o);if(`message`in a)return l(a.message);d(!0);let s=await e.create(a);d(!1),s&&t()};return(0,X.jsxs)(`form`,{className:`rules-form`,onSubmit:e=>void p(e),children:[(0,X.jsx)(`label`,{htmlFor:`${f}-name`,children:`Name`}),(0,X.jsx)(`input`,{id:`${f}-name`,value:n,placeholder:`power-board`,onChange:e=>r(e.target.value),"aria-invalid":c!==void 0}),(0,X.jsx)(`label`,{htmlFor:`${f}-w`,children:`Board width (mm)`}),(0,X.jsx)(`input`,{id:`${f}-w`,inputMode:`decimal`,value:i,onChange:e=>a(e.target.value)}),(0,X.jsx)(`label`,{htmlFor:`${f}-h`,children:`Board height (mm)`}),(0,X.jsx)(`input`,{id:`${f}-h`,inputMode:`decimal`,value:o,onChange:e=>s(e.target.value)}),(0,X.jsx)(`p`,{role:c?`alert`:void 0,children:c??`Written as <name>.circuit.tsx in the project folder; Undo removes it again.`}),(0,X.jsx)(`button`,{type:`submit`,disabled:u,children:`Create`})]})}function Ng(e,t,n){if(!t)return`Not written in this file`;if(e.library)return`From library part ${e.library}; change it in the library`;if(n.has(t.name))return`Locked`;if(!t.editable)return`Read-only`;let r=t.props.footprint;return r&&r.literal===void 0?`Written as ${r.source}`:void 0}function Pg({components:e,parts:t,locked:n}){return e.map(e=>{let r=Ng(e,t.find(t=>t.name===e.id),n);return{name:e.id,kind:e.kind,value:e.value??``,footprint:e.footprint??``,...r?{fixed:r}:{}}})}var Fg=e=>[...new Set(e.map(e=>e.footprint).filter(e=>e!==``))].sort(),Ig=/^[\w.\-+:,=()]+$/;function Lg(e,t){let n=e.filter(e=>t[e.name]!==void 0&&t[e.name]?.trim()!==e.footprint);if(n.length===0)return{message:`No footprint was changed.`};let r=n.find(e=>e.fixed);if(r)return{message:`${r.name}: ${r.fixed}`};let i=n.find(e=>!Ig.test((t[e.name]??``).trim()));return i?{message:`${i.name}: a footprint is a name such as 0603 or soic8, without spaces`}:{edits:n.map(e=>({kind:`setProps`,part:e.name,props:{footprint:(t[e.name]??``).trim()}})),summary:`change footprints: ${n.slice(0,3).map(e=>`${e.name} → ${(t[e.name]??``).trim()}`).join(`, `)}${n.length>3?` and ${n.length-3} more`:``}`}}function Rg({panel:e,onClose:t}){let n=(0,_.useMemo)(()=>e.source?Pg(e.source):[],[e.source]),[r,i]=(0,_.useState)({}),[a,o]=(0,_.useState)(),s=(0,_.useId)();if(n.length===0)return(0,X.jsx)(`p`,{children:`The open circuit has no parts yet.`});let c=async i=>{i.preventDefault();let a=Lg(n,r);if(`message`in a)return o(a.message);await e.write(a.edits,a.summary)&&t()};return(0,X.jsxs)(`form`,{className:`footprint-manager`,onSubmit:e=>void c(e),children:[(0,X.jsx)(`datalist`,{id:s,children:Fg(n).map(e=>(0,X.jsx)(`option`,{value:e},e))}),(0,X.jsxs)(`table`,{children:[(0,X.jsx)(`thead`,{children:(0,X.jsxs)(`tr`,{children:[(0,X.jsx)(`th`,{scope:`col`,children:`Designator`}),(0,X.jsx)(`th`,{scope:`col`,children:`Kind`}),(0,X.jsx)(`th`,{scope:`col`,children:`Value`}),(0,X.jsx)(`th`,{scope:`col`,children:`Footprint`})]})}),(0,X.jsx)(`tbody`,{children:n.map(e=>(0,X.jsxs)(`tr`,{children:[(0,X.jsx)(`td`,{children:e.name}),(0,X.jsx)(`td`,{children:e.kind}),(0,X.jsx)(`td`,{children:e.value}),(0,X.jsx)(`td`,{children:(0,X.jsx)(`input`,{"aria-label":`Footprint of ${e.name}`,list:s,value:r[e.name]??e.footprint,disabled:e.fixed!==void 0,title:e.fixed,onChange:t=>i(n=>({...n,[e.name]:t.target.value}))})})]},e.name))})]}),(0,X.jsx)(`p`,{role:a?`alert`:void 0,children:a??`Changed footprints are written to the circuit file as one change; Undo takes them all back.`}),(0,X.jsx)(`button`,{type:`submit`,children:`Save`})]})}var zg={name:`default`,trackWidth:.25,clearance:.2,via:{drill:.3,diameter:.6},patterns:[]};function Bg(e){let t=[...e].map(e=>e===`*`?`.*`:e===`?`?`.`:e.replace(/[.+^${}()|[\]\\]/g,`\\$&`)).join(``);return RegExp(`^${t}$`,`s`)}function Vg(e,t){if(e===`*`)return!0;let n=Bg(e);return t.names.some(e=>n.test(e))}var Hg=(e,t)=>e.classes.filter(e=>e.patterns.some(e=>Vg(e,t))).map(e=>e.name);function Ug(e,t){return Hg(e,t)[0]??zg.name}function Wg(e,t){let n=new Map,r=[];for(let i of t){let t=Hg(e,i);if(n.set(i.id,t[0]??zg.name),t.length<2)continue;let a=`Net ${i.id.replace(/^net\./,``)} matches the net classes ${t.join(` and `)}; it uses ${t[0]}`;r.push(Zr(`net-class-conflict`,`error`,a,[i.id]))}return{byNet:n,diagnostics:[...r,...Gg(e,t)]}}function Gg(e,t){return e.classes.flatMap(e=>e.patterns.filter(e=>!t.some(t=>Vg(e,t))).map(t=>Zr(`rules`,`warning`,`Net class ${e.name}: the pattern "${t}" matches no net`,[e.name])))}var Kg=(e,t)=>e.classes.find(e=>e.name===t)?.clearance??zg.clearance;function qg(e,t,n){let r=e.classClearance.filter(e=>e.a===t&&e.b===n||e.a===n&&e.b===t).map(e=>e.clearance);return Math.max(Kg(e,t),Kg(e,n),e.fabrication.minClearance,...r)}var Jg=(e,t)=>e.classes.find(n=>n.name===Ug(e,t))??zg,Yg=(e,t)=>Math.max(Jg(e,t).trackWidth,e.fabrication.minTrackWidth),Xg=e=>Math.round(e*1e6)/1e6;function Zg(e,t){let n=Math.max(t.drill,e.fabrication.minDrill);return{drill:n,diameter:Math.max(t.diameter,Xg(n+2*e.fabrication.minAnnularRing))}}var Qg=(e,t)=>Zg(e,Jg(e,t).via),$g=e=>Zg(e,zg.via),e_=e=>e.fabrication.filletRadius??1,t_=`Fillet radius`,n_=`Edit → Fillet tracks rounds corners with this radius. Empty is the default, 1 mm. A track's width is the floor: a smaller radius is raised to the width.`;function r_(e){let t=e?.filletRadius;return{value:t===void 0?``:String(t),placeholder:`1 mm (default)`}}function i_(e){if(e.trim()===``)return{radius:null};let t=ei(e);return t===void 0||t<=0||t>50?{message:`Type a length above 0 and at most 50 mm, such as 1, 0.5mm or 40mil, or leave it empty for the default.`}:{radius:Math.round(t*1e6)/1e6}}var a_=`modulepreload`,o_=function(e,t){return new URL(e,t).href},s_={},c_=function(e){return e.pathname.endsWith(`.css`)},l_=function(e,t,n){if(t in e)return e[t];let r=n();if(!r){e[t]=void 0;return}let i=r.then(()=>{e[t]=void 0},n=>{throw e[t]=void 0,n});return e[t]=i,i},u_=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e,i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}function s(e){return import.meta.resolve?new URL(import.meta.resolve(e)):new URL(e,import.meta.url)}r=o(t.map(t=>{t=o_(t,n);let r=s(t),i=c_(r);return l_(s_,r.href,()=>{if(e===void 0){e={all:new Set,styles:new Set};let t=document.getElementsByTagName(`link`);for(let n=t.length-1;n>=0;n--){let r=t[n];e.all.add(r.href),r.rel===`stylesheet`&&e.styles.add(r.href)}}if((i?e.styles:e.all).has(r.href))return;let t=document.createElement(`link`);if(t.rel=i?`stylesheet`:a_,i||(t.as=`script`),t.crossOrigin=``,t.href=r.href,a&&t.setAttribute(`nonce`,a),document.head.appendChild(t),i)return new Promise((e,n)=>{t.addEventListener(`load`,e),t.addEventListener(`error`,()=>n(Error(`Unable to preload CSS for ${r}`)))})})}).filter(e=>e!==void 0))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})},d_=Zh(()=>u_(()=>import(`./NewPartDialog-BBJaZFCo.js`).then(e=>e.NewPartForm),[],import.meta.url)),f_=Zh(()=>u_(()=>import(`./VerifyPartDialog-Ey6xpQ_U.js`).then(e=>e.VerifyPartForm),__vite__mapDeps([0,1]),import.meta.url)),p_=`button, [href], input, select, textarea, [tabindex]:not([tabindex='-1'])`;function m_(e,t){fh(!0,n=>{let r=sh(n.key);if(r===`hold`)return;if(n.preventDefault(),r===`close`)return t();let i=[...e.current?.querySelectorAll(p_)??[]];(i[ch(i.indexOf(document.activeElement),i.length,n.shiftKey)]??e.current)?.focus()})}function h_({title:e,onClose:t,children:n,wide:r=!1,large:i=!1}){let a=(0,_.useRef)(null);return(0,_.useEffect)(()=>{let e=document.activeElement;return(a.current?.querySelector(`[data-default]`)??a.current?.querySelector(p_)??a.current)?.focus(),()=>{e instanceof HTMLElement&&e.isConnected&&e.focus()}},[]),m_(a,t),(0,X.jsx)(`div`,{className:`dialog-backdrop`,onPointerDown:e=>e.target===e.currentTarget&&t(),children:(0,X.jsxs)(`section`,{ref:a,tabIndex:-1,className:i?`dialog large`:r?`dialog wide`:`dialog`,role:`dialog`,"aria-modal":`true`,"aria-label":e,children:[(0,X.jsxs)(`header`,{className:`hairline-b`,children:[(0,X.jsx)(`h2`,{children:e}),(0,X.jsx)(`button`,{className:`icon`,"aria-label":`Close`,onClick:t,children:(0,X.jsx)(nh,{})})]}),(0,X.jsx)(`div`,{className:`dialog-body`,children:n})]})})}function g_(){return(0,X.jsx)(`table`,{children:(0,X.jsx)(`tbody`,{children:Ch().map(e=>(0,X.jsxs)(`tr`,{children:[(0,X.jsx)(`td`,{children:(0,X.jsx)(`kbd`,{children:e.keys})}),(0,X.jsx)(`td`,{children:e.label})]},e.keys))})})}function __({rules:e,onClose:t}){let n=r_(e.fabrication),[r,i]=(0,_.useState)(n.value),[a,o]=(0,_.useState)(),s=(0,_.useId)(),c=async i=>{i.preventDefault();let a=i_(r);if(`message`in a)return o(a.message);if(r.trim()===n.value)return t();await e.save(a.radius)&&t()};return(0,X.jsxs)(`form`,{className:`rules-form`,onSubmit:e=>void c(e),children:[(0,X.jsx)(`label`,{htmlFor:s,children:t_}),(0,X.jsx)(`input`,{id:s,value:r,placeholder:n.placeholder,onChange:e=>i(e.target.value),"aria-describedby":`${s}-note`,"aria-invalid":a!==void 0}),(0,X.jsx)(`p`,{id:`${s}-note`,children:a??n_}),(0,X.jsx)(`p`,{children:`The rest of the design rules are in rules.yaml in the project.`}),(0,X.jsx)(`button`,{type:`submit`,children:`Save`})]})}function v_({panel:e,onClose:t}){let n=e=>()=>{t(),e()};return(0,X.jsxs)(`div`,{className:`rules-form`,children:[(0,X.jsx)(`p`,{children:e.question}),(0,X.jsx)(`button`,{type:`button`,"data-default":!0,onClick:n(e.showChecks),children:`Show checks`}),(0,X.jsx)(`button`,{type:`button`,onClick:n(e.exportAnyway),children:`Export anyway`})]})}function y_({name:e,onClose:t,rules:n,makeSheet:r,importPart:i,newPart:a,system:o,newCircuit:s,footprints:c,exportChecks:l}){return e===`exportChecks`?(0,X.jsx)(h_,{title:`Fabrication files`,onClose:t,children:(0,X.jsx)(v_,{panel:l,onClose:t})}):e===`footprints`?(0,X.jsx)(h_,{title:`Footprint manager`,onClose:t,wide:!0,children:(0,X.jsx)(Rg,{panel:c,onClose:t})}):e===`newCircuit`?(0,X.jsx)(h_,{title:`New circuit`,onClose:t,children:(0,X.jsx)(Mg,{panel:s,onClose:t})}):e===`system`?(0,X.jsx)(h_,{title:`System settings`,onClose:t,children:(0,X.jsx)(Dg,{panel:o,onClose:t})}):e===`newPart`?(0,X.jsx)(h_,{title:`New part`,onClose:t,wide:!0,children:(0,X.jsx)($h,{what:`New part`,onRetry:d_.retry,render:()=>{let e=d_.component();return(0,X.jsx)(e,{panel:a,onClose:t})}})}):e===`importPart`?(0,X.jsx)(h_,{title:`Import by LCSC number`,onClose:t,children:(0,X.jsx)(Mh,{panel:i,onClose:t})}):e===`makeSheet`?(0,X.jsx)(h_,{title:`Make sub-sheet`,onClose:t,children:(0,X.jsx)(Yh,{panel:r,onClose:t})}):e===`rules`?(0,X.jsx)(h_,{title:`Design rules`,onClose:t,children:(0,X.jsx)(__,{rules:n,onClose:t})}):e===`keys`?(0,X.jsx)(h_,{title:`Keys`,onClose:t,children:(0,X.jsx)(g_,{})}):(0,X.jsxs)(h_,{title:`About copperflow`,onClose:t,children:[(0,X.jsxs)(`p`,{children:[(0,X.jsx)(`strong`,{children:`copperflow`}),` Studio`]}),(0,X.jsx)(`p`,{children:`Design circuits in code with a human and an AI agent editing the same files.`}),(0,X.jsx)(`p`,{children:`Apache License 2.0`})]})}function b_({target:e,panel:t,onClose:n}){return(0,X.jsx)(h_,{title:`Verify ${e.title}`,onClose:n,large:!0,children:(0,X.jsx)($h,{what:`Verify`,onRetry:f_.retry,render:()=>{let n=f_.component();return(0,X.jsx)(n,{panel:t,id:e.id})}})})}var x_=.001;function $(e){let t=Number(e.toFixed(3));return String(t===0?0:t)}var S_=e=>`${$(e)} mm`,C_=(e,t)=>`${$(e)} × ${$(t)} mm`;function w_(e){let t=[...new Set(e)].sort(T_),n=[];for(let e=0;e<t.length;){let r=e;for(;r+1<t.length&&Number(t[r+1])===Number(t[r])+1;)r++;n.push(r-e>=2?`${t[e]}–${t[r]}`:t.slice(e,r+1).join(`, `)),e=r+1}return n.join(`, `)}function T_(e,t){let[n,r]=[Number(e),Number(t)];return Number.isFinite(n)&&Number.isFinite(r)?n-r:e.localeCompare(t)}function E_(e){let t=e.rotation*Math.PI/180,[n,r]=[Math.abs(Math.cos(t)),Math.abs(Math.sin(t))];return{width:e.width*n+e.height*r,height:e.width*r+e.height*n}}function D_(e){return e.length===0?[{label:`Pads`,value:`0`}]:[{label:`Pads`,value:String(e.length)},...O_(e),...P_(e),...k_(e)]}function O_(e){let t=G_(e,e=>{let t=E_(e);return C_(t.width,t.height)});return t.size===1?[{label:`Pad width × height`,value:[...t.keys()][0]??``}]:[...t].map(([e,t])=>{let n=[...new Set(t.map(e=>e.number))];return{label:`Pad width × height, pad${n.length===1?``:`s`} ${w_(n)}`,value:e}})}function k_(e){let t=e.filter(e=>e.drill!==void 0);if(t.length===0)return[];let n=G_(t,e=>{let t=e.drill??{width:0,height:0};return t.width===t.height?S_(t.width):`${C_(t.width,t.height)} (slot)`}),r=(e,t)=>n.size===1?e:`${e}, pads ${w_(t.map(e=>e.number))}`;return[...n].flatMap(([e,t])=>[{label:r(`Drill`,t),value:e},{label:r(`Annular ring`,t),value:S_(Math.min(...t.map(A_)))}])}function A_(e){let t=e.drill??{width:0,height:0};return Math.min(e.width-t.width,e.height-t.height)/2}var j_=e=>e===`x`?`y`:`x`,M_=(e,t)=>(t===`x`?E_(e).width:E_(e).height)/2;function N_(e,t){return Math.max(...e.map(e=>e[t]+M_(e,t)))-Math.min(...e.map(e=>e[t]-M_(e,t)))}function P_(e){if(e.length===1)return[];if(e.length===2)return F_(e[0],e[1]);let t=t=>R_(e,j_(t)),[n,r]=[t(`x`),t(`y`)];for(let n of[`x`,`y`])if(t(n).length===1)return[{label:`Pitch along`,value:z_(e,n)},{label:`Span outside the pads`,value:S_(N_(e,n))}];let i=(r.length===2?[`y`]:[]).concat(n.length===2?[`x`]:[]);if(i.length>0){let n=i.sort((e,n)=>Math.max(...t(n).map(e=>e.length))-Math.max(...t(e).map(e=>e.length)))[0],[r,a]=t(n),o=j_(n);return[{label:`Pitch along`,value:z_(e,n)},{label:`Rows centre to centre`,value:S_(Math.abs(a[0][o]-r[0][o]))},{label:`Span outside the pads`,value:S_(N_(e,o))}]}return I_(e,n,r)||(L_(e)??[{label:`Pitch along`,value:z_(U_(e),H_(e))},{label:`Span outside the pads`,value:C_(N_(e,`x`),N_(e,`y`))}])}function F_(e,t){let n=Math.abs(t.x-e.x)>=Math.abs(t.y-e.y)?`x`:`y`;return[{label:`Pads centre to centre`,value:S_(Math.hypot(t.x-e.x,t.y-e.y))},{label:`Gap between the pads`,value:S_(W_(e,t))},{label:`Span outside the pads`,value:S_(N_([e,t],n))}]}function I_(e,t,n){let r=e=>e.every(t=>t.length===e[0]?.length);if(r(t)&&r(n)&&t.length*n.length===e.length)return[{label:`Pitch along`,value:z_(e,`x`)},{label:`Pitch across`,value:z_(e,`y`)},{label:`Span outside the pads`,value:C_(N_(e,`x`),N_(e,`y`))}]}function L_(e){let t=(t,n)=>e.filter(e=>Math.abs(e[t]-n)<x_),n=e.map(e=>e.x),r=e.map(e=>e.y),[i,a,o,s]=[t(`x`,Math.min(...n)),t(`x`,Math.max(...n)),t(`y`,Math.min(...r)),t(`y`,Math.max(...r))];if([i,a,o,s].some(e=>e.length<2))return;let c=new Set([...i,...a,...o,...s]);if(c.size!==i.length+a.length+o.length+s.length)return;let l=e=>e.x>Math.min(...n)+x_&&e.x<Math.max(...n)-x_&&e.y>Math.min(...r)+x_&&e.y<Math.max(...r)-x_;if(!e.some(e=>!c.has(e)&&!l(e)))return[{label:`Pitch along`,value:V_([...B_(i,`y`),...B_(a,`y`),...B_(o,`x`),...B_(s,`x`)])},{label:`Rows centre to centre`,value:C_(Math.max(...n)-Math.min(...n),Math.max(...r)-Math.min(...r))},{label:`Span outside the pads`,value:C_(N_(e,`x`),N_(e,`y`))}]}function R_(e,t){let n=[];for(let r of[...e].sort((e,n)=>e[t]-n[t])){let e=n.at(-1);e&&Math.abs(e[0][t]-r[t])<x_?e.push(r):n.push([r])}return n}function z_(e,t){return V_(R_(e,j_(t)).flatMap(e=>B_(e,t)))}function B_(e,t){let n=e.map(e=>e[t]).sort((e,t)=>e-t);return n.slice(1).map((e,t)=>e-n[t]).filter(e=>e>x_)}function V_(e){let t=[...new Set(e.map($))].sort((e,t)=>Number(e)-Number(t));return t.length===0?`–`:`${t.join(`, `)} mm`}function H_(e){let t=t=>Math.max(...R_(e,j_(t)).map(e=>e.length));return t(`x`)>=t(`y`)?`x`:`y`}function U_(e){return R_(e,j_(H_(e))).reduce((e,t)=>t.length>e.length?t:e,[])}function W_(e,t){let n=e=>e.shape===`circle`&&e.width===e.height;if(n(e)&&n(t))return Math.max(0,Math.hypot(t.x-e.x,t.y-e.y)-e.width/2-t.width/2);let r=Math.max(0,Math.abs(t.x-e.x)-M_(e,`x`)-M_(t,`x`)),i=Math.max(0,Math.abs(t.y-e.y)-M_(e,`y`)-M_(t,`y`));return Math.hypot(r,i)}function G_(e,t){let n=new Map;for(let r of e)n.set(t(r),[...n.get(t(r))??[],r]);return n}var K_=()=>Mo(`light`).background,q_={width:297,height:210,margin:10};function J_(){return{width:(q_.width-2*q_.margin)*8,height:(q_.height-2*q_.margin-Y_)*8}}var Y_=8;function X_(e){return e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).replace(/"/g,`"`).replace(/'/g,`'`)}function Z_(e){let t={width:q_.width-2*q_.margin,height:q_.height-2*q_.margin},n={width:t.width,height:t.height-Y_};return[`<svg xmlns="http://www.w3.org/2000/svg" width="${t.width}mm" height="${t.height}mm" viewBox="0 0 ${t.width} ${t.height}">`,`<text x="0" y="5" font-size="4" font-family="Arial, sans-serif">${X_(e.title)}</text>`,`<image x="0" y="${Y_}" width="${n.width}" height="${n.height}" preserveAspectRatio="xMidYMid meet" href="${X_(e.image)}" />`,`<rect x="0" y="${Y_}" width="${n.width}" height="${n.height}" fill="none" stroke="currentColor" stroke-width="0.2" />`,`</svg>`].join(``)}function Q_(e,t){let n=t.map(e=>`<section class="sheet">${Z_(e)}</section>`).join(``);return[`<!doctype html>`,`<html><head><meta charset="utf-8"><title>${X_(e)}</title>`,`<style>`,`@page { size: A4 landscape; margin: ${q_.margin}mm }`,`html, body { margin: 0; background: Canvas; color: CanvasText; color-scheme: light }`,`.sheet { break-after: page; page-break-after: always }`,`.sheet:last-child { break-after: auto; page-break-after: auto }`,`</style></head><body>`,n,`</body></html>`].join(``)}var $_=5,ev=10,tv=`Print at 100 % (actual size), not fit to page; the bar must measure 10 mm.`;function nv(e){let t=e.shape===`circle`||e.shape===`oval`?`<ellipse cx="0" cy="0" rx="${$(e.width/2)}" ry="${$(e.height/2)}" />`:`<rect x="${$(-e.width/2)}" y="${$(-e.height/2)}" width="${$(e.width)}" height="${$(e.height)}" />`,n=e.drill===void 0?``:`<ellipse class="drill" cx="0" cy="0" rx="${$(e.drill.width/2)}" ry="${$(e.drill.height/2)}" />`,r=Math.max(.3,Math.min(e.width,e.height)*.5);return`<g transform="translate(${$(e.x)} ${$(-e.y)}) rotate(${$(-e.rotation)})">${t}${n}</g><text x="${$(e.x)}" y="${$(-e.y+r/3)}" font-size="${$(r)}">${X_(e.number)}</text>`}function rv(e,t){let n=[...t.pads.flatMap(e=>{let t=E_(e);return[{x:e.x-t.width/2,y:e.y-t.height/2},{x:e.x+t.width/2,y:e.y+t.height/2}]}),...t.courtyard,{x:0,y:0}],[r,i]=[Math.min(...n.map(e=>e.x)),Math.max(...n.map(e=>e.x))],[a,o]=[Math.min(...n.map(e=>-e.y)),Math.max(...n.map(e=>-e.y))],s=r-$_,c=a-$_-4,l=i-r+15+ev,u=Math.max(o-a,6)+10+4,d=i+$_,f=t.courtyard.map(e=>`${$(e.x)},${$(-e.y)}`).join(` `),p=[`<svg xmlns="http://www.w3.org/2000/svg" width="${$(l)}mm" height="${$(u)}mm" viewBox="${$(s)} ${$(c)} ${$(l)} ${$(u)}">`,`<text x="${$(s+1)}" y="${$(c+3)}" font-size="2.5">${X_(e)}</text>`,f===``?``:`<polygon class="courtyard" points="${f}" />`,`<path class="origin" d="M -1 0 H 1 M 0 -1 V 1" />`,...t.pads.map(nv),`<rect class="scale" x="${$(d)}" y="${$(a)}" width="${ev}" height="0.4" />`,`<text x="${$(d)}" y="${$(a+3)}" font-size="2">${ev} mm</text>`,`</svg>`].join(``);return[`<!doctype html>`,`<html><head><meta charset="utf-8"><title>${X_(e)} at 1:1</title>`,`<style>`,`@page { margin: 10mm }`,`html, body { margin: 0; background: #fff; color: #000; color-scheme: light; font-family: Arial, sans-serif }`,`p { font-size: 10pt; margin: 0 0 4mm }`,`svg { display: block }`,`svg g { fill: #999; stroke: #000; stroke-width: 0.05 }`,`svg .drill { fill: #fff }`,`svg text { fill: #000; text-anchor: start }`,`svg g + text { text-anchor: middle }`,`svg .courtyard, svg .origin { fill: none; stroke: #000; stroke-width: 0.05; stroke-dasharray: 0.3 0.3 }`,`svg .scale { fill: #000 }`,`</style></head><body>`,`<p>${X_(tv)}</p>`,p,`</body></html>`].join(``)}function iv(e){let t=window.open(``,`_blank`);return t?(t.document.open(),t.document.write(e),t.document.close(),t.focus(),t.setTimeout(()=>t.print(),0),!0):!1}function av(e){return(0,_.useMemo)(()=>({load:e=>B(`/api/part?id=${encodeURIComponent(e)}`),tick:async(e,t,n,r)=>{try{return await B(`/api/tick`,{id:e,items:t,ticked:n,shown:r})}catch(e){let t=e;if(t.status===409&&typeof t.data?.checklist==`string`)return{changed:t.data.checklist};throw e}},mark:async(t,n)=>{await B(`/api/verify`,{id:t,...n}),await e()},frame:async(e,t)=>URL.createObjectURL(await me(`/api/part-datasheet?id=${encodeURIComponent(e)}&file=${encodeURIComponent(t)}`)),release:e=>URL.revokeObjectURL(e),print:(e,t)=>iv(rv(e,t))}),[e])}function ov(e){return`Created ${e.id}: ${e.title}, ${e.pins} pin${e.pins===1?``:`s`}, footprint ${e.footprint}. Not verified: check it in ${e.verification}.`}function sv({label:e,shortcut:t,menu:n,index:r,enabled:i,checked:a,reason:o,onActivate:s}){return(0,X.jsxs)(`button`,{role:a===void 0?`menuitem`:`menuitemcheckbox`,"aria-checked":a,className:a?`menu-item checked`:`menu-item`,...n===void 0?{}:{"data-menu":n},"data-item":r,tabIndex:-1,"aria-disabled":!i||void 0,title:o,onClick:e=>{let t=!wm(e);t||Em(e),i&&s(t)},children:[(0,X.jsx)(`span`,{children:e}),t&&(0,X.jsx)(`kbd`,{children:t})]})}function cv(e,t,n){(0,_.useEffect)(()=>{if(!e)return;let r=e=>{e.target instanceof Node&&t.current?.contains(e.target)||n()};return window.addEventListener(`pointerdown`,r,!0),()=>window.removeEventListener(`pointerdown`,r,!0)},[e,t,n])}var lv=(e,t)=>(e+t)%t,uv=e=>e===`item`||e===`disabled`;function dv(e,t,n,r=uv){let i=e.length,a=t??(n===1?-1:i);for(let t=0;t<i;t++)if(a=lv(a+n,i),r(e[a]))return a;return null}var fv=e=>e?dv(e,null,1):null,pv=e=>e?dv(e,null,-1):null,mv=(e,t)=>e?dv(e,null,t,e=>e===`item`)??dv(e,null,t):null,hv=e=>mv(e,1),gv=e=>mv(e,-1),_v=(e,t,n=!0)=>({open:e,focus:t,preventDefault:n}),vv=(e,t)=>_v(e,{menu:e,item:t});function yv(e,t,n,r){let i=r.length,a={ArrowLeft:lv(t-1,i),ArrowRight:lv(t+1,i),Home:0,End:i-1}[e];return a===void 0?e===`ArrowDown`?vv(t,hv(r[t])):e===`ArrowUp`?vv(t,gv(r[t])):n===null?null:e===`Escape`?_v(null,{menu:t,item:null}):e===`Tab`?_v(null,`keep`,!1):null:_v(n===null?null:a,{menu:a,item:null})}function bv(e,t,n){let r=n[t.menu]??[],i=n.length,a={ArrowDown:dv(r,t.item,1),ArrowUp:dv(r,t.item,-1),Home:fv(r),End:pv(r)};if(e in a)return vv(t.menu,a[e]??null);if(e===`ArrowLeft`||e===`ArrowRight`){let r=lv(t.menu+(e===`ArrowLeft`?-1:1),i);return vv(r,hv(n[r]))}return e===`Escape`?_v(null,{menu:t.menu,item:null}):e===`Tab`?_v(null,{menu:t.menu,item:null},!1):null}function xv(e,t,n){return e===`Escape`?_v(null,`keep`):e===`Tab`?_v(null,`keep`,!1):e===`ArrowDown`||e===`Home`?vv(t,hv(n[t])):e===`ArrowUp`||e===`End`?vv(t,gv(n[t])):e===`ArrowLeft`||e===`ArrowRight`?_v(lv(t+(e===`ArrowLeft`?-1:1),n.length),`keep`):null}function Sv(e,t,n,r,i={}){return r.length===0||(i.alt||i.ctrl||i.meta)&&e!==`Tab`?null:t===null?n===null?null:xv(e,n,r):t.item===null?yv(e,t.menu,n,r):bv(e,{menu:t.menu,item:t.item},r)}function Cv(e){return hv(e)}var wv=e=>e.item===null?`[data-menu="${e.menu}"]:not([data-item])`:`[data-menu="${e.menu}"][data-item="${e.item}"]`;function Tv(e,t){let n=t instanceof HTMLElement&&e?.contains(t)?t.closest(`[data-menu]`):null;if(!n)return null;let r=n.dataset.item;return{menu:Number(n.dataset.menu),item:r===void 0?null:Number(r)}}function Ev(e){let t=(0,_.useRef)(null);return(0,_.useLayoutEffect)(()=>{let n=t.current;n&&(t.current=null,e.current?.querySelector(wv(n))?.focus())}),(0,_.useCallback)(n=>{let r=e.current?.querySelector(wv(n));r?r.focus():t.current=n},[e])}function Dv({entry:e,menu:t,index:n,view:r,selected:i,off:a,toggles:o,onRun:s}){if(e===`separator`)return(0,X.jsx)(`li`,{className:`menu-separator`,role:`separator`});let{label:c,shortcut:l,command:u,toggle:d}=e,{enabled:f,reason:p}=bh(e,r,i,a);return(0,X.jsx)(`li`,{role:`none`,children:(0,X.jsx)(sv,{label:c,...l?{shortcut:l}:{},...d?{checked:o[d]}:{},menu:t,index:n,enabled:f,...p?{reason:p}:{},onActivate:e=>u&&s(u,t,e)})})}function Ov({menu:e,index:t,view:n,selected:r,off:i,toggles:a,onRun:o}){return(0,X.jsx)(`ul`,{className:`menu-dropdown`,role:`menu`,"aria-label":e.title,children:e.entries.map((e,s)=>(0,X.jsx)(Dv,{entry:e,menu:t,index:s,view:n,selected:r,off:i,toggles:a,onRun:o},e===`separator`?`sep${s}`:e.label))})}function kv({menu:e,index:t,open:n,current:r,onPointer:i,onHover:a,onKeyboard:o,view:s,selected:c,off:l,toggles:u,onRun:d}){return(0,X.jsxs)(`div`,{className:`menu`,children:[(0,X.jsx)(`button`,{role:`menuitem`,"data-menu":t,"aria-haspopup":`menu`,"aria-expanded":n,tabIndex:r?0:-1,className:`menu-title${n?` open`:``}`,onClick:e=>{if(!wm(e))return o({open:t,focus:{menu:t,item:Cv(Th(s,c,l)[t])},preventDefault:!0});Em(e),i(t)},onPointerEnter:()=>a(t),children:e.title}),n&&(0,X.jsx)(Ov,{menu:e,index:t,view:s,selected:c,off:l,toggles:u,onRun:d})]})}function Av({run:e,view:t,selected:n,toggles:r,off:i,children:a}){let[o,s]=(0,_.useReducer)(wh,{open:null}),[c,l]=(0,_.useState)(0),u=(0,_.useRef)(null),d=Ev(u),f=o.open===null?null:vh.findIndex(e=>e.title===o.open),p=(0,_.useMemo)(()=>Th(t,n,i),[t,n,i]),m=e=>{s({type:`set`,title:e.open===null?null:vh[e.open]?.title??null}),e.focus!==`keep`&&(l(e.focus.menu),d(e.focus))},h=e=>{let t=Sv(e.key,Tv(u.current,document.activeElement),f,p,{alt:e.altKey,ctrl:e.ctrlKey,meta:e.metaKey});return t?(t.preventDefault&&e.preventDefault(),m(t),!0):!1};fh(f!==null,e=>void h(e)),cv(f!==null,u,(0,_.useCallback)(()=>s({type:`outside`}),[]));let g=(t,n,r)=>{r&&m({open:null,focus:{menu:n,item:null},preventDefault:!0}),s({type:`run`}),e(t)},v=e=>{l(e),s({type:`click`,title:vh[e]?.title??``})},y=e=>s({type:`hover`,title:vh[e]?.title??``});return(0,X.jsxs)(`header`,{className:`menubar hairline-b`,ref:u,children:[(0,X.jsx)(`span`,{className:`brand`,title:`copperflow`,children:`copperflow`}),(0,X.jsx)(`nav`,{className:`menus`,role:`menubar`,"aria-label":`Menu`,onKeyDown:e=>h(e)&&e.stopPropagation(),children:vh.map((e,a)=>(0,X.jsx)(kv,{menu:e,index:a,open:f===a,current:c===a,onPointer:v,onHover:y,onKeyboard:m,view:t,selected:n,off:i,toggles:r,onRun:g},e.title))}),(0,X.jsx)(`div`,{className:`menubar-end`,children:a})]})}var jv=`Main`;function Mv(e){let t=e?.schematic.pages?.map(e=>e.name);return t&&t.length>0?t:[jv]}function Nv(e,t){let n=Mv(e);return n.includes(t)?t:n[0]??`Main`}function Pv(e,t){let n=e.schematic.pages??[],r=n.find(e=>e.name===t);if(n.length<=1||!r)return e;let i=(e,t,n)=>{let r=new Set(t);return e.filter(e=>r.has(n(e)))},{schematic:a}=e;return{...e,schematic:{...a,symbols:i(a.symbols,r.parts,e=>e.component),wires:i(a.wires,r.wires,e=>e.id),labels:i(a.labels,r.labels,e=>e.id),drawings:i(a.drawings,r.drawings,e=>e.id),junctions:r.junctions,...a.noConnects?{noConnects:i(a.noConnects,r.parts,e=>e.component)}:{}}}}function Fv(e){for(let t=e.length+1;;t++)if(!e.includes(`Page ${t}`))return`Page ${t}`}function Iv(e,t){if(t===`Main`)return`${jv} is the first page and cannot be deleted`;let n=e?.schematic.pages?.find(e=>e.name===t)?.parts??[];if(n.length>0)return`Page ${t} still has parts (${n.join(`, `)}); move or delete them first`;let r=e?.circuit.connections.filter(e=>e.page===t)??[];if(r.length===0)return;let i=r.map(e=>`${e.from.replace(/^net\./,``)} to ${e.to.replace(/^net\./,``)}`).join(`, `);return`${t} still has ${r.length===1?`1 trace`:`${r.length} traces`}: ${i}; move or remove ${r.length===1?`it`:`them`} first`}function Lv(e){return e===`Main`?`${jv} is the first page and keeps its name`:void 0}function Rv(e,t){return e.status===`building`?`Building`:e.status===`failed`?`Build failed`:e.status!==`done`||!e.design?`Not built`:t===0?`Build OK`:`${t} ${t===1?`error`:`errors`}`}function zv(e,t){return e.status===`building`?`busy`:e.status===`failed`||t>0?`bad`:e.status===`done`?`good`:`idle`}function Bv({build:e,errors:t,onOpen:n}){return(0,X.jsxs)(`button`,{className:`build ${zv(e,t)}`,onClick:e=>{km(e),n()},title:`Show DRC`,children:[(0,X.jsx)(`span`,{className:`dot`,"aria-hidden":`true`}),(0,X.jsx)(`span`,{role:`status`,children:Rv(e,t)})]})}var Vv=`light`,Hv=`copperflow.theme`,Uv=()=>typeof window>`u`?void 0:window.localStorage,Wv=e=>e===`dark`||e===`light`?e:Vv;function Gv(e){try{return Wv(e()?.getItem(Hv))}catch{return Vv}}function Kv(e,t){try{let n=e();return n?(n.setItem(Hv,t),!0):!1}catch{return!1}}function qv(e,t){e.setAttribute(`data-theme`,t)}var Jv=e=>({themeLight:e===`light`,themeDark:e===`dark`}),Yv=e=>e===`dark`?`dots`:`lines`,Xv=(e,t,n)=>t===n?e:Zv(e,n),Zv=(e,t)=>({...e,schematic:Yv(t)}),Qv=(e,t,n,r,i)=>({id:e,title:t,icon:n,command:r,group:i}),$v=(e,t,n,r,i)=>({id:e,title:t,icon:n,pending:r,group:i}),ey=[Qv(`undo`,`Undo (Ctrl+Z)`,`undo`,`undo`,0),Qv(`redo`,`Redo (Ctrl+Y)`,`redo`,`redo`,0)],ty=[Qv(`zoomIn`,`Zoom in`,`zoomIn`,`zoomIn`,1),Qv(`zoomOut`,`Zoom out`,`zoomOut`,`zoomOut`,1),Qv(`fit`,`Fit all (K)`,`fit`,`fit`,1),Qv(`fitSelection`,`Fit selection`,`fitSelection`,`fitSelection`,1),Qv(`fitArea`,`Fit area`,`fitArea`,`fitArea`,1)],ny=e=>[Qv(`rotate`,`Rotate (Space)`,`rotate`,`rotate`,e),Qv(`rotateRight`,`Rotate right`,`rotateRight`,`rotateRight`,e)],ry=e=>[Qv(`gridStyle`,`Grid style`,`grid`,`gridStyle`,e),Qv(`snap`,`Snap (Alt+S)`,`snap`,`snap`,e)],iy=e=>[Qv(`alignLeft`,`Align left (Ctrl+Shift+L)`,`alignLeft`,`alignLeft`,e),Qv(`distributeH`,`Distribute horizontally (Ctrl+Shift+H)`,`distributeH`,`distributeH`,e)],ay=e=>Qv(`checkDrc`,`Check DRC`,`check`,`checkDrc`,e),oy={schematic:[...ey,...ty,...ry(2),Qv(`component`,`Component (Shift+F)`,`component`,`placeComponent`,3),Qv(`wire`,`Wire (Alt+W)`,`wire`,`wire`,3),Qv(`bus`,`Bus (Alt+B)`,`bus`,`drawBus`,3),Qv(`netLabel`,`Net label (Alt+N)`,`netLabel`,`netLabel`,3),Qv(`ground`,`Ground flag`,`ground`,`groundFlag`,3),Qv(`power`,`Power flag`,`power`,`powerFlag`,3),Qv(`noConnect`,`No connect flag`,`noConnect`,`noConnect`,3),Qv(`polyline`,`Polyline (Alt+L)`,`polyline`,`drawPolyline`,4),Qv(`arc`,`Arc (Alt+A)`,`arc`,`drawArc`,4),Qv(`circle`,`Circle (Alt+C)`,`circle`,`drawCircle`,4),Qv(`rectangle`,`Rectangle (Alt+R)`,`rectangle`,`drawRectangle`,4),Qv(`text`,`Text (Alt+T)`,`text`,`drawText`,4),...ny(5),...iy(6),ay(7)],pcb:[...ey,...ty,{id:`unit`,title:`Unit (Q)`,text:`unit`,command:`toggleUnit`,group:2},...ry(2),Qv(`via`,`Via (Alt+V)`,`via`,`placeVia`,3),$v(`boardOutline`,`Board outline`,`boardOutline`,_h,3),$v(`copperArea`,`Copper area`,`copperArea`,_h,3),ay(4),Qv(`singleRouting`,`Single routing (Alt+W)`,`singleRouting`,`singleRouting`,5),...iy(6),...ny(7),Qv(`gerber`,`Gerber`,`gerber`,`exportFabrication`,8)]};function sy(e,t,n={}){if(e.pending!==void 0)return{enabled:!1,title:`${e.title}: ${e.pending}`};let r=n[e.command];if(r!==void 0)return{enabled:!1,title:`${e.title}: ${r}`};let i=gh(e.command,t);return i?{enabled:!1,title:`${e.title}: ${i}`}:{enabled:!0,title:e.title}}function cy(e){let t=[];for(let n of oy[e]){let e=t.at(-1);e&&e[0]?.group===n.group?e.push(n):t.push([n])}return t}var ly=new Set([`wire`,`netLabel`,`groundFlag`,`powerFlag`,`fitArea`,`singleRouting`,`placeVia`,`noConnect`,`junction`,...k]);function uy(e){return ly.has(e)}var dy={snap:`snap`};function fy(e,t,n){let r=dy[e];return r?n[r]:t===e}function py(e){return uy(e)||e in dy}function my(e,t){return e?`wire`:t===`label`?`netLabel`:t===`gnd`?`groundFlag`:t===`vcc`?`powerFlag`:null}function hy(e){return e?A[e]:null}var gy={active:null,stop:null},_y=gy,vy=new Set;function yy(e){if(e.active!==_y.active||e.stop!==_y.stop){_y=e;for(let e of vy)e()}}function by(){return _y}function xy(){yy(gy)}function Sy(e){return vy.add(e),()=>{vy.delete(e)}}function Cy(){return(0,_.useSyncExternalStore)(Sy,by)}function wy(e,t){return t.active===e&&t.stop?`stop`:`run`}var Ty=m(),Ey=[`onPointerDown`,`onPointerMove`,`onPointerUp`,`onPointerCancel`,`onMouseDown`,`onMouseMove`,`onMouseUp`,`onDoubleClick`,`onWheel`,`onContextMenu`];function Dy(){let e=e=>e.stopPropagation();return Object.fromEntries(Ey.map(t=>[t,e]))}var Oy=`toolbar-view-slot`,ky=Dy();function Ay({children:e}){let[t,n]=(0,_.useState)(null);return(0,_.useLayoutEffect)(()=>n(document.getElementById(Oy)),[]),t?(0,Ty.createPortal)((0,X.jsx)(`div`,{className:`canvas-tools`,...ky,onClick:km,children:e}),t):null}function jy({item:e,unit:t}){if(e.text===`unit`)return(0,X.jsx)(X.Fragment,{children:t});let n=oh[e.icon];return(0,X.jsx)(n,{})}function My({view:e,unit:t,selected:n,toggles:r,off:i,run:a}){let o=Cy();return(0,X.jsxs)(`div`,{className:`studio-toolbar hairline-b`,role:`toolbar`,"aria-label":`Tools`,children:[cy(e).map((e,s)=>(0,X.jsxs)(_.Fragment,{children:[s>0&&(0,X.jsx)(`span`,{className:`toolbar-separator`,role:`separator`,"aria-orientation":`vertical`}),e.map(e=>{let s=e.command!==void 0&&fy(e.command,o.active,r),c=sy(e,n,i);return(0,X.jsx)(`button`,{className:e.text?`toolbar-button text`:`toolbar-button`,title:c.title,"aria-label":e.text===`unit`?`${e.title}, now ${t}`:c.title,"aria-disabled":!c.enabled||void 0,"aria-pressed":e.command!==void 0&&py(e.command)?s:void 0,"data-pressed":s||void 0,onClick:t=>{km(t),c.enabled&&e.command!==void 0&&(wy(e.command,o)===`stop`?o.stop?.():a(e.command))},children:(0,X.jsx)(jy,{item:e,unit:t})},e.id)})]},e[0]?.group)),(0,X.jsx)(`div`,{className:`toolbar-view-slot`,id:Oy})]})}var Ny=[`Designators`,`Quantity`,`Value`,`Footprint`,`Manufacturer`,`MPN`,`Supplier part`,`Verified`];function Py(e){return/[",\r\n]/.test(e)?`"${e.replace(/"/g,`""`)}"`:e}function Fy(e){return[Ny,...e.map(e=>[e.designators.join(` `),String(e.quantity),e.value||e.kind,e.footprint,e.manufacturer,e.mpn,e.supplier,e.libraryPart?e.verified?`yes`:`no`:``])].map(e=>e.map(Py).join(`,`)).join(`\r
|
|
15
|
-
`)+`\r
|
|
16
|
-
`}function Iy(e){return`${(e.split(/[\\/]/).at(-1)??e).replace(/\.circuit\.tsx$|\.tsx$/,``)}-bom.csv`}var Ly=[`F_Cu`,`In1_Cu`,`In2_Cu`,`B_Cu`,`F_Mask`,`B_Mask`,`F_Paste`,`B_Paste`,`F_Silkscreen`,`B_Silkscreen`,`Edge_Cuts`];function Ry(e,t,n){let r=(e,t)=>n.find(t=>t.endsWith(e))??t;return`upload ${e.split(`/`).pop()??e} to JLCPCB's PCB order, and ${r(`-bom.csv`,`the BOM`)} and ${r(`-pick-and-place.csv`,`the pick-and-place file`)} from ${t}/ at its assembly step (the zip holds them too)`}var zy=(e,t)=>`${e} ${t}${e===1?``:`s`}`;function By(e){let t=`Checks: ${zy(e.errors,`error`)}, ${zy(e.warnings,`warning`)}.`;return e.errors>0?`${t} Run check_circuit (or copperflow check <file>) and fix the errors before anyone orders this board.`:t}var Vy=3;function Hy(e){let t=e.slice(0,Vy).map(e=>`Warning: ${e}.`),n=e.length-Vy;return n>0?[...t,`And ${n} more ${n===1?`warning`:`warnings`}.`]:t}function Uy(e){if(!e.written)return`No fabrication files written: ${e.errors.join(`; `)}`;let t=Ry(e.zip,e.folder,e.files),n=e.model===void 0?[]:[e.model];return[`Wrote ${e.files.length} fabrication files to ${e.folder}/ and ${e.zip}.`,`U${t.slice(1)}.`,...n,...Hy(e.warnings),By(e.checks)].join(` `)}function Wy(e){return e.errors>0}var Gy=(e,t)=>`${e} ${t}${e===1?``:`s`}`;function Ky(e){return`The design rule check reports ${Gy(e.errors,`error`)} and ${Gy(e.warnings,`warning`)}. Look at them before you order this board.`}var qy=1e-9,Jy=(e,t)=>({x:e.x-t.x,y:e.y-t.y}),Yy=(e,t)=>({x:e.x+t.x,y:e.y+t.y}),Xy=(e,t)=>({x:e.x*t,y:e.y*t}),Zy=(e,t)=>e.x*t.y-e.y*t.x,Qy=(e,t)=>e.x===t.x&&e.y===t.y;function $y(e){return e.every((t,n)=>n===0||tl(e[n-1],t)!==`slanted`)}function eb(e){let t=e.map(e=>({x:H(e.x),y:H(e.y)})),n=t.filter((e,n)=>n===0||!Qy(t[n-1],e)),r=[];for(let[e,t]of n.entries()){let[i,a]=[r[r.length-1],n[e+1]];i&&a&&Math.abs(Zy(Jy(t,i),Jy(a,t)))<qy||r.push(t)}return r}function tb(e,t,n,r){let i=Zy(t,r);if(!(Math.abs(i)<qy))return Yy(e,Xy(t,Zy(Jy(n,e),r)/i))}function nb(e,t,n){let[r,i]=[e[t],e[t+1]],a=Jy(i,r),o=Yy(r,n),s=(r,i)=>{let s=e[r],c=e[i],l=c&&tb(c,Jy(s,c),o,a);return l?[l]:r===t?[s,Yy(s,n)]:[Yy(s,n),s]},c=t===0?[r,o]:s(t,t-1),l=t+1===e.length-1?[Yy(i,n),i]:s(t+1,t+2);return[...e.slice(0,t),...c,...l,...e.slice(t+2)]}function rb(e,t,n,r){let i={x:Te(e.x+n.x,r.step,r.snap),y:Te(e.y+n.y,r.step,r.snap)},a=Jy(t,e),o=Math.hypot(a.x,a.y);if(o<qy)return{x:0,y:0};let s={x:-a.y/o,y:a.x/o};return Xy(s,(i.x-e.x)*s.x+(i.y-e.y)*s.y)}function ib(e,t,n,r){let i=e[t],a={x:Te(i.x+n.x,r.step,r.snap),y:Te(i.y+n.y,r.step,r.snap)};return e.map((e,n)=>n===t?a:e)}function ab(e,t,n,r){let i=e[t.index],a=e[t.index+1];if(!i||t.kind===`segment`&&!a)return[...e];let o;o=$y(e)?Xl(e,t,n,r):t.kind===`corner`?ib(e,t.index,n,r):nb(e,t.index,rb(i,a,n,r));let s=eb(o);return s.length>=2?s:[...e]}var ob=e=>Math.max(e.length-1,0),sb=(e,t)=>Number.isInteger(t)&&t>=0&&t<ob(e),cb=e=>e.map(e=>({x:e.x,y:e.y}));function lb(e,t){let n=ob(e.points);if(!sb(e.points,t))return{message:`${e.id} has no segment ${t}; it has ${n} (0 to ${n-1})`};if(e.locked)return{message:`${e.id} is locked`};let[r,i]=[e.points.slice(0,t+1),e.points.slice(t+1)].filter(e=>e.length>=2);if(!r)return{edits:[{kind:`removeTrack`,id:e.id}]};let a=e.net??e.carried,o=a===void 0?{}:{net:a},s={kind:`setTrack`,id:e.id,...e.net===void 0?o:{},points:cb(r)};return i?{edits:[s,{kind:`addTrack`,...o,layer:e.layer,width:e.width,points:cb(i)}]}:{edits:[s]}}var ub={tracks:new Map,vias:new Map},db=(e,t)=>({x:e.x+t.x,y:e.y+t.y}),fb=(e,t)=>e.length===t.length&&e.every((e,n)=>e.x===t[n]?.x&&e.y===t[n]?.y),pb=(e,t)=>Math.hypot(t.x-e.at.x,t.y-e.at.y)<=e.diameter/2;function mb(e,t,n){return e.vias.filter(r=>{if(!t.has(r.id))return!1;if(r.locked)return void n.push(`${r.id} is locked`);let i=e=>[e.points[0],e.points.at(-1)].some(e=>e!==void 0&&pb(r,e)),a=e.tracks.find(e=>e.locked&&i(e));return!a||void n.push(`${r.id} has the locked track ${a.id} on it`)})}function hb(e,t,n,r,i){let a=t=>r.some(e=>pb(e,t))||!i(t,e.layer)&&!n.some(e=>pb(e,t)),[o,s]=[e.points[0],e.points.at(-1)];return eb(ul(e.points,t,{start:a(o),end:a(s)}))}function gb(e,t,n){let r=e.points.length-1,i=(e,t)=>(t===0||t===r)&&n.some(t=>pb(t,e));return e.points.some(i)?eb(e.points.map((e,n)=>i(e,n)?db(e,t):e)):e.points}function _b(e,t,n,r){let i=[];if(n.x===0&&n.y===0)return{edits:[],shapes:ub,skipped:i};let a=new Set(t),o=mb(e,a,i),s=new Map;for(let t of e.tracks){a.has(t.id)&&t.locked&&i.push(`${t.id} is locked`);let c=a.has(t.id)&&!t.locked?hb(t,n,e.vias,o,r):gb(t,n,o);!fb(c,t.points)&&c.length>=2&&s.set(t.id,c)}let c=new Map(o.map(e=>[e.id,db(e.at,n)]));return{edits:[...[...c].map(([e,t])=>({kind:`setVia`,id:e,at:t})),...[...s].map(([e,t])=>({kind:`setTrack`,id:e,points:[...t]}))],shapes:{tracks:s,vias:c},skipped:i}}function vb(e,t){if(!fb(t,e.points))return e.locked?{message:`${e.id} is locked`}:{kind:`setTrack`,id:e.id,points:[...t]}}function yb(e,t){let n=new Set(t),r=[...e.tracks.map(e=>({...e,kind:`removeTrack`})),...e.vias.map(e=>({...e,kind:`removeVia`}))].filter(e=>n.has(e.id)),i=r.filter(e=>!e.locked);return{edits:i.map(e=>({kind:e.kind,id:e.id})),removed:i.map(e=>e.id),skipped:r.filter(e=>e.locked).map(e=>`${e.id} is locked`)}}function bb(e,t){if(!e)return{message:`${t.id} is gone`};if(!mo(t,e.points))return{message:`the track changed; select the segment again`};let n={...e.named===void 0?{}:{net:e.named},...e.net===void 0?{}:{carried:e.net}},r=lb({id:e.id,...n,layer:e.layer,width:e.width,points:e.points,locked:e.locked},t.index);return`message`in r?r:{edits:r.edits,summary:`Delete segment ${t.index} of ${e.id}`}}function xb(e,t){return{tracks:new Map([...e.tracks,...t.tracks]),vias:new Map([...e.vias,...t.vias])}}function Sb(e,t){return{tracks:e.tracks.map(e=>{let n=t.tracks.get(e.id);return n?{...e,points:[...n]}:e}),vias:e.vias.map(e=>{let n=t.vias.get(e.id);return n?{...e,at:n}:e})}}function Cb(e,t,n){let r=new Set(t),i=e.tracks.filter(e=>r.has(e.id)&&e.locked!==n),a=e.vias.filter(e=>r.has(e.id)&&e.locked!==n),o=[...i.map(e=>({kind:`setTrack`,id:e.id,locked:n})),...a.map(e=>({kind:`setVia`,id:e.id,locked:n}))];return o.length===0?{message:`The selected copper is already ${n?`locked`:`unlocked`}.`}:{edits:o,summary:`${n?`Lock`:`Unlock`} ${st([...i,...a].map(e=>e.id))}`}}function wb(e,t){return!t&&e.copper.length>0&&e.total===e.copper.length}function Tb(e){let t=e.lastIndexOf(`/`);return t>0?e.slice(0,t):void 0}var Eb=e=>/(^|\/)hole:\d+$/.test(e);function Db(e,t,n){return`${e} is a ${Eb(e)?`hole`:`copper pour`} inside the sub-sheet instance ${t}; edit ${n??`its sheet file`} instead`}var Ob=(e,t)=>e.x===t.x&&e.y===t.y,kb=(e,t,n)=>(t.x-e.x)*(n.y-e.y)-(t.y-e.y)*(n.x-e.x);function Ab(e,t,n,r){let[i,a,o,s]=[kb(n,r,e),kb(n,r,t),kb(e,t,n),kb(e,t,r)];if((i>0&&a<0||i<0&&a>0)&&(o>0&&s<0||o<0&&s>0))return!0;let c=(e,t,n)=>Math.min(e.x,t.x)<=n.x&&n.x<=Math.max(e.x,t.x)&&Math.min(e.y,t.y)<=n.y&&n.y<=Math.max(e.y,t.y);return i===0&&c(n,r,e)||a===0&&c(n,r,t)||o===0&&c(e,t,n)||s===0&&c(e,t,r)}function jb(e){let t=e.length;if(t<3)return`an outline needs at least 3 corners`;if(e.some((n,r)=>Ob(n,e[(r+1)%t])))return`two corners in a row are at the same place`;for(let n=0;n<t;n++)for(let r=n+1;r<t;r++){if(r===n+1||n===0&&r===t-1)continue;let[i,a,o,s]=[e[n],e[(n+1)%t],e[r],e[(r+1)%t]];if(Ab(i,a,o,s))return`two of its edges cross`}let n=e.reduce((n,r,i)=>n+kb({x:0,y:0},r,e[(i+1)%t]),0);return Math.abs(n)<1e-9?`its corners are all on one line, so it has no area`:void 0}function Mb(e,t){return`${t}:${e.filter(e=>e.tag===t).length+1}`}var Nb=3.2,Pb=100,Fb=e=>({tool:e,points:[]}),Ib=(e,t)=>e.x===t.x&&e.y===t.y,Lb=e=>({state:e});function Rb(e){return e.filter((t,n)=>n===0||!Ib(t,e[n-1]))}function zb(e){let t=Rb(e.points);if(t.length>=3&&t.at(-1)&&Ib(t[0],t.at(-1))&&t.pop(),t.length<3)return Lb(e);let n=jb(t);return n?{state:e,refused:`Not closed: ${n}`}:{state:Fb(e.tool),outline:t}}function Bb(e,t,n){if(e.tool===`hole`)return{state:e,hole:t};if(n&&e.points.length>0)return zb(e);let r=e.points[0];return r&&e.points.length>=3&&Ib(r,t)?zb(e):Lb({...e,points:Rb([...e.points,t])})}function Vb(e,t){switch(t.type){case`press`:return Bb(e,t.at,t.double);case`finish`:return e.tool===`pour`?zb(e):Lb(e);case`removeCorner`:return Lb({...e,points:e.points.slice(0,-1)});case`cancel`:return{state:e.points.length>0?Fb(e.tool):null}}}function Hb(e,t){return!e||e.tool!==`pour`||e.points.length===0?[]:t?Rb([...e.points,t]):[...e.points]}function Ub(e){let t=e.circuit.nets.flatMap(e=>e.names);return t.includes(`GND`)?`GND`:t[0]}function Wb(e,t,n){return{kind:`addPour`,net:e,layer:t,...n?{outline:[...n]}:{}}}var Gb=(e,t,n)=>`add a ${e} copper pour on the ${t} layer${n?` over the whole board`:``}`;function Kb(e,t){return{kind:`addHole`,x:e.x,y:e.y,diameter:t}}var qb=e=>`add a ${e} mm hole`;function Jb(e){let t=Number(e.trim().replace(/\s*mm$/i,``));return e.trim()===``||!Number.isFinite(t)||t<=0||t>Pb?{message:`The diameter must be a number of mm above 0 and at most ${Pb}`}:Math.round(t*1e3)/1e3}function Yb(e,t,n,r){let i=t.map((e,t)=>t===n?{x:r.x,y:r.y}:{x:e.x,y:e.y}),a=jb(i);return a?{message:`Not moved: the outline would not be a simple polygon (${a})`}:{edit:{kind:`setPour`,id:e,props:{outline:i}},summary:`move a corner of ${e}`}}function Xb(e,t,n){let r=Tb(n);if(r!==void 0)return Db(n,r,Ih({parts:e.parts??[],imports:e.imports??[]},r));let i=e.boardItems?.find(e=>e.id===n);return i?t.has(n)?`${n} is locked`:i.editable?null:`${n} is read-only (${i.readonlyReason})`:`${n} is not in the code yet`}var Zb=e=>Number(e.slice(e.indexOf(`:`)+1)),Qb=e=>e.tag===`hole`?`hole ${Zb(e.id)}`:`copper pour ${Zb(e.id)}`;function $b(e,t){return n=>{let r=n.map(n=>({id:n,blocker:Xb(e,t,n)})),i=r.flatMap(e=>e.blocker===null?[e.id]:[]);return{edits:[...i].sort((e,t)=>Zb(t)-Zb(e)).map(e=>Eb(e)?{kind:`removeHole`,id:e}:{kind:`removePour`,id:e}),names:i.flatMap(t=>e.boardItems?.find(e=>e.id===t)??[]).map(Qb),skipped:r.flatMap(e=>e.blocker??[]),removed:i}}}var ex=`Esc or a right click stops.`;function tx(e){if(e)return e.tool===`hole`?`Click where the hole goes; set its diameter in the field. ${ex}`:e.points.length===0?`Click the first corner of the copper pour. ${ex}`:`Click for each corner; double click, Enter or a click on the first corner closes the pour. Backspace removes a corner, Esc cancels.`}var nx=[{value:`top`,label:`Top Layer`},{value:`bottom`,label:`Bottom Layer`}],rx=[{value:`inner1`,label:`Inner Layer 1`},{value:`inner2`,label:`Inner Layer 2`}],ix=[{value:`relief`,label:`Relief (spokes)`},{value:`solid`,label:`Solid`}],ax=e=>String(Number(e.toFixed(4))),ox=e=>e===void 0?`Not filled`:`${e.toFixed(2)} mm²`;function sx(e,t){let n=e.circuit.nets.flatMap(e=>e.names[0]?[{value:e.names[0],label:e.names[0]}]:[]),r=e.pcb.pours.find(e=>e.id===t.id);return[{label:`Net`,value:Fu(e,t.net),field:`net`,choices:n},{label:`Layer`,value:t.layer,field:`layer`,choices:e.pcb.board?.layers===4?[...nx,...rx]:nx},{label:`Priority`,value:String(t.priority),field:`priority`},{label:`Clearance (mm)`,value:t.clearance===void 0?``:ax(t.clearance),field:`clearance`},{label:`Min width (mm)`,value:ax(t.minWidth),field:`minWidth`},{label:`Thermal`,value:t.thermal,field:`thermal`,choices:ix},{label:`Outline`,value:t.outline?`${t.outline.length} corners`:`Whole board`},{label:`Fill area`,value:ox(r?.area)}]}function cx(e){return[{label:`X (mm)`,value:ax(e.x),field:`x`},{label:`Y (mm)`,value:ax(e.y),field:`y`},{label:`Diameter (mm)`,value:ax(e.diameter),field:`diameter`}]}function lx(e,t){let n=Nu(e).find(e=>e.id===t);if(n)return{kind:`pour`,title:`Copper pour`,rows:sx(e,n)};let r=e.pcb.holes.find(e=>e.id===t);return r&&{kind:`hole`,title:`Hole`,rows:cx(r)}}function ux(e,t,n){let r=Number(e.trim());return e.trim()===``||!Number.isFinite(r)?{message:`${t} must be a number`}:n===`whole`&&!Number.isInteger(r)?{message:`${t} must be a whole number`}:n===`positive`&&r<=0?{message:`${t} must be above 0`}:r}function dx(e,t){return e===`net`||e===`layer`||e===`thermal`?t:e===`clearance`&&t.trim()===``?null:ux(t,e,e===`priority`?`whole`:`positive`)}function fx(e,t){return e===`diameter`?Jb(t):ux(t,e,`any`)}function px(e,t,n,r){let i=lx(e,t)?.rows.find(e=>e.field===n);if(!i||i.value===r.trim())return;let a=Eb(t),o=a?fx(n,r):dx(n,r);if(typeof o==`object`&&o)return o;let s=`set ${t} ${n}=${o===null?`the net class's`:o}`;return a?{edit:{kind:`setHole`,id:t,props:{[n]:o}},summary:s}:{edit:{kind:`setPour`,id:t,props:{[n]:o}},summary:s}}function mx(e,t){let n=Eb(e)?`hole`:`copper pour`;return t.locked.has(e)?t.violated.has(e)?{command:`lock`,label:`Lock again`,pressed:!0,title:`Changed outside the editor: lock it again to accept the change`}:{command:`unlock`,label:`Locked`,pressed:!0,title:`Unlock this ${n}`}:{command:`lock`,label:`Lock`,pressed:!1,title:`Lock this ${n}, so the agent cannot change or remove it`}}function hx(e,t,n,r=new Set){return Ct([...e.names,...e.board],t,n,r)}var gx=.5,_x=e=>Math.round(e*1e3)/1e3||0,vx=e=>e.pcb??{x:0,y:0,rotation:0};function yx(e,t,n){let r=[{x:e.minX,y:e.minY},{x:e.maxX,y:e.minY},{x:e.maxX,y:e.maxY},{x:e.minX,y:e.maxY}].map(e=>wx(Cx(e,t),n)),i=r.map(e=>e.x),a=r.map(e=>e.y);return{minX:Math.min(...i),maxX:Math.max(...i),minY:Math.min(...a),maxY:Math.max(...a)}}var bx=(e,t)=>e.minX<t.maxX&&t.minX<e.maxX&&e.minY<t.maxY&&t.minY<e.maxY;function xx(e,t,n,r){let i=[t,...n].filter(e=>!r(e.name)).map(e=>e.name);if(i.length>0)return`Place ${i.join(`, `)} on the board first (pcbX and pcbY on the instance), then replicate the layout.`;let a=Dx(e,t);if(!a)return;let o=[t,...n].map(e=>({name:e.name,box:yx(a,vx(t),vx(e))}));for(let[e,t]of o.entries()){let n=o.slice(e+1).find(e=>bx(t.box,e.box));if(n)return`${t.name} and ${n.name} would overlap; place the instances apart first, then replicate the layout.`}}function Sx(e,t){let n=t*Math.PI/180,[r,i]=Number.isInteger(t/90)?[[1,0],[0,1],[-1,0],[0,-1]][(t/90%4+4)%4]:[Math.cos(n),Math.sin(n)];return{x:e.x*r-e.y*i,y:e.x*i+e.y*r}}var Cx=(e,t)=>Sx({x:e.x-t.x,y:e.y-t.y},-t.rotation),wx=(e,t)=>{let n=Sx(e,t.rotation);return{x:_x(n.x+t.x),y:_x(n.y+t.y)}};function Tx(e,t){let n=gn(e,t)?.pcb;return n!==void 0&&(n.x!==0||n.y!==0)}function Ex(e,t){for(let n of t){let t=gn(e,n)??gn(e,_n(e,n)?.outer??``);if(t)return t}}function Dx(e,t){let n=new Set(t.parts),r=e.pcb.parts.filter(e=>n.has(e.component)).flatMap(e=>e.courtyard);if(r.length===0)return;let i=r.map(e=>e.x),a=r.map(e=>e.y);return{minX:Math.min(...i)-gx,maxX:Math.max(...i)+gx,minY:Math.min(...a)-gx,maxY:Math.max(...a)+gx}}function Ox(e,t,n=[]){if(t?.startsWith(`net.${e.path}/`))return!0;let r=new Set(e.parts);return n.length>0&&n.every(e=>r.has(e.split(`#`)[0]??``))}function kx(e,t,n,r,i=[]){if(n?.startsWith(`net.${t.path}/`))return!0;let a=new Set(t.parts);if(i.length>0&&i.every(e=>a.has(e.split(`#`)[0]??``)))return!0;let o=Dx(e,t);return o!==void 0&&r.every(e=>e.x>=o.minX&&e.x<=o.maxX&&e.y>=o.minY&&e.y<=o.maxY)}function Ax(e,t,n){let r=_n(e,t)?.localId;return e.circuit.components.find(e=>e.instance===n.path&&e.localId===r)?.id}function jx(e,t,n,r){if(t===void 0)return;if(t.startsWith(`net.${n.path}/`))return`net.${r.path}/${t.slice(`net.${n.path}/`.length)}`;if(t.startsWith(`net:`)){let[n,i]=t.slice(4).split(`.`),a=n===void 0?void 0:Ax(e,n,r);return a&&i?`net:${a}.${i}`:void 0}let i=t.replace(/^net\./,``),a=n.ports.find(e=>!e.bus&&e.net===i),o=a&&r.ports.find(e=>e.name===a.name);return o?`net.${o.net}`:t}function Mx(e,t){let n=vx(t);return e.circuit.components.flatMap(r=>{if(r.instance!==t.path||r.localId===void 0||typeof r.props.pcbX==`number`&&typeof r.props.pcbY==`number`)return[];let i=e.pcb.parts.find(e=>e.component===r.id);if(!i)return[];let a=Cx(i,n),o=((i.rotation-n.rotation)%360+360)%360,s={pcbX:_x(a.x),pcbY:_x(a.y),...o===0?{}:{pcbRotation:_x(o)}};return[{kind:`setProps`,part:r.localId,props:s}]})}function Nx(e,t,n,r){let i=t.tracks.filter(t=>kx(e,n,t.net,t.points,t.pads)),a=t.vias.filter(t=>kx(e,n,t.net,[t.at])),o=vx(n);return r.flatMap(r=>{let s=vx(r),c=e=>wx(Cx(e,o),s),l=t=>{let i=jx(e,t,n,r);return i===void 0?{}:{net:i}},u=[...t.tracks.filter(e=>Ox(r,e.net,e.pads)).map(e=>({kind:`removeTrack`,id:e.id})),...t.vias.filter(e=>Ox(r,e.net)).map(e=>({kind:`removeVia`,id:e.id}))],d=[...i.map(e=>({kind:`addTrack`,...l(e.net),layer:e.layer,width:e.width,points:e.points.map(c)})),...a.map(e=>({kind:`addVia`,...l(e.net),at:c(e.at),drill:e.drill,diameter:e.diameter,layers:[...e.layers]}))];return[...u,...d]})}function Px(e,t,n){let r=t.filter(e=>n.has(e.name)||n.has(e.path)).map(e=>e.name);if(r.length===0)return;let[i,a]=r.length===1?[`is`,`it`]:[`are`,`them`];return`${r.join(`, `)} ${i} locked; unlock ${a} to replicate the layout of ${e.name} to ${a}.`}function Fx(e,t,n,r=new Set){if(!e)return{message:`Wait for the build to finish, then try again.`};let i=Ex(e,t);if(!i)return{message:`Select a part of the instance whose layout to copy, or its symbol on the schematic.`};let a=(e.circuit.instances??[]).filter(e=>e.file===i.file&&e.path!==i.path&&!e.path.includes(`/`));if(a.length===0)return{message:`${i.name} is the only instance of ${i.sheet}; there is nothing to copy its layout to.`};let o=Px(i,a,r);if(o)return{message:o};let s=xx(e,i,a,n??(t=>Tx(e,t)));if(s)return{message:s};let c=a.map(e=>e.name).join(`, `),l={file:i.file,edits:Mx(e,i),summary:`Replicate the placement of ${i.name} in ${i.sheet}`},u={edits:Nx(e,e.pcb,i,a),summary:`Replicate the copper of ${i.name} to ${c}`};return l.edits.length===0&&u.edits.length===0?{message:`${i.name} has no placement or copper the other instances lack.`}:{source:i.name,targets:a.map(e=>e.name),sheet:l,layout:u}}var Ix={toggleUnit:`toggleUnit`,gridStyle:`toggleGridStyle`,snap:`toggleSnap`,toggleLeftPanel:`toggleLeftPanel`,toggleRightPanel:`toggleRightPanel`,toggleBottomPanel:`toggleBottomPanel`,clearHighlight:`clearHighlight`,placeComponent:`openLibrary`};[...w];var Lx=[`wire`,`netLabel`,`groundFlag`,`powerFlag`,...k],Rx=[`noConnect`,`junction`],zx=[`singleRouting`,`placeVia`,`routingCorner`],Bx=[`placePour`,`placePourBoard`,`placeHole`],Vx=[`filletTracks`,`straightenTracks`],Hx=new Set;function Ux(e){return Hx.add(e),()=>{Hx.delete(e)}}function Wx(e){for(let t of Hx)if(t(e))return!0;return!1}function Gx(e){let t=(0,_.useRef)(e);t.current=e,(0,_.useEffect)(()=>Ux(e=>{let n=t.current[e];return n?(n(),!0):!1}),[])}var Kx=(e,t)=>e.by===`router`&&!e.locked&&(t===void 0||t.has(e.id)),qx=1e-6;function Jx(e,t,n){let[r,i]=[n.x-t.x,n.y-t.y],a=r*r+i*i,o=a===0?0:Math.max(0,Math.min(1,((e.x-t.x)*r+(e.y-t.y)*i)/a));return Math.hypot(e.x-(t.x+o*r),e.y-(t.y+o*i))}function Yx(e,t){if(t.at===void 0||t.diameter===void 0)return!1;let n=t.diameter/2+(e.width??0)/2+qx,r=t.at;return e.points.length===1?Math.hypot(e.points[0].x-r.x,e.points[0].y-r.y)<=n:e.points.some((t,i)=>i>0&&Jx(r,e.points[i-1],t)<=n)}function Xx(e,t={}){let n=t.ids===void 0?void 0:new Set(t.ids),r=[],i=e.tracks.filter(e=>{if(!Kx(e,n))return!1;let i=t.lockedPart?.(e);return i!==void 0&&r.push(`${e.id} starts on the locked part ${i}`),i===void 0}),a=e.tracks.filter(e=>e.by!==`router`),o=[],s=e.vias.filter(e=>{if(!Kx(e,n))return!1;let t=a.some(t=>Yx(t,e));return t&&o.push(e.id),!t});return{edits:[...i.map(e=>({kind:`removeTrack`,id:e.id})),...s.map(e=>({kind:`removeVia`,id:e.id}))],skipped:r,kept:o}}var Zx=[`top`,`bottom`,`inner1`,`inner2`],Qx=e=>e===4?Zx:[`top`,`bottom`],$x=({x0:e,x1:t,y0:n,y1:r})=>Math.max(0,t-e+1)*Math.max(0,r-n+1),eS=class{cell;cells=new Map;wide=[];constructor(e){if(this.cell=e,!(e>0))throw Error(`Grid cell size must be positive, got ${e}`)}insert(e,t){let n=this.rangeOf(t);$x(n)>4096?this.wide.push(e):tS(n,t=>{let n=this.cells.get(t);n===void 0?this.cells.set(t,[e]):n.push(e)})}query(e){let t=this.rangeOf(e),n=new Set(this.wide),r=e=>e?.forEach(e=>n.add(e));return $x(t)>4096?this.cells.forEach(r):tS(t,e=>r(this.cells.get(e))),[...n]}rangeOf(e){if(![e.minX,e.minY,e.maxX,e.maxY].every(Number.isFinite))throw Error(`Grid box must have finite bounds, got ${JSON.stringify(e)}`);let t=e=>Math.floor(e/this.cell);return{x0:t(e.minX),x1:t(e.maxX),y0:t(e.minY),y1:t(e.maxY)}}};function tS({x0:e,x1:t,y0:n,y1:r},i){for(let a=e;a<=t;a++)for(let e=n;e<=r;e++)i(`${a},${e}`)}var nS=[`top`,`inner1`,`inner2`,`bottom`],rS=1e-9,iS=(e,t)=>e.layers===`through`||e.layers===t,aS=e=>({core:[e],radius:0});function oS(e){return e.reduce((t,n,r)=>r===0?0:t+Math.hypot(n.x-(e[r-1]?.x??n.x),n.y-(e[r-1]?.y??n.y)),0)}function sS(e){let t=e.layers.map(e=>nS.indexOf(e));return new Set(nS.slice(Math.min(...t),Math.max(...t)+1))}function cS(e,t,n){return t!==void 0&&_i(t,aS(n))<=rS}function lS(e,t,n){return e.flatMap(e=>e.pads.filter(e=>iS(e,n)&&cS(e,si(e),t)))}function uS(e,t){return _i(e,t)<=rS}function dS(e,t){if(t.length===0)return{message:`Select parts, or a sub-sheet instance, to route their connections.`};let n=t.length===1?gn(e,t[0]):void 0;if(n)return{kind:`instance`,instance:n.path};let r=new Set(t.map(t=>_n(e,t)?.outer)),[i]=r;if(r.size===1&&i!==void 0){let n=vn(e,i);if(n.length===t.length&&n.every(e=>t.includes(e)))return{kind:`instance`,instance:i}}return{kind:`parts`,parts:[...t]}}function fS(e){return e.length===0?{message:`Click a net in the Nets panel to highlight it, then Autoroute net.`}:{kind:`nets`,nets:[...e]}}function pS(e,t,n=new Set){if(!e)return{message:`Wait for the build to finish, then try again.`};let r=Cn(n,e),i=t=>{let n=t.points[0];return n===void 0?void 0:lS(e.pcb.parts,n,t.layer).find(e=>r.has(e.component))?.component},a=t.length===0?void 0:t,{edits:o,skipped:s}=Xx(e.pcb,{...a?{ids:a}:{},lockedPart:i});if(o.length>0)return a?{ids:[...a]}:{};let c=a?`None of the selected copper was made by the router and unlocked; Unroute removes only that`:`The board has no unlocked router copper to remove`;return{message:s.length===0?`${c}.`:`${c}: ${s.join(`; `)}.`}}function mS(e,t){if(t.length===0)return{message:`Select the parts to place first.`};let n=t.flatMap(t=>gn(e,t)?.parts??[t]);return{kind:`parts`,parts:[...new Set(n)]}}function hS(e,t){for(let n of t){let t=gn(e,n)?.path??_n(e,n)?.outer;if(t!==void 0)return{kind:`instance`,instance:t}}return{message:`Select a part of a sub-sheet instance, or its symbol on the schematic, to place that instance.`}}function gS(e,t,n){let r=e.ask(t,n)?.trim();return r===void 0||r===``?void 0:r}async function _S(e){let t=gS(e,`Name of the new page`,Fv(Mv(e.design)));t!==void 0&&await e.edit([{kind:`addPage`,name:t}],`add page ${t}`)&&e.openPage(t)}async function vS(e){let t=Lv(e.page);if(t)return e.notify(t);let n=gS(e,`New name for page ${e.page}`,e.page);n!==void 0&&n!==e.page&&await e.edit([{kind:`renamePage`,from:e.page,to:n}],`rename page ${e.page} to ${n}`)&&e.openPage(n)}async function yS(e){let t=Iv(e.design,e.page);if(t)return e.notify(t);let n=Mv(e.design).indexOf(e.page),r=Mv(e.design)[Math.max(0,n-1)]??`Main`;await e.edit([{kind:`removePage`,name:e.page}],`delete page ${e.page}`)&&e.openPage(r)}function bS(e,t){return e===`addPage`?_S(t):e===`renamePage`?vS(t):yS(t)}function xS(e,t){return t===`Main`?[...e]:e.map(e=>(e.kind===`addPart`||e.kind===`addDrawing`||e.kind===`addTrace`)&&e.page===void 0?{...e,page:t}:e)}function SS(e){let t=dn(e),n=`strokeWidth`in e?e.strokeWidth/2:0;return{minX:t.minX-n,minY:t.minY-n,maxX:t.maxX+n,maxY:t.maxY+n}}function CS(e){let t=[...vc(e).map(e=>e.box),...df(e).map(e=>e.box)];t.push(...e.labels.map(Dr),...e.drawings.map(SS));let n=Oe([...e.wires.flatMap(e=>e.points),...e.junctions]);return n&&t.push(n),ke(t)}var wS=.04;function TS(e,t){let n=document.createElement(`canvas`);n.width=e.width,n.height=e.height;let r=n.getContext(`2d`);if(r)return r.fillStyle=t,r.fillRect(0,0,e.width,e.height),{canvas:n,ctx:r}}function ES(e,t,n){let r=Pv(e,t).schematic,i=CS(r),a=Mo(`light`),o=i&&TS(n,a.background);if(i&&o)return Fo(a),_c(o.ctx,r,{camera:be(i,n,wS),size:n},{ratio:1}),o.canvas.toDataURL(`image/png`)}function DS(e,t){let n=e.pcb,r=Oe(n.board?.outline??[])??ke(n.parts.map(e=>({minX:e.x-1,minY:e.y-1,maxX:e.x+1,maxY:e.y+1}))),i=r&&TS(t,K_());if(!r||!i)return;let a=be(r,t,wS);return Yf(i.ctx,n,{camera:a,size:t},{ratio:1,copper:{tracks:n.tracks,vias:n.vias,selected:new Set}}),i.canvas.toDataURL(`image/png`)}function OS(e,t,n=Wv(document.documentElement.getAttribute(`data-theme`))){let r=J_(),i=[];try{for(let n of Mv(e)){let a=ES(e,n,r);a&&i.push({title:`${t} · Schematic · ${n}`,image:a,...r})}}finally{Fo(Mo(n))}let a=DS(e,r);return a&&i.push({title:`${t} · PCB`,image:a,...r}),i}function kS(e,t){let n=window.open(``,`_blank`);return n?(n.document.open(),n.document.write(Q_(e,t)),n.document.close(),n.focus(),n.setTimeout(()=>n.print(),0),!0):!1}var AS=12.7,jS=e=>Math.round(e*1e3)/1e3+0;function MS(e,t,n){let r=t.find(t=>t.name===e);return r?n.has(e)?`locked`:r.editable?void 0:`read-only`:`inside a sub-sheet; change it in its sheet`}function NS(e,t,n){let r=[],i=[];for(let a of e){let e=MS(a,t,n);e===void 0?r.push(a):i.push(`${a} (${e})`)}return{ok:r,skipped:i}}var PS=e=>e.length===0?``:`; left ${e.join(`, `)}`;function FS(e,t,n,r){let i=e.filter(e=>t.some(t=>t.component===e));if(i.length===0)return{message:`Select a part on the PCB to flip.`};let{ok:a,skipped:o}=NS(i,n,r);if(a.length===0)return{message:`Cannot flip ${o.join(`, `)}.`};let s=a.map(e=>{let r=t.find(t=>t.component===e),i=n.find(t=>t.name===e)?.props??{},a=i.pcbX||i.pcbY?{}:{pcbX:jS(r.x),pcbY:jS(r.y)};return{kind:`setProps`,part:e,props:{layer:r.side===`bottom`?`top`:`bottom`,...a}}}),c=new Set(a.map(e=>t.find(t=>t.component===e)?.side)),l=c.size===1?c.has(`bottom`)?` to the top`:` to the bottom`:``;return{edits:s,summary:`flip ${a.join(`, `)}${l}${PS(o)}`,skipped:o}}var IS=e=>({x:e.reduce((e,t)=>e+t.x,0)/e.length,y:e.reduce((e,t)=>e+t.y,0)/e.length});function LS(e){let t=[...new Set(e.map(e=>e.page??0))].sort((e,t)=>e-t),n=new Map,r=0;for(let i of t){let t=e.filter(e=>(e.page??0)===i),a=Math.min(...t.map(e=>e.x)),o=Math.max(...t.map(e=>e.x)),s=IS(t).y;for(let e of t)n.set(e.component,{x:r+(e.x-a)*AS,y:(e.y-s)*AS});r+=(o-a)*AS+10}let i=IS([...n.values()]);return new Map([...n].map(([e,t])=>[e,{x:t.x-i.x,y:t.y-i.y}]))}function RS(e,t,n,r,i){let a=e.filter(e=>t.some(t=>t.component===e)&&n.some(t=>t.component===e));if(a.length===0)return{message:`No part is on both the schematic and the PCB.`};let{ok:o,skipped:s}=NS(a,r,i);if(o.length===0)return{message:`${s.join(`, `)} cannot move: locked or read-only.`};let c=o.map(e=>t.find(t=>t.component===e)),l=LS(c),u=IS(o.map(e=>n.find(t=>t.component===e)));return{edits:c.map(e=>{let t=l.get(e.component),n=e.rotation===void 0?{}:{pcbRotation:e.rotation};return{kind:`setProps`,part:e.component,props:{pcbX:jS(u.x+t.x),pcbY:jS(u.y+t.y),...n}}}),summary:`place ${o.length===1?o[0]:`${o.length} parts`} as on the schematic${PS(s)}`,skipped:s}}var zS=(e,t)=>e.kind===t.kind&&e.footprint===t.footprint&&e.value===t.value;function BS(e,t,n,r){let i=t.find(t=>t.id===e.parts[0]);if(i){let e=t.filter(e=>zS(e,i)).map(e=>e.id),n=[i.kind,i.value,i.footprint].filter(e=>e!==void 0&&e!==``).join(`, `);return{parts:e,drawings:[],note:`Selected ${e.length} ${e.length===1?`part`:`parts`} like ${i.id} (${n})`}}let a=n.find(t=>t.id===e.drawings[0]);if(a){let e=n.filter(e=>e.kind===a.kind).map(e=>e.id);return{parts:[],drawings:e,note:`Selected ${e.length} ${a.kind} ${e.length===1?`drawing`:`drawings`}`}}let o=e.board?.[0];if(o!==void 0){let e=o.split(`:`)[0]??o,t=(r??[]).filter(t=>t.split(`:`)[0]===e);return{parts:[],drawings:[],board:t,note:`Selected ${t.length} ${e===`copperpour`?`copper pour`:e}${t.length===1?``:`s`}`}}return{message:`Select a part, a drawing, a pour or a hole first; Find similar objects selects the ones like it.`}}var VS=/^([A-Za-z_]+)(\d+)$/;function HS(e,t){return!e.at||!t.at?e.at?-1:t.at?1:e.name.localeCompare(t.name):e.at.page-t.at.page||t.at.y-e.at.y||e.at.x-t.at.x||e.name.localeCompare(t.name)}function US(e,t){let n=new Set(t.filter(e=>!e.renamable).map(e=>Number(VS.exec(e.name)?.[2]))),r=1;return[...t].filter(e=>e.renamable).sort(HS).map(t=>{for(;n.has(r);)r++;return{from:t.name,to:`${e}${r++}`}})}function WS(e){let t=new Map;for(let n of e){let e=VS.exec(n.name)?.[1];e!==void 0&&t.set(e,[...t.get(e)??[],n])}let n=[...t].flatMap(([e,t])=>US(e,t)).filter(e=>e.from!==e.to);if(n.length===0)return{message:`Every designator is already numbered in order.`};let r=n.slice(0,4).map(e=>`${e.from} → ${e.to}`).join(`, `);return{edit:{kind:`renameParts`,mapping:n},summary:`annotate designators: ${r}${n.length>4?` and ${n.length-4} more`:``}`}}var GS={sch:.5,pcb:2.54},KS=new Set([`name`,`pinLabels`]),qS=new Set([`from`,`to`,`schematicRouteHints`]),JS=/(pin\d+)\s*:\s*["']([A-Za-z_][\w]*)["']/g;function YS(e){if(!e)return;let t=Object.fromEntries([...e.matchAll(JS)].map(e=>[e[1],e[2]]));return Object.keys(t).length>0?t:void 0}function XS(e){let t=e===void 0?void 0:Kt(e);return t?t.kind===`net`?void 0:t.part:null}var ZS=e=>e.slice(0,e.lastIndexOf(`/`)+1);function QS(e,t,n=``){let r=e.parts.filter(e=>t.includes(e.name)),i=r.filter(t=>e.imports.some(e=>e.local===t.tag&&/\.sheet(\.tsx)?$/.test(e.source))),a=r.filter(e=>!i.includes(e));if(a.length===0)return{message:i.length>0?`Sub-sheet instances are not copied; make another instance from the sheet instead.`:`Select the parts to copy first.`};let o=[],s=a.map(t=>{let n={};for(let[e,r]of Object.entries(t.props))KS.has(e)||(r.literal===void 0?o.push(`${t.name}.${e}`):n[e]=r.literal);let r=YS(t.props.pinLabels?.source);t.props.pinLabels&&!r&&o.push(`${t.name}.pinLabels`);let i=e.imports.find(e=>e.local===t.tag)?.source;return{tag:t.tag,name:t.name,props:n,...r?{pinLabels:r}:{},...i?{importFrom:i}:{}}});o.push(...i.map(e=>`${e.name} (a sub-sheet instance)`));let c=new Set(a.map(e=>e.name));return{parts:s,traces:e.traces.flatMap(e=>{let t=[XS(e.from),XS(e.to)];if(t.some(e=>e===null))return[];let n=t.filter(e=>typeof e==`string`);if(n.length===0||n.some(e=>!c.has(e)))return[];let r=Object.fromEntries(Object.entries(e.props).flatMap(([e,t])=>qS.has(e)||t.literal===void 0?[]:[[e,t.literal]]));return[{from:e.from,to:e.to,props:r,...e.schematicRouteHints?{hints:e.schematicRouteHints}:{}}]}),left:o,folder:ZS(n),anchor:eC(s)}}var $S=(e,t)=>t===void 0?void 0:e.startsWith(`pcb`)?ei(t):typeof t==`number`?t:void 0;function eC(e){let t=(t,n)=>{let r=e.flatMap(e=>{let[r,i]=[$S(t,e.props[t]),$S(n,e.props[n])];return r===void 0||i===void 0?[]:[{x:r,y:i}]});return r.length===0?void 0:{x:r.reduce((e,t)=>e+t.x,0)/r.length,y:r.reduce((e,t)=>e+t.y,0)/r.length}},n=t(`schX`,`schY`),r=t(`pcbX`,`pcbY`);return{...n?{sch:n}:{},...r?{pcb:r}:{}}}var tC=/^([A-Za-z_]+?)(\d+)$/;function nC(e,t){let n=new Set(t),r=new Map;for(let t of e){let e=tC.exec(t)?.[1]??`${t}_`,i=1;for(;n.has(`${e}${i}`);)i++;let a=`${e}${i}`;n.add(a),r.set(t,a)}return r}var rC=e=>Math.round(e*1e4)/1e4+0;function iC(e,t,n){let r=e=>({x:e*n,y:-e*n}),i={sch:r(GS.sch),pcb:r(GS.pcb)},a=t?e.anchor[t.view]:void 0;return!t||!a?i:{...i,[t.view]:{x:rC(t.at.x-a.x),y:rC(t.at.y-a.y)}}}function aC(e,t,n){let r=e===`schX`?n.sch.x:e===`schY`?n.sch.y:e===`pcbX`?n.pcb.x:e===`pcbY`?n.pcb.y:void 0;if(r===void 0)return t;let i=$S(e,t);return i===void 0?t:rC(i+r)}function oC(e,t){let n=Kt(e);return n?.kind===`pin`?`${t.get(n.part)??n.part}.${n.pin}`:e}function sC(e,t,n,r){if(!e.importFrom)return;let i=r.imports.find(t=>t.local===e.tag);return i?i.source===e.importFrom?void 0:{message:`${e.tag} is imported from "${i.source}" here, not "${e.importFrom}"; paste into a file that imports it the same way`}:ZS(n.file??``)===t.folder?e.importFrom:{message:`${e.name} needs "${e.importFrom}", which is relative to another folder; paste it into a circuit in that folder, or add the import first`}}function cC(e,t,n={}){let r=[...t.parts.map(e=>e.name),...t.drawings.flatMap(e=>[e.id,e.name??``]),...n.taken??[]],i=nC(e.parts.map(e=>e.name),r),a=n.page,o=a===void 0||a===`Main`?{}:{page:a},s=n.shift??iC(e,void 0,1),c=[];for(let r of e.parts){let a=sC(r,e,n,t);if(typeof a==`object`)return a;c.push({kind:`addPart`,tag:r.tag,name:i.get(r.name),props:Object.fromEntries(Object.entries(r.props).map(([e,t])=>[e,aC(e,t,s)])),...r.pinLabels?{pinLabels:r.pinLabels}:{},...a?{importFrom:a}:{},...o})}let l=e.traces.map(e=>({kind:`addTrace`,from:oC(e.from,i),to:oC(e.to,i),...Object.keys(e.props).length>0?{props:e.props}:{},...e.hints?{schematicRouteHints:e.hints.map(e=>({x:rC(e.x+s.sch.x),y:rC(e.y+s.sch.y)}))}:{},...o})),u=[...i.values()];return{edits:[...c,...l],summary:`paste ${u.length===1?u[0]:`${u.length} parts (${u.join(`, `)})`}`,names:u}}var lC={};function uC(e,t){t?lC[e]=t:delete lC[e]}function dC(e){return lC[e]}var fC=e=>new Set(e?.annotations.locks.filter(e=>!e.drawing).map(e=>e.part));function pC(e,t){if(`message`in t)return e.notify(t.message);e.edit(t.edits,t.summary)}function mC({design:e,circuit:t,selection:n,actions:r}){e&&t&&pC(r,FS(n.names,e.pcb.parts,t.model.parts,fC(t)))}function hC({design:e,circuit:t,selection:n,actions:r}){if(!e||!t)return;let i=n.names.length>0?n.names:e.pcb.parts.map(e=>e.component),a=e.schematic.pages??[],o=e=>Math.max(0,a.findIndex(t=>t.parts.includes(e)));pC(r,RS(i,e.schematic.symbols.map(e=>({component:e.component,x:e.x,y:e.y,page:o(e.component),rotation:e.rotation})),e.pcb.parts,t.model.parts,fC(t)))}function gC({design:e,circuit:t,actions:n}){if(!e||!t)return;let r=fC(t),i=e.schematic.pages??[],a=new Set(e.circuit.components.filter(e=>e.kind===`sheet`).map(e=>e.id)),o=t.model.parts.filter(e=>!a.has(e.name)).map(t=>{let n=e.schematic.symbols.find(e=>e.component===t.name),a=Math.max(0,i.findIndex(e=>e.parts.includes(t.name)));return{name:t.name,renamable:t.editable&&!r.has(t.name),...n?{at:{page:a,x:n.x,y:n.y}}:{}}}),s=new Set(t.model.parts.map(e=>e.name)),c=e.circuit.components.filter(e=>!s.has(e.id)&&e.kind!==`sheet`).map(e=>({name:e.id,renamable:!1})),l=WS([...o,...c]);if(`message`in l)return n.notify(l.message);n.renameParts(l.edit.mapping,l.summary).then(e=>e.ok&&n.notify(`Annotated ${l.edit.mapping.length} designators`))}var _C,vC=0;function yC({circuit:e,selection:t,actions:n}){if(!e)return;let r=QS(e.model,t.names,e.file);if(`message`in r)return n.notify(r.message);_C=r,vC=0;let i=r.parts.length===1?r.parts[0]?.name??``:`${r.parts.length} parts`,a=r.traces.length>0?` and ${r.traces.length} ${r.traces.length===1?`trace`:`traces`}`:``,o=r.left.length>0?`; left out ${r.left.join(`, `)}`:``;n.notify(`Copied ${i}${a}${o}`)}function bC({design:e,circuit:t,select:n,actions:r},i,a){if(!t)return;if(!_C)return r.notify(`Copy some parts first (Ctrl+C).`);let o=dC(a),s=iC(_C,o?{view:a,at:o}:void 0,vC+1),c=new Set(t.model.parts.map(e=>e.name)),l=(e?.circuit.components??[]).map(e=>e.id).filter(e=>!c.has(e)),u=cC(_C,t.model,{file:t.file,...i?{page:i}:{},taken:l,shift:s});if(`message`in u)return r.notify(u.message);vC+=1;let{edits:d,summary:f,names:p}=u;r.edit(d,f).then(e=>{e&&(n(()=>_o.none.all(p)),r.notify(`Pasted ${p.join(`, `)}`))})}function xC({design:e,circuit:t,selection:n,select:r,actions:i}){if(!e)return;let a=e.circuit.components.map(e=>({id:e.id,kind:e.kind,...e.footprint?{footprint:e.footprint}:{},...e.value?{value:e.value}:{}})),o=(t?.model.boardItems??[]).map(e=>e.id),s=BS({parts:n.names,drawings:n.drawings,board:n.board},a,e.schematic.drawings,o);if(`message`in s)return i.notify(s.message);r(()=>_o.none.all(s.parts).addDrawings(s.drawings).addBoard(s.board??[])),i.notify(s.note)}var SC=new Set([...Lx,...Rx]),CC=new Set([...zx,...Vx,...Bx]),wC=e=>SC.has(e)?`schematic`:CC.has(e)?`pcb`:void 0,TC=Ix;function EC(e,t){if(`message`in t)return e.actions.notify(t.message);e.actions.route(t)}function DC(e,t){if(`message`in t)return e.actions.notify(t.message);e.actions.autoplace(t)}function OC(e){let t=new Set(e.circuit?.annotations.locks.filter(e=>!e.drawing).map(e=>e.part)),n=pS(e.design,e.selection.copper,t);if(`message`in n)return e.actions.notify(n.message);e.actions.unroute(n.ids)}function kC(e,t){let{design:n,page:r,actions:i,openPage:a}=e;bS(t,{design:n,page:r,edit:i.edit,notify:i.notify,ask:(e,t)=>window.prompt(e,t),openPage:a})}function AC(e,t){e&&(t.notify(`Exporting the BOM and datasheets…`),B(`/api/package`,{file:e}).then(e=>t.notify(`Exported ${e.files.length} files to ${e.outDir}`)).catch(e=>t.notify(e.message)))}function jC(e,t){let{design:n,file:r,actions:i}=e;if(!n||!r)return i.notify(`Wait for the build to finish, then try again.`);let a=OS(n,r);if(a.length===0)return i.notify(`Nothing to print yet: the circuit has no parts.`);let o=r.replace(/\.circuit\.tsx$/,``);if(!kS(o,a))return i.notify(`The browser blocked the print window; allow pop-ups for Studio and try again.`);i.notify(t?`Choose "Save as PDF" in the print dialog to save ${o}.pdf (${a.length} sheets)`:`Printing ${a.length} sheets`)}function MC(e){if(e.file){if(Wy(e.checkCounts))return e.openDialog(`exportChecks`);NC(e.file,e.actions)}}function NC(e,t){e&&(t.notify(`Writing the fabrication files…`),B(`/api/export`,{file:e}).then(e=>t.notify(Uy(e))).catch(e=>t.notify(e.message)))}var PC=1e6;function FC(e,t){let n=Object.assign(document.createElement(`input`),{type:`file`,accept:`.dxf,.kicad_pcb`});n.addEventListener(`change`,()=>{let r=n.files?.[0];if(!r)return;let i=/\.kicad_pcb$/i.test(r.name);if(r.size>PC)return e.notify(`${r.name} is larger than 1 MB; import it with the agent's import_board or ${i?`copperflow import kicad`:`copperflow board --dxf`}`);r.text().then(async n=>{if(!i)return void await e.importBoard(r.name,n);let a=await e.importKicad(r.name,n);a!==void 0&&t(a)}).catch(t=>e.notify(t.message))}),n.click()}function IC(e,t){e&&B(`/api/bom?file=${encodeURIComponent(e)}`).then(({lines:n})=>{let r=URL.createObjectURL(new Blob([Fy(n)],{type:`text/csv`}));Object.assign(document.createElement(`a`),{href:r,download:Iy(e)}).click(),URL.revokeObjectURL(r),t.notify(`Saved ${Iy(e)}`)}).catch(e=>t.notify(e.message))}function LC(e,t){let{copper:n}=e.selection;if(n.length>0&&e.copperRecords){let r=Cb(e.copperRecords,n,t);if(`message`in r?e.actions.notify(r.message):e.actions.editLayout(r.edits,r.summary),e.selection.size+e.selection.boardCount===0)return}RC(e,t)}function RC(e,t){let n=new Set(e.circuit?.annotations.locks.map(e=>e.part)),r=new Set(e.circuit?.violations.map(e=>e.part)),i=hx(e.selection,n,t,r);if(`message`in i)return e.actions.notify(i.message);e.actions.lock(i.parts,t)}function zC(e){let t=xn(e.design,e.selection.names);if(!t)return e.actions.notify(`Select a part of a sub-sheet instance, or its symbol on the schematic, first.`);let n=e.view===`schematic`?e.selection.names.flatMap(t=>gn(e.design,t)?.path??_n(e.design,t)?.outer??[]):t;e.select(e=>e.all([...new Set(n)]))}async function BC(e){let t=t=>{let n=e.circuit?.model.parts.find(e=>e.name===t)?.props;return n?.pcbX!==void 0&&n.pcbY!==void 0},n=new Set(e.circuit?.annotations.locks.map(e=>e.part)),r=Fx(e.design,e.selection.names,t,n);if(`message`in r)return e.actions.notify(r.message);let{sheet:i,layout:a}=r;(a.edits.length===0?await e.actions.editFile(i.file,i.edits,i.summary):await e.actions.editLayout(a.edits,i.edits.length===0?a.summary:`${a.summary} and its placement`,i.edits.length===0?void 0:{file:i.file,edits:i.edits})).ok&&e.actions.notify(`Copied the layout of ${r.source} to ${r.targets.join(`, `)}`)}function VC(e){let t=zh(e.circuit?.model,e.selection.names);if(`message`in t)return e.actions.notify(t.message);e.openDialog(`makeSheet`)}function HC(e,t){let n=TC[t];return n?()=>e.workspace.run(n):{openFile:e.workspace.openPageTree,exportBom:()=>IC(e.file,e.actions),exportPackage:()=>AC(e.file,e.actions),exportFabrication:()=>MC(e),undo:()=>void e.actions.undo(),redo:()=>void e.actions.redo(),selectAll:()=>e.select(Ya(e.circuit?.model.parts.map(e=>e.name)??[],e.pickLayers,e.pickFilter,e.sheetWires,e.sheetLabels,e.sheetDrawings,e.pcbCopper)),selectInstance:()=>zC(e),replicateLayout:()=>void BC(e),makeSheet:()=>VC(e),find:e.openFind,checkDrc:e.openChecks,designRules:()=>e.openDialog(`rules`),autoplace:()=>DC(e,{kind:`all`}),autoplaceSelection:()=>DC(e,mS(e.design,e.selection.names)),autoplaceInstance:()=>DC(e,hS(e.design,e.selection.names)),fitBoard:()=>void e.actions.fitBoard(),importBoardDxf:()=>FC(e.actions,e.openImported),autoroute:()=>EC(e,{kind:`all`}),autorouteSelection:()=>EC(e,dS(e.design,e.selection.names)),autorouteNet:()=>EC(e,fS(e.highlight)),unroute:()=>OC(e),lock:()=>LC(e,!0),unlock:()=>LC(e,!1),history:()=>e.workspace.openBottom(`log`),keys:()=>e.openDialog(`keys`),about:()=>e.openDialog(`about`),addPage:()=>kC(e,`addPage`),renamePage:()=>kC(e,`renamePage`),deletePage:()=>kC(e,`deletePage`),themeLight:()=>e.workspace.setTheme(`light`),themeDark:()=>e.workspace.setTheme(`dark`),hoverLabels:e.workspace.toggleHoverLabels,pourSolid:()=>e.workspace.setPourFill(nd.pourSolid),pourHatched:()=>e.workspace.setPourFill(nd.pourHatched),pourOutline:()=>e.workspace.setPourFill(nd.pourOutline),findSimilar:()=>xC(e),placementTransfer:()=>hC(e),flip:()=>mC(e),annotate:()=>gC(e),systemSettings:()=>e.openDialog(`system`),newCircuit:()=>e.openDialog(`newCircuit`),footprintManager:()=>e.openDialog(`footprints`),print:()=>jC(e,!1),exportPdf:()=>jC(e,!0),copy:()=>yC(e),paste:()=>bC(e,e.view===`schematic`?e.page:void 0,e.view===`schematic`?`sch`:`pcb`)}[t]}var UC=[`undo`,`redo`,`openFile`,`selectAll`,`find`,`findSimilar`,`placementTransfer`,`flip`,`copy`,`paste`],WC=e=>UC.includes(e??``);function GC(e,t){(0,_.useEffect)(()=>{let n=n=>{let r=Yd(Pd(n),{view:t})?.action;WC(r)&&(r!==`copy`||(window.getSelection()?.toString()??``)===``)&&(n.preventDefault(),e(r))};return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[e,t])}function KC(e){let[t,n]=(0,_.useState)(null),{file:r,openImported:i,view:a,setView:o,selection:s,select:c,circuit:l,actions:u,pickLayers:d,pickFilter:f,sheetWires:p,sheetLabels:m,sheetDrawings:h,pcbCopper:g,copperRecords:v,openChecks:y,checkCounts:b,openFind:x,openDialog:S,design:C,page:w,openPage:T,highlight:E}=e,{run:D,openBottom:O,openPageTree:k,setTheme:A,toggleHoverLabels:j,setPourFill:M}=e.workspace;(0,_.useEffect)(()=>{if(!t||a!==t.view)return;let e=window.setTimeout(()=>{n(null),Wx(t.command)||u.notify(`The ${t.view===`pcb`?`PCB`:`schematic`} is still building; try again in a moment.`)},0);return()=>window.clearTimeout(e)},[t,a,u]);let ee=(0,_.useCallback)(e=>{let t=HC({file:r,openImported:i,view:a,setView:o,selection:s,select:c,circuit:l,actions:u,pickLayers:d,pickFilter:f,sheetWires:p,sheetLabels:m,sheetDrawings:h,pcbCopper:g,copperRecords:v,workspace:{run:D,openBottom:O,openPageTree:k,setTheme:A,toggleHoverLabels:j,setPourFill:M},openChecks:y,checkCounts:b,openFind:x,openDialog:S,design:C,page:w,openPage:T,highlight:E},e);if(t)return t();let _=wC(e);_&&a!==_?(o(_),n({command:e,view:_})):Wx(e)||u.notify(`Wait for the build to finish, then try again.`)},[r,i,a,o,s,c,l,u,d,f,p,m,h,g,v,D,O,k,A,j,M,y,b,x,S,C,w,T,E]);return GC(ee,a),ee}function qC({file:e,buildId:t,actions:n}){let[r,i]=(0,_.useState)([]),[a,o]=(0,_.useState)(``),[s,c]=(0,_.useState)(!1);(0,_.useEffect)(()=>{B(`/api/bom?file=${encodeURIComponent(e)}`).then(e=>{i(e.lines),o(e.report)}).catch(e=>n.notify(e.message))},[e,t,n]);let l=r.reduce((e,t)=>e+t.quantity,0);return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`h3`,{children:[`Bill of materials `,(0,X.jsxs)(`span`,{className:`count`,children:[l,` parts`]})]}),a&&(0,X.jsx)(`pre`,{className:`order-report`,children:a}),(0,X.jsxs)(`table`,{className:`bom`,children:[(0,X.jsx)(`thead`,{children:(0,X.jsxs)(`tr`,{children:[(0,X.jsx)(`th`,{scope:`col`,children:`Parts`}),(0,X.jsx)(`th`,{scope:`col`,children:`Value`}),(0,X.jsx)(`th`,{scope:`col`,children:`Supplier`})]})}),(0,X.jsx)(`tbody`,{children:r.map(e=>(0,X.jsxs)(`tr`,{children:[(0,X.jsxs)(`td`,{children:[e.designators.join(`, `),e.libraryPart&&!e.verified&&(0,X.jsx)(`span`,{className:`badge unverified`,children:`Unverified`})]}),(0,X.jsx)(`td`,{title:e.footprint,children:e.value||e.kind}),(0,X.jsx)(`td`,{children:(0,X.jsx)(`code`,{children:e.supplier.replace(/^\w+ /,``)})})]},e.designators.join(` `)))})]}),(0,X.jsx)(`button`,{disabled:s,onClick:()=>{c(!0),B(`/api/package`,{file:e}).then(e=>n.notify(`Exported ${e.files.length} files to ${e.outDir}`)).catch(e=>n.notify(e.message)).finally(()=>c(!1))},children:s?`Exporting`:`Export BOM and datasheets`})]})}var JC=`No problems found.`,YC=e=>e===`error`?0:1,XC=e=>e.startsWith(`net.`)||e.includes(`:`);function ZC(e){return e.items.find(e=>!XC(e))?.split(/[#.]/,1)[0]||void 0}function QC(e,t){let n=ZC(e);return n!==void 0&&t.has(n)?n:void 0}function $C(e,t,n,r){let i=e.items.filter(e=>n.has(e)),a=e.items.filter(e=>ew(r).has(e)),o=e.at??(e.view===`pcb`?a.map(e=>qu(r,e)).find(e=>e!==void 0):void 0);if(i.length>0||a.length>0)return{...e,...i.length>0?{copper:i}:{},...a.length>0?{board:a}:{},...o?{at:o}:{}};let s=QC(e,t);return s===void 0?e:{...e,part:s}}function ew(e){let t=e.pcb;return new Set([...t?.board?.pours??[],...t?.holes??[]].map(e=>e.id))}function tw(e){let t=e.pcb;return new Set([...t?.tracks??[],...t?.vias??[]].map(e=>e.id))}function nw(e){let t={id:e.id,severity:e.severity,code:e.code,message:e.message,items:e.items,view:e.view};return e.at?{...t,at:e.at}:t}var rw=(e,t)=>({id:`diagnostic:${t}`,severity:e.severity,code:e.code,message:e.message,items:e.items,view:`code`}),iw=(e,t)=>e<t?`${e} ${t}`:`${t} ${e}`;function aw(e,t){if(t?.state!==`done`)return[];let n=new Map(e.pcb.ratsnest.map(e=>[iw(e.from,e.to),e]));return t.unrouted.flatMap(e=>{let t=n.get(iw(e.from,e.to));if(t===void 0)return[];let r={x:(t.a.x+t.b.x)/2,y:(t.a.y+t.b.y)/2};return[{id:`route:${e.from}:${e.to}`,severity:`warning`,code:`unrouted`,message:e.reason,items:[e.from,e.to,...e.blockers],view:`pcb`,at:r}]})}function ow(e,t){let n=new Set(e.circuit.components.map(e=>e.id)),r=tw(e);return[...e.violations.map(nw),...aw(e,t),...e.diagnostics.map(rw)].map(t=>$C(t,n,r,e)).sort((e,t)=>YC(e.severity)-YC(t.severity))}function sw(e){return[...new Set(e.map(e=>e.code))].map(t=>{let n=e.filter(e=>e.code===t);return{code:t,severity:n.some(e=>e.severity===`error`)?`error`:`warning`,rows:n}})}function cw(e,t){return e.flatMap(e=>e.view===t&&e.at?[{id:e.id,at:e.at,severity:e.severity}]:[])}function lw(e){let t=e.filter(e=>e.severity===`error`).length;return{errors:t,warnings:e.length-t}}var uw=(e,t)=>`${e} ${t}${e===1?``:`s`}`;function dw({errors:e,warnings:t}){let n=[...e>0?[uw(e,`error`)]:[],...t>0?[uw(t,`warning`)]:[]];return n.length===0?JC:n.join(`, `)}var fw=`.insp-body:not([hidden]) .insp-value input:not([disabled]):not([type="checkbox"])`,pw={resistor:[[`resistance`,`10k`],[`footprint`,`0402`]],capacitor:[[`capacitance`,`100nF`],[`footprint`,`0402`]],inductor:[[`inductance`,`10uH`],[`footprint`,`0805`]],led:[[`color`,`green`],[`footprint`,`0603`]],diode:[[`footprint`,`sod123`]],fuse:[[`currentRating`,`500mA`],[`footprint`,`1206`]],crystal:[[`frequency`,`16MHz`],[`footprint`,`hc49`]],pinheader:[[`pinCount`,`4`],[`pitch`,`2.54mm`]],port:[[`side`,`left`],[`order`,`1`]]},mw=[`pcbX`,`pcbY`,`pcbRotation`,`schX`,`schY`,`schRotation`,`side`,`layer`],hw=[`schNameAt`,`schValueAt`,`pcbNameAt`],gw=`footprint`;function _w(e,t){return gw in e.props?[`prop:${gw}`]:t.includes(gw)?[`suggest:${gw}`]:[]}var vw={label:`Placement`,value:`Placed by Studio`};function yw(e,t){let n=Object.keys(e.props).filter(e=>!mw.includes(e)&&!hw.includes(e)&&e!==gw),r=(pw[e.tag]??[]).map(([e])=>e).filter(t=>!(t in e.props)),i=r.filter(e=>e!==gw),a=mw.filter(t=>t in e.props),o=hw.filter(t=>t in e.props),s=_w(e,r);return[{title:`Basic`,rows:[`name`,`kind`,...n.map(e=>`prop:${e}`),...i.map(e=>`suggest:${e}`)]},...s.length>0?[{title:`Footprint`,rows:s}]:[],{title:`Position`,rows:[...t.autoPlaced?[`placed`]:[],...a.map(e=>`prop:${e}`),...o.map(e=>`textAt:${e}`),`lock`]},{title:`Connections`,rows:[`connections`]},...t.library?[{title:`Library`,rows:[`library`]}]:[],{title:`Notes`,rows:[`notes`]}]}function bw(){return[{title:`Build`,rows:[`build`]},{title:`Notes for the agent`,rows:[`notes`]}]}function xw(e,t,n=0,r=0,i=0,a=0,o=0){let s=e+t+n+r+i+a+o;return s===0?`board`:s>1?`group`:e===1?`part`:t===1?`wire`:i===1?`copper`:a===1?`text`:o===1?`pour`:n===1?`label`:`drawing`}var Sw={parts:`Parts`,wires:`Wires`,labels:`Net labels and flags`,drawings:`Drawings`,copper:`Tracks and vias`,texts:`Names and values`,pours:`Copper pours and holes`},Cw=/^kind:(parts|wires|labels|drawings|copper|texts|pours):(\d+)$/;function ww(e){let t=Cw.exec(e);return t?{kind:t[1],count:Number(t[2])}:void 0}function Tw(e,t,n=0,r=0,i=0,a=0,o=0,s=0){let c=`Selected objects: ${e.length+n+r+i+a+o+s}`,[l]=e,u=e.map(e=>`part:${e.name}`),d=[[`parts`,e.length],[`wires`,n],[`labels`,r],[`drawings`,i],[`copper`,a],[`texts`,o],[`pours`,s]].flatMap(([e,t])=>t>0?[`kind:${e}:${t}`]:[]);return n+r+i+a+o+s>0?{header:c,sections:[{title:`Selection`,rows:[...d,...u]}]}:l?e.length===1?{header:c,sections:yw(l,t)}:{header:c,sections:[{title:`Selection`,rows:u}]}:{header:c,sections:bw()}}var Ew=[{label:`Rotate`,command:`rotate`},{label:`Lock`,command:`lock`},{label:`Unlock`,command:`unlock`},{label:`Delete`,command:`delete`}];function Dw(e,t,n,r=0){let i=t.map(e=>e.name);return e===`lock`||e===`unlock`?`parts`in Ct(i,n.locked,e===`lock`,n.violated):e===`delete`&&r>0||t.some(e=>e.editable&&!n.locked.has(e.name))}function Ow(e,t){return t.locked.has(e)?t.violated.has(e)?{command:`lock`,label:`Lock again`,pressed:!0,title:`Changed outside the editor: lock it again to accept the change`}:{command:`unlock`,label:`Locked`,pressed:!0,title:`Unlock this part`}:{command:`lock`,label:`Lock`,pressed:!1,title:`Lock this part, so the agent cannot move or change it`}}function kw({label:e,htmlFor:t,children:n}){return(0,X.jsxs)(`div`,{className:`insp-row`,children:[(0,X.jsx)(`label`,{className:`insp-label`,htmlFor:t,title:e,children:(0,X.jsx)(`span`,{children:e})}),(0,X.jsx)(`div`,{className:`insp-value`,children:n})]})}function Aw({title:e,open:t,onToggle:n,children:r}){return(0,X.jsxs)(`section`,{className:t?`insp-section`:`insp-section collapsed`,children:[(0,X.jsxs)(`button`,{type:`button`,className:`insp-head hairline-t`,"aria-expanded":t,onClick:n,children:[(0,X.jsx)(rh,{className:`insp-chevron`}),(0,X.jsx)(`span`,{className:`insp-title`,children:e})]}),(0,X.jsx)(`div`,{className:`insp-body`,hidden:!t,children:r})]})}function jw({name:e,prop:t,disabled:n,onCommit:r,notify:i}){let a=t.literal===void 0?t.source:String(t.literal),[o,s]=(0,_.useState)(a);return(0,_.useEffect)(()=>s(a),[a]),t.editable?(0,X.jsx)(kw,{label:e,htmlFor:`prop-${e}`,children:(0,X.jsx)(`input`,{id:`prop-${e}`,value:o,disabled:n,spellCheck:!1,onChange:e=>s(e.target.value),onBlur:()=>{if(o===a)return;let n=Pw(t.literal,o);n===void 0?(i(`${e} needs ${typeof t.literal==`number`?`a number`:`true or false`}`),s(a)):r(n).then(e=>e||s(a))},onKeyDown:e=>{e.key===`Enter`&&e.currentTarget.blur(),e.key===`Escape`&&s(a)}})}):(0,X.jsx)(kw,{label:e,children:(0,X.jsx)(`code`,{className:`expr`,title:`An expression; change it in the code`,children:t.source.replace(/\s+/g,` `)})})}var Mw=new Set([`pcbX`,`pcbY`,`pcbRotation`,`schX`,`schY`,`schRotation`,`pinCount`,`order`,`base`]);function Nw({name:e,example:t,disabled:n,onCommit:r}){let[i,a]=(0,_.useState)(``);return(0,X.jsx)(kw,{label:e,htmlFor:`new-prop-${e}`,children:(0,X.jsx)(`input`,{id:`new-prop-${e}`,className:`new-prop`,placeholder:t,value:i,disabled:n,spellCheck:!1,onChange:e=>a(e.target.value),onBlur:()=>{let t=i.trim();t&&r(Mw.has(e)&&Number.isFinite(Number(t))?Number(t):t).then(e=>e&&a(``))},onKeyDown:e=>{e.key===`Enter`&&e.currentTarget.blur()}})})}function Pw(e,t){if(typeof e==`number`){let e=Number(t);return t.trim()!==``&&Number.isFinite(e)?e:void 0}return typeof e==`boolean`?t===`true`||t!==`false`&&void 0:t}function Fw({label:e,onAdd:t}){let[n,r]=(0,_.useState)(``),i=(0,_.useId)();return(0,X.jsxs)(`form`,{className:`mark-form`,onSubmit:e=>{e.preventDefault(),n.trim()&&t(n.trim()).then(e=>e&&r(``))},children:[(0,X.jsx)(`label`,{htmlFor:i,children:e}),(0,X.jsxs)(`div`,{className:`inline`,children:[(0,X.jsx)(`input`,{id:i,value:n,onChange:e=>r(e.target.value),placeholder:`Route ground under this part`}),(0,X.jsx)(`button`,{type:`submit`,children:`Add`})]})]})}var Iw={rotate:$m,lock:Ym,unlock:Xm,delete:eh};function Lw({view:e,parts:t,others:n,locks:r,run:i,onClear:a,collapsed:o,toggle:s}){let{locked:c}=r,l=new Map(t.map(e=>[e.name,e])),u=e=>{let t=ww(e);if(t)return(0,X.jsx)(kw,{label:Sw[t.kind],children:(0,X.jsx)(`span`,{className:`static`,children:t.count})},e);let n=e.slice(5),r=l.get(n);return(0,X.jsx)(kw,{label:n,children:(0,X.jsxs)(`span`,{className:`static`,children:[r?.tag,c.has(n)?`, locked`:``]})},e)};return(0,X.jsxs)(`div`,{className:`inspector`,children:[(0,X.jsxs)(`header`,{className:`insp-header`,children:[(0,X.jsx)(`span`,{children:e.header}),(0,X.jsx)(`button`,{className:`icon`,"aria-label":`Clear the selection`,onClick:a,children:(0,X.jsx)(nh,{})})]}),(0,X.jsx)(`div`,{className:`inspector-actions`,children:Ew.map(({label:e,command:a})=>{let o=Iw[a];return(0,X.jsxs)(`button`,{className:a===`delete`?`danger`:void 0,disabled:!Dw(a,t,r,n),onClick:()=>i(a),children:[(0,X.jsx)(o,{}),` `,e]},a)})}),e.sections.map(e=>(0,X.jsx)(Aw,{title:e.title,open:!o.has(e.title),onToggle:()=>s(e.title),children:e.rows.map(u)},e.title))]})}function Rw(){let e=null;return{answer(t){return e=t,()=>{e===t&&(e=null)}},send(t){return e?(e(t),!0):!1}}}var zw=Rw();function Bw(e){let t=e;return{set(e){t=e},call:e=>t(e)}}var Vw=`Label`;function Hw({design:e,label:t,run:n,notify:r,onClear:i,collapsed:a,toggle:o}){let s=lm(e,t);return s?(0,X.jsxs)(`div`,{className:`inspector`,children:[(0,X.jsxs)(`header`,{className:`insp-header`,children:[(0,X.jsx)(`span`,{children:`Selected objects: 1`}),(0,X.jsx)(`button`,{className:`icon`,"aria-label":`Clear the selection`,onClick:i,children:(0,X.jsx)(nh,{})})]}),(0,X.jsxs)(`div`,{className:`inspector-actions`,children:[(0,X.jsx)(`button`,{title:`Rename this label's net`,onClick:()=>{zw.send({kind:`renameLabel`,labelId:t})||r(`Open the schematic to rename this label.`)},children:`Rename`}),(0,X.jsx)(`button`,{title:`Light this label's net in both views`,onClick:()=>n(`highlight`),children:`Highlight net`})]}),(0,X.jsx)(Aw,{title:Vw,open:!a.has(Vw),onToggle:()=>o(Vw),children:s.rows.map(e=>(0,X.jsx)(kw,{label:e.label,children:(0,X.jsx)(`span`,{className:`static`,title:e.value,children:e.value})},e.label))})]}):null}var Uw={path:`line`,rect:`rectangle`,circle:`circle`,arc:`arc`,text:`text`,bus:`bus`,junction:`junction`},Ww=(e,t)=>({x:H(e.x+t.x),y:H(e.y+t.y)}),Gw=e=>e.kind===`path`||e.kind===`bus`,Kw=e=>Gw(e)?[`points`]:[`x`,`y`],qw=(e,t)=>e.drawings.find(e=>e.id===t);function Jw(e,t,n,r=[]){let i=qw(e,n);if(!i)return`${n} has no editable source element`;if(t.has(n))return`${n} is locked`;if(!i.editable)return`${n} is read-only (${i.readonlyReason??`not a literal element`})`;let a=r.find(e=>i.props[e]&&!i.props[e]?.editable);return a?`${n}.${a} is an expression; change it in the code`:null}var Yw=(e,t,n)=>Jw(e,t,n.id,Kw(n));function Xw(e){return e.kind===`path`||e.kind===`bus`?e.points[0]??{x:0,y:0}:{x:e.x,y:e.y}}function Zw(e,t,n){let r=e.props[t]?.literal;return typeof r==`number`?r:H(n)}function Qw(e,t,n){if(Gw(t))return{points:(e.points??[]).map(e=>Ww(e,n))};let{groupOffset:r}=t,i=Xw(t);return{x:H(Zw(e,`x`,i.x-r.x)+n.x),y:H(Zw(e,`y`,i.y-r.y)+n.y)}}function $w(e,t){let{groupOffset:n}=e;return e.kind===`path`||e.kind===`bus`?`points`in t?{...e,points:t.points.map(e=>Ww(e,n))}:e:`x`in t?{...e,x:H(t.x+n.x),y:H(t.y+n.y)}:e}function eT(e){return e.length>1?[`${e.length} drawings`]:e.map(e=>e.name??`the ${Uw[e.kind]}`)}function tT(e,t,n,r,i){let a=t.find(e=>e.id===n),o=qw(e,n);if(!a)return{id:n,blocker:`${n} is not on the sheet`};let s=Yw(e,i,a);return s||!o?{id:n,blocker:s??`${n} has no editable source element`}:{id:n,drawing:a,placed:Qw(o,a,r)}}function nT(e,t,n,r,i){let a=n.map(n=>tT(e,t,n,r,i)),o=a.flatMap(e=>`placed`in e?[e]:[]);return{edits:o.map(({id:e,placed:t})=>({kind:`setDrawingProps`,id:e,props:{...t}})),names:eT(o.map(e=>e.drawing)),skipped:a.flatMap(e=>`blocker`in e?[e.blocker]:[]),shown:o.map(({drawing:e,placed:t})=>$w(e,t))}}function rT(e,t,n){return r=>{let i=r.map(t=>({id:t,blocker:Jw(e,n,t)})),a=i.flatMap(e=>e.blocker??[]),o=i.flatMap(e=>e.blocker===null?[e.id]:[]),s=t=>qw(e,t)?.start??0,c=[...o].sort((e,t)=>s(t)-s(e)),l=o.flatMap(e=>t.find(t=>t.id===e)??[]);return{edits:c.map(e=>({kind:`removeDrawing`,id:e})),names:eT(l),skipped:a,removed:o}}}var iT=/^[A-Za-z_][A-Za-z0-9_]*$/,aT=/^G(\d+)$/;function oT(e){let t=[...e.parts.map(e=>e.name),...e.drawings.flatMap(e=>[e.id,e.name??``])];return`G${Math.max(0,...t.map(e=>Number(aT.exec(e)?.[1]??0)))+1}`}function sT(e,t,n,r){if(t===`bus`?rn(n)===void 0:!iT.test(n))throw new Lh(`invalid`,`"${n}" is not a valid ${t===`bus`?`bus`:`drawing`} name; use ${t===`bus`?`a net name such as "CLK" or a range such as "D[0:7]"`:`letters, digits and _`}`);if(e.parts.some(e=>e.name===n))throw new Lh(`invalid`,`A part named ${n} already exists`);let i=(e,r)=>t===`bus`&&e===`bus`&&r===n;if(e.drawings.some(e=>e.id!==r&&(e.name===n||e.id===n)&&!i(e.tag,e.name)))throw new Lh(`invalid`,`A drawing named ${n} already exists`)}function cT(e,t){if(typeof t==`string`&&t!==``)return e!==`bus`||rn(t)!==void 0?t:void 0}function lT(e,t){return`drawing:${e}:${t}`}function uT(e,t){let n=2;for(;e.has(`${t}~${n}`);)n++;return`${t}~${n}`}function dT(e,t){let n=new Set(t),r=new Set,i=new Map;return e.map(({kind:e,name:t})=>{let a=(i.get(e)??0)+1;i.set(e,a);let o=t??lT(e,a);if(!n.has(o))return n.add(o),e===`bus`&&r.add(o),{id:o,base:o};let s=uT(n,o);return n.add(s),{id:s,base:o,repeat:e===`bus`&&r.has(o)?`piece`:`duplicate`}})}var fT=`Name the bus, such as D[0:7] or CLK`;function pT(e,t){return new Set([...e.parts.map(e=>e.name),...e.drawings.flatMap(e=>[e.id,e.name??``]),...t])}function mT(e,t=[]){let n=pT(e,t),r=1;for(;n.has(`BUS${r}`);)r++;return`BUS${r}`}function hT(e,t,n){let r=t.trim();if(r===``)return fT;try{sT(e,`bus`,r,n);return}catch(e){return e instanceof Error?e.message:String(e)}}function gT(e,t){return e.drawings.map(e=>{let n=en(e.tag)??`path`;return{kind:n,name:e.id===t?.id?t.name:cT(n,e.name)}})}var _T=(e,t,n)=>dT(t,e.parts.map(e=>e.name))[n]?.id??``;function vT(e,t,n=[]){let r=n.filter(e=>e===t).map(e=>({kind:`bus`,name:e})),i=[...gT(e),...r,{kind:`bus`,name:t}];return _T(e,i,i.length-1)}function yT(e,t,n){let r=e.drawings.findIndex(e=>e.id===t);return r<0?n:_T(e,gT(e,{id:t,name:n}),r)}function bT(e){let t=`${e.length} member${e.length===1?``:`s`}`;return`${e.length>2?`${e[0]} … ${e.at(-1)}`:e.join(`, `)}, ${t}`}var xT={x:{label:`X`,field:`number`},y:{label:`Y`,field:`number`},points:{label:`Points`,field:`points`},width:{label:`Width`,field:`number`,rule:`positive`},height:{label:`Height`,field:`number`,rule:`positive`},radius:{label:`Radius`,field:`number`,rule:`positive`},startAngle:{label:`Start angle`,field:`number`},endAngle:{label:`End angle`,field:`number`},text:{label:`Text`,field:`text`},fontSize:{label:`Font size`,field:`number`,rule:`positive`},anchor:{label:`Anchor`,field:`choice`,options:$t},strokeWidth:{label:`Stroke width`,field:`number`,rule:`nonNegative`},lineStyle:{label:`Line style`,field:`choice`,options:Qt},color:{label:`Colour`,field:`color`},filled:{label:`Filled`,field:`check`}},ST=[`strokeWidth`,`lineStyle`,`color`],CT={path:[`points`,...ST],rect:[`x`,`y`,`width`,`height`,...ST,`filled`],circle:[`x`,`y`,`radius`,...ST,`filled`],arc:[`x`,`y`,`radius`,`startAngle`,`endAngle`,...ST],text:[`x`,`y`,`text`,`fontSize`,`anchor`,`color`],bus:[`points`],junction:[`x`,`y`,`color`]},wT={path:`Line`,rect:`Rectangle`,circle:`Circle`,arc:`Arc`,text:`Text`,bus:`Bus`,junction:`Junction`},TT=e=>e.map(e=>`${e.x}, ${e.y}`).join(`; `);function ET(e,t){let{groupOffset:n}=e;if((e.kind===`path`||e.kind===`bus`)&&t===`points`)return TT(e.points.map(e=>({x:H(e.x-n.x),y:H(e.y-n.y)})));let r=e[t];return t===`x`||t===`y`?String(H(r-n[t])):r===void 0?``:String(r)}function DT(e,t,n,r){let i=xT[n],a=t?.props[n],o=a!==void 0&&!a.editable,s=n===`color`?{placeholder:Po().drawing}:{},c=i.options?{options:i.options}:{},l=o?a.source:ET(e,n);return{key:n,label:i.label,value:l,field:i.field,...c,...s,editable:r&&t!==void 0&&!o}}var OT=`Renames this piece of the bus only; its wires keep their nets`;function kT(e,t,n){return e.kind===`bus`?[{key:`name`,label:`Name`,value:e.name,field:`text`,editable:n&&t?.name!==void 0,hint:OT},{key:`members`,label:`Members`,value:bT(e.members),field:`static`,editable:!1}]:[{key:`name`,label:`Name`,value:e.name??`(none)`,field:`static`,editable:!1}]}function AT(e,t,n){let r=t?.line??e.source.line;return[{key:`kind`,label:`Kind`,value:`${wT[e.kind]}, line ${r}`,field:`static`,editable:!1},...kT(e,t,n),...CT[e.kind].map(r=>DT(e,t,r,n))]}var jT=/^#[0-9A-Fa-f]{6}$/,MT={any:{ok:()=>!0,says:`must be a number`},positive:{ok:e=>e>0,says:`must be a number greater than 0`},nonNegative:{ok:e=>e>=0,says:`must be a number of 0 or more`}};function NT(e){let t=e.split(`;`).map(e=>e.split(`,`).map(e=>e.trim())).map(e=>e.length===2&&e.every(e=>e!==``&&Number.isFinite(Number(e)))?{x:H(Number(e[0])),y:H(Number(e[1]))}:void 0);return t.length>=2&&t.every(e=>e!==void 0)?t:void 0}function PT(e,t){let n=t.trim();if(e.field===`number`){let t=MT[e.rule??`any`],r=Number(n);return n!==``&&Number.isFinite(r)&&t.ok(r)?r:{message:`${e.label} ${t.says}`}}return e.field===`points`?NT(n)??{message:`${e.label} needs two or more x, y pairs, such as 0, 0; 1, 0`}:e.field===`choice`?e.options?.includes(n)?n:{message:`${e.label} must be one of ${e.options?.join(`, `)}`}:e.field===`check`?n===`true`||n===`false`?n===`true`:{message:`${e.label} must be true or false`}:e.field===`color`?jT.test(n)?n:{message:`${e.label} must be a colour such as "#000080"`}:t===``?{message:`${e.label} cannot be empty`}:t}function FT(e,t,n){let r=t.trim(),i=hT(n,r,e.id);return i?{message:i}:{edit:{kind:`setDrawingProps`,id:e.id,props:{name:r}},summary:`rename the bus ${e.name} to ${r}`}}function IT(e,t,n,r){if(t===`name`&&e.kind===`bus`&&r)return FT(e,n,r);let i=xT[t];if(!i)return{message:`${t} cannot be set here`};let a=PT(i,n);if(typeof a==`object`&&!Array.isArray(a))return a;let o=e.name??`the ${Uw[e.kind]}`,s=Array.isArray(a)?`set ${o} ${t}`:`set ${o} ${t}=${JSON.stringify(a)}`;return{edit:{kind:`setDrawingProps`,id:e.id,props:{[t]:a}},summary:s}}var LT=`Drawing`;function RT({design:e,circuit:t,drawing:n,locked:r,actions:i,onRename:a,run:o,onClear:s,collapsed:c,toggle:l}){let u=e.schematic.drawings.find(e=>e.id===n);if(!u)return null;let d=Jw(t.model,r,n),f=AT(u,qw(t.model,n),d===null),p=(e,r)=>{let o=IT(u,e,r,t.model);if(`message`in o)return i.notify(o.message),Promise.resolve(!1);let{edit:s}=o,c=s.kind===`setDrawingProps`?s.props.name:void 0,l=typeof c==`string`?a({from:n,to:yT(t.model,n,c)}):void 0;return i.edit([s],o.summary).catch(()=>!1).then(e=>(e||l?.(),e))};return(0,X.jsxs)(`div`,{className:`inspector`,children:[(0,X.jsxs)(`header`,{className:`insp-header`,children:[(0,X.jsx)(`span`,{children:`Selected objects: 1`}),(0,X.jsx)(`button`,{className:`icon`,"aria-label":`Clear the selection`,onClick:s,children:(0,X.jsx)(nh,{})})]}),(0,X.jsx)(`div`,{className:`inspector-actions`,children:(0,X.jsxs)(`button`,{className:`danger`,disabled:d!==null,title:d??`Delete this drawing (Delete)`,onClick:()=>o(`delete`),children:[(0,X.jsx)(eh,{}),` Delete`]})}),d&&(0,X.jsxs)(`p`,{className:`note`,children:[d,`.`]}),(0,X.jsx)(Aw,{title:LT,open:!c.has(LT),onToggle:()=>l(LT),children:f.map(e=>(0,X.jsx)(zT,{row:e,onCommit:t=>p(e.key,t)},`${u.id}:${e.key}`))})]})}function zT({row:e,onCommit:t}){let n=(0,_.useId)();return e.field===`static`||!e.editable?(0,X.jsx)(kw,{label:e.label,children:(0,X.jsx)(`span`,{className:e.field===`static`?`static`:`expr`,title:e.value,children:e.value})}):e.field===`check`?(0,X.jsx)(kw,{label:e.label,htmlFor:n,children:(0,X.jsx)(`input`,{id:n,type:`checkbox`,checked:e.value===`true`,onChange:e=>void t(String(e.target.checked))})}):e.field===`choice`?(0,X.jsx)(kw,{label:e.label,htmlFor:n,children:(0,X.jsx)(`select`,{id:n,value:e.value,onChange:e=>void t(e.target.value),children:e.options?.map(e=>(0,X.jsx)(`option`,{value:e,children:e},e))})}):(0,X.jsx)(BT,{id:n,row:e,onCommit:t})}function BT({id:e,row:t,onCommit:n}){let[r,i]=(0,_.useState)(t.value);return(0,_.useEffect)(()=>i(t.value),[t.value]),(0,X.jsx)(kw,{label:t.label,htmlFor:e,children:(0,X.jsx)(`input`,{id:e,value:r,placeholder:t.placeholder,title:t.hint,spellCheck:!1,onChange:e=>i(e.target.value),onBlur:()=>{r!==t.value&&n(r).then(e=>e||i(t.value))},onKeyDown:e=>{e.key===`Enter`&&e.currentTarget.blur(),e.key===`Escape`&&i(t.value)}})})}var VT={top:`Top Layer`,bottom:`Bottom Layer`,inner1:`Inner Layer 1`,inner2:`Inner Layer 2`},HT={human:`You`,agent:`The agent`,router:`The router`},UT=e=>`${Math.round(e*1e3)/1e3} mm`;function WT(e,t){return t===void 0?`No net`:e.circuit.nets.find(e=>e.id===t)?.names[0]??t}function GT(e,t){return[{label:`Net`,value:WT(e,t.net)},{label:`Layer`,value:t.layer,field:`layer`},{label:`Width`,value:String(t.width),field:`width`},{label:`Length`,value:UT(oS(t.points))},{label:`Drawn by`,value:HT[t.by]},{label:`Locked`,value:String(t.locked),field:`lock`}]}function KT(e,t){let[n=`top`,r=`bottom`]=[t.layers[0],t.layers.at(-1)];return[{label:`Net`,value:WT(e,t.net)},{label:`Layers`,value:`${VT[n]} to ${VT[r]}`},{label:`Drill`,value:UT(t.drill)},{label:`Diameter`,value:UT(t.diameter)},{label:`Drawn by`,value:HT[t.by]},{label:`Locked`,value:String(t.locked),field:`lock`}]}function qT(e,t){let n=e.pcb.tracks.find(e=>e.id===t);if(n)return{kind:`track`,title:`Track`,locked:n.locked,rows:GT(e,n)};let r=e.pcb.vias.find(e=>e.id===t);return r&&{kind:`via`,title:`Via`,locked:r.locked,rows:KT(e,r)}}var JT=e=>`(${Math.round(e.x*1e3)/1e3}, ${Math.round(e.y*1e3)/1e3}) mm`;function YT(e,t){let n=e.pcb.tracks.find(e=>e.id===t.id);if(!n||!sb(n.points,t.index)||!mo(t,n.points))return;let[r,i]=[n.points[t.index],n.points[t.index+1]];return{kind:`segment`,title:`Segment`,locked:n.locked,rows:[{label:`Net`,value:WT(e,n.net)},{label:`Track`,value:n.id},{label:`Length`,value:UT(oS([r,i]))},{label:`Start`,value:JT(r)},{label:`End`,value:JT(i)}]}}function XT(e,t){let n=t===`true`;if(n!==e.locked)return{edit:{kind:e.points?`setTrack`:`setVia`,id:e.id,locked:n},summary:`${n?`Lock`:`Unlock`} ${e.id}`}}function ZT(e,t,n){if(t===`lock`)return XT(e,n);if(e.locked)return{message:`${e.id} is locked`};if(t===`width`){let t=Number(n.trim());return n.trim()===``||!Number.isFinite(t)||t<=0?{message:`The width must be a number of mm above 0`}:t===e.width?void 0:{edit:{kind:`setTrack`,id:e.id,width:t},summary:`Set the width of ${e.id} to ${t} mm`}}return n!==`top`&&n!==`bottom`?{message:`The layer must be top or bottom`}:n===e.layer?void 0:{edit:{kind:`setTrack`,id:e.id,layer:n},summary:`Move ${e.id} to the ${n} layer`}}var QT=[{value:`top`,label:`Top Layer`},{value:`bottom`,label:`Bottom Layer`}];function $T({design:e,id:t,segment:n,actions:r,run:i,onClear:a,collapsed:o,toggle:s}){let c=n?.id===t?YT(e,n):void 0;if(c)return(0,X.jsx)(eE,{shown:c,id:t,run:i,onClear:a,collapsed:o,toggle:s});let l=qT(e,t),u=e.pcb.tracks.find(e=>e.id===t)??e.pcb.vias.find(e=>e.id===t);if(!l||!u)return null;let d=async(e,t)=>{let n=ZT(u,e,t);return n?`message`in n?(r.notify(n.message),!1):(await r.editLayout([n.edit],n.summary)).ok:!0};return(0,X.jsxs)(`div`,{className:`inspector`,children:[(0,X.jsxs)(`header`,{className:`insp-header`,children:[(0,X.jsx)(`span`,{children:`Selected objects: 1`}),(0,X.jsx)(`button`,{className:`icon`,"aria-label":`Clear the selection`,onClick:a,children:(0,X.jsx)(nh,{})})]}),(0,X.jsx)(`div`,{className:`inspector-actions`,children:(0,X.jsxs)(`button`,{className:`danger`,disabled:l.locked,title:l.locked?`${t} is locked`:`Delete this ${l.kind} (Delete)`,onClick:()=>i(`delete`),children:[(0,X.jsx)(eh,{}),` Delete`]})}),(0,X.jsx)(Aw,{title:l.title,open:!o.has(l.title),onToggle:()=>s(l.title),children:l.rows.map(e=>(0,X.jsx)(tE,{row:e,locked:l.locked,onCommit:d},e.label))})]})}function eE({shown:e,id:t,run:n,onClear:r,collapsed:i,toggle:a}){return(0,X.jsxs)(`div`,{className:`inspector`,children:[(0,X.jsxs)(`header`,{className:`insp-header`,children:[(0,X.jsx)(`span`,{children:`Selected objects: 1`}),(0,X.jsx)(`button`,{className:`icon`,"aria-label":`Clear the selection`,onClick:r,children:(0,X.jsx)(nh,{})})]}),(0,X.jsx)(`div`,{className:`inspector-actions`,children:(0,X.jsxs)(`button`,{className:`danger`,disabled:e.locked,title:e.locked?`${t} is locked`:`Delete this segment of the track (Delete)`,onClick:()=>n(`delete`),children:[(0,X.jsx)(eh,{}),` Delete segment`]})}),(0,X.jsx)(Aw,{title:e.title,open:!i.has(e.title),onToggle:()=>a(e.title),children:e.rows.map(e=>(0,X.jsx)(kw,{label:e.label,children:(0,X.jsx)(`span`,{className:`static`,title:e.value,children:e.value})},e.label))})]})}function tE({row:e,locked:t,onCommit:n}){let r=(0,_.useId)();return e.field===`lock`?(0,X.jsx)(kw,{label:e.label,htmlFor:r,children:(0,X.jsx)(`input`,{id:r,type:`checkbox`,checked:e.value===`true`,onChange:e=>void n(`lock`,String(e.target.checked))})}):e.field===`layer`?(0,X.jsx)(kw,{label:e.label,htmlFor:r,children:(0,X.jsxs)(`select`,{id:r,value:e.value,disabled:t,onChange:e=>void n(`layer`,e.target.value),children:[QT.map(e=>(0,X.jsx)(`option`,{value:e.value,children:e.label},e.value)),!QT.some(t=>t.value===e.value)&&(0,X.jsx)(`option`,{value:e.value,disabled:!0,children:e.value===`inner1`?`Inner Layer 1`:`Inner Layer 2`})]})}):e.field===`width`?(0,X.jsx)(nE,{id:r,value:e.value,locked:t,onCommit:e=>n(`width`,e)}):(0,X.jsx)(kw,{label:e.label,children:(0,X.jsx)(`span`,{className:`static`,title:e.value,children:e.value})})}function nE({id:e,value:t,locked:n,onCommit:r}){let[i,a]=(0,_.useState)(t);return(0,_.useEffect)(()=>a(t),[t]),(0,X.jsx)(kw,{label:`Width (mm)`,htmlFor:e,children:(0,X.jsx)(`input`,{id:e,value:i,disabled:n,inputMode:`decimal`,spellCheck:!1,onChange:e=>a(e.target.value),onBlur:()=>{i!==t&&r(i).then(e=>e||a(t))},onKeyDown:e=>{e.key===`Enter`&&e.currentTarget.blur(),e.key===`Escape`&&a(t)}})})}function rE({design:e,circuit:t,id:n,locks:r,actions:i,run:a,onClear:o,collapsed:s,toggle:c}){let l=lx(e,n);if(!l)return null;let u=Xb(t.model,r.locked,n),d=mx(n,r),f=async(t,r)=>{let a=px(e,n,t,r);return a?`message`in a?(i.notify(a.message),!1):i.edit([a.edit],a.summary):!0};return(0,X.jsxs)(`div`,{className:`inspector`,children:[(0,X.jsxs)(`header`,{className:`insp-header`,children:[(0,X.jsx)(`span`,{children:`Selected objects: 1`}),(0,X.jsx)(`button`,{className:`icon`,"aria-label":`Clear the selection`,onClick:o,children:(0,X.jsx)(nh,{})})]}),(0,X.jsxs)(`div`,{className:`inspector-actions`,children:[(0,X.jsxs)(`button`,{className:d.pressed?`toggle on`:`toggle`,"aria-pressed":d.pressed,title:d.title,onClick:()=>a(d.command),children:[d.pressed?(0,X.jsx)(Ym,{}):(0,X.jsx)(Xm,{}),d.label]}),(0,X.jsxs)(`button`,{className:`danger`,disabled:u!==null,title:u??`Delete this ${l.kind===`hole`?`hole`:`copper pour`} (Delete)`,onClick:()=>a(`delete`),children:[(0,X.jsx)(eh,{}),` Delete`]})]}),(0,X.jsx)(Aw,{title:l.title,open:!s.has(l.title),onToggle:()=>c(l.title),children:l.rows.map(e=>(0,X.jsx)(iE,{row:e,disabled:u!==null,onCommit:f},e.label))})]})}function iE({row:e,disabled:t,onCommit:n}){let r=(0,_.useId)(),{field:i,choices:a}=e;return!i||t?(0,X.jsx)(kw,{label:e.label,children:(0,X.jsx)(`span`,{className:`static`,title:e.value,children:e.value===``?`Net class`:e.value})}):a?(0,X.jsx)(kw,{label:e.label,htmlFor:r,children:(0,X.jsxs)(`select`,{id:r,value:e.value,onChange:e=>void n(i,e.target.value),children:[a.map(e=>(0,X.jsx)(`option`,{value:e.value,children:e.label},e.value)),!a.some(t=>t.value===e.value)&&(0,X.jsx)(`option`,{value:e.value,disabled:!0,children:e.value})]})}):(0,X.jsx)(aE,{id:r,row:e,field:i,onCommit:n})}function aE({id:e,row:t,field:n,onCommit:r}){let[i,a]=(0,_.useState)(t.value);return(0,_.useEffect)(()=>a(t.value),[t.value]),(0,X.jsx)(kw,{label:t.label,htmlFor:e,children:(0,X.jsx)(`input`,{id:e,value:i,inputMode:`decimal`,spellCheck:!1,placeholder:n===`clearance`?`Net class`:void 0,onChange:e=>a(e.target.value),onBlur:()=>{i!==t.value&&r(n,i).then(e=>e||a(t.value))},onKeyDown:e=>{e.key===`Enter`&&e.currentTarget.blur(),e.key===`Escape`&&a(t.value)}})})}var oE=.001,sE=e=>e.flatMap(e=>e.kind===`junction`&&e.x!==void 0&&e.y!==void 0?[{id:e.id,x:e.x,y:e.y}]:[]);function cE(e,t){for(let n=1;n<t.length;n++){let[r,i]=[t[n-1],t[n]],[a,o]=[i.x-r.x,i.y-r.y],s=a*a+o*o,c=s===0?0:Math.max(0,Math.min(1,((e.x-r.x)*a+(e.y-r.y)*o)/s));if(Math.hypot(r.x+c*a-e.x,r.y+c*o-e.y)<=oE)return{segment:n-1,t:c}}}var lE=(e,t)=>t.some(t=>cE(e,t)!==void 0);function uE(e,t){let n=t[0];for(let r=1;r<t.length;r++){let[i,a]=[t[r-1],t[r]],[o,s]=[a.x-i.x,a.y-i.y],c=o*o+s*s,l=c===0?0:Math.max(0,Math.min(1,((e.x-i.x)*o+(e.y-i.y)*s)/c)),u={x:i.x+l*o,y:i.y+l*s};Math.hypot(u.x-e.x,u.y-e.y)<Math.hypot(n.x-e.x,n.y-e.y)&&(n=u)}return n}var dE=e=>Math.round(e*1e3)/1e3;function fE(e,t,n,r){return n.length<2?[]:e.flatMap(e=>{let i=cE(e,t);if(i===void 0||lE(e,r))return[];let a=n.length===t.length,[o,s]=[n[i.segment],n[i.segment+1]],c=a?{x:o.x+i.t*(s.x-o.x),y:o.y+i.t*(s.y-o.y)}:uE(e,n),l={x:dE(c.x),y:dE(c.y)};return Math.abs(l.x-e.x)<oE&&Math.abs(l.y-e.y)<oE?[]:[{kind:`setDrawingProps`,id:e.id,props:l}]})}function pE(e,t,n){return e.filter(e=>lE(e,t)&&!lE(e,n)).map(e=>e.id)}var mE=`This wire is no longer on the sheet`,hE=`This wire has no corners`,gE=`Studio draws this wire's corner; the code has none to remove`,_E=`This wire repeats another between the same ends; delete it in the code`;function vE(e,t){let n=e.schematic.wires.find(e=>e.id===t);return n&&Tp(e.circuit.nets,n.net)}function yE(e,t){let n=vE(e,t),r=e.circuit.nets.find(e=>e.id===n);return r?Jp(r):(n??``).replace(/^net\./,``)}var bE=(e,t)=>`This wire has no trace of its own: Studio draws it for net ${yE(e,t)}`,xE=e=>e.startsWith(`net.`)?`net ${e.slice(4)}`:e;function SE(e,t){let{writer:n}=t;if(n.kind===`engine`)return[Rn(e,n.from)?.id??xE(n.from),Rn(e,n.to)?.id??xE(n.to)];let r=e.schematic.wires.find(e=>e.id===t.id),i=e.circuit.connections.find(e=>e.id===r?.connection);return i?[xE(i.from),xE(i.to)]:void 0}function CE(e,t){let n=SE(e,t);return n?`the wire from ${n[0]} to ${n[1]}`:`the wire`}function wE(e,t,n){let{writer:r}=t;if(r.kind===`none`)return r.reason;if(r.kind===`engine`)return bE(e,t.id);let i=xr(e,r.components,r.trace,n);return i===void 0?r.repeat?_E:r.trace.editable?null:`This wire is read-only (${r.trace.readonlyReason}); delete it in the code`:`${i} is locked`}function TE(e,t,n){if(t.writer.kind!==`trace`)return wE(e,t,n);if(t.points.length<=2)return hE;let r=q(e,t,n);return r===null?(t.writer.trace.schematicRouteHints?.length??0)>0?null:gE:r}function EE(e){let t=e.writer.kind===`trace`?e.writer.trace:void 0;return{from:t?.from??``,to:t?.to??``}}function DE(e,t,n){let r=wE(e,t,n);return r===null?{edits:[{kind:`removeTrace`,...EE(t)}],summary:`remove ${CE(e,t)}`}:{blocked:r}}function OE(e,t,n){let r=TE(e,t,n);return r===null?{edits:[{kind:`setTraceHints`,...EE(t),schematicRouteHints:[]}],summary:`remove the corners of ${CE(e,t)}`}:{blocked:r}}var kE=e=>`blocked`in e?e.blocked:null;function AE(e,t,n){return{remove:kE(DE(e,t,n)),removeCorners:kE(OE(e,t,n))}}function jE(e,t,n){let r=t?CE(e,t):`the wire`,i=r.charAt(0).toUpperCase()+r.slice(1);return n.startsWith(`This wire`)?`${i}${n.slice(9)}`:`${i}: ${n}`}function ME(e,t){if(t.writer.kind!==`none`)return t.writer.components;let n=e.circuit.connections.find(n=>n.id===e.schematic.wires.find(e=>e.id===t.id)?.connection),r=n?[n.from,n.to]:[];return e.circuit.components.filter(e=>e.pins.some(e=>r.includes(e.id))).map(e=>e.id)}function NE(e,t,n,r,i){let a=K(e,t,n);if(a&&ME(e,a).some(e=>r.has(e)))return{id:n,kind:`withParts`};let o=a?DE(e,a,i):{blocked:mE};return`blocked`in o?{id:n,kind:`skipped`,reason:o.blocked,named:jE(e,a,o.blocked),studio:a?.writer.kind===`engine`}:{id:n,kind:`removed`,edits:o.edits,name:a?CE(e,a):`the wire`}}var PE=e=>`${e} wires have no trace of their own: Studio draws them for their nets`;function FE(e,t){let n=e.flatMap(e=>e.kind===`skipped`&&!t.has(e.reason)?[e]:[]),r=n.filter(e=>e.studio);return[...n.filter(e=>!e.studio).map(e=>e.named),...r.length>1?[PE(r.length)]:r.map(e=>e.named)]}function IE(e,t,n,r,i=gr,a=new Set){let o=n.map(n=>NE(e,t,n,r,i)),s=o.flatMap(e=>e.kind===`removed`?[e]:[]),c=o.flatMap(e=>e.kind===`withParts`?[e.id]:[]),l=new Set([...s.map(e=>e.id),...c]),u=t=>e.schematic.wires.filter(e=>l.has(e.id)!==t).map(e=>e.points);return{edits:s.flatMap(e=>e.edits),removed:s.map(e=>e.id),names:s.map(e=>e.name),withParts:c,skipped:FE(o,a),junctions:pE(sE(e.schematic.drawings),u(!1),u(!0))}}function LE(e,t,n,r=gr){let i=K(e,t,n);return i?OE(e,i,r):{blocked:mE}}function RE(e,t,n,r=gr){let i=K(e,t,n);return i?AE(e,i,r):{remove:mE,removeCorners:mE}}function zE(e){return e.writer.kind===`trace`?`Trace, line ${e.writer.trace.line}`:e.writer.kind===`engine`?`Routed by Studio`:`Not found in the code`}function BE(e,t,n,r=gr){let i=K(e,t,n);if(!i)return;let[a,o]=SE(e,i)??[`unknown`,`unknown`],s=[{label:`Net`,value:yE(e,n)},{label:`From`,value:a},{label:`To`,value:o},{label:`Corners`,value:String(Math.max(0,i.points.length-2))},{label:`Kind`,value:zE(i)}];return{net:vE(e,n),rows:s,...AE(e,i,r)}}var VE=`Wire`;function HE({design:e,circuit:t,wire:n,locked:r,run:i,onClear:a,collapsed:o,toggle:s}){let c=BE(e,t,n,r);return c?(0,X.jsxs)(`div`,{className:`inspector`,children:[(0,X.jsxs)(`header`,{className:`insp-header`,children:[(0,X.jsx)(`span`,{children:`Selected objects: 1`}),(0,X.jsx)(`button`,{className:`icon`,"aria-label":`Clear the selection`,onClick:a,children:(0,X.jsx)(nh,{})})]}),(0,X.jsxs)(`div`,{className:`inspector-actions`,children:[(0,X.jsx)(`button`,{disabled:c.net===void 0,title:`Light this wire's net in both views`,onClick:()=>i(`highlight`),children:`Highlight net`}),(0,X.jsx)(`button`,{disabled:c.removeCorners!==null,title:c.removeCorners??`Let Studio draw this wire on its own, with at most one elbow`,onClick:()=>i(`removeCorners`),children:`Remove corners`}),(0,X.jsxs)(`button`,{className:`danger`,disabled:c.remove!==null,title:c.remove??`Delete this wire's trace (Delete)`,onClick:()=>i(`delete`),children:[(0,X.jsx)(eh,{}),` Delete`]})]}),c.remove&&(0,X.jsxs)(`p`,{className:`note`,children:[c.remove,`.`]}),(0,X.jsx)(Aw,{title:VE,open:!o.has(VE),onToggle:()=>s(VE),children:c.rows.map(e=>(0,X.jsx)(kw,{label:e.label,children:(0,X.jsx)(`span`,{className:`static`,title:e.value,children:e.value})},e.label))})]}):null}function UE({design:e,circuit:t,text:n,locked:r,actions:i,onClear:a,collapsed:o,toggle:s}){let c=Af(e,t,n,r);if(!c)return null;let l=Tf(e,t,n,r);return(0,X.jsxs)(`div`,{className:`inspector`,children:[(0,X.jsxs)(`header`,{className:`insp-header`,children:[(0,X.jsx)(`span`,{children:`Selected objects: 1`}),(0,X.jsx)(`button`,{className:`icon`,"aria-label":`Clear the selection`,onClick:a,children:(0,X.jsx)(nh,{})})]}),(0,X.jsx)(`div`,{className:`inspector-actions`,children:(0,X.jsx)(`button`,{disabled:l!==null,title:l??`Put it back where the layout puts it`,onClick:()=>void i.edit(xf(n),`Reset ${c.rows[0]?.value??``} ${c.title.toLowerCase()} position`),children:`Reset position`})}),c.blocker&&(0,X.jsxs)(`p`,{className:`note`,children:[c.blocker,`.`]}),(0,X.jsx)(Aw,{title:c.title,open:!o.has(c.title),onToggle:()=>s(c.title),children:c.rows.map(e=>(0,X.jsx)(kw,{label:e.label,children:(0,X.jsx)(`span`,{className:`static`,title:e.value,children:e.value})},e.label))})]})}function WE({id:e,verified:t,actions:n}){let[r,i]=(0,_.useState)();if((0,_.useEffect)(()=>{B(`/api/part?id=${encodeURIComponent(e)}`).then(i).catch(e=>n.notify(e.message))},[e,t,n]),!r)return(0,X.jsx)(`p`,{className:`note`,children:`Loading…`});let{part:a}=r,o=r.checklist.split(`
|
|
17
|
-
`).filter(e=>e.startsWith(`- [`));return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`dl`,{className:`facts`,children:[(0,X.jsx)(`dt`,{children:`Part`}),(0,X.jsx)(`dd`,{children:a.title}),a.manufacturer&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`dt`,{children:`Maker`}),(0,X.jsx)(`dd`,{children:a.manufacturer})]}),a.mpn&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`dt`,{children:`MPN`}),(0,X.jsx)(`dd`,{children:(0,X.jsx)(`code`,{children:a.mpn})})]}),(0,X.jsx)(`dt`,{children:`Footprint`}),(0,X.jsx)(`dd`,{children:(0,X.jsx)(`code`,{children:a.footprint})}),Object.entries(a.suppliers??{}).map(([e,t])=>(0,X.jsxs)(`span`,{className:`contents`,children:[(0,X.jsx)(`dt`,{children:e}),(0,X.jsx)(`dd`,{children:(0,X.jsx)(`code`,{children:t})})]},e)),a.datasheet?.url&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`dt`,{children:`Datasheet`}),(0,X.jsx)(`dd`,{children:(0,X.jsx)(`a`,{href:a.datasheet.url,target:`_blank`,rel:`noreferrer noopener`,children:`Open`})})]})]}),(0,X.jsxs)(`p`,{className:`hint`,children:[`These come from parts/`,e,`/part.yaml and are the same for every copy of the part.`]}),t?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`p`,{className:`note ok`,children:[`Verified by `,a.verified?.by,` against `,a.verified?.against,`.`]}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>n.openVerify(e,a.title),"aria-label":`Look again at ${a.title}`,children:`Look again`})]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`p`,{className:`note warn`,children:[`Not verified: `,o.length,` item`,o.length===1?``:`s`,` in parts/`,e,`/verification.md to check against the datasheet.`]}),(0,X.jsx)(`button`,{type:`button`,className:`primary`,onClick:()=>n.openVerify(e,a.title),"aria-label":`Verify ${a.title}`,children:`Verify…`})]})]})}var GE=/^https?:\/\//,KE=e=>[e.type,e.carries].filter(Boolean).join(`, `);function qE({instance:e}){let t=e.sources??[];return!e.does&&t.length===0?null:(0,_.createElement)(`div`,{className:`instance-card`},e.does?(0,_.createElement)(`p`,{className:`note`},e.does):null,t.length>0?(0,_.createElement)(`ul`,{className:`instance-sources`},t.map(e=>(0,_.createElement)(`li`,{key:e},GE.test(e)?(0,_.createElement)(`a`,{href:e,target:`_blank`,rel:`noreferrer`},e):e))):null)}function JE({id:e,value:t,disabled:n,placeholder:r,onCommit:i}){let[a,o]=(0,_.useState)(t);return(0,_.useEffect)(()=>o(t),[t]),(0,X.jsx)(`input`,{id:e,value:a,disabled:n,placeholder:r,spellCheck:!1,onChange:e=>o(e.target.value),onBlur:()=>{a.trim()!==t&&i(a.trim()).then(e=>e||o(t))},onKeyDown:e=>{e.key===`Enter`&&e.currentTarget.blur(),e.key===`Escape`&&o(t)}})}function YE({design:e,name:t,editable:n,actions:r,onOpenSheet:i,collapsed:a,toggle:o}){let s=gn(e,t),c=(0,_.useId)();if(!s)return null;let l=(e,n)=>{let i=n===``?void 0:pn(s.sheet,e,n,s.ports.find(t=>t.name===e)?.bus===!0);return i===void 0?r.edit([{kind:`setConnections`,part:t,connections:Sn(s,e,n)}],`Connect ${t}.${e} to ${n===``?`nothing`:n}`):(r.notify(i),Promise.resolve(!1))};return(0,X.jsxs)(Aw,{title:`Sub-sheet`,open:!a.has(`Sub-sheet`),onToggle:()=>o(`Sub-sheet`),children:[(0,X.jsx)(kw,{label:`Sheet`,children:(0,X.jsx)(`span`,{className:`static`,children:bn(s.sheet,yn(e,s.file))})}),(0,X.jsx)(`div`,{className:`inspector-actions`,children:(0,X.jsxs)(`button`,{onClick:()=>i(s.file),title:`Open ${s.file}`,children:[`Open `,s.sheet]})}),(0,X.jsx)(qE,{instance:s}),s.ports.map(e=>(0,X.jsxs)(kw,{label:`${e.name}${e.bus?` (bus)`:``}`,htmlFor:`${c}-${e.name}`,children:[(0,X.jsx)(JE,{id:`${c}-${e.name}`,value:s.connections[e.name]??``,placeholder:`not connected`,disabled:!n,onCommit:t=>l(e.name,t)}),KE(e)?(0,X.jsx)(`span`,{className:`port-about`,children:KE(e)}):null]},e.name)),(0,X.jsx)(kw,{label:`base`,htmlFor:`${c}-base`,children:(0,X.jsx)(JE,{id:`${c}-base`,value:String(s.base),disabled:!n,onCommit:e=>{let n=Number(e);return!Number.isInteger(n)||n<=0?(r.notify(`The base is a whole number above 0, such as 300`),Promise.resolve(!1)):r.edit([{kind:`setProps`,part:t,props:{base:n}}],`Set ${t} base=${n}`)}})})]})}function XE({design:e,part:t,onSelect:n,onOpenSheet:r}){let i=_n(e,t);return i?(0,X.jsxs)(`div`,{className:`inspector`,children:[(0,X.jsx)(`header`,{className:`insp-header`,children:(0,X.jsx)(`span`,{children:t})}),(0,X.jsxs)(`p`,{className:`note`,children:[i.localId,` of instance `,i.instance,` (`,i.sheet,`). `,bn(i.sheet,yn(e,i.file)),`: change it in its sheet, and every instance changes with it.`]}),(0,X.jsxs)(`div`,{className:`inspector-actions`,children:[(0,X.jsx)(`button`,{onClick:()=>n(t=>t.all(vn(e,i.outer))),children:`Select the instance`}),(0,X.jsxs)(`button`,{onClick:()=>r(i.file),title:`Open ${i.file}`,children:[`Open `,i.sheet]})]})]}):null}function ZE({file:e,parentDesign:t}){let n=t?yn(t,e):void 0;return(0,X.jsxs)(`p`,{className:`note`,children:[bn(at(e),n),`.`]})}function QE({part:e,editable:t,actions:n,collapsed:r,toggle:i}){let a=(0,_.useId)(),o=e.props.bus?.literal===!0,s=t=>n.edit([{kind:`renamePort`,from:e.name,to:t}],`Rename port ${e.name} to ${t}`),c=t=>n.edit([{kind:`setProps`,part:e.name,props:{bus:t}}],`${t?`Make`:`Unmake`} ${e.name} a bus port`);return(0,X.jsxs)(Aw,{title:`Port`,open:!r.has(`Port`),onToggle:()=>i(`Port`),children:[(0,X.jsx)(kw,{label:`Name`,htmlFor:`${a}-name`,children:(0,X.jsx)(JE,{id:`${a}-name`,value:e.name,disabled:!t,onCommit:s})}),(0,X.jsx)(kw,{label:`Bus`,htmlFor:`${a}-bus`,children:(0,X.jsx)(`input`,{id:`${a}-bus`,type:`checkbox`,checked:o,disabled:!t,onChange:e=>void c(e.target.checked)})}),(0,X.jsx)(`p`,{className:`hint`,children:`Drag its pin on a symbol of this sheet to move it along the box or to another side.`})]})}function $E({parts:e,onPlace:t,onImport:n,onNewPart:r,focus:i,onFocused:a}){let[o,s]=(0,_.useState)(``),c=(0,_.useRef)(null);(0,_.useEffect)(()=>{i&&(c.current?.focus(),a())},[i,a]);let l=o.trim().toLowerCase(),u=(...e)=>l===``||e.some(e=>e?.toLowerCase().includes(l)),d=e.library.filter(e=>u(e.id,e.title,e.mpn,e.footprint)),f=e.builtin.filter(e=>u(e));return(0,X.jsxs)(`div`,{className:`library`,children:[(0,X.jsx)(`input`,{ref:c,className:`search`,type:`search`,placeholder:`Search parts`,"aria-label":`Search parts`,value:o,onChange:e=>s(e.target.value)}),(0,X.jsxs)(`h3`,{children:[`Project library `,(0,X.jsx)(`span`,{className:`count`,children:e.library.length})]}),(0,X.jsx)(`button`,{className:`library-import`,onClick:r,children:`New part…`}),(0,X.jsx)(`button`,{className:`library-import`,onClick:n,children:`Import by LCSC number…`}),e.library.length===0&&(0,X.jsx)(`p`,{className:`note`,children:`No parts yet. Write one from its datasheet with New part…, import one by its LCSC number, or ask the agent to create one.`}),(0,X.jsx)(`ul`,{children:d.map(e=>(0,X.jsxs)(`li`,{className:`library-item`,children:[(0,X.jsxs)(`div`,{className:`text`,children:[(0,X.jsx)(`span`,{className:`title`,children:e.title}),(0,X.jsxs)(`span`,{className:`meta`,children:[e.mpn??e.id,`, `,e.footprint]}),e.origin&&(0,X.jsx)(`span`,{className:`meta`,children:Ah(e.origin)})]}),(0,X.jsx)(`span`,{className:`badge ${e.verified?`verified`:`unverified`}`,title:e.verified?`Checked by ${e.verifiedBy}`:`Not checked against the datasheet yet`,children:e.verified?`Verified`:`Unverified`}),(0,X.jsx)(`button`,{onClick:()=>t(e.id),"aria-label":`Place ${e.title}`,children:`Place`})]},e.id))}),(0,X.jsx)(`h3`,{children:`Built-in parts`}),(0,X.jsx)(`ul`,{className:`builtin`,children:f.map(e=>(0,X.jsx)(`li`,{children:(0,X.jsx)(`button`,{className:`chip-button`,onClick:()=>t(e),"aria-label":`Place a ${e}`,children:e})},e))}),(0,X.jsx)(`p`,{className:`hint`,children:`Placed parts start at the board centre; drag them into position on the PCB.`})]})}function eD({design:e,highlight:t,onHighlight:n}){let r=(0,_.useMemo)(()=>e?Xp(e):[],[e]);if(r.length===0)return(0,X.jsx)(`p`,{className:`note`,children:`No nets yet.`});let i=e=>t.length===1&&t[0]===e;return(0,X.jsx)(`ul`,{className:`nets`,children:r.map(e=>(0,X.jsx)(`li`,{children:(0,X.jsxs)(`button`,{className:`row${t.includes(e.id)?` selected`:``}`,"aria-pressed":t.includes(e.id),onClick:()=>n(i(e.id)?Ep:[e.id]),title:i(e.id)?`Click to clear the highlight`:`Click to highlight this net`,children:[(0,X.jsx)(`span`,{className:`name`,children:e.label}),e.badge&&(0,X.jsx)(`span`,{className:`badge ${e.badge}`,children:e.badge}),e.length!==void 0&&(0,X.jsx)(`span`,{className:`value`,children:Yp(e)}),(0,X.jsx)(`span`,{className:`value`,children:e.pins===1?`1 pin`:`${e.pins} pins`})]})},e.id))})}var tD=`No PROJECT.md yet. The agent writes it with set_project and note_decision; you can also write it by hand at the project root.`,nD=e=>e.map(e=>e.trim()).filter(e=>e!==``).map(e=>e.replace(/^[-*]\s+/,``));function rD(e){if(e==null)return{kind:`missing`,note:tD};let t=e.replace(/\r\n/g,`
|
|
18
|
-
`).split(`
|
|
19
|
-
`),n=t.find(e=>/^# /.test(e))?.slice(2).trim()||`Project`,r=[],i;for(let e of t){let t=/^## (.*)$/.exec(e);t?(i&&r.push({title:i.title,lines:nD(i.body)}),i={title:(t[1]??``).trim(),body:[]}):i&&i.body.push(e)}return i&&r.push({title:i.title,lines:nD(i.body)}),{kind:`file`,title:n,sections:r}}function iD(){let[e,t]=(0,_.useState)(void 0),[n,r]=(0,_.useState)(),i=(0,_.useCallback)(()=>{B(`/api/project-memory`).then(e=>{t(e.text),r(void 0)}).catch(e=>r(e.message))},[]);if((0,_.useEffect)(i,[i]),n)return(0,X.jsxs)(`p`,{className:`note project-memory`,children:[`PROJECT.md could not be read: `,n]});if(e===void 0)return(0,X.jsx)(`p`,{className:`note project-memory`,children:`Reading PROJECT.md…`});let a=rD(e);return(0,X.jsxs)(`div`,{className:`project-memory`,children:[(0,X.jsxs)(`div`,{className:`project-memory-head`,children:[(0,X.jsx)(`h3`,{children:a.kind===`file`?a.title:`PROJECT.md`}),(0,X.jsx)(`button`,{type:`button`,onClick:i,children:`Reload`})]}),a.kind===`missing`&&(0,X.jsx)(`p`,{className:`note`,children:a.note}),a.kind===`file`&&a.sections.map((e,t)=>(0,X.jsxs)(`section`,{children:[(0,X.jsx)(`h4`,{children:e.title}),e.lines.length===0?(0,X.jsx)(`p`,{className:`empty`,children:`(empty)`}):(0,X.jsx)(`ul`,{children:e.lines.map((e,t)=>(0,X.jsx)(`li`,{children:e},t))})]},`${e.title}-${t}`))]})}function aD({tree:e,onOpen:t,focus:n,onFocused:r}){let i=(0,_.useRef)(null);return(0,_.useEffect)(()=>{n&&(i.current?.querySelector(`.tree-row.file`)?.focus(),r())},[n,r]),(0,X.jsxs)(`nav`,{className:`page-tree`,"aria-label":`Pages`,children:[(0,X.jsx)(`div`,{className:`tree-row project`,children:e.project}),(0,X.jsx)(`ul`,{ref:i,children:e.files.map(n=>(0,X.jsxs)(`li`,{children:[(0,X.jsx)(`button`,{className:`tree-row file`,title:`Open ${n.file}`,onClick:()=>t(n.file,e.view),children:n.file}),(0,X.jsx)(`ul`,{children:n.documents.map(e=>(0,X.jsx)(`li`,{children:(0,X.jsx)(`button`,{className:`tree-row doc${e.active?` active`:``}`,"aria-current":e.active?`page`:void 0,onClick:()=>t(n.file,e.view,e.page),children:e.label})},e.page??e.view))})]},n.file))})]})}var oD=e=>`${e}-panel`,sD=e=>`side-tab-${e}`;function cD({side:e,tabs:t,active:n,open:r,onClick:i,onSelect:a}){let o=Nm({ids:t.map(e=>e.id),current:n,onSelect:a,onPointerClick:i});return(0,X.jsx)(`div`,{className:`side-strip ${e} hairline-${e===`left`?`r`:`l`}`,role:`tablist`,"aria-orientation":`vertical`,"aria-label":e===`left`?`Left panel`:`Right panel`,onKeyDown:o.onKeyDown,children:t.map(t=>{let i=r&&t.id===n;return(0,X.jsx)(`button`,{role:`tab`,id:sD(t.id),"aria-controls":oD(e),"aria-selected":i,className:`side-tab${i?` on`:``}`,...o.tab(t.id),children:t.label},t.id)})})}var lD={page:`Page`,net:`Net`,component:`Component`,object:`Object`,project:`Project`},uD=Object.keys(lD),dD=`design-panel`;function fD({sub:e,onSub:t}){let n=Nm({ids:uD,current:e,onSelect:t});return(0,X.jsx)(`div`,{className:`sub-tabs hairline-b`,role:`tablist`,"aria-label":`Project Design`,onKeyDown:n.onKeyDown,children:uD.map(t=>(0,X.jsx)(`button`,{role:`tab`,id:`sub-tab-${t}`,"aria-controls":dD,"aria-selected":e===t,className:`sub-tab${e===t?` on`:``}`,...n.tab(t),children:lD[t]},t))})}function pD(e){let{left:t,onSub:n}=e,r=t.strip===`design`;return(0,X.jsxs)(`aside`,{className:`panel left hairline-r`,id:oD(`left`),role:`tabpanel`,"aria-labelledby":sD(t.strip),hidden:e.hidden,onClick:km,children:[r&&(0,X.jsx)(fD,{sub:t.sub,onSub:n}),(0,X.jsxs)(`div`,{className:`panel-body`,...r?{id:dD,role:`tabpanel`,"aria-labelledby":`sub-tab-${t.sub}`}:{},children:[!r&&(0,X.jsx)($E,{parts:e.parts,onPlace:e.onPlace,onImport:e.onImport,onNewPart:e.onNewPart,focus:e.focusSearch,onFocused:e.onSearchFocused}),r&&(0,X.jsx)(mD,{...e})]})]})}function mD(e){switch(e.left.sub){case`page`:return(0,X.jsx)(aD,{tree:e.pageTree,onOpen:e.onOpenDocument,focus:e.focusPage,onFocused:e.onPageFocused});case`net`:return(0,X.jsx)(eD,{design:e.design,highlight:e.highlight,onHighlight:e.onHighlight});case`component`:return(0,X.jsx)(hD,{...e});case`object`:return(0,X.jsx)(_D,{...e});case`project`:return(0,X.jsx)(iD,{})}}function hD({circuit:e,parts:t,selection:n,onSelect:r,autoPlaced:i}){let a=new Set(e.annotations.locks.map(e=>e.part)),o=e=>t.library.find(t=>t.component===e)?.title??e,s=new Map;for(let t of e.model.parts)s.set(t.tag,[...s.get(t.tag)??[],t]);return(0,X.jsxs)(`div`,{className:`tree`,children:[[...s].map(([e,t])=>(0,X.jsxs)(`section`,{children:[(0,X.jsxs)(`h3`,{title:e,children:[o(e),` `,(0,X.jsx)(`span`,{className:`count`,children:t.length})]}),(0,X.jsx)(`ul`,{role:`listbox`,"aria-multiselectable":`true`,"aria-label":o(e),"data-keys":`parts`,children:t.map(e=>(0,X.jsx)(`li`,{role:`none`,children:(0,X.jsxs)(`button`,{role:`option`,"aria-selected":n.has(e.name),className:`row${n.has(e.name)?` selected`:``}${e.editable?``:` readonly`}`,onClick:t=>r(bo(e.name,t)),title:e.readonlyReason?`Read-only: ${e.readonlyReason}`:void 0,children:[(0,X.jsx)(`span`,{className:`name`,children:e.name}),(0,X.jsx)(`span`,{className:`value`,children:gD(e.props)}),i.has(e.name)&&(0,X.jsx)(`span`,{className:`placed-dot`,role:`img`,"aria-label":vw.value,title:vw.value}),a.has(e.name)&&(0,X.jsx)(Ym,{className:`locked-icon`,"aria-label":`Locked`})]})},e.name))})]},e)),e.model.skipped.length>0&&(0,X.jsxs)(`p`,{className:`note`,children:[e.model.skipped.length,` element(s) cannot be edited here; see the code.`]})]})}function gD(e){for(let t of[`resistance`,`capacitance`,`inductance`,`color`,`footprint`,`standard`]){let n=e[t]?.literal;if(n!==void 0)return String(n)}return``}function _D({circuit:e,selection:t,actions:n}){return(0,X.jsxs)(`div`,{className:`connections`,children:[(0,X.jsx)(`ul`,{children:e.model.traces.map((e,r)=>(0,X.jsxs)(`li`,{className:t.names.some(t=>yD(e,t))?`selected`:``,children:[(0,X.jsx)(`code`,{children:e.editable?e.from:`line ${e.line}`}),(0,X.jsx)(`span`,{className:`arrow`,"aria-hidden":`true`,children:`—`}),(0,X.jsx)(`code`,{children:e.editable?e.to:`read-only`}),(0,X.jsx)(`button`,{className:`icon`,disabled:!e.editable,"aria-label":`Remove connection ${e.from} to ${e.to}`,onClick:()=>{e.from&&e.to&&n.edit([{kind:`removeTrace`,from:e.from,to:e.to}],`remove trace ${e.from} -> ${e.to}`)},children:(0,X.jsx)(nh,{})})]},`${e.from}-${e.to}-${r}`))}),(0,X.jsx)(vD,{actions:n})]})}function vD({actions:e}){let[t,n]=(0,_.useState)(``),[r,i]=(0,_.useState)(``);return(0,X.jsxs)(`form`,{className:`add-connection hairline-t`,onSubmit:a=>{a.preventDefault(),t&&r&&e.edit([{kind:`addTrace`,from:t,to:r}],`add trace ${t} -> ${r}`).then(e=>{e&&(n(``),i(``))})},children:[(0,X.jsxs)(`label`,{children:[`From`,(0,X.jsx)(`input`,{placeholder:`.R1 > .pin1`,value:t,onChange:e=>n(e.target.value)})]}),(0,X.jsxs)(`label`,{children:[`To`,(0,X.jsx)(`input`,{placeholder:`net.GND`,value:r,onChange:e=>i(e.target.value)})]}),(0,X.jsx)(`button`,{type:`submit`,className:`primary`,children:`Connect`})]})}function yD(e,t){return t?[e.from,e.to].some(e=>e!==void 0&&Fh(e).includes(t)):!1}function bD(e,t){let n=t.size===0&&t.soleLabel?.startsWith(`port:`)?t.soleLabel.slice(5):void 0;return(n===void 0?t.names:[n]).flatMap(t=>e.model.parts.find(e=>e.name===t)??[])}function xD(e,t,n){(0,_.useEffect)(()=>{t&&(e.current?.querySelector(fw)?.focus(),n())},[e,t,n])}function SD(e){let t=(0,_.useRef)(null);xD(t,e.focusField,e.onFieldFocused);let n=bD(e.circuit,e.selection),[r]=n,i=n.length===1&&e.selection.size===0,{wireCount:a,labelCount:o,drawingCount:s,copperCount:c,soleWire:l,soleLabel:u,soleDrawing:d,soleCopper:f,soleText:p,textCount:m,boardCount:h,soleBoard:g}=e.selection,[v,y]=i?[0,0]:[a,o],b=xw(n.length,v,y,s,c,m,h),x=n.length===0&&e.selection.size===1&&e.selection.primary!==void 0?_n(e.build.design,e.selection.primary):void 0,S=b===`part`&&r?e.parts.library.find(e=>e.component===r.tag):void 0,C=b===`part`&&r!==void 0&&Qe(e.build.design,e.openView).has(r.name),w=Tw(n,{library:S!==void 0,autoPlaced:C},v,y,s,c,m,h),T={locked:new Set(e.circuit.annotations.locks.map(e=>e.part)),violated:new Set(e.circuit.violations.map(e=>e.part))},[E,D]=(0,_.useState)(new Set),O=e=>D(t=>{let n=new Set(t);return n.delete(e)||n.add(e),n}),k=()=>e.onSelect(e=>e.clear()),A=e.build.design;return(0,X.jsxs)(`aside`,{ref:t,className:`panel right`,id:e.hidden?void 0:oD(`right`),role:`tabpanel`,"aria-labelledby":sD(`properties`),hidden:e.hidden,children:[b===`wire`&&l!==void 0&&A&&(0,X.jsx)(HE,{design:A,circuit:e.circuit,wire:l,locked:T.locked,run:e.run,onClear:k,collapsed:E,toggle:O}),b===`label`&&u!==void 0&&A&&(0,X.jsx)(Hw,{design:A,label:u,run:e.run,notify:e.actions.notify,onClear:k,collapsed:E,toggle:O}),b===`drawing`&&d!==void 0&&A&&(0,X.jsx)(RT,{design:A,circuit:e.circuit,drawing:d,locked:T.locked,actions:e.actions,onRename:e.onRenameDrawing,run:e.run,onClear:k,collapsed:E,toggle:O}),b===`text`&&p!==void 0&&A&&(0,X.jsx)(UE,{design:A,circuit:e.circuit,text:p,locked:T.locked,actions:e.actions,onClear:k,collapsed:E,toggle:O}),b===`copper`&&f!==void 0&&A&&(0,X.jsx)($T,{design:A,id:f,segment:e.selection.segment,actions:e.actions,run:e.run,onClear:k,collapsed:E,toggle:O}),b===`pour`&&g!==void 0&&A&&(0,X.jsx)(rE,{design:A,circuit:e.circuit,id:g,locks:T,actions:e.actions,run:e.run,onClear:k,collapsed:E,toggle:O}),b===`group`&&(0,X.jsx)(Lw,{view:w,parts:n,others:v+y+s+c+h,locks:T,run:e.run,onClear:k,collapsed:E,toggle:O}),b===`part`&&r&&(0,X.jsx)(wD,{...e,view:w,collapsed:E,toggle:O,part:r,locks:T}),x&&A&&(0,X.jsx)(XE,{design:A,part:x.part,onSelect:e.onSelect,onOpenSheet:e.onOpenSheet}),b===`board`&&!x&&(0,X.jsx)(OD,{...e,view:w,collapsed:E,toggle:O})]})}function CD(e,t){let n=e&&Zf(e.pcb).find(e=>e.name===t);return n&&{x:Math.round(n.center.x*1e3)/1e3,y:Math.round(n.center.y*1e3)/1e3}}function wD({circuit:e,build:t,parts:n,part:r,locks:i,actions:a,onSelect:o,run:s,view:c,collapsed:l,toggle:u,onOpenSheet:d,parentDesign:f}){let p=i.locked.has(r.name),m=n.library.find(e=>e.component===r.tag),h=(e,t)=>a.edit([{kind:`setProps`,part:r.name,props:{[e]:t}}],`set ${r.name} ${e}=${JSON.stringify(t)}`),g=r.editable&&!p,_=e.model.traces.filter(e=>yD(e,r.name)),v=e=>{let[n,i=``]=e.split(`:`),o=r.props[i];if(n===`name`)return(0,X.jsx)(kw,{label:`Name`,children:(0,X.jsx)(`span`,{className:`static`,children:r.name})},e);if(n===`kind`)return(0,X.jsx)(kw,{label:`Kind`,children:(0,X.jsxs)(`span`,{className:`static`,children:[r.tag,`, line `,r.line]})},e);if(n===`placed`)return(0,X.jsx)(kw,{label:vw.label,children:(0,X.jsx)(`span`,{className:`static`,children:vw.value})},e);if(n===`prop`&&o)return(0,X.jsx)(jw,{name:i,prop:o,disabled:!g,onCommit:e=>h(i,e),notify:a.notify},e);if(n===`suggest`){let t=pw[r.tag]?.find(([e])=>e===i)?.[1]??``;return(0,X.jsx)(Nw,{name:i,example:t,disabled:!g,onCommit:e=>h(i,e)},e)}return n===`textAt`&&o?(0,X.jsx)(kw,{label:`${lf[i]??i} offset`,children:(0,X.jsx)(`span`,{className:`static`,title:`Drag it on the canvas, or select it for Reset position`,children:o.source.replace(/[{}]/g,``).trim()})},e):n===`lock`?(0,X.jsx)(ED,{locked:p,onChange:e=>s(e?`lock`:`unlock`)},e):n===`connections`?(0,X.jsx)(DD,{traces:_},e):n===`library`?m&&(0,X.jsx)(WE,{id:m.id,verified:m.verified,actions:a},e):(0,X.jsx)(Fw,{label:`Note for the agent about ${r.name}`,onAdd:e=>{let n=CD(t.design,r.name);return a.mark(n?e:`${r.name}: ${e}`,n?{view:`pcb`,...n}:void 0)}},e)};return(0,X.jsxs)(`div`,{className:`inspector`,children:[(0,X.jsxs)(`header`,{className:`insp-header`,children:[(0,X.jsx)(`span`,{children:c.header}),(0,X.jsx)(`button`,{className:`icon`,"aria-label":`Close`,onClick:()=>o(e=>e.clear()),children:(0,X.jsx)(nh,{})})]}),(0,X.jsx)(TD,{part:r,locks:i,run:s}),p&&(0,X.jsx)(`p`,{className:`note locked`,children:`Locked. The agent cannot move or change this part.`}),r.readonlyReason&&(0,X.jsxs)(`p`,{className:`note`,children:[`Read-only here: `,r.readonlyReason,`. Change it in the code.`]}),it(e.file)&&(0,X.jsx)(ZE,{file:e.file,parentDesign:f}),r.tag===`port`&&it(e.file)&&(0,X.jsx)(QE,{part:r,editable:g,actions:a,collapsed:l,toggle:u}),t.design&&gn(t.design,r.name)&&(0,X.jsx)(YE,{design:t.design,name:r.name,editable:g,actions:a,onOpenSheet:d,collapsed:l,toggle:u}),c.sections.map(e=>(0,X.jsx)(Aw,{title:e.title,open:!l.has(e.title),onToggle:()=>u(e.title),children:e.rows.map(v)},e.title))]})}function TD({part:e,locks:t,run:n}){let r=Ow(e.name,t),i=n=>Dw(n,[e],t);return(0,X.jsxs)(`div`,{className:`inspector-actions`,children:[(0,X.jsxs)(`button`,{className:r.pressed?`toggle on`:`toggle`,"aria-pressed":r.pressed,title:r.title,onClick:()=>n(r.command),children:[r.pressed?(0,X.jsx)(Ym,{}):(0,X.jsx)(Xm,{}),r.label]}),(0,X.jsxs)(`button`,{disabled:!i(`rotate`),onClick:()=>n(`rotate`),children:[(0,X.jsx)($m,{}),` Rotate`]}),(0,X.jsxs)(`button`,{className:`danger`,disabled:!i(`delete`),onClick:()=>n(`delete`),children:[(0,X.jsx)(eh,{}),` Remove`]})]})}function ED({locked:e,onChange:t}){let n=(0,_.useId)();return(0,X.jsx)(kw,{label:`Locked`,htmlFor:n,children:(0,X.jsx)(`input`,{id:n,type:`checkbox`,checked:e,onChange:e=>t(e.target.checked)})})}function DD({traces:e}){return e.length===0?(0,X.jsx)(`p`,{className:`note`,children:`Not connected.`}):(0,X.jsx)(`ul`,{className:`part-traces`,children:e.map((e,t)=>(0,X.jsxs)(`li`,{children:[(0,X.jsx)(`code`,{children:e.from}),` — `,(0,X.jsx)(`code`,{children:e.to})]},`${e.from}-${e.to}-${t}`))})}function OD({circuit:e,build:t,actions:n,counts:r,onShowChecks:i,view:a,collapsed:o,toggle:s}){let c=a=>a===`build`?(0,X.jsxs)(`div`,{children:[t.status===`failed`&&(0,X.jsx)(`p`,{className:`note error`,children:t.error}),t.status===`building`&&(0,X.jsx)(`p`,{className:`note`,children:`Building…`}),t.design&&(0,X.jsx)(kD,{counts:r,onShowChecks:i})]},a):(0,X.jsxs)(`div`,{children:[e.annotations.marks.length===0&&(0,X.jsx)(`p`,{className:`note`,children:`Select a part to leave a note at it, or use Place → Note box to draw one on the canvas.`}),(0,X.jsx)(`ul`,{className:`marks`,children:e.annotations.marks.map(e=>(0,X.jsxs)(`li`,{children:[(0,X.jsx)(`span`,{children:e.text}),(0,X.jsx)(`button`,{className:`icon`,"aria-label":`Remove note ${e.id}`,onClick:()=>void n.unmark(e.id),children:(0,X.jsx)(nh,{})})]},e.id))}),(0,X.jsx)(Fw,{label:`Note for the agent`,onAdd:e=>n.mark(e)})]},a);return(0,X.jsxs)(`div`,{className:`inspector`,children:[(0,X.jsxs)(`header`,{className:`insp-header`,children:[(0,X.jsx)(`span`,{children:a.header}),(0,X.jsxs)(`span`,{className:`insp-file`,children:[e.file,`: `,e.model.parts.length,` parts, `,e.model.traces.length,` connections`]})]}),a.sections.map(e=>(0,X.jsx)(Aw,{title:e.title,open:!o.has(e.title),onToggle:()=>s(e.title),children:e.rows.map(c)},e.title)),(0,X.jsx)(qC,{file:e.file,buildId:t.finishedAt,actions:n}),(0,X.jsx)(`p`,{className:`hint`,children:`Select a part to see and change its properties.`})]})}function kD({counts:e,onShowChecks:t}){let n=e.errors>0?`error`:e.warnings>0?`warn`:`ok`;return(0,X.jsxs)(`div`,{className:`check-counts`,children:[(0,X.jsx)(`p`,{className:`note ${n}`,children:dw(e)}),e.errors+e.warnings>0&&(0,X.jsx)(`button`,{onClick:t,title:`DRC (\\)`,children:`Show checks`})]})}var AD=12,jD=32,MD={minor:W.grid,fifth:W.gridFifth},ND={lines:MD,dots:{...MD,px:1}};function PD(e,t,n,r,i){Eg(e,t,n,r,ND,i)}var FD={selected:W.selection,selectedFill:W.selectionFill,hover:W.hover,noteStroke:W.selectionBox,noteFill:W.selectionBoxFill,noteDash:[1,3],boxStroke:W.selectionBox,boxFill:W.selectionBoxFill,boxDash:[1,3],lockFill:W.document,lockGlyph:W.background,markPin:W.document,markPanel:W.notePanel,markText:W.document};function ID(e){return{selected:e.selection,hover:e.hover,noteStroke:e.selection,noteFill:e.selectionFill,noteDash:[5,4],boxStroke:e.selectionBox,boxFill:e.selectionBoxFill,boxDash:[5,4],lockFill:e.lockBadge,lockGlyph:e.lockGlyph,markPin:e.notePin,markPanel:e.notePanel,markText:e.noteText,...e.selectionGlow>0?{glow:e.selectionGlow}:{}}}ID(Ao);function LD(e,t,n,r,i,a,o,s){let c=V(t,n,{x:r.minX+i.x,y:r.maxY+i.y}),l=V(t,n,{x:r.maxX+i.x,y:r.minY+i.y}),u=a===`selected`?Qo(1.5,s):1,d=es({x:c.x-3,y:c.y-3},{x:l.x+3,y:l.y+3},s,u);e.save(),e.lineWidth=u/s,e.strokeStyle=a===`selected`?o.selected:o.hover,e.setLineDash(a===`selected`?[]:[4,3]),a===`selected`&&o.selectedFill&&(e.fillStyle=o.selectedFill,e.fillRect(d.x,d.y,d.width,d.height)),e.shadowBlur=a===`selected`?o.glow??0:0,e.shadowBlur>0&&(e.shadowColor=o.selected),e.strokeRect(d.x,d.y,d.width,d.height),e.restore()}function RD(e,t,n,r,i,a){let o=V(t,n,{x:r.maxX,y:r.maxY}),s=Jo(o.x-4,a),c=Jo(o.y-12,a),l=Yo(14,a);e.save(),e.fillStyle=i.lockFill,UD(e,s,c,l,l,3),e.fill(),e.strokeStyle=i.lockGlyph,e.fillStyle=i.lockGlyph,e.lineWidth=1.3,e.beginPath(),e.arc(s+7,c+6,2.4,Math.PI,0),e.stroke(),e.fillRect(s+3.5,c+6,7,5),e.restore()}function zD(e,t,n,r,i,a){let{at:o,id:s,text:c}=r,l=V(t,n,o),u=`${s} ${c.length>jD?`${c.slice(0,31)}…`:c}`;e.save(),cs(e),e.font=`${os(AD,1,a)}px ${ya}`;let d=e.measureText(u).width+12;e.fillStyle=i.markPanel,UD(e,l.x+10,l.y-22,d,20,4),e.fill(),e.fillStyle=i.markText;let f=ss({x:l.x+16,y:l.y-8},a);e.fillText(u,f.x,f.y),e.strokeStyle=i.markPin,e.lineWidth=Qo(1.5,a)/a,e.beginPath(),e.moveTo(l.x,l.y),e.lineTo(l.x+10,l.y-12),e.stroke(),e.fillStyle=i.markPin,e.beginPath(),e.arc(l.x,l.y,4,0,Math.PI*2),e.fill(),e.restore()}function BD(e,t,n,r,i,a){HD(e,t,n,{stroke:r.boxStroke,fill:r.boxFill,dash:i===`inside`?[]:r.boxDash},a)}function VD(e,t,n,r,i){HD(e,t,n,{stroke:r.noteStroke,fill:r.noteFill,dash:r.noteDash},i)}function HD(e,t,n,r,i){let a=es(t,n,i);e.save(),e.lineWidth=Ko(i),e.fillStyle=r.fill,e.strokeStyle=r.stroke,e.setLineDash(r.dash),e.fillRect(a.x,a.y,a.width,a.height),e.strokeRect(a.x,a.y,a.width,a.height),e.restore()}function UD(e,t,n,r,i,a){e.beginPath(),e.moveTo(t+a,n),e.arcTo(t+r,n,t+r,n+i,a),e.arcTo(t+r,n+i,t,n+i,a),e.arcTo(t,n+i,t,n,a),e.arcTo(t,n,t+r,n,a),e.closePath()}function WD(e,t,n,r,i,a,o){let s=r.map(e=>V(t,n,e)),c=s[s.length-1];c&&(e.save(),e.strokeStyle=a,e.lineWidth=Qo(2,o)/o,e.lineCap=`round`,e.lineJoin=`round`,e.globalAlpha=i===`pending`?.75:1,e.setLineDash(i===`pending`?[6,5]:[]),e.beginPath(),s.forEach((t,n)=>n===0?e.moveTo(t.x,t.y):e.lineTo(t.x,t.y)),e.stroke(),i===`drawing`&&(e.setLineDash([]),e.beginPath(),e.arc(c.x,c.y,5,0,Math.PI*2),e.stroke()),e.restore())}function GD(e,t,n,r,i,a){for(let o of n){let n=r.selected.includes(o.id)?`selected`:o.id===r.hover?`hover`:void 0;n&&LD(e,t.camera,t.size,o.box,{x:0,y:0},n,i,a)}}var KD=(e,t,n)=>Math.min(Math.max(e,t),n);function qD(e){let t=Math.max(0,Math.floor((e.length-2)/2)),[n,r]=[e[t],e[t+1]];return n&&r?{x:(n.x+r.x)/2,y:(n.y+r.y)/2}:void 0}function JD(e,t,n){let r=e[0];if(r===void 0||t!==e.length)return;let i=n.tracks.find(e=>e.id===r);if(i)return{id:r,points:i.points};let a=n.vias.find(e=>e.id===r);return a&&{id:r,points:[a.at]}}var YD=e=>e.points.length===1?e.points[0]:qD(e.points);function XD(e,t,n,r){let i=n&&qD(n.points);if(n&&i)return{target:{kind:`wire`,id:n.id},middle:i};let a=r&&YD(r);if(r&&a)return{target:{kind:`copper`,id:r.id},middle:a};let o=e===void 0?void 0:t.find(t=>t.name===e);return o&&{target:{kind:`part`,name:o.name},middle:{x:(o.box.minX+o.box.maxX)/2,y:(o.box.minY+o.box.maxY)/2}}}function ZD(e,t,n,r,i,a,o){let s=n?XD(e,t,a,o):void 0,c=s&&n?V(n,r,s.middle):{x:r.width/2,y:r.height/2},l=r.width>0?i.width/r.width:1,u=r.height>0?i.height/r.height:1,d={x:i.left+KD(c.x,0,r.width)*l,y:i.top+KD(c.y,0,r.height)*u};return{target:s?.target??{kind:`canvas`},at:d}}function QD(e,t){return{width:Math.round(e.width*t),height:Math.round(e.height*t)}}function $D(e,t,n){let r=QD(t,n);return e.width===r.width&&e.height===r.height?!1:(e.width=r.width,e.height=r.height,!0)}function eO(e){typeof e.reset==`function`?e.reset():(e.setTransform(1,0,0,1,0,0),e.globalAlpha=1,e.globalCompositeOperation=`source-over`,e.setLineDash([]))}var tO=.0015,nO=1.25;function rO(e,t,n){let r=(0,_.useMemo)(()=>t===`pcb`?Zf(e.pcb):vc(e.schematic),[e,t]),i=(0,_.useMemo)(()=>Pe(e,t),[e,t]),a=(0,_.useMemo)(()=>[...i.values()].some(e=>e.autoPlaced),[i]),o=(0,_.useMemo)(()=>Cn(new Set(n.annotations.locks.map(e=>e.part)),e),[n,e]);return{boxes:r,anchors:i,autoPlaced:a,locked:o,blockerFor:(0,_.useCallback)(r=>wn(e,o,r)??Fe(n,o,r,t),[e,n,o,t])}}function iO(e,t,n){let{anchors:r,boxes:i}=e;return(0,_.useMemo)(()=>({anchors:r,boxes:i,step:t,snap:n}),[r,i,t,n])}function aO(e,t,n,r,i,a,o){return(0,_.useCallback)(()=>ZD(t,n,r,i,e.current?.getBoundingClientRect()??{left:0,top:0,width:i.width,height:i.height},a,o),[e,t,n,r,i,a,o])}function oO(e){let[t,n]=(0,_.useState)({width:0,height:0});return(0,_.useEffect)(()=>{let t=e.current;if(!t)return;let r=new ResizeObserver(([e])=>{e&&n({width:Math.floor(e.contentRect.width),height:Math.floor(e.contentRect.height)})});return r.observe(t),()=>r.disconnect()},[e]),t}function sO(e,t,n){let r=e?.getBoundingClientRect();return!r||r.width===0||r.height===0?{x:0,y:0}:{x:(n.clientX-r.left)*t.width/r.width,y:(n.clientY-r.top)*t.height/r.height}}function cO(e,t,n,r){let[i,a]=(0,_.useState)();uO(e,t,a);let o=(0,_.useCallback)(()=>{n&&t.width>0&&a(be(n,t,r))},[n,t,r]);(0,_.useEffect)(()=>{i||o()},[i,o]);let s=e=>()=>a(n=>n&&Ce(n,t,{x:t.width/2,y:t.height/2},e));return Gx({zoomIn:s(nO),zoomOut:s(1/nO)}),{camera:i,setCamera:a,fit:o}}function lO(e,t,n,r,i){(0,_.useEffect)(()=>{t&&t.view===e&&n&&(r(Se(n,t.at)),i())},[e,t,n,r,i])}function uO(e,t,n){let r=(0,_.useCallback)(r=>{r.preventDefault();let i=sO(e.current,t,r);n(e=>e&&Ce(e,t,i,Math.exp(-r.deltaY*tO)))},[e,t,n]);(0,_.useEffect)(()=>{let t=e.current;if(t)return t.addEventListener(`wheel`,r,{passive:!1}),()=>t.removeEventListener(`wheel`,r)},[e,r])}function dO(e,t,n,r,i){if(!e||t.width===0)return null;let a=window.devicePixelRatio||1;$D(e,t,a);let o=e.getContext(`2d`);return o?(eO(o),o.fillStyle=r,o.fillRect(0,0,e.width,e.height),o.setTransform(a,0,0,a,0,0),i(o,n,t,a),{ctx:o,ratio:a}):null}function fO(e,t,n,r){let{look:i,gesture:a,ratio:o}=r;for(let a of r.boxes){let s=r.moving?.names.includes(a.name)?r.moving.offset:{x:0,y:0},c=r.selection.has(a.name);a.name===r.hover&&!c&&LD(e,t,n,a.box,s,`hover`,i,o),c&&LD(e,t,n,a.box,s,`selected`,i,o),r.locked.has(a.name)&&RD(e,t,n,a.box,i,o)}for(let a of r.marks)a.view===r.view&&a.x!==void 0&&a.y!==void 0&&zD(e,t,n,{at:{x:a.x,y:a.y},id:a.id,text:a.text},i,o);a?.kind===`box`&&BD(e,a.start,a.current,i,Xa(a.start,a.current),o),a?.kind===`zoom`&&BD(e,a.start,a.current,i,Xa(a.start,a.current),o),a?.kind===`note`&&VD(e,a.start,a.current,i,o)}function pO(e){return e.target instanceof HTMLElement&&e.target.closest(`input, textarea, select`)?!1:!(e.ctrlKey||e.metaKey||e.altKey)}var mO=`Waiting for the build…`,hO=`Snap off`;function gO(e){if(e?.kind===`drag`&&e.moved&&!e.blocker)return e.offset;if(e?.kind===`label`&&e.moved&&!e.blocker)return{x:e.at.x-e.label.at.x,y:e.at.y-e.label.at.y};if(e?.kind===`text`&&e.moved&&!e.blocker)return{x:e.at.x-e.from.x,y:e.at.y-e.from.y}}var _O=(e,t)=>rg(e,t??`mm`);function vO(e){let{cursor:t,zoom:n,unit:r}=e,i=gO(e.gesture);return{position:[n===void 0?``:`Zoom ${ag(n,r?10:60)}%`,t?`X ${_O(t.x,r)} Y ${_O(t.y,r)}`:``].filter(e=>e!==``).join(` `),drag:i?`dX ${_O(i.x,r)} dY ${_O(i.y,r)}`:``,notice:e.rotateHeld?mO:``,snap:e.snap===!1?hO:``}}function yO(e,t,n,r){return`Routing ${e} on ${t}, ${n} mm, ${r} — Space corner, V layer+via, Enter ends open, Esc`}function bO({step:e,options:t,onChange:n}){return(0,X.jsxs)(`label`,{children:[`Grid`,(0,X.jsx)(`select`,{value:e,onChange:e=>n(Number(e.target.value)),children:t.map(e=>(0,X.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})}function xO({show:e,onKeep:t,title:n}){return e?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:`tool-divider`,"aria-hidden":`true`}),(0,X.jsx)(`button`,{onClick:t,title:n,children:`Keep these positions`})]}):null}function SO({cursor:e,zoom:t,unit:n,onToggleUnit:r,detail:i,gesture:a,rotateHeld:o,snap:s}){let{position:c,drag:l,notice:u,snap:d}=vO({cursor:e,zoom:t,unit:n,gesture:a,rotateHeld:o,snap:s});return(0,X.jsxs)(`div`,{className:`canvas-status`,"aria-live":`off`,children:[(0,X.jsx)(`span`,{children:c}),n&&(0,X.jsx)(`button`,{className:`unit-toggle`,onClick:e=>{r?.(),km(e)},onPointerDown:e=>e.stopPropagation(),title:`Switch between mm and mil (Q)`,children:n}),l&&(0,X.jsx)(`span`,{children:` ${l}`}),i&&(0,X.jsx)(`span`,{children:` ${i}`}),d&&(0,X.jsx)(`span`,{children:` ${d}`}),u&&(0,X.jsx)(`span`,{children:` ${u}`})]})}var CO=(e,t)=>({x:e.x+t.x,y:e.y+t.y}),wO=(e,t,n)=>({...e.length>0?{wires:e}:{},...t.length>0?{labels:t}:{},...n.length>0?{drawings:n}:{}}),TO=(e,t,n,r,i)=>so(e.names,t)&&so(e.wires??[],n)&&so(e.labels??[],r)&&so(e.drawings??[],i);function EO(e,t,n,r,i=[],a=[],o=[]){let s=e!==void 0&&TO(e,n,i,a,o);if(e&&s&&e.inFlight)return{burst:{...e,total:CO(e.total,r),dirty:!0},send:null,fresh:!1};if(e&&s&&e.base===t){let t=CO(e.total,r);return{burst:{...e,total:t,inFlight:!0,dirty:!1},send:t,fresh:!1}}return{burst:{base:t,names:n,...wO(i,a,o),total:r,inFlight:!0,dirty:!1},send:r,fresh:!0}}function DO(e,t){if(t)return e.dirty?{burst:{...e,dirty:!1,inFlight:!0},send:e.total,fresh:!1}:{burst:{...e,inFlight:!1},send:null,fresh:!1}}var OO={inFlight:0,seq:0,waiting:void 0,written:0,held:void 0,history:void 0};function kO(e,t){return e.inFlight>0||t.moveWaiting?!1:e.waiting===void 0||t.buildStatus===`done`&&t.builtMark!==void 0&&t.builtMark>e.written}var AO=(e,t)=>e.waiting&&kO(e,t)?{...e,waiting:void 0,history:void 0}:e;function jO(e,t,n,r){if(n)return{gate:e,send:!1};if(kO(e,r)&&!e.held)return{gate:AO(e,r),send:!0};let i=e.held&&so(e.held.names,t)?e.held.count+1:1;return{gate:{...e,held:{names:t,count:i}},send:!1}}function MO(e,t,n){let{held:r}=e;if(!r||!kO(e,n))return{gate:r?e:AO(e,n),send:!1};let i=AO(e,n);return so(r.names,t)?{gate:{...i,held:r.count>1?{...r,count:r.count-1}:void 0},send:!0}:{gate:{...i,held:void 0},send:!1}}function NO(e){let t=e.seq+1;return{...e,inFlight:e.inFlight+1,seq:t,waiting:{seq:t}}}function PO(e,t,n,r,i){let a=Math.max(0,e.inFlight-1);return t?{...e,inFlight:a,written:Math.max(e.written,i??0)}:{...e,inFlight:a,waiting:e.waiting?.seq===n?r:e.waiting,held:void 0}}function FO(e){let t=NO(e);return{...t,history:{seq:t.seq}}}function IO(e,t,n,r,i){if(t)return PO(e,!0,n,r.waiting,i);let a=e=>e?.seq===n,o=Math.max(0,e.inFlight-1),s=a(e.waiting)?r.waiting:e.waiting;return{...e,inFlight:o,waiting:s,history:a(e.history)?r.history:e.history}}function LO(e,t){return e.history===void 0?{gate:e,send:!0}:kO(e,t)?{gate:AO(e,t),send:!0}:{gate:e,send:!1}}function RO(e,t,n,r=[],i=[],a=[]){let o=e!==void 0&&TO(e,t,r,i,a);return{names:t,...wO(r,i,a),total:e&&o?CO(e.total,n):n}}function zO(e,t,n,r,i=[],a=[],o=[]){if(!t)return{gate:e,held:t,send:null};let s=LO(e,r);return s.send?{gate:s.gate,held:void 0,send:TO(t,n,i,a,o)?t.total:null}:{gate:e,held:t,send:null}}var BO=new Set([`fit`,`highlight`,`contextMenu`,`delete`,`rotate`,`nudgeLeft`,`nudgeRight`,`nudgeUp`,`nudgeDown`,`alignLeft`,`distributeH`]);function VO(e,t,n,r,i=t){return!r||!BO.has(e)?!1:e.startsWith(`nudge`)?i>0&&!n:e===`rotate`?t>0&&!n:e===`alignLeft`||e===`distributeH`?!n:!0}function HO(e){let t={},n=(e,t)=>({x:e.at.x+t.x,y:e.at.y+t.y}),r=(i,a)=>{let{text:o}=t;o&&e(o,n(o,a)).then(e=>{if(t.burst!==i&&t.burst?.base!==i.base)return;let n=t.burst?DO(t.burst,e):void 0;t.burst=n?.burst,n?.burst&&n.send&&r(n.burst,n.send)})};return{press(e,i,a,o){let s=EO(t.burst,e,[a],o);if(s.fresh&&(t.text=i(a)),t.burst=s.burst,!t.text)t.burst=void 0;else return s.send&&r(s.burst,s.send),n(t.text,s.burst.total)}}}function UO(e){return e?.kind===`text`&&e.moved&&!e.blocker?{id:e.id,at:e.at}:void 0}function WO({view:e,design:t,circuit:n,actions:r,locked:i,builtFrom:a,drawn:o}){let[s,c]=(0,_.useState)([]);(0,_.useEffect)(()=>c(e=>e.every(e=>e.sentAt>a)?e:e.filter(e=>e.sentAt>a)),[a]);let l=(0,_.useMemo)(()=>mf(e,t),[e,t]),u=(0,_.useMemo)(()=>s.filter(e=>e.sentAt>a),[s,a]),d=(0,_.useMemo)(()=>yf(l,u),[l,u]),f=(e,t)=>{let n={id:e,at:t,sentAt:Date.now()};return c(t=>[...t.filter(t=>t.id!==e),n]),n},p=async(e,t)=>{let a=wf(n,i,e.id);if(a)return r.notify(a),!1;let o=bf(e,t);if(o.length===0)return!0;let s=f(e.id,t),l=await r.edit(o,`Move ${e.part} ${lf[e.prop]?.toLowerCase()??e.prop}`);return l||c(e=>e.filter(e=>e!==s)),l},m=(e,t)=>{let n=d.find(t=>t.id===e);n&&p(n,t)},h=(0,_.useRef)(p);h.current=p;let[g]=(0,_.useState)(()=>HO((e,t)=>h.current(e,t)));return{tools:{at:e=>_f(o?d.filter(e=>o(e.part)):d,e)?.id,position:e=>d.find(t=>t.id===e)?.at,blocker:e=>wf(n,i,e),commit:m},placed:d,pending:u,nudge:(e,r)=>{let a=g.press(t,e=>d.find(t=>t.id===e),e,r);a&&wf(n,i,e)===null&&f(e,a)}}}function GO(e,t){let{placed:n,pending:r}=e;return(0,_.useMemo)(()=>{let e=UO(t);return{moves:e?[e,...r.filter(t=>t.id!==e.id)]:r,shown:e?yf(n,[e]):n}},[t,n,r])}var KO=e=>e*Math.PI/180;function qO(e,t,n=!1){let r=n&&e.length>2?[...e,e[0]]:e,i=1/0;for(let e=1;e<r.length;e++)i=Math.min(i,Kc(t,r[e-1],r[e]));return i}function JO(e,t,n,r){let i=r-n;if(Math.abs(i)>=360)return!0;let a=(i%360+360)%360;return((Math.atan2(e.y-t.y,e.x-t.x)*180/Math.PI-n)%360+360)%360<=a}function YO(e,t){let n={x:e.x,y:e.y};if(JO(t,n,e.startAngle,e.endAngle))return Math.abs(Math.hypot(t.x-n.x,t.y-n.y)-e.radius);let r=t=>({x:n.x+e.radius*Math.cos(KO(t)),y:n.y+e.radius*Math.sin(KO(t))}),[i,a]=[r(e.startAngle),r(e.endAngle)];return Math.min(Math.hypot(t.x-i.x,t.y-i.y),Math.hypot(t.x-a.x,t.y-a.y))}var XO=(e,t)=>t.x>=e.minX&&t.x<=e.maxX&&t.y>=e.minY&&t.y<=e.maxY,ZO=(e,t)=>Math.hypot(Math.max(e.minX-t.x,0,t.x-e.maxX),Math.max(e.minY-t.y,0,t.y-e.maxY));function QO(e,t){switch(e.kind){case`path`:case`bus`:return qO(e.points,t);case`rect`:{let{x:n,y:r,width:i,height:a}=e;return qO([{x:n,y:r},{x:n+i,y:r},{x:n+i,y:r+a},{x:n,y:r+a}],t,!0)}case`circle`:return Math.abs(Math.hypot(t.x-e.x,t.y-e.y)-e.radius);case`arc`:return YO(e,t);case`text`:case`junction`:return ZO(dn(e),t)}}function $O(e,t){return Wo(e)?e.kind===`circle`?Math.hypot(t.x-e.x,t.y-e.y)<=e.radius:XO(dn(e),t):!1}function ek(e,t,n){return QO(e,t)<=n+zo(e)/2?`line`:$O(e,t)?`inside`:void 0}var tk=(e,t)=>e.kind!==`text`||t===void 0||e.fontSize*t>=3;function nk(e,t,n,r){let i;for(let a=e.length-1;a>=0;a--){let o=e[a];if(!tk(o,r))continue;let s=ek(o,t,n);if(s===`line`)return{id:o.id,place:s};s===`inside`&&!i&&(i={id:o.id,place:s})}return i}function rk(e){let t=dn(e),n=zo(e)/2;return{minX:t.minX-n,minY:t.minY-n,maxX:t.maxX+n,maxY:t.maxY+n}}function ik(e){return e.map(e=>({id:e.id,box:rk(e)}))}function ak(e,t,n,r){return $a(e,t,n,r)}var ok=.1,sk=`None of the selected parts is in this view.`,ck=1e-6;function lk(e,t,n){let r=Math.max(e.maxX-e.minX,ck),i=Math.max(e.maxY-e.minY,ck),a=Math.min(t.width/r,t.height/i)*(1-2*n);return{cx:(e.minX+e.maxX)/2,cy:(e.minY+e.maxY)/2,scale:je(a)}}function uk(e,t,n,r){let i=new Set(t),a=ke(e.filter(e=>i.has(e.name)).map(e=>e.box));return!a||n.width<=0||n.height<=0?{message:sk}:{camera:lk(a,n,r)}}function dk(e,t,n){return lk({minX:Math.min(e.x,t.x),minY:Math.min(e.y,t.y),maxX:Math.max(e.x,t.x),maxY:Math.max(e.y,t.y)},n,0)}var fk=new Set([`part`,`selectedPart`,`label`,`selectedLabel`,`wire`,`selectedWire`,`wireCorner`,`drawing`,`selectedDrawing`,`text`]),pk=new Set([`selectedPart`,`selectedWire`,`selectedLabel`,`selectedDrawing`]),mk=0,hk=1,gk=2,_k={wire:`wireSegment`,wireCorner:`wireCorner`};function vk(e,t,n){return e.button===hk?`pan`:e.button===gk?`rightPress`:e.button===mk?n===`note`?`note`:n===`zoom`?`zoom`:n===`place`&&t===`empty`?`pan`:yo(e)?fk.has(t)?`toggle`:`addBox`:t===`part`||t===`drawing`?`move`:pk.has(t)?`moveGroup`:t===`wire`||t===`wireCorner`?n===null?_k[t]:`wire`:t===`text`?`text`:t===`label`?`label`:`box`:`none`}var yk=2;function bk(e){return(e&yk)!==0}function xk(e,t){return e===`rightPress`?t?`disarm`:`menu`:e===`moveGroup`?`selectAlone`:e===`box`?`clear`:`none`}function Sk(e,t){return Math.hypot(t.x-e.x,t.y-e.y)>=3}var Ck=`input, textarea, select, form, button`;function wk(e){if(e.button!==mk)return!1;let t=e.target;return typeof t?.closest!=`function`||!t.closest(Ck)}var Tk=(e,t)=>({x:H(e.x+t.x),y:H(e.y+t.y)}),Ek=(e,t)=>e.x===t.x&&e.y===t.y,Dk=e=>Tk(e.at,e.by);function Ok(e,t,n){let r=e.schematic.symbols.find(e=>e.component===n);if(!r)return;let i=e.circuit.components.find(e=>e.id===n)?.groupOffset.sch??Ne,a=Le(t,n,`schematic`,{origin:r,group:i}),o={x:H(a.x),y:H(a.y)};return{props:o,ahead:{x:H(o.x+i.x-r.x),y:H(o.y+i.y-r.y)}}}var kk=(e,t)=>typeof e==`number`?H(e-t):0;function Ak(e,t,n){let r=new Map;for(let i of n){if(i.kind!==`setProps`)continue;let{schX:n,schY:a}=i.props,o=typeof n==`number`||typeof a==`number`?Ok(e,t,i.part):void 0;o&&r.set(i.part,{x:kk(n,o.props.x),y:kk(a,o.props.y)})}return r}function jk(e){let t=e.trace.schematicRouteHints??[];return e.reversed?[...t].reverse():[...t]}function Mk(e,t,n,r,i){let a=(n,r)=>{if(n===void 0||r===void 0)return;let a=Ok(e,t,r);return a&&{at:Tk(n,a.ahead),by:i.get(r)??Ne}},o=a(n.points[0],r.components[0]);if(!o||r.toNet)return o&&[o,void 0];let s=a(n.points[n.points.length-1],r.components[1]);return s&&[o,s]}function Nk(e,t,n){let r=tl(e,t);return r===`horizontal`?{x:0,y:n.y}:r===`vertical`?{x:n.x,y:0}:Ne}function Pk(e,t,n){if(n&&Ek(e.by,n.by))return t.map(t=>Tk(t,e.by));let r=t.length-1,[i,a]=[t[0],t[r]],o=i?Nk(e.at,i,e.by):Ne,s=n&&a?Nk(n.at,a,n.by):Ne;return t.map((e,t)=>Tk(Tk(e,t===0?o:Ne),t===r?s:Ne))}function Fk(e,t,n,r,i){let a=jk(r),o=a.length>0?Mk(e,t,n,r,i):void 0;if(!o)return;let[s,c]=o;return{start:s,end:c,corners:a,path:fl([s.at,...a,...c?[c.at]:[]])}}function Ik(e,t,n,r,i){let a=n.length<2?[]:Nl(e,{...t,points:n},n,r,i);return Array.isArray(a)&&a.length>0?{line:{id:t.id,points:n},edits:a}:void 0}function Lk(e,t,n,r,i){let{writer:a}=n;if(a.kind!==`trace`||!a.components.some(e=>r.has(e)))return;let o=Fk(e,t,n,a,r);if(!o)return;let{start:s,end:c}=o,l=c?[Dk(c)]:[],u=o.path.slice(1,c?-1:void 0);return Ik(e,n,fl([Dk(s),...Pk(s,u,c),...l]),i,[Dk(s),...o.corners,...l])}function Rk(e,t,n,r,i){if(n.size===0)return[];let a=new Set(e.circuit.components.filter(e=>n.has(e.id)).flatMap(e=>e.pins.map(e=>e.id))),o=new Set(e.circuit.connections.filter(e=>a.has(e.from)||a.has(e.to)).map(e=>e.id));return e.schematic.wires.flatMap(a=>{let s=a.connection!==void 0&&o.has(a.connection)&&!i.has(a.id)?K(e,t,a.id):void 0,c=s&&Lk(e,t,s,n,r);return c?[c]:[]})}function zk(e,t,n,r,i,a,o){let s=Fk(e,t,n,r,a);if(!s)return;let[c,l]=r.components,u=s.end?l!==void 0&&a.has(l):i.labelEnd,d={start:c!==void 0&&a.has(c),end:u};return Ik(e,n,ul(s.path,i.offset,d),o,s.path)}function Bk(e,t,n,r,i){let{design:a,locked:o}=e,s=K(a,t,n),c=s?.writer;if(!s||c?.kind!==`trace`||jk(c).length===0)return{kind:`leave`};let l=q(a,s,o);if(l!==null)return{kind:`blocked`,reason:l,named:jE(a,s,l)};let u=CE(a,s);return!c.toNet&&c.components.every(e=>i.has(e))?{kind:`follow`,id:n,name:u}:{kind:`carry`,id:n,name:u,move:zk(a,t,s,c,r,i,o)}}var Vk=`Studio draws this wire's shape between its pins; drag one of its segments to give it corners first`,Hk=`Studio draws these wires' shapes between their pins; drag one of their segments to give them corners first`;function Uk(e,t,n){let r=e.flatMap(e=>e.kind===`blocked`&&!t.includes(e.reason)?[e.named]:[]),i=e.filter(e=>e.kind===`leave`).length,a=n&&i>0?[i===1?Vk:Hk]:[];return[...r,...a]}function Wk(e,t){return e.flatMap(e=>e.kind===`carry`&&e.move||e.kind===`follow`&&t.has(e.id)?[e.name]:[])}var Gk=(e,t,n,r,i)=>`move ${st([...e,...ct(t),...rm(n),...r])}${Me.schematic.where} by (${H(i.x)}, ${H(i.y)})`;function Kk(e,t,n,r){let i=n?.wires??[],a=Zp(e.design,n?.labels??[],e=>r.has(e),i),o=i=>Bk(e,t,i,{offset:n?.offset??Ne,labelEnd:a.riding.has(i)},r),s=[...a.riding.keys()].filter(e=>!i.includes(e));return{outcomes:i.map(o),riding:s.map(o),ridingIds:s,sort:a}}function qk(e,t,n,r){return n.riding.flatMap((i,a)=>{if(i.kind===`carry`||i.kind===`follow`)return[];let o=n.ridingIds[a]??``,s=K(e.design,t,o),c=i.kind===`blocked`?i.reason:s&&q(e.design,s,e.locked),l=e.design.schematic.labels.find(e=>e.id===n.sort.riding.get(o));return c&&!r.includes(c)?[$p(l,c)]:[]})}function Jk(e){let t=new Set([...e.outcomes,...e.riding].flatMap(e=>e.kind===`carry`&&e.move?[e.id]:[]));return[...e.sort.onPins,...[...e.sort.riding].flatMap(([e,n])=>t.has(e)?[n]:[])]}function Yk(e,t,n,r){if(!n)return{plan:e,lines:[],labels:[],drawings:[]};let i=Ak(n.design,t,e.edits),a=Kk(n,t,r,i),o=[...a.outcomes,...a.riding].flatMap(e=>e.kind===`carry`&&e.move?[e.move]:[]),s=Rk(n.design,t,i,n.locked,new Set(o.map(e=>e.line.id))),c=[...o,...s],l=r?.offset??Ne,u=tm(n.design,t,a.sort.alone,l,n.locked,e.skipped),d=nT(t.model,n.design.schematic.drawings,r?.drawings??[],l,n.locked),f=Wk(a.outcomes,new Set(s.map(e=>e.line.id))),p=[...nm(n.design,Jk(a)),...u.names],m=[...u.edits,...d.edits],h=e.edits.length===0&&c.length===0&&m.length===0,g=[...Uk(a.outcomes,e.skipped,h),...qk(n,t,a,e.skipped),...u.notes,...d.skipped],_={lines:c.map(e=>e.line),labels:u.shown,drawings:d.shown};if(c.length===0&&m.length===0&&f.length+p.length+g.length===0)return{plan:e,..._};let v=r&&f.length+p.length+d.names.length>0?Gk(e.parts,f,p,d.names,l):e.summary,y=[...e.edits,...c.flatMap(e=>e.edits),...m];return{plan:{...e,edits:y,summary:v,skipped:[...e.skipped,...g]},..._}}function Xk(e,t,n,r){return Yk(e,t,n,r).plan}function Zk(e,t,n,r=[],i=[],a=[]){return Yk(dt(e.circuit,t,e.view,ft(e.anchors,e.boxes),n,e.blockerFor),e.circuit,e.follow,{wires:r,labels:i,drawings:a,offset:n})}var Qk=6,$k=H;function eA(e,t,n,r,i,a,o){let s=t?.at(n),c=i?.at(n),l=a?.at(n),u=o?.at(n),d=e=>l?.place===e?[{kind:`drawing`,id:l.id}]:[],[f]=Ua([...s?[{kind:`label`,label:s}]:[],...c===void 0?[]:[{kind:`wire`,id:c}],...d(`line`),...De(e,n).map(e=>({kind:`part`,name:e.name})),...u===void 0?[]:[{kind:`text`,id:u}],...d(`inside`)],r);return f??{kind:`canvas`}}function tA(e,t,n,r){return eA(e,void 0,t,n,void 0,void 0,r).kind===`text`}function nA({busy:e,handle:t,target:n,selectedBefore:r}){return e?{kind:`none`}:t?t.id===r?{kind:`removeCorner`,...t}:{kind:`properties`,target:{kind:`wire`,id:t.id}}:n.kind===`part`||n.kind===`wire`||n.kind===`drawing`?{kind:`properties`,target:n}:n.kind===`label`?{kind:`rename`,label:n.label}:{kind:`none`}}var rA=e=>({selection:e.selection,armed:e.tool.armed,layers:e.layers,filter:e.filter});function iA(e,t){return e.kind===`part`?t.has(e.name)?`selectedPart`:`part`:e.kind===`wire`?t.hasWire(e.id)&&t.total>1?`selectedWire`:`wire`:e.kind===`label`?t.hasLabel(e.label.id)&&t.total>1?`selectedLabel`:`label`:e.kind===`drawing`?t.hasDrawing(e.id)?`selectedDrawing`:`drawing`:e.kind===`text`?`text`:`empty`}function aA(e,t,n){let r=Jl(e.wires?.drag,rA(e),t,n.scale);if(r)return{target:{kind:`wire`,id:r.id},under:`wireCorner`,corner:r.index};let i=eA(e.boxes,e.labels,t,rA(e),e.wires,e.drawings,e.texts),a=i.kind===`text`?void 0:e.copperAt?.(t);return a===void 0?{target:i,under:iA(i,e.selection)}:{target:{kind:`copper`,id:a},under:`empty`}}var oA=new Set([`wire`,`wireSegment`,`wireCorner`]);function sA(e,t,n,r,i){if(e.onSelect(e=>e.onlyWire(t)),n===`wire`)return;let a=e.wires?.drag,o=a?.points(t),s=o&&Yl(o,r.world,i.scale,n===`wireCorner`?r.corner:void 0);return s&&Zl(a,t,s,r.point)}function cA(e,t,n){let{camera:r}=e;if(!r)return;let i=ye(r,e.size,n),{target:a,under:o,corner:s}=aA(e,i,r),c=vk(t,o,e.tool.armed);if(R(c)&&ce.refuses())return lA(e,a,c);let l=xk(c,e.tool.armed);if(c===`pan`||c===`rightPress`)return{kind:`pan`,start:n,camera:r,moved:!1,still:l,target:a};if(c===`note`||c===`zoom`)return{kind:c,start:n,current:n};if(c===`box`||c===`addBox`)return{kind:`box`,start:n,current:n,adds:c===`addBox`,still:l};if(a.kind===`label`)return uA(e,a.label,c,n,l);if(a.kind===`wire`)return pA(e,a.id,c,{world:i,point:n,still:l,...s===void 0?{}:{corner:s}},r);if(a.kind===`drawing`)return fA(e,a.id,c,n,l);if(a.kind===`text`)return dA(e,a.id,c,n);let u=a.kind===`part`?e.boxes.find(e=>e.name===a.name):void 0;if(u){if(c===`toggle`)e.onSelect(e=>e.toggle(u.name));else return c===`move`||c===`moveGroup`?gA(e,{part:u},c,n,l):void 0}}function lA(e,t,n){n!==`moveGroup`&&(t.kind===`part`?e.onSelect(e=>e.only(t.name)):t.kind===`label`?e.onSelect(e=>e.onlyLabel(t.label.id)):t.kind===`wire`?e.onSelect(e=>e.onlyWire(t.id)):t.kind===`drawing`?e.onSelect(e=>e.onlyDrawing(t.id)):t.kind===`text`&&e.onSelect(e=>e.onlyText(t.id)))}function uA(e,t,n,r,i){if(n===`toggle`)e.onSelect(e=>e.toggleLabel(t.id));else{if(n===`moveGroup`)return gA(e,{label:t.id},n,r,i);if(n===`label`)return e.onSelect(e=>e.onlyLabel(t.id)),{kind:`label`,label:t,start:r,at:t.at,moved:!1,blocker:e.labels?.blocker(t.id)??null}}}function dA(e,t,n,r){if(n===`toggle`){e.onSelect(e=>e.toggleText(t));return}let i=e.texts?.position(t);if(n===`text`&&i)return e.onSelect(e=>e.onlyText(t)),{kind:`text`,id:t,start:r,from:i,at:i,moved:!1,blocker:e.texts?.blocker(t)??null}}function fA(e,t,n,r,i){if(n===`toggle`)e.onSelect(e=>e.toggleDrawing(t));else return n===`move`||n===`moveGroup`?gA(e,{drawing:t},n,r,i):void 0}function pA(e,t,n,r,i){if(n===`toggle`)e.onSelect(e=>e.toggleWire(t));else return n===`moveGroup`?gA(e,{wire:t},n,r.point,r.still):oA.has(n)?sA(e,t,n,r,i):void 0}var mA={names:[],wires:[],labels:[],drawings:[]};function hA(e,t,n){if(n){let t=new Set(e.boxes.map(e=>e.name)),{names:n,wires:r,labels:i,drawings:a}=e.selection;return{names:n.filter(e=>t.has(e)),wires:r,labels:i,drawings:a}}if(`part`in t){let{name:n}=t.part;return e.onSelect(e=>e.only(n)),{...mA,names:[n]}}if(!(`drawing`in t))return mA;let{drawing:r}=t;return e.onSelect(e=>e.onlyDrawing(r)),{...mA,drawings:[r]}}function gA(e,t,n,r,i){let a=hA(e,t,n===`moveGroup`),o=a.names.filter(t=>e.blockerFor(t)===null),s=`part`in t?e.blockerFor(t.part.name):`drawing`in t?e.drawings?.blocker?.(t.drawing)??null:null,c=`drawing`in t?e.drawings?.origin?.(t.drawing):void 0;return{kind:`drag`,...t,...c?{origin:c}:{},...a,movable:o,start:r,offset:Ne,moved:!1,blocker:s,still:i}}function _A(e,t,n,r){if(t.kind===`pan`)return e.setCamera(xe(t.camera,t.start,n)),!t.moved&&Sk(t.start,n)?{...t,moved:!0}:void 0;if(t.kind===`box`||t.kind===`note`||t.kind===`zoom`)return{...t,current:n};if(!t.moved&&!Sk(t.start,n))return;let i=ye(r,e.size,n),a=ye(r,e.size,t.start),o={x:i.x-a.x,y:i.y-a.y};if(t.kind===`reshape`)return Ql(t,o,{step:e.step,snap:e.snap!==!1},t=>e.actions.notify(t));if(t.kind===`drag`&&t.drawing!==void 0&&t.blocker)return t.moved||e.actions.notify(t.blocker),t.moved?void 0:{...t,moved:!0};let s=t=>Te(t,e.step,e.snap!==!1);if(t.kind===`label`){let{at:e}=t.label;return{...t,moved:!0,at:{x:s(e.x+o.x),y:s(e.y+o.y)}}}if(t.kind===`text`)return{...t,moved:!0,at:{x:s(t.from.x+o.x),y:s(t.from.y+o.y)}};let{part:c}=t,l=c?e.anchors.get(c.name)?.origin??c.center:t.origin??Ne;return{...t,moved:!0,offset:{x:$k(s(l.x+o.x)-l.x),y:$k(s(l.y+o.y)-l.y)}}}function vA(e,t,n,r,i){if(t.kind===`label`)return t.moved?t.blocker?e.actions.notify(t.blocker):e.labels?.commit(t.label,t.at):void 0;if(t.kind===`text`)return t.moved?t.blocker?e.actions.notify(t.blocker):e.texts?.commit(t.id,t.at):void 0;if(t.kind===`drag`)return yA(e,t,r);if(t.kind===`reshape`)return eu(e.wires?.drag,t,t=>e.actions.notify(t));if(t.kind===`pan`){if(t.moved)return;t.still===`menu`&&e.onContextMenu(t.target,i),t.still===`disarm`&&e.tool.disarm()}else{if(t.kind===`box`)return SA(e,t,n);if(t.kind===`zoom`)return CA(e,t,n);wA(e,t,n)}}function yA(e,t,n){if(!t.moved)t.still===`selectAlone`&&e.onSelect(bA(t));else{if(t.blocker)return t.drawing===void 0?e.actions.notify(t.blocker):void 0;n(t.names,t.offset,t.wires,t.labels,t.drawings)}}function bA({part:e,wire:t,label:n,drawing:r}){return i=>e?i.only(e.name):t===void 0?r===void 0?n===void 0?i:i.onlyLabel(n):i.onlyDrawing(r):i.onlyWire(t)}function xA(e,t,n){return Math.abs(t.start.x-t.current.x)<Qk&&Math.abs(t.start.y-t.current.y)<Qk?void 0:[ye(n,e.size,t.start),ye(n,e.size,t.current)]}function SA(e,t,n){let r=xA(e,t,n);if(!r){t.still===`clear`&&e.onSelect(e=>e.clear());return}let i=Xa(t.start,t.current),a={parts:eo(e.boxes,r[0],r[1],i),wires:io(e.wires?.lines??[],r[0],r[1],i),labels:to(e.labels?.boxes??[],r[0],r[1],i),drawings:ak(e.drawings?.boxes??[],r[0],r[1],i),copper:hu(e.copper??[],r[0],r[1],i)};e.onSelect(ao(a,t.adds,e.tool.armed,e.layers,e.filter))}function CA(e,t,n){let r=xA(e,t,n);r&&(e.tool.disarm(),e.setCamera(dk(r[0],r[1],e.size)))}function wA(e,t,n){let r=xA(e,t,n);if(!r)return;let[i,a]=r;e.tool.disarm();let o=window.prompt(Me[e.view].notePrompt);o&&e.actions.mark(o,{view:e.view,x:$k((i.x+a.x)/2),y:$k((i.y+a.y)/2)})}function TA(e,t){return e.kind===`reshape`&&!t?.drag}var EA=new Set([`label`,`text`,`reshape`]),DA=e=>e!==void 0&&EA.has(e);function OA(e,t,n){return TA(e,n)?!0:t!==void 0&&(t===0||e.kind===`reshape`&&bk(t))}function kA(e,t){let n,r=[],i=e=>{n=e,t(e)};return{press(t,n){let{input:a}=e();r=[...r,a.selection.soleWire].slice(-2);let o=cA(a,t,n);o&&i(o)},wireBeforeDoubleClick:()=>r.length===2?r[0]:void 0,move(t,r){let{input:a}=e();if(!n||!a.camera)return!1;if(OA(n,r,a.wires))return i(void 0),!1;let o=_A(a,n,t,a.camera);return o&&i(o),!0},release(t){let r=n;i(void 0);let{input:a,commit:o}=e();r&&a.camera&&vA(a,r,a.camera,o,t)},cancel(){i(void 0)}}}function AA(e){let{actions:t,builtFrom:n}=e,[r,i]=(0,_.useState)();return(0,_.useEffect)(()=>i(e=>e&&e.sentAt>n?e:void 0),[n]),{pending:(0,_.useMemo)(()=>r&&r.sentAt>n?r:void 0,[r,n]),commit:(n,r,a=[],o=[],s=[])=>{if(r.x===0&&r.y===0)return;let{plan:c,lines:l,labels:u,drawings:d}=Zk(e,n,r,a,o,s),f=c.edits.length>0?{names:c.parts,offset:r,wires:l,labels:u,drawings:d,sentAt:Date.now()}:void 0;f&&i(f),U(c,t).then(e=>e||i(e=>e===f?void 0:e))}}}function jA(e,t){(0,_.useEffect)(()=>{if(!DA(e))return;let n=e=>{e.key===`Escape`&&(e.stopPropagation(),t())};return window.addEventListener(`keydown`,n,!0),()=>window.removeEventListener(`keydown`,n,!0)},[e,t])}function MA(e,t){let n=t?.kind===`drag`&&t.moved&&!t.blocker?t:void 0,{follow:r,circuit:i}=e;return(0,_.useMemo)(()=>{if(!n)return;if(!r)return{names:n.movable,offset:n.offset,wires:[]};let{lines:t,labels:i,drawings:a}=Zk(e,n.names,n.offset,n.wires,n.labels,n.drawings);return{names:n.movable,offset:n.offset,wires:t,labels:i,drawings:a}},[n,r,i])}function NA(e){let[t,n]=(0,_.useState)(),{pending:r,commit:i}=AA(e),a=(0,_.useRef)({input:e,commit:i});a.current={input:e,commit:i};let[o]=(0,_.useState)(()=>kA(()=>a.current,n)),s=MA(e,t)??r;jA(t?.kind,o.cancel),(0,_.useEffect)(()=>{t&&TA(t,e.wires)&&o.cancel()},[t,e.wires,o]);let{press:c,move:l,release:u,cancel:d,wireBeforeDoubleClick:f}=o;return{gesture:t,moving:s,pending:r,press:c,move:l,release:u,cancel:d,wireBeforeDoubleClick:f}}function PA(e,t,n){return e?.kind===`pan`&&(e.moved||e.still===`none`)?`grabbing`:e?.kind===`drag`||e?.kind===`label`||e?.kind===`text`||e?.kind===`reshape`?e.blocker?`not-allowed`:`move`:t||e?.kind===`note`||e?.kind===`zoom`?`crosshair`:n?`pointer`:`default`}function FA(e){let t=t=>sO(e.element.current,e.size,t);return{onPointerDown:n=>{if(!e.camera)return;n.currentTarget.setPointerCapture(n.pointerId);let r=t(n);e.tool?.(n,ye(e.camera,e.size,r))||e.gestures.press(n,r)},onPointerMove:n=>{if(!e.camera)return;let r=t(n),i=ye(e.camera,e.size,r);e.setCursor(i),e.gestures.move(r,n.buttons)||e.hover(i)},onPointerUp:n=>{e.camera&&e.toolRelease&&e.toolRelease(ye(e.camera,e.size,t(n))),e.gestures.release({x:n.clientX,y:n.clientY})},onPointerCancel:()=>e.gestures.cancel(),onLostPointerCapture:()=>e.gestures.cancel(),onDoubleClick:n=>{e.camera&&wk(n)&&e.open?.(ye(e.camera,e.size,t(n)))}}}function IA({selection:e,boxes:t,size:n,setCamera:r,notify:i}){Gx({fitSelection:()=>{let a=uk(t,e.names,n,ok);`camera`in a?r(a.camera):i(a.message)}})}var LA=`Drag a box where the note for the agent goes. Esc or a right click stops.`,RA=`Drag a box to zoom to it. Esc or a right click stops.`,zA=e=>e,BA=e=>e===`note`?LA:e===`zoom`?RA:void 0,VA=e=>e===`zoom`?`fitArea`:null;function HA(e,t){(0,_.useEffect)(()=>{if(!e)return;let n=e=>{Xd(Pd(e))&&(e.stopPropagation(),t())};return window.addEventListener(`keydown`,n,!0),()=>window.removeEventListener(`keydown`,n,!0)},[e,t])}function UA(e){let[t,n]=(0,_.useState)(null),r=(0,_.useCallback)(()=>n(null),[]),i=(0,_.useCallback)(t=>{e?.(),n(zA(t))},[e]);return Gx({noteBox:()=>i(`note`),fitArea:()=>i(`zoom`)}),HA(t!==null,r),{armed:t!==null,which:t,tool:t,arm:i,disarm:r,hint:BA(t)}}function WA(e,t){return t===void 0?`no net`:e.circuit.nets.find(e=>e.id===t)?.names[0]??t}function GA(e,t){let n=e.circuit.nets.find(e=>e.id===t);if(n)return{id:t,name:n.names[0]??t,width:Yg(e.rules,n),via:Qg(e.rules,n)}}function KA(e,t){let n=e.circuit.components.find(e=>e.id===t.component)?.pins.find(e=>e.id===t.pin),r=n?.names.find(e=>!/^pin\d+$/.test(e))??n?.names[0];return r?`${t.component}.${r}`:t.id}var qA=(e,t)=>t===void 0?{}:{net:t,netName:WA(e,t)};function JA(e,t,n){if(!iu({kind:`via`},e.visible))return;let r=e.copper.vias.find(e=>e.missingLayer===void 0&&Math.hypot(t.x-e.at.x,t.y-e.at.y)<=Math.max(e.diameter/2,n));return r&&{kind:`via`,id:r.id,at:r.at,...qA(e.design,r.net)}}function YA(e,t,n){let r=vp(e.design.pcb,t,n,e.visible);return r&&{kind:`pad`,id:r.id,label:KA(e.design,r),part:r.component,at:{x:r.x,y:r.y},...qA(e.design,r.net),layer:r.layers}}function XA(e,t,n,r){let[i,a]=[t.x-e.x,t.y-e.y],o=i*i+a*a,s=o===0?0:Math.max(0,Math.min(1,((n.x-e.x)*i+(n.y-e.y)*a)/o)),c={x:H(e.x+s*i),y:H(e.y+s*a)},l=a===0&&i!==0?`x`:i===0&&a!==0?`y`:void 0;if(!l||!r?.snap)return c;let u=Te(c[l],r.step);return u>=Math.min(e[l],t[l])&&u<=Math.max(e[l],t[l])?{...c,[l]:u}:c}function ZA(e,t,n,r,i){let a;for(let o of e.copper.tracks)if(!(r!==void 0&&o.layer!==r||!iu({kind:`track`,layer:o.layer},e.visible)))for(let e=1;e<o.points.length;e++){let r=XA(o.points[e-1],o.points[e],t,void 0),s=Math.hypot(r.x-t.x,r.y-t.y);s<=Math.max(o.width/2,n)&&(!a||s<a.d)&&(a={track:o,at:XA(o.points[e-1],o.points[e],t,i),d:s})}return a&&{kind:`track`,id:a.track.id,at:a.at,...qA(e.design,a.track.net),layer:a.track.layer}}function QA(e,t,n,r,i){return JA(e,t,n)??YA(e,t,n)??ZA(e,t,n,r,i)}var $A=(e,t)=>e.mark===void 0||t===void 0||t<=e.mark,ej=(e,t,n)=>[...e,{...n,id:t}],tj=(e,t,n)=>e.map(e=>e.id===t?{...e,mark:n}:e),nj=(e,t)=>e.filter(e=>e.id!==t),rj=(e,t)=>e.filter(e=>$A(e,t)),ij=e=>e.some(e=>e.mark===void 0);function aj(e,t){return rj(e,t).reduce((e,t)=>xb(e,t.shapes),ub)}function oj(e,t){return[...rj(e,t)].reverse().find(e=>e.parts!==void 0)?.parts}var sj=Math.PI/12,cj=.005,lj=.01,uj=.001,dj=2*uj,fj=1e-4,pj=.01,mj=1e6,hj=(e,t)=>({x:e.x-t.x,y:e.y-t.y}),gj=(e,t)=>({x:e.x+t.x,y:e.y+t.y}),_j=(e,t)=>({x:e.x*t,y:e.y*t}),vj=e=>Math.hypot(e.x,e.y),yj=e=>_j(e,1/vj(e)),bj=(e,t)=>e.x*t.y-e.y*t.x,xj=(e,t)=>e.x*t.x+e.y*t.y,Sj=e=>({x:Math.round(e.x*mj)/mj,y:Math.round(e.y*mj)/mj}),Cj=(e,t)=>Math.abs(e-t)<=fj+pj*Math.max(e,t),wj=(e,t)=>Math.abs(e-t)<=uj;function Tj(e){let t=e<=.005/2?Math.PI:2*Math.acos(1-cj/e);return Math.min(sj,t)}function Ej(e){return e.filter((t,n)=>n===0||t.x!==e[n-1]?.x||t.y!==e[n-1]?.y)}function Dj(e){return e.map((t,n)=>{let[r,i]=[e[n-1],e[n+1]];if(r===void 0||i===void 0)return 0;let[a,o]=[hj(t,r),hj(i,t)];return Math.atan2(bj(a,o),xj(a,o))})}function Oj(e,t,n,r){let[i,a]=[hj(t,e),hj(r,n)],o=bj(i,a);if(!(Math.abs(o)<1e-12))return gj(e,_j(i,bj(hj(n,e),a)/o))}function kj(e,t,n){let r=t[n];if(Math.abs(r)<=uj||Math.abs(r)>sj/2+uj)return;let i=n+1;for(;i<e.length-1&&wj(t[i],2*r);)i++;if(i>=e.length-1||!wj(t[i],r))return;let a=vj(hj(e[n+1],e[n]));for(let t=n+1;t<i;t++)if(!Cj(vj(hj(e[t+1],e[t])),a))return;let[o,s]=[e[n],e[i]],c=Oj(e[n-1],o,s,e[i+1]);if(c===void 0)return;let[l,u]=[hj(c,o),hj(s,c)];return xj(l,hj(o,e[n-1]))>0&&xj(u,hj(e[i+1],s))>0&&Cj(vj(l),vj(u))?{first:n,last:i,corner:c}:void 0}function Aj(e){let t=Dj(e),n=[];for(let r=1;r<e.length-1;r++){let i=kj(e,t,r);i&&(n.push(i),r=i.last)}return n}var jj=(e,t)=>Math.max(1,Math.ceil(e/Tj(t)-1e-9));function Mj(e,t,n,r,i){let a=Math.abs(i),o=r*Math.tan(a/2),[s,c]=[hj(e,_j(t,o)),gj(e,_j(n,o))],l=Math.sign(i),u=gj(s,_j({x:-t.y*l,y:t.x*l},r)),d=jj(a,r),f=hj(s,u);return[s,...Array.from({length:d-1},(e,t)=>{let n=l*a*(t+1)/d;return gj(u,{x:f.x*Math.cos(n)-f.y*Math.sin(n),y:f.x*Math.sin(n)+f.y*Math.cos(n)})}),c].map(Sj)}function Nj(e,t,n,r){let i=Ej(e),a=Math.max(t,n),o=Dj(i),s=new Set(Aj(i).flatMap(e=>Array.from({length:e.last-e.first+1},(t,n)=>e.first+n))),c=[i[0]],l=[],u=0;for(let t=1;t<i.length-1;t++){let[n,d,f]=[i[t],c.at(-1),i[t+1]],p=Math.abs(o[t]);if(s.has(t)||p/jj(p,a)/2<=dj){c.push(n);continue}let m=a*Math.tan(p/2),h=p<Math.PI-uj&&m+lj<=vj(hj(n,d))&&m+lj<=vj(hj(f,n))?Mj(n,yj(hj(n,i[t-1])),yj(hj(f,n)),a,o[t]):void 0,g=h?r?.(n,h):`too short`;h&&g===void 0?(c.push(...h),u++):(l.push({index:e.indexOf(n),at:n,reason:g??`too short`}),c.push(n))}return i.length>1&&c.push(i.at(-1)),{points:u===0?[...e]:c,rounded:u,square:l}}function Pj(e,t){let n=Ej(e),r=[],i=Aj(n).filter(e=>{let i=Sj(e.corner),a=t?.(i,n.slice(e.first,e.last+1));return a===void 0||void r.push({at:i,reason:a})});if(i.length===0)return{points:[...e],straightened:0,round:r};let a=[],o=0;for(let e of i)a.push(...n.slice(o,e.first),Sj(e.corner)),o=e.last+1;return a.push(...n.slice(o)),{points:a,straightened:i.length,round:r}}var Fj=[`45`,`45r`,`90`,`arc`],Ij={45:`45°`,"45r":`45° reversed`,90:`90°`,arc:`Arc`},Lj=e=>Ij[e];function Rj(e){return Fj[(Fj.indexOf(e)+1)%Fj.length]}var zj=(e,t)=>({x:H(e),y:H(t)});function Bj(e,t,n){let[r,i]=[t.x-e.x,t.y-e.y],a=Math.min(Math.abs(r),Math.abs(i)),[o,s]=[Math.sign(r),Math.sign(i)];return n?Math.abs(r)>Math.abs(i)?zj(e.x+o*(Math.abs(r)-a),e.y):zj(e.x,e.y+s*(Math.abs(i)-a)):zj(e.x+o*a,e.y+s*a)}function Vj(e,t,n,r=0){let[i,a]=[Math.abs(t.x-e.x),Math.abs(t.y-e.y)];return i===0||a===0||i===a?[t]:n===`90`?On([e,t]).slice(1):n===`arc`?Uj(e,t,r):[Bj(e,t,n===`45`),t]}var Hj=.98;function Uj(e,t,n){let r=On([e,t]),i=Hj*Math.min(Math.abs(t.x-e.x),Math.abs(t.y-e.y));return i<n/2?r.slice(1):Nj([e,...r.slice(1)],i,n).points.slice(1)}function Wj(e,t,n=0){let r=[e],i=e;for(let e of t)r.push(...Vj(i,e.to,e.mode,n)),i=e.to;return eb(r)}var Gj={top:`Top Layer`,bottom:`Bottom Layer`,inner1:`Inner Layer 1`,inner2:`Inner Layer 2`},Kj=e=>Gj[e],qj=e=>e===`top`?`bottom`:`top`;function Jj(e,t){if(e.kind===`pad`){if(t.locked.has(e.part))return{message:`${e.part} is locked: a track may not start on its pads. Unlock it first.`};let n=e.layer===`through`;return{start:{label:e.label,at:e.at,through:n},layer:e.layer===`through`?t.activeLayer:e.layer}}let n=`${e.kind} ${e.id}`;return e.kind===`via`?{start:{label:n,at:e.at,through:!0},layer:t.activeLayer}:e.layer!==`top`&&e.layer!==`bottom`?{message:`${n} is on ${Kj(e.layer)}, which cannot be routed yet`}:{start:{label:n,at:e.at,through:!1},layer:e.layer}}function Yj(e,t){let n=e.net===void 0?void 0:t.netOf(e.net),r=e.kind===`pad`?e.label:`${e.kind} ${e.id}`;if(!n)return{message:`${r} is on no net; connect it in the schematic first`};let i=Jj(e,t);return`message`in i?i:{route:{net:n,start:i.start,layer:i.layer,mode:t.mode??`45`,corners:[]}}}function Xj(e,t,n){if(!n.snap)return t;let r=r=>Math.abs(t[r]-e[r])<n.step/2?e[r]:Te(t[r],n.step);return{x:r(`x`),y:r(`y`)}}var Zj=e=>e.corners.at(-1)?.at??e.start.at,Qj=(e,t)=>e.x===t.x&&e.y===t.y;function $j(e,t){return Qj(t,Zj(e))?e:{...e,corners:[...e.corners,{at:t,mode:e.mode,layer:e.layer}]}}var eM=e=>({...e,mode:Rj(e.mode)});function tM(e,t=qj(e.layer)){return t===e.layer?e:e.corners.length===0&&!e.start.through?{message:`${e.start.label} is on the ${Kj(e.layer)} only; click a corner before changing layer`}:{...e,layer:t}}function nM(e){let t=e.corners.at(-1);return t?{...e,corners:e.corners.slice(0,-1),layer:t.layer}:e}function rM(e,t){let n=[...e.corners,{at:t,mode:e.mode,layer:e.layer}],{width:r,via:i}=e.net,a={tracks:[],vias:[]},o={layer:n[0]?.layer??e.layer,from:e.start.at,legs:[]},s=e.start.at,c=()=>{let e=Wj(o.from,o.legs.map(e=>({to:e.at,mode:e.mode})),r);e.length>=2&&a.tracks.push({layer:o.layer,width:r,points:e})};for(let e of n)e.layer!==o.layer&&(c(),a.vias.push({at:s,...i}),o={layer:e.layer,from:s,legs:[]}),o.legs.push(e),s=e.at;return c(),a}function iM(e,t){let n=t===void 0?{}:{net:t},r=t=>{let[r,i]=[e.tracks[t],e.vias[t]];return[...r?[{kind:`addTrack`,...n,layer:r.layer,width:r.width,points:r.points}]:[],...i?[{kind:`addVia`,...n,at:i.at,drill:i.drill,diameter:i.diameter,layers:[`top`,`bottom`]}]:[]]};return Array.from({length:Math.max(e.tracks.length,e.vias.length)},(e,t)=>r(t)).flat()}function aM(e,t){let n=t.kind===`pad`?t.label:t.kind===`track`?`Track ${t.id}`:`Via ${t.id}`;if(t.net!==e.net.id)return`${n} is on ${t.netName??`no net`}, but the track is on ${e.net.name}`;let r=t.kind===`via`?`through`:t.layer;if(r!==`through`&&r!==e.layer)return`${n} is on the ${Kj(r)}; press V to change layer first`}var oM=e=>e.kind===`pad`?e.label:`${e.kind} ${e.id}`;function sM(e,t){if(e.corners.length===0&&Qj(t.at,e.start.at))return;let n=aM(e,t);if(n)return{message:n};let r=rM(e,t.at);return{edits:iM(r,e.net.name),summary:`Route ${e.net.name} from ${e.start.label} to ${oM(t)}`,drawing:r}}function cM(e){let t=e.corners.at(-1);if(!t)return{message:`Click a corner first: a track needs two points. Esc drops it.`};let n=rM({...e,layer:t.layer},t.at);return{edits:iM(n,e.net.name),summary:`Route ${e.net.name} from ${e.start.label}, open at (${t.at.x}, ${t.at.y})`,drawing:n}}function lM(e,t,n,r=zg.via){if(e?.kind===`via`)return{message:`Via ${e.id} is already there`};let i=e?.net===void 0?void 0:n(e.net);return uM(e?e.at:t,i,r)}function uM(e,t,n=zg.via){let r=t?.via??n,i={tracks:[],vias:[{at:e,drill:r.drill,diameter:r.diameter}]},a=`at (${e.x}, ${e.y})`;return{edits:iM(i,t?.name),summary:t?`Add via on ${t.name} ${a}`:`Add via ${a}`,drawing:i}}var dM={route:`singleRouting`,via:`placeVia`},fM=12;function pM(){let[e,t]=(0,_.useState)(null),[n,r]=(0,_.useState)(null),[i,a]=(0,_.useState)(`45`);return{armed:e,setArmed:t,disarm:(0,_.useCallback)(()=>t(null),[]),route:n,setRoute:r,mode:i,setMode:a}}var mM=`new`;function hM(e){let t=e=>e.net===void 0?{}:{net:e.net};return{tracks:e.flatMap(e=>e.drawing.tracks.map(n=>({id:mM,...t(e),...n}))),vias:e.flatMap(e=>e.drawing.vias.map(n=>({id:mM,...t(e),at:n.at,diameter:n.diameter})))}}function gM(e,t){let[n,r]=(0,_.useState)([]),i=(0,_.useRef)(0);(0,_.useEffect)(()=>r(t=>rj(t,e)),[e]);let a=(0,_.useMemo)(()=>rj(n,e),[n,e]);return{drawings:(0,_.useMemo)(()=>a.map(e=>({drawing:e.drawing,alpha:_u})),[a]),copper:(0,_.useMemo)(()=>hM(a),[a]),send:(0,_.useCallback)((e,n)=>{i.current+=1;let a=i.current;r(t=>[...t,{id:a,drawing:e.drawing,...n===void 0?{}:{net:n}}]),t.editLayout(e.edits,e.summary).then(e=>r(t=>e.ok&&e.mark!==void 0?tj(t,a,e.mark):nj(t,a)))},[t])}}function _M(e,t){let n={tracks:[...e.copper.tracks,...t.tracks],vias:[...e.copper.vias,...t.vias]};return{design:e.design,copper:n,visible:e.layers}}function vM(e,t,n){let{design:r,actions:i,onActiveLayer:a,arm:o,onArm:s}=e,{route:c,setRoute:l}=o,u=(n,r=c===null)=>{if(!e.camera)return;let i=r?void 0:c?.layer??e.activeLayer;return QA(_M(e,t),n,fM/e.camera.scale,i,{step:e.step,snap:e.snap})},d=t=>{l(t),t.layer!==e.activeLayer&&a(t.layer)};return{input:e,route:c,setRoute:l,put:d,targetAt:u,start:t=>{let n=Yj(t,{activeLayer:e.activeLayer,locked:e.locked,netOf:e=>GA(r,e),mode:o.mode});if(`message`in n)return i.notify(n.message);d(n.route)},changeLayer:e=>{if(!c)return a(e);let t=tM(c,e);`message`in t&&i.notify(t.message),d(`message`in t?c:t)},arm:e=>{s(),l(null),o.setArmed(e)},cancel:()=>c?l(null):o.disarm(),send:n,stepCorner:()=>{let e=Rj(c?.mode??o.mode);o.setMode(e),c?d({...c,mode:e}):i.notify(`Routing corner: ${Lj(e)}`)}}}function yM(e){let{input:t,route:n}=e;if(!n)return;let r=cM(n);if(`message`in r)return t.actions.notify(r.message);e.setRoute(null),e.send(r,n.net.id)}function bM(e,t){let{input:n,route:r}=e,i=Pd(t),a=()=>{t.preventDefault(),t.stopPropagation()};if(Xd(i)&&(r||n.arm.armed))return a(),e.cancel();let o=Yd(i,{view:`pcb`,drawing:r!==null});if(o){if(o.action===`route`||o.action===`placeVia`){if(o.preventDefault&&t.preventDefault(),r)return;e.arm(o.action===`route`?`route`:`via`);let i=o.action===`route`&&n.cursor?e.targetAt(n.cursor):void 0;i&&e.start(i)}else{if(o.action===`switchLayer`)return a(),e.changeLayer(qj(r?.layer??n.activeLayer));if(o.action===`routingCorner`)return a(),e.stepCorner();if(o.action===`finishShape`)return r?(a(),yM(e)):void 0;!r||o.action!==`flipBend`&&o.action!==`removeCorner`||(a(),o.action===`flipBend`&&n.arm.setMode(eM(r).mode),e.put(o.action===`flipBend`?eM(r):nM(r)))}}}function xM(e){(0,_.useEffect)(()=>{let t=t=>bM(e.current,t);return window.addEventListener(`keydown`,t,!0),()=>window.removeEventListener(`keydown`,t,!0)},[e])}function SM(e,t,n){let{input:r}=e,i=e.targetAt(t,!0),a=lM(i,Ee(t,r.step,r.snap),e=>GA(r.design,e),$g(r.design.rules));if(`message`in a)return r.actions.notify(a.message);n(a,i?.net)}function CM(e,t,n){let{input:r,route:i}=e,a=e.targetAt(t);if(!i){a&&e.start(a);return}if(!a){let n=$j(i,Xj(Zj(i),t,r));return n===i&&i.corners.length>0?yM(e):e.put(n)}let o=sM(i,a);if(o){if(`message`in o)return r.actions.notify(o.message);e.setRoute(null),n(o,i.net.id)}}function wM(e,t,n,r){let{input:i}=e;return!i.arm.armed||t.button!==0?!1:(i.arm.armed===`via`?SM(e,n,r):CM(e,n,r),!0)}function TM(e,t){let{route:n,input:r}=e;if(n&&t)return rM(n,e.targetAt(t)?.at??Xj(Zj(n),t,r))}var EM=(e,t,n)=>e===`via`?`Via: click to place one; it takes the net of the pad or track under it. Esc to stop.`:e===`route`&&!t?`Single routing: click a pad, a track or a via to start a track on the ${Kj(n)}. Esc to stop.`:void 0;function DM(e){let{route:t,setRoute:n}=e.arm,r=gM(e.builtMark,e.actions),i=vM(e,r.copper,r.send),a=(0,_.useRef)(i);a.current=i,xM(a),Gx({singleRouting:()=>a.current.arm(`route`),placeVia:()=>a.current.arm(`via`),routingCorner:()=>a.current.stepCorner()});let{armed:o}=e.arm;(0,_.useEffect)(()=>{o!==`route`&&n(null)},[o,n]),(0,_.useEffect)(()=>{t&&t.layer!==e.activeLayer&&a.current.changeLayer(e.activeLayer)},[t,e.activeLayer]);let s=TM(i,e.cursor),c=s?[...r.drawings,{drawing:s,alpha:1}]:r.drawings,l=o?dM[o]:null;return{armed:o!==null,routing:t!==null,command:l,routes:c,status:t?yO(t.net.name,Kj(t.layer),t.net.width,Lj(t.mode)):void 0,hint:EM(o,t,e.activeLayer),press:(e,t)=>wM(a.current,e,t,r.send),cancel:()=>a.current.cancel()}}var OM;function kM(e){OM=e}function AM(){return OM}function jM(e,t,n){if(!t||n!==void 0&&n>t.mark)return e;let{filletRadius:r,...i}=e.rules.fabrication;return{...e,rules:{...e.rules,fabrication:t.radius===null?i:{...i,filletRadius:t.radius}}}}var MM=1e-6;function NM(e,t){return!(e>=t-MM)}function PM(e,t,n,r,i,a){let o=Xr(r),s={id:`${e}:${o.join(`,`)}`,code:e,severity:t,message:n,items:o,view:i};return a===void 0?s:{...s,at:a}}var FM=e=>e.toFixed(3),IM=e=>e>0?`${FM(e)} mm apart`:`touching or overlapping`;function LM(e,t,n,r,i){return{...PM(e,`error`,t,r,`pcb`,i),id:`${e}:${n.join(`|`)}`}}var RM=2,zM=(e,t)=>({minX:e.minX-t,minY:e.minY-t,maxX:e.maxX+t,maxY:e.maxY+t}),BM=([e,t])=>({x:(e.x+t.x)/2,y:(e.y+t.y)/2}),VM=(e,t)=>e.net!==void 0&&e.net===t.net;function HM(e,t){return e.flatMap(e=>e.shapes.map(n=>({piece:e,shape:n,box:bi(n),rank:t(e)})))}function UM(e,t){let n=[...new Set(e.map(e=>e.className))].sort(Yr);return n.flatMap(e=>n.map(n=>qg(t,e,n))).reduce((e,t)=>Math.max(e,t),t.fabrication.minClearance)}function WM(e,t){return t.piece===e.piece||VM(e.piece,t.piece)?!1:t.rank===-1||t.rank>e.rank}function GM(e,t){return Yr(e.piece.id,t.piece.id)<=0?[e,t]:[t,e]}function KM(e,t,n){let[r,i]=GM(t,n),a=`${r.piece.id}|${i.piece.id}`,o=_i(r.shape,i.shape),s=e.get(a);(s===void 0||o<s.distance)&&e.set(a,{a:r,b:i,distance:o})}function qM(e,t,n,r){let i=new eS(n);for(let t of e)i.insert(t,t.box);for(let n of e)if(n.rank!==-1)for(let e of i.query(zM(n.box,t)))WM(n,e)&&KM(r,n,e)}function JM({a:e,b:t}){if(e.piece.kind!==`pad`&&t.piece.kind!==`pad`)return uS(e.shape,t.shape);let[n,r]=e.piece.kind===`pad`?[e,t]:[t,e];return n.piece.net===void 0?!1:r.piece.kind===`track`?r.piece.pads?.includes(n.piece.id)??!1:r.shape.core.some(e=>uS(n.shape,{core:[e],radius:0}))}function YM(e,t,n){if(t===n)return t;let r=e.classClearance.find(e=>e.a===t&&e.b===n||e.a===n&&e.b===t);return r===void 0?`${t}–${n}`:`${r.a}–${r.b}`}function XM(e,t,n,r){return qg({...e,fabrication:{...e.fabrication,minClearance:0}},t,n)<r?`the fabrication minimum is ${FM(r)} mm`:`${YM(e,t,n)} needs ${FM(r)} mm`}var ZM=({a:e,b:t})=>e.piece.net!==void 0&&t.piece.net!==void 0&&e.piece.net!==t.piece.net;function QM(e,t){if(JM(e)&&!ZM(e))return;let{a:n,b:r,distance:i}=e,a=qg(t,n.piece.className,r.piece.className);return NM(i,a)?LM(`copper-clearance`,`${n.piece.id} and ${r.piece.id} are ${IM(i)}; ${XM(t,n.piece.className,r.piece.className,a)}`,[n.piece.id,r.piece.id],[n.piece.id,r.piece.id],BM(yi(n.shape,r.shape))):void 0}var $M=e=>t=>t.piece.layers.includes(e);function eN(e,t,n){if(e.length===0)return[];let r=new Map(e.map((e,t)=>[e,t])),i=[...HM(e,e=>r.get(e)??-1),...HM(t,()=>-1)],a=UM([...e,...t],n),o=Math.max(RM,a),s=new Map;for(let e of Zx){let t=i.filter($M(e));t.some(e=>e.rank!==-1)&&qM(t,a,o,s)}return[...s.keys()].sort(Yr).flatMap(e=>QM(s.get(e),n)??[])}var tN=e=>e===void 0?{}:{net:e};function nN(e){return e.layers===`through`?Zx:[e.layers]}function rN(e,t){let n=si(e);if(n===void 0)return;let r=e.net===void 0?zg.name:t(e.net);return{id:e.id,kind:`pad`,...tN(e.net),className:r,layers:nN(e),shapes:[n],at:{x:e.x,y:e.y}}}function iN(e){let t=e.width/2;return e.points.length===1?[{core:[e.points[0]],radius:t}]:e.points.slice(1).map((n,r)=>({core:[e.points[r],n],radius:t}))}function aN(e,t){let n=e.points[0]??{x:0,y:0};return{id:e.id,kind:`track`,...tN(e.net),className:t(e.net),layers:[e.layer],shapes:iN(e),at:n,pads:e.pads}}function oN(e,t){let n={core:[e.at],radius:e.diameter/2};return{id:e.id,kind:`via`,...tN(e.net),className:t(e.net),layers:[...sS(e)],shapes:[n],at:e.at}}function sN(e,t){return e.parts.flatMap(e=>e.pads).flatMap(e=>rN(e,t)??[])}function cN(e,t){let n=e=>e.missingLayer===void 0;return[...e.tracks.filter(n).map(e=>aN(e,t)),...e.vias.filter(n).map(e=>oN(e,t))].filter(e=>e.shapes.length>0).sort((e,t)=>Yr(e.id,t.id))}function lN(e,t){let n={distance:1/0,at:t[0]};for(let r of e)t.forEach((e,i)=>{let a={core:[e,t[(i+1)%t.length]],radius:0},o=_i(r,a);o<n.distance&&(n={distance:o,at:yi(r,a)[1]})});return n}function uN(e,t){return!mi(e,t)&&lN([{core:[e],radius:0}],t).distance>1e-6}function dN(e,t,n){let r=n.fabrication.boardEdgeClearance,i=(t,n)=>LM(`copper-edge`,t,[e.id],[e.id],n),a=e.shapes.flatMap(e=>e.core).find(e=>uN(e,t));if(a!==void 0)return i(`${e.id} ${e.kind===`track`?`runs`:`is`} outside the board`,a);let{distance:o,at:s}=lN(e.shapes,t);if(NM(o,r))return i(o>0?`${e.id} is ${FM(o)} mm from the board edge; the minimum is ${FM(r)} mm`:`${e.id} crosses the board edge; the minimum gap to it is ${FM(r)} mm`,s)}var fN=(e,t)=>e.layers===`all`||t.layers.includes(e.layers);function pN(e,t){let n=e.core.find(e=>mi(e,t));if(n!==void 0)return n;let r={core:[...t],radius:0};return _i(e,r)<-1e-6?yi(e,r)[1]:void 0}function mN(e,t){if(!fN(t,e))return;let n=e.shapes.map(e=>pN(e,t.outline)).find(e=>e!==void 0);if(n!==void 0)return LM(`copper-keepout`,`${e.id} lies inside ${t.id}`,[e.id,t.id],[e.id,t.id],n)}var hN=(e,t)=>e.minX<=t.maxX&&t.minX<=e.maxX&&e.minY<=t.maxY&&t.minY<=e.maxY,gN=(e,t)=>({minX:e.minX-t,minY:e.minY-t,maxX:e.maxX+t,maxY:e.maxY+t});function _N(e){return e.map(bi).reduce((e,t)=>({minX:Math.min(e.minX,t.minX),minY:Math.min(e.minY,t.minY),maxX:Math.max(e.maxX,t.maxX),maxY:Math.max(e.maxY,t.maxY)}))}function vN({layout:e,rules:t,classOf:n}){let r=[t.fabrication.minClearance,zg.clearance,...t.classes.map(e=>e.clearance),...t.classClearance.map(e=>e.clearance)];return{copper:cN(e,n),pads:sN(e,n),reach:Math.max(...r)}}var yN=(e,t)=>t.slice(1).map((n,r)=>({core:[t[r],n],radius:e.width/2}));function bN(e,t,n){let r=e.net===void 0?{}:{net:e.net};return{id:e.id,kind:`track`,...r,className:n(e.net),layers:[e.layer],shapes:yN(e,t),at:t[0],pads:e.pads}}var xN=(e,t)=>e.shapes.some(e=>t.some(t=>uS(e,t)));function SN(e,t,n,r){return e.some(e=>e.net===t.net&&xN(e,n)&&!xN(e,r.shapes))}function CN(e,t,n,r){let i=e.find(e=>e!==t.id)??``,a=n.find(e=>e.id===i);return a?.net===void 0?i:r.netName(a.net)}function wN(e,t){let n=t.layout.board;if(n===void 0)return;if(ti(n)&&dN(e,n.outline,t.rules))return`too close to the board edge`;let r={...e,shapes:e.shapes.map(e=>({...e,radius:e.radius+t.rules.fabrication.minClearance}))},i=n.keepouts.find(e=>e.outline.length>=3&&mN(r,e));return i?`too close to ${i.id}`:void 0}function TN(e,t,n){let r=e=>e.id!==n.id&&e.layers.includes(n.layer),[i,a]=[t.copper.filter(r),t.pads.filter(r)];return(r,o,s)=>{let c=bN(n,r,e.classOf),l=yN(n,o),u=gN(_N([...c.shapes,...l]),t.reach+n.width),d=e=>hN(_N(e.shapes),u),[f,p]=[i.filter(d),a.filter(d)];if(SN([...f,...p],n,l,c))return s;let m=eN([c,...f],p,e.rules).find(e=>e.items.includes(n.id));return m?`too close to ${CN(m.items,n,[...f,...p],e)}`:wN(c,e)}}var EN=(e,t)=>[t[0],e,t.at(-1)];function DN(e,t,n){let r=TN(e,t,n);return(e,t)=>r(t,EN(e,t),`joined on the corner's legs`)}function ON(e,t,n){let r=TN(e,t,n);return(e,t)=>r(EN(e,t),t,`joined on the arc`)}var kN=(e,t)=>`${e} ${t}${e===1?``:`s`}`;function AN(e,t){let n=t.ids===void 0?void 0:new Set(t.ids),r=e.pcb.tracks.filter(e=>e.missingLayer===void 0&&(n===void 0||n.has(e.id))),i=[],a=t.lockedParts?.size?mn(t.lockedParts,e.circuit.instances):void 0;return{tracks:r.filter(t=>{if(t.locked)return void i.push(`${t.id} is locked`);let n=t.points[0],r=n&&a?lS(e.pcb.parts,n,t.layer).find(e=>a.has(e.component))?.component:void 0;return r===void 0||void i.push(`${t.id} starts on the locked part ${r}`)}),skipped:i}}var jN=(e,t)=>[e,...t].join(`; `);function MN(e){let t=Wg(e.rules,e.circuit.nets).byNet,n=new Map(e.circuit.nets.map(e=>[e.id,e.names[0]??e.id]));return{layout:e.pcb,rules:e.rules,classOf:e=>e===void 0?zg.name:t.get(e)??zg.name,netName:e=>n.get(e)??e}}function NN(e,t={}){let{tracks:n,skipped:r}=AN(e,t);if(n.length===0)return{changes:[],summary:jN(`No tracks to round`,r)};let i=t.radius??e_(e.rules),a=MN(e),o=vN(a),s=[],c=[],[l,u]=[0,0];for(let e of n){let t=Nj(e.points,i,e.width,DN(a,o,e));t.rounded>0&&s.push({id:e.id,points:t.points}),l+=t.rounded,u+=t.square.length;for(let e of t.square)c.includes(e.reason)||c.push(e.reason)}return l===0&&u===0?{changes:s,summary:jN(`No square corners to round`,r)}:{changes:s,summary:jN(l===0?`No corner was rounded`:`Rounded ${kN(l,`corner`)} on ${kN(s.length,`track`)}`,[...u===0?[]:[`${u} left square: ${c.join(`, `)}`],...r])}}function PN(e,t={}){let{tracks:n,skipped:r}=AN(e,t),i=MN(e),a=vN(i),o=[],s=[],[c,l]=[0,0];for(let e of n){let t=Pj(e.points,ON(i,a,e));t.straightened>0&&o.push({id:e.id,points:t.points}),c+=t.straightened,l+=t.round.length;for(let e of t.round)s.includes(e.reason)||s.push(e.reason)}return c===0&&l===0?{changes:o,summary:jN(`No rounded corners to straighten`,r)}:{changes:o,summary:jN(c===0?`No corner was straightened`:`Straightened ${kN(c,`corner`)} on ${kN(o.length,`track`)}`,[...l===0?[]:[`${l} kept round: ${s.join(`, `)}`],...r])}}var FN={filletTracks:`Fillet`,straightenTracks:`Straighten`};function IN(e,t,n){let r=new Set(t.map(e=>e.id));if(n.total>0){let t=n.copper.filter(e=>r.has(e));return t.length>0?{ids:t}:{message:`Select tracks to ${FN[e].toLowerCase()}, or nothing for every track of the board.`}}if(t.length===0)return{message:`The board has no tracks.`};let i=t.length===1?`the board's one track`:`all ${t.length} tracks of the board`;return{confirm:`${FN[e]} ${i}?`}}function LN(e,t,n,r){let i={...n?{ids:n}:{},lockedParts:r},a=e===`filletTracks`?NN(t,i):PN(t,i);if(a.changes.length===0)return{message:a.summary};let o=a.changes.map(e=>({kind:`setTrack`,id:e.id,points:e.points})),s=new Map(a.changes.map(e=>[e.id,e.points]));return{edits:o,summary:a.summary,shapes:{tracks:s,vias:new Map}}}function RN(e,t){if(e.busy())return e.notify(`Wait for the last copper change to land, then try again.`);let n=jM(e.design,AM(),e.builtMark),r=IN(t,n.pcb.tracks.filter(e=>e.missingLayer===void 0),e.selection);if(`message`in r)return e.notify(r.message);if(r.confirm!==void 0&&!window.confirm(r.confirm))return;let i=LN(t,n,r.ids,e.lockedParts);if(`message`in i)return e.notify(i.message);e.send(i),e.notify(i.summary)}function zN(e){let t=(0,_.useRef)(e);t.current=e,Gx({filletTracks:()=>RN(t.current,`filletTracks`),straightenTracks:()=>RN(t.current,`straightenTracks`)}),(0,_.useEffect)(()=>{let e=e=>{if(t.current.routing||e.repeat)return;let n=Yd(Pd(e),{view:`pcb`})?.action;(n===`filletTracks`||n===`straightenTracks`)&&(e.preventDefault(),RN(t.current,n))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[])}function BN(e){let t=e.withoutTexts(e.texts);return t.total===0&&e.total>0?void 0:t}var VN=`Deleted in two changes: the copper in the layout file, the rest in the circuit file.`;function HN(e,t){if(!t)return{copper:[],rest:e};let n=e.withoutCopper(e.copper);return{copper:e.copper,rest:n.total===0?void 0:n}}function UN(e,t,n){return e>0?{removeCopper:!0,notice:t}:n?{removeCopper:!1}:{removeCopper:!1,notice:t}}var WN=`Select a part or a wire first.`,GN=e=>[...new Set(e)];function KN(e,t){let n=e?.withWires.filter(e=>t.has(e.wire)).map(e=>e.label)??[];return new Set([...e?.withParts??[],...n])}function qN(e,t,n,r,i,a){if(e.total===0)return{message:WN};let o=bt(e.names,t),s=new Set(o.parts),c=r&&e.labelCount>0?r(e.labels,s):void 0,l=GN([...e.wires,...c?.withWires.map(e=>e.wire)??[]]),u=n&&l.length>0?n(l,s,new Set(o.skipped)):void 0,d=GN([...e.drawings,...u?.junctions??[]]),f=i&&d.length>0?i(d):void 0,p=a&&e.boardCount>0?a(e.board):void 0,m={edits:[...u?.edits??[],...f?.edits??[],...p?.edits??[],...o.edits],summary:`remove ${st([...o.parts,...ct(u?.names??[]),...f?.names??[],...p?.names??[]])}`,parts:o.parts,skipped:[...o.skipped,...u?.skipped??[],...c?.skipped??[],...f?.skipped??[],...p?.skipped??[]],done:`removed`},h=new Set([...u?.removed??[],...u?.withParts??[]]),g=KN(c,h);return{plan:m,wires:e.wires.filter(e=>h.has(e)),labels:e.labels.filter(e=>g.has(e)),drawings:f?.removed??[],board:p?.removed??[],...o.parts.length>0?{question:xt(o.parts,(u?.removed??[]).filter(t=>e.hasWire(t)).length)}:{}}}var JN=new Set;function YN(e){return JN.add(e),()=>{JN.delete(e)}}function XN(e){for(let t of JN)t(e);return e}var ZN=e=>(e.minX+e.maxX)/2,QN=e=>(e.minY+e.maxY)/2,$N=e=>e.maxX-e.minX,eP=e=>e.maxY-e.minY;function tP(e,t,n,r){let i=new Map;for(let{name:a,box:o}of e){let e=H(n(o)-r(o));e!==0&&i.set(a,t===`x`?{x:e,y:0}:{x:0,y:e})}return i}function nP(e,t){let[n,r,i]=t===`x`?[`minX`,`maxX`,$N]:[`minY`,`maxY`,eP],a=[...e].sort((e,t)=>e.box[n]-t.box[n]||e.name.localeCompare(t.name)),o=a[0],s=a.slice(1).reduce((e,t)=>!e||t.box[r]>e.box[r]?t:e,void 0);if(!o||!s||a.length<3)return new Map;let c=(s.box[r]-o.box[n]-a.reduce((e,{box:t})=>e+i(t),0))/(a.length-1),l=new Map,u=o.box[r];for(let{name:e,box:r}of a.slice(1).filter(e=>e!==s)){let a=H(u+c-r[n]);a!==0&&l.set(e,t===`x`?{x:a,y:0}:{x:0,y:a}),u+=c+i(r)}return l}function rP(e,t){let n=ke(t.map(e=>e.box));if(!n)return new Map;switch(e){case`alignLeft`:return tP(t,`x`,()=>n.minX,e=>e.minX);case`alignRight`:return tP(t,`x`,()=>n.maxX,e=>e.maxX);case`alignTop`:return tP(t,`y`,()=>n.maxY,e=>e.maxY);case`alignBottom`:return tP(t,`y`,()=>n.minY,e=>e.minY);case`alignHCentres`:return tP(t,`y`,()=>QN(n),QN);case`alignVCentres`:return tP(t,`x`,()=>ZN(n),ZN);case`distributeH`:return nP(t,`x`);case`distributeV`:return nP(t,`y`)}}var iP={alignLeft:`align {} left`,alignRight:`align {} right`,alignTop:`align {} top`,alignBottom:`align {} bottom`,alignHCentres:`align {} horizontal centres`,alignVCentres:`align {} vertical centres`,distributeH:`distribute {} horizontally`,distributeV:`distribute {} vertically`};function aP(e,t,n){return iP[e].replace(`{}`,st(t))+Me[n].where}function oP(e,t,n,r,i){let[a,o]=Me[n].position,[s,c]=Re(e,t,n,ft(r.anchors,r.boxes)(t),i);return{[a]:s,[o]:c}}function sP(e,t,n,r,i,a){let o=_t(r),s=r.boxes.filter(e=>t.includes(e.name)),c=new Set(s.map(e=>e.name)),l=t.filter(e=>!c.has(e)).map(e=>`${e} ${o(e)?`has no box in`:`is not in`} this view`),u=D(i);if(s.length<u){let e=l.length>0?` (${l.join(`; `)})`:``;return{message:`${u===2?`Align`:`Distribute`} needs ${u} or more parts in this view${e}.`}}let d=rP(i,s),f=i.startsWith(`distribute`)?` and kept its place; others may overlap it`:``,p=[...d.keys()].flatMap(e=>{let t=a(e);return t===null?[]:`${t}${f}`}),m=s.map(e=>e.name).filter(e=>d.has(e)&&a(e)===null),h=[...l,...p];return m.length===0?{message:h.length>0?`Nothing moves. ${h.join(`; `)}.`:`The parts are already there.`}:{edits:m.map(t=>({kind:`setProps`,part:t,props:oP(e,t,n,r,d.get(t))})),summary:aP(i,m,n),parts:m,skipped:h,done:`moved`}}function cP(e,t,n,r=[],i=[]){return{parts:t.edits.flatMap(t=>{if(t.kind!==`setProps`)return[];let{schX:n,schY:r}=t.props;if(typeof n!=`number`||typeof r!=`number`)return[];let i=e.circuit.components.find(e=>e.id===t.part)?.groupOffset.sch??Ne;return[{name:t.part,to:{x:H(n+i.x),y:H(r+i.y)}}]}),wires:n,...r.length>0?{labels:r}:{},...i.length>0?{drawings:i}:{}}}function lP(e,t){let n=e.parts.find(e=>t.has(e.name)),r=n&&t.get(n.name)?.origin,i=n&&r?{x:H(n.to.x-r.x),y:H(n.to.y-r.y)}:Ne,{labels:a,drawings:o}=e;return{names:e.parts.map(e=>e.name),offset:i,wires:e.wires,...a?{labels:a}:{},...o?{drawings:o}:{}}}var uP=e=>`${e.x},${e.y}`;function dP(e,t,n,r){let i=t.get(e.id),a=i?.[i.length-1];return i&&a?a.x===e.at.x&&a.y===e.at.y?void 0:{at:a,side:Br(i[i.length-2],a)}:n.has(uP(e.at))&&(r.x!==0||r.y!==0)?{at:{x:H(e.at.x+r.x),y:H(e.at.y+r.y)},side:e.side}:void 0}function fP(e,t){if(!t)return e.labels;let n=new Set(e.symbols.filter(e=>t.names.includes(e.component)).flatMap(e=>Object.values(e.pinEnds).map(uP))),r=new Map((t.wires??[]).map(e=>[`label:${e.id.slice(5)}`,e.points])),i=e.labels.map(e=>dP(e,r,n,t.offset));return i.every(e=>e===void 0)?e.labels:e.labels.map((e,t)=>({...e,...i[t]}))}function pP(e,t){e.gate.held||(e.queue=[]);let n=e.gate.held!==void 0||e.arrows!==void 0;n!==e.told&&(e.told=n,t.holding(n))}function mP(e,t,n,r){let i=e.gate.waiting;n.edits.length>0&&(e.gate=NO(e.gate));let{seq:a}=e.gate;return wt(n,r.actions).then(({ok:r,mark:o})=>(n.edits.length>0&&(e.gate=PO(e.gate,r,a,i,o)),pP(e,t),t.resolved(),r))}function hP(e,t,n,r){let i=vt(n.circuit,n.selection.names,n.view,n.layout,n.blockerFor,r);if(`message`in i)return n.actions.notify(i.message);mP(e,t,i,n)}function gP(e,t,n,r){let i=sP(n.circuit,n.selection.names,n.view,n.layout,r,n.blockerFor);if(`message`in i)return n.actions.notify(i.message);mP(e,t,Xk(i,n.circuit,n.follow),n)}function _P(e,t,n,r){r===`rotate`?hP(e,t,n,90):r===`rotateRight`?hP(e,t,n,-90):gP(e,t,n,r)}function vP(e,t,n,r,i){let a=jO(e.gate,n.selection.names,i,n);e.gate=a.gate,a.send?_P(e,t,n,r):i||(e.queue=(e.gate.held?.count??0)>1?[...e.queue,r]:[r]),pP(e,t)}function yP(e,t,n,r){let{burst:i,layout:a}=e;if(!i||!a)return;let o=yt(i.base,i.names,n.view,a,r,n.blockerFor),s={wires:i.wires??[],labels:i.labels??[],drawings:i.drawings??[],offset:r},{plan:c,lines:l,labels:u,drawings:d}=Yk(o,i.base,n.follow,s),f=mP(e,t,c,n);n.follow&&c.edits.length>0&&t.moved?.(cP(n.follow.design,c,l,u,d),f),f.then(r=>{if(e.burst!==i&&e.burst?.base!==i.base)return;let a=e.burst?DO(e.burst,r):void 0;e.burst=a?.burst,a?.send&&yP(e,t,n,a.send)})}function bP(e,t,n,r){let{names:i,wires:a,labels:o,drawings:s}=n.selection,c=EO(e.burst,n.circuit,i,r,a,o,s);e.burst=c.burst,c.fresh&&(e.layout=n.layout),c.send&&yP(e,t,n,c.send)}function xP(e,t,n){let r={waiting:e.gate.waiting,history:e.gate.history};e.gate=FO(e.gate),e.burst=void 0;let{seq:i}=e.gate;n.catch(()=>({ok:!1})).then(({ok:n,mark:a})=>{e.gate=IO(e.gate,n,i,r,a),pP(e,t),t.resolved()})}function SP(e){let t={gate:OO,told:!1,queue:[]};return{nudge(n,r){let i=Od(r.action);if(!i||n.selection.total===0)return;let a=pt(i,n.layout.step,r.steps??1,n.layout.snap!==!1),o=LO(t.gate,n);t.gate=o.gate,o.send?bP(t,e,n,a):t.arrows=RO(t.arrows,n.selection.names,a,n.selection.wires,n.selection.labels,n.selection.drawings),pP(t,e)},rotate(n,r){vP(t,e,n,`rotate`,r)},rotateRight(n){vP(t,e,n,`rotateRight`,!1)},align(n,r){vP(t,e,n,r,!1)},settle(n){let r=MO(t.gate,n.selection.names,n);t.gate=r.gate,r.send&&_P(t,e,n,t.queue.shift()??`rotate`);let{names:i,wires:a,labels:o,drawings:s}=n.selection,c=zO(t.gate,t.arrows,i,n,a,o,s);t.gate=c.gate,t.arrows=c.held,c.send&&bP(t,e,n,c.send),pP(t,e)},historyWrite:n=>xP(t,e,n)}}function CP(e){let[t,n]=(0,_.useState)(0),[r,i]=(0,_.useState)(!1),[a,o]=(0,_.useState)(),[s]=(0,_.useState)(()=>SP({resolved:()=>n(e=>e+1),holding:i,moved:(e,t)=>{let n={...e,sentAt:Date.now()};o(n),t.then(e=>e||o(e=>e===n?void 0:e))}})),{builtMark:c,buildStatus:l,moveWaiting:u,circuit:d}=e;return(0,_.useEffect)(()=>YN(e=>s.historyWrite(e)),[s]),(0,_.useEffect)(()=>s.settle(e),[s,c,l,u,d,t]),{edits:s,held:r,moved:a}}function wP(e,t){let n=BN(e.selection);if(e.paused||!n)return;let{copper:r,rest:i}=HN(n,e.copper!==void 0),a=()=>r.length>0?e.copper?.remove(r):void 0;if(!i)return a();let o=qN(i,e.blockerFor,e.wire?.removal,e.wire?.labelRemoval,e.drawings,e.board);if(`message`in o){let n=UN(r.length,o.message,t);return n.removeCopper&&a(),n.notice===void 0?void 0:e.actions.notify(n.notice)}let{plan:s,wires:c,labels:l,drawings:u,board:d,question:f}=o;if(f&&!window.confirm(f))return;a();let p=e=>e.without(s.parts).withoutWires(c).withoutLabels(l).withoutDrawings(u).withoutBoard(d);U(s,e.actions).then(t=>{t&&(e.onSelect(p),r.length>0&&e.actions.notify(VN))})}function TP(e,t,n){let r=e.texts&&jf(e.selection,t,e.layout);if(!r)return n.nudge(e,t);e.texts?.nudge(r.id,r.by)}function EP(e,t,n,r){let{action:i}=t;if(E(i))return e.paused||r?void 0:n.align(e,i);if(i.startsWith(`nudge`))return e.paused?void 0:TP(e,t,n);if(i===`fit`)return e.fit();if(i===`delete`)return wP(e,!0);if(i===`contextMenu`){if(e.paused)return;let{target:t,at:n}=e.menuPlace();return e.onContextMenu(t,n)}if(i===`highlight`){let t=e.netUnderPointer();t!==void 0&&e.onHighlight([t])}else i===`rotate`&&e.selection.size>0&&!e.paused&&n.rotate(e,r)}function DP(e){let t=Ap(e.selection,t=>e.wire?.net(t),e.netsOf,t=>e.wire?.labelNet(t));`nets`in t?e.onHighlight(t.nets):e.actions.notify(t.message)}function OP(e,t){let n=t=>()=>{e.paused||(e.selection.size>0?t(e):e.actions.notify(`Select a part first.`))};Gx({...Object.fromEntries(w.map(n=>[n,()=>e.paused?void 0:t.align(e,n)])),fit:e.fit,rotate:n(e=>t.rotate(e,!1)),rotateRight:n(e=>t.rotateRight(e)),delete:()=>wP(e,!1),highlight:()=>DP(e)})}function kP(e){let{edits:t,held:n,moved:r}=CP(e);OP(e,t);let{view:i,selection:a,paused:o,circuit:s,actions:c,onSelect:l,blockerFor:u,layout:d,builtMark:f,buildStatus:p,moveWaiting:m,fit:h,netUnderPointer:g,netsOf:v,onHighlight:y,menuPlace:b,onContextMenu:x,wire:S,drawings:C,board:w,follow:T,copper:E,texts:D}=e;return(0,_.useEffect)(()=>{let e={view:i,selection:a,paused:o,circuit:s,actions:c,onSelect:l,blockerFor:u,layout:d,builtMark:f,buildStatus:p,moveWaiting:m,fit:h,netUnderPointer:g,netsOf:v,onHighlight:y,menuPlace:b,onContextMenu:x,wire:S,drawings:C,board:w,follow:T,copper:E,texts:D},n=n=>{let r=Yd(Pd(n),{view:i,drawing:o});r&&(VO(r.action,a.size,o,r.preventDefault,a.total)&&n.preventDefault(),EP(e,r,t,n.repeat))};return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[t,i,a,o,s,c,l,u,d,f,p,m,h,g,v,y,b,x,S,C,w,T,E,D]),{rotateHeld:n,keyMove:r}}var AP={x:0,y:0};function jP(e,t,n){let r={id:e.id,start:n.point,moved:!1,offset:AP};if(e.kind===`via`){let n=t.vias.find(t=>t.id===e.id);return n&&{...r,kind:`via`,at:n.at,blocker:n.locked?`${n.id} is locked`:null}}let i=t.tracks.find(t=>t.id===e.id),a=i&&fu(i.points,n.world,n.scale,n.sole,n.width);if(i&&a)return{...r,kind:`track`,grip:a,points:i.points,world:n.world,blocker:i.locked?`${i.id} is locked`:null}}function MP(e,t){return e.kind===`track`&&e.grip?.kind===`segment`&&t?.id===e.id&&t.index===e.grip.index?{...e,segment:t.index}:e}function NP(e){if(e.kind!==`track`||e.segment===void 0)return;let{id:t}=e;if(!e.moved)return e=>e.onlyCopper(t);if(!e.path||!e.world||!e.last)return;let n=qc(e.path,{x:e.world.x+e.last.x,y:e.world.y+e.last.y})?.index,r=n===void 0?void 0:po({id:t,points:e.path},n);return r&&(e=>e.onlySegment(r))}function PP(e){let{id:t=``,part:n,names:r,copper:i,start:a,origin:o}=e;return{kind:`group`,id:t,start:a,moved:!1,blocker:null,offset:AP,names:r,copper:i,...n===void 0?{}:{part:n},...o?{origin:o}:{}}}function FP(e,t,n){let r=e=>Te(e,n.step,n.snap);return{x:H(r(e.x+t.x)-e.x),y:H(r(e.y+t.y)-e.y)}}function IP(e,t,n,r){return e.blocker?(e.moved||r(e.blocker),{...e,moved:!0}):e.kind===`track`&&e.points&&e.grip?{...e,moved:!0,last:t,path:ab(e.points,e.grip,t,n)}:{...e,moved:!0,offset:FP(e.at??e.origin??AP,t,n)}}var LP=e=>e.kind===`group`?e.copper??[]:[e.id];function RP(e,t,n){return!e.moved||e.blocker?ub:e.kind===`track`?e.path?{tracks:new Map([[e.id,e.path]]),vias:new Map}:ub:_b(t,LP(e),e.offset,n).shapes}function zP(e){let t=e.offset.x!==0||e.offset.y!==0;return e.kind===`group`&&e.moved&&t&&(e.names?.length??0)>0?{names:e.names??[],offset:e.offset}:void 0}function BP(e,t,n){if(!e.moved||e.blocker)return;if(e.kind===`track`){let r=t.tracks.find(t=>t.id===e.id),i=r&&e.path?vb(r,e.path):void 0;return!i||`message`in i?i:{edits:[i],summary:`Reshape track ${e.id}`,shapes:RP(e,t,n)}}let r=LP(e),i=_b(t,r,e.offset,n);if(i.edits.length===0)return i.skipped.length>0?{message:i.skipped.join(`; `)}:void 0;let a=i.shapes.vias.get(e.id)??AP,o=e.kind===`group`?`Move ${st(r)} by (${e.offset.x}, ${e.offset.y})`:`Move via ${e.id} to (${a.x}, ${a.y})`;return{edits:i.edits,summary:o,shapes:i.shapes}}function VP(e,t){let[n,r]=(0,_.useState)([]),i=(0,_.useRef)(0);(0,_.useEffect)(()=>r(t=>rj(t,e)),[e]);let a=(0,_.useMemo)(()=>aj(n,e),[n,e]),o=(0,_.useMemo)(()=>oj(n,e),[n,e]),s=(0,_.useCallback)((e,t)=>{i.current+=1;let n=i.current;r(t=>ej(t,n,e)),t.then(e=>r(t=>e.ok&&e.mark!==void 0?tj(t,n,e.mark):nj(t,n)))},[]);return{shapes:a,moving:o,send:(0,_.useCallback)(e=>s({shapes:e.shapes},t.editLayout(e.edits,e.summary)),[s,t]),sendParts:(0,_.useCallback)((e,t)=>s({shapes:ub,parts:e},t),[s]),inFlight:ij(n)}}function HP(e){return(t,n)=>{let r=Xf(e.pcb,t);return r!==void 0&&(r.layers===`through`||r.layers===n)}}function UP(e){(0,_.useEffect)(()=>{let t=t=>{let{input:n,shown:r,onPad:i,send:a,cancel:o,inFlight:s}=e.current;if(t.key===`Escape`&&o())return t.stopPropagation();let{copper:c}=n.selection;if(!wb(n.selection,n.routing===!0))return;let l=Yd(Pd(t),{view:`pcb`}),u=l&&Od(l.action);if(!l||!u||(t.preventDefault(),t.stopPropagation(),t.repeat&&s))return;let d=pt(u,n.step,l.steps??1,n.snap),f=_b(r,c,d,i);f.skipped.length>0&&n.actions.notify(`Not moved: ${f.skipped.join(`; `)}`),f.edits.length>0&&a({edits:f.edits,summary:`Move ${st(c)} by (${d.x}, ${d.y})`,shapes:f.shapes})};return window.addEventListener(`keydown`,t,!0),()=>window.removeEventListener(`keydown`,t,!0)},[e])}function WP(e,t,n,r){let{camera:i,selection:a}=e;if(!i||r.button!==0||e.armed===`note`||e.armed===`zoom`)return;let o=uu(t,n,i.scale,e.layers,{selection:a,armed:e.armed,filter:e.filter});if(!o)return GP(e,n,r);if(yo(r))return e.onSelect(e=>e.toggleCopper(o.id)),`toggled`;if(a.hasCopper(o.id)&&a.total>1)return PP({id:o.id,names:a.names,copper:a.copper,start:n});let s=a.soleCopper===o.id,c=t.tracks.find(e=>e.id===o.id)?.width??0,l=jP(o,t,{world:n,point:n,scale:i.scale,sole:s,width:c}),u=l&&MP(l,a.segment);return u?.segment===void 0&&e.onSelect(e=>e.onlyCopper(o.id)),u??`toggled`}function GP(e,t,n){let{selection:r,parts:i}=e;if(r.copper.length===0||yo(n))return;let a=i.selectedAt(t);if(a!==void 0&&i.blockerFor(a)===null)return PP({part:a,names:r.names,copper:r.copper,start:t,origin:i.originOf(a)})}function KP(e,t,n){let r=bb(t.tracks.find(e=>e.id===n.id),n);if(`message`in r)return e.actions.notify(`Not removed: ${r.message}`);e.actions.editLayout(r.edits,r.summary).then(t=>t.ok&&e.onSelect(e=>e.withoutCopper([n.id])))}function qP(e,t,n){let{segment:r}=e.selection;if(r&&n.length===1&&n[0]===r.id)return KP(e,t,r);let{edits:i,removed:a,skipped:o}=yb(t,n);o.length>0&&e.actions.notify(`Not removed: ${o.join(`; `)}`),i.length!==0&&e.actions.editLayout(i,`Remove ${st(a)}`).then(t=>t.ok&&e.onSelect(e=>e.withoutCopper(a)))}function JP(e){let{design:t,builtMark:n,actions:r,selection:i}=e,a=VP(n,r),o=(0,_.useMemo)(()=>Sb(t.pcb,a.shapes),[t,a.shapes]),s=(0,_.useMemo)(()=>HP(t),[t]),[c,l]=(0,_.useState)(),[u,d]=(0,_.useState)(),f=(0,_.useRef)(void 0),p=e=>{f.current=e,l(e)},m={input:e,shown:o,onPad:s,send:a.send,sendParts:a.sendParts,cancel:()=>f.current?(p(void 0),!0):!1,inFlight:a.inFlight},h=(0,_.useRef)(m);h.current=m,UP(h),YP(o.tracks,i,e.onSelect);let g=(0,_.useMemo)(()=>c?Sb(o,RP(c,o,s)):o,[c,o,s]);return{scene:{tracks:g.tracks,vias:g.vias,selected:new Set(i.copper),...i.segment?{segment:i.segment}:{},...u===void 0?{}:{hover:u}},shown:o,drag:c,hover:u,setHover:d,put:p,dragRef:f,latest:h,keys:(0,_.useMemo)(()=>({remove:e=>qP(h.current.input,h.current.shown,e)}),[]),moving:(0,_.useMemo)(()=>XP(c,e.parts)??a.moving,[c,e.parts,a.moving])}}function YP(e,t,n){let r=vo(t,e)!==t;(0,_.useEffect)(()=>{r&&n(t=>vo(t,e))},[r,e,n])}function XP(e,t){let n=e&&zP(e);return n&&{names:n.names.filter(e=>t.blockerFor(e)===null),offset:n.offset}}function ZP(e,t){let{input:n,shown:r}=e.latest.current,i=n.camera&&uu(r,t,n.camera.scale,n.layers,{selection:_o.none,armed:n.armed,filter:n.filter});return i?i.id:void 0}function QP(e,t){let{input:n,shown:r}=e.latest.current;return n.camera&&du(r,t,n.camera.scale,n.layers,{selection:n.selection,armed:n.armed,filter:n.filter})}function $P(e,t){let n=ZP(e,t);return e.setHover(n),n!==void 0}function eF(e){return(t,n)=>{let{input:r,shown:i}=e.latest.current,a=WP(r,i,n,t);return a&&a!==`toggled`&&e.put(a),a!==void 0}}function tF(e,t,n){let{input:r}=e.latest.current,i={x:n.x-t.start.x,y:n.y-t.start.y};!t.moved&&Math.hypot(i.x,i.y)*(r.camera?.scale??1)<3||e.put(IP(t,i,{step:r.step,snap:r.snap},e=>r.actions.notify(e)))}function nF(e,t){e.put(void 0);let{input:n,shown:r,onPad:i,send:a,sendParts:o}=e.latest.current;if(t.kind===`group`&&!t.moved)return n.onSelect(rF(t));let s=NP(t);s&&n.onSelect(s);let c=zP(t);c&&o(c,n.parts.move(c.names,c.offset));let l=BP(t,r,i);l&&(`message`in l?n.actions.notify(l.message):a(l))}function rF(e){return t=>e.part===void 0?e.id?t.onlyCopper(e.id):t:t.only(e.part)}function iF(e,t,n){let r=t=>{let{input:n}=e.latest.current;return n.camera?ye(n.camera,n.size,sO(n.canvas.current,n.size,t)):void 0};return{...t,onPointerMove:i=>{let a=e.dragRef.current,o=a&&r(i);if(!a||!o)return t.onPointerMove(i);if(n(o),i.buttons===0)return void e.put(void 0);ce.refuses()||tF(e,a,o)},onPointerUp:n=>{let r=e.dragRef.current;r?nF(e,r):t.onPointerUp(n)},onPointerCancel:()=>{e.put(void 0),t.onPointerCancel()},onLostPointerCapture:()=>{e.put(void 0),t.onLostPointerCapture()}}}function aF(e){return e.drag?e.drag.blocker?`not-allowed`:`move`:e.hover===void 0?void 0:`pointer`}var oF={phase:`idle`};function sF(e,t,n,r){return e.phase===`shown`&&r?{...e,at:t}:e.phase===`dismissed`&&r?e:{phase:`waiting`,at:t,since:n}}function cF(e,t){switch(t.kind){case`move`:return sF(e,t.at,t.now,t.still);case`tick`:return e.phase!==`waiting`||t.now-e.since<250?e:t.target?{phase:`shown`,target:t.target,at:e.at}:oF;case`key`:case`press`:return e.phase===`shown`||e.phase===`dismissed`?{phase:`dismissed`,target:e.target}:oF;case`leave`:case`stale`:case`busy`:return oF}}function lF(e,t){return e.phase===`waiting`?Math.max(0,e.since+250-t):void 0}var uF=e=>e.phase===`shown`||e.phase===`dismissed`;function dF(e){if(e.phase===`shown`)return{text:e.target.text,left:e.at.x+12,top:e.at.y+12}}function fF(e,t,n){let r=(e,t,n)=>e+t>n?Math.max(0,e-24-t):e;return{left:r(e.left,t.width,n.width),top:r(e.top,t.height,n.height)}}var pF=1;function mF(e,t,n){let r=oF,i,a,o=!1,s=!1,c=()=>{a!==void 0&&e.clearTimer(a),a=void 0},l=()=>{c();let t=lF(r,e.now());t!==void 0&&(a=e.setTimer(d,t+pF))},u=e=>{let n=cF(r,e);n!==r&&(r=n,t(r)),l()};function d(){a=void 0,u({kind:`tick`,now:e.now(),target:i&&n()?.pick(i)})}let f=e.listenKeys(()=>u({kind:`key`}));return{move(t,a){if(o||s)return;i=t;let c=n(),l=uF(r)&&c!==void 0&&c.still(r.target,t);u({kind:`move`,at:a,now:e.now(),still:l})},leave:()=>u({kind:`leave`}),press:()=>u({kind:`press`}),stale:()=>u({kind:`stale`}),quiet(e){o=e,e&&u({kind:`busy`})},over(e){!e&&!s&&u({kind:`leave`}),s=!e},dispose(){c(),f()}}}function hF(e,t,n){let{onPointerDown:r,onPointerMove:i}=e,a=(...e)=>{t.press(),r(...e)},o=(...e)=>{let r=e[0];n&&t.over(r?.target===n.current),i(...e)};return{...e,onPointerDown:a,onPointerMove:o,onWheel:()=>t.stale()}}var gF={now:()=>performance.now(),setTimer:(e,t)=>window.setTimeout(e,t),clearTimer:e=>window.clearTimeout(e),listenKeys:e=>(window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0))};function _F({enabled:e,busy:t,probe:n,camera:r,design:i}){let[a,o]=(0,_.useState)(oF),s=(0,_.useRef)(n);s.current=n;let c=(0,_.useRef)(void 0);return(0,_.useEffect)(()=>{let e=mF(gF,o,()=>s.current);return c.current=e,()=>{e.dispose(),c.current=void 0}},[]),(0,_.useEffect)(()=>c.current?.quiet(!e||t),[e,t]),(0,_.useEffect)(()=>c.current?.stale(),[r,i]),{state:a,...(0,_.useMemo)(()=>({move:(e,t)=>c.current?.move(e,t),leave:()=>c.current?.leave(),press:()=>c.current?.press(),stale:()=>c.current?.stale(),over:e=>c.current?.over(e)}),[])}}function vF({state:e}){let t=dF(e),n=(0,_.useRef)(null);return(0,_.useLayoutEffect)(()=>{let e=n.current,r=e?.parentElement;if(!e||!r||!t)return;let i=fF(t,{width:e.offsetWidth,height:e.offsetHeight},{width:r.clientWidth,height:r.clientHeight});e.style.left=`${i.left}px`,e.style.top=`${i.top}px`}),t?(0,X.jsx)(`div`,{ref:n,className:`hover-label`,role:`tooltip`,style:{left:t.left,top:t.top},children:t.text}):null}var yF=` · `;function bF(e,t){if(t===void 0)return`no net`;let n=e.circuit.nets.find(e=>e.id===t);return n?n.names[0]??t:t.startsWith(`net.`)?t.slice(4):t}var xF=e=>`${Number(e.toFixed(4))} mm`,SF=(e,t)=>e.circuit.components.find(e=>e.id===t);function CF(e,t){let n=SF(e,t.component),r=n?.pins.find(e=>e.id===t.pin),i=r&&In(n?.props??{},r.number),a=n?.instance===void 0?``:` [${n.instance}]`;return`${t.component}.${t.number}${i?` ${i}`:``}${yF}${bF(e,t.net)}${a}`}var wF=(e,t)=>`via ${t.id}${yF}${bF(e,t.net)}${yF}${t.layers[0]}–${t.layers.at(-1)}`;function TF(e,t){return`track ${t.id}${yF}${bF(e,t.net)}${yF}${xF(t.width)}${yF}${t.layer}${t.by===`router`?`${yF}routed`:``}`}var EF=new Set;function DF(e,t){let{design:n,scale:r,layers:i,context:a}=t;if(!Va({kind:`pour`,id:``},a))return;let o=n.pcb.holes?.find(t=>t.id===Uu(n.pcb.holes??[],e,r,i.visible));return o?{kind:`hole`,id:o.id,text:Ru(o)}:OF(n,Vu(n,e,r,i.visible,t.pours?.hidden??EF))}function OF(e,t){let n=t===void 0?void 0:Nu(e).find(e=>e.id===t);return n&&{kind:`pour`,id:n.id,text:Iu(e,n)}}function kF(e,t){let{design:n,layers:r,context:i}=t;if(n.pcb.pours&&Va({kind:`pour`,id:``},i))return OF(n,Ku(n,e,r.visible,t.pours?.hidden??EF,t.pours?.activeLayer))}function AF(e,t){let{design:n,copper:r,scale:i,layers:a,context:o}=t;if(tA(t.boxes,e,o,t.texts))return;let s=uu(r,e,i,a.visible,o),c=s?.kind===`via`?r.vias.find(e=>e.id===s.id):void 0;if(c)return{kind:`via`,id:c.id,text:wF(n,c)};let l=s?.kind===`track`?r.tracks.find(e=>e.id===s.id):void 0;if(l)return{kind:`track`,id:l.id,text:TF(n,l)};let u=DF(e,t);if(u)return u;let d=Xf(n.pcb,e,a.visible,e=>Va({kind:`part`,name:e},o));return d?{kind:`pad`,id:d.id,text:CF(n,d)}:kF(e,t)}function jF(e,t){let n=e.circuit.nets.find(e=>e.id===t.net);return n?.names.includes(t.text)?t.text:n?.names[0]??t.text}var MF=(e,t)=>`${t.component}.${In(SF(e,t.component)?.props??{},t.number)??`pin${t.number}`}`;function NF(e,t){let n=e.circuit.nets.find(e=>e.pins.includes(t.id));return`${MF(e,t)}${yF}${bF(e,n?.id)}`}function PF(e,t){for(let n of e.circuit.instances??[]){let e=n.ports.find(e=>`${n.path}.${e.name}`===t);if(e)return{kind:`port`,id:t,text:`${t}${yF}${e.bus?`bus ${e.net}`:e.net}`}}}function FF(e,t){let{design:n}=t,r=Jn(n,e,12/t.scale),i=r&&n.schematic.symbols.find(e=>r.pin in e.pinEnds);if(!r||!i||!Va({kind:`part`,name:i.component},t.context))return;let a=SF(n,i.component)?.pins.find(e=>e.id===r.pin);return a?{kind:`pin`,id:a.id,text:NF(n,a)}:PF(n,r.pin)}function IF(e,t,n){let r=FF(t,n);if(!r)return e;let i=r.text.slice(0,r.text.indexOf(yF));return{...e,text:`${e.text}${yF}pin ${i}`,pin:r.id}}function LF(e,t){let{design:n}=t,r=eA(t.boxes,t.labels,e,t.context,t.wires,t.drawings,t.texts);if(r.kind===`label`)return IF({kind:`label`,id:r.label.id,text:jF(n,r.label)},e,t);if(r.kind===`wire`){let i=n.schematic.wires.find(e=>e.id===r.id);return IF({kind:`wire`,id:r.id,text:`wire${yF}${bF(n,i?.net)}`},e,t)}return r.kind===`drawing`?void 0:FF(e,t)}function RF(e,t){return t.view===`pcb`?AF(e,t):LF(e,t)}function zF(e,t,n){let{copper:r,scale:i}=n;if(e.kind===`via`){let n=r.vias.find(t=>t.id===e.id);return n!==void 0&&Math.hypot(t.x-n.at.x,t.y-n.at.y)<=ou(n.diameter,i)}if(e.kind===`track`){let n=r.tracks.find(t=>t.id===e.id);return n!==void 0&&Jc(n.points,t,ou(n.width,i))!==void 0}if(e.kind===`hole`)return Uu(n.design.pcb.holes??[],t,i,n.layers.visible)===e.id;if(e.kind===`pour`){let r=n.design.pcb.pours?.find(t=>t.id===e.id);return Vu(n.design,t,i,n.layers.visible,n.pours?.hidden??EF)===e.id||r!==void 0&&Gu(r,t)}let a=e.id.slice(0,e.id.indexOf(`#`)),o=n.design.pcb.parts.find(e=>e.component===a)?.pads.find(t=>t.id===e.id);return e.kind===`pad`&&o!==void 0&&xp(o,t)<=0}function BF(e,t,n){let r=12/n.scale,i=e=>{let i=n.design.schematic.symbols.find(t=>e in t.pinEnds)?.pinEnds[e];return i!==void 0&&Math.hypot(t.x-i.x,t.y-i.y)<=r},a=e.pin===void 0||i(e.pin);return e.kind===`label`?n.labels?.at(t)?.id===e.id&&a:e.kind===`wire`?n.wires?.at(t)===e.id&&a:i(e.id)}function VF(e,t,n){return n.view===`pcb`?zF(e,t,n):BF(e,t,n)}function HF({value:e,onChange:t}){let n=(0,_.useId)();return(0,X.jsxs)(`div`,{className:`hole-field`,onPointerDown:e=>e.stopPropagation(),children:[(0,X.jsx)(`label`,{htmlFor:n,children:`Hole diameter (mm)`}),(0,X.jsx)(`input`,{id:n,value:e,inputMode:`decimal`,spellCheck:!1,onChange:e=>t(e.target.value)})]})}var UF=.1,WF=e=>Math.round(e*1e4)/1e4||0,GF=(e,t)=>e.x===t.x&&e.y===t.y,KF=(e,t)=>WF(Math.hypot(t.x-e.x,t.y-e.y));function qF(e,t){return WF((Math.atan2(t.y-e.y,t.x-e.x)*180/Math.PI%360+360)%360)%360}var JF=e=>({tool:e,points:[],flip:!1,dragging:!1});function YF(e,t,n){let r=Ee(e,t,n);return{x:WF(r.x),y:WF(r.y)}}function XF(e,t){return e?t.time-e.time<=400&&Math.hypot(t.at.x-e.at.x,t.at.y-e.at.y)<=4:!1}function ZF(e,t){return(e?.tool===`text`||e?.naming===!0)&&t===0}function QF(e,t,n){let r=e.points.at(-1);if(!r)return[t];let i=n?On([r,t],[e.flip]).slice(1):[t];return[...e.points,...i.map(e=>({x:WF(e.x),y:WF(e.y)}))].filter((e,t,n)=>t===0||!GF(e,n[t-1]))}function $F(e,t){let[n,r]=[WF(Math.abs(t.x-e.x)),WF(Math.abs(t.y-e.y))];if(n!==0&&r!==0)return{x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),width:n,height:r}}function eI(e,t,n){let[r,i]=[qF(e,t),qF(e,n)];if(!(GF(n,e)||r===i))return{x:e.x,y:e.y,radius:KF(e,t),startAngle:r,endAngle:i}}var tI=(e,t)=>({state:JF(e),drawing:t}),nI=e=>({state:e});function rI(e){return e.points.length<2?nI(JF(e.tool)):e.tool===`bus`?nI({...e,naming:!0}):tI(`polyline`,{tag:`schematicpath`,props:{points:[...e.points]}})}function iI(e,t){return e.naming?nI(e):t.double&&e.points.length>0?rI(e):nI({...e,points:QF(e,t.at,t.shift)})}function aI(e,t){let[n]=e.points;if(!n)return nI({...e,points:[t],dragging:!0});let r=$F(n,t);return r?tI(`rectangle`,{tag:`schematicrect`,props:r}):nI(e)}function oI(e,t){let[n]=e.points;if(!n)return nI({...e,points:[t]});let r=KF(n,t);return r>0?tI(`circle`,{tag:`schematiccircle`,props:{x:n.x,y:n.y,radius:r}}):nI(e)}function sI(e,t){let[n,r]=e.points;if(!n)return nI({...e,points:[t]});if(!r)return GF(t,n)?nI(e):nI({...e,points:[n,t]});let i=eI(n,r,t);return i?tI(`arc`,{tag:`schematicarc`,props:i}):nI(e)}function cI(e,t){switch(e.tool){case`bus`:case`polyline`:return iI(e,t);case`rectangle`:return aI(e,t.at);case`circle`:return oI(e,t.at);case`arc`:return sI(e,t.at);case`text`:return nI({...e,points:[t.at]})}}function lI(e,t){let[n]=e.points;if(e.tool!==`rectangle`||!e.dragging||!n)return nI(e);let r=$F(n,t);return r?tI(`rectangle`,{tag:`schematicrect`,props:r}):nI({...e,dragging:!1})}function uI(e,t){let n=t.trim();return!e.naming||rn(n)===void 0?nI(e):tI(`bus`,{tag:`bus`,name:n,props:{points:[...e.points]}})}function dI(e,t){if(e.tool===`bus`)return uI(e,t);let[n]=e.points,r=t.trim();return e.tool!==`text`||!n||r===``?nI(JF(e.tool)):tI(`text`,{tag:`schematictext`,props:{x:n.x,y:n.y,text:r,fontSize:UF,anchor:`left`}})}function fI(e,t){switch(t.type){case`press`:return cI(e,t);case`release`:return lI(e,t.at);case`finish`:return(e.tool===`polyline`||e.tool===`bus`)&&!e.naming?rI(e):nI(e);case`removeCorner`:return e.naming?nI(e):nI(e.points.length<=1?JF(e.tool):{...e,points:e.points.slice(0,-1)});case`flip`:return nI(e.naming?e:{...e,flip:!e.flip});case`cancel`:return{state:e.points.length>0?JF(e.tool):null};case`text`:return dI(e,t.text)}}var pI={file:``,line:0,column:0,offset:0},mI={strokeWidth:.01,lineStyle:`dashed`,groupOffset:{x:0,y:0},source:pI};function hI(e,t,n){let[r,i]=e.points;if(!r)return;let a=`drawing:preview`;if(e.tool===`bus`)return{id:a,kind:`bus`,name:``,members:[],points:e.naming?[...e.points]:QF(e,t,n),groupOffset:mI.groupOffset,source:pI};if(e.tool===`polyline`)return{id:a,kind:`path`,points:QF(e,t,n),...mI};if(e.tool===`rectangle`){let e=$F(r,t);return e&&{id:a,kind:`rect`,x:e.x??0,y:e.y??0,width:e.width??0,height:e.height??0,filled:!1,...mI}}if(e.tool===`circle`)return{id:a,kind:`circle`,x:r.x,y:r.y,radius:KF(r,t),filled:!1,...mI};if(e.tool!==`arc`)return;if(!i)return{id:a,kind:`path`,points:[r,t],...mI};let o=eI(r,i,t);return o&&{id:a,kind:`arc`,x:r.x,y:r.y,radius:o.radius??0,startAngle:o.startAngle??0,endAngle:o.endAngle??0,...mI}}function gI(e,t){let{props:n}=e,r=e=>Number(n[e]??0),i={id:t,x:r(`x`),y:r(`y`)};switch(e.tag){case`bus`:return{id:t,kind:`bus`,name:e.name??``,members:rn(e.name??``)??[],points:n.points??[],groupOffset:mI.groupOffset,source:pI};case`schematicpath`:return{id:t,kind:`path`,points:n.points??[],...mI};case`schematicrect`:return{...i,kind:`rect`,width:r(`width`),height:r(`height`),filled:!1,...mI};case`schematiccircle`:return{...i,kind:`circle`,radius:r(`radius`),filled:!1,...mI};case`schematicarc`:return{...i,kind:`arc`,radius:r(`radius`),startAngle:r(`startAngle`),endAngle:r(`endAngle`),...mI};case`schematictext`:return{...i,kind:`text`,text:String(n.text??``),fontSize:UF,anchor:`left`,groupOffset:mI.groupOffset,source:pI}}}var _I=/^G(\d+)$/;function vI(e,t,n=[]){if(e.name!==void 0)return{kind:`addDrawing`,tag:e.tag,name:e.name,props:e.props};let r=Number(_I.exec(oT(t))?.[1]??1),i=Math.max(r-1,...n.map(e=>Number(_I.exec(e)?.[1]??0)));return{kind:`addDrawing`,tag:e.tag,name:`G${i+1}`,props:e.props}}var yI={bus:`bus`,polyline:`line`,rectangle:`rectangle`,circle:`circle`,arc:`arc`,text:`text`},bI=(e,t)=>`add the ${yI[e]} ${t}`,xI=`Esc or a right click stops.`,SI=`Esc cancels.`,CI={bus:`Click to start a bus, Enter to finish, then name it. ${xI}`,polyline:`Click to start a polyline, Enter to finish. ${xI}`,rectangle:`Drag, or click two opposite corners, to draw a rectangle. ${xI}`,circle:`Click the centre of a circle. ${xI}`,arc:`Click the centre of an arc. ${xI}`,text:`Click where the text goes. ${xI}`},wI=`Click for each corner, double click or Enter to finish. Shift keeps a leg square and Space flips its bend; Backspace removes a corner, ${SI}`;function TI(e){if(!e)return;let t=e.points.length;return t===0?CI[e.tool]:e.naming?`Name the bus, such as D[0:7] or CLK; Enter writes it, ${SI}`:e.tool===`polyline`||e.tool===`bus`?wI:e.tool===`rectangle`?`Click the opposite corner. ${SI}`:e.tool===`circle`?`Click to set the radius. ${SI}`:e.tool===`text`?`Type the text; Enter writes it, ${SI}`:t===1?`Click where the arc starts. Backspace steps back, ${SI}`:`Click where the arc ends. Backspace steps back, ${SI}`}var EI=e=>new Set(e.annotations.locks.map(e=>e.part));function DI(e,t){let[n,r]=(0,_.useState)(null),i=Nu(e);return(0,_.useEffect)(()=>{n!==null&&i.some(e=>e.id===n)&&(t(e=>e.clear().onlyBoard(n)),r(null))},[i,n,t]),(0,_.useCallback)(e=>r(e),[])}var OI=e=>t=>(e.notify(`Not written: ${t instanceof Error?t.message:String(t)}`),!1);function kI(e,t){let[n,r]=(0,_.useState)(null),i=(0,_.useRef)(n);return i.current=n,{state:n,send:(0,_.useCallback)(e=>{let n=i.current;if(!n)return;let a=Vb(n,e);i.current=a.state,r(a.state),(a.outline||a.hole||a.refused)&&t(a)},[t]),arm:(0,_.useCallback)(t=>{e(),i.current=Fb(t),r(i.current)},[e]),disarm:(0,_.useCallback)(()=>{i.current=null,r(null)},[])}}function AI(e,t){(0,_.useEffect)(()=>{if(!e)return;let n=e.points.length>0,r=e=>{e.key!==`Escape`||Pd(e).typing||(e.stopPropagation(),t({type:`cancel`}))},i=e=>{let r=n?Yd(Pd(e),{view:`pcb`,drawing:!0})?.action:void 0,i=r===`finishShape`?{type:`finish`}:r===`removeCorner`?{type:`removeCorner`}:void 0;i&&(e.preventDefault(),t(i))};return window.addEventListener(`keydown`,r,!0),window.addEventListener(`keydown`,i),()=>{window.removeEventListener(`keydown`,r,!0),window.removeEventListener(`keydown`,i)}},[e,t])}function jI(e,t){let n=(0,_.useRef)(t);n.current=t,(0,_.useEffect)(()=>{if(!e)return;let t=e=>{e.key===`Escape`&&(e.stopPropagation(),n.current())};return window.addEventListener(`keydown`,t,!0),()=>window.removeEventListener(`keydown`,t,!0)},[e])}function MI(e,t){let{input:n}=e,r=Ub(n.design);if(r===void 0)return n.actions.notify(`The circuit has no net for a copper pour yet.`);let i=Mb(n.circuit.model.boardItems??[],`copperpour`);n.actions.edit([Wb(r,n.activeLayer,t)],Gb(r,n.activeLayer,t===void 0)).catch(OI(n.actions)).then(t=>t&&e.waitForPour(i))}function NI(e,t){let n=Jb(e.diameter);if(typeof n!=`number`)return e.input.actions.notify(n.message);e.input.actions.edit([Kb(t,n)],qb(n)).catch(OI(e.input.actions))}function PI(e,t,n){let{input:r}=e,{camera:i,design:a,selection:o}=r;if(!i||t.button!==0||r.armed===`note`||r.armed===`zoom`||!Va({kind:`pour`,id:``},{selection:o,armed:r.armed,filter:r.filter}))return!1;let s=Uu(a.pcb.holes,n,i.scale,r.layers)??Vu(a,n,i.scale,r.layers,r.hidden);return s!==void 0&&(r.onSelect(e=>yo(t)?e.toggleBoard(s):e.onlyBoard(s)),!0)}function FI(e,t,n,r){let{input:i}=e,a=i.selection.soleBoard,o=a===void 0?void 0:Nu(i.design).find(e=>e.id===a);if(!o?.outline||!i.camera||t.button!==0||yo(t))return!1;let s=Hu(o.outline,n,i.camera.scale);if(s===void 0)return!1;let c=Xb(i.circuit.model,EI(i.circuit),o.id);return c?(i.actions.notify(`Not moved: ${c}`),!0):(r({id:o.id,index:s,outline:o.outline,start:n,to:o.outline[s],moved:!1}),!0)}var II=e=>e.outline.map((t,n)=>n===e.index?e.to:t);function LI(e){let{design:t,circuit:n,onSelect:r}=e,[i,a]=(0,_.useState)(String(Nb)),o=DI(t,r),[s,c]=(0,_.useState)(),l=(0,_.useRef)(void 0),[u,d]=(0,_.useState)(),[f,p]=(0,_.useState)();(0,_.useEffect)(()=>p(void 0),[t]);let m=e=>{l.current=e,c(e)},h={input:e,diameter:i,drag:s,waitForPour:o},g=(0,_.useRef)(h);g.current=h;let v=(0,_.useCallback)(e=>{e.refused&&g.current.input.actions.notify(e.refused),e.outline&&MI(g.current,e.outline),e.hole&&NI(g.current,e.hole)},[]),y=kI(e.onArm,v);AI(y.state,y.send);let{disarm:b}=y;(0,_.useEffect)(()=>{e.othersArmed&&b()},[e.othersArmed,b]),jI(s!==void 0,()=>m(void 0)),Gx({placePour:()=>y.arm(`pour`),placeHole:()=>y.arm(`hole`),placePourBoard:()=>MI(g.current,void 0)});let x=(0,_.useRef)(void 0),S=t=>Ee(t,e.step,e.snap),C=(t,n)=>{if(!y.state||!e.camera||t.button===1)return!1;if(t.button===2)return y.send({type:`cancel`}),!0;let r={at:{x:n.x*e.camera.scale,y:n.y*e.camera.scale},time:Date.now()},i=XF(x.current,r);return x.current=i?void 0:r,y.send({type:`press`,at:S(n),double:i}),!0},w=(0,_.useMemo)(()=>{let e=new Map;return f&&e.set(f.id,f.outline),s?.moved&&e.set(s.id,II(s)),e},[f,s]),T=Hb(y.state,e.cursor&&S(e.cursor)),E={mode:e.mode,hidden:e.hidden,selected:new Set(e.selection.board),...u===void 0?{}:{hover:u},activeLayer:e.activeLayer,outlines:w,...T.length>0?{preview:T}:{}},D=(0,_.useMemo)(()=>$b(n.model,EI(n)),[n]);return{state:y.state,armed:y.state!==null,busy:y.state!==null&&y.state.points.length>0,disarm:y.disarm,hint:tx(y.state),diameter:i,setDiameter:a,toolPress:C,cornerPress:(e,t)=>FI(g.current,e,t,m),pickPress:(e,t)=>PI(g.current,e,t),hoverAt:n=>{let{camera:r}=e,i={selection:e.selection,armed:e.armed,filter:e.filter},a=r&&Va({kind:`pour`,id:``},i)?Uu(t.pcb.holes,n,r.scale,e.layers)??Vu(t,n,r.scale,e.layers,e.hidden):void 0;return d(a),a!==void 0},clearHover:()=>d(void 0),hover:u,drag:s,dragRef:l,put:m,release:t=>{if(m(void 0),!t.moved)return;let n=Yb(t.id,t.outline,t.index,t.to);if(`message`in n)return e.actions.notify(n.message);p({id:t.id,outline:II(t)}),e.actions.edit([n.edit],n.summary).catch(OI(e.actions)).then(e=>e||p(void 0))},latest:g,scene:E,removal:D,cursor:s?`move`:y.state?`crosshair`:u===void 0?void 0:`pointer`}}function RI(e,t,n){let r=t=>{let{input:n}=e.latest.current;return n.camera?ye(n.camera,n.size,sO(n.canvas.current,n.size,t)):void 0};return{...t,onPointerMove:i=>{let a=e.dragRef.current,o=a&&r(i);if(!a||!o)return t.onPointerMove(i);if(n(o),i.buttons===0)return void e.put(void 0);let{input:s}=e.latest.current,c=Math.hypot(o.x-a.start.x,o.y-a.start.y)*(s.camera?.scale??1)>=3;(a.moved||c)&&(ce.refuses()||e.put({...a,moved:!0,to:Ee(o,s.step,s.snap)}))},onPointerUp:n=>{let r=e.dragRef.current;r?e.release(r):t.onPointerUp(n)},onPointerCancel:()=>{e.put(void 0),t.onPointerCancel()},onLostPointerCapture:()=>{e.put(void 0),t.onLostPointerCapture()}}}function zI(e){return(t,n)=>e.pourTool(t,n)||e.route(t,n)||e.pourCorner(t,n)||!e.text(n)&&(e.copper(t,n)||e.pour(t,n))}var BI=W.background;function VI(e,t){let n=e.circuit.nets.find(e=>e.id===t.net)?.names[0];return`${KA(e,t)}${n?` on ${n}`:``}`}function HI(e,t,n){(0,_.useEffect)(()=>{yy({active:e,stop:()=>{t(),n()}})},[e,t,n]),(0,_.useEffect)(()=>xy,[])}function UI(e,t){let{design:n,camera:r,size:i,layers:a,hoverPad:o,moving:s,boxes:c,hover:l,selection:u,locked:d,circuit:f,gesture:p,highlightNets:m,markers:h,activeViolation:g,grid:v,copper:y,texts:b,pours:x}=t,S=(0,_.useMemo)(()=>Of(n.pcb,b.moves),[n.pcb,b.moves]),C=(0,_.useMemo)(()=>m.length>0?m:o?.net?[o.net]:Ep,[m,o]);(0,_.useEffect)(()=>{if(!r)return;let t=dO(e.current,i,r,BI,(e,t,n,r)=>PD(e,t,n,v,r));if(!t)return;let{ctx:n,ratio:o}=t;Yf(n,S,{camera:r,size:i},{ratio:o,layers:a,...C.length>0?{highlight:{nets:C}}:{},...s?{moving:{components:s.names,by:s.offset}}:{},violations:h,...g?{activeViolation:g}:{},copper:y,pours:x}),n.setTransform(o,0,0,o,0,0),fO(n,r,i,{view:`pcb`,boxes:c,moving:s,hover:l,selection:u,locked:d,marks:f.annotations.marks,gesture:p,look:FD,ratio:o}),GD(n,{camera:r,size:i},b.shown,{selected:u.texts,hover:p?void 0:b.hover},FD,o)},[e,S,r,i,a,C,s,c,l,u,d,f,p,h,g,v,y,b,x])}function WI({unit:e,step:t,setStep:n,keep:r}){return(0,X.jsxs)(Ay,{children:[(0,X.jsx)(bO,{step:t,options:fg(`pcb`,e),onChange:n}),(0,X.jsx)(xO,{...r,title:`Write the faded parts' positions into the code as pcbX and pcbY`})]})}function GI(e,t,n,r,i){let[a,o]=(0,_.useState)(),[s,c]=(0,_.useState)(),[l,u]=(0,_.useState)();return{part:a,text:s,pad:l,at:a=>{let s={selection:_o.none,armed:null,layers:n,filter:r},l=eA(t,void 0,a,s,void 0,void 0,i);o(l.kind===`part`?l.name:void 0),c(l.kind===`text`?l.id:void 0),u(Xf(e.pcb,a,n.visible,e=>Va({kind:`part`,name:e},s)))},leave:()=>{o(void 0),c(void 0),u(void 0)}}}function KI(e,t,n,r){let i=(0,_.useRef)(void 0);i.current=t;let a=(0,_.useCallback)(()=>i.current?Np(e.pcb,i.current,n):void 0,[e,n]),o=(0,_.useCallback)(t=>Op(e,t),[e]);return kP({...r,netUnderPointer:a,netsOf:o})}function qI({canvasRef:e,size:t,cursorStyle:n,pointer:r,onLeave:i,hint:a}){return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`canvas`,{ref:e,style:{width:t.width,height:t.height,cursor:n},...r,onPointerLeave:i,onContextMenu:e=>e.preventDefault(),"aria-label":`PCB layout. Drag parts to move them, drag the background to select, drag with the right button to pan, scroll to zoom.`,role:`img`}),a&&(0,X.jsx)(`div`,{className:`canvas-top`,children:(0,X.jsx)(`div`,{className:`canvas-hint`,children:a})})]})}function JI({parts:e,circuit:t,actions:n,selection:r,armed:i,pick:a,pickFilter:o}){return(0,_.useMemo)(()=>({selectedAt:t=>{let n=eA(e.boxes,void 0,t,{selection:r,armed:i,layers:a,filter:o});return n.kind===`part`&&r.has(n.name)?n.name:void 0},originOf:t=>e.anchors.get(t)?.origin??e.boxes.find(e=>e.name===t)?.center??{x:0,y:0},blockerFor:e.blockerFor,move:(r,i)=>wt(dt(t,r,`pcb`,ft(e.anchors,e.boxes),i,e.blockerFor),n)}),[e,t,n,r,i,a,o])}function YI(e,t){return(0,_.useMemo)(()=>Oe(e.pcb.board?.outline??[])??ke(t.map(e=>e.box)),[e,t])}function XI({copper:e,pours:t,track:n,hover:r,boxes:i,context:a,texts:o,camera:s,size:c,canvasRef:l,gestures:u,setCursor:d,onOpenProperties:f,onSelect:p,label:m}){let h=e=>tA(i,e,a,o),g=r=>{if(n.armed||t.armed)return;let o=h(r)?void 0:QP(e,r);if(o)return p(e=>e.onlySegment(o));if(!h(r)&&ZP(e,r)!==void 0)return;let s=eA(i,void 0,r,a);s.kind===`part`&&f(s)},_=n=>{if(uC(`pcb`,n),m.at(n),h(n))return e.setHover(void 0),t.clearHover(),r.at(n);if($P(e,n))return t.clearHover(),r.leave();r.at(n),t.hoverAt(n)},v=eF(e);return{pointer:hF(RI(t,iF(e,FA({camera:s,size:c,element:l,gestures:u,setCursor:d,hover:_,open:g,tool:zI({pourTool:t.toolPress,route:n.press,pourCorner:t.cornerPress,text:h,copper:v,pour:t.pickPress})}),d),d),m),onLeave:()=>{m.leave(),r.leave(),e.setHover(void 0),t.clearHover(),d(void 0)}}}function ZI(e){let{design:t,builtFrom:n,builtMark:r,buildStatus:i,circuit:a,actions:o,selection:s,onSelect:c,highlight:l,onHighlight:u,unit:d,onToggleUnit:f,gridStyle:p,gridStep:m,snap:h,onGridStep:g,markers:v,activeViolation:y,focus:b,onFocused:x,layers:S,pickFilter:C}=e,w=(0,_.useRef)(null),T=(0,_.useRef)(null),E=oO(w),[D,O]=(0,_.useState)(),k=(0,_.useMemo)(()=>({step:m,style:p}),[m,p]),A=(0,_.useMemo)(()=>Ia(t.pcb.parts,S),[t,S]),j=rO(t,`pcb`,a),{camera:M,setCamera:ee,fit:te}=cO(w,E,YI(t,j.boxes));lO(`pcb`,b,M,ee,x),IA({selection:s,boxes:j.boxes,size:E,setCamera:ee,notify:o.notify});let ne={view:`pcb`,circuit:a,actions:o,onSelect:c,blockerFor:j.blockerFor},N=pM(),P=(0,_.useRef)(()=>void 0),F=UA((0,_.useCallback)(()=>{N.disarm(),P.current()},[N])),re=(0,_.useCallback)(()=>{F.disarm(),N.disarm()},[F,N]),I=LI({design:t,circuit:a,actions:o,camera:M,size:E,canvas:T,cursor:D,layers:S,hidden:e.hiddenPours,filter:C,armed:F.tool,othersArmed:F.armed||N.armed!==null,selection:s,onSelect:c,step:m,snap:h,activeLayer:e.activeLayer,mode:e.pourFill,onArm:re});P.current=I.disarm;let L=JP({design:t,builtMark:r,parts:JI({parts:j,circuit:a,actions:o,selection:s,armed:F.tool,pick:A,pickFilter:C}),camera:M,size:E,canvas:T,layers:S,filter:C,armed:F.tool,selection:s,onSelect:c,actions:o,step:m,snap:h,routing:N.route!==null}),R=(0,_.useMemo)(()=>mu(L.shown,S),[L.shown,S]);zN({design:t,builtMark:r,selection:s,lockedParts:j.locked,routing:N.route!==null,send:e=>L.latest.current.send(e),busy:()=>L.latest.current.inFlight,notify:o.notify});let z=DM({design:t,builtMark:r,copper:L.shown,camera:M,cursor:D,step:m,snap:h,layers:S,activeLayer:e.activeLayer,onActiveLayer:e.onActiveLayer,locked:j.locked,actions:o,arm:N,onArm:F.disarm});HI(z.command??VA(F.which),F.disarm,N.disarm);let ie=(0,_.useCallback)(e=>{let n=t.pcb.parts.find(t=>t.component===e);return n!==void 0&&S[n.side===`top`?`topSilk`:`bottomSilk`]},[t,S]),ae=WO({view:`pcb`,design:t,circuit:a,actions:o,locked:j.locked,builtFrom:n,drawn:ie}),oe=NA({...ne,camera:M,setCamera:ee,size:E,boxes:j.boxes,anchors:j.anchors,step:m,snap:h,builtFrom:n,selection:s,tool:{armed:F.tool,disarm:F.disarm},layers:A,copper:R,copperAt:e=>ZP(L,e),texts:ae.tools,filter:C,onContextMenu:z.armed?z.cancel:e.onContextMenu}),se=iO(j,m,h),ce=(0,_.useMemo)(()=>JD(s.copper,s.total,L.shown),[s,L.shown]),le=aO(T,s.primary,j.boxes,M,E,void 0,ce),{rotateHeld:ue}=KI(t,D,S,{...ne,paused:z.routing||I.busy,board:I.removal,selection:s,layout:se,builtMark:r,buildStatus:i,moveWaiting:oe.pending!==void 0,fit:te,onHighlight:u,menuPlace:le,onContextMenu:e.onContextMenu,copper:L.keys,texts:ae}),de=GI(t,j.boxes,A,C,ae.tools),{gesture:fe}=oe,pe=GO(ae,fe),B=(0,_.useMemo)(()=>({...pe,hover:de.text}),[pe,de.text]),me=L.moving?{names:L.moving.names,offset:L.moving.offset}:oe.moving,he={...L.scene,activeLayer:e.activeLayer,routes:z.routes};UI(T,{design:t,camera:M,size:E,layers:S,hoverPad:de.pad,moving:me,boxes:j.boxes,hover:de.part,selection:s,locked:j.locked,circuit:a,gesture:fe,highlightNets:l,markers:v,activeViolation:y,grid:k,copper:he,texts:B,pours:I.scene});let ge={selection:s,armed:F.tool,layers:A,filter:C},_e=M&&{view:`pcb`,design:t,copper:L.shown,scale:M.scale,layers:A,context:ge,boxes:j.boxes,texts:ae.tools,pours:{hidden:e.hiddenPours,activeLayer:e.activeLayer}},ve=_e&&{pick:e=>RF(e,_e),still:(e,t)=>VF(e,t,_e)},ye=_F({enabled:e.hoverLabels,busy:z.routing,probe:ve,camera:M,design:t}),be={...ye,at:e=>M&&ye.move(e,V(M,E,e))},{pointer:xe,onLeave:Se}=XI({copper:L,pours:I,track:z,hover:de,boxes:j.boxes,context:ge,texts:ae.tools,camera:M,size:E,canvasRef:T,gestures:oe,setCursor:O,onOpenProperties:e.onOpenProperties,onSelect:c,label:be}),Ce=z.armed?`crosshair`:I.cursor??aF(L)??PA(fe,F.armed,de.part!==void 0||de.text!==void 0);return(0,X.jsxs)(`div`,{className:`pcb-canvas`,ref:w,children:[(0,X.jsx)(qI,{canvasRef:T,size:E,cursorStyle:Ce,pointer:xe,onLeave:Se,hint:F.hint??I.hint??z.hint}),I.state?.tool===`hole`&&(0,X.jsx)(HF,{value:I.diameter,onChange:I.setDiameter}),(0,X.jsx)(vF,{state:ye.state}),(0,X.jsx)(WI,{unit:d,step:m,setStep:g,keep:{show:j.autoPlaced,onKeep:()=>Je(t,`pcb`,j.blockerFor,o,a)}}),(0,X.jsx)(SO,{cursor:D,zoom:M?.scale,unit:d,onToggleUnit:f,detail:z.status??(de.pad&&VI(t,de.pad)),gesture:fe,rotateHeld:ue,snap:h})]})}function QI(e){if(e.tool)return`Click a pin to place ${e.tool===`gnd`?`GND`:e.tool===`vcc`?e.typed||`VCC`:e.typed||`a net label`}.${e.tool===`gnd`?``:` Tab changes the name.`} Esc or a right click stops.`}function $I({palette:e,camera:t,size:n}){let{editing:r}=e;if(!r||!t)return null;let i=V(t,n,r.at);return(0,X.jsx)(eL,{at:i,initial:r.initial,palette:e},`${r.pin??r.rename?.id??`tab`}:${r.at.x}:${r.at.y}`)}function eL({at:e,initial:t,palette:n}){let[r,i]=(0,_.useState)(t),[a,o]=(0,_.useState)();return(0,X.jsxs)(`form`,{className:`label-name`,style:{left:e.x+12,top:e.y+12},onPointerDown:e=>e.stopPropagation(),onSubmit:e=>{e.preventDefault(),o(n.submitName(r))},children:[(0,X.jsx)(`input`,{autoFocus:!0,"aria-label":`Net name`,placeholder:`Net name`,value:r,onFocus:e=>e.currentTarget.select(),onChange:e=>i(e.target.value),onKeyDown:e=>{e.key===`Tab`&&e.preventDefault(),e.key===`Escape`&&(e.stopPropagation(),n.cancelName())}}),a&&(0,X.jsx)(`span`,{role:`alert`,children:a})]})}function tL(e){let t=e.gridFifth?{fifth:e.gridFifth}:{};return{lines:{minor:e.grid,...t},dots:{minor:e.gridDot,...t,px:2}}}function nL(e,t,n,r,i,a=Po()){Eg(e,t,n,r,tL(a),i)}var rL=.12,iL=.09,aL=.14,oL=.06,sL=2,cL=[[`label`,iL],[`value`,aL]];function lL(e,t){return rs(`detail`,as(e,t),is(rL,e,t))}function uL(e,t,n,r,i,a=1){let o=V(t,n,{x:r.minX,y:r.minY}),s=V(t,n,{x:r.maxX,y:r.maxY});e.lineWidth=a/i;let c=es(o,s,i,a);e.strokeRect(c.x,c.y,c.width,c.height)}function dL(e,t,n,r,i,a){let o=V(t,n,r),s=V(t,n,i),c=o.x===s.x,l=e=>c?{x:qo(e.x,a),y:e.y}:{x:e.x,y:qo(e.y,a)},[u,d]=[l(o),l(s)];e.moveTo(u.x,u.y),e.lineTo(d.x,d.y)}function fL(e,t,n,r){let i=is(n,t.scale,r);return rs(`detail`,as(t.scale,r),i)?(e.font=Sa(xa.regular,i/r),!0):!1}function pL(e,t,n,r,i,a,o){if(!i)return;let s=o===void 0?i:xs(i,o*t.scale,t=>e.measureText(t).width);if(s===null)return;let c=ss(V(t,n,r),a);e.fillText(s,c.x,c.y)}function mL(e,t,n,r,i){let{sheet:a,dividers:{xs:o,ys:s}}=r;e.lineWidth=Ko(i),e.beginPath();for(let r of o)dL(e,t,n,{x:r,y:a.outer.minY},{x:r,y:a.inner.minY},i),dL(e,t,n,{x:r,y:a.inner.maxY},{x:r,y:a.outer.maxY},i);for(let r of s)dL(e,t,n,{x:a.outer.minX,y:r},{x:a.inner.minX,y:r},i),dL(e,t,n,{x:a.inner.maxX,y:r},{x:a.outer.maxX,y:r},i);if(e.stroke(),lL(t.scale,i)&&fL(e,t,.12,i)){e.fillStyle=Po().titleText,e.textBaseline=`middle`,e.textAlign=`center`;for(let a of r.labels)pL(e,t,n,a,a.text,i)}}function hL(e,t,n,r,i){let a=r.block;uL(e,t,n,a.box,i);for(let r of a.cells)uL(e,t,n,r.box,i);e.fillStyle=Po().titleText,e.textBaseline=`middle`,e.textAlign=`left`;for(let[r,o]of cL)if(fL(e,t,o,i))for(let o of a.cells)o.kind===r&&pL(e,t,n,{x:o.box.minX+oL,y:(o.box.minY+o.box.maxY)/2},o.text,i,o.box.maxX-o.box.minX-2*oL)}function gL(e,t,n,r,i){let{sheet:a}=r;e.save(),cs(e),e.strokeStyle=Po().border,uL(e,t,n,a.outer,i,Qo(sL,i)),uL(e,t,n,a.inner,i),mL(e,t,n,r,i),hL(e,t,n,r,i),e.restore()}var _L=[{name:`A4`,width:11.69,height:8.27,zonesX:6,zonesY:4},{name:`A3`,width:16.54,height:11.69,zonesX:8,zonesY:6},{name:`A2`,width:23.39,height:16.54,zonesX:12,zonesY:8},{name:`A1`,width:33.11,height:23.39,zonesX:16,zonesY:12},{name:`A0`,width:46.81,height:33.11,zonesX:24,zonesY:16}],vL=.2,yL=1.2,bL=.8,xL=10,SL=1e-6;function CL(e){return Math.round(e*xL)/xL}function wL(e,t){let n=t??{minX:0,minY:0,maxX:0,maxY:0},r=CL((n.minX+n.maxX)/2-e.width/2),i=CL((n.minY+n.maxY)/2-e.height/2),a={minX:r,minY:i,maxX:r+e.width,maxY:i+e.height};return{size:e,outer:a,inner:{minX:a.minX+vL,minY:a.minY+vL,maxX:a.maxX-vL,maxY:a.maxY-vL},empty:t===void 0}}function TL(e){let{inner:t}=e;return{minX:t.maxX-4,minY:t.minY,maxX:t.maxX,maxY:t.minY+yL}}var EL=(e,t)=>e.minX<t.maxX&&t.minX<e.maxX&&e.minY<t.maxY&&t.minY<e.maxY;function DL(e,t){let{outer:n}=e;return t.minX-.5>=n.minX-SL&&t.minY-.5>=n.minY-SL&&t.maxX+.5<=n.maxX+SL&&t.maxY+.5<=n.maxY+SL&&!EL(t,TL(e))}function OL(e,t){let n=Math.max(0,t?_L.indexOf(t):0),r=_L.slice(n);if(!e)return wL(r[0],void 0);let i=r.map(t=>wL(t,e));return i.find(t=>DL(t,e))??i[i.length-1]}function kL(e,t){return t?e&&!e.empty&&DL(e,t)?e:OL(t,e&&!e.empty?e.size:void 0):e??OL(void 0)}function AL(e,t){return(e?.empty??!1)&&!t.empty}function jL(e){let{size:t,inner:n,outer:r}=e,i=[],a=(n.maxX-n.minX)/t.zonesX,o=(n.maxY-n.minY)/t.zonesY;for(let e=0;e<t.zonesX;e++){let t=n.minX+(e+.5)*a;i.push({text:String(e+1),x:t,y:(r.maxY+n.maxY)/2},{text:String(e+1),x:t,y:(r.minY+n.minY)/2})}for(let e=0;e<t.zonesY;e++){let t=n.maxY-(e+.5)*o,a=String.fromCharCode(65+e);i.push({text:a,x:(r.minX+n.minX)/2,y:t},{text:a,x:(r.maxX+n.maxX)/2,y:t})}return i}function ML(e){let{size:t,inner:n}=e,r=(e,t,n)=>Array.from({length:n-1},(r,i)=>e+(i+1)*(t-e)/n);return{xs:r(n.minX,n.maxX,t.zonesX),ys:r(n.minY,n.maxY,t.zonesY)}}var NL=[[`Project`,`project`],[`Page`,`page`],[`File`,`file`],[`Date`,`date`],[`Rev`,`rev`]];function PL(e,t){let n=TL(e),r=yL/NL.length,i=n.minX+bL;return{box:n,cells:NL.flatMap(([e,a],o)=>{let s=n.maxY-o*r,c=s-r;return[{box:{minX:n.minX,minY:c,maxX:i,maxY:s},text:e,kind:`label`},{box:{minX:i,minY:c,maxX:n.maxX,maxY:s},text:t[a],kind:`value`}]})}}function FL(e){return e&&/^\d{4}-\d{2}-\d{2}/.test(e)?e.slice(0,10):``}function IL(e,t){return{sheet:e,dividers:ML(e),labels:jL(e),block:PL(e,t)}}function LL({design:e,circuit:t,actions:n,builtFrom:r}){let[i,a]=(0,_.useState)([]);(0,_.useEffect)(()=>a(e=>e.every(e=>e.sentAt>r)?e:e.filter(e=>e.sentAt>r)),[r]);let o=(0,_.useMemo)(()=>new Set(t.annotations.locks.map(e=>e.part)),[t]);return{tools:{boxes:(0,_.useMemo)(()=>e.schematic.labels.map(e=>({id:e.id,box:Er(e)})),[e.schematic.labels]),at:t=>Ar(e,t),blocker:n=>Wr(e,t,n,o),commit:(r,i)=>{let s=Kr(e,t,r.id,i,o);if(!Array.isArray(s))return n.notify(s.blocked);let c=Vr(e,r.id,i);if(s.length===0||!c)return;let l={id:r.id,...c,sentAt:Date.now()};a(e=>[...e.filter(e=>e.id!==r.id),l]),n.edit(s,`Move ${r.text} label`).then(e=>e||a(e=>e.filter(e=>e!==l)))}},pending:(0,_.useMemo)(()=>i.filter(e=>e.sentAt>r),[i,r])}}function RL(e,t){return(0,_.useMemo)(()=>{let n=t&&Vr(e,t.id,t.at);return t&&n?{id:t.id,...n}:void 0},[e,t])}function zL(e){let t=(0,_.useRef)(Bw(e));t.current.set(e),(0,_.useEffect)(()=>zw.answer(e=>t.current.call(e)),[])}var BL=.5,VL=.1,HL=/^[A-Za-z_][A-Za-z0-9_]*$/,UL=`Use letters, digits and _, starting with a letter or _`,WL=[`right`,`top`,`left`,`bottom`],GL={right:{x:1,y:0},left:{x:-1,y:0},top:{x:0,y:1},bottom:{x:0,y:-1}},KL=e=>Math.round(e*1e3)/1e3||0,qL=e=>KL(Math.round(e/VL)*VL);function JL(e,t){if(e===`gnd`)return`GND`;let n=t.trim();return e===`vcc`&&n===``?`VCC`:n}function YL(e,t){let n=e.schematic.symbols.find(e=>e.pinEnds[t.id]),r=n?.pinEnds[t.id],i=n?.symbol.pins.find(e=>e.number===t.number)?.side;if(!n||!r||!i)return;let a=Math.round((n.rotation%360+360)%360/90)%4,o=WL[(WL.indexOf(i)+a)%4]??i,s=GL[o];return{end:r,side:o,corner:{x:qL(r.x+s.x*BL),y:qL(r.y+s.y*BL)}}}var XL=(e,t)=>e.circuit.components.flatMap(e=>e.pins).find(e=>e.id===t),ZL=(e,t)=>e.circuit.nets.find(e=>e.pins.includes(t));function QL(e){return e===``?`Name the net label`:HL.test(e)?void 0:UL}function $L(e,t,n,r){let i=Ln(e,t),a=QL(n);if(a)return a;if(!dr(i))return`${i} has a repeated name and cannot be wired from the Studio`;if(r.has(t.component))return`${t.component} is locked`;if(ZL(e,t.id)?.names.includes(n))return`${i} is already on ${n}`}function eR(e,t,n,r,i,a){let o=XL(e,i),s=o&&YL(e,o);if(!o||!s)return{blocked:`No pin there`};let c=JL(n,r),l=$L(e,o,c,a);return l?{blocked:l}:[{kind:`addTrace`,from:Ln(e,o),to:`net.${c}`,schematicRouteHints:[s.corner]}]}function tR(e,t,n){return e===`label`?`Add ${t} label at ${n}`:`Add ${t} at ${n}`}function nR(e,t,n,r){let i=XL(e,r),a=i&&YL(e,i);if(!i||!a)return;let o=JL(t,n),s=Kp([o])??`label`;return{wire:[a.end,a.corner],label:{id:`label:pending:${r}:${o}`,net:`net.${o}`,text:o,at:a.corner,side:a.side,style:s}}}function rR(e,t,n){let r=ZL(e,t);return r&&!r.names.includes(n)?r.names[0]:void 0}var iR=/^net\.([\w-]+)$/,aR=`schematicRouteHints`,oR=(e,t)=>iR.exec(e?.trim()??``)?.[1]===t,sR=(e,t)=>e.model.traces.filter(e=>oR(e.from,t)||oR(e.to,t));function cR(e,t,n,r){if(t.trim().startsWith(`net.`))return;let i=Rn(e,t)?.component;return i===void 0?`${t} is not a pin the Studio can find; rename ${n} in the code`:r.has(i)?`${i} is locked`:void 0}function lR(e,t,n,r){let i=`rename ${n} in the code`;return t.editable?t.parent!==void 0&&t.parent!==`board`?`The trace on line ${t.line} is inside <${t.parent}>; ${i}`:Object.entries(t.props).some(([e,n])=>n.literal===void 0&&!(e===aR&&t.schematicRouteHints))?`The trace on line ${t.line} has an expression; ${i}`:[t.from,t.to].map(t=>t===void 0?void 0:cR(e,t,n,r)).find(e=>e!==void 0):`The trace on line ${t.line} is read-only (${t.readonlyReason}); ${i}`}function uR(e,t,n){let r=e=>oR(e,t)?`net.${n}`:e??``,i=Object.entries(e.props).filter(([e])=>e!==aR),a=Object.fromEntries(i.map(([e,t])=>[e,t.literal]));return{kind:`addTrace`,from:r(e.from),to:r(e.to),...i.length>0?{props:a}:{},...e.schematicRouteHints?{schematicRouteHints:e.schematicRouteHints}:{}}}var dR=(e,t)=>e.circuit.nets.filter(e=>e.id!==t.net).flatMap(e=>e.names);function fR(e,t,n,r,i){let a=r.trim(),o=n.text,s=QL(a);if(s)return{blocked:s};let c=`Rename net ${o} to ${a}`;if(a===o)return{edits:[],summary:c};if(e.circuit.nets.find(e=>e.id===n.net)?.names.includes(a))return{blocked:`${o} and ${a} already name this net`};let l=sR(t,o);if(l.length===0)return{blocked:`${o} is not written on a trace the Studio can change; rename it in the code`};let u=l.map(t=>lR(e,t,o,i)).find(e=>e!==void 0);if(u)return{blocked:u};let d=l.map(e=>({kind:`removeTrace`,from:e.from??``,to:e.to??``})),f=l.map(e=>uR(e,o,a)),p=dR(e,n).includes(a)?{joins:a}:{};return{edits:[...d,...f],summary:c,...p}}function pR(e,t){if(t.style===`label`)return;let n=sR(e,t.text).length;return`Rename the ${t.text} net everywhere (${n} ${n===1?`connection`:`connections`})?`}var mR=12;function hR(e){let[t,n]=(0,_.useState)([]);return(0,_.useEffect)(()=>n(t=>t.every(t=>t.sentAt>e)?t:t.filter(t=>t.sentAt>e)),[e]),{visible:(0,_.useMemo)(()=>t.filter(t=>t.sentAt>e),[t,e]),add:e=>{let t={...e,sentAt:Date.now()};return n(e=>[...e,t]),t},drop:e=>n(t=>t.filter(t=>t!==e))}}function gR(e){(0,_.useEffect)(()=>{let t=t=>{Yd(Pd(t),{view:`schematic`})?.action===`armNetLabel`&&(t.preventDefault(),e(`label`))};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e])}function _R(e,t,n,r){(0,_.useEffect)(()=>{if(e!==`label`&&e!==`vcc`)return;let i=i=>{i.key!==`Tab`||i.shiftKey||Pd(i).typing||(i.preventDefault(),r({at:n,initial:t||(e===`vcc`?`VCC`:``)}))};return window.addEventListener(`keydown`,i),()=>window.removeEventListener(`keydown`,i)},[e,t,n,r])}function vR({design:e,circuit:t,actions:n,pending:r,setTyped:i}){let a=(0,_.useMemo)(()=>new Set(t.annotations.locks.map(e=>e.part)),[t]);return(o,s,c)=>{let l=eR(e,t,o,c,s,a);if(!Array.isArray(l))return n.notify(l.blocked);let u=JL(o,c),d=rR(e,s,u);if(d&&!window.confirm(`This joins ${d} and ${u} into one net, a short circuit if they carry different voltages. Connect them anyway?`))return;let f=nR(e,o,c,s),p=f&&r.add(f),m=l[0]?.kind===`addTrace`?l[0].from:s;n.edit(l,tR(o,u,m)).then(e=>e||p&&r.drop(p)),o===`label`&&i(``)}}function yR({design:e,circuit:t,actions:n}){let r=(0,_.useMemo)(()=>new Set(t.annotations.locks.map(e=>e.part)),[t]);return(i,a)=>{let o=fR(e,t,i,a,r);if(`blocked`in o)return n.notify(o.blocked);if(o.edits.length===0)return;let s=`This joins ${i.text} and ${o.joins} into one net, a short circuit if they carry different voltages. Rename anyway?`;(!o.joins||window.confirm(s))&&n.edit(o.edits,o.summary)}}function bR(e){let{tool:t,typed:n,camera:r,design:i,setTyped:a,setEditing:o}=e,s=vR(e),c=yR(e),l=o;return{press:(e,a,o)=>{if(!t||!r)return!1;if(e.button===2)return o(),!0;if(e.button!==0||e.shiftKey)return!1;let c=Jn(i,a,mR/r.scale);return c?(t===`label`&&n===``?l({pin:c.pin,at:c.at,initial:``}):s(t,c.pin,n),!0):!1},submitName:(e,n)=>{let r=e.trim(),i=QL(r);if(i||!n)return i;n.rename?(l(null),c(n.rename,r)):t&&(l(null),n.pin?s(t,n.pin,r):a(r))},open:l}}function xR(e){let[t,n]=(0,_.useState)(null),[r,i]=(0,_.useState)(``),[a,o]=(0,_.useState)(null),s=(0,_.useCallback)(()=>{n(null),i(``),o(null)},[]);return{tool:t,typed:r,setTyped:i,editing:a,setEditing:o,arm:(0,_.useCallback)(t=>{e(),n(t),i(``),o(null)},[e]),disarm:s}}function SR(e){let{camera:t,cursor:n}=e,{tool:r,typed:i,setTyped:a,editing:o,setEditing:s,arm:c,disarm:l}=xR(e.onArm),u=hR(e.builtFrom),d=bR({...e,tool:r,typed:i,setTyped:a,setEditing:s,pending:u});_R(r,i,(0,_.useMemo)(()=>n??{x:t?.cx??0,y:t?.cy??0},[n,t]),d.open),HA(r!==null,l),gR(c);let f=u.visible.map(e=>e.label);return{tool:r,armed:r!==null,arm:c,disarm:l,press:(e,t)=>(o?.rename&&s(null),d.press(e,t,l)),rename:t=>{let n=pR(e.circuit,t);(!n||window.confirm(n))&&s({at:t.at,initial:t.text,rename:t})},editing:o,cancelName:()=>d.open(null),submitName:e=>d.submitName(e,o),typed:i,ghosts:f,ghostWires:u.visible.map(e=>e.wire)}}var CR=(e,t,n=!1)=>({start:e,...t?{pin:t}:{},corners:[],bends:[],flip:n}),wR=e=>[...e.bends,e.flip],TR=(e,t)=>An([e.start.at,...e.corners,t],wR(e)),ER=12,DR=(e,t)=>e.pin===t.pin&&e.end?.selector===t.end?.selector&&e.end?.at.x===t.end?.at.x&&e.end?.at.y===t.end?.at.y;function OR(e,t,n){let{start:r,corners:i}=t;if(cr(n,r))return{};let a=Gn(e,r,n);if(a)return`edits`in a?{...a,points:[]}:a;let o=[r,n].find(e=>e.selector.split(`.`)[0]?.includes(`~`));if(o)return{notice:`${o.label} has a repeated name and cannot be wired from the Studio`};let s=mr(e,r,n,i,wR(t));if(s.length===0)return{notice:`${r.label} and ${n.label} are already connected`};let c=lr(e,r,n);return c&&!window.confirm(`This wire joins ${c[0]} and ${c[1]} into one net, a short circuit if they carry different voltages. Connect them anyway?`)?{}:{edits:s,points:TR(t,n.at),summary:`connect ${r.label} to ${n.label}`}}function kR(e){let[t,n]=(0,_.useState)({}),r=(0,_.useRef)({}),i=(0,_.useCallback)(e=>{r.current=e,n(t=>DR(t,e)?t:e)},[]);return(0,_.useEffect)(()=>i({}),[e,i]),{under:t,setUnder:i,underRef:r}}function AR(e){let[t,n]=(0,_.useState)([]);return(0,_.useEffect)(()=>n(t=>t.every(t=>t.sentAt>e)?t:t.filter(t=>t.sentAt>e)),[e]),{visible:(0,_.useMemo)(()=>t.filter(t=>t.sentAt>e).map(e=>e.points),[t,e]),add:e=>{let t={points:e,sentAt:Date.now()};return n(e=>[...e,t]),t},drop:e=>n(t=>t.filter(t=>t!==e))}}function jR({drawing:e,setDrawing:t,setWiring:n,underRef:r,start:i,escape:a}){(0,_.useEffect)(()=>{let o=o=>{let s=Yd(Pd(o),{view:`schematic`,drawing:e!==null});if(s?.action===`wire`){if(s.preventDefault&&o.preventDefault(),e)return;let{end:t,pin:a}=r.current;return t?i(t,a):n(e=>!e)}if(s?.action===`removeCorner`&&e)return o.preventDefault(),t({...e,corners:e.corners.slice(0,-1),bends:e.bends.slice(0,-1)});if(s?.action===`flipBend`&&e)return o.preventDefault(),t({...e,flip:!e.flip});o.key===`Escape`&&pO(o)&&a()};return window.addEventListener(`keydown`,o),()=>window.removeEventListener(`keydown`,o)},[e,t,n,r,i,a])}function MR(e,t,n,r,i){return(0,_.useMemo)(()=>{let a=t.end?.at??(n&&Ee(n,r,i));return e&&a?TR(e,a):void 0},[e,t,n,r,i])}var NR=(e,t,n)=>({step:t,snap:n,...e?{from:e.corners.at(-1)??e.start.at}:{}});function PR(e,t,n,r,i){if(!t)return{};let a=ER/t.scale,o=Jn(e,r,a)?.pin;if(!n&&!o)return{};let s=Yn(e,r,a,i);return{...s?{end:s}:{},...o?{pin:o}:{}}}function FR(e,t,n,r){let[i,a]=(0,_.useState)(null);(0,_.useEffect)(()=>{i&&!e.schematic.drawings.some(e=>`bus:${e.id}`===i.bus.selector)&&a(null)},[e,i]);let o=(e,i,a)=>{let o=tr(e,a);i===`start`?n(CR(o,void 0)):t&&r(t,o)},s=(e,t)=>{let[n,...r]=e.members??[];if(n!==void 0&&r.length===0)return o(e,t,n);a({bus:e,role:t})};return{picking:i,open:s,pick:e=>{i&&(a(null),o(i.bus,i.role,e))},cancelPick:(0,_.useCallback)(()=>a(null),[]),start:(e,t)=>e.members?s(e,`start`):n(CR(e,t))}}function IR(e,t,n,r){return(i,a)=>{r(null);let o=OR(e,i,a);if(!(`edits`in o))return o.notice&&t.notify(o.notice);let s=n.add(o.points);t.edit(o.edits,o.summary).then(e=>e||n.drop(s))}}function LR(e){let{design:t,camera:n,step:r,snap:i}=e,[a,o]=(0,_.useState)(!1),[s,c]=(0,_.useState)(null),{under:l,setUnder:u,underRef:d}=kR(e.buildId),f=AR(e.builtFrom),p=IR(t,e.actions,f,c),m=FR(t,s,c,p);jR({drawing:s,setDrawing:c,setWiring:o,underRef:d,start:m.start,escape:()=>m.picking?m.cancelPick():s?c(null):o(!1)});let h=MR(s,(0,_.useMemo)(()=>m.picking?.role===`end`?{end:m.picking.bus}:l,[m.picking,l]),e.cursor,r,i),g=(0,_.useMemo)(()=>[s?.pin,l.pin].filter(e=>e!==void 0),[s,l]),v=e=>PR(t,n,a||s!==null,e,NR(s,r,i)),y=(e,o)=>RR({design:t,camera:n,wiring:a,drawing:s,setDrawing:c,step:r,snap:i,finish:p,underAt:v,picks:m},e,o),b=(0,_.useCallback)(()=>{o(!1),c(null),m.cancelPick()},[m.cancelPick]),x=l.end!==void 0&&(a||s!==null||l.pin!==void 0&&Un(t,l.pin));return{wiring:a,toggleWiring:()=>{b(),o(!a)},cancel:b,drawing:s,under:l,pendingWires:f.visible,preview:h,activePins:g,overPin:x,press:y,hover:e=>u(v(e)),leave:()=>u({}),picking:m.picking,pick:m.pick,cancelPick:m.cancelPick}}function RR(e,t,n){if(!e.camera)return!1;if(e.picks.picking)return e.picks.cancelPick(),!0;if(t.button===2&&e.drawing)return e.setDrawing(null),!0;if(t.button===1||t.button===2||t.shiftKey)return!1;if(e.drawing){let t=Yn(e.design,n,ER/e.camera.scale,NR(e.drawing,e.step,e.snap));return t?.members&&!e.drawing.start.port?.bus?e.picks.open(t,`end`):t?e.finish(e.drawing,t):zR(e.drawing,n,e,e.setDrawing),!0}let{end:r,pin:i}=e.underAt(n);return!r||!e.wiring&&!(i&&Un(e.design,i))?!1:(e.picks.start(r,i),!0)}function zR(e,t,n,r){let i=Ee(t,n.step,n.snap),a=e.corners[e.corners.length-1]??e.start.at;(i.x!==a.x||i.y!==a.y)&&r({...e,corners:[...e.corners,i],bends:[...e.bends,e.flip]})}var BR=`This wire's new trace is still being built; reshape it again when the build is done`;function VR(e,t,n){let r=e.filter(e=>e.from===t&&e.to===n).length;return r===0?`wire:${t}|${n}`:`wire:${t}|${n}#${r+1}`}var HR=(e,t)=>t.startsWith(`net.`)?t:Rn(e,t)?.id,UR=(e,t)=>{let[n,r]=[HR(e,t.from??``),HR(e,t.to??``)];return n&&r?`wire:${n}|${r}`:void 0};function WR(e,t){let{writer:n}=t;if(n.kind!==`engine`)return{newTrace:!1,wire:t.id};if(n.onWire?.trace){let t=UR(e,n.onWire.trace);return t?{newTrace:!0,wire:t}:{newTrace:!0}}let[r,i]=[HR(e,n.from),HR(e,n.to)];return r&&i?{newTrace:!0,wire:VR(e.circuit.connections,r,i)}:{newTrace:!0}}function GR(e,t){return e.some(e=>e.id===t&&e.newTrace)?BR:null}function KR(e,t,n){let r=e.filter(e=>e.sentAt<=t),i=r.length===0?e:e.filter(e=>e.sentAt>t),a=r.filter(e=>e.newTrace&&e.wire!==void 0&&n.has(e.wire));return{waiting:i,follow:e=>{let t=e.wires.map(e=>a.find(t=>t.id===e)?.wire??e);return e.all(e.names,t,e.labels,e.drawings)}}}function qR(e,t,n,r=gr){let i=K(e,t,n);return i?q(e,i,r):mE}function JR(e,t,n,r,i,a){let o=e.schematic.wires.filter(e=>e.id!==n.id).map(e=>e.points);return fE(sE(e.schematic.drawings).filter(e=>Jw(t.model,i,e.id,[`x`,`y`])===null),a??n.points,fl(r),o)}function YR(e,t,n,r,i,a,o){let s=Nl(e,n,r,a,o);return Array.isArray(s)?{edits:s.length===0?s:[...s,...JR(e,t,n,r,a,o)],summary:`${i} ${CE(e,n)}`,points:fl(r),...WR(e,n)}:s}function XR(e,t,n,r,i=gr,a){let o=K(e,t,n);return o?YR(e,t,o,r,`reshape`,i,a):{blocked:mE}}function ZR(e,t,n,r,i=gr,a){let o=K(e,t,n);if(!o)return{blocked:mE};let s=a!==void 0&&!Ml(a,o.points)?null:TE(e,o,i);return s===null?YR(e,t,o,dl(a??o.points,r),`remove a corner of`,i,a):{blocked:s}}function QR(e,t,{design:n,builtFrom:r,onSelect:i}){(0,_.useEffect)(()=>{let{waiting:a,follow:o}=KR(e,r,new Set(n.schematic.wires.map(e=>e.id)));a!==e&&(t(e=>e.filter(e=>e.sentAt>r)),i(o))},[e,t,n,r,i])}function $R(e){let{design:t,circuit:n,actions:r,locked:i,builtFrom:a}=e,[o,s]=(0,_.useState)([]);QR(o,s,e);let c=(0,_.useMemo)(()=>o.filter(e=>e.sentAt>a).map(({id:e,points:t})=>({id:e,points:t})),[o,a]),l=(0,_.useCallback)(e=>GR(o,e)??qR(t,n,e,i),[o,t,n,i]),u=(0,_.useCallback)((e,t)=>{if(`blocked`in t)return r.notify(t.blocked);if(t.edits.length===0)return;let{edits:n,summary:i,...a}=t,o={id:e,...a,sentAt:Date.now()};s(t=>[...t.filter(t=>t.id!==e),o]),r.edit(n,i).then(e=>e||s(e=>e.filter(e=>e!==o)))},[r]),d=(0,_.useCallback)(e=>c.find(t=>t.id===e)?.points,[c]);return{pending:c,blocker:l,commit:(0,_.useCallback)((e,r)=>u(e,XR(t,n,e,r,i,d(e))),[u,t,n,i,d]),dropCorner:(0,_.useCallback)((e,r)=>{let a=GR(o,e);u(e,a?{blocked:a}:ZR(t,n,e,r,i,d(e)))},[u,o,t,n,i,d])}}async function ez(e,t){return`blocked`in e?(t.notify(e.blocked),!1):t.edit(e.edits,e.summary)}function tz({design:e,circuit:t,actions:n,locked:r,selection:i}){let a=(0,_.useCallback)((n,i,a)=>IE(e,t,n,i,r,a),[e,t,r]),o=(0,_.useCallback)((t,n)=>cm(e,t,n),[e]),s=(0,_.useCallback)(t=>vE(e,t),[e]),c=(0,_.useCallback)(t=>{let n=e.schematic.labels.find(e=>e.id===t);return n&&Tp(e.circuit.nets,n.net)},[e]);return Gx({removeCorners:()=>{let a=i.soleWire;if(a===void 0)return n.notify(`Select one wire first.`);ez(LE(e,t,a,r),n)}}),(0,_.useMemo)(()=>({net:s,removal:a,labelRemoval:o,labelNet:c}),[s,a,o,c])}function nz(e){let{design:t,camera:n,selection:r,wiring:i}=e,{pending:a,blocker:o,commit:s,dropCorner:c}=$R(e),l=(0,_.useMemo)(()=>nu(t.schematic.wires,a),[t.schematic.wires,a]),u=(0,_.useCallback)(e=>e===void 0?void 0:l.find(t=>t.id===e),[l]),d=(0,_.useMemo)(()=>{let e=e=>n?Yc(l,e,Gc(n.scale)/n.scale):void 0;return i?{at:e,lines:l}:{at:e,lines:l,drag:{points:e=>u(e)?.points,blocker:o,commit:s}}},[l,n,u,o,s,i]),f={at:(e,t)=>n?Jl(d.drag,t,e,n.scale):void 0,drop:c};return{hits:d,selected:(0,_.useMemo)(()=>u(r.soleWire),[u,r.soleWire]),menuWire:(0,_.useMemo)(()=>r.size===0?u(r.wires.at(-1)):void 0,[u,r]),lineOf:u,keys:tz(e),pending:a,corners:f}}function rz({design:e,circuit:t,camera:n,locked:r}){let{drawings:i}=e.schematic,a=(0,_.useCallback)(e=>e===void 0?void 0:i.find(t=>t.id===e),[i]);return{hits:(0,_.useMemo)(()=>({at:e=>n?nk(i,e,6/n.scale,n.scale):void 0,boxes:ik(i),origin:e=>{let t=a(e);return t&&Xw(t)},blocker:e=>{let n=a(e);return n?Yw(t.model,r,n):null}}),[i,n,a,t.model,r]),removal:(0,_.useCallback)(e=>rT(t.model,i,r)(e),[t.model,i,r]),drawingOf:a}}var iz=7,az=20;function oz(e){let{state:t}=e;if(t?.tool===`text`&&t.points[0])return{label:`Text`,initial:``,at:t.points[0]};let n=t?.points.at(-1);if(t?.tool===`bus`&&t.naming&&n)return{label:`Bus name`,initial:e.busName(),at:n}}function sz({draw:e,camera:t,size:n}){let r=oz(e);if(!r||!t)return null;let i=V(t,n,r.at);return(0,X.jsx)(cz,{left:i.x-iz,top:i.y-az,field:r,draw:e},r.label)}function cz({left:e,top:t,field:n,draw:r}){let[i,a]=(0,_.useState)(n.initial),[o,s]=(0,_.useState)(),c=(0,_.useRef)(null);return(0,_.useEffect)(()=>{let e=requestAnimationFrame(()=>c.current?.focus());return()=>cancelAnimationFrame(e)},[e,t]),(0,X.jsxs)(`form`,{className:`label-name`,style:{left:e,top:t},onPointerDown:e=>e.stopPropagation(),onSubmit:e=>{e.preventDefault(),s(r.submitText(i))},children:[(0,X.jsx)(`input`,{ref:c,autoFocus:!0,"aria-label":n.label,placeholder:n.label,value:i,style:{fontFamily:ya},onFocus:e=>n.initial!==``&&e.currentTarget.select(),onChange:e=>a(e.target.value),onKeyDown:e=>{e.key===`Escape`&&(e.stopPropagation(),r.cancelText())}}),o&&(0,X.jsx)(`span`,{role:`alert`,children:o})]})}function lz(e,t,n){switch(n){case`ArrowDown`:return{index:(e+1)%t};case`ArrowUp`:return{index:(e-1+t)%t};case`Home`:return{index:0};case`End`:return{index:t-1};case`Enter`:return{pick:e};case`Escape`:return{cancel:!0};default:return}}var uz=21,dz=6,fz=12,pz=e=>Math.min(e*uz+dz,220);function mz(e,t,n){let r=Math.min(e.x+fz,t.width-100),i=Math.min(e.y+fz,t.height-pz(n));return{left:Math.max(r,0),top:Math.max(i,0)}}function hz({wire:e,camera:t,size:n}){let{picking:r}=e;if(!r||!t)return null;let i=r.bus.members??[],{left:a,top:o}=mz(V(t,n,r.bus.at),n,i.length),s=`${r.bus.selector}:${r.bus.at.x}:${r.bus.at.y}`;return(0,X.jsx)(gz,{left:a,top:o,name:r.bus.label,members:i,wire:e},s)}function gz({left:e,top:t,name:n,members:r,wire:i}){let[a,o]=(0,_.useState)(0),s=(0,_.useRef)(null);return(0,_.useEffect)(()=>{let e=requestAnimationFrame(()=>s.current?.focus());return()=>cancelAnimationFrame(e)},[]),(0,_.useEffect)(()=>s.current?.children[a]?.scrollIntoView({block:`nearest`}),[a]),(0,X.jsx)(`ul`,{ref:s,className:`bus-members`,role:`listbox`,"aria-label":`Members of ${n}`,"aria-activedescendant":`bus-member-${a}`,tabIndex:0,style:{left:e,top:t},onPointerDown:e=>e.stopPropagation(),onBlur:e=>{e.currentTarget.contains(e.relatedTarget)||i.cancelPick()},onKeyDown:e=>{let t=lz(a,r.length,e.key);if(!t)return;if(e.preventDefault(),e.stopPropagation(),`index`in t)return o(t.index);if(`cancel`in t)return i.cancelPick();let n=r[t.pick];n!==void 0&&i.pick(n)},children:r.map((e,t)=>(0,X.jsx)(`li`,{id:`bus-member-${t}`,role:`option`,"aria-selected":t===a,onPointerEnter:()=>o(t),onClick:()=>i.pick(e),children:e},e))})}var _z={finishShape:{type:`finish`},removeCorner:{type:`removeCorner`},flipBend:{type:`flip`}};function vz(e){let[t,n]=(0,_.useState)([]);return(0,_.useEffect)(()=>n(t=>t.every(t=>t.sentAt>e)?t:t.filter(t=>t.sentAt>e)),[e]),{visible:(0,_.useMemo)(()=>t.filter(t=>t.sentAt>e).map(e=>e.drawing),[t,e]),add:(0,_.useCallback)(e=>{let t={drawing:e,sentAt:Date.now()};return n(e=>[...e,t]),t},[]),drop:(0,_.useCallback)(e=>n(t=>t.filter(t=>t!==e)),[])}}function yz(e,t){let[n,r]=(0,_.useState)([]);return(0,_.useEffect)(()=>{let i=n.filter(t=>e.schematic.drawings.some(e=>e.id===t));i.length!==0&&(t(()=>_o.none.addDrawings(i)),r(e=>e.filter(e=>!i.includes(e))))},[e,n,t]),{wait:(0,_.useCallback)(e=>r(t=>[...t,e]),[]),forget:(0,_.useCallback)(e=>r(t=>t.filter(t=>t!==e)),[])}}function bz(e){let[t,n]=(0,_.useState)(!1);return(0,_.useEffect)(()=>{if(!e){n(!1);return}let t=e=>n(e.shiftKey),r=()=>n(!1);return window.addEventListener(`keydown`,t),window.addEventListener(`keyup`,t),window.addEventListener(`blur`,r),()=>{window.removeEventListener(`keydown`,t),window.removeEventListener(`keyup`,t),window.removeEventListener(`blur`,r)}},[e]),t}function xz(e){(0,_.useEffect)(()=>{let t=t=>{let n=Yd(Pd(t),{view:`schematic`})?.action;n&&M(n)&&(t.preventDefault(),e(j[n]))};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e]),Gx(Object.fromEntries(k.map(t=>[t,()=>e(j[t])])))}function Sz(e,t){(0,_.useEffect)(()=>{if(!e)return;let n=e.points.length>0,r=e=>{Xd(Pd(e))&&(e.stopPropagation(),t({type:`cancel`}))},i=e=>{let r=n?Yd(Pd(e),{view:`schematic`,drawing:!0})?.action:void 0,i=r===void 0?void 0:_z[r];i&&(e.preventDefault(),t(i))};return window.addEventListener(`keydown`,r,!0),window.addEventListener(`keydown`,i),()=>{window.removeEventListener(`keydown`,r,!0),window.removeEventListener(`keydown`,i)}},[e,t])}function Cz(e,t){let[n,r]=(0,_.useState)(null),i=(0,_.useRef)(n);return i.current=n,{state:n,send:(0,_.useCallback)(e=>{let n=i.current;if(!n)return;let a=fI(n,e);i.current=a.state,r(a.state),a.drawing&&t(n.tool,a.drawing)},[t]),arm:(0,_.useCallback)(t=>{e(),i.current=JF(t),r(i.current)},[e]),disarm:(0,_.useCallback)(()=>{i.current=null,r(null)},[])}}function wz(e,t){let{circuit:n,actions:r}=e,{add:i,drop:a,visible:o}=t,{wait:s,forget:c}=yz(e.design,e.onSelect),l=(0,_.useRef)([]);return{write:(0,_.useCallback)((e,t)=>{let{model:u}=n;l.current=l.current.filter(e=>!u.drawings.some(t=>t.name===e||t.id===e));let d=vI(t,u,l.current),f=d.name??``,p=vT(u,f,o.flatMap(e=>e.kind===`bus`?[e.name]:[]));l.current=[...l.current,f];let m=i(gI(t,p));s(p),r.edit([d],bI(e,f)).catch(()=>!1).then(e=>{e||(l.current=l.current.filter(e=>e!==f),a(m),c(p))})},[n,r,s,c,i,a,o]),taken:l}}function Tz(e,t,n,r){return{submitText:r=>{let i=e?.tool===`bus`?hT(n,r):void 0;return i||t({type:`text`,text:r}),i},busName:()=>mT(n,r.current)}}function Ez(e){let{camera:t,cursor:n,step:r,snap:i}=e,a=vz(e.builtFrom),{write:o,taken:s}=wz(e,a),{state:c,send:l,arm:u,disarm:d}=Cz(e.onArm,o),f=bz(c!==null),p=(0,_.useRef)(void 0);xz(u),Sz(c,l);let m=(0,_.useMemo)(()=>c&&n?hI(c,YF(n,r,i),f):void 0,[c,n,r,i,f]),h=(e,n)=>{if(!c||!t||e.button===1)return!1;if(ZF(c,e.button)&&e.preventDefault?.(),e.button===2)return l({type:`cancel`}),!0;let a={at:{x:n.x*t.scale,y:n.y*t.scale},time:Date.now()},o=XF(p.current,a);return p.current=o?void 0:a,l({type:`press`,at:YF(n,r,i),shift:e.shiftKey,double:o}),!0},g=(0,_.useMemo)(()=>m?[...a.visible,m]:a.visible,[a.visible,m]);return{state:c,tool:c?.tool??null,armed:c!==null,busy:c!==null&&c.points.length>0,arm:u,disarm:d,press:h,release:e=>{c&&l({type:`release`,at:YF(e,r,i)})},...Tz(c,l,e.circuit.model,s),cancelText:()=>l({type:`cancel`}),pending:g}}var Dz=.2,Oz=.2,kz=1.2,Az=.6,jz=.4,Mz=e=>Dt(Math.ceil(e/Dz-1e-9)*Dz),Nz=e=>Math.max(0,...e.map(e=>e.name.length))*Et*Tt[`pin-name`];function Pz(e){let t=t=>e.filter(e=>e.side===t),n=t=>Math.max(0,...e.filter(e=>t.includes(e.side)).map(e=>e.order)),r=(n([`top`,`bottom`])+1)*Dz,i=(n([`left`,`right`])+1)*Dz,a=Nz(t(`left`))+Nz(t(`right`))+jz;return{width:Mz(Math.max(kz,r,a)),height:Mz(Math.max(Az,i))}}function Fz(e,t,n,r){let i=Dt(t*Dz);return e===`left`?{edge:Ot(0,-i),end:Ot(-.2,-i)}:e===`right`?{edge:Ot(n,-i),end:Ot(n+Oz,-i)}:e===`top`?{edge:Ot(i,0),end:Ot(i,Oz)}:{edge:Ot(i,-r),end:Ot(i,-r-Oz)}}function Iz(e,t={}){let n=Pz(e),r=Math.max(n.width,Mz(t.width??0)),i=Math.max(n.height,Mz(t.height??0));return{width:r,height:i,needed:n,pins:e.map(e=>({name:e.name,side:e.side,order:e.order,bus:e.bus===!0,...Fz(e.side,e.order,r,i)}))}}function Lz(e,t,n,r){let i=e===`left`||e===`right`?-t.y:t.x,a=Math.max(1,Math.round((e===`left`||e===`right`?r:n)/Dz)-1);return Math.min(a,Math.max(1,Math.round(i/Dz)))}function Rz(e,t,n){let[r]=[[`left`,Math.abs(e.x)],[`right`,Math.abs(e.x-t)],[`top`,Math.abs(e.y)],[`bottom`,Math.abs(e.y+n)]].reduce((e,t)=>t[1]<e[1]?t:e);return{side:r,order:Lz(r,e,t,n)}}function zz(e,t){let n=gn(e,t),r=e.schematic.symbols.find(e=>e.component===t);if(n&&r)return{instance:n,placed:r,layout:Iz(n.ports,n.size)}}var Bz=(e,t)=>ef(t,e.placed),Vz=(e,t)=>$d({x:t.x-e.placed.x,y:t.y-e.placed.y},-e.placed.rotation);function Hz(e,t){return t.flatMap(t=>{let n=zz(e,t);if(!n)return[];let{instance:r,layout:i}=n;return[...i.pins.map(e=>({kind:`pin`,instance:t,file:r.file,port:e.name,at:Bz(n,e.edge)})),{kind:`corner`,instance:t,file:r.file,at:Bz(n,{x:i.width,y:-i.height})}]})}function Uz(e,t,n){let r;for(let i of e){let e=Math.hypot(i.at.x-t.x,i.at.y-t.y);e<=n&&(!r||e<r.distance)&&(r={handle:i,distance:e})}return r?.handle}function Wz(e,t,n){let r=zz(e,t.instance),i=r?.instance.ports.find(e=>e.name===t.port);if(!r||!i)return{message:`${t.instance} has no port ${t.port} any more`};let a=Rz(Vz(r,n),r.layout.width,r.layout.height);if(a.side===i.side&&a.order===i.order)return{message:`${i.name} stays where it is`};let o=r.instance.ports.find(e=>e!==i&&e.side===a.side&&e.order===a.order),s=[{kind:`setProps`,part:i.name,props:{side:a.side,order:a.order}}];o&&s.push({kind:`setProps`,part:o.name,props:{side:i.side,order:i.order}});let c=o?`, ${o.name} to ${i.side} ${i.order}`:``;return{file:r.instance.file,edits:s,summary:`Move port ${i.name} of ${r.instance.sheet} to ${a.side} ${a.order}${c}`}}var Gz=e=>Math.round(Math.ceil(e/Dz-1e-9)*Dz*1e3)/1e3;function Kz(e,t,n){let r=zz(e,t.instance);if(!r)return{message:`${t.instance} is gone`};let i=Vz(r,n),a=Math.max(r.layout.needed.width,Gz(i.x)),o=Math.max(r.layout.needed.height,Gz(-i.y));return a===r.layout.width&&o===r.layout.height?{message:`${r.instance.sheet} keeps its size`}:{file:r.instance.file,edits:[{kind:`setSheetSize`,width:a,height:o}],summary:`Size the ${r.instance.sheet} symbol to ${a} × ${o}`}}var qz=6;function Jz({design:e,selection:t,camera:n,actions:r}){let i=(0,_.useMemo)(()=>Hz(e,t.names),[e,t.names]),[a,o]=(0,_.useState)(),s=(0,_.useRef)(void 0),c=e=>{s.current=e,o(e)};return{press:(e,t)=>{if(e.button!==0||e.shiftKey||e.ctrlKey||e.metaKey||!n||i.length===0)return!1;let r=Uz(i,t,qz/n.scale);return c(r),r!==void 0},release:t=>{let n=s.current;if(!n)return;c(void 0);let i=n.kind===`pin`?Wz(e,n,t):Kz(e,n,t);if(`message`in i)return r.notify(i.message);r.editFile(i.file,i.edits,i.summary)},hint:a===void 0?void 0:a.kind===`pin`?`Drop ${a.port} on any side of ${a.instance}'s box; the release writes its side and order in ${a.file}.`:`Drop the corner to size ${a.instance}'s box; the release writes width and height in ${a.file}.`,holding:a!==void 0}}var Yz=`noConnect`;function Xz(e){return typeof e==`string`?[...new Set(e.split(`,`).map(e=>e.trim()).filter(e=>e!==``))]:[]}var Zz=(e,t)=>e.names.includes(t)||`pin${e.number}`===t;function Qz(e,t){let n=Xz(e);return(n.some(e=>Zz(t,e))?n.filter(e=>!Zz(t,e)):[...n,`pin${t.number}`]).join(`,`)}function $z(e,t,n){let r;for(let i of e.symbols)for(let[e,a]of Object.entries(i.pinEnds)){let o=Math.hypot(a.x-t.x,a.y-t.y);o<=n&&(!r||o<r.distance)&&(r={component:i.component,pin:e,end:a,distance:o})}return r&&{component:r.component,pin:r.pin,end:r.end}}function eB(e,t,n){let r=$z(e.sheet,t,n);if(!r)return{message:`Click the end of a pin to put a no connect flag on it.`};let i=e.components.find(e=>e.id===r.component)?.pins.find(e=>e.id===r.pin),a=e.parts.find(e=>e.name===r.component);if(!i||!a)return{message:`${r.pin} belongs to a part this file does not write; flag it in its own file.`};if(e.locked.has(a.name))return{message:`${a.name} is locked; unlock it to change its no connect flags.`};if(!a.editable)return{message:`${a.name} is read-only (${a.readonlyReason??`written as an expression`}).`};let o=a.props[Yz];if(o&&o.literal===void 0)return{message:`${a.name}.${Yz} is an expression (${o.source}); change it in the code.`};let s=Qz(o?.literal,i),c=`${Xz(s).length<Xz(o?.literal).length?`remove the no connect flag from`:`flag no connect on`} ${r.pin}`;return{edit:{kind:`setProps`,part:a.name,props:{[Yz]:s===``?null:s}},summary:c}}function tB(e,t,n){let[r,i]=[n.x-t.x,n.y-t.y],a=r*r+i*i,o=a===0?0:Math.max(0,Math.min(1,((e.x-t.x)*r+(e.y-t.y)*i)/a));return{x:t.x+o*r,y:t.y+o*i}}function nB(e,t,n){let r;for(let i of e.wires)for(let e=1;e<i.points.length;e++){let a=tB(t,i.points[e-1],i.points[e]),o=Math.hypot(a.x-t.x,a.y-t.y);o<=n&&(!r||o<r.distance)&&(r={wire:i.id,point:a,distance:o})}return r&&{wire:r.wire,point:{x:H(r.point.x),y:H(r.point.y)}}}function rB(e,t,n){let r=nB(e,t,n);if(!r)return{message:`Click a wire to put a junction on it.`};let i=e.pages?.find(e=>e.wires.includes(r.wire))?.name;return{edit:{kind:`addDrawing`,tag:`junction`,props:{x:r.point.x,y:r.point.y},...i&&i!==`Main`?{page:i}:{}},summary:`add a junction at ${r.point.x}, ${r.point.y}`}}var iB=12,aB={noConnect:`No connect flag: click the end of a pin to flag it (again to take the flag off). Esc to stop.`,junction:`Junction: click a wire to put a junction on it. Esc to stop.`};function oB(e){let[t,n]=(0,_.useState)(null),r=(0,_.useRef)(e);r.current=e;let i=(0,_.useCallback)(e=>{r.current.onArm(),n(e)},[]),a=(0,_.useCallback)(()=>n(null),[]);return Gx({noConnect:()=>i(`noConnect`),junction:()=>i(`junction`)}),(0,_.useEffect)(()=>{let e=e=>{let r=Pd(e);if(Xd(r)&&t)return e.stopPropagation(),n(null);Yd(r,{view:`schematic`})?.action===`junction`&&(e.preventDefault(),i(`junction`))};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[t,i]),{tool:t,armed:t!==null,arm:i,disarm:a,press:(e,i)=>{let{design:a,circuit:o,actions:s,camera:c,locked:l}=r.current;if(!t||!c||e.button===1)return!1;if(e.button===2)return n(null),!0;let u=iB/c.scale,d=t===`junction`?rB(a.schematic,i,u):eB({sheet:a.schematic,components:a.circuit.components,parts:o.model.parts,locked:l},i,u);return`message`in d?s.notify(d.message):s.edit([d.edit],d.summary),!0},hint:t?aB[t]:void 0}}var sB={cx:0,cy:0,scale:60},cB=.06,lB=12;function uB(e,t,n,r){return{sheet:(0,_.useMemo)(()=>{let t=fP(e.schematic,r);return n.length===0&&t===e.schematic.labels?e.schematic:{...e.schematic,wires:[...nu(e.schematic.wires,n)],labels:[...t]}},[e.schematic,n,r]),selected:(0,_.useMemo)(()=>t&&nu([t],n)[0],[t,n])}}function dB(e,t){let{design:n,border:r,camera:i,size:a,moving:o,boxes:s,hover:c,selection:l,locked:u,circuit:d,gesture:f,movingLabels:p,hoverLabel:m,hoverDrawing:h,hoverWire:g,palette:v,highlight:y,markers:b,activeViolation:x,grid:S,texts:C,theme:w}=t,{wiring:T,drawing:E,activePins:D,pendingWires:O,preview:k}=t.wire,{ghosts:A,ghostWires:j,armed:M}=v,ee=t.draw.pending,te=uB(n,t.selectedWire,t.wireShapes,o),ne=te.selected,N=(0,_.useMemo)(()=>Df(te.sheet,C.moves),[te.sheet,C.moves]);(0,_.useEffect)(()=>{let t=i??sB,n=Mo(w);Fo(n);let _=ID(n),v=Pl(n),te=dO(e.current,a,t,n.background,(e,t,r,i)=>nL(e,t,r,S,i,n));if(!te)return;let{ctx:P,ratio:F}=te;gL(P,t,a,r,F),_c(P,N,{camera:t,size:a},{ratio:F,showPins:T||E!==null||M,activePins:D,pending:[...O,...j,...p.map(e=>e.wire)],movingLabels:p,ghostLabels:A,selectedWires:l.wires,selectedLabels:l.labels,selectedDrawings:l.drawings,...o?.drawings?{movingDrawings:o.drawings}:{},pendingDrawings:ee,...y?{highlight:y}:{},...o?{moving:{components:o.names,by:o.offset}}:{},violations:b,...x?{activeViolation:x}:{}}),P.setTransform(F,0,0,F,0,0),k&&WD(P,t,a,k,`drawing`,n.wire,F),fO(P,t,a,{view:`schematic`,boxes:s,moving:o,hover:E?void 0:c,selection:l,locked:u,marks:d.annotations.marks,gesture:f,look:_,ratio:F}),m&&!E&&!f&&LD(P,t,a,Dr(m),{x:0,y:0},`hover`,_,F),GD(P,{camera:t,size:a},C.shown,{selected:l.texts,hover:E||f?void 0:C.hover},_,F),h&&!l.hasDrawing(h.id)&&!E&&!f&&LD(P,t,a,rk(h),{x:0,y:0},`hover`,_,F),!g||l.hasWire(g.id)||T||E||f||Ul(P,t,a,g.points,v,F),ne&&!p.some(e=>e.hideWire===ne.id)&&Wl(P,t,a,ne.points,v,F)},[e,N,r,i,a,T,E,D,O,k,o,p,m,h,g,ne,s,c,l,u,d,f,A,j,M,ee,y,b,x,S,C,w])}function fB({step:e,setStep:t,keep:n}){return(0,X.jsxs)(Ay,{children:[(0,X.jsx)(bO,{step:e,options:fg(`schematic`),onChange:t}),(0,X.jsx)(xO,{...n,title:`Write the faded symbols' positions into the code as schX and schY`})]})}function pB({boxes:e,wire:t,labels:n,filter:r,wires:i,drawings:a,texts:o,setCursor:s}){let[c,l]=(0,_.useState)({kind:`canvas`});return{part:c.kind===`part`?c.name:void 0,label:c.kind===`label`?c.label:void 0,wire:c.kind===`wire`?c.id:void 0,drawing:c.kind===`drawing`?c.id:void 0,text:c.kind===`text`?c.id:void 0,over:c.kind!==`canvas`,at:s=>{t.hover(s),l(eA(e,n,s,{selection:_o.none,armed:null,filter:r},i,a,o))},leave:()=>{l({kind:`canvas`}),s(void 0),t.leave()}}}function mB({wrapRef:e,canvasRef:t,size:n,camera:r,cursor:i,pointer:a,onLeave:o,cursorStyle:s,wire:c,palette:l,note:u,draw:d,gesture:f,rotateHeld:p,snap:m,empty:h,symbolHint:g,label:_,markHint:v}){let y=g??v??vB(c)??QI(l)??TI(d.state)??u.hint;return(0,X.jsxs)(`div`,{className:`schematic-canvas`,ref:e,style:{cursor:s},...a,onPointerLeave:o,onContextMenu:e=>e.preventDefault(),children:[(0,X.jsx)(`canvas`,{ref:t,style:{width:n.width,height:n.height},role:`img`,"aria-label":`Schematic. Drag symbols, net labels and drawings to move them, click a wire to select it, Shift or Ctrl click parts, wires, net labels and drawings to add them, drag a wire or its corner handles to reshape it, drag the background to select, drag with the right button to pan, scroll to zoom. Double click a net label to rename its net. Click a free pin or press W over a pin to draw a wire. Place → Bus draws a bus, and a wire that ends on a bus picks one of its members. Place → Polyline, Arc, Circle, Rectangle and Text draw on the sheet.`}),y&&(0,X.jsx)(`div`,{className:`canvas-top`,children:(0,X.jsx)(`div`,{className:`canvas-hint`,children:y})}),(0,X.jsx)($I,{palette:l,camera:r,size:n}),(0,X.jsx)(sz,{draw:d,camera:r,size:n}),(0,X.jsx)(hz,{wire:c,camera:r,size:n}),(0,X.jsx)(vF,{state:_}),(0,X.jsx)(SO,{cursor:i,zoom:(r??sB).scale,detail:c.under.end?.label,gesture:f,rotateHeld:p,snap:m}),h&&(0,X.jsx)(`p`,{className:`empty`,children:`This schematic has no parts yet.`})]})}function hB(e,t,n){zL(r=>{let i=e.schematic.labels.find(e=>e.id===r.labelId);i?t.rename(i):n.notify(`That label is gone; right click it again.`)})}function gB(e){let t=(0,_.useRef)(void 0),n=(0,_.useMemo)(()=>CS(e.schematic),[e.schematic]);return(0,_.useMemo)(()=>{let e=kL(t.current,n);return t.current=e,e},[n])}function _B(e,t){let n=(0,_.useRef)(void 0);(0,_.useEffect)(()=>{AL(n.current,e)&&t(),n.current=e},[e,t])}function vB(e){return e.picking?`Pick the member of ${e.picking.bus.label} to connect: arrow keys and Enter, or a click. Esc closes the list.`:e.drawing?`From ${e.drawing.start.label}: click the sheet for a corner, then a pin, a wire, a bus or a net label to finish. Backspace removes a corner, Esc cancels.`:e.wiring?`Click a pin or a bus to start a wire. Esc stops wiring.`:void 0}function yB(e,t){return(0,_.useMemo)(()=>Dp(e,t),[e,t])}function bB(e,t,n){return(0,_.useMemo)(()=>{let r=tu(e?.kind===`reshape`?e:void 0,t);return n&&n.length>0?[...n,...r]:r},[e,t,n])}function xB(e,t,n){return(0,_.useMemo)(()=>e&&e.sentAt>t?lP(e,n):void 0,[e,t,n])}function SB(e,t,n,r){let i=RL(e,(0,_.useMemo)(()=>t?.kind===`label`&&t.moved&&!t.blocker?{id:t.label.id,at:t.at}:void 0,[t]));return(0,_.useMemo)(()=>{let e=[...i?[i]:[],...r??[]];return e.length===0?n:[...e,...n.filter(t=>!e.some(e=>e.id===t.id))]},[i,n,r])}function CB({design:e,builtFrom:t,camera:n,cursor:r,fit:i,wire:a,palette:o,drawBusy:s,highlightNets:c,onHighlight:l,keys:u,texts:d}){let f=(0,_.useRef)(void 0);f.current=r;let p=(0,_.useCallback)(()=>n&&f.current?wp(e,f.current,lB/n.scale):void 0,[e,n]),m=(0,_.useCallback)(t=>Op(e,t),[e]),{rotateHeld:h,keyMove:g}=kP({...u,paused:a.drawing!==null||s,fit:i,netUnderPointer:p,netsOf:m,onHighlight:l,texts:d}),{wiring:v,drawing:y}=a,{disarm:b}=o;return(0,_.useEffect)(()=>{(v||y)&&b()},[v,y,b]),Gx({wire:()=>{b(),v||a.toggleWiring()},netLabel:()=>o.arm(`label`),groundFlag:()=>o.arm(`gnd`),powerFlag:()=>o.arm(`vcc`)}),Gx({tidySheet:()=>nt(e,u.blockerFor,u.actions,u.circuit)}),{highlight:yB(e,c),rotateHeld:h,keyMoving:xB(g,t,u.layout.anchors)}}function wB(e,t,n,r,i){let{wiring:a,cancel:o}=e,{tool:s,disarm:c}=t,{which:l,disarm:u}=n,{disarm:d}=r,{disarm:f}=i,p=my(a,s)??hy(r.tool)??i.tool??VA(l);(0,_.useEffect)(()=>{yy({active:p,stop:()=>{c(),o(),u(),d(),f()}})},[p,c,o,u,d,f]),(0,_.useEffect)(()=>xy,[])}function TB(e,t,n,r,i){let{cancel:a,wiring:o,drawing:s}=t,{disarm:c,armed:l}=n,{disarm:u,armed:d}=r,{disarm:f,armed:p}=i,m=(0,_.useCallback)(()=>{c(),a(),u(),f()},[c,a,u,f]),h=oB({...e,onArm:m}),g=h.disarm;return(0,_.useEffect)(()=>{(o||s||l||d||p)&&g()},[o,s,l,d,p,g]),h}function EB(e,t){let{cancel:n,wiring:r,drawing:i}=e,{disarm:a,armed:o}=t,s=UA((0,_.useCallback)(()=>{a(),n()},[a,n])),c=s.disarm;return(0,_.useEffect)(()=>{(r||i||o)&&c()},[r,i,o,c]),s}function DB(e,t,n,r){let{cancel:i,wiring:a,drawing:o}=t,{disarm:s,armed:c}=n,{disarm:l,armed:u}=r,d=(0,_.useCallback)(()=>{s(),i(),l()},[s,i,l]),f=Ez({...e,onArm:d}),p=f.disarm;return(0,_.useEffect)(()=>{(a||o||c||u)&&p()},[a,o,c,u,p]),f}function OB(e,t,n,r){let{disarm:i}=e,{disarm:a}=t,{disarm:o}=n,{disarm:s}=r,c=(0,_.useCallback)(()=>{i(),a(),o(),s()},[i,a,o,s]);return{armed:e.tool??(t.armed||n.armed||r.armed?`place`:null),disarm:c}}function kB({boxes:e,labels:t,wires:n,drawings:r,corners:i,wire:a,palette:o,note:s,draw:c,marks:l,picking:u,onOpenProperties:d,symbolEdit:f,sheetOf:p,onOpenSheet:m,...h}){let g=()=>!s.armed&&!o.armed&&!c.armed&&!l.armed&&!a.wiring&&a.drawing===null,_=(e,t)=>g()&&f.press(e,t)||!s.armed&&(l.press(e,t)||c.press(e,t)||o.press(e,t)||a.press(e,t)),v=e=>{c.release(e),f.release(e)},y=f=>{let g=s.armed||o.armed||c.armed||l.armed||a.wiring||a.drawing!==null,_=eA(e,t,f,u,n,r),v=nA({busy:g,handle:i.at(f,u),target:_,selectedBefore:h.gestures.wireBeforeDoubleClick()});v.kind===`removeCorner`&&i.drop(v.id,v.index);let y=v.kind===`properties`&&v.target.kind===`part`?p(v.target.name):void 0;y===void 0?v.kind===`properties`&&d(v.target):m(y),v.kind===`rename`&&o.rename(v.label)};return FA({...h,tool:_,toolRelease:v,open:y})}function AB(e){let{design:t,buildId:n,builtMark:r,buildStatus:i,project:a,builtFrom:o,circuit:s,actions:c,selection:l,onSelect:u,highlight:d,onHighlight:f,gridStyle:p,gridStep:m,snap:h,onGridStep:g,markers:v,activeViolation:y,focus:b,onFocused:x}=e,S=(0,_.useRef)(null),C=(0,_.useRef)(null),w=oO(S),[T,E]=(0,_.useState)(),D=(0,_.useMemo)(()=>({step:m,style:p}),[m,p]),O=rO(t,`schematic`,s),k=gB(t),{camera:A,setCamera:j,fit:M}=cO(S,w,k.outer,cB);_B(k,M);let ee=(0,_.useMemo)(()=>IL(k,{project:a??``,page:`Schematic`,file:s.file,date:FL(n),rev:``}),[k,a,s.file,n]);lO(`schematic`,b,A,j,x),IA({selection:l,boxes:O.boxes,size:w,setCamera:j,notify:c.notify});let te=LR({design:t,actions:c,camera:A,cursor:T,step:m,snap:h,buildId:n,builtFrom:o}),ne=Jz({design:t,selection:l,camera:A,actions:c}),N=SR({design:t,circuit:s,actions:c,camera:A,cursor:T,builtFrom:o,onArm:te.cancel}),P=EB(te,N),F=DB({design:t,circuit:s,actions:c,camera:A,cursor:T,step:m,snap:h,builtFrom:o,onSelect:u},te,N,P),re=(0,_.useMemo)(()=>({design:t,locked:O.locked}),[t,O.locked]),I={view:`schematic`,circuit:s,actions:c,onSelect:u,blockerFor:O.blockerFor,follow:re},L=LL({design:t,circuit:s,actions:c,builtFrom:o}),R=nz({design:t,circuit:s,actions:c,locked:O.locked,camera:A,selection:l,onSelect:u,builtFrom:o,wiring:te.wiring||te.drawing!==null}),z=rz({design:t,circuit:s,camera:A,locked:O.locked}),ie=WO({view:`schematic`,design:t,circuit:s,actions:c,locked:O.locked,builtFrom:o}),ae=TB({design:t,circuit:s,actions:c,camera:A,locked:O.locked},te,N,P,F),oe=OB(P,N,F,ae);wB(te,N,P,F,ae);let se=NA({...I,camera:A,setCamera:j,size:w,boxes:O.boxes,anchors:O.anchors,step:m,snap:h,builtFrom:o,labels:L.tools,wires:R.hits,drawings:z.hits,texts:ie.tools,selection:l,tool:oe,filter:e.pickFilter,onContextMenu:e.onContextMenu});hB(t,N,c);let ce=iO(O,m,h),le=aO(S,l.primary,O.boxes,A,w,R.menuWire),ue={...I,selection:l,layout:ce,builtMark:r,buildStatus:i,moveWaiting:se.pending!==void 0,menuPlace:le,onContextMenu:e.onContextMenu,wire:R.keys,drawings:z.removal},{highlight:de,rotateHeld:fe,keyMoving:pe}=CB({design:t,builtFrom:o,camera:A,cursor:T,fit:M,wire:te,palette:N,drawBusy:F.busy,highlightNets:d,onHighlight:f,keys:ue,texts:ie}),B=pB({boxes:O.boxes,wire:te,labels:L.tools,filter:e.pickFilter,wires:R.hits,drawings:z.hits,texts:ie.tools,setCursor:E}),{gesture:me}=se,he=GO(ie,me),ge=(0,_.useMemo)(()=>({...he,hover:B.text}),[he,B.text]),_e=se.moving??pe,ve=SB(t,me,L.pending,_e?.labels),ye=(0,_.useMemo)(()=>R.lineOf(B.wire),[R.lineOf,B.wire]),be=bB(me,R.pending,_e?.wires);dB(C,{design:t,border:ee,camera:A,size:w,wire:te,moving:_e,boxes:O.boxes,hover:B.part,selection:l,locked:O.locked,circuit:s,gesture:me,movingLabels:ve,hoverLabel:B.label,hoverDrawing:z.drawingOf(B.drawing),hoverWire:ye,selectedWire:R.selected,wireShapes:be,palette:N,draw:F,highlight:de,markers:v,activeViolation:y,grid:D,texts:ge,theme:e.theme});let xe={selection:l,armed:oe.armed,filter:e.pickFilter},Se=e=>gn(t,e)?.file,Ce=A??sB,H={view:`schematic`,design:t,scale:Ce.scale,context:xe,boxes:O.boxes,labels:L.tools,wires:R.hits,drawings:z.hits,texts:ie.tools},we=_F({enabled:e.hoverLabels,busy:te.drawing!==null||F.busy,probe:{pick:e=>RF(e,H),still:(e,t)=>VF(e,t,H)},camera:A,design:t}),Te=e=>{uC(`sch`,e),B.at(e),we.move(e,V(Ce,w,e))},Ee=()=>{we.leave(),B.leave()},De=hF(kB({symbolEdit:ne,sheetOf:Se,onOpenSheet:e.onOpenSheet,camera:A,size:w,element:S,gestures:se,setCursor:E,hover:Te,boxes:O.boxes,labels:L.tools,wires:R.hits,drawings:z.hits,corners:R.corners,wire:te,palette:N,note:P,draw:F,marks:ae,picking:xe,onOpenProperties:e.onOpenProperties}),we,C),Oe=PA(me,te.drawing!==null||te.overPin||N.armed||P.armed||F.armed||ae.armed,B.over);return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(fB,{step:m,setStep:g,keep:{show:O.autoPlaced,onKeep:()=>Je(t,`schematic`,O.blockerFor,c,s)}}),(0,X.jsx)(mB,{wrapRef:S,canvasRef:C,size:w,camera:A,cursor:T,pointer:De,onLeave:Ee,cursorStyle:Oe,wire:te,palette:N,note:P,draw:F,gesture:me,rotateHeld:fe,snap:h,empty:O.boxes.length===0,symbolHint:ne.hint,label:we.state,markHint:ae.hint})]})}function jB(){document.getElementById(`doc-panel`)?.focus()}function MB({text:e,seq:t,onText:n,onSearch:r,onClose:i,status:a}){let o=(0,_.useRef)(null);(0,_.useEffect)(()=>{let e=()=>{o.current?.focus(),o.current?.select()};e();let t=window.setTimeout(e,0);return()=>window.clearTimeout(t)},[t]);let s=()=>{i(),jB()};return(0,X.jsxs)(`div`,{className:`find-box`,role:`search`,children:[(0,X.jsx)(`input`,{ref:o,type:`text`,value:e,placeholder:`Find a part or a net`,"aria-label":`Find a part or a net`,spellCheck:!1,autoComplete:`off`,onChange:e=>n(e.target.value),onKeyDown:t=>{if(t.key===`Enter`)r(e);else if(t.key===`Escape`)s();else if((t.ctrlKey||t.metaKey)&&t.key.toLowerCase()===`f`)o.current?.select();else return;t.preventDefault(),t.stopPropagation()}}),(0,X.jsx)(`button`,{type:`button`,className:`find-close`,title:`Close (Esc)`,"aria-label":`Close the find box`,onClick:s,children:(0,X.jsx)(nh,{})}),(0,X.jsx)(`span`,{className:`find-status`,role:`status`,"aria-live":`polite`,children:a})]})}var NB=new Set([`name`,`pcbX`,`pcbY`,`pcbRotation`,`schX`,`schY`,`schRotation`,`layer`,`side`]),PB=`Press Ctrl+F to find a part or a net.`,FB=e=>`Nothing matches "${e}".`;function IB(e,t){return e===null?``:t===0?`No results`:t===1?`1 result`:`${t} results`}var LB=new Intl.Collator(`en`,{numeric:!0});function RB(e){let t=new Map(Xp(e).map(e=>[e.id,e.label]));return e.circuit.nets.map(e=>({id:e.id,label:t.get(e.id)??e.id,names:e.names}))}var zB=e=>typeof e==`string`||typeof e==`number`?String(e):void 0;function BB(e,t){return t.find(t=>t.component===e.tag)}function VB(e,t){let n=[{field:`name`,text:e.name},{field:`kind`,text:e.tag}];for(let[t,r]of Object.entries(e.props)){let e=NB.has(t)?void 0:zB(r.literal);e!==void 0&&n.push({field:t,text:e})}let r=BB(e,t);return r?.mpn&&n.push({field:`mpn`,text:r.mpn}),r&&n.push({field:`title`,text:r.title}),n}function HB(e,t,n){let r=VB(e,t).filter(e=>e.text.toLowerCase().includes(n));return r.filter((e,t)=>r.findIndex(t=>t.field===e.field)===t)}function UB(e,t){return e.names.filter(e=>e.toLowerCase().includes(t)).map(e=>({field:`net name`,text:e}))}var WB=(e,t)=>LB.compare(e.name,t.name);function GB(e,t,n,r=[]){let i=e.trim().toLowerCase();if(i===``)return[];let a=t.map(e=>({id:`part:${e.name}`,kind:`part`,name:e.name,matches:HB(e,r,i)})).filter(e=>e.matches.length>0).sort(WB),o=n.map(e=>({id:`net:${e.id}`,kind:`net`,name:e.label,net:e.id,matches:UB(e,i)})).filter(e=>e.matches.length>0).sort(WB);return[...a,...o]}function KB(e){return e.matches.map(e=>e.field===`name`||e.field===`net name`?e.field:`${e.field} ${e.text}`).join(`, `)}function qB(e,t,n){if(e.kind===`net`)return e.net?{highlight:[e.net]}:{};let r=t?Pe(t,n).get(e.name)?.origin:void 0;return{select:e.name,...r?{focus:{view:n,at:r}}:{}}}var JB={pcb:`Show on the PCB`,schematic:`Show on the schematic`,code:`From the code`};function YB({rows:e,counts:t,active:n,onPick:r}){let i=(0,_.useMemo)(()=>sw(e),[e]);return(0,X.jsxs)(`section`,{className:`checks`,"aria-label":`Checks`,onClick:km,children:[(0,X.jsxs)(`header`,{className:`checks-head hairline-b`,children:[(0,X.jsx)(`h2`,{children:`Checks`}),e.length>0&&(0,X.jsx)(`span`,{className:`count`,children:dw(t)})]}),(0,X.jsx)(`div`,{className:`checks-body`,children:i.length===0?(0,X.jsx)(`p`,{className:`note ok`,children:JC}):i.map(e=>(0,X.jsx)(XB,{group:e,active:n,onPick:r},e.code))})]})}function XB({group:e,active:t,onPick:n}){return(0,X.jsxs)(`section`,{className:`check-group ${e.severity}`,children:[(0,X.jsxs)(`h3`,{children:[(0,X.jsx)(`span`,{className:`dot`,role:`img`,"aria-label":e.severity===`error`?`Error`:`Warning`}),(0,X.jsx)(`span`,{className:`code`,children:e.code}),(0,X.jsx)(`span`,{className:`count`,children:e.rows.length})]}),(0,X.jsx)(`ul`,{children:e.rows.map(e=>(0,X.jsx)(`li`,{children:(0,X.jsx)(ZB,{row:e,active:e.id===t,onPick:n})},e.id))})]})}function ZB({row:e,active:t,onPick:n}){return(0,X.jsxs)(`button`,{className:`check-row ${e.severity}${t?` active`:``}`,"aria-current":t||void 0,title:JB[e.view],onClick:()=>n(e),children:[(0,X.jsx)(`span`,{className:`message`,children:e.message}),e.items.length>0&&(0,X.jsx)(`span`,{className:`items`,children:e.items.join(`, `)})]})}var QB={part:`Select the part`,net:`Highlight the net`};function $B({query:e,rows:t,active:n,pick:r}){return e===null?(0,X.jsx)(`p`,{className:`note bottom-note`,children:PB}):t.length===0?(0,X.jsx)(`p`,{className:`note bottom-note`,children:FB(e)}):(0,X.jsxs)(`section`,{className:`find-results`,"aria-label":`Find results`,onClick:km,children:[(0,X.jsxs)(`header`,{className:`find-head hairline-b`,children:[(0,X.jsx)(`h2`,{children:`Find results`}),(0,X.jsx)(`span`,{className:`count`,children:`${t.length} found for "${e}"`})]}),(0,X.jsx)(`ul`,{children:t.map(e=>(0,X.jsx)(`li`,{children:(0,X.jsxs)(`button`,{className:`find-row${e.id===n?` active`:``}`,"aria-current":e.id===n||void 0,title:QB[e.kind],onClick:()=>r(e),children:[(0,X.jsx)(`span`,{className:`kind ${e.kind}`,children:e.kind===`part`?`Part`:`Net`}),(0,X.jsx)(`span`,{className:`name`,children:e.name}),(0,X.jsx)(`span`,{className:`matched`,children:KB(e)})]})},e.id))})]})}var eV=.04,tV=`A change is shown: the board cannot be edited. Close it to edit.`;function nV(e){if(e[0]?.author!==`ai`)return;let t=e.find(e=>e.author===`human`)?.id;return t?{since:t,label:`Since my last change`}:{since:`c0000`,label:`Everything the agent did`}}function rV(e,t){let n=e.pcb,r=Oe(n.board?.outline??[])??ke(n.parts.flatMap(e=>Oe(e.courtyard)??[]));return r&&t.width>0&&t.height>0?be(r,t,eV):void 0}function iV(e){return e===`Escape`?`close`:void 0}function aV(e){return e?Object.fromEntries(P.map(e=>[e,tV])):{}}function oV(e,t){return t===`before`?e.before:e.after}function sV(e){return`id`in e?`/api/change?id=${encodeURIComponent(e.id)}`:`/api/change?since=${encodeURIComponent(e.since)}`}function cV({entry:e,onShow:t}){return(0,_.createElement)(`button`,{type:`button`,"aria-label":`Show change ${e.id}: ${e.summary}`,onClick:()=>t({id:e.id})},`Show`)}function lV({history:e,onShow:t}){let n=nV(e);return n===void 0?null:(0,_.createElement)(`p`,{className:`history-since`},(0,_.createElement)(`button`,{type:`button`,onClick:()=>t({since:n.since})},n.label))}function uV(e){return e.undone?{className:`undone`,undoable:!1}:e.redoneAs?{className:e.undoOf?`redone`:``,note:`redone as ${e.redoneAs}`,undoable:!1}:{className:``,undoable:e.undoOf===void 0}}function dV({history:e,problems:t,actions:n,onShow:r=()=>void 0}){let i=t.map(e=>(0,X.jsxs)(`p`,{className:`note`,role:`alert`,children:[`Skipped `,e.file,`: `,e.reason]},e.file));return e.length===0?(0,X.jsxs)(X.Fragment,{children:[t.length===0&&(0,X.jsx)(`p`,{className:`note`,children:`Changes from you and the agent appear here.`}),i]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(lV,{history:e,onShow:r}),(0,X.jsx)(`ul`,{className:`history`,children:e.map(e=>{let t=uV(e);return(0,X.jsxs)(`li`,{className:t.className,children:[(0,X.jsx)(`span`,{className:`who ${e.author}`,children:e.author===`ai`?`Agent`:`You`}),(0,X.jsx)(`span`,{className:`what`,title:e.file,children:e.summary}),t.note&&(0,X.jsx)(`span`,{className:`history-note`,children:t.note}),(0,X.jsx)(cV,{entry:e,onShow:r}),t.undoable&&(0,X.jsx)(`button`,{className:`icon`,"aria-label":`Undo ${e.summary}`,onClick:()=>void n.undo(e.id),children:(0,X.jsx)(th,{})})]},e.id)})}),i]})}var fV,pV=0,mV=new Set;function hV(e){fV=e;for(let e of mV)e()}var gV={async show(e){let t=++pV;hV({request:e,mode:`both`,status:`loading`});try{let n=await B(sV(e));t===pV&&fV&&hV({...fV,status:`ready`,data:n})}catch(e){t===pV&&fV&&hV({...fV,status:`failed`,error:e.message})}},setMode(e){fV&&hV({...fV,mode:e})},close(){pV+=1,hV(void 0)},shown:()=>fV!==void 0,subscribe(e){return mV.add(e),()=>mV.delete(e)},get:()=>fV};function _V(){return(0,_.useSyncExternalStore)(gV.subscribe,gV.get,gV.get)}var vV={resistor:{resistance:`10k`,footprint:`0402`},capacitor:{capacitance:`100nF`,footprint:`0402`},inductor:{inductance:`10uH`,footprint:`0805`},led:{color:`red`,footprint:`0603`},crystal:{frequency:`16MHz`},fuse:{currentRating:`500mA`,footprint:`1206`}};function yV(e){let t=vV[e]??{},n=Object.keys(t).find(e=>e!==`footprint`);return n?t[n]??``:``}function bV(e){let t=e.library.map(e=>({part:e.id,name:e.mpn??e.id,value:``,footprint:e.footprint,description:e.title,verified:e.verified?`Verified`:`Unverified`,tooltip:`${e.title} (${e.component})`,verifiedTip:e.verified?`Checked by ${e.verifiedBy}${e.verifiedAgainst?` against ${e.verifiedAgainst}`:``}`:`Not checked against the datasheet yet`,extra:`${e.id} ${e.mpn??``} ${e.component}`})),n=e.builtin.map(e=>({part:e,name:e,value:yV(e),footprint:vV[e]?.footprint??``,description:``,verified:``,tooltip:e,verifiedTip:``,extra:e}));return[...t,...n]}function xV(e,t){let n=t.trim().toLowerCase();return n===``?[...e]:e.filter(e=>[e.name,e.value,e.footprint,e.description,e.verified,e.extra].some(e=>e.toLowerCase().includes(n)))}function SV(e,t,n,r=!1){if(n===0||e===`Enter`&&r)return null;let i=n-1;switch(e){case`ArrowDown`:return{move:Math.min(t+1,i)};case`ArrowUp`:return{move:Math.max(t-1,0)};case`Home`:return{move:0};case`End`:return{move:i};case`Enter`:return{place:!0};default:return null}}var CV=(e,t)=>e===null||t-e>=500,wV=e=>e<=1,TV=(e,t)=>Math.max(0,Math.min(e,t-1));function EV(e){let t=(0,_.useRef)(null);return n=>{let r=Date.now();CV(t.current,r)&&(t.current=r,e(n))}}function DV(){return(0,X.jsx)(`thead`,{children:(0,X.jsxs)(`tr`,{children:[(0,X.jsx)(`th`,{className:`wide`,children:`Name`}),(0,X.jsx)(`th`,{children:`Value`}),(0,X.jsx)(`th`,{children:`Footprint`}),(0,X.jsx)(`th`,{className:`wide`,children:`Description`}),(0,X.jsx)(`th`,{children:`Verified`}),(0,X.jsx)(`th`,{className:`action`,"aria-label":`Verify`}),(0,X.jsx)(`th`,{className:`action`,"aria-label":`Place`})]})})}function OV({row:e,tabStop:t,onFocus:n,onPlace:r,onVerify:i,onKey:a}){return(0,X.jsxs)(`tr`,{tabIndex:t?0:-1,title:e.tooltip,onFocus:n,onDoubleClick:r,onKeyDown:a,children:[(0,X.jsx)(`td`,{className:`wide`,children:e.name}),(0,X.jsx)(`td`,{children:e.value}),(0,X.jsx)(`td`,{children:e.footprint}),(0,X.jsx)(`td`,{className:`wide`,children:e.description}),(0,X.jsx)(`td`,{children:e.verified&&(0,X.jsx)(`span`,{className:`badge ${e.verified===`Verified`?`verified`:`unverified`}`,title:e.verifiedTip,children:e.verified})}),(0,X.jsx)(`td`,{className:`action`,children:e.verified&&(0,X.jsx)(`button`,{className:`lib-place`,tabIndex:t?0:-1,onClick:i,onDoubleClick:e=>e.stopPropagation(),"aria-label":e.verified===`Verified`?`Look again at ${e.description}`:`Verify ${e.description}`,children:e.verified===`Verified`?`Look again`:`Verify…`})}),(0,X.jsx)(`td`,{className:`action`,children:(0,X.jsx)(`button`,{className:`lib-place`,tabIndex:-1,onClick:e=>wV(e.detail)&&r(),onDoubleClick:e=>e.stopPropagation(),"aria-label":`Place ${e.name}`,children:`Place`})})]})}function kV({parts:e,onPlace:t,onVerify:n}){let[r,i]=(0,_.useState)(``),a=(0,_.useRef)(null),[o,s]=(0,_.useState)(0),c=(0,_.useId)(),l=EV(t),u=(0,_.useMemo)(()=>xV(bV(e),r),[e,r]),d=TV(o,u.length),f=(e,t,n)=>{if(e.target!==e.currentTarget)return;let r=SV(e.key,t,u.length,e.repeat);r&&(e.preventDefault(),`place`in r?l(n):(a.current?.rows[r.move])?.focus())};return(0,X.jsxs)(`div`,{className:`lib-table`,children:[(0,X.jsx)(`input`,{className:`lib-table-search`,type:`search`,placeholder:`Search parts`,"aria-label":`Search parts`,value:r,onChange:e=>i(e.target.value)}),(0,X.jsx)(`p`,{id:c,className:`lib-table-hint`,children:`Enter places the focused part; so does a double click on a row.`}),(0,X.jsxs)(`div`,{className:`lib-table-scroll hairline-t`,children:[(0,X.jsxs)(`table`,{"aria-label":`Library parts`,"aria-describedby":c,children:[(0,X.jsx)(DV,{}),(0,X.jsx)(`tbody`,{ref:a,children:u.map((e,t)=>(0,X.jsx)(OV,{row:e,tabStop:t===d,onFocus:()=>s(t),onPlace:()=>l(e.part),onVerify:()=>n(e.part,e.description),onKey:n=>f(n,t,e.part)},e.part))})]}),u.length===0&&(0,X.jsx)(`p`,{className:`note lib-table-empty`,children:`No parts match.`})]})]})}function AV(e){return(0,X.jsx)(`div`,{className:`bottom-panel hairline-t`,id:vm,role:`tabpanel`,"aria-labelledby":ym(e.tab),onClick:km,children:(0,X.jsx)(jV,{...e})})}function jV(e){switch(e.tab){case`library`:return(0,X.jsx)(kV,{parts:e.parts,onPlace:e.onPlace,onVerify:e.actions.openVerify});case`log`:return(0,X.jsx)(`div`,{className:`bottom-scroll`,children:(0,X.jsx)(dV,{history:e.history,problems:e.historyProblems,actions:e.actions,onShow:e=>void gV.show(e)})});case`drc`:return e.built?(0,X.jsx)(YB,{rows:e.rows,counts:e.counts,active:e.active,onPick:e.onPick}):(0,X.jsx)(`p`,{className:`note bottom-note`,children:e.buildError??`Building the circuit…`});case`find`:return(0,X.jsx)($B,{...e.find})}}var MV={added:{colour:W.selectionBox,dash:[],label:`Added`},removed:{colour:W.warning,dash:[7,4],label:`Removed`},moved:{colour:W.document,dash:[2,3],label:`Moved`},dim:`rgb(0 0 0 / 55%)`,legendPanel:W.notePanel},NV=3,PV=10,FV=4,IV={pad:8,row:18,sample:26,font:12,margin:10};function LV(e,t){e.save(),e.fillStyle=MV.dim,RV(e,0,0,t.width,t.height),e.fill(),e.restore()}function RV(e,t,n,r,i){e.beginPath(),e.moveTo(t,n),e.lineTo(t+r,n),e.lineTo(t+r,n+i),e.lineTo(t,n+i),e.closePath()}function zV(e,t,n,r){e.save(),e.strokeStyle=t.colour,e.lineWidth=n,e.lineCap=`butt`,e.lineJoin=`round`,e.setLineDash([...t.dash]),e.beginPath(),r(),e.stroke(),e.restore()}function BV(e,t,n,r){n.forEach((n,r)=>{let i=V(t.camera,t.size,n);r===0?e.moveTo(i.x,i.y):e.lineTo(i.x,i.y)}),r&&n.length>2&&e.closePath()}function VV(e){if(e.courtyard.length>2)return e.courtyard;let t=.5;return[{x:e.x-t,y:e.y-t},{x:e.x+t,y:e.y-t},{x:e.x+t,y:e.y+t},{x:e.x-t,y:e.y+t}]}function HV(e,t,n,r){let i=MV[r];for(let a of n.parts[r])zV(e,i,NV,()=>BV(e,t,VV(a),!0));for(let a of n.tracks[r])zV(e,i,Math.max(NV,a.width*t.camera.scale),()=>BV(e,t,a.points,!1));for(let a of n.vias[r]){let n=V(t.camera,t.size,a.at);zV(e,i,NV,()=>e.arc(n.x,n.y,Math.max(FV,a.diameter/2*t.camera.scale),0,Math.PI*2))}for(let a of n.pours[r])a.outline&&zV(e,i,NV,()=>BV(e,t,a.outline,!0));for(let a of n.board.holes[r]){let n=V(t.camera,t.size,a);zV(e,i,NV,()=>e.arc(n.x,n.y,Math.max(FV,a.diameter/2*t.camera.scale),0,Math.PI*2))}}function UV(e,t,n,r){let i=Math.atan2(n.y-t.y,n.x-t.x),a=e=>({x:n.x-PV*Math.cos(i+e),y:n.y-PV*Math.sin(i+e)});e.save(),e.strokeStyle=r,e.fillStyle=r,e.lineWidth=2,e.setLineDash([]),e.beginPath(),e.moveTo(t.x,t.y),e.lineTo(n.x,n.y),e.stroke();let[o,s]=[a(.45),a(-.45)];e.beginPath(),e.moveTo(n.x,n.y),e.lineTo(o.x,o.y),e.lineTo(s.x,s.y),e.closePath(),e.fill(),e.restore()}function WV(e,t,n,r){let i=MV.moved;for(let a of n.parts.moved){if(zV(e,i,NV,()=>BV(e,t,VV(a.from),!0)),r===`before`)continue;let n=V(t.camera,t.size,a.from),o=V(t.camera,t.size,a.to);Math.hypot(o.x-n.x,o.y-n.y)>PV&&UV(e,n,o,i.colour)}}function GV(e,t,n,r){r!==`after`&&HV(e,t,n,`removed`),r!==`before`&&HV(e,t,n,`added`),WV(e,t,n,r)}function KV(e,t,n=`both`){let r=[MV.added,MV.removed,MV.moved].filter(e=>n===`both`||e!==(n===`before`?MV.added:MV.removed));e.save(),e.font=Sa(xa.regular,IV.font),e.textAlign=`left`,e.textBaseline=`middle`;let i=Math.max(...r.map(t=>e.measureText(t.label).width)),a=IV.pad*3+IV.sample+i,o=IV.pad*2+IV.row*r.length,s=IV.margin,c=t.height-IV.margin-o;e.fillStyle=MV.legendPanel,RV(e,s,c,a,o),e.fill(),r.forEach((t,n)=>{let r=c+IV.pad+IV.row*n+IV.row/2,i=s+IV.pad;t===MV.moved?UV(e,{x:i,y:r},{x:i+IV.sample,y:r},t.colour):zV(e,t,NV,()=>{e.moveTo(i,r),e.lineTo(i+IV.sample,r)}),e.fillStyle=t.colour,e.fillText(t.label,i+IV.sample+IV.pad,r)}),e.restore()}function qV({design:e,diff:t,mode:n,focus:r}){let i=(0,_.useRef)(null),a=(0,_.useRef)(null),o=oO(i),{camera:s,setCamera:c}=cO(i,o,void 0),l=(0,_.useRef)(void 0);(0,_.useEffect)(()=>{let t=rV(e,o);t&&c(t)},[e,n,o,c]),(0,_.useEffect)(()=>{r&&c(e=>e&&Se(e,r.at))},[r,c]),(0,_.useEffect)(()=>{if(!s)return;let r=dO(a.current,o,s,W.background,()=>void 0);if(!r)return;let i=r.ctx,c={camera:s,size:o};Yf(i,e.pcb,c,{ratio:r.ratio,copper:{tracks:e.pcb.tracks,vias:e.pcb.vias,selected:new Set}}),LV(i,o),GV(i,c,t,n),KV(i,o,n)},[s,o,e,t,n]);let u=e=>sO(i.current,o,e);return(0,X.jsx)(`div`,{className:`change-canvas`,ref:i,onPointerDown:e=>{s&&(e.currentTarget.setPointerCapture(e.pointerId),l.current={start:u(e),camera:s})},onPointerMove:e=>{l.current&&c(xe(l.current.camera,l.current.start,u(e)))},onPointerUp:()=>l.current=void 0,onPointerCancel:()=>l.current=void 0,children:(0,X.jsx)(`canvas`,{ref:a,role:`img`,"aria-label":`The board with the change marked; it cannot be edited here`})})}var JV=[{mode:`before`,label:`Before`},{mode:`after`,label:`After`},{mode:`both`,label:`Both`}];function YV(e,t,n){let{at:r,items:i}=e;return i?(0,_.createElement)(`li`,{key:t},(0,_.createElement)(`details`,null,(0,_.createElement)(`summary`,null,e.text),(0,_.createElement)(`ul`,null,i.map((e,t)=>YV(e,t,n))))):r?(0,_.createElement)(`li`,{key:t},(0,_.createElement)(`button`,{type:`button`,className:`change-line`,title:`Centre the view on it`,onClick:()=>n(r)},e.text)):(0,_.createElement)(`li`,{key:t},e.text)}function XV({state:e,onMode:t,onLine:n,onClose:r}){let i=e.status===`ready`?e.data:void 0,a=`id`in e.request?`Change ${e.request.id}`:e.request.since===`c0000`?`Everything the agent did`:`Since ${e.request.since}`,o=i?.onBoard?(0,_.createElement)(`span`,{className:`change-modes`,role:`group`,"aria-label":`Show`},JV.map(({mode:n,label:r})=>(0,_.createElement)(`button`,{key:n,type:`button`,"aria-pressed":e.mode===n,onClick:()=>t(n)},r))):null;return(0,_.createElement)(`div`,{className:`change-bar`,role:`region`,"aria-label":`Change view`},(0,_.createElement)(`div`,{className:`change-head`},(0,_.createElement)(`strong`,{className:`change-title`},i?.title??a),o,(0,_.createElement)(`button`,{type:`button`,className:`change-close`,"aria-label":`Close the change view`,onClick:r},`Close`)),(0,_.createElement)(`p`,{className:`change-note`},tV),e.status===`loading`?(0,_.createElement)(`p`,{className:`change-note`},`Building the change…`):null,e.status===`failed`?(0,_.createElement)(`p`,{className:`change-error`,role:`alert`},e.error):null,i?(0,_.createElement)(`ul`,{className:`change-lines`},i.lines.map((e,t)=>YV(e,t,n))):null)}function ZV({state:e}){let[t,n]=(0,_.useState)(void 0);(0,_.useEffect)(()=>{let e=e=>{iV(e.key)===`close`&&(e.preventDefault(),gV.close())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[]),(0,_.useEffect)(()=>n(void 0),[e.request]);let r=e.status===`ready`?e.data:void 0,i=r?oV(r,e.mode):void 0;return(0,X.jsxs)(`div`,{className:`change-view`,children:[(0,X.jsx)(XV,{state:e,onMode:gV.setMode,onClose:gV.close,onLine:e=>n(t=>({at:e,seq:(t?.seq??0)+1}))}),r?.onBoard&&i&&r.diff&&(0,X.jsx)(qV,{design:i,diff:r.diff,mode:e.mode,...t?{focus:t}:{}}),r?.onBoard&&!i&&(0,X.jsx)(`p`,{className:`empty`,children:`The circuit does not build on this side of the change, so there is no board to draw.`})]})}var QV=String.raw`\d+(?:\.\d+)?`,$V=new RegExp(String.raw`^([a-z]*)(${QV})?(?:x(${QV}))?([a-z]*)$`),eH=/^\d+$/,tH=/^([a-z]+)(.*)$/,nH=new RegExp(String.raw`^(${QV})(?:mm)?x(${QV})(?:mm)?$`);function rH(e){let[t=``,...n]=e.trim().toLowerCase().split(`_`),r=$V.exec(t);if(!r||t===``)return;let[,i=``,a=``,o,s=``]=r,c=eH.test(n[0]??``)?n[0]:void 0,l=c===void 0?n:n.slice(1),u=l.filter(e=>nH.test(e));if(u.length>1)return;let d=oH(l.filter(e=>!nH.test(e)));if(!d)return;let f=u[0]===void 0?void 0:aH(u[0]);return{kind:i,code:a,...o===void 0?{}:{cross:o},...s===``?{}:{suffix:s},...c===void 0?{}:{variant:c},...f===void 0?{}:{size:f},params:d.params,...Object.keys(d.pairs).length===0?{}:{pairs:d.pairs}}}function iH(e){return e.cross===void 0&&e.suffix===void 0&&e.size===void 0&&e.pairs===void 0}function aH(e){let t=nH.exec(e);return t?[Number(t[1]),Number(t[2])]:void 0}function oH(e){let t={},n={};for(let r of e){let e=tH.exec(r);if(!e)return;let i=e[1]??``,a=e[2]??``;if(Object.hasOwn(t,i)||Object.hasOwn(n,i))return;let o=aH(a);if(o){n[i]=o;continue}let s=a===``||ei(a);if(s===void 0)return;t[i]=s}return{params:t,pairs:n}}var sH=`EIA/IEC 60384-21 chip capacitor sizes: thickness up to the body width plus its tolerance (resistors are thinner)`,cH=(e,t)=>({packages:`chip ${e}`,height:t,source:sH,matches:t=>t.kind===``&&t.code===e&&t.variant===void 0}),lH=e=>e.params.p===void 0||e.params.p===2.54,uH=`makers' drawings of general-purpose radial aluminium electrolytic series: the common can length for the diameter`,dH=(e,t)=>({packages:`radial can ${e} mm across`,height:t,source:uH,matches:t=>t.kind===`radial`&&t.code===e}),fH=[cH(`0402`,.55),cH(`0603`,.9),cH(`0805`,1.45),cH(`1206`,1.8),{packages:`SOIC (narrow)`,height:1.75,source:`JEDEC MS-012, A max 1.75 mm`,document:`NXP TJA1051 data sheet Rev. 9, p15, Fig 9, SOT96-1 (SO8, JEDEC MS-012): A max 1.75 mm`,matches:e=>e.kind===`soic`&&e.suffix===void 0},{packages:`SOIC (wide)`,height:2.65,source:`JEDEC MS-013, A max 2.65 mm`,document:`Microchip MCP2515 data sheet DS20001801J, p82, 18-lead SOIC 7.50 mm body (drawing C04-051C): A max 2.65 mm`,matches:e=>e.kind===`soic`&&e.suffix===`w`},{packages:`SOT-23 (3 leads)`,height:1.12,source:`JEDEC TO-236 AB, A max 1.12 mm`,matches:e=>e.kind===`sot`&&e.code===`23`&&e.variant===void 0},{packages:`SOT-23-5, SOT-23-6`,height:1.45,source:`JEDEC MO-178, A max 1.45 mm`,matches:e=>e.kind===`sot`&&e.code===`23`&&(e.variant===`5`||e.variant===`6`)},{packages:`QFN`,height:1,source:`JEDEC MO-220, A max 1.00 mm`,matches:e=>e.kind===`qfn`},{packages:`DFN`,height:1,source:`JEDEC MO-229, A max 1.00 mm`,matches:e=>e.kind===`dfn`},{packages:`LQFP, QFP`,height:1.6,source:`JEDEC MS-026 (LQFP), A max 1.60 mm`,matches:e=>e.kind===`lqfp`||e.kind===`qfp`},{packages:`TQFP`,height:1.2,source:`JEDEC MS-026 (TQFP), A max 1.20 mm`,matches:e=>e.kind===`tqfp`},{packages:`SOD-123`,height:1.35,source:`makers' SOD-123 drawings (for example onsemi case 425), A max 1.35 mm`,matches:e=>e.kind===`sod`&&e.code===`123`},{packages:`pin header, 2.54 mm pitch`,height:8.5,source:`makers' drawings of straight 2.54 mm headers: 2.5 mm insulator and 6 mm of pin above it`,matches:e=>e.kind===`pinrow`&&lH(e)},{packages:`HC-49/U crystal`,height:13.46,source:`crystal makers' HC-49/U drawings, height max 13.46 mm`,matches:e=>e.kind===`hc`&&e.code===`49`&&e.suffix===void 0},{packages:`HC-49/S crystal`,height:3.5,source:`crystal makers' HC-49/S (HC-49/US) drawings, height max 3.5 mm`,matches:e=>e.kind===`hc`&&e.code===`49`&&e.suffix===`s`},dH(`4`,7),dH(`5`,11),dH(`6.3`,11),dH(`8`,11.5),dH(`10`,16),dH(`12.5`,20),dH(`16`,25),dH(`18`,35.5)];function pH(e){let t=ei(e.height);return t!==void 0&&t>0?t:void 0}function mH(e){let t=pH(e.props);if(t!==void 0)return{height:t,source:`given`,state:`given`,assumed:!1};let n=e.footprint===void 0||e.footprint.includes(`/`)?void 0:rH(e.footprint),r=n===void 0?void 0:fH.find(e=>e.matches(n));return r===void 0?{height:1,source:`assumed`,state:`assumed`,assumed:!0}:r.document===void 0?{height:r.height,source:r.source,state:`typical`,assumed:!1}:{height:r.height,source:r.document,state:`read`,assumed:!1}}function hH(e){let t=e.pcb.board;return t?.thicknessGiven?t.thickness:e.rules?.fabrication?.boardThickness??1.6}var gH=.5;function _H(e){let t=0;for(let n=0;n<e.length;n++){let r=e[n],i=e[(n+1)%e.length];t+=r.x*i.y-i.x*r.y}return t}function vH(e){let{from:t,to:n,centre:r,ccw:i}=e,a=Math.atan2(t.y-r.y,t.x-r.x),o=Math.atan2(n.y-r.y,n.x-r.x),s=i?o-a:a-o;for(;s<=1e-12;)s+=2*Math.PI;for(;s>2*Math.PI+1e-12;)s-=2*Math.PI;return i?s:-s}var yH=e=>e.map((t,n)=>({kind:`line`,from:t,to:e[(n+1)%e.length]}));function bH(e,t){let n={x:e.x+t,y:e.y},r={x:e.x-t,y:e.y};return[{kind:`arc`,from:n,to:r,centre:e,radius:t,ccw:!1},{kind:`arc`,from:r,to:n,centre:e,radius:t,ccw:!1}]}function xH(e,t){let n=Math.min(t.width,t.height)/2,r=Math.abs(t.width-t.height)/2,i=(e.rotation+(t.width>=t.height?0:90))*Math.PI/180,[a,o]=[Math.cos(i),Math.sin(i)],s=(t,n)=>({x:e.x+a*t-o*n,y:e.y+o*t+a*n}),[c,l]=[s(r,0),s(-r,0)];return[{kind:`line`,from:s(r,-n),to:s(-r,-n)},{kind:`arc`,from:s(-r,-n),to:s(-r,n),centre:l,radius:n,ccw:!1},{kind:`line`,from:s(-r,n),to:s(r,n)},{kind:`arc`,from:s(r,n),to:s(r,-n),centre:c,radius:n,ccw:!1}]}function SH(e){let t=e.drill;if(e.layers===`through`&&t!==void 0&&t.width>0&&t.height>0)return t.width===t.height?bH(e,t.width/2):xH(e,t)}function CH(e,t){let n=e.pcb.board;if(n===void 0||n.outline.length<3)return;let r=_H(n.outline)<0?[...n.outline].reverse():n.outline,i=e.pcb.parts.flatMap(e=>e.pads.flatMap(e=>{let t=SH(e);return t===void 0?[]:[t]})),a=e.pcb.holes.map(e=>bH(e,e.diameter/2));return{outline:yH(r),holes:[...a,...i],thickness:t}}function wH(e){if(e===void 0)return{minX:-.5,minY:-.5,maxX:gH,maxY:gH};let t=e.courtyard.length>=3?e.courtyard:e.pads.flatMap(TH);if(t.length===0)return wH(void 0);let n=t.map(e=>e.x),r=t.map(e=>e.y);return{minX:Math.min(...n),minY:Math.min(...r),maxX:Math.max(...n),maxY:Math.max(...r)}}function TH(e){let t=e.rotation*Math.PI/180,[n,r]=[Math.cos(t),Math.sin(t)];return[[-1,-1],[1,-1],[1,1],[-1,1]].map(([t,i])=>{let[a,o]=[t*e.width/2,i*e.height/2];return{x:e.x+a*n-o*r,y:e.y+a*r+o*n}})}function EH(e,t){let n=t.rotation*Math.PI/180,[r,i]=[Math.cos(n),Math.sin(n)],[a,o]=[e.x*r-e.y*i,e.x*i+e.y*r];return{x:t.x+(t.side===`bottom`?-a:a),y:t.y+o}}function DH(e,t,n,r){let{minX:i,minY:a,maxX:o,maxY:s}=wH(e.footprint),c=[{x:i,y:a},{x:o,y:a},{x:o,y:s},{x:i,y:s}].map(t=>EH(t,e)),l=_H(c)<0?[c[0],c[3],c[2],c[1]]:c,{height:u,source:d,state:f,assumed:p}=mH({...n===void 0?{}:{footprint:n},props:t}),[m,h]=e.side===`top`?[r,r+u]:[-u,0];return{name:e.component,side:e.side,corners:l,bottom:m,top:h,height:u,source:d,state:f,assumed:p}}function OH(e){let t=hH(e),n=CH(e,t),r=new Map(e.circuit.components.map(e=>[e.id,e])),i=e.pcb.parts.map(e=>{let n=r.get(e.component);return DH(e,n?.props??{},n?.footprint,t)});return{...n?{board:n}:{},parts:i}}var kH={green:{name:`green mask`,sentence:`The common solder mask: deep green, lighter where copper lies under it.`,over:[18,82,44],onCopper:[56,132,66],see:.1,gloss:.6},black:{name:`black mask`,sentence:`Glossy black; copper under it shows only as a faint sheen.`,over:[20,21,23],onCopper:[40,42,44],see:.04,gloss:.9},"matte-black":{name:`matte black mask`,sentence:`Black without gloss; the copper under it barely shows.`,over:[33,33,34],onCopper:[43,43,44],see:.02,gloss:.1},blue:{name:`blue mask`,sentence:`Medium blue, lighter over copper.`,over:[16,52,122],onCopper:[44,92,168],see:.08,gloss:.6},red:{name:`red mask`,sentence:`Deep red, lighter over copper.`,over:[146,22,30],onCopper:[190,56,52],see:.08,gloss:.6},white:{name:`white mask`,sentence:`White; copper under it reads as a pale warm tint. Its print is black by default.`,over:[232,233,229],onCopper:[242,238,222],see:.06,gloss:.4},yellow:{name:`yellow mask`,sentence:`Strong yellow, paler over copper.`,over:[212,176,28],onCopper:[232,204,78],see:.06,gloss:.5},purple:{name:`purple mask`,sentence:`Dark purple, lighter over copper.`,over:[70,30,108],onCopper:[106,62,152],see:.08,gloss:.6}},AH={white:{name:`white print`,sentence:`The usual legend ink.`,colour:[244,244,238]},black:{name:`black print`,sentence:`Dark legend ink, for a white or yellow mask.`,colour:[24,24,26]}},jH={enig:{name:`ENIG`,sentence:`Immersion gold over nickel: flat and gold.`,face:[212,170,78],rim:[150,110,44],shine:[246,214,132]},hasl:{name:`HASL`,sentence:`Hot-air levelled solder: silver grey, a little domed.`,face:[190,193,198],rim:[124,127,132],shine:[236,238,242]}},MH={lit:[184,180,156],shaded:[138,132,106]},NH=[70,62,46],PH=Object.keys(kH),FH=Object.keys(AH),IH=Object.keys(jH),LH=/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i;function RH(e={}){let t=e.mask??`green`;if(!(t in kH))throw Error(`mask must be one of ${PH.join(`, `)}`);let n=e.silk??(t===`white`?`black`:`white`);if(!(n in AH))throw Error(`silk must be one of ${FH.join(`, `)}`);let r=e.finish??`enig`;if(!(r in jH))throw Error(`finish must be one of ${IH.join(`, `)}`);if(e.background===void 0)return{mask:t,silk:n,finish:r};let i=LH.exec(e.background);if(!i)throw Error(`background must be a colour written "#rrggbb"`);return{mask:t,silk:n,finish:r,background:[1,2,3].map(e=>parseInt(i[e],16))}}var zH=`Parts are simple shapes, not their real models; heights marked typical come from a package table, assumed ones are guesses.`,BH=e=>String(Math.round(e*100)/100),VH=(e,t)=>e.filter(e=>e.side===t).reduce((e,t)=>e===void 0||t.height>e.height?t:e,void 0);function HH(e){let t=e.board;if(!t)return`No board outline`;let n=t.outline.map(e=>e.from.x),r=t.outline.map(e=>e.from.y);return`Board ${BH(Math.max(...n)-Math.min(...n))} × ${BH(Math.max(...r)-Math.min(...r))} mm, ${BH(t.thickness)} mm thick`}function UH(e){let[t,n]=[VH(e.parts,`top`),VH(e.parts,`bottom`)],r=(e,t)=>`Tallest on ${e}: ${t?`${t.name}, ${BH(t.height)} mm${WH(t)}`:`none`}`,i=e.board?.thickness??0;return{board:HH(e),top:r(`top`,t),bottom:r(`bottom`,n),total:`Total height: ${BH(i+(t?.height??0)+(n?.height??0))} mm`,limits:zH}}var WH=e=>e.state===`typical`||e.state===`assumed`?`, ${e.state}`:``,GH=e=>`${e.name}, ${BH(e.height)} mm high${WH(e)} (${e.side})`;function KH({model:e}){let t=UH(e);return(0,_.createElement)(`ul`,{className:`look-readout`,"aria-label":`Sizes`},(0,_.createElement)(`li`,null,t.board),(0,_.createElement)(`li`,null,t.top),(0,_.createElement)(`li`,null,t.bottom),(0,_.createElement)(`li`,null,t.total),(0,_.createElement)(`li`,{className:`look-limits`},t.limits))}function qH({model:e,active:t,onActive:n}){return(0,_.createElement)(`ul`,{className:`look-parts`,"aria-label":`Parts`},e.parts.map((e,r)=>(0,_.createElement)(`li`,{key:e.name},(0,_.createElement)(`button`,{type:`button`,"aria-pressed":t===r,onFocus:()=>n(r),onBlur:()=>n(void 0),onMouseEnter:()=>n(r),onMouseLeave:()=>n(void 0)},GH(e)))))}function JH({look:e,onLook:t,ready:n}){let r=(e,n,r,i,a)=>(0,_.createElement)(`label`,null,e,` `,(0,_.createElement)(`select`,{value:n,onChange:e=>t(a(e.target.value))},r.map(e=>(0,_.createElement)(`option`,{key:e,value:e},i(e)))));return(0,_.createElement)(`div`,{className:`look-chooser`,role:`group`,"aria-label":`How the board is made`},r(`Mask`,e.mask??`green`,PH,e=>kH[e].name,t=>({...e,mask:t})),r(`Finish`,e.finish??`enig`,IH,e=>jH[e].name,t=>({...e,finish:t})),r(`Print`,e.silk??(e.mask===`white`?`black`:`white`),FH,e=>AH[e].name,t=>({...e,silk:t})),(0,_.createElement)(`p`,{className:`look-note`,"aria-live":`polite`},n?`The board as made, drawn from its fabrication layers.`:`Drawing the board as made…`))}var YH={yaw:-30,pitch:35,zoom:1},XH={yaw:0,pitch:90,zoom:1},ZH={yaw:0,pitch:-90,zoom:1},QH=.4,$H=.2,eU=20,tU=.85,nU=e=>Math.max(-90,Math.min(90,e)),rU=e=>Math.max($H,Math.min(eU,e)),iU=e=>((e+180)%360+360)%360-180,aU=(e,t,n)=>({...e,yaw:iU(e.yaw+t),pitch:nU(e.pitch+n)}),oU=(e,t,n)=>aU(e,-t*QH,n*QH),sU=(e,t)=>({...e,zoom:rU(e.zoom*Math.exp(-t*.0015))});function cU(e,t){switch(t){case`ArrowLeft`:return aU(e,15,0);case`ArrowRight`:return aU(e,-15,0);case`ArrowUp`:return aU(e,0,15);case`ArrowDown`:return aU(e,0,-15);case`+`:case`=`:return sU(e,-200);case`-`:return sU(e,200);case`Home`:case`0`:return YH;case`t`:case`T`:return XH;case`b`:case`B`:return ZH;default:return}}var lU=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],uU=(e,t)=>[e[1]*t[2]-e[2]*t[1],e[2]*t[0]-e[0]*t[2],e[0]*t[1]-e[1]*t[0]];function dU(e,t,n,r){let[i,a]=[e.yaw*Math.PI/180,e.pitch*Math.PI/180],o=[Math.cos(a)*Math.sin(i),-Math.cos(a)*Math.cos(i),Math.sin(a)],s=[Math.cos(i),Math.sin(i),0],c=uU(o,s),[l,u]=t.bounds,d=e.target??[(l[0]+u[0])/2,(l[1]+u[1])/2,(l[2]+u[2])/2],f=Math.hypot(u[0]-l[0],u[1]-l[1],u[2]-l[2])||1;return{eye:o,right:s,up:c,target:d,scale:Math.min(n,r)*tU/f*e.zoom,width:n,height:r}}var fU=e=>`top`in e?e:{top:e,side:e};function pU(e,t,n,r,i,a,o){if(!(n>t)||e.length<3)return[];let{top:s,side:c}=fU(r);return[{loops:[e.map(e=>[e.x,e.y,n])],normal:[0,0,1],color:s,material:i,role:a},...e.map((r,s)=>{let l=e[(s+1)%e.length],u=Math.hypot(l.x-r.x,l.y-r.y)||1;return{loops:[[[r.x,r.y,t],[l.x,l.y,t],[l.x,l.y,n],[r.x,r.y,n]]],normal:[(l.y-r.y)/u,-(l.x-r.x)/u,0],color:o?.(s)??c,material:i,role:a}})]}function mU(e,t,n,r,i,a){return t>n?[{loops:[[...e].reverse().map(e=>[e.x,e.y,n])],normal:[0,0,-1],color:r,material:i,role:a},...pU(e,n,t,r,i,a).slice(1)]:[]}var hU=e=>[{x:e.minX,y:e.minY},{x:e.maxX,y:e.minY},{x:e.maxX,y:e.maxY},{x:e.minX,y:e.maxY}],gU=(e,t,n,r,i,a)=>e.maxX>e.minX&&e.maxY>e.minY?pU(hU(e),t,n,r,i,a):[],_U=(e,t,n,r=20)=>Array.from({length:r},(i,a)=>({x:e+n*Math.cos(2*Math.PI*a/r),y:t+n*Math.sin(2*Math.PI*a/r)}));function vU(e,t,n,r,i=10){let a=r/2,o=Math.max(0,n/2-a),s=(n,r)=>Array.from({length:i+1},(o,s)=>{let c=r+Math.PI*s/i;return{x:e+n+a*Math.cos(c),y:t+a*Math.sin(c)}});return[...s(o,-Math.PI/2),...s(-o,Math.PI/2)]}function yU(e,t){if(t===0)return[...e];let n=t*Math.PI/180,[r,i]=[Math.cos(n),Math.sin(n)],a=e=>[e[0]*r-e[1]*i,e[0]*i+e[1]*r,e[2]];return e.map(e=>({...e,loops:e.loops.map(e=>e.map(a)),normal:a(e.normal)}))}var bU=(e,t)=>({minX:e.minX-t,minY:e.minY-t,maxX:e.maxX+t,maxY:e.maxY+t}),xU=(e,t)=>({minX:Math.max(e.minX,t.minX),minY:Math.max(e.minY,t.minY),maxX:Math.min(e.maxX,t.maxX),maxY:Math.min(e.maxY,t.maxY)}),SU=e=>e.length===0?void 0:{minX:Math.min(...e.map(e=>e.x)),minY:Math.min(...e.map(e=>e.y)),maxX:Math.max(...e.map(e=>e.x)),maxY:Math.max(...e.map(e=>e.y))};function CU(e){let t=e.rotation*Math.PI/180,[n,r]=[Math.abs(Math.cos(t)),Math.abs(Math.sin(t))],[i,a]=[(e.width*n+e.height*r)/2,(e.width*r+e.height*n)/2];return{minX:e.x-i,minY:e.y-a,maxX:e.x+i,maxY:e.y+a}}var wU=e=>SU(e.flatMap(e=>{let t=CU(e);return[{x:t.minX,y:t.minY},{x:t.maxX,y:t.maxY}]})),TU=1.6;function EU(e,t=e.look.metal){return e.pads.flatMap(n=>{if(n.layers!==`through`||n.drill===void 0)return[];let r=Math.min(n.drill.width,n.drill.height)*.32;return mU(_U(n.x,n.y,r,8),0,-(e.thickness+TU),t,`metal`,`lead`)})}var DU=e=>e.find(e=>e.number===`1`)??e[0],OU=.22;function kU(e){let[t,n]=[e.pads.find(e=>e.number===`1`)??e.pads[0],e.pads.find(e=>e.number===`2`)??e.pads[1]];if(t===void 0||n===void 0)return[];let r=Math.atan2(n.y-t.y,n.x-t.x)*180/Math.PI,i=-r*Math.PI/180,a=(e,t)=>e*Math.cos(i)-t*Math.sin(i),o=(e,t)=>e*Math.sin(i)+t*Math.cos(i),s={x:(t.x+n.x)/2,y:(t.y+n.y)/2},c=Math.hypot(n.x-t.x,n.y-t.y),l=CU(n),u=[[l.minX,l.minY],[l.maxX,l.maxY],[l.minX,l.maxY],[l.maxX,l.minY]].map(([e,t])=>({u:a(e-s.x,t-s.y),v:o(e-s.x,t-s.y)})),d=Math.max(...u.map(e=>e.u))-Math.min(...u.map(e=>e.u)),f=Math.max(...u.map(e=>e.v))-Math.min(...u.map(e=>e.v)),p=c+d*.3,m=Math.min(f*.92,p*.62),h=Math.max(p*OU,.1),g=e.height,_=p/2,v=(e,t,n)=>({minX:e,maxX:t,minY:-n/2,maxY:n/2}),{look:y}=e,b=g*.97,x=[...gU(v(-_,-_+h,m*1.02),0,g,y.metal,`metal`,`cap`),...gU(v(_-h,_,m*1.02),0,g,y.metal,`metal`,`cap`),...gU(v(-_+h,_-h,m),.02,b,{top:y.top??y.body,side:y.body},`matt`,`body`)],S=(e,t)=>e!==void 0&&e.join()===t.join();return!S(y.body,y.mark)&&!S(y.top,y.mark)&&x.push(...gU(v(_-h-m*.32,_-h-m*.12,m*.7),b-.01,g,y.mark,`matt`,`cathode`)),AU(yU(x,r).map(e=>({...e,loops:e.loops.map(e=>e.map(e=>[e[0]+s.x,e[1]+s.y,e[2]]))})),e.limit)}function AU(e,t){let n=xU({minX:-1/0,minY:-1/0,maxX:1/0,maxY:1/0},t),r=(e,t,n)=>Math.min(n,Math.max(t,e));return e.map(e=>({...e,loops:e.loops.map(e=>e.map(e=>[r(e[0],n.minX,n.maxX),r(e[1],n.minY,n.maxY),e[2]]))}))}function jU(e){let t=xU(e.body??bU(e.limit,-.15),e.limit),{look:n}=e;return[...AU(gU(t,0,e.height,{top:n.top??n.body,side:n.body},`matt`,`body`),e.limit),...EU(e)]}function MU(e){return gU(e.limit,0,e.height,e.look.body,`matt`,`body`)}var NU=.15;function PU(e){let[t,n]=[e.pads.find(e=>e.number===`1`)??e.pads[0],e.pads.find(e=>e.number===`2`)??e.pads[1]];if(t===void 0||n===void 0)return EU(e);let r=Math.atan2(n.y-t.y,n.x-t.x)*180/Math.PI,i={x:(t.x+n.x)/2,y:(t.y+n.y)/2},a=Math.abs(Math.sin(r*Math.PI/180))>.7,o=e.body??e.limit,s=(a?o.maxY-o.minY:o.maxX-o.minX)-2*NU,c=(a?o.maxX-o.minX:o.maxY-o.minY)-2*NU,l=Math.min(c,s*.6),u=e.height,{look:d}=e,f=Math.min(.5,u*.1);return[...AU(yU([...pU(vU(0,0,s,l),0,f,d.body,`metal`,`body`),...pU(vU(0,0,s-.3,l-.3),f,u,d.body,`metal`,`body`)],r).map(e=>({...e,loops:e.loops.map(e=>e.map(e=>[e[0]+i.x,e[1]+i.y,e[2]]))})),e.limit),...EU(e)]}var FU=24;function IU(e){let t=e.limit,n=Math.min(t.maxX-t.minX,t.maxY-t.minY)/2-NU,r=(t.minX+t.maxX)/2,i=(t.minY+t.maxY)/2,a=e.pads.find(e=>e.number===`2`),o=a===void 0?0:Math.atan2(a.y-i,a.x-r),s=e.height,{look:c}=e,l=Math.min(.4,s*.05);return[...AU([...pU(_U(r,i,n,FU),0,s-l,{top:c.top??c.body,side:c.body},`matt`,`body`,e=>{let t=2*Math.PI*(e+.5)/FU;return Math.abs(Math.atan2(Math.sin(t-o),Math.cos(t-o)))<Math.PI/6?c.mark:void 0}),...pU(_U(r,i,n*.9,FU),s-l,s,c.top??c.metal,`metal`,`body`)],e.limit),...EU(e)]}var LU=[196,198,200],RU={resistor:{sentence:`Chip resistor: a pale ceramic body under a near-black coat, between two tinned end caps.`,body:[216,214,204],top:[34,34,36],metal:LU,mark:[34,34,36]},capacitor:{sentence:`Chip capacitor: a tan ceramic body between two tinned end caps.`,body:[176,138,92],metal:LU,mark:[176,138,92]},led:{sentence:`Chip LED: a white body under a pale yellow lens, a green mark at the cathode.`,body:[234,234,226],top:[244,232,168],metal:LU,mark:[64,168,92]},chip:{sentence:`Any other chip part: a grey-brown body between two tinned end caps.`,body:[120,112,100],metal:LU,mark:[120,112,100]},molded:{sentence:`Moulded diode: a near-black body, a light grey band at the cathode, flat tinned leads.`,body:[44,44,46],metal:LU,mark:[200,200,194]},gullwing:{sentence:`Gull-wing chip: a near-black moulded body with a pin 1 dot, tinned legs bent down to the pads.`,body:[40,40,43],metal:LU,mark:[96,96,100]},leadless:{sentence:`Leadless chip: a near-black body with a pin 1 dot, tinned terminals at its edges.`,body:[40,40,43],metal:LU,mark:[96,96,100]},header:{sentence:`Pin header: a black plastic base with a gold pin on every pad.`,body:[28,28,30],metal:[214,176,86],mark:[28,28,30]},crystal:{sentence:`Crystal: a plain metal can with rounded ends.`,body:[188,190,194],metal:LU,mark:[188,190,194]},electrolytic:{sentence:`Electrolytic capacitor: a dark blue sleeve with a pale stripe at the minus lead, a metal lid.`,body:[38,52,98],top:[182,186,192],metal:LU,mark:[198,204,214]},relay:{sentence:`Relay: a mid-blue box with its leads.`,body:[46,86,156],top:[58,100,170],metal:LU,mark:[46,86,156]},terminal:{sentence:`Connector at another pitch, such as a terminal block: a green box with its leads.`,body:[44,128,78],metal:LU,mark:[44,128,78]},block:{sentence:`Any other through-hole part: a dark grey box with its leads.`,body:[72,74,78],metal:LU,mark:[72,74,78]},box:{sentence:`Anything else: a plain box, as before shapes were drawn.`,body:[96,138,118],metal:LU,mark:[96,138,118]}},zU=new Set([`0201`,`0402`,`0603`,`0805`,`1206`,`1210`,`1812`,`2010`,`2512`]),BU=new Set([`soic`,`sot`,`sop`,`ssop`,`tssop`,`msop`,`qfp`,`lqfp`,`tqfp`,`sc`,`sod323f`]),VU=new Set([`qfn`,`dfn`,`son`,`wson`,`vson`]),HU=new Set([`sod`,`sma`,`smb`,`smc`,`do`,`minimelf`,`melf`]),UU=e=>e===void 0||e.includes(`/`)||e.endsWith(`.yaml`)?void 0:rH(e);function WU(e){return e===`resistor`?`resistor`:e===`capacitor`?`capacitor`:e===`led`?`led`:`chip`}function GU(e){let t=/^[A-Za-z]+/.exec(e)?.[0]?.toUpperCase()??``;return t===`K`?`relay`:t===`J`||t===`P`||t===`X`||t===`CN`?`terminal`:`block`}function KU(e,t,n=!1,r=``){let i=UU(t),a=(e,t)=>({family:e,look:t,...i?{parsed:i}:{}});if(i!==void 0){if(i.kind===``&&zU.has(i.code))return a(`chip`,WU(e));if(HU.has(i.kind))return a(`molded`,`molded`);if(BU.has(i.kind))return a(`gullwing`,`gullwing`);if(VU.has(i.kind))return a(`leadless`,`leadless`);if(i.kind===`pinrow`&&(i.params.p===void 0||i.params.p===2.54))return a(`header`,`header`);if(i.kind===`hc`&&i.code===`49`)return a(`crystal`,`crystal`);if(i.kind===`radial`)return a(`electrolytic`,`electrolytic`);if(i.kind===`pinrow`)return a(`block`,GU(r||`J`))}return n?a(`block`,GU(r)):a(`box`,`box`)}var qU=.15,JU=.08;function YU(e){let t=CU(e);return t.maxX-t.minX>=t.maxY-t.minY?e.x>=0?`right`:`left`:e.y>=0?`top`:`bottom`}function XU(e,t=.02){let n=e.pads.map(e=>({pad:e,side:YU(e),r:CU(e)})),r=e=>n.filter(t=>t.side===e),i=wU(e.pads)??e.limit,a=(e,n)=>{let i=r(e);return i.length===0?n:e===`right`?Math.min(...i.map(e=>e.r.minX))-t:e===`left`?Math.max(...i.map(e=>e.r.maxX))+t:e===`top`?Math.min(...i.map(e=>e.r.minY))-t:Math.max(...i.map(e=>e.r.maxY))+t},o=.45,s={minX:a(`left`,i.minX-(r(`top`).length+r(`bottom`).length,0)+(r(`left`).length===0&&r(`right`).length,0)-o),maxX:a(`right`,i.maxX+o),minY:a(`bottom`,i.minY-o),maxY:a(`top`,i.maxY+o)},c={minX:r(`left`).length===0?Math.max(s.minX,i.minX-o):s.minX,maxX:r(`right`).length===0?Math.min(s.maxX,i.maxX+o):s.maxX,minY:r(`bottom`).length===0?Math.max(s.minY,i.minY-o):s.minY,maxY:r(`top`).length===0?Math.min(s.maxY,i.maxY+o):s.maxY};return xU(e.body?xU(e.body,c):c,e.limit)}function ZU(e,t,n,r,i){let a=CU(e),o=t===`left`||t===`right`,s=t===`right`||t===`top`?1:-1,c=t===`right`?n.maxX:t===`left`?n.minX:t===`top`?n.maxY:n.minY,l=o?e.x:e.y,u=o?a.maxX-a.minX:a.maxY-a.minY,d=o?a.maxY-a.minY:a.maxX-a.minX,f=Math.min(d*.72,.5),p=o?e.y:e.x,m=s*(l-c);if(m<=.05)return[];let h=c+s*Math.min(m*.38,.6),g=l+s*Math.min(u*.3,Math.abs(u/2)-.02),_=Math.min(Math.max(r*.38,qU*1.5),r-qU*1.5),v=(e,t,n,r)=>{let[a,s]=[Math.min(e,t),Math.max(e,t)];return gU(o?{minX:a,maxX:s,minY:p-f/2,maxY:p+f/2}:{minY:a,maxY:s,minX:p-f/2,maxX:p+f/2},n,r,i,`metal`,`leg`)};return[...v(c,h+s*qU,_,_+qU),...v(h,h+s*qU,qU,_),...v(h,g,0,qU)]}function QU(e){let t=XU(e),n=e.height,r=n-.02,{look:i}=e,a=[...gU(t,JU,r,i.body,`matt`,`body`)];for(let r of e.pads)a.push(...ZU(r,YU(r),t,n,i.metal));let o=DU(e.pads);if(o!==void 0){let e=Math.min(t.maxX-t.minX,t.maxY-t.minY),s=Math.min(e*.12,.4),c=s+e*.08,l=o.x<(t.minX+t.maxX)/2?t.minX+c:t.maxX-c,u=o.y<(t.minY+t.maxY)/2?t.minY+c:t.maxY-c;a.push(...pU(_U(l,u,s,12),r-.01,n,i.mark,`matt`,`pin1`))}return AU(a,e.limit)}var $U=2.54,eW=2.5,tW=.64;function nW(e){if(wU(e.pads)===void 0)return[];let t=e.pads.map(e=>e.x),n=e.pads.map(e=>e.y),r=$U/2,i=xU({minX:Math.min(...t)-r,maxX:Math.max(...t)+r,minY:Math.min(...n)-r,maxY:Math.max(...n)+r},e.limit),a=e.height,{look:o}=e,s=Math.min(eW,a*.4),c=[...gU(i,0,s,o.body,`matt`,`body`)];for(let t of e.pads){let n={minX:t.x-tW/2,maxX:t.x+tW/2,minY:t.y-tW/2,maxY:t.y+tW/2};c.push(...gU(n,s,a,o.metal,`metal`,`pin`)),c.push(...mU(hU(n),0,-(e.thickness+TU),o.metal,`metal`,`lead`))}return AU(c.filter(e=>e.role!==`lead`),e.limit).concat(c.filter(e=>e.role===`lead`))}var rW=.2;function iW(e){let t=e.pads.reduce((e,t)=>{let n=CU(t);return{minX:Math.min(e.minX,n.minX),minY:Math.min(e.minY,n.minY),maxX:Math.max(e.maxX,n.maxX),maxY:Math.max(e.maxY,n.maxY)}},{minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}),n=xU(e.body??(Number.isFinite(t.minX)?bU(t,-.05):XU(e)),e.limit),r=e.height,i=r-.02,{look:a}=e,o=[...gU(n,rW*.5,i,a.body,`matt`,`body`)];for(let t of e.pads)o.push(...gU(xU(CU(t),bU(n,.01)),0,rW,a.metal,`metal`,`leg`));let s=DU(e.pads);if(s!==void 0){let e=Math.min(n.maxX-n.minX,n.maxY-n.minY),t=Math.min(e*.1,.35),c=t+e*.1,l=s.x<(n.minX+n.maxX)/2?n.minX+c:n.maxX-c,u=s.y<(n.minY+n.maxY)/2?n.minY+c:n.maxY-c;o.push(...pU(_U(l,u,t,12),i-.01,r,a.mark,`matt`,`pin1`))}return AU(o,e.limit)}var aW=.12;function oW(e){let t=e.pads.find(e=>e.number===`1`)??e.pads[0],n=e.pads.find(e=>e.number===`2`)??e.pads[1];if(t===void 0||n===void 0)return[];let r=Math.atan2(n.y-t.y,n.x-t.x)*180/Math.PI,i={x:(t.x+n.x)/2,y:(t.y+n.y)/2},a=Math.hypot(n.x-t.x,n.y-t.y),o=CU(n),s=Math.abs(Math.sin(r*Math.PI/180))>.7,c=s?o.maxX-o.minX:o.maxY-o.minY,l=s?o.maxY-o.minY:o.maxX-o.minX,u=e.body?s?e.body.maxY-e.body.minY:e.body.maxX-e.body.minX:a-l*.2,d=e.body?s?e.body.maxX-e.body.minX:e.body.maxY-e.body.minY:c*1.4,f=Math.min(u,a+l*.6),p=d,m=e.height,h=m*.97,g=(e,t,n)=>({minX:e,maxX:t,minY:-n/2,maxY:n/2}),{look:_}=e,v=Math.min(c*.6,p*.6),y=Math.max(f*.16,.2);return AU(yU([...gU(g(-a/2-l*.3,-f/2+.05,v),0,aW,_.metal,`metal`,`leg`),...gU(g(f/2-.05,a/2+l*.3,v),0,aW,_.metal,`metal`,`leg`),...gU(g(-f/2,f/2,p),.04,h,_.body,`matt`,`body`),...gU(g(f/2-y*1.9,f/2-y*.9,p*.96),h-.01,m,_.mark,`matt`,`cathode`)],r).map(e=>({...e,loops:e.loops.map(e=>e.map(e=>[e[0]+i.x,e[1]+i.y,e[2]]))})),e.limit)}var sW={chip:kU,molded:oW,gullwing:QU,leadless:iW,header:nW,crystal:PU,electrolytic:IU,block:jU,box:MU},cW={minX:-.5,minY:-.5,maxX:.5,maxY:.5};function lW(e,t){let n=e.rotation*Math.PI/180,[r,i]=[Math.cos(n),Math.sin(n)],a=e.side===`bottom`;return{point:n=>{let[o,s]=[n[0]*r-n[1]*i,n[0]*i+n[1]*r];return[e.x+(a?-o:o),e.y+s,a?-n[2]:t+n[2]]},normal:e=>{let[t,n]=[e[0]*r-e[1]*i,e[0]*i+e[1]*r];return[a?-t:t,n,a?-e[2]:e[2]]}}}function uW(e,t,n,r,i){let a=e.footprint,o=SU(a?.courtyard??[])??SU((a?.pads??[]).map(e=>({x:e.x,y:e.y})))??cW,s=SU((a?.fabrication??[]).flat());return{pads:a?.pads??[],height:t,limit:o,...s?{body:s}:{},look:n,...r?{parsed:r}:{},thickness:i}}function dW(e,t){let n=t.board?.thickness??t.parts.find(e=>e.side===`top`)?.bottom??1.6,r=new Map(e.circuit.components.map(e=>[e.id,e]));return e.pcb.parts.flatMap((e,i)=>{let a=t.parts[i];if(a===void 0)return[];let o=r.get(e.component),s=e.pads.some(e=>e.layers===`through`),{family:c,look:l,parsed:u}=KU(o?.kind??``,o?.footprint,s,e.component),d=uW(e,a.height,RU[l],u,n),f=e.footprint===void 0?MU(d):sW[c](d),p=lW(e,n);return f.map(e=>({loops:e.loops.map(e=>e.map(p.point)),normal:p.normal(e.normal),color:e.color,alpha:1,part:i,material:e.material,role:e.role}))})}var fW=e=>{let t=Math.hypot(e[0],e[1],e[2]);return[e[0]/t,e[1]/t,e[2]/t]},pW=fW([-.55,.5,.78]),mW=.36,hW=.2,gW=.44/pW[2],_W=.55,vW=18,yW=e=>e[2]>=0?pW:[pW[0],pW[1],-pW[2]],bW=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2];function xW(e,t,n,r=`matt`){let i=bW(e,t),a=i<0?[-e[0],-e[1],-e[2]]:e,o=Math.max(0,bW(a,n)),s=mW+hW*Math.abs(i)+gW*o*(r===`metal`?.8:1);if(r!==`metal`)return{scale:s,add:0};let c=fW([n[0]+t[0],n[1]+t[1],n[2]+t[2]]);return{scale:s,add:255*_W*Math.max(0,bW(a,c))**vW}}var SW=.35,CW=.45,wW=1e-6;function TW(e,t,n){if(n&&n.width===e&&n.height===t)return n;let r=e*t;return{width:e,height:t,color:new Uint8ClampedArray(r*4),ids:new Int32Array(r),depth:new Float32Array(r),faces:new Int32Array(r)}}function EW(e,t){let n=lU(e.normal,t.eye);if(Math.abs(n)<wW)return;let r=e.loops[0]?.[0];if(r===void 0)return;let[i,a]=[lU(e.normal,t.right),lU(e.normal,t.up)],o=lU(e.normal,t.target)-lU(e.normal,r),s=i/t.scale/n,c=-a/t.scale/n,l=(o-i*t.width/2/t.scale+a*t.height/2/t.scale)/n;return{loops:e.loops.map(e=>e.map(e=>{let n=[e[0]-t.target[0],e[1]-t.target[1],e[2]-t.target[2]];return{x:t.width/2+t.scale*lU(n,t.right),y:t.height/2-t.scale*lU(n,t.up)}})),a:s,b:c,c:l}}function DW(e,t,n,r){let[i,a]=[1/0,-1/0];for(let t of e.loops)for(let e of t)[i,a]=[Math.min(i,e.y),Math.max(a,e.y)];let o=Math.max(0,Math.ceil(i-.5)),s=Math.min(n-1,Math.floor(a-.5)),c=[];for(let n=o;n<=s;n++){let i=n+.5;c.length=0;for(let t of e.loops)for(let e=0;e<t.length;e++){let n=t[e],r=t[(e+1)%t.length];(n.y<=i&&r.y>i||r.y<=i&&n.y>i)&&c.push(n.x+(i-n.y)/(r.y-n.y)*(r.x-n.x))}c.sort((e,t)=>e-t);for(let a=0;a+1<c.length;a+=2){let o=Math.max(0,Math.ceil(c[a]-.5)),s=Math.min(t-1,Math.floor(c[a+1]-.5));for(let a=o;a<=s;a++)r(n*t+a,e.a*(a+.5)+e.b*i+e.c)}}}function OW(e,t,n){let r=SW+.65*Math.abs(lU(e.normal,t.eye)),i=e.part>=0&&e.part===n?CW:0;return e.color.map(e=>Math.round(e*r+(255-e*r)*i))}function kW(e,t,n,r,i){let a=TW(n,r,i.reuse),o=dU(t,e,n,r),[s,c,l]=i.background;a.color.subarray(0,4).set([s,c,l,255]);for(let e=4;e<a.color.length;e*=2)a.color.copyWithin(e,0,Math.min(e,a.color.length-e));if(a.ids.fill(-1),a.depth.fill(1/0),a.faces.fill(-1),i.lit)return MW(e,o,a,i),a;let u=e.faces.filter(e=>e.alpha>=1),d=e.faces.filter(e=>e.alpha<1);for(let e of u){let t=EW(e,o);if(!t)continue;let[s,c,l]=OW(e,o,i.highlight);DW(t,n,r,(t,n)=>{n>=a.depth[t]||(a.depth[t]=n,a.ids[t]=e.part,a.color[t*4]=s,a.color[t*4+1]=c,a.color[t*4+2]=l)})}for(let e of d){let t=EW(e,o);if(!t)continue;let[i,s,c]=OW(e,o,void 0),l=1-e.alpha;DW(t,n,r,(t,n)=>{n>=a.depth[t]||(a.color[t*4]=a.color[t*4]*l+i*e.alpha,a.color[t*4+1]=a.color[t*4+1]*l+s*e.alpha,a.color[t*4+2]=a.color[t*4+2]*l+c*e.alpha)})}return a}var AW=.78,jW=.94;function MW(e,t,n,r){let i=yW(t.eye),a=new Float32Array(3),{width:o,height:s}=n;e.faces.forEach((e,c)=>{if(lU(e.normal,t.eye)<=0)return;let l=EW(e,t);if(!l)return;let{scale:u,add:d}=xW(e.normal,t.eye,i,e.material),f=e.part>=0&&e.part===r.highlight?CW:0,p=e=>Math.min(255,e*u+d)*(1-f)+255*f,m=e.paint;if(!m){let[t,r,i]=[p(e.color[0]),p(e.color[1]),p(e.color[2])];DW(l,o,s,(a,o)=>{o>=n.depth[a]||(n.depth[a]=o,n.ids[a]=e.part,n.faces[a]=c,n.color[a*4]=t,n.color[a*4+1]=r,n.color[a*4+2]=i)});return}let h=t.scale,{a:g,b:_,c:v}=l,y=e=>({A:t.right[e]/h-g*t.eye[e],B:-t.up[e]/h-_*t.eye[e],C:t.target[e]+(.5-o/2)*t.right[e]/h+(s/2-.5)*t.up[e]/h-(.5*g+.5*_+v)*t.eye[e]}),[b,x,S]=[y(0),y(1),y(2)],C=r.fine??!1,w=m.texture;if(w&&!C){let e=w.mirrored?-1:1,t=w.pxPerMm,[r,i,a]=[e*t*b.A,e*t*b.B,w.origin.x+e*t*b.C],[u,d,f]=[-t*x.A,-t*x.B,w.origin.y-t*x.C],{rgba:m,width:h,height:g}=w;DW(l,o,s,(e,t)=>{if(t>=n.depth[e])return;let s=e/o|0,l=e-s*o,_=Math.floor(r*l+i*s+a),v=Math.floor(u*l+d*s+f);if(_<0||v<0||_>=h||v>=g)return;let y=(v*h+_)*4;m[y+3]<128||(n.depth[e]=t,n.ids[e]=-1,n.faces[e]=c,n.color[e*4]=p(m[y]),n.color[e*4+1]=p(m[y+1]),n.color[e*4+2]=p(m[y+2]))})}else DW(l,o,s,(t,r)=>{if(r>=n.depth[t])return;let i=t/o|0,s=t-i*o,l=b.A*s+b.B*i+b.C,u=x.A*s+x.B*i+x.C,d=S.A*s+S.B*i+S.C;m.at(l,u,d,a,C)<.5||(n.depth[t]=r,n.ids[t]=e.part,n.faces[t]=c,n.color[t*4]=p(a[0]),n.color[t*4+1]=p(a[1]),n.color[t*4+2]=p(a[2]))})}),NW(e,n,t.scale)}function NW(e,t,n){let{width:r,height:i,faces:a,depth:o,color:s}=t,c=2/n,l=new Uint8Array(r*i),u=(t,n)=>{let[r,i]=[a[t],a[n]];if(r===i)return!1;if(r<0||i<0)return r!==i&&(r>=0||i>=0);let[s,l]=[e.faces[r],e.faces[i]];return s.part!==l.part||Math.abs(o[t]-o[n])>c||lU(s.normal,l.normal)<jW};for(let e=0;e<i;e++)for(let t=0;t<r;t++){let n=e*r+t,s=a[n];t+1<r&&a[n+1]!==s&&u(n,n+1)&&(l[o[n]>o[n+1]?n+1:n]=1),e+1<i&&a[n+r]!==s&&u(n,n+r)&&(l[o[n]>o[n+r]?n+r:n]=1)}for(let e=0;e<l.length;e++)!l[e]||a[e]<0||(s[e*4]=s[e*4]*AW,s[e*4+1]=s[e*4+1]*AW,s[e*4+2]=s[e*4+2]*AW)}function PW(e,t,n,r,i,a=2){let o=kW(e,t,n*a,r*a,{...i,reuse:void 0,fine:!0}),s=TW(n,r,i.reuse),c=a*a;for(let e=0;e<r;e++)for(let t=0;t<n;t++){let[r,i,l]=[0,0,0];for(let n=0;n<a;n++)for(let s=0;s<a;s++){let c=((e*a+n)*o.width+t*a+s)*4;r+=o.color[c],i+=o.color[c+1],l+=o.color[c+2]}let u=e*n+t,d=(e*a+(a>>1))*o.width+t*a+(a>>1);s.color[u*4]=r/c,s.color[u*4+1]=i/c,s.color[u*4+2]=l/c,s.color[u*4+3]=255,s.ids[u]=o.ids[d],s.depth[u]=o.depth[d],s.faces[u]=o.faces[d]}return s}function FW(e){let{rgba:t,width:n,height:r,origin:i,pxPerMm:a,mirrored:o}=e,s=o?-1:1;return{texture:e,at(e,o,c,l,u){let d=i.x+s*e*a,f=i.y-o*a;if(!u){let[e,i]=[Math.floor(d),Math.floor(f)];if(e<0||i<0||e>=n||i>=r)return 0;let a=(i*n+e)*4;return l[0]=t[a],l[1]=t[a+1],l[2]=t[a+2],t[a+3]/255}let[p,m]=[d-.5,f-.5],[h,g]=[Math.floor(p),Math.floor(m)],[_,v]=[p-h,m-g],y=0;l[0]=l[1]=l[2]=0;for(let[e,i,a]of[[0,0,(1-_)*(1-v)],[1,0,_*(1-v)],[0,1,(1-_)*v],[1,1,_*v]]){let[o,s]=[Math.min(n-1,Math.max(0,h+e)),Math.min(r-1,Math.max(0,g+i))],c=(s*n+o)*4,u=a*t[c+3]/255;l[0]+=t[c]*u,l[1]+=t[c+1]*u,l[2]+=t[c+2]*u,y+=u}return y>0&&(l[0]/=y,l[1]/=y,l[2]/=y),y}}}var IW=[176,112,58],LW=.0175;function RW(e,t,n){let r=t===4?[0,e/3,2*e/3,e]:[0,e],i=MH.lit;return{at(t,a,o,s){let c=o<.02||o>e-.02,l=r.some(t=>Math.abs(o-(t===0?.027500000000000004:t===e?e-LW-.01:t))<=LW),u=c?n:l?IW:i;return s[0]=u[0],s[1]=u[1],s[2]=u[2],1}}}function zW(e){return{mask:kH[RH({...e,background:void 0}).mask].over,laminate:MH.lit,barrel:NH}}var BW=.45,VW=[40,120,70];function HW(e){let t=Number.parseInt(e.slice(1),16);return[t>>16&255,t>>8&255,t&255]}var UW=e=>HW(e===`top`?W.topAssembly:W.bottomAssembly),WW=Math.PI/12;function GW(e){return e.flatMap(e=>{if(e.kind===`line`)return[e.from];let t=vH(e),n=Math.max(2,Math.ceil(Math.abs(t)/WW)),r=Math.atan2(e.from.y-e.centre.y,e.from.x-e.centre.x);return Array.from({length:n},(i,a)=>{let o=r+t*a/n;return a===0?e.from:{x:e.centre.x+e.radius*Math.cos(o),y:e.centre.y+e.radius*Math.sin(o)}})})}function KW(e,t,n,r,i,a){let o=e=>t=>[t.x,t.y,e];return[{loops:e.map(e=>e.map(o(n))),normal:[0,0,1],color:r,alpha:i,part:a},{loops:e.map(e=>[...e].reverse().map(o(t))),normal:[0,0,-1],color:r,alpha:i,part:a},...e.flatMap(e=>e.map((s,c)=>{let l=e[(c+1)%e.length],u=Math.hypot(l.x-s.x,l.y-s.y)||1;return{loops:[[o(t)(s),o(t)(l),o(n)(l),o(n)(s)]],normal:[(l.y-s.y)/u,-(l.x-s.x)/u,0],color:r,alpha:i,part:a}}))]}function qW(e,t){let n=zW(t.look??{}),r=[e.outline,...e.holes].map(GW),i=e.thickness,a=e=>t=>[t.x,t.y,e],o=e=>e?r.slice(0,1):r,s={loops:o(t.textures?.top).map(e=>e.map(a(i))),normal:[0,0,1],color:n.mask,alpha:1,part:-1,material:`matt`,role:`board`,...t.textures?.top?{paint:FW(t.textures.top)}:{}},c={loops:o(t.textures?.bottom).map(e=>[...e].reverse().map(a(0))),normal:[0,0,-1],color:n.mask,alpha:1,part:-1,material:`matt`,role:`board`,...t.textures?.bottom?{paint:FW(t.textures.bottom)}:{}},l=RW(i,t.layers??2,n.mask),u=t.mounting??0;return[s,c,...r.flatMap((e,t)=>e.map((r,o)=>{let s=e[(o+1)%e.length],c=Math.hypot(s.x-r.x,s.y-r.y)||1,d=t===0,f=!d&&t-1>=u;return{loops:[[a(0)(r),a(0)(s),a(i)(s),a(i)(r)]],normal:[(s.y-r.y)/c,-(s.x-r.x)/c,0],color:f?n.barrel:n.laminate,alpha:1,part:-1,material:f?`metal`:`matt`,role:`board`,...d?{paint:l}:{}}}))]}function JW(e,t){let n=e.board,r=n?t?qW(n,t):KW([n.outline,...n.holes].map(GW),0,n.thickness,VW,BW,-1):[],i=[...t?.parts??e.parts.flatMap((e,t)=>KW([e.corners],e.bottom,e.top,UW(e.side),1,t)),...r],a=[1/0,1/0,1/0],o=[-1/0,-1/0,-1/0];for(let e of i.flatMap(e=>e.loops.flat()))for(let t=0;t<3;t++)a[t]=Math.min(a[t],e[t]),o[t]=Math.max(o[t],e[t]);return{faces:i,bounds:i.length===0?[[0,0,0],[0,0,0]]:[a,o]}}function YW(e){let{width:t,height:n}=e.drill,r={x:e.x,y:e.y};if(t===n)return{diameter:t,at:r,function:`ComponentDrill`};let i=t>n,a=Math.abs(t-n)/2,o=(e.rotation+(i?0:90))*Math.PI/180,[s,c]=[a*Math.cos(o),a*Math.sin(o)];return{diameter:Math.min(t,n),at:{x:e.x-s,y:e.y-c},to:{x:e.x+s,y:e.y+c},function:`ComponentDrill`}}function XW(e){let t=e.parts.flatMap(e=>e.pads).filter(e=>e.layers===`through`&&e.drill!==void 0).map(YW),n=e.vias.filter(e=>e.missingLayer===void 0).map(e=>({diameter:e.drill,at:e.at,function:`ViaDrill`})),r=e.holes.map(e=>({diameter:e.diameter,at:{x:e.x,y:e.y},function:`MechanicalDrill`}));return{plated:[...t,...n],nonPlated:r}}var ZW=c(o(((e,t)=>{(function(){var e={};e.version=`6.4.2.2`,e.use_lines=!0,e.use_xyz=!1;var n=!1;t!==void 0&&t.exports?(t.exports=e,n=!0):(typeof define==`function`&&define.amd&&define(e),typeof document<`u`?window.ClipperLib=e:self.ClipperLib=e);var r;if(n){var i=`chrome`;r=`Netscape`}else{var i=navigator.userAgent.toString().toLowerCase();r=navigator.appName}var a={};a.chrome=+(i.indexOf(`chrome`)!=-1&&i.indexOf(`chromium`)==-1),a.chromium=i.indexOf(`chromium`)==-1?0:1,a.safari=+(i.indexOf(`safari`)!=-1&&i.indexOf(`chrome`)==-1&&i.indexOf(`chromium`)==-1),a.firefox=i.indexOf(`firefox`)==-1?0:1,a.firefox17=i.indexOf(`firefox/17`)==-1?0:1,a.firefox15=i.indexOf(`firefox/15`)==-1?0:1,a.firefox3=i.indexOf(`firefox/3`)==-1?0:1,a.opera=i.indexOf(`opera`)==-1?0:1,a.msie10=i.indexOf(`msie 10`)==-1?0:1,a.msie9=i.indexOf(`msie 9`)==-1?0:1,a.msie8=i.indexOf(`msie 8`)==-1?0:1,a.msie7=i.indexOf(`msie 7`)==-1?0:1,a.msie=i.indexOf(`msie `)==-1?0:1,e.biginteger_used=null;var o,s=!0;function c(t,n,r){e.biginteger_used=1,t!=null&&(typeof t==`number`&&n===void 0?this.fromInt(t):typeof t==`number`?this.fromNumber(t,n,r):n==null&&typeof t!=`string`?this.fromString(t,256):this.fromString(t,n))}function l(){return new c(null,void 0,void 0)}function u(e,t,n,r,i,a){for(;--a>=0;){var o=t*this[e++]+n[r]+i;i=Math.floor(o/67108864),n[r++]=o&67108863}return i}function d(e,t,n,r,i,a){for(var o=t&32767,s=t>>15;--a>=0;){var c=this[e]&32767,l=this[e++]>>15,u=s*c+l*o;c=o*c+((u&32767)<<15)+n[r]+(i&1073741823),i=(c>>>30)+(u>>>15)+s*l+(i>>>30),n[r++]=c&1073741823}return i}function f(e,t,n,r,i,a){for(var o=t&16383,s=t>>14;--a>=0;){var c=this[e]&16383,l=this[e++]>>14,u=s*c+l*o;c=o*c+((u&16383)<<14)+n[r]+i,i=(c>>28)+(u>>14)+s*l,n[r++]=c&268435455}return i}s&&r==`Microsoft Internet Explorer`?(c.prototype.am=d,o=30):s&&r!=`Netscape`?(c.prototype.am=u,o=26):(c.prototype.am=f,o=28),c.prototype.DB=o,c.prototype.DM=(1<<o)-1,c.prototype.DV=1<<o;var p=52;c.prototype.FV=2**p,c.prototype.F1=p-o,c.prototype.F2=2*o-p;for(var m=`0123456789abcdefghijklmnopqrstuvwxyz`,h=[],g=48,_=0;_<=9;++_)h[g++]=_;for(g=97,_=10;_<36;++_)h[g++]=_;for(g=65,_=10;_<36;++_)h[g++]=_;function v(e){return m.charAt(e)}function y(e,t){return h[e.charCodeAt(t)]??-1}function b(e){for(var t=this.t-1;t>=0;--t)e[t]=this[t];e.t=this.t,e.s=this.s}function x(e){this.t=1,this.s=e<0?-1:0,e>0?this[0]=e:e<-1?this[0]=e+this.DV:this.t=0}function S(e){var t=l();return t.fromInt(e),t}function C(e,t){var n;if(t==16)n=4;else if(t==8)n=3;else if(t==256)n=8;else if(t==2)n=1;else if(t==32)n=5;else if(t==4)n=2;else{this.fromRadix(e,t);return}this.t=0,this.s=0;for(var r=e.length,i=!1,a=0;--r>=0;){var o=n==8?e[r]&255:y(e,r);o<0?e.charAt(r)==`-`&&(i=!0):(i=!1,a==0?this[this.t++]=o:a+n>this.DB?(this[this.t-1]|=(o&(1<<this.DB-a)-1)<<a,this[this.t++]=o>>this.DB-a):this[this.t-1]|=o<<a,a+=n,a>=this.DB&&(a-=this.DB))}n==8&&e[0]&128&&(this.s=-1,a>0&&(this[this.t-1]|=(1<<this.DB-a)-1<<a)),this.clamp(),i&&c.ZERO.subTo(this,this)}function w(){for(var e=this.s&this.DM;this.t>0&&this[this.t-1]==e;)--this.t}function T(e){if(this.s<0)return`-`+this.negate().toString(e);var t;if(e==16)t=4;else if(e==8)t=3;else if(e==2)t=1;else if(e==32)t=5;else if(e==4)t=2;else return this.toRadix(e);var n=(1<<t)-1,r,i=!1,a=``,o=this.t,s=this.DB-o*this.DB%t;if(o-->0)for(s<this.DB&&(r=this[o]>>s)>0&&(i=!0,a=v(r));o>=0;)s<t?(r=(this[o]&(1<<s)-1)<<t-s,r|=this[--o]>>(s+=this.DB-t)):(r=this[o]>>(s-=t)&n,s<=0&&(s+=this.DB,--o)),r>0&&(i=!0),i&&(a+=v(r));return i?a:`0`}function E(){var e=l();return c.ZERO.subTo(this,e),e}function D(){return this.s<0?this.negate():this}function O(e){var t=this.s-e.s;if(t!=0)return t;var n=this.t;if(t=n-e.t,t!=0)return this.s<0?-t:t;for(;--n>=0;)if((t=this[n]-e[n])!=0)return t;return 0}function k(e){var t=1,n;return(n=e>>>16)!=0&&(e=n,t+=16),(n=e>>8)!=0&&(e=n,t+=8),(n=e>>4)!=0&&(e=n,t+=4),(n=e>>2)!=0&&(e=n,t+=2),(n=e>>1)!=0&&(e=n,t+=1),t}function A(){return this.t<=0?0:this.DB*(this.t-1)+k(this[this.t-1]^this.s&this.DM)}function j(e,t){for(var n=this.t-1;n>=0;--n)t[n+e]=this[n];for(n=e-1;n>=0;--n)t[n]=0;t.t=this.t+e,t.s=this.s}function M(e,t){for(var n=e;n<this.t;++n)t[n-e]=this[n];t.t=Math.max(this.t-e,0),t.s=this.s}function ee(e,t){for(var n=e%this.DB,r=this.DB-n,i=(1<<r)-1,a=Math.floor(e/this.DB),o=this.s<<n&this.DM,s=this.t-1;s>=0;--s)t[s+a+1]=this[s]>>r|o,o=(this[s]&i)<<n;for(s=a-1;s>=0;--s)t[s]=0;t[a]=o,t.t=this.t+a+1,t.s=this.s,t.clamp()}function te(e,t){t.s=this.s;var n=Math.floor(e/this.DB);if(n>=this.t)t.t=0;else{var r=e%this.DB,i=this.DB-r,a=(1<<r)-1;t[0]=this[n]>>r;for(var o=n+1;o<this.t;++o)t[o-n-1]|=(this[o]&a)<<i,t[o-n]=this[o]>>r;r>0&&(t[this.t-n-1]|=(this.s&a)<<i),t.t=this.t-n,t.clamp()}}function ne(e,t){for(var n=0,r=0,i=Math.min(e.t,this.t);n<i;)r+=this[n]-e[n],t[n++]=r&this.DM,r>>=this.DB;if(e.t<this.t){for(r-=e.s;n<this.t;)r+=this[n],t[n++]=r&this.DM,r>>=this.DB;r+=this.s}else{for(r+=this.s;n<e.t;)r-=e[n],t[n++]=r&this.DM,r>>=this.DB;r-=e.s}t.s=r<0?-1:0,r<-1?t[n++]=this.DV+r:r>0&&(t[n++]=r),t.t=n,t.clamp()}function N(e,t){var n=this.abs(),r=e.abs(),i=n.t;for(t.t=i+r.t;--i>=0;)t[i]=0;for(i=0;i<r.t;++i)t[i+n.t]=n.am(0,r[i],t,i,0,n.t);t.s=0,t.clamp(),this.s!=e.s&&c.ZERO.subTo(t,t)}function P(e){for(var t=this.abs(),n=e.t=2*t.t;--n>=0;)e[n]=0;for(n=0;n<t.t-1;++n){var r=t.am(n,t[n],e,2*n,0,1);(e[n+t.t]+=t.am(n+1,2*t[n],e,2*n+1,r,t.t-n-1))>=t.DV&&(e[n+t.t]-=t.DV,e[n+t.t+1]=1)}e.t>0&&(e[e.t-1]+=t.am(n,t[n],e,2*n,0,1)),e.s=0,e.clamp()}function F(e,t,n){var r=e.abs();if(!(r.t<=0)){var i=this.abs();if(i.t<r.t)t?.fromInt(0),n!=null&&this.copyTo(n);else{n??=l();var a=l(),o=this.s,s=e.s,u=this.DB-k(r[r.t-1]);u>0?(r.lShiftTo(u,a),i.lShiftTo(u,n)):(r.copyTo(a),i.copyTo(n));var d=a.t,f=a[d-1];if(f!=0){var p=f*(1<<this.F1)+(d>1?a[d-2]>>this.F2:0),m=this.FV/p,h=(1<<this.F1)/p,g=1<<this.F2,_=n.t,v=_-d,y=t??l();for(a.dlShiftTo(v,y),n.compareTo(y)>=0&&(n[n.t++]=1,n.subTo(y,n)),c.ONE.dlShiftTo(d,y),y.subTo(a,a);a.t<d;)a[a.t++]=0;for(;--v>=0;){var b=n[--_]==f?this.DM:Math.floor(n[_]*m+(n[_-1]+g)*h);if((n[_]+=a.am(0,b,n,v,0,d))<b)for(a.dlShiftTo(v,y),n.subTo(y,n);n[_]<--b;)n.subTo(y,n)}t!=null&&(n.drShiftTo(d,t),o!=s&&c.ZERO.subTo(t,t)),n.t=d,n.clamp(),u>0&&n.rShiftTo(u,n),o<0&&c.ZERO.subTo(n,n)}}}}function re(e){var t=l();return this.abs().divRemTo(e,null,t),this.s<0&&t.compareTo(c.ZERO)>0&&e.subTo(t,t),t}function I(e){this.m=e}function L(e){return e.s<0||e.compareTo(this.m)>=0?e.mod(this.m):e}function R(e){return e}function z(e){e.divRemTo(this.m,null,e)}function ie(e,t,n){e.multiplyTo(t,n),this.reduce(n)}function ae(e,t){e.squareTo(t),this.reduce(t)}I.prototype.convert=L,I.prototype.revert=R,I.prototype.reduce=z,I.prototype.mulTo=ie,I.prototype.sqrTo=ae;function oe(){if(this.t<1)return 0;var e=this[0];if(!(e&1))return 0;var t=e&3;return t=t*(2-(e&15)*t)&15,t=t*(2-(e&255)*t)&255,t=t*(2-((e&65535)*t&65535))&65535,t=t*(2-e*t%this.DV)%this.DV,t>0?this.DV-t:-t}function se(e){this.m=e,this.mp=e.invDigit(),this.mpl=this.mp&32767,this.mph=this.mp>>15,this.um=(1<<e.DB-15)-1,this.mt2=2*e.t}function ce(e){var t=l();return e.abs().dlShiftTo(this.m.t,t),t.divRemTo(this.m,null,t),e.s<0&&t.compareTo(c.ZERO)>0&&this.m.subTo(t,t),t}function le(e){var t=l();return e.copyTo(t),this.reduce(t),t}function ue(e){for(;e.t<=this.mt2;)e[e.t++]=0;for(var t=0;t<this.m.t;++t){var n=e[t]&32767,r=n*this.mpl+((n*this.mph+(e[t]>>15)*this.mpl&this.um)<<15)&e.DM;for(n=t+this.m.t,e[n]+=this.m.am(0,r,e,t,0,this.m.t);e[n]>=e.DV;)e[n]-=e.DV,e[++n]++}e.clamp(),e.drShiftTo(this.m.t,e),e.compareTo(this.m)>=0&&e.subTo(this.m,e)}function de(e,t){e.squareTo(t),this.reduce(t)}function fe(e,t,n){e.multiplyTo(t,n),this.reduce(n)}se.prototype.convert=ce,se.prototype.revert=le,se.prototype.reduce=ue,se.prototype.mulTo=fe,se.prototype.sqrTo=de;function pe(){return(this.t>0?this[0]&1:this.s)==0}function B(e,t){if(e>4294967295||e<1)return c.ONE;var n=l(),r=l(),i=t.convert(this),a=k(e)-1;for(i.copyTo(n);--a>=0;)if(t.sqrTo(n,r),(e&1<<a)>0)t.mulTo(r,i,n);else{var o=n;n=r,r=o}return t.revert(n)}function me(e,t){var n=e<256||t.isEven()?new I(t):new se(t);return this.exp(e,n)}c.prototype.copyTo=b,c.prototype.fromInt=x,c.prototype.fromString=C,c.prototype.clamp=w,c.prototype.dlShiftTo=j,c.prototype.drShiftTo=M,c.prototype.lShiftTo=ee,c.prototype.rShiftTo=te,c.prototype.subTo=ne,c.prototype.multiplyTo=N,c.prototype.squareTo=P,c.prototype.divRemTo=F,c.prototype.invDigit=oe,c.prototype.isEven=pe,c.prototype.exp=B,c.prototype.toString=T,c.prototype.negate=E,c.prototype.abs=D,c.prototype.compareTo=O,c.prototype.bitLength=A,c.prototype.mod=re,c.prototype.modPowInt=me,c.ZERO=S(0),c.ONE=S(1);function he(){var e=l();return this.copyTo(e),e}function ge(){if(this.s<0){if(this.t==1)return this[0]-this.DV;if(this.t==0)return-1}else if(this.t==1)return this[0];else if(this.t==0)return 0;return(this[1]&(1<<32-this.DB)-1)<<this.DB|this[0]}function _e(){return this.t==0?this.s:this[0]<<24>>24}function ve(){return this.t==0?this.s:this[0]<<16>>16}function V(e){return Math.floor(Math.LN2*this.DB/Math.log(e))}function ye(){return this.s<0?-1:this.t<=0||this.t==1&&this[0]<=0?0:1}function be(e){if(e??=10,this.signum()==0||e<2||e>36)return`0`;var t=this.chunkSize(e),n=e**+t,r=S(n),i=l(),a=l(),o=``;for(this.divRemTo(r,i,a);i.signum()>0;)o=(n+a.intValue()).toString(e).substr(1)+o,i.divRemTo(r,i,a);return a.intValue().toString(e)+o}function xe(e,t){this.fromInt(0),t??=10;for(var n=this.chunkSize(t),r=t**+n,i=!1,a=0,o=0,s=0;s<e.length;++s){var l=y(e,s);l<0?e.charAt(s)==`-`&&this.signum()==0&&(i=!0):(o=t*o+l,++a>=n&&(this.dMultiply(r),this.dAddOffset(o,0),a=0,o=0))}a>0&&(this.dMultiply(t**+a),this.dAddOffset(o,0)),i&&c.ZERO.subTo(this,this)}function Se(e,t,n){if(typeof t==`number`){if(e<2)this.fromInt(1);else for(this.fromNumber(e,n),this.testBit(e-1)||this.bitwiseTo(c.ONE.shiftLeft(e-1),ke,this),this.isEven()&&this.dAddOffset(1,0);!this.isProbablePrime(t);)this.dAddOffset(2,0),this.bitLength()>e&&this.subTo(c.ONE.shiftLeft(e-1),this)}else{var r=[],i=e&7;r.length=(e>>3)+1,t.nextBytes(r),i>0?r[0]&=(1<<i)-1:r[0]=0,this.fromString(r,256)}}function Ce(){var e=this.t,t=[];t[0]=this.s;var n=this.DB-e*this.DB%8,r,i=0;if(e-->0)for(n<this.DB&&(r=this[e]>>n)!=(this.s&this.DM)>>n&&(t[i++]=r|this.s<<this.DB-n);e>=0;)n<8?(r=(this[e]&(1<<n)-1)<<8-n,r|=this[--e]>>(n+=this.DB-8)):(r=this[e]>>(n-=8)&255,n<=0&&(n+=this.DB,--e)),r&128&&(r|=-256),i==0&&(this.s&128)!=(r&128)&&++i,(i>0||r!=this.s)&&(t[i++]=r);return t}function H(e){return this.compareTo(e)==0}function we(e){return this.compareTo(e)<0?this:e}function Te(e){return this.compareTo(e)>0?this:e}function Ee(e,t,n){var r,i,a=Math.min(e.t,this.t);for(r=0;r<a;++r)n[r]=t(this[r],e[r]);if(e.t<this.t){for(i=e.s&this.DM,r=a;r<this.t;++r)n[r]=t(this[r],i);n.t=this.t}else{for(i=this.s&this.DM,r=a;r<e.t;++r)n[r]=t(i,e[r]);n.t=e.t}n.s=t(this.s,e.s),n.clamp()}function De(e,t){return e&t}function Oe(e){var t=l();return this.bitwiseTo(e,De,t),t}function ke(e,t){return e|t}function Ae(e){var t=l();return this.bitwiseTo(e,ke,t),t}function je(e,t){return e^t}function Me(e){var t=l();return this.bitwiseTo(e,je,t),t}function Ne(e,t){return e&~t}function Pe(e){var t=l();return this.bitwiseTo(e,Ne,t),t}function Fe(){for(var e=l(),t=0;t<this.t;++t)e[t]=this.DM&~this[t];return e.t=this.t,e.s=~this.s,e}function Ie(e){var t=l();return e<0?this.rShiftTo(-e,t):this.lShiftTo(e,t),t}function Le(e){var t=l();return e<0?this.lShiftTo(-e,t):this.rShiftTo(e,t),t}function Re(e){if(e==0)return-1;var t=0;return e&65535||(e>>=16,t+=16),e&255||(e>>=8,t+=8),e&15||(e>>=4,t+=4),e&3||(e>>=2,t+=2),e&1||++t,t}function ze(){for(var e=0;e<this.t;++e)if(this[e]!=0)return e*this.DB+Re(this[e]);return this.s<0?this.t*this.DB:-1}function Be(e){for(var t=0;e!=0;)e&=e-1,++t;return t}function Ve(){for(var e=0,t=this.s&this.DM,n=0;n<this.t;++n)e+=Be(this[n]^t);return e}function He(e){var t=Math.floor(e/this.DB);return t>=this.t?this.s!=0:!!(this[t]&1<<e%this.DB)}function Ue(e,t){var n=c.ONE.shiftLeft(e);return this.bitwiseTo(n,t,n),n}function We(e){return this.changeBit(e,ke)}function Ge(e){return this.changeBit(e,Ne)}function Ke(e){return this.changeBit(e,je)}function qe(e,t){for(var n=0,r=0,i=Math.min(e.t,this.t);n<i;)r+=this[n]+e[n],t[n++]=r&this.DM,r>>=this.DB;if(e.t<this.t){for(r+=e.s;n<this.t;)r+=this[n],t[n++]=r&this.DM,r>>=this.DB;r+=this.s}else{for(r+=this.s;n<e.t;)r+=e[n],t[n++]=r&this.DM,r>>=this.DB;r+=e.s}t.s=r<0?-1:0,r>0?t[n++]=r:r<-1&&(t[n++]=this.DV+r),t.t=n,t.clamp()}function Je(e){var t=l();return this.addTo(e,t),t}function Ye(e){var t=l();return this.subTo(e,t),t}function Xe(e){var t=l();return this.multiplyTo(e,t),t}function Ze(){var e=l();return this.squareTo(e),e}function Qe(e){var t=l();return this.divRemTo(e,t,null),t}function $e(e){var t=l();return this.divRemTo(e,null,t),t}function et(e){var t=l(),n=l();return this.divRemTo(e,t,n),[t,n]}function tt(e){this[this.t]=this.am(0,e-1,this,0,0,this.t),++this.t,this.clamp()}function nt(e,t){if(e!=0){for(;this.t<=t;)this[this.t++]=0;for(this[t]+=e;this[t]>=this.DV;)this[t]-=this.DV,++t>=this.t&&(this[this.t++]=0),++this[t]}}function rt(){}function it(e){return e}function at(e,t,n){e.multiplyTo(t,n)}function ot(e,t){e.squareTo(t)}rt.prototype.convert=it,rt.prototype.revert=it,rt.prototype.mulTo=at,rt.prototype.sqrTo=ot;function st(e){return this.exp(e,new rt)}function ct(e,t,n){var r=Math.min(this.t+e.t,t);for(n.s=0,n.t=r;r>0;)n[--r]=0;for(var i=n.t-this.t;r<i;++r)n[r+this.t]=this.am(0,e[r],n,r,0,this.t);for(i=Math.min(e.t,t);r<i;++r)this.am(0,e[r],n,r,0,t-r);n.clamp()}function lt(e,t,n){--t;var r=n.t=this.t+e.t-t;for(n.s=0;--r>=0;)n[r]=0;for(r=Math.max(t-this.t,0);r<e.t;++r)n[this.t+r-t]=this.am(t-r,e[r],n,0,0,this.t+r-t);n.clamp(),n.drShiftTo(1,n)}function ut(e){this.r2=l(),this.q3=l(),c.ONE.dlShiftTo(2*e.t,this.r2),this.mu=this.r2.divide(e),this.m=e}function dt(e){if(e.s<0||e.t>2*this.m.t)return e.mod(this.m);if(e.compareTo(this.m)<0)return e;var t=l();return e.copyTo(t),this.reduce(t),t}function ft(e){return e}function pt(e){for(e.drShiftTo(this.m.t-1,this.r2),e.t>this.m.t+1&&(e.t=this.m.t+1,e.clamp()),this.mu.multiplyUpperTo(this.r2,this.m.t+1,this.q3),this.m.multiplyLowerTo(this.q3,this.m.t+1,this.r2);e.compareTo(this.r2)<0;)e.dAddOffset(1,this.m.t+1);for(e.subTo(this.r2,e);e.compareTo(this.m)>=0;)e.subTo(this.m,e)}function mt(e,t){e.squareTo(t),this.reduce(t)}function ht(e,t,n){e.multiplyTo(t,n),this.reduce(n)}ut.prototype.convert=dt,ut.prototype.revert=ft,ut.prototype.reduce=pt,ut.prototype.mulTo=ht,ut.prototype.sqrTo=mt;function gt(e,t){var n=e.bitLength(),r,i=S(1),a;if(n<=0)return i;r=n<18?1:n<48?3:n<144?4:n<768?5:6,a=n<8?new I(t):t.isEven()?new ut(t):new se(t);var o=[],s=3,c=r-1,u=(1<<r)-1;if(o[1]=a.convert(this),r>1){var d=l();for(a.sqrTo(o[1],d);s<=u;)o[s]=l(),a.mulTo(d,o[s-2],o[s]),s+=2}var f=e.t-1,p,m=!0,h=l(),g;for(n=k(e[f])-1;f>=0;){for(n>=c?p=e[f]>>n-c&u:(p=(e[f]&(1<<n+1)-1)<<c-n,f>0&&(p|=e[f-1]>>this.DB+n-c)),s=r;!(p&1);)p>>=1,--s;if((n-=s)<0&&(n+=this.DB,--f),m)o[p].copyTo(i),m=!1;else{for(;s>1;)a.sqrTo(i,h),a.sqrTo(h,i),s-=2;s>0?a.sqrTo(i,h):(g=i,i=h,h=g),a.mulTo(h,o[p],i)}for(;f>=0&&!(e[f]&1<<n);)a.sqrTo(i,h),g=i,i=h,h=g,--n<0&&(n=this.DB-1,--f)}return a.revert(i)}function _t(e){var t=this.s<0?this.negate():this.clone(),n=e.s<0?e.negate():e.clone();if(t.compareTo(n)<0){var r=t;t=n,n=r}var i=t.getLowestSetBit(),a=n.getLowestSetBit();if(a<0)return t;for(i<a&&(a=i),a>0&&(t.rShiftTo(a,t),n.rShiftTo(a,n));t.signum()>0;)(i=t.getLowestSetBit())>0&&t.rShiftTo(i,t),(i=n.getLowestSetBit())>0&&n.rShiftTo(i,n),t.compareTo(n)>=0?(t.subTo(n,t),t.rShiftTo(1,t)):(n.subTo(t,n),n.rShiftTo(1,n));return a>0&&n.lShiftTo(a,n),n}function vt(e){if(e<=0)return 0;var t=this.DV%e,n=this.s<0?e-1:0;if(this.t>0){if(t==0)n=this[0]%e;else for(var r=this.t-1;r>=0;--r)n=(t*n+this[r])%e}return n}function yt(e){var t=e.isEven();if(this.isEven()&&t||e.signum()==0)return c.ZERO;for(var n=e.clone(),r=this.clone(),i=S(1),a=S(0),o=S(0),s=S(1);n.signum()!=0;){for(;n.isEven();)n.rShiftTo(1,n),t?(i.isEven()&&a.isEven()||(i.addTo(this,i),a.subTo(e,a)),i.rShiftTo(1,i)):a.isEven()||a.subTo(e,a),a.rShiftTo(1,a);for(;r.isEven();)r.rShiftTo(1,r),t?(o.isEven()&&s.isEven()||(o.addTo(this,o),s.subTo(e,s)),o.rShiftTo(1,o)):s.isEven()||s.subTo(e,s),s.rShiftTo(1,s);n.compareTo(r)>=0?(n.subTo(r,n),t&&i.subTo(o,i),a.subTo(s,a)):(r.subTo(n,r),t&&o.subTo(i,o),s.subTo(a,s))}if(r.compareTo(c.ONE)!=0)return c.ZERO;if(s.compareTo(e)>=0)return s.subtract(e);if(s.signum()<0)s.addTo(e,s);else return s;return s.signum()<0?s.add(e):s}var bt=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997],xt=(1<<26)/bt[bt.length-1];function St(e){var t,n=this.abs();if(n.t==1&&n[0]<=bt[bt.length-1]){for(t=0;t<bt.length;++t)if(n[0]==bt[t])return!0;return!1}if(n.isEven())return!1;for(t=1;t<bt.length;){for(var r=bt[t],i=t+1;i<bt.length&&r<xt;)r*=bt[i++];for(r=n.modInt(r);t<i;)if(r%bt[t++]==0)return!1}return n.millerRabin(e)}function Ct(e){var t=this.subtract(c.ONE),n=t.getLowestSetBit();if(n<=0)return!1;var r=t.shiftRight(n);e=e+1>>1,e>bt.length&&(e=bt.length);for(var i=l(),a=0;a<e;++a){i.fromInt(bt[Math.floor(Math.random()*bt.length)]);var o=i.modPow(r,this);if(o.compareTo(c.ONE)!=0&&o.compareTo(t)!=0){for(var s=1;s++<n&&o.compareTo(t)!=0;)if(o=o.modPowInt(2,this),o.compareTo(c.ONE)==0)return!1;if(o.compareTo(t)!=0)return!1}}return!0}c.prototype.chunkSize=V,c.prototype.toRadix=be,c.prototype.fromRadix=xe,c.prototype.fromNumber=Se,c.prototype.bitwiseTo=Ee,c.prototype.changeBit=Ue,c.prototype.addTo=qe,c.prototype.dMultiply=tt,c.prototype.dAddOffset=nt,c.prototype.multiplyLowerTo=ct,c.prototype.multiplyUpperTo=lt,c.prototype.modInt=vt,c.prototype.millerRabin=Ct,c.prototype.clone=he,c.prototype.intValue=ge,c.prototype.byteValue=_e,c.prototype.shortValue=ve,c.prototype.signum=ye,c.prototype.toByteArray=Ce,c.prototype.equals=H,c.prototype.min=we,c.prototype.max=Te,c.prototype.and=Oe,c.prototype.or=Ae,c.prototype.xor=Me,c.prototype.andNot=Pe,c.prototype.not=Fe,c.prototype.shiftLeft=Ie,c.prototype.shiftRight=Le,c.prototype.getLowestSetBit=ze,c.prototype.bitCount=Ve,c.prototype.testBit=He,c.prototype.setBit=We,c.prototype.clearBit=Ge,c.prototype.flipBit=Ke,c.prototype.add=Je,c.prototype.subtract=Ye,c.prototype.multiply=Xe,c.prototype.divide=Qe,c.prototype.remainder=$e,c.prototype.divideAndRemainder=et,c.prototype.modPow=gt,c.prototype.modInverse=yt,c.prototype.pow=st,c.prototype.gcd=_t,c.prototype.isProbablePrime=St,c.prototype.square=Ze;var U=c;U.prototype.IsNegative=function(){return this.compareTo(U.ZERO)==-1},U.op_Equality=function(e,t){return e.compareTo(t)==0},U.op_Inequality=function(e,t){return e.compareTo(t)!=0},U.op_GreaterThan=function(e,t){return e.compareTo(t)>0},U.op_LessThan=function(e,t){return e.compareTo(t)<0},U.op_Addition=function(e,t){return new U(e,void 0,void 0).add(new U(t,void 0,void 0))},U.op_Subtraction=function(e,t){return new U(e,void 0,void 0).subtract(new U(t,void 0,void 0))},U.Int128Mul=function(e,t){return new U(e,void 0,void 0).multiply(new U(t,void 0,void 0))},U.op_Division=function(e,t){return e.divide(t)},U.prototype.ToDouble=function(){return parseFloat(this.toString())};var wt=function(e,t){var n;if(Object.getOwnPropertyNames===void 0){for(n in t.prototype)(e.prototype[n]===void 0||e.prototype[n]===Object.prototype[n])&&(e.prototype[n]=t.prototype[n]);for(n in t)e[n]===void 0&&(e[n]=t[n]);e.$baseCtor=t}else{for(var r=Object.getOwnPropertyNames(t.prototype),i=0;i<r.length;i++)Object.getOwnPropertyDescriptor(e.prototype,r[i])===void 0&&Object.defineProperty(e.prototype,r[i],Object.getOwnPropertyDescriptor(t.prototype,r[i]));for(n in t)e[n]===void 0&&(e[n]=t[n]);e.$baseCtor=t}};e.Path=function(){return[]},e.Path.prototype.push=Array.prototype.push,e.Paths=function(){return[]},e.Paths.prototype.push=Array.prototype.push,e.DoublePoint=function(){var e=arguments;this.X=0,this.Y=0,e.length===1?(this.X=e[0].X,this.Y=e[0].Y):e.length===2&&(this.X=e[0],this.Y=e[1])},e.DoublePoint0=function(){this.X=0,this.Y=0},e.DoublePoint0.prototype=e.DoublePoint.prototype,e.DoublePoint1=function(e){this.X=e.X,this.Y=e.Y},e.DoublePoint1.prototype=e.DoublePoint.prototype,e.DoublePoint2=function(e,t){this.X=e,this.Y=t},e.DoublePoint2.prototype=e.DoublePoint.prototype,e.PolyNode=function(){this.m_Parent=null,this.m_polygon=new e.Path,this.m_Index=0,this.m_jointype=0,this.m_endtype=0,this.m_Childs=[],this.IsOpen=!1},e.PolyNode.prototype.IsHoleNode=function(){for(var e=!0,t=this.m_Parent;t!==null;)e=!e,t=t.m_Parent;return e},e.PolyNode.prototype.ChildCount=function(){return this.m_Childs.length},e.PolyNode.prototype.Contour=function(){return this.m_polygon},e.PolyNode.prototype.AddChild=function(e){var t=this.m_Childs.length;this.m_Childs.push(e),e.m_Parent=this,e.m_Index=t},e.PolyNode.prototype.GetNext=function(){return this.m_Childs.length>0?this.m_Childs[0]:this.GetNextSiblingUp()},e.PolyNode.prototype.GetNextSiblingUp=function(){return this.m_Parent===null?null:this.m_Index===this.m_Parent.m_Childs.length-1?this.m_Parent.GetNextSiblingUp():this.m_Parent.m_Childs[this.m_Index+1]},e.PolyNode.prototype.Childs=function(){return this.m_Childs},e.PolyNode.prototype.Parent=function(){return this.m_Parent},e.PolyNode.prototype.IsHole=function(){return this.IsHoleNode()},e.PolyTree=function(){this.m_AllPolys=[],e.PolyNode.call(this)},e.PolyTree.prototype.Clear=function(){for(var e=0,t=this.m_AllPolys.length;e<t;e++)this.m_AllPolys[e]=null;this.m_AllPolys.length=0,this.m_Childs.length=0},e.PolyTree.prototype.GetFirst=function(){return this.m_Childs.length>0?this.m_Childs[0]:null},e.PolyTree.prototype.Total=function(){var e=this.m_AllPolys.length;return e>0&&this.m_Childs[0]!==this.m_AllPolys[0]&&e--,e},wt(e.PolyTree,e.PolyNode),e.Math_Abs_Int64=e.Math_Abs_Int32=e.Math_Abs_Double=function(e){return Math.abs(e)},e.Math_Max_Int32_Int32=function(e,t){return Math.max(e,t)},e.Cast_Int32=a.msie||a.opera||a.safari?function(e){return e|0}:function(e){return~~e},Number.toInteger===void 0&&(Number.toInteger=null),e.Cast_Int64=a.chrome?function(e){return e<-2147483648||e>2147483647?e<0?Math.ceil(e):Math.floor(e):~~e}:a.firefox&&typeof Number.toInteger==`function`?function(e){return Number.toInteger(e)}:a.msie7||a.msie8?function(e){return parseInt(e,10)}:a.msie?function(e){return e<-2147483648||e>2147483647?e<0?Math.ceil(e):Math.floor(e):e|0}:function(e){return e<0?Math.ceil(e):Math.floor(e)},e.Clear=function(e){e.length=0},e.PI=3.141592653589793,e.PI2=6.283185307179586,e.IntPoint=function(){var t=arguments,n=t.length;if(this.X=0,this.Y=0,e.use_xyz){if(this.Z=0,n===3)this.X=t[0],this.Y=t[1],this.Z=t[2];else if(n===2)this.X=t[0],this.Y=t[1],this.Z=0;else if(n===1){if(t[0]instanceof e.DoublePoint){var r=t[0];this.X=e.Clipper.Round(r.X),this.Y=e.Clipper.Round(r.Y),this.Z=0}else{var i=t[0];i.Z===void 0&&(i.Z=0),this.X=i.X,this.Y=i.Y,this.Z=i.Z}}else this.X=0,this.Y=0,this.Z=0}else if(n===2)this.X=t[0],this.Y=t[1];else if(n===1){if(t[0]instanceof e.DoublePoint){var r=t[0];this.X=e.Clipper.Round(r.X),this.Y=e.Clipper.Round(r.Y)}else{var i=t[0];this.X=i.X,this.Y=i.Y}}else this.X=0,this.Y=0},e.IntPoint.op_Equality=function(e,t){return e.X===t.X&&e.Y===t.Y},e.IntPoint.op_Inequality=function(e,t){return e.X!==t.X||e.Y!==t.Y},e.IntPoint0=function(){this.X=0,this.Y=0,e.use_xyz&&(this.Z=0)},e.IntPoint0.prototype=e.IntPoint.prototype,e.IntPoint1=function(t){this.X=t.X,this.Y=t.Y,e.use_xyz&&(this.Z=t.Z===void 0?0:t.Z)},e.IntPoint1.prototype=e.IntPoint.prototype,e.IntPoint1dp=function(t){this.X=e.Clipper.Round(t.X),this.Y=e.Clipper.Round(t.Y),e.use_xyz&&(this.Z=0)},e.IntPoint1dp.prototype=e.IntPoint.prototype,e.IntPoint2=function(t,n,r){this.X=t,this.Y=n,e.use_xyz&&(this.Z=r===void 0?0:r)},e.IntPoint2.prototype=e.IntPoint.prototype,e.IntRect=function(){var e=arguments,t=e.length;if(t===4)this.left=e[0],this.top=e[1],this.right=e[2],this.bottom=e[3];else if(t===1){var n=e[0];this.left=n.left,this.top=n.top,this.right=n.right,this.bottom=n.bottom}else this.left=0,this.top=0,this.right=0,this.bottom=0},e.IntRect0=function(){this.left=0,this.top=0,this.right=0,this.bottom=0},e.IntRect0.prototype=e.IntRect.prototype,e.IntRect1=function(e){this.left=e.left,this.top=e.top,this.right=e.right,this.bottom=e.bottom},e.IntRect1.prototype=e.IntRect.prototype,e.IntRect4=function(e,t,n,r){this.left=e,this.top=t,this.right=n,this.bottom=r},e.IntRect4.prototype=e.IntRect.prototype,e.ClipType={ctIntersection:0,ctUnion:1,ctDifference:2,ctXor:3},e.PolyType={ptSubject:0,ptClip:1},e.PolyFillType={pftEvenOdd:0,pftNonZero:1,pftPositive:2,pftNegative:3},e.JoinType={jtSquare:0,jtRound:1,jtMiter:2},e.EndType={etOpenSquare:0,etOpenRound:1,etOpenButt:2,etClosedLine:3,etClosedPolygon:4},e.EdgeSide={esLeft:0,esRight:1},e.Direction={dRightToLeft:0,dLeftToRight:1},e.TEdge=function(){this.Bot=new e.IntPoint0,this.Curr=new e.IntPoint0,this.Top=new e.IntPoint0,this.Delta=new e.IntPoint0,this.Dx=0,this.PolyTyp=e.PolyType.ptSubject,this.Side=e.EdgeSide.esLeft,this.WindDelta=0,this.WindCnt=0,this.WindCnt2=0,this.OutIdx=0,this.Next=null,this.Prev=null,this.NextInLML=null,this.NextInAEL=null,this.PrevInAEL=null,this.NextInSEL=null,this.PrevInSEL=null},e.IntersectNode=function(){this.Edge1=null,this.Edge2=null,this.Pt=new e.IntPoint0},e.MyIntersectNodeSort=function(){},e.MyIntersectNodeSort.Compare=function(e,t){var n=t.Pt.Y-e.Pt.Y;return n>0?1:n<0?-1:0},e.LocalMinima=function(){this.Y=0,this.LeftBound=null,this.RightBound=null,this.Next=null},e.Scanbeam=function(){this.Y=0,this.Next=null},e.Maxima=function(){this.X=0,this.Next=null,this.Prev=null},e.OutRec=function(){this.Idx=0,this.IsHole=!1,this.IsOpen=!1,this.FirstLeft=null,this.Pts=null,this.BottomPt=null,this.PolyNode=null},e.OutPt=function(){this.Idx=0,this.Pt=new e.IntPoint0,this.Next=null,this.Prev=null},e.Join=function(){this.OutPt1=null,this.OutPt2=null,this.OffPt=new e.IntPoint0},e.ClipperBase=function(){this.m_MinimaList=null,this.m_CurrentLM=null,this.m_edges=[],this.m_UseFullRange=!1,this.m_HasOpenPaths=!1,this.PreserveCollinear=!1,this.m_Scanbeam=null,this.m_PolyOuts=null,this.m_ActiveEdges=null},e.ClipperBase.horizontal=-9007199254740992,e.ClipperBase.Skip=-2,e.ClipperBase.Unassigned=-1,e.ClipperBase.tolerance=1e-20,e.ClipperBase.loRange=47453132,e.ClipperBase.hiRange=0xfffffffffffff,e.ClipperBase.near_zero=function(t){return t>-e.ClipperBase.tolerance&&t<e.ClipperBase.tolerance},e.ClipperBase.IsHorizontal=function(e){return e.Delta.Y===0},e.ClipperBase.prototype.PointIsVertex=function(t,n){var r=n;do{if(e.IntPoint.op_Equality(r.Pt,t))return!0;r=r.Next}while(r!==n);return!1},e.ClipperBase.prototype.PointOnLineSegment=function(e,t,n,r){return r?e.X===t.X&&e.Y===t.Y||e.X===n.X&&e.Y===n.Y||e.X>t.X==e.X<n.X&&e.Y>t.Y==e.Y<n.Y&&U.op_Equality(U.Int128Mul(e.X-t.X,n.Y-t.Y),U.Int128Mul(n.X-t.X,e.Y-t.Y)):e.X===t.X&&e.Y===t.Y||e.X===n.X&&e.Y===n.Y||e.X>t.X==e.X<n.X&&e.Y>t.Y==e.Y<n.Y&&(e.X-t.X)*(n.Y-t.Y)===(n.X-t.X)*(e.Y-t.Y)},e.ClipperBase.prototype.PointOnPolygon=function(e,t,n){for(var r=t;;){if(this.PointOnLineSegment(e,r.Pt,r.Next.Pt,n))return!0;if(r=r.Next,r===t)break}return!1},e.ClipperBase.prototype.SlopesEqual=e.ClipperBase.SlopesEqual=function(){var t=arguments,n=t.length,r,i,a,o,s,c,l;return n===3?(r=t[0],i=t[1],l=t[2],l?U.op_Equality(U.Int128Mul(r.Delta.Y,i.Delta.X),U.Int128Mul(r.Delta.X,i.Delta.Y)):e.Cast_Int64(r.Delta.Y*i.Delta.X)===e.Cast_Int64(r.Delta.X*i.Delta.Y)):n===4?(a=t[0],o=t[1],s=t[2],l=t[3],l?U.op_Equality(U.Int128Mul(a.Y-o.Y,o.X-s.X),U.Int128Mul(a.X-o.X,o.Y-s.Y)):e.Cast_Int64((a.Y-o.Y)*(o.X-s.X))-e.Cast_Int64((a.X-o.X)*(o.Y-s.Y))===0):(a=t[0],o=t[1],s=t[2],c=t[3],l=t[4],l?U.op_Equality(U.Int128Mul(a.Y-o.Y,s.X-c.X),U.Int128Mul(a.X-o.X,s.Y-c.Y)):e.Cast_Int64((a.Y-o.Y)*(s.X-c.X))-e.Cast_Int64((a.X-o.X)*(s.Y-c.Y))===0)},e.ClipperBase.SlopesEqual3=function(t,n,r){return r?U.op_Equality(U.Int128Mul(t.Delta.Y,n.Delta.X),U.Int128Mul(t.Delta.X,n.Delta.Y)):e.Cast_Int64(t.Delta.Y*n.Delta.X)===e.Cast_Int64(t.Delta.X*n.Delta.Y)},e.ClipperBase.SlopesEqual4=function(t,n,r,i){return i?U.op_Equality(U.Int128Mul(t.Y-n.Y,n.X-r.X),U.Int128Mul(t.X-n.X,n.Y-r.Y)):e.Cast_Int64((t.Y-n.Y)*(n.X-r.X))-e.Cast_Int64((t.X-n.X)*(n.Y-r.Y))===0},e.ClipperBase.SlopesEqual5=function(t,n,r,i,a){return a?U.op_Equality(U.Int128Mul(t.Y-n.Y,r.X-i.X),U.Int128Mul(t.X-n.X,r.Y-i.Y)):e.Cast_Int64((t.Y-n.Y)*(r.X-i.X))-e.Cast_Int64((t.X-n.X)*(r.Y-i.Y))===0},e.ClipperBase.prototype.Clear=function(){this.DisposeLocalMinimaList();for(var t=0,n=this.m_edges.length;t<n;++t){for(var r=0,i=this.m_edges[t].length;r<i;++r)this.m_edges[t][r]=null;e.Clear(this.m_edges[t])}e.Clear(this.m_edges),this.m_UseFullRange=!1,this.m_HasOpenPaths=!1},e.ClipperBase.prototype.DisposeLocalMinimaList=function(){for(;this.m_MinimaList!==null;){var e=this.m_MinimaList.Next;this.m_MinimaList=null,this.m_MinimaList=e}this.m_CurrentLM=null},e.ClipperBase.prototype.RangeTest=function(t,n){n.Value?(t.X>e.ClipperBase.hiRange||t.Y>e.ClipperBase.hiRange||-t.X>e.ClipperBase.hiRange||-t.Y>e.ClipperBase.hiRange)&&e.Error(`Coordinate outside allowed range in RangeTest().`):(t.X>e.ClipperBase.loRange||t.Y>e.ClipperBase.loRange||-t.X>e.ClipperBase.loRange||-t.Y>e.ClipperBase.loRange)&&(n.Value=!0,this.RangeTest(t,n))},e.ClipperBase.prototype.InitEdge=function(t,n,r,i){t.Next=n,t.Prev=r,t.Curr.X=i.X,t.Curr.Y=i.Y,e.use_xyz&&(t.Curr.Z=i.Z),t.OutIdx=-1},e.ClipperBase.prototype.InitEdge2=function(t,n){t.Curr.Y>=t.Next.Curr.Y?(t.Bot.X=t.Curr.X,t.Bot.Y=t.Curr.Y,e.use_xyz&&(t.Bot.Z=t.Curr.Z),t.Top.X=t.Next.Curr.X,t.Top.Y=t.Next.Curr.Y,e.use_xyz&&(t.Top.Z=t.Next.Curr.Z)):(t.Top.X=t.Curr.X,t.Top.Y=t.Curr.Y,e.use_xyz&&(t.Top.Z=t.Curr.Z),t.Bot.X=t.Next.Curr.X,t.Bot.Y=t.Next.Curr.Y,e.use_xyz&&(t.Bot.Z=t.Next.Curr.Z)),this.SetDx(t),t.PolyTyp=n},e.ClipperBase.prototype.FindNextLocMin=function(t){for(var n;;){for(;e.IntPoint.op_Inequality(t.Bot,t.Prev.Bot)||e.IntPoint.op_Equality(t.Curr,t.Top);)t=t.Next;if(t.Dx!==e.ClipperBase.horizontal&&t.Prev.Dx!==e.ClipperBase.horizontal)break;for(;t.Prev.Dx===e.ClipperBase.horizontal;)t=t.Prev;for(n=t;t.Dx===e.ClipperBase.horizontal;)t=t.Next;if(t.Top.Y!==t.Prev.Bot.Y){n.Prev.Bot.X<t.Bot.X&&(t=n);break}}return t},e.ClipperBase.prototype.ProcessBound=function(t,n){var r,i=t,a;if(i.OutIdx===e.ClipperBase.Skip){if(t=i,n){for(;t.Top.Y===t.Next.Bot.Y;)t=t.Next;for(;t!==i&&t.Dx===e.ClipperBase.horizontal;)t=t.Prev}else{for(;t.Top.Y===t.Prev.Bot.Y;)t=t.Prev;for(;t!==i&&t.Dx===e.ClipperBase.horizontal;)t=t.Next}if(t===i)i=n?t.Next:t.Prev;else{t=n?i.Next:i.Prev;var o=new e.LocalMinima;o.Next=null,o.Y=t.Bot.Y,o.LeftBound=null,o.RightBound=t,t.WindDelta=0,i=this.ProcessBound(t,n),this.InsertLocalMinima(o)}return i}if(t.Dx===e.ClipperBase.horizontal&&(r=n?t.Prev:t.Next,r.Dx===e.ClipperBase.horizontal?r.Bot.X!==t.Bot.X&&r.Top.X!==t.Bot.X&&this.ReverseHorizontal(t):r.Bot.X!==t.Bot.X&&this.ReverseHorizontal(t)),r=t,n){for(;i.Top.Y===i.Next.Bot.Y&&i.Next.OutIdx!==e.ClipperBase.Skip;)i=i.Next;if(i.Dx===e.ClipperBase.horizontal&&i.Next.OutIdx!==e.ClipperBase.Skip){for(a=i;a.Prev.Dx===e.ClipperBase.horizontal;)a=a.Prev;a.Prev.Top.X>i.Next.Top.X&&(i=a.Prev)}for(;t!==i;)t.NextInLML=t.Next,t.Dx===e.ClipperBase.horizontal&&t!==r&&t.Bot.X!==t.Prev.Top.X&&this.ReverseHorizontal(t),t=t.Next;t.Dx===e.ClipperBase.horizontal&&t!==r&&t.Bot.X!==t.Prev.Top.X&&this.ReverseHorizontal(t),i=i.Next}else{for(;i.Top.Y===i.Prev.Bot.Y&&i.Prev.OutIdx!==e.ClipperBase.Skip;)i=i.Prev;if(i.Dx===e.ClipperBase.horizontal&&i.Prev.OutIdx!==e.ClipperBase.Skip){for(a=i;a.Next.Dx===e.ClipperBase.horizontal;)a=a.Next;(a.Next.Top.X===i.Prev.Top.X||a.Next.Top.X>i.Prev.Top.X)&&(i=a.Next)}for(;t!==i;)t.NextInLML=t.Prev,t.Dx===e.ClipperBase.horizontal&&t!==r&&t.Bot.X!==t.Next.Top.X&&this.ReverseHorizontal(t),t=t.Prev;t.Dx===e.ClipperBase.horizontal&&t!==r&&t.Bot.X!==t.Next.Top.X&&this.ReverseHorizontal(t),i=i.Prev}return i},e.ClipperBase.prototype.AddPath=function(t,n,r){e.use_lines?!r&&n===e.PolyType.ptClip&&e.Error(`AddPath: Open paths must be subject.`):r||e.Error(`AddPath: Open paths have been disabled.`);var i=t.length-1;if(r)for(;i>0&&e.IntPoint.op_Equality(t[i],t[0]);)--i;for(;i>0&&e.IntPoint.op_Equality(t[i],t[i-1]);)--i;if(r&&i<2||!r&&i<1)return!1;for(var a=[],o=0;o<=i;o++)a.push(new e.TEdge);var s=!0;a[1].Curr.X=t[1].X,a[1].Curr.Y=t[1].Y,e.use_xyz&&(a[1].Curr.Z=t[1].Z);var c={Value:this.m_UseFullRange};this.RangeTest(t[0],c),this.m_UseFullRange=c.Value,c.Value=this.m_UseFullRange,this.RangeTest(t[i],c),this.m_UseFullRange=c.Value,this.InitEdge(a[0],a[1],a[i],t[0]),this.InitEdge(a[i],a[0],a[i-1],t[i]);for(var o=i-1;o>=1;--o)c.Value=this.m_UseFullRange,this.RangeTest(t[o],c),this.m_UseFullRange=c.Value,this.InitEdge(a[o],a[o+1],a[o-1],t[o]);for(var l=a[0],u=l,d=l;;)if(u.Curr===u.Next.Curr&&(r||u.Next!==l)){if(u===u.Next)break;u===l&&(l=u.Next),u=this.RemoveEdge(u),d=u}else{if(u.Prev===u.Next)break;if(r&&e.ClipperBase.SlopesEqual4(u.Prev.Curr,u.Curr,u.Next.Curr,this.m_UseFullRange)&&(!this.PreserveCollinear||!this.Pt2IsBetweenPt1AndPt3(u.Prev.Curr,u.Curr,u.Next.Curr)))u===l&&(l=u.Next),u=this.RemoveEdge(u),u=u.Prev,d=u;else if(u=u.Next,u===d||!r&&u.Next===l)break}if(!r&&u===u.Next||r&&u.Prev===u.Next)return!1;r||(this.m_HasOpenPaths=!0,l.Prev.OutIdx=e.ClipperBase.Skip),u=l;do this.InitEdge2(u,n),u=u.Next,s&&u.Curr.Y!==l.Curr.Y&&(s=!1);while(u!==l);if(s){if(r)return!1;u.Prev.OutIdx=e.ClipperBase.Skip;var f=new e.LocalMinima;for(f.Next=null,f.Y=u.Bot.Y,f.LeftBound=null,f.RightBound=u,f.RightBound.Side=e.EdgeSide.esRight,f.RightBound.WindDelta=0;u.Bot.X!==u.Prev.Top.X&&this.ReverseHorizontal(u),u.Next.OutIdx!==e.ClipperBase.Skip;)u.NextInLML=u.Next,u=u.Next;return this.InsertLocalMinima(f),this.m_edges.push(a),!0}this.m_edges.push(a);var p,m=null;for(e.IntPoint.op_Equality(u.Prev.Bot,u.Prev.Top)&&(u=u.Next);u=this.FindNextLocMin(u),u!==m;){m===null&&(m=u);var f=new e.LocalMinima;f.Next=null,f.Y=u.Bot.Y,u.Dx<u.Prev.Dx?(f.LeftBound=u.Prev,f.RightBound=u,p=!1):(f.LeftBound=u,f.RightBound=u.Prev,p=!0),f.LeftBound.Side=e.EdgeSide.esLeft,f.RightBound.Side=e.EdgeSide.esRight,r?f.LeftBound.Next===f.RightBound?f.LeftBound.WindDelta=-1:f.LeftBound.WindDelta=1:f.LeftBound.WindDelta=0,f.RightBound.WindDelta=-f.LeftBound.WindDelta,u=this.ProcessBound(f.LeftBound,p),u.OutIdx===e.ClipperBase.Skip&&(u=this.ProcessBound(u,p));var h=this.ProcessBound(f.RightBound,!p);h.OutIdx===e.ClipperBase.Skip&&(h=this.ProcessBound(h,!p)),f.LeftBound.OutIdx===e.ClipperBase.Skip?f.LeftBound=null:f.RightBound.OutIdx===e.ClipperBase.Skip&&(f.RightBound=null),this.InsertLocalMinima(f),p||(u=h)}return!0},e.ClipperBase.prototype.AddPaths=function(e,t,n){for(var r=!1,i=0,a=e.length;i<a;++i)this.AddPath(e[i],t,n)&&(r=!0);return r},e.ClipperBase.prototype.Pt2IsBetweenPt1AndPt3=function(t,n,r){return e.IntPoint.op_Equality(t,r)||e.IntPoint.op_Equality(t,n)||e.IntPoint.op_Equality(r,n)?!1:t.X===r.X?n.Y>t.Y==n.Y<r.Y:n.X>t.X==n.X<r.X},e.ClipperBase.prototype.RemoveEdge=function(e){e.Prev.Next=e.Next,e.Next.Prev=e.Prev;var t=e.Next;return e.Prev=null,t},e.ClipperBase.prototype.SetDx=function(t){t.Delta.X=t.Top.X-t.Bot.X,t.Delta.Y=t.Top.Y-t.Bot.Y,t.Dx=t.Delta.Y===0?e.ClipperBase.horizontal:t.Delta.X/t.Delta.Y},e.ClipperBase.prototype.InsertLocalMinima=function(e){if(this.m_MinimaList===null)this.m_MinimaList=e;else if(e.Y>=this.m_MinimaList.Y)e.Next=this.m_MinimaList,this.m_MinimaList=e;else{for(var t=this.m_MinimaList;t.Next!==null&&e.Y<t.Next.Y;)t=t.Next;e.Next=t.Next,t.Next=e}},e.ClipperBase.prototype.PopLocalMinima=function(e,t){return t.v=this.m_CurrentLM,this.m_CurrentLM!==null&&this.m_CurrentLM.Y===e&&(this.m_CurrentLM=this.m_CurrentLM.Next,!0)},e.ClipperBase.prototype.ReverseHorizontal=function(t){var n=t.Top.X;t.Top.X=t.Bot.X,t.Bot.X=n,e.use_xyz&&(n=t.Top.Z,t.Top.Z=t.Bot.Z,t.Bot.Z=n)},e.ClipperBase.prototype.Reset=function(){if(this.m_CurrentLM=this.m_MinimaList,this.m_CurrentLM!==null){this.m_Scanbeam=null;for(var t=this.m_MinimaList;t!==null;){this.InsertScanbeam(t.Y);var n=t.LeftBound;n!==null&&(n.Curr.X=n.Bot.X,n.Curr.Y=n.Bot.Y,e.use_xyz&&(n.Curr.Z=n.Bot.Z),n.OutIdx=e.ClipperBase.Unassigned),n=t.RightBound,n!==null&&(n.Curr.X=n.Bot.X,n.Curr.Y=n.Bot.Y,e.use_xyz&&(n.Curr.Z=n.Bot.Z),n.OutIdx=e.ClipperBase.Unassigned),t=t.Next}this.m_ActiveEdges=null}},e.ClipperBase.prototype.InsertScanbeam=function(t){if(this.m_Scanbeam===null)this.m_Scanbeam=new e.Scanbeam,this.m_Scanbeam.Next=null,this.m_Scanbeam.Y=t;else if(t>this.m_Scanbeam.Y){var n=new e.Scanbeam;n.Y=t,n.Next=this.m_Scanbeam,this.m_Scanbeam=n}else{for(var r=this.m_Scanbeam;r.Next!==null&&t<=r.Next.Y;)r=r.Next;if(t===r.Y)return;var i=new e.Scanbeam;i.Y=t,i.Next=r.Next,r.Next=i}},e.ClipperBase.prototype.PopScanbeam=function(e){return this.m_Scanbeam===null?(e.v=0,!1):(e.v=this.m_Scanbeam.Y,this.m_Scanbeam=this.m_Scanbeam.Next,!0)},e.ClipperBase.prototype.LocalMinimaPending=function(){return this.m_CurrentLM!==null},e.ClipperBase.prototype.CreateOutRec=function(){var t=new e.OutRec;return t.Idx=e.ClipperBase.Unassigned,t.IsHole=!1,t.IsOpen=!1,t.FirstLeft=null,t.Pts=null,t.BottomPt=null,t.PolyNode=null,this.m_PolyOuts.push(t),t.Idx=this.m_PolyOuts.length-1,t},e.ClipperBase.prototype.DisposeOutRec=function(e){var t=this.m_PolyOuts[e];t.Pts=null,t=null,this.m_PolyOuts[e]=null},e.ClipperBase.prototype.UpdateEdgeIntoAEL=function(t){t.NextInLML===null&&e.Error(`UpdateEdgeIntoAEL: invalid call`);var n=t.PrevInAEL,r=t.NextInAEL;return t.NextInLML.OutIdx=t.OutIdx,n===null?this.m_ActiveEdges=t.NextInLML:n.NextInAEL=t.NextInLML,r!==null&&(r.PrevInAEL=t.NextInLML),t.NextInLML.Side=t.Side,t.NextInLML.WindDelta=t.WindDelta,t.NextInLML.WindCnt=t.WindCnt,t.NextInLML.WindCnt2=t.WindCnt2,t=t.NextInLML,t.Curr.X=t.Bot.X,t.Curr.Y=t.Bot.Y,t.PrevInAEL=n,t.NextInAEL=r,e.ClipperBase.IsHorizontal(t)||this.InsertScanbeam(t.Top.Y),t},e.ClipperBase.prototype.SwapPositionsInAEL=function(e,t){if(e.NextInAEL!==e.PrevInAEL&&t.NextInAEL!==t.PrevInAEL){if(e.NextInAEL===t){var n=t.NextInAEL;n!==null&&(n.PrevInAEL=e);var r=e.PrevInAEL;r!==null&&(r.NextInAEL=t),t.PrevInAEL=r,t.NextInAEL=e,e.PrevInAEL=t,e.NextInAEL=n}else if(t.NextInAEL===e){var i=e.NextInAEL;i!==null&&(i.PrevInAEL=t);var a=t.PrevInAEL;a!==null&&(a.NextInAEL=e),e.PrevInAEL=a,e.NextInAEL=t,t.PrevInAEL=e,t.NextInAEL=i}else{var o=e.NextInAEL,s=e.PrevInAEL;e.NextInAEL=t.NextInAEL,e.NextInAEL!==null&&(e.NextInAEL.PrevInAEL=e),e.PrevInAEL=t.PrevInAEL,e.PrevInAEL!==null&&(e.PrevInAEL.NextInAEL=e),t.NextInAEL=o,t.NextInAEL!==null&&(t.NextInAEL.PrevInAEL=t),t.PrevInAEL=s,t.PrevInAEL!==null&&(t.PrevInAEL.NextInAEL=t)}e.PrevInAEL===null?this.m_ActiveEdges=e:t.PrevInAEL===null&&(this.m_ActiveEdges=t)}},e.ClipperBase.prototype.DeleteFromAEL=function(e){var t=e.PrevInAEL,n=e.NextInAEL;(t!==null||n!==null||e===this.m_ActiveEdges)&&(t===null?this.m_ActiveEdges=n:t.NextInAEL=n,n!==null&&(n.PrevInAEL=t),e.NextInAEL=null,e.PrevInAEL=null)},e.Clipper=function(t){t===void 0&&(t=0),this.m_PolyOuts=null,this.m_ClipType=e.ClipType.ctIntersection,this.m_Scanbeam=null,this.m_Maxima=null,this.m_ActiveEdges=null,this.m_SortedEdges=null,this.m_IntersectList=null,this.m_IntersectNodeComparer=null,this.m_ExecuteLocked=!1,this.m_ClipFillType=e.PolyFillType.pftEvenOdd,this.m_SubjFillType=e.PolyFillType.pftEvenOdd,this.m_Joins=null,this.m_GhostJoins=null,this.m_UsingPolyTree=!1,this.ReverseSolution=!1,this.StrictlySimple=!1,e.ClipperBase.call(this),this.m_Scanbeam=null,this.m_Maxima=null,this.m_ActiveEdges=null,this.m_SortedEdges=null,this.m_IntersectList=[],this.m_IntersectNodeComparer=e.MyIntersectNodeSort.Compare,this.m_ExecuteLocked=!1,this.m_UsingPolyTree=!1,this.m_PolyOuts=[],this.m_Joins=[],this.m_GhostJoins=[],this.ReverseSolution=!!(1&t),this.StrictlySimple=!!(2&t),this.PreserveCollinear=!!(4&t),e.use_xyz&&(this.ZFillFunction=null)},e.Clipper.ioReverseSolution=1,e.Clipper.ioStrictlySimple=2,e.Clipper.ioPreserveCollinear=4,e.Clipper.prototype.Clear=function(){this.m_edges.length!==0&&(this.DisposeAllPolyPts(),e.ClipperBase.prototype.Clear.call(this))},e.Clipper.prototype.InsertMaxima=function(t){var n=new e.Maxima;if(n.X=t,this.m_Maxima===null)this.m_Maxima=n,this.m_Maxima.Next=null,this.m_Maxima.Prev=null;else if(t<this.m_Maxima.X)n.Next=this.m_Maxima,n.Prev=null,this.m_Maxima=n;else{for(var r=this.m_Maxima;r.Next!==null&&t>=r.Next.X;)r=r.Next;if(t===r.X)return;n.Next=r.Next,n.Prev=r,r.Next!==null&&(r.Next.Prev=n),r.Next=n}},e.Clipper.prototype.Execute=function(){var t=arguments,n=t.length,r=t[1]instanceof e.PolyTree;if(n===4&&!r){var i=t[0],a=t[1],o=t[2],s=t[3];if(this.m_ExecuteLocked)return!1;this.m_HasOpenPaths&&e.Error(`Error: PolyTree struct is needed for open path clipping.`),this.m_ExecuteLocked=!0,e.Clear(a),this.m_SubjFillType=o,this.m_ClipFillType=s,this.m_ClipType=i,this.m_UsingPolyTree=!1;try{var c=this.ExecuteInternal();c&&this.BuildResult(a)}finally{this.DisposeAllPolyPts(),this.m_ExecuteLocked=!1}return c}if(n===4&&r){var i=t[0],l=t[1],o=t[2],s=t[3];if(this.m_ExecuteLocked)return!1;this.m_ExecuteLocked=!0,this.m_SubjFillType=o,this.m_ClipFillType=s,this.m_ClipType=i,this.m_UsingPolyTree=!0;try{var c=this.ExecuteInternal();c&&this.BuildResult2(l)}finally{this.DisposeAllPolyPts(),this.m_ExecuteLocked=!1}return c}if(n===2&&!r){var i=t[0],a=t[1];return this.Execute(i,a,e.PolyFillType.pftEvenOdd,e.PolyFillType.pftEvenOdd)}if(n===2&&r){var i=t[0],l=t[1];return this.Execute(i,l,e.PolyFillType.pftEvenOdd,e.PolyFillType.pftEvenOdd)}},e.Clipper.prototype.FixHoleLinkage=function(e){if(!(e.FirstLeft===null||e.IsHole!==e.FirstLeft.IsHole&&e.FirstLeft.Pts!==null)){for(var t=e.FirstLeft;t!==null&&(t.IsHole===e.IsHole||t.Pts===null);)t=t.FirstLeft;e.FirstLeft=t}},e.Clipper.prototype.ExecuteInternal=function(){try{this.Reset(),this.m_SortedEdges=null,this.m_Maxima=null;var e={},t={};if(!this.PopScanbeam(e))return!1;for(this.InsertLocalMinimaIntoAEL(e.v);this.PopScanbeam(t)||this.LocalMinimaPending();){if(this.ProcessHorizontals(),this.m_GhostJoins.length=0,!this.ProcessIntersections(t.v))return!1;this.ProcessEdgesAtTopOfScanbeam(t.v),e.v=t.v,this.InsertLocalMinimaIntoAEL(e.v)}for(var n,r=0,i=this.m_PolyOuts.length;r<i;r++)n=this.m_PolyOuts[r],n.Pts===null||n.IsOpen||(n.IsHole^this.ReverseSolution)==this.Area$1(n)>0&&this.ReversePolyPtLinks(n.Pts);for(this.JoinCommonEdges(),r=0,i=this.m_PolyOuts.length;r<i;r++)n=this.m_PolyOuts[r],n.Pts!==null&&(n.IsOpen?this.FixupOutPolyline(n):this.FixupOutPolygon(n));return this.StrictlySimple&&this.DoSimplePolygons(),!0}finally{this.m_Joins.length=0,this.m_GhostJoins.length=0}},e.Clipper.prototype.DisposeAllPolyPts=function(){for(var t=0,n=this.m_PolyOuts.length;t<n;++t)this.DisposeOutRec(t);e.Clear(this.m_PolyOuts)},e.Clipper.prototype.AddJoin=function(t,n,r){var i=new e.Join;i.OutPt1=t,i.OutPt2=n,i.OffPt.X=r.X,i.OffPt.Y=r.Y,e.use_xyz&&(i.OffPt.Z=r.Z),this.m_Joins.push(i)},e.Clipper.prototype.AddGhostJoin=function(t,n){var r=new e.Join;r.OutPt1=t,r.OffPt.X=n.X,r.OffPt.Y=n.Y,e.use_xyz&&(r.OffPt.Z=n.Z),this.m_GhostJoins.push(r)},e.Clipper.prototype.SetZ=function(t,n,r){if(this.ZFillFunction!==null){if(t.Z!==0||this.ZFillFunction===null)return;e.IntPoint.op_Equality(t,n.Bot)?t.Z=n.Bot.Z:e.IntPoint.op_Equality(t,n.Top)?t.Z=n.Top.Z:e.IntPoint.op_Equality(t,r.Bot)?t.Z=r.Bot.Z:e.IntPoint.op_Equality(t,r.Top)?t.Z=r.Top.Z:this.ZFillFunction(n.Bot,n.Top,r.Bot,r.Top,t)}},e.Clipper.prototype.InsertLocalMinimaIntoAEL=function(t){for(var n={},r,i;this.PopLocalMinima(t,n);){r=n.v.LeftBound,i=n.v.RightBound;var a=null;if(r===null?(this.InsertEdgeIntoAEL(i,null),this.SetWindingCount(i),this.IsContributing(i)&&(a=this.AddOutPt(i,i.Bot))):i===null?(this.InsertEdgeIntoAEL(r,null),this.SetWindingCount(r),this.IsContributing(r)&&(a=this.AddOutPt(r,r.Bot)),this.InsertScanbeam(r.Top.Y)):(this.InsertEdgeIntoAEL(r,null),this.InsertEdgeIntoAEL(i,r),this.SetWindingCount(r),i.WindCnt=r.WindCnt,i.WindCnt2=r.WindCnt2,this.IsContributing(r)&&(a=this.AddLocalMinPoly(r,i,r.Bot)),this.InsertScanbeam(r.Top.Y)),i!==null&&(e.ClipperBase.IsHorizontal(i)?(i.NextInLML!==null&&this.InsertScanbeam(i.NextInLML.Top.Y),this.AddEdgeToSEL(i)):this.InsertScanbeam(i.Top.Y)),r!==null&&i!==null){if(a!==null&&e.ClipperBase.IsHorizontal(i)&&this.m_GhostJoins.length>0&&i.WindDelta!==0)for(var o=0,s=this.m_GhostJoins.length;o<s;o++){var c=this.m_GhostJoins[o];this.HorzSegmentsOverlap(c.OutPt1.Pt.X,c.OffPt.X,i.Bot.X,i.Top.X)&&this.AddJoin(c.OutPt1,a,c.OffPt)}if(r.OutIdx>=0&&r.PrevInAEL!==null&&r.PrevInAEL.Curr.X===r.Bot.X&&r.PrevInAEL.OutIdx>=0&&e.ClipperBase.SlopesEqual5(r.PrevInAEL.Curr,r.PrevInAEL.Top,r.Curr,r.Top,this.m_UseFullRange)&&r.WindDelta!==0&&r.PrevInAEL.WindDelta!==0){var l=this.AddOutPt(r.PrevInAEL,r.Bot);this.AddJoin(a,l,r.Top)}if(r.NextInAEL!==i){if(i.OutIdx>=0&&i.PrevInAEL.OutIdx>=0&&e.ClipperBase.SlopesEqual5(i.PrevInAEL.Curr,i.PrevInAEL.Top,i.Curr,i.Top,this.m_UseFullRange)&&i.WindDelta!==0&&i.PrevInAEL.WindDelta!==0){var l=this.AddOutPt(i.PrevInAEL,i.Bot);this.AddJoin(a,l,i.Top)}var u=r.NextInAEL;if(u!==null)for(;u!==i;)this.IntersectEdges(i,u,r.Curr),u=u.NextInAEL}}}},e.Clipper.prototype.InsertEdgeIntoAEL=function(e,t){if(this.m_ActiveEdges===null)e.PrevInAEL=null,e.NextInAEL=null,this.m_ActiveEdges=e;else if(t===null&&this.E2InsertsBeforeE1(this.m_ActiveEdges,e))e.PrevInAEL=null,e.NextInAEL=this.m_ActiveEdges,this.m_ActiveEdges.PrevInAEL=e,this.m_ActiveEdges=e;else{for(t===null&&(t=this.m_ActiveEdges);t.NextInAEL!==null&&!this.E2InsertsBeforeE1(t.NextInAEL,e);)t=t.NextInAEL;e.NextInAEL=t.NextInAEL,t.NextInAEL!==null&&(t.NextInAEL.PrevInAEL=e),e.PrevInAEL=t,t.NextInAEL=e}},e.Clipper.prototype.E2InsertsBeforeE1=function(t,n){return n.Curr.X===t.Curr.X?n.Top.Y>t.Top.Y?n.Top.X<e.Clipper.TopX(t,n.Top.Y):t.Top.X>e.Clipper.TopX(n,t.Top.Y):n.Curr.X<t.Curr.X},e.Clipper.prototype.IsEvenOddFillType=function(t){return t.PolyTyp===e.PolyType.ptSubject?this.m_SubjFillType===e.PolyFillType.pftEvenOdd:this.m_ClipFillType===e.PolyFillType.pftEvenOdd},e.Clipper.prototype.IsEvenOddAltFillType=function(t){return t.PolyTyp===e.PolyType.ptSubject?this.m_ClipFillType===e.PolyFillType.pftEvenOdd:this.m_SubjFillType===e.PolyFillType.pftEvenOdd},e.Clipper.prototype.IsContributing=function(t){var n,r;switch(t.PolyTyp===e.PolyType.ptSubject?(n=this.m_SubjFillType,r=this.m_ClipFillType):(n=this.m_ClipFillType,r=this.m_SubjFillType),n){case e.PolyFillType.pftEvenOdd:if(t.WindDelta===0&&t.WindCnt!==1)return!1;break;case e.PolyFillType.pftNonZero:if(Math.abs(t.WindCnt)!==1)return!1;break;case e.PolyFillType.pftPositive:if(t.WindCnt!==1)return!1;break;default:if(t.WindCnt!==-1)return!1}switch(this.m_ClipType){case e.ClipType.ctIntersection:switch(r){case e.PolyFillType.pftEvenOdd:case e.PolyFillType.pftNonZero:return t.WindCnt2!==0;case e.PolyFillType.pftPositive:return t.WindCnt2>0;default:return t.WindCnt2<0}case e.ClipType.ctUnion:switch(r){case e.PolyFillType.pftEvenOdd:case e.PolyFillType.pftNonZero:return t.WindCnt2===0;case e.PolyFillType.pftPositive:return t.WindCnt2<=0;default:return t.WindCnt2>=0}case e.ClipType.ctDifference:if(t.PolyTyp===e.PolyType.ptSubject)switch(r){case e.PolyFillType.pftEvenOdd:case e.PolyFillType.pftNonZero:return t.WindCnt2===0;case e.PolyFillType.pftPositive:return t.WindCnt2<=0;default:return t.WindCnt2>=0}else switch(r){case e.PolyFillType.pftEvenOdd:case e.PolyFillType.pftNonZero:return t.WindCnt2!==0;case e.PolyFillType.pftPositive:return t.WindCnt2>0;default:return t.WindCnt2<0}case e.ClipType.ctXor:if(t.WindDelta===0)switch(r){case e.PolyFillType.pftEvenOdd:case e.PolyFillType.pftNonZero:return t.WindCnt2===0;case e.PolyFillType.pftPositive:return t.WindCnt2<=0;default:return t.WindCnt2>=0}else return!0}return!0},e.Clipper.prototype.SetWindingCount=function(t){for(var n=t.PrevInAEL;n!==null&&(n.PolyTyp!==t.PolyTyp||n.WindDelta===0);)n=n.PrevInAEL;if(n===null){var r=t.PolyTyp===e.PolyType.ptSubject?this.m_SubjFillType:this.m_ClipFillType;t.WindCnt=t.WindDelta===0?r===e.PolyFillType.pftNegative?-1:1:t.WindDelta,t.WindCnt2=0,n=this.m_ActiveEdges}else if(t.WindDelta===0&&this.m_ClipType!==e.ClipType.ctUnion)t.WindCnt=1,t.WindCnt2=n.WindCnt2,n=n.NextInAEL;else if(this.IsEvenOddFillType(t)){if(t.WindDelta===0){for(var i=!0,a=n.PrevInAEL;a!==null;)a.PolyTyp===n.PolyTyp&&a.WindDelta!==0&&(i=!i),a=a.PrevInAEL;t.WindCnt=+!i}else t.WindCnt=t.WindDelta;t.WindCnt2=n.WindCnt2,n=n.NextInAEL}else t.WindCnt=n.WindCnt*n.WindDelta<0?Math.abs(n.WindCnt)>1?n.WindDelta*t.WindDelta<0?n.WindCnt:n.WindCnt+t.WindDelta:t.WindDelta===0?1:t.WindDelta:t.WindDelta===0?n.WindCnt<0?n.WindCnt-1:n.WindCnt+1:n.WindDelta*t.WindDelta<0?n.WindCnt:n.WindCnt+t.WindDelta,t.WindCnt2=n.WindCnt2,n=n.NextInAEL;if(this.IsEvenOddAltFillType(t))for(;n!==t;)n.WindDelta!==0&&(t.WindCnt2=+(t.WindCnt2===0)),n=n.NextInAEL;else for(;n!==t;)t.WindCnt2+=n.WindDelta,n=n.NextInAEL},e.Clipper.prototype.AddEdgeToSEL=function(e){this.m_SortedEdges===null?(this.m_SortedEdges=e,e.PrevInSEL=null,e.NextInSEL=null):(e.NextInSEL=this.m_SortedEdges,e.PrevInSEL=null,this.m_SortedEdges.PrevInSEL=e,this.m_SortedEdges=e)},e.Clipper.prototype.PopEdgeFromSEL=function(e){if(e.v=this.m_SortedEdges,e.v===null)return!1;var t=e.v;return this.m_SortedEdges=e.v.NextInSEL,this.m_SortedEdges!==null&&(this.m_SortedEdges.PrevInSEL=null),t.NextInSEL=null,t.PrevInSEL=null,!0},e.Clipper.prototype.CopyAELToSEL=function(){var e=this.m_ActiveEdges;for(this.m_SortedEdges=e;e!==null;)e.PrevInSEL=e.PrevInAEL,e.NextInSEL=e.NextInAEL,e=e.NextInAEL},e.Clipper.prototype.SwapPositionsInSEL=function(e,t){if((e.NextInSEL!==null||e.PrevInSEL!==null)&&(t.NextInSEL!==null||t.PrevInSEL!==null)){if(e.NextInSEL===t){var n=t.NextInSEL;n!==null&&(n.PrevInSEL=e);var r=e.PrevInSEL;r!==null&&(r.NextInSEL=t),t.PrevInSEL=r,t.NextInSEL=e,e.PrevInSEL=t,e.NextInSEL=n}else if(t.NextInSEL===e){var n=e.NextInSEL;n!==null&&(n.PrevInSEL=t);var r=t.PrevInSEL;r!==null&&(r.NextInSEL=e),e.PrevInSEL=r,e.NextInSEL=t,t.PrevInSEL=e,t.NextInSEL=n}else{var n=e.NextInSEL,r=e.PrevInSEL;e.NextInSEL=t.NextInSEL,e.NextInSEL!==null&&(e.NextInSEL.PrevInSEL=e),e.PrevInSEL=t.PrevInSEL,e.PrevInSEL!==null&&(e.PrevInSEL.NextInSEL=e),t.NextInSEL=n,t.NextInSEL!==null&&(t.NextInSEL.PrevInSEL=t),t.PrevInSEL=r,t.PrevInSEL!==null&&(t.PrevInSEL.NextInSEL=t)}e.PrevInSEL===null?this.m_SortedEdges=e:t.PrevInSEL===null&&(this.m_SortedEdges=t)}},e.Clipper.prototype.AddLocalMaxPoly=function(e,t,n){this.AddOutPt(e,n),t.WindDelta===0&&this.AddOutPt(t,n),e.OutIdx===t.OutIdx?(e.OutIdx=-1,t.OutIdx=-1):e.OutIdx<t.OutIdx?this.AppendPolygon(e,t):this.AppendPolygon(t,e)},e.Clipper.prototype.AddLocalMinPoly=function(t,n,r){var i,a,o;if(e.ClipperBase.IsHorizontal(n)||t.Dx>n.Dx?(i=this.AddOutPt(t,r),n.OutIdx=t.OutIdx,t.Side=e.EdgeSide.esLeft,n.Side=e.EdgeSide.esRight,a=t,o=a.PrevInAEL===n?n.PrevInAEL:a.PrevInAEL):(i=this.AddOutPt(n,r),t.OutIdx=n.OutIdx,t.Side=e.EdgeSide.esRight,n.Side=e.EdgeSide.esLeft,a=n,o=a.PrevInAEL===t?t.PrevInAEL:a.PrevInAEL),o!==null&&o.OutIdx>=0&&o.Top.Y<r.Y&&a.Top.Y<r.Y){var s=e.Clipper.TopX(o,r.Y),c=e.Clipper.TopX(a,r.Y);if(s===c&&a.WindDelta!==0&&o.WindDelta!==0&&e.ClipperBase.SlopesEqual5(new e.IntPoint2(s,r.Y),o.Top,new e.IntPoint2(c,r.Y),a.Top,this.m_UseFullRange)){var l=this.AddOutPt(o,r);this.AddJoin(i,l,a.Top)}}return i},e.Clipper.prototype.AddOutPt=function(t,n){if(t.OutIdx<0){var r=this.CreateOutRec();r.IsOpen=t.WindDelta===0;var i=new e.OutPt;return r.Pts=i,i.Idx=r.Idx,i.Pt.X=n.X,i.Pt.Y=n.Y,e.use_xyz&&(i.Pt.Z=n.Z),i.Next=i,i.Prev=i,r.IsOpen||this.SetHoleState(t,r),t.OutIdx=r.Idx,i}var r=this.m_PolyOuts[t.OutIdx],a=r.Pts,o=t.Side===e.EdgeSide.esLeft;if(o&&e.IntPoint.op_Equality(n,a.Pt))return a;if(!o&&e.IntPoint.op_Equality(n,a.Prev.Pt))return a.Prev;var i=new e.OutPt;return i.Idx=r.Idx,i.Pt.X=n.X,i.Pt.Y=n.Y,e.use_xyz&&(i.Pt.Z=n.Z),i.Next=a,i.Prev=a.Prev,i.Prev.Next=i,a.Prev=i,o&&(r.Pts=i),i},e.Clipper.prototype.GetLastOutPt=function(t){var n=this.m_PolyOuts[t.OutIdx];return t.Side===e.EdgeSide.esLeft?n.Pts:n.Pts.Prev},e.Clipper.prototype.SwapPoints=function(t,n){var r=new e.IntPoint1(t.Value);t.Value.X=n.Value.X,t.Value.Y=n.Value.Y,e.use_xyz&&(t.Value.Z=n.Value.Z),n.Value.X=r.X,n.Value.Y=r.Y,e.use_xyz&&(n.Value.Z=r.Z)},e.Clipper.prototype.HorzSegmentsOverlap=function(e,t,n,r){var i;return e>t&&(i=e,e=t,t=i),n>r&&(i=n,n=r,r=i),e<r&&n<t},e.Clipper.prototype.SetHoleState=function(e,t){for(var n=e.PrevInAEL,r=null;n!==null;)n.OutIdx>=0&&n.WindDelta!==0&&(r===null?r=n:r.OutIdx===n.OutIdx&&(r=null)),n=n.PrevInAEL;r===null?(t.FirstLeft=null,t.IsHole=!1):(t.FirstLeft=this.m_PolyOuts[r.OutIdx],t.IsHole=!t.FirstLeft.IsHole)},e.Clipper.prototype.GetDx=function(t,n){return t.Y===n.Y?e.ClipperBase.horizontal:(n.X-t.X)/(n.Y-t.Y)},e.Clipper.prototype.FirstIsBottomPt=function(t,n){for(var r=t.Prev;e.IntPoint.op_Equality(r.Pt,t.Pt)&&r!==t;)r=r.Prev;var i=Math.abs(this.GetDx(t.Pt,r.Pt));for(r=t.Next;e.IntPoint.op_Equality(r.Pt,t.Pt)&&r!==t;)r=r.Next;var a=Math.abs(this.GetDx(t.Pt,r.Pt));for(r=n.Prev;e.IntPoint.op_Equality(r.Pt,n.Pt)&&r!==n;)r=r.Prev;var o=Math.abs(this.GetDx(n.Pt,r.Pt));for(r=n.Next;e.IntPoint.op_Equality(r.Pt,n.Pt)&&r!==n;)r=r.Next;var s=Math.abs(this.GetDx(n.Pt,r.Pt));return Math.max(i,a)===Math.max(o,s)&&Math.min(i,a)===Math.min(o,s)?this.Area(t)>0:i>=o&&i>=s||a>=o&&a>=s},e.Clipper.prototype.GetBottomPt=function(t){for(var n=null,r=t.Next;r!==t;)r.Pt.Y>t.Pt.Y?(t=r,n=null):r.Pt.Y===t.Pt.Y&&r.Pt.X<=t.Pt.X&&(r.Pt.X<t.Pt.X?(n=null,t=r):r.Next!==t&&r.Prev!==t&&(n=r)),r=r.Next;if(n!==null)for(;n!==r;)for(this.FirstIsBottomPt(r,n)||(t=n),n=n.Next;e.IntPoint.op_Inequality(n.Pt,t.Pt);)n=n.Next;return t},e.Clipper.prototype.GetLowermostRec=function(e,t){e.BottomPt===null&&(e.BottomPt=this.GetBottomPt(e.Pts)),t.BottomPt===null&&(t.BottomPt=this.GetBottomPt(t.Pts));var n=e.BottomPt,r=t.BottomPt;return n.Pt.Y>r.Pt.Y?e:n.Pt.Y<r.Pt.Y?t:n.Pt.X<r.Pt.X?e:n.Pt.X>r.Pt.X||n.Next===n?t:r.Next===r||this.FirstIsBottomPt(n,r)?e:t},e.Clipper.prototype.OutRec1RightOfOutRec2=function(e,t){do if(e=e.FirstLeft,e===t)return!0;while(e!==null);return!1},e.Clipper.prototype.GetOutRec=function(e){for(var t=this.m_PolyOuts[e];t!==this.m_PolyOuts[t.Idx];)t=this.m_PolyOuts[t.Idx];return t},e.Clipper.prototype.AppendPolygon=function(t,n){var r=this.m_PolyOuts[t.OutIdx],i=this.m_PolyOuts[n.OutIdx],a=this.OutRec1RightOfOutRec2(r,i)?i:this.OutRec1RightOfOutRec2(i,r)?r:this.GetLowermostRec(r,i),o=r.Pts,s=o.Prev,c=i.Pts,l=c.Prev;t.Side===e.EdgeSide.esLeft?n.Side===e.EdgeSide.esLeft?(this.ReversePolyPtLinks(c),c.Next=o,o.Prev=c,s.Next=l,l.Prev=s,r.Pts=l):(l.Next=o,o.Prev=l,c.Prev=s,s.Next=c,r.Pts=c):n.Side===e.EdgeSide.esRight?(this.ReversePolyPtLinks(c),s.Next=l,l.Prev=s,c.Next=o,o.Prev=c):(s.Next=c,c.Prev=s,o.Prev=l,l.Next=o),r.BottomPt=null,a===i&&(i.FirstLeft!==r&&(r.FirstLeft=i.FirstLeft),r.IsHole=i.IsHole),i.Pts=null,i.BottomPt=null,i.FirstLeft=r;var u=t.OutIdx,d=n.OutIdx;t.OutIdx=-1,n.OutIdx=-1;for(var f=this.m_ActiveEdges;f!==null;){if(f.OutIdx===d){f.OutIdx=u,f.Side=t.Side;break}f=f.NextInAEL}i.Idx=r.Idx},e.Clipper.prototype.ReversePolyPtLinks=function(e){if(e!==null){var t=e,n;do n=t.Next,t.Next=t.Prev,t.Prev=n,t=n;while(t!==e)}},e.Clipper.SwapSides=function(e,t){var n=e.Side;e.Side=t.Side,t.Side=n},e.Clipper.SwapPolyIndexes=function(e,t){var n=e.OutIdx;e.OutIdx=t.OutIdx,t.OutIdx=n},e.Clipper.prototype.IntersectEdges=function(t,n,r){var i=t.OutIdx>=0,a=n.OutIdx>=0;if(e.use_xyz&&this.SetZ(r,t,n),e.use_lines&&(t.WindDelta===0||n.WindDelta===0)){if(t.WindDelta===0&&n.WindDelta===0)return;t.PolyTyp===n.PolyTyp&&t.WindDelta!==n.WindDelta&&this.m_ClipType===e.ClipType.ctUnion?t.WindDelta===0?a&&(this.AddOutPt(t,r),i&&(t.OutIdx=-1)):i&&(this.AddOutPt(n,r),a&&(n.OutIdx=-1)):t.PolyTyp!==n.PolyTyp&&(t.WindDelta===0&&Math.abs(n.WindCnt)===1&&(this.m_ClipType!==e.ClipType.ctUnion||n.WindCnt2===0)?(this.AddOutPt(t,r),i&&(t.OutIdx=-1)):n.WindDelta===0&&Math.abs(t.WindCnt)===1&&(this.m_ClipType!==e.ClipType.ctUnion||t.WindCnt2===0)&&(this.AddOutPt(n,r),a&&(n.OutIdx=-1)))}else{if(t.PolyTyp===n.PolyTyp){if(this.IsEvenOddFillType(t)){var o=t.WindCnt;t.WindCnt=n.WindCnt,n.WindCnt=o}else t.WindCnt+n.WindDelta===0?t.WindCnt=-t.WindCnt:t.WindCnt+=n.WindDelta,n.WindCnt-t.WindDelta===0?n.WindCnt=-n.WindCnt:n.WindCnt-=t.WindDelta}else this.IsEvenOddFillType(n)?t.WindCnt2=+(t.WindCnt2===0):t.WindCnt2+=n.WindDelta,this.IsEvenOddFillType(t)?n.WindCnt2=+(n.WindCnt2===0):n.WindCnt2-=t.WindDelta;var s,c,l,u;t.PolyTyp===e.PolyType.ptSubject?(s=this.m_SubjFillType,l=this.m_ClipFillType):(s=this.m_ClipFillType,l=this.m_SubjFillType),n.PolyTyp===e.PolyType.ptSubject?(c=this.m_SubjFillType,u=this.m_ClipFillType):(c=this.m_ClipFillType,u=this.m_SubjFillType);var d,f;switch(s){case e.PolyFillType.pftPositive:d=t.WindCnt;break;case e.PolyFillType.pftNegative:d=-t.WindCnt;break;default:d=Math.abs(t.WindCnt)}switch(c){case e.PolyFillType.pftPositive:f=n.WindCnt;break;case e.PolyFillType.pftNegative:f=-n.WindCnt;break;default:f=Math.abs(n.WindCnt)}if(i&&a)d!==0&&d!==1||f!==0&&f!==1||t.PolyTyp!==n.PolyTyp&&this.m_ClipType!==e.ClipType.ctXor?this.AddLocalMaxPoly(t,n,r):(this.AddOutPt(t,r),this.AddOutPt(n,r),e.Clipper.SwapSides(t,n),e.Clipper.SwapPolyIndexes(t,n));else if(i)(f===0||f===1)&&(this.AddOutPt(t,r),e.Clipper.SwapSides(t,n),e.Clipper.SwapPolyIndexes(t,n));else if(a)(d===0||d===1)&&(this.AddOutPt(n,r),e.Clipper.SwapSides(t,n),e.Clipper.SwapPolyIndexes(t,n));else if((d===0||d===1)&&(f===0||f===1)){var p,m;switch(l){case e.PolyFillType.pftPositive:p=t.WindCnt2;break;case e.PolyFillType.pftNegative:p=-t.WindCnt2;break;default:p=Math.abs(t.WindCnt2)}switch(u){case e.PolyFillType.pftPositive:m=n.WindCnt2;break;case e.PolyFillType.pftNegative:m=-n.WindCnt2;break;default:m=Math.abs(n.WindCnt2)}if(t.PolyTyp!==n.PolyTyp)this.AddLocalMinPoly(t,n,r);else if(d===1&&f===1)switch(this.m_ClipType){case e.ClipType.ctIntersection:p>0&&m>0&&this.AddLocalMinPoly(t,n,r);break;case e.ClipType.ctUnion:p<=0&&m<=0&&this.AddLocalMinPoly(t,n,r);break;case e.ClipType.ctDifference:(t.PolyTyp===e.PolyType.ptClip&&p>0&&m>0||t.PolyTyp===e.PolyType.ptSubject&&p<=0&&m<=0)&&this.AddLocalMinPoly(t,n,r);break;case e.ClipType.ctXor:this.AddLocalMinPoly(t,n,r)}else e.Clipper.SwapSides(t,n)}}},e.Clipper.prototype.DeleteFromSEL=function(e){var t=e.PrevInSEL,n=e.NextInSEL;(t!==null||n!==null||e===this.m_SortedEdges)&&(t===null?this.m_SortedEdges=n:t.NextInSEL=n,n!==null&&(n.PrevInSEL=t),e.NextInSEL=null,e.PrevInSEL=null)},e.Clipper.prototype.ProcessHorizontals=function(){for(var e={};this.PopEdgeFromSEL(e);)this.ProcessHorizontal(e.v)},e.Clipper.prototype.GetHorzDirection=function(t,n){t.Bot.X<t.Top.X?(n.Left=t.Bot.X,n.Right=t.Top.X,n.Dir=e.Direction.dLeftToRight):(n.Left=t.Top.X,n.Right=t.Bot.X,n.Dir=e.Direction.dRightToLeft)},e.Clipper.prototype.ProcessHorizontal=function(t){var n={Dir:null,Left:null,Right:null};this.GetHorzDirection(t,n);for(var r=n.Dir,i=n.Left,a=n.Right,o=t.WindDelta===0,s=t,c=null;s.NextInLML!==null&&e.ClipperBase.IsHorizontal(s.NextInLML);)s=s.NextInLML;s.NextInLML===null&&(c=this.GetMaximaPair(s));var l=this.m_Maxima;if(l!==null){if(r===e.Direction.dLeftToRight){for(;l!==null&&l.X<=t.Bot.X;)l=l.Next;l!==null&&l.X>=s.Top.X&&(l=null)}else{for(;l.Next!==null&&l.Next.X<t.Bot.X;)l=l.Next;l.X<=s.Top.X&&(l=null)}}for(var u=null;;){for(var d=t===s,f=this.GetNextInAEL(t,r);f!==null;){if(l!==null){if(r===e.Direction.dLeftToRight)for(;l!==null&&l.X<f.Curr.X;)t.OutIdx>=0&&!o&&this.AddOutPt(t,new e.IntPoint2(l.X,t.Bot.Y)),l=l.Next;else for(;l!==null&&l.X>f.Curr.X;)t.OutIdx>=0&&!o&&this.AddOutPt(t,new e.IntPoint2(l.X,t.Bot.Y)),l=l.Prev}if(r===e.Direction.dLeftToRight&&f.Curr.X>a||r===e.Direction.dRightToLeft&&f.Curr.X<i||f.Curr.X===t.Top.X&&t.NextInLML!==null&&f.Dx<t.NextInLML.Dx)break;if(t.OutIdx>=0&&!o){e.use_xyz&&(r===e.Direction.dLeftToRight?this.SetZ(f.Curr,t,f):this.SetZ(f.Curr,f,t)),u=this.AddOutPt(t,f.Curr);for(var p=this.m_SortedEdges;p!==null;){if(p.OutIdx>=0&&this.HorzSegmentsOverlap(t.Bot.X,t.Top.X,p.Bot.X,p.Top.X)){var m=this.GetLastOutPt(p);this.AddJoin(m,u,p.Top)}p=p.NextInSEL}this.AddGhostJoin(u,t.Bot)}if(f===c&&d){t.OutIdx>=0&&this.AddLocalMaxPoly(t,c,t.Top),this.DeleteFromAEL(t),this.DeleteFromAEL(c);return}if(r===e.Direction.dLeftToRight){var h=new e.IntPoint2(f.Curr.X,t.Curr.Y);this.IntersectEdges(t,f,h)}else{var h=new e.IntPoint2(f.Curr.X,t.Curr.Y);this.IntersectEdges(f,t,h)}var g=this.GetNextInAEL(f,r);this.SwapPositionsInAEL(t,f),f=g}if(t.NextInLML===null||!e.ClipperBase.IsHorizontal(t.NextInLML))break;t=this.UpdateEdgeIntoAEL(t),t.OutIdx>=0&&this.AddOutPt(t,t.Bot),n={Dir:r,Left:i,Right:a},this.GetHorzDirection(t,n),r=n.Dir,i=n.Left,a=n.Right}if(t.OutIdx>=0&&u===null){u=this.GetLastOutPt(t);for(var p=this.m_SortedEdges;p!==null;){if(p.OutIdx>=0&&this.HorzSegmentsOverlap(t.Bot.X,t.Top.X,p.Bot.X,p.Top.X)){var m=this.GetLastOutPt(p);this.AddJoin(m,u,p.Top)}p=p.NextInSEL}this.AddGhostJoin(u,t.Top)}if(t.NextInLML!==null){if(t.OutIdx>=0){if(u=this.AddOutPt(t,t.Top),t=this.UpdateEdgeIntoAEL(t),t.WindDelta===0)return;var _=t.PrevInAEL,g=t.NextInAEL;if(_!==null&&_.Curr.X===t.Bot.X&&_.Curr.Y===t.Bot.Y&&_.WindDelta===0&&_.OutIdx>=0&&_.Curr.Y>_.Top.Y&&e.ClipperBase.SlopesEqual3(t,_,this.m_UseFullRange)){var m=this.AddOutPt(_,t.Bot);this.AddJoin(u,m,t.Top)}else if(g!==null&&g.Curr.X===t.Bot.X&&g.Curr.Y===t.Bot.Y&&g.WindDelta!==0&&g.OutIdx>=0&&g.Curr.Y>g.Top.Y&&e.ClipperBase.SlopesEqual3(t,g,this.m_UseFullRange)){var m=this.AddOutPt(g,t.Bot);this.AddJoin(u,m,t.Top)}}else t=this.UpdateEdgeIntoAEL(t)}else t.OutIdx>=0&&this.AddOutPt(t,t.Top),this.DeleteFromAEL(t)},e.Clipper.prototype.GetNextInAEL=function(t,n){return n===e.Direction.dLeftToRight?t.NextInAEL:t.PrevInAEL},e.Clipper.prototype.IsMinima=function(e){return e!==null&&e.Prev.NextInLML!==e&&e.Next.NextInLML!==e},e.Clipper.prototype.IsMaxima=function(e,t){return e!==null&&e.Top.Y===t&&e.NextInLML===null},e.Clipper.prototype.IsIntermediate=function(e,t){return e.Top.Y===t&&e.NextInLML!==null},e.Clipper.prototype.GetMaximaPair=function(t){return e.IntPoint.op_Equality(t.Next.Top,t.Top)&&t.Next.NextInLML===null?t.Next:e.IntPoint.op_Equality(t.Prev.Top,t.Top)&&t.Prev.NextInLML===null?t.Prev:null},e.Clipper.prototype.GetMaximaPairEx=function(t){var n=this.GetMaximaPair(t);return n===null||n.OutIdx===e.ClipperBase.Skip||n.NextInAEL===n.PrevInAEL&&!e.ClipperBase.IsHorizontal(n)?null:n},e.Clipper.prototype.ProcessIntersections=function(t){if(this.m_ActiveEdges===null)return!0;try{if(this.BuildIntersectList(t),this.m_IntersectList.length===0)return!0;if(this.m_IntersectList.length===1||this.FixupIntersectionOrder())this.ProcessIntersectList();else return!1}catch{this.m_SortedEdges=null,this.m_IntersectList.length=0,e.Error(`ProcessIntersections error`)}return this.m_SortedEdges=null,!0},e.Clipper.prototype.BuildIntersectList=function(t){if(this.m_ActiveEdges!==null){var n=this.m_ActiveEdges;for(this.m_SortedEdges=n;n!==null;)n.PrevInSEL=n.PrevInAEL,n.NextInSEL=n.NextInAEL,n.Curr.X=e.Clipper.TopX(n,t),n=n.NextInAEL;for(var r=!0;r&&this.m_SortedEdges!==null;){for(r=!1,n=this.m_SortedEdges;n.NextInSEL!==null;){var i=n.NextInSEL,a=new e.IntPoint0;if(n.Curr.X>i.Curr.X){this.IntersectPoint(n,i,a),a.Y<t&&(a=new e.IntPoint2(e.Clipper.TopX(n,t),t));var o=new e.IntersectNode;o.Edge1=n,o.Edge2=i,o.Pt.X=a.X,o.Pt.Y=a.Y,e.use_xyz&&(o.Pt.Z=a.Z),this.m_IntersectList.push(o),this.SwapPositionsInSEL(n,i),r=!0}else n=i}if(n.PrevInSEL!==null)n.PrevInSEL.NextInSEL=null;else break}this.m_SortedEdges=null}},e.Clipper.prototype.EdgesAdjacent=function(e){return e.Edge1.NextInSEL===e.Edge2||e.Edge1.PrevInSEL===e.Edge2},e.Clipper.IntersectNodeSort=function(e,t){return t.Pt.Y-e.Pt.Y},e.Clipper.prototype.FixupIntersectionOrder=function(){this.m_IntersectList.sort(this.m_IntersectNodeComparer),this.CopyAELToSEL();for(var e=this.m_IntersectList.length,t=0;t<e;t++){if(!this.EdgesAdjacent(this.m_IntersectList[t])){for(var n=t+1;n<e&&!this.EdgesAdjacent(this.m_IntersectList[n]);)n++;if(n===e)return!1;var r=this.m_IntersectList[t];this.m_IntersectList[t]=this.m_IntersectList[n],this.m_IntersectList[n]=r}this.SwapPositionsInSEL(this.m_IntersectList[t].Edge1,this.m_IntersectList[t].Edge2)}return!0},e.Clipper.prototype.ProcessIntersectList=function(){for(var e=0,t=this.m_IntersectList.length;e<t;e++){var n=this.m_IntersectList[e];this.IntersectEdges(n.Edge1,n.Edge2,n.Pt),this.SwapPositionsInAEL(n.Edge1,n.Edge2)}this.m_IntersectList.length=0};var Tt=function(e){return e<0?Math.ceil(e-.5):Math.round(e)},Et=function(e){return e<0?Math.ceil(e-.5):Math.floor(e+.5)},Dt=function(e){return e<0?-Math.round(Math.abs(e)):Math.round(e)},Ot=function(e){return e<0?(e-=.5,e<-2147483648?Math.ceil(e):e|0):(e+=.5,e>2147483647?Math.floor(e):e|0)};a.msie?e.Clipper.Round=Tt:a.chromium?e.Clipper.Round=Dt:a.safari?e.Clipper.Round=Ot:e.Clipper.Round=Et,e.Clipper.TopX=function(t,n){return n===t.Top.Y?t.Top.X:t.Bot.X+e.Clipper.Round(t.Dx*(n-t.Bot.Y))},e.Clipper.prototype.IntersectPoint=function(t,n,r){r.X=0,r.Y=0;var i,a;if(t.Dx===n.Dx)r.Y=t.Curr.Y,r.X=e.Clipper.TopX(t,r.Y);else{if(t.Delta.X===0)r.X=t.Bot.X,e.ClipperBase.IsHorizontal(n)?r.Y=n.Bot.Y:(a=n.Bot.Y-n.Bot.X/n.Dx,r.Y=e.Clipper.Round(r.X/n.Dx+a));else if(n.Delta.X===0)r.X=n.Bot.X,e.ClipperBase.IsHorizontal(t)?r.Y=t.Bot.Y:(i=t.Bot.Y-t.Bot.X/t.Dx,r.Y=e.Clipper.Round(r.X/t.Dx+i));else{i=t.Bot.X-t.Bot.Y*t.Dx,a=n.Bot.X-n.Bot.Y*n.Dx;var o=(a-i)/(t.Dx-n.Dx);r.Y=e.Clipper.Round(o),r.X=Math.abs(t.Dx)<Math.abs(n.Dx)?e.Clipper.Round(t.Dx*o+i):e.Clipper.Round(n.Dx*o+a)}if(r.Y<t.Top.Y||r.Y<n.Top.Y){if(t.Top.Y>n.Top.Y)return r.Y=t.Top.Y,r.X=e.Clipper.TopX(n,t.Top.Y),r.X<t.Top.X;r.Y=n.Top.Y,r.X=Math.abs(t.Dx)<Math.abs(n.Dx)?e.Clipper.TopX(t,r.Y):e.Clipper.TopX(n,r.Y)}r.Y>t.Curr.Y&&(r.Y=t.Curr.Y,r.X=Math.abs(t.Dx)>Math.abs(n.Dx)?e.Clipper.TopX(n,r.Y):e.Clipper.TopX(t,r.Y))}},e.Clipper.prototype.ProcessEdgesAtTopOfScanbeam=function(t){for(var n=this.m_ActiveEdges;n!==null;){var r=this.IsMaxima(n,t);if(r){var i=this.GetMaximaPairEx(n);r=i===null||!e.ClipperBase.IsHorizontal(i)}if(r){this.StrictlySimple&&this.InsertMaxima(n.Top.X);var a=n.PrevInAEL;this.DoMaxima(n),n=a===null?this.m_ActiveEdges:a.NextInAEL}else{if(this.IsIntermediate(n,t)&&e.ClipperBase.IsHorizontal(n.NextInLML)?(n=this.UpdateEdgeIntoAEL(n),n.OutIdx>=0&&this.AddOutPt(n,n.Bot),this.AddEdgeToSEL(n)):(n.Curr.X=e.Clipper.TopX(n,t),n.Curr.Y=t),e.use_xyz&&(n.Top.Y===t?n.Curr.Z=n.Top.Z:n.Bot.Y===t?n.Curr.Z=n.Bot.Z:n.Curr.Z=0),this.StrictlySimple){var a=n.PrevInAEL;if(n.OutIdx>=0&&n.WindDelta!==0&&a!==null&&a.OutIdx>=0&&a.Curr.X===n.Curr.X&&a.WindDelta!==0){var o=new e.IntPoint1(n.Curr);e.use_xyz&&this.SetZ(o,a,n);var s=this.AddOutPt(a,o),c=this.AddOutPt(n,o);this.AddJoin(s,c,o)}}n=n.NextInAEL}}for(this.ProcessHorizontals(),this.m_Maxima=null,n=this.m_ActiveEdges;n!==null;){if(this.IsIntermediate(n,t)){var s=null;n.OutIdx>=0&&(s=this.AddOutPt(n,n.Top)),n=this.UpdateEdgeIntoAEL(n);var a=n.PrevInAEL,l=n.NextInAEL;if(a!==null&&a.Curr.X===n.Bot.X&&a.Curr.Y===n.Bot.Y&&s!==null&&a.OutIdx>=0&&a.Curr.Y===a.Top.Y&&e.ClipperBase.SlopesEqual5(n.Curr,n.Top,a.Curr,a.Top,this.m_UseFullRange)&&n.WindDelta!==0&&a.WindDelta!==0){var c=this.AddOutPt(ePrev2,n.Bot);this.AddJoin(s,c,n.Top)}else if(l!==null&&l.Curr.X===n.Bot.X&&l.Curr.Y===n.Bot.Y&&s!==null&&l.OutIdx>=0&&l.Curr.Y===l.Top.Y&&e.ClipperBase.SlopesEqual5(n.Curr,n.Top,l.Curr,l.Top,this.m_UseFullRange)&&n.WindDelta!==0&&l.WindDelta!==0){var c=this.AddOutPt(l,n.Bot);this.AddJoin(s,c,n.Top)}}n=n.NextInAEL}},e.Clipper.prototype.DoMaxima=function(t){var n=this.GetMaximaPairEx(t);if(n===null)t.OutIdx>=0&&this.AddOutPt(t,t.Top),this.DeleteFromAEL(t);else{for(var r=t.NextInAEL;r!==null&&r!==n;)this.IntersectEdges(t,r,t.Top),this.SwapPositionsInAEL(t,r),r=t.NextInAEL;t.OutIdx===-1&&n.OutIdx===-1?(this.DeleteFromAEL(t),this.DeleteFromAEL(n)):t.OutIdx>=0&&n.OutIdx>=0?(t.OutIdx>=0&&this.AddLocalMaxPoly(t,n,t.Top),this.DeleteFromAEL(t),this.DeleteFromAEL(n)):e.use_lines&&t.WindDelta===0?(t.OutIdx>=0&&(this.AddOutPt(t,t.Top),t.OutIdx=e.ClipperBase.Unassigned),this.DeleteFromAEL(t),n.OutIdx>=0&&(this.AddOutPt(n,t.Top),n.OutIdx=e.ClipperBase.Unassigned),this.DeleteFromAEL(n)):e.Error(`DoMaxima error`)}},e.Clipper.ReversePaths=function(e){for(var t=0,n=e.length;t<n;t++)e[t].reverse()},e.Clipper.Orientation=function(t){return e.Clipper.Area(t)>=0},e.Clipper.prototype.PointCount=function(e){if(e===null)return 0;var t=0,n=e;do t++,n=n.Next;while(n!==e);return t},e.Clipper.prototype.BuildResult=function(t){e.Clear(t);for(var n=0,r=this.m_PolyOuts.length;n<r;n++){var i=this.m_PolyOuts[n];if(i.Pts!==null){var a=i.Pts.Prev,o=this.PointCount(a);if(!(o<2)){for(var s=Array(o),c=0;c<o;c++)s[c]=a.Pt,a=a.Prev;t.push(s)}}}},e.Clipper.prototype.BuildResult2=function(t){t.Clear();for(var n=0,r=this.m_PolyOuts.length;n<r;n++){var i=this.m_PolyOuts[n],a=this.PointCount(i.Pts);if(!(i.IsOpen&&a<2||!i.IsOpen&&a<3)){this.FixHoleLinkage(i);var o=new e.PolyNode;t.m_AllPolys.push(o),i.PolyNode=o,o.m_polygon.length=a;for(var s=i.Pts.Prev,c=0;c<a;c++)o.m_polygon[c]=s.Pt,s=s.Prev}}for(var n=0,r=this.m_PolyOuts.length;n<r;n++){var i=this.m_PolyOuts[n];i.PolyNode!==null&&(i.IsOpen?(i.PolyNode.IsOpen=!0,t.AddChild(i.PolyNode)):i.FirstLeft!==null&&i.FirstLeft.PolyNode!==null?i.FirstLeft.PolyNode.AddChild(i.PolyNode):t.AddChild(i.PolyNode))}},e.Clipper.prototype.FixupOutPolyline=function(t){for(var n=t.Pts,r=n.Prev;n!==r;)if(n=n.Next,e.IntPoint.op_Equality(n.Pt,n.Prev.Pt)){n===r&&(r=n.Prev);var i=n.Prev;i.Next=n.Next,n.Next.Prev=i,n=i}n===n.Prev&&(t.Pts=null)},e.Clipper.prototype.FixupOutPolygon=function(t){var n=null;t.BottomPt=null;for(var r=t.Pts,i=this.PreserveCollinear||this.StrictlySimple;;){if(r.Prev===r||r.Prev===r.Next){t.Pts=null;return}if(e.IntPoint.op_Equality(r.Pt,r.Next.Pt)||e.IntPoint.op_Equality(r.Pt,r.Prev.Pt)||e.ClipperBase.SlopesEqual4(r.Prev.Pt,r.Pt,r.Next.Pt,this.m_UseFullRange)&&(!i||!this.Pt2IsBetweenPt1AndPt3(r.Prev.Pt,r.Pt,r.Next.Pt)))n=null,r.Prev.Next=r.Next,r.Next.Prev=r.Prev,r=r.Prev;else if(r===n)break;else n===null&&(n=r),r=r.Next}t.Pts=r},e.Clipper.prototype.DupOutPt=function(t,n){var r=new e.OutPt;return r.Pt.X=t.Pt.X,r.Pt.Y=t.Pt.Y,e.use_xyz&&(r.Pt.Z=t.Pt.Z),r.Idx=t.Idx,n?(r.Next=t.Next,r.Prev=t,t.Next.Prev=r,t.Next=r):(r.Prev=t.Prev,r.Next=t,t.Prev.Next=r,t.Prev=r),r},e.Clipper.prototype.GetOverlap=function(e,t,n,r,i){return e<t?n<r?(i.Left=Math.max(e,n),i.Right=Math.min(t,r)):(i.Left=Math.max(e,r),i.Right=Math.min(t,n)):n<r?(i.Left=Math.max(t,n),i.Right=Math.min(e,r)):(i.Left=Math.max(t,r),i.Right=Math.min(e,n)),i.Left<i.Right},e.Clipper.prototype.JoinHorz=function(t,n,r,i,a,o){var s=t.Pt.X>n.Pt.X?e.Direction.dRightToLeft:e.Direction.dLeftToRight,c=r.Pt.X>i.Pt.X?e.Direction.dRightToLeft:e.Direction.dLeftToRight;if(s===c)return!1;if(s===e.Direction.dLeftToRight){for(;t.Next.Pt.X<=a.X&&t.Next.Pt.X>=t.Pt.X&&t.Next.Pt.Y===a.Y;)t=t.Next;o&&t.Pt.X!==a.X&&(t=t.Next),n=this.DupOutPt(t,!o),e.IntPoint.op_Inequality(n.Pt,a)&&(t=n,t.Pt.X=a.X,t.Pt.Y=a.Y,e.use_xyz&&(t.Pt.Z=a.Z),n=this.DupOutPt(t,!o))}else{for(;t.Next.Pt.X>=a.X&&t.Next.Pt.X<=t.Pt.X&&t.Next.Pt.Y===a.Y;)t=t.Next;!o&&t.Pt.X!==a.X&&(t=t.Next),n=this.DupOutPt(t,o),e.IntPoint.op_Inequality(n.Pt,a)&&(t=n,t.Pt.X=a.X,t.Pt.Y=a.Y,e.use_xyz&&(t.Pt.Z=a.Z),n=this.DupOutPt(t,o))}if(c===e.Direction.dLeftToRight){for(;r.Next.Pt.X<=a.X&&r.Next.Pt.X>=r.Pt.X&&r.Next.Pt.Y===a.Y;)r=r.Next;o&&r.Pt.X!==a.X&&(r=r.Next),i=this.DupOutPt(r,!o),e.IntPoint.op_Inequality(i.Pt,a)&&(r=i,r.Pt.X=a.X,r.Pt.Y=a.Y,e.use_xyz&&(r.Pt.Z=a.Z),i=this.DupOutPt(r,!o))}else{for(;r.Next.Pt.X>=a.X&&r.Next.Pt.X<=r.Pt.X&&r.Next.Pt.Y===a.Y;)r=r.Next;!o&&r.Pt.X!==a.X&&(r=r.Next),i=this.DupOutPt(r,o),e.IntPoint.op_Inequality(i.Pt,a)&&(r=i,r.Pt.X=a.X,r.Pt.Y=a.Y,e.use_xyz&&(r.Pt.Z=a.Z),i=this.DupOutPt(r,o))}return s===e.Direction.dLeftToRight===o?(t.Prev=r,r.Next=t,n.Next=i,i.Prev=n):(t.Next=r,r.Prev=t,n.Prev=i,i.Next=n),!0},e.Clipper.prototype.JoinPoints=function(t,n,r){var i=t.OutPt1,a=new e.OutPt,o=t.OutPt2,s=new e.OutPt,c=t.OutPt1.Pt.Y===t.OffPt.Y;if(c&&e.IntPoint.op_Equality(t.OffPt,t.OutPt1.Pt)&&e.IntPoint.op_Equality(t.OffPt,t.OutPt2.Pt)){if(n!==r)return!1;for(a=t.OutPt1.Next;a!==i&&e.IntPoint.op_Equality(a.Pt,t.OffPt);)a=a.Next;var l=a.Pt.Y>t.OffPt.Y;for(s=t.OutPt2.Next;s!==o&&e.IntPoint.op_Equality(s.Pt,t.OffPt);)s=s.Next;return l===s.Pt.Y>t.OffPt.Y?!1:l?(a=this.DupOutPt(i,!1),s=this.DupOutPt(o,!0),i.Prev=o,o.Next=i,a.Next=s,s.Prev=a,t.OutPt1=i,t.OutPt2=a,!0):(a=this.DupOutPt(i,!0),s=this.DupOutPt(o,!1),i.Next=o,o.Prev=i,a.Prev=s,s.Next=a,t.OutPt1=i,t.OutPt2=a,!0)}if(c){for(a=i;i.Prev.Pt.Y===i.Pt.Y&&i.Prev!==a&&i.Prev!==o;)i=i.Prev;for(;a.Next.Pt.Y===a.Pt.Y&&a.Next!==i&&a.Next!==o;)a=a.Next;if(a.Next===i||a.Next===o)return!1;for(s=o;o.Prev.Pt.Y===o.Pt.Y&&o.Prev!==s&&o.Prev!==a;)o=o.Prev;for(;s.Next.Pt.Y===s.Pt.Y&&s.Next!==o&&s.Next!==i;)s=s.Next;if(s.Next===o||s.Next===i)return!1;var u={Left:null,Right:null};if(!this.GetOverlap(i.Pt.X,a.Pt.X,o.Pt.X,s.Pt.X,u))return!1;var d=u.Left,f=u.Right,p=new e.IntPoint0,m;return i.Pt.X>=d&&i.Pt.X<=f?(p.X=i.Pt.X,p.Y=i.Pt.Y,e.use_xyz&&(p.Z=i.Pt.Z),m=i.Pt.X>a.Pt.X):o.Pt.X>=d&&o.Pt.X<=f?(p.X=o.Pt.X,p.Y=o.Pt.Y,e.use_xyz&&(p.Z=o.Pt.Z),m=o.Pt.X>s.Pt.X):a.Pt.X>=d&&a.Pt.X<=f?(p.X=a.Pt.X,p.Y=a.Pt.Y,e.use_xyz&&(p.Z=a.Pt.Z),m=a.Pt.X>i.Pt.X):(p.X=s.Pt.X,p.Y=s.Pt.Y,e.use_xyz&&(p.Z=s.Pt.Z),m=s.Pt.X>o.Pt.X),t.OutPt1=i,t.OutPt2=o,this.JoinHorz(i,a,o,s,p,m)}for(a=i.Next;e.IntPoint.op_Equality(a.Pt,i.Pt)&&a!==i;)a=a.Next;var h=a.Pt.Y>i.Pt.Y||!e.ClipperBase.SlopesEqual4(i.Pt,a.Pt,t.OffPt,this.m_UseFullRange);if(h){for(a=i.Prev;e.IntPoint.op_Equality(a.Pt,i.Pt)&&a!==i;)a=a.Prev;if(a.Pt.Y>i.Pt.Y||!e.ClipperBase.SlopesEqual4(i.Pt,a.Pt,t.OffPt,this.m_UseFullRange))return!1}for(s=o.Next;e.IntPoint.op_Equality(s.Pt,o.Pt)&&s!==o;)s=s.Next;var g=s.Pt.Y>o.Pt.Y||!e.ClipperBase.SlopesEqual4(o.Pt,s.Pt,t.OffPt,this.m_UseFullRange);if(g){for(s=o.Prev;e.IntPoint.op_Equality(s.Pt,o.Pt)&&s!==o;)s=s.Prev;if(s.Pt.Y>o.Pt.Y||!e.ClipperBase.SlopesEqual4(o.Pt,s.Pt,t.OffPt,this.m_UseFullRange))return!1}return a===i||s===o||a===s||n===r&&h===g?!1:h?(a=this.DupOutPt(i,!1),s=this.DupOutPt(o,!0),i.Prev=o,o.Next=i,a.Next=s,s.Prev=a,t.OutPt1=i,t.OutPt2=a,!0):(a=this.DupOutPt(i,!0),s=this.DupOutPt(o,!1),i.Next=o,o.Prev=i,a.Prev=s,s.Next=a,t.OutPt1=i,t.OutPt2=a,!0)},e.Clipper.GetBounds=function(t){for(var n=0,r=t.length;n<r&&t[n].length===0;)n++;if(n===r)return new e.IntRect(0,0,0,0);var i=new e.IntRect;for(i.left=t[n][0].X,i.right=i.left,i.top=t[n][0].Y,i.bottom=i.top;n<r;n++)for(var a=0,o=t[n].length;a<o;a++)t[n][a].X<i.left?i.left=t[n][a].X:t[n][a].X>i.right&&(i.right=t[n][a].X),t[n][a].Y<i.top?i.top=t[n][a].Y:t[n][a].Y>i.bottom&&(i.bottom=t[n][a].Y);return i},e.Clipper.prototype.GetBounds2=function(t){var n=t,r=new e.IntRect;for(r.left=t.Pt.X,r.right=t.Pt.X,r.top=t.Pt.Y,r.bottom=t.Pt.Y,t=t.Next;t!==n;)t.Pt.X<r.left&&(r.left=t.Pt.X),t.Pt.X>r.right&&(r.right=t.Pt.X),t.Pt.Y<r.top&&(r.top=t.Pt.Y),t.Pt.Y>r.bottom&&(r.bottom=t.Pt.Y),t=t.Next;return r},e.Clipper.PointInPolygon=function(e,t){var n=0,r=t.length;if(r<3)return 0;for(var i=t[0],a=1;a<=r;++a){var o=a===r?t[0]:t[a];if(o.Y===e.Y&&(o.X===e.X||i.Y===e.Y&&o.X>e.X==i.X<e.X))return-1;if(i.Y<e.Y!=o.Y<e.Y){if(i.X>=e.X){if(o.X>e.X)n=1-n;else{var s=(i.X-e.X)*(o.Y-e.Y)-(o.X-e.X)*(i.Y-e.Y);if(s===0)return-1;s>0==o.Y>i.Y&&(n=1-n)}}else if(o.X>e.X){var s=(i.X-e.X)*(o.Y-e.Y)-(o.X-e.X)*(i.Y-e.Y);if(s===0)return-1;s>0==o.Y>i.Y&&(n=1-n)}}i=o}return n},e.Clipper.prototype.PointInPolygon=function(e,t){var n=0,r=t,i=e.X,a=e.Y,o=t.Pt.X,s=t.Pt.Y;do{t=t.Next;var c=t.Pt.X,l=t.Pt.Y;if(l===a&&(c===i||s===a&&c>i==o<i))return-1;if(s<a!=l<a){if(o>=i){if(c>i)n=1-n;else{var u=(o-i)*(l-a)-(c-i)*(s-a);if(u===0)return-1;u>0==l>s&&(n=1-n)}}else if(c>i){var u=(o-i)*(l-a)-(c-i)*(s-a);if(u===0)return-1;u>0==l>s&&(n=1-n)}}o=c,s=l}while(r!==t);return n},e.Clipper.prototype.Poly2ContainsPoly1=function(e,t){var n=e;do{var r=this.PointInPolygon(n.Pt,t);if(r>=0)return r>0;n=n.Next}while(n!==e);return!0},e.Clipper.prototype.FixupFirstLefts1=function(t,n){for(var r,i,a=0,o=this.m_PolyOuts.length;a<o;a++)r=this.m_PolyOuts[a],i=e.Clipper.ParseFirstLeft(r.FirstLeft),r.Pts!==null&&i===t&&this.Poly2ContainsPoly1(r.Pts,n.Pts)&&(r.FirstLeft=n)},e.Clipper.prototype.FixupFirstLefts2=function(t,n){for(var r=n.FirstLeft,i,a,o=0,s=this.m_PolyOuts.length;o<s;o++)i=this.m_PolyOuts[o],i.Pts!==null&&i!==n&&i!==t&&(a=e.Clipper.ParseFirstLeft(i.FirstLeft),(a===r||a===t||a===n)&&(this.Poly2ContainsPoly1(i.Pts,t.Pts)?i.FirstLeft=t:this.Poly2ContainsPoly1(i.Pts,n.Pts)?i.FirstLeft=n:(i.FirstLeft===t||i.FirstLeft===n)&&(i.FirstLeft=r)))},e.Clipper.prototype.FixupFirstLefts3=function(t,n){for(var r,i,a=0,o=this.m_PolyOuts.length;a<o;a++)r=this.m_PolyOuts[a],i=e.Clipper.ParseFirstLeft(r.FirstLeft),r.Pts!==null&&i===t&&(r.FirstLeft=n)},e.Clipper.ParseFirstLeft=function(e){for(;e!==null&&e.Pts===null;)e=e.FirstLeft;return e},e.Clipper.prototype.JoinCommonEdges=function(){for(var e=0,t=this.m_Joins.length;e<t;e++){var n=this.m_Joins[e],r=this.GetOutRec(n.OutPt1.Idx),i=this.GetOutRec(n.OutPt2.Idx);if(r.Pts!==null&&i.Pts!==null&&!(r.IsOpen||i.IsOpen)){var a=r===i?r:this.OutRec1RightOfOutRec2(r,i)?i:this.OutRec1RightOfOutRec2(i,r)?r:this.GetLowermostRec(r,i);this.JoinPoints(n,r,i)&&(r===i?(r.Pts=n.OutPt1,r.BottomPt=null,i=this.CreateOutRec(),i.Pts=n.OutPt2,this.UpdateOutPtIdxs(i),this.Poly2ContainsPoly1(i.Pts,r.Pts)?(i.IsHole=!r.IsHole,i.FirstLeft=r,this.m_UsingPolyTree&&this.FixupFirstLefts2(i,r),(i.IsHole^this.ReverseSolution)==this.Area$1(i)>0&&this.ReversePolyPtLinks(i.Pts)):this.Poly2ContainsPoly1(r.Pts,i.Pts)?(i.IsHole=r.IsHole,r.IsHole=!i.IsHole,i.FirstLeft=r.FirstLeft,r.FirstLeft=i,this.m_UsingPolyTree&&this.FixupFirstLefts2(r,i),(r.IsHole^this.ReverseSolution)==this.Area$1(r)>0&&this.ReversePolyPtLinks(r.Pts)):(i.IsHole=r.IsHole,i.FirstLeft=r.FirstLeft,this.m_UsingPolyTree&&this.FixupFirstLefts1(r,i))):(i.Pts=null,i.BottomPt=null,i.Idx=r.Idx,r.IsHole=a.IsHole,a===i&&(r.FirstLeft=i.FirstLeft),i.FirstLeft=r,this.m_UsingPolyTree&&this.FixupFirstLefts3(i,r)))}}},e.Clipper.prototype.UpdateOutPtIdxs=function(e){var t=e.Pts;do t.Idx=e.Idx,t=t.Prev;while(t!==e.Pts)},e.Clipper.prototype.DoSimplePolygons=function(){for(var t=0;t<this.m_PolyOuts.length;){var n=this.m_PolyOuts[t++],r=n.Pts;if(!(r===null||n.IsOpen))do{for(var i=r.Next;i!==n.Pts;){if(e.IntPoint.op_Equality(r.Pt,i.Pt)&&i.Next!==r&&i.Prev!==r){var a=r.Prev,o=i.Prev;r.Prev=o,o.Next=r,i.Prev=a,a.Next=i,n.Pts=r;var s=this.CreateOutRec();s.Pts=i,this.UpdateOutPtIdxs(s),this.Poly2ContainsPoly1(s.Pts,n.Pts)?(s.IsHole=!n.IsHole,s.FirstLeft=n,this.m_UsingPolyTree&&this.FixupFirstLefts2(s,n)):this.Poly2ContainsPoly1(n.Pts,s.Pts)?(s.IsHole=n.IsHole,n.IsHole=!s.IsHole,s.FirstLeft=n.FirstLeft,n.FirstLeft=s,this.m_UsingPolyTree&&this.FixupFirstLefts2(n,s)):(s.IsHole=n.IsHole,s.FirstLeft=n.FirstLeft,this.m_UsingPolyTree&&this.FixupFirstLefts1(n,s)),i=r}i=i.Next}r=r.Next}while(r!==n.Pts)}},e.Clipper.Area=function(e){if(!Array.isArray(e))return 0;var t=e.length;if(t<3)return 0;for(var n=0,r=0,i=t-1;r<t;++r)n+=(e[i].X+e[r].X)*(e[i].Y-e[r].Y),i=r;return-n*.5},e.Clipper.prototype.Area=function(e){var t=e;if(e===null)return 0;var n=0;do n+=(e.Prev.Pt.X+e.Pt.X)*(e.Prev.Pt.Y-e.Pt.Y),e=e.Next;while(e!==t);return n*.5},e.Clipper.prototype.Area$1=function(e){return this.Area(e.Pts)},e.Clipper.SimplifyPolygon=function(t,n){var r=[],i=new e.Clipper(0);return i.StrictlySimple=!0,i.AddPath(t,e.PolyType.ptSubject,!0),i.Execute(e.ClipType.ctUnion,r,n,n),r},e.Clipper.SimplifyPolygons=function(t,n){n===void 0&&(n=e.PolyFillType.pftEvenOdd);var r=[],i=new e.Clipper(0);return i.StrictlySimple=!0,i.AddPaths(t,e.PolyType.ptSubject,!0),i.Execute(e.ClipType.ctUnion,r,n,n),r},e.Clipper.DistanceSqrd=function(e,t){var n=e.X-t.X,r=e.Y-t.Y;return n*n+r*r},e.Clipper.DistanceFromLineSqrd=function(e,t,n){var r=t.Y-n.Y,i=n.X-t.X,a=r*t.X+i*t.Y;return a=r*e.X+i*e.Y-a,a*a/(r*r+i*i)},e.Clipper.SlopesNearCollinear=function(t,n,r,i){return Math.abs(t.X-n.X)>Math.abs(t.Y-n.Y)?t.X>n.X==t.X<r.X?e.Clipper.DistanceFromLineSqrd(t,n,r)<i:n.X>t.X==n.X<r.X?e.Clipper.DistanceFromLineSqrd(n,t,r)<i:e.Clipper.DistanceFromLineSqrd(r,t,n)<i:t.Y>n.Y==t.Y<r.Y?e.Clipper.DistanceFromLineSqrd(t,n,r)<i:n.Y>t.Y==n.Y<r.Y?e.Clipper.DistanceFromLineSqrd(n,t,r)<i:e.Clipper.DistanceFromLineSqrd(r,t,n)<i},e.Clipper.PointsAreClose=function(e,t,n){var r=e.X-t.X,i=e.Y-t.Y;return r*r+i*i<=n},e.Clipper.ExcludeOp=function(e){var t=e.Prev;return t.Next=e.Next,e.Next.Prev=t,t.Idx=0,t},e.Clipper.CleanPolygon=function(t,n){n===void 0&&(n=1.415);var r=t.length;if(r===0)return[];for(var i=Array(r),a=0;a<r;++a)i[a]=new e.OutPt;for(var a=0;a<r;++a)i[a].Pt=t[a],i[a].Next=i[(a+1)%r],i[a].Next.Prev=i[a],i[a].Idx=0;for(var o=n*n,s=i[0];s.Idx===0&&s.Next!==s.Prev;)e.Clipper.PointsAreClose(s.Pt,s.Prev.Pt,o)?(s=e.Clipper.ExcludeOp(s),r--):e.Clipper.PointsAreClose(s.Prev.Pt,s.Next.Pt,o)?(e.Clipper.ExcludeOp(s.Next),s=e.Clipper.ExcludeOp(s),r-=2):e.Clipper.SlopesNearCollinear(s.Prev.Pt,s.Pt,s.Next.Pt,o)?(s=e.Clipper.ExcludeOp(s),r--):(s.Idx=1,s=s.Next);r<3&&(r=0);for(var c=Array(r),a=0;a<r;++a)c[a]=new e.IntPoint1(s.Pt),s=s.Next;return i=null,c},e.Clipper.CleanPolygons=function(t,n){for(var r=Array(t.length),i=0,a=t.length;i<a;i++)r[i]=e.Clipper.CleanPolygon(t[i],n);return r},e.Clipper.Minkowski=function(t,n,r,i){var a=+!!i,o=t.length,s=n.length,c=[];if(r)for(var l=0;l<s;l++){for(var u=Array(o),d=0,f=t.length,p=t[d];d<f;d++,p=t[d])u[d]=new e.IntPoint2(n[l].X+p.X,n[l].Y+p.Y);c.push(u)}else for(var l=0;l<s;l++){for(var u=Array(o),d=0,f=t.length,p=t[d];d<f;d++,p=t[d])u[d]=new e.IntPoint2(n[l].X-p.X,n[l].Y-p.Y);c.push(u)}for(var m=[],l=0;l<s-1+a;l++)for(var d=0;d<o;d++){var h=[];h.push(c[l%s][d%o]),h.push(c[(l+1)%s][d%o]),h.push(c[(l+1)%s][(d+1)%o]),h.push(c[l%s][(d+1)%o]),e.Clipper.Orientation(h)||h.reverse(),m.push(h)}return m},e.Clipper.MinkowskiSum=function(t,n,r){if(n[0]instanceof Array){for(var i=n,a=new e.Paths,o=new e.Clipper,s=0;s<i.length;++s){var c=e.Clipper.Minkowski(t,i[s],!0,r);if(o.AddPaths(c,e.PolyType.ptSubject,!0),r){var l=e.Clipper.TranslatePath(i[s],t[0]);o.AddPath(l,e.PolyType.ptClip,!0)}}return o.Execute(e.ClipType.ctUnion,a,e.PolyFillType.pftNonZero,e.PolyFillType.pftNonZero),a}var l=n,i=e.Clipper.Minkowski(t,l,!0,r),o=new e.Clipper;return o.AddPaths(i,e.PolyType.ptSubject,!0),o.Execute(e.ClipType.ctUnion,i,e.PolyFillType.pftNonZero,e.PolyFillType.pftNonZero),i},e.Clipper.TranslatePath=function(t,n){for(var r=new e.Path,i=0;i<t.length;i++)r.push(new e.IntPoint2(t[i].X+n.X,t[i].Y+n.Y));return r},e.Clipper.MinkowskiDiff=function(t,n){var r=e.Clipper.Minkowski(t,n,!1,!0),i=new e.Clipper;return i.AddPaths(r,e.PolyType.ptSubject,!0),i.Execute(e.ClipType.ctUnion,r,e.PolyFillType.pftNonZero,e.PolyFillType.pftNonZero),r},e.Clipper.PolyTreeToPaths=function(t){var n=[];return e.Clipper.AddPolyNodeToPaths(t,e.Clipper.NodeType.ntAny,n),n},e.Clipper.AddPolyNodeToPaths=function(t,n,r){var i=!0;switch(n){case e.Clipper.NodeType.ntOpen:return;case e.Clipper.NodeType.ntClosed:i=!t.IsOpen}t.m_polygon.length>0&&i&&r.push(t.m_polygon);for(var a=0,o=t.Childs(),s=o.length,c=o[a];a<s;a++,c=o[a])e.Clipper.AddPolyNodeToPaths(c,n,r)},e.Clipper.OpenPathsFromPolyTree=function(t){for(var n=new e.Paths,r=0,i=t.ChildCount();r<i;r++)t.Childs()[r].IsOpen&&n.push(t.Childs()[r].m_polygon);return n},e.Clipper.ClosedPathsFromPolyTree=function(t){var n=new e.Paths;return e.Clipper.AddPolyNodeToPaths(t,e.Clipper.NodeType.ntClosed,n),n},wt(e.Clipper,e.ClipperBase),e.Clipper.NodeType={ntAny:0,ntOpen:1,ntClosed:2},e.ClipperOffset=function(t,n){t===void 0&&(t=2),n===void 0&&(n=e.ClipperOffset.def_arc_tolerance),this.m_destPolys=new e.Paths,this.m_srcPoly=new e.Path,this.m_destPoly=new e.Path,this.m_normals=[],this.m_delta=0,this.m_sinA=0,this.m_sin=0,this.m_cos=0,this.m_miterLim=0,this.m_StepsPerRad=0,this.m_lowest=new e.IntPoint0,this.m_polyNodes=new e.PolyNode,this.MiterLimit=t,this.ArcTolerance=n,this.m_lowest.X=-1},e.ClipperOffset.two_pi=6.28318530717959,e.ClipperOffset.def_arc_tolerance=.25,e.ClipperOffset.prototype.Clear=function(){e.Clear(this.m_polyNodes.Childs()),this.m_lowest.X=-1},e.ClipperOffset.Round=e.Clipper.Round,e.ClipperOffset.prototype.AddPath=function(t,n,r){var i=t.length-1;if(!(i<0)){var a=new e.PolyNode;if(a.m_jointype=n,a.m_endtype=r,r===e.EndType.etClosedLine||r===e.EndType.etClosedPolygon)for(;i>0&&e.IntPoint.op_Equality(t[0],t[i]);)i--;a.m_polygon.push(t[0]);for(var o=0,s=0,c=1;c<=i;c++)e.IntPoint.op_Inequality(a.m_polygon[o],t[c])&&(o++,a.m_polygon.push(t[c]),(t[c].Y>a.m_polygon[s].Y||t[c].Y===a.m_polygon[s].Y&&t[c].X<a.m_polygon[s].X)&&(s=o));if(!(r===e.EndType.etClosedPolygon&&o<2)&&(this.m_polyNodes.AddChild(a),r===e.EndType.etClosedPolygon)){if(this.m_lowest.X<0)this.m_lowest=new e.IntPoint2(this.m_polyNodes.ChildCount()-1,s);else{var l=this.m_polyNodes.Childs()[this.m_lowest.X].m_polygon[this.m_lowest.Y];(a.m_polygon[s].Y>l.Y||a.m_polygon[s].Y===l.Y&&a.m_polygon[s].X<l.X)&&(this.m_lowest=new e.IntPoint2(this.m_polyNodes.ChildCount()-1,s))}}}},e.ClipperOffset.prototype.AddPaths=function(e,t,n){for(var r=0,i=e.length;r<i;r++)this.AddPath(e[r],t,n)},e.ClipperOffset.prototype.FixOrientations=function(){if(this.m_lowest.X>=0&&!e.Clipper.Orientation(this.m_polyNodes.Childs()[this.m_lowest.X].m_polygon))for(var t=0;t<this.m_polyNodes.ChildCount();t++){var n=this.m_polyNodes.Childs()[t];(n.m_endtype===e.EndType.etClosedPolygon||n.m_endtype===e.EndType.etClosedLine&&e.Clipper.Orientation(n.m_polygon))&&n.m_polygon.reverse()}else for(var t=0;t<this.m_polyNodes.ChildCount();t++){var n=this.m_polyNodes.Childs()[t];n.m_endtype===e.EndType.etClosedLine&&!e.Clipper.Orientation(n.m_polygon)&&n.m_polygon.reverse()}},e.ClipperOffset.GetUnitNormal=function(t,n){var r=n.X-t.X,i=n.Y-t.Y;if(r===0&&i===0)return new e.DoublePoint2(0,0);var a=1/Math.sqrt(r*r+i*i);return r*=a,i*=a,new e.DoublePoint2(i,-r)},e.ClipperOffset.prototype.DoOffset=function(t){if(this.m_destPolys=[],this.m_delta=t,e.ClipperBase.near_zero(t))for(var n=0;n<this.m_polyNodes.ChildCount();n++){var r=this.m_polyNodes.Childs()[n];r.m_endtype===e.EndType.etClosedPolygon&&this.m_destPolys.push(r.m_polygon)}else{this.m_miterLim=this.MiterLimit>2?2/(this.MiterLimit*this.MiterLimit):.5;var i=this.ArcTolerance<=0?e.ClipperOffset.def_arc_tolerance:this.ArcTolerance>Math.abs(t)*e.ClipperOffset.def_arc_tolerance?Math.abs(t)*e.ClipperOffset.def_arc_tolerance:this.ArcTolerance,a=3.14159265358979/Math.acos(1-i/Math.abs(t));this.m_sin=Math.sin(e.ClipperOffset.two_pi/a),this.m_cos=Math.cos(e.ClipperOffset.two_pi/a),this.m_StepsPerRad=a/e.ClipperOffset.two_pi,t<0&&(this.m_sin=-this.m_sin);for(var n=0;n<this.m_polyNodes.ChildCount();n++){var r=this.m_polyNodes.Childs()[n];this.m_srcPoly=r.m_polygon;var o=this.m_srcPoly.length;if(!(o===0||t<=0&&(o<3||r.m_endtype!==e.EndType.etClosedPolygon))){if(this.m_destPoly=[],o===1){if(r.m_jointype===e.JoinType.jtRound)for(var s=1,c=0,l=1;l<=a;l++){this.m_destPoly.push(new e.IntPoint2(e.ClipperOffset.Round(this.m_srcPoly[0].X+s*t),e.ClipperOffset.Round(this.m_srcPoly[0].Y+c*t)));var u=s;s=s*this.m_cos-this.m_sin*c,c=u*this.m_sin+c*this.m_cos}else for(var s=-1,c=-1,l=0;l<4;++l)this.m_destPoly.push(new e.IntPoint2(e.ClipperOffset.Round(this.m_srcPoly[0].X+s*t),e.ClipperOffset.Round(this.m_srcPoly[0].Y+c*t))),s<0?s=1:c<0?c=1:s=-1;this.m_destPolys.push(this.m_destPoly)}else{this.m_normals.length=0;for(var l=0;l<o-1;l++)this.m_normals.push(e.ClipperOffset.GetUnitNormal(this.m_srcPoly[l],this.m_srcPoly[l+1]));if(r.m_endtype===e.EndType.etClosedLine||r.m_endtype===e.EndType.etClosedPolygon?this.m_normals.push(e.ClipperOffset.GetUnitNormal(this.m_srcPoly[o-1],this.m_srcPoly[0])):this.m_normals.push(new e.DoublePoint1(this.m_normals[o-2])),r.m_endtype===e.EndType.etClosedPolygon){for(var d=o-1,l=0;l<o;l++)d=this.OffsetPoint(l,d,r.m_jointype);this.m_destPolys.push(this.m_destPoly)}else if(r.m_endtype===e.EndType.etClosedLine){for(var d=o-1,l=0;l<o;l++)d=this.OffsetPoint(l,d,r.m_jointype);this.m_destPolys.push(this.m_destPoly),this.m_destPoly=[];for(var f=this.m_normals[o-1],l=o-1;l>0;l--)this.m_normals[l]=new e.DoublePoint2(-this.m_normals[l-1].X,-this.m_normals[l-1].Y);this.m_normals[0]=new e.DoublePoint2(-f.X,-f.Y),d=0;for(var l=o-1;l>=0;l--)d=this.OffsetPoint(l,d,r.m_jointype);this.m_destPolys.push(this.m_destPoly)}else{for(var d=0,l=1;l<o-1;++l)d=this.OffsetPoint(l,d,r.m_jointype);var p;if(r.m_endtype===e.EndType.etOpenButt){var l=o-1;p=new e.IntPoint2(e.ClipperOffset.Round(this.m_srcPoly[l].X+this.m_normals[l].X*t),e.ClipperOffset.Round(this.m_srcPoly[l].Y+this.m_normals[l].Y*t)),this.m_destPoly.push(p),p=new e.IntPoint2(e.ClipperOffset.Round(this.m_srcPoly[l].X-this.m_normals[l].X*t),e.ClipperOffset.Round(this.m_srcPoly[l].Y-this.m_normals[l].Y*t)),this.m_destPoly.push(p)}else{var l=o-1;d=o-2,this.m_sinA=0,this.m_normals[l]=new e.DoublePoint2(-this.m_normals[l].X,-this.m_normals[l].Y),r.m_endtype===e.EndType.etOpenSquare?this.DoSquare(l,d):this.DoRound(l,d)}for(var l=o-1;l>0;l--)this.m_normals[l]=new e.DoublePoint2(-this.m_normals[l-1].X,-this.m_normals[l-1].Y);this.m_normals[0]=new e.DoublePoint2(-this.m_normals[1].X,-this.m_normals[1].Y),d=o-1;for(var l=d-1;l>0;--l)d=this.OffsetPoint(l,d,r.m_jointype);r.m_endtype===e.EndType.etOpenButt?(p=new e.IntPoint2(e.ClipperOffset.Round(this.m_srcPoly[0].X-this.m_normals[0].X*t),e.ClipperOffset.Round(this.m_srcPoly[0].Y-this.m_normals[0].Y*t)),this.m_destPoly.push(p),p=new e.IntPoint2(e.ClipperOffset.Round(this.m_srcPoly[0].X+this.m_normals[0].X*t),e.ClipperOffset.Round(this.m_srcPoly[0].Y+this.m_normals[0].Y*t)),this.m_destPoly.push(p)):(d=1,this.m_sinA=0,r.m_endtype===e.EndType.etOpenSquare?this.DoSquare(0,1):this.DoRound(0,1)),this.m_destPolys.push(this.m_destPoly)}}}}}},e.ClipperOffset.prototype.Execute=function(){var t=arguments;if(t[0]instanceof e.PolyTree){var n=t[0],r=t[1];n.Clear(),this.FixOrientations(),this.DoOffset(r);var i=new e.Clipper(0);if(i.AddPaths(this.m_destPolys,e.PolyType.ptSubject,!0),r>0)i.Execute(e.ClipType.ctUnion,n,e.PolyFillType.pftPositive,e.PolyFillType.pftPositive);else{var a=e.Clipper.GetBounds(this.m_destPolys),o=new e.Path;if(o.push(new e.IntPoint2(a.left-10,a.bottom+10)),o.push(new e.IntPoint2(a.right+10,a.bottom+10)),o.push(new e.IntPoint2(a.right+10,a.top-10)),o.push(new e.IntPoint2(a.left-10,a.top-10)),i.AddPath(o,e.PolyType.ptSubject,!0),i.ReverseSolution=!0,i.Execute(e.ClipType.ctUnion,n,e.PolyFillType.pftNegative,e.PolyFillType.pftNegative),n.ChildCount()===1&&n.Childs()[0].ChildCount()>0){var s=n.Childs()[0];n.Childs()[0]=s.Childs()[0],n.Childs()[0].m_Parent=n;for(var c=1;c<s.ChildCount();c++)n.AddChild(s.Childs()[c])}else n.Clear()}}else{var n=t[0],r=t[1];e.Clear(n),this.FixOrientations(),this.DoOffset(r);var i=new e.Clipper(0);if(i.AddPaths(this.m_destPolys,e.PolyType.ptSubject,!0),r>0)i.Execute(e.ClipType.ctUnion,n,e.PolyFillType.pftPositive,e.PolyFillType.pftPositive);else{var a=e.Clipper.GetBounds(this.m_destPolys),o=new e.Path;o.push(new e.IntPoint2(a.left-10,a.bottom+10)),o.push(new e.IntPoint2(a.right+10,a.bottom+10)),o.push(new e.IntPoint2(a.right+10,a.top-10)),o.push(new e.IntPoint2(a.left-10,a.top-10)),i.AddPath(o,e.PolyType.ptSubject,!0),i.ReverseSolution=!0,i.Execute(e.ClipType.ctUnion,n,e.PolyFillType.pftNegative,e.PolyFillType.pftNegative),n.length>0&&n.splice(0,1)}}},e.ClipperOffset.prototype.OffsetPoint=function(t,n,r){if(this.m_sinA=this.m_normals[n].X*this.m_normals[t].Y-this.m_normals[t].X*this.m_normals[n].Y,Math.abs(this.m_sinA*this.m_delta)<1){if(this.m_normals[n].X*this.m_normals[t].X+this.m_normals[t].Y*this.m_normals[n].Y>0)return this.m_destPoly.push(new e.IntPoint2(e.ClipperOffset.Round(this.m_srcPoly[t].X+this.m_normals[n].X*this.m_delta),e.ClipperOffset.Round(this.m_srcPoly[t].Y+this.m_normals[n].Y*this.m_delta))),n}else this.m_sinA>1?this.m_sinA=1:this.m_sinA<-1&&(this.m_sinA=-1);if(this.m_sinA*this.m_delta<0)this.m_destPoly.push(new e.IntPoint2(e.ClipperOffset.Round(this.m_srcPoly[t].X+this.m_normals[n].X*this.m_delta),e.ClipperOffset.Round(this.m_srcPoly[t].Y+this.m_normals[n].Y*this.m_delta))),this.m_destPoly.push(new e.IntPoint1(this.m_srcPoly[t])),this.m_destPoly.push(new e.IntPoint2(e.ClipperOffset.Round(this.m_srcPoly[t].X+this.m_normals[t].X*this.m_delta),e.ClipperOffset.Round(this.m_srcPoly[t].Y+this.m_normals[t].Y*this.m_delta)));else switch(r){case e.JoinType.jtMiter:var i=1+(this.m_normals[t].X*this.m_normals[n].X+this.m_normals[t].Y*this.m_normals[n].Y);i>=this.m_miterLim?this.DoMiter(t,n,i):this.DoSquare(t,n);break;case e.JoinType.jtSquare:this.DoSquare(t,n);break;case e.JoinType.jtRound:this.DoRound(t,n)}return n=t,n},e.ClipperOffset.prototype.DoSquare=function(t,n){var r=Math.tan(Math.atan2(this.m_sinA,this.m_normals[n].X*this.m_normals[t].X+this.m_normals[n].Y*this.m_normals[t].Y)/4);this.m_destPoly.push(new e.IntPoint2(e.ClipperOffset.Round(this.m_srcPoly[t].X+this.m_delta*(this.m_normals[n].X-this.m_normals[n].Y*r)),e.ClipperOffset.Round(this.m_srcPoly[t].Y+this.m_delta*(this.m_normals[n].Y+this.m_normals[n].X*r)))),this.m_destPoly.push(new e.IntPoint2(e.ClipperOffset.Round(this.m_srcPoly[t].X+this.m_delta*(this.m_normals[t].X+this.m_normals[t].Y*r)),e.ClipperOffset.Round(this.m_srcPoly[t].Y+this.m_delta*(this.m_normals[t].Y-this.m_normals[t].X*r))))},e.ClipperOffset.prototype.DoMiter=function(t,n,r){var i=this.m_delta/r;this.m_destPoly.push(new e.IntPoint2(e.ClipperOffset.Round(this.m_srcPoly[t].X+(this.m_normals[n].X+this.m_normals[t].X)*i),e.ClipperOffset.Round(this.m_srcPoly[t].Y+(this.m_normals[n].Y+this.m_normals[t].Y)*i)))},e.ClipperOffset.prototype.DoRound=function(t,n){for(var r=Math.atan2(this.m_sinA,this.m_normals[n].X*this.m_normals[t].X+this.m_normals[n].Y*this.m_normals[t].Y),i=Math.max(e.Cast_Int32(e.ClipperOffset.Round(this.m_StepsPerRad*Math.abs(r))),1),a=this.m_normals[n].X,o=this.m_normals[n].Y,s,c=0;c<i;++c)this.m_destPoly.push(new e.IntPoint2(e.ClipperOffset.Round(this.m_srcPoly[t].X+a*this.m_delta),e.ClipperOffset.Round(this.m_srcPoly[t].Y+o*this.m_delta))),s=a,a=a*this.m_cos-this.m_sin*o,o=s*this.m_sin+o*this.m_cos;this.m_destPoly.push(new e.IntPoint2(e.ClipperOffset.Round(this.m_srcPoly[t].X+this.m_normals[t].X*this.m_delta),e.ClipperOffset.Round(this.m_srcPoly[t].Y+this.m_normals[t].Y*this.m_delta)))},e.Error=function(e){try{throw Error(e)}catch(e){alert(e.message)}},e.JS={},e.JS.AreaOfPolygon=function(t,n){return n||=1,e.Clipper.Area(t)/(n*n)},e.JS.AreaOfPolygons=function(t,n){n||=1;for(var r=0,i=0;i<t.length;i++)r+=e.Clipper.Area(t[i]);return r/(n*n)},e.JS.BoundsOfPath=function(t,n){return e.JS.BoundsOfPaths([t],n)},e.JS.BoundsOfPaths=function(t,n){n||=1;var r=e.Clipper.GetBounds(t);return r.left/=n,r.bottom/=n,r.right/=n,r.top/=n,r},e.JS.Clean=function(t,n){if(!(t instanceof Array))return[];var r=t[0]instanceof Array,t=e.JS.Clone(t);if(typeof n!=`number`||n===null)return e.Error(`Delta is not a number in Clean().`),t;if(t.length===0||t.length===1&&t[0].length===0||n<0)return t;r||(t=[t]);for(var i=t.length,a,o,s,c,l,u,d,f=[],p=0;p<i;p++)if(o=t[p],a=o.length,a!==0){if(a<3)s=o,f.push(s);else{for(s=o,c=n*n,l=o[0],u=1,d=1;d<a;d++)(o[d].X-l.X)*(o[d].X-l.X)+(o[d].Y-l.Y)*(o[d].Y-l.Y)<=c||(s[u]=o[d],l=o[d],u++);l=o[u-1],(o[0].X-l.X)*(o[0].X-l.X)+(o[0].Y-l.Y)*(o[0].Y-l.Y)<=c&&u--,u<a&&s.splice(u,a-u),s.length&&f.push(s)}}return!r&&f.length?f=f[0]:!r&&f.length===0?f=[]:r&&f.length===0&&(f=[[]]),f},e.JS.Clone=function(e){if(!(e instanceof Array)||e.length===0)return[];if(e.length===1&&e[0].length===0)return[[]];var t=e[0]instanceof Array;t||(e=[e]);var n=e.length,r,i,a,o,s=Array(n);for(i=0;i<n;i++){for(r=e[i].length,o=Array(r),a=0;a<r;a++)o[a]={X:e[i][a].X,Y:e[i][a].Y};s[i]=o}return t||(s=s[0]),s},e.JS.Lighten=function(t,n){if(!(t instanceof Array))return[];if(typeof n!=`number`||n===null)return e.Error(`Tolerance is not a number in Lighten().`),e.JS.Clone(t);if(t.length===0||t.length===1&&t[0].length===0||n<0)return e.JS.Clone(t);var r=t[0]instanceof Array;r||(t=[t]);var i,a,o,s,c,l,u,d,f,p,m,h,g,_,v,y,b,x=t.length,S=n*n,C=[];for(i=0;i<x;i++)if(o=t[i],l=o.length,l!==0){for(s=0;s<1e6;s++){for(c=[],l=o.length,o[l-1].X!==o[0].X||o[l-1].Y!==o[0].Y?(h=1,o.push({X:o[0].X,Y:o[0].Y}),l=o.length):h=0,m=[],a=0;a<l-2;a++)u=o[a],f=o[a+1],d=o[a+2],y=u.X,b=u.Y,g=d.X-y,_=d.Y-b,(g!==0||_!==0)&&(v=((f.X-y)*g+(f.Y-b)*_)/(g*g+_*_),v>1?(y=d.X,b=d.Y):v>0&&(y+=g*v,b+=_*v)),g=f.X-y,_=f.Y-b,p=g*g+_*_,p<=S&&(m[a+1]=1,a++);for(c.push({X:o[0].X,Y:o[0].Y}),a=1;a<l-1;a++)m[a]||c.push({X:o[a].X,Y:o[a].Y});if(c.push({X:o[l-1].X,Y:o[l-1].Y}),h&&o.pop(),m.length)o=c;else break}l=c.length,c[l-1].X===c[0].X&&c[l-1].Y===c[0].Y&&c.pop(),c.length>2&&C.push(c)}return r||(C=C[0]),C===void 0&&(C=[]),C},e.JS.PerimeterOfPath=function(e,t,n){if(e===void 0)return 0;var r=Math.sqrt,i=0,a,o,s=0,c=0,l=0,u=0,d=e.length;if(d<2)return 0;for(t&&(e[d]=e[0],d++);--d;)a=e[d],s=a.X,c=a.Y,o=e[d-1],l=o.X,u=o.Y,i+=r((s-l)*(s-l)+(c-u)*(c-u));return t&&e.pop(),i/n},e.JS.PerimeterOfPaths=function(t,n,r){r||=1;for(var i=0,a=0;a<t.length;a++)i+=e.JS.PerimeterOfPath(t[a],n,r);return i},e.JS.ScaleDownPath=function(e,t){var n,r;for(t||=1,n=e.length;n--;)r=e[n],r.X/=t,r.Y/=t},e.JS.ScaleDownPaths=function(e,t){var n,r,i;for(t||=1,n=e.length;n--;)for(r=e[n].length;r--;)i=e[n][r],i.X/=t,i.Y/=t},e.JS.ScaleUpPath=function(e,t){var n,r,i=Math.round;for(t||=1,n=e.length;n--;)r=e[n],r.X=i(r.X*t),r.Y=i(r.Y*t)},e.JS.ScaleUpPaths=function(e,t){var n,r,i,a=Math.round;for(t||=1,n=e.length;n--;)for(r=e[n].length;r--;)i=e[n][r],i.X=a(i.X*t),i.Y=a(i.Y*t)},e.ExPolygons=function(){return[]},e.ExPolygon=function(){this.outer=null,this.holes=null},e.JS.AddOuterPolyNodeToExPolygons=function(t,n){var r=new e.ExPolygon;r.outer=t.Contour();var i=t.Childs(),a=i.length;r.holes=Array(a);for(var o,s,c=0,l,u,d;c<a;c++)for(o=i[c],r.holes[c]=o.Contour(),l=0,u=o.Childs(),d=u.length;l<d;l++)s=u[l],e.JS.AddOuterPolyNodeToExPolygons(s,n);n.push(r)},e.JS.ExPolygonsToPaths=function(t){var n,r,i,a,o=new e.Paths;for(n=0,i=t.length;n<i;n++)for(o.push(t[n].outer),r=0,a=t[n].holes.length;r<a;r++)o.push(t[n].holes[r]);return o},e.JS.PolyTreeToExPolygons=function(t){for(var n=new e.ExPolygons,r,i=0,a=t.Childs(),o=a.length;i<o;i++)r=a[i],e.JS.AddOuterPolyNodeToExPolygons(r,n);return n}})()}))(),1),QW=1e3,$W=e=>Math.round(e*QW),eG=e=>e.map(e=>({X:$W(e.x),Y:$W(e.y)})),tG=e=>e.map(e=>({x:e.X/QW,y:e.Y/QW}));function nG(e,t){let n=new ZW.default.Clipper;return n.StrictlySimple=!0,n.AddPaths(e.filter(e=>e.length>=3),ZW.default.PolyType.ptSubject,!0),n.AddPaths(t.filter(e=>e.length>=3),ZW.default.PolyType.ptClip,!0),n}function rG(e){let t=new ZW.default.PolyTree,n=ZW.default.PolyFillType.pftNonZero;return nG(e,[]).Execute(ZW.default.ClipType.ctUnion,t,n,n),ZW.default.JS.PolyTreeToExPolygons(t).map(e=>({outer:e.outer,holes:e.holes}))}var iG=e=>ZW.default.Clipper.Area(e),aG=.1,oG=[`top`,`bottom`],sG=1e-9,cG={top:`F_Cu`,inner1:`In1_Cu`,inner2:`In2_Cu`,bottom:`B_Cu`},lG={top:`F`,bottom:`B`},uG={top:`Top`,bottom:`Bot`},dG=e=>e.drill===void 0&&e.layers!==`through`,fG=(e,t)=>e.layers===`through`||e.layers===t;function pG(e,t=0,n){let r=e.width+2*t,i=e.height+2*t;if(r<=0||i<=0)return;let a={x:e.x,y:e.y},o=(e.rotation%360+360)%360%180,s=Math.abs(o%90)<sG||Math.abs(o%90-90)<sG,c=Math.abs(o-90)<sG?{width:i,height:r}:{width:r,height:i},l=n===void 0?{}:{function:n},u=()=>s?{kind:`flash`,at:a,aperture:{shape:`rect`,...c},...l}:{kind:`region`,points:gG(a,r,i,e.rotation),...l};switch(e.shape){case`circle`:return{kind:`flash`,at:a,aperture:{shape:`circle`,diameter:r},...l};case`rect`:return u();case`oval`:return s?{kind:`flash`,at:a,aperture:{shape:`obround`,...c},...l}:{kind:`region`,points:hG(a,r,i,e.rotation),...l};case`roundrect`:{let n=Math.min(Math.max((e.cornerRadius??0)+t,0),r/2,i/2);return n<=0?u():{kind:`flash`,at:a,aperture:{shape:`roundrect`,radius:n,...s?{...c,rotation:0}:{width:r,height:i,rotation:o}},...l}}}}var mG=11;function hG(e,t,n,r){let i=Math.min(t,n)/2,a=Math.max(t,n)/2-i,o=(r+(n>t?90:0))*Math.PI/180,[s,c]=[Math.cos(o),Math.sin(o)],l=(e,t)=>Array.from({length:mG},(n,r)=>{let a=t+Math.PI*r/10;return{x:e+i*Math.cos(a),y:i*Math.sin(a)}});return[...l(a,-Math.PI/2),...l(-a,Math.PI/2)].map(({x:t,y:n})=>({x:e.x+t*s-n*c,y:e.y+t*c+n*s}))}function gG(e,t,n,r){let i=r*Math.PI/180,[a,o]=[Math.cos(i),Math.sin(i)];return[[-t/2,-n/2],[t/2,-n/2],[t/2,n/2],[-t/2,n/2]].map(([t,n])=>({x:e.x+t*a-n*o,y:e.y+t*o+n*a}))}var _G=e=>e.flatMap(e=>e.pads),vG=e=>dG(e)?`SMDPad,CuDef`:`ComponentPad`,yG=`Other,Legend`,bG=e=>e!==void 0;function xG(e,t){let n=e.pours.filter(e=>e.layer===t).flatMap(e=>e.polygons.flatMap(e=>[eG(e.outer),...e.holes.map(eG)]));return n.length===0?[]:rG(n).sort((e,t)=>Math.abs(iG(t.outer))-Math.abs(iG(e.outer))).flatMap(e=>[{kind:`region`,points:tG(e.outer),function:`Conductor`},...e.holes.map(e=>({kind:`region`,points:tG(e),polarity:`clear`}))])}function SG(e,t){let n=_G(e.parts).filter(e=>e.layers===`through`||e.layers===t).map(e=>pG(e,0,vG(e))),r=e.tracks.filter(e=>e.layer===t&&e.missingLayer===void 0).map(e=>({kind:`draw`,points:e.points,width:e.width,function:`Conductor`})),i=e.vias.filter(e=>e.missingLayer===void 0&&sS(e).has(t)).map(e=>({kind:`flash`,at:e.at,aperture:{shape:`circle`,diameter:e.diameter},function:`ViaPad`}));return[...xG(e,t),...n.filter(bG),...r,...i]}function CG(e,t,n,r){let i=$i(e,n,r).filter(e=>e.side===t);return[...e.parts.filter(e=>e.side===t).flatMap(e=>e.silkscreen),...i.flatMap(e=>Oi(e.component,e.at,1,t===`bottom`,e.rotation===90))].filter(e=>e.length>0).map(e=>({kind:`draw`,points:e,width:ki,function:yG}))}function wG(e){let t=e.board?.outline??[],n=t[0];return n===void 0?[]:[{kind:`draw`,points:[...t,n],width:aG,function:`Profile`}]}function TG(e,t){let n=Qx(e.board?.layers??2),r=t.maskExpansion??.05,i=t.pasteReduction??0,a=new Map;[`top`,`inner1`,`inner2`,`bottom`].filter(e=>n.includes(e)).forEach((t,n)=>{let r=t===`top`?`Top`:t===`bottom`?`Bot`:`Inr`;a.set(cG[t],{fileFunction:`Copper,L${n+1},${r}`,polarity:`Positive`,objects:SG(e,t)})});for(let n of oG){let o=_G(e.parts).filter(e=>fG(e,n)),s=o.map(e=>pG(e,r,vG(e))).filter(bG),c=o.filter(dG).map(e=>pG(e,-i,vG(e))).filter(bG);a.set(`${lG[n]}_Mask`,{fileFunction:`Soldermask,${uG[n]}`,polarity:`Negative`,objects:s}),a.set(`${lG[n]}_Paste`,{fileFunction:`Paste,${uG[n]}`,polarity:`Positive`,objects:c}),a.set(`${lG[n]}_Silkscreen`,{fileFunction:`Legend,${uG[n]}`,polarity:`Positive`,objects:CG(e,n,r,ma(t))})}return a.set(`Edge_Cuts`,{fileFunction:`Profile,NP`,polarity:`Positive`,objects:wG(e)}),Ly.flatMap(e=>{let t=a.get(e);return t===void 0?[]:[{name:e,layer:t}]})}var EG=.06,DG=.035,OG=.08,kG=34,AG=14,jG=.42,MG=.97,NG=e=>e<0?0:e>1?1:e,PG=(e,t,n)=>{let r=NG((n-e)/(t-e));return r*r*(3-2*r)},FG=(e,t)=>e.data[t],IG=(e,t)=>Math.max(1,Math.round(e*t));function LG(e,t,n,r,i){let a=new Float32Array(e.length),[o,s]=i?[n,t]:[t,n],c=i?1:t,l=1/(2*r+1);for(let n=0;n<o;n+=1){let o=i?n*t:n,u=o+(s-1)*c,d=0;for(let t=-r;t<=r;t+=1)d+=e[o+Math.min(Math.max(t,0),s-1)*c];for(let t=0,n=o;t<s;t+=1,n+=c){a[n]=d*l;let i=t+r+1<s?n+(r+1)*c:u,f=t-r>0?n-r*c:o;d+=e[i]-e[f]}}return a}function RG(e,t){let n=e.data;for(let r=0;r<2;r+=1)n=LG(LG(n,e.width,e.height,t,!0),e.width,e.height,t,!1);return{width:e.width,height:e.height,data:n}}function zG(e,t){let{width:n,height:r}=e,i=new Float32Array(n*r),a=Math.max(1,Math.round(t/2)),o=(t+1)/(2*a);for(let t=0;t<r;t+=1){let[s,c]=[Math.max(t-a,0),Math.min(t+a,r-1)];for(let r=0;r<n;r+=1){let[l,u]=[Math.max(r-a,0),Math.min(r+a,n-1)];i[t*n+r]=Math.max(-1,Math.min(1,(e.data[c*n+u]-e.data[s*n+l])*-o))}}return i}function BG(e,t,n,r,i,a){for(let o=0;o<3;o+=1)e[t+o]=n[r+o]+(i[o]-n[r+o])*a}function VG(e){let t=e.body.data.length,n=new Float32Array(t*3),r=MH.shaded,i=[0,1,2].map(e=>MH.lit[e]-r[e]);for(let a=0;a<t;a+=1){let t=(1-FG(e.copper,a))*(1-FG(e.otherCopper,a));n[a*3]=r[0]+i[0]*t,n[a*3+1]=r[1]+i[1]*t,n[a*3+2]=r[2]+i[2]*t}return n}function HG(e,t,n,r){let i=kH[n.mask],{width:a,height:o}=t.body,s=new Float32Array(e.length),c=[0,0,0];for(let n=0;n<o;n+=1){let l=i.gloss*AG*.5;for(let u=0;u<a;u+=1){let d=n*a+u,f=FG(t.body,d)*(1-FG(t.openings,d)),p=FG(r.soft,d),m=r.slope[d]*kG*(.5+i.gloss*.5),h=l*(1-u/a-n/o);for(let t=0;t<3;t+=1){let n=i.over[t]+(i.onCopper[t]-i.over[t])*p;c[t]=n+(e[d*3+t]-MH.shaded[t])*i.see+m+h}BG(s,d*3,e,d*3,c,f)}}return s}function UG(e,t,n,r){let i=jH[n.finish],a=new Float32Array(e),o=[0,0,0];for(let n=0;n<t.body.data.length;n+=1){let s=FG(t.copper,n)*FG(t.openings,n)*FG(t.body,n);if(s<=0)continue;let c=PG(.1,.9,FG(r.soft,n)),l=r.slope[n];for(let e=0;e<3;e+=1){let t=i.rim[e]+(i.face[e]-i.rim[e])*c;o[e]=l>=0?t+(i.shine[e]-t)*l*.8:t+(i.rim[e]-t)*-l*.6}BG(a,n*3,e,n*3,o,s)}return a}function WG(e,t,n){let r=AH[n.silk].colour,i=new Float32Array(e);for(let n=0;n<t.body.data.length;n+=1){let a=FG(t.silk,n)*FG(t.body,n)*(1-FG(t.openings,n))*(1-Math.max(FG(t.plated,n),FG(t.nonPlated,n)));a>0&&BG(i,n*3,e,n*3,r,a*MG)}return i}var GG=(e,t)=>Math.max(FG(e.bore,t),FG(e.nonPlated,t));function KG(e,t){let n=t.body.data.length,r=new Float32Array(n*4);for(let i=0;i<n;i+=1){let n=Math.max(0,FG(t.plated,i)-FG(t.bore,i));n>0?BG(r,i*4,e,i*3,NH,n):(r[i*4]=e[i*3],r[i*4+1]=e[i*3+1],r[i*4+2]=e[i*3+2]),r[i*4+3]=FG(t.body,i)*(1-GG(t,i))}return r}function qG(e,t){let n=new Float32Array(e);for(let r=0;r<t.data.length;r+=1){let i=NG((1-FG(t,r))*2.5);if(!(i<=0))for(let t=0;t<3;t+=1)n[r*4+t]=e[r*4+t]*(1-jG*i)}return n}function JG(e,t){let n=new Uint8ClampedArray(e.length);for(let r=0;r<e.length;r+=4){let i=e[r+3];if(t===void 0){for(let t=0;t<3;t+=1)n[r+t]=e[r+t];n[r+3]=i*255}else{for(let a=0;a<3;a+=1)n[r+a]=t[a]+(e[r+a]-t[a])*i;n[r+3]=255}}return n}function YG(e,t,n){let r=(e,t)=>{let r=IG(t,n),i=RG(e,r);return{soft:i,slope:zG(i,r)}},i=e.body.data.length,a={...e.copper,data:new Float32Array(i)},o={...e.body,data:new Float32Array(i)};for(let t=0;t<i;t+=1)a.data[t]=FG(e.copper,t)*FG(e.openings,t),o.data[t]=FG(e.body,t)*(1-GG(e,t));return JG(qG(KG(WG(UG(HG(VG(e),e,t,r(e.copper,EG)),e,t,r(a,DG)),e,t),e),RG(o,IG(OG,n))),t.background)}var XG=16;function ZG(e,t,n){let r=Math.max(1,Math.ceil((e.maxX-e.minX)*t-1e-9));return{width:r,height:Math.max(1,Math.ceil((e.maxY-e.minY)*t-1e-9)),pxPerMm:t,minX:e.minX,maxX:e.minX+r/t,maxY:e.maxY,mirrored:n}}var QG=e=>({width:e.width,height:e.height,data:new Float32Array(e.width*e.height)});function $G(e,t){return{x:(e.mirrored?e.maxX-t.x:t.x-e.minX)*e.pxPerMm,y:(e.maxY-t.y)*e.pxPerMm}}function eK(e,t){let n=Math.max(e-.5,-t),r=Math.min(e+.5,t);return r>n?Math.min(r-n,1):0}var tK=(e,t)=>Math.sqrt(e*e+t*t),nK=e=>e<0?0:e>1?1:e;function rK(e,t,n,r){if(!(n<=0)){if(r===`dark`)n>e[t]&&(e[t]=n);else{let r=1-n;r<e[t]&&(e[t]=r)}}}function iK(e,t,n,r,i,a){let o=Math.max(0,Math.floor(Math.min(t.x,n.x)-r)),s=Math.min(e.width,Math.ceil(Math.max(t.x,n.x)+r)),c=Math.max(0,Math.floor(Math.min(t.y,n.y)-r)),l=Math.min(e.height,Math.ceil(Math.max(t.y,n.y)+r));for(let t=c;t<l;t+=1){let n=t*e.width;for(let r=o;r<s;r+=1)rK(e.data,n+r,i(r+.5,t+.5),a)}}function aK(e,t,n,r=`dark`){iK(e,t,t,n+1,(e,r)=>eK(tK(e-t.x,r-t.y),n),r)}function oK(e,t,n,r,i=`dark`){let[a,o]=[n.x-t.x,n.y-t.y],s=a*a+o*o;if(s===0)return aK(e,t,r,i);iK(e,t,n,r+1,(e,n)=>{let i=nK(((e-t.x)*a+(n-t.y)*o)/s);return eK(tK(e-t.x-i*a,n-t.y-i*o),r)},i)}function sK(e,t,n,r,i,a,o=`dark`){let[s,c]=[Math.cos(i),Math.sin(i)],l=Math.hypot(n,r)+1,u=Math.min(a,n,r);iK(e,t,t,l,(e,i)=>{let a=(e-t.x)*s+(i-t.y)*c,o=-(e-t.x)*c+(i-t.y)*s;if(u<=0)return eK(a,n)*eK(o,r);let l=Math.abs(a)-(n-u),d=Math.abs(o)-(r-u);return nK(.5-(tK(Math.max(l,0),Math.max(d,0))+Math.min(Math.max(l,d),0)-u))},o)}function cK(e){let t=[];for(let n of e)for(let e=0;e<n.length;e+=1){let r=n[e],i=n[(e+1)%n.length];if(r.y===i.y)continue;let[a,o,s]=r.y<i.y?[r,i,1]:[i,r,-1];t.push({x0:a.x,y0:a.y,y1:o.y,slope:(o.x-a.x)/(o.y-a.y),dir:s})}return t.sort((e,t)=>e.y0-t.y0)}function lK(e,t,n,r,i){let a=Math.floor(n),o=Math.floor(r);a===o?e[a]=e[a]+(r-n)*i:(e[a]=e[a]+(a+1-n)*i,t[a+1]=t[a+1]+i,t[o]=t[o]-i,e[o]=e[o]+(r-o)*i)}function uK(e,t,n,r=`dark`){let i=cK(t);if(i.length===0)return;let a=Math.max(0,Math.floor(i[0]?.y0??0)),o=Math.min(e.height,Math.ceil(Math.max(...i.map(e=>e.y1)))),s=new Float32Array(e.width+2),c=new Float32Array(e.width+2),l=[],u=0,d=[],f=1/XG;for(let t=a;t<o;t+=1){for(;u<i.length&&i[u].y0<t+1;)d.push(i[u++]);if(d=d.filter(e=>e.y1>t),d.length===0)continue;let a=e.width,o=0;for(let r=0;r<XG;r+=1){let i=t+(r+.5)*f;l.length=0;for(let e of d)e.y0<=i&&i<e.y1&&l.push({x:e.x0+(i-e.y0)*e.slope,dir:e.dir});l.sort((e,t)=>e.x-t.x);let u=0;for(let t=0;t<l.length-1;t+=1){let r=l[t];if(u=n===`nonzero`?u+r.dir:u^1,u===0)continue;let i=Math.max(r.x,0),d=Math.min(l[t+1].x,e.width);if(d<=i)continue;let p=Math.min(d,e.width-1e-9);lK(s,c,i,p,f),a=Math.min(a,Math.floor(i)),o=Math.max(o,Math.floor(p)+1)}}let p=0,m=t*e.width;for(let t=a;t<o;t+=1)p+=c[t],rK(e.data,m+t,Math.min(p+s[t],1),r),s[t]=0,c[t]=0;o>a&&(c[o]=0)}}function dK(e,t){let n=t*Math.PI/180;return Math.atan2(-Math.sin(n),(e.mirrored?-1:1)*Math.cos(n))}function fK(e,t,n,r,i){let a=t.pxPerMm,o=$G(t,n);switch(r.shape){case`circle`:return aK(e,o,r.diameter/2*a,i);case`rect`:return sK(e,o,r.width/2*a,r.height/2*a,0,0,i);case`obround`:{let t=r.width>=r.height,n=Math.abs(r.width-r.height)/2*a,[s,c]=t?[n,0]:[0,n];return oK(e,{x:o.x-s,y:o.y-c},{x:o.x+s,y:o.y+c},Math.min(r.width,r.height)/2*a,i)}case`roundrect`:return sK(e,o,r.width/2*a,r.height/2*a,dK(t,r.rotation),r.radius*a,i)}}function pK(e,t,n){let r=t.pxPerMm;if(n.kind===`flash`)return fK(e,t,n.at,n.aperture,`dark`);if(n.kind===`region`)return uK(e,[n.points.map(e=>$G(t,e))],`nonzero`,n.polarity===`clear`?`clear`:`dark`);let i=n.points.map(e=>$G(t,e)),a=n.width/2*r;if(i.length===1)return aK(e,i[0],a);for(let t=1;t<i.length;t+=1)oK(e,i[t-1],i[t],a)}function mK(e,t){let n=QG(e);for(let r of t.objects)pK(n,e,r);return n}function hK(e,t){let n=QG(e);return uK(n,t.objects.flatMap(t=>t.kind===`draw`&&t.points.length>=3?[t.points.map(t=>$G(e,t))]:[]),`evenodd`),n}function gK(e,t,n=0){let r=QG(e);for(let i of t){let t=(i.diameter/2-n)*e.pxPerMm;if(t<=0)continue;let a=$G(e,i.at);i.to===void 0?aK(r,a,t):oK(r,a,$G(e,i.to),t)}return r}var _K=4e3,vK=.05,yK={top:{copper:`F_Cu`,mask:`F_Mask`,paste:`F_Paste`,silk:`F_Silkscreen`},bottom:{copper:`B_Cu`,mask:`B_Mask`,paste:`B_Paste`,silk:`B_Silkscreen`}},bK=new Set([`F_Cu`,`In1_Cu`,`In2_Cu`,`B_Cu`]);function xK(e){let t=e.board?.outline??[];if(t.length<3)throw Error(`The board has no outline to draw`);let n=t.map(e=>e.x),r=t.map(e=>e.y);return{minX:Math.min(...n),minY:Math.min(...r),maxX:Math.max(...n),maxY:Math.max(...r)}}function SK(e,t){let n=ZG(t.box??xK(e.pcb),t.pxPerMm??20,(t.side??`top`)===`bottom`);if(Math.max(n.width,n.height)>4e3)throw Error(`The picture would be ${n.width} x ${n.height} px; at most ${_K} on its long side`);return n}function CK(e,t,n){xK(e.pcb);let r=new Map(TG(e.pcb,e.rules.fabrication).map(({name:e,layer:t})=>[e,t])),i=yK[n],a=e=>{let n=r.get(e);return n===void 0?QG(t):mK(t,n)},o=QG(t);for(let e of bK){if(e===i.copper||!r.has(e))continue;let t=a(e);for(let e=0;e<t.data.length;e+=1)t.data[e]>o.data[e]&&(o.data[e]=t.data[e])}let s=r.get(`Edge_Cuts`),c=XW(e.pcb);return{body:s===void 0?QG(t):hK(t,s),copper:a(i.copper),otherCopper:o,openings:a(i.mask),paste:a(i.paste),silk:a(i.silk),plated:gK(t,c.plated),bore:gK(t,c.plated,Math.max(vK,1/t.pxPerMm)),nonPlated:gK(t,c.nonPlated)}}function wK(e,t={}){let n=t.side??`top`,r=RH(t.look),i=SK(e,t),a=YG(CK(e,i,n),r,i.pxPerMm);return{width:i.width,height:i.height,rgba:a,pxPerMm:i.pxPerMm,mmPerPx:1/i.pxPerMm,box:{minX:i.minX,minY:i.maxY-i.height/i.pxPerMm,maxX:i.maxX,maxY:i.maxY},origin:$G(i,{x:0,y:0}),mirrored:i.mirrored,side:n,look:r}}var TK=4e3,EK=4e6;function DK(e){let[t,n]=[e.maxX-e.minX,e.maxY-e.minY];return Math.min(40,TK/Math.max(t,n,1e-9),Math.sqrt(EK/Math.max(t*n,1e-9)))}var OK=4,kK=.45,AK=2.6,jK=.45;function MK(e){let t=[...e].sort((e,t)=>e.x-t.x||e.y-t.y),n=(e,t,n)=>(t.x-e.x)*(n.y-e.y)-(t.y-e.y)*(n.x-e.x),r=e=>{let t=[];for(let r of e){for(;t.length>=2&&n(t[t.length-2],t[t.length-1],r)<=0;)t.pop();t.push(r)}return t.pop(),t};return[...r(t),...r([...t].reverse())]}function NK(e,t,n,r){let i=(e,i)=>{let a=new Float32Array(e.length),[o,s]=i?[n,t]:[t,n];for(let n=0;n<o;n++){let o=0,c=e=>i?n*t+e:e*t+n;for(let t=-r;t<=r;t++)o+=t>=0&&t<s?e[c(t)]:0;for(let t=0;t<s;t++){a[c(t)]=o/(2*r+1);let[n,i]=[t+r+1,t-r];n<s&&(o+=e[c(n)]),i>=0&&(o-=e[c(i)])}}return a},a=e;for(let e=0;e<2;e++)a=i(i(a,!0),!1);return a}function PK(e,t,n){let[r,i]=[Math.ceil(e.width/OK),Math.ceil(e.height/OK)],a=new Float32Array(r*i),o=(t,n)=>({x:(e.origin.x+(e.mirrored?-t:t)*e.pxPerMm)/OK,y:(e.origin.y-n*e.pxPerMm)/OK}),[s,c]=[-pW[0]/pW[2],-pW[1]/pW[2]];for(let e of t.filter(e=>e.side===n)){let t=Math.min(e.height,AK),n=MK(e.corners.flatMap(e=>[e,{x:e.x+s*t,y:e.y+c*t}]).map(e=>o(e.x,e.y))),[l,u]=[Math.max(0,Math.floor(Math.min(...n.map(e=>e.x)))),Math.min(r-1,Math.ceil(Math.max(...n.map(e=>e.x))))],[d,f]=[Math.max(0,Math.floor(Math.min(...n.map(e=>e.y)))),Math.min(i-1,Math.ceil(Math.max(...n.map(e=>e.y))))];for(let e=d;e<=f;e++)for(let t=l;t<=u;t++){let[i,o]=[t+.5,e+.5],s=0,c=!0;for(let e=0;e<n.length&&c;e++){let t=n[e],r=n[(e+1)%n.length],a=Math.sign((r.x-t.x)*(o-t.y)-(r.y-t.y)*(i-t.x));a!==0&&(s===0?s=a:a!==s&&(c=!1))}c&&(a[e*r+t]=1)}}let l=NK(a,r,i,Math.max(1,Math.round(jK*e.pxPerMm/OK/2))),u=new Uint8ClampedArray(e.rgba);for(let t=0;t<e.height;t++){let n=Math.min(i-1.001,Math.max(0,t/OK-.5)),[a,o]=[Math.floor(n),n-Math.floor(n)];for(let n=0;n<e.width;n++){let s=(t*e.width+n)*4;if(u[s+3]===0)continue;let c=Math.min(r-1.001,Math.max(0,n/OK-.5)),[d,f]=[Math.floor(c),c-Math.floor(c)],p=(e,t)=>l[Math.min(i-1,t)*r+Math.min(r-1,e)],m=(p(d,a)*(1-f)+p(d+1,a)*f)*(1-o)+(p(d,a+1)*(1-f)+p(d+1,a+1)*f)*o;if(m<=.002)continue;let h=1-kK*Math.min(1,m);u[s]=u[s]*h,u[s+1]=u[s+1]*h,u[s+2]=u[s+2]*h}}return u}function FK(e,t,n,r=wK){let i;try{i=xK(e.pcb)}catch{return{}}let a=DK(i),o=i=>{let o=r(e,{side:i,look:{...n,background:void 0},pxPerMm:a}),s={rgba:o.rgba,width:o.width,height:o.height,origin:o.origin,pxPerMm:o.pxPerMm,mirrored:o.mirrored};return{...s,rgba:PK(s,t.parts,i)}};return{top:o(`top`),bottom:o(`bottom`)}}var IK=e=>`${e.mask??``}/${e.silk??``}/${e.finish??``}`,LK=0;function RK(e,t,n){return new Promise((r,i)=>{let a=new Worker(new URL(new URL(`texture-worker-CyI_g_XZ.js`,import.meta.url).href,``+import.meta.url),{type:`module`}),o=++LK;a.onmessage=e=>{a.terminate(),e.data.id===o&&(e.data.error?i(Error(e.data.error)):r(e.data.textures))},a.onerror=e=>{a.terminate(),i(Error(e.message))},a.postMessage({id:o,design:e,model:t,look:n})})}var zK=e=>new Promise(t=>setTimeout(()=>t(e()),50));function BK(e,t,n){let r=IK(n),[i,a]=(0,_.useState)(void 0);(0,_.useEffect)(()=>{let i=!0,o=performance.now(),s=t=>i&&a({design:e,key:r,textures:t,ms:performance.now()-o}),c=()=>zK(()=>FK(e,t,n)).then(s);return typeof Worker>`u`?c():RK(e,t,n).then(s,c),()=>{i=!1}},[e,r]);let o=i&&i.design===e&&i.key===r?i:void 0;return{textures:o?.textures,ms:o?.ms}}var VK=160,HK=`Drag to turn, wheel to zoom. Keys: arrows turn, + and − zoom, T top, B bottom, Home resets.`;function UK({design:e}){let t=(0,_.useMemo)(()=>OH(e),[e]),[n,r]=(0,_.useState)({}),{textures:i}=BK(e,t,n),a=(0,_.useMemo)(()=>dW(e,t),[e,t]),o=(0,_.useMemo)(()=>JW(t,{parts:a,...i?{textures:i}:{},look:n,mounting:e.pcb.holes.length,layers:e.pcb.board?.layers??2}),[t,a,i,n,e]),[s,c]=(0,_.useState)(!0),l=(0,_.useRef)(null),u=(0,_.useRef)(null),d=(0,_.useRef)(void 0),f=(0,_.useRef)(void 0),p=oO(l),[m,h]=(0,_.useState)(YH),[g,v]=(0,_.useState)(void 0),[y,b]=(0,_.useState)(void 0),[x,S]=(0,_.useState)(void 0),C=g??y;(0,_.useEffect)(()=>{let e=u.current,{width:t,height:n}=p;if(!e||t===0||n===0)return;let r=performance.now(),i={background:HW(W.background),highlight:C,reuse:d.current,lit:!0};d.current=s?PW(o,m,t,n,i):kW(o,m,t,n,i),e.width!==t&&(e.width=t),e.height!==n&&(e.height=n),e.getContext(`2d`)?.putImageData(new ImageData(d.current.color,t,n),0,0),s||S(performance.now()-r)},[o,m,p,C,s]),(0,_.useEffect)(()=>{c(!1);let e=setTimeout(()=>c(!0),VK);return()=>clearTimeout(e)},[m,p]),(0,_.useEffect)(()=>{let e=l.current;if(!e)return;let t=e=>{e.preventDefault(),h(t=>sU(t,e.deltaY))};return e.addEventListener(`wheel`,t,{passive:!1}),()=>e.removeEventListener(`wheel`,t)},[]);let w=e=>{let t=l.current?.getBoundingClientRect();return{x:e.clientX-(t?.left??0),y:e.clientY-(t?.top??0)}},T=e=>{let{x:t,y:n}=w(e),r=d.current;if(!r||t<0||n<0||t>=r.width||n>=r.height)return;let i=r.ids[Math.floor(n)*r.width+Math.floor(t)]??-1;return i>=0?i:void 0},E=C===void 0?void 0:t.parts[C];return(0,X.jsxs)(`div`,{className:`look`,children:[(0,X.jsxs)(`div`,{className:`look-view`,ref:l,tabIndex:0,role:`group`,"aria-label":`3D view of the board and its parts; it cannot be edited here`,"aria-describedby":`look-help`,"data-frame-ms":x===void 0?void 0:x.toFixed(1),onKeyDown:e=>{let t=cU(m,e.key);t!==void 0&&(e.preventDefault(),h(t))},onPointerDown:e=>{e.target.closest(`button`)||(e.currentTarget.setPointerCapture(e.pointerId),f.current={...w(e),orbit:m})},onPointerMove:e=>{if(f.current){let{x:t,y:n}=w(e);h(oU(f.current.orbit,t-f.current.x,n-f.current.y))}else v(T(e))},onPointerUp:()=>f.current=void 0,onPointerCancel:()=>f.current=void 0,onPointerLeave:()=>v(void 0),children:[(0,X.jsx)(`canvas`,{ref:u}),(0,X.jsxs)(`div`,{className:`look-tools`,children:[(0,X.jsx)(`button`,{type:`button`,onClick:()=>h(XH),children:`Top`}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>h(ZH),children:`Bottom`}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>h(YH),title:`Home`,children:`Reset view`})]}),(0,X.jsx)(`p`,{className:`look-status`,"aria-live":`polite`,children:E?GH(E):(0,X.jsx)(`span`,{id:`look-help`,children:HK})})]}),(0,X.jsxs)(`aside`,{className:`look-side`,children:[(0,X.jsx)(KH,{model:t}),(0,X.jsx)(JH,{look:n,onLook:r,ready:i!==void 0}),(0,X.jsx)(qH,{model:t,active:C,onActive:b})]})]})}var WK=(e,t,n)=>n?{label:e,command:t,shortcut:n}:{label:e,command:t},GK={alignLeft:`Align left`,alignRight:`Align right`,alignTop:`Align top`,alignBottom:`Align bottom`,alignHCentres:`Align horizontal centres`,alignVCentres:`Align vertical centres`,distributeH:`Distribute horizontally`,distributeV:`Distribute vertically`},KK={alignLeft:`Ctrl+Shift+L`,distributeH:`Ctrl+Shift+H`};function qK(e){if(e<2)return[];let t=t=>{let n=O(t,e),r=KK[t];return{label:GK[t],command:t,...r?{shortcut:r}:{},...n?{pending:n}:{}}};return[`separator`,...w.slice(0,6).map(t),`separator`,...w.slice(6).map(t)]}function JK({allLocked:e,selected:t}){return[{label:`Properties`,special:`properties`},`separator`,WK(`Rotate`,`rotate`,`Space`),e?WK(`Unlock`,`unlock`):WK(`Lock`,`lock`),WK(`Highlight its nets`,`highlight`,`H`),WK(`Copy`,`copy`,`Ctrl+C`),...qK(t),`separator`,WK(`Delete`,`delete`,`Delete`)]}var YK=[WK(`Fit all`,`fit`,`K`),WK(`Grid style`,`gridStyle`),`separator`,WK(`Zoom in`,`zoomIn`),WK(`Zoom out`,`zoomOut`),`separator`,WK(`Paste`,`paste`,`Ctrl+V`)],XK={remove:null,removeCorners:`Select this wire alone to remove its corners`},ZK=(e,t)=>t?{...e,pending:t}:e;function QK(e){return[{label:`Properties`,special:`properties`},`separator`,WK(`Highlight net`,`highlight`,`H`),ZK(WK(`Remove corners`,`removeCorners`),e?.removeCorners),`separator`,ZK(WK(`Delete`,`delete`,`Delete`),e?.remove)]}var $K=[{label:`Properties`,special:`properties`},`separator`,WK(`Delete`,`delete`,`Delete`)],eq=[{label:`Rename`,special:`rename`},{label:`Highlight net`,special:`highlightNet`}],tq=[WK(`Fillet tracks`,`filletTracks`,`U`),WK(`Straighten tracks`,`straightenTracks`,`Shift+U`),`separator`];function nq(e,t,n){let r=e.startsWith(`t`)?tq:[],i=WK(n?`Delete segment`:`Delete`,`delete`,`Delete`);return[{label:`Properties`,special:`properties`},`separator`,...r,t?WK(`Unlock`,`unlock`):WK(`Lock`,`lock`),`separator`,i]}function rq(e){let t={label:`Reset position`,special:`resetText`};return[e?{...t,pending:e}:t,`separator`,{label:`Properties`,special:`properties`}]}function iq(e,t){return e.kind===`part`?JK(t):e.kind===`copper`?nq(e.id,t.copperLocked,t.segment):e.kind===`wire`?QK(t.wire):e.kind===`drawing`?[...$K]:e.kind===`text`?rq(t.textReset):[...e.kind===`label`?eq:YK]}function aq(e){return e.map(e=>e===`separator`?`separator`:e.pending?`disabled`:`item`)}function oq(e,t){return e.length>0&&e.every(e=>t.has(e))}function sq(e,t){return t.kind===`drawing`?e.hasDrawing(t.id)?e:e.onlyDrawing(t.id):t.kind===`wire`?e.hasWire(t.id)?e:e.onlyWire(t.id):t.kind===`label`?e.hasLabel(t.label.id)?e:e.onlyLabel(t.label.id):t.kind===`copper`?e.hasCopper(t.id)?e:e.onlyCopper(t.id):t.kind===`text`?e.hasText(t.id)?e:e.onlyText(t.id):t.kind===`part`&&!e.has(t.name)?e.only(t.name):e}var cq=28,lq=9,uq=10;function dq(e){return{width:240,height:e.reduce((e,t)=>e+(t===`separator`?lq:cq),0)+uq}}function fq(e,t,n){let r=(e,t,n)=>Math.max(0,e+t>n?e-t:e);return{x:r(e.x,t.width,n.width),y:r(e.y,t.height,n.height)}}function pq(e){(0,_.useEffect)(()=>(window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)),[e])}function mq(e,t){let n=(0,_.useRef)(Cv(t));(0,_.useLayoutEffect)(()=>{let t=e.current,r=document.activeElement;return n.current!==null&&t?.querySelector(`[data-item="${n.current}"]`)?.focus(),()=>{r instanceof HTMLElement&&r.isConnected&&Om(document.activeElement,document.body,t)&&r.focus()}},[e])}var hq=(e,t)=>{let n=t instanceof HTMLElement&&e?.contains(t)?t.closest(`[data-item]`):null;return n?Number(n.dataset.item):null};function gq({entries:e,at:t,onRun:n,onClose:r}){let i=(0,_.useRef)(null),a=(0,_.useMemo)(()=>aq(e),[e]),[o,s]=(0,_.useState)(null);(0,_.useLayoutEffect)(()=>{let e=i.current?.getBoundingClientRect();e&&s({width:e.width,height:e.height})},[e]);let c=(0,_.useMemo)(()=>fq(t,o??dq(e),{width:window.innerWidth,height:window.innerHeight}),[t,e,o]);return fh(!0,e=>{let t=hq(i.current,document.activeElement),n=Sv(e.key,t===null?null:{menu:0,item:t},0,[a],{alt:e.altKey,ctrl:e.ctrlKey,meta:e.metaKey});if(n){if(n.preventDefault&&e.preventDefault(),n.open===null)return r();n.focus!==`keep`&&n.focus.item!==null&&i.current?.querySelector(`[data-item="${n.focus.item}"]`)?.focus()}}),mq(i,a),cv(!0,i,r),pq(r),(0,X.jsx)(`ul`,{className:`menu-dropdown context-menu`,role:`menu`,"aria-label":`Context menu`,ref:i,onContextMenu:e=>e.preventDefault(),style:{left:c.x,top:c.y},children:e.map((e,t)=>e===`separator`?(0,X.jsx)(`li`,{className:`menu-separator`,role:`separator`},`sep${t}`):(0,X.jsx)(`li`,{role:`none`,children:(0,X.jsx)(sv,{label:e.label,...e.shortcut?{shortcut:e.shortcut}:{},index:t,enabled:!e.pending,...e.pending?{reason:e.pending}:{},onActivate:()=>{r(),n(e)}})},e.label))})}var _q=[{view:`schematic`,label:`Schematic`},{view:`pcb`,label:`PCB`}];function vq(e,t,n,r){let i=e===t;return it(e)?[{view:`schematic`,label:`Schematic`,active:i}]:_q.flatMap(({view:e,label:t})=>e===`pcb`||!i||!r||r.names.length<=1?[{view:e,label:t,active:i&&e===n}]:r.names.map(t=>({view:e,label:t,page:t,active:n===`schematic`&&t===r.open})))}function yq(e,t,n,r,i){return{project:e||`Project`,view:r,files:t.map(e=>({file:e,documents:vq(e,n,r,i)}))}}_q.map(e=>e.view);var bq=`schematic:`,xq=`parent:`;function Sq(e){return e===`3d`?{view:`pcb`,look:!0}:e.startsWith(xq)?{...Sq(e.slice(7)),parent:!0}:e.startsWith(bq)?{view:`schematic`,page:e.slice(10)}:{view:e===`pcb`?`pcb`:`schematic`}}function Cq(e,t){return[...t===void 0?[]:wq(t,`pcb`).map(e=>({...e,id:`${xq}${e.id}`,active:!1,parent:!0})),{id:`schematic`,view:`schematic`,title:`${at(e)} (sheet)`,active:!0}]}function wq(e,t,n=[jv],r=jv,i){if(e!==void 0&&it(e))return Cq(e,i);let a=(e??``).replace(/\.circuit\.tsx$/,``),o=(e,t)=>a?`${a}${t}${e}`:e;return _q.flatMap(({view:e,label:i})=>e===`pcb`||n.length<=1?[{id:e,view:e,title:o(i,` `),active:e===t}]:n.map(n=>({id:`${bq}${n}`,view:e,page:n,title:o(n,` — `),active:t===`schematic`&&n===r})))}function Tq(e,t,n){if(t!==void 0&&it(t))return[...e];let r=(t??``).replace(/\.circuit\.tsx$/,``);return[...e.map(e=>n&&e.active?{...e,active:!1}:e),{id:`3d`,view:`pcb`,title:r?`${r} 3D`:`3D`,active:n,look:!0}]}function Eq({file:e,view:t,pages:n,page:r,onView:i,onPage:a,parent:o,onParent:s,look:c=!1,onLook:l}){let u=Tq(wq(e,t,n,r,o),e,c),d=u.find(e=>e.active)?.id??t,f=Nm({ids:u.map(e=>e.id),current:d,onSelect:e=>{let t=Sq(e);l?.(t.look===!0),t.look?i(t.view):t.parent?s?.(t.view):t.page===void 0?i(t.view):a(t.page)}});return(0,X.jsx)(`div`,{className:`doc-tabs hairline-b`,role:`tablist`,"aria-label":`Documents`,onKeyDown:f.onKeyDown,children:u.map((e,t)=>(0,X.jsx)(`button`,{role:`tab`,id:e.look?`doc-tab-3d`:e.active||e.page===void 0&&!e.parent?`doc-tab-${e.view}`:`doc-tab-${e.view}-${t}`,"aria-controls":`doc-panel`,"aria-selected":e.active,className:`doc-tab${e.active?` on`:``}`,title:e.title,...f.tab(e.id),children:(0,X.jsx)(`span`,{className:`doc-tab-label`,children:e.title})},e.id))})}function Dq({view:e,filter:t,onToggle:n}){return(0,X.jsxs)(`aside`,{className:`panel right filter-panel`,id:oD(`right`),role:`tabpanel`,"aria-labelledby":sD(`filter`),onClick:km,children:[(0,X.jsx)(`h3`,{className:`filter-head hairline-b`,children:`Pick`}),(0,X.jsx)(`ul`,{className:`filter-list`,children:G(e).map(e=>(0,X.jsx)(`li`,{children:(0,X.jsxs)(`label`,{className:`filter-row`,children:[(0,X.jsx)(`input`,{type:`checkbox`,checked:t[e.kind],onChange:()=>n(e.kind)}),(0,X.jsx)(`span`,{children:e.label})]})},e.kind))}),(0,X.jsx)(`p`,{className:`filter-note`,children:`A kind that is off still draws and stays in the Component tree and the Net list.`})]})}var Oq=e=>e?.state===`started`||e?.state===`running`||e?.state===`cleanup`,kq=e=>e.state===`done`&&e.entryId!==void 0?e.writeMark:void 0,Aq=`cleanup stopped at its pass cap`,jq=(e,t,n=`${t}s`)=>`${e} ${e===1?t:n}`;function Mq(e){switch(e.state){case`started`:return e.inProcess?`Autorouting in the server process (worker threads are unavailable)…`:`Autorouting…`;case`running`:return`Autorouting: pass ${e.pass}, ${e.done} of ${jq(e.total,`connection`)}`;case`cleanup`:return e.capped?`Autorouting: ${Aq}`:`Autorouting: cleaning up`;case`done`:{if(e.total===0)return`Nothing to route: the scope has no connection left to route`;let t=e.unrouted.length===0?``:`; ${e.unrouted.length} not routed, see Checks`,n=e.cleanupCapped?`; ${Aq}`:``;return`Routed ${e.routed} of ${jq(e.total,`connection`)} in ${jq(e.passes,`pass`,`passes`)}${t}${n}`}case`discarded`:return e.reason;case`cancelled`:return`Autorouting cancelled; nothing was written`;case`failed`:return`Autorouting failed: ${e.error}`}}function Nq({route:e,onCancel:t}){return!e||!Oq(e)?null:(0,X.jsxs)(`div`,{className:`canvas-status route-status`,role:`status`,children:[(0,X.jsx)(`span`,{children:Mq(e)}),(0,X.jsx)(`button`,{className:`unit-toggle`,onClick:e=>{km(e),t()},onPointerDown:e=>e.stopPropagation(),title:`Stop routing; nothing is written`,children:`Cancel`})]})}var Pq=e=>e?.state===`started`||e?.state===`running`,Fq=e=>e.state===`done`&&e.entryId!==void 0?e.writeMark:void 0,Iq=(e,t)=>`${e} ${t}${e===1?``:`s`}`,Lq=e=>String(Math.round(e));function Rq(e){switch(e.state){case`started`:return e.inProcess?`Autoplacing in the server process (worker threads are unavailable)…`:`Autoplacing…`;case`running`:return e.stage===`construct`?`Autoplacing: ${e.done} of ${Iq(e.total,`part`)}`:`Autoplacing: refining, ${Math.round(100*e.done/Math.max(1,e.total))}%`;case`done`:{if(e.placed===0&&e.unplaced.length===0)return`Nothing to place: every part in the scope is placed or locked`;let t=e.unplaced.length===0?``:`; ${e.unplaced.length} not placed (${e.unplaced.map(e=>e.name).join(`, `)})`,n=e.board&&`width`in e.board?`; board ${e.board.width} × ${e.board.height} mm`:``;return`Placed ${Iq(e.placed,`part`)}; wire length ${Lq(e.wireLength)} mm (was ${Lq(e.before)})${n}${t}`}case`discarded`:return e.reason;case`cancelled`:return`Autoplacing cancelled; nothing was written`;case`failed`:return`Autoplacing failed: ${e.error}`}}function zq({place:e,onCancel:t}){return!e||!Pq(e)?null:(0,X.jsxs)(`div`,{className:`canvas-status route-status`,role:`status`,children:[(0,X.jsx)(`span`,{children:Rq(e)}),(0,X.jsx)(`button`,{className:`unit-toggle`,onClick:e=>{km(e),t()},onPointerDown:e=>e.stopPropagation(),title:`Stop placing; nothing is written`,children:`Cancel`})]})}var Bq=[{id:`all`,label:`All`},{id:`copper`,label:`Copper`},{id:`non-copper`,label:`Non-copper`}],Vq=Bq.map(e=>e.id);function Hq({pours:e,onTogglePour:t}){return e.length===0?null:(0,X.jsx)(`ul`,{className:`layer-list layer-pours hairline-t`,"aria-label":`Copper pours`,children:e.map(e=>(0,X.jsxs)(`li`,{children:[(0,X.jsxs)(`div`,{className:`layer-pours-title`,children:[`Copper pours · `,e.name]}),(0,X.jsx)(`ul`,{className:`layer-list`,children:e.pours.map(n=>(0,X.jsxs)(`li`,{className:`layer-row${n.shown?``:` off`}`,children:[(0,X.jsx)(`span`,{className:`layer-swatch`,style:{background:rd[n.layer]??W.topCopper,opacity:.6},"aria-hidden":`true`}),(0,X.jsx)(`span`,{className:`layer-name`,title:n.id,children:n.net}),(0,X.jsx)(`button`,{className:`layer-eye`,"aria-pressed":n.shown,"aria-label":`${n.net} pour on the ${e.name}`,title:`${n.shown?`Hide`:`Show`} the ${n.net} pour`,onClick:()=>t(n.id),children:(0,X.jsx)(ih,{off:!n.shown})})]},n.id))})]},e.layer))})}function Uq({active:e,onActive:t}){return(0,X.jsxs)(`label`,{className:`layer-active hairline-b`,title:`The layer tracks are drawn on (V)`,children:[`Active layer`,(0,X.jsx)(`select`,{value:e,onChange:e=>t(e.target.value),children:Ta.map(e=>(0,X.jsx)(`option`,{value:e.id,children:e.name},e.id))})]})}function Wq({filter:e,onFilter:t}){let n=Nm({ids:Vq,current:e,onSelect:t});return(0,X.jsx)(`div`,{className:`layer-filters hairline-b`,role:`radiogroup`,"aria-label":`Show layers`,onKeyDown:n.onKeyDown,children:Bq.map(({id:t,label:r})=>(0,X.jsx)(`button`,{className:`layer-filter${e===t?` on`:``}`,role:`radio`,"aria-checked":e===t,...n.tab(t),children:r},t))})}function Gq({visibility:e,filter:t,hasKeepouts:n,onFilter:r,onToggle:i,active:a,onActive:o,pours:s,onTogglePour:c}){return(0,X.jsxs)(`aside`,{className:`panel right layer-panel`,id:oD(`right`),role:`tabpanel`,"aria-labelledby":sD(`layer`),onClick:km,children:[(0,X.jsx)(Wq,{filter:t,onFilter:r}),(0,X.jsx)(Uq,{active:a,onActive:o}),(0,X.jsx)(`ul`,{className:`layer-list`,children:Da(n,t).map(t=>{let n=e[t.id];return(0,X.jsxs)(`li`,{className:`layer-row${n?``:` off`}`,children:[(0,X.jsx)(`span`,{className:`layer-swatch`,style:{background:Oa(t)},"aria-hidden":`true`}),(0,X.jsx)(`span`,{className:`layer-name`,children:t.name}),(0,X.jsx)(`button`,{className:`layer-eye`,"aria-pressed":n,"aria-label":t.name,title:`${n?`Hide`:`Show`} ${t.name}`,onClick:()=>i(t.id),children:(0,X.jsx)(ih,{off:!n})})]},t.id)})}),t!==`non-copper`&&(0,X.jsx)(Hq,{pours:s,onTogglePour:c})]})}function Kq(e,t,n,r,i){return t.total>1?XK:n&&r?RE(n,r,e,i):void 0}function qq(e,t){let n=[...e?.pcb.tracks??[],...e?.pcb.vias??[]].filter(e=>t.includes(e.id));return n.length>0&&n.every(e=>e.locked)}function Jq(e){let{circuit:t,design:n,selection:r,onSelect:i,run:a,openProperties:o,onHighlight:s,edit:c}=e,[l,u]=(0,_.useState)(null),d=(0,_.useCallback)((e,t)=>{i(t=>sq(t,e)),u({target:e,at:t})},[i]),f=(0,_.useCallback)(()=>u(null),[]);return{open:(0,_.useMemo)(()=>{if(!l)return null;let e=new Set(t?.annotations.locks.map(e=>e.part)),i=sq(r,l.target),{target:a}=l,o=a.kind===`wire`?Kq(a.id,i,n,t,e):void 0,s=a.kind===`copper`&&qq(n,i.copper),c=a.kind===`copper`&&i.segment?.id===a.id,u=a.kind===`text`?n&&t?Tf(n,t,a.id,e):`It is not on this sheet`:void 0;return{entries:iq(a,{allLocked:oq(i.names,e),selected:i.size,wire:o,copperLocked:s,segment:c,textReset:u}),at:l.at}},[l,t,n,r]),close:f,show:d,runItem:(0,_.useCallback)(e=>{if(e.command)return a(e.command);if(e.special===`properties`)return o();if(e.special===`resetText`&&l?.target.kind===`text`)return void c(xf(l.target.id),`Reset text position`);if(e.special===`rename`&&l?.target.kind===`label`)return void zw.send({kind:`renameLabel`,labelId:l.target.label.id});e.special===`highlightNet`&&l?.target.kind===`label`&&n&&s([Tp(n.circuit.nets,l.target.label.net)])},[a,o,s,c,l,n])}}function Yq(e){return e===`pcb`?[`properties`,`layer`,`filter`]:[`properties`,`filter`]}function Xq(e,t){return e.active!==`layer`||t===`pcb`?e:{...e,active:`properties`}}var Zq={active:`properties`,open:!0},Qq={strip:`design`,sub:`page`,open:!0};function $q(e,t){return e.open&&e.active===t?{...e,open:!1}:{active:t,open:!0}}function eJ(e){return{...e,open:!e.open}}function tJ(e,t){return{active:t,open:!0}}function nJ(e,t){let n=$q({active:e.strip,open:e.open},t);return{...e,strip:n.active,open:n.open}}function rJ(e,t){return{...e,strip:t,open:!0}}function iJ(e){return{strip:`design`,sub:e,open:!0}}function aJ(e){return{...e,strip:`library`,open:!0}}function oJ(e){return{...e,open:!e.open}}var sJ=[{id:`design`,label:`Project Design`},{id:`library`,label:`Common Library`}],cJ={properties:`Properties`,layer:`Layer`,filter:`Filter`},lJ=e=>Yq(e).map(e=>({id:e,label:cJ[e]}));function uJ({data:e,workspace:t,checks:n,selection:r,onSelect:i,actions:a,onOpenSheet:o},s){let{build:c,circuit:l}=e;if(c.design&&l)return{design:c.design,buildId:c.finishedAt,buildStatus:c.status,builtMark:c.startMark,project:e.project,builtFrom:c.startedAt?Date.parse(c.startedAt):-1/0,circuit:l,actions:a,selection:r,onSelect:i,highlight:t.highlight,onHighlight:t.setHighlight,unit:t.unit,onToggleUnit:t.toggleUnit,activeViolation:n.active,focus:n.focus,onFocused:n.focused,layers:t.layerVisibility,pickFilter:t.pickFilter,onContextMenu:s,onOpenSheet:o,onOpenProperties:e=>{i(t=>e.kind===`wire`?t.onlyWire(e.id):e.kind===`drawing`?t.onlyDrawing(e.id):t.only(e.name)),t.openProperties()}}}function dJ(e,t){return{gridStyle:e.gridStyles[t],gridStep:e.gridSteps[t],snap:e.snap,onGridStep:n=>e.changeGridStep(t,n),theme:e.theme,hoverLabels:e.hoverLabels}}function fJ(e,t){let n=e?.design,r=e?.actions,i=(0,_.useMemo)(()=>n?Pv(n,t):void 0,[n,t]),a=(0,_.useMemo)(()=>r?{...r,edit:(e,n)=>r.edit(xS(e,t),n),editMarked:(e,n)=>r.editMarked(xS(e,t),n)}:void 0,[r,t]);return e&&i&&a?{...e,design:i,actions:a}:void 0}function pJ({sheetParent:e,onOpenDocument:t}){return e?{parent:e.file,onParent:n=>t(e.file,n)}:{}}function mJ(e){let{data:t,workspace:n,checks:r,find:i,view:a,page:o}=e,{build:s}=t,c=uJ(e,e.onContextMenu),l=fJ(c,o),u=(0,_.useMemo)(()=>Mv(s.design),[s.design]),d=_V(),[f,p]=(0,_.useState)(!1),m=f&&a===`pcb`;return(0,X.jsxs)(`div`,{className:`center`,children:[(0,X.jsx)(Eq,{file:t.file,view:a,pages:u,page:o,onView:e.onView,onPage:e.onPage,look:m,onLook:p,...pJ(e)}),(0,X.jsx)(`div`,{className:`ai-lock-band`,children:e.lockControl}),(0,X.jsxs)(`section`,{className:e.aiLocked?`canvas ai-locked`:`canvas`,id:`doc-panel`,role:`tabpanel`,"aria-labelledby":m?`doc-tab-3d`:`doc-tab-${a}`,tabIndex:-1,children:[!s.design&&(0,X.jsx)(`p`,{className:`empty`,children:s.status===`failed`?s.error:`Building the circuit…`}),d&&(0,X.jsx)(ZV,{state:d}),!d&&m&&s.design&&(0,X.jsx)(UK,{design:s.design}),!d&&!m&&c&&a===`pcb`&&(0,X.jsx)(ZI,{...c,...dJ(n,`pcb`),markers:r.markers.pcb,activeLayer:n.activeLayer,onActiveLayer:n.setActiveLayer,pourFill:n.pourFill,hiddenPours:n.hiddenPours},t.file),!d&&l&&a===`schematic`&&(0,X.jsx)(AB,{...l,...dJ(n,`schematic`),markers:r.markers.schematic},`${t.file}
|
|
20
|
-
${o}`),(0,X.jsx)(Nq,{route:t.route,onCancel:()=>void e.actions.cancelRoute()}),(0,X.jsx)(zq,{place:t.place,onCancel:()=>void e.actions.cancelAutoplace()}),i.box.open&&(0,X.jsx)(MB,{text:i.box.text,seq:i.box.seq,onText:i.setText,onSearch:i.search,onClose:i.close,status:IB(i.results.query,i.results.rows.length)})]}),n.bottom.open&&(0,X.jsx)(AV,{tab:n.bottom.tab,parts:t.parts,onPlace:e.onPlace,history:t.history,historyProblems:t.historyProblems,actions:e.actions,built:s.design!==void 0,buildError:s.status===`failed`?s.error??`The build failed.`:void 0,rows:r.rows,counts:r.counts,active:r.active,onPick:r.pick,find:i.results})]})}function hJ({data:e,workspace:t,view:n,page:r,selection:i,onSelect:a,actions:o,onPlace:s,onImportPart:c,onNewPart:l,onOpenDocument:u}){let{circuit:d,build:f,project:p,files:m,sheets:h,file:g}=e,v=(0,_.useMemo)(()=>yq(p,[...m,...h],g,n,{names:Mv(f.design),open:r}),[p,m,h,g,n,f.design,r]),y=(0,_.useMemo)(()=>Qe(f.design,n),[f.design,n]);return d?(0,X.jsx)(pD,{circuit:d,parts:e.parts,onPlace:s,onImport:c,onNewPart:l,selection:i,onSelect:a,actions:o,design:f.design,autoPlaced:y,left:t.left,onSub:t.showSub,pageTree:v,onOpenDocument:u,focusSearch:t.focusSearch,onSearchFocused:t.searchFocused,focusPage:t.focusPage,onPageFocused:t.pageFocused,highlight:t.highlight,onHighlight:t.setHighlight,hidden:!t.leftOpen}):null}function gJ({data:e,workspace:t,checks:n,selection:r,onSelect:i,onRenameDrawing:a,actions:o,run:s,openChecks:c,view:l,onOpenSheet:u,sheetParent:d}){if(!e.circuit)return null;let{right:f}=t,p=f.open&&f.active===`layer`,m=f.open&&f.active===`filter`,h=e.build.design?.pcb.board?.keepouts??[],g=e.build.design,_=g?ja(g.pcb.board?.pours??[],e=>Fu(g,e),t.hiddenPours):[];return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(SD,{circuit:e.circuit,build:e.build,parts:e.parts,openView:l,selection:r,onSelect:i,onRenameDrawing:a,actions:o,run:s,counts:n.counts,onShowChecks:c,hidden:!f.open||f.active!==`properties`,focusField:t.focusField,onFieldFocused:t.fieldFocused,onOpenSheet:u,parentDesign:d?.design}),p&&(0,X.jsx)(Gq,{visibility:t.layerVisibility,filter:t.layerFilter,hasKeepouts:h.length>0,onFilter:t.setLayerFilter,onToggle:t.toggleLayerShown,active:t.activeLayer,onActive:t.setActiveLayer,pours:_,onTogglePour:t.togglePourShown}),m&&(0,X.jsx)(Dq,{view:l,filter:t.pickFilter,onToggle:t.togglePickable})]})}function _J(e){let{data:t,workspace:n,selection:r,onSelect:i}=e,a=Jq({circuit:t.circuit,design:t.build.design,selection:r,onSelect:i,run:e.run,openProperties:n.openProperties,edit:e.actions.edit,onHighlight:n.setHighlight});return(0,X.jsxs)(`main`,{className:`workspace`,children:[(0,X.jsx)(cD,{side:`left`,tabs:sJ,active:n.left.strip,open:n.left.open,onClick:n.clickLeft,onSelect:n.selectLeft}),(0,X.jsx)(hJ,{...e}),(0,X.jsx)(mJ,{...e,onContextMenu:a.show}),(0,X.jsx)(gJ,{...e}),(0,X.jsx)(cD,{side:`right`,tabs:lJ(e.view),active:n.right.active,open:n.right.open,onClick:n.clickRight,onSelect:n.selectRight}),a.open&&(0,X.jsx)(gq,{entries:a.open.entries,at:a.open.at,onRun:a.runItem,onClose:a.close})]})}function vJ({file:e,refresh:t,notify:n,openVerify:r}){let i=(0,_.useCallback)(async r=>{try{return await r(),!0}catch(e){return n(e.message),!1}finally{e&&await t(e).catch(()=>void 0)}},[e,t,n]),a=(0,_.useCallback)(async(e,t)=>{let n;return{ok:await i(async()=>{n=(await B(e,t)).writeMark}),mark:n}},[i]),o=(0,_.useCallback)((t,n)=>a(`/api/edit`,{file:e,edits:t,summary:n}),[e,a]),s=(0,_.useCallback)((t,n,r)=>a(`/api/layout`,{file:e,edits:t,summary:n,...r?{sheet:r}:{}}),[e,a]);return(0,_.useMemo)(()=>({edit:async(e,t)=>(await o(e,t)).ok,editMarked:o,editFile:(e,t,n)=>a(`/api/edit`,{file:e,edits:t,summary:n}),editLayout:s,renameParts:(t,n)=>XN(a(`/api/rename-parts`,{file:e,mapping:t,summary:n})),lock:(t,n)=>i(()=>B(`/api/lock`,{file:e,parts:t,locked:n})),mark:(t,n)=>i(()=>B(`/api/mark`,{file:e,text:t,...n})),unmark:t=>i(()=>B(`/api/unmark`,{file:e,id:t})),undo:e=>XN(a(`/api/undo`,e?{id:e}:{})),redo:e=>XN(a(`/api/redo`,e?{id:e}:{})),openVerify:r,makeSheet:t=>i(async()=>{n(Wh((await B(`/api/make-sheet`,{file:e,...t})).preview,t.parts.length))}),route:async t=>{try{return await B(`/api/route`,{file:e,scope:t}),!0}catch(e){return n(e.message),!1}},cancelRoute:async()=>{try{return(await B(`/api/route/cancel`,{})).cancelled}catch(e){return n(e.message),!1}},autoplace:async t=>{try{return await B(`/api/autoplace`,{file:e,scope:t}),!0}catch(e){return n(e.message),!1}},cancelAutoplace:async()=>{try{return(await B(`/api/autoplace/cancel`,{})).cancelled}catch(e){return n(e.message),!1}},fitBoard:()=>XN((async()=>{let t;return{ok:await i(async()=>{let r=await B(`/api/fit-board`,{file:e});t=r.writeMark,n(r.summary)}),mark:t}})()),importBoard:(t,r)=>XN((async()=>{let a;return{ok:await i(async()=>{let i=await B(`/api/import-board`,{file:e,name:t,text:r});a=i.writeMark,n(i.summary)}),mark:a}})()),importKicad:async(t,r)=>{let a;return await i(async()=>{let i=await B(`/api/import-board`,{file:e??``,name:t,text:r});a=i.file,n(i.summary)}),a},unroute:t=>XN((async()=>{let r;return{ok:await i(async()=>{let i=await B(`/api/unroute`,{file:e,...t?{ids:t}:{}});r=i.writeMark,n(i.summary)}),mark:r}})()),setFilletRadius:t=>i(async()=>{let r=await B(`/api/rules`,{filletRadius:t,...e?{file:e}:{}});r.writeMark!==void 0&&kM({radius:t,mark:r.writeMark}),n(r.summary)}),notify:n}),[e,i,n,o,s,a,r])}function yJ({file:e,refresh:t,notify:n},r,i=`Main`){return(0,_.useCallback)(a=>{let o=vV[a];B(`/api/place`,{file:e,part:a,...o?{props:o}:{},...i===`Main`?{}:{page:i}}).then(e=>{r(e.name),n(`Placed ${e.name}${o?` with a starting value; change it on the right`:``}. Drag it into position on the PCB.`)}).catch(e=>n(e.message)).finally(()=>{e&&t(e).catch(()=>void 0)})},[e,t,n,r,i])}function bJ(e,t){return e===0&&t>0}function xJ(e){let t=e.view===`code`?void 0:e.view;return{...t?{tab:t}:{},...t&&e.at?{focus:{view:t,at:e.at}}:{},...e.copper?.length||e.board?.length?{selectCopper:e.copper??[],...e.board?.length?{selectBoard:e.board}:{}}:e.part?{select:e.part}:{}}}function SJ({file:e,build:t,route:n,onTab:r,onSelect:i,onSelectCopper:a,onOpen:o}){let s=t.design,c=(0,_.useMemo)(()=>s?ow(s,n):[],[s,n]),l=(0,_.useMemo)(()=>lw(c),[c]),u=(0,_.useMemo)(()=>({pcb:cw(c,`pcb`),schematic:cw(c,`schematic`)}),[c]),[d,f]=(0,_.useState)(null),[p,m]=(0,_.useState)(null);return CJ(e,t,l.errors,o),{rows:c,counts:l,markers:u,active:d,focus:p,pick:(0,_.useCallback)(e=>{let t=xJ(e);f(e.id),t.tab&&r(t.tab),t.focus&&m(t.focus),t.select&&i(t.select),t.selectCopper&&a(t.selectCopper,t.selectBoard??[])},[r,i,a]),focused:(0,_.useCallback)(()=>m(null),[]),requestFocus:m}}function CJ(e,t,n,r){let i=(0,_.useRef)(void 0);(0,_.useEffect)(()=>{i.current=void 0},[e]);let a=t.status===`done`?t.finishedAt:void 0;(0,_.useEffect)(()=>{a!==void 0&&(bJ(i.current,n)&&r(),i.current=n)},[a,n,r])}var wJ={open:!1,text:``,seq:0};function TJ({file:e,circuit:t,library:n,design:r,view:i,onSelect:a,onHighlight:o,requestFocus:s,openResults:c}){let[l,u]=(0,_.useState)(wJ),[d,f]=(0,_.useState)(null),[p,m]=(0,_.useState)(null),h=t?.model.parts,g=(0,_.useMemo)(()=>d===null?[]:GB(d,h??[],r?RB(r):[],n),[d,h,r,n]);return(0,_.useEffect)(()=>{f(null),m(null)},[e]),{box:l,open:(0,_.useCallback)(()=>u(e=>({...e,open:!0,seq:e.seq+1})),[]),close:(0,_.useCallback)(()=>u(e=>({...e,open:!1})),[]),setText:(0,_.useCallback)(e=>u(t=>({...t,text:e})),[]),search:(0,_.useCallback)(e=>{let t=e.trim();t!==``&&(f(t),m(null),c())},[c]),results:{query:d,rows:g,active:p,pick:(0,_.useCallback)(e=>{let t=qB(e,r,i);if(m(e.id),t.select){let e=t.select;a(t=>t.only(e))}t.focus&&s(t.focus),t.highlight&&o(t.highlight)},[r,i,a,o,s])}}}function EJ(e,t,n){let[r,i]=(0,_.useState)([]),[a,o]=(0,_.useState)([]),[s,c]=(0,_.useState)();return(0,_.useEffect)(()=>{B(`/api/circuits`).then(e=>{i(e),t(t=>t??e[0])}).catch(t=>e(t.message)),B(`/api/sheets`).then(o).catch(t=>e(t.message)),B(`/api/project`).then(e=>c(e.name)).catch(t=>e(t.message)),n().catch(t=>e(t.message))},[e,t,n]),{files:r,sheets:a,project:s,refreshFiles:(0,_.useCallback)(()=>B(`/api/circuits`).then(i),[])}}function DJ(e,t){let[n,r]=(0,_.useState)(),[i,a]=(0,_.useState)(),[o,s]=(0,_.useState)({status:`idle`}),[c,l]=(0,_.useState)([]),[u,d]=(0,_.useState)([]),[f,p]=(0,_.useState)({library:[],builtin:[]}),[m,h]=(0,_.useState)(),[g,v]=(0,_.useState)(),[y,b]=(0,_.useState)(!1),S=(0,_.useCallback)(e=>b(!e),[]),C=(0,_.useCallback)(t=>{x(t)&&s({status:`failed`,error:t}),e(t)},[e]),w=(0,_.useCallback)(async e=>{let[t,n]=await Promise.all([B(`/api/circuit?file=${encodeURIComponent(e)}`),B(`/api/history?limit=30`).catch(e=>({entries:[],problems:[{file:`history`,reason:e.message}]}))]);a(t),l(n.entries),d(n.problems)},[]),T=(0,_.useCallback)(async()=>{p(await B(`/api/parts`))},[]),E=(0,_.useCallback)(async e=>{let t=await B(`/api/build?file=${encodeURIComponent(e)}`);s(e=>t.status===`building`&&e.design?{...t,design:e.design}:t)},[]),{files:D,sheets:O,project:k,refreshFiles:A}=EJ(C,r,T),j=(0,_.useCallback)(t=>{if(h(t),Oq(t))return;e(Mq(t));let n=kq(t);n!==void 0&&(XN(Promise.resolve({ok:!0,mark:n})),w(t.file).catch(e=>C(e.message)))},[e,w,C]),M=(0,_.useCallback)(t=>{if(v(t),Pq(t))return;e(Rq(t));let n=Fq(t);n!==void 0&&(XN(Promise.resolve({ok:!0,mark:n})),w(t.file).catch(e=>C(e.message)))},[e,w,C]);return(0,_.useEffect)(()=>{if(n)return t(),h(void 0),v(void 0),w(n).catch(e=>C(e.message)),B(`/api/build`,{file:n}).then(()=>E(n)).catch(e=>C(e.message)),ge((e,t,r)=>{if(e===`library`)T().catch(e=>C(e.message));else if(t===n){if(e===`route`)return j(r);if(e===`place`)return M(r);(e===`change`?w(n):E(n)).catch(e=>C(e.message))}},S)},[n,w,E,T,C,t,j,M,S]),{files:D,sheets:O,project:k,file:n,setFile:r,circuit:i,build:o,history:c,historyProblems:u,parts:f,route:m,place:g,serverGone:y,refresh:w,refreshParts:T,refreshFiles:A}}function OJ(e,t,n,r){let[i,a]=(0,_.useState)(),o=(0,_.useRef)(void 0);(0,_.useEffect)(()=>ce.listen(r),[r]),(0,_.useEffect)(()=>{if(!t)return;let n=e[0];(n?.id!==o.current||i===void 0)&&(o.current=n?.id,a(e=>e===void 0?te(n?.author):n?N(e,n.author):e))},[e,t,i]);let s=i?.closed??!1;return(0,_.useLayoutEffect)(()=>ce.set(s),[s]),kJ(s,n),{closed:s,toggle:(0,_.useCallback)(()=>a(e=>ne(e??te(void 0))),[])}}function kJ(e,t){(0,_.useEffect)(()=>{if(!e)return;let n=e=>{let n=Yd(Pd(e),{view:t})?.action;n!==void 0&&I(n)&&(e.preventDefault(),e.stopImmediatePropagation(),ce.refuses())};return window.addEventListener(`keydown`,n,!0),()=>window.removeEventListener(`keydown`,n,!0)},[e,t])}function AJ({closed:e,onToggle:t}){let{title:n,hint:r}=ae(e),i=e?Zm:Qm,a=e?34:16;return(0,X.jsxs)(`button`,{type:`button`,className:e?`ai-lock closed`:`ai-lock`,"aria-pressed":e,"aria-label":`AI lock: ${n}. ${r}`,title:r,onClick:t,children:[(0,X.jsx)(i,{className:`ai-lock-icon`,width:a,height:a}),(0,X.jsxs)(`span`,{className:`ai-lock-words`,children:[(0,X.jsx)(`span`,{className:`ai-lock-title`,children:n}),(0,X.jsx)(`span`,{className:`ai-lock-hint`,children:r})]})]})}var jJ=`copperflow.hoverLabels`,MJ=`off`,NJ=`on`;function PJ(e){try{return e()?.getItem(jJ)!==MJ}catch{return!0}}function FJ(e,t){try{let n=e();return n?(n.setItem(jJ,t?NJ:MJ),!0):!1}catch{return!1}}var IJ=`copperflow.system`,LJ={unit:`mm`,grid:{schematic:ug,pcb:cg}},RJ=(e,t,n)=>typeof e==`number`&&t.includes(e)?e:n;function zJ(e){let t={};try{t=e?JSON.parse(e):{}}catch{t={}}let n=typeof t.grid==`object`&&t.grid!==null?t.grid:{};return{unit:t.unit===`mil`?`mil`:`mm`,grid:{schematic:RJ(n.schematic,lg,ug),pcb:RJ(n.pcb,sg,cg)}}}function BJ(e){try{return zJ(e()?.getItem(IJ))}catch{return LJ}}function VJ(e,t){try{let n=e();return n?(n.setItem(IJ,JSON.stringify({unit:t.unit,grid:t.grid})),!0):!1}catch{return!1}}function HJ(){let[e,t]=(0,_.useState)(ka),[n,r]=(0,_.useState)(`all`),[i,a]=(0,_.useState)(`top`),o=(0,_.useCallback)(e=>t(t=>Ma(t,e)),[]),[s,c]=(0,_.useState)(()=>new Set);return{layerVisibility:e,layerFilter:n,setLayerFilter:r,toggleLayerShown:o,activeLayer:i,setActiveLayer:a,hiddenPours:s,togglePourShown:(0,_.useCallback)(e=>c(t=>Aa(t,e)),[])}}function UJ(){let[e,t]=(0,_.useState)(La);return{pickFilter:e,togglePickable:(0,_.useCallback)(e=>t(t=>Ra(t,e)),[])}}var WJ=new Set([`toggleLeftPanel`,`toggleRightPanel`,`toggleBottomPanel`,`toggleUnit`,`clearHighlight`,`openLibrary`,`toggleSnap`]);function GJ(e){let[t,n]=(0,_.useState)(Qq),[r,i]=(0,_.useState)(Zq),a=Xq(r,e),[o,s]=(0,_.useState)(bm);return{left:t,setLeft:n,right:a,setRight:i,bottom:o,setBottom:s,clickLeft:(0,_.useCallback)(e=>n(t=>nJ(t,e)),[]),selectLeft:(0,_.useCallback)(e=>n(t=>rJ(t,e)),[]),clickRight:(0,_.useCallback)(t=>i(n=>$q(Xq(n,e),t)),[e]),selectRight:(0,_.useCallback)(e=>i(t=>tJ(t,e)),[]),clickBottomTab:(0,_.useCallback)(e=>s(t=>xm(t,e)),[]),openBottom:(0,_.useCallback)(e=>s(t=>Cm(t,e)),[]),showSub:(0,_.useCallback)(e=>n(iJ(e)),[])}}function KJ(){let[e,t]=(0,_.useState)(!1);return[e,(0,_.useCallback)(()=>t(!0),[]),(0,_.useCallback)(()=>t(!1),[])]}function qJ(e){let[t,n]=(0,_.useState)(()=>Zv(pg,e)),[r,i]=(0,_.useState)(()=>BJ(Uv).grid);return{gridStyles:t,gridSteps:r,setGridSteps:i,changeGridStep:(0,_.useCallback)((e,t)=>i(n=>dg(n,e,t)),[]),toggleGridStyleOf:(0,_.useCallback)(e=>n(t=>hg(t,e)),[]),gridFollowsTheme:(0,_.useCallback)((e,t)=>n(n=>Xv(n,e,t)),[])}}function JJ(){let[e,t]=(0,_.useState)(()=>Gv(Uv));(0,_.useEffect)(()=>qv(document.documentElement,e),[e]);let{gridFollowsTheme:n,...r}=qJ(e),i=(0,_.useRef)(e);return{theme:e,setTheme:(0,_.useCallback)(e=>{n(i.current,e),i.current=e,t(e),Kv(Uv,e)},[n]),grid:r}}function YJ(){let[e,t]=(0,_.useState)(!0);return{snap:e,toggleSnap:(0,_.useCallback)(()=>t(e=>!e),[])}}function XJ(){let[e,t]=(0,_.useState)(()=>PJ(Uv)),n=(0,_.useRef)(!0);return(0,_.useEffect)(()=>{n.current?n.current=!1:FJ(Uv,e)},[e]),{hoverLabels:e,setHoverLabels:t,toggleHoverLabels:(0,_.useCallback)(()=>t(e=>!e),[])}}function ZJ(){let[e,t]=(0,_.useState)(()=>$u(Uv));return{pourFill:e,setPourFill:(0,_.useCallback)(e=>{t(e),ed(Uv,e)},[])}}function QJ(e,t){(0,_.useEffect)(()=>{let n=n=>{let r=Yd(Pd(n),{view:e});r&&WJ.has(r.action)&&(r.preventDefault&&n.preventDefault(),t(r.action))};return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[e,t])}function $J(e,t){let[n,r,i]=KJ(),[a,o,s]=KJ(),[c,l,u]=KJ();return{focusSearch:n,requestSearch:r,searchFocused:i,focusPage:a,pageFocused:s,openPageTree:(0,_.useCallback)(()=>{e(iJ(`page`)),o()},[e,o]),focusField:c,fieldFocused:u,openProperties:(0,_.useCallback)(()=>{t(e=>tJ(e,`properties`)),l()},[t,l])}}function eY(e,{strips:t,setUnit:n,setHighlight:r,toggleGridStyleOf:i,toggleSnap:a,requestSearch:o}){let{setLeft:s,setRight:c,setBottom:l}=t,u=(0,_.useRef)(e);return u.current=e,(0,_.useCallback)(e=>{e===`toggleLeftPanel`&&s(oJ),e===`toggleRightPanel`&&c(eJ),e===`toggleBottomPanel`&&l(Sm),e===`toggleUnit`&&n(tg),e===`toggleGridStyle`&&i(u.current),e===`toggleSnap`&&a(),e===`clearHighlight`&&r(Ep),e===`openLibrary`&&(s(aJ),o())},[s,c,l,n,r,o,i,a])}function tY(e){let{setLeft:t,setRight:n,setBottom:r,...i}=GJ(e),{requestSearch:a,...o}=$J(t,n),[s,c]=(0,_.useState)(()=>BJ(Uv).unit),[l,u]=(0,_.useState)(Ep),{theme:d,setTheme:f,grid:p}=JJ(),{toggleGridStyleOf:m,setGridSteps:h,...g}=p,{snap:v,toggleSnap:y}=YJ(),{hoverLabels:b,setHoverLabels:x,toggleHoverLabels:S}=XJ(),{pourFill:C,setPourFill:w}=ZJ(),T=HJ(),E=UJ(),D=eY(e,{strips:{setLeft:t,setRight:n,setBottom:r},setUnit:c,setHighlight:u,toggleGridStyleOf:m,toggleSnap:y,requestSearch:a});QJ(e,D);let O=(0,_.useCallback)(()=>c(tg),[]),k=(0,_.useCallback)(e=>{f(e.theme),c(e.unit),h(e.grid),x(e.hoverLabels),VJ(Uv,e)},[f,h,x]);return{...i,...g,theme:d,setTheme:f,applySystem:k,snap:v,hoverLabels:b,toggleHoverLabels:S,pourFill:C,setPourFill:w,...T,...E,...o,leftOpen:i.left.open,unit:s,toggleUnit:O,highlight:l,setHighlight:u,run:D}}function nY(){let[e,t]=(0,_.useState)(null);return{message:e,notify:(0,_.useCallback)(e=>{t(e),window.setTimeout(()=>t(t=>t===e?null:t),6e3)},[]),dismiss:(0,_.useCallback)(()=>t(null),[])}}function rY(e){(0,_.useEffect)(()=>{let t=t=>{let n=t.target instanceof HTMLElement&&t.target.closest(`input, textarea, select`);t.key===`Escape`&&!n&&e(e=>e.clear())};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e])}function iY(e,t){let n=(0,_.useRef)([]);(0,_.useEffect)(()=>{if(!e)return;let r=e.model.parts.map(e=>e.name),i=xo(n.current,r);n.current=r,i.length>0&&t(e=>e.without(i))},[e,t])}function aY(e,t){let n=(0,_.useRef)(void 0),r=(0,_.useRef)([]);return(0,_.useEffect)(()=>{if(!e||e===n.current)return;let i=n.current;n.current=e;let a=e.schematic.drawings,o=r.current;r.current=Bp(_o.none,o,a).waiting,t(t=>{let n=Bp(am(t.wireCount===0?t:hm(t,i&&dm(i.schematic),dm(e.schematic)),i,e),o,a).selection;return Vp(n,i?.schematic.drawings,a)})},[e,t]),{seen:n,onRenameDrawing:(0,_.useCallback)(e=>(r.current=[...r.current,e],()=>{r.current=r.current.filter(t=>t!==e)}),[])}}function oY(e,t,n,r,i){return(0,_.useMemo)(()=>{let a=r===`pcb`?n?.circuit.components.filter(e=>e.instance!==void 0).map(e=>e.id)??[]:[],o=t&&[...t.model.parts.map(e=>e.name),...a],s=n?.schematic,c=e=>e?.map(e=>e.id),l=s&&zp(i?.schematic.drawings,s.drawings),u=n&&[...n.pcb.tracks,...n.pcb.vias].map(e=>e.id),d=n&&[...n.pcb.board?.pours??[],...n.pcb.holes??[]].map(e=>e.id),f=n&&c(r===`pcb`?pf(n.pcb):r===`schematic`?df(n.schematic):[]);return gm(e,{view:r,parts:o,wires:c(s?.wires),labels:c(s?.labels),drawings:l,copper:u,texts:f,board:d})},[e,t,n,r,i])}function sY(e,t){let n=(0,_.useRef)(void 0);(0,_.useEffect)(()=>{let r=n.current;n.current=e,e&&e!==r&&t(t=>Mp(t,r,e))},[e,t])}function cY(){return(0,X.jsxs)(`p`,{className:`empty`,children:[`Open the address that `,(0,X.jsx)(`code`,{children:`copperflow studio`}),` printed in the terminal. It contains a key for this session.`]})}function lY(e,t,n){return DJ(e,(0,_.useCallback)(()=>{t(_o.none),n(Ep)},[t,n]))}function uY({data:e,tab:t,setTab:n,select:r,selectOnly:i,workspace:a}){let{file:o,build:s}=e,{setHighlight:c,openBottom:l}=a,u=(0,_.useCallback)(()=>l(`drc`),[l]),d=(0,_.useCallback)((e,t)=>r(()=>_o.none.all([],[],[],[],e).addBoard(t)),[r]),f=SJ({file:o,build:s,route:e.route,onTab:n,onSelect:i,onSelectCopper:d,onOpen:u}),p=(0,_.useCallback)(()=>l(`find`),[l]);return{checks:f,find:TJ({file:o,circuit:e.circuit,library:e.parts.library,design:s.design,view:t,onSelect:r,onHighlight:c,requestFocus:f.requestFocus,openResults:p}),openChecks:u}}function dY(){let e=nY(),[t,n]=(0,_.useState)(_o.none),r=(0,_.useCallback)(e=>n(t=>t.only(e)),[]),[i,a]=(0,_.useState)(`pcb`),[o,s]=(0,_.useState)(null),[c,l]=(0,_.useState)(),u=(0,_.useCallback)((e,t)=>l({id:e,title:t}),[]),d=(0,_.useCallback)(()=>l(void 0),[]),f=tY(i),p=lY(e.notify,n,f.setHighlight),{file:m,setFile:h,build:g,circuit:v}=p;iY(v,n);let{seen:y,onRenameDrawing:b}=aY(g.design,n),x=oY(t,v,g.design,i,y.current),S=vJ({file:m,refresh:p.refresh,notify:e.notify,openVerify:u}),[C,w]=(0,_.useState)(jv),T=Nv(g.design,C),E=yJ({file:m,refresh:p.refresh,notify:e.notify},r,i===`schematic`?T:jv),{checks:D,find:O,openChecks:k}=uY({data:p,tab:i,setTab:a,select:n,selectOnly:r,workspace:f});rY(n),sY(g.design,f.setHighlight);let A=(0,_.useCallback)(()=>s(null),[]),j=(0,_.useCallback)(()=>s(`importPart`),[]),M=(0,_.useCallback)(()=>s(`newPart`),[]),[ee,te]=(0,_.useState)(),ne=(0,_.useCallback)((e,t,n)=>{n===void 0?e!==m&&w(jv):w(n),it(e)?te(e=>m&&!it(m)?{file:m,design:g.design}:e):te(void 0),h(e),a(it(e)?`schematic`:t)},[h,m,g.design]),N=(0,_.useCallback)(e=>ne(e,`schematic`),[ne]),P=(0,_.useCallback)(e=>{w(e),a(`schematic`)},[]),F=g.design?.pcb,re=(0,_.useMemo)(()=>i===`pcb`&&F?Ia(F.parts,f.layerVisibility):void 0,[i,F,f.layerVisibility]),I=(0,_.useMemo)(()=>g.design?Pv(g.design,T).schematic:void 0,[g.design,T]),L={sheetWires:(0,_.useMemo)(()=>i===`schematic`&&I?I.wires.map(e=>e.id):[],[i,I]),sheetLabels:(0,_.useMemo)(()=>i===`schematic`&&I?I.labels.map(e=>e.id):[],[i,I]),sheetDrawings:(0,_.useMemo)(()=>i===`schematic`&&I?I.drawings.map(e=>e.id):[],[i,I]),pcbCopper:(0,_.useMemo)(()=>i===`pcb`&&F?mu(F,f.layerVisibility).map(({kind:e,id:t})=>({kind:e,id:t})):[],[i,F,f.layerVisibility]),copperRecords:i===`pcb`?F:void 0},R=OJ(p.history,v!==void 0,i,e.notify),z=KC({file:m,openImported:(0,_.useCallback)(e=>void p.refreshFiles().then(()=>ne(e,`pcb`)),[p,ne]),view:i,setView:a,selection:x,select:n,circuit:v,actions:S,pickLayers:re,pickFilter:f.pickFilter,...L,workspace:f,openChecks:k,checkCounts:D.counts,openFind:O.open,openDialog:s,design:g.design,page:T,openPage:P,highlight:f.highlight}),ie=_V()!==void 0;return{verifying:c,closeVerify:d,aiLock:R,toast:e,tab:i,setTab:a,dialog:o,closeDialog:A,openImportPart:j,openNewPart:M,workspace:f,data:p,selection:x,select:n,onRenameDrawing:b,actions:S,place:E,checks:D,find:O,openChecks:k,openDocument:ne,openSheet:N,sheetParent:ee,runCommand:(0,_.useCallback)(t=>ie&&oe(t)?e.notify(tV):R.closed&&oe(t)?void ce.refuses():z(t),[R.closed,ie,z,e.notify]),page:T,openPage:P}}function fY(e){return(0,_.useMemo)(()=>{let t=$e(e);return t===null?{}:{tidySheet:t}},[e])}function pY(e,t){return(0,_.useMemo)(()=>({import:async n=>{let r=await B(`/api/import-part`,n);return await e(),t(Oh(r)),r}}),[e,t])}function mY(e,t){return(0,_.useMemo)(()=>({create:async n=>{let r=await B(`/api/create-part`,n);return await e(),t(ov(r)),r}}),[e,t])}function hY(e,t,n){return(0,_.useMemo)(()=>({create:async r=>{try{let i=await B(`/api/new-circuit`,r);return await e(),t(i.file,`schematic`),n(`Created ${i.file}; Undo removes it again`),!0}catch(e){return n(e.message),!1}}}),[e,t,n])}function gY(e,t,n){return(0,_.useMemo)(()=>{let r=new Set(t?.annotations.locks.filter(e=>!e.drawing).map(e=>e.part));return{source:e&&t?{components:e.circuit.components,parts:t.model.parts,locked:r}:void 0,write:n.edit}},[e,t,n])}function _Y(e,t,n,r){return(0,_.useMemo)(()=>({question:Ky(t),showChecks:n,exportAnyway:()=>NC(e,r)}),[e,t,n,r])}function vY(e,t,n){return(0,_.useMemo)(()=>({parts:t,preview:n=>B(`/api/make-sheet`,{file:e,parts:t,...n,preview:!0}),make:e=>n.makeSheet({parts:t,...e})}),[e,t,n])}function yY(){let{verifying:e,closeVerify:t,aiLock:n,toast:r,tab:i,setTab:a,dialog:o,closeDialog:s,openImportPart:c,openNewPart:l,workspace:u,data:d,selection:f,select:p,onRenameDrawing:m,actions:h,place:g,checks:v,find:y,openChecks:b,openDocument:x,openSheet:S,sheetParent:C,runCommand:w,page:T,openPage:E}=dY(),{build:D,circuit:O}=d,{message:k,dismiss:A}=r,j={snap:u.snap,hoverLabels:u.hoverLabels,...Jv(u.theme),...td(u.pourFill)},M=fY(D.design),ee=_V()!==void 0,te=(0,_.useMemo)(()=>({...M,...F(n.closed),...aV(ee)}),[M,n.closed,ee]),ne=vY(d.file,f.names,h),N=pY(d.refreshParts,r.notify),P=mY(d.refreshParts,r.notify),re=av(d.refreshParts),I=hY(d.refreshFiles,x,r.notify),L=gY(D.design,O,h),R=_Y(d.file,v.counts,b,h),z={settings:{theme:u.theme,unit:u.unit,grid:u.gridSteps,hoverLabels:u.hoverLabels},apply:u.applySystem};return(0,_.useEffect)(()=>zm(window),[]),pe?(0,X.jsxs)(`div`,{className:`app`,children:[(0,X.jsx)(Av,{run:w,view:i,selected:f.size,toggles:j,off:te,children:(0,X.jsx)(Bv,{build:D,errors:v.counts.errors,onOpen:b})}),(0,X.jsx)(My,{view:i,unit:u.unit,selected:f.size,toggles:j,off:te,run:w}),o&&(0,X.jsx)(y_,{name:o,onClose:s,rules:{fabrication:D.design?.rules.fabrication,save:h.setFilletRadius},makeSheet:ne,importPart:N,newPart:P,system:z,newCircuit:I,footprints:L,exportChecks:R}),e&&(0,X.jsx)(b_,{target:e,panel:re,onClose:t}),d.serverGone&&(0,X.jsx)(`div`,{className:`banner`,role:`alert`,children:`The copperflow Studio server is not answering. Start "copperflow studio" again in the project folder, then reload this page.`}),O&&O.violations.length>0&&(0,X.jsxs)(`div`,{className:`banner`,role:`alert`,children:[`Locked parts changed outside the editor: `,O.violations.map(e=>`${e.part} (${e.detail})`).join(`, `),`. Lock them again to accept the change, or undo it in the code.`]}),(0,X.jsx)(_J,{data:d,workspace:u,checks:v,find:y,view:i,onView:a,page:T,onPage:E,selection:f,onSelect:p,onRenameDrawing:m,actions:h,run:w,onPlace:g,onImportPart:c,onNewPart:l,onOpenDocument:x,onOpenSheet:S,sheetParent:C,openChecks:b,aiLocked:n.closed,lockControl:(0,X.jsx)(AJ,{closed:n.closed,onToggle:n.toggle})}),(0,X.jsx)(Lm,{state:u.bottom,onClick:u.clickBottomTab,onOpen:u.openBottom}),k&&(0,X.jsx)(`div`,{className:`toast`,role:`status`,onClick:A,children:k})]}):(0,X.jsx)(cY,{})}dh(window),qv(document.documentElement,Gv(Uv)),(0,v.createRoot)(document.getElementById(`root`)).render((0,X.jsx)(_.StrictMode,{children:(0,X.jsx)(yY,{})}));export{W_ as a,E_ as c,u as d,T_ as i,Fm as l,rH as n,D_ as o,ov as r,$ as s,iH as t,W as u};
|