copperflow 0.3.3 → 0.3.4
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 +36 -0
- package/dist/app/assets/{NewPartDialog-B_cnPuI-.js → NewPartDialog-C4sKWnGI.js} +2 -2
- package/dist/app/assets/index-BgzJedaB.css +1 -0
- package/dist/app/assets/index-C_U9me2P.js +19 -0
- package/dist/app/index.html +2 -2
- package/dist/cli-commands.js +51 -8
- package/dist/cli-commands.js.map +1 -1
- package/dist/cli-library.d.ts +5 -0
- package/dist/cli-library.js +58 -0
- package/dist/cli-library.js.map +1 -0
- package/dist/cli-modules.d.ts +6 -0
- package/dist/cli-modules.js +33 -0
- package/dist/cli-modules.js.map +1 -0
- package/dist/cli-studio.d.ts +1 -0
- package/dist/cli-studio.js +27 -0
- package/dist/cli-studio.js.map +1 -0
- package/dist/core/board-import.d.ts +39 -0
- package/dist/core/board-import.js +114 -0
- package/dist/core/board-import.js.map +1 -0
- package/dist/core/board-shape-edit.d.ts +13 -0
- package/dist/core/board-shape-edit.js +134 -0
- package/dist/core/board-shape-edit.js.map +1 -0
- package/dist/core/edit.js +9 -3
- package/dist/core/edit.js.map +1 -1
- package/dist/core/git.d.ts +16 -0
- package/dist/core/git.js +51 -0
- package/dist/core/git.js.map +1 -0
- package/dist/core/home.d.ts +2 -0
- package/dist/core/home.js +10 -0
- package/dist/core/home.js.map +1 -0
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.js +1 -0
- package/dist/core/index.js.map +1 -1
- package/dist/core/instance-copper.d.ts +25 -0
- package/dist/core/instance-copper.js +142 -0
- package/dist/core/instance-copper.js.map +1 -0
- package/dist/core/instance-move.d.ts +23 -0
- package/dist/core/instance-move.js +59 -0
- package/dist/core/instance-move.js.map +1 -0
- package/dist/core/instance-requests.d.ts +3 -2
- package/dist/core/instance-requests.js +17 -3
- package/dist/core/instance-requests.js.map +1 -1
- package/dist/core/library-modules.d.ts +29 -0
- package/dist/core/library-modules.js +324 -0
- package/dist/core/library-modules.js.map +1 -0
- package/dist/core/library-sources.d.ts +33 -0
- package/dist/core/library-sources.js +179 -0
- package/dist/core/library-sources.js.map +1 -0
- package/dist/core/modules.d.ts +44 -0
- package/dist/core/modules.js +284 -0
- package/dist/core/modules.js.map +1 -0
- package/dist/core/new-circuit-sheets.d.ts +11 -2
- package/dist/core/new-circuit-sheets.js +35 -6
- package/dist/core/new-circuit-sheets.js.map +1 -1
- package/dist/core/placement-write.d.ts +2 -0
- package/dist/core/placement-write.js +12 -6
- package/dist/core/placement-write.js.map +1 -1
- package/dist/core/plain-sheet.d.ts +12 -0
- package/dist/core/plain-sheet.js +169 -0
- package/dist/core/plain-sheet.js.map +1 -0
- package/dist/core/sheet-card.d.ts +33 -0
- package/dist/core/sheet-card.js +118 -0
- package/dist/core/sheet-card.js.map +1 -0
- package/dist/core/types.d.ts +20 -0
- package/dist/core/workspace.d.ts +4 -0
- package/dist/core/workspace.js +13 -2
- package/dist/core/workspace.js.map +1 -1
- package/dist/engine/checks/drc-parts.js +7 -7
- package/dist/engine/checks/drc-parts.js.map +1 -1
- package/dist/engine/checks/erc.js +35 -3
- package/dist/engine/checks/erc.js.map +1 -1
- package/dist/engine/component.d.ts +2 -0
- package/dist/engine/component.js +18 -1
- package/dist/engine/component.js.map +1 -1
- package/dist/engine/dxf/board.d.ts +42 -0
- package/dist/engine/dxf/board.js +218 -0
- package/dist/engine/dxf/board.js.map +1 -0
- package/dist/engine/dxf/index.d.ts +2 -0
- package/dist/engine/dxf/index.js +3 -0
- package/dist/engine/dxf/index.js.map +1 -0
- package/dist/engine/dxf/reader.d.ts +43 -0
- package/dist/engine/dxf/reader.js +142 -0
- package/dist/engine/dxf/reader.js.map +1 -0
- package/dist/engine/elaborate.js +14 -4
- package/dist/engine/elaborate.js.map +1 -1
- package/dist/engine/fab/designator-places.d.ts +101 -0
- package/dist/engine/fab/designator-places.js +259 -0
- package/dist/engine/fab/designator-places.js.map +1 -0
- package/dist/engine/fab/designators.d.ts +26 -14
- package/dist/engine/fab/designators.js +320 -70
- package/dist/engine/fab/designators.js.map +1 -1
- package/dist/engine/fab/layers.js +6 -6
- package/dist/engine/fab/layers.js.map +1 -1
- package/dist/engine/fab/stroke-font.d.ts +2 -2
- package/dist/engine/fab/stroke-font.js +7 -6
- package/dist/engine/fab/stroke-font.js.map +1 -1
- package/dist/engine/model.d.ts +15 -1
- package/dist/engine/model.js.map +1 -1
- package/dist/engine/pcb-place/block-board.d.ts +9 -0
- package/dist/engine/pcb-place/block-board.js +256 -0
- package/dist/engine/pcb-place/block-board.js.map +1 -0
- package/dist/engine/pcb-place/blocks.d.ts +31 -6
- package/dist/engine/pcb-place/blocks.js +37 -8
- package/dist/engine/pcb-place/blocks.js.map +1 -1
- package/dist/engine/pcb-place/constructive.d.ts +3 -2
- package/dist/engine/pcb-place/constructive.js +14 -2
- package/dist/engine/pcb-place/constructive.js.map +1 -1
- package/dist/engine/pcb-place/index.d.ts +8 -0
- package/dist/engine/pcb-place/index.js +7 -0
- package/dist/engine/pcb-place/index.js.map +1 -1
- package/dist/engine/pcb-place/scope.js +6 -1
- package/dist/engine/pcb-place/scope.js.map +1 -1
- package/dist/engine/pcb.d.ts +6 -0
- package/dist/engine/pcb.js +12 -1
- package/dist/engine/pcb.js.map +1 -1
- package/dist/engine/router/replicate.js +4 -0
- package/dist/engine/router/replicate.js.map +1 -1
- package/dist/engine/router/route-board.d.ts +2 -0
- package/dist/engine/router/route-board.js +27 -1
- package/dist/engine/router/route-board.js.map +1 -1
- package/dist/engine/sheet-ports.d.ts +17 -1
- package/dist/engine/sheet-ports.js +38 -1
- package/dist/engine/sheet-ports.js.map +1 -1
- package/dist/mcp/batch.d.ts +2 -2
- package/dist/mcp/batch.js +12 -12
- package/dist/mcp/batch.js.map +1 -1
- package/dist/mcp/board-import-tool.d.ts +25 -0
- package/dist/mcp/board-import-tool.js +25 -0
- package/dist/mcp/board-import-tool.js.map +1 -0
- package/dist/mcp/board-summary.d.ts +1 -1
- package/dist/mcp/board-summary.js +1 -1
- package/dist/mcp/board-summary.js.map +1 -1
- package/dist/mcp/copper-tools.d.ts +4 -4
- package/dist/mcp/copper-tools.js +19 -19
- package/dist/mcp/copper-tools.js.map +1 -1
- package/dist/mcp/create-part.d.ts +1 -1
- package/dist/mcp/create-part.js +8 -8
- package/dist/mcp/create-part.js.map +1 -1
- package/dist/mcp/datasheet-tools.d.ts +1 -1
- package/dist/mcp/datasheet-tools.js +4 -4
- package/dist/mcp/datasheet-tools.js.map +1 -1
- package/dist/mcp/fillet-tools.d.ts +2 -2
- package/dist/mcp/fillet-tools.js +6 -6
- package/dist/mcp/fillet-tools.js.map +1 -1
- package/dist/mcp/guide.d.ts +1 -1
- package/dist/mcp/guide.js +4 -3
- package/dist/mcp/guide.js.map +1 -1
- package/dist/mcp/import-part.d.ts +1 -1
- package/dist/mcp/import-part.js +4 -4
- package/dist/mcp/import-part.js.map +1 -1
- package/dist/mcp/make-sheet.d.ts +1 -1
- package/dist/mcp/make-sheet.js +6 -6
- package/dist/mcp/make-sheet.js.map +1 -1
- package/dist/mcp/module-tools.d.ts +4 -0
- package/dist/mcp/module-tools.js +21 -0
- package/dist/mcp/module-tools.js.map +1 -0
- package/dist/mcp/new-circuit.d.ts +13 -2
- package/dist/mcp/new-circuit.js +30 -28
- package/dist/mcp/new-circuit.js.map +1 -1
- package/dist/mcp/open-studio.d.ts +30 -0
- package/dist/mcp/open-studio.js +97 -0
- package/dist/mcp/open-studio.js.map +1 -0
- package/dist/mcp/place-tools.d.ts +2 -2
- package/dist/mcp/place-tools.js +14 -11
- package/dist/mcp/place-tools.js.map +1 -1
- package/dist/mcp/pour-tools.d.ts +4 -4
- package/dist/mcp/pour-tools.js +18 -18
- package/dist/mcp/pour-tools.js.map +1 -1
- package/dist/mcp/project-tools.d.ts +3 -3
- package/dist/mcp/project-tools.js +8 -8
- package/dist/mcp/project-tools.js.map +1 -1
- package/dist/mcp/render-tool.d.ts +1 -1
- package/dist/mcp/render-tool.js +6 -6
- package/dist/mcp/render-tool.js.map +1 -1
- package/dist/mcp/route-tools.d.ts +2 -2
- package/dist/mcp/route-tools.js +10 -10
- package/dist/mcp/route-tools.js.map +1 -1
- package/dist/mcp/server.js +47 -31
- package/dist/mcp/server.js.map +1 -1
- package/dist/mcp/sheet-card-tools.d.ts +28 -0
- package/dist/mcp/sheet-card-tools.js +45 -0
- package/dist/mcp/sheet-card-tools.js.map +1 -0
- package/dist/render/render.js +75 -20
- package/dist/studio/idle.d.ts +7 -0
- package/dist/studio/idle.js +34 -0
- package/dist/studio/idle.js.map +1 -0
- package/dist/studio/place-runner.js +1 -1
- package/dist/studio/place-runner.js.map +1 -1
- package/dist/studio/run-studio.d.ts +21 -0
- package/dist/studio/run-studio.js +68 -0
- package/dist/studio/run-studio.js.map +1 -0
- package/dist/studio/server.d.ts +5 -0
- package/dist/studio/server.js +24 -2
- package/dist/studio/server.js.map +1 -1
- package/dist/studio/studio-control.d.ts +6 -0
- package/dist/studio/studio-control.js +14 -0
- package/dist/studio/studio-control.js.map +1 -0
- package/dist/studio/studio-note.d.ts +33 -0
- package/dist/studio/studio-note.js +130 -0
- package/dist/studio/studio-note.js.map +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/library/modules/CanNode/CanNode.sheet.tsx +65 -0
- package/library/modules/CanNode/module.json +4 -0
- package/library/modules/CanNode/parts/MCP2515-I-SO/MCP2515_I_SO.tsx +10 -0
- package/library/modules/CanNode/parts/MCP2515-I-SO/part.yaml +64 -0
- package/library/modules/CanNode/parts/MCP2515-I-SO/verification.md +42 -0
- package/library/modules/CanNode/parts/TJA1051T-3/TJA1051T_3.tsx +10 -0
- package/library/modules/CanNode/parts/TJA1051T-3/part.yaml +34 -0
- package/library/modules/CanNode/parts/TJA1051T-3/verification.md +28 -0
- package/library/modules/DigitalInput24V/DigitalInput24V.sheet.tsx +24 -0
- package/library/modules/DigitalInput24V/module.json +4 -0
- package/library/modules/RelayDriver/RelayDriver.sheet.tsx +39 -0
- package/library/modules/RelayDriver/module.json +4 -0
- package/library/modules/RelayDriver/parts/AO3400A/AO3400A.tsx +11 -0
- package/library/modules/RelayDriver/parts/AO3400A/part.yaml +21 -0
- package/library/modules/RelayDriver/parts/AO3400A/verification.md +24 -0
- package/library/modules/RelayDriver/parts/SRD-12VDC-SL-C/SRD_12VDC_SL_C.tsx +11 -0
- package/library/modules/RelayDriver/parts/SRD-12VDC-SL-C/footprint.yaml +70 -0
- package/library/modules/RelayDriver/parts/SRD-12VDC-SL-C/part.yaml +31 -0
- package/library/modules/RelayDriver/parts/SRD-12VDC-SL-C/verification.md +37 -0
- package/package.json +2 -1
- package/skills/copperflow/SKILL.md +16 -16
- package/skills/copperflow/references/copper.md +81 -6
- package/skills/copperflow/references/modules.md +80 -0
- package/skills/copperflow/references/planning.md +55 -11
- package/skills/copperflow/references/writing-circuits.md +29 -3
- package/skills/copperflow-plan/SKILL.md +7 -4
- package/dist/app/assets/index-CSWIIMFE.css +0 -1
- package/dist/app/assets/index-CjN3tctq.js +0 -19
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
var e=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t,t.exports),e=null),t.exports);(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 t=e((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 ee(e){var t={"=":`=0`,":":`=2`};return`$`+e.replace(/[=:]/g,function(e){return t[e]})}var D=/\/+/g;function O(e,t){return typeof e==`object`&&e&&e.key!=null?ee(``+e.key):t.toString(36)}function k(){}function A(e){switch(e.status){case`fulfilled`:return e.value;case`rejected`:throw e.reason;default:switch(typeof e.status==`string`?e.then(k,k):(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 j(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,j(c(e._payload),r,i,a,o)}}if(c)return o=o(e),c=a===``?`.`+O(e,0):a,x(o)?(i=``,c!=null&&(i=c.replace(D,`$&/`)+`/`),j(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(D,`$&/`)+`/`)+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+O(a,u),c+=j(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+O(a,u++),c+=j(a,r,i,s,o);else if(s===`object`){if(typeof e.then==`function`)return j(A(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 te(e,t,n){if(e==null)return e;var r=[],i=0;return j(e,r,``,``,function(e){return t.call(n,e,i++)}),r}function M(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:te,forEach:function(e,t,n){te(e,function(){t.apply(this,arguments)},n)},count:function(e){var t=0;return te(e,function(){t++}),t},toArray:function(e){return te(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:M}},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`})),n=e(((e,n)=>{n.exports=t()})),r=e((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,D());else{var t=n(l);t!==null&&A(x,t.startTime-e)}}}var S=!1,C=-1,w=5,T=-1;function E(){return g?!0:!(e.unstable_now()-T<w)}function ee(){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&&A(x,u.startTime-t),i=!1}}break a}finally{d=null,f=a,p=!1}i=void 0}}finally{i?D():S=!1}}}var D;if(typeof y==`function`)D=function(){y(ee)};else if(typeof MessageChannel<`u`){var O=new MessageChannel,k=O.port2;O.port1.onmessage=ee,D=function(){k.postMessage(null)}}else D=function(){_(ee,0)};function A(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,A(x,a-o))):(r.sortIndex=s,t(c,r),m||p||(m=!0,S||(S=!0,D()))),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}}}})),i=e(((e,t)=>{t.exports=r()})),a=e((e=>{var t=n();function r(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 i(){}var a={d:{f:i,r:function(){throw Error(r(522))},D:i,C:i,L:i,m:i,X:i,S:i,M:i},p:0,findDOMNode:null},o=Symbol.for(`react.portal`);function s(e,t,n){var r=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:o,key:r==null?null:``+r,children:e,containerInfo:t,implementation:n}}var c=t.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;function l(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=a,e.createPortal=function(e,t){var n=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!t||t.nodeType!==1&&t.nodeType!==9&&t.nodeType!==11)throw Error(r(299));return s(e,t,null,n)},e.flushSync=function(e){var t=c.T,n=a.p;try{if(c.T=null,a.p=2,e)return e()}finally{c.T=t,a.p=n,a.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,a.d.C(e,t))},e.prefetchDNS=function(e){typeof e==`string`&&a.d.D(e)},e.preinit=function(e,t){if(typeof e==`string`&&t&&typeof t.as==`string`){var n=t.as,r=l(n,t.crossOrigin),i=typeof t.integrity==`string`?t.integrity:void 0,o=typeof t.fetchPriority==`string`?t.fetchPriority:void 0;n===`style`?a.d.S(e,typeof t.precedence==`string`?t.precedence:void 0,{crossOrigin:r,integrity:i,fetchPriority:o}):n===`script`&&a.d.X(e,{crossOrigin:r,integrity:i,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=l(t.as,t.crossOrigin);a.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??a.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=l(n,t.crossOrigin);a.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=l(t.as,t.crossOrigin);a.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 a.d.m(e)}},e.requestFormReset=function(e){a.d.r(e)},e.unstable_batchedUpdates=function(e,t){return e(t)},e.useFormState=function(e,t,n){return c.H.useFormState(e,t,n)},e.useFormStatus=function(){return c.H.useHostTransitionStatus()},e.version=`19.1.0`})),o=e(((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=a()})),s=e((e=>{var t=i(),r=n(),a=o();function s(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 c(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11)}function l(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 u(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 d(e){if(l(e)!==e)throw Error(s(188))}function f(e){var t=e.alternate;if(!t){if(t=l(e),t===null)throw Error(s(188));return t===e?e:null}for(var n=e,r=t;;){var i=n.return;if(i===null)break;var a=i.alternate;if(a===null){if(r=i.return,r!==null){n=r;continue}break}if(i.child===a.child){for(a=i.child;a;){if(a===n)return d(i),e;if(a===r)return d(i),t;a=a.sibling}throw Error(s(188))}if(n.return!==r.return)n=i,r=a;else{for(var o=!1,c=i.child;c;){if(c===n){o=!0,n=i,r=a;break}if(c===r){o=!0,r=i,n=a;break}c=c.sibling}if(!o){for(c=a.child;c;){if(c===n){o=!0,n=a,r=i;break}if(c===r){o=!0,r=a,n=i;break}c=c.sibling}if(!o)throw Error(s(189))}}if(n.alternate!==r)throw Error(s(190))}if(n.tag!==3)throw Error(s(188));return n.stateNode.current===n?e:t}function p(e){var t=e.tag;if(t===5||t===26||t===27||t===6)return e;for(e=e.child;e!==null;){if(t=p(e),t!==null)return t;e=e.sibling}return null}var m=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`),ee=Symbol.for(`react.memo`),D=Symbol.for(`react.lazy`),O=Symbol.for(`react.activity`),k=Symbol.for(`react.memo_cache_sentinel`),A=Symbol.iterator;function j(e){return typeof e!=`object`||!e?null:(e=A&&e[A]||e[`@@iterator`],typeof e==`function`?e:null)}var te=Symbol.for(`react.client.reference`);function M(e){if(e==null)return null;if(typeof e==`function`)return e.$$typeof===te?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 O: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 ee:return t=e.displayName||null,t===null?M(e.type)||`Memo`:t;case D:t=e._payload,e=e._init;try{return M(e(t))}catch{}}return null}var ne=Array.isArray,N=r.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,P=a.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,F={pending:!1,data:null,method:null,action:null},re=[],ie=-1;function I(e){return{current:e}}function ae(e){0>ie||(e.current=re[ie],re[ie]=null,ie--)}function L(e,t){ie++,re[ie]=e.current,e.current=t}var oe=I(null),se=I(null),R=I(null),ce=I(null);function le(e,t){switch(L(R,t),L(se,e),L(oe,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}}ae(oe),L(oe,e)}function ue(){ae(oe),ae(se),ae(R)}function de(e){e.memoizedState!==null&&L(ce,e);var t=oe.current,n=Md(t,e.type);t!==n&&(L(se,e),L(oe,n))}function fe(e){se.current===e&&(ae(oe),ae(se)),ce.current===e&&(ae(ce),zf._currentValue=F)}var pe=Object.prototype.hasOwnProperty,me=t.unstable_scheduleCallback,he=t.unstable_cancelCallback,ge=t.unstable_shouldYield,z=t.unstable_requestPaint,_e=t.unstable_now,ve=t.unstable_getCurrentPriorityLevel,ye=t.unstable_ImmediatePriority,be=t.unstable_UserBlockingPriority,xe=t.unstable_NormalPriority,Se=t.unstable_LowPriority,Ce=t.unstable_IdlePriority,we=t.log,Te=t.unstable_setDisableYieldValue,Ee=null,De=null;function Oe(e){if(typeof we==`function`&&Te(e),De&&typeof De.setStrictMode==`function`)try{De.setStrictMode(Ee,e)}catch{}}var ke=Math.clz32?Math.clz32:Me,Ae=Math.log,je=Math.LN2;function Me(e){return e>>>=0,e===0?32:31-(Ae(e)/je|0)|0}var Ne=256,Pe=4194304;function Fe(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 Ie(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=Fe(n))):i=Fe(o):i=Fe(s)):(r=s&~a,r===0?(o&=s,o===0?n||(n=s&~e,n!==0&&(i=Fe(n))):i=Fe(o)):i=Fe(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 Le(e,t){return(e.pendingLanes&~(e.suspendedLanes&~e.pingedLanes)&t)===0}function Re(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 ze(){var e=Ne;return Ne<<=1,!(Ne&4194048)&&(Ne=256),e}function Be(){var e=Pe;return Pe<<=1,!(Pe&62914560)&&(Pe=4194304),e}function Ve(e){for(var t=[],n=0;31>n;n++)t.push(e);return t}function He(e,t){e.pendingLanes|=t,t!==268435456&&(e.suspendedLanes=0,e.pingedLanes=0,e.warmLanes=0)}function Ue(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-ke(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&&We(e,r,0),a!==0&&i===0&&e.tag!==0&&(e.suspendedLanes|=a&~(o&~t))}function We(e,t,n){e.pendingLanes|=t,e.suspendedLanes&=~t;var r=31-ke(t);e.entangledLanes|=t,e.entanglements[r]=e.entanglements[r]|1073741824|n&4194090}function Ge(e,t){var n=e.entangledLanes|=t;for(e=e.entanglements;n;){var r=31-ke(n),i=1<<r;i&t|e[r]&t&&(e[r]|=t),n&=~i}}function Ke(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 qe(e){return e&=-e,2<e?8<e?e&134217727?32:268435456:8:2}function Je(){var e=P.p;return e===0?(e=window.event,e===void 0?32:ep(e.type)):e}function Ye(e,t){var n=P.p;try{return P.p=e,t()}finally{P.p=n}}var Xe=Math.random().toString(36).slice(2),Ze=`__reactFiber$`+Xe,Qe=`__reactProps$`+Xe,$e=`__reactContainer$`+Xe,et=`__reactEvents$`+Xe,tt=`__reactListeners$`+Xe,nt=`__reactHandles$`+Xe,rt=`__reactResources$`+Xe,it=`__reactMarker$`+Xe;function at(e){delete e[Ze],delete e[Qe],delete e[et],delete e[tt],delete e[nt]}function ot(e){var t=e[Ze];if(t)return t;for(var n=e.parentNode;n;){if(t=n[$e]||n[Ze]){if(n=t.alternate,t.child!==null||n!==null&&n.child!==null)for(e=Xd(e);e!==null;){if(n=e[Ze])return n;e=Xd(e)}return t}e=n,n=e.parentNode}return null}function st(e){if(e=e[Ze]||e[$e]){var t=e.tag;if(t===5||t===6||t===13||t===26||t===27||t===3)return e}return null}function ct(e){var t=e.tag;if(t===5||t===26||t===27||t===6)return e.stateNode;throw Error(s(33))}function lt(e){var t=e[rt];return t||=e[rt]={hoistableStyles:new Map,hoistableScripts:new Map},t}function ut(e){e[it]=!0}var dt=new Set,ft={};function pt(e,t){mt(e,t),mt(e+`Capture`,t)}function mt(e,t){for(ft[e]=t,e=0;e<t.length;e++)dt.add(t[e])}var ht=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]*$`),gt={},_t={};function vt(e){return pe.call(_t,e)?!0:pe.call(gt,e)?!1:ht.test(e)?_t[e]=!0:(gt[e]=!0,!1)}function yt(e,t,n){if(vt(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 bt(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 xt(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 St,Ct;function wt(e){if(St===void 0)try{throw Error()}catch(e){var t=e.stack.trim().match(/\n( *(at )?)/);St=t&&t[1]||``,Ct=-1<e.stack.indexOf(`
|
|
2
|
-
at`)?` (<anonymous>)`:-1<e.stack.indexOf(`@`)?`@unknown:0:0`:``}return`
|
|
3
|
-
`+St+e+Ct}var Tt=!1;function Et(e,t){if(!e||Tt)return``;Tt=!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(`
|
|
4
|
-
`),l=s.split(`
|
|
5
|
-
`);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=`
|
|
6
|
-
`+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{Tt=!1,Error.prepareStackTrace=n}return(n=e?e.displayName||e.name:``)?wt(n):``}function Dt(e){switch(e.tag){case 26:case 27:case 5:return wt(e.type);case 16:return wt(`Lazy`);case 13:return wt(`Suspense`);case 19:return wt(`SuspenseList`);case 0:case 15:return Et(e.type,!1);case 11:return Et(e.type.render,!1);case 1:return Et(e.type,!0);case 31:return wt(`Activity`);default:return``}}function Ot(e){try{var t=``;do t+=Dt(e),e=e.return;while(e);return t}catch(e){return`
|
|
7
|
-
Error generating stack: `+e.message+`
|
|
8
|
-
`+e.stack}}function kt(e){switch(typeof e){case`bigint`:case`boolean`:case`number`:case`string`:case`undefined`:return e;case`object`:return e;default:return``}}function At(e){var t=e.type;return(e=e.nodeName)&&e.toLowerCase()===`input`&&(t===`checkbox`||t===`radio`)}function jt(e){var t=At(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 Mt(e){e._valueTracker||=jt(e)}function Nt(e){if(!e)return!1;var t=e._valueTracker;if(!t)return!0;var n=t.getValue(),r=``;return e&&(r=At(e)?e.checked?`true`:`false`:e.value),e=r,e!==n&&(t.setValue(e),!0)}function Pt(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 Ft=/[\n"\\]/g;function It(e){return e.replace(Ft,function(e){return`\\`+e.charCodeAt(0).toString(16)+` `})}function Lt(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=``+kt(t)):e.value!==``+kt(t)&&(e.value=``+kt(t)),t==null?n==null?r!=null&&e.removeAttribute(`value`):zt(e,o,kt(n)):zt(e,o,kt(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=``+kt(s):e.removeAttribute(`name`)}function Rt(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?``:``+kt(n),t=t==null?n:``+kt(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 zt(e,t,n){t===`number`&&Pt(e.ownerDocument)===e||e.defaultValue===``+n||(e.defaultValue=``+n)}function Bt(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=``+kt(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 Vt(e,t,n){t!=null&&(t=``+kt(t),t!==e.value&&(e.value=t),n==null)?e.defaultValue!==t&&(e.defaultValue=t):e.defaultValue=n==null?``:``+kt(n)}function Ht(e,t,n,r){if(t==null){if(r!=null){if(n!=null)throw Error(s(92));if(ne(r)){if(1<r.length)throw Error(s(93));r=r[0]}n=r}n??=``,t=n}n=kt(t),e.defaultValue=n,r=e.textContent,r===n&&r!==``&&r!==null&&(e.value=r)}function Ut(e,t){if(t){var n=e.firstChild;if(n&&n===e.lastChild&&n.nodeType===3){n.nodeValue=t;return}}e.textContent=t}var Wt=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 Gt(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||Wt.has(t)?t===`float`?e.cssFloat=n:e[t]=(``+n).trim():e[t]=n+`px`}function Kt(e,t,n){if(t!=null&&typeof t!=`object`)throw Error(s(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 i in t)r=t[i],t.hasOwnProperty(i)&&n[i]!==r&&Gt(e,i,r)}else for(var a in t)t.hasOwnProperty(a)&&Gt(e,a,t[a])}function qt(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 Jt=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`]]),Yt=/^[\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 Xt(e){return Yt.test(``+e)?`javascript:throw new Error('React has blocked a javascript: URL as a security precaution.')`:e}var Zt=null;function Qt(e){return e=e.target||e.srcElement||window,e.correspondingUseElement&&(e=e.correspondingUseElement),e.nodeType===3?e.parentNode:e}var $t=null,en=null;function tn(e){var t=st(e);if(t&&(e=t.stateNode)){var n=e[Qe]||null;a:switch(e=t.stateNode,t.type){case`input`:if(Lt(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="`+It(``+t)+`"][type="radio"]`),t=0;t<n.length;t++){var r=n[t];if(r!==e&&r.form===e.form){var i=r[Qe]||null;if(!i)throw Error(s(90));Lt(r,i.value,i.defaultValue,i.defaultValue,i.checked,i.defaultChecked,i.type,i.name)}}for(t=0;t<n.length;t++)r=n[t],r.form===e.form&&Nt(r)}break a;case`textarea`:Vt(e,n.value,n.defaultValue);break a;case`select`:t=n.value,t!=null&&Bt(e,!!n.multiple,t,!1)}}}var nn=!1;function rn(e,t,n){if(nn)return e(t,n);nn=!0;try{return e(t)}finally{if(nn=!1,($t!==null||en!==null)&&(fu(),$t&&(t=$t,e=en,en=$t=null,tn(t),e)))for(t=0;t<e.length;t++)tn(e[t])}}function an(e,t){var n=e.stateNode;if(n===null)return null;var r=n[Qe]||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(s(231,t,typeof n));return n}var on=typeof window<`u`&&window.document!==void 0&&window.document.createElement!==void 0,sn=!1;if(on)try{var cn={};Object.defineProperty(cn,"passive",{get:function(){sn=!0}}),window.addEventListener(`test`,cn,cn),window.removeEventListener(`test`,cn,cn)}catch{sn=!1}var ln=null,un=null,dn=null;function fn(){if(dn)return dn;var e,t=un,n=t.length,r,i=`value`in ln?ln.value:ln.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 dn=i.slice(e,1<r?1-r:void 0)}function pn(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 mn(){return!0}function hn(){return!1}function gn(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)?mn:hn,this.isPropagationStopped=hn,this}return m(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=mn)},stopPropagation:function(){var e=this.nativeEvent;e&&(e.stopPropagation?e.stopPropagation():typeof e.cancelBubble!=`unknown`&&(e.cancelBubble=!0),this.isPropagationStopped=mn)},persist:function(){},isPersistent:mn}),t}var _n={eventPhase:0,bubbles:0,cancelable:0,timeStamp:function(e){return e.timeStamp||Date.now()},defaultPrevented:0,isTrusted:0},vn=gn(_n),yn=m({},_n,{view:0,detail:0}),bn=gn(yn),xn,Sn,Cn,wn=m({},yn,{screenX:0,screenY:0,clientX:0,clientY:0,pageX:0,pageY:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,getModifierState:Fn,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!==Cn&&(Cn&&e.type===`mousemove`?(xn=e.screenX-Cn.screenX,Sn=e.screenY-Cn.screenY):Sn=xn=0,Cn=e),xn)},movementY:function(e){return`movementY`in e?e.movementY:Sn}}),Tn=gn(wn),En=gn(m({},wn,{dataTransfer:0})),Dn=gn(m({},yn,{relatedTarget:0})),On=gn(m({},_n,{animationName:0,elapsedTime:0,pseudoElement:0})),kn=gn(m({},_n,{clipboardData:function(e){return`clipboardData`in e?e.clipboardData:window.clipboardData}})),An=gn(m({},_n,{data:0})),jn={Esc:`Escape`,Spacebar:` `,Left:`ArrowLeft`,Up:`ArrowUp`,Right:`ArrowRight`,Down:`ArrowDown`,Del:`Delete`,Win:`OS`,Menu:`ContextMenu`,Apps:`ContextMenu`,Scroll:`ScrollLock`,MozPrintableKey:`Unidentified`},Mn={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`},Nn={Alt:`altKey`,Control:`ctrlKey`,Meta:`metaKey`,Shift:`shiftKey`};function Pn(e){var t=this.nativeEvent;return t.getModifierState?t.getModifierState(e):(e=Nn[e])?!!t[e]:!1}function Fn(){return Pn}var In=gn(m({},yn,{key:function(e){if(e.key){var t=jn[e.key]||e.key;if(t!==`Unidentified`)return t}return e.type===`keypress`?(e=pn(e),e===13?`Enter`:String.fromCharCode(e)):e.type===`keydown`||e.type===`keyup`?Mn[e.keyCode]||`Unidentified`:``},code:0,location:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,repeat:0,locale:0,getModifierState:Fn,charCode:function(e){return e.type===`keypress`?pn(e):0},keyCode:function(e){return e.type===`keydown`||e.type===`keyup`?e.keyCode:0},which:function(e){return e.type===`keypress`?pn(e):e.type===`keydown`||e.type===`keyup`?e.keyCode:0}})),Ln=gn(m({},wn,{pointerId:0,width:0,height:0,pressure:0,tangentialPressure:0,tiltX:0,tiltY:0,twist:0,pointerType:0,isPrimary:0})),Rn=gn(m({},yn,{touches:0,targetTouches:0,changedTouches:0,altKey:0,metaKey:0,ctrlKey:0,shiftKey:0,getModifierState:Fn})),zn=gn(m({},_n,{propertyName:0,elapsedTime:0,pseudoElement:0})),Bn=gn(m({},wn,{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})),Vn=gn(m({},_n,{newState:0,oldState:0})),Hn=[9,13,27,32],Un=on&&`CompositionEvent`in window,Wn=null;on&&`documentMode`in document&&(Wn=document.documentMode);var Gn=on&&`TextEvent`in window&&!Wn,Kn=on&&(!Un||Wn&&8<Wn&&11>=Wn),qn=` `,Jn=!1;function Yn(e,t){switch(e){case`keyup`:return Hn.indexOf(t.keyCode)!==-1;case`keydown`:return t.keyCode!==229;case`keypress`:case`mousedown`:case`focusout`:return!0;default:return!1}}function Xn(e){return e=e.detail,typeof e==`object`&&`data`in e?e.data:null}var Zn=!1;function Qn(e,t){switch(e){case`compositionend`:return Xn(t);case`keypress`:return t.which===32?(Jn=!0,qn):null;case`textInput`:return e=t.data,e===qn&&Jn?null:e;default:return null}}function $n(e,t){if(Zn)return e===`compositionend`||!Un&&Yn(e,t)?(e=fn(),dn=un=ln=null,Zn=!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 Kn&&t.locale!==`ko`?null:t.data;default:return null}}var er={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 tr(e){var t=e&&e.nodeName&&e.nodeName.toLowerCase();return t===`input`?!!er[e.type]:t===`textarea`}function nr(e,t,n,r){$t?en?en.push(r):en=[r]:$t=r,t=_d(t,`onChange`),0<t.length&&(n=new vn(`onChange`,`change`,null,n,r),e.push({event:n,listeners:t}))}var rr=null,ir=null;function ar(e){ud(e,0)}function or(e){if(Nt(ct(e)))return e}function sr(e,t){if(e===`change`)return t}var cr=!1;if(on){var lr;if(on){var ur=`oninput`in document;if(!ur){var dr=document.createElement(`div`);dr.setAttribute(`oninput`,`return;`),ur=typeof dr.oninput==`function`}lr=ur}else lr=!1;cr=lr&&(!document.documentMode||9<document.documentMode)}function fr(){rr&&(rr.detachEvent(`onpropertychange`,pr),ir=rr=null)}function pr(e){if(e.propertyName===`value`&&or(ir)){var t=[];nr(t,ir,e,Qt(e)),rn(ar,t)}}function mr(e,t,n){e===`focusin`?(fr(),rr=t,ir=n,rr.attachEvent(`onpropertychange`,pr)):e===`focusout`&&fr()}function hr(e){if(e===`selectionchange`||e===`keyup`||e===`keydown`)return or(ir)}function gr(e,t){if(e===`click`)return or(t)}function _r(e,t){if(e===`input`||e===`change`)return or(t)}function vr(e,t){return e===t&&(e!==0||1/e==1/t)||e!==e&&t!==t}var yr=typeof Object.is==`function`?Object.is:vr;function br(e,t){if(yr(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(!pe.call(t,i)||!yr(e[i],t[i]))return!1}return!0}function xr(e){for(;e&&e.firstChild;)e=e.firstChild;return e}function Sr(e,t){var n=xr(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=xr(n)}}function Cr(e,t){return e&&t?e===t?!0:e&&e.nodeType===3?!1:t&&t.nodeType===3?Cr(e,t.parentNode):`contains`in e?e.contains(t):e.compareDocumentPosition?!!(e.compareDocumentPosition(t)&16):!1:!1}function wr(e){e=e!=null&&e.ownerDocument!=null&&e.ownerDocument.defaultView!=null?e.ownerDocument.defaultView:window;for(var t=Pt(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=Pt(e.document)}return t}function Tr(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 Er=on&&`documentMode`in document&&11>=document.documentMode,Dr=null,Or=null,kr=null,Ar=!1;function jr(e,t,n){var r=n.window===n?n.document:n.nodeType===9?n:n.ownerDocument;Ar||Dr==null||Dr!==Pt(r)||(r=Dr,`selectionStart`in r&&Tr(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}),kr&&br(kr,r)||(kr=r,r=_d(Or,`onSelect`),0<r.length&&(t=new vn(`onSelect`,`select`,null,t,n),e.push({event:t,listeners:r}),t.target=Dr)))}function Mr(e,t){var n={};return n[e.toLowerCase()]=t.toLowerCase(),n[`Webkit`+e]=`webkit`+t,n[`Moz`+e]=`moz`+t,n}var Nr={animationend:Mr(`Animation`,`AnimationEnd`),animationiteration:Mr(`Animation`,`AnimationIteration`),animationstart:Mr(`Animation`,`AnimationStart`),transitionrun:Mr(`Transition`,`TransitionRun`),transitionstart:Mr(`Transition`,`TransitionStart`),transitioncancel:Mr(`Transition`,`TransitionCancel`),transitionend:Mr(`Transition`,`TransitionEnd`)},Pr={},Fr={};on&&(Fr=document.createElement(`div`).style,`AnimationEvent`in window||(delete Nr.animationend.animation,delete Nr.animationiteration.animation,delete Nr.animationstart.animation),`TransitionEvent`in window||delete Nr.transitionend.transition);function Ir(e){if(Pr[e])return Pr[e];if(!Nr[e])return e;var t=Nr[e],n;for(n in t)if(t.hasOwnProperty(n)&&n in Fr)return Pr[e]=t[n];return e}var Lr=Ir(`animationend`),Rr=Ir(`animationiteration`),zr=Ir(`animationstart`),Br=Ir(`transitionrun`),Vr=Ir(`transitionstart`),Hr=Ir(`transitioncancel`),Ur=Ir(`transitionend`),Wr=new Map,Gr=`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(` `);Gr.push(`scrollEnd`);function Kr(e,t){Wr.set(e,t),pt(t,[e])}var qr=new WeakMap;function Jr(e,t){if(typeof e==`object`&&e){var n=qr.get(e);return n===void 0?(t={value:e,source:t,stack:Ot(t)},qr.set(e,t),t):n}return{value:e,source:t,stack:Ot(t)}}var Yr=[],Xr=0,Zr=0;function Qr(){for(var e=Xr,t=Zr=Xr=0;t<e;){var n=Yr[t];Yr[t++]=null;var r=Yr[t];Yr[t++]=null;var i=Yr[t];Yr[t++]=null;var a=Yr[t];if(Yr[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&&ni(n,i,a)}}function $r(e,t,n,r){Yr[Xr++]=e,Yr[Xr++]=t,Yr[Xr++]=n,Yr[Xr++]=r,Zr|=r,e.lanes|=r,e=e.alternate,e!==null&&(e.lanes|=r)}function ei(e,t,n,r){return $r(e,t,n,r),B(e)}function ti(e,t){return $r(e,null,null,t),B(e)}function ni(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-ke(n),e=a.hiddenUpdates,r=e[i],r===null?e[i]=[t]:r.push(t),t.lane=n|536870912),a):null}function B(e){if(50<iu)throw iu=0,au=null,Error(s(185));for(var t=e.return;t!==null;)e=t,t=e.return;return e.tag===3?e.stateNode:null}var ri={};function ii(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 ai(e,t,n,r){return new ii(e,t,n,r)}function oi(e){return e=e.prototype,!(!e||!e.isReactComponent)}function si(e,t){var n=e.alternate;return n===null?(n=ai(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 ci(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 li(e,t,n,r,i,a){var o=0;if(r=e,typeof e==`function`)oi(e)&&(o=1);else if(typeof e==`string`)o=kf(e,n,oe.current)?26:e===`html`||e===`head`||e===`body`?27:5;else a:switch(e){case O:return e=ai(31,n,t,i),e.elementType=O,e.lanes=a,e;case v:return ui(n.children,i,a,t);case y:o=8,i|=24;break;case b:return e=ai(12,n,t,i|2),e.elementType=b,e.lanes=a,e;case T:return e=ai(13,n,t,i),e.elementType=T,e.lanes=a,e;case E:return e=ai(19,n,t,i),e.elementType=E,e.lanes=a,e;default:if(typeof e==`object`&&e)switch(e.$$typeof){case x:case C:o=10;break a;case S:o=9;break a;case w:o=11;break a;case ee:o=14;break a;case D:o=16,r=null;break a}o=29,n=Error(s(130,e===null?`null`:typeof e,``)),r=null}return t=ai(o,n,t,i),t.elementType=e,t.type=r,t.lanes=a,t}function ui(e,t,n,r){return e=ai(7,e,r,t),e.lanes=n,e}function di(e,t,n){return e=ai(6,e,null,t),e.lanes=n,e}function fi(e,t,n){return t=ai(4,e.children===null?[]:e.children,e.key,t),t.lanes=n,t.stateNode={containerInfo:e.containerInfo,pendingChildren:null,implementation:e.implementation},t}var pi=[],mi=0,hi=null,gi=0,_i=[],vi=0,yi=null,bi=1,xi=``;function Si(e,t){pi[mi++]=gi,pi[mi++]=hi,hi=e,gi=t}function Ci(e,t,n){_i[vi++]=bi,_i[vi++]=xi,_i[vi++]=yi,yi=e;var r=bi;e=xi;var i=32-ke(r)-1;r&=~(1<<i),n+=1;var a=32-ke(t)+i;if(30<a){var o=i-i%5;a=(r&(1<<o)-1).toString(32),r>>=o,i-=o,bi=1<<32-ke(t)+i|n<<i|r,xi=a+e}else bi=1<<a|n<<i|r,xi=e}function wi(e){e.return!==null&&(Si(e,1),Ci(e,1,0))}function Ti(e){for(;e===hi;)hi=pi[--mi],pi[mi]=null,gi=pi[--mi],pi[mi]=null;for(;e===yi;)yi=_i[--vi],_i[vi]=null,xi=_i[--vi],_i[vi]=null,bi=_i[--vi],_i[vi]=null}var Ei=null,Di=null,V=!1,Oi=null,ki=!1,Ai=Error(s(519));function ji(e){throw Li(Jr(Error(s(418,``)),e)),Ai}function Mi(e){var t=e.stateNode,n=e.type,r=e.memoizedProps;switch(t[Ze]=e,t[Qe]=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),Rt(t,r.value,r.defaultValue,r.checked,r.defaultChecked,r.type,r.name,!0),Mt(t);break;case`select`:J(`invalid`,t);break;case`textarea`:J(`invalid`,t),Ht(t,r.value,r.defaultValue,r.children),Mt(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||ji(e)}function Ni(e){for(Ei=e.return;Ei;)switch(Ei.tag){case 5:case 13:ki=!1;return;case 27:case 3:ki=!0;return;default:Ei=Ei.return}}function Pi(e){if(e!==Ei)return!1;if(!V)return Ni(e),V=!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&&Di&&ji(e),Ni(e),t===13){if(e=e.memoizedState,e=e===null?null:e.dehydrated,!e)throw Error(s(317));a:{for(e=e.nextSibling,t=0;e;){if(e.nodeType===8){if(n=e.data,n===`/$`){if(t===0){Di=Jd(e.nextSibling);break a}t--}else n!==`$`&&n!==`$!`&&n!==`$?`||t++}e=e.nextSibling}Di=null}}else t===27?(t=Di,Vd(e.type)?(e=Yd,Yd=null,Di=e):Di=t):Di=Ei?Jd(e.stateNode.nextSibling):null;return!0}function Fi(){Di=Ei=null,V=!1}function Ii(){var e=Oi;return e!==null&&(Gl===null?Gl=e:Gl.push.apply(Gl,e),Oi=null),e}function Li(e){Oi===null?Oi=[e]:Oi.push(e)}var Ri=I(null),zi=null,Bi=null;function Vi(e,t,n){L(Ri,t._currentValue),t._currentValue=n}function Hi(e){e._currentValue=Ri.current,ae(Ri)}function Ui(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 Wi(e,t,n,r){var i=e.child;for(i!==null&&(i.return=e);i!==null;){var a=i.dependencies;if(a!==null){var o=i.child;a=a.firstContext;a:for(;a!==null;){var c=a;a=i;for(var l=0;l<t.length;l++)if(c.context===t[l]){a.lanes|=n,c=a.alternate,c!==null&&(c.lanes|=n),Ui(a.return,n,e),r||(o=null);break a}a=c.next}}else if(i.tag===18){if(o=i.return,o===null)throw Error(s(341));o.lanes|=n,a=o.alternate,a!==null&&(a.lanes|=n),Ui(o,n,e),o=null}else o=i.child;if(o!==null)o.return=i;else for(o=i;o!==null;){if(o===e){o=null;break}if(i=o.sibling,i!==null){i.return=o.return,o=i;break}o=o.return}i=o}}function Gi(e,t,n,r){e=null;for(var i=t,a=!1;i!==null;){if(!a){if(i.flags&524288)a=!0;else if(i.flags&262144)break}if(i.tag===10){var o=i.alternate;if(o===null)throw Error(s(387));if(o=o.memoizedProps,o!==null){var c=i.type;yr(i.pendingProps.value,o.value)||(e===null?e=[c]:e.push(c))}}else if(i===ce.current){if(o=i.alternate,o===null)throw Error(s(387));o.memoizedState.memoizedState!==i.memoizedState.memoizedState&&(e===null?e=[zf]:e.push(zf))}i=i.return}e!==null&&Wi(t,e,n,r),t.flags|=262144}function Ki(e){for(e=e.firstContext;e!==null;){if(!yr(e.context._currentValue,e.memoizedValue))return!0;e=e.next}return!1}function qi(e){zi=e,Bi=null,e=e.dependencies,e!==null&&(e.firstContext=null)}function Ji(e){return Xi(zi,e)}function Yi(e,t){return zi===null&&qi(e),Xi(e,t)}function Xi(e,t){var n=t._currentValue;if(t={context:t,memoizedValue:n,next:null},Bi===null){if(e===null)throw Error(s(308));Bi=t,e.dependencies={lanes:0,firstContext:t},e.flags|=524288}else Bi=Bi.next=t;return n}var Zi=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()})}},Qi=t.unstable_scheduleCallback,$i=t.unstable_NormalPriority,ea={$$typeof:C,Consumer:null,Provider:null,_currentValue:null,_currentValue2:null,_threadCount:0};function ta(){return{controller:new Zi,data:new Map,refCount:0}}function na(e){e.refCount--,e.refCount===0&&Qi($i,function(){e.controller.abort()})}var ra=null,ia=0,aa=0,oa=null;function sa(e,t){if(ra===null){var n=ra=[];ia=0,aa=nd(),oa={status:`pending`,value:void 0,then:function(e){n.push(e)}}}return ia++,t.then(ca,ca),t}function ca(){if(--ia===0&&ra!==null){oa!==null&&(oa.status=`fulfilled`);var e=ra;ra=null,aa=0,oa=null;for(var t=0;t<e.length;t++)(0,e[t])()}}function la(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 ua=N.S;N.S=function(e,t){typeof t==`object`&&t&&typeof t.then==`function`&&sa(e,t),ua!==null&&ua(e,t)};var da=I(null);function fa(){var e=da.current;return e===null?jl.pooledCache:e}function H(e,t){t===null?L(da,da.current):L(da,t.pool)}function pa(){var e=fa();return e===null?null:{parent:ea._currentValue,pool:e}}var ma=Error(s(460)),ha=Error(s(474)),ga=Error(s(542)),_a={then:function(){}};function va(e){return e=e.status,e===`fulfilled`||e===`rejected`}function ya(){}function ba(e,t,n){switch(n=e[n],n===void 0?e.push(t):n!==t&&(t.then(ya,ya),t=n),t.status){case`fulfilled`:return t.value;case`rejected`:throw e=t.reason,Ca(e),e;default:if(typeof t.status==`string`)t.then(ya,ya);else{if(e=jl,e!==null&&100<e.shellSuspendCounter)throw Error(s(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,Ca(e),e}throw xa=t,ma}}var xa=null;function Sa(){if(xa===null)throw Error(s(459));var e=xa;return xa=null,e}function Ca(e){if(e===ma||e===ga)throw Error(s(483))}var wa=!1;function Ta(e){e.updateQueue={baseState:e.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,lanes:0,hiddenCallbacks:null},callbacks:null}}function Ea(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 Da(e){return{lane:e,tag:0,payload:null,callback:null,next:null}}function Oa(e,t,n){var r=e.updateQueue;if(r===null)return null;if(r=r.shared,Al&2){var i=r.pending;return i===null?t.next=t:(t.next=i.next,i.next=t),r.pending=t,t=B(e),ni(e,null,n),t}return $r(e,r,t,n),B(e)}function ka(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,Ge(e,n)}}function Aa(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 ja=!1;function Ma(){if(ja){var e=oa;if(e!==null)throw e}}function Na(e,t,n,r){ja=!1;var i=e.updateQueue;wa=!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,p=f!==s.lane;if(p?(G&f)===f:(r&f)===f){f!==0&&f===aa&&(ja=!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=m({},d,f);break a;case 2:wa=!0}}f=s.callback,f!==null&&(e.flags|=64,p&&(e.flags|=8192),p=i.callbacks,p===null?i.callbacks=[f]:p.push(f))}else p={lane:f,tag:s.tag,payload:s.payload,callback:s.callback,next:null},u===null?(l=u=p,c=d):u=u.next=p,o|=f;if(s=s.next,s===null){if(s=i.shared.pending,s===null)break;p=s,s=p.next,p.next=null,i.lastBaseUpdate=p,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),zl|=o,e.lanes=o,e.memoizedState=d}}function Pa(e,t){if(typeof e!=`function`)throw Error(s(191,e));e.call(t)}function Fa(e,t){var n=e.callbacks;if(n!==null)for(e.callbacks=null,e=0;e<n.length;e++)Pa(n[e],t)}var Ia=I(null),La=I(0);function Ra(e,t){e=Ll,L(La,e),L(Ia,t),Ll=e|t.baseLanes}function za(){L(La,Ll),L(Ia,Ia.current)}function Ba(){Ll=La.current,ae(Ia),ae(La)}var Va=0,U=null,Ha=null,Ua=null,Wa=!1,Ga=!1,Ka=!1,qa=0,Ja=0,Ya=null,Xa=0;function Za(){throw Error(s(321))}function Qa(e,t){if(t===null)return!1;for(var n=0;n<t.length&&n<e.length;n++)if(!yr(e[n],t[n]))return!1;return!0}function $a(e,t,n,r,i,a){return Va=a,U=t,t.memoizedState=null,t.updateQueue=null,t.lanes=0,N.H=e===null||e.memoizedState===null?gs:_s,Ka=!1,a=n(r,i),Ka=!1,Ga&&(a=to(t,n,r,i)),eo(e),a}function eo(e){N.H=hs;var t=Ha!==null&&Ha.next!==null;if(Va=0,Ua=Ha=U=null,Wa=!1,Ja=0,Ya=null,t)throw Error(s(300));e===null||Qs||(e=e.dependencies,e!==null&&Ki(e)&&(Qs=!0))}function to(e,t,n,r){U=e;var i=0;do{if(Ga&&(Ya=null),Ja=0,Ga=!1,25<=i)throw Error(s(301));if(i+=1,Ua=Ha=null,e.updateQueue!=null){var a=e.updateQueue;a.lastEffect=null,a.events=null,a.stores=null,a.memoCache!=null&&(a.memoCache.index=0)}N.H=vs,a=t(n,r)}while(Ga);return a}function no(){var e=N.H,t=e.useState()[0];return t=typeof t.then==`function`?lo(t):t,e=e.useState()[0],(Ha===null?null:Ha.memoizedState)!==e&&(U.flags|=1024),t}function ro(){var e=qa!==0;return qa=0,e}function io(e,t,n){t.updateQueue=e.updateQueue,t.flags&=-2053,e.lanes&=~n}function ao(e){if(Wa){for(e=e.memoizedState;e!==null;){var t=e.queue;t!==null&&(t.pending=null),e=e.next}Wa=!1}Va=0,Ua=Ha=U=null,Ga=!1,Ja=qa=0,Ya=null}function oo(){var e={memoizedState:null,baseState:null,baseQueue:null,queue:null,next:null};return Ua===null?U.memoizedState=Ua=e:Ua=Ua.next=e,Ua}function so(){if(Ha===null){var e=U.alternate;e=e===null?null:e.memoizedState}else e=Ha.next;var t=Ua===null?U.memoizedState:Ua.next;if(t!==null)Ua=t,Ha=e;else{if(e===null)throw U.alternate===null?Error(s(467)):Error(s(310));Ha=e,e={memoizedState:Ha.memoizedState,baseState:Ha.baseState,baseQueue:Ha.baseQueue,queue:Ha.queue,next:null},Ua===null?U.memoizedState=Ua=e:Ua=Ua.next=e}return Ua}function co(){return{lastEffect:null,events:null,stores:null,memoCache:null}}function lo(e){var t=Ja;return Ja+=1,Ya===null&&(Ya=[]),e=ba(Ya,e,t),t=U,(Ua===null?t.memoizedState:Ua.next)===null&&(t=t.alternate,N.H=t===null||t.memoizedState===null?gs:_s),e}function uo(e){if(typeof e==`object`&&e){if(typeof e.then==`function`)return lo(e);if(e.$$typeof===C)return Ji(e)}throw Error(s(438,String(e)))}function fo(e){var t=null,n=U.updateQueue;if(n!==null&&(t=n.memoCache),t==null){var r=U.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=co(),U.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]=k;return t.index++,n}function po(e,t){return typeof t==`function`?t(e):t}function mo(e){return ho(so(),Ha,e)}function ho(e,t,n){var r=e.queue;if(r===null)throw Error(s(311));r.lastRenderedReducer=n;var i=e.baseQueue,a=r.pending;if(a!==null){if(i!==null){var o=i.next;i.next=a.next,a.next=o}t.baseQueue=i=a,r.pending=null}if(a=e.baseState,i===null)e.memoizedState=a;else{t=i.next;var c=o=null,l=null,u=t,d=!1;do{var f=u.lane&-536870913;if(f===u.lane?(Va&f)===f:(G&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===aa&&(d=!0);else if((Va&p)===p){u=u.next,p===aa&&(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,o=a):l=l.next=f,U.lanes|=p,zl|=p;f=u.action,Ka&&n(a,f),a=u.hasEagerState?u.eagerState:n(a,f)}else p={lane:f,revertLane:u.revertLane,action:u.action,hasEagerState:u.hasEagerState,eagerState:u.eagerState,next:null},l===null?(c=l=p,o=a):l=l.next=p,U.lanes|=f,zl|=f;u=u.next}while(u!==null&&u!==t);if(l===null?o=a:l.next=c,!yr(a,e.memoizedState)&&(Qs=!0,d&&(n=oa,n!==null)))throw n;e.memoizedState=a,e.baseState=o,e.baseQueue=l,r.lastRenderedState=a}return i===null&&(r.lanes=0),[e.memoizedState,r.dispatch]}function go(e){var t=so(),n=t.queue;if(n===null)throw Error(s(311));n.lastRenderedReducer=e;var r=n.dispatch,i=n.pending,a=t.memoizedState;if(i!==null){n.pending=null;var o=i=i.next;do a=e(a,o.action),o=o.next;while(o!==i);yr(a,t.memoizedState)||(Qs=!0),t.memoizedState=a,t.baseQueue===null&&(t.baseState=a),n.lastRenderedState=a}return[a,r]}function _o(e,t,n){var r=U,i=so(),a=V;if(a){if(n===void 0)throw Error(s(407));n=n()}else n=t();var o=!yr((Ha||i).memoizedState,n);if(o&&(i.memoizedState=n,Qs=!0),i=i.queue,Vo(2048,8,bo.bind(null,r,i,e),[e]),i.getSnapshot!==t||o||Ua!==null&&Ua.memoizedState.tag&1){if(r.flags|=2048,Lo(9,Ro(),yo.bind(null,r,i,n,t),null),jl===null)throw Error(s(349));a||Va&124||vo(r,t,n)}return n}function vo(e,t,n){e.flags|=16384,e={getSnapshot:t,value:n},t=U.updateQueue,t===null?(t=co(),U.updateQueue=t,t.stores=[e]):(n=t.stores,n===null?t.stores=[e]:n.push(e))}function yo(e,t,n,r){t.value=n,t.getSnapshot=r,xo(t)&&So(e)}function bo(e,t,n){return n(function(){xo(t)&&So(e)})}function xo(e){var t=e.getSnapshot;e=e.value;try{var n=t();return!yr(e,n)}catch{return!0}}function So(e){var t=ti(e,2);t!==null&&su(t,e,2)}function Co(e){var t=oo();if(typeof e==`function`){var n=e;if(e=n(),Ka){Oe(!0);try{n()}finally{Oe(!1)}}}return t.memoizedState=t.baseState=e,t.queue={pending:null,lanes:0,dispatch:null,lastRenderedReducer:po,lastRenderedState:e},t}function wo(e,t,n,r){return e.baseState=n,ho(e,Ha,typeof r==`function`?r:po)}function To(e,t,n,r,i){if(fs(e))throw Error(s(485));if(e=t.action,e!==null){var a={payload:i,action:e,next:null,isTransition:!0,status:`pending`,value:null,reason:null,listeners:[],then:function(e){a.listeners.push(e)}};N.T===null?a.isTransition=!1:n(!0),r(a),n=t.pending,n===null?(a.next=t.pending=a,Eo(t,a)):(a.next=n.next,t.pending=n.next=a)}}function Eo(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),Do(e,t,s)}catch(n){ko(e,t,n)}finally{N.T=a}}else try{a=n(i,r),Do(e,t,a)}catch(n){ko(e,t,n)}}function Do(e,t,n){typeof n==`object`&&n&&typeof n.then==`function`?n.then(function(n){Oo(e,t,n)},function(n){return ko(e,t,n)}):Oo(e,t,n)}function Oo(e,t,n){t.status=`fulfilled`,t.value=n,Ao(t),e.state=n,t=e.pending,t!==null&&(n=t.next,n===t?e.pending=null:(n=n.next,t.next=n,Eo(e,n)))}function ko(e,t,n){var r=e.pending;if(e.pending=null,r!==null){r=r.next;do t.status=`rejected`,t.reason=n,Ao(t),t=t.next;while(t!==r)}e.action=null}function Ao(e){e=e.listeners;for(var t=0;t<e.length;t++)(0,e[t])()}function jo(e,t){return t}function Mo(e,t){if(V){var n=jl.formState;if(n!==null){a:{var r=U;if(V){if(Di){b:{for(var i=Di,a=ki;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){Di=Jd(i.nextSibling),r=i.data===`F!`;break a}}ji(r)}r=!1}r&&(t=n[0])}}return n=oo(),n.memoizedState=n.baseState=t,r={pending:null,lanes:0,dispatch:null,lastRenderedReducer:jo,lastRenderedState:t},n.queue=r,n=ls.bind(null,U,r),r.dispatch=n,r=Co(!1),a=ds.bind(null,U,!1,r.queue),r=oo(),i={state:t,dispatch:null,action:e,pending:null},r.queue=i,n=To.bind(null,U,i,a,n),i.dispatch=n,r.memoizedState=e,[t,n,!1]}function No(e){return Po(so(),Ha,e)}function Po(e,t,n){if(t=ho(e,t,jo)[0],e=mo(po)[0],typeof t==`object`&&t&&typeof t.then==`function`)try{var r=lo(t)}catch(e){throw e===ma?ga:e}else r=t;t=so();var i=t.queue,a=i.dispatch;return n!==t.memoizedState&&(U.flags|=2048,Lo(9,Ro(),Fo.bind(null,i,n),null)),[r,a,e]}function Fo(e,t){e.action=t}function Io(e){var t=so(),n=Ha;if(n!==null)return Po(t,n,e);so(),t=t.memoizedState,n=so();var r=n.queue.dispatch;return n.memoizedState=e,[t,r,!1]}function Lo(e,t,n,r){return e={tag:e,create:n,deps:r,inst:t,next:null},t=U.updateQueue,t===null&&(t=co(),U.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 Ro(){return{destroy:void 0,resource:void 0}}function zo(){return so().memoizedState}function Bo(e,t,n,r){var i=oo();r=r===void 0?null:r,U.flags|=e,i.memoizedState=Lo(1|t,Ro(),n,r)}function Vo(e,t,n,r){var i=so();r=r===void 0?null:r;var a=i.memoizedState.inst;Ha!==null&&r!==null&&Qa(r,Ha.memoizedState.deps)?i.memoizedState=Lo(t,a,n,r):(U.flags|=e,i.memoizedState=Lo(1|t,a,n,r))}function Ho(e,t){Bo(8390656,8,e,t)}function Uo(e,t){Vo(2048,8,e,t)}function Wo(e,t){return Vo(4,2,e,t)}function Go(e,t){return Vo(4,4,e,t)}function Ko(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 qo(e,t,n){n=n==null?null:n.concat([e]),Vo(4,4,Ko.bind(null,t,e),n)}function Jo(){}function Yo(e,t){var n=so();t=t===void 0?null:t;var r=n.memoizedState;return t!==null&&Qa(t,r[1])?r[0]:(n.memoizedState=[e,t],e)}function Xo(e,t){var n=so();t=t===void 0?null:t;var r=n.memoizedState;if(t!==null&&Qa(t,r[1]))return r[0];if(r=e(),Ka){Oe(!0);try{e()}finally{Oe(!1)}}return n.memoizedState=[r,t],r}function Zo(e,t,n){return n===void 0||Va&1073741824?e.memoizedState=t:(e.memoizedState=n,e=ou(),U.lanes|=e,zl|=e,n)}function Qo(e,t,n,r){return yr(n,t)?n:Ia.current===null?Va&42?(e=ou(),U.lanes|=e,zl|=e,t):(Qs=!0,e.memoizedState=n):(e=Zo(e,n,r),yr(e,t)||(Qs=!0),e)}function $o(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,ds(e,!1,t,n);try{var c=i(),l=N.S;l!==null&&l(s,c),typeof c==`object`&&c&&typeof c.then==`function`?us(e,t,la(c,r),K(e)):us(e,t,r,K(e))}catch(n){us(e,t,{then:function(){},status:`rejected`,reason:n},K())}finally{P.p=a,N.T=o}}function es(){}function ts(e,t,n,r){if(e.tag!==5)throw Error(s(476));var i=ns(e).queue;$o(e,i,t,F,n===null?es:function(){return rs(e),n(r)})}function ns(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:po,lastRenderedState:F},next:null};var n={};return t.next={memoizedState:n,baseState:n,baseQueue:null,queue:{pending:null,lanes:0,dispatch:null,lastRenderedReducer:po,lastRenderedState:n},next:null},e.memoizedState=t,e=e.alternate,e!==null&&(e.memoizedState=t),t}function rs(e){var t=ns(e).next.queue;us(e,t,{},K())}function is(){return Ji(zf)}function as(){return so().memoizedState}function os(){return so().memoizedState}function ss(e){for(var t=e.return;t!==null;){switch(t.tag){case 24:case 3:var n=K();e=Da(n);var r=Oa(t,e,n);r!==null&&(su(r,t,n),ka(r,t,n)),t={cache:ta()},e.payload=t;return}t=t.return}}function cs(e,t,n){var r=K();n={lane:r,revertLane:0,action:n,hasEagerState:!1,eagerState:null,next:null},fs(e)?ps(t,n):(n=ei(e,t,n,r),n!==null&&(su(n,e,r),ms(n,t,r)))}function ls(e,t,n){us(e,t,n,K())}function us(e,t,n,r){var i={lane:r,revertLane:0,action:n,hasEagerState:!1,eagerState:null,next:null};if(fs(e))ps(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,yr(s,o))return $r(e,t,i,0),jl===null&&Qr(),!1}catch{}if(n=ei(e,t,i,r),n!==null)return su(n,e,r),ms(n,t,r),!0}return!1}function ds(e,t,n,r){if(r={lane:2,revertLane:nd(),action:r,hasEagerState:!1,eagerState:null,next:null},fs(e)){if(t)throw Error(s(479))}else t=ei(e,n,r,2),t!==null&&su(t,e,2)}function fs(e){var t=e.alternate;return e===U||t!==null&&t===U}function ps(e,t){Ga=Wa=!0;var n=e.pending;n===null?t.next=t:(t.next=n.next,n.next=t),e.pending=t}function ms(e,t,n){if(n&4194048){var r=t.lanes;r&=e.pendingLanes,n|=r,t.lanes=n,Ge(e,n)}}var hs={readContext:Ji,use:uo,useCallback:Za,useContext:Za,useEffect:Za,useImperativeHandle:Za,useLayoutEffect:Za,useInsertionEffect:Za,useMemo:Za,useReducer:Za,useRef:Za,useState:Za,useDebugValue:Za,useDeferredValue:Za,useTransition:Za,useSyncExternalStore:Za,useId:Za,useHostTransitionStatus:Za,useFormState:Za,useActionState:Za,useOptimistic:Za,useMemoCache:Za,useCacheRefresh:Za},gs={readContext:Ji,use:uo,useCallback:function(e,t){return oo().memoizedState=[e,t===void 0?null:t],e},useContext:Ji,useEffect:Ho,useImperativeHandle:function(e,t,n){n=n==null?null:n.concat([e]),Bo(4194308,4,Ko.bind(null,t,e),n)},useLayoutEffect:function(e,t){return Bo(4194308,4,e,t)},useInsertionEffect:function(e,t){Bo(4,2,e,t)},useMemo:function(e,t){var n=oo();t=t===void 0?null:t;var r=e();if(Ka){Oe(!0);try{e()}finally{Oe(!1)}}return n.memoizedState=[r,t],r},useReducer:function(e,t,n){var r=oo();if(n!==void 0){var i=n(t);if(Ka){Oe(!0);try{n(t)}finally{Oe(!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=cs.bind(null,U,e),[r.memoizedState,e]},useRef:function(e){var t=oo();return e={current:e},t.memoizedState=e},useState:function(e){e=Co(e);var t=e.queue,n=ls.bind(null,U,t);return t.dispatch=n,[e.memoizedState,n]},useDebugValue:Jo,useDeferredValue:function(e,t){return Zo(oo(),e,t)},useTransition:function(){var e=Co(!1);return e=$o.bind(null,U,e.queue,!0,!1),oo().memoizedState=e,[!1,e]},useSyncExternalStore:function(e,t,n){var r=U,i=oo();if(V){if(n===void 0)throw Error(s(407));n=n()}else{if(n=t(),jl===null)throw Error(s(349));G&124||vo(r,t,n)}i.memoizedState=n;var a={value:n,getSnapshot:t};return i.queue=a,Ho(bo.bind(null,r,a,e),[e]),r.flags|=2048,Lo(9,Ro(),yo.bind(null,r,a,n,t),null),n},useId:function(){var e=oo(),t=jl.identifierPrefix;if(V){var n=xi,r=bi;n=(r&~(1<<32-ke(r)-1)).toString(32)+n,t=`«`+t+`R`+n,n=qa++,0<n&&(t+=`H`+n.toString(32)),t+=`»`}else n=Xa++,t=`«`+t+`r`+n.toString(32)+`»`;return e.memoizedState=t},useHostTransitionStatus:is,useFormState:Mo,useActionState:Mo,useOptimistic:function(e){var t=oo();t.memoizedState=t.baseState=e;var n={pending:null,lanes:0,dispatch:null,lastRenderedReducer:null,lastRenderedState:null};return t.queue=n,t=ds.bind(null,U,!0,n),n.dispatch=t,[e,t]},useMemoCache:fo,useCacheRefresh:function(){return oo().memoizedState=ss.bind(null,U)}},_s={readContext:Ji,use:uo,useCallback:Yo,useContext:Ji,useEffect:Uo,useImperativeHandle:qo,useInsertionEffect:Wo,useLayoutEffect:Go,useMemo:Xo,useReducer:mo,useRef:zo,useState:function(){return mo(po)},useDebugValue:Jo,useDeferredValue:function(e,t){return Qo(so(),Ha.memoizedState,e,t)},useTransition:function(){var e=mo(po)[0],t=so().memoizedState;return[typeof e==`boolean`?e:lo(e),t]},useSyncExternalStore:_o,useId:as,useHostTransitionStatus:is,useFormState:No,useActionState:No,useOptimistic:function(e,t){return wo(so(),Ha,e,t)},useMemoCache:fo,useCacheRefresh:os},vs={readContext:Ji,use:uo,useCallback:Yo,useContext:Ji,useEffect:Uo,useImperativeHandle:qo,useInsertionEffect:Wo,useLayoutEffect:Go,useMemo:Xo,useReducer:go,useRef:zo,useState:function(){return go(po)},useDebugValue:Jo,useDeferredValue:function(e,t){var n=so();return Ha===null?Zo(n,e,t):Qo(n,Ha.memoizedState,e,t)},useTransition:function(){var e=go(po)[0],t=so().memoizedState;return[typeof e==`boolean`?e:lo(e),t]},useSyncExternalStore:_o,useId:as,useHostTransitionStatus:is,useFormState:Io,useActionState:Io,useOptimistic:function(e,t){var n=so();return Ha===null?(n.baseState=e,[e,n.queue.dispatch]):wo(n,Ha,e,t)},useMemoCache:fo,useCacheRefresh:os},ys=null,bs=0;function xs(e){var t=bs;return bs+=1,ys===null&&(ys=[]),ba(ys,e,t)}function Ss(e,t){t=t.props.ref,e.ref=t===void 0?null:t}function Cs(e,t){throw t.$$typeof===h?Error(s(525)):(e=Object.prototype.toString.call(t),Error(s(31,e===`[object Object]`?`object with keys {`+Object.keys(t).join(`, `)+`}`:e)))}function ws(e){var t=e._init;return t(e._payload)}function Ts(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 i(e,t){return e=si(e,t),e.index=0,e.sibling=null,e}function a(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 o(t){return e&&t.alternate===null&&(t.flags|=67108866),t}function c(e,t,n,r){return t===null||t.tag!==6?(t=di(n,e.mode,r),t.return=e,t):(t=i(t,n),t.return=e,t)}function l(e,t,n,r){var a=n.type;return a===v?d(e,t,n.props.children,r,n.key):t!==null&&(t.elementType===a||typeof a==`object`&&a&&a.$$typeof===D&&ws(a)===t.type)?(t=i(t,n.props),Ss(t,n),t.return=e,t):(t=li(n.type,n.key,n.props,null,e.mode,r),Ss(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=fi(n,e.mode,r),t.return=e,t):(t=i(t,n.children||[]),t.return=e,t)}function d(e,t,n,r,a){return t===null||t.tag!==7?(t=ui(n,e.mode,r,a),t.return=e,t):(t=i(t,n),t.return=e,t)}function f(e,t,n){if(typeof t==`string`&&t!==``||typeof t==`number`||typeof t==`bigint`)return t=di(``+t,e.mode,n),t.return=e,t;if(typeof t==`object`&&t){switch(t.$$typeof){case g:return n=li(t.type,t.key,t.props,null,e.mode,n),Ss(n,t),n.return=e,n;case _:return t=fi(t,e.mode,n),t.return=e,t;case D:var r=t._init;return t=r(t._payload),f(e,t,n)}if(ne(t)||j(t))return t=ui(t,e.mode,n,null),t.return=e,t;if(typeof t.then==`function`)return f(e,xs(t),n);if(t.$$typeof===C)return f(e,Yi(e,t),n);Cs(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 D:return i=n._init,n=i(n._payload),p(e,t,n,r)}if(ne(n)||j(n))return i===null?d(e,t,n,r,null):null;if(typeof n.then==`function`)return p(e,t,xs(n),r);if(n.$$typeof===C)return p(e,t,Yi(e,n),r);Cs(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 D:var a=r._init;return r=a(r._payload),m(e,t,n,r,i)}if(ne(r)||j(r))return e=e.get(n)||null,d(t,e,r,i,null);if(typeof r.then==`function`)return m(e,t,n,xs(r),i);if(r.$$typeof===C)return m(e,t,n,Yi(t,r),i);Cs(t,r)}return null}function h(i,o,s,c){for(var l=null,u=null,d=o,h=o=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),o=a(_,o,h),u===null?l=_:u.sibling=_,u=_,d=g}if(h===s.length)return n(i,d),V&&Si(i,h),l;if(d===null){for(;h<s.length;h++)d=f(i,s[h],c),d!==null&&(o=a(d,o,h),u===null?l=d:u.sibling=d,u=d);return V&&Si(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),o=a(g,o,h),u===null?l=g:u.sibling=g,u=g);return e&&d.forEach(function(e){return t(i,e)}),V&&Si(i,h),l}function y(i,o,c,l){if(c==null)throw Error(s(151));for(var u=null,d=null,h=o,g=o=0,_=null,v=c.next();h!==null&&!v.done;g++,v=c.next()){h.index>g?(_=h,h=null):_=h.sibling;var y=p(i,h,v.value,l);if(y===null){h===null&&(h=_);break}e&&h&&y.alternate===null&&t(i,h),o=a(y,o,g),d===null?u=y:d.sibling=y,d=y,h=_}if(v.done)return n(i,h),V&&Si(i,g),u;if(h===null){for(;!v.done;g++,v=c.next())v=f(i,v.value,l),v!==null&&(o=a(v,o,g),d===null?u=v:d.sibling=v,d=v);return V&&Si(i,g),u}for(h=r(h);!v.done;g++,v=c.next())v=m(h,i,g,v.value,l),v!==null&&(e&&v.alternate!==null&&h.delete(v.key===null?g:v.key),o=a(v,o,g),d===null?u=v:d.sibling=v,d=v);return e&&h.forEach(function(e){return t(i,e)}),V&&Si(i,g),u}function b(e,r,a,c){if(typeof a==`object`&&a&&a.type===v&&a.key===null&&(a=a.props.children),typeof a==`object`&&a){switch(a.$$typeof){case g:a:{for(var l=a.key;r!==null;){if(r.key===l){if(l=a.type,l===v){if(r.tag===7){n(e,r.sibling),c=i(r,a.props.children),c.return=e,e=c;break a}}else if(r.elementType===l||typeof l==`object`&&l&&l.$$typeof===D&&ws(l)===r.type){n(e,r.sibling),c=i(r,a.props),Ss(c,a),c.return=e,e=c;break a}n(e,r);break}t(e,r),r=r.sibling}a.type===v?(c=ui(a.props.children,e.mode,c,a.key),c.return=e,e=c):(c=li(a.type,a.key,a.props,null,e.mode,c),Ss(c,a),c.return=e,e=c)}return o(e);case _:a:{for(l=a.key;r!==null;){if(r.key===l){if(r.tag===4&&r.stateNode.containerInfo===a.containerInfo&&r.stateNode.implementation===a.implementation){n(e,r.sibling),c=i(r,a.children||[]),c.return=e,e=c;break a}n(e,r);break}t(e,r),r=r.sibling}c=fi(a,e.mode,c),c.return=e,e=c}return o(e);case D:return l=a._init,a=l(a._payload),b(e,r,a,c)}if(ne(a))return h(e,r,a,c);if(j(a)){if(l=j(a),typeof l!=`function`)throw Error(s(150));return a=l.call(a),y(e,r,a,c)}if(typeof a.then==`function`)return b(e,r,xs(a),c);if(a.$$typeof===C)return b(e,r,Yi(e,a),c);Cs(e,a)}return typeof a==`string`&&a!==``||typeof a==`number`||typeof a==`bigint`?(a=``+a,r!==null&&r.tag===6?(n(e,r.sibling),c=i(r,a),c.return=e,e=c):(n(e,r),c=di(a,e.mode,c),c.return=e,e=c),o(e)):n(e,r)}return function(e,t,n,r){try{bs=0;var i=b(e,t,n,r);return ys=null,i}catch(t){if(t===ma||t===ga)throw t;var a=ai(29,t,null,e.mode);return a.lanes=r,a.return=e,a}}}var Es=Ts(!0),Ds=Ts(!1),Os=I(null),ks=null;function As(e){var t=e.alternate;L(Ps,Ps.current&1),L(Os,e),ks===null&&(t===null||Ia.current!==null||t.memoizedState!==null)&&(ks=e)}function js(e){if(e.tag===22){if(L(Ps,Ps.current),L(Os,e),ks===null){var t=e.alternate;t!==null&&t.memoizedState!==null&&(ks=e)}}else Ms(e)}function Ms(){L(Ps,Ps.current),L(Os,Os.current)}function Ns(e){ae(Os),ks===e&&(ks=null),ae(Ps)}var Ps=I(0);function Fs(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 Is(e,t,n,r){t=e.memoizedState,n=n(r,t),n=n==null?t:m({},t,n),e.memoizedState=n,e.lanes===0&&(e.updateQueue.baseState=n)}var Ls={enqueueSetState:function(e,t,n){e=e._reactInternals;var r=K(),i=Da(r);i.payload=t,n!=null&&(i.callback=n),t=Oa(e,i,r),t!==null&&(su(t,e,r),ka(t,e,r))},enqueueReplaceState:function(e,t,n){e=e._reactInternals;var r=K(),i=Da(r);i.tag=1,i.payload=t,n!=null&&(i.callback=n),t=Oa(e,i,r),t!==null&&(su(t,e,r),ka(t,e,r))},enqueueForceUpdate:function(e,t){e=e._reactInternals;var n=K(),r=Da(n);r.tag=2,t!=null&&(r.callback=t),t=Oa(e,r,n),t!==null&&(su(t,e,n),ka(t,e,n))}};function Rs(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?!br(n,r)||!br(i,a):!0}function zs(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&&Ls.enqueueReplaceState(t,t.state,null)}function Bs(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=m({},n)),e)n[i]===void 0&&(n[i]=e[i]);return n}var Vs=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 Hs(e){Vs(e)}function Us(e){console.error(e)}function Ws(e){Vs(e)}function Gs(e,t){try{var n=e.onUncaughtError;n(t.value,{componentStack:t.stack})}catch(e){setTimeout(function(){throw e})}}function Ks(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 qs(e,t,n){return n=Da(n),n.tag=3,n.payload={element:null},n.callback=function(){Gs(e,t)},n}function Js(e){return e=Da(e),e.tag=3,e}function Ys(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(){Ks(t,n,r)}}var o=n.stateNode;o!==null&&typeof o.componentDidCatch==`function`&&(e.callback=function(){Ks(t,n,r),typeof i!=`function`&&(Xl===null?Xl=new Set([this]):Xl.add(this));var e=r.stack;this.componentDidCatch(r.value,{componentStack:e===null?``:e})})}function Xs(e,t,n,r,i){if(n.flags|=32768,typeof r==`object`&&r&&typeof r.then==`function`){if(t=n.alternate,t!==null&&Gi(t,n,i,!0),n=Os.current,n!==null){switch(n.tag){case 13:return ks===null?vu():n.alternate===null&&Rl===0&&(Rl=3),n.flags&=-257,n.flags|=65536,n.lanes=i,r===_a?n.flags|=16384:(t=n.updateQueue,t===null?n.updateQueue=new Set([r]):t.add(r),Iu(e,r,i)),!1;case 22:return n.flags|=65536,r===_a?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,i)),!1}throw Error(s(435,n.tag))}return Iu(e,r,i),vu(),!1}if(V)return t=Os.current,t===null?(r!==Ai&&(t=Error(s(423),{cause:r}),Li(Jr(t,n))),e=e.current.alternate,e.flags|=65536,i&=-i,e.lanes|=i,r=Jr(r,n),i=qs(e.stateNode,r,i),Aa(e,i),Rl!==4&&(Rl=2)):(!(t.flags&65536)&&(t.flags|=256),t.flags|=65536,t.lanes=i,r!==Ai&&(e=Error(s(422),{cause:r}),Li(Jr(e,n)))),!1;var a=Error(s(520),{cause:r});if(a=Jr(a,n),Wl===null?Wl=[a]:Wl.push(a),Rl!==4&&(Rl=2),t===null)return!0;r=Jr(r,n),n=t;do{switch(n.tag){case 3:return n.flags|=65536,e=i&-i,n.lanes|=e,e=qs(n.stateNode,r,e),Aa(n,e),!1;case 1:if(t=n.type,a=n.stateNode,!(n.flags&128)&&(typeof t.getDerivedStateFromError==`function`||a!==null&&typeof a.componentDidCatch==`function`&&(Xl===null||!Xl.has(a))))return n.flags|=65536,i&=-i,n.lanes|=i,i=Js(i),Ys(i,e,n,r),Aa(n,i),!1}n=n.return}while(n!==null);return!1}var Zs=Error(s(461)),Qs=!1;function $s(e,t,n,r){t.child=e===null?Ds(t,null,n,r):Es(t,e.child,n,r)}function ec(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 qi(t),r=$a(e,t,n,o,a,i),s=ro(),e!==null&&!Qs?(io(e,t,i),bc(e,t,i)):(V&&s&&wi(t),t.flags|=1,$s(e,t,r,i),t.child)}function tc(e,t,n,r,i){if(e===null){var a=n.type;return typeof a==`function`&&!oi(a)&&a.defaultProps===void 0&&n.compare===null?(t.tag=15,t.type=a,nc(e,t,a,r,i)):(e=li(n.type,null,r,t,t.mode,i),e.ref=t.ref,e.return=t,t.child=e)}if(a=e.child,!xc(e,i)){var o=a.memoizedProps;if(n=n.compare,n=n===null?br:n,n(o,r)&&e.ref===t.ref)return bc(e,t,i)}return t.flags|=1,e=si(a,r),e.ref=t.ref,e.return=t,t.child=e}function nc(e,t,n,r,i){if(e!==null){var a=e.memoizedProps;if(br(a,r)&&e.ref===t.ref){if(Qs=!1,t.pendingProps=r=a,xc(e,i))e.flags&131072&&(Qs=!0);else return t.lanes=e.lanes,bc(e,t,i)}}return oc(e,t,n,r,i)}function rc(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 ic(e,t,r,n)}if(n&536870912)t.memoizedState={baseLanes:0,cachePool:null},e!==null&&H(t,a===null?null:a.cachePool),a===null?za():Ra(t,a),js(t);else return t.lanes=t.childLanes=536870912,ic(e,t,a===null?n:a.baseLanes|n,n)}else a===null?(e!==null&&H(t,null),za(),Ms(t)):(H(t,a.cachePool),Ra(t,a),Ms(t),t.memoizedState=null);return $s(e,t,i,n),t.child}function ic(e,t,n,r){var i=fa();return i=i===null?null:{parent:ea._currentValue,pool:i},t.memoizedState={baseLanes:n,cachePool:i},e!==null&&H(t,null),za(),js(t),e!==null&&Gi(e,t,r,!0),null}function ac(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(s(284));(e===null||e.ref!==n)&&(t.flags|=4194816)}}function oc(e,t,n,r,i){return qi(t),n=$a(e,t,n,r,void 0,i),r=ro(),e!==null&&!Qs?(io(e,t,i),bc(e,t,i)):(V&&r&&wi(t),t.flags|=1,$s(e,t,n,i),t.child)}function sc(e,t,n,r,i,a){return qi(t),t.updateQueue=null,n=to(t,r,n,i),eo(e),r=ro(),e!==null&&!Qs?(io(e,t,a),bc(e,t,a)):(V&&r&&wi(t),t.flags|=1,$s(e,t,n,a),t.child)}function cc(e,t,n,r,i){if(qi(t),t.stateNode===null){var a=ri,o=n.contextType;typeof o==`object`&&o&&(a=Ji(o)),a=new n(r,a),t.memoizedState=a.state!==null&&a.state!==void 0?a.state:null,a.updater=Ls,t.stateNode=a,a._reactInternals=t,a=t.stateNode,a.props=r,a.state=t.memoizedState,a.refs={},Ta(t),o=n.contextType,a.context=typeof o==`object`&&o?Ji(o):ri,a.state=t.memoizedState,o=n.getDerivedStateFromProps,typeof o==`function`&&(Is(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&&Ls.enqueueReplaceState(a,a.state,null),Na(t,r,a,i),Ma(),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=Bs(n,s);a.props=c;var l=a.context,u=n.contextType;o=ri,typeof u==`object`&&u&&(o=Ji(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)&&zs(t,a,r,o),wa=!1;var f=t.memoizedState;a.state=f,Na(t,r,a,i),Ma(),l=t.memoizedState,s||f!==l||wa?(typeof d==`function`&&(Is(t,n,d,r),l=t.memoizedState),(c=wa||Rs(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,Ea(e,t),o=t.memoizedProps,u=Bs(n,o),a.props=u,d=t.pendingProps,f=a.context,l=n.contextType,c=ri,typeof l==`object`&&l&&(c=Ji(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)&&zs(t,a,r,c),wa=!1,f=t.memoizedState,a.state=f,Na(t,r,a,i),Ma();var p=t.memoizedState;o!==d||f!==p||wa||e!==null&&e.dependencies!==null&&Ki(e.dependencies)?(typeof s==`function`&&(Is(t,n,s,r),p=t.memoizedState),(u=wa||Rs(t,n,u,r,f,p,c)||e!==null&&e.dependencies!==null&&Ki(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,ac(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=Es(t,e.child,null,i),t.child=Es(t,null,n,i)):$s(e,t,n,i),t.memoizedState=a.state,e=t.child):e=bc(e,t,i),e}function lc(e,t,n,r){return Fi(),t.flags|=256,$s(e,t,n,r),t.child}var uc={dehydrated:null,treeContext:null,retryLane:0,hydrationErrors:null};function dc(e){return{baseLanes:e,cachePool:pa()}}function fc(e,t,n){return e=e===null?0:e.childLanes&~n,t&&(e|=Hl),e}function pc(e,t,n){var r=t.pendingProps,i=!1,a=!!(t.flags&128),o;if((o=a)||(o=e!==null&&e.memoizedState===null?!1:!!(Ps.current&2)),o&&(i=!0,t.flags&=-129),o=!!(t.flags&32),t.flags&=-33,e===null){if(V){if(i?As(t):Ms(t),V){var c=Di,l;if(l=c){c:{for(l=c,c=ki;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:yi===null?null:{id:bi,overflow:xi},retryLane:536870912,hydrationErrors:null},l=ai(18,null,null,0),l.stateNode=c,l.return=t,t.child=l,Ei=t,Di=null,l=!0)}l||ji(t)}if(c=t.memoizedState,c!==null&&(c=c.dehydrated,c!==null))return Kd(c)?t.lanes=32:t.lanes=536870912,null;Ns(t)}return c=r.children,r=r.fallback,i?(Ms(t),i=t.mode,c=hc({mode:`hidden`,children:c},i),r=ui(r,i,n,null),c.return=t,r.return=t,c.sibling=r,t.child=c,i=t.child,i.memoizedState=dc(n),i.childLanes=fc(e,o,n),t.memoizedState=uc,r):(As(t),mc(t,c))}if(l=e.memoizedState,l!==null&&(c=l.dehydrated,c!==null)){if(a)t.flags&256?(As(t),t.flags&=-257,t=gc(e,t,n)):t.memoizedState===null?(Ms(t),i=r.fallback,c=t.mode,r=hc({mode:`visible`,children:r.children},c),i=ui(i,c,n,null),i.flags|=2,r.return=t,i.return=t,r.sibling=i,t.child=r,Es(t,e.child,null,n),r=t.child,r.memoizedState=dc(n),r.childLanes=fc(e,o,n),t.memoizedState=uc,t=i):(Ms(t),t.child=e.child,t.flags|=128,t=null);else if(As(t),Kd(c)){if(o=c.nextSibling&&c.nextSibling.dataset,o)var u=o.dgst;o=u,r=Error(s(419)),r.stack=``,r.digest=o,Li({value:r,source:null,stack:null}),t=gc(e,t,n)}else if(Qs||Gi(e,t,n,!1),o=(n&e.childLanes)!==0,Qs||o){if(o=jl,o!==null&&(r=n&-n,r=r&42?1:Ke(r),r=(r&(o.suspendedLanes|n))===0?r:0,r!==0&&r!==l.retryLane))throw l.retryLane=r,ti(e,r),su(o,e,r),Zs;c.data===`$?`||vu(),t=gc(e,t,n)}else c.data===`$?`?(t.flags|=192,t.child=e.child,t=null):(e=l.treeContext,Di=Jd(c.nextSibling),Ei=t,V=!0,Oi=null,ki=!1,e!==null&&(_i[vi++]=bi,_i[vi++]=xi,_i[vi++]=yi,bi=e.id,xi=e.overflow,yi=t),t=mc(t,r.children),t.flags|=4096);return t}return i?(Ms(t),i=r.fallback,c=t.mode,l=e.child,u=l.sibling,r=si(l,{mode:`hidden`,children:r.children}),r.subtreeFlags=l.subtreeFlags&65011712,u===null?(i=ui(i,c,n,null),i.flags|=2):i=si(u,i),i.return=t,r.return=t,r.sibling=i,t.child=r,r=i,i=t.child,c=e.child.memoizedState,c===null?c=dc(n):(l=c.cachePool,l===null?l=pa():(u=ea._currentValue,l=l.parent===u?l:{parent:u,pool:u}),c={baseLanes:c.baseLanes|n,cachePool:l}),i.memoizedState=c,i.childLanes=fc(e,o,n),t.memoizedState=uc,r):(As(t),n=e.child,e=n.sibling,n=si(n,{mode:`visible`,children:r.children}),n.return=t,n.sibling=null,e!==null&&(o=t.deletions,o===null?(t.deletions=[e],t.flags|=16):o.push(e)),t.child=n,t.memoizedState=null,n)}function mc(e,t){return t=hc({mode:`visible`,children:t},e.mode),t.return=e,e.child=t}function hc(e,t){return e=ai(22,e,null,t),e.lanes=0,e.stateNode={_visibility:1,_pendingMarkers:null,_retryCache:null,_transitions:null},e}function gc(e,t,n){return Es(t,e.child,null,n),e=mc(t,t.pendingProps.children),e.flags|=2,t.memoizedState=null,e}function _c(e,t,n){e.lanes|=t;var r=e.alternate;r!==null&&(r.lanes|=t),Ui(e.return,t,n)}function vc(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 yc(e,t,n){var r=t.pendingProps,i=r.revealOrder,a=r.tail;if($s(e,t,r.children,n),r=Ps.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&&_c(e,n,t);else if(e.tag===19)_c(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(L(Ps,r),i){case`forwards`:for(n=t.child,i=null;n!==null;)e=n.alternate,e!==null&&Fs(e)===null&&(i=n),n=n.sibling;n=i,n===null?(i=t.child,t.child=null):(i=n.sibling,n.sibling=null),vc(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&&Fs(e)===null){t.child=i;break}e=i.sibling,i.sibling=n,n=i,i=e}vc(t,!0,n,null,a);break;case`together`:vc(t,!1,null,null,void 0);break;default:t.memoizedState=null}return t.child}function bc(e,t,n){if(e!==null&&(t.dependencies=e.dependencies),zl|=t.lanes,(n&t.childLanes)===0){if(e!==null){if(Gi(e,t,n,!1),(n&t.childLanes)===0)return null}else return null}if(e!==null&&t.child!==e.child)throw Error(s(153));if(t.child!==null){for(e=t.child,n=si(e,e.pendingProps),t.child=n,n.return=t;e.sibling!==null;)e=e.sibling,n=n.sibling=si(e,e.pendingProps),n.return=t;n.sibling=null}return t.child}function xc(e,t){return(e.lanes&t)!==0||(e=e.dependencies,!!(e!==null&&Ki(e)))}function Sc(e,t,n){switch(t.tag){case 3:le(t,t.stateNode.containerInfo),Vi(t,ea,e.memoizedState.cache),Fi();break;case 27:case 5:de(t);break;case 4:le(t,t.stateNode.containerInfo);break;case 10:Vi(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?(As(t),e=bc(e,t,n),e===null?null:e.sibling):pc(e,t,n):(As(t),t.flags|=128,null);As(t);break;case 19:var i=!!(e.flags&128);if(r=(n&t.childLanes)!==0,r||=(Gi(e,t,n,!1),(n&t.childLanes)!==0),i){if(r)return yc(e,t,n);t.flags|=128}if(i=t.memoizedState,i!==null&&(i.rendering=null,i.tail=null,i.lastEffect=null),L(Ps,Ps.current),r)break;return null;case 22:case 23:return t.lanes=0,rc(e,t,n);case 24:Vi(t,ea,e.memoizedState.cache)}return bc(e,t,n)}function Cc(e,t,n){if(e!==null){if(e.memoizedProps!==t.pendingProps)Qs=!0;else{if(!xc(e,n)&&!(t.flags&128))return Qs=!1,Sc(e,t,n);Qs=!!(e.flags&131072)}}else Qs=!1,V&&t.flags&1048576&&Ci(t,gi,t.index);switch(t.lanes=0,t.tag){case 16:a:{e=t.pendingProps;var r=t.elementType,i=r._init;if(r=i(r._payload),t.type=r,typeof r==`function`)oi(r)?(e=Bs(r,e),t.tag=1,t=cc(null,t,r,e,n)):(t.tag=0,t=oc(null,t,r,e,n));else{if(r!=null){if(i=r.$$typeof,i===w){t.tag=11,t=ec(null,t,r,e,n);break a}if(i===ee){t.tag=14,t=tc(null,t,r,e,n);break a}}throw t=M(r)||r,Error(s(306,t,``))}}return t;case 0:return oc(e,t,t.type,t.pendingProps,n);case 1:return r=t.type,i=Bs(r,t.pendingProps),cc(e,t,r,i,n);case 3:a:{if(le(t,t.stateNode.containerInfo),e===null)throw Error(s(387));r=t.pendingProps;var a=t.memoizedState;i=a.element,Ea(e,t),Na(t,r,null,n);var o=t.memoizedState;if(r=o.cache,Vi(t,ea,r),r!==a.cache&&Wi(t,[ea],n,!0),Ma(),r=o.element,a.isDehydrated){if(a={element:r,isDehydrated:!1,cache:o.cache},t.updateQueue.baseState=a,t.memoizedState=a,t.flags&256){t=lc(e,t,r,n);break a}if(r!==i){i=Jr(Error(s(424)),t),Li(i),t=lc(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(Di=Jd(e.firstChild),Ei=t,V=!0,Oi=null,ki=!0,n=Ds(t,null,r,n),t.child=n;n;)n.flags=n.flags&-3|4096,n=n.sibling}else{if(Fi(),r===i){t=bc(e,t,n);break a}$s(e,t,r,n)}t=t.child}return t;case 26:return ac(e,t),e===null?(n=hf(t.type,null,t.pendingProps,null))?t.memoizedState=n:V||(n=t.type,e=t.pendingProps,r=Ad(R.current).createElement(n),r[Ze]=t,r[Qe]=e,Ed(r,n,e),ut(r),t.stateNode=r):t.memoizedState=hf(t.type,e.memoizedProps,t.pendingProps,e.memoizedState),null;case 27:return de(t),e===null&&V&&(r=t.stateNode=Zd(t.type,t.pendingProps,R.current),Ei=t,ki=!0,i=Di,Vd(t.type)?(Yd=i,Di=Jd(r.firstChild)):Di=i),$s(e,t,t.pendingProps.children,n),ac(e,t),e===null&&(t.flags|=4194304),t.child;case 5:return e===null&&V&&((i=r=Di)&&(r=Wd(r,t.type,t.pendingProps,ki),r===null?i=!1:(t.stateNode=r,Ei=t,Di=Jd(r.firstChild),ki=!1,i=!0)),i||ji(t)),de(t),i=t.type,a=t.pendingProps,o=e===null?null:e.memoizedProps,r=a.children,Nd(i,a)?r=null:o!==null&&Nd(i,o)&&(t.flags|=32),t.memoizedState!==null&&(i=$a(e,t,no,null,null,n),zf._currentValue=i),ac(e,t),$s(e,t,r,n),t.child;case 6:return e===null&&V&&((e=n=Di)&&(n=Gd(n,t.pendingProps,ki),n===null?e=!1:(t.stateNode=n,Ei=t,Di=null,e=!0)),e||ji(t)),null;case 13:return pc(e,t,n);case 4:return le(t,t.stateNode.containerInfo),r=t.pendingProps,e===null?t.child=Es(t,null,r,n):$s(e,t,r,n),t.child;case 11:return ec(e,t,t.type,t.pendingProps,n);case 7:return $s(e,t,t.pendingProps,n),t.child;case 8:return $s(e,t,t.pendingProps.children,n),t.child;case 12:return $s(e,t,t.pendingProps.children,n),t.child;case 10:return r=t.pendingProps,Vi(t,t.type,r.value),$s(e,t,r.children,n),t.child;case 9:return i=t.type._context,r=t.pendingProps.children,qi(t),i=Ji(i),r=r(i),t.flags|=1,$s(e,t,r,n),t.child;case 14:return tc(e,t,t.type,t.pendingProps,n);case 15:return nc(e,t,t.type,t.pendingProps,n);case 19:return yc(e,t,n);case 31:return r=t.pendingProps,n=t.mode,r={mode:r.mode,children:r.children},e===null?(n=hc(r,n),n.ref=t.ref,t.child=n,n.return=t,t=n):(n=si(e.child,r),n.ref=t.ref,t.child=n,n.return=t,t=n),t;case 22:return rc(e,t,n);case 24:return qi(t),r=Ji(ea),e===null?(i=fa(),i===null&&(i=jl,a=ta(),i.pooledCache=a,a.refCount++,a!==null&&(i.pooledCacheLanes|=n),i=a),t.memoizedState={parent:r,cache:i},Ta(t),Vi(t,ea,i)):((e.lanes&n)!==0&&(Ea(e,t),Na(t,null,null,n),Ma()),i=e.memoizedState,a=t.memoizedState,i.parent===r?(r=a.cache,Vi(t,ea,r),r!==i.cache&&Wi(t,[ea],n,!0)):(i={parent:r,cache:r},t.memoizedState=i,t.lanes===0&&(t.memoizedState=t.updateQueue.baseState=i),Vi(t,ea,r))),$s(e,t,t.pendingProps.children,n),t.child;case 29:throw t.pendingProps}throw Error(s(156,t.tag))}function wc(e){e.flags|=4}function Tc(e,t){if(t.type!==`stylesheet`||t.state.loading&4)e.flags&=-16777217;else if(e.flags|=16777216,!Af(t)){if(t=Os.current,t!==null&&((G&4194048)===G?ks!==null:(G&62914560)!==G&&!(G&536870912)||t!==ks))throw xa=_a,ha;e.flags|=8192}}function Ec(e,t){t!==null&&(e.flags|=4),e.flags&16384&&(t=e.tag===22?536870912:Be(),e.lanes|=t,Ul|=t)}function Dc(e,t){if(!V)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 Oc(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 kc(e,t,n){var r=t.pendingProps;switch(Ti(t),t.tag){case 31:case 16:case 15:case 0:case 11:case 7:case 8:case 12:case 9:case 14:return Oc(t),null;case 1:return Oc(t),null;case 3:return n=t.stateNode,r=null,e!==null&&(r=e.memoizedState.cache),t.memoizedState.cache!==r&&(t.flags|=2048),Hi(ea),ue(),n.pendingContext&&(n.context=n.pendingContext,n.pendingContext=null),(e===null||e.child===null)&&(Pi(t)?wc(t):e===null||e.memoizedState.isDehydrated&&!(t.flags&256)||(t.flags|=1024,Ii())),Oc(t),null;case 26:return n=t.memoizedState,e===null?(wc(t),n===null?(Oc(t),t.flags&=-16777217):(Oc(t),Tc(t,n))):n?n===e.memoizedState?(Oc(t),t.flags&=-16777217):(wc(t),Oc(t),Tc(t,n)):(e.memoizedProps!==r&&wc(t),Oc(t),t.flags&=-16777217),null;case 27:fe(t),n=R.current;var i=t.type;if(e!==null&&t.stateNode!=null)e.memoizedProps!==r&&wc(t);else{if(!r){if(t.stateNode===null)throw Error(s(166));return Oc(t),null}e=oe.current,Pi(t)?Mi(t,e):(e=Zd(i,r,n),t.stateNode=e,wc(t))}return Oc(t),null;case 5:if(fe(t),n=t.type,e!==null&&t.stateNode!=null)e.memoizedProps!==r&&wc(t);else{if(!r){if(t.stateNode===null)throw Error(s(166));return Oc(t),null}if(e=oe.current,Pi(t))Mi(t,e);else{switch(i=Ad(R.current),e){case 1:e=i.createElementNS(`http://www.w3.org/2000/svg`,n);break;case 2:e=i.createElementNS(`http://www.w3.org/1998/Math/MathML`,n);break;default:switch(n){case`svg`:e=i.createElementNS(`http://www.w3.org/2000/svg`,n);break;case`math`:e=i.createElementNS(`http://www.w3.org/1998/Math/MathML`,n);break;case`script`:e=i.createElement(`div`),e.innerHTML=`<script><\/script>`,e=e.removeChild(e.firstChild);break;case`select`:e=typeof r.is==`string`?i.createElement(`select`,{is:r.is}):i.createElement(`select`),r.multiple?e.multiple=!0:r.size&&(e.size=r.size);break;default:e=typeof r.is==`string`?i.createElement(n,{is:r.is}):i.createElement(n)}}e[Ze]=t,e[Qe]=r;a:for(i=t.child;i!==null;){if(i.tag===5||i.tag===6)e.appendChild(i.stateNode);else if(i.tag!==4&&i.tag!==27&&i.child!==null){i.child.return=i,i=i.child;continue}if(i===t)break a;for(;i.sibling===null;){if(i.return===null||i.return===t)break a;i=i.return}i.sibling.return=i.return,i=i.sibling}t.stateNode=e;a:switch(Ed(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&&wc(t)}}return Oc(t),t.flags&=-16777217,null;case 6:if(e&&t.stateNode!=null)e.memoizedProps!==r&&wc(t);else{if(typeof r!=`string`&&t.stateNode===null)throw Error(s(166));if(e=R.current,Pi(t)){if(e=t.stateNode,n=t.memoizedProps,r=null,i=Ei,i!==null)switch(i.tag){case 27:case 5:r=i.memoizedProps}e[Ze]=t,e=!!(e.nodeValue===n||r!==null&&!0===r.suppressHydrationWarning||Cd(e.nodeValue,n)),e||ji(t)}else e=Ad(e).createTextNode(r),e[Ze]=t,t.stateNode=e}return Oc(t),null;case 13:if(r=t.memoizedState,e===null||e.memoizedState!==null&&e.memoizedState.dehydrated!==null){if(i=Pi(t),r!==null&&r.dehydrated!==null){if(e===null){if(!i)throw Error(s(318));if(i=t.memoizedState,i=i===null?null:i.dehydrated,!i)throw Error(s(317));i[Ze]=t}else Fi(),!(t.flags&128)&&(t.memoizedState=null),t.flags|=4;Oc(t),i=!1}else i=Ii(),e!==null&&e.memoizedState!==null&&(e.memoizedState.hydrationErrors=i),i=!0;if(!i)return t.flags&256?(Ns(t),t):(Ns(t),null)}if(Ns(t),t.flags&128)return t.lanes=n,t;if(n=r!==null,e=e!==null&&e.memoizedState!==null,n){r=t.child,i=null,r.alternate!==null&&r.alternate.memoizedState!==null&&r.alternate.memoizedState.cachePool!==null&&(i=r.alternate.memoizedState.cachePool.pool);var a=null;r.memoizedState!==null&&r.memoizedState.cachePool!==null&&(a=r.memoizedState.cachePool.pool),a!==i&&(r.flags|=2048)}return n!==e&&n&&(t.child.flags|=8192),Ec(t,t.updateQueue),Oc(t),null;case 4:return ue(),e===null&&pd(t.stateNode.containerInfo),Oc(t),null;case 10:return Hi(t.type),Oc(t),null;case 19:if(ae(Ps),i=t.memoizedState,i===null)return Oc(t),null;if(r=!!(t.flags&128),a=i.rendering,a===null){if(r)Dc(i,!1);else{if(Rl!==0||e!==null&&e.flags&128)for(e=t.child;e!==null;){if(a=Fs(e),a!==null){for(t.flags|=128,Dc(i,!1),e=a.updateQueue,t.updateQueue=e,Ec(t,e),t.subtreeFlags=0,e=n,n=t.child;n!==null;)ci(n,e),n=n.sibling;return L(Ps,Ps.current&1|2),t.child}e=e.sibling}i.tail!==null&&_e()>Jl&&(t.flags|=128,r=!0,Dc(i,!1),t.lanes=4194304)}}else{if(!r){if(e=Fs(a),e!==null){if(t.flags|=128,r=!0,e=e.updateQueue,t.updateQueue=e,Ec(t,e),Dc(i,!0),i.tail===null&&i.tailMode===`hidden`&&!a.alternate&&!V)return Oc(t),null}else 2*_e()-i.renderingStartTime>Jl&&n!==536870912&&(t.flags|=128,r=!0,Dc(i,!1),t.lanes=4194304)}i.isBackwards?(a.sibling=t.child,t.child=a):(e=i.last,e===null?t.child=a:e.sibling=a,i.last=a)}return i.tail===null?(Oc(t),null):(t=i.tail,i.rendering=t,i.tail=t.sibling,i.renderingStartTime=_e(),t.sibling=null,e=Ps.current,L(Ps,r?e&1|2:e&1),t);case 22:case 23:return Ns(t),Ba(),r=t.memoizedState!==null,e===null?r&&(t.flags|=8192):e.memoizedState!==null!==r&&(t.flags|=8192),r?n&536870912&&!(t.flags&128)&&(Oc(t),t.subtreeFlags&6&&(t.flags|=8192)):Oc(t),n=t.updateQueue,n!==null&&Ec(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&&ae(da),null;case 24:return n=null,e!==null&&(n=e.memoizedState.cache),t.memoizedState.cache!==n&&(t.flags|=2048),Hi(ea),Oc(t),null;case 25:return null;case 30:return null}throw Error(s(156,t.tag))}function Ac(e,t){switch(Ti(t),t.tag){case 1:return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 3:return Hi(ea),ue(),e=t.flags,e&65536&&!(e&128)?(t.flags=e&-65537|128,t):null;case 26:case 27:case 5:return fe(t),null;case 13:if(Ns(t),e=t.memoizedState,e!==null&&e.dehydrated!==null){if(t.alternate===null)throw Error(s(340));Fi()}return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 19:return ae(Ps),null;case 4:return ue(),null;case 10:return Hi(t.type),null;case 22:case 23:return Ns(t),Ba(),e!==null&&ae(da),e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 24:return Hi(ea),null;case 25:return null;default:return null}}function jc(e,t){switch(Ti(t),t.tag){case 3:Hi(ea),ue();break;case 26:case 27:case 5:fe(t);break;case 4:ue();break;case 13:Ns(t);break;case 19:ae(Ps);break;case 10:Hi(t.type);break;case 22:case 23:Ns(t),Ba(),e!==null&&ae(da);break;case 24:Hi(ea)}}function Mc(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){q(t,t.return,e)}}function Nc(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){q(i,c,e)}}}r=r.next}while(r!==a)}}catch(e){q(t,t.return,e)}}function Pc(e){var t=e.updateQueue;if(t!==null){var n=e.stateNode;try{Fa(t,n)}catch(t){q(e,e.return,t)}}}function Fc(e,t,n){n.props=Bs(e.type,e.memoizedProps),n.state=e.memoizedState;try{n.componentWillUnmount()}catch(n){q(e,t,n)}}function Ic(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){q(e,t,n)}}function Lc(e,t){var n=e.ref,r=e.refCleanup;if(n!==null){if(typeof r==`function`)try{r()}catch(n){q(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){q(e,t,n)}else n.current=null}}function Rc(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){q(e,e.return,t)}}function zc(e,t,n){try{var r=e.stateNode;Dd(r,e.type,n,t),r[Qe]=t}catch(t){q(e,e.return,t)}}function Bc(e){return e.tag===5||e.tag===3||e.tag===26||e.tag===27&&Vd(e.type)||e.tag===4}function Vc(e){a:for(;;){for(;e.sibling===null;){if(e.return===null||Bc(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 Hc(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(Hc(e,t,n),e=e.sibling;e!==null;)Hc(e,t,n),e=e.sibling}function Uc(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(Uc(e,t,n),e=e.sibling;e!==null;)Uc(e,t,n),e=e.sibling}function Wc(e){var t=e.stateNode,n=e.memoizedProps;try{for(var r=e.type,i=t.attributes;i.length;)t.removeAttributeNode(i[0]);Ed(t,r,n),t[Ze]=e,t[Qe]=n}catch(t){q(e,e.return,t)}}var Gc=!1,Kc=!1,qc=!1,Jc=typeof WeakSet==`function`?WeakSet:Set,Yc=null;function Xc(e,t){if(e=e.containerInfo,Od=qf,e=wr(e),Tr(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 i=r.anchorOffset,a=r.focusNode;r=r.focusOffset;try{n.nodeType,a.nodeType}catch{n=null;break a}var o=0,c=-1,l=-1,u=0,d=0,f=e,p=null;b:for(;;){for(var m;f!==n||i!==0&&f.nodeType!==3||(c=o+i),f!==a||r!==0&&f.nodeType!==3||(l=o+r),f.nodeType===3&&(o+=f.nodeValue.length),(m=f.firstChild)!==null;)p=f,f=m;for(;;){if(f===e)break b;if(p===n&&++u===i&&(c=o),p===a&&++d===r&&(l=o),(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,Yc=t;Yc!==null;)if(t=Yc,e=t.child,t.subtreeFlags&1024&&e!==null)e.return=t,Yc=e;else for(;Yc!==null;){switch(t=Yc,a=t.alternate,e=t.flags,t.tag){case 0:break;case 11:case 15:break;case 1:if(e&1024&&a!==null){e=void 0,n=t,i=a.memoizedProps,a=a.memoizedState,r=n.stateNode;try{var h=Bs(n.type,i,n.elementType===n.type);e=r.getSnapshotBeforeUpdate(h,a),r.__reactInternalSnapshotBeforeUpdate=e}catch(e){q(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(s(163))}if(e=t.sibling,e!==null){e.return=t.return,Yc=e;break}Yc=t.return}}function Zc(e,t,n){var r=n.flags;switch(n.tag){case 0:case 11:case 15:dl(e,n),r&4&&Mc(5,n);break;case 1:if(dl(e,n),r&4){if(e=n.stateNode,t===null)try{e.componentDidMount()}catch(e){q(n,n.return,e)}else{var i=Bs(n.type,t.memoizedProps);t=t.memoizedState;try{e.componentDidUpdate(i,t,e.__reactInternalSnapshotBeforeUpdate)}catch(e){q(n,n.return,e)}}}r&64&&Pc(n),r&512&&Ic(n,n.return);break;case 3:if(dl(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{Fa(e,t)}catch(e){q(n,n.return,e)}}break;case 27:t===null&&r&4&&Wc(n);case 26:case 5:dl(e,n),t===null&&r&4&&Rc(n),r&512&&Ic(n,n.return);break;case 12:dl(e,n);break;case 13:dl(e,n),r&4&&rl(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||Gc,!r){t=t!==null&&t.memoizedState!==null||Kc,i=Gc;var a=Kc;Gc=r,(Kc=t)&&!a?pl(e,n,!!(n.subtreeFlags&8772)):dl(e,n),Gc=i,Kc=a}break;case 30:break;default:dl(e,n)}}function Qc(e){var t=e.alternate;t!==null&&(e.alternate=null,Qc(t)),e.child=null,e.deletions=null,e.sibling=null,e.tag===5&&(t=e.stateNode,t!==null&&at(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 $c=null,el=!1;function tl(e,t,n){for(n=n.child;n!==null;)nl(e,t,n),n=n.sibling}function nl(e,t,n){if(De&&typeof De.onCommitFiberUnmount==`function`)try{De.onCommitFiberUnmount(Ee,n)}catch{}switch(n.tag){case 26:Kc||Lc(n,t),tl(e,t,n),n.memoizedState?n.memoizedState.count--:n.stateNode&&(n=n.stateNode,n.parentNode.removeChild(n));break;case 27:Kc||Lc(n,t);var r=$c,i=el;Vd(n.type)&&($c=n.stateNode,el=!1),tl(e,t,n),Qd(n.stateNode),$c=r,el=i;break;case 5:Kc||Lc(n,t);case 6:if(r=$c,i=el,$c=null,tl(e,t,n),$c=r,el=i,$c!==null){if(el)try{($c.nodeType===9?$c.body:$c.nodeName===`HTML`?$c.ownerDocument.body:$c).removeChild(n.stateNode)}catch(e){q(n,t,e)}else try{$c.removeChild(n.stateNode)}catch(e){q(n,t,e)}}break;case 18:$c!==null&&(el?(e=$c,Hd(e.nodeType===9?e.body:e.nodeName===`HTML`?e.ownerDocument.body:e,n.stateNode),_p(e)):Hd($c,n.stateNode));break;case 4:r=$c,i=el,$c=n.stateNode.containerInfo,el=!0,tl(e,t,n),$c=r,el=i;break;case 0:case 11:case 14:case 15:Kc||Nc(2,n,t),Kc||Nc(4,n,t),tl(e,t,n);break;case 1:Kc||(Lc(n,t),r=n.stateNode,typeof r.componentWillUnmount==`function`&&Fc(n,t,r)),tl(e,t,n);break;case 21:tl(e,t,n);break;case 22:Kc=(r=Kc)||n.memoizedState!==null,tl(e,t,n),Kc=r;break;default:tl(e,t,n)}}function rl(e,t){if(t.memoizedState===null&&(e=t.alternate,e!==null&&(e=e.memoizedState,e!==null&&(e=e.dehydrated,e!==null))))try{_p(e)}catch(e){q(t,t.return,e)}}function il(e){switch(e.tag){case 13:case 19:var t=e.stateNode;return t===null&&(t=e.stateNode=new Jc),t;case 22:return e=e.stateNode,t=e._retryCache,t===null&&(t=e._retryCache=new Jc),t;default:throw Error(s(435,e.tag))}}function al(e,t){var n=il(e);t.forEach(function(t){var r=Bu.bind(null,e,t);n.has(t)||(n.add(t),t.then(r,r))})}function ol(e,t){var n=t.deletions;if(n!==null)for(var r=0;r<n.length;r++){var i=n[r],a=e,o=t,c=o;a:for(;c!==null;){switch(c.tag){case 27:if(Vd(c.type)){$c=c.stateNode,el=!1;break a}break;case 5:$c=c.stateNode,el=!1;break a;case 3:case 4:$c=c.stateNode.containerInfo,el=!0;break a}c=c.return}if($c===null)throw Error(s(160));nl(a,o,i),$c=null,el=!1,a=i.alternate,a!==null&&(a.return=null),i.return=null}if(t.subtreeFlags&13878)for(t=t.child;t!==null;)cl(t,e),t=t.sibling}var sl=null;function cl(e,t){var n=e.alternate,r=e.flags;switch(e.tag){case 0:case 11:case 14:case 15:ol(t,e),ll(e),r&4&&(Nc(3,e,e.return),Mc(3,e),Nc(5,e,e.return));break;case 1:ol(t,e),ll(e),r&512&&(Kc||n===null||Lc(n,n.return)),r&64&&Gc&&(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 i=sl;if(ol(t,e),ll(e),r&512&&(Kc||n===null||Lc(n,n.return)),r&4){var a=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,i=i.ownerDocument||i;b:switch(r){case`title`:a=i.getElementsByTagName(`title`)[0],(!a||a[it]||a[Ze]||a.namespaceURI===`http://www.w3.org/2000/svg`||a.hasAttribute(`itemprop`))&&(a=i.createElement(r),i.head.insertBefore(a,i.querySelector(`head > title`))),Ed(a,r,n),a[Ze]=e,ut(a),r=a;break a;case`link`:var o=Df(`link`,`href`,i).get(r+(n.href||``));if(o){for(var c=0;c<o.length;c++)if(a=o[c],a.getAttribute(`href`)===(n.href==null||n.href===``?null:n.href)&&a.getAttribute(`rel`)===(n.rel==null?null:n.rel)&&a.getAttribute(`title`)===(n.title==null?null:n.title)&&a.getAttribute(`crossorigin`)===(n.crossOrigin==null?null:n.crossOrigin)){o.splice(c,1);break b}}a=i.createElement(r),Ed(a,r,n),i.head.appendChild(a);break;case`meta`:if(o=Df(`meta`,`content`,i).get(r+(n.content||``))){for(c=0;c<o.length;c++)if(a=o[c],a.getAttribute(`content`)===(n.content==null?null:``+n.content)&&a.getAttribute(`name`)===(n.name==null?null:n.name)&&a.getAttribute(`property`)===(n.property==null?null:n.property)&&a.getAttribute(`http-equiv`)===(n.httpEquiv==null?null:n.httpEquiv)&&a.getAttribute(`charset`)===(n.charSet==null?null:n.charSet)){o.splice(c,1);break b}}a=i.createElement(r),Ed(a,r,n),i.head.appendChild(a);break;default:throw Error(s(468,r))}a[Ze]=e,ut(a),r=a}e.stateNode=r}else Of(i,e.type,e.stateNode)}else e.stateNode=Sf(i,r,e.memoizedProps)}else a===r?r===null&&e.stateNode!==null&&zc(e,e.memoizedProps,n.memoizedProps):(a===null?n.stateNode!==null&&(n=n.stateNode,n.parentNode.removeChild(n)):a.count--,r===null?Of(i,e.type,e.stateNode):Sf(i,r,e.memoizedProps))}break;case 27:ol(t,e),ll(e),r&512&&(Kc||n===null||Lc(n,n.return)),n!==null&&r&4&&zc(e,e.memoizedProps,n.memoizedProps);break;case 5:if(ol(t,e),ll(e),r&512&&(Kc||n===null||Lc(n,n.return)),e.flags&32){i=e.stateNode;try{Ut(i,``)}catch(t){q(e,e.return,t)}}r&4&&e.stateNode!=null&&(i=e.memoizedProps,zc(e,i,n===null?i:n.memoizedProps)),r&1024&&(qc=!0);break;case 6:if(ol(t,e),ll(e),r&4){if(e.stateNode===null)throw Error(s(162));r=e.memoizedProps,n=e.stateNode;try{n.nodeValue=r}catch(t){q(e,e.return,t)}}break;case 3:if(Ef=null,i=sl,sl=tf(t.containerInfo),ol(t,e),sl=i,ll(e),r&4&&n!==null&&n.memoizedState.isDehydrated)try{_p(t.containerInfo)}catch(t){q(e,e.return,t)}qc&&(qc=!1,ul(e));break;case 4:r=sl,sl=tf(e.stateNode.containerInfo),ol(t,e),ll(e),sl=r;break;case 12:ol(t,e),ll(e);break;case 13:ol(t,e),ll(e),e.child.flags&8192&&e.memoizedState!==null!=(n!==null&&n.memoizedState!==null)&&(ql=_e()),r&4&&(r=e.updateQueue,r!==null&&(e.updateQueue=null,al(e,r)));break;case 22:i=e.memoizedState!==null;var l=n!==null&&n.memoizedState!==null,u=Gc,d=Kc;if(Gc=u||i,Kc=d||l,ol(t,e),Kc=d,Gc=u,ll(e),r&8192)a:for(t=e.stateNode,t._visibility=i?t._visibility&-2:t._visibility|1,i&&(n===null||l||Gc||Kc||fl(e)),n=null,t=e;;){if(t.tag===5||t.tag===26){if(n===null){l=n=t;try{if(a=l.stateNode,i)o=a.style,typeof o.setProperty==`function`?o.setProperty(`display`,`none`,`important`):o.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){q(l,l.return,e)}}}else if(t.tag===6){if(n===null){l=t;try{l.stateNode.nodeValue=i?``:l.memoizedProps}catch(e){q(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,al(e,n))));break;case 19:ol(t,e),ll(e),r&4&&(r=e.updateQueue,r!==null&&(e.updateQueue=null,al(e,r)));break;case 30:break;case 21:break;default:ol(t,e),ll(e)}}function ll(e){var t=e.flags;if(t&2){try{for(var n,r=e.return;r!==null;){if(Bc(r)){n=r;break}r=r.return}if(n==null)throw Error(s(160));switch(n.tag){case 27:var i=n.stateNode;Uc(e,Vc(e),i);break;case 5:var a=n.stateNode;n.flags&32&&(Ut(a,``),n.flags&=-33),Uc(e,Vc(e),a);break;case 3:case 4:var o=n.stateNode.containerInfo;Hc(e,Vc(e),o);break;default:throw Error(s(161))}}catch(t){q(e,e.return,t)}e.flags&=-3}t&4096&&(e.flags&=-4097)}function ul(e){if(e.subtreeFlags&1024)for(e=e.child;e!==null;){var t=e;ul(t),t.tag===5&&t.flags&1024&&t.stateNode.reset(),e=e.sibling}}function dl(e,t){if(t.subtreeFlags&8772)for(t=t.child;t!==null;)Zc(e,t.alternate,t),t=t.sibling}function fl(e){for(e=e.child;e!==null;){var t=e;switch(t.tag){case 0:case 11:case 14:case 15:Nc(4,t,t.return),fl(t);break;case 1:Lc(t,t.return);var n=t.stateNode;typeof n.componentWillUnmount==`function`&&Fc(t,t.return,n),fl(t);break;case 27:Qd(t.stateNode);case 26:case 5:Lc(t,t.return),fl(t);break;case 22:t.memoizedState===null&&fl(t);break;case 30:fl(t);break;default:fl(t)}e=e.sibling}}function pl(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:pl(i,a,n),Mc(4,a);break;case 1:if(pl(i,a,n),r=a,i=r.stateNode,typeof i.componentDidMount==`function`)try{i.componentDidMount()}catch(e){q(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++)Pa(c[i],s)}catch(e){q(r,r.return,e)}}n&&o&64&&Pc(a),Ic(a,a.return);break;case 27:Wc(a);case 26:case 5:pl(i,a,n),n&&r===null&&o&4&&Rc(a),Ic(a,a.return);break;case 12:pl(i,a,n);break;case 13:pl(i,a,n),n&&o&4&&rl(i,a);break;case 22:a.memoizedState===null&&pl(i,a,n),Ic(a,a.return);break;case 30:break;default:pl(i,a,n)}t=t.sibling}}function ml(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&&na(n))}function hl(e,t){e=null,t.alternate!==null&&(e=t.alternate.memoizedState.cache),t=t.memoizedState.cache,t!==e&&(t.refCount++,e!=null&&na(e))}function gl(e,t,n,r){if(t.subtreeFlags&10256)for(t=t.child;t!==null;)_l(e,t,n,r),t=t.sibling}function _l(e,t,n,r){var i=t.flags;switch(t.tag){case 0:case 11:case 15:gl(e,t,n,r),i&2048&&Mc(9,t);break;case 1:gl(e,t,n,r);break;case 3:gl(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&&na(e)));break;case 12:if(i&2048){gl(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){q(t,t.return,e)}}else gl(e,t,n,r);break;case 13:gl(e,t,n,r);break;case 23:break;case 22:a=t.stateNode,o=t.alternate,t.memoizedState===null?a._visibility&2?gl(e,t,n,r):(a._visibility|=2,vl(e,t,n,r,!!(t.subtreeFlags&10256))):a._visibility&2?gl(e,t,n,r):yl(e,t),i&2048&&ml(o,t);break;case 24:gl(e,t,n,r),i&2048&&hl(t.alternate,t);break;default:gl(e,t,n,r)}}function vl(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:vl(a,o,s,c,i),Mc(8,o);break;case 23:break;case 22:var u=o.stateNode;o.memoizedState===null?(u._visibility|=2,vl(a,o,s,c,i)):u._visibility&2?vl(a,o,s,c,i):yl(a,o),i&&l&2048&&ml(o.alternate,o);break;case 24:vl(a,o,s,c,i),i&&l&2048&&hl(o.alternate,o);break;default:vl(a,o,s,c,i)}t=t.sibling}}function yl(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:yl(n,r),i&2048&&ml(r.alternate,r);break;case 24:yl(n,r),i&2048&&hl(r.alternate,r);break;default:yl(n,r)}t=t.sibling}}var bl=8192;function xl(e){if(e.subtreeFlags&bl)for(e=e.child;e!==null;)Sl(e),e=e.sibling}function Sl(e){switch(e.tag){case 26:xl(e),e.flags&bl&&e.memoizedState!==null&&Nf(sl,e.memoizedState,e.memoizedProps);break;case 5:xl(e);break;case 3:case 4:var t=sl;sl=tf(e.stateNode.containerInfo),xl(e),sl=t;break;case 22:e.memoizedState===null&&(t=e.alternate,t!==null&&t.memoizedState!==null?(t=bl,bl=16777216,xl(e),bl=t):xl(e));break;default:xl(e)}}function Cl(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 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];Yc=r,Dl(r,e)}Cl(e)}if(e.subtreeFlags&10256)for(e=e.child;e!==null;)Tl(e),e=e.sibling}function Tl(e){switch(e.tag){case 0:case 11:case 15:wl(e),e.flags&2048&&Nc(9,e,e.return);break;case 3:wl(e);break;case 12:wl(e);break;case 22:var t=e.stateNode;e.memoizedState!==null&&t._visibility&2&&(e.return===null||e.return.tag!==13)?(t._visibility&=-3,El(e)):wl(e);break;default:wl(e)}}function El(e){var t=e.deletions;if(e.flags&16){if(t!==null)for(var n=0;n<t.length;n++){var r=t[n];Yc=r,Dl(r,e)}Cl(e)}for(e=e.child;e!==null;){switch(t=e,t.tag){case 0:case 11:case 15:Nc(8,t,t.return),El(t);break;case 22:n=t.stateNode,n._visibility&2&&(n._visibility&=-3,El(t));break;default:El(t)}e=e.sibling}}function Dl(e,t){for(;Yc!==null;){var n=Yc;switch(n.tag){case 0:case 11:case 15:Nc(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:na(n.memoizedState.cache)}if(r=n.child,r!==null)r.return=n,Yc=r;else a:for(n=e;Yc!==null;){r=Yc;var i=r.sibling,a=r.return;if(Qc(r),r===n){Yc=null;break a}if(i!==null){i.return=a,Yc=i;break a}Yc=a}}}var Ol={getCacheForType:function(e){var t=Ji(ea),n=t.data.get(e);return n===void 0&&(n=e(),t.data.set(e,n)),n}},kl=typeof WeakMap==`function`?WeakMap:Map,Al=0,jl=null,W=null,G=0,Ml=0,Nl=null,Pl=!1,Fl=!1,Il=!1,Ll=0,Rl=0,zl=0,Bl=0,Vl=0,Hl=0,Ul=0,Wl=null,Gl=null,Kl=!1,ql=0,Jl=1/0,Yl=null,Xl=null,Zl=0,Ql=null,$l=null,eu=0,tu=0,nu=null,ru=null,iu=0,au=null;function K(){if(Al&2&&G!==0)return G&-G;if(N.T!==null){var e=aa;return e===0?nd():e}return Je()}function ou(){Hl===0&&(Hl=!(G&536870912)||V?ze():536870912);var e=Os.current;return e!==null&&(e.flags|=32),Hl}function su(e,t,n){(e===jl&&(Ml===2||Ml===9)||e.cancelPendingCommit!==null)&&(mu(e,0),du(e,G,Hl,!1)),He(e,n),Al&2&&e===jl||(e===jl&&(!(Al&2)&&(Bl|=n),Rl===4&&du(e,G,Hl,!1)),Ju(e))}function cu(e,t,n){if(Al&6)throw Error(s(327));var r=!n&&!(t&124)&&(t&e.expiredLanes)===0||Le(e,t),i=r?xu(e,t):yu(e,t,!0),a=r;do{if(i===0){Fl&&!r&&du(e,t,0,!1);break}if(n=e.current.alternate,a&&!uu(n))i=yu(e,t,!1),a=!1;else{if(i===2){if(a=t,e.errorRecoveryDisabledLanes&a)var o=0;else o=e.pendingLanes&-536870913,o=o===0?o&536870912?536870912:0:o;if(o!==0){t=o;a:{var c=e;i=Wl;var l=c.current.memoizedState.isDehydrated;if(l&&(mu(c,o).flags|=256),o=yu(c,o,!1),o!==2){if(Il&&!l){c.errorRecoveryDisabledLanes|=a,Bl|=a,i=4;break a}a=Gl,Gl=i,a!==null&&(Gl===null?Gl=a:Gl.push.apply(Gl,a))}i=o}if(a=!1,i!==2)continue}}if(i===1){mu(e,0),du(e,t,0,!0);break}a:{switch(r=e,a=i,a){case 0:case 1:throw Error(s(345));case 4:if((t&4194048)!==t)break;case 6:du(r,t,Hl,!Pl);break a;case 2:Gl=null;break;case 3:case 5:break;default:throw Error(s(329))}if((t&62914560)===t&&(i=ql+300-_e(),10<i)){if(du(r,t,Hl,!Pl),Ie(r,0,!0)!==0)break a;r.timeoutHandle=Id(lu.bind(null,r,n,Gl,Yl,Kl,t,Hl,Bl,Ul,Pl,a,2,-0,0),i);break a}lu(r,n,Gl,Yl,Kl,t,Hl,Bl,Ul,Pl,a,0,-0,0)}break}}while(1);Ju(e)}function lu(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},Sl(t),d=Pf(),d!==null)?(e.cancelPendingCommit=d(Ou.bind(null,e,t,a,n,r,i,o,s,c,u,1,f,p)),du(e,a,o,!l)):Ou(e,t,a,n,r,i,o,s,c)}function uu(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(!yr(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 du(e,t,n,r){t&=~Vl,t&=~Bl,e.suspendedLanes|=t,e.pingedLanes&=~t,r&&(e.warmLanes|=t),r=e.expirationTimes;for(var i=t;0<i;){var a=31-ke(i),o=1<<a;r[a]=-1,i&=~o}n!==0&&We(e,n,t)}function fu(){return Al&6?!0:(Yu(0,!1),!1)}function pu(){if(W!==null){if(Ml===0)var e=W.return;else e=W,Bi=zi=null,ao(e),ys=null,bs=0,e=W;for(;e!==null;)jc(e.alternate,e),e=e.return;W=null}}function mu(e,t){var n=e.timeoutHandle;n!==-1&&(e.timeoutHandle=-1,Ld(n)),n=e.cancelPendingCommit,n!==null&&(e.cancelPendingCommit=null,n()),pu(),jl=e,W=n=si(e.current,null),G=t,Ml=0,Nl=null,Pl=!1,Fl=Le(e,t),Il=!1,Ul=Hl=Vl=Bl=zl=Rl=0,Gl=Wl=null,Kl=!1,t&8&&(t|=t&32);var r=e.entangledLanes;if(r!==0)for(e=e.entanglements,r&=t;0<r;){var i=31-ke(r),a=1<<i;t|=e[i],r&=~a}return Ll=t,Qr(),n}function hu(e,t){U=null,N.H=hs,t===ma||t===ga?(t=Sa(),Ml=3):t===ha?(t=Sa(),Ml=4):Ml=t===Zs?8:typeof t==`object`&&t&&typeof t.then==`function`?6:1,Nl=t,W===null&&(Rl=1,Gs(e,Jr(t,e.current)))}function gu(){var e=N.H;return N.H=hs,e===null?hs:e}function _u(){var e=N.A;return N.A=Ol,e}function vu(){Rl=4,Pl||(G&4194048)!==G&&Os.current!==null||(Fl=!0),!(zl&134217727)&&!(Bl&134217727)||jl===null||du(jl,G,Hl,!1)}function yu(e,t,n){var r=Al;Al|=2;var i=gu(),a=_u();(jl!==e||G!==t)&&(Yl=null,mu(e,t)),t=!1;var o=Rl;a:do try{if(Ml!==0&&W!==null){var s=W,c=Nl;switch(Ml){case 8:pu(),o=6;break a;case 3:case 2:case 9:case 6:Os.current===null&&(t=!0);var l=Ml;if(Ml=0,Nl=null,Tu(e,s,c,l),n&&Fl){o=0;break a}break;default:l=Ml,Ml=0,Nl=null,Tu(e,s,c,l)}}bu(),o=Rl;break}catch(t){hu(e,t)}while(1);return t&&e.shellSuspendCounter++,Bi=zi=null,Al=r,N.H=i,N.A=a,W===null&&(jl=null,G=0,Qr()),o}function bu(){for(;W!==null;)Cu(W)}function xu(e,t){var n=Al;Al|=2;var r=gu(),i=_u();jl!==e||G!==t?(Yl=null,Jl=_e()+500,mu(e,t)):Fl=Le(e,t);a:do try{if(Ml!==0&&W!==null){t=W;var a=Nl;b:switch(Ml){case 1:Ml=0,Nl=null,Tu(e,t,a,1);break;case 2:case 9:if(va(a)){Ml=0,Nl=null,wu(t);break}t=function(){Ml!==2&&Ml!==9||jl!==e||(Ml=7),Ju(e)},a.then(t,t);break a;case 3:Ml=7;break a;case 4:Ml=5;break a;case 7:va(a)?(Ml=0,Nl=null,wu(t)):(Ml=0,Nl=null,Tu(e,t,a,7));break;case 5:var o=null;switch(W.tag){case 26:o=W.memoizedState;case 5:case 27:var c=W;if(!o||Af(o)){Ml=0,Nl=null;var l=c.sibling;if(l!==null)W=l;else{var u=c.return;u===null?W=null:(W=u,Eu(u))}break b}}Ml=0,Nl=null,Tu(e,t,a,5);break;case 6:Ml=0,Nl=null,Tu(e,t,a,6);break;case 8:pu(),Rl=6;break a;default:throw Error(s(462))}}Su();break}catch(t){hu(e,t)}while(1);return Bi=zi=null,N.H=r,N.A=i,Al=n,W===null?(jl=null,G=0,Qr(),Rl):0}function Su(){for(;W!==null&&!ge();)Cu(W)}function Cu(e){var t=Cc(e.alternate,e,Ll);e.memoizedProps=e.pendingProps,t===null?Eu(e):W=t}function wu(e){var t=e,n=t.alternate;switch(t.tag){case 15:case 0:t=sc(n,t,t.pendingProps,t.type,void 0,G);break;case 11:t=sc(n,t,t.pendingProps,t.type.render,t.ref,G);break;case 5:ao(t);default:jc(n,t),t=W=ci(t,Ll),t=Cc(n,t,Ll)}e.memoizedProps=e.pendingProps,t===null?Eu(e):W=t}function Tu(e,t,n,r){Bi=zi=null,ao(t),ys=null,bs=0;var i=t.return;try{if(Xs(e,i,t,n,G)){Rl=1,Gs(e,Jr(n,e.current)),W=null;return}}catch(t){if(i!==null)throw W=i,t;Rl=1,Gs(e,Jr(n,e.current)),W=null;return}t.flags&32768?(V||r===1?e=!0:Fl||G&536870912?e=!1:(Pl=e=!0,(r===2||r===9||r===3||r===6)&&(r=Os.current,r!==null&&r.tag===13&&(r.flags|=16384))),Du(t,e)):Eu(t)}function Eu(e){var t=e;do{if(t.flags&32768){Du(t,Pl);return}e=t.return;var n=kc(t.alternate,t,Ll);if(n!==null){W=n;return}if(t=t.sibling,t!==null){W=t;return}W=t=e}while(t!==null);Rl===0&&(Rl=5)}function Du(e,t){do{var n=Ac(e.alternate,e);if(n!==null){n.flags&=32767,W=n;return}if(n=e.return,n!==null&&(n.flags|=32768,n.subtreeFlags=0,n.deletions=null),!t&&(e=e.sibling,e!==null)){W=e;return}W=e=n}while(e!==null);Rl=6,W=null}function Ou(e,t,n,r,i,a,o,c,l){e.cancelPendingCommit=null;do Nu();while(Zl!==0);if(Al&6)throw Error(s(327));if(t!==null){if(t===e.current)throw Error(s(177));if(a=t.lanes|t.childLanes,a|=Zr,Ue(e,n,a,o,c,l),e===jl&&(W=jl=null,G=0),$l=t,Ql=e,eu=n,tu=a,nu=i,ru=r,t.subtreeFlags&10256||t.flags&10256?(e.callbackNode=null,e.callbackPriority=0,Vu(xe,function(){return Pu(!0),null})):(e.callbackNode=null,e.callbackPriority=0),r=!!(t.flags&13878),t.subtreeFlags&13878||r){r=N.T,N.T=null,i=P.p,P.p=2,o=Al,Al|=4;try{Xc(e,t,n)}finally{Al=o,P.p=i,N.T=r}}Zl=1,ku(),Au(),ju()}}function ku(){if(Zl===1){Zl=0;var e=Ql,t=$l,n=!!(t.flags&13878);if(t.subtreeFlags&13878||n){n=N.T,N.T=null;var r=P.p;P.p=2;var i=Al;Al|=4;try{cl(t,e);var a=kd,o=wr(e.containerInfo),s=a.focusedElem,c=a.selectionRange;if(o!==s&&s&&s.ownerDocument&&Cr(s.ownerDocument.documentElement,s)){if(c!==null&&Tr(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 _=Sr(s,h),v=Sr(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{Al=i,P.p=r,N.T=n}}e.current=t,Zl=2}}function Au(){if(Zl===2){Zl=0;var e=Ql,t=$l,n=!!(t.flags&8772);if(t.subtreeFlags&8772||n){n=N.T,N.T=null;var r=P.p;P.p=2;var i=Al;Al|=4;try{Zc(e,t.alternate,t)}finally{Al=i,P.p=r,N.T=n}}Zl=3}}function ju(){if(Zl===4||Zl===3){Zl=0,z();var e=Ql,t=$l,n=eu,r=ru;t.subtreeFlags&10256||t.flags&10256?Zl=5:(Zl=0,$l=Ql=null,Mu(e,e.pendingLanes));var i=e.pendingLanes;if(i===0&&(Xl=null),qe(n),t=t.stateNode,De&&typeof De.onCommitFiberRoot==`function`)try{De.onCommitFiberRoot(Ee,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}}eu&3&&Nu(),Ju(e),i=e.pendingLanes,n&4194090&&i&42?e===au?iu++:(iu=0,au=e):iu=0,Yu(0,!1)}}function Mu(e,t){(e.pooledCacheLanes&=t)===0&&(t=e.pooledCache,t!=null&&(e.pooledCache=null,na(t)))}function Nu(e){return ku(),Au(),ju(),Pu(e)}function Pu(){if(Zl!==5)return!1;var e=Ql,t=tu;tu=0;var n=qe(eu),r=N.T,i=P.p;try{P.p=32>n?32:n,N.T=null,n=nu,nu=null;var a=Ql,o=eu;if(Zl=0,$l=Ql=null,eu=0,Al&6)throw Error(s(331));var c=Al;if(Al|=4,Tl(a.current),_l(a,a.current,o,n),Al=c,Yu(0,!1),De&&typeof De.onPostCommitFiberRoot==`function`)try{De.onPostCommitFiberRoot(Ee,a)}catch{}return!0}finally{P.p=i,N.T=r,Mu(e,t)}}function Fu(e,t,n){t=Jr(n,t),t=qs(e.stateNode,t,2),e=Oa(e,t,2),e!==null&&(He(e,2),Ju(e))}function q(e,t,n){if(e.tag===3)Fu(e,e,n);else for(;t!==null;){if(t.tag===3){Fu(t,e,n);break}if(t.tag===1){var r=t.stateNode;if(typeof t.type.getDerivedStateFromError==`function`||typeof r.componentDidCatch==`function`&&(Xl===null||!Xl.has(r))){e=Jr(n,e),n=Js(2),r=Oa(t,n,2),r!==null&&(Ys(n,r,t,e),He(r,2),Ju(r));break}}t=t.return}}function Iu(e,t,n){var r=e.pingCache;if(r===null){r=e.pingCache=new kl;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)||(Il=!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,jl===e&&(G&n)===n&&(Rl===4||Rl===3&&(G&62914560)===G&&300>_e()-ql?!(Al&2)&&mu(e,0):Vl|=n,Ul===G&&(Ul=0)),Ju(e)}function Ru(e,t){t===0&&(t=Be()),e=ti(e,t),e!==null&&(He(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,i=e.memoizedState;i!==null&&(n=i.retryLane);break;case 19:r=e.stateNode;break;case 22:r=e.stateNode._retryCache;break;default:throw Error(s(314))}r!==null&&r.delete(t),Ru(e,n)}function Vu(e,t){return me(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-ke(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=G,a=Ie(r,r===jl?a:0,r.cancelPendingCommit!==null||r.timeoutHandle!==-1),!(a&3)||Le(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=_e(),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-ke(a),s=1<<o,c=i[o];c===-1?((s&n)===0||(s&r)!==0)&&(i[o]=Re(s,t)):c<=t&&(e.expiredLanes|=s),a&=~s}if(t=jl,n=G,n=Ie(e,e===t?n:0,e.cancelPendingCommit!==null||e.timeoutHandle!==-1),r=e.callbackNode,n===0||e===t&&(Ml===2||Ml===9)||e.cancelPendingCommit!==null)return r!==null&&r!==null&&he(r),e.callbackNode=null,e.callbackPriority=0;if(!(n&3)||Le(e,n)){if(t=n&-n,t===e.callbackPriority)return t;switch(r!==null&&he(r),qe(n)){case 2:case 8:n=be;break;case 32:n=xe;break;case 268435456:n=Ce;break;default:n=xe}return r=$u.bind(null,e),n=me(n,r),e.callbackPriority=t,e.callbackNode=n,t}return r!==null&&r!==null&&he(r),e.callbackPriority=2,e.callbackNode=null,2}function $u(e,t){if(Zl!==0&&Zl!==5)return e.callbackNode=null,e.callbackPriority=0,null;var n=e.callbackNode;if(Nu(!0)&&e.callbackNode!==n)return null;var r=G;return r=Ie(e,e===jl?r:0,e.cancelPendingCommit!==null||e.timeoutHandle!==-1),r===0?null:(cu(e,r,t),Qu(e,_e()),e.callbackNode!=null&&e.callbackNode===n?$u.bind(null,e):null)}function ed(e,t){if(Nu())return null;cu(e,t,!0)}function td(){zd(function(){Al&6?me(ye,Xu):Zu()})}function nd(){return qu===0&&(qu=ze()),qu}function rd(e){return e==null||typeof e==`symbol`||typeof e==`boolean`?null:typeof e==`function`?e:Xt(``+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[Qe]||null).action),o=r.submitter;o&&(t=(t=o[Qe]||null)?rd(t.formAction):o.getAttribute(`formAction`),t!==null&&(a=t,o=null));var s=new vn(`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);ts(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),ts(n,{pending:!0,data:e,method:i.method,action:a},a,e))},currentTarget:i}]})}}for(var od=0;od<Gr.length;od++){var sd=Gr[od];Kr(sd.toLowerCase(),`on`+(sd[0].toUpperCase()+sd.slice(1)))}Kr(Lr,`onAnimationEnd`),Kr(Rr,`onAnimationIteration`),Kr(zr,`onAnimationStart`),Kr(`dblclick`,`onDoubleClick`),Kr(`focusin`,`onFocus`),Kr(`focusout`,`onBlur`),Kr(Br,`onTransitionRun`),Kr(Vr,`onTransitionStart`),Kr(Hr,`onTransitionCancel`),Kr(Ur,`onTransitionEnd`),mt(`onMouseEnter`,[`mouseout`,`mouseover`]),mt(`onMouseLeave`,[`mouseout`,`mouseover`]),mt(`onPointerEnter`,[`pointerout`,`pointerover`]),mt(`onPointerLeave`,[`pointerout`,`pointerover`]),pt(`onChange`,`change click focusin focusout input keydown keyup selectionchange`.split(` `)),pt(`onSelect`,`focusout contextmenu dragend focusin keydown keyup mousedown mouseup selectionchange`.split(` `)),pt(`onBeforeInput`,[`compositionend`,`keypress`,`textInput`,`paste`]),pt(`onCompositionEnd`,`compositionend focusout keydown keypress keyup mousedown`.split(` `)),pt(`onCompositionStart`,`compositionstart focusout keydown keypress keyup mousedown`.split(` `)),pt(`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){Vs(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){Vs(e)}i.currentTarget=null,a=c}}}}function J(e,t){var n=t[et];n===void 0&&(n=t[et]=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,dt.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,!sn||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 o=r.tag;if(o===3||o===4){var s=r.stateNode.containerInfo;if(s===i)break;if(o===4)for(o=r.return;o!==null;){var c=o.tag;if((c===3||c===4)&&o.stateNode.containerInfo===i)return;o=o.return}for(;s!==null;){if(o=ot(s),o===null)return;if(c=o.tag,c===5||c===6||c===26||c===27){r=a=o;continue a}s=s.parentNode}}r=r.return}rn(function(){var r=a,i=Qt(n),o=[];a:{var s=Wr.get(e);if(s!==void 0){var c=vn,u=e;switch(e){case`keypress`:if(pn(n)===0)break a;case`keydown`:case`keyup`:c=In;break;case`focusin`:u=`focus`,c=Dn;break;case`focusout`:u=`blur`,c=Dn;break;case`beforeblur`:case`afterblur`:c=Dn;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`:c=Tn;break;case`drag`:case`dragend`:case`dragenter`:case`dragexit`:case`dragleave`:case`dragover`:case`dragstart`:case`drop`:c=En;break;case`touchcancel`:case`touchend`:case`touchmove`:case`touchstart`:c=Rn;break;case Lr:case Rr:case zr:c=On;break;case Ur:c=zn;break;case`scroll`:case`scrollend`:c=bn;break;case`wheel`:c=Bn;break;case`copy`:case`cut`:case`paste`:c=kn;break;case`gotpointercapture`:case`lostpointercapture`:case`pointercancel`:case`pointerdown`:case`pointermove`:case`pointerout`:case`pointerover`:case`pointerup`:c=Ln;break;case`toggle`:case`beforetoggle`:c=Vn}var d=!!(t&4),f=!d&&(e===`scroll`||e===`scrollend`),p=d?s===null?null:s+`Capture`:s;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=an(m,p),g!=null&&d.push(gd(m,g,h))),f)break;m=m.return}0<d.length&&(s=new c(s,u,null,n,i),o.push({event:s,listeners:d}))}}if(!(t&7)){a:{if(s=e===`mouseover`||e===`pointerover`,c=e===`mouseout`||e===`pointerout`,s&&n!==Zt&&(u=n.relatedTarget||n.fromElement)&&(ot(u)||u[$e]))break a;if((c||s)&&(s=i.window===i?i:(s=i.ownerDocument)?s.defaultView||s.parentWindow:window,c?(u=n.relatedTarget||n.toElement,c=r,u=u?ot(u):null,u!==null&&(f=l(u),d=u.tag,u!==f||d!==5&&d!==27&&d!==6)&&(u=null)):(c=null,u=r),c!==u)){if(d=Tn,g=`onMouseLeave`,p=`onMouseEnter`,m=`mouse`,(e===`pointerout`||e===`pointerover`)&&(d=Ln,g=`onPointerLeave`,p=`onPointerEnter`,m=`pointer`),f=c==null?s:ct(c),h=u==null?s:ct(u),s=new d(g,m+`leave`,c,n,i),s.target=f,s.relatedTarget=h,g=null,ot(i)===r&&(d=new d(p,m+`enter`,u,n,i),d.target=h,d.relatedTarget=f,g=d),f=g,c&&u)b:{for(d=c,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;c!==null&&yd(o,s,c,d,!1),u!==null&&f!==null&&yd(o,f,u,d,!0)}}a:{if(s=r?ct(r):window,c=s.nodeName&&s.nodeName.toLowerCase(),c===`select`||c===`input`&&s.type===`file`)var _=sr;else if(tr(s)){if(cr)_=_r;else{_=hr;var v=mr}}else c=s.nodeName,!c||c.toLowerCase()!==`input`||s.type!==`checkbox`&&s.type!==`radio`?r&&qt(r.elementType)&&(_=sr):_=gr;if(_&&=_(e,r)){nr(o,_,n,i);break a}v&&v(e,s,r),e===`focusout`&&r&&s.type===`number`&&r.memoizedProps.value!=null&&zt(s,`number`,s.value)}switch(v=r?ct(r):window,e){case`focusin`:(tr(v)||v.contentEditable===`true`)&&(Dr=v,Or=r,kr=null);break;case`focusout`:kr=Or=Dr=null;break;case`mousedown`:Ar=!0;break;case`contextmenu`:case`mouseup`:case`dragend`:Ar=!1,jr(o,n,i);break;case`selectionchange`:if(Er)break;case`keydown`:case`keyup`:jr(o,n,i)}var y;if(Un)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 Zn?Yn(e,n)&&(b=`onCompositionEnd`):e===`keydown`&&n.keyCode===229&&(b=`onCompositionStart`);b&&(Kn&&n.locale!==`ko`&&(Zn||b!==`onCompositionStart`?b===`onCompositionEnd`&&Zn&&(y=fn()):(ln=i,un=`value`in ln?ln.value:ln.textContent,Zn=!0)),v=_d(r,b),0<v.length&&(b=new An(b,e,null,n,i),o.push({event:b,listeners:v}),y?b.data=y:(y=Xn(n),y!==null&&(b.data=y)))),(y=Gn?Qn(e,n):$n(e,n))&&(b=_d(r,`onBeforeInput`),0<b.length&&(v=new An(`onBeforeInput`,`beforeinput`,null,n,i),o.push({event:v,listeners:b}),v.data=y)),ad(o,e,r,n,i)}ud(o,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=an(e,n),i!=null&&r.unshift(gd(e,i,a)),i=an(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=an(n,a),l!=null&&o.unshift(gd(n,l,c))):i||(l=an(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,`
|
|
9
|
-
`).replace(xd,``)}function Cd(e,t){return t=Sd(t),Sd(e)===t}function wd(){}function Y(e,t,n,r,i,a){switch(n){case`children`:typeof r==`string`?t===`body`||t===`textarea`&&r===``||Ut(e,r):(typeof r==`number`||typeof r==`bigint`)&&t!==`body`&&Ut(e,``+r);break;case`className`:bt(e,`class`,r);break;case`tabIndex`:bt(e,`tabindex`,r);break;case`dir`:case`role`:case`viewBox`:case`width`:case`height`:bt(e,n,r);break;case`style`:Kt(e,r,a);break;case`data`:if(t!==`object`){bt(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=Xt(``+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 a==`function`&&(n===`formAction`?(t!==`input`&&Y(e,t,`name`,i.name,i,null),Y(e,t,`formEncType`,i.formEncType,i,null),Y(e,t,`formMethod`,i.formMethod,i,null),Y(e,t,`formTarget`,i.formTarget,i,null)):(Y(e,t,`encType`,i.encType,i,null),Y(e,t,`method`,i.method,i,null),Y(e,t,`target`,i.target,i,null))),r==null||typeof r==`symbol`||typeof r==`boolean`){e.removeAttribute(n);break}r=Xt(``+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(s(61));if(n=r.__html,n!=null){if(i.children!=null)throw Error(s(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=Xt(``+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),yt(e,`popover`,r);break;case`xlinkActuate`:xt(e,`http://www.w3.org/1999/xlink`,`xlink:actuate`,r);break;case`xlinkArcrole`:xt(e,`http://www.w3.org/1999/xlink`,`xlink:arcrole`,r);break;case`xlinkRole`:xt(e,`http://www.w3.org/1999/xlink`,`xlink:role`,r);break;case`xlinkShow`:xt(e,`http://www.w3.org/1999/xlink`,`xlink:show`,r);break;case`xlinkTitle`:xt(e,`http://www.w3.org/1999/xlink`,`xlink:title`,r);break;case`xlinkType`:xt(e,`http://www.w3.org/1999/xlink`,`xlink:type`,r);break;case`xmlBase`:xt(e,`http://www.w3.org/XML/1998/namespace`,`xml:base`,r);break;case`xmlLang`:xt(e,`http://www.w3.org/XML/1998/namespace`,`xml:lang`,r);break;case`xmlSpace`:xt(e,`http://www.w3.org/XML/1998/namespace`,`xml:space`,r);break;case`is`:yt(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=Jt.get(n)||n,yt(e,n,r))}}function Td(e,t,n,r,i,a){switch(n){case`style`:Kt(e,r,a);break;case`dangerouslySetInnerHTML`:if(r!=null){if(typeof r!=`object`||!(`__html`in r))throw Error(s(61));if(n=r.__html,n!=null){if(i.children!=null)throw Error(s(60));e.innerHTML=n}}break;case`children`:typeof r==`string`?Ut(e,r):(typeof r==`number`||typeof r==`bigint`)&&Ut(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(!ft.hasOwnProperty(n))a:{if(n[0]===`o`&&n[1]===`n`&&(i=n.endsWith(`Capture`),t=n.slice(2,i?n.length-7:void 0),a=e[Qe]||null,a=a==null?null:a[n],typeof a==`function`&&e.removeEventListener(t,a,i),typeof r==`function`)){typeof a!=`function`&&a!==null&&(n in e?e[n]=null:e.hasAttribute(n)&&e.removeAttribute(n)),e.addEventListener(t,r,i);break a}n in e?e[n]=r:!0===r?e.setAttribute(n,``):yt(e,n,r)}}}function Ed(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,i=!1,a;for(a in n)if(n.hasOwnProperty(a)){var o=n[a];if(o!=null)switch(a){case`src`:r=!0;break;case`srcSet`:i=!0;break;case`children`:case`dangerouslySetInnerHTML`:throw Error(s(137,t));default:Y(e,t,a,o,n,null)}}i&&Y(e,t,`srcSet`,n.srcSet,n,null),r&&Y(e,t,`src`,n.src,n,null);return;case`input`:J(`invalid`,e);var c=a=o=i=null,l=null,u=null;for(r in n)if(n.hasOwnProperty(r)){var d=n[r];if(d!=null)switch(r){case`name`:i=d;break;case`type`:o=d;break;case`checked`:l=d;break;case`defaultChecked`:u=d;break;case`value`:a=d;break;case`defaultValue`:c=d;break;case`children`:case`dangerouslySetInnerHTML`:if(d!=null)throw Error(s(137,t));break;default:Y(e,t,r,d,n,null)}}Rt(e,a,c,l,u,o,i,!1),Mt(e);return;case`select`:for(i in J(`invalid`,e),r=o=a=null,n)if(n.hasOwnProperty(i)&&(c=n[i],c!=null))switch(i){case`value`:a=c;break;case`defaultValue`:o=c;break;case`multiple`:r=c;default:Y(e,t,i,c,n,null)}t=a,n=o,e.multiple=!!r,t==null?n!=null&&Bt(e,!!r,n,!0):Bt(e,!!r,t,!1);return;case`textarea`:for(o in J(`invalid`,e),a=i=r=null,n)if(n.hasOwnProperty(o)&&(c=n[o],c!=null))switch(o){case`value`:r=c;break;case`defaultValue`:i=c;break;case`children`:a=c;break;case`dangerouslySetInnerHTML`:if(c!=null)throw Error(s(91));break;default:Y(e,t,o,c,n,null)}Ht(e,r,i,a),Mt(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:Y(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(s(137,t));default:Y(e,t,u,r,n,null)}return;default:if(qt(t)){for(d in n)n.hasOwnProperty(d)&&(r=n[d],r!==void 0&&Td(e,t,d,r,n,void 0));return}}for(c in n)n.hasOwnProperty(c)&&(r=n[c],r!=null&&Y(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 i=null,a=null,o=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)||Y(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`:a=m;break;case`name`:i=m;break;case`checked`:u=m;break;case`defaultChecked`:d=m;break;case`value`:o=m;break;case`defaultValue`:c=m;break;case`children`:case`dangerouslySetInnerHTML`:if(m!=null)throw Error(s(137,t));break;default:m!==f&&Y(e,t,p,m,r,f)}}Lt(e,o,c,l,u,d,a,i);return;case`select`:for(a in m=o=c=p=null,n)if(l=n[a],n.hasOwnProperty(a)&&l!=null)switch(a){case`value`:break;case`multiple`:m=l;default:r.hasOwnProperty(a)||Y(e,t,a,null,r,l)}for(i in r)if(a=r[i],l=n[i],r.hasOwnProperty(i)&&(a!=null||l!=null))switch(i){case`value`:p=a;break;case`defaultValue`:c=a;break;case`multiple`:o=a;default:a!==l&&Y(e,t,i,a,r,l)}t=c,n=o,r=m,p==null?!!r!=!!n&&(t==null?Bt(e,!!n,n?[]:``,!1):Bt(e,!!n,t,!0)):Bt(e,!!n,p,!1);return;case`textarea`:for(c in m=p=null,n)if(i=n[c],n.hasOwnProperty(c)&&i!=null&&!r.hasOwnProperty(c))switch(c){case`value`:break;case`children`:break;default:Y(e,t,c,null,r,i)}for(o in r)if(i=r[o],a=n[o],r.hasOwnProperty(o)&&(i!=null||a!=null))switch(o){case`value`:p=i;break;case`defaultValue`:m=i;break;case`children`:break;case`dangerouslySetInnerHTML`:if(i!=null)throw Error(s(91));break;default:i!==a&&Y(e,t,o,i,r,a)}Vt(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:Y(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:Y(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)&&Y(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(s(137,t));break;default:Y(e,t,u,p,r,m)}return;default:if(qt(t)){for(var _ in n)p=n[_],n.hasOwnProperty(_)&&p!==void 0&&!r.hasOwnProperty(_)&&Td(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||Td(e,t,d,p,r,m);return}}for(var v in n)p=n[v],n.hasOwnProperty(v)&&p!=null&&!r.hasOwnProperty(v)&&Y(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||Y(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[it]||c===`SCRIPT`||c===`STYLE`||c===`LINK`&&o.rel.toLowerCase()===`stylesheet`||n.removeChild(o),o=s}}if(i===0){e.removeChild(a),_p(t);return}i--}else n===`$`||n===`$?`||n===`$!`?i++:r=n.charCodeAt(0)-48}else r=0;n=a}while(n);_p(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),at(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[it])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(s(452));return e;case`head`:if(e=t.head,!e)throw Error(s(453));return e;case`body`:if(e=t.body,!e)throw Error(s(454));return e;default:throw Error(s(451))}}function Qd(e){for(var t=e.attributes;t.length;)e.removeAttributeNode(t[0]);at(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=fu();return e||t}function af(e){var t=st(e);t!==null&&t.tag===5&&t.type===`form`?rs(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=It(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`),Ed(t,`link`,e),ut(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="`+It(t)+`"]`;t===`image`&&n&&n.imageSrcSet?(i+=`[imagesrcset="`+It(n.imageSrcSet)+`"]`,typeof n.imageSizes==`string`&&(i+=`[imagesizes="`+It(n.imageSizes)+`"]`)):i+=`[href="`+It(e)+`"]`;var a=i;switch(t){case`style`:a=gf(e);break;case`script`:a=bf(e)}$d.has(a)||(e=m({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`),Ed(t,`link`,e),ut(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="`+It(r)+`"][href="`+It(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=m({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`),Ed(r,`link`,e),ut(r),n.head.appendChild(r)}}}function ff(e,t,n){nf.S(e,t,n);var r=of;if(r&&e){var i=lt(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=m({rel:`stylesheet`,href:e,"data-precedence":t},n),(n=$d.get(a))&&wf(e,n);var c=o=r.createElement(`link`);ut(c),Ed(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=lt(n).hoistableScripts,i=bf(e),a=r.get(i);a||(a=n.querySelector(xf(i)),a||(e=m({src:e,async:!0},t),(t=$d.get(i))&&Tf(e,t),a=n.createElement(`script`),ut(a),Ed(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=lt(n).hoistableScripts,i=bf(e),a=r.get(i);a||(a=n.querySelector(xf(i)),a||(e=m({src:e,async:!0,type:`module`},t),(t=$d.get(i))&&Tf(e,t),a=n.createElement(`script`),ut(a),Ed(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 i=(i=R.current)?tf(i):null;if(!i)throw Error(s(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=lt(i).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 a=lt(i).hoistableStyles,o=a.get(e);if(o||(i=i.ownerDocument||i,o={type:`stylesheet`,instance:null,count:0,state:{loading:0,preload:null}},a.set(e,o),(a=i.querySelector(_f(e)))&&!a._p&&(o.instance=a,o.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),a||yf(i,e,n,o.state))),t&&r===null)throw Error(s(528,``));return o}if(t&&r!==null)throw Error(s(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=lt(i).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(s(444,e))}}function gf(e){return`href="`+It(e)+`"`}function _f(e){return`link[rel="stylesheet"][`+e+`]`}function vf(e){return m({},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}),Ed(t,`link`,n),ut(t),e.head.appendChild(t))}function bf(e){return`[src="`+It(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~="`+It(n.href)+`"]`);if(r)return t.instance=r,ut(r),r;var i=m({},n,{"data-href":n.href,"data-precedence":n.precedence,href:null,precedence:null});return r=(e.ownerDocument||e).createElement(`style`),ut(r),Ed(r,`style`,i),Cf(r,n.precedence,e),t.instance=r;case`stylesheet`:i=gf(n.href);var a=e.querySelector(_f(i));if(a)return t.state.loading|=4,t.instance=a,ut(a),a;r=vf(n),(i=$d.get(i))&&wf(r,i),a=(e.ownerDocument||e).createElement(`link`),ut(a);var o=a;return o._p=new Promise(function(e,t){o.onload=e,o.onerror=t}),Ed(a,`link`,r),t.state.loading|=4,Cf(a,n.precedence,e),t.instance=a;case`script`:return a=bf(n.src),(i=e.querySelector(xf(a)))?(t.instance=i,ut(i),i):(r=n,(i=$d.get(a))&&(r=m({},n),Tf(r,i)),e=e.ownerDocument||e,i=e.createElement(`script`),ut(i),Ed(i,`link`,r),e.head.appendChild(i),t.instance=i);case`void`:return null;default:throw Error(s(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[it]||a[Ze]||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(s(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 i=gf(n.href),a=e.querySelector(_f(i));if(a){e=a._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=a,ut(a);return}a=e.ownerDocument||e,n=vf(n),(i=$d.get(i))&&wf(n,i),a=a.createElement(`link`),ut(a);var o=a;o._p=new Promise(function(e,t){o.onload=e,o.onerror=t}),Ed(a,`link`,n),t.instance=a}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(s(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=Ve(-1),this.entangledLanes=this.shellSuspendCounter=this.errorRecoveryDisabledLanes=this.expiredLanes=this.warmLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=Ve(0),this.hiddenUpdates=Ve(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=ai(3,null,null,t),e.current=a,a.stateNode=e,t=ta(),t.refCount++,e.pooledCache=t,t.refCount++,a.memoizedState={element:r,isDehydrated:n,cache:t},Ta(a),e}function Hf(e){return e?(e=ri,e):ri}function Uf(e,t,n,r,i,a){i=Hf(i),r.context===null?r.context=i:r.pendingContext=i,r=Da(t),r.payload={element:n},a=a===void 0?null:a,a!==null&&(r.callback=a),n=Oa(e,r,t),n!==null&&(su(n,e,t),ka(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=ti(e,67108864);t!==null&&su(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(up(i,e,t,n,r))r.stopPropagation();else if(lp(e,r),t&4&&-1<cp.indexOf(e)){for(;i!==null;){var a=st(i);if(a!==null)switch(a.tag){case 3:if(a=a.stateNode,a.current.memoizedState.isDehydrated){var o=Fe(a.pendingLanes);if(o!==0){var s=a;for(s.pendingLanes|=2,s.entangledLanes|=2;o;){var c=1<<31-ke(o);s.entanglements[1]|=c,o&=~c}Ju(a),!(Al&6)&&(Jl=_e()+500,Yu(0,!1))}}break;case 13:s=ti(a,2),s!==null&&su(s,a,2),fu(),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=Qt(e),$f(e)}var Qf=null;function $f(e){if(Qf=null,e=ot(e),e!==null){var t=l(e);if(t===null)e=null;else{var n=t.tag;if(n===13){if(e=u(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(ve()){case ye:return 2;case be:return 8;case xe:case Se:return 32;case Ce: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 X(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=st(t),t!==null&&Kf(t)),e):(e.eventSystemFlags|=r,t=e.targetContainers,i!==null&&t.indexOf(i)===-1&&t.push(i),e)}function up(e,t,n,r,i){switch(t){case`focusin`:return np=X(np,e,t,n,r,i),!0;case`dragenter`:return rp=X(rp,e,t,n,r,i),!0;case`mouseover`:return ip=X(ip,e,t,n,r,i),!0;case`pointerover`:var a=i.pointerId;return ap.set(a,X(ap.get(a)||null,e,t,n,r,i)),!0;case`gotpointercapture`:return a=i.pointerId,op.set(a,X(op.get(a)||null,e,t,n,r,i)),!0}return!1}function dp(e){var t=ot(e.target);if(t!==null){var n=l(t);if(n!==null){if(t=n.tag,t===13){if(t=u(n),t!==null){e.blockedOn=t,Ye(e.priority,function(){if(n.tag===13){var e=K();e=Ke(e);var t=ti(n,e);t!==null&&su(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 fp(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);Zt=r,n.target.dispatchEvent(r),Zt=null}else return t=st(n),t!==null&&Kf(t),e.blockedOn=n,!1;t.shift()}return!0}function pp(e,t,n){fp(e)&&n.delete(t)}function Z(){tp=!1,np!==null&&fp(np)&&(np=null),rp!==null&&fp(rp)&&(rp=null),ip!==null&&fp(ip)&&(ip=null),ap.forEach(pp),op.forEach(pp)}function mp(e,n){e.blockedOn===n&&(e.blockedOn=null,tp||(tp=!0,t.unstable_scheduleCallback(t.unstable_NormalPriority,Z)))}var hp=null;function gp(e){hp!==e&&(hp=e,t.unstable_scheduleCallback(t.unstable_NormalPriority,function(){hp===e&&(hp=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=st(n);a!==null&&(e.splice(t,3),t-=3,ts(a,{pending:!0,data:i,method:n.method,action:r},r,i))}}))}function _p(e){function t(t){return mp(t,e)}np!==null&&mp(np,e),rp!==null&&mp(rp,e),ip!==null&&mp(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);)dp(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[Qe]||null;if(typeof a==`function`)o||gp(n);else if(o){var s=null;if(a&&a.hasAttribute(`formAction`)){if(i=a,o=a[Qe]||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),gp(n)}}}function vp(e){this._internalRoot=e}yp.prototype.render=vp.prototype.render=function(e){var t=this._internalRoot;if(t===null)throw Error(s(409));var n=t.current;Uf(n,K(),e,t,null,null)},yp.prototype.unmount=vp.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),fu(),t[$e]=null}};function yp(e){this._internalRoot=e}yp.prototype.unstable_scheduleHydration=function(e){if(e){var t=Je();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&&dp(e)}};var bp=r.version;if(bp!==`19.1.0`)throw Error(s(527,bp,`19.1.0`));P.findDOMNode=function(e){var t=e._reactInternals;if(t===void 0)throw typeof e.render==`function`?Error(s(188)):(e=Object.keys(e).join(`,`),Error(s(268,e)));return e=f(t),e=e===null?null:p(e),e=e===null?null:e.stateNode,e};var xp={bundleType:0,version:`19.1.0`,rendererPackageName:`react-dom`,currentDispatcherRef:N,reconcilerVersion:`19.1.0`};if(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<`u`){var Sp=__REACT_DEVTOOLS_GLOBAL_HOOK__;if(!Sp.isDisabled&&Sp.supportsFiber)try{Ee=Sp.inject(xp),De=Sp}catch{}}e.createRoot=function(e,t){if(!c(e))throw Error(s(299));var n=!1,r=``,i=Hs,a=Us,o=Ws,l=null;return t!=null&&(!0===t.unstable_strictMode&&(n=!0),t.identifierPrefix!==void 0&&(r=t.identifierPrefix),t.onUncaughtError!==void 0&&(i=t.onUncaughtError),t.onCaughtError!==void 0&&(a=t.onCaughtError),t.onRecoverableError!==void 0&&(o=t.onRecoverableError),t.unstable_transitionCallbacks!==void 0&&(l=t.unstable_transitionCallbacks)),t=Vf(e,1,!1,null,null,n,r,i,a,o,l,null),e[$e]=t.current,pd(e),new vp(t)}})),c=e(((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=s()})),l=n(),u=c(),d="This tab's key is out of date. Open the address printed by `copperflow studio` again.";function f(e,t){return e===403&&/session token/i.test(t??``)?d:t??`Request failed (${e})`}function p(e){return e===d}var m=`The copperflow Studio server is not answering. Start "copperflow studio" again in the project folder, then reload this page.`;function h(e){return e instanceof TypeError?m:e instanceof Error?e.message:String(e)}var g=[`alignLeft`,`alignRight`,`alignTop`,`alignBottom`,`alignHCentres`,`alignVCentres`,`distributeH`,`distributeV`],_=new Set([`distributeH`,`distributeV`]),v=e=>g.includes(e),y=e=>_.has(e)?3:2;function b(e,t){return t>=y(e)?null:y(e)===2?`Select two or more parts`:`Select three or more parts`}var x=[`drawBus`,`drawPolyline`,`drawArc`,`drawCircle`,`drawRectangle`,`drawText`],S={bus:`drawBus`,polyline:`drawPolyline`,arc:`drawArc`,circle:`drawCircle`,rectangle:`drawRectangle`,text:`drawText`},C={drawBus:`bus`,drawPolyline:`polyline`,drawArc:`arc`,drawCircle:`circle`,drawRectangle:`rectangle`,drawText:`text`},w=e=>x.includes(e),T=`The AI lock is on. Open it to edit.`;function E(e){return{closed:e===`ai`,editedSinceOpen:!1}}function ee(e){return{closed:!e.closed,editedSinceOpen:!1}}function D(e,t){return e.closed?e:t===`human`?e.editedSinceOpen?e:{...e,editedSinceOpen:!0}:e.editedSinceOpen?e:{...e,closed:!0}}var O=[`undo`,`redo`,`delete`,`replicateLayout`,`makeSheet`,`placeComponent`,`wire`,`netLabel`,`groundFlag`,`powerFlag`,...x,`singleRouting`,`placeVia`,`placePour`,`placePourBoard`,`placeHole`,`autoplace`,`autoplaceSelection`,`autoplaceInstance`,`fitBoard`,`autoroute`,`autorouteSelection`,`autorouteNet`,`unroute`,`rotate`,`rotateRight`,`removeCorners`,`filletTracks`,`straightenTracks`,`designRules`,`tidySheet`,`addPage`,`renamePage`,`deletePage`,...g,`newCircuit`,`paste`,`noConnect`,`junction`,`annotate`,`placementTransfer`,`routingCorner`,`flip`,`footprintManager`];function k(e){return e?Object.fromEntries(O.map(e=>[e,T])):{}}var A=new Set([`wire`,`route`,`placeVia`,`armNetLabel`,...x,`rotate`,`openLibrary`,`undo`,`redo`,`nudgeLeft`,`nudgeRight`,`nudgeUp`,`nudgeDown`,`delete`,`removeCorner`,`flipBend`,`alignLeft`,`distributeH`,`filletTracks`,`straightenTracks`,`routingCorner`,`flip`,`paste`,`junction`,`placementTransfer`]);function j(e){return A.has(e)}var te=new Set([`move`,`moveGroup`,`label`,`text`,`wireSegment`,`wireCorner`]);function M(e){return te.has(e)}var ne=new Set([`/api/edit`,`/api/layout`,`/api/undo`,`/api/redo`,`/api/rename-parts`,`/api/make-sheet`,`/api/route`,`/api/autoplace`,`/api/fit-board`,`/api/unroute`,`/api/rules`,`/api/place`,`/api/new-circuit`]);function N(e,t){return t===void 0||typeof t==`object`&&t&&t.preview===!0?!1:ne.has(e.split(`?`)[0]??e)}function P(e){return e?{title:`AI is driving`,hint:`Unlock to edit`}:{title:`You are editing`,hint:`Lock for the agent`}}function F(e){return O.includes(e)}function re(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(T)),!0):!1}}}var ie=re(()=>void 0),I=`copperflow-token`,ae=2e3;function L(){let e=/[#&]token=([^&]+)/.exec(window.location.hash);if(e?.[1]){let t=decodeURIComponent(e[1]);try{sessionStorage.setItem(I,t)}catch{}return window.history.replaceState(null,``,window.location.pathname+window.location.search),t}try{return sessionStorage.getItem(I)??``}catch{return``}}var oe=L(),se=oe!==``;window.addEventListener(`hashchange`,()=>{/[#&]token=/.test(window.location.hash)&&window.location.reload()});async function R(e,t){if(ie.closed()&&N(e,t))throw Error(T);let n;try{n=await fetch(e,{method:t===void 0?`GET`:`POST`,headers:{"x-copperflow-token":oe,"content-type":`application/json`},...t===void 0?{}:{body:JSON.stringify(t)}})}catch(e){throw Error(h(e))}let r=await n.json();if(!r.ok)throw Error(f(n.status,r.error));return r.data}var ce=[`change`,`build`,`library`,`route`,`place`];function le(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&&ce.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":oe},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(`
|
|
10
|
-
|
|
11
|
-
`);e>=0;e=a.indexOf(`
|
|
12
|
-
|
|
13
|
-
`))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,ae))}})(),()=>n.abort()}var ue=.5,de=2e3;function fe(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 pe(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 me(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:we(a)}}function he(e,t){return{...e,cx:t.x,cy:t.y}}function ge(e,t,n,r){let i=pe(e,t,n),a=we(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 z=e=>Math.round(e*1e4)/1e4;function _e(e,t){let n=Math.max(0,-Math.floor(Math.log10(t))+2);return Number((Math.round(e/t)*t).toFixed(n))}var ve=(e,t,n=!0)=>z(n?_e(e,t):e),ye=(e,t,n=!0)=>({x:ve(e.x,t,n),y:ve(e.y,t,n)});function be(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 xe(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 Se(e){return xe(e.flatMap(e=>[{x:e.minX,y:e.minY},{x:e.maxX,y:e.maxY}]))}function Ce(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 we(e){return Math.min(de,Math.max(ue,e))}var Te={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`}},Ee={x:0,y:0};function De(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)??Ee,autoPlaced:e.autoPlaced}]))}function Oe(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=Te[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 ke(e,t,n,r=90){let i=Te[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 Ae(e,t,n,r){let i=e.model.parts.find(e=>e.name===t)?.props,[a,o]=Te[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 je(e,t,n,r,i){let a=Ae(e,t,n,r);return[z(a.x+i.x),z(a.y+i.y)]}var Me=`Keep auto-placed positions`,Ne=`a repeated name cannot be addressed from the Studio`,Pe=e=>Math.round(e*100)/100;function Fe(e,t){let n=t===`pcb`?e.pcb.parts:e.schematic.symbols;return new Map(n.map(e=>[e.component,e.rotation]))}var Ie=(e,t,n)=>e?.model.parts.find(e=>e.name===t)?.props[Te[n].rotation]!==void 0;function Le(e,t,n=()=>null,r){let[i,a]=Te[t].position,o=Fe(e,t),s=[],c=[];for(let[l,{origin:u,group:d,autoPlaced:f}]of De(e,t)){if(!f)continue;let e=l.includes(`~`)?Ne:n(l);if(e!==null){c.push({part:l,reason:e});continue}let p=o.get(l)??0,m={[i]:Pe(u.x-d.x),[a]:Pe(u.y-d.y),...p!==0||Ie(r,l,t)?{[Te[t].rotation]:p}:{}};s.push({kind:`setProps`,part:l,props:m})}return{edits:s,skipped:c}}function Re(e,t){return t.skipped.length===0?e:`${e} Skipped ${t.skipped.map(e=>`${e.part} (${e.reason})`).join(`, `)}.`}function ze(e){let t=e.edits.length;return Re(t===0?`No auto-placed part could be kept.`:`Kept the positions of ${t} auto-placed ${t===1?`part`:`parts`}.`,e)}function Be(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 Ve(e,t,n,r,i){Be(Le(e,t,n,i),Me,ze,r)}var He=`Tidy sheet`,Ue=`Every part on the sheet has a position of its own`,We=`The schematic is not built yet`;function Ge(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 Ke(e){return e?Ge(e,`schematic`).size>0?null:Ue:We}var qe=(e,t=()=>null,n)=>Le(e,`schematic`,t,n);function Je(e){let t=e.edits.length;return Re(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 Ye(e,t,n,r){let i=Ke(e);if(i!==null)return n.notify(i);Be(qe(e,t,r),He,Je,n)}var Xe=/\.sheet\.tsx$/,Ze=e=>e!==void 0&&Xe.test(e),Qe=e=>(e.split(`/`).pop()??e).replace(Xe,``),$e=3;function et(e){return e.length<=1?e[0]??``:e.length>$e?`${e.slice(0,$e).join(`, `)} and ${e.length-$e} more`:`${e.slice(0,-1).join(`, `)} and ${e.at(-1)}`}var tt=e=>e.length>1?[`${e.length} wires`]:[...e],nt=e=>`by ${e}°`;function rt(e,t,n,r,i=90){let{rotation:a,where:o}=Te[n],s=[],c=[];for(let a of t){let t=r(a)??ke(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 ${et(l)}${o} ${nt(i)}`;return{edits:s.map(e=>({kind:`setProps`,part:e.name,props:{[a]:e.to}})),summary:d,parts:l,skipped:c,done:`rotated`}}function it(e,t,n,r,i,a){let[o,s]=Te[n].position,{where:c}=Te[n],l=t.flatMap(e=>a(e)??[]),u=t.filter(e=>a(e)===null),d=u.map(t=>({name:t,to:je(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 ${et(u)}${c} by (${z(i.x)}, ${z(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 at(e,t){return n=>e.get(n)??{origin:t.find(e=>e.name===n)?.center??Ee,group:Ee}}function ot(e,t,n,r=!0){let i=r?t:t/10;return{x:z(e.dx*i*n),y:z(e.dy*i*n)}}function st(e,t){let n=Se(e);return n?{x:_e((n.minX+n.maxX)/2,t),y:_e((n.minY+n.maxY)/2,t)}:void 0}function ct(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 lt(e,t,n,r,i,a,o=()=>!0,s=90){if(t.length===1)return rt(e,t,n,a,s);let{rotation:c,position:l,where:u}=Te[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)??ke(e,u,n,s);if(typeof t==`string`){p.push(t);continue}let m=r(u),h=m.origin,g=ct(h,i,s),[_,v]=je(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 ${et(f)}${u} ${nt(s)}`,parts:f,skipped:p,done:`rotated`}}function ut(e){let t=new Set(e.boxes.map(e=>e.name));return n=>t.has(n)||e.anchors.has(n)}function dt(e,t,n,r,i,a=90){if(t.length===1)return rt(e,t,n,i,a);let o=st(r.boxes.filter(e=>t.includes(e.name)).map(e=>e.box),r.step);return o?lt(e,t,n,at(r.anchors,r.boxes),o,i,ut(r),a):{message:`None of the selected parts is in this view.`}}function ft(e,t,n,r,i,a){let o=ut(r),s=t.filter(e=>!o(e)).map(e=>`${e} is not in this view`),c=it(e,t.filter(o),n,at(r.anchors,r.boxes),i,a);return{...c,skipped:[...s,...c.skipped]}}function pt(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 ${et(r)}`,parts:r,skipped:n,done:`removed`}}function mt(e,t=0){let n=e.length===1?`${e[0]} and its connections`:`${e.length} parts (${et(e)}) and their connections`;return t===0?`Remove ${n}?`:`Remove ${n}, and ${t} ${t===1?`wire`:`wires`}?`}function ht(e){if(e.skipped.length===0)return;let t=e.skipped.join(`; `);return e.edits.length===0?t:`Not ${e.done}: ${t}`}function gt(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:`${et(e)} ${a} ${n?`already locked`:`not locked`}.`}}async function _t(e,t){return(await vt(e,t)).ok}async function vt(e,t){let n=ht(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 yt={reference:.16,value:.16,"pin-name":.12,"pin-number":.1},bt=.6,xt=e=>Math.round(e*1e6)/1e6,St=(e,t)=>({x:xt(e),y:xt(t)}),Ct=(...e)=>({type:`polyline`,points:e.map(([e,t])=>St(e,t))});function wt(e,t,n,r){return{type:`text`,text:e,at:t,anchor:n,size:yt[r],role:r}}function Tt(e){let t=bt*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 Et(e){if(e.type===`text`)return Tt(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 Dt(e,t){let n=[...e.map(Et),...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:xt(Math.min(...n.map(e=>e.minX))),minY:xt(Math.min(...n.map(e=>e.minY))),maxX:xt(Math.max(...n.map(e=>e.maxX))),maxY:xt(Math.max(...n.map(e=>e.maxY)))}}var Ot=(e,t,n)=>({end:St(e,t),side:n});Ot(-.5,0,`left`),Ot(.5,0,`right`),Ot(-.5,0,`left`),Ot(.5,0,`right`),Ot(-.5,0,`left`),Ot(.3,-.5,`bottom`),Ot(.3,.5,`top`);function kt(){return[Ct([0,0],[0,-.1]),Ct([-.15,-.1],[.15,-.1]),Ct([-.1,-.15],[.1,-.15]),Ct([-.05,-.2],[.05,-.2])]}function At(e){return[Ct([0,0],[0,.1]),Ct([-.1,.1],[.1,.1]),wt(e,St(0,.2),`center`,`value`)]}var jt=.16,Mt=jt*1.5,Nt=.66,Pt={right:{x:1,y:0},left:{x:-1,y:0},top:{x:0,y:1},bottom:{x:0,y:-1}};function Ft(e){let t=Pt[e.side],n=e.text.length*jt*Nt+Mt,r=t.x===0,i={x:e.at.x+t.x*n/2,y:e.at.y+t.y*n/2},[a,o]=r?[Mt,n]:[n,Mt];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 It=/[\w-]+/,Lt=new RegExp(String.raw`^net\.(${It.source})$`),Rt=/^([A-Za-z_][\w-]*)\.([\w-]+)$/,zt=/^\.([A-Za-z_][\w-]*)\s*>\s*\.([\w-]+)$/;function Bt(e){let t=e.trim(),n=Lt.exec(t);if(n?.[1])return{kind:`net`,name:n[1]};let r=zt.exec(t)??Rt.exec(t);return r?.[1]&&r[2]?{kind:`pin`,part:r[1],pin:r[2]}:void 0}var Vt=/^net\.((?:[\w-]+(?:~\d+)?\/)+)([\w-]+)$/;function Ht(e){let t=Vt.exec(e.trim());return t?.[1]&&t[2]?{instance:t[1].slice(0,-1),net:t[2]}:void 0}function Ut(e,t){return`${e.instance}/${e.net} is local to instance ${e.instance}; edit ${t??`its sheet file`} and use ${e.net} there`}var Wt={schematicpath:`path`,schematicrect:`rect`,schematiccircle:`circle`,schematicarc:`arc`,schematictext:`text`,bus:`bus`,junction:`junction`},Gt=.04,Kt=[`solid`,`dashed`,`dotted`],qt=[`left`,`center`,`right`];function Jt(e){return Object.hasOwn(Wt,e)?Wt[e]:void 0}var Yt=new RegExp(String.raw`^${It.source}$`),Xt=new RegExp(String.raw`^(${It.source})\[(\d+):(\d+)\]$`);function Zt(e){if(Yt.test(e))return[e];let t=Xt.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 Qt(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 $t(e,t){let n=t-e;return Math.abs(n)>=360?360:(n%360+360)%360}function en(e,t,n,r,i){let a=$t(r,i),o=[r,r+a];for(let e=Math.ceil(r/90)*90;e<r+a;e+=90)o.push(e);return Qt(o.map(r=>({x:e+n*Math.cos(r*Math.PI/180),y:t+n*Math.sin(r*Math.PI/180)})))}function tn(e,t,n,r,i){let a=bt*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 nn(e){switch(e.kind){case`path`:case`bus`:return Qt(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 en(e.x,e.y,e.radius,e.startAngle,e.endAngle);case`text`:return tn(e.x,e.y,e.text,e.fontSize,e.anchor);case`junction`:return{minX:e.x-Gt,minY:e.y-Gt,maxX:e.x+Gt,maxY:e.y+Gt}}}var rn=e=>xt(e)+0;function an(e){let t=nn(e);return{minX:rn(t.minX),minY:rn(t.minY),maxX:rn(t.maxX),maxY:rn(t.maxY)}}var on=/^[A-Za-z_][\w-]*$/;function sn(e,t,n,r){let i=Ht(n);if(i)return Ut(i,void 0);let a=n.replace(/^net\./,``);return r?Zt(a)===void 0?`${e} port ${t} is a bus port and takes a bus name such as "D[0:7]", not "${n}"`:void 0:on.test(a)?void 0:`${e} port ${t} is a net port and takes a net name such as "VBUS", not "${n}"`}function cn(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 ln=e=>e?.circuit.instances??[];function un(e,t){return ln(e).find(e=>e.path===t&&!e.path.includes(`/`))}function dn(e,t){let n=e?.circuit.components.find(e=>e.id===t);if(n?.instance===void 0)return;let r=ln(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 fn(e,t){return[...ln(e).find(e=>e.path===t)?.parts??[]]}function pn(e,t){return ln(e).filter(e=>e.file===t).length}function mn(e,t){return t===void 0?`In ${e}; every instance of it changes with it`:`In ${e}, used ${t===1?`once`:`${t} times`}`}function hn(e,t){let n=t.flatMap(t=>{let n=un(e,t);if(n)return[n.path];let r=dn(e,t);return r?[r.outer]:[]});if(n.length!==0)return[...new Set(n)].flatMap(t=>fn(e,t))}function gn(e,t,n){let r=Object.fromEntries(Object.entries(e.connections).filter(([e])=>e!==t));return n===``?r:{...e.connections,[t]:n}}function _n(e,t){return cn(e,t?.circuit.instances)}function vn(e,t,n){let r=dn(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 ${Qe(r.file)} shares it`}var yn=e=>Math.round(e*1e4)/1e4||0,bn=(e,t)=>e.x===t.x&&e.y===t.y;function xn(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 Sn(e,t=[]){let n=e[0];if(!n)return[];let r=[n];for(let n=1;n<e.length;n++)r.push(...xn(e[n-1],e[n],t[n-1]===!0));return r}function Cn(e){let t=e.map(e=>({x:yn(e.x),y:yn(e.y)})),n=[];for(let e of t){let t=n[n.length-1];t&&bn(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 wn(e,t=[]){return Cn(Sn(e,t))}var Tn=.2,En=/^[\w-]+$/,Dn=/^[A-Za-z_][\w-]*$/,On=/^([A-Za-z_][\w-]*)\.([\w-]+)$/,kn=/^\.([A-Za-z_][\w-]*)\s*>\s*\.([\w-]+)$/;function An(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 jn(e,t){let n=e.circuit.components.find(e=>e.id===t.component),r=An(n?.props??{},t.number),i=(n?.pins??[]).filter(e=>e.id!==t.id),a=r!==void 0&&En.test(r)&&!i.some(e=>e.names.includes(r));return`${t.component}.${a?r:`pin${t.number}`}`}function Mn(e,t){let n=t.trim(),r=On.exec(n)??kn.exec(n);return(r&&e.circuit.components.find(e=>e.id===r[1]))?.pins.find(e=>e.names.includes(r?.[2]??``))}var Nn=e=>e.circuit.components.flatMap(e=>e.pins),Pn=(e,t)=>e.circuit.nets.find(e=>e.pins.includes(t)),Fn=(e,t)=>Math.hypot(e.x-t.x,e.y-t.y);function In(e,t,n){let r=Pn(e,t.id)?.names[0],i=jn(e,t);return{selector:i,at:n,label:i,pin:t.id,...r===void 0?{}:{net:r}}}function Ln(e,t){let n=Pn(e,t);return n===void 0||n.pins.length<2&&n.names.length===0}function Rn(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 zn(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?Vn(a,i):Bn(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=sn(o.sheet,a.name,s,a.bus);return c===void 0?{edits:[{kind:`setConnections`,part:o.path,connections:gn(o,a.name,s)}],summary:`connect ${r.label} to ${s}`}:{notice:c}}var Bn=e=>e.members?void 0:e.selector.startsWith(`net.`)?e.selector.slice(4):e.net;function Vn(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 Hn(e,t,n){let r;for(let i of e.schematic.symbols)for(let[e,a]of Object.entries(i.pinEnds)){let i=Fn(a,t);i<=n&&(!r||i<r.d)&&(r={pin:e,at:a,d:i})}return r&&{pin:r.pin,at:r.at}}function Un(e,t,n,r={}){let i=Hn(e,t,n),a=i&&Nn(e).find(e=>e.id===i.pin);return i&&a?In(e,a,i.at):i&&Rn(e,i.pin,i.at)||(Xn(e,t,n)??Jn(e,t,n,r)??Qn(e,t,n,r))}function Wn(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=er(t,i,a),s=Fn(o,t);(!n||s<n.d)&&(n={at:o,d:s,a:i,b:a})}return n}var Gn=e=>Math.round(e*1e4)/1e4||0;function Kn(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=Gn(Math.round(e/a.step)*a.step);return o(s)?s:e}function qn(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=Kn(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 Jn(e,t,n,r){let i;for(let r of e.schematic.drawings){if(r.kind!==`bus`)continue;let e=Wn(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&&qn(i.near,t,n,r);return i&&a&&{selector:`bus:${i.id}`,at:{x:Gn(a.x),y:Gn(a.y)},label:i.name,members:i.members}}function Yn(e,t){return{selector:`net.${t}`,at:e.at,label:t,net:t}}function Xn(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=Zn(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 Zn(e,t){if(e.style!==`label`)return Math.max(Fn(e.at,t)-Tn,0);let{box:n}=Ft(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 Qn(e,t,n,r){let i;for(let r of e.schematic.wires){let e=Wn(r.points,t);e&&e.d<=n&&(!i||e.d<i.near.d)&&(i={net:r.net,near:e})}return i&&$n(e,i.net,qn(i.near,t,n,r))}function $n(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=Nn(e).find(e=>e.id===a);return o?{selector:jn(e,o),at:n,label:jn(e,o),pin:o.id}:void 0}function er(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 tr(e,t){if(t.pin!==void 0)return Pn(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=Nn(e).find(t=>jn(e,t)===n);return r&&Pn(e,r.id)}function nr(e,t){return e.selector===t.selector||e.pin!==void 0&&e.pin===t.pin}function rr(e,t,n){let[r,i]=[tr(e,t),tr(e,n)],[a,o]=[ir(t,r),ir(n,i)];if(r&&i&&r.id!==i.id&&a!==void 0&&o!==void 0)return[a,o]}var ir=(e,t)=>e.selector.startsWith(`net.`)?e.selector.slice(4):t?.names[0];function ar(e){let t=e.startsWith(`net.`)?void 0:e.split(`.`)[0];return t===void 0||Dn.test(t)&&!t.includes(`~`)}var or=e=>e.selector.startsWith(`net.`);function sr(e,t,n,r=[]){let i=wn([e.at,...n,t.at],r);return i.slice(+!or(e),or(t)?i.length:i.length-1)}function cr(e,t,n,r,i=[]){if(t.members||n.members||!ar(t.selector)||!ar(n.selector))return[];let[a,o]=[tr(e,t),tr(e,n)];if(nr(t,n)||a!==void 0&&a.id===o?.id)return[];let s=sr(t,n,r,i);return[{kind:`addTrace`,from:t.selector,to:n.selector,...s.length>0?{schematicRouteHints:s}:{}}]}var lr=/^net\.([\w-]+)$/,ur=new Set;function dr(e,t,n){return`pin`in n?t!==void 0&&Mn(e,t)?.id===n.pin:n.net.includes(lr.exec(t?.trim()??``)?.[1]??``)}function fr(e,t,n,r){return t.model.traces.filter(t=>dr(e,t.from,n)&&dr(e,t.to,r)||dr(e,t.from,r)&&dr(e,t.to,n))}function pr(e,t){return e[Number(/#(\d+)$/.exec(t??``)?.[1]??1)-1]??e[0]}function mr(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 hr(e,t,n,r){let i=[n?.from,n?.to].flatMap(t=>t===void 0?[]:[Mn(e,t)?.component??``]);return[...t,...i].find(e=>r.has(e))}function gr(e,t){return e.circuit.nets.find(e=>e.id===t)?.names??[t.replace(/^net\./,``)]}function _r(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 vr=.1,yr=e=>Math.round(e*1e3)/1e3||0;function br(e){if(e.style===`label`)return Ft(e).box;let t=Dt(e.style===`ground`?kt():At(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 xr(e){let t=br(e);return e.style===`label`?t:{minX:t.minX-vr,minY:t.minY-vr,maxX:t.maxX+vr,maxY:t.maxY+vr}}var Sr=(e,t)=>t.x>=e.minX&&t.x<=e.maxX&&t.y>=e.minY&&t.y<=e.maxY,Cr=e=>(e.maxX-e.minX)*(e.maxY-e.minY);function wr(e,t){return e.schematic.labels.map(e=>({label:e,box:xr(e)})).filter(({box:e})=>Sr(e,t)).sort((e,t)=>Cr(e.box)-Cr(t.box))[0]?.label}function Tr(e,t){return e.schematic.symbols.find(e=>e.pinEnds[t])?.pinEnds[t]}function Er(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&&Tr(e,o.id);return o&&s?{label:n,pin:o,end:s,...r?{connection:r}:{}}:void 0}function Dr(e,t){let n=Er(e,t);return n&&{part:n.pin.component,...n.connection?{wire:`wire:${n.connection.id}`}:{}}}function Or(e,t){let n=Er(e,t);return n&&`${n.label.net}|${n.pin.id}`}function kr(e){return`the ${e.text} ${e.style===`label`?`label`:`flag`}`}function Ar(e){let t=e.connection?.corners??[];return e.connection?.from===e.pin.id?t:[...t].reverse()}function jr(e,t){if(e.connection&&t.x===e.end.x&&t.y===e.end.y)return[];let n=e.connection?Ar(e).slice(0,-1):[],r=n[n.length-1]??e.end;return[...n,...Ce([r,t]).slice(1)]}var Mr=(e,t)=>e.length===t.length&&e.every((e,n)=>e.x===t[n]?.x&&e.y===t[n]?.y),Nr=e=>({x:yr(e.x),y:yr(e.y)});function Pr(e,t){return e?t.x===e.x?t.y<e.y?`bottom`:`top`:t.x>e.x?`right`:`left`:`right`}function Fr(e,t,n){let r=Er(e,t);if(!r)return;let i=Nr(n),a=[r.end,...jr(r,i)];return{at:i,side:Pr(a[a.length-2],i),wire:a,...r.connection?{hideWire:`wire:${r.connection.id}`}:{}}}function Ir(e,t,n){return pr(fr(e,t,{pin:n.pin.id},{net:gr(e,n.label.net)}),n.connection?.id)}function Lr(e,t,n,r){let i=Er(e,n);if(!i)return{blocked:`This label is not attached to a pin the Studio can find`};let a=Ir(e,t,i),o=hr(e,[i.pin.component],a,r);if(o!==void 0)return{blocked:`${o} is locked`};let s=a?_r(t,a)??mr(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&&!ar(jn(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 Rr(e,t,n,r=ur){let i=Lr(e,t,n,r);return`blocked`in i?i.blocked:null}function zr(e,t){let n=gr(e,t.net);return`net.${n.includes(t.text)?t.text:n[0]??t.text}`}function Br(e,t,n,r,i=ur){let a=Lr(e,t,n,i);if(`blocked`in a)return a;let{anchor:o,trace:s}=a,c=jr(o,Nr(r)).map(Nr);if(Mr(c,o.connection?Ar(o):[]))return[];if(!s)return[{kind:`addTrace`,from:jn(e,o.pin),to:zr(e,o.label),schematicRouteHints:c}];let l=s.from!==void 0&&Mn(e,s.from)?.id===o.pin.id;return[{kind:`setTraceHints`,from:s.from??``,to:s.to??``,schematicRouteHints:l?c:[...c].reverse()}]}var Vr=new Intl.Collator(`en`,{numeric:!0});function Hr(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 Ur(e,t){return Vr.compare(e,t)||Hr(e,t)}function Wr(e){return[...e].sort(Ur)}var Gr=4,Kr=6,qr=6;function Jr(e,t){let n=[...e].length;return n===0?0:((n-1)*qr+Gr)*t/Kr}function Yr(e){if(e.courtyard.length===0)return[{x:e.x,y:e.y}];let t=e.courtyard.map(e=>e.x),n=e.courtyard.map(e=>e.y),[r,i,a,o]=[Math.min(...t),Math.max(...t),Math.min(...n),Math.max(...n)],[s,c]=[(r+i)/2,(a+o)/2],[l,u]=[Jr(e.component,1)/2,1/2];return[{x:s,y:o+u},{x:s,y:a-u},{x:r-l,y:c},{x:i+l,y:c}]}var Xr=e=>e.nameAt??e.designatorAt??Yr(e)[0],Zr=.3,Qr=.5,$r=`"Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", sans-serif`,ei=`"Cascadia Mono", "JetBrains Mono", ui-monospace, Consolas, monospace`,ti={strong:600,regular:400},ni=(e,t,n=$r)=>`${e} ${t}px ${n}`,B={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 ri(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 ii=[`top`,`bottom`,`topSilk`,`bottomSilk`,`topAssembly`,`bottomAssembly`,`courtyard`,`boardOutline`,`multiLayer`,`hole`,`ratline`,`keepout`],ai=[{id:`top`,name:`Top Layer`},{id:`bottom`,name:`Bottom Layer`}],oi=[{id:`top`,name:`Top Layer`,group:`copper`,color:B.topCopper},{id:`bottom`,name:`Bottom Layer`,group:`copper`,color:B.bottomCopper},{id:`topSilk`,name:`Top Silkscreen`,group:`non-copper`,color:B.topSilk},{id:`bottomSilk`,name:`Bottom Silkscreen`,group:`non-copper`,color:B.bottomSilk},{id:`topAssembly`,name:`Top Assembly`,group:`non-copper`,color:B.topAssembly},{id:`bottomAssembly`,name:`Bottom Assembly`,group:`non-copper`,color:B.bottomAssembly},{id:`courtyard`,name:`Courtyard`,group:`non-copper`,color:B.topAssembly,bottomColor:B.bottomAssembly},{id:`boardOutline`,name:`Board Outline`,group:`non-copper`,color:B.boardEdge},{id:`multiLayer`,name:`Multi-Layer`,group:`copper`,color:B.multiLayer},{id:`hole`,name:`Hole`,group:`non-copper`,color:B.drill},{id:`ratline`,name:`Ratline`,group:`non-copper`,color:B.ratsnest},{id:`keepout`,name:`Keepout`,group:`non-copper`,color:B.keepout}];function si(e,t){return oi.filter(n=>(e||n.id!==`keepout`)&&(t===`all`||n.group===t))}function ci(e){return e.bottomColor?`linear-gradient(135deg, ${e.color} 50%, ${e.bottomColor} 50%)`:e.color}var li={...Object.fromEntries(ii.map(e=>[e,!0])),topAssembly:!1,bottomAssembly:!1};function ui(e,t){let n=new Set(e);return n.delete(t)||n.add(t),n}function di(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 fi(e,t){return{...e,[t]:!e[t]}}function pi(e){return e.layers===`through`?`multiLayer`:e.layers===`bottom`?`bottom`:`top`}function mi(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(pi(t)),t.drill&&n.add(`hole`);return[...n]}function hi(e,t){return e.some(e=>t[e])}function gi(e,t){let n=new Map(e.map(e=>[e.component,mi(e)]));return{visible:t,of:e=>n.get(e)}}var _i={parts:!0,labels:!0,wires:!0,drawings:!0,tracks:!0,vias:!0,texts:!0,pours:!0};function vi(e,t){return{...e,[t]:!e[t]}}function yi(e,t){return e===void 0||e[t]}function bi(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 xi={part:`parts`,label:`labels`,wire:`wires`,drawing:`drawings`,track:`tracks`,via:`vias`,text:`texts`,pour:`pours`,hole:`pours`};function Si(e,t){if(!Ci(xi[e.kind],t))return!1;let{layers:n}=t,r=e.kind===`part`?n?.of(e.name):void 0;return!n||!r||hi(r,n.visible)}function Ci(e,t){return t.armed===`note`||t.armed===`zoom`?!1:yi(t.filter,e)}function wi(e,t){return e.filter(e=>Si(e,t))}function Ti(e,t){return wi(e.map(e=>({kind:`part`,name:e})),t).map(e=>e.name)}function Ei(e,t){return wi(e.map(e=>({kind:`wire`,id:e})),t).map(e=>e.id)}function Di(e,t){return Ci(`labels`,t)?[...e]:[]}function V(e,t){return Ci(`drawings`,t)?[...e]:[]}function Oi(e,t){return wi(e.map(({kind:e,id:t})=>({kind:e,id:t})),t).map(e=>e.id)}function ki(e,t,n,r=[],i=[],a=[],o=[]){return s=>{let c={selection:s,armed:null,layers:t,filter:n};return s.all(Ti(e,c),Ei(r,c),Di(i,c),V(a,c),Oi(o,c))}}function Ai(e,t){return t.x>=e.x?`inside`:`touching`}var ji=(e,t)=>t.minX>=e.minX&&t.maxX<=e.maxX&&t.minY>=e.minY&&t.maxY<=e.maxY,Mi=(e,t)=>e.minX<=t.maxX&&t.minX<=e.maxX&&e.minY<=t.maxY&&t.minY<=e.maxY;function Ni(e,t,n,r){let i=xe([t,n]);if(!i)return[];let a=r===`inside`?e=>ji(i,e):e=>Mi(i,e);return e.filter(e=>a(e.box)).map(e=>e.id)}function Pi(e,t,n,r){return Ni(e.map(e=>({id:e.name,box:e.box})),t,n,r)}function Fi(e,t,n,r){return Ni(e,t,n,r)}var Ii=(e,t)=>t.x>=e.minX&&t.x<=e.maxX&&t.y>=e.minY&&t.y<=e.maxY;function Li(e,t,n){if(Ii(e,t)||Ii(e,n))return!0;let r=xe([t,n]);if(!r||!Mi(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 Ri(e,t,n,r){let i=xe([t,n]);if(!i)return[];let a=r===`inside`?e=>e.every(e=>Ii(i,e)):e=>e.some((t,n)=>Li(i,e[n-1]??t,t));return e.filter(e=>a(e.points)).map(e=>e.id)}function zi(e,t,n=null,r,i){return a=>{let o={selection:a,armed:n,layers:r,filter:i},[s,c,l]=[Ti(e.parts,o),Ei(e.wires??[],o),Di(e.labels??[],o)],u=V(e.drawings??[],o),d=Oi(e.copper??[],o);return t?a.add(s).addWires(c).addLabels(l).addDrawings(u).addCopper(d):a.all(s,c,l,u,d)}}var Bi=e=>[...new Set(e)],Vi=(e,t)=>e.length===t.length&&e.every((e,n)=>e===t[n]),Hi=(e,t)=>e.filter(e=>!t.includes(e)),Ui=(e,t)=>{let n=new Set(t);return e.filter(e=>n.has(e))},Wi=(e,t)=>e!==void 0&&e.x===t.x&&e.y===t.y,Gi=(e,t)=>e!==void 0&&e.id===t.id&&e.index===t.index&&Wi(e.from,t.from)&&Wi(e.to,t.to);function Ki(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 qi(e,t){return Wi(t[e.index],e.from)&&Wi(t[e.index+1],e.to)}var Ji={names:[],wires:[],labels:[],drawings:[],copper:[],texts:[],board:[]},Yi=[`names`,`wires`,`labels`,`drawings`,`copper`,`texts`,`board`],Xi=class e{static none=new e(Ji);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 Yi.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 Yi.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({...Ji,board:[t]})}toggleBoard(e){return this.hasBoard(e)?this.withoutBoard([e]):this.grown({board:[...this.board,e]})}addBoard(e){let t=Bi(e).filter(e=>!this.hasBoard(e));return t.length===0?this:this.grown({board:[...this.board,...t]})}withoutBoard(e){return this.with({board:Hi(this.board,e)})}keepBoard(e){return this.with({board:Ui(this.board,e)})}only(t){return this.total===1&&this.names[0]===t?this:new e({...Ji,names:[t]})}onlyWire(t){return this.soleWire===t?this:new e({...Ji,wires:[t]})}onlyLabel(t){return this.soleLabel===t?this:new e({...Ji,labels:[t]})}onlyDrawing(t){return this.soleDrawing===t?this:new e({...Ji,drawings:[t]})}onlyText(t){return this.soleText===t?this:new e({...Ji,texts:[t]})}onlyCopper(t){return this.soleCopper===t&&!this.segment?this:new e({...Ji,copper:[t]})}onlySegment(t){return Gi(this.segment,t)?this:new e({...Ji,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:Hi(this.texts,[e])}):this.grown({texts:[...this.texts,e]})}add(e){let t=Bi(e).filter(e=>!this.has(e));return t.length===0?this:this.grown({names:[...this.names,...t]})}addWires(e){let t=Bi(e).filter(e=>!this.hasWire(e));return t.length===0?this:this.grown({wires:[...this.wires,...t]})}addLabels(e){let t=Bi(e).filter(e=>!this.hasLabel(e));return t.length===0?this:this.grown({labels:[...this.labels,...t]})}addDrawings(e){let t=Bi(e).filter(e=>!this.hasDrawing(e));return t.length===0?this:this.grown({drawings:[...this.drawings,...t]})}addCopper(e){let t=Bi(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:Bi(t),wires:Bi(n),labels:Bi(r),drawings:Bi(i),copper:Bi(a),texts:[],board:[]};return Yi.every(e=>Vi(o[e],this[e]))?this:e.from(o)}without(e){return this.with({names:Hi(this.names,e)})}withoutWires(e){return this.with({wires:Hi(this.wires,e)})}withoutLabels(e){return this.with({labels:Hi(this.labels,e)})}withoutDrawings(e){return this.with({drawings:Hi(this.drawings,e)})}withoutCopper(e){return this.with({copper:Hi(this.copper,e)})}keep(e){return this.with({names:Ui(this.names,e)})}keepWires(e){return this.with({wires:Ui(this.wires,e)})}keepLabels(e){return this.with({labels:Ui(this.labels,e)})}keepDrawings(e){return this.with({drawings:Ui(this.drawings,e)})}withoutTexts(e){return this.with({texts:Hi(this.texts,e)})}keepTexts(e){return this.with({texts:Ui(this.texts,e)})}keepCopper(e){return this.with({copper:Ui(this.copper,e)})}};function Zi(e,t){let{segment:n}=e,r=n&&t.find(e=>e.id===n.id);return n&&r&&!qi(n,r.points)?e.onlyCopper(n.id):e}function Qi(e){return e.shiftKey||e.ctrlKey||e.metaKey}function $i(e,t){let n=Qi(t);return t=>n?t.toggle(e):t.only(e)}function ea(e,t){let n=new Set(t);return e.filter(e=>!n.has(e))}var ta={error:B.error,warning:B.warning},na=6,ra=1.5,ia=3,aa=1;function oa(e,t,n,r,i,a=ta){if(n.length!==0){e.globalAlpha=1,e.setLineDash([]);for(let o of n){let n=fe(t.camera,t.size,o.at),s=o.id===r?ia:ra;i&&ca(e,n,s),e.strokeStyle=o.severity===`error`?a.error:a.warning,sa(e,n,na,s)}}}function sa(e,t,n,r){e.lineWidth=r,e.beginPath(),e.arc(t.x,t.y,n,0,Math.PI*2),e.stroke()}function ca(e,t,n){let r=(n+aa)/2;e.strokeStyle=B.ringHaloOuter,sa(e,t,na+r,aa),e.strokeStyle=B.ringHaloInner,sa(e,t,na-r,aa)}var la={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:B.error,markerWarning:B.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`},ua={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`},da=e=>e===`dark`?ua:la,fa=la,H=()=>fa;function pa(e){fa=e}function ma(e,t,n=fa){let r=t?n.selectionGlow:0;e.shadowBlur=r,e.shadowColor=r>0?n.selection:`transparent`}var ha=.02,ga=3*ha;function _a(e){return e.kind===`bus`?ga:e.kind===`text`||e.kind===`junction`?0:e.strokeWidth}var va=(e,t)=>Math.max(e,t);function ya(e,t){return e===`dashed`?[4*t,3*t]:e===`dotted`?[0,2*t]:[]}function ba(e){return e.kind===`bus`||e.kind===`text`||e.kind===`junction`?`solid`:e.lineStyle}function xa(e){return e.kind===`bus`?H().bus:e.kind===`junction`?e.color??H().junction:e.color??H().drawing}var Sa=e=>(e.kind===`rect`||e.kind===`circle`)&&e.filled,Ca=e=>`${e}33`,wa=e=>1/e,Ta=(e,t)=>(Math.floor(e*t)+.5)/t,Ea=(e,t)=>Math.round(e*t)/t,Da=(e,t)=>Math.max(1,Math.round(e*t))/t,Oa=(e,t)=>Math.round(e*t)/t,ka=(e,t)=>e/t,Aa=(e,t)=>Math.max(1,Math.round(e*t)),ja=(e,t,n)=>n%2==1?Ta(e,t):Ea(e,t);function Ma(e,t,n,r=1){let i=e=>ja(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 Na=.16;function Pa(e){return e<7?`none`:e<9?`names`:`all`}function Fa(e,t,n){if(n<5)return!1;let r=Pa(t);return e===`name`?r!==`none`:e===`pin-number`?t>=11:r===`all`}var Ia=(e,t,n)=>Math.max(1,Math.round(e*t*n)),La=(e,t)=>Ia(Na,e,t),Ra=(e,t,n)=>Ia(e,t,n)/n,za=(e,t)=>({x:Ea(e.x,t),y:Oa(e.y,t)});function Ba(e){`textRendering`in e&&(e.textRendering=`geometricPrecision`)}var Va=(e,t,n)=>t<=n||t<=0?e:Math.max(1,Math.floor(e*n/t)),U=e=>e*Math.PI/180;function Ha(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 Ua(e,t){let n=t-e;return Math.abs(n)>=360?360:(n%360+360)%360}function Wa(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=U(t.startAngle);e.arc(t.x,t.y,t.radius,n,n+U(Ua(t.startAngle,t.endAngle)))}function Ga(e,t){return t.selected?.includes(e.id)?{color:H().selection,alpha:1}:{color:xa(e),alpha:t.dim?Zr:1}}function Ka(e,t,n,r,i){e.globalAlpha=r,e.fillStyle=n,e.beginPath(),e.arc(t.x,t.y,Gt,0,2*Math.PI),ma(e,i),e.fill(),ma(e,!1)}function qa(e,t,n,r){for(let i of t){if(i.kind===`text`)continue;let{color:t,alpha:a}=Ga(i,r);if(i.kind===`junction`){Ka(e,i,t,a,r.selected?.includes(i.id)??!1);continue}let o=va(_a(i),n);e.globalAlpha=a,e.lineWidth=o,e.strokeStyle=t,e.setLineDash(ya(r.pending?`dashed`:ba(i),o)),Wa(e,i),Sa(i)&&(e.fillStyle=Ca(t),e.fill()),ma(e,r.selected?.includes(i.id)??!1),e.stroke(),ma(e,!1),e.setLineDash([])}e.globalAlpha=1}function Ja(e,t,n,r,i,a){for(let o of t){if(o.kind!==`text`||o.text===``)continue;let t=Ia(o.fontSize,n.scale,a);if(!Fa(`detail`,La(n.scale,a),t))continue;let s=t/a,{color:c,alpha:l}=Ga(o,i),u=za(fe(n,r,o),a),[,d]=ri(o.anchor);e.globalAlpha=l,e.fillStyle=c,e.font=`${s}px ${$r}`,e.textAlign=d,e.textBaseline=`middle`,e.fillText(o.text,u.x,u.y)}e.globalAlpha=1}var Ya=.7,Xa=`…`,Za=2;function Qa(e,t,n){if(n(e)<=t)return e;for(let r=e.length-1;r>=Za;r--){let i=e.slice(0,r)+Xa;if(n(i)<=t)return i}return null}function $a(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>=Za;r--){let i=e.slice(0,r)+Xa;if(t(i)>=n)return{text:i,scale:n}}return null}function eo(e,t,n){if(t+n<=e)return t;let r=e/2;return t<=r?t:n<=r?e-n:r}var to=(e,t,n,r)=>t===`x`===e.quarter?e.size:r(n),no=e=>e.side===`left`||e.side===`right`,ro=e=>no(e)?`x`:`y`,io=e=>no(e)?`y`:`x`,ao=e=>no(e)?1:.5,oo={left:`right`,right:`left`,top:`bottom`,bottom:`top`};function so(e,t,n,r){let[i,a]=[ro(e),io(e)],o=e.side===`left`||e.side===`bottom`?1:-1,s=e=>to(e,i,e.text,n)*ao(e),c=t=>Math.abs(t.local[a]-e.local[a])<(to(e,a,e.text,n)+to(t,a,t.text,n))/2,l=t.filter(t=>t.side===oo[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 eo(Math.abs((l?l.local[i]:-e.local[i])-e.local[i])-r,s(e),l?s(l):0)/ao(e)}function co(e,t,n){let r=io(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 lo(e,t,n,r,i){let a=so(e,t,n,r),o=co(e,t,r);return $a(e.text,t=>Math.min(a/to(e,ro(e),t,n),o/to(e,io(e),t,n)),i)}function uo(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 fo=(e,t)=>e.x0<t.x1&&t.x0<e.x1&&e.y0<t.y1&&t.y0<e.y1;function po(e,t){let n=new Set;return e.forEach((r,i)=>{e.forEach((e,a)=>{a>i&&r&&e&&t(i,a)&&fo(r,e)&&n.add(i).add(a)})}),n}function mo(e,t,n,r=Ya){let i=e.map(i=>lo(i,e,t,n,r)),a=i.map((n,r)=>n===null?null:uo(e[r],n,t)),o=po(a,(t,n)=>e[t]?.side===e[n]?.side),s=po(a.map((e,t)=>o.has(t)?null:e),()=>!0);return i.map((e,t)=>o.has(t)||s.has(t)?null:e)}var ho=.25,go=.8,_o=.2,vo={top:go,middle:.6000000000000001/2,bottom:-.2},yo=(e,t,n)=>ni(e.strong?ti.strong:ti.regular,t/n,e.mono?ei:void 0);function bo(e,t,{camera:n,ratio:r}){let i=Ia(t.size,n.scale,r);return t.maxWidth===void 0?i:(e.font=yo(t,i,r),Va(i,e.measureText(t.text).width,t.maxWidth*n.scale))}function xo(e,t,n,r){e.textBaseline=n;let i=e.measureText(t),a=(vo[n]??0)*r;return{ascent:i.actualBoundingBoxAscent??go*r-a,descent:i.actualBoundingBoxDescent??_o*r+a}}function So(e,{label:t,devicePx:n},r){let i=t.pinOf;if(!i)return null;let a=n/r.ratio,o=fe(r.camera,r.size,t.at),[s,c]=ri(t.anchor),l={x:i.local.x*r.camera.scale,y:i.local.y*r.camera.scale},u=xo(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 Co(e,t,n){let r=t[0];if(!r)return t;e.font=yo(r.label,r.devicePx,n.ratio);let i=t.map(t=>So(e,t,n)).filter(e=>e!==null);if(i.length!==t.length)return t;let a=Math.ceil(r.devicePx*Ya)/r.devicePx,o=mo(i,t=>e.measureText(t).width,r.devicePx/n.ratio*ho,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 wo(e,t,n){let r=La(n.camera.scale,n.ratio),i=({label:e,devicePx:t})=>Fa(e.kind,r,t),a=t.filter(e=>e.text!==``).map(t=>({label:t,devicePx:bo(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=>Co(e,t,n));return[...a.filter(({label:e})=>!e.pinOf),...s.filter(i)]}function To(e,{label:t,devicePx:n},r){let i=za(fe(r.camera,r.size,t.at),r.ratio),[a,o]=ri(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=yo(t,n,r.ratio),e.textAlign=o,e.textBaseline=a,e.fillText(t.text,0,0),e.restore()}function Eo(e,t,n,r,i){let a={camera:n,size:r,ratio:i};Ba(e);for(let n of wo(e,t,a))To(e,n,a)}var Do=.05,Oo=.015;function ko(e){let t=Do;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 Ao(e,t,n,r){if(t.length!==0){e.strokeStyle=H().noConnect,e.lineWidth=n(Oo),e.globalAlpha=r?Zr:1;for(let n of t)for(let[t,r]of ko(n.at))e.beginPath(),e.moveTo(t.x,t.y),e.lineTo(r.x,r.y),e.stroke();e.globalAlpha=1}}var jo={x:0,y:0},Mo=.02,No=1.2,Po=3.5,Fo=.06,Io=1.5,Lo=1.6,Ro=.04,zo=3,Bo=[.1,.06],Vo=.1,Ho=.07,Uo=2.5,Wo={reference:`name`,value:`detail`,"pin-name":`detail`,"pin-number":`pin-number`},Go={reference:`designator`,value:`value`,"pin-name":`pinName`,"pin-number":`pinNumber`},Ko={right:{x:1,y:0},left:{x:-1,y:0},top:{x:0,y:1},bottom:{x:0,y:-1}},qo=e=>e*Math.PI/180,Jo=e=>Math.max(ha*e,No);function Yo(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:jo;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`,ss(e,t,r,o,s);let d=Ha(t.drawings,r.movingDrawings),f=r.pendingDrawings??[],p=[...d,...f],m={...r.selectedDrawings?{selected:r.selectedDrawings}:{},dim:r.highlight!==void 0};qa(e,d,o/r.ratio,m),qa(e,f,o/r.ratio,{pending:!0,dim:m.dim});for(let n of t.symbols)cs(e,n,l(n),{line:s,px:o,fade:rs(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:H().selection,alpha:1}:ns(n.net,r.highlight);ma(e,i),_s(e,gs(n,r),s,c,t,a),ma(e,!1)}for(let t of r.ghostLabels??[])_s(e,t,s,c,!0,ns(t.net,void 0));bs(e,t,r,o,l),Ao(e,t.noConnects??[],s,r.highlight!==void 0),e.setTransform(r.ratio,0,0,r.ratio,0,0),Eo(e,c,i,a,r.ratio),Ja(e,p,i,a,m,r.ratio),oa(e,n,r.violations??[],r.activeViolation,!1,{error:H().markerError,warning:H().markerWarning}),e.restore()}function Xo(e){return e.symbols.map(e=>{let t=Qo(e);return{name:e.component,pcbComponentId:e.component,center:{x:(t.minX+t.maxX)/2,y:(t.minY+t.maxY)/2},box:t}})}var Zo=e=>e.type===`text`&&(e.role===`reference`||e.role===`value`);function Qo(e){let{minX:t,minY:n,maxX:r,maxY:i}=Dt(e.symbol.shapes.filter(e=>!Zo(e)),e.symbol.pins),a=[{x:t,y:n},{x:r,y:n},{x:r,y:i},{x:t,y:i}].map(t=>$o(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 $o(e,t){let n=qo(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 es(e,t){e.beginPath(),t.forEach((t,n)=>n===0?e.moveTo(t.x,t.y):e.lineTo(t.x,t.y))}function ts(e,t,n){e.beginPath(),e.arc(t.x,t.y,Math.max(n,0),0,Math.PI*2)}function ns(e,t){return t?e===t.net||t.aliases?.includes(e)?{color:H().highlight,alpha:1}:{color:void 0,alpha:Zr}:{color:void 0,alpha:1}}function rs(e,t){return t?t.pins?.some(t=>t in e.pinEnds)?1:Zr:1}var is=1e-9;function as(e,t,n){let r=Math.abs((n.x-t.x)*(e.y-t.y)-(n.y-t.y)*(e.x-t.x))<is,i=(e,t,n)=>e>=Math.min(t,n)-is&&e<=Math.max(t,n)+is;return r&&i(e.x,t.x,n.x)&&i(e.y,t.y,n.y)}function os(e,t,n){return e.wires.some(e=>ns(e.net,n).color!==void 0&&e.points.some((n,r)=>r>0&&as(t,e.points[r-1]??n,n)))}function ss(e,t,n,r,i){e.lineWidth=i(ha);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:H().selection,alpha:1}:ns(r.net,n.highlight);e.strokeStyle=i.color??H().wire,e.globalAlpha=i.alpha,ma(e,t),es(e,r.points),e.stroke()}ma(e,!1);for(let i of t.junctions){let a=n.highlight!==void 0&&os(t,i,n.highlight);e.fillStyle=a?H().highlight:H().junction,e.globalAlpha=n.highlight&&!a?Zr:1,ts(e,i,Math.max(Ro,zo*r)),e.fill()}e.globalAlpha=1,e.strokeStyle=H().wire;let a=(n.pending??[]).filter(e=>e.length>=2);if(a.length!==0){e.setLineDash(Bo);for(let t of a)es(e,t),e.stroke();e.setLineDash([])}}function cs(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(Mo),ds(e,t.symbol.shapes,a,H().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(...us(t.symbol,a)),i.push(...s.map(e=>({...e,alpha:o,...ls(e,t)})))}function ls(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:Uo*Math.hypot(n.end.x-r.end.x,n.end.y-r.end.y)}:{}}function us(e,t){return e.pins.map(e=>{let n=Ko[e.side],r={x:e.end.x-n.x*Vo,y:e.end.y-n.y*Vo},i=n.x===0?{x:r.x+Ho,y:r.y}:{x:r.x,y:r.y+Ho};return{text:String(e.number),at:$o(i,t),size:.1,anchor:`center`,color:H().pinNumber,mono:!0,kind:`pin-number`}})}function ds(e,t,n,r,i){e.save(),e.translate(n.x,n.y),n.rotation&&e.rotate(qo(n.rotation)),e.strokeStyle=r,e.fillStyle=r;for(let a of t)a.type===`text`?i.push(ms(a,n,r)):a.type===`polyline`&&a.bus?fs(e,a):ps(e,a);e.restore()}function fs(e,t){let[n,r]=[e.strokeStyle,e.fillStyle];e.strokeStyle=H().bus,e.fillStyle=H().bus,es(e,t.points),e.closePath(),e.fill(),e.stroke(),e.strokeStyle=n,e.fillStyle=r}function ps(e,t){if(t.type===`polyline`)es(e,t.points),(t.closed||t.fill)&&e.closePath(),t.fill&&e.fill(),e.stroke();else if(t.type===`circle`)ts(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,qo(t.start),qo(n)),e.stroke()}}function ms(e,t,n){let r=e.anchor===`left`?1:e.anchor===`right`?-1:0,i=qo(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:Wo[e.role],...e.role===`pin-name`?{pinOf:hs(e,t)}:{},...e.role===`reference`?{strong:!0}:{},...e.role===`pin-number`?{mono:!0}:{}};return{text:e.text,at:$o(e.at,t),size:e.size,anchor:s,color:H()[Go[e.role]]??n,...c}}function hs(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(qo(t.rotation)))>.5}}function gs(e,t){let n=t.movingLabels?.find(t=>t.id===e.id);return n?{...e,at:n.at,side:n.side}:e}function _s(e,t,n,r,i,a){e.setLineDash(i?Bo:[]),e.globalAlpha=a.alpha,vs(e,t,n,r,a),e.globalAlpha=1,e.setLineDash([])}function vs(e,t,n,r,i){if(t.style!==`label`){let a=t.style===`ground`?kt():At(t.text);e.lineWidth=n(Mo);let o=r.length;ds(e,a,{x:t.at.x,y:t.at.y,rotation:0},i.color??H().flag,r);for(let e=o;e<r.length;e++)r[e]={...r[e],strong:!0,kind:`name`,color:i.color??H().netName,alpha:i.alpha};return}let{middle:a,upright:o,box:s}=Ft(t);r.push({text:t.text,at:a,size:jt,anchor:`center`,strong:!0,kind:`name`,color:i.color??H().netName,rotation:o?90:0,alpha:i.alpha}),t.port&&ys(e,t,s,n,i)}function ys(e,t,n,r,i){e.strokeStyle=i.color??H().netName,e.lineWidth=r(t.bus?Mo*3:Mo),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 bs(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?H().highlight:H().pin;let c=a?Math.min(Po*r,Math.max(Fo,Io*r)):(s?Lo:1)*Po*r;ts(e,{x:o.x+t.x,y:o.y+t.y},c),e.fill()}}}var xs=2;function Ss(e,t){return Math.max(e,Jo(t)/2+xs)}var Cs=e=>Ss(6,e);function ws(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 Ts(e,t){let n;for(let r=1;r<e.length;r++){let i=ws(t,e[r-1],e[r]);(!n||i<n.distance)&&(n={index:r-1,distance:i})}return n}function Es(e,t,n){let r=Ts(e,t);return r&&r.distance<=n?r.index:void 0}function Ds(e,t,n){let r;for(let i of e){let e=Ts(i.points,t);e&&e.distance<=n&&(!r||e.distance<r.distance)&&(r={id:i.id,distance:e.distance})}return r?.id}function Os(e){return e.length<2?{corners:[],ends:[...e]}:{corners:e.slice(1,-1),ends:[e[0],e[e.length-1]]}}function ks(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 As=1e-9,js={x:0,y:0},Ms=(e,t)=>Math.abs(e-t)<As;function Ns(e,t){return Ms(e.y,t.y)?`horizontal`:Ms(e.x,t.x)?`vertical`:`slanted`}function Ps(e,t){return e===`horizontal`?{x:0,y:t.y}:e===`vertical`?{x:t.x,y:0}:t}function Fs(e,t){return e===`horizontal`?Ms(t.y,0):e!==`vertical`||Ms(t.x,0)}function Is(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=>!Ms(e.x,0))?.x??0,y:r.find(e=>!Ms(e.y,0))?.y??0}})}function Ls(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&&!Fs(Ns(a,o),n)}function Rs(e,t){let n=Is(e,t);return Cn(e.flatMap((r,i)=>{let a=n[i]??js,o={x:r.x+a.x,y:r.y+a.y},s=t.has(i-1);return s===t.has(i)||!Ls(e,i,a,t)?[o]:s?[o,r]:[r,o]}))}function zs(e,t,n){let[r,i]=[e[t],e[t+1]];return!r||!i?Cn(e):Rs(e,new Map([[t,Ps(Ns(r,i),n)]]))}function Bs(e,t,n){let[r,i,a]=[e[t-1],e[t],e[t+1]];if(!r||!i||!a)return Cn(e);let o={x:n.x-i.x,y:n.y-i.y};return Rs(e,new Map([[t-1,Ps(Ns(r,i),o)],[t,Ps(Ns(i,a),o)]]))}var Vs=(e,t)=>({x:e.x+t.x,y:e.y+t.y});function Hs(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 Cn(e);let s=n.start?[Vs(r,t)]:[r,Vs(r,Ps(Ns(r,i),t))],c=n.end?[Vs(o,t)]:[Vs(o,Ps(Ns(a,o),t)),o];return Cn([...s,...e.slice(1,-1).map(e=>Vs(e,t)),...c])}function Us(e,t){let[n,r]=[e[t-1],e[t]];if(!n||!r||t>=e.length-1)return Cn(e);let i=e.slice(0,-2).map(()=>!1);return i[t-1]=Ns(n,r)===`horizontal`,Cn(Sn(e.filter((e,n)=>n!==t),i))}var Ws=Cn,Gs=`The pin of this wire has several traces to its net; change its corners in the code`,Ks=1e-6;function qs(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)-Ks<=t.x&&t.x<=Math.max(i.x,n.x)+Ks&&Math.min(i.y,n.y)-Ks<=t.y&&t.y<=Math.max(i.y,n.y)+Ks;return Math.abs(a)<=Ks&&o})}function Js(e,t,n,r){return e.schematic.wires.some(e=>e.id!==t&&e.net===n&&qs(e.points,r))}function Ys(e,t,n,r){let i=fr(e,t,{pin:n.id},{net:gr(e,r)}),[a]=i;if(!a)return{};if(i.length>1||a.props.schematicRouteHints)return{blocked:Gs};let o=mr(a)??_r(t,a);return o===void 0?{trace:a}:{blocked:o}}function Xs(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 Zs=/^wire:.+:\d+$/,Qs=e=>e.startsWith(`net.`),$s=(e,t)=>e.x===t.x&&e.y===t.y,ec=(e,t)=>e.circuit.components.flatMap(e=>e.pins).find(e=>e.id===t);function tc(e,t,n){return{id:e,points:t,fixed:{start:!0,end:!0},writer:n}}function nc(e,t,n){let r=t=>Qs(t)?{net:gr(e,t)}:{pin:t};return pr(fr(e,t,r(n.from),r(n.to)).filter(t=>dr(e,t.from,r(n.from))),n.id)}function rc(e,t,n,r,i){let a=nc(e,t,i);if(!a)return tc(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=>!Qs(e)),s=o.map(t=>ec(e,t)?.component??``),c=o.length===1,l=_r(t,a);return tc(n,r,{kind:`trace`,trace:a,toNet:c,reversed:c&&Qs(i.from),components:s,...l?{repeat:l}:{}})}function ic(e,t,n){let r=t.find(t=>e.schematic.symbols.some(e=>e.pinEnds[t]!==void 0&&$s(e.pinEnds[t],n)));return r===void 0?void 0:ec(e,r)}var ac=(e,t)=>{let n=t.find(t=>!ar(jn(e,t)));return n?{unaddressable:`${n.id} has a repeated name and cannot be wired from the Studio`}:{}};function oc(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||!Js(e,n,o,c))return;let l={pinLast:a,...Ys(e,t,i,o)};return tc(n,r,{kind:`engine`,from:jn(e,i),to:`net.${s}`,components:[i.component],...ac(e,[i]),onWire:l})}function sc(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?[ic(e,a.pins,o),ic(e,a.pins,s)]:[];return(c&&!l?oc(e,t,n,r,c,!1,i):!c&&l?oc(e,t,n,r,l,!0,i):void 0)||(!c||!l?tc(n,r,{kind:`none`,reason:`The pins of this wire are not on the sheet`}):tc(n,r,{kind:`engine`,from:jn(e,c),to:jn(e,l),components:[c.component,l.component],...ac(e,[c,l])}))}function cc(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?rc(e,t,r.id,i,a):Zs.test(r.id)?sc(e,t,r.id,i,r.net):tc(r.id,i,{kind:`none`,reason:`This wire is not drawn from the code`})}function lc(e,t,n=ur){let{writer:r}=t;if(r.kind===`none`)return r.reason;let i=hr(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??mr(r.trace)??null:`${i} is locked`}function uc(e,t){let n=e.slice(1,t.toNet?void 0:-1);return t.reversed?[...n].reverse():n}function dc(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&&$s(n,i)&&$s(r,a)}var fc=(e,t)=>e.length===t.length&&e.every((e,n)=>$s(e,t[n]));function pc(e,t,n,r=ur,i=t.points){let a=lc(e,t,r);if(a!==null)return{blocked:a};let o=Ws(n);if(!dc(o,t))return{blocked:`The ends of a wire stay on their pins`};if(fc(o,Ws(i)))return[];let{writer:s}=t;if(s.kind===`trace`)return[{kind:`setTraceHints`,from:s.trace.from??``,to:s.trace.to??``,schematicRouteHints:uc(o,s)}];if(s.kind!==`engine`)return[];if(s.onWire)return Xs(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 mc=e=>({hover:e.hover,selected:e.selection,handleFill:e.handleFill});mc(la);var hc=3,gc=e=>Ss(hc,e),_c=[4,3],vc=(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}},yc=e=>({x:-e.y,y:e.x}),bc=(e,t,n)=>({x:e.x+t.x*n,y:e.y+t.y*n});function xc(e,t,n,r,i){let a=e[n];if(n===0)return bc(bc(a,t[0],-r),yc(t[0]),r*i);if(n===e.length-1)return bc(bc(a,t[n-1],r),yc(t[n-1]),r*i);let[o,s]=[yc(t[n-1]),yc(t[n])],c=o.x*s.x+o.y*s.y;return bc(a,1+c<.1?o:{x:(o.x+s.x)/(1+c),y:(o.y+s.y)/(1+c)},r*i)}function Sc(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)=>vc(n[t],e)),i=e=>n.map((i,a)=>xc(n,r,a,t,e));return[...i(1),...i(-1).reverse()]}function Cc(e,t,n,r,i,a){let o=Sc(r.map(e=>fe(t,n,e)),gc(t.scale));o.length!==0&&(e.save(),e.strokeStyle=i.hover,e.lineWidth=wa(a),e.setLineDash(_c),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 wc(e,t,n,r,i,a){let{corners:o,ends:s}=Os(r),c=Da(6,a),l=wa(a),u=(r,i)=>{let o=fe(t,n,r),[s,u]=[Ea(o.x-c/2,a),Ea(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 Tc=e=>3/e,Ec=e=>Cs(e)/e;function Dc(e,t,n,r){let i=t===void 0?void 0:e?.points(t),a=i?ks(i,n,Tc(r)):void 0;return t===void 0||a===void 0?void 0:{id:t,index:a}}function Oc(e,t,n,r){let i=t.selection.soleWire;if(i!==void 0&&Si({kind:`wire`,id:i},t))return Dc(e,i,n,r)}function kc(e,t,n,r){if(r!==void 0)return{kind:`corner`,index:r};let i=Es(e,t,Ec(n));return i===void 0?void 0:{kind:`segment`,index:i}}function Ac(e,t,n,r){let i=e[t.index];if(!i)return Ws(e);let a={x:ve(i.x+n.x,r.step,r.snap),y:ve(i.y+n.y,r.step,r.snap)};return t.kind===`corner`?Bs(e,t.index,a):zs(e,t.index,{x:a.x-i.x,y:a.y-i.y})}function jc(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 Mc(e,t,n,r){return e.blocker?(e.moved||r(e.blocker),{...e,moved:!0}):{...e,moved:!0,path:Ac(e.points,e.grip,t,n)}}var Nc=`The wire changed while you dragged it; try again`;function Pc(e,t,n){if(!e||!t.moved||t.blocker||fc(t.path,Ws(t.points)))return;let r=e.points(t.wire);if(!r||!fc(r,t.points))return n(Nc);e.commit(t.wire,t.path)}function Fc(e,t){return!e?.moved||e.blocker?t:[{id:e.wire,points:e.path},...t.filter(t=>t.id!==e.wire)]}function Ic(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 Lc=e=>e.missingLayer===void 0?{}:{missingLayer:e.missingLayer};function Rc(e,t){return e.missingLayer===void 0?e.kind===`via`?t.multiLayer:(e.layer===`top`||e.layer===`bottom`)&&t[e.layer]:t.keepout}var zc=2,Bc=(e,t)=>Math.max(6,e*t/2+zc)/t;function Vc(e,t,n,r,i){let a=e.find(e=>Rc({kind:`via`,...Lc(e)},r)&&Si({kind:`via`,id:e.id},i)&&Math.hypot(t.x-e.at.x,t.y-e.at.y)<=Bc(e.diameter,n));return a&&{kind:`via`,id:a.id}}function Hc(e,t){let n=1/0;for(let r=1;r<e.length;r++)n=Math.min(n,ws(t,e[r-1],e[r]));return n}function Uc(e,t,n,r,i){let a;for(let o of e){if(!Rc({kind:`track`,layer:o.layer,...Lc(o)},r)||!Si({kind:`track`,id:o.id},i))continue;let e=Hc(o.points,t);e<=Bc(o.width,n)&&(!a||e<a.distance)&&(a={id:o.id,distance:e})}return a&&{kind:`track`,id:a.id}}function Wc(e,t,n,r,i){return Vc(e.vias,t,n,r,i)??Uc(e.tracks,t,n,r,i)}function Gc(e,t,n,r,i){let a=Wc(e,t,n,r,i),o=a?.kind===`track`?e.tracks.find(e=>e.id===a.id):void 0,s=o&&Es(o.points,t,Bc(o.width,n));return o&&s!==void 0?Ki(o,s):void 0}function Kc(e,t,n,r,i=0){let a=r?ks(e,t,Tc(n)):void 0;if(a!==void 0)return{kind:`corner`,index:a};let o=Es(e,t,Bc(i,n));return o===void 0?void 0:{kind:`segment`,index:o}}var qc=(e,t)=>{let n=e.map(e=>e.x),r=e.map(e=>e.y),i=e=>z(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 Jc(e,t){let n=e.tracks.filter(e=>Rc({kind:`track`,layer:e.layer,...Lc(e)},t)),r=e.vias.filter(e=>Rc({kind:`via`,...Lc(e)},t));return[...n.map(e=>({kind:`track`,id:e.id,box:qc(e.points,e.width/2)})),...r.map(e=>({kind:`via`,id:e.id,box:qc([e.at],e.diameter/2)}))]}function Yc(e,t,n,r){let i=new Set(Ni(e,t,n,r));return e.filter(e=>i.has(e.id)).map(({kind:e,id:t})=>({kind:e,id:t}))}var Xc=.4,Zc=.7,Qc=1.5,$c={top:B.topCopper,bottom:B.bottomCopper,inner1:B.topCopper,inner2:B.topCopper},el=e=>e.missingLayer===void 0?$c[e.layer]:B.keepout,tl=e=>e.missingLayer===void 0?B.viaRing:B.keepout,nl=(e,t)=>Rc({kind:`track`,layer:e.layer,...Lc(e)},t),rl=(e,t)=>Rc({kind:`via`,...Lc(e)},t),il=(e,t)=>e&&(t===void 0||!e.nets.includes(t))?Qr:1;function al(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 ol(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 sl(e,t,n,r){let i=t.activeLayer??`top`,a=t.tracks.filter(e=>nl(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:Xc)*il(r,t.net),al(e,t.points,el(t),t.width);e.globalAlpha=1}function cl(e,t,n,r){for(let i of t.vias.filter(e=>rl(e,n)))e.globalAlpha=il(r,i.net),ol(e,i.at,i.diameter/2,tl(i)),n.hole&&ol(e,i.at,i.drill/2,B.drill);e.globalAlpha=1}function ll(e,t,n){for(let{drawing:r,alpha:i}of t.routes??[]){e.globalAlpha=i;for(let t of r.tracks)Rc({kind:`track`,layer:t.layer},n)&&al(e,t.points,$c[t.layer],t.width);if(Rc({kind:`via`},n))for(let t of r.vias)ol(e,t.at,t.diameter/2,B.viaRing),n.hole&&ol(e,t.at,t.drill/2,B.drill)}e.globalAlpha=1}function ul(e,t,n){let{segment:r}=e;return n&&r?.id===t.id&&qi(r,t.points)?[r.from,r.to]:t.points}function dl(e,t,n,r,i,a,o){let s=t.tracks.find(e=>e.id===r);if(s&&nl(s,n)){let n=ul(t,s,a);al(e,n,i,s.width+2*Qc*o),al(e,n,el(s),s.width),a&&al(e,n,B.selectionFill,s.width);return}let c=t.vias.find(e=>e.id===r);c&&rl(c,n)&&(ol(e,c.at,c.diameter/2+Qc*o,i),ol(e,c.at,c.diameter/2,tl(c)),a&&ol(e,c.at,c.diameter/2,B.selectionFill),n.hole&&ol(e,c.at,c.drill/2,B.drill))}function fl(e,t,n,r,i){sl(e,t,n,r),cl(e,t,n,r),ll(e,t,n),t.hover!==void 0&&!t.selected.has(t.hover)&&dl(e,t,n,t.hover,B.hover,!1,i);for(let r of t.selected)dl(e,t,n,r,B.selection,!0,i)}var pl=e=>e.pcb.board?.pours??[];function ml(e,t){return e.outline??t?.outline??[]}function hl(e,t){return e.circuit.nets.find(e=>e.id===t)?.names[0]??t}var gl=(e,t)=>`pour ${hl(e,t.net)} · ${t.layer}`,_l=e=>`${Number(e.toFixed(4))} mm`,vl=e=>`hole ${_l(e.diameter)}`;function yl(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 bl(e){return e.map((t,n)=>[t,e[(n+1)%e.length]])}function xl(e,t,n,r,i){let a=6/n,o;for(let n of pl(e))if(yl(n,r,i))for(let[r,i]of bl(ml(n,e.pcb.board))){let e=ws(t,r,i);e<=a&&(!o||e<o.distance)&&(o={id:n.id,distance:e})}return o?.id}function Sl(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 Cl(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 wl(e,t){let n=!1;for(let[r,i]of bl(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 Tl(e,t){return e.polygons.some(e=>wl(t,e.outer)&&!e.holes.some(e=>wl(t,e)))}function El(e,t,n,r,i){let a=e.pcb.pours.filter(e=>yl(e,n,r));return[...a.filter(e=>e.layer===i),...a.filter(e=>e.layer!==i)].find(e=>Tl(e,t))?.id}function Dl(e,t){let n=e.pcb.holes.find(e=>e.id===t);if(n)return{x:n.x,y:n.y};let r=pl(e).find(e=>e.id===t),i=r?ml(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 Ol=[`solid`,`hatched`,`outline`],kl=`solid`,Al=`copperflow.pourFill`,jl=.35,W=e=>Ol.includes(e);function G(e){try{let t=e()?.getItem(Al);return W(t)?t:kl}catch{return kl}}function Ml(e,t){try{let n=e();return n?(n.setItem(Al,t),!0):!1}catch{return!1}}function Nl(e){return{pourSolid:e===`solid`,pourHatched:e===`hatched`,pourOutline:e===`outline`}}var Pl={pourSolid:`solid`,pourHatched:`hatched`,pourOutline:`outline`},Fl={top:B.topCopper,bottom:B.bottomCopper,inner1:B.inner1Copper,inner2:B.inner2Copper},Il=Fl,Ll=.5,Rl=6,zl=1,Bl=1.5;function Vl(e,t){t.forEach((t,n)=>n===0?e.moveTo(t.x,t.y):e.lineTo(t.x,t.y)),e.closePath()}function Hl(e,t){Gl()&&e instanceof Path2D||e.beginPath();for(let n of t.polygons){Vl(e,n.outer);for(let t of n.holes)Vl(e,t)}}function Ul(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(Ll,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 Wl=new WeakMap,Gl=()=>typeof Path2D==`function`;function Kl(e){let t=Wl.get(e);if(t)return t;let n={};return Wl.set(e,n),n}function ql(e){if(!Gl())return;let t=Kl(e);return t.rings||(t.rings=new Path2D,Hl(t.rings,e)),t.rings}function Jl(e,t){if(!Gl())return;let n=Kl(e);if(n.hatch?.px!==t){let r=new Path2D;for(let[n,i]of Ul(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 Yl(e,t,n){e.lineWidth=n;let r=ql(t);if(r)return e.stroke(r);Hl(e,t),e.stroke()}function Xl(e,t,n){let r=ql(t);if(r)return n===`fill`?e.fill(r,`evenodd`):e.clip(r,`evenodd`);Hl(e,t),n===`fill`?e.fill(`evenodd`):e.clip(`evenodd`)}function Zl(e,t,n){let r=Jl(t,n);if(r)return e.stroke(r);e.beginPath();for(let[r,i]of Ul(t,n))e.moveTo(r.x,r.y),e.lineTo(i.x,i.y);e.stroke()}function Ql(e,t,n,r){let i=Il[t.layer]??B.topCopper;if(e.fillStyle=i,e.strokeStyle=i,n===`outline`)e.globalAlpha=1,Yl(e,t,zl*r);else{if(e.globalAlpha=jl,n===`solid`)return Xl(e,t,`fill`);e.save(),Xl(e,t,`clip`),e.lineWidth=zl*r,e.globalAlpha=1,Zl(e,t,r),e.restore(),e.globalAlpha=1,Yl(e,t,zl*r)}}function $l(e,t,n,r,i){let a=(t.pours??[]).filter(e=>yl(e,r,n.hidden)),o=[...a.filter(e=>e.layer!==n.activeLayer),...a.filter(e=>e.layer===n.activeLayer)];for(let t of o)Ql(e,t,n.mode,i);e.globalAlpha=1}function eu(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 tu(e,t,n,r){if(e.strokeStyle=B.selection,e.lineWidth=Bl*r,e.beginPath(),Vl(e,t),e.stroke(),n){e.fillStyle=B.selection;for(let n of t)eu(e,n,Rl*r),e.fill()}}function nu(e,t,n,r,i,a){if(r.selected.has(t.id))return tu(e,n,t.outline!==void 0,i);let o=r.hover===t.id;(o||t.outline!==void 0)&&(e.strokeStyle=o?B.hover:Il[t.layer]??B.topCopper,e.lineWidth=Math.max(a,zl*i),e.setLineDash([4*i,3*i]),e.beginPath(),Vl(e,n),e.stroke(),e.setLineDash([]))}function ru(e,t,n){t.length<2||(e.strokeStyle=B.selection,e.lineWidth=zl*n,e.setLineDash([4*n,3*n]),e.beginPath(),Vl(e,t),e.stroke(),e.setLineDash([]))}function iu(e,t,n,r,i,a){for(let o of t.board?.pours??[])yl(o,r,n.hidden)&&nu(e,o,n.outlines?.get(o.id)??ml(o,t.board),n,i,a);n.preview&&ru(e,n.preview,i)}function au(e,t,n,r,i,a){if(r.hole)for(let r of t){let t=r.diameter/2;e.fillStyle=B.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?B.selection:n.hover===r.id?B.hover:B.multiLayer,e.lineWidth=o?Bl*i:a,e.stroke()}}var K=(e,t=!1)=>({action:e,preventDefault:t}),ou=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 su(e){for(let t of ou.values())if(t.action===e)return{dx:t.dx,dy:t.dy}}function cu(e){let t=ou.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 lu=`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']`,uu=`input:not([type='checkbox']):not([type='radio']), textarea, select, [contenteditable='true']`,du=`button, a[href], summary, input[type='checkbox'], input[type='radio']`,fu=`[data-keys='parts']`;function pu(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(uu)!=null,onButton:t?.closest(du)!=null,ownsKeys:t?.closest(lu)!=null,partRows:t?.closest(fu)!=null,handled:e.defaultPrevented}}var mu=e=>e.code?.startsWith(`Key`)?e.code.slice(3).toLowerCase():e.key.toLowerCase(),hu=new Map([[`w`,`wire`],[`n`,`armNetLabel`],[`b`,`drawBus`],[`l`,`drawPolyline`],[`r`,`drawRectangle`],[`c`,`drawCircle`],[`a`,`drawArc`],[`t`,`drawText`],[`j`,`junction`]]),gu=new Map([[`w`,`route`],[`v`,`placeVia`]]);function _u(e,t){if(e.shiftKey)return null;let n=mu(e);if(n===`s`)return K(`toggleSnap`,!0);let r=(t.view===`schematic`?hu:gu).get(n);return r?K(r,!0):null}function vu(e,t,n){switch(e){case`w`:return K(n.view===`schematic`?`wire`:`route`);case`v`:return n.view===`pcb`?K(`switchLayer`,!0):null;case`r`:return K(`rotate`);case`k`:return K(`fit`);case`f`:return t.shiftKey?K(`openLibrary`,!0):K(`fit`);case`h`:return t.shiftKey?K(`clearHighlight`):K(`highlight`);case`q`:return n.view===`pcb`?K(`toggleUnit`):null;case`u`:return n.view===`pcb`?K(t.shiftKey?`straightenTracks`:`filletTracks`,!0):null;case`l`:return n.view===`pcb`&&!t.shiftKey?K(`routingCorner`,!0):null;case`x`:return n.view===`pcb`&&!t.shiftKey?K(`flip`,!0):null;default:return null}}var yu=new Map([[`[`,`toggleLeftPanel`],[`]`,`toggleRightPanel`],[`\\`,`toggleBottomPanel`]]),bu=e=>!e.metaKey&&(e.altGraph===!0||e.ctrlKey&&e.altKey||!e.ctrlKey&&!e.altKey),xu=new Map([[`z`,`undo`],[`y`,`redo`],[`o`,`openFile`],[`a`,`selectAll`],[`f`,`find`],[`c`,`copy`],[`v`,`paste`]]),Su=new Map([[`z`,`redo`],[`l`,`alignLeft`],[`h`,`distributeH`],[`f`,`findSimilar`],[`x`,`placementTransfer`]]);function Cu(e){if(e.altKey||e.altGraph)return null;let t=(e.shiftKey?Su:xu).get(e.key.toLowerCase());return t?K(t,t!==`copy`):null}function wu(e,t){return t.drawing?e.key===`Backspace`&&!e.ownsKeys?K(`removeCorner`,!0):null:K(`delete`)}var Tu=e=>e.key===`Delete`||e.key===`Backspace`,Eu=e=>e.ownsKeys===!0&&!(e.partRows===!0&&Tu(e)),Du=e=>e.key===`ContextMenu`||e.key===`F10`&&e.shiftKey&&!e.ctrlKey&&!e.altKey&&!e.metaKey;function Ou(e,t){if(e.typing)return null;if(Du(e))return K(`contextMenu`,!0);let n=yu.get(e.key);return n&&bu(e)?K(n):e.ctrlKey||e.metaKey?Cu(e):e.altKey?_u(e,t):e.handled||Eu(e)?null:cu(e)||(e.key===`Enter`?t.drawing&&!e.onButton&&!e.shiftKey?K(`finishShape`,!0):null:Tu(e)?wu(e,t):e.key===` `?e.onButton?null:K(t.drawing?`flipBend`:`rotate`,!0):vu(e.key.toLowerCase(),e,t))}function ku(e){return e.key===`Escape`&&!e.typing}var Au=e=>xt(e)+0,ju=e=>Math.round((e%360+360)%360/90)%4;function Mu(e,t){switch(ju(t)){case 1:return{x:Au(-e.y),y:Au(e.x)};case 2:return{x:Au(-e.x),y:Au(-e.y)};case 3:return{x:Au(e.y),y:Au(-e.x)};default:return{x:Au(e.x),y:Au(e.y)}}}function Nu(e,t){let n=Mu(e,t.rotation);return{x:Au(t.x+n.x),y:Au(t.y+n.y)}}var Pu={reference:`schNameAt`,value:`schValueAt`},Fu=(e,t)=>`${e}:${t}`;function q(e){let t=e.lastIndexOf(`:`);return t>0?{part:e.slice(0,t),prop:e.slice(t+1)}:void 0}function Iu(e,t,n){let r=bt*t*n/2;return{minX:e.x-r,maxX:e.x+r,minY:e.y-t/2,maxY:e.y+t/2}}function Lu(e){return e.symbol.shapes.flatMap(t=>{if(t.type!==`text`||t.role!==`reference`&&t.role!==`value`)return[];let n=Nu(t.at,e),r=Pu[t.role],i={x:Au(n.x-e.x),y:Au(n.y-e.y)};return[{id:Fu(e.component,r),part:e.component,prop:r,text:t.text,at:n,offset:i,box:Iu(n,t.size,t.text.length)}]})}var Ru=.8,zu={schematic:[`schNameAt`,`schValueAt`],pcb:[`pcbNameAt`]},Bu={schNameAt:`Name`,schValueAt:`Value`,pcbNameAt:`Designator`};function Vu(e){let t=q(e)?.prop;if(t!==void 0)return zu.schematic.includes(t)?`schematic`:zu.pcb.includes(t)?`pcb`:void 0}function Hu(e){return e.symbols.flatMap(e=>Lu(e))}function Uu(e){let t=Xr(e),n={x:t.x-e.x,y:t.y-e.y};return{id:Fu(e.component,`pcbNameAt`),part:e.component,prop:`pcbNameAt`,text:e.component,at:t,offset:n,box:Iu(t,Ru,e.component.length)}}function Wu(e){return e.parts.map(Uu)}function Gu(e,t){return e===`pcb`?Wu(t.pcb):Hu(t.schematic)}var Ku=(e,t)=>t.x>=e.minX&&t.x<=e.maxX&&t.y>=e.minY&&t.y<=e.maxY,qu=e=>(e.maxX-e.minX)*(e.maxY-e.minY);function Ju(e,t){return e.filter(e=>Ku(e.box,t)).sort((e,t)=>qu(e.box)-qu(t.box))[0]}function Yu(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 Xu(e,t){return t.length===0?[...e]:e.map(e=>{let n=t.find(t=>t.id===e.id);return n?Yu(e,n.at):e})}function Zu(e,t){let n={x:e.at.x-e.offset.x,y:e.at.y-e.offset.y},r={x:z(t.x-n.x),y:z(t.y-n.y)};return z(e.offset.x)===r.x&&z(e.offset.y)===r.y?[]:[{kind:`setProps`,part:e.part,props:{[e.prop]:r}}]}function Qu(e){let t=q(e);return t?[{kind:`setProps`,part:t.part,props:{[t.prop]:null}}]:[]}function $u(e,t){let n=q(t);return n!==void 0&&e.model.parts.find(e=>e.name===n.part)?.props[n.prop]!==void 0}function ed(e,t,n){let r=q(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 td(e,t,n,r){let i=od(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 nd(e,t,n){let r=t===`schNameAt`?`reference`:t===`schValueAt`?`value`:void 0,i=Mu({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 rd(e,t){if(t.length===0)return e;let n=e.symbols.map(e=>t.reduce((t,n)=>{let r=q(n.id);return r?.part===e.component?nd(t,r.prop,n.at):t},e));return{...e,symbols:n}}function id(e,t){if(t.length===0)return e;let n=e.parts.map(e=>{let n=t.find(t=>t.id===Fu(e.component,`pcbNameAt`));return n?{...e,nameAt:n.at}:e});return{...e,parts:n}}var ad=e=>String(z(e));function od(e,t,n,r){let i=Vu(n),a=i&&Gu(i,e).find(e=>e.id===n);if(!i||!a)return;let o=$u(t,n),s=i===`pcb`?` mm`:``,c=[{label:`Part`,value:a.part},{label:`Text`,value:a.text},{label:`Offset X`,value:`${ad(a.offset.x)}${s}`},{label:`Offset Y`,value:`${ad(a.offset.y)}${s}`},{label:`Position`,value:o?`Moved (${a.prop})`:`Where the layout puts it`}];return{title:Bu[a.prop]??a.prop,rows:c,moved:o,blocker:ed(t,r,n)}}function sd(e,t,n){let r=e.soleText,i=su(t.action);if(r!==void 0&&i)return{id:r,by:ot(i,n.step,t.steps??1,n.snap!==!1)}}var cd={mode:`solid`,hidden:new Set,selected:new Set,activeLayer:`top`},ld={x:0,y:0},ud=1.5,J=.35,dd=1.5,fd=.6,pd=.12,md=1.5,hd=.7,gd=.5,_d=1e-9,vd=.25,yd=.6,bd=e=>e*Math.PI/180,xd=(e,t,n)=>e[`${t.side===`top`?`top`:`bottom`}${n}`],Sd=e=>e.autoPlaced?yd:1,Cd=e=>e.side===`top`?B.topAssembly:B.bottomAssembly;function wd(e,t,n,r){let i={...li,...r.layers},{camera:a,size:o}=n,s=1/a.scale,c=ka(s,r.ratio),l=e=>r.moving?.components.includes(e.component)?r.moving.by:ld,u=n=>{for(let r of t.parts)Od(e,l(r).x,l(r).y,0,()=>{e.globalAlpha=Sd(r),n(r)});e.globalAlpha=1};e.save(),e.setTransform(...Ed(n,r.ratio)),e.lineCap=`round`,e.lineJoin=`round`,i.keepout&&Pd(e,t,s,c);let d=r.pours??cd;$l(e,t,d,i,s),Rd(e,i,r.highlight,u,s),r.copper&&fl(e,r.copper,i,r.highlight,s),i.hole&&Bd(e,u),au(e,t.holes??[],d,i,s,c),iu(e,t,d,i,s,c),u(t=>{xd(i,t,`Silk`)&&Vd(e,t.silkscreen,t.side===`top`?B.topSilk:B.bottomSilk,Math.max(pd,c),!1)}),i.courtyard&&Hd(e,u,s,c),u(t=>{xd(i,t,`Assembly`)&&Vd(e,t.fabrication,Cd(t),c,!1)}),i.boardOutline&&Nd(e,t,()=>{e.strokeStyle=B.boardEdge,e.lineWidth=md*s,e.stroke()}),r.ratsnest!==!1&&i.ratline&&Ud(e,t,r,c),e.setTransform(r.ratio,0,0,r.ratio,0,0),Ba(e);for(let n of t.parts)xd(i,n,`Silk`)&&Gd(e,n,a,o,l(n),r.ratio);oa(e,n,r.violations??[],r.activeViolation,!0),e.restore()}function Y(e,t,n,r){for(let i of e.parts){if(r&&!r(i.component))continue;let e=i.pads.find(e=>(!n||n[pi(e)])&&qd(e,t));if(e)return e}}function Td(e){return e.parts.map(e=>{let t=Dd(e);return{name:e.component,pcbComponentId:e.component,center:{x:(t.minX+t.maxX)/2,y:(t.minY+t.maxY)/2},box:t}})}function Ed({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 Dd(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 Od(e,t,n,r,i){e.save(),e.translate(t,n),r&&e.rotate(bd(r)),i(),e.restore()}function kd(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 Ad(e,t,n,r){e.beginPath(),e.arc(t,n,Math.max(r,0),0,Math.PI*2)}function jd(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 Md=(e,t,n)=>jd(e,t,n,Math.min(t,n)/2);function Nd(e,t,n){let r=t.board?.outline;!r||r.length<3||(kd(e,r),n())}function Pd(e,t,n,r){let i=t.board?.keepouts??[];if(i.length!==0){e.strokeStyle=B.keepout,e.globalAlpha=hd;for(let t of i){e.lineWidth=r,e.setLineDash([4*n,3*n]),kd(e,t.outline),e.stroke(),e.setLineDash([]),e.save(),kd(e,t.outline),e.clip();for(let[n,r]of Fd(t.outline))Wd(e,n,r);e.restore()}e.globalAlpha=1}}function Fd(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(gd,l/399),d=Math.floor(l/u+_d)+1;return Array.from({length:d},(e,t)=>{let n=c+t*u;return[{x:n,y:a},{x:n+s,y:o}]})}function Id(e,t){Od(e,t.x,t.y,t.rotation,()=>{t.shape===`circle`?Ad(e,0,0,t.width/2):t.shape===`oval`?Md(e,t.width,t.height):jd(e,t.width,t.height,t.shape===`roundrect`?t.cornerRadius??vd*Math.min(t.width,t.height):0)})}function Ld(e){return e.layers===`through`?B.multiLayer:e.layers===`bottom`?B.bottomCopper:B.topCopper}function Rd(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?Qr:1)*Sd(t),e.fillStyle=Ld(r),Id(e,r),e.fill(),a&&zd(e,r,i,Sd(t))}});e.globalAlpha=1}function zd(e,t,n,r){e.globalAlpha=J*r,e.fillStyle=B.highlight,Id(e,t),e.fill(),e.globalAlpha=r,e.strokeStyle=B.highlight,e.lineWidth=dd*n,e.stroke()}function Bd(e,t){e.fillStyle=B.drill,t(t=>{for(let n of t.pads){let{drill:t}=n;t&&(t.width===t.height?Ad(e,n.x,n.y,t.width/2):Od(e,n.x,n.y,n.rotation,()=>Md(e,t.width,t.height)),e.fill())}})}function Vd(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 Hd(e,t,n,r){e.setLineDash([4*n,3*n]),t(t=>{e.globalAlpha=1,Vd(e,[t.courtyard],Cd(t),t.autoPlaced?ud*n:r,!0)}),e.setLineDash([])}function Ud(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?B.highlight:B.ratsnest,e.globalAlpha=t?1:n.highlight?fd*Qr:fd,Wd(e,o(r.a,r.from),o(r.b,r.to))}e.globalAlpha=1}function Wd(e,t,n){e.beginPath(),e.moveTo(t.x,t.y),e.lineTo(n.x,n.y),e.stroke()}function Gd(e,t,n,r,i,a){let o=Ia(Ru,n.scale,a);if(!Fa(`name`,o,o))return;let s=Xr(t),c=za(fe(n,r,{x:s.x+i.x,y:s.y+i.y}),a);e.fillStyle=t.side===`top`?B.topSilk:B.bottomSilk,e.globalAlpha=Sd(t),e.font=ni(ti.strong,o/a),e.textAlign=`center`,e.textBaseline=`middle`,e.fillText(t.component,c.x,c.y),e.globalAlpha=1}function Kd(e,t,n,r){let i;for(let a of e.parts)for(let e of a.pads){if(r&&!r[pi(e)])continue;let a=Yd(e,t);a<=n&&(!i||a<i.distance)&&(i={pad:e,distance:a})}return i?.pad}var qd=(e,t)=>Yd(e,t)<=0;function Jd(e,t){let n=bd(-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 Yd(e,t){let{x:n,y:r}=Jd(e,t);return e.shape===`circle`?Math.max(0,Math.hypot(n,r)-e.width/2):e.shape===`oval`?Xd(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 Xd(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 Zd(e,t,n){let r=Ds(e.schematic.wires,t,n);return e.schematic.wires.find(e=>e.id===r)?.net}function Qd(e,t,n){let r=Hn(e,t,n);if(r)return e.circuit.nets.find(e=>e.pins.includes(r.pin))?.id;let i=wr(e,t)?.net??Zd(e,t,n);return i===void 0?void 0:$d(e.circuit.nets,i)}function $d(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 ef=[];function tf(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 nf(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 rf(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:`${et(e)} ${e.length===1?`is`:`are`} on no net.`}}function af(e,t,n,r=()=>void 0){let i=[...new Set([...e.wires.flatMap(e=>t(e)??[]),...e.labels.flatMap(e=>r(e)??[])])],a=rf(e.names,n);return`nets`in a?{nets:[...new Set([...i,...a.nets])]}:i.length>0?{nets:i}:a}function of(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 sf(e,t,n){let r=[...new Set(e.flatMap(e=>of(e,t,n)??[]))];return r.length===e.length&&r.every((t,n)=>t===e[n])?e:r.length===0?ef:r}function cf(e,t,n){return Y(e,t,n)?.net??void 0}var lf=e=>e.startsWith(`drawing:`)||e.includes(`~`),uf=e=>JSON.stringify({...e,source:void 0}),df=(e,t)=>e.filter(e=>e.kind===t).length,ff=(e,t)=>t.some(t=>t.id.startsWith(`${e}~`));function pf(e,t,n,r){return!lf(t.id)&&!ff(t.id,n)&&!ff(t.id,r)?!0:e.kind===t.kind?df(n,t.kind)===df(r,t.kind)||uf(e)===uf(t):!1}function mf(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||pf(i,r,e,t)?[r.id]:[]})}function hf(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 gf(e,t,n){return e.drawingCount===0?e:e.keepDrawings(mf(t,n))}var _f=/^[ADPF]?GND\w*$|^VSS\w*$/i,vf=/^(VCC|VDD|VBUS|VIN|V\d|\+)/i,yf=new Intl.Collator(`en`,{numeric:!0});function bf(e){return _f.test(e)?`ground`:vf.test(e)?`power`:void 0}function xf(e){for(let t of e){let e=bf(t);if(e)return e}}var Sf=e=>e.find(e=>bf(e))??e[0];function Cf(e){return Sf(e.names)??`(unnamed) ${e.pins[0]??e.id}`}function wf(e){return e.circuit.nets.map(e=>{let t=Sf(e.names),n=xf(e.names);return{id:e.id,label:Cf(e),pins:e.pins.length,named:t!==void 0,...n?{badge:n}:{}}}).sort((e,t)=>Number(t.named)-Number(e.named)||yf.compare(e.label,t.label))}function Tf(e,t,n,r){let i=new Map,a=[],o=[];for(let s of t){let t=Dr(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 Ef=(e,t)=>e.schematic.labels.find(e=>e.id===t);function Df(e,t){let n=e?kr(e):`the label`;return`${n.charAt(0).toUpperCase()}${n.slice(1)}: ${t}`}function Of(e,t,n,r,i,a){let o=Ef(e,n),s={edits:[],shown:[],names:[],notes:[]};if(!o)return s;let c={x:z(o.at.x+r.x),y:z(o.at.y+r.y)},l=Br(e,t,n,c,i);if(!Array.isArray(l))return a.includes(l.blocked)?s:{...s,notes:[Df(o,l.blocked)]};let u=l.length>0?Fr(e,n,c):void 0;return u?{edits:l,shown:[{id:n,...u}],names:[kr(o)],notes:[]}:s}function kf(e,t,n,r,i,a){let o=n.map(n=>Of(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 Af(e,t){return t.flatMap(t=>{let n=Ef(e,t);return n?[kr(n)]:[]})}var jf=e=>e.length>1?[`${e.length} labels`]:[...e];function Mf(e,t,n,r){if(r.has(e))return e;let i=t&&Or(t,e);return i===void 0?void 0:n.schematic.labels.find(e=>Or(n,e.id)===i)?.id}function Nf(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=>Mf(e,t,n,r)??[]);return e.all(e.names,e.wires,i,e.drawings)}var Pf=(e,t)=>e.slice(`label:${t}:`.length);function Ff(e,t,n){let r=e.schematic.labels.find(e=>e.id===t),i=Dr(e,t);return i?.wire===void 0?i&&n.has(i.part)?{kind:`part`,label:t}:r?{kind:`skipped`,reason:Df(r,`Studio places it on ${Pf(t,r.net)} for its net; delete that pin's part or wire instead`)}:{kind:`gone`}:{kind:`wire`,label:t,wire:i.wire}}function If(e,t,n){let r=t.map(t=>Ff(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 Lf(e,t){let n=e.schematic.labels.find(e=>e.id===t);if(!n)return;let r=$d(e.circuit.nets,n.net),i=e.circuit.nets.find(e=>e.id===r),a=Dr(e,t)?.wire===void 0?`At a pin`:`Hand-drawn`;return{net:r,rows:[{label:`Net`,value:i?Cf(i):r.replace(/^net\./,``)},{label:`Text`,value:n.text},{label:`Kind`,value:a}]}}var Rf=e=>`${e.x},${e.y}`;function zf(e){let t=new Map(e.symbols.flatMap(e=>Object.entries(e.pinEnds).map(([e,t])=>[Rf(t),e])));return e.wires.map(e=>{let[n,r]=[e.points[0],e.points[e.points.length-1]],i=n&&r?[t.get(Rf(n)),t.get(Rf(r))]:[],a=i.length===2&&i.every(e=>e!==void 0);return e.connection===void 0&&a?{...e,ends:i}:e})}var Bf=(e,t)=>e.x===t.x&&e.y===t.y;function Vf(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:Bf(n,i)&&Bf(r,a)||Bf(n,a)&&Bf(r,i)}function Hf(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&&!Vf(i,r)}function Uf(e,t,n){return e.withoutWires(e.wires.filter(e=>Hf(e,t,n)))}function Wf(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 Gf=[{id:`library`,label:`Library`},{id:`log`,label:`Log`},{id:`drc`,label:`DRC`},{id:`find`,label:`Find Results`}],Kf=`bottom-panel`,qf=e=>`bottom-tab-${e}`,Jf={open:!1,tab:`drc`};function Yf(e,t){return e.open&&e.tab===t?{...e,open:!1}:{open:!0,tab:t}}function Xf(e){return{...e,open:!e.open}}function Zf(e,t){return{open:!0,tab:t}}function Qf(e){return e.detail>0}var $f=`button, input[type='checkbox']`;function ep(e){e.target instanceof HTMLElement&&e.target.closest($f)?.blur()}function tp(e,t,n){return t>0||e===`checkbox`&&!n}function np(e,t,n){return e===null||e===t||(n?.contains(e)??!1)}function rp(e){let t=e.target instanceof HTMLElement?e.target.closest($f):null;t&&tp(t instanceof HTMLInputElement?`checkbox`:`button`,e.detail,t.matches(`:focus-visible`))&&t.blur()}var ip=new Set([`ArrowLeft`,`ArrowUp`]),ap=new Set([`ArrowRight`,`ArrowDown`]);function op(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=ip.has(n)?-1:+!!ap.has(n);return r===0?null:e[(Math.max(0,e.indexOf(t))+r+e.length)%e.length]??null}function sp({ids:e,current:t,onSelect:n,onPointerClick:r}){return{onKeyDown:r=>{let i=op(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(!Qf(t))return n(e);ep(t),(r??n)(e)}})}}var cp=e((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})),lp=e(((e,t)=>{t.exports=cp()})),X=lp(),up=Gf.map(e=>e.id);function dp({state:e,onClick:t,onOpen:n}){let r=sp({ids:up,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:Gf.map(t=>{let n=e.open&&e.tab===t.id;return(0,X.jsx)(`button`,{role:`tab`,id:qf(t.id),"aria-controls":Kf,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 fp(e){return{"--dpr":String(Number.isFinite(e)&&e>0?e:1)}}function pp(e){let t=e.document.documentElement,n,r=()=>{for(let[n,r]of Object.entries(fp(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},mp=(e,t,n,r)=>r?{tag:`circle`,cx:e,cy:t,r:n,fill:r}:{tag:`circle`,cx:e,cy:t,r:n},hp=(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},gp=Z(`M2.5 5.5v-3h3M10.5 2.5h3v3M13.5 10.5v3h-3M5.5 13.5h-3v-3`),_p=[hp(3,7,10,7,1.5),Z(`M8 10v1.5`)],vp=[4,8,12].flatMap(e=>[4,8,12].map(t=>mp(t,e,1,!0))),yp={lock:[..._p,Z(`M5.5 7V5a2.5 2.5 0 0 1 5 0v2`)],unlock:[..._p,Z(`M5.5 7V5a2.5 2.5 0 0 1 5 0`)],padlock:[hp(2.5,7,11,7.5,1.5),Z(`M5 7V5a3 3 0 0 1 6 0v2`),Z(`M8 10v2`)],padlockOpen:[hp(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`),mp(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`),mp(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:[mp(7,7,4.5),Z(`M10.5 10.5 14 14M7 5v4M5 7h4`)],zoomOut:[mp(7,7,4.5),Z(`M10.5 10.5 14 14M5 7h4`)],fit:[gp,hp(6,6,4,4,.5)],fitSelection:[gp,hp(5.5,5.5,5,5,1,!0)],fitArea:[hp(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:vp,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:[hp(4.5,3,7,10,1),Z(`M2 6h2.5M2 10h2.5M11.5 6H14M11.5 10H14`)],wire:[mp(3.5,12.5,1.5),mp(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:[mp(8,8,5.5)],rectangle:[hp(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:[mp(8,8,5.5),mp(8,8,2)],boardOutline:[Z(`M2.5 3.5h8l3 3v6h-11z`)],copperArea:[hp(2.5,2.5,11,11,1),Z(`M5.5 10.5l5-5M5.5 7.5l2-2M8.5 10.5l2-2`)],singleRouting:[mp(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`),hp(5,3.5,8.5,3.5,1),hp(5,9,5,3.5,1)],distributeH:[Z(`M2.5 2v12M13.5 2v12`),hp(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`)]},bp={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 xp(e,t){let{tag:n,fill:r,dash:i,...a}=e;return{key:t,...a,...r?{fill:`currentColor`,stroke:`none`}:{},...i?{strokeDasharray:i}:{}}}function Sp(e,t={}){let n=yp[e];return(0,l.createElement)(`svg`,{...bp,...t},...n.map((e,t)=>(0,l.createElement)(e.tag,xp(e,t))))}var Cp=e=>Sp(`lock`,e),wp=e=>Sp(`unlock`,e),Tp=e=>Sp(`padlock`,e),Ep=e=>Sp(`padlockOpen`,e),Dp=e=>Sp(`rotate`,e),Op=e=>Sp(`trash`,e),kp=e=>Sp(`undo`,e),Ap=e=>Sp(`close`,e),jp=e=>Sp(`chevron`,e),Mp=({off:e,...t})=>Sp(e?`eyeOff`:`eye`,t),Q=e=>t=>Sp(e,t),Np={undo:Q(`undo`),redo:Q(`redo`),zoomIn:Q(`zoomIn`),zoomOut:Q(`zoomOut`),fit:Q(`fit`),fitSelection:Q(`fitSelection`),fitArea:Q(`fitArea`),component:Q(`component`),wire:Q(`wire`),netLabel:Q(`netLabel`),ground:Q(`ground`),power:Q(`power`),rotate:Q(`rotate`),rotateRight:Q(`rotateRight`),snap:Q(`snap`),check:Q(`check`),grid:Q(`grid`),alignLeft:Q(`alignLeft`),distributeH:Q(`distributeH`),polyline:Q(`polyline`),arc:Q(`arc`),circle:Q(`circle`),rectangle:Q(`rectangle`),text:Q(`text`),bus:Q(`bus`),noConnect:Q(`noConnect`),via:Q(`via`),boardOutline:Q(`boardOutline`),copperArea:Q(`copperArea`),singleRouting:Q(`singleRouting`),gerber:Q(`gerber`)};function Pp(e){return e===`Escape`?`close`:e===`Tab`?`trap`:`hold`}function Fp(e,t,n){return t<=0?-1:e<0||e>=t?n?t-1:0:(e+(n?-1:1)+t)%t}function Ip(){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 Lp=Ip();function Rp(e){let t=e=>void Lp.dispatch(e);return e.addEventListener(`keydown`,t,!0),()=>e.removeEventListener(`keydown`,t,!0)}function zp(e,t){let n=(0,l.useRef)(t);(0,l.useLayoutEffect)(()=>{n.current=t}),(0,l.useEffect)(()=>e?Lp.hold(e=>n.current(e)):void 0,[e])}var Bp=[`fitSelection`,`rotateRight`,`selectInstance`,`replicateLayout`,`makeSheet`,`autorouteSelection`,`autoplaceSelection`,`autoplaceInstance`],Vp=`Select a part first`,Hp=e=>Bp.includes(e);function Up(e,t){return v(e)?b(e,t):Hp(e)&&t<1?Vp:null}var Wp=`Comes with hand routing (engine stage 4)`,$=(e,t,n)=>n?{label:e,command:t,shortcut:n}:{label:e,command:t},Gp=[{title:`File`,entries:[$(`Open circuit file`,`openFile`,`Ctrl+O`),$(`New circuit…`,`newCircuit`),`separator`,$(`Export BOM`,`exportBom`),$(`Export package`,`exportPackage`),$(`Export Gerber`,`exportFabrication`),$(`Print…`,`print`)]},{title:`Edit`,entries:[$(`Undo`,`undo`,`Ctrl+Z`),$(`Redo`,`redo`,`Ctrl+Y`),`separator`,$(`Copy`,`copy`,`Ctrl+C`),$(`Paste`,`paste`,`Ctrl+V`),$(`Delete`,`delete`,`Delete`),`separator`,$(`Select all`,`selectAll`,`Ctrl+A`),$(`Select the instance`,`selectInstance`),{label:`Make sub-sheet…`,command:`makeSheet`,only:`schematic`},$(`Find`,`find`,`Ctrl+F`),$(`Find similar objects`,`findSimilar`,`Ctrl+Shift+F`),`separator`,$(`Fillet tracks`,`filletTracks`,`U`),$(`Straighten tracks`,`straightenTracks`,`Shift+U`)]},{title:`View`,entries:[$(`Fit all`,`fit`,`K`),$(`Fit selection`,`fitSelection`),$(`Fit area`,`fitArea`),$(`Zoom in`,`zoomIn`),$(`Zoom out`,`zoomOut`),`separator`,{...$(`Unit`,`toggleUnit`,`Q`),only:`pcb`},$(`Grid style`,`gridStyle`),{...$(`Snap`,`snap`,`Alt+S`),toggle:`snap`},{...$(`Hover labels`,`hoverLabels`),toggle:`hoverLabels`},{...$(`Pour fill: Solid`,`pourSolid`),toggle:`pourSolid`},{...$(`Pour fill: Hatched`,`pourHatched`),toggle:`pourHatched`},{...$(`Pour fill: Outline only`,`pourOutline`),toggle:`pourOutline`},`separator`,$(`Left panel`,`toggleLeftPanel`,`[`),$(`Right panel`,`toggleRightPanel`,`]`),$(`Bottom panel`,`toggleBottomPanel`,`\\`),`separator`,{...$(`Theme: Light`,`themeLight`),toggle:`themeLight`},{...$(`Theme: Dark`,`themeDark`),toggle:`themeDark`}]},{title:`Place`,entries:[$(`Component`,`placeComponent`,`Shift+F`),$(`Wire`,`wire`,`Alt+W`),$(`Net label`,`netLabel`,`Alt+N`),$(`Ground flag`,`groundFlag`),$(`Power flag`,`powerFlag`),`separator`,$(`Note box`,`noteBox`),`separator`,$(`Bus`,`drawBus`,`Alt+B`),{label:`No connect flag`,command:`noConnect`,only:`schematic`},{label:`Junction`,command:`junction`,shortcut:`Alt+J`,only:`schematic`},`separator`,$(`Copper pour`,`placePour`),$(`Copper pour: Whole board`,`placePourBoard`),$(`Hole`,`placeHole`),`separator`,{label:`Autoplace`,command:`autoplace`,only:`pcb`},{label:`Autoplace selection`,command:`autoplaceSelection`,only:`pcb`},{label:`Autoplace instance`,command:`autoplaceInstance`,only:`pcb`},`separator`,$(`Polyline`,`drawPolyline`,`Alt+L`),$(`Arc`,`drawArc`,`Alt+A`),$(`Circle`,`drawCircle`,`Alt+C`),$(`Rectangle`,`drawRectangle`,`Alt+R`),$(`Text`,`drawText`,`Alt+T`)]},{title:`Design`,entries:[$(`Check DRC`,`checkDrc`),$(`Design rules`,`designRules`),`separator`,$(`Highlight net`,`highlight`,`H`),$(`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`},$(`Annotate designators`,`annotate`),{label:`Placement transfer`,command:`placementTransfer`,shortcut:`Ctrl+Shift+X`,only:`pcb`}]},{title:`Route`,entries:[$(`Single routing`,`singleRouting`,`Alt+W`),$(`Via`,`placeVia`,`Alt+V`),{label:`Routing corner`,command:`routingCorner`,shortcut:`L`,only:`pcb`},`separator`,$(`Autoroute`,`autoroute`),$(`Autoroute selection`,`autorouteSelection`),$(`Autoroute net`,`autorouteNet`),$(`Unroute`,`unroute`)]},{title:`Layout`,entries:[$(`Rotate`,`rotate`,`Space`),$(`Rotate right`,`rotateRight`),{label:`Flip`,command:`flip`,shortcut:`X`,only:`pcb`},`separator`,$(`Lock`,`lock`),$(`Unlock`,`unlock`),`separator`,$(`Align left`,`alignLeft`,`Ctrl+Shift+L`),$(`Align right`,`alignRight`),$(`Align top`,`alignTop`),$(`Align bottom`,`alignBottom`),$(`Align horizontal centres`,`alignHCentres`),$(`Align vertical centres`,`alignVCentres`),`separator`,$(`Distribute horizontally`,`distributeH`,`Ctrl+Shift+H`),$(`Distribute vertically`,`distributeV`),`separator`,{label:`Fit board`,command:`fitBoard`,only:`pcb`},`separator`,{label:`Tidy sheet`,command:`tidySheet`,only:`schematic`}]},{title:`Tools`,entries:[$(`History`,`history`),$(`Footprint manager…`,`footprintManager`)]},{title:`Export`,entries:[$(`BOM`,`exportBom`),$(`Package`,`exportPackage`),$(`Fabrication files (JLCPCB)`,`exportFabrication`),$(`Gerber`,`exportFabrication`),$(`Pick and place (CPL)`,`exportFabrication`),$(`PDF…`,`exportPdf`)]},{title:`Settings`,entries:[$(`System…`,`systemSettings`),$(`Hotkeys`,`keys`)]},{title:`Help`,entries:[$(`Keys`,`keys`),$(`About`,`about`)]}];Gp.map(e=>e.title);var Kp={pcb:`PCB only`,schematic:`Schematic only`};function qp(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:Kp[e.only]};let i=r[e.command];if(i!==void 0)return{enabled:!1,reason:i};let a=n===void 0?null:Up(e.command,n);return a?{enabled:!1,reason:a}:{enabled:!0}}function Jp(e){return e.entries.filter(e=>e!==`separator`)}var Yp=[{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 Xp(){let e=new Set,t=[];for(let n of Gp.flatMap(Jp))n.command&&n.shortcut&&!e.has(n.shortcut)&&(e.add(n.shortcut),t.push({keys:n.shortcut,label:n.label}));return[...t,...Yp.filter(t=>!e.has(t.keys))]}function Zp(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 Qp(e,t,n={}){return Gp.map(r=>r.entries.map(r=>r===`separator`?`separator`:qp(r,e,t,n).enabled?`item`:`disabled`))}var $p=`Type the LCSC part number, e.g. C7950. The part is fetched from EasyEDA, so this needs the internet.`;function em(e,t,n){let r=e.trim().toUpperCase();if(r===``)return{message:$p};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 tm(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 nm(e){return`Not verified: check every pin and pad in parts/${e.id}/verification.md against the datasheet before verifying it.`}function rm(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 im({result:e}){return(0,X.jsxs)(`div`,{className:`import-result`,role:`status`,children:[(0,X.jsx)(`p`,{children:(0,X.jsx)(`strong`,{children:tm(e)})}),(0,X.jsx)(`p`,{children:nm(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 am({panel:e,onClose:t}){let[n,r]=(0,l.useState)(``),[i,a]=(0,l.useState)(``),[o,s]=(0,l.useState)(!1),[c,u]=(0,l.useState)(!1),[d,f]=(0,l.useState)(),[p,m]=(0,l.useState)(),h=(0,l.useId)(),g=async r=>{if(r.preventDefault(),c)return;if(p)return t();let a=em(n,i,o);if(`message`in a)return f(a.message);u(!0),f(void 0);try{m(await e.import(a))}catch(e){f(e.message)}finally{u(!1)}};return(0,X.jsxs)(`form`,{className:`rules-form import-part-form`,onSubmit:e=>void g(e),children:[(0,X.jsx)(`label`,{htmlFor:h,children:`LCSC part number`}),(0,X.jsx)(`input`,{id:h,value:n,placeholder:`C7950`,disabled:c||p!==void 0,onChange:e=>r(e.target.value),"aria-describedby":`${h}-note`,"aria-invalid":d!==void 0}),(0,X.jsx)(`label`,{htmlFor:`${h}-id`,children:`Part id`}),(0,X.jsx)(`input`,{id:`${h}-id`,value:i,placeholder:`the MPN`,disabled:c||p!==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||p!==void 0,onChange:e=>s(e.target.checked)}),`Replace a part with this id that is not verified`]}),(0,X.jsx)(`p`,{id:`${h}-note`,role:d?`alert`:void 0,children:c?`Fetching from EasyEDA…`:d??(p?``:`Type the LCSC part number, e.g. C7950. The part is fetched from EasyEDA, so this needs the internet.`)}),p&&(0,X.jsx)(im,{result:p}),(0,X.jsx)(`button`,{type:`submit`,disabled:c,children:p?`Close`:`Import`})]})}var om=/(?:^|[\s>])\.([A-Za-z_][\w-]*)/,sm=/^([A-Za-z_][\w-]*)\.[\w-]+$/;function cm(e){let t=new Set;for(let n of e.split(`,`)){let e=n.trim();if(e.startsWith(`net.`))continue;let r=sm.exec(e)??om.exec(e);r?.[1]&&t.add(r[1])}return[...t]}function lm(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 um=class extends Error{code;constructor(e,t){super(t),this.code=e,this.name=`EditError`}};function dm(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(lm(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 fm(e,t){if(!e)return{message:`Wait for the circuit to load, then try again.`};let n=dm(e,t);return n===void 0?{parts:[...new Set(t)]}:{message:n}}function pm(e){return e.ports.map(t=>({port:t.name,joins:`${t.bus?`bus`:`net`} ${e.connections[t.name]??t.name}`}))}function mm(e){return e.mapping.map(e=>({now:e.from,sheet:e.to,board:e.flat}))}var hm=e=>`${e.trim()||`PowerStage`}1`,gm=`Type the sheet's name, e.g. PowerStage: a capital letter, then letters, digits and _.`;function _m(e,t){return`Made ${e.file}: ${e.instance} (base ${e.base}) replaces ${t} part${t===1?``:`s`}`}var vm=200;function ym(e,t){let{name:n,instance:r,rename:i}=t,[a,o]=(0,l.useState)({problem:gm});return(0,l.useEffect)(()=>{if(n.trim()===``){o({problem:gm});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}))},vm);return()=>{t=!1,window.clearTimeout(a)}},[e,n,r,i]),a}function bm({preview:e}){let t=pm(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 xm({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:mm(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 Sm({panel:e,onClose:t}){let[n,r]=(0,l.useState)(``),[i,a]=(0,l.useState)(``),[o,s]=(0,l.useState)(!1),c=i.trim(),u={name:n.trim(),rename:o,...c?{instance:c}:{}},{preview:d,problem:f}=ym(e,u),p=(0,l.useId)(),m=async n=>{n.preventDefault(),d&&await e.make(u)&&t()};return(0,X.jsxs)(`form`,{className:`rules-form make-sheet-form`,onSubmit:e=>void m(e),children:[(0,X.jsx)(`label`,{htmlFor:p,children:`Sheet name`}),(0,X.jsx)(`input`,{id:p,value:n,placeholder:`PowerStage`,onChange:e=>r(e.target.value),"aria-describedby":`${p}-note`,"aria-invalid":f!==void 0&&n!==``}),(0,X.jsx)(`label`,{htmlFor:`${p}-instance`,children:`Instance name`}),(0,X.jsx)(`input`,{id:`${p}-instance`,value:i,placeholder:hm(n),onChange:e=>a(e.target.value)}),(0,X.jsx)(`p`,{id:`${p}-note`,children:d?`Writes ${d.file}; ${d.instance} (base ${d.base}) takes the place of ${e.parts.length} part${e.parts.length===1?``:`s`}.`:f}),d&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`h3`,{children:`Ports`}),(0,X.jsx)(bm,{preview:d}),(0,X.jsx)(`h3`,{children:`Designators`}),(0,X.jsx)(xm,{preview:d})]}),(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:!d,children:`Make sub-sheet`})]})}function Cm(e){let t;return()=>(t??=e().catch(e=>{throw t=void 0,e}),t)}function wm(e){let t=Cm(e),n=()=>(0,l.lazy)(()=>t().then(e=>({default:e}))),r=n();return{component:()=>r,retry:()=>{r=n()}}}function Tm({what:e,message:t,onRetry:n}){return(0,l.createElement)(`div`,{role:`alert`},(0,l.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,l.createElement)(`button`,{type:`button`,onClick:n},`Retry`))}var Em=class extends l.Component{state={};static getDerivedStateFromError(e){return{error:e instanceof Error?e:Error(String(e))}}render(){let{error:e}=this.state;return e?(0,l.createElement)(Tm,{what:this.props.what,message:e.message,onRetry:()=>{this.props.onRetry(),this.setState({error:void 0})}}):(0,l.createElement)(l.Suspense,{fallback:(0,l.createElement)(`p`,null,`Loading…`)},this.props.render())}},Dm=.0254,Om=e=>e===`mm`?`mil`:`mm`,km=(e,t)=>t===`mil`?e/Dm:e;function Am(e,t){let n=km(e,t).toFixed(t===`mil`?1:2);return/^-0(\.0+)?$/.test(n)?n.slice(1):n}function jm(e,t){return`${Number(km(e,t).toFixed(t===`mm`?4:2))} ${t}`}var Mm=(e,t)=>Math.round(e/t*100),Nm=.0254,Pm=[2*Nm,.1,5*Nm,10*Nm,.5,20*Nm,25*Nm,1,50*Nm,100*Nm].map(e=>Number(e.toFixed(4))),Fm=.5,Im=[.05,.1,.2],Lm=.1,Rm=(e,t,n)=>({...e,[t]:n});function zm(e,t){if(e===`schematic`)return Im.map(e=>({value:e,label:`${e} in`}));if(!t)throw Error(`The PCB's Grid steps need its display unit`);return Pm.map(e=>({value:e,label:jm(e,t)}))}var Bm={schematic:`lines`,pcb:`lines`},Vm=e=>e===`lines`?`dots`:`lines`,Hm=(e,t)=>({...e,[t]:Vm(e[t])}),Um=5,Wm=2;function Gm(e,t,n=1){let r=e;for(let e=0;e<=Wm;e++,r*=Um)if(r*t*n>=3)return r;return null}function Km(e,t,n,r=1){let i=Gm(n,e.scale,r);if(i===null)return null;let a=pe(e,t,{x:0,y:0}),o=pe(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 qm=e=>e%5==0,Jm=e=>({...e,columns:e.columns.filter(qm),rows:e.rows.filter(qm)});function Ym(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||qm(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=wa(a),s(r.columns,e=>{let r=Ta(fe(t,n,{x:e*o,y:0}).x,a);return[r,0,r,n.height]}),s(r.rows,e=>{let r=Ta(fe(t,n,{x:0,y:e*o}).y,a);return[0,r,n.width,r]})}function Xm(e,t,n,r){let i=Math.floor((Math.round(n*r)-1)/2)/r;return e.map(e=>({at:Ea(t(e),r)-i,fifth:qm(e)}))}function Zm(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 Qm(e,t,n,r,i,a){let{spacing:o}=r,s=Da(i.px,a),c=Xm(r.columns,e=>fe(t,n,{x:e*o,y:0}).x,s,a),l=Xm(r.rows,e=>fe(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&&Zm(e,u,i.fifth,s)}function $m(e,t,n,r,i,a){let o=Km(t,n,r.step,a);if(!o)return;let s=o.minor?o:Jm(o);e.save(),r.style===`dots`?Qm(e,t,n,s,i.dots,a):Ym(e,t,n,s,i.lines,a),e.restore()}function eh({panel:e,onClose:t}){let[n,r]=(0,l.useState)(e.settings),i=(0,l.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:zm(`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:zm(`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 th={width:30,height:20},nh=1e3,rh=/^[\w\- ]+(\/[\w\- ]+)*$/;function ih(e,t,n){let r=e.trim().replace(/\.circuit\.tsx$/,``);if(r===``)return{message:`Give the circuit a name`};if(!rh.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>nh)?{message:`The board's width and height are mm above 0 and at most ${nh}`}:{file:`${r}.circuit.tsx`,width:i[0],height:i[1]}}function ah({panel:e,onClose:t}){let[n,r]=(0,l.useState)(``),[i,a]=(0,l.useState)(String(th.width)),[o,s]=(0,l.useState)(String(th.height)),[c,u]=(0,l.useState)(),[d,f]=(0,l.useState)(!1),p=(0,l.useId)(),m=async r=>{r.preventDefault();let a=ih(n,i,o);if(`message`in a)return u(a.message);f(!0);let s=await e.create(a);f(!1),s&&t()};return(0,X.jsxs)(`form`,{className:`rules-form`,onSubmit:e=>void m(e),children:[(0,X.jsx)(`label`,{htmlFor:`${p}-name`,children:`Name`}),(0,X.jsx)(`input`,{id:`${p}-name`,value:n,placeholder:`power-board`,onChange:e=>r(e.target.value),"aria-invalid":c!==void 0}),(0,X.jsx)(`label`,{htmlFor:`${p}-w`,children:`Board width (mm)`}),(0,X.jsx)(`input`,{id:`${p}-w`,inputMode:`decimal`,value:i,onChange:e=>a(e.target.value)}),(0,X.jsx)(`label`,{htmlFor:`${p}-h`,children:`Board height (mm)`}),(0,X.jsx)(`input`,{id:`${p}-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:d,children:`Create`})]})}function oh(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 sh({components:e,parts:t,locked:n}){return e.map(e=>{let r=oh(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 ch=e=>[...new Set(e.map(e=>e.footprint).filter(e=>e!==``))].sort(),lh=/^[\w.\-+:,=()]+$/;function uh(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=>!lh.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 dh({panel:e,onClose:t}){let n=(0,l.useMemo)(()=>e.source?sh(e.source):[],[e.source]),[r,i]=(0,l.useState)({}),[a,o]=(0,l.useState)(),s=(0,l.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=uh(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:ch(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`})]})}function fh(e,t,n,r,i){let a={code:e,severity:t,message:n,items:Wr(r)};return i?{...a,source:i}:a}var ph={name:`default`,trackWidth:.25,clearance:.2,via:{drill:.3,diameter:.6},patterns:[]};function mh(e){let t=[...e].map(e=>e===`*`?`.*`:e===`?`?`.`:e.replace(/[.+^${}()|[\]\\]/g,`\\$&`)).join(``);return RegExp(`^${t}$`,`s`)}function hh(e,t){if(e===`*`)return!0;let n=mh(e);return t.names.some(e=>n.test(e))}var gh=(e,t)=>e.classes.filter(e=>e.patterns.some(e=>hh(e,t))).map(e=>e.name);function _h(e,t){return gh(e,t)[0]??ph.name}function vh(e,t){let n=new Map,r=[];for(let i of t){let t=gh(e,i);if(n.set(i.id,t[0]??ph.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(fh(`net-class-conflict`,`error`,a,[i.id]))}return{byNet:n,diagnostics:[...r,...yh(e,t)]}}function yh(e,t){return e.classes.flatMap(e=>e.patterns.filter(e=>!t.some(t=>hh(e,t))).map(t=>fh(`rules`,`warning`,`Net class ${e.name}: the pattern "${t}" matches no net`,[e.name])))}var bh=(e,t)=>e.classes.find(e=>e.name===t)?.clearance??ph.clearance;function xh(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(bh(e,t),bh(e,n),e.fabrication.minClearance,...r)}var Sh=(e,t)=>e.classes.find(n=>n.name===_h(e,t))??ph,Ch=(e,t)=>Math.max(Sh(e,t).trackWidth,e.fabrication.minTrackWidth),wh=e=>Math.round(e*1e6)/1e6;function Th(e,t){let n=Math.max(t.drill,e.fabrication.minDrill);return{drill:n,diameter:Math.max(t.diameter,wh(n+2*e.fabrication.minAnnularRing))}}var Eh=(e,t)=>Th(e,Sh(e,t).via),Dh=e=>Th(e,ph.via),Oh=e=>e.fabrication.filletRadius??1,kh=/^([+-]?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?)\s*(mm|in|mil)?$/i,Ah={mm:1,in:25.4,mil:.0254};function jh(e){if(typeof e==`number`)return Number.isFinite(e)?e:void 0;if(typeof e!=`string`)return;let t=kh.exec(e.trim());if(!t)return;let n=Number(t[1])*(Ah[(t[2]??`mm`).toLowerCase()]??1);return Number.isFinite(n)?n:void 0}var Mh=`Fillet radius`,Nh=`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 Ph(e){let t=e?.filletRadius;return{value:t===void 0?``:String(t),placeholder:`1 mm (default)`}}function Fh(e){if(e.trim()===``)return{radius:null};let t=jh(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 Ih=`modulepreload`,Lh=function(e,t){return new URL(e,t).href},Rh={},zh=function(e){return e.pathname.endsWith(`.css`)},Bh=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},Vh=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=Lh(t,n);let r=s(t),i=zh(r);return Bh(Rh,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`:Ih,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)})},Hh=wm(()=>Vh(()=>import(`./NewPartDialog-B_cnPuI-.js`).then(e=>e.NewPartForm),[],import.meta.url)),Uh=`button, [href], input, select, textarea, [tabindex]:not([tabindex='-1'])`;function Wh(e,t){zp(!0,n=>{let r=Pp(n.key);if(r===`hold`)return;if(n.preventDefault(),r===`close`)return t();let i=[...e.current?.querySelectorAll(Uh)??[]];(i[Fp(i.indexOf(document.activeElement),i.length,n.shiftKey)]??e.current)?.focus()})}function Gh({title:e,onClose:t,children:n,wide:r=!1}){let i=(0,l.useRef)(null);return(0,l.useEffect)(()=>{let e=document.activeElement;return(i.current?.querySelector(`[data-default]`)??i.current?.querySelector(Uh)??i.current)?.focus(),()=>{e instanceof HTMLElement&&e.isConnected&&e.focus()}},[]),Wh(i,t),(0,X.jsx)(`div`,{className:`dialog-backdrop`,onPointerDown:e=>e.target===e.currentTarget&&t(),children:(0,X.jsxs)(`section`,{ref:i,tabIndex:-1,className: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)(Ap,{})})]}),(0,X.jsx)(`div`,{className:`dialog-body`,children:n})]})})}function Kh(){return(0,X.jsx)(`table`,{children:(0,X.jsx)(`tbody`,{children:Xp().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 qh({rules:e,onClose:t}){let n=Ph(e.fabrication),[r,i]=(0,l.useState)(n.value),[a,o]=(0,l.useState)(),s=(0,l.useId)(),c=async i=>{i.preventDefault();let a=Fh(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:Mh}),(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??Nh}),(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 Jh({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 Yh({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)(Gh,{title:`Fabrication files`,onClose:t,children:(0,X.jsx)(Jh,{panel:l,onClose:t})}):e===`footprints`?(0,X.jsx)(Gh,{title:`Footprint manager`,onClose:t,wide:!0,children:(0,X.jsx)(dh,{panel:c,onClose:t})}):e===`newCircuit`?(0,X.jsx)(Gh,{title:`New circuit`,onClose:t,children:(0,X.jsx)(ah,{panel:s,onClose:t})}):e===`system`?(0,X.jsx)(Gh,{title:`System settings`,onClose:t,children:(0,X.jsx)(eh,{panel:o,onClose:t})}):e===`newPart`?(0,X.jsx)(Gh,{title:`New part`,onClose:t,wide:!0,children:(0,X.jsx)(Em,{what:`New part`,onRetry:Hh.retry,render:()=>{let e=Hh.component();return(0,X.jsx)(e,{panel:a,onClose:t})}})}):e===`importPart`?(0,X.jsx)(Gh,{title:`Import by LCSC number`,onClose:t,children:(0,X.jsx)(am,{panel:i,onClose:t})}):e===`makeSheet`?(0,X.jsx)(Gh,{title:`Make sub-sheet`,onClose:t,children:(0,X.jsx)(Sm,{panel:r,onClose:t})}):e===`rules`?(0,X.jsx)(Gh,{title:`Design rules`,onClose:t,children:(0,X.jsx)(qh,{rules:n,onClose:t})}):e===`keys`?(0,X.jsx)(Gh,{title:`Keys`,onClose:t,children:(0,X.jsx)(Kh,{})}):(0,X.jsxs)(Gh,{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 Xh(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 Zh({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=!Qf(e);t||ep(e),i&&s(t)},children:[(0,X.jsx)(`span`,{children:e}),t&&(0,X.jsx)(`kbd`,{children:t})]})}function Qh(e,t,n){(0,l.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 $h=(e,t)=>(e+t)%t,eg=e=>e===`item`||e===`disabled`;function tg(e,t,n,r=eg){let i=e.length,a=t??(n===1?-1:i);for(let t=0;t<i;t++)if(a=$h(a+n,i),r(e[a]))return a;return null}var ng=e=>e?tg(e,null,1):null,rg=e=>e?tg(e,null,-1):null,ig=(e,t)=>e?tg(e,null,t,e=>e===`item`)??tg(e,null,t):null,ag=e=>ig(e,1),og=e=>ig(e,-1),sg=(e,t,n=!0)=>({open:e,focus:t,preventDefault:n}),cg=(e,t)=>sg(e,{menu:e,item:t});function lg(e,t,n,r){let i=r.length,a={ArrowLeft:$h(t-1,i),ArrowRight:$h(t+1,i),Home:0,End:i-1}[e];return a===void 0?e===`ArrowDown`?cg(t,ag(r[t])):e===`ArrowUp`?cg(t,og(r[t])):n===null?null:e===`Escape`?sg(null,{menu:t,item:null}):e===`Tab`?sg(null,`keep`,!1):null:sg(n===null?null:a,{menu:a,item:null})}function ug(e,t,n){let r=n[t.menu]??[],i=n.length,a={ArrowDown:tg(r,t.item,1),ArrowUp:tg(r,t.item,-1),Home:ng(r),End:rg(r)};if(e in a)return cg(t.menu,a[e]??null);if(e===`ArrowLeft`||e===`ArrowRight`){let r=$h(t.menu+(e===`ArrowLeft`?-1:1),i);return cg(r,ag(n[r]))}return e===`Escape`?sg(null,{menu:t.menu,item:null}):e===`Tab`?sg(null,{menu:t.menu,item:null},!1):null}function dg(e,t,n){return e===`Escape`?sg(null,`keep`):e===`Tab`?sg(null,`keep`,!1):e===`ArrowDown`||e===`Home`?cg(t,ag(n[t])):e===`ArrowUp`||e===`End`?cg(t,og(n[t])):e===`ArrowLeft`||e===`ArrowRight`?sg($h(t+(e===`ArrowLeft`?-1:1),n.length),`keep`):null}function fg(e,t,n,r,i={}){return r.length===0||(i.alt||i.ctrl||i.meta)&&e!==`Tab`?null:t===null?n===null?null:dg(e,n,r):t.item===null?lg(e,t.menu,n,r):ug(e,{menu:t.menu,item:t.item},r)}function pg(e){return ag(e)}var mg=e=>e.item===null?`[data-menu="${e.menu}"]:not([data-item])`:`[data-menu="${e.menu}"][data-item="${e.item}"]`;function hg(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 gg(e){let t=(0,l.useRef)(null);return(0,l.useLayoutEffect)(()=>{let n=t.current;n&&(t.current=null,e.current?.querySelector(mg(n))?.focus())}),(0,l.useCallback)(n=>{let r=e.current?.querySelector(mg(n));r?r.focus():t.current=n},[e])}function _g({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}=qp(e,r,i,a);return(0,X.jsx)(`li`,{role:`none`,children:(0,X.jsx)(Zh,{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 vg({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)(_g,{entry:e,menu:t,index:s,view:n,selected:r,off:i,toggles:a,onRun:o},e===`separator`?`sep${s}`:e.label))})}function yg({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(!Qf(e))return o({open:t,focus:{menu:t,item:pg(Qp(s,c,l)[t])},preventDefault:!0});ep(e),i(t)},onPointerEnter:()=>a(t),children:e.title}),n&&(0,X.jsx)(vg,{menu:e,index:t,view:s,selected:c,off:l,toggles:u,onRun:d})]})}function bg({run:e,view:t,selected:n,toggles:r,off:i,children:a}){let[o,s]=(0,l.useReducer)(Zp,{open:null}),[c,u]=(0,l.useState)(0),d=(0,l.useRef)(null),f=gg(d),p=o.open===null?null:Gp.findIndex(e=>e.title===o.open),m=(0,l.useMemo)(()=>Qp(t,n,i),[t,n,i]),h=e=>{s({type:`set`,title:e.open===null?null:Gp[e.open]?.title??null}),e.focus!==`keep`&&(u(e.focus.menu),f(e.focus))},g=e=>{let t=fg(e.key,hg(d.current,document.activeElement),p,m,{alt:e.altKey,ctrl:e.ctrlKey,meta:e.metaKey});return t?(t.preventDefault&&e.preventDefault(),h(t),!0):!1};zp(p!==null,e=>void g(e)),Qh(p!==null,d,(0,l.useCallback)(()=>s({type:`outside`}),[]));let _=(t,n,r)=>{r&&h({open:null,focus:{menu:n,item:null},preventDefault:!0}),s({type:`run`}),e(t)},v=e=>{u(e),s({type:`click`,title:Gp[e]?.title??``})},y=e=>s({type:`hover`,title:Gp[e]?.title??``});return(0,X.jsxs)(`header`,{className:`menubar hairline-b`,ref:d,children:[(0,X.jsx)(`span`,{className:`brand`,title:`copperflow`,children:`copperflow`}),(0,X.jsx)(`nav`,{className:`menus`,role:`menubar`,"aria-label":`Menu`,onKeyDown:e=>g(e)&&e.stopPropagation(),children:Gp.map((e,a)=>(0,X.jsx)(yg,{menu:e,index:a,open:p===a,current:c===a,onPointer:v,onHover:y,onKeyboard:h,view:t,selected:n,off:i,toggles:r,onRun:_},e.title))}),(0,X.jsx)(`div`,{className:`menubar-end`,children:a})]})}var xg=`Main`;function Sg(e){let t=e?.schematic.pages?.map(e=>e.name);return t&&t.length>0?t:[xg]}function Cg(e,t){let n=Sg(e);return n.includes(t)?t:n[0]??`Main`}function wg(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 Tg(e){for(let t=e.length+1;;t++)if(!e.includes(`Page ${t}`))return`Page ${t}`}function Eg(e,t){if(t===`Main`)return`${xg} 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 Dg(e){return e===`Main`?`${xg} is the first page and keeps its name`:void 0}function Og(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 kg(e,t){return e.status===`building`?`busy`:e.status===`failed`||t>0?`bad`:e.status===`done`?`good`:`idle`}function Ag({build:e,errors:t,onOpen:n}){return(0,X.jsxs)(`button`,{className:`build ${kg(e,t)}`,onClick:e=>{rp(e),n()},title:`Show DRC`,children:[(0,X.jsx)(`span`,{className:`dot`,"aria-hidden":`true`}),(0,X.jsx)(`span`,{role:`status`,children:Og(e,t)})]})}var jg=`light`,Mg=`copperflow.theme`,Ng=()=>typeof window>`u`?void 0:window.localStorage,Pg=e=>e===`dark`||e===`light`?e:jg;function Fg(e){try{return Pg(e()?.getItem(Mg))}catch{return jg}}function Ig(e,t){try{let n=e();return n?(n.setItem(Mg,t),!0):!1}catch{return!1}}function Lg(e,t){e.setAttribute(`data-theme`,t)}var Rg=e=>({themeLight:e===`light`,themeDark:e===`dark`}),zg=e=>e===`dark`?`dots`:`lines`,Bg=(e,t,n)=>t===n?e:Vg(e,n),Vg=(e,t)=>({...e,schematic:zg(t)}),Hg=(e,t,n,r,i)=>({id:e,title:t,icon:n,command:r,group:i}),Ug=(e,t,n,r,i)=>({id:e,title:t,icon:n,pending:r,group:i}),Wg=[Hg(`undo`,`Undo (Ctrl+Z)`,`undo`,`undo`,0),Hg(`redo`,`Redo (Ctrl+Y)`,`redo`,`redo`,0)],Gg=[Hg(`zoomIn`,`Zoom in`,`zoomIn`,`zoomIn`,1),Hg(`zoomOut`,`Zoom out`,`zoomOut`,`zoomOut`,1),Hg(`fit`,`Fit all (K)`,`fit`,`fit`,1),Hg(`fitSelection`,`Fit selection`,`fitSelection`,`fitSelection`,1),Hg(`fitArea`,`Fit area`,`fitArea`,`fitArea`,1)],Kg=e=>[Hg(`rotate`,`Rotate (Space)`,`rotate`,`rotate`,e),Hg(`rotateRight`,`Rotate right`,`rotateRight`,`rotateRight`,e)],qg=e=>[Hg(`gridStyle`,`Grid style`,`grid`,`gridStyle`,e),Hg(`snap`,`Snap (Alt+S)`,`snap`,`snap`,e)],Jg=e=>[Hg(`alignLeft`,`Align left (Ctrl+Shift+L)`,`alignLeft`,`alignLeft`,e),Hg(`distributeH`,`Distribute horizontally (Ctrl+Shift+H)`,`distributeH`,`distributeH`,e)],Yg=e=>Hg(`checkDrc`,`Check DRC`,`check`,`checkDrc`,e),Xg={schematic:[...Wg,...Gg,...qg(2),Hg(`component`,`Component (Shift+F)`,`component`,`placeComponent`,3),Hg(`wire`,`Wire (Alt+W)`,`wire`,`wire`,3),Hg(`bus`,`Bus (Alt+B)`,`bus`,`drawBus`,3),Hg(`netLabel`,`Net label (Alt+N)`,`netLabel`,`netLabel`,3),Hg(`ground`,`Ground flag`,`ground`,`groundFlag`,3),Hg(`power`,`Power flag`,`power`,`powerFlag`,3),Hg(`noConnect`,`No connect flag`,`noConnect`,`noConnect`,3),Hg(`polyline`,`Polyline (Alt+L)`,`polyline`,`drawPolyline`,4),Hg(`arc`,`Arc (Alt+A)`,`arc`,`drawArc`,4),Hg(`circle`,`Circle (Alt+C)`,`circle`,`drawCircle`,4),Hg(`rectangle`,`Rectangle (Alt+R)`,`rectangle`,`drawRectangle`,4),Hg(`text`,`Text (Alt+T)`,`text`,`drawText`,4),...Kg(5),...Jg(6),Yg(7)],pcb:[...Wg,...Gg,{id:`unit`,title:`Unit (Q)`,text:`unit`,command:`toggleUnit`,group:2},...qg(2),Hg(`via`,`Via (Alt+V)`,`via`,`placeVia`,3),Ug(`boardOutline`,`Board outline`,`boardOutline`,Wp,3),Ug(`copperArea`,`Copper area`,`copperArea`,Wp,3),Yg(4),Hg(`singleRouting`,`Single routing (Alt+W)`,`singleRouting`,`singleRouting`,5),...Jg(6),...Kg(7),Hg(`gerber`,`Gerber`,`gerber`,`exportFabrication`,8)]};function Zg(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=Up(e.command,t);return i?{enabled:!1,title:`${e.title}: ${i}`}:{enabled:!0,title:e.title}}function Qg(e){let t=[];for(let n of Xg[e]){let e=t.at(-1);e&&e[0]?.group===n.group?e.push(n):t.push([n])}return t}var $g=new Set([`wire`,`netLabel`,`groundFlag`,`powerFlag`,`fitArea`,`singleRouting`,`placeVia`,`noConnect`,`junction`,...x]);function e_(e){return $g.has(e)}var t_={snap:`snap`};function n_(e,t,n){let r=t_[e];return r?n[r]:t===e}function r_(e){return e_(e)||e in t_}function i_(e,t){return e?`wire`:t===`label`?`netLabel`:t===`gnd`?`groundFlag`:t===`vcc`?`powerFlag`:null}function a_(e){return e?S[e]:null}var o_={active:null,stop:null},s_=o_,c_=new Set;function l_(e){if(e.active!==s_.active||e.stop!==s_.stop){s_=e;for(let e of c_)e()}}function u_(){return s_}function d_(){l_(o_)}function f_(e){return c_.add(e),()=>{c_.delete(e)}}function p_(){return(0,l.useSyncExternalStore)(f_,u_)}function m_(e,t){return t.active===e&&t.stop?`stop`:`run`}var h_=o(),g_=[`onPointerDown`,`onPointerMove`,`onPointerUp`,`onPointerCancel`,`onMouseDown`,`onMouseMove`,`onMouseUp`,`onDoubleClick`,`onWheel`,`onContextMenu`];function __(){let e=e=>e.stopPropagation();return Object.fromEntries(g_.map(t=>[t,e]))}var v_=`toolbar-view-slot`,y_=__();function b_({children:e}){let[t,n]=(0,l.useState)(null);return(0,l.useLayoutEffect)(()=>n(document.getElementById(v_)),[]),t?(0,h_.createPortal)((0,X.jsx)(`div`,{className:`canvas-tools`,...y_,onClick:rp,children:e}),t):null}function x_({item:e,unit:t}){if(e.text===`unit`)return(0,X.jsx)(X.Fragment,{children:t});let n=Np[e.icon];return(0,X.jsx)(n,{})}function S_({view:e,unit:t,selected:n,toggles:r,off:i,run:a}){let o=p_();return(0,X.jsxs)(`div`,{className:`studio-toolbar hairline-b`,role:`toolbar`,"aria-label":`Tools`,children:[Qg(e).map((e,s)=>(0,X.jsxs)(l.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&&n_(e.command,o.active,r),c=Zg(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&&r_(e.command)?s:void 0,"data-pressed":s||void 0,onClick:t=>{rp(t),c.enabled&&e.command!==void 0&&(m_(e.command,o)===`stop`?o.stop?.():a(e.command))},children:(0,X.jsx)(x_,{item:e,unit:t})},e.id)})]},e[0]?.group)),(0,X.jsx)(`div`,{className:`toolbar-view-slot`,id:v_})]})}var C_=[`Designators`,`Quantity`,`Value`,`Footprint`,`Manufacturer`,`MPN`,`Supplier part`,`Verified`];function w_(e){return/[",\r\n]/.test(e)?`"${e.replace(/"/g,`""`)}"`:e}function T_(e){return[C_,...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(w_).join(`,`)).join(`\r
|
|
14
|
-
`)+`\r
|
|
15
|
-
`}function E_(e){return`${(e.split(/[\\/]/).at(-1)??e).replace(/\.circuit\.tsx$|\.tsx$/,``)}-bom.csv`}function D_(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 O_=(e,t)=>`${e} ${t}${e===1?``:`s`}`;function k_(e){let t=`Checks: ${O_(e.errors,`error`)}, ${O_(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 A_=3;function j_(e){let t=e.slice(0,A_).map(e=>`Warning: ${e}.`),n=e.length-A_;return n>0?[...t,`And ${n} more ${n===1?`warning`:`warnings`}.`]:t}function M_(e){if(!e.written)return`No fabrication files written: ${e.errors.join(`; `)}`;let t=D_(e.zip,e.folder,e.files);return[`Wrote ${e.files.length} fabrication files to ${e.folder}/ and ${e.zip}.`,`U${t.slice(1)}.`,...j_(e.warnings),k_(e.checks)].join(` `)}function N_(e){return e.errors>0}var P_=(e,t)=>`${e} ${t}${e===1?``:`s`}`;function F_(e){return`The design rule check reports ${P_(e.errors,`error`)} and ${P_(e.warnings,`warning`)}. Look at them before you order this board.`}var I_=1e-9,L_=(e,t)=>({x:e.x-t.x,y:e.y-t.y}),R_=(e,t)=>({x:e.x+t.x,y:e.y+t.y}),z_=(e,t)=>({x:e.x*t,y:e.y*t}),B_=(e,t)=>e.x*t.y-e.y*t.x,V_=(e,t)=>e.x===t.x&&e.y===t.y;function H_(e){return e.every((t,n)=>n===0||Ns(e[n-1],t)!==`slanted`)}function U_(e){let t=e.map(e=>({x:z(e.x),y:z(e.y)})),n=t.filter((e,n)=>n===0||!V_(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(B_(L_(t,i),L_(a,t)))<I_||r.push(t)}return r}function W_(e,t,n,r){let i=B_(t,r);if(!(Math.abs(i)<I_))return R_(e,z_(t,B_(L_(n,e),r)/i))}function G_(e,t,n){let[r,i]=[e[t],e[t+1]],a=L_(i,r),o=R_(r,n),s=(r,i)=>{let s=e[r],c=e[i],l=c&&W_(c,L_(s,c),o,a);return l?[l]:r===t?[s,R_(s,n)]:[R_(s,n),s]},c=t===0?[r,o]:s(t,t-1),l=t+1===e.length-1?[R_(i,n),i]:s(t+1,t+2);return[...e.slice(0,t),...c,...l,...e.slice(t+2)]}function K_(e,t,n,r){let i={x:ve(e.x+n.x,r.step,r.snap),y:ve(e.y+n.y,r.step,r.snap)},a=L_(t,e),o=Math.hypot(a.x,a.y);if(o<I_)return{x:0,y:0};let s={x:-a.y/o,y:a.x/o};return z_(s,(i.x-e.x)*s.x+(i.y-e.y)*s.y)}function q_(e,t,n,r){let i=e[t],a={x:ve(i.x+n.x,r.step,r.snap),y:ve(i.y+n.y,r.step,r.snap)};return e.map((e,n)=>n===t?a:e)}function J_(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=H_(e)?Ac(e,t,n,r):t.kind===`corner`?q_(e,t.index,n,r):G_(e,t.index,K_(i,a,n,r));let s=U_(o);return s.length>=2?s:[...e]}var Y_=e=>Math.max(e.length-1,0),X_=(e,t)=>Number.isInteger(t)&&t>=0&&t<Y_(e),Z_=e=>e.map(e=>({x:e.x,y:e.y}));function Q_(e,t){let n=Y_(e.points);if(!X_(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:Z_(r)};return i?{edits:[s,{kind:`addTrack`,...o,layer:e.layer,width:e.width,points:Z_(i)}]}:{edits:[s]}}var $_={tracks:new Map,vias:new Map},ev=(e,t)=>({x:e.x+t.x,y:e.y+t.y}),tv=(e,t)=>e.length===t.length&&e.every((e,n)=>e.x===t[n]?.x&&e.y===t[n]?.y),nv=(e,t)=>Math.hypot(t.x-e.at.x,t.y-e.at.y)<=e.diameter/2;function rv(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&&nv(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 iv(e,t,n,r,i){let a=t=>r.some(e=>nv(e,t))||!i(t,e.layer)&&!n.some(e=>nv(e,t)),[o,s]=[e.points[0],e.points.at(-1)];return U_(Hs(e.points,t,{start:a(o),end:a(s)}))}function av(e,t,n){let r=e.points.length-1,i=(e,t)=>(t===0||t===r)&&n.some(t=>nv(t,e));return e.points.some(i)?U_(e.points.map((e,n)=>i(e,n)?ev(e,t):e)):e.points}function ov(e,t,n,r){let i=[];if(n.x===0&&n.y===0)return{edits:[],shapes:$_,skipped:i};let a=new Set(t),o=rv(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?iv(t,n,e.vias,o,r):av(t,n,o);!tv(c,t.points)&&c.length>=2&&s.set(t.id,c)}let c=new Map(o.map(e=>[e.id,ev(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 sv(e,t){if(!tv(t,e.points))return e.locked?{message:`${e.id} is locked`}:{kind:`setTrack`,id:e.id,points:[...t]}}function cv(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 lv(e,t){if(!e)return{message:`${t.id} is gone`};if(!qi(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=Q_({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 uv(e,t){return{tracks:new Map([...e.tracks,...t.tracks]),vias:new Map([...e.vias,...t.vias])}}function dv(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 fv(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`} ${et([...i,...a].map(e=>e.id))}`}}function pv(e,t){return!t&&e.copper.length>0&&e.total===e.copper.length}function mv(e){let t=e.lastIndexOf(`/`);return t>0?e.slice(0,t):void 0}var hv=e=>/(^|\/)hole:\d+$/.test(e);function gv(e,t,n){return`${e} is a ${hv(e)?`hole`:`copper pour`} inside the sub-sheet instance ${t}; edit ${n??`its sheet file`} instead`}var _v=(e,t)=>e.x===t.x&&e.y===t.y,vv=(e,t,n)=>(t.x-e.x)*(n.y-e.y)-(t.y-e.y)*(n.x-e.x);function yv(e,t,n,r){let[i,a,o,s]=[vv(n,r,e),vv(n,r,t),vv(e,t,n),vv(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 bv(e){let t=e.length;if(t<3)return`an outline needs at least 3 corners`;if(e.some((n,r)=>_v(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(yv(i,a,o,s))return`two of its edges cross`}let n=e.reduce((n,r,i)=>n+vv({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 xv(e,t){return`${t}:${e.filter(e=>e.tag===t).length+1}`}var Sv=3.2,Cv=100,wv=e=>({tool:e,points:[]}),Tv=(e,t)=>e.x===t.x&&e.y===t.y,Ev=e=>({state:e});function Dv(e){return e.filter((t,n)=>n===0||!Tv(t,e[n-1]))}function Ov(e){let t=Dv(e.points);if(t.length>=3&&t.at(-1)&&Tv(t[0],t.at(-1))&&t.pop(),t.length<3)return Ev(e);let n=bv(t);return n?{state:e,refused:`Not closed: ${n}`}:{state:wv(e.tool),outline:t}}function kv(e,t,n){if(e.tool===`hole`)return{state:e,hole:t};if(n&&e.points.length>0)return Ov(e);let r=e.points[0];return r&&e.points.length>=3&&Tv(r,t)?Ov(e):Ev({...e,points:Dv([...e.points,t])})}function Av(e,t){switch(t.type){case`press`:return kv(e,t.at,t.double);case`finish`:return e.tool===`pour`?Ov(e):Ev(e);case`removeCorner`:return Ev({...e,points:e.points.slice(0,-1)});case`cancel`:return{state:e.points.length>0?wv(e.tool):null}}}function jv(e,t){return!e||e.tool!==`pour`||e.points.length===0?[]:t?Dv([...e.points,t]):[...e.points]}function Mv(e){let t=e.circuit.nets.flatMap(e=>e.names);return t.includes(`GND`)?`GND`:t[0]}function Nv(e,t,n){return{kind:`addPour`,net:e,layer:t,...n?{outline:[...n]}:{}}}var Pv=(e,t,n)=>`add a ${e} copper pour on the ${t} layer${n?` over the whole board`:``}`;function Fv(e,t){return{kind:`addHole`,x:e.x,y:e.y,diameter:t}}var Iv=e=>`add a ${e} mm hole`;function Lv(e){let t=Number(e.trim().replace(/\s*mm$/i,``));return e.trim()===``||!Number.isFinite(t)||t<=0||t>Cv?{message:`The diameter must be a number of mm above 0 and at most ${Cv}`}:Math.round(t*1e3)/1e3}function Rv(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=bv(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 zv(e,t,n){let r=mv(n);if(r!==void 0)return gv(n,r,lm({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 Bv=e=>Number(e.slice(e.indexOf(`:`)+1)),Vv=e=>e.tag===`hole`?`hole ${Bv(e.id)}`:`copper pour ${Bv(e.id)}`;function Hv(e,t){return n=>{let r=n.map(n=>({id:n,blocker:zv(e,t,n)})),i=r.flatMap(e=>e.blocker===null?[e.id]:[]);return{edits:[...i].sort((e,t)=>Bv(t)-Bv(e)).map(e=>hv(e)?{kind:`removeHole`,id:e}:{kind:`removePour`,id:e}),names:i.flatMap(t=>e.boardItems?.find(e=>e.id===t)??[]).map(Vv),skipped:r.flatMap(e=>e.blocker??[]),removed:i}}}var Uv=`Esc or a right click stops.`;function Wv(e){if(e)return e.tool===`hole`?`Click where the hole goes; set its diameter in the field. ${Uv}`:e.points.length===0?`Click the first corner of the copper pour. ${Uv}`:`Click for each corner; double click, Enter or a click on the first corner closes the pour. Backspace removes a corner, Esc cancels.`}var Gv=[{value:`top`,label:`Top Layer`},{value:`bottom`,label:`Bottom Layer`}],Kv=[{value:`inner1`,label:`Inner Layer 1`},{value:`inner2`,label:`Inner Layer 2`}],qv=[{value:`relief`,label:`Relief (spokes)`},{value:`solid`,label:`Solid`}],Jv=e=>String(Number(e.toFixed(4))),Yv=e=>e===void 0?`Not filled`:`${e.toFixed(2)} mm²`;function Xv(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:hl(e,t.net),field:`net`,choices:n},{label:`Layer`,value:t.layer,field:`layer`,choices:e.pcb.board?.layers===4?[...Gv,...Kv]:Gv},{label:`Priority`,value:String(t.priority),field:`priority`},{label:`Clearance (mm)`,value:t.clearance===void 0?``:Jv(t.clearance),field:`clearance`},{label:`Min width (mm)`,value:Jv(t.minWidth),field:`minWidth`},{label:`Thermal`,value:t.thermal,field:`thermal`,choices:qv},{label:`Outline`,value:t.outline?`${t.outline.length} corners`:`Whole board`},{label:`Fill area`,value:Yv(r?.area)}]}function Zv(e){return[{label:`X (mm)`,value:Jv(e.x),field:`x`},{label:`Y (mm)`,value:Jv(e.y),field:`y`},{label:`Diameter (mm)`,value:Jv(e.diameter),field:`diameter`}]}function Qv(e,t){let n=pl(e).find(e=>e.id===t);if(n)return{kind:`pour`,title:`Copper pour`,rows:Xv(e,n)};let r=e.pcb.holes.find(e=>e.id===t);return r&&{kind:`hole`,title:`Hole`,rows:Zv(r)}}function $v(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 ey(e,t){return e===`net`||e===`layer`||e===`thermal`?t:e===`clearance`&&t.trim()===``?null:$v(t,e,e===`priority`?`whole`:`positive`)}function ty(e,t){return e===`diameter`?Lv(t):$v(t,e,`any`)}function ny(e,t,n,r){let i=Qv(e,t)?.rows.find(e=>e.field===n);if(!i||i.value===r.trim())return;let a=hv(t),o=a?ty(n,r):ey(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 ry(e,t){let n=hv(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 iy(e,t,n,r=new Set){return gt([...e.names,...e.board],t,n,r)}var ay=.5,oy=e=>Math.round(e*1e3)/1e3||0,sy=e=>e.pcb??{x:0,y:0,rotation:0};function cy(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=>py(fy(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 ly=(e,t)=>e.minX<t.maxX&&t.minX<e.maxX&&e.minY<t.maxY&&t.minY<e.maxY;function uy(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=gy(e,t);if(!a)return;let o=[t,...n].map(e=>({name:e.name,box:cy(a,sy(t),sy(e))}));for(let[e,t]of o.entries()){let n=o.slice(e+1).find(e=>ly(t.box,e.box));if(n)return`${t.name} and ${n.name} would overlap; place the instances apart first, then replicate the layout.`}}function dy(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 fy=(e,t)=>dy({x:e.x-t.x,y:e.y-t.y},-t.rotation),py=(e,t)=>{let n=dy(e,t.rotation);return{x:oy(n.x+t.x),y:oy(n.y+t.y)}};function my(e,t){let n=un(e,t)?.pcb;return n!==void 0&&(n.x!==0||n.y!==0)}function hy(e,t){for(let n of t){let t=un(e,n)??un(e,dn(e,n)?.outer??``);if(t)return t}}function gy(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)-ay,maxX:Math.max(...i)+ay,minY:Math.min(...a)-ay,maxY:Math.max(...a)+ay}}function _y(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 vy(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=gy(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 yy(e,t,n){let r=dn(e,t)?.localId;return e.circuit.components.find(e=>e.instance===n.path&&e.localId===r)?.id}function by(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:yy(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 xy(e,t){let n=sy(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=fy(i,n),o=((i.rotation-n.rotation)%360+360)%360,s={pcbX:oy(a.x),pcbY:oy(a.y),...o===0?{}:{pcbRotation:oy(o)}};return[{kind:`setProps`,part:r.localId,props:s}]})}function Sy(e,t,n,r){let i=t.tracks.filter(t=>vy(e,n,t.net,t.points,t.pads)),a=t.vias.filter(t=>vy(e,n,t.net,[t.at])),o=sy(n);return r.flatMap(r=>{let s=sy(r),c=e=>py(fy(e,o),s),l=t=>{let i=by(e,t,n,r);return i===void 0?{}:{net:i}},u=[...t.tracks.filter(e=>_y(r,e.net,e.pads)).map(e=>({kind:`removeTrack`,id:e.id})),...t.vias.filter(e=>_y(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 Cy(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 wy(e,t,n,r=new Set){if(!e)return{message:`Wait for the build to finish, then try again.`};let i=hy(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=Cy(i,a,r);if(o)return{message:o};let s=uy(e,i,a,n??(t=>my(e,t)));if(s)return{message:s};let c=a.map(e=>e.name).join(`, `),l={file:i.file,edits:xy(e,i),summary:`Replicate the placement of ${i.name} in ${i.sheet}`},u={edits:Sy(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 Ty={toggleUnit:`toggleUnit`,gridStyle:`toggleGridStyle`,snap:`toggleSnap`,toggleLeftPanel:`toggleLeftPanel`,toggleRightPanel:`toggleRightPanel`,toggleBottomPanel:`toggleBottomPanel`,clearHighlight:`clearHighlight`,placeComponent:`openLibrary`};[...g];var Ey=[`wire`,`netLabel`,`groundFlag`,`powerFlag`,...x],Dy=[`noConnect`,`junction`],Oy=[`singleRouting`,`placeVia`,`routingCorner`],ky=[`placePour`,`placePourBoard`,`placeHole`],Ay=[`filletTracks`,`straightenTracks`],jy=new Set;function My(e){return jy.add(e),()=>{jy.delete(e)}}function Ny(e){for(let t of jy)if(t(e))return!0;return!1}function Py(e){let t=(0,l.useRef)(e);t.current=e,(0,l.useEffect)(()=>My(e=>{let n=t.current[e];return n?(n(),!0):!1}),[])}var Fy=(e,t)=>e.by===`router`&&!e.locked&&(t===void 0||t.has(e.id)),Iy=1e-6;function Ly(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 Ry(e,t){if(t.at===void 0||t.diameter===void 0)return!1;let n=t.diameter/2+(e.width??0)/2+Iy,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&&Ly(r,e.points[i-1],t)<=n)}function zy(e,t={}){let n=t.ids===void 0?void 0:new Set(t.ids),r=[],i=e.tracks.filter(e=>{if(!Fy(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(!Fy(e,n))return!1;let t=a.some(t=>Ry(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 By=[`top`,`bottom`,`inner1`,`inner2`],Vy=Math.PI/180,Hy=1e-12;function Uy(e,t){let n=Math.cos(t.rotation*Vy),r=Math.sin(t.rotation*Vy);return{x:t.x+e.x*n-e.y*r,y:t.y+e.x*r+e.y*n}}function Wy(e,t,n){return t<=Hy&&n<=Hy?[Uy({x:0,y:0},e)]:n<=Hy?[Uy({x:-t,y:0},e),Uy({x:t,y:0},e)]:t<=Hy?[Uy({x:0,y:-n},e),Uy({x:0,y:n},e)]:[{x:-t,y:-n},{x:t,y:-n},{x:t,y:n},{x:-t,y:n}].map(t=>Uy(t,e))}function Gy(e,t,n){let r=Math.min(t,n),i=(Math.max(t,n)-r)/2;return{core:t>=n?Wy(e,i,0):Wy(e,0,i),radius:r/2}}function Ky(e){switch(e.shape){case`rect`:return{core:Wy(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:Wy(e,e.width/2-t,e.height/2-t),radius:t}}case`circle`:return{core:[Uy({x:0,y:0},e)],radius:e.width/2};case`oval`:return Gy(e,e.width,e.height);default:return}}function qy(e,t){return{x:e.x-t.x,y:e.y-t.y}}function Jy(e,t){return e.x*t.y-e.y*t.x}function Yy(e,t,n){let r=qy(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 Xy(e,t,n,r){let i=qy(t,e),a=qy(r,n),o=Jy(i,a);if(o===0)return;let s=Jy(qy(n,e),a)/o,c=Jy(qy(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 Zy(e,t,n,r){let i=Xy(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=Yy(i,n,r);a.push({distance:e.distance,from:i,to:e.at})}for(let i of[n,r]){let n=Yy(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 Qy(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 $y(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 eb(e,t){if(!(e.length<3))return t.find(t=>$y(t,e))}function tb(e,t){let n=eb(e,t)??eb(t,e);if(n!==void 0)return{distance:0,from:n,to:n};let r;for(let[n,i]of Qy(e))for(let[e,a]of Qy(t)){let t=Zy(n,i,e,a);(r===void 0||t.distance<r.distance)&&(r=t)}return r}function nb(e,t){return tb(e.core,t.core).distance-e.radius-t.radius}function rb(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 ib(e,t){let{from:n,to:r}=tb(e.core,t.core);return[rb(n,r,e.radius),rb(r,n,t.radius)]}function ab(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 ob=({x0:e,x1:t,y0:n,y1:r})=>Math.max(0,t-e+1)*Math.max(0,r-n+1),sb=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);ob(n)>4096?this.wide.push(e):cb(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 ob(t)>4096?this.cells.forEach(r):cb(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 cb({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 lb=[`top`,`inner1`,`inner2`,`bottom`],ub=1e-9,db=(e,t)=>e.layers===`through`||e.layers===t,fb=e=>({core:[e],radius:0});function pb(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 mb(e){let t=e.layers.map(e=>lb.indexOf(e));return new Set(lb.slice(Math.min(...t),Math.max(...t)+1))}function hb(e,t,n){return t!==void 0&&nb(t,fb(n))<=ub}function gb(e,t,n){return e.flatMap(e=>e.pads.filter(e=>db(e,n)&&hb(e,Ky(e),t)))}function _b(e,t){return nb(e,t)<=ub}function vb(e,t){if(t.length===0)return{message:`Select parts, or a sub-sheet instance, to route their connections.`};let n=t.length===1?un(e,t[0]):void 0;if(n)return{kind:`instance`,instance:n.path};let r=new Set(t.map(t=>dn(e,t)?.outer)),[i]=r;if(r.size===1&&i!==void 0){let n=fn(e,i);if(n.length===t.length&&n.every(e=>t.includes(e)))return{kind:`instance`,instance:i}}return{kind:`parts`,parts:[...t]}}function yb(e){return e.length===0?{message:`Click a net in the Nets panel to highlight it, then Autoroute net.`}:{kind:`nets`,nets:[...e]}}function bb(e,t,n=new Set){if(!e)return{message:`Wait for the build to finish, then try again.`};let r=_n(n,e),i=t=>{let n=t.points[0];return n===void 0?void 0:gb(e.pcb.parts,n,t.layer).find(e=>r.has(e.component))?.component},a=t.length===0?void 0:t,{edits:o,skipped:s}=zy(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 xb(e,t){if(t.length===0)return{message:`Select the parts to place first.`};let n=t.flatMap(t=>un(e,t)?.parts??[t]);return{kind:`parts`,parts:[...new Set(n)]}}function Sb(e,t){for(let n of t){let t=un(e,n)?.path??dn(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 Cb(e,t,n){let r=e.ask(t,n)?.trim();return r===void 0||r===``?void 0:r}async function wb(e){let t=Cb(e,`Name of the new page`,Tg(Sg(e.design)));t!==void 0&&await e.edit([{kind:`addPage`,name:t}],`add page ${t}`)&&e.openPage(t)}async function Tb(e){let t=Dg(e.page);if(t)return e.notify(t);let n=Cb(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 Eb(e){let t=Eg(e.design,e.page);if(t)return e.notify(t);let n=Sg(e.design).indexOf(e.page),r=Sg(e.design)[Math.max(0,n-1)]??`Main`;await e.edit([{kind:`removePage`,name:e.page}],`delete page ${e.page}`)&&e.openPage(r)}function Db(e,t){return e===`addPage`?wb(t):e===`renamePage`?Tb(t):Eb(t)}function Ob(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 kb(e){let t=an(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 Ab(e){let t=[...Xo(e).map(e=>e.box),...Hu(e).map(e=>e.box)];t.push(...e.labels.map(xr),...e.drawings.map(kb));let n=xe([...e.wires.flatMap(e=>e.points),...e.junctions]);return n&&t.push(n),Se(t)}var jb=()=>da(`light`).background,Mb={width:297,height:210,margin:10};function Nb(){return{width:(Mb.width-2*Mb.margin)*8,height:(Mb.height-2*Mb.margin-Pb)*8}}var Pb=8;function Fb(e){return e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).replace(/"/g,`"`).replace(/'/g,`'`)}function Ib(e){let t={width:Mb.width-2*Mb.margin,height:Mb.height-2*Mb.margin},n={width:t.width,height:t.height-Pb};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">${Fb(e.title)}</text>`,`<image x="0" y="${Pb}" width="${n.width}" height="${n.height}" preserveAspectRatio="xMidYMid meet" href="${Fb(e.image)}" />`,`<rect x="0" y="${Pb}" width="${n.width}" height="${n.height}" fill="none" stroke="currentColor" stroke-width="0.2" />`,`</svg>`].join(``)}function Lb(e,t){let n=t.map(e=>`<section class="sheet">${Ib(e)}</section>`).join(``);return[`<!doctype html>`,`<html><head><meta charset="utf-8"><title>${Fb(e)}</title>`,`<style>`,`@page { size: A4 landscape; margin: ${Mb.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 Rb=.04;function zb(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 Bb(e,t,n){let r=wg(e,t).schematic,i=Ab(r),a=da(`light`),o=i&&zb(n,a.background);if(i&&o)return pa(a),Yo(o.ctx,r,{camera:me(i,n,Rb),size:n},{ratio:1}),o.canvas.toDataURL(`image/png`)}function Vb(e,t){let n=e.pcb,r=xe(n.board?.outline??[])??Se(n.parts.map(e=>({minX:e.x-1,minY:e.y-1,maxX:e.x+1,maxY:e.y+1}))),i=r&&zb(t,jb());if(!r||!i)return;let a=me(r,t,Rb);return wd(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 Hb(e,t,n=Pg(document.documentElement.getAttribute(`data-theme`))){let r=Nb(),i=[];try{for(let n of Sg(e)){let a=Bb(e,n,r);a&&i.push({title:`${t} · Schematic · ${n}`,image:a,...r})}}finally{pa(da(n))}let a=Vb(e,r);return a&&i.push({title:`${t} · PCB`,image:a,...r}),i}function Ub(e,t){let n=window.open(``,`_blank`);return n?(n.document.open(),n.document.write(Lb(e,t)),n.document.close(),n.focus(),n.setTimeout(()=>n.print(),0),!0):!1}var Wb=12.7,Gb=e=>Math.round(e*1e3)/1e3+0;function Kb(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 qb(e,t,n){let r=[],i=[];for(let a of e){let e=Kb(a,t,n);e===void 0?r.push(a):i.push(`${a} (${e})`)}return{ok:r,skipped:i}}var Jb=e=>e.length===0?``:`; left ${e.join(`, `)}`;function Yb(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}=qb(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:Gb(r.x),pcbY:Gb(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}${Jb(o)}`,skipped:o}}var Xb=e=>({x:e.reduce((e,t)=>e+t.x,0)/e.length,y:e.reduce((e,t)=>e+t.y,0)/e.length});function Zb(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=Xb(t).y;for(let e of t)n.set(e.component,{x:r+(e.x-a)*Wb,y:(e.y-s)*Wb});r+=(o-a)*Wb+10}let i=Xb([...n.values()]);return new Map([...n].map(([e,t])=>[e,{x:t.x-i.x,y:t.y-i.y}]))}function Qb(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}=qb(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=Zb(c),u=Xb(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:Gb(u.x+t.x),pcbY:Gb(u.y+t.y),...n}}}),summary:`place ${o.length===1?o[0]:`${o.length} parts`} as on the schematic${Jb(s)}`,skipped:s}}var $b=(e,t)=>e.kind===t.kind&&e.footprint===t.footprint&&e.value===t.value;function ex(e,t,n,r){let i=t.find(t=>t.id===e.parts[0]);if(i){let e=t.filter(e=>$b(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 tx=/^([A-Za-z_]+)(\d+)$/;function nx(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 rx(e,t){let n=new Set(t.filter(e=>!e.renamable).map(e=>Number(tx.exec(e.name)?.[2]))),r=1;return[...t].filter(e=>e.renamable).sort(nx).map(t=>{for(;n.has(r);)r++;return{from:t.name,to:`${e}${r++}`}})}function ix(e){let t=new Map;for(let n of e){let e=tx.exec(n.name)?.[1];e!==void 0&&t.set(e,[...t.get(e)??[],n])}let n=[...t].flatMap(([e,t])=>rx(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 ax={sch:.5,pcb:2.54},ox=new Set([`name`,`pinLabels`]),sx=new Set([`from`,`to`,`schematicRouteHints`]),cx=/(pin\d+)\s*:\s*["']([A-Za-z_][\w]*)["']/g;function lx(e){if(!e)return;let t=Object.fromEntries([...e.matchAll(cx)].map(e=>[e[1],e[2]]));return Object.keys(t).length>0?t:void 0}function ux(e){let t=e===void 0?void 0:Bt(e);return t?t.kind===`net`?void 0:t.part:null}var dx=e=>e.slice(0,e.lastIndexOf(`/`)+1);function fx(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))ox.has(e)||(r.literal===void 0?o.push(`${t.name}.${e}`):n[e]=r.literal);let r=lx(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=[ux(e.from),ux(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])=>sx.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:dx(n),anchor:mx(s)}}var px=(e,t)=>t===void 0?void 0:e.startsWith(`pcb`)?jh(t):typeof t==`number`?t:void 0;function mx(e){let t=(t,n)=>{let r=e.flatMap(e=>{let[r,i]=[px(t,e.props[t]),px(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 hx=/^([A-Za-z_]+?)(\d+)$/;function gx(e,t){let n=new Set(t),r=new Map;for(let t of e){let e=hx.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 _x=e=>Math.round(e*1e4)/1e4+0;function vx(e,t,n){let r=e=>({x:e*n,y:-e*n}),i={sch:r(ax.sch),pcb:r(ax.pcb)},a=t?e.anchor[t.view]:void 0;return!t||!a?i:{...i,[t.view]:{x:_x(t.at.x-a.x),y:_x(t.at.y-a.y)}}}function yx(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=px(e,t);return i===void 0?t:_x(i+r)}function bx(e,t){let n=Bt(e);return n?.kind===`pin`?`${t.get(n.part)??n.part}.${n.pin}`:e}function xx(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`}:dx(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 Sx(e,t,n={}){let r=[...t.parts.map(e=>e.name),...t.drawings.flatMap(e=>[e.id,e.name??``]),...n.taken??[]],i=gx(e.parts.map(e=>e.name),r),a=n.page,o=a===void 0||a===`Main`?{}:{page:a},s=n.shift??vx(e,void 0,1),c=[];for(let r of e.parts){let a=xx(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,yx(e,t,s)])),...r.pinLabels?{pinLabels:r.pinLabels}:{},...a?{importFrom:a}:{},...o})}let l=e.traces.map(e=>({kind:`addTrace`,from:bx(e.from,i),to:bx(e.to,i),...Object.keys(e.props).length>0?{props:e.props}:{},...e.hints?{schematicRouteHints:e.hints.map(e=>({x:_x(e.x+s.sch.x),y:_x(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 Cx={};function wx(e,t){t?Cx[e]=t:delete Cx[e]}function Tx(e){return Cx[e]}var Ex=e=>new Set(e?.annotations.locks.filter(e=>!e.drawing).map(e=>e.part));function Dx(e,t){if(`message`in t)return e.notify(t.message);e.edit(t.edits,t.summary)}function Ox({design:e,circuit:t,selection:n,actions:r}){e&&t&&Dx(r,Yb(n.names,e.pcb.parts,t.model.parts,Ex(t)))}function kx({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)));Dx(r,Qb(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,Ex(t)))}function Ax({design:e,circuit:t,actions:n}){if(!e||!t)return;let r=Ex(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=ix([...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 jx,Mx=0;function Nx({circuit:e,selection:t,actions:n}){if(!e)return;let r=fx(e.model,t.names,e.file);if(`message`in r)return n.notify(r.message);jx=r,Mx=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 Px({design:e,circuit:t,select:n,actions:r},i,a){if(!t)return;if(!jx)return r.notify(`Copy some parts first (Ctrl+C).`);let o=Tx(a),s=vx(jx,o?{view:a,at:o}:void 0,Mx+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=Sx(jx,t.model,{file:t.file,...i?{page:i}:{},taken:l,shift:s});if(`message`in u)return r.notify(u.message);Mx+=1;let{edits:d,summary:f,names:p}=u;r.edit(d,f).then(e=>{e&&(n(()=>Xi.none.all(p)),r.notify(`Pasted ${p.join(`, `)}`))})}function Fx({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=ex({parts:n.names,drawings:n.drawings,board:n.board},a,e.schematic.drawings,o);if(`message`in s)return i.notify(s.message);r(()=>Xi.none.all(s.parts).addDrawings(s.drawings).addBoard(s.board??[])),i.notify(s.note)}var Ix=new Set([...Ey,...Dy]),Lx=new Set([...Oy,...Ay,...ky]),Rx=e=>Ix.has(e)?`schematic`:Lx.has(e)?`pcb`:void 0,zx=Ty;function Bx(e,t){if(`message`in t)return e.actions.notify(t.message);e.actions.route(t)}function Vx(e,t){if(`message`in t)return e.actions.notify(t.message);e.actions.autoplace(t)}function Hx(e){let t=new Set(e.circuit?.annotations.locks.filter(e=>!e.drawing).map(e=>e.part)),n=bb(e.design,e.selection.copper,t);if(`message`in n)return e.actions.notify(n.message);e.actions.unroute(n.ids)}function Ux(e,t){let{design:n,page:r,actions:i,openPage:a}=e;Db(t,{design:n,page:r,edit:i.edit,notify:i.notify,ask:(e,t)=>window.prompt(e,t),openPage:a})}function Wx(e,t){e&&(t.notify(`Exporting the BOM and datasheets…`),R(`/api/package`,{file:e}).then(e=>t.notify(`Exported ${e.files.length} files to ${e.outDir}`)).catch(e=>t.notify(e.message)))}function Gx(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=Hb(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(!Ub(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 Kx(e){if(e.file){if(N_(e.checkCounts))return e.openDialog(`exportChecks`);qx(e.file,e.actions)}}function qx(e,t){e&&(t.notify(`Writing the fabrication files…`),R(`/api/export`,{file:e}).then(e=>t.notify(M_(e))).catch(e=>t.notify(e.message)))}function Jx(e,t){e&&R(`/api/bom?file=${encodeURIComponent(e)}`).then(n=>{let r=URL.createObjectURL(new Blob([T_(n)],{type:`text/csv`}));Object.assign(document.createElement(`a`),{href:r,download:E_(e)}).click(),URL.revokeObjectURL(r),t.notify(`Saved ${E_(e)}`)}).catch(e=>t.notify(e.message))}function Yx(e,t){let{copper:n}=e.selection;if(n.length>0&&e.copperRecords){let r=fv(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}Xx(e,t)}function Xx(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=iy(e.selection,n,t,r);if(`message`in i)return e.actions.notify(i.message);e.actions.lock(i.parts,t)}function Zx(e){let t=hn(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=>un(e.design,t)?.path??dn(e.design,t)?.outer??[]):t;e.select(e=>e.all([...new Set(n)]))}async function Qx(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=wy(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 $x(e){let t=fm(e.circuit?.model,e.selection.names);if(`message`in t)return e.actions.notify(t.message);e.openDialog(`makeSheet`)}function eS(e,t){let n=zx[t];return n?()=>e.workspace.run(n):{openFile:e.workspace.openPageTree,exportBom:()=>Jx(e.file,e.actions),exportPackage:()=>Wx(e.file,e.actions),exportFabrication:()=>Kx(e),undo:()=>void e.actions.undo(),redo:()=>void e.actions.redo(),selectAll:()=>e.select(ki(e.circuit?.model.parts.map(e=>e.name)??[],e.pickLayers,e.pickFilter,e.sheetWires,e.sheetLabels,e.sheetDrawings,e.pcbCopper)),selectInstance:()=>Zx(e),replicateLayout:()=>void Qx(e),makeSheet:()=>$x(e),find:e.openFind,checkDrc:e.openChecks,designRules:()=>e.openDialog(`rules`),autoplace:()=>Vx(e,{kind:`all`}),autoplaceSelection:()=>Vx(e,xb(e.design,e.selection.names)),autoplaceInstance:()=>Vx(e,Sb(e.design,e.selection.names)),fitBoard:()=>void e.actions.fitBoard(),autoroute:()=>Bx(e,{kind:`all`}),autorouteSelection:()=>Bx(e,vb(e.design,e.selection.names)),autorouteNet:()=>Bx(e,yb(e.highlight)),unroute:()=>Hx(e),lock:()=>Yx(e,!0),unlock:()=>Yx(e,!1),history:()=>e.workspace.openBottom(`log`),keys:()=>e.openDialog(`keys`),about:()=>e.openDialog(`about`),addPage:()=>Ux(e,`addPage`),renamePage:()=>Ux(e,`renamePage`),deletePage:()=>Ux(e,`deletePage`),themeLight:()=>e.workspace.setTheme(`light`),themeDark:()=>e.workspace.setTheme(`dark`),hoverLabels:e.workspace.toggleHoverLabels,pourSolid:()=>e.workspace.setPourFill(Pl.pourSolid),pourHatched:()=>e.workspace.setPourFill(Pl.pourHatched),pourOutline:()=>e.workspace.setPourFill(Pl.pourOutline),findSimilar:()=>Fx(e),placementTransfer:()=>kx(e),flip:()=>Ox(e),annotate:()=>Ax(e),systemSettings:()=>e.openDialog(`system`),newCircuit:()=>e.openDialog(`newCircuit`),footprintManager:()=>e.openDialog(`footprints`),print:()=>Gx(e,!1),exportPdf:()=>Gx(e,!0),copy:()=>Nx(e),paste:()=>Px(e,e.view===`schematic`?e.page:void 0,e.view===`schematic`?`sch`:`pcb`)}[t]}var tS=[`undo`,`redo`,`openFile`,`selectAll`,`find`,`findSimilar`,`placementTransfer`,`flip`,`copy`,`paste`],nS=e=>tS.includes(e??``);function rS(e,t){(0,l.useEffect)(()=>{let n=n=>{let r=Ou(pu(n),{view:t})?.action;nS(r)&&(r!==`copy`||(window.getSelection()?.toString()??``)===``)&&(n.preventDefault(),e(r))};return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[e,t])}function iS(e){let[t,n]=(0,l.useState)(null),{file:r,view:i,setView:a,selection:o,select:s,circuit:c,actions:u,pickLayers:d,pickFilter:f,sheetWires:p,sheetLabels:m,sheetDrawings:h,pcbCopper:g,copperRecords:_,openChecks:v,checkCounts:y,openFind:b,openDialog:x,design:S,page:C,openPage:w,highlight:T}=e,{run:E,openBottom:ee,openPageTree:D,setTheme:O,toggleHoverLabels:k,setPourFill:A}=e.workspace;(0,l.useEffect)(()=>{if(!t||i!==t.view)return;let e=window.setTimeout(()=>{n(null),Ny(t.command)||u.notify(`The ${t.view===`pcb`?`PCB`:`schematic`} is still building; try again in a moment.`)},0);return()=>window.clearTimeout(e)},[t,i,u]);let j=(0,l.useCallback)(e=>{let t=eS({file:r,view:i,setView:a,selection:o,select:s,circuit:c,actions:u,pickLayers:d,pickFilter:f,sheetWires:p,sheetLabels:m,sheetDrawings:h,pcbCopper:g,copperRecords:_,workspace:{run:E,openBottom:ee,openPageTree:D,setTheme:O,toggleHoverLabels:k,setPourFill:A},openChecks:v,checkCounts:y,openFind:b,openDialog:x,design:S,page:C,openPage:w,highlight:T},e);if(t)return t();let l=Rx(e);l&&i!==l?(a(l),n({command:e,view:l})):Ny(e)||u.notify(`Wait for the build to finish, then try again.`)},[r,i,a,o,s,c,u,d,f,p,m,h,g,_,E,ee,D,O,k,A,v,y,b,x,S,C,w,T]);return rS(j,i),j}function aS({file:e,buildId:t,actions:n}){let[r,i]=(0,l.useState)([]),[a,o]=(0,l.useState)(!1);(0,l.useEffect)(()=>{R(`/api/bom?file=${encodeURIComponent(e)}`).then(i).catch(e=>n.notify(e.message))},[e,t,n]);let s=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:[s,` parts`]})]}),(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:a,onClick:()=>{o(!0),R(`/api/package`,{file:e}).then(e=>n.notify(`Exported ${e.files.length} files to ${e.outDir}`)).catch(e=>n.notify(e.message)).finally(()=>o(!1))},children:a?`Exporting`:`Export BOM and datasheets`})]})}var oS=`No problems found.`,sS=e=>e===`error`?0:1,cS=e=>e.startsWith(`net.`)||e.includes(`:`);function lS(e){return e.items.find(e=>!cS(e))?.split(/[#.]/,1)[0]||void 0}function uS(e,t){let n=lS(e);return n!==void 0&&t.has(n)?n:void 0}function dS(e,t,n,r){let i=e.items.filter(e=>n.has(e)),a=e.items.filter(e=>fS(r).has(e)),o=e.at??(e.view===`pcb`?a.map(e=>Dl(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=uS(e,t);return s===void 0?e:{...e,part:s}}function fS(e){let t=e.pcb;return new Set([...t?.board?.pours??[],...t?.holes??[]].map(e=>e.id))}function pS(e){let t=e.pcb;return new Set([...t?.tracks??[],...t?.vias??[]].map(e=>e.id))}function mS(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 hS=(e,t)=>({id:`diagnostic:${t}`,severity:e.severity,code:e.code,message:e.message,items:e.items,view:`code`}),gS=(e,t)=>e<t?`${e} ${t}`:`${t} ${e}`;function _S(e,t){if(t?.state!==`done`)return[];let n=new Map(e.pcb.ratsnest.map(e=>[gS(e.from,e.to),e]));return t.unrouted.flatMap(e=>{let t=n.get(gS(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 vS(e,t){let n=new Set(e.circuit.components.map(e=>e.id)),r=pS(e);return[...e.violations.map(mS),..._S(e,t),...e.diagnostics.map(hS)].map(t=>dS(t,n,r,e)).sort((e,t)=>sS(e.severity)-sS(t.severity))}function yS(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 bS(e,t){return e.flatMap(e=>e.view===t&&e.at?[{id:e.id,at:e.at,severity:e.severity}]:[])}function xS(e){let t=e.filter(e=>e.severity===`error`).length;return{errors:t,warnings:e.length-t}}var SS=(e,t)=>`${e} ${t}${e===1?``:`s`}`;function CS({errors:e,warnings:t}){let n=[...e>0?[SS(e,`error`)]:[],...t>0?[SS(t,`warning`)]:[]];return n.length===0?oS:n.join(`, `)}var wS=`.insp-body:not([hidden]) .insp-value input:not([disabled]):not([type="checkbox"])`,TS={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`]]},ES=[`pcbX`,`pcbY`,`pcbRotation`,`schX`,`schY`,`schRotation`,`side`,`layer`],DS=[`schNameAt`,`schValueAt`,`pcbNameAt`],OS=`footprint`;function kS(e,t){return OS in e.props?[`prop:${OS}`]:t.includes(OS)?[`suggest:${OS}`]:[]}var AS={label:`Placement`,value:`Placed by Studio`};function jS(e,t){let n=Object.keys(e.props).filter(e=>!ES.includes(e)&&!DS.includes(e)&&e!==OS),r=(TS[e.tag]??[]).map(([e])=>e).filter(t=>!(t in e.props)),i=r.filter(e=>e!==OS),a=ES.filter(t=>t in e.props),o=DS.filter(t=>t in e.props),s=kS(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 MS(){return[{title:`Build`,rows:[`build`]},{title:`Notes for the agent`,rows:[`notes`]}]}function NS(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 PS={parts:`Parts`,wires:`Wires`,labels:`Net labels and flags`,drawings:`Drawings`,copper:`Tracks and vias`,texts:`Names and values`,pours:`Copper pours and holes`},FS=/^kind:(parts|wires|labels|drawings|copper|texts|pours):(\d+)$/;function IS(e){let t=FS.exec(e);return t?{kind:t[1],count:Number(t[2])}:void 0}function LS(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:jS(l,t)}:{header:c,sections:[{title:`Selection`,rows:u}]}:{header:c,sections:MS()}}var RS=[{label:`Rotate`,command:`rotate`},{label:`Lock`,command:`lock`},{label:`Unlock`,command:`unlock`},{label:`Delete`,command:`delete`}];function zS(e,t,n,r=0){let i=t.map(e=>e.name);return e===`lock`||e===`unlock`?`parts`in gt(i,n.locked,e===`lock`,n.violated):e===`delete`&&r>0||t.some(e=>e.editable&&!n.locked.has(e.name))}function BS(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 VS({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 HS({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)(jp,{className:`insp-chevron`}),(0,X.jsx)(`span`,{className:`insp-title`,children:e})]}),(0,X.jsx)(`div`,{className:`insp-body`,hidden:!t,children:r})]})}function US({name:e,prop:t,disabled:n,onCommit:r,notify:i}){let a=t.literal===void 0?t.source:String(t.literal),[o,s]=(0,l.useState)(a);return(0,l.useEffect)(()=>s(a),[a]),t.editable?(0,X.jsx)(VS,{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=KS(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)(VS,{label:e,children:(0,X.jsx)(`code`,{className:`expr`,title:`An expression; change it in the code`,children:t.source.replace(/\s+/g,` `)})})}var WS=new Set([`pcbX`,`pcbY`,`pcbRotation`,`schX`,`schY`,`schRotation`,`pinCount`,`order`,`base`]);function GS({name:e,example:t,disabled:n,onCommit:r}){let[i,a]=(0,l.useState)(``);return(0,X.jsx)(VS,{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(WS.has(e)&&Number.isFinite(Number(t))?Number(t):t).then(e=>e&&a(``))},onKeyDown:e=>{e.key===`Enter`&&e.currentTarget.blur()}})})}function KS(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 qS({label:e,onAdd:t}){let[n,r]=(0,l.useState)(``),i=(0,l.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 JS={rotate:Dp,lock:Cp,unlock:wp,delete:Op};function YS({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=IS(e);if(t)return(0,X.jsx)(VS,{label:PS[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)(VS,{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)(Ap,{})})]}),(0,X.jsx)(`div`,{className:`inspector-actions`,children:RS.map(({label:e,command:a})=>{let o=JS[a];return(0,X.jsxs)(`button`,{className:a===`delete`?`danger`:void 0,disabled:!zS(a,t,r,n),onClick:()=>i(a),children:[(0,X.jsx)(o,{}),` `,e]},a)})}),e.sections.map(e=>(0,X.jsx)(HS,{title:e.title,open:!o.has(e.title),onToggle:()=>s(e.title),children:e.rows.map(u)},e.title))]})}function XS(){let e=null;return{answer(t){return e=t,()=>{e===t&&(e=null)}},send(t){return e?(e(t),!0):!1}}}var ZS=XS();function QS(e){let t=e;return{set(e){t=e},call:e=>t(e)}}var $S=`Label`;function eC({design:e,label:t,run:n,notify:r,onClear:i,collapsed:a,toggle:o}){let s=Lf(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)(Ap,{})})]}),(0,X.jsxs)(`div`,{className:`inspector-actions`,children:[(0,X.jsx)(`button`,{title:`Rename this label's net`,onClick:()=>{ZS.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)(HS,{title:$S,open:!a.has($S),onToggle:()=>o($S),children:s.rows.map(e=>(0,X.jsx)(VS,{label:e.label,children:(0,X.jsx)(`span`,{className:`static`,title:e.value,children:e.value})},e.label))})]}):null}var tC={path:`line`,rect:`rectangle`,circle:`circle`,arc:`arc`,text:`text`,bus:`bus`,junction:`junction`},nC=(e,t)=>({x:z(e.x+t.x),y:z(e.y+t.y)}),rC=e=>e.kind===`path`||e.kind===`bus`,iC=e=>rC(e)?[`points`]:[`x`,`y`],aC=(e,t)=>e.drawings.find(e=>e.id===t);function oC(e,t,n,r=[]){let i=aC(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 sC=(e,t,n)=>oC(e,t,n.id,iC(n));function cC(e){return e.kind===`path`||e.kind===`bus`?e.points[0]??{x:0,y:0}:{x:e.x,y:e.y}}function lC(e,t,n){let r=e.props[t]?.literal;return typeof r==`number`?r:z(n)}function uC(e,t,n){if(rC(t))return{points:(e.points??[]).map(e=>nC(e,n))};let{groupOffset:r}=t,i=cC(t);return{x:z(lC(e,`x`,i.x-r.x)+n.x),y:z(lC(e,`y`,i.y-r.y)+n.y)}}function dC(e,t){let{groupOffset:n}=e;return e.kind===`path`||e.kind===`bus`?`points`in t?{...e,points:t.points.map(e=>nC(e,n))}:e:`x`in t?{...e,x:z(t.x+n.x),y:z(t.y+n.y)}:e}function fC(e){return e.length>1?[`${e.length} drawings`]:e.map(e=>e.name??`the ${tC[e.kind]}`)}function pC(e,t,n,r,i){let a=t.find(e=>e.id===n),o=aC(e,n);if(!a)return{id:n,blocker:`${n} is not on the sheet`};let s=sC(e,i,a);return s||!o?{id:n,blocker:s??`${n} has no editable source element`}:{id:n,drawing:a,placed:uC(o,a,r)}}function mC(e,t,n,r,i){let a=n.map(n=>pC(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:fC(o.map(e=>e.drawing)),skipped:a.flatMap(e=>`blocker`in e?[e.blocker]:[]),shown:o.map(({drawing:e,placed:t})=>dC(e,t))}}function hC(e,t,n){return r=>{let i=r.map(t=>({id:t,blocker:oC(e,n,t)})),a=i.flatMap(e=>e.blocker??[]),o=i.flatMap(e=>e.blocker===null?[e.id]:[]),s=t=>aC(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:fC(l),skipped:a,removed:o}}}var gC=/^[A-Za-z_][A-Za-z0-9_]*$/,_C=/^G(\d+)$/;function vC(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(_C.exec(e)?.[1]??0)))+1}`}function yC(e,t,n,r){if(t===`bus`?Zt(n)===void 0:!gC.test(n))throw new um(`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 um(`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 um(`invalid`,`A drawing named ${n} already exists`)}function bC(e,t){if(typeof t==`string`&&t!==``)return e!==`bus`||Zt(t)!==void 0?t:void 0}function xC(e,t){return`drawing:${e}:${t}`}function SC(e,t){let n=2;for(;e.has(`${t}~${n}`);)n++;return`${t}~${n}`}function CC(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??xC(e,a);if(!n.has(o))return n.add(o),e===`bus`&&r.add(o),{id:o,base:o};let s=SC(n,o);return n.add(s),{id:s,base:o,repeat:e===`bus`&&r.has(o)?`piece`:`duplicate`}})}var wC=`Name the bus, such as D[0:7] or CLK`;function TC(e,t){return new Set([...e.parts.map(e=>e.name),...e.drawings.flatMap(e=>[e.id,e.name??``]),...t])}function EC(e,t=[]){let n=TC(e,t),r=1;for(;n.has(`BUS${r}`);)r++;return`BUS${r}`}function DC(e,t,n){let r=t.trim();if(r===``)return wC;try{yC(e,`bus`,r,n);return}catch(e){return e instanceof Error?e.message:String(e)}}function OC(e,t){return e.drawings.map(e=>{let n=Jt(e.tag)??`path`;return{kind:n,name:e.id===t?.id?t.name:bC(n,e.name)}})}var kC=(e,t,n)=>CC(t,e.parts.map(e=>e.name))[n]?.id??``;function AC(e,t,n=[]){let r=n.filter(e=>e===t).map(e=>({kind:`bus`,name:e})),i=[...OC(e),...r,{kind:`bus`,name:t}];return kC(e,i,i.length-1)}function jC(e,t,n){let r=e.drawings.findIndex(e=>e.id===t);return r<0?n:kC(e,OC(e,{id:t,name:n}),r)}function MC(e){let t=`${e.length} member${e.length===1?``:`s`}`;return`${e.length>2?`${e[0]} … ${e.at(-1)}`:e.join(`, `)}, ${t}`}var NC={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:qt},strokeWidth:{label:`Stroke width`,field:`number`,rule:`nonNegative`},lineStyle:{label:`Line style`,field:`choice`,options:Kt},color:{label:`Colour`,field:`color`},filled:{label:`Filled`,field:`check`}},PC=[`strokeWidth`,`lineStyle`,`color`],FC={path:[`points`,...PC],rect:[`x`,`y`,`width`,`height`,...PC,`filled`],circle:[`x`,`y`,`radius`,...PC,`filled`],arc:[`x`,`y`,`radius`,`startAngle`,`endAngle`,...PC],text:[`x`,`y`,`text`,`fontSize`,`anchor`,`color`],bus:[`points`],junction:[`x`,`y`,`color`]},IC={path:`Line`,rect:`Rectangle`,circle:`Circle`,arc:`Arc`,text:`Text`,bus:`Bus`,junction:`Junction`},LC=e=>e.map(e=>`${e.x}, ${e.y}`).join(`; `);function RC(e,t){let{groupOffset:n}=e;if((e.kind===`path`||e.kind===`bus`)&&t===`points`)return LC(e.points.map(e=>({x:z(e.x-n.x),y:z(e.y-n.y)})));let r=e[t];return t===`x`||t===`y`?String(z(r-n[t])):r===void 0?``:String(r)}function zC(e,t,n,r){let i=NC[n],a=t?.props[n],o=a!==void 0&&!a.editable,s=n===`color`?{placeholder:H().drawing}:{},c=i.options?{options:i.options}:{},l=o?a.source:RC(e,n);return{key:n,label:i.label,value:l,field:i.field,...c,...s,editable:r&&t!==void 0&&!o}}var BC=`Renames this piece of the bus only; its wires keep their nets`;function VC(e,t,n){return e.kind===`bus`?[{key:`name`,label:`Name`,value:e.name,field:`text`,editable:n&&t?.name!==void 0,hint:BC},{key:`members`,label:`Members`,value:MC(e.members),field:`static`,editable:!1}]:[{key:`name`,label:`Name`,value:e.name??`(none)`,field:`static`,editable:!1}]}function HC(e,t,n){let r=t?.line??e.source.line;return[{key:`kind`,label:`Kind`,value:`${IC[e.kind]}, line ${r}`,field:`static`,editable:!1},...VC(e,t,n),...FC[e.kind].map(r=>zC(e,t,r,n))]}var UC=/^#[0-9A-Fa-f]{6}$/,WC={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 GC(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:z(Number(e[0])),y:z(Number(e[1]))}:void 0);return t.length>=2&&t.every(e=>e!==void 0)?t:void 0}function KC(e,t){let n=t.trim();if(e.field===`number`){let t=WC[e.rule??`any`],r=Number(n);return n!==``&&Number.isFinite(r)&&t.ok(r)?r:{message:`${e.label} ${t.says}`}}return e.field===`points`?GC(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`?UC.test(n)?n:{message:`${e.label} must be a colour such as "#000080"`}:t===``?{message:`${e.label} cannot be empty`}:t}function qC(e,t,n){let r=t.trim(),i=DC(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 JC(e,t,n,r){if(t===`name`&&e.kind===`bus`&&r)return qC(e,n,r);let i=NC[t];if(!i)return{message:`${t} cannot be set here`};let a=KC(i,n);if(typeof a==`object`&&!Array.isArray(a))return a;let o=e.name??`the ${tC[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 YC=`Drawing`;function XC({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=oC(t.model,r,n),f=HC(u,aC(t.model,n),d===null),p=(e,r)=>{let o=JC(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:jC(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)(Ap,{})})]}),(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)(Op,{}),` Delete`]})}),d&&(0,X.jsxs)(`p`,{className:`note`,children:[d,`.`]}),(0,X.jsx)(HS,{title:YC,open:!c.has(YC),onToggle:()=>l(YC),children:f.map(e=>(0,X.jsx)(ZC,{row:e,onCommit:t=>p(e.key,t)},`${u.id}:${e.key}`))})]})}function ZC({row:e,onCommit:t}){let n=(0,l.useId)();return e.field===`static`||!e.editable?(0,X.jsx)(VS,{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)(VS,{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)(VS,{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)(QC,{id:n,row:e,onCommit:t})}function QC({id:e,row:t,onCommit:n}){let[r,i]=(0,l.useState)(t.value);return(0,l.useEffect)(()=>i(t.value),[t.value]),(0,X.jsx)(VS,{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 $C={top:`Top Layer`,bottom:`Bottom Layer`,inner1:`Inner Layer 1`,inner2:`Inner Layer 2`},ew={human:`You`,agent:`The agent`,router:`The router`},tw=e=>`${Math.round(e*1e3)/1e3} mm`;function nw(e,t){return t===void 0?`No net`:e.circuit.nets.find(e=>e.id===t)?.names[0]??t}function rw(e,t){return[{label:`Net`,value:nw(e,t.net)},{label:`Layer`,value:t.layer,field:`layer`},{label:`Width`,value:String(t.width),field:`width`},{label:`Length`,value:tw(pb(t.points))},{label:`Drawn by`,value:ew[t.by]},{label:`Locked`,value:String(t.locked),field:`lock`}]}function iw(e,t){let[n=`top`,r=`bottom`]=[t.layers[0],t.layers.at(-1)];return[{label:`Net`,value:nw(e,t.net)},{label:`Layers`,value:`${$C[n]} to ${$C[r]}`},{label:`Drill`,value:tw(t.drill)},{label:`Diameter`,value:tw(t.diameter)},{label:`Drawn by`,value:ew[t.by]},{label:`Locked`,value:String(t.locked),field:`lock`}]}function aw(e,t){let n=e.pcb.tracks.find(e=>e.id===t);if(n)return{kind:`track`,title:`Track`,locked:n.locked,rows:rw(e,n)};let r=e.pcb.vias.find(e=>e.id===t);return r&&{kind:`via`,title:`Via`,locked:r.locked,rows:iw(e,r)}}var ow=e=>`(${Math.round(e.x*1e3)/1e3}, ${Math.round(e.y*1e3)/1e3}) mm`;function sw(e,t){let n=e.pcb.tracks.find(e=>e.id===t.id);if(!n||!X_(n.points,t.index)||!qi(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:nw(e,n.net)},{label:`Track`,value:n.id},{label:`Length`,value:tw(pb([r,i]))},{label:`Start`,value:ow(r)},{label:`End`,value:ow(i)}]}}function cw(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 lw(e,t,n){if(t===`lock`)return cw(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 uw=[{value:`top`,label:`Top Layer`},{value:`bottom`,label:`Bottom Layer`}];function dw({design:e,id:t,segment:n,actions:r,run:i,onClear:a,collapsed:o,toggle:s}){let c=n?.id===t?sw(e,n):void 0;if(c)return(0,X.jsx)(fw,{shown:c,id:t,run:i,onClear:a,collapsed:o,toggle:s});let l=aw(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=lw(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)(Ap,{})})]}),(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)(Op,{}),` Delete`]})}),(0,X.jsx)(HS,{title:l.title,open:!o.has(l.title),onToggle:()=>s(l.title),children:l.rows.map(e=>(0,X.jsx)(pw,{row:e,locked:l.locked,onCommit:d},e.label))})]})}function fw({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)(Ap,{})})]}),(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)(Op,{}),` Delete segment`]})}),(0,X.jsx)(HS,{title:e.title,open:!i.has(e.title),onToggle:()=>a(e.title),children:e.rows.map(e=>(0,X.jsx)(VS,{label:e.label,children:(0,X.jsx)(`span`,{className:`static`,title:e.value,children:e.value})},e.label))})]})}function pw({row:e,locked:t,onCommit:n}){let r=(0,l.useId)();return e.field===`lock`?(0,X.jsx)(VS,{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)(VS,{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:[uw.map(e=>(0,X.jsx)(`option`,{value:e.value,children:e.label},e.value)),!uw.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)(mw,{id:r,value:e.value,locked:t,onCommit:e=>n(`width`,e)}):(0,X.jsx)(VS,{label:e.label,children:(0,X.jsx)(`span`,{className:`static`,title:e.value,children:e.value})})}function mw({id:e,value:t,locked:n,onCommit:r}){let[i,a]=(0,l.useState)(t);return(0,l.useEffect)(()=>a(t),[t]),(0,X.jsx)(VS,{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 hw({design:e,circuit:t,id:n,locks:r,actions:i,run:a,onClear:o,collapsed:s,toggle:c}){let l=Qv(e,n);if(!l)return null;let u=zv(t.model,r.locked,n),d=ry(n,r),f=async(t,r)=>{let a=ny(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)(Ap,{})})]}),(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)(Cp,{}):(0,X.jsx)(wp,{}),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)(Op,{}),` Delete`]})]}),(0,X.jsx)(HS,{title:l.title,open:!s.has(l.title),onToggle:()=>c(l.title),children:l.rows.map(e=>(0,X.jsx)(gw,{row:e,disabled:u!==null,onCommit:f},e.label))})]})}function gw({row:e,disabled:t,onCommit:n}){let r=(0,l.useId)(),{field:i,choices:a}=e;return!i||t?(0,X.jsx)(VS,{label:e.label,children:(0,X.jsx)(`span`,{className:`static`,title:e.value,children:e.value===``?`Net class`:e.value})}):a?(0,X.jsx)(VS,{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)(_w,{id:r,row:e,field:i,onCommit:n})}function _w({id:e,row:t,field:n,onCommit:r}){let[i,a]=(0,l.useState)(t.value);return(0,l.useEffect)(()=>a(t.value),[t.value]),(0,X.jsx)(VS,{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 vw=.001,yw=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 bw(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)<=vw)return{segment:n-1,t:c}}}var xw=(e,t)=>t.some(t=>bw(e,t)!==void 0);function Sw(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 Cw=e=>Math.round(e*1e3)/1e3;function ww(e,t,n,r){return n.length<2?[]:e.flatMap(e=>{let i=bw(e,t);if(i===void 0||xw(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)}:Sw(e,n),l={x:Cw(c.x),y:Cw(c.y)};return Math.abs(l.x-e.x)<vw&&Math.abs(l.y-e.y)<vw?[]:[{kind:`setDrawingProps`,id:e.id,props:l}]})}function Tw(e,t,n){return e.filter(e=>xw(e,t)&&!xw(e,n)).map(e=>e.id)}var Ew=`This wire is no longer on the sheet`,Dw=`This wire has no corners`,Ow=`Studio draws this wire's corner; the code has none to remove`,kw=`This wire repeats another between the same ends; delete it in the code`;function Aw(e,t){let n=e.schematic.wires.find(e=>e.id===t);return n&&$d(e.circuit.nets,n.net)}function jw(e,t){let n=Aw(e,t),r=e.circuit.nets.find(e=>e.id===n);return r?Cf(r):(n??``).replace(/^net\./,``)}var Mw=(e,t)=>`This wire has no trace of its own: Studio draws it for net ${jw(e,t)}`,Nw=e=>e.startsWith(`net.`)?`net ${e.slice(4)}`:e;function Pw(e,t){let{writer:n}=t;if(n.kind===`engine`)return[Mn(e,n.from)?.id??Nw(n.from),Mn(e,n.to)?.id??Nw(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?[Nw(i.from),Nw(i.to)]:void 0}function Fw(e,t){let n=Pw(e,t);return n?`the wire from ${n[0]} to ${n[1]}`:`the wire`}function Iw(e,t,n){let{writer:r}=t;if(r.kind===`none`)return r.reason;if(r.kind===`engine`)return Mw(e,t.id);let i=hr(e,r.components,r.trace,n);return i===void 0?r.repeat?kw:r.trace.editable?null:`This wire is read-only (${r.trace.readonlyReason}); delete it in the code`:`${i} is locked`}function Lw(e,t,n){if(t.writer.kind!==`trace`)return Iw(e,t,n);if(t.points.length<=2)return Dw;let r=lc(e,t,n);return r===null?(t.writer.trace.schematicRouteHints?.length??0)>0?null:Ow:r}function Rw(e){let t=e.writer.kind===`trace`?e.writer.trace:void 0;return{from:t?.from??``,to:t?.to??``}}function zw(e,t,n){let r=Iw(e,t,n);return r===null?{edits:[{kind:`removeTrace`,...Rw(t)}],summary:`remove ${Fw(e,t)}`}:{blocked:r}}function Bw(e,t,n){let r=Lw(e,t,n);return r===null?{edits:[{kind:`setTraceHints`,...Rw(t),schematicRouteHints:[]}],summary:`remove the corners of ${Fw(e,t)}`}:{blocked:r}}var Vw=e=>`blocked`in e?e.blocked:null;function Hw(e,t,n){return{remove:Vw(zw(e,t,n)),removeCorners:Vw(Bw(e,t,n))}}function Uw(e,t,n){let r=t?Fw(e,t):`the wire`,i=r.charAt(0).toUpperCase()+r.slice(1);return n.startsWith(`This wire`)?`${i}${n.slice(9)}`:`${i}: ${n}`}function Ww(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 Gw(e,t,n,r,i){let a=cc(e,t,n);if(a&&Ww(e,a).some(e=>r.has(e)))return{id:n,kind:`withParts`};let o=a?zw(e,a,i):{blocked:Ew};return`blocked`in o?{id:n,kind:`skipped`,reason:o.blocked,named:Uw(e,a,o.blocked),studio:a?.writer.kind===`engine`}:{id:n,kind:`removed`,edits:o.edits,name:a?Fw(e,a):`the wire`}}var Kw=e=>`${e} wires have no trace of their own: Studio draws them for their nets`;function qw(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?[Kw(r.length)]:r.map(e=>e.named)]}function Jw(e,t,n,r,i=ur,a=new Set){let o=n.map(n=>Gw(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:qw(o,a),junctions:Tw(yw(e.schematic.drawings),u(!1),u(!0))}}function Yw(e,t,n,r=ur){let i=cc(e,t,n);return i?Bw(e,i,r):{blocked:Ew}}function Xw(e,t,n,r=ur){let i=cc(e,t,n);return i?Hw(e,i,r):{remove:Ew,removeCorners:Ew}}function Zw(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 Qw(e,t,n,r=ur){let i=cc(e,t,n);if(!i)return;let[a,o]=Pw(e,i)??[`unknown`,`unknown`],s=[{label:`Net`,value:jw(e,n)},{label:`From`,value:a},{label:`To`,value:o},{label:`Corners`,value:String(Math.max(0,i.points.length-2))},{label:`Kind`,value:Zw(i)}];return{net:Aw(e,n),rows:s,...Hw(e,i,r)}}var $w=`Wire`;function eT({design:e,circuit:t,wire:n,locked:r,run:i,onClear:a,collapsed:o,toggle:s}){let c=Qw(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)(Ap,{})})]}),(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)(Op,{}),` Delete`]})]}),c.remove&&(0,X.jsxs)(`p`,{className:`note`,children:[c.remove,`.`]}),(0,X.jsx)(HS,{title:$w,open:!o.has($w),onToggle:()=>s($w),children:c.rows.map(e=>(0,X.jsx)(VS,{label:e.label,children:(0,X.jsx)(`span`,{className:`static`,title:e.value,children:e.value})},e.label))})]}):null}function tT({design:e,circuit:t,text:n,locked:r,actions:i,onClear:a,collapsed:o,toggle:s}){let c=od(e,t,n,r);if(!c)return null;let l=td(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)(Ap,{})})]}),(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(Qu(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)(HS,{title:c.title,open:!o.has(c.title),onToggle:()=>s(c.title),children:c.rows.map(e=>(0,X.jsx)(VS,{label:e.label,children:(0,X.jsx)(`span`,{className:`static`,title:e.value,children:e.value})},e.label))})]})}function nT({id:e,verified:t,actions:n}){let[r,i]=(0,l.useState)();if((0,l.useEffect)(()=>{R(`/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(`
|
|
16
|
-
`).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)(`p`,{className:`note ok`,children:[`Verified by `,a.verified?.by,` against `,a.verified?.against,`.`]}):(0,X.jsx)(rT,{id:e,checklist:o,actions:n})]})}function rT({id:e,checklist:t,actions:n}){let[r,i]=(0,l.useState)(``),[a,o]=(0,l.useState)(``),[s,c]=(0,l.useState)(``);return(0,X.jsxs)(`form`,{className:`verify`,onSubmit:t=>{t.preventDefault(),n.verify(e,r.trim(),a.trim(),s)},children:[(0,X.jsx)(`p`,{className:`note warn`,children:`Not verified. Check each item against the datasheet:`}),(0,X.jsx)(`ul`,{className:`checklist`,children:t.map(e=>(0,X.jsx)(`li`,{children:e.replace(/^- \[ \] /,``)},e))}),(0,X.jsxs)(`label`,{children:[`Checked against`,(0,X.jsx)(`input`,{value:a,onChange:e=>o(e.target.value),placeholder:`Datasheet, revision, page`,required:!0})]}),(0,X.jsxs)(`label`,{children:[`Your name`,(0,X.jsx)(`input`,{"aria-label":`Your name`,value:r,onChange:e=>i(e.target.value),required:!0})]}),(0,X.jsxs)(`label`,{children:[`Type `,e,` to confirm`,(0,X.jsx)(`input`,{"aria-label":`Type ${e} to confirm`,value:s,onChange:e=>c(e.target.value),spellCheck:!1,required:!0})]}),(0,X.jsx)(`button`,{type:`submit`,className:`primary`,disabled:s.trim()!==e||!r.trim()||!a.trim(),children:`Mark verified`})]})}function iT({id:e,value:t,disabled:n,placeholder:r,onCommit:i}){let[a,o]=(0,l.useState)(t);return(0,l.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 aT({design:e,name:t,editable:n,actions:r,onOpenSheet:i,collapsed:a,toggle:o}){let s=un(e,t),c=(0,l.useId)();if(!s)return null;let u=(e,n)=>{let i=n===``?void 0:sn(s.sheet,e,n,s.ports.find(t=>t.name===e)?.bus===!0);return i===void 0?r.edit([{kind:`setConnections`,part:t,connections:gn(s,e,n)}],`Connect ${t}.${e} to ${n===``?`nothing`:n}`):(r.notify(i),Promise.resolve(!1))};return(0,X.jsxs)(HS,{title:`Sub-sheet`,open:!a.has(`Sub-sheet`),onToggle:()=>o(`Sub-sheet`),children:[(0,X.jsx)(VS,{label:`Sheet`,children:(0,X.jsx)(`span`,{className:`static`,children:mn(s.sheet,pn(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]})}),s.ports.map(e=>(0,X.jsx)(VS,{label:`${e.name}${e.bus?` (bus)`:``}`,htmlFor:`${c}-${e.name}`,children:(0,X.jsx)(iT,{id:`${c}-${e.name}`,value:s.connections[e.name]??``,placeholder:`not connected`,disabled:!n,onCommit:t=>u(e.name,t)})},e.name)),(0,X.jsx)(VS,{label:`base`,htmlFor:`${c}-base`,children:(0,X.jsx)(iT,{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 oT({design:e,part:t,onSelect:n,onOpenSheet:r}){let i=dn(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,`). `,mn(i.sheet,pn(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(fn(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 sT({file:e,parentDesign:t}){let n=t?pn(t,e):void 0;return(0,X.jsxs)(`p`,{className:`note`,children:[mn(Qe(e),n),`.`]})}function cT({part:e,editable:t,actions:n,collapsed:r,toggle:i}){let a=(0,l.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)(HS,{title:`Port`,open:!r.has(`Port`),onToggle:()=>i(`Port`),children:[(0,X.jsx)(VS,{label:`Name`,htmlFor:`${a}-name`,children:(0,X.jsx)(iT,{id:`${a}-name`,value:e.name,disabled:!t,onCommit:s})}),(0,X.jsx)(VS,{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 lT({parts:e,onPlace:t,onImport:n,onNewPart:r,focus:i,onFocused:a}){let[o,s]=(0,l.useState)(``),c=(0,l.useRef)(null);(0,l.useEffect)(()=>{i&&(c.current?.focus(),a())},[i,a]);let u=o.trim().toLowerCase(),d=(...e)=>u===``||e.some(e=>e?.toLowerCase().includes(u)),f=e.library.filter(e=>d(e.id,e.title,e.mpn,e.footprint)),p=e.builtin.filter(e=>d(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:f.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:rm(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:p.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 uT({design:e,highlight:t,onHighlight:n}){let r=(0,l.useMemo)(()=>e?wf(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)?ef:[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}),(0,X.jsx)(`span`,{className:`value`,children:e.pins===1?`1 pin`:`${e.pins} pins`})]})},e.id))})}var dT=`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.`,fT=e=>e.map(e=>e.trim()).filter(e=>e!==``).map(e=>e.replace(/^[-*]\s+/,``));function pT(e){if(e==null)return{kind:`missing`,note:dT};let t=e.replace(/\r\n/g,`
|
|
17
|
-
`).split(`
|
|
18
|
-
`),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:fT(i.body)}),i={title:(t[1]??``).trim(),body:[]}):i&&i.body.push(e)}return i&&r.push({title:i.title,lines:fT(i.body)}),{kind:`file`,title:n,sections:r}}function mT(){let[e,t]=(0,l.useState)(void 0),[n,r]=(0,l.useState)(),i=(0,l.useCallback)(()=>{R(`/api/project-memory`).then(e=>{t(e.text),r(void 0)}).catch(e=>r(e.message))},[]);if((0,l.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=pT(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 hT({tree:e,onOpen:t,focus:n,onFocused:r}){let i=(0,l.useRef)(null);return(0,l.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 gT=e=>`${e}-panel`,_T=e=>`side-tab-${e}`;function vT({side:e,tabs:t,active:n,open:r,onClick:i,onSelect:a}){let o=sp({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:_T(t.id),"aria-controls":gT(e),"aria-selected":i,className:`side-tab${i?` on`:``}`,...o.tab(t.id),children:t.label},t.id)})})}var yT={page:`Page`,net:`Net`,component:`Component`,object:`Object`,project:`Project`},bT=Object.keys(yT),xT=`design-panel`;function ST({sub:e,onSub:t}){let n=sp({ids:bT,current:e,onSelect:t});return(0,X.jsx)(`div`,{className:`sub-tabs hairline-b`,role:`tablist`,"aria-label":`Project Design`,onKeyDown:n.onKeyDown,children:bT.map(t=>(0,X.jsx)(`button`,{role:`tab`,id:`sub-tab-${t}`,"aria-controls":xT,"aria-selected":e===t,className:`sub-tab${e===t?` on`:``}`,...n.tab(t),children:yT[t]},t))})}function CT(e){let{left:t,onSub:n}=e,r=t.strip===`design`;return(0,X.jsxs)(`aside`,{className:`panel left hairline-r`,id:gT(`left`),role:`tabpanel`,"aria-labelledby":_T(t.strip),hidden:e.hidden,onClick:rp,children:[r&&(0,X.jsx)(ST,{sub:t.sub,onSub:n}),(0,X.jsxs)(`div`,{className:`panel-body`,...r?{id:xT,role:`tabpanel`,"aria-labelledby":`sub-tab-${t.sub}`}:{},children:[!r&&(0,X.jsx)(lT,{parts:e.parts,onPlace:e.onPlace,onImport:e.onImport,onNewPart:e.onNewPart,focus:e.focusSearch,onFocused:e.onSearchFocused}),r&&(0,X.jsx)(wT,{...e})]})]})}function wT(e){switch(e.left.sub){case`page`:return(0,X.jsx)(hT,{tree:e.pageTree,onOpen:e.onOpenDocument,focus:e.focusPage,onFocused:e.onPageFocused});case`net`:return(0,X.jsx)(uT,{design:e.design,highlight:e.highlight,onHighlight:e.onHighlight});case`component`:return(0,X.jsx)(TT,{...e});case`object`:return(0,X.jsx)(DT,{...e});case`project`:return(0,X.jsx)(mT,{})}}function TT({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($i(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:ET(e.props)}),i.has(e.name)&&(0,X.jsx)(`span`,{className:`placed-dot`,role:`img`,"aria-label":AS.value,title:AS.value}),a.has(e.name)&&(0,X.jsx)(Cp,{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 ET(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 DT({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=>kT(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)(Ap,{})})]},`${e.from}-${e.to}-${r}`))}),(0,X.jsx)(OT,{actions:n})]})}function OT({actions:e}){let[t,n]=(0,l.useState)(``),[r,i]=(0,l.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 kT(e,t){return t?[e.from,e.to].some(e=>e!==void 0&&cm(e).includes(t)):!1}function AT(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 jT(e,t,n){(0,l.useEffect)(()=>{t&&(e.current?.querySelector(wS)?.focus(),n())},[e,t,n])}function MT(e){let t=(0,l.useRef)(null);jT(t,e.focusField,e.onFieldFocused);let n=AT(e.circuit,e.selection),[r]=n,i=n.length===1&&e.selection.size===0,{wireCount:a,labelCount:o,drawingCount:s,copperCount:c,soleWire:u,soleLabel:d,soleDrawing:f,soleCopper:p,soleText:m,textCount:h,boardCount:g,soleBoard:_}=e.selection,[v,y]=i?[0,0]:[a,o],b=NS(n.length,v,y,s,c,h,g),x=n.length===0&&e.selection.size===1&&e.selection.primary!==void 0?dn(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&&Ge(e.build.design,e.openView).has(r.name),w=LS(n,{library:S!==void 0,autoPlaced:C},v,y,s,c,h,g),T={locked:new Set(e.circuit.annotations.locks.map(e=>e.part)),violated:new Set(e.circuit.violations.map(e=>e.part))},[E,ee]=(0,l.useState)(new Set),D=e=>ee(t=>{let n=new Set(t);return n.delete(e)||n.add(e),n}),O=()=>e.onSelect(e=>e.clear()),k=e.build.design;return(0,X.jsxs)(`aside`,{ref:t,className:`panel right`,id:e.hidden?void 0:gT(`right`),role:`tabpanel`,"aria-labelledby":_T(`properties`),hidden:e.hidden,children:[b===`wire`&&u!==void 0&&k&&(0,X.jsx)(eT,{design:k,circuit:e.circuit,wire:u,locked:T.locked,run:e.run,onClear:O,collapsed:E,toggle:D}),b===`label`&&d!==void 0&&k&&(0,X.jsx)(eC,{design:k,label:d,run:e.run,notify:e.actions.notify,onClear:O,collapsed:E,toggle:D}),b===`drawing`&&f!==void 0&&k&&(0,X.jsx)(XC,{design:k,circuit:e.circuit,drawing:f,locked:T.locked,actions:e.actions,onRename:e.onRenameDrawing,run:e.run,onClear:O,collapsed:E,toggle:D}),b===`text`&&m!==void 0&&k&&(0,X.jsx)(tT,{design:k,circuit:e.circuit,text:m,locked:T.locked,actions:e.actions,onClear:O,collapsed:E,toggle:D}),b===`copper`&&p!==void 0&&k&&(0,X.jsx)(dw,{design:k,id:p,segment:e.selection.segment,actions:e.actions,run:e.run,onClear:O,collapsed:E,toggle:D}),b===`pour`&&_!==void 0&&k&&(0,X.jsx)(hw,{design:k,circuit:e.circuit,id:_,locks:T,actions:e.actions,run:e.run,onClear:O,collapsed:E,toggle:D}),b===`group`&&(0,X.jsx)(YS,{view:w,parts:n,others:v+y+s+c+g,locks:T,run:e.run,onClear:O,collapsed:E,toggle:D}),b===`part`&&r&&(0,X.jsx)(PT,{...e,view:w,collapsed:E,toggle:D,part:r,locks:T}),x&&k&&(0,X.jsx)(oT,{design:k,part:x.part,onSelect:e.onSelect,onOpenSheet:e.onOpenSheet}),b===`board`&&!x&&(0,X.jsx)(RT,{...e,view:w,collapsed:E,toggle:D})]})}function NT(e,t){let n=e&&Td(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 PT({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=>kT(e,r.name)),v=e=>{let[n,i=``]=e.split(`:`),o=r.props[i];if(n===`name`)return(0,X.jsx)(VS,{label:`Name`,children:(0,X.jsx)(`span`,{className:`static`,children:r.name})},e);if(n===`kind`)return(0,X.jsx)(VS,{label:`Kind`,children:(0,X.jsxs)(`span`,{className:`static`,children:[r.tag,`, line `,r.line]})},e);if(n===`placed`)return(0,X.jsx)(VS,{label:AS.label,children:(0,X.jsx)(`span`,{className:`static`,children:AS.value})},e);if(n===`prop`&&o)return(0,X.jsx)(US,{name:i,prop:o,disabled:!g,onCommit:e=>h(i,e),notify:a.notify},e);if(n===`suggest`){let t=TS[r.tag]?.find(([e])=>e===i)?.[1]??``;return(0,X.jsx)(GS,{name:i,example:t,disabled:!g,onCommit:e=>h(i,e)},e)}return n===`textAt`&&o?(0,X.jsx)(VS,{label:`${Bu[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)(IT,{locked:p,onChange:e=>s(e?`lock`:`unlock`)},e):n===`connections`?(0,X.jsx)(LT,{traces:_},e):n===`library`?m&&(0,X.jsx)(nT,{id:m.id,verified:m.verified,actions:a},e):(0,X.jsx)(qS,{label:`Note for the agent about ${r.name}`,onAdd:e=>{let n=NT(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)(Ap,{})})]}),(0,X.jsx)(FT,{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.`]}),Ze(e.file)&&(0,X.jsx)(sT,{file:e.file,parentDesign:f}),r.tag===`port`&&Ze(e.file)&&(0,X.jsx)(cT,{part:r,editable:g,actions:a,collapsed:l,toggle:u}),t.design&&un(t.design,r.name)&&(0,X.jsx)(aT,{design:t.design,name:r.name,editable:g,actions:a,onOpenSheet:d,collapsed:l,toggle:u}),c.sections.map(e=>(0,X.jsx)(HS,{title:e.title,open:!l.has(e.title),onToggle:()=>u(e.title),children:e.rows.map(v)},e.title))]})}function FT({part:e,locks:t,run:n}){let r=BS(e.name,t),i=n=>zS(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)(Cp,{}):(0,X.jsx)(wp,{}),r.label]}),(0,X.jsxs)(`button`,{disabled:!i(`rotate`),onClick:()=>n(`rotate`),children:[(0,X.jsx)(Dp,{}),` Rotate`]}),(0,X.jsxs)(`button`,{className:`danger`,disabled:!i(`delete`),onClick:()=>n(`delete`),children:[(0,X.jsx)(Op,{}),` Remove`]})]})}function IT({locked:e,onChange:t}){let n=(0,l.useId)();return(0,X.jsx)(VS,{label:`Locked`,htmlFor:n,children:(0,X.jsx)(`input`,{id:n,type:`checkbox`,checked:e,onChange:e=>t(e.target.checked)})})}function LT({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 RT({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)(zT,{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)(Ap,{})})]},e.id))}),(0,X.jsx)(qS,{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)(HS,{title:e.title,open:!o.has(e.title),onToggle:()=>s(e.title),children:e.rows.map(c)},e.title)),(0,X.jsx)(aS,{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 zT({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:CS(e)}),e.errors+e.warnings>0&&(0,X.jsx)(`button`,{onClick:t,title:`DRC (\\)`,children:`Show checks`})]})}var BT=12,VT=32,HT={minor:B.grid,fifth:B.gridFifth},UT={lines:HT,dots:{...HT,px:1}};function WT(e,t,n,r,i){$m(e,t,n,r,UT,i)}var GT={selected:B.selection,selectedFill:B.selectionFill,hover:B.hover,noteStroke:B.selectionBox,noteFill:B.selectionBoxFill,noteDash:[1,3],boxStroke:B.selectionBox,boxFill:B.selectionBoxFill,boxDash:[1,3],lockFill:B.document,lockGlyph:B.background,markPin:B.document,markPanel:B.notePanel,markText:B.document};function KT(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}:{}}}KT(la);function qT(e,t,n,r,i,a,o,s){let c=fe(t,n,{x:r.minX+i.x,y:r.maxY+i.y}),l=fe(t,n,{x:r.maxX+i.x,y:r.minY+i.y}),u=a===`selected`?Aa(1.5,s):1,d=Ma({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 JT(e,t,n,r,i,a){let o=fe(t,n,{x:r.maxX,y:r.maxY}),s=Ea(o.x-4,a),c=Ea(o.y-12,a),l=Da(14,a);e.save(),e.fillStyle=i.lockFill,$T(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 YT(e,t,n,r,i,a){let{at:o,id:s,text:c}=r,l=fe(t,n,o),u=`${s} ${c.length>VT?`${c.slice(0,31)}…`:c}`;e.save(),Ba(e),e.font=`${Ra(BT,1,a)}px ${$r}`;let d=e.measureText(u).width+12;e.fillStyle=i.markPanel,$T(e,l.x+10,l.y-22,d,20,4),e.fill(),e.fillStyle=i.markText;let f=za({x:l.x+16,y:l.y-8},a);e.fillText(u,f.x,f.y),e.strokeStyle=i.markPin,e.lineWidth=Aa(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 XT(e,t,n,r,i,a){QT(e,t,n,{stroke:r.boxStroke,fill:r.boxFill,dash:i===`inside`?[]:r.boxDash},a)}function ZT(e,t,n,r,i){QT(e,t,n,{stroke:r.noteStroke,fill:r.noteFill,dash:r.noteDash},i)}function QT(e,t,n,r,i){let a=Ma(t,n,i);e.save(),e.lineWidth=wa(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 $T(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 eE(e,t,n,r,i,a,o){let s=r.map(e=>fe(t,n,e)),c=s[s.length-1];c&&(e.save(),e.strokeStyle=a,e.lineWidth=Aa(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 tE(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&&qT(e,t.camera,t.size,o.box,{x:0,y:0},n,i,a)}}var nE=(e,t,n)=>Math.min(Math.max(e,t),n);function rE(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 iE(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 aE=e=>e.points.length===1?e.points[0]:rE(e.points);function oE(e,t,n,r){let i=n&&rE(n.points);if(n&&i)return{target:{kind:`wire`,id:n.id},middle:i};let a=r&&aE(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 sE(e,t,n,r,i,a,o){let s=n?oE(e,t,a,o):void 0,c=s&&n?fe(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+nE(c.x,0,r.width)*l,y:i.top+nE(c.y,0,r.height)*u};return{target:s?.target??{kind:`canvas`},at:d}}function cE(e,t){return{width:Math.round(e.width*t),height:Math.round(e.height*t)}}function lE(e,t,n){let r=cE(t,n);return e.width===r.width&&e.height===r.height?!1:(e.width=r.width,e.height=r.height,!0)}function uE(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 dE=.0015,fE=1.25;function pE(e,t,n){let r=(0,l.useMemo)(()=>t===`pcb`?Td(e.pcb):Xo(e.schematic),[e,t]),i=(0,l.useMemo)(()=>De(e,t),[e,t]),a=(0,l.useMemo)(()=>[...i.values()].some(e=>e.autoPlaced),[i]),o=(0,l.useMemo)(()=>_n(new Set(n.annotations.locks.map(e=>e.part)),e),[n,e]);return{boxes:r,anchors:i,autoPlaced:a,locked:o,blockerFor:(0,l.useCallback)(r=>vn(e,o,r)??Oe(n,o,r,t),[e,n,o,t])}}function mE(e,t,n){let{anchors:r,boxes:i}=e;return(0,l.useMemo)(()=>({anchors:r,boxes:i,step:t,snap:n}),[r,i,t,n])}function hE(e,t,n,r,i,a,o){return(0,l.useCallback)(()=>sE(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 gE(e){let[t,n]=(0,l.useState)({width:0,height:0});return(0,l.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 _E(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 vE(e,t,n,r){let[i,a]=(0,l.useState)();bE(e,t,a);let o=(0,l.useCallback)(()=>{n&&t.width>0&&a(me(n,t,r))},[n,t,r]);(0,l.useEffect)(()=>{i||o()},[i,o]);let s=e=>()=>a(n=>n&&ge(n,t,{x:t.width/2,y:t.height/2},e));return Py({zoomIn:s(fE),zoomOut:s(1/fE)}),{camera:i,setCamera:a,fit:o}}function yE(e,t,n,r,i){(0,l.useEffect)(()=>{t&&t.view===e&&n&&(r(he(n,t.at)),i())},[e,t,n,r,i])}function bE(e,t,n){let r=(0,l.useCallback)(r=>{r.preventDefault();let i=_E(e.current,t,r);n(e=>e&&ge(e,t,i,Math.exp(-r.deltaY*dE)))},[e,t,n]);(0,l.useEffect)(()=>{let t=e.current;if(t)return t.addEventListener(`wheel`,r,{passive:!1}),()=>t.removeEventListener(`wheel`,r)},[e,r])}function xE(e,t,n,r,i){if(!e||t.width===0)return null;let a=window.devicePixelRatio||1;lE(e,t,a);let o=e.getContext(`2d`);return o?(uE(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 SE(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&&qT(e,t,n,a.box,s,`hover`,i,o),c&&qT(e,t,n,a.box,s,`selected`,i,o),r.locked.has(a.name)&&JT(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&&YT(e,t,n,{at:{x:a.x,y:a.y},id:a.id,text:a.text},i,o);a?.kind===`box`&&XT(e,a.start,a.current,i,Ai(a.start,a.current),o),a?.kind===`zoom`&&XT(e,a.start,a.current,i,Ai(a.start,a.current),o),a?.kind===`note`&&ZT(e,a.start,a.current,i,o)}function CE(e){return e.target instanceof HTMLElement&&e.target.closest(`input, textarea, select`)?!1:!(e.ctrlKey||e.metaKey||e.altKey)}var wE=`Waiting for the build…`,TE=`Snap off`;function EE(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 DE=(e,t)=>Am(e,t??`mm`);function OE(e){let{cursor:t,zoom:n,unit:r}=e,i=EE(e.gesture);return{position:[n===void 0?``:`Zoom ${Mm(n,r?10:60)}%`,t?`X ${DE(t.x,r)} Y ${DE(t.y,r)}`:``].filter(e=>e!==``).join(` `),drag:i?`dX ${DE(i.x,r)} dY ${DE(i.y,r)}`:``,notice:e.rotateHeld?wE:``,snap:e.snap===!1?TE:``}}function kE(e,t,n,r){return`Routing ${e} on ${t}, ${n} mm, ${r} — Space corner, V layer+via, Enter ends open, Esc`}function AE({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 jE({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 ME({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}=OE({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?.(),rp(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 NE=(e,t)=>({x:e.x+t.x,y:e.y+t.y}),PE=(e,t,n)=>({...e.length>0?{wires:e}:{},...t.length>0?{labels:t}:{},...n.length>0?{drawings:n}:{}}),FE=(e,t,n,r,i)=>Vi(e.names,t)&&Vi(e.wires??[],n)&&Vi(e.labels??[],r)&&Vi(e.drawings??[],i);function IE(e,t,n,r,i=[],a=[],o=[]){let s=e!==void 0&&FE(e,n,i,a,o);if(e&&s&&e.inFlight)return{burst:{...e,total:NE(e.total,r),dirty:!0},send:null,fresh:!1};if(e&&s&&e.base===t){let t=NE(e.total,r);return{burst:{...e,total:t,inFlight:!0,dirty:!1},send:t,fresh:!1}}return{burst:{base:t,names:n,...PE(i,a,o),total:r,inFlight:!0,dirty:!1},send:r,fresh:!0}}function LE(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 RE={inFlight:0,seq:0,waiting:void 0,written:0,held:void 0,history:void 0};function zE(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 BE=(e,t)=>e.waiting&&zE(e,t)?{...e,waiting:void 0,history:void 0}:e;function VE(e,t,n,r){if(n)return{gate:e,send:!1};if(zE(e,r)&&!e.held)return{gate:BE(e,r),send:!0};let i=e.held&&Vi(e.held.names,t)?e.held.count+1:1;return{gate:{...e,held:{names:t,count:i}},send:!1}}function HE(e,t,n){let{held:r}=e;if(!r||!zE(e,n))return{gate:r?e:BE(e,n),send:!1};let i=BE(e,n);return Vi(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 UE(e){let t=e.seq+1;return{...e,inFlight:e.inFlight+1,seq:t,waiting:{seq:t}}}function WE(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 GE(e){let t=UE(e);return{...t,history:{seq:t.seq}}}function KE(e,t,n,r,i){if(t)return WE(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 qE(e,t){return e.history===void 0?{gate:e,send:!0}:zE(e,t)?{gate:BE(e,t),send:!0}:{gate:e,send:!1}}function JE(e,t,n,r=[],i=[],a=[]){let o=e!==void 0&&FE(e,t,r,i,a);return{names:t,...PE(r,i,a),total:e&&o?NE(e.total,n):n}}function YE(e,t,n,r,i=[],a=[],o=[]){if(!t)return{gate:e,held:t,send:null};let s=qE(e,r);return s.send?{gate:s.gate,held:void 0,send:FE(t,n,i,a,o)?t.total:null}:{gate:e,held:t,send:null}}var XE=new Set([`fit`,`highlight`,`contextMenu`,`delete`,`rotate`,`nudgeLeft`,`nudgeRight`,`nudgeUp`,`nudgeDown`,`alignLeft`,`distributeH`]);function ZE(e,t,n,r,i=t){return!r||!XE.has(e)?!1:e.startsWith(`nudge`)?i>0&&!n:e===`rotate`?t>0&&!n:e===`alignLeft`||e===`distributeH`?!n:!0}function QE(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?LE(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=IE(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 $E(e){return e?.kind===`text`&&e.moved&&!e.blocker?{id:e.id,at:e.at}:void 0}function eD({view:e,design:t,circuit:n,actions:r,locked:i,builtFrom:a,drawn:o}){let[s,c]=(0,l.useState)([]);(0,l.useEffect)(()=>c(e=>e.every(e=>e.sentAt>a)?e:e.filter(e=>e.sentAt>a)),[a]);let u=(0,l.useMemo)(()=>Gu(e,t),[e,t]),d=(0,l.useMemo)(()=>s.filter(e=>e.sentAt>a),[s,a]),f=(0,l.useMemo)(()=>Xu(u,d),[u,d]),p=(e,t)=>{let n={id:e,at:t,sentAt:Date.now()};return c(t=>[...t.filter(t=>t.id!==e),n]),n},m=async(e,t)=>{let a=ed(n,i,e.id);if(a)return r.notify(a),!1;let o=Zu(e,t);if(o.length===0)return!0;let s=p(e.id,t),l=await r.edit(o,`Move ${e.part} ${Bu[e.prop]?.toLowerCase()??e.prop}`);return l||c(e=>e.filter(e=>e!==s)),l},h=(e,t)=>{let n=f.find(t=>t.id===e);n&&m(n,t)},g=(0,l.useRef)(m);g.current=m;let[_]=(0,l.useState)(()=>QE((e,t)=>g.current(e,t)));return{tools:{at:e=>Ju(o?f.filter(e=>o(e.part)):f,e)?.id,position:e=>f.find(t=>t.id===e)?.at,blocker:e=>ed(n,i,e),commit:h},placed:f,pending:d,nudge:(e,r)=>{let a=_.press(t,e=>f.find(t=>t.id===e),e,r);a&&ed(n,i,e)===null&&p(e,a)}}}function tD(e,t){let{placed:n,pending:r}=e;return(0,l.useMemo)(()=>{let e=$E(t);return{moves:e?[e,...r.filter(t=>t.id!==e.id)]:r,shown:e?Xu(n,[e]):n}},[t,n,r])}var nD=e=>e*Math.PI/180;function rD(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,ws(t,r[e-1],r[e]));return i}function iD(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 aD(e,t){let n={x:e.x,y:e.y};if(iD(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(nD(t)),y:n.y+e.radius*Math.sin(nD(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 oD=(e,t)=>t.x>=e.minX&&t.x<=e.maxX&&t.y>=e.minY&&t.y<=e.maxY,sD=(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 cD(e,t){switch(e.kind){case`path`:case`bus`:return rD(e.points,t);case`rect`:{let{x:n,y:r,width:i,height:a}=e;return rD([{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 aD(e,t);case`text`:case`junction`:return sD(an(e),t)}}function lD(e,t){return Sa(e)?e.kind===`circle`?Math.hypot(t.x-e.x,t.y-e.y)<=e.radius:oD(an(e),t):!1}function uD(e,t,n){return cD(e,t)<=n+_a(e)/2?`line`:lD(e,t)?`inside`:void 0}var dD=(e,t)=>e.kind!==`text`||t===void 0||e.fontSize*t>=3;function fD(e,t,n,r){let i;for(let a=e.length-1;a>=0;a--){let o=e[a];if(!dD(o,r))continue;let s=uD(o,t,n);if(s===`line`)return{id:o.id,place:s};s===`inside`&&!i&&(i={id:o.id,place:s})}return i}function pD(e){let t=an(e),n=_a(e)/2;return{minX:t.minX-n,minY:t.minY-n,maxX:t.maxX+n,maxY:t.maxY+n}}function mD(e){return e.map(e=>({id:e.id,box:pD(e)}))}function hD(e,t,n,r){return Ni(e,t,n,r)}var gD=.1,_D=`None of the selected parts is in this view.`,vD=1e-6;function yD(e,t,n){let r=Math.max(e.maxX-e.minX,vD),i=Math.max(e.maxY-e.minY,vD),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:we(a)}}function bD(e,t,n,r){let i=new Set(t),a=Se(e.filter(e=>i.has(e.name)).map(e=>e.box));return!a||n.width<=0||n.height<=0?{message:_D}:{camera:yD(a,n,r)}}function xD(e,t,n){return yD({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 SD=new Set([`part`,`selectedPart`,`label`,`selectedLabel`,`wire`,`selectedWire`,`wireCorner`,`drawing`,`selectedDrawing`,`text`]),CD=new Set([`selectedPart`,`selectedWire`,`selectedLabel`,`selectedDrawing`]),wD=0,TD=1,ED=2,DD={wire:`wireSegment`,wireCorner:`wireCorner`};function OD(e,t,n){return e.button===TD?`pan`:e.button===ED?`rightPress`:e.button===wD?n===`note`?`note`:n===`zoom`?`zoom`:n===`place`&&t===`empty`?`pan`:Qi(e)?SD.has(t)?`toggle`:`addBox`:t===`part`||t===`drawing`?`move`:CD.has(t)?`moveGroup`:t===`wire`||t===`wireCorner`?n===null?DD[t]:`wire`:t===`text`?`text`:t===`label`?`label`:`box`:`none`}var kD=2;function AD(e){return(e&kD)!==0}function jD(e,t){return e===`rightPress`?t?`disarm`:`menu`:e===`moveGroup`?`selectAlone`:e===`box`?`clear`:`none`}function MD(e,t){return Math.hypot(t.x-e.x,t.y-e.y)>=3}var ND=`input, textarea, select, form, button`;function PD(e){if(e.button!==wD)return!1;let t=e.target;return typeof t?.closest!=`function`||!t.closest(ND)}var FD=(e,t)=>({x:z(e.x+t.x),y:z(e.y+t.y)}),ID=(e,t)=>e.x===t.x&&e.y===t.y,LD=e=>FD(e.at,e.by);function RD(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??Ee,a=Ae(t,n,`schematic`,{origin:r,group:i}),o={x:z(a.x),y:z(a.y)};return{props:o,ahead:{x:z(o.x+i.x-r.x),y:z(o.y+i.y-r.y)}}}var zD=(e,t)=>typeof e==`number`?z(e-t):0;function BD(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`?RD(e,t,i.part):void 0;o&&r.set(i.part,{x:zD(n,o.props.x),y:zD(a,o.props.y)})}return r}function VD(e){let t=e.trace.schematicRouteHints??[];return e.reversed?[...t].reverse():[...t]}function HD(e,t,n,r,i){let a=(n,r)=>{if(n===void 0||r===void 0)return;let a=RD(e,t,r);return a&&{at:FD(n,a.ahead),by:i.get(r)??Ee}},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 UD(e,t,n){let r=Ns(e,t);return r===`horizontal`?{x:0,y:n.y}:r===`vertical`?{x:n.x,y:0}:Ee}function WD(e,t,n){if(n&&ID(e.by,n.by))return t.map(t=>FD(t,e.by));let r=t.length-1,[i,a]=[t[0],t[r]],o=i?UD(e.at,i,e.by):Ee,s=n&&a?UD(n.at,a,n.by):Ee;return t.map((e,t)=>FD(FD(e,t===0?o:Ee),t===r?s:Ee))}function GD(e,t,n,r,i){let a=VD(r),o=a.length>0?HD(e,t,n,r,i):void 0;if(!o)return;let[s,c]=o;return{start:s,end:c,corners:a,path:Ws([s.at,...a,...c?[c.at]:[]])}}function KD(e,t,n,r,i){let a=n.length<2?[]:pc(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 qD(e,t,n,r,i){let{writer:a}=n;if(a.kind!==`trace`||!a.components.some(e=>r.has(e)))return;let o=GD(e,t,n,a,r);if(!o)return;let{start:s,end:c}=o,l=c?[LD(c)]:[],u=o.path.slice(1,c?-1:void 0);return KD(e,n,Ws([LD(s),...WD(s,u,c),...l]),i,[LD(s),...o.corners,...l])}function JD(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)?cc(e,t,a.id):void 0,c=s&&qD(e,t,s,n,r);return c?[c]:[]})}function YD(e,t,n,r,i,a,o){let s=GD(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 KD(e,n,Hs(s.path,i.offset,d),o,s.path)}function XD(e,t,n,r,i){let{design:a,locked:o}=e,s=cc(a,t,n),c=s?.writer;if(!s||c?.kind!==`trace`||VD(c).length===0)return{kind:`leave`};let l=lc(a,s,o);if(l!==null)return{kind:`blocked`,reason:l,named:Uw(a,s,l)};let u=Fw(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:YD(a,t,s,c,r,i,o)}}var ZD=`Studio draws this wire's shape between its pins; drag one of its segments to give it corners first`,QD=`Studio draws these wires' shapes between their pins; drag one of their segments to give them corners first`;function $D(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?ZD:QD]:[];return[...r,...a]}function eO(e,t){return e.flatMap(e=>e.kind===`carry`&&e.move||e.kind===`follow`&&t.has(e.id)?[e.name]:[])}var tO=(e,t,n,r,i)=>`move ${et([...e,...tt(t),...jf(n),...r])}${Te.schematic.where} by (${z(i.x)}, ${z(i.y)})`;function nO(e,t,n,r){let i=n?.wires??[],a=Tf(e.design,n?.labels??[],e=>r.has(e),i),o=i=>XD(e,t,i,{offset:n?.offset??Ee,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 rO(e,t,n,r){return n.riding.flatMap((i,a)=>{if(i.kind===`carry`||i.kind===`follow`)return[];let o=n.ridingIds[a]??``,s=cc(e.design,t,o),c=i.kind===`blocked`?i.reason:s&&lc(e.design,s,e.locked),l=e.design.schematic.labels.find(e=>e.id===n.sort.riding.get(o));return c&&!r.includes(c)?[Df(l,c)]:[]})}function iO(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 aO(e,t,n,r){if(!n)return{plan:e,lines:[],labels:[],drawings:[]};let i=BD(n.design,t,e.edits),a=nO(n,t,r,i),o=[...a.outcomes,...a.riding].flatMap(e=>e.kind===`carry`&&e.move?[e.move]:[]),s=JD(n.design,t,i,n.locked,new Set(o.map(e=>e.line.id))),c=[...o,...s],l=r?.offset??Ee,u=kf(n.design,t,a.sort.alone,l,n.locked,e.skipped),d=mC(t.model,n.design.schematic.drawings,r?.drawings??[],l,n.locked),f=eO(a.outcomes,new Set(s.map(e=>e.line.id))),p=[...Af(n.design,iO(a)),...u.names],m=[...u.edits,...d.edits],h=e.edits.length===0&&c.length===0&&m.length===0,g=[...$D(a.outcomes,e.skipped,h),...rO(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?tO(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 oO(e,t,n,r){return aO(e,t,n,r).plan}function sO(e,t,n,r=[],i=[],a=[]){return aO(it(e.circuit,t,e.view,at(e.anchors,e.boxes),n,e.blockerFor),e.circuit,e.follow,{wires:r,labels:i,drawings:a,offset:n})}var cO=6,lO=z;function uO(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]=wi([...s?[{kind:`label`,label:s}]:[],...c===void 0?[]:[{kind:`wire`,id:c}],...d(`line`),...be(e,n).map(e=>({kind:`part`,name:e.name})),...u===void 0?[]:[{kind:`text`,id:u}],...d(`inside`)],r);return f??{kind:`canvas`}}function dO(e,t,n,r){return uO(e,void 0,t,n,void 0,void 0,r).kind===`text`}function fO({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 pO=e=>({selection:e.selection,armed:e.tool.armed,layers:e.layers,filter:e.filter});function mO(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 hO(e,t,n){let r=Oc(e.wires?.drag,pO(e),t,n.scale);if(r)return{target:{kind:`wire`,id:r.id},under:`wireCorner`,corner:r.index};let i=uO(e.boxes,e.labels,t,pO(e),e.wires,e.drawings,e.texts),a=i.kind===`text`?void 0:e.copperAt?.(t);return a===void 0?{target:i,under:mO(i,e.selection)}:{target:{kind:`copper`,id:a},under:`empty`}}var gO=new Set([`wire`,`wireSegment`,`wireCorner`]);function _O(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&&kc(o,r.world,i.scale,n===`wireCorner`?r.corner:void 0);return s&&jc(a,t,s,r.point)}function vO(e,t,n){let{camera:r}=e;if(!r)return;let i=pe(r,e.size,n),{target:a,under:o,corner:s}=hO(e,i,r),c=OD(t,o,e.tool.armed);if(M(c)&&ie.refuses())return yO(e,a,c);let l=jD(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 bO(e,a.label,c,n,l);if(a.kind===`wire`)return CO(e,a.id,c,{world:i,point:n,still:l,...s===void 0?{}:{corner:s}},r);if(a.kind===`drawing`)return SO(e,a.id,c,n,l);if(a.kind===`text`)return xO(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`?EO(e,{part:u},c,n,l):void 0}}function yO(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 bO(e,t,n,r,i){if(n===`toggle`)e.onSelect(e=>e.toggleLabel(t.id));else{if(n===`moveGroup`)return EO(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 xO(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 SO(e,t,n,r,i){if(n===`toggle`)e.onSelect(e=>e.toggleDrawing(t));else return n===`move`||n===`moveGroup`?EO(e,{drawing:t},n,r,i):void 0}function CO(e,t,n,r,i){if(n===`toggle`)e.onSelect(e=>e.toggleWire(t));else return n===`moveGroup`?EO(e,{wire:t},n,r.point,r.still):gO.has(n)?_O(e,t,n,r,i):void 0}var wO={names:[],wires:[],labels:[],drawings:[]};function TO(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)),{...wO,names:[n]}}if(!(`drawing`in t))return wO;let{drawing:r}=t;return e.onSelect(e=>e.onlyDrawing(r)),{...wO,drawings:[r]}}function EO(e,t,n,r,i){let a=TO(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:Ee,moved:!1,blocker:s,still:i}}function DO(e,t,n,r){if(t.kind===`pan`){let r=(n.x-t.start.x)/t.camera.scale,i=(n.y-t.start.y)/t.camera.scale;return e.setCamera({...t.camera,cx:t.camera.cx-r,cy:t.camera.cy+i}),!t.moved&&MD(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&&!MD(t.start,n))return;let i=pe(r,e.size,n),a=pe(r,e.size,t.start),o={x:i.x-a.x,y:i.y-a.y};if(t.kind===`reshape`)return Mc(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=>ve(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??Ee;return{...t,moved:!0,offset:{x:lO(s(l.x+o.x)-l.x),y:lO(s(l.y+o.y)-l.y)}}}function OO(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 kO(e,t,r);if(t.kind===`reshape`)return Pc(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 MO(e,t,n);if(t.kind===`zoom`)return NO(e,t,n);PO(e,t,n)}}function kO(e,t,n){if(!t.moved)t.still===`selectAlone`&&e.onSelect(AO(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 AO({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 jO(e,t,n){return Math.abs(t.start.x-t.current.x)<cO&&Math.abs(t.start.y-t.current.y)<cO?void 0:[pe(n,e.size,t.start),pe(n,e.size,t.current)]}function MO(e,t,n){let r=jO(e,t,n);if(!r){t.still===`clear`&&e.onSelect(e=>e.clear());return}let i=Ai(t.start,t.current),a={parts:Pi(e.boxes,r[0],r[1],i),wires:Ri(e.wires?.lines??[],r[0],r[1],i),labels:Fi(e.labels?.boxes??[],r[0],r[1],i),drawings:hD(e.drawings?.boxes??[],r[0],r[1],i),copper:Yc(e.copper??[],r[0],r[1],i)};e.onSelect(zi(a,t.adds,e.tool.armed,e.layers,e.filter))}function NO(e,t,n){let r=jO(e,t,n);r&&(e.tool.disarm(),e.setCamera(xD(r[0],r[1],e.size)))}function PO(e,t,n){let r=jO(e,t,n);if(!r)return;let[i,a]=r;e.tool.disarm();let o=window.prompt(Te[e.view].notePrompt);o&&e.actions.mark(o,{view:e.view,x:lO((i.x+a.x)/2),y:lO((i.y+a.y)/2)})}function FO(e,t){return e.kind===`reshape`&&!t?.drag}var IO=new Set([`label`,`text`,`reshape`]),LO=e=>e!==void 0&&IO.has(e);function RO(e,t,n){return FO(e,n)?!0:t!==void 0&&(t===0||e.kind===`reshape`&&AD(t))}function zO(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=vO(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(RO(n,r,a.wires))return i(void 0),!1;let o=DO(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&&OO(a,r,a.camera,o,t)},cancel(){i(void 0)}}}function BO(e){let{actions:t,builtFrom:n}=e,[r,i]=(0,l.useState)();return(0,l.useEffect)(()=>i(e=>e&&e.sentAt>n?e:void 0),[n]),{pending:(0,l.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}=sO(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),_t(c,t).then(e=>e||i(e=>e===f?void 0:e))}}}function VO(e,t){(0,l.useEffect)(()=>{if(!LO(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 HO(e,t){let n=t?.kind===`drag`&&t.moved&&!t.blocker?t:void 0,{follow:r,circuit:i}=e;return(0,l.useMemo)(()=>{if(!n)return;if(!r)return{names:n.movable,offset:n.offset,wires:[]};let{lines:t,labels:i,drawings:a}=sO(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 UO(e){let[t,n]=(0,l.useState)(),{pending:r,commit:i}=BO(e),a=(0,l.useRef)({input:e,commit:i});a.current={input:e,commit:i};let[o]=(0,l.useState)(()=>zO(()=>a.current,n)),s=HO(e,t)??r;VO(t?.kind,o.cancel),(0,l.useEffect)(()=>{t&&FO(t,e.wires)&&o.cancel()},[t,e.wires,o]);let{press:c,move:u,release:d,cancel:f,wireBeforeDoubleClick:p}=o;return{gesture:t,moving:s,pending:r,press:c,move:u,release:d,cancel:f,wireBeforeDoubleClick:p}}function WO(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 GO(e){let t=t=>_E(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,pe(e.camera,e.size,r))||e.gestures.press(n,r)},onPointerMove:n=>{if(!e.camera)return;let r=t(n),i=pe(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(pe(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&&PD(n)&&e.open?.(pe(e.camera,e.size,t(n)))}}}function KO({selection:e,boxes:t,size:n,setCamera:r,notify:i}){Py({fitSelection:()=>{let a=bD(t,e.names,n,gD);`camera`in a?r(a.camera):i(a.message)}})}var qO=`Drag a box where the note for the agent goes. Esc or a right click stops.`,JO=`Drag a box to zoom to it. Esc or a right click stops.`,YO=e=>e,XO=e=>e===`note`?qO:e===`zoom`?JO:void 0,ZO=e=>e===`zoom`?`fitArea`:null;function QO(e,t){(0,l.useEffect)(()=>{if(!e)return;let n=e=>{ku(pu(e))&&(e.stopPropagation(),t())};return window.addEventListener(`keydown`,n,!0),()=>window.removeEventListener(`keydown`,n,!0)},[e,t])}function $O(e){let[t,n]=(0,l.useState)(null),r=(0,l.useCallback)(()=>n(null),[]),i=(0,l.useCallback)(t=>{e?.(),n(YO(t))},[e]);return Py({noteBox:()=>i(`note`),fitArea:()=>i(`zoom`)}),QO(t!==null,r),{armed:t!==null,which:t,tool:t,arm:i,disarm:r,hint:XO(t)}}function ek(e,t){return t===void 0?`no net`:e.circuit.nets.find(e=>e.id===t)?.names[0]??t}function tk(e,t){let n=e.circuit.nets.find(e=>e.id===t);if(n)return{id:t,name:n.names[0]??t,width:Ch(e.rules,n),via:Eh(e.rules,n)}}function nk(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 rk=(e,t)=>t===void 0?{}:{net:t,netName:ek(e,t)};function ik(e,t,n){if(!Rc({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,...rk(e.design,r.net)}}function ak(e,t,n){let r=Kd(e.design.pcb,t,n,e.visible);return r&&{kind:`pad`,id:r.id,label:nk(e.design,r),part:r.component,at:{x:r.x,y:r.y},...rk(e.design,r.net),layer:r.layers}}function ok(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:z(e.x+s*i),y:z(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=ve(c[l],r.step);return u>=Math.min(e[l],t[l])&&u<=Math.max(e[l],t[l])?{...c,[l]:u}:c}function sk(e,t,n,r,i){let a;for(let o of e.copper.tracks)if(!(r!==void 0&&o.layer!==r||!Rc({kind:`track`,layer:o.layer},e.visible)))for(let e=1;e<o.points.length;e++){let r=ok(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:ok(o.points[e-1],o.points[e],t,i),d:s})}return a&&{kind:`track`,id:a.track.id,at:a.at,...rk(e.design,a.track.net),layer:a.track.layer}}function ck(e,t,n,r,i){return ik(e,t,n)??ak(e,t,n)??sk(e,t,n,r,i)}var lk=(e,t)=>e.mark===void 0||t===void 0||t<=e.mark,uk=(e,t,n)=>[...e,{...n,id:t}],dk=(e,t,n)=>e.map(e=>e.id===t?{...e,mark:n}:e),fk=(e,t)=>e.filter(e=>e.id!==t),pk=(e,t)=>e.filter(e=>lk(e,t)),mk=e=>e.some(e=>e.mark===void 0);function hk(e,t){return pk(e,t).reduce((e,t)=>uv(e,t.shapes),$_)}function gk(e,t){return[...pk(e,t)].reverse().find(e=>e.parts!==void 0)?.parts}var _k=Math.PI/12,vk=.005,yk=.01,bk=.001,xk=2*bk,Sk=1e-4,Ck=.01,wk=1e6,Tk=(e,t)=>({x:e.x-t.x,y:e.y-t.y}),Ek=(e,t)=>({x:e.x+t.x,y:e.y+t.y}),Dk=(e,t)=>({x:e.x*t,y:e.y*t}),Ok=e=>Math.hypot(e.x,e.y),kk=e=>Dk(e,1/Ok(e)),Ak=(e,t)=>e.x*t.y-e.y*t.x,jk=(e,t)=>e.x*t.x+e.y*t.y,Mk=e=>({x:Math.round(e.x*wk)/wk,y:Math.round(e.y*wk)/wk}),Nk=(e,t)=>Math.abs(e-t)<=Sk+Ck*Math.max(e,t),Pk=(e,t)=>Math.abs(e-t)<=bk;function Fk(e){let t=e<=.005/2?Math.PI:2*Math.acos(1-vk/e);return Math.min(_k,t)}function Ik(e){return e.filter((t,n)=>n===0||t.x!==e[n-1]?.x||t.y!==e[n-1]?.y)}function Lk(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]=[Tk(t,r),Tk(i,t)];return Math.atan2(Ak(a,o),jk(a,o))})}function Rk(e,t,n,r){let[i,a]=[Tk(t,e),Tk(r,n)],o=Ak(i,a);if(!(Math.abs(o)<1e-12))return Ek(e,Dk(i,Ak(Tk(n,e),a)/o))}function zk(e,t,n){let r=t[n];if(Math.abs(r)<=bk||Math.abs(r)>_k/2+bk)return;let i=n+1;for(;i<e.length-1&&Pk(t[i],2*r);)i++;if(i>=e.length-1||!Pk(t[i],r))return;let a=Ok(Tk(e[n+1],e[n]));for(let t=n+1;t<i;t++)if(!Nk(Ok(Tk(e[t+1],e[t])),a))return;let[o,s]=[e[n],e[i]],c=Rk(e[n-1],o,s,e[i+1]);if(c===void 0)return;let[l,u]=[Tk(c,o),Tk(s,c)];return jk(l,Tk(o,e[n-1]))>0&&jk(u,Tk(e[i+1],s))>0&&Nk(Ok(l),Ok(u))?{first:n,last:i,corner:c}:void 0}function Bk(e){let t=Lk(e),n=[];for(let r=1;r<e.length-1;r++){let i=zk(e,t,r);i&&(n.push(i),r=i.last)}return n}var Vk=(e,t)=>Math.max(1,Math.ceil(e/Fk(t)-1e-9));function Hk(e,t,n,r,i){let a=Math.abs(i),o=r*Math.tan(a/2),[s,c]=[Tk(e,Dk(t,o)),Ek(e,Dk(n,o))],l=Math.sign(i),u=Ek(s,Dk({x:-t.y*l,y:t.x*l},r)),d=Vk(a,r),f=Tk(s,u);return[s,...Array.from({length:d-1},(e,t)=>{let n=l*a*(t+1)/d;return Ek(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(Mk)}function Uk(e,t,n,r){let i=Ik(e),a=Math.max(t,n),o=Lk(i),s=new Set(Bk(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/Vk(p,a)/2<=xk){c.push(n);continue}let m=a*Math.tan(p/2),h=p<Math.PI-bk&&m+yk<=Ok(Tk(n,d))&&m+yk<=Ok(Tk(f,n))?Hk(n,kk(Tk(n,i[t-1])),kk(Tk(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 Wk(e,t){let n=Ik(e),r=[],i=Bk(n).filter(e=>{let i=Mk(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),Mk(e.corner)),o=e.last+1;return a.push(...n.slice(o)),{points:a,straightened:i.length,round:r}}var Gk=[`45`,`45r`,`90`,`arc`],Kk={45:`45°`,"45r":`45° reversed`,90:`90°`,arc:`Arc`},qk=e=>Kk[e];function Jk(e){return Gk[(Gk.indexOf(e)+1)%Gk.length]}var Yk=(e,t)=>({x:z(e),y:z(t)});function Xk(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)?Yk(e.x+o*(Math.abs(r)-a),e.y):Yk(e.x,e.y+s*(Math.abs(i)-a)):Yk(e.x+o*a,e.y+s*a)}function Zk(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`?Sn([e,t]).slice(1):n===`arc`?$k(e,t,r):[Xk(e,t,n===`45`),t]}var Qk=.98;function $k(e,t,n){let r=Sn([e,t]),i=Qk*Math.min(Math.abs(t.x-e.x),Math.abs(t.y-e.y));return i<n/2?r.slice(1):Uk([e,...r.slice(1)],i,n).points.slice(1)}function eA(e,t,n=0){let r=[e],i=e;for(let e of t)r.push(...Zk(i,e.to,e.mode,n)),i=e.to;return U_(r)}var tA={top:`Top Layer`,bottom:`Bottom Layer`,inner1:`Inner Layer 1`,inner2:`Inner Layer 2`},nA=e=>tA[e],rA=e=>e===`top`?`bottom`:`top`;function iA(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 ${nA(e.layer)}, which cannot be routed yet`}:{start:{label:n,at:e.at,through:!1},layer:e.layer}}function aA(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=iA(e,t);return`message`in i?i:{route:{net:n,start:i.start,layer:i.layer,mode:t.mode??`45`,corners:[]}}}function oA(e,t,n){if(!n.snap)return t;let r=r=>Math.abs(t[r]-e[r])<n.step/2?e[r]:ve(t[r],n.step);return{x:r(`x`),y:r(`y`)}}var sA=e=>e.corners.at(-1)?.at??e.start.at,cA=(e,t)=>e.x===t.x&&e.y===t.y;function lA(e,t){return cA(t,sA(e))?e:{...e,corners:[...e.corners,{at:t,mode:e.mode,layer:e.layer}]}}var uA=e=>({...e,mode:Jk(e.mode)});function dA(e,t=rA(e.layer)){return t===e.layer?e:e.corners.length===0&&!e.start.through?{message:`${e.start.label} is on the ${nA(e.layer)} only; click a corner before changing layer`}:{...e,layer:t}}function fA(e){let t=e.corners.at(-1);return t?{...e,corners:e.corners.slice(0,-1),layer:t.layer}:e}function pA(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=eA(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 mA(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 hA(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 ${nA(r)}; press V to change layer first`}var gA=e=>e.kind===`pad`?e.label:`${e.kind} ${e.id}`;function _A(e,t){if(e.corners.length===0&&cA(t.at,e.start.at))return;let n=hA(e,t);if(n)return{message:n};let r=pA(e,t.at);return{edits:mA(r,e.net.name),summary:`Route ${e.net.name} from ${e.start.label} to ${gA(t)}`,drawing:r}}function vA(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=pA({...e,layer:t.layer},t.at);return{edits:mA(n,e.net.name),summary:`Route ${e.net.name} from ${e.start.label}, open at (${t.at.x}, ${t.at.y})`,drawing:n}}function yA(e,t,n,r=ph.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 bA(e?e.at:t,i,r)}function bA(e,t,n=ph.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:mA(i,t?.name),summary:t?`Add via on ${t.name} ${a}`:`Add via ${a}`,drawing:i}}var xA={route:`singleRouting`,via:`placeVia`},SA=12;function CA(){let[e,t]=(0,l.useState)(null),[n,r]=(0,l.useState)(null),[i,a]=(0,l.useState)(`45`);return{armed:e,setArmed:t,disarm:(0,l.useCallback)(()=>t(null),[]),route:n,setRoute:r,mode:i,setMode:a}}var wA=`new`;function TA(e){let t=e=>e.net===void 0?{}:{net:e.net};return{tracks:e.flatMap(e=>e.drawing.tracks.map(n=>({id:wA,...t(e),...n}))),vias:e.flatMap(e=>e.drawing.vias.map(n=>({id:wA,...t(e),at:n.at,diameter:n.diameter})))}}function EA(e,t){let[n,r]=(0,l.useState)([]),i=(0,l.useRef)(0);(0,l.useEffect)(()=>r(t=>pk(t,e)),[e]);let a=(0,l.useMemo)(()=>pk(n,e),[n,e]);return{drawings:(0,l.useMemo)(()=>a.map(e=>({drawing:e.drawing,alpha:Zc})),[a]),copper:(0,l.useMemo)(()=>TA(a),[a]),send:(0,l.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?dk(t,a,e.mark):fk(t,a)))},[t])}}function DA(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 OA(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 ck(DA(e,t),n,SA/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=aA(t,{activeLayer:e.activeLayer,locked:e.locked,netOf:e=>tk(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=dA(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=Jk(c?.mode??o.mode);o.setMode(e),c?d({...c,mode:e}):i.notify(`Routing corner: ${qk(e)}`)}}}function kA(e){let{input:t,route:n}=e;if(!n)return;let r=vA(n);if(`message`in r)return t.actions.notify(r.message);e.setRoute(null),e.send(r,n.net.id)}function AA(e,t){let{input:n,route:r}=e,i=pu(t),a=()=>{t.preventDefault(),t.stopPropagation()};if(ku(i)&&(r||n.arm.armed))return a(),e.cancel();let o=Ou(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(rA(r?.layer??n.activeLayer));if(o.action===`routingCorner`)return a(),e.stepCorner();if(o.action===`finishShape`)return r?(a(),kA(e)):void 0;!r||o.action!==`flipBend`&&o.action!==`removeCorner`||(a(),o.action===`flipBend`&&n.arm.setMode(uA(r).mode),e.put(o.action===`flipBend`?uA(r):fA(r)))}}}function jA(e){(0,l.useEffect)(()=>{let t=t=>AA(e.current,t);return window.addEventListener(`keydown`,t,!0),()=>window.removeEventListener(`keydown`,t,!0)},[e])}function MA(e,t,n){let{input:r}=e,i=e.targetAt(t,!0),a=yA(i,ye(t,r.step,r.snap),e=>tk(r.design,e),Dh(r.design.rules));if(`message`in a)return r.actions.notify(a.message);n(a,i?.net)}function NA(e,t,n){let{input:r,route:i}=e,a=e.targetAt(t);if(!i){a&&e.start(a);return}if(!a){let n=lA(i,oA(sA(i),t,r));return n===i&&i.corners.length>0?kA(e):e.put(n)}let o=_A(i,a);if(o){if(`message`in o)return r.actions.notify(o.message);e.setRoute(null),n(o,i.net.id)}}function PA(e,t,n,r){let{input:i}=e;return!i.arm.armed||t.button!==0?!1:(i.arm.armed===`via`?MA(e,n,r):NA(e,n,r),!0)}function FA(e,t){let{route:n,input:r}=e;if(n&&t)return pA(n,e.targetAt(t)?.at??oA(sA(n),t,r))}var IA=(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 ${nA(n)}. Esc to stop.`:void 0;function LA(e){let{route:t,setRoute:n}=e.arm,r=EA(e.builtMark,e.actions),i=OA(e,r.copper,r.send),a=(0,l.useRef)(i);a.current=i,jA(a),Py({singleRouting:()=>a.current.arm(`route`),placeVia:()=>a.current.arm(`via`),routingCorner:()=>a.current.stepCorner()});let{armed:o}=e.arm;(0,l.useEffect)(()=>{o!==`route`&&n(null)},[o,n]),(0,l.useEffect)(()=>{t&&t.layer!==e.activeLayer&&a.current.changeLayer(e.activeLayer)},[t,e.activeLayer]);let s=FA(i,e.cursor),c=s?[...r.drawings,{drawing:s,alpha:1}]:r.drawings,u=o?xA[o]:null;return{armed:o!==null,routing:t!==null,command:u,routes:c,status:t?kE(t.net.name,nA(t.layer),t.net.width,qk(t.mode)):void 0,hint:IA(o,t,e.activeLayer),press:(e,t)=>PA(a.current,e,t,r.send),cancel:()=>a.current.cancel()}}var RA;function zA(e){RA=e}function BA(){return RA}function VA(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}}}}function HA(e){return e!==void 0&&e.outline.length>=3}var UA=1e-6;function WA(e,t){return!(e>=t-UA)}function GA(e,t,n,r,i,a){let o=Wr(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 KA=e=>e.toFixed(3),qA=e=>e>0?`${KA(e)} mm apart`:`touching or overlapping`;function JA(e,t,n,r,i){return{...GA(e,`error`,t,r,`pcb`,i),id:`${e}:${n.join(`|`)}`}}var YA=2,XA=(e,t)=>({minX:e.minX-t,minY:e.minY-t,maxX:e.maxX+t,maxY:e.maxY+t}),ZA=([e,t])=>({x:(e.x+t.x)/2,y:(e.y+t.y)/2}),QA=(e,t)=>e.net!==void 0&&e.net===t.net;function $A(e,t){return e.flatMap(e=>e.shapes.map(n=>({piece:e,shape:n,box:ab(n),rank:t(e)})))}function ej(e,t){let n=[...new Set(e.map(e=>e.className))].sort(Ur);return n.flatMap(e=>n.map(n=>xh(t,e,n))).reduce((e,t)=>Math.max(e,t),t.fabrication.minClearance)}function tj(e,t){return t.piece===e.piece||QA(e.piece,t.piece)?!1:t.rank===-1||t.rank>e.rank}function nj(e,t){return Ur(e.piece.id,t.piece.id)<=0?[e,t]:[t,e]}function rj(e,t,n){let[r,i]=nj(t,n),a=`${r.piece.id}|${i.piece.id}`,o=nb(r.shape,i.shape),s=e.get(a);(s===void 0||o<s.distance)&&e.set(a,{a:r,b:i,distance:o})}function ij(e,t,n,r){let i=new sb(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(XA(n.box,t)))tj(n,e)&&rj(r,n,e)}function aj({a:e,b:t}){if(e.piece.kind!==`pad`&&t.piece.kind!==`pad`)return _b(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=>_b(n.shape,{core:[e],radius:0}))}function oj(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 sj(e,t,n,r){return xh({...e,fabrication:{...e.fabrication,minClearance:0}},t,n)<r?`the fabrication minimum is ${KA(r)} mm`:`${oj(e,t,n)} needs ${KA(r)} mm`}var cj=({a:e,b:t})=>e.piece.net!==void 0&&t.piece.net!==void 0&&e.piece.net!==t.piece.net;function lj(e,t){if(aj(e)&&!cj(e))return;let{a:n,b:r,distance:i}=e,a=xh(t,n.piece.className,r.piece.className);return WA(i,a)?JA(`copper-clearance`,`${n.piece.id} and ${r.piece.id} are ${qA(i)}; ${sj(t,n.piece.className,r.piece.className,a)}`,[n.piece.id,r.piece.id],[n.piece.id,r.piece.id],ZA(ib(n.shape,r.shape))):void 0}var uj=e=>t=>t.piece.layers.includes(e);function dj(e,t,n){if(e.length===0)return[];let r=new Map(e.map((e,t)=>[e,t])),i=[...$A(e,e=>r.get(e)??-1),...$A(t,()=>-1)],a=ej([...e,...t],n),o=Math.max(YA,a),s=new Map;for(let e of By){let t=i.filter(uj(e));t.some(e=>e.rank!==-1)&&ij(t,a,o,s)}return[...s.keys()].sort(Ur).flatMap(e=>lj(s.get(e),n)??[])}var fj=e=>e===void 0?{}:{net:e};function pj(e){return e.layers===`through`?By:[e.layers]}function mj(e,t){let n=Ky(e);if(n===void 0)return;let r=e.net===void 0?ph.name:t(e.net);return{id:e.id,kind:`pad`,...fj(e.net),className:r,layers:pj(e),shapes:[n],at:{x:e.x,y:e.y}}}function hj(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 gj(e,t){let n=e.points[0]??{x:0,y:0};return{id:e.id,kind:`track`,...fj(e.net),className:t(e.net),layers:[e.layer],shapes:hj(e),at:n,pads:e.pads}}function _j(e,t){let n={core:[e.at],radius:e.diameter/2};return{id:e.id,kind:`via`,...fj(e.net),className:t(e.net),layers:[...mb(e)],shapes:[n],at:e.at}}function vj(e,t){return e.parts.flatMap(e=>e.pads).flatMap(e=>mj(e,t)??[])}function yj(e,t){let n=e=>e.missingLayer===void 0;return[...e.tracks.filter(n).map(e=>gj(e,t)),...e.vias.filter(n).map(e=>_j(e,t))].filter(e=>e.shapes.length>0).sort((e,t)=>Ur(e.id,t.id))}function bj(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=nb(r,a);o<n.distance&&(n={distance:o,at:ib(r,a)[1]})});return n}function xj(e,t){return!$y(e,t)&&bj([{core:[e],radius:0}],t).distance>1e-6}function Sj(e,t,n){let r=n.fabrication.boardEdgeClearance,i=(t,n)=>JA(`copper-edge`,t,[e.id],[e.id],n),a=e.shapes.flatMap(e=>e.core).find(e=>xj(e,t));if(a!==void 0)return i(`${e.id} ${e.kind===`track`?`runs`:`is`} outside the board`,a);let{distance:o,at:s}=bj(e.shapes,t);if(WA(o,r))return i(o>0?`${e.id} is ${KA(o)} mm from the board edge; the minimum is ${KA(r)} mm`:`${e.id} crosses the board edge; the minimum gap to it is ${KA(r)} mm`,s)}var Cj=(e,t)=>e.layers===`all`||t.layers.includes(e.layers);function wj(e,t){let n=e.core.find(e=>$y(e,t));if(n!==void 0)return n;let r={core:[...t],radius:0};return nb(e,r)<-1e-6?ib(e,r)[1]:void 0}function Tj(e,t){if(!Cj(t,e))return;let n=e.shapes.map(e=>wj(e,t.outline)).find(e=>e!==void 0);if(n!==void 0)return JA(`copper-keepout`,`${e.id} lies inside ${t.id}`,[e.id,t.id],[e.id,t.id],n)}var Ej=(e,t)=>e.minX<=t.maxX&&t.minX<=e.maxX&&e.minY<=t.maxY&&t.minY<=e.maxY,Dj=(e,t)=>({minX:e.minX-t,minY:e.minY-t,maxX:e.maxX+t,maxY:e.maxY+t});function Oj(e){return e.map(ab).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 kj({layout:e,rules:t,classOf:n}){let r=[t.fabrication.minClearance,ph.clearance,...t.classes.map(e=>e.clearance),...t.classClearance.map(e=>e.clearance)];return{copper:yj(e,n),pads:vj(e,n),reach:Math.max(...r)}}var Aj=(e,t)=>t.slice(1).map((n,r)=>({core:[t[r],n],radius:e.width/2}));function jj(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:Aj(e,t),at:t[0],pads:e.pads}}var Mj=(e,t)=>e.shapes.some(e=>t.some(t=>_b(e,t)));function Nj(e,t,n,r){return e.some(e=>e.net===t.net&&Mj(e,n)&&!Mj(e,r.shapes))}function Pj(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 Fj(e,t){let n=t.layout.board;if(n===void 0)return;if(HA(n)&&Sj(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&&Tj(r,e));return i?`too close to ${i.id}`:void 0}function Ij(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=jj(n,r,e.classOf),l=Aj(n,o),u=Dj(Oj([...c.shapes,...l]),t.reach+n.width),d=e=>Ej(Oj(e.shapes),u),[f,p]=[i.filter(d),a.filter(d)];if(Nj([...f,...p],n,l,c))return s;let m=dj([c,...f],p,e.rules).find(e=>e.items.includes(n.id));return m?`too close to ${Pj(m.items,n,[...f,...p],e)}`:Fj(c,e)}}var Lj=(e,t)=>[t[0],e,t.at(-1)];function Rj(e,t,n){let r=Ij(e,t,n);return(e,t)=>r(t,Lj(e,t),`joined on the corner's legs`)}function zj(e,t,n){let r=Ij(e,t,n);return(e,t)=>r(Lj(e,t),t,`joined on the arc`)}var Bj=(e,t)=>`${e} ${t}${e===1?``:`s`}`;function Vj(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?cn(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?gb(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 Hj=(e,t)=>[e,...t].join(`; `);function Uj(e){let t=vh(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?ph.name:t.get(e)??ph.name,netName:e=>n.get(e)??e}}function Wj(e,t={}){let{tracks:n,skipped:r}=Vj(e,t);if(n.length===0)return{changes:[],summary:Hj(`No tracks to round`,r)};let i=t.radius??Oh(e.rules),a=Uj(e),o=kj(a),s=[],c=[],[l,u]=[0,0];for(let e of n){let t=Uk(e.points,i,e.width,Rj(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:Hj(`No square corners to round`,r)}:{changes:s,summary:Hj(l===0?`No corner was rounded`:`Rounded ${Bj(l,`corner`)} on ${Bj(s.length,`track`)}`,[...u===0?[]:[`${u} left square: ${c.join(`, `)}`],...r])}}function Gj(e,t={}){let{tracks:n,skipped:r}=Vj(e,t),i=Uj(e),a=kj(i),o=[],s=[],[c,l]=[0,0];for(let e of n){let t=Wk(e.points,zj(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:Hj(`No rounded corners to straighten`,r)}:{changes:o,summary:Hj(c===0?`No corner was straightened`:`Straightened ${Bj(c,`corner`)} on ${Bj(o.length,`track`)}`,[...l===0?[]:[`${l} kept round: ${s.join(`, `)}`],...r])}}var Kj={filletTracks:`Fillet`,straightenTracks:`Straighten`};function qj(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 ${Kj[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:`${Kj[e]} ${i}?`}}function Jj(e,t,n,r){let i={...n?{ids:n}:{},lockedParts:r},a=e===`filletTracks`?Wj(t,i):Gj(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 Yj(e,t){if(e.busy())return e.notify(`Wait for the last copper change to land, then try again.`);let n=VA(e.design,BA(),e.builtMark),r=qj(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=Jj(t,n,r.ids,e.lockedParts);if(`message`in i)return e.notify(i.message);e.send(i),e.notify(i.summary)}function Xj(e){let t=(0,l.useRef)(e);t.current=e,Py({filletTracks:()=>Yj(t.current,`filletTracks`),straightenTracks:()=>Yj(t.current,`straightenTracks`)}),(0,l.useEffect)(()=>{let e=e=>{if(t.current.routing||e.repeat)return;let n=Ou(pu(e),{view:`pcb`})?.action;(n===`filletTracks`||n===`straightenTracks`)&&(e.preventDefault(),Yj(t.current,n))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[])}function Zj(e){let t=e.withoutTexts(e.texts);return t.total===0&&e.total>0?void 0:t}var Qj=`Deleted in two changes: the copper in the layout file, the rest in the circuit file.`;function $j(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 eM(e,t,n){return e>0?{removeCopper:!0,notice:t}:n?{removeCopper:!1}:{removeCopper:!1,notice:t}}var tM=`Select a part or a wire first.`,nM=e=>[...new Set(e)];function rM(e,t){let n=e?.withWires.filter(e=>t.has(e.wire)).map(e=>e.label)??[];return new Set([...e?.withParts??[],...n])}function iM(e,t,n,r,i,a){if(e.total===0)return{message:tM};let o=pt(e.names,t),s=new Set(o.parts),c=r&&e.labelCount>0?r(e.labels,s):void 0,l=nM([...e.wires,...c?.withWires.map(e=>e.wire)??[]]),u=n&&l.length>0?n(l,s,new Set(o.skipped)):void 0,d=nM([...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 ${et([...o.parts,...tt(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=rM(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:mt(o.parts,(u?.removed??[]).filter(t=>e.hasWire(t)).length)}:{}}}var aM=new Set;function oM(e){return aM.add(e),()=>{aM.delete(e)}}function sM(e){for(let t of aM)t(e);return e}var cM=e=>(e.minX+e.maxX)/2,lM=e=>(e.minY+e.maxY)/2,uM=e=>e.maxX-e.minX,dM=e=>e.maxY-e.minY;function fM(e,t,n,r){let i=new Map;for(let{name:a,box:o}of e){let e=z(n(o)-r(o));e!==0&&i.set(a,t===`x`?{x:e,y:0}:{x:0,y:e})}return i}function pM(e,t){let[n,r,i]=t===`x`?[`minX`,`maxX`,uM]:[`minY`,`maxY`,dM],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=z(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 mM(e,t){let n=Se(t.map(e=>e.box));if(!n)return new Map;switch(e){case`alignLeft`:return fM(t,`x`,()=>n.minX,e=>e.minX);case`alignRight`:return fM(t,`x`,()=>n.maxX,e=>e.maxX);case`alignTop`:return fM(t,`y`,()=>n.maxY,e=>e.maxY);case`alignBottom`:return fM(t,`y`,()=>n.minY,e=>e.minY);case`alignHCentres`:return fM(t,`y`,()=>lM(n),lM);case`alignVCentres`:return fM(t,`x`,()=>cM(n),cM);case`distributeH`:return pM(t,`x`);case`distributeV`:return pM(t,`y`)}}var hM={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 gM(e,t,n){return hM[e].replace(`{}`,et(t))+Te[n].where}function _M(e,t,n,r,i){let[a,o]=Te[n].position,[s,c]=je(e,t,n,at(r.anchors,r.boxes)(t),i);return{[a]:s,[o]:c}}function vM(e,t,n,r,i,a){let o=ut(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=y(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=mM(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:_M(e,t,n,r,d.get(t))})),summary:gM(i,m,n),parts:m,skipped:h,done:`moved`}}function yM(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??Ee;return[{name:t.part,to:{x:z(n+i.x),y:z(r+i.y)}}]}),wires:n,...r.length>0?{labels:r}:{},...i.length>0?{drawings:i}:{}}}function bM(e,t){let n=e.parts.find(e=>t.has(e.name)),r=n&&t.get(n.name)?.origin,i=n&&r?{x:z(n.to.x-r.x),y:z(n.to.y-r.y)}:Ee,{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 xM=e=>`${e.x},${e.y}`;function SM(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:Pr(i[i.length-2],a)}:n.has(xM(e.at))&&(r.x!==0||r.y!==0)?{at:{x:z(e.at.x+r.x),y:z(e.at.y+r.y)},side:e.side}:void 0}function CM(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(xM))),r=new Map((t.wires??[]).map(e=>[`label:${e.id.slice(5)}`,e.points])),i=e.labels.map(e=>SM(e,r,n,t.offset));return i.every(e=>e===void 0)?e.labels:e.labels.map((e,t)=>({...e,...i[t]}))}function wM(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 TM(e,t,n,r){let i=e.gate.waiting;n.edits.length>0&&(e.gate=UE(e.gate));let{seq:a}=e.gate;return vt(n,r.actions).then(({ok:r,mark:o})=>(n.edits.length>0&&(e.gate=WE(e.gate,r,a,i,o)),wM(e,t),t.resolved(),r))}function EM(e,t,n,r){let i=dt(n.circuit,n.selection.names,n.view,n.layout,n.blockerFor,r);if(`message`in i)return n.actions.notify(i.message);TM(e,t,i,n)}function DM(e,t,n,r){let i=vM(n.circuit,n.selection.names,n.view,n.layout,r,n.blockerFor);if(`message`in i)return n.actions.notify(i.message);TM(e,t,oO(i,n.circuit,n.follow),n)}function OM(e,t,n,r){r===`rotate`?EM(e,t,n,90):r===`rotateRight`?EM(e,t,n,-90):DM(e,t,n,r)}function kM(e,t,n,r,i){let a=VE(e.gate,n.selection.names,i,n);e.gate=a.gate,a.send?OM(e,t,n,r):i||(e.queue=(e.gate.held?.count??0)>1?[...e.queue,r]:[r]),wM(e,t)}function AM(e,t,n,r){let{burst:i,layout:a}=e;if(!i||!a)return;let o=ft(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}=aO(o,i.base,n.follow,s),f=TM(e,t,c,n);n.follow&&c.edits.length>0&&t.moved?.(yM(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?LE(e.burst,r):void 0;e.burst=a?.burst,a?.send&&AM(e,t,n,a.send)})}function jM(e,t,n,r){let{names:i,wires:a,labels:o,drawings:s}=n.selection,c=IE(e.burst,n.circuit,i,r,a,o,s);e.burst=c.burst,c.fresh&&(e.layout=n.layout),c.send&&AM(e,t,n,c.send)}function MM(e,t,n){let r={waiting:e.gate.waiting,history:e.gate.history};e.gate=GE(e.gate),e.burst=void 0;let{seq:i}=e.gate;n.catch(()=>({ok:!1})).then(({ok:n,mark:a})=>{e.gate=KE(e.gate,n,i,r,a),wM(e,t),t.resolved()})}function NM(e){let t={gate:RE,told:!1,queue:[]};return{nudge(n,r){let i=su(r.action);if(!i||n.selection.total===0)return;let a=ot(i,n.layout.step,r.steps??1,n.layout.snap!==!1),o=qE(t.gate,n);t.gate=o.gate,o.send?jM(t,e,n,a):t.arrows=JE(t.arrows,n.selection.names,a,n.selection.wires,n.selection.labels,n.selection.drawings),wM(t,e)},rotate(n,r){kM(t,e,n,`rotate`,r)},rotateRight(n){kM(t,e,n,`rotateRight`,!1)},align(n,r){kM(t,e,n,r,!1)},settle(n){let r=HE(t.gate,n.selection.names,n);t.gate=r.gate,r.send&&OM(t,e,n,t.queue.shift()??`rotate`);let{names:i,wires:a,labels:o,drawings:s}=n.selection,c=YE(t.gate,t.arrows,i,n,a,o,s);t.gate=c.gate,t.arrows=c.held,c.send&&jM(t,e,n,c.send),wM(t,e)},historyWrite:n=>MM(t,e,n)}}function PM(e){let[t,n]=(0,l.useState)(0),[r,i]=(0,l.useState)(!1),[a,o]=(0,l.useState)(),[s]=(0,l.useState)(()=>NM({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:u,moveWaiting:d,circuit:f}=e;return(0,l.useEffect)(()=>oM(e=>s.historyWrite(e)),[s]),(0,l.useEffect)(()=>s.settle(e),[s,c,u,d,f,t]),{edits:s,held:r,moved:a}}function FM(e,t){let n=Zj(e.selection);if(e.paused||!n)return;let{copper:r,rest:i}=$j(n,e.copper!==void 0),a=()=>r.length>0?e.copper?.remove(r):void 0;if(!i)return a();let o=iM(i,e.blockerFor,e.wire?.removal,e.wire?.labelRemoval,e.drawings,e.board);if(`message`in o){let n=eM(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);_t(s,e.actions).then(t=>{t&&(e.onSelect(p),r.length>0&&e.actions.notify(Qj))})}function IM(e,t,n){let r=e.texts&&sd(e.selection,t,e.layout);if(!r)return n.nudge(e,t);e.texts?.nudge(r.id,r.by)}function LM(e,t,n,r){let{action:i}=t;if(v(i))return e.paused||r?void 0:n.align(e,i);if(i.startsWith(`nudge`))return e.paused?void 0:IM(e,t,n);if(i===`fit`)return e.fit();if(i===`delete`)return FM(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 RM(e){let t=af(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 zM(e,t){let n=t=>()=>{e.paused||(e.selection.size>0?t(e):e.actions.notify(`Select a part first.`))};Py({...Object.fromEntries(g.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:()=>FM(e,!1),highlight:()=>RM(e)})}function BM(e){let{edits:t,held:n,moved:r}=PM(e);zM(e,t);let{view:i,selection:a,paused:o,circuit:s,actions:c,onSelect:u,blockerFor:d,layout:f,builtMark:p,buildStatus:m,moveWaiting:h,fit:g,netUnderPointer:_,netsOf:v,onHighlight:y,menuPlace:b,onContextMenu:x,wire:S,drawings:C,board:w,follow:T,copper:E,texts:ee}=e;return(0,l.useEffect)(()=>{let e={view:i,selection:a,paused:o,circuit:s,actions:c,onSelect:u,blockerFor:d,layout:f,builtMark:p,buildStatus:m,moveWaiting:h,fit:g,netUnderPointer:_,netsOf:v,onHighlight:y,menuPlace:b,onContextMenu:x,wire:S,drawings:C,board:w,follow:T,copper:E,texts:ee},n=n=>{let r=Ou(pu(n),{view:i,drawing:o});r&&(ZE(r.action,a.size,o,r.preventDefault,a.total)&&n.preventDefault(),LM(e,r,t,n.repeat))};return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[t,i,a,o,s,c,u,d,f,p,m,h,g,_,v,y,b,x,S,C,w,T,E,ee]),{rotateHeld:n,keyMove:r}}var VM={x:0,y:0};function HM(e,t,n){let r={id:e.id,start:n.point,moved:!1,offset:VM};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&&Kc(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 UM(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 WM(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=Ts(e.path,{x:e.world.x+e.last.x,y:e.world.y+e.last.y})?.index,r=n===void 0?void 0:Ki({id:t,points:e.path},n);return r&&(e=>e.onlySegment(r))}function GM(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:VM,names:r,copper:i,...n===void 0?{}:{part:n},...o?{origin:o}:{}}}function KM(e,t,n){let r=e=>ve(e,n.step,n.snap);return{x:z(r(e.x+t.x)-e.x),y:z(r(e.y+t.y)-e.y)}}function qM(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:J_(e.points,e.grip,t,n)}:{...e,moved:!0,offset:KM(e.at??e.origin??VM,t,n)}}var JM=e=>e.kind===`group`?e.copper??[]:[e.id];function YM(e,t,n){return!e.moved||e.blocker?$_:e.kind===`track`?e.path?{tracks:new Map([[e.id,e.path]]),vias:new Map}:$_:ov(t,JM(e),e.offset,n).shapes}function XM(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 ZM(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?sv(r,e.path):void 0;return!i||`message`in i?i:{edits:[i],summary:`Reshape track ${e.id}`,shapes:YM(e,t,n)}}let r=JM(e),i=ov(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)??VM,o=e.kind===`group`?`Move ${et(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 QM(e,t){let[n,r]=(0,l.useState)([]),i=(0,l.useRef)(0);(0,l.useEffect)(()=>r(t=>pk(t,e)),[e]);let a=(0,l.useMemo)(()=>hk(n,e),[n,e]),o=(0,l.useMemo)(()=>gk(n,e),[n,e]),s=(0,l.useCallback)((e,t)=>{i.current+=1;let n=i.current;r(t=>uk(t,n,e)),t.then(e=>r(t=>e.ok&&e.mark!==void 0?dk(t,n,e.mark):fk(t,n)))},[]);return{shapes:a,moving:o,send:(0,l.useCallback)(e=>s({shapes:e.shapes},t.editLayout(e.edits,e.summary)),[s,t]),sendParts:(0,l.useCallback)((e,t)=>s({shapes:$_,parts:e},t),[s]),inFlight:mk(n)}}function $M(e){return(t,n)=>{let r=Y(e.pcb,t);return r!==void 0&&(r.layers===`through`||r.layers===n)}}function eN(e){(0,l.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(!pv(n.selection,n.routing===!0))return;let l=Ou(pu(t),{view:`pcb`}),u=l&&su(l.action);if(!l||!u||(t.preventDefault(),t.stopPropagation(),t.repeat&&s))return;let d=ot(u,n.step,l.steps??1,n.snap),f=ov(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 ${et(c)} by (${d.x}, ${d.y})`,shapes:f.shapes})};return window.addEventListener(`keydown`,t,!0),()=>window.removeEventListener(`keydown`,t,!0)},[e])}function tN(e,t,n,r){let{camera:i,selection:a}=e;if(!i||r.button!==0||e.armed===`note`||e.armed===`zoom`)return;let o=Wc(t,n,i.scale,e.layers,{selection:a,armed:e.armed,filter:e.filter});if(!o)return nN(e,n,r);if(Qi(r))return e.onSelect(e=>e.toggleCopper(o.id)),`toggled`;if(a.hasCopper(o.id)&&a.total>1)return GM({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=HM(o,t,{world:n,point:n,scale:i.scale,sole:s,width:c}),u=l&&UM(l,a.segment);return u?.segment===void 0&&e.onSelect(e=>e.onlyCopper(o.id)),u??`toggled`}function nN(e,t,n){let{selection:r,parts:i}=e;if(r.copper.length===0||Qi(n))return;let a=i.selectedAt(t);if(a!==void 0&&i.blockerFor(a)===null)return GM({part:a,names:r.names,copper:r.copper,start:t,origin:i.originOf(a)})}function rN(e,t,n){let r=lv(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 iN(e,t,n){let{segment:r}=e.selection;if(r&&n.length===1&&n[0]===r.id)return rN(e,t,r);let{edits:i,removed:a,skipped:o}=cv(t,n);o.length>0&&e.actions.notify(`Not removed: ${o.join(`; `)}`),i.length!==0&&e.actions.editLayout(i,`Remove ${et(a)}`).then(t=>t.ok&&e.onSelect(e=>e.withoutCopper(a)))}function aN(e){let{design:t,builtMark:n,actions:r,selection:i}=e,a=QM(n,r),o=(0,l.useMemo)(()=>dv(t.pcb,a.shapes),[t,a.shapes]),s=(0,l.useMemo)(()=>$M(t),[t]),[c,u]=(0,l.useState)(),[d,f]=(0,l.useState)(),p=(0,l.useRef)(void 0),m=e=>{p.current=e,u(e)},h={input:e,shown:o,onPad:s,send:a.send,sendParts:a.sendParts,cancel:()=>p.current?(m(void 0),!0):!1,inFlight:a.inFlight},g=(0,l.useRef)(h);g.current=h,eN(g),oN(o.tracks,i,e.onSelect);let _=(0,l.useMemo)(()=>c?dv(o,YM(c,o,s)):o,[c,o,s]);return{scene:{tracks:_.tracks,vias:_.vias,selected:new Set(i.copper),...i.segment?{segment:i.segment}:{},...d===void 0?{}:{hover:d}},shown:o,drag:c,hover:d,setHover:f,put:m,dragRef:p,latest:g,keys:(0,l.useMemo)(()=>({remove:e=>iN(g.current.input,g.current.shown,e)}),[]),moving:(0,l.useMemo)(()=>sN(c,e.parts)??a.moving,[c,e.parts,a.moving])}}function oN(e,t,n){let r=Zi(t,e)!==t;(0,l.useEffect)(()=>{r&&n(t=>Zi(t,e))},[r,e,n])}function sN(e,t){let n=e&&XM(e);return n&&{names:n.names.filter(e=>t.blockerFor(e)===null),offset:n.offset}}function cN(e,t){let{input:n,shown:r}=e.latest.current,i=n.camera&&Wc(r,t,n.camera.scale,n.layers,{selection:Xi.none,armed:n.armed,filter:n.filter});return i?i.id:void 0}function lN(e,t){let{input:n,shown:r}=e.latest.current;return n.camera&&Gc(r,t,n.camera.scale,n.layers,{selection:n.selection,armed:n.armed,filter:n.filter})}function uN(e,t){let n=cN(e,t);return e.setHover(n),n!==void 0}function dN(e){return(t,n)=>{let{input:r,shown:i}=e.latest.current,a=tN(r,i,n,t);return a&&a!==`toggled`&&e.put(a),a!==void 0}}function fN(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(qM(t,i,{step:r.step,snap:r.snap},e=>r.actions.notify(e)))}function pN(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(mN(t));let s=WM(t);s&&n.onSelect(s);let c=XM(t);c&&o(c,n.parts.move(c.names,c.offset));let l=ZM(t,r,i);l&&(`message`in l?n.actions.notify(l.message):a(l))}function mN(e){return t=>e.part===void 0?e.id?t.onlyCopper(e.id):t:t.only(e.part)}function hN(e,t,n){let r=t=>{let{input:n}=e.latest.current;return n.camera?pe(n.camera,n.size,_E(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);ie.refuses()||fN(e,a,o)},onPointerUp:n=>{let r=e.dragRef.current;r?pN(e,r):t.onPointerUp(n)},onPointerCancel:()=>{e.put(void 0),t.onPointerCancel()},onLostPointerCapture:()=>{e.put(void 0),t.onLostPointerCapture()}}}function gN(e){return e.drag?e.drag.blocker?`not-allowed`:`move`:e.hover===void 0?void 0:`pointer`}var _N={phase:`idle`};function vN(e,t,n,r){return e.phase===`shown`&&r?{...e,at:t}:e.phase===`dismissed`&&r?e:{phase:`waiting`,at:t,since:n}}function yN(e,t){switch(t.kind){case`move`:return vN(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}:_N;case`key`:case`press`:return e.phase===`shown`||e.phase===`dismissed`?{phase:`dismissed`,target:e.target}:_N;case`leave`:case`stale`:case`busy`:return _N}}function bN(e,t){return e.phase===`waiting`?Math.max(0,e.since+250-t):void 0}var xN=e=>e.phase===`shown`||e.phase===`dismissed`;function SN(e){if(e.phase===`shown`)return{text:e.target.text,left:e.at.x+12,top:e.at.y+12}}function CN(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 wN=1;function TN(e,t,n){let r=_N,i,a,o=!1,s=!1,c=()=>{a!==void 0&&e.clearTimer(a),a=void 0},l=()=>{c();let t=bN(r,e.now());t!==void 0&&(a=e.setTimer(d,t+wN))},u=e=>{let n=yN(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=xN(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 EN(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 DN={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 ON({enabled:e,busy:t,probe:n,camera:r,design:i}){let[a,o]=(0,l.useState)(_N),s=(0,l.useRef)(n);s.current=n;let c=(0,l.useRef)(void 0);return(0,l.useEffect)(()=>{let e=TN(DN,o,()=>s.current);return c.current=e,()=>{e.dispose(),c.current=void 0}},[]),(0,l.useEffect)(()=>c.current?.quiet(!e||t),[e,t]),(0,l.useEffect)(()=>c.current?.stale(),[r,i]),{state:a,...(0,l.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 kN({state:e}){let t=SN(e),n=(0,l.useRef)(null);return(0,l.useLayoutEffect)(()=>{let e=n.current,r=e?.parentElement;if(!e||!r||!t)return;let i=CN(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 AN=` · `;function jN(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 MN=e=>`${Number(e.toFixed(4))} mm`,NN=(e,t)=>e.circuit.components.find(e=>e.id===t);function PN(e,t){let n=NN(e,t.component),r=n?.pins.find(e=>e.id===t.pin),i=r&&An(n?.props??{},r.number),a=n?.instance===void 0?``:` [${n.instance}]`;return`${t.component}.${t.number}${i?` ${i}`:``}${AN}${jN(e,t.net)}${a}`}var FN=(e,t)=>`via ${t.id}${AN}${jN(e,t.net)}${AN}${t.layers[0]}–${t.layers.at(-1)}`;function IN(e,t){return`track ${t.id}${AN}${jN(e,t.net)}${AN}${MN(t.width)}${AN}${t.layer}${t.by===`router`?`${AN}routed`:``}`}var LN=new Set;function RN(e,t){let{design:n,scale:r,layers:i,context:a}=t;if(!Si({kind:`pour`,id:``},a))return;let o=n.pcb.holes?.find(t=>t.id===Cl(n.pcb.holes??[],e,r,i.visible));return o?{kind:`hole`,id:o.id,text:vl(o)}:zN(n,xl(n,e,r,i.visible,t.pours?.hidden??LN))}function zN(e,t){let n=t===void 0?void 0:pl(e).find(e=>e.id===t);return n&&{kind:`pour`,id:n.id,text:gl(e,n)}}function BN(e,t){let{design:n,layers:r,context:i}=t;if(n.pcb.pours&&Si({kind:`pour`,id:``},i))return zN(n,El(n,e,r.visible,t.pours?.hidden??LN,t.pours?.activeLayer))}function VN(e,t){let{design:n,copper:r,scale:i,layers:a,context:o}=t;if(dO(t.boxes,e,o,t.texts))return;let s=Wc(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:FN(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:IN(n,l)};let u=RN(e,t);if(u)return u;let d=Y(n.pcb,e,a.visible,e=>Si({kind:`part`,name:e},o));return d?{kind:`pad`,id:d.id,text:PN(n,d)}:BN(e,t)}function HN(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 UN=(e,t)=>`${t.component}.${An(NN(e,t.component)?.props??{},t.number)??`pin${t.number}`}`;function WN(e,t){let n=e.circuit.nets.find(e=>e.pins.includes(t.id));return`${UN(e,t)}${AN}${jN(e,n?.id)}`}function GN(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}${AN}${e.bus?`bus ${e.net}`:e.net}`}}}function KN(e,t){let{design:n}=t,r=Hn(n,e,12/t.scale),i=r&&n.schematic.symbols.find(e=>r.pin in e.pinEnds);if(!r||!i||!Si({kind:`part`,name:i.component},t.context))return;let a=NN(n,i.component)?.pins.find(e=>e.id===r.pin);return a?{kind:`pin`,id:a.id,text:WN(n,a)}:GN(n,r.pin)}function qN(e,t,n){let r=KN(t,n);if(!r)return e;let i=r.text.slice(0,r.text.indexOf(AN));return{...e,text:`${e.text}${AN}pin ${i}`,pin:r.id}}function JN(e,t){let{design:n}=t,r=uO(t.boxes,t.labels,e,t.context,t.wires,t.drawings,t.texts);if(r.kind===`label`)return qN({kind:`label`,id:r.label.id,text:HN(n,r.label)},e,t);if(r.kind===`wire`){let i=n.schematic.wires.find(e=>e.id===r.id);return qN({kind:`wire`,id:r.id,text:`wire${AN}${jN(n,i?.net)}`},e,t)}return r.kind===`drawing`?void 0:KN(e,t)}function YN(e,t){return t.view===`pcb`?VN(e,t):JN(e,t)}function XN(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)<=Bc(n.diameter,i)}if(e.kind===`track`){let n=r.tracks.find(t=>t.id===e.id);return n!==void 0&&Es(n.points,t,Bc(n.width,i))!==void 0}if(e.kind===`hole`)return Cl(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 xl(n.design,t,i,n.layers.visible,n.pours?.hidden??LN)===e.id||r!==void 0&&Tl(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&&Yd(o,t)<=0}function ZN(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 QN(e,t,n){return n.view===`pcb`?XN(e,t,n):ZN(e,t,n)}function $N({value:e,onChange:t}){let n=(0,l.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 eP=.1,tP=e=>Math.round(e*1e4)/1e4||0,nP=(e,t)=>e.x===t.x&&e.y===t.y,rP=(e,t)=>tP(Math.hypot(t.x-e.x,t.y-e.y));function iP(e,t){return tP((Math.atan2(t.y-e.y,t.x-e.x)*180/Math.PI%360+360)%360)%360}var aP=e=>({tool:e,points:[],flip:!1,dragging:!1});function oP(e,t,n){let r=ye(e,t,n);return{x:tP(r.x),y:tP(r.y)}}function sP(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 cP(e,t){return(e?.tool===`text`||e?.naming===!0)&&t===0}function lP(e,t,n){let r=e.points.at(-1);if(!r)return[t];let i=n?Sn([r,t],[e.flip]).slice(1):[t];return[...e.points,...i.map(e=>({x:tP(e.x),y:tP(e.y)}))].filter((e,t,n)=>t===0||!nP(e,n[t-1]))}function uP(e,t){let[n,r]=[tP(Math.abs(t.x-e.x)),tP(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 dP(e,t,n){let[r,i]=[iP(e,t),iP(e,n)];if(!(nP(n,e)||r===i))return{x:e.x,y:e.y,radius:rP(e,t),startAngle:r,endAngle:i}}var fP=(e,t)=>({state:aP(e),drawing:t}),pP=e=>({state:e});function mP(e){return e.points.length<2?pP(aP(e.tool)):e.tool===`bus`?pP({...e,naming:!0}):fP(`polyline`,{tag:`schematicpath`,props:{points:[...e.points]}})}function hP(e,t){return e.naming?pP(e):t.double&&e.points.length>0?mP(e):pP({...e,points:lP(e,t.at,t.shift)})}function gP(e,t){let[n]=e.points;if(!n)return pP({...e,points:[t],dragging:!0});let r=uP(n,t);return r?fP(`rectangle`,{tag:`schematicrect`,props:r}):pP(e)}function _P(e,t){let[n]=e.points;if(!n)return pP({...e,points:[t]});let r=rP(n,t);return r>0?fP(`circle`,{tag:`schematiccircle`,props:{x:n.x,y:n.y,radius:r}}):pP(e)}function vP(e,t){let[n,r]=e.points;if(!n)return pP({...e,points:[t]});if(!r)return nP(t,n)?pP(e):pP({...e,points:[n,t]});let i=dP(n,r,t);return i?fP(`arc`,{tag:`schematicarc`,props:i}):pP(e)}function yP(e,t){switch(e.tool){case`bus`:case`polyline`:return hP(e,t);case`rectangle`:return gP(e,t.at);case`circle`:return _P(e,t.at);case`arc`:return vP(e,t.at);case`text`:return pP({...e,points:[t.at]})}}function bP(e,t){let[n]=e.points;if(e.tool!==`rectangle`||!e.dragging||!n)return pP(e);let r=uP(n,t);return r?fP(`rectangle`,{tag:`schematicrect`,props:r}):pP({...e,dragging:!1})}function xP(e,t){let n=t.trim();return!e.naming||Zt(n)===void 0?pP(e):fP(`bus`,{tag:`bus`,name:n,props:{points:[...e.points]}})}function SP(e,t){if(e.tool===`bus`)return xP(e,t);let[n]=e.points,r=t.trim();return e.tool!==`text`||!n||r===``?pP(aP(e.tool)):fP(`text`,{tag:`schematictext`,props:{x:n.x,y:n.y,text:r,fontSize:eP,anchor:`left`}})}function CP(e,t){switch(t.type){case`press`:return yP(e,t);case`release`:return bP(e,t.at);case`finish`:return(e.tool===`polyline`||e.tool===`bus`)&&!e.naming?mP(e):pP(e);case`removeCorner`:return e.naming?pP(e):pP(e.points.length<=1?aP(e.tool):{...e,points:e.points.slice(0,-1)});case`flip`:return pP(e.naming?e:{...e,flip:!e.flip});case`cancel`:return{state:e.points.length>0?aP(e.tool):null};case`text`:return SP(e,t.text)}}var wP={file:``,line:0,column:0,offset:0},TP={strokeWidth:.01,lineStyle:`dashed`,groupOffset:{x:0,y:0},source:wP};function EP(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]:lP(e,t,n),groupOffset:TP.groupOffset,source:wP};if(e.tool===`polyline`)return{id:a,kind:`path`,points:lP(e,t,n),...TP};if(e.tool===`rectangle`){let e=uP(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,...TP}}if(e.tool===`circle`)return{id:a,kind:`circle`,x:r.x,y:r.y,radius:rP(r,t),filled:!1,...TP};if(e.tool!==`arc`)return;if(!i)return{id:a,kind:`path`,points:[r,t],...TP};let o=dP(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,...TP}}function DP(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:Zt(e.name??``)??[],points:n.points??[],groupOffset:TP.groupOffset,source:wP};case`schematicpath`:return{id:t,kind:`path`,points:n.points??[],...TP};case`schematicrect`:return{...i,kind:`rect`,width:r(`width`),height:r(`height`),filled:!1,...TP};case`schematiccircle`:return{...i,kind:`circle`,radius:r(`radius`),filled:!1,...TP};case`schematicarc`:return{...i,kind:`arc`,radius:r(`radius`),startAngle:r(`startAngle`),endAngle:r(`endAngle`),...TP};case`schematictext`:return{...i,kind:`text`,text:String(n.text??``),fontSize:eP,anchor:`left`,groupOffset:TP.groupOffset,source:wP}}}var OP=/^G(\d+)$/;function kP(e,t,n=[]){if(e.name!==void 0)return{kind:`addDrawing`,tag:e.tag,name:e.name,props:e.props};let r=Number(OP.exec(vC(t))?.[1]??1),i=Math.max(r-1,...n.map(e=>Number(OP.exec(e)?.[1]??0)));return{kind:`addDrawing`,tag:e.tag,name:`G${i+1}`,props:e.props}}var AP={bus:`bus`,polyline:`line`,rectangle:`rectangle`,circle:`circle`,arc:`arc`,text:`text`},jP=(e,t)=>`add the ${AP[e]} ${t}`,MP=`Esc or a right click stops.`,NP=`Esc cancels.`,PP={bus:`Click to start a bus, Enter to finish, then name it. ${MP}`,polyline:`Click to start a polyline, Enter to finish. ${MP}`,rectangle:`Drag, or click two opposite corners, to draw a rectangle. ${MP}`,circle:`Click the centre of a circle. ${MP}`,arc:`Click the centre of an arc. ${MP}`,text:`Click where the text goes. ${MP}`},FP=`Click for each corner, double click or Enter to finish. Shift keeps a leg square and Space flips its bend; Backspace removes a corner, ${NP}`;function IP(e){if(!e)return;let t=e.points.length;return t===0?PP[e.tool]:e.naming?`Name the bus, such as D[0:7] or CLK; Enter writes it, ${NP}`:e.tool===`polyline`||e.tool===`bus`?FP:e.tool===`rectangle`?`Click the opposite corner. ${NP}`:e.tool===`circle`?`Click to set the radius. ${NP}`:e.tool===`text`?`Type the text; Enter writes it, ${NP}`:t===1?`Click where the arc starts. Backspace steps back, ${NP}`:`Click where the arc ends. Backspace steps back, ${NP}`}var LP=e=>new Set(e.annotations.locks.map(e=>e.part));function RP(e,t){let[n,r]=(0,l.useState)(null),i=pl(e);return(0,l.useEffect)(()=>{n!==null&&i.some(e=>e.id===n)&&(t(e=>e.clear().onlyBoard(n)),r(null))},[i,n,t]),(0,l.useCallback)(e=>r(e),[])}var zP=e=>t=>(e.notify(`Not written: ${t instanceof Error?t.message:String(t)}`),!1);function BP(e,t){let[n,r]=(0,l.useState)(null),i=(0,l.useRef)(n);return i.current=n,{state:n,send:(0,l.useCallback)(e=>{let n=i.current;if(!n)return;let a=Av(n,e);i.current=a.state,r(a.state),(a.outline||a.hole||a.refused)&&t(a)},[t]),arm:(0,l.useCallback)(t=>{e(),i.current=wv(t),r(i.current)},[e]),disarm:(0,l.useCallback)(()=>{i.current=null,r(null)},[])}}function VP(e,t){(0,l.useEffect)(()=>{if(!e)return;let n=e.points.length>0,r=e=>{e.key!==`Escape`||pu(e).typing||(e.stopPropagation(),t({type:`cancel`}))},i=e=>{let r=n?Ou(pu(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 HP(e,t){let n=(0,l.useRef)(t);n.current=t,(0,l.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 UP(e,t){let{input:n}=e,r=Mv(n.design);if(r===void 0)return n.actions.notify(`The circuit has no net for a copper pour yet.`);let i=xv(n.circuit.model.boardItems??[],`copperpour`);n.actions.edit([Nv(r,n.activeLayer,t)],Pv(r,n.activeLayer,t===void 0)).catch(zP(n.actions)).then(t=>t&&e.waitForPour(i))}function WP(e,t){let n=Lv(e.diameter);if(typeof n!=`number`)return e.input.actions.notify(n.message);e.input.actions.edit([Fv(t,n)],Iv(n)).catch(zP(e.input.actions))}function GP(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`||!Si({kind:`pour`,id:``},{selection:o,armed:r.armed,filter:r.filter}))return!1;let s=Cl(a.pcb.holes,n,i.scale,r.layers)??xl(a,n,i.scale,r.layers,r.hidden);return s!==void 0&&(r.onSelect(e=>Qi(t)?e.toggleBoard(s):e.onlyBoard(s)),!0)}function KP(e,t,n,r){let{input:i}=e,a=i.selection.soleBoard,o=a===void 0?void 0:pl(i.design).find(e=>e.id===a);if(!o?.outline||!i.camera||t.button!==0||Qi(t))return!1;let s=Sl(o.outline,n,i.camera.scale);if(s===void 0)return!1;let c=zv(i.circuit.model,LP(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 qP=e=>e.outline.map((t,n)=>n===e.index?e.to:t);function JP(e){let{design:t,circuit:n,onSelect:r}=e,[i,a]=(0,l.useState)(String(Sv)),o=RP(t,r),[s,c]=(0,l.useState)(),u=(0,l.useRef)(void 0),[d,f]=(0,l.useState)(),[p,m]=(0,l.useState)();(0,l.useEffect)(()=>m(void 0),[t]);let h=e=>{u.current=e,c(e)},g={input:e,diameter:i,drag:s,waitForPour:o},_=(0,l.useRef)(g);_.current=g;let v=(0,l.useCallback)(e=>{e.refused&&_.current.input.actions.notify(e.refused),e.outline&&UP(_.current,e.outline),e.hole&&WP(_.current,e.hole)},[]),y=BP(e.onArm,v);VP(y.state,y.send);let{disarm:b}=y;(0,l.useEffect)(()=>{e.othersArmed&&b()},[e.othersArmed,b]),HP(s!==void 0,()=>h(void 0)),Py({placePour:()=>y.arm(`pour`),placeHole:()=>y.arm(`hole`),placePourBoard:()=>UP(_.current,void 0)});let x=(0,l.useRef)(void 0),S=t=>ye(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=sP(x.current,r);return x.current=i?void 0:r,y.send({type:`press`,at:S(n),double:i}),!0},w=(0,l.useMemo)(()=>{let e=new Map;return p&&e.set(p.id,p.outline),s?.moved&&e.set(s.id,qP(s)),e},[p,s]),T=jv(y.state,e.cursor&&S(e.cursor)),E={mode:e.mode,hidden:e.hidden,selected:new Set(e.selection.board),...d===void 0?{}:{hover:d},activeLayer:e.activeLayer,outlines:w,...T.length>0?{preview:T}:{}},ee=(0,l.useMemo)(()=>Hv(n.model,LP(n)),[n]);return{state:y.state,armed:y.state!==null,busy:y.state!==null&&y.state.points.length>0,disarm:y.disarm,hint:Wv(y.state),diameter:i,setDiameter:a,toolPress:C,cornerPress:(e,t)=>KP(_.current,e,t,h),pickPress:(e,t)=>GP(_.current,e,t),hoverAt:n=>{let{camera:r}=e,i={selection:e.selection,armed:e.armed,filter:e.filter},a=r&&Si({kind:`pour`,id:``},i)?Cl(t.pcb.holes,n,r.scale,e.layers)??xl(t,n,r.scale,e.layers,e.hidden):void 0;return f(a),a!==void 0},clearHover:()=>f(void 0),hover:d,drag:s,dragRef:u,put:h,release:t=>{if(h(void 0),!t.moved)return;let n=Rv(t.id,t.outline,t.index,t.to);if(`message`in n)return e.actions.notify(n.message);m({id:t.id,outline:qP(t)}),e.actions.edit([n.edit],n.summary).catch(zP(e.actions)).then(e=>e||m(void 0))},latest:_,scene:E,removal:ee,cursor:s?`move`:y.state?`crosshair`:d===void 0?void 0:`pointer`}}function YP(e,t,n){let r=t=>{let{input:n}=e.latest.current;return n.camera?pe(n.camera,n.size,_E(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)&&(ie.refuses()||e.put({...a,moved:!0,to:ye(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 XP(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 ZP=B.background;function QP(e,t){let n=e.circuit.nets.find(e=>e.id===t.net)?.names[0];return`${nk(e,t)}${n?` on ${n}`:``}`}function $P(e,t,n){(0,l.useEffect)(()=>{l_({active:e,stop:()=>{t(),n()}})},[e,t,n]),(0,l.useEffect)(()=>d_,[])}function eF(e,t){let{design:n,camera:r,size:i,layers:a,hoverPad:o,moving:s,boxes:c,hover:u,selection:d,locked:f,circuit:p,gesture:m,highlightNets:h,markers:g,activeViolation:_,grid:v,copper:y,texts:b,pours:x}=t,S=(0,l.useMemo)(()=>id(n.pcb,b.moves),[n.pcb,b.moves]),C=(0,l.useMemo)(()=>h.length>0?h:o?.net?[o.net]:ef,[h,o]);(0,l.useEffect)(()=>{if(!r)return;let t=xE(e.current,i,r,ZP,(e,t,n,r)=>WT(e,t,n,v,r));if(!t)return;let{ctx:n,ratio:o}=t;wd(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:g,..._?{activeViolation:_}:{},copper:y,pours:x}),n.setTransform(o,0,0,o,0,0),SE(n,r,i,{view:`pcb`,boxes:c,moving:s,hover:u,selection:d,locked:f,marks:p.annotations.marks,gesture:m,look:GT,ratio:o}),tE(n,{camera:r,size:i},b.shown,{selected:d.texts,hover:m?void 0:b.hover},GT,o)},[e,S,r,i,a,C,s,c,u,d,f,p,m,g,_,v,y,b,x])}function tF({unit:e,step:t,setStep:n,keep:r}){return(0,X.jsxs)(b_,{children:[(0,X.jsx)(AE,{step:t,options:zm(`pcb`,e),onChange:n}),(0,X.jsx)(jE,{...r,title:`Write the faded parts' positions into the code as pcbX and pcbY`})]})}function nF(e,t,n,r,i){let[a,o]=(0,l.useState)(),[s,c]=(0,l.useState)(),[u,d]=(0,l.useState)();return{part:a,text:s,pad:u,at:a=>{let s={selection:Xi.none,armed:null,layers:n,filter:r},l=uO(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),d(Y(e.pcb,a,n.visible,e=>Si({kind:`part`,name:e},s)))},leave:()=>{o(void 0),c(void 0),d(void 0)}}}function rF(e,t,n,r){let i=(0,l.useRef)(void 0);i.current=t;let a=(0,l.useCallback)(()=>i.current?cf(e.pcb,i.current,n):void 0,[e,n]),o=(0,l.useCallback)(t=>nf(e,t),[e]);return BM({...r,netUnderPointer:a,netsOf:o})}function iF({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 aF({parts:e,circuit:t,actions:n,selection:r,armed:i,pick:a,pickFilter:o}){return(0,l.useMemo)(()=>({selectedAt:t=>{let n=uO(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)=>vt(it(t,r,`pcb`,at(e.anchors,e.boxes),i,e.blockerFor),n)}),[e,t,n,r,i,a,o])}function oF(e,t){return(0,l.useMemo)(()=>xe(e.pcb.board?.outline??[])??Se(t.map(e=>e.box)),[e,t])}function sF({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=>dO(i,e,a,o),g=r=>{if(n.armed||t.armed)return;let o=h(r)?void 0:lN(e,r);if(o)return p(e=>e.onlySegment(o));if(!h(r)&&cN(e,r)!==void 0)return;let s=uO(i,void 0,r,a);s.kind===`part`&&f(s)},_=n=>{if(wx(`pcb`,n),m.at(n),h(n))return e.setHover(void 0),t.clearHover(),r.at(n);if(uN(e,n))return t.clearHover(),r.leave();r.at(n),t.hoverAt(n)},v=dN(e);return{pointer:EN(YP(t,hN(e,GO({camera:s,size:c,element:l,gestures:u,setCursor:d,hover:_,open:g,tool:XP({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 cF(e){let{design:t,builtFrom:n,builtMark:r,buildStatus:i,circuit:a,actions:o,selection:s,onSelect:c,highlight:u,onHighlight:d,unit:f,onToggleUnit:p,gridStyle:m,gridStep:h,snap:g,onGridStep:_,markers:v,activeViolation:y,focus:b,onFocused:x,layers:S,pickFilter:C}=e,w=(0,l.useRef)(null),T=(0,l.useRef)(null),E=gE(w),[ee,D]=(0,l.useState)(),O=(0,l.useMemo)(()=>({step:h,style:m}),[h,m]),k=(0,l.useMemo)(()=>gi(t.pcb.parts,S),[t,S]),A=pE(t,`pcb`,a),{camera:j,setCamera:te,fit:M}=vE(w,E,oF(t,A.boxes));yE(`pcb`,b,j,te,x),KO({selection:s,boxes:A.boxes,size:E,setCamera:te,notify:o.notify});let ne={view:`pcb`,circuit:a,actions:o,onSelect:c,blockerFor:A.blockerFor},N=CA(),P=(0,l.useRef)(()=>void 0),F=$O((0,l.useCallback)(()=>{N.disarm(),P.current()},[N])),re=(0,l.useCallback)(()=>{F.disarm(),N.disarm()},[F,N]),ie=JP({design:t,circuit:a,actions:o,camera:j,size:E,canvas:T,cursor:ee,layers:S,hidden:e.hiddenPours,filter:C,armed:F.tool,othersArmed:F.armed||N.armed!==null,selection:s,onSelect:c,step:h,snap:g,activeLayer:e.activeLayer,mode:e.pourFill,onArm:re});P.current=ie.disarm;let I=aN({design:t,builtMark:r,parts:aF({parts:A,circuit:a,actions:o,selection:s,armed:F.tool,pick:k,pickFilter:C}),camera:j,size:E,canvas:T,layers:S,filter:C,armed:F.tool,selection:s,onSelect:c,actions:o,step:h,snap:g,routing:N.route!==null}),ae=(0,l.useMemo)(()=>Jc(I.shown,S),[I.shown,S]);Xj({design:t,builtMark:r,selection:s,lockedParts:A.locked,routing:N.route!==null,send:e=>I.latest.current.send(e),busy:()=>I.latest.current.inFlight,notify:o.notify});let L=LA({design:t,builtMark:r,copper:I.shown,camera:j,cursor:ee,step:h,snap:g,layers:S,activeLayer:e.activeLayer,onActiveLayer:e.onActiveLayer,locked:A.locked,actions:o,arm:N,onArm:F.disarm});$P(L.command??ZO(F.which),F.disarm,N.disarm);let oe=(0,l.useCallback)(e=>{let n=t.pcb.parts.find(t=>t.component===e);return n!==void 0&&S[n.side===`top`?`topSilk`:`bottomSilk`]},[t,S]),se=eD({view:`pcb`,design:t,circuit:a,actions:o,locked:A.locked,builtFrom:n,drawn:oe}),R=UO({...ne,camera:j,setCamera:te,size:E,boxes:A.boxes,anchors:A.anchors,step:h,snap:g,builtFrom:n,selection:s,tool:{armed:F.tool,disarm:F.disarm},layers:k,copper:ae,copperAt:e=>cN(I,e),texts:se.tools,filter:C,onContextMenu:L.armed?L.cancel:e.onContextMenu}),ce=mE(A,h,g),le=(0,l.useMemo)(()=>iE(s.copper,s.total,I.shown),[s,I.shown]),ue=hE(T,s.primary,A.boxes,j,E,void 0,le),{rotateHeld:de}=rF(t,ee,S,{...ne,paused:L.routing||ie.busy,board:ie.removal,selection:s,layout:ce,builtMark:r,buildStatus:i,moveWaiting:R.pending!==void 0,fit:M,onHighlight:d,menuPlace:ue,onContextMenu:e.onContextMenu,copper:I.keys,texts:se}),pe=nF(t,A.boxes,k,C,se.tools),{gesture:me}=R,he=tD(se,me),ge=(0,l.useMemo)(()=>({...he,hover:pe.text}),[he,pe.text]),z=I.moving?{names:I.moving.names,offset:I.moving.offset}:R.moving,_e={...I.scene,activeLayer:e.activeLayer,routes:L.routes};eF(T,{design:t,camera:j,size:E,layers:S,hoverPad:pe.pad,moving:z,boxes:A.boxes,hover:pe.part,selection:s,locked:A.locked,circuit:a,gesture:me,highlightNets:u,markers:v,activeViolation:y,grid:O,copper:_e,texts:ge,pours:ie.scene});let ve={selection:s,armed:F.tool,layers:k,filter:C},ye=j&&{view:`pcb`,design:t,copper:I.shown,scale:j.scale,layers:k,context:ve,boxes:A.boxes,texts:se.tools,pours:{hidden:e.hiddenPours,activeLayer:e.activeLayer}},be=ye&&{pick:e=>YN(e,ye),still:(e,t)=>QN(e,t,ye)},xe=ON({enabled:e.hoverLabels,busy:L.routing,probe:be,camera:j,design:t}),Se={...xe,at:e=>j&&xe.move(e,fe(j,E,e))},{pointer:Ce,onLeave:we}=sF({copper:I,pours:ie,track:L,hover:pe,boxes:A.boxes,context:ve,texts:se.tools,camera:j,size:E,canvasRef:T,gestures:R,setCursor:D,onOpenProperties:e.onOpenProperties,onSelect:c,label:Se}),Te=L.armed?`crosshair`:ie.cursor??gN(I)??WO(me,F.armed,pe.part!==void 0||pe.text!==void 0);return(0,X.jsxs)(`div`,{className:`pcb-canvas`,ref:w,children:[(0,X.jsx)(iF,{canvasRef:T,size:E,cursorStyle:Te,pointer:Ce,onLeave:we,hint:F.hint??ie.hint??L.hint}),ie.state?.tool===`hole`&&(0,X.jsx)($N,{value:ie.diameter,onChange:ie.setDiameter}),(0,X.jsx)(kN,{state:xe.state}),(0,X.jsx)(tF,{unit:f,step:h,setStep:_,keep:{show:A.autoPlaced,onKeep:()=>Ve(t,`pcb`,A.blockerFor,o,a)}}),(0,X.jsx)(ME,{cursor:ee,zoom:j?.scale,unit:f,onToggleUnit:p,detail:L.status??(pe.pad&&QP(t,pe.pad)),gesture:me,rotateHeld:de,snap:g})]})}function lF(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 uF({palette:e,camera:t,size:n}){let{editing:r}=e;if(!r||!t)return null;let i=fe(t,n,r.at);return(0,X.jsx)(dF,{at:i,initial:r.initial,palette:e},`${r.pin??r.rename?.id??`tab`}:${r.at.x}:${r.at.y}`)}function dF({at:e,initial:t,palette:n}){let[r,i]=(0,l.useState)(t),[a,o]=(0,l.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 fF(e){let t=e.gridFifth?{fifth:e.gridFifth}:{};return{lines:{minor:e.grid,...t},dots:{minor:e.gridDot,...t,px:2}}}function pF(e,t,n,r,i,a=H()){$m(e,t,n,r,fF(a),i)}var mF=.12,hF=.09,gF=.14,_F=.06,vF=2,yF=[[`label`,hF],[`value`,gF]];function bF(e,t){return Fa(`detail`,La(e,t),Ia(mF,e,t))}function xF(e,t,n,r,i,a=1){let o=fe(t,n,{x:r.minX,y:r.minY}),s=fe(t,n,{x:r.maxX,y:r.maxY});e.lineWidth=a/i;let c=Ma(o,s,i,a);e.strokeRect(c.x,c.y,c.width,c.height)}function SF(e,t,n,r,i,a){let o=fe(t,n,r),s=fe(t,n,i),c=o.x===s.x,l=e=>c?{x:Ta(e.x,a),y:e.y}:{x:e.x,y:Ta(e.y,a)},[u,d]=[l(o),l(s)];e.moveTo(u.x,u.y),e.lineTo(d.x,d.y)}function CF(e,t,n,r){let i=Ia(n,t.scale,r);return Fa(`detail`,La(t.scale,r),i)?(e.font=ni(ti.regular,i/r),!0):!1}function wF(e,t,n,r,i,a,o){if(!i)return;let s=o===void 0?i:Qa(i,o*t.scale,t=>e.measureText(t).width);if(s===null)return;let c=za(fe(t,n,r),a);e.fillText(s,c.x,c.y)}function TF(e,t,n,r,i){let{sheet:a,dividers:{xs:o,ys:s}}=r;e.lineWidth=wa(i),e.beginPath();for(let r of o)SF(e,t,n,{x:r,y:a.outer.minY},{x:r,y:a.inner.minY},i),SF(e,t,n,{x:r,y:a.inner.maxY},{x:r,y:a.outer.maxY},i);for(let r of s)SF(e,t,n,{x:a.outer.minX,y:r},{x:a.inner.minX,y:r},i),SF(e,t,n,{x:a.inner.maxX,y:r},{x:a.outer.maxX,y:r},i);if(e.stroke(),bF(t.scale,i)&&CF(e,t,.12,i)){e.fillStyle=H().titleText,e.textBaseline=`middle`,e.textAlign=`center`;for(let a of r.labels)wF(e,t,n,a,a.text,i)}}function EF(e,t,n,r,i){let a=r.block;xF(e,t,n,a.box,i);for(let r of a.cells)xF(e,t,n,r.box,i);e.fillStyle=H().titleText,e.textBaseline=`middle`,e.textAlign=`left`;for(let[r,o]of yF)if(CF(e,t,o,i))for(let o of a.cells)o.kind===r&&wF(e,t,n,{x:o.box.minX+_F,y:(o.box.minY+o.box.maxY)/2},o.text,i,o.box.maxX-o.box.minX-2*_F)}function DF(e,t,n,r,i){let{sheet:a}=r;e.save(),Ba(e),e.strokeStyle=H().border,xF(e,t,n,a.outer,i,Aa(vF,i)),xF(e,t,n,a.inner,i),TF(e,t,n,r,i),EF(e,t,n,r,i),e.restore()}var OF=[{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}],kF=.2,AF=1.2,jF=.8,MF=10,NF=1e-6;function PF(e){return Math.round(e*MF)/MF}function FF(e,t){let n=t??{minX:0,minY:0,maxX:0,maxY:0},r=PF((n.minX+n.maxX)/2-e.width/2),i=PF((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+kF,minY:a.minY+kF,maxX:a.maxX-kF,maxY:a.maxY-kF},empty:t===void 0}}function IF(e){let{inner:t}=e;return{minX:t.maxX-4,minY:t.minY,maxX:t.maxX,maxY:t.minY+AF}}var LF=(e,t)=>e.minX<t.maxX&&t.minX<e.maxX&&e.minY<t.maxY&&t.minY<e.maxY;function RF(e,t){let{outer:n}=e;return t.minX-.5>=n.minX-NF&&t.minY-.5>=n.minY-NF&&t.maxX+.5<=n.maxX+NF&&t.maxY+.5<=n.maxY+NF&&!LF(t,IF(e))}function zF(e,t){let n=Math.max(0,t?OF.indexOf(t):0),r=OF.slice(n);if(!e)return FF(r[0],void 0);let i=r.map(t=>FF(t,e));return i.find(t=>RF(t,e))??i[i.length-1]}function BF(e,t){return t?e&&!e.empty&&RF(e,t)?e:zF(t,e&&!e.empty?e.size:void 0):e??zF(void 0)}function VF(e,t){return(e?.empty??!1)&&!t.empty}function HF(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 UF(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 WF=[[`Project`,`project`],[`Page`,`page`],[`File`,`file`],[`Date`,`date`],[`Rev`,`rev`]];function GF(e,t){let n=IF(e),r=AF/WF.length,i=n.minX+jF;return{box:n,cells:WF.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 KF(e){return e&&/^\d{4}-\d{2}-\d{2}/.test(e)?e.slice(0,10):``}function qF(e,t){return{sheet:e,dividers:UF(e),labels:HF(e),block:GF(e,t)}}function JF({design:e,circuit:t,actions:n,builtFrom:r}){let[i,a]=(0,l.useState)([]);(0,l.useEffect)(()=>a(e=>e.every(e=>e.sentAt>r)?e:e.filter(e=>e.sentAt>r)),[r]);let o=(0,l.useMemo)(()=>new Set(t.annotations.locks.map(e=>e.part)),[t]);return{tools:{boxes:(0,l.useMemo)(()=>e.schematic.labels.map(e=>({id:e.id,box:br(e)})),[e.schematic.labels]),at:t=>wr(e,t),blocker:n=>Rr(e,t,n,o),commit:(r,i)=>{let s=Br(e,t,r.id,i,o);if(!Array.isArray(s))return n.notify(s.blocked);let c=Fr(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,l.useMemo)(()=>i.filter(e=>e.sentAt>r),[i,r])}}function YF(e,t){return(0,l.useMemo)(()=>{let n=t&&Fr(e,t.id,t.at);return t&&n?{id:t.id,...n}:void 0},[e,t])}function XF(e){let t=(0,l.useRef)(QS(e));t.current.set(e),(0,l.useEffect)(()=>ZS.answer(e=>t.current.call(e)),[])}var ZF=.5,QF=.1,$F=/^[A-Za-z_][A-Za-z0-9_]*$/,eI=`Use letters, digits and _, starting with a letter or _`,tI=[`right`,`top`,`left`,`bottom`],nI={right:{x:1,y:0},left:{x:-1,y:0},top:{x:0,y:1},bottom:{x:0,y:-1}},rI=e=>Math.round(e*1e3)/1e3||0,iI=e=>rI(Math.round(e/QF)*QF);function aI(e,t){if(e===`gnd`)return`GND`;let n=t.trim();return e===`vcc`&&n===``?`VCC`:n}function oI(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=tI[(tI.indexOf(i)+a)%4]??i,s=nI[o];return{end:r,side:o,corner:{x:iI(r.x+s.x*ZF),y:iI(r.y+s.y*ZF)}}}var sI=(e,t)=>e.circuit.components.flatMap(e=>e.pins).find(e=>e.id===t),cI=(e,t)=>e.circuit.nets.find(e=>e.pins.includes(t));function lI(e){return e===``?`Name the net label`:$F.test(e)?void 0:eI}function uI(e,t,n,r){let i=jn(e,t),a=lI(n);if(a)return a;if(!ar(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(cI(e,t.id)?.names.includes(n))return`${i} is already on ${n}`}function dI(e,t,n,r,i,a){let o=sI(e,i),s=o&&oI(e,o);if(!o||!s)return{blocked:`No pin there`};let c=aI(n,r),l=uI(e,o,c,a);return l?{blocked:l}:[{kind:`addTrace`,from:jn(e,o),to:`net.${c}`,schematicRouteHints:[s.corner]}]}function fI(e,t,n){return e===`label`?`Add ${t} label at ${n}`:`Add ${t} at ${n}`}function pI(e,t,n,r){let i=sI(e,r),a=i&&oI(e,i);if(!i||!a)return;let o=aI(t,n),s=xf([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 mI(e,t,n){let r=cI(e,t);return r&&!r.names.includes(n)?r.names[0]:void 0}var hI=/^net\.([\w-]+)$/,gI=`schematicRouteHints`,_I=(e,t)=>hI.exec(e?.trim()??``)?.[1]===t,vI=(e,t)=>e.model.traces.filter(e=>_I(e.from,t)||_I(e.to,t));function yI(e,t,n,r){if(t.trim().startsWith(`net.`))return;let i=Mn(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 bI(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===gI&&t.schematicRouteHints))?`The trace on line ${t.line} has an expression; ${i}`:[t.from,t.to].map(t=>t===void 0?void 0:yI(e,t,n,r)).find(e=>e!==void 0):`The trace on line ${t.line} is read-only (${t.readonlyReason}); ${i}`}function xI(e,t,n){let r=e=>_I(e,t)?`net.${n}`:e??``,i=Object.entries(e.props).filter(([e])=>e!==gI),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 SI=(e,t)=>e.circuit.nets.filter(e=>e.id!==t.net).flatMap(e=>e.names);function CI(e,t,n,r,i){let a=r.trim(),o=n.text,s=lI(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=vI(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=>bI(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=>xI(e,o,a)),p=SI(e,n).includes(a)?{joins:a}:{};return{edits:[...d,...f],summary:c,...p}}function wI(e,t){if(t.style===`label`)return;let n=vI(e,t.text).length;return`Rename the ${t.text} net everywhere (${n} ${n===1?`connection`:`connections`})?`}var TI=12;function EI(e){let[t,n]=(0,l.useState)([]);return(0,l.useEffect)(()=>n(t=>t.every(t=>t.sentAt>e)?t:t.filter(t=>t.sentAt>e)),[e]),{visible:(0,l.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 DI(e){(0,l.useEffect)(()=>{let t=t=>{Ou(pu(t),{view:`schematic`})?.action===`armNetLabel`&&(t.preventDefault(),e(`label`))};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e])}function OI(e,t,n,r){(0,l.useEffect)(()=>{if(e!==`label`&&e!==`vcc`)return;let i=i=>{i.key!==`Tab`||i.shiftKey||pu(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 kI({design:e,circuit:t,actions:n,pending:r,setTyped:i}){let a=(0,l.useMemo)(()=>new Set(t.annotations.locks.map(e=>e.part)),[t]);return(o,s,c)=>{let l=dI(e,t,o,c,s,a);if(!Array.isArray(l))return n.notify(l.blocked);let u=aI(o,c),d=mI(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=pI(e,o,c,s),p=f&&r.add(f),m=l[0]?.kind===`addTrace`?l[0].from:s;n.edit(l,fI(o,u,m)).then(e=>e||p&&r.drop(p)),o===`label`&&i(``)}}function AI({design:e,circuit:t,actions:n}){let r=(0,l.useMemo)(()=>new Set(t.annotations.locks.map(e=>e.part)),[t]);return(i,a)=>{let o=CI(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 jI(e){let{tool:t,typed:n,camera:r,design:i,setTyped:a,setEditing:o}=e,s=kI(e),c=AI(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=Hn(i,a,TI/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=lI(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 MI(e){let[t,n]=(0,l.useState)(null),[r,i]=(0,l.useState)(``),[a,o]=(0,l.useState)(null),s=(0,l.useCallback)(()=>{n(null),i(``),o(null)},[]);return{tool:t,typed:r,setTyped:i,editing:a,setEditing:o,arm:(0,l.useCallback)(t=>{e(),n(t),i(``),o(null)},[e]),disarm:s}}function NI(e){let{camera:t,cursor:n}=e,{tool:r,typed:i,setTyped:a,editing:o,setEditing:s,arm:c,disarm:u}=MI(e.onArm),d=EI(e.builtFrom),f=jI({...e,tool:r,typed:i,setTyped:a,setEditing:s,pending:d});OI(r,i,(0,l.useMemo)(()=>n??{x:t?.cx??0,y:t?.cy??0},[n,t]),f.open),QO(r!==null,u),DI(c);let p=d.visible.map(e=>e.label);return{tool:r,armed:r!==null,arm:c,disarm:u,press:(e,t)=>(o?.rename&&s(null),f.press(e,t,u)),rename:t=>{let n=wI(e.circuit,t);(!n||window.confirm(n))&&s({at:t.at,initial:t.text,rename:t})},editing:o,cancelName:()=>f.open(null),submitName:e=>f.submitName(e,o),typed:i,ghosts:p,ghostWires:d.visible.map(e=>e.wire)}}var PI=(e,t,n=!1)=>({start:e,...t?{pin:t}:{},corners:[],bends:[],flip:n}),FI=e=>[...e.bends,e.flip],II=(e,t)=>wn([e.start.at,...e.corners,t],FI(e)),LI=12,RI=(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 zI(e,t,n){let{start:r,corners:i}=t;if(nr(n,r))return{};let a=zn(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=cr(e,r,n,i,FI(t));if(s.length===0)return{notice:`${r.label} and ${n.label} are already connected`};let c=rr(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:II(t,n.at),summary:`connect ${r.label} to ${n.label}`}}function BI(e){let[t,n]=(0,l.useState)({}),r=(0,l.useRef)({}),i=(0,l.useCallback)(e=>{r.current=e,n(t=>RI(t,e)?t:e)},[]);return(0,l.useEffect)(()=>i({}),[e,i]),{under:t,setUnder:i,underRef:r}}function VI(e){let[t,n]=(0,l.useState)([]);return(0,l.useEffect)(()=>n(t=>t.every(t=>t.sentAt>e)?t:t.filter(t=>t.sentAt>e)),[e]),{visible:(0,l.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 HI({drawing:e,setDrawing:t,setWiring:n,underRef:r,start:i,escape:a}){(0,l.useEffect)(()=>{let o=o=>{let s=Ou(pu(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`&&CE(o)&&a()};return window.addEventListener(`keydown`,o),()=>window.removeEventListener(`keydown`,o)},[e,t,n,r,i,a])}function UI(e,t,n,r,i){return(0,l.useMemo)(()=>{let a=t.end?.at??(n&&ye(n,r,i));return e&&a?II(e,a):void 0},[e,t,n,r,i])}var WI=(e,t,n)=>({step:t,snap:n,...e?{from:e.corners.at(-1)??e.start.at}:{}});function GI(e,t,n,r,i){if(!t)return{};let a=LI/t.scale,o=Hn(e,r,a)?.pin;if(!n&&!o)return{};let s=Un(e,r,a,i);return{...s?{end:s}:{},...o?{pin:o}:{}}}function KI(e,t,n,r){let[i,a]=(0,l.useState)(null);(0,l.useEffect)(()=>{i&&!e.schematic.drawings.some(e=>`bus:${e.id}`===i.bus.selector)&&a(null)},[e,i]);let o=(e,i,a)=>{let o=Yn(e,a);i===`start`?n(PI(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,l.useCallback)(()=>a(null),[]),start:(e,t)=>e.members?s(e,`start`):n(PI(e,t))}}function qI(e,t,n,r){return(i,a)=>{r(null);let o=zI(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 JI(e){let{design:t,camera:n,step:r,snap:i}=e,[a,o]=(0,l.useState)(!1),[s,c]=(0,l.useState)(null),{under:u,setUnder:d,underRef:f}=BI(e.buildId),p=VI(e.builtFrom),m=qI(t,e.actions,p,c),h=KI(t,s,c,m);HI({drawing:s,setDrawing:c,setWiring:o,underRef:f,start:h.start,escape:()=>h.picking?h.cancelPick():s?c(null):o(!1)});let g=UI(s,(0,l.useMemo)(()=>h.picking?.role===`end`?{end:h.picking.bus}:u,[h.picking,u]),e.cursor,r,i),_=(0,l.useMemo)(()=>[s?.pin,u.pin].filter(e=>e!==void 0),[s,u]),v=e=>GI(t,n,a||s!==null,e,WI(s,r,i)),y=(e,o)=>YI({design:t,camera:n,wiring:a,drawing:s,setDrawing:c,step:r,snap:i,finish:m,underAt:v,picks:h},e,o),b=(0,l.useCallback)(()=>{o(!1),c(null),h.cancelPick()},[h.cancelPick]),x=u.end!==void 0&&(a||s!==null||u.pin!==void 0&&Ln(t,u.pin));return{wiring:a,toggleWiring:()=>{b(),o(!a)},cancel:b,drawing:s,under:u,pendingWires:p.visible,preview:g,activePins:_,overPin:x,press:y,hover:e=>d(v(e)),leave:()=>d({}),picking:h.picking,pick:h.pick,cancelPick:h.cancelPick}}function YI(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=Un(e.design,n,LI/e.camera.scale,WI(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):XI(e.drawing,n,e,e.setDrawing),!0}let{end:r,pin:i}=e.underAt(n);return!r||!e.wiring&&!(i&&Ln(e.design,i))?!1:(e.picks.start(r,i),!0)}function XI(e,t,n,r){let i=ye(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 ZI=`This wire's new trace is still being built; reshape it again when the build is done`;function QI(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 $I=(e,t)=>t.startsWith(`net.`)?t:Mn(e,t)?.id,eL=(e,t)=>{let[n,r]=[$I(e,t.from??``),$I(e,t.to??``)];return n&&r?`wire:${n}|${r}`:void 0};function tL(e,t){let{writer:n}=t;if(n.kind!==`engine`)return{newTrace:!1,wire:t.id};if(n.onWire?.trace){let t=eL(e,n.onWire.trace);return t?{newTrace:!0,wire:t}:{newTrace:!0}}let[r,i]=[$I(e,n.from),$I(e,n.to)];return r&&i?{newTrace:!0,wire:QI(e.circuit.connections,r,i)}:{newTrace:!0}}function nL(e,t){return e.some(e=>e.id===t&&e.newTrace)?ZI:null}function rL(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 iL(e,t,n,r=ur){let i=cc(e,t,n);return i?lc(e,i,r):Ew}function aL(e,t,n,r,i,a){let o=e.schematic.wires.filter(e=>e.id!==n.id).map(e=>e.points);return ww(yw(e.schematic.drawings).filter(e=>oC(t.model,i,e.id,[`x`,`y`])===null),a??n.points,Ws(r),o)}function oL(e,t,n,r,i,a,o){let s=pc(e,n,r,a,o);return Array.isArray(s)?{edits:s.length===0?s:[...s,...aL(e,t,n,r,a,o)],summary:`${i} ${Fw(e,n)}`,points:Ws(r),...tL(e,n)}:s}function sL(e,t,n,r,i=ur,a){let o=cc(e,t,n);return o?oL(e,t,o,r,`reshape`,i,a):{blocked:Ew}}function cL(e,t,n,r,i=ur,a){let o=cc(e,t,n);if(!o)return{blocked:Ew};let s=a!==void 0&&!fc(a,o.points)?null:Lw(e,o,i);return s===null?oL(e,t,o,Us(a??o.points,r),`remove a corner of`,i,a):{blocked:s}}function lL(e,t,{design:n,builtFrom:r,onSelect:i}){(0,l.useEffect)(()=>{let{waiting:a,follow:o}=rL(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 uL(e){let{design:t,circuit:n,actions:r,locked:i,builtFrom:a}=e,[o,s]=(0,l.useState)([]);lL(o,s,e);let c=(0,l.useMemo)(()=>o.filter(e=>e.sentAt>a).map(({id:e,points:t})=>({id:e,points:t})),[o,a]),u=(0,l.useCallback)(e=>nL(o,e)??iL(t,n,e,i),[o,t,n,i]),d=(0,l.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]),f=(0,l.useCallback)(e=>c.find(t=>t.id===e)?.points,[c]);return{pending:c,blocker:u,commit:(0,l.useCallback)((e,r)=>d(e,sL(t,n,e,r,i,f(e))),[d,t,n,i,f]),dropCorner:(0,l.useCallback)((e,r)=>{let a=nL(o,e);d(e,a?{blocked:a}:cL(t,n,e,r,i,f(e)))},[d,o,t,n,i,f])}}async function dL(e,t){return`blocked`in e?(t.notify(e.blocked),!1):t.edit(e.edits,e.summary)}function fL({design:e,circuit:t,actions:n,locked:r,selection:i}){let a=(0,l.useCallback)((n,i,a)=>Jw(e,t,n,i,r,a),[e,t,r]),o=(0,l.useCallback)((t,n)=>If(e,t,n),[e]),s=(0,l.useCallback)(t=>Aw(e,t),[e]),c=(0,l.useCallback)(t=>{let n=e.schematic.labels.find(e=>e.id===t);return n&&$d(e.circuit.nets,n.net)},[e]);return Py({removeCorners:()=>{let a=i.soleWire;if(a===void 0)return n.notify(`Select one wire first.`);dL(Yw(e,t,a,r),n)}}),(0,l.useMemo)(()=>({net:s,removal:a,labelRemoval:o,labelNet:c}),[s,a,o,c])}function pL(e){let{design:t,camera:n,selection:r,wiring:i}=e,{pending:a,blocker:o,commit:s,dropCorner:c}=uL(e),u=(0,l.useMemo)(()=>Ic(t.schematic.wires,a),[t.schematic.wires,a]),d=(0,l.useCallback)(e=>e===void 0?void 0:u.find(t=>t.id===e),[u]),f=(0,l.useMemo)(()=>{let e=e=>n?Ds(u,e,Cs(n.scale)/n.scale):void 0;return i?{at:e,lines:u}:{at:e,lines:u,drag:{points:e=>d(e)?.points,blocker:o,commit:s}}},[u,n,d,o,s,i]),p={at:(e,t)=>n?Oc(f.drag,t,e,n.scale):void 0,drop:c};return{hits:f,selected:(0,l.useMemo)(()=>d(r.soleWire),[d,r.soleWire]),menuWire:(0,l.useMemo)(()=>r.size===0?d(r.wires.at(-1)):void 0,[d,r]),lineOf:d,keys:fL(e),pending:a,corners:p}}function mL({design:e,circuit:t,camera:n,locked:r}){let{drawings:i}=e.schematic,a=(0,l.useCallback)(e=>e===void 0?void 0:i.find(t=>t.id===e),[i]);return{hits:(0,l.useMemo)(()=>({at:e=>n?fD(i,e,6/n.scale,n.scale):void 0,boxes:mD(i),origin:e=>{let t=a(e);return t&&cC(t)},blocker:e=>{let n=a(e);return n?sC(t.model,r,n):null}}),[i,n,a,t.model,r]),removal:(0,l.useCallback)(e=>hC(t.model,i,r)(e),[t.model,i,r]),drawingOf:a}}var hL=7,gL=20;function _L(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 vL({draw:e,camera:t,size:n}){let r=_L(e);if(!r||!t)return null;let i=fe(t,n,r.at);return(0,X.jsx)(yL,{left:i.x-hL,top:i.y-gL,field:r,draw:e},r.label)}function yL({left:e,top:t,field:n,draw:r}){let[i,a]=(0,l.useState)(n.initial),[o,s]=(0,l.useState)(),c=(0,l.useRef)(null);return(0,l.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:$r},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 bL(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 xL=21,SL=6,CL=12,wL=e=>Math.min(e*xL+SL,220);function TL(e,t,n){let r=Math.min(e.x+CL,t.width-100),i=Math.min(e.y+CL,t.height-wL(n));return{left:Math.max(r,0),top:Math.max(i,0)}}function EL({wire:e,camera:t,size:n}){let{picking:r}=e;if(!r||!t)return null;let i=r.bus.members??[],{left:a,top:o}=TL(fe(t,n,r.bus.at),n,i.length),s=`${r.bus.selector}:${r.bus.at.x}:${r.bus.at.y}`;return(0,X.jsx)(DL,{left:a,top:o,name:r.bus.label,members:i,wire:e},s)}function DL({left:e,top:t,name:n,members:r,wire:i}){let[a,o]=(0,l.useState)(0),s=(0,l.useRef)(null);return(0,l.useEffect)(()=>{let e=requestAnimationFrame(()=>s.current?.focus());return()=>cancelAnimationFrame(e)},[]),(0,l.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=bL(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 OL={finishShape:{type:`finish`},removeCorner:{type:`removeCorner`},flipBend:{type:`flip`}};function kL(e){let[t,n]=(0,l.useState)([]);return(0,l.useEffect)(()=>n(t=>t.every(t=>t.sentAt>e)?t:t.filter(t=>t.sentAt>e)),[e]),{visible:(0,l.useMemo)(()=>t.filter(t=>t.sentAt>e).map(e=>e.drawing),[t,e]),add:(0,l.useCallback)(e=>{let t={drawing:e,sentAt:Date.now()};return n(e=>[...e,t]),t},[]),drop:(0,l.useCallback)(e=>n(t=>t.filter(t=>t!==e)),[])}}function AL(e,t){let[n,r]=(0,l.useState)([]);return(0,l.useEffect)(()=>{let i=n.filter(t=>e.schematic.drawings.some(e=>e.id===t));i.length!==0&&(t(()=>Xi.none.addDrawings(i)),r(e=>e.filter(e=>!i.includes(e))))},[e,n,t]),{wait:(0,l.useCallback)(e=>r(t=>[...t,e]),[]),forget:(0,l.useCallback)(e=>r(t=>t.filter(t=>t!==e)),[])}}function jL(e){let[t,n]=(0,l.useState)(!1);return(0,l.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 ML(e){(0,l.useEffect)(()=>{let t=t=>{let n=Ou(pu(t),{view:`schematic`})?.action;n&&w(n)&&(t.preventDefault(),e(C[n]))};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e]),Py(Object.fromEntries(x.map(t=>[t,()=>e(C[t])])))}function NL(e,t){(0,l.useEffect)(()=>{if(!e)return;let n=e.points.length>0,r=e=>{ku(pu(e))&&(e.stopPropagation(),t({type:`cancel`}))},i=e=>{let r=n?Ou(pu(e),{view:`schematic`,drawing:!0})?.action:void 0,i=r===void 0?void 0:OL[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 PL(e,t){let[n,r]=(0,l.useState)(null),i=(0,l.useRef)(n);return i.current=n,{state:n,send:(0,l.useCallback)(e=>{let n=i.current;if(!n)return;let a=CP(n,e);i.current=a.state,r(a.state),a.drawing&&t(n.tool,a.drawing)},[t]),arm:(0,l.useCallback)(t=>{e(),i.current=aP(t),r(i.current)},[e]),disarm:(0,l.useCallback)(()=>{i.current=null,r(null)},[])}}function FL(e,t){let{circuit:n,actions:r}=e,{add:i,drop:a,visible:o}=t,{wait:s,forget:c}=AL(e.design,e.onSelect),u=(0,l.useRef)([]);return{write:(0,l.useCallback)((e,t)=>{let{model:l}=n;u.current=u.current.filter(e=>!l.drawings.some(t=>t.name===e||t.id===e));let d=kP(t,l,u.current),f=d.name??``,p=AC(l,f,o.flatMap(e=>e.kind===`bus`?[e.name]:[]));u.current=[...u.current,f];let m=i(DP(t,p));s(p),r.edit([d],jP(e,f)).catch(()=>!1).then(e=>{e||(u.current=u.current.filter(e=>e!==f),a(m),c(p))})},[n,r,s,c,i,a,o]),taken:u}}function IL(e,t,n,r){return{submitText:r=>{let i=e?.tool===`bus`?DC(n,r):void 0;return i||t({type:`text`,text:r}),i},busName:()=>EC(n,r.current)}}function LL(e){let{camera:t,cursor:n,step:r,snap:i}=e,a=kL(e.builtFrom),{write:o,taken:s}=FL(e,a),{state:c,send:u,arm:d,disarm:f}=PL(e.onArm,o),p=jL(c!==null),m=(0,l.useRef)(void 0);ML(d),NL(c,u);let h=(0,l.useMemo)(()=>c&&n?EP(c,oP(n,r,i),p):void 0,[c,n,r,i,p]),g=(e,n)=>{if(!c||!t||e.button===1)return!1;if(cP(c,e.button)&&e.preventDefault?.(),e.button===2)return u({type:`cancel`}),!0;let a={at:{x:n.x*t.scale,y:n.y*t.scale},time:Date.now()},o=sP(m.current,a);return m.current=o?void 0:a,u({type:`press`,at:oP(n,r,i),shift:e.shiftKey,double:o}),!0},_=(0,l.useMemo)(()=>h?[...a.visible,h]:a.visible,[a.visible,h]);return{state:c,tool:c?.tool??null,armed:c!==null,busy:c!==null&&c.points.length>0,arm:d,disarm:f,press:g,release:e=>{c&&u({type:`release`,at:oP(e,r,i)})},...IL(c,u,e.circuit.model,s),cancelText:()=>u({type:`cancel`}),pending:_}}var RL=.2,zL=.2,BL=1.2,VL=.6,HL=.4,UL=e=>xt(Math.ceil(e/RL-1e-9)*RL),WL=e=>Math.max(0,...e.map(e=>e.name.length))*bt*yt[`pin-name`];function GL(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)*RL,i=(n([`left`,`right`])+1)*RL,a=WL(t(`left`))+WL(t(`right`))+HL;return{width:UL(Math.max(BL,r,a)),height:UL(Math.max(VL,i))}}function KL(e,t,n,r){let i=xt(t*RL);return e===`left`?{edge:St(0,-i),end:St(-.2,-i)}:e===`right`?{edge:St(n,-i),end:St(n+zL,-i)}:e===`top`?{edge:St(i,0),end:St(i,zL)}:{edge:St(i,-r),end:St(i,-r-zL)}}function qL(e,t={}){let n=GL(e),r=Math.max(n.width,UL(t.width??0)),i=Math.max(n.height,UL(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,...KL(e.side,e.order,r,i)}))}}function JL(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)/RL)-1);return Math.min(a,Math.max(1,Math.round(i/RL)))}function YL(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:JL(r,e,t,n)}}function XL(e,t){let n=un(e,t),r=e.schematic.symbols.find(e=>e.component===t);if(n&&r)return{instance:n,placed:r,layout:qL(n.ports,n.size)}}var ZL=(e,t)=>Nu(t,e.placed),QL=(e,t)=>Mu({x:t.x-e.placed.x,y:t.y-e.placed.y},-e.placed.rotation);function $L(e,t){return t.flatMap(t=>{let n=XL(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:ZL(n,e.edge)})),{kind:`corner`,instance:t,file:r.file,at:ZL(n,{x:i.width,y:-i.height})}]})}function eR(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 tR(e,t,n){let r=XL(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=YL(QL(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 nR=e=>Math.round(Math.ceil(e/RL-1e-9)*RL*1e3)/1e3;function rR(e,t,n){let r=XL(e,t.instance);if(!r)return{message:`${t.instance} is gone`};let i=QL(r,n),a=Math.max(r.layout.needed.width,nR(i.x)),o=Math.max(r.layout.needed.height,nR(-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 iR=6;function aR({design:e,selection:t,camera:n,actions:r}){let i=(0,l.useMemo)(()=>$L(e,t.names),[e,t.names]),[a,o]=(0,l.useState)(),s=(0,l.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=eR(i,t,iR/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`?tR(e,n,t):rR(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 oR=`noConnect`;function sR(e){return typeof e==`string`?[...new Set(e.split(`,`).map(e=>e.trim()).filter(e=>e!==``))]:[]}var cR=(e,t)=>e.names.includes(t)||`pin${e.number}`===t;function lR(e,t){let n=sR(e);return(n.some(e=>cR(t,e))?n.filter(e=>!cR(t,e)):[...n,`pin${t.number}`]).join(`,`)}function uR(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 dR(e,t,n){let r=uR(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[oR];if(o&&o.literal===void 0)return{message:`${a.name}.${oR} is an expression (${o.source}); change it in the code.`};let s=lR(o?.literal,i),c=`${sR(s).length<sR(o?.literal).length?`remove the no connect flag from`:`flag no connect on`} ${r.pin}`;return{edit:{kind:`setProps`,part:a.name,props:{[oR]:s===``?null:s}},summary:c}}function fR(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 pR(e,t,n){let r;for(let i of e.wires)for(let e=1;e<i.points.length;e++){let a=fR(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:z(r.point.x),y:z(r.point.y)}}}function mR(e,t,n){let r=pR(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 hR=12,gR={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 _R(e){let[t,n]=(0,l.useState)(null),r=(0,l.useRef)(e);r.current=e;let i=(0,l.useCallback)(e=>{r.current.onArm(),n(e)},[]),a=(0,l.useCallback)(()=>n(null),[]);return Py({noConnect:()=>i(`noConnect`),junction:()=>i(`junction`)}),(0,l.useEffect)(()=>{let e=e=>{let r=pu(e);if(ku(r)&&t)return e.stopPropagation(),n(null);Ou(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=hR/c.scale,d=t===`junction`?mR(a.schematic,i,u):dR({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?gR[t]:void 0}}var vR={cx:0,cy:0,scale:60},yR=.06,bR=12;function xR(e,t,n,r){return{sheet:(0,l.useMemo)(()=>{let t=CM(e.schematic,r);return n.length===0&&t===e.schematic.labels?e.schematic:{...e.schematic,wires:[...Ic(e.schematic.wires,n)],labels:[...t]}},[e.schematic,n,r]),selected:(0,l.useMemo)(()=>t&&Ic([t],n)[0],[t,n])}}function SR(e,t){let{design:n,border:r,camera:i,size:a,moving:o,boxes:s,hover:c,selection:u,locked:d,circuit:f,gesture:p,movingLabels:m,hoverLabel:h,hoverDrawing:g,hoverWire:_,palette:v,highlight:y,markers:b,activeViolation:x,grid:S,texts:C,theme:w}=t,{wiring:T,drawing:E,activePins:ee,pendingWires:D,preview:O}=t.wire,{ghosts:k,ghostWires:A,armed:j}=v,te=t.draw.pending,M=xR(n,t.selectedWire,t.wireShapes,o),ne=M.selected,N=(0,l.useMemo)(()=>rd(M.sheet,C.moves),[M.sheet,C.moves]);(0,l.useEffect)(()=>{let t=i??vR,n=da(w);pa(n);let l=KT(n),v=mc(n),M=xE(e.current,a,t,n.background,(e,t,r,i)=>pF(e,t,r,S,i,n));if(!M)return;let{ctx:P,ratio:F}=M;DF(P,t,a,r,F),Yo(P,N,{camera:t,size:a},{ratio:F,showPins:T||E!==null||j,activePins:ee,pending:[...D,...A,...m.map(e=>e.wire)],movingLabels:m,ghostLabels:k,selectedWires:u.wires,selectedLabels:u.labels,selectedDrawings:u.drawings,...o?.drawings?{movingDrawings:o.drawings}:{},pendingDrawings:te,...y?{highlight:y}:{},...o?{moving:{components:o.names,by:o.offset}}:{},violations:b,...x?{activeViolation:x}:{}}),P.setTransform(F,0,0,F,0,0),O&&eE(P,t,a,O,`drawing`,n.wire,F),SE(P,t,a,{view:`schematic`,boxes:s,moving:o,hover:E?void 0:c,selection:u,locked:d,marks:f.annotations.marks,gesture:p,look:l,ratio:F}),h&&!E&&!p&&qT(P,t,a,xr(h),{x:0,y:0},`hover`,l,F),tE(P,{camera:t,size:a},C.shown,{selected:u.texts,hover:E||p?void 0:C.hover},l,F),g&&!u.hasDrawing(g.id)&&!E&&!p&&qT(P,t,a,pD(g),{x:0,y:0},`hover`,l,F),!_||u.hasWire(_.id)||T||E||p||Cc(P,t,a,_.points,v,F),ne&&!m.some(e=>e.hideWire===ne.id)&&wc(P,t,a,ne.points,v,F)},[e,N,r,i,a,T,E,ee,D,O,o,m,h,g,_,ne,s,c,u,d,f,p,k,A,j,te,y,b,x,S,C,w])}function CR({step:e,setStep:t,keep:n}){return(0,X.jsxs)(b_,{children:[(0,X.jsx)(AE,{step:e,options:zm(`schematic`),onChange:t}),(0,X.jsx)(jE,{...n,title:`Write the faded symbols' positions into the code as schX and schY`})]})}function wR({boxes:e,wire:t,labels:n,filter:r,wires:i,drawings:a,texts:o,setCursor:s}){let[c,u]=(0,l.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),u(uO(e,n,s,{selection:Xi.none,armed:null,filter:r},i,a,o))},leave:()=>{u({kind:`canvas`}),s(void 0),t.leave()}}}function TR({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??kR(c)??lF(l)??IP(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)(uF,{palette:l,camera:r,size:n}),(0,X.jsx)(vL,{draw:d,camera:r,size:n}),(0,X.jsx)(EL,{wire:c,camera:r,size:n}),(0,X.jsx)(kN,{state:_}),(0,X.jsx)(ME,{cursor:i,zoom:(r??vR).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 ER(e,t,n){XF(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 DR(e){let t=(0,l.useRef)(void 0),n=(0,l.useMemo)(()=>Ab(e.schematic),[e.schematic]);return(0,l.useMemo)(()=>{let e=BF(t.current,n);return t.current=e,e},[n])}function OR(e,t){let n=(0,l.useRef)(void 0);(0,l.useEffect)(()=>{VF(n.current,e)&&t(),n.current=e},[e,t])}function kR(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 AR(e,t){return(0,l.useMemo)(()=>tf(e,t),[e,t])}function jR(e,t,n){return(0,l.useMemo)(()=>{let r=Fc(e?.kind===`reshape`?e:void 0,t);return n&&n.length>0?[...n,...r]:r},[e,t,n])}function MR(e,t,n){return(0,l.useMemo)(()=>e&&e.sentAt>t?bM(e,n):void 0,[e,t,n])}function NR(e,t,n,r){let i=YF(e,(0,l.useMemo)(()=>t?.kind===`label`&&t.moved&&!t.blocker?{id:t.label.id,at:t.at}:void 0,[t]));return(0,l.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 PR({design:e,builtFrom:t,camera:n,cursor:r,fit:i,wire:a,palette:o,drawBusy:s,highlightNets:c,onHighlight:u,keys:d,texts:f}){let p=(0,l.useRef)(void 0);p.current=r;let m=(0,l.useCallback)(()=>n&&p.current?Qd(e,p.current,bR/n.scale):void 0,[e,n]),h=(0,l.useCallback)(t=>nf(e,t),[e]),{rotateHeld:g,keyMove:_}=BM({...d,paused:a.drawing!==null||s,fit:i,netUnderPointer:m,netsOf:h,onHighlight:u,texts:f}),{wiring:v,drawing:y}=a,{disarm:b}=o;return(0,l.useEffect)(()=>{(v||y)&&b()},[v,y,b]),Py({wire:()=>{b(),v||a.toggleWiring()},netLabel:()=>o.arm(`label`),groundFlag:()=>o.arm(`gnd`),powerFlag:()=>o.arm(`vcc`)}),Py({tidySheet:()=>Ye(e,d.blockerFor,d.actions,d.circuit)}),{highlight:AR(e,c),rotateHeld:g,keyMoving:MR(_,t,d.layout.anchors)}}function FR(e,t,n,r,i){let{wiring:a,cancel:o}=e,{tool:s,disarm:c}=t,{which:u,disarm:d}=n,{disarm:f}=r,{disarm:p}=i,m=i_(a,s)??a_(r.tool)??i.tool??ZO(u);(0,l.useEffect)(()=>{l_({active:m,stop:()=>{c(),o(),d(),f(),p()}})},[m,c,o,d,f,p]),(0,l.useEffect)(()=>d_,[])}function IR(e,t,n,r,i){let{cancel:a,wiring:o,drawing:s}=t,{disarm:c,armed:u}=n,{disarm:d,armed:f}=r,{disarm:p,armed:m}=i,h=(0,l.useCallback)(()=>{c(),a(),d(),p()},[c,a,d,p]),g=_R({...e,onArm:h}),_=g.disarm;return(0,l.useEffect)(()=>{(o||s||u||f||m)&&_()},[o,s,u,f,m,_]),g}function LR(e,t){let{cancel:n,wiring:r,drawing:i}=e,{disarm:a,armed:o}=t,s=$O((0,l.useCallback)(()=>{a(),n()},[a,n])),c=s.disarm;return(0,l.useEffect)(()=>{(r||i||o)&&c()},[r,i,o,c]),s}function RR(e,t,n,r){let{cancel:i,wiring:a,drawing:o}=t,{disarm:s,armed:c}=n,{disarm:u,armed:d}=r,f=(0,l.useCallback)(()=>{s(),i(),u()},[s,i,u]),p=LL({...e,onArm:f}),m=p.disarm;return(0,l.useEffect)(()=>{(a||o||c||d)&&m()},[a,o,c,d,m]),p}function zR(e,t,n,r){let{disarm:i}=e,{disarm:a}=t,{disarm:o}=n,{disarm:s}=r,c=(0,l.useCallback)(()=>{i(),a(),o(),s()},[i,a,o,s]);return{armed:e.tool??(t.armed||n.armed||r.armed?`place`:null),disarm:c}}function BR({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,_=uO(e,t,f,u,n,r),v=fO({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 GO({...h,tool:_,toolRelease:v,open:y})}function VR(e){let{design:t,buildId:n,builtMark:r,buildStatus:i,project:a,builtFrom:o,circuit:s,actions:c,selection:u,onSelect:d,highlight:f,onHighlight:p,gridStyle:m,gridStep:h,snap:g,onGridStep:_,markers:v,activeViolation:y,focus:b,onFocused:x}=e,S=(0,l.useRef)(null),C=(0,l.useRef)(null),w=gE(S),[T,E]=(0,l.useState)(),ee=(0,l.useMemo)(()=>({step:h,style:m}),[h,m]),D=pE(t,`schematic`,s),O=DR(t),{camera:k,setCamera:A,fit:j}=vE(S,w,O.outer,yR);OR(O,j);let te=(0,l.useMemo)(()=>qF(O,{project:a??``,page:`Schematic`,file:s.file,date:KF(n),rev:``}),[O,a,s.file,n]);yE(`schematic`,b,k,A,x),KO({selection:u,boxes:D.boxes,size:w,setCamera:A,notify:c.notify});let M=JI({design:t,actions:c,camera:k,cursor:T,step:h,snap:g,buildId:n,builtFrom:o}),ne=aR({design:t,selection:u,camera:k,actions:c}),N=NI({design:t,circuit:s,actions:c,camera:k,cursor:T,builtFrom:o,onArm:M.cancel}),P=LR(M,N),F=RR({design:t,circuit:s,actions:c,camera:k,cursor:T,step:h,snap:g,builtFrom:o,onSelect:d},M,N,P),re=(0,l.useMemo)(()=>({design:t,locked:D.locked}),[t,D.locked]),ie={view:`schematic`,circuit:s,actions:c,onSelect:d,blockerFor:D.blockerFor,follow:re},I=JF({design:t,circuit:s,actions:c,builtFrom:o}),ae=pL({design:t,circuit:s,actions:c,locked:D.locked,camera:k,selection:u,onSelect:d,builtFrom:o,wiring:M.wiring||M.drawing!==null}),L=mL({design:t,circuit:s,camera:k,locked:D.locked}),oe=eD({view:`schematic`,design:t,circuit:s,actions:c,locked:D.locked,builtFrom:o}),se=IR({design:t,circuit:s,actions:c,camera:k,locked:D.locked},M,N,P,F),R=zR(P,N,F,se);FR(M,N,P,F,se);let ce=UO({...ie,camera:k,setCamera:A,size:w,boxes:D.boxes,anchors:D.anchors,step:h,snap:g,builtFrom:o,labels:I.tools,wires:ae.hits,drawings:L.hits,texts:oe.tools,selection:u,tool:R,filter:e.pickFilter,onContextMenu:e.onContextMenu});ER(t,N,c);let le=mE(D,h,g),ue=hE(S,u.primary,D.boxes,k,w,ae.menuWire),de={...ie,selection:u,layout:le,builtMark:r,buildStatus:i,moveWaiting:ce.pending!==void 0,menuPlace:ue,onContextMenu:e.onContextMenu,wire:ae.keys,drawings:L.removal},{highlight:pe,rotateHeld:me,keyMoving:he}=PR({design:t,builtFrom:o,camera:k,cursor:T,fit:j,wire:M,palette:N,drawBusy:F.busy,highlightNets:f,onHighlight:p,keys:de,texts:oe}),ge=wR({boxes:D.boxes,wire:M,labels:I.tools,filter:e.pickFilter,wires:ae.hits,drawings:L.hits,texts:oe.tools,setCursor:E}),{gesture:z}=ce,_e=tD(oe,z),ve=(0,l.useMemo)(()=>({..._e,hover:ge.text}),[_e,ge.text]),ye=ce.moving??he,be=NR(t,z,I.pending,ye?.labels),xe=(0,l.useMemo)(()=>ae.lineOf(ge.wire),[ae.lineOf,ge.wire]),Se=jR(z,ae.pending,ye?.wires);SR(C,{design:t,border:te,camera:k,size:w,wire:M,moving:ye,boxes:D.boxes,hover:ge.part,selection:u,locked:D.locked,circuit:s,gesture:z,movingLabels:be,hoverLabel:ge.label,hoverDrawing:L.drawingOf(ge.drawing),hoverWire:xe,selectedWire:ae.selected,wireShapes:Se,palette:N,draw:F,highlight:pe,markers:v,activeViolation:y,grid:ee,texts:ve,theme:e.theme});let Ce={selection:u,armed:R.armed,filter:e.pickFilter},we=e=>un(t,e)?.file,Te=k??vR,Ee={view:`schematic`,design:t,scale:Te.scale,context:Ce,boxes:D.boxes,labels:I.tools,wires:ae.hits,drawings:L.hits,texts:oe.tools},De=ON({enabled:e.hoverLabels,busy:M.drawing!==null||F.busy,probe:{pick:e=>YN(e,Ee),still:(e,t)=>QN(e,t,Ee)},camera:k,design:t}),Oe=e=>{wx(`sch`,e),ge.at(e),De.move(e,fe(Te,w,e))},ke=()=>{De.leave(),ge.leave()},Ae=EN(BR({symbolEdit:ne,sheetOf:we,onOpenSheet:e.onOpenSheet,camera:k,size:w,element:S,gestures:ce,setCursor:E,hover:Oe,boxes:D.boxes,labels:I.tools,wires:ae.hits,drawings:L.hits,corners:ae.corners,wire:M,palette:N,note:P,draw:F,marks:se,picking:Ce,onOpenProperties:e.onOpenProperties}),De,C),je=WO(z,M.drawing!==null||M.overPin||N.armed||P.armed||F.armed||se.armed,ge.over);return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(CR,{step:h,setStep:_,keep:{show:D.autoPlaced,onKeep:()=>Ve(t,`schematic`,D.blockerFor,c,s)}}),(0,X.jsx)(TR,{wrapRef:S,canvasRef:C,size:w,camera:k,cursor:T,pointer:Ae,onLeave:ke,cursorStyle:je,wire:M,palette:N,note:P,draw:F,gesture:z,rotateHeld:me,snap:g,empty:D.boxes.length===0,symbolHint:ne.hint,label:De.state,markHint:se.hint})]})}function HR(){document.getElementById(`doc-panel`)?.focus()}function UR({text:e,seq:t,onText:n,onSearch:r,onClose:i,status:a}){let o=(0,l.useRef)(null);(0,l.useEffect)(()=>{let e=()=>{o.current?.focus(),o.current?.select()};e();let t=window.setTimeout(e,0);return()=>window.clearTimeout(t)},[t]);let s=()=>{i(),HR()};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)(Ap,{})}),(0,X.jsx)(`span`,{className:`find-status`,role:`status`,"aria-live":`polite`,children:a})]})}var WR=new Set([`name`,`pcbX`,`pcbY`,`pcbRotation`,`schX`,`schY`,`schRotation`,`layer`,`side`]),GR=`Press Ctrl+F to find a part or a net.`,KR=e=>`Nothing matches "${e}".`;function qR(e,t){return e===null?``:t===0?`No results`:t===1?`1 result`:`${t} results`}var JR=new Intl.Collator(`en`,{numeric:!0});function YR(e){let t=new Map(wf(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 XR=e=>typeof e==`string`||typeof e==`number`?String(e):void 0;function ZR(e,t){return t.find(t=>t.component===e.tag)}function QR(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=WR.has(t)?void 0:XR(r.literal);e!==void 0&&n.push({field:t,text:e})}let r=ZR(e,t);return r?.mpn&&n.push({field:`mpn`,text:r.mpn}),r&&n.push({field:`title`,text:r.title}),n}function $R(e,t,n){let r=QR(e,t).filter(e=>e.text.toLowerCase().includes(n));return r.filter((e,t)=>r.findIndex(t=>t.field===e.field)===t)}function ez(e,t){return e.names.filter(e=>e.toLowerCase().includes(t)).map(e=>({field:`net name`,text:e}))}var tz=(e,t)=>JR.compare(e.name,t.name);function nz(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:$R(e,r,i)})).filter(e=>e.matches.length>0).sort(tz),o=n.map(e=>({id:`net:${e.id}`,kind:`net`,name:e.label,net:e.id,matches:ez(e,i)})).filter(e=>e.matches.length>0).sort(tz);return[...a,...o]}function rz(e){return e.matches.map(e=>e.field===`name`||e.field===`net name`?e.field:`${e.field} ${e.text}`).join(`, `)}function iz(e,t,n){if(e.kind===`net`)return e.net?{highlight:[e.net]}:{};let r=t?De(t,n).get(e.name)?.origin:void 0;return{select:e.name,...r?{focus:{view:n,at:r}}:{}}}var az={pcb:`Show on the PCB`,schematic:`Show on the schematic`,code:`From the code`};function oz({rows:e,counts:t,active:n,onPick:r}){let i=(0,l.useMemo)(()=>yS(e),[e]);return(0,X.jsxs)(`section`,{className:`checks`,"aria-label":`Checks`,onClick:rp,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:CS(t)})]}),(0,X.jsx)(`div`,{className:`checks-body`,children:i.length===0?(0,X.jsx)(`p`,{className:`note ok`,children:oS}):i.map(e=>(0,X.jsx)(sz,{group:e,active:n,onPick:r},e.code))})]})}function sz({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)(cz,{row:e,active:e.id===t,onPick:n})},e.id))})]})}function cz({row:e,active:t,onPick:n}){return(0,X.jsxs)(`button`,{className:`check-row ${e.severity}${t?` active`:``}`,"aria-current":t||void 0,title:az[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 lz={part:`Select the part`,net:`Highlight the net`};function uz({query:e,rows:t,active:n,pick:r}){return e===null?(0,X.jsx)(`p`,{className:`note bottom-note`,children:GR}):t.length===0?(0,X.jsx)(`p`,{className:`note bottom-note`,children:KR(e)}):(0,X.jsxs)(`section`,{className:`find-results`,"aria-label":`Find results`,onClick:rp,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:lz[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:rz(e)})]})},e.id))})]})}function dz(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 fz({history:e,problems:t,actions:n}){let r=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.`}),r]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`ul`,{className:`history`,children:e.map(e=>{let t=dz(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}),t.undoable&&(0,X.jsx)(`button`,{className:`icon`,"aria-label":`Undo ${e.summary}`,onClick:()=>void n.undo(e.id),children:(0,X.jsx)(kp,{})})]},e.id)})}),r]})}var pz={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 mz(e){let t=pz[e]??{},n=Object.keys(t).find(e=>e!==`footprint`);return n?t[n]??``:``}function hz(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}`:`Not checked against the datasheet yet`,extra:`${e.id} ${e.mpn??``} ${e.component}`})),n=e.builtin.map(e=>({part:e,name:e,value:mz(e),footprint:pz[e]?.footprint??``,description:``,verified:``,tooltip:e,verifiedTip:``,extra:e}));return[...t,...n]}function gz(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 _z(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 vz=(e,t)=>e===null||t-e>=500,yz=e=>e<=1,bz=(e,t)=>Math.max(0,Math.min(e,t-1));function xz(e){let t=(0,l.useRef)(null);return n=>{let r=Date.now();vz(t.current,r)&&(t.current=r,e(n))}}function Sz(){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":`Place`})]})})}function Cz({row:e,tabStop:t,onFocus:n,onPlace:r,onKey:i}){return(0,X.jsxs)(`tr`,{tabIndex:t?0:-1,title:e.tooltip,onFocus:n,onDoubleClick:r,onKeyDown:i,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:(0,X.jsx)(`button`,{className:`lib-place`,tabIndex:-1,onClick:e=>yz(e.detail)&&r(),onDoubleClick:e=>e.stopPropagation(),"aria-label":`Place ${e.name}`,children:`Place`})})]})}function wz({parts:e,onPlace:t}){let[n,r]=(0,l.useState)(``),i=(0,l.useRef)(null),[a,o]=(0,l.useState)(0),s=(0,l.useId)(),c=xz(t),u=(0,l.useMemo)(()=>gz(hz(e),n),[e,n]),d=bz(a,u.length),f=(e,t,n)=>{if(e.target!==e.currentTarget)return;let r=_z(e.key,t,u.length,e.repeat);r&&(e.preventDefault(),`place`in r?c(n):(i.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:n,onChange:e=>r(e.target.value)}),(0,X.jsx)(`p`,{id:s,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":s,children:[(0,X.jsx)(Sz,{}),(0,X.jsx)(`tbody`,{ref:i,children:u.map((e,t)=>(0,X.jsx)(Cz,{row:e,tabStop:t===d,onFocus:()=>o(t),onPlace:()=>c(e.part),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 Tz(e){return(0,X.jsx)(`div`,{className:`bottom-panel hairline-t`,id:Kf,role:`tabpanel`,"aria-labelledby":qf(e.tab),onClick:rp,children:(0,X.jsx)(Ez,{...e})})}function Ez(e){switch(e.tab){case`library`:return(0,X.jsx)(wz,{parts:e.parts,onPlace:e.onPlace});case`log`:return(0,X.jsx)(`div`,{className:`bottom-scroll`,children:(0,X.jsx)(fz,{history:e.history,problems:e.historyProblems,actions:e.actions})});case`drc`:return e.built?(0,X.jsx)(oz,{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)(uz,{...e.find})}}var Dz=(e,t,n)=>n?{label:e,command:t,shortcut:n}:{label:e,command:t},Oz={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`},kz={alignLeft:`Ctrl+Shift+L`,distributeH:`Ctrl+Shift+H`};function Az(e){if(e<2)return[];let t=t=>{let n=b(t,e),r=kz[t];return{label:Oz[t],command:t,...r?{shortcut:r}:{},...n?{pending:n}:{}}};return[`separator`,...g.slice(0,6).map(t),`separator`,...g.slice(6).map(t)]}function jz({allLocked:e,selected:t}){return[{label:`Properties`,special:`properties`},`separator`,Dz(`Rotate`,`rotate`,`Space`),e?Dz(`Unlock`,`unlock`):Dz(`Lock`,`lock`),Dz(`Highlight its nets`,`highlight`,`H`),Dz(`Copy`,`copy`,`Ctrl+C`),...Az(t),`separator`,Dz(`Delete`,`delete`,`Delete`)]}var Mz=[Dz(`Fit all`,`fit`,`K`),Dz(`Grid style`,`gridStyle`),`separator`,Dz(`Zoom in`,`zoomIn`),Dz(`Zoom out`,`zoomOut`),`separator`,Dz(`Paste`,`paste`,`Ctrl+V`)],Nz={remove:null,removeCorners:`Select this wire alone to remove its corners`},Pz=(e,t)=>t?{...e,pending:t}:e;function Fz(e){return[{label:`Properties`,special:`properties`},`separator`,Dz(`Highlight net`,`highlight`,`H`),Pz(Dz(`Remove corners`,`removeCorners`),e?.removeCorners),`separator`,Pz(Dz(`Delete`,`delete`,`Delete`),e?.remove)]}var Iz=[{label:`Properties`,special:`properties`},`separator`,Dz(`Delete`,`delete`,`Delete`)],Lz=[{label:`Rename`,special:`rename`},{label:`Highlight net`,special:`highlightNet`}],Rz=[Dz(`Fillet tracks`,`filletTracks`,`U`),Dz(`Straighten tracks`,`straightenTracks`,`Shift+U`),`separator`];function zz(e,t,n){let r=e.startsWith(`t`)?Rz:[],i=Dz(n?`Delete segment`:`Delete`,`delete`,`Delete`);return[{label:`Properties`,special:`properties`},`separator`,...r,t?Dz(`Unlock`,`unlock`):Dz(`Lock`,`lock`),`separator`,i]}function Bz(e){let t={label:`Reset position`,special:`resetText`};return[e?{...t,pending:e}:t,`separator`,{label:`Properties`,special:`properties`}]}function Vz(e,t){return e.kind===`part`?jz(t):e.kind===`copper`?zz(e.id,t.copperLocked,t.segment):e.kind===`wire`?Fz(t.wire):e.kind===`drawing`?[...Iz]:e.kind===`text`?Bz(t.textReset):[...e.kind===`label`?Lz:Mz]}function Hz(e){return e.map(e=>e===`separator`?`separator`:e.pending?`disabled`:`item`)}function Uz(e,t){return e.length>0&&e.every(e=>t.has(e))}function Wz(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 Gz=28,Kz=9,qz=10;function Jz(e){return{width:240,height:e.reduce((e,t)=>e+(t===`separator`?Kz:Gz),0)+qz}}function Yz(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 Xz(e){(0,l.useEffect)(()=>(window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)),[e])}function Zz(e,t){let n=(0,l.useRef)(pg(t));(0,l.useLayoutEffect)(()=>{let t=e.current,r=document.activeElement;return n.current!==null&&t?.querySelector(`[data-item="${n.current}"]`)?.focus(),()=>{r instanceof HTMLElement&&r.isConnected&&np(document.activeElement,document.body,t)&&r.focus()}},[e])}var Qz=(e,t)=>{let n=t instanceof HTMLElement&&e?.contains(t)?t.closest(`[data-item]`):null;return n?Number(n.dataset.item):null};function $z({entries:e,at:t,onRun:n,onClose:r}){let i=(0,l.useRef)(null),a=(0,l.useMemo)(()=>Hz(e),[e]),[o,s]=(0,l.useState)(null);(0,l.useLayoutEffect)(()=>{let e=i.current?.getBoundingClientRect();e&&s({width:e.width,height:e.height})},[e]);let c=(0,l.useMemo)(()=>Yz(t,o??Jz(e),{width:window.innerWidth,height:window.innerHeight}),[t,e,o]);return zp(!0,e=>{let t=Qz(i.current,document.activeElement),n=fg(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()}}),Zz(i,a),Qh(!0,i,r),Xz(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)(Zh,{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 eB=[{view:`schematic`,label:`Schematic`},{view:`pcb`,label:`PCB`}];function tB(e,t,n,r){let i=e===t;return Ze(e)?[{view:`schematic`,label:`Schematic`,active:i}]:eB.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 nB(e,t,n,r,i){return{project:e||`Project`,view:r,files:t.map(e=>({file:e,documents:tB(e,n,r,i)}))}}eB.map(e=>e.view);var rB=`schematic:`,iB=`parent:`;function aB(e){return e.startsWith(iB)?{...aB(e.slice(7)),parent:!0}:e.startsWith(rB)?{view:`schematic`,page:e.slice(10)}:{view:e===`pcb`?`pcb`:`schematic`}}function oB(e,t){return[...t===void 0?[]:sB(t,`pcb`).map(e=>({...e,id:`${iB}${e.id}`,active:!1,parent:!0})),{id:`schematic`,view:`schematic`,title:`${Qe(e)} (sheet)`,active:!0}]}function sB(e,t,n=[xg],r=xg,i){if(e!==void 0&&Ze(e))return oB(e,i);let a=(e??``).replace(/\.circuit\.tsx$/,``),o=(e,t)=>a?`${a}${t}${e}`:e;return eB.flatMap(({view:e,label:i})=>e===`pcb`||n.length<=1?[{id:e,view:e,title:o(i,` `),active:e===t}]:n.map(n=>({id:`${rB}${n}`,view:e,page:n,title:o(n,` — `),active:t===`schematic`&&n===r})))}function cB({file:e,view:t,pages:n,page:r,onView:i,onPage:a,parent:o,onParent:s}){let c=sB(e,t,n,r,o),l=c.find(e=>e.active)?.id??t,u=sp({ids:c.map(e=>e.id),current:l,onSelect:e=>{let t=aB(e);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:u.onKeyDown,children:c.map((e,t)=>(0,X.jsx)(`button`,{role:`tab`,id: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,...u.tab(e.id),children:(0,X.jsx)(`span`,{className:`doc-tab-label`,children:e.title})},e.id))})}function lB({view:e,filter:t,onToggle:n}){return(0,X.jsxs)(`aside`,{className:`panel right filter-panel`,id:gT(`right`),role:`tabpanel`,"aria-labelledby":_T(`filter`),onClick:rp,children:[(0,X.jsx)(`h3`,{className:`filter-head hairline-b`,children:`Pick`}),(0,X.jsx)(`ul`,{className:`filter-list`,children:bi(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 uB=e=>e?.state===`started`||e?.state===`running`||e?.state===`cleanup`,dB=e=>e.state===`done`&&e.entryId!==void 0?e.writeMark:void 0,fB=`cleanup stopped at its pass cap`,pB=(e,t,n=`${t}s`)=>`${e} ${e===1?t:n}`;function mB(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 ${pB(e.total,`connection`)}`;case`cleanup`:return e.capped?`Autorouting: ${fB}`:`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?`; ${fB}`:``;return`Routed ${e.routed} of ${pB(e.total,`connection`)} in ${pB(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 hB({route:e,onCancel:t}){return!e||!uB(e)?null:(0,X.jsxs)(`div`,{className:`canvas-status route-status`,role:`status`,children:[(0,X.jsx)(`span`,{children:mB(e)}),(0,X.jsx)(`button`,{className:`unit-toggle`,onClick:e=>{rp(e),t()},onPointerDown:e=>e.stopPropagation(),title:`Stop routing; nothing is written`,children:`Cancel`})]})}var gB=e=>e?.state===`started`||e?.state===`running`,_B=e=>e.state===`done`&&e.entryId!==void 0?e.writeMark:void 0,vB=(e,t)=>`${e} ${t}${e===1?``:`s`}`,yB=e=>String(Math.round(e));function bB(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 ${vB(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 ${vB(e.placed,`part`)}; wire length ${yB(e.wireLength)} mm (was ${yB(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 xB({place:e,onCancel:t}){return!e||!gB(e)?null:(0,X.jsxs)(`div`,{className:`canvas-status route-status`,role:`status`,children:[(0,X.jsx)(`span`,{children:bB(e)}),(0,X.jsx)(`button`,{className:`unit-toggle`,onClick:e=>{rp(e),t()},onPointerDown:e=>e.stopPropagation(),title:`Stop placing; nothing is written`,children:`Cancel`})]})}var SB=[{id:`all`,label:`All`},{id:`copper`,label:`Copper`},{id:`non-copper`,label:`Non-copper`}],CB=SB.map(e=>e.id);function wB({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:Fl[n.layer]??B.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)(Mp,{off:!n.shown})})]},n.id))})]},e.layer))})}function TB({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:ai.map(e=>(0,X.jsx)(`option`,{value:e.id,children:e.name},e.id))})]})}function EB({filter:e,onFilter:t}){let n=sp({ids:CB,current:e,onSelect:t});return(0,X.jsx)(`div`,{className:`layer-filters hairline-b`,role:`radiogroup`,"aria-label":`Show layers`,onKeyDown:n.onKeyDown,children:SB.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 DB({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:gT(`right`),role:`tabpanel`,"aria-labelledby":_T(`layer`),onClick:rp,children:[(0,X.jsx)(EB,{filter:t,onFilter:r}),(0,X.jsx)(TB,{active:a,onActive:o}),(0,X.jsx)(`ul`,{className:`layer-list`,children:si(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:ci(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)(Mp,{off:!n})})]},t.id)})}),t!==`non-copper`&&(0,X.jsx)(wB,{pours:s,onTogglePour:c})]})}function OB(e,t,n,r,i){return t.total>1?Nz:n&&r?Xw(n,r,e,i):void 0}function kB(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 AB(e){let{circuit:t,design:n,selection:r,onSelect:i,run:a,openProperties:o,onHighlight:s,edit:c}=e,[u,d]=(0,l.useState)(null),f=(0,l.useCallback)((e,t)=>{i(t=>Wz(t,e)),d({target:e,at:t})},[i]),p=(0,l.useCallback)(()=>d(null),[]);return{open:(0,l.useMemo)(()=>{if(!u)return null;let e=new Set(t?.annotations.locks.map(e=>e.part)),i=Wz(r,u.target),{target:a}=u,o=a.kind===`wire`?OB(a.id,i,n,t,e):void 0,s=a.kind===`copper`&&kB(n,i.copper),c=a.kind===`copper`&&i.segment?.id===a.id,l=a.kind===`text`?n&&t?td(n,t,a.id,e):`It is not on this sheet`:void 0;return{entries:Vz(a,{allLocked:Uz(i.names,e),selected:i.size,wire:o,copperLocked:s,segment:c,textReset:l}),at:u.at}},[u,t,n,r]),close:p,show:f,runItem:(0,l.useCallback)(e=>{if(e.command)return a(e.command);if(e.special===`properties`)return o();if(e.special===`resetText`&&u?.target.kind===`text`)return void c(Qu(u.target.id),`Reset text position`);if(e.special===`rename`&&u?.target.kind===`label`)return void ZS.send({kind:`renameLabel`,labelId:u.target.label.id});e.special===`highlightNet`&&u?.target.kind===`label`&&n&&s([$d(n.circuit.nets,u.target.label.net)])},[a,o,s,c,u,n])}}function jB(e){return e===`pcb`?[`properties`,`layer`,`filter`]:[`properties`,`filter`]}function MB(e,t){return e.active!==`layer`||t===`pcb`?e:{...e,active:`properties`}}var NB={active:`properties`,open:!0},PB={strip:`design`,sub:`page`,open:!0};function FB(e,t){return e.open&&e.active===t?{...e,open:!1}:{active:t,open:!0}}function IB(e){return{...e,open:!e.open}}function LB(e,t){return{active:t,open:!0}}function RB(e,t){let n=FB({active:e.strip,open:e.open},t);return{...e,strip:n.active,open:n.open}}function zB(e,t){return{...e,strip:t,open:!0}}function BB(e){return{strip:`design`,sub:e,open:!0}}function VB(e){return{...e,strip:`library`,open:!0}}function HB(e){return{...e,open:!e.open}}var UB=[{id:`design`,label:`Project Design`},{id:`library`,label:`Common Library`}],WB={properties:`Properties`,layer:`Layer`,filter:`Filter`},GB=e=>jB(e).map(e=>({id:e,label:WB[e]}));function KB({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 qB(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 JB(e,t){let n=e?.design,r=e?.actions,i=(0,l.useMemo)(()=>n?wg(n,t):void 0,[n,t]),a=(0,l.useMemo)(()=>r?{...r,edit:(e,n)=>r.edit(Ob(e,t),n),editMarked:(e,n)=>r.editMarked(Ob(e,t),n)}:void 0,[r,t]);return e&&i&&a?{...e,design:i,actions:a}:void 0}function YB({sheetParent:e,onOpenDocument:t}){return e?{parent:e.file,onParent:n=>t(e.file,n)}:{}}function XB(e){let{data:t,workspace:n,checks:r,find:i,view:a,page:o}=e,{build:s}=t,c=KB(e,e.onContextMenu),u=JB(c,o),d=(0,l.useMemo)(()=>Sg(s.design),[s.design]);return(0,X.jsxs)(`div`,{className:`center`,children:[(0,X.jsx)(cB,{file:t.file,view:a,pages:d,page:o,onView:e.onView,onPage:e.onPage,...YB(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":`doc-tab-${a}`,tabIndex:-1,children:[!s.design&&(0,X.jsx)(`p`,{className:`empty`,children:s.status===`failed`?s.error:`Building the circuit…`}),c&&a===`pcb`&&(0,X.jsx)(cF,{...c,...qB(n,`pcb`),markers:r.markers.pcb,activeLayer:n.activeLayer,onActiveLayer:n.setActiveLayer,pourFill:n.pourFill,hiddenPours:n.hiddenPours},t.file),u&&a===`schematic`&&(0,X.jsx)(VR,{...u,...qB(n,`schematic`),markers:r.markers.schematic},`${t.file}
|
|
19
|
-
${o}`),(0,X.jsx)(hB,{route:t.route,onCancel:()=>void e.actions.cancelRoute()}),(0,X.jsx)(xB,{place:t.place,onCancel:()=>void e.actions.cancelAutoplace()}),i.box.open&&(0,X.jsx)(UR,{text:i.box.text,seq:i.box.seq,onText:i.setText,onSearch:i.search,onClose:i.close,status:qR(i.results.query,i.results.rows.length)})]}),n.bottom.open&&(0,X.jsx)(Tz,{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 ZB({data:e,workspace:t,view:n,page:r,selection:i,onSelect:a,actions:o,onPlace:s,onImportPart:c,onNewPart:u,onOpenDocument:d}){let{circuit:f,build:p,project:m,files:h,sheets:g,file:_}=e,v=(0,l.useMemo)(()=>nB(m,[...h,...g],_,n,{names:Sg(p.design),open:r}),[m,h,g,_,n,p.design,r]),y=(0,l.useMemo)(()=>Ge(p.design,n),[p.design,n]);return f?(0,X.jsx)(CT,{circuit:f,parts:e.parts,onPlace:s,onImport:c,onNewPart:u,selection:i,onSelect:a,actions:o,design:p.design,autoPlaced:y,left:t.left,onSub:t.showSub,pageTree:v,onOpenDocument:d,focusSearch:t.focusSearch,onSearchFocused:t.searchFocused,focusPage:t.focusPage,onPageFocused:t.pageFocused,highlight:t.highlight,onHighlight:t.setHighlight,hidden:!t.leftOpen}):null}function QB({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?di(g.pcb.board?.pours??[],e=>hl(g,e),t.hiddenPours):[];return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(MT,{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)(DB,{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)(lB,{view:l,filter:t.pickFilter,onToggle:t.togglePickable})]})}function $B(e){let{data:t,workspace:n,selection:r,onSelect:i}=e,a=AB({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)(vT,{side:`left`,tabs:UB,active:n.left.strip,open:n.left.open,onClick:n.clickLeft,onSelect:n.selectLeft}),(0,X.jsx)(ZB,{...e}),(0,X.jsx)(XB,{...e,onContextMenu:a.show}),(0,X.jsx)(QB,{...e}),(0,X.jsx)(vT,{side:`right`,tabs:GB(e.view),active:n.right.active,open:n.right.open,onClick:n.clickRight,onSelect:n.selectRight}),a.open&&(0,X.jsx)($z,{entries:a.open.entries,at:a.open.at,onRun:a.runItem,onClose:a.close})]})}function eV({file:e,refresh:t,refreshParts:n,notify:r}){let i=(0,l.useCallback)(async n=>{try{return await n(),!0}catch(e){return r(e.message),!1}finally{e&&await t(e).catch(()=>void 0)}},[e,t,r]),a=(0,l.useCallback)(async(e,t)=>{let n;return{ok:await i(async()=>{n=(await R(e,t)).writeMark}),mark:n}},[i]),o=(0,l.useCallback)((t,n)=>a(`/api/edit`,{file:e,edits:t,summary:n}),[e,a]),s=(0,l.useCallback)((t,n,r)=>a(`/api/layout`,{file:e,edits:t,summary:n,...r?{sheet:r}:{}}),[e,a]);return(0,l.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)=>sM(a(`/api/rename-parts`,{file:e,mapping:t,summary:n})),lock:(t,n)=>i(()=>R(`/api/lock`,{file:e,parts:t,locked:n})),mark:(t,n)=>i(()=>R(`/api/mark`,{file:e,text:t,...n})),unmark:t=>i(()=>R(`/api/unmark`,{file:e,id:t})),undo:e=>sM(a(`/api/undo`,e?{id:e}:{})),redo:e=>sM(a(`/api/redo`,e?{id:e}:{})),verify:async(e,t,r,a)=>{let o=await i(()=>R(`/api/verify`,{id:e,by:t,against:r,confirm:a}));return o&&await n(),o},makeSheet:t=>i(async()=>{r(_m((await R(`/api/make-sheet`,{file:e,...t})).preview,t.parts.length))}),route:async t=>{try{return await R(`/api/route`,{file:e,scope:t}),!0}catch(e){return r(e.message),!1}},cancelRoute:async()=>{try{return(await R(`/api/route/cancel`,{})).cancelled}catch(e){return r(e.message),!1}},autoplace:async t=>{try{return await R(`/api/autoplace`,{file:e,scope:t}),!0}catch(e){return r(e.message),!1}},cancelAutoplace:async()=>{try{return(await R(`/api/autoplace/cancel`,{})).cancelled}catch(e){return r(e.message),!1}},fitBoard:()=>sM((async()=>{let t;return{ok:await i(async()=>{let n=await R(`/api/fit-board`,{file:e});t=n.writeMark,r(n.summary)}),mark:t}})()),unroute:t=>sM((async()=>{let n;return{ok:await i(async()=>{let i=await R(`/api/unroute`,{file:e,...t?{ids:t}:{}});n=i.writeMark,r(i.summary)}),mark:n}})()),setFilletRadius:t=>i(async()=>{let n=await R(`/api/rules`,{filletRadius:t,...e?{file:e}:{}});n.writeMark!==void 0&&zA({radius:t,mark:n.writeMark}),r(n.summary)}),notify:r}),[e,i,r,n,o,s,a])}function tV({file:e,refresh:t,notify:n},r,i=`Main`){return(0,l.useCallback)(a=>{let o=pz[a];R(`/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 nV(e,t){return e===0&&t>0}function rV(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 iV({file:e,build:t,route:n,onTab:r,onSelect:i,onSelectCopper:a,onOpen:o}){let s=t.design,c=(0,l.useMemo)(()=>s?vS(s,n):[],[s,n]),u=(0,l.useMemo)(()=>xS(c),[c]),d=(0,l.useMemo)(()=>({pcb:bS(c,`pcb`),schematic:bS(c,`schematic`)}),[c]),[f,p]=(0,l.useState)(null),[m,h]=(0,l.useState)(null);return aV(e,t,u.errors,o),{rows:c,counts:u,markers:d,active:f,focus:m,pick:(0,l.useCallback)(e=>{let t=rV(e);p(e.id),t.tab&&r(t.tab),t.focus&&h(t.focus),t.select&&i(t.select),t.selectCopper&&a(t.selectCopper,t.selectBoard??[])},[r,i,a]),focused:(0,l.useCallback)(()=>h(null),[]),requestFocus:h}}function aV(e,t,n,r){let i=(0,l.useRef)(void 0);(0,l.useEffect)(()=>{i.current=void 0},[e]);let a=t.status===`done`?t.finishedAt:void 0;(0,l.useEffect)(()=>{a!==void 0&&(nV(i.current,n)&&r(),i.current=n)},[a,n,r])}var oV={open:!1,text:``,seq:0};function sV({file:e,circuit:t,library:n,design:r,view:i,onSelect:a,onHighlight:o,requestFocus:s,openResults:c}){let[u,d]=(0,l.useState)(oV),[f,p]=(0,l.useState)(null),[m,h]=(0,l.useState)(null),g=t?.model.parts,_=(0,l.useMemo)(()=>f===null?[]:nz(f,g??[],r?YR(r):[],n),[f,g,r,n]);return(0,l.useEffect)(()=>{p(null),h(null)},[e]),{box:u,open:(0,l.useCallback)(()=>d(e=>({...e,open:!0,seq:e.seq+1})),[]),close:(0,l.useCallback)(()=>d(e=>({...e,open:!1})),[]),setText:(0,l.useCallback)(e=>d(t=>({...t,text:e})),[]),search:(0,l.useCallback)(e=>{let t=e.trim();t!==``&&(p(t),h(null),c())},[c]),results:{query:f,rows:_,active:m,pick:(0,l.useCallback)(e=>{let t=iz(e,r,i);if(h(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 cV(e,t,n){let[r,i]=(0,l.useState)([]),[a,o]=(0,l.useState)([]),[s,c]=(0,l.useState)();return(0,l.useEffect)(()=>{R(`/api/circuits`).then(e=>{i(e),t(t=>t??e[0])}).catch(t=>e(t.message)),R(`/api/sheets`).then(o).catch(t=>e(t.message)),R(`/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,l.useCallback)(()=>R(`/api/circuits`).then(i),[])}}function lV(e,t){let[n,r]=(0,l.useState)(),[i,a]=(0,l.useState)(),[o,s]=(0,l.useState)({status:`idle`}),[c,u]=(0,l.useState)([]),[d,f]=(0,l.useState)([]),[m,h]=(0,l.useState)({library:[],builtin:[]}),[g,_]=(0,l.useState)(),[v,y]=(0,l.useState)(),[b,x]=(0,l.useState)(!1),S=(0,l.useCallback)(e=>x(!e),[]),C=(0,l.useCallback)(t=>{p(t)&&s({status:`failed`,error:t}),e(t)},[e]),w=(0,l.useCallback)(async e=>{let[t,n]=await Promise.all([R(`/api/circuit?file=${encodeURIComponent(e)}`),R(`/api/history?limit=30`).catch(e=>({entries:[],problems:[{file:`history`,reason:e.message}]}))]);a(t),u(n.entries),f(n.problems)},[]),T=(0,l.useCallback)(async()=>{h(await R(`/api/parts`))},[]),E=(0,l.useCallback)(async e=>{let t=await R(`/api/build?file=${encodeURIComponent(e)}`);s(e=>t.status===`building`&&e.design?{...t,design:e.design}:t)},[]),{files:ee,sheets:D,project:O,refreshFiles:k}=cV(C,r,T),A=(0,l.useCallback)(t=>{if(_(t),uB(t))return;e(mB(t));let n=dB(t);n!==void 0&&(sM(Promise.resolve({ok:!0,mark:n})),w(t.file).catch(e=>C(e.message)))},[e,w,C]),j=(0,l.useCallback)(t=>{if(y(t),gB(t))return;e(bB(t));let n=_B(t);n!==void 0&&(sM(Promise.resolve({ok:!0,mark:n})),w(t.file).catch(e=>C(e.message)))},[e,w,C]);return(0,l.useEffect)(()=>{if(n)return t(),_(void 0),y(void 0),w(n).catch(e=>C(e.message)),R(`/api/build`,{file:n}).then(()=>E(n)).catch(e=>C(e.message)),le((e,t,r)=>{if(e===`library`)T().catch(e=>C(e.message));else if(t===n){if(e===`route`)return A(r);if(e===`place`)return j(r);(e===`change`?w(n):E(n)).catch(e=>C(e.message))}},S)},[n,w,E,T,C,t,A,j,S]),{files:ee,sheets:D,project:O,file:n,setFile:r,circuit:i,build:o,history:c,historyProblems:d,parts:m,route:g,place:v,serverGone:b,refresh:w,refreshParts:T,refreshFiles:k}}function uV(e,t,n,r){let[i,a]=(0,l.useState)(),o=(0,l.useRef)(void 0);(0,l.useEffect)(()=>ie.listen(r),[r]),(0,l.useEffect)(()=>{if(!t)return;let n=e[0];(n?.id!==o.current||i===void 0)&&(o.current=n?.id,a(e=>e===void 0?E(n?.author):n?D(e,n.author):e))},[e,t,i]);let s=i?.closed??!1;return(0,l.useLayoutEffect)(()=>ie.set(s),[s]),dV(s,n),{closed:s,toggle:(0,l.useCallback)(()=>a(e=>ee(e??E(void 0))),[])}}function dV(e,t){(0,l.useEffect)(()=>{if(!e)return;let n=e=>{let n=Ou(pu(e),{view:t})?.action;n!==void 0&&j(n)&&(e.preventDefault(),e.stopImmediatePropagation(),ie.refuses())};return window.addEventListener(`keydown`,n,!0),()=>window.removeEventListener(`keydown`,n,!0)},[e,t])}function fV({closed:e,onToggle:t}){let{title:n,hint:r}=P(e),i=e?Tp:Ep,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 pV=`copperflow.hoverLabels`,mV=`off`,hV=`on`;function gV(e){try{return e()?.getItem(pV)!==mV}catch{return!0}}function _V(e,t){try{let n=e();return n?(n.setItem(pV,t?hV:mV),!0):!1}catch{return!1}}var vV=`copperflow.system`,yV={unit:`mm`,grid:{schematic:Lm,pcb:Fm}},bV=(e,t,n)=>typeof e==`number`&&t.includes(e)?e:n;function xV(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:bV(n.schematic,Im,Lm),pcb:bV(n.pcb,Pm,Fm)}}}function SV(e){try{return xV(e()?.getItem(vV))}catch{return yV}}function CV(e,t){try{let n=e();return n?(n.setItem(vV,JSON.stringify({unit:t.unit,grid:t.grid})),!0):!1}catch{return!1}}function wV(){let[e,t]=(0,l.useState)(li),[n,r]=(0,l.useState)(`all`),[i,a]=(0,l.useState)(`top`),o=(0,l.useCallback)(e=>t(t=>fi(t,e)),[]),[s,c]=(0,l.useState)(()=>new Set);return{layerVisibility:e,layerFilter:n,setLayerFilter:r,toggleLayerShown:o,activeLayer:i,setActiveLayer:a,hiddenPours:s,togglePourShown:(0,l.useCallback)(e=>c(t=>ui(t,e)),[])}}function TV(){let[e,t]=(0,l.useState)(_i);return{pickFilter:e,togglePickable:(0,l.useCallback)(e=>t(t=>vi(t,e)),[])}}var EV=new Set([`toggleLeftPanel`,`toggleRightPanel`,`toggleBottomPanel`,`toggleUnit`,`clearHighlight`,`openLibrary`,`toggleSnap`]);function DV(e){let[t,n]=(0,l.useState)(PB),[r,i]=(0,l.useState)(NB),a=MB(r,e),[o,s]=(0,l.useState)(Jf);return{left:t,setLeft:n,right:a,setRight:i,bottom:o,setBottom:s,clickLeft:(0,l.useCallback)(e=>n(t=>RB(t,e)),[]),selectLeft:(0,l.useCallback)(e=>n(t=>zB(t,e)),[]),clickRight:(0,l.useCallback)(t=>i(n=>FB(MB(n,e),t)),[e]),selectRight:(0,l.useCallback)(e=>i(t=>LB(t,e)),[]),clickBottomTab:(0,l.useCallback)(e=>s(t=>Yf(t,e)),[]),openBottom:(0,l.useCallback)(e=>s(t=>Zf(t,e)),[]),showSub:(0,l.useCallback)(e=>n(BB(e)),[])}}function OV(){let[e,t]=(0,l.useState)(!1);return[e,(0,l.useCallback)(()=>t(!0),[]),(0,l.useCallback)(()=>t(!1),[])]}function kV(e){let[t,n]=(0,l.useState)(()=>Vg(Bm,e)),[r,i]=(0,l.useState)(()=>SV(Ng).grid);return{gridStyles:t,gridSteps:r,setGridSteps:i,changeGridStep:(0,l.useCallback)((e,t)=>i(n=>Rm(n,e,t)),[]),toggleGridStyleOf:(0,l.useCallback)(e=>n(t=>Hm(t,e)),[]),gridFollowsTheme:(0,l.useCallback)((e,t)=>n(n=>Bg(n,e,t)),[])}}function AV(){let[e,t]=(0,l.useState)(()=>Fg(Ng));(0,l.useEffect)(()=>Lg(document.documentElement,e),[e]);let{gridFollowsTheme:n,...r}=kV(e),i=(0,l.useRef)(e);return{theme:e,setTheme:(0,l.useCallback)(e=>{n(i.current,e),i.current=e,t(e),Ig(Ng,e)},[n]),grid:r}}function jV(){let[e,t]=(0,l.useState)(!0);return{snap:e,toggleSnap:(0,l.useCallback)(()=>t(e=>!e),[])}}function MV(){let[e,t]=(0,l.useState)(()=>gV(Ng)),n=(0,l.useRef)(!0);return(0,l.useEffect)(()=>{n.current?n.current=!1:_V(Ng,e)},[e]),{hoverLabels:e,setHoverLabels:t,toggleHoverLabels:(0,l.useCallback)(()=>t(e=>!e),[])}}function NV(){let[e,t]=(0,l.useState)(()=>G(Ng));return{pourFill:e,setPourFill:(0,l.useCallback)(e=>{t(e),Ml(Ng,e)},[])}}function PV(e,t){(0,l.useEffect)(()=>{let n=n=>{let r=Ou(pu(n),{view:e});r&&EV.has(r.action)&&(r.preventDefault&&n.preventDefault(),t(r.action))};return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[e,t])}function FV(e,t){let[n,r,i]=OV(),[a,o,s]=OV(),[c,u,d]=OV();return{focusSearch:n,requestSearch:r,searchFocused:i,focusPage:a,pageFocused:s,openPageTree:(0,l.useCallback)(()=>{e(BB(`page`)),o()},[e,o]),focusField:c,fieldFocused:d,openProperties:(0,l.useCallback)(()=>{t(e=>LB(e,`properties`)),u()},[t,u])}}function IV(e,{strips:t,setUnit:n,setHighlight:r,toggleGridStyleOf:i,toggleSnap:a,requestSearch:o}){let{setLeft:s,setRight:c,setBottom:u}=t,d=(0,l.useRef)(e);return d.current=e,(0,l.useCallback)(e=>{e===`toggleLeftPanel`&&s(HB),e===`toggleRightPanel`&&c(IB),e===`toggleBottomPanel`&&u(Xf),e===`toggleUnit`&&n(Om),e===`toggleGridStyle`&&i(d.current),e===`toggleSnap`&&a(),e===`clearHighlight`&&r(ef),e===`openLibrary`&&(s(VB),o())},[s,c,u,n,r,o,i,a])}function LV(e){let{setLeft:t,setRight:n,setBottom:r,...i}=DV(e),{requestSearch:a,...o}=FV(t,n),[s,c]=(0,l.useState)(()=>SV(Ng).unit),[u,d]=(0,l.useState)(ef),{theme:f,setTheme:p,grid:m}=AV(),{toggleGridStyleOf:h,setGridSteps:g,..._}=m,{snap:v,toggleSnap:y}=jV(),{hoverLabels:b,setHoverLabels:x,toggleHoverLabels:S}=MV(),{pourFill:C,setPourFill:w}=NV(),T=wV(),E=TV(),ee=IV(e,{strips:{setLeft:t,setRight:n,setBottom:r},setUnit:c,setHighlight:d,toggleGridStyleOf:h,toggleSnap:y,requestSearch:a});PV(e,ee);let D=(0,l.useCallback)(()=>c(Om),[]),O=(0,l.useCallback)(e=>{p(e.theme),c(e.unit),g(e.grid),x(e.hoverLabels),CV(Ng,e)},[p,g,x]);return{...i,..._,theme:f,setTheme:p,applySystem:O,snap:v,hoverLabels:b,toggleHoverLabels:S,pourFill:C,setPourFill:w,...T,...E,...o,leftOpen:i.left.open,unit:s,toggleUnit:D,highlight:u,setHighlight:d,run:ee}}function RV(){let[e,t]=(0,l.useState)(null);return{message:e,notify:(0,l.useCallback)(e=>{t(e),window.setTimeout(()=>t(t=>t===e?null:t),6e3)},[]),dismiss:(0,l.useCallback)(()=>t(null),[])}}function zV(e){(0,l.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 BV(e,t){let n=(0,l.useRef)([]);(0,l.useEffect)(()=>{if(!e)return;let r=e.model.parts.map(e=>e.name),i=ea(n.current,r);n.current=r,i.length>0&&t(e=>e.without(i))},[e,t])}function VV(e,t){let n=(0,l.useRef)(void 0),r=(0,l.useRef)([]);return(0,l.useEffect)(()=>{if(!e||e===n.current)return;let i=n.current;n.current=e;let a=e.schematic.drawings,o=r.current;r.current=hf(Xi.none,o,a).waiting,t(t=>{let n=hf(Nf(t.wireCount===0?t:Uf(t,i&&zf(i.schematic),zf(e.schematic)),i,e),o,a).selection;return gf(n,i?.schematic.drawings,a)})},[e,t]),{seen:n,onRenameDrawing:(0,l.useCallback)(e=>(r.current=[...r.current,e],()=>{r.current=r.current.filter(t=>t!==e)}),[])}}function HV(e,t,n,r,i){return(0,l.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&&mf(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`?Wu(n.pcb):r===`schematic`?Hu(n.schematic):[]);return Wf(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 UV(e,t){let n=(0,l.useRef)(void 0);(0,l.useEffect)(()=>{let r=n.current;n.current=e,e&&e!==r&&t(t=>sf(t,r,e))},[e,t])}function WV(){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 GV(e,t,n){return lV(e,(0,l.useCallback)(()=>{t(Xi.none),n(ef)},[t,n]))}function KV({data:e,tab:t,setTab:n,select:r,selectOnly:i,workspace:a}){let{file:o,build:s}=e,{setHighlight:c,openBottom:u}=a,d=(0,l.useCallback)(()=>u(`drc`),[u]),f=(0,l.useCallback)((e,t)=>r(()=>Xi.none.all([],[],[],[],e).addBoard(t)),[r]),p=iV({file:o,build:s,route:e.route,onTab:n,onSelect:i,onSelectCopper:f,onOpen:d}),m=(0,l.useCallback)(()=>u(`find`),[u]);return{checks:p,find:sV({file:o,circuit:e.circuit,library:e.parts.library,design:s.design,view:t,onSelect:r,onHighlight:c,requestFocus:p.requestFocus,openResults:m}),openChecks:d}}function qV(){let e=RV(),[t,n]=(0,l.useState)(Xi.none),r=(0,l.useCallback)(e=>n(t=>t.only(e)),[]),[i,a]=(0,l.useState)(`pcb`),[o,s]=(0,l.useState)(null),c=LV(i),u=GV(e.notify,n,c.setHighlight),{file:d,setFile:f,build:p,circuit:m}=u;BV(m,n);let{seen:h,onRenameDrawing:g}=VV(p.design,n),_=HV(t,m,p.design,i,h.current),v=eV({file:d,refresh:u.refresh,refreshParts:u.refreshParts,notify:e.notify}),[y,b]=(0,l.useState)(xg),x=Cg(p.design,y),S=tV({file:d,refresh:u.refresh,refreshParts:u.refreshParts,notify:e.notify},r,i===`schematic`?x:xg),{checks:C,find:w,openChecks:T}=KV({data:u,tab:i,setTab:a,select:n,selectOnly:r,workspace:c});zV(n),UV(p.design,c.setHighlight);let E=(0,l.useCallback)(()=>s(null),[]),ee=(0,l.useCallback)(()=>s(`importPart`),[]),D=(0,l.useCallback)(()=>s(`newPart`),[]),[O,k]=(0,l.useState)(),A=(0,l.useCallback)((e,t,n)=>{n===void 0?e!==d&&b(xg):b(n),Ze(e)?k(e=>d&&!Ze(d)?{file:d,design:p.design}:e):k(void 0),f(e),a(Ze(e)?`schematic`:t)},[f,d,p.design]),j=(0,l.useCallback)(e=>A(e,`schematic`),[A]),te=(0,l.useCallback)(e=>{b(e),a(`schematic`)},[]),M=p.design?.pcb,ne=(0,l.useMemo)(()=>i===`pcb`&&M?gi(M.parts,c.layerVisibility):void 0,[i,M,c.layerVisibility]),N=(0,l.useMemo)(()=>p.design?wg(p.design,x).schematic:void 0,[p.design,x]),P={sheetWires:(0,l.useMemo)(()=>i===`schematic`&&N?N.wires.map(e=>e.id):[],[i,N]),sheetLabels:(0,l.useMemo)(()=>i===`schematic`&&N?N.labels.map(e=>e.id):[],[i,N]),sheetDrawings:(0,l.useMemo)(()=>i===`schematic`&&N?N.drawings.map(e=>e.id):[],[i,N]),pcbCopper:(0,l.useMemo)(()=>i===`pcb`&&M?Jc(M,c.layerVisibility).map(({kind:e,id:t})=>({kind:e,id:t})):[],[i,M,c.layerVisibility]),copperRecords:i===`pcb`?M:void 0},re=uV(u.history,m!==void 0,i,e.notify),I=iS({file:d,view:i,setView:a,selection:_,select:n,circuit:m,actions:v,pickLayers:ne,pickFilter:c.pickFilter,...P,workspace:c,openChecks:T,checkCounts:C.counts,openFind:w.open,openDialog:s,design:p.design,page:x,openPage:te,highlight:c.highlight});return{aiLock:re,toast:e,tab:i,setTab:a,dialog:o,closeDialog:E,openImportPart:ee,openNewPart:D,workspace:c,data:u,selection:_,select:n,onRenameDrawing:g,actions:v,place:S,checks:C,find:w,openChecks:T,openDocument:A,openSheet:j,sheetParent:O,runCommand:(0,l.useCallback)(e=>re.closed&&F(e)?void ie.refuses():I(e),[re.closed,I]),page:x,openPage:te}}function JV(e){return(0,l.useMemo)(()=>{let t=Ke(e);return t===null?{}:{tidySheet:t}},[e])}function YV(e,t){return(0,l.useMemo)(()=>({import:async n=>{let r=await R(`/api/import-part`,n);return await e(),t(tm(r)),r}}),[e,t])}function XV(e,t){return(0,l.useMemo)(()=>({create:async n=>{let r=await R(`/api/create-part`,n);return await e(),t(Xh(r)),r}}),[e,t])}function ZV(e,t,n){return(0,l.useMemo)(()=>({create:async r=>{try{let i=await R(`/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 QV(e,t,n){return(0,l.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 $V(e,t,n,r){return(0,l.useMemo)(()=>({question:F_(t),showChecks:n,exportAnyway:()=>qx(e,r)}),[e,t,n,r])}function eH(e,t,n){return(0,l.useMemo)(()=>({parts:t,preview:n=>R(`/api/make-sheet`,{file:e,parts:t,...n,preview:!0}),make:e=>n.makeSheet({parts:t,...e})}),[e,t,n])}function tH(){let{aiLock:e,toast:t,tab:n,setTab:r,dialog:i,closeDialog:a,openImportPart:o,openNewPart:s,workspace:c,data:u,selection:d,select:f,onRenameDrawing:p,actions:m,place:h,checks:g,find:_,openChecks:v,openDocument:y,openSheet:b,sheetParent:x,runCommand:S,page:C,openPage:w}=qV(),{build:T,circuit:E}=u,{message:ee,dismiss:D}=t,O={snap:c.snap,hoverLabels:c.hoverLabels,...Rg(c.theme),...Nl(c.pourFill)},A=JV(T.design),j=(0,l.useMemo)(()=>({...A,...k(e.closed)}),[A,e.closed]),te=eH(u.file,d.names,m),M=YV(u.refreshParts,t.notify),ne=XV(u.refreshParts,t.notify),N=ZV(u.refreshFiles,y,t.notify),P=QV(T.design,E,m),F=$V(u.file,g.counts,v,m),re={settings:{theme:c.theme,unit:c.unit,grid:c.gridSteps,hoverLabels:c.hoverLabels},apply:c.applySystem};return(0,l.useEffect)(()=>pp(window),[]),se?(0,X.jsxs)(`div`,{className:`app`,children:[(0,X.jsx)(bg,{run:S,view:n,selected:d.size,toggles:O,off:j,children:(0,X.jsx)(Ag,{build:T,errors:g.counts.errors,onOpen:v})}),(0,X.jsx)(S_,{view:n,unit:c.unit,selected:d.size,toggles:O,off:j,run:S}),i&&(0,X.jsx)(Yh,{name:i,onClose:a,rules:{fabrication:T.design?.rules.fabrication,save:m.setFilletRadius},makeSheet:te,importPart:M,newPart:ne,system:re,newCircuit:N,footprints:P,exportChecks:F}),u.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.`}),E&&E.violations.length>0&&(0,X.jsxs)(`div`,{className:`banner`,role:`alert`,children:[`Locked parts changed outside the editor: `,E.violations.map(e=>`${e.part} (${e.detail})`).join(`, `),`. Lock them again to accept the change, or undo it in the code.`]}),(0,X.jsx)($B,{data:u,workspace:c,checks:g,find:_,view:n,onView:r,page:C,onPage:w,selection:d,onSelect:f,onRenameDrawing:p,actions:m,run:S,onPlace:h,onImportPart:o,onNewPart:s,onOpenDocument:y,onOpenSheet:b,sheetParent:x,openChecks:v,aiLocked:e.closed,lockControl:(0,X.jsx)(fV,{closed:e.closed,onToggle:e.toggle})}),(0,X.jsx)(dp,{state:c.bottom,onClick:c.clickBottomTab,onOpen:c.openBottom}),ee&&(0,X.jsx)(`div`,{className:`toast`,role:`status`,onClick:D,children:ee})]}):(0,X.jsx)(WV,{})}Rp(window),Lg(document.documentElement,Fg(Ng)),(0,u.createRoot)(document.getElementById(`root`)).render((0,X.jsx)(l.StrictMode,{children:(0,X.jsx)(tH,{})}));export{n as a,B as i,jh as n,lp as r,Xh as t};
|