copperflow 0.3.4 → 0.4.0
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 +107 -13
- package/dist/app/THIRD_PARTY_LICENSES.txt +5 -0
- package/dist/app/assets/NewPartDialog-BBJaZFCo.js +160 -0
- package/dist/app/assets/VerifyPartDialog-BHLqD_WJ.css +1 -0
- package/dist/app/assets/VerifyPartDialog-Ey6xpQ_U.js +2 -0
- package/dist/app/assets/index-BKoIKo22.css +1 -0
- package/dist/app/assets/index-DPmr2dR1.js +20 -0
- package/dist/app/assets/texture-worker-CyI_g_XZ.js +1 -0
- package/dist/app/index.html +2 -2
- package/dist/cli-commands.js +120 -16
- package/dist/cli-commands.js.map +1 -1
- package/dist/cli-impedance.d.ts +4 -0
- package/dist/cli-impedance.js +56 -0
- package/dist/cli-impedance.js.map +1 -0
- package/dist/cli-simulate.d.ts +3 -0
- package/dist/cli-simulate.js +54 -0
- package/dist/cli-simulate.js.map +1 -0
- package/dist/core/analyze.js +5 -2
- package/dist/core/analyze.js.map +1 -1
- package/dist/core/bom.d.ts +6 -1
- package/dist/core/bom.js +23 -4
- package/dist/core/bom.js.map +1 -1
- package/dist/core/case-results.d.ts +4 -0
- package/dist/core/case-results.js +9 -0
- package/dist/core/case-results.js.map +1 -0
- package/dist/core/change-files.d.ts +31 -0
- package/dist/core/change-files.js +67 -0
- package/dist/core/change-files.js.map +1 -0
- package/dist/core/change-render.d.ts +18 -0
- package/dist/core/change-render.js +48 -0
- package/dist/core/change-render.js.map +1 -0
- package/dist/core/change-view.d.ts +33 -0
- package/dist/core/change-view.js +73 -0
- package/dist/core/change-view.js.map +1 -0
- package/dist/core/change-words.d.ts +39 -0
- package/dist/core/change-words.js +214 -0
- package/dist/core/change-words.js.map +1 -0
- package/dist/core/checklist-text.d.ts +21 -0
- package/dist/core/checklist-text.js +59 -0
- package/dist/core/checklist-text.js.map +1 -0
- package/dist/core/edit.js +5 -2
- package/dist/core/edit.js.map +1 -1
- package/dist/core/fabrication.d.ts +9 -2
- package/dist/core/fabrication.js +29 -10
- package/dist/core/fabrication.js.map +1 -1
- package/dist/core/library.d.ts +46 -0
- package/dist/core/library.js +54 -16
- package/dist/core/library.js.map +1 -1
- package/dist/core/modules.d.ts +1 -0
- package/dist/core/modules.js +17 -0
- package/dist/core/modules.js.map +1 -1
- package/dist/core/order-report.d.ts +10 -0
- package/dist/core/order-report.js +93 -0
- package/dist/core/order-report.js.map +1 -0
- package/dist/core/pin-header.d.ts +5 -0
- package/dist/core/pin-header.js +77 -0
- package/dist/core/pin-header.js.map +1 -0
- package/dist/core/pin-map.d.ts +46 -0
- package/dist/core/pin-map.js +101 -0
- package/dist/core/pin-map.js.map +1 -0
- package/dist/core/render.d.ts +24 -4
- package/dist/core/render.js +16 -6
- package/dist/core/render.js.map +1 -1
- package/dist/core/sheet-card.d.ts +4 -0
- package/dist/core/sheet-card.js +46 -1
- package/dist/core/sheet-card.js.map +1 -1
- package/dist/core/sheet-files.js +10 -3
- package/dist/core/sheet-files.js.map +1 -1
- package/dist/core/simulate.d.ts +19 -0
- package/dist/core/simulate.js +72 -0
- package/dist/core/simulate.js.map +1 -0
- package/dist/core/step-export.d.ts +17 -0
- package/dist/core/step-export.js +35 -0
- package/dist/core/step-export.js.map +1 -0
- package/dist/core/supplier-prop.d.ts +6 -0
- package/dist/core/supplier-prop.js +21 -0
- package/dist/core/supplier-prop.js.map +1 -0
- package/dist/core/workspace.d.ts +2 -1
- package/dist/core/workspace.js +2 -1
- package/dist/core/workspace.js.map +1 -1
- package/dist/engine/board.js +3 -1
- package/dist/engine/board.js.map +1 -1
- package/dist/engine/checks/fast-lines.d.ts +60 -0
- package/dist/engine/checks/fast-lines.js +209 -0
- package/dist/engine/checks/fast-lines.js.map +1 -0
- package/dist/engine/checks/index.js +2 -0
- package/dist/engine/checks/index.js.map +1 -1
- package/dist/engine/design-diff.d.ts +120 -0
- package/dist/engine/design-diff.js +249 -0
- package/dist/engine/design-diff.js.map +1 -0
- package/dist/engine/design.d.ts +3 -0
- package/dist/engine/design.js +7 -2
- package/dist/engine/design.js.map +1 -1
- package/dist/engine/fab/export.d.ts +17 -1
- package/dist/engine/fab/export.js +26 -4
- package/dist/engine/fab/export.js.map +1 -1
- package/dist/engine/fab/names.d.ts +2 -2
- package/dist/engine/fab/names.js +4 -2
- package/dist/engine/fab/names.js.map +1 -1
- package/dist/engine/fab/picture/board-picture.d.ts +52 -0
- package/dist/engine/fab/picture/board-picture.js +102 -0
- package/dist/engine/fab/picture/board-picture.js.map +1 -0
- package/dist/engine/fab/picture/board-view.d.ts +20 -0
- package/dist/engine/fab/picture/board-view.js +50 -0
- package/dist/engine/fab/picture/board-view.js.map +1 -0
- package/dist/engine/fab/picture/compose.d.ts +50 -0
- package/dist/engine/fab/picture/compose.js +208 -0
- package/dist/engine/fab/picture/compose.js.map +1 -0
- package/dist/engine/fab/picture/layer-images.d.ts +9 -0
- package/dist/engine/fab/picture/layer-images.js +67 -0
- package/dist/engine/fab/picture/layer-images.js.map +1 -0
- package/dist/engine/fab/picture/looks.d.ts +152 -0
- package/dist/engine/fab/picture/looks.js +53 -0
- package/dist/engine/fab/picture/looks.js.map +1 -0
- package/dist/engine/fab/picture/png.d.ts +31 -0
- package/dist/engine/fab/picture/png.js +47 -0
- package/dist/engine/fab/picture/png.js.map +1 -0
- package/dist/engine/fab/picture/raster.d.ts +46 -0
- package/dist/engine/fab/picture/raster.js +170 -0
- package/dist/engine/fab/picture/raster.js.map +1 -0
- package/dist/engine/fab/zip.d.ts +2 -1
- package/dist/engine/fab/zip.js +1 -1
- package/dist/engine/fab/zip.js.map +1 -1
- package/dist/engine/impedance.d.ts +72 -0
- package/dist/engine/impedance.js +133 -0
- package/dist/engine/impedance.js.map +1 -0
- package/dist/engine/line-length.d.ts +15 -0
- package/dist/engine/line-length.js +116 -0
- package/dist/engine/line-length.js.map +1 -0
- package/dist/engine/model.d.ts +2 -0
- package/dist/engine/model.js.map +1 -1
- package/dist/engine/pcb-place/roles.d.ts +3 -1
- package/dist/engine/pcb-place/roles.js +5 -0
- package/dist/engine/pcb-place/roles.js.map +1 -1
- package/dist/engine/rules/impedance-widths.d.ts +20 -0
- package/dist/engine/rules/impedance-widths.js +57 -0
- package/dist/engine/rules/impedance-widths.js.map +1 -0
- package/dist/engine/rules/load.js +11 -2
- package/dist/engine/rules/load.js.map +1 -1
- package/dist/engine/rules/pairs.d.ts +27 -0
- package/dist/engine/rules/pairs.js +86 -0
- package/dist/engine/rules/pairs.js.map +1 -0
- package/dist/engine/rules/profiles.js +16 -0
- package/dist/engine/rules/profiles.js.map +1 -1
- package/dist/engine/rules/schema.d.ts +44 -0
- package/dist/engine/rules/schema.js +16 -1
- package/dist/engine/rules/schema.js.map +1 -1
- package/dist/engine/sim/answer.d.ts +13 -0
- package/dist/engine/sim/answer.js +101 -0
- package/dist/engine/sim/answer.js.map +1 -0
- package/dist/engine/sim/cases.d.ts +29 -0
- package/dist/engine/sim/cases.js +63 -0
- package/dist/engine/sim/cases.js.map +1 -0
- package/dist/engine/sim/devices.d.ts +109 -0
- package/dist/engine/sim/devices.js +137 -0
- package/dist/engine/sim/devices.js.map +1 -0
- package/dist/engine/sim/elements.d.ts +49 -0
- package/dist/engine/sim/elements.js +2 -0
- package/dist/engine/sim/elements.js.map +1 -0
- package/dist/engine/sim/from-circuit.d.ts +52 -0
- package/dist/engine/sim/from-circuit.js +354 -0
- package/dist/engine/sim/from-circuit.js.map +1 -0
- package/dist/engine/sim/limits.d.ts +12 -0
- package/dist/engine/sim/limits.js +79 -0
- package/dist/engine/sim/limits.js.map +1 -0
- package/dist/engine/sim/linear.d.ts +2 -0
- package/dist/engine/sim/linear.js +49 -0
- package/dist/engine/sim/linear.js.map +1 -0
- package/dist/engine/sim/model-schema.d.ts +246 -0
- package/dist/engine/sim/model-schema.js +115 -0
- package/dist/engine/sim/model-schema.js.map +1 -0
- package/dist/engine/sim/part-models.d.ts +47 -0
- package/dist/engine/sim/part-models.js +102 -0
- package/dist/engine/sim/part-models.js.map +1 -0
- package/dist/engine/sim/run.d.ts +14 -0
- package/dist/engine/sim/run.js +13 -0
- package/dist/engine/sim/run.js.map +1 -0
- package/dist/engine/sim/solve.d.ts +42 -0
- package/dist/engine/sim/solve.js +294 -0
- package/dist/engine/sim/solve.js.map +1 -0
- package/dist/engine/sim/spice.d.ts +5 -0
- package/dist/engine/sim/spice.js +66 -0
- package/dist/engine/sim/spice.js.map +1 -0
- package/dist/engine/sim/values.d.ts +4 -0
- package/dist/engine/sim/values.js +40 -0
- package/dist/engine/sim/values.js.map +1 -0
- package/dist/engine/solid/heights.d.ts +29 -0
- package/dist/engine/solid/heights.js +87 -0
- package/dist/engine/solid/heights.js.map +1 -0
- package/dist/engine/solid/limits.d.ts +7 -0
- package/dist/engine/solid/limits.js +20 -0
- package/dist/engine/solid/limits.js.map +1 -0
- package/dist/engine/solid/model.d.ts +54 -0
- package/dist/engine/solid/model.js +147 -0
- package/dist/engine/solid/model.js.map +1 -0
- package/dist/engine/solid/step.d.ts +5 -0
- package/dist/engine/solid/step.js +164 -0
- package/dist/engine/solid/step.js.map +1 -0
- package/dist/engine/solid/thickness.d.ts +11 -0
- package/dist/engine/solid/thickness.js +10 -0
- package/dist/engine/solid/thickness.js.map +1 -0
- package/dist/library/kicad/board.d.ts +26 -0
- package/dist/library/kicad/board.js +96 -0
- package/dist/library/kicad/board.js.map +1 -0
- package/dist/library/kicad/copper.d.ts +44 -0
- package/dist/library/kicad/copper.js +106 -0
- package/dist/library/kicad/copper.js.map +1 -0
- package/dist/library/kicad/footprints.d.ts +62 -0
- package/dist/library/kicad/footprints.js +184 -0
- package/dist/library/kicad/footprints.js.map +1 -0
- package/dist/library/kicad/geometry.d.ts +36 -0
- package/dist/library/kicad/geometry.js +84 -0
- package/dist/library/kicad/geometry.js.map +1 -0
- package/dist/library/kicad/import.d.ts +58 -0
- package/dist/library/kicad/import.js +240 -0
- package/dist/library/kicad/import.js.map +1 -0
- package/dist/library/kicad/plan.d.ts +40 -0
- package/dist/library/kicad/plan.js +139 -0
- package/dist/library/kicad/plan.js.map +1 -0
- package/dist/library/kicad/read.d.ts +30 -0
- package/dist/library/kicad/read.js +105 -0
- package/dist/library/kicad/read.js.map +1 -0
- package/dist/library/kicad/sexpr.d.ts +36 -0
- package/dist/library/kicad/sexpr.js +153 -0
- package/dist/library/kicad/sexpr.js.map +1 -0
- package/dist/library/kicad/tally.d.ts +32 -0
- package/dist/library/kicad/tally.js +55 -0
- package/dist/library/kicad/tally.js.map +1 -0
- package/dist/library/kicad/write.d.ts +37 -0
- package/dist/library/kicad/write.js +146 -0
- package/dist/library/kicad/write.js.map +1 -0
- package/dist/library/new-part.d.ts +2 -0
- package/dist/library/new-part.js +1 -0
- package/dist/library/new-part.js.map +1 -1
- package/dist/mcp/board-import-tool.d.ts +1 -1
- package/dist/mcp/board-import-tool.js +14 -4
- package/dist/mcp/board-import-tool.js.map +1 -1
- package/dist/mcp/copper-summary.d.ts +2 -0
- package/dist/mcp/copper-summary.js +4 -2
- package/dist/mcp/copper-summary.js.map +1 -1
- package/dist/mcp/create-part.d.ts +23 -0
- package/dist/mcp/create-part.js +1 -0
- package/dist/mcp/create-part.js.map +1 -1
- package/dist/mcp/fast-summary.d.ts +3 -0
- package/dist/mcp/fast-summary.js +46 -0
- package/dist/mcp/fast-summary.js.map +1 -0
- package/dist/mcp/render-tool.d.ts +33 -2
- package/dist/mcp/render-tool.js +21 -5
- package/dist/mcp/render-tool.js.map +1 -1
- package/dist/mcp/server.js +18 -8
- package/dist/mcp/server.js.map +1 -1
- package/dist/mcp/sheet-card-tools.d.ts +3 -1
- package/dist/mcp/sheet-card-tools.js +3 -1
- package/dist/mcp/sheet-card-tools.js.map +1 -1
- package/dist/mcp/simulate-tool.d.ts +10 -0
- package/dist/mcp/simulate-tool.js +12 -0
- package/dist/mcp/simulate-tool.js.map +1 -0
- package/dist/render/render.js +8113 -108
- package/dist/studio/change-route.d.ts +18 -0
- package/dist/studio/change-route.js +24 -0
- package/dist/studio/change-route.js.map +1 -0
- package/dist/studio/http-error.d.ts +5 -0
- package/dist/studio/http-error.js +9 -0
- package/dist/studio/http-error.js.map +1 -0
- package/dist/studio/live.d.ts +2 -0
- package/dist/studio/live.js.map +1 -1
- package/dist/studio/server.js +43 -15
- package/dist/studio/server.js.map +1 -1
- package/dist/studio/verify-routes.d.ts +42 -0
- package/dist/studio/verify-routes.js +110 -0
- package/dist/studio/verify-routes.js.map +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/library/modules/CanNode/CanNode.sheet.tsx +1 -1
- package/library/modules/CanNode/parts/MCP2515-I-SO/MCP2515_I_SO.tsx +1 -0
- package/library/modules/CanNode/parts/MCP2515-I-SO/part.yaml +2 -0
- package/library/modules/CanNode/parts/MCP2515-I-SO/verification.md +2 -1
- package/library/modules/CanNode/parts/TJA1051T-3/TJA1051T_3.tsx +1 -0
- package/library/modules/CanNode/parts/TJA1051T-3/part.yaml +2 -0
- package/library/modules/CanNode/parts/TJA1051T-3/verification.md +2 -1
- package/library/modules/DigitalInput24V/DigitalInput24V.sheet.tsx +7 -7
- package/library/modules/RelayDriver/RelayDriver.sheet.tsx +3 -3
- package/library/modules/RelayDriver/parts/AO3400A/part.yaml +34 -0
- package/library/modules/RelayDriver/parts/AO3400A/verification.md +11 -1
- package/library/modules/RelayDriver/parts/SRD-12VDC-SL-C/SRD_12VDC_SL_C.tsx +1 -0
- package/library/modules/RelayDriver/parts/SRD-12VDC-SL-C/part.yaml +14 -0
- package/library/modules/RelayDriver/parts/SRD-12VDC-SL-C/verification.md +4 -1
- package/package.json +1 -1
- package/skills/copperflow/references/copper.md +8 -0
- package/skills/copperflow/references/design-rules.md +48 -0
- package/skills/copperflow/references/modules.md +26 -0
- package/skills/copperflow/references/writing-circuits.md +3 -0
- package/dist/app/assets/NewPartDialog-C4sKWnGI.js +0 -160
- package/dist/app/assets/index-BgzJedaB.css +0 -1
- package/dist/app/assets/index-C_U9me2P.js +0 -19
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(){var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t,t.exports),e=null),t.exports),s=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},c=(n,r,o)=>(o=n==null?{}:e(i(n)),s(r||!n||!n.__esModule||!a.call(n,`default`)?t(o,`default`,{value:n,enumerable:!0}):o,n));let l=[`top`,`bottom`,`inner1`,`inner2`],u=e=>e===4?l:[`top`,`bottom`],d=[`F_Cu`,`In1_Cu`,`In2_Cu`,`B_Cu`,`F_Mask`,`B_Mask`,`F_Paste`,`B_Paste`,`F_Silkscreen`,`B_Silkscreen`,`Edge_Cuts`];function f(e){let{width:t,height:n}=e.drill,r={x:e.x,y:e.y};if(t===n)return{diameter:t,at:r,function:`ComponentDrill`};let i=t>n,a=Math.abs(t-n)/2,o=(e.rotation+(i?0:90))*Math.PI/180,[s,c]=[a*Math.cos(o),a*Math.sin(o)];return{diameter:Math.min(t,n),at:{x:e.x-s,y:e.y-c},to:{x:e.x+s,y:e.y+c},function:`ComponentDrill`}}function p(e){let t=e.parts.flatMap(e=>e.pads).filter(e=>e.layers===`through`&&e.drill!==void 0).map(f),n=e.vias.filter(e=>e.missingLayer===void 0).map(e=>({diameter:e.drill,at:e.at,function:`ViaDrill`})),r=e.holes.map(e=>({diameter:e.diameter,at:{x:e.x,y:e.y},function:`MechanicalDrill`}));return{plated:[...t,...n],nonPlated:r}}function m(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}let h=new Intl.Collator(`en`,{numeric:!0});function g(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 _(e,t){return h.compare(e,t)||g(e,t)}let v=[`top`,`inner1`,`inner2`,`bottom`];function y(e){let t=e.layers.map(e=>v.indexOf(e));return new Set(v.slice(Math.min(...t),Math.max(...t)+1))}var b=/* @__PURE__ */ c((/* @__PURE__ */ o(((e,t)=>{(function(){"use strict";var e={};e.version=`6.4.2.2`,e.use_lines=!0,e.use_xyz=!1;var n=!1;t!==void 0&&t.exports?(t.exports=e,n=!0):(typeof define==`function`&&define.amd&&define(e),typeof document<`u`?window.ClipperLib=e:self.ClipperLib=e);var r;if(n){var i=`chrome`;r=`Netscape`}else{var i=navigator.userAgent.toString().toLowerCase();r=navigator.appName}var a={};a.chrome=+(i.indexOf(`chrome`)!=-1&&i.indexOf(`chromium`)==-1),a.chromium=i.indexOf(`chromium`)==-1?0:1,a.safari=+(i.indexOf(`safari`)!=-1&&i.indexOf(`chrome`)==-1&&i.indexOf(`chromium`)==-1),a.firefox=i.indexOf(`firefox`)==-1?0:1,a.firefox17=i.indexOf(`firefox/17`)==-1?0:1,a.firefox15=i.indexOf(`firefox/15`)==-1?0:1,a.firefox3=i.indexOf(`firefox/3`)==-1?0:1,a.opera=i.indexOf(`opera`)==-1?0:1,a.msie10=i.indexOf(`msie 10`)==-1?0:1,a.msie9=i.indexOf(`msie 9`)==-1?0:1,a.msie8=i.indexOf(`msie 8`)==-1?0:1,a.msie7=i.indexOf(`msie 7`)==-1?0:1,a.msie=i.indexOf(`msie `)==-1?0:1,e.biginteger_used=null;var o,s=!0;function c(t,n,r){e.biginteger_used=1,t!=null&&(typeof t==`number`&&n===void 0?this.fromInt(t):typeof t==`number`?this.fromNumber(t,n,r):n==null&&typeof t!=`string`?this.fromString(t,256):this.fromString(t,n))}function l(){return new c(null,void 0,void 0)}function u(e,t,n,r,i,a){for(;--a>=0;){var o=t*this[e++]+n[r]+i;i=Math.floor(o/67108864),n[r++]=o&67108863}return i}function d(e,t,n,r,i,a){for(var o=t&32767,s=t>>15;--a>=0;){var c=this[e]&32767,l=this[e++]>>15,u=s*c+l*o;c=o*c+((u&32767)<<15)+n[r]+(i&1073741823),i=(c>>>30)+(u>>>15)+s*l+(i>>>30),n[r++]=c&1073741823}return i}function f(e,t,n,r,i,a){for(var o=t&16383,s=t>>14;--a>=0;){var c=this[e]&16383,l=this[e++]>>14,u=s*c+l*o;c=o*c+((u&16383)<<14)+n[r]+i,i=(c>>28)+(u>>14)+s*l,n[r++]=c&268435455}return i}s&&r==`Microsoft Internet Explorer`?(c.prototype.am=d,o=30):s&&r!=`Netscape`?(c.prototype.am=u,o=26):(c.prototype.am=f,o=28),c.prototype.DB=o,c.prototype.DM=(1<<o)-1,c.prototype.DV=1<<o;var p=52;c.prototype.FV=2**p,c.prototype.F1=p-o,c.prototype.F2=2*o-p;for(var m=`0123456789abcdefghijklmnopqrstuvwxyz`,h=[],g=48,_=0;_<=9;++_)h[g++]=_;for(g=97,_=10;_<36;++_)h[g++]=_;for(g=65,_=10;_<36;++_)h[g++]=_;function v(e){return m.charAt(e)}function y(e,t){return h[e.charCodeAt(t)]??-1}function b(e){for(var t=this.t-1;t>=0;--t)e[t]=this[t];e.t=this.t,e.s=this.s}function x(e){this.t=1,this.s=e<0?-1:0,e>0?this[0]=e:e<-1?this[0]=e+this.DV:this.t=0}function S(e){var t=l();return t.fromInt(e),t}function C(e,t){var n;if(t==16)n=4;else if(t==8)n=3;else if(t==256)n=8;else if(t==2)n=1;else if(t==32)n=5;else if(t==4)n=2;else{this.fromRadix(e,t);return}this.t=0,this.s=0;for(var r=e.length,i=!1,a=0;--r>=0;){var o=n==8?e[r]&255:y(e,r);o<0?e.charAt(r)==`-`&&(i=!0):(i=!1,a==0?this[this.t++]=o:a+n>this.DB?(this[this.t-1]|=(o&(1<<this.DB-a)-1)<<a,this[this.t++]=o>>this.DB-a):this[this.t-1]|=o<<a,a+=n,a>=this.DB&&(a-=this.DB))}n==8&&e[0]&128&&(this.s=-1,a>0&&(this[this.t-1]|=(1<<this.DB-a)-1<<a)),this.clamp(),i&&c.ZERO.subTo(this,this)}function ee(){for(var e=this.s&this.DM;this.t>0&&this[this.t-1]==e;)--this.t}function te(e){if(this.s<0)return`-`+this.negate().toString(e);var t;if(e==16)t=4;else if(e==8)t=3;else if(e==2)t=1;else if(e==32)t=5;else if(e==4)t=2;else return this.toRadix(e);var n=(1<<t)-1,r,i=!1,a=``,o=this.t,s=this.DB-o*this.DB%t;if(o-->0)for(s<this.DB&&(r=this[o]>>s)>0&&(i=!0,a=v(r));o>=0;)s<t?(r=(this[o]&(1<<s)-1)<<t-s,r|=this[--o]>>(s+=this.DB-t)):(r=this[o]>>(s-=t)&n,s<=0&&(s+=this.DB,--o)),r>0&&(i=!0),i&&(a+=v(r));return i?a:`0`}function ne(){var e=l();return c.ZERO.subTo(this,e),e}function re(){return this.s<0?this.negate():this}function ie(e){var t=this.s-e.s;if(t!=0)return t;var n=this.t;if(t=n-e.t,t!=0)return this.s<0?-t:t;for(;--n>=0;)if((t=this[n]-e[n])!=0)return t;return 0}function w(e){var t=1,n;return(n=e>>>16)!=0&&(e=n,t+=16),(n=e>>8)!=0&&(e=n,t+=8),(n=e>>4)!=0&&(e=n,t+=4),(n=e>>2)!=0&&(e=n,t+=2),(n=e>>1)!=0&&(e=n,t+=1),t}function ae(){return this.t<=0?0:this.DB*(this.t-1)+w(this[this.t-1]^this.s&this.DM)}function T(e,t){for(var n=this.t-1;n>=0;--n)t[n+e]=this[n];for(n=e-1;n>=0;--n)t[n]=0;t.t=this.t+e,t.s=this.s}function oe(e,t){for(var n=e;n<this.t;++n)t[n-e]=this[n];t.t=Math.max(this.t-e,0),t.s=this.s}function se(e,t){for(var n=e%this.DB,r=this.DB-n,i=(1<<r)-1,a=Math.floor(e/this.DB),o=this.s<<n&this.DM,s=this.t-1;s>=0;--s)t[s+a+1]=this[s]>>r|o,o=(this[s]&i)<<n;for(s=a-1;s>=0;--s)t[s]=0;t[a]=o,t.t=this.t+a+1,t.s=this.s,t.clamp()}function ce(e,t){t.s=this.s;var n=Math.floor(e/this.DB);if(n>=this.t)t.t=0;else{var r=e%this.DB,i=this.DB-r,a=(1<<r)-1;t[0]=this[n]>>r;for(var o=n+1;o<this.t;++o)t[o-n-1]|=(this[o]&a)<<i,t[o-n]=this[o]>>r;r>0&&(t[this.t-n-1]|=(this.s&a)<<i),t.t=this.t-n,t.clamp()}}function E(e,t){for(var n=0,r=0,i=Math.min(e.t,this.t);n<i;)r+=this[n]-e[n],t[n++]=r&this.DM,r>>=this.DB;if(e.t<this.t){for(r-=e.s;n<this.t;)r+=this[n],t[n++]=r&this.DM,r>>=this.DB;r+=this.s}else{for(r+=this.s;n<e.t;)r-=e[n],t[n++]=r&this.DM,r>>=this.DB;r-=e.s}t.s=r<0?-1:0,r<-1?t[n++]=this.DV+r:r>0&&(t[n++]=r),t.t=n,t.clamp()}function D(e,t){var n=this.abs(),r=e.abs(),i=n.t;for(t.t=i+r.t;--i>=0;)t[i]=0;for(i=0;i<r.t;++i)t[i+n.t]=n.am(0,r[i],t,i,0,n.t);t.s=0,t.clamp(),this.s!=e.s&&c.ZERO.subTo(t,t)}function le(e){for(var t=this.abs(),n=e.t=2*t.t;--n>=0;)e[n]=0;for(n=0;n<t.t-1;++n){var r=t.am(n,t[n],e,2*n,0,1);(e[n+t.t]+=t.am(n+1,2*t[n],e,2*n+1,r,t.t-n-1))>=t.DV&&(e[n+t.t]-=t.DV,e[n+t.t+1]=1)}e.t>0&&(e[e.t-1]+=t.am(n,t[n],e,2*n,0,1)),e.s=0,e.clamp()}function ue(e,t,n){var r=e.abs();if(!(r.t<=0)){var i=this.abs();if(i.t<r.t)t?.fromInt(0),n!=null&&this.copyTo(n);else{n??=l();var a=l(),o=this.s,s=e.s,u=this.DB-w(r[r.t-1]);u>0?(r.lShiftTo(u,a),i.lShiftTo(u,n)):(r.copyTo(a),i.copyTo(n));var d=a.t,f=a[d-1];if(f!=0){var p=f*(1<<this.F1)+(d>1?a[d-2]>>this.F2:0),m=this.FV/p,h=(1<<this.F1)/p,g=1<<this.F2,_=n.t,v=_-d,y=t??l();for(a.dlShiftTo(v,y),n.compareTo(y)>=0&&(n[n.t++]=1,n.subTo(y,n)),c.ONE.dlShiftTo(d,y),y.subTo(a,a);a.t<d;)a[a.t++]=0;for(;--v>=0;){var b=n[--_]==f?this.DM:Math.floor(n[_]*m+(n[_-1]+g)*h);if((n[_]+=a.am(0,b,n,v,0,d))<b)for(a.dlShiftTo(v,y),n.subTo(y,n);n[_]<--b;)n.subTo(y,n)}t!=null&&(n.drShiftTo(d,t),o!=s&&c.ZERO.subTo(t,t)),n.t=d,n.clamp(),u>0&&n.rShiftTo(u,n),o<0&&c.ZERO.subTo(n,n)}}}}function de(e){var t=l();return this.abs().divRemTo(e,null,t),this.s<0&&t.compareTo(c.ZERO)>0&&e.subTo(t,t),t}function O(e){this.m=e}function fe(e){return e.s<0||e.compareTo(this.m)>=0?e.mod(this.m):e}function pe(e){return e}function me(e){e.divRemTo(this.m,null,e)}function he(e,t,n){e.multiplyTo(t,n),this.reduce(n)}function k(e,t){e.squareTo(t),this.reduce(t)}O.prototype.convert=fe,O.prototype.revert=pe,O.prototype.reduce=me,O.prototype.mulTo=he,O.prototype.sqrTo=k;function ge(){if(this.t<1)return 0;var e=this[0];if(!(e&1))return 0;var t=e&3;return t=t*(2-(e&15)*t)&15,t=t*(2-(e&255)*t)&255,t=t*(2-((e&65535)*t&65535))&65535,t=t*(2-e*t%this.DV)%this.DV,t>0?this.DV-t:-t}function A(e){this.m=e,this.mp=e.invDigit(),this.mpl=this.mp&32767,this.mph=this.mp>>15,this.um=(1<<e.DB-15)-1,this.mt2=2*e.t}function _e(e){var t=l();return e.abs().dlShiftTo(this.m.t,t),t.divRemTo(this.m,null,t),e.s<0&&t.compareTo(c.ZERO)>0&&this.m.subTo(t,t),t}function j(e){var t=l();return e.copyTo(t),this.reduce(t),t}function ve(e){for(;e.t<=this.mt2;)e[e.t++]=0;for(var t=0;t<this.m.t;++t){var n=e[t]&32767,r=n*this.mpl+((n*this.mph+(e[t]>>15)*this.mpl&this.um)<<15)&e.DM;for(n=t+this.m.t,e[n]+=this.m.am(0,r,e,t,0,this.m.t);e[n]>=e.DV;)e[n]-=e.DV,e[++n]++}e.clamp(),e.drShiftTo(this.m.t,e),e.compareTo(this.m)>=0&&e.subTo(this.m,e)}function ye(e,t){e.squareTo(t),this.reduce(t)}function be(e,t,n){e.multiplyTo(t,n),this.reduce(n)}A.prototype.convert=_e,A.prototype.revert=j,A.prototype.reduce=ve,A.prototype.mulTo=be,A.prototype.sqrTo=ye;function xe(){return(this.t>0?this[0]&1:this.s)==0}function Se(e,t){if(e>4294967295||e<1)return c.ONE;var n=l(),r=l(),i=t.convert(this),a=w(e)-1;for(i.copyTo(n);--a>=0;)if(t.sqrTo(n,r),(e&1<<a)>0)t.mulTo(r,i,n);else{var o=n;n=r,r=o}return t.revert(n)}function Ce(e,t){var n=e<256||t.isEven()?new O(t):new A(t);return this.exp(e,n)}c.prototype.copyTo=b,c.prototype.fromInt=x,c.prototype.fromString=C,c.prototype.clamp=ee,c.prototype.dlShiftTo=T,c.prototype.drShiftTo=oe,c.prototype.lShiftTo=se,c.prototype.rShiftTo=ce,c.prototype.subTo=E,c.prototype.multiplyTo=D,c.prototype.squareTo=le,c.prototype.divRemTo=ue,c.prototype.invDigit=ge,c.prototype.isEven=xe,c.prototype.exp=Se,c.prototype.toString=te,c.prototype.negate=ne,c.prototype.abs=re,c.prototype.compareTo=ie,c.prototype.bitLength=ae,c.prototype.mod=de,c.prototype.modPowInt=Ce,c.ZERO=S(0),c.ONE=S(1);function we(){var e=l();return this.copyTo(e),e}function M(){if(this.s<0){if(this.t==1)return this[0]-this.DV;if(this.t==0)return-1}else if(this.t==1)return this[0];else if(this.t==0)return 0;return(this[1]&(1<<32-this.DB)-1)<<this.DB|this[0]}function Te(){return this.t==0?this.s:this[0]<<24>>24}function Ee(){return this.t==0?this.s:this[0]<<16>>16}function De(e){return Math.floor(Math.LN2*this.DB/Math.log(e))}function Oe(){return this.s<0?-1:this.t<=0||this.t==1&&this[0]<=0?0:1}function ke(e){if(e??=10,this.signum()==0||e<2||e>36)return`0`;var t=this.chunkSize(e),n=e**+t,r=S(n),i=l(),a=l(),o=``;for(this.divRemTo(r,i,a);i.signum()>0;)o=(n+a.intValue()).toString(e).substr(1)+o,i.divRemTo(r,i,a);return a.intValue().toString(e)+o}function Ae(e,t){this.fromInt(0),t??=10;for(var n=this.chunkSize(t),r=t**+n,i=!1,a=0,o=0,s=0;s<e.length;++s){var l=y(e,s);l<0?e.charAt(s)==`-`&&this.signum()==0&&(i=!0):(o=t*o+l,++a>=n&&(this.dMultiply(r),this.dAddOffset(o,0),a=0,o=0))}a>0&&(this.dMultiply(t**+a),this.dAddOffset(o,0)),i&&c.ZERO.subTo(this,this)}function je(e,t,n){if(typeof t==`number`){if(e<2)this.fromInt(1);else for(this.fromNumber(e,n),this.testBit(e-1)||this.bitwiseTo(c.ONE.shiftLeft(e-1),I,this),this.isEven()&&this.dAddOffset(1,0);!this.isProbablePrime(t);)this.dAddOffset(2,0),this.bitLength()>e&&this.subTo(c.ONE.shiftLeft(e-1),this)}else{var r=[],i=e&7;r.length=(e>>3)+1,t.nextBytes(r),i>0?r[0]&=(1<<i)-1:r[0]=0,this.fromString(r,256)}}function Me(){var e=this.t,t=[];t[0]=this.s;var n=this.DB-e*this.DB%8,r,i=0;if(e-->0)for(n<this.DB&&(r=this[e]>>n)!=(this.s&this.DM)>>n&&(t[i++]=r|this.s<<this.DB-n);e>=0;)n<8?(r=(this[e]&(1<<n)-1)<<8-n,r|=this[--e]>>(n+=this.DB-8)):(r=this[e]>>(n-=8)&255,n<=0&&(n+=this.DB,--e)),r&128&&(r|=-256),i==0&&(this.s&128)!=(r&128)&&++i,(i>0||r!=this.s)&&(t[i++]=r);return t}function Ne(e){return this.compareTo(e)==0}function Pe(e){return this.compareTo(e)<0?this:e}function N(e){return this.compareTo(e)>0?this:e}function Fe(e,t,n){var r,i,a=Math.min(e.t,this.t);for(r=0;r<a;++r)n[r]=t(this[r],e[r]);if(e.t<this.t){for(i=e.s&this.DM,r=a;r<this.t;++r)n[r]=t(this[r],i);n.t=this.t}else{for(i=this.s&this.DM,r=a;r<e.t;++r)n[r]=t(i,e[r]);n.t=e.t}n.s=t(this.s,e.s),n.clamp()}function P(e,t){return e&t}function F(e){var t=l();return this.bitwiseTo(e,P,t),t}function I(e,t){return e|t}function Ie(e){var t=l();return this.bitwiseTo(e,I,t),t}function L(e,t){return e^t}function Le(e){var t=l();return this.bitwiseTo(e,L,t),t}function Re(e,t){return e&~t}function ze(e){var t=l();return this.bitwiseTo(e,Re,t),t}function R(){for(var e=l(),t=0;t<this.t;++t)e[t]=this.DM&~this[t];return e.t=this.t,e.s=~this.s,e}function z(e){var t=l();return e<0?this.rShiftTo(-e,t):this.lShiftTo(e,t),t}function Be(e){var t=l();return e<0?this.lShiftTo(-e,t):this.rShiftTo(e,t),t}function Ve(e){if(e==0)return-1;var t=0;return e&65535||(e>>=16,t+=16),e&255||(e>>=8,t+=8),e&15||(e>>=4,t+=4),e&3||(e>>=2,t+=2),e&1||++t,t}function He(){for(var e=0;e<this.t;++e)if(this[e]!=0)return e*this.DB+Ve(this[e]);return this.s<0?this.t*this.DB:-1}function Ue(e){for(var t=0;e!=0;)e&=e-1,++t;return t}function We(){for(var e=0,t=this.s&this.DM,n=0;n<this.t;++n)e+=Ue(this[n]^t);return e}function B(e){var t=Math.floor(e/this.DB);return t>=this.t?this.s!=0:!!(this[t]&1<<e%this.DB)}function V(e,t){var n=c.ONE.shiftLeft(e);return this.bitwiseTo(n,t,n),n}function H(e){return this.changeBit(e,I)}function Ge(e){return this.changeBit(e,Re)}function Ke(e){return this.changeBit(e,L)}function qe(e,t){for(var n=0,r=0,i=Math.min(e.t,this.t);n<i;)r+=this[n]+e[n],t[n++]=r&this.DM,r>>=this.DB;if(e.t<this.t){for(r+=e.s;n<this.t;)r+=this[n],t[n++]=r&this.DM,r>>=this.DB;r+=this.s}else{for(r+=this.s;n<e.t;)r+=e[n],t[n++]=r&this.DM,r>>=this.DB;r+=e.s}t.s=r<0?-1:0,r>0?t[n++]=r:r<-1&&(t[n++]=this.DV+r),t.t=n,t.clamp()}function Je(e){var t=l();return this.addTo(e,t),t}function Ye(e){var t=l();return this.subTo(e,t),t}function Xe(e){var t=l();return this.multiplyTo(e,t),t}function Ze(){var e=l();return this.squareTo(e),e}function Qe(e){var t=l();return this.divRemTo(e,t,null),t}function $e(e){var t=l();return this.divRemTo(e,null,t),t}function U(e){var t=l(),n=l();return this.divRemTo(e,t,n),[t,n]}function et(e){this[this.t]=this.am(0,e-1,this,0,0,this.t),++this.t,this.clamp()}function tt(e,t){if(e!=0){for(;this.t<=t;)this[this.t++]=0;for(this[t]+=e;this[t]>=this.DV;)this[t]-=this.DV,++t>=this.t&&(this[this.t++]=0),++this[t]}}function W(){}function nt(e){return e}function G(e,t,n){e.multiplyTo(t,n)}function rt(e,t){e.squareTo(t)}W.prototype.convert=nt,W.prototype.revert=nt,W.prototype.mulTo=G,W.prototype.sqrTo=rt;function it(e){return this.exp(e,new W)}function at(e,t,n){var r=Math.min(this.t+e.t,t);for(n.s=0,n.t=r;r>0;)n[--r]=0;for(var i=n.t-this.t;r<i;++r)n[r+this.t]=this.am(0,e[r],n,r,0,this.t);for(i=Math.min(e.t,t);r<i;++r)this.am(0,e[r],n,r,0,t-r);n.clamp()}function ot(e,t,n){--t;var r=n.t=this.t+e.t-t;for(n.s=0;--r>=0;)n[r]=0;for(r=Math.max(t-this.t,0);r<e.t;++r)n[this.t+r-t]=this.am(t-r,e[r],n,0,0,this.t+r-t);n.clamp(),n.drShiftTo(1,n)}function K(e){this.r2=l(),this.q3=l(),c.ONE.dlShiftTo(2*e.t,this.r2),this.mu=this.r2.divide(e),this.m=e}function st(e){if(e.s<0||e.t>2*this.m.t)return e.mod(this.m);if(e.compareTo(this.m)<0)return e;var t=l();return e.copyTo(t),this.reduce(t),t}function ct(e){return e}function lt(e){for(e.drShiftTo(this.m.t-1,this.r2),e.t>this.m.t+1&&(e.t=this.m.t+1,e.clamp()),this.mu.multiplyUpperTo(this.r2,this.m.t+1,this.q3),this.m.multiplyLowerTo(this.q3,this.m.t+1,this.r2);e.compareTo(this.r2)<0;)e.dAddOffset(1,this.m.t+1);for(e.subTo(this.r2,e);e.compareTo(this.m)>=0;)e.subTo(this.m,e)}function ut(e,t){e.squareTo(t),this.reduce(t)}function dt(e,t,n){e.multiplyTo(t,n),this.reduce(n)}K.prototype.convert=st,K.prototype.revert=ct,K.prototype.reduce=lt,K.prototype.mulTo=dt,K.prototype.sqrTo=ut;function q(e,t){var n=e.bitLength(),r,i=S(1),a;if(n<=0)return i;r=n<18?1:n<48?3:n<144?4:n<768?5:6,a=n<8?new O(t):t.isEven()?new K(t):new A(t);var o=[],s=3,c=r-1,u=(1<<r)-1;if(o[1]=a.convert(this),r>1){var d=l();for(a.sqrTo(o[1],d);s<=u;)o[s]=l(),a.mulTo(d,o[s-2],o[s]),s+=2}var f=e.t-1,p,m=!0,h=l(),g;for(n=w(e[f])-1;f>=0;){for(n>=c?p=e[f]>>n-c&u:(p=(e[f]&(1<<n+1)-1)<<c-n,f>0&&(p|=e[f-1]>>this.DB+n-c)),s=r;!(p&1);)p>>=1,--s;if((n-=s)<0&&(n+=this.DB,--f),m)o[p].copyTo(i),m=!1;else{for(;s>1;)a.sqrTo(i,h),a.sqrTo(h,i),s-=2;s>0?a.sqrTo(i,h):(g=i,i=h,h=g),a.mulTo(h,o[p],i)}for(;f>=0&&!(e[f]&1<<n);)a.sqrTo(i,h),g=i,i=h,h=g,--n<0&&(n=this.DB-1,--f)}return a.revert(i)}function J(e){var t=this.s<0?this.negate():this.clone(),n=e.s<0?e.negate():e.clone();if(t.compareTo(n)<0){var r=t;t=n,n=r}var i=t.getLowestSetBit(),a=n.getLowestSetBit();if(a<0)return t;for(i<a&&(a=i),a>0&&(t.rShiftTo(a,t),n.rShiftTo(a,n));t.signum()>0;)(i=t.getLowestSetBit())>0&&t.rShiftTo(i,t),(i=n.getLowestSetBit())>0&&n.rShiftTo(i,n),t.compareTo(n)>=0?(t.subTo(n,t),t.rShiftTo(1,t)):(n.subTo(t,n),n.rShiftTo(1,n));return a>0&&n.lShiftTo(a,n),n}function Y(e){if(e<=0)return 0;var t=this.DV%e,n=this.s<0?e-1:0;if(this.t>0){if(t==0)n=this[0]%e;else for(var r=this.t-1;r>=0;--r)n=(t*n+this[r])%e}return n}function ft(e){var t=e.isEven();if(this.isEven()&&t||e.signum()==0)return c.ZERO;for(var n=e.clone(),r=this.clone(),i=S(1),a=S(0),o=S(0),s=S(1);n.signum()!=0;){for(;n.isEven();)n.rShiftTo(1,n),t?(i.isEven()&&a.isEven()||(i.addTo(this,i),a.subTo(e,a)),i.rShiftTo(1,i)):a.isEven()||a.subTo(e,a),a.rShiftTo(1,a);for(;r.isEven();)r.rShiftTo(1,r),t?(o.isEven()&&s.isEven()||(o.addTo(this,o),s.subTo(e,s)),o.rShiftTo(1,o)):s.isEven()||s.subTo(e,s),s.rShiftTo(1,s);n.compareTo(r)>=0?(n.subTo(r,n),t&&i.subTo(o,i),a.subTo(s,a)):(r.subTo(n,r),t&&o.subTo(i,o),s.subTo(a,s))}if(r.compareTo(c.ONE)!=0)return c.ZERO;if(s.compareTo(e)>=0)return s.subtract(e);if(s.signum()<0)s.addTo(e,s);else return s;return s.signum()<0?s.add(e):s}var X=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997],pt=(1<<26)/X[X.length-1];function mt(e){var t,n=this.abs();if(n.t==1&&n[0]<=X[X.length-1]){for(t=0;t<X.length;++t)if(n[0]==X[t])return!0;return!1}if(n.isEven())return!1;for(t=1;t<X.length;){for(var r=X[t],i=t+1;i<X.length&&r<pt;)r*=X[i++];for(r=n.modInt(r);t<i;)if(r%X[t++]==0)return!1}return n.millerRabin(e)}function Z(e){var t=this.subtract(c.ONE),n=t.getLowestSetBit();if(n<=0)return!1;var r=t.shiftRight(n);e=e+1>>1,e>X.length&&(e=X.length);for(var i=l(),a=0;a<e;++a){i.fromInt(X[Math.floor(Math.random()*X.length)]);var o=i.modPow(r,this);if(o.compareTo(c.ONE)!=0&&o.compareTo(t)!=0){for(var s=1;s++<n&&o.compareTo(t)!=0;)if(o=o.modPowInt(2,this),o.compareTo(c.ONE)==0)return!1;if(o.compareTo(t)!=0)return!1}}return!0}c.prototype.chunkSize=De,c.prototype.toRadix=ke,c.prototype.fromRadix=Ae,c.prototype.fromNumber=je,c.prototype.bitwiseTo=Fe,c.prototype.changeBit=V,c.prototype.addTo=qe,c.prototype.dMultiply=et,c.prototype.dAddOffset=tt,c.prototype.multiplyLowerTo=at,c.prototype.multiplyUpperTo=ot,c.prototype.modInt=Y,c.prototype.millerRabin=Z,c.prototype.clone=we,c.prototype.intValue=M,c.prototype.byteValue=Te,c.prototype.shortValue=Ee,c.prototype.signum=Oe,c.prototype.toByteArray=Me,c.prototype.equals=Ne,c.prototype.min=Pe,c.prototype.max=N,c.prototype.and=F,c.prototype.or=Ie,c.prototype.xor=Le,c.prototype.andNot=ze,c.prototype.not=R,c.prototype.shiftLeft=z,c.prototype.shiftRight=Be,c.prototype.getLowestSetBit=He,c.prototype.bitCount=We,c.prototype.testBit=B,c.prototype.setBit=H,c.prototype.clearBit=Ge,c.prototype.flipBit=Ke,c.prototype.add=Je,c.prototype.subtract=Ye,c.prototype.multiply=Xe,c.prototype.divide=Qe,c.prototype.remainder=$e,c.prototype.divideAndRemainder=U,c.prototype.modPow=q,c.prototype.modInverse=ft,c.prototype.pow=it,c.prototype.gcd=J,c.prototype.isProbablePrime=mt,c.prototype.square=Ze;var Q=c;Q.prototype.IsNegative=function(){return this.compareTo(Q.ZERO)==-1},Q.op_Equality=function(e,t){return e.compareTo(t)==0},Q.op_Inequality=function(e,t){return e.compareTo(t)!=0},Q.op_GreaterThan=function(e,t){return e.compareTo(t)>0},Q.op_LessThan=function(e,t){return e.compareTo(t)<0},Q.op_Addition=function(e,t){return new Q(e,void 0,void 0).add(new Q(t,void 0,void 0))},Q.op_Subtraction=function(e,t){return new Q(e,void 0,void 0).subtract(new Q(t,void 0,void 0))},Q.Int128Mul=function(e,t){return new Q(e,void 0,void 0).multiply(new Q(t,void 0,void 0))},Q.op_Division=function(e,t){return e.divide(t)},Q.prototype.ToDouble=function(){return parseFloat(this.toString())};var ht=function(e,t){var n;if(Object.getOwnPropertyNames===void 0){for(n in t.prototype)(e.prototype[n]===void 0||e.prototype[n]===Object.prototype[n])&&(e.prototype[n]=t.prototype[n]);for(n in t)e[n]===void 0&&(e[n]=t[n]);e.$baseCtor=t}else{for(var r=Object.getOwnPropertyNames(t.prototype),i=0;i<r.length;i++)Object.getOwnPropertyDescriptor(e.prototype,r[i])===void 0&&Object.defineProperty(e.prototype,r[i],Object.getOwnPropertyDescriptor(t.prototype,r[i]));for(n in t)e[n]===void 0&&(e[n]=t[n]);e.$baseCtor=t}};e.Path=function(){return[]},e.Path.prototype.push=Array.prototype.push,e.Paths=function(){return[]},e.Paths.prototype.push=Array.prototype.push,e.DoublePoint=function(){var e=arguments;this.X=0,this.Y=0,e.length===1?(this.X=e[0].X,this.Y=e[0].Y):e.length===2&&(this.X=e[0],this.Y=e[1])},e.DoublePoint0=function(){this.X=0,this.Y=0},e.DoublePoint0.prototype=e.DoublePoint.prototype,e.DoublePoint1=function(e){this.X=e.X,this.Y=e.Y},e.DoublePoint1.prototype=e.DoublePoint.prototype,e.DoublePoint2=function(e,t){this.X=e,this.Y=t},e.DoublePoint2.prototype=e.DoublePoint.prototype,e.PolyNode=function(){this.m_Parent=null,this.m_polygon=new e.Path,this.m_Index=0,this.m_jointype=0,this.m_endtype=0,this.m_Childs=[],this.IsOpen=!1},e.PolyNode.prototype.IsHoleNode=function(){for(var e=!0,t=this.m_Parent;t!==null;)e=!e,t=t.m_Parent;return e},e.PolyNode.prototype.ChildCount=function(){return this.m_Childs.length},e.PolyNode.prototype.Contour=function(){return this.m_polygon},e.PolyNode.prototype.AddChild=function(e){var t=this.m_Childs.length;this.m_Childs.push(e),e.m_Parent=this,e.m_Index=t},e.PolyNode.prototype.GetNext=function(){return this.m_Childs.length>0?this.m_Childs[0]:this.GetNextSiblingUp()},e.PolyNode.prototype.GetNextSiblingUp=function(){return this.m_Parent===null?null:this.m_Index===this.m_Parent.m_Childs.length-1?this.m_Parent.GetNextSiblingUp():this.m_Parent.m_Childs[this.m_Index+1]},e.PolyNode.prototype.Childs=function(){return this.m_Childs},e.PolyNode.prototype.Parent=function(){return this.m_Parent},e.PolyNode.prototype.IsHole=function(){return this.IsHoleNode()},e.PolyTree=function(){this.m_AllPolys=[],e.PolyNode.call(this)},e.PolyTree.prototype.Clear=function(){for(var e=0,t=this.m_AllPolys.length;e<t;e++)this.m_AllPolys[e]=null;this.m_AllPolys.length=0,this.m_Childs.length=0},e.PolyTree.prototype.GetFirst=function(){return this.m_Childs.length>0?this.m_Childs[0]:null},e.PolyTree.prototype.Total=function(){var e=this.m_AllPolys.length;return e>0&&this.m_Childs[0]!==this.m_AllPolys[0]&&e--,e},ht(e.PolyTree,e.PolyNode),e.Math_Abs_Int64=e.Math_Abs_Int32=e.Math_Abs_Double=function(e){return Math.abs(e)},e.Math_Max_Int32_Int32=function(e,t){return Math.max(e,t)},e.Cast_Int32=a.msie||a.opera||a.safari?function(e){return e|0}:function(e){return~~e},Number.toInteger===void 0&&(Number.toInteger=null),e.Cast_Int64=a.chrome?function(e){return e<-2147483648||e>2147483647?e<0?Math.ceil(e):Math.floor(e):~~e}:a.firefox&&typeof Number.toInteger==`function`?function(e){return Number.toInteger(e)}:a.msie7||a.msie8?function(e){return parseInt(e,10)}:a.msie?function(e){return e<-2147483648||e>2147483647?e<0?Math.ceil(e):Math.floor(e):e|0}:function(e){return e<0?Math.ceil(e):Math.floor(e)},e.Clear=function(e){e.length=0},e.PI=3.141592653589793,e.PI2=6.283185307179586,e.IntPoint=function(){var t=arguments,n=t.length;if(this.X=0,this.Y=0,e.use_xyz){if(this.Z=0,n===3)this.X=t[0],this.Y=t[1],this.Z=t[2];else if(n===2)this.X=t[0],this.Y=t[1],this.Z=0;else if(n===1){if(t[0]instanceof e.DoublePoint){var r=t[0];this.X=e.Clipper.Round(r.X),this.Y=e.Clipper.Round(r.Y),this.Z=0}else{var i=t[0];i.Z===void 0&&(i.Z=0),this.X=i.X,this.Y=i.Y,this.Z=i.Z}}else this.X=0,this.Y=0,this.Z=0}else if(n===2)this.X=t[0],this.Y=t[1];else if(n===1){if(t[0]instanceof e.DoublePoint){var r=t[0];this.X=e.Clipper.Round(r.X),this.Y=e.Clipper.Round(r.Y)}else{var i=t[0];this.X=i.X,this.Y=i.Y}}else this.X=0,this.Y=0},e.IntPoint.op_Equality=function(e,t){return e.X===t.X&&e.Y===t.Y},e.IntPoint.op_Inequality=function(e,t){return e.X!==t.X||e.Y!==t.Y},e.IntPoint0=function(){this.X=0,this.Y=0,e.use_xyz&&(this.Z=0)},e.IntPoint0.prototype=e.IntPoint.prototype,e.IntPoint1=function(t){this.X=t.X,this.Y=t.Y,e.use_xyz&&(this.Z=t.Z===void 0?0:t.Z)},e.IntPoint1.prototype=e.IntPoint.prototype,e.IntPoint1dp=function(t){this.X=e.Clipper.Round(t.X),this.Y=e.Clipper.Round(t.Y),e.use_xyz&&(this.Z=0)},e.IntPoint1dp.prototype=e.IntPoint.prototype,e.IntPoint2=function(t,n,r){this.X=t,this.Y=n,e.use_xyz&&(this.Z=r===void 0?0:r)},e.IntPoint2.prototype=e.IntPoint.prototype,e.IntRect=function(){var e=arguments,t=e.length;if(t===4)this.left=e[0],this.top=e[1],this.right=e[2],this.bottom=e[3];else if(t===1){var n=e[0];this.left=n.left,this.top=n.top,this.right=n.right,this.bottom=n.bottom}else this.left=0,this.top=0,this.right=0,this.bottom=0},e.IntRect0=function(){this.left=0,this.top=0,this.right=0,this.bottom=0},e.IntRect0.prototype=e.IntRect.prototype,e.IntRect1=function(e){this.left=e.left,this.top=e.top,this.right=e.right,this.bottom=e.bottom},e.IntRect1.prototype=e.IntRect.prototype,e.IntRect4=function(e,t,n,r){this.left=e,this.top=t,this.right=n,this.bottom=r},e.IntRect4.prototype=e.IntRect.prototype,e.ClipType={ctIntersection:0,ctUnion:1,ctDifference:2,ctXor:3},e.PolyType={ptSubject:0,ptClip:1},e.PolyFillType={pftEvenOdd:0,pftNonZero:1,pftPositive:2,pftNegative:3},e.JoinType={jtSquare:0,jtRound:1,jtMiter:2},e.EndType={etOpenSquare:0,etOpenRound:1,etOpenButt:2,etClosedLine:3,etClosedPolygon:4},e.EdgeSide={esLeft:0,esRight:1},e.Direction={dRightToLeft:0,dLeftToRight:1},e.TEdge=function(){this.Bot=new e.IntPoint0,this.Curr=new e.IntPoint0,this.Top=new e.IntPoint0,this.Delta=new e.IntPoint0,this.Dx=0,this.PolyTyp=e.PolyType.ptSubject,this.Side=e.EdgeSide.esLeft,this.WindDelta=0,this.WindCnt=0,this.WindCnt2=0,this.OutIdx=0,this.Next=null,this.Prev=null,this.NextInLML=null,this.NextInAEL=null,this.PrevInAEL=null,this.NextInSEL=null,this.PrevInSEL=null},e.IntersectNode=function(){this.Edge1=null,this.Edge2=null,this.Pt=new e.IntPoint0},e.MyIntersectNodeSort=function(){},e.MyIntersectNodeSort.Compare=function(e,t){var n=t.Pt.Y-e.Pt.Y;return n>0?1:n<0?-1:0},e.LocalMinima=function(){this.Y=0,this.LeftBound=null,this.RightBound=null,this.Next=null},e.Scanbeam=function(){this.Y=0,this.Next=null},e.Maxima=function(){this.X=0,this.Next=null,this.Prev=null},e.OutRec=function(){this.Idx=0,this.IsHole=!1,this.IsOpen=!1,this.FirstLeft=null,this.Pts=null,this.BottomPt=null,this.PolyNode=null},e.OutPt=function(){this.Idx=0,this.Pt=new e.IntPoint0,this.Next=null,this.Prev=null},e.Join=function(){this.OutPt1=null,this.OutPt2=null,this.OffPt=new e.IntPoint0},e.ClipperBase=function(){this.m_MinimaList=null,this.m_CurrentLM=null,this.m_edges=[],this.m_UseFullRange=!1,this.m_HasOpenPaths=!1,this.PreserveCollinear=!1,this.m_Scanbeam=null,this.m_PolyOuts=null,this.m_ActiveEdges=null},e.ClipperBase.horizontal=-9007199254740992,e.ClipperBase.Skip=-2,e.ClipperBase.Unassigned=-1,e.ClipperBase.tolerance=1e-20,e.ClipperBase.loRange=47453132,e.ClipperBase.hiRange=0xfffffffffffff,e.ClipperBase.near_zero=function(t){return t>-e.ClipperBase.tolerance&&t<e.ClipperBase.tolerance},e.ClipperBase.IsHorizontal=function(e){return e.Delta.Y===0},e.ClipperBase.prototype.PointIsVertex=function(t,n){var r=n;do{if(e.IntPoint.op_Equality(r.Pt,t))return!0;r=r.Next}while(r!==n);return!1},e.ClipperBase.prototype.PointOnLineSegment=function(e,t,n,r){return r?e.X===t.X&&e.Y===t.Y||e.X===n.X&&e.Y===n.Y||e.X>t.X==e.X<n.X&&e.Y>t.Y==e.Y<n.Y&&Q.op_Equality(Q.Int128Mul(e.X-t.X,n.Y-t.Y),Q.Int128Mul(n.X-t.X,e.Y-t.Y)):e.X===t.X&&e.Y===t.Y||e.X===n.X&&e.Y===n.Y||e.X>t.X==e.X<n.X&&e.Y>t.Y==e.Y<n.Y&&(e.X-t.X)*(n.Y-t.Y)===(n.X-t.X)*(e.Y-t.Y)},e.ClipperBase.prototype.PointOnPolygon=function(e,t,n){for(var r=t;;){if(this.PointOnLineSegment(e,r.Pt,r.Next.Pt,n))return!0;if(r=r.Next,r===t)break}return!1},e.ClipperBase.prototype.SlopesEqual=e.ClipperBase.SlopesEqual=function(){var t=arguments,n=t.length,r,i,a,o,s,c,l;return n===3?(r=t[0],i=t[1],l=t[2],l?Q.op_Equality(Q.Int128Mul(r.Delta.Y,i.Delta.X),Q.Int128Mul(r.Delta.X,i.Delta.Y)):e.Cast_Int64(r.Delta.Y*i.Delta.X)===e.Cast_Int64(r.Delta.X*i.Delta.Y)):n===4?(a=t[0],o=t[1],s=t[2],l=t[3],l?Q.op_Equality(Q.Int128Mul(a.Y-o.Y,o.X-s.X),Q.Int128Mul(a.X-o.X,o.Y-s.Y)):e.Cast_Int64((a.Y-o.Y)*(o.X-s.X))-e.Cast_Int64((a.X-o.X)*(o.Y-s.Y))===0):(a=t[0],o=t[1],s=t[2],c=t[3],l=t[4],l?Q.op_Equality(Q.Int128Mul(a.Y-o.Y,s.X-c.X),Q.Int128Mul(a.X-o.X,s.Y-c.Y)):e.Cast_Int64((a.Y-o.Y)*(s.X-c.X))-e.Cast_Int64((a.X-o.X)*(s.Y-c.Y))===0)},e.ClipperBase.SlopesEqual3=function(t,n,r){return r?Q.op_Equality(Q.Int128Mul(t.Delta.Y,n.Delta.X),Q.Int128Mul(t.Delta.X,n.Delta.Y)):e.Cast_Int64(t.Delta.Y*n.Delta.X)===e.Cast_Int64(t.Delta.X*n.Delta.Y)},e.ClipperBase.SlopesEqual4=function(t,n,r,i){return i?Q.op_Equality(Q.Int128Mul(t.Y-n.Y,n.X-r.X),Q.Int128Mul(t.X-n.X,n.Y-r.Y)):e.Cast_Int64((t.Y-n.Y)*(n.X-r.X))-e.Cast_Int64((t.X-n.X)*(n.Y-r.Y))===0},e.ClipperBase.SlopesEqual5=function(t,n,r,i,a){return a?Q.op_Equality(Q.Int128Mul(t.Y-n.Y,r.X-i.X),Q.Int128Mul(t.X-n.X,r.Y-i.Y)):e.Cast_Int64((t.Y-n.Y)*(r.X-i.X))-e.Cast_Int64((t.X-n.X)*(r.Y-i.Y))===0},e.ClipperBase.prototype.Clear=function(){this.DisposeLocalMinimaList();for(var t=0,n=this.m_edges.length;t<n;++t){for(var r=0,i=this.m_edges[t].length;r<i;++r)this.m_edges[t][r]=null;e.Clear(this.m_edges[t])}e.Clear(this.m_edges),this.m_UseFullRange=!1,this.m_HasOpenPaths=!1},e.ClipperBase.prototype.DisposeLocalMinimaList=function(){for(;this.m_MinimaList!==null;){var e=this.m_MinimaList.Next;this.m_MinimaList=null,this.m_MinimaList=e}this.m_CurrentLM=null},e.ClipperBase.prototype.RangeTest=function(t,n){n.Value?(t.X>e.ClipperBase.hiRange||t.Y>e.ClipperBase.hiRange||-t.X>e.ClipperBase.hiRange||-t.Y>e.ClipperBase.hiRange)&&e.Error(`Coordinate outside allowed range in RangeTest().`):(t.X>e.ClipperBase.loRange||t.Y>e.ClipperBase.loRange||-t.X>e.ClipperBase.loRange||-t.Y>e.ClipperBase.loRange)&&(n.Value=!0,this.RangeTest(t,n))},e.ClipperBase.prototype.InitEdge=function(t,n,r,i){t.Next=n,t.Prev=r,t.Curr.X=i.X,t.Curr.Y=i.Y,e.use_xyz&&(t.Curr.Z=i.Z),t.OutIdx=-1},e.ClipperBase.prototype.InitEdge2=function(t,n){t.Curr.Y>=t.Next.Curr.Y?(t.Bot.X=t.Curr.X,t.Bot.Y=t.Curr.Y,e.use_xyz&&(t.Bot.Z=t.Curr.Z),t.Top.X=t.Next.Curr.X,t.Top.Y=t.Next.Curr.Y,e.use_xyz&&(t.Top.Z=t.Next.Curr.Z)):(t.Top.X=t.Curr.X,t.Top.Y=t.Curr.Y,e.use_xyz&&(t.Top.Z=t.Curr.Z),t.Bot.X=t.Next.Curr.X,t.Bot.Y=t.Next.Curr.Y,e.use_xyz&&(t.Bot.Z=t.Next.Curr.Z)),this.SetDx(t),t.PolyTyp=n},e.ClipperBase.prototype.FindNextLocMin=function(t){for(var n;;){for(;e.IntPoint.op_Inequality(t.Bot,t.Prev.Bot)||e.IntPoint.op_Equality(t.Curr,t.Top);)t=t.Next;if(t.Dx!==e.ClipperBase.horizontal&&t.Prev.Dx!==e.ClipperBase.horizontal)break;for(;t.Prev.Dx===e.ClipperBase.horizontal;)t=t.Prev;for(n=t;t.Dx===e.ClipperBase.horizontal;)t=t.Next;if(t.Top.Y!==t.Prev.Bot.Y){n.Prev.Bot.X<t.Bot.X&&(t=n);break}}return t},e.ClipperBase.prototype.ProcessBound=function(t,n){var r,i=t,a;if(i.OutIdx===e.ClipperBase.Skip){if(t=i,n){for(;t.Top.Y===t.Next.Bot.Y;)t=t.Next;for(;t!==i&&t.Dx===e.ClipperBase.horizontal;)t=t.Prev}else{for(;t.Top.Y===t.Prev.Bot.Y;)t=t.Prev;for(;t!==i&&t.Dx===e.ClipperBase.horizontal;)t=t.Next}if(t===i)i=n?t.Next:t.Prev;else{t=n?i.Next:i.Prev;var o=new e.LocalMinima;o.Next=null,o.Y=t.Bot.Y,o.LeftBound=null,o.RightBound=t,t.WindDelta=0,i=this.ProcessBound(t,n),this.InsertLocalMinima(o)}return i}if(t.Dx===e.ClipperBase.horizontal&&(r=n?t.Prev:t.Next,r.Dx===e.ClipperBase.horizontal?r.Bot.X!==t.Bot.X&&r.Top.X!==t.Bot.X&&this.ReverseHorizontal(t):r.Bot.X!==t.Bot.X&&this.ReverseHorizontal(t)),r=t,n){for(;i.Top.Y===i.Next.Bot.Y&&i.Next.OutIdx!==e.ClipperBase.Skip;)i=i.Next;if(i.Dx===e.ClipperBase.horizontal&&i.Next.OutIdx!==e.ClipperBase.Skip){for(a=i;a.Prev.Dx===e.ClipperBase.horizontal;)a=a.Prev;a.Prev.Top.X>i.Next.Top.X&&(i=a.Prev)}for(;t!==i;)t.NextInLML=t.Next,t.Dx===e.ClipperBase.horizontal&&t!==r&&t.Bot.X!==t.Prev.Top.X&&this.ReverseHorizontal(t),t=t.Next;t.Dx===e.ClipperBase.horizontal&&t!==r&&t.Bot.X!==t.Prev.Top.X&&this.ReverseHorizontal(t),i=i.Next}else{for(;i.Top.Y===i.Prev.Bot.Y&&i.Prev.OutIdx!==e.ClipperBase.Skip;)i=i.Prev;if(i.Dx===e.ClipperBase.horizontal&&i.Prev.OutIdx!==e.ClipperBase.Skip){for(a=i;a.Next.Dx===e.ClipperBase.horizontal;)a=a.Next;(a.Next.Top.X===i.Prev.Top.X||a.Next.Top.X>i.Prev.Top.X)&&(i=a.Next)}for(;t!==i;)t.NextInLML=t.Prev,t.Dx===e.ClipperBase.horizontal&&t!==r&&t.Bot.X!==t.Next.Top.X&&this.ReverseHorizontal(t),t=t.Prev;t.Dx===e.ClipperBase.horizontal&&t!==r&&t.Bot.X!==t.Next.Top.X&&this.ReverseHorizontal(t),i=i.Prev}return i},e.ClipperBase.prototype.AddPath=function(t,n,r){e.use_lines?!r&&n===e.PolyType.ptClip&&e.Error(`AddPath: Open paths must be subject.`):r||e.Error(`AddPath: Open paths have been disabled.`);var i=t.length-1;if(r)for(;i>0&&e.IntPoint.op_Equality(t[i],t[0]);)--i;for(;i>0&&e.IntPoint.op_Equality(t[i],t[i-1]);)--i;if(r&&i<2||!r&&i<1)return!1;for(var a=[],o=0;o<=i;o++)a.push(new e.TEdge);var s=!0;a[1].Curr.X=t[1].X,a[1].Curr.Y=t[1].Y,e.use_xyz&&(a[1].Curr.Z=t[1].Z);var c={Value:this.m_UseFullRange};this.RangeTest(t[0],c),this.m_UseFullRange=c.Value,c.Value=this.m_UseFullRange,this.RangeTest(t[i],c),this.m_UseFullRange=c.Value,this.InitEdge(a[0],a[1],a[i],t[0]),this.InitEdge(a[i],a[0],a[i-1],t[i]);for(var o=i-1;o>=1;--o)c.Value=this.m_UseFullRange,this.RangeTest(t[o],c),this.m_UseFullRange=c.Value,this.InitEdge(a[o],a[o+1],a[o-1],t[o]);for(var l=a[0],u=l,d=l;;)if(u.Curr===u.Next.Curr&&(r||u.Next!==l)){if(u===u.Next)break;u===l&&(l=u.Next),u=this.RemoveEdge(u),d=u}else{if(u.Prev===u.Next)break;if(r&&e.ClipperBase.SlopesEqual4(u.Prev.Curr,u.Curr,u.Next.Curr,this.m_UseFullRange)&&(!this.PreserveCollinear||!this.Pt2IsBetweenPt1AndPt3(u.Prev.Curr,u.Curr,u.Next.Curr)))u===l&&(l=u.Next),u=this.RemoveEdge(u),u=u.Prev,d=u;else if(u=u.Next,u===d||!r&&u.Next===l)break}if(!r&&u===u.Next||r&&u.Prev===u.Next)return!1;r||(this.m_HasOpenPaths=!0,l.Prev.OutIdx=e.ClipperBase.Skip),u=l;do this.InitEdge2(u,n),u=u.Next,s&&u.Curr.Y!==l.Curr.Y&&(s=!1);while(u!==l);if(s){if(r)return!1;u.Prev.OutIdx=e.ClipperBase.Skip;var f=new e.LocalMinima;for(f.Next=null,f.Y=u.Bot.Y,f.LeftBound=null,f.RightBound=u,f.RightBound.Side=e.EdgeSide.esRight,f.RightBound.WindDelta=0;u.Bot.X!==u.Prev.Top.X&&this.ReverseHorizontal(u),u.Next.OutIdx!==e.ClipperBase.Skip;)u.NextInLML=u.Next,u=u.Next;return this.InsertLocalMinima(f),this.m_edges.push(a),!0}this.m_edges.push(a);var p,m=null;for(e.IntPoint.op_Equality(u.Prev.Bot,u.Prev.Top)&&(u=u.Next);u=this.FindNextLocMin(u),u!==m;){m===null&&(m=u);var f=new e.LocalMinima;f.Next=null,f.Y=u.Bot.Y,u.Dx<u.Prev.Dx?(f.LeftBound=u.Prev,f.RightBound=u,p=!1):(f.LeftBound=u,f.RightBound=u.Prev,p=!0),f.LeftBound.Side=e.EdgeSide.esLeft,f.RightBound.Side=e.EdgeSide.esRight,r?f.LeftBound.Next===f.RightBound?f.LeftBound.WindDelta=-1:f.LeftBound.WindDelta=1:f.LeftBound.WindDelta=0,f.RightBound.WindDelta=-f.LeftBound.WindDelta,u=this.ProcessBound(f.LeftBound,p),u.OutIdx===e.ClipperBase.Skip&&(u=this.ProcessBound(u,p));var h=this.ProcessBound(f.RightBound,!p);h.OutIdx===e.ClipperBase.Skip&&(h=this.ProcessBound(h,!p)),f.LeftBound.OutIdx===e.ClipperBase.Skip?f.LeftBound=null:f.RightBound.OutIdx===e.ClipperBase.Skip&&(f.RightBound=null),this.InsertLocalMinima(f),p||(u=h)}return!0},e.ClipperBase.prototype.AddPaths=function(e,t,n){for(var r=!1,i=0,a=e.length;i<a;++i)this.AddPath(e[i],t,n)&&(r=!0);return r},e.ClipperBase.prototype.Pt2IsBetweenPt1AndPt3=function(t,n,r){return e.IntPoint.op_Equality(t,r)||e.IntPoint.op_Equality(t,n)||e.IntPoint.op_Equality(r,n)?!1:t.X===r.X?n.Y>t.Y==n.Y<r.Y:n.X>t.X==n.X<r.X},e.ClipperBase.prototype.RemoveEdge=function(e){e.Prev.Next=e.Next,e.Next.Prev=e.Prev;var t=e.Next;return e.Prev=null,t},e.ClipperBase.prototype.SetDx=function(t){t.Delta.X=t.Top.X-t.Bot.X,t.Delta.Y=t.Top.Y-t.Bot.Y,t.Dx=t.Delta.Y===0?e.ClipperBase.horizontal:t.Delta.X/t.Delta.Y},e.ClipperBase.prototype.InsertLocalMinima=function(e){if(this.m_MinimaList===null)this.m_MinimaList=e;else if(e.Y>=this.m_MinimaList.Y)e.Next=this.m_MinimaList,this.m_MinimaList=e;else{for(var t=this.m_MinimaList;t.Next!==null&&e.Y<t.Next.Y;)t=t.Next;e.Next=t.Next,t.Next=e}},e.ClipperBase.prototype.PopLocalMinima=function(e,t){return t.v=this.m_CurrentLM,this.m_CurrentLM!==null&&this.m_CurrentLM.Y===e&&(this.m_CurrentLM=this.m_CurrentLM.Next,!0)},e.ClipperBase.prototype.ReverseHorizontal=function(t){var n=t.Top.X;t.Top.X=t.Bot.X,t.Bot.X=n,e.use_xyz&&(n=t.Top.Z,t.Top.Z=t.Bot.Z,t.Bot.Z=n)},e.ClipperBase.prototype.Reset=function(){if(this.m_CurrentLM=this.m_MinimaList,this.m_CurrentLM!==null){this.m_Scanbeam=null;for(var t=this.m_MinimaList;t!==null;){this.InsertScanbeam(t.Y);var n=t.LeftBound;n!==null&&(n.Curr.X=n.Bot.X,n.Curr.Y=n.Bot.Y,e.use_xyz&&(n.Curr.Z=n.Bot.Z),n.OutIdx=e.ClipperBase.Unassigned),n=t.RightBound,n!==null&&(n.Curr.X=n.Bot.X,n.Curr.Y=n.Bot.Y,e.use_xyz&&(n.Curr.Z=n.Bot.Z),n.OutIdx=e.ClipperBase.Unassigned),t=t.Next}this.m_ActiveEdges=null}},e.ClipperBase.prototype.InsertScanbeam=function(t){if(this.m_Scanbeam===null)this.m_Scanbeam=new e.Scanbeam,this.m_Scanbeam.Next=null,this.m_Scanbeam.Y=t;else if(t>this.m_Scanbeam.Y){var n=new e.Scanbeam;n.Y=t,n.Next=this.m_Scanbeam,this.m_Scanbeam=n}else{for(var r=this.m_Scanbeam;r.Next!==null&&t<=r.Next.Y;)r=r.Next;if(t===r.Y)return;var i=new e.Scanbeam;i.Y=t,i.Next=r.Next,r.Next=i}},e.ClipperBase.prototype.PopScanbeam=function(e){return this.m_Scanbeam===null?(e.v=0,!1):(e.v=this.m_Scanbeam.Y,this.m_Scanbeam=this.m_Scanbeam.Next,!0)},e.ClipperBase.prototype.LocalMinimaPending=function(){return this.m_CurrentLM!==null},e.ClipperBase.prototype.CreateOutRec=function(){var t=new e.OutRec;return t.Idx=e.ClipperBase.Unassigned,t.IsHole=!1,t.IsOpen=!1,t.FirstLeft=null,t.Pts=null,t.BottomPt=null,t.PolyNode=null,this.m_PolyOuts.push(t),t.Idx=this.m_PolyOuts.length-1,t},e.ClipperBase.prototype.DisposeOutRec=function(e){var t=this.m_PolyOuts[e];t.Pts=null,t=null,this.m_PolyOuts[e]=null},e.ClipperBase.prototype.UpdateEdgeIntoAEL=function(t){t.NextInLML===null&&e.Error(`UpdateEdgeIntoAEL: invalid call`);var n=t.PrevInAEL,r=t.NextInAEL;return t.NextInLML.OutIdx=t.OutIdx,n===null?this.m_ActiveEdges=t.NextInLML:n.NextInAEL=t.NextInLML,r!==null&&(r.PrevInAEL=t.NextInLML),t.NextInLML.Side=t.Side,t.NextInLML.WindDelta=t.WindDelta,t.NextInLML.WindCnt=t.WindCnt,t.NextInLML.WindCnt2=t.WindCnt2,t=t.NextInLML,t.Curr.X=t.Bot.X,t.Curr.Y=t.Bot.Y,t.PrevInAEL=n,t.NextInAEL=r,e.ClipperBase.IsHorizontal(t)||this.InsertScanbeam(t.Top.Y),t},e.ClipperBase.prototype.SwapPositionsInAEL=function(e,t){if(e.NextInAEL!==e.PrevInAEL&&t.NextInAEL!==t.PrevInAEL){if(e.NextInAEL===t){var n=t.NextInAEL;n!==null&&(n.PrevInAEL=e);var r=e.PrevInAEL;r!==null&&(r.NextInAEL=t),t.PrevInAEL=r,t.NextInAEL=e,e.PrevInAEL=t,e.NextInAEL=n}else if(t.NextInAEL===e){var i=e.NextInAEL;i!==null&&(i.PrevInAEL=t);var a=t.PrevInAEL;a!==null&&(a.NextInAEL=e),e.PrevInAEL=a,e.NextInAEL=t,t.PrevInAEL=e,t.NextInAEL=i}else{var o=e.NextInAEL,s=e.PrevInAEL;e.NextInAEL=t.NextInAEL,e.NextInAEL!==null&&(e.NextInAEL.PrevInAEL=e),e.PrevInAEL=t.PrevInAEL,e.PrevInAEL!==null&&(e.PrevInAEL.NextInAEL=e),t.NextInAEL=o,t.NextInAEL!==null&&(t.NextInAEL.PrevInAEL=t),t.PrevInAEL=s,t.PrevInAEL!==null&&(t.PrevInAEL.NextInAEL=t)}e.PrevInAEL===null?this.m_ActiveEdges=e:t.PrevInAEL===null&&(this.m_ActiveEdges=t)}},e.ClipperBase.prototype.DeleteFromAEL=function(e){var t=e.PrevInAEL,n=e.NextInAEL;(t!==null||n!==null||e===this.m_ActiveEdges)&&(t===null?this.m_ActiveEdges=n:t.NextInAEL=n,n!==null&&(n.PrevInAEL=t),e.NextInAEL=null,e.PrevInAEL=null)},e.Clipper=function(t){t===void 0&&(t=0),this.m_PolyOuts=null,this.m_ClipType=e.ClipType.ctIntersection,this.m_Scanbeam=null,this.m_Maxima=null,this.m_ActiveEdges=null,this.m_SortedEdges=null,this.m_IntersectList=null,this.m_IntersectNodeComparer=null,this.m_ExecuteLocked=!1,this.m_ClipFillType=e.PolyFillType.pftEvenOdd,this.m_SubjFillType=e.PolyFillType.pftEvenOdd,this.m_Joins=null,this.m_GhostJoins=null,this.m_UsingPolyTree=!1,this.ReverseSolution=!1,this.StrictlySimple=!1,e.ClipperBase.call(this),this.m_Scanbeam=null,this.m_Maxima=null,this.m_ActiveEdges=null,this.m_SortedEdges=null,this.m_IntersectList=[],this.m_IntersectNodeComparer=e.MyIntersectNodeSort.Compare,this.m_ExecuteLocked=!1,this.m_UsingPolyTree=!1,this.m_PolyOuts=[],this.m_Joins=[],this.m_GhostJoins=[],this.ReverseSolution=!!(1&t),this.StrictlySimple=!!(2&t),this.PreserveCollinear=!!(4&t),e.use_xyz&&(this.ZFillFunction=null)},e.Clipper.ioReverseSolution=1,e.Clipper.ioStrictlySimple=2,e.Clipper.ioPreserveCollinear=4,e.Clipper.prototype.Clear=function(){this.m_edges.length!==0&&(this.DisposeAllPolyPts(),e.ClipperBase.prototype.Clear.call(this))},e.Clipper.prototype.InsertMaxima=function(t){var n=new e.Maxima;if(n.X=t,this.m_Maxima===null)this.m_Maxima=n,this.m_Maxima.Next=null,this.m_Maxima.Prev=null;else if(t<this.m_Maxima.X)n.Next=this.m_Maxima,n.Prev=null,this.m_Maxima=n;else{for(var r=this.m_Maxima;r.Next!==null&&t>=r.Next.X;)r=r.Next;if(t===r.X)return;n.Next=r.Next,n.Prev=r,r.Next!==null&&(r.Next.Prev=n),r.Next=n}},e.Clipper.prototype.Execute=function(){var t=arguments,n=t.length,r=t[1]instanceof e.PolyTree;if(n===4&&!r){var i=t[0],a=t[1],o=t[2],s=t[3];if(this.m_ExecuteLocked)return!1;this.m_HasOpenPaths&&e.Error(`Error: PolyTree struct is needed for open path clipping.`),this.m_ExecuteLocked=!0,e.Clear(a),this.m_SubjFillType=o,this.m_ClipFillType=s,this.m_ClipType=i,this.m_UsingPolyTree=!1;try{var c=this.ExecuteInternal();c&&this.BuildResult(a)}finally{this.DisposeAllPolyPts(),this.m_ExecuteLocked=!1}return c}if(n===4&&r){var i=t[0],l=t[1],o=t[2],s=t[3];if(this.m_ExecuteLocked)return!1;this.m_ExecuteLocked=!0,this.m_SubjFillType=o,this.m_ClipFillType=s,this.m_ClipType=i,this.m_UsingPolyTree=!0;try{var c=this.ExecuteInternal();c&&this.BuildResult2(l)}finally{this.DisposeAllPolyPts(),this.m_ExecuteLocked=!1}return c}if(n===2&&!r){var i=t[0],a=t[1];return this.Execute(i,a,e.PolyFillType.pftEvenOdd,e.PolyFillType.pftEvenOdd)}if(n===2&&r){var i=t[0],l=t[1];return this.Execute(i,l,e.PolyFillType.pftEvenOdd,e.PolyFillType.pftEvenOdd)}},e.Clipper.prototype.FixHoleLinkage=function(e){if(!(e.FirstLeft===null||e.IsHole!==e.FirstLeft.IsHole&&e.FirstLeft.Pts!==null)){for(var t=e.FirstLeft;t!==null&&(t.IsHole===e.IsHole||t.Pts===null);)t=t.FirstLeft;e.FirstLeft=t}},e.Clipper.prototype.ExecuteInternal=function(){try{this.Reset(),this.m_SortedEdges=null,this.m_Maxima=null;var e={},t={};if(!this.PopScanbeam(e))return!1;for(this.InsertLocalMinimaIntoAEL(e.v);this.PopScanbeam(t)||this.LocalMinimaPending();){if(this.ProcessHorizontals(),this.m_GhostJoins.length=0,!this.ProcessIntersections(t.v))return!1;this.ProcessEdgesAtTopOfScanbeam(t.v),e.v=t.v,this.InsertLocalMinimaIntoAEL(e.v)}for(var n,r=0,i=this.m_PolyOuts.length;r<i;r++)n=this.m_PolyOuts[r],n.Pts===null||n.IsOpen||(n.IsHole^this.ReverseSolution)==this.Area$1(n)>0&&this.ReversePolyPtLinks(n.Pts);for(this.JoinCommonEdges(),r=0,i=this.m_PolyOuts.length;r<i;r++)n=this.m_PolyOuts[r],n.Pts!==null&&(n.IsOpen?this.FixupOutPolyline(n):this.FixupOutPolygon(n));return this.StrictlySimple&&this.DoSimplePolygons(),!0}finally{this.m_Joins.length=0,this.m_GhostJoins.length=0}},e.Clipper.prototype.DisposeAllPolyPts=function(){for(var t=0,n=this.m_PolyOuts.length;t<n;++t)this.DisposeOutRec(t);e.Clear(this.m_PolyOuts)},e.Clipper.prototype.AddJoin=function(t,n,r){var i=new e.Join;i.OutPt1=t,i.OutPt2=n,i.OffPt.X=r.X,i.OffPt.Y=r.Y,e.use_xyz&&(i.OffPt.Z=r.Z),this.m_Joins.push(i)},e.Clipper.prototype.AddGhostJoin=function(t,n){var r=new e.Join;r.OutPt1=t,r.OffPt.X=n.X,r.OffPt.Y=n.Y,e.use_xyz&&(r.OffPt.Z=n.Z),this.m_GhostJoins.push(r)},e.Clipper.prototype.SetZ=function(t,n,r){if(this.ZFillFunction!==null){if(t.Z!==0||this.ZFillFunction===null)return;e.IntPoint.op_Equality(t,n.Bot)?t.Z=n.Bot.Z:e.IntPoint.op_Equality(t,n.Top)?t.Z=n.Top.Z:e.IntPoint.op_Equality(t,r.Bot)?t.Z=r.Bot.Z:e.IntPoint.op_Equality(t,r.Top)?t.Z=r.Top.Z:this.ZFillFunction(n.Bot,n.Top,r.Bot,r.Top,t)}},e.Clipper.prototype.InsertLocalMinimaIntoAEL=function(t){for(var n={},r,i;this.PopLocalMinima(t,n);){r=n.v.LeftBound,i=n.v.RightBound;var a=null;if(r===null?(this.InsertEdgeIntoAEL(i,null),this.SetWindingCount(i),this.IsContributing(i)&&(a=this.AddOutPt(i,i.Bot))):i===null?(this.InsertEdgeIntoAEL(r,null),this.SetWindingCount(r),this.IsContributing(r)&&(a=this.AddOutPt(r,r.Bot)),this.InsertScanbeam(r.Top.Y)):(this.InsertEdgeIntoAEL(r,null),this.InsertEdgeIntoAEL(i,r),this.SetWindingCount(r),i.WindCnt=r.WindCnt,i.WindCnt2=r.WindCnt2,this.IsContributing(r)&&(a=this.AddLocalMinPoly(r,i,r.Bot)),this.InsertScanbeam(r.Top.Y)),i!==null&&(e.ClipperBase.IsHorizontal(i)?(i.NextInLML!==null&&this.InsertScanbeam(i.NextInLML.Top.Y),this.AddEdgeToSEL(i)):this.InsertScanbeam(i.Top.Y)),r!==null&&i!==null){if(a!==null&&e.ClipperBase.IsHorizontal(i)&&this.m_GhostJoins.length>0&&i.WindDelta!==0)for(var o=0,s=this.m_GhostJoins.length;o<s;o++){var c=this.m_GhostJoins[o];this.HorzSegmentsOverlap(c.OutPt1.Pt.X,c.OffPt.X,i.Bot.X,i.Top.X)&&this.AddJoin(c.OutPt1,a,c.OffPt)}if(r.OutIdx>=0&&r.PrevInAEL!==null&&r.PrevInAEL.Curr.X===r.Bot.X&&r.PrevInAEL.OutIdx>=0&&e.ClipperBase.SlopesEqual5(r.PrevInAEL.Curr,r.PrevInAEL.Top,r.Curr,r.Top,this.m_UseFullRange)&&r.WindDelta!==0&&r.PrevInAEL.WindDelta!==0){var l=this.AddOutPt(r.PrevInAEL,r.Bot);this.AddJoin(a,l,r.Top)}if(r.NextInAEL!==i){if(i.OutIdx>=0&&i.PrevInAEL.OutIdx>=0&&e.ClipperBase.SlopesEqual5(i.PrevInAEL.Curr,i.PrevInAEL.Top,i.Curr,i.Top,this.m_UseFullRange)&&i.WindDelta!==0&&i.PrevInAEL.WindDelta!==0){var l=this.AddOutPt(i.PrevInAEL,i.Bot);this.AddJoin(a,l,i.Top)}var u=r.NextInAEL;if(u!==null)for(;u!==i;)this.IntersectEdges(i,u,r.Curr),u=u.NextInAEL}}}},e.Clipper.prototype.InsertEdgeIntoAEL=function(e,t){if(this.m_ActiveEdges===null)e.PrevInAEL=null,e.NextInAEL=null,this.m_ActiveEdges=e;else if(t===null&&this.E2InsertsBeforeE1(this.m_ActiveEdges,e))e.PrevInAEL=null,e.NextInAEL=this.m_ActiveEdges,this.m_ActiveEdges.PrevInAEL=e,this.m_ActiveEdges=e;else{for(t===null&&(t=this.m_ActiveEdges);t.NextInAEL!==null&&!this.E2InsertsBeforeE1(t.NextInAEL,e);)t=t.NextInAEL;e.NextInAEL=t.NextInAEL,t.NextInAEL!==null&&(t.NextInAEL.PrevInAEL=e),e.PrevInAEL=t,t.NextInAEL=e}},e.Clipper.prototype.E2InsertsBeforeE1=function(t,n){return n.Curr.X===t.Curr.X?n.Top.Y>t.Top.Y?n.Top.X<e.Clipper.TopX(t,n.Top.Y):t.Top.X>e.Clipper.TopX(n,t.Top.Y):n.Curr.X<t.Curr.X},e.Clipper.prototype.IsEvenOddFillType=function(t){return t.PolyTyp===e.PolyType.ptSubject?this.m_SubjFillType===e.PolyFillType.pftEvenOdd:this.m_ClipFillType===e.PolyFillType.pftEvenOdd},e.Clipper.prototype.IsEvenOddAltFillType=function(t){return t.PolyTyp===e.PolyType.ptSubject?this.m_ClipFillType===e.PolyFillType.pftEvenOdd:this.m_SubjFillType===e.PolyFillType.pftEvenOdd},e.Clipper.prototype.IsContributing=function(t){var n,r;switch(t.PolyTyp===e.PolyType.ptSubject?(n=this.m_SubjFillType,r=this.m_ClipFillType):(n=this.m_ClipFillType,r=this.m_SubjFillType),n){case e.PolyFillType.pftEvenOdd:if(t.WindDelta===0&&t.WindCnt!==1)return!1;break;case e.PolyFillType.pftNonZero:if(Math.abs(t.WindCnt)!==1)return!1;break;case e.PolyFillType.pftPositive:if(t.WindCnt!==1)return!1;break;default:if(t.WindCnt!==-1)return!1}switch(this.m_ClipType){case e.ClipType.ctIntersection:switch(r){case e.PolyFillType.pftEvenOdd:case e.PolyFillType.pftNonZero:return t.WindCnt2!==0;case e.PolyFillType.pftPositive:return t.WindCnt2>0;default:return t.WindCnt2<0}case e.ClipType.ctUnion:switch(r){case e.PolyFillType.pftEvenOdd:case e.PolyFillType.pftNonZero:return t.WindCnt2===0;case e.PolyFillType.pftPositive:return t.WindCnt2<=0;default:return t.WindCnt2>=0}case e.ClipType.ctDifference:if(t.PolyTyp===e.PolyType.ptSubject)switch(r){case e.PolyFillType.pftEvenOdd:case e.PolyFillType.pftNonZero:return t.WindCnt2===0;case e.PolyFillType.pftPositive:return t.WindCnt2<=0;default:return t.WindCnt2>=0}else switch(r){case e.PolyFillType.pftEvenOdd:case e.PolyFillType.pftNonZero:return t.WindCnt2!==0;case e.PolyFillType.pftPositive:return t.WindCnt2>0;default:return t.WindCnt2<0}case e.ClipType.ctXor:if(t.WindDelta===0)switch(r){case e.PolyFillType.pftEvenOdd:case e.PolyFillType.pftNonZero:return t.WindCnt2===0;case e.PolyFillType.pftPositive:return t.WindCnt2<=0;default:return t.WindCnt2>=0}else return!0}return!0},e.Clipper.prototype.SetWindingCount=function(t){for(var n=t.PrevInAEL;n!==null&&(n.PolyTyp!==t.PolyTyp||n.WindDelta===0);)n=n.PrevInAEL;if(n===null){var r=t.PolyTyp===e.PolyType.ptSubject?this.m_SubjFillType:this.m_ClipFillType;t.WindCnt=t.WindDelta===0?r===e.PolyFillType.pftNegative?-1:1:t.WindDelta,t.WindCnt2=0,n=this.m_ActiveEdges}else if(t.WindDelta===0&&this.m_ClipType!==e.ClipType.ctUnion)t.WindCnt=1,t.WindCnt2=n.WindCnt2,n=n.NextInAEL;else if(this.IsEvenOddFillType(t)){if(t.WindDelta===0){for(var i=!0,a=n.PrevInAEL;a!==null;)a.PolyTyp===n.PolyTyp&&a.WindDelta!==0&&(i=!i),a=a.PrevInAEL;t.WindCnt=+!i}else t.WindCnt=t.WindDelta;t.WindCnt2=n.WindCnt2,n=n.NextInAEL}else t.WindCnt=n.WindCnt*n.WindDelta<0?Math.abs(n.WindCnt)>1?n.WindDelta*t.WindDelta<0?n.WindCnt:n.WindCnt+t.WindDelta:t.WindDelta===0?1:t.WindDelta:t.WindDelta===0?n.WindCnt<0?n.WindCnt-1:n.WindCnt+1:n.WindDelta*t.WindDelta<0?n.WindCnt:n.WindCnt+t.WindDelta,t.WindCnt2=n.WindCnt2,n=n.NextInAEL;if(this.IsEvenOddAltFillType(t))for(;n!==t;)n.WindDelta!==0&&(t.WindCnt2=+(t.WindCnt2===0)),n=n.NextInAEL;else for(;n!==t;)t.WindCnt2+=n.WindDelta,n=n.NextInAEL},e.Clipper.prototype.AddEdgeToSEL=function(e){this.m_SortedEdges===null?(this.m_SortedEdges=e,e.PrevInSEL=null,e.NextInSEL=null):(e.NextInSEL=this.m_SortedEdges,e.PrevInSEL=null,this.m_SortedEdges.PrevInSEL=e,this.m_SortedEdges=e)},e.Clipper.prototype.PopEdgeFromSEL=function(e){if(e.v=this.m_SortedEdges,e.v===null)return!1;var t=e.v;return this.m_SortedEdges=e.v.NextInSEL,this.m_SortedEdges!==null&&(this.m_SortedEdges.PrevInSEL=null),t.NextInSEL=null,t.PrevInSEL=null,!0},e.Clipper.prototype.CopyAELToSEL=function(){var e=this.m_ActiveEdges;for(this.m_SortedEdges=e;e!==null;)e.PrevInSEL=e.PrevInAEL,e.NextInSEL=e.NextInAEL,e=e.NextInAEL},e.Clipper.prototype.SwapPositionsInSEL=function(e,t){if((e.NextInSEL!==null||e.PrevInSEL!==null)&&(t.NextInSEL!==null||t.PrevInSEL!==null)){if(e.NextInSEL===t){var n=t.NextInSEL;n!==null&&(n.PrevInSEL=e);var r=e.PrevInSEL;r!==null&&(r.NextInSEL=t),t.PrevInSEL=r,t.NextInSEL=e,e.PrevInSEL=t,e.NextInSEL=n}else if(t.NextInSEL===e){var n=e.NextInSEL;n!==null&&(n.PrevInSEL=t);var r=t.PrevInSEL;r!==null&&(r.NextInSEL=e),e.PrevInSEL=r,e.NextInSEL=t,t.PrevInSEL=e,t.NextInSEL=n}else{var n=e.NextInSEL,r=e.PrevInSEL;e.NextInSEL=t.NextInSEL,e.NextInSEL!==null&&(e.NextInSEL.PrevInSEL=e),e.PrevInSEL=t.PrevInSEL,e.PrevInSEL!==null&&(e.PrevInSEL.NextInSEL=e),t.NextInSEL=n,t.NextInSEL!==null&&(t.NextInSEL.PrevInSEL=t),t.PrevInSEL=r,t.PrevInSEL!==null&&(t.PrevInSEL.NextInSEL=t)}e.PrevInSEL===null?this.m_SortedEdges=e:t.PrevInSEL===null&&(this.m_SortedEdges=t)}},e.Clipper.prototype.AddLocalMaxPoly=function(e,t,n){this.AddOutPt(e,n),t.WindDelta===0&&this.AddOutPt(t,n),e.OutIdx===t.OutIdx?(e.OutIdx=-1,t.OutIdx=-1):e.OutIdx<t.OutIdx?this.AppendPolygon(e,t):this.AppendPolygon(t,e)},e.Clipper.prototype.AddLocalMinPoly=function(t,n,r){var i,a,o;if(e.ClipperBase.IsHorizontal(n)||t.Dx>n.Dx?(i=this.AddOutPt(t,r),n.OutIdx=t.OutIdx,t.Side=e.EdgeSide.esLeft,n.Side=e.EdgeSide.esRight,a=t,o=a.PrevInAEL===n?n.PrevInAEL:a.PrevInAEL):(i=this.AddOutPt(n,r),t.OutIdx=n.OutIdx,t.Side=e.EdgeSide.esRight,n.Side=e.EdgeSide.esLeft,a=n,o=a.PrevInAEL===t?t.PrevInAEL:a.PrevInAEL),o!==null&&o.OutIdx>=0&&o.Top.Y<r.Y&&a.Top.Y<r.Y){var s=e.Clipper.TopX(o,r.Y),c=e.Clipper.TopX(a,r.Y);if(s===c&&a.WindDelta!==0&&o.WindDelta!==0&&e.ClipperBase.SlopesEqual5(new e.IntPoint2(s,r.Y),o.Top,new e.IntPoint2(c,r.Y),a.Top,this.m_UseFullRange)){var l=this.AddOutPt(o,r);this.AddJoin(i,l,a.Top)}}return i},e.Clipper.prototype.AddOutPt=function(t,n){if(t.OutIdx<0){var r=this.CreateOutRec();r.IsOpen=t.WindDelta===0;var i=new e.OutPt;return r.Pts=i,i.Idx=r.Idx,i.Pt.X=n.X,i.Pt.Y=n.Y,e.use_xyz&&(i.Pt.Z=n.Z),i.Next=i,i.Prev=i,r.IsOpen||this.SetHoleState(t,r),t.OutIdx=r.Idx,i}var r=this.m_PolyOuts[t.OutIdx],a=r.Pts,o=t.Side===e.EdgeSide.esLeft;if(o&&e.IntPoint.op_Equality(n,a.Pt))return a;if(!o&&e.IntPoint.op_Equality(n,a.Prev.Pt))return a.Prev;var i=new e.OutPt;return i.Idx=r.Idx,i.Pt.X=n.X,i.Pt.Y=n.Y,e.use_xyz&&(i.Pt.Z=n.Z),i.Next=a,i.Prev=a.Prev,i.Prev.Next=i,a.Prev=i,o&&(r.Pts=i),i},e.Clipper.prototype.GetLastOutPt=function(t){var n=this.m_PolyOuts[t.OutIdx];return t.Side===e.EdgeSide.esLeft?n.Pts:n.Pts.Prev},e.Clipper.prototype.SwapPoints=function(t,n){var r=new e.IntPoint1(t.Value);t.Value.X=n.Value.X,t.Value.Y=n.Value.Y,e.use_xyz&&(t.Value.Z=n.Value.Z),n.Value.X=r.X,n.Value.Y=r.Y,e.use_xyz&&(n.Value.Z=r.Z)},e.Clipper.prototype.HorzSegmentsOverlap=function(e,t,n,r){var i;return e>t&&(i=e,e=t,t=i),n>r&&(i=n,n=r,r=i),e<r&&n<t},e.Clipper.prototype.SetHoleState=function(e,t){for(var n=e.PrevInAEL,r=null;n!==null;)n.OutIdx>=0&&n.WindDelta!==0&&(r===null?r=n:r.OutIdx===n.OutIdx&&(r=null)),n=n.PrevInAEL;r===null?(t.FirstLeft=null,t.IsHole=!1):(t.FirstLeft=this.m_PolyOuts[r.OutIdx],t.IsHole=!t.FirstLeft.IsHole)},e.Clipper.prototype.GetDx=function(t,n){return t.Y===n.Y?e.ClipperBase.horizontal:(n.X-t.X)/(n.Y-t.Y)},e.Clipper.prototype.FirstIsBottomPt=function(t,n){for(var r=t.Prev;e.IntPoint.op_Equality(r.Pt,t.Pt)&&r!==t;)r=r.Prev;var i=Math.abs(this.GetDx(t.Pt,r.Pt));for(r=t.Next;e.IntPoint.op_Equality(r.Pt,t.Pt)&&r!==t;)r=r.Next;var a=Math.abs(this.GetDx(t.Pt,r.Pt));for(r=n.Prev;e.IntPoint.op_Equality(r.Pt,n.Pt)&&r!==n;)r=r.Prev;var o=Math.abs(this.GetDx(n.Pt,r.Pt));for(r=n.Next;e.IntPoint.op_Equality(r.Pt,n.Pt)&&r!==n;)r=r.Next;var s=Math.abs(this.GetDx(n.Pt,r.Pt));return Math.max(i,a)===Math.max(o,s)&&Math.min(i,a)===Math.min(o,s)?this.Area(t)>0:i>=o&&i>=s||a>=o&&a>=s},e.Clipper.prototype.GetBottomPt=function(t){for(var n=null,r=t.Next;r!==t;)r.Pt.Y>t.Pt.Y?(t=r,n=null):r.Pt.Y===t.Pt.Y&&r.Pt.X<=t.Pt.X&&(r.Pt.X<t.Pt.X?(n=null,t=r):r.Next!==t&&r.Prev!==t&&(n=r)),r=r.Next;if(n!==null)for(;n!==r;)for(this.FirstIsBottomPt(r,n)||(t=n),n=n.Next;e.IntPoint.op_Inequality(n.Pt,t.Pt);)n=n.Next;return t},e.Clipper.prototype.GetLowermostRec=function(e,t){e.BottomPt===null&&(e.BottomPt=this.GetBottomPt(e.Pts)),t.BottomPt===null&&(t.BottomPt=this.GetBottomPt(t.Pts));var n=e.BottomPt,r=t.BottomPt;return n.Pt.Y>r.Pt.Y?e:n.Pt.Y<r.Pt.Y?t:n.Pt.X<r.Pt.X?e:n.Pt.X>r.Pt.X||n.Next===n?t:r.Next===r||this.FirstIsBottomPt(n,r)?e:t},e.Clipper.prototype.OutRec1RightOfOutRec2=function(e,t){do if(e=e.FirstLeft,e===t)return!0;while(e!==null);return!1},e.Clipper.prototype.GetOutRec=function(e){for(var t=this.m_PolyOuts[e];t!==this.m_PolyOuts[t.Idx];)t=this.m_PolyOuts[t.Idx];return t},e.Clipper.prototype.AppendPolygon=function(t,n){var r=this.m_PolyOuts[t.OutIdx],i=this.m_PolyOuts[n.OutIdx],a=this.OutRec1RightOfOutRec2(r,i)?i:this.OutRec1RightOfOutRec2(i,r)?r:this.GetLowermostRec(r,i),o=r.Pts,s=o.Prev,c=i.Pts,l=c.Prev;t.Side===e.EdgeSide.esLeft?n.Side===e.EdgeSide.esLeft?(this.ReversePolyPtLinks(c),c.Next=o,o.Prev=c,s.Next=l,l.Prev=s,r.Pts=l):(l.Next=o,o.Prev=l,c.Prev=s,s.Next=c,r.Pts=c):n.Side===e.EdgeSide.esRight?(this.ReversePolyPtLinks(c),s.Next=l,l.Prev=s,c.Next=o,o.Prev=c):(s.Next=c,c.Prev=s,o.Prev=l,l.Next=o),r.BottomPt=null,a===i&&(i.FirstLeft!==r&&(r.FirstLeft=i.FirstLeft),r.IsHole=i.IsHole),i.Pts=null,i.BottomPt=null,i.FirstLeft=r;var u=t.OutIdx,d=n.OutIdx;t.OutIdx=-1,n.OutIdx=-1;for(var f=this.m_ActiveEdges;f!==null;){if(f.OutIdx===d){f.OutIdx=u,f.Side=t.Side;break}f=f.NextInAEL}i.Idx=r.Idx},e.Clipper.prototype.ReversePolyPtLinks=function(e){if(e!==null){var t=e,n;do n=t.Next,t.Next=t.Prev,t.Prev=n,t=n;while(t!==e)}},e.Clipper.SwapSides=function(e,t){var n=e.Side;e.Side=t.Side,t.Side=n},e.Clipper.SwapPolyIndexes=function(e,t){var n=e.OutIdx;e.OutIdx=t.OutIdx,t.OutIdx=n},e.Clipper.prototype.IntersectEdges=function(t,n,r){var i=t.OutIdx>=0,a=n.OutIdx>=0;if(e.use_xyz&&this.SetZ(r,t,n),e.use_lines&&(t.WindDelta===0||n.WindDelta===0)){if(t.WindDelta===0&&n.WindDelta===0)return;t.PolyTyp===n.PolyTyp&&t.WindDelta!==n.WindDelta&&this.m_ClipType===e.ClipType.ctUnion?t.WindDelta===0?a&&(this.AddOutPt(t,r),i&&(t.OutIdx=-1)):i&&(this.AddOutPt(n,r),a&&(n.OutIdx=-1)):t.PolyTyp!==n.PolyTyp&&(t.WindDelta===0&&Math.abs(n.WindCnt)===1&&(this.m_ClipType!==e.ClipType.ctUnion||n.WindCnt2===0)?(this.AddOutPt(t,r),i&&(t.OutIdx=-1)):n.WindDelta===0&&Math.abs(t.WindCnt)===1&&(this.m_ClipType!==e.ClipType.ctUnion||t.WindCnt2===0)&&(this.AddOutPt(n,r),a&&(n.OutIdx=-1)))}else{if(t.PolyTyp===n.PolyTyp){if(this.IsEvenOddFillType(t)){var o=t.WindCnt;t.WindCnt=n.WindCnt,n.WindCnt=o}else t.WindCnt+n.WindDelta===0?t.WindCnt=-t.WindCnt:t.WindCnt+=n.WindDelta,n.WindCnt-t.WindDelta===0?n.WindCnt=-n.WindCnt:n.WindCnt-=t.WindDelta}else this.IsEvenOddFillType(n)?t.WindCnt2=+(t.WindCnt2===0):t.WindCnt2+=n.WindDelta,this.IsEvenOddFillType(t)?n.WindCnt2=+(n.WindCnt2===0):n.WindCnt2-=t.WindDelta;var s,c,l,u;t.PolyTyp===e.PolyType.ptSubject?(s=this.m_SubjFillType,l=this.m_ClipFillType):(s=this.m_ClipFillType,l=this.m_SubjFillType),n.PolyTyp===e.PolyType.ptSubject?(c=this.m_SubjFillType,u=this.m_ClipFillType):(c=this.m_ClipFillType,u=this.m_SubjFillType);var d,f;switch(s){case e.PolyFillType.pftPositive:d=t.WindCnt;break;case e.PolyFillType.pftNegative:d=-t.WindCnt;break;default:d=Math.abs(t.WindCnt)}switch(c){case e.PolyFillType.pftPositive:f=n.WindCnt;break;case e.PolyFillType.pftNegative:f=-n.WindCnt;break;default:f=Math.abs(n.WindCnt)}if(i&&a)d!==0&&d!==1||f!==0&&f!==1||t.PolyTyp!==n.PolyTyp&&this.m_ClipType!==e.ClipType.ctXor?this.AddLocalMaxPoly(t,n,r):(this.AddOutPt(t,r),this.AddOutPt(n,r),e.Clipper.SwapSides(t,n),e.Clipper.SwapPolyIndexes(t,n));else if(i)(f===0||f===1)&&(this.AddOutPt(t,r),e.Clipper.SwapSides(t,n),e.Clipper.SwapPolyIndexes(t,n));else if(a)(d===0||d===1)&&(this.AddOutPt(n,r),e.Clipper.SwapSides(t,n),e.Clipper.SwapPolyIndexes(t,n));else if((d===0||d===1)&&(f===0||f===1)){var p,m;switch(l){case e.PolyFillType.pftPositive:p=t.WindCnt2;break;case e.PolyFillType.pftNegative:p=-t.WindCnt2;break;default:p=Math.abs(t.WindCnt2)}switch(u){case e.PolyFillType.pftPositive:m=n.WindCnt2;break;case e.PolyFillType.pftNegative:m=-n.WindCnt2;break;default:m=Math.abs(n.WindCnt2)}if(t.PolyTyp!==n.PolyTyp)this.AddLocalMinPoly(t,n,r);else if(d===1&&f===1)switch(this.m_ClipType){case e.ClipType.ctIntersection:p>0&&m>0&&this.AddLocalMinPoly(t,n,r);break;case e.ClipType.ctUnion:p<=0&&m<=0&&this.AddLocalMinPoly(t,n,r);break;case e.ClipType.ctDifference:(t.PolyTyp===e.PolyType.ptClip&&p>0&&m>0||t.PolyTyp===e.PolyType.ptSubject&&p<=0&&m<=0)&&this.AddLocalMinPoly(t,n,r);break;case e.ClipType.ctXor:this.AddLocalMinPoly(t,n,r)}else e.Clipper.SwapSides(t,n)}}},e.Clipper.prototype.DeleteFromSEL=function(e){var t=e.PrevInSEL,n=e.NextInSEL;(t!==null||n!==null||e===this.m_SortedEdges)&&(t===null?this.m_SortedEdges=n:t.NextInSEL=n,n!==null&&(n.PrevInSEL=t),e.NextInSEL=null,e.PrevInSEL=null)},e.Clipper.prototype.ProcessHorizontals=function(){for(var e={};this.PopEdgeFromSEL(e);)this.ProcessHorizontal(e.v)},e.Clipper.prototype.GetHorzDirection=function(t,n){t.Bot.X<t.Top.X?(n.Left=t.Bot.X,n.Right=t.Top.X,n.Dir=e.Direction.dLeftToRight):(n.Left=t.Top.X,n.Right=t.Bot.X,n.Dir=e.Direction.dRightToLeft)},e.Clipper.prototype.ProcessHorizontal=function(t){var n={Dir:null,Left:null,Right:null};this.GetHorzDirection(t,n);for(var r=n.Dir,i=n.Left,a=n.Right,o=t.WindDelta===0,s=t,c=null;s.NextInLML!==null&&e.ClipperBase.IsHorizontal(s.NextInLML);)s=s.NextInLML;s.NextInLML===null&&(c=this.GetMaximaPair(s));var l=this.m_Maxima;if(l!==null){if(r===e.Direction.dLeftToRight){for(;l!==null&&l.X<=t.Bot.X;)l=l.Next;l!==null&&l.X>=s.Top.X&&(l=null)}else{for(;l.Next!==null&&l.Next.X<t.Bot.X;)l=l.Next;l.X<=s.Top.X&&(l=null)}}for(var u=null;;){for(var d=t===s,f=this.GetNextInAEL(t,r);f!==null;){if(l!==null){if(r===e.Direction.dLeftToRight)for(;l!==null&&l.X<f.Curr.X;)t.OutIdx>=0&&!o&&this.AddOutPt(t,new e.IntPoint2(l.X,t.Bot.Y)),l=l.Next;else for(;l!==null&&l.X>f.Curr.X;)t.OutIdx>=0&&!o&&this.AddOutPt(t,new e.IntPoint2(l.X,t.Bot.Y)),l=l.Prev}if(r===e.Direction.dLeftToRight&&f.Curr.X>a||r===e.Direction.dRightToLeft&&f.Curr.X<i||f.Curr.X===t.Top.X&&t.NextInLML!==null&&f.Dx<t.NextInLML.Dx)break;if(t.OutIdx>=0&&!o){e.use_xyz&&(r===e.Direction.dLeftToRight?this.SetZ(f.Curr,t,f):this.SetZ(f.Curr,f,t)),u=this.AddOutPt(t,f.Curr);for(var p=this.m_SortedEdges;p!==null;){if(p.OutIdx>=0&&this.HorzSegmentsOverlap(t.Bot.X,t.Top.X,p.Bot.X,p.Top.X)){var m=this.GetLastOutPt(p);this.AddJoin(m,u,p.Top)}p=p.NextInSEL}this.AddGhostJoin(u,t.Bot)}if(f===c&&d){t.OutIdx>=0&&this.AddLocalMaxPoly(t,c,t.Top),this.DeleteFromAEL(t),this.DeleteFromAEL(c);return}if(r===e.Direction.dLeftToRight){var h=new e.IntPoint2(f.Curr.X,t.Curr.Y);this.IntersectEdges(t,f,h)}else{var h=new e.IntPoint2(f.Curr.X,t.Curr.Y);this.IntersectEdges(f,t,h)}var g=this.GetNextInAEL(f,r);this.SwapPositionsInAEL(t,f),f=g}if(t.NextInLML===null||!e.ClipperBase.IsHorizontal(t.NextInLML))break;t=this.UpdateEdgeIntoAEL(t),t.OutIdx>=0&&this.AddOutPt(t,t.Bot),n={Dir:r,Left:i,Right:a},this.GetHorzDirection(t,n),r=n.Dir,i=n.Left,a=n.Right}if(t.OutIdx>=0&&u===null){u=this.GetLastOutPt(t);for(var p=this.m_SortedEdges;p!==null;){if(p.OutIdx>=0&&this.HorzSegmentsOverlap(t.Bot.X,t.Top.X,p.Bot.X,p.Top.X)){var m=this.GetLastOutPt(p);this.AddJoin(m,u,p.Top)}p=p.NextInSEL}this.AddGhostJoin(u,t.Top)}if(t.NextInLML!==null){if(t.OutIdx>=0){if(u=this.AddOutPt(t,t.Top),t=this.UpdateEdgeIntoAEL(t),t.WindDelta===0)return;var _=t.PrevInAEL,g=t.NextInAEL;if(_!==null&&_.Curr.X===t.Bot.X&&_.Curr.Y===t.Bot.Y&&_.WindDelta===0&&_.OutIdx>=0&&_.Curr.Y>_.Top.Y&&e.ClipperBase.SlopesEqual3(t,_,this.m_UseFullRange)){var m=this.AddOutPt(_,t.Bot);this.AddJoin(u,m,t.Top)}else if(g!==null&&g.Curr.X===t.Bot.X&&g.Curr.Y===t.Bot.Y&&g.WindDelta!==0&&g.OutIdx>=0&&g.Curr.Y>g.Top.Y&&e.ClipperBase.SlopesEqual3(t,g,this.m_UseFullRange)){var m=this.AddOutPt(g,t.Bot);this.AddJoin(u,m,t.Top)}}else t=this.UpdateEdgeIntoAEL(t)}else t.OutIdx>=0&&this.AddOutPt(t,t.Top),this.DeleteFromAEL(t)},e.Clipper.prototype.GetNextInAEL=function(t,n){return n===e.Direction.dLeftToRight?t.NextInAEL:t.PrevInAEL},e.Clipper.prototype.IsMinima=function(e){return e!==null&&e.Prev.NextInLML!==e&&e.Next.NextInLML!==e},e.Clipper.prototype.IsMaxima=function(e,t){return e!==null&&e.Top.Y===t&&e.NextInLML===null},e.Clipper.prototype.IsIntermediate=function(e,t){return e.Top.Y===t&&e.NextInLML!==null},e.Clipper.prototype.GetMaximaPair=function(t){return e.IntPoint.op_Equality(t.Next.Top,t.Top)&&t.Next.NextInLML===null?t.Next:e.IntPoint.op_Equality(t.Prev.Top,t.Top)&&t.Prev.NextInLML===null?t.Prev:null},e.Clipper.prototype.GetMaximaPairEx=function(t){var n=this.GetMaximaPair(t);return n===null||n.OutIdx===e.ClipperBase.Skip||n.NextInAEL===n.PrevInAEL&&!e.ClipperBase.IsHorizontal(n)?null:n},e.Clipper.prototype.ProcessIntersections=function(t){if(this.m_ActiveEdges===null)return!0;try{if(this.BuildIntersectList(t),this.m_IntersectList.length===0)return!0;if(this.m_IntersectList.length===1||this.FixupIntersectionOrder())this.ProcessIntersectList();else return!1}catch{this.m_SortedEdges=null,this.m_IntersectList.length=0,e.Error(`ProcessIntersections error`)}return this.m_SortedEdges=null,!0},e.Clipper.prototype.BuildIntersectList=function(t){if(this.m_ActiveEdges!==null){var n=this.m_ActiveEdges;for(this.m_SortedEdges=n;n!==null;)n.PrevInSEL=n.PrevInAEL,n.NextInSEL=n.NextInAEL,n.Curr.X=e.Clipper.TopX(n,t),n=n.NextInAEL;for(var r=!0;r&&this.m_SortedEdges!==null;){for(r=!1,n=this.m_SortedEdges;n.NextInSEL!==null;){var i=n.NextInSEL,a=new e.IntPoint0;if(n.Curr.X>i.Curr.X){this.IntersectPoint(n,i,a),a.Y<t&&(a=new e.IntPoint2(e.Clipper.TopX(n,t),t));var o=new e.IntersectNode;o.Edge1=n,o.Edge2=i,o.Pt.X=a.X,o.Pt.Y=a.Y,e.use_xyz&&(o.Pt.Z=a.Z),this.m_IntersectList.push(o),this.SwapPositionsInSEL(n,i),r=!0}else n=i}if(n.PrevInSEL!==null)n.PrevInSEL.NextInSEL=null;else break}this.m_SortedEdges=null}},e.Clipper.prototype.EdgesAdjacent=function(e){return e.Edge1.NextInSEL===e.Edge2||e.Edge1.PrevInSEL===e.Edge2},e.Clipper.IntersectNodeSort=function(e,t){return t.Pt.Y-e.Pt.Y},e.Clipper.prototype.FixupIntersectionOrder=function(){this.m_IntersectList.sort(this.m_IntersectNodeComparer),this.CopyAELToSEL();for(var e=this.m_IntersectList.length,t=0;t<e;t++){if(!this.EdgesAdjacent(this.m_IntersectList[t])){for(var n=t+1;n<e&&!this.EdgesAdjacent(this.m_IntersectList[n]);)n++;if(n===e)return!1;var r=this.m_IntersectList[t];this.m_IntersectList[t]=this.m_IntersectList[n],this.m_IntersectList[n]=r}this.SwapPositionsInSEL(this.m_IntersectList[t].Edge1,this.m_IntersectList[t].Edge2)}return!0},e.Clipper.prototype.ProcessIntersectList=function(){for(var e=0,t=this.m_IntersectList.length;e<t;e++){var n=this.m_IntersectList[e];this.IntersectEdges(n.Edge1,n.Edge2,n.Pt),this.SwapPositionsInAEL(n.Edge1,n.Edge2)}this.m_IntersectList.length=0};var gt=function(e){return e<0?Math.ceil(e-.5):Math.round(e)},_t=function(e){return e<0?Math.ceil(e-.5):Math.floor(e+.5)},vt=function(e){return e<0?-Math.round(Math.abs(e)):Math.round(e)},yt=function(e){return e<0?(e-=.5,e<-2147483648?Math.ceil(e):e|0):(e+=.5,e>2147483647?Math.floor(e):e|0)};a.msie?e.Clipper.Round=gt:a.chromium?e.Clipper.Round=vt:a.safari?e.Clipper.Round=yt:e.Clipper.Round=_t,e.Clipper.TopX=function(t,n){return n===t.Top.Y?t.Top.X:t.Bot.X+e.Clipper.Round(t.Dx*(n-t.Bot.Y))},e.Clipper.prototype.IntersectPoint=function(t,n,r){r.X=0,r.Y=0;var i,a;if(t.Dx===n.Dx)r.Y=t.Curr.Y,r.X=e.Clipper.TopX(t,r.Y);else{if(t.Delta.X===0)r.X=t.Bot.X,e.ClipperBase.IsHorizontal(n)?r.Y=n.Bot.Y:(a=n.Bot.Y-n.Bot.X/n.Dx,r.Y=e.Clipper.Round(r.X/n.Dx+a));else if(n.Delta.X===0)r.X=n.Bot.X,e.ClipperBase.IsHorizontal(t)?r.Y=t.Bot.Y:(i=t.Bot.Y-t.Bot.X/t.Dx,r.Y=e.Clipper.Round(r.X/t.Dx+i));else{i=t.Bot.X-t.Bot.Y*t.Dx,a=n.Bot.X-n.Bot.Y*n.Dx;var o=(a-i)/(t.Dx-n.Dx);r.Y=e.Clipper.Round(o),r.X=Math.abs(t.Dx)<Math.abs(n.Dx)?e.Clipper.Round(t.Dx*o+i):e.Clipper.Round(n.Dx*o+a)}if(r.Y<t.Top.Y||r.Y<n.Top.Y){if(t.Top.Y>n.Top.Y)return r.Y=t.Top.Y,r.X=e.Clipper.TopX(n,t.Top.Y),r.X<t.Top.X;r.Y=n.Top.Y,r.X=Math.abs(t.Dx)<Math.abs(n.Dx)?e.Clipper.TopX(t,r.Y):e.Clipper.TopX(n,r.Y)}r.Y>t.Curr.Y&&(r.Y=t.Curr.Y,r.X=Math.abs(t.Dx)>Math.abs(n.Dx)?e.Clipper.TopX(n,r.Y):e.Clipper.TopX(t,r.Y))}},e.Clipper.prototype.ProcessEdgesAtTopOfScanbeam=function(t){for(var n=this.m_ActiveEdges;n!==null;){var r=this.IsMaxima(n,t);if(r){var i=this.GetMaximaPairEx(n);r=i===null||!e.ClipperBase.IsHorizontal(i)}if(r){this.StrictlySimple&&this.InsertMaxima(n.Top.X);var a=n.PrevInAEL;this.DoMaxima(n),n=a===null?this.m_ActiveEdges:a.NextInAEL}else{if(this.IsIntermediate(n,t)&&e.ClipperBase.IsHorizontal(n.NextInLML)?(n=this.UpdateEdgeIntoAEL(n),n.OutIdx>=0&&this.AddOutPt(n,n.Bot),this.AddEdgeToSEL(n)):(n.Curr.X=e.Clipper.TopX(n,t),n.Curr.Y=t),e.use_xyz&&(n.Top.Y===t?n.Curr.Z=n.Top.Z:n.Bot.Y===t?n.Curr.Z=n.Bot.Z:n.Curr.Z=0),this.StrictlySimple){var a=n.PrevInAEL;if(n.OutIdx>=0&&n.WindDelta!==0&&a!==null&&a.OutIdx>=0&&a.Curr.X===n.Curr.X&&a.WindDelta!==0){var o=new e.IntPoint1(n.Curr);e.use_xyz&&this.SetZ(o,a,n);var s=this.AddOutPt(a,o),c=this.AddOutPt(n,o);this.AddJoin(s,c,o)}}n=n.NextInAEL}}for(this.ProcessHorizontals(),this.m_Maxima=null,n=this.m_ActiveEdges;n!==null;){if(this.IsIntermediate(n,t)){var s=null;n.OutIdx>=0&&(s=this.AddOutPt(n,n.Top)),n=this.UpdateEdgeIntoAEL(n);var a=n.PrevInAEL,l=n.NextInAEL;if(a!==null&&a.Curr.X===n.Bot.X&&a.Curr.Y===n.Bot.Y&&s!==null&&a.OutIdx>=0&&a.Curr.Y===a.Top.Y&&e.ClipperBase.SlopesEqual5(n.Curr,n.Top,a.Curr,a.Top,this.m_UseFullRange)&&n.WindDelta!==0&&a.WindDelta!==0){var c=this.AddOutPt(ePrev2,n.Bot);this.AddJoin(s,c,n.Top)}else if(l!==null&&l.Curr.X===n.Bot.X&&l.Curr.Y===n.Bot.Y&&s!==null&&l.OutIdx>=0&&l.Curr.Y===l.Top.Y&&e.ClipperBase.SlopesEqual5(n.Curr,n.Top,l.Curr,l.Top,this.m_UseFullRange)&&n.WindDelta!==0&&l.WindDelta!==0){var c=this.AddOutPt(l,n.Bot);this.AddJoin(s,c,n.Top)}}n=n.NextInAEL}},e.Clipper.prototype.DoMaxima=function(t){var n=this.GetMaximaPairEx(t);if(n===null)t.OutIdx>=0&&this.AddOutPt(t,t.Top),this.DeleteFromAEL(t);else{for(var r=t.NextInAEL;r!==null&&r!==n;)this.IntersectEdges(t,r,t.Top),this.SwapPositionsInAEL(t,r),r=t.NextInAEL;t.OutIdx===-1&&n.OutIdx===-1?(this.DeleteFromAEL(t),this.DeleteFromAEL(n)):t.OutIdx>=0&&n.OutIdx>=0?(t.OutIdx>=0&&this.AddLocalMaxPoly(t,n,t.Top),this.DeleteFromAEL(t),this.DeleteFromAEL(n)):e.use_lines&&t.WindDelta===0?(t.OutIdx>=0&&(this.AddOutPt(t,t.Top),t.OutIdx=e.ClipperBase.Unassigned),this.DeleteFromAEL(t),n.OutIdx>=0&&(this.AddOutPt(n,t.Top),n.OutIdx=e.ClipperBase.Unassigned),this.DeleteFromAEL(n)):e.Error(`DoMaxima error`)}},e.Clipper.ReversePaths=function(e){for(var t=0,n=e.length;t<n;t++)e[t].reverse()},e.Clipper.Orientation=function(t){return e.Clipper.Area(t)>=0},e.Clipper.prototype.PointCount=function(e){if(e===null)return 0;var t=0,n=e;do t++,n=n.Next;while(n!==e);return t},e.Clipper.prototype.BuildResult=function(t){e.Clear(t);for(var n=0,r=this.m_PolyOuts.length;n<r;n++){var i=this.m_PolyOuts[n];if(i.Pts!==null){var a=i.Pts.Prev,o=this.PointCount(a);if(!(o<2)){for(var s=Array(o),c=0;c<o;c++)s[c]=a.Pt,a=a.Prev;t.push(s)}}}},e.Clipper.prototype.BuildResult2=function(t){t.Clear();for(var n=0,r=this.m_PolyOuts.length;n<r;n++){var i=this.m_PolyOuts[n],a=this.PointCount(i.Pts);if(!(i.IsOpen&&a<2||!i.IsOpen&&a<3)){this.FixHoleLinkage(i);var o=new e.PolyNode;t.m_AllPolys.push(o),i.PolyNode=o,o.m_polygon.length=a;for(var s=i.Pts.Prev,c=0;c<a;c++)o.m_polygon[c]=s.Pt,s=s.Prev}}for(var n=0,r=this.m_PolyOuts.length;n<r;n++){var i=this.m_PolyOuts[n];i.PolyNode!==null&&(i.IsOpen?(i.PolyNode.IsOpen=!0,t.AddChild(i.PolyNode)):i.FirstLeft!==null&&i.FirstLeft.PolyNode!==null?i.FirstLeft.PolyNode.AddChild(i.PolyNode):t.AddChild(i.PolyNode))}},e.Clipper.prototype.FixupOutPolyline=function(t){for(var n=t.Pts,r=n.Prev;n!==r;)if(n=n.Next,e.IntPoint.op_Equality(n.Pt,n.Prev.Pt)){n===r&&(r=n.Prev);var i=n.Prev;i.Next=n.Next,n.Next.Prev=i,n=i}n===n.Prev&&(t.Pts=null)},e.Clipper.prototype.FixupOutPolygon=function(t){var n=null;t.BottomPt=null;for(var r=t.Pts,i=this.PreserveCollinear||this.StrictlySimple;;){if(r.Prev===r||r.Prev===r.Next){t.Pts=null;return}if(e.IntPoint.op_Equality(r.Pt,r.Next.Pt)||e.IntPoint.op_Equality(r.Pt,r.Prev.Pt)||e.ClipperBase.SlopesEqual4(r.Prev.Pt,r.Pt,r.Next.Pt,this.m_UseFullRange)&&(!i||!this.Pt2IsBetweenPt1AndPt3(r.Prev.Pt,r.Pt,r.Next.Pt)))n=null,r.Prev.Next=r.Next,r.Next.Prev=r.Prev,r=r.Prev;else if(r===n)break;else n===null&&(n=r),r=r.Next}t.Pts=r},e.Clipper.prototype.DupOutPt=function(t,n){var r=new e.OutPt;return r.Pt.X=t.Pt.X,r.Pt.Y=t.Pt.Y,e.use_xyz&&(r.Pt.Z=t.Pt.Z),r.Idx=t.Idx,n?(r.Next=t.Next,r.Prev=t,t.Next.Prev=r,t.Next=r):(r.Prev=t.Prev,r.Next=t,t.Prev.Next=r,t.Prev=r),r},e.Clipper.prototype.GetOverlap=function(e,t,n,r,i){return e<t?n<r?(i.Left=Math.max(e,n),i.Right=Math.min(t,r)):(i.Left=Math.max(e,r),i.Right=Math.min(t,n)):n<r?(i.Left=Math.max(t,n),i.Right=Math.min(e,r)):(i.Left=Math.max(t,r),i.Right=Math.min(e,n)),i.Left<i.Right},e.Clipper.prototype.JoinHorz=function(t,n,r,i,a,o){var s=t.Pt.X>n.Pt.X?e.Direction.dRightToLeft:e.Direction.dLeftToRight,c=r.Pt.X>i.Pt.X?e.Direction.dRightToLeft:e.Direction.dLeftToRight;if(s===c)return!1;if(s===e.Direction.dLeftToRight){for(;t.Next.Pt.X<=a.X&&t.Next.Pt.X>=t.Pt.X&&t.Next.Pt.Y===a.Y;)t=t.Next;o&&t.Pt.X!==a.X&&(t=t.Next),n=this.DupOutPt(t,!o),e.IntPoint.op_Inequality(n.Pt,a)&&(t=n,t.Pt.X=a.X,t.Pt.Y=a.Y,e.use_xyz&&(t.Pt.Z=a.Z),n=this.DupOutPt(t,!o))}else{for(;t.Next.Pt.X>=a.X&&t.Next.Pt.X<=t.Pt.X&&t.Next.Pt.Y===a.Y;)t=t.Next;!o&&t.Pt.X!==a.X&&(t=t.Next),n=this.DupOutPt(t,o),e.IntPoint.op_Inequality(n.Pt,a)&&(t=n,t.Pt.X=a.X,t.Pt.Y=a.Y,e.use_xyz&&(t.Pt.Z=a.Z),n=this.DupOutPt(t,o))}if(c===e.Direction.dLeftToRight){for(;r.Next.Pt.X<=a.X&&r.Next.Pt.X>=r.Pt.X&&r.Next.Pt.Y===a.Y;)r=r.Next;o&&r.Pt.X!==a.X&&(r=r.Next),i=this.DupOutPt(r,!o),e.IntPoint.op_Inequality(i.Pt,a)&&(r=i,r.Pt.X=a.X,r.Pt.Y=a.Y,e.use_xyz&&(r.Pt.Z=a.Z),i=this.DupOutPt(r,!o))}else{for(;r.Next.Pt.X>=a.X&&r.Next.Pt.X<=r.Pt.X&&r.Next.Pt.Y===a.Y;)r=r.Next;!o&&r.Pt.X!==a.X&&(r=r.Next),i=this.DupOutPt(r,o),e.IntPoint.op_Inequality(i.Pt,a)&&(r=i,r.Pt.X=a.X,r.Pt.Y=a.Y,e.use_xyz&&(r.Pt.Z=a.Z),i=this.DupOutPt(r,o))}return s===e.Direction.dLeftToRight===o?(t.Prev=r,r.Next=t,n.Next=i,i.Prev=n):(t.Next=r,r.Prev=t,n.Prev=i,i.Next=n),!0},e.Clipper.prototype.JoinPoints=function(t,n,r){var i=t.OutPt1,a=new e.OutPt,o=t.OutPt2,s=new e.OutPt,c=t.OutPt1.Pt.Y===t.OffPt.Y;if(c&&e.IntPoint.op_Equality(t.OffPt,t.OutPt1.Pt)&&e.IntPoint.op_Equality(t.OffPt,t.OutPt2.Pt)){if(n!==r)return!1;for(a=t.OutPt1.Next;a!==i&&e.IntPoint.op_Equality(a.Pt,t.OffPt);)a=a.Next;var l=a.Pt.Y>t.OffPt.Y;for(s=t.OutPt2.Next;s!==o&&e.IntPoint.op_Equality(s.Pt,t.OffPt);)s=s.Next;return l===s.Pt.Y>t.OffPt.Y?!1:l?(a=this.DupOutPt(i,!1),s=this.DupOutPt(o,!0),i.Prev=o,o.Next=i,a.Next=s,s.Prev=a,t.OutPt1=i,t.OutPt2=a,!0):(a=this.DupOutPt(i,!0),s=this.DupOutPt(o,!1),i.Next=o,o.Prev=i,a.Prev=s,s.Next=a,t.OutPt1=i,t.OutPt2=a,!0)}if(c){for(a=i;i.Prev.Pt.Y===i.Pt.Y&&i.Prev!==a&&i.Prev!==o;)i=i.Prev;for(;a.Next.Pt.Y===a.Pt.Y&&a.Next!==i&&a.Next!==o;)a=a.Next;if(a.Next===i||a.Next===o)return!1;for(s=o;o.Prev.Pt.Y===o.Pt.Y&&o.Prev!==s&&o.Prev!==a;)o=o.Prev;for(;s.Next.Pt.Y===s.Pt.Y&&s.Next!==o&&s.Next!==i;)s=s.Next;if(s.Next===o||s.Next===i)return!1;var u={Left:null,Right:null};if(!this.GetOverlap(i.Pt.X,a.Pt.X,o.Pt.X,s.Pt.X,u))return!1;var d=u.Left,f=u.Right,p=new e.IntPoint0,m;return i.Pt.X>=d&&i.Pt.X<=f?(p.X=i.Pt.X,p.Y=i.Pt.Y,e.use_xyz&&(p.Z=i.Pt.Z),m=i.Pt.X>a.Pt.X):o.Pt.X>=d&&o.Pt.X<=f?(p.X=o.Pt.X,p.Y=o.Pt.Y,e.use_xyz&&(p.Z=o.Pt.Z),m=o.Pt.X>s.Pt.X):a.Pt.X>=d&&a.Pt.X<=f?(p.X=a.Pt.X,p.Y=a.Pt.Y,e.use_xyz&&(p.Z=a.Pt.Z),m=a.Pt.X>i.Pt.X):(p.X=s.Pt.X,p.Y=s.Pt.Y,e.use_xyz&&(p.Z=s.Pt.Z),m=s.Pt.X>o.Pt.X),t.OutPt1=i,t.OutPt2=o,this.JoinHorz(i,a,o,s,p,m)}for(a=i.Next;e.IntPoint.op_Equality(a.Pt,i.Pt)&&a!==i;)a=a.Next;var h=a.Pt.Y>i.Pt.Y||!e.ClipperBase.SlopesEqual4(i.Pt,a.Pt,t.OffPt,this.m_UseFullRange);if(h){for(a=i.Prev;e.IntPoint.op_Equality(a.Pt,i.Pt)&&a!==i;)a=a.Prev;if(a.Pt.Y>i.Pt.Y||!e.ClipperBase.SlopesEqual4(i.Pt,a.Pt,t.OffPt,this.m_UseFullRange))return!1}for(s=o.Next;e.IntPoint.op_Equality(s.Pt,o.Pt)&&s!==o;)s=s.Next;var g=s.Pt.Y>o.Pt.Y||!e.ClipperBase.SlopesEqual4(o.Pt,s.Pt,t.OffPt,this.m_UseFullRange);if(g){for(s=o.Prev;e.IntPoint.op_Equality(s.Pt,o.Pt)&&s!==o;)s=s.Prev;if(s.Pt.Y>o.Pt.Y||!e.ClipperBase.SlopesEqual4(o.Pt,s.Pt,t.OffPt,this.m_UseFullRange))return!1}return a===i||s===o||a===s||n===r&&h===g?!1:h?(a=this.DupOutPt(i,!1),s=this.DupOutPt(o,!0),i.Prev=o,o.Next=i,a.Next=s,s.Prev=a,t.OutPt1=i,t.OutPt2=a,!0):(a=this.DupOutPt(i,!0),s=this.DupOutPt(o,!1),i.Next=o,o.Prev=i,a.Prev=s,s.Next=a,t.OutPt1=i,t.OutPt2=a,!0)},e.Clipper.GetBounds=function(t){for(var n=0,r=t.length;n<r&&t[n].length===0;)n++;if(n===r)return new e.IntRect(0,0,0,0);var i=new e.IntRect;for(i.left=t[n][0].X,i.right=i.left,i.top=t[n][0].Y,i.bottom=i.top;n<r;n++)for(var a=0,o=t[n].length;a<o;a++)t[n][a].X<i.left?i.left=t[n][a].X:t[n][a].X>i.right&&(i.right=t[n][a].X),t[n][a].Y<i.top?i.top=t[n][a].Y:t[n][a].Y>i.bottom&&(i.bottom=t[n][a].Y);return i},e.Clipper.prototype.GetBounds2=function(t){var n=t,r=new e.IntRect;for(r.left=t.Pt.X,r.right=t.Pt.X,r.top=t.Pt.Y,r.bottom=t.Pt.Y,t=t.Next;t!==n;)t.Pt.X<r.left&&(r.left=t.Pt.X),t.Pt.X>r.right&&(r.right=t.Pt.X),t.Pt.Y<r.top&&(r.top=t.Pt.Y),t.Pt.Y>r.bottom&&(r.bottom=t.Pt.Y),t=t.Next;return r},e.Clipper.PointInPolygon=function(e,t){var n=0,r=t.length;if(r<3)return 0;for(var i=t[0],a=1;a<=r;++a){var o=a===r?t[0]:t[a];if(o.Y===e.Y&&(o.X===e.X||i.Y===e.Y&&o.X>e.X==i.X<e.X))return-1;if(i.Y<e.Y!=o.Y<e.Y){if(i.X>=e.X){if(o.X>e.X)n=1-n;else{var s=(i.X-e.X)*(o.Y-e.Y)-(o.X-e.X)*(i.Y-e.Y);if(s===0)return-1;s>0==o.Y>i.Y&&(n=1-n)}}else if(o.X>e.X){var s=(i.X-e.X)*(o.Y-e.Y)-(o.X-e.X)*(i.Y-e.Y);if(s===0)return-1;s>0==o.Y>i.Y&&(n=1-n)}}i=o}return n},e.Clipper.prototype.PointInPolygon=function(e,t){var n=0,r=t,i=e.X,a=e.Y,o=t.Pt.X,s=t.Pt.Y;do{t=t.Next;var c=t.Pt.X,l=t.Pt.Y;if(l===a&&(c===i||s===a&&c>i==o<i))return-1;if(s<a!=l<a){if(o>=i){if(c>i)n=1-n;else{var u=(o-i)*(l-a)-(c-i)*(s-a);if(u===0)return-1;u>0==l>s&&(n=1-n)}}else if(c>i){var u=(o-i)*(l-a)-(c-i)*(s-a);if(u===0)return-1;u>0==l>s&&(n=1-n)}}o=c,s=l}while(r!==t);return n},e.Clipper.prototype.Poly2ContainsPoly1=function(e,t){var n=e;do{var r=this.PointInPolygon(n.Pt,t);if(r>=0)return r>0;n=n.Next}while(n!==e);return!0},e.Clipper.prototype.FixupFirstLefts1=function(t,n){for(var r,i,a=0,o=this.m_PolyOuts.length;a<o;a++)r=this.m_PolyOuts[a],i=e.Clipper.ParseFirstLeft(r.FirstLeft),r.Pts!==null&&i===t&&this.Poly2ContainsPoly1(r.Pts,n.Pts)&&(r.FirstLeft=n)},e.Clipper.prototype.FixupFirstLefts2=function(t,n){for(var r=n.FirstLeft,i,a,o=0,s=this.m_PolyOuts.length;o<s;o++)i=this.m_PolyOuts[o],i.Pts!==null&&i!==n&&i!==t&&(a=e.Clipper.ParseFirstLeft(i.FirstLeft),(a===r||a===t||a===n)&&(this.Poly2ContainsPoly1(i.Pts,t.Pts)?i.FirstLeft=t:this.Poly2ContainsPoly1(i.Pts,n.Pts)?i.FirstLeft=n:(i.FirstLeft===t||i.FirstLeft===n)&&(i.FirstLeft=r)))},e.Clipper.prototype.FixupFirstLefts3=function(t,n){for(var r,i,a=0,o=this.m_PolyOuts.length;a<o;a++)r=this.m_PolyOuts[a],i=e.Clipper.ParseFirstLeft(r.FirstLeft),r.Pts!==null&&i===t&&(r.FirstLeft=n)},e.Clipper.ParseFirstLeft=function(e){for(;e!==null&&e.Pts===null;)e=e.FirstLeft;return e},e.Clipper.prototype.JoinCommonEdges=function(){for(var e=0,t=this.m_Joins.length;e<t;e++){var n=this.m_Joins[e],r=this.GetOutRec(n.OutPt1.Idx),i=this.GetOutRec(n.OutPt2.Idx);if(r.Pts!==null&&i.Pts!==null&&!(r.IsOpen||i.IsOpen)){var a=r===i?r:this.OutRec1RightOfOutRec2(r,i)?i:this.OutRec1RightOfOutRec2(i,r)?r:this.GetLowermostRec(r,i);this.JoinPoints(n,r,i)&&(r===i?(r.Pts=n.OutPt1,r.BottomPt=null,i=this.CreateOutRec(),i.Pts=n.OutPt2,this.UpdateOutPtIdxs(i),this.Poly2ContainsPoly1(i.Pts,r.Pts)?(i.IsHole=!r.IsHole,i.FirstLeft=r,this.m_UsingPolyTree&&this.FixupFirstLefts2(i,r),(i.IsHole^this.ReverseSolution)==this.Area$1(i)>0&&this.ReversePolyPtLinks(i.Pts)):this.Poly2ContainsPoly1(r.Pts,i.Pts)?(i.IsHole=r.IsHole,r.IsHole=!i.IsHole,i.FirstLeft=r.FirstLeft,r.FirstLeft=i,this.m_UsingPolyTree&&this.FixupFirstLefts2(r,i),(r.IsHole^this.ReverseSolution)==this.Area$1(r)>0&&this.ReversePolyPtLinks(r.Pts)):(i.IsHole=r.IsHole,i.FirstLeft=r.FirstLeft,this.m_UsingPolyTree&&this.FixupFirstLefts1(r,i))):(i.Pts=null,i.BottomPt=null,i.Idx=r.Idx,r.IsHole=a.IsHole,a===i&&(r.FirstLeft=i.FirstLeft),i.FirstLeft=r,this.m_UsingPolyTree&&this.FixupFirstLefts3(i,r)))}}},e.Clipper.prototype.UpdateOutPtIdxs=function(e){var t=e.Pts;do t.Idx=e.Idx,t=t.Prev;while(t!==e.Pts)},e.Clipper.prototype.DoSimplePolygons=function(){for(var t=0;t<this.m_PolyOuts.length;){var n=this.m_PolyOuts[t++],r=n.Pts;if(!(r===null||n.IsOpen))do{for(var i=r.Next;i!==n.Pts;){if(e.IntPoint.op_Equality(r.Pt,i.Pt)&&i.Next!==r&&i.Prev!==r){var a=r.Prev,o=i.Prev;r.Prev=o,o.Next=r,i.Prev=a,a.Next=i,n.Pts=r;var s=this.CreateOutRec();s.Pts=i,this.UpdateOutPtIdxs(s),this.Poly2ContainsPoly1(s.Pts,n.Pts)?(s.IsHole=!n.IsHole,s.FirstLeft=n,this.m_UsingPolyTree&&this.FixupFirstLefts2(s,n)):this.Poly2ContainsPoly1(n.Pts,s.Pts)?(s.IsHole=n.IsHole,n.IsHole=!s.IsHole,s.FirstLeft=n.FirstLeft,n.FirstLeft=s,this.m_UsingPolyTree&&this.FixupFirstLefts2(n,s)):(s.IsHole=n.IsHole,s.FirstLeft=n.FirstLeft,this.m_UsingPolyTree&&this.FixupFirstLefts1(n,s)),i=r}i=i.Next}r=r.Next}while(r!==n.Pts)}},e.Clipper.Area=function(e){if(!Array.isArray(e))return 0;var t=e.length;if(t<3)return 0;for(var n=0,r=0,i=t-1;r<t;++r)n+=(e[i].X+e[r].X)*(e[i].Y-e[r].Y),i=r;return-n*.5},e.Clipper.prototype.Area=function(e){var t=e;if(e===null)return 0;var n=0;do n+=(e.Prev.Pt.X+e.Pt.X)*(e.Prev.Pt.Y-e.Pt.Y),e=e.Next;while(e!==t);return n*.5},e.Clipper.prototype.Area$1=function(e){return this.Area(e.Pts)},e.Clipper.SimplifyPolygon=function(t,n){var r=[],i=new e.Clipper(0);return i.StrictlySimple=!0,i.AddPath(t,e.PolyType.ptSubject,!0),i.Execute(e.ClipType.ctUnion,r,n,n),r},e.Clipper.SimplifyPolygons=function(t,n){n===void 0&&(n=e.PolyFillType.pftEvenOdd);var r=[],i=new e.Clipper(0);return i.StrictlySimple=!0,i.AddPaths(t,e.PolyType.ptSubject,!0),i.Execute(e.ClipType.ctUnion,r,n,n),r},e.Clipper.DistanceSqrd=function(e,t){var n=e.X-t.X,r=e.Y-t.Y;return n*n+r*r},e.Clipper.DistanceFromLineSqrd=function(e,t,n){var r=t.Y-n.Y,i=n.X-t.X,a=r*t.X+i*t.Y;return a=r*e.X+i*e.Y-a,a*a/(r*r+i*i)},e.Clipper.SlopesNearCollinear=function(t,n,r,i){return Math.abs(t.X-n.X)>Math.abs(t.Y-n.Y)?t.X>n.X==t.X<r.X?e.Clipper.DistanceFromLineSqrd(t,n,r)<i:n.X>t.X==n.X<r.X?e.Clipper.DistanceFromLineSqrd(n,t,r)<i:e.Clipper.DistanceFromLineSqrd(r,t,n)<i:t.Y>n.Y==t.Y<r.Y?e.Clipper.DistanceFromLineSqrd(t,n,r)<i:n.Y>t.Y==n.Y<r.Y?e.Clipper.DistanceFromLineSqrd(n,t,r)<i:e.Clipper.DistanceFromLineSqrd(r,t,n)<i},e.Clipper.PointsAreClose=function(e,t,n){var r=e.X-t.X,i=e.Y-t.Y;return r*r+i*i<=n},e.Clipper.ExcludeOp=function(e){var t=e.Prev;return t.Next=e.Next,e.Next.Prev=t,t.Idx=0,t},e.Clipper.CleanPolygon=function(t,n){n===void 0&&(n=1.415);var r=t.length;if(r===0)return[];for(var i=Array(r),a=0;a<r;++a)i[a]=new e.OutPt;for(var a=0;a<r;++a)i[a].Pt=t[a],i[a].Next=i[(a+1)%r],i[a].Next.Prev=i[a],i[a].Idx=0;for(var o=n*n,s=i[0];s.Idx===0&&s.Next!==s.Prev;)e.Clipper.PointsAreClose(s.Pt,s.Prev.Pt,o)?(s=e.Clipper.ExcludeOp(s),r--):e.Clipper.PointsAreClose(s.Prev.Pt,s.Next.Pt,o)?(e.Clipper.ExcludeOp(s.Next),s=e.Clipper.ExcludeOp(s),r-=2):e.Clipper.SlopesNearCollinear(s.Prev.Pt,s.Pt,s.Next.Pt,o)?(s=e.Clipper.ExcludeOp(s),r--):(s.Idx=1,s=s.Next);r<3&&(r=0);for(var c=Array(r),a=0;a<r;++a)c[a]=new e.IntPoint1(s.Pt),s=s.Next;return i=null,c},e.Clipper.CleanPolygons=function(t,n){for(var r=Array(t.length),i=0,a=t.length;i<a;i++)r[i]=e.Clipper.CleanPolygon(t[i],n);return r},e.Clipper.Minkowski=function(t,n,r,i){var a=+!!i,o=t.length,s=n.length,c=[];if(r)for(var l=0;l<s;l++){for(var u=Array(o),d=0,f=t.length,p=t[d];d<f;d++,p=t[d])u[d]=new e.IntPoint2(n[l].X+p.X,n[l].Y+p.Y);c.push(u)}else for(var l=0;l<s;l++){for(var u=Array(o),d=0,f=t.length,p=t[d];d<f;d++,p=t[d])u[d]=new e.IntPoint2(n[l].X-p.X,n[l].Y-p.Y);c.push(u)}for(var m=[],l=0;l<s-1+a;l++)for(var d=0;d<o;d++){var h=[];h.push(c[l%s][d%o]),h.push(c[(l+1)%s][d%o]),h.push(c[(l+1)%s][(d+1)%o]),h.push(c[l%s][(d+1)%o]),e.Clipper.Orientation(h)||h.reverse(),m.push(h)}return m},e.Clipper.MinkowskiSum=function(t,n,r){if(n[0]instanceof Array){for(var i=n,a=new e.Paths,o=new e.Clipper,s=0;s<i.length;++s){var c=e.Clipper.Minkowski(t,i[s],!0,r);if(o.AddPaths(c,e.PolyType.ptSubject,!0),r){var l=e.Clipper.TranslatePath(i[s],t[0]);o.AddPath(l,e.PolyType.ptClip,!0)}}return o.Execute(e.ClipType.ctUnion,a,e.PolyFillType.pftNonZero,e.PolyFillType.pftNonZero),a}var l=n,i=e.Clipper.Minkowski(t,l,!0,r),o=new e.Clipper;return o.AddPaths(i,e.PolyType.ptSubject,!0),o.Execute(e.ClipType.ctUnion,i,e.PolyFillType.pftNonZero,e.PolyFillType.pftNonZero),i},e.Clipper.TranslatePath=function(t,n){for(var r=new e.Path,i=0;i<t.length;i++)r.push(new e.IntPoint2(t[i].X+n.X,t[i].Y+n.Y));return r},e.Clipper.MinkowskiDiff=function(t,n){var r=e.Clipper.Minkowski(t,n,!1,!0),i=new e.Clipper;return i.AddPaths(r,e.PolyType.ptSubject,!0),i.Execute(e.ClipType.ctUnion,r,e.PolyFillType.pftNonZero,e.PolyFillType.pftNonZero),r},e.Clipper.PolyTreeToPaths=function(t){var n=[];return e.Clipper.AddPolyNodeToPaths(t,e.Clipper.NodeType.ntAny,n),n},e.Clipper.AddPolyNodeToPaths=function(t,n,r){var i=!0;switch(n){case e.Clipper.NodeType.ntOpen:return;case e.Clipper.NodeType.ntClosed:i=!t.IsOpen}t.m_polygon.length>0&&i&&r.push(t.m_polygon);for(var a=0,o=t.Childs(),s=o.length,c=o[a];a<s;a++,c=o[a])e.Clipper.AddPolyNodeToPaths(c,n,r)},e.Clipper.OpenPathsFromPolyTree=function(t){for(var n=new e.Paths,r=0,i=t.ChildCount();r<i;r++)t.Childs()[r].IsOpen&&n.push(t.Childs()[r].m_polygon);return n},e.Clipper.ClosedPathsFromPolyTree=function(t){var n=new e.Paths;return e.Clipper.AddPolyNodeToPaths(t,e.Clipper.NodeType.ntClosed,n),n},ht(e.Clipper,e.ClipperBase),e.Clipper.NodeType={ntAny:0,ntOpen:1,ntClosed:2},e.ClipperOffset=function(t,n){t===void 0&&(t=2),n===void 0&&(n=e.ClipperOffset.def_arc_tolerance),this.m_destPolys=new e.Paths,this.m_srcPoly=new e.Path,this.m_destPoly=new e.Path,this.m_normals=[],this.m_delta=0,this.m_sinA=0,this.m_sin=0,this.m_cos=0,this.m_miterLim=0,this.m_StepsPerRad=0,this.m_lowest=new e.IntPoint0,this.m_polyNodes=new e.PolyNode,this.MiterLimit=t,this.ArcTolerance=n,this.m_lowest.X=-1},e.ClipperOffset.two_pi=6.28318530717959,e.ClipperOffset.def_arc_tolerance=.25,e.ClipperOffset.prototype.Clear=function(){e.Clear(this.m_polyNodes.Childs()),this.m_lowest.X=-1},e.ClipperOffset.Round=e.Clipper.Round,e.ClipperOffset.prototype.AddPath=function(t,n,r){var i=t.length-1;if(!(i<0)){var a=new e.PolyNode;if(a.m_jointype=n,a.m_endtype=r,r===e.EndType.etClosedLine||r===e.EndType.etClosedPolygon)for(;i>0&&e.IntPoint.op_Equality(t[0],t[i]);)i--;a.m_polygon.push(t[0]);for(var o=0,s=0,c=1;c<=i;c++)e.IntPoint.op_Inequality(a.m_polygon[o],t[c])&&(o++,a.m_polygon.push(t[c]),(t[c].Y>a.m_polygon[s].Y||t[c].Y===a.m_polygon[s].Y&&t[c].X<a.m_polygon[s].X)&&(s=o));if(!(r===e.EndType.etClosedPolygon&&o<2)&&(this.m_polyNodes.AddChild(a),r===e.EndType.etClosedPolygon)){if(this.m_lowest.X<0)this.m_lowest=new e.IntPoint2(this.m_polyNodes.ChildCount()-1,s);else{var l=this.m_polyNodes.Childs()[this.m_lowest.X].m_polygon[this.m_lowest.Y];(a.m_polygon[s].Y>l.Y||a.m_polygon[s].Y===l.Y&&a.m_polygon[s].X<l.X)&&(this.m_lowest=new e.IntPoint2(this.m_polyNodes.ChildCount()-1,s))}}}},e.ClipperOffset.prototype.AddPaths=function(e,t,n){for(var r=0,i=e.length;r<i;r++)this.AddPath(e[r],t,n)},e.ClipperOffset.prototype.FixOrientations=function(){if(this.m_lowest.X>=0&&!e.Clipper.Orientation(this.m_polyNodes.Childs()[this.m_lowest.X].m_polygon))for(var t=0;t<this.m_polyNodes.ChildCount();t++){var n=this.m_polyNodes.Childs()[t];(n.m_endtype===e.EndType.etClosedPolygon||n.m_endtype===e.EndType.etClosedLine&&e.Clipper.Orientation(n.m_polygon))&&n.m_polygon.reverse()}else for(var t=0;t<this.m_polyNodes.ChildCount();t++){var n=this.m_polyNodes.Childs()[t];n.m_endtype===e.EndType.etClosedLine&&!e.Clipper.Orientation(n.m_polygon)&&n.m_polygon.reverse()}},e.ClipperOffset.GetUnitNormal=function(t,n){var r=n.X-t.X,i=n.Y-t.Y;if(r===0&&i===0)return new e.DoublePoint2(0,0);var a=1/Math.sqrt(r*r+i*i);return r*=a,i*=a,new e.DoublePoint2(i,-r)},e.ClipperOffset.prototype.DoOffset=function(t){if(this.m_destPolys=[],this.m_delta=t,e.ClipperBase.near_zero(t))for(var n=0;n<this.m_polyNodes.ChildCount();n++){var r=this.m_polyNodes.Childs()[n];r.m_endtype===e.EndType.etClosedPolygon&&this.m_destPolys.push(r.m_polygon)}else{this.m_miterLim=this.MiterLimit>2?2/(this.MiterLimit*this.MiterLimit):.5;var i=this.ArcTolerance<=0?e.ClipperOffset.def_arc_tolerance:this.ArcTolerance>Math.abs(t)*e.ClipperOffset.def_arc_tolerance?Math.abs(t)*e.ClipperOffset.def_arc_tolerance:this.ArcTolerance,a=3.14159265358979/Math.acos(1-i/Math.abs(t));this.m_sin=Math.sin(e.ClipperOffset.two_pi/a),this.m_cos=Math.cos(e.ClipperOffset.two_pi/a),this.m_StepsPerRad=a/e.ClipperOffset.two_pi,t<0&&(this.m_sin=-this.m_sin);for(var n=0;n<this.m_polyNodes.ChildCount();n++){var r=this.m_polyNodes.Childs()[n];this.m_srcPoly=r.m_polygon;var o=this.m_srcPoly.length;if(!(o===0||t<=0&&(o<3||r.m_endtype!==e.EndType.etClosedPolygon))){if(this.m_destPoly=[],o===1){if(r.m_jointype===e.JoinType.jtRound)for(var s=1,c=0,l=1;l<=a;l++){this.m_destPoly.push(new e.IntPoint2(e.ClipperOffset.Round(this.m_srcPoly[0].X+s*t),e.ClipperOffset.Round(this.m_srcPoly[0].Y+c*t)));var u=s;s=s*this.m_cos-this.m_sin*c,c=u*this.m_sin+c*this.m_cos}else for(var s=-1,c=-1,l=0;l<4;++l)this.m_destPoly.push(new e.IntPoint2(e.ClipperOffset.Round(this.m_srcPoly[0].X+s*t),e.ClipperOffset.Round(this.m_srcPoly[0].Y+c*t))),s<0?s=1:c<0?c=1:s=-1;this.m_destPolys.push(this.m_destPoly)}else{this.m_normals.length=0;for(var l=0;l<o-1;l++)this.m_normals.push(e.ClipperOffset.GetUnitNormal(this.m_srcPoly[l],this.m_srcPoly[l+1]));if(r.m_endtype===e.EndType.etClosedLine||r.m_endtype===e.EndType.etClosedPolygon?this.m_normals.push(e.ClipperOffset.GetUnitNormal(this.m_srcPoly[o-1],this.m_srcPoly[0])):this.m_normals.push(new e.DoublePoint1(this.m_normals[o-2])),r.m_endtype===e.EndType.etClosedPolygon){for(var d=o-1,l=0;l<o;l++)d=this.OffsetPoint(l,d,r.m_jointype);this.m_destPolys.push(this.m_destPoly)}else if(r.m_endtype===e.EndType.etClosedLine){for(var d=o-1,l=0;l<o;l++)d=this.OffsetPoint(l,d,r.m_jointype);this.m_destPolys.push(this.m_destPoly),this.m_destPoly=[];for(var f=this.m_normals[o-1],l=o-1;l>0;l--)this.m_normals[l]=new e.DoublePoint2(-this.m_normals[l-1].X,-this.m_normals[l-1].Y);this.m_normals[0]=new e.DoublePoint2(-f.X,-f.Y),d=0;for(var l=o-1;l>=0;l--)d=this.OffsetPoint(l,d,r.m_jointype);this.m_destPolys.push(this.m_destPoly)}else{for(var d=0,l=1;l<o-1;++l)d=this.OffsetPoint(l,d,r.m_jointype);var p;if(r.m_endtype===e.EndType.etOpenButt){var l=o-1;p=new e.IntPoint2(e.ClipperOffset.Round(this.m_srcPoly[l].X+this.m_normals[l].X*t),e.ClipperOffset.Round(this.m_srcPoly[l].Y+this.m_normals[l].Y*t)),this.m_destPoly.push(p),p=new e.IntPoint2(e.ClipperOffset.Round(this.m_srcPoly[l].X-this.m_normals[l].X*t),e.ClipperOffset.Round(this.m_srcPoly[l].Y-this.m_normals[l].Y*t)),this.m_destPoly.push(p)}else{var l=o-1;d=o-2,this.m_sinA=0,this.m_normals[l]=new e.DoublePoint2(-this.m_normals[l].X,-this.m_normals[l].Y),r.m_endtype===e.EndType.etOpenSquare?this.DoSquare(l,d):this.DoRound(l,d)}for(var l=o-1;l>0;l--)this.m_normals[l]=new e.DoublePoint2(-this.m_normals[l-1].X,-this.m_normals[l-1].Y);this.m_normals[0]=new e.DoublePoint2(-this.m_normals[1].X,-this.m_normals[1].Y),d=o-1;for(var l=d-1;l>0;--l)d=this.OffsetPoint(l,d,r.m_jointype);r.m_endtype===e.EndType.etOpenButt?(p=new e.IntPoint2(e.ClipperOffset.Round(this.m_srcPoly[0].X-this.m_normals[0].X*t),e.ClipperOffset.Round(this.m_srcPoly[0].Y-this.m_normals[0].Y*t)),this.m_destPoly.push(p),p=new e.IntPoint2(e.ClipperOffset.Round(this.m_srcPoly[0].X+this.m_normals[0].X*t),e.ClipperOffset.Round(this.m_srcPoly[0].Y+this.m_normals[0].Y*t)),this.m_destPoly.push(p)):(d=1,this.m_sinA=0,r.m_endtype===e.EndType.etOpenSquare?this.DoSquare(0,1):this.DoRound(0,1)),this.m_destPolys.push(this.m_destPoly)}}}}}},e.ClipperOffset.prototype.Execute=function(){var t=arguments;if(t[0]instanceof e.PolyTree){var n=t[0],r=t[1];n.Clear(),this.FixOrientations(),this.DoOffset(r);var i=new e.Clipper(0);if(i.AddPaths(this.m_destPolys,e.PolyType.ptSubject,!0),r>0)i.Execute(e.ClipType.ctUnion,n,e.PolyFillType.pftPositive,e.PolyFillType.pftPositive);else{var a=e.Clipper.GetBounds(this.m_destPolys),o=new e.Path;if(o.push(new e.IntPoint2(a.left-10,a.bottom+10)),o.push(new e.IntPoint2(a.right+10,a.bottom+10)),o.push(new e.IntPoint2(a.right+10,a.top-10)),o.push(new e.IntPoint2(a.left-10,a.top-10)),i.AddPath(o,e.PolyType.ptSubject,!0),i.ReverseSolution=!0,i.Execute(e.ClipType.ctUnion,n,e.PolyFillType.pftNegative,e.PolyFillType.pftNegative),n.ChildCount()===1&&n.Childs()[0].ChildCount()>0){var s=n.Childs()[0];n.Childs()[0]=s.Childs()[0],n.Childs()[0].m_Parent=n;for(var c=1;c<s.ChildCount();c++)n.AddChild(s.Childs()[c])}else n.Clear()}}else{var n=t[0],r=t[1];e.Clear(n),this.FixOrientations(),this.DoOffset(r);var i=new e.Clipper(0);if(i.AddPaths(this.m_destPolys,e.PolyType.ptSubject,!0),r>0)i.Execute(e.ClipType.ctUnion,n,e.PolyFillType.pftPositive,e.PolyFillType.pftPositive);else{var a=e.Clipper.GetBounds(this.m_destPolys),o=new e.Path;o.push(new e.IntPoint2(a.left-10,a.bottom+10)),o.push(new e.IntPoint2(a.right+10,a.bottom+10)),o.push(new e.IntPoint2(a.right+10,a.top-10)),o.push(new e.IntPoint2(a.left-10,a.top-10)),i.AddPath(o,e.PolyType.ptSubject,!0),i.ReverseSolution=!0,i.Execute(e.ClipType.ctUnion,n,e.PolyFillType.pftNegative,e.PolyFillType.pftNegative),n.length>0&&n.splice(0,1)}}},e.ClipperOffset.prototype.OffsetPoint=function(t,n,r){if(this.m_sinA=this.m_normals[n].X*this.m_normals[t].Y-this.m_normals[t].X*this.m_normals[n].Y,Math.abs(this.m_sinA*this.m_delta)<1){if(this.m_normals[n].X*this.m_normals[t].X+this.m_normals[t].Y*this.m_normals[n].Y>0)return this.m_destPoly.push(new e.IntPoint2(e.ClipperOffset.Round(this.m_srcPoly[t].X+this.m_normals[n].X*this.m_delta),e.ClipperOffset.Round(this.m_srcPoly[t].Y+this.m_normals[n].Y*this.m_delta))),n}else this.m_sinA>1?this.m_sinA=1:this.m_sinA<-1&&(this.m_sinA=-1);if(this.m_sinA*this.m_delta<0)this.m_destPoly.push(new e.IntPoint2(e.ClipperOffset.Round(this.m_srcPoly[t].X+this.m_normals[n].X*this.m_delta),e.ClipperOffset.Round(this.m_srcPoly[t].Y+this.m_normals[n].Y*this.m_delta))),this.m_destPoly.push(new e.IntPoint1(this.m_srcPoly[t])),this.m_destPoly.push(new e.IntPoint2(e.ClipperOffset.Round(this.m_srcPoly[t].X+this.m_normals[t].X*this.m_delta),e.ClipperOffset.Round(this.m_srcPoly[t].Y+this.m_normals[t].Y*this.m_delta)));else switch(r){case e.JoinType.jtMiter:var i=1+(this.m_normals[t].X*this.m_normals[n].X+this.m_normals[t].Y*this.m_normals[n].Y);i>=this.m_miterLim?this.DoMiter(t,n,i):this.DoSquare(t,n);break;case e.JoinType.jtSquare:this.DoSquare(t,n);break;case e.JoinType.jtRound:this.DoRound(t,n)}return n=t,n},e.ClipperOffset.prototype.DoSquare=function(t,n){var r=Math.tan(Math.atan2(this.m_sinA,this.m_normals[n].X*this.m_normals[t].X+this.m_normals[n].Y*this.m_normals[t].Y)/4);this.m_destPoly.push(new e.IntPoint2(e.ClipperOffset.Round(this.m_srcPoly[t].X+this.m_delta*(this.m_normals[n].X-this.m_normals[n].Y*r)),e.ClipperOffset.Round(this.m_srcPoly[t].Y+this.m_delta*(this.m_normals[n].Y+this.m_normals[n].X*r)))),this.m_destPoly.push(new e.IntPoint2(e.ClipperOffset.Round(this.m_srcPoly[t].X+this.m_delta*(this.m_normals[t].X+this.m_normals[t].Y*r)),e.ClipperOffset.Round(this.m_srcPoly[t].Y+this.m_delta*(this.m_normals[t].Y-this.m_normals[t].X*r))))},e.ClipperOffset.prototype.DoMiter=function(t,n,r){var i=this.m_delta/r;this.m_destPoly.push(new e.IntPoint2(e.ClipperOffset.Round(this.m_srcPoly[t].X+(this.m_normals[n].X+this.m_normals[t].X)*i),e.ClipperOffset.Round(this.m_srcPoly[t].Y+(this.m_normals[n].Y+this.m_normals[t].Y)*i)))},e.ClipperOffset.prototype.DoRound=function(t,n){for(var r=Math.atan2(this.m_sinA,this.m_normals[n].X*this.m_normals[t].X+this.m_normals[n].Y*this.m_normals[t].Y),i=Math.max(e.Cast_Int32(e.ClipperOffset.Round(this.m_StepsPerRad*Math.abs(r))),1),a=this.m_normals[n].X,o=this.m_normals[n].Y,s,c=0;c<i;++c)this.m_destPoly.push(new e.IntPoint2(e.ClipperOffset.Round(this.m_srcPoly[t].X+a*this.m_delta),e.ClipperOffset.Round(this.m_srcPoly[t].Y+o*this.m_delta))),s=a,a=a*this.m_cos-this.m_sin*o,o=s*this.m_sin+o*this.m_cos;this.m_destPoly.push(new e.IntPoint2(e.ClipperOffset.Round(this.m_srcPoly[t].X+this.m_normals[t].X*this.m_delta),e.ClipperOffset.Round(this.m_srcPoly[t].Y+this.m_normals[t].Y*this.m_delta)))},e.Error=function(e){try{throw Error(e)}catch(e){alert(e.message)}},e.JS={},e.JS.AreaOfPolygon=function(t,n){return n||=1,e.Clipper.Area(t)/(n*n)},e.JS.AreaOfPolygons=function(t,n){n||=1;for(var r=0,i=0;i<t.length;i++)r+=e.Clipper.Area(t[i]);return r/(n*n)},e.JS.BoundsOfPath=function(t,n){return e.JS.BoundsOfPaths([t],n)},e.JS.BoundsOfPaths=function(t,n){n||=1;var r=e.Clipper.GetBounds(t);return r.left/=n,r.bottom/=n,r.right/=n,r.top/=n,r},e.JS.Clean=function(t,n){if(!(t instanceof Array))return[];var r=t[0]instanceof Array,t=e.JS.Clone(t);if(typeof n!=`number`||n===null)return e.Error(`Delta is not a number in Clean().`),t;if(t.length===0||t.length===1&&t[0].length===0||n<0)return t;r||(t=[t]);for(var i=t.length,a,o,s,c,l,u,d,f=[],p=0;p<i;p++)if(o=t[p],a=o.length,a!==0){if(a<3)s=o,f.push(s);else{for(s=o,c=n*n,l=o[0],u=1,d=1;d<a;d++)(o[d].X-l.X)*(o[d].X-l.X)+(o[d].Y-l.Y)*(o[d].Y-l.Y)<=c||(s[u]=o[d],l=o[d],u++);l=o[u-1],(o[0].X-l.X)*(o[0].X-l.X)+(o[0].Y-l.Y)*(o[0].Y-l.Y)<=c&&u--,u<a&&s.splice(u,a-u),s.length&&f.push(s)}}return!r&&f.length?f=f[0]:!r&&f.length===0?f=[]:r&&f.length===0&&(f=[[]]),f},e.JS.Clone=function(e){if(!(e instanceof Array)||e.length===0)return[];if(e.length===1&&e[0].length===0)return[[]];var t=e[0]instanceof Array;t||(e=[e]);var n=e.length,r,i,a,o,s=Array(n);for(i=0;i<n;i++){for(r=e[i].length,o=Array(r),a=0;a<r;a++)o[a]={X:e[i][a].X,Y:e[i][a].Y};s[i]=o}return t||(s=s[0]),s},e.JS.Lighten=function(t,n){if(!(t instanceof Array))return[];if(typeof n!=`number`||n===null)return e.Error(`Tolerance is not a number in Lighten().`),e.JS.Clone(t);if(t.length===0||t.length===1&&t[0].length===0||n<0)return e.JS.Clone(t);var r=t[0]instanceof Array;r||(t=[t]);var i,a,o,s,c,l,u,d,f,p,m,h,g,_,v,y,b,x=t.length,S=n*n,C=[];for(i=0;i<x;i++)if(o=t[i],l=o.length,l!==0){for(s=0;s<1e6;s++){for(c=[],l=o.length,o[l-1].X!==o[0].X||o[l-1].Y!==o[0].Y?(h=1,o.push({X:o[0].X,Y:o[0].Y}),l=o.length):h=0,m=[],a=0;a<l-2;a++)u=o[a],f=o[a+1],d=o[a+2],y=u.X,b=u.Y,g=d.X-y,_=d.Y-b,(g!==0||_!==0)&&(v=((f.X-y)*g+(f.Y-b)*_)/(g*g+_*_),v>1?(y=d.X,b=d.Y):v>0&&(y+=g*v,b+=_*v)),g=f.X-y,_=f.Y-b,p=g*g+_*_,p<=S&&(m[a+1]=1,a++);for(c.push({X:o[0].X,Y:o[0].Y}),a=1;a<l-1;a++)m[a]||c.push({X:o[a].X,Y:o[a].Y});if(c.push({X:o[l-1].X,Y:o[l-1].Y}),h&&o.pop(),m.length)o=c;else break}l=c.length,c[l-1].X===c[0].X&&c[l-1].Y===c[0].Y&&c.pop(),c.length>2&&C.push(c)}return r||(C=C[0]),C===void 0&&(C=[]),C},e.JS.PerimeterOfPath=function(e,t,n){if(e===void 0)return 0;var r=Math.sqrt,i=0,a,o,s=0,c=0,l=0,u=0,d=e.length;if(d<2)return 0;for(t&&(e[d]=e[0],d++);--d;)a=e[d],s=a.X,c=a.Y,o=e[d-1],l=o.X,u=o.Y,i+=r((s-l)*(s-l)+(c-u)*(c-u));return t&&e.pop(),i/n},e.JS.PerimeterOfPaths=function(t,n,r){r||=1;for(var i=0,a=0;a<t.length;a++)i+=e.JS.PerimeterOfPath(t[a],n,r);return i},e.JS.ScaleDownPath=function(e,t){var n,r;for(t||=1,n=e.length;n--;)r=e[n],r.X/=t,r.Y/=t},e.JS.ScaleDownPaths=function(e,t){var n,r,i;for(t||=1,n=e.length;n--;)for(r=e[n].length;r--;)i=e[n][r],i.X/=t,i.Y/=t},e.JS.ScaleUpPath=function(e,t){var n,r,i=Math.round;for(t||=1,n=e.length;n--;)r=e[n],r.X=i(r.X*t),r.Y=i(r.Y*t)},e.JS.ScaleUpPaths=function(e,t){var n,r,i,a=Math.round;for(t||=1,n=e.length;n--;)for(r=e[n].length;r--;)i=e[n][r],i.X=a(i.X*t),i.Y=a(i.Y*t)},e.ExPolygons=function(){return[]},e.ExPolygon=function(){this.outer=null,this.holes=null},e.JS.AddOuterPolyNodeToExPolygons=function(t,n){var r=new e.ExPolygon;r.outer=t.Contour();var i=t.Childs(),a=i.length;r.holes=Array(a);for(var o,s,c=0,l,u,d;c<a;c++)for(o=i[c],r.holes[c]=o.Contour(),l=0,u=o.Childs(),d=u.length;l<d;l++)s=u[l],e.JS.AddOuterPolyNodeToExPolygons(s,n);n.push(r)},e.JS.ExPolygonsToPaths=function(t){var n,r,i,a,o=new e.Paths;for(n=0,i=t.length;n<i;n++)for(o.push(t[n].outer),r=0,a=t[n].holes.length;r<a;r++)o.push(t[n].holes[r]);return o},e.JS.PolyTreeToExPolygons=function(t){for(var n=new e.ExPolygons,r,i=0,a=t.Childs(),o=a.length;i<o;i++)r=a[i],e.JS.AddOuterPolyNodeToExPolygons(r,n);return n}})()})))(),1);let x=1e3,S=e=>Math.round(e*x),C=e=>e.map(e=>({X:S(e.x),Y:S(e.y)})),ee=e=>e.map(e=>({x:e.X/x,y:e.Y/x}));function te(e,t){let n=new b.default.Clipper;return n.StrictlySimple=!0,n.AddPaths(e.filter(e=>e.length>=3),b.default.PolyType.ptSubject,!0),n.AddPaths(t.filter(e=>e.length>=3),b.default.PolyType.ptClip,!0),n}function ne(e){let t=new b.default.PolyTree,n=b.default.PolyFillType.pftNonZero;return te(e,[]).Execute(b.default.ClipType.ctUnion,t,n,n),b.default.JS.PolyTreeToExPolygons(t).map(e=>({outer:e.outer,holes:e.holes}))}let re=e=>b.default.Clipper.Area(e);function ie(e){return e!==void 0&&e.outline.length>=3}let w={A:`0,0 0,4 2,6 4,4 4,0;0,3 4,3`,B:`0,0 0,6 3,6 4,5 4,4 3,3 0,3;3,3 4,2 4,1 3,0 0,0`,C:`4,1 3,0 1,0 0,1 0,5 1,6 3,6 4,5`,D:`0,0 0,6 3,6 4,5 4,1 3,0 0,0`,E:`4,0 0,0 0,6 4,6;0,3 3,3`,F:`0,0 0,6 4,6;0,3 3,3`,G:`4,5 3,6 1,6 0,5 0,1 1,0 3,0 4,1 4,3 2,3`,H:`0,0 0,6;4,0 4,6;0,3 4,3`,I:`1,0 3,0;2,0 2,6;1,6 3,6`,J:`0,1 1,0 2,0 3,1 3,6;2,6 4,6`,K:`0,0 0,6;4,6 0,2;1,3 4,0`,L:`0,6 0,0 4,0`,M:`0,0 0,6 2,3 4,6 4,0`,N:`0,0 0,6 4,0 4,6`,O:`1,0 0,1 0,5 1,6 3,6 4,5 4,1 3,0 1,0`,P:`0,0 0,6 3,6 4,5 4,4 3,3 0,3`,Q:`1,0 0,1 0,5 1,6 3,6 4,5 4,1 3,0 1,0;2,2 4,0`,R:`0,0 0,6 3,6 4,5 4,4 3,3 0,3;2,3 4,0`,S:`4,5 3,6 1,6 0,5 0,4 1,3 3,3 4,2 4,1 3,0 1,0 0,1`,T:`0,6 4,6;2,6 2,0`,U:`0,6 0,1 1,0 3,0 4,1 4,6`,V:`0,6 2,0 4,6`,W:`0,6 1,0 2,3 3,0 4,6`,X:`0,0 4,6;0,6 4,0`,Y:`0,6 2,3 4,6;2,3 2,0`,Z:`0,6 4,6 0,0 4,0`,0:`1,0 0,1 0,5 1,6 3,6 4,5 4,1 3,0 1,0;0,1 4,5`,1:`1,5 2,6 2,0;1,0 3,0`,2:`0,5 1,6 3,6 4,5 4,4 0,0 4,0`,3:`0,5 1,6 3,6 4,5 4,4 3,3 4,2 4,1 3,0 1,0 0,1;1,3 3,3`,4:`3,0 3,6 0,2 4,2`,5:`4,6 0,6 0,3 3,3 4,2 4,1 3,0 1,0 0,1`,6:`4,5 3,6 1,6 0,5 0,1 1,0 3,0 4,1 4,2 3,3 0,3`,7:`0,6 4,6 1,0`,8:`1,3 0,4 0,5 1,6 3,6 4,5 4,4 3,3 1,3 0,2 0,1 1,0 3,0 4,1 4,2 3,3`,9:`0,1 1,0 3,0 4,1 4,5 3,6 1,6 0,5 0,4 1,3 4,3`,"-":`1,3 3,3`,_:`0,0 4,0`,"+":`2,1 2,5;0,3 4,3`,".":`2,0 2,0`,"/":`0,0 4,6`,"~":`0,3 1,4 3,2 4,3`,"(":`3,6 2,5 2,1 3,0`,")":`1,6 2,5 2,1 1,0`,"#":`1,0 1,6;3,0 3,6;0,2 4,2;0,4 4,4`," ":``};function ae(e){let t=w[e.toUpperCase()]??`0,0 4,0 4,6 0,6 0,0`;return t===``?[]:t.split(`;`).map(e=>e.split(` `).map(e=>{let[t,n]=e.split(`,`).map(Number);return{x:t??0,y:n??0}}))}function T(e,t){let n=[...e].length;return n===0?0:((n-1)*6+4)*t/6}function oe(e,t,n,r=!1,i=!1){let a=n/6,o=[...e],s=T(e,6),c=r?-1:1;return o.flatMap((e,n)=>ae(e).map(e=>e.map(e=>{let r=c*(n*6+e.x-s/2)*a,o=(e.y-3)*a;return i?{x:t.x-o,y:t.y+r}:{x:t.x+r,y:t.y+o}})))}let se=.15,ce=[0,.4,.8,1.2,1.6],E={pad:100,hole:100,via:50,designator:100,courtyard:2,edge:1e3},D=(e,t)=>e.minX<t.maxX&&t.minX<e.maxX&&e.minY<t.maxY&&t.minY<e.maxY,le=(e,t)=>Math.max(0,Math.min(e.maxX,t.maxX)-Math.max(e.minX,t.minX))*Math.max(0,Math.min(e.maxY,t.maxY)-Math.max(e.minY,t.minY)),ue=(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)}),de=(e,t)=>({minX:e.minX-t,minY:e.minY-t,maxX:e.maxX+t,maxY:e.maxY+t});function O(e,t,n=0){let r=T(e,1)/2+se/2,i=.575,[a,o]=n===90?[i,r]:[r,i];return{minX:t.x-a,minY:t.y-o,maxX:t.x+a,maxY:t.y+o}}function fe(e,t){let n=e.rotation*Math.PI/180,[r,i]=[Math.abs(Math.cos(n)),Math.abs(Math.sin(n))],[a,o]=[e.width/2+t,e.height/2+t],[s,c]=e.shape===`circle`?[a,a]:[a*r+o*i,a*i+o*r];return{minX:e.x-s,minY:e.y-c,maxX:e.x+s,maxY:e.y+c}}function pe(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 me(e,t){let n=Math.abs(e-t),r=Math.max(e,n),i=Math.max(.5,r/4),a=[0,n,e,...Array.from({length:Math.floor(r/i)},(e,t)=>(t+1)*i)].flatMap(e=>[-e,e]).map(e=>Math.round(e*1e6)/1e6+0);return[...new Set(a)]}function he(e,t,n){return n===void 0?[...k(e,t,e=>e?0:90),...k(e,t,e=>e?90:0)]:k(e,t,()=>n)}function k(e,t,n){if(e.courtyard.length===0)return[{at:{x:e.x,y:e.y},rotation:n(!0)}];let r=pe(e.courtyard),[i,a]=[(r.minX+r.maxX)/2,(r.minY+r.maxY)/2],[o,s]=[(r.maxX-r.minX)/2,(r.maxY-r.minY)/2],c=T(e.component,1)/2+se/2,l=.575,u=[],d={flat:me(o,n(!0)===0?c:l),upright:me(s,n(!1)===0?l:c)};for(let e of ce){let o=t+e;for(let e of[`top`,`bottom`,`left`,`right`]){let t=e===`top`||e===`bottom`,s=n(t),[f,p]=s===0===t?[c,l]:[l,c];if(t){let t=e===`top`,n=t?r.maxY+o+p:r.minY-o-p,[a,c]=t?[r.maxY,n+p]:[n-p,r.minY];for(let e of d.flat)u.push({at:{x:i+e,y:n},rotation:s,reach:{minX:i+e-f,maxX:i+e+f,minY:a,maxY:c}})}else{let t=e===`right`,n=t?r.maxX+o+p:r.minX-o-p,[i,c]=t?[r.maxX,n+p]:[n-p,r.minX];for(let e of d.upright)u.push({at:{x:n,y:a+e},rotation:s,reach:{minX:i,maxX:c,minY:a+e-f,maxY:a+e+f}})}}}let f=e=>Math.round(Math.hypot(e.at.x-i,e.at.y-a)*1e3);return u.map((e,t)=>({place:e,i:t,d:f(e)})).sort((e,t)=>e.d-t.d||e.i-t.i).map(e=>e.place)}var ge=class{outline;clearance;fixedIndex=new A;textIndex=new A;designators=/* @__PURE__ */ new Map;keptOf=/* @__PURE__ */ new WeakMap;constructor(e,t){this.outline=e,this.clearance=t}add(e,t,n,r){let i={kind:e,component:t,side:n,box:r};e===`designator`?(this.remove(t),this.designators.set(t,i),this.textIndex.insert(i,r)):this.fixedIndex.insert(i,r)}remove(e){let t=this.designators.get(e);t&&(t.gone=!0),this.designators.delete(e)}covered(e,t,n=!0){let{near:r,fixed:i}=n?this.kept(e,t):this.measured(e,t,!1);if(this.designators.size===0)return i;let a;for(let t of this.textIndex.query(r))!t.gone&&t.side===e.side&&t.component!==e.component&&D(r,t.box)&&(a??={...i,designators:[]},a.score+=E.designator*(1+le(r,t.box)),a.designators.push(t.component));return a??i}kept(e,t){let n=this.keptOf.get(t);if(n)return n;let r=this.measured(e,t,!0);return this.keptOf.set(t,r),r}measured(e,t,n){let r=O(e.component,t.at,t.rotation);return{near:n?de(r,this.clearance):r,fixed:this.fixedCovered(e,t,r,n)}}fixedCovered(e,t,n,r){let i=t.reach??n,a={pads:[],designators:[],courtyards:[],vias:!1,holes:!1,edge:!1,score:0,fixed:0,between:0};for(let t of this.fixedIndex.query(r?ue(n,i):n)){if(t.side!==`both`&&t.side!==e.side||t.component===e.component&&t.kind!==`pad`)continue;let o=t.kind===`courtyard`&&r&&!D(n,t.box)&&D(i,t.box);if(!o&&!D(n,t.box))continue;let s=le(n,t.box),c=o?1:E[t.kind]*(t.kind===`courtyard`?Math.max(s,.001):1+s);a.score+=c,o?a.between+=1:a.fixed+=c,o||(t.kind===`pad`?a.pads.push(t.component):t.kind===`courtyard`?a.courtyards.push(t.component):t.kind===`via`?a.vias=!0:a.holes=!0)}return this.outline&&!_e(n,this.outline)&&(a.edge=!0,a.score+=E.edge,a.fixed+=E.edge),a}},A=class e{cells=/* @__PURE__ */ new Map;stamp=0;static key(e,t){return(e+32768)*65536+(t+32768)}insert(t,n){for(let r=Math.floor(n.minX/2);r<=Math.floor(n.maxX/2);r++)for(let i=Math.floor(n.minY/2);i<=Math.floor(n.maxY/2);i++){let n=e.key(r,i),a=this.cells.get(n);a?a.push(t):this.cells.set(n,[t])}}query(t){let n=++this.stamp,r=[];for(let i=Math.floor(t.minX/2);i<=Math.floor(t.maxX/2);i++)for(let a=Math.floor(t.minY/2);a<=Math.floor(t.maxY/2);a++)for(let t of this.cells.get(e.key(i,a))??[])t.seen!==n&&(t.seen=n,r.push(t));return r}};function _e(e,t){return[{x:e.minX,y:e.minY},{x:e.maxX,y:e.minY},{x:e.maxX,y:e.maxY},{x:e.minX,y:e.maxY}].every(e=>m(e,t))?!t.some(t=>t.x>e.minX&&t.x<e.maxX&&t.y>e.minY&&t.y<e.maxY):!1}let j=e=>[...new Set(e)].sort(_),ve=e=>(Math.round(e)%360+360)%360;function ye(e,t,n){let r=new ge(ie(e.board)?e.board?.outline:void 0,n);for(let n of e.parts){for(let e of n.pads)r.add(`pad`,n.component,e.layers===`through`?`both`:e.layers,fe(e,t));n.courtyard.length>0&&r.add(`courtyard`,n.component,n.side,pe(n.courtyard))}for(let t of e.vias??[]){let e=t.diameter/2;r.add(`via`,``,`both`,{minX:t.at.x-e,minY:t.at.y-e,maxX:t.at.x+e,maxY:t.at.y+e})}for(let t of e.holes??[]){let e=t.diameter/2;r.add(`hole`,``,`both`,{minX:t.x-e,minY:t.y-e,maxX:t.x+e,maxY:t.y+e})}return r}function be(e){let t=/* @__PURE__ */ new Map;for(let n of e){if(n.copyOf===void 0)continue;let e=`${n.copyOf}@${ve(n.rotation)}${n.side}`;t.set(e,[...t.get(e)??[],n])}return t}function xe(e,t,n=.15){let r=`${t}/${n}`,i=Ce(e,r);if(i)return i;let a=Ee(e,t,n);return we(e,r,a),a}let Se=/* @__PURE__ */ new WeakMap;function Ce(e,t){let n=e.parts[0],r=n&&Se.get(n);if(r&&r.key===t&&r.vias===e.vias&&r.holes===e.holes&&r.board===e.board&&r.parts.length===e.parts.length){for(let t=0;t<r.parts.length;t++)if(r.parts[t]!==e.parts[t])return;return r.placements}}function we(e,t,n){let r=e.parts[0];r&&Se.set(r,{key:t,parts:e.parts,vias:e.vias,holes:e.holes,board:e.board,placements:n})}function M(e,t){let n;for(let r of e){let e=t(r);if(e.score===0)return r;n===void 0&&e.score===e.between*1&&(n=r)}return n}function Te(e,t,n){let[r,i]=[0,0];for(let e of t){let t=n(e);if(t.score===0&&r++,t.score===t.between*1&&i++,r>=Oe)break}return{clear:r,fair:i}}function Ee(e,t,n){let r=e.parts.filter(e=>e.component!==``),i=ye(e,t,n),a=/* @__PURE__ */ new Map,o=(e,t)=>{a.set(e.component,t),i.add(`designator`,e.component,e.side,O(e.component,t.at,t.rotation))},s=/* @__PURE__ */ new Map,c=e=>{let t=s.get(e.component);if(t)return t;let r=he(e,n,e.nameRotation);return s.set(e.component,r),r},l=(e,t)=>i.covered(e,t).score===0,u=(e,t)=>{let n=i.covered(e,t);return n.score===n.between*1},d=e=>{let t=c(e),n=M(t,t=>i.covered(e,t));if(n)return n;let r={place:t[0],score:1/0};for(let n of t){let t=i.covered(e,n).score;t<r.score&&(r={place:n,score:t})}return r.place};for(let e of r)e.nameAt&&o(e,{at:e.nameAt,rotation:e.nameRotation??0});let f=new Map(r.filter(e=>!e.nameAt).map(e=>[e.component,Te(e,c(e),t=>i.covered(e,t))])),p=De(r.filter(e=>!e.nameAt),e=>f.get(e.component)??{clear:0,fair:0});for(let e of p)e.length>1?je(e,c,l,d,o):o(e[0],d(e[0]));return ke(r,a,{tries:c,clear:l,fair:u,settle:o,covered:(e,t)=>i.covered(e,t),remove:e=>i.remove(e.component)}),r.map(e=>{let t=a.get(e.component),n=i.covered(e,t,!1);return{component:e.component,side:e.side,at:t.at,rotation:t.rotation,coversPads:j(n.pads),coversDesignators:j(n.designators),coversParts:j(n.courtyards),offBoard:n.edge}})}function De(e,t){let n=e=>t(e).clear>0?0:t(e).fair>0?1:2,r=e=>[t(e).clear,t(e).fair,0][n(e)],i=new Map([...be(e).values()].flatMap(e=>e.map(t=>[t.component,e]))),a=[],o=/* @__PURE__ */ new Set;for(let t of e){if(o.has(t.component))continue;let e=i.get(t.component)??[t];e.forEach(e=>o.add(e.component));let r=e.filter(e=>n(e)===0);r.length>0&&a.push(r),a.push(...e.filter(e=>n(e)>0).map(e=>[e]))}let s=e=>({tier:Math.max(...e.map(n)),size:Math.min(...e.map(r))});return a.map((e,t)=>({members:e,i:t,...s(e)})).sort((e,t)=>e.tier-t.tier||e.size-t.size||e.i-t.i).map(e=>e.members)}let Oe=12;function ke(e,t,n){let r=new Map(e.map(e=>[e.component,e])),i=new Set(e.filter(e=>e.nameAt).map(e=>e.component));for(let a=0;a<2;a++){let a=!1;for(let o of e){let e=t.get(o.component);if(i.has(o.component)||n.clear(o,e))continue;let s=n.fair(o,e);n.remove(o);let c=M(n.tries(o),e=>n.covered(o,e)),l=c&&(n.clear(o,c)||!s)?c:void 0,u=[];for(let e of l?[]:n.tries(o)){let t=n.covered(o,e);if(t.fixed!==0||t.between!==0&&s||t.designators.some(e=>i.has(e))||u.push(e),u.length>=4)break}l&&n.settle(o,l);let d=l!==void 0||u.some(e=>Ae(o,e,r,t,n));d||n.settle(o,e),a||=d}if(!a)return}}function Ae(e,t,n,r,i){let a=j(i.covered(e,t).designators).map(e=>n.get(e)),o=a.map(e=>[e,r.get(e.component)]);a.forEach(i.remove),i.settle(e,t);let s=[];for(let e of a){let t=M(i.tries(e),t=>i.covered(e,t));if(!t)break;i.settle(e,t),s.push(e)}return s.length===a.length||(s.forEach(i.remove),i.remove(e),o.forEach(([e,t])=>i.settle(e,t)),!1)}function je(e,t,n,r,i){let a=e.map(t),o=Math.min(...a.map(e=>e.length)),s=t=>e.every((e,r)=>n(e,a[r]?.[t]))&&Me(e,a,t);for(let t=0;t<o;t++)if(s(t)){e.forEach((e,n)=>i(e,a[n]?.[t]));return}let c={index:-1,clear:0};for(let t=0;t<o;t++){let r=e.filter((e,r)=>n(e,a[r]?.[t])).length;r>c.clear&&(c={index:t,clear:r})}let l=[];e.forEach((e,t)=>{let r=c.index>=0?a[t]?.[c.index]:void 0;r&&n(e,r)?i(e,r):l.push(e)}),l.forEach(e=>i(e,r(e)))}function Me(e,t,n){let r=e.map((e,r)=>{let i=t[r]?.[n];return O(e.component,i.at,i.rotation)});return r.every((e,t)=>r.every((n,r)=>r<=t||!(e.minX<n.maxX&&n.minX<e.maxX&&e.minY<n.maxY&&n.minY<e.maxY)))}let Ne=e=>e.minSilkToPad??.15,Pe=[`top`,`bottom`],N=1e-9,Fe={top:`F_Cu`,inner1:`In1_Cu`,inner2:`In2_Cu`,bottom:`B_Cu`},P={top:`F`,bottom:`B`},F={top:`Top`,bottom:`Bot`},I=e=>e.drill===void 0&&e.layers!==`through`,Ie=(e,t)=>e.layers===`through`||e.layers===t;function L(e,t=0,n){let r=e.width+2*t,i=e.height+2*t;if(r<=0||i<=0)return;let a={x:e.x,y:e.y},o=(e.rotation%360+360)%360%180,s=Math.abs(o%90)<N||Math.abs(o%90-90)<N,c=Math.abs(o-90)<N?{width:i,height:r}:{width:r,height:i},l=n===void 0?{}:{function:n},u=()=>s?{kind:`flash`,at:a,aperture:{shape:`rect`,...c},...l}:{kind:`region`,points:Re(a,r,i,e.rotation),...l};switch(e.shape){case`circle`:return{kind:`flash`,at:a,aperture:{shape:`circle`,diameter:r},...l};case`rect`:return u();case`oval`:return s?{kind:`flash`,at:a,aperture:{shape:`obround`,...c},...l}:{kind:`region`,points:Le(a,r,i,e.rotation),...l};case`roundrect`:{let n=Math.min(Math.max((e.cornerRadius??0)+t,0),r/2,i/2);return n<=0?u():{kind:`flash`,at:a,aperture:{shape:`roundrect`,radius:n,...s?{...c,rotation:0}:{width:r,height:i,rotation:o}},...l}}}}function Le(e,t,n,r){let i=Math.min(t,n)/2,a=Math.max(t,n)/2-i,o=(r+(n>t?90:0))*Math.PI/180,[s,c]=[Math.cos(o),Math.sin(o)],l=(e,t)=>Array.from({length:11},(n,r)=>{let a=t+Math.PI*r/10;return{x:e+i*Math.cos(a),y:i*Math.sin(a)}});return[...l(a,-Math.PI/2),...l(-a,Math.PI/2)].map(({x:t,y:n})=>({x:e.x+t*s-n*c,y:e.y+t*c+n*s}))}function Re(e,t,n,r){let i=r*Math.PI/180,[a,o]=[Math.cos(i),Math.sin(i)];return[[-t/2,-n/2],[t/2,-n/2],[t/2,n/2],[-t/2,n/2]].map(([t,n])=>({x:e.x+t*a-n*o,y:e.y+t*o+n*a}))}let ze=e=>e.flatMap(e=>e.pads),R=e=>I(e)?`SMDPad,CuDef`:`ComponentPad`,z=e=>e!==void 0;function Be(e,t){let n=e.pours.filter(e=>e.layer===t).flatMap(e=>e.polygons.flatMap(e=>[C(e.outer),...e.holes.map(C)]));return n.length===0?[]:ne(n).sort((e,t)=>Math.abs(re(t.outer))-Math.abs(re(e.outer))).flatMap(e=>[{kind:`region`,points:ee(e.outer),function:`Conductor`},...e.holes.map(e=>({kind:`region`,points:ee(e),polarity:`clear`}))])}function Ve(e,t){let n=ze(e.parts).filter(e=>e.layers===`through`||e.layers===t).map(e=>L(e,0,R(e))),r=e.tracks.filter(e=>e.layer===t&&e.missingLayer===void 0).map(e=>({kind:`draw`,points:e.points,width:e.width,function:`Conductor`})),i=e.vias.filter(e=>e.missingLayer===void 0&&y(e).has(t)).map(e=>({kind:`flash`,at:e.at,aperture:{shape:`circle`,diameter:e.diameter},function:`ViaPad`}));return[...Be(e,t),...n.filter(z),...r,...i]}function He(e,t,n,r){let i=xe(e,n,r).filter(e=>e.side===t);return[...e.parts.filter(e=>e.side===t).flatMap(e=>e.silkscreen),...i.flatMap(e=>oe(e.component,e.at,1,t===`bottom`,e.rotation===90))].filter(e=>e.length>0).map(e=>({kind:`draw`,points:e,width:se,function:`Other,Legend`}))}function Ue(e){let t=e.board?.outline??[],n=t[0];return n===void 0?[]:[{kind:`draw`,points:[...t,n],width:.1,function:`Profile`}]}function We(e,t){let n=u(e.board?.layers??2),r=t.maskExpansion??.05,i=t.pasteReduction??0,a=/* @__PURE__ */ new Map;[`top`,`inner1`,`inner2`,`bottom`].filter(e=>n.includes(e)).forEach((t,n)=>{let r=t===`top`?`Top`:t===`bottom`?`Bot`:`Inr`;a.set(Fe[t],{fileFunction:`Copper,L${n+1},${r}`,polarity:`Positive`,objects:Ve(e,t)})});for(let n of Pe){let o=ze(e.parts).filter(e=>Ie(e,n)),s=o.map(e=>L(e,r,R(e))).filter(z),c=o.filter(I).map(e=>L(e,-i,R(e))).filter(z);a.set(`${P[n]}_Mask`,{fileFunction:`Soldermask,${F[n]}`,polarity:`Negative`,objects:s}),a.set(`${P[n]}_Paste`,{fileFunction:`Paste,${F[n]}`,polarity:`Positive`,objects:c}),a.set(`${P[n]}_Silkscreen`,{fileFunction:`Legend,${F[n]}`,polarity:`Positive`,objects:He(e,n,r,Ne(t))})}return a.set(`Edge_Cuts`,{fileFunction:`Profile,NP`,polarity:`Positive`,objects:Ue(e)}),d.flatMap(e=>{let t=a.get(e);return t===void 0?[]:[{name:e,layer:t}]})}let B={green:{name:`green mask`,sentence:`The common solder mask: deep green, lighter where copper lies under it.`,over:[18,82,44],onCopper:[56,132,66],see:.1,gloss:.6},black:{name:`black mask`,sentence:`Glossy black; copper under it shows only as a faint sheen.`,over:[20,21,23],onCopper:[40,42,44],see:.04,gloss:.9},"matte-black":{name:`matte black mask`,sentence:`Black without gloss; the copper under it barely shows.`,over:[33,33,34],onCopper:[43,43,44],see:.02,gloss:.1},blue:{name:`blue mask`,sentence:`Medium blue, lighter over copper.`,over:[16,52,122],onCopper:[44,92,168],see:.08,gloss:.6},red:{name:`red mask`,sentence:`Deep red, lighter over copper.`,over:[146,22,30],onCopper:[190,56,52],see:.08,gloss:.6},white:{name:`white mask`,sentence:`White; copper under it reads as a pale warm tint. Its print is black by default.`,over:[232,233,229],onCopper:[242,238,222],see:.06,gloss:.4},yellow:{name:`yellow mask`,sentence:`Strong yellow, paler over copper.`,over:[212,176,28],onCopper:[232,204,78],see:.06,gloss:.5},purple:{name:`purple mask`,sentence:`Dark purple, lighter over copper.`,over:[70,30,108],onCopper:[106,62,152],see:.08,gloss:.6}},V={white:{name:`white print`,sentence:`The usual legend ink.`,colour:[244,244,238]},black:{name:`black print`,sentence:`Dark legend ink, for a white or yellow mask.`,colour:[24,24,26]}},H={enig:{name:`ENIG`,sentence:`Immersion gold over nickel: flat and gold.`,face:[212,170,78],rim:[150,110,44],shine:[246,214,132]},hasl:{name:`HASL`,sentence:`Hot-air levelled solder: silver grey, a little domed.`,face:[190,193,198],rim:[124,127,132],shine:[236,238,242]}},Ge={lit:[184,180,156],shaded:[138,132,106]},Ke=[70,62,46],qe=Object.keys(B),Je=Object.keys(V),Ye=Object.keys(H),Xe=/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i;function Ze(e={}){let t=e.mask??`green`;if(!(t in B))throw Error(`mask must be one of ${qe.join(`, `)}`);let n=e.silk??(t===`white`?`black`:`white`);if(!(n in V))throw Error(`silk must be one of ${Je.join(`, `)}`);let r=e.finish??`enig`;if(!(r in H))throw Error(`finish must be one of ${Ye.join(`, `)}`);if(e.background===void 0)return{mask:t,silk:n,finish:r};let i=Xe.exec(e.background);if(!i)throw Error(`background must be a colour written "#rrggbb"`);return{mask:t,silk:n,finish:r,background:[1,2,3].map(e=>parseInt(i[e],16))}}let Qe=e=>e<0?0:e>1?1:e,$e=(e,t,n)=>{let r=Qe((n-e)/(t-e));return r*r*(3-2*r)},U=(e,t)=>e.data[t],et=(e,t)=>Math.max(1,Math.round(e*t));function tt(e,t,n,r,i){let a=new Float32Array(e.length),[o,s]=i?[n,t]:[t,n],c=i?1:t,l=1/(2*r+1);for(let n=0;n<o;n+=1){let o=i?n*t:n,u=o+(s-1)*c,d=0;for(let t=-r;t<=r;t+=1)d+=e[o+Math.min(Math.max(t,0),s-1)*c];for(let t=0,n=o;t<s;t+=1,n+=c){a[n]=d*l;let i=t+r+1<s?n+(r+1)*c:u,f=t-r>0?n-r*c:o;d+=e[i]-e[f]}}return a}function W(e,t){let n=e.data;for(let r=0;r<2;r+=1)n=tt(tt(n,e.width,e.height,t,!0),e.width,e.height,t,!1);return{width:e.width,height:e.height,data:n}}function nt(e,t){let{width:n,height:r}=e,i=new Float32Array(n*r),a=Math.max(1,Math.round(t/2)),o=(t+1)/(2*a);for(let t=0;t<r;t+=1){let[s,c]=[Math.max(t-a,0),Math.min(t+a,r-1)];for(let r=0;r<n;r+=1){let[l,u]=[Math.max(r-a,0),Math.min(r+a,n-1)];i[t*n+r]=Math.max(-1,Math.min(1,(e.data[c*n+u]-e.data[s*n+l])*-o))}}return i}function G(e,t,n,r,i,a){for(let o=0;o<3;o+=1)e[t+o]=n[r+o]+(i[o]-n[r+o])*a}function rt(e){let t=e.body.data.length,n=new Float32Array(t*3),r=Ge.shaded,i=[0,1,2].map(e=>Ge.lit[e]-r[e]);for(let a=0;a<t;a+=1){let t=(1-U(e.copper,a))*(1-U(e.otherCopper,a));n[a*3]=r[0]+i[0]*t,n[a*3+1]=r[1]+i[1]*t,n[a*3+2]=r[2]+i[2]*t}return n}function it(e,t,n,r){let i=B[n.mask],{width:a,height:o}=t.body,s=new Float32Array(e.length),c=[0,0,0];for(let n=0;n<o;n+=1){let l=i.gloss*14*.5;for(let u=0;u<a;u+=1){let d=n*a+u,f=U(t.body,d)*(1-U(t.openings,d)),p=U(r.soft,d),m=r.slope[d]*34*(.5+i.gloss*.5),h=l*(1-u/a-n/o);for(let t=0;t<3;t+=1){let n=i.over[t]+(i.onCopper[t]-i.over[t])*p;c[t]=n+(e[d*3+t]-Ge.shaded[t])*i.see+m+h}G(s,d*3,e,d*3,c,f)}}return s}function at(e,t,n,r){let i=H[n.finish],a=new Float32Array(e),o=[0,0,0];for(let n=0;n<t.body.data.length;n+=1){let s=U(t.copper,n)*U(t.openings,n)*U(t.body,n);if(s<=0)continue;let c=$e(.1,.9,U(r.soft,n)),l=r.slope[n];for(let e=0;e<3;e+=1){let t=i.rim[e]+(i.face[e]-i.rim[e])*c;o[e]=l>=0?t+(i.shine[e]-t)*l*.8:t+(i.rim[e]-t)*-l*.6}G(a,n*3,e,n*3,o,s)}return a}function ot(e,t,n){let r=V[n.silk].colour,i=new Float32Array(e);for(let n=0;n<t.body.data.length;n+=1){let a=U(t.silk,n)*U(t.body,n)*(1-U(t.openings,n))*(1-Math.max(U(t.plated,n),U(t.nonPlated,n)));a>0&&G(i,n*3,e,n*3,r,a*.97)}return i}let K=(e,t)=>Math.max(U(e.bore,t),U(e.nonPlated,t));function st(e,t){let n=t.body.data.length,r=new Float32Array(n*4);for(let i=0;i<n;i+=1){let n=Math.max(0,U(t.plated,i)-U(t.bore,i));n>0?G(r,i*4,e,i*3,Ke,n):(r[i*4]=e[i*3],r[i*4+1]=e[i*3+1],r[i*4+2]=e[i*3+2]),r[i*4+3]=U(t.body,i)*(1-K(t,i))}return r}function ct(e,t){let n=new Float32Array(e);for(let r=0;r<t.data.length;r+=1){let i=Qe((1-U(t,r))*2.5);if(!(i<=0))for(let t=0;t<3;t+=1)n[r*4+t]=e[r*4+t]*(1-.42*i)}return n}function lt(e,t){let n=new Uint8ClampedArray(e.length);for(let r=0;r<e.length;r+=4){let i=e[r+3];if(t===void 0){for(let t=0;t<3;t+=1)n[r+t]=e[r+t];n[r+3]=i*255}else{for(let a=0;a<3;a+=1)n[r+a]=t[a]+(e[r+a]-t[a])*i;n[r+3]=255}}return n}function ut(e,t,n){let r=(e,t)=>{let r=et(t,n),i=W(e,r);return{soft:i,slope:nt(i,r)}},i=e.body.data.length,a={...e.copper,data:new Float32Array(i)},o={...e.body,data:new Float32Array(i)};for(let t=0;t<i;t+=1)a.data[t]=U(e.copper,t)*U(e.openings,t),o.data[t]=U(e.body,t)*(1-K(e,t));return lt(ct(st(ot(at(it(rt(e),e,t,r(e.copper,.06)),e,t,r(a,.035)),e,t),e),W(o,et(.08,n))),t.background)}function dt(e,t,n){let r=Math.max(1,Math.ceil((e.maxX-e.minX)*t-1e-9));return{width:r,height:Math.max(1,Math.ceil((e.maxY-e.minY)*t-1e-9)),pxPerMm:t,minX:e.minX,maxX:e.minX+r/t,maxY:e.maxY,mirrored:n}}let q=e=>({width:e.width,height:e.height,data:new Float32Array(e.width*e.height)});function J(e,t){return{x:(e.mirrored?e.maxX-t.x:t.x-e.minX)*e.pxPerMm,y:(e.maxY-t.y)*e.pxPerMm}}function Y(e,t){let n=Math.max(e-.5,-t),r=Math.min(e+.5,t);return r>n?Math.min(r-n,1):0}let ft=(e,t)=>Math.sqrt(e*e+t*t),X=e=>e<0?0:e>1?1:e;function pt(e,t,n,r){if(!(n<=0)){if(r===`dark`)n>e[t]&&(e[t]=n);else{let r=1-n;r<e[t]&&(e[t]=r)}}}function mt(e,t,n,r,i,a){let o=Math.max(0,Math.floor(Math.min(t.x,n.x)-r)),s=Math.min(e.width,Math.ceil(Math.max(t.x,n.x)+r)),c=Math.max(0,Math.floor(Math.min(t.y,n.y)-r)),l=Math.min(e.height,Math.ceil(Math.max(t.y,n.y)+r));for(let t=c;t<l;t+=1){let n=t*e.width;for(let r=o;r<s;r+=1)pt(e.data,n+r,i(r+.5,t+.5),a)}}function Z(e,t,n,r=`dark`){mt(e,t,t,n+1,(e,r)=>Y(ft(e-t.x,r-t.y),n),r)}function Q(e,t,n,r,i=`dark`){let[a,o]=[n.x-t.x,n.y-t.y],s=a*a+o*o;if(s===0)return Z(e,t,r,i);mt(e,t,n,r+1,(e,n)=>{let i=X(((e-t.x)*a+(n-t.y)*o)/s);return Y(ft(e-t.x-i*a,n-t.y-i*o),r)},i)}function ht(e,t,n,r,i,a,o=`dark`){let[s,c]=[Math.cos(i),Math.sin(i)],l=Math.hypot(n,r)+1,u=Math.min(a,n,r);mt(e,t,t,l,(e,i)=>{let a=(e-t.x)*s+(i-t.y)*c,o=-(e-t.x)*c+(i-t.y)*s;if(u<=0)return Y(a,n)*Y(o,r);let l=Math.abs(a)-(n-u),d=Math.abs(o)-(r-u),f=ft(Math.max(l,0),Math.max(d,0))+Math.min(Math.max(l,d),0)-u;return X(.5-f)},o)}function gt(e){let t=[];for(let n of e)for(let e=0;e<n.length;e+=1){let r=n[e],i=n[(e+1)%n.length];if(r.y===i.y)continue;let[a,o,s]=r.y<i.y?[r,i,1]:[i,r,-1];t.push({x0:a.x,y0:a.y,y1:o.y,slope:(o.x-a.x)/(o.y-a.y),dir:s})}return t.sort((e,t)=>e.y0-t.y0)}function _t(e,t,n,r,i){let a=Math.floor(n),o=Math.floor(r);a===o?e[a]=e[a]+(r-n)*i:(e[a]=e[a]+(a+1-n)*i,t[a+1]=t[a+1]+i,t[o]=t[o]-i,e[o]=e[o]+(r-o)*i)}function vt(e,t,n,r=`dark`){let i=gt(t);if(i.length===0)return;let a=Math.max(0,Math.floor(i[0]?.y0??0)),o=Math.min(e.height,Math.ceil(Math.max(...i.map(e=>e.y1)))),s=new Float32Array(e.width+2),c=new Float32Array(e.width+2),l=[],u=0,d=[],f=1/16;for(let t=a;t<o;t+=1){for(;u<i.length&&i[u].y0<t+1;)d.push(i[u++]);if(d=d.filter(e=>e.y1>t),d.length===0)continue;let a=e.width,o=0;for(let r=0;r<16;r+=1){let i=t+(r+.5)*f;l.length=0;for(let e of d)e.y0<=i&&i<e.y1&&l.push({x:e.x0+(i-e.y0)*e.slope,dir:e.dir});l.sort((e,t)=>e.x-t.x);let u=0;for(let t=0;t<l.length-1;t+=1){let r=l[t];if(u=n===`nonzero`?u+r.dir:u^1,u===0)continue;let i=Math.max(r.x,0),d=Math.min(l[t+1].x,e.width);if(d<=i)continue;let p=Math.min(d,e.width-1e-9);_t(s,c,i,p,f),a=Math.min(a,Math.floor(i)),o=Math.max(o,Math.floor(p)+1)}}let p=0,m=t*e.width;for(let t=a;t<o;t+=1)p+=c[t],pt(e.data,m+t,Math.min(p+s[t],1),r),s[t]=0,c[t]=0;o>a&&(c[o]=0)}}function yt(e,t){let n=t*Math.PI/180;return Math.atan2(-Math.sin(n),(e.mirrored?-1:1)*Math.cos(n))}function bt(e,t,n,r,i){let a=t.pxPerMm,o=J(t,n);switch(r.shape){case`circle`:return Z(e,o,r.diameter/2*a,i);case`rect`:return ht(e,o,r.width/2*a,r.height/2*a,0,0,i);case`obround`:{let t=r.width>=r.height,n=Math.abs(r.width-r.height)/2*a,[s,c]=t?[n,0]:[0,n];return Q(e,{x:o.x-s,y:o.y-c},{x:o.x+s,y:o.y+c},Math.min(r.width,r.height)/2*a,i)}case`roundrect`:return ht(e,o,r.width/2*a,r.height/2*a,yt(t,r.rotation),r.radius*a,i)}}function xt(e,t,n){let r=t.pxPerMm;if(n.kind===`flash`)return bt(e,t,n.at,n.aperture,`dark`);if(n.kind===`region`)return vt(e,[n.points.map(e=>J(t,e))],`nonzero`,n.polarity===`clear`?`clear`:`dark`);let i=n.points.map(e=>J(t,e)),a=n.width/2*r;if(i.length===1)return Z(e,i[0],a);for(let t=1;t<i.length;t+=1)Q(e,i[t-1],i[t],a)}function St(e,t){let n=q(e);for(let r of t.objects)xt(n,e,r);return n}function Ct(e,t){let n=q(e);return vt(n,t.objects.flatMap(t=>t.kind===`draw`&&t.points.length>=3?[t.points.map(t=>J(e,t))]:[]),`evenodd`),n}function wt(e,t,n=0){let r=q(e);for(let i of t){let t=(i.diameter/2-n)*e.pxPerMm;if(t<=0)continue;let a=J(e,i.at);i.to===void 0?Z(r,a,t):Q(r,a,J(e,i.to),t)}return r}let Tt={top:{copper:`F_Cu`,mask:`F_Mask`,paste:`F_Paste`,silk:`F_Silkscreen`},bottom:{copper:`B_Cu`,mask:`B_Mask`,paste:`B_Paste`,silk:`B_Silkscreen`}},Et=/* @__PURE__ */ new Set([`F_Cu`,`In1_Cu`,`In2_Cu`,`B_Cu`]);function Dt(e){let t=e.board?.outline??[];if(t.length<3)throw Error(`The board has no outline to draw`);let n=t.map(e=>e.x),r=t.map(e=>e.y);return{minX:Math.min(...n),minY:Math.min(...r),maxX:Math.max(...n),maxY:Math.max(...r)}}function Ot(e,t){let n=dt(t.box??Dt(e.pcb),t.pxPerMm??20,(t.side??`top`)===`bottom`);if(Math.max(n.width,n.height)>4e3)throw Error(`The picture would be ${n.width} x ${n.height} px; at most 4000 on its long side`);return n}function kt(e,t,n){Dt(e.pcb);let r=new Map(We(e.pcb,e.rules.fabrication).map(({name:e,layer:t})=>[e,t])),i=Tt[n],a=e=>{let n=r.get(e);return n===void 0?q(t):St(t,n)},o=q(t);for(let e of Et){if(e===i.copper||!r.has(e))continue;let t=a(e);for(let e=0;e<t.data.length;e+=1)t.data[e]>o.data[e]&&(o.data[e]=t.data[e])}let s=r.get(`Edge_Cuts`),c=p(e.pcb);return{body:s===void 0?q(t):Ct(t,s),copper:a(i.copper),otherCopper:o,openings:a(i.mask),paste:a(i.paste),silk:a(i.silk),plated:wt(t,c.plated),bore:wt(t,c.plated,Math.max(.05,1/t.pxPerMm)),nonPlated:wt(t,c.nonPlated)}}function At(e,t={}){let n=t.side??`top`,r=Ze(t.look),i=Ot(e,t),a=ut(kt(e,i,n),r,i.pxPerMm);return{width:i.width,height:i.height,rgba:a,pxPerMm:i.pxPerMm,mmPerPx:1/i.pxPerMm,box:{minX:i.minX,minY:i.maxY-i.height/i.pxPerMm,maxX:i.maxX,maxY:i.maxY},origin:J(i,{x:0,y:0}),mirrored:i.mirrored,side:n,look:r}}let $=(e=>{let t=Math.hypot(e[0],e[1],e[2]);return[e[0]/t,e[1]/t,e[2]/t]})([-.55,.5,.78]);.44/$[2];function jt(e){let[t,n]=[e.maxX-e.minX,e.maxY-e.minY];return Math.min(40,4e3/Math.max(t,n,1e-9),Math.sqrt(4e6/Math.max(t*n,1e-9)))}function Mt(e){let t=[...e].sort((e,t)=>e.x-t.x||e.y-t.y),n=(e,t,n)=>(t.x-e.x)*(n.y-e.y)-(t.y-e.y)*(n.x-e.x),r=e=>{let t=[];for(let r of e){for(;t.length>=2&&n(t[t.length-2],t[t.length-1],r)<=0;)t.pop();t.push(r)}return t.pop(),t};return[...r(t),...r([...t].reverse())]}function Nt(e,t,n,r){let i=(e,i)=>{let a=new Float32Array(e.length),[o,s]=i?[n,t]:[t,n];for(let n=0;n<o;n++){let o=0,c=e=>i?n*t+e:e*t+n;for(let t=-r;t<=r;t++)o+=t>=0&&t<s?e[c(t)]:0;for(let t=0;t<s;t++){a[c(t)]=o/(2*r+1);let[n,i]=[t+r+1,t-r];n<s&&(o+=e[c(n)]),i>=0&&(o-=e[c(i)])}}return a},a=e;for(let e=0;e<2;e++)a=i(i(a,!0),!1);return a}function Pt(e,t,n){let[r,i]=[Math.ceil(e.width/4),Math.ceil(e.height/4)],a=new Float32Array(r*i),o=(t,n)=>({x:(e.origin.x+(e.mirrored?-t:t)*e.pxPerMm)/4,y:(e.origin.y-n*e.pxPerMm)/4}),[s,c]=[-$[0]/$[2],-$[1]/$[2]];for(let e of t.filter(e=>e.side===n)){let t=Math.min(e.height,2.6),n=Mt(e.corners.flatMap(e=>[e,{x:e.x+s*t,y:e.y+c*t}]).map(e=>o(e.x,e.y))),[l,u]=[Math.max(0,Math.floor(Math.min(...n.map(e=>e.x)))),Math.min(r-1,Math.ceil(Math.max(...n.map(e=>e.x))))],[d,f]=[Math.max(0,Math.floor(Math.min(...n.map(e=>e.y)))),Math.min(i-1,Math.ceil(Math.max(...n.map(e=>e.y))))];for(let e=d;e<=f;e++)for(let t=l;t<=u;t++){let[i,o]=[t+.5,e+.5],s=0,c=!0;for(let e=0;e<n.length&&c;e++){let t=n[e],r=n[(e+1)%n.length],a=Math.sign((r.x-t.x)*(o-t.y)-(r.y-t.y)*(i-t.x));a!==0&&(s===0?s=a:a!==s&&(c=!1))}c&&(a[e*r+t]=1)}}let l=Nt(a,r,i,Math.max(1,Math.round(.45*e.pxPerMm/4/2))),u=new Uint8ClampedArray(e.rgba);for(let t=0;t<e.height;t++){let n=Math.min(i-1.001,Math.max(0,t/4-.5)),[a,o]=[Math.floor(n),n-Math.floor(n)];for(let n=0;n<e.width;n++){let s=(t*e.width+n)*4;if(u[s+3]===0)continue;let c=Math.min(r-1.001,Math.max(0,n/4-.5)),[d,f]=[Math.floor(c),c-Math.floor(c)],p=(e,t)=>l[Math.min(i-1,t)*r+Math.min(r-1,e)],m=(p(d,a)*(1-f)+p(d+1,a)*f)*(1-o)+(p(d,a+1)*(1-f)+p(d+1,a+1)*f)*o;if(m<=.002)continue;let h=1-.45*Math.min(1,m);u[s]=u[s]*h,u[s+1]=u[s+1]*h,u[s+2]=u[s+2]*h}}return u}function Ft(e,t,n,r=At){let i;try{i=Dt(e.pcb)}catch{return{}}let a=jt(i),o=i=>{let o=r(e,{side:i,look:{...n,background:void 0},pxPerMm:a}),s={rgba:o.rgba,width:o.width,height:o.height,origin:o.origin,pxPerMm:o.pxPerMm,mirrored:o.mirrored};return{...s,rgba:Pt(s,t.parts,i)}};return{top:o(`top`),bottom:o(`bottom`)}}self.onmessage=e=>{let{id:t,design:n,model:r,look:i}=e.data;try{let e=Ft(n,r,i),a=[e.top,e.bottom].flatMap(e=>e?[e.rgba.buffer]:[]);self.postMessage({id:t,textures:e},a)}catch(e){self.postMessage({id:t,error:e.message})}}})();
|
package/dist/app/index.html
CHANGED
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
<title>copperflow studio</title>
|
|
7
7
|
<!-- The remembered theme (theme-state.ts, key copperflow.theme) before any style loads, so Dark never flashes light. An external file: the server's Content-Security-Policy blocks inline scripts. -->
|
|
8
8
|
<script src="./theme-boot.js"></script>
|
|
9
|
-
<script type="module" crossorigin src="./assets/index-
|
|
10
|
-
<link rel="stylesheet" crossorigin href="./assets/index-
|
|
9
|
+
<script type="module" crossorigin src="./assets/index-DPmr2dR1.js"></script>
|
|
10
|
+
<link rel="stylesheet" crossorigin href="./assets/index-BKoIKo22.css">
|
|
11
11
|
</head>
|
|
12
12
|
<body>
|
|
13
13
|
<div id="root"></div>
|
package/dist/cli-commands.js
CHANGED
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
import { resolve } from "node:path";
|
|
2
2
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
3
|
-
import {
|
|
3
|
+
import { bomWithReport, exportFabrication, exportPackage, formatFabrication, formatBomCsv, formatBomMarkdown, listParts, placePart, readPart, rebuildComponents, verifyPart, addMark, checkCircuit, formatCheck, formatBoardImport, formatHistory, formatSummary, importBoard, listHistory, loadCircuit, lockParts, removeMark, undoChange, unlockParts, updateAnnotations, writeRender, } from "./core/index.js";
|
|
4
|
+
import { PIN_FORMATS, pinMapText } from "./core/pin-map.js";
|
|
4
5
|
import { buildWith } from "./core/design-source.js";
|
|
6
|
+
import { Engine } from "./engine/engine.js";
|
|
5
7
|
import { formatImport, importLcscPart } from "./library/import-lcsc.js";
|
|
8
|
+
import { formatKicadImport, importKicad } from "./library/kicad/import.js";
|
|
6
9
|
import { createCopperflowServer } from "./mcp/server.js";
|
|
7
10
|
import { studioCommand } from "./cli-studio.js";
|
|
11
|
+
import { impedanceCommand } from "./cli-impedance.js";
|
|
8
12
|
import { VERSION } from "./version.js";
|
|
9
13
|
import { installSkill } from "./skill-install.js";
|
|
10
14
|
import { modulesCommand } from "./cli-modules.js";
|
|
11
15
|
import { libraryCommand } from "./cli-library.js";
|
|
16
|
+
import { changeTarget, changeText, changeView } from "./core/change-view.js";
|
|
17
|
+
import { changeRequest } from "./core/change-render.js";
|
|
18
|
+
import { simulateCommand, spiceCommand } from "./cli-simulate.js";
|
|
19
|
+
import { exportStep, formatStepExport } from "./core/step-export.js";
|
|
12
20
|
const HELP = `copperflow ${VERSION}
|
|
13
21
|
|
|
14
22
|
Usage:
|
|
@@ -47,16 +55,36 @@ Usage:
|
|
|
47
55
|
add a library or built-in part to a circuit
|
|
48
56
|
copperflow bom <file> [--csv] print the bill of materials
|
|
49
57
|
copperflow package <file> [--out dir]
|
|
50
|
-
write BOM, datasheets
|
|
58
|
+
write BOM, datasheets, part status and pin maps to a folder
|
|
59
|
+
copperflow pins <file> [--part <name>] [--format md|csv|c]
|
|
60
|
+
which net is on each pin of the library chips and connectors
|
|
51
61
|
copperflow export <file> [--out dir] write the fabrication files for JLCPCB: Gerbers, drills,
|
|
52
62
|
pick-and-place and BOM in <name>-fab/ and <name>-fab.zip
|
|
53
|
-
beside the circuit (or in the project folder --out)
|
|
54
|
-
copperflow
|
|
63
|
+
beside the circuit (or in the project folder --out), with <name>.step
|
|
64
|
+
copperflow step <file> [--out file.step] write the board and its parts (as boxes) as a STEP file for CAD,
|
|
65
|
+
<name>.step beside the circuit
|
|
66
|
+
copperflow render <file> [--view pcb|schematic|board|3d] [--page <name>] [--parts U1,C3] [--width n] [--out file.png]
|
|
67
|
+
board: the bare board as made [--side bottom] [--mask black] [--finish hasl] [--silk black] [--background #rrggbb]
|
|
68
|
+
3d: the board as made with its parts as simple shapes [--angle top|bottom|front|iso] and the same look options
|
|
69
|
+
[--change <id> | --since <id>]
|
|
55
70
|
draw the board or a schematic page to a PNG, as the Studio shows it
|
|
56
71
|
(<name>-pcb.png or <name>-schematic-<page>.png beside the circuit)
|
|
72
|
+
copperflow simulate <file> --set V12=12 --set CTRL=3.3 [--sheet <name>] [--closed SW1,J2] [--coil K1] [--all]
|
|
73
|
+
the DC operating point from ideal sources and simple models: no time,
|
|
74
|
+
no frequency, no temperature, no tolerance; chips are not modelled.
|
|
75
|
+
With --sheet and no --set it runs the sheet's cases
|
|
76
|
+
copperflow spice <file> [--sheet <name>] [--set net=volts ...] [--out file.cir]
|
|
77
|
+
write the same circuit as a SPICE3 netlist for another simulator
|
|
57
78
|
copperflow board <file> --dxf <path> [--layer <name>] [--units mm|inch] [--origin keep] [--replace]
|
|
58
79
|
set the board's outline, holes and keepouts from a DXF drawing
|
|
80
|
+
copperflow import kicad <board.kicad_pcb> [--name <circuit name>] [--replace] [--origin keep]
|
|
81
|
+
make a new circuit from a KiCad board: its outline, parts (as
|
|
82
|
+
library parts, not verified), nets, tracks, vias and pours
|
|
83
|
+
copperflow impedance [--single 50] [--pair 90] [--gap 0.2] [--width 0.3]
|
|
84
|
+
line widths and gaps for an impedance on the board's stack (rules.yaml);
|
|
85
|
+
an estimate: the router does not route pairs together or tune lengths
|
|
59
86
|
copperflow history [--limit n] list recent changes
|
|
87
|
+
copperflow history <id> | --since <id> what one change did, or everything after it
|
|
60
88
|
copperflow undo [id] undo the newest change, or the given one
|
|
61
89
|
|
|
62
90
|
Every command accepts --root <dir> (default: the current directory).
|
|
@@ -67,9 +95,16 @@ export async function runCli(args, cwd, io, options = {}) {
|
|
|
67
95
|
const [command, ...rest] = afterRoot;
|
|
68
96
|
try {
|
|
69
97
|
switch (command) {
|
|
70
|
-
case "mcp":
|
|
71
|
-
|
|
98
|
+
case "mcp": {
|
|
99
|
+
// One engine for the whole session. A new one for each call starts a worker and loads the builder again,
|
|
100
|
+
// which cost most of a second on every call that builds. It stops when the agent's program closes the pipe.
|
|
101
|
+
const own = options.engine ? undefined : new Engine();
|
|
102
|
+
if (own)
|
|
103
|
+
for (const event of ["end", "close"])
|
|
104
|
+
process.stdin.once(event, () => void own.stop());
|
|
105
|
+
await createCopperflowServer(root, own ? { ...options, engine: own } : options).connect(new StdioServerTransport());
|
|
72
106
|
return 0;
|
|
107
|
+
}
|
|
73
108
|
case "studio":
|
|
74
109
|
io.out(await studioCommand(root, rest, takeOption));
|
|
75
110
|
return 0;
|
|
@@ -97,11 +132,15 @@ export async function runCli(args, cwd, io, options = {}) {
|
|
|
97
132
|
io.out(`Removed mark ${rest[1]}`);
|
|
98
133
|
return 0;
|
|
99
134
|
case "history": {
|
|
100
|
-
const [limit] = takeOption(rest, "--limit");
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
135
|
+
const [limit, afterLimit] = takeOption(rest, "--limit");
|
|
136
|
+
const [since, args] = takeOption(afterLimit, "--since");
|
|
137
|
+
const target = changeTarget(args[0], since);
|
|
138
|
+
if (target) {
|
|
139
|
+
io.out(changeText(await changeView(root, target, options.engine ? { engine: options.engine } : {})));
|
|
140
|
+
return 0;
|
|
104
141
|
}
|
|
142
|
+
const { entries, problems } = await listHistory(root, positiveInt(limit ?? "20"));
|
|
143
|
+
io.out(formatHistory(entries, problems));
|
|
105
144
|
return 0;
|
|
106
145
|
}
|
|
107
146
|
case "parts":
|
|
@@ -123,8 +162,8 @@ export async function runCli(args, cwd, io, options = {}) {
|
|
|
123
162
|
case "bom": {
|
|
124
163
|
const [csv, withoutCsv] = takeFlag(rest, "--csv");
|
|
125
164
|
const file = required(rejectBuildFlag(withoutCsv)[0], "file");
|
|
126
|
-
const lines = await
|
|
127
|
-
io.out(csv ? formatBomCsv(lines) : formatBomMarkdown(lines));
|
|
165
|
+
const { lines, report } = await bomWithReport(root, file, designOptions(options));
|
|
166
|
+
io.out(csv ? formatBomCsv(lines) : `${formatBomMarkdown(lines)}\n${report}`);
|
|
128
167
|
return 0;
|
|
129
168
|
}
|
|
130
169
|
case "package": {
|
|
@@ -134,18 +173,44 @@ export async function runCli(args, cwd, io, options = {}) {
|
|
|
134
173
|
io.out(`Wrote ${result.outDir}:\n${result.files.join("\n")}`);
|
|
135
174
|
return 0;
|
|
136
175
|
}
|
|
176
|
+
case "pins": {
|
|
177
|
+
const [part, afterPart] = takeOption(rest, "--part");
|
|
178
|
+
const [format, args] = takeOption(afterPart, "--format");
|
|
179
|
+
if (format !== undefined && !PIN_FORMATS.includes(format))
|
|
180
|
+
throw new Error(`--format takes ${PIN_FORMATS.join(", ")} (got ${format})`);
|
|
181
|
+
const text = await pinMapText(root, required(args[0], "file"), { ...designOptions(options), ...(part ? { part } : {}), ...(format ? { format: format } : {}) });
|
|
182
|
+
io.out(text);
|
|
183
|
+
return 0;
|
|
184
|
+
}
|
|
137
185
|
case "export": {
|
|
138
186
|
const [outDir, args] = takeOption(rest, "--out");
|
|
139
187
|
const result = await exportFabrication(root, required(args[0], "file"), { ...designOptions(options), ...(outDir ? { outDir } : {}) });
|
|
140
188
|
io.out(formatFabrication(result));
|
|
141
189
|
return result.written ? 0 : 1;
|
|
142
190
|
}
|
|
191
|
+
case "step": {
|
|
192
|
+
const [out, args] = takeOption(rest, "--out");
|
|
193
|
+
io.out(formatStepExport(await exportStep(root, required(args[0], "file"), { ...designOptions(options), ...(out ? { out } : {}) })));
|
|
194
|
+
return 0;
|
|
195
|
+
}
|
|
143
196
|
case "render":
|
|
144
197
|
io.out(await renderCommand(root, rest, options));
|
|
145
198
|
return 0;
|
|
199
|
+
case "simulate":
|
|
200
|
+
io.out(await simulateCommand(root, rest, options.engine));
|
|
201
|
+
return 0;
|
|
202
|
+
case "spice":
|
|
203
|
+
io.out(await spiceCommand(root, rest, options.engine));
|
|
204
|
+
return 0;
|
|
146
205
|
case "board":
|
|
147
206
|
io.out(await boardCommand(root, rest, options));
|
|
148
207
|
return 0;
|
|
208
|
+
case "import":
|
|
209
|
+
io.out(await importCommand(cwd, root, rest, options));
|
|
210
|
+
return 0;
|
|
211
|
+
case "impedance":
|
|
212
|
+
io.out(await impedanceCommand(root, rest));
|
|
213
|
+
return 0;
|
|
149
214
|
case "undo": {
|
|
150
215
|
// The built design tells which tracks start on locked parts, so copper can be undone while parts are locked.
|
|
151
216
|
const design = (circuit) => buildWith(root, circuit, options.engine);
|
|
@@ -187,22 +252,61 @@ async function boardCommand(root, rest, options) {
|
|
|
187
252
|
const result = await importBoard(root, required(args[0], "file"), request, { author: "human", ...designOptions(options) });
|
|
188
253
|
return formatBoardImport(result).join("\n");
|
|
189
254
|
}
|
|
255
|
+
const KICAD_USAGE = "Usage: copperflow import kicad <board.kicad_pcb> [--name <circuit name>] [--replace] [--origin keep]";
|
|
256
|
+
/** `import kicad <path>`: the path is read from where the command runs, as a person typed it. */
|
|
257
|
+
async function importCommand(cwd, root, rest, options) {
|
|
258
|
+
const [kind, ...args] = rest;
|
|
259
|
+
if (kind !== "kicad")
|
|
260
|
+
throw new Error(`import reads kicad boards only. ${KICAD_USAGE}`);
|
|
261
|
+
const [name, afterName] = takeOption(args, "--name");
|
|
262
|
+
const [origin, afterOrigin] = takeOption(afterName, "--origin");
|
|
263
|
+
const [replace, remaining] = takeFlag(afterOrigin, "--replace");
|
|
264
|
+
if (origin !== undefined && origin !== "keep")
|
|
265
|
+
throw new Error(`--origin takes keep, not ${origin}`);
|
|
266
|
+
const unknown = remaining.find((arg) => arg.startsWith("-"));
|
|
267
|
+
if (unknown)
|
|
268
|
+
throw new Error(`Unknown option "${unknown}" for import kicad. ${KICAD_USAGE}`);
|
|
269
|
+
if (remaining[0] === undefined)
|
|
270
|
+
throw new Error(`Missing the KiCad board (.kicad_pcb). ${KICAD_USAGE}`);
|
|
271
|
+
const request = { kicad: resolve(cwd, remaining[0]), replace, ...(name !== undefined ? { name } : {}), ...(origin === "keep" ? { origin: "keep" } : {}) };
|
|
272
|
+
return formatKicadImport(await importKicad(root, request, { author: "human", caller: "cli", ...designOptions(options) })).join("\n");
|
|
273
|
+
}
|
|
190
274
|
async function renderCommand(root, rest, options) {
|
|
191
275
|
const [view, afterView] = takeOption(rest, "--view");
|
|
192
276
|
const [page, afterPage] = takeOption(afterView, "--page");
|
|
193
277
|
const [parts, afterParts] = takeOption(afterPage, "--parts");
|
|
194
278
|
const [width, afterWidth] = takeOption(afterParts, "--width");
|
|
195
|
-
const [out,
|
|
196
|
-
|
|
197
|
-
|
|
279
|
+
const [out, afterOut] = takeOption(afterWidth, "--out");
|
|
280
|
+
const [change, afterChange] = takeOption(afterOut, "--change");
|
|
281
|
+
const [since, afterSince] = takeOption(afterChange, "--since");
|
|
282
|
+
const [side, afterSide] = takeOption(afterSince, "--side");
|
|
283
|
+
const [mask, afterMask] = takeOption(afterSide, "--mask");
|
|
284
|
+
const [finish, afterFinish] = takeOption(afterMask, "--finish");
|
|
285
|
+
const [silk, afterSilk] = takeOption(afterFinish, "--silk");
|
|
286
|
+
const [background, afterBackground] = takeOption(afterSilk, "--background");
|
|
287
|
+
const [angle, args] = takeOption(afterBackground, "--angle");
|
|
288
|
+
if (view !== undefined && view !== "pcb" && view !== "schematic" && view !== "board" && view !== "3d")
|
|
289
|
+
throw new Error(`--view must be pcb, schematic, board or 3d, not ${view}`);
|
|
290
|
+
if (angle !== undefined && !["top", "bottom", "front", "iso"].includes(angle))
|
|
291
|
+
throw new Error(`--angle must be top, bottom, front or iso, not ${angle}`);
|
|
292
|
+
if (side !== undefined && side !== "top" && side !== "bottom")
|
|
293
|
+
throw new Error(`--side must be top or bottom, not ${side}`);
|
|
294
|
+
const look = { ...(mask !== undefined ? { mask } : {}), ...(finish !== undefined ? { finish } : {}), ...(silk !== undefined ? { silk } : {}), ...(background !== undefined ? { background } : {}) };
|
|
198
295
|
const request = {
|
|
199
296
|
view: view ?? "pcb",
|
|
297
|
+
...(side !== undefined ? { side: side } : {}),
|
|
298
|
+
...(angle !== undefined ? { angle: angle } : {}),
|
|
299
|
+
...(Object.keys(look).length > 0 ? { look } : {}),
|
|
200
300
|
...(page !== undefined ? { page } : {}),
|
|
201
301
|
...(parts !== undefined ? { parts: parts.split(",").map((name) => name.trim()).filter((name) => name !== "") } : {}),
|
|
202
302
|
...(width !== undefined ? { width: Number(width) } : {}),
|
|
203
303
|
};
|
|
204
304
|
const renderOptions = { ...designOptions(options), ...(options.renderer ? { renderer: options.renderer } : {}) };
|
|
205
|
-
|
|
305
|
+
const file = required(args[0], "file");
|
|
306
|
+
const marked = await changeRequest(root, file, request, { change, since }, options.engine);
|
|
307
|
+
if (marked)
|
|
308
|
+
return writeRender(root, file, marked.request, out, { ...renderOptions, design: marked.design });
|
|
309
|
+
return writeRender(root, file, request, out, renderOptions);
|
|
206
310
|
}
|
|
207
311
|
async function changeLocks(root, command, rest, io) {
|
|
208
312
|
const file = required(rest[0], "file");
|